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>
51 #include <atalk/compat.h>
55 #include <sys/types.h>
56 #endif /* ADMIN_GRP */
59 #define MIN(a, b) ((a) < (b) ? (a) : (b))
63 const char *Cnid_srv = "localhost";
64 const char *Cnid_port = "4700";
66 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:hIvVm:"
69 /* return an option. this uses an internal array, so it's necessary
70 * to duplicate it if you want to hold it for long. this is probably
72 static char *getoption(char *buf, const char *option)
74 static char string[LENGTH + 1];
78 if (option && (buf = strstr(buf, option)))
79 buf = strpbrk(buf, " \t");
81 while (buf && isspace(*buf))
87 /* search for any quoted stuff */
88 if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
90 len = MIN(end - buf, LENGTH);
91 } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
92 len = MIN(end - buf, LENGTH);
94 len = MIN(strlen(buf), LENGTH);
96 strncpy(string, buf, len);
101 /* get rid of any allocated afp_option buffers. */
102 void afp_options_free(struct afp_options *opt,
103 const struct afp_options *save)
105 if (opt->defaultvol.name && (opt->defaultvol.name != save->defaultvol.name))
106 free(opt->defaultvol.name);
107 if (opt->defaultvol.full_name && (opt->defaultvol.full_name != save->defaultvol.full_name))
108 free(opt->defaultvol.full_name);
110 if (opt->systemvol.name && (opt->systemvol.name != save->systemvol.name))
111 free(opt->systemvol.name);
112 if (opt->systemvol.full_name && (opt->systemvol.full_name != save->systemvol.full_name))
113 free(opt->systemvol.full_name);
115 if (opt->uservol.name && (opt->uservol.name != save->uservol.name))
116 free(opt->uservol.name);
117 if (opt->uservol.full_name && (opt->uservol.full_name != save->uservol.full_name))
118 free(opt->uservol.full_name);
120 if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
121 free(opt->loginmesg);
122 if (opt->guest && (opt->guest != save->guest))
124 if (opt->server && (opt->server != save->server))
126 if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
128 if (opt->port && (opt->port != save->port))
130 if (opt->fqdn && (opt->fqdn != save->fqdn))
132 if (opt->uampath && (opt->uampath != save->uampath))
134 if (opt->uamlist && (opt->uamlist != save->uamlist))
136 if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
137 free(opt->passwdfile);
138 if (opt->signatureopt && (opt->signatureopt != save->signatureopt))
139 free(opt->signatureopt);
140 if (opt->signature && (opt->signature != save->signature))
141 free(opt->signature);
142 if (opt->k5service && (opt->k5service != save->k5service))
143 free(opt->k5service);
144 if (opt->k5realm && (opt->k5realm != save->k5realm))
146 if (opt->k5keytab && (opt->k5keytab != save->k5keytab))
148 if (opt->unixcodepage && (opt->unixcodepage != save->unixcodepage))
149 free(opt->unixcodepage);
150 if (opt->maccodepage && (opt->maccodepage != save->maccodepage))
151 free(opt->maccodepage);
153 if (opt->ntdomain && (opt->ntdomain != save->ntdomain))
155 if (opt->ntseparator && (opt->ntseparator != save->ntseparator))
156 free(opt->ntseparator);
159 /* initialize options */
160 void afp_options_init(struct afp_options *options)
162 memset(options, 0, sizeof(struct afp_options));
163 options->connections = 20;
164 options->pidfile = _PATH_AFPDLOCK;
165 options->defaultvol.name = _PATH_AFPDDEFVOL;
166 options->systemvol.name = _PATH_AFPDSYSVOL;
167 options->configfile = _PATH_AFPDCONF;
168 options->sigconffile = _PATH_AFPDSIGCONF;
169 options->uampath = _PATH_AFPDUAMPATH;
170 options->uamlist = "uams_dhx.so,uams_dhx2.so";
171 options->guest = "nobody";
172 options->loginmesg = "";
173 options->transports = AFPTRANS_TCP; /* TCP only */
174 options->passwdfile = _PATH_AFPDPWFILE;
175 options->tickleval = 30;
176 options->timeout = 4;
177 options->sleep = 10* 120; /* 10 h in 30 seconds tick */
178 options->server_notif = 1;
179 options->authprintdir = NULL;
180 options->signatureopt = "auto";
183 options->admingid = 0;
184 #endif /* ADMIN_GRP */
185 options->k5service = NULL;
186 options->k5realm = NULL;
187 options->k5keytab = NULL;
188 options->unixcharset = CH_UNIX;
189 options->unixcodepage = "LOCALE";
190 options->maccharset = CH_MAC;
191 options->maccodepage = "MAC_ROMAN";
192 options->volnamelen = 80; /* spec: 255, 10.1: 73, 10.4/10.5: 80 */
193 options->ntdomain = NULL;
194 options->ntseparator = NULL;
196 /* don't advertize slp by default */
197 options->flags |= OPTION_NOSLP;
201 /* parse an afpd.conf line. i'm doing it this way because it's
202 * easy. it is, however, massively hokey. sample afpd.conf:
203 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
204 * "private machine"@zone2 -noguest -port 11012
205 * server2 -nocleartxt -nodsi
207 * NOTE: this ignores unknown options
209 int afp_options_parseline(char *buf, struct afp_options *options)
214 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
215 options->server = opt;
218 if (strstr(buf, " -nodebug"))
219 options->flags &= ~OPTION_DEBUG;
221 if (strstr(buf, " -slp"))
222 options->flags &= ~OPTION_NOSLP;
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;
243 if (strstr(buf, " -nosavepassword"))
244 options->passwdbits |= PASSWD_NOSAVE;
245 if (strstr(buf, " -savepassword"))
246 options->passwdbits &= ~PASSWD_NOSAVE;
247 if (strstr(buf, " -nosetpassword"))
248 options->passwdbits &= ~PASSWD_SET;
249 if (strstr(buf, " -setpassword"))
250 options->passwdbits |= PASSWD_SET;
253 if (strstr(buf, " -transall"))
254 options->transports = AFPTRANS_ALL;
255 if (strstr(buf, " -notransall"))
256 options->transports = AFPTRANS_NONE;
257 if (strstr(buf, " -tcp"))
258 options->transports |= AFPTRANS_TCP;
259 if (strstr(buf, " -notcp"))
260 options->transports &= ~AFPTRANS_TCP;
261 if (strstr(buf, " -ddp"))
262 options->transports |= AFPTRANS_DDP;
263 if (strstr(buf, " -noddp"))
264 options->transports &= ~AFPTRANS_DDP;
265 if (strstr(buf, "-client_polling"))
266 options->server_notif = 0;
268 /* figure out options w/ values. currently, this will ignore the setting
269 * if memory is lacking. */
271 if ((c = getoption(buf, "-hostname"))) {
272 int len = strlen (c);
273 if (len <= MAXHOSTNAMELEN) {
274 memcpy(options->hostname, c, len);
275 options->hostname[len] = 0;
278 LOG(log_info, logtype_afpd, "WARNING: hostname %s is too long (%d)",c,len);
281 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
282 options->defaultvol.name = opt;
283 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
284 options->systemvol.name = opt;
285 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c)))
286 options->loginmesg = opt;
287 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
288 options->guest = opt;
289 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
290 options->passwdfile = opt;
291 if ((c = getoption(buf, "-passwdminlen")))
292 options->passwdminlen = MIN(1, atoi(c));
293 if ((c = getoption(buf, "-loginmaxfail")))
294 options->loginmaxfail = atoi(c);
295 if ((c = getoption(buf, "-tickleval"))) {
296 options->tickleval = atoi(c);
297 if (options->tickleval <= 0) {
298 options->tickleval = 30;
301 if ((c = getoption(buf, "-timeout"))) {
302 options->timeout = atoi(c);
303 if (options->timeout <= 0) {
304 options->timeout = 4;
308 if ((c = getoption(buf, "-sleep"))) {
309 options->sleep = atoi(c) *120;
310 if (options->sleep <= 4) {
315 if ((c = getoption(buf, "-server_quantum")))
316 options->server_quantum = strtoul(c, NULL, 0);
318 if ((c = getoption(buf, "-volnamelen"))) {
319 options->volnamelen = atoi(c);
320 if (options->volnamelen < 8) {
321 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
323 if (options->volnamelen > 255) {
324 options->volnamelen = 255; /* AFP3 spec */
328 /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
330 /* Now THIS is hokey! Multiple occurrences are not supported by our current code, */
331 /* so I have to loop myself. */
332 while (NULL != (c = strstr(c, "-setuplog"))) {
334 if ((optstr = getoption(c, "-setuplog"))) {
336 c += sizeof("-setuplog");
340 if ((c = getoption(buf, "-unsetuplog")))
344 if ((c = getoption(buf, "-admingroup"))) {
345 struct group *gr = getgrnam(c);
347 options->admingid = gr->gr_gid;
350 #endif /* ADMIN_GRP */
352 if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
353 options->k5service = opt;
354 if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
355 options->k5realm = opt;
356 if ((c = getoption(buf, "-k5keytab"))) {
357 if ( NULL == (options->k5keytab = (char *) malloc(sizeof(char)*(strlen(c)+14)) )) {
358 LOG(log_error, logtype_afpd, "malloc failed");
361 snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
362 putenv(options->k5keytab);
363 /* setenv( "KRB5_KTNAME", c, 1 ); */
365 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
366 options->authprintdir = opt;
367 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
368 options->uampath = opt;
369 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
370 options->uamlist = opt;
372 if ((c = getoption(buf, "-ipaddr"))) {
374 struct in_addr inaddr;
375 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
376 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
377 LOG(log_info, logtype_afpd, "WARNING: can't find %s", opt);
378 options->ipaddr = opt;
381 LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
384 options->ipaddr = strdup(c);
387 /* FIXME CNID Cnid_srv is a server attribute */
388 if ((c = getoption(buf, "-cnidserver"))) {
389 char *p = strrchr(c, ':');
392 Cnid_srv = strdup(c);
394 Cnid_port = strdup(p + 1);
395 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
398 if ((c = getoption(buf, "-port")))
399 options->port = strdup(c);
400 if ((c = getoption(buf, "-ddpaddr")))
401 atalk_aton(c, &options->ddpaddr);
402 if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
403 options->signatureopt = opt;
405 /* do a little checking for the domain name. */
406 if ((c = getoption(buf, "-fqdn"))) {
407 char *p = strchr(c, ':');
410 if (gethostbyname(c)) {
413 if ((opt = strdup(c)))
417 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
421 if ((c = getoption(buf, "-unixcodepage"))) {
422 if ((charset_t)-1 == ( options->unixcharset = add_charset(c)) ) {
423 options->unixcharset = CH_UNIX;
424 LOG(log_warning, logtype_afpd, "setting Unix codepage to '%s' failed", c);
427 if ((opt = strdup(c)))
428 options->unixcodepage = opt;
432 if ((c = getoption(buf, "-maccodepage"))) {
433 if ((charset_t)-1 == ( options->maccharset = add_charset(c)) ) {
434 options->maccharset = CH_MAC;
435 LOG(log_warning, logtype_afpd, "setting Mac codepage to '%s' failed", c);
438 if ((opt = strdup(c)))
439 options->maccodepage = opt;
443 if ((c = strstr(buf, "-closevol"))) {
444 options->closevol= 1;
447 if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
448 options->ntdomain = opt;
450 if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
451 options->ntseparator = opt;
457 * Show version information about afpd.
460 static void show_version( void )
462 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
464 puts( "This program is free software; you can redistribute it and/or modify it under" );
465 puts( "the terms of the GNU General Public License as published by the Free Software" );
466 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
467 puts( "version. Please see the file COPYING for further information and details.\n" );
469 puts( "afpd has been compiled with support for these features:\n" );
471 printf( " AFP3.x support:\t" );
478 printf( " Transport layers:\t" );
482 puts( "TCP/IP DDP" );
485 printf( " CNID backends:\t" );
486 #ifdef CNID_BACKEND_CDB
489 #ifdef CNID_BACKEND_DB3
492 #ifdef CNID_BACKEND_DBD
493 #ifdef CNID_BACKEND_DBD_TXN
494 printf( "dbd-txn " );
499 #ifdef CNID_BACKEND_HASH
502 #ifdef CNID_BACKEND_LAST
505 #ifdef CNID_BACKEND_MTAB
508 #ifdef CNID_BACKEND_TDB
515 * Show extended version information about afpd and Netatalk.
518 static void show_version_extended(void )
522 printf( " SLP support:\t" );
529 printf( " TCP wrappers support:\t" );
536 printf( " Quota support:\t" );
537 #ifndef NO_QUOTA_SUPPORT
543 printf( " Admin group support:\t" );
550 printf( " Valid shell checks:\t" );
551 #ifndef DISABLE_SHELLCHECK
557 printf( " cracklib support:\t" );
564 printf( " Dropbox kludge:\t" );
571 printf( " Force volume uid/gid:\t" );
580 * Display compiled-in default paths
582 static void show_paths( void )
584 printf( " afpd.conf:\t%s\n", _PATH_AFPDCONF );
585 printf( " afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
586 printf( " AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
587 printf( " AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
588 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
589 printf( " Server messages path:\t%s\n", SERVERTEXT);
593 * Display usage information about afpd.
595 static void show_usage( char *name )
597 fprintf( stderr, "Usage:\t%s [-duptDTI] [-f defaultvolumes] [-s systemvolumes] [-n nbpname]\n", name );
598 fprintf( stderr, "\t [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
599 fprintf( stderr, "\t [-F configfile] [-U uams] [-m umask]\n" );
600 fprintf( stderr, "\t%s -h|-v|-V\n", name );
603 int afp_options_parse(int ac, char **av, struct afp_options *options)
609 char *tmp; /* Used for error checking the result of strtol */
612 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
613 perror( "gethostname" );
616 if (NULL != ( p = strchr(options->hostname, '.' )) ) {
620 if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
626 while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
629 options->flags |= OPTION_DEBUG;
632 options->server = optarg;
635 options->defaultvol.name = optarg;
638 options->systemvol.name = optarg;
641 options->flags |= OPTION_USERVOLFIRST;
644 options->connections = atoi( optarg );
647 options->guest = optarg;
651 options->pidfile = optarg;
655 options->passwdbits |= PASSWD_NOSAVE;
658 options->passwdbits |= PASSWD_SET;
662 options->transports &= ~AFPTRANS_DDP;
665 options->port = optarg;
668 options->transports &= ~AFPTRANS_TCP;
671 options->loginmesg = optarg;
674 options->configfile = optarg;
677 options->uamlist = optarg;
679 case 'v': /* version */
680 show_version( ); puts( "" );
681 show_paths( ); puts( "" );
684 case 'V': /* extended version */
685 show_version_extended( ); puts( "" );
686 show_paths( ); puts( "" );
689 case 'h': /* usage */
694 options->flags |= OPTION_CUSTOMICON;
697 options->umask = strtoul(optarg, &tmp, 8);
698 if ((options->umask > 0777)) {
699 fprintf(stderr, "%s: out of range umask setting provided\n", p);
702 if (tmp[0] != '\0') {
703 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
711 if ( err || optind != ac ) {
717 openlog( p, LOG_PID ); /* ultrix only */