2 * $Id: afp_options.c,v 1.7 2001-06-20 18:33:04 rufustfirefly 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 #endif /* HAVE_UNISTD_H */
22 #include <sys/param.h>
23 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <arpa/inet.h>
30 #endif /* HAVE_NETDB_H */
32 #include <atalk/paths.h>
33 #include <atalk/util.h>
38 #include <atalk/compat.h>
42 #include <sys/types.h>
43 #endif /* ADMIN_GRP */
46 #define MIN(a, b) ((a) < (b) ? (a) : (b))
49 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:I"
52 /* return an option. this uses an internal array, so it's necessary
53 * to duplicate it if you want to hold it for long. this is probably
55 static char *getoption(char *buf, const char *option)
57 static char string[LENGTH + 1];
61 if (option && (buf = strstr(buf, option)))
62 buf = strpbrk(buf, " \t");
64 while (buf && isspace(*buf))
70 /* search for any quoted stuff */
71 if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
73 len = MIN(end - buf, LENGTH);
74 } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
75 len = MIN(end - buf, LENGTH);
77 len = MIN(strlen(buf), LENGTH);
79 strncpy(string, buf, len);
84 /* get rid of any allocated afp_option buffers. */
85 void afp_options_free(struct afp_options *opt,
86 const struct afp_options *save)
88 if (opt->defaultvol && (opt->defaultvol != save->defaultvol))
89 free(opt->defaultvol);
90 if (opt->systemvol && (opt->systemvol != save->systemvol))
92 if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
94 if (opt->guest && (opt->guest != save->guest))
96 if (opt->server && (opt->server != save->server))
98 if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
100 if (opt->fqdn && (opt->fqdn != save->fqdn))
102 if (opt->uampath && (opt->uampath != save->uampath))
104 if (opt->uamlist && (opt->uamlist != save->uamlist))
106 if (opt->nlspath && (opt->nlspath != save->nlspath))
108 if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
109 free(opt->passwdfile);
112 /* initialize options */
113 void afp_options_init(struct afp_options *options)
115 memset(options, 0, sizeof(struct afp_options));
116 options->connections = 20;
117 options->pidfile = _PATH_AFPDLOCK;
118 options->defaultvol = _PATH_AFPDDEFVOL;
119 options->systemvol = _PATH_AFPDSYSVOL;
120 options->configfile = _PATH_AFPDCONF;
121 options->nlspath = _PATH_AFPDNLSPATH;
122 options->uampath = _PATH_AFPDUAMPATH;
123 options->uamlist = "uams_guest.so,uams_clrtxt.so,uams_dhx.so";
124 options->guest = "nobody";
125 options->loginmesg = "";
126 options->transports = AFPTRANS_ALL;
127 options->passwdfile = _PATH_AFPDPWFILE;
128 options->tickleval = 30;
129 options->authprintdir = NULL;
131 options->admingid = 0;
132 #endif /* ADMIN_GRP */
135 /* parse an afpd.conf line. i'm doing it this way because it's
136 * easy. it is, however, massively hokey. sample afpd.conf:
137 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
138 * "private machine"@zone2 -noguest -port 11012
139 * server2 -nocleartxt -nodsi
141 * NOTE: this ignores unknown options
143 int afp_options_parseline(char *buf, struct afp_options *options)
148 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
149 options->server = opt;
152 if (strstr(buf, " -nodebug"))
153 options->flags &= ~OPTION_DEBUG;
155 if (strstr(buf, " -nouservolfirst"))
156 options->flags &= ~OPTION_USERVOLFIRST;
157 if (strstr(buf, " -uservolfirst"))
158 options->flags |= OPTION_USERVOLFIRST;
159 if (strstr(buf, " -nouservol"))
160 options->flags |= OPTION_NOUSERVOL;
161 if (strstr(buf, " -uservol"))
162 options->flags &= ~OPTION_NOUSERVOL;
163 if (strstr(buf, " -proxy"))
164 options->flags |= OPTION_PROXY;
165 if (strstr(buf, " -noicon"))
166 options->flags &= ~OPTION_CUSTOMICON;
167 if (strstr(buf, " -icon"))
168 options->flags |= OPTION_CUSTOMICON;
171 if (strstr(buf, " -nosavepassword"))
172 options->passwdbits |= PASSWD_NOSAVE;
173 if (strstr(buf, " -savepassword"))
174 options->passwdbits &= ~PASSWD_NOSAVE;
175 if (strstr(buf, " -nosetpassword"))
176 options->passwdbits &= ~PASSWD_SET;
177 if (strstr(buf, " -setpassword"))
178 options->passwdbits |= PASSWD_SET;
181 if (strstr(buf, " -transall"))
182 options->transports = AFPTRANS_ALL;
183 if (strstr(buf, " -notransall"))
184 options->transports = AFPTRANS_NONE;
185 if (strstr(buf, " -tcp"))
186 options->transports |= AFPTRANS_TCP;
187 if (strstr(buf, " -notcp"))
188 options->transports &= ~AFPTRANS_TCP;
189 if (strstr(buf, " -ddp"))
190 options->transports |= AFPTRANS_DDP;
191 if (strstr(buf, " -noddp"))
192 options->transports &= ~AFPTRANS_DDP;
194 /* figure out options w/ values. currently, this will ignore the setting
195 * if memory is lacking. */
196 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
197 options->defaultvol = opt;
198 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
199 options->systemvol = opt;
200 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c)))
201 options->loginmesg = opt;
202 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
203 options->guest = opt;
204 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
205 options->passwdfile = opt;
206 if ((c = getoption(buf, "-passwdminlen")))
207 options->passwdminlen = MIN(1, atoi(c));
208 if ((c = getoption(buf, "-loginmaxfail")))
209 options->loginmaxfail = atoi(c);
210 if ((c = getoption(buf, "-tickleval")))
211 options->tickleval = atoi(c);
213 if ((c = getoption(buf, "-server_quantum")))
214 options->server_quantum = strtoul(c, NULL, 0);
218 if ((c = getoption(buf, "-admingroup"))) {
219 struct group *gr = getgrnam(c);
221 options->admingid = gr->gr_gid;
224 #endif /* ADMIN_GRP */
226 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
227 options->authprintdir = opt;
228 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
229 options->uampath = opt;
230 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
231 options->uamlist = opt;
232 if ((c = getoption(buf, "-nlspath")) && (opt = strdup(c)))
233 options->nlspath = opt;
235 if ((c = getoption(buf, "-ipaddr"))) {
236 struct in_addr inaddr;
237 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
238 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
239 syslog(LOG_INFO, "WARNING: can't find %s\n", opt);
240 options->ipaddr = opt;
244 if ((c = getoption(buf, "-port")))
245 options->port = atoi(c);
246 if ((c = getoption(buf, "-ddpaddr")))
247 atalk_aton(c, &options->ddpaddr);
249 /* do a little checking for the domain name. */
250 if ((c = getoption(buf, "-fqdn"))) {
251 char *p = strchr(c, ':');
254 if (gethostbyname(c)) {
257 if ((opt = strdup(c)))
265 int afp_options_parse(int ac, char **av, struct afp_options *options)
273 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
274 perror( "gethostname" );
277 if (( p = strchr(options->hostname, '.' )) != 0 ) {
281 if (( p = strrchr( av[ 0 ], '/' )) == NULL ) {
287 while (( c = getopt( ac, av, OPTIONS )) != EOF ) {
290 options->flags |= OPTION_DEBUG;
293 options->server = optarg;
296 options->defaultvol = optarg;
299 options->systemvol = optarg;
302 options->flags |= OPTION_USERVOLFIRST;
305 options->connections = atoi( optarg );
308 options->guest = optarg;
312 options->pidfile = optarg;
316 options->passwdbits |= PASSWD_NOSAVE;
319 options->passwdbits |= PASSWD_SET;
323 options->transports &= ~AFPTRANS_DDP;
326 options->port = atoi(optarg);
329 options->transports &= ~AFPTRANS_TCP;
332 options->loginmesg = optarg;
335 options->configfile = optarg;
338 options->uamlist = optarg;
341 options->flags |= OPTION_CUSTOMICON;
346 if ( err || optind != ac ) {
348 "Usage:\t%s [ -dpDTIt ] [ -n nbpname ] [ -f defvols ] \
349 [ -P pidfile ] [ -s sysvols ] \n", p );
351 "\t[ -u ] [ -c maxconn ] [ -g guest ] \
352 [ -S port ] [ -L loginmesg ] [ -F configfile ] [ -U uamlist ]\n" );
357 openlog( p, LOG_PID );
359 openlog( p, LOG_NDELAY|LOG_PID, LOG_DAEMON);