📄 viewmth.c
字号:
case LM_viewMask: nlen = EBufferUsed(&tvbp->value_u.v_string); if (nlen > VIEW_MAXMASKLEN) { testproc_error(pktp, tvbp, WRONG_VALUE); 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 < STO_OTHER) || (value > STO_NONVOL)) { 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 RS_ACTIVE: case RS_NIS: if (create_row) { testproc_error(pktp, tvbp, INCONSISTENT_VALUE); return; } break; case RS_CAGO: if (create_row == 0) { testproc_error(pktp, tvbp, INCONSISTENT_VALUE); return; } value = RS_ACTIVE; cago = 1; break; case RS_CAWAIT: if (create_row == 0) { testproc_error(pktp, tvbp, INCONSISTENT_VALUE); return; } value = RS_NIS; break; case RS_DESTROY: break; default: testproc_error(pktp, tvbp, WRONG_VALUE); return; } SNMP_View_Set_Status(&tempview, (int)value); break; } } /* Mark all vbs in the row except for setvbp as being tested, set and done. This means that setvbp is taking responsibility for all of the other vbs in the row. Then mark setvbp as having it's test started & done so we don't have to worry about it later, we can do this because the routine will complete and setvbp will be done */for(tvbp = vbplist; tvbp; tvbp = tvbp->vb_link) if (tvbp != setvbp) { setproc_all_bits(pktp, tvbp); }testproc_started(pktp, setvbp);testproc_good(pktp, setvbp);/* The values are ok */if (SNMP_View_Get_Status(&tempview) == RS_DESTROY) { if (view != 0) { ptret = SNMP_VIEW_DESTROY_TEST(pktp, view); if (ptret != NO_ERROR) { testproc_tproc_error(pktp, setvbp, ptret); } else { testproc_good(pktp, setvbp); setvbp->vb_priv = (PTR_T)view; setvbp->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, setvbp); } return; } /* Because of how we do the backout stuff we always allocate a new viewleaf and set it up */newview = SNMP_View_Create(tlist + 1, tcount - 1);if (newview == 0) { testproc_error(pktp, setvbp, RESOURCE_UNAVAILABLE); return; }newview->index = tempview.index;newview->type = tempview.type;newview->storage = tempview.storage;newview->status = tempview.status;if (EBufferClone(&tempview.mask, &newview->mask) != 0) { SNMP_View_Delete(newview); testproc_error(pktp, setvbp, RESOURCE_UNAVAILABLE); return; }/* 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_Install((UINT_16_T)tlist[0], newview) != 0) { SNMP_View_Delete(newview); testproc_error(pktp, setvbp, RESOURCE_UNAVAILABLE); return; } ptret = SNMP_VIEW_CREATE_TEST(pktp, newview); if (ptret != TPROC_GOOD) { if (SNMP_View_Deinstall((UINT_16_T)tlist[0], tlist + 1, tcount - 1) == 0) SNMP_View_Delete(newview); testproc_error(pktp, setvbp, RESOURCE_UNAVAILABLE); return; } }else { ptret = SNMP_VIEW_UPDATE_TEST(pktp, view, newview); if (ptret != TPROC_GOOD) { SNMP_View_Delete(newview); testproc_error(pktp, setvbp, RESOURCE_UNAVAILABLE); return; } }if (cago) SNMP_View_Set_Status(newview, RS_CAGO);setvbp->vb_priv = (PTR_T)newview;setvbp->vb_free_priv = viewtable_test_cleanup;testproc_good(pktp, setvbp);return;}/****************************************************************************NAME: viewtable_getPURPOSE: Find the appropriate entry in the acl table and attach information from it to the vbp using the getproc_got_* functions. If we can't find an entry indicate that by calling getproc_nosuchins.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 processed. VB_T * Variable being processed.RETURNS: void****************************************************************************/void viewtable_get(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){VIEWLEAF_T *view;/* There must be at least 1 subid, the first subid must be less than the max view, and the view must exist */if ((tcount < 1) || (tlist[0] > VIEW_MAXINDEXL) || ((view = SNMP_View_Lookup((UINT_16_T)tlist[0], tlist + 1, tcount - 1)) == 0)) { getproc_nosuchins(pktp, vbp); return; }/* we found a node dig out the information */switch(last_match) { case LM_viewMask: getproc_got_string(pktp, vbp, SNMP_View_Get_MaskLen(view), SNMP_View_Get_Mask(view), 0, VT_STRING); break; case LM_viewType: getproc_got_int32(pktp, vbp, SNMP_View_Get_Type(view)); break; case LM_viewStorageType: getproc_got_int32(pktp, vbp, SNMP_View_Get_StorageType(view)); break; case LM_viewStatus: getproc_got_int32(pktp, vbp, SNMP_View_Get_Status(view)); break; }return;}/****************************************************************************NAME: viewtable_nextPURPOSE: Find the appropriate entry in the acl table and attach information from it to the vbp using the getproc_got_* functions. If we can't find an entry indicate that by calling nextproc_no_next.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 processed. VB_T * Variable being processed.RETURNS: void****************************************************************************/void viewtable_next(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){VIEWLEAF_T *view;VIEWINDEX_T *vindex;UINT_16_T indx = 0;OIDC_T *rlist;if (tcount > 0) { if (*tlist > VIEW_MAXINDEXL) { nextproc_no_next(pktp, vbp); return; } else indx = (UINT_16_T)(*tlist); }for(vindex = viewroot; vindex != 0; vindex = vindex->next) { if (vindex->index < indx) continue; for (view = vindex->lexilist; view != 0; view = view->lexinext) { if (vindex->index == indx) { if (tcount - 1 < view->subtree.num_components) { if (oidorder(tlist + 1, view->subtree.component_list, tcount - 1) == 1) continue; } else { if (oidorder(tlist + 1, view->subtree.component_list, view->subtree.num_components) != -1) continue; } } rlist = (OIDC_T *)SNMP_memory_alloc((view->subtree.num_components + 1) * sizeof(OIDC_T)); if (rlist == 0) { nextproc_error(pktp, vbp, GEN_ERR); return; } *rlist = (OIDC_T)vindex->index; MEMCPY(rlist + 1, view->subtree.component_list, (unsigned int) view->subtree.num_components * sizeof(OIDC_T)); nextproc_next_instance(pktp, vbp, view->subtree.num_components + 1, rlist); SNMP_memory_free(rlist); switch(last_match) { case LM_viewMask: getproc_got_string(pktp, vbp, SNMP_View_Get_MaskLen(view), SNMP_View_Get_Mask(view), 0, VT_STRING); break; case LM_viewType: getproc_got_int32(pktp, vbp, SNMP_View_Get_Type(view)); break; case LM_viewStorageType: getproc_got_int32(pktp, vbp, SNMP_View_Get_StorageType(view)); break; case LM_viewStatus: getproc_got_int32(pktp, vbp, SNMP_View_Get_Status(view)); break; } return; } }nextproc_no_next(pktp, vbp);return;}/****************************************************************************NAME: viewtable_setPURPOSE: Perform the set of the view, by the time we get here the viewleaf has been built and filled in by the test function. If the tree node points to the viewleaf then, this was a creation request and we already installed the leaf. We do need to reset the vb_priv and vb_free_priv pointers so we won't free the data later. Otherwise we need to install the new leaf and save a pointer to the old leaf in case an undo is required.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 processed. VB_T * Variable being processed.RETURNS: void****************************************************************************/void viewtable_set(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){VIEWLEAF_T *oldview, *newview, tview;oldview = SNMP_View_Lookup((UINT_16_T)tlist[0], tlist + 1, tcount - 1);if ((last_match == LM_viewStatus) && (vbp->value_u.v_number == RS_DESTROY)) { if (oldview) { if (SNMP_View_Deinstall((UINT_16_T)tlist[0], tlist + 1, tcount - 1)) { setproc_error(pktp, vbp, COMMIT_FAILED); return; } else { vbp->vb_priv = (PTR_T)oldview; vbp->vb_free_priv = viewtable_set_cleanup; undoproc_set(pktp, vbp, viewtable_undo); } } else /* no undo proc required */ undoproc_good(pktp, vbp); setproc_good(pktp, vbp); return; }if (oldview == 0) { setproc_error(pktp, vbp, COMMIT_FAILED); undoproc_good(pktp, vbp); return; }newview = (VIEWLEAF_T *)vbp->vb_priv;if (SNMP_View_Get_Status(newview) == RS_CAGO) SNMP_View_Set_Status(newview, RS_ACTIVE);/* If the two views are equal then we are creating the view. We call the create hook and reset the priv info. Otherwise this is an update and we swap the info from the newview (from the vb_priv field) with that from the oldview. We need to keep the old info around in case we need to undo the set. The newview storage space will be freed by vb_free_priv */if (oldview == newview) { SNMP_VIEW_CREATE_HOOK(newview); vbp->vb_priv = 0; }else { SNMP_VIEW_UPDATE_HOOK(oldview, newview); /* copy the old stuff to a temp block */ tview.type = oldview->type; tview.storage = oldview->storage; tview.status = oldview->status; MEMCPY(&tview.mask, &oldview->mask, sizeof(EBUFFER_T)); /* copy the new stuff to the old block */ oldview->type = newview->type; oldview->storage = newview->storage; oldview->status = newview->status; MEMCPY(&oldview->mask, &newview->mask, sizeof(EBUFFER_T)); /* copy the stuff in the temp block (the old info) to the new block */ newview->type = tview.type; newview->storage = tview.storage; newview->status = tview.status; MEMCPY(&newview->mask, &tview.mask, sizeof(EBUFFER_T)); }/* use the correct cleanup routine. */vbp->vb_free_priv = viewtable_set_cleanup;undoproc_set(pktp, vbp, viewtable_undo);setproc_good(pktp, vbp);return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -