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 static const char *configfile;
50 /* get rid of any allocated afp_option buffers. */
51 void afp_options_free(struct afp_options *opt)
55 if (opt->adminauthuser)
56 free(opt->adminauthuser);
58 free(opt->configfile);
78 free(opt->maccodepage);
80 free(opt->mimicmodel);
84 free(opt->ntseparator);
86 free(opt->passwdfile);
89 if (opt->signatureopt)
90 free(opt->signatureopt);
95 if (opt->unixcodepage)
96 free(opt->unixcodepage);
100 int afp_config_parse(AFPObj *AFPObj)
104 struct afp_options *options = &AFPObj->options;
110 options->configfile = configfile ? strdup(configfile) : strdup(_PATH_CONFDIR "afp.conf");
111 options->sigconffile = strdup(_PATH_CONFDIR "afp_signature.conf");
112 options->uuidconf = strdup(_PATH_CONFDIR "afp_voluuid.conf");
113 options->flags = OPTION_ACL2MACCESS | OPTION_UUID | OPTION_SERVERNOTIF | flags;
115 if ((config = iniparser_load(AFPObj->options.configfile)) == NULL)
117 AFPObj->iniconfig = config;
120 options->logconfig = iniparser_getstrdup(config, INISEC_GLOBAL, "loglevel", "default:note");
121 options->logfile = iniparser_getstrdup(config, INISEC_GLOBAL, "logfile", NULL);
122 set_processname("afpd");
123 setuplog(options->logconfig, options->logfile);
125 /* [AFP] "options" options wo values */
126 p = iniparser_getstring(config, INISEC_AFP, "options", "");
128 strlcat(val, p, MAXVAL);
130 if (strstr(val, " nozeroconf"))
131 options->flags |= OPTION_NOZEROCONF;
132 if (strstr(val, " icon"))
133 options->flags |= OPTION_CUSTOMICON;
134 if (strstr(val, " noicon"))
135 options->flags &= ~OPTION_CUSTOMICON;
136 if (strstr(val, " advertise_ssh"))
137 options->flags |= OPTION_ANNOUNCESSH;
138 if (strstr(val, " noacl2maccess"))
139 options->flags &= ~OPTION_ACL2MACCESS;
140 if (strstr(val, " keepsessions"))
141 options->flags |= OPTION_KEEPSESSIONS;
142 if (strstr(val, " closevol"))
143 options->flags |= OPTION_CLOSEVOL;
144 if (strstr(val, " client_polling"))
145 options->flags &= ~OPTION_SERVERNOTIF;
146 if (strstr(val, " nosavepassword"))
147 options->passwdbits |= PASSWD_NOSAVE;
148 if (strstr(val, " savepassword"))
149 options->passwdbits &= ~PASSWD_NOSAVE;
150 if (strstr(val, " nosetpassword"))
151 options->passwdbits &= ~PASSWD_SET;
152 if (strstr(val, " setpassword"))
153 options->passwdbits |= PASSWD_SET;
155 /* figure out options w values */
157 options->loginmesg = iniparser_getstrdup(config, INISEC_AFP, "loginmesg", "");
158 options->guest = iniparser_getstrdup(config, INISEC_AFP, "guestname", "nobody");
159 options->passwdfile = iniparser_getstrdup(config, INISEC_AFP, "passwdfile", _PATH_AFPDPWFILE);
160 options->uampath = iniparser_getstrdup(config, INISEC_AFP, "uampath", _PATH_AFPDUAMPATH);
161 options->uamlist = iniparser_getstrdup(config, INISEC_AFP, "uamlist", "uams_dhx.so,uams_dhx2.so");
162 options->port = iniparser_getstrdup(config, INISEC_AFP, "port", "548");
163 options->signatureopt = iniparser_getstrdup(config, INISEC_AFP, "signature", "auto");
164 options->k5service = iniparser_getstrdup(config, INISEC_AFP, "k5service", NULL);
165 options->k5realm = iniparser_getstrdup(config, INISEC_AFP, "k5realm", NULL);
166 options->authprintdir = iniparser_getstrdup(config, INISEC_AFP, "authprintdir", NULL);
167 options->listen = iniparser_getstrdup(config, INISEC_AFP, "listen", NULL);
168 options->ntdomain = iniparser_getstrdup(config, INISEC_AFP, "ntdomain", NULL);
169 options->ntseparator = iniparser_getstrdup(config, INISEC_AFP, "ntseparator", NULL);
170 options->mimicmodel = iniparser_getstrdup(config, INISEC_AFP, "mimicmodel", NULL);
171 options->adminauthuser = iniparser_getstrdup(config, INISEC_AFP, "adminauthuser", NULL);
172 options->connections = iniparser_getint (config, INISEC_AFP, "maxcon", 200);
173 options->passwdminlen = iniparser_getint (config, INISEC_AFP, "passwdminlen", 0);
174 options->tickleval = iniparser_getint (config, INISEC_AFP, "tickleval", 30);
175 options->timeout = iniparser_getint (config, INISEC_AFP, "timeout", 4);
176 options->dsireadbuf = iniparser_getint (config, INISEC_AFP, "dsireadbuf", 12);
177 options->server_quantum = iniparser_getint (config, INISEC_AFP, "server_quantum", DSI_SERVQUANT_DEF);
178 options->volnamelen = iniparser_getint (config, INISEC_AFP, "volnamelen", 80);
179 options->dircachesize = iniparser_getint (config, INISEC_AFP, "dircachesize", DEFAULT_MAX_DIRCACHE_SIZE);
180 options->tcp_sndbuf = iniparser_getint (config, INISEC_AFP, "tcpsndbuf", 0);
181 options->tcp_rcvbuf = iniparser_getint (config, INISEC_AFP, "tcprcvbuf", 0);
182 options->fce_fmodwait = iniparser_getint (config, INISEC_AFP, "fceholdfmod", 60);
183 options->sleep = iniparser_getint (config, INISEC_AFP, "sleep", 10) * 60 * 2;
184 options->disconnected = iniparser_getint (config, INISEC_AFP, "disconnect", 24) * 60 * 2;
186 if ((p = iniparser_getstring(config, INISEC_AFP, "hostname", NULL))) {
187 EC_NULL_LOG( options->hostname = strdup(p) );
189 if (gethostname(val, sizeof(val)) < 0 ) {
190 perror( "gethostname" );
193 if ((q = strchr(val, '.')))
195 options->hostname = strdup(val);
198 if ((p = iniparser_getstring(config, INISEC_AFP, "k5keytab", NULL))) {
199 EC_NULL_LOG( options->k5keytab = malloc(strlen(p) + 14) );
200 snprintf(options->k5keytab, strlen(p) + 14, "KRB5_KTNAME=%s", p);
201 putenv(options->k5keytab);
205 if ((p = iniparser_getstring(config, INISEC_AFP, "admingroup", NULL))) {
206 struct group *gr = getgrnam(p);
208 options->admingid = gr->gr_gid;
210 #endif /* ADMIN_GRP */
212 q = iniparser_getstrdup(config, INISEC_AFP, "cnidserver", "localhost:4700");
216 options->Cnid_srv = strdup(q);
218 options->Cnid_port = strdup(r + 1);
219 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", options->Cnid_srv, options->Cnid_port);
223 if ((q = iniparser_getstrdup(config, INISEC_AFP, "fqdn", NULL))) {
224 /* do a little checking for the domain name. */
228 if (gethostbyname(q)) {
231 EC_NULL_LOG( options->fqdn = strdup(q) );
233 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
238 if (!(p = iniparser_getstring(config, INISEC_AFP, "unixcodepage", NULL))) {
239 options->unixcharset = CH_UNIX;
240 options->unixcodepage = strdup("LOCALE");
242 if ((options->unixcharset = add_charset(p)) == (charset_t)-1) {
243 options->unixcharset = CH_UNIX;
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 LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
258 options->maccodepage = strdup(p);
262 if ((p = iniparser_getstring(config, INISEC_AFP, "fcelistener", NULL))) {
263 LOG(log_note, logtype_afpd, "Adding FCE listener: %s", p);
264 fce_add_udp_socket(p);
266 if ((p = iniparser_getstring(config, INISEC_AFP, "fcecoalesce", NULL))) {
267 LOG(log_note, logtype_afpd, "Fce coalesce: %s", p);
270 if ((p = iniparser_getstring(config, INISEC_AFP, "fceevents", NULL))) {
271 LOG(log_note, logtype_afpd, "Fce events: %s", p);
275 /* Check for sane values */
276 if (options->tickleval <= 0)
277 options->tickleval = 30;
278 if (options->timeout <= 0)
279 options->timeout = 4;
280 if (options->sleep <= 4)
281 options->disconnected = options->sleep = 4;
282 if (options->dsireadbuf < 6)
283 options->dsireadbuf = 6;
284 if (options->volnamelen < 8)
285 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
286 if (options->volnamelen > 255)
287 options->volnamelen = 255; /* AFP3 spec */
294 * Show version information about afpd.
297 static void show_version( void )
301 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
303 puts( "This program is free software; you can redistribute it and/or modify it under" );
304 puts( "the terms of the GNU General Public License as published by the Free Software" );
305 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
306 puts( "version. Please see the file COPYING for further information and details.\n" );
308 puts( "afpd has been compiled with support for these features:\n" );
310 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
311 printf( " AFP versions:\t" );
312 for ( i = 0; i < num; i++ ) {
313 printf( "%d.%d ", afp_versions[ i ].av_number/10, afp_versions[ i ].av_number%10);
317 printf( " CNID backends:\t" );
318 #ifdef CNID_BACKEND_CDB
321 #ifdef CNID_BACKEND_DB3
324 #ifdef CNID_BACKEND_DBD
325 #ifdef CNID_BACKEND_DBD_TXN
326 printf( "dbd-txn " );
331 #ifdef CNID_BACKEND_HASH
334 #ifdef CNID_BACKEND_LAST
337 #ifdef CNID_BACKEND_MTAB
340 #ifdef CNID_BACKEND_TDB
347 * Show extended version information about afpd and Netatalk.
350 static void show_version_extended(void )
354 printf( " Zeroconf support:\t" );
361 printf( " TCP wrappers support:\t" );
368 printf( " Quota support:\t" );
369 #ifndef NO_QUOTA_SUPPORT
375 printf( " Admin group support:\t" );
382 printf( " Valid shell checks:\t" );
383 #ifndef DISABLE_SHELLCHECK
389 printf( " cracklib support:\t" );
396 printf( " EA support:\t" );
399 printf( " ACL support:\t" );
406 printf( " LDAP support:\t" );
415 * Display compiled-in default paths
417 static void show_paths( void )
419 printf( " afp.conf:\t%s\n", _PATH_CONFDIR "afp.conf");
420 printf( " afp_signature.conf:\t%s\n", _PATH_CONFDIR "afp_signature.conf");
421 printf( " afp_voluuid.conf:\t%s\n", _PATH_CONFDIR "afp_voluuid.conf");
422 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
423 printf( " Server messages path:\t%s\n", SERVERTEXT);
424 printf( " lockfile:\t%s\n", _PATH_AFPDLOCK);
428 * Display usage information about afpd.
430 static void show_usage(void)
432 fprintf( stderr, "Usage:\tafpd [-d] [-F configfile]\n");
433 fprintf( stderr, "\tafpd -h|-v|-V\n");
436 void afp_options_parse_cmdline(int ac, char **av)
440 while (EOF != ( c = getopt( ac, av, "dFvVh" )) ) {
443 flags = OPTION_DEBUG;
446 configfile = strdup(optarg);
448 case 'v': /* version */
449 show_version( ); puts( "" );
450 show_paths( ); puts( "" );
453 case 'V': /* extended version */
454 show_version_extended( ); puts( "" );
455 show_paths( ); puts( "" );
458 case 'h': /* usage */
466 if ( err || optind != ac ) {