Ethernetwebsoc
Dependencies: C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip
EthernetInterface/lwip/netif/ppp/pap.c@0:0ed2a7c7190c, 2013-05-31 (annotated)
- Committer:
- GordonSin
- Date:
- Fri May 31 04:09:54 2013 +0000
- Revision:
- 0:0ed2a7c7190c
31/5/2013;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GordonSin | 0:0ed2a7c7190c | 1 | /***************************************************************************** |
GordonSin | 0:0ed2a7c7190c | 2 | * pap.c - Network Password Authentication Protocol program file. |
GordonSin | 0:0ed2a7c7190c | 3 | * |
GordonSin | 0:0ed2a7c7190c | 4 | * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. |
GordonSin | 0:0ed2a7c7190c | 5 | * portions Copyright (c) 1997 by Global Election Systems Inc. |
GordonSin | 0:0ed2a7c7190c | 6 | * |
GordonSin | 0:0ed2a7c7190c | 7 | * The authors hereby grant permission to use, copy, modify, distribute, |
GordonSin | 0:0ed2a7c7190c | 8 | * and license this software and its documentation for any purpose, provided |
GordonSin | 0:0ed2a7c7190c | 9 | * that existing copyright notices are retained in all copies and that this |
GordonSin | 0:0ed2a7c7190c | 10 | * notice and the following disclaimer are included verbatim in any |
GordonSin | 0:0ed2a7c7190c | 11 | * distributions. No written agreement, license, or royalty fee is required |
GordonSin | 0:0ed2a7c7190c | 12 | * for any of the authorized uses. |
GordonSin | 0:0ed2a7c7190c | 13 | * |
GordonSin | 0:0ed2a7c7190c | 14 | * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR |
GordonSin | 0:0ed2a7c7190c | 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
GordonSin | 0:0ed2a7c7190c | 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
GordonSin | 0:0ed2a7c7190c | 17 | * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
GordonSin | 0:0ed2a7c7190c | 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
GordonSin | 0:0ed2a7c7190c | 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
GordonSin | 0:0ed2a7c7190c | 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
GordonSin | 0:0ed2a7c7190c | 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
GordonSin | 0:0ed2a7c7190c | 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
GordonSin | 0:0ed2a7c7190c | 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
GordonSin | 0:0ed2a7c7190c | 24 | * |
GordonSin | 0:0ed2a7c7190c | 25 | ****************************************************************************** |
GordonSin | 0:0ed2a7c7190c | 26 | * REVISION HISTORY |
GordonSin | 0:0ed2a7c7190c | 27 | * |
GordonSin | 0:0ed2a7c7190c | 28 | * 03-01-01 Marc Boucher <marc@mbsi.ca> |
GordonSin | 0:0ed2a7c7190c | 29 | * Ported to lwIP. |
GordonSin | 0:0ed2a7c7190c | 30 | * 97-12-12 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc. |
GordonSin | 0:0ed2a7c7190c | 31 | * Original. |
GordonSin | 0:0ed2a7c7190c | 32 | *****************************************************************************/ |
GordonSin | 0:0ed2a7c7190c | 33 | /* |
GordonSin | 0:0ed2a7c7190c | 34 | * upap.c - User/Password Authentication Protocol. |
GordonSin | 0:0ed2a7c7190c | 35 | * |
GordonSin | 0:0ed2a7c7190c | 36 | * Copyright (c) 1989 Carnegie Mellon University. |
GordonSin | 0:0ed2a7c7190c | 37 | * All rights reserved. |
GordonSin | 0:0ed2a7c7190c | 38 | * |
GordonSin | 0:0ed2a7c7190c | 39 | * Redistribution and use in source and binary forms are permitted |
GordonSin | 0:0ed2a7c7190c | 40 | * provided that the above copyright notice and this paragraph are |
GordonSin | 0:0ed2a7c7190c | 41 | * duplicated in all such forms and that any documentation, |
GordonSin | 0:0ed2a7c7190c | 42 | * advertising materials, and other materials related to such |
GordonSin | 0:0ed2a7c7190c | 43 | * distribution and use acknowledge that the software was developed |
GordonSin | 0:0ed2a7c7190c | 44 | * by Carnegie Mellon University. The name of the |
GordonSin | 0:0ed2a7c7190c | 45 | * University may not be used to endorse or promote products derived |
GordonSin | 0:0ed2a7c7190c | 46 | * from this software without specific prior written permission. |
GordonSin | 0:0ed2a7c7190c | 47 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
GordonSin | 0:0ed2a7c7190c | 48 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
GordonSin | 0:0ed2a7c7190c | 49 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
GordonSin | 0:0ed2a7c7190c | 50 | */ |
GordonSin | 0:0ed2a7c7190c | 51 | |
GordonSin | 0:0ed2a7c7190c | 52 | #include "lwip/opt.h" |
GordonSin | 0:0ed2a7c7190c | 53 | |
GordonSin | 0:0ed2a7c7190c | 54 | #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ |
GordonSin | 0:0ed2a7c7190c | 55 | |
GordonSin | 0:0ed2a7c7190c | 56 | #if PAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ |
GordonSin | 0:0ed2a7c7190c | 57 | |
GordonSin | 0:0ed2a7c7190c | 58 | #include "ppp.h" |
GordonSin | 0:0ed2a7c7190c | 59 | #include "pppdebug.h" |
GordonSin | 0:0ed2a7c7190c | 60 | |
GordonSin | 0:0ed2a7c7190c | 61 | #include "auth.h" |
GordonSin | 0:0ed2a7c7190c | 62 | #include "pap.h" |
GordonSin | 0:0ed2a7c7190c | 63 | |
GordonSin | 0:0ed2a7c7190c | 64 | #include <string.h> |
GordonSin | 0:0ed2a7c7190c | 65 | |
GordonSin | 0:0ed2a7c7190c | 66 | #if 0 /* UNUSED */ |
GordonSin | 0:0ed2a7c7190c | 67 | static bool hide_password = 1; |
GordonSin | 0:0ed2a7c7190c | 68 | |
GordonSin | 0:0ed2a7c7190c | 69 | /* |
GordonSin | 0:0ed2a7c7190c | 70 | * Command-line options. |
GordonSin | 0:0ed2a7c7190c | 71 | */ |
GordonSin | 0:0ed2a7c7190c | 72 | static option_t pap_option_list[] = { |
GordonSin | 0:0ed2a7c7190c | 73 | { "hide-password", o_bool, &hide_password, |
GordonSin | 0:0ed2a7c7190c | 74 | "Don't output passwords to log", 1 }, |
GordonSin | 0:0ed2a7c7190c | 75 | { "show-password", o_bool, &hide_password, |
GordonSin | 0:0ed2a7c7190c | 76 | "Show password string in debug log messages", 0 }, |
GordonSin | 0:0ed2a7c7190c | 77 | { "pap-restart", o_int, &upap[0].us_timeouttime, |
GordonSin | 0:0ed2a7c7190c | 78 | "Set retransmit timeout for PAP" }, |
GordonSin | 0:0ed2a7c7190c | 79 | { "pap-max-authreq", o_int, &upap[0].us_maxtransmits, |
GordonSin | 0:0ed2a7c7190c | 80 | "Set max number of transmissions for auth-reqs" }, |
GordonSin | 0:0ed2a7c7190c | 81 | { "pap-timeout", o_int, &upap[0].us_reqtimeout, |
GordonSin | 0:0ed2a7c7190c | 82 | "Set time limit for peer PAP authentication" }, |
GordonSin | 0:0ed2a7c7190c | 83 | { NULL } |
GordonSin | 0:0ed2a7c7190c | 84 | }; |
GordonSin | 0:0ed2a7c7190c | 85 | #endif |
GordonSin | 0:0ed2a7c7190c | 86 | |
GordonSin | 0:0ed2a7c7190c | 87 | /* |
GordonSin | 0:0ed2a7c7190c | 88 | * Protocol entry points. |
GordonSin | 0:0ed2a7c7190c | 89 | */ |
GordonSin | 0:0ed2a7c7190c | 90 | static void upap_init (int); |
GordonSin | 0:0ed2a7c7190c | 91 | static void upap_lowerup (int); |
GordonSin | 0:0ed2a7c7190c | 92 | static void upap_lowerdown (int); |
GordonSin | 0:0ed2a7c7190c | 93 | static void upap_input (int, u_char *, int); |
GordonSin | 0:0ed2a7c7190c | 94 | static void upap_protrej (int); |
GordonSin | 0:0ed2a7c7190c | 95 | #if PPP_ADDITIONAL_CALLBACKS |
GordonSin | 0:0ed2a7c7190c | 96 | static int upap_printpkt (u_char *, int, void (*)(void *, char *, ...), void *); |
GordonSin | 0:0ed2a7c7190c | 97 | #endif /* PPP_ADDITIONAL_CALLBACKS */ |
GordonSin | 0:0ed2a7c7190c | 98 | |
GordonSin | 0:0ed2a7c7190c | 99 | struct protent pap_protent = { |
GordonSin | 0:0ed2a7c7190c | 100 | PPP_PAP, |
GordonSin | 0:0ed2a7c7190c | 101 | upap_init, |
GordonSin | 0:0ed2a7c7190c | 102 | upap_input, |
GordonSin | 0:0ed2a7c7190c | 103 | upap_protrej, |
GordonSin | 0:0ed2a7c7190c | 104 | upap_lowerup, |
GordonSin | 0:0ed2a7c7190c | 105 | upap_lowerdown, |
GordonSin | 0:0ed2a7c7190c | 106 | NULL, |
GordonSin | 0:0ed2a7c7190c | 107 | NULL, |
GordonSin | 0:0ed2a7c7190c | 108 | #if PPP_ADDITIONAL_CALLBACKS |
GordonSin | 0:0ed2a7c7190c | 109 | upap_printpkt, |
GordonSin | 0:0ed2a7c7190c | 110 | NULL, |
GordonSin | 0:0ed2a7c7190c | 111 | #endif /* PPP_ADDITIONAL_CALLBACKS */ |
GordonSin | 0:0ed2a7c7190c | 112 | 1, |
GordonSin | 0:0ed2a7c7190c | 113 | "PAP", |
GordonSin | 0:0ed2a7c7190c | 114 | #if PPP_ADDITIONAL_CALLBACKS |
GordonSin | 0:0ed2a7c7190c | 115 | NULL, |
GordonSin | 0:0ed2a7c7190c | 116 | NULL, |
GordonSin | 0:0ed2a7c7190c | 117 | NULL |
GordonSin | 0:0ed2a7c7190c | 118 | #endif /* PPP_ADDITIONAL_CALLBACKS */ |
GordonSin | 0:0ed2a7c7190c | 119 | }; |
GordonSin | 0:0ed2a7c7190c | 120 | |
GordonSin | 0:0ed2a7c7190c | 121 | upap_state upap[NUM_PPP]; /* UPAP state; one for each unit */ |
GordonSin | 0:0ed2a7c7190c | 122 | |
GordonSin | 0:0ed2a7c7190c | 123 | static void upap_timeout (void *); |
GordonSin | 0:0ed2a7c7190c | 124 | static void upap_reqtimeout(void *); |
GordonSin | 0:0ed2a7c7190c | 125 | static void upap_rauthreq (upap_state *, u_char *, u_char, int); |
GordonSin | 0:0ed2a7c7190c | 126 | static void upap_rauthack (upap_state *, u_char *, int, int); |
GordonSin | 0:0ed2a7c7190c | 127 | static void upap_rauthnak (upap_state *, u_char *, int, int); |
GordonSin | 0:0ed2a7c7190c | 128 | static void upap_sauthreq (upap_state *); |
GordonSin | 0:0ed2a7c7190c | 129 | static void upap_sresp (upap_state *, u_char, u_char, char *, int); |
GordonSin | 0:0ed2a7c7190c | 130 | |
GordonSin | 0:0ed2a7c7190c | 131 | |
GordonSin | 0:0ed2a7c7190c | 132 | /* |
GordonSin | 0:0ed2a7c7190c | 133 | * upap_init - Initialize a UPAP unit. |
GordonSin | 0:0ed2a7c7190c | 134 | */ |
GordonSin | 0:0ed2a7c7190c | 135 | static void |
GordonSin | 0:0ed2a7c7190c | 136 | upap_init(int unit) |
GordonSin | 0:0ed2a7c7190c | 137 | { |
GordonSin | 0:0ed2a7c7190c | 138 | upap_state *u = &upap[unit]; |
GordonSin | 0:0ed2a7c7190c | 139 | |
GordonSin | 0:0ed2a7c7190c | 140 | UPAPDEBUG(LOG_INFO, ("upap_init: %d\n", unit)); |
GordonSin | 0:0ed2a7c7190c | 141 | u->us_unit = unit; |
GordonSin | 0:0ed2a7c7190c | 142 | u->us_user = NULL; |
GordonSin | 0:0ed2a7c7190c | 143 | u->us_userlen = 0; |
GordonSin | 0:0ed2a7c7190c | 144 | u->us_passwd = NULL; |
GordonSin | 0:0ed2a7c7190c | 145 | u->us_passwdlen = 0; |
GordonSin | 0:0ed2a7c7190c | 146 | u->us_clientstate = UPAPCS_INITIAL; |
GordonSin | 0:0ed2a7c7190c | 147 | u->us_serverstate = UPAPSS_INITIAL; |
GordonSin | 0:0ed2a7c7190c | 148 | u->us_id = 0; |
GordonSin | 0:0ed2a7c7190c | 149 | u->us_timeouttime = UPAP_DEFTIMEOUT; |
GordonSin | 0:0ed2a7c7190c | 150 | u->us_maxtransmits = 10; |
GordonSin | 0:0ed2a7c7190c | 151 | u->us_reqtimeout = UPAP_DEFREQTIME; |
GordonSin | 0:0ed2a7c7190c | 152 | } |
GordonSin | 0:0ed2a7c7190c | 153 | |
GordonSin | 0:0ed2a7c7190c | 154 | /* |
GordonSin | 0:0ed2a7c7190c | 155 | * upap_authwithpeer - Authenticate us with our peer (start client). |
GordonSin | 0:0ed2a7c7190c | 156 | * |
GordonSin | 0:0ed2a7c7190c | 157 | * Set new state and send authenticate's. |
GordonSin | 0:0ed2a7c7190c | 158 | */ |
GordonSin | 0:0ed2a7c7190c | 159 | void |
GordonSin | 0:0ed2a7c7190c | 160 | upap_authwithpeer(int unit, char *user, char *password) |
GordonSin | 0:0ed2a7c7190c | 161 | { |
GordonSin | 0:0ed2a7c7190c | 162 | upap_state *u = &upap[unit]; |
GordonSin | 0:0ed2a7c7190c | 163 | |
GordonSin | 0:0ed2a7c7190c | 164 | UPAPDEBUG(LOG_INFO, ("upap_authwithpeer: %d user=%s password=%s s=%d\n", |
GordonSin | 0:0ed2a7c7190c | 165 | unit, user, password, u->us_clientstate)); |
GordonSin | 0:0ed2a7c7190c | 166 | |
GordonSin | 0:0ed2a7c7190c | 167 | /* Save the username and password we're given */ |
GordonSin | 0:0ed2a7c7190c | 168 | u->us_user = user; |
GordonSin | 0:0ed2a7c7190c | 169 | u->us_userlen = (int)strlen(user); |
GordonSin | 0:0ed2a7c7190c | 170 | u->us_passwd = password; |
GordonSin | 0:0ed2a7c7190c | 171 | u->us_passwdlen = (int)strlen(password); |
GordonSin | 0:0ed2a7c7190c | 172 | |
GordonSin | 0:0ed2a7c7190c | 173 | u->us_transmits = 0; |
GordonSin | 0:0ed2a7c7190c | 174 | |
GordonSin | 0:0ed2a7c7190c | 175 | /* Lower layer up yet? */ |
GordonSin | 0:0ed2a7c7190c | 176 | if (u->us_clientstate == UPAPCS_INITIAL || |
GordonSin | 0:0ed2a7c7190c | 177 | u->us_clientstate == UPAPCS_PENDING) { |
GordonSin | 0:0ed2a7c7190c | 178 | u->us_clientstate = UPAPCS_PENDING; |
GordonSin | 0:0ed2a7c7190c | 179 | return; |
GordonSin | 0:0ed2a7c7190c | 180 | } |
GordonSin | 0:0ed2a7c7190c | 181 | |
GordonSin | 0:0ed2a7c7190c | 182 | upap_sauthreq(u); /* Start protocol */ |
GordonSin | 0:0ed2a7c7190c | 183 | } |
GordonSin | 0:0ed2a7c7190c | 184 | |
GordonSin | 0:0ed2a7c7190c | 185 | |
GordonSin | 0:0ed2a7c7190c | 186 | /* |
GordonSin | 0:0ed2a7c7190c | 187 | * upap_authpeer - Authenticate our peer (start server). |
GordonSin | 0:0ed2a7c7190c | 188 | * |
GordonSin | 0:0ed2a7c7190c | 189 | * Set new state. |
GordonSin | 0:0ed2a7c7190c | 190 | */ |
GordonSin | 0:0ed2a7c7190c | 191 | void |
GordonSin | 0:0ed2a7c7190c | 192 | upap_authpeer(int unit) |
GordonSin | 0:0ed2a7c7190c | 193 | { |
GordonSin | 0:0ed2a7c7190c | 194 | upap_state *u = &upap[unit]; |
GordonSin | 0:0ed2a7c7190c | 195 | |
GordonSin | 0:0ed2a7c7190c | 196 | /* Lower layer up yet? */ |
GordonSin | 0:0ed2a7c7190c | 197 | if (u->us_serverstate == UPAPSS_INITIAL || |
GordonSin | 0:0ed2a7c7190c | 198 | u->us_serverstate == UPAPSS_PENDING) { |
GordonSin | 0:0ed2a7c7190c | 199 | u->us_serverstate = UPAPSS_PENDING; |
GordonSin | 0:0ed2a7c7190c | 200 | return; |
GordonSin | 0:0ed2a7c7190c | 201 | } |
GordonSin | 0:0ed2a7c7190c | 202 | |
GordonSin | 0:0ed2a7c7190c | 203 | u->us_serverstate = UPAPSS_LISTEN; |
GordonSin | 0:0ed2a7c7190c | 204 | if (u->us_reqtimeout > 0) { |
GordonSin | 0:0ed2a7c7190c | 205 | TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout); |
GordonSin | 0:0ed2a7c7190c | 206 | } |
GordonSin | 0:0ed2a7c7190c | 207 | } |
GordonSin | 0:0ed2a7c7190c | 208 | |
GordonSin | 0:0ed2a7c7190c | 209 | /* |
GordonSin | 0:0ed2a7c7190c | 210 | * upap_timeout - Retransmission timer for sending auth-reqs expired. |
GordonSin | 0:0ed2a7c7190c | 211 | */ |
GordonSin | 0:0ed2a7c7190c | 212 | static void |
GordonSin | 0:0ed2a7c7190c | 213 | upap_timeout(void *arg) |
GordonSin | 0:0ed2a7c7190c | 214 | { |
GordonSin | 0:0ed2a7c7190c | 215 | upap_state *u = (upap_state *) arg; |
GordonSin | 0:0ed2a7c7190c | 216 | |
GordonSin | 0:0ed2a7c7190c | 217 | UPAPDEBUG(LOG_INFO, ("upap_timeout: %d timeout %d expired s=%d\n", |
GordonSin | 0:0ed2a7c7190c | 218 | u->us_unit, u->us_timeouttime, u->us_clientstate)); |
GordonSin | 0:0ed2a7c7190c | 219 | |
GordonSin | 0:0ed2a7c7190c | 220 | if (u->us_clientstate != UPAPCS_AUTHREQ) { |
GordonSin | 0:0ed2a7c7190c | 221 | UPAPDEBUG(LOG_INFO, ("upap_timeout: not in AUTHREQ state!\n")); |
GordonSin | 0:0ed2a7c7190c | 222 | return; |
GordonSin | 0:0ed2a7c7190c | 223 | } |
GordonSin | 0:0ed2a7c7190c | 224 | |
GordonSin | 0:0ed2a7c7190c | 225 | if (u->us_transmits >= u->us_maxtransmits) { |
GordonSin | 0:0ed2a7c7190c | 226 | /* give up in disgust */ |
GordonSin | 0:0ed2a7c7190c | 227 | UPAPDEBUG(LOG_ERR, ("No response to PAP authenticate-requests\n")); |
GordonSin | 0:0ed2a7c7190c | 228 | u->us_clientstate = UPAPCS_BADAUTH; |
GordonSin | 0:0ed2a7c7190c | 229 | auth_withpeer_fail(u->us_unit, PPP_PAP); |
GordonSin | 0:0ed2a7c7190c | 230 | return; |
GordonSin | 0:0ed2a7c7190c | 231 | } |
GordonSin | 0:0ed2a7c7190c | 232 | |
GordonSin | 0:0ed2a7c7190c | 233 | upap_sauthreq(u); /* Send Authenticate-Request and set upap timeout*/ |
GordonSin | 0:0ed2a7c7190c | 234 | } |
GordonSin | 0:0ed2a7c7190c | 235 | |
GordonSin | 0:0ed2a7c7190c | 236 | |
GordonSin | 0:0ed2a7c7190c | 237 | /* |
GordonSin | 0:0ed2a7c7190c | 238 | * upap_reqtimeout - Give up waiting for the peer to send an auth-req. |
GordonSin | 0:0ed2a7c7190c | 239 | */ |
GordonSin | 0:0ed2a7c7190c | 240 | static void |
GordonSin | 0:0ed2a7c7190c | 241 | upap_reqtimeout(void *arg) |
GordonSin | 0:0ed2a7c7190c | 242 | { |
GordonSin | 0:0ed2a7c7190c | 243 | upap_state *u = (upap_state *) arg; |
GordonSin | 0:0ed2a7c7190c | 244 | |
GordonSin | 0:0ed2a7c7190c | 245 | if (u->us_serverstate != UPAPSS_LISTEN) { |
GordonSin | 0:0ed2a7c7190c | 246 | return; /* huh?? */ |
GordonSin | 0:0ed2a7c7190c | 247 | } |
GordonSin | 0:0ed2a7c7190c | 248 | |
GordonSin | 0:0ed2a7c7190c | 249 | auth_peer_fail(u->us_unit, PPP_PAP); |
GordonSin | 0:0ed2a7c7190c | 250 | u->us_serverstate = UPAPSS_BADAUTH; |
GordonSin | 0:0ed2a7c7190c | 251 | } |
GordonSin | 0:0ed2a7c7190c | 252 | |
GordonSin | 0:0ed2a7c7190c | 253 | |
GordonSin | 0:0ed2a7c7190c | 254 | /* |
GordonSin | 0:0ed2a7c7190c | 255 | * upap_lowerup - The lower layer is up. |
GordonSin | 0:0ed2a7c7190c | 256 | * |
GordonSin | 0:0ed2a7c7190c | 257 | * Start authenticating if pending. |
GordonSin | 0:0ed2a7c7190c | 258 | */ |
GordonSin | 0:0ed2a7c7190c | 259 | static void |
GordonSin | 0:0ed2a7c7190c | 260 | upap_lowerup(int unit) |
GordonSin | 0:0ed2a7c7190c | 261 | { |
GordonSin | 0:0ed2a7c7190c | 262 | upap_state *u = &upap[unit]; |
GordonSin | 0:0ed2a7c7190c | 263 | |
GordonSin | 0:0ed2a7c7190c | 264 | UPAPDEBUG(LOG_INFO, ("upap_lowerup: init %d clientstate s=%d\n", unit, u->us_clientstate)); |
GordonSin | 0:0ed2a7c7190c | 265 | |
GordonSin | 0:0ed2a7c7190c | 266 | if (u->us_clientstate == UPAPCS_INITIAL) { |
GordonSin | 0:0ed2a7c7190c | 267 | u->us_clientstate = UPAPCS_CLOSED; |
GordonSin | 0:0ed2a7c7190c | 268 | } else if (u->us_clientstate == UPAPCS_PENDING) { |
GordonSin | 0:0ed2a7c7190c | 269 | upap_sauthreq(u); /* send an auth-request */ |
GordonSin | 0:0ed2a7c7190c | 270 | /* now client state is UPAPCS__AUTHREQ */ |
GordonSin | 0:0ed2a7c7190c | 271 | } |
GordonSin | 0:0ed2a7c7190c | 272 | |
GordonSin | 0:0ed2a7c7190c | 273 | if (u->us_serverstate == UPAPSS_INITIAL) { |
GordonSin | 0:0ed2a7c7190c | 274 | u->us_serverstate = UPAPSS_CLOSED; |
GordonSin | 0:0ed2a7c7190c | 275 | } else if (u->us_serverstate == UPAPSS_PENDING) { |
GordonSin | 0:0ed2a7c7190c | 276 | u->us_serverstate = UPAPSS_LISTEN; |
GordonSin | 0:0ed2a7c7190c | 277 | if (u->us_reqtimeout > 0) { |
GordonSin | 0:0ed2a7c7190c | 278 | TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout); |
GordonSin | 0:0ed2a7c7190c | 279 | } |
GordonSin | 0:0ed2a7c7190c | 280 | } |
GordonSin | 0:0ed2a7c7190c | 281 | } |
GordonSin | 0:0ed2a7c7190c | 282 | |
GordonSin | 0:0ed2a7c7190c | 283 | |
GordonSin | 0:0ed2a7c7190c | 284 | /* |
GordonSin | 0:0ed2a7c7190c | 285 | * upap_lowerdown - The lower layer is down. |
GordonSin | 0:0ed2a7c7190c | 286 | * |
GordonSin | 0:0ed2a7c7190c | 287 | * Cancel all timeouts. |
GordonSin | 0:0ed2a7c7190c | 288 | */ |
GordonSin | 0:0ed2a7c7190c | 289 | static void |
GordonSin | 0:0ed2a7c7190c | 290 | upap_lowerdown(int unit) |
GordonSin | 0:0ed2a7c7190c | 291 | { |
GordonSin | 0:0ed2a7c7190c | 292 | upap_state *u = &upap[unit]; |
GordonSin | 0:0ed2a7c7190c | 293 | |
GordonSin | 0:0ed2a7c7190c | 294 | UPAPDEBUG(LOG_INFO, ("upap_lowerdown: %d s=%d\n", unit, u->us_clientstate)); |
GordonSin | 0:0ed2a7c7190c | 295 | |
GordonSin | 0:0ed2a7c7190c | 296 | if (u->us_clientstate == UPAPCS_AUTHREQ) { /* Timeout pending? */ |
GordonSin | 0:0ed2a7c7190c | 297 | UNTIMEOUT(upap_timeout, u); /* Cancel timeout */ |
GordonSin | 0:0ed2a7c7190c | 298 | } |
GordonSin | 0:0ed2a7c7190c | 299 | if (u->us_serverstate == UPAPSS_LISTEN && u->us_reqtimeout > 0) { |
GordonSin | 0:0ed2a7c7190c | 300 | UNTIMEOUT(upap_reqtimeout, u); |
GordonSin | 0:0ed2a7c7190c | 301 | } |
GordonSin | 0:0ed2a7c7190c | 302 | |
GordonSin | 0:0ed2a7c7190c | 303 | u->us_clientstate = UPAPCS_INITIAL; |
GordonSin | 0:0ed2a7c7190c | 304 | u->us_serverstate = UPAPSS_INITIAL; |
GordonSin | 0:0ed2a7c7190c | 305 | } |
GordonSin | 0:0ed2a7c7190c | 306 | |
GordonSin | 0:0ed2a7c7190c | 307 | |
GordonSin | 0:0ed2a7c7190c | 308 | /* |
GordonSin | 0:0ed2a7c7190c | 309 | * upap_protrej - Peer doesn't speak this protocol. |
GordonSin | 0:0ed2a7c7190c | 310 | * |
GordonSin | 0:0ed2a7c7190c | 311 | * This shouldn't happen. In any case, pretend lower layer went down. |
GordonSin | 0:0ed2a7c7190c | 312 | */ |
GordonSin | 0:0ed2a7c7190c | 313 | static void |
GordonSin | 0:0ed2a7c7190c | 314 | upap_protrej(int unit) |
GordonSin | 0:0ed2a7c7190c | 315 | { |
GordonSin | 0:0ed2a7c7190c | 316 | upap_state *u = &upap[unit]; |
GordonSin | 0:0ed2a7c7190c | 317 | |
GordonSin | 0:0ed2a7c7190c | 318 | if (u->us_clientstate == UPAPCS_AUTHREQ) { |
GordonSin | 0:0ed2a7c7190c | 319 | UPAPDEBUG(LOG_ERR, ("PAP authentication failed due to protocol-reject\n")); |
GordonSin | 0:0ed2a7c7190c | 320 | auth_withpeer_fail(unit, PPP_PAP); |
GordonSin | 0:0ed2a7c7190c | 321 | } |
GordonSin | 0:0ed2a7c7190c | 322 | if (u->us_serverstate == UPAPSS_LISTEN) { |
GordonSin | 0:0ed2a7c7190c | 323 | UPAPDEBUG(LOG_ERR, ("PAP authentication of peer failed (protocol-reject)\n")); |
GordonSin | 0:0ed2a7c7190c | 324 | auth_peer_fail(unit, PPP_PAP); |
GordonSin | 0:0ed2a7c7190c | 325 | } |
GordonSin | 0:0ed2a7c7190c | 326 | upap_lowerdown(unit); |
GordonSin | 0:0ed2a7c7190c | 327 | } |
GordonSin | 0:0ed2a7c7190c | 328 | |
GordonSin | 0:0ed2a7c7190c | 329 | |
GordonSin | 0:0ed2a7c7190c | 330 | /* |
GordonSin | 0:0ed2a7c7190c | 331 | * upap_input - Input UPAP packet. |
GordonSin | 0:0ed2a7c7190c | 332 | */ |
GordonSin | 0:0ed2a7c7190c | 333 | static void |
GordonSin | 0:0ed2a7c7190c | 334 | upap_input(int unit, u_char *inpacket, int l) |
GordonSin | 0:0ed2a7c7190c | 335 | { |
GordonSin | 0:0ed2a7c7190c | 336 | upap_state *u = &upap[unit]; |
GordonSin | 0:0ed2a7c7190c | 337 | u_char *inp; |
GordonSin | 0:0ed2a7c7190c | 338 | u_char code, id; |
GordonSin | 0:0ed2a7c7190c | 339 | int len; |
GordonSin | 0:0ed2a7c7190c | 340 | |
GordonSin | 0:0ed2a7c7190c | 341 | /* |
GordonSin | 0:0ed2a7c7190c | 342 | * Parse header (code, id and length). |
GordonSin | 0:0ed2a7c7190c | 343 | * If packet too short, drop it. |
GordonSin | 0:0ed2a7c7190c | 344 | */ |
GordonSin | 0:0ed2a7c7190c | 345 | inp = inpacket; |
GordonSin | 0:0ed2a7c7190c | 346 | if (l < (int)UPAP_HEADERLEN) { |
GordonSin | 0:0ed2a7c7190c | 347 | UPAPDEBUG(LOG_INFO, ("pap_input: rcvd short header.\n")); |
GordonSin | 0:0ed2a7c7190c | 348 | return; |
GordonSin | 0:0ed2a7c7190c | 349 | } |
GordonSin | 0:0ed2a7c7190c | 350 | GETCHAR(code, inp); |
GordonSin | 0:0ed2a7c7190c | 351 | GETCHAR(id, inp); |
GordonSin | 0:0ed2a7c7190c | 352 | GETSHORT(len, inp); |
GordonSin | 0:0ed2a7c7190c | 353 | if (len < (int)UPAP_HEADERLEN) { |
GordonSin | 0:0ed2a7c7190c | 354 | UPAPDEBUG(LOG_INFO, ("pap_input: rcvd illegal length.\n")); |
GordonSin | 0:0ed2a7c7190c | 355 | return; |
GordonSin | 0:0ed2a7c7190c | 356 | } |
GordonSin | 0:0ed2a7c7190c | 357 | if (len > l) { |
GordonSin | 0:0ed2a7c7190c | 358 | UPAPDEBUG(LOG_INFO, ("pap_input: rcvd short packet.\n")); |
GordonSin | 0:0ed2a7c7190c | 359 | return; |
GordonSin | 0:0ed2a7c7190c | 360 | } |
GordonSin | 0:0ed2a7c7190c | 361 | len -= UPAP_HEADERLEN; |
GordonSin | 0:0ed2a7c7190c | 362 | |
GordonSin | 0:0ed2a7c7190c | 363 | /* |
GordonSin | 0:0ed2a7c7190c | 364 | * Action depends on code. |
GordonSin | 0:0ed2a7c7190c | 365 | */ |
GordonSin | 0:0ed2a7c7190c | 366 | switch (code) { |
GordonSin | 0:0ed2a7c7190c | 367 | case UPAP_AUTHREQ: |
GordonSin | 0:0ed2a7c7190c | 368 | upap_rauthreq(u, inp, id, len); |
GordonSin | 0:0ed2a7c7190c | 369 | break; |
GordonSin | 0:0ed2a7c7190c | 370 | |
GordonSin | 0:0ed2a7c7190c | 371 | case UPAP_AUTHACK: |
GordonSin | 0:0ed2a7c7190c | 372 | upap_rauthack(u, inp, id, len); |
GordonSin | 0:0ed2a7c7190c | 373 | break; |
GordonSin | 0:0ed2a7c7190c | 374 | |
GordonSin | 0:0ed2a7c7190c | 375 | case UPAP_AUTHNAK: |
GordonSin | 0:0ed2a7c7190c | 376 | upap_rauthnak(u, inp, id, len); |
GordonSin | 0:0ed2a7c7190c | 377 | break; |
GordonSin | 0:0ed2a7c7190c | 378 | |
GordonSin | 0:0ed2a7c7190c | 379 | default: /* XXX Need code reject */ |
GordonSin | 0:0ed2a7c7190c | 380 | UPAPDEBUG(LOG_INFO, ("pap_input: UNHANDLED default: code: %d, id: %d, len: %d.\n", code, id, len)); |
GordonSin | 0:0ed2a7c7190c | 381 | break; |
GordonSin | 0:0ed2a7c7190c | 382 | } |
GordonSin | 0:0ed2a7c7190c | 383 | } |
GordonSin | 0:0ed2a7c7190c | 384 | |
GordonSin | 0:0ed2a7c7190c | 385 | |
GordonSin | 0:0ed2a7c7190c | 386 | /* |
GordonSin | 0:0ed2a7c7190c | 387 | * upap_rauth - Receive Authenticate. |
GordonSin | 0:0ed2a7c7190c | 388 | */ |
GordonSin | 0:0ed2a7c7190c | 389 | static void |
GordonSin | 0:0ed2a7c7190c | 390 | upap_rauthreq(upap_state *u, u_char *inp, u_char id, int len) |
GordonSin | 0:0ed2a7c7190c | 391 | { |
GordonSin | 0:0ed2a7c7190c | 392 | u_char ruserlen, rpasswdlen; |
GordonSin | 0:0ed2a7c7190c | 393 | char *ruser, *rpasswd; |
GordonSin | 0:0ed2a7c7190c | 394 | u_char retcode; |
GordonSin | 0:0ed2a7c7190c | 395 | char *msg; |
GordonSin | 0:0ed2a7c7190c | 396 | int msglen; |
GordonSin | 0:0ed2a7c7190c | 397 | |
GordonSin | 0:0ed2a7c7190c | 398 | UPAPDEBUG(LOG_INFO, ("pap_rauth: Rcvd id %d.\n", id)); |
GordonSin | 0:0ed2a7c7190c | 399 | |
GordonSin | 0:0ed2a7c7190c | 400 | if (u->us_serverstate < UPAPSS_LISTEN) { |
GordonSin | 0:0ed2a7c7190c | 401 | return; |
GordonSin | 0:0ed2a7c7190c | 402 | } |
GordonSin | 0:0ed2a7c7190c | 403 | |
GordonSin | 0:0ed2a7c7190c | 404 | /* |
GordonSin | 0:0ed2a7c7190c | 405 | * If we receive a duplicate authenticate-request, we are |
GordonSin | 0:0ed2a7c7190c | 406 | * supposed to return the same status as for the first request. |
GordonSin | 0:0ed2a7c7190c | 407 | */ |
GordonSin | 0:0ed2a7c7190c | 408 | if (u->us_serverstate == UPAPSS_OPEN) { |
GordonSin | 0:0ed2a7c7190c | 409 | upap_sresp(u, UPAP_AUTHACK, id, "", 0); /* return auth-ack */ |
GordonSin | 0:0ed2a7c7190c | 410 | return; |
GordonSin | 0:0ed2a7c7190c | 411 | } |
GordonSin | 0:0ed2a7c7190c | 412 | if (u->us_serverstate == UPAPSS_BADAUTH) { |
GordonSin | 0:0ed2a7c7190c | 413 | upap_sresp(u, UPAP_AUTHNAK, id, "", 0); /* return auth-nak */ |
GordonSin | 0:0ed2a7c7190c | 414 | return; |
GordonSin | 0:0ed2a7c7190c | 415 | } |
GordonSin | 0:0ed2a7c7190c | 416 | |
GordonSin | 0:0ed2a7c7190c | 417 | /* |
GordonSin | 0:0ed2a7c7190c | 418 | * Parse user/passwd. |
GordonSin | 0:0ed2a7c7190c | 419 | */ |
GordonSin | 0:0ed2a7c7190c | 420 | if (len < (int)sizeof (u_char)) { |
GordonSin | 0:0ed2a7c7190c | 421 | UPAPDEBUG(LOG_INFO, ("pap_rauth: rcvd short packet.\n")); |
GordonSin | 0:0ed2a7c7190c | 422 | return; |
GordonSin | 0:0ed2a7c7190c | 423 | } |
GordonSin | 0:0ed2a7c7190c | 424 | GETCHAR(ruserlen, inp); |
GordonSin | 0:0ed2a7c7190c | 425 | len -= sizeof (u_char) + ruserlen + sizeof (u_char); |
GordonSin | 0:0ed2a7c7190c | 426 | if (len < 0) { |
GordonSin | 0:0ed2a7c7190c | 427 | UPAPDEBUG(LOG_INFO, ("pap_rauth: rcvd short packet.\n")); |
GordonSin | 0:0ed2a7c7190c | 428 | return; |
GordonSin | 0:0ed2a7c7190c | 429 | } |
GordonSin | 0:0ed2a7c7190c | 430 | ruser = (char *) inp; |
GordonSin | 0:0ed2a7c7190c | 431 | INCPTR(ruserlen, inp); |
GordonSin | 0:0ed2a7c7190c | 432 | GETCHAR(rpasswdlen, inp); |
GordonSin | 0:0ed2a7c7190c | 433 | if (len < rpasswdlen) { |
GordonSin | 0:0ed2a7c7190c | 434 | UPAPDEBUG(LOG_INFO, ("pap_rauth: rcvd short packet.\n")); |
GordonSin | 0:0ed2a7c7190c | 435 | return; |
GordonSin | 0:0ed2a7c7190c | 436 | } |
GordonSin | 0:0ed2a7c7190c | 437 | rpasswd = (char *) inp; |
GordonSin | 0:0ed2a7c7190c | 438 | |
GordonSin | 0:0ed2a7c7190c | 439 | /* |
GordonSin | 0:0ed2a7c7190c | 440 | * Check the username and password given. |
GordonSin | 0:0ed2a7c7190c | 441 | */ |
GordonSin | 0:0ed2a7c7190c | 442 | retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd, rpasswdlen, &msg, &msglen); |
GordonSin | 0:0ed2a7c7190c | 443 | /* lwip: currently retcode is always UPAP_AUTHACK */ |
GordonSin | 0:0ed2a7c7190c | 444 | BZERO(rpasswd, rpasswdlen); |
GordonSin | 0:0ed2a7c7190c | 445 | |
GordonSin | 0:0ed2a7c7190c | 446 | upap_sresp(u, retcode, id, msg, msglen); |
GordonSin | 0:0ed2a7c7190c | 447 | |
GordonSin | 0:0ed2a7c7190c | 448 | if (retcode == UPAP_AUTHACK) { |
GordonSin | 0:0ed2a7c7190c | 449 | u->us_serverstate = UPAPSS_OPEN; |
GordonSin | 0:0ed2a7c7190c | 450 | auth_peer_success(u->us_unit, PPP_PAP, ruser, ruserlen); |
GordonSin | 0:0ed2a7c7190c | 451 | } else { |
GordonSin | 0:0ed2a7c7190c | 452 | u->us_serverstate = UPAPSS_BADAUTH; |
GordonSin | 0:0ed2a7c7190c | 453 | auth_peer_fail(u->us_unit, PPP_PAP); |
GordonSin | 0:0ed2a7c7190c | 454 | } |
GordonSin | 0:0ed2a7c7190c | 455 | |
GordonSin | 0:0ed2a7c7190c | 456 | if (u->us_reqtimeout > 0) { |
GordonSin | 0:0ed2a7c7190c | 457 | UNTIMEOUT(upap_reqtimeout, u); |
GordonSin | 0:0ed2a7c7190c | 458 | } |
GordonSin | 0:0ed2a7c7190c | 459 | } |
GordonSin | 0:0ed2a7c7190c | 460 | |
GordonSin | 0:0ed2a7c7190c | 461 | |
GordonSin | 0:0ed2a7c7190c | 462 | /* |
GordonSin | 0:0ed2a7c7190c | 463 | * upap_rauthack - Receive Authenticate-Ack. |
GordonSin | 0:0ed2a7c7190c | 464 | */ |
GordonSin | 0:0ed2a7c7190c | 465 | static void |
GordonSin | 0:0ed2a7c7190c | 466 | upap_rauthack(upap_state *u, u_char *inp, int id, int len) |
GordonSin | 0:0ed2a7c7190c | 467 | { |
GordonSin | 0:0ed2a7c7190c | 468 | u_char msglen; |
GordonSin | 0:0ed2a7c7190c | 469 | char *msg; |
GordonSin | 0:0ed2a7c7190c | 470 | |
GordonSin | 0:0ed2a7c7190c | 471 | LWIP_UNUSED_ARG(id); |
GordonSin | 0:0ed2a7c7190c | 472 | |
GordonSin | 0:0ed2a7c7190c | 473 | UPAPDEBUG(LOG_INFO, ("pap_rauthack: Rcvd id %d s=%d\n", id, u->us_clientstate)); |
GordonSin | 0:0ed2a7c7190c | 474 | |
GordonSin | 0:0ed2a7c7190c | 475 | if (u->us_clientstate != UPAPCS_AUTHREQ) { /* XXX */ |
GordonSin | 0:0ed2a7c7190c | 476 | UPAPDEBUG(LOG_INFO, ("pap_rauthack: us_clientstate != UPAPCS_AUTHREQ\n")); |
GordonSin | 0:0ed2a7c7190c | 477 | return; |
GordonSin | 0:0ed2a7c7190c | 478 | } |
GordonSin | 0:0ed2a7c7190c | 479 | |
GordonSin | 0:0ed2a7c7190c | 480 | /* |
GordonSin | 0:0ed2a7c7190c | 481 | * Parse message. |
GordonSin | 0:0ed2a7c7190c | 482 | */ |
GordonSin | 0:0ed2a7c7190c | 483 | if (len < (int)sizeof (u_char)) { |
GordonSin | 0:0ed2a7c7190c | 484 | UPAPDEBUG(LOG_INFO, ("pap_rauthack: ignoring missing msg-length.\n")); |
GordonSin | 0:0ed2a7c7190c | 485 | } else { |
GordonSin | 0:0ed2a7c7190c | 486 | GETCHAR(msglen, inp); |
GordonSin | 0:0ed2a7c7190c | 487 | if (msglen > 0) { |
GordonSin | 0:0ed2a7c7190c | 488 | len -= sizeof (u_char); |
GordonSin | 0:0ed2a7c7190c | 489 | if (len < msglen) { |
GordonSin | 0:0ed2a7c7190c | 490 | UPAPDEBUG(LOG_INFO, ("pap_rauthack: rcvd short packet.\n")); |
GordonSin | 0:0ed2a7c7190c | 491 | return; |
GordonSin | 0:0ed2a7c7190c | 492 | } |
GordonSin | 0:0ed2a7c7190c | 493 | msg = (char *) inp; |
GordonSin | 0:0ed2a7c7190c | 494 | PRINTMSG(msg, msglen); |
GordonSin | 0:0ed2a7c7190c | 495 | } |
GordonSin | 0:0ed2a7c7190c | 496 | } |
GordonSin | 0:0ed2a7c7190c | 497 | UNTIMEOUT(upap_timeout, u); /* Cancel timeout */ |
GordonSin | 0:0ed2a7c7190c | 498 | u->us_clientstate = UPAPCS_OPEN; |
GordonSin | 0:0ed2a7c7190c | 499 | |
GordonSin | 0:0ed2a7c7190c | 500 | auth_withpeer_success(u->us_unit, PPP_PAP); |
GordonSin | 0:0ed2a7c7190c | 501 | } |
GordonSin | 0:0ed2a7c7190c | 502 | |
GordonSin | 0:0ed2a7c7190c | 503 | |
GordonSin | 0:0ed2a7c7190c | 504 | /* |
GordonSin | 0:0ed2a7c7190c | 505 | * upap_rauthnak - Receive Authenticate-Nak. |
GordonSin | 0:0ed2a7c7190c | 506 | */ |
GordonSin | 0:0ed2a7c7190c | 507 | static void |
GordonSin | 0:0ed2a7c7190c | 508 | upap_rauthnak(upap_state *u, u_char *inp, int id, int len) |
GordonSin | 0:0ed2a7c7190c | 509 | { |
GordonSin | 0:0ed2a7c7190c | 510 | u_char msglen; |
GordonSin | 0:0ed2a7c7190c | 511 | char *msg; |
GordonSin | 0:0ed2a7c7190c | 512 | |
GordonSin | 0:0ed2a7c7190c | 513 | LWIP_UNUSED_ARG(id); |
GordonSin | 0:0ed2a7c7190c | 514 | |
GordonSin | 0:0ed2a7c7190c | 515 | UPAPDEBUG(LOG_INFO, ("pap_rauthnak: Rcvd id %d s=%d\n", id, u->us_clientstate)); |
GordonSin | 0:0ed2a7c7190c | 516 | |
GordonSin | 0:0ed2a7c7190c | 517 | if (u->us_clientstate != UPAPCS_AUTHREQ) { /* XXX */ |
GordonSin | 0:0ed2a7c7190c | 518 | return; |
GordonSin | 0:0ed2a7c7190c | 519 | } |
GordonSin | 0:0ed2a7c7190c | 520 | |
GordonSin | 0:0ed2a7c7190c | 521 | /* |
GordonSin | 0:0ed2a7c7190c | 522 | * Parse message. |
GordonSin | 0:0ed2a7c7190c | 523 | */ |
GordonSin | 0:0ed2a7c7190c | 524 | if (len < sizeof (u_char)) { |
GordonSin | 0:0ed2a7c7190c | 525 | UPAPDEBUG(LOG_INFO, ("pap_rauthnak: ignoring missing msg-length.\n")); |
GordonSin | 0:0ed2a7c7190c | 526 | } else { |
GordonSin | 0:0ed2a7c7190c | 527 | GETCHAR(msglen, inp); |
GordonSin | 0:0ed2a7c7190c | 528 | if(msglen > 0) { |
GordonSin | 0:0ed2a7c7190c | 529 | len -= sizeof (u_char); |
GordonSin | 0:0ed2a7c7190c | 530 | if (len < msglen) { |
GordonSin | 0:0ed2a7c7190c | 531 | UPAPDEBUG(LOG_INFO, ("pap_rauthnak: rcvd short packet.\n")); |
GordonSin | 0:0ed2a7c7190c | 532 | return; |
GordonSin | 0:0ed2a7c7190c | 533 | } |
GordonSin | 0:0ed2a7c7190c | 534 | msg = (char *) inp; |
GordonSin | 0:0ed2a7c7190c | 535 | PRINTMSG(msg, msglen); |
GordonSin | 0:0ed2a7c7190c | 536 | } |
GordonSin | 0:0ed2a7c7190c | 537 | } |
GordonSin | 0:0ed2a7c7190c | 538 | |
GordonSin | 0:0ed2a7c7190c | 539 | u->us_clientstate = UPAPCS_BADAUTH; |
GordonSin | 0:0ed2a7c7190c | 540 | |
GordonSin | 0:0ed2a7c7190c | 541 | UPAPDEBUG(LOG_ERR, ("PAP authentication failed\n")); |
GordonSin | 0:0ed2a7c7190c | 542 | auth_withpeer_fail(u->us_unit, PPP_PAP); |
GordonSin | 0:0ed2a7c7190c | 543 | } |
GordonSin | 0:0ed2a7c7190c | 544 | |
GordonSin | 0:0ed2a7c7190c | 545 | |
GordonSin | 0:0ed2a7c7190c | 546 | /* |
GordonSin | 0:0ed2a7c7190c | 547 | * upap_sauthreq - Send an Authenticate-Request. |
GordonSin | 0:0ed2a7c7190c | 548 | */ |
GordonSin | 0:0ed2a7c7190c | 549 | static void |
GordonSin | 0:0ed2a7c7190c | 550 | upap_sauthreq(upap_state *u) |
GordonSin | 0:0ed2a7c7190c | 551 | { |
GordonSin | 0:0ed2a7c7190c | 552 | u_char *outp; |
GordonSin | 0:0ed2a7c7190c | 553 | int outlen; |
GordonSin | 0:0ed2a7c7190c | 554 | |
GordonSin | 0:0ed2a7c7190c | 555 | outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) |
GordonSin | 0:0ed2a7c7190c | 556 | + u->us_userlen + u->us_passwdlen; |
GordonSin | 0:0ed2a7c7190c | 557 | outp = outpacket_buf[u->us_unit]; |
GordonSin | 0:0ed2a7c7190c | 558 | |
GordonSin | 0:0ed2a7c7190c | 559 | MAKEHEADER(outp, PPP_PAP); |
GordonSin | 0:0ed2a7c7190c | 560 | |
GordonSin | 0:0ed2a7c7190c | 561 | PUTCHAR(UPAP_AUTHREQ, outp); |
GordonSin | 0:0ed2a7c7190c | 562 | PUTCHAR(++u->us_id, outp); |
GordonSin | 0:0ed2a7c7190c | 563 | PUTSHORT(outlen, outp); |
GordonSin | 0:0ed2a7c7190c | 564 | PUTCHAR(u->us_userlen, outp); |
GordonSin | 0:0ed2a7c7190c | 565 | BCOPY(u->us_user, outp, u->us_userlen); |
GordonSin | 0:0ed2a7c7190c | 566 | INCPTR(u->us_userlen, outp); |
GordonSin | 0:0ed2a7c7190c | 567 | PUTCHAR(u->us_passwdlen, outp); |
GordonSin | 0:0ed2a7c7190c | 568 | BCOPY(u->us_passwd, outp, u->us_passwdlen); |
GordonSin | 0:0ed2a7c7190c | 569 | |
GordonSin | 0:0ed2a7c7190c | 570 | pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN); |
GordonSin | 0:0ed2a7c7190c | 571 | |
GordonSin | 0:0ed2a7c7190c | 572 | UPAPDEBUG(LOG_INFO, ("pap_sauth: Sent id %d\n", u->us_id)); |
GordonSin | 0:0ed2a7c7190c | 573 | |
GordonSin | 0:0ed2a7c7190c | 574 | TIMEOUT(upap_timeout, u, u->us_timeouttime); |
GordonSin | 0:0ed2a7c7190c | 575 | ++u->us_transmits; |
GordonSin | 0:0ed2a7c7190c | 576 | u->us_clientstate = UPAPCS_AUTHREQ; |
GordonSin | 0:0ed2a7c7190c | 577 | } |
GordonSin | 0:0ed2a7c7190c | 578 | |
GordonSin | 0:0ed2a7c7190c | 579 | |
GordonSin | 0:0ed2a7c7190c | 580 | /* |
GordonSin | 0:0ed2a7c7190c | 581 | * upap_sresp - Send a response (ack or nak). |
GordonSin | 0:0ed2a7c7190c | 582 | */ |
GordonSin | 0:0ed2a7c7190c | 583 | static void |
GordonSin | 0:0ed2a7c7190c | 584 | upap_sresp(upap_state *u, u_char code, u_char id, char *msg, int msglen) |
GordonSin | 0:0ed2a7c7190c | 585 | { |
GordonSin | 0:0ed2a7c7190c | 586 | u_char *outp; |
GordonSin | 0:0ed2a7c7190c | 587 | int outlen; |
GordonSin | 0:0ed2a7c7190c | 588 | |
GordonSin | 0:0ed2a7c7190c | 589 | outlen = UPAP_HEADERLEN + sizeof (u_char) + msglen; |
GordonSin | 0:0ed2a7c7190c | 590 | outp = outpacket_buf[u->us_unit]; |
GordonSin | 0:0ed2a7c7190c | 591 | MAKEHEADER(outp, PPP_PAP); |
GordonSin | 0:0ed2a7c7190c | 592 | |
GordonSin | 0:0ed2a7c7190c | 593 | PUTCHAR(code, outp); |
GordonSin | 0:0ed2a7c7190c | 594 | PUTCHAR(id, outp); |
GordonSin | 0:0ed2a7c7190c | 595 | PUTSHORT(outlen, outp); |
GordonSin | 0:0ed2a7c7190c | 596 | PUTCHAR(msglen, outp); |
GordonSin | 0:0ed2a7c7190c | 597 | BCOPY(msg, outp, msglen); |
GordonSin | 0:0ed2a7c7190c | 598 | pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN); |
GordonSin | 0:0ed2a7c7190c | 599 | |
GordonSin | 0:0ed2a7c7190c | 600 | UPAPDEBUG(LOG_INFO, ("pap_sresp: Sent code %d, id %d s=%d\n", code, id, u->us_clientstate)); |
GordonSin | 0:0ed2a7c7190c | 601 | } |
GordonSin | 0:0ed2a7c7190c | 602 | |
GordonSin | 0:0ed2a7c7190c | 603 | #if PPP_ADDITIONAL_CALLBACKS |
GordonSin | 0:0ed2a7c7190c | 604 | static char *upap_codenames[] = { |
GordonSin | 0:0ed2a7c7190c | 605 | "AuthReq", "AuthAck", "AuthNak" |
GordonSin | 0:0ed2a7c7190c | 606 | }; |
GordonSin | 0:0ed2a7c7190c | 607 | |
GordonSin | 0:0ed2a7c7190c | 608 | /* |
GordonSin | 0:0ed2a7c7190c | 609 | * upap_printpkt - print the contents of a PAP packet. |
GordonSin | 0:0ed2a7c7190c | 610 | */ |
GordonSin | 0:0ed2a7c7190c | 611 | static int upap_printpkt( |
GordonSin | 0:0ed2a7c7190c | 612 | u_char *p, |
GordonSin | 0:0ed2a7c7190c | 613 | int plen, |
GordonSin | 0:0ed2a7c7190c | 614 | void (*printer) (void *, char *, ...), |
GordonSin | 0:0ed2a7c7190c | 615 | void *arg |
GordonSin | 0:0ed2a7c7190c | 616 | ) |
GordonSin | 0:0ed2a7c7190c | 617 | { |
GordonSin | 0:0ed2a7c7190c | 618 | LWIP_UNUSED_ARG(p); |
GordonSin | 0:0ed2a7c7190c | 619 | LWIP_UNUSED_ARG(plen); |
GordonSin | 0:0ed2a7c7190c | 620 | LWIP_UNUSED_ARG(printer); |
GordonSin | 0:0ed2a7c7190c | 621 | LWIP_UNUSED_ARG(arg); |
GordonSin | 0:0ed2a7c7190c | 622 | return 0; |
GordonSin | 0:0ed2a7c7190c | 623 | } |
GordonSin | 0:0ed2a7c7190c | 624 | #endif /* PPP_ADDITIONAL_CALLBACKS */ |
GordonSin | 0:0ed2a7c7190c | 625 | |
GordonSin | 0:0ed2a7c7190c | 626 | #endif /* PAP_SUPPORT */ |
GordonSin | 0:0ed2a7c7190c | 627 | |
GordonSin | 0:0ed2a7c7190c | 628 | #endif /* PPP_SUPPORT */ |