mteTriggerTable.c
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:128k
源码类别:

SNMP编程

开发平台:

Unix_Linux

  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.  * This should always be included first before anything else 
  7.  */
  8. #include <net-snmp/net-snmp-config.h>
  9. #if HAVE_STDLIB_H
  10. #include <stdlib.h>
  11. #endif
  12. #if HAVE_STRING_H
  13. #include <string.h>
  14. #else
  15. #include <strings.h>
  16. #endif
  17. #ifdef HAVE_LIMITS_H
  18. #include <limits.h>
  19. #endif
  20. /*
  21.  * minimal include directives 
  22.  */
  23. #include <net-snmp/net-snmp-includes.h>
  24. #include <net-snmp/agent/net-snmp-agent-includes.h>
  25. #include "header_complex.h"
  26. #include "mteTriggerTable.h"
  27. #include "mteTriggerBooleanTable.h"
  28. #include "mteTriggerDeltaTable.h"
  29. #include "mteTriggerExistenceTable.h"
  30. #include "mteTriggerThresholdTable.h"
  31. #include "mteEventTable.h"
  32. #include "mteObjectsTable.h"
  33. /*
  34.  * mteTriggerTable_variables_oid:
  35.  *   this is the top level oid that we want to register under.  This
  36.  *   is essentially a prefix, with the suffix appearing in the
  37.  *   variable below.
  38.  */
  39. /*
  40.  * trap definitions 
  41.  */
  42. oid             mteTriggerFired[] = { 1, 3, 6, 1, 2, 1, 88, 2, 0, 1 };
  43. oid             mteTriggerRising[] = { 1, 3, 6, 1, 2, 1, 88, 2, 0, 2 };
  44. oid             mteTriggerFalling[] = { 1, 3, 6, 1, 2, 1, 88, 2, 0, 3 };
  45. oid             mteTriggerFailure[] = { 1, 3, 6, 1, 2, 1, 88, 2, 0, 4 };
  46. oid             mteEventSetFailure[] = { 1, 3, 6, 1, 2, 1, 88, 2, 0, 5 };
  47. /*
  48.  * trap objects 
  49.  */
  50. oid             mteHotTrigger[] = { 1, 3, 6, 1, 2, 1, 88, 2, 1, 1 };
  51. oid             mteHotTargetName[] = { 1, 3, 6, 1, 2, 1, 88, 2, 1, 2 };
  52. oid             mteHotContextName[] = { 1, 3, 6, 1, 2, 1, 88, 2, 1, 3 };
  53. oid             mteHotOID[] = { 1, 3, 6, 1, 2, 1, 88, 2, 1, 4 };
  54. oid             mteHotValue[] = { 1, 3, 6, 1, 2, 1, 88, 2, 1, 5 };
  55. oid             mteFailedReason[] = { 1, 3, 6, 1, 2, 1, 88, 2, 1, 6 };
  56. /*
  57.  * For discontinuity checking.  
  58.  */
  59. oid             sysUpTimeInstance[] = { 1, 3, 6, 1, 2, 1, 1, 3, 0 };
  60. oid             mteTriggerTable_variables_oid[] =
  61.     { 1, 3, 6, 1, 2, 1, 88, 1, 2, 2 };
  62. /*
  63.  * variable2 mteTriggerTable_variables:
  64.  *   this variable defines function callbacks and type return information 
  65.  *   for the mteTriggerTable mib section 
  66.  */
  67. struct variable2 mteTriggerTable_variables[] = {
  68.     /*
  69.      * magic number        , variable type , ro/rw , callback fn  , L, oidsuffix 
  70.      */
  71. #define   MTETRIGGERCOMMENT     5
  72.     {MTETRIGGERCOMMENT, ASN_OCTET_STR, RWRITE, var_mteTriggerTable, 2,
  73.      {1, 3}},
  74. #define   MTETRIGGERTEST        6
  75.     {MTETRIGGERTEST, ASN_OCTET_STR, RWRITE, var_mteTriggerTable, 2, {1, 4}},
  76. #define   MTETRIGGERSAMPLETYPE  7
  77.     {MTETRIGGERSAMPLETYPE, ASN_INTEGER, RWRITE, var_mteTriggerTable, 2,
  78.      {1, 5}},
  79. #define   MTETRIGGERVALUEID     8
  80.     {MTETRIGGERVALUEID, ASN_OBJECT_ID, RWRITE, var_mteTriggerTable, 2,
  81.      {1, 6}},
  82. #define   MTETRIGGERVALUEIDWILDCARD  9
  83.     {MTETRIGGERVALUEIDWILDCARD, ASN_INTEGER, RWRITE, var_mteTriggerTable,
  84.      2, {1, 7}},
  85. #define   MTETRIGGERTARGETTAG   10
  86.     {MTETRIGGERTARGETTAG, ASN_OCTET_STR, RWRITE, var_mteTriggerTable, 2,
  87.      {1, 8}},
  88. #define   MTETRIGGERCONTEXTNAME  11
  89.     {MTETRIGGERCONTEXTNAME, ASN_OCTET_STR, RWRITE, var_mteTriggerTable, 2,
  90.      {1, 9}},
  91. #define   MTETRIGGERCONTEXTNAMEWILDCARD  12
  92.     {MTETRIGGERCONTEXTNAMEWILDCARD, ASN_INTEGER, RWRITE,
  93.      var_mteTriggerTable, 2, {1, 10}},
  94. #define   MTETRIGGERFREQUENCY   13
  95.     {MTETRIGGERFREQUENCY, ASN_UNSIGNED, RWRITE, var_mteTriggerTable, 2,
  96.      {1, 11}},
  97. #define   MTETRIGGEROBJECTSOWNER  14
  98.     {MTETRIGGEROBJECTSOWNER, ASN_OCTET_STR, RWRITE, var_mteTriggerTable, 2,
  99.      {1, 12}},
  100. #define   MTETRIGGEROBJECTS     15
  101.     {MTETRIGGEROBJECTS, ASN_OCTET_STR, RWRITE, var_mteTriggerTable, 2,
  102.      {1, 13}},
  103. #define   MTETRIGGERENABLED     16
  104.     {MTETRIGGERENABLED, ASN_INTEGER, RWRITE, var_mteTriggerTable, 2,
  105.      {1, 14}},
  106. #define   MTETRIGGERENTRYSTATUS  17
  107.     {MTETRIGGERENTRYSTATUS, ASN_INTEGER, RWRITE, var_mteTriggerTable, 2,
  108.      {1, 15}},
  109. };
  110. /*
  111.  * (L = length of the oidsuffix) 
  112.  */
  113. /*
  114.  * global storage of our data, saved in and configured by header_complex() 
  115.  */
  116. struct header_complex_index *mteTriggerTableStorage = NULL;
  117. netsnmp_session *mte_callback_sess = NULL;
  118. extern int      callback_master_num;
  119. /*
  120.  * init_mteTriggerTable():
  121.  *   Initialization routine.  This is called when the agent starts up.
  122.  *   At a minimum, registration of your variables should take place here.
  123.  */
  124. void
  125. init_mteTriggerTable(void)
  126. {
  127.     DEBUGMSGTL(("mteTriggerTable", "initializing...  "));
  128. #ifndef SNMP_TRANSPORT_CALLBACK_DOMAIN
  129.     snmp_log(LOG_WARNING,"mteTriggerTable has been disabled because "
  130.                "the callback transport is not available.n");
  131.     return;
  132. #endif
  133.     /*
  134.      * register ourselves with the agent to handle our mib tree 
  135.      */
  136.     REGISTER_MIB("mteTriggerTable", mteTriggerTable_variables, variable2,
  137.                  mteTriggerTable_variables_oid);
  138.     /*
  139.      * register our config handler(s) to deal with registrations 
  140.      */
  141.     snmpd_register_config_handler("mteTriggerTable", parse_mteTriggerTable,
  142.                                   NULL, NULL);
  143.     snmpd_register_config_handler("monitor", parse_simple_monitor, NULL,
  144.                                   "[options] monitor_expression [see "man snmpd.conf"]");
  145.     snmpd_register_config_handler("defaultMonitors",
  146.                                   parse_default_monitors, NULL, "yes|no");
  147.     netsnmp_ds_register_config(ASN_OCTET_STR, "snmpd", "agentSecName",
  148.                        NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_INTERNAL_SECNAME);
  149.     /*
  150.      * we need to be called back later to store our data 
  151.      */
  152.     snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
  153.                            store_mteTriggerTable, NULL);
  154.     /*
  155.      * place any other initialization junk you need here 
  156.      */
  157.     se_add_pair_to_slist("mteBooleanOperators", strdup("!="),
  158.                          MTETRIGGERBOOLEANCOMPARISON_UNEQUAL);
  159.     se_add_pair_to_slist("mteBooleanOperators", strdup("=="),
  160.                          MTETRIGGERBOOLEANCOMPARISON_EQUAL);
  161.     se_add_pair_to_slist("mteBooleanOperators", strdup("<"),
  162.                          MTETRIGGERBOOLEANCOMPARISON_LESS);
  163.     se_add_pair_to_slist("mteBooleanOperators", strdup("<="),
  164.                          MTETRIGGERBOOLEANCOMPARISON_LESSOREQUAL);
  165.     se_add_pair_to_slist("mteBooleanOperators", strdup(">"),
  166.                          MTETRIGGERBOOLEANCOMPARISON_GREATER);
  167.     se_add_pair_to_slist("mteBooleanOperators", strdup(">="),
  168.                          MTETRIGGERBOOLEANCOMPARISON_GREATEROREQUAL);
  169. #ifdef SNMP_TRANSPORT_CALLBACK_DOMAIN
  170.     /*
  171.      * open a 'callback' session to the main agent 
  172.      */
  173.     if (mte_callback_sess == NULL) {
  174.         mte_callback_sess = netsnmp_callback_open(callback_master_num,
  175.                                                   NULL, NULL, NULL);
  176.         DEBUGMSGTL(("mteTriggerTable", "created callback session = %08xn",
  177.                     mte_callback_sess));
  178.     }
  179. #endif
  180.     DEBUGMSGTL(("mteTriggerTable", "done.n"));
  181. }
  182. struct mteTriggerTable_data *
  183. create_mteTriggerTable_data(void)
  184. {
  185.     struct mteTriggerTable_data *StorageNew;
  186.     StorageNew = SNMP_MALLOC_STRUCT(mteTriggerTable_data);
  187.     /*
  188.      * fill in default row values here into StorageNew 
  189.      */
  190.     /*
  191.      * fill in values for all tables (even if not
  192.      * appropriate), since its easier to do here than anywhere
  193.      * else 
  194.      */
  195.     StorageNew->mteTriggerComment = strdup("");
  196.     StorageNew->mteTriggerTest = strdup("");
  197.     StorageNew->mteTriggerTest[0] |= (char) MTETRIGGERTEST_BOOLEAN;
  198.     StorageNew->mteTriggerTestLen = 1;
  199.     StorageNew->mteTriggerSampleType = MTETRIGGERSAMPLETYPE_ABSOLUTEVALUE;
  200.     StorageNew->mteTriggerValueID = calloc(1, sizeof(oid) * sizeof(2)); /* 0.0 */
  201.     StorageNew->mteTriggerValueIDLen = 2;
  202.     StorageNew->mteTriggerValueIDWildcard =
  203.         MTETRIGGERVALUEIDWILDCARD_FALSE;
  204.     StorageNew->mteTriggerTargetTag = strdup("");
  205.     StorageNew->mteTriggerContextName = strdup("");
  206.     StorageNew->mteTriggerContextNameWildcard =
  207.         MTETRIGGERCONTEXTNAMEWILDCARD_FALSE;
  208.     StorageNew->mteTriggerFrequency = 600;
  209.     StorageNew->mteTriggerObjectsOwner = strdup("");
  210.     StorageNew->mteTriggerObjects = strdup("");
  211.     StorageNew->mteTriggerEnabled = MTETRIGGERENABLED_FALSE;
  212.     memdup((unsigned char **)
  213.            &(StorageNew->mteTriggerDeltaDiscontinuityID),
  214.            (unsigned char *) sysUpTimeInstance, sizeof(sysUpTimeInstance));
  215.     StorageNew->mteTriggerDeltaDiscontinuityIDLen =
  216.         sizeof(sysUpTimeInstance) / sizeof(oid);
  217.     StorageNew->mteTriggerDeltaDiscontinuityIDWildcard = TV_FALSE;
  218.     StorageNew->mteTriggerDeltaDiscontinuityIDType =
  219.         MTETRIGGERDELTADISCONTINUITYIDTYPE_TIMETICKS;
  220.     StorageNew->mteTriggerExistenceTest = strdup("");
  221.     StorageNew->mteTriggerExistenceTest[0] =
  222.         (char) (MTETRIGGEREXISTENCETEST_PRESENT |
  223.                 MTETRIGGEREXISTENCETEST_ABSENT);
  224.     StorageNew->mteTriggerExistenceTestLen = 1;
  225.     StorageNew->mteTriggerExistenceStartup = strdup("");
  226.     StorageNew->mteTriggerExistenceStartup[0] =
  227.         (char) (MTETRIGGEREXISTENCESTARTUP_PRESENT);
  228.     StorageNew->mteTriggerExistenceStartupLen = 1;
  229.     StorageNew->mteTriggerExistenceObjectsOwner = strdup("");
  230.     StorageNew->mteTriggerExistenceObjects = strdup("");
  231.     StorageNew->mteTriggerExistenceEventOwner = strdup("");
  232.     StorageNew->mteTriggerExistenceEvent = strdup("");
  233.     StorageNew->mteTriggerBooleanComparison =
  234.         MTETRIGGERBOOLEANCOMPARISON_UNEQUAL;
  235.     StorageNew->mteTriggerBooleanStartup = MTETRIGGERBOOLEANSTARTUP_TRUE;
  236.     StorageNew->mteTriggerBooleanObjectsOwner = strdup("");
  237.     StorageNew->mteTriggerBooleanObjects = strdup("");
  238.     StorageNew->mteTriggerBooleanEventOwner = strdup("");
  239.     StorageNew->mteTriggerBooleanEvent = strdup("");
  240.     StorageNew->mteTriggerThresholdStartup =
  241.         MTETRIGGERTHRESHOLDSTARTUP_RISINGORFALLING;
  242.     StorageNew->mteTriggerThresholdObjectsOwner = strdup("");
  243.     StorageNew->mteTriggerThresholdObjects = strdup("");
  244.     StorageNew->mteTriggerThresholdRisingEventOwner = strdup("");
  245.     StorageNew->mteTriggerThresholdRisingEvent = strdup("");
  246.     StorageNew->mteTriggerThresholdFallingEventOwner = strdup("");
  247.     StorageNew->mteTriggerThresholdFallingEvent = strdup("");
  248.     StorageNew->mteTriggerThresholdDeltaRisingEventOwner = strdup("");
  249.     StorageNew->mteTriggerThresholdDeltaRisingEvent = strdup("");
  250.     StorageNew->mteTriggerThresholdDeltaFallingEventOwner = strdup("");
  251.     StorageNew->mteTriggerThresholdDeltaFallingEvent = strdup("");
  252.     StorageNew->lastboolresult = -1;
  253.     StorageNew->storageType = ST_NONVOLATILE;
  254.     StorageNew->prevDiscoTicks = 0;
  255.     StorageNew->prevUptimeTicks = 0;
  256.     return StorageNew;
  257. }
  258. /*
  259.  * mteTriggerTable_add(): adds a structure node to our data set 
  260.  */
  261. int
  262. mteTriggerTable_add(struct mteTriggerTable_data *thedata)
  263. {
  264.     netsnmp_variable_list *vars = NULL;
  265.     DEBUGMSGTL(("mteTriggerTable", "adding data...  "));
  266.     /*
  267.      * add the index variables to the varbind list, which is 
  268.      * used by header_complex to index the data 
  269.      */
  270.     snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->mteOwner, thedata->mteOwnerLen); /* mteOwner */
  271.     snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OCTET_STR, (char *) thedata->mteTriggerName, thedata->mteTriggerNameLen);        /* mteTriggerName */
  272.     header_complex_add_data(&mteTriggerTableStorage, vars, thedata);
  273.     DEBUGMSGTL(("mteTriggerTable", "registered an entryn"));
  274.     DEBUGMSGTL(("mteTriggerTable", "done.n"));
  275.     return SNMPERR_SUCCESS;
  276. }
  277. #define MTE_PROCESS_LINE(line) 
  278.   snprintf(buf, SPRINT_MAX_LEN, "-u %s %s", mte_default_user, line); 
  279.   parse_simple_monitor("monitor", buf);
  280. void
  281. parse_default_monitors(const char *token, char *line)
  282. {
  283.     char            buf[SPRINT_MAX_LEN];
  284.     char           *mte_default_user =
  285.         netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_INTERNAL_SECNAME);
  286.     if (strncmp(line, "yes", 3) == 0) {
  287.         DEBUGMSGTL(("mteTriggerTable", "registering default monitorsn"));
  288.         if (mte_default_user == NULL) {
  289.             config_perror
  290.                 ("You must specify a user name first using the agentSecName tokenn");
  291.             return;
  292.         }
  293.         /*
  294.          * we don't include many additional objects here as most of
  295.          * the error messages are complete with the needed
  296.          * information 
  297.          */
  298.         MTE_PROCESS_LINE
  299.             ("-o prNames -o prErrMessage "process table" prErrorFlag != 0");
  300.         MTE_PROCESS_LINE
  301.             ("-o memErrorName -o memSwapErrorMsg "memory" memSwapError != 0");
  302.         MTE_PROCESS_LINE
  303.             ("-o extNames -o extOutput "extTable" extResult != 0");
  304.         MTE_PROCESS_LINE
  305.             ("-o dskPath -o dskErrorMsg "dskTable" dskErrorFlag != 0");
  306.         MTE_PROCESS_LINE
  307.             ("-o laNames -o laErrMessage  "laTable" laErrorFlag != 0");
  308.         MTE_PROCESS_LINE
  309.             ("-o fileName -o fileErrorMsg  "fileTable" fileErrorFlag != 0");
  310.         /*
  311.          * this one is not *all* that useful, because the error is
  312.          * only kept for 30 seconds at most.  Maybe scan it every 30
  313.          * seconds, but I'm not doing so without seeking other peoples
  314.          * opinions first. 
  315.          */
  316.         MTE_PROCESS_LINE
  317.             ("-o snmperrErrMessage  "snmperrs" snmperrErrorFlag != 0");
  318.     }
  319. }
  320. static int      monitor_call_count = 0;
  321. void
  322. parse_simple_monitor(const char *token, char *line)
  323. {
  324.     char            buf[SPRINT_MAX_LEN], *cp, ebuf[SPRINT_MAX_LEN],
  325.                     eventname[64];
  326.     oid             obuf[MAX_OID_LEN];
  327.     size_t          obufLen;
  328.     struct mteTriggerTable_data *StorageNew;
  329.     monitor_call_count++;
  330.     eventname[0] = '';
  331.     StorageNew = create_mteTriggerTable_data();
  332.     StorageNew->storageType = ST_READONLY;
  333.     StorageNew->mteTriggerEnabled = MTETRIGGERENABLED_TRUE;
  334.     StorageNew->mteTriggerEntryStatus = RS_ACTIVE;
  335.     StorageNew->mteTriggerValueIDWildcard = MTETRIGGERVALUEIDWILDCARD_TRUE;
  336.     StorageNew->mteTriggerBooleanStartup = MTETRIGGERBOOLEANSTARTUP_TRUE;
  337.     StorageNew->mteTriggerThresholdStartup =
  338.         MTETRIGGERTHRESHOLDSTARTUP_RISINGORFALLING;
  339.     StorageNew->mteTriggerExistenceTest[0] = 0;
  340.     /*
  341.      * owner = snmpd.conf, why not? 
  342.      */
  343.     StorageNew->mteOwner = strdup("snmpd.conf");
  344.     StorageNew->mteOwnerLen = strlen(StorageNew->mteOwner);
  345.     StorageNew->pdu_version = SNMP_VERSION_3;
  346.     StorageNew->pdu_securityModel = SNMP_SEC_MODEL_USM;
  347.     StorageNew->pdu_securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;
  348.     cp = line;
  349.     while (cp && *cp == '-') {
  350.         cp = copy_nword(cp, buf, sizeof(buf));
  351.         switch (buf[1]) {
  352.         case 't':
  353.            /*
  354.             * Threshold toggle
  355.             */
  356.            StorageNew->mteTriggerTest[0] = MTETRIGGERTEST_THRESHOLD;
  357.            break;
  358.         case 'i':
  359.            /*
  360.             * Single instance
  361.             */
  362.            StorageNew->mteTriggerValueIDWildcard = MTETRIGGERVALUEIDWILDCARD_FALSE;
  363.            break;
  364.         case 'r':
  365.             if (cp) {
  366.                 cp = copy_nword(cp, buf, sizeof(buf));
  367.                 StorageNew->mteTriggerFrequency = strtoul(buf, NULL, 0);
  368.             } else {
  369.                 config_perror("No parameter after -r givenn");
  370.                 /*
  371.                  * XXX: free StorageNew 
  372.                  */
  373.                 return;
  374.             }
  375.             break;
  376.         case 'u':
  377.             if (cp) {
  378.                 cp = copy_nword(cp, buf, sizeof(buf));
  379.                 StorageNew->pdu_securityName = strdup(buf);
  380.                 StorageNew->pdu_securityNameLen = strlen(buf);
  381.             } else {
  382.                 config_perror("No parameter after -u givenn");
  383.                 /*
  384.                  * XXX: free StorageNew 
  385.                  */
  386.                 return;
  387.             }
  388.             break;
  389.         case 'e':
  390.             if (cp) {
  391.                 cp = copy_nword(cp, eventname, sizeof(eventname));
  392.             } else {
  393.                 config_perror("No parameter after -e givenn");
  394.                 /*
  395.                  * XXX: free StorageNew 
  396.                  */
  397.                 return;
  398.             }
  399.             break;
  400.         case 'o':
  401.             /*
  402.              * oid 
  403.              */
  404.             cp = copy_nword(cp, buf, sizeof(buf));
  405.             obufLen = MAX_OID_LEN;
  406.             if (!snmp_parse_oid(buf, obuf, &obufLen)) {
  407.                 sprintf(ebuf, "unable to parse oid: %s", buf);
  408.                 config_perror(ebuf);
  409.                 /*
  410.                  * XXX: free StorageNew 
  411.                  */
  412.                 return;
  413.             }
  414.             sprintf(buf, "snmpd.conf%d", monitor_call_count);
  415.             mte_add_object_to_table("snmpd.conf", buf, obuf, obufLen, 1);
  416.             if (StorageNew->mteTriggerObjectsOwnerLen == 0) {
  417.                 SNMP_FREE(StorageNew->mteTriggerObjectsOwner);
  418.                 StorageNew->mteTriggerObjectsOwner = strdup("snmpd.conf");
  419.                 StorageNew->mteTriggerObjectsOwnerLen =
  420.                     strlen("snmpd.conf");
  421.             }
  422.             if (StorageNew->mteTriggerObjectsLen == 0) {
  423.                 SNMP_FREE(StorageNew->mteTriggerObjects);
  424.                 StorageNew->mteTriggerObjects = strdup(buf);
  425.                 StorageNew->mteTriggerObjectsLen = strlen(buf);
  426.             }
  427.             break;
  428.         }
  429.     }
  430.     if (StorageNew->pdu_securityNameLen == 0) {
  431.         char           *mte_default_user =
  432.             netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_INTERNAL_SECNAME);
  433.         if (mte_default_user) {
  434.             StorageNew->pdu_securityName = strdup(mte_default_user);
  435.             StorageNew->pdu_securityNameLen = strlen(mte_default_user);
  436.         } else {
  437.             config_perror("-u USER parameter requiredn");
  438.             /*
  439.              * XXX: free StorageNew 
  440.              */
  441.             return;
  442.         }
  443.     }
  444.     /*
  445.      * name 
  446.      */
  447.     cp = copy_nword(cp, buf, sizeof(buf));
  448.     if (!cp) {
  449.         config_perror("illegal monitor: no name specified");
  450.         /*
  451.          * XXX: free StorageNew 
  452.          */
  453.         return;
  454.     }
  455.     StorageNew->mteTriggerName = strdup(buf);
  456.     StorageNew->mteTriggerNameLen = strlen(StorageNew->mteTriggerName);
  457.     /*
  458.      * oid 
  459.      */
  460.     cp = copy_nword(cp, buf, sizeof(buf));
  461.     obufLen = MAX_OID_LEN;
  462.     if (!snmp_parse_oid(buf, obuf, &obufLen)) {
  463.         sprintf(ebuf, "unable to parse oid: %s", buf);
  464.         config_perror(ebuf);
  465.         /*
  466.          * XXX: free StorageNew 
  467.          */
  468.         return;
  469.     }
  470.     if (StorageNew->mteTriggerValueID)
  471.         free(StorageNew->mteTriggerValueID);
  472.     StorageNew->mteTriggerValueID = snmp_duplicate_objid(obuf, obufLen);
  473.     StorageNew->mteTriggerValueIDLen = obufLen;
  474.     if (StorageNew->mteTriggerTest[0] == MTETRIGGERTEST_THRESHOLD) {
  475.        /*
  476.         * it's a threshold
  477.         * grab 'low' and 'high' params
  478.         */
  479.         if (!cp) {
  480.             config_perror("no lower threshold value specified");
  481.        }
  482.        cp = copy_nword(cp, buf, sizeof(buf));
  483.        StorageNew->mteTriggerThresholdFalling = strtol(buf, NULL, 0);
  484.         if (!cp) {
  485.             config_perror("no upper threshold value specified");
  486.        }
  487.        cp = copy_nword(cp, buf, sizeof(buf));
  488.        StorageNew->mteTriggerThresholdRising = strtol(buf, NULL, 0);
  489.     } else {
  490.         /*
  491.          * if nothing beyond here, it's an existence test 
  492.          */
  493.         if (!cp) {
  494.             StorageNew->mteTriggerTest[0] = (u_char)MTETRIGGERTEST_EXISTENCE;
  495.             if (eventname[0] != '') {
  496.                 StorageNew->mteTriggerExistenceEventOwner =
  497.                     strdup("snmpd.conf");
  498.                 StorageNew->mteTriggerExistenceEventOwnerLen =
  499.                     strlen(StorageNew->mteTriggerExistenceEventOwner);
  500.                 StorageNew->mteTriggerExistenceEvent =
  501.                     strdup(eventname);
  502.                 StorageNew->mteTriggerExistenceEventLen =
  503.                     strlen(eventname);
  504.             }
  505.             mteTriggerTable_add(StorageNew);
  506.             return;
  507.         }
  508.         /*
  509.          * assume boolean (need to deal with threshold statements) 
  510.          */
  511.         cp = copy_nword(cp, buf, sizeof(buf));
  512.         if ((StorageNew->mteTriggerBooleanComparison =
  513.              se_find_value_in_slist("mteBooleanOperators", buf)) == -1) {
  514.             config_perror("illegal boolean operator");
  515.             return;
  516.         }
  517.         /*
  518.          * XXX: add threshold 
  519.          */
  520.         StorageNew->mteTriggerTest[0] = MTETRIGGERTEST_BOOLEAN;
  521.         if (!cp) {
  522.             config_perror("no comparison value specified");
  523.             /*
  524.              * XXX: free StorageNew 
  525.              */
  526.             return;
  527.         }
  528.         cp = copy_nword(cp, buf, sizeof(buf));
  529.         StorageNew->mteTriggerBooleanValue = strtol(buf, NULL, 0);
  530.         if (eventname[0] != '') {
  531.             StorageNew->mteTriggerBooleanEventOwner =
  532.                 strdup("snmpd.conf");
  533.             StorageNew->mteTriggerBooleanEventOwnerLen =
  534.                 strlen(StorageNew->mteTriggerBooleanEventOwner);
  535.             StorageNew->mteTriggerBooleanEvent =
  536.                 strdup(eventname);
  537.             StorageNew->mteTriggerBooleanEventLen =
  538.                 strlen(eventname);
  539.         }
  540.     }
  541.     mteTriggerTable_add(StorageNew);
  542.     mte_enable_trigger(StorageNew);
  543.     DEBUGMSGTL(("mteTriggerTable", "added simple monitor: %sn",
  544.                 StorageNew->mteTriggerName));
  545. }
  546. /*
  547.  * parse_mteTriggerTable():
  548.  *   parses .conf file entries needed to configure the mib.
  549.  */
  550. void
  551. parse_mteTriggerTable(const char *token, char *line)
  552. {
  553.     size_t          tmpint;
  554.     oid            *tmpoid = NULL;
  555.     struct mteTriggerTable_data *StorageTmp =
  556.         SNMP_MALLOC_STRUCT(mteTriggerTable_data);
  557.     DEBUGMSGTL(("mteTriggerTable", "parsing config...  "));
  558.     if (StorageTmp == NULL) {
  559.         config_perror("malloc failure");
  560.         return;
  561.     }
  562.     line =
  563.         read_config_read_data(ASN_OCTET_STR, line, &StorageTmp->mteOwner,
  564.                               &StorageTmp->mteOwnerLen);
  565.     if (StorageTmp->mteOwner == NULL) {
  566.         config_perror("invalid specification for mteOwner");
  567.         return;
  568.     }
  569.     line =
  570.         read_config_read_data(ASN_OCTET_STR, line,
  571.                               &StorageTmp->mteTriggerName,
  572.                               &StorageTmp->mteTriggerNameLen);
  573.     if (StorageTmp->mteTriggerName == NULL) {
  574.         config_perror("invalid specification for mteTriggerName");
  575.         return;
  576.     }
  577.     line =
  578.         read_config_read_data(ASN_OCTET_STR, line,
  579.                               &StorageTmp->mteTriggerComment,
  580.                               &StorageTmp->mteTriggerCommentLen);
  581.     if (StorageTmp->mteTriggerComment == NULL) {
  582.         config_perror("invalid specification for mteTriggerComment");
  583.         return;
  584.     }
  585.     line =
  586.         read_config_read_data(ASN_OCTET_STR, line,
  587.                               &StorageTmp->mteTriggerTest,
  588.                               &StorageTmp->mteTriggerTestLen);
  589.     if (StorageTmp->mteTriggerTest == NULL) {
  590.         config_perror("invalid specification for mteTriggerTest");
  591.         return;
  592.     }
  593.     line =
  594.         read_config_read_data(ASN_INTEGER, line,
  595.                               &StorageTmp->mteTriggerSampleType, &tmpint);
  596.     line =
  597.         read_config_read_data(ASN_OBJECT_ID, line,
  598.                               &StorageTmp->mteTriggerValueID,
  599.                               &StorageTmp->mteTriggerValueIDLen);
  600.     if (StorageTmp->mteTriggerValueID == NULL) {
  601.         config_perror("invalid specification for mteTriggerValueID");
  602.         return;
  603.     }
  604.     line =
  605.         read_config_read_data(ASN_INTEGER, line,
  606.                               &StorageTmp->mteTriggerValueIDWildcard,
  607.                               &tmpint);
  608.     line =
  609.         read_config_read_data(ASN_OCTET_STR, line,
  610.                               &StorageTmp->mteTriggerTargetTag,
  611.                               &StorageTmp->mteTriggerTargetTagLen);
  612.     if (StorageTmp->mteTriggerTargetTag == NULL) {
  613.         config_perror("invalid specification for mteTriggerTargetTag");
  614.         return;
  615.     }
  616.     line =
  617.         read_config_read_data(ASN_OCTET_STR, line,
  618.                               &StorageTmp->mteTriggerContextName,
  619.                               &StorageTmp->mteTriggerContextNameLen);
  620.     if (StorageTmp->mteTriggerContextName == NULL) {
  621.         config_perror("invalid specification for mteTriggerContextName");
  622.         return;
  623.     }
  624.     line =
  625.         read_config_read_data(ASN_INTEGER, line,
  626.                               &StorageTmp->mteTriggerContextNameWildcard,
  627.                               &tmpint);
  628.     line =
  629.         read_config_read_data(ASN_UNSIGNED, line,
  630.                               &StorageTmp->mteTriggerFrequency, &tmpint);
  631.     line =
  632.         read_config_read_data(ASN_OCTET_STR, line,
  633.                               &StorageTmp->mteTriggerObjectsOwner,
  634.                               &StorageTmp->mteTriggerObjectsOwnerLen);
  635.     if (StorageTmp->mteTriggerObjectsOwner == NULL) {
  636.         config_perror("invalid specification for mteTriggerObjectsOwner");
  637.         return;
  638.     }
  639.     line =
  640.         read_config_read_data(ASN_OCTET_STR, line,
  641.                               &StorageTmp->mteTriggerObjects,
  642.                               &StorageTmp->mteTriggerObjectsLen);
  643.     if (StorageTmp->mteTriggerObjects == NULL) {
  644.         config_perror("invalid specification for mteTriggerObjects");
  645.         return;
  646.     }
  647.     line =
  648.         read_config_read_data(ASN_INTEGER, line,
  649.                               &StorageTmp->mteTriggerEnabled, &tmpint);
  650.     line =
  651.         read_config_read_data(ASN_INTEGER, line,
  652.                               &StorageTmp->mteTriggerEntryStatus, &tmpint);
  653.     /*
  654.      * delta table 
  655.      */
  656.     line =
  657.         read_config_read_data(ASN_OBJECT_ID, line,
  658.                               &StorageTmp->mteTriggerDeltaDiscontinuityID,
  659.                               &StorageTmp->
  660.                               mteTriggerDeltaDiscontinuityIDLen);
  661.     if (StorageTmp->mteTriggerDeltaDiscontinuityID == NULL) {
  662.         config_perror
  663.             ("invalid specification for mteTriggerDeltaDiscontinuityID");
  664.         return;
  665.     }
  666.     line =
  667.         read_config_read_data(ASN_INTEGER, line,
  668.                               &StorageTmp->
  669.                               mteTriggerDeltaDiscontinuityIDWildcard,
  670.                               &tmpint);
  671.     line =
  672.         read_config_read_data(ASN_INTEGER, line,
  673.                               &StorageTmp->
  674.                               mteTriggerDeltaDiscontinuityIDType, &tmpint);
  675.     /*
  676.      * existence table 
  677.      */
  678.     line =
  679.         read_config_read_data(ASN_OCTET_STR, line,
  680.                               &StorageTmp->mteTriggerExistenceTest,
  681.                               &StorageTmp->mteTriggerExistenceTestLen);
  682.     if (StorageTmp->mteTriggerExistenceTest == NULL) {
  683.         config_perror("invalid specification for mteTriggerExistenceTest");
  684.         return;
  685.     }
  686.     line =
  687.         read_config_read_data(ASN_OCTET_STR, line,
  688.                               &StorageTmp->mteTriggerExistenceStartup,
  689.                               &StorageTmp->mteTriggerExistenceStartupLen);
  690.     if (StorageTmp->mteTriggerExistenceStartup == NULL) {
  691.         config_perror
  692.             ("invalid specification for mteTriggerExistenceStartup");
  693.         return;
  694.     }
  695.     line =
  696.         read_config_read_data(ASN_OCTET_STR, line,
  697.                               &StorageTmp->mteTriggerExistenceObjectsOwner,
  698.                               &StorageTmp->
  699.                               mteTriggerExistenceObjectsOwnerLen);
  700.     if (StorageTmp->mteTriggerExistenceObjectsOwner == NULL) {
  701.         config_perror
  702.             ("invalid specification for mteTriggerExistenceObjectsOwner");
  703.         return;
  704.     }
  705.     line =
  706.         read_config_read_data(ASN_OCTET_STR, line,
  707.                               &StorageTmp->mteTriggerExistenceObjects,
  708.                               &StorageTmp->mteTriggerExistenceObjectsLen);
  709.     if (StorageTmp->mteTriggerExistenceObjects == NULL) {
  710.         config_perror
  711.             ("invalid specification for mteTriggerExistenceObjects");
  712.         return;
  713.     }
  714.     line =
  715.         read_config_read_data(ASN_OCTET_STR, line,
  716.                               &StorageTmp->mteTriggerExistenceEventOwner,
  717.                               &StorageTmp->
  718.                               mteTriggerExistenceEventOwnerLen);
  719.     if (StorageTmp->mteTriggerExistenceEventOwner == NULL) {
  720.         config_perror
  721.             ("invalid specification for mteTriggerExistenceEventOwner");
  722.         return;
  723.     }
  724.     line =
  725.         read_config_read_data(ASN_OCTET_STR, line,
  726.                               &StorageTmp->mteTriggerExistenceEvent,
  727.                               &StorageTmp->mteTriggerExistenceEventLen);
  728.     if (StorageTmp->mteTriggerExistenceEvent == NULL) {
  729.         config_perror
  730.             ("invalid specification for mteTriggerExistenceEvent");
  731.         return;
  732.     }
  733.     /*
  734.      * boolean table 
  735.      */
  736.     line =
  737.         read_config_read_data(ASN_INTEGER, line,
  738.                               &StorageTmp->mteTriggerBooleanComparison,
  739.                               &tmpint);
  740.     line =
  741.         read_config_read_data(ASN_INTEGER, line,
  742.                               &StorageTmp->mteTriggerBooleanValue,
  743.                               &tmpint);
  744.     line =
  745.         read_config_read_data(ASN_INTEGER, line,
  746.                               &StorageTmp->mteTriggerBooleanStartup,
  747.                               &tmpint);
  748.     line =
  749.         read_config_read_data(ASN_OCTET_STR, line,
  750.                               &StorageTmp->mteTriggerBooleanObjectsOwner,
  751.                               &StorageTmp->
  752.                               mteTriggerBooleanObjectsOwnerLen);
  753.     if (StorageTmp->mteTriggerBooleanObjectsOwner == NULL) {
  754.         config_perror
  755.             ("invalid specification for mteTriggerBooleanObjectsOwner");
  756.         return;
  757.     }
  758.     line =
  759.         read_config_read_data(ASN_OCTET_STR, line,
  760.                               &StorageTmp->mteTriggerBooleanObjects,
  761.                               &StorageTmp->mteTriggerBooleanObjectsLen);
  762.     if (StorageTmp->mteTriggerBooleanObjects == NULL) {
  763.         config_perror
  764.             ("invalid specification for mteTriggerBooleanObjects");
  765.         return;
  766.     }
  767.     line =
  768.         read_config_read_data(ASN_OCTET_STR, line,
  769.                               &StorageTmp->mteTriggerBooleanEventOwner,
  770.                               &StorageTmp->mteTriggerBooleanEventOwnerLen);
  771.     if (StorageTmp->mteTriggerBooleanEventOwner == NULL) {
  772.         config_perror
  773.             ("invalid specification for mteTriggerBooleanEventOwner");
  774.         return;
  775.     }
  776.     line =
  777.         read_config_read_data(ASN_OCTET_STR, line,
  778.                               &StorageTmp->mteTriggerBooleanEvent,
  779.                               &StorageTmp->mteTriggerBooleanEventLen);
  780.     if (StorageTmp->mteTriggerBooleanEvent == NULL) {
  781.         config_perror("invalid specification for mteTriggerBooleanEvent");
  782.         return;
  783.     }
  784.     /*
  785.      * threshold table 
  786.      */
  787.     line =
  788.         read_config_read_data(ASN_INTEGER, line,
  789.                               &StorageTmp->mteTriggerThresholdStartup,
  790.                               &tmpint);
  791.     line =
  792.         read_config_read_data(ASN_INTEGER, line,
  793.                               &StorageTmp->mteTriggerThresholdRising,
  794.                               &tmpint);
  795.     line =
  796.         read_config_read_data(ASN_INTEGER, line,
  797.                               &StorageTmp->mteTriggerThresholdFalling,
  798.                               &tmpint);
  799.     line =
  800.         read_config_read_data(ASN_INTEGER, line,
  801.                               &StorageTmp->mteTriggerThresholdDeltaRising,
  802.                               &tmpint);
  803.     line =
  804.         read_config_read_data(ASN_INTEGER, line,
  805.                               &StorageTmp->mteTriggerThresholdDeltaFalling,
  806.                               &tmpint);
  807.     line =
  808.         read_config_read_data(ASN_OCTET_STR, line,
  809.                               &StorageTmp->mteTriggerThresholdObjectsOwner,
  810.                               &StorageTmp->
  811.                               mteTriggerThresholdObjectsOwnerLen);
  812.     if (StorageTmp->mteTriggerThresholdObjectsOwner == NULL) {
  813.         config_perror
  814.             ("invalid specification for mteTriggerThresholdObjectsOwner");
  815.         return;
  816.     }
  817.     line =
  818.         read_config_read_data(ASN_OCTET_STR, line,
  819.                               &StorageTmp->mteTriggerThresholdObjects,
  820.                               &StorageTmp->mteTriggerThresholdObjectsLen);
  821.     if (StorageTmp->mteTriggerThresholdObjects == NULL) {
  822.         config_perror
  823.             ("invalid specification for mteTriggerThresholdObjects");
  824.         return;
  825.     }
  826.     line =
  827.         read_config_read_data(ASN_OCTET_STR, line,
  828.                               &StorageTmp->
  829.                               mteTriggerThresholdRisingEventOwner,
  830.                               &StorageTmp->
  831.                               mteTriggerThresholdRisingEventOwnerLen);
  832.     if (StorageTmp->mteTriggerThresholdRisingEventOwner == NULL) {
  833.         config_perror
  834.             ("invalid specification for mteTriggerThresholdRisingEventOwner");
  835.         return;
  836.     }
  837.     line =
  838.         read_config_read_data(ASN_OCTET_STR, line,
  839.                               &StorageTmp->mteTriggerThresholdRisingEvent,
  840.                               &StorageTmp->
  841.                               mteTriggerThresholdRisingEventLen);
  842.     if (StorageTmp->mteTriggerThresholdRisingEvent == NULL) {
  843.         config_perror
  844.             ("invalid specification for mteTriggerThresholdRisingEvent");
  845.         return;
  846.     }
  847.     line =
  848.         read_config_read_data(ASN_OCTET_STR, line,
  849.                               &StorageTmp->
  850.                               mteTriggerThresholdFallingEventOwner,
  851.                               &StorageTmp->
  852.                               mteTriggerThresholdFallingEventOwnerLen);
  853.     if (StorageTmp->mteTriggerThresholdFallingEventOwner == NULL) {
  854.         config_perror
  855.             ("invalid specification for mteTriggerThresholdFallingEventOwner");
  856.         return;
  857.     }
  858.     line =
  859.         read_config_read_data(ASN_OCTET_STR, line,
  860.                               &StorageTmp->mteTriggerThresholdFallingEvent,
  861.                               &StorageTmp->
  862.                               mteTriggerThresholdFallingEventLen);
  863.     if (StorageTmp->mteTriggerThresholdFallingEvent == NULL) {
  864.         config_perror
  865.             ("invalid specification for mteTriggerThresholdFallingEvent");
  866.         return;
  867.     }
  868.     line =
  869.         read_config_read_data(ASN_OCTET_STR, line,
  870.                               &StorageTmp->
  871.                               mteTriggerThresholdDeltaRisingEventOwner,
  872.                               &StorageTmp->
  873.                               mteTriggerThresholdDeltaRisingEventOwnerLen);
  874.     if (StorageTmp->mteTriggerThresholdDeltaRisingEventOwner == NULL) {
  875.         config_perror
  876.             ("invalid specification for mteTriggerThresholdDeltaRisingEventOwner");
  877.         return;
  878.     }
  879.     line =
  880.         read_config_read_data(ASN_OCTET_STR, line,
  881.                               &StorageTmp->
  882.                               mteTriggerThresholdDeltaRisingEvent,
  883.                               &StorageTmp->
  884.                               mteTriggerThresholdDeltaRisingEventLen);
  885.     if (StorageTmp->mteTriggerThresholdDeltaRisingEvent == NULL) {
  886.         config_perror
  887.             ("invalid specification for mteTriggerThresholdDeltaRisingEvent");
  888.         return;
  889.     }
  890.     line =
  891.         read_config_read_data(ASN_OCTET_STR, line,
  892.                               &StorageTmp->
  893.                               mteTriggerThresholdDeltaFallingEventOwner,
  894.                               &StorageTmp->
  895.                               mteTriggerThresholdDeltaFallingEventOwnerLen);
  896.     if (StorageTmp->mteTriggerThresholdDeltaFallingEventOwner == NULL) {
  897.         config_perror
  898.             ("invalid specification for mteTriggerThresholdDeltaFallingEventOwner");
  899.         return;
  900.     }
  901.     line =
  902.         read_config_read_data(ASN_OCTET_STR, line,
  903.                               &StorageTmp->
  904.                               mteTriggerThresholdDeltaFallingEvent,
  905.                               &StorageTmp->
  906.                               mteTriggerThresholdDeltaFallingEventLen);
  907.     if (StorageTmp->mteTriggerThresholdDeltaFallingEvent == NULL) {
  908.         config_perror
  909.             ("invalid specification for mteTriggerThresholdDeltaFallingEvent");
  910.         return;
  911.     }
  912.     /*
  913.      * local internal variables 
  914.      */
  915.     line =
  916.         read_config_read_data(ASN_INTEGER, line,
  917.                               &StorageTmp->have_copied_auth_info, &tmpint);
  918.     if (StorageTmp->have_copied_auth_info) {
  919.         line =
  920.             read_config_read_data(ASN_INTEGER, line,
  921.                                   &StorageTmp->pdu_version, &tmpint);
  922.         line =
  923.             read_config_read_data(ASN_INTEGER, line,
  924.                                   &StorageTmp->pdu_securityModel, &tmpint);
  925.         line =
  926.             read_config_read_data(ASN_INTEGER, line,
  927.                                   &StorageTmp->pdu_securityLevel, &tmpint);
  928.         line =
  929.             read_config_read_data(ASN_OBJECT_ID, line, &tmpoid, &tmpint);
  930.         if (!netsnmp_tdomain_support
  931.             (tmpoid, tmpint, &StorageTmp->pdu_tDomain,
  932.              &StorageTmp->pdu_tDomainLen)) {
  933.             config_perror
  934.                 ("unsupported transport domain for mteTriggerEntry");
  935.             return;
  936.         }
  937.         if (tmpoid != NULL) {
  938.             free(tmpoid);
  939.         }
  940.         /*
  941.          * can be NULL?  Yes.  
  942.          */
  943.         line = read_config_read_data(ASN_OCTET_STR, line,
  944.                                      &(StorageTmp->pdu_transport),
  945.                                      &StorageTmp->pdu_transportLen);
  946.         line =
  947.             read_config_read_data(ASN_OCTET_STR, line,
  948.                                   &StorageTmp->pdu_community,
  949.                                   &StorageTmp->pdu_community_len);
  950.         if (StorageTmp->pdu_community == NULL) {
  951.             config_perror("invalid specification for pdu_community");
  952.             return;
  953.         }
  954.         line =
  955.             read_config_read_data(ASN_OCTET_STR, line,
  956.                                   &StorageTmp->pdu_securityName,
  957.                                   &StorageTmp->pdu_securityNameLen);
  958.         if (StorageTmp->pdu_securityName == NULL) {
  959.             config_perror("invalid specification for pdu_securityName");
  960.             return;
  961.         }
  962.     }
  963.     StorageTmp->storageType = ST_NONVOLATILE;   /* the only type stored */
  964.     mteTriggerTable_add(StorageTmp);
  965.     /*
  966.      * technically this is too early 
  967.      */
  968.     if (StorageTmp->mteTriggerEnabled == MTETRIGGERENABLED_TRUE &&
  969.         StorageTmp->mteTriggerEntryStatus == RS_ACTIVE)
  970.         mte_enable_trigger(StorageTmp);
  971.     DEBUGMSGTL(("mteTriggerTable", "done.n"));
  972. }
  973. /*
  974.  * store_mteTriggerTable():
  975.  *   stores .conf file entries needed to configure the mib.
  976.  */
  977. int
  978. store_mteTriggerTable(int majorID, int minorID, void *serverarg,
  979.                       void *clientarg)
  980. {
  981.     char            line[SNMP_MAXBUF];
  982.     char           *cptr;
  983.     size_t          tmpint;
  984.     struct mteTriggerTable_data *StorageTmp;
  985.     struct header_complex_index *hcindex;
  986.     DEBUGMSGTL(("mteTriggerTable", "storing data...  "));
  987.     for (hcindex = mteTriggerTableStorage; hcindex != NULL;
  988.          hcindex = hcindex->next) {
  989.         StorageTmp = (struct mteTriggerTable_data *) hcindex->data;
  990.         if (StorageTmp->storageType == ST_NONVOLATILE) {
  991.             memset(line, 0, sizeof(line));
  992.             strcat(line, "mteTriggerTable ");
  993.             cptr = line + strlen(line);
  994.             cptr =
  995.                 read_config_store_data(ASN_OCTET_STR, cptr,
  996.                                        &StorageTmp->mteOwner,
  997.                                        &StorageTmp->mteOwnerLen);
  998.             cptr =
  999.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1000.                                        &StorageTmp->mteTriggerName,
  1001.                                        &StorageTmp->mteTriggerNameLen);
  1002.             cptr =
  1003.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1004.                                        &StorageTmp->mteTriggerComment,
  1005.                                        &StorageTmp->mteTriggerCommentLen);
  1006.             cptr =
  1007.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1008.                                        &StorageTmp->mteTriggerTest,
  1009.                                        &StorageTmp->mteTriggerTestLen);
  1010.             cptr =
  1011.                 read_config_store_data(ASN_INTEGER, cptr,
  1012.                                        &StorageTmp->mteTriggerSampleType,
  1013.                                        &tmpint);
  1014.             cptr =
  1015.                 read_config_store_data(ASN_OBJECT_ID, cptr,
  1016.                                        &StorageTmp->mteTriggerValueID,
  1017.                                        &StorageTmp->mteTriggerValueIDLen);
  1018.             cptr =
  1019.                 read_config_store_data(ASN_INTEGER, cptr,
  1020.                                        &StorageTmp->
  1021.                                        mteTriggerValueIDWildcard, &tmpint);
  1022.             cptr =
  1023.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1024.                                        &StorageTmp->mteTriggerTargetTag,
  1025.                                        &StorageTmp->
  1026.                                        mteTriggerTargetTagLen);
  1027.             cptr =
  1028.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1029.                                        &StorageTmp->mteTriggerContextName,
  1030.                                        &StorageTmp->
  1031.                                        mteTriggerContextNameLen);
  1032.             cptr =
  1033.                 read_config_store_data(ASN_INTEGER, cptr,
  1034.                                        &StorageTmp->
  1035.                                        mteTriggerContextNameWildcard,
  1036.                                        &tmpint);
  1037.             cptr =
  1038.                 read_config_store_data(ASN_UNSIGNED, cptr,
  1039.                                        &StorageTmp->mteTriggerFrequency,
  1040.                                        &tmpint);
  1041.             cptr =
  1042.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1043.                                        &StorageTmp->mteTriggerObjectsOwner,
  1044.                                        &StorageTmp->
  1045.                                        mteTriggerObjectsOwnerLen);
  1046.             cptr =
  1047.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1048.                                        &StorageTmp->mteTriggerObjects,
  1049.                                        &StorageTmp->mteTriggerObjectsLen);
  1050.             cptr =
  1051.                 read_config_store_data(ASN_INTEGER, cptr,
  1052.                                        &StorageTmp->mteTriggerEnabled,
  1053.                                        &tmpint);
  1054.             cptr =
  1055.                 read_config_store_data(ASN_INTEGER, cptr,
  1056.                                        &StorageTmp->mteTriggerEntryStatus,
  1057.                                        &tmpint);
  1058.             /*
  1059.              * delta table 
  1060.              */
  1061.             cptr =
  1062.                 read_config_store_data(ASN_OBJECT_ID, cptr,
  1063.                                        &StorageTmp->
  1064.                                        mteTriggerDeltaDiscontinuityID,
  1065.                                        &StorageTmp->
  1066.                                        mteTriggerDeltaDiscontinuityIDLen);
  1067.             cptr =
  1068.                 read_config_store_data(ASN_INTEGER, cptr,
  1069.                                        &StorageTmp->
  1070.                                        mteTriggerDeltaDiscontinuityIDWildcard,
  1071.                                        &tmpint);
  1072.             cptr =
  1073.                 read_config_store_data(ASN_INTEGER, cptr,
  1074.                                        &StorageTmp->
  1075.                                        mteTriggerDeltaDiscontinuityIDType,
  1076.                                        &tmpint);
  1077.             /*
  1078.              * existence table 
  1079.              */
  1080.             cptr =
  1081.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1082.                                        &StorageTmp->
  1083.                                        mteTriggerExistenceTest,
  1084.                                        &StorageTmp->
  1085.                                        mteTriggerExistenceTestLen);
  1086.             cptr =
  1087.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1088.                                        &StorageTmp->
  1089.                                        mteTriggerExistenceStartup,
  1090.                                        &StorageTmp->
  1091.                                        mteTriggerExistenceStartupLen);
  1092.             cptr =
  1093.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1094.                                        &StorageTmp->
  1095.                                        mteTriggerExistenceObjectsOwner,
  1096.                                        &StorageTmp->
  1097.                                        mteTriggerExistenceObjectsOwnerLen);
  1098.             cptr =
  1099.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1100.                                        &StorageTmp->
  1101.                                        mteTriggerExistenceObjects,
  1102.                                        &StorageTmp->
  1103.                                        mteTriggerExistenceObjectsLen);
  1104.             cptr =
  1105.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1106.                                        &StorageTmp->
  1107.                                        mteTriggerExistenceEventOwner,
  1108.                                        &StorageTmp->
  1109.                                        mteTriggerExistenceEventOwnerLen);
  1110.             cptr =
  1111.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1112.                                        &StorageTmp->
  1113.                                        mteTriggerExistenceEvent,
  1114.                                        &StorageTmp->
  1115.                                        mteTriggerExistenceEventLen);
  1116.             /*
  1117.              * boolean table 
  1118.              */
  1119.             cptr =
  1120.                 read_config_store_data(ASN_INTEGER, cptr,
  1121.                                        &StorageTmp->
  1122.                                        mteTriggerBooleanComparison,
  1123.                                        &tmpint);
  1124.             cptr =
  1125.                 read_config_store_data(ASN_INTEGER, cptr,
  1126.                                        &StorageTmp->mteTriggerBooleanValue,
  1127.                                        &tmpint);
  1128.             cptr =
  1129.                 read_config_store_data(ASN_INTEGER, cptr,
  1130.                                        &StorageTmp->
  1131.                                        mteTriggerBooleanStartup, &tmpint);
  1132.             cptr =
  1133.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1134.                                        &StorageTmp->
  1135.                                        mteTriggerBooleanObjectsOwner,
  1136.                                        &StorageTmp->
  1137.                                        mteTriggerBooleanObjectsOwnerLen);
  1138.             cptr =
  1139.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1140.                                        &StorageTmp->
  1141.                                        mteTriggerBooleanObjects,
  1142.                                        &StorageTmp->
  1143.                                        mteTriggerBooleanObjectsLen);
  1144.             cptr =
  1145.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1146.                                        &StorageTmp->
  1147.                                        mteTriggerBooleanEventOwner,
  1148.                                        &StorageTmp->
  1149.                                        mteTriggerBooleanEventOwnerLen);
  1150.             cptr =
  1151.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1152.                                        &StorageTmp->mteTriggerBooleanEvent,
  1153.                                        &StorageTmp->
  1154.                                        mteTriggerBooleanEventLen);
  1155.             /*
  1156.              * threshold table 
  1157.              */
  1158.             cptr =
  1159.                 read_config_store_data(ASN_INTEGER, cptr,
  1160.                                        &StorageTmp->
  1161.                                        mteTriggerThresholdStartup,
  1162.                                        &tmpint);
  1163.             cptr =
  1164.                 read_config_store_data(ASN_INTEGER, cptr,
  1165.                                        &StorageTmp->
  1166.                                        mteTriggerThresholdRising, &tmpint);
  1167.             cptr =
  1168.                 read_config_store_data(ASN_INTEGER, cptr,
  1169.                                        &StorageTmp->
  1170.                                        mteTriggerThresholdFalling,
  1171.                                        &tmpint);
  1172.             cptr =
  1173.                 read_config_store_data(ASN_INTEGER, cptr,
  1174.                                        &StorageTmp->
  1175.                                        mteTriggerThresholdDeltaRising,
  1176.                                        &tmpint);
  1177.             cptr =
  1178.                 read_config_store_data(ASN_INTEGER, cptr,
  1179.                                        &StorageTmp->
  1180.                                        mteTriggerThresholdDeltaFalling,
  1181.                                        &tmpint);
  1182.             cptr =
  1183.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1184.                                        &StorageTmp->
  1185.                                        mteTriggerThresholdObjectsOwner,
  1186.                                        &StorageTmp->
  1187.                                        mteTriggerThresholdObjectsOwnerLen);
  1188.             cptr =
  1189.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1190.                                        &StorageTmp->
  1191.                                        mteTriggerThresholdObjects,
  1192.                                        &StorageTmp->
  1193.                                        mteTriggerThresholdObjectsLen);
  1194.             cptr =
  1195.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1196.                                        &StorageTmp->
  1197.                                        mteTriggerThresholdRisingEventOwner,
  1198.                                        &StorageTmp->
  1199.                                        mteTriggerThresholdRisingEventOwnerLen);
  1200.             cptr =
  1201.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1202.                                        &StorageTmp->
  1203.                                        mteTriggerThresholdRisingEvent,
  1204.                                        &StorageTmp->
  1205.                                        mteTriggerThresholdRisingEventLen);
  1206.             cptr =
  1207.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1208.                                        &StorageTmp->
  1209.                                        mteTriggerThresholdFallingEventOwner,
  1210.                                        &StorageTmp->
  1211.                                        mteTriggerThresholdFallingEventOwnerLen);
  1212.             cptr =
  1213.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1214.                                        &StorageTmp->
  1215.                                        mteTriggerThresholdFallingEvent,
  1216.                                        &StorageTmp->
  1217.                                        mteTriggerThresholdFallingEventLen);
  1218.             cptr =
  1219.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1220.                                        &StorageTmp->
  1221.                                        mteTriggerThresholdDeltaRisingEventOwner,
  1222.                                        &StorageTmp->
  1223.                                        mteTriggerThresholdDeltaRisingEventOwnerLen);
  1224.             cptr =
  1225.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1226.                                        &StorageTmp->
  1227.                                        mteTriggerThresholdDeltaRisingEvent,
  1228.                                        &StorageTmp->
  1229.                                        mteTriggerThresholdDeltaRisingEventLen);
  1230.             cptr =
  1231.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1232.                                        &StorageTmp->
  1233.                                        mteTriggerThresholdDeltaFallingEventOwner,
  1234.                                        &StorageTmp->
  1235.                                        mteTriggerThresholdDeltaFallingEventOwnerLen);
  1236.             cptr =
  1237.                 read_config_store_data(ASN_OCTET_STR, cptr,
  1238.                                        &StorageTmp->
  1239.                                        mteTriggerThresholdDeltaFallingEvent,
  1240.                                        &StorageTmp->
  1241.                                        mteTriggerThresholdDeltaFallingEventLen);
  1242.             /*
  1243.              * local internal variables 
  1244.              */
  1245.             cptr =
  1246.                 read_config_store_data(ASN_INTEGER, cptr,
  1247.                                        &StorageTmp->have_copied_auth_info,
  1248.                                        &tmpint);
  1249.             if (StorageTmp->have_copied_auth_info) {
  1250.                 cptr =
  1251.                     read_config_store_data(ASN_INTEGER, cptr,
  1252.                                            &StorageTmp->pdu_version,
  1253.                                            &tmpint);
  1254.                 cptr =
  1255.                     read_config_store_data(ASN_INTEGER, cptr,
  1256.                                            &StorageTmp->pdu_securityModel,
  1257.                                            &tmpint);
  1258.                 cptr =
  1259.                     read_config_store_data(ASN_INTEGER, cptr,
  1260.                                            &StorageTmp->pdu_securityLevel,
  1261.                                            &tmpint);
  1262.                 cptr =
  1263.                     read_config_store_data(ASN_OBJECT_ID, cptr,
  1264.                                            (void *)(&StorageTmp->pdu_tDomain),
  1265.                                            &StorageTmp->pdu_tDomainLen);
  1266.                 cptr =
  1267.                     read_config_store_data(ASN_OCTET_STR, cptr,
  1268.                                            &StorageTmp->pdu_transport,
  1269.                                            &StorageTmp->pdu_transportLen);
  1270.                 cptr =
  1271.                     read_config_store_data(ASN_OCTET_STR, cptr,
  1272.                                            &StorageTmp->pdu_community,
  1273.                                            &StorageTmp->pdu_community_len);
  1274.                 cptr =
  1275.                     read_config_store_data(ASN_OCTET_STR, cptr,
  1276.                                            &StorageTmp->pdu_securityName,
  1277.                                            &StorageTmp->
  1278.                                            pdu_securityNameLen);
  1279.             }
  1280.             snmpd_store_config(line);
  1281.         }
  1282.     }
  1283.     DEBUGMSGTL(("mteTriggerTable", "done.n"));
  1284.     return SNMPERR_SUCCESS;
  1285. }
  1286. /*
  1287.  * var_mteTriggerTable():
  1288.  *   Handle this table separately from the scalar value case.
  1289.  *   The workings of this are basically the same as for var_mteTriggerTable above.
  1290.  */
  1291. unsigned char  *
  1292. var_mteTriggerTable(struct variable *vp,
  1293.                     oid * name,
  1294.                     size_t * length,
  1295.                     int exact,
  1296.                     size_t * var_len, WriteMethod ** write_method)
  1297. {
  1298.     struct mteTriggerTable_data *StorageTmp = NULL;
  1299.     DEBUGMSGTL(("mteTriggerTable",
  1300.                 "var_mteTriggerTable: Entering...  n"));
  1301.     /*
  1302.      * this assumes you have registered all your data properly
  1303.      */
  1304.     if ((StorageTmp =
  1305.          header_complex(mteTriggerTableStorage, vp, name, length, exact,
  1306.                         var_len, write_method)) == NULL) {
  1307.         if (vp->magic == MTETRIGGERENTRYSTATUS)
  1308.             *write_method = write_mteTriggerEntryStatus;
  1309.         return NULL;
  1310.     }
  1311.     /*
  1312.      * this is where we do the value assignments for the mib results.
  1313.      */
  1314.     switch (vp->magic) {
  1315.     case MTETRIGGERCOMMENT:
  1316.         *write_method = write_mteTriggerComment;
  1317.         *var_len = StorageTmp->mteTriggerCommentLen;
  1318.         return (u_char *) StorageTmp->mteTriggerComment;
  1319.     case MTETRIGGERTEST:
  1320.         *write_method = write_mteTriggerTest;
  1321.         *var_len = StorageTmp->mteTriggerTestLen;
  1322.         return (u_char *) StorageTmp->mteTriggerTest;
  1323.     case MTETRIGGERSAMPLETYPE:
  1324.         *write_method = write_mteTriggerSampleType;
  1325.         *var_len = sizeof(StorageTmp->mteTriggerSampleType);
  1326.         return (u_char *) & StorageTmp->mteTriggerSampleType;
  1327.     case MTETRIGGERVALUEID:
  1328.         *write_method = write_mteTriggerValueID;
  1329.         *var_len = StorageTmp->mteTriggerValueIDLen * sizeof(oid);
  1330.         return (u_char *) StorageTmp->mteTriggerValueID;
  1331.     case MTETRIGGERVALUEIDWILDCARD:
  1332.         *write_method = write_mteTriggerValueIDWildcard;
  1333.         *var_len = sizeof(StorageTmp->mteTriggerValueIDWildcard);
  1334.         return (u_char *) & StorageTmp->mteTriggerValueIDWildcard;
  1335.     case MTETRIGGERTARGETTAG:
  1336.         *write_method = write_mteTriggerTargetTag;
  1337.         *var_len = StorageTmp->mteTriggerTargetTagLen;
  1338.         return (u_char *) StorageTmp->mteTriggerTargetTag;
  1339.     case MTETRIGGERCONTEXTNAME:
  1340.         *write_method = write_mteTriggerContextName;
  1341.         *var_len = StorageTmp->mteTriggerContextNameLen;
  1342.         return (u_char *) StorageTmp->mteTriggerContextName;
  1343.     case MTETRIGGERCONTEXTNAMEWILDCARD:
  1344.         *write_method = write_mteTriggerContextNameWildcard;
  1345.         *var_len = sizeof(StorageTmp->mteTriggerContextNameWildcard);
  1346.         return (u_char *) & StorageTmp->mteTriggerContextNameWildcard;
  1347.     case MTETRIGGERFREQUENCY:
  1348.         *write_method = write_mteTriggerFrequency;
  1349.         *var_len = sizeof(StorageTmp->mteTriggerFrequency);
  1350.         return (u_char *) & StorageTmp->mteTriggerFrequency;
  1351.     case MTETRIGGEROBJECTSOWNER:
  1352.         *write_method = write_mteTriggerObjectsOwner;
  1353.         *var_len = StorageTmp->mteTriggerObjectsOwnerLen;
  1354.         return (u_char *) StorageTmp->mteTriggerObjectsOwner;
  1355.     case MTETRIGGEROBJECTS:
  1356.         *write_method = write_mteTriggerObjects;
  1357.         *var_len = StorageTmp->mteTriggerObjectsLen;
  1358.         return (u_char *) StorageTmp->mteTriggerObjects;
  1359.     case MTETRIGGERENABLED:
  1360.         *write_method = write_mteTriggerEnabled;
  1361.         *var_len = sizeof(StorageTmp->mteTriggerEnabled);
  1362.         return (u_char *) & StorageTmp->mteTriggerEnabled;
  1363.     case MTETRIGGERENTRYSTATUS:
  1364.         *write_method = write_mteTriggerEntryStatus;
  1365.         *var_len = sizeof(StorageTmp->mteTriggerEntryStatus);
  1366.         return (u_char *) & StorageTmp->mteTriggerEntryStatus;
  1367.     default:
  1368.         ERROR_MSG("");
  1369.     }
  1370.     return NULL;
  1371. }
  1372. int
  1373. write_mteTriggerComment(int action,
  1374.                         u_char * var_val,
  1375.                         u_char var_val_type,
  1376.                         size_t var_val_len,
  1377.                         u_char * statP, oid * name, size_t name_len)
  1378. {
  1379.     static char    *tmpvar;
  1380.     struct mteTriggerTable_data *StorageTmp = NULL;
  1381.     static size_t   tmplen;
  1382.     size_t          newlen =
  1383.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  1384.                     3 - 1);
  1385.     DEBUGMSGTL(("mteTriggerTable",
  1386.                 "write_mteTriggerComment entering action=%d...  n",
  1387.                 action));
  1388.     if ((StorageTmp =
  1389.          header_complex(mteTriggerTableStorage, NULL,
  1390.                         &name[sizeof(mteTriggerTable_variables_oid) /
  1391.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  1392.                         NULL)) == NULL)
  1393.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  1394.     switch (action) {
  1395.     case RESERVE1:
  1396.         if (var_val_type != ASN_OCTET_STR) {
  1397.             snmp_log(LOG_ERR,
  1398.                      "write to mteTriggerComment not ASN_OCTET_STRn");
  1399.             return SNMP_ERR_WRONGTYPE;
  1400.         }
  1401.         if (StorageTmp->storageType != ST_NONVOLATILE)
  1402.             return SNMP_ERR_NOTWRITABLE;
  1403.         break;
  1404.     case RESERVE2:
  1405.         /*
  1406.          * memory reseveration, final preparation... 
  1407.          */
  1408.         break;
  1409.     case FREE:
  1410.         /*
  1411.          * Release any resources that have been allocated 
  1412.          */
  1413.         break;
  1414.     case ACTION:
  1415.         /*
  1416.          * The variable has been stored in string for
  1417.          * you to use, and you have just been asked to do something with
  1418.          * it.  Note that anything done here must be reversable in the UNDO case 
  1419.          */
  1420.         tmpvar = StorageTmp->mteTriggerComment;
  1421.         tmplen = StorageTmp->mteTriggerCommentLen;
  1422.         memdup((u_char **) & StorageTmp->mteTriggerComment, var_val,
  1423.                var_val_len);
  1424.         StorageTmp->mteTriggerCommentLen = var_val_len;
  1425.         break;
  1426.     case UNDO:
  1427.         /*
  1428.          * Back out any changes made in the ACTION case 
  1429.          */
  1430.         SNMP_FREE(StorageTmp->mteTriggerComment);
  1431.         StorageTmp->mteTriggerComment = tmpvar;
  1432.         StorageTmp->mteTriggerCommentLen = tmplen;
  1433.         break;
  1434.     case COMMIT:
  1435.         /*
  1436.          * Things are working well, so it's now safe to make the change
  1437.          * permanently.  Make sure that anything done here can't fail! 
  1438.          */
  1439.         SNMP_FREE(tmpvar);
  1440.         break;
  1441.     }
  1442.     return SNMP_ERR_NOERROR;
  1443. }
  1444. int
  1445. write_mteTriggerTest(int action,
  1446.                      u_char * var_val,
  1447.                      u_char var_val_type,
  1448.                      size_t var_val_len,
  1449.                      u_char * statP, oid * name, size_t name_len)
  1450. {
  1451.     static char    *tmpvar;
  1452.     struct mteTriggerTable_data *StorageTmp = NULL;
  1453.     static size_t   tmplen;
  1454.     size_t          newlen =
  1455.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  1456.                     3 - 1);
  1457.     DEBUGMSGTL(("mteTriggerTable",
  1458.                 "write_mteTriggerTest entering action=%d...  n", action));
  1459.     if ((StorageTmp =
  1460.          header_complex(mteTriggerTableStorage, NULL,
  1461.                         &name[sizeof(mteTriggerTable_variables_oid) /
  1462.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  1463.                         NULL)) == NULL)
  1464.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  1465.     switch (action) {
  1466.     case RESERVE1:
  1467.         if (var_val_type != ASN_OCTET_STR) {
  1468.             snmp_log(LOG_ERR, "write to mteTriggerTest not ASN_OCTET_STRn");
  1469.             return SNMP_ERR_WRONGTYPE;
  1470.         }
  1471.         if (StorageTmp->storageType != ST_NONVOLATILE)
  1472.             return SNMP_ERR_NOTWRITABLE;
  1473.         break;
  1474.     case RESERVE2:
  1475.         /*
  1476.          * memory reseveration, final preparation... 
  1477.          */
  1478.         break;
  1479.     case FREE:
  1480.         /*
  1481.          * Release any resources that have been allocated 
  1482.          */
  1483.         break;
  1484.     case ACTION:
  1485.         /*
  1486.          * The variable has been stored in string for
  1487.          * you to use, and you have just been asked to do something with
  1488.          * it.  Note that anything done here must be reversable in the UNDO case 
  1489.          */
  1490.         tmpvar = StorageTmp->mteTriggerTest;
  1491.         tmplen = StorageTmp->mteTriggerTestLen;
  1492.         memdup((u_char **) & StorageTmp->mteTriggerTest, var_val,
  1493.                var_val_len);
  1494.         StorageTmp->mteTriggerTestLen = var_val_len;
  1495.         break;
  1496.     case UNDO:
  1497.         /*
  1498.          * Back out any changes made in the ACTION case 
  1499.          */
  1500.         SNMP_FREE(StorageTmp->mteTriggerTest);
  1501.         StorageTmp->mteTriggerTest = tmpvar;
  1502.         StorageTmp->mteTriggerTestLen = tmplen;
  1503.         break;
  1504.     case COMMIT:
  1505.         /*
  1506.          * Things are working well, so it's now safe to make the change
  1507.          * permanently.  Make sure that anything done here can't fail! 
  1508.          */
  1509.         SNMP_FREE(tmpvar);
  1510.         break;
  1511.     }
  1512.     return SNMP_ERR_NOERROR;
  1513. }
  1514. int
  1515. write_mteTriggerSampleType(int action,
  1516.                            u_char * var_val,
  1517.                            u_char var_val_type,
  1518.                            size_t var_val_len,
  1519.                            u_char * statP, oid * name, size_t name_len)
  1520. {
  1521.     static int      tmpvar;
  1522.     struct mteTriggerTable_data *StorageTmp = NULL;
  1523.     size_t          newlen =
  1524.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  1525.                     3 - 1);
  1526.     DEBUGMSGTL(("mteTriggerTable",
  1527.                 "write_mteTriggerSampleType entering action=%d...  n",
  1528.                 action));
  1529.     if ((StorageTmp =
  1530.          header_complex(mteTriggerTableStorage, NULL,
  1531.                         &name[sizeof(mteTriggerTable_variables_oid) /
  1532.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  1533.                         NULL)) == NULL)
  1534.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  1535.     switch (action) {
  1536.     case RESERVE1:
  1537.         if (var_val_type != ASN_INTEGER) {
  1538.             snmp_log(LOG_ERR,
  1539.                      "write to mteTriggerSampleType not ASN_INTEGERn");
  1540.             return SNMP_ERR_WRONGTYPE;
  1541.         }
  1542.         if (StorageTmp->storageType != ST_NONVOLATILE)
  1543.             return SNMP_ERR_NOTWRITABLE;
  1544.         break;
  1545.     case RESERVE2:
  1546.         /*
  1547.          * memory reseveration, final preparation... 
  1548.          */
  1549.         break;
  1550.     case FREE:
  1551.         /*
  1552.          * Release any resources that have been allocated 
  1553.          */
  1554.         break;
  1555.     case ACTION:
  1556.         /*
  1557.          * The variable has been stored in long_ret for
  1558.          * you to use, and you have just been asked to do something with
  1559.          * it.  Note that anything done here must be reversable in the UNDO case 
  1560.          */
  1561.         tmpvar = StorageTmp->mteTriggerSampleType;
  1562.         StorageTmp->mteTriggerSampleType = *((long *) var_val);
  1563.         break;
  1564.     case UNDO:
  1565.         /*
  1566.          * Back out any changes made in the ACTION case 
  1567.          */
  1568.         StorageTmp->mteTriggerSampleType = tmpvar;
  1569.         break;
  1570.     case COMMIT:
  1571.         /*
  1572.          * Things are working well, so it's now safe to make the change
  1573.          * permanently.  Make sure that anything done here can't fail! 
  1574.          */
  1575.         break;
  1576.     }
  1577.     return SNMP_ERR_NOERROR;
  1578. }
  1579. int
  1580. write_mteTriggerValueID(int action,
  1581.                         u_char * var_val,
  1582.                         u_char var_val_type,
  1583.                         size_t var_val_len,
  1584.                         u_char * statP, oid * name, size_t name_len)
  1585. {
  1586.     static oid     *tmpvar;
  1587.     struct mteTriggerTable_data *StorageTmp = NULL;
  1588.     static size_t   tmplen;
  1589.     size_t          newlen =
  1590.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  1591.                     3 - 1);
  1592.     DEBUGMSGTL(("mteTriggerTable",
  1593.                 "write_mteTriggerValueID entering action=%d...  n",
  1594.                 action));
  1595.     if ((StorageTmp =
  1596.          header_complex(mteTriggerTableStorage, NULL,
  1597.                         &name[sizeof(mteTriggerTable_variables_oid) /
  1598.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  1599.                         NULL)) == NULL)
  1600.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  1601.     switch (action) {
  1602.     case RESERVE1:
  1603.         if (var_val_type != ASN_OBJECT_ID) {
  1604.             snmp_log(LOG_ERR,
  1605.                      "write to mteTriggerValueID not ASN_OBJECT_IDn");
  1606.             return SNMP_ERR_WRONGTYPE;
  1607.         }
  1608.         if (StorageTmp->storageType != ST_NONVOLATILE)
  1609.             return SNMP_ERR_NOTWRITABLE;
  1610.         break;
  1611.     case RESERVE2:
  1612.         /*
  1613.          * memory reseveration, final preparation... 
  1614.          */
  1615.         break;
  1616.     case FREE:
  1617.         /*
  1618.          * Release any resources that have been allocated 
  1619.          */
  1620.         break;
  1621.     case ACTION:
  1622.         /*
  1623.          * The variable has been stored in objid for
  1624.          * you to use, and you have just been asked to do something with
  1625.          * it.  Note that anything done here must be reversable in the UNDO case 
  1626.          */
  1627.         tmpvar = StorageTmp->mteTriggerValueID;
  1628.         tmplen = StorageTmp->mteTriggerValueIDLen;
  1629.         memdup((u_char **) & StorageTmp->mteTriggerValueID, var_val,
  1630.                var_val_len);
  1631.         StorageTmp->mteTriggerValueIDLen = var_val_len / sizeof(oid);
  1632.         break;
  1633.     case UNDO:
  1634.         /*
  1635.          * Back out any changes made in the ACTION case 
  1636.          */
  1637.         SNMP_FREE(StorageTmp->mteTriggerValueID);
  1638.         StorageTmp->mteTriggerValueID = tmpvar;
  1639.         StorageTmp->mteTriggerValueIDLen = tmplen;
  1640.         break;
  1641.     case COMMIT:
  1642.         /*
  1643.          * Things are working well, so it's now safe to make the change
  1644.          * permanently.  Make sure that anything done here can't fail! 
  1645.          */
  1646.         /*
  1647.          * XXX: if the valueID has actually changed, shouldn't we dump any
  1648.          * previous values, as these are from a different object?  
  1649.          */
  1650.         SNMP_FREE(tmpvar);
  1651.         break;
  1652.     }
  1653.     return SNMP_ERR_NOERROR;
  1654. }
  1655. int
  1656. write_mteTriggerValueIDWildcard(int action,
  1657.                                 u_char * var_val,
  1658.                                 u_char var_val_type,
  1659.                                 size_t var_val_len,
  1660.                                 u_char * statP,
  1661.                                 oid * name, size_t name_len)
  1662. {
  1663.     static int      tmpvar;
  1664.     struct mteTriggerTable_data *StorageTmp = NULL;
  1665.     size_t          newlen =
  1666.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  1667.                     3 - 1);
  1668.     DEBUGMSGTL(("mteTriggerTable",
  1669.                 "write_mteTriggerValueIDWildcard entering action=%d...  n",
  1670.                 action));
  1671.     if ((StorageTmp =
  1672.          header_complex(mteTriggerTableStorage, NULL,
  1673.                         &name[sizeof(mteTriggerTable_variables_oid) /
  1674.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  1675.                         NULL)) == NULL)
  1676.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  1677.     switch (action) {
  1678.     case RESERVE1:
  1679.         if (var_val_type != ASN_INTEGER) {
  1680.             snmp_log(LOG_ERR,
  1681.                      "write to mteTriggerValueIDWildcard not ASN_INTEGERn");
  1682.             return SNMP_ERR_WRONGTYPE;
  1683.         }
  1684.         if (StorageTmp->storageType != ST_NONVOLATILE)
  1685.             return SNMP_ERR_NOTWRITABLE;
  1686.         break;
  1687.     case RESERVE2:
  1688.         /*
  1689.          * memory reseveration, final preparation... 
  1690.          */
  1691.         break;
  1692.     case FREE:
  1693.         /*
  1694.          * Release any resources that have been allocated 
  1695.          */
  1696.         break;
  1697.     case ACTION:
  1698.         /*
  1699.          * The variable has been stored in long_ret for
  1700.          * you to use, and you have just been asked to do something with
  1701.          * it.  Note that anything done here must be reversable in the UNDO case 
  1702.          */
  1703.         tmpvar = StorageTmp->mteTriggerValueIDWildcard;
  1704.         StorageTmp->mteTriggerValueIDWildcard = *((long *) var_val);
  1705.         break;
  1706.     case UNDO:
  1707.         /*
  1708.          * Back out any changes made in the ACTION case 
  1709.          */
  1710.         StorageTmp->mteTriggerValueIDWildcard = tmpvar;
  1711.         break;
  1712.     case COMMIT:
  1713.         /*
  1714.          * Things are working well, so it's now safe to make the change
  1715.          * permanently.  Make sure that anything done here can't fail! 
  1716.          */
  1717.         break;
  1718.     }
  1719.     return SNMP_ERR_NOERROR;
  1720. }
  1721. int
  1722. write_mteTriggerTargetTag(int action,
  1723.                           u_char * var_val,
  1724.                           u_char var_val_type,
  1725.                           size_t var_val_len,
  1726.                           u_char * statP, oid * name, size_t name_len)
  1727. {
  1728.     static char    *tmpvar;
  1729.     struct mteTriggerTable_data *StorageTmp = NULL;
  1730.     static size_t   tmplen;
  1731.     size_t          newlen =
  1732.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  1733.                     3 - 1);
  1734.     DEBUGMSGTL(("mteTriggerTable",
  1735.                 "write_mteTriggerTargetTag entering action=%d...  n",
  1736.                 action));
  1737.     if ((StorageTmp =
  1738.          header_complex(mteTriggerTableStorage, NULL,
  1739.                         &name[sizeof(mteTriggerTable_variables_oid) /
  1740.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  1741.                         NULL)) == NULL)
  1742.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  1743.     switch (action) {
  1744.     case RESERVE1:
  1745.         if (var_val_type != ASN_OCTET_STR) {
  1746.             snmp_log(LOG_ERR,
  1747.                      "write to mteTriggerTargetTag not ASN_OCTET_STRn");
  1748.             return SNMP_ERR_WRONGTYPE;
  1749.         }
  1750.         if (StorageTmp->storageType != ST_NONVOLATILE)
  1751.             return SNMP_ERR_NOTWRITABLE;
  1752.         break;
  1753.     case RESERVE2:
  1754.         /*
  1755.          * memory reseveration, final preparation... 
  1756.          */
  1757.         break;
  1758.     case FREE:
  1759.         /*
  1760.          * Release any resources that have been allocated 
  1761.          */
  1762.         break;
  1763.     case ACTION:
  1764.         /*
  1765.          * The variable has been stored in string for
  1766.          * you to use, and you have just been asked to do something with
  1767.          * it.  Note that anything done here must be reversable in the UNDO case 
  1768.          */
  1769.         tmpvar = StorageTmp->mteTriggerTargetTag;
  1770.         tmplen = StorageTmp->mteTriggerTargetTagLen;
  1771.         memdup((u_char **) & StorageTmp->mteTriggerTargetTag, var_val,
  1772.                var_val_len);
  1773.         StorageTmp->mteTriggerTargetTagLen = var_val_len;
  1774.         break;
  1775.     case UNDO:
  1776.         /*
  1777.          * Back out any changes made in the ACTION case 
  1778.          */
  1779.         SNMP_FREE(StorageTmp->mteTriggerTargetTag);
  1780.         StorageTmp->mteTriggerTargetTag = tmpvar;
  1781.         StorageTmp->mteTriggerTargetTagLen = tmplen;
  1782.         break;
  1783.     case COMMIT:
  1784.         /*
  1785.          * Things are working well, so it's now safe to make the change
  1786.          * permanently.  Make sure that anything done here can't fail! 
  1787.          */
  1788.         SNMP_FREE(tmpvar);
  1789.         break;
  1790.     }
  1791.     return SNMP_ERR_NOERROR;
  1792. }
  1793. int
  1794. write_mteTriggerContextName(int action,
  1795.                             u_char * var_val,
  1796.                             u_char var_val_type,
  1797.                             size_t var_val_len,
  1798.                             u_char * statP, oid * name, size_t name_len)
  1799. {
  1800.     static char    *tmpvar;
  1801.     struct mteTriggerTable_data *StorageTmp = NULL;
  1802.     static size_t   tmplen;
  1803.     size_t          newlen =
  1804.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  1805.                     3 - 1);
  1806.     DEBUGMSGTL(("mteTriggerTable",
  1807.                 "write_mteTriggerContextName entering action=%d...  n",
  1808.                 action));
  1809.     if ((StorageTmp =
  1810.          header_complex(mteTriggerTableStorage, NULL,
  1811.                         &name[sizeof(mteTriggerTable_variables_oid) /
  1812.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  1813.                         NULL)) == NULL)
  1814.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  1815.     switch (action) {
  1816.     case RESERVE1:
  1817.         if (var_val_type != ASN_OCTET_STR) {
  1818.             snmp_log(LOG_ERR,
  1819.                      "write to mteTriggerContextName not ASN_OCTET_STRn");
  1820.             return SNMP_ERR_WRONGTYPE;
  1821.         }
  1822.         if (StorageTmp->storageType != ST_NONVOLATILE)
  1823.             return SNMP_ERR_NOTWRITABLE;
  1824.         break;
  1825.     case RESERVE2:
  1826.         /*
  1827.          * memory reseveration, final preparation... 
  1828.          */
  1829.         break;
  1830.     case FREE:
  1831.         /*
  1832.          * Release any resources that have been allocated 
  1833.          */
  1834.         break;
  1835.     case ACTION:
  1836.         /*
  1837.          * The variable has been stored in string for
  1838.          * you to use, and you have just been asked to do something with
  1839.          * it.  Note that anything done here must be reversable in the UNDO case 
  1840.          */
  1841.         tmpvar = StorageTmp->mteTriggerContextName;
  1842.         tmplen = StorageTmp->mteTriggerContextNameLen;
  1843.         memdup((u_char **) & StorageTmp->mteTriggerContextName, var_val,
  1844.                var_val_len);
  1845.         StorageTmp->mteTriggerContextNameLen = var_val_len;
  1846.         break;
  1847.     case UNDO:
  1848.         /*
  1849.          * Back out any changes made in the ACTION case 
  1850.          */
  1851.         SNMP_FREE(StorageTmp->mteTriggerContextName);
  1852.         StorageTmp->mteTriggerContextName = tmpvar;
  1853.         StorageTmp->mteTriggerContextNameLen = tmplen;
  1854.         break;
  1855.     case COMMIT:
  1856.         /*
  1857.          * Things are working well, so it's now safe to make the change
  1858.          * permanently.  Make sure that anything done here can't fail! 
  1859.          */
  1860.         SNMP_FREE(tmpvar);
  1861.         break;
  1862.     }
  1863.     return SNMP_ERR_NOERROR;
  1864. }
  1865. int
  1866. write_mteTriggerContextNameWildcard(int action,
  1867.                                     u_char * var_val,
  1868.                                     u_char var_val_type,
  1869.                                     size_t var_val_len,
  1870.                                     u_char * statP,
  1871.                                     oid * name, size_t name_len)
  1872. {
  1873.     static int      tmpvar;
  1874.     struct mteTriggerTable_data *StorageTmp = NULL;
  1875.     size_t          newlen =
  1876.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  1877.                     3 - 1);
  1878.     DEBUGMSGTL(("mteTriggerTable",
  1879.                 "write_mteTriggerContextNameWildcard entering action=%d...  n",
  1880.                 action));
  1881.     if ((StorageTmp =
  1882.          header_complex(mteTriggerTableStorage, NULL,
  1883.                         &name[sizeof(mteTriggerTable_variables_oid) /
  1884.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  1885.                         NULL)) == NULL)
  1886.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  1887.     switch (action) {
  1888.     case RESERVE1:
  1889.         if (var_val_type != ASN_INTEGER) {
  1890.             snmp_log(LOG_ERR,
  1891.                      "write to mteTriggerContextNameWildcard not ASN_INTEGERn");
  1892.             return SNMP_ERR_WRONGTYPE;
  1893.         }
  1894.         if (StorageTmp->storageType != ST_NONVOLATILE)
  1895.             return SNMP_ERR_NOTWRITABLE;
  1896.         break;
  1897.     case RESERVE2:
  1898.         /*
  1899.          * memory reseveration, final preparation... 
  1900.          */
  1901.         break;
  1902.     case FREE:
  1903.         /*
  1904.          * Release any resources that have been allocated 
  1905.          */
  1906.         break;
  1907.     case ACTION:
  1908.         /*
  1909.          * The variable has been stored in long_ret for
  1910.          * you to use, and you have just been asked to do something with
  1911.          * it.  Note that anything done here must be reversable in the UNDO case 
  1912.          */
  1913.         tmpvar = StorageTmp->mteTriggerContextNameWildcard;
  1914.         StorageTmp->mteTriggerContextNameWildcard = *((long *) var_val);
  1915.         break;
  1916.     case UNDO:
  1917.         /*
  1918.          * Back out any changes made in the ACTION case 
  1919.          */
  1920.         StorageTmp->mteTriggerContextNameWildcard = tmpvar;
  1921.         break;
  1922.     case COMMIT:
  1923.         /*
  1924.          * Things are working well, so it's now safe to make the change
  1925.          * permanently.  Make sure that anything done here can't fail! 
  1926.          */
  1927.         break;
  1928.     }
  1929.     return SNMP_ERR_NOERROR;
  1930. }
  1931. int
  1932. write_mteTriggerFrequency(int action,
  1933.                           u_char * var_val,
  1934.                           u_char var_val_type,
  1935.                           size_t var_val_len,
  1936.                           u_char * statP, oid * name, size_t name_len)
  1937. {
  1938.     static int      tmpvar;
  1939.     struct mteTriggerTable_data *StorageTmp = NULL;
  1940.     size_t          newlen =
  1941.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  1942.                     3 - 1);
  1943.     DEBUGMSGTL(("mteTriggerTable",
  1944.                 "write_mteTriggerFrequency entering action=%d...  n",
  1945.                 action));
  1946.     if ((StorageTmp =
  1947.          header_complex(mteTriggerTableStorage, NULL,
  1948.                         &name[sizeof(mteTriggerTable_variables_oid) /
  1949.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  1950.                         NULL)) == NULL)
  1951.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  1952.     switch (action) {
  1953.     case RESERVE1:
  1954.         if (var_val_type != ASN_UNSIGNED) {
  1955.             snmp_log(LOG_ERR,
  1956.                      "write to mteTriggerFrequency not ASN_UNSIGNEDn");
  1957.             return SNMP_ERR_WRONGTYPE;
  1958.         }
  1959.         if (StorageTmp->storageType != ST_NONVOLATILE)
  1960.             return SNMP_ERR_NOTWRITABLE;
  1961.         break;
  1962.     case RESERVE2:
  1963.         /*
  1964.          * memory reseveration, final preparation... 
  1965.          */
  1966.         break;
  1967.     case FREE:
  1968.         /*
  1969.          * Release any resources that have been allocated 
  1970.          */
  1971.         break;
  1972.     case ACTION:
  1973.         /*
  1974.          * The variable has been stored in ulong_ret for
  1975.          * you to use, and you have just been asked to do something with
  1976.          * it.  Note that anything done here must be reversable in the UNDO case 
  1977.          */
  1978.         tmpvar = StorageTmp->mteTriggerFrequency;
  1979.         StorageTmp->mteTriggerFrequency = *((unsigned long *) var_val);
  1980.         break;
  1981.     case UNDO:
  1982.         /*
  1983.          * Back out any changes made in the ACTION case 
  1984.          */
  1985.         StorageTmp->mteTriggerFrequency = tmpvar;
  1986.         break;
  1987.     case COMMIT:
  1988.         /*
  1989.          * Things are working well, so it's now safe to make the change
  1990.          * permanently.  Make sure that anything done here can't fail! 
  1991.          */
  1992.         if (StorageTmp->mteTriggerEnabled == MTETRIGGERENABLED_TRUE &&
  1993.             StorageTmp->mteTriggerEntryStatus == RS_ACTIVE)
  1994.             mte_enable_trigger(StorageTmp);
  1995.         break;
  1996.     }
  1997.     return SNMP_ERR_NOERROR;
  1998. }
  1999. int
  2000. write_mteTriggerObjectsOwner(int action,
  2001.                              u_char * var_val,
  2002.                              u_char var_val_type,
  2003.                              size_t var_val_len,
  2004.                              u_char * statP, oid * name, size_t name_len)
  2005. {
  2006.     static char    *tmpvar;
  2007.     struct mteTriggerTable_data *StorageTmp = NULL;
  2008.     static size_t   tmplen;
  2009.     size_t          newlen =
  2010.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  2011.                     3 - 1);
  2012.     DEBUGMSGTL(("mteTriggerTable",
  2013.                 "write_mteTriggerObjectsOwner entering action=%d...  n",
  2014.                 action));
  2015.     if ((StorageTmp =
  2016.          header_complex(mteTriggerTableStorage, NULL,
  2017.                         &name[sizeof(mteTriggerTable_variables_oid) /
  2018.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  2019.                         NULL)) == NULL)
  2020.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  2021.     switch (action) {
  2022.     case RESERVE1:
  2023.         if (var_val_type != ASN_OCTET_STR) {
  2024.             snmp_log(LOG_ERR,
  2025.                      "write to mteTriggerObjectsOwner not ASN_OCTET_STRn");
  2026.             return SNMP_ERR_WRONGTYPE;
  2027.         }
  2028.         if (StorageTmp->storageType != ST_NONVOLATILE)
  2029.             return SNMP_ERR_NOTWRITABLE;
  2030.         break;
  2031.     case RESERVE2:
  2032.         /*
  2033.          * memory reseveration, final preparation... 
  2034.          */
  2035.         break;
  2036.     case FREE:
  2037.         /*
  2038.          * Release any resources that have been allocated 
  2039.          */
  2040.         break;
  2041.     case ACTION:
  2042.         /*
  2043.          * The variable has been stored in string for
  2044.          * you to use, and you have just been asked to do something with
  2045.          * it.  Note that anything done here must be reversable in the UNDO case 
  2046.          */
  2047.         tmpvar = StorageTmp->mteTriggerObjectsOwner;
  2048.         tmplen = StorageTmp->mteTriggerObjectsOwnerLen;
  2049.         memdup((u_char **) & StorageTmp->mteTriggerObjectsOwner, var_val,
  2050.                var_val_len);
  2051.         StorageTmp->mteTriggerObjectsOwnerLen = var_val_len;
  2052.         break;
  2053.     case UNDO:
  2054.         /*
  2055.          * Back out any changes made in the ACTION case 
  2056.          */
  2057.         SNMP_FREE(StorageTmp->mteTriggerObjectsOwner);
  2058.         StorageTmp->mteTriggerObjectsOwner = tmpvar;
  2059.         StorageTmp->mteTriggerObjectsOwnerLen = tmplen;
  2060.         break;
  2061.     case COMMIT:
  2062.         /*
  2063.          * Things are working well, so it's now safe to make the change
  2064.          * permanently.  Make sure that anything done here can't fail! 
  2065.          */
  2066.         SNMP_FREE(tmpvar);
  2067.         break;
  2068.     }
  2069.     return SNMP_ERR_NOERROR;
  2070. }
  2071. int
  2072. write_mteTriggerObjects(int action,
  2073.                         u_char * var_val,
  2074.                         u_char var_val_type,
  2075.                         size_t var_val_len,
  2076.                         u_char * statP, oid * name, size_t name_len)
  2077. {
  2078.     static char    *tmpvar;
  2079.     struct mteTriggerTable_data *StorageTmp = NULL;
  2080.     static size_t   tmplen;
  2081.     size_t          newlen =
  2082.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  2083.                     3 - 1);
  2084.     DEBUGMSGTL(("mteTriggerTable",
  2085.                 "write_mteTriggerObjects entering action=%d...  n",
  2086.                 action));
  2087.     if ((StorageTmp =
  2088.          header_complex(mteTriggerTableStorage, NULL,
  2089.                         &name[sizeof(mteTriggerTable_variables_oid) /
  2090.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  2091.                         NULL)) == NULL)
  2092.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  2093.     switch (action) {
  2094.     case RESERVE1:
  2095.         if (var_val_type != ASN_OCTET_STR) {
  2096.             snmp_log(LOG_ERR,
  2097.                      "write to mteTriggerObjects not ASN_OCTET_STRn");
  2098.             return SNMP_ERR_WRONGTYPE;
  2099.         }
  2100.         if (StorageTmp->storageType != ST_NONVOLATILE)
  2101.             return SNMP_ERR_NOTWRITABLE;
  2102.         break;
  2103.     case RESERVE2:
  2104.         /*
  2105.          * memory reseveration, final preparation... 
  2106.          */
  2107.         break;
  2108.     case FREE:
  2109.         /*
  2110.          * Release any resources that have been allocated 
  2111.          */
  2112.         break;
  2113.     case ACTION:
  2114.         /*
  2115.          * The variable has been stored in string for
  2116.          * you to use, and you have just been asked to do something with
  2117.          * it.  Note that anything done here must be reversable in the UNDO case 
  2118.          */
  2119.         tmpvar = StorageTmp->mteTriggerObjects;
  2120.         tmplen = StorageTmp->mteTriggerObjectsLen;
  2121.         memdup((u_char **) & StorageTmp->mteTriggerObjects, var_val,
  2122.                var_val_len);
  2123.         StorageTmp->mteTriggerObjectsLen = var_val_len;
  2124.         break;
  2125.     case UNDO:
  2126.         /*
  2127.          * Back out any changes made in the ACTION case 
  2128.          */
  2129.         SNMP_FREE(StorageTmp->mteTriggerObjects);
  2130.         StorageTmp->mteTriggerObjects = tmpvar;
  2131.         StorageTmp->mteTriggerObjectsLen = tmplen;
  2132.         break;
  2133.     case COMMIT:
  2134.         /*
  2135.          * Things are working well, so it's now safe to make the change
  2136.          * permanently.  Make sure that anything done here can't fail! 
  2137.          */
  2138.         SNMP_FREE(tmpvar);
  2139.         break;
  2140.     }
  2141.     return SNMP_ERR_NOERROR;
  2142. }
  2143. int
  2144. write_mteTriggerEnabled(int action,
  2145.                         u_char * var_val,
  2146.                         u_char var_val_type,
  2147.                         size_t var_val_len,
  2148.                         u_char * statP, oid * name, size_t name_len)
  2149. {
  2150.     static int      tmpvar;
  2151.     struct mteTriggerTable_data *StorageTmp = NULL;
  2152.     size_t          newlen =
  2153.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  2154.                     3 - 1);
  2155.     DEBUGMSGTL(("mteTriggerTable",
  2156.                 "write_mteTriggerEnabled entering action=%d...  n",
  2157.                 action));
  2158.     if ((StorageTmp =
  2159.          header_complex(mteTriggerTableStorage, NULL,
  2160.                         &name[sizeof(mteTriggerTable_variables_oid) /
  2161.                               sizeof(oid) + 3 - 1], &newlen, 1, NULL,
  2162.                         NULL)) == NULL)
  2163.         return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
  2164.     switch (action) {
  2165.     case RESERVE1:
  2166.         if (var_val_type != ASN_INTEGER) {
  2167.             snmp_log(LOG_ERR,
  2168.                      "write to mteTriggerEnabled not ASN_INTEGERn");
  2169.             return SNMP_ERR_WRONGTYPE;
  2170.         }
  2171.         if (StorageTmp->storageType != ST_NONVOLATILE)
  2172.             return SNMP_ERR_NOTWRITABLE;
  2173.         break;
  2174.     case RESERVE2:
  2175.         /*
  2176.          * memory reseveration, final preparation... 
  2177.          */
  2178.         break;
  2179.     case FREE:
  2180.         /*
  2181.          * Release any resources that have been allocated 
  2182.          */
  2183.         break;
  2184.     case ACTION:
  2185.         /*
  2186.          * The variable has been stored in long_ret for
  2187.          * you to use, and you have just been asked to do something with
  2188.          * it.  Note that anything done here must be reversable in the UNDO case 
  2189.          */
  2190.         tmpvar = StorageTmp->mteTriggerEnabled;
  2191.         StorageTmp->mteTriggerEnabled = *((long *) var_val);
  2192.         break;
  2193.     case UNDO:
  2194.         /*
  2195.          * Back out any changes made in the ACTION case 
  2196.          */
  2197.         StorageTmp->mteTriggerEnabled = tmpvar;
  2198.         break;
  2199.     case COMMIT:
  2200.         /*
  2201.          * Things are working well, so it's now safe to make the change
  2202.          * permanently.  Make sure that anything done here can't fail! 
  2203.          */
  2204.         if (StorageTmp->mteTriggerEnabled == MTETRIGGERENABLED_TRUE &&
  2205.             StorageTmp->mteTriggerEntryStatus == RS_ACTIVE)
  2206.             mte_enable_trigger(StorageTmp);
  2207.         else if (StorageTmp->mteTriggerEnabled == MTETRIGGERENABLED_FALSE)
  2208.             mte_disable_trigger(StorageTmp);
  2209.         break;
  2210.     }
  2211.     return SNMP_ERR_NOERROR;
  2212. }
  2213. int
  2214. write_mteTriggerEntryStatus(int action,
  2215.                             u_char * var_val,
  2216.                             u_char var_val_type,
  2217.                             size_t var_val_len,
  2218.                             u_char * statP, oid * name, size_t name_len)
  2219. {
  2220.     struct mteTriggerTable_data *StorageTmp = NULL;
  2221.     static struct mteTriggerTable_data *StorageNew, *StorageDel;
  2222.     size_t          newlen =
  2223.         name_len - (sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  2224.                     3 - 1);
  2225.     static int      old_value;
  2226.     int             set_value;
  2227.     static netsnmp_variable_list *vars, *vp;
  2228.     struct header_complex_index *hciptr;
  2229.     StorageTmp =
  2230.         header_complex(mteTriggerTableStorage, NULL,
  2231.                        &name[sizeof(mteTriggerTable_variables_oid) /
  2232.                              sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL);
  2233.     if (var_val_type != ASN_INTEGER || var_val == NULL) {
  2234.         snmp_log(LOG_ERR,
  2235.                  "write to mteTriggerEntryStatus not ASN_INTEGERn");
  2236.         return SNMP_ERR_WRONGTYPE;
  2237.     }
  2238.     set_value = *((long *) var_val);
  2239.     /*
  2240.      * check legal range, and notReady is reserved for us, not a user 
  2241.      */
  2242.     if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY)
  2243.         return SNMP_ERR_INCONSISTENTVALUE;
  2244.     switch (action) {
  2245.     case RESERVE1:
  2246.         /*
  2247.          * stage one: test validity 
  2248.          */
  2249.         if (StorageTmp == NULL) {
  2250.             /*
  2251.              * create the row now? 
  2252.              */
  2253.             /*
  2254.              * ditch illegal values now 
  2255.              */
  2256.             if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE)
  2257.                 return SNMP_ERR_INCONSISTENTVALUE;
  2258.             /*
  2259.              * destroying a non-existent row is actually legal 
  2260.              */
  2261.             if (set_value == RS_DESTROY) {
  2262.                 return SNMP_ERR_NOERROR;
  2263.             }
  2264.             /*
  2265.              * illegal creation values 
  2266.              */
  2267.             if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) {
  2268.                 return SNMP_ERR_INCONSISTENTVALUE;
  2269.             }
  2270.         } else {
  2271.             /*
  2272.              * row exists.  Check for a valid state change 
  2273.              */
  2274.             if (set_value == RS_CREATEANDGO
  2275.                 || set_value == RS_CREATEANDWAIT) {
  2276.                 /*
  2277.                  * can't create a row that exists 
  2278.                  */
  2279.                 return SNMP_ERR_INCONSISTENTVALUE;
  2280.             }
  2281.             if (StorageTmp->mteTriggerEntryStatus == RS_ACTIVE &&
  2282.                 set_value != RS_DESTROY) {
  2283.                 /*
  2284.                  * "Once made active an entry may not be modified except to 
  2285.                  * delete it."  XXX: doesn't this in fact apply to ALL
  2286.                  * columns of the table and not just this one?  
  2287.                  */
  2288.                 return SNMP_ERR_INCONSISTENTVALUE;
  2289.             }
  2290.             if (StorageTmp->storageType != ST_NONVOLATILE)
  2291.                 return SNMP_ERR_NOTWRITABLE;
  2292.         }
  2293.         break;
  2294.     case RESERVE2:
  2295.         /*
  2296.          * memory reseveration, final preparation... 
  2297.          */
  2298.         if (StorageTmp == NULL) {
  2299.             /*
  2300.              * creation 
  2301.              */
  2302.             vars = NULL;
  2303.             snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0);  /* mteOwner */
  2304.             snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OCTET_STR, NULL, 0);     /* mteTriggerName */
  2305.             if (header_complex_parse_oid
  2306.                 (&
  2307.                  (name
  2308.                   [sizeof(mteTriggerTable_variables_oid) / sizeof(oid) +
  2309.                    2]), newlen, vars) != SNMPERR_SUCCESS) {
  2310.                 /*
  2311.                  * XXX: free, zero vars 
  2312.                  */
  2313.                 return SNMP_ERR_INCONSISTENTNAME;
  2314.             }
  2315.             vp = vars;
  2316.             StorageNew = create_mteTriggerTable_data();
  2317.             StorageNew->mteOwner = malloc(vp->val_len + 1);
  2318.             memcpy(StorageNew->mteOwner, vp->val.string, vp->val_len);
  2319.             StorageNew->mteOwner[vp->val_len] = '';
  2320.             StorageNew->mteOwnerLen = vp->val_len;
  2321.             vp = vp->next_variable;
  2322.             StorageNew->mteTriggerName = malloc(vp->val_len + 1);
  2323.             memcpy(StorageNew->mteTriggerName, vp->val.string,
  2324.                    vp->val_len);
  2325.             StorageNew->mteTriggerName[vp->val_len] = '';
  2326.             StorageNew->mteTriggerNameLen = vp->val_len;
  2327.             vp = vp->next_variable;
  2328.             StorageNew->mteTriggerEntryStatus = set_value;
  2329.         }
  2330.         break;
  2331.     case FREE:
  2332.         /*
  2333.          * XXX: free, zero vars 
  2334.          */
  2335.         /*
  2336.          * Release any resources that have been allocated 
  2337.          */
  2338.         break;
  2339.     case ACTION:
  2340.         /*
  2341.          * The variable has been stored in set_value for you to
  2342.          * use, and you have just been asked to do something with
  2343.          * it.  Note that anything done here must be reversable in
  2344.          * the UNDO case 
  2345.          */
  2346.         if (StorageTmp == NULL) {
  2347.             /*
  2348.              * row creation, so add it 
  2349.              */
  2350.             if (StorageNew != NULL)
  2351.                 mteTriggerTable_add(StorageNew);
  2352.             /*
  2353.              * XXX: ack, and if it is NULL? 
  2354.              */
  2355.         } else if (set_value != RS_DESTROY) {
  2356.             /*
  2357.              * set the flag? 
  2358.              */
  2359.             old_value = StorageTmp->mteTriggerEntryStatus;
  2360.             StorageTmp->mteTriggerEntryStatus = *((long *) var_val);
  2361.         } else {
  2362.             /*
  2363.              * destroy...  extract it for now 
  2364.              */
  2365.             hciptr =
  2366.                 header_complex_find_entry(mteTriggerTableStorage,
  2367.                                           StorageTmp);
  2368.             StorageDel =
  2369.                 header_complex_extract_entry(&mteTriggerTableStorage,
  2370.                                              hciptr);
  2371.         }
  2372.         break;
  2373.     case UNDO:
  2374.         /*
  2375.          * Back out any changes made in the ACTION case 
  2376.          */
  2377.         if (StorageTmp == NULL) {
  2378.             /*
  2379.              * row creation, so remove it again 
  2380.              */
  2381.             hciptr =
  2382.                 header_complex_find_entry(mteTriggerTableStorage,
  2383.                                           StorageTmp);
  2384.             StorageDel =
  2385.                 header_complex_extract_entry(&mteTriggerTableStorage,
  2386.                                              hciptr);
  2387.             /*
  2388.              * XXX: free it 
  2389.              */
  2390.         } else if (StorageDel != NULL) {
  2391.             /*
  2392.              * row deletion, so add it again 
  2393.              */
  2394.             mteTriggerTable_add(StorageDel);
  2395.         } else {
  2396.             StorageTmp->mteTriggerEntryStatus = old_value;
  2397.         }
  2398.         break;
  2399.     case COMMIT:
  2400.         /*
  2401.          * Things are working well, so it's now safe to make the change
  2402.          * permanently.  Make sure that anything done here can't fail! 
  2403.          */
  2404.         if (StorageDel != NULL) {
  2405.             mte_disable_trigger(StorageDel);
  2406.             StorageDel = 0;
  2407.             /*
  2408.              * XXX: free it, its dead 
  2409.              */
  2410.         } else {
  2411.             if (StorageTmp
  2412.                 && StorageTmp->mteTriggerEntryStatus == RS_CREATEANDGO) {
  2413.                 StorageTmp->mteTriggerEntryStatus = RS_ACTIVE;
  2414.             } else if (StorageTmp &&
  2415.                        StorageTmp->mteTriggerEntryStatus ==
  2416.                        RS_CREATEANDWAIT) {
  2417.                 StorageTmp->mteTriggerEntryStatus = RS_NOTINSERVICE;
  2418.             }
  2419.         }
  2420.         if (StorageTmp &&
  2421.             StorageTmp->mteTriggerEntryStatus == RS_ACTIVE &&
  2422.             !StorageTmp->have_copied_auth_info) {
  2423.             netsnmp_agent_session *asp =
  2424.                 netsnmp_get_current_agent_session();
  2425.             netsnmp_pdu    *pdu = NULL;
  2426.             if (!asp) {
  2427.                 snmp_log(LOG_ERR,
  2428.                          "snmpTriggerTable: can't get master session for authentication paramsn");
  2429.             } else {
  2430.                 pdu = asp->orig_pdu;
  2431.                 if (!pdu) {
  2432.                     snmp_log(LOG_ERR,
  2433.                              "snmpTriggerTable: can't get master pdu for authentication paramsn");
  2434.                 }
  2435.             }
  2436.             if (pdu) {
  2437.                 DEBUGMSGTL(("mteTriggerTest", "copying PDU auth infon"));
  2438.                 StorageTmp->pdu_version = pdu->version;
  2439.                 StorageTmp->pdu_securityModel = pdu->securityModel;
  2440.                 StorageTmp->pdu_securityLevel = pdu->securityLevel;
  2441.                 StorageTmp->pdu_tDomain = pdu->tDomain;
  2442.                 StorageTmp->pdu_tDomainLen = pdu->tDomainLen;
  2443.                 if (pdu->transport_data != NULL) {
  2444.                     StorageTmp->pdu_transport =
  2445.                         malloc(pdu->transport_data_length);
  2446.                     memcpy(StorageTmp->pdu_transport, pdu->transport_data,
  2447.                            pdu->transport_data_length);
  2448.                 }
  2449.                 StorageTmp->pdu_transportLen = pdu->transport_data_length;
  2450.                 if (pdu->community) {
  2451.                     StorageTmp->pdu_community =
  2452.                         calloc(1, pdu->community_len + 1);
  2453.                     memcpy(StorageTmp->pdu_community, pdu->community,
  2454.                            pdu->community_len);
  2455.                     StorageTmp->pdu_community_len = pdu->community_len;
  2456.                 } else {
  2457.                     StorageTmp->pdu_community = NULL;
  2458.                     StorageTmp->pdu_community_len = 0;
  2459.                 }
  2460.                 if (pdu->securityName) {
  2461.                     StorageTmp->pdu_securityName =
  2462.                         calloc(1, pdu->securityNameLen + 1);
  2463.                     memcpy(StorageTmp->pdu_securityName, pdu->securityName,
  2464.                            pdu->securityNameLen);
  2465.                     StorageTmp->pdu_securityNameLen = pdu->securityNameLen;
  2466.                 } else {
  2467.                     StorageTmp->pdu_securityName = NULL;
  2468.                     StorageTmp->pdu_securityNameLen = 0;
  2469.                 }
  2470.                 StorageTmp->have_copied_auth_info = 1;
  2471.             }
  2472.         }
  2473.         if (StorageTmp &&
  2474.             StorageTmp->mteTriggerEnabled == MTETRIGGERENABLED_TRUE &&
  2475.             StorageTmp->mteTriggerEntryStatus == RS_ACTIVE)
  2476.             mte_enable_trigger(StorageTmp);
  2477.         break;
  2478.     }
  2479.     return SNMP_ERR_NOERROR;
  2480. }
  2481. /*
  2482.  * send trap 
  2483.  */
  2484. void
  2485. send_mte_trap(struct mteTriggerTable_data *item,
  2486.               oid * trap_oid, size_t trap_oid_len,
  2487.               oid * name_oid, size_t name_oid_len,
  2488.               long *value, const char *objowner, const char *objname,
  2489.               const char *reason)
  2490. {
  2491.     static oid      objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };     /* snmpTrapIOD.0 */
  2492.     netsnmp_variable_list *var_list = NULL;
  2493.     /*
  2494.      * snmpTrap oid 
  2495.      */
  2496.     snmp_varlist_add_variable(&var_list, objid_snmptrap,
  2497.                               sizeof(objid_snmptrap) / sizeof(oid),
  2498.                               ASN_OBJECT_ID, (u_char *) trap_oid,
  2499.                               trap_oid_len * sizeof(oid));
  2500.     /*
  2501.      * mteHotTrigger 
  2502.      */
  2503.     snmp_varlist_add_variable(&var_list, mteHotTrigger,
  2504.                               sizeof(mteHotTrigger) / sizeof(oid),
  2505.                               ASN_OCTET_STR,
  2506.                               (u_char *) item->mteTriggerName,
  2507.                               item->mteTriggerNameLen);
  2508.     /*
  2509.      * mteHotTargetName 
  2510.      */
  2511.     snmp_varlist_add_variable(&var_list, mteHotTargetName, sizeof(mteHotTargetName) / sizeof(oid), ASN_OCTET_STR, (u_char *) item->mteTriggerTargetTag, /*XXX: targetName,not tag */
  2512.                               item->mteTriggerTargetTagLen);    /*XXX */
  2513.     /*
  2514.      * mteHotContextName 
  2515.      */
  2516.     snmp_varlist_add_variable(&var_list, mteHotContextName,
  2517.                               sizeof(mteHotContextName) / sizeof(oid),
  2518.                               ASN_OCTET_STR,
  2519.                               (u_char *) item->mteTriggerContextName,
  2520.                               item->mteTriggerContextNameLen);
  2521.     snmp_varlist_add_variable(&var_list, mteHotOID,
  2522.                               sizeof(mteHotOID) / sizeof(oid),
  2523.                               ASN_OBJECT_ID, (u_char *) name_oid,
  2524.                               sizeof(oid) * name_oid_len);
  2525.     if (trap_oid == mteTriggerFailure || trap_oid == mteEventSetFailure) {
  2526.         /*
  2527.          * mteFailedReason  
  2528.          */
  2529.         snmp_varlist_add_variable(&var_list, mteFailedReason,
  2530.                                   sizeof(mteFailedReason) / sizeof(oid),
  2531.                                   ASN_INTEGER, (u_char *) value,
  2532.                                   sizeof(value));
  2533.     } else {
  2534.         /*
  2535.          * mteHotValue  
  2536.          */
  2537.         snmp_varlist_add_variable(&var_list, mteHotValue,
  2538.                                   sizeof(mteHotValue) / sizeof(oid),
  2539.                                   ASN_INTEGER, (u_char *) value,
  2540.                                   sizeof(value));
  2541.     }
  2542.     /*
  2543.      * add in traps from main table 
  2544.      */
  2545.     mte_add_objects(var_list, item, item->mteTriggerObjectsOwner,
  2546.                     item->mteTriggerObjects,
  2547.                     name_oid + item->mteTriggerValueIDLen,
  2548.                     name_oid_len - item->mteTriggerValueIDLen);
  2549.     /*
  2550.      * add in traps from sub table 
  2551.      */
  2552.     mte_add_objects(var_list, item, objowner, objname,
  2553.                     name_oid + item->mteTriggerValueIDLen,
  2554.                     name_oid_len - item->mteTriggerValueIDLen);
  2555.     /*
  2556.      * XXX: stuff based on event table 
  2557.      */
  2558.     DEBUGMSGTL(("mteTriggerTest:send_mte_trap", "sending the trap (%s): ",
  2559.                 reason));
  2560.     DEBUGMSGOID(("mteTriggerTest:send_mte_trap", name_oid, name_oid_len));
  2561.     DEBUGMSG(("mteTriggerTest:send_mte_trap", " = %ldn", *value));
  2562.     send_v2trap(var_list);
  2563.     snmp_free_varbind(var_list);
  2564. }
  2565. void
  2566. last_state_clean(void *data)
  2567. {
  2568.     struct last_state *cleanme = (struct last_state *) data;
  2569.     SNMP_FREE(cleanme->value);
  2570.     SNMP_FREE(cleanme);
  2571. }
  2572. /*
  2573.  * retrieves requested info in pdu from the current target 
  2574.  */
  2575. netsnmp_pdu    *
  2576. mte_get_response(struct mteTriggerTable_data *item, netsnmp_pdu *pdu)
  2577. {
  2578.     netsnmp_pdu    *response = NULL;
  2579.     int             status = 0;
  2580.     char            buf[SPRINT_MAX_LEN];
  2581.     /*
  2582.      * local agent check 
  2583.      */
  2584.     pdu->errstat = SNMPERR_SUCCESS;
  2585.     pdu->errindex = 0;
  2586.     pdu->version = item->pdu_version;
  2587.     pdu->securityModel = item->pdu_securityModel;
  2588.     pdu->securityLevel = item->pdu_securityLevel;
  2589.     pdu->tDomain = item->pdu_tDomain;
  2590.     pdu->tDomainLen = item->pdu_tDomainLen;
  2591.     memdup((u_char **) & pdu->transport_data, item->pdu_transport,
  2592.            item->pdu_transportLen);
  2593.     pdu->transport_data_length = item->pdu_transportLen;
  2594.     memdup(&pdu->community, item->pdu_community, item->pdu_community_len);
  2595.     pdu->community_len = item->pdu_community_len;
  2596.     memdup((u_char **) & pdu->contextName, item->mteTriggerContextName,
  2597.            item->mteTriggerContextNameLen);
  2598.     pdu->contextNameLen = item->mteTriggerContextNameLen;
  2599.     memdup((u_char **) & pdu->securityName, item->pdu_securityName,
  2600.            item->pdu_securityNameLen);
  2601.     pdu->securityNameLen = item->pdu_securityNameLen;
  2602.     DEBUGMSGTL(("mteTriggerTable",
  2603.                 "accessing locally with secName "%s" community "%s"n",
  2604.                 item->pdu_securityName ? (char *) item->
  2605.                 pdu_securityName : "[NIL]",
  2606.                 item->pdu_community ? (char *) item->
  2607.                 pdu_community : "[NIL]"));
  2608.     if (item->mteTriggerTargetTagLen == 0) {
  2609.         /*
  2610.          * send to the local agent 
  2611.          */
  2612.         status = snmp_synch_response(mte_callback_sess, pdu, &response);
  2613.         if (status != SNMP_ERR_NOERROR ||
  2614.             response->errstat != SNMP_ERR_NOERROR) {
  2615.             /*
  2616.              * xxx 
  2617.              */
  2618.             char           *errstr;
  2619.             snmp_error(mte_callback_sess, 0, 0, &errstr);
  2620.             if (response) {
  2621.                 DEBUGMSGTL(("mteTriggerTable",
  2622.                             "Error received: status=%d, sess_error=%s, pduerr=%d/%s, pdu version=%dn",
  2623.                             status, errstr,
  2624.                             response->errstat,
  2625.                             snmp_api_errstring(response->errstat),
  2626.                             response->version));
  2627.             } else {
  2628.                 DEBUGMSGTL(("mteTriggerTable",
  2629.                             "Error received: status=%d, sess_error=%s [no response pointer]n",
  2630.                             status, errstr));
  2631.             }
  2632.             if (errstr)
  2633.                 free(errstr);
  2634.             return NULL;        /* XXX: proper failure, trap sent, etc */
  2635.         }
  2636.     } else {
  2637.         /*
  2638.          * remote target list 
  2639.          */
  2640.         /*
  2641.          * XXX 
  2642.          */
  2643.     }
  2644.     if (response->variables)
  2645.         snprint_variable(buf, sizeof(buf), response->variables->name,
  2646.                          response->variables->name_length,
  2647.                          response->variables);
  2648.     else
  2649.         strcpy(buf, "empty");
  2650.     buf[sizeof(buf) - 1] = '';
  2651.     DEBUGMSGTL(("mteTriggerTable", "got a variables: %sn", buf));
  2652.     return response;
  2653. }
  2654. /*
  2655.  * Return 1 if `type' is an integer type; specifically, to quote RFC 2981,
  2656.  * p. 13, "anything that ends up encoded for transmission (that is, in BER,
  2657.  * not ASN.1) as an integer".  Return 0 for all other types.  
  2658.  */
  2659. int
  2660. mte_is_integer_type(unsigned char type)
  2661. {
  2662.     switch (type) {
  2663.     case ASN_INTEGER:
  2664.     case ASN_COUNTER:
  2665.     case ASN_GAUGE:
  2666.     case ASN_TIMETICKS:
  2667.     case ASN_UINTEGER:
  2668.     case ASN_COUNTER64:
  2669. #ifdef OPAQUE_SPECIAL_TYPES
  2670.     case ASN_OPAQUE_COUNTER64:
  2671.     case ASN_OPAQUE_U64:
  2672.     case ASN_OPAQUE_I64:
  2673. #endif                          /* OPAQUE_SPECIAL_TYPES */
  2674.         return 1;
  2675.     default:
  2676.         return 0;
  2677.     }
  2678. }
  2679. /*
  2680.  * Return 0 if the discontinuity object was checked and no discontinuity has
  2681.  * occurred, 1 if the discontinuity object was checked and a discontinuity
  2682.  * has occurred or -1 if the discontinuity object is not accessible.  
  2683.  */
  2684. int
  2685. mte_discontinuity_occurred(struct mteTriggerTable_data *item)
  2686. {
  2687.     netsnmp_pdu    *pdu = NULL, *response = NULL;
  2688.     unsigned long   discoTicks = 0;     /*  cool var name  */
  2689.     if (item->mteTriggerDeltaDiscontinuityIDLen == 0 ||
  2690.         (snmp_oid_compare(item->mteTriggerDeltaDiscontinuityID,
  2691.                           item->mteTriggerDeltaDiscontinuityIDLen,
  2692.                           sysUpTimeInstance,
  2693.                           sizeof(sysUpTimeInstance) / sizeof(oid)) == 0)) {
  2694.         DEBUGMSGTL(("mte_disco",
  2695.                     "discoID either zero-length or sysUpTimeInstancen"));
  2696.     } else {
  2697.         if (item->mteTriggerValueIDWildcard == TV_TRUE) {
  2698.             pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
  2699.         } else {
  2700.             pdu = snmp_pdu_create(SNMP_MSG_GET);
  2701.         }
  2702.         snmp_add_null_var(pdu, item->mteTriggerDeltaDiscontinuityID,
  2703.                           item->mteTriggerDeltaDiscontinuityIDLen);
  2704.         response = mte_get_response(item, pdu);
  2705.         if (response == NULL) {
  2706.             /*
  2707.              * XXX:  send a mteTriggerFailure notification with the appropriate
  2708.              * error code here.  
  2709.              */
  2710.             /*
  2711.              * "If the object identified is not accessible the sample attempt is in 
  2712.              * error, with the error code as from an SNMP request."  
  2713.              */
  2714.             DEBUGMSGTL(("mte_disco", "failure (auth?) getting discoIDn"));
  2715.             return -1;
  2716.         } else {
  2717.             if (item->mteTriggerDeltaDiscontinuityIDType ==
  2718.                 MTETRIGGERDELTADISCONTINUITYIDTYPE_TIMETICKS ||
  2719.                 item->mteTriggerDeltaDiscontinuityIDType ==
  2720.                 MTETRIGGERDELTADISCONTINUITYIDTYPE_TIMESTAMP) {
  2721.                 if (response->errstat == SNMPERR_SUCCESS) {
  2722.                     if (response->variables != NULL &&
  2723.                         response->variables->type == ASN_TIMETICKS) {
  2724.                         DEBUGMSGTL(("mte_disco",
  2725.                                     "got ASN_TIMETICKS-valued variablen"));
  2726.                         discoTicks =
  2727.                             *((unsigned long *) response->variables->val.
  2728.                               integer);
  2729.                         if (item->prevDiscoTicks != 0) {
  2730.                             if (discoTicks != item->prevDiscoTicks) {
  2731.                                 /*
  2732.                                  * Danger Will Robinson: there has been a discontinuity!  
  2733.                                  */
  2734.                                 DEBUGMSGTL(("mte_disco",
  2735.                                             "a discontinuity has occurredn"));
  2736.                                 item->prevDiscoTicks = discoTicks;
  2737.                                 snmp_free_pdu(response);
  2738.                                 return 1;
  2739.                             }
  2740.                         }
  2741.                         item->prevDiscoTicks = discoTicks;
  2742.                     } else {
  2743.                         /*
  2744.                          * XXX: send a mteTriggerFailure notification with the
  2745.                          * appropriate error code here.  
  2746.                          */
  2747.                         if (response->variables != NULL &&
  2748.                             (response->variables->type == SNMP_NOSUCHOBJECT
  2749.                              || response->variables->type ==
  2750.                              SNMP_NOSUCHINSTANCE
  2751.                              || response->variables->type ==
  2752.                              SNMP_ENDOFMIBVIEW)) {
  2753.                             /*
  2754.                              * noSuchName I guess.  
  2755.                              */
  2756.                         } else {
  2757.                             /*
  2758.                              * badType.  
  2759.                              */
  2760.                         }
  2761.                         DEBUGMSGTL(("mte_disco",
  2762.                                     "failure getting discoIDn"));
  2763.                         snmp_free_pdu(response);
  2764.                         return -1;
  2765.                     }
  2766.                 } else {
  2767.                     /*
  2768.                      * XXX: send a mteTriggerFailure notification with the appropriate
  2769.                      * error code (just use response->errstat) here.  
  2770.                      */
  2771.                     DEBUGMSGTL(("mte_disco", "failure getting discoIDn"));
  2772.                     snmp_free_pdu(response);
  2773.                     return -1;
  2774.                 }
  2775.             } else {
  2776.                 /*
  2777.                  * Don't handle dateAndTime type queries yet.  
  2778.                  */
  2779.                 DEBUGMSGTL(("mte_disco",
  2780.                             "dateAndTime query UNIMPLEMENTEDn"));
  2781.             }
  2782.             snmp_free_pdu(response);
  2783.         }
  2784.     }
  2785.     /*
  2786.      * "...if this object does not point to sysUpTime discontinuity checking
  2787.      * MUST still check sysUpTime for an overall discontinuity."  
  2788.      */
  2789.     if (snmp_oid_compare(item->mteTriggerDeltaDiscontinuityID,
  2790.                          item->mteTriggerDeltaDiscontinuityIDLen,
  2791.                          sysUpTimeInstance,
  2792.                          sizeof(sysUpTimeInstance) / sizeof(oid)) != 0) {
  2793.         DEBUGMSGTL(("mte_disco", "discoID != sysUpTimeInstancen"));
  2794.         /*
  2795.          * At the moment we only support checking the local system so there's no
  2796.          * point doing anything extra here.  
  2797.          */
  2798.     }
  2799.     /*
  2800.      * Well if we got all the way to here, then there has been neither a
  2801.      * discontinuity nor an error.  
  2802.      */
  2803.     DEBUGMSGTL(("mte_disco", "no discontinuityn"));
  2804.     return 0;
  2805. }
  2806. void
  2807. mte_run_trigger(unsigned int clientreg, void *clientarg)
  2808. {
  2809.     struct mteTriggerTable_data *item =
  2810.         (struct mteTriggerTable_data *) clientarg;
  2811.     netsnmp_pdu    *pdu = NULL, *response = NULL;
  2812.     char            buf[SPRINT_MAX_LEN];
  2813.     int             msg_type = SNMP_MSG_GET, disco;
  2814.     oid            *next_oid;
  2815.     size_t          next_oid_len;
  2816.     long           *value, *old_value, x;
  2817.     struct last_state *laststate;
  2818.     char            lastbool = 0, boolresult = 0, lastthresh = 0, senttrap = 0;
  2819.     if (!item) {
  2820.         /*
  2821.          * ack 
  2822.          */
  2823.         snmp_alarm_unregister(clientreg);
  2824.         return;
  2825.     }
  2826.     DEBUGMSGTL(("mteTriggertable", "Running trigger for %s/%sn",
  2827.                 item->mteOwner, item->mteTriggerName));
  2828.     next_oid = item->mteTriggerValueID;
  2829.     next_oid_len = item->mteTriggerValueIDLen;
  2830.     if (item->mteTriggerValueIDWildcard == TV_TRUE)
  2831.         msg_type = SNMP_MSG_GETNEXT;
  2832.     item->hc_storage_old = item->hc_storage;
  2833.     item->hc_storage = NULL;
  2834.     do {
  2835.         pdu = snmp_pdu_create(msg_type);
  2836.         snmp_add_null_var(pdu, next_oid, next_oid_len);
  2837.         response = mte_get_response(item, pdu);
  2838.         if (!response)
  2839.             break;              /* XXX: proper failure */
  2840.         if (item->mteTriggerValueIDWildcard == TV_TRUE &&
  2841.             ((response->variables->type >= SNMP_NOSUCHOBJECT &&
  2842.               response->variables->type <= SNMP_ENDOFMIBVIEW) ||
  2843.              snmp_oid_compare(item->mteTriggerValueID,
  2844.                               item->mteTriggerValueIDLen,
  2845.                               response->variables->name,
  2846.                               item->mteTriggerValueIDLen) != 0)) {
  2847.             DEBUGMSGTL(("mteTriggerTable",
  2848.                         "DONE, last varbind processedn"));
  2849.             snmp_free_pdu(response);
  2850.             break;
  2851.         }
  2852.         /*
  2853.          * shorter pointers 
  2854.          */
  2855.         next_oid = response->variables->name;
  2856.         next_oid_len = response->variables->name_length;
  2857.         /*
  2858.          * Send a "bad type" notification if the type of the target object is 
  2859.          * non-INTEGER and the test type is either `boolean' or `threshold'
  2860.          * (which want to do arithmetic).  
  2861.          */
  2862.         if (((item->mteTriggerTest[0] & MTETRIGGERTEST_BOOLEAN) ||
  2863.              (item->mteTriggerTest[0] & MTETRIGGERTEST_THRESHOLD)) &&
  2864.             response->errstat == SNMPERR_SUCCESS &&
  2865.             !mte_is_integer_type(response->variables->type)) {
  2866.             long            failure = MTE_FAILURE_BADTYPE;
  2867.             send_mte_trap(item, mteTriggerFailure,
  2868.                           sizeof(mteTriggerFailure) / sizeof(oid),
  2869.                           next_oid, next_oid_len, &failure,
  2870.                           NULL, NULL, "failure: bad type");
  2871.             snmp_free_pdu(response);
  2872.             /*
  2873.              * RFC2981, p.15: "If the value syntax of those objects
  2874.              * [returned by a getNext-style match] is not usable, that
  2875.              * results in a `badType' error THAT TERMINATES THE SCAN."
  2876.              * (my emphasis).  
  2877.              */
  2878.             break;
  2879.         }
  2880.         /*
  2881.          * Clone the value.  XXX: What happens if it's an unsigned type? Or a
  2882.          * 64-bit type, or an OCTET STRING for the sake of argument.  Do
  2883.          * everything in 64-bit arithmetic perhaps?  Generate "bad type"
  2884.          * notifications for non-INTEGER cases (except for existence).  
  2885.          */
  2886.         if (response->errstat == SNMPERR_SUCCESS &&
  2887.             response->variables->val.integer)
  2888.             memdup((unsigned char **) &value,
  2889.                    (unsigned char *) response->variables->val.integer,
  2890.                    sizeof(*response->variables->val.integer));
  2891.         else
  2892.             value = NULL;
  2893.         snprint_variable(buf, sizeof(buf),
  2894.                          next_oid, next_oid_len, response->variables);
  2895.         buf[sizeof(buf) - 1] = '';
  2896.         DEBUGMSGTL(("mteTriggerTable", "received %s (type %d)n", buf,
  2897.                     response->variables->type));
  2898.         /*
  2899.          * see if we have old values for this 
  2900.          */
  2901.         laststate = header_complex_get_from_oid(item->hc_storage_old,
  2902.                                                 next_oid, next_oid_len);
  2903.         if (laststate) {
  2904.             old_value = laststate->value;
  2905.             lastbool = laststate->lastbool;
  2906.             lastthresh = laststate->lastthreshold;
  2907.         } else {
  2908.             old_value = NULL;
  2909.             lastthresh = MTE_THRESHOLD_BEGIN;
  2910.         }
  2911.         /*
  2912.          * deal with existence tests 
  2913.          */
  2914.         if (item->mteTriggerTest[0] & MTETRIGGERTEST_EXISTENCE) {
  2915.             if ((item->mteTriggerExistenceTest[0] &
  2916.                  MTETRIGGEREXISTENCETEST_PRESENT)
  2917.                 && value && !old_value &&
  2918.                 (item->started ||
  2919.                  (item->mteTriggerExistenceStartup[0] &
  2920.                   MTETRIGGEREXISTENCESTARTUP_PRESENT))) {
  2921.                 /*
  2922.                  * XXX: if mteTriggerExistenceTest is not "present", for
  2923.                  * example, and then turned on when has been previously
  2924.                  * off, do we respect the value of the last known
  2925.                  * existence status? 
  2926.                  */
  2927.                 send_mte_trap(item, mteTriggerFired,
  2928.                               sizeof(mteTriggerFired) / sizeof(oid),
  2929.                               next_oid, next_oid_len,
  2930.                               value, item->mteTriggerExistenceObjectsOwner,
  2931.                               item->mteTriggerExistenceObjects,
  2932.                               "existence: present");
  2933.                 run_mte_events(item, next_oid, next_oid_len,
  2934.                                item->mteTriggerExistenceEventOwner,
  2935.                                item->mteTriggerExistenceEvent);
  2936.                 senttrap = 1;
  2937.             }
  2938.             if ((item->mteTriggerExistenceTest[0] &
  2939.                  MTETRIGGEREXISTENCETEST_CHANGED)
  2940.                 && value && old_value && *old_value != *value) {
  2941.                 /*
  2942.                  * XXX: if mteTriggerExistenceTest is not "present", for
  2943.                  * example, and then turned on when has been previously
  2944.                  * off, do we respect the value of the last known
  2945.                  * existence status? 
  2946.                  */
  2947.                 send_mte_trap(item, mteTriggerFired,
  2948.                               sizeof(mteTriggerFired) / sizeof(oid),
  2949.                               next_oid, next_oid_len,
  2950.                               value, item->mteTriggerExistenceObjectsOwner,
  2951.                               item->mteTriggerExistenceObjects,
  2952.                               "existence: changed");
  2953.                 run_mte_events(item, next_oid, next_oid_len,
  2954.                                item->mteTriggerExistenceEventOwner,
  2955.                                item->mteTriggerExistenceEvent);
  2956.                 senttrap = 1;
  2957.             }
  2958.         }
  2959.         /*
  2960.          * Deal with boolean tests.  
  2961.          */
  2962.         if ((item->mteTriggerTest[0] & MTETRIGGERTEST_BOOLEAN) &&
  2963.             ((item->mteTriggerSampleType ==
  2964.               MTETRIGGERSAMPLETYPE_ABSOLUTEVALUE && value)
  2965.              || (item->mteTriggerSampleType ==
  2966.                  MTETRIGGERSAMPLETYPE_DELTAVALUE && value && old_value))) {
  2967.             if (item->mteTriggerSampleType ==
  2968.                 MTETRIGGERSAMPLETYPE_DELTAVALUE) {
  2969.                 /*
  2970.                  * XXX: Must check the discontinuity OID here.  
  2971.                  */
  2972.                 disco = mte_discontinuity_occurred(item);
  2973.                 if (disco == -1) {
  2974.                     /*
  2975.                      * An error notification has already been sent; just bail
  2976.                      * out now.  
  2977.                      */
  2978.                     /*
  2979.                      * XXX: should save values here?  
  2980.                      */
  2981.                     return;
  2982.                 } else if (disco == 1) {
  2983.                     /*
  2984.                      * A discontinuity has occurred; the right thing to do here
  2985.                      * depends on the exact type.  FOR NOW, assume long.  
  2986.                      */
  2987.                     x = *((long *) value) + (INT_MAX -
  2988.                                              *((long *) old_value));
  2989.                 } else {
  2990.                     x = *((long *) value) - *((long *) old_value);
  2991.                 }
  2992.             } else {
  2993.                 x = *((long *) value);
  2994.             }
  2995.             switch (item->mteTriggerBooleanComparison) {
  2996.             case MTETRIGGERBOOLEANCOMPARISON_UNEQUAL:
  2997.                 boolresult = (x != item->mteTriggerBooleanValue);
  2998.                 break;
  2999.             case MTETRIGGERBOOLEANCOMPARISON_EQUAL:
  3000.                 boolresult = (x == item->mteTriggerBooleanValue);
  3001.                 break;
  3002.             case MTETRIGGERBOOLEANCOMPARISON_LESS:
  3003.                 boolresult = (x < item->mteTriggerBooleanValue);
  3004.                 break;
  3005.             case MTETRIGGERBOOLEANCOMPARISON_LESSOREQUAL:
  3006.                 boolresult = (x <= item->mteTriggerBooleanValue);
  3007.                 break;
  3008.             case MTETRIGGERBOOLEANCOMPARISON_GREATER:
  3009.                 boolresult = (x > item->mteTriggerBooleanValue);
  3010.                 break;
  3011.             case MTETRIGGERBOOLEANCOMPARISON_GREATEROREQUAL:
  3012.                 boolresult = (x >= item->mteTriggerBooleanValue);
  3013.                 break;
  3014.             default:
  3015.                 snmp_log(LOG_WARNING,
  3016.                          "illegal value in mteTriggerBooleanComparison object: %ld",
  3017.                          item->mteTriggerBooleanComparison);
  3018.                 boolresult = item->lastboolresult;      /* to fail next test */
  3019.             }
  3020.             if (boolresult &&
  3021.                 ((item->mteTriggerBooleanStartup ==
  3022.                   MTETRIGGERBOOLEANSTARTUP_TRUE
  3023.                   && lastbool == (char)-1) || lastbool != boolresult)) {
  3024.                 send_mte_trap(item, mteTriggerFired,
  3025.                               sizeof(mteTriggerFired) / sizeof(oid),
  3026.                               next_oid, next_oid_len,
  3027.                               &x, item->mteTriggerBooleanObjectsOwner,
  3028.                               item->mteTriggerBooleanObjects,
  3029.                               "boolean: true");
  3030.                 run_mte_events(item, next_oid, next_oid_len,
  3031.                                item->mteTriggerBooleanEventOwner,
  3032.                                item->mteTriggerBooleanEvent);
  3033.                 senttrap = 1;
  3034.             }
  3035.             DEBUGMSGTL(("mteTriggerTable",
  3036.                         "value: %d %ld %lu x: %d %ld %lun", *value,
  3037.                         *value, *value, x, x, x));
  3038.             DEBUGMSGTL(("mteTriggerTable",
  3039.                         "boolean result: x=%d %s configured=%d = %dn",
  3040.                         x,
  3041.                         se_find_label_in_slist("mteBooleanOperators",
  3042.                                                item->
  3043.                                                mteTriggerBooleanComparison),
  3044.                         item->mteTriggerBooleanValue, boolresult));
  3045.         }
  3046.         /*
  3047.          * Deal with threshold tests.  XXX: doesn't handle "delta-type"
  3048.          * sampling.  
  3049.          */
  3050.         if ((item->mteTriggerTest[0] & MTETRIGGERTEST_THRESHOLD) &&
  3051.             ((item->mteTriggerSampleType ==
  3052.               MTETRIGGERSAMPLETYPE_ABSOLUTEVALUE && value)
  3053.              || (item->mteTriggerSampleType ==
  3054.                  MTETRIGGERSAMPLETYPE_DELTAVALUE && value && old_value))) {
  3055.             /*
  3056.              * XXX: correct intepretation of mteTriggerThresholdStartup? 
  3057.              */
  3058.             /*
  3059.              * only fires when passed and just set to active?  What
  3060.              * about a newly discovered node that is past a
  3061.              * threshold once we've been active for a turn at least? 
  3062.              */
  3063.             /*
  3064.              * XXX: Check notions of > vs >= 
  3065.              */
  3066.             if (((item->started == MTE_STARTED && laststate &&
  3067.                   lastthresh == MTE_THRESHOLD_LOW) ||
  3068.                  (item->started != MTE_STARTED &&
  3069.                   (item->mteTriggerThresholdStartup ==
  3070.                    MTETRIGGERTHRESHOLDSTARTUP_RISING
  3071.                    || item->mteTriggerThresholdStartup ==
  3072.                    MTETRIGGERTHRESHOLDSTARTUP_RISINGORFALLING)))
  3073.                 && (*value >= item->mteTriggerThresholdRising)) {
  3074.                 send_mte_trap(item, mteTriggerRising,
  3075.                               sizeof(mteTriggerRising) / sizeof(oid),
  3076.                               next_oid, next_oid_len, value,
  3077.                               item->mteTriggerThresholdObjectsOwner,
  3078.                               item->mteTriggerThresholdObjects,
  3079.                               "threshold: rising");
  3080.                 run_mte_events(item, next_oid, next_oid_len,
  3081.                                item->mteTriggerThresholdRisingEventOwner,
  3082.                                item->mteTriggerThresholdRisingEvent);
  3083.                 senttrap = 1;
  3084.             }
  3085.             if (((item->started == MTE_STARTED && laststate &&
  3086.                   lastthresh == MTE_THRESHOLD_HIGH) ||
  3087.                  (item->started != MTE_STARTED &&
  3088.                   (item->mteTriggerThresholdStartup ==
  3089.                    MTETRIGGERTHRESHOLDSTARTUP_FALLING
  3090.                    || item->mteTriggerThresholdStartup ==
  3091.                    MTETRIGGERTHRESHOLDSTARTUP_RISINGORFALLING)))
  3092.                 && (*value <= item->mteTriggerThresholdFalling)) {
  3093.                 send_mte_trap(item, mteTriggerFalling,
  3094.                               sizeof(mteTriggerFalling) / sizeof(oid),
  3095.                               next_oid, next_oid_len, value,
  3096.                               item->mteTriggerThresholdObjectsOwner,
  3097.                               item->mteTriggerThresholdObjects,
  3098.                               "threshold: falling");
  3099.                 run_mte_events(item, next_oid, next_oid_len,
  3100.                                item->mteTriggerThresholdFallingEventOwner,
  3101.                                item->mteTriggerThresholdFallingEvent);
  3102.                 senttrap = 1;
  3103.             }
  3104.         }
  3105.         if (value) {
  3106.             struct last_state *new_last_state =
  3107.                 SNMP_MALLOC_STRUCT(last_state);
  3108.             new_last_state->value = value;
  3109.             new_last_state->lastbool = boolresult;
  3110.             header_complex_add_data_by_oid(&item->hc_storage, next_oid,
  3111.                                            next_oid_len, new_last_state);
  3112.             /*
  3113.              * set our notion of the current known threshold state 
  3114.              */
  3115.             if (lastthresh == MTE_THRESHOLD_LOW &&
  3116.                 *value >= item->mteTriggerThresholdRising &&
  3117.                 *value > item->mteTriggerThresholdFalling)
  3118.                 new_last_state->lastthreshold = MTE_THRESHOLD_HIGH;
  3119.             else if (lastthresh == MTE_THRESHOLD_HIGH &&
  3120.                      *value < item->mteTriggerThresholdRising &&
  3121.                      *value <= item->mteTriggerThresholdFalling)
  3122.                 new_last_state->lastthreshold = MTE_THRESHOLD_LOW;
  3123.             else if (lastthresh == MTE_THRESHOLD_BEGIN) {
  3124.                 if (*value >= item->mteTriggerThresholdRising)
  3125.                     new_last_state->lastthreshold = MTE_THRESHOLD_HIGH;
  3126.                 else if (*value <= item->mteTriggerThresholdFalling)
  3127.                     new_last_state->lastthreshold = MTE_THRESHOLD_LOW;
  3128.                 /*
  3129.                  * XXX: else???  in between?  undefined? 
  3130.                  */
  3131.             } else {
  3132.                 new_last_state->lastthreshold = lastthresh;
  3133.             }
  3134.         }
  3135.         /*
  3136.          * extract from old hc storage 
  3137.          */
  3138.         if (laststate) {
  3139.             header_complex_extract_entry(&item->hc_storage_old,
  3140.                                          header_complex_find_entry(item->
  3141.                                                                    hc_storage_old,
  3142.                                                                    (void *)
  3143.                                                                    laststate));
  3144.             last_state_clean(laststate);
  3145.         }
  3146.         /*
  3147.          * We are now done with the response PDU.  
  3148.          */
  3149.         if (senttrap) 
  3150.             senttrap = 0;
  3151.         else
  3152.             snmp_free_pdu(response);
  3153.     } while (item->mteTriggerValueIDWildcard == TV_TRUE);
  3154.     /*
  3155.      * loop through old values for DNE cases 
  3156.      */
  3157.     if (item->mteTriggerExistenceTest[0] & MTETRIGGEREXISTENCETEST_ABSENT) {
  3158.         struct header_complex_index *iter;
  3159.         /*
  3160.          * XXX: broken 
  3161.          */
  3162.         if ((item->mteTriggerExistenceStartup[0] &
  3163.              MTETRIGGEREXISTENCESTARTUP_ABSENT)) {
  3164.             /*
  3165.              * XXX: send trap that nothing was found? 
  3166.              */
  3167.             /*
  3168.              * only if !wild? (see mib)
  3169.              */
  3170.         }
  3171.         for (iter = item->hc_storage_old; iter; iter = iter->next) {
  3172.             laststate = (struct last_state *) iter->data;
  3173.             send_mte_trap(item, mteTriggerFired,
  3174.                           sizeof(mteTriggerFired) / sizeof(oid),
  3175.                           iter->name, iter->namelen, laststate->value,
  3176.                           item->mteTriggerExistenceObjectsOwner,
  3177.                           item->mteTriggerExistenceObjects,
  3178.                           "existence: absent");
  3179.         }
  3180.         header_complex_free_all(item->hc_storage_old, last_state_clean);
  3181.         item->hc_storage_old = NULL;
  3182.     }
  3183.     item->started = MTE_STARTED;
  3184. }
  3185. /*
  3186.  * handling routines 
  3187.  */
  3188. void
  3189. mte_enable_trigger(struct mteTriggerTable_data *item)
  3190. {
  3191.     if (!item)
  3192.         return;
  3193.     if (item->alarmreg)
  3194.         snmp_alarm_unregister(item->alarmreg);
  3195.     if (item->mteTriggerFrequency > 0) {
  3196.         DEBUGMSGTL(("mteTriggertable", "Enabling trigger for %s/%s @ %un",
  3197.                     item->mteOwner, item->mteTriggerName,
  3198.                     item->mteTriggerFrequency));
  3199.         item->alarmreg =
  3200.             snmp_alarm_register(item->mteTriggerFrequency, SA_REPEAT,
  3201.                                 mte_run_trigger, item);
  3202.     }
  3203. }
  3204. void
  3205. mte_disable_trigger(struct mteTriggerTable_data *item)
  3206. {
  3207.     if (!item)
  3208.         return;
  3209.     if (item->alarmreg) {
  3210.         DEBUGMSGTL(("mteTriggertable", "Disabling trigger for %s/%sn",
  3211.                     item->mteOwner, item->mteTriggerName));
  3212.         snmp_alarm_unregister(item->alarmreg);
  3213.         item->alarmreg = 0;
  3214.     }
  3215.     item->started = MTE_NOTSTARTED;
  3216. }