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