Experimental HTTPClient with proxy support

Committer:
igorsk
Date:
Wed Jun 29 16:01:58 2011 +0000
Revision:
0:b56b6a05cad4

        

Who changed what in which revision?

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