2 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3 * Copyright (c) 1990,1993 Regents of The University of Michigan.
4 * All Rights Reserved. See COPYRIGHT.
6 * modified from main.c. this handles afp options.
11 #endif /* HAVE_CONFIG_H */
18 #include <sys/param.h>
19 #include <sys/socket.h>
20 #include <atalk/logger.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
27 #endif /* HAVE_NETDB_H */
31 #include <sys/types.h>
32 #endif /* ADMIN_GRP */
34 #include <atalk/paths.h>
35 #include <atalk/util.h>
36 #include <atalk/compat.h>
37 #include <atalk/globals.h>
38 #include <atalk/fce_api.h>
39 #include <atalk/errchk.h>
47 /* get rid of any allocated afp_option buffers. */
48 void afp_options_free(struct afp_options *opt)
52 if (opt->adminauthuser)
53 free(opt->adminauthuser);
55 free(opt->configfile);
75 free(opt->maccodepage);
77 free(opt->mimicmodel);
81 free(opt->ntseparator);
83 free(opt->passwdfile);
86 if (opt->signatureopt)
87 free(opt->signatureopt);
92 if (opt->unixcodepage)
93 free(opt->unixcodepage);
97 int afp_config_parse(AFPObj *AFPObj)
101 struct afp_options *options = &AFPObj->options;
107 options->configfile = AFPObj->cmdlineconfigfile ? strdup(AFPObj->cmdlineconfigfile) : strdup(_PATH_CONFDIR "afp.conf");
108 options->sigconffile = strdup(_PATH_CONFDIR "afp_signature.conf");
109 options->uuidconf = strdup(_PATH_CONFDIR "afp_voluuid.conf");
110 options->flags = OPTION_ACL2MACCESS | OPTION_UUID | OPTION_SERVERNOTIF | AFPObj->cmdlineflags;
112 if ((config = iniparser_load(AFPObj->options.configfile)) == NULL)
114 AFPObj->iniconfig = config;
117 options->logconfig = iniparser_getstrdup(config, INISEC_GLOBAL, "loglevel", "default:note");
118 options->logfile = iniparser_getstrdup(config, INISEC_GLOBAL, "logfile", NULL);
119 set_processname("afpd");
120 setuplog(options->logconfig, options->logfile);
122 /* [AFP] "options" options wo values */
123 p = iniparser_getstring(config, INISEC_AFP, "options", "");
125 strlcat(val, p, MAXVAL);
127 if (strstr(val, " nozeroconf"))
128 options->flags |= OPTION_NOZEROCONF;
129 if (strstr(val, " icon"))
130 options->flags |= OPTION_CUSTOMICON;
131 if (strstr(val, " noicon"))
132 options->flags &= ~OPTION_CUSTOMICON;
133 if (strstr(val, " advertise_ssh"))
134 options->flags |= OPTION_ANNOUNCESSH;
135 if (strstr(val, " noacl2maccess"))
136 options->flags &= ~OPTION_ACL2MACCESS;
137 if (strstr(val, " keepsessions"))
138 options->flags |= OPTION_KEEPSESSIONS;
139 if (strstr(val, " closevol"))
140 options->flags |= OPTION_CLOSEVOL;
141 if (strstr(val, " client_polling"))
142 options->flags &= ~OPTION_SERVERNOTIF;
143 if (strstr(val, " nosavepassword"))
144 options->passwdbits |= PASSWD_NOSAVE;
145 if (strstr(val, " savepassword"))
146 options->passwdbits &= ~PASSWD_NOSAVE;
147 if (strstr(val, " nosetpassword"))
148 options->passwdbits &= ~PASSWD_SET;
149 if (strstr(val, " setpassword"))
150 options->passwdbits |= PASSWD_SET;
152 /* figure out options w values */
154 options->loginmesg = iniparser_getstrdup(config, INISEC_AFP, "loginmesg", "");
155 options->guest = iniparser_getstrdup(config, INISEC_AFP, "guestname", "nobody");
156 options->passwdfile = iniparser_getstrdup(config, INISEC_AFP, "passwdfile", _PATH_AFPDPWFILE);
157 options->uampath = iniparser_getstrdup(config, INISEC_AFP, "uampath", _PATH_AFPDUAMPATH);
158 options->uamlist = iniparser_getstrdup(config, INISEC_AFP, "uamlist", "uams_dhx.so,uams_dhx2.so");
159 options->port = iniparser_getstrdup(config, INISEC_AFP, "port", "548");
160 options->signatureopt = iniparser_getstrdup(config, INISEC_AFP, "signature", "auto");
161 options->k5service = iniparser_getstrdup(config, INISEC_AFP, "k5service", NULL);
162 options->k5realm = iniparser_getstrdup(config, INISEC_AFP, "k5realm", NULL);
163 options->authprintdir = iniparser_getstrdup(config, INISEC_AFP, "authprintdir", NULL);
164 options->listen = iniparser_getstrdup(config, INISEC_AFP, "listen", NULL);
165 options->ntdomain = iniparser_getstrdup(config, INISEC_AFP, "ntdomain", NULL);
166 options->ntseparator = iniparser_getstrdup(config, INISEC_AFP, "ntseparator", NULL);
167 options->mimicmodel = iniparser_getstrdup(config, INISEC_AFP, "mimicmodel", NULL);
168 options->adminauthuser = iniparser_getstrdup(config, INISEC_AFP, "adminauthuser", NULL);
169 options->connections = iniparser_getint (config, INISEC_AFP, "maxcon", 200);
170 options->passwdminlen = iniparser_getint (config, INISEC_AFP, "passwdminlen", 0);
171 options->tickleval = iniparser_getint (config, INISEC_AFP, "tickleval", 30);
172 options->timeout = iniparser_getint (config, INISEC_AFP, "timeout", 4);
173 options->dsireadbuf = iniparser_getint (config, INISEC_AFP, "dsireadbuf", 12);
174 options->server_quantum = iniparser_getint (config, INISEC_AFP, "server_quantum", DSI_SERVQUANT_DEF);
175 options->volnamelen = iniparser_getint (config, INISEC_AFP, "volnamelen", 80);
176 options->dircachesize = iniparser_getint (config, INISEC_AFP, "dircachesize", DEFAULT_MAX_DIRCACHE_SIZE);
177 options->tcp_sndbuf = iniparser_getint (config, INISEC_AFP, "tcpsndbuf", 0);
178 options->tcp_rcvbuf = iniparser_getint (config, INISEC_AFP, "tcprcvbuf", 0);
179 options->fce_fmodwait = iniparser_getint (config, INISEC_AFP, "fceholdfmod", 60);
180 options->sleep = iniparser_getint (config, INISEC_AFP, "sleep", 10) * 60 * 2;
181 options->disconnected = iniparser_getint (config, INISEC_AFP, "disconnect", 24) * 60 * 2;
183 if ((p = iniparser_getstring(config, INISEC_AFP, "hostname", NULL))) {
184 EC_NULL_LOG( options->hostname = strdup(p) );
186 if (gethostname(val, sizeof(val)) < 0 ) {
187 perror( "gethostname" );
190 if ((q = strchr(val, '.')))
192 options->hostname = strdup(val);
195 if ((p = iniparser_getstring(config, INISEC_AFP, "k5keytab", NULL))) {
196 EC_NULL_LOG( options->k5keytab = malloc(strlen(p) + 14) );
197 snprintf(options->k5keytab, strlen(p) + 14, "KRB5_KTNAME=%s", p);
198 putenv(options->k5keytab);
202 if ((p = iniparser_getstring(config, INISEC_AFP, "admingroup", NULL))) {
203 struct group *gr = getgrnam(p);
205 options->admingid = gr->gr_gid;
207 #endif /* ADMIN_GRP */
209 q = iniparser_getstrdup(config, INISEC_AFP, "cnidserver", "localhost:4700");
213 options->Cnid_srv = strdup(q);
215 options->Cnid_port = strdup(r + 1);
217 options->Cnid_port = strdup("4700");
218 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", options->Cnid_srv, options->Cnid_port);
222 if ((q = iniparser_getstrdup(config, INISEC_AFP, "fqdn", NULL))) {
223 /* do a little checking for the domain name. */
227 if (gethostbyname(q)) {
230 EC_NULL_LOG( options->fqdn = strdup(q) );
232 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
237 if (!(p = iniparser_getstring(config, INISEC_AFP, "unixcodepage", NULL))) {
238 options->unixcharset = CH_UNIX;
239 options->unixcodepage = strdup("LOCALE");
241 if ((options->unixcharset = add_charset(p)) == (charset_t)-1) {
242 options->unixcharset = CH_UNIX;
243 options->unixcodepage = strdup("LOCALE");
244 LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
246 options->unixcodepage = strdup(p);
250 if (!(p = iniparser_getstring(config, INISEC_AFP, "maccodepage", NULL))) {
251 options->maccharset = CH_MAC;
252 options->maccodepage = strdup("MAC_ROMAN");
254 if ((options->maccharset = add_charset(p)) == (charset_t)-1) {
255 options->maccharset = CH_MAC;
256 options->maccodepage = strdup("MAC_ROMAN");
257 LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
259 options->maccodepage = strdup(p);
263 if ((p = iniparser_getstring(config, INISEC_AFP, "fcelistener", NULL))) {
264 LOG(log_note, logtype_afpd, "Adding FCE listener: %s", p);
265 fce_add_udp_socket(p);
267 if ((p = iniparser_getstring(config, INISEC_AFP, "fcecoalesce", NULL))) {
268 LOG(log_note, logtype_afpd, "Fce coalesce: %s", p);
271 if ((p = iniparser_getstring(config, INISEC_AFP, "fceevents", NULL))) {
272 LOG(log_note, logtype_afpd, "Fce events: %s", p);
276 /* Check for sane values */
277 if (options->tickleval <= 0)
278 options->tickleval = 30;
279 if (options->timeout <= 0)
280 options->timeout = 4;
281 if (options->sleep <= 4)
282 options->disconnected = options->sleep = 4;
283 if (options->dsireadbuf < 6)
284 options->dsireadbuf = 6;
285 if (options->volnamelen < 8)
286 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
287 if (options->volnamelen > 255)
288 options->volnamelen = 255; /* AFP3 spec */
295 * Show version information about afpd.
298 static void show_version( void )
302 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
304 puts( "This program is free software; you can redistribute it and/or modify it under" );
305 puts( "the terms of the GNU General Public License as published by the Free Software" );
306 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
307 puts( "version. Please see the file COPYING for further information and details.\n" );
309 puts( "afpd has been compiled with support for these features:\n" );
311 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
312 printf( " AFP versions:\t" );
313 for ( i = 0; i < num; i++ ) {
314 printf( "%d.%d ", afp_versions[ i ].av_number/10, afp_versions[ i ].av_number%10);
318 printf( " CNID backends:\t" );
319 #ifdef CNID_BACKEND_CDB
322 #ifdef CNID_BACKEND_DB3
325 #ifdef CNID_BACKEND_DBD
326 #ifdef CNID_BACKEND_DBD_TXN
327 printf( "dbd-txn " );
332 #ifdef CNID_BACKEND_HASH
335 #ifdef CNID_BACKEND_LAST
338 #ifdef CNID_BACKEND_MTAB
341 #ifdef CNID_BACKEND_TDB
348 * Show extended version information about afpd and Netatalk.
351 static void show_version_extended(void )
355 printf( " Zeroconf support:\t" );
362 printf( " TCP wrappers support:\t" );
369 printf( " Quota support:\t" );
370 #ifndef NO_QUOTA_SUPPORT
376 printf( " Admin group support:\t" );
383 printf( " Valid shell checks:\t" );
384 #ifndef DISABLE_SHELLCHECK
390 printf( " cracklib support:\t" );
397 printf( " EA support:\t" );
400 printf( " ACL support:\t" );
407 printf( " LDAP support:\t" );
416 * Display compiled-in default paths
418 static void show_paths( void )
420 printf( " afp.conf:\t%s\n", _PATH_CONFDIR "afp.conf");
421 printf( " afp_signature.conf:\t%s\n", _PATH_CONFDIR "afp_signature.conf");
422 printf( " afp_voluuid.conf:\t%s\n", _PATH_CONFDIR "afp_voluuid.conf");
423 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
424 printf( " Server messages path:\t%s\n", SERVERTEXT);
425 printf( " lockfile:\t%s\n", _PATH_AFPDLOCK);
429 * Display usage information about afpd.
431 static void show_usage(void)
433 fprintf( stderr, "Usage:\tafpd [-d] [-F configfile]\n");
434 fprintf( stderr, "\tafpd -h|-v|-V\n");
437 void afp_options_parse_cmdline(AFPObj *obj, int ac, char **av)
441 while (EOF != ( c = getopt( ac, av, "dFvVh" )) ) {
444 obj->cmdlineflags |= OPTION_DEBUG;
447 obj->cmdlineconfigfile = strdup(optarg);
449 case 'v': /* version */
450 show_version( ); puts( "" );
451 show_paths( ); puts( "" );
454 case 'V': /* extended version */
455 show_version_extended( ); puts( "" );
456 show_paths( ); puts( "" );
459 case 'h': /* usage */
467 if ( err || optind != ac ) {