📄 v3mt_acc.c
字号:
/****************************************************************************NAME: accesstable_destroy_cleanupPURPOSE: Cleanup after an access test (delete) succeeded but some other test failed. We merely call the DESTROY_BACKOUT macro to allow the customer to restore any changed state. Expects the pointer to point to a VB_TPARAMETERS: ptr_t A pointer to the vb that points to the access that we were going to delete, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void accesstable_destroy_cleanup(ptr_t accessptr){SNMP_V3_ACCESS_DESTROY_BACKOUT(((VB_T *)accessptr)->vb_priv, 0);}/****************************************************************************NAME: accesstable_create_cleanupPURPOSE: Cleanup after an access create test succeeded but some other test failed. As this is a create the state pointer points to a structure that is installed, we need to deinstall it, call the backout routine, and cleanup the state. Expects the pointer to point to a VB_TPARAMETERS: ptr_t A pointer to the vb that points to the access that we were going to create, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void accesstable_create_cleanup(ptr_t accessptr){SNMP_ACCESS_T *access;access = (SNMP_ACCESS_T *)(((VB_T *)accessptr)->vb_priv);SNMP_V3_ACCESS_CREATE_BACKOUT(0, access);SNMP_V3_Access_Deinstall(access);SNMP_V3_Access_Destroy(access);}/****************************************************************************NAME: accesstable_update_cleanupPURPOSE: Cleanup after an access update test succeeded but some other test failed. As this is an update the state pointer points to a structure that isn't installed. The next pointer of that structure points to the installed copy. We call the backout routine and cleanup the state.PARAMETERS: ptr_t A pointer to the vb that points to the access that contained the update information, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void accesstable_update_cleanup(ptr_t accessptr){SNMP_ACCESS_T *access;access = (SNMP_ACCESS_T *)(((VB_T *)accessptr)->vb_priv);SNMP_V3_ACCESS_UPDATE_BACKOUT(access->next, access);SNMP_V3_Access_Destroy(access);}/****************************************************************************NAME: accesstable_destory_undoPURPOSE: This routine attempts to undo a previous destory set. It expects the old information to be pointed to by vb_priv and tries to reinstall it. If we can't reinstall the access we leave the cleanup routine alone in order to get the FINISHED macro to run.PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processsed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/static void accesstable_destroy_undo(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_ACCESS_T *access;bits8_t grp_name[ETC_ACCESS_GROUP_MAX], pre_name[ETC_ACCESS_ACCESS_MAX];ALENGTH_T grp_len = ETC_ACCESS_GROUP_MAX, pre_len = ETC_ACCESS_ACCESS_MAX;/* assume things will go well and mark the vbp as done */undoproc_good(pktp, vbp);/* find the state block we saved and then reset the vb_priv info so we don't have any accidents later */access = (SNMP_ACCESS_T *)vbp->vb_priv;vbp->vb_priv = 0;/* Reacquire the naming information, we don't need to test it as it was validated during the testproc */ (void) oid_to_string(tcount, tlist, &grp_len, grp_name, 0); (void) oid_to_string(tcount - ((int)(grp_len + 1)), tlist + grp_len + 1, &pre_len, pre_name, 0);if (SNMP_V3_Access_Install(access, grp_name, grp_len, pre_name, pre_len, (sbits32_t)tlist[2 + grp_len + pre_len], (sbits32_t)tlist[3 + grp_len + pre_len]) == 0) {#if defined(SNMP_V3_ACCESS_DESTROY_UNDO) if (SNMP_V3_ACCESS_DESTROY_UNDO(pktp, vbp, 0, access) == 0) { vbp->vb_free_priv = 0; return; } else SNMP_V3_Access_Deinstall(access);#else vbp->vb_free_priv = 0; return;#endif }SNMP_V3_Access_Destroy(access);undoproc_error(pktp, vbp, UNDO_FAILED);return;}/****************************************************************************NAME: accesstable_create_undoPURPOSE: This routine attempts to undo a previous create set. It expects the new information to be pointed to by vb_priv and tries to deinstall and destroy the entry.PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processsed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/static void accesstable_create_undo(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_ACCESS_T *access;/* assume things will go well */undoproc_good(pktp, vbp);/* find the state block we saved and then reset the vb_priv info so we don't have any accidents later */access = (SNMP_ACCESS_T *)vbp->vb_priv;vbp->vb_priv = 0;vbp->vb_free_priv = 0;#if defined(SNMP_V3_ACCESS_CREATE_UNDO)if (SNMP_V3_ACCESS_CREATE_UNDO(pktp, vbp, access, 0)) { undoproc_error(pktp, vbp, UNDO_FAILED); return; }#endifSNMP_V3_Access_Deinstall(access);SNMP_V3_Access_Destroy(access);return;}/****************************************************************************NAME: accesstable_update_undoPURPOSE: This routine attempts to undo a previous update set. It expects the struct pointed to by vb_priv to contain the old information and a pointer to the new (installed) struct.PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processsed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/static void accesstable_update_undo(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_ACCESS_T *cur_acc, *sav_acc;/* assume things will go well */undoproc_good(pktp, vbp);/* find the state block we saved and then reset the vb_priv info so we don't have any accidents later */sav_acc = (SNMP_ACCESS_T *)vbp->vb_priv;vbp->vb_priv = 0;vbp->vb_free_priv = 0;cur_acc = sav_acc->next;#if defined(SNMP_V3_ACCESS_UPDATE_UNDO)if (SNMP_V3_ACCESS_UPDATE_UNDO(pktp, vbp, cur_acc, sav_acc)) { /* we had an undo failure indicate that to our caller and get rid of the oldaccess */ undoproc_error(pktp, vbp, UNDO_FAILED); SNMP_V3_Access_Destroy(sav_acc); return; }#endif/* swap the info from saved access back into current access, we only need to move strings if the names are different finally free the saved block */SNMP_V3_Access_Set_Status(cur_acc, SNMP_V3_Access_Get_Status(sav_acc));SNMP_V3_Access_Set_Storage(cur_acc, SNMP_V3_Access_Get_Storage(sav_acc));SNMP_V3_Access_Set_Prefix_Match(cur_acc, SNMP_V3_Access_Get_Prefix_Match(sav_acc));if (EBufferStart(&cur_acc->readview) != EBufferStart(&sav_acc->readview)) { EBufferClean(&cur_acc->readview); MEMCPY(&cur_acc->readview, &sav_acc->readview, sizeof(EBUFFER_T)); EBufferInitialize(&sav_acc->readview); }if (EBufferStart(&cur_acc->writeview) != EBufferStart(&sav_acc->writeview)) { EBufferClean(&cur_acc->writeview); MEMCPY(&cur_acc->writeview, &sav_acc->writeview, sizeof(EBUFFER_T)); EBufferInitialize(&sav_acc->writeview); }if (EBufferStart(&cur_acc->notifyview) != EBufferStart(&sav_acc->notifyview)){ EBufferClean(&cur_acc->notifyview); MEMCPY(&cur_acc->notifyview, &sav_acc->notifyview, sizeof(EBUFFER_T)); EBufferInitialize(&sav_acc->notifyview); }SNMP_V3_Access_Destroy(sav_acc);return;}/****************************************************************************NAME: accesstable_set_cleanupPURPOSE: Free the saved access and indicate that we are finished.PARAMETERS: ptr_t A pointer to the vb that points to the access that contained the update information, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void accesstable_set_cleanup(ptr_t accessptr){if (((VB_T *)accessptr)->vb_priv) { if (((VB_T *)accessptr)->undoproc == accesstable_create_undo) ((VB_T *)accessptr)->vb_priv = 0; else SNMP_V3_Access_Destroy(((VB_T *)accessptr)->vb_priv); }SNMP_V3_ACCESS_FINISHED();}/****************************************************************************NAME: accesstable_testPURPOSE: This routine collects all of the var binds that want to be set in a row and does value and consistency checking on those varbinds before trying to allocate any space. PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processsed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void accesstable_test(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_ACCESS_T *access, tempaccess, *newaccess;sbits32_t value, ptret;int cago = 0, create_row = 0, rd_chg = 0, wr_chg = 0, no_chg = 0;ALENGTH_T nlen = 0;VB_T *tvbp;bits8_t grp_name[ETC_ACCESS_GROUP_MAX], name[ETC_ACCESS_ACCESS_MAX];ALENGTH_T grp_namelen = ETC_ACCESS_GROUP_MAX, namelen = ETC_ACCESS_ACCESS_MAX;/* get the list of var binds that may go into this structure then mark all the vbs except the first one as having been tested, set and done. This means that vbp is taking responsibility for all of the other vbs in the row. Then mark vbp as haing it's test started & done so we don't have to worry about it later. We can do this because the routine will run to completion */group_by_getproc_and_instance(pktp, vbp, tcount, tlist);for(tvbp = vbp->vb_link; tvbp; tvbp = tvbp->vb_link) setproc_all_bits(pktp, tvbp);testproc_good(pktp, vbp);/* gather the indexing information, the index will be of the form: <len> <group name> <len> <prefix> <model> <level> first we do some minor checks then we attempt to find the access */if ((tcount < 5 ) || (tlist[0] == 0) || oid_to_string(tcount, tlist, &grp_namelen, grp_name, 0) || ((bits32_t)(grp_namelen + 1) > (bits32_t)tcount) || oid_to_string(tcount - ((int)(grp_namelen + 1)), tlist + grp_namelen + 1, &namelen, name, 0) || ((bits32_t)(grp_namelen + namelen + 4) != (bits32_t)tcount) || (tlist[2 + grp_namelen + namelen] >= 0x80000000L) || (tlist[3 + grp_namelen + namelen] == 0) || (tlist[3 + grp_namelen + namelen] > 4)) { testproc_error(pktp, vbp, NO_CREATION); return; }access = SNMP_V3_Access_Lookup(grp_name, grp_namelen, name, namelen, (sbits32_t)tlist[2 + grp_namelen + namelen], (sbits32_t)tlist[3 + grp_namelen + namelen]);/* Note that the check for status is simpler than the general case as this table has few objects and all but status have defvals. This means that several conditions can't occur. So create and go is always acceptable and is almost the same as create and wait, active and not in service are also similiar. *//* is the leaf writable, (if it's read only it isn't writable) */if (access != 0) { if (SNMP_V3_Access_Get_Storage(access) == ETC_STO_RONLY) { testproc_error(pktp, vbp, NOT_WRITABLE); return; } MEMCPY(&tempaccess, access, sizeof(SNMP_ACCESS_T)); }else { SNMP_V3_Access_Set_Defaults(&tempaccess); create_row = 1; } for (tvbp = vbp; tvbp; tvbp = tvbp->vb_link) { switch (tvbp->vb_ml.ml_last_match) { case LM_accessContextMatch: value = tvbp->value_u.v_number; if ((value != ETC_ACCESS_EXACT) && (value != ETC_ACCESS_PREFIX)) { testproc_error(pktp, tvbp, WRONG_VALUE); return; } SNMP_V3_Access_Set_Prefix_Match(&tempaccess, (int)value); break; case LM_accessRead: nlen = EBufferUsed(&tvbp->value_u.v_string); if (nlen > ETC_ACCESS_VIEW_MAX) { testproc_error(pktp, tvbp, WRONG_LENGTH);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -