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.
6 * modified from main.c. this handles afp options.
18 #include <sys/param.h>
19 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
26 #include <atalk/paths.h>
27 #include <atalk/util.h>
32 #include <atalk/compat.h>
36 #include <sys/types.h>
40 #define MIN(a, b) ((a) < (b) ? (a) : (b))
43 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:I"
46 /* return an option. this uses an internal array, so it's necessary
47 * to duplicate it if you want to hold it for long. this is probably
49 static char *getoption(char *buf, const char *option)
51 static char string[LENGTH + 1];
55 if (option && (buf = strstr(buf, option)))
56 buf = strpbrk(buf, " \t");
58 while (buf && isspace(*buf))
64 /* search for any quoted stuff */
65 if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
67 len = MIN(end - buf, LENGTH);
68 } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
69 len = MIN(end - buf, LENGTH);
71 len = MIN(strlen(buf), LENGTH);
73 strncpy(string, buf, len);
78 /* get rid of any allocated afp_option buffers. */
79 void afp_options_free(struct afp_options *opt,
80 const struct afp_options *save)
82 if (opt->defaultvol && (opt->defaultvol != save->defaultvol))
83 free(opt->defaultvol);
84 if (opt->systemvol && (opt->systemvol != save->systemvol))
86 if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
88 if (opt->guest && (opt->guest != save->guest))
90 if (opt->server && (opt->server != save->server))
92 if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
94 if (opt->fqdn && (opt->fqdn != save->fqdn))
96 if (opt->uampath && (opt->uampath != save->uampath))
98 if (opt->uamlist && (opt->uamlist != save->uamlist))
100 if (opt->nlspath && (opt->nlspath != save->nlspath))
102 if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
103 free(opt->passwdfile);
106 /* initialize options */
107 void afp_options_init(struct afp_options *options)
109 memset(options, 0, sizeof(struct afp_options));
110 options->connections = 20;
111 options->pidfile = _PATH_AFPDLOCK;
112 options->defaultvol = _PATH_AFPDDEFVOL;
113 options->systemvol = _PATH_AFPDSYSVOL;
114 options->configfile = _PATH_AFPDCONF;
115 options->nlspath = _PATH_AFPDNLSPATH;
116 options->uampath = _PATH_AFPDUAMPATH;
117 options->uamlist = "uams_guest.so,uams_clrtxt.so,uams_dhx.so";
118 options->guest = "nobody";
119 options->loginmesg = "";
120 options->transports = AFPTRANS_ALL;
121 options->passwdfile = _PATH_AFPDPWFILE;
122 options->tickleval = 30;
123 options->authprintdir = NULL;
125 options->admingid = 0;
129 /* parse an afpd.conf line. i'm doing it this way because it's
130 * easy. it is, however, massively hokey. sample afpd.conf:
131 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
132 * "private machine"@zone2 -noguest -port 11012
133 * server2 -nocleartxt -nodsi
135 * NOTE: this ignores unknown options
137 int afp_options_parseline(char *buf, struct afp_options *options)
142 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
143 options->server = opt;
146 if (strstr(buf, " -nodebug"))
147 options->flags &= ~OPTION_DEBUG;
149 if (strstr(buf, " -nouservolfirst"))
150 options->flags &= ~OPTION_USERVOLFIRST;
151 if (strstr(buf, " -uservolfirst"))
152 options->flags |= OPTION_USERVOLFIRST;
153 if (strstr(buf, " -nouservol"))
154 options->flags |= OPTION_NOUSERVOL;
155 if (strstr(buf, " -uservol"))
156 options->flags &= ~OPTION_NOUSERVOL;
157 if (strstr(buf, " -proxy"))
158 options->flags |= OPTION_PROXY;
159 if (strstr(buf, " -noicon"))
160 options->flags &= ~OPTION_CUSTOMICON;
161 if (strstr(buf, " -icon"))
162 options->flags |= OPTION_CUSTOMICON;
165 if (strstr(buf, " -nosavepassword"))
166 options->passwdbits |= PASSWD_NOSAVE;
167 if (strstr(buf, " -savepassword"))
168 options->passwdbits &= ~PASSWD_NOSAVE;
169 if (strstr(buf, " -nosetpassword"))
170 options->passwdbits &= ~PASSWD_SET;
171 if (strstr(buf, " -setpassword"))
172 options->passwdbits |= PASSWD_SET;
175 if (strstr(buf, " -transall"))
176 options->transports = AFPTRANS_ALL;
177 if (strstr(buf, " -notransall"))
178 options->transports = AFPTRANS_NONE;
179 if (strstr(buf, " -tcp"))
180 options->transports |= AFPTRANS_TCP;
181 if (strstr(buf, " -notcp"))
182 options->transports &= ~AFPTRANS_TCP;
183 if (strstr(buf, " -ddp"))
184 options->transports |= AFPTRANS_DDP;
185 if (strstr(buf, " -noddp"))
186 options->transports &= ~AFPTRANS_DDP;
188 /* figure out options w/ values. currently, this will ignore the setting
189 * if memory is lacking. */
190 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
191 options->defaultvol = opt;
192 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
193 options->systemvol = opt;
194 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c)))
195 options->loginmesg = opt;
196 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
197 options->guest = opt;
198 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
199 options->passwdfile = opt;
200 if ((c = getoption(buf, "-passwdminlen")))
201 options->passwdminlen = MIN(1, atoi(c));
202 if ((c = getoption(buf, "-loginmaxfail")))
203 options->loginmaxfail = atoi(c);
204 if ((c = getoption(buf, "-tickleval")))
205 options->tickleval = atoi(c);
207 if ((c = getoption(buf, "-server_quantum")))
208 options->server_quantum = strtoul(c, NULL, 0);
212 if ((c = getoption(buf, "-admingroup"))) {
213 struct group *gr = getgrnam(c);
215 options->admingid = gr->gr_gid;
220 if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
221 options->authprintdir = opt;
222 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
223 options->uampath = opt;
224 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
225 options->uamlist = opt;
226 if ((c = getoption(buf, "-nlspath")) && (opt = strdup(c)))
227 options->nlspath = opt;
229 if ((c = getoption(buf, "-ipaddr"))) {
230 struct in_addr inaddr;
231 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
232 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
233 syslog(LOG_INFO, "WARNING: can't find %s\n", opt);
234 options->ipaddr = opt;
238 if ((c = getoption(buf, "-port")))
239 options->port = atoi(c);
240 if ((c = getoption(buf, "-ddpaddr")))
241 atalk_aton(c, &options->ddpaddr);
243 /* do a little checking for the domain name. */
244 if ((c = getoption(buf, "-fqdn"))) {
245 char *p = strchr(c, ':');
248 if (gethostbyname(c)) {
251 if ((opt = strdup(c)))
259 int afp_options_parse(int ac, char **av, struct afp_options *options)
267 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
268 perror( "gethostname" );
271 if (( p = strchr(options->hostname, '.' )) != 0 ) {
275 if (( p = strrchr( av[ 0 ], '/' )) == NULL ) {
281 while (( c = getopt( ac, av, OPTIONS )) != EOF ) {
284 options->flags |= OPTION_DEBUG;
287 options->server = optarg;
290 options->defaultvol = optarg;
293 options->systemvol = optarg;
296 options->flags |= OPTION_USERVOLFIRST;
299 options->connections = atoi( optarg );
302 options->guest = optarg;
306 options->pidfile = optarg;
310 options->passwdbits |= PASSWD_NOSAVE;
313 options->passwdbits |= PASSWD_SET;
317 options->transports &= ~AFPTRANS_DDP;
320 options->port = atoi(optarg);
323 options->transports &= ~AFPTRANS_TCP;
326 options->loginmesg = optarg;
329 options->configfile = optarg;
332 options->uamlist = optarg;
335 options->flags |= OPTION_CUSTOMICON;
340 if ( err || optind != ac ) {
342 "Usage:\t%s [ -dpDTIt ] [ -n nbpname ] [ -f defvols ] \
343 [ -P pidfile ] [ -s sysvols ] \n", p );
345 "\t[ -u ] [ -c maxconn ] [ -g guest ] \
346 [ -S port ] [ -L loginmesg ] [ -F configfile ] [ -U uamlist ]\n" );
351 openlog( p, LOG_PID );
353 openlog( p, LOG_NDELAY|LOG_PID, LOG_DAEMON);