2 * $Id: afp_options.c,v 1.20 2002-02-16 11:04:50 srittau Exp $
4 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
5 * Copyright (c) 1990,1993 Regents of The University of Michigan.
6 * All Rights Reserved. See COPYRIGHT.
8 * modified from main.c. this handles afp options.
13 #endif /* HAVE_CONFIG_H */
21 #else /* STDC_HEADERS */
25 #endif /* HAVE_STRCHR */
26 char *strchr (), *strrchr ();
28 #define memcpy(d,s,n) bcopy ((s), (d), (n))
29 #define memmove(d,s,n) bcopy ((s), (d), (n))
30 #endif /* ! HAVE_MEMCPY */
31 #endif /* STDC_HEADERS */
36 #endif /* HAVE_UNISTD_H */
37 #include <sys/param.h>
38 #include <sys/socket.h>
39 #include <atalk/logger.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
45 #endif /* HAVE_NETDB_H */
47 #include <atalk/paths.h>
48 #include <atalk/util.h>
53 #include <atalk/compat.h>
57 #include <sys/types.h>
58 #endif /* ADMIN_GRP */
61 #define MIN(a, b) ((a) < (b) ? (a) : (b))
64 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:Ivm:"
67 /* return an option. this uses an internal array, so it's necessary
68 * to duplicate it if you want to hold it for long. this is probably
70 static char *getoption(char *buf, const char *option)
72 static char string[LENGTH + 1];
76 if (option && (buf = strstr(buf, option)))
77 buf = strpbrk(buf, " \t");
79 while (buf && isspace(*buf))
85 /* search for any quoted stuff */
86 if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
88 len = MIN(end - buf, LENGTH);
89 } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
90 len = MIN(end - buf, LENGTH);
92 len = MIN(strlen(buf), LENGTH);
94 strncpy(string, buf, len);
99 /* get rid of any allocated afp_option buffers. */
100 void afp_options_free(struct afp_options *opt,
101 const struct afp_options *save)
103 if (opt->defaultvol && (opt->defaultvol != save->defaultvol))
104 free(opt->defaultvol);
105 if (opt->systemvol && (opt->systemvol != save->systemvol))
106 free(opt->systemvol);
107 if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
108 free(opt->loginmesg);
109 if (opt->guest && (opt->guest != save->guest))
111 if (opt->server && (opt->server != save->server))
113 if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
115 if (opt->fqdn && (opt->fqdn != save->fqdn))
117 if (opt->uampath && (opt->uampath != save->uampath))
119 if (opt->uamlist && (opt->uamlist != save->uamlist))
121 if (opt->nlspath && (opt->nlspath != save->nlspath))
123 if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
124 free(opt->passwdfile);
127 /* initialize options */
128 void afp_options_init(struct afp_options *options)
130 memset(options, 0, sizeof(struct afp_options));
131 options->connections = 20;
132 options->pidfile = _PATH_AFPDLOCK;
133 options->defaultvol = _PATH_AFPDDEFVOL;
134 options->systemvol = _PATH_AFPDSYSVOL;
135 options->configfile = _PATH_AFPDCONF;
136 options->nlspath = _PATH_AFPDNLSPATH;
137 options->uampath = _PATH_AFPDUAMPATH;
138 options->uamlist = "uams_clrtxt.so,uams_dhx.so";
139 options->guest = "nobody";
140 options->loginmesg = "";
141 options->transports = AFPTRANS_ALL;
142 options->passwdfile = _PATH_AFPDPWFILE;
143 options->tickleval = 30;
144 options->timeout = 4;
145 options->server_notif = 1;
146 options->authprintdir = NULL;
149 options->admingid = 0;
150 #endif /* ADMIN_GRP */
153 /* parse an afpd.conf line. i'm doing it this way because it's
154 * easy. it is, however, massively hokey. sample afpd.conf:
155 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
156 * "private machine"@zone2 -noguest -port 11012
157 * server2 -nocleartxt -nodsi
159 * NOTE: this ignores unknown options
161 int afp_options_parseline(char *buf, struct afp_options *options)
166 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
167 options->server = opt;
170 if (strstr(buf, " -nodebug"))
171 options->flags &= ~OPTION_DEBUG;
173 if (strstr(buf, " -nouservolfirst"))
174 options->flags &= ~OPTION_USERVOLFIRST;
175 if (strstr(buf, " -uservolfirst"))
176 options->flags |= OPTION_USERVOLFIRST;
177 if (strstr(buf, " -nouservol"))
178 options->flags |= OPTION_NOUSERVOL;
179 if (strstr(buf, " -uservol"))
180 options->flags &= ~OPTION_NOUSERVOL;
181 if (strstr(buf, " -proxy"))
182 options->flags |= OPTION_PROXY;
183 if (strstr(buf, " -noicon"))
184 options->flags &= ~OPTION_CUSTOMICON;
185 if (strstr(buf, " -icon"))
186 options->flags |= OPTION_CUSTOMICON;
189 if (strstr(buf, " -nosavepassword"))
190 options->passwdbits |= PASSWD_NOSAVE;
191 if (strstr(buf, " -savepassword"))
192 options->passwdbits &= ~PASSWD_NOSAVE;
193 if (strstr(buf, " -nosetpassword"))
194 options->passwdbits &= ~PASSWD_SET;
195 if (strstr(buf, " -setpassword"))
196 options->passwdbits |= PASSWD_SET;
199 if (strstr(buf, " -transall"))
200 options->transports = AFPTRANS_ALL;
201 if (strstr(buf, " -notransall"))
202 options->transports = AFPTRANS_NONE;
203 if (strstr(buf, " -tcp"))
204 options->transports |= AFPTRANS_TCP;
205 if (strstr(buf, " -notcp"))
206 options->transports &= ~AFPTRANS_TCP;
207 if (strstr(buf, " -ddp"))
208 options->transports |= AFPTRANS_DDP;
209 if (strstr(buf, " -noddp"))
210 options->transports &= ~AFPTRANS_DDP;
211 if (strstr(buf, "-client_polling"))
212 options->server_notif = 0;
214 /* figure out options w/ values. currently, this will ignore the setting
215 * if memory is lacking. */
216 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
217 options->defaultvol = opt;
218 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
219 options->systemvol = opt;
220 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c)))
221 options->loginmesg = opt;
222 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
223 options->guest = opt;
224 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
225 options->passwdfile = opt;
226 if ((c = getoption(buf, "-passwdminlen")))
227 options->passwdminlen = MIN(1, atoi(c));
228 if ((c = getoption(buf, "-loginmaxfail")))
229 options->loginmaxfail = atoi(c);
230 if ((c = getoption(buf, "-tickleval"))) {
231 options->tickleval = atoi(c);
232 if (options->tickleval <= 0) {
233 options->tickleval = 30;
236 if ((c = getoption(buf, "-timeout"))) {
237 options->timeout = atoi(c);
238 if (options->timeout <= 0) {
239 options->timeout = 4;
243 if ((c = getoption(buf, "-server_quantum")))
244 options->server_quantum = strtoul(c, NULL, 0);
248 if ((c = getoption(buf, "-admingroup"))) {
249 struct group *gr = getgrnam(c);
251 options->admingid = gr->gr_gid;
254 #endif /* ADMIN_GRP */
256 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
257 options->authprintdir = opt;
258 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
259 options->uampath = opt;
260 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
261 options->uamlist = opt;
262 if ((c = getoption(buf, "-nlspath")) && (opt = strdup(c)))
263 options->nlspath = opt;
265 if ((c = getoption(buf, "-ipaddr"))) {
266 struct in_addr inaddr;
267 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
268 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
269 LOG(log_info, logtype_default, "WARNING: can't find %s\n", opt);
270 options->ipaddr = opt;
274 if ((c = getoption(buf, "-port")))
275 options->port = atoi(c);
276 if ((c = getoption(buf, "-ddpaddr")))
277 atalk_aton(c, &options->ddpaddr);
279 /* do a little checking for the domain name. */
280 if ((c = getoption(buf, "-fqdn"))) {
281 char *p = strchr(c, ':');
284 if (gethostbyname(c)) {
287 if ((opt = strdup(c)))
295 int afp_options_parse(int ac, char **av, struct afp_options *options)
301 char *tmp; /* Used for error checking the result of strtol */
304 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
305 perror( "gethostname" );
308 if (( p = strchr(options->hostname, '.' )) != 0 ) {
312 if (( p = strrchr( av[ 0 ], '/' )) == NULL ) {
318 while (( c = getopt( ac, av, OPTIONS )) != EOF ) {
321 options->flags |= OPTION_DEBUG;
324 options->server = optarg;
327 options->defaultvol = optarg;
330 options->systemvol = optarg;
333 options->flags |= OPTION_USERVOLFIRST;
336 options->connections = atoi( optarg );
339 options->guest = optarg;
343 options->pidfile = optarg;
347 options->passwdbits |= PASSWD_NOSAVE;
350 options->passwdbits |= PASSWD_SET;
354 options->transports &= ~AFPTRANS_DDP;
357 options->port = atoi(optarg);
360 options->transports &= ~AFPTRANS_TCP;
363 options->loginmesg = optarg;
366 options->configfile = optarg;
369 options->uamlist = optarg;
371 case 'v': /* version */
372 printf( "afpd (version %s)\n", VERSION );
376 options->flags |= OPTION_CUSTOMICON;
379 options->umask = strtoul(optarg, &tmp, 8);
380 if ((options->umask > 0777)) {
381 fprintf(stderr, "%s: out of range umask setting provided\n", p);
384 if (tmp[0] != '\0') {
385 fprintf(stderr, "%s: invalid characters in umask setting provided\n", p);
393 if ( err || optind != ac ) {
395 "Usage:\t%s [ -dpDTIt ] [ -n nbpname ] [ -f defvols ] \
396 [ -P pidfile ] [ -s sysvols ] \n", p );
398 "\t[ -u ] [ -c maxconn ] [ -g guest ] \
399 [ -S port ] [ -L loginmesg ] [ -F configfile ] [ -U uamlist ]\n" );
404 openlog( p, LOG_PID ); /* ultrix only */
407 syslog_setup(log_debug, logtype_default, logoption_ndelay|logoption_pid, logfacility_daemon);