Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

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