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

📄 pppradiuscomponent.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    (    ACCOUNTING_DATA *acct    )    {    if (acct->attributeRequestHandle)       radius_delete_attribute_list(acct->attributeRequestHandle);    if (acct->attributeResponseHandle)       radius_delete_attribute_list(acct->attributeResponseHandle);    bzero ((void *)acct, sizeof (ACCOUNTING_DATA));    }/******************************************************************************** radiusClearRcvdAttr - free RADIUS server returned parameters **/LOCAL void radiusClearRcvdAttr    (    RADIUS_RECEIVED_ATTRIBUTES *attr    )    {    if (attr->class != NULL)        pfwFree(attr->class);    if (attr->userName != NULL)        pfwFree(attr->userName);    if (attr->gateway != NULL)        pfwFree(attr->gateway);    if (attr->destination != NULL)        pfwFree(attr->destination);    bzero ((void *)attr, sizeof (RADIUS_RECEIVED_ATTRIBUTES));    }/******************************************************************************** radiusClearServerData - free RADIUS server configuration**/LOCAL void radiusClearServerData    (    RADIUS_SERVER_DATA  *serverData    )    {	if (serverData->serverString != NULL)        pfwFree(serverData->serverString);    if (serverData->serverConfig != NULL)        pfwFree(serverData->serverConfig);    bzero ((void *)serverData, sizeof (RADIUS_SERVER_DATA));    }/******************************************************************************** radiusIpcpUpEventHandler - Process IPCP UP event** Routes and interface mask are set when IPCP reaches the open state*/LOCAL STATUS radiusIpcpUpEventHandler    (    PFW_PLUGIN_OBJ_STATE * state,    void * eventData    )    {    int id;    PFW_OBJ       * pfwObj;    PFW_STACK_OBJ * stackObj;    PFW_PLUGIN_OBJ  * pluginObj;    PFW_PLUGIN_OBJ_STATE * radiusState;    RADIUS_STACK_DATA * pStackData;    PPP_IP_ROUTES_INTERFACE  * ipRoutesInterface;    PFW_PLUGIN_OBJ_STATE * ipState;    RADIUS_RECEIVED_ATTRIBUTES * attr;    pfwObj   = state->pluginObj->pfwObj;    stackObj = state->stackObj;    if ((pluginObj = pfwPluginObjGet(pfwObj, "PPP_RADIUS")) == NULL)        {        logMsg("Could not find PPP_RADIUS plugin object\n",                          0, 0, 0, 0, 0, 0 );        return ERROR;        }    if ((radiusState = pfwPluginObjStateGet(stackObj, pluginObj)) == NULL)        {        logMsg("Could not find PPP_RADIUS plugin object State\n",                          0, 0, 0, 0, 0, 0 );        return ERROR;        }    pStackData = (RADIUS_STACK_DATA *) radiusState->stackData;    attr = &pStackData->rcvdAttributes;    if (pStackData->pppIpRoutesInterface.interfaceObj == NULL)	{	if ((id = pfwInterfaceIdGet(pfwObj, "PPP_IP_ROUTES_INTERFACE")) > 0)	    {	    if (pfwInterfaceObjAndStateGetViaStackObj(stackObj,				    id, &pStackData->pppIpRoutesInterface) != OK)		{		pfwPrintError (__FILE__, "radiusIpcpUpEventHandler",                               __LINE__, NULL, stackObj, 		               "PPP_IP_ROUTES_INTERFACE get error");		return ERROR;		}	    }	else	    return ERROR;        }    ipRoutesInterface = 	(PPP_IP_ROUTES_INTERFACE*)pStackData->pppIpRoutesInterface.interfaceObj;    ipState = pStackData->pppIpRoutesInterface.state;    /* Add route if both destination and gateway are present */    if ((attr->destination != NULL) && (attr->gateway != NULL))	{        ipRoutesInterface->ipRouteAdd(ipState, attr->destination,                                attr->gateway, attr->destMask, 0, 0);        }    /* Set interface mask */    if (attr->ipNetMask)        {        ipRoutesInterface->ipSetIfMask(ipState, attr->ipNetMask);        }    return OK;    }/******************************************************************************** radiusIpcpDownEventHandler - Process IPCP DOWN event** Routes are removed when the IPCP goes out of open state*/LOCAL STATUS radiusIpcpDownEventHandler    (    PFW_PLUGIN_OBJ_STATE * state,    void * eventData    )    {    PFW_OBJ       * pfwObj;    PFW_STACK_OBJ * stackObj;    PFW_PLUGIN_OBJ  * pluginObj;    PFW_PLUGIN_OBJ_STATE * radiusState;    RADIUS_STACK_DATA * pStackData;    PPP_IP_ROUTES_INTERFACE  * ipRoutesInterface;    PFW_PLUGIN_OBJ_STATE * ipState;    RADIUS_RECEIVED_ATTRIBUTES * attr;    pfwObj   = state->pluginObj->pfwObj;    stackObj = state->stackObj;    if ((pluginObj = pfwPluginObjGet(pfwObj, "PPP_RADIUS")) == NULL)        {        logMsg("Could not find PPP_RADIUS plugin object\n",                          0, 0, 0, 0, 0, 0 );        return ERROR;        }    if ((radiusState = pfwPluginObjStateGet(stackObj, pluginObj)) == NULL)        {        logMsg("Could not find PPP_RADIUS plugin object State\n",                          0, 0, 0, 0, 0, 0 );        return ERROR;        }    pStackData = (RADIUS_STACK_DATA *) radiusState->stackData;    attr = &pStackData->rcvdAttributes;    if (attr->destination == NULL)	{        return OK;        }    ipRoutesInterface = 	(PPP_IP_ROUTES_INTERFACE*)pStackData->pppIpRoutesInterface.interfaceObj;    ipState = pStackData->pppIpRoutesInterface.state;    /* Delete the installed route */    if (ipRoutesInterface)        {        ipRoutesInterface->ipRouteDelete(ipState,                         attr->destination, attr->destMask, 0, 0);        }    return OK;    }/******************************************************************************** challengeAuthVerify - Authenticate the user using CHAP** Send an RADIUS_ACCESS_REQUEST to the RADIUS server to authenticate the user*/LOCAL void challengeAuthVerify    (    PFW_PLUGIN_OBJ_STATE * state,    char * userName,    char * response,    unsigned int responseLen,    char * challenge,    unsigned int challengeLen,    BYTE id,    CHALLENGE_AUTH_METHOD method,    REMOTE_AUTHENTICATION_CALLBACKS * radiusCallbacks    )    {    RADIUS_SERVER_HANDLE  authServerHandle;    RADIUS_ATTRIBUTE_LIST_HANDLE attributeListHandle;    CHAP_AUTHENTICATION_DATA * chap;    PFW_OBJ                  * pfw;    RADIUS_STACK_DATA        * pStackData;    PFW_PLUGIN_OBJ_STATE     * adapterState;    PHY_PORT_INTERFACE       * phyPortInterface;    UINT                       nasPort, nasPortType;    pfw = state->pluginObj->pfwObj;    pStackData = (RADIUS_STACK_DATA *) state->stackData;    chap = &pStackData->chapAuthData;      	if (pfwPluginObjStateLock (state) == ERROR)	{	logMsg("challengeAuthVerify - unable to lock state\n",                          0, 0, 0, 0, 0, 0 );	return;	}    /* Allow authentication only if configured */    if (!(pStackData->radiusFlags & RADIUS_ALLOW_AUTHENTICATION))        {		pfwPluginObjStateRelease (state);        radiusCallbacks->authErrorCallback(state, id);        return;        }    /* Ignore authenticate request if previous request is pending */    if (pStackData->radiusState & RADIUS_CHAP_AUTH_PENDING)        {		pfwPluginObjStateRelease (state);#ifdef PPP_DEBUG        logMsg("CHAP Authentication Pending, Ignoring...\n",                    0, 0, 0, 0, 0, 0);#endif /* PPP_DEBUG */        chap->id = id;        return;	}    if ((authServerHandle = get_radius_server(&pStackData->authServerData,         RADIUS_AUTHENTICATION_SERVER_TYPE)) == INVALID_HANDLE)        {		pfwPluginObjStateRelease (state);        radiusCallbacks->authErrorCallback(state, id);        return;        }        chap->userName = pfwMalloc (pfw, strlen(userName) + 1);        chap->response = pfwMalloc (pfw, responseLen + 1);        chap->challenge = pfwMalloc (pfw, challengeLen);        attributeListHandle = radius_create_attribute_list();        if ((attributeListHandle == INVALID_HANDLE) ||            (chap->userName == NULL) ||            (chap->response == NULL) ||            (chap->challenge == NULL))		{		pfwPluginObjStateRelease (state);		radiusClearChapData(chap);        radiusCallbacks->authErrorCallback(state, id);        return;		}        phyPortInterface = (PHY_PORT_INTERFACE *)            pStackData->physicalPortInterface.interfaceObj;        adapterState =            pStackData->physicalPortInterface.state;        if (phyPortInterface != NULL)	   {           nasPort = htonl(phyPortInterface->portNumberGet(adapterState));           nasPortType = htonl(phyPortInterface->portTypeGet(adapterState));           }        bzero(chap->userName, strlen(userName) + 1);        bcopy(userName, chap->userName, strlen(userName));        bcopy(challenge, chap->challenge, challengeLen);        bcopy(response, chap->response + 1, responseLen);        chap->id = id;        chap->response[0] = id;        chap->responseLen = responseLen;        chap->challengeLen = challengeLen;        chap->pfw = pfw;        chap->state = state;        chap->pStackData = pStackData;        chap->radiusCallbacks = radiusCallbacks;        chap->attributeRequestHandle = attributeListHandle;		pStackData->state = state;        radius_add_attribute_to_list (attributeListHandle,           RADIUS_USER_NAME, strlen(userName), userName);            radius_add_attribute_to_list (attributeListHandle,           RADIUS_CHAP_PASSWORD, responseLen + 1, chap->response);            radius_add_attribute_to_list (attributeListHandle,           RADIUS_CHAP_CHALLENGE, challengeLen, challenge);        radius_add_attribute_to_list (attributeListHandle,           RADIUS_SERVICE_TYPE, 4, (BYTE *) &pStackData->serviceType);            radius_add_attribute_to_list (attributeListHandle,           RADIUS_FRAMED_PROTOCOL, 4, (BYTE *) &pStackData->framedProtocol);        if (phyPortInterface != NULL)	   {           radius_add_attribute_to_list (attributeListHandle,              RADIUS_NAS_PORT, 4, (BYTE *) &nasPort);           radius_add_attribute_to_list (attributeListHandle,              RADIUS_NAS_PORT_TYPE, 4, (BYTE *) &nasPortType);	   }        if (pStackData->nasIdentifier != NULL)           radius_add_attribute_to_list (attributeListHandle,               RADIUS_NAS_IDENTIFIER, strlen(pStackData->nasIdentifier),                                      pStackData->nasIdentifier); 		if (pStackData->nasIPaddress != 0)           radius_add_attribute_to_list (attributeListHandle,               RADIUS_NAS_IP_ADDRESS, 4, (BYTE *) &pStackData->nasIPaddress);        radiusClearRcvdAttr(&pStackData->rcvdAttributes);        pStackData->radiusState |= RADIUS_CHAP_AUTH_PENDING;		++pStackData->numberOfRadiusPendingRequest;		pfwPluginObjStateRelease (state);        netJobAdd((FUNCPTR) radiusSendRequest, (int) authServerHandle,           (int) chap, (int) &pStackData->chapRequestCallbacks,           (int) RADIUS_ACCESS_REQUEST, (int) chap->attributeRequestHandle);    }/******************************************************************************** passwordAuthVerify - Authenticate the user using PAP** Send an RADIUS_ACCESS_REQUEST to the RADIUS server to authenticate the user*/LOCAL void passwordAuthVerify    (    PFW_PLUGIN_OBJ_STATE * state,    char * userName,    char * password,    BYTE id,    REMOTE_AUTHENTICATION_CALLBACKS * radiusCallbacks    )    {    RADIUS_SERVER_HANDLE  authServerHandle;    RADIUS_ATTRIBUTE_LIST_HANDLE attributeListHandle;    PAP_AUTHENTICATION_DATA * pap;    PFW_OBJ                 * pfw;    RADIUS_STACK_DATA       * pStackData;    PFW_PLUGIN_OBJ_STATE    * adapterState;    PHY_PORT_INTERFACE      * phyPortInterface;    UINT                      nasPort, nasPortType;    pfw = state->pluginObj->pfwObj;    pStackData = (RADIUS_STACK_DATA *) state->stackData;    pap = &pStackData->papAuthData;      	if (pfwPluginObjStateLock (state) == ERROR)	{	logMsg("passwordAuthVerify - unable to lock state\n",                          0, 0, 0, 0, 0, 0 );	return;	}    /* Allow authentication only if configured */    if (!(pStackData->radiusFlags & RADIUS_ALLOW_AUTHENTICATION))        {		pfwPluginObjStateRelease (state);        radiusCallbacks->authErrorCallback(state, id);        return;        }    /* Ignore authenticate request if previous request is pending */    if (pStackData->radiusState & RADIUS_PAP_AUTH_PENDING)        {		pfwPluginObjStateRelease (state);#ifdef PPP_DEBUG        logMsg("PAP Authentication Pending, Ignoring...\n",                    0, 0, 0, 0, 0, 0);#endif /* PPP_DEBUG */        pap->id = id;        return;	}    if ((authServerHandle = get_radius_server(&pStackData->authServerData,         RADIUS_AUTHENTICATION_SERVER_TYPE)) == INVALID_HANDLE)        {		pfwPluginObjStateRelease (state);        radiusCallbacks->authErrorCallback(state, id);        return;        }        pap->userName = pfwMalloc (pfw, strlen(userName) + 1);        pap->password = pfwMalloc (pfw, strlen(password) + 1);        attributeListHandle = radius_create_attribute_list();        if ((attributeListHandle == INVALID_HANDLE) ||            (pap->userName == NULL) ||            (pap->password == NULL))        {		pfwPluginObjStateRelease (state);        radiusClearPapData(pap);        radiusCallbacks->authErrorCallback(state, id);        return;		}        phyPortInterface = (PHY_PORT_INTERFACE *)            pStackData->physicalPortInterface.interfaceObj;        adapterState =            pStackData->physicalPortInterface.state;

⌨️ 快捷键说明

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