📄 m2pppsecuritysecretslib.c
字号:
{ /* malloc for identity was successful and we copy identity * of conflicting entry into new -under construction- entry. */ strcpy(newDataEntryPtr->pppSecuritySecretsIdentity, retrievedDataEntryPtr-> pppSecuritySecretsIdentity); } } else { /* input identity was not NULL hence memory for its * storage has been already allocated and now we assign * the input identity to the new -under construction- entry. */ strcpy(newDataEntryPtr->pppSecuritySecretsIdentity, identity); } if (NULL == secret) /* if NULL == secret then memory is NOT allocated as yet */ { /* NULL == secret and so we need allocate memory and * copy the secret of the existing entry into the new. */ if (NULL == (newDataEntryPtr->pppSecuritySecretsSecret = (char *)malloc(sizeof(char)* (strlen(retrievedDataEntryPtr-> pppSecuritySecretsSecret) +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*/ free(newDataEntryPtr->pppSecuritySecretsIdentity); 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 { /* malloc for secret was successful and we copy the secret * of the conflicting entry into the data of the new entry. */ strcpy(newDataEntryPtr->pppSecuritySecretsSecret, (retrievedEntryPtr-> pSecretsDataEntry)-> pppSecuritySecretsSecret); } /* the subsequent parenthesis closes the * part of the code that will be executed * if NULL == secret */ } else { /* input secret was not NULL hence memory for its * storage has been already allocated and now we incorporate * the input secret to the new data entry. */ strcpy(newDataEntryPtr->pppSecuritySecretsSecret, secret); } newDataEntryPtr->pppSecuritySecretsStatus = PPP_SECURITY_SECRETS_STATUS_VALID; /* construction of the new entry has been completed */ auxGenericArgument.p = (void *)newDataEntryPtr; if (0 == ldpiDataKeyCompare((void *)(retrievedEntryPtr-> pSecretsDataEntry), auxGenericArgument)) { /* * the keys are the same hence we need only alter the secret. * However, first we free memory reserved for the new primary * SHALLOW data. */ free(newEntryPtr); if (secret != NULL) /* * as a matter of fact if NULL == secret then the request * was redundant. */ { free((retrievedEntryPtr-> pSecretsDataEntry)-> pppSecuritySecretsSecret); /* assign the new secret */ (retrievedEntryPtr-> pSecretsDataEntry)-> pppSecuritySecretsSecret = newDataEntryPtr-> pppSecuritySecretsSecret; /* * before we exit we free memory reserved for the * secondary tree entry. This includes memory for its * identity and memory for its shallow data. */ free(newDataEntryPtr->pppSecuritySecretsIdentity); free(newDataEntryPtr); /* new secret was asssigned to an existing entry */ PPP_SECRETS_SEM_GIVE; return OK; } else { /* it seems that the request was redundant */ free(newDataEntryPtr->pppSecuritySecretsIdentity); free(newDataEntryPtr->pppSecuritySecretsSecret); free(newDataEntryPtr); /* the request was redundant */ PPP_SECRETS_SEM_GIVE; return OK; } } else { /* * data keys differ hence we should delete the old data entry * and insert the new one. This is an implicit deletion * substitution with no analog in m2pppSecretsEntrySet. * It is necessary in order to maintain the integrity of * the secrets database. That is, in order to have * (link, idIndex) and (link, direction, protocol, identity) * keys unique and also have one to one correspondence * between primary and secondary keys. */ auxGenericArgument.p = (void *)(retrievedDataEntryPtr); if (NULL == (retrievedDataEntryPtr = avlDelete(pppSecretsDataTreePtr, auxGenericArgument, ldpiDataKeyCompare))) /* * note retrievedDataEntryPtr appears intentioally twice * in the above conditional. Once as a key and once as * the place holder for the return value of avlDelete. * The reason is that even though we have a valid node * pointer we cannot delete it directly but we should * first remove it from the tree. When avlDelete returns * the value of retrievedDataEntryPtr is not expected to * change. */ { logMsg("inconsistency: secondary entry not visible\n", 0,0,0,0,0,0); logMsg("we will leave altering nothing\n",0,0,0,0,0,0); free(newDataEntryPtr->pppSecuritySecretsIdentity); free(newDataEntryPtr->pppSecuritySecretsSecret); free(newDataEntryPtr); free(newEntryPtr); /* We constructed a new entry using new and old data. * We attempted to delete the old secondary entry and * we failed due to database inconsistency. */ PPP_SECRETS_SEM_GIVE; return ERROR; } else { /* we free the memory reserved for the old data entry */ free(retrievedDataEntryPtr->pppSecuritySecretsIdentity); free(retrievedDataEntryPtr->pppSecuritySecretsSecret); free(retrievedDataEntryPtr); retrievedEntryPtr->pSecretsDataEntry = newDataEntryPtr; /* free SHALLOW new entry */ free(newEntryPtr); /* we will forcefully insert the new data entry */ auxGenericArgument.p = (void *)newDataEntryPtr; if (NULL == (retrievedDataEntryPtr = avlRemoveInsert(pppSecretsDataTreePtr, newDataEntryPtr, auxGenericArgument, ldpiDataKeyCompare))) /* newDataEntryPtr appears twice */ { /* We constructed a new entry using new and old data. * We deleted the old secondary entry and the new entry * was entered without conflict. */ PPP_SECRETS_SEM_GIVE; return OK; } else { /* in order to enter the new data entry we had to * remove another data entry. We will retrieve its * (link,idIndex) primary key and we will delete * the corresponding primary tree node. */ POPULATE_PPP_SECRETS_KEY_ENTRY; keyDataEntry.pppSecuritySecretsLink = retrievedDataEntryPtr->pppSecuritySecretsLink; keyDataEntry.pppSecuritySecretsIdIndex = retrievedDataEntryPtr->pppSecuritySecretsIdIndex; /* we free the memory reserved for the old data entry */ free(retrievedDataEntryPtr->pppSecuritySecretsIdentity); free(retrievedDataEntryPtr->pppSecuritySecretsSecret); free(retrievedDataEntryPtr); auxGenericArgument.p = (void *)(&keyEntry); if (NULL == (retrievedEntryPtr = avlDelete(pppSecretsTreePtr, auxGenericArgument, m2pppAgentKeyCompare))) { logMsg("inconsistency: invisible primary node\n", 0,0,0,0,0,0); logMsg("SERIOUS INCONSISTENCY\n",0,0,0,0,0,0); logMsg("recovery was not attempted\n",0,0,0,0,0,0); logMsg("corresponding secondary node was removed\n", 0,0,0,0,0,0); /* We constructed a new entry using new and old * data. We deleted the old secondary entry and * when we tried to enter the new secondary entry * we encountered conflict. To resolve it we had * to remove the primary entry that corresponds to * the conflicting secondary entry. Unfortunately * we failed due to database inconsistency. */ PPP_SECRETS_SEM_GIVE; return ERROR; } else { free(retrievedEntryPtr); /* We constructed a new entry using new and old * data. We deleted the old secondary entry and * when we tried to enter the new secondary entry * we encountered conflict. To resolve it we had * to remove the primary entry that corresponds to * the conflicting secondary entry. */ PPP_SECRETS_SEM_GIVE; return OK; } } } } } else { /* * The input (link, idIndex) pair was a new primary key and * avlInsertInform inserted a new node in the primary tree. * We will check for consistency of data once more and * we will try to forcefully insert this entry via its * secondary key. */ if ((NULL == pDirection) || (NULL == pProtocol) || (NULL == identity) || (NULL == secret)) { /* we will abort due to insufficient data */ auxGenericArgument.p = (void *)(newEntryPtr); if (NULL == (retrievedEntryPtr = avlDelete(pppSecretsTreePtr, auxGenericArgument, m2pppAgentKeyCompare))) /* we expect retrievedEntryPtr to be equal to newEntryPtr */ { logMsg("inconsistency; invisible improper primary node\n", 0,0,0,0,0,0); logMsg("recovery will not be attempted\n",0,0,0,0,0,0); logMsg("SERIOUS INCONSISTENCY\n",0,0,0,0,0,0); logMsg("inserted improper primary node is invisible\n", 0,0,0,0,0,0); /* We inserted a primary node. We realized that we do not * have sufficient data to proceed. We tried to cancel * the insertion of the primary node but we failed due to * database inconsistency. */ PPP_SECRETS_SEM_GIVE; return ERROR; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -