Debian Codegraph @

agent/mibgroup/disman/event/mteEventTable.c

raw
1 /*
2 * DisMan Event MIB:
3 * Implementation of the mteEventTable 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 "utilities/iquery.h"
14 #include "disman/event/mteEvent.h"
15 #include "disman/event/mteEventTable.h"
16
17 netsnmp_feature_require(iquery);
18 netsnmp_feature_require(table_tdata);
19 #ifndef NETSNMP_NO_WRITE_SUPPORT
20 netsnmp_feature_require(iquery_pdu_session);
21 netsnmp_feature_require(check_vb_type_and_max_size);
22 netsnmp_feature_require(mteevent_removeentry);
23 netsnmp_feature_require(check_vb_truthvalue);
24 netsnmp_feature_require(table_tdata_insert_row);
25 #endif /* NETSNMP_NO_WRITE_SUPPORT */
26
27 static netsnmp_table_registration_info *table_info;
28
29 /* Initializes the mteEventTable module */
30 void
31 init_mteEventTable(void)
32 {
33 static oid mteEventTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 4, 2 };
34 size_t mteEventTable_oid_len = OID_LENGTH(mteEventTable_oid);
35 netsnmp_handler_registration *reg;
36
37 /*
38 * Ensure the (combined) table container is available...
39 */
40 init_event_table_data();
41
42 /*
43 * ... then set up the MIB interface to the mteEventTable slice
44 */
45 #ifndef NETSNMP_NO_WRITE_SUPPORT
46 reg = netsnmp_create_handler_registration("mteEventTable",
47 mteEventTable_handler,
48 mteEventTable_oid,
49 mteEventTable_oid_len,
50 HANDLER_CAN_RWRITE);
51 #else /* !NETSNMP_NO_WRITE_SUPPORT */
52 reg = netsnmp_create_handler_registration("mteEventTable",
53 mteEventTable_handler,
54 mteEventTable_oid,
55 mteEventTable_oid_len,
56 HANDLER_CAN_RONLY);
57 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
58
59 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
60 netsnmp_table_helper_add_indexes(table_info,
61 ASN_OCTET_STR, /* index: mteOwner */
62 /* index: mteEventName */
63 ASN_PRIV_IMPLIED_OCTET_STR,
64 0);
65
66 table_info->min_column = COLUMN_MTEEVENTCOMMENT;
67 table_info->max_column = COLUMN_MTEEVENTENTRYSTATUS;
68
69 /* Register this using the (common) event_table_data container */
70 netsnmp_tdata_register(reg, event_table_data, table_info);
71 DEBUGMSGTL(("disman:event:init", "Event Table container (%p)\n",
72 event_table_data));
73 }
74
75 void
76 shutdown_mteEventTable(void)
77 {
78 if (table_info) {
79 netsnmp_table_registration_info_free(table_info);
80 table_info = NULL;
81 }
82 }
83
84 /** handles requests for the mteEventTable table */
85 int
86 mteEventTable_handler(netsnmp_mib_handler *handler,
87 netsnmp_handler_registration *reginfo,
88 netsnmp_agent_request_info *reqinfo,
89 netsnmp_request_info *requests)
90 {
91
92 netsnmp_request_info *request;
93 netsnmp_table_request_info *tinfo;
94 struct mteEvent *entry;
95 #ifndef NETSNMP_NO_WRITE_SUPPORT
96 netsnmp_tdata_row *row;
97 char mteOwner[MTE_STR1_LEN+1];
98 char mteEName[MTE_STR1_LEN+1];
99 #endif
100 long ret;
101
102 DEBUGMSGTL(("disman:event:mib", "Event Table handler (%d)\n",
103 reqinfo->mode));
104
105 switch (reqinfo->mode) {
106 /*
107 * Read-support (also covers GetNext requests)
108 */
109 case MODE_GET:
110 for (request = requests; request; request = request->next) {
111 if (request->processed)
112 continue;
113
114 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
115 tinfo = netsnmp_extract_table_info(request);
116 if (!entry || !(entry->flags & MTE_EVENT_FLAG_VALID))
117 continue;
118
119 switch (tinfo->colnum) {
120 case COLUMN_MTEEVENTCOMMENT:
121 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
122 entry->mteEventComment,
123 strlen(entry->mteEventComment));
124 break;
125 case COLUMN_MTEEVENTACTIONS:
126 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
127 &entry->mteEventActions, 1);
128 break;
129 case COLUMN_MTEEVENTENABLED:
130 ret = (entry->flags & MTE_EVENT_FLAG_ENABLED ) ?
131 TV_TRUE : TV_FALSE;
132 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
133 break;
134 case COLUMN_MTEEVENTENTRYSTATUS:
135 ret = (entry->flags & MTE_EVENT_FLAG_ACTIVE ) ?
136 RS_ACTIVE : RS_NOTINSERVICE;
137 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
138 break;
139 }
140 }
141 break;
142
143
144 #ifndef NETSNMP_NO_WRITE_SUPPORT
145 /*
146 * Write-support
147 */
148 case MODE_SET_RESERVE1:
149 for (request = requests; request; request = request->next) {
150 if (request->processed)
151 continue;
152
153 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
154 tinfo = netsnmp_extract_table_info(request);
155
156 switch (tinfo->colnum) {
157 case COLUMN_MTEEVENTCOMMENT:
158 ret = netsnmp_check_vb_type_and_max_size(
159 request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN);
160 if (ret != SNMP_ERR_NOERROR) {
161 netsnmp_set_request_error(reqinfo, request, ret);
162 return SNMP_ERR_NOERROR;
163 }
164 /*
165 * Can't modify the comment of an active row
166 * (No good reason for this, but that's what the MIB says!)
167 */
168 if (entry &&
169 entry->flags & MTE_EVENT_FLAG_ACTIVE ) {
170 netsnmp_set_request_error(reqinfo, request,
171 SNMP_ERR_INCONSISTENTVALUE);
172 return SNMP_ERR_NOERROR;
173 }
174 break;
175 case COLUMN_MTEEVENTACTIONS:
176 ret = netsnmp_check_vb_type_and_size(
177 request->requestvb, ASN_OCTET_STR, 1);
178 if (ret != SNMP_ERR_NOERROR) {
179 netsnmp_set_request_error(reqinfo, request, ret);
180 return SNMP_ERR_NOERROR;
181 }
182 /*
183 * Can't modify the event types of an active row
184 * (A little more understandable perhaps,
185 * but still an unnecessary restriction IMO)
186 */
187 if (entry &&
188 entry->flags & MTE_EVENT_FLAG_ACTIVE ) {
189 netsnmp_set_request_error(reqinfo, request,
190 SNMP_ERR_INCONSISTENTVALUE);
191 return SNMP_ERR_NOERROR;
192 }
193 break;
194 case COLUMN_MTEEVENTENABLED:
195 ret = netsnmp_check_vb_truthvalue(request->requestvb);
196 if (ret != SNMP_ERR_NOERROR) {
197 netsnmp_set_request_error(reqinfo, request, ret);
198 return SNMP_ERR_NOERROR;
199 }
200 /*
201 * The published version of the Event MIB forbids
202 * enabling (or disabling) an active row, which
203 * would make this object completely pointless!
204 * Fortunately this ludicrous decision has since been corrected.
205 */
206 break;
207
208 case COLUMN_MTEEVENTENTRYSTATUS:
209 ret = netsnmp_check_vb_rowstatus(request->requestvb,
210 (entry ? RS_ACTIVE : RS_NONEXISTENT));
211 if (ret != SNMP_ERR_NOERROR) {
212 netsnmp_set_request_error(reqinfo, request, ret);
213 return SNMP_ERR_NOERROR;
214 }
215 /* An active row can only be deleted */
216 if (entry &&
217 entry->flags & MTE_EVENT_FLAG_ACTIVE &&
218 *request->requestvb->val.integer == RS_NOTINSERVICE ) {
219 netsnmp_set_request_error(reqinfo, request,
220 SNMP_ERR_INCONSISTENTVALUE);
221 return SNMP_ERR_NOERROR;
222 }
223 break;
224 default:
225 netsnmp_set_request_error(reqinfo, request,
226 SNMP_ERR_NOTWRITABLE);
227 return SNMP_ERR_NOERROR;
228 }
229 }
230 break;
231
232 case MODE_SET_RESERVE2:
233 for (request = requests; request; request = request->next) {
234 if (request->processed)
235 continue;
236
237 tinfo = netsnmp_extract_table_info(request);
238
239 switch (tinfo->colnum) {
240 case COLUMN_MTEEVENTENTRYSTATUS:
241 switch (*request->requestvb->val.integer) {
242 case RS_CREATEANDGO:
243 case RS_CREATEANDWAIT:
244 /*
245 * Create an (empty) new row structure
246 */
247 memset(mteOwner, 0, sizeof(mteOwner));
248 memcpy(mteOwner, tinfo->indexes->val.string,
249 tinfo->indexes->val_len);
250 memset(mteEName, 0, sizeof(mteEName));
251 memcpy(mteEName,
252 tinfo->indexes->next_variable->val.string,
253 tinfo->indexes->next_variable->val_len);
254
255 row = mteEvent_createEntry(mteOwner, mteEName, 0);
256 if (!row) {
257 netsnmp_set_request_error(reqinfo, request,
258 SNMP_ERR_RESOURCEUNAVAILABLE);
259 return SNMP_ERR_NOERROR;
260 }
261 netsnmp_insert_tdata_row( request, row );
262 }
263 }
264 }
265 break;
266
267 case MODE_SET_FREE:
268 for (request = requests; request; request = request->next) {
269 if (request->processed)
270 continue;
271
272 tinfo = netsnmp_extract_table_info(request);
273
274 switch (tinfo->colnum) {
275 case COLUMN_MTEEVENTENTRYSTATUS:
276 switch (*request->requestvb->val.integer) {
277 case RS_CREATEANDGO:
278 case RS_CREATEANDWAIT:
279 /*
280 * Tidy up after a failed row creation request
281 */
282 entry = (struct mteEvent *)
283 netsnmp_tdata_extract_entry(request);
284 if (entry &&
285 !(entry->flags & MTE_EVENT_FLAG_VALID)) {
286 row = (netsnmp_tdata_row *)
287 netsnmp_tdata_extract_row(request);
288 mteEvent_removeEntry( row );
289 }
290 }
291 }
292 }
293 break;
294
295 case MODE_SET_ACTION:
296 for (request = requests; request; request = request->next) {
297 if (request->processed)
298 continue;
299
300 tinfo = netsnmp_extract_table_info(request);
301 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
302 if (!entry) {
303 /*
304 * New rows must be created via the RowStatus column
305 */
306 netsnmp_set_request_error(reqinfo, request,
307 SNMP_ERR_NOCREATION);
308 /* or inconsistentName? */
309 return SNMP_ERR_NOERROR;
310
311 }
312 }
313 break;
314
315 case MODE_SET_UNDO:
316 break;
317
318 case MODE_SET_COMMIT:
319 /*
320 * All these assignments are "unfailable", so it's
321 * (reasonably) safe to apply them in the Commit phase
322 */
323 for (request = requests; request; request = request->next) {
324 if (request->processed)
325 continue;
326
327 entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
328 tinfo = netsnmp_extract_table_info(request);
329
330 switch (tinfo->colnum) {
331 case COLUMN_MTEEVENTCOMMENT:
332 memset(entry->mteEventComment, 0,
333 sizeof(entry->mteEventComment));
334 memcpy(entry->mteEventComment,
335 request->requestvb->val.string,
336 request->requestvb->val_len);
337 break;
338
339 case COLUMN_MTEEVENTACTIONS:
340 entry->mteEventActions = request->requestvb->val.string[0];
341 break;
342
343 case COLUMN_MTEEVENTENABLED:
344 if (*request->requestvb->val.integer == TV_TRUE)
345 entry->flags |= MTE_EVENT_FLAG_ENABLED;
346 else
347 entry->flags &= ~MTE_EVENT_FLAG_ENABLED;
348 break;
349
350 case COLUMN_MTEEVENTENTRYSTATUS:
351 switch (*request->requestvb->val.integer) {
352 case RS_ACTIVE:
353 entry->flags |= MTE_EVENT_FLAG_ACTIVE;
354 break;
355 case RS_CREATEANDGO:
356 entry->flags |= MTE_EVENT_FLAG_ACTIVE;
357 /* fall-through */
358 case RS_CREATEANDWAIT:
359 entry->flags |= MTE_EVENT_FLAG_VALID;
360 entry->session =
361 netsnmp_iquery_pdu_session(reqinfo->asp->pdu);
362 break;
363
364 case RS_DESTROY:
365 row = (netsnmp_tdata_row *)
366 netsnmp_tdata_extract_row(request);
367 mteEvent_removeEntry(row);
368 }
369 }
370 }
371 break;
372 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
373
374 }
375 DEBUGMSGTL(("disman:event:mib", "Table handler, done\n"));
376 return SNMP_ERR_NOERROR;
377 }