Blame SOURCES/net-snmp-5.7.2-client-write-var.patch

34d7f3
1151310 - snmptrap can't create (or write to) /var/lib/net-snmp/snmpapp.conf if isn't run under root
34d7f3
Backported from:
34d7f3
34d7f3
commit 53ee5f1d240ac90adae935538bdc2ca13a8caa32
34d7f3
Author: Jan Safranek <jsafranek@users.sourceforge.net>
34d7f3
Date:   Wed Feb 18 16:29:16 2015 +0100
34d7f3
34d7f3
    CHANGES: snmplib: Fixed reporting 'error writing to /var/xxx/snmpapp.conf'.
34d7f3
    
34d7f3
    When a client utility, such as snmptrap, tries to write to its persistent
34d7f3
    configuration file (/var/net-snmp/snmpapp.conf in Fedora), do not report
34d7f3
    any error when open() fails. The tool is typically run by non-root, who
34d7f3
    cannot write to /var and the error just confuses users.
34d7f3
    
34d7f3
    And when doing it, make sure that "snmpapp" string is defined only on one
34d7f3
    place, just in case.
34d7f3
34d7f3
diff -up net-snmp-5.7.2/agent/mibgroup/disman/expression/expValueTable.c.test net-snmp-5.7.2/agent/mibgroup/disman/expression/expValueTable.c
34d7f3
--- net-snmp-5.7.2/agent/mibgroup/disman/expression/expValueTable.c.test	2012-10-10 00:28:58.000000000 +0200
34d7f3
+++ net-snmp-5.7.2/agent/mibgroup/disman/expression/expValueTable.c	2015-06-18 14:06:47.871027563 +0200
34d7f3
@@ -127,7 +127,7 @@ init_expValueTable(void)
34d7f3
     REGISTER_MIB("expValueTable",
34d7f3
                  expValueTable_variables, variable2,
34d7f3
                  expValueTable_variables_oid);
34d7f3
-    init_snmp("snmpapp");
34d7f3
+    init_snmp(NETSNMP_APPLICATION_CONFIG_TYPE);
34d7f3
 
34d7f3
     /*
34d7f3
      * Initialize a "session" that defines who we're going to talk to
34d7f3
diff -up net-snmp-5.7.2/apps/snmptranslate.c.test net-snmp-5.7.2/apps/snmptranslate.c
34d7f3
--- net-snmp-5.7.2/apps/snmptranslate.c.test	2012-10-10 00:28:58.000000000 +0200
34d7f3
+++ net-snmp-5.7.2/apps/snmptranslate.c	2015-06-18 14:06:47.872027568 +0200
34d7f3
@@ -236,7 +236,7 @@ main(int argc, char *argv[])
34d7f3
         }
34d7f3
     }
34d7f3
 
34d7f3
-    init_snmp("snmpapp");
34d7f3
+    init_snmp(NETSNMP_APPLICATION_CONFIG_TYPE);
34d7f3
     if (optind < argc)
34d7f3
         current_name = argv[optind];
34d7f3
 
34d7f3
diff -up net-snmp-5.7.2/apps/snmptrap.c.test net-snmp-5.7.2/apps/snmptrap.c
34d7f3
--- net-snmp-5.7.2/apps/snmptrap.c.test	2012-10-10 00:28:58.000000000 +0200
34d7f3
+++ net-snmp-5.7.2/apps/snmptrap.c	2015-06-18 14:06:47.872027568 +0200
34d7f3
@@ -386,7 +386,7 @@ main(int argc, char *argv[])
34d7f3
         snmp_free_pdu(response);
34d7f3
 
34d7f3
     snmp_close(ss);
34d7f3
-    snmp_shutdown("snmpapp");
34d7f3
+    snmp_shutdown(NETSNMP_APPLICATION_CONFIG_TYPE);
34d7f3
     SOCK_CLEANUP;
34d7f3
     return exitval;
34d7f3
 }
34d7f3
diff -up net-snmp-5.7.2/include/net-snmp/library/read_config.h.test net-snmp-5.7.2/include/net-snmp/library/read_config.h
34d7f3
--- net-snmp-5.7.2/include/net-snmp/library/read_config.h.test	2012-10-10 00:28:58.000000000 +0200
34d7f3
+++ net-snmp-5.7.2/include/net-snmp/library/read_config.h	2015-06-18 14:06:47.873027572 +0200
34d7f3
@@ -15,6 +15,12 @@ extern          "C" {
34d7f3
 #define PREMIB_CONFIG 1
34d7f3
 #define EITHER_CONFIG 2
34d7f3
 
34d7f3
+/*
34d7f3
+ * Value of 'type' parameter of various snmp_config calls,
34d7f3
+ * used by Net-SNMP client utilities.
34d7f3
+ */
34d7f3
+#define NETSNMP_APPLICATION_CONFIG_TYPE "snmpapp"
34d7f3
+
34d7f3
 #include <net-snmp/config_api.h>
