Merge from vendor branch TNF:
[pkgsrcv2.git] / net / ppp-mppe / patches / patch-bb
1 $NetBSD$
2
3 --- pppd/auth.c.orig2   Sat Sep 25 12:36:32 1999
4 +++ pppd/auth.c Sat Sep 25 12:48:02 1999
5 @@ -74,8 +74,16 @@
6  #ifdef CBCP_SUPPORT
7  #include "cbcp.h"
8  #endif
9 +#ifdef CHAPMS
10 +#include "chap_ms.h"
11 +#endif
12  #include "pathnames.h"
13  
14 +#ifdef DYNAMIC
15 +#define _PATH_DYNAMIC "/etc/ppp/getaddr"
16 +#endif
17 +static char xuser[MAXNAMELEN];
18 +
19  static const char rcsid[] = RCSID;
20  
21  /* Bits in scan_authfile return value */
22 @@ -108,6 +116,11 @@
23  /* Set if we got the contents of passwd[] from the pap-secrets file. */
24  static int passwd_from_file;
25  
26 +#ifdef CBCP_SUPPORT
27 +/* Set if we have done call-back sequences. */
28 +static int did_callback;
29 +#endif
30 +
31  /*
32   * This is used to ensure that we don't start an auth-up/down
33   * script while one is already running.
34 @@ -144,7 +157,7 @@
35  
36  /* Prototypes for procedures local to this file. */
37  
38 -static void network_phase __P((int));
39 +void network_phase __P((int));
40  static void check_idle __P((void *));
41  static void connect_time_expired __P((void *));
42  static int  plogin __P((char *, char *, char **, int *));
43 @@ -177,14 +190,36 @@
44        "Don't agree to auth to peer with PAP", 1 },
45      { "-pap", o_bool, &refuse_pap,
46        "Don't allow PAP authentication with peer", 1 },
47 -    { "require-chap", o_bool, &lcp_wantoptions[0].neg_chap,
48 -      "Require CHAP authentication from peer", 1, &auth_required },
49 -    { "+chap", o_bool, &lcp_wantoptions[0].neg_chap,
50 -      "Require CHAP authentication from peer", 1, &auth_required },
51 +    { "require-chap", o_special_noarg, reqchap,
52 +      "Require CHAP authentication from peer" },
53 +    { "+chap", o_special_noarg, reqchap,
54 +      "Require CHAP authentication from peer" },
55      { "refuse-chap", o_bool, &refuse_chap,
56        "Don't agree to auth to peer with CHAP", 1 },
57      { "-chap", o_bool, &refuse_chap,
58        "Don't allow CHAP authentication with peer", 1 },
59 +    { "refuse-chap-md5", o_bool, &lcp_wantoptions[0].use_digest,
60 +      "Don't allow md5-digest style CHAP", 0 },
61 +    { "-chap-md5", o_bool, &lcp_wantoptions[0].use_digest,
62 +      "Don't allow md5-digest style CHAP", 0 },
63 +#ifdef CHAPMS
64 +    { "require-chapms", o_special_noarg, reqchapms,
65 +      "Require MSCHAP (v1) authentication" },
66 +    { "+chapms", o_special_noarg, reqchapms,
67 +      "Require MSCHAP (v1) authentication" },
68 +    { "refuse-chapms", o_special_noarg, nochapms,
69 +      "Refuse MSCHAP (v1) authentication" },
70 +    { "-chapms", o_special_noarg, nochapms,
71 +      "Refuse MSCHAP (v1) authentication" },
72 +    { "require-chapms-v2", o_special_noarg, reqchapms_v2,
73 +      "Require MSCHAP-v2 authentication" },
74 +    { "+chapms-v2", o_special_noarg, reqchapms_v2,
75 +      "Require MSCHAP-v2 authentication" },
76 +    { "refuse-chapms-v2", o_special_noarg, nochapms_v2,
77 +      "Refuse MSCHAP-v2 authentication" },
78 +    { "-chapms-v2", o_special_noarg, nochapms_v2,
79 +      "Refuse MSCHAP-v2 authentication" },
80 +#endif
81      { "name", o_string, our_name,
82        "Set local name for authentication",
83        OPT_PRIV|OPT_STATIC, NULL, MAXNAMELEN },
84 @@ -402,11 +437,14 @@
85  /*
86   * Proceed to the network phase.
87   */
88 -static void
89 +void
90  network_phase(unit)
91      int unit;
92  {
93      lcp_options *go = &lcp_gotoptions[unit];
94 +#ifdef CBCP_SUPPORT
95 +    lcp_options *ho = &lcp_hisoptions[unit];
96 +#endif
97  
98      /*
99       * If the peer had to authenticate, run the auth-up script now.
100 @@ -423,8 +461,9 @@
101      /*
102       * If we negotiated callback, do it now.
103       */
104 -    if (go->neg_cbcp) {
105 +    if ((go->neg_cbcp || ho->neg_cbcp) && !did_callback) {
106         phase = PHASE_CALLBACK;
107 +       did_callback = 1;
108         (*cbcp_protent.open)(unit);
109         return;
110      }
111 @@ -510,6 +549,8 @@
112         namelen = sizeof(peer_authname) - 1;
113      BCOPY(name, peer_authname, namelen);
114      peer_authname[namelen] = 0;
115 +    BCOPY(name, xuser, namelen);
116 +    xuser[namelen] = 0;
117      script_setenv("PEERNAME", peer_authname);
118  
119      /*
120 @@ -1291,6 +1332,61 @@
121  
122      return 1;
123  }
124 +
125 +#ifdef DYNAMIC
126 +/*
127 + * get_ip_addr_dynamic - scans dynamic-givable address space for
128 + * most recently used address for given user.
129 + */
130 +int
131 +get_ip_addr_dynamic(unit, addr)
132 +    int unit;
133 +    u_int32_t *addr;
134 +{
135 +    u_int32_t a;
136 +    struct wordlist *addrs;
137 +    FILE *fd;
138 +    int dfd;
139 +    char command[256];
140 +    char mypid[40], *s;
141 +    char address[50];
142 +    u_int32_t mask;
143 +    
144 +    if ((addrs = addresses[unit]) == NULL)
145 +       return 0;               /* no restriction */
146 +
147 +    fd = (FILE *)NULL;
148 +    for(; addrs != NULL; addrs = addrs->next) {
149 +       if(strcmp(addrs->word, "*") != 0)
150 +           continue;
151 +       sprintf(mypid, "/var/tmp/ppp_dynamic.%d", getpid());
152 +       sprintf(command, "%s %s %s %s", _PATH_DYNAMIC, xuser, devnam, mypid);
153 +       dfd = open("/dev/null", O_RDWR);
154 +       device_script(command, dfd, dfd);
155 +       close(dfd);
156 +       fd = fopen(mypid, "r");
157 +       if(fd == (FILE *)NULL)
158 +         break;
159 +       if(fgets(address, sizeof(address), fd) == (char *)NULL)
160 +         break;
161 +       if((s = strchr(address, '\n')) != (char *)NULL)
162 +         *s = '\0';
163 +       a = inet_addr(address);
164 +       if(a == -1L)
165 +         break;
166 +       fclose(fd);
167 +       unlink(mypid);
168 +       *addr = a;
169 +       return 1;
170 +    }
171 +    if(fd != (FILE *)NULL)
172 +    {
173 +      fclose(fd);
174 +      unlink(mypid);
175 +    }
176 +    return 0;
177 +}
178 +#endif
179  
180  /*
181   * set_allowed_addrs() - set the list of allowed addresses.