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>
34 #define MIN(a, b) ((a) < (b) ? (a) : (b))
37 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:I"
40 /* return an option. this uses an internal array, so it's necessary
41 * to duplicate it if you want to hold it for long. this is probably
43 static char *getoption(char *buf, const char *option)
45 static char string[LENGTH + 1];
49 if (option && (buf = strstr(buf, option)))
50 buf = strpbrk(buf, " \t");
52 while (buf && isspace(*buf))
58 /* search for any quoted stuff */
59 if (*buf == '"' && (end = strchr(buf + 1, '"'))) {
61 len = MIN(end - buf, LENGTH);
62 } else if ((end = strpbrk(buf, " \t\n"))) /* option or eoln */
63 len = MIN(end - buf, LENGTH);
65 len = MIN(strlen(buf), LENGTH);
67 strncpy(string, buf, len);
72 /* get rid of any allocated afp_option buffers. */
73 void afp_options_free(struct afp_options *opt,
74 const struct afp_options *save)
76 if (opt->defaultvol && (opt->defaultvol != save->defaultvol))
77 free(opt->defaultvol);
78 if (opt->systemvol && (opt->systemvol != save->systemvol))
80 if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
82 if (opt->guest && (opt->guest != save->guest))
84 if (opt->server && (opt->server != save->server))
86 if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
88 if (opt->fqdn && (opt->fqdn != save->fqdn))
90 if (opt->uampath && (opt->uampath != save->uampath))
92 if (opt->uamlist && (opt->uamlist != save->uamlist))
94 if (opt->nlspath && (opt->nlspath != save->nlspath))
96 if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
97 free(opt->passwdfile);
100 /* initialize options */
101 void afp_options_init(struct afp_options *options)
103 memset(options, 0, sizeof(struct afp_options));
104 options->connections = 20;
105 options->pidfile = _PATH_AFPDLOCK;
106 options->defaultvol = _PATH_AFPDDEFVOL;
107 options->systemvol = _PATH_AFPDSYSVOL;
108 options->configfile = _PATH_AFPDCONF;
109 options->nlspath = _PATH_AFPDNLSPATH;
110 options->uampath = _PATH_AFPDUAMPATH;
111 options->uamlist = "uams_guest.so,uams_clrtxt.so,uams_dhx.so";
112 options->guest = "nobody";
113 options->loginmesg = "";
114 options->transports = AFPTRANS_ALL;
115 options->passwdfile = _PATH_AFPDPWFILE;
116 options->tickleval = 30;
119 /* parse an afpd.conf line. i'm doing it this way because it's
120 * easy. it is, however, massively hokey. sample afpd.conf:
121 * server:AFPServer@zone -loginmesg "blah blah blah" -nodsi
122 * "private machine"@zone2 -noguest -port 11012
123 * server2 -nocleartxt -nodsi
125 * NOTE: this ignores unknown options
127 int afp_options_parseline(char *buf, struct afp_options *options)
132 if (*buf != '-' && (c = getoption(buf, NULL)) && (opt = strdup(c)))
133 options->server = opt;
136 if (strstr(buf, " -nodebug"))
137 options->flags &= ~OPTION_DEBUG;
139 if (strstr(buf, " -nouservolfirst"))
140 options->flags &= ~OPTION_USERVOLFIRST;
141 if (strstr(buf, " -uservolfirst"))
142 options->flags |= OPTION_USERVOLFIRST;
143 if (strstr(buf, " -nouservol"))
144 options->flags |= OPTION_NOUSERVOL;
145 if (strstr(buf, " -uservol"))
146 options->flags &= ~OPTION_NOUSERVOL;
147 if (strstr(buf, " -proxy"))
148 options->flags |= OPTION_PROXY;
149 if (strstr(buf, " -noicon"))
150 options->flags &= ~OPTION_CUSTOMICON;
151 if (strstr(buf, " -icon"))
152 options->flags |= OPTION_CUSTOMICON;
155 if (strstr(buf, " -nosavepassword"))
156 options->passwdbits |= PASSWD_NOSAVE;
157 if (strstr(buf, " -savepassword"))
158 options->passwdbits &= ~PASSWD_NOSAVE;
159 if (strstr(buf, " -nosetpassword"))
160 options->passwdbits &= ~PASSWD_SET;
161 if (strstr(buf, " -setpassword"))
162 options->passwdbits |= PASSWD_SET;
165 if (strstr(buf, " -transall"))
166 options->transports = AFPTRANS_ALL;
167 if (strstr(buf, " -notransall"))
168 options->transports = AFPTRANS_NONE;
169 if (strstr(buf, " -tcp"))
170 options->transports |= AFPTRANS_TCP;
171 if (strstr(buf, " -notcp"))
172 options->transports &= ~AFPTRANS_TCP;
173 if (strstr(buf, " -ddp"))
174 options->transports |= AFPTRANS_DDP;
175 if (strstr(buf, " -noddp"))
176 options->transports &= ~AFPTRANS_DDP;
178 /* figure out options w/ values. currently, this will ignore the setting
179 * if memory is lacking. */
180 if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
181 options->defaultvol = opt;
182 if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
183 options->systemvol = opt;
184 if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c)))
185 options->loginmesg = opt;
186 if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
187 options->guest = opt;
188 if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
189 options->passwdfile = opt;
190 if ((c = getoption(buf, "-passwdminlen")))
191 options->passwdminlen = MIN(1, atoi(c));
192 if ((c = getoption(buf, "-loginmaxfail")))
193 options->loginmaxfail = atoi(c);
194 if ((c = getoption(buf, "-tickleval")))
195 options->tickleval = atoi(c);
197 if (c = getoption(buf, "-server_quantum"))
198 options->server_quantum = strtoul(c, NULL, 0);
201 if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
202 options->uampath = opt;
203 if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
204 options->uamlist = opt;
205 if ((c = getoption(buf, "-nlspath")) && (opt = strdup(c)))
206 options->nlspath = opt;
208 if (c = getoption(buf, "-ipaddr")) {
209 struct in_addr inaddr;
210 if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
211 if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
212 syslog(LOG_INFO, "WARNING: can't find %s\n", opt);
213 options->ipaddr = opt;
217 if ((c = getoption(buf, "-port")))
218 options->port = atoi(c);
219 if (c = getoption(buf, "-ddpaddr"))
220 atalk_aton(c, &options->ddpaddr);
222 /* do a little checking for the domain name. */
223 if (c = getoption(buf, "-fqdn")) {
224 char *p = strchr(c, ':');
227 if (gethostbyname(c)) {
238 int afp_options_parse(int ac, char **av, struct afp_options *options)
246 if (gethostname(options->hostname, sizeof(options->hostname )) < 0 ) {
247 perror( "gethostname" );
250 if (( p = strchr(options->hostname, '.' )) != 0 ) {
254 if (( p = strrchr( av[ 0 ], '/' )) == NULL ) {
260 while (( c = getopt( ac, av, OPTIONS )) != EOF ) {
263 options->flags |= OPTION_DEBUG;
266 options->server = optarg;
269 options->defaultvol = optarg;
272 options->systemvol = optarg;
275 options->flags |= OPTION_USERVOLFIRST;
278 options->connections = atoi( optarg );
281 options->guest = optarg;
285 options->pidfile = optarg;
289 options->passwdbits |= PASSWD_NOSAVE;
292 options->passwdbits |= PASSWD_SET;
296 options->transports &= ~AFPTRANS_DDP;
299 options->port = atoi(optarg);
302 options->transports &= ~AFPTRANS_TCP;
305 options->loginmesg = optarg;
308 options->configfile = optarg;
311 options->uamlist = optarg;
314 options->flags |= OPTION_CUSTOMICON;
319 if ( err || optind != ac ) {
321 "Usage:\t%s [ -dpDTIt ] [ -n nbpname ] [ -f defvols ] \
322 [ -P pidfile ] [ -s sysvols ] \n", p );
324 "\t[ -u ] [ -c maxconn ] [ -g guest ] \
325 [ -S port ] [ -L loginmesg ] [ -F configfile ] [ -U uamlist ]\n" );
330 openlog( p, LOG_PID );
332 openlog( p, LOG_NDELAY|LOG_PID, LOG_DAEMON );