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>
46 /* get rid of any allocated afp_option buffers. */
47 void afp_options_free(struct afp_options *opt)
49 if (opt->adminauthuser)
50 free(opt->adminauthuser);
52 free(opt->configfile);
70 free(opt->maccodepage);
72 free(opt->mimicmodel);
76 free(opt->ntseparator);
78 free(opt->passwdfile);
83 if (opt->signatureopt)
84 free(opt->signatureopt);
89 if (opt->unixcodepage)
90 free(opt->unixcodepage);
94 int afp_config_parse(AFPObj *AFPObj)
96 dictionary *config = AFPObj->iniconfig;
97 struct afp_options *options = &AFPObj->options;
102 memset(options, 0, sizeof(struct afp_options));
103 options->configfile = strdup(_PATH_CONFDIR "afp.conf");
104 options->sigconffile = strdup(_PATH_CONFDIR "afp_signature.conf");
105 options->uuidconf = strdup(_PATH_CONFDIR "afp_voluuid.conf");
106 options->flags |= OPTION_ACL2MACCESS | OPTION_UUID | OPTION_SERVERNOTIF;
108 while (EOF != (p = getopt(AFPObj->argc, AFPObj->argv, "dF:"))) {
111 options->flags |= OPTION_DEBUG;
114 if (options->configfile)
115 free(options->configfile);
116 options->configfile = optarg;
123 if ((config = iniparser_load(AFPObj->options.configfile)) == NULL)
125 AFPObj->iniconfig = config;
128 options->logconfig = iniparser_getstring(config, INISEC_GLOBAL, "loglevel", "default:note");
129 options->logfile = iniparser_getstring(config, INISEC_GLOBAL, "logfile", NULL);
130 set_processname("afpd");
131 setuplog(logconfig, logfile);
133 /* [AFP] "options" options wo values */
134 p = iniparser_getstring(config, INISEC_AFP, "options", "");
136 strlcat(val, p, MAXVAL);
138 if (strstr(val, " nozeroconf"))
139 options->flags |= OPTION_NOZEROCONF;
140 if (strstr(val, " icon"))
141 options->flags |= OPTION_CUSTOMICON;
142 if (strstr(val, " noicon"))
143 options->flags &= ~OPTION_CUSTOMICON;
144 if (strstr(val, " advertise_ssh"))
145 options->flags |= OPTION_ANNOUNCESSH;
146 if (strstr(val, " noacl2maccess"))
147 options->flags &= ~OPTION_ACL2MACCESS;
148 if (strstr(val, " keepsessions"))
149 options->flags |= OPTION_KEEPSESSIONS;
150 if (strstr(val, " keepsessions"))
151 options->flags |= OPTION_CLOSEVOL;
152 if (strstr(val, " client_polling"))
153 options->flags &= ~OPTION_SERVERNOTIF;
154 if (strstr(val, " nosavepassword"))
155 options->passwdbits |= PASSWD_NOSAVE;
156 if (strstr(val, " savepassword"))
157 options->passwdbits &= ~PASSWD_NOSAVE;
158 if (strstr(val, " nosetpassword"))
159 options->passwdbits &= ~PASSWD_SET;
160 if (strstr(val, " setpassword"))
161 options->passwdbits |= PASSWD_SET;
163 /* figure out options w values */
165 options->loginmesg = iniparser_getstring(config, INISEC_AFP, "loginmesg", "");
166 options->guest = iniparser_getstring(config, INISEC_AFP, "guestname", "nobody");
167 options->passwdfile = iniparser_getstring(config, INISEC_AFP, "passwdfile", _PATH_AFPDPWFILE);
168 options->uampath = iniparser_getstring(config, INISEC_AFP, "uampath", _PATH_AFPDUAMPATH);
169 options->uamlist = iniparser_getstring(config, INISEC_AFP, "uamlist", "uams_dhx.so,uams_dhx2.so");
170 options->port = iniparser_getstring(config, INISEC_AFP, "port", "548");
171 options->signatureopt = iniparser_getstring(config, INISEC_AFP, "signature", "auto");
173 options->connections = iniparser_getint (config, INISEC_AFP, "maxcon", 200);
174 options->passwdminlen = iniparser_getint (config, INISEC_AFP, "passwdminlen", 0);
175 options->tickleval = iniparser_getint (config, INISEC_AFP, "tickleval", 30);
176 options->timeout = iniparser_getint (config, INISEC_AFP, "timeout", 4);
177 options->dsireadbuf = iniparser_getint (config, INISEC_AFP, "dsireadbuf", 12);
178 options->server_quantum = iniparser_getint (config, INISEC_AFP, "server_quantum", DSI_SERVQUANT_DEF);
179 options->volnamelen = iniparser_getint (config, INISEC_AFP, "volnamelen", 80);
180 options->dircachesize = iniparser_getint (config, INISEC_AFP, "dircachesize", DEFAULT_MAX_DIRCACHE_SIZE);
181 options->tcp_sndbuf = iniparser_getint (config, INISEC_AFP, "tcpsndbuf", 0);
182 options->tcp_rcvbuf = iniparser_getint (config, INISEC_AFP, "tcprcvbuf", 0);
183 options->fce_fmodwait = iniparser_getint (config, INISEC_AFP, "fceholdfmod", 60);
184 options->sleep = iniparser_getint (config, INISEC_AFP, "sleep", 10) * 60 * 2;
185 options->disconnect = iniparser_getint (config, INISEC_AFP, "disconnect" 24) * 60 * 2;
187 options->k5service = iniparser_getstringdup(config, INISEC_AFP, "k5service", NULL);
188 options->k5realm = iniparser_getstringdup(config, INISEC_AFP, "k5realm", NULL);
189 options->authprintdir = iniparser_getstringdup(config, INISEC_AFP, "authprintdir", NULL);
190 options->ipaddr = iniparser_getstringdup(config, INISEC_AFP, "ipaddr", NULL);
191 options->hostname = iniparser_getstringdup(config, INISEC_AFP, "hostname", NULL);
192 options->ntdomain = iniparser_getstringdup(config, INISEC_AFP, "ntdomain", NULL);
193 options->ntseparator = iniparser_getstringdup(config, INISEC_AFP, "ntseparator", NULL);
194 options->mimicmodel = iniparser_getstringdup(config, INISEC_AFP, "mimicmodel", NULL);
195 options->adminauthuser = iniparser_getstringdup(config, INISEC_AFP, "adminauthuser", NULL);
197 if ((p = iniparser_getstring(config, INISEC_AFP, "k5keytab", NULL))) {
198 EC_NULL_LOG( options->k5keytab = malloc(strlen(p) + 14) );
199 snprintf(options->k5keytab, strlen(p) + 14, "KRB5_KTNAME=%s", p);
200 putenv(options->k5keytab);
204 if ((p = iniparser_getstring(config, INISEC_AFP, "admingroup", NULL))) {
205 struct group *gr = getgrnam(p);
207 options->admingid = gr->gr_gid;
209 #endif /* ADMIN_GRP */
211 p = iniparser_getstring(config, INISEC_AFP, "cnidserver", "localhost:4700");
212 tmp = strrchr(p, ':');
215 options->Cnid_srv = strdup(p);
217 options->Cnid_port = strdup(tmp + 1);
218 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", options->Cnid_srv, options->Cnid_port);
221 if ((p = iniparser_getstring(config, INISEC_AFP, "fqdn", NULL))) {
222 /* do a little checking for the domain name. */
223 tmp = strchr(c, ':');
226 if (gethostbyname(p)) {
229 if ((opt = strdup(p)))
232 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
236 p = iniparser_getstring(config, INISEC_AFP, "unixcodepage", "LOCALE");
237 if ((options->unixcharset = add_charset(p)) == (charset_t)-1) {
238 options->unixcharset = CH_UNIX;
239 LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
241 options->unixcodepage = strdup(p);
244 p = iniparser_getstring(config, INISEC_AFP, "maccodepage", "MAC_ROMAN");
245 if ((options->maccharset = add_charset(p)) == (charset_t)-1) {
246 options->maccharset = CH_MAC;
247 LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
249 options->maccharset = strdup(p);
252 if ((p = iniparser_getstring(config, INISEC_AFP, "fcelistener", NULL))) {
253 LOG(log_note, logtype_afpd, "Adding FCE listener: %s", p);
254 fce_add_udp_socket(p);
256 if ((p = iniparser_getstring(config, INISEC_AFP, "fcecoalesce", NULL))) {
257 LOG(log_note, logtype_afpd, "Fce coalesce: %s", p);
260 if ((p = iniparser_getstring(config, INISEC_AFP, "fceevents", NULL))) {
261 LOG(log_note, logtype_afpd, "Fce events: %s", p);
265 /* Check for sane values */
266 if (options->tickleval <= 0)
267 options->tickleval = 30;
268 if (options->timeout <= 0)
269 options->timeout = 4;
270 if (options->sleep <= 4)
271 options->disconnected = options->sleep = 4;
272 if (options->dsireadbuf < 6)
273 options->dsireadbuf = 6;
274 if (options->volnamelen < 8)
275 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
276 if (options->volnamelen > 255)
277 options->volnamelen = 255; /* AFP3 spec */
283 * Show version information about afpd.
286 static void show_version( void )
290 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
292 puts( "This program is free software; you can redistribute it and/or modify it under" );
293 puts( "the terms of the GNU General Public License as published by the Free Software" );
294 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
295 puts( "version. Please see the file COPYING for further information and details.\n" );
297 puts( "afpd has been compiled with support for these features:\n" );
299 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
300 printf( " AFP versions:\t" );
301 for ( i = 0; i < num; i++ ) {
302 printf( "%d.%d ", afp_versions[ i ].av_number/10, afp_versions[ i ].av_number%10);
306 printf( " CNID backends:\t" );
307 #ifdef CNID_BACKEND_CDB
310 #ifdef CNID_BACKEND_DB3
313 #ifdef CNID_BACKEND_DBD
314 #ifdef CNID_BACKEND_DBD_TXN
315 printf( "dbd-txn " );
320 #ifdef CNID_BACKEND_HASH
323 #ifdef CNID_BACKEND_LAST
326 #ifdef CNID_BACKEND_MTAB
329 #ifdef CNID_BACKEND_TDB
336 * Show extended version information about afpd and Netatalk.
339 static void show_version_extended(void )
343 printf( " Zeroconf support:\t" );
350 printf( " TCP wrappers support:\t" );
357 printf( " Quota support:\t" );
358 #ifndef NO_QUOTA_SUPPORT
364 printf( " Admin group support:\t" );
371 printf( " Valid shell checks:\t" );
372 #ifndef DISABLE_SHELLCHECK
378 printf( " cracklib support:\t" );
385 printf( " EA support:\t" );
388 printf( " ACL support:\t" );
395 printf( " LDAP support:\t" );
404 * Display compiled-in default paths
406 static void show_paths( void )
408 printf( " afpd.conf:\t%s\n", _PATH_AFPDCONF );
409 printf( " AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
410 printf( " AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
411 printf( " afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
412 printf( " afp_voluuid.conf:\t%s\n", _PATH_AFPDUUIDCONF );
414 printf( " afp_ldap.conf:\t%s\n", _PATH_ACL_LDAPCONF );
416 printf( " afp_ldap.conf:\tnot supported\n");
418 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
419 printf( " Server messages path:\t%s\n", SERVERTEXT);
420 printf( " lockfile:\t%s\n", _PATH_AFPDLOCK);
424 * Display usage information about afpd.
426 static void show_usage( char *name )
428 fprintf( stderr, "Usage:\t%s [-duptDTI] [-n nbpname]\n", name );
429 fprintf( stderr, "\t [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
430 fprintf( stderr, "\t [-F configfile] [-U uams] [-m umask]\n" );
431 fprintf( stderr, "\t%s -h|-v|-V\n", name );
434 int afp_options_parse_cmdline(int ac, char **av)
437 char *tmp; /* Used for error checking the result of strtol */
441 if (gethostname(buf, sizeof(buf)) < 0 ) {
442 perror( "gethostname" );
445 if (NULL != (p = strchr(buf, '.')))
447 options->hostname = strdup(buf);
449 while (EOF != ( c = getopt( ac, av, "vVh" )) ) {
451 case 'v': /* version */
452 show_version( ); puts( "" );
453 show_paths( ); puts( "" );
456 case 'V': /* extended version */
457 show_version_extended( ); puts( "" );
458 show_paths( ); puts( "" );
461 case 'h': /* usage */
469 if ( err || optind != ac ) {