]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/afp_options.c
Completely disable all AppleTalk stuff if not enabled
[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     options->fce_fmodwait = 60; /* put fmod events 60 seconds on hold */
197 }
198
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
204  *
205  * NOTE: this ignores unknown options 
206  */
207 int afp_options_parseline(char *buf, struct afp_options *options)
208 {
209     char *c, *opt;
210
211     /* handle server */
212     if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
213         options->server = opt;
214
215     /* parse toggles */
216     if (strstr(buf, " -nodebug"))
217         options->flags &= ~OPTION_DEBUG;
218 #ifdef USE_SRVLOC
219     if (strstr(buf, " -slp"))
220         options->flags &= ~OPTION_NOSLP;
221 #endif
222 #ifdef USE_ZEROCONF
223     if (strstr(buf, " -nozeroconf"))
224         options->flags |= OPTION_NOZEROCONF;
225 #endif
226     if (strstr(buf, " -nouservolfirst"))
227         options->flags &= ~OPTION_USERVOLFIRST;
228     if (strstr(buf, " -uservolfirst"))
229         options->flags |= OPTION_USERVOLFIRST;
230     if (strstr(buf, " -nouservol"))
231         options->flags |= OPTION_NOUSERVOL;
232     if (strstr(buf, " -uservol"))
233         options->flags &= ~OPTION_NOUSERVOL;
234     if (strstr(buf, " -proxy"))
235         options->flags |= OPTION_PROXY;
236     if (strstr(buf, " -noicon"))
237         options->flags &= ~OPTION_CUSTOMICON;
238     if (strstr(buf, " -icon"))
239         options->flags |= OPTION_CUSTOMICON;
240     if (strstr(buf, " -advertise_ssh"))
241         options->flags |= OPTION_ANNOUNCESSH;
242     if (strstr(buf, " -noacl2maccess"))
243         options->flags &= ~OPTION_ACL2MACCESS;
244     if (strstr(buf, " -keepsessions")) {
245         default_options.flags |= OPTION_KEEPSESSIONS;
246         options->flags |= OPTION_KEEPSESSIONS;
247     }
248
249     /* passwd bits */
250     if (strstr(buf, " -nosavepassword"))
251         options->passwdbits |= PASSWD_NOSAVE;
252     if (strstr(buf, " -savepassword"))
253         options->passwdbits &= ~PASSWD_NOSAVE;
254     if (strstr(buf, " -nosetpassword"))
255         options->passwdbits &= ~PASSWD_SET;
256     if (strstr(buf, " -setpassword"))
257         options->passwdbits |= PASSWD_SET;
258
259     /* transports */
260     if (strstr(buf, " -transall"))
261         options->transports = AFPTRANS_ALL;
262     if (strstr(buf, " -notransall"))
263         options->transports = AFPTRANS_NONE;
264     if (strstr(buf, " -tcp"))
265         options->transports |= AFPTRANS_TCP;
266     if (strstr(buf, " -notcp"))
267         options->transports &= ~AFPTRANS_TCP;
268     if (strstr(buf, " -ddp"))
269         options->transports |= AFPTRANS_DDP;
270     if (strstr(buf, " -noddp"))
271         options->transports &= ~AFPTRANS_DDP;
272     if (strstr(buf, "-client_polling"))
273         options->server_notif = 0;
274
275     /* figure out options w/ values. currently, this will ignore the setting
276      * if memory is lacking. */
277
278     if ((c = getoption(buf, "-hostname"))) {
279         int len = strlen (c);
280         if (len <= MAXHOSTNAMELEN) {
281             memcpy(options->hostname, c, len);
282             options->hostname[len] = 0;
283         }
284         else
285             LOG(log_info, logtype_afpd, "WARNING: hostname %s is too long (%d)",c,len);
286     }
287
288     if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
289         options->defaultvol.name = opt;
290     if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
291         options->systemvol.name = opt;
292     if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c))) {
293         int i = 0, j = 0;
294         while (c[i]) {
295             if (c[i] != '\\') {
296                 opt[j++] = c[i];
297             } else {
298                 i++;
299                 if (c[i] == 'n')
300                     opt[j++] = '\n';
301             }
302             i++;
303         }
304         opt[j] = 0;
305         options->loginmesg = opt;
306         
307     }
308     if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
309         options->guest = opt;
310     if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
311         options->passwdfile = opt;
312     if ((c = getoption(buf, "-passwdminlen")))
313         options->passwdminlen = MIN(1, atoi(c));
314     if ((c = getoption(buf, "-loginmaxfail")))
315         options->loginmaxfail = atoi(c);
316     if ((c = getoption(buf, "-tickleval"))) {
317         options->tickleval = atoi(c);
318         if (options->tickleval <= 0) {
319             options->tickleval = 30;
320         }
321     }
322     if ((c = getoption(buf, "-timeout"))) {
323         options->timeout = atoi(c);
324         if (options->timeout <= 0) {
325             options->timeout = 4;
326         }
327     }
328
329     if ((c = getoption(buf, "-sleep"))) {
330         options->disconnected = options->sleep = atoi(c) * 120;
331         if (options->sleep <= 4) {
332             options->disconnected = options->sleep = 4;
333         }
334     }
335
336     if ((c = getoption(buf, "-dsireadbuf"))) {
337         options->dsireadbuf = atoi(c);
338         if (options->dsireadbuf < 6)
339             options->dsireadbuf = 6;
340     }
341
342     if ((c = getoption(buf, "-server_quantum")))
343         options->server_quantum = strtoul(c, NULL, 0);
344
345     if ((c = getoption(buf, "-volnamelen"))) {
346         options->volnamelen = atoi(c);
347         if (options->volnamelen < 8) {
348             options->volnamelen = 8; /* max mangled volname "???#FFFF" */
349         }
350         if (options->volnamelen > 255) {
351             options->volnamelen = 255; /* AFP3 spec */
352         }
353     }
354
355     /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
356     c = buf;
357     /* Now THIS is hokey! Multiple occurrences are not supported by our current code, */
358     /* so I have to loop myself. */
359     while (NULL != (c = strstr(c, "-setuplog"))) {
360         char *optstr;
361         if ((optstr = getoption(c, "-setuplog"))) {
362             /* hokey2: options->logconfig must be converted to store an array of logstrings */
363             if (options->logconfig)
364                 free(options->logconfig);
365             options->logconfig = strdup(optstr);
366             setuplog(optstr);
367             c += sizeof("-setuplog");
368         }
369     }
370
371     if ((c = getoption(buf, "-unsetuplog")))
372       unsetuplog(c);
373
374 #ifdef ADMIN_GRP
375     if ((c = getoption(buf, "-admingroup"))) {
376         struct group *gr = getgrnam(c);
377         if (gr != NULL) {
378             options->admingid = gr->gr_gid;
379         }
380     }
381 #endif /* ADMIN_GRP */
382
383     if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
384         options->k5service = opt;
385     if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
386         options->k5realm = opt;
387     if ((c = getoption(buf, "-k5keytab"))) {
388         if ( NULL == (options->k5keytab = (char *) malloc(sizeof(char)*(strlen(c)+14)) )) {
389                 LOG(log_error, logtype_afpd, "malloc failed");
390                 exit(-1);
391         }
392         snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
393         putenv(options->k5keytab);
394         /* setenv( "KRB5_KTNAME", c, 1 ); */
395     }
396     if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
397         options->authprintdir = opt;
398     if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
399         options->uampath = opt;
400     if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
401         options->uamlist = opt;
402
403     if ((c = getoption(buf, "-ipaddr"))) {
404 #if 0
405         struct in_addr inaddr;
406         if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
407             if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
408                 LOG(log_info, logtype_afpd, "WARNING: can't find %s", opt);
409             options->ipaddr = opt;
410         }
411         else {
412             LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
413         }
414 #endif
415         options->ipaddr = strdup(c);
416     }
417
418     /* FIXME CNID Cnid_srv is a server attribute */
419     if ((c = getoption(buf, "-cnidserver"))) {
420         char *p = strrchr(c, ':');
421         if (p)
422             *p = 0;
423         Cnid_srv = strdup(c);
424         if (p)
425             Cnid_port = strdup(p + 1);
426         LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
427     }
428
429     if ((c = getoption(buf, "-port")))
430         options->port = strdup(c);
431 #ifndef NO_DDP
432     if ((c = getoption(buf, "-ddpaddr")))
433         atalk_aton(c, &options->ddpaddr);
434 #endif
435     if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
436         options->signatureopt = opt;
437
438     /* do a little checking for the domain name. */
439     if ((c = getoption(buf, "-fqdn"))) {
440         char *p = strchr(c, ':');
441         if (p)
442             *p = '\0';
443         if (gethostbyname(c)) {
444             if (p)
445                 *p = ':';
446             if ((opt = strdup(c)))
447                 options->fqdn = opt;
448         }
449         else {
450             LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
451         }
452     }
453
454     if ((c = getoption(buf, "-unixcodepage"))) {
455         if ((charset_t)-1  == ( options->unixcharset = add_charset(c)) ) {
456             options->unixcharset = CH_UNIX;
457             LOG(log_warning, logtype_afpd, "setting Unix codepage to '%s' failed", c);
458         }
459         else {
460             if ((opt = strdup(c)))
461                 options->unixcodepage = opt;
462         }
463     }
464         
465     if ((c = getoption(buf, "-maccodepage"))) {
466         if ((charset_t)-1 == ( options->maccharset = add_charset(c)) ) {
467             options->maccharset = CH_MAC;
468             LOG(log_warning, logtype_afpd, "setting Mac codepage to '%s' failed", c);
469         }
470         else {
471             if ((opt = strdup(c)))
472                 options->maccodepage = opt;
473         }
474     }
475     
476     if ((c = strstr(buf, "-closevol"))) {
477         options->closevol= 1;
478     }
479
480     if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
481        options->ntdomain = opt;
482
483     if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
484        options->ntseparator = opt;
485
486     if ((c = getoption(buf, "-dircachesize")))
487         options->dircachesize = atoi(c);
488      
489     if ((c = getoption(buf, "-tcpsndbuf")))
490         options->tcp_sndbuf = atoi(c);
491
492     if ((c = getoption(buf, "-tcprcvbuf")))
493         options->tcp_rcvbuf = atoi(c);
494
495         if ((c = getoption(buf, "-fcelistener"))) {
496                 LOG(log_note, logtype_afpd, "Adding fce listener \"%s\"", c);
497                 fce_add_udp_socket(c);
498         }
499         if ((c = getoption(buf, "-fcecoalesce"))) {
500                 LOG(log_note, logtype_afpd, "Fce coalesce: %s", c);
501                 fce_set_coalesce(c);
502         }
503         if ((c = getoption(buf, "-fceevents"))) {
504                 LOG(log_note, logtype_afpd, "Fce events: %s", c);
505                 fce_set_events(c);
506         }
507
508     if ((c = getoption(buf, "-fceholdfmod")))
509         options->fce_fmodwait = atoi(c);
510
511     if ((c = getoption(buf, "-mimicmodel")) && (opt = strdup(c)))
512        options->mimicmodel = opt;
513
514     return 1;
515 }
516
517 /*
518  * Show version information about afpd.
519  * Used by "afp -v".
520  */
521 static void show_version( void )
522 {
523         int num, i;
524
525         printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
526
527         puts( "This program is free software; you can redistribute it and/or modify it under" );
528         puts( "the terms of the GNU General Public License as published by the Free Software" );
529         puts( "Foundation; either version 2 of the License, or (at your option) any later" );
530         puts( "version. Please see the file COPYING for further information and details.\n" );
531
532         puts( "afpd has been compiled with support for these features:\n" );
533
534         num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
535         printf( "          AFP versions:\t" );
536         for ( i = 0; i < num; i++ ) {
537                 printf( "%d.%d ", afp_versions[ i ].av_number/10, afp_versions[ i ].av_number%10);
538         }
539         puts( "" );
540
541         printf( "DDP(AppleTalk) Support:\t" );
542 #ifdef NO_DDP
543         puts( "No" );
544 #else
545         puts( "Yes" );
546 #endif
547
548         printf( "         CNID backends:\t" );
549 #ifdef CNID_BACKEND_CDB
550         printf( "cdb ");
551 #endif
552 #ifdef CNID_BACKEND_DB3
553         printf( "db3 " );
554 #endif
555 #ifdef CNID_BACKEND_DBD
556 #ifdef CNID_BACKEND_DBD_TXN
557         printf( "dbd-txn " );
558 #else
559         printf( "dbd " );
560 #endif
561 #endif
562 #ifdef CNID_BACKEND_HASH
563         printf( "hash " );
564 #endif
565 #ifdef CNID_BACKEND_LAST
566         printf( "last " );
567 #endif
568 #ifdef CNID_BACKEND_MTAB
569         printf( "mtab " );
570 #endif
571 #ifdef CNID_BACKEND_TDB
572         printf( "tdb " );
573 #endif
574         puts( "" );
575 }
576
577 /*
578  * Show extended version information about afpd and Netatalk.
579  * Used by "afp -V".
580  */
581 static void show_version_extended(void )
582 {
583         show_version( );
584
585         printf( "           SLP support:\t" );
586 #ifdef USE_SRVLOC
587         puts( "Yes" );
588 #else
589         puts( "No" );
590 #endif
591
592         printf( "      Zeroconf support:\t" );
593 #ifdef USE_ZEROCONF
594         puts( "Yes" );
595 #else
596         puts( "No" );
597 #endif
598
599         printf( "  TCP wrappers support:\t" );
600 #ifdef TCPWRAP
601         puts( "Yes" );
602 #else
603         puts( "No" );
604 #endif
605
606         printf( "         Quota support:\t" );
607 #ifndef NO_QUOTA_SUPPORT
608         puts( "Yes" );
609 #else
610         puts( "No" );
611 #endif
612
613         printf( "   Admin group support:\t" );
614 #ifdef ADMIN_GRP
615         puts( "Yes" );
616 #else
617         puts( "No" );
618 #endif
619
620         printf( "    Valid shell checks:\t" );
621 #ifndef DISABLE_SHELLCHECK
622         puts( "Yes" );
623 #else
624         puts( "No" );
625 #endif
626
627         printf( "      cracklib support:\t" );
628 #ifdef USE_CRACKLIB
629         puts( "Yes" );
630 #else
631         puts( "No" );
632 #endif
633
634         printf( "        Dropbox kludge:\t" );
635 #ifdef DROPKLUDGE
636         puts( "Yes" );
637 #else
638         puts( "No" );
639 #endif
640
641         printf( "  Force volume uid/gid:\t" );
642 #ifdef FORCE_UIDGID
643         puts( "Yes" );
644 #else
645         puts( "No" );
646 #endif
647
648         printf( "           ACL support:\t" );
649 #ifdef HAVE_ACLS
650         puts( "Yes" );
651 #else
652         puts( "No" );
653 #endif
654
655         printf( "            EA support:\t" );
656         puts( EA_MODULES );
657
658         printf( "          LDAP support:\t" );
659 #ifdef HAVE_LDAP
660         puts( "Yes" );
661 #else
662         puts( "No" );
663 #endif
664 }
665
666 /*
667  * Display compiled-in default paths
668  */
669 static void show_paths( void )
670 {
671         printf( "             afpd.conf:\t%s\n", _PATH_AFPDCONF );
672         printf( "   AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
673         printf( "  AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
674         printf( "    afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
675         printf( "      afp_voluuid.conf:\t%s\n", _PATH_AFPDUUIDCONF );
676 #ifdef HAVE_LDAP
677         printf( "         afp_ldap.conf:\t%s\n", _PATH_ACL_LDAPCONF );
678 #else
679         printf( "         afp_ldap.conf:\tnot supported\n");
680 #endif
681         printf( "       UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
682         printf( "  Server messages path:\t%s\n", SERVERTEXT);
683         printf( "              lockfile:\t%s\n", _PATH_AFPDLOCK);
684 }
685
686 /*
687  * Display usage information about afpd.
688  */
689 static void show_usage( char *name )
690 {
691         fprintf( stderr, "Usage:\t%s [-duptDTI] [-f defaultvolumes] [-s systemvolumes] [-n nbpname]\n", name );
692         fprintf( stderr, "\t     [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
693         fprintf( stderr, "\t     [-F configfile] [-U uams] [-m umask]\n" );
694         fprintf( stderr, "\t%s -h|-v|-V\n", name );
695 }
696
697 int afp_options_parse(int ac, char **av, struct afp_options *options)
698 {
699     extern char *optarg;
700     extern int optind;
701
702     char *p;
703     char *tmp;  /* Used for error checking the result of strtol */
704     int c, err = 0;
705
706     if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
707         perror( "gethostname" );
708         return 0;
709     }
710     if (NULL != ( p = strchr(options->hostname, '.' )) ) {
711         *p = '\0';
712     }
713
714 #ifdef ultrix
715     if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
716         p = av[ 0 ];
717     } else {
718         p++;
719     }
720     openlog( p, LOG_PID ); /* ultrix only */
721 #endif /* ultrix */
722
723     while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
724         switch ( c ) {
725         case 'd' :
726             options->flags |= OPTION_DEBUG;
727             break;
728         case 'n' :
729             options->server = optarg;
730             break;
731         case 'f' :
732             options->defaultvol.name = optarg;
733             break;
734         case 's' :
735             options->systemvol.name = optarg;
736             break;
737         case 'u' :
738             options->flags |= OPTION_USERVOLFIRST;
739             break;
740         case 'c' :
741             options->connections = atoi( optarg );
742             break;
743         case 'g' :
744             options->guest = optarg;
745             break;
746
747         case 'P' :
748             options->pidfile = optarg;
749             break;
750
751         case 'p':
752             options->passwdbits |= PASSWD_NOSAVE;
753             break;
754         case 't':
755             options->passwdbits |= PASSWD_SET;
756             break;
757
758         case 'D':
759             options->transports &= ~AFPTRANS_DDP;
760             break;
761         case 'S':
762             options->port = optarg;
763             break;
764         case 'T':
765             options->transports &= ~AFPTRANS_TCP;
766             break;
767         case 'L':
768             options->loginmesg = optarg;
769             break;
770         case 'F':
771             options->configfile = optarg;
772             break;
773         case 'U':
774             options->uamlist = optarg;
775             break;
776         case 'v':       /* version */
777             show_version( ); puts( "" );
778             show_paths( ); puts( "" );
779             exit( 0 );
780             break;
781         case 'V':       /* extended version */
782             show_version_extended( ); puts( "" );
783             show_paths( ); puts( "" );
784             exit( 0 );
785             break;
786         case 'h':       /* usage */
787             show_usage( p );
788             exit( 0 );
789             break;
790         case 'I':
791             options->flags |= OPTION_CUSTOMICON;
792             break;
793         case 'm':
794             options->umask = strtoul(optarg, &tmp, 8);
795             if ((options->umask > 0777)) {
796                 fprintf(stderr, "%s: out of range umask setting provided\n", p);
797                 err++;
798             }
799             if (tmp[0] != '\0') {
800                 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
801                 err++;
802             }
803             break;
804         default :
805             err++;
806         }
807     }
808     if ( err || optind != ac ) {
809         show_usage( p );
810         exit( 2 );
811     }
812
813     return 1;
814 }