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>
44 #define MIN(a, b) ((a) < (b) ? (a) : (b))
48 const char *Cnid_srv = "localhost";
49 const char *Cnid_port = "4700";
51 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:hIvVm:"
54 /* return an option. this uses an internal array, so it's necessary
55 * to duplicate it if you want to hold it for long. this is probably
57 static char *getoption(char *buf, const char *option)
59 static char string[LENGTH + 1];
63 if (option && (buf = strstr(buf, option)))
64 buf = strpbrk(buf, " \t");
66 while (buf && isspace(*buf))
72 /* search for any quoted stuff */
73 if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
75 len = MIN(end - buf, LENGTH);
76 } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
77 len = MIN(end - buf, LENGTH);
79 len = MIN(strlen(buf), LENGTH);
81 strncpy(string, buf, len);
86 /* get rid of any allocated afp_option buffers. */
87 void afp_options_free(struct afp_options *opt,
88 const struct afp_options *save)
90 if (opt->defaultvol.name && (opt->defaultvol.name != save->defaultvol.name))
91 free(opt->defaultvol.name);
92 if (opt->defaultvol.full_name && (opt->defaultvol.full_name != save->defaultvol.full_name))
93 free(opt->defaultvol.full_name);
95 if (opt->systemvol.name && (opt->systemvol.name != save->systemvol.name))
96 free(opt->systemvol.name);
97 if (opt->systemvol.full_name && (opt->systemvol.full_name != save->systemvol.full_name))
98 free(opt->systemvol.full_name);
100 if (opt->uservol.name && (opt->uservol.name != save->uservol.name))
101 free(opt->uservol.name);
102 if (opt->uservol.full_name && (opt->uservol.full_name != save->uservol.full_name))
103 free(opt->uservol.full_name);
105 if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
106 free(opt->loginmesg);
107 if (opt->guest && (opt->guest != save->guest))
109 if (opt->server && (opt->server != save->server))
111 if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
113 if (opt->port && (opt->port != save->port))
115 if (opt->fqdn && (opt->fqdn != save->fqdn))
117 if (opt->uampath && (opt->uampath != save->uampath))
119 if (opt->uamlist && (opt->uamlist != save->uamlist))
121 if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
122 free(opt->passwdfile);
123 if (opt->signatureopt && (opt->signatureopt != save->signatureopt))
124 free(opt->signatureopt);
125 if (opt->k5service && (opt->k5service != save->k5service))
126 free(opt->k5service);
127 if (opt->k5realm && (opt->k5realm != save->k5realm))
129 if (opt->k5keytab && (opt->k5keytab != save->k5keytab))
131 if (opt->unixcodepage && (opt->unixcodepage != save->unixcodepage))
132 free(opt->unixcodepage);
133 if (opt->maccodepage && (opt->maccodepage != save->maccodepage))
134 free(opt->maccodepage);
136 if (opt->ntdomain && (opt->ntdomain != save->ntdomain))
138 if (opt->ntseparator && (opt->ntseparator != save->ntseparator))
139 free(opt->ntseparator);
140 if (opt->logconfig && (opt->logconfig != save->logconfig))
141 free(opt->logconfig);
144 /* initialize options */
145 void afp_options_init(struct afp_options *options)
147 memset(options, 0, sizeof(struct afp_options));
148 options->connections = 20;
149 options->pidfile = _PATH_AFPDLOCK;
150 options->defaultvol.name = _PATH_AFPDDEFVOL;
151 options->systemvol.name = _PATH_AFPDSYSVOL;
152 options->configfile = _PATH_AFPDCONF;
153 options->sigconffile = _PATH_AFPDSIGCONF;
154 options->uuidconf = _PATH_AFPDUUIDCONF;
155 options->uampath = _PATH_AFPDUAMPATH;
156 options->uamlist = "uams_dhx.so,uams_dhx2.so";
157 options->guest = "nobody";
158 options->loginmesg = "";
159 options->transports = AFPTRANS_TCP; /* TCP only */
160 options->passwdfile = _PATH_AFPDPWFILE;
161 options->tickleval = 30;
162 options->timeout = 4;
163 options->sleep = 10* 120; /* 10 h in 30 seconds tick */
164 options->server_notif = 1;
165 options->authprintdir = NULL;
166 options->signatureopt = "auto";
169 options->admingid = 0;
170 #endif /* ADMIN_GRP */
171 options->k5service = NULL;
172 options->k5realm = NULL;
173 options->k5keytab = NULL;
174 options->unixcharset = CH_UNIX;
175 options->unixcodepage = "LOCALE";
176 options->maccharset = CH_MAC;
177 options->maccodepage = "MAC_ROMAN";
178 options->volnamelen = 80; /* spec: 255, 10.1: 73, 10.4/10.5: 80 */
179 options->ntdomain = NULL;
180 options->ntseparator = NULL;
182 /* don't advertize slp by default */
183 options->flags |= OPTION_NOSLP;
185 options->dircachesize = DEFAULT_MAX_DIRCACHE_SIZE;
186 options->flags |= OPTION_ACL2MACCESS;
187 options->flags |= OPTION_UUID;
190 /* parse an afpd.conf line. i'm doing it this way because it's
191 * easy. it is, however, massively hokey. sample afpd.conf:
192 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
193 * "private machine"@zone2 -noguest -port 11012
194 * server2 -nocleartxt -nodsi
196 * NOTE: this ignores unknown options
198 int afp_options_parseline(char *buf, struct afp_options *options)
203 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
204 options->server = opt;
207 if (strstr(buf, " -nodebug"))
208 options->flags &= ~OPTION_DEBUG;
210 if (strstr(buf, " -slp"))
211 options->flags &= ~OPTION_NOSLP;
214 if (strstr(buf, " -nozeroconf"))
215 options->flags |= OPTION_NOZEROCONF;
217 if (strstr(buf, " -nouservolfirst"))
218 options->flags &= ~OPTION_USERVOLFIRST;
219 if (strstr(buf, " -uservolfirst"))
220 options->flags |= OPTION_USERVOLFIRST;
221 if (strstr(buf, " -nouservol"))
222 options->flags |= OPTION_NOUSERVOL;
223 if (strstr(buf, " -uservol"))
224 options->flags &= ~OPTION_NOUSERVOL;
225 if (strstr(buf, " -proxy"))
226 options->flags |= OPTION_PROXY;
227 if (strstr(buf, " -noicon"))
228 options->flags &= ~OPTION_CUSTOMICON;
229 if (strstr(buf, " -icon"))
230 options->flags |= OPTION_CUSTOMICON;
231 if (strstr(buf, " -advertise_ssh"))
232 options->flags |= OPTION_ANNOUNCESSH;
233 if (strstr(buf, " -noacl2maccess"))
234 options->flags &= ~OPTION_ACL2MACCESS;
235 if ((c = getoption(buf, "-searchtype"))) {
236 if (strcmp(c, "db") == 0)
237 options->flags |= OPTION_CATSEARCH_DB;
241 if (strstr(buf, " -nosavepassword"))
242 options->passwdbits |= PASSWD_NOSAVE;
243 if (strstr(buf, " -savepassword"))
244 options->passwdbits &= ~PASSWD_NOSAVE;
245 if (strstr(buf, " -nosetpassword"))
246 options->passwdbits &= ~PASSWD_SET;
247 if (strstr(buf, " -setpassword"))
248 options->passwdbits |= PASSWD_SET;
251 if (strstr(buf, " -transall"))
252 options->transports = AFPTRANS_ALL;
253 if (strstr(buf, " -notransall"))
254 options->transports = AFPTRANS_NONE;
255 if (strstr(buf, " -tcp"))
256 options->transports |= AFPTRANS_TCP;
257 if (strstr(buf, " -notcp"))
258 options->transports &= ~AFPTRANS_TCP;
259 if (strstr(buf, " -ddp"))
260 options->transports |= AFPTRANS_DDP;
261 if (strstr(buf, " -noddp"))
262 options->transports &= ~AFPTRANS_DDP;
263 if (strstr(buf, "-client_polling"))
264 options->server_notif = 0;
266 /* figure out options w/ values. currently, this will ignore the setting
267 * if memory is lacking. */
269 if ((c = getoption(buf, "-hostname"))) {
270 int len = strlen (c);
271 if (len <= MAXHOSTNAMELEN) {
272 memcpy(options->hostname, c, len);
273 options->hostname[len] = 0;
276 LOG(log_info, logtype_afpd, "WARNING: hostname %s is too long (%d)",c,len);
279 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
280 options->defaultvol.name = opt;
281 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
282 options->systemvol.name = opt;
283 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c))) {
296 options->loginmesg = opt;
299 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
300 options->guest = opt;
301 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
302 options->passwdfile = opt;
303 if ((c = getoption(buf, "-passwdminlen")))
304 options->passwdminlen = MIN(1, atoi(c));
305 if ((c = getoption(buf, "-loginmaxfail")))
306 options->loginmaxfail = atoi(c);
307 if ((c = getoption(buf, "-tickleval"))) {
308 options->tickleval = atoi(c);
309 if (options->tickleval <= 0) {
310 options->tickleval = 30;
313 if ((c = getoption(buf, "-timeout"))) {
314 options->timeout = atoi(c);
315 if (options->timeout <= 0) {
316 options->timeout = 4;
320 if ((c = getoption(buf, "-sleep"))) {
321 options->sleep = atoi(c) *120;
322 if (options->sleep <= 4) {
327 if ((c = getoption(buf, "-server_quantum")))
328 options->server_quantum = strtoul(c, NULL, 0);
330 if ((c = getoption(buf, "-volnamelen"))) {
331 options->volnamelen = atoi(c);
332 if (options->volnamelen < 8) {
333 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
335 if (options->volnamelen > 255) {
336 options->volnamelen = 255; /* AFP3 spec */
340 /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
342 /* Now THIS is hokey! Multiple occurrences are not supported by our current code, */
343 /* so I have to loop myself. */
344 while (NULL != (c = strstr(c, "-setuplog"))) {
346 if ((optstr = getoption(c, "-setuplog"))) {
348 options->logconfig = optstr; /* at least store the last (possibly only) one */
349 c += sizeof("-setuplog");
353 if ((c = getoption(buf, "-unsetuplog")))
357 if ((c = getoption(buf, "-admingroup"))) {
358 struct group *gr = getgrnam(c);
360 options->admingid = gr->gr_gid;
363 #endif /* ADMIN_GRP */
365 if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
366 options->k5service = opt;
367 if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
368 options->k5realm = opt;
369 if ((c = getoption(buf, "-k5keytab"))) {
370 if ( NULL == (options->k5keytab = (char *) malloc(sizeof(char)*(strlen(c)+14)) )) {
371 LOG(log_error, logtype_afpd, "malloc failed");
374 snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
375 putenv(options->k5keytab);
376 /* setenv( "KRB5_KTNAME", c, 1 ); */
378 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
379 options->authprintdir = opt;
380 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
381 options->uampath = opt;
382 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
383 options->uamlist = opt;
385 if ((c = getoption(buf, "-ipaddr"))) {
387 struct in_addr inaddr;
388 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
389 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
390 LOG(log_info, logtype_afpd, "WARNING: can't find %s", opt);
391 options->ipaddr = opt;
394 LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
397 options->ipaddr = strdup(c);
400 /* FIXME CNID Cnid_srv is a server attribute */
401 if ((c = getoption(buf, "-cnidserver"))) {
402 char *p = strrchr(c, ':');
405 Cnid_srv = strdup(c);
407 Cnid_port = strdup(p + 1);
408 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
411 if ((c = getoption(buf, "-port")))
412 options->port = strdup(c);
413 if ((c = getoption(buf, "-ddpaddr")))
414 atalk_aton(c, &options->ddpaddr);
415 if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
416 options->signatureopt = opt;
418 /* do a little checking for the domain name. */
419 if ((c = getoption(buf, "-fqdn"))) {
420 char *p = strchr(c, ':');
423 if (gethostbyname(c)) {
426 if ((opt = strdup(c)))
430 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
434 if ((c = getoption(buf, "-unixcodepage"))) {
435 if ((charset_t)-1 == ( options->unixcharset = add_charset(c)) ) {
436 options->unixcharset = CH_UNIX;
437 LOG(log_warning, logtype_afpd, "setting Unix codepage to '%s' failed", c);
440 if ((opt = strdup(c)))
441 options->unixcodepage = opt;
445 if ((c = getoption(buf, "-maccodepage"))) {
446 if ((charset_t)-1 == ( options->maccharset = add_charset(c)) ) {
447 options->maccharset = CH_MAC;
448 LOG(log_warning, logtype_afpd, "setting Mac codepage to '%s' failed", c);
451 if ((opt = strdup(c)))
452 options->maccodepage = opt;
456 if ((c = strstr(buf, "-closevol"))) {
457 options->closevol= 1;
460 if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
461 options->ntdomain = opt;
463 if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
464 options->ntseparator = opt;
466 if ((c = getoption(buf, "-dircachesize")))
467 options->dircachesize = atoi(c);
473 * Show version information about afpd.
476 static void show_version( void )
478 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
480 puts( "This program is free software; you can redistribute it and/or modify it under" );
481 puts( "the terms of the GNU General Public License as published by the Free Software" );
482 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
483 puts( "version. Please see the file COPYING for further information and details.\n" );
485 puts( "afpd has been compiled with support for these features:\n" );
487 printf( " AFP3.x support:\t" );
494 printf( " TCP/IP Support:\t" );
497 printf( "DDP(AppleTalk) Support:\t" );
504 printf( " CNID backends:\t" );
505 #ifdef CNID_BACKEND_CDB
508 #ifdef CNID_BACKEND_DB3
511 #ifdef CNID_BACKEND_DBD
512 #ifdef CNID_BACKEND_DBD_TXN
513 printf( "dbd-txn " );
518 #ifdef CNID_BACKEND_HASH
521 #ifdef CNID_BACKEND_LAST
524 #ifdef CNID_BACKEND_MTAB
527 #ifdef CNID_BACKEND_TDB
534 * Show extended version information about afpd and Netatalk.
537 static void show_version_extended(void )
541 printf( " SLP support:\t" );
548 printf( " Zeroconf support:\t" );
555 printf( " TCP wrappers support:\t" );
562 printf( " Quota support:\t" );
563 #ifndef NO_QUOTA_SUPPORT
569 printf( " Admin group support:\t" );
576 printf( " Valid shell checks:\t" );
577 #ifndef DISABLE_SHELLCHECK
583 printf( " cracklib support:\t" );
590 printf( " Dropbox kludge:\t" );
597 printf( " Force volume uid/gid:\t" );
604 printf( " ACL support:\t" );
611 printf( " EA support:\t" );
614 printf( " LDAP support:\t" );
623 * Display compiled-in default paths
625 static void show_paths( void )
627 printf( " afpd.conf:\t%s\n", _PATH_AFPDCONF );
628 printf( " afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
629 printf( " AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
630 printf( " AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
631 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
632 printf( " Server messages path:\t%s\n", SERVERTEXT);
636 * Display usage information about afpd.
638 static void show_usage( char *name )
640 fprintf( stderr, "Usage:\t%s [-duptDTI] [-f defaultvolumes] [-s systemvolumes] [-n nbpname]\n", name );
641 fprintf( stderr, "\t [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
642 fprintf( stderr, "\t [-F configfile] [-U uams] [-m umask]\n" );
643 fprintf( stderr, "\t%s -h|-v|-V\n", name );
646 int afp_options_parse(int ac, char **av, struct afp_options *options)
652 char *tmp; /* Used for error checking the result of strtol */
655 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
656 perror( "gethostname" );
659 if (NULL != ( p = strchr(options->hostname, '.' )) ) {
663 if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
669 while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
672 options->flags |= OPTION_DEBUG;
675 options->server = optarg;
678 options->defaultvol.name = optarg;
681 options->systemvol.name = optarg;
684 options->flags |= OPTION_USERVOLFIRST;
687 options->connections = atoi( optarg );
690 options->guest = optarg;
694 options->pidfile = optarg;
698 options->passwdbits |= PASSWD_NOSAVE;
701 options->passwdbits |= PASSWD_SET;
705 options->transports &= ~AFPTRANS_DDP;
708 options->port = optarg;
711 options->transports &= ~AFPTRANS_TCP;
714 options->loginmesg = optarg;
717 options->configfile = optarg;
720 options->uamlist = optarg;
722 case 'v': /* version */
723 show_version( ); puts( "" );
724 show_paths( ); puts( "" );
727 case 'V': /* extended version */
728 show_version_extended( ); puts( "" );
729 show_paths( ); puts( "" );
732 case 'h': /* usage */
737 options->flags |= OPTION_CUSTOMICON;
740 options->umask = strtoul(optarg, &tmp, 8);
741 if ((options->umask > 0777)) {
742 fprintf(stderr, "%s: out of range umask setting provided\n", p);
745 if (tmp[0] != '\0') {
746 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
754 if ( err || optind != ac ) {
760 openlog( p, LOG_PID ); /* ultrix only */