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>
45 #define MIN(a, b) ((a) < (b) ? (a) : (b))
49 const char *Cnid_srv = "localhost";
50 const char *Cnid_port = "4700";
52 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:hIvVm:"
55 /* return an option. this uses an internal array, so it's necessary
56 * to duplicate it if you want to hold it for long. this is probably
58 static char *getoption(char *buf, const char *option)
60 static char string[LENGTH + 1];
64 if (option && (buf = strstr(buf, option)))
65 buf = strpbrk(buf, " \t");
67 while (buf && isspace(*buf))
73 /* search for any quoted stuff */
74 if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
76 len = MIN(end - buf, LENGTH);
77 } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
78 len = MIN(end - buf, LENGTH);
80 len = MIN(strlen(buf), LENGTH);
82 strncpy(string, buf, len);
87 /* get rid of any allocated afp_option buffers. */
88 void afp_options_free(struct afp_options *opt,
89 const struct afp_options *save)
91 if (opt->defaultvol.name && (opt->defaultvol.name != save->defaultvol.name))
92 free(opt->defaultvol.name);
93 if (opt->defaultvol.full_name && (opt->defaultvol.full_name != save->defaultvol.full_name))
94 free(opt->defaultvol.full_name);
96 if (opt->systemvol.name && (opt->systemvol.name != save->systemvol.name))
97 free(opt->systemvol.name);
98 if (opt->systemvol.full_name && (opt->systemvol.full_name != save->systemvol.full_name))
99 free(opt->systemvol.full_name);
101 if (opt->uservol.name && (opt->uservol.name != save->uservol.name))
102 free(opt->uservol.name);
103 if (opt->uservol.full_name && (opt->uservol.full_name != save->uservol.full_name))
104 free(opt->uservol.full_name);
106 if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
107 free(opt->loginmesg);
108 if (opt->guest && (opt->guest != save->guest))
110 if (opt->server && (opt->server != save->server))
112 if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
114 if (opt->port && (opt->port != save->port))
116 if (opt->fqdn && (opt->fqdn != save->fqdn))
118 if (opt->uampath && (opt->uampath != save->uampath))
120 if (opt->uamlist && (opt->uamlist != save->uamlist))
122 if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
123 free(opt->passwdfile);
124 if (opt->signatureopt && (opt->signatureopt != save->signatureopt))
125 free(opt->signatureopt);
126 if (opt->k5service && (opt->k5service != save->k5service))
127 free(opt->k5service);
128 if (opt->k5realm && (opt->k5realm != save->k5realm))
130 if (opt->k5keytab && (opt->k5keytab != save->k5keytab))
132 if (opt->unixcodepage && (opt->unixcodepage != save->unixcodepage))
133 free(opt->unixcodepage);
134 if (opt->maccodepage && (opt->maccodepage != save->maccodepage))
135 free(opt->maccodepage);
137 if (opt->ntdomain && (opt->ntdomain != save->ntdomain))
139 if (opt->ntseparator && (opt->ntseparator != save->ntseparator))
140 free(opt->ntseparator);
141 if (opt->logconfig && (opt->logconfig != save->logconfig))
142 free(opt->logconfig);
143 if (opt->mimicmodel && (opt->mimicmodel != save->mimicmodel))
144 free(opt->mimicmodel);
145 if (opt->adminauthuser && (opt->adminauthuser != save->adminauthuser))
146 free(opt->adminauthuser);
149 /* initialize options */
150 void afp_options_init(struct afp_options *options)
152 memset(options, 0, sizeof(struct afp_options));
153 options->connections = 20;
154 options->pidfile = _PATH_AFPDLOCK;
155 options->defaultvol.name = _PATH_AFPDDEFVOL;
156 options->systemvol.name = _PATH_AFPDSYSVOL;
157 options->configfile = _PATH_AFPDCONF;
158 options->sigconffile = _PATH_AFPDSIGCONF;
159 options->uuidconf = _PATH_AFPDUUIDCONF;
160 options->uampath = _PATH_AFPDUAMPATH;
161 options->uamlist = "uams_dhx.so,uams_dhx2.so";
162 options->guest = "nobody";
163 options->loginmesg = "";
164 options->transports = AFPTRANS_TCP; /* TCP only */
165 options->passwdfile = _PATH_AFPDPWFILE;
166 options->tickleval = 30;
167 options->timeout = 4; /* 4 tickles = 2 minutes */
168 options->sleep = 10 * 60 * 2; /* 10 h in 30 seconds tick */
169 options->disconnected = 10 * 60 * 2; /* 10 h in 30 seconds tick */
170 options->server_notif = 1;
171 options->authprintdir = NULL;
172 options->signatureopt = "auto";
175 options->admingid = 0;
176 #endif /* ADMIN_GRP */
177 options->k5service = NULL;
178 options->k5realm = NULL;
179 options->k5keytab = NULL;
180 options->unixcharset = CH_UNIX;
181 options->unixcodepage = "LOCALE";
182 options->maccharset = CH_MAC;
183 options->maccodepage = "MAC_ROMAN";
184 options->volnamelen = 80; /* spec: 255, 10.1: 73, 10.4/10.5: 80 */
185 options->ntdomain = NULL;
186 options->ntseparator = NULL;
188 /* don't advertize slp by default */
189 options->flags |= OPTION_NOSLP;
191 options->dircachesize = DEFAULT_MAX_DIRCACHE_SIZE;
192 options->flags |= OPTION_ACL2MACCESS;
193 options->flags |= OPTION_UUID;
194 options->tcp_sndbuf = 0; /* 0 means don't change OS default */
195 options->tcp_rcvbuf = 0; /* 0 means don't change OS default */
196 options->dsireadbuf = 12;
197 options->mimicmodel = NULL;
198 options->fce_fmodwait = 60; /* put fmod events 60 seconds on hold */
199 options->adminauthuser = NULL;
202 /* parse an afpd.conf line. i'm doing it this way because it's
203 * easy. it is, however, massively hokey. sample afpd.conf:
204 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
205 * "private machine"@zone2 -noguest -port 11012
206 * server2 -nocleartxt -nodsi
208 * NOTE: this ignores unknown options
210 int afp_options_parseline(char *buf, struct afp_options *options)
215 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
216 options->server = opt;
219 if (strstr(buf, " -nodebug"))
220 options->flags &= ~OPTION_DEBUG;
222 if (strstr(buf, " -slp"))
223 options->flags &= ~OPTION_NOSLP;
226 if (strstr(buf, " -nozeroconf"))
227 options->flags |= OPTION_NOZEROCONF;
229 if (strstr(buf, " -nouservolfirst"))
230 options->flags &= ~OPTION_USERVOLFIRST;
231 if (strstr(buf, " -uservolfirst"))
232 options->flags |= OPTION_USERVOLFIRST;
233 if (strstr(buf, " -nouservol"))
234 options->flags |= OPTION_NOUSERVOL;
235 if (strstr(buf, " -uservol"))
236 options->flags &= ~OPTION_NOUSERVOL;
237 if (strstr(buf, " -proxy"))
238 options->flags |= OPTION_PROXY;
239 if (strstr(buf, " -noicon"))
240 options->flags &= ~OPTION_CUSTOMICON;
241 if (strstr(buf, " -icon"))
242 options->flags |= OPTION_CUSTOMICON;
243 if (strstr(buf, " -advertise_ssh"))
244 options->flags |= OPTION_ANNOUNCESSH;
245 if (strstr(buf, " -noacl2maccess"))
246 options->flags &= ~OPTION_ACL2MACCESS;
247 if (strstr(buf, " -keepsessions")) {
248 default_options.flags |= OPTION_KEEPSESSIONS;
249 options->flags |= OPTION_KEEPSESSIONS;
253 if (strstr(buf, " -nosavepassword"))
254 options->passwdbits |= PASSWD_NOSAVE;
255 if (strstr(buf, " -savepassword"))
256 options->passwdbits &= ~PASSWD_NOSAVE;
257 if (strstr(buf, " -nosetpassword"))
258 options->passwdbits &= ~PASSWD_SET;
259 if (strstr(buf, " -setpassword"))
260 options->passwdbits |= PASSWD_SET;
263 if (strstr(buf, " -transall"))
264 options->transports = AFPTRANS_ALL;
265 if (strstr(buf, " -notransall"))
266 options->transports = AFPTRANS_NONE;
267 if (strstr(buf, " -tcp"))
268 options->transports |= AFPTRANS_TCP;
269 if (strstr(buf, " -notcp"))
270 options->transports &= ~AFPTRANS_TCP;
271 if (strstr(buf, " -ddp"))
272 options->transports |= AFPTRANS_DDP;
273 if (strstr(buf, " -noddp"))
274 options->transports &= ~AFPTRANS_DDP;
275 if (strstr(buf, "-client_polling"))
276 options->server_notif = 0;
278 /* figure out options w/ values. currently, this will ignore the setting
279 * if memory is lacking. */
281 if ((c = getoption(buf, "-hostname"))) {
282 int len = strlen (c);
283 if (len <= MAXHOSTNAMELEN) {
284 memcpy(options->hostname, c, len);
285 options->hostname[len] = 0;
288 LOG(log_info, logtype_afpd, "WARNING: hostname %s is too long (%d)",c,len);
291 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
292 options->defaultvol.name = opt;
293 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
294 options->systemvol.name = opt;
295 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c))) {
308 options->loginmesg = opt;
311 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
312 options->guest = opt;
313 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
314 options->passwdfile = opt;
315 if ((c = getoption(buf, "-passwdminlen")))
316 options->passwdminlen = MIN(1, atoi(c));
317 if ((c = getoption(buf, "-loginmaxfail")))
318 options->loginmaxfail = atoi(c);
319 if ((c = getoption(buf, "-tickleval"))) {
320 options->tickleval = atoi(c);
321 if (options->tickleval <= 0) {
322 options->tickleval = 30;
325 if ((c = getoption(buf, "-timeout"))) {
326 options->timeout = atoi(c);
327 if (options->timeout <= 0) {
328 options->timeout = 4;
332 if ((c = getoption(buf, "-sleep"))) {
333 options->disconnected = options->sleep = atoi(c) * 120;
334 if (options->sleep <= 4) {
335 options->disconnected = options->sleep = 4;
339 if ((c = getoption(buf, "-dsireadbuf"))) {
340 options->dsireadbuf = atoi(c);
341 if (options->dsireadbuf < 6)
342 options->dsireadbuf = 6;
345 if ((c = getoption(buf, "-server_quantum")))
346 options->server_quantum = strtoul(c, NULL, 0);
348 if ((c = getoption(buf, "-volnamelen"))) {
349 options->volnamelen = atoi(c);
350 if (options->volnamelen < 8) {
351 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
353 if (options->volnamelen > 255) {
354 options->volnamelen = 255; /* AFP3 spec */
358 /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
360 /* Now THIS is hokey! Multiple occurrences are not supported by our current code, */
361 /* so I have to loop myself. */
362 while (NULL != (c = strstr(c, "-setuplog"))) {
364 if ((optstr = getoption(c, "-setuplog"))) {
365 /* hokey2: options->logconfig must be converted to store an array of logstrings */
366 if (options->logconfig)
367 free(options->logconfig);
368 options->logconfig = strdup(optstr);
370 c += sizeof("-setuplog");
374 if ((c = getoption(buf, "-unsetuplog")))
378 if ((c = getoption(buf, "-admingroup"))) {
379 struct group *gr = getgrnam(c);
381 options->admingid = gr->gr_gid;
384 #endif /* ADMIN_GRP */
386 if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
387 options->k5service = opt;
388 if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
389 options->k5realm = opt;
390 if ((c = getoption(buf, "-k5keytab"))) {
391 if ( NULL == (options->k5keytab = (char *) malloc(sizeof(char)*(strlen(c)+14)) )) {
392 LOG(log_error, logtype_afpd, "malloc failed");
395 snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
396 putenv(options->k5keytab);
397 /* setenv( "KRB5_KTNAME", c, 1 ); */
399 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
400 options->authprintdir = opt;
401 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
402 options->uampath = opt;
403 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
404 options->uamlist = opt;
406 if ((c = getoption(buf, "-ipaddr"))) {
408 struct in_addr inaddr;
409 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
410 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
411 LOG(log_info, logtype_afpd, "WARNING: can't find %s", opt);
412 options->ipaddr = opt;
415 LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
418 options->ipaddr = strdup(c);
421 /* FIXME CNID Cnid_srv is a server attribute */
422 if ((c = getoption(buf, "-cnidserver"))) {
423 char *p = strrchr(c, ':');
426 Cnid_srv = strdup(c);
428 Cnid_port = strdup(p + 1);
429 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
432 if ((c = getoption(buf, "-port")))
433 options->port = strdup(c);
435 if ((c = getoption(buf, "-ddpaddr")))
436 atalk_aton(c, &options->ddpaddr);
438 if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
439 options->signatureopt = opt;
441 /* do a little checking for the domain name. */
442 if ((c = getoption(buf, "-fqdn"))) {
443 char *p = strchr(c, ':');
446 if (gethostbyname(c)) {
449 if ((opt = strdup(c)))
453 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
457 if ((c = getoption(buf, "-unixcodepage"))) {
458 if ((charset_t)-1 == ( options->unixcharset = add_charset(c)) ) {
459 options->unixcharset = CH_UNIX;
460 LOG(log_warning, logtype_afpd, "setting Unix codepage to '%s' failed", c);
463 if ((opt = strdup(c)))
464 options->unixcodepage = opt;
468 if ((c = getoption(buf, "-maccodepage"))) {
469 if ((charset_t)-1 == ( options->maccharset = add_charset(c)) ) {
470 options->maccharset = CH_MAC;
471 LOG(log_warning, logtype_afpd, "setting Mac codepage to '%s' failed", c);
474 if ((opt = strdup(c)))
475 options->maccodepage = opt;
479 if ((c = strstr(buf, "-closevol"))) {
480 options->closevol= 1;
483 if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
484 options->ntdomain = opt;
486 if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
487 options->ntseparator = opt;
489 if ((c = getoption(buf, "-dircachesize")))
490 options->dircachesize = atoi(c);
492 if ((c = getoption(buf, "-tcpsndbuf")))
493 options->tcp_sndbuf = atoi(c);
495 if ((c = getoption(buf, "-tcprcvbuf")))
496 options->tcp_rcvbuf = atoi(c);
498 if ((c = getoption(buf, "-fcelistener"))) {
499 LOG(log_note, logtype_afpd, "Adding fce listener \"%s\"", c);
500 fce_add_udp_socket(c);
502 if ((c = getoption(buf, "-fcecoalesce"))) {
503 LOG(log_note, logtype_afpd, "Fce coalesce: %s", c);
506 if ((c = getoption(buf, "-fceevents"))) {
507 LOG(log_note, logtype_afpd, "Fce events: %s", c);
511 if ((c = getoption(buf, "-fceholdfmod")))
512 options->fce_fmodwait = atoi(c);
514 if ((c = getoption(buf, "-mimicmodel")) && (opt = strdup(c)))
515 options->mimicmodel = opt;
517 if ((c = getoption(buf, "-adminauthuser")) && (opt = strdup(c)))
518 options->adminauthuser = opt;
524 * Show version information about afpd.
527 static void show_version( void )
531 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
533 puts( "This program is free software; you can redistribute it and/or modify it under" );
534 puts( "the terms of the GNU General Public License as published by the Free Software" );
535 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
536 puts( "version. Please see the file COPYING for further information and details.\n" );
538 puts( "afpd has been compiled with support for these features:\n" );
540 num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
541 printf( " AFP versions:\t" );
542 for ( i = 0; i < num; i++ ) {
543 printf( "%d.%d ", afp_versions[ i ].av_number/10, afp_versions[ i ].av_number%10);
547 printf( "DDP(AppleTalk) Support:\t" );
554 printf( " CNID backends:\t" );
555 #ifdef CNID_BACKEND_CDB
558 #ifdef CNID_BACKEND_DB3
561 #ifdef CNID_BACKEND_DBD
562 #ifdef CNID_BACKEND_DBD_TXN
563 printf( "dbd-txn " );
568 #ifdef CNID_BACKEND_HASH
571 #ifdef CNID_BACKEND_LAST
574 #ifdef CNID_BACKEND_MTAB
577 #ifdef CNID_BACKEND_TDB
584 * Show extended version information about afpd and Netatalk.
587 static void show_version_extended(void )
591 printf( " SLP support:\t" );
598 printf( " Zeroconf support:\t" );
605 printf( " TCP wrappers support:\t" );
612 printf( " Quota support:\t" );
613 #ifndef NO_QUOTA_SUPPORT
619 printf( " Admin group support:\t" );
626 printf( " Valid shell checks:\t" );
627 #ifndef DISABLE_SHELLCHECK
633 printf( " cracklib support:\t" );
640 printf( " Dropbox kludge:\t" );
647 printf( " Force volume uid/gid:\t" );
654 printf( " ACL support:\t" );
661 printf( " EA support:\t" );
664 printf( " LDAP support:\t" );
673 * Display compiled-in default paths
675 static void show_paths( void )
677 printf( " afpd.conf:\t%s\n", _PATH_AFPDCONF );
678 printf( " AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
679 printf( " AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
680 printf( " afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
681 printf( " afp_voluuid.conf:\t%s\n", _PATH_AFPDUUIDCONF );
683 printf( " afp_ldap.conf:\t%s\n", _PATH_ACL_LDAPCONF );
685 printf( " afp_ldap.conf:\tnot supported\n");
687 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
688 printf( " Server messages path:\t%s\n", SERVERTEXT);
689 printf( " lockfile:\t%s\n", _PATH_AFPDLOCK);
693 * Display usage information about afpd.
695 static void show_usage( char *name )
697 fprintf( stderr, "Usage:\t%s [-duptDTI] [-f defaultvolumes] [-s systemvolumes] [-n nbpname]\n", name );
698 fprintf( stderr, "\t [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
699 fprintf( stderr, "\t [-F configfile] [-U uams] [-m umask]\n" );
700 fprintf( stderr, "\t%s -h|-v|-V\n", name );
703 int afp_options_parse(int ac, char **av, struct afp_options *options)
709 char *tmp; /* Used for error checking the result of strtol */
712 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
713 perror( "gethostname" );
716 if (NULL != ( p = strchr(options->hostname, '.' )) ) {
721 if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
726 openlog( p, LOG_PID ); /* ultrix only */
729 while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
732 options->flags |= OPTION_DEBUG;
735 options->server = optarg;
738 options->defaultvol.name = optarg;
741 options->systemvol.name = optarg;
744 options->flags |= OPTION_USERVOLFIRST;
747 options->connections = atoi( optarg );
750 options->guest = optarg;
754 options->pidfile = optarg;
758 options->passwdbits |= PASSWD_NOSAVE;
761 options->passwdbits |= PASSWD_SET;
765 options->transports &= ~AFPTRANS_DDP;
768 options->port = optarg;
771 options->transports &= ~AFPTRANS_TCP;
774 options->loginmesg = optarg;
777 options->configfile = optarg;
780 options->uamlist = optarg;
782 case 'v': /* version */
783 show_version( ); puts( "" );
784 show_paths( ); puts( "" );
787 case 'V': /* extended version */
788 show_version_extended( ); puts( "" );
789 show_paths( ); puts( "" );
792 case 'h': /* usage */
797 options->flags |= OPTION_CUSTOMICON;
800 options->umask = strtoul(optarg, &tmp, 8);
801 if ((options->umask > 0777)) {
802 fprintf(stderr, "%s: out of range umask setting provided\n", p);
805 if (tmp[0] != '\0') {
806 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
814 if ( err || optind != ac ) {