📄 vmth2275.c
字号:
/* find the state block we saved and then reset the vb_priv info so we don't have any accidents later */view = (VIEWLEAF_T *)vbp->vb_priv;vbp->vb_priv = 0;vbp->vb_free_priv = 0;#if defined(SNMP_VIEW_2275_CREATE_UNDO)if (SNMP_VIEW_2275_CREATE_UNDO(pktp, vbp, view, 0)) { undoproc_error(pktp, vbp, UNDO_FAILED); return; }#endifSNMP_View_2275_Deinstall(view);SNMP_View_Delete(view);return;}/****************************************************************************NAME: viewtable_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 viewtable_update_undo(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){VIEWLEAF_T *cur_view, *sav_view;/* 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_view = (VIEWLEAF_T *)vbp->vb_priv;vbp->vb_priv = 0;vbp->vb_free_priv = 0;cur_view = sav_view->lexinext;#if defined(SNMP_VIEW_2275_UPDATE_UNDO)if (SNMP_VIEW_2275_UPDATE_UNDO(pktp, vbp, cur_view, sav_view)) { /* we had an undo failure indicate that to our caller and get rid of the old view */ undoproc_error(pktp, vbp, UNDO_FAILED); SNMP_View_Delete(sav_view); return; }#endif/* swap the info from saved view back into current view, we only need to move strings if the names are different finally free the saved block */SNMP_View_Set_Type(cur_view, SNMP_View_Get_Type(sav_view));SNMP_View_Set_Status(cur_view, SNMP_View_Get_Status(sav_view));SNMP_View_Set_StorageType(cur_view, SNMP_View_Get_StorageType(sav_view));if (EBufferStart(&cur_view->mask) != EBufferStart(&sav_view->mask)) { EBufferClean(&cur_view->mask); MEMCPY(&cur_view->mask, &sav_view->mask, sizeof(EBUFFER_T)); EBufferInitialize(&sav_view->mask); }SNMP_View_Delete(sav_view);return;}/****************************************************************************NAME: viewtable_set_cleanupPURPOSE: Free the saved view and indicate that we are finished.PARAMETERS: PTR_T A pointer to the vb that points to the view to delete cast as a PTR_TRETURNS: Nothing****************************************************************************/static void viewtable_set_cleanup(PTR_T viewptr){if (((VB_T *)viewptr)->vb_priv) { if (((VB_T *)viewptr)->undoproc == viewtable_create_undo) ((VB_T *)viewptr)->vb_priv = 0; else SNMP_View_Delete((VIEWLEAF_T *)(((VB_T *)viewptr)->vb_priv)); }SNMP_VIEW_2275_FINISHED();}/****************************************************************************NAME: viewtable_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 viewtable_test(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){VIEWLEAF_T *view, tempview, *newview;sbits32_t value, ptret;int cago = 0, create_row = 0, mask_chg = 0, oidclen;ALENGTH_T nlen = 0, namelen = ETC_VIEW_NAME_MAX;VB_T *tvbp;bits8_t name[ETC_VIEW_NAME_MAX];OIDC_T *oidc;/* 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);/* The index will be of the form <len> <name> <len> <subtree> first we see if the name will work then we try and find the view */if ((tcount < 1) || (oid_to_string(tcount, tlist, &namelen, name, 0)) || (namelen > ETC_VIEW_NAME_MAX) || (namelen < ETC_VIEW_NAME_MIN) || ((OIDC_T)tcount != (2 + namelen + tlist[namelen+1])) || (tlist[namelen+1] > MAX_SUBIDS)) { testproc_error(pktp, vbp, NO_CREATION); return; }oidc = tlist + namelen + 2;oidclen = (int)(tlist[namelen+1]);view = SNMP_View_2275_Lookup(name, namelen, oidc, oidclen);/* 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 (view != 0) { if (SNMP_View_Get_StorageType(view) == ETC_STO_RONLY) { testproc_error(pktp, vbp, NOT_WRITABLE); return; } MEMCPY(&tempview, view, sizeof(VIEWLEAF_T)); }else { SNMP_View_Set_Defaults(&tempview); create_row = 1; } for (tvbp = vbp; tvbp; tvbp = tvbp->vb_link) { switch (tvbp->vb_ml.ml_last_match) { case LM_viewMask: nlen = EBufferUsed(&tvbp->value_u.v_string); if (nlen > VIEW_MAXMASKLEN) { testproc_error(pktp, tvbp, WRONG_LENGTH); return; } EBufferPreLoad(BFL_IS_STATIC, &tempview.mask, EBufferStart(&tvbp->value_u.v_string), nlen); break; case LM_viewType: value = tvbp->value_u.v_number; if ((value != VIEW_INCLUDED) && (value != VIEW_EXCLUDED)) { testproc_error(pktp, tvbp, WRONG_VALUE); return; } SNMP_View_Set_Type(&tempview, value); break; case LM_viewStorageType: value = tvbp->value_u.v_number; if ((value < ETC_STO_OTHER) || (value > ETC_STO_RONLY) || ((view != 0) && (value > ETC_STO_NONVOL)) || (SNMP_View_Get_StorageType(&tempview) >= ETC_STO_PERM)) { testproc_error(pktp, tvbp, WRONG_VALUE); return; } SNMP_View_Set_StorageType(&tempview, (int)value); break; case LM_viewStatus: value = tvbp->value_u.v_number; switch (value) { case ETC_RS_ACTIVE: case ETC_RS_NIS: if (create_row) { testproc_error(pktp, tvbp, INCONSISTENT_VALUE); return; } break; case ETC_RS_CAGO: if (create_row == 0) { testproc_error(pktp, tvbp, INCONSISTENT_VALUE); return; } value = ETC_RS_ACTIVE; cago = 1; break; case ETC_RS_CAWAIT: if (create_row == 0) { testproc_error(pktp, tvbp, INCONSISTENT_VALUE); return; } value = ETC_RS_NIS; break; case ETC_RS_DESTROY: if (SNMP_View_Get_StorageType(&tempview) >= ETC_STO_PERM) { testproc_error(pktp, tvbp, WRONG_VALUE); return; } break; default: testproc_error(pktp, tvbp, WRONG_VALUE); return; } if (SNMP_View_Get_Status(&tempview) != ETC_RS_DESTROY) SNMP_View_Set_Status(&tempview, (int)value); break; } } /* The values are ok */if (SNMP_View_Get_Status(&tempview) == ETC_RS_DESTROY) { if (view != 0) { ptret = SNMP_VIEW_2275_DESTROY_TEST(pktp, vbp, view, 0); if (ptret != NO_ERROR) { testproc_error(pktp, vbp, ptret); } else { vbp->vb_priv = (PTR_T)view; vbp->vb_free_priv = viewtable_destroy_cleanup; } } else { /* We have a destroy request, but no view so we don't have to do anything during the set and, if necessary, the undo phases so we mark the setvbp as set and undone */ setproc_all_bits(pktp, vbp); } return; }/* See if anything actually changed, if it didn't we can mark the vbp as done and not have to do any more work. If we are creating an entry mark the mask as having chagned so they will get copied */if (view) { if ((SNMP_View_Get_Mask(view) == SNMP_View_Get_Mask(&tempview)) || ((SNMP_View_Get_MaskLen(view) == SNMP_View_Get_MaskLen(&tempview)) && (MEMCMP_NULLOK(SNMP_View_Get_Mask(view), SNMP_View_Get_Mask(&tempview), SNMP_View_Get_MaskLen(view)) == 0))) { if ((SNMP_View_Get_Type(view) == SNMP_View_Get_Type(&tempview)) && (SNMP_View_Get_Status(view) == SNMP_View_Get_Status(&tempview)) && (SNMP_View_Get_StorageType(view) == SNMP_View_Get_StorageType(&tempview))) { setproc_all_bits(pktp, vbp); return; } } else mask_chg = 1; } else { mask_chg = 1; }/* Because of how we do the backout stuff we always allocate a new viewleaf and set it up */newview = SNMP_View_Create(oidc, oidclen);if (newview == 0) { testproc_error(pktp, vbp, RESOURCE_UNAVAILABLE); return; }SNMP_View_Set_Type(newview, SNMP_View_Get_Type(&tempview));SNMP_View_Set_Status(newview, SNMP_View_Get_Status(&tempview));SNMP_View_Set_StorageType(newview, SNMP_View_Get_StorageType(&tempview));if (mask_chg) { if (EBufferClone(&tempview.mask, &newview->mask) != 0) { SNMP_View_Delete(newview); testproc_error(pktp, vbp, RESOURCE_UNAVAILABLE); return; } }else { EBufferPreLoad(BFL_IS_STATIC, &newview->mask, SNMP_View_Get_Mask(view), SNMP_View_Get_MaskLen(view)); }/* if we are creating a new viewleaf we need to install it in the tree and run the create test, if we are updating an old viewleaf we just run the update test */if (view == 0) { if (SNMP_View_2275_Install(newview, name, namelen)) { SNMP_View_Delete(newview); testproc_error(pktp, vbp, RESOURCE_UNAVAILABLE); return; } ptret = SNMP_VIEW_2275_CREATE_TEST(pktp, vbp, 0, newview); if (ptret != NO_ERROR) { SNMP_View_2275_Deinstall(newview); SNMP_View_Delete(newview); testproc_error(pktp, vbp, ptret); return; } vbp->vb_free_priv = viewtable_create_cleanup; }else { ptret = SNMP_VIEW_2275_UPDATE_TEST(pktp, vbp, view, newview); if (ptret != NO_ERROR) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -