| 1 |
/* |
| 2 |
* DisMan Event MIB: |
| 3 |
* Implementation of the object table configure handling |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <net-snmp/net-snmp-config.h> |
| 7 |
#include <net-snmp/net-snmp-includes.h> |
| 8 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 9 |
#include <net-snmp/agent/agent_callbacks.h> |
| 10 |
#include "disman/event/mteObjects.h" |
| 11 |
#include "disman/event/mteObjectsConf.h" |
| 12 |
|
| 13 |
|
| 14 |
/** Initializes the mteObjectsConf module */ |
| 15 |
void |
| 16 |
init_mteObjectsConf(void) |
| 17 |
{ |
| 18 |
init_objects_table_data(); |
| 19 |
|
| 20 |
/* |
| 21 |
* Register config handlers for current and previous style |
| 22 |
* persistent configuration directives |
| 23 |
*/ |
| 24 |
snmpd_register_config_handler("_mteOTable", |
| 25 |
parse_mteOTable, NULL, NULL); |
| 26 |
snmpd_register_config_handler("mteObjectsTable", |
| 27 |
parse_mteOTable, NULL, NULL); |
| 28 |
/* |
| 29 |
* Register to save (non-fixed) entries when the agent shuts down |
| 30 |
*/ |
| 31 |
snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, |
| 32 |
store_mteOTable, NULL); |
| 33 |
snmp_register_callback(SNMP_CALLBACK_APPLICATION, |
| 34 |
SNMPD_CALLBACK_PRE_UPDATE_CONFIG, |
| 35 |
clear_mteOTable, NULL); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
void |
| 40 |
parse_mteOTable(const char *token, char *line) |
| 41 |
{ |
| 42 |
char owner[MTE_STR1_LEN+1]; |
| 43 |
char oname[MTE_STR1_LEN+1]; |
| 44 |
void *vp; |
| 45 |
u_long index; |
| 46 |
size_t tmpint; |
| 47 |
size_t len; |
| 48 |
netsnmp_tdata_row *row; |
| 49 |
struct mteObject *entry; |
| 50 |
|
| 51 |
DEBUGMSGTL(("disman:event:conf", "Parsing mteObjectTable config... ")); |
| 52 |
|
| 53 |
/* |
| 54 |
* Read in the index information for this entry |
| 55 |
* and create a (non-fixed) data structure for it. |
| 56 |
*/ |
| 57 |
memset( owner, 0, sizeof(owner)); |
| 58 |
memset( oname, 0, sizeof(oname)); |
| 59 |
len = MTE_STR1_LEN; vp = owner; |
| 60 |
line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len); |
| 61 |
len = MTE_STR1_LEN; vp = oname; |
| 62 |
line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len); |
| 63 |
line = read_config_read_data(ASN_UNSIGNED, line, &index, &len); |
| 64 |
|
| 65 |
DEBUGMSG(("disman:event:conf", "(%s, %s, %lu) ", owner, oname, index)); |
| 66 |
|
| 67 |
row = mteObjects_createEntry( owner, oname, index, 0 ); |
| 68 |
/* entry = (struct mteObject *)netsnmp_tdata_row_entry( row ); */ |
| 69 |
entry = (struct mteObject *)row->data; |
| 70 |
|
| 71 |
|
| 72 |
/* |
| 73 |
* Read in the accessible column values |
| 74 |
*/ |
| 75 |
entry->mteObjectID_len = MAX_OID_LEN; |
| 76 |
vp = entry->mteObjectID; |
| 77 |
line = read_config_read_data(ASN_OBJECT_ID, line, &vp, |
| 78 |
&entry->mteObjectID_len); |
| 79 |
|
| 80 |
if (!strcasecmp(token, "mteObjectsTable")) { |
| 81 |
/* |
| 82 |
* The previous Event-MIB implementation saved |
| 83 |
* these fields as separate (integer) values |
| 84 |
* Accept this (for backwards compatability) |
| 85 |
*/ |
| 86 |
line = read_config_read_data(ASN_UNSIGNED, line, &tmpint, &len); |
| 87 |
if (tmpint == TV_TRUE) |
| 88 |
entry->flags |= MTE_OBJECT_FLAG_WILD; |
| 89 |
line = read_config_read_data(ASN_UNSIGNED, line, &tmpint, &len); |
| 90 |
if (tmpint == RS_ACTIVE) |
| 91 |
entry->flags |= MTE_OBJECT_FLAG_ACTIVE; |
| 92 |
} else { |
| 93 |
/* |
| 94 |
* This implementation saves the (relevant) flag bits directly |
| 95 |
*/ |
| 96 |
line = read_config_read_data(ASN_UNSIGNED, line, &tmpint, &len); |
| 97 |
if (tmpint & MTE_OBJECT_FLAG_WILD) |
| 98 |
entry->flags |= MTE_OBJECT_FLAG_WILD; |
| 99 |
if (tmpint & MTE_OBJECT_FLAG_ACTIVE) |
| 100 |
entry->flags |= MTE_OBJECT_FLAG_ACTIVE; |
| 101 |
} |
| 102 |
|
| 103 |
entry->flags |= MTE_OBJECT_FLAG_VALID; |
| 104 |
|
| 105 |
DEBUGMSG(("disman:event:conf", "\n")); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
int |
| 111 |
store_mteOTable(int majorID, int minorID, void *serverarg, void *clientarg) |
| 112 |
{ |
| 113 |
char line[SNMP_MAXBUF]; |
| 114 |
char *cptr, *cp; |
| 115 |
void *vp; |
| 116 |
size_t tint; |
| 117 |
netsnmp_tdata_row *row; |
| 118 |
struct mteObject *entry; |
| 119 |
|
| 120 |
|
| 121 |
DEBUGMSGTL(("disman:event:conf", "Storing mteObjectTable config:\n")); |
| 122 |
|
| 123 |
for (row = netsnmp_tdata_row_first( objects_table_data ); |
| 124 |
row; |
| 125 |
row = netsnmp_tdata_row_next( objects_table_data, row )) { |
| 126 |
|
| 127 |
/* |
| 128 |
* Skip entries that were set up via static config directives |
| 129 |
*/ |
| 130 |
entry = (struct mteObject *)netsnmp_tdata_row_entry( row ); |
| 131 |
if ( entry->flags & MTE_OBJECT_FLAG_FIXED ) |
| 132 |
continue; |
| 133 |
|
| 134 |
DEBUGMSGTL(("disman:event:conf", " Storing (%s %s %ld)\n", |
| 135 |
entry->mteOwner, entry->mteOName, entry->mteOIndex)); |
| 136 |
memset(line, 0, sizeof(line)); |
| 137 |
strcat(line, "_mteOTable "); |
| 138 |
cptr = line + strlen(line); |
| 139 |
|
| 140 |
cp = entry->mteOwner; tint = strlen( cp ); |
| 141 |
cptr = read_config_store_data(ASN_OCTET_STR, cptr, &cp, &tint ); |
| 142 |
cp = entry->mteOName; tint = strlen( cp ); |
| 143 |
cptr = read_config_store_data(ASN_OCTET_STR, cptr, &cp, &tint ); |
| 144 |
cptr = read_config_store_data(ASN_UNSIGNED, cptr, |
| 145 |
&entry->mteOIndex, NULL); |
| 146 |
vp = entry->mteObjectID; |
| 147 |
cptr = read_config_store_data(ASN_OBJECT_ID, cptr, &vp, |
| 148 |
&entry->mteObjectID_len); |
| 149 |
tint = entry->flags & (MTE_OBJECT_FLAG_WILD|MTE_OBJECT_FLAG_ACTIVE); |
| 150 |
cptr = read_config_store_data(ASN_UNSIGNED, cptr, &tint, NULL); |
| 151 |
snmpd_store_config(line); |
| 152 |
} |
| 153 |
|
| 154 |
DEBUGMSGTL(("disman:event:conf", " done.\n")); |
| 155 |
return SNMPERR_SUCCESS; |
| 156 |
} |
| 157 |
|
| 158 |
int |
| 159 |
clear_mteOTable(int majorID, int minorID, void *serverarg, void *clientarg) |
| 160 |
{ |
| 161 |
netsnmp_tdata_row *row; |
| 162 |
netsnmp_variable_list owner_var; |
| 163 |
|
| 164 |
/* |
| 165 |
* We're only interested in entries set up via the config files |
| 166 |
*/ |
| 167 |
memset( &owner_var, 0, sizeof(netsnmp_variable_list)); |
| 168 |
snmp_set_var_typed_value( &owner_var, ASN_OCTET_STR, |
| 169 |
"snmpd.conf", strlen("snmpd.conf")); |
| 170 |
while (( row = netsnmp_tdata_row_next_byidx( objects_table_data, |
| 171 |
&owner_var ))) { |
| 172 |
/* |
| 173 |
* XXX - check for owner of "snmpd.conf" |
| 174 |
* and break at the end of these |
| 175 |
*/ |
| 176 |
netsnmp_tdata_remove_and_delete_row( objects_table_data, row ); |
| 177 |
} |
| 178 |
return SNMPERR_SUCCESS; |
| 179 |
} |