Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

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