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