failure to set a MIB entry
gary clark <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
Using net-snmp.5.1.3 on Windows.
I attempt to set a MIB entry on a table. I used the mib2c to build the template
generated code.
I keep on getting a segmentation fault within the MODE_SET_ACTION:
The following statement is returning NULL?
table_entry = (struct secureTable_entry *)netsnmp_extract_iterator_contex(request);
Any ideas why this would return a NULL value?
Thanks,
Garyc
I have attached the file?
*
* Note: this file originally auto-generated by mib2c using
* : mib2c.iterate.conf,v 5.17 2005/05/09 08:13:45 dts12 Exp $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "secureAxis.h"
struct secureTable_entry *
secureTable_createEntry(
long usbDeviceIndex,
long usbVendorId,
long usbProductId,
long usbRevisionId,
long usbClassId,
long usbSubClassId,
char * usbProductName,
char * usbDeviceDescription,
char * usbSerialNumber,
long usbDeviceConnectedState,
long usbAuthorizationState
);
/** Initializes the secureAxis module */
#include <stdio.h>
/* Typical data structure for a row entry */
struct secureTable_entry {
/* Index values */
long usbDeviceIndex;
/* Column values */
long usbVendorId;
long old_usbVendorId;
long usbProductId;
long old_usbProductId;
long usbRevisionId;
long old_usbRevisionId;
long usbClassId;
long old_usbClassId;
long usbSubClassId;
long old_usbSubClassId;
char usbProductName[256];
char old_usbProductName[256];
char usbDeviceDescription[256];
char old_usbDeviceDescription[256];
char usbSerialNumber[256];
char old_usbSerialNumber[256];
long usbDeviceConnectedState;
long old_usbDeviceConnectedState;
long usbAuthorizationState;
long old_usbAuthorizationState;
/* Illustrate using a simple linked list */
int valid;
struct secureTable_entry *next;
};
struct secureTable_entry *secureTable_head;
FILE * fpDebug;
void
init_secureAxis(void)
{
/* here we initialize all the tables we're planning on supporting */
fpDebug=fopen("secureAxisDebug.txt","w+");
fprintf(fpDebug,"Enter init_secureAxis 2\n");
fflush(fpDebug);
secureTable_head=NULL;
initialize_table_secureTable();
}
/** Initialize the secureTable table by defining its contents and how it's structured */
void
initialize_table_secureTable(void)
{
int rows;
struct secureTable_entry * prevPtr=NULL;
struct secureTable_entry * tmpPtr=NULL;
static oid secureTable_oid[] = {1,3,6,1,3,20,2,1};
size_t secureTable_oid_len = OID_LENGTH(secureTable_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;
fprintf(fpDebug,"Enter initialize_table_secureTable\n");
fflush(fpDebug);
reg = netsnmp_create_handler_registration(
"secureTable", secureTable_handler,
secureTable_oid, secureTable_oid_len,
HANDLER_CAN_RWRITE
);
for (rows=0;rows<10;rows++)
{
struct secureTable_entry * entry;
entry=secureTable_createEntry(rows,0,0,0,0,0,"","","",0,0);
if (secureTable_head==NULL)
{
secureTable_head=entry;
entry->next=NULL;
fprintf(fpDebug,"HeadPtr is 0x%0x!!\n",secureTable_head);
fflush(fpDebug);
}
else
{
/* Cycle through the list of secureTable objects */
tmpPtr=secureTable_head;
while(tmpPtr!=NULL)
{
prevPtr=tmpPtr;
tmpPtr=tmpPtr->next;
}
prevPtr->next=entry;
entry->next=NULL;
fprintf(fpDebug,"PrevPtr is 0x%0x!!\n",entry);
fflush(fpDebug);
}
entry->valid = 1;
}
table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
netsnmp_table_helper_add_indexes(table_info,
ASN_INTEGER, /* index: usbDeviceIndex */
0);
table_info->min_column = 2;
table_info->max_column = 11;
iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
iinfo->get_first_data_point = secureTable_get_first_data_point;
iinfo->get_next_data_point = secureTable_get_next_data_point;
iinfo->table_reginfo = table_info;
netsnmp_register_table_iterator( reg, iinfo );
fprintf(fpDebug,"Exit initialize_table_secureTable\n");
fflush(fpDebug);
}
/* create a new row in the (unsorted) table */
struct secureTable_entry *
secureTable_createEntry(
long usbDeviceIndex,
long usbVendorId,
long usbProductId,
long usbRevisionId,
long usbClassId,
long usbSubClassId,
char * usbProductName,
char * usbDeviceDescription,
char * usbSerialNumber,
long usbDeviceConnectedState,
long usbAuthorizationState
)
{
struct secureTable_entry *entry;
entry = SNMP_MALLOC_TYPEDEF(struct secureTable_entry);
if (!entry){
fprintf(fpDebug,"Enter secureTable_createEntry::No memory\n");
fflush(fpDebug);
return NULL;
}
entry->usbDeviceIndex = usbDeviceIndex;
entry->usbVendorId=usbVendorId;
entry->usbProductId=usbProductId;
entry->usbProductId=usbRevisionId;
entry->usbClassId=usbClassId;
entry->usbSubClassId=usbSubClassId;
strcpy(entry->usbProductName,usbProductName);
strcpy(entry->usbDeviceDescription,usbDeviceDescription);
strcpy(entry->usbSerialNumber,usbSerialNumber);
entry->usbDeviceConnectedState=usbDeviceConnectedState;
entry->usbAuthorizationState=usbAuthorizationState;
fprintf(fpDebug,"Enter secureTable_createEntry::entry Created:0x%0x\n",entry);
fflush(fpDebug);
return entry;
}
/* remove a row from the table */
void
secureTable_removeEntry( struct secureTable_entry *entry ) {
struct secureTable_entry *ptr, *prev;
if (!entry)
return; /* Nothing to remove */
for ( ptr = secureTable_head, prev = NULL;
ptr != NULL;
prev = ptr, ptr = ptr->next ) {
if ( ptr == entry )
break;
}
if ( !ptr )
return; /* Can't find it */
if ( prev == NULL )
secureTable_head = ptr->next;
else
prev->next = ptr->next;
SNMP_FREE( entry ); /* XXX - release any other internal resources */
}
/* Example iterator hook routines - using 'get_next' to do most of the work */
netsnmp_variable_list *
secureTable_get_first_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list *put_index_data,
netsnmp_iterator_info *mydata)
{
*my_loop_context = secureTable_head;
return secureTable_get_next_data_point(my_loop_context, my_data_context,
put_index_data, mydata );
}
netsnmp_variable_list *
secureTable_get_next_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list *put_index_data,
netsnmp_iterator_info *mydata)
{
struct secureTable_entry *entry = (struct secureTable_entry *)*my_loop_context;
netsnmp_variable_list *idx = put_index_data;
fprintf(fpDebug,"Enter secureTable_get_next_data\n");
fflush(fpDebug);
if ( entry ) {
fprintf(fpDebug,"Exit secureTable_get_next_data:entry->usbDeviceIndex:%d\n",entry->usbDeviceIndex);
fflush(fpDebug);
// Changed the entry->usbDeviceIndex to be a reference it was
// crashing snmp_client
//
snmp_set_var_value( idx, (unsigned char *)&entry->usbDeviceIndex, sizeof(entry->usbDeviceIndex) );
fprintf(fpDebug,"Enter secureTable_get_next_data was called!!\n");
fflush(fpDebug);
idx = idx->next_variable;
*my_data_context = (void *)entry;
*my_loop_context = (void *)entry->next;
} else {
return NULL;
}
fprintf(fpDebug,"Exit secureTable_get_next_data\n");
fflush(fpDebug);
return NULL;
}
/** handles requests for the secureTable table */
int
secureTable_handler(
netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
struct secureTable_entry *table_entry;
switch (reqinfo->mode) {
/*
* Read-support (also covers GetNext requests)
*/
case MODE_GET:
for (request=requests; request; request=request->next) {
table_entry = (struct secureTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info( request);
switch (table_info->colnum) {
case COLUMN_USBVENDORID:
snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
table_entry->usbVendorId,
sizeof(table_entry->usbVendorId));
break;
case COLUMN_USBPRODUCTID:
snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
table_entry->usbProductId,
sizeof(table_entry->usbProductId));
break;
case COLUMN_USBREVISIONID:
snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
table_entry->usbRevisionId,
sizeof(table_entry->usbRevisionId));
break;
case COLUMN_USBCLASSID:
snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
table_entry->usbClassId,
sizeof(table_entry->usbClassId));
break;
case COLUMN_USBSUBCLASSID:
snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
table_entry->usbSubClassId,
sizeof(table_entry->usbSubClassId));
break;
case COLUMN_USBPRODUCTNAME:
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
table_entry->usbProductName,
sizeof(table_entry->usbProductName));
break;
case COLUMN_USBDEVICEDESCRIPTION:
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
table_entry->usbDeviceDescription,
sizeof(table_entry->usbDeviceDescription));
break;
case COLUMN_USBSERIALNUMBER:
snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
table_entry->usbSerialNumber,
sizeof(table_entry->usbSerialNumber));
break;
case COLUMN_USBDEVICECONNECTEDSTATE:
snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
table_entry->usbDeviceConnectedState,
sizeof(table_entry->usbDeviceConnectedState));
break;
case COLUMN_USBAUTHORIZATIONSTATE:
snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
table_entry->usbAuthorizationState,
sizeof(table_entry->usbAuthorizationState));
break;
}
}
break;
/*
* Write-support
*/
case MODE_SET_RESERVE1:
fprintf(fpDebug,"Enter SET_RESERVE1\n");
fflush(fpDebug);
for (request=requests; request; request=request->next) {
table_entry = (struct secureTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info( request);
switch (table_info->colnum) {
case COLUMN_USBVENDORID:
if ( request->requestvb->type != ASN_INTEGER ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
case COLUMN_USBPRODUCTID:
if ( request->requestvb->type != ASN_INTEGER ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
case COLUMN_USBREVISIONID:
if ( request->requestvb->type != ASN_INTEGER ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
case COLUMN_USBCLASSID:
if ( request->requestvb->type != ASN_INTEGER ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
case COLUMN_USBSUBCLASSID:
if ( request->requestvb->type != ASN_INTEGER ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
case COLUMN_USBPRODUCTNAME:
if ( request->requestvb->type != ASN_OCTET_STR ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
case COLUMN_USBDEVICEDESCRIPTION:
if ( request->requestvb->type != ASN_OCTET_STR ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
case COLUMN_USBSERIALNUMBER:
if ( request->requestvb->type != ASN_OCTET_STR ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
case COLUMN_USBDEVICECONNECTEDSTATE:
if ( request->requestvb->type != ASN_INTEGER ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
case COLUMN_USBAUTHORIZATIONSTATE:
if ( request->requestvb->type != ASN_INTEGER ) {
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_WRONGTYPE );
return SNMP_ERR_NOERROR;
}
/* Also may need to check size/value */
break;
default:
netsnmp_set_request_error( reqinfo, request,
SNMP_ERR_NOTWRITABLE );
return SNMP_ERR_NOERROR;
}
}
fprintf(fpDebug,"Exit SET_RESERVE1\n");
fflush(fpDebug);
break;
case MODE_SET_RESERVE2:
break;
case MODE_SET_FREE:
break;
case MODE_SET_ACTION:
fprintf(fpDebug,"Enter SET_ACTION::MODE_SET_ACTION:\n");
fflush(fpDebug);
for (request=requests; request; request=request->next) {
table_entry = (struct secureTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info( request);
fprintf(fpDebug,"Enter SET_ACTION::table_entry:0x%0x\n",table_entry);
fflush(fpDebug);
switch (table_info->colnum) {
case COLUMN_USBVENDORID:
/* Need to save old 'table_entry->usbVendorId' value.
May need to use 'memcpy' */
fprintf(fpDebug,"Enter SET_ACTION::COLUMN_USBVENDORID\n");
fflush(fpDebug);
table_entry->old_usbVendorId = table_entry->usbVendorId;
fprintf(fpDebug,"Enter SET_ACTION::old_table_entry::usbVendorId:%d\n",table_entry->usbVendorId);
fflush(fpDebug);
fprintf(fpDebug,"Enter SET_ACTION::table_entry::new usbVendorId:%d\n",request->requestvb->val.integer);
fflush(fpDebug);
table_entry->usbVendorId = request->requestvb->val.integer;
break;
case COLUMN_USBPRODUCTID:
/* Need to save old 'table_entry->usbProductId' value.
May need to use 'memcpy' */
table_entry->old_usbProductId = table_entry->usbProductId;
table_entry->usbProductId = request->requestvb->val.integer;
break;
case COLUMN_USBREVISIONID:
/* Need to save old 'table_entry->usbRevisionId' value.
May need to use 'memcpy' */
table_entry->old_usbRevisionId = table_entry->usbRevisionId;
table_entry->usbRevisionId = request->requestvb->val.integer;
break;
case COLUMN_USBCLASSID:
/* Need to save old 'table_entry->usbClassId' value.
May need to use 'memcpy' */
table_entry->old_usbClassId = table_entry->usbClassId;
table_entry->usbClassId = request->requestvb->val.integer;
break;
case COLUMN_USBSUBCLASSID:
/* Need to save old 'table_entry->usbSubClassId' value.
May need to use 'memcpy' */
table_entry->old_usbSubClassId = table_entry->usbSubClassId;
table_entry->usbSubClassId = request->requestvb->val.integer;
break;
case COLUMN_USBPRODUCTNAME:
/* Need to save old 'table_entry->usbProductName' value.
May need to use 'memcpy' */
memcpy(table_entry->old_usbProductName,table_entry->usbProductName,sizeof(table_entry->usbProductName));
memcpy(table_entry->usbProductName,request->requestvb->val.string,sizeof(request->requestvb->val.string));
break;
case COLUMN_USBDEVICEDESCRIPTION:
/* Need to save old 'table_entry->usbDeviceDescription' value.
May need to use 'memcpy' */
memcpy(table_entry->old_usbDeviceDescription,table_entry->usbDeviceDescription,sizeof(table_entry->usbDeviceDescription));
memcpy(table_entry->usbDeviceDescription,request->requestvb->val.string,sizeof(request->requestvb->val.string));
break;
case COLUMN_USBSERIALNUMBER:
/* Need to save old 'table_entry->usbSerialNumber' value.
May need to use 'memcpy' */
memcpy(table_entry->old_usbSerialNumber,table_entry->usbSerialNumber,sizeof(table_entry->usbSerialNumber));
memcpy(table_entry->usbSerialNumber,request->requestvb->val.string,sizeof(request->requestvb->val.string));
break;
case COLUMN_USBDEVICECONNECTEDSTATE:
/* Need to save old 'table_entry->usbDeviceConnectedState' value.
May need to use 'memcpy' */
table_entry->old_usbDeviceConnectedState = table_entry->usbDeviceConnectedState;
table_entry->usbDeviceConnectedState = request->requestvb->val.integer;
break;
case COLUMN_USBAUTHORIZATIONSTATE:
/* Need to save old 'table_entry->usbAuthorizationState' value.
May need to use 'memcpy' */
table_entry->old_usbAuthorizationState = table_entry->usbAuthorizationState;
table_entry->usbAuthorizationState = request->requestvb->val.integer;
break;
}
}
break;
case MODE_SET_UNDO:
fprintf(fpDebug,"Enter MODE_SET_UNDO\n");
fflush(fpDebug);
for (request=requests; request; request=request->next) {
table_entry = (struct secureTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info( request);
switch (table_info->colnum) {
case COLUMN_USBVENDORID:
/* Need to restore old 'table_entry->usbVendorId' value.
May need to use 'memcpy' */
table_entry->usbVendorId = table_entry->old_usbVendorId;
break;
case COLUMN_USBPRODUCTID:
/* Need to restore old 'table_entry->usbProductId' value.
May need to use 'memcpy' */
table_entry->usbProductId = table_entry->old_usbProductId;
break;
case COLUMN_USBREVISIONID:
/* Need to restore old 'table_entry->usbRevisionId' value.
May need to use 'memcpy' */
table_entry->usbRevisionId = table_entry->old_usbRevisionId;
break;
case COLUMN_USBCLASSID:
/* Need to restore old 'table_entry->usbClassId' value.
May need to use 'memcpy' */
table_entry->usbClassId = table_entry->old_usbClassId;
break;
case COLUMN_USBSUBCLASSID:
/* Need to restore old 'table_entry->usbSubClassId' value.
May need to use 'memcpy' */
table_entry->usbSubClassId = table_entry->old_usbSubClassId;
break;
case COLUMN_USBPRODUCTNAME:
/* Need to restore old 'table_entry->usbProductName' value.
May need to use 'memcpy' */
strcpy(table_entry->usbProductName,table_entry->old_usbProductName);
break;
case COLUMN_USBDEVICEDESCRIPTION:
/* Need to restore old 'table_entry->usbDeviceDescription' value.
May need to use 'memcpy' */
strcpy(table_entry->usbDeviceDescription,table_entry->old_usbDeviceDescription);
break;
case COLUMN_USBSERIALNUMBER:
/* Need to restore old 'table_entry->usbSerialNumber' value.
May need to use 'memcpy' */
strcpy(table_entry->usbSerialNumber,table_entry->old_usbSerialNumber);
break;
case COLUMN_USBDEVICECONNECTEDSTATE:
/* Need to restore old 'table_entry->usbDeviceConnectedState' value.
May need to use 'memcpy' */
table_entry->usbDeviceConnectedState = table_entry->old_usbDeviceConnectedState;
break;
case COLUMN_USBAUTHORIZATIONSTATE:
/* Need to restore old 'table_entry->usbAuthorizationState' value.
May need to use 'memcpy' */
table_entry->usbAuthorizationState = table_entry->old_usbAuthorizationState;
break;
}
}
fprintf(fpDebug,"Exit MODE_SET_UNDO\n");
fflush(fpDebug);
break;
case MODE_SET_COMMIT:
fprintf(fpDebug,"Enter MODE_SET_COMMIT\n");
fflush(fpDebug);
break;
}
return SNMP_ERR_NOERROR;
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users