Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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