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