⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pppchapcomponent.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* pppChapComponent.c - Challenge Handshake Authentication Protocol *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01s,07aug03,rp  updating include path for random.h and message digest01r,12dec02,ijm merged fix for SPR#76442, check name and password lengths01q,05nov02,ijm use printf instead of logMsg01p,28may02,rvr fixed build warnings01o,23feb03,jr  setting the pointers to NULL after freeing01n,22feb02,ak	input parameter validations in AUTH_INFO_INTERFACE functions01m,12feb02,ijm corrected PPP_DEBUG message in chapReceive01l,08nov01,ijm trim excess bytes from received packet,SPR#6433401k,20jun01,ak	AUTH_INFO_INTERFACE01j,28feb01,ijm release interfaces when stack is deleted (SPR# 63868)01i,16dec00,md  in ...ChallengeOrRetry() check if retry count >= max_retries01h,17apr00,sj  get mBufs from framework netpool01g,23mar00,sj  store chap response id separately01f,15mar00,sj  random_number_string should be of size 16 for 16 byte challenge01e,08mar00,sj  send 16 byte challenge, new challenge on each retry,ACK and NAK             	packets do not have message_length field.01d,08mar00,sj  set "padding" member of ACK and NAK message to '!' + generate             	new challenge packet for each retry01c,23feb00,sj  Pedantic ANSI C fixes01b,30nov99,sj  removing debug Messages01a,23oct99,sgv  created from routerware source*//*DESCRIPTIONThis component implements the Challenge Handshake Authentication Protocolspecified in RFC 1994*/#include "vxWorks.h"#include "logLib.h"#include "tickLib.h"#include "errnoLib.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "ctype.h"#include "memLib.h"#include "netBufLib.h"#include "sockLib.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "pfw/pfwProfile.h"#include "pfw/pfwComponent.h"#include "pfw/pfwLayer.h"#include "pfw/pfwEvent.h"#include "pfw/pfwTimer.h"#include "pfw/pfwInterface.h"#include "pfw/pfwMemory.h"#include "ppp/kstart.h"#include "ppp/kppp.h"#include "private/ppp/vpppstr.h"#include "private/ppp/vlcpstr.h"#include "private/ppp/vpppastr.h"#include "private/ppp/pppoptn.h"#include "ppp/interfaces/pppControlLayerInterface.h"#include "ppp/interfaces/pppControlProtocolInterface.h"#include "ppp/interfaces/lcpInterfaces.h"#include "ppp/pppChapComponent.h"#include "ppp/interfaces/authInfoInterface.h" /* WindNet Multilink */#include "wrn/util/mdLib.h"#include "wrn/util/random.h"#define CHAP_DEFAULT_MAX_RETRIES 8#define CHAP_DEFAULT_RETRY_TIMEOUT 5#define CHAP_DEFAULT_CHALLENGE_INTERVAL 30#define CHAP_CHALLENGE_INITIAL 0/*#define CHAP_CHALLENGE_RETRY 1*/typedef struct pppChapComponent    {    PFW_COMPONENT_OBJ component;    FPTR_AUTH_PACKET_RECEIVED      		    fptr_chap_packet_rxed[12]; /* TO DO #define the number */    CONTROL_PROTOCOL_INTERFACE chapControlInterface;	AUTH_INFO_INTERFACE			authMpInterface; /* WindNet Multilink */    } PPP_CHAP_COMPONENT;typedef struct chapProfileData    {    char                                  localUserName[NAME_SIZE];    USHORT                                maximum_number_of_retries;    ULONG                       	  retryInterval;    ULONG                       	  challengeInterval;    } CHAP_PROFILE_DATA;typedef struct chapStackData    {    PPP_STATE                             serverState;    PPP_STATE                             clientState;    BYTE_ENUM(BOOLEAN)                    serverEnabled;    BYTE_ENUM(BOOLEAN)                    clientEnabled;    BYTE_ENUM(BOOLEAN)                    state;    PPP_AUTHENTICATION_STATISTICS         statistics;    USHORT                                current_number_of_retries;    ULONG                                 number_of_authentication_requests;    char                                  challenge[CHALLENGE_VALUE_SIZE];    char                                  peer_user_name[NAME_SIZE];    char                                  peer_response[RESPONSE_VALUE_SIZE];    BYTE                                  id_sequence_number;    BYTE                                  id;    USHORT				  last_id_of_chap_packet_sent;    USHORT				  last_id_of_chap_response_sent;    PFW_TIMER_OBJ                       * retryTimer;    PFW_TIMER_OBJ                       * challengeTimer;    PFW_INTERFACE_STATE_PAIR              lcpNegotiatedAuthProtocols;    M_BLK_ID                              challengePacket;    M_BLK_ID                              lastSentResponsePacket;    PPP_CONTROL_LAYER_INTERFACE   	  *controlLayerInterface;    PFW_PLUGIN_OBJ_CALLBACKS    	  *callbacks;    } CHAP_STACK_DATA;LOCAL void send_chap_authentication_ack (PFW_PLUGIN_OBJ_STATE * state, 	BYTE id_from_request_packet);LOCAL void send_chap_authentication_nak (PFW_PLUGIN_OBJ_STATE * state, 	BYTE id_from_request_packet);    /* component interfaces */LOCAL STATUS stackAdd (PFW_PLUGIN_OBJ_STATE *state, 					PFW_PLUGIN_OBJ_CALLBACKS * callbacks);LOCAL STATUS stackDelete (PFW_PLUGIN_OBJ_STATE *state);LOCAL STATUS profileDataConstruct (PFW_OBJ *pfw, void *profileData);LOCAL STATUS chapInterfaceBind (PFW_PLUGIN_OBJ * pluginObj);LOCAL STATUS stackDataConstruct (PFW_OBJ *pfw, void * stackData,							 void * profileData);LOCAL STATUS chapReceive (PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID * pkt);LOCAL STATUS chapSend (PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID * pkt);/* control layer interfaces */LOCAL PPP_CONTROL_PHASE chap_pppPhaseGet ();LOCAL PPP_STATE chap_pppStateGet (PFW_PLUGIN_OBJ_STATE * state);LOCAL void send_authentication_packet (PFW_PLUGIN_OBJ_STATE * state,					M_BLK_ID packet, BYTE code,					BYTE id, USHORT protocol_type);LOCAL void chap_initialize_restart_counter (PFW_PLUGIN_OBJ_STATE *pluginState);    /* my callbacks */LOCAL void chapCallback (PFW_PLUGIN_OBJ_STATE *, BYTE id, TEST);    /* timer handlers */LOCAL STATUS sendChapPeriodicChallengeOrRetry ( PFW_PLUGIN_OBJ_STATE *,int);LOCAL STATUS sendChapResponseRetry ( PFW_PLUGIN_OBJ_STATE *,int);    /* misc */LOCAL ULONG get_my_random_number (void);/* parameter handlers */LOCAL STATUS chap_localUserName ( PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE type,					    void * profileData, char * value);LOCAL STATUS chap_maxRetries ( PFW_OBJ *,PFW_PARAMETER_OPERATION_TYPE type,					    void * profileData, char * value);LOCAL STATUS chap_retryInterval ( PFW_OBJ *,PFW_PARAMETER_OPERATION_TYPE type,					    void * profileData, char * value);LOCAL STATUS chap_challengeInterval(PFW_OBJ *,PFW_PARAMETER_OPERATION_TYPE ,					    void * profileData, char * value);LOCAL M_BLK_ID chapDupPkt (M_BLK_ID pPacket);LOCAL void send_chap_server_packet ( PFW_PLUGIN_OBJ_STATE * state); LOCAL void chapStateMachine ( PFW_PLUGIN_OBJ_STATE *, PPP_EVENT, M_BLK_ID);/* WindNet Multilink */void chapLocalUserNameGet (PFW_PLUGIN_OBJ_STATE *, char *);void chapRemoteUserNameGet (PFW_PLUGIN_OBJ_STATE *, char *);void chapLocalUserNameSet (PFW_PLUGIN_OBJ_STATE *, char *);/******************************************************************************** pppChapComponentCreate - initialize and add CHAP component to the framework** This component implements RFC 1994** RETURNS: OK or ERROR*/STATUS pppChapComponentCreate   (   PFW_OBJ *pfw   )   {   PPP_CHAP_COMPONENT *pChapComponent;   PFW_PLUGIN_OBJ *chapPluginObj;   pChapComponent = (PPP_CHAP_COMPONENT *) pfwMalloc (pfw,					    sizeof (PPP_CHAP_COMPONENT));   if (pChapComponent == NULL)       {       printf ("pppChapInit - Unable to allocate memory of size %d byte s\n",                (int)sizeof (PPP_CHAP_COMPONENT));       return (ERROR);       }   memset((void *)pChapComponent,0,sizeof(PPP_CHAP_COMPONENT));   chapPluginObj = (PFW_PLUGIN_OBJ *)&pChapComponent->component;     strcpy (chapPluginObj->name, "PPP_CHAP");   chapPluginObj->pfwObj = pfw;   pChapComponent->component.layerObj = pfwLayerObjGet (pfw, "CONTROL_LAYER");   pChapComponent->component.protocol = CHAP_PROTOCOL;   chapPluginObj->profileDataSize = sizeof (CHAP_PROFILE_DATA);   chapPluginObj->stackDataSize = sizeof (CHAP_STACK_DATA);   chapPluginObj->profileDataConstruct = profileDataConstruct;   chapPluginObj->profileDataCopy = NULL;   chapPluginObj->profileDataDestruct = NULL;   chapPluginObj->interfaceBind = chapInterfaceBind;   chapPluginObj->receive = chapReceive;   chapPluginObj->send = chapSend;   chapPluginObj->stackAdd = stackAdd;   chapPluginObj->stackDelete = stackDelete;   chapPluginObj->stackDataShow = NULL;   chapPluginObj->stackDataConstruct = stackDataConstruct;   chapPluginObj->stackDataDestruct = NULL;   if (pfwComponentAdd (&pChapComponent->component) == ERROR)        {        printf ("pppChapInit - CHAP could not be added to the framework\n");        return (ERROR);        }   pfwParameterAdd (chapPluginObj, "chap_localUserName", chap_localUserName);   pfwParameterAdd (chapPluginObj, "chap_maxRetries", chap_maxRetries);   pfwParameterAdd (chapPluginObj, "chap_retryInterval", chap_retryInterval);   pfwParameterAdd (chapPluginObj, "chap_challengeInterval",						   chap_challengeInterval);   return (OK);   }/******************************************************************************** pppChapComponentDelete - delete CHAP component from the framework** The CHAP plug-in component object allocated by pppChapComponentCreate() is * freed if there are no references to this object from a * Stack or Profile object in the framework.** RETURNS: OK or ERROR*/STATUS pppChapComponentDelete   (   PFW_OBJ *pfw	/* framework */   )   {    PFW_COMPONENT_OBJ *pComponent;    pComponent = pfwComponentObjGetByName(pfw,"PPP_CHAP");    if (pComponent == NULL)	return ERROR;    if (pfwComponentDelete(pComponent) == OK)	{        pfwFree(pComponent);        pComponent = NULL;	return OK;	}   return ERROR;   }/********************************************************************************* chapInterfaceBind -*/LOCAL STATUS chapInterfaceBind    (    PFW_PLUGIN_OBJ * pluginObj    )    {    int id;    PPP_CHAP_COMPONENT * pComponent = (PPP_CHAP_COMPONENT *)pluginObj;	AUTH_INFO_INTERFACE	*pAuthMpInterface;	/* WindNet Multilink */    CONTROL_PROTOCOL_INTERFACE * chapControlInterface =					    &pComponent->chapControlInterface;    if ((id = pfwInterfaceIdGet(pluginObj->pfwObj,					    "CONTROL_PROTOCOL_INTERFACE")) > 0)        {        chapControlInterface->interfaceObj.id = id;        chapControlInterface->interfaceObj.pluginObj = pluginObj;        chapControlInterface->pppPhaseGet = chap_pppPhaseGet;        chapControlInterface->pppStateGet = chap_pppStateGet;        chapControlInterface->executeStateMachine = chapStateMachine;        pfwInterfaceBind (&chapControlInterface->interfaceObj);        }/* WindNet Multilink */	pAuthMpInterface = &pComponent->authMpInterface;      if ((id = pfwInterfaceIdGet(pluginObj->pfwObj,						    "AUTH_INFO_INTERFACE")) > 0)        {        pAuthMpInterface->interfaceObj.id = id;        pAuthMpInterface->interfaceObj.pluginObj = pluginObj;        pAuthMpInterface->localUserNameGet= chapLocalUserNameGet;        pAuthMpInterface->remoteUserNameGet = chapRemoteUserNameGet;        pAuthMpInterface->localUserNameSet = chapLocalUserNameSet;        pfwInterfaceBind (&pAuthMpInterface->interfaceObj);        }/* WindNet Multilink */    return OK;    }/********************************************************************************* chapSend -*/LOCAL STATUS chapSend   (   PFW_PLUGIN_OBJ_STATE *state,   M_BLK_ID        * pkt   )   {   return (OK);   }/******************************************************************************** stackAdd -*/LOCAL STATUS stackAdd    (    PFW_PLUGIN_OBJ_STATE *state,    PFW_PLUGIN_OBJ_CALLBACKS * callbacks    )    {    int id;    CHAP_STACK_DATA *pStackData = (CHAP_STACK_DATA *)state->stackData;    PFW_LAYER_OBJ * layerObj =		    ((PFW_COMPONENT_OBJ *)state->pluginObj)->layerObj;    pStackData->callbacks = callbacks;    if ((pStackData->retryTimer = pfwTimerCreate(state)) == NULL)	return ERROR;    if ((pStackData->challengeTimer = pfwTimerCreate(state)) == NULL)	return ERROR;    if ((id = pfwInterfaceIdGet(state->pluginObj->pfwObj,                                "PPP_CONTROL_LAYER_INTERFACE")) > 0)        {        pStackData->controlLayerInterface =                    (PPP_CONTROL_LAYER_INTERFACE *)                    pfwInterfaceObjGetViaPluginObj (&layerObj->pluginObj,id);        }    if ((id = pfwInterfaceIdGet(state->pluginObj->pfwObj,                                "LCP_NEGOTIATED_AUTH_PROTOCOL_INTERFACE")) > 0)        {	if (pfwInterfaceObjAndStateGetViaStackObj(state->stackObj,			    id, &pStackData->lcpNegotiatedAuthProtocols) != OK)	    return ERROR;        }    if (pStackData->callbacks &&        pStackData->callbacks->stackAddComplete)        {        (*pStackData->callbacks->stackAddComplete)                                 (pStackData->callbacks, state);	return OK;        }    else        return ERROR;    }/******************************************************************************** stackDelete -*/LOCAL STATUS stackDelete    (    PFW_PLUGIN_OBJ_STATE *state    )    {    CHAP_STACK_DATA *pStackData;    pStackData = (CHAP_STACK_DATA *)state->stackData;    /* Inform the upper layers we are down */    pfwTimerDelete(pStackData->challengeTimer);    pfwTimerDelete(pStackData->retryTimer);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -