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