NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

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