34d7f3
 
34d7f3
     /*
34d7f3
diff -up net-snmp-5.7.2/snmplib/read_config.c.test net-snmp-5.7.2/snmplib/read_config.c
34d7f3
--- net-snmp-5.7.2/snmplib/read_config.c.test	2012-10-10 00:28:58.000000000 +0200
34d7f3
+++ net-snmp-5.7.2/snmplib/read_config.c	2015-06-18 14:06:47.874027577 +0200
34d7f3
@@ -1540,7 +1540,14 @@ read_config_store(const char *type, cons
34d7f3
         DEBUGMSGTL(("read_config:store", "storing: %s\n", line));
34d7f3
         fclose(fout);
34d7f3
     } else {
34d7f3
-        snmp_log(LOG_ERR, "read_config_store open failure on %s\n", filep);
34d7f3
+        if (strcmp(NETSNMP_APPLICATION_CONFIG_TYPE, type) != 0) {
34d7f3
+            /*
34d7f3
+             * Ignore this error in client utilities, they can run with random
34d7f3
+             * UID/GID and typically cannot write to /var. Error message just
34d7f3
+             * confuses people.
34d7f3
+             */
34d7f3
+            snmp_log(LOG_ERR, "read_config_store open failure on %s");
34d7f3
+        }
34d7f3
     }
34d7f3
 #ifdef NETSNMP_PERSISTENT_MASK
34d7f3
     umask(oldmask);
34d7f3
diff -up net-snmp-5.7.2/snmplib/snmp_parse_args.c.test net-snmp-5.7.2/snmplib/snmp_parse_args.c
34d7f3
--- net-snmp-5.7.2/snmplib/snmp_parse_args.c.test	2012-10-10 00:28:58.000000000 +0200
34d7f3
+++ net-snmp-5.7.2/snmplib/snmp_parse_args.c	2015-06-18 14:06:47.874027577 +0200
34d7f3
@@ -250,7 +250,7 @@ netsnmp_parse_args(int argc,
34d7f3
             break;
34d7f3
 
34d7f3
         case 'H':
34d7f3
-            init_snmp("snmpapp");
34d7f3
+            init_snmp(NETSNMP_APPLICATION_CONFIG_TYPE);
34d7f3
             fprintf(stderr, "Configuration directives understood:\n");
34d7f3
             read_config_print_usage("  ");
34d7f3
             return (NETSNMP_PARSE_ARGS_SUCCESS_EXIT);
34d7f3
@@ -640,7 +640,7 @@ netsnmp_parse_args(int argc,
34d7f3
     /*
34d7f3
      * read in MIB database and initialize the snmp library
34d7f3
      */
34d7f3
-    init_snmp("snmpapp");
34d7f3
+    init_snmp(NETSNMP_APPLICATION_CONFIG_TYPE);
34d7f3
 
34d7f3
     /*
34d7f3
      * session default version 
34d7f3
commit 653da2f955f88d7419363e6d31f2b5f0ffdc4f73
34d7f3
Author: Jan Safranek <jsafranek@users.sourceforge.net>
34d7f3
Date:   Thu Feb 19 13:40:37 2015 +0100
34d7f3
34d7f3
    Fixed missing printf argument from previous commit.
34d7f3
34d7f3
diff --git a/snmplib/read_config.c b/snmplib/read_config.c
34d7f3
index 6157fc6..2972232 100644
34d7f3
--- a/snmplib/read_config.c
34d7f3
+++ b/snmplib/read_config.c
34d7f3
@@ -1317,7 +1317,7 @@ read_config_store(const char *type, const char *line)
34d7f3
              * UID/GID and typically cannot write to /var. Error message just
34d7f3
              * confuses people.
34d7f3
              */
34d7f3
-            snmp_log(LOG_ERR, "read_config_store open failure on %s");
34d7f3
+            snmp_log(LOG_ERR, "read_config_store open failure on %s\n", filep);
34d7f3
         }
34d7f3
     }
34d7f3
 #ifdef NETSNMP_PERSISTENT_MASK