Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

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