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);
158 /* initialize options */
159 void afp_options_init(struct afp_options *options)
161 memset(options, 0, sizeof(struct afp_options));
162 options->connections = 20;
163 options->pidfile = _PATH_AFPDLOCK;
164 options->defaultvol.name = _PATH_AFPDDEFVOL;
165 options->systemvol.name = _PATH_AFPDSYSVOL;
166 options->configfile = _PATH_AFPDCONF;
167 options->sigconffile = _PATH_AFPDSIGCONF;
168 options->uampath = _PATH_AFPDUAMPATH;
169 options->uamlist = "uams_dhx.so,uams_dhx2.so";
170 options->guest = "nobody";
171 options->loginmesg = "";
172 options->transports = AFPTRANS_TCP; /* TCP only */
173 options->passwdfile = _PATH_AFPDPWFILE;
174 options->tickleval = 30;
175 options->timeout = 4;
176 options->sleep = 10* 120; /* 10 h in 30 seconds tick */
177 options->server_notif = 1;
178 options->authprintdir = NULL;
179 options->signatureopt = "auto";
182 options->admingid = 0;
183 #endif /* ADMIN_GRP */
184 options->k5service = NULL;
185 options->k5realm = NULL;
186 options->k5keytab = NULL;
187 options->unixcharset = CH_UNIX;
188 options->unixcodepage = "LOCALE";
189 options->maccharset = CH_MAC;
190 options->maccodepage = "MAC_ROMAN";
191 options->volnamelen = 80; /* spec: 255, 10.1: 73, 10.4/10.5: 80 */
192 options->ntdomain = NULL;
193 options->ntseparator = NULL;
195 /* don't advertize slp by default */
196 options->flags |= OPTION_NOSLP;
198 options->dircachesize = DEFAULT_MAX_DIRCACHE_SIZE;
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;
241 if (strstr(buf, " -acl2os9mode"))
242 options->flags |= OPTION_ACL2OS9MODE;
245 if (strstr(buf, " -nosavepassword"))
246 options->passwdbits |= PASSWD_NOSAVE;
247 if (strstr(buf, " -savepassword"))
248 options->passwdbits &= ~PASSWD_NOSAVE;
249 if (strstr(buf, " -nosetpassword"))
250 options->passwdbits &= ~PASSWD_SET;
251 if (strstr(buf, " -setpassword"))
252 options->passwdbits |= PASSWD_SET;
255 if (strstr(buf, " -transall"))
256 options->transports = AFPTRANS_ALL;
257 if (strstr(buf, " -notransall"))
258 options->transports = AFPTRANS_NONE;
259 if (strstr(buf, " -tcp"))
260 options->transports |= AFPTRANS_TCP;
261 if (strstr(buf, " -notcp"))
262 options->transports &= ~AFPTRANS_TCP;
263 if (strstr(buf, " -ddp"))
264 options->transports |= AFPTRANS_DDP;
265 if (strstr(buf, " -noddp"))
266 options->transports &= ~AFPTRANS_DDP;
267 if (strstr(buf, "-client_polling"))
268 options->server_notif = 0;
270 /* figure out options w/ values. currently, this will ignore the setting
271 * if memory is lacking. */
273 if ((c = getoption(buf, "-hostname"))) {
274 int len = strlen (c);
275 if (len <= MAXHOSTNAMELEN) {
276 memcpy(options->hostname, c, len);
277 options->hostname[len] = 0;
280 LOG(log_info, logtype_afpd, "WARNING: hostname %s is too long (%d)",c,len);
283 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
284 options->defaultvol.name = opt;
285 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
286 options->systemvol.name = opt;
287 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c)))
288 options->loginmesg = opt;
289 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
290 options->guest = opt;
291 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
292 options->passwdfile = opt;
293 if ((c = getoption(buf, "-passwdminlen")))
294 options->passwdminlen = MIN(1, atoi(c));
295 if ((c = getoption(buf, "-loginmaxfail")))
296 options->loginmaxfail = atoi(c);
297 if ((c = getoption(buf, "-tickleval"))) {
298 options->tickleval = atoi(c);
299 if (options->tickleval <= 0) {
300 options->tickleval = 30;
303 if ((c = getoption(buf, "-timeout"))) {
304 options->timeout = atoi(c);
305 if (options->timeout <= 0) {
306 options->timeout = 4;
310 if ((c = getoption(buf, "-sleep"))) {
311 options->sleep = atoi(c) *120;
312 if (options->sleep <= 4) {
317 if ((c = getoption(buf, "-server_quantum")))
318 options->server_quantum = strtoul(c, NULL, 0);
320 if ((c = getoption(buf, "-volnamelen"))) {
321 options->volnamelen = atoi(c);
322 if (options->volnamelen < 8) {
323 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
325 if (options->volnamelen > 255) {
326 options->volnamelen = 255; /* AFP3 spec */
330 /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
332 /* Now THIS is hokey! Multiple occurrences are not supported by our current code, */
333 /* so I have to loop myself. */
334 while (NULL != (c = strstr(c, "-setuplog"))) {
336 if ((optstr = getoption(c, "-setuplog"))) {
338 c += sizeof("-setuplog");
342 if ((c = getoption(buf, "-unsetuplog")))
346 if ((c = getoption(buf, "-admingroup"))) {
347 struct group *gr = getgrnam(c);
349 options->admingid = gr->gr_gid;
352 #endif /* ADMIN_GRP */
354 if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
355 options->k5service = opt;
356 if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
357 options->k5realm = opt;
358 if ((c = getoption(buf, "-k5keytab"))) {
359 if ( NULL == (options->k5keytab = (char *) malloc(sizeof(char)*(strlen(c)+14)) )) {
360 LOG(log_error, logtype_afpd, "malloc failed");
363 snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
364 putenv(options->k5keytab);
365 /* setenv( "KRB5_KTNAME", c, 1 ); */
367 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
368 options->authprintdir = opt;
369 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
370 options->uampath = opt;
371 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
372 options->uamlist = opt;
374 if ((c = getoption(buf, "-ipaddr"))) {
376 struct in_addr inaddr;
377 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
378 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
379 LOG(log_info, logtype_afpd, "WARNING: can't find %s", opt);
380 options->ipaddr = opt;
383 LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
386 options->ipaddr = strdup(c);
389 /* FIXME CNID Cnid_srv is a server attribute */
390 if ((c = getoption(buf, "-cnidserver"))) {
391 char *p = strrchr(c, ':');
394 Cnid_srv = strdup(c);
396 Cnid_port = strdup(p + 1);
397 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
400 if ((c = getoption(buf, "-port")))
401 options->port = strdup(c);
402 if ((c = getoption(buf, "-ddpaddr")))
403 atalk_aton(c, &options->ddpaddr);
404 if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
405 options->signatureopt = opt;
407 /* do a little checking for the domain name. */
408 if ((c = getoption(buf, "-fqdn"))) {
409 char *p = strchr(c, ':');
412 if (gethostbyname(c)) {
415 if ((opt = strdup(c)))
419 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
423 if ((c = getoption(buf, "-unixcodepage"))) {
424 if ((charset_t)-1 == ( options->unixcharset = add_charset(c)) ) {
425 options->unixcharset = CH_UNIX;
426 LOG(log_warning, logtype_afpd, "setting Unix codepage to '%s' failed", c);
429 if ((opt = strdup(c)))
430 options->unixcodepage = opt;
434 if ((c = getoption(buf, "-maccodepage"))) {
435 if ((charset_t)-1 == ( options->maccharset = add_charset(c)) ) {
436 options->maccharset = CH_MAC;
437 LOG(log_warning, logtype_afpd, "setting Mac codepage to '%s' failed", c);
440 if ((opt = strdup(c)))
441 options->maccodepage = opt;
445 if ((c = strstr(buf, "-closevol"))) {
446 options->closevol= 1;
449 if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
450 options->ntdomain = opt;
452 if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
453 options->ntseparator = opt;
455 if ((c = getoption(buf, "-dircachesize")))
456 options->dircachesize = atoi(c);
462 * Show version information about afpd.
465 static void show_version( void )
467 printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
469 puts( "This program is free software; you can redistribute it and/or modify it under" );
470 puts( "the terms of the GNU General Public License as published by the Free Software" );
471 puts( "Foundation; either version 2 of the License, or (at your option) any later" );
472 puts( "version. Please see the file COPYING for further information and details.\n" );
474 puts( "afpd has been compiled with support for these features:\n" );
476 printf( " AFP3.x support:\t" );
483 printf( " Transport layers:\t" );
487 puts( "TCP/IP DDP" );
490 printf( " CNID backends:\t" );
491 #ifdef CNID_BACKEND_CDB
494 #ifdef CNID_BACKEND_DB3
497 #ifdef CNID_BACKEND_DBD
498 #ifdef CNID_BACKEND_DBD_TXN
499 printf( "dbd-txn " );
504 #ifdef CNID_BACKEND_HASH
507 #ifdef CNID_BACKEND_LAST
510 #ifdef CNID_BACKEND_MTAB
513 #ifdef CNID_BACKEND_TDB
520 * Show extended version information about afpd and Netatalk.
523 static void show_version_extended(void )
527 printf( " SLP support:\t" );
534 printf( " TCP wrappers support:\t" );
541 printf( " Quota support:\t" );
542 #ifndef NO_QUOTA_SUPPORT
548 printf( " Admin group support:\t" );
555 printf( " Valid shell checks:\t" );
556 #ifndef DISABLE_SHELLCHECK
562 printf( " cracklib support:\t" );
569 printf( " Dropbox kludge:\t" );
576 printf( " Force volume uid/gid:\t" );
585 * Display compiled-in default paths
587 static void show_paths( void )
589 printf( " afpd.conf:\t%s\n", _PATH_AFPDCONF );
590 printf( " afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
591 printf( " AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
592 printf( " AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
593 printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
594 printf( " Server messages path:\t%s\n", SERVERTEXT);
598 * Display usage information about afpd.
600 static void show_usage( char *name )
602 fprintf( stderr, "Usage:\t%s [-duptDTI] [-f defaultvolumes] [-s systemvolumes] [-n nbpname]\n", name );
603 fprintf( stderr, "\t [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
604 fprintf( stderr, "\t [-F configfile] [-U uams] [-m umask]\n" );
605 fprintf( stderr, "\t%s -h|-v|-V\n", name );
608 int afp_options_parse(int ac, char **av, struct afp_options *options)
614 char *tmp; /* Used for error checking the result of strtol */
617 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
618 perror( "gethostname" );
621 if (NULL != ( p = strchr(options->hostname, '.' )) ) {
625 if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
631 while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
634 options->flags |= OPTION_DEBUG;
637 options->server = optarg;
640 options->defaultvol.name = optarg;
643 options->systemvol.name = optarg;
646 options->flags |= OPTION_USERVOLFIRST;
649 options->connections = atoi( optarg );
652 options->guest = optarg;
656 options->pidfile = optarg;
660 options->passwdbits |= PASSWD_NOSAVE;
663 options->passwdbits |= PASSWD_SET;
667 options->transports &= ~AFPTRANS_DDP;
670 options->port = optarg;
673 options->transports &= ~AFPTRANS_TCP;
676 options->loginmesg = optarg;
679 options->configfile = optarg;
682 options->uamlist = optarg;
684 case 'v': /* version */
685 show_version( ); puts( "" );
686 show_paths( ); puts( "" );
689 case 'V': /* extended version */
690 show_version_extended( ); puts( "" );
691 show_paths( ); puts( "" );
694 case 'h': /* usage */
699 options->flags |= OPTION_CUSTOMICON;
702 options->umask = strtoul(optarg, &tmp, 8);
703 if ((options->umask > 0777)) {
704 fprintf(stderr, "%s: out of range umask setting provided\n", p);
707 if (tmp[0] != '\0') {
708 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
716 if ( err || optind != ac ) {
722 openlog( p, LOG_PID ); /* ultrix only */