HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

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