pap.c (6060) | pap.c (6735) |
---|---|
1/* 2 * PPP PAP Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993-94, Internet Initiative Japan, Inc. 7 * All rights reserverd. 8 * --- 5 unchanged lines hidden (view full) --- 14 * by the Internet Initiative Japan, Inc. The name of the 15 * IIJ may not be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * $Id:$ | 1/* 2 * PPP PAP Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993-94, Internet Initiative Japan, Inc. 7 * All rights reserverd. 8 * --- 5 unchanged lines hidden (view full) --- 14 * by the Internet Initiative Japan, Inc. The name of the 15 * IIJ may not be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * $Id:$ |
22 * | 22 * |
23 * TODO: | 23 * TODO: |
24 * o Imprement retransmission timer. | |
25 */ 26#include "fsm.h" 27#include "lcp.h" 28#include "pap.h" 29#include "vars.h" 30#include "hdlc.h" 31#include "lcpproto.h" 32#include "phase.h" | 24 */ 25#include "fsm.h" 26#include "lcp.h" 27#include "pap.h" 28#include "vars.h" 29#include "hdlc.h" 30#include "lcpproto.h" 31#include "phase.h" |
32#include "auth.h" |
|
33 34static char *papcodes[] = { 35 "???", "REQUEST", "ACK", "NAK" 36}; 37 | 33 34static char *papcodes[] = { 35 "???", "REQUEST", "ACK", "NAK" 36}; 37 |
38static int papid; | 38struct authinfo AuthPapInfo = { 39 SendPapChallenge, 40}; |
39 40void | 41 42void |
41SendPapChallenge() | 43SendPapChallenge(papid) 44int papid; |
42{ 43 struct fsmheader lh; 44 struct mbuf *bp; 45 u_char *cp; 46 int namelen, keylen, plen; 47 48 namelen = strlen(VarAuthName); 49 keylen = strlen(VarAuthKey); 50 plen = namelen + keylen + 2; 51#ifdef DEBUG 52 logprintf("namelen = %d, keylen = %d\n", namelen, keylen); | 45{ 46 struct fsmheader lh; 47 struct mbuf *bp; 48 u_char *cp; 49 int namelen, keylen, plen; 50 51 namelen = strlen(VarAuthName); 52 keylen = strlen(VarAuthKey); 53 plen = namelen + keylen + 2; 54#ifdef DEBUG 55 logprintf("namelen = %d, keylen = %d\n", namelen, keylen); |
53 LogPrintf(LOG_PHASE, "PAP: %s (%s)\n", VarAuthName, VarAuthKey); | |
54#endif | 56#endif |
57 LogPrintf(LOG_PHASE, "PAP: %s (%s)\n", VarAuthName, VarAuthKey); |
|
55 lh.code = PAP_REQUEST; | 58 lh.code = PAP_REQUEST; |
56 lh.id = ++papid; | 59 lh.id = papid; |
57 lh.length = htons(plen + sizeof(struct fsmheader)); 58 bp = mballoc(plen + sizeof(struct fsmheader), MB_FSM); 59 bcopy(&lh, MBUF_CTOP(bp), sizeof(struct fsmheader)); 60 cp = MBUF_CTOP(bp) + sizeof(struct fsmheader); 61 *cp++ = namelen; 62 bcopy(VarAuthName, cp, namelen); 63 cp += namelen; 64 *cp++ = keylen; --- 35 unchanged lines hidden (view full) --- 100u_char *name, *key; 101{ 102 int nlen, klen; 103 104 nlen = *name++; 105 klen = *key; 106 *key++ = 0; 107 key[klen] = 0; | 60 lh.length = htons(plen + sizeof(struct fsmheader)); 61 bp = mballoc(plen + sizeof(struct fsmheader), MB_FSM); 62 bcopy(&lh, MBUF_CTOP(bp), sizeof(struct fsmheader)); 63 cp = MBUF_CTOP(bp) + sizeof(struct fsmheader); 64 *cp++ = namelen; 65 bcopy(VarAuthName, cp, namelen); 66 cp += namelen; 67 *cp++ = keylen; --- 35 unchanged lines hidden (view full) --- 103u_char *name, *key; 104{ 105 int nlen, klen; 106 107 nlen = *name++; 108 klen = *key; 109 *key++ = 0; 110 key[klen] = 0; |
111#ifdef DEBUG |
|
108 logprintf("name: %s (%d), key: %s (%d)\n", name, nlen, key, klen); | 112 logprintf("name: %s (%d), key: %s (%d)\n", name, nlen, key, klen); |
113#endif |
|
109 return(AuthValidate(SECRETFILE, name, key)); 110} 111 112void 113PapInput(bp) 114struct mbuf *bp; 115{ 116 int len = plength(bp); --- 17 unchanged lines hidden (view full) --- 134 if (lcp->auth_iwait == 0) 135 NewPhase(PHASE_NETWORK); 136 } else { 137 SendPapCode(php->id, PAP_NAK, "Login incorrect"); 138 LcpClose(); 139 } 140 break; 141 case PAP_ACK: | 114 return(AuthValidate(SECRETFILE, name, key)); 115} 116 117void 118PapInput(bp) 119struct mbuf *bp; 120{ 121 int len = plength(bp); --- 17 unchanged lines hidden (view full) --- 139 if (lcp->auth_iwait == 0) 140 NewPhase(PHASE_NETWORK); 141 } else { 142 SendPapCode(php->id, PAP_NAK, "Login incorrect"); 143 LcpClose(); 144 } 145 break; 146 case PAP_ACK: |
147 StopAuthTimer(&AuthPapInfo); |
|
142 cp = (u_char *)(php + 1); 143 len = *cp++; 144 cp[len] = 0; 145 LogPrintf(LOG_PHASE, "Received PAP_ACK (%s)\n", cp); 146 if (lcp->auth_iwait == PROTO_PAP) { 147 lcp->auth_iwait = 0; 148 if (lcp->auth_ineed == 0) 149 NewPhase(PHASE_NETWORK); 150 } 151 break; 152 case PAP_NAK: | 148 cp = (u_char *)(php + 1); 149 len = *cp++; 150 cp[len] = 0; 151 LogPrintf(LOG_PHASE, "Received PAP_ACK (%s)\n", cp); 152 if (lcp->auth_iwait == PROTO_PAP) { 153 lcp->auth_iwait = 0; 154 if (lcp->auth_ineed == 0) 155 NewPhase(PHASE_NETWORK); 156 } 157 break; 158 case PAP_NAK: |
159 StopAuthTimer(&AuthPapInfo); |
|
153 cp = (u_char *)(php + 1); 154 len = *cp++; 155 cp[len] = 0; 156 LogPrintf(LOG_PHASE, "Received PAP_NAK (%s)\n", cp); 157 LcpClose(); 158 break; 159 } 160 } 161 } 162 pfree(bp); 163} | 160 cp = (u_char *)(php + 1); 161 len = *cp++; 162 cp[len] = 0; 163 LogPrintf(LOG_PHASE, "Received PAP_NAK (%s)\n", cp); 164 LcpClose(); 165 break; 166 } 167 } 168 } 169 pfree(bp); 170} |