Dependencies:   FatFileSystem mbed WeatherMeters SDFileSystem

Committer:
dcoban
Date:
Tue Apr 03 18:43:13 2012 +0000
Revision:
0:1a61c61d0845

        

Who changed what in which revision?

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