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->k5service && (opt->k5service != save->k5service))
141 free(opt->k5service);
142 if (opt->k5realm && (opt->k5realm != save->k5realm))
144 if (opt->k5keytab && (opt->k5keytab != save->k5keytab))
146 if (opt->unixcodepage && (opt->unixcodepage != save->unixcodepage))
147 free(opt->unixcodepage);
148 if (opt->maccodepage && (opt->maccodepage != save->maccodepage))
149 free(opt->maccodepage);
151 if (opt->ntdomain && (opt->ntdomain != save->ntdomain))
153 if (opt->ntseparator && (opt->ntseparator != save->ntseparator))
154 free(opt->ntseparator);
157 /* initialize options */
158 void afp_options_init(struct afp_options *options)
160 memset(options, 0, sizeof(struct afp_options));
161 options->connections = 20;
162 options->pidfile = _PATH_AFPDLOCK;
163 options->defaultvol.name = _PATH_AFPDDEFVOL;
164 options->systemvol.name = _PATH_AFPDSYSVOL;
165 options->configfile = _PATH_AFPDCONF;
166 options->sigconffile = _PATH_AFPDSIGCONF;
167 options->uampath = _PATH_AFPDUAMPATH;
168 options->uamlist = "uams_dhx.so,uams_dhx2.so";
169 options->guest = "nobody";
170 options->loginmesg = "";
171 options->transports = AFPTRANS_TCP; /* TCP only */
172 options->passwdfile = _PATH_AFPDPWFILE;
173 options->tickleval = 30;
174 options->timeout = 4;
175 options->sleep = 10* 120; /* 10 h in 30 seconds tick */
176 options->server_notif = 1;
177 options->authprintdir = NULL;
178 options->signatureopt = "auto";
181 options->admingid = 0;
182 #endif /* ADMIN_GRP */
183 options->k5service = NULL;
184 options->k5realm = NULL;
185 options->k5keytab = NULL;
186 options->unixcharset = CH_UNIX;
187 options->unixcodepage = "LOCALE";
188 options->maccharset = CH_MAC;
189 options->maccodepage = "MAC_ROMAN";
190 options->volnamelen = 80; /* spec: 255, 10.1: 73, 10.4/10.5: 80 */
191 options->ntdomain = NULL;
192 options->ntseparator = NULL;
194 /* don't advertize slp by default */
195 options->flags |= OPTION_NOSLP;
199 /* parse an afpd.conf line. i'm doing it this way because it's
200 * easy. it is, however, massively hokey. sample afpd.conf:
201 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
202 * "private machine"@zone2 -noguest -port 11012
203 * server2 -nocleartxt -nodsi
205 * NOTE: this ignores unknown options
207 int afp_options_parseline(char *buf, struct afp_options *options)
212 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
213 options->server = opt;
216 if (strstr(buf, " -nodebug"))
217 options->flags &= ~OPTION_DEBUG;
219 if (strstr(buf, " -slp"))
220 options->flags &= ~OPTION_NOSLP;
223 if (strstr(buf, " -nouservolfirst"))
224 options->flags &= ~OPTION_USERVOLFIRST;
225 if (strstr(buf, " -uservolfirst"))
226 options->flags |= OPTION_USERVOLFIRST;
227 if (strstr(buf, " -nouservol"))
228 options->flags |= OPTION_NOUSERVOL;
229 if (strstr(buf, " -uservol"))
230 options->flags &= ~OPTION_NOUSERVOL;
231 if (strstr(buf, " -proxy"))
232 options->flags |= OPTION_PROXY;
233 if (strstr(buf, " -noicon"))
234 options->flags &= ~OPTION_CUSTOMICON;
235 if (strstr(buf, " -icon"))
236 options->flags |= OPTION_CUSTOMICON;
237 if (strstr(buf, " -advertise_ssh"))
238 options->flags |= OPTION_ANNOUNCESSH;
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)))
284 options->loginmesg = opt;
285 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
286 options->guest = opt;
287 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
288 options->passwdfile = opt;
289 if ((c = getoption(buf, "-passwdminlen")))
290 options->passwdminlen = MIN(1, atoi(c));
291 if ((c = getoption(buf, "-loginmaxfail")))
292 options->loginmaxfail = atoi(c);
293 if ((c = getoption(buf, "-tickleval"))) {
294 options->tickleval = atoi(c);
295 if (options->tickleval <= 0) {
296 options->tickleval = 30;
299 if ((c = getoption(buf, "-timeout"))) {
300 options->timeout = atoi(c);
301 if (options->timeout <= 0) {
302 options->timeout = 4;
306 if ((c = getoption(buf, "-sleep"))) {
307 options->sleep = atoi(c) *120;
308 if (options->sleep <= 4) {
313 if ((c = getoption(buf, "-server_quantum")))
314 options->server_quantum = strtoul(c, NULL, 0);
316 if ((c = getoption(buf, "-volnamelen"))) {
317 options->volnamelen = atoi(c);
318 if (options->volnamelen < 8) {
319 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
321 if (options->volnamelen > 255) {
322 options->volnamelen = 255; /* AFP3 spec */
326 /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
328 /* Now THIS is hokey! Multiple occurrences are not supported by our current code, */
329 /* so I have to loop myself. */
330 while (NULL != (c = strstr(c, "-setuplog"))) {
332 if ((optstr = getoption(c, "-setuplog"))) {
334 c += sizeof("-setuplog");
338 if ((c = getoption(buf, "-unsetuplog")))
342 if ((c = getoption(buf, "-admingroup"))) {
343 struct group *gr = getgrnam(c);
345 options->admingid = gr->gr_gid;
348 #endif /* ADMIN_GRP */
350 if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
351 options->k5service = opt;
352 if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
353 options->k5realm = opt;
354 if ((c = getoption(buf, "-k5keytab"))) {
355 if ( NULL == (options->k5keytab = (char *) malloc(sizeof(char)*(strlen(c)+14)) )) {
356 LOG(log_error, logtype_afpd, "malloc failed");
359 snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
360 putenv(options->k5keytab);
361 /* setenv( "KRB5_KTNAME", c, 1 ); */
363 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
364 options->authprintdir = opt;
365 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
366 options->uampath = opt;
367 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
368 options->uamlist = opt;
370 if ((c = getoption(buf, "-ipaddr"))) {
372 struct in_addr inaddr;
373 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
374 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
375 LOG(log_info, logtype_afpd, "WARNING: can't find %s", opt);
376 options->ipaddr = opt;
379 LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
382 options->ipaddr = strdup(c);
385 /* FIXME CNID Cnid_srv is a server attribute */
386 if ((c = getoption(buf, "-cnidserver"))) {
387 char *p = strrchr(c, ':');
390 Cnid_srv = strdup(c);
392 Cnid_port = strdup(p + 1);
393 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
396 if ((c = getoption(buf, "-port")))
397 options->port = strdup(c);
398 if ((c = getoption(buf, "-ddpaddr")))
399 atalk_aton(c, &options->ddpaddr);
400 if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
401 options->signatureopt = opt;
403 /* do a little checking for the domain name. */
404 if ((c = getoption(buf, "-fqdn"))) {
405 char *p = strchr(c, ':');
408 if (gethostbyname(c)) {
411 if ((opt = strdup(c)))
415 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
419 if ((c = getoption(buf, "-unixcodepage"))) {
420 if ((charset_t)-1 == ( options->unixcharset = add_charset(c)) ) {
421 options->unixcharset = CH_UNIX;
422 LOG(log_warning, logtype_afpd, "setting Unix codepage to '%s' failed", c);
425 if ((opt = strdup(c)))
426 options->unixcodepage = opt;
430 if ((c = getoption(buf, "-maccodepage"))) {
431 if ((charset_t)-1 == ( options->maccharset = add_charset(c)) ) {
432 options->maccharset = CH_MAC;
433 LOG(log_warning, logtype_afpd, "setting Mac codepage to '%s' failed", c);
436 if ((opt = strdup(c)))
437 options->maccodepage = opt;
441 if ((c = strstr(buf, "-closevol"))) {
442 options->closevol= 1;
445 if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
446 options->ntdomain = opt;
448 if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
449 options->ntseparator = opt;
455 * Show version information about afpd.
458 static void show_version( void )
460 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
462 puts( "This program is free software; you can redistribute it and/or modify it under" );
463 puts( "the terms of the GNU General Public License as published by the Free Software" );
464 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
465 puts( "version. Please see the file COPYING for further information and details.\n" );
467 puts( "afpd has been compiled with support for these features:\n" );
469 printf( " AFP3.x support:\t" );
476 printf( " Transport layers:\t" );
480 puts( "TCP/IP DDP" );
483 printf( " CNID backends:\t" );
484 #ifdef CNID_BACKEND_CDB
487 #ifdef CNID_BACKEND_DB3
490 #ifdef CNID_BACKEND_DBD
491 #ifdef CNID_BACKEND_DBD_TXN
492 printf( "dbd-txn " );
497 #ifdef CNID_BACKEND_HASH
500 #ifdef CNID_BACKEND_LAST
503 #ifdef CNID_BACKEND_MTAB
506 #ifdef CNID_BACKEND_TDB
513 * Show extended version information about afpd and Netatalk.
516 static void show_version_extended(void )
520 printf( " SLP support:\t" );
527 printf( " TCP wrappers support:\t" );
534 printf( " Quota support:\t" );
535 #ifndef NO_QUOTA_SUPPORT
541 printf( " Admin group support:\t" );
548 printf( " Valid shell checks:\t" );
549 #ifndef DISABLE_SHELLCHECK
555 printf( " cracklib support:\t" );
562 printf( " Dropbox kludge:\t" );
569 printf( " Force volume uid/gid:\t" );
578 * Display compiled-in default paths
580 static void show_paths( void )
582 printf( " afpd.conf:\t%s\n", _PATH_AFPDCONF );
583 printf( " afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
584 printf( " AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
585 printf( " AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
586 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
587 printf( " Server messages path:\t%s\n", SERVERTEXT);
591 * Display usage information about afpd.
593 static void show_usage( char *name )
595 fprintf( stderr, "Usage:\t%s [-duptDTI] [-f defaultvolumes] [-s systemvolumes] [-n nbpname]\n", name );
596 fprintf( stderr, "\t [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
597 fprintf( stderr, "\t [-F configfile] [-U uams] [-m umask]\n" );
598 fprintf( stderr, "\t%s -h|-v|-V\n", name );
601 int afp_options_parse(int ac, char **av, struct afp_options *options)
607 char *tmp; /* Used for error checking the result of strtol */
610 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
611 perror( "gethostname" );
614 if (NULL != ( p = strchr(options->hostname, '.' )) ) {
618 if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
624 while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
627 options->flags |= OPTION_DEBUG;
630 options->server = optarg;
633 options->defaultvol.name = optarg;
636 options->systemvol.name = optarg;
639 options->flags |= OPTION_USERVOLFIRST;
642 options->connections = atoi( optarg );
645 options->guest = optarg;
649 options->pidfile = optarg;
653 options->passwdbits |= PASSWD_NOSAVE;
656 options->passwdbits |= PASSWD_SET;
660 options->transports &= ~AFPTRANS_DDP;
663 options->port = optarg;
666 options->transports &= ~AFPTRANS_TCP;
669 options->loginmesg = optarg;
672 options->configfile = optarg;
675 options->uamlist = optarg;
677 case 'v': /* version */
678 show_version( ); puts( "" );
679 show_paths( ); puts( "" );
682 case 'V': /* extended version */
683 show_version_extended( ); puts( "" );
684 show_paths( ); puts( "" );
687 case 'h': /* usage */
692 options->flags |= OPTION_CUSTOMICON;
695 options->umask = strtoul(optarg, &tmp, 8);
696 if ((options->umask > 0777)) {
697 fprintf(stderr, "%s: out of range umask setting provided\n", p);
700 if (tmp[0] != '\0') {
701 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
709 if ( err || optind != ac ) {
715 openlog( p, LOG_PID ); /* ultrix only */