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>
31 #include <atalk/compat.h>
35 #include <sys/types.h>
39 #define MIN(a, b) ((a) < (b) ? (a) : (b))
42 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:I"
45 /* return an option. this uses an internal array, so it's necessary
46 * to duplicate it if you want to hold it for long. this is probably
48 static char *getoption(char *buf, const char *option)
50 static char string[LENGTH + 1];
54 if (option && (buf = strstr(buf, option)))
55 buf = strpbrk(buf, " \t");
57 while (buf && isspace(*buf))
63 /* search for any quoted stuff */
64 if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
66 len = MIN(end - buf, LENGTH);
67 } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
68 len = MIN(end - buf, LENGTH);
70 len = MIN(strlen(buf), LENGTH);
72 strncpy(string, buf, len);
77 /* get rid of any allocated afp_option buffers. */
78 void afp_options_free(struct afp_options *opt,
79 const struct afp_options *save)
81 if (opt->defaultvol && (opt->defaultvol != save->defaultvol))
82 free(opt->defaultvol);
83 if (opt->systemvol && (opt->systemvol != save->systemvol))
85 if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
87 if (opt->guest && (opt->guest != save->guest))
89 if (opt->server && (opt->server != save->server))
91 if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
93 if (opt->fqdn && (opt->fqdn != save->fqdn))
95 if (opt->uampath && (opt->uampath != save->uampath))
97 if (opt->uamlist && (opt->uamlist != save->uamlist))
99 if (opt->nlspath && (opt->nlspath != save->nlspath))
101 if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
102 free(opt->passwdfile);
105 /* initialize options */
106 void afp_options_init(struct afp_options *options)
108 memset(options, 0, sizeof(struct afp_options));
109 options->connections = 20;
110 options->pidfile = _PATH_AFPDLOCK;
111 options->defaultvol = _PATH_AFPDDEFVOL;
112 options->systemvol = _PATH_AFPDSYSVOL;
113 options->configfile = _PATH_AFPDCONF;
114 options->nlspath = _PATH_AFPDNLSPATH;
115 options->uampath = _PATH_AFPDUAMPATH;
116 options->uamlist = "uams_guest.so,uams_clrtxt.so,uams_dhx.so";
117 options->guest = "nobody";
118 options->loginmesg = "";
119 options->transports = AFPTRANS_ALL;
120 options->passwdfile = _PATH_AFPDPWFILE;
121 options->tickleval = 30;
123 options->admingid = 0;
127 /* parse an afpd.conf line. i'm doing it this way because it's
128 * easy. it is, however, massively hokey. sample afpd.conf:
129 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
130 * "private machine"@zone2 -noguest -port 11012
131 * server2 -nocleartxt -nodsi
133 * NOTE: this ignores unknown options
135 int afp_options_parseline(char *buf, struct afp_options *options)
140 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
141 options->server = opt;
144 if (strstr(buf, " -nodebug"))
145 options->flags &= ~OPTION_DEBUG;
147 if (strstr(buf, " -nouservolfirst"))
148 options->flags &= ~OPTION_USERVOLFIRST;
149 if (strstr(buf, " -uservolfirst"))
150 options->flags |= OPTION_USERVOLFIRST;
151 if (strstr(buf, " -nouservol"))
152 options->flags |= OPTION_NOUSERVOL;
153 if (strstr(buf, " -uservol"))
154 options->flags &= ~OPTION_NOUSERVOL;
155 if (strstr(buf, " -proxy"))
156 options->flags |= OPTION_PROXY;
157 if (strstr(buf, " -noicon"))
158 options->flags &= ~OPTION_CUSTOMICON;
159 if (strstr(buf, " -icon"))
160 options->flags |= OPTION_CUSTOMICON;
163 if (strstr(buf, " -nosavepassword"))
164 options->passwdbits |= PASSWD_NOSAVE;
165 if (strstr(buf, " -savepassword"))
166 options->passwdbits &= ~PASSWD_NOSAVE;
167 if (strstr(buf, " -nosetpassword"))
168 options->passwdbits &= ~PASSWD_SET;
169 if (strstr(buf, " -setpassword"))
170 options->passwdbits |= PASSWD_SET;
173 if (strstr(buf, " -transall"))
174 options->transports = AFPTRANS_ALL;
175 if (strstr(buf, " -notransall"))
176 options->transports = AFPTRANS_NONE;
177 if (strstr(buf, " -tcp"))
178 options->transports |= AFPTRANS_TCP;
179 if (strstr(buf, " -notcp"))
180 options->transports &= ~AFPTRANS_TCP;
181 if (strstr(buf, " -ddp"))
182 options->transports |= AFPTRANS_DDP;
183 if (strstr(buf, " -noddp"))
184 options->transports &= ~AFPTRANS_DDP;
186 /* figure out options w/ values. currently, this will ignore the setting
187 * if memory is lacking. */
188 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
189 options->defaultvol = opt;
190 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
191 options->systemvol = opt;
192 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c)))
193 options->loginmesg = opt;
194 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
195 options->guest = opt;
196 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
197 options->passwdfile = opt;
198 if ((c = getoption(buf, "-passwdminlen")))
199 options->passwdminlen = MIN(1, atoi(c));
200 if ((c = getoption(buf, "-loginmaxfail")))
201 options->loginmaxfail = atoi(c);
202 if ((c = getoption(buf, "-tickleval")))
203 options->tickleval = atoi(c);
205 if (c = getoption(buf, "-server_quantum"))
206 options->server_quantum = strtoul(c, NULL, 0);
210 if ((c = getoption(buf, "-admingroup"))) {
211 struct group *gr = getgrnam(c);
213 options->admingid = gr->gr_gid;
217 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
218 options->uampath = opt;
219 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
220 options->uamlist = opt;
221 if ((c = getoption(buf, "-nlspath")) && (opt = strdup(c)))
222 options->nlspath = opt;
224 if (c = getoption(buf, "-ipaddr")) {
225 struct in_addr inaddr;
226 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
227 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
228 syslog(LOG_INFO, "WARNING: can't find %s\n", opt);
229 options->ipaddr = opt;
233 if ((c = getoption(buf, "-port")))
234 options->port = atoi(c);
235 if (c = getoption(buf, "-ddpaddr"))
236 atalk_aton(c, &options->ddpaddr);
238 /* do a little checking for the domain name. */
239 if (c = getoption(buf, "-fqdn")) {
240 char *p = strchr(c, ':');
243 if (gethostbyname(c)) {
254 int afp_options_parse(int ac, char **av, struct afp_options *options)
262 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
263 perror( "gethostname" );
266 if (( p = strchr(options->hostname, '.' )) != 0 ) {
270 if (( p = strrchr( av[ 0 ], '/' )) == NULL ) {
276 while (( c = getopt( ac, av, OPTIONS )) != EOF ) {
279 options->flags |= OPTION_DEBUG;
282 options->server = optarg;
285 options->defaultvol = optarg;
288 options->systemvol = optarg;
291 options->flags |= OPTION_USERVOLFIRST;
294 options->connections = atoi( optarg );
297 options->guest = optarg;
301 options->pidfile = optarg;
305 options->passwdbits |= PASSWD_NOSAVE;
308 options->passwdbits |= PASSWD_SET;
312 options->transports &= ~AFPTRANS_DDP;
315 options->port = atoi(optarg);
318 options->transports &= ~AFPTRANS_TCP;
321 options->loginmesg = optarg;
324 options->configfile = optarg;
327 options->uamlist = optarg;
330 options->flags |= OPTION_CUSTOMICON;
335 if ( err || optind != ac ) {
337 "Usage:\t%s [ -dpDTIt ] [ -n nbpname ] [ -f defvols ] \
338 [ -P pidfile ] [ -s sysvols ] \n", p );
340 "\t[ -u ] [ -c maxconn ] [ -g guest ] \
341 [ -S port ] [ -L loginmesg ] [ -F configfile ] [ -U uamlist ]\n" );
346 openlog( p, LOG_PID );
348 openlog( p, LOG_NDELAY|LOG_PID, LOG_LOCAL0 );