1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * upap.c - User/Password Authentication Protocol. 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * Copyright (c) 2000 by Sun Microsystems, Inc. 5*7c478bd9Sstevel@tonic-gate * All rights reserved. 6*7c478bd9Sstevel@tonic-gate * 7*7c478bd9Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this software and its 8*7c478bd9Sstevel@tonic-gate * documentation is hereby granted, provided that the above copyright 9*7c478bd9Sstevel@tonic-gate * notice appears in all copies. 10*7c478bd9Sstevel@tonic-gate * 11*7c478bd9Sstevel@tonic-gate * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF 12*7c478bd9Sstevel@tonic-gate * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 13*7c478bd9Sstevel@tonic-gate * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 14*7c478bd9Sstevel@tonic-gate * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR 15*7c478bd9Sstevel@tonic-gate * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR 16*7c478bd9Sstevel@tonic-gate * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES 17*7c478bd9Sstevel@tonic-gate * 18*7c478bd9Sstevel@tonic-gate * Copyright (c) 1989 Carnegie Mellon University. 19*7c478bd9Sstevel@tonic-gate * All rights reserved. 20*7c478bd9Sstevel@tonic-gate * 21*7c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted 22*7c478bd9Sstevel@tonic-gate * provided that the above copyright notice and this paragraph are 23*7c478bd9Sstevel@tonic-gate * duplicated in all such forms and that any documentation, 24*7c478bd9Sstevel@tonic-gate * advertising materials, and other materials related to such 25*7c478bd9Sstevel@tonic-gate * distribution and use acknowledge that the software was developed 26*7c478bd9Sstevel@tonic-gate * by Carnegie Mellon University. The name of the 27*7c478bd9Sstevel@tonic-gate * University may not be used to endorse or promote products derived 28*7c478bd9Sstevel@tonic-gate * from this software without specific prior written permission. 29*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 30*7c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 31*7c478bd9Sstevel@tonic-gate * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 32*7c478bd9Sstevel@tonic-gate */ 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 35*7c478bd9Sstevel@tonic-gate #define RCSID "$Id: upap.c,v 1.23 1999/11/20 05:11:47 paulus Exp $" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include <stdio.h> 38*7c478bd9Sstevel@tonic-gate #include <string.h> 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #include "pppd.h" 41*7c478bd9Sstevel@tonic-gate #include "upap.h" 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #if !defined(lint) && !defined(_lint) 44*7c478bd9Sstevel@tonic-gate static const char rcsid[] = RCSID; 45*7c478bd9Sstevel@tonic-gate #endif 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate static bool hide_password = 1; 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate /* 50*7c478bd9Sstevel@tonic-gate * Command-line options. 51*7c478bd9Sstevel@tonic-gate */ 52*7c478bd9Sstevel@tonic-gate static option_t pap_option_list[] = { 53*7c478bd9Sstevel@tonic-gate { "hide-password", o_bool, &hide_password, 54*7c478bd9Sstevel@tonic-gate "Don't output passwords to log", 1 }, 55*7c478bd9Sstevel@tonic-gate { "show-password", o_bool, &hide_password, 56*7c478bd9Sstevel@tonic-gate "Show password string in debug log messages", 0 }, 57*7c478bd9Sstevel@tonic-gate { "pap-restart", o_int, &upap[0].us_timeouttime, 58*7c478bd9Sstevel@tonic-gate "Set retransmit timeout for PAP" }, 59*7c478bd9Sstevel@tonic-gate { "pap-max-authreq", o_int, &upap[0].us_maxtransmits, 60*7c478bd9Sstevel@tonic-gate "Max number of PAP Authenticate-Request sent" }, 61*7c478bd9Sstevel@tonic-gate { "pap-max-receive", o_int, &upap[0].us_maxreceives, 62*7c478bd9Sstevel@tonic-gate "Max allowable PAP Authenticate-Request received" }, 63*7c478bd9Sstevel@tonic-gate { "pap-timeout", o_int, &upap[0].us_reqtimeout, 64*7c478bd9Sstevel@tonic-gate "Set time limit for peer PAP authentication" }, 65*7c478bd9Sstevel@tonic-gate { NULL } 66*7c478bd9Sstevel@tonic-gate }; 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate /* 69*7c478bd9Sstevel@tonic-gate * Protocol entry points. 70*7c478bd9Sstevel@tonic-gate */ 71*7c478bd9Sstevel@tonic-gate static void upap_init __P((int)); 72*7c478bd9Sstevel@tonic-gate static void upap_lowerup __P((int)); 73*7c478bd9Sstevel@tonic-gate static void upap_lowerdown __P((int)); 74*7c478bd9Sstevel@tonic-gate static void upap_input __P((int, u_char *, int)); 75*7c478bd9Sstevel@tonic-gate static void upap_protrej __P((int)); 76*7c478bd9Sstevel@tonic-gate static int upap_printpkt __P((u_char *, int, 77*7c478bd9Sstevel@tonic-gate void (*) __P((void *, const char *, ...)), void *)); 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate struct protent pap_protent = { 80*7c478bd9Sstevel@tonic-gate PPP_PAP, 81*7c478bd9Sstevel@tonic-gate upap_init, 82*7c478bd9Sstevel@tonic-gate upap_input, 83*7c478bd9Sstevel@tonic-gate upap_protrej, 84*7c478bd9Sstevel@tonic-gate upap_lowerup, 85*7c478bd9Sstevel@tonic-gate upap_lowerdown, 86*7c478bd9Sstevel@tonic-gate NULL, 87*7c478bd9Sstevel@tonic-gate NULL, 88*7c478bd9Sstevel@tonic-gate upap_printpkt, 89*7c478bd9Sstevel@tonic-gate NULL, 90*7c478bd9Sstevel@tonic-gate 1, 91*7c478bd9Sstevel@tonic-gate "PAP", 92*7c478bd9Sstevel@tonic-gate NULL, 93*7c478bd9Sstevel@tonic-gate pap_option_list, 94*7c478bd9Sstevel@tonic-gate NULL, 95*7c478bd9Sstevel@tonic-gate NULL, 96*7c478bd9Sstevel@tonic-gate NULL 97*7c478bd9Sstevel@tonic-gate }; 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate upap_state upap[NUM_PPP]; /* UPAP state; one for each unit */ 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate static void upap_timeout __P((void *)); 102*7c478bd9Sstevel@tonic-gate static void upap_reqtimeout __P((void *)); 103*7c478bd9Sstevel@tonic-gate static void upap_rauthreq __P((upap_state *, u_char *, int, int)); 104*7c478bd9Sstevel@tonic-gate static void upap_rauthack __P((upap_state *, u_char *, int, int)); 105*7c478bd9Sstevel@tonic-gate static void upap_rauthnak __P((upap_state *, u_char *, int, int)); 106*7c478bd9Sstevel@tonic-gate static void upap_sauthreq __P((upap_state *)); 107*7c478bd9Sstevel@tonic-gate static void upap_sresp __P((upap_state *, int, int, char *, int)); 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate static const char * 110*7c478bd9Sstevel@tonic-gate pap_cstate(clientstate) 111*7c478bd9Sstevel@tonic-gate int clientstate; 112*7c478bd9Sstevel@tonic-gate { 113*7c478bd9Sstevel@tonic-gate static const char *cstate[] = { UPAPCS__NAMES }; 114*7c478bd9Sstevel@tonic-gate static char buf[32]; 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate if (clientstate < 0 || clientstate >= Dim(cstate)) { 117*7c478bd9Sstevel@tonic-gate (void) slprintf(buf, sizeof (buf), "Cli#%d", clientstate); 118*7c478bd9Sstevel@tonic-gate return ((const char *)buf); 119*7c478bd9Sstevel@tonic-gate } 120*7c478bd9Sstevel@tonic-gate return (cstate[clientstate]); 121*7c478bd9Sstevel@tonic-gate } 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate static const char * 124*7c478bd9Sstevel@tonic-gate pap_sstate(serverstate) 125*7c478bd9Sstevel@tonic-gate int serverstate; 126*7c478bd9Sstevel@tonic-gate { 127*7c478bd9Sstevel@tonic-gate static const char *sstate[] = { UPAPSS__NAMES }; 128*7c478bd9Sstevel@tonic-gate static char buf[32]; 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate if (serverstate < 0 || serverstate >= Dim(sstate)) { 131*7c478bd9Sstevel@tonic-gate (void) slprintf(buf, sizeof (buf), "Srv#%d", serverstate); 132*7c478bd9Sstevel@tonic-gate return ((const char *)buf); 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate return (sstate[serverstate]); 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate /* 138*7c478bd9Sstevel@tonic-gate * upap_init - Initialize a UPAP unit. 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate static void 141*7c478bd9Sstevel@tonic-gate upap_init(unit) 142*7c478bd9Sstevel@tonic-gate int unit; 143*7c478bd9Sstevel@tonic-gate { 144*7c478bd9Sstevel@tonic-gate upap_state *u = &upap[unit]; 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate u->us_unit = unit; 147*7c478bd9Sstevel@tonic-gate u->us_user = NULL; 148*7c478bd9Sstevel@tonic-gate u->us_userlen = 0; 149*7c478bd9Sstevel@tonic-gate u->us_passwd = NULL; 150*7c478bd9Sstevel@tonic-gate u->us_clientstate = UPAPCS_INITIAL; 151*7c478bd9Sstevel@tonic-gate u->us_serverstate = UPAPSS_INITIAL; 152*7c478bd9Sstevel@tonic-gate u->us_id = 0; 153*7c478bd9Sstevel@tonic-gate u->us_timeouttime = UPAP_DEFTIMEOUT; 154*7c478bd9Sstevel@tonic-gate u->us_maxtransmits = 10; 155*7c478bd9Sstevel@tonic-gate u->us_reqtimeout = UPAP_DEFREQTIME; 156*7c478bd9Sstevel@tonic-gate u->us_maxreceives = 3; 157*7c478bd9Sstevel@tonic-gate u->us_msg = ""; 158*7c478bd9Sstevel@tonic-gate u->us_msglen = 0; 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate /* 163*7c478bd9Sstevel@tonic-gate * upap_authwithpeer - Authenticate us with our peer (start client). 164*7c478bd9Sstevel@tonic-gate * 165*7c478bd9Sstevel@tonic-gate * Set new state and send authenticate's. 166*7c478bd9Sstevel@tonic-gate */ 167*7c478bd9Sstevel@tonic-gate void 168*7c478bd9Sstevel@tonic-gate upap_authwithpeer(unit, user, password) 169*7c478bd9Sstevel@tonic-gate int unit; 170*7c478bd9Sstevel@tonic-gate char *user, *password; 171*7c478bd9Sstevel@tonic-gate { 172*7c478bd9Sstevel@tonic-gate upap_state *u = &upap[unit]; 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate /* Save the username and password we're given */ 175*7c478bd9Sstevel@tonic-gate u->us_user = user; 176*7c478bd9Sstevel@tonic-gate u->us_userlen = strlen(user); 177*7c478bd9Sstevel@tonic-gate u->us_passwd = password; 178*7c478bd9Sstevel@tonic-gate u->us_transmits = 0; 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate /* Lower layer up yet? */ 181*7c478bd9Sstevel@tonic-gate if (u->us_clientstate == UPAPCS_INITIAL || 182*7c478bd9Sstevel@tonic-gate u->us_clientstate == UPAPCS_PENDING) { 183*7c478bd9Sstevel@tonic-gate u->us_clientstate = UPAPCS_PENDING; 184*7c478bd9Sstevel@tonic-gate return; 185*7c478bd9Sstevel@tonic-gate } 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate upap_sauthreq(u); /* Start protocol */ 188*7c478bd9Sstevel@tonic-gate } 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate /* 192*7c478bd9Sstevel@tonic-gate * upap_authpeer - Authenticate our peer (start server). 193*7c478bd9Sstevel@tonic-gate * 194*7c478bd9Sstevel@tonic-gate * Set new state. 195*7c478bd9Sstevel@tonic-gate */ 196*7c478bd9Sstevel@tonic-gate void 197*7c478bd9Sstevel@tonic-gate upap_authpeer(unit) 198*7c478bd9Sstevel@tonic-gate int unit; 199*7c478bd9Sstevel@tonic-gate { 200*7c478bd9Sstevel@tonic-gate upap_state *u = &upap[unit]; 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate /* Lower layer up yet? */ 203*7c478bd9Sstevel@tonic-gate if (u->us_serverstate == UPAPSS_INITIAL || 204*7c478bd9Sstevel@tonic-gate u->us_serverstate == UPAPSS_PENDING) { 205*7c478bd9Sstevel@tonic-gate u->us_serverstate = UPAPSS_PENDING; 206*7c478bd9Sstevel@tonic-gate return; 207*7c478bd9Sstevel@tonic-gate } 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate u->us_serverstate = UPAPSS_LISTEN; 210*7c478bd9Sstevel@tonic-gate u->us_receives = 0; 211*7c478bd9Sstevel@tonic-gate if (u->us_reqtimeout > 0) 212*7c478bd9Sstevel@tonic-gate TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout); 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate /* 217*7c478bd9Sstevel@tonic-gate * upap_timeout - Retransmission timer for sending auth-reqs expired. 218*7c478bd9Sstevel@tonic-gate */ 219*7c478bd9Sstevel@tonic-gate static void 220*7c478bd9Sstevel@tonic-gate upap_timeout(arg) 221*7c478bd9Sstevel@tonic-gate void *arg; 222*7c478bd9Sstevel@tonic-gate { 223*7c478bd9Sstevel@tonic-gate upap_state *u = (upap_state *) arg; 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate if (u->us_clientstate != UPAPCS_AUTHREQ) 226*7c478bd9Sstevel@tonic-gate return; 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate if (u->us_transmits >= u->us_maxtransmits) { 229*7c478bd9Sstevel@tonic-gate /* give up in disgust */ 230*7c478bd9Sstevel@tonic-gate error("No response to %d PAP Authenticate-Requests", u->us_transmits); 231*7c478bd9Sstevel@tonic-gate u->us_clientstate = UPAPCS_BADAUTH; 232*7c478bd9Sstevel@tonic-gate auth_withpeer_fail(u->us_unit, PPP_PAP); 233*7c478bd9Sstevel@tonic-gate return; 234*7c478bd9Sstevel@tonic-gate } 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate upap_sauthreq(u); /* Send Authenticate-Request */ 237*7c478bd9Sstevel@tonic-gate } 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate /* 241*7c478bd9Sstevel@tonic-gate * upap_reqtimeout - Give up waiting for the peer to send a valid auth-req. 242*7c478bd9Sstevel@tonic-gate */ 243*7c478bd9Sstevel@tonic-gate static void 244*7c478bd9Sstevel@tonic-gate upap_reqtimeout(arg) 245*7c478bd9Sstevel@tonic-gate void *arg; 246*7c478bd9Sstevel@tonic-gate { 247*7c478bd9Sstevel@tonic-gate upap_state *u = (upap_state *) arg; 248*7c478bd9Sstevel@tonic-gate 249*7c478bd9Sstevel@tonic-gate if (u->us_serverstate != UPAPSS_LISTEN) 250*7c478bd9Sstevel@tonic-gate return; /* huh?? */ 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate auth_peer_fail(u->us_unit, PPP_PAP); 253*7c478bd9Sstevel@tonic-gate u->us_serverstate = UPAPSS_BADAUTH; 254*7c478bd9Sstevel@tonic-gate } 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate /* 258*7c478bd9Sstevel@tonic-gate * upap_lowerup - The lower layer is up. 259*7c478bd9Sstevel@tonic-gate * 260*7c478bd9Sstevel@tonic-gate * Start authenticating if pending. 261*7c478bd9Sstevel@tonic-gate */ 262*7c478bd9Sstevel@tonic-gate static void 263*7c478bd9Sstevel@tonic-gate upap_lowerup(unit) 264*7c478bd9Sstevel@tonic-gate int unit; 265*7c478bd9Sstevel@tonic-gate { 266*7c478bd9Sstevel@tonic-gate upap_state *u = &upap[unit]; 267*7c478bd9Sstevel@tonic-gate 268*7c478bd9Sstevel@tonic-gate if (u->us_clientstate == UPAPCS_INITIAL) 269*7c478bd9Sstevel@tonic-gate u->us_clientstate = UPAPCS_CLOSED; 270*7c478bd9Sstevel@tonic-gate else if (u->us_clientstate == UPAPCS_PENDING) { 271*7c478bd9Sstevel@tonic-gate upap_sauthreq(u); /* send an auth-request */ 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gate if (u->us_serverstate == UPAPSS_INITIAL) 275*7c478bd9Sstevel@tonic-gate u->us_serverstate = UPAPSS_CLOSED; 276*7c478bd9Sstevel@tonic-gate else if (u->us_serverstate == UPAPSS_PENDING) { 277*7c478bd9Sstevel@tonic-gate u->us_serverstate = UPAPSS_LISTEN; 278*7c478bd9Sstevel@tonic-gate if (u->us_reqtimeout > 0) 279*7c478bd9Sstevel@tonic-gate TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout); 280*7c478bd9Sstevel@tonic-gate } 281*7c478bd9Sstevel@tonic-gate } 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate /* 285*7c478bd9Sstevel@tonic-gate * upap_lowerdown - The lower layer is down. 286*7c478bd9Sstevel@tonic-gate * 287*7c478bd9Sstevel@tonic-gate * Cancel all timeouts. 288*7c478bd9Sstevel@tonic-gate */ 289*7c478bd9Sstevel@tonic-gate static void 290*7c478bd9Sstevel@tonic-gate upap_lowerdown(unit) 291*7c478bd9Sstevel@tonic-gate int unit; 292*7c478bd9Sstevel@tonic-gate { 293*7c478bd9Sstevel@tonic-gate upap_state *u = &upap[unit]; 294*7c478bd9Sstevel@tonic-gate 295*7c478bd9Sstevel@tonic-gate /* Cancel timeouts */ 296*7c478bd9Sstevel@tonic-gate if (u->us_clientstate == UPAPCS_AUTHREQ && u->us_timeouttime > 0) 297*7c478bd9Sstevel@tonic-gate UNTIMEOUT(upap_timeout, u); 298*7c478bd9Sstevel@tonic-gate if (u->us_serverstate == UPAPSS_LISTEN && u->us_reqtimeout > 0) 299*7c478bd9Sstevel@tonic-gate UNTIMEOUT(upap_reqtimeout, u); 300*7c478bd9Sstevel@tonic-gate 301*7c478bd9Sstevel@tonic-gate u->us_clientstate = UPAPCS_INITIAL; 302*7c478bd9Sstevel@tonic-gate u->us_serverstate = UPAPSS_INITIAL; 303*7c478bd9Sstevel@tonic-gate } 304*7c478bd9Sstevel@tonic-gate 305*7c478bd9Sstevel@tonic-gate 306*7c478bd9Sstevel@tonic-gate /* 307*7c478bd9Sstevel@tonic-gate * upap_protrej - Peer doesn't speak this protocol. 308*7c478bd9Sstevel@tonic-gate * 309*7c478bd9Sstevel@tonic-gate * This shouldn't happen. In any case, pretend lower layer went down. 310*7c478bd9Sstevel@tonic-gate */ 311*7c478bd9Sstevel@tonic-gate static void 312*7c478bd9Sstevel@tonic-gate upap_protrej(unit) 313*7c478bd9Sstevel@tonic-gate int unit; 314*7c478bd9Sstevel@tonic-gate { 315*7c478bd9Sstevel@tonic-gate upap_state *u = &upap[unit]; 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate if (u->us_clientstate == UPAPCS_AUTHREQ) { 318*7c478bd9Sstevel@tonic-gate error("PAP authentication failed due to protocol-reject"); 319*7c478bd9Sstevel@tonic-gate auth_withpeer_fail(unit, PPP_PAP); 320*7c478bd9Sstevel@tonic-gate } 321*7c478bd9Sstevel@tonic-gate if (u->us_serverstate == UPAPSS_LISTEN) { 322*7c478bd9Sstevel@tonic-gate error("PAP authentication of peer failed (protocol-reject)"); 323*7c478bd9Sstevel@tonic-gate auth_peer_fail(unit, PPP_PAP); 324*7c478bd9Sstevel@tonic-gate } 325*7c478bd9Sstevel@tonic-gate upap_lowerdown(unit); 326*7c478bd9Sstevel@tonic-gate } 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate 329*7c478bd9Sstevel@tonic-gate /* 330*7c478bd9Sstevel@tonic-gate * upap_input - Input UPAP packet. 331*7c478bd9Sstevel@tonic-gate */ 332*7c478bd9Sstevel@tonic-gate static void 333*7c478bd9Sstevel@tonic-gate upap_input(unit, inpacket, l) 334*7c478bd9Sstevel@tonic-gate int unit; 335*7c478bd9Sstevel@tonic-gate u_char *inpacket; 336*7c478bd9Sstevel@tonic-gate int l; 337*7c478bd9Sstevel@tonic-gate { 338*7c478bd9Sstevel@tonic-gate upap_state *u = &upap[unit]; 339*7c478bd9Sstevel@tonic-gate u_char *inp; 340*7c478bd9Sstevel@tonic-gate u_char code, id; 341*7c478bd9Sstevel@tonic-gate int len; 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate /* 344*7c478bd9Sstevel@tonic-gate * Parse header (code, id and length). 345*7c478bd9Sstevel@tonic-gate * If packet too short, drop it. 346*7c478bd9Sstevel@tonic-gate */ 347*7c478bd9Sstevel@tonic-gate inp = inpacket; 348*7c478bd9Sstevel@tonic-gate if (l < UPAP_HEADERLEN) { 349*7c478bd9Sstevel@tonic-gate error("PAP: packet is too small (%d < %d)", l, UPAP_HEADERLEN); 350*7c478bd9Sstevel@tonic-gate return; 351*7c478bd9Sstevel@tonic-gate } 352*7c478bd9Sstevel@tonic-gate GETCHAR(code, inp); 353*7c478bd9Sstevel@tonic-gate GETCHAR(id, inp); 354*7c478bd9Sstevel@tonic-gate GETSHORT(len, inp); 355*7c478bd9Sstevel@tonic-gate if ((len < UPAP_HEADERLEN) || (len > l)) { 356*7c478bd9Sstevel@tonic-gate error("PAP: packet has illegal length %d (%d..%d)", len, 357*7c478bd9Sstevel@tonic-gate UPAP_HEADERLEN, l); 358*7c478bd9Sstevel@tonic-gate return; 359*7c478bd9Sstevel@tonic-gate } 360*7c478bd9Sstevel@tonic-gate len -= UPAP_HEADERLEN; 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate /* 363*7c478bd9Sstevel@tonic-gate * Action depends on code. 364*7c478bd9Sstevel@tonic-gate */ 365*7c478bd9Sstevel@tonic-gate switch (code) { 366*7c478bd9Sstevel@tonic-gate case UPAP_AUTHREQ: 367*7c478bd9Sstevel@tonic-gate upap_rauthreq(u, inp, id, len); 368*7c478bd9Sstevel@tonic-gate break; 369*7c478bd9Sstevel@tonic-gate 370*7c478bd9Sstevel@tonic-gate case UPAP_AUTHACK: 371*7c478bd9Sstevel@tonic-gate upap_rauthack(u, inp, id, len); 372*7c478bd9Sstevel@tonic-gate break; 373*7c478bd9Sstevel@tonic-gate 374*7c478bd9Sstevel@tonic-gate case UPAP_AUTHNAK: 375*7c478bd9Sstevel@tonic-gate upap_rauthnak(u, inp, id, len); 376*7c478bd9Sstevel@tonic-gate break; 377*7c478bd9Sstevel@tonic-gate 378*7c478bd9Sstevel@tonic-gate default: 379*7c478bd9Sstevel@tonic-gate warn("Unknown PAP code (%d) received.", code); 380*7c478bd9Sstevel@tonic-gate break; 381*7c478bd9Sstevel@tonic-gate } 382*7c478bd9Sstevel@tonic-gate } 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate 385*7c478bd9Sstevel@tonic-gate /* 386*7c478bd9Sstevel@tonic-gate * upap_rauth - Receive Authenticate. 387*7c478bd9Sstevel@tonic-gate */ 388*7c478bd9Sstevel@tonic-gate static void 389*7c478bd9Sstevel@tonic-gate upap_rauthreq(u, inp, id, len) 390*7c478bd9Sstevel@tonic-gate upap_state *u; 391*7c478bd9Sstevel@tonic-gate u_char *inp; 392*7c478bd9Sstevel@tonic-gate int id; 393*7c478bd9Sstevel@tonic-gate int len; 394*7c478bd9Sstevel@tonic-gate { 395*7c478bd9Sstevel@tonic-gate u_char ruserlen, rpasswdlen; 396*7c478bd9Sstevel@tonic-gate char *ruser, *rpasswd; 397*7c478bd9Sstevel@tonic-gate int retcode; 398*7c478bd9Sstevel@tonic-gate char *msg; 399*7c478bd9Sstevel@tonic-gate int msglen; 400*7c478bd9Sstevel@tonic-gate 401*7c478bd9Sstevel@tonic-gate if (u->us_serverstate < UPAPSS_LISTEN) { 402*7c478bd9Sstevel@tonic-gate info("PAP: discarded Authenticate-Request in state %s", 403*7c478bd9Sstevel@tonic-gate pap_sstate(u->us_serverstate)); 404*7c478bd9Sstevel@tonic-gate return; 405*7c478bd9Sstevel@tonic-gate } 406*7c478bd9Sstevel@tonic-gate 407*7c478bd9Sstevel@tonic-gate /* 408*7c478bd9Sstevel@tonic-gate * If we receive a duplicate authenticate-request, we are 409*7c478bd9Sstevel@tonic-gate * supposed to return the same status as for the first request. 410*7c478bd9Sstevel@tonic-gate */ 411*7c478bd9Sstevel@tonic-gate if (u->us_serverstate == UPAPSS_OPEN) { 412*7c478bd9Sstevel@tonic-gate /* return auth-ack */ 413*7c478bd9Sstevel@tonic-gate upap_sresp(u, UPAP_AUTHACK, id, u->us_msg, u->us_msglen); 414*7c478bd9Sstevel@tonic-gate return; 415*7c478bd9Sstevel@tonic-gate } 416*7c478bd9Sstevel@tonic-gate if (u->us_serverstate == UPAPSS_BADAUTH) { 417*7c478bd9Sstevel@tonic-gate /* return auth-nak */ 418*7c478bd9Sstevel@tonic-gate upap_sresp(u, UPAP_AUTHNAK, id, u->us_msg, u->us_msglen); 419*7c478bd9Sstevel@tonic-gate return; 420*7c478bd9Sstevel@tonic-gate } 421*7c478bd9Sstevel@tonic-gate 422*7c478bd9Sstevel@tonic-gate /* 423*7c478bd9Sstevel@tonic-gate * Parse user/passwd. 424*7c478bd9Sstevel@tonic-gate */ 425*7c478bd9Sstevel@tonic-gate if (len < 1) { 426*7c478bd9Sstevel@tonic-gate error("PAP: rcvd short packet; no data"); 427*7c478bd9Sstevel@tonic-gate return; 428*7c478bd9Sstevel@tonic-gate } 429*7c478bd9Sstevel@tonic-gate GETCHAR(ruserlen, inp); 430*7c478bd9Sstevel@tonic-gate len -= sizeof (u_char) + ruserlen + sizeof (u_char); 431*7c478bd9Sstevel@tonic-gate if (len < 0) { 432*7c478bd9Sstevel@tonic-gate error("PAP: rcvd short packet; peer name missing"); 433*7c478bd9Sstevel@tonic-gate return; 434*7c478bd9Sstevel@tonic-gate } 435*7c478bd9Sstevel@tonic-gate ruser = (char *) inp; 436*7c478bd9Sstevel@tonic-gate INCPTR(ruserlen, inp); 437*7c478bd9Sstevel@tonic-gate GETCHAR(rpasswdlen, inp); 438*7c478bd9Sstevel@tonic-gate if (len < rpasswdlen) { 439*7c478bd9Sstevel@tonic-gate error("PAP: rcvd short packet; pass len %d < %d", len, rpasswdlen); 440*7c478bd9Sstevel@tonic-gate return; 441*7c478bd9Sstevel@tonic-gate } 442*7c478bd9Sstevel@tonic-gate rpasswd = (char *) inp; 443*7c478bd9Sstevel@tonic-gate 444*7c478bd9Sstevel@tonic-gate /* 445*7c478bd9Sstevel@tonic-gate * Check the username and password given. 446*7c478bd9Sstevel@tonic-gate */ 447*7c478bd9Sstevel@tonic-gate retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd, 448*7c478bd9Sstevel@tonic-gate rpasswdlen, &msg); 449*7c478bd9Sstevel@tonic-gate BZERO(rpasswd, rpasswdlen); 450*7c478bd9Sstevel@tonic-gate msglen = strlen(msg); 451*7c478bd9Sstevel@tonic-gate if (msglen > 255) 452*7c478bd9Sstevel@tonic-gate msglen = 255; 453*7c478bd9Sstevel@tonic-gate 454*7c478bd9Sstevel@tonic-gate u->us_msg = msg; 455*7c478bd9Sstevel@tonic-gate u->us_msglen = msglen; 456*7c478bd9Sstevel@tonic-gate upap_sresp(u, retcode, id, u->us_msg, u->us_msglen); 457*7c478bd9Sstevel@tonic-gate 458*7c478bd9Sstevel@tonic-gate if (retcode == UPAP_AUTHACK) { 459*7c478bd9Sstevel@tonic-gate u->us_serverstate = UPAPSS_OPEN; 460*7c478bd9Sstevel@tonic-gate auth_peer_success(u->us_unit, PPP_PAP, ruser, ruserlen); 461*7c478bd9Sstevel@tonic-gate } else if (++u->us_receives >= u->us_maxreceives) { 462*7c478bd9Sstevel@tonic-gate u->us_serverstate = UPAPSS_BADAUTH; 463*7c478bd9Sstevel@tonic-gate auth_peer_fail(u->us_unit, PPP_PAP); 464*7c478bd9Sstevel@tonic-gate } else { 465*7c478bd9Sstevel@tonic-gate /* Just wait for a good one to arrive, or for time-out. */ 466*7c478bd9Sstevel@tonic-gate return; 467*7c478bd9Sstevel@tonic-gate } 468*7c478bd9Sstevel@tonic-gate 469*7c478bd9Sstevel@tonic-gate if (u->us_reqtimeout > 0) 470*7c478bd9Sstevel@tonic-gate UNTIMEOUT(upap_reqtimeout, u); 471*7c478bd9Sstevel@tonic-gate } 472*7c478bd9Sstevel@tonic-gate 473*7c478bd9Sstevel@tonic-gate 474*7c478bd9Sstevel@tonic-gate /* 475*7c478bd9Sstevel@tonic-gate * upap_rauthack - Receive Authenticate-Ack. 476*7c478bd9Sstevel@tonic-gate */ 477*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 478*7c478bd9Sstevel@tonic-gate static void 479*7c478bd9Sstevel@tonic-gate upap_rauthack(u, inp, id, len) 480*7c478bd9Sstevel@tonic-gate upap_state *u; 481*7c478bd9Sstevel@tonic-gate u_char *inp; 482*7c478bd9Sstevel@tonic-gate int id; 483*7c478bd9Sstevel@tonic-gate int len; 484*7c478bd9Sstevel@tonic-gate { 485*7c478bd9Sstevel@tonic-gate u_char msglen; 486*7c478bd9Sstevel@tonic-gate char *msg; 487*7c478bd9Sstevel@tonic-gate 488*7c478bd9Sstevel@tonic-gate if (u->us_clientstate != UPAPCS_AUTHREQ) { 489*7c478bd9Sstevel@tonic-gate info("PAP: discarded Authenticate-Ack in state %s", 490*7c478bd9Sstevel@tonic-gate pap_cstate(u->us_clientstate)); 491*7c478bd9Sstevel@tonic-gate return; 492*7c478bd9Sstevel@tonic-gate } 493*7c478bd9Sstevel@tonic-gate 494*7c478bd9Sstevel@tonic-gate if (id != u->us_id) { 495*7c478bd9Sstevel@tonic-gate dbglog("PAP: discard Authenticate-Ack; ID %d != %d", 496*7c478bd9Sstevel@tonic-gate id, u->us_id); 497*7c478bd9Sstevel@tonic-gate return; 498*7c478bd9Sstevel@tonic-gate } 499*7c478bd9Sstevel@tonic-gate 500*7c478bd9Sstevel@tonic-gate if (u->us_timeouttime > 0) 501*7c478bd9Sstevel@tonic-gate UNTIMEOUT(upap_timeout, u); 502*7c478bd9Sstevel@tonic-gate 503*7c478bd9Sstevel@tonic-gate /* 504*7c478bd9Sstevel@tonic-gate * Parse message. 505*7c478bd9Sstevel@tonic-gate */ 506*7c478bd9Sstevel@tonic-gate if (len < 1) { 507*7c478bd9Sstevel@tonic-gate info("PAP: Ignoring missing ack msg-length octet"); 508*7c478bd9Sstevel@tonic-gate } else { 509*7c478bd9Sstevel@tonic-gate GETCHAR(msglen, inp); 510*7c478bd9Sstevel@tonic-gate if (msglen > 0) { 511*7c478bd9Sstevel@tonic-gate len -= sizeof (u_char); 512*7c478bd9Sstevel@tonic-gate if (len < msglen) { 513*7c478bd9Sstevel@tonic-gate error("PAP: Discarding short packet (%d < %d)", len, msglen); 514*7c478bd9Sstevel@tonic-gate return; 515*7c478bd9Sstevel@tonic-gate } 516*7c478bd9Sstevel@tonic-gate msg = (char *) inp; 517*7c478bd9Sstevel@tonic-gate PRINTMSG(msg, msglen); 518*7c478bd9Sstevel@tonic-gate } 519*7c478bd9Sstevel@tonic-gate } 520*7c478bd9Sstevel@tonic-gate 521*7c478bd9Sstevel@tonic-gate u->us_clientstate = UPAPCS_OPEN; 522*7c478bd9Sstevel@tonic-gate 523*7c478bd9Sstevel@tonic-gate auth_withpeer_success(u->us_unit, PPP_PAP); 524*7c478bd9Sstevel@tonic-gate } 525*7c478bd9Sstevel@tonic-gate 526*7c478bd9Sstevel@tonic-gate 527*7c478bd9Sstevel@tonic-gate /* 528*7c478bd9Sstevel@tonic-gate * upap_rauthnak - Receive Authenticate-Nakk. 529*7c478bd9Sstevel@tonic-gate */ 530*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 531*7c478bd9Sstevel@tonic-gate static void 532*7c478bd9Sstevel@tonic-gate upap_rauthnak(u, inp, id, len) 533*7c478bd9Sstevel@tonic-gate upap_state *u; 534*7c478bd9Sstevel@tonic-gate u_char *inp; 535*7c478bd9Sstevel@tonic-gate int id; 536*7c478bd9Sstevel@tonic-gate int len; 537*7c478bd9Sstevel@tonic-gate { 538*7c478bd9Sstevel@tonic-gate u_char msglen; 539*7c478bd9Sstevel@tonic-gate char *msg; 540*7c478bd9Sstevel@tonic-gate 541*7c478bd9Sstevel@tonic-gate if (u->us_clientstate != UPAPCS_AUTHREQ) { 542*7c478bd9Sstevel@tonic-gate info("PAP: discarded Authenticate-Nak in state %s", 543*7c478bd9Sstevel@tonic-gate pap_cstate(u->us_clientstate)); 544*7c478bd9Sstevel@tonic-gate return; 545*7c478bd9Sstevel@tonic-gate } 546*7c478bd9Sstevel@tonic-gate 547*7c478bd9Sstevel@tonic-gate if (id != u->us_id) { 548*7c478bd9Sstevel@tonic-gate dbglog("PAP: discard Authenticate-Ack; ID %d != %d", 549*7c478bd9Sstevel@tonic-gate id, u->us_id); 550*7c478bd9Sstevel@tonic-gate return; 551*7c478bd9Sstevel@tonic-gate } 552*7c478bd9Sstevel@tonic-gate 553*7c478bd9Sstevel@tonic-gate if (u->us_timeouttime > 0) 554*7c478bd9Sstevel@tonic-gate UNTIMEOUT(upap_timeout, u); 555*7c478bd9Sstevel@tonic-gate 556*7c478bd9Sstevel@tonic-gate /* 557*7c478bd9Sstevel@tonic-gate * Parse message. 558*7c478bd9Sstevel@tonic-gate */ 559*7c478bd9Sstevel@tonic-gate if (len < 1) { 560*7c478bd9Sstevel@tonic-gate error("PAP: ignoring missing nak msg-length octet"); 561*7c478bd9Sstevel@tonic-gate } else { 562*7c478bd9Sstevel@tonic-gate GETCHAR(msglen, inp); 563*7c478bd9Sstevel@tonic-gate if (msglen > 0) { 564*7c478bd9Sstevel@tonic-gate len -= sizeof (u_char); 565*7c478bd9Sstevel@tonic-gate if (len < msglen) { 566*7c478bd9Sstevel@tonic-gate error("PAP: Discarding short packet (%d < %d)", len, msglen); 567*7c478bd9Sstevel@tonic-gate return; 568*7c478bd9Sstevel@tonic-gate } 569*7c478bd9Sstevel@tonic-gate msg = (char *) inp; 570*7c478bd9Sstevel@tonic-gate PRINTMSG(msg, msglen); 571*7c478bd9Sstevel@tonic-gate } 572*7c478bd9Sstevel@tonic-gate } 573*7c478bd9Sstevel@tonic-gate 574*7c478bd9Sstevel@tonic-gate /* Try to get a new password from the plugin. */ 575*7c478bd9Sstevel@tonic-gate if (pap_passwd_hook != NULL) { 576*7c478bd9Sstevel@tonic-gate if (u->us_transmits < u->us_maxtransmits) { 577*7c478bd9Sstevel@tonic-gate if ((*pap_passwd_hook)(user, passwd) >= 0) { 578*7c478bd9Sstevel@tonic-gate upap_sauthreq(u); 579*7c478bd9Sstevel@tonic-gate return; 580*7c478bd9Sstevel@tonic-gate } 581*7c478bd9Sstevel@tonic-gate } else { 582*7c478bd9Sstevel@tonic-gate /* Tell plug-in that we're giving up. */ 583*7c478bd9Sstevel@tonic-gate (void) (*pap_passwd_hook)(NULL, NULL); 584*7c478bd9Sstevel@tonic-gate } 585*7c478bd9Sstevel@tonic-gate } 586*7c478bd9Sstevel@tonic-gate 587*7c478bd9Sstevel@tonic-gate u->us_clientstate = UPAPCS_BADAUTH; 588*7c478bd9Sstevel@tonic-gate 589*7c478bd9Sstevel@tonic-gate error("PAP authentication failed"); 590*7c478bd9Sstevel@tonic-gate auth_withpeer_fail(u->us_unit, PPP_PAP); 591*7c478bd9Sstevel@tonic-gate } 592*7c478bd9Sstevel@tonic-gate 593*7c478bd9Sstevel@tonic-gate 594*7c478bd9Sstevel@tonic-gate /* 595*7c478bd9Sstevel@tonic-gate * upap_sauthreq - Send an Authenticate-Request. 596*7c478bd9Sstevel@tonic-gate */ 597*7c478bd9Sstevel@tonic-gate static void 598*7c478bd9Sstevel@tonic-gate upap_sauthreq(u) 599*7c478bd9Sstevel@tonic-gate upap_state *u; 600*7c478bd9Sstevel@tonic-gate { 601*7c478bd9Sstevel@tonic-gate u_char *outp; 602*7c478bd9Sstevel@tonic-gate int pwlen; 603*7c478bd9Sstevel@tonic-gate int outlen; 604*7c478bd9Sstevel@tonic-gate 605*7c478bd9Sstevel@tonic-gate pwlen = strllen(passwd, MAXSECRETLEN); 606*7c478bd9Sstevel@tonic-gate if (pwlen > 0xFF) 607*7c478bd9Sstevel@tonic-gate pwlen = 0xFF; 608*7c478bd9Sstevel@tonic-gate outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) + u->us_userlen + pwlen; 609*7c478bd9Sstevel@tonic-gate outp = outpacket_buf; 610*7c478bd9Sstevel@tonic-gate 611*7c478bd9Sstevel@tonic-gate MAKEHEADER(outp, PPP_PAP); 612*7c478bd9Sstevel@tonic-gate 613*7c478bd9Sstevel@tonic-gate PUTCHAR(UPAP_AUTHREQ, outp); 614*7c478bd9Sstevel@tonic-gate PUTCHAR(++u->us_id, outp); 615*7c478bd9Sstevel@tonic-gate PUTSHORT(outlen, outp); 616*7c478bd9Sstevel@tonic-gate PUTCHAR(u->us_userlen, outp); 617*7c478bd9Sstevel@tonic-gate BCOPY(u->us_user, outp, u->us_userlen); 618*7c478bd9Sstevel@tonic-gate INCPTR(u->us_userlen, outp); 619*7c478bd9Sstevel@tonic-gate PUTCHAR(pwlen, outp); 620*7c478bd9Sstevel@tonic-gate BCOPY(u->us_passwd, outp, pwlen); 621*7c478bd9Sstevel@tonic-gate 622*7c478bd9Sstevel@tonic-gate output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN); 623*7c478bd9Sstevel@tonic-gate 624*7c478bd9Sstevel@tonic-gate if (u->us_timeouttime > 0) 625*7c478bd9Sstevel@tonic-gate TIMEOUT(upap_timeout, u, u->us_timeouttime); 626*7c478bd9Sstevel@tonic-gate ++u->us_transmits; 627*7c478bd9Sstevel@tonic-gate u->us_clientstate = UPAPCS_AUTHREQ; 628*7c478bd9Sstevel@tonic-gate } 629*7c478bd9Sstevel@tonic-gate 630*7c478bd9Sstevel@tonic-gate 631*7c478bd9Sstevel@tonic-gate /* 632*7c478bd9Sstevel@tonic-gate * upap_sresp - Send a response (ack or nak). 633*7c478bd9Sstevel@tonic-gate */ 634*7c478bd9Sstevel@tonic-gate static void 635*7c478bd9Sstevel@tonic-gate upap_sresp(u, code, id, msg, msglen) 636*7c478bd9Sstevel@tonic-gate upap_state *u; 637*7c478bd9Sstevel@tonic-gate u_char code, id; 638*7c478bd9Sstevel@tonic-gate char *msg; 639*7c478bd9Sstevel@tonic-gate int msglen; 640*7c478bd9Sstevel@tonic-gate { 641*7c478bd9Sstevel@tonic-gate u_char *outp; 642*7c478bd9Sstevel@tonic-gate int outlen; 643*7c478bd9Sstevel@tonic-gate 644*7c478bd9Sstevel@tonic-gate outlen = UPAP_HEADERLEN + sizeof (u_char) + msglen; 645*7c478bd9Sstevel@tonic-gate outp = outpacket_buf; 646*7c478bd9Sstevel@tonic-gate MAKEHEADER(outp, PPP_PAP); 647*7c478bd9Sstevel@tonic-gate 648*7c478bd9Sstevel@tonic-gate PUTCHAR(code, outp); 649*7c478bd9Sstevel@tonic-gate PUTCHAR(id, outp); 650*7c478bd9Sstevel@tonic-gate PUTSHORT(outlen, outp); 651*7c478bd9Sstevel@tonic-gate PUTCHAR(msglen, outp); 652*7c478bd9Sstevel@tonic-gate BCOPY(msg, outp, msglen); 653*7c478bd9Sstevel@tonic-gate output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN); 654*7c478bd9Sstevel@tonic-gate } 655*7c478bd9Sstevel@tonic-gate 656*7c478bd9Sstevel@tonic-gate /* 657*7c478bd9Sstevel@tonic-gate * upap_printpkt - print the contents of a PAP packet. 658*7c478bd9Sstevel@tonic-gate */ 659*7c478bd9Sstevel@tonic-gate static char *upap_codenames[] = { 660*7c478bd9Sstevel@tonic-gate "AuthReq", "AuthAck", "AuthNak" 661*7c478bd9Sstevel@tonic-gate }; 662*7c478bd9Sstevel@tonic-gate 663*7c478bd9Sstevel@tonic-gate static int 664*7c478bd9Sstevel@tonic-gate upap_printpkt(p, plen, printer, arg) 665*7c478bd9Sstevel@tonic-gate u_char *p; 666*7c478bd9Sstevel@tonic-gate int plen; 667*7c478bd9Sstevel@tonic-gate void (*printer) __P((void *, const char *, ...)); 668*7c478bd9Sstevel@tonic-gate void *arg; 669*7c478bd9Sstevel@tonic-gate { 670*7c478bd9Sstevel@tonic-gate int code, id, len; 671*7c478bd9Sstevel@tonic-gate int mlen, ulen, wlen; 672*7c478bd9Sstevel@tonic-gate char *user, *pwd, *msg; 673*7c478bd9Sstevel@tonic-gate u_char *pstart; 674*7c478bd9Sstevel@tonic-gate 675*7c478bd9Sstevel@tonic-gate if (plen < UPAP_HEADERLEN) 676*7c478bd9Sstevel@tonic-gate return (0); 677*7c478bd9Sstevel@tonic-gate pstart = p; 678*7c478bd9Sstevel@tonic-gate GETCHAR(code, p); 679*7c478bd9Sstevel@tonic-gate GETCHAR(id, p); 680*7c478bd9Sstevel@tonic-gate GETSHORT(len, p); 681*7c478bd9Sstevel@tonic-gate if (len < UPAP_HEADERLEN || len > plen) 682*7c478bd9Sstevel@tonic-gate return (0); 683*7c478bd9Sstevel@tonic-gate 684*7c478bd9Sstevel@tonic-gate if (code >= 1 && code <= Dim(upap_codenames)) 685*7c478bd9Sstevel@tonic-gate printer(arg, " %s", upap_codenames[code-1]); 686*7c478bd9Sstevel@tonic-gate else 687*7c478bd9Sstevel@tonic-gate printer(arg, " code=0x%x", code); 688*7c478bd9Sstevel@tonic-gate printer(arg, " id=0x%x", id); 689*7c478bd9Sstevel@tonic-gate len -= UPAP_HEADERLEN; 690*7c478bd9Sstevel@tonic-gate switch (code) { 691*7c478bd9Sstevel@tonic-gate case UPAP_AUTHREQ: 692*7c478bd9Sstevel@tonic-gate if (len < 1) 693*7c478bd9Sstevel@tonic-gate break; 694*7c478bd9Sstevel@tonic-gate ulen = p[0]; 695*7c478bd9Sstevel@tonic-gate if (len < ulen + 2) 696*7c478bd9Sstevel@tonic-gate break; 697*7c478bd9Sstevel@tonic-gate wlen = p[ulen + 1]; 698*7c478bd9Sstevel@tonic-gate if (len < ulen + wlen + 2) 699*7c478bd9Sstevel@tonic-gate break; 700*7c478bd9Sstevel@tonic-gate user = (char *) (p + 1); 701*7c478bd9Sstevel@tonic-gate pwd = (char *) (p + ulen + 2); 702*7c478bd9Sstevel@tonic-gate p += ulen + wlen + 2; 703*7c478bd9Sstevel@tonic-gate len -= ulen + wlen + 2; 704*7c478bd9Sstevel@tonic-gate printer(arg, " user="); 705*7c478bd9Sstevel@tonic-gate print_string(user, ulen, printer, arg); 706*7c478bd9Sstevel@tonic-gate printer(arg, " password="); 707*7c478bd9Sstevel@tonic-gate if (!hide_password) 708*7c478bd9Sstevel@tonic-gate print_string(pwd, wlen, printer, arg); 709*7c478bd9Sstevel@tonic-gate else 710*7c478bd9Sstevel@tonic-gate printer(arg, "<hidden>"); 711*7c478bd9Sstevel@tonic-gate break; 712*7c478bd9Sstevel@tonic-gate case UPAP_AUTHACK: 713*7c478bd9Sstevel@tonic-gate case UPAP_AUTHNAK: 714*7c478bd9Sstevel@tonic-gate if (len < 1) 715*7c478bd9Sstevel@tonic-gate break; 716*7c478bd9Sstevel@tonic-gate mlen = p[0]; 717*7c478bd9Sstevel@tonic-gate if (len < mlen + 1) 718*7c478bd9Sstevel@tonic-gate break; 719*7c478bd9Sstevel@tonic-gate msg = (char *) (p + 1); 720*7c478bd9Sstevel@tonic-gate p += mlen + 1; 721*7c478bd9Sstevel@tonic-gate len -= mlen + 1; 722*7c478bd9Sstevel@tonic-gate printer(arg, " "); 723*7c478bd9Sstevel@tonic-gate print_string(msg, mlen, printer, arg); 724*7c478bd9Sstevel@tonic-gate break; 725*7c478bd9Sstevel@tonic-gate } 726*7c478bd9Sstevel@tonic-gate 727*7c478bd9Sstevel@tonic-gate /* print the rest of the bytes in the packet */ 728*7c478bd9Sstevel@tonic-gate for (; len > 0; --len) { 729*7c478bd9Sstevel@tonic-gate GETCHAR(code, p); 730*7c478bd9Sstevel@tonic-gate printer(arg, " %.2x", code); 731*7c478bd9Sstevel@tonic-gate } 732*7c478bd9Sstevel@tonic-gate 733*7c478bd9Sstevel@tonic-gate return (p - pstart); 734*7c478bd9Sstevel@tonic-gate } 735