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