📄 v3mt_com.c
字号:
/* * Copyright 2000-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//* * Copyright 1999 Integrated Systems, Inc. * All rights reserved. *//* * $Log: v3mt_com.c,v $ * Revision 1.4 2002/11/22 16:14:12 josh * snmpCommunityEntry_test() had a memory leak because * SNMP_Community_Set_Defaults() allocates memory unnecessarily * * Revision 1.3 2002/03/11 19:21:23 josh * index is a bad name for a local variable -- use comm_index instead * * Revision 1.2 2001/11/06 21:20:33 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:40 tneale * Tornado shuffle * * Revision 1.1.2.4 2001/09/28 20:49:05 josh * method routines will now allow rows to be created as permanent or * read-only rows. It will also prevent the deletion of such rows. * * Revision 1.1.2.3 2001/09/21 18:43:19 josh * fixing a typo in one of the method routines * * Revision 1.1.2.2 2001/08/24 14:09:07 josh * use the envoy_err_t error codes where appropriate * * Revision 1.1.2.1 2001/07/16 18:02:11 josh * a first-round commit adding infrastructure support * for the SNMPv3 Coexistence RFC (2576) * * *//* [clearcase]modification history-------------------01b,18apr05,job update copyright notices01a,24nov03,job update copyright information*/#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/mib.h>#include <wrn/wm/snmp/engine/localio.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/v3_eng.h>#include <wrn/wm/snmp/engine/v3_comm.h>#include <wrn/wm/snmp/engine/ntfy_chk.h>/* default values for the macros to map the method routines to the target_addrs non volatile storage */#if !defined(SNMP_V3_COMM_DESTROY_BACKOUT)#define SNMP_V3_COMM_DESTROY_BACKOUT(CUR, NEW)#endif#if !defined(SNMP_V3_COMM_CREATE_BACKOUT)#define SNMP_V3_COMM_CREATE_BACKOUT(CUR, NEW)#endif#if !defined(SNMP_V3_COMM_UPDATE_BACKOUT)#define SNMP_V3_COMM_UPDATE_BACKOUT(CUR, NEW)#endif#if !defined(SNMP_V3_COMM_FINISHED)#define SNMP_V3_COMM_FINISHED()#endif#if !defined(SNMP_V3_COMM_DESTROY_TEST)#define SNMP_V3_COMM_DESTROY_TEST(PKT, VBP, CUR, NEW) NO_ERROR#endif#if !defined(SNMP_V3_COMM_CREATE_TEST)#define SNMP_V3_COMM_CREATE_TEST(PKT, VBP, CUR, NEW) NO_ERROR#endif#if !defined(SNMP_V3_COMM_UPDATE_TEST)#define SNMP_V3_COMM_UPDATE_TEST(PKT, VBP, CUR, NEW) NO_ERROR#endif#if !defined(SNMP_V3_COMM_DESTROY_SET)#define SNMP_V3_COMM_DESTROY_SET(PKT, VBP, CUR, NEW)#endif#if !defined(SNMP_V3_COMM_CREATE_SET)#define SNMP_V3_COMM_CREATE_SET(PKT, VBP, CUR, NEW)#endif#if !defined(SNMP_V3_COMM_UPDATE_SET)#define SNMP_V3_COMM_UPDATE_SET(PKT, VBP, CUR, NEW)#endif/* these aren't defined by default *//*#define SNMP_V3_COMM_DESTROY_UNDO(PKT, VBP, CUR, SAV)#define SNMP_V3_COMM_CREATE_UNDO(PKT, VBP, CUR, SAV)#define SNMP_V3_COMM_UPDATE_UNDO(PKT, VBP, CUR, SAV)*//* * Method routines for the snmpCommunityTable: * * snmpCommunityIndex -- not-accessible * The unique index value of a row in this table. * * snmpCommunityName -- read-create * The community string for which a row in this table * represents a configuration. * * snmpCommunitySecurityName -- read-create * A human readable string representing the corresponding * value of snmpCommunityName in a Security Model * independent format. * * snmpCommunityContextEngineID -- read-create * The contextEngineID indicating the location of the * context in which management information is accessed * when using the community string specified by the * corresponding instance of snmpCommunityName. * * The default value is the snmpEngineID of the entity in * which this object is instantiated. * * snmpCommunityContextName -- read-create * The context in which management information is accessed * when using the community string specified by the corresponding * instance of snmpCommunityName. * * snmpCommunityTransportTag -- read-create * This object specifies a set of transport endpoints * from which a command responder application will accept * management requests. If a management request containing * this community is received on a transport endpoint other * than the transport endpoints identified by this object, * the request is deemed unauthentic. * * The transports identified by this object are specified * in the snmpTargetAddrTable. Entries in that table * whose snmpTargetAddrTagList contains this tag value * are identified. * * If the value of this object has zero-length, transport * endpoints are not checked when authenticating messages * containing this community string. * * snmpCommunityStorageType -- read-create * The storage type for this conceptual row in the * snmpCommunityTable. Conceptual rows having the value * 'permanent' need not allow write-access to any * columnar object in the row. * * snmpCommunityStatus -- read-create * The status of this conceptual row in the snmpCommunityTable. * * An entry in this table is not qualified for activation * until instances of all corresponding columns have been * initialized, either through default values, or through * Set operations. The snmpCommunityName and * snmpCommunitySecurityName objects must be explicitly set. * * There is no restriction on setting columns in this table * when the value of snmpCommunityStatus is active(1). *//* An internal routine to retrieve the values of the variables, used * by the method routines snmpCommunityEntry_get and * snmpCommunityEntry_next. */static int snmpCommunityEntry_get_value(OIDC_T lastmatch, SNMP_PKT_T *pktp, VB_T *vbp, SNMP_COMMUNITY_T *community){switch(lastmatch) { case LEAF_snmpCommunityName: getproc_got_string(pktp, vbp, SNMP_Community_Get_Name_Len(community), SNMP_Community_Get_Name(community), 0, VT_STRING); break; case LEAF_snmpCommunitySecurityName: getproc_got_string(pktp, vbp, SNMP_Community_Get_Sec_Name_Len(community), SNMP_Community_Get_Sec_Name(community), 0, VT_STRING); break; case LEAF_snmpCommunityContextEngineID: getproc_got_string(pktp, vbp, SNMP_Community_Get_Con_ID_Len(community), SNMP_Community_Get_Con_ID(community), 0, VT_STRING); break; case LEAF_snmpCommunityContextName: getproc_got_string(pktp, vbp, SNMP_Community_Get_Con_Name_Len(community), SNMP_Community_Get_Con_Name(community), 0, VT_STRING); break; case LEAF_snmpCommunityTransportTag: getproc_got_string(pktp, vbp, SNMP_Community_Get_Tag_Len(community), SNMP_Community_Get_Tag(community), 0, VT_STRING); break; case LEAF_snmpCommunityStorageType: /* Values: * other(1) = VAL_snmpCommunityStorageType_other * volatile(2) = VAL_snmpCommunityStorageType_volatile * nonVolatile(3) = VAL_snmpCommunityStorageType_nonVolatile * permanent(4) = VAL_snmpCommunityStorageType_permanent * readOnly(5) = VAL_snmpCommunityStorageType_readOnly */ getproc_got_int32(pktp, vbp, SNMP_Community_Get_Storage(community)); break; case LEAF_snmpCommunityStatus: /* Values: * active(1) = VAL_snmpCommunityStatus_active * notInService(2) = VAL_snmpCommunityStatus_notInService * notReady(3) = VAL_snmpCommunityStatus_notReady * createAndGo(4) = VAL_snmpCommunityStatus_createAndGo * createAndWait(5) = VAL_snmpCommunityStatus_createAndWait * destroy(6) = VAL_snmpCommunityStatus_destroy */ getproc_got_int32(pktp, vbp, SNMP_Community_Get_Status(community)); break; default: return GEN_ERR; }return NO_ERROR;}void snmpCommunityEntry_get(OIDC_T lastmatch, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_COMMUNITY_T *community = 0;bits8_t name[ETC_COMMUNITY_MAX];ALENGTH_T name_len = ETC_COMMUNITY_MAX;int error;/* find all the varbinds that share the same getproc and instance */group_by_getproc_and_instance(pktp, vbp, tcount, tlist);/* use the instance (tcount and tlist) to look up the entry in the * table. */if ((oid_to_string(tcount, tlist, &name_len, name, 1) == 0) && (name_len != 0)) community = SNMP_Community_Lookup(name, name_len);if (community == 0) { for ( ; vbp ; vbp = vbp->vb_link) getproc_nosuchins(pktp, vbp); }else { /* retrieve all the values from the same data structure */ for ( ; vbp; vbp = vbp->vb_link) { if ((error = snmpCommunityEntry_get_value(vbp->vb_ml.ml_last_match, pktp, vbp, community)) != NO_ERROR) getproc_error(pktp, vbp, error); } }}void snmpCommunityEntry_next(OIDC_T lastmatch, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_COMMUNITY_T *community;OIDC_T best_inst[ETC_COMMUNITY_MAX];int error;/* find all the varbinds that share the same getproc and instance */group_by_getproc_and_instance(pktp, vbp, tcount, tlist);community = SNMP_Community_Next(tcount, tlist);if ((community) && ((error = string_to_oid(SNMP_Community_Get_Index_Len(community), SNMP_Community_Get_Index(community), ETC_COMMUNITY_MAX, best_inst, 1)) == 0)) { for ( ; vbp ; vbp = vbp->vb_link ) { if ((error = snmpCommunityEntry_get_value(vbp->vb_ml.ml_last_match, pktp, vbp, community)) == NO_ERROR) nextproc_next_instance(pktp, vbp, SNMP_Community_Get_Index_Len(community), best_inst); else nextproc_error(pktp, vbp, error); } }else /* there's no more in this table */ for ( ; vbp ; vbp = vbp->vb_link ) nextproc_no_next(pktp, vbp);}/****************************************************************************NAME: commtable_destroy_cleanupPURPOSE: Cleanup after a community 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 community object that we were going to delete, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void commtable_destroy_cleanup(ptr_t commptr){SNMP_V3_COMM_DESTROY_BACKOUT(((VB_T *)commptr)->vb_priv, 0);}/****************************************************************************NAME: commtable_create_cleanupPURPOSE: Cleanup after a community 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 community object that we were going to create, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void commtable_create_cleanup(ptr_t commptr){SNMP_COMMUNITY_T *community;community = (SNMP_COMMUNITY_T *)(((VB_T *)commptr)->vb_priv);SNMP_V3_COMM_CREATE_BACKOUT(0, community);SNMP_Community_Deinstall(community);SNMP_Community_Destroy(community);}/****************************************************************************NAME: commtable_update_cleanupPURPOSE: Cleanup after a community 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 community object that contained the update information, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void commtable_update_cleanup(ptr_t commptr){SNMP_COMMUNITY_T *community;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -