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