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