Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

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