Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Wed Dec 15 18:01:30 2010 +0000
Revision:
7:4e2468d7d5cb
Parent:
0:ac1725ba162c

        

Who changed what in which revision?

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