Clean (void) casts from usr.sbin
[dragonfly.git] / usr.sbin / pppd / options.c
1 /*
2  * options.c - handles option processing for PPP.
3  *
4  * Copyright (c) 1989 Carnegie Mellon University.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted
8  * provided that the above copyright notice and this paragraph are
9  * duplicated in all such forms and that any documentation,
10  * advertising materials, and other materials related to such
11  * distribution and use acknowledge that the software was developed
12  * by Carnegie Mellon University.  The name of the
13  * University may not be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * $FreeBSD: src/usr.sbin/pppd/options.c,v 1.20.2.2 2002/08/31 18:16:01 dwmalone Exp $
20  * $DragonFly: src/usr.sbin/pppd/options.c,v 1.5 2004/12/18 22:48:04 swildner Exp $
21  */
22
23 #include <ctype.h>
24 #include <stdio.h>
25 #include <errno.h>
26 #include <unistd.h>
27 #include <limits.h>
28 #include <stdlib.h>
29 #include <termios.h>
30 #include <syslog.h>
31 #include <string.h>
32 #include <netdb.h>
33 #include <paths.h>
34 #include <pwd.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
39 #ifdef PPP_FILTER
40 #include <pcap.h>
41 #include <pcap-int.h>   /* XXX: To get struct pcap */
42 #endif
43
44 #include "pppd.h"
45 #include "pathnames.h"
46 #include "patchlevel.h"
47 #include "fsm.h"
48 #include "lcp.h"
49 #include "ipcp.h"
50 #include "upap.h"
51 #include "chap.h"
52 #include "ccp.h"
53 #ifdef CBCP_SUPPORT
54 #include "cbcp.h"
55 #endif
56
57 #ifdef IPX_CHANGE
58 #include "ipxcp.h"
59 #endif /* IPX_CHANGE */
60
61 #include <net/ppp_layer/ppp_comp.h>
62
63 #define FALSE   0
64 #define TRUE    1
65
66 #if defined(ultrix) || defined(NeXT)
67 char *strdup(char *);
68 #endif
69
70 #ifndef GIDSET_TYPE
71 #define GIDSET_TYPE     gid_t
72 #endif
73
74 /*
75  * Option variables and default values.
76  */
77 #ifdef PPP_FILTER
78 int     dflag = 0;              /* Tell libpcap we want debugging */
79 #endif
80 int     debug = 0;              /* Debug flag */
81 int     kdebugflag = 0;         /* Tell kernel to print debug messages */
82 int     default_device = 1;     /* Using /dev/tty or equivalent */
83 char    devnam[MAXPATHLEN] = _PATH_TTY; /* Device name */
84 int     crtscts = 0;            /* Use hardware flow control */
85 int     modem = 1;              /* Use modem control lines */
86 int     inspeed = 0;            /* Input/Output speed requested */
87 u_int32_t netmask = 0;          /* IP netmask to set on interface */
88 int     lockflag = 0;           /* Create lock file to lock the serial dev */
89 int     nodetach = 0;           /* Don't detach from controlling tty */
90 char    *connector = NULL;      /* Script to establish physical link */
91 char    *disconnector = NULL;   /* Script to disestablish physical link */
92 char    *welcomer = NULL;       /* Script to run after phys link estab. */
93 int     max_con_attempts = 0;   /* Maximum connect tries in non-demand mode */
94 int     maxconnect = 0;         /* Maximum connect time */
95 char    user[MAXNAMELEN];       /* Username for PAP */
96 char    passwd[MAXSECRETLEN];   /* Password for PAP */
97 int     auth_required = 0;      /* Peer is required to authenticate */
98 int     defaultroute = 0;       /* assign default route through interface */
99 int     proxyarp = 0;           /* Set up proxy ARP entry for peer */
100 int     persist = 0;            /* Reopen link after it goes down */
101 int     uselogin = 0;           /* Use /etc/passwd for checking PAP */
102 int     lcp_echo_interval = 0;  /* Interval between LCP echo-requests */
103 int     lcp_echo_fails = 0;     /* Tolerance to unanswered echo-requests */
104 char    our_name[MAXNAMELEN];   /* Our name for authentication purposes */
105 char    remote_name[MAXNAMELEN]; /* Peer's name for authentication */
106 int     explicit_remote = 0;    /* User specified explicit remote name */
107 int     usehostname = 0;        /* Use hostname for our_name */
108 int     disable_defaultip = 0;  /* Don't use hostname for default IP adrs */
109 int     demand = 0;             /* do dial-on-demand */
110 char    *ipparam = NULL;        /* Extra parameter for ip up/down scripts */
111 int     cryptpap;               /* Passwords in pap-secrets are encrypted */
112 int     idle_time_limit = 0;    /* Disconnect if idle for this many seconds */
113 int     holdoff = 30;           /* # seconds to pause before reconnecting */
114 int     refuse_pap = 0;         /* Set to say we won't do PAP */
115 int     refuse_chap = 0;        /* Set to say we won't do CHAP */
116
117 #ifdef MSLANMAN
118 int     ms_lanman = 0;          /* Nonzero if use LanMan password instead of NT */
119                                 /* Has meaning only with MS-CHAP challenges */
120 #endif
121
122 struct option_info auth_req_info;
123 struct option_info connector_info;
124 struct option_info disconnector_info;
125 struct option_info welcomer_info;
126 struct option_info devnam_info;
127 #ifdef PPP_FILTER
128 struct  bpf_program pass_filter;/* Filter program for packets to pass */
129 struct  bpf_program active_filter; /* Filter program for link-active pkts */
130 pcap_t  pc;                     /* Fake struct pcap so we can compile expr */
131 #endif
132
133 /*
134  * Prototypes
135  */
136 static int setdevname(char *, int);
137 static int setspeed(char *);
138 static int setdebug(char **);
139 static int setkdebug(char **);
140 static int setpassive(char **);
141 static int setsilent(char **);
142 static int noopt(char **);
143 static int setnovj(char **);
144 static int setnovjccomp(char **);
145 static int setvjslots(char **);
146 static int reqpap(char **);
147 static int nopap(char **);
148 #ifdef OLD_OPTIONS
149 static int setupapfile(char **);
150 #endif
151 static int nochap(char **);
152 static int reqchap(char **);
153 static int noaccomp(char **);
154 static int noasyncmap(char **);
155 static int noip(char **);
156 static int nomagicnumber(char **);
157 static int setasyncmap(char **);
158 static int setescape(char **);
159 static int setmru(char **);
160 static int setmtu(char **);
161 #ifdef CBCP_SUPPORT
162 static int setcbcp(char **);
163 #endif
164 static int nomru(char **);
165 static int nopcomp(char **);
166 static int setconnector(char **);
167 static int setdisconnector(char **);
168 static int setwelcomer(char **);
169 static int setmaxcon(char **);
170 static int setmaxconnect(char **);
171 static int setdomain(char **);
172 static int setnetmask(char **);
173 static int setcrtscts(char **);
174 static int setnocrtscts(char **);
175 static int setxonxoff(char **);
176 static int setnodetach(char **);
177 static int setupdetach(char **);
178 static int setmodem(char **);
179 static int setlocal(char **);
180 static int setlock(char **);
181 static int setname(char **);
182 static int setuser(char **);
183 static int setremote(char **);
184 static int setauth(char **);
185 static int setnoauth(char **);
186 static int readfile(char **);
187 static int callfile(char **);
188 static int setdefaultroute(char **);
189 static int setnodefaultroute(char **);
190 static int setproxyarp(char **);
191 static int setnoproxyarp(char **);
192 static int setpersist(char **);
193 static int setnopersist(char **);
194 static int setdologin(char **);
195 static int setusehostname(char **);
196 static int setnoipdflt(char **);
197 static int setlcptimeout(char **);
198 static int setlcpterm(char **);
199 static int setlcpconf(char **);
200 static int setlcpfails(char **);
201 static int setipcptimeout(char **);
202 static int setipcpterm(char **);
203 static int setipcpconf(char **);
204 static int setipcpfails(char **);
205 static int setpaptimeout(char **);
206 static int setpapreqs(char **);
207 static int setpapreqtime(char **);
208 static int setchaptimeout(char **);
209 static int setchapchal(char **);
210 static int setchapintv(char **);
211 static int setipcpaccl(char **);
212 static int setipcpaccr(char **);
213 static int setlcpechointv(char **);
214 static int setlcpechofails(char **);
215 static int noccp(char **);
216 static int setbsdcomp(char **);
217 static int setnobsdcomp(char **);
218 static int setdeflate(char **);
219 static int setnodeflate(char **);
220 static int setnodeflatedraft(char **);
221 static int setdemand(char **);
222 static int setpred1comp(char **);
223 static int setnopred1comp(char **);
224 static int setipparam(char **);
225 static int setpapcrypt(char **);
226 static int setidle(char **);
227 static int setholdoff(char **);
228 static int setdnsaddr(char **);
229 static int resetipxproto(char **);
230 static int setwinsaddr(char **);
231 static int showversion(char **);
232 static int showhelp(char **);
233
234 #ifdef PPP_FILTER
235 static int setpdebug(char **);
236 static int setpassfilter(char **);
237 static int setactivefilter(char **);
238 #endif
239
240 #ifdef IPX_CHANGE
241 static int setipxproto(char **);
242 static int setipxanet(char **);
243 static int setipxalcl(char **);
244 static int setipxarmt(char **);
245 static int setipxnetwork(char **);
246 static int setipxnode(char **);
247 static int setipxrouter(char **);
248 static int setipxname(char **);
249 static int setipxcptimeout(char **);
250 static int setipxcpterm(char **);
251 static int setipxcpconf(char **);
252 static int setipxcpfails(char **);
253 #endif /* IPX_CHANGE */
254
255 #ifdef MSLANMAN
256 static int setmslanman(char **);
257 #endif
258
259 static int number_option(char *, u_int32_t *, int);
260 static int int_option(char *, int *);
261 static int readable(int fd);
262
263 /*
264  * Valid arguments.
265  */
266 static struct cmd {
267     char *cmd_name;
268     int num_args;
269     int (*cmd_func)(char **);
270 } cmds[] = {
271     {"-all", 0, noopt},         /* Don't request/allow any options (useless) */
272     {"noaccomp", 0, noaccomp},  /* Disable Address/Control compression */
273     {"-ac", 0, noaccomp},       /* Disable Address/Control compress */
274     {"default-asyncmap", 0, noasyncmap}, /* Disable asyncmap negoatiation */
275     {"-am", 0, noasyncmap},     /* Disable asyncmap negotiation */
276     {"-as", 1, setasyncmap},    /* set the desired async map */
277     {"-d", 0, setdebug},        /* Increase debugging level */
278     {"nodetach", 0, setnodetach}, /* Don't detach from controlling tty */
279     {"-detach", 0, setnodetach}, /* don't fork */
280     {"updetach", 0, setupdetach}, /* Detach once an NP has come up */
281     {"noip", 0, noip},          /* Disable IP and IPCP */
282     {"-ip", 0, noip},           /* Disable IP and IPCP */
283     {"nomagic", 0, nomagicnumber}, /* Disable magic number negotiation */
284     {"-mn", 0, nomagicnumber},  /* Disable magic number negotiation */
285     {"default-mru", 0, nomru},  /* Disable MRU negotiation */
286     {"-mru", 0, nomru},         /* Disable mru negotiation */
287     {"-p", 0, setpassive},      /* Set passive mode */
288     {"nopcomp", 0, nopcomp},    /* Disable protocol field compression */
289     {"-pc", 0, nopcomp},        /* Disable protocol field compress */
290 #if OLD_OPTIONS
291     {"+ua", 1, setupapfile},    /* Get PAP user and password from file */
292 #endif
293     {"require-pap", 0, reqpap}, /* Require PAP authentication from peer */
294     {"+pap", 0, reqpap},        /* Require PAP auth from peer */
295     {"refuse-pap", 0, nopap},   /* Don't agree to auth to peer with PAP */
296     {"-pap", 0, nopap},         /* Don't allow UPAP authentication with peer */
297     {"require-chap", 0, reqchap}, /* Require CHAP authentication from peer */
298     {"+chap", 0, reqchap},      /* Require CHAP authentication from peer */
299     {"refuse-chap", 0, nochap}, /* Don't agree to auth to peer with CHAP */
300     {"-chap", 0, nochap},       /* Don't allow CHAP authentication with peer */
301     {"novj", 0, setnovj},       /* Disable VJ compression */
302     {"-vj", 0, setnovj},        /* disable VJ compression */
303     {"novjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
304     {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
305     {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
306     {"asyncmap", 1, setasyncmap}, /* set the desired async map */
307     {"escape", 1, setescape},   /* set chars to escape on transmission */
308     {"connect", 1, setconnector}, /* A program to set up a connection */
309     {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
310     {"welcome", 1, setwelcomer},/* Script to welcome client */
311     {"connect-max-attempts", 1, setmaxcon},  /* maximum # connect attempts */
312     {"maxconnect", 1, setmaxconnect},  /* specify a maximum connect time */
313     {"crtscts", 0, setcrtscts}, /* set h/w flow control */
314     {"nocrtscts", 0, setnocrtscts}, /* clear h/w flow control */
315     {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
316     {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
317     {"debug", 0, setdebug},     /* Increase debugging level */
318     {"kdebug", 1, setkdebug},   /* Enable kernel-level debugging */
319     {"domain", 1, setdomain},   /* Add given domain name to hostname*/
320     {"mru", 1, setmru},         /* Set MRU value for negotiation */
321     {"mtu", 1, setmtu},         /* Set our MTU */
322 #ifdef CBCP_SUPPORT
323     {"callback", 1, setcbcp},   /* Ask for callback */
324 #endif
325     {"netmask", 1, setnetmask}, /* set netmask */
326     {"passive", 0, setpassive}, /* Set passive mode */
327     {"silent", 0, setsilent},   /* Set silent mode */
328     {"modem", 0, setmodem},     /* Use modem control lines */
329     {"local", 0, setlocal},     /* Don't use modem control lines */
330     {"lock", 0, setlock},       /* Lock serial device (with lock file) */
331     {"name", 1, setname},       /* Set local name for authentication */
332     {"user", 1, setuser},       /* Set name for auth with peer */
333     {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
334     {"remotename", 1, setremote}, /* Set remote name for authentication */
335     {"auth", 0, setauth},       /* Require authentication from peer */
336     {"noauth", 0, setnoauth},   /* Don't require peer to authenticate */
337     {"file", 1, readfile},      /* Take options from a file */
338     {"call", 1, callfile},      /* Take options from a privileged file */
339     {"defaultroute", 0, setdefaultroute}, /* Add default route */
340     {"nodefaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
341     {"-defaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
342     {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
343     {"noproxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
344     {"-proxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
345     {"persist", 0, setpersist}, /* Keep on reopening connection after close */
346     {"nopersist", 0, setnopersist},  /* Turn off persist option */
347     {"demand", 0, setdemand},   /* Dial on demand */
348     {"login", 0, setdologin},   /* Use system password database for UPAP */
349     {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
350     {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
351     {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
352     {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
353     {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
354     {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
355     {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
356     {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
357     {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
358     {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
359     {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
360     {"pap-restart", 1, setpaptimeout},  /* Set retransmit timeout for PAP */
361     {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
362     {"pap-timeout", 1, setpapreqtime},  /* Set time limit for peer PAP auth. */
363     {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
364     {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
365     {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
366     {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
367     {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
368     {"noccp", 0, noccp},                /* Disable CCP negotiation */
369     {"-ccp", 0, noccp},                 /* Disable CCP negotiation */
370     {"bsdcomp", 1, setbsdcomp},         /* request BSD-Compress */
371     {"nobsdcomp", 0, setnobsdcomp},     /* don't allow BSD-Compress */
372     {"-bsdcomp", 0, setnobsdcomp},      /* don't allow BSD-Compress */
373     {"deflate", 1, setdeflate},         /* request Deflate compression */
374     {"nodeflate", 0, setnodeflate},     /* don't allow Deflate compression */
375     {"-deflate", 0, setnodeflate},      /* don't allow Deflate compression */
376     {"nodeflatedraft", 0, setnodeflatedraft}, /* don't use draft deflate # */
377     {"predictor1", 0, setpred1comp},    /* request Predictor-1 */
378     {"nopredictor1", 0, setnopred1comp},/* don't allow Predictor-1 */
379     {"-predictor1", 0, setnopred1comp}, /* don't allow Predictor-1 */
380     {"ipparam", 1, setipparam},         /* set ip script parameter */
381     {"papcrypt", 0, setpapcrypt},       /* PAP passwords encrypted */
382     {"idle", 1, setidle},               /* idle time limit (seconds) */
383     {"holdoff", 1, setholdoff},         /* set holdoff time (seconds) */
384 /* backwards compat hack */
385     {"dns1", 1, setdnsaddr},            /* DNS address for the peer's use */
386     {"dns2", 1, setdnsaddr},            /* DNS address for the peer's use */
387 /* end compat hack */
388     {"ms-dns", 1, setdnsaddr},          /* DNS address for the peer's use */
389     {"ms-wins", 1, setwinsaddr},        /* Nameserver for SMB over TCP/IP for peer */
390     {"noipx",  0, resetipxproto},       /* Disable IPXCP (and IPX) */
391     {"-ipx",   0, resetipxproto},       /* Disable IPXCP (and IPX) */
392     {"--version", 0, showversion},      /* Show version number */
393     {"--help", 0, showhelp},            /* Show brief listing of options */
394     {"-h", 0, showhelp},                /* ditto */
395
396 #ifdef PPP_FILTER
397     {"pdebug", 1, setpdebug},           /* libpcap debugging */
398     {"pass-filter", 1, setpassfilter},  /* set filter for packets to pass */
399     {"active-filter", 1, setactivefilter}, /* set filter for active pkts */
400 #endif
401
402 #ifdef IPX_CHANGE
403     {"ipx-network",          1, setipxnetwork}, /* IPX network number */
404     {"ipxcp-accept-network", 0, setipxanet},    /* Accept peer netowrk */
405     {"ipx-node",             1, setipxnode},    /* IPX node number */
406     {"ipxcp-accept-local",   0, setipxalcl},    /* Accept our address */
407     {"ipxcp-accept-remote",  0, setipxarmt},    /* Accept peer's address */
408     {"ipx-routing",          1, setipxrouter},  /* IPX routing proto number */
409     {"ipx-router-name",      1, setipxname},    /* IPX router name */
410     {"ipxcp-restart",        1, setipxcptimeout}, /* Set timeout for IPXCP */
411     {"ipxcp-max-terminate",  1, setipxcpterm},  /* max #xmits for term-reqs */
412     {"ipxcp-max-configure",  1, setipxcpconf},  /* max #xmits for conf-reqs */
413     {"ipxcp-max-failure",    1, setipxcpfails}, /* max #conf-naks for IPXCP */
414 #if 0
415     {"ipx-compression", 1, setipxcompression}, /* IPX compression number */
416 #endif
417     {"ipx",                  0, setipxproto},   /* Enable IPXCP (and IPX) */
418     {"+ipx",                 0, setipxproto},   /* Enable IPXCP (and IPX) */
419 #endif /* IPX_CHANGE */
420
421 #ifdef MSLANMAN
422     {"ms-lanman", 0, setmslanman},      /* Use LanMan psswd when using MS-CHAP */
423 #endif
424
425     {NULL, 0, NULL}
426 };
427
428
429 #ifndef IMPLEMENTATION
430 #define IMPLEMENTATION ""
431 #endif
432
433 static const char usage_string[] = "\
434 pppd version %s patch level %d%s\n\
435 Usage: %s [ options ], where options are:\n\
436         <device>        Communicate over the named device\n\
437         <speed>         Set the baud rate to <speed>\n\
438         <loc>:<rem>     Set the local and/or remote interface IP\n\
439                         addresses.  Either one may be omitted.\n\
440         asyncmap <n>    Set the desired async map to hex <n>\n\
441         auth            Require authentication from peer\n\
442         connect <p>     Invoke shell command <p> to set up the serial line\n\
443         crtscts         Use hardware RTS/CTS flow control\n\
444         defaultroute    Add default route through interface\n\
445         file <f>        Take options from file <f>\n\
446         modem           Use modem control lines\n\
447         mru <n>         Set MRU value to <n> for negotiation\n\
448 See pppd(8) for more options.\n\
449 ";
450
451 static char *current_option;    /* the name of the option being parsed */
452 static int privileged_option;   /* set iff the current option came from root */
453 static char *option_source;     /* string saying where the option came from */
454
455 /*
456  * parse_args - parse a string of arguments from the command line.
457  */
458 int
459 parse_args(argc, argv)
460     int argc;
461     char **argv;
462 {
463     char *arg;
464     struct cmd *cmdp;
465     int ret;
466
467     privileged_option = privileged;
468     option_source = "command line";
469     while (argc > 0) {
470         arg = *argv++;
471         --argc;
472
473         /*
474          * First see if it's a command.
475          */
476         for (cmdp = cmds; cmdp->cmd_name; cmdp++)
477             if (!strcmp(arg, cmdp->cmd_name))
478                 break;
479
480         if (cmdp->cmd_name != NULL) {
481             if (argc < cmdp->num_args) {
482                 option_error("too few parameters for option %s", arg);
483                 return 0;
484             }
485             current_option = arg;
486             if (!(*cmdp->cmd_func)(argv))
487                 return 0;
488             argc -= cmdp->num_args;
489             argv += cmdp->num_args;
490
491         } else {
492             /*
493              * Maybe a tty name, speed or IP address?
494              */
495             if ((ret = setdevname(arg, 0)) == 0
496                 && (ret = setspeed(arg)) == 0
497                 && (ret = setipaddr(arg)) == 0) {
498                 option_error("unrecognized option '%s'", arg);
499                 usage();
500                 return 0;
501             }
502             if (ret < 0)        /* error */
503                 return 0;
504         }
505     }
506     return 1;
507 }
508
509 /*
510  * scan_args - scan the command line arguments to get the tty name,
511  * if specified.
512  */
513 void
514 scan_args(argc, argv)
515     int argc;
516     char **argv;
517 {
518     char *arg;
519     struct cmd *cmdp;
520
521     while (argc > 0) {
522         arg = *argv++;
523         --argc;
524
525         /* Skip options and their arguments */
526         for (cmdp = cmds; cmdp->cmd_name; cmdp++)
527             if (!strcmp(arg, cmdp->cmd_name))
528                 break;
529
530         if (cmdp->cmd_name != NULL) {
531             argc -= cmdp->num_args;
532             argv += cmdp->num_args;
533             continue;
534         }
535
536         /* Check if it's a tty name and copy it if so */
537         setdevname(arg, 1);
538     }
539 }
540
541 /*
542  * usage - print out a message telling how to use the program.
543  */
544 void
545 usage()
546 {
547     if (phase == PHASE_INITIALIZE)
548         fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
549                 progname);
550 }
551
552 /*
553  * showhelp - print out usage message and exit.
554  */
555 static int
556 showhelp(argv)
557     char **argv;
558 {
559     if (phase == PHASE_INITIALIZE) {
560         usage();
561         exit(0);
562     }
563     return 0;
564 }
565
566 /*
567  * showversion - print out the version number and exit.
568  */
569 static int
570 showversion(argv)
571     char **argv;
572 {
573     if (phase == PHASE_INITIALIZE) {
574         fprintf(stderr, "pppd version %s patch level %d%s\n",
575                 VERSION, PATCHLEVEL, IMPLEMENTATION);
576         exit(0);
577     }
578     return 0;
579 }
580
581 /*
582  * options_from_file - Read a string of options from a file,
583  * and interpret them.
584  */
585 int
586 options_from_file(filename, must_exist, check_prot, priv)
587     char *filename;
588     int must_exist;
589     int check_prot;
590     int priv;
591 {
592     FILE *f;
593     int i, newline, ret;
594     struct cmd *cmdp;
595     int oldpriv;
596     char *argv[MAXARGS];
597     char args[MAXARGS][MAXWORDLEN];
598     char cmd[MAXWORDLEN];
599
600     if ((f = fopen(filename, "r")) == NULL) {
601         if (!must_exist && errno == ENOENT)
602             return 1;
603         option_error("Can't open options file %s: %m", filename);
604         return 0;
605     }
606     if (check_prot && !readable(fileno(f))) {
607         option_error("Can't open options file %s: access denied", filename);
608         fclose(f);
609         return 0;
610     }
611
612     oldpriv = privileged_option;
613     privileged_option = priv;
614     ret = 0;
615     while (getword(f, cmd, &newline, filename)) {
616         /*
617          * First see if it's a command.
618          */
619         for (cmdp = cmds; cmdp->cmd_name; cmdp++)
620             if (!strcmp(cmd, cmdp->cmd_name))
621                 break;
622
623         if (cmdp->cmd_name != NULL) {
624             for (i = 0; i < cmdp->num_args; ++i) {
625                 if (!getword(f, args[i], &newline, filename)) {
626                     option_error(
627                         "In file %s: too few parameters for option '%s'",
628                         filename, cmd);
629                     goto err;
630                 }
631                 argv[i] = args[i];
632             }
633             current_option = cmd;
634             if (!(*cmdp->cmd_func)(argv))
635                 goto err;
636
637         } else {
638             /*
639              * Maybe a tty name, speed or IP address?
640              */
641             if ((i = setdevname(cmd, 0)) == 0
642                 && (i = setspeed(cmd)) == 0
643                 && (i = setipaddr(cmd)) == 0) {
644                 option_error("In file %s: unrecognized option '%s'",
645                              filename, cmd);
646                 goto err;
647             }
648             if (i < 0)          /* error */
649                 goto err;
650         }
651     }
652     ret = 1;
653
654 err:
655     fclose(f);
656     privileged_option = oldpriv;
657     return ret;
658 }
659
660 /*
661  * options_from_user - See if the use has a ~/.ppprc file,
662  * and if so, interpret options from it.
663  */
664 int
665 options_from_user()
666 {
667     char *user, *path, *file;
668     int ret;
669     struct passwd *pw;
670
671     pw = getpwuid(getuid());
672     if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
673         return 1;
674     file = _PATH_USEROPT;
675     path = malloc(strlen(user) + strlen(file) + 2);
676     if (path == NULL)
677         novm("init file name");
678     strcpy(path, user);
679     strcat(path, "/");
680     strcat(path, file);
681     ret = options_from_file(path, 0, 1, privileged);
682     free(path);
683     return ret;
684 }
685
686 /*
687  * options_for_tty - See if an options file exists for the serial
688  * device, and if so, interpret options from it.
689  */
690 int
691 options_for_tty()
692 {
693     char *dev, *path, *p;
694     int ret;
695
696     dev = devnam;
697     if (strncmp(dev, _PATH_DEV, sizeof _PATH_DEV - 1) == 0)
698         dev += 5;
699     if (strcmp(dev, "tty") == 0)
700         return 1;               /* don't look for /etc/ppp/options.tty */
701     path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
702     if (path == NULL)
703         novm("tty init file name");
704     strcpy(path, _PATH_TTYOPT);
705     /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
706     for (p = path + strlen(path); *dev != 0; ++dev)
707         *p++ = (*dev == '/'? '.': *dev);
708     *p = 0;
709     ret = options_from_file(path, 0, 0, 1);
710     free(path);
711     return ret;
712 }
713
714 /*
715  * option_error - print a message about an error in an option.
716  * The message is logged, and also sent to
717  * stderr if phase == PHASE_INITIALIZE.
718  */
719 void
720 option_error __V((char *fmt, ...))
721 {
722     va_list args;
723     char buf[256];
724
725 #if __STDC__
726     va_start(args, fmt);
727 #else
728     char *fmt;
729     va_start(args);
730     fmt = va_arg(args, char *);
731 #endif
732     vfmtmsg(buf, sizeof(buf), fmt, args);
733     va_end(args);
734     if (phase == PHASE_INITIALIZE)
735         fprintf(stderr, "%s: %s\n", progname, buf);
736     syslog(LOG_ERR, "%s", buf);
737 }
738
739 /*
740  * readable - check if a file is readable by the real user.
741  */
742 static int
743 readable(fd)
744     int fd;
745 {
746     uid_t uid;
747     int ngroups, i;
748     struct stat sbuf;
749     GIDSET_TYPE groups[NGROUPS_MAX];
750
751     uid = getuid();
752     if (uid == 0)
753         return 1;
754     if (fstat(fd, &sbuf) != 0)
755         return 0;
756     if (sbuf.st_uid == uid)
757         return sbuf.st_mode & S_IRUSR;
758     if (sbuf.st_gid == getgid())
759         return sbuf.st_mode & S_IRGRP;
760     ngroups = getgroups(NGROUPS_MAX, groups);
761     for (i = 0; i < ngroups; ++i)
762         if (sbuf.st_gid == groups[i])
763             return sbuf.st_mode & S_IRGRP;
764     return sbuf.st_mode & S_IROTH;
765 }
766
767 /*
768  * Read a word from a file.
769  * Words are delimited by white-space or by quotes (" or ').
770  * Quotes, white-space and \ may be escaped with \.
771  * \<newline> is ignored.
772  */
773 int
774 getword(f, word, newlinep, filename)
775     FILE *f;
776     char *word;
777     int *newlinep;
778     char *filename;
779 {
780     int c, len, escape;
781     int quoted, comment;
782     int value, digit, got, n;
783
784 #define isoctal(c) ((c) >= '0' && (c) < '8')
785
786     *newlinep = 0;
787     len = 0;
788     escape = 0;
789     comment = 0;
790
791     /*
792      * First skip white-space and comments.
793      */
794     for (;;) {
795         c = getc(f);
796         if (c == EOF)
797             break;
798
799         /*
800          * A newline means the end of a comment; backslash-newline
801          * is ignored.  Note that we cannot have escape && comment.
802          */
803         if (c == '\n') {
804             if (!escape) {
805                 *newlinep = 1;
806                 comment = 0;
807             } else
808                 escape = 0;
809             continue;
810         }
811
812         /*
813          * Ignore characters other than newline in a comment.
814          */
815         if (comment)
816             continue;
817
818         /*
819          * If this character is escaped, we have a word start.
820          */
821         if (escape)
822             break;
823
824         /*
825          * If this is the escape character, look at the next character.
826          */
827         if (c == '\\') {
828             escape = 1;
829             continue;
830         }
831
832         /*
833          * If this is the start of a comment, ignore the rest of the line.
834          */
835         if (c == '#') {
836             comment = 1;
837             continue;
838         }
839
840         /*
841          * A non-whitespace character is the start of a word.
842          */
843         if (!isspace(c))
844             break;
845     }
846
847     /*
848      * Save the delimiter for quoted strings.
849      */
850     if (!escape && (c == '"' || c == '\'')) {
851         quoted = c;
852         c = getc(f);
853     } else
854         quoted = 0;
855
856     /*
857      * Process characters until the end of the word.
858      */
859     while (c != EOF) {
860         if (escape) {
861             /*
862              * This character is escaped: backslash-newline is ignored,
863              * various other characters indicate particular values
864              * as for C backslash-escapes.
865              */
866             escape = 0;
867             if (c == '\n') {
868                 c = getc(f);
869                 continue;
870             }
871
872             got = 0;
873             switch (c) {
874             case 'a':
875                 value = '\a';
876                 break;
877             case 'b':
878                 value = '\b';
879                 break;
880             case 'f':
881                 value = '\f';
882                 break;
883             case 'n':
884                 value = '\n';
885                 break;
886             case 'r':
887                 value = '\r';
888                 break;
889             case 's':
890                 value = ' ';
891                 break;
892             case 't':
893                 value = '\t';
894                 break;
895
896             default:
897                 if (isoctal(c)) {
898                     /*
899                      * \ddd octal sequence
900                      */
901                     value = 0;
902                     for (n = 0; n < 3 && isoctal(c); ++n) {
903                         value = (value << 3) + (c & 07);
904                         c = getc(f);
905                     }
906                     got = 1;
907                     break;
908                 }
909
910                 if (c == 'x') {
911                     /*
912                      * \x<hex_string> sequence
913                      */
914                     value = 0;
915                     c = getc(f);
916                     for (n = 0; n < 2 && isxdigit(c); ++n) {
917                         digit = toupper(c) - '0';
918                         if (digit > 10)
919                             digit += '0' + 10 - 'A';
920                         value = (value << 4) + digit;
921                         c = getc (f);
922                     }
923                     got = 1;
924                     break;
925                 }
926
927                 /*
928                  * Otherwise the character stands for itself.
929                  */
930                 value = c;
931                 break;
932             }
933
934             /*
935              * Store the resulting character for the escape sequence.
936              */
937             if (len < MAXWORDLEN-1)
938                 word[len] = value;
939             ++len;
940
941             if (!got)
942                 c = getc(f);
943             continue;
944
945         }
946
947         /*
948          * Not escaped: see if we've reached the end of the word.
949          */
950         if (quoted) {
951             if (c == quoted)
952                 break;
953         } else {
954             if (isspace(c) || c == '#') {
955                 ungetc (c, f);
956                 break;
957             }
958         }
959
960         /*
961          * Backslash starts an escape sequence.
962          */
963         if (c == '\\') {
964             escape = 1;
965             c = getc(f);
966             continue;
967         }
968
969         /*
970          * An ordinary character: store it in the word and get another.
971          */
972         if (len < MAXWORDLEN-1)
973             word[len] = c;
974         ++len;
975
976         c = getc(f);
977     }
978
979     /*
980      * End of the word: check for errors.
981      */
982     if (c == EOF) {
983         if (ferror(f)) {
984             if (errno == 0)
985                 errno = EIO;
986             option_error("Error reading %s: %m", filename);
987             die(1);
988         }
989         /*
990          * If len is zero, then we didn't find a word before the
991          * end of the file.
992          */
993         if (len == 0)
994             return 0;
995     }
996
997     /*
998      * Warn if the word was too long, and append a terminating null.
999      */
1000     if (len >= MAXWORDLEN) {
1001         option_error("warning: word in file %s too long (%.20s...)",
1002                      filename, word);
1003         len = MAXWORDLEN - 1;
1004     }
1005     word[len] = 0;
1006
1007     return 1;
1008
1009 #undef isoctal
1010
1011 }
1012
1013 /*
1014  * number_option - parse an unsigned numeric parameter for an option.
1015  */
1016 static int
1017 number_option(str, valp, base)
1018     char *str;
1019     u_int32_t *valp;
1020     int base;
1021 {
1022     char *ptr;
1023
1024     *valp = strtoul(str, &ptr, base);
1025     if (ptr == str) {
1026         option_error("invalid numeric parameter '%s' for %s option",
1027                      str, current_option);
1028         return 0;
1029     }
1030     return 1;
1031 }
1032
1033
1034 /*
1035  * int_option - like number_option, but valp is int *,
1036  * the base is assumed to be 0, and *valp is not changed
1037  * if there is an error.
1038  */
1039 static int
1040 int_option(str, valp)
1041     char *str;
1042     int *valp;
1043 {
1044     u_int32_t v;
1045
1046     if (!number_option(str, &v, 0))
1047         return 0;
1048     *valp = (int) v;
1049     return 1;
1050 }
1051
1052
1053 /*
1054  * The following procedures parse options.
1055  */
1056
1057 /*
1058  * readfile - take commands from a file.
1059  */
1060 static int
1061 readfile(argv)
1062     char **argv;
1063 {
1064     return options_from_file(*argv, 1, 1, privileged_option);
1065 }
1066
1067 /*
1068  * callfile - take commands from /etc/ppp/peers/<name>.
1069  * Name may not contain /../, start with / or ../, or end in /..
1070  */
1071 static int
1072 callfile(argv)
1073     char **argv;
1074 {
1075     char *fname, *arg, *p;
1076     int l, ok;
1077
1078     arg = *argv;
1079     ok = 1;
1080     if (arg[0] == '/' || arg[0] == 0)
1081         ok = 0;
1082     else {
1083         for (p = arg; *p != 0; ) {
1084             if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
1085                 ok = 0;
1086                 break;
1087             }
1088             while (*p != '/' && *p != 0)
1089                 ++p;
1090             if (*p == '/')
1091                 ++p;
1092         }
1093     }
1094     if (!ok) {
1095         option_error("call option value may not contain .. or start with /");
1096         return 0;
1097     }
1098
1099     l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
1100     if ((fname = (char *) malloc(l)) == NULL)
1101         novm("call file name");
1102     strcpy(fname, _PATH_PEERFILES);
1103     strcat(fname, arg);
1104
1105     ok = options_from_file(fname, 1, 1, 1);
1106
1107     free(fname);
1108     return ok;
1109 }
1110
1111
1112 /*
1113  * setdebug - Set debug (command line argument).
1114  */
1115 static int
1116 setdebug(argv)
1117     char **argv;
1118 {
1119     debug++;
1120     return (1);
1121 }
1122
1123 /*
1124  * setkdebug - Set kernel debugging level.
1125  */
1126 static int
1127 setkdebug(argv)
1128     char **argv;
1129 {
1130     return int_option(*argv, &kdebugflag);
1131 }
1132
1133 #ifdef PPP_FILTER
1134 /*
1135  * setpdebug - Set libpcap debugging level.
1136  */
1137 static int
1138 setpdebug(argv)
1139     char **argv;
1140 {
1141     return int_option(*argv, &dflag);
1142 }
1143
1144 /*
1145  * setpassfilter - Set the pass filter for packets
1146  */
1147 static int
1148 setpassfilter(argv)
1149     char **argv;
1150 {
1151     pc.linktype = DLT_PPP;
1152     pc.snapshot = PPP_HDRLEN;
1153  
1154     if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0)
1155         return 1;
1156     option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc));
1157     return 0;
1158 }
1159
1160 /*
1161  * setactivefilter - Set the active filter for packets
1162  */
1163 static int
1164 setactivefilter(argv)
1165     char **argv;
1166 {
1167     pc.linktype = DLT_PPP;
1168     pc.snapshot = PPP_HDRLEN;
1169  
1170     if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0)
1171         return 1;
1172     option_error("error in active-filter expression: %s\n", pcap_geterr(&pc));
1173     return 0;
1174 }
1175 #endif
1176
1177 /*
1178  * noopt - Disable all options.
1179  */
1180 static int
1181 noopt(argv)
1182     char **argv;
1183 {
1184     BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
1185     BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
1186     BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
1187     BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
1188
1189 #ifdef IPX_CHANGE
1190     BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
1191     BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
1192 #endif /* IPX_CHANGE */
1193
1194     return (1);
1195 }
1196
1197 /*
1198  * noaccomp - Disable Address/Control field compression negotiation.
1199  */
1200 static int
1201 noaccomp(argv)
1202     char **argv;
1203 {
1204     lcp_wantoptions[0].neg_accompression = 0;
1205     lcp_allowoptions[0].neg_accompression = 0;
1206     return (1);
1207 }
1208
1209
1210 /*
1211  * noasyncmap - Disable async map negotiation.
1212  */
1213 static int
1214 noasyncmap(argv)
1215     char **argv;
1216 {
1217     lcp_wantoptions[0].neg_asyncmap = 0;
1218     lcp_allowoptions[0].neg_asyncmap = 0;
1219     return (1);
1220 }
1221
1222
1223 /*
1224  * noip - Disable IP and IPCP.
1225  */
1226 static int
1227 noip(argv)
1228     char **argv;
1229 {
1230     ipcp_protent.enabled_flag = 0;
1231     return (1);
1232 }
1233
1234
1235 /*
1236  * nomagicnumber - Disable magic number negotiation.
1237  */
1238 static int
1239 nomagicnumber(argv)
1240     char **argv;
1241 {
1242     lcp_wantoptions[0].neg_magicnumber = 0;
1243     lcp_allowoptions[0].neg_magicnumber = 0;
1244     return (1);
1245 }
1246
1247
1248 /*
1249  * nomru - Disable mru negotiation.
1250  */
1251 static int
1252 nomru(argv)
1253     char **argv;
1254 {
1255     lcp_wantoptions[0].neg_mru = 0;
1256     lcp_allowoptions[0].neg_mru = 0;
1257     return (1);
1258 }
1259
1260
1261 /*
1262  * setmru - Set MRU for negotiation.
1263  */
1264 static int
1265 setmru(argv)
1266     char **argv;
1267 {
1268     u_int32_t mru;
1269
1270     if (!number_option(*argv, &mru, 0))
1271         return 0;
1272     lcp_wantoptions[0].mru = mru;
1273     lcp_wantoptions[0].neg_mru = 1;
1274     return (1);
1275 }
1276
1277
1278 /*
1279  * setmru - Set the largest MTU we'll use.
1280  */
1281 static int
1282 setmtu(argv)
1283     char **argv;
1284 {
1285     u_int32_t mtu;
1286
1287     if (!number_option(*argv, &mtu, 0))
1288         return 0;
1289     if (mtu < MINMRU || mtu > MAXMRU) {
1290         option_error("mtu option value of %u is too %s", mtu,
1291                      (mtu < MINMRU? "small": "large"));
1292         return 0;
1293     }
1294     lcp_allowoptions[0].mru = mtu;
1295     return (1);
1296 }
1297
1298 #ifdef CBCP_SUPPORT
1299 static int
1300 setcbcp(argv)
1301     char **argv;
1302 {
1303     lcp_wantoptions[0].neg_cbcp = 1;
1304     cbcp_protent.enabled_flag = 1;
1305     cbcp[0].us_number = strdup(*argv);
1306     if (cbcp[0].us_number == 0)
1307         novm("callback number");
1308     cbcp[0].us_type |= (1 << CB_CONF_USER);
1309     cbcp[0].us_type |= (1 << CB_CONF_ADMIN);
1310     return (1);
1311 }
1312 #endif
1313
1314 /*
1315  * nopcomp - Disable Protocol field compression negotiation.
1316  */
1317 static int
1318 nopcomp(argv)
1319     char **argv;
1320 {
1321     lcp_wantoptions[0].neg_pcompression = 0;
1322     lcp_allowoptions[0].neg_pcompression = 0;
1323     return (1);
1324 }
1325
1326
1327 /*
1328  * setpassive - Set passive mode (don't give up if we time out sending
1329  * LCP configure-requests).
1330  */
1331 static int
1332 setpassive(argv)
1333     char **argv;
1334 {
1335     lcp_wantoptions[0].passive = 1;
1336     return (1);
1337 }
1338
1339
1340 /*
1341  * setsilent - Set silent mode (don't start sending LCP configure-requests
1342  * until we get one from the peer).
1343  */
1344 static int
1345 setsilent(argv)
1346     char **argv;
1347 {
1348     lcp_wantoptions[0].silent = 1;
1349     return 1;
1350 }
1351
1352
1353 /*
1354  * nopap - Disable PAP authentication with peer.
1355  */
1356 static int
1357 nopap(argv)
1358     char **argv;
1359 {
1360     refuse_pap = 1;
1361     return (1);
1362 }
1363
1364
1365 /*
1366  * reqpap - Require PAP authentication from peer.
1367  */
1368 static int
1369 reqpap(argv)
1370     char **argv;
1371 {
1372     lcp_wantoptions[0].neg_upap = 1;
1373     setauth(NULL);
1374     return 1;
1375 }
1376
1377 #if OLD_OPTIONS
1378 /*
1379  * setupapfile - specifies UPAP info for authenticating with peer.
1380  */
1381 static int
1382 setupapfile(argv)
1383     char **argv;
1384 {
1385     FILE * ufile;
1386     int l;
1387
1388     lcp_allowoptions[0].neg_upap = 1;
1389
1390     /* open user info file */
1391     if ((ufile = fopen(*argv, "r")) == NULL) {
1392         option_error("unable to open user login data file %s", *argv);
1393         return 0;
1394     }
1395     if (!readable(fileno(ufile))) {
1396         option_error("%s: access denied", *argv);
1397         return 0;
1398     }
1399     check_access(ufile, *argv);
1400
1401     /* get username */
1402     if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1403         || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1404         option_error("unable to read user login data file %s", *argv);
1405         return 0;
1406     }
1407     fclose(ufile);
1408
1409     /* get rid of newlines */
1410     l = strlen(user);
1411     if (l > 0 && user[l-1] == '\n')
1412         user[l-1] = 0;
1413     l = strlen(passwd);
1414     if (l > 0 && passwd[l-1] == '\n')
1415         passwd[l-1] = 0;
1416
1417     return (1);
1418 }
1419 #endif
1420
1421 /*
1422  * nochap - Disable CHAP authentication with peer.
1423  */
1424 static int
1425 nochap(argv)
1426     char **argv;
1427 {
1428     refuse_chap = 1;
1429     return (1);
1430 }
1431
1432
1433 /*
1434  * reqchap - Require CHAP authentication from peer.
1435  */
1436 static int
1437 reqchap(argv)
1438     char **argv;
1439 {
1440     lcp_wantoptions[0].neg_chap = 1;
1441     setauth(NULL);
1442     return (1);
1443 }
1444
1445
1446 /*
1447  * setnovj - disable vj compression
1448  */
1449 static int
1450 setnovj(argv)
1451     char **argv;
1452 {
1453     ipcp_wantoptions[0].neg_vj = 0;
1454     ipcp_allowoptions[0].neg_vj = 0;
1455     return (1);
1456 }
1457
1458
1459 /*
1460  * setnovjccomp - disable VJ connection-ID compression
1461  */
1462 static int
1463 setnovjccomp(argv)
1464     char **argv;
1465 {
1466     ipcp_wantoptions[0].cflag = 0;
1467     ipcp_allowoptions[0].cflag = 0;
1468     return 1;
1469 }
1470
1471
1472 /*
1473  * setvjslots - set maximum number of connection slots for VJ compression
1474  */
1475 static int
1476 setvjslots(argv)
1477     char **argv;
1478 {
1479     int value;
1480
1481     if (!int_option(*argv, &value))
1482         return 0;
1483     if (value < 2 || value > 16) {
1484         option_error("vj-max-slots value must be between 2 and 16");
1485         return 0;
1486     }
1487     ipcp_wantoptions [0].maxslotindex =
1488         ipcp_allowoptions[0].maxslotindex = value - 1;
1489     return 1;
1490 }
1491
1492
1493 /*
1494  * setconnector - Set a program to connect to a serial line
1495  */
1496 static int
1497 setconnector(argv)
1498     char **argv;
1499 {
1500     connector = strdup(*argv);
1501     if (connector == NULL)
1502         novm("connect script");
1503     connector_info.priv = privileged_option;
1504     connector_info.source = option_source;
1505
1506     return (1);
1507 }
1508
1509 /*
1510  * setdisconnector - Set a program to disconnect from the serial line
1511  */
1512 static int
1513 setdisconnector(argv)
1514     char **argv;
1515 {
1516     disconnector = strdup(*argv);
1517     if (disconnector == NULL)
1518         novm("disconnect script");
1519     disconnector_info.priv = privileged_option;
1520     disconnector_info.source = option_source;
1521   
1522     return (1);
1523 }
1524
1525 /*
1526  * setwelcomer - Set a program to welcome a client after connection
1527  */
1528 static int
1529 setwelcomer(argv)
1530     char **argv;
1531 {
1532     welcomer = strdup(*argv);
1533     if (welcomer == NULL)
1534         novm("welcome script");
1535     welcomer_info.priv = privileged_option;
1536     welcomer_info.source = option_source;
1537
1538     return (1);
1539 }
1540
1541 static int
1542 setmaxcon(argv)
1543     char **argv;
1544 {
1545     return int_option(*argv, &max_con_attempts);
1546 }
1547
1548 /*
1549  * setmaxconnect - Set the maximum connect time
1550  */
1551 static int
1552 setmaxconnect(argv)
1553     char **argv;
1554 {
1555     int value;
1556
1557     if (!int_option(*argv, &value))
1558         return 0;
1559     if (value < 0) {
1560         option_error("maxconnect time must be positive");
1561         return 0;
1562     }
1563     if (maxconnect > 0 && (value == 0 || value > maxconnect)) {
1564         option_error("maxconnect time cannot be increased");
1565         return 0;
1566     }
1567     maxconnect = value;
1568     return 1;
1569 }
1570
1571 /*
1572  * setdomain - Set domain name to append to hostname 
1573  */
1574 static int
1575 setdomain(argv)
1576     char **argv;
1577 {
1578     if (!privileged_option) {
1579         option_error("using the domain option requires root privilege");
1580         return 0;
1581     }
1582     gethostname(hostname, MAXNAMELEN);
1583     if (**argv != 0) {
1584         if (**argv != '.')
1585             strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1586         strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1587     }
1588     hostname[MAXNAMELEN-1] = 0;
1589     return (1);
1590 }
1591
1592
1593 /*
1594  * setasyncmap - add bits to asyncmap (what we request peer to escape).
1595  */
1596 static int
1597 setasyncmap(argv)
1598     char **argv;
1599 {
1600     u_int32_t asyncmap;
1601
1602     if (!number_option(*argv, &asyncmap, 16))
1603         return 0;
1604     lcp_wantoptions[0].asyncmap |= asyncmap;
1605     lcp_wantoptions[0].neg_asyncmap = 1;
1606     return(1);
1607 }
1608
1609
1610 /*
1611  * setescape - add chars to the set we escape on transmission.
1612  */
1613 static int
1614 setescape(argv)
1615     char **argv;
1616 {
1617     int n, ret;
1618     char *p, *endp;
1619
1620     p = *argv;
1621     ret = 1;
1622     while (*p) {
1623         n = strtol(p, &endp, 16);
1624         if (p == endp) {
1625             option_error("escape parameter contains invalid hex number '%s'",
1626                          p);
1627             return 0;
1628         }
1629         p = endp;
1630         if (n < 0 || (0x20 <= n && n <= 0x3F) || n == 0x5E || n > 0xFF) {
1631             option_error("can't escape character 0x%x", n);
1632             ret = 0;
1633         } else
1634             xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1635         while (*p == ',' || *p == ' ')
1636             ++p;
1637     }
1638     return ret;
1639 }
1640
1641
1642 /*
1643  * setspeed - Set the speed.
1644  */
1645 static int
1646 setspeed(arg)
1647     char *arg;
1648 {
1649     char *ptr;
1650     int spd;
1651
1652     spd = strtol(arg, &ptr, 0);
1653     if (ptr == arg || *ptr != 0 || spd == 0)
1654         return 0;
1655     inspeed = spd;
1656     return 1;
1657 }
1658
1659
1660 /*
1661  * setdevname - Set the device name.
1662  */
1663 static int
1664 setdevname(cp, quiet)
1665     char *cp;
1666     int quiet;
1667 {
1668     struct stat statbuf;
1669     char dev[MAXPATHLEN];
1670
1671     if (*cp == 0)
1672         return 0;
1673
1674     if (strncmp(_PATH_DEV, cp, sizeof _PATH_DEV - 1) != 0) {
1675         strcpy(dev, _PATH_DEV);
1676         strncat(dev, cp, MAXPATHLEN - sizeof _PATH_DEV - 1);
1677         dev[MAXPATHLEN-1] = 0;
1678         cp = dev;
1679     }
1680
1681     /*
1682      * Check if there is a device by this name.
1683      */
1684     if (stat(cp, &statbuf) < 0) {
1685         if (errno == ENOENT || quiet)
1686             return 0;
1687         option_error("Couldn't stat %s: %m", cp);
1688         return -1;
1689     }
1690
1691     strncpy(devnam, cp, MAXPATHLEN);
1692     devnam[MAXPATHLEN-1] = 0;
1693     default_device = FALSE;
1694     devnam_info.priv = privileged_option;
1695     devnam_info.source = option_source;
1696   
1697     return 1;
1698 }
1699
1700
1701 /*
1702  * setipaddr - Set the IP address
1703  */
1704 int
1705 setipaddr(arg)
1706     char *arg;
1707 {
1708     struct hostent *hp;
1709     char *colon;
1710     u_int32_t local, remote;
1711     ipcp_options *wo = &ipcp_wantoptions[0];
1712   
1713     /*
1714      * IP address pair separated by ":".
1715      */
1716     if ((colon = strchr(arg, ':')) == NULL)
1717         return 0;
1718   
1719     /*
1720      * If colon first character, then no local addr.
1721      */
1722     if (colon != arg) {
1723         *colon = '\0';
1724         if ((local = inet_addr(arg)) == -1) {
1725             if ((hp = gethostbyname(arg)) == NULL) {
1726                 option_error("unknown host: %s", arg);
1727                 return -1;
1728             } else {
1729                 local = *(u_int32_t *)hp->h_addr;
1730             }
1731         }
1732         if (bad_ip_adrs(local)) {
1733             option_error("bad local IP address %s", ip_ntoa(local));
1734             return -1;
1735         }
1736         if (local != 0)
1737             wo->ouraddr = local;
1738         *colon = ':';
1739     }
1740   
1741     /*
1742      * If colon last character, then no remote addr.
1743      */
1744     if (*++colon != '\0') {
1745         if ((remote = inet_addr(colon)) == -1) {
1746             if ((hp = gethostbyname(colon)) == NULL) {
1747                 option_error("unknown host: %s", colon);
1748                 return -1;
1749             } else {
1750                 remote = *(u_int32_t *)hp->h_addr;
1751                 if (remote_name[0] == 0) {
1752                     strncpy(remote_name, colon, MAXNAMELEN);
1753                     remote_name[MAXNAMELEN-1] = 0;
1754                 }
1755             }
1756         }
1757         if (bad_ip_adrs(remote)) {
1758             option_error("bad remote IP address %s", ip_ntoa(remote));
1759             return -1;
1760         }
1761         if (remote != 0)
1762             wo->hisaddr = remote;
1763     }
1764
1765     return 1;
1766 }
1767
1768
1769 /*
1770  * setnoipdflt - disable setipdefault()
1771  */
1772 static int
1773 setnoipdflt(argv)
1774     char **argv;
1775 {
1776     disable_defaultip = 1;
1777     return 1;
1778 }
1779
1780
1781 /*
1782  * setipcpaccl - accept peer's idea of our address
1783  */
1784 static int
1785 setipcpaccl(argv)
1786     char **argv;
1787 {
1788     ipcp_wantoptions[0].accept_local = 1;
1789     return 1;
1790 }
1791
1792
1793 /*
1794  * setipcpaccr - accept peer's idea of its address
1795  */
1796 static int
1797 setipcpaccr(argv)
1798     char **argv;
1799 {
1800     ipcp_wantoptions[0].accept_remote = 1;
1801     return 1;
1802 }
1803
1804
1805 /*
1806  * setnetmask - set the netmask to be used on the interface.
1807  */
1808 static int
1809 setnetmask(argv)
1810     char **argv;
1811 {
1812     struct in_addr mask;
1813
1814     if (!inet_aton(*argv, &mask) || (netmask & ~mask.s_addr)) {
1815         fprintf(stderr, "Invalid netmask %s\n", *argv);
1816         return (0);
1817     }
1818
1819     netmask = mask.s_addr;
1820     return (1);
1821 }
1822
1823 static int
1824 setcrtscts(argv)
1825     char **argv;
1826 {
1827     crtscts = 1;
1828     return (1);
1829 }
1830
1831 static int
1832 setnocrtscts(argv)
1833     char **argv;
1834 {
1835     crtscts = -1;
1836     return (1);
1837 }
1838
1839 static int
1840 setxonxoff(argv)
1841     char **argv;
1842 {
1843     lcp_wantoptions[0].asyncmap |= 0x000A0000;  /* escape ^S and ^Q */
1844     lcp_wantoptions[0].neg_asyncmap = 1;
1845
1846     crtscts = -2;
1847     return (1);
1848 }
1849
1850 static int
1851 setnodetach(argv)
1852     char **argv;
1853 {
1854     nodetach = 1;
1855     return (1);
1856 }
1857
1858 static int
1859 setupdetach(argv)
1860     char **argv;
1861 {
1862     nodetach = -1;
1863     return (1);
1864 }
1865
1866 static int
1867 setdemand(argv)
1868     char **argv;
1869 {
1870     demand = 1;
1871     persist = 1;
1872     return 1;
1873 }
1874
1875 static int
1876 setmodem(argv)
1877     char **argv;
1878 {
1879     modem = 1;
1880     return 1;
1881 }
1882
1883 static int
1884 setlocal(argv)
1885     char **argv;
1886 {
1887     modem = 0;
1888     return 1;
1889 }
1890
1891 static int
1892 setlock(argv)
1893     char **argv;
1894 {
1895     lockflag = 1;
1896     return 1;
1897 }
1898
1899 static int
1900 setusehostname(argv)
1901     char **argv;
1902 {
1903     usehostname = 1;
1904     return 1;
1905 }
1906
1907 static int
1908 setname(argv)
1909     char **argv;
1910 {
1911     if (!privileged_option) {
1912         option_error("using the name option requires root privilege");
1913         return 0;
1914     }
1915     strncpy(our_name, argv[0], MAXNAMELEN);
1916     our_name[MAXNAMELEN-1] = 0;
1917     return 1;
1918 }
1919
1920 static int
1921 setuser(argv)
1922     char **argv;
1923 {
1924     strncpy(user, argv[0], MAXNAMELEN);
1925     user[MAXNAMELEN-1] = 0;
1926     return 1;
1927 }
1928
1929 static int
1930 setremote(argv)
1931     char **argv;
1932 {
1933     strncpy(remote_name, argv[0], MAXNAMELEN);
1934     remote_name[MAXNAMELEN-1] = 0;
1935     return 1;
1936 }
1937
1938 static int
1939 setauth(argv)
1940     char **argv;
1941 {
1942     auth_required = 1;
1943     if (privileged_option > auth_req_info.priv) {
1944         auth_req_info.priv = privileged_option;
1945         auth_req_info.source = option_source;
1946     }
1947     return 1;
1948 }
1949
1950 static int
1951 setnoauth(argv)
1952     char **argv;
1953 {
1954     if (auth_required && privileged_option < auth_req_info.priv) {
1955         option_error("cannot override auth option set by %s",
1956                      auth_req_info.source);
1957         return 0;
1958     }
1959     auth_required = 0;
1960     return 1;
1961 }
1962
1963 static int
1964 setdefaultroute(argv)
1965     char **argv;
1966 {
1967     if (!ipcp_allowoptions[0].default_route) {
1968         option_error("defaultroute option is disabled");
1969         return 0;
1970     }
1971     ipcp_wantoptions[0].default_route = 1;
1972     return 1;
1973 }
1974
1975 static int
1976 setnodefaultroute(argv)
1977     char **argv;
1978 {
1979     ipcp_allowoptions[0].default_route = 0;
1980     ipcp_wantoptions[0].default_route = 0;
1981     return 1;
1982 }
1983
1984 static int
1985 setproxyarp(argv)
1986     char **argv;
1987 {
1988     if (!ipcp_allowoptions[0].proxy_arp) {
1989         option_error("proxyarp option is disabled");
1990         return 0;
1991     }
1992     ipcp_wantoptions[0].proxy_arp = 1;
1993     return 1;
1994 }
1995
1996 static int
1997 setnoproxyarp(argv)
1998     char **argv;
1999 {
2000     ipcp_wantoptions[0].proxy_arp = 0;
2001     ipcp_allowoptions[0].proxy_arp = 0;
2002     return 1;
2003 }
2004
2005 static int
2006 setpersist(argv)
2007     char **argv;
2008 {
2009     persist = 1;
2010     return 1;
2011 }
2012
2013 static int
2014 setnopersist(argv)
2015     char **argv;
2016 {
2017     persist = 0;
2018     return 1;
2019 }
2020
2021 static int
2022 setdologin(argv)
2023     char **argv;
2024 {
2025     uselogin = 1;
2026     return 1;
2027 }
2028
2029 /*
2030  * Functions to set the echo interval for modem-less monitors
2031  */
2032
2033 static int
2034 setlcpechointv(argv)
2035     char **argv;
2036 {
2037     return int_option(*argv, &lcp_echo_interval);
2038 }
2039
2040 static int
2041 setlcpechofails(argv)
2042     char **argv;
2043 {
2044     return int_option(*argv, &lcp_echo_fails);
2045 }
2046
2047 /*
2048  * Functions to set timeouts, max transmits, etc.
2049  */
2050 static int
2051 setlcptimeout(argv)
2052     char **argv;
2053 {
2054     return int_option(*argv, &lcp_fsm[0].timeouttime);
2055 }
2056
2057 static int
2058 setlcpterm(argv)
2059     char **argv;
2060 {
2061     return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
2062 }
2063
2064 static int
2065 setlcpconf(argv)
2066     char **argv;
2067 {
2068     return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
2069 }
2070
2071 static int
2072 setlcpfails(argv)
2073     char **argv;
2074 {
2075     return int_option(*argv, &lcp_fsm[0].maxnakloops);
2076 }
2077
2078 static int
2079 setipcptimeout(argv)
2080     char **argv;
2081 {
2082     return int_option(*argv, &ipcp_fsm[0].timeouttime);
2083 }
2084
2085 static int
2086 setipcpterm(argv)
2087     char **argv;
2088 {
2089     return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
2090 }
2091
2092 static int
2093 setipcpconf(argv)
2094     char **argv;
2095 {
2096     return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
2097 }
2098
2099 static int
2100 setipcpfails(argv)
2101     char **argv;
2102 {
2103     return int_option(*argv, &lcp_fsm[0].maxnakloops);
2104 }
2105
2106 static int
2107 setpaptimeout(argv)
2108     char **argv;
2109 {
2110     return int_option(*argv, &upap[0].us_timeouttime);
2111 }
2112
2113 static int
2114 setpapreqtime(argv)
2115     char **argv;
2116 {
2117     return int_option(*argv, &upap[0].us_reqtimeout);
2118 }
2119
2120 static int
2121 setpapreqs(argv)
2122     char **argv;
2123 {
2124     return int_option(*argv, &upap[0].us_maxtransmits);
2125 }
2126
2127 static int
2128 setchaptimeout(argv)
2129     char **argv;
2130 {
2131     return int_option(*argv, &chap[0].timeouttime);
2132 }
2133
2134 static int
2135 setchapchal(argv)
2136     char **argv;
2137 {
2138     return int_option(*argv, &chap[0].max_transmits);
2139 }
2140
2141 static int
2142 setchapintv(argv)
2143     char **argv;
2144 {
2145     return int_option(*argv, &chap[0].chal_interval);
2146 }
2147
2148 static int
2149 noccp(argv)
2150     char **argv;
2151 {
2152     ccp_protent.enabled_flag = 0;
2153     return 1;
2154 }
2155
2156 static int
2157 setbsdcomp(argv)
2158     char **argv;
2159 {
2160     int rbits, abits;
2161     char *str, *endp;
2162
2163     str = *argv;
2164     abits = rbits = strtol(str, &endp, 0);
2165     if (endp != str && *endp == ',') {
2166         str = endp + 1;
2167         abits = strtol(str, &endp, 0);
2168     }
2169     if (*endp != 0 || endp == str) {
2170         option_error("invalid parameter '%s' for bsdcomp option", *argv);
2171         return 0;
2172     }
2173     if ((rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS))
2174         || (abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS))) {
2175         option_error("bsdcomp option values must be 0 or %d .. %d",
2176                      BSD_MIN_BITS, BSD_MAX_BITS);
2177         return 0;
2178     }
2179     if (rbits > 0) {
2180         ccp_wantoptions[0].bsd_compress = 1;
2181         ccp_wantoptions[0].bsd_bits = rbits;
2182     } else
2183         ccp_wantoptions[0].bsd_compress = 0;
2184     if (abits > 0) {
2185         ccp_allowoptions[0].bsd_compress = 1;
2186         ccp_allowoptions[0].bsd_bits = abits;
2187     } else
2188         ccp_allowoptions[0].bsd_compress = 0;
2189     return 1;
2190 }
2191
2192 static int
2193 setnobsdcomp(argv)
2194     char **argv;
2195 {
2196     ccp_wantoptions[0].bsd_compress = 0;
2197     ccp_allowoptions[0].bsd_compress = 0;
2198     return 1;
2199 }
2200
2201 static int
2202 setdeflate(argv)
2203     char **argv;
2204 {
2205     int rbits, abits;
2206     char *str, *endp;
2207
2208     str = *argv;
2209     abits = rbits = strtol(str, &endp, 0);
2210     if (endp != str && *endp == ',') {
2211         str = endp + 1;
2212         abits = strtol(str, &endp, 0);
2213     }
2214     if (*endp != 0 || endp == str) {
2215         option_error("invalid parameter '%s' for deflate option", *argv);
2216         return 0;
2217     }
2218     if ((rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE))
2219         || (abits != 0 && (abits < DEFLATE_MIN_SIZE
2220                           || abits > DEFLATE_MAX_SIZE))) {
2221         option_error("deflate option values must be 0 or %d .. %d",
2222                      DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
2223         return 0;
2224     }
2225     if (rbits > 0) {
2226         ccp_wantoptions[0].deflate = 1;
2227         ccp_wantoptions[0].deflate_size = rbits;
2228     } else
2229         ccp_wantoptions[0].deflate = 0;
2230     if (abits > 0) {
2231         ccp_allowoptions[0].deflate = 1;
2232         ccp_allowoptions[0].deflate_size = abits;
2233     } else
2234         ccp_allowoptions[0].deflate = 0;
2235
2236     /* XXX copy over settings for switch compatibility */
2237     ccp_wantoptions[0].baddeflate = ccp_wantoptions[0].deflate;
2238     ccp_wantoptions[0].baddeflate_size = ccp_wantoptions[0].deflate_size;
2239     ccp_allowoptions[0].baddeflate = ccp_allowoptions[0].deflate;
2240     ccp_allowoptions[0].baddeflate_size = ccp_allowoptions[0].deflate_size;
2241
2242     return 1;
2243 }
2244
2245 static int
2246 setnodeflate(argv)
2247     char **argv;
2248 {
2249     ccp_wantoptions[0].deflate = 0;
2250     ccp_allowoptions[0].deflate = 0;
2251     return 1;
2252 }
2253
2254 static int
2255 setnodeflatedraft(argv)
2256     char **argv;
2257 {
2258     ccp_wantoptions[0].deflate_draft = 0;
2259     ccp_allowoptions[0].deflate_draft = 0;
2260     return 1;
2261 }
2262
2263 static int
2264 setpred1comp(argv)
2265     char **argv;
2266 {
2267     ccp_wantoptions[0].predictor_1 = 1;
2268     ccp_allowoptions[0].predictor_1 = 1;
2269     return 1;
2270 }
2271
2272 static int
2273 setnopred1comp(argv)
2274     char **argv;
2275 {
2276     ccp_wantoptions[0].predictor_1 = 0;
2277     ccp_allowoptions[0].predictor_1 = 0;
2278     return 1;
2279 }
2280
2281 static int
2282 setipparam(argv)
2283     char **argv;
2284 {
2285     ipparam = strdup(*argv);
2286     if (ipparam == NULL)
2287         novm("ipparam string");
2288
2289     return 1;
2290 }
2291
2292 static int
2293 setpapcrypt(argv)
2294     char **argv;
2295 {
2296     cryptpap = 1;
2297     return 1;
2298 }
2299
2300 static int
2301 setidle(argv)
2302     char **argv;
2303 {
2304     return int_option(*argv, &idle_time_limit);
2305 }
2306
2307 static int
2308 setholdoff(argv)
2309     char **argv;
2310 {
2311     return int_option(*argv, &holdoff);
2312 }
2313
2314 /*
2315  * setdnsaddr - set the dns address(es)
2316  */
2317 static int
2318 setdnsaddr(argv)
2319     char **argv;
2320 {
2321     u_int32_t dns;
2322     struct hostent *hp;
2323
2324     dns = inet_addr(*argv);
2325     if (dns == -1) {
2326         if ((hp = gethostbyname(*argv)) == NULL) {
2327             option_error("invalid address parameter '%s' for ms-dns option",
2328                          *argv);
2329             return 0;
2330         }
2331         dns = *(u_int32_t *)hp->h_addr;
2332     }
2333
2334     /* if there is no primary then update it. */
2335     if (ipcp_allowoptions[0].dnsaddr[0] == 0)
2336         ipcp_allowoptions[0].dnsaddr[0] = dns;
2337
2338     /* always set the secondary address value to the same value. */
2339     ipcp_allowoptions[0].dnsaddr[1] = dns;
2340
2341     return (1);
2342 }
2343
2344 /*
2345  * setwinsaddr - set the wins address(es)
2346  * This is primrarly used with the Samba package under UNIX or for pointing
2347  * the caller to the existing WINS server on a Windows NT platform.
2348  */
2349 static int
2350 setwinsaddr(argv)
2351     char **argv;
2352 {
2353     u_int32_t wins;
2354     struct hostent *hp;
2355
2356     wins = inet_addr(*argv);
2357     if (wins == -1) {
2358         if ((hp = gethostbyname(*argv)) == NULL) {
2359             option_error("invalid address parameter '%s' for ms-wins option",
2360                          *argv);
2361             return 0;
2362         }
2363         wins = *(u_int32_t *)hp->h_addr;
2364     }
2365
2366     /* if there is no primary then update it. */
2367     if (ipcp_allowoptions[0].winsaddr[0] == 0)
2368         ipcp_allowoptions[0].winsaddr[0] = wins;
2369
2370     /* always set the secondary address value to the same value. */
2371     ipcp_allowoptions[0].winsaddr[1] = wins;
2372
2373     return (1);
2374 }
2375
2376 #ifdef IPX_CHANGE
2377 static int
2378 setipxrouter (argv)
2379     char **argv;
2380 {
2381     ipxcp_wantoptions[0].neg_router  = 1;
2382     ipxcp_allowoptions[0].neg_router = 1;
2383     return int_option(*argv, &ipxcp_wantoptions[0].router); 
2384 }
2385
2386 static int
2387 setipxname (argv)
2388     char **argv;
2389 {
2390     char *dest = ipxcp_wantoptions[0].name;
2391     char *src  = *argv;
2392     int  count;
2393     char ch;
2394
2395     ipxcp_wantoptions[0].neg_name  = 1;
2396     ipxcp_allowoptions[0].neg_name = 1;
2397     memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
2398
2399     count = 0;
2400     while (*src) {
2401         ch = *src++;
2402         if (! isalnum (ch) && ch != '_') {
2403             option_error("IPX router name must be alphanumeric or _");
2404             return 0;
2405         }
2406
2407         if (count >= sizeof (ipxcp_wantoptions[0].name)) {
2408             option_error("IPX router name is limited to %d characters",
2409                          sizeof (ipxcp_wantoptions[0].name) - 1);
2410             return 0;
2411         }
2412
2413         dest[count++] = toupper (ch);
2414     }
2415
2416     return 1;
2417 }
2418
2419 static int
2420 setipxcptimeout (argv)
2421     char **argv;
2422 {
2423     return int_option(*argv, &ipxcp_fsm[0].timeouttime);
2424 }
2425
2426 static int
2427 setipxcpterm (argv)
2428     char **argv;
2429 {
2430     return int_option(*argv, &ipxcp_fsm[0].maxtermtransmits);
2431 }
2432
2433 static int
2434 setipxcpconf (argv)
2435     char **argv;
2436 {
2437     return int_option(*argv, &ipxcp_fsm[0].maxconfreqtransmits);
2438 }
2439
2440 static int
2441 setipxcpfails (argv)
2442     char **argv;
2443 {
2444     return int_option(*argv, &ipxcp_fsm[0].maxnakloops);
2445 }
2446
2447 static int
2448 setipxnetwork(argv)
2449     char **argv;
2450 {
2451     u_int32_t v;
2452
2453     if (!number_option(*argv, &v, 16))
2454         return 0;
2455
2456     ipxcp_wantoptions[0].our_network = (int) v;
2457     ipxcp_wantoptions[0].neg_nn      = 1;
2458     return 1;
2459 }
2460
2461 static int
2462 setipxanet(argv)
2463     char **argv;
2464 {
2465     ipxcp_wantoptions[0].accept_network = 1;
2466     ipxcp_allowoptions[0].accept_network = 1;
2467     return 1;
2468 }
2469
2470 static int
2471 setipxalcl(argv)
2472     char **argv;
2473 {
2474     ipxcp_wantoptions[0].accept_local = 1;
2475     ipxcp_allowoptions[0].accept_local = 1;
2476     return 1;
2477 }
2478
2479 static int
2480 setipxarmt(argv)
2481     char **argv;
2482 {
2483     ipxcp_wantoptions[0].accept_remote = 1;
2484     ipxcp_allowoptions[0].accept_remote = 1;
2485     return 1;
2486 }
2487
2488 static u_char *
2489 setipxnodevalue(src,dst)
2490 u_char *src, *dst;
2491 {
2492     int indx;
2493     int item;
2494
2495     for (;;) {
2496         if (!isxdigit (*src))
2497             break;
2498         
2499         for (indx = 0; indx < 5; ++indx) {
2500             dst[indx] <<= 4;
2501             dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
2502         }
2503
2504         item = toupper (*src) - '0';
2505         if (item > 9)
2506             item -= 7;
2507
2508         dst[5] = (dst[5] << 4) | item;
2509         ++src;
2510     }
2511     return src;
2512 }
2513
2514 static int
2515 setipxnode(argv)
2516     char **argv;
2517 {
2518     char *end;
2519
2520     memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
2521     memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
2522
2523     end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
2524     if (*end == ':')
2525         end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
2526
2527     if (*end == '\0') {
2528         ipxcp_wantoptions[0].neg_node = 1;
2529         return 1;
2530     }
2531
2532     option_error("invalid parameter '%s' for ipx-node option", *argv);
2533     return 0;
2534 }
2535
2536 static int
2537 setipxproto(argv)
2538     char **argv;
2539 {
2540     ipxcp_protent.enabled_flag = 1;
2541     return 1;
2542 }
2543
2544 static int
2545 resetipxproto(argv)
2546     char **argv;
2547 {
2548     ipxcp_protent.enabled_flag = 0;
2549     return 1;
2550 }
2551 #else
2552
2553 static int
2554 resetipxproto(argv)
2555     char **argv;
2556 {
2557     return 1;
2558 }
2559 #endif /* IPX_CHANGE */
2560
2561 #ifdef MSLANMAN
2562 static int
2563 setmslanman(argv)
2564     char **argv;
2565 {
2566     ms_lanman = 1;
2567     return (1);
2568 }
2569 #endif