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