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

📄 m2pppsecuritysecretslib.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
                free(newEntryPtr);                /* Only secondary insertion was accomplished;                 * insertion failed due to database inconsistency                 */                PPP_SECRETS_SEM_GIVE;                return ERROR;                }            else                {                /* successful insertion of new node */                PPP_SECRETS_SEM_GIVE;                return OK;                }            }        }    }/******************************************************************************** m2pppSecretsSecretGet - get the secret that corresponds to the auxiliary key* * Get the secret corresponding to the non-specified internal key* (pppSecuritySecretsLink, pppSecuritySecretsDirection, * pppSecuritySecretsProtocol, pppSecuritySecretsIdentity). ** RETURNS: OK if a database entry is paired to the input key -in which case it* places its secret in the buffer pointed by <secret> - or ERROR*/STATUS m2pppSecretsSecretGet    (    UINT32                          link,      /* pppSecuritySecretsLink */    PPP_SECURITY_SECRETS_DIRECTION  direction, /* pppSecuritySecretsDirection */    PPP_SECURITY_PROTOCOL           protocol,  /* pppSecuritySecretsProtocol */    char *                          identity,  /* pppSecuritySecretsIdentity */    char *                          secret     /* placeholder of return data */    )    {    PPP_SECURITY_SECRETS_DATA_ENTRY keyDataEntry;    PPP_SECURITY_SECRETS_DATA_ENTRY *   retrievedDataEntryPtr;    GENERIC_ARGUMENT auxGenericArgument;    /* first we check consistency of input data */    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) ||         (NULL == secret))        {        /* we will abort m2pppSecretsEntryGet due to invalid input data */        return ERROR;        };            POPULATE_PPP_SECRETS_DATA_KEY_ENTRY;    PPP_SECRETS_SEM_TAKE;    auxGenericArgument.p = (void *)(&keyDataEntry);    if  (NULL == (retrievedDataEntryPtr =                   avlSearch(pppSecretsDataTree,                            auxGenericArgument,                            ldpiDataKeyCompare)))        {        PPP_SECRETS_SEM_GIVE;        return ERROR;        }    else        {        strcpy(secret, retrievedDataEntryPtr->pppSecuritySecretsSecret);        PPP_SECRETS_SEM_GIVE;        return OK;        }    }/******************************************************************************** m2pppSecretsEntryAgentSet - delete/insert/modify keyed by (link, idIndex)** Delete, insert, or modify an m2pppSecuritySecretsLib database entry* accessing it via its SNMP specified key (pppSecuritySecretsLink, * pppSecuritySecretsIdIndex). ** If the status is set to PPP_SECURITY_SECRETS_STATUS_INVALID then* it will be interpreted as a request for deletion and the only input data* required would be pppSecuritySecretsLink and pppSecuritySecretsIdIndex.** 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.** Besides the uniqueness of the ordered * pair (pppSecuritySecretsLink, pppSecuritySecretsIdIndex) we also enforce * uniqueness of the ordered quadraple * (pppSecuritySecretsLink, pppSecuritySecretsDirection, * pppSecuritySecretsProtocol, pppSecuritySecretsIdentity). * Subsequently, the semantics of an insertion-modification should be* expanded to include a potential implicit deletion necessitated * by the requirement to preserve the integrity of the internal database.* * RETURNS: OK or ERROR*/STATUS m2pppSecretsEntryAgentSet    (    UINT32                              link,       /* required */     UINT32                              idIndex,    /* required */    PPP_SECURITY_SECRETS_DIRECTION *    pDirection, /* NULL if not supplied */    PPP_SECURITY_PROTOCOL *             pProtocol,  /* NULL if not supplied */    char *                              identity,   /* NULL if not supplied */    char *                              secret,     /* NULL if not supplied */    PPP_SECURITY_SECRETS_STATUS         status      /* required */    )    {    PPP_SECURITY_SECRETS_ENTRY  keyEntry;    PPP_SECURITY_SECRETS_ENTRY *    retrievedEntryPtr = NULL;    PPP_SECURITY_SECRETS_ENTRY *    newEntryPtr = NULL;    PPP_SECURITY_SECRETS_DATA_ENTRY keyDataEntry;    PPP_SECURITY_SECRETS_DATA_ENTRY *   retrievedDataEntryPtr = NULL;    PPP_SECURITY_SECRETS_DATA_ENTRY *   newDataEntryPtr = NULL;    GENERIC_ARGUMENT auxGenericArgument;    if  ((link > MAX_LINK) ||         (idIndex > MAX_ID_INDEX) ||         ((status != PPP_SECURITY_SECRETS_STATUS_INVALID) &&           (status != PPP_SECURITY_SECRETS_STATUS_VALID)) ||         /* We remove this test and we allow this set of data            *          * ((PPP_SECURITY_SECRETS_STATUS_VALID == status) &&           *  (NULL == pDirection) && (NULL == pProtocol) &&          *  (NULL == identity) && (NULL == secret)) ||          *          */         ((pDirection != NULL) &&           (*pDirection != PPP_SECURITY_SECRETS_DIRECTION_LOCAL_TO_REMOTE) &&           (*pDirection != PPP_SECURITY_SECRETS_DIRECTION_REMOTE_TO_LOCAL)) ||         ((pProtocol != NULL) &&          (*pProtocol != PPP_SECURITY_PAP_PROTOCOL) &&           (*pProtocol != PPP_SECURITY_CHAP_MD5_PROTOCOL)) ||         ((identity != NULL) && (strlen(identity) > 255)) ||         ((secret != NULL) && (strlen(secret) > 255)))        /* first we check consistency of input data */        {        /* we will abort pppSecretsSet 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 m2pppSecretsEntryAgentDelete(link, idIndex);        }    /*      * if control reaches here then <status> == "VALID".     * 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 m2pppSecretsEntryAgentSet",0,0,0,0,0,0);        return ERROR;        }    else if ((identity != NULL) &&             (NULL == (newDataEntryPtr->pppSecuritySecretsIdentity = (char *)                         malloc(sizeof(char)*(strlen(identity)+1)))))            /* we also allocate space for the new identity */        {        logMsg("malloc failure in m2pppSecretsEntryAgentSet",0,0,0,0,0,0);        /* before we return we free reserved memory */        free(newDataEntryPtr);        return ERROR;        }    else if ((secret != NULL) &&             (NULL == (newDataEntryPtr->pppSecuritySecretsSecret = (char *)                         malloc(sizeof(char)*(strlen(secret)+1)))))            /* we also allocate space for the new secret */        {        logMsg("malloc failure in m2pppSecretsEntryAgentSet",0,0,0,0,0,0);        /* before we return we free reserved memory */        if  (identity != NULL)             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 m2pppSecretsEntryAgentSet",0,0,0,0,0,0);        /* before we return we free reserverd memory*/        if  (identity != NULL)            free(newDataEntryPtr->pppSecuritySecretsIdentity);        if  (secret != NULL)            free(newDataEntryPtr->pppSecuritySecretsSecret);        free(newDataEntryPtr);        return ERROR;        }    /* if control reaches this point then we know that we have received a     * request for insertion or update and we will first attempt insertion in     * primary - SNMP specified - tree that is indexed by (link, idIndex).     */    else        {        (newDataEntryPtr->avlBase).left = NULL;        (newDataEntryPtr->avlBase).right = NULL;        (newDataEntryPtr->avlBase).height = 1;          newDataEntryPtr->pppSecuritySecretsLink = link;        newDataEntryPtr->pppSecuritySecretsIdIndex = idIndex;        /*               * direction, protocol, identity, secret, and status         * initialization is postponed         *          * newDataEntryPtr->pppSecuritySecretsDirection =         * newDataEntryPtr->pppSecuritySecretsProtocol =          * newDataEntryPtr->pppSecuritySecretsIdentity =         * newDataEntryPtr->pppSecuritySecretsSecret =         * newDataEntryPtr->pppSecuritySecretsStatus =          */                (newEntryPtr->avlBase).left = NULL;        (newEntryPtr->avlBase).right = NULL;        (newEntryPtr->avlBase).height = 1;        newEntryPtr->pSecretsDataEntry = newDataEntryPtr;        PPP_SECRETS_SEM_TAKE;        auxGenericArgument.p = (void *)newEntryPtr;        if  (ERROR ==              avlInsertInform(pppSecretsTreePtr,                             /*                               * avlInsertInform's first argument should be a                               * pointer to a pointer to the root node.                              */                             newEntryPtr,                              auxGenericArgument,                             (void **)(&retrievedEntryPtr),                             m2pppAgentKeyCompare))                             /* note newEntryPtr appears twice */            /* We attempt insertion. If successful then retrievedEntryPtr             * will be equal to newEntryPtr and it will not be used. Else             * it will point to the conflicting primary tree node.             */            {            /* An entry with the given key exists already in the database.             * It is pointed by the retrievedEntryPtr. We will now combine             * the input data with the data of the existing data entry and if             * the ppp keys of the new -composite- data entry and the current             * one match then we will simply change the secret or in case             * that we have created a new ppp key we will remove the current             * data entry and we will insert the new one to the data tree.             *             * WE TREAT MODIFICATION/INSERTION AS A POTENTIAL INSERTION             */            /* First, the pointer to the old PPP_SECURITY_SECRETS_DATA_ENTRY              * is copied for safekeeping in retrievedDataEntryPtr.             */            retrievedDataEntryPtr = retrievedEntryPtr->pSecretsDataEntry;            /* Second, we start assemblying the new entry */                        newDataEntryPtr->pppSecuritySecretsDirection =                 ((pDirection != NULL)                  ? *pDirection                 : retrievedDataEntryPtr-> pppSecuritySecretsDirection);                             newDataEntryPtr->pppSecuritySecretsProtocol =                 ((pProtocol != NULL)                  ? *pProtocol                 : retrievedDataEntryPtr-> pppSecuritySecretsProtocol);            if  (NULL == identity)                /* if NULL == identity then memory is NOT allocated as yet */                {                /* NULL == identity and so we need allocate memory and                 * copy the identity of the existing entry into the new.                 */                if  (NULL == (newDataEntryPtr->pppSecuritySecretsIdentity =                              (char *)malloc(sizeof(char)*                                             (strlen(retrievedDataEntryPtr->                                                     pppSecuritySecretsIdentity)                                              +1))))                    {                    /* malloc failed and we will abort */                    logMsg("malloc failure in m2pppSecretsEntryAgentSet",                           0,0,0,0,0,0);                    /* before we return we free reserverd memory*/                    if  (secret != NULL)                        free(newDataEntryPtr->pppSecuritySecretsSecret);                    free(newDataEntryPtr);                    free(newEntryPtr);                            /* we encountered an element with the input (link, idIndex)                     * primary key; we started constructing the new entry                     * but we were forced to exit due to malloc failure.                     */                                        PPP_SECRETS_SEM_GIVE;                    return ERROR;                    }                else

⌨️ 快捷键说明

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