📄 ppppapcomponent.c
字号:
*/LOCAL void send_pap_authentication_request ( PFW_PLUGIN_OBJ_STATE * state ) { AUTHENTICATION_REQUEST_PACKET *sptr_authentication_request_packet; char password[NAME_SIZE]; USHORT number_of_bytes; BYTE *bptr_password_section; BYTE length_of_password; M_BLK_ID packet; PAP_STACK_DATA *stackData = (PAP_STACK_DATA *)state->stackData; PAP_PROFILE_DATA *profileData = (PAP_PROFILE_DATA *)state->profileData; NET_POOL_ID netPoolId = pfwNetPoolIdGet(state->pluginObj->pfwObj); (*stackData->controlLayerInterface->pppAuthRequest) (state, profileData->localUserName, password); if ((packet = netTupleGet(netPoolId,sizeof(AUTHENTICATION_REQUEST_PACKET), M_DONTWAIT, MT_DATA, TRUE)) == NULL) { pfwPrintError (__FILE__, "send_pap_authentication_request", __LINE__, NULL, state->stackObj, "netTupleGet error"); return; } /* copy secret */ sptr_authentication_request_packet = mtod (packet, AUTHENTICATION_REQUEST_PACKET *); sptr_authentication_request_packet->code = AUTHENTICATION_REQUEST; stackData->id_sequence_number = (BYTE) (stackData->id_sequence_number + 1); sptr_authentication_request_packet->id = stackData->id_sequence_number; sptr_authentication_request_packet->header.protocol_type = htons((USHORT)PAP_PROTOCOL); sptr_authentication_request_packet->peer_id_length = (BYTE) strlen (profileData->localUserName); strncpy (sptr_authentication_request_packet->peer_id, profileData->localUserName, sptr_authentication_request_packet->peer_id_length); /* this field is variable length so we have to set it */ bptr_password_section = (BYTE *) ((ULONG) &sptr_authentication_request_packet->peer_id[0] + sptr_authentication_request_packet->peer_id_length); length_of_password = (BYTE) strlen (password); sptr_authentication_request_packet->peer_password_length=length_of_password; *bptr_password_section = length_of_password; ++bptr_password_section; /* move to password itself */ strncpy ( (char *) bptr_password_section, password, length_of_password); stackData->lastSendAuthRequestPacketId = sptr_authentication_request_packet->id; number_of_bytes = (USHORT) (sizeof (LCP_HEADER) + sptr_authentication_request_packet->peer_id_length + sizeof (sptr_authentication_request_packet->peer_id_length) + length_of_password + sizeof (sptr_authentication_request_packet->peer_password_length)); sptr_authentication_request_packet->length = htons (number_of_bytes); packet->mBlkHdr.mLen = number_of_bytes + sizeof(PPP_HEADER); stackData->lastSentAuthRequestPacket = packet;#ifdef PPP_DEBUG printf ("PAP:Sending Auth request:ID %d, gotSecret %s for localName %s\n", sptr_authentication_request_packet->id, password,profileData->localUserName);#endif /* PPP_DEBUG */ sendAuthRequestRetry(state,0); }/********************************************************************************* send_pap_authentication_ack -*/LOCAL void send_pap_authentication_ack ( PFW_PLUGIN_OBJ_STATE * state, BYTE id_from_request_packet ) { AUTHENTICATION_ACK_PACKET *sptr_authentication_ack_packet; USHORT number_of_bytes; M_BLK_ID packet; PAP_STACK_DATA * stackData = (PAP_STACK_DATA *)state->stackData; NET_POOL_ID netPoolId = pfwNetPoolIdGet(state->pluginObj->pfwObj); /* * if we are only a client for authentication, silently * discard packet */ if (!stackData->serverEnabled) {#ifdef PPP_DEBUG printf ("PAP:Client not sending Auth-ack\n");#endif /* PPP_DEBUG */ return; } if ((packet = netTupleGet(netPoolId,sizeof(AUTHENTICATION_ACK_PACKET), M_DONTWAIT, MT_DATA, TRUE)) == NULL) { return; } sptr_authentication_ack_packet = mtod (packet, AUTHENTICATION_ACK_PACKET *); sptr_authentication_ack_packet->message_length = (BYTE) strlen ("you are authenticated") + 1/* for padding */; sptr_authentication_ack_packet->code = AUTHENTICATION_ACK; sptr_authentication_ack_packet->id = id_from_request_packet; sptr_authentication_ack_packet->length = htons ((USHORT) (sizeof (LCP_HEADER) + sizeof (sptr_authentication_ack_packet->message_length) + sptr_authentication_ack_packet->message_length)); number_of_bytes = htons (sptr_authentication_ack_packet->length); sptr_authentication_ack_packet->header.protocol_type = htons((USHORT)PAP_PROTOCOL); sptr_authentication_ack_packet->padding = '!'; strncpy (sptr_authentication_ack_packet->message, "you are authenticated",sptr_authentication_ack_packet->message_length); packet->mBlkHdr.mLen = number_of_bytes + sizeof (PPP_HEADER); pfwSend (state, packet); (*stackData->controlLayerInterface->pppAuthAckTransmitted) (state);#ifdef PPP_DEBUG printf ("PAP:Sending Auth Ack:ID %d\n", sptr_authentication_ack_packet->id);#endif /* PPP_DEBUG */ if (stackData->serverState != PPP_OPENED_STATE) { stackData->serverState = PPP_OPENED_STATE; if ((stackData->clientEnabled == FALSE) || (stackData->clientEnabled == TRUE && stackData->clientState == PPP_OPENED_STATE)) { stackData->state = PPP_OPENED_STATE; (*stackData->controlLayerInterface->protocolUp) (state); } } }/********************************************************************************* send_pap_authentication_nak -*/LOCAL void send_pap_authentication_nak ( PFW_PLUGIN_OBJ_STATE * state, BYTE id_from_request_packet ) { AUTHENTICATION_NAK_PACKET *sptr_authentication_nak_packet; USHORT number_of_bytes; M_BLK_ID packet; PAP_STACK_DATA * stackData = (PAP_STACK_DATA *)state->stackData; NET_POOL_ID netPoolId = pfwNetPoolIdGet(state->pluginObj->pfwObj); /* * if we are only a client for authentication, silently * discard packet */ if (!stackData->serverEnabled) {#ifdef PPP_DEBUG printf ("PAP:Client not sending Auth-nack\n");#endif /* PPP_DEBUG */ return; } if ((packet = netTupleGet(netPoolId,sizeof(AUTHENTICATION_ACK_PACKET), M_DONTWAIT, MT_DATA, TRUE)) == NULL) { pfwPrintError (__FILE__, "send_pap_authentication_nak", __LINE__, NULL, state->stackObj, "netTupleGet error"); return; } sptr_authentication_nak_packet = mtod (packet, AUTHENTICATION_NAK_PACKET *); sptr_authentication_nak_packet->message_length = (BYTE) strlen ("you are not authenticated") + 1/* for padding */; sptr_authentication_nak_packet->code = AUTHENTICATION_NAK; sptr_authentication_nak_packet->id = id_from_request_packet; number_of_bytes = (USHORT)(sizeof (LCP_HEADER) + sizeof (sptr_authentication_nak_packet->message_length) + sptr_authentication_nak_packet->message_length); sptr_authentication_nak_packet->length = htons (number_of_bytes); sptr_authentication_nak_packet->header.protocol_type = htons((USHORT)PAP_PROTOCOL); sptr_authentication_nak_packet->padding = '!'; strncpy (sptr_authentication_nak_packet->message, "you are not authenticated", sptr_authentication_nak_packet->message_length - 1); packet->mBlkHdr.mLen = number_of_bytes + sizeof (PPP_HEADER); pfwSend (state, packet); (*stackData->controlLayerInterface->pppAuthFailed) (state); }/******************************************************************************** pap_initialize_restart_counter -*/LOCAL void pap_initialize_restart_counter ( PFW_PLUGIN_OBJ_STATE *pluginState ) { PAP_STACK_DATA * stackData = (PAP_STACK_DATA *)pluginState->stackData; stackData->currentAuthRequestRetries = 0; }/********************************************************************************* pap_pppStateGet -*/LOCAL PPP_STATE pap_pppStateGet ( PFW_PLUGIN_OBJ_STATE * state ) { PAP_STACK_DATA *stackData = state->stackData; return (stackData->state); }/********************************************************************************* pap_maxAuthRequestRetries -*/LOCAL STATUS pap_maxAuthRequestRetries ( PFW_OBJ * pfw, PFW_PARAMETER_OPERATION_TYPE type, void * profileData, char * value ) { if (type == PFW_PARAMETER_SET) ((PAP_PROFILE_DATA *) profileData)->maxAuthRequestRetries = atoi (value); else sprintf(value, "%d", ((PAP_PROFILE_DATA *) profileData)->maxAuthRequestRetries); return (OK); }/********************************************************************************* pap_authRequestInterval -*/LOCAL STATUS pap_authRequestInterval ( PFW_OBJ * pfw, PFW_PARAMETER_OPERATION_TYPE type, void * profileData, char * value ) { if (type == PFW_PARAMETER_SET) ((PAP_PROFILE_DATA *) profileData)->authRequestInterval = atoi (value); else sprintf(value, "%ld", ((PAP_PROFILE_DATA *) profileData)->authRequestInterval); return (OK); }/********************************************************************************* pap_localUserName -*/LOCAL STATUS pap_localUserName ( PFW_OBJ * pfw, PFW_PARAMETER_OPERATION_TYPE type, void * profileData, char * value ) { if (type == PFW_PARAMETER_SET) { strcpy(((PAP_PROFILE_DATA *) profileData)->localUserName, value); } else if (type == PFW_PARAMETER_GET) strcpy(value, ((PAP_PROFILE_DATA *) profileData)->localUserName); return (OK); }/********************************************************************************* pap_pppPhaseGet -*/LOCAL PPP_CONTROL_PHASE pap_pppPhaseGet () { return (AUTHENTICATE_PHASE); }/******************************************************************************** papDupPkt - DUP the given packet** RETURNS: The the duplicated MBLK for the packet if successful, else it frees* the original packet and returns NULL*/LOCAL M_BLK_ID papDupPkt ( M_BLK_ID pPacket /* packet to DUP */ ) { NET_POOL_ID pNetPool = NULL; M_BLK_ID pDupPkt = NULL; if ((pPacket == NULL) || ((pNetPool = MBLK_TO_NET_POOL(pPacket)) == NULL)) return NULL; /* dup the given packet/chain */ if (pPacket->mBlkHdr.mNext != NULL) { if ((pDupPkt = netMblkChainDup(pNetPool, pPacket, 0, M_COPYALL, M_DONTWAIT)) == NULL) return NULL; } else { /* get a new MBLK */ if ((pDupPkt = netMblkGet (pNetPool, M_DONTWAIT, MT_DATA)) == NULL) return NULL; if (netMblkDup (pPacket, pDupPkt) == NULL) { netMblkFree(pNetPool,pDupPkt); return NULL; } } return pDupPkt; }/* WindNet Multilink - AUTH_INFO_INTERFACE *//******************************************************************************** papLocalUserNameSet - Configure the local username for PAP component* * This function configures the local user name for the PAP component in the * given stack. This function is called when a link is configured for a bundle* * RETURNS N/A*/void papLocalUserNameSet ( PFW_PLUGIN_OBJ_STATE *pAuthState, /* plugin Obj state of the Authentication component */ char *pLocalUserName /* Local user name to be set */ ) { PFW_OBJ *pfwObj = NULL; UINT paramId = 0; if ((pAuthState == NULL) || (pLocalUserName == NULL)) { printf ("PAP:Auth Info Interface:Invalid parameters\n"); return; } pfwObj = pfwStackObjPfwGet (pAuthState->stackObj); if (pfwObj == NULL) { printf ("NULL Framework Reference\n"); return; } paramId = pfwParameterIdGet (pfwObj, "pap_localUserName"); pfwStackParamSet (pAuthState->stackObj, paramId, pLocalUserName); }/******************************************************************************** papLocalUserNameGet - Gets the local user name configured in the PAP * component in the given stack** This function copy the local user name configured in the PAP component in the * given stack. This function is called when a link is added to the bundle to * construct the bundle identifier of the link.** RETURNS N/A*/void papLocalUserNameGet ( PFW_PLUGIN_OBJ_STATE *pPapState, /* PAP Component plugin state */ char *pLocalUserName /* Local user name */ ) { PFW_OBJ *pfwObj = NULL; UINT paramId = 0; if ((pPapState == NULL) || (pLocalUserName == NULL)) { printf ("PAP:Auth Info Interface:Invalid parameters\n"); return; } pfwObj = pfwStackObjPfwGet (pPapState->stackObj); if (pfwObj == NULL) { printf ("NULL Framework Reference\n"); return; } paramId = pfwParameterIdGet (pfwObj, "pap_localUserName"); pfwStackParamGet (pPapState->stackObj, paramId, pLocalUserName); }/******************************************************************************** papRemoteUserNameGet - Gets the remote user name configured in the PAP * component in the given stack** This function copy the remote user name configured in the PAP component in the * given stack. This function is called when a link is added to the bundle to * construct the bundle identifier of the link.** RETURNS N/A*/void papRemoteUserNameGet ( PFW_PLUGIN_OBJ_STATE *pPapState, /* PAP Component plugin state */ char *pRemoteUserName /* Remote user name */ ) { PAP_STACK_DATA *pStackData = NULL; if ((pPapState == NULL) || (pRemoteUserName == NULL)) { printf ("PAP:Auth Info Interface:Invalid Parameters\n"); return; } if ((pStackData = pPapState->stackData) == NULL) { printf ("PAP:Auth Info Interface:Invalid Parameters\n"); return; } strcpy (pRemoteUserName, pStackData->remoteUserName); }/* WindNet Multilink - AUTH_INFO_INTERFACE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -