📄 v3mt_acc.c
字号:
/* The values are ok */if (SNMP_Group_Get_Status(&tempgrp) == ETC_RS_DESTROY) { if (grp != 0) { ptret = SNMP_V3_GROUP_DESTROY_TEST(pktp, vbp, grp, 0); if (ptret != NO_ERROR) { testproc_error(pktp, vbp, ptret); } else { vbp->vb_priv = (PTR_T)grp; vbp->vb_free_priv = grouptable_destroy_cleanup; } } else { /* We have a destroy request, but no group so we don't have to do anything during the set and, if necessary, the undo phases so we mark vbp as set and undone */ setproc_all_bits(pktp, vbp); } return; }/* check on status */if ((rs_vbp) && (rs_vbp->value_u.v_number != ETC_RS_CAWAIT)) { if (((cago) || ((grp) && (SNMP_Group_Get_Status(grp) == ETC_RS_NREADY))) && (!vg_vbp)) { testproc_error(pktp, rs_vbp, INCONSISTENT_VALUE); return; } }else { if ((SNMP_Group_Get_Status(&tempgrp) == ETC_RS_NREADY) && (vg_vbp)) SNMP_Group_Set_Status(&tempgrp, ETC_RS_NIS); }/* 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 group as having changed so it will get copied. */if (grp) { if ((SNMP_Group_Get_Group(grp) == SNMP_Group_Get_Group(&tempgrp)) || ((SNMP_Group_Get_Group_Len(grp) == SNMP_Group_Get_Group_Len(&tempgrp)) && (MEMCMP_NULLOK(SNMP_Group_Get_Group(grp), SNMP_Group_Get_Group(&tempgrp), SNMP_Group_Get_Group_Len(grp)) == 0))) { if ((grp->storage == tempgrp.storage) && (grp->status == tempgrp.status)) { setproc_all_bits(pktp, vbp); return; } } else grp_changed = 1; }else { grp_changed = 1; }/* Because of how we do the backout stuff we always allocate a new group and set it up */newgrp = SNMP_Group_Create();if (newgrp == 0) { testproc_error(pktp, vbp, RESOURCE_UNAVAILABLE); return; }newgrp->storage = tempgrp.storage;newgrp->status = tempgrp.status;/* if the grp name changed then we need to make our own copy of the new name. If it didn't change then we use the current one but need to make sure that we don't free it and don't swap them in the set phase */if (grp_changed) { if (EBufferClone(&tempgrp.grp_name, &newgrp->grp_name) != 0) { SNMP_Group_Destroy(newgrp); testproc_error(pktp, vbp, RESOURCE_UNAVAILABLE); return; } }else { EBufferPreLoad(BFL_IS_STATIC, &newgrp->grp_name, SNMP_Group_Get_Group(grp), SNMP_Group_Get_Group_Len(grp)); } /* if we are creating a new group we need to install it and run the create test, if we are updating an old group we just run the update test */if (grp == 0) { if (SNMP_Group_Install(newgrp, (sbits32_t)tlist[0], name, namelen)) { SNMP_Group_Destroy(newgrp); testproc_error(pktp, vbp, RESOURCE_UNAVAILABLE); return; } ptret = SNMP_V3_GROUP_CREATE_TEST(pktp, vbp, 0, newgrp); if (ptret != NO_ERROR) { SNMP_Group_Deinstall(newgrp); SNMP_Group_Destroy(newgrp); testproc_error(pktp, vbp, ptret); return; } vbp->vb_free_priv = grouptable_create_cleanup; }else { ptret = SNMP_V3_GROUP_UPDATE_TEST(pktp, vbp, grp, newgrp); if (ptret != NO_ERROR) { SNMP_Group_Destroy(newgrp); testproc_error(pktp, vbp, ptret); return; } newgrp->next = grp; vbp->vb_free_priv = grouptable_update_cleanup; }if (cago) SNMP_Group_Set_Status(newgrp, ETC_RS_CAGO);vbp->vb_priv = (PTR_T)newgrp;return;}/****************************************************************************NAME: grouptable_setPURPOSE: Perform the set of the group, by the time we get here the group struct has been built and filled in by the test function. For a destroy we remove the group from the list, but we don't destroy it yet, we keep it around in case we need to undo it. For a create we don't do much, we only need to call the create hook macro and set vb_priv to 0 so we don't destroy the group when we run the cleanup routine. For an update we need to copy the info from the new to the old one as well as saving the old info in case of 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 grouptable_set(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_GROUP_T *oldgroup, *newgroup;bits16_t temp_value;EBUFFER_T temp_ebuf;newgroup = (SNMP_GROUP_T *)vbp->vb_priv;if (vbp->vb_free_priv == grouptable_destroy_cleanup) { SNMP_V3_GROUP_DESTROY_SET(pktp, vbp, newgroup, 0); SNMP_Group_Deinstall(newgroup); vbp->vb_free_priv = grouptable_set_cleanup; undoproc_set(pktp, vbp, grouptable_destroy_undo); }else if (vbp->vb_free_priv == grouptable_create_cleanup) { if (SNMP_Group_Get_Status(newgroup) == ETC_RS_CAGO) SNMP_Group_Set_Status(newgroup, ETC_RS_ACTIVE); SNMP_V3_GROUP_CREATE_SET(pktp, vbp, 0, newgroup); undoproc_set(pktp, vbp, grouptable_create_undo); }else { oldgroup = newgroup->next; SNMP_V3_GROUP_UPDATE_SET(pktp, vbp, oldgroup, newgroup); /* deal with status & storage information */ temp_value = SNMP_Group_Get_Status(oldgroup); SNMP_Group_Set_Status(oldgroup, SNMP_Group_Get_Status(newgroup)); SNMP_Group_Set_Status(newgroup, temp_value); temp_value = SNMP_Group_Get_Storage(oldgroup); SNMP_Group_Set_Storage(oldgroup, SNMP_Group_Get_Storage(newgroup)); SNMP_Group_Set_Storage(newgroup, temp_value); /* deal with the group name info, if the two pointers are equal we don't need to do anything, otherwise we need to copy the buffer info around */ if (SNMP_Group_Get_Group(oldgroup) != SNMP_Group_Get_Group(newgroup)) { MEMCPY(&temp_ebuf, &oldgroup->grp_name, sizeof(EBUFFER_T)); MEMCPY(&oldgroup->grp_name, &newgroup->grp_name, sizeof(EBUFFER_T)); MEMCPY(&newgroup->grp_name, &temp_ebuf, sizeof(EBUFFER_T)); } undoproc_set(pktp, vbp, grouptable_update_undo); }vbp->vb_free_priv = grouptable_set_cleanup;setproc_good(pktp, vbp);return;}/* access table stuff */#define LM_accessContextMatch 4#define LM_accessRead 5#define LM_accessWrite 6#define LM_accessNotify 7#define LM_accessStorage 8#define LM_accessStatus 9/****************************************************************************NAME: get_access_dataPURPOSE: install data into a series of vbps. this routine will be called from accesstable_get and accesstable_next, they will have already found the proper access we just find the right field in that access and stuff it into the vbpPARAMETERS: SNMP_PKT_T * SNMP packet currently being processed. VB_T * Variable being processed. SNMP_ACCESS_T * the struct to extract inforamtion fromRETURNS: void****************************************************************************/static void get_access_data(SNMP_PKT_T *pktp, VB_T *vbp, SNMP_ACCESS_T *access){for(; vbp; vbp = vbp->vb_link) { switch(vbp->vb_ml.ml_last_match) { case LM_accessContextMatch: getproc_got_int32(pktp, vbp, SNMP_V3_Access_Get_Prefix_Match(access)); break; case LM_accessRead: getproc_got_string(pktp, vbp, SNMP_V3_Access_Get_Read_Len(access), SNMP_V3_Access_Get_Read(access), 0, VT_STRING); break; case LM_accessWrite: getproc_got_string(pktp, vbp, SNMP_V3_Access_Get_Write_Len(access), SNMP_V3_Access_Get_Write(access), 0, VT_STRING); break; case LM_accessNotify: getproc_got_string(pktp, vbp, SNMP_V3_Access_Get_Notify_Len(access), SNMP_V3_Access_Get_Notify(access), 0, VT_STRING); break; case LM_accessStorage: getproc_got_int32(pktp, vbp, SNMP_V3_Access_Get_Storage(access)); break; case LM_accessStatus: getproc_got_int32(pktp, vbp, SNMP_V3_Access_Get_Status(access)); break; } }return;}/****************************************************************************NAME: accesstable_getPURPOSE: Find the appropriate entry in the access 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 accesstable_get(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_ACCESS_T *access = 0;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;/* group the vbs that are touching the given entry */group_by_getproc_and_instance(pktp, vbp, tcount, tlist);/* 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) && (tlist[0] <= ETC_ACCESS_GROUP_MAX) && (oid_to_string(tcount, tlist, &grp_namelen, grp_name, 0) == 0) && ((bits32_t)(grp_namelen + 1) < (bits32_t)tcount) && (oid_to_string(tcount - ((int)(grp_namelen + 1)), tlist + grp_namelen + 1, &namelen, name, 0) == 0) && ((bits32_t)(grp_namelen + namelen + 4) == (bits32_t)tcount) && (namelen <= ETC_ACCESS_ACCESS_MAX) && (tlist[2 + grp_namelen + namelen] < 0x80000000L) && (tlist[3 + grp_namelen + namelen] > 0) && (tlist[3 + grp_namelen + namelen] < 4)) { 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]); }/* install the right info into the vbps */if (access == 0) for(; vbp; vbp = vbp->vb_link) getproc_nosuchins(pktp,vbp);else get_access_data(pktp, vbp, access);return;}/****************************************************************************NAME: accesstable_nextPURPOSE: Find the appropriate entry in the access 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_nextPARAMETERS: 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 accesstable_next(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_ACCESS_T *access = 0;bits8_t grp_name[ETC_ACCESS_GROUP_MAX], name[ETC_ACCESS_ACCESS_MAX];ALENGTH_T grp_namelen = 0, namelen = 0;sbits32_t model = 0, level = 0;OIDC_T *rlist;int rcount;/* group the vbs that are touching the given entry */group_by_getproc_and_instance(pktp, vbp, tcount, tlist);access = SNMP_V3_Access_Next(tcount, tlist);/* install the right info into the vbps */if (access == 0) for(; vbp; vbp = vbp->vb_link) nextproc_no_next(pktp,vbp);else { /* determine the instance information */ grp_namelen = ETC_ACCESS_GROUP_MAX; namelen = ETC_ACCESS_ACCESS_MAX; SNMP_V3_Access_Name(access, grp_name, &grp_namelen, name, &namelen, &model, &level); rcount = 4 + grp_namelen + namelen; rlist = SNMP_memory_alloc((unsigned int)(rcount * sizeof(OIDC_T))); if (rlist == 0) nextproc_error(pktp, vbp, GEN_ERR); else { /* insert the data */ get_access_data(pktp, vbp, access); /* then the instance info */ (void) string_to_oid(grp_namelen, grp_name, (int)(grp_namelen + 1), rlist, 0); (void) string_to_oid(namelen, name, (int)(namelen + 1), rlist + grp_namelen + 1, 0); rlist[grp_namelen + namelen + 2] = model; rlist[grp_namelen + namelen + 3] = level; for(; vbp; vbp = vbp->vb_link) nextproc_next_instance(pktp, vbp, rcount, rlist); SNMP_memory_free(rlist); } }return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -