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