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