Rod Coleman / NetServSB2
Committer:
RodColeman
Date:
Thu Sep 08 10:48:09 2011 +0000
Revision:
0:850eacf3e945
revised fixed length to 178 bytes

Who changed what in which revision?

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