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