|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* DisMan Event MIB:
|
|
Packit |
fcad23 |
* Implementation of the object table configure handling
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
#include <net-snmp/net-snmp-config.h>
|
|
Packit |
fcad23 |
#include <net-snmp/net-snmp-includes.h>
|
|
Packit |
fcad23 |
#include <net-snmp/agent/net-snmp-agent-includes.h>
|
|
Packit |
fcad23 |
#include <net-snmp/agent/agent_callbacks.h>
|
|
Packit |
fcad23 |
#include "disman/event/mteObjects.h"
|
|
Packit |
fcad23 |
#include "disman/event/mteObjectsConf.h"
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/** Initializes the mteObjectsConf module */
|
|
Packit |
fcad23 |
void
|
|
Packit |
fcad23 |
init_mteObjectsConf(void)
|
|
Packit |
fcad23 |
{
|
|
Packit |
fcad23 |
init_objects_table_data();
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* Register config handlers for current and previous style
|
|
Packit |
fcad23 |
* persistent configuration directives
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
snmpd_register_config_handler("_mteOTable",
|
|
Packit |
fcad23 |
parse_mteOTable, NULL, NULL);
|
|
Packit |
fcad23 |
snmpd_register_config_handler("mteObjectsTable",
|
|
Packit |
fcad23 |
parse_mteOTable, NULL, NULL);
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* Register to save (non-fixed) entries when the agent shuts down
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
|
|
Packit |
fcad23 |
store_mteOTable, NULL);
|
|
Packit |
fcad23 |
snmp_register_callback(SNMP_CALLBACK_APPLICATION,
|
|
Packit |
fcad23 |
SNMPD_CALLBACK_PRE_UPDATE_CONFIG,
|
|
Packit |
fcad23 |
clear_mteOTable, NULL);
|
|
Packit |
fcad23 |
}
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
void
|
|
Packit |
fcad23 |
parse_mteOTable(const char *token, char *line)
|
|
Packit |
fcad23 |
{
|
|
Packit |
fcad23 |
char owner[MTE_STR1_LEN+1];
|
|
Packit |
fcad23 |
char oname[MTE_STR1_LEN+1];
|
|
Packit |
fcad23 |
void *vp;
|
|
Packit |
fcad23 |
u_long index;
|
|
Packit |
fcad23 |
size_t tmpint;
|
|
Packit |
fcad23 |
size_t len;
|
|
Packit |
fcad23 |
netsnmp_tdata_row *row;
|
|
Packit |
fcad23 |
struct mteObject *entry;
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
DEBUGMSGTL(("disman:event:conf", "Parsing mteObjectTable config... "));
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* Read in the index information for this entry
|
|
Packit |
fcad23 |
* and create a (non-fixed) data structure for it.
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
memset( owner, 0, sizeof(owner));
|
|
Packit |
fcad23 |
memset( oname, 0, sizeof(oname));
|
|
Packit |
fcad23 |
len = MTE_STR1_LEN; vp = owner;
|
|
Packit |
fcad23 |
line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len;;
|
|
Packit |
fcad23 |
len = MTE_STR1_LEN; vp = oname;
|
|
Packit |
fcad23 |
line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len;;
|
|
Packit |
fcad23 |
line = read_config_read_data(ASN_UNSIGNED, line, &index, &len;;
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
DEBUGMSG(("disman:event:conf", "(%s, %s, %lu) ", owner, oname, index));
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
row = mteObjects_createEntry( owner, oname, index, 0 );
|
|
Packit |
fcad23 |
/* entry = (struct mteObject *)netsnmp_tdata_row_entry( row ); */
|
|
Packit |
fcad23 |
entry = (struct mteObject *)row->data;
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* Read in the accessible column values
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
entry->mteObjectID_len = MAX_OID_LEN;
|
|
Packit |
fcad23 |
vp = entry->mteObjectID;
|
|
Packit |
fcad23 |
line = read_config_read_data(ASN_OBJECT_ID, line, &vp,
|
|
Packit |
fcad23 |
&entry->mteObjectID_len);
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
if (!strcasecmp(token, "mteObjectsTable")) {
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* The previous Event-MIB implementation saved
|
|
Packit |
fcad23 |
* these fields as separate (integer) values
|
|
Packit |
fcad23 |
* Accept this (for backwards compatability)
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
line = read_config_read_data(ASN_UNSIGNED, line, &tmpint, &len;;
|
|
Packit |
fcad23 |
if (tmpint == TV_TRUE)
|
|
Packit |
fcad23 |
entry->flags |= MTE_OBJECT_FLAG_WILD;
|
|
Packit |
fcad23 |
line = read_config_read_data(ASN_UNSIGNED, line, &tmpint, &len;;
|
|
Packit |
fcad23 |
if (tmpint == RS_ACTIVE)
|
|
Packit |
fcad23 |
entry->flags |= MTE_OBJECT_FLAG_ACTIVE;
|
|
Packit |
fcad23 |
} else {
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* This implementation saves the (relevant) flag bits directly
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
line = read_config_read_data(ASN_UNSIGNED, line, &tmpint, &len;;
|
|
Packit |
fcad23 |
if (tmpint & MTE_OBJECT_FLAG_WILD)
|
|
Packit |
fcad23 |
entry->flags |= MTE_OBJECT_FLAG_WILD;
|
|
Packit |
fcad23 |
if (tmpint & MTE_OBJECT_FLAG_ACTIVE)
|
|
Packit |
fcad23 |
entry->flags |= MTE_OBJECT_FLAG_ACTIVE;
|
|
Packit |
fcad23 |
}
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
entry->flags |= MTE_OBJECT_FLAG_VALID;
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
DEBUGMSG(("disman:event:conf", "\n"));
|
|
Packit |
fcad23 |
}
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
int
|
|
Packit |
fcad23 |
store_mteOTable(int majorID, int minorID, void *serverarg, void *clientarg)
|
|
Packit |
fcad23 |
{
|
|
Packit |
fcad23 |
char line[SNMP_MAXBUF];
|
|
Packit |
fcad23 |
char *cptr, *cp;
|
|
Packit |
fcad23 |
void *vp;
|
|
Packit |
fcad23 |
size_t tint;
|
|
Packit |
fcad23 |
netsnmp_tdata_row *row;
|
|
Packit |
fcad23 |
struct mteObject *entry;
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
DEBUGMSGTL(("disman:event:conf", "Storing mteObjectTable config:\n"));
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
for (row = netsnmp_tdata_row_first( objects_table_data );
|
|
Packit |
fcad23 |
row;
|
|
Packit |
fcad23 |
row = netsnmp_tdata_row_next( objects_table_data, row )) {
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* Skip entries that were set up via static config directives
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
entry = (struct mteObject *)netsnmp_tdata_row_entry( row );
|
|
Packit |
fcad23 |
if ( entry->flags & MTE_OBJECT_FLAG_FIXED )
|
|
Packit |
fcad23 |
continue;
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
DEBUGMSGTL(("disman:event:conf", " Storing (%s %s %ld)\n",
|
|
Packit |
fcad23 |
entry->mteOwner, entry->mteOName, entry->mteOIndex));
|
|
Packit |
fcad23 |
memset(line, 0, sizeof(line));
|
|
Packit |
fcad23 |
strcat(line, "_mteOTable ");
|
|
Packit |
fcad23 |
cptr = line + strlen(line);
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
cp = entry->mteOwner; tint = strlen( cp );
|
|
Packit |
fcad23 |
cptr = read_config_store_data(ASN_OCTET_STR, cptr, &cp, &tint );
|
|
Packit |
fcad23 |
cp = entry->mteOName; tint = strlen( cp );
|
|
Packit |
fcad23 |
cptr = read_config_store_data(ASN_OCTET_STR, cptr, &cp, &tint );
|
|
Packit |
fcad23 |
cptr = read_config_store_data(ASN_UNSIGNED, cptr,
|
|
Packit |
fcad23 |
&entry->mteOIndex, NULL);
|
|
Packit |
fcad23 |
vp = entry->mteObjectID;
|
|
Packit |
fcad23 |
cptr = read_config_store_data(ASN_OBJECT_ID, cptr, &vp,
|
|
Packit |
fcad23 |
&entry->mteObjectID_len);
|
|
Packit |
fcad23 |
tint = entry->flags & (MTE_OBJECT_FLAG_WILD|MTE_OBJECT_FLAG_ACTIVE);
|
|
Packit |
fcad23 |
cptr = read_config_store_data(ASN_UNSIGNED, cptr, &tint, NULL);
|
|
Packit |
fcad23 |
snmpd_store_config(line);
|
|
Packit |
fcad23 |
}
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
DEBUGMSGTL(("disman:event:conf", " done.\n"));
|
|
Packit |
fcad23 |
return SNMPERR_SUCCESS;
|
|
Packit |
fcad23 |
}
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
int
|
|
Packit |
fcad23 |
clear_mteOTable(int majorID, int minorID, void *serverarg, void *clientarg)
|
|
Packit |
fcad23 |
{
|
|
Packit |
fcad23 |
netsnmp_tdata_row *row;
|
|
Packit |
fcad23 |
netsnmp_variable_list owner_var;
|
|
Packit |
fcad23 |
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* We're only interested in entries set up via the config files
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
memset( &owner_var, 0, sizeof(netsnmp_variable_list));
|
|
Packit |
fcad23 |
snmp_set_var_typed_value( &owner_var, ASN_OCTET_STR,
|
|
Packit |
fcad23 |
"snmpd.conf", strlen("snmpd.conf"));
|
|
Packit |
fcad23 |
while (( row = netsnmp_tdata_row_next_byidx( objects_table_data,
|
|
Packit |
fcad23 |
&owner_var ))) {
|
|
Packit |
fcad23 |
/*
|
|
Packit |
fcad23 |
* XXX - check for owner of "snmpd.conf"
|
|
Packit |
fcad23 |
* and break at the end of these
|
|
Packit |
fcad23 |
*/
|
|
Packit |
fcad23 |
netsnmp_tdata_remove_and_delete_row( objects_table_data, row );
|
|
Packit |
fcad23 |
}
|
|
Packit |
fcad23 |
return SNMPERR_SUCCESS;
|
|
Packit |
fcad23 |
}
|