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

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