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

SNMP编程

开发平台:

Unix_Linux

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