Debian Codegraph @

agent/mibgroup/disman/event/mteTriggerExistenceTable.c

raw
1 /*
2 * DisMan Event MIB:
3 * Implementation of the mteTriggerExistenceTable MIB interface
4 * See 'mteTrigger.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/mteTrigger.h"
14 #include "disman/event/mteTriggerExistenceTable.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 #endif /* NETSNMP_NO_WRITE_SUPPORT */
20
21 static netsnmp_table_registration_info *table_info;
22
23 /* Initializes the mteTriggerExistenceTable module */
24 void
25 init_mteTriggerExistenceTable(void)
26 {
27 static oid mteTExistTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 2, 4 };
28 size_t mteTExistTable_oid_len = OID_LENGTH(mteTExistTable_oid);
29 netsnmp_handler_registration *reg;
30 int rc;
31
32 /*
33 * Ensure the (combined) table container is available...
34 */
35 init_trigger_table_data();
36
37 /*
38 * ... then set up the MIB interface to the mteTriggerExistenceTable slice
39 */
40 #ifndef NETSNMP_NO_WRITE_SUPPORT
41 reg = netsnmp_create_handler_registration("mteTriggerExistenceTable",
42 mteTriggerExistenceTable_handler,
43 mteTExistTable_oid,
44 mteTExistTable_oid_len,
45 HANDLER_CAN_RWRITE);
46 #else /* !NETSNMP_NO_WRITE_SUPPORT */
47 reg = netsnmp_create_handler_registration("mteTriggerExistenceTable",
48 mteTriggerExistenceTable_handler,
49 mteTExistTable_oid,
50 mteTExistTable_oid_len,
51 HANDLER_CAN_RONLY);
52 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
53
54 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
55 netsnmp_table_helper_add_indexes(table_info,
56 ASN_OCTET_STR, /* index: mteOwner */
57 /* index: mteTriggerName */
58 ASN_PRIV_IMPLIED_OCTET_STR,
59 0);
60
61 table_info->min_column = COLUMN_MTETRIGGEREXISTENCETEST;
62 table_info->max_column = COLUMN_MTETRIGGEREXISTENCEEVENT;
63
64 /* Register this using the (common) trigger_table_data container */
65 rc = netsnmp_tdata_register(reg, trigger_table_data, table_info);
66 if (rc != SNMPERR_SUCCESS) {
67 snmp_log(LOG_ERR, "%s: netsnmp_tdata_register() returned %d\n",
68 __func__, rc);
69 return;
70 }
71 netsnmp_handler_owns_table_info(reg->handler->next);
72 DEBUGMSGTL(("disman:event:init", "Trigger Exist Table\n"));
73 }
74
75
76 /** handles requests for the mteTriggerExistenceTable table */
77 int
78 mteTriggerExistenceTable_handler(netsnmp_mib_handler *handler,
79 netsnmp_handler_registration *reginfo,
80 netsnmp_agent_request_info *reqinfo,
81 netsnmp_request_info *requests)
82 {
83
84 netsnmp_request_info *request;
85 netsnmp_table_request_info *tinfo;
86 struct mteTrigger *entry;
87 int ret;
88
89 DEBUGMSGTL(("disman:event:mib", "Exist Table handler (%d)\n",
90 reqinfo->mode));
91
92 switch (reqinfo->mode) {
93 /*
94 * Read-support (also covers GetNext requests)
95 */
96 case MODE_GET:
97 for (request = requests; request; request = request->next) {
98 if (request->processed)
99 continue;
100
101 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
102 tinfo = netsnmp_extract_table_info(request);
103
104 /*
105 * The mteTriggerExistenceTable should only contains entries for
106 * rows where the mteTriggerTest 'existence(0)' bit is set.
107 * So skip entries where this isn't the case.
108 */
109 if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_EXISTENCE )) {
110 netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
111 continue;
112 }
113
114 switch (tinfo->colnum) {
115 case COLUMN_MTETRIGGEREXISTENCETEST:
116 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
117 (u_char *)&entry->mteTExTest, 1);
118 break;
119 case COLUMN_MTETRIGGEREXISTENCESTARTUP:
120 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
121 (u_char *)&entry->mteTExStartup, 1);
122 break;
123 case COLUMN_MTETRIGGEREXISTENCEOBJECTSOWNER:
124 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
125 (u_char *) entry->mteTExObjOwner,
126 strlen(entry->mteTExObjOwner));
127 break;
128 case COLUMN_MTETRIGGEREXISTENCEOBJECTS:
129 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
130 (u_char *) entry->mteTExObjects,
131 strlen(entry->mteTExObjects));
132 break;
133 case COLUMN_MTETRIGGEREXISTENCEEVENTOWNER:
134 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
135 (u_char *) entry->mteTExEvOwner,
136 strlen(entry->mteTExEvOwner));
137 break;
138 case COLUMN_MTETRIGGEREXISTENCEEVENT:
139 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
140 (u_char *) entry->mteTExEvent,
141 strlen(entry->mteTExEvent));
142 break;
143 }
144 }
145 break;
146
147 #ifndef NETSNMP_NO_WRITE_SUPPORT
148 /*
149 * Write-support
150 */
151 case MODE_SET_RESERVE1:
152 for (request = requests; request; request = request->next) {
153 if (request->processed)
154 continue;
155
156 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
157 tinfo = netsnmp_extract_table_info(request);
158
159 /*
160 * Since the mteTriggerExistenceTable only contains entries for
161 * rows where the mteTriggerTest 'existence(0)' bit is set,
162 * strictly speaking we should reject assignments where
163 * this isn't the case.
164 * But SET requests that include an assignment of the
165 * 'existence(0)' bit at the same time are valid, so would
166 * need to be accepted. Unfortunately, this assignment
167 * is only applied in the COMMIT pass, so it's difficult
168 * to detect whether this holds or not.
169 *
170 * Let's fudge things for now, by processing assignments
171 * even if the 'existence(0)' bit isn't set.
172 */
173 switch (tinfo->colnum) {
174 case COLUMN_MTETRIGGEREXISTENCETEST:
175 case COLUMN_MTETRIGGEREXISTENCESTARTUP:
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 break;
183
184 case COLUMN_MTETRIGGEREXISTENCEOBJECTSOWNER:
185 case COLUMN_MTETRIGGEREXISTENCEOBJECTS:
186 case COLUMN_MTETRIGGEREXISTENCEEVENTOWNER:
187 case COLUMN_MTETRIGGEREXISTENCEEVENT:
188 ret = netsnmp_check_vb_type_and_max_size(
189 request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN);
190 if (ret != SNMP_ERR_NOERROR ) {
191 netsnmp_set_request_error(reqinfo, request, ret );
192 return SNMP_ERR_NOERROR;
193 }
194 break;
195
196 default:
197 netsnmp_set_request_error(reqinfo, request,
198 SNMP_ERR_NOTWRITABLE);
199 return SNMP_ERR_NOERROR;
200 }
201
202 /*
203 * The Event MIB is somewhat ambiguous as to whether the
204 * various trigger table entries can be modified once the
205 * main mteTriggerTable entry has been marked 'active'.
206 * But it's clear from discussion on the DisMan mailing
207 * list is that the intention is not.
208 *
209 * So check for whether this row is already active,
210 * and reject *all* SET requests if it is.
211 */
212 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
213 if (entry &&
214 entry->flags & MTE_TRIGGER_FLAG_ACTIVE ) {
215 netsnmp_set_request_error(reqinfo, request,
216 SNMP_ERR_INCONSISTENTVALUE);
217 return SNMP_ERR_NOERROR;
218 }
219 }
220 break;
221
222 case MODE_SET_RESERVE2:
223 case MODE_SET_FREE:
224 case MODE_SET_UNDO:
225 break;
226
227 case MODE_SET_ACTION:
228 for (request = requests; request; request = request->next) {
229 if (request->processed)
230 continue;
231
232 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
233 if (!entry) {
234 /*
235 * New rows must be created via the RowStatus column
236 * (in the main mteTriggerTable)
237 */
238 netsnmp_set_request_error(reqinfo, request,
239 SNMP_ERR_NOCREATION);
240 /* or inconsistentName? */
241 return SNMP_ERR_NOERROR;
242
243 }
244 }
245 break;
246
247 case MODE_SET_COMMIT:
248 /*
249 * All these assignments are "unfailable", so it's
250 * (reasonably) safe to apply them in the Commit phase
251 */
252 for (request = requests; request; request = request->next) {
253 if (request->processed)
254 continue;
255
256 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
257 tinfo = netsnmp_extract_table_info(request);
258
259 switch (tinfo->colnum) {
260 case COLUMN_MTETRIGGEREXISTENCETEST:
261 entry->mteTExTest = request->requestvb->val.string[0];
262 break;
263 case COLUMN_MTETRIGGEREXISTENCESTARTUP:
264 entry->mteTExStartup = request->requestvb->val.string[0];
265 break;
266 case COLUMN_MTETRIGGEREXISTENCEOBJECTSOWNER:
267 memset(entry->mteTExObjOwner, 0, sizeof(entry->mteTExObjOwner));
268 memcpy(entry->mteTExObjOwner, request->requestvb->val.string,
269 request->requestvb->val_len);
270 break;
271 case COLUMN_MTETRIGGEREXISTENCEOBJECTS:
272 memset(entry->mteTExObjects, 0, sizeof(entry->mteTExObjects));
273 memcpy(entry->mteTExObjects, request->requestvb->val.string,
274 request->requestvb->val_len);
275 break;
276 case COLUMN_MTETRIGGEREXISTENCEEVENTOWNER:
277 memset(entry->mteTExEvOwner, 0, sizeof(entry->mteTExEvOwner));
278 memcpy(entry->mteTExEvOwner, request->requestvb->val.string,
279 request->requestvb->val_len);
280 break;
281 case COLUMN_MTETRIGGEREXISTENCEEVENT:
282 memset(entry->mteTExEvent, 0, sizeof(entry->mteTExEvent));
283 memcpy(entry->mteTExEvent, request->requestvb->val.string,
284 request->requestvb->val_len);
285 break;
286 }
287 }
288 break;
289 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
290 }
291 return SNMP_ERR_NOERROR;
292 }