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