SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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