Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:48:09 2011 +0000
Revision:
0:850eacf3e945
revised fixed length to 178 bytes

Who changed what in which revision?

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