📄 m2pppsecurityconfig.c
字号:
/* m2pppSecurityConfig.c - SNMP pppSecurityConfigTable implementation *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01g,18dec02,qhu rollback the change made previously.01f,18dep02,qhu the global variable m2pppSecurityConfigInterfacesTable is never got deleted after Unregistered that causes memory leak. fix this by adding pfwTableDelete in the "Unregister" function.01e,07may02,adb added newline at the end of file01d,27apr00,adb SNMP integration m2pppSecurityConfigEntryLookup modification01c,28feb00,adb PPP integration testing and debugging01b,22feb00,sj documenting public routines01a,31jan00,sj created.*//*DESCRIPTIONThis library serves as an interface layer between the SNMP agent and thePPP Security Config Group MIB backend routinesINCLUDE FILES: m2pppSecurityConfig.h m2pppLib.h lcpInterfaces.h pfwStack.h pfwTable.h*//* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "logLib.h"#include "tickLib.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "pfw/pfwTable.h"#include "pfw/pfwMemory.h"#include "ppp/m2pppLib.h"#include "ppp/m2pppSecurityConfig.h"#include "ppp/interfaces/lcpInterfaces.h"/* defines */#define PROTOCOL_NUMBER_MD5_CHAP 0xc22305#define PROTOCOL_NUMBER_PAP 0xc023/* typdefs */typedef struct m2pppSecurityConfigInterfacesEntry { PFW_OBJ * pfwObj; /*framework for which*/ /*these interfaces */ /* exist */ int key; /* tableItem number */ PPP_SECURITY_CONFIG_ENTRY_INTERFACE *interface; }M2_PPP_SECURITY_CONFIG_ENTRY;/* globals *//* locals */LOCAL PFW_TABLE_OBJ * m2pppSecurityConfigInterfacesTable = NULL;/* forwards */LOCAL M2_PPP_SECURITY_CONFIG_ENTRY * securityConfigInterfacesGet (PFW_OBJ *);LOCAL BOOL compareSecurityConfigEntry (UINT32 key, void * pItem, void * arg);/******************************************************************************** m2pppSecurityConfigRegister - register/initialize pppSecurityConfig interfaces** This routine allows the PPP framework component that supports the * pppSecurityConfigTable to publish its support. Typically the LCP* framework component supports this MIB table.* * RETURNS: OK on successful registration and ERROR otherwise*/STATUS m2pppSecurityConfigRegister ( PFW_OBJ * pfwObj /* PPP Framework context */ ) { M2_PPP_SECURITY_CONFIG_ENTRY * securityConfigInterfaces; int id; if (m2pppSecurityConfigInterfacesTable == NULL) { if ((m2pppSecurityConfigInterfacesTable = pfwTableCreate(NULL,2,-1)) == NULL) { printf ("m2pppSecurityConfigInit: Failed to create m2pppSecurityConfigInterfacesTable \n"); return ERROR; } } if ((securityConfigInterfaces = pfwMalloc(pfwObj, sizeof(M2_PPP_SECURITY_CONFIG_ENTRY))) == NULL) { return ERROR; } /* get the interface pointers */ securityConfigInterfaces->pfwObj = pfwObj; if ((id = pfwInterfaceIdGet(pfwObj, "PPP_SECURITY_CONFIG_ENTRY_INTERFACE")) == 0) { logMsg("m2LinkGroup: Could not get Security Config interface ID\n", 1,2,3,4,5,6); return ERROR; } if ((securityConfigInterfaces->interface = (PPP_SECURITY_CONFIG_ENTRY_INTERFACE *) pfwInterfaceObjGetViaPfwObj (pfwObj,id)) == NULL) { pfwPrintError (__FILE__,"m2pppSecurityConfigInit", __LINE__, pfwObj, 0,"No PPP_SECURITY_CONFIG_ENTRY_INTERFACE !"); return ERROR; } /* save interfaces information in table */ securityConfigInterfaces->key = pfwTableItemAdd(m2pppSecurityConfigInterfacesTable, securityConfigInterfaces); return OK; }/******************************************************************************** m2pppSecurityConfigUnregister - withdraw pppSecurityConfigTable support** This routine allows the PPP framework component that supports the * pppSecurityConfigTable to withdraw its support.** RETURNS: OK on success and ERROR otherwise*/STATUS m2pppSecurityConfigUnregister ( PFW_OBJ * pfwObj /* reference to publishing component's framework */ ) { M2_PPP_SECURITY_CONFIG_ENTRY * securityConfigInterfaces; if (m2pppSecurityConfigInterfacesTable == NULL) return ERROR; if ((securityConfigInterfaces = securityConfigInterfacesGet(pfwObj)) == NULL) return ERROR; pfwInterfaceReferenceDelete( &securityConfigInterfaces->interface->interfaceObj); /* delete interfaces information from table */ pfwTableItemDelete(m2pppSecurityConfigInterfacesTable, securityConfigInterfaces->key); pfwFree(securityConfigInterfaces); return OK; }/******************************************************************************** m2pppSecurityConfigEntryLookup - access pppSecurityConfigEntry data** This routine retrieves the pppSecurityConfigEntry data that correspond to* the indexing ordered pair * (pppSecurityConfigLinkId, pppSecurityConfigPreference).** Link ID and preference should be the first and second entries of the * input array <oid>.** The argument <oidLen> that specifies the number of* elements in the <oid> array should be typically set to 2.* Only in the case of a M2_PPP_ENTRY_NEXT_MATCH call the value* of <oidlen> may be set to 1 implying that only link ID is available* and preference is set to 0.** If <M2_PPP_ENTRY_MATCH_TYPE> is set to M2_PPP_ENTRY_EXACT_MATCH * the data that correspond to the input key will be retrieved.* If <M2_PPP_ENTRY_MATCH_TYPE> is set to M2_PPP_ENTRY_NEXT_MATCH, * the data corresponding to the key that is minimum lexicographically* superior to the input key will be retrieved, provided that an entry * exists with key lexicographicallly superior to the input key. ** The input link ID may be 0 only in the M2_PPP_ENTRY_NEXT_MATCH case call.** The field* <status> in <data> is set to PPP_SECURITY_SECRETS_STATUS_VALID if an* entry is successfully retrieved.** This routine must be called before a set operation can be performed for any* of the leaf objects in this entry in order to retrieve the necessary * references and contexts which are stored in the corresponding* PPP_SECURITY_CONFIG_ENTRY_DATA structure.* * RETURNS: OK if the input link ID is valid and ERROR otherwise*/STATUS m2pppSecurityConfigEntryLookup ( UINT32 oidLen, /* size of variable array */ UINT32 * oid, /* variable array pointer */ PPP_SECURITY_CONFIG_ENTRY_DATA * data, /* retrieved data placeholder */ M2_PPP_ENTRY_MATCH_TYPE match /* EXACT or NEXT */ ) { int ifIndex = (oid != NULL && oidLen >= 1) ? oid[0] : 0; int preference = (oid != NULL && oidLen == 2) ? oid[1] : -1; int nextIfIndex = 0; M2_PPP_SECURITY_CONFIG_ENTRY * securityConfigInterfaces; PFW_STACK_OBJ * stackObj; PFW_PLUGIN_OBJ_STATE * lcpState; int foundPreference; UINT8 protocol[4]; UINT8 protocolLen; int i; if (match == M2_PPP_ENTRY_EXACT_MATCH && ifIndex <= 0) return ERROR; else if (match == M2_PPP_ENTRY_NEXT_MATCH && ifIndex < 0) return ERROR; switch(match) { case M2_PPP_ENTRY_EXACT_MATCH: if (m2pppInterfaceStackObjGet(ifIndex,&stackObj) != OK) return ERROR; else if (stackObj == NULL) return ERROR; if ((securityConfigInterfaces = securityConfigInterfacesGet(pfwStackObjPfwGet(stackObj))) == NULL) return ERROR; lcpState = pfwPluginObjStateGet(stackObj, securityConfigInterfaces->interface->interfaceObj.pluginObj); if (lcpState == NULL) return ERROR; data->state = lcpState; data->interface = &securityConfigInterfaces->interface->interfaceObj; data->status = PPP_SECURITY_SECRETS_STATUS_INVALID; if ((foundPreference = securityConfigInterfaces->interface->pppSecurityConfigProtocolGet( lcpState,preference,protocol,&protocolLen)) == preference) { data->link = ifIndex; data->preference = preference; data->protocol = 0; i = 0; while(protocolLen--) data->protocol = ((data->protocol << 8) | protocol[i++]); if (data->protocol == PROTOCOL_NUMBER_MD5_CHAP) data->protocol = PPP_SECURITY_CHAP_MD5_PROTOCOL; else if (data->protocol == PROTOCOL_NUMBER_PAP) data->protocol = PPP_SECURITY_PAP_PROTOCOL; else return ERROR; data->status = PPP_SECURITY_SECRETS_STATUS_VALID; } break; case M2_PPP_ENTRY_NEXT_MATCH: /* if the ifIndex is not valid then we pass to the next valid one */ if ((ifIndex == 0) || (m2pppInterfaceStackObjGet(ifIndex,&stackObj) != OK) || (stackObj == NULL)) { if ((m2pppNextInterfaceStackObjGet((UINT32) ifIndex, (UINT32 *)&nextIfIndex, &stackObj)) != OK) return ERROR; else if (stackObj == NULL) return ERROR; ifIndex = nextIfIndex; preference = -1; } FOREVER { if (stackObj == NULL) return ERROR; if ((securityConfigInterfaces = securityConfigInterfacesGet(pfwStackObjPfwGet(stackObj))) == NULL) return ERROR; lcpState = pfwPluginObjStateGet(stackObj, securityConfigInterfaces->interface->interfaceObj.pluginObj); if (lcpState == NULL) return ERROR; data->state = lcpState; data->interface = &securityConfigInterfaces->interface->interfaceObj; data->status = PPP_SECURITY_SECRETS_STATUS_INVALID; if ((foundPreference = securityConfigInterfaces->interface-> pppSecurityConfigProtocolGet(lcpState,(preference+1), protocol,&protocolLen)) > preference) { data->link = ifIndex; data->preference = foundPreference; data->protocol = 0; i = 0; while(protocolLen--) data->protocol=((data->protocol << 8) | protocol[i++]); if (data->protocol == PROTOCOL_NUMBER_MD5_CHAP) data->protocol = PPP_SECURITY_CHAP_MD5_PROTOCOL; else if (data->protocol == PROTOCOL_NUMBER_PAP) data->protocol = PPP_SECURITY_PAP_PROTOCOL; else return ERROR; data->status = PPP_SECURITY_SECRETS_STATUS_VALID; break; } else { if (m2pppNextInterfaceStackObjGet((UINT32)ifIndex, (UINT32 *)&nextIfIndex, &stackObj) != OK) return ERROR; if (stackObj != NULL) { ifIndex = nextIfIndex; preference = -1; } } } break; default: return ERROR;; } return OK; }/******************************************************************************** m2pppSecurityConfigEntrySet - insert/modify/delete pppSecurityConfigEntry data** This routine allows an agent to insert/modify/delete pppSecurityConfigEntry* data of a PPP link. ** Before calling this routine * m2pppSecurityConfigEntryLookup()* must be called to verify the validity of the key (link ID, preference)* and test the existence of an entry with the input key.** Subsequently, to delete an existing entry the <status> field of the * <data> argument must be* set to PPP_SECURITY_SECRETS_STATUS_INVALID and to add an entry or * modify an existing entry all members* of <data> must be supplied and its <status> field must be set to * PPP_SECURITY_SECRETS_STATUS_VALID.** RETURNS: OK on success and ERROR otherwise** SEE ALSO: m2pppSecurityConfigEntryLookup()*/STATUS m2pppSecurityConfigEntrySet ( PPP_SECURITY_CONFIG_ENTRY_DATA * data /* input */ ) { int preference = data->preference; int ifIndex = data->link; PPP_SECURITY_CONFIG_ENTRY_INTERFACE * pppSecurityConfigInterface; PFW_PLUGIN_OBJ_STATE * lcpState; UINT8 protocol[4] = {0,0,0,0}; UINT8 protocolLen; if (preference < 0 || ifIndex <= 0) return ERROR; if ((lcpState = data->state) == NULL) return ERROR; if ((pppSecurityConfigInterface = ((PPP_SECURITY_CONFIG_ENTRY_INTERFACE *)data->interface)) == NULL) return ERROR; switch (data->status) { case PPP_SECURITY_SECRETS_STATUS_INVALID: if (pppSecurityConfigInterface->pppSecurityConfigStatusSet( lcpState,preference, PPP_SECURITY_SECRETS_STATUS_INVALID) != OK) { return ERROR; } break; case PPP_SECURITY_SECRETS_STATUS_VALID: if (data->protocol == PPP_SECURITY_CHAP_MD5_PROTOCOL) { protocol[0] = 0xc2; protocol[1] = 0x23; protocol[2] = 0x05; protocolLen = 3; } else if (data->protocol == PPP_SECURITY_PAP_PROTOCOL) { protocol[0] = 0xc0; protocol[1] = 0x23; protocolLen = 2; } else { return ERROR; } if (pppSecurityConfigInterface->pppSecurityConfigProtocolSet( lcpState,preference, protocol,protocolLen) != OK) { return ERROR; } break; default: return ERROR; } /* release state */ return OK; }/******************************************************************************** securityConfigInterfacesGet -*/LOCAL M2_PPP_SECURITY_CONFIG_ENTRY * securityConfigInterfacesGet ( PFW_OBJ * pfwObj ) { int key; key = pfwTableTraverse(m2pppSecurityConfigInterfacesTable, compareSecurityConfigEntry,pfwObj); if (key == 0) return NULL; else return (pfwTableItemGet(m2pppSecurityConfigInterfacesTable,key)); }/******************************************************************************** compareSecurityConfigEntry -*/LOCAL BOOL compareSecurityConfigEntry ( UINT32 key, void * pItem, void * arg ) { M2_PPP_SECURITY_CONFIG_ENTRY * tableEntry = pItem; PFW_OBJ * thisPfw = arg; if (tableEntry->pfwObj == thisPfw) return TRUE; return FALSE; }/******************************************************************************** m2pppSecurityConfigEntrySetWrap - it wraps m2pppSecurityConfigEntrySet** This function is going to be used only during debugging* * NOMANUAL*/STATUS m2pppSecurityConfigEntrySetWrap(UINT32 link, UINT32 preference, PPP_SECURITY_PROTOCOL protocol, PPP_SECURITY_SECRETS_STATUS status) { PPP_SECURITY_CONFIG_ENTRY_DATA aux; M2_PPP_SECURITY_CONFIG_ENTRY * securityConfigInterfaces; PFW_STACK_OBJ * stackObj; if (m2pppInterfaceStackObjGet(link, &stackObj) != OK) return ERROR; if (NULL == (securityConfigInterfaces = securityConfigInterfacesGet(pfwStackObjPfwGet(stackObj)))) return ERROR; if (NULL == (aux.state = pfwPluginObjStateGet(stackObj, securityConfigInterfaces-> interface-> interfaceObj.pluginObj))) return ERROR; aux.interface = &securityConfigInterfaces->interface->interfaceObj; aux.link = link; aux.preference = preference; aux.protocol = protocol; aux.status = status; return m2pppSecurityConfigEntrySet(&aux); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -