]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afp_options.c
028a1efb2c6702d006783b0c20d0a198d41e53f1
[netatalk.git] / etc / afpd / afp_options.c
1 /*
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.
5  *
6  * modified from main.c. this handles afp options.
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif /* HAVE_CONFIG_H */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <ctype.h>
17 #include <unistd.h>
18 #include <sys/param.h>
19 #include <sys/socket.h>
20 #include <atalk/logger.h>
21
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24
25 #ifdef HAVE_NETDB_H
26 #include <netdb.h>
27 #endif /* HAVE_NETDB_H */
28
29 #ifdef ADMIN_GRP
30 #include <grp.h>
31 #include <sys/types.h>
32 #endif /* ADMIN_GRP */
33
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>
39
40 #include "status.h"
41 #include "auth.h"
42 #include "dircache.h"
43
44 #ifndef MIN
45 #define MIN(a, b)  ((a) < (b) ? (a) : (b))
46 #endif /* MIN */
47
48 /* FIXME CNID */
49 const char *Cnid_srv = "localhost";
50 const char *Cnid_port = "4700";
51
52 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:hIvVm:"
53 #define LENGTH 512
54
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
57  * non-optimal. */
58 static char *getoption(char *buf, const char *option)
59 {
60     static char string[LENGTH + 1];
61     char *end;
62     int len;
63
64     if (option && (buf = strstr(buf, option)))
65         buf = strpbrk(buf, " \t");
66
67     while (buf && isspace(*buf))
68         buf++;
69
70     if (!buf)
71         return NULL;
72
73     /* search for any quoted stuff */
74     if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
75         buf++;
76         len = MIN(end - buf, LENGTH);
77     } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
78         len = MIN(end - buf, LENGTH);
79     else
80         len = MIN(strlen(buf), LENGTH);
81
82     strncpy(string, buf, len);
83     string[len] = '\0';
84     return string;
85 }
86
87 /* get rid of any allocated afp_option buffers. */
88 void afp_options_free(struct afp_options *opt,
89                       const struct afp_options *save)
90 {
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);
95
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);
100
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);
105
106     if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
107         free(opt->loginmesg);
108     if (opt->guest && (opt->guest != save->guest))
109         free(opt->guest);
110     if (opt->server && (opt->server != save->server))
111         free(opt->server);
112     if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
113         free(opt->ipaddr);
114     if (opt->port && (opt->port != save->port))
115         free(opt->port);
116     if (opt->fqdn && (opt->fqdn != save->fqdn))
117         free(opt->fqdn);
118     if (opt->uampath && (opt->uampath != save->uampath))
119         free(opt->uampath);
120     if (opt->uamlist && (opt->uamlist != save->uamlist))
121         free(opt->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))
129         free(opt->k5realm);
130     if (opt->k5keytab && (opt->k5keytab != save->k5keytab))
131         free(opt->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);
136
137     if (opt->ntdomain && (opt->ntdomain != save->ntdomain))
138         free(opt->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);
145 }
146
147 /* initialize options */
148 void afp_options_init(struct afp_options *options)
149 {
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";
171     options->umask = 0;
172 #ifdef ADMIN_GRP
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;
185 #ifdef USE_SRVLOC
186     /* don't advertize slp by default */
187     options->flags |= OPTION_NOSLP;
188 #endif
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;
196 }
197
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
203  *
204  * NOTE: this ignores unknown options 
205  */
206 int afp_options_parseline(char *buf, struct afp_options *options)
207 {
208     char *c, *opt;
209
210     /* handle server */
211     if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
212         options->server = opt;
213
214     /* parse toggles */
215     if (strstr(buf, " -nodebug"))
216         options->flags &= ~OPTION_DEBUG;
217 #ifdef USE_SRVLOC
218     if (strstr(buf, " -slp"))
219         options->flags &= ~OPTION_NOSLP;
220 #endif
221 #ifdef USE_ZEROCONF
222     if (strstr(buf, " -nozeroconf"))
223         options->flags |= OPTION_NOZEROCONF;
224 #endif
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;
246     }
247
248     /* passwd bits */
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;
257
258     /* transports */
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;
273
274     /* figure out options w/ values. currently, this will ignore the setting
275      * if memory is lacking. */
276
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;
282         }
283         else
284             LOG(log_info, logtype_afpd, "WARNING: hostname %s is too long (%d)",c,len);
285     }
286
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))) {
292         int i = 0, j = 0;
293         while (c[i]) {
294             if (c[i] != '\\') {
295                 opt[j++] = c[i];
296             } else {
297                 i++;
298                 if (c[i] == 'n')
299                     opt[j++] = '\n';
300             }
301             i++;
302         }
303         opt[j] = 0;
304         options->loginmesg = opt;
305         
306     }
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;
319         }
320     }
321     if ((c = getoption(buf, "-timeout"))) {
322         options->timeout = atoi(c);
323         if (options->timeout <= 0) {
324             options->timeout = 4;
325         }
326     }
327
328     if ((c = getoption(buf, "-sleep"))) {
329         options->disconnected = options->sleep = atoi(c) * 120;
330         if (options->sleep <= 4) {
331             options->disconnected = options->sleep = 4;
332         }
333     }
334
335     if ((c = getoption(buf, "-dsireadbuf"))) {
336         options->dsireadbuf = atoi(c);
337         if (options->dsireadbuf < 6)
338             options->dsireadbuf = 6;
339     }
340
341     if ((c = getoption(buf, "-server_quantum")))
342         options->server_quantum = strtoul(c, NULL, 0);
343
344     if ((c = getoption(buf, "-volnamelen"))) {
345         options->volnamelen = atoi(c);
346         if (options->volnamelen < 8) {
347             options->volnamelen = 8; /* max mangled volname "???#FFFF" */
348         }
349         if (options->volnamelen > 255) {
350             options->volnamelen = 255; /* AFP3 spec */
351         }
352     }
353
354     /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
355     c = buf;
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"))) {
359         char *optstr;
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);
365             setuplog(optstr);
366             c += sizeof("-setuplog");
367         }
368     }
369
370     if ((c = getoption(buf, "-unsetuplog")))
371       unsetuplog(c);
372
373 #ifdef ADMIN_GRP
374     if ((c = getoption(buf, "-admingroup"))) {
375         struct group *gr = getgrnam(c);
376         if (gr != NULL) {
377             options->admingid = gr->gr_gid;
378         }
379     }
380 #endif /* ADMIN_GRP */
381
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");
389                 exit(-1);
390         }
391         snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
392         putenv(options->k5keytab);
393         /* setenv( "KRB5_KTNAME", c, 1 ); */
394     }
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;
401
402     if ((c = getoption(buf, "-ipaddr"))) {
403 #if 0
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;
409         }
410         else {
411             LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
412         }
413 #endif
414         options->ipaddr = strdup(c);
415     }
416
417     /* FIXME CNID Cnid_srv is a server attribute */
418     if ((c = getoption(buf, "-cnidserver"))) {
419         char *p = strrchr(c, ':');
420         if (p)
421             *p = 0;
422         Cnid_srv = strdup(c);
423         if (p)
424             Cnid_port = strdup(p + 1);
425         LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
426     }
427
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;
434
435     /* do a little checking for the domain name. */
436     if ((c = getoption(buf, "-fqdn"))) {
437         char *p = strchr(c, ':');
438         if (p)
439             *p = '\0';
440         if (gethostbyname(c)) {
441             if (p)
442                 *p = ':';
443             if ((opt = strdup(c)))
444                 options->fqdn = opt;
445         }
446         else {
447             LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
448         }
449     }
450
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);
455         }
456         else {
457             if ((opt = strdup(c)))
458                 options->unixcodepage = opt;
459         }
460     }
461         
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);
466         }
467         else {
468             if ((opt = strdup(c)))
469                 options->maccodepage = opt;
470         }
471     }
472     
473     if ((c = strstr(buf, "-closevol"))) {
474         options->closevol= 1;
475     }
476
477     if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
478        options->ntdomain = opt;
479
480     if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
481        options->ntseparator = opt;
482
483     if ((c = getoption(buf, "-dircachesize")))
484         options->dircachesize = atoi(c);
485      
486     if ((c = getoption(buf, "-tcpsndbuf")))
487         options->tcp_sndbuf = atoi(c);
488
489     if ((c = getoption(buf, "-tcprcvbuf")))
490         options->tcp_rcvbuf = atoi(c);
491
492         if ((c = getoption(buf, "-fcelistener"))) {
493                 LOG(log_note, logtype_afpd, "Adding fce listener \"%s\"", c);
494                 fce_add_udp_socket(c);
495         }
496         if ((c = getoption(buf, "-fcecoalesce"))) {
497                 LOG(log_note, logtype_afpd, "Fce coalesce: %s", c);
498                 fce_set_coalesce(c);
499         }
500         if ((c = getoption(buf, "-fceevents"))) {
501                 LOG(log_note, logtype_afpd, "Fce events: %s", c);
502                 fce_set_events(c);
503         }
504
505     if ((c = getoption(buf, "-mimicmodel")) && (opt = strdup(c)))
506        options->mimicmodel = opt;
507
508     return 1;
509 }
510
511 /*
512  * Show version information about afpd.
513  * Used by "afp -v".
514  */
515 static void show_version( void )
516 {
517         printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
518
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" );
523
524         puts( "afpd has been compiled with support for these features:\n" );
525
526         printf( "        AFP3.x support:\tYes\n" );
527         printf( "        TCP/IP Support:\t" );
528         puts( "Yes" );
529
530         printf( "DDP(AppleTalk) Support:\t" );
531 #ifdef NO_DDP
532         puts( "No" );
533 #else
534         puts( "Yes" );
535 #endif
536
537         printf( "         CNID backends:\t" );
538 #ifdef CNID_BACKEND_CDB
539         printf( "cdb ");
540 #endif
541 #ifdef CNID_BACKEND_DB3
542         printf( "db3 " );
543 #endif
544 #ifdef CNID_BACKEND_DBD
545 #ifdef CNID_BACKEND_DBD_TXN
546         printf( "dbd-txn " );
547 #else
548         printf( "dbd " );
549 #endif
550 #endif
551 #ifdef CNID_BACKEND_HASH
552         printf( "hash " );
553 #endif
554 #ifdef CNID_BACKEND_LAST
555         printf( "last " );
556 #endif
557 #ifdef CNID_BACKEND_MTAB
558         printf( "mtab " );
559 #endif
560 #ifdef CNID_BACKEND_TDB
561         printf( "tdb " );
562 #endif
563         puts( "" );
564 }
565
566 /*
567  * Show extended version information about afpd and Netatalk.
568  * Used by "afp -V".
569  */
570 static void show_version_extended(void )
571 {
572         show_version( );
573
574         printf( "           SLP support:\t" );
575 #ifdef USE_SRVLOC
576         puts( "Yes" );
577 #else
578         puts( "No" );
579 #endif
580
581         printf( "      Zeroconf support:\t" );
582 #ifdef USE_ZEROCONF
583         puts( "Yes" );
584 #else
585         puts( "No" );
586 #endif
587
588         printf( "  TCP wrappers support:\t" );
589 #ifdef TCPWRAP
590         puts( "Yes" );
591 #else
592         puts( "No" );
593 #endif
594
595         printf( "         Quota support:\t" );
596 #ifndef NO_QUOTA_SUPPORT
597         puts( "Yes" );
598 #else
599         puts( "No" );
600 #endif
601
602         printf( "   Admin group support:\t" );
603 #ifdef ADMIN_GRP
604         puts( "Yes" );
605 #else
606         puts( "No" );
607 #endif
608
609         printf( "    Valid shell checks:\t" );
610 #ifndef DISABLE_SHELLCHECK
611         puts( "Yes" );
612 #else
613         puts( "No" );
614 #endif
615
616         printf( "      cracklib support:\t" );
617 #ifdef USE_CRACKLIB
618         puts( "Yes" );
619 #else
620         puts( "No" );
621 #endif
622
623         printf( "        Dropbox kludge:\t" );
624 #ifdef DROPKLUDGE
625         puts( "Yes" );
626 #else
627         puts( "No" );
628 #endif
629
630         printf( "  Force volume uid/gid:\t" );
631 #ifdef FORCE_UIDGID
632         puts( "Yes" );
633 #else
634         puts( "No" );
635 #endif
636
637         printf( "           ACL support:\t" );
638 #ifdef HAVE_ACLS
639         puts( "Yes" );
640 #else
641         puts( "No" );
642 #endif
643
644         printf( "            EA support:\t" );
645         puts( EA_MODULES );
646
647         printf( "          LDAP support:\t" );
648 #ifdef HAVE_LDAP
649         puts( "Yes" );
650 #else
651         puts( "No" );
652 #endif
653 }
654
655 /*
656  * Display compiled-in default paths
657  */
658 static void show_paths( void )
659 {
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 );
665 #ifdef HAVE_LDAP
666         printf( "         afp_ldap.conf:\t%s\n", _PATH_ACL_LDAPCONF );
667 #else
668         printf( "         afp_ldap.conf:\tnot supported\n");
669 #endif
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);
673 }
674
675 /*
676  * Display usage information about afpd.
677  */
678 static void show_usage( char *name )
679 {
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 );
684 }
685
686 int afp_options_parse(int ac, char **av, struct afp_options *options)
687 {
688     extern char *optarg;
689     extern int optind;
690
691     char *p;
692     char *tmp;  /* Used for error checking the result of strtol */
693     int c, err = 0;
694
695     if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
696         perror( "gethostname" );
697         return 0;
698     }
699     if (NULL != ( p = strchr(options->hostname, '.' )) ) {
700         *p = '\0';
701     }
702
703 #ifdef ultrix
704     if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
705         p = av[ 0 ];
706     } else {
707         p++;
708     }
709     openlog( p, LOG_PID ); /* ultrix only */
710 #endif /* ultrix */
711
712     while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
713         switch ( c ) {
714         case 'd' :
715             options->flags |= OPTION_DEBUG;
716             break;
717         case 'n' :
718             options->server = optarg;
719             break;
720         case 'f' :
721             options->defaultvol.name = optarg;
722             break;
723         case 's' :
724             options->systemvol.name = optarg;
725             break;
726         case 'u' :
727             options->flags |= OPTION_USERVOLFIRST;
728             break;
729         case 'c' :
730             options->connections = atoi( optarg );
731             break;
732         case 'g' :
733             options->guest = optarg;
734             break;
735
736         case 'P' :
737             options->pidfile = optarg;
738             break;
739
740         case 'p':
741             options->passwdbits |= PASSWD_NOSAVE;
742             break;
743         case 't':
744             options->passwdbits |= PASSWD_SET;
745             break;
746
747         case 'D':
748             options->transports &= ~AFPTRANS_DDP;
749             break;
750         case 'S':
751             options->port = optarg;
752             break;
753         case 'T':
754             options->transports &= ~AFPTRANS_TCP;
755             break;
756         case 'L':
757             options->loginmesg = optarg;
758             break;
759         case 'F':
760             options->configfile = optarg;
761             break;
762         case 'U':
763             options->uamlist = optarg;
764             break;
765         case 'v':       /* version */
766             show_version( ); puts( "" );
767             show_paths( ); puts( "" );
768             exit( 0 );
769             break;
770         case 'V':       /* extended version */
771             show_version_extended( ); puts( "" );
772             show_paths( ); puts( "" );
773             exit( 0 );
774             break;
775         case 'h':       /* usage */
776             show_usage( p );
777             exit( 0 );
778             break;
779         case 'I':
780             options->flags |= OPTION_CUSTOMICON;
781             break;
782         case 'm':
783             options->umask = strtoul(optarg, &tmp, 8);
784             if ((options->umask > 0777)) {
785                 fprintf(stderr, "%s: out of range umask setting provided\n", p);
786                 err++;
787             }
788             if (tmp[0] != '\0') {
789                 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
790                 err++;
791             }
792             break;
793         default :
794             err++;
795         }
796     }
797     if ( err || optind != ac ) {
798         show_usage( p );
799         exit( 2 );
800     }
801
802     return 1;
803 }