source: rtems/cpukit/pppd/options.c @ 4bf1801

4.104.114.84.95
Last change on this file since 4bf1801 was d0950ad, checked in by Joel Sherrill <joel.sherrill@…>, on 11/30/99 at 22:12:50

Added port of ppp-2.3.5 from Tomasz Domin <dot@…> of ComArch? SA.
Tomasz only tested this on the mpc823.

The official site for the original source for this PPP implementation is:

ftp://cs.anu.edu.au/pub/software/ppp

NOTE: As of 11/30/1999, the current version of this source is 2.3.10.

  • Property mode set to 100644
File size: 11.7 KB
Line 
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$"; */
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
67#ifndef GIDSET_TYPE
68#define GIDSET_TYPE     gid_t
69#endif
70#if 0
71static int privileged_option;   /* set iff the current option came from root */
72static char *option_source;     /* string saying where the option came from */
73#endif
74
75/*
76 * Option variables and default values.
77 */
78#ifdef PPP_FILTER
79int     dflag = 0;              /* Tell libpcap we want debugging */
80#endif
81int     debug = 1;              /* Debug flag */
82int     kdebugflag = 1;         /* Tell kernel to print debug messages */
83int     default_device = 1;     /* Using /dev/tty or equivalent */
84char    devnam[MAXPATHLEN] = "/dev/sccppp";     /* Device name */
85int     crtscts = 0;            /* Use hardware flow control */
86int     modem = 0;              /* Use modem control lines */
87int     inspeed = B115200;              /* Input/Output speed requested */
88u_int32_t netmask = 0;          /* IP netmask to set on interface */
89int     lockflag = 0;           /* Create lock file to lock the serial dev */
90int     nodetach = 0;           /* Don't detach from controlling tty */
91char *connector[]={"TIMEOUT","3","ABORT","\nBUSY\r","ABORT","\nNO DIALTONE\r","ABORT","\nNO CARRIER\r","ABORT","\nNO ANSWER\r","ABORT","\nRINGING\r\n\r\nRINGING\r",
92                                                                                                "","\rAT","OK-+++\\c-OK","ATH0","TIMEOUT","30","OK","ATDT13","CONNECT",""};
93/*char *connector[]={"TIMEOUT","3","ABORT","\nBUSY\r","ABORT","\nNO DIALTONE\r","ABORT","\nNO CARRIER\r","ABORT","\nNO ANSWER\r","ABORT","\nRINGING\r\n\r\nRINGING\r",
94                                                                                                "","\rAT","OK-+++\\c-OK","ATH0","TIMEOUT","30","OK","ATDT0202122","CONNECT","","ppp","","Username:","ppp","Password:","ppp"};
95*/
96char    *disconnector [];       /* Script to disestablish physical link */
97char    *welcomer [];   /* Script to run after phys link estab. */
98int     maxconnect = 0;         /* Maximum connect time */
99char    user[MAXNAMELEN]="stb"; /* Username for PAP */
100char    passwd[MAXSECRETLEN]="stb";     /* Password for PAP */
101int     auth_required = 0;      /* Peer is required to authenticate */
102int     defaultroute = 1;       /* assign default route through interface */
103int     proxyarp = 0;           /* Set up proxy ARP entry for peer */
104int     persist = 1;            /* Reopen link after it goes down */
105int     uselogin = 0;           /* Use /etc/passwd for checking PAP */
106int     lcp_echo_interval = 0;  /* Interval between LCP echo-requests */
107int     lcp_echo_fails = 0;     /* Tolerance to unanswered echo-requests */
108char    our_name[MAXNAMELEN]="infotel"; /* Our name for authentication purposes */
109char    remote_name[MAXNAMELEN]; /* Peer's name for authentication */
110int     explicit_remote = 0;    /* User specified explicit remote name */
111int     usehostname = 0;        /* Use hostname for our_name */
112int     disable_defaultip = 1;  /* Don't use hostname for default IP adrs */
113int     demand = 0;             /* do dial-on-demand */
114char    *ipparam = NULL;        /* Extra parameter for ip up/down scripts */
115int     cryptpap;               /* Passwords in pap-secrets are encrypted */
116int     idle_time_limit = 0;    /* Disconnect if idle for this many seconds */
117int     holdoff = 30;           /* # seconds to pause before reconnecting */
118int     refuse_pap = 0;         /* Set to say we won't do PAP */
119int     refuse_chap = 1;        /* Set to say we won't do CHAP */
120
121#ifdef MSLANMAN
122int     ms_lanman = 0;          /* Nonzero if use LanMan password instead of NT */
123                                /* Has meaning only with MS-CHAP challenges */
124#endif
125
126struct option_info auth_req_info;
127struct option_info connector_info;
128struct option_info disconnector_info;
129struct option_info welcomer_info;
130struct option_info devnam_info;
131#ifdef PPP_FILTER
132struct  bpf_program pass_filter;/* Filter program for packets to pass */
133struct  bpf_program active_filter; /* Filter program for link-active pkts */
134pcap_t  pc;                     /* Fake struct pcap so we can compile expr */
135#endif
136
137/*
138 * Prototypes
139 */
140#if 0
141static int setdevname __P((char *, int));
142static int setipaddr __P((char *));
143static int setspeed __P((char *));
144static int setdebug __P((char **));
145static int setkdebug __P((char **));
146static int setpassive __P((char **));
147static int setsilent __P((char **));
148static int noopt __P((char **));
149static int setnovj __P((char **));
150static int setnovjccomp __P((char **));
151static int setvjslots __P((char **));
152static int reqpap __P((char **));
153static int nopap __P((char **));
154#ifdef OLD_OPTIONS
155static int setupapfile __P((char **));
156#endif
157static int nochap __P((char **));
158static int reqchap __P((char **));
159static int noaccomp __P((char **));
160static int noasyncmap __P((char **));
161static int noip __P((char **));
162static int nomagicnumber __P((char **));
163static int setasyncmap __P((char **));
164static int setescape __P((char **));
165static int setmru __P((char **));
166static int setmtu __P((char **));
167#ifdef CBCP_SUPPORT
168static int setcbcp __P((char **));
169#endif
170static int nomru __P((char **));
171static int nopcomp __P((char **));
172static int setconnector __P((char **));
173static int setdisconnector __P((char **));
174static int setwelcomer __P((char **));
175static int setmaxconnect __P((char **));
176static int setdomain __P((char **));
177static int setnetmask __P((char **));
178static int setcrtscts __P((char **));
179static int setnocrtscts __P((char **));
180static int setxonxoff __P((char **));
181static int setnodetach __P((char **));
182static int setupdetach __P((char **));
183static int setmodem __P((char **));
184static int setlocal __P((char **));
185static int setlock __P((char **));
186static int setname __P((char **));
187static int setuser __P((char **));
188static int setremote __P((char **));
189static int setauth __P((char **));
190static int setnoauth __P((char **));
191static int readfile __P((char **));
192static int callfile __P((char **));
193static int setdefaultroute __P((char **));
194static int setnodefaultroute __P((char **));
195static int setproxyarp __P((char **));
196static int setnoproxyarp __P((char **));
197static int setpersist __P((char **));
198static int setnopersist __P((char **));
199static int setdologin __P((char **));
200static int setusehostname __P((char **));
201static int setnoipdflt __P((char **));
202static int setlcptimeout __P((char **));
203static int setlcpterm __P((char **));
204static int setlcpconf __P((char **));
205static int setlcpfails __P((char **));
206static int setipcptimeout __P((char **));
207static int setipcpterm __P((char **));
208static int setipcpconf __P((char **));
209static int setipcpfails __P((char **));
210static int setpaptimeout __P((char **));
211static int setpapreqs __P((char **));
212static int setpapreqtime __P((char **));
213static int setchaptimeout __P((char **));
214static int setchapchal __P((char **));
215static int setchapintv __P((char **));
216static int setipcpaccl __P((char **));
217static int setipcpaccr __P((char **));
218static int setlcpechointv __P((char **));
219static int setlcpechofails __P((char **));
220static int noccp __P((char **));
221static int setbsdcomp __P((char **));
222static int setnobsdcomp __P((char **));
223static int setdeflate __P((char **));
224static int setnodeflate __P((char **));
225static int setnodeflatedraft __P((char **));
226static int setdemand __P((char **));
227static int setpred1comp __P((char **));
228static int setnopred1comp __P((char **));
229static int setipparam __P((char **));
230static int setpapcrypt __P((char **));
231static int setidle __P((char **));
232static int setholdoff __P((char **));
233static int setdnsaddr __P((char **));
234static int resetipxproto __P((char **));
235static int setwinsaddr __P((char **));
236static int showversion __P((char **));
237static int showhelp __P((char **));
238
239#ifdef PPP_FILTER
240static int setpdebug __P((char **));
241static int setpassfilter __P((char **));
242static int setactivefilter __P((char **));
243#endif
244
245#ifdef IPX_CHANGE
246static int setipxproto __P((char **));
247static int setipxanet __P((char **));
248static int setipxalcl __P((char **));
249static int setipxarmt __P((char **));
250static int setipxnetwork __P((char **));
251static int setipxnode __P((char **));
252static int setipxrouter __P((char **));
253static int setipxname __P((char **));
254static int setipxcptimeout __P((char **));
255static int setipxcpterm __P((char **));
256static int setipxcpconf __P((char **));
257static int setipxcpfails __P((char **));
258#endif /* IPX_CHANGE */
259
260#ifdef MSLANMAN
261static int setmslanman __P((char **));
262#endif
263
264static int number_option __P((char *, u_int32_t *, int));
265static int int_option __P((char *, int *));
266static int readable __P((int fd));
267#endif
268
269/*
270 * Valid arguments.
271 */
272 
273/*
274 * parse_args - parse a string of arguments from the command line.
275 */
276int
277parse_args(argc, argv)
278    int argc;
279    char **argv;
280{
281
282
283return 0;
284}
285
286/*
287 * scan_args - scan the command line arguments to get the tty name,
288 * if specified.
289 */
290
291/*
292 * usage - print out a message telling how to use the program.
293 */
294void
295usage()
296{
297 }
298
299/*
300 * showhelp - print out usage message and exit.
301 */
302static int
303showhelp(argv)
304    char **argv;
305{
306    return 0;
307}
308
309/*
310 * showversion - print out the version number and exit.
311 */
312static int
313showversion(argv)
314    char **argv;
315{
316    return 0;
317}
318
319void
320option_error __V((char *fmt, ...))
321{
322}
323/*
324 * readable - check if a file is readable by the real user.
325 */
326/*static int
327readable(fd)
328    int fd;
329{
330    uid_t uid;
331    int ngroups, i;
332    struct stat sbuf;
333    GIDSET_TYPE groups[NGROUPS_MAX];
334
335    uid = getuid();
336    if (uid == 0)
337        return 1;
338    if (fstat(fd, &sbuf) != 0)
339        return 0;
340    if (sbuf.st_uid == uid)
341        return sbuf.st_mode & S_IRUSR;
342    if (sbuf.st_gid == getgid())
343        return sbuf.st_mode & S_IRGRP;
344    ngroups = getgroups(NGROUPS_MAX, groups);
345    for (i = 0; i < ngroups; ++i)
346        if (sbuf.st_gid == groups[i])
347            return sbuf.st_mode & S_IRGRP;
348    return sbuf.st_mode & S_IROTH;
349}
350*/
351/*
352 * Read a word from a file.
353 * Words are delimited by white-space or by quotes (" or ').
354 * Quotes, white-space and \ may be escaped with \.
355 * \<newline> is ignored.
356 */
357
358 /*
359 * The following procedures parse options.
360 */
361
362/*
363 * readfile - take commands from a file.
364 */
365 
366/*
367 * callfile - take commands from /etc/ppp/peers/<name>.
368 * Name may not contain /../, start with / or ../, or end in /..
369 */
370 /*
371 * setdebug - Set debug (command line argument).
372 */
373 
374
375/*
376 * noopt - Disable all options.
377 */
378static int
379noopt(argv)
380    char **argv;
381{
382    BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
383    BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
384    BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
385    BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
386
387#ifdef IPX_CHANGE
388    BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
389    BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
390#endif /* IPX_CHANGE */
391
392    return (1);
393}
Note: See TracBrowser for help on using the repository browser.