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