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);
147 /* initialize options */
148 void afp_options_init(struct afp_options *options)
150 memset(options, 0, sizeof(struct afp_options));
151 options->connections = 20;
152 options->pidfile = _PATH_AFPDLOCK;
153 options->defaultvol.name = _PATH_AFPDDEFVOL;
154 options->systemvol.name = _PATH_AFPDSYSVOL;
155 options->configfile = _PATH_AFPDCONF;
156 options->sigconffile = _PATH_AFPDSIGCONF;
157 options->uuidconf = _PATH_AFPDUUIDCONF;
158 options->uampath = _PATH_AFPDUAMPATH;
159 options->uamlist = "uams_dhx.so,uams_dhx2.so";
160 options->guest = "nobody";
161 options->loginmesg = "";
162 options->transports = AFPTRANS_TCP; /* TCP only */
163 options->passwdfile = _PATH_AFPDPWFILE;
164 options->tickleval = 30;
165 options->timeout = 4; /* 4 tickles = 2 minutes */
166 options->sleep = 10 * 60 * 2; /* 10 h in 30 seconds tick */
167 options->disconnected = 10 * 60 * 2; /* 10 h in 30 seconds tick */
168 options->server_notif = 1;
169 options->authprintdir = NULL;
170 options->signatureopt = "auto";
173 options->admingid = 0;
174 #endif /* ADMIN_GRP */
175 options->k5service = NULL;
176 options->k5realm = NULL;
177 options->k5keytab = NULL;
178 options->unixcharset = CH_UNIX;
179 options->unixcodepage = "LOCALE";
180 options->maccharset = CH_MAC;
181 options->maccodepage = "MAC_ROMAN";
182 options->volnamelen = 80; /* spec: 255, 10.1: 73, 10.4/10.5: 80 */
183 options->ntdomain = NULL;
184 options->ntseparator = NULL;
186 /* don't advertize slp by default */
187 options->flags |= OPTION_NOSLP;
189 options->dircachesize = DEFAULT_MAX_DIRCACHE_SIZE;
190 options->flags |= OPTION_ACL2MACCESS;
191 options->flags |= OPTION_UUID;
192 options->tcp_sndbuf = 0; /* 0 means don't change OS default */
193 options->tcp_rcvbuf = 0; /* 0 means don't change OS default */
194 options->dsireadbuf = 12;
195 options->mimicmodel = NULL;
198 /* parse an afpd.conf line. i'm doing it this way because it's
199 * easy. it is, however, massively hokey. sample afpd.conf:
200 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
201 * "private machine"@zone2 -noguest -port 11012
202 * server2 -nocleartxt -nodsi
204 * NOTE: this ignores unknown options
206 int afp_options_parseline(char *buf, struct afp_options *options)
211 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
212 options->server = opt;
215 if (strstr(buf, " -nodebug"))
216 options->flags &= ~OPTION_DEBUG;
218 if (strstr(buf, " -slp"))
219 options->flags &= ~OPTION_NOSLP;
222 if (strstr(buf, " -nozeroconf"))
223 options->flags |= OPTION_NOZEROCONF;
225 if (strstr(buf, " -nouservolfirst"))
226 options->flags &= ~OPTION_USERVOLFIRST;
227 if (strstr(buf, " -uservolfirst"))
228 options->flags |= OPTION_USERVOLFIRST;
229 if (strstr(buf, " -nouservol"))
230 options->flags |= OPTION_NOUSERVOL;
231 if (strstr(buf, " -uservol"))
232 options->flags &= ~OPTION_NOUSERVOL;
233 if (strstr(buf, " -proxy"))
234 options->flags |= OPTION_PROXY;
235 if (strstr(buf, " -noicon"))
236 options->flags &= ~OPTION_CUSTOMICON;
237 if (strstr(buf, " -icon"))
238 options->flags |= OPTION_CUSTOMICON;
239 if (strstr(buf, " -advertise_ssh"))
240 options->flags |= OPTION_ANNOUNCESSH;
241 if (strstr(buf, " -noacl2maccess"))
242 options->flags &= ~OPTION_ACL2MACCESS;
243 if (strstr(buf, " -keepsessions")) {
244 default_options.flags |= OPTION_KEEPSESSIONS;
245 options->flags |= OPTION_KEEPSESSIONS;
249 if (strstr(buf, " -nosavepassword"))
250 options->passwdbits |= PASSWD_NOSAVE;
251 if (strstr(buf, " -savepassword"))
252 options->passwdbits &= ~PASSWD_NOSAVE;
253 if (strstr(buf, " -nosetpassword"))
254 options->passwdbits &= ~PASSWD_SET;
255 if (strstr(buf, " -setpassword"))
256 options->passwdbits |= PASSWD_SET;
259 if (strstr(buf, " -transall"))
260 options->transports = AFPTRANS_ALL;
261 if (strstr(buf, " -notransall"))
262 options->transports = AFPTRANS_NONE;
263 if (strstr(buf, " -tcp"))
264 options->transports |= AFPTRANS_TCP;
265 if (strstr(buf, " -notcp"))
266 options->transports &= ~AFPTRANS_TCP;
267 if (strstr(buf, " -ddp"))
268 options->transports |= AFPTRANS_DDP;
269 if (strstr(buf, " -noddp"))
270 options->transports &= ~AFPTRANS_DDP;
271 if (strstr(buf, "-client_polling"))
272 options->server_notif = 0;
274 /* figure out options w/ values. currently, this will ignore the setting
275 * if memory is lacking. */
277 if ((c = getoption(buf, "-hostname"))) {
278 int len = strlen (c);
279 if (len <= MAXHOSTNAMELEN) {
280 memcpy(options->hostname, c, len);
281 options->hostname[len] = 0;
284 LOG(log_info, logtype_afpd, "WARNING: hostname %s is too long (%d)",c,len);
287 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
288 options->defaultvol.name = opt;
289 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
290 options->systemvol.name = opt;
291 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c))) {
304 options->loginmesg = opt;
307 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
308 options->guest = opt;
309 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
310 options->passwdfile = opt;
311 if ((c = getoption(buf, "-passwdminlen")))
312 options->passwdminlen = MIN(1, atoi(c));
313 if ((c = getoption(buf, "-loginmaxfail")))
314 options->loginmaxfail = atoi(c);
315 if ((c = getoption(buf, "-tickleval"))) {
316 options->tickleval = atoi(c);
317 if (options->tickleval <= 0) {
318 options->tickleval = 30;
321 if ((c = getoption(buf, "-timeout"))) {
322 options->timeout = atoi(c);
323 if (options->timeout <= 0) {
324 options->timeout = 4;
328 if ((c = getoption(buf, "-sleep"))) {
329 options->sleep = atoi(c) *120;
330 if (options->sleep <= 4) {
335 if ((c = getoption(buf, "-dsireadbuf"))) {
336 options->dsireadbuf = atoi(c);
337 if (options->dsireadbuf < 6)
338 options->dsireadbuf = 6;
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"))) {
361 /* hokey2: options->logconfig must be converted to store an array of logstrings */
362 if (options->logconfig)
363 free(options->logconfig);
364 options->logconfig = strdup(optstr);
366 c += sizeof("-setuplog");
370 if ((c = getoption(buf, "-unsetuplog")))
374 if ((c = getoption(buf, "-admingroup"))) {
375 struct group *gr = getgrnam(c);
377 options->admingid = gr->gr_gid;
380 #endif /* ADMIN_GRP */
382 if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
383 options->k5service = opt;
384 if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
385 options->k5realm = opt;
386 if ((c = getoption(buf, "-k5keytab"))) {
387 if ( NULL == (options->k5keytab = (char *) malloc(sizeof(char)*(strlen(c)+14)) )) {
388 LOG(log_error, logtype_afpd, "malloc failed");
391 snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
392 putenv(options->k5keytab);
393 /* setenv( "KRB5_KTNAME", c, 1 ); */
395 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
396 options->authprintdir = opt;
397 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
398 options->uampath = opt;
399 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
400 options->uamlist = opt;
402 if ((c = getoption(buf, "-ipaddr"))) {
404 struct in_addr inaddr;
405 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
406 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
407 LOG(log_info, logtype_afpd, "WARNING: can't find %s", opt);
408 options->ipaddr = opt;
411 LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
414 options->ipaddr = strdup(c);
417 /* FIXME CNID Cnid_srv is a server attribute */
418 if ((c = getoption(buf, "-cnidserver"))) {
419 char *p = strrchr(c, ':');
422 Cnid_srv = strdup(c);
424 Cnid_port = strdup(p + 1);
425 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
428 if ((c = getoption(buf, "-port")))
429 options->port = strdup(c);
430 if ((c = getoption(buf, "-ddpaddr")))
431 atalk_aton(c, &options->ddpaddr);
432 if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
433 options->signatureopt = opt;
435 /* do a little checking for the domain name. */
436 if ((c = getoption(buf, "-fqdn"))) {
437 char *p = strchr(c, ':');
440 if (gethostbyname(c)) {
443 if ((opt = strdup(c)))
447 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
451 if ((c = getoption(buf, "-unixcodepage"))) {
452 if ((charset_t)-1 == ( options->unixcharset = add_charset(c)) ) {
453 options->unixcharset = CH_UNIX;
454 LOG(log_warning, logtype_afpd, "setting Unix codepage to '%s' failed", c);
457 if ((opt = strdup(c)))
458 options->unixcodepage = opt;
462 if ((c = getoption(buf, "-maccodepage"))) {
463 if ((charset_t)-1 == ( options->maccharset = add_charset(c)) ) {
464 options->maccharset = CH_MAC;
465 LOG(log_warning, logtype_afpd, "setting Mac codepage to '%s' failed", c);
468 if ((opt = strdup(c)))
469 options->maccodepage = opt;
473 if ((c = strstr(buf, "-closevol"))) {
474 options->closevol= 1;
477 if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
478 options->ntdomain = opt;
480 if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
481 options->ntseparator = opt;
483 if ((c = getoption(buf, "-dircachesize")))
484 options->dircachesize = atoi(c);
486 if ((c = getoption(buf, "-tcpsndbuf")))
487 options->tcp_sndbuf = atoi(c);
489 if ((c = getoption(buf, "-tcprcvbuf")))
490 options->tcp_rcvbuf = atoi(c);
492 if ((c = getoption(buf, "-fcelistener"))) {
493 LOG(log_note, logtype_afpd, "Adding fce listener \"%s\"", c);
494 fce_add_udp_socket(c);
496 if ((c = getoption(buf, "-fcecoalesce"))) {
497 LOG(log_note, logtype_afpd, "Fce coalesce: %s", c);
500 if ((c = getoption(buf, "-fceevents"))) {
501 LOG(log_note, logtype_afpd, "Fce events: %s", c);
505 if ((c = getoption(buf, "-mimicmodel")) && (opt = strdup(c)))
506 options->mimicmodel = opt;
512 * Show version information about afpd.
515 static void show_version( void )
517 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
519 puts( "This program is free software; you can redistribute it and/or modify it under" );
520 puts( "the terms of the GNU General Public License as published by the Free Software" );
521 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
522 puts( "version. Please see the file COPYING for further information and details.\n" );
524 puts( "afpd has been compiled with support for these features:\n" );
526 printf( " AFP3.x support:\tYes\n" );
527 printf( " TCP/IP Support:\t" );
530 printf( "DDP(AppleTalk) Support:\t" );
537 printf( " CNID backends:\t" );
538 #ifdef CNID_BACKEND_CDB
541 #ifdef CNID_BACKEND_DB3
544 #ifdef CNID_BACKEND_DBD
545 #ifdef CNID_BACKEND_DBD_TXN
546 printf( "dbd-txn " );
551 #ifdef CNID_BACKEND_HASH
554 #ifdef CNID_BACKEND_LAST
557 #ifdef CNID_BACKEND_MTAB
560 #ifdef CNID_BACKEND_TDB
567 * Show extended version information about afpd and Netatalk.
570 static void show_version_extended(void )
574 printf( " SLP support:\t" );
581 printf( " Zeroconf support:\t" );
588 printf( " TCP wrappers support:\t" );
595 printf( " Quota support:\t" );
596 #ifndef NO_QUOTA_SUPPORT
602 printf( " Admin group support:\t" );
609 printf( " Valid shell checks:\t" );
610 #ifndef DISABLE_SHELLCHECK
616 printf( " cracklib support:\t" );
623 printf( " Dropbox kludge:\t" );
630 printf( " Force volume uid/gid:\t" );
637 printf( " ACL support:\t" );
644 printf( " EA support:\t" );
647 printf( " LDAP support:\t" );
656 * Display compiled-in default paths
658 static void show_paths( void )
660 printf( " afpd.conf:\t%s\n", _PATH_AFPDCONF );
661 printf( " AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
662 printf( " AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
663 printf( " afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
664 printf( " afp_voluuid.conf:\t%s\n", _PATH_AFPDUUIDCONF );
666 printf( " afp_ldap.conf:\t%s\n", _PATH_ACL_LDAPCONF );
668 printf( " afp_ldap.conf:\tnot supported\n");
670 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
671 printf( " Server messages path:\t%s\n", SERVERTEXT);
672 printf( " lockfile:\t%s\n", _PATH_AFPDLOCK);
676 * Display usage information about afpd.
678 static void show_usage( char *name )
680 fprintf( stderr, "Usage:\t%s [-duptDTI] [-f defaultvolumes] [-s systemvolumes] [-n nbpname]\n", name );
681 fprintf( stderr, "\t [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
682 fprintf( stderr, "\t [-F configfile] [-U uams] [-m umask]\n" );
683 fprintf( stderr, "\t%s -h|-v|-V\n", name );
686 int afp_options_parse(int ac, char **av, struct afp_options *options)
692 char *tmp; /* Used for error checking the result of strtol */
695 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
696 perror( "gethostname" );
699 if (NULL != ( p = strchr(options->hostname, '.' )) ) {
703 if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
709 while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
712 options->flags |= OPTION_DEBUG;
715 options->server = optarg;
718 options->defaultvol.name = optarg;
721 options->systemvol.name = optarg;
724 options->flags |= OPTION_USERVOLFIRST;
727 options->connections = atoi( optarg );
730 options->guest = optarg;
734 options->pidfile = optarg;
738 options->passwdbits |= PASSWD_NOSAVE;
741 options->passwdbits |= PASSWD_SET;
745 options->transports &= ~AFPTRANS_DDP;
748 options->port = optarg;
751 options->transports &= ~AFPTRANS_TCP;
754 options->loginmesg = optarg;
757 options->configfile = optarg;
760 options->uamlist = optarg;
762 case 'v': /* version */
763 show_version( ); puts( "" );
764 show_paths( ); puts( "" );
767 case 'V': /* extended version */
768 show_version_extended( ); puts( "" );
769 show_paths( ); puts( "" );
772 case 'h': /* usage */
777 options->flags |= OPTION_CUSTOMICON;
780 options->umask = strtoul(optarg, &tmp, 8);
781 if ((options->umask > 0777)) {
782 fprintf(stderr, "%s: out of range umask setting provided\n", p);
785 if (tmp[0] != '\0') {
786 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
794 if ( err || optind != ac ) {
800 openlog( p, LOG_PID ); /* ultrix only */