| 1 |
/* |
| 2 |
* DisMan Event MIB: |
| 3 |
* Implementation of the mteEventSetTable MIB interface |
| 4 |
* See 'mteEvent.c' for active behaviour of this table. |
| 5 |
* |
| 6 |
* (based on mib2c.table_data.conf output) |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <net-snmp/net-snmp-config.h> |
| 10 |
#include <net-snmp/net-snmp-features.h> |
| 11 |
#include <net-snmp/net-snmp-includes.h> |
| 12 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 13 |
#include "disman/event/mteEvent.h" |
| 14 |
#include "disman/event/mteEventSetTable.h" |
| 15 |
|
| 16 |
netsnmp_feature_require(table_tdata); |
| 17 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 18 |
netsnmp_feature_require(check_vb_type_and_max_size); |
| 19 |
netsnmp_feature_require(check_vb_oid); |
| 20 |
netsnmp_feature_require(check_vb_truthvalue); |
| 21 |
#endif /* NETSNMP_NO_WRITE_SUPPORT */ |
| 22 |
|
| 23 |
static netsnmp_table_registration_info *table_info; |
| 24 |
|
| 25 |
/* Initializes the mteEventSetTable module */ |
| 26 |
void |
| 27 |
init_mteEventSetTable(void) |
| 28 |
{ |
| 29 |
static oid mteEventSetTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 4, 4 }; |
| 30 |
size_t mteEventSetTable_oid_len = OID_LENGTH(mteEventSetTable_oid); |
| 31 |
netsnmp_handler_registration *reg; |
| 32 |
|
| 33 |
/* |
| 34 |
* Ensure the (combined) table container is available... |
| 35 |
*/ |
| 36 |
init_event_table_data(); |
| 37 |
|
| 38 |
/* |
| 39 |
* ... then set up the MIB interface to the mteEventSetTable slice |
| 40 |
*/ |
| 41 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 42 |
reg = netsnmp_create_handler_registration("mteEventSetTable", |
| 43 |
mteEventSetTable_handler, |
| 44 |
mteEventSetTable_oid, |
| 45 |
mteEventSetTable_oid_len, |
| 46 |
HANDLER_CAN_RWRITE); |
| 47 |
#else /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 48 |
reg = netsnmp_create_handler_registration("mteEventSetTable", |
| 49 |
mteEventSetTable_handler, |
| 50 |
mteEventSetTable_oid, |
| 51 |
mteEventSetTable_oid_len, |
| 52 |
HANDLER_CAN_RONLY); |
| 53 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 54 |
|
| 55 |
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); |
| 56 |
netsnmp_table_helper_add_indexes(table_info, |
| 57 |
ASN_OCTET_STR, /* index: mteOwner */ |
| 58 |
/* index: mteEventName */ |
| 59 |
ASN_PRIV_IMPLIED_OCTET_STR, |
| 60 |
0); |
| 61 |
|
| 62 |
table_info->min_column = COLUMN_MTEEVENTSETOBJECT; |
| 63 |
table_info->max_column = COLUMN_MTEEVENTSETCONTEXTNAMEWILDCARD; |
| 64 |
|
| 65 |
/* Register this using the (common) event_table_data container */ |
| 66 |
netsnmp_tdata_register(reg, event_table_data, table_info); |
| 67 |
DEBUGMSGTL(("disman:event:init", "Event Set Table container (%p)\n", |
| 68 |
event_table_data)); |
| 69 |
} |
| 70 |
|
| 71 |
void |
| 72 |
shutdown_mteEventSetTable(void) |
| 73 |
{ |
| 74 |
if (table_info) { |
| 75 |
netsnmp_table_registration_info_free(table_info); |
| 76 |
table_info = NULL; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
/** handles requests for the mteEventSetTable table */ |
| 82 |
int |
| 83 |
mteEventSetTable_handler(netsnmp_mib_handler *handler, |
| 84 |
netsnmp_handler_registration *reginfo, |
| 85 |
netsnmp_agent_request_info *reqinfo, |
| 86 |
netsnmp_request_info *requests) |
| 87 |
{ |
| 88 |
|
| 89 |
netsnmp_request_info *request; |
| 90 |
netsnmp_table_request_info *tinfo; |
| 91 |
struct mteEvent *entry; |
| 92 |
int ret; |
| 93 |
|
| 94 |
DEBUGMSGTL(("disman:event:mib", "Set Table handler (%d)\n", |
| 95 |
reqinfo->mode)); |
| 96 |
|
| 97 |
switch (reqinfo->mode) { |
| 98 |
/* |
| 99 |
* Read-support (also covers GetNext requests) |
| 100 |
*/ |
| 101 |
case MODE_GET: |
| 102 |
for (request = requests; request; request = request->next) { |
| 103 |
if (request->processed) |
| 104 |
continue; |
| 105 |
|
| 106 |
entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); |
| 107 |
tinfo = netsnmp_extract_table_info(request); |
| 108 |
|
| 109 |
/* |
| 110 |
* The mteEventSetTable should only contains entries for |
| 111 |
* rows where the mteEventActions 'set(1)' bit is set. |
| 112 |
* So skip entries where this isn't the case. |
| 113 |
*/ |
| 114 |
if (!entry || !(entry->mteEventActions & MTE_EVENT_SET)) |
| 115 |
continue; |
| 116 |
|
| 117 |
switch (tinfo->colnum) { |
| 118 |
case COLUMN_MTEEVENTSETOBJECT: |
| 119 |
snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, |
| 120 |
(u_char *) entry->mteSetOID, |
| 121 |
entry->mteSetOID_len*sizeof(oid)); |
| 122 |
break; |
| 123 |
case COLUMN_MTEEVENTSETOBJECTWILDCARD: |
| 124 |
ret = (entry->flags & MTE_SET_FLAG_OBJWILD ) ? |
| 125 |
TV_TRUE : TV_FALSE; |
| 126 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); |
| 127 |
break; |
| 128 |
case COLUMN_MTEEVENTSETVALUE: |
| 129 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, |
| 130 |
entry->mteSetValue); |
| 131 |
break; |
| 132 |
case COLUMN_MTEEVENTSETTARGETTAG: |
| 133 |
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, |
| 134 |
(u_char *) entry->mteSetTarget, |
| 135 |
strlen(entry->mteSetTarget)); |
| 136 |
break; |
| 137 |
case COLUMN_MTEEVENTSETCONTEXTNAME: |
| 138 |
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, |
| 139 |
(u_char *) entry->mteSetContext, |
| 140 |
strlen(entry->mteSetContext)); |
| 141 |
break; |
| 142 |
case COLUMN_MTEEVENTSETCONTEXTNAMEWILDCARD: |
| 143 |
ret = (entry->flags & MTE_SET_FLAG_CTXWILD ) ? |
| 144 |
TV_TRUE : TV_FALSE; |
| 145 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); |
| 146 |
break; |
| 147 |
} |
| 148 |
} |
| 149 |
break; |
| 150 |
|
| 151 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 152 |
/* |
| 153 |
* Write-support |
| 154 |
*/ |
| 155 |
case MODE_SET_RESERVE1: |
| 156 |
for (request = requests; request; request = request->next) { |
| 157 |
if (request->processed) |
| 158 |
continue; |
| 159 |
|
| 160 |
tinfo = netsnmp_extract_table_info(request); |
| 161 |
|
| 162 |
/* |
| 163 |
* Since the mteEventSetTable only contains entries for |
| 164 |
* rows where the mteEventActions 'set(1)' bit is set, |
| 165 |
* strictly speaking we should reject assignments where |
| 166 |
* this isn't the case. |
| 167 |
* But SET requests that include an assignment of the |
| 168 |
* 'set(1)' bit at the same time are valid, so would |
| 169 |
* need to be accepted. Unfortunately, this assignment |
| 170 |
* is only applied in the COMMIT pass, so it's difficult |
| 171 |
* to detect whether this holds or not. |
| 172 |
* |
| 173 |
* Let's fudge things for now, by processing assignments |
| 174 |
* even if the 'set(1)' bit isn't set. |
| 175 |
*/ |
| 176 |
switch (tinfo->colnum) { |
| 177 |
case COLUMN_MTEEVENTSETOBJECT: |
| 178 |
ret = netsnmp_check_vb_oid( request->requestvb ); |
| 179 |
if (ret != SNMP_ERR_NOERROR) { |
| 180 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 181 |
return SNMP_ERR_NOERROR; |
| 182 |
} |
| 183 |
break; |
| 184 |
case COLUMN_MTEEVENTSETOBJECTWILDCARD: |
| 185 |
case COLUMN_MTEEVENTSETCONTEXTNAMEWILDCARD: |
| 186 |
ret = netsnmp_check_vb_truthvalue( request->requestvb ); |
| 187 |
if (ret != SNMP_ERR_NOERROR) { |
| 188 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 189 |
return SNMP_ERR_NOERROR; |
| 190 |
} |
| 191 |
break; |
| 192 |
case COLUMN_MTEEVENTSETVALUE: |
| 193 |
ret = netsnmp_check_vb_int( request->requestvb ); |
| 194 |
if (ret != SNMP_ERR_NOERROR) { |
| 195 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 196 |
return SNMP_ERR_NOERROR; |
| 197 |
} |
| 198 |
break; |
| 199 |
case COLUMN_MTEEVENTSETTARGETTAG: |
| 200 |
case COLUMN_MTEEVENTSETCONTEXTNAME: |
| 201 |
ret = netsnmp_check_vb_type_and_max_size( |
| 202 |
request->requestvb, ASN_OCTET_STR, MTE_STR2_LEN); |
| 203 |
if (ret != SNMP_ERR_NOERROR) { |
| 204 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 205 |
return SNMP_ERR_NOERROR; |
| 206 |
} |
| 207 |
break; |
| 208 |
default: |
| 209 |
netsnmp_set_request_error(reqinfo, request, |
| 210 |
SNMP_ERR_NOTWRITABLE); |
| 211 |
return SNMP_ERR_NOERROR; |
| 212 |
} |
| 213 |
|
| 214 |
/* |
| 215 |
* The Event MIB is somewhat ambiguous as to whether |
| 216 |
* mteEventSetTable (and mteEventNotificationTable) |
| 217 |
* entries can be modified once the main mteEventTable |
| 218 |
* entry has been marked 'active'. |
| 219 |
* But it's clear from discussion on the DisMan mailing |
| 220 |
* list is that the intention is not. |
| 221 |
* |
| 222 |
* So check for whether this row is already active, |
| 223 |
* and reject *all* SET requests if it is. |
| 224 |
*/ |
| 225 |
entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); |
| 226 |
if (entry && |
| 227 |
entry->flags & MTE_EVENT_FLAG_ACTIVE ) { |
| 228 |
netsnmp_set_request_error(reqinfo, request, |
| 229 |
SNMP_ERR_INCONSISTENTVALUE); |
| 230 |
return SNMP_ERR_NOERROR; |
| 231 |
} |
| 232 |
} |
| 233 |
break; |
| 234 |
|
| 235 |
case MODE_SET_RESERVE2: |
| 236 |
case MODE_SET_FREE: |
| 237 |
case MODE_SET_UNDO: |
| 238 |
break; |
| 239 |
|
| 240 |
case MODE_SET_ACTION: |
| 241 |
for (request = requests; request; request = request->next) { |
| 242 |
if (request->processed) |
| 243 |
continue; |
| 244 |
|
| 245 |
entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); |
| 246 |
if (!entry) { |
| 247 |
/* |
| 248 |
* New rows must be created via the RowStatus column |
| 249 |
* (in the main mteEventTable) |
| 250 |
*/ |
| 251 |
netsnmp_set_request_error(reqinfo, request, |
| 252 |
SNMP_ERR_NOCREATION); |
| 253 |
/* or inconsistentName? */ |
| 254 |
return SNMP_ERR_NOERROR; |
| 255 |
|
| 256 |
} |
| 257 |
} |
| 258 |
break; |
| 259 |
|
| 260 |
case MODE_SET_COMMIT: |
| 261 |
/* |
| 262 |
* All these assignments are "unfailable", so it's |
| 263 |
* (reasonably) safe to apply them in the Commit phase |
| 264 |
*/ |
| 265 |
for (request = requests; request; request = request->next) { |
| 266 |
if (request->processed) |
| 267 |
continue; |
| 268 |
|
| 269 |
entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); |
| 270 |
tinfo = netsnmp_extract_table_info(request); |
| 271 |
|
| 272 |
switch (tinfo->colnum) { |
| 273 |
case COLUMN_MTEEVENTSETOBJECT: |
| 274 |
memset(entry->mteSetOID, 0, sizeof(entry->mteSetOID)); |
| 275 |
memcpy(entry->mteSetOID, request->requestvb->val.objid, |
| 276 |
request->requestvb->val_len); |
| 277 |
entry->mteSetOID_len = request->requestvb->val_len/sizeof(oid); |
| 278 |
break; |
| 279 |
case COLUMN_MTEEVENTSETOBJECTWILDCARD: |
| 280 |
if (*request->requestvb->val.integer == TV_TRUE) |
| 281 |
entry->flags |= MTE_SET_FLAG_OBJWILD; |
| 282 |
else |
| 283 |
entry->flags &= ~MTE_SET_FLAG_OBJWILD; |
| 284 |
break; |
| 285 |
case COLUMN_MTEEVENTSETVALUE: |
| 286 |
entry->mteSetValue = *request->requestvb->val.integer; |
| 287 |
break; |
| 288 |
case COLUMN_MTEEVENTSETTARGETTAG: |
| 289 |
memset(entry->mteSetTarget, 0, sizeof(entry->mteSetTarget)); |
| 290 |
memcpy(entry->mteSetTarget, request->requestvb->val.string, |
| 291 |
request->requestvb->val_len); |
| 292 |
break; |
| 293 |
case COLUMN_MTEEVENTSETCONTEXTNAME: |
| 294 |
memset(entry->mteSetContext, 0, sizeof(entry->mteSetContext)); |
| 295 |
memcpy(entry->mteSetContext, request->requestvb->val.string, |
| 296 |
request->requestvb->val_len); |
| 297 |
break; |
| 298 |
case COLUMN_MTEEVENTSETCONTEXTNAMEWILDCARD: |
| 299 |
if (*request->requestvb->val.integer == TV_TRUE) |
| 300 |
entry->flags |= MTE_SET_FLAG_CTXWILD; |
| 301 |
else |
| 302 |
entry->flags &= ~MTE_SET_FLAG_CTXWILD; |
| 303 |
break; |
| 304 |
} |
| 305 |
} |
| 306 |
break; |
| 307 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 308 |
} |
| 309 |
return SNMP_ERR_NOERROR; |
| 310 |
} |