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

📄 m2pppsecuritysecretslib.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
*/STATUS m2pppSecretsEntryAgentDelete    (    UINT32  link,   /* pppSecuritySecretsLink part of input key */    UINT32  idIndex /* pppSecuritySecretsIdIndex part of input key */    )    {    /* this function assumes that the input data are valid and it will     * delete entries from both data and main tree.     */    PPP_SECURITY_SECRETS_ENTRY  keyEntry;    PPP_SECURITY_SECRETS_ENTRY *    retrievedEntryPtr = NULL;    PPP_SECURITY_SECRETS_DIRECTION  direction;    PPP_SECURITY_PROTOCOL   protocol;    char *  identity;    PPP_SECURITY_SECRETS_DATA_ENTRY keyDataEntry;    PPP_SECURITY_SECRETS_DATA_ENTRY *   retrievedDataEntryPtr = NULL;    GENERIC_ARGUMENT auxGenericArgument;    POPULATE_PPP_SECRETS_KEY_ENTRY;    PPP_SECRETS_SEM_TAKE;            auxGenericArgument.p = (void *)(&keyEntry);    if  (NULL == (retrievedEntryPtr =                     avlDelete(pppSecretsTreePtr,                              auxGenericArgument,                              m2pppAgentKeyCompare)))        {        /* Deletion attempt will be aborted. There is no entry with the          * given (link, idIndex) key on the primary tree.         */        PPP_SECRETS_SEM_GIVE;        return ERROR;        }    else        {        /* the primary key node with key matching the input key was         * removed from the primary tree and it is pointed by          * retrievedEntryPtr. Now we will construct the secondary          * key and we will attempt to revove the corresponding          * secondary (data) tree node.         */        direction = (retrievedEntryPtr->                     pSecretsDataEntry)->                    pppSecuritySecretsDirection;        protocol = (retrievedEntryPtr->                    pSecretsDataEntry)->                   pppSecuritySecretsProtocol;        identity = (retrievedEntryPtr->                    pSecretsDataEntry)->                   pppSecuritySecretsIdentity;        POPULATE_PPP_SECRETS_DATA_KEY_ENTRY;        auxGenericArgument.p = (void *)(&keyDataEntry);        if  (NULL == (retrievedDataEntryPtr =                        avlDelete(pppSecretsDataTreePtr,                                  auxGenericArgument,                                  ldpiDataKeyCompare)))            /* we attempt removal of the corresponding data tree node */            {            /* corresponding primary tree node is invisible */            logMsg("inconsistency: only primary tree node will be deleted\n",                   0,0,0,0,0,0);                  free(retrievedEntryPtr);            /* (link, idIndex) keyed deletion was unsuccessful              * due to database inconsistency.             */            PPP_SECRETS_SEM_GIVE;            return ERROR;            }        else            {            /* the corresponding data tree node was removed from the             * data tree and it is pointed by retrievedDataEntryPrt.             */            free(retrievedEntryPtr);                free(retrievedDataEntryPtr->pppSecuritySecretsIdentity);            free(retrievedDataEntryPtr->pppSecuritySecretsSecret);            free(retrievedDataEntryPtr);            /* successful deletion keyed by (link, idIndex) key */            PPP_SECRETS_SEM_GIVE;            return OK;            }           }    }/******************************************************************************** m2pppSecretsEntrySet - delete/insert/modify keyed by the auxiliary key* * Delete, insert of modify data using the non-specified internal key* (pppSecuritySecretsLink, pppSecuritySecretsDirection, * pppSecuritySecretsProtocol, pppSecuritySecretsIdentity). * * If the status is set to PPP_SECURITY_SECRETS_STATUS_INVALID then* it will be interpreted as a request for deletion.** If the status is set to PPP_SECURITY_SECRETS_STATUS_VALID then * it will be interpreted as a request for modification or insertion * and the implementation dynamically will check sufficiency of input data.** RETURNS: OK or ERROR**/STATUS m2pppSecretsEntrySet    (    UINT32                          link,      /* required */    PPP_SECURITY_SECRETS_DIRECTION  direction, /* required */    PPP_SECURITY_PROTOCOL           protocol,  /* required */    char *                          identity,  /* required */    char *                          secret,    /* NULL if not supplied */    PPP_SECURITY_SECRETS_STATUS     status     /* required */    )    {    PPP_SECURITY_SECRETS_DATA_ENTRY keyDataEntry;    PPP_SECURITY_SECRETS_DATA_ENTRY *   retrievedDataEntryPtr = NULL;    PPP_SECURITY_SECRETS_DATA_ENTRY *   newDataEntryPtr = NULL;    PPP_SECURITY_SECRETS_ENTRY  keyEntry;    PPP_SECURITY_SECRETS_ENTRY *    retrievedEntryPtr = NULL;    PPP_SECURITY_SECRETS_ENTRY *    newEntryPtr = NULL;    UINT32  idIndex = 0;    STATUS auxStatus;    GENERIC_ARGUMENT auxGenericArgument;    if  ((link > MAX_LINK) ||         ((direction != PPP_SECURITY_SECRETS_DIRECTION_LOCAL_TO_REMOTE) &&           (direction != PPP_SECURITY_SECRETS_DIRECTION_REMOTE_TO_LOCAL)) ||         ((protocol != PPP_SECURITY_PAP_PROTOCOL) &&           (protocol != PPP_SECURITY_CHAP_MD5_PROTOCOL)) ||         (NULL == identity) ||         (strlen(identity) > 255) ||         ((status != PPP_SECURITY_SECRETS_STATUS_INVALID) &&          (status != PPP_SECURITY_SECRETS_STATUS_VALID)) ||         ((PPP_SECURITY_SECRETS_STATUS_VALID == status) && (NULL == secret)) ||         ((secret != NULL) && (strlen(secret) > 255)))        /* first we check consistency of input data */        {        /*  m2pppSecretsEntrySet will be aborted due to invalid input data */        return ERROR;        }          else if (PPP_SECURITY_SECRETS_STATUS_INVALID == status)        /*          * If pppSecretsSet is called with <status> == "INVALID"         * then it is interpreted as a request for deletion.         */        {        return m2pppSecretsEntryDelete(link, direction, protocol, identity);        }    /*      * if control reaches here then <status> == "VALID" and <secret> |= NULL.     * A call of pppSecretsSet with <status> == "VALID" is interpreted as a     * request for secret modification or new entry creation and insertion.     */    else if (NULL == (newDataEntryPtr = (PPP_SECURITY_SECRETS_DATA_ENTRY *)                        malloc(sizeof(PPP_SECURITY_SECRETS_DATA_ENTRY))))            /* We are responsible for memory management.             * The functionality of avlLib does not include memory management.             */        {        logMsg("malloc failure in m2pppSecretsEntrySet\n",0,0,0,0,0,0);        PPP_SECRETS_SEM_GIVE;        return ERROR;        }    else if (NULL == (newDataEntryPtr->pppSecuritySecretsIdentity = (char *)                         malloc(sizeof(char)*(strlen(identity)+1))))        /* we also allocate space for the new identity */        {        logMsg("malloc failure in m2pppSecretsEntrySet\n",0,0,0,0,0,0);        /* before we return we free reserved memory */        free(newDataEntryPtr);        return ERROR;        }    else if (NULL == (newDataEntryPtr->pppSecuritySecretsSecret = (char *)                         malloc(sizeof(char)*(strlen(secret)+1))))        /* we also allocate space for the new secret */        {        logMsg("malloc failure in m2pppSecretsEntrySet\n",0,0,0,0,0,0);        /* before we return we free reserved memory */        free(newDataEntryPtr->pppSecuritySecretsIdentity);        free(newDataEntryPtr);        return ERROR;        }    else if (NULL == (newEntryPtr = (PPP_SECURITY_SECRETS_ENTRY *)                        malloc(sizeof(PPP_SECURITY_SECRETS_ENTRY))))            /* We are responsible for memory management.             * The functionality of avlLib does not include memory management.             */        {        logMsg("malloc failure in m2pppSecretsEntrySet\n",0,0,0,0,0,0);        /* before we return we free reserverd memory*/        free(newDataEntryPtr->pppSecuritySecretsIdentity);        free(newDataEntryPtr->pppSecuritySecretsSecret);        free(newDataEntryPtr);        return ERROR;        }    else        {        /* data checks and memory allocation (almost all needed)          * have successfully completed. Since <status> == "VALID"          * We will now construct newDataEntry and newEntry the two         * nodes and we will attempt insertion keyed by the ldpi key.         */         (newDataEntryPtr->avlBase).left = NULL;        (newDataEntryPtr->avlBase).right = NULL;        (newDataEntryPtr->avlBase).height = 1;          newDataEntryPtr->pppSecuritySecretsLink = link;        newDataEntryPtr->pppSecuritySecretsIdIndex = 0;        newDataEntryPtr->pppSecuritySecretsDirection = direction;        newDataEntryPtr->pppSecuritySecretsProtocol = protocol;        strcpy(newDataEntryPtr->pppSecuritySecretsIdentity, identity);        strcpy(newDataEntryPtr->pppSecuritySecretsSecret, secret);        newDataEntryPtr->pppSecuritySecretsStatus =         PPP_SECURITY_SECRETS_STATUS_VALID;        (newEntryPtr->avlBase).left = NULL;        (newEntryPtr->avlBase).right = NULL;        (newEntryPtr->avlBase).height = 1;        newEntryPtr->pSecretsDataEntry = newDataEntryPtr;        PPP_SECRETS_SEM_TAKE;        auxGenericArgument.p = (void *)newDataEntryPtr;        auxStatus = avlInsertInform(pppSecretsDataTreePtr,                                    /*                                      * avlInsertInform's first argument                                      * should be a pointer to a pointer to                                      * the root node.                                     */                                    newDataEntryPtr,                                     auxGenericArgument,                                    (void **)(&retrievedDataEntryPtr),                                    ldpiDataKeyCompare);                                    /* note newDataEntryPtr appears twice */        if  (ERROR == auxStatus)            {            /* An entry with the given key exists already in the database.             * It is pointed by the retrievedDataEntryPtr. We will now             * change its secret, free unused memory, and return.             */            free(retrievedDataEntryPtr->pppSecuritySecretsSecret);            retrievedDataEntryPtr->pppSecuritySecretsSecret =                 newDataEntryPtr->pppSecuritySecretsSecret;            free(newDataEntryPtr->pppSecuritySecretsIdentity);            free(newDataEntryPtr);            free(newEntryPtr);            /* successful secret modification for an existing entry              * keyed by ldpi input key.             */            PPP_SECRETS_SEM_GIVE;            return OK;            }        else            {            /*              * If control reaches here then the value of retrievedDataEntryPtr              * is equal to newDataEntryPtr and we completed a new insertion in              * pppSecretsDataTree and it is necessary to insert a new node             * in the pppSecretsTree and In order to do this first we have             * to find the appropriate idIndex. To this end we will             * increase the link by one and set idIndex to zero so that             * using avlPredecessorGet we will get null or the pointer              * to the node with idIndex the maximum for the given link.             */            POPULATE_PPP_SECRETS_KEY_ENTRY;            keyDataEntry.pppSecuritySecretsLink++;            keyDataEntry.pppSecuritySecretsIdIndex = 0;            auxGenericArgument.p = (void *)(&keyEntry);            retrievedEntryPtr =             avlPredecessorGet(pppSecretsTree,                              auxGenericArgument,                              m2pppAgentKeyCompare);            newDataEntryPtr->pppSecuritySecretsIdIndex =                 (((retrievedEntryPtr != NULL) &&                  ((retrievedEntryPtr->                    pSecretsDataEntry)->                   pppSecuritySecretsLink == link))                   /* CAREFUL == is needed here */                 ? (retrievedEntryPtr->                    pSecretsDataEntry)->                   pppSecuritySecretsIdIndex + 1                 : 0);            auxGenericArgument.p = (void *)newEntryPtr;            if  (avlInsert(pppSecretsTreePtr,                                                   newEntryPtr,                           auxGenericArgument,                           m2pppAgentKeyCompare)                           /* note newEntryPtr appears twice */                 != OK)                /* we attempt to insert the corresponding primary node */                {                /* unexpected inertion failure */                logMsg("inconsistency: only secondary node was inserted\n",                       0,0,0,0,0,0);

⌨️ 快捷键说明

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