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 */
19 #else /* STDC_HEADERS */
23 #endif /* HAVE_STRCHR */
24 char *strchr (), *strrchr ();
26 #define memcpy(d,s,n) bcopy ((s), (d), (n))
27 #define memmove(d,s,n) bcopy ((s), (d), (n))
28 #endif /* ! HAVE_MEMCPY */
29 #endif /* STDC_HEADERS */
34 #endif /* HAVE_UNISTD_H */
35 #include <sys/param.h>
36 #include <sys/socket.h>
37 #include <atalk/logger.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
43 #endif /* HAVE_NETDB_H */
45 #include <atalk/paths.h>
46 #include <atalk/util.h>
52 #include <atalk/compat.h>
56 #include <sys/types.h>
57 #endif /* ADMIN_GRP */
60 #define MIN(a, b) ((a) < (b) ? (a) : (b))
64 const char *Cnid_srv = "localhost";
65 const char *Cnid_port = "4700";
67 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:hIvVm:"
70 /* return an option. this uses an internal array, so it's necessary
71 * to duplicate it if you want to hold it for long. this is probably
73 static char *getoption(char *buf, const char *option)
75 static char string[LENGTH + 1];
79 if (option && (buf = strstr(buf, option)))
80 buf = strpbrk(buf, " \t");
82 while (buf && isspace(*buf))
88 /* search for any quoted stuff */
89 if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
91 len = MIN(end - buf, LENGTH);
92 } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
93 len = MIN(end - buf, LENGTH);
95 len = MIN(strlen(buf), LENGTH);
97 strncpy(string, buf, len);
102 /* get rid of any allocated afp_option buffers. */
103 void afp_options_free(struct afp_options *opt,
104 const struct afp_options *save)
106 if (opt->defaultvol.name && (opt->defaultvol.name != save->defaultvol.name))
107 free(opt->defaultvol.name);
108 if (opt->defaultvol.full_name && (opt->defaultvol.full_name != save->defaultvol.full_name))
109 free(opt->defaultvol.full_name);
111 if (opt->systemvol.name && (opt->systemvol.name != save->systemvol.name))
112 free(opt->systemvol.name);
113 if (opt->systemvol.full_name && (opt->systemvol.full_name != save->systemvol.full_name))
114 free(opt->systemvol.full_name);
116 if (opt->uservol.name && (opt->uservol.name != save->uservol.name))
117 free(opt->uservol.name);
118 if (opt->uservol.full_name && (opt->uservol.full_name != save->uservol.full_name))
119 free(opt->uservol.full_name);
121 if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
122 free(opt->loginmesg);
123 if (opt->guest && (opt->guest != save->guest))
125 if (opt->server && (opt->server != save->server))
127 if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
129 if (opt->port && (opt->port != save->port))
131 if (opt->fqdn && (opt->fqdn != save->fqdn))
133 if (opt->uampath && (opt->uampath != save->uampath))
135 if (opt->uamlist && (opt->uamlist != save->uamlist))
137 if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
138 free(opt->passwdfile);
139 if (opt->signatureopt && (opt->signatureopt != save->signatureopt))
140 free(opt->signatureopt);
141 if (opt->k5service && (opt->k5service != save->k5service))
142 free(opt->k5service);
143 if (opt->k5realm && (opt->k5realm != save->k5realm))
145 if (opt->k5keytab && (opt->k5keytab != save->k5keytab))
147 if (opt->unixcodepage && (opt->unixcodepage != save->unixcodepage))
148 free(opt->unixcodepage);
149 if (opt->maccodepage && (opt->maccodepage != save->maccodepage))
150 free(opt->maccodepage);
152 if (opt->ntdomain && (opt->ntdomain != save->ntdomain))
154 if (opt->ntseparator && (opt->ntseparator != save->ntseparator))
155 free(opt->ntseparator);
156 if (opt->logconfig && (opt->logconfig != save->logconfig))
157 free(opt->logconfig);
160 /* initialize options */
161 void afp_options_init(struct afp_options *options)
163 memset(options, 0, sizeof(struct afp_options));
164 options->connections = 20;
165 options->pidfile = _PATH_AFPDLOCK;
166 options->defaultvol.name = _PATH_AFPDDEFVOL;
167 options->systemvol.name = _PATH_AFPDSYSVOL;
168 options->configfile = _PATH_AFPDCONF;
169 options->sigconffile = _PATH_AFPDSIGCONF;
170 options->uuidconf = _PATH_AFPDUUIDCONF;
171 options->uampath = _PATH_AFPDUAMPATH;
172 options->uamlist = "uams_dhx.so,uams_dhx2.so";
173 options->guest = "nobody";
174 options->loginmesg = "";
175 options->transports = AFPTRANS_TCP; /* TCP only */
176 options->passwdfile = _PATH_AFPDPWFILE;
177 options->tickleval = 30;
178 options->timeout = 4;
179 options->sleep = 10* 120; /* 10 h in 30 seconds tick */
180 options->server_notif = 1;
181 options->authprintdir = NULL;
182 options->signatureopt = "auto";
185 options->admingid = 0;
186 #endif /* ADMIN_GRP */
187 options->k5service = NULL;
188 options->k5realm = NULL;
189 options->k5keytab = NULL;
190 options->unixcharset = CH_UNIX;
191 options->unixcodepage = "LOCALE";
192 options->maccharset = CH_MAC;
193 options->maccodepage = "MAC_ROMAN";
194 options->volnamelen = 80; /* spec: 255, 10.1: 73, 10.4/10.5: 80 */
195 options->ntdomain = NULL;
196 options->ntseparator = NULL;
198 /* don't advertize slp by default */
199 options->flags |= OPTION_NOSLP;
201 options->dircachesize = DEFAULT_MAX_DIRCACHE_SIZE;
202 options->flags |= OPTION_ACL2MACCESS;
203 options->flags |= OPTION_UUID; /* gets disabled if LDAP isn't configured */
206 /* parse an afpd.conf line. i'm doing it this way because it's
207 * easy. it is, however, massively hokey. sample afpd.conf:
208 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
209 * "private machine"@zone2 -noguest -port 11012
210 * server2 -nocleartxt -nodsi
212 * NOTE: this ignores unknown options
214 int afp_options_parseline(char *buf, struct afp_options *options)
219 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
220 options->server = opt;
223 if (strstr(buf, " -nodebug"))
224 options->flags &= ~OPTION_DEBUG;
226 if (strstr(buf, " -slp"))
227 options->flags &= ~OPTION_NOSLP;
230 if (strstr(buf, " -nozeroconf"))
231 options->flags |= OPTION_NOZEROCONF;
233 if (strstr(buf, " -nouservolfirst"))
234 options->flags &= ~OPTION_USERVOLFIRST;
235 if (strstr(buf, " -uservolfirst"))
236 options->flags |= OPTION_USERVOLFIRST;
237 if (strstr(buf, " -nouservol"))
238 options->flags |= OPTION_NOUSERVOL;
239 if (strstr(buf, " -uservol"))
240 options->flags &= ~OPTION_NOUSERVOL;
241 if (strstr(buf, " -proxy"))
242 options->flags |= OPTION_PROXY;
243 if (strstr(buf, " -noicon"))
244 options->flags &= ~OPTION_CUSTOMICON;
245 if (strstr(buf, " -icon"))
246 options->flags |= OPTION_CUSTOMICON;
247 if (strstr(buf, " -advertise_ssh"))
248 options->flags |= OPTION_ANNOUNCESSH;
249 if (strstr(buf, " -noacl2maccess"))
250 options->flags &= ~OPTION_ACL2MACCESS;
251 if (strstr(buf, " -nouuid"))
252 options->flags &= ~OPTION_UUID
255 if (strstr(buf, " -nosavepassword"))
256 options->passwdbits |= PASSWD_NOSAVE;
257 if (strstr(buf, " -savepassword"))
258 options->passwdbits &= ~PASSWD_NOSAVE;
259 if (strstr(buf, " -nosetpassword"))
260 options->passwdbits &= ~PASSWD_SET;
261 if (strstr(buf, " -setpassword"))
262 options->passwdbits |= PASSWD_SET;
265 if (strstr(buf, " -transall"))
266 options->transports = AFPTRANS_ALL;
267 if (strstr(buf, " -notransall"))
268 options->transports = AFPTRANS_NONE;
269 if (strstr(buf, " -tcp"))
270 options->transports |= AFPTRANS_TCP;
271 if (strstr(buf, " -notcp"))
272 options->transports &= ~AFPTRANS_TCP;
273 if (strstr(buf, " -ddp"))
274 options->transports |= AFPTRANS_DDP;
275 if (strstr(buf, " -noddp"))
276 options->transports &= ~AFPTRANS_DDP;
277 if (strstr(buf, "-client_polling"))
278 options->server_notif = 0;
280 /* figure out options w/ values. currently, this will ignore the setting
281 * if memory is lacking. */
283 if ((c = getoption(buf, "-hostname"))) {
284 int len = strlen (c);
285 if (len <= MAXHOSTNAMELEN) {
286 memcpy(options->hostname, c, len);
287 options->hostname[len] = 0;
290 LOG(log_info, logtype_afpd, "WARNING: hostname %s is too long (%d)",c,len);
293 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
294 options->defaultvol.name = opt;
295 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
296 options->systemvol.name = opt;
297 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c))) {
310 options->loginmesg = opt;
313 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
314 options->guest = opt;
315 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
316 options->passwdfile = opt;
317 if ((c = getoption(buf, "-passwdminlen")))
318 options->passwdminlen = MIN(1, atoi(c));
319 if ((c = getoption(buf, "-loginmaxfail")))
320 options->loginmaxfail = atoi(c);
321 if ((c = getoption(buf, "-tickleval"))) {
322 options->tickleval = atoi(c);
323 if (options->tickleval <= 0) {
324 options->tickleval = 30;
327 if ((c = getoption(buf, "-timeout"))) {
328 options->timeout = atoi(c);
329 if (options->timeout <= 0) {
330 options->timeout = 4;
334 if ((c = getoption(buf, "-sleep"))) {
335 options->sleep = atoi(c) *120;
336 if (options->sleep <= 4) {
341 if ((c = getoption(buf, "-server_quantum")))
342 options->server_quantum = strtoul(c, NULL, 0);
344 if ((c = getoption(buf, "-volnamelen"))) {
345 options->volnamelen = atoi(c);
346 if (options->volnamelen < 8) {
347 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
349 if (options->volnamelen > 255) {
350 options->volnamelen = 255; /* AFP3 spec */
354 /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
356 /* Now THIS is hokey! Multiple occurrences are not supported by our current code, */
357 /* so I have to loop myself. */
358 while (NULL != (c = strstr(c, "-setuplog"))) {
360 if ((optstr = getoption(c, "-setuplog"))) {
362 options->logconfig = optstr; /* at least store the last (possibly only) one */
363 c += sizeof("-setuplog");
367 if ((c = getoption(buf, "-unsetuplog")))
371 if ((c = getoption(buf, "-admingroup"))) {
372 struct group *gr = getgrnam(c);
374 options->admingid = gr->gr_gid;
377 #endif /* ADMIN_GRP */
379 if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
380 options->k5service = opt;
381 if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
382 options->k5realm = opt;
383 if ((c = getoption(buf, "-k5keytab"))) {
384 if ( NULL == (options->k5keytab = (char *) malloc(sizeof(char)*(strlen(c)+14)) )) {
385 LOG(log_error, logtype_afpd, "malloc failed");
388 snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
389 putenv(options->k5keytab);
390 /* setenv( "KRB5_KTNAME", c, 1 ); */
392 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
393 options->authprintdir = opt;
394 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
395 options->uampath = opt;
396 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
397 options->uamlist = opt;
399 if ((c = getoption(buf, "-ipaddr"))) {
401 struct in_addr inaddr;
402 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
403 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
404 LOG(log_info, logtype_afpd, "WARNING: can't find %s", opt);
405 options->ipaddr = opt;
408 LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
411 options->ipaddr = strdup(c);
414 /* FIXME CNID Cnid_srv is a server attribute */
415 if ((c = getoption(buf, "-cnidserver"))) {
416 char *p = strrchr(c, ':');
419 Cnid_srv = strdup(c);
421 Cnid_port = strdup(p + 1);
422 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
425 if ((c = getoption(buf, "-port")))
426 options->port = strdup(c);
427 if ((c = getoption(buf, "-ddpaddr")))
428 atalk_aton(c, &options->ddpaddr);
429 if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
430 options->signatureopt = opt;
432 /* do a little checking for the domain name. */
433 if ((c = getoption(buf, "-fqdn"))) {
434 char *p = strchr(c, ':');
437 if (gethostbyname(c)) {
440 if ((opt = strdup(c)))
444 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
448 if ((c = getoption(buf, "-unixcodepage"))) {
449 if ((charset_t)-1 == ( options->unixcharset = add_charset(c)) ) {
450 options->unixcharset = CH_UNIX;
451 LOG(log_warning, logtype_afpd, "setting Unix codepage to '%s' failed", c);
454 if ((opt = strdup(c)))
455 options->unixcodepage = opt;
459 if ((c = getoption(buf, "-maccodepage"))) {
460 if ((charset_t)-1 == ( options->maccharset = add_charset(c)) ) {
461 options->maccharset = CH_MAC;
462 LOG(log_warning, logtype_afpd, "setting Mac codepage to '%s' failed", c);
465 if ((opt = strdup(c)))
466 options->maccodepage = opt;
470 if ((c = strstr(buf, "-closevol"))) {
471 options->closevol= 1;
474 if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
475 options->ntdomain = opt;
477 if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
478 options->ntseparator = opt;
480 if ((c = getoption(buf, "-dircachesize")))
481 options->dircachesize = atoi(c);
487 * Show version information about afpd.
490 static void show_version( void )
492 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
494 puts( "This program is free software; you can redistribute it and/or modify it under" );
495 puts( "the terms of the GNU General Public License as published by the Free Software" );
496 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
497 puts( "version. Please see the file COPYING for further information and details.\n" );
499 puts( "afpd has been compiled with support for these features:\n" );
501 printf( " AFP3.x support:\t" );
508 printf( " TCP/IP Support:\t" );
511 printf( "DDP(AppleTalk) Support:\t" );
518 printf( " CNID backends:\t" );
519 #ifdef CNID_BACKEND_CDB
522 #ifdef CNID_BACKEND_DB3
525 #ifdef CNID_BACKEND_DBD
526 #ifdef CNID_BACKEND_DBD_TXN
527 printf( "dbd-txn " );
532 #ifdef CNID_BACKEND_HASH
535 #ifdef CNID_BACKEND_LAST
538 #ifdef CNID_BACKEND_MTAB
541 #ifdef CNID_BACKEND_TDB
548 * Show extended version information about afpd and Netatalk.
551 static void show_version_extended(void )
555 printf( " SLP support:\t" );
562 printf( " Zeroconf support:\t" );
569 printf( " TCP wrappers support:\t" );
576 printf( " Quota support:\t" );
577 #ifndef NO_QUOTA_SUPPORT
583 printf( " Admin group support:\t" );
590 printf( " Valid shell checks:\t" );
591 #ifndef DISABLE_SHELLCHECK
597 printf( " cracklib support:\t" );
604 printf( " Dropbox kludge:\t" );
611 printf( " Force volume uid/gid:\t" );
620 * Display compiled-in default paths
622 static void show_paths( void )
624 printf( " afpd.conf:\t%s\n", _PATH_AFPDCONF );
625 printf( " afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
626 printf( " AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
627 printf( " AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
628 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
629 printf( " Server messages path:\t%s\n", SERVERTEXT);
633 * Display usage information about afpd.
635 static void show_usage( char *name )
637 fprintf( stderr, "Usage:\t%s [-duptDTI] [-f defaultvolumes] [-s systemvolumes] [-n nbpname]\n", name );
638 fprintf( stderr, "\t [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
639 fprintf( stderr, "\t [-F configfile] [-U uams] [-m umask]\n" );
640 fprintf( stderr, "\t%s -h|-v|-V\n", name );
643 int afp_options_parse(int ac, char **av, struct afp_options *options)
649 char *tmp; /* Used for error checking the result of strtol */
652 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
653 perror( "gethostname" );
656 if (NULL != ( p = strchr(options->hostname, '.' )) ) {
660 if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
666 while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
669 options->flags |= OPTION_DEBUG;
672 options->server = optarg;
675 options->defaultvol.name = optarg;
678 options->systemvol.name = optarg;
681 options->flags |= OPTION_USERVOLFIRST;
684 options->connections = atoi( optarg );
687 options->guest = optarg;
691 options->pidfile = optarg;
695 options->passwdbits |= PASSWD_NOSAVE;
698 options->passwdbits |= PASSWD_SET;
702 options->transports &= ~AFPTRANS_DDP;
705 options->port = optarg;
708 options->transports &= ~AFPTRANS_TCP;
711 options->loginmesg = optarg;
714 options->configfile = optarg;
717 options->uamlist = optarg;
719 case 'v': /* version */
720 show_version( ); puts( "" );
721 show_paths( ); puts( "" );
724 case 'V': /* extended version */
725 show_version_extended( ); puts( "" );
726 show_paths( ); puts( "" );
729 case 'h': /* usage */
734 options->flags |= OPTION_CUSTOMICON;
737 options->umask = strtoul(optarg, &tmp, 8);
738 if ((options->umask > 0777)) {
739 fprintf(stderr, "%s: out of range umask setting provided\n", p);
742 if (tmp[0] != '\0') {
743 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
751 if ( err || optind != ac ) {
757 openlog( p, LOG_PID ); /* ultrix only */