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

📄 m2pppsecuritysecretslib.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* m2pppSecuritySecretsLib.c - SNMP pppSecuritySecretsTable implementation *//* Copyright 2000 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01h,28jun02,ijm fixed compilation warning01g,29sep00,sj  merging with TOR2_0-WINDNET_PPP-CUM_PATCH_201f,18sep00,adb  Avoid casting to GENERIC_ARGUMENT and two malloc strlen+101e,28apr00,adb  pass SNMPcompc to m2pppNextSecretsEntryAgentLookup01d,14feb00,adb  WRS coding conventions01c,11feb00,adb  added MAX_LINK and MAX_ID_INDEX tests01b,11feb00,adb  minor naming changes.01a,01feb00,abd  created.*//*DESCRIPTIONThis library implements the SNMP pppSecuritySecretsTable which is part of the PPP security MIB group which is specified in RFC 1472.INCLUDE FILES:  m2pppSecuritySecretsLib.h, pfwStack.hSEE ALSO: m2pppLib*//* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "semLib.h"#include "logLib.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "avlLib.h"#include "ppp/m2pppSecuritySecretsLib.h"IMPORT STATUS avlInsertInform (AVL_TREE * pRoot, void * pNewNode,                               GENERIC_ARGUMENT key,void ** ppKeyHolder,                               int compare (void *, GENERIC_ARGUMENT)                              );/* defines */#define PPP_SECRETS_SEM_TAKE                                            \    do  {                                                               \        if  (semTake(pppSecretsSem, WAIT_FOREVER) != OK)                \            {                                                           \            logMsg("Failure to acquire pppSecretsSem semaphore\n",      \                    0,0,0,0,0,0);                                       \            return ERROR;                                               \            };                                                          \        } while(0)#define PPP_SECRETS_SEM_GIVE                                                \    do  {                                                                   \        if  (semGive(pppSecretsSem) != OK)                                  \            {                                                               \            logMsg("semGive failed; pppSecretsSem is likely invalid\n",     \                    0,0,0,0,0,0);                                           \            return ERROR;                                                   \            };                                                              \        } while(0)#define POPULATE_PPP_SECRETS_DATA_KEY_ENTRY                     \    do  {                                                       \        (keyDataEntry.avlBase).left = NULL;                     \        (keyDataEntry.avlBase).right = NULL;                    \        (keyDataEntry.avlBase).height = 1;                      \        keyDataEntry.pppSecuritySecretsLink = link;             \        keyDataEntry.pppSecuritySecretsIdIndex = 0;             \        keyDataEntry.pppSecuritySecretsDirection = direction;   \        keyDataEntry.pppSecuritySecretsProtocol = protocol;     \        keyDataEntry.pppSecuritySecretsIdentity = identity;     \        keyDataEntry.pppSecuritySecretsSecret = NULL;           \        keyDataEntry.pppSecuritySecretsStatus =                 \        PPP_SECURITY_SECRETS_STATUS_UNDEFINED;                  \        } while(0)#define POPULATE_PPP_SECRETS_KEY_ENTRY                              \    do  {                                                           \        (keyEntry.avlBase).left = NULL;                             \        (keyEntry.avlBase).right = NULL;                            \        (keyEntry.avlBase).height = 1;                              \        keyEntry.pSecretsDataEntry = &keyDataEntry;                 \                                                                    \        (keyDataEntry.avlBase).left = NULL;                         \        (keyDataEntry.avlBase).right = NULL;                        \        (keyDataEntry.avlBase).height = 1;                          \        keyDataEntry.pppSecuritySecretsLink = link;                 \        keyDataEntry.pppSecuritySecretsIdIndex = idIndex;           \        keyDataEntry.pppSecuritySecretsDirection =                  \        PPP_SECURITY_SECRETS_DIRECTION_UNDEFINED;                   \        keyDataEntry.pppSecuritySecretsProtocol =                   \        PPP_SECURITY_UNDEFINED_PROTOCOL;                            \        keyDataEntry.pppSecuritySecretsIdentity = NULL;             \        keyDataEntry.pppSecuritySecretsSecret = NULL;               \        keyDataEntry.pppSecuritySecretsStatus =                     \        PPP_SECURITY_SECRETS_STATUS_UNDEFINED;                      \        } while(0)/* typedefs *//* globals *//* locals */LOCAL SEM_ID        pppSecretsSem = NULL;LOCAL AVL_TREE      pppSecretsDataTree = NULL;LOCAL AVL_TREE      pppSecretsTree = NULL;                    /* pointers to the root nodes of the trees */LOCAL AVL_TREE *    pppSecretsDataTreePtr = &pppSecretsDataTree;LOCAL AVL_TREE *    pppSecretsTreePtr    = &pppSecretsTree;                    /* pointers to the trees */                    /* Note that avlInsert requires as input a valid pointer                      * to an AVL_TREE pointing to a valid pointer to AVL_NODE.                     * In the body of avlInsert the input AVL_TREE pointer                     * will be dereferenced to an AVL_TREE i.e. to an                      * AVL_NODE pointer which subsequently will be evaluated.                     * It is simpler to statically declare and initialize both.                     *//* forward declarations */extern STATUS m2pppSecretsDataEntryPtrAgentLookup    /*      * This and the next two Get routines receive as input the SNMP indexing key     * (link, idIndex) and return in the position pointed by ppSecretsDataEntry     * a pointer to the corresponding data. All those routines compromise     * the robustness of the system and so it is suggested to be used only     * internally to avoid recovery of possibly dangling pointers.     */    (UINT32                             link,      UINT32                             idIndex,      PPP_SECURITY_SECRETS_DATA_ENTRY ** ppSecretsDataEntry);    extern STATUS m2pppNextSecretsDataEntryPtrAgentLookup    (UINT32                             link,      UINT32                             idIndex,      PPP_SECURITY_SECRETS_DATA_ENTRY ** ppSecretsDataEntry); extern STATUS m2pppPreviousSecretsDataEntryPtrAgentLookup    (UINT32                             lnk,      UINT32                             idIndex,      PPP_SECURITY_SECRETS_DATA_ENTRY ** ppSecretsDataEntry);LOCAL int ldpiDataKeyCompare          /* Node ordering comparison function using the auxiliary internal key.           * Manipulation of an avlTree requires a function that compares keys.           * This function is instance specific and its arguments are a pointer           * to an AVL_NODE and a generic argument to be used as a key bind. We           * will pass a key by passing a pointer to an encompassing tree node.           */        (    void *              nodePtr,     GENERIC_ARGUMENT    keyPtr    );LOCAL int m2pppAgentKeyCompare          /* Node ordering comparison function using the SNMP specified key. */    (    void *              nodePtr,     GENERIC_ARGUMENT    keyPtr    );void secretsDataNodeNicePrint(PPP_SECURITY_SECRETS_DATA_ENTRY * pDataEntry);void printSecretsDataNode(void * nodep);void printSecretsNode(void * nodep);void clearPrimaryNode(AVL_TREE * ppBase);void clearDataNode(AVL_TREE * ppBase);/******************************************************************************** m2pppSecuritySecretsLibInit - initialize m2pppSecuritySecretsLib** It creates and allocates all structures necessary for the implementation of * the SNMP MIB-2 pppSecuritySecretsTable ** NOTE: There will be no action if pppSecretsSem is non-NULL.** RETURNS: OK if the initialization was successful and ERROR otherwise.*/STATUS m2pppSecuritySecretsLibInit (void)    {    if  (NULL == pppSecretsSem)         {        if  ((pppSecretsSem = semMCreate(SEM_DELETE_SAFE |                                          SEM_Q_PRIORITY |                                          SEM_INVERSION_SAFE))              != NULL)            {            return OK;            }        else            {            logMsg("m2pppSecuritySecretsLibInit failed; semMCreate failure\n",                   0,0,0,0,0,0);            return ERROR;            }        }    else        {        logMsg("m2pppSecurityLibInit failed;  pppSecretsSem was not NULL\n",               0,0,0,0,0,0);        return ERROR;        }    }/********************************************************************************m2pppSecretsEntryDelete - delete keyed by (link, direction, protocol, identity)** Delete a pppSecuritySecretsEntry keyed by the internal, non-specified, key* (pppSecuritySecretsLink, pppSecuritySecretsDirection, * pppSecuritySecretsProtocol, pppSecuritySecretsIdentity).** RETURNS: OK if deletion was carried out or ERROR**/STATUS m2pppSecretsEntryDelete    (    UINT32                          link,      /* pppSecuritySecretsLink */    PPP_SECURITY_SECRETS_DIRECTION  direction, /* pppSecuritySecretsDirection */    PPP_SECURITY_PROTOCOL           protocol,  /* pppSecuritySecretsProtocol */    char *                          identity   /* pppSecuritySecretsIdentity */    )    {    /* this function assumes that the input data are valid and it will     * delete entries from both data and main tree.     */    PPP_SECURITY_SECRETS_DATA_ENTRY keyDataEntry;    PPP_SECURITY_SECRETS_DATA_ENTRY *   retrievedDataEntryPtr = NULL;    PPP_SECURITY_SECRETS_ENTRY  keyEntry;    PPP_SECURITY_SECRETS_ENTRY *    retrievedEntryPtr = NULL;    UINT32  idIndex = 0;    GENERIC_ARGUMENT auxGenericArgument;    POPULATE_PPP_SECRETS_DATA_KEY_ENTRY;    PPP_SECRETS_SEM_TAKE;            auxGenericArgument.p = (void *)(&keyDataEntry);    if  (NULL == (retrievedDataEntryPtr =                     avlDelete(pppSecretsDataTreePtr,                              auxGenericArgument,                              ldpiDataKeyCompare)))        {        /* Deletion will be aborted; no entry matches the given ldpi key */        PPP_SECRETS_SEM_GIVE;        return ERROR;        }    else        {        /* retrievedDataEntryPtr points to the removed secondary node         * with ldpi key costructed from the input data         */        idIndex = retrievedDataEntryPtr->pppSecuritySecretsIdIndex;        POPULATE_PPP_SECRETS_KEY_ENTRY;        auxGenericArgument.p = (void *)(&keyEntry);        if  (NULL == (retrievedEntryPtr =                        avlDelete(pppSecretsTreePtr,                                  auxGenericArgument,                                  m2pppAgentKeyCompare)))            /* we attempt to remove the corresponding primary tree node */            {            /* the corresponding primary tree node is not visible */            logMsg("inconsistency: only secondary tree node will be deleted\n",                   0,0,0,0,0,0);            free(retrievedDataEntryPtr->pppSecuritySecretsIdentity);            free(retrievedDataEntryPtr->pppSecuritySecretsSecret);            free(retrievedDataEntryPtr);            /* unsuccessful ldpi key keyed deletion due to              * database inconsistency.             */            PPP_SECRETS_SEM_GIVE;            return ERROR;            }        else            {            /* the corresponding primary tree node was removed from the              * the primary tree and it is pointed by retrievedEntryPtr             */            free(retrievedDataEntryPtr->pppSecuritySecretsIdentity);            free(retrievedDataEntryPtr->pppSecuritySecretsSecret);            free(retrievedDataEntryPtr);            free(retrievedEntryPtr);            /* successful ldpi key keyed deletion */                PPP_SECRETS_SEM_GIVE;            return OK;            }           }    }/******************************************************************************** m2pppSecretsEntryAgentDelete - delete keyed by  (link, idIndex)** Delete a pppSecuritySecretsEntry keyed by the ordered pair * (pppSecuritySecretsLink, pppSecuritySecretsIdIndex).** RETURNS: OK if the deletion was carried out and ERROR otherwise

⌨️ 快捷键说明

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