Debian Codegraph @

agent/mibgroup/disman/mteObjectsTable.c

raw
1 /*
2 * This file was generated by mib2c and is intended for use as
3 * a mib module for the ucd-snmp snmpd agent.
4 */
5
6
7 /*
8 * This should always be included first before anything else
9 */
10 #include <net-snmp/net-snmp-config.h>
11 #include <net-snmp/net-snmp-features.h>
12 #ifdef HAVE_STDLIB_H
13 #include <stdlib.h>
14 #endif
15 #ifdef HAVE_STRING_H
16 #include <string.h>
17 #else
18 #include <strings.h>
19 #endif
20
21 #ifndef NETSNMP_NO_WRITE_SUPPORT
22 netsnmp_feature_require(header_complex_find_entry);
23 #endif /* NETSNMP_NO_WRITE_SUPPORT */
24
25 /*
26 * minimal include directives
27 */
28 #include <net-snmp/net-snmp-includes.h>
29 #include <net-snmp/agent/net-snmp-agent-includes.h>
30
31 #include "header_complex.h"
32 #include "mteTriggerTable.h"
33 #include "mteObjectsTable.h"
34
35
36 /*
37 * mteObjectsTable_variables_oid:
38 * this is the top level oid that we want to register under. This
39 * is essentially a prefix, with the suffix appearing in the
40 * variable below.
41 */
42
43
44 oid mteObjectsTable_variables_oid[] =
45 { 1, 3, 6, 1, 2, 1, 88, 1, 3, 1 };
46
47
48 /*
49 * variable2 mteObjectsTable_variables:
50 * this variable defines function callbacks and type return information
51 * for the mteObjectsTable mib section
52 */
53
54
55 #ifndef NETSNMP_NO_WRITE_SUPPORT
56 struct variable2 mteObjectsTable_variables[] = {
57 /*
58 * magic number , variable type , ro/rw , callback fn , L, oidsuffix
59 */
60 #define MTEOBJECTSID 5
61 {MTEOBJECTSID, ASN_OBJECT_ID, NETSNMP_OLDAPI_RWRITE,
62 var_mteObjectsTable, 2, {1, 3}},
63 #define MTEOBJECTSIDWILDCARD 6
64 {MTEOBJECTSIDWILDCARD, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
65 var_mteObjectsTable, 2, {1, 4}},
66 #define MTEOBJECTSENTRYSTATUS 7
67 {MTEOBJECTSENTRYSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
68 var_mteObjectsTable, 2, {1, 5}},
69
70 };
71 #else /* !NETSNMP_NO_WRITE_SUPPORT */
72 struct variable2 mteObjectsTable_variables[] = {
73 /*
74 * magic number , variable type , ro/rw , callback fn , L, oidsuffix
75 */
76 #define MTEOBJECTSID 5
77 {MTEOBJECTSID, ASN_OBJECT_ID, NETSNMP_OLDAPI_RONLY,
78 var_mteObjectsTable, 2, {1, 3}},
79 #define MTEOBJECTSIDWILDCARD 6
80 {MTEOBJECTSIDWILDCARD, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
81 var_mteObjectsTable, 2, {1, 4}},
82 #define MTEOBJECTSENTRYSTATUS 7
83 {MTEOBJECTSENTRYSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
84 var_mteObjectsTable, 2, {1, 5}},
85
86 };
87 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
88
89 /*
90 * (L = length of the oidsuffix)
91 */
92
93
94 /*
95 * global storage of our data, saved in and configured by header_complex()
96 */
97 static struct header_complex_index *mteObjectsTableStorage = NULL;
98
99
100
101
102 /*
103 * init_mteObjectsTable():
104 * Initialization routine. This is called when the agent starts up.
105 * At a minimum, registration of your variables should take place here.
106 */
107 void
108 init_mteObjectsTable(void)
109 {
110 DEBUGMSGTL(("mteObjectsTable", "initializing... "));
111
112
113 /*
114 * register ourselves with the agent to handle our mib tree
115 */
116 REGISTER_MIB("mteObjectsTable", mteObjectsTable_variables, variable2,
117 mteObjectsTable_variables_oid);
118
119
120 /*
121 * register our config handler(s) to deal with registrations
122 */
123 snmpd_register_config_handler("mteObjectsTable", parse_mteObjectsTable,
124 NULL, NULL);
125
126
127 /*
128 * we need to be called back later to store our data
129 */
130 snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
131 store_mteObjectsTable, NULL);
132
133
134 /*
135 * place any other initialization junk you need here
136 */
137
138
139 DEBUGMSGTL(("mteObjectsTable", "done.\n"));
140 }
141
142
143 /*
144 * mteObjectsTable_add(): adds a structure node to our data set
145 */
146 int
147 mteObjectsTable_add(struct mteObjectsTable_data *thedata)
148 {
149 netsnmp_variable_list *vars = NULL;
150
151
152 DEBUGMSGTL(("mteObjectsTable", "adding data... "));
153 /*
154 * add the index variables to the varbind list, which is
155 * used by header_complex to index the data
156 */
157
158
159 snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->mteOwner, thedata->mteOwnerLen); /* mteOwner */
160 snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->mteObjectsName, thedata->mteObjectsNameLen); /* mteObjectsName */
161 snmp_varlist_add_variable(&vars, NULL, 0, ASN_UNSIGNED, (char *) &thedata->mteObjectsIndex, sizeof(thedata->mteObjectsIndex)); /* mteObjectsIndex */
162
163
164
165 header_complex_add_data(&mteObjectsTableStorage, vars, thedata);
166 DEBUGMSGTL(("mteObjectsTable", "registered an entry\n"));
167
168
169 DEBUGMSGTL(("mteObjectsTable", "done.\n"));
170 return SNMPERR_SUCCESS;
171 }
172
173
174 /*
175 * parse_mteObjectsTable():
176 * parses .conf file entries needed to configure the mib.
177 */
178 void
179 parse_mteObjectsTable(const char *token, char *line)
180 {
181 size_t tmpint;
182 struct mteObjectsTable_data *StorageTmp =
183 SNMP_MALLOC_STRUCT(mteObjectsTable_data);
184
185 DEBUGMSGTL(("mteObjectsTable", "parsing config... "));
186
187
188 if (StorageTmp == NULL) {
189 config_perror("malloc failure");
190 return;
191 }
192
193
194 line =
195 read_config_read_data(ASN_OCTET_STR, line, &StorageTmp->mteOwner,
196 &StorageTmp->mteOwnerLen);
197 if (StorageTmp->mteOwner == NULL) {
198 config_perror("invalid specification for mteOwner");
199 return;
200 }
201
202 line =
203 read_config_read_data(ASN_OCTET_STR, line,
204 &StorageTmp->mteObjectsName,
205 &StorageTmp->mteObjectsNameLen);
206 if (StorageTmp->mteObjectsName == NULL) {
207 config_perror("invalid specification for mteObjectsName");
208 return;
209 }
210
211 line =
212 read_config_read_data(ASN_UNSIGNED, line,
213 &StorageTmp->mteObjectsIndex, &tmpint);
214
215 line =
216 read_config_read_data(ASN_OBJECT_ID, line,
217 &StorageTmp->mteObjectsID,
218 &StorageTmp->mteObjectsIDLen);
219 if (StorageTmp->mteObjectsID == NULL) {
220 config_perror("invalid specification for mteObjectsID");
221 return;
222 }
223
224 line =
225 read_config_read_data(ASN_INTEGER, line,
226 &StorageTmp->mteObjectsIDWildcard, &tmpint);
227
228 line =
229 read_config_read_data(ASN_INTEGER, line,
230 &StorageTmp->mteObjectsEntryStatus, &tmpint);
231
232
233
234
235 mteObjectsTable_add(StorageTmp);
236
237
238 DEBUGMSGTL(("mteObjectsTable", "done.\n"));
239 }
240
241
242
243
244 /*
245 * store_mteObjectsTable():
246 * stores .conf file entries needed to configure the mib.
247 */
248 int
249 store_mteObjectsTable(int majorID, int minorID, void *serverarg,
250 void *clientarg)
251 {
252 char line[SNMP_MAXBUF];
253 char *cptr;
254 size_t tmpint;
255 struct mteObjectsTable_data *StorageTmp;
256 struct header_complex_index *hcindex;
257
258
259 DEBUGMSGTL(("mteObjectsTable", "storing data... "));
260
261
262 for (hcindex = mteObjectsTableStorage; hcindex != NULL;
263 hcindex = hcindex->next) {
264 StorageTmp = (struct mteObjectsTable_data *) hcindex->data;
265
266 if (StorageTmp->storagetype != ST_READONLY) {
267 memset(line, 0, sizeof(line));
268 strcat(line, "mteObjectsTable ");
269 cptr = line + strlen(line);
270
271
272 cptr =
273 read_config_store_data(ASN_OCTET_STR, cptr,
274 &StorageTmp->mteOwner,
275 &StorageTmp->mteOwnerLen);
276 cptr =
277 read_config_store_data(ASN_OCTET_STR, cptr,
278 &StorageTmp->mteObjectsName,
279 &StorageTmp->mteObjectsNameLen);
280 cptr =
281 read_config_store_data(ASN_UNSIGNED, cptr,
282 &StorageTmp->mteObjectsIndex,
283 &tmpint);
284 cptr =
285 read_config_store_data(ASN_OBJECT_ID, cptr,
286 &StorageTmp->mteObjectsID,
287 &StorageTmp->mteObjectsIDLen);
288 cptr =
289 read_config_store_data(ASN_INTEGER, cptr,
290 &StorageTmp->mteObjectsIDWildcard,
291 &tmpint);
292 cptr =
293 read_config_store_data(ASN_INTEGER, cptr,
294 &StorageTmp->mteObjectsEntryStatus,
295 &tmpint);
296
297
298
299 snmpd_store_config(line);
300 }
301 }
302 DEBUGMSGTL(("mteObjectsTable", "done.\n"));
303 return SNMPERR_SUCCESS;
304 }
305
306
307
308
309 /*
310 * var_mteObjectsTable():
311 * Handle this table separately from the scalar value case.
312 * The workings of this are basically the same as for var_mteObjectsTable above.
313 */
314 unsigned char *
315 var_mteObjectsTable(struct variable *vp,
316 oid * name,
317 size_t * length,
318 int exact,
319 size_t * var_len, WriteMethod ** write_method)
320 {
321
322
323 struct mteObjectsTable_data *StorageTmp = NULL;
324
325
326 DEBUGMSGTL(("mteObjectsTable",
327 "var_mteObjectsTable: Entering... \n"));
328
329 /* set default value */
330 *write_method = NULL;
331
332 /*
333 * this assumes you have registered all your data properly
334 */
335 if ((StorageTmp =
336 header_complex(mteObjectsTableStorage, vp, name, length, exact,
337 var_len, write_method)) == NULL) {
338 if (vp->magic == MTEOBJECTSENTRYSTATUS)
339 *write_method = write_mteObjectsEntryStatus;
340 return NULL;
341 }
342
343 /*
344 * this is where we do the value assignments for the mib results.
345 */
346 switch (vp->magic) {
347
348
349 case MTEOBJECTSID:
350 #ifndef NETSNMP_NO_WRITE_SUPPORT
351 *write_method = write_mteObjectsID;
352 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
353 *var_len = (StorageTmp->mteObjectsIDLen) * sizeof(oid);
354 return (u_char *) StorageTmp->mteObjectsID;
355
356 case MTEOBJECTSIDWILDCARD:
357 #ifndef NETSNMP_NO_WRITE_SUPPORT
358 *write_method = write_mteObjectsIDWildcard;
359 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
360 *var_len = sizeof(StorageTmp->mteObjectsIDWildcard);
361 return (u_char *) & StorageTmp->mteObjectsIDWildcard;
362
363 case MTEOBJECTSENTRYSTATUS:
364 #ifndef NETSNMP_NO_WRITE_SUPPORT
365 *write_method = write_mteObjectsEntryStatus;
366 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
367 *var_len = sizeof(StorageTmp->mteObjectsEntryStatus);
368 return (u_char *) & StorageTmp->mteObjectsEntryStatus;
369
370
371 default:
372 ERROR_MSG("");
373 }
374 return NULL;
375 }
376
377
378
379 #ifndef NETSNMP_NO_WRITE_SUPPORT
380
381 int
382 write_mteObjectsID(int action,
383 u_char * var_val,
384 u_char var_val_type,
385 size_t var_val_len,
386 u_char * statP, oid * name, size_t name_len)
387 {
388 static oid *tmpvar;
389 struct mteObjectsTable_data *StorageTmp = NULL;
390 static size_t tmplen;
391 size_t newlen =
392 name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
393 3 - 1);
394
395
396 DEBUGMSGTL(("mteObjectsTable",
397 "write_mteObjectsID entering action=%d... \n", action));
398 if ((StorageTmp =
399 header_complex(mteObjectsTableStorage, NULL,
400 &name[sizeof(mteObjectsTable_variables_oid) /
401 sizeof(oid) + 3 - 1], &newlen, 1, NULL,
402 NULL)) == NULL)
403 return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
404
405 if (StorageTmp && StorageTmp->storagetype == ST_READONLY) {
406 return SNMP_ERR_NOTWRITABLE;
407 }
408
409 switch (action) {
410 case RESERVE1:
411 if (var_val_type != ASN_OBJECT_ID) {
412 snmp_log(LOG_ERR, "write to mteObjectsID not ASN_OBJECT_ID\n");
413 return SNMP_ERR_WRONGTYPE;
414 }
415 break;
416
417
418 case RESERVE2:
419 /*
420 * memory reseveration, final preparation...
421 */
422 break;
423
424
425 case FREE:
426 /*
427 * Release any resources that have been allocated
428 */
429 break;
430
431
432 case ACTION:
433 /*
434 * The variable has been stored in objid for
435 * you to use, and you have just been asked to do something with
436 * it. Note that anything done here must be reversable in the UNDO case
437 */
438 tmpvar = StorageTmp->mteObjectsID;
439 tmplen = StorageTmp->mteObjectsIDLen;
440 StorageTmp->mteObjectsID = netsnmp_memdup(var_val, var_val_len);
441 StorageTmp->mteObjectsIDLen = var_val_len / sizeof(oid);
442 break;
443
444
445 case UNDO:
446 /*
447 * Back out any changes made in the ACTION case
448 */
449 SNMP_FREE(StorageTmp->mteObjectsID);
450 StorageTmp->mteObjectsID = tmpvar;
451 StorageTmp->mteObjectsIDLen = tmplen;
452 break;
453
454
455 case COMMIT:
456 /*
457 * Things are working well, so it's now safe to make the change
458 * permanently. Make sure that anything done here can't fail!
459 */
460 SNMP_FREE(tmpvar);
461
462 snmp_store_needed(NULL);
463
464 break;
465 }
466 return SNMP_ERR_NOERROR;
467 }
468
469
470
471 int
472 write_mteObjectsIDWildcard(int action,
473 u_char * var_val,
474 u_char var_val_type,
475 size_t var_val_len,
476 u_char * statP, oid * name, size_t name_len)
477 {
478 static int tmpvar;
479 struct mteObjectsTable_data *StorageTmp = NULL;
480 size_t newlen =
481 name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
482 3 - 1);
483
484
485 DEBUGMSGTL(("mteObjectsTable",
486 "write_mteObjectsIDWildcard entering action=%d... \n",
487 action));
488 if ((StorageTmp =
489 header_complex(mteObjectsTableStorage, NULL,
490 &name[sizeof(mteObjectsTable_variables_oid) /
491 sizeof(oid) + 3 - 1], &newlen, 1, NULL,
492 NULL)) == NULL)
493 return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
494
495 if (StorageTmp && StorageTmp->storagetype == ST_READONLY) {
496 return SNMP_ERR_NOTWRITABLE;
497 }
498
499 switch (action) {
500 case RESERVE1:
501 if (var_val_type != ASN_INTEGER) {
502 snmp_log(LOG_ERR,
503 "write to mteObjectsIDWildcard not ASN_INTEGER\n");
504 return SNMP_ERR_WRONGTYPE;
505 }
506 break;
507
508
509 case RESERVE2:
510 /*
511 * memory reseveration, final preparation...
512 */
513 break;
514
515
516 case FREE:
517 /*
518 * Release any resources that have been allocated
519 */
520 break;
521
522
523 case ACTION:
524 /*
525 * The variable has been stored in long_ret for
526 * you to use, and you have just been asked to do something with
527 * it. Note that anything done here must be reversable in the UNDO case
528 */
529 tmpvar = StorageTmp->mteObjectsIDWildcard;
530 StorageTmp->mteObjectsIDWildcard = *((long *) var_val);
531 break;
532
533
534 case UNDO:
535 /*
536 * Back out any changes made in the ACTION case
537 */
538 StorageTmp->mteObjectsIDWildcard = tmpvar;
539 break;
540
541
542 case COMMIT:
543 /*
544 * Things are working well, so it's now safe to make the change
545 * permanently. Make sure that anything done here can't fail!
546 */
547
548 snmp_store_needed(NULL);
549
550 break;
551 }
552 return SNMP_ERR_NOERROR;
553 }
554
555
556
557
558
559
560 int
561 write_mteObjectsEntryStatus(int action,
562 u_char * var_val,
563 u_char var_val_type,
564 size_t var_val_len,
565 u_char * statP, oid * name, size_t name_len)
566 {
567 struct mteObjectsTable_data *StorageTmp = NULL;
568 static struct mteObjectsTable_data *StorageNew, *StorageDel;
569 size_t newlen =
570 name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
571 3 - 1);
572 static int old_value;
573 int set_value;
574 static netsnmp_variable_list *vars, *vp;
575 struct header_complex_index *hciptr;
576
577
578 StorageTmp =
579 header_complex(mteObjectsTableStorage, NULL,
580 &name[sizeof(mteObjectsTable_variables_oid) /
581 sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL);
582
583 if (var_val_type != ASN_INTEGER || var_val == NULL) {
584 snmp_log(LOG_ERR,
585 "write to mteObjectsEntryStatus not ASN_INTEGER\n");
586 return SNMP_ERR_WRONGTYPE;
587 }
588
589 if (StorageTmp && StorageTmp->storagetype == ST_READONLY) {
590 return SNMP_ERR_NOTWRITABLE;
591 }
592
593 set_value = *((long *) var_val);
594
595
596 /*
597 * check legal range, and notReady is reserved for us, not a user
598 */
599 if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY)
600 return SNMP_ERR_INCONSISTENTVALUE;
601
602
603 switch (action) {
604 case RESERVE1:
605 /*
606 * stage one: test validity
607 */
608 if (StorageTmp == NULL) {
609 /*
610 * create the row now?
611 */
612
613
614 /*
615 * ditch illegal values now
616 */
617 if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE)
618 return SNMP_ERR_INCONSISTENTVALUE;
619
620
621 /*
622 * destroying a non-existent row is actually legal
623 */
624 if (set_value == RS_DESTROY) {
625 return SNMP_ERR_NOERROR;
626 }
627
628
629 /*
630 * illegal creation values
631 */
632 if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) {
633 return SNMP_ERR_INCONSISTENTVALUE;
634 }
635 } else {
636 /*
637 * row exists. Check for a valid state change
638 */
639 if (set_value == RS_CREATEANDGO
640 || set_value == RS_CREATEANDWAIT) {
641 /*
642 * can't create a row that exists
643 */
644 return SNMP_ERR_INCONSISTENTVALUE;
645 }
646 /*
647 * XXX: interaction with row storage type needed
648 */
649 }
650 break;
651
652
653
654
655 case RESERVE2:
656 /*
657 * memory reseveration, final preparation...
658 */
659 if (StorageTmp == NULL) {
660 /*
661 * creation
662 */
663 vars = NULL;
664
665
666 snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* mteOwner */
667 snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* mteObjectsName */
668 snmp_varlist_add_variable(&vars, NULL, 0, ASN_UNSIGNED, NULL, 0); /* mteObjectsIndex */
669
670 if (header_complex_parse_oid
671 (&
672 (name
673 [sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
674 2]), newlen, vars) != SNMPERR_SUCCESS) {
675 /*
676 * XXX: free, zero vars
677 */
678 return SNMP_ERR_INCONSISTENTNAME;
679 }
680 vp = vars;
681
682
683 StorageNew = SNMP_MALLOC_STRUCT(mteObjectsTable_data);
684 if (StorageNew == NULL)
685 return SNMP_ERR_GENERR;
686 StorageNew->mteOwner = netsnmp_strdup_and_null(vp->val.string,
687 vp->val_len);
688 StorageNew->mteOwnerLen = vp->val_len;
689 vp = vp->next_variable;
690 StorageNew->mteObjectsName =
691 netsnmp_strdup_and_null(vp->val.string,
692 vp->val_len);
693 StorageNew->mteObjectsNameLen = vp->val_len;
694 vp = vp->next_variable;
695 StorageNew->mteObjectsIndex = *(vp->val.integer);
696
697 /*
698 * XXX: fill in default row values here into StorageNew
699 */
700 StorageNew->mteObjectsID = calloc(1, sizeof(oid) * sizeof(2)); /* 0.0 */
701 StorageNew->mteObjectsIDLen = 2;
702 StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_FALSE;
703
704 StorageNew->mteObjectsEntryStatus = set_value;
705 /*
706 * XXX: free, zero vars, no longer needed?
707 */
708 }
709
710
711 break;
712
713
714
715
716 case FREE:
717 /*
718 * XXX: free, zero vars
719 */
720 /*
721 * Release any resources that have been allocated
722 */
723 break;
724
725
726
727
728 case ACTION:
729 /*
730 * The variable has been stored in set_value for you to
731 * use, and you have just been asked to do something with
732 * it. Note that anything done here must be reversable in
733 * the UNDO case
734 */
735
736
737 if (StorageTmp == NULL) {
738 /*
739 * row creation, so add it
740 */
741 if (StorageNew != NULL)
742 mteObjectsTable_add(StorageNew);
743 /*
744 * XXX: ack, and if it is NULL?
745 */
746 } else if (set_value != RS_DESTROY) {
747 /*
748 * set the flag?
749 */
750 old_value = StorageTmp->mteObjectsEntryStatus;
751 StorageTmp->mteObjectsEntryStatus = *((long *) var_val);
752 } else {
753 /*
754 * destroy... extract it for now
755 */
756 hciptr =
757 header_complex_find_entry(mteObjectsTableStorage,
758 StorageTmp);
759 StorageDel =
760 header_complex_extract_entry(&mteObjectsTableStorage,
761 hciptr);
762 }
763 break;
764
765
766
767
768 case UNDO:
769 /*
770 * Back out any changes made in the ACTION case
771 */
772 if (StorageTmp == NULL) {
773 /*
774 * row creation, so remove it again
775 */
776 hciptr =
777 header_complex_find_entry(mteObjectsTableStorage,
778 StorageTmp);
779 StorageDel =
780 header_complex_extract_entry(&mteObjectsTableStorage,
781 hciptr);
782 /*
783 * XXX: free it
784 */
785 } else if (StorageDel != NULL) {
786 /*
787 * row deletion, so add it again
788 */
789 mteObjectsTable_add(StorageDel);
790 } else {
791 StorageTmp->mteObjectsEntryStatus = old_value;
792 }
793 break;
794
795
796
797
798 case COMMIT:
799 /*
800 * Things are working well, so it's now safe to make the change
801 * permanently. Make sure that anything done here can't fail!
802 */
803 if (StorageDel != NULL) {
804 StorageDel = NULL;
805 /*
806 * XXX: free it, its dead
807 */
808 } else {
809 if (StorageTmp
810 && StorageTmp->mteObjectsEntryStatus == RS_CREATEANDGO) {
811 StorageTmp->mteObjectsEntryStatus = RS_ACTIVE;
812 } else if (StorageTmp &&
813 StorageTmp->mteObjectsEntryStatus ==
814 RS_CREATEANDWAIT) {
815 StorageTmp->mteObjectsEntryStatus = RS_NOTINSERVICE;
816 }
817 }
818 snmp_store_needed(NULL);
819
820 break;
821 }
822 return SNMP_ERR_NOERROR;
823 }
824
825 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
826
827
828 void
829 mte_add_objects(netsnmp_variable_list * vars,
830 struct mteTriggerTable_data *item, const char *owner,
831 const char *name, oid * suffix, size_t suffix_len)
832 {
833 struct header_complex_index *hcptr = mteObjectsTableStorage;
834
835 DEBUGMSGTL(("mteObjectsTable",
836 "Searching for objects to add for owner=%s / name=%s\n",
837 owner, name));
838
839 if (vars == NULL || item == NULL || owner == NULL || name == NULL ||
840 hcptr == NULL)
841 return;
842
843 /*
844 * get to end of variable chain
845 */
846 while (vars->next_variable != NULL)
847 vars = vars->next_variable;
848
849
850 /*
851 * get to start of objects list
852 */
853 while (hcptr &&
854 (strcmp(((struct mteObjectsTable_data *) hcptr->data)->mteOwner,
855 owner) != 0 ||
856 strcmp(((struct mteObjectsTable_data *) hcptr->data)->
857 mteObjectsName, name) != 0))
858 hcptr = hcptr->next;
859
860 /*
861 * add all objects
862 */
863 while (hcptr &&
864 strcmp(((struct mteObjectsTable_data *) hcptr->data)->mteOwner,
865 owner) == 0 &&
866 strcmp(((struct mteObjectsTable_data *) hcptr->data)->
867 mteObjectsName, name) == 0) {
868 /*
869 * loop through objects
870 */
871 netsnmp_pdu *pdu = NULL, *response = NULL;
872 struct mteObjectsTable_data *node =
873 (struct mteObjectsTable_data *) hcptr->data;
874 oid theoid[MAX_OID_LEN];
875 size_t theoid_len;
876
877 /*
878 * copy in the suffix
879 */
880 memcpy(theoid, node->mteObjectsID,
881 node->mteObjectsIDLen * sizeof(oid));
882 theoid_len = node->mteObjectsIDLen;
883 if (node->mteObjectsIDWildcard == MTEOBJECTSIDWILDCARD_TRUE &&
884 suffix && suffix_len > 0) {
885 theoid_len += suffix_len;
886 if (theoid_len > MAX_OID_LEN) {
887 break; /* XXX: properly send trap or something? */
888 }
889
890 memcpy(&theoid[node->mteObjectsIDLen], suffix,
891 suffix_len * sizeof(oid));
892 }
893
894 /*
895 * retrieve the value
896 */
897 pdu = snmp_pdu_create(SNMP_MSG_GET);
898 snmp_add_null_var(pdu, theoid, theoid_len);
899 response = mte_get_response(item, pdu);
900
901 if (response) {
902 if (vars) {
903 vars->next_variable = response->variables;
904 vars = vars->next_variable;
905 DEBUGMSGTL(("mteObjectsTable", "Adding: "));
906 DEBUGMSGOID(("mteObjectsTable", response->variables->name,
907 response->variables->name_length));
908 DEBUGMSG(("mteObjectsTable", "\n"));
909 } else {
910 vars = response->variables;
911 }
912 /*
913 * erase response notion of the values we stole from it
914 */
915 response->variables = NULL;
916 snmp_free_pdu(response);
917 }
918
919 /*
920 * move along
921 */
922 hcptr = hcptr->next;
923 }
924 DEBUGMSGTL(("mteObjectsTable", "Done adding objects\n"));
925 }
926
927 int
928 mte_add_object_to_table(const char *owner, const char *objname,
929 oid * oidname, size_t oidname_len, int iswild)
930 {
931 struct header_complex_index *hcptr = mteObjectsTableStorage, *lastnode;
932 static struct mteObjectsTable_data *StorageNew;
933
934 /*
935 * malloc initial struct
936 */
937 StorageNew = SNMP_MALLOC_STRUCT(mteObjectsTable_data);
938 if (StorageNew == NULL)
939 return SNMP_ERR_GENERR;
940 StorageNew->mteOwner = netsnmp_strdup_and_null(owner, strlen(owner));
941 StorageNew->mteOwnerLen = strlen(owner);
942 StorageNew->mteObjectsName = netsnmp_strdup_and_null(objname,
943 strlen(objname));
944 StorageNew->mteObjectsNameLen = strlen(objname);
945
946 /*
947 * find the next number
948 */
949 /*
950 * get to start of objects list
951 */
952 while (hcptr &&
953 (strcmp(((struct mteObjectsTable_data *) hcptr->data)->mteOwner,
954 owner) != 0 ||
955 strcmp(((struct mteObjectsTable_data *) hcptr->data)->
956 mteObjectsName, objname) != 0))
957 hcptr = hcptr->next;
958
959 if (hcptr) {
960 /*
961 * an object existed. Find the first one past and increment
962 * the previous number
963 */
964 lastnode = hcptr;
965 while (hcptr &&
966 strcmp(((struct mteObjectsTable_data *) hcptr->data)->
967 mteOwner, owner) == 0
968 && strcmp(((struct mteObjectsTable_data *) hcptr->data)->
969 mteObjectsName, objname) == 0) {
970 lastnode = hcptr;
971 hcptr = hcptr->next;
972 }
973 StorageNew->mteObjectsIndex =
974 ((struct mteObjectsTable_data *) lastnode->data)->
975 mteObjectsIndex + 1;
976 } else {
977 StorageNew->mteObjectsIndex = 1;
978 }
979
980 /*
981 * XXX: fill in default row values here into StorageNew
982 */
983 StorageNew->mteObjectsID = snmp_duplicate_objid(oidname, oidname_len);
984 StorageNew->mteObjectsIDLen = oidname_len;
985
986 if (iswild)
987 StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_TRUE;
988 else
989 StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_FALSE;
990
991 StorageNew->mteObjectsEntryStatus = RS_ACTIVE;
992 StorageNew->storagetype = ST_READONLY;
993 return mteObjectsTable_add(StorageNew);
994 }