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