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