]> git.pld-linux.org Git - packages/net-snmp.git/commitdiff
- make "load" readonly if defined in main config, like sysDescription behaves
authorElan Ruusamäe <glen@pld-linux.org>
Mon, 21 Dec 2009 22:34:02 +0000 (22:34 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    net-snmp-loadave-writable.patch -> 1.5

net-snmp-loadave-writable.patch

index 9c2e5e18c1dc1083e31962221b29f84d095c2780..7b69ef335840d7d4a45b6015039e210a3ef0ba43 100644 (file)
@@ -1,22 +1,27 @@
 --- net-snmp-5.4.2.1/agent/mibgroup/ucd-snmp/loadave.c~        2009-12-21 21:00:10.094254079 +0200
 +++ net-snmp-5.4.2.1/agent/mibgroup/ucd-snmp/loadave.c 2009-12-21 22:02:45.398903148 +0200
-@@ -137,6 +137,15 @@
- double          maxload[3];
+@@ -135,7 +135,19 @@
+ #include "util_funcs.h"
+ #include "kernel.h"
  
+-double          maxload[3];
++static double maxload[3];
++static int laConfigSet = 0;
++
 +static int
 +loadave_store_config(int a, int b, void *c, void *d)
 +{
 +    char line[SNMP_MAXBUF_SMALL];
-+    snprintf(line, SNMP_MAXBUF_SMALL, "load %.02f %.02f %.02f", maxload[0], maxload[1], maxload[2]);
-+    snmpd_store_config(line);
++    if (laConfigSet > 0) {
++        snprintf(line, SNMP_MAXBUF_SMALL, "pload %.02f %.02f %.02f", maxload[0], maxload[1], maxload[2]);
++        snmpd_store_config(line);
++    }
 +    return SNMPERR_SUCCESS;
 +}
-+
  void
  init_loadave(void)
- {
-@@ -152,7 +161,7 @@
+@@ -152,7 +164,7 @@
           {ERRORNAME}},
          {LOADAVE, ASN_OCTET_STR, RONLY, var_extensible_loadave, 1,
           {LOADAVE}},
           {LOADMAXVAL}},
          {LOADAVEINT, ASN_INTEGER, RONLY, var_extensible_loadave, 1,
           {LOADAVEINT}},
-@@ -182,6 +191,14 @@
+@@ -179,9 +191,22 @@
+     REGISTER_MIB("ucd-snmp/loadave", extensible_loadave_variables,
+                  variable2, loadave_variables_oid);
++    laConfigSet = 0;
++
      snmpd_register_config_handler("load", loadave_parse_config,
                                    loadave_free_config,
                                    "max1 [max5] [max15]");
 +
++    snmpd_register_config_handler("pload",
++                                  loadave_parse_config, NULL, NULL);
++
 +
 +    /*
 +     * we need to be called back later
  }
  
  void
-@@ -309,6 +326,63 @@
+@@ -189,6 +214,25 @@
+ {
+     int             i;
++    if (strcmp(token, "pload") == 0) {
++        if (laConfigSet < 0) {
++            snmp_log(LOG_WARNING,
++                     "ignoring attempted override of read-only load\n");
++            return;
++        } else {
++            laConfigSet++;
++        }
++    } else {
++        if (laConfigSet > 0) {
++            snmp_log(LOG_WARNING,
++                     "ignoring attempted override of read-only load\n");
++            /*
++             * Fall through and copy in this value.
++             */
++        }
++        laConfigSet = -1;
++    }
++
+     for (i = 0; i <= 2; i++) {
+         if (cptr != NULL)
+             maxload[i] = atof(cptr);
+@@ -309,6 +353,71 @@
      return 0;
  }
  
@@ -54,7 +93,7 @@
 +    static double laConfig = 0;
 +
 +    switch (action) {
-+    case RESERVE1:
++    case RESERVE1: /* Check values for acceptability */
 +        if (var_val_type != ASN_OCTET_STR) {
 +            DEBUGMSGTL(("ucd-snmp/loadave",
 +                        "write to laConfig not ASN_OCTET_STR\n"));
 +                        "write to laConfig: bad length\n"));
 +            return SNMP_ERR_WRONGLENGTH;
 +        }
++
++        if (laConfigSet < 0) {
++            /*
++             * The object is set in a read-only configuration file.
++             */
++            return SNMP_ERR_NOTWRITABLE;
++        }
 +        break;
 +
-+    case RESERVE2:
++    case RESERVE2: /* Allocate memory and similar resources */
 +        {
 +            u_char buf[8];
 +            int old_errno = errno;
 +        {
 +            int idx = name[name_len - 1] - 1;
 +            maxload[idx] = laConfig;
++            laConfigSet = 1;
 +        }
 +    }
 +
  u_char         *
  var_extensible_loadave(struct variable * vp,
                         oid * name,
-@@ -328,6 +402,10 @@
+@@ -328,6 +437,10 @@
      case MIBINDEX:
          long_ret = name[*length - 1];
          return ((u_char *) (&long_ret));
This page took 0.11226 seconds and 4 git commands to generate.