I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tax 0:66300c77c6e9 1 /*****************************************************************************
tax 0:66300c77c6e9 2 * auth.c - Network Authentication and Phase Control program file.
tax 0:66300c77c6e9 3 *
tax 0:66300c77c6e9 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
tax 0:66300c77c6e9 5 * Copyright (c) 1997 by Global Election Systems Inc. All rights reserved.
tax 0:66300c77c6e9 6 *
tax 0:66300c77c6e9 7 * The authors hereby grant permission to use, copy, modify, distribute,
tax 0:66300c77c6e9 8 * and license this software and its documentation for any purpose, provided
tax 0:66300c77c6e9 9 * that existing copyright notices are retained in all copies and that this
tax 0:66300c77c6e9 10 * notice and the following disclaimer are included verbatim in any
tax 0:66300c77c6e9 11 * distributions. No written agreement, license, or royalty fee is required
tax 0:66300c77c6e9 12 * for any of the authorized uses.
tax 0:66300c77c6e9 13 *
tax 0:66300c77c6e9 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
tax 0:66300c77c6e9 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
tax 0:66300c77c6e9 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
tax 0:66300c77c6e9 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
tax 0:66300c77c6e9 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
tax 0:66300c77c6e9 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
tax 0:66300c77c6e9 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
tax 0:66300c77c6e9 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
tax 0:66300c77c6e9 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
tax 0:66300c77c6e9 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tax 0:66300c77c6e9 24 *
tax 0:66300c77c6e9 25 ******************************************************************************
tax 0:66300c77c6e9 26 * REVISION HISTORY
tax 0:66300c77c6e9 27 *
tax 0:66300c77c6e9 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
tax 0:66300c77c6e9 29 * Ported to lwIP.
tax 0:66300c77c6e9 30 * 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
tax 0:66300c77c6e9 31 * Ported from public pppd code.
tax 0:66300c77c6e9 32 *****************************************************************************/
tax 0:66300c77c6e9 33 /*
tax 0:66300c77c6e9 34 * auth.c - PPP authentication and phase control.
tax 0:66300c77c6e9 35 *
tax 0:66300c77c6e9 36 * Copyright (c) 1993 The Australian National University.
tax 0:66300c77c6e9 37 * All rights reserved.
tax 0:66300c77c6e9 38 *
tax 0:66300c77c6e9 39 * Redistribution and use in source and binary forms are permitted
tax 0:66300c77c6e9 40 * provided that the above copyright notice and this paragraph are
tax 0:66300c77c6e9 41 * duplicated in all such forms and that any documentation,
tax 0:66300c77c6e9 42 * advertising materials, and other materials related to such
tax 0:66300c77c6e9 43 * distribution and use acknowledge that the software was developed
tax 0:66300c77c6e9 44 * by the Australian National University. The name of the University
tax 0:66300c77c6e9 45 * may not be used to endorse or promote products derived from this
tax 0:66300c77c6e9 46 * software without specific prior written permission.
tax 0:66300c77c6e9 47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
tax 0:66300c77c6e9 48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
tax 0:66300c77c6e9 49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
tax 0:66300c77c6e9 50 *
tax 0:66300c77c6e9 51 * Copyright (c) 1989 Carnegie Mellon University.
tax 0:66300c77c6e9 52 * All rights reserved.
tax 0:66300c77c6e9 53 *
tax 0:66300c77c6e9 54 * Redistribution and use in source and binary forms are permitted
tax 0:66300c77c6e9 55 * provided that the above copyright notice and this paragraph are
tax 0:66300c77c6e9 56 * duplicated in all such forms and that any documentation,
tax 0:66300c77c6e9 57 * advertising materials, and other materials related to such
tax 0:66300c77c6e9 58 * distribution and use acknowledge that the software was developed
tax 0:66300c77c6e9 59 * by Carnegie Mellon University. The name of the
tax 0:66300c77c6e9 60 * University may not be used to endorse or promote products derived
tax 0:66300c77c6e9 61 * from this software without specific prior written permission.
tax 0:66300c77c6e9 62 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
tax 0:66300c77c6e9 63 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
tax 0:66300c77c6e9 64 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
tax 0:66300c77c6e9 65 */
tax 0:66300c77c6e9 66
tax 0:66300c77c6e9 67 #include "lwip/opt.h"
tax 0:66300c77c6e9 68
tax 0:66300c77c6e9 69 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
tax 0:66300c77c6e9 70
tax 0:66300c77c6e9 71 #include "ppp.h"
tax 0:66300c77c6e9 72 #include "pppdebug.h"
tax 0:66300c77c6e9 73
tax 0:66300c77c6e9 74 #include "fsm.h"
tax 0:66300c77c6e9 75 #include "lcp.h"
tax 0:66300c77c6e9 76 #include "pap.h"
tax 0:66300c77c6e9 77 #include "chap.h"
tax 0:66300c77c6e9 78 #include "auth.h"
tax 0:66300c77c6e9 79 #include "ipcp.h"
tax 0:66300c77c6e9 80
tax 0:66300c77c6e9 81 #if CBCP_SUPPORT
tax 0:66300c77c6e9 82 #include "cbcp.h"
tax 0:66300c77c6e9 83 #endif /* CBCP_SUPPORT */
tax 0:66300c77c6e9 84
tax 0:66300c77c6e9 85 #include "lwip/inet.h"
tax 0:66300c77c6e9 86
tax 0:66300c77c6e9 87 #include <string.h>
tax 0:66300c77c6e9 88
tax 0:66300c77c6e9 89 #if 0 /* UNUSED */
tax 0:66300c77c6e9 90 /* Bits in scan_authfile return value */
tax 0:66300c77c6e9 91 #define NONWILD_SERVER 1
tax 0:66300c77c6e9 92 #define NONWILD_CLIENT 2
tax 0:66300c77c6e9 93
tax 0:66300c77c6e9 94 #define ISWILD(word) (word[0] == '*' && word[1] == 0)
tax 0:66300c77c6e9 95 #endif /* UNUSED */
tax 0:66300c77c6e9 96
tax 0:66300c77c6e9 97 #if PAP_SUPPORT || CHAP_SUPPORT
tax 0:66300c77c6e9 98 /* The name by which the peer authenticated itself to us. */
tax 0:66300c77c6e9 99 static char peer_authname[MAXNAMELEN];
tax 0:66300c77c6e9 100 #endif /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 101
tax 0:66300c77c6e9 102 /* Records which authentication operations haven't completed yet. */
tax 0:66300c77c6e9 103 static int auth_pending[NUM_PPP];
tax 0:66300c77c6e9 104
tax 0:66300c77c6e9 105 /* Set if we have successfully called plogin() */
tax 0:66300c77c6e9 106 static int logged_in;
tax 0:66300c77c6e9 107
tax 0:66300c77c6e9 108 /* Set if we have run the /etc/ppp/auth-up script. */
tax 0:66300c77c6e9 109 static int did_authup; /* @todo, we don't need this in lwip*/
tax 0:66300c77c6e9 110
tax 0:66300c77c6e9 111 /* List of addresses which the peer may use. */
tax 0:66300c77c6e9 112 static struct wordlist *addresses[NUM_PPP];
tax 0:66300c77c6e9 113
tax 0:66300c77c6e9 114 #if 0 /* UNUSED */
tax 0:66300c77c6e9 115 /* Wordlist giving addresses which the peer may use
tax 0:66300c77c6e9 116 without authenticating itself. */
tax 0:66300c77c6e9 117 static struct wordlist *noauth_addrs;
tax 0:66300c77c6e9 118
tax 0:66300c77c6e9 119 /* Extra options to apply, from the secrets file entry for the peer. */
tax 0:66300c77c6e9 120 static struct wordlist *extra_options;
tax 0:66300c77c6e9 121 #endif /* UNUSED */
tax 0:66300c77c6e9 122
tax 0:66300c77c6e9 123 /* Number of network protocols which we have opened. */
tax 0:66300c77c6e9 124 static int num_np_open;
tax 0:66300c77c6e9 125
tax 0:66300c77c6e9 126 /* Number of network protocols which have come up. */
tax 0:66300c77c6e9 127 static int num_np_up;
tax 0:66300c77c6e9 128
tax 0:66300c77c6e9 129 #if PAP_SUPPORT || CHAP_SUPPORT
tax 0:66300c77c6e9 130 /* Set if we got the contents of passwd[] from the pap-secrets file. */
tax 0:66300c77c6e9 131 static int passwd_from_file;
tax 0:66300c77c6e9 132 #endif /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 133
tax 0:66300c77c6e9 134 #if 0 /* UNUSED */
tax 0:66300c77c6e9 135 /* Set if we require authentication only because we have a default route. */
tax 0:66300c77c6e9 136 static bool default_auth;
tax 0:66300c77c6e9 137
tax 0:66300c77c6e9 138 /* Hook to enable a plugin to control the idle time limit */
tax 0:66300c77c6e9 139 int (*idle_time_hook) __P((struct ppp_idle *)) = NULL;
tax 0:66300c77c6e9 140
tax 0:66300c77c6e9 141 /* Hook for a plugin to say whether we can possibly authenticate any peer */
tax 0:66300c77c6e9 142 int (*pap_check_hook) __P((void)) = NULL;
tax 0:66300c77c6e9 143
tax 0:66300c77c6e9 144 /* Hook for a plugin to check the PAP user and password */
tax 0:66300c77c6e9 145 int (*pap_auth_hook) __P((char *user, char *passwd, char **msgp,
tax 0:66300c77c6e9 146 struct wordlist **paddrs,
tax 0:66300c77c6e9 147 struct wordlist **popts)) = NULL;
tax 0:66300c77c6e9 148
tax 0:66300c77c6e9 149 /* Hook for a plugin to know about the PAP user logout */
tax 0:66300c77c6e9 150 void (*pap_logout_hook) __P((void)) = NULL;
tax 0:66300c77c6e9 151
tax 0:66300c77c6e9 152 /* Hook for a plugin to get the PAP password for authenticating us */
tax 0:66300c77c6e9 153 int (*pap_passwd_hook) __P((char *user, char *passwd)) = NULL;
tax 0:66300c77c6e9 154
tax 0:66300c77c6e9 155 /*
tax 0:66300c77c6e9 156 * This is used to ensure that we don't start an auth-up/down
tax 0:66300c77c6e9 157 * script while one is already running.
tax 0:66300c77c6e9 158 */
tax 0:66300c77c6e9 159 enum script_state {
tax 0:66300c77c6e9 160 s_down,
tax 0:66300c77c6e9 161 s_up
tax 0:66300c77c6e9 162 };
tax 0:66300c77c6e9 163
tax 0:66300c77c6e9 164 static enum script_state auth_state = s_down;
tax 0:66300c77c6e9 165 static enum script_state auth_script_state = s_down;
tax 0:66300c77c6e9 166 static pid_t auth_script_pid = 0;
tax 0:66300c77c6e9 167
tax 0:66300c77c6e9 168 /*
tax 0:66300c77c6e9 169 * Option variables.
tax 0:66300c77c6e9 170 * lwip: some of these are present in the ppp_settings structure
tax 0:66300c77c6e9 171 */
tax 0:66300c77c6e9 172 bool uselogin = 0; /* Use /etc/passwd for checking PAP */
tax 0:66300c77c6e9 173 bool cryptpap = 0; /* Passwords in pap-secrets are encrypted */
tax 0:66300c77c6e9 174 bool refuse_pap = 0; /* Don't wanna auth. ourselves with PAP */
tax 0:66300c77c6e9 175 bool refuse_chap = 0; /* Don't wanna auth. ourselves with CHAP */
tax 0:66300c77c6e9 176 bool usehostname = 0; /* Use hostname for our_name */
tax 0:66300c77c6e9 177 bool auth_required = 0; /* Always require authentication from peer */
tax 0:66300c77c6e9 178 bool allow_any_ip = 0; /* Allow peer to use any IP address */
tax 0:66300c77c6e9 179 bool explicit_remote = 0; /* User specified explicit remote name */
tax 0:66300c77c6e9 180 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
tax 0:66300c77c6e9 181
tax 0:66300c77c6e9 182 #endif /* UNUSED */
tax 0:66300c77c6e9 183
tax 0:66300c77c6e9 184 /* Bits in auth_pending[] */
tax 0:66300c77c6e9 185 #define PAP_WITHPEER 1
tax 0:66300c77c6e9 186 #define PAP_PEER 2
tax 0:66300c77c6e9 187 #define CHAP_WITHPEER 4
tax 0:66300c77c6e9 188 #define CHAP_PEER 8
tax 0:66300c77c6e9 189
tax 0:66300c77c6e9 190 /* @todo, move this somewhere */
tax 0:66300c77c6e9 191 /* Used for storing a sequence of words. Usually malloced. */
tax 0:66300c77c6e9 192 struct wordlist {
tax 0:66300c77c6e9 193 struct wordlist *next;
tax 0:66300c77c6e9 194 char word[1];
tax 0:66300c77c6e9 195 };
tax 0:66300c77c6e9 196
tax 0:66300c77c6e9 197
tax 0:66300c77c6e9 198 extern char *crypt (const char *, const char *);
tax 0:66300c77c6e9 199
tax 0:66300c77c6e9 200 /* Prototypes for procedures local to this file. */
tax 0:66300c77c6e9 201
tax 0:66300c77c6e9 202 static void network_phase (int);
tax 0:66300c77c6e9 203 static void check_idle (void *);
tax 0:66300c77c6e9 204 static void connect_time_expired (void *);
tax 0:66300c77c6e9 205 #if 0
tax 0:66300c77c6e9 206 static int plogin (char *, char *, char **, int *);
tax 0:66300c77c6e9 207 #endif
tax 0:66300c77c6e9 208 static void plogout (void);
tax 0:66300c77c6e9 209 static int null_login (int);
tax 0:66300c77c6e9 210 static int get_pap_passwd (int, char *, char *);
tax 0:66300c77c6e9 211 static int have_pap_secret (void);
tax 0:66300c77c6e9 212 static int have_chap_secret (char *, char *, u32_t);
tax 0:66300c77c6e9 213 static int ip_addr_check (u32_t, struct wordlist *);
tax 0:66300c77c6e9 214
tax 0:66300c77c6e9 215 #if 0 /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 216 static int scan_authfile (FILE *, char *, char *, char *,
tax 0:66300c77c6e9 217 struct wordlist **, struct wordlist **,
tax 0:66300c77c6e9 218 char *);
tax 0:66300c77c6e9 219 static void free_wordlist (struct wordlist *);
tax 0:66300c77c6e9 220 static void auth_script (char *);
tax 0:66300c77c6e9 221 static void auth_script_done (void *);
tax 0:66300c77c6e9 222 static void set_allowed_addrs (int unit, struct wordlist *addrs);
tax 0:66300c77c6e9 223 static int some_ip_ok (struct wordlist *);
tax 0:66300c77c6e9 224 static int setupapfile (char **);
tax 0:66300c77c6e9 225 static int privgroup (char **);
tax 0:66300c77c6e9 226 static int set_noauth_addr (char **);
tax 0:66300c77c6e9 227 static void check_access (FILE *, char *);
tax 0:66300c77c6e9 228 #endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 229
tax 0:66300c77c6e9 230 #if 0 /* UNUSED */
tax 0:66300c77c6e9 231 /*
tax 0:66300c77c6e9 232 * Authentication-related options.
tax 0:66300c77c6e9 233 */
tax 0:66300c77c6e9 234 option_t auth_options[] = {
tax 0:66300c77c6e9 235 { "require-pap", o_bool, &lcp_wantoptions[0].neg_upap,
tax 0:66300c77c6e9 236 "Require PAP authentication from peer", 1, &auth_required },
tax 0:66300c77c6e9 237 { "+pap", o_bool, &lcp_wantoptions[0].neg_upap,
tax 0:66300c77c6e9 238 "Require PAP authentication from peer", 1, &auth_required },
tax 0:66300c77c6e9 239 { "refuse-pap", o_bool, &refuse_pap,
tax 0:66300c77c6e9 240 "Don't agree to auth to peer with PAP", 1 },
tax 0:66300c77c6e9 241 { "-pap", o_bool, &refuse_pap,
tax 0:66300c77c6e9 242 "Don't allow PAP authentication with peer", 1 },
tax 0:66300c77c6e9 243 { "require-chap", o_bool, &lcp_wantoptions[0].neg_chap,
tax 0:66300c77c6e9 244 "Require CHAP authentication from peer", 1, &auth_required },
tax 0:66300c77c6e9 245 { "+chap", o_bool, &lcp_wantoptions[0].neg_chap,
tax 0:66300c77c6e9 246 "Require CHAP authentication from peer", 1, &auth_required },
tax 0:66300c77c6e9 247 { "refuse-chap", o_bool, &refuse_chap,
tax 0:66300c77c6e9 248 "Don't agree to auth to peer with CHAP", 1 },
tax 0:66300c77c6e9 249 { "-chap", o_bool, &refuse_chap,
tax 0:66300c77c6e9 250 "Don't allow CHAP authentication with peer", 1 },
tax 0:66300c77c6e9 251 { "name", o_string, our_name,
tax 0:66300c77c6e9 252 "Set local name for authentication",
tax 0:66300c77c6e9 253 OPT_PRIV|OPT_STATIC, NULL, MAXNAMELEN },
tax 0:66300c77c6e9 254 { "user", o_string, user,
tax 0:66300c77c6e9 255 "Set name for auth with peer", OPT_STATIC, NULL, MAXNAMELEN },
tax 0:66300c77c6e9 256 { "usehostname", o_bool, &usehostname,
tax 0:66300c77c6e9 257 "Must use hostname for authentication", 1 },
tax 0:66300c77c6e9 258 { "remotename", o_string, remote_name,
tax 0:66300c77c6e9 259 "Set remote name for authentication", OPT_STATIC,
tax 0:66300c77c6e9 260 &explicit_remote, MAXNAMELEN },
tax 0:66300c77c6e9 261 { "auth", o_bool, &auth_required,
tax 0:66300c77c6e9 262 "Require authentication from peer", 1 },
tax 0:66300c77c6e9 263 { "noauth", o_bool, &auth_required,
tax 0:66300c77c6e9 264 "Don't require peer to authenticate", OPT_PRIV, &allow_any_ip },
tax 0:66300c77c6e9 265 { "login", o_bool, &uselogin,
tax 0:66300c77c6e9 266 "Use system password database for PAP", 1 },
tax 0:66300c77c6e9 267 { "papcrypt", o_bool, &cryptpap,
tax 0:66300c77c6e9 268 "PAP passwords are encrypted", 1 },
tax 0:66300c77c6e9 269 { "+ua", o_special, (void *)setupapfile,
tax 0:66300c77c6e9 270 "Get PAP user and password from file" },
tax 0:66300c77c6e9 271 { "password", o_string, passwd,
tax 0:66300c77c6e9 272 "Password for authenticating us to the peer", OPT_STATIC,
tax 0:66300c77c6e9 273 NULL, MAXSECRETLEN },
tax 0:66300c77c6e9 274 { "privgroup", o_special, (void *)privgroup,
tax 0:66300c77c6e9 275 "Allow group members to use privileged options", OPT_PRIV },
tax 0:66300c77c6e9 276 { "allow-ip", o_special, (void *)set_noauth_addr,
tax 0:66300c77c6e9 277 "Set IP address(es) which can be used without authentication",
tax 0:66300c77c6e9 278 OPT_PRIV },
tax 0:66300c77c6e9 279 { NULL }
tax 0:66300c77c6e9 280 };
tax 0:66300c77c6e9 281 #endif /* UNUSED */
tax 0:66300c77c6e9 282 #if 0 /* UNUSED */
tax 0:66300c77c6e9 283 /*
tax 0:66300c77c6e9 284 * setupapfile - specifies UPAP info for authenticating with peer.
tax 0:66300c77c6e9 285 */
tax 0:66300c77c6e9 286 static int
tax 0:66300c77c6e9 287 setupapfile(char **argv)
tax 0:66300c77c6e9 288 {
tax 0:66300c77c6e9 289 FILE * ufile;
tax 0:66300c77c6e9 290 int l;
tax 0:66300c77c6e9 291
tax 0:66300c77c6e9 292 lcp_allowoptions[0].neg_upap = 1;
tax 0:66300c77c6e9 293
tax 0:66300c77c6e9 294 /* open user info file */
tax 0:66300c77c6e9 295 seteuid(getuid());
tax 0:66300c77c6e9 296 ufile = fopen(*argv, "r");
tax 0:66300c77c6e9 297 seteuid(0);
tax 0:66300c77c6e9 298 if (ufile == NULL) {
tax 0:66300c77c6e9 299 option_error("unable to open user login data file %s", *argv);
tax 0:66300c77c6e9 300 return 0;
tax 0:66300c77c6e9 301 }
tax 0:66300c77c6e9 302 check_access(ufile, *argv);
tax 0:66300c77c6e9 303
tax 0:66300c77c6e9 304 /* get username */
tax 0:66300c77c6e9 305 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
tax 0:66300c77c6e9 306 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
tax 0:66300c77c6e9 307 option_error("unable to read user login data file %s", *argv);
tax 0:66300c77c6e9 308 return 0;
tax 0:66300c77c6e9 309 }
tax 0:66300c77c6e9 310 fclose(ufile);
tax 0:66300c77c6e9 311
tax 0:66300c77c6e9 312 /* get rid of newlines */
tax 0:66300c77c6e9 313 l = strlen(user);
tax 0:66300c77c6e9 314 if (l > 0 && user[l-1] == '\n')
tax 0:66300c77c6e9 315 user[l-1] = 0;
tax 0:66300c77c6e9 316 l = strlen(passwd);
tax 0:66300c77c6e9 317 if (l > 0 && passwd[l-1] == '\n')
tax 0:66300c77c6e9 318 passwd[l-1] = 0;
tax 0:66300c77c6e9 319
tax 0:66300c77c6e9 320 return (1);
tax 0:66300c77c6e9 321 }
tax 0:66300c77c6e9 322 #endif /* UNUSED */
tax 0:66300c77c6e9 323
tax 0:66300c77c6e9 324 #if 0 /* UNUSED */
tax 0:66300c77c6e9 325 /*
tax 0:66300c77c6e9 326 * privgroup - allow members of the group to have privileged access.
tax 0:66300c77c6e9 327 */
tax 0:66300c77c6e9 328 static int
tax 0:66300c77c6e9 329 privgroup(char **argv)
tax 0:66300c77c6e9 330 {
tax 0:66300c77c6e9 331 struct group *g;
tax 0:66300c77c6e9 332 int i;
tax 0:66300c77c6e9 333
tax 0:66300c77c6e9 334 g = getgrnam(*argv);
tax 0:66300c77c6e9 335 if (g == 0) {
tax 0:66300c77c6e9 336 option_error("group %s is unknown", *argv);
tax 0:66300c77c6e9 337 return 0;
tax 0:66300c77c6e9 338 }
tax 0:66300c77c6e9 339 for (i = 0; i < ngroups; ++i) {
tax 0:66300c77c6e9 340 if (groups[i] == g->gr_gid) {
tax 0:66300c77c6e9 341 privileged = 1;
tax 0:66300c77c6e9 342 break;
tax 0:66300c77c6e9 343 }
tax 0:66300c77c6e9 344 }
tax 0:66300c77c6e9 345 return 1;
tax 0:66300c77c6e9 346 }
tax 0:66300c77c6e9 347 #endif
tax 0:66300c77c6e9 348
tax 0:66300c77c6e9 349 #if 0 /* UNUSED */
tax 0:66300c77c6e9 350 /*
tax 0:66300c77c6e9 351 * set_noauth_addr - set address(es) that can be used without authentication.
tax 0:66300c77c6e9 352 * Equivalent to specifying an entry like `"" * "" addr' in pap-secrets.
tax 0:66300c77c6e9 353 */
tax 0:66300c77c6e9 354 static int
tax 0:66300c77c6e9 355 set_noauth_addr(char **argv)
tax 0:66300c77c6e9 356 {
tax 0:66300c77c6e9 357 char *addr = *argv;
tax 0:66300c77c6e9 358 int l = strlen(addr);
tax 0:66300c77c6e9 359 struct wordlist *wp;
tax 0:66300c77c6e9 360
tax 0:66300c77c6e9 361 wp = (struct wordlist *) malloc(sizeof(struct wordlist) + l + 1);
tax 0:66300c77c6e9 362 if (wp == NULL)
tax 0:66300c77c6e9 363 novm("allow-ip argument");
tax 0:66300c77c6e9 364 wp->word = (char *) (wp + 1);
tax 0:66300c77c6e9 365 wp->next = noauth_addrs;
tax 0:66300c77c6e9 366 BCOPY(addr, wp->word, l);
tax 0:66300c77c6e9 367 noauth_addrs = wp;
tax 0:66300c77c6e9 368 return 1;
tax 0:66300c77c6e9 369 }
tax 0:66300c77c6e9 370 #endif /* UNUSED */
tax 0:66300c77c6e9 371
tax 0:66300c77c6e9 372 /*
tax 0:66300c77c6e9 373 * An Open on LCP has requested a change from Dead to Establish phase.
tax 0:66300c77c6e9 374 * Do what's necessary to bring the physical layer up.
tax 0:66300c77c6e9 375 */
tax 0:66300c77c6e9 376 void
tax 0:66300c77c6e9 377 link_required(int unit)
tax 0:66300c77c6e9 378 {
tax 0:66300c77c6e9 379 LWIP_UNUSED_ARG(unit);
tax 0:66300c77c6e9 380
tax 0:66300c77c6e9 381 AUTHDEBUG(LOG_INFO, ("link_required: %d\n", unit));
tax 0:66300c77c6e9 382 }
tax 0:66300c77c6e9 383
tax 0:66300c77c6e9 384 /*
tax 0:66300c77c6e9 385 * LCP has terminated the link; go to the Dead phase and take the
tax 0:66300c77c6e9 386 * physical layer down.
tax 0:66300c77c6e9 387 */
tax 0:66300c77c6e9 388 void
tax 0:66300c77c6e9 389 link_terminated(int unit)
tax 0:66300c77c6e9 390 {
tax 0:66300c77c6e9 391 AUTHDEBUG(LOG_INFO, ("link_terminated: %d\n", unit));
tax 0:66300c77c6e9 392 if (lcp_phase[unit] == PHASE_DEAD) {
tax 0:66300c77c6e9 393 return;
tax 0:66300c77c6e9 394 }
tax 0:66300c77c6e9 395 if (logged_in) {
tax 0:66300c77c6e9 396 plogout();
tax 0:66300c77c6e9 397 }
tax 0:66300c77c6e9 398 lcp_phase[unit] = PHASE_DEAD;
tax 0:66300c77c6e9 399 AUTHDEBUG(LOG_NOTICE, ("Connection terminated.\n"));
tax 0:66300c77c6e9 400 pppLinkTerminated(unit);
tax 0:66300c77c6e9 401 }
tax 0:66300c77c6e9 402
tax 0:66300c77c6e9 403 /*
tax 0:66300c77c6e9 404 * LCP has gone down; it will either die or try to re-establish.
tax 0:66300c77c6e9 405 */
tax 0:66300c77c6e9 406 void
tax 0:66300c77c6e9 407 link_down(int unit)
tax 0:66300c77c6e9 408 {
tax 0:66300c77c6e9 409 int i;
tax 0:66300c77c6e9 410 struct protent *protp;
tax 0:66300c77c6e9 411
tax 0:66300c77c6e9 412 AUTHDEBUG(LOG_INFO, ("link_down: %d\n", unit));
tax 0:66300c77c6e9 413
tax 0:66300c77c6e9 414 if (did_authup) {
tax 0:66300c77c6e9 415 /* XXX Do link down processing. */
tax 0:66300c77c6e9 416 did_authup = 0;
tax 0:66300c77c6e9 417 }
tax 0:66300c77c6e9 418 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
tax 0:66300c77c6e9 419 if (!protp->enabled_flag) {
tax 0:66300c77c6e9 420 continue;
tax 0:66300c77c6e9 421 }
tax 0:66300c77c6e9 422 if (protp->protocol != PPP_LCP && protp->lowerdown != NULL) {
tax 0:66300c77c6e9 423 (*protp->lowerdown)(unit);
tax 0:66300c77c6e9 424 }
tax 0:66300c77c6e9 425 if (protp->protocol < 0xC000 && protp->close != NULL) {
tax 0:66300c77c6e9 426 (*protp->close)(unit, "LCP down");
tax 0:66300c77c6e9 427 }
tax 0:66300c77c6e9 428 }
tax 0:66300c77c6e9 429 num_np_open = 0; /* number of network protocols we have opened */
tax 0:66300c77c6e9 430 num_np_up = 0; /* Number of network protocols which have come up */
tax 0:66300c77c6e9 431
tax 0:66300c77c6e9 432 if (lcp_phase[unit] != PHASE_DEAD) {
tax 0:66300c77c6e9 433 lcp_phase[unit] = PHASE_TERMINATE;
tax 0:66300c77c6e9 434 }
tax 0:66300c77c6e9 435 pppLinkDown(unit);
tax 0:66300c77c6e9 436 }
tax 0:66300c77c6e9 437
tax 0:66300c77c6e9 438 /*
tax 0:66300c77c6e9 439 * The link is established.
tax 0:66300c77c6e9 440 * Proceed to the Dead, Authenticate or Network phase as appropriate.
tax 0:66300c77c6e9 441 */
tax 0:66300c77c6e9 442 void
tax 0:66300c77c6e9 443 link_established(int unit)
tax 0:66300c77c6e9 444 {
tax 0:66300c77c6e9 445 int auth;
tax 0:66300c77c6e9 446 int i;
tax 0:66300c77c6e9 447 struct protent *protp;
tax 0:66300c77c6e9 448 lcp_options *wo = &lcp_wantoptions[unit];
tax 0:66300c77c6e9 449 lcp_options *go = &lcp_gotoptions[unit];
tax 0:66300c77c6e9 450 #if PAP_SUPPORT || CHAP_SUPPORT
tax 0:66300c77c6e9 451 lcp_options *ho = &lcp_hisoptions[unit];
tax 0:66300c77c6e9 452 #endif /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 453
tax 0:66300c77c6e9 454 AUTHDEBUG(LOG_INFO, ("link_established: unit %d; Lowering up all protocols...\n", unit));
tax 0:66300c77c6e9 455 /*
tax 0:66300c77c6e9 456 * Tell higher-level protocols that LCP is up.
tax 0:66300c77c6e9 457 */
tax 0:66300c77c6e9 458 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
tax 0:66300c77c6e9 459 if (protp->protocol != PPP_LCP && protp->enabled_flag && protp->lowerup != NULL) {
tax 0:66300c77c6e9 460 (*protp->lowerup)(unit);
tax 0:66300c77c6e9 461 }
tax 0:66300c77c6e9 462 }
tax 0:66300c77c6e9 463 if (ppp_settings.auth_required && !(go->neg_chap || go->neg_upap)) {
tax 0:66300c77c6e9 464 /*
tax 0:66300c77c6e9 465 * We wanted the peer to authenticate itself, and it refused:
tax 0:66300c77c6e9 466 * treat it as though it authenticated with PAP using a username
tax 0:66300c77c6e9 467 * of "" and a password of "". If that's not OK, boot it out.
tax 0:66300c77c6e9 468 */
tax 0:66300c77c6e9 469 if (!wo->neg_upap || !null_login(unit)) {
tax 0:66300c77c6e9 470 AUTHDEBUG(LOG_WARNING, ("peer refused to authenticate\n"));
tax 0:66300c77c6e9 471 lcp_close(unit, "peer refused to authenticate");
tax 0:66300c77c6e9 472 return;
tax 0:66300c77c6e9 473 }
tax 0:66300c77c6e9 474 }
tax 0:66300c77c6e9 475
tax 0:66300c77c6e9 476 lcp_phase[unit] = PHASE_AUTHENTICATE;
tax 0:66300c77c6e9 477 auth = 0;
tax 0:66300c77c6e9 478 #if CHAP_SUPPORT
tax 0:66300c77c6e9 479 if (go->neg_chap) {
tax 0:66300c77c6e9 480 ChapAuthPeer(unit, ppp_settings.our_name, go->chap_mdtype);
tax 0:66300c77c6e9 481 auth |= CHAP_PEER;
tax 0:66300c77c6e9 482 }
tax 0:66300c77c6e9 483 #endif /* CHAP_SUPPORT */
tax 0:66300c77c6e9 484 #if PAP_SUPPORT && CHAP_SUPPORT
tax 0:66300c77c6e9 485 else
tax 0:66300c77c6e9 486 #endif /* PAP_SUPPORT && CHAP_SUPPORT */
tax 0:66300c77c6e9 487 #if PAP_SUPPORT
tax 0:66300c77c6e9 488 if (go->neg_upap) {
tax 0:66300c77c6e9 489 upap_authpeer(unit);
tax 0:66300c77c6e9 490 auth |= PAP_PEER;
tax 0:66300c77c6e9 491 }
tax 0:66300c77c6e9 492 #endif /* PAP_SUPPORT */
tax 0:66300c77c6e9 493 #if CHAP_SUPPORT
tax 0:66300c77c6e9 494 if (ho->neg_chap) {
tax 0:66300c77c6e9 495 ChapAuthWithPeer(unit, ppp_settings.user, ho->chap_mdtype);
tax 0:66300c77c6e9 496 auth |= CHAP_WITHPEER;
tax 0:66300c77c6e9 497 }
tax 0:66300c77c6e9 498 #endif /* CHAP_SUPPORT */
tax 0:66300c77c6e9 499 #if PAP_SUPPORT && CHAP_SUPPORT
tax 0:66300c77c6e9 500 else
tax 0:66300c77c6e9 501 #endif /* PAP_SUPPORT && CHAP_SUPPORT */
tax 0:66300c77c6e9 502 #if PAP_SUPPORT
tax 0:66300c77c6e9 503 if (ho->neg_upap) {
tax 0:66300c77c6e9 504 if (ppp_settings.passwd[0] == 0) {
tax 0:66300c77c6e9 505 passwd_from_file = 1;
tax 0:66300c77c6e9 506 if (!get_pap_passwd(unit, ppp_settings.user, ppp_settings.passwd)) {
tax 0:66300c77c6e9 507 AUTHDEBUG(LOG_ERR, ("No secret found for PAP login\n"));
tax 0:66300c77c6e9 508 }
tax 0:66300c77c6e9 509 }
tax 0:66300c77c6e9 510 upap_authwithpeer(unit, ppp_settings.user, ppp_settings.passwd);
tax 0:66300c77c6e9 511 auth |= PAP_WITHPEER;
tax 0:66300c77c6e9 512 }
tax 0:66300c77c6e9 513 #endif /* PAP_SUPPORT */
tax 0:66300c77c6e9 514 auth_pending[unit] = auth;
tax 0:66300c77c6e9 515
tax 0:66300c77c6e9 516 if (!auth) {
tax 0:66300c77c6e9 517 network_phase(unit);
tax 0:66300c77c6e9 518 }
tax 0:66300c77c6e9 519 }
tax 0:66300c77c6e9 520
tax 0:66300c77c6e9 521 /*
tax 0:66300c77c6e9 522 * Proceed to the network phase.
tax 0:66300c77c6e9 523 */
tax 0:66300c77c6e9 524 static void
tax 0:66300c77c6e9 525 network_phase(int unit)
tax 0:66300c77c6e9 526 {
tax 0:66300c77c6e9 527 int i;
tax 0:66300c77c6e9 528 struct protent *protp;
tax 0:66300c77c6e9 529 lcp_options *go = &lcp_gotoptions[unit];
tax 0:66300c77c6e9 530
tax 0:66300c77c6e9 531 /*
tax 0:66300c77c6e9 532 * If the peer had to authenticate, run the auth-up script now.
tax 0:66300c77c6e9 533 */
tax 0:66300c77c6e9 534 if ((go->neg_chap || go->neg_upap) && !did_authup) {
tax 0:66300c77c6e9 535 /* XXX Do setup for peer authentication. */
tax 0:66300c77c6e9 536 did_authup = 1;
tax 0:66300c77c6e9 537 }
tax 0:66300c77c6e9 538
tax 0:66300c77c6e9 539 #if CBCP_SUPPORT
tax 0:66300c77c6e9 540 /*
tax 0:66300c77c6e9 541 * If we negotiated callback, do it now.
tax 0:66300c77c6e9 542 */
tax 0:66300c77c6e9 543 if (go->neg_cbcp) {
tax 0:66300c77c6e9 544 lcp_phase[unit] = PHASE_CALLBACK;
tax 0:66300c77c6e9 545 (*cbcp_protent.open)(unit);
tax 0:66300c77c6e9 546 return;
tax 0:66300c77c6e9 547 }
tax 0:66300c77c6e9 548 #endif /* CBCP_SUPPORT */
tax 0:66300c77c6e9 549
tax 0:66300c77c6e9 550 lcp_phase[unit] = PHASE_NETWORK;
tax 0:66300c77c6e9 551 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
tax 0:66300c77c6e9 552 if (protp->protocol < 0xC000 && protp->enabled_flag && protp->open != NULL) {
tax 0:66300c77c6e9 553 (*protp->open)(unit);
tax 0:66300c77c6e9 554 if (protp->protocol != PPP_CCP) {
tax 0:66300c77c6e9 555 ++num_np_open;
tax 0:66300c77c6e9 556 }
tax 0:66300c77c6e9 557 }
tax 0:66300c77c6e9 558 }
tax 0:66300c77c6e9 559
tax 0:66300c77c6e9 560 if (num_np_open == 0) {
tax 0:66300c77c6e9 561 /* nothing to do */
tax 0:66300c77c6e9 562 lcp_close(0, "No network protocols running");
tax 0:66300c77c6e9 563 }
tax 0:66300c77c6e9 564 }
tax 0:66300c77c6e9 565 /* @todo: add void start_networks(void) here (pppd 2.3.11) */
tax 0:66300c77c6e9 566
tax 0:66300c77c6e9 567 /*
tax 0:66300c77c6e9 568 * The peer has failed to authenticate himself using `protocol'.
tax 0:66300c77c6e9 569 */
tax 0:66300c77c6e9 570 void
tax 0:66300c77c6e9 571 auth_peer_fail(int unit, u16_t protocol)
tax 0:66300c77c6e9 572 {
tax 0:66300c77c6e9 573 LWIP_UNUSED_ARG(protocol);
tax 0:66300c77c6e9 574
tax 0:66300c77c6e9 575 AUTHDEBUG(LOG_INFO, ("auth_peer_fail: %d proto=%X\n", unit, protocol));
tax 0:66300c77c6e9 576 /*
tax 0:66300c77c6e9 577 * Authentication failure: take the link down
tax 0:66300c77c6e9 578 */
tax 0:66300c77c6e9 579 lcp_close(unit, "Authentication failed");
tax 0:66300c77c6e9 580 }
tax 0:66300c77c6e9 581
tax 0:66300c77c6e9 582
tax 0:66300c77c6e9 583 #if PAP_SUPPORT || CHAP_SUPPORT
tax 0:66300c77c6e9 584 /*
tax 0:66300c77c6e9 585 * The peer has been successfully authenticated using `protocol'.
tax 0:66300c77c6e9 586 */
tax 0:66300c77c6e9 587 void
tax 0:66300c77c6e9 588 auth_peer_success(int unit, u16_t protocol, char *name, int namelen)
tax 0:66300c77c6e9 589 {
tax 0:66300c77c6e9 590 int pbit;
tax 0:66300c77c6e9 591
tax 0:66300c77c6e9 592 AUTHDEBUG(LOG_INFO, ("auth_peer_success: %d proto=%X\n", unit, protocol));
tax 0:66300c77c6e9 593 switch (protocol) {
tax 0:66300c77c6e9 594 case PPP_CHAP:
tax 0:66300c77c6e9 595 pbit = CHAP_PEER;
tax 0:66300c77c6e9 596 break;
tax 0:66300c77c6e9 597 case PPP_PAP:
tax 0:66300c77c6e9 598 pbit = PAP_PEER;
tax 0:66300c77c6e9 599 break;
tax 0:66300c77c6e9 600 default:
tax 0:66300c77c6e9 601 AUTHDEBUG(LOG_WARNING, ("auth_peer_success: unknown protocol %x\n", protocol));
tax 0:66300c77c6e9 602 return;
tax 0:66300c77c6e9 603 }
tax 0:66300c77c6e9 604
tax 0:66300c77c6e9 605 /*
tax 0:66300c77c6e9 606 * Save the authenticated name of the peer for later.
tax 0:66300c77c6e9 607 */
tax 0:66300c77c6e9 608 if (namelen > (int)sizeof(peer_authname) - 1) {
tax 0:66300c77c6e9 609 namelen = sizeof(peer_authname) - 1;
tax 0:66300c77c6e9 610 }
tax 0:66300c77c6e9 611 BCOPY(name, peer_authname, namelen);
tax 0:66300c77c6e9 612 peer_authname[namelen] = 0;
tax 0:66300c77c6e9 613
tax 0:66300c77c6e9 614 /*
tax 0:66300c77c6e9 615 * If there is no more authentication still to be done,
tax 0:66300c77c6e9 616 * proceed to the network (or callback) phase.
tax 0:66300c77c6e9 617 */
tax 0:66300c77c6e9 618 if ((auth_pending[unit] &= ~pbit) == 0) {
tax 0:66300c77c6e9 619 network_phase(unit);
tax 0:66300c77c6e9 620 }
tax 0:66300c77c6e9 621 }
tax 0:66300c77c6e9 622
tax 0:66300c77c6e9 623 /*
tax 0:66300c77c6e9 624 * We have failed to authenticate ourselves to the peer using `protocol'.
tax 0:66300c77c6e9 625 */
tax 0:66300c77c6e9 626 void
tax 0:66300c77c6e9 627 auth_withpeer_fail(int unit, u16_t protocol)
tax 0:66300c77c6e9 628 {
tax 0:66300c77c6e9 629 int errCode = PPPERR_AUTHFAIL;
tax 0:66300c77c6e9 630
tax 0:66300c77c6e9 631 LWIP_UNUSED_ARG(protocol);
tax 0:66300c77c6e9 632
tax 0:66300c77c6e9 633 AUTHDEBUG(LOG_INFO, ("auth_withpeer_fail: %d proto=%X\n", unit, protocol));
tax 0:66300c77c6e9 634 if (passwd_from_file) {
tax 0:66300c77c6e9 635 BZERO(ppp_settings.passwd, MAXSECRETLEN);
tax 0:66300c77c6e9 636 }
tax 0:66300c77c6e9 637
tax 0:66300c77c6e9 638 /*
tax 0:66300c77c6e9 639 * We've failed to authenticate ourselves to our peer.
tax 0:66300c77c6e9 640 * He'll probably take the link down, and there's not much
tax 0:66300c77c6e9 641 * we can do except wait for that.
tax 0:66300c77c6e9 642 */
tax 0:66300c77c6e9 643 pppIOCtl(unit, PPPCTLS_ERRCODE, &errCode);
tax 0:66300c77c6e9 644 lcp_close(unit, "Failed to authenticate ourselves to peer");
tax 0:66300c77c6e9 645 }
tax 0:66300c77c6e9 646
tax 0:66300c77c6e9 647 /*
tax 0:66300c77c6e9 648 * We have successfully authenticated ourselves with the peer using `protocol'.
tax 0:66300c77c6e9 649 */
tax 0:66300c77c6e9 650 void
tax 0:66300c77c6e9 651 auth_withpeer_success(int unit, u16_t protocol)
tax 0:66300c77c6e9 652 {
tax 0:66300c77c6e9 653 int pbit;
tax 0:66300c77c6e9 654
tax 0:66300c77c6e9 655 AUTHDEBUG(LOG_INFO, ("auth_withpeer_success: %d proto=%X\n", unit, protocol));
tax 0:66300c77c6e9 656 switch (protocol) {
tax 0:66300c77c6e9 657 case PPP_CHAP:
tax 0:66300c77c6e9 658 pbit = CHAP_WITHPEER;
tax 0:66300c77c6e9 659 break;
tax 0:66300c77c6e9 660 case PPP_PAP:
tax 0:66300c77c6e9 661 if (passwd_from_file) {
tax 0:66300c77c6e9 662 BZERO(ppp_settings.passwd, MAXSECRETLEN);
tax 0:66300c77c6e9 663 }
tax 0:66300c77c6e9 664 pbit = PAP_WITHPEER;
tax 0:66300c77c6e9 665 break;
tax 0:66300c77c6e9 666 default:
tax 0:66300c77c6e9 667 AUTHDEBUG(LOG_WARNING, ("auth_peer_success: unknown protocol %x\n", protocol));
tax 0:66300c77c6e9 668 pbit = 0;
tax 0:66300c77c6e9 669 }
tax 0:66300c77c6e9 670
tax 0:66300c77c6e9 671 /*
tax 0:66300c77c6e9 672 * If there is no more authentication still being done,
tax 0:66300c77c6e9 673 * proceed to the network (or callback) phase.
tax 0:66300c77c6e9 674 */
tax 0:66300c77c6e9 675 if ((auth_pending[unit] &= ~pbit) == 0) {
tax 0:66300c77c6e9 676 network_phase(unit);
tax 0:66300c77c6e9 677 }
tax 0:66300c77c6e9 678 }
tax 0:66300c77c6e9 679 #endif /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 680
tax 0:66300c77c6e9 681
tax 0:66300c77c6e9 682 /*
tax 0:66300c77c6e9 683 * np_up - a network protocol has come up.
tax 0:66300c77c6e9 684 */
tax 0:66300c77c6e9 685 void
tax 0:66300c77c6e9 686 np_up(int unit, u16_t proto)
tax 0:66300c77c6e9 687 {
tax 0:66300c77c6e9 688 LWIP_UNUSED_ARG(unit);
tax 0:66300c77c6e9 689 LWIP_UNUSED_ARG(proto);
tax 0:66300c77c6e9 690
tax 0:66300c77c6e9 691 AUTHDEBUG(LOG_INFO, ("np_up: %d proto=%X\n", unit, proto));
tax 0:66300c77c6e9 692 if (num_np_up == 0) {
tax 0:66300c77c6e9 693 AUTHDEBUG(LOG_INFO, ("np_up: maxconnect=%d idle_time_limit=%d\n",ppp_settings.maxconnect,ppp_settings.idle_time_limit));
tax 0:66300c77c6e9 694 /*
tax 0:66300c77c6e9 695 * At this point we consider that the link has come up successfully.
tax 0:66300c77c6e9 696 */
tax 0:66300c77c6e9 697 if (ppp_settings.idle_time_limit > 0) {
tax 0:66300c77c6e9 698 TIMEOUT(check_idle, NULL, ppp_settings.idle_time_limit);
tax 0:66300c77c6e9 699 }
tax 0:66300c77c6e9 700
tax 0:66300c77c6e9 701 /*
tax 0:66300c77c6e9 702 * Set a timeout to close the connection once the maximum
tax 0:66300c77c6e9 703 * connect time has expired.
tax 0:66300c77c6e9 704 */
tax 0:66300c77c6e9 705 if (ppp_settings.maxconnect > 0) {
tax 0:66300c77c6e9 706 TIMEOUT(connect_time_expired, 0, ppp_settings.maxconnect);
tax 0:66300c77c6e9 707 }
tax 0:66300c77c6e9 708 }
tax 0:66300c77c6e9 709 ++num_np_up;
tax 0:66300c77c6e9 710 }
tax 0:66300c77c6e9 711
tax 0:66300c77c6e9 712 /*
tax 0:66300c77c6e9 713 * np_down - a network protocol has gone down.
tax 0:66300c77c6e9 714 */
tax 0:66300c77c6e9 715 void
tax 0:66300c77c6e9 716 np_down(int unit, u16_t proto)
tax 0:66300c77c6e9 717 {
tax 0:66300c77c6e9 718 LWIP_UNUSED_ARG(unit);
tax 0:66300c77c6e9 719 LWIP_UNUSED_ARG(proto);
tax 0:66300c77c6e9 720
tax 0:66300c77c6e9 721 AUTHDEBUG(LOG_INFO, ("np_down: %d proto=%X\n", unit, proto));
tax 0:66300c77c6e9 722 if (--num_np_up == 0 && ppp_settings.idle_time_limit > 0) {
tax 0:66300c77c6e9 723 UNTIMEOUT(check_idle, NULL);
tax 0:66300c77c6e9 724 }
tax 0:66300c77c6e9 725 }
tax 0:66300c77c6e9 726
tax 0:66300c77c6e9 727 /*
tax 0:66300c77c6e9 728 * np_finished - a network protocol has finished using the link.
tax 0:66300c77c6e9 729 */
tax 0:66300c77c6e9 730 void
tax 0:66300c77c6e9 731 np_finished(int unit, u16_t proto)
tax 0:66300c77c6e9 732 {
tax 0:66300c77c6e9 733 LWIP_UNUSED_ARG(unit);
tax 0:66300c77c6e9 734 LWIP_UNUSED_ARG(proto);
tax 0:66300c77c6e9 735
tax 0:66300c77c6e9 736 AUTHDEBUG(LOG_INFO, ("np_finished: %d proto=%X\n", unit, proto));
tax 0:66300c77c6e9 737 if (--num_np_open <= 0) {
tax 0:66300c77c6e9 738 /* no further use for the link: shut up shop. */
tax 0:66300c77c6e9 739 lcp_close(0, "No network protocols running");
tax 0:66300c77c6e9 740 }
tax 0:66300c77c6e9 741 }
tax 0:66300c77c6e9 742
tax 0:66300c77c6e9 743 /*
tax 0:66300c77c6e9 744 * check_idle - check whether the link has been idle for long
tax 0:66300c77c6e9 745 * enough that we can shut it down.
tax 0:66300c77c6e9 746 */
tax 0:66300c77c6e9 747 static void
tax 0:66300c77c6e9 748 check_idle(void *arg)
tax 0:66300c77c6e9 749 {
tax 0:66300c77c6e9 750 struct ppp_idle idle;
tax 0:66300c77c6e9 751 u_short itime;
tax 0:66300c77c6e9 752
tax 0:66300c77c6e9 753 LWIP_UNUSED_ARG(arg);
tax 0:66300c77c6e9 754 if (!get_idle_time(0, &idle)) {
tax 0:66300c77c6e9 755 return;
tax 0:66300c77c6e9 756 }
tax 0:66300c77c6e9 757 itime = LWIP_MIN(idle.xmit_idle, idle.recv_idle);
tax 0:66300c77c6e9 758 if (itime >= ppp_settings.idle_time_limit) {
tax 0:66300c77c6e9 759 /* link is idle: shut it down. */
tax 0:66300c77c6e9 760 AUTHDEBUG(LOG_INFO, ("Terminating connection due to lack of activity.\n"));
tax 0:66300c77c6e9 761 lcp_close(0, "Link inactive");
tax 0:66300c77c6e9 762 } else {
tax 0:66300c77c6e9 763 TIMEOUT(check_idle, NULL, ppp_settings.idle_time_limit - itime);
tax 0:66300c77c6e9 764 }
tax 0:66300c77c6e9 765 }
tax 0:66300c77c6e9 766
tax 0:66300c77c6e9 767 /*
tax 0:66300c77c6e9 768 * connect_time_expired - log a message and close the connection.
tax 0:66300c77c6e9 769 */
tax 0:66300c77c6e9 770 static void
tax 0:66300c77c6e9 771 connect_time_expired(void *arg)
tax 0:66300c77c6e9 772 {
tax 0:66300c77c6e9 773 LWIP_UNUSED_ARG(arg);
tax 0:66300c77c6e9 774
tax 0:66300c77c6e9 775 AUTHDEBUG(LOG_INFO, ("Connect time expired\n"));
tax 0:66300c77c6e9 776 lcp_close(0, "Connect time expired"); /* Close connection */
tax 0:66300c77c6e9 777 }
tax 0:66300c77c6e9 778
tax 0:66300c77c6e9 779 #if 0 /* UNUSED */
tax 0:66300c77c6e9 780 /*
tax 0:66300c77c6e9 781 * auth_check_options - called to check authentication options.
tax 0:66300c77c6e9 782 */
tax 0:66300c77c6e9 783 void
tax 0:66300c77c6e9 784 auth_check_options(void)
tax 0:66300c77c6e9 785 {
tax 0:66300c77c6e9 786 lcp_options *wo = &lcp_wantoptions[0];
tax 0:66300c77c6e9 787 int can_auth;
tax 0:66300c77c6e9 788 ipcp_options *ipwo = &ipcp_wantoptions[0];
tax 0:66300c77c6e9 789 u32_t remote;
tax 0:66300c77c6e9 790
tax 0:66300c77c6e9 791 /* Default our_name to hostname, and user to our_name */
tax 0:66300c77c6e9 792 if (ppp_settings.our_name[0] == 0 || ppp_settings.usehostname) {
tax 0:66300c77c6e9 793 strcpy(ppp_settings.our_name, ppp_settings.hostname);
tax 0:66300c77c6e9 794 }
tax 0:66300c77c6e9 795
tax 0:66300c77c6e9 796 if (ppp_settings.user[0] == 0) {
tax 0:66300c77c6e9 797 strcpy(ppp_settings.user, ppp_settings.our_name);
tax 0:66300c77c6e9 798 }
tax 0:66300c77c6e9 799
tax 0:66300c77c6e9 800 /* If authentication is required, ask peer for CHAP or PAP. */
tax 0:66300c77c6e9 801 if (ppp_settings.auth_required && !wo->neg_chap && !wo->neg_upap) {
tax 0:66300c77c6e9 802 wo->neg_chap = 1;
tax 0:66300c77c6e9 803 wo->neg_upap = 1;
tax 0:66300c77c6e9 804 }
tax 0:66300c77c6e9 805
tax 0:66300c77c6e9 806 /*
tax 0:66300c77c6e9 807 * Check whether we have appropriate secrets to use
tax 0:66300c77c6e9 808 * to authenticate the peer.
tax 0:66300c77c6e9 809 */
tax 0:66300c77c6e9 810 can_auth = wo->neg_upap && have_pap_secret();
tax 0:66300c77c6e9 811 if (!can_auth && wo->neg_chap) {
tax 0:66300c77c6e9 812 remote = ipwo->accept_remote? 0: ipwo->hisaddr;
tax 0:66300c77c6e9 813 can_auth = have_chap_secret(ppp_settings.remote_name, ppp_settings.our_name, remote);
tax 0:66300c77c6e9 814 }
tax 0:66300c77c6e9 815
tax 0:66300c77c6e9 816 if (ppp_settings.auth_required && !can_auth) {
tax 0:66300c77c6e9 817 ppp_panic("No auth secret");
tax 0:66300c77c6e9 818 }
tax 0:66300c77c6e9 819 }
tax 0:66300c77c6e9 820 #endif /* UNUSED */
tax 0:66300c77c6e9 821
tax 0:66300c77c6e9 822 /*
tax 0:66300c77c6e9 823 * auth_reset - called when LCP is starting negotiations to recheck
tax 0:66300c77c6e9 824 * authentication options, i.e. whether we have appropriate secrets
tax 0:66300c77c6e9 825 * to use for authenticating ourselves and/or the peer.
tax 0:66300c77c6e9 826 */
tax 0:66300c77c6e9 827 void
tax 0:66300c77c6e9 828 auth_reset(int unit)
tax 0:66300c77c6e9 829 {
tax 0:66300c77c6e9 830 lcp_options *go = &lcp_gotoptions[unit];
tax 0:66300c77c6e9 831 lcp_options *ao = &lcp_allowoptions[0];
tax 0:66300c77c6e9 832 ipcp_options *ipwo = &ipcp_wantoptions[0];
tax 0:66300c77c6e9 833 u32_t remote;
tax 0:66300c77c6e9 834
tax 0:66300c77c6e9 835 AUTHDEBUG(LOG_INFO, ("auth_reset: %d\n", unit));
tax 0:66300c77c6e9 836 ao->neg_upap = !ppp_settings.refuse_pap && (ppp_settings.passwd[0] != 0 || get_pap_passwd(unit, NULL, NULL));
tax 0:66300c77c6e9 837 ao->neg_chap = !ppp_settings.refuse_chap && ppp_settings.passwd[0] != 0 /*have_chap_secret(ppp_settings.user, ppp_settings.remote_name, (u32_t)0)*/;
tax 0:66300c77c6e9 838
tax 0:66300c77c6e9 839 if (go->neg_upap && !have_pap_secret()) {
tax 0:66300c77c6e9 840 go->neg_upap = 0;
tax 0:66300c77c6e9 841 }
tax 0:66300c77c6e9 842 if (go->neg_chap) {
tax 0:66300c77c6e9 843 remote = ipwo->accept_remote? 0: ipwo->hisaddr;
tax 0:66300c77c6e9 844 if (!have_chap_secret(ppp_settings.remote_name, ppp_settings.our_name, remote)) {
tax 0:66300c77c6e9 845 go->neg_chap = 0;
tax 0:66300c77c6e9 846 }
tax 0:66300c77c6e9 847 }
tax 0:66300c77c6e9 848 }
tax 0:66300c77c6e9 849
tax 0:66300c77c6e9 850 #if PAP_SUPPORT
tax 0:66300c77c6e9 851 /*
tax 0:66300c77c6e9 852 * check_passwd - Check the user name and passwd against the PAP secrets
tax 0:66300c77c6e9 853 * file. If requested, also check against the system password database,
tax 0:66300c77c6e9 854 * and login the user if OK.
tax 0:66300c77c6e9 855 *
tax 0:66300c77c6e9 856 * returns:
tax 0:66300c77c6e9 857 * UPAP_AUTHNAK: Authentication failed.
tax 0:66300c77c6e9 858 * UPAP_AUTHACK: Authentication succeeded.
tax 0:66300c77c6e9 859 * In either case, msg points to an appropriate message.
tax 0:66300c77c6e9 860 */
tax 0:66300c77c6e9 861 u_char
tax 0:66300c77c6e9 862 check_passwd( int unit, char *auser, int userlen, char *apasswd, int passwdlen, char **msg, int *msglen)
tax 0:66300c77c6e9 863 {
tax 0:66300c77c6e9 864 #if 1 /* XXX Assume all entries OK. */
tax 0:66300c77c6e9 865 LWIP_UNUSED_ARG(unit);
tax 0:66300c77c6e9 866 LWIP_UNUSED_ARG(auser);
tax 0:66300c77c6e9 867 LWIP_UNUSED_ARG(userlen);
tax 0:66300c77c6e9 868 LWIP_UNUSED_ARG(apasswd);
tax 0:66300c77c6e9 869 LWIP_UNUSED_ARG(passwdlen);
tax 0:66300c77c6e9 870 LWIP_UNUSED_ARG(msglen);
tax 0:66300c77c6e9 871 *msg = (char *) 0;
tax 0:66300c77c6e9 872 return UPAP_AUTHACK; /* XXX Assume all entries OK. */
tax 0:66300c77c6e9 873 #else
tax 0:66300c77c6e9 874 u_char ret = 0;
tax 0:66300c77c6e9 875 struct wordlist *addrs = NULL;
tax 0:66300c77c6e9 876 char passwd[256], user[256];
tax 0:66300c77c6e9 877 char secret[MAXWORDLEN];
tax 0:66300c77c6e9 878 static u_short attempts = 0;
tax 0:66300c77c6e9 879
tax 0:66300c77c6e9 880 /*
tax 0:66300c77c6e9 881 * Make copies of apasswd and auser, then null-terminate them.
tax 0:66300c77c6e9 882 */
tax 0:66300c77c6e9 883 BCOPY(apasswd, passwd, passwdlen);
tax 0:66300c77c6e9 884 passwd[passwdlen] = '\0';
tax 0:66300c77c6e9 885 BCOPY(auser, user, userlen);
tax 0:66300c77c6e9 886 user[userlen] = '\0';
tax 0:66300c77c6e9 887 *msg = (char *) 0;
tax 0:66300c77c6e9 888
tax 0:66300c77c6e9 889 /* XXX Validate user name and password. */
tax 0:66300c77c6e9 890 ret = UPAP_AUTHACK; /* XXX Assume all entries OK. */
tax 0:66300c77c6e9 891
tax 0:66300c77c6e9 892 if (ret == UPAP_AUTHNAK) {
tax 0:66300c77c6e9 893 if (*msg == (char *) 0) {
tax 0:66300c77c6e9 894 *msg = "Login incorrect";
tax 0:66300c77c6e9 895 }
tax 0:66300c77c6e9 896 *msglen = strlen(*msg);
tax 0:66300c77c6e9 897 /*
tax 0:66300c77c6e9 898 * Frustrate passwd stealer programs.
tax 0:66300c77c6e9 899 * Allow 10 tries, but start backing off after 3 (stolen from login).
tax 0:66300c77c6e9 900 * On 10'th, drop the connection.
tax 0:66300c77c6e9 901 */
tax 0:66300c77c6e9 902 if (attempts++ >= 10) {
tax 0:66300c77c6e9 903 AUTHDEBUG(LOG_WARNING, ("%d LOGIN FAILURES BY %s\n", attempts, user));
tax 0:66300c77c6e9 904 /*ppp_panic("Excess Bad Logins");*/
tax 0:66300c77c6e9 905 }
tax 0:66300c77c6e9 906 if (attempts > 3) {
tax 0:66300c77c6e9 907 /* @todo: this was sleep(), i.e. seconds, not milliseconds
tax 0:66300c77c6e9 908 * I don't think we really need this in lwIP - we would block tcpip_thread!
tax 0:66300c77c6e9 909 */
tax 0:66300c77c6e9 910 /*sys_msleep((attempts - 3) * 5);*/
tax 0:66300c77c6e9 911 }
tax 0:66300c77c6e9 912 if (addrs != NULL) {
tax 0:66300c77c6e9 913 free_wordlist(addrs);
tax 0:66300c77c6e9 914 }
tax 0:66300c77c6e9 915 } else {
tax 0:66300c77c6e9 916 attempts = 0; /* Reset count */
tax 0:66300c77c6e9 917 if (*msg == (char *) 0) {
tax 0:66300c77c6e9 918 *msg = "Login ok";
tax 0:66300c77c6e9 919 }
tax 0:66300c77c6e9 920 *msglen = strlen(*msg);
tax 0:66300c77c6e9 921 set_allowed_addrs(unit, addrs);
tax 0:66300c77c6e9 922 }
tax 0:66300c77c6e9 923
tax 0:66300c77c6e9 924 BZERO(passwd, sizeof(passwd));
tax 0:66300c77c6e9 925 BZERO(secret, sizeof(secret));
tax 0:66300c77c6e9 926
tax 0:66300c77c6e9 927 return ret;
tax 0:66300c77c6e9 928 #endif
tax 0:66300c77c6e9 929 }
tax 0:66300c77c6e9 930 #endif /* PAP_SUPPORT */
tax 0:66300c77c6e9 931
tax 0:66300c77c6e9 932 #if 0 /* UNUSED */
tax 0:66300c77c6e9 933 /*
tax 0:66300c77c6e9 934 * This function is needed for PAM.
tax 0:66300c77c6e9 935 */
tax 0:66300c77c6e9 936
tax 0:66300c77c6e9 937 #ifdef USE_PAM
tax 0:66300c77c6e9 938
tax 0:66300c77c6e9 939 /* lwip does not support PAM*/
tax 0:66300c77c6e9 940
tax 0:66300c77c6e9 941 #endif /* USE_PAM */
tax 0:66300c77c6e9 942
tax 0:66300c77c6e9 943 #endif /* UNUSED */
tax 0:66300c77c6e9 944
tax 0:66300c77c6e9 945
tax 0:66300c77c6e9 946 #if 0 /* UNUSED */
tax 0:66300c77c6e9 947 /*
tax 0:66300c77c6e9 948 * plogin - Check the user name and password against the system
tax 0:66300c77c6e9 949 * password database, and login the user if OK.
tax 0:66300c77c6e9 950 *
tax 0:66300c77c6e9 951 * returns:
tax 0:66300c77c6e9 952 * UPAP_AUTHNAK: Login failed.
tax 0:66300c77c6e9 953 * UPAP_AUTHACK: Login succeeded.
tax 0:66300c77c6e9 954 * In either case, msg points to an appropriate message.
tax 0:66300c77c6e9 955 */
tax 0:66300c77c6e9 956 static int
tax 0:66300c77c6e9 957 plogin(char *user, char *passwd, char **msg, int *msglen)
tax 0:66300c77c6e9 958 {
tax 0:66300c77c6e9 959
tax 0:66300c77c6e9 960 LWIP_UNUSED_ARG(user);
tax 0:66300c77c6e9 961 LWIP_UNUSED_ARG(passwd);
tax 0:66300c77c6e9 962 LWIP_UNUSED_ARG(msg);
tax 0:66300c77c6e9 963 LWIP_UNUSED_ARG(msglen);
tax 0:66300c77c6e9 964
tax 0:66300c77c6e9 965
tax 0:66300c77c6e9 966 /* The new lines are here align the file when
tax 0:66300c77c6e9 967 * compared against the pppd 2.3.11 code */
tax 0:66300c77c6e9 968
tax 0:66300c77c6e9 969
tax 0:66300c77c6e9 970
tax 0:66300c77c6e9 971
tax 0:66300c77c6e9 972
tax 0:66300c77c6e9 973
tax 0:66300c77c6e9 974
tax 0:66300c77c6e9 975
tax 0:66300c77c6e9 976
tax 0:66300c77c6e9 977
tax 0:66300c77c6e9 978
tax 0:66300c77c6e9 979
tax 0:66300c77c6e9 980
tax 0:66300c77c6e9 981
tax 0:66300c77c6e9 982
tax 0:66300c77c6e9 983
tax 0:66300c77c6e9 984 /* XXX Fail until we decide that we want to support logins. */
tax 0:66300c77c6e9 985 return (UPAP_AUTHNAK);
tax 0:66300c77c6e9 986 }
tax 0:66300c77c6e9 987 #endif
tax 0:66300c77c6e9 988
tax 0:66300c77c6e9 989
tax 0:66300c77c6e9 990
tax 0:66300c77c6e9 991 /*
tax 0:66300c77c6e9 992 * plogout - Logout the user.
tax 0:66300c77c6e9 993 */
tax 0:66300c77c6e9 994 static void
tax 0:66300c77c6e9 995 plogout(void)
tax 0:66300c77c6e9 996 {
tax 0:66300c77c6e9 997 logged_in = 0;
tax 0:66300c77c6e9 998 }
tax 0:66300c77c6e9 999
tax 0:66300c77c6e9 1000 /*
tax 0:66300c77c6e9 1001 * null_login - Check if a username of "" and a password of "" are
tax 0:66300c77c6e9 1002 * acceptable, and iff so, set the list of acceptable IP addresses
tax 0:66300c77c6e9 1003 * and return 1.
tax 0:66300c77c6e9 1004 */
tax 0:66300c77c6e9 1005 static int
tax 0:66300c77c6e9 1006 null_login(int unit)
tax 0:66300c77c6e9 1007 {
tax 0:66300c77c6e9 1008 LWIP_UNUSED_ARG(unit);
tax 0:66300c77c6e9 1009 /* XXX Fail until we decide that we want to support logins. */
tax 0:66300c77c6e9 1010 return 0;
tax 0:66300c77c6e9 1011 }
tax 0:66300c77c6e9 1012
tax 0:66300c77c6e9 1013
tax 0:66300c77c6e9 1014 /*
tax 0:66300c77c6e9 1015 * get_pap_passwd - get a password for authenticating ourselves with
tax 0:66300c77c6e9 1016 * our peer using PAP. Returns 1 on success, 0 if no suitable password
tax 0:66300c77c6e9 1017 * could be found.
tax 0:66300c77c6e9 1018 */
tax 0:66300c77c6e9 1019 static int
tax 0:66300c77c6e9 1020 get_pap_passwd(int unit, char *user, char *passwd)
tax 0:66300c77c6e9 1021 {
tax 0:66300c77c6e9 1022 LWIP_UNUSED_ARG(unit);
tax 0:66300c77c6e9 1023 /* normally we would reject PAP if no password is provided,
tax 0:66300c77c6e9 1024 but this causes problems with some providers (like CHT in Taiwan)
tax 0:66300c77c6e9 1025 who incorrectly request PAP and expect a bogus/empty password, so
tax 0:66300c77c6e9 1026 always provide a default user/passwd of "none"/"none"
tax 0:66300c77c6e9 1027
tax 0:66300c77c6e9 1028 @todo: This should be configured by the user, instead of being hardcoded here!
tax 0:66300c77c6e9 1029 */
tax 0:66300c77c6e9 1030 if(user) {
tax 0:66300c77c6e9 1031 strcpy(user, "none");
tax 0:66300c77c6e9 1032 }
tax 0:66300c77c6e9 1033 if(passwd) {
tax 0:66300c77c6e9 1034 strcpy(passwd, "none");
tax 0:66300c77c6e9 1035 }
tax 0:66300c77c6e9 1036 return 1;
tax 0:66300c77c6e9 1037 }
tax 0:66300c77c6e9 1038
tax 0:66300c77c6e9 1039 /*
tax 0:66300c77c6e9 1040 * have_pap_secret - check whether we have a PAP file with any
tax 0:66300c77c6e9 1041 * secrets that we could possibly use for authenticating the peer.
tax 0:66300c77c6e9 1042 */
tax 0:66300c77c6e9 1043 static int
tax 0:66300c77c6e9 1044 have_pap_secret(void)
tax 0:66300c77c6e9 1045 {
tax 0:66300c77c6e9 1046 /* XXX Fail until we set up our passwords. */
tax 0:66300c77c6e9 1047 return 0;
tax 0:66300c77c6e9 1048 }
tax 0:66300c77c6e9 1049
tax 0:66300c77c6e9 1050 /*
tax 0:66300c77c6e9 1051 * have_chap_secret - check whether we have a CHAP file with a
tax 0:66300c77c6e9 1052 * secret that we could possibly use for authenticating `client'
tax 0:66300c77c6e9 1053 * on `server'. Either can be the null string, meaning we don't
tax 0:66300c77c6e9 1054 * know the identity yet.
tax 0:66300c77c6e9 1055 */
tax 0:66300c77c6e9 1056 static int
tax 0:66300c77c6e9 1057 have_chap_secret(char *client, char *server, u32_t remote)
tax 0:66300c77c6e9 1058 {
tax 0:66300c77c6e9 1059 LWIP_UNUSED_ARG(client);
tax 0:66300c77c6e9 1060 LWIP_UNUSED_ARG(server);
tax 0:66300c77c6e9 1061 LWIP_UNUSED_ARG(remote);
tax 0:66300c77c6e9 1062
tax 0:66300c77c6e9 1063 /* XXX Fail until we set up our passwords. */
tax 0:66300c77c6e9 1064 return 0;
tax 0:66300c77c6e9 1065 }
tax 0:66300c77c6e9 1066 #if CHAP_SUPPORT
tax 0:66300c77c6e9 1067
tax 0:66300c77c6e9 1068 /*
tax 0:66300c77c6e9 1069 * get_secret - open the CHAP secret file and return the secret
tax 0:66300c77c6e9 1070 * for authenticating the given client on the given server.
tax 0:66300c77c6e9 1071 * (We could be either client or server).
tax 0:66300c77c6e9 1072 */
tax 0:66300c77c6e9 1073 int
tax 0:66300c77c6e9 1074 get_secret(int unit, char *client, char *server, char *secret, int *secret_len, int save_addrs)
tax 0:66300c77c6e9 1075 {
tax 0:66300c77c6e9 1076 #if 1
tax 0:66300c77c6e9 1077 int len;
tax 0:66300c77c6e9 1078 struct wordlist *addrs;
tax 0:66300c77c6e9 1079
tax 0:66300c77c6e9 1080 LWIP_UNUSED_ARG(unit);
tax 0:66300c77c6e9 1081 LWIP_UNUSED_ARG(server);
tax 0:66300c77c6e9 1082 LWIP_UNUSED_ARG(save_addrs);
tax 0:66300c77c6e9 1083
tax 0:66300c77c6e9 1084 addrs = NULL;
tax 0:66300c77c6e9 1085
tax 0:66300c77c6e9 1086 if(!client || !client[0] || strcmp(client, ppp_settings.user)) {
tax 0:66300c77c6e9 1087 return 0;
tax 0:66300c77c6e9 1088 }
tax 0:66300c77c6e9 1089
tax 0:66300c77c6e9 1090 len = (int)strlen(ppp_settings.passwd);
tax 0:66300c77c6e9 1091 if (len > MAXSECRETLEN) {
tax 0:66300c77c6e9 1092 AUTHDEBUG(LOG_ERR, ("Secret for %s on %s is too long\n", client, server));
tax 0:66300c77c6e9 1093 len = MAXSECRETLEN;
tax 0:66300c77c6e9 1094 }
tax 0:66300c77c6e9 1095
tax 0:66300c77c6e9 1096 BCOPY(ppp_settings.passwd, secret, len);
tax 0:66300c77c6e9 1097 *secret_len = len;
tax 0:66300c77c6e9 1098
tax 0:66300c77c6e9 1099 return 1;
tax 0:66300c77c6e9 1100 #else
tax 0:66300c77c6e9 1101 int ret = 0, len;
tax 0:66300c77c6e9 1102 struct wordlist *addrs;
tax 0:66300c77c6e9 1103 char secbuf[MAXWORDLEN];
tax 0:66300c77c6e9 1104
tax 0:66300c77c6e9 1105 addrs = NULL;
tax 0:66300c77c6e9 1106 secbuf[0] = 0;
tax 0:66300c77c6e9 1107
tax 0:66300c77c6e9 1108 /* XXX Find secret. */
tax 0:66300c77c6e9 1109 if (ret < 0) {
tax 0:66300c77c6e9 1110 return 0;
tax 0:66300c77c6e9 1111 }
tax 0:66300c77c6e9 1112
tax 0:66300c77c6e9 1113 if (save_addrs) {
tax 0:66300c77c6e9 1114 set_allowed_addrs(unit, addrs);
tax 0:66300c77c6e9 1115 }
tax 0:66300c77c6e9 1116
tax 0:66300c77c6e9 1117 len = strlen(secbuf);
tax 0:66300c77c6e9 1118 if (len > MAXSECRETLEN) {
tax 0:66300c77c6e9 1119 AUTHDEBUG(LOG_ERR, ("Secret for %s on %s is too long\n", client, server));
tax 0:66300c77c6e9 1120 len = MAXSECRETLEN;
tax 0:66300c77c6e9 1121 }
tax 0:66300c77c6e9 1122
tax 0:66300c77c6e9 1123 BCOPY(secbuf, secret, len);
tax 0:66300c77c6e9 1124 BZERO(secbuf, sizeof(secbuf));
tax 0:66300c77c6e9 1125 *secret_len = len;
tax 0:66300c77c6e9 1126
tax 0:66300c77c6e9 1127 return 1;
tax 0:66300c77c6e9 1128 #endif
tax 0:66300c77c6e9 1129 }
tax 0:66300c77c6e9 1130 #endif /* CHAP_SUPPORT */
tax 0:66300c77c6e9 1131
tax 0:66300c77c6e9 1132
tax 0:66300c77c6e9 1133 #if 0 /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 1134 /*
tax 0:66300c77c6e9 1135 * set_allowed_addrs() - set the list of allowed addresses.
tax 0:66300c77c6e9 1136 */
tax 0:66300c77c6e9 1137 static void
tax 0:66300c77c6e9 1138 set_allowed_addrs(int unit, struct wordlist *addrs)
tax 0:66300c77c6e9 1139 {
tax 0:66300c77c6e9 1140 if (addresses[unit] != NULL) {
tax 0:66300c77c6e9 1141 free_wordlist(addresses[unit]);
tax 0:66300c77c6e9 1142 }
tax 0:66300c77c6e9 1143 addresses[unit] = addrs;
tax 0:66300c77c6e9 1144
tax 0:66300c77c6e9 1145 #if 0
tax 0:66300c77c6e9 1146 /*
tax 0:66300c77c6e9 1147 * If there's only one authorized address we might as well
tax 0:66300c77c6e9 1148 * ask our peer for that one right away
tax 0:66300c77c6e9 1149 */
tax 0:66300c77c6e9 1150 if (addrs != NULL && addrs->next == NULL) {
tax 0:66300c77c6e9 1151 char *p = addrs->word;
tax 0:66300c77c6e9 1152 struct ipcp_options *wo = &ipcp_wantoptions[unit];
tax 0:66300c77c6e9 1153 u32_t a;
tax 0:66300c77c6e9 1154 struct hostent *hp;
tax 0:66300c77c6e9 1155
tax 0:66300c77c6e9 1156 if (wo->hisaddr == 0 && *p != '!' && *p != '-' && strchr(p, '/') == NULL) {
tax 0:66300c77c6e9 1157 hp = gethostbyname(p);
tax 0:66300c77c6e9 1158 if (hp != NULL && hp->h_addrtype == AF_INET) {
tax 0:66300c77c6e9 1159 a = *(u32_t *)hp->h_addr;
tax 0:66300c77c6e9 1160 } else {
tax 0:66300c77c6e9 1161 a = inet_addr(p);
tax 0:66300c77c6e9 1162 }
tax 0:66300c77c6e9 1163 if (a != (u32_t) -1) {
tax 0:66300c77c6e9 1164 wo->hisaddr = a;
tax 0:66300c77c6e9 1165 }
tax 0:66300c77c6e9 1166 }
tax 0:66300c77c6e9 1167 }
tax 0:66300c77c6e9 1168 #endif
tax 0:66300c77c6e9 1169 }
tax 0:66300c77c6e9 1170 #endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 1171
tax 0:66300c77c6e9 1172 /*
tax 0:66300c77c6e9 1173 * auth_ip_addr - check whether the peer is authorized to use
tax 0:66300c77c6e9 1174 * a given IP address. Returns 1 if authorized, 0 otherwise.
tax 0:66300c77c6e9 1175 */
tax 0:66300c77c6e9 1176 int
tax 0:66300c77c6e9 1177 auth_ip_addr(int unit, u32_t addr)
tax 0:66300c77c6e9 1178 {
tax 0:66300c77c6e9 1179 return ip_addr_check(addr, addresses[unit]);
tax 0:66300c77c6e9 1180 }
tax 0:66300c77c6e9 1181
tax 0:66300c77c6e9 1182 static int /* @todo: integrate this funtion into auth_ip_addr()*/
tax 0:66300c77c6e9 1183 ip_addr_check(u32_t addr, struct wordlist *addrs)
tax 0:66300c77c6e9 1184 {
tax 0:66300c77c6e9 1185 /* don't allow loopback or multicast address */
tax 0:66300c77c6e9 1186 if (bad_ip_adrs(addr)) {
tax 0:66300c77c6e9 1187 return 0;
tax 0:66300c77c6e9 1188 }
tax 0:66300c77c6e9 1189
tax 0:66300c77c6e9 1190 if (addrs == NULL) {
tax 0:66300c77c6e9 1191 return !ppp_settings.auth_required; /* no addresses authorized */
tax 0:66300c77c6e9 1192 }
tax 0:66300c77c6e9 1193
tax 0:66300c77c6e9 1194 /* XXX All other addresses allowed. */
tax 0:66300c77c6e9 1195 return 1;
tax 0:66300c77c6e9 1196 }
tax 0:66300c77c6e9 1197
tax 0:66300c77c6e9 1198 /*
tax 0:66300c77c6e9 1199 * bad_ip_adrs - return 1 if the IP address is one we don't want
tax 0:66300c77c6e9 1200 * to use, such as an address in the loopback net or a multicast address.
tax 0:66300c77c6e9 1201 * addr is in network byte order.
tax 0:66300c77c6e9 1202 */
tax 0:66300c77c6e9 1203 int
tax 0:66300c77c6e9 1204 bad_ip_adrs(u32_t addr)
tax 0:66300c77c6e9 1205 {
tax 0:66300c77c6e9 1206 addr = ntohl(addr);
tax 0:66300c77c6e9 1207 return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
tax 0:66300c77c6e9 1208 || IN_MULTICAST(addr) || IN_BADCLASS(addr);
tax 0:66300c77c6e9 1209 }
tax 0:66300c77c6e9 1210
tax 0:66300c77c6e9 1211 #if 0 /* UNUSED */ /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 1212 /*
tax 0:66300c77c6e9 1213 * some_ip_ok - check a wordlist to see if it authorizes any
tax 0:66300c77c6e9 1214 * IP address(es).
tax 0:66300c77c6e9 1215 */
tax 0:66300c77c6e9 1216 static int
tax 0:66300c77c6e9 1217 some_ip_ok(struct wordlist *addrs)
tax 0:66300c77c6e9 1218 {
tax 0:66300c77c6e9 1219 for (; addrs != 0; addrs = addrs->next) {
tax 0:66300c77c6e9 1220 if (addrs->word[0] == '-')
tax 0:66300c77c6e9 1221 break;
tax 0:66300c77c6e9 1222 if (addrs->word[0] != '!')
tax 0:66300c77c6e9 1223 return 1; /* some IP address is allowed */
tax 0:66300c77c6e9 1224 }
tax 0:66300c77c6e9 1225 return 0;
tax 0:66300c77c6e9 1226 }
tax 0:66300c77c6e9 1227
tax 0:66300c77c6e9 1228 /*
tax 0:66300c77c6e9 1229 * check_access - complain if a secret file has too-liberal permissions.
tax 0:66300c77c6e9 1230 */
tax 0:66300c77c6e9 1231 static void
tax 0:66300c77c6e9 1232 check_access(FILE *f, char *filename)
tax 0:66300c77c6e9 1233 {
tax 0:66300c77c6e9 1234 struct stat sbuf;
tax 0:66300c77c6e9 1235
tax 0:66300c77c6e9 1236 if (fstat(fileno(f), &sbuf) < 0) {
tax 0:66300c77c6e9 1237 warn("cannot stat secret file %s: %m", filename);
tax 0:66300c77c6e9 1238 } else if ((sbuf.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
tax 0:66300c77c6e9 1239 warn("Warning - secret file %s has world and/or group access",
tax 0:66300c77c6e9 1240 filename);
tax 0:66300c77c6e9 1241 }
tax 0:66300c77c6e9 1242 }
tax 0:66300c77c6e9 1243
tax 0:66300c77c6e9 1244
tax 0:66300c77c6e9 1245 /*
tax 0:66300c77c6e9 1246 * scan_authfile - Scan an authorization file for a secret suitable
tax 0:66300c77c6e9 1247 * for authenticating `client' on `server'. The return value is -1
tax 0:66300c77c6e9 1248 * if no secret is found, otherwise >= 0. The return value has
tax 0:66300c77c6e9 1249 * NONWILD_CLIENT set if the secret didn't have "*" for the client, and
tax 0:66300c77c6e9 1250 * NONWILD_SERVER set if the secret didn't have "*" for the server.
tax 0:66300c77c6e9 1251 * Any following words on the line up to a "--" (i.e. address authorization
tax 0:66300c77c6e9 1252 * info) are placed in a wordlist and returned in *addrs. Any
tax 0:66300c77c6e9 1253 * following words (extra options) are placed in a wordlist and
tax 0:66300c77c6e9 1254 * returned in *opts.
tax 0:66300c77c6e9 1255 * We assume secret is NULL or points to MAXWORDLEN bytes of space.
tax 0:66300c77c6e9 1256 */
tax 0:66300c77c6e9 1257 static int
tax 0:66300c77c6e9 1258 scan_authfile(FILE *f, char *client, char *server, char *secret, struct wordlist **addrs, struct wordlist **opts, char *filename)
tax 0:66300c77c6e9 1259 {
tax 0:66300c77c6e9 1260 /* We do not (currently) need this in lwip */
tax 0:66300c77c6e9 1261 return 0; /* dummy */
tax 0:66300c77c6e9 1262 }
tax 0:66300c77c6e9 1263 /*
tax 0:66300c77c6e9 1264 * free_wordlist - release memory allocated for a wordlist.
tax 0:66300c77c6e9 1265 */
tax 0:66300c77c6e9 1266 static void
tax 0:66300c77c6e9 1267 free_wordlist(struct wordlist *wp)
tax 0:66300c77c6e9 1268 {
tax 0:66300c77c6e9 1269 struct wordlist *next;
tax 0:66300c77c6e9 1270
tax 0:66300c77c6e9 1271 while (wp != NULL) {
tax 0:66300c77c6e9 1272 next = wp->next;
tax 0:66300c77c6e9 1273 free(wp);
tax 0:66300c77c6e9 1274 wp = next;
tax 0:66300c77c6e9 1275 }
tax 0:66300c77c6e9 1276 }
tax 0:66300c77c6e9 1277
tax 0:66300c77c6e9 1278 /*
tax 0:66300c77c6e9 1279 * auth_script_done - called when the auth-up or auth-down script
tax 0:66300c77c6e9 1280 * has finished.
tax 0:66300c77c6e9 1281 */
tax 0:66300c77c6e9 1282 static void
tax 0:66300c77c6e9 1283 auth_script_done(void *arg)
tax 0:66300c77c6e9 1284 {
tax 0:66300c77c6e9 1285 auth_script_pid = 0;
tax 0:66300c77c6e9 1286 switch (auth_script_state) {
tax 0:66300c77c6e9 1287 case s_up:
tax 0:66300c77c6e9 1288 if (auth_state == s_down) {
tax 0:66300c77c6e9 1289 auth_script_state = s_down;
tax 0:66300c77c6e9 1290 auth_script(_PATH_AUTHDOWN);
tax 0:66300c77c6e9 1291 }
tax 0:66300c77c6e9 1292 break;
tax 0:66300c77c6e9 1293 case s_down:
tax 0:66300c77c6e9 1294 if (auth_state == s_up) {
tax 0:66300c77c6e9 1295 auth_script_state = s_up;
tax 0:66300c77c6e9 1296 auth_script(_PATH_AUTHUP);
tax 0:66300c77c6e9 1297 }
tax 0:66300c77c6e9 1298 break;
tax 0:66300c77c6e9 1299 }
tax 0:66300c77c6e9 1300 }
tax 0:66300c77c6e9 1301
tax 0:66300c77c6e9 1302 /*
tax 0:66300c77c6e9 1303 * auth_script - execute a script with arguments
tax 0:66300c77c6e9 1304 * interface-name peer-name real-user tty speed
tax 0:66300c77c6e9 1305 */
tax 0:66300c77c6e9 1306 static void
tax 0:66300c77c6e9 1307 auth_script(char *script)
tax 0:66300c77c6e9 1308 {
tax 0:66300c77c6e9 1309 char strspeed[32];
tax 0:66300c77c6e9 1310 struct passwd *pw;
tax 0:66300c77c6e9 1311 char struid[32];
tax 0:66300c77c6e9 1312 char *user_name;
tax 0:66300c77c6e9 1313 char *argv[8];
tax 0:66300c77c6e9 1314
tax 0:66300c77c6e9 1315 if ((pw = getpwuid(getuid())) != NULL && pw->pw_name != NULL)
tax 0:66300c77c6e9 1316 user_name = pw->pw_name;
tax 0:66300c77c6e9 1317 else {
tax 0:66300c77c6e9 1318 slprintf(struid, sizeof(struid), "%d", getuid());
tax 0:66300c77c6e9 1319 user_name = struid;
tax 0:66300c77c6e9 1320 }
tax 0:66300c77c6e9 1321 slprintf(strspeed, sizeof(strspeed), "%d", baud_rate);
tax 0:66300c77c6e9 1322
tax 0:66300c77c6e9 1323 argv[0] = script;
tax 0:66300c77c6e9 1324 argv[1] = ifname;
tax 0:66300c77c6e9 1325 argv[2] = peer_authname;
tax 0:66300c77c6e9 1326 argv[3] = user_name;
tax 0:66300c77c6e9 1327 argv[4] = devnam;
tax 0:66300c77c6e9 1328 argv[5] = strspeed;
tax 0:66300c77c6e9 1329 argv[6] = NULL;
tax 0:66300c77c6e9 1330
tax 0:66300c77c6e9 1331 auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL);
tax 0:66300c77c6e9 1332 }
tax 0:66300c77c6e9 1333 #endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */
tax 0:66300c77c6e9 1334 #endif /* PPP_SUPPORT */