packages: net-snmp/net-snmp-loadave-writable.patch - make "load" readonly i...

glen glen at pld-linux.org
Mon Dec 21 23:34:07 CET 2009


Author: glen                         Date: Mon Dec 21 22:34:07 2009 GMT
Module: packages                      Tag: HEAD
---- Log message:
- make "load" readonly if defined in main config, like sysDescription behaves

---- Files affected:
packages/net-snmp:
   net-snmp-loadave-writable.patch (1.4 -> 1.5) 

---- Diffs:

================================================================
Index: packages/net-snmp/net-snmp-loadave-writable.patch
diff -u packages/net-snmp/net-snmp-loadave-writable.patch:1.4 packages/net-snmp/net-snmp-loadave-writable.patch:1.5
--- packages/net-snmp/net-snmp-loadave-writable.patch:1.4	Mon Dec 21 22:02:14 2009
+++ packages/net-snmp/net-snmp-loadave-writable.patch	Mon Dec 21 23:34:02 2009
@@ -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}},
@@ -25,11 +30,19 @@
           {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
@@ -40,7 +53,33 @@
  }
  
  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"));
@@ -65,9 +104,16 @@
 +                        "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;
@@ -95,6 +141,7 @@
 +        {
 +            int idx = name[name_len - 1] - 1;
 +            maxload[idx] = laConfig;
++            laConfigSet = 1;
 +        }
 +    }
 +
@@ -104,7 +151,7 @@
  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));
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/net-snmp/net-snmp-loadave-writable.patch?r1=1.4&r2=1.5&f=u



More information about the pld-cvs-commit mailing list