Debian Codegraph @

agent/mibgroup/notification/snmpNotifyTable_data.c

raw
1 /*
2 * This file was created to separate data storage from MIB implementation.
3 *
4 * Portions of this file are copyrighted by:
5 * Copyright (c) 2016 VMware, Inc. All rights reserved.
6 * Use is subject to license terms specified in the COPYING file
7 * distributed with the Net-SNMP package.
8 */
9
10
11 /*
12 * This should always be included first before anything else
13 */
14 #include <net-snmp/net-snmp-config.h>
15 #include <net-snmp/net-snmp-features.h>
16
17 #include <sys/types.h>
18 #ifdef HAVE_STDLIB_H
19 #include <stdlib.h>
20 #endif
21 #ifdef HAVE_STRING_H
22 #include <string.h>
23 #else
24 #include <strings.h>
25 #endif
26
27 /*
28 * minimal include directives
29 */
30 #include <net-snmp/net-snmp-includes.h>
31 #include <net-snmp/agent/net-snmp-agent-includes.h>
32
33 #include "agent_global_vars.h"
34 #include "header_complex.h"
35 #include "snmpNotifyTable_data.h"
36 #include "notification/snmpNotifyFilterProfileTable_data.h"
37 #include "target/snmpTargetParamsEntry_data.h"
38 #include "target/snmpTargetAddrEntry_data.h"
39 #include "target/target.h"
40 #include "agentx/subagent.h"
41 #include "snmp-notification-mib/snmpNotifyFilterTable/snmpNotifyFilterTable_data_storage.h"
42 #include <net-snmp/agent/agent_callbacks.h>
43 #include <net-snmp/agent/agent_trap.h>
44 #include <net-snmp/agent/mib_module_config.h>
45 #include "net-snmp/agent/sysORTable.h"
46
47 #ifdef USING_NOTIFICATION_LOG_MIB_NOTIFICATION_LOG_MODULE
48 # include "notification-log-mib/notification_log.h"
49 #endif
50
51 SNMPCallback store_snmpNotifyTable;
52
53 static int
54 _unregister_notification_cb(int major, int minor,
55 void *serverarg, void *clientarg);
56
57 /*
58 * global storage of our data, saved in and configured by header_complex()
59 */
60 static struct header_complex_index *snmpNotifyTableStorage = NULL;
61 static int _active = 0;
62
63 static int
64 _checkFilter(const char* paramName, netsnmp_pdu *pdu)
65 {
66 /*
67 * find appropriate filterProfileEntry
68 */
69 netsnmp_variable_list *var, *trap_var = NULL;
70 char *profileName;
71 size_t profileNameLen;
72 struct vacm_viewEntry *vp, *head;
73 int vb_oid_excluded = 0, free_trapvar = 0;
74
75 netsnmp_assert(NULL != paramName);
76 netsnmp_assert(NULL != pdu);
77
78 DEBUGMSGTL(("send_notifications", "checking filters for '%s'...\n",
79 paramName));
80
81 /*
82 A notification originator uses the snmpNotifyFilterTable to filter
83 notifications. A notification filter profile may be associated with
84 a particular entry in the snmpTargetParamsTable. The associated
85 filter profile is identified by an entry in the
86 snmpNotifyFilterProfileTable whose index is equal to the index of the
87 entry in the snmpTargetParamsTable. If no such entry exists in the
88 snmpNotifyFilterProfileTable, no filtering is performed for that
89 management target.
90 */
91 /** xxx paramName from session doesn't have length. will be
92 * trouble with paramNames with embedded NULL */
93 profileName = get_FilterProfileName(paramName, strlen(paramName),
94 &profileNameLen);
95 if (NULL == profileName) /* try default */
96 profileName = get_FilterProfileName("default", 7, &profileNameLen);
97 if (NULL == profileName) {
98 DEBUGMSGTL(("send_notifications", " no matching profile\n"));
99 return 0;
100 }
101
102 /*
103 If such an entry does exist, the value of snmpNotifyFilterProfileName
104 of the entry is compared with the corresponding portion of the index
105 of all active entries in the snmpNotifyFilterTable. All such entries
106 for which this comparison results in an exact match are used for
107 filtering a notification generated using the associated
108 snmpTargetParamsEntry. If no such entries exist, no filtering is
109 performed, and a notification may be sent to the management target.
110 */
111 head = snmpNotifyFilter_vacm_view_subtree(profileName);
112 if (NULL == head) {
113 DEBUGMSGTL(("send_notifications", " no matching filters\n"));
114 return 0;
115 }
116
117 /*
118 Otherwise, if matching entries do exist, a notification may be sent
119 if the NOTIFICATION-TYPE OBJECT IDENTIFIER of the notification (this
120 is the value of the element of the variable bindings whose name is
121 snmpTrapOID.0, i.e., the second variable binding) is specifically
122 included, and none of the object instances to be included in the
123 variable-bindings of the notification are specifically excluded by
124 the matching entries.
125 */
126 if (NULL != pdu->variables) {
127 trap_var = find_varbind_in_list( pdu->variables,
128 snmptrap_oid, snmptrap_oid_len);
129 }
130 #if !defined(NETSNMP_DISABLE_SNMPV1)
131 else {
132 /** snmpv1 pdus have no varbinds. build trapoid */
133 oid enterprise[MAX_OID_LEN];
134 size_t enterprise_len;
135 enterprise_len = OID_LENGTH(enterprise);
136 if ((netsnmp_build_trap_oid(pdu, enterprise, &enterprise_len)
137 != SNMPERR_SUCCESS) ||
138 !snmp_varlist_add_variable(&trap_var, snmptrap_oid,
139 snmptrap_oid_len,
140 ASN_OBJECT_ID, (u_char*)enterprise,
141 enterprise_len*sizeof(oid))) {
142 snmp_log(LOG_WARNING,
143 "checkFilter: failed to build snmpTrapOID varbind\n");
144 } else
145 free_trapvar = 1;
146 }
147 #endif /* NETSNMP_DISABLE_SNMPV1 */
148
149 if (NULL != trap_var) {
150 /*
151 For a notification name, if none match,
152 then the notification name is considered excluded, and the
153 notification should not be sent to this management target.
154 */
155 vp = netsnmp_view_get(head, profileName, trap_var->val.objid,
156 trap_var->val_len / sizeof(oid), VACM_MODE_FIND);
157 if ((NULL == vp) || (SNMP_VIEW_INCLUDED != vp->viewType)) {
158 DEBUGMSGTL(("send_notifications", " filtered (snmpTrapOID.0 "));
159 DEBUGMSGOID(("send_notifications",trap_var->val.objid,
160 trap_var->val_len / sizeof(oid)));
161 DEBUGMSG(("send_notifications", " not included)\n"));
162 free(head);
163 if (free_trapvar)
164 snmp_free_varbind(trap_var);
165 return 1;
166 }
167 }
168 if (free_trapvar) {
169 snmp_free_varbind(trap_var);
170 trap_var = NULL;
171 }
172
173 /*
174 * check varbinds
175 */
176 for(var = pdu->variables; var; var = var->next_variable) {
177 /*
178 For an
179 object instance, if none match, the object instance is considered
180 included, and the notification may be sent to this management target.
181 */
182
183 if (var == trap_var) {
184 continue;
185 }
186
187 vp = netsnmp_view_get(head, profileName, var->name,
188 var->name_length, VACM_MODE_FIND);
189 if ((NULL != vp) && (SNMP_VIEW_EXCLUDED == vp->viewType)) {
190 DEBUGMSGTL(("send_notifications"," filtered (varbind "));
191 DEBUGMSGOID(("send_notifications",var->name, var->name_length));
192 DEBUGMSG(("send_notifications", " excluded)\n"));
193 vb_oid_excluded = 1;
194 break;
195 }
196 }
197
198 free(head);
199
200 return vb_oid_excluded;
201 }
202
203 int
204 send_notifications(int major, int minor, void *serverarg, void *clientarg)
205 {
206 struct header_complex_index *hptr;
207 struct snmpNotifyTable_data *nptr;
208 netsnmp_session *sess, *sptr;
209 netsnmp_pdu *template_pdu = (netsnmp_pdu *) serverarg;
210 int count = 0;
211
212 DEBUGMSGTL(("send_notifications", "starting: pdu=%p, vars=%p\n",
213 template_pdu, template_pdu->variables));
214
215 for (hptr = snmpNotifyTableStorage; hptr; hptr = hptr->next) {
216 nptr = (struct snmpNotifyTable_data *) hptr->data;
217 if (nptr->snmpNotifyRowStatus != RS_ACTIVE)
218 continue;
219 if (!nptr->snmpNotifyTag)
220 continue;
221
222 sess = get_target_sessions(nptr->snmpNotifyTag, NULL, NULL);
223
224 /*
225 * filter appropriately, per section 6 of RFC 3413
226 */
227
228 for (sptr = sess; sptr; sptr = sptr->next) {
229 #ifndef NETSNMP_DISABLE_SNMPV1
230 if (sptr->version == SNMP_VERSION_1 &&
231 minor != SNMPD_CALLBACK_SEND_TRAP1) {
232 continue;
233 } else
234 #endif
235 if (sptr->version == SNMP_VERSION_3
236 #ifndef NETSNMP_DISABLE_SNMPV2C
237 || sptr->version == SNMP_VERSION_2c
238 #endif
239 ) {
240 if(minor != SNMPD_CALLBACK_SEND_TRAP2)
241 continue;
242 if (nptr->snmpNotifyType == SNMPNOTIFYTYPE_INFORM) {
243 template_pdu->command = SNMP_MSG_INFORM;
244 } else {
245 template_pdu->command = SNMP_MSG_TRAP2;
246 }
247 }
248 if (sess->paramName) {
249 int filter = _checkFilter(sess->paramName, template_pdu);
250 if (filter)
251 continue;
252 }
253 send_trap_to_sess(sptr, template_pdu);
254 ++count;
255 } /* for(sptr) */
256 } /* for(hptr) */
257
258 DEBUGMSGTL(("send_notifications", "sent %d notifications\n", count));
259
260 #ifdef USING_NOTIFICATION_LOG_MIB_NOTIFICATION_LOG_MODULE
261 if (count)
262 log_notification(template_pdu, NULL);
263 #endif
264
265 return 0;
266 }
267
268 #define MAX_ENTRIES 1024
269
270 int
271 notifyTable_register_notifications(int major, int minor,
272 void *serverarg, void *clientarg)
273 {
274 struct targetAddrTable_struct *ptr = NULL;
275 struct targetParamTable_struct *pptr = NULL;
276 struct snmpNotifyTable_data *nptr = NULL;
277 int confirm, close_sess, i;
278 char buf[SNMP_MAXBUF_SMALL];
279 netsnmp_transport *t = NULL;
280 struct agent_add_trap_args *args =
281 (struct agent_add_trap_args *) serverarg;
282 netsnmp_session *ss;
283 const char *name, *tag, *notifyProfile;
284 int nameLen, tagLen, notifyProfileLen;
285
286 if (!args || !(args->ss)) {
287 return (0);
288 }
289 args->rc = SNMPERR_GENERR;
290 confirm = args->confirm;
291 ss = args->ss;
292 close_sess = args->close_sess;
293 name = args->nameData;
294 nameLen = args->nameLen;
295 tag = args->tagData;
296 tagLen = args->tagLen;
297 notifyProfile = args->profileData;
298 notifyProfileLen = args->profileLen;
299
300 /*
301 * XXX: START move target creation to target code
302 */
303 if (NULL == name) {
304 int len;
305 for (i = 0; i < MAX_ENTRIES; i++) {
306 sprintf(buf, "internal%d", i);
307 len = strlen(buf);
308 if ((get_addrForName2(buf,len) == NULL) &&
309 (get_paramEntry2(buf,len) == NULL))
310 break;
311 }
312 if (i == MAX_ENTRIES) {
313 snmp_log(LOG_ERR,
314 "Can't register new trap destination: max limit reached: %d",
315 MAX_ENTRIES);
316 snmp_close(ss);
317 return (0);
318 }
319 name = buf;
320 nameLen = len;
321 if (NULL == tag) {
322 tag = buf;
323 tagLen = len;
324 }
325 } else {
326 if (NULL == tag) {
327 tag = name;
328 tagLen = nameLen;
329 }
330 }
331
332 /*
333 * address
334 */
335 t = snmp_sess_transport(snmp_sess_pointer(ss));
336 if (!t) {
337 snmp_log(LOG_ERR,
338 "Cannot add new trap destination, transport is closed.");
339 snmp_close(ss);
340 return 0;
341 }
342 ptr = snmpTargetAddrTable_create();
343 if (!ptr)
344 goto bail;
345 ptr->nameData = netsnmp_memdup_nt(name, nameLen, &ptr->nameLen);
346 memcpy(ptr->tDomain, t->domain, t->domain_length * sizeof(oid));
347 ptr->tDomainLen = t->domain_length;
348 if (t->f_get_taddr)
349 t->f_get_taddr(t, &ptr->tAddress, &ptr->tAddressLen);
350 else
351 netsnmp_assert(0);
352
353 ptr->timeout = ss->timeout / 1000;
354 ptr->retryCount = ss->retries;
355 SNMP_FREE(ptr->tagListData);
356 ptr->tagListData = netsnmp_memdup_nt(tag, tagLen, &ptr->tagListLen);
357 /** link to target param table */
358 ptr->paramsData = netsnmp_memdup_nt(name, nameLen, &ptr->paramsLen);
359 if (!ptr->paramsData || !ptr->tagListData || !ptr->nameData)
360 goto bail;
361 ptr->storageType = ST_READONLY;
362 ptr->rowStatus = RS_ACTIVE;
363 ptr->sess = ss;
364 ptr->close_sess = close_sess;
365 DEBUGMSGTL(("trapsess", "adding %s to trap table\n", ptr->nameData));
366 snmpTargetAddrTable_add(ptr);
367
368 /*
369 * param
370 */
371 pptr = snmpTargetParamTable_create();
372 if (NULL == pptr)
373 goto bail;
374 /** link from target addr table */
375 pptr->paramNameData = netsnmp_memdup_nt(ptr->paramsData, ptr->paramsLen,
376 &pptr->paramNameLen);
377 if (!pptr->paramNameData)
378 goto bail;
379 pptr->mpModel = ss->version;
380 if (ss->version == SNMP_VERSION_3) {
381 pptr->secModel = ss->securityModel;
382 pptr->secLevel = ss->securityLevel;
383 if (!ss->securityName) {
384 snmp_log(LOG_ERR, "Security name is missing.");
385 goto bail;
386 }
387 pptr->secNameData = netsnmp_memdup_nt(ss->securityName,
388 ss->securityNameLen,
389 &pptr->secNameLen);
390 if (pptr->secNameData == NULL)
391 goto bail;
392 }
393 #if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C)
394 else {
395 pptr->secModel =
396 #ifndef NETSNMP_DISABLE_SNMPV1
397 ss->version == SNMP_VERSION_1 ? SNMP_SEC_MODEL_SNMPv1 :
398 #endif
399 SNMP_SEC_MODEL_SNMPv2c;
400 pptr->secLevel = SNMP_SEC_LEVEL_NOAUTH;
401 pptr->secNameData = NULL;
402 if (ss->community && (ss->community_len > 0)) {
403 pptr->secNameData = netsnmp_memdup_nt(ss->community,
404 ss->community_len,
405 &pptr->secNameLen);
406 if (pptr->secNameData == NULL)
407 goto bail;
408 }
409 }
410 #endif
411 pptr->storageType = ST_READONLY;
412 pptr->rowStatus = RS_ACTIVE;
413 snmpTargetParamTable_add(pptr);
414 /*
415 * XXX: END move target creation to target code
416 */
417
418 /*
419 * notify table
420 */
421 nptr = SNMP_MALLOC_STRUCT(snmpNotifyTable_data);
422 if (nptr == NULL)
423 goto bail;
424 ++_active;
425 nptr->snmpNotifyName = netsnmp_memdup_nt(name, nameLen,
426 &nptr->snmpNotifyNameLen);
427 /** selects target addr */
428 nptr->snmpNotifyTag = netsnmp_memdup_nt(tag, tagLen,
429 &nptr->snmpNotifyTagLen);
430 if (!nptr->snmpNotifyName || !nptr->snmpNotifyTag)
431 goto bail;
432 nptr->snmpNotifyType = confirm ?
433 SNMPNOTIFYTYPE_INFORM : SNMPNOTIFYTYPE_TRAP;
434 nptr->snmpNotifyStorageType = ST_READONLY;
435 nptr->snmpNotifyRowStatus = RS_ACTIVE;
436
437 if (snmpNotifyTable_add(nptr) == SNMPERR_GENERR) {
438 snmpNotifyTable_dispose(nptr);
439 nptr = NULL;
440 goto bail;
441 }
442
443 /*
444 * filter profile
445 */
446 if (NULL != notifyProfile) {
447 struct snmpNotifyFilterProfileTable_data *profile;
448 profile = snmpNotifyFilterProfileTable_create(ptr->paramsData,
449 ptr->paramsLen,
450 notifyProfile,
451 notifyProfileLen);
452 if (NULL == profile) {
453 snmp_log(LOG_ERR, "couldn't create notify filter profile\n");
454 goto bail;
455 } else {
456 profile->snmpNotifyFilterProfileRowStatus = RS_ACTIVE;
457 profile->snmpNotifyFilterProfileStorType = ST_READONLY;
458
459 if (snmpNotifyFilterProfileTable_add(profile) != SNMPERR_SUCCESS) {
460 snmp_log(LOG_ERR, "couldn't add notify filter profile\n");
461 snmpNotifyFilterProfileTable_free(profile);
462 }
463 }
464 }
465
466 args->rc = SNMPERR_SUCCESS;
467 return 0;
468
469 bail:
470 snmp_log(LOG_ERR, "Cannot add new trap destination %s\n", name);
471
472 if (NULL != nptr)
473 snmpNotifyTable_remove(nptr);
474 free(nptr);
475
476 if (NULL != pptr)
477 snmpTargetParamTable_remove(pptr);
478
479 if (NULL != ptr)
480 snmpTargetAddrTable_remove(ptr);
481
482 snmp_close(ss);
483
484 return 0;
485 }
486
487 void
488 snmpNotifyTable_dispose(struct snmpNotifyTable_data *thedata)
489 {
490 if (NULL == thedata)
491 return;
492
493 SNMP_FREE(thedata->snmpNotifyName);
494 SNMP_FREE(thedata->snmpNotifyTag);
495 free(thedata);
496 --_active;
497 }
498
499 /*
500 * XXX: this really needs to be done for the target mib entries too.
501 * But we can only trust that we've added stuff here and we don't want
502 * to destroy other valid entries in the target tables, so... Don't
503 * do too many kill -HUPs to your agent as re reading the config file
504 * will be a slow memory leak in the target mib.
505 */
506 int
507 notifyTable_unregister_all_notifications(int major, int minor,
508 void *serverarg, void *clientarg)
509 {
510 struct header_complex_index *hptr, *nhptr;
511
512 for (hptr = snmpNotifyTableStorage; hptr; hptr = nhptr) {
513 struct snmpNotifyTable_data *nptr = hptr->data;
514 nhptr = hptr->next;
515 if (nptr->snmpNotifyStorageType == ST_READONLY) {
516 header_complex_extract_entry(&snmpNotifyTableStorage, hptr);
517 snmpNotifyTable_dispose(nptr);
518 }
519 }
520 snmpNotifyTableStorage = NULL;
521 return (0);
522 }
523
524 /*
525 * init_snmpNotifyTable_data():
526 * Initialization routine. This is called when the agent starts up.
527 */
528 void
529 init_snmpNotifyTable_data(void)
530 {
531 static int done = 0;
532
533 if (++done != 1) {
534 DEBUGMSGTL(("snmpNotifyTable_data", "multiple init calls"));
535 return;
536 }
537
538 DEBUGMSGTL(("snmpNotifyTable_data", "initializing... "));
539
540 /*
541 * we need to be called back later to store our data
542 */
543 snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
544 store_snmpNotifyTable, NULL);
545
546
547 #ifndef DISABLE_SNMPV1
548 snmp_register_callback(SNMP_CALLBACK_APPLICATION,
549 SNMPD_CALLBACK_SEND_TRAP1, send_notifications,
550 NULL);
551 #endif
552 snmp_register_callback(SNMP_CALLBACK_APPLICATION,
553 SNMPD_CALLBACK_SEND_TRAP2, send_notifications,
554 NULL);
555 snmp_register_callback(SNMP_CALLBACK_APPLICATION,
556 SNMPD_CALLBACK_REGISTER_NOTIFICATIONS,
557 notifyTable_register_notifications, NULL);
558 snmp_register_callback(SNMP_CALLBACK_APPLICATION,
559 SNMPD_CALLBACK_UNREGISTER_NOTIFICATIONS,
560 _unregister_notification_cb, NULL);
561 snmp_register_callback(SNMP_CALLBACK_APPLICATION,
562 SNMPD_CALLBACK_PRE_UPDATE_CONFIG,
563 notifyTable_unregister_all_notifications, NULL);
564
565 DEBUGMSGTL(("snmpNotifyTable_data", "done.\n"));
566 }
567
568 void
569 shutdown_snmpNotifyTable_data(void)
570 {
571 DEBUGMSGTL(("snmpNotifyTable_data", "shutting down ... "));
572
573 snmp_unregister_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
574 store_snmpNotifyTable, NULL, FALSE);
575
576 notifyTable_unregister_all_notifications(SNMP_CALLBACK_APPLICATION,
577 SNMPD_CALLBACK_PRE_UPDATE_CONFIG,
578 NULL, NULL);
579
580 snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
581 SNMPD_CALLBACK_PRE_UPDATE_CONFIG,
582 notifyTable_unregister_all_notifications, NULL,
583 FALSE);
584 snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
585 SNMPD_CALLBACK_REGISTER_NOTIFICATIONS,
586 notifyTable_register_notifications, NULL, FALSE);
587 snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
588 SNMPD_CALLBACK_UNREGISTER_NOTIFICATIONS,
589 _unregister_notification_cb, NULL, FALSE);
590 snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
591 SNMPD_CALLBACK_SEND_TRAP2, send_notifications,
592 NULL, FALSE);
593 #ifndef DISABLE_SNMPV1
594 snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
595 SNMPD_CALLBACK_SEND_TRAP1, send_notifications,
596 NULL, FALSE);
597 #endif
598 DEBUGMSGTL(("trap:notify:shutdown", "active count %d\n", _active));
599 if (_active != 0) {
600 DEBUGMSGTL(("trap:notify:shutdown",
601 "unexpected count %d after cleanup!\n",_active));
602 snmp_log(LOG_WARNING,
603 "notify count %d, not 0, after shutdown.\n", _active);
604 }
605
606 DEBUGMSGTL(("snmpNotifyTable_data", "done.\n"));
607 }
608
609 /*
610 * snmpNotifyTable_add(): adds a structure node to our data set
611 */
612 int
613 snmpNotifyTable_add(struct snmpNotifyTable_data *thedata)
614 {
615 netsnmp_variable_list *vars = NULL;
616 int retVal;
617
618 if (NULL == thedata)
619 return SNMPERR_GENERR;
620
621 DEBUGMSGTL(("snmpNotifyTable_data", "adding data... "));
622 /*
623 * add the index variables to the varbind list, which is
624 * used by header_complex to index the data. the allocated
625 * variable will be freed by header_complex_maybe_add_data().
626 */
627 snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OCTET_STR, (u_char *) thedata->snmpNotifyName, thedata->snmpNotifyNameLen); /* snmpNotifyName */
628
629 if (header_complex_maybe_add_data(&snmpNotifyTableStorage, vars, thedata, 1)
630 != NULL){
631 DEBUGMSGTL(("snmpNotifyTable", "registered an entry\n"));
632 retVal = SNMPERR_SUCCESS;
633 }else{
634 retVal = SNMPERR_GENERR;
635 }
636
637
638 DEBUGMSGTL(("snmpNotifyTable", "done.\n"));
639 return retVal;
640 }
641
642 struct snmpNotifyTable_data *
643 snmpNotifyTable_extract(struct snmpNotifyTable_data *thedata)
644 {
645 struct header_complex_index *hptr;
646
647 hptr = header_complex_find_entry(snmpNotifyTableStorage, thedata);
648 if (NULL == hptr)
649 return NULL;
650
651 return header_complex_extract_entry((struct header_complex_index**)
652 &snmpNotifyTableStorage, hptr);
653 }
654
655 int
656 snmpNotifyTable_remove(struct snmpNotifyTable_data *thedata)
657 {
658 struct snmpNotifyTable_data *nptr = snmpNotifyTable_extract(thedata);
659 if (nptr) {
660 snmpNotifyTable_dispose(nptr);
661 return 1;
662 }
663 return 0;
664 }
665
666 struct snmpNotifyTable_data *
667 get_notifyTable2(const char *name, size_t nameLen)
668 {
669 struct header_complex_index *hptr;
670
671 for (hptr = snmpNotifyTableStorage; hptr; hptr = hptr->next) {
672 struct snmpNotifyTable_data *nptr = hptr->data;
673 if (nptr->snmpNotifyNameLen == nameLen && nptr->snmpNotifyName &&
674 memcmp(nptr->snmpNotifyName, name, nameLen) == 0)
675 return nptr;
676 }
677 return NULL;
678 }
679
680 struct snmpNotifyTable_data *
681 find_row_notifyTable(struct variable *vp, oid * name, size_t * len, int exact,
682 size_t * var_len, WriteMethod ** write_method)
683 {
684 struct snmpNotifyTable_data *result =
685 header_complex((struct header_complex_index *)
686 snmpNotifyTableStorage, vp, name, len, exact,
687 var_len, write_method);
688 return result;
689 }
690
691 void
692 snmpNotifyTable_unregister_notification(const char *name, unsigned char nameLen)
693 {
694 struct targetAddrTable_struct *ta = get_addrForName2(name,nameLen);
695 struct targetParamTable_struct *tp = get_paramEntry2(name,nameLen);
696 struct snmpNotifyTable_data *nt = get_notifyTable2(name,nameLen);
697 struct snmpNotifyFilterProfileTable_data *fp =
698 snmpNotifyFilterProfileTable_find(name, nameLen);
699
700 DEBUGMSGTL(("trapsess", "removing %s from trap tables\n", name));
701
702 if (NULL != nt)
703 snmpNotifyTable_remove(nt);
704 else
705 DEBUGMSGTL(("snmpNotifyTable:unregister",
706 "No NotifyTable entry for %s\n", name));
707
708 if (NULL != tp)
709 snmpTargetParamTable_remove(tp);
710 else
711 DEBUGMSGTL(("snmpNotifyTable:unregister",
712 "No TargetParamTable entry for %s\n", name));
713
714 if (NULL != ta)
715 snmpTargetAddrTable_remove(ta);
716 else
717 DEBUGMSGTL(("snmpNotifyTable:unregister",
718 "No TargetAddrTable entry for %s\n", name));
719
720 if (NULL != fp)
721 snmpNotifyFilterProfileTable_remove(fp);
722 else
723 DEBUGMSGTL(("snmpNotifyTable:unregister",
724 "No FilterProfileTable entry for %s\n", name));
725
726 }
727
728 static int
729 _unregister_notification_cb(int major, int minor,
730 void *serverarg, void *clientarg)
731 {
732 struct agent_add_trap_args *args =
733 (struct agent_add_trap_args *) serverarg;
734
735 if (!args || !(args->nameData))
736 return 0;
737
738 snmpNotifyTable_unregister_notification(args->nameData, args->nameLen);
739 return 1;
740 }
741
742 /*
743 * store_snmpNotifyTable():
744 * stores .conf file entries needed to configure the mib.
745 */
746 int
747 store_snmpNotifyTable(int majorID, int minorID, void *serverarg,
748 void *clientarg)
749 {
750 char line[SNMP_MAXBUF];
751 char *cptr;
752 size_t tmpint;
753 struct snmpNotifyTable_data *StorageTmp;
754 struct header_complex_index *hcindex;
755
756
757 DEBUGMSGTL(("snmpNotifyTable", "storing data... "));
758
759
760 for (hcindex = snmpNotifyTableStorage; hcindex != NULL;
761 hcindex = hcindex->next) {
762 StorageTmp = (struct snmpNotifyTable_data *) hcindex->data;
763
764 /*
765 * store permanent and nonvolatile rows.
766 * XXX should there be a qualification on RowStatus??
767 */
768 if ((StorageTmp->snmpNotifyStorageType == ST_NONVOLATILE) ||
769 (StorageTmp->snmpNotifyStorageType == ST_PERMANENT) ){
770
771 memset(line, 0, sizeof(line));
772 strcat(line, "snmpNotifyTable ");
773 cptr = line + strlen(line);
774
775 cptr =
776 read_config_store_data(ASN_OCTET_STR, cptr,
777 &StorageTmp->snmpNotifyName,
778 &StorageTmp->snmpNotifyNameLen);
779 cptr =
780 read_config_store_data(ASN_OCTET_STR, cptr,
781 &StorageTmp->snmpNotifyTag,
782 &StorageTmp->snmpNotifyTagLen);
783 cptr =
784 read_config_store_data(ASN_INTEGER, cptr,
785 &StorageTmp->snmpNotifyType,
786 &tmpint);
787 cptr =
788 read_config_store_data(ASN_INTEGER, cptr,
789 &StorageTmp->snmpNotifyStorageType,
790 &tmpint);
791 cptr =
792 read_config_store_data(ASN_INTEGER, cptr,
793 &StorageTmp->snmpNotifyRowStatus,
794 &tmpint);
795
796 snmpd_store_config(line);
797 }
798 }
799 DEBUGMSGTL(("snmpNotifyTable", "done.\n"));
800 return 0;
801 }
802