dev

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
yihui
Date:
Mon Mar 02 08:19:15 2015 +0000
Revision:
19:6c91d95ef874
Parent:
0:51ac1d130fd4
minor changes

Who changed what in which revision?

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