Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

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