On Mon, 25 Jul 2011 21:01:47 +0200 Claus wrote:
CK> A note about the general Mib index handling:
CK>
CK> The default is to create the MIB index at the persistentDir.
CK> But the default is owned by root and readonly, or sometime as on my
CK> macbook, not readable for users.
CK>
CK> So IMHO at leased the persistendDir should be configured at users
CK> snmp.conf.
Does this patch help?
diff --git a/acconfig.h b/acconfig.h
index 9a5d0ec..aa64f1a 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -115,8 +115,14 @@
/* AGENT_DIRECTORY_MODE: the mode the agents should use to create
directories with. Since the data stored here is probably sensitive, it
- probably should be read-only by root/administrator. */
-#define NETSNMP_AGENT_DIRECTORY_MODE 0700
+ probably should be read-only by root/administrator, and executable by
+ group/world (for access to public subdirs). */
+#define NETSNMP_AGENT_DIRECTORY_MODE 0711
+
+/* PUBLIC_DIRECTORY_MODE: the mode the library should use to create public
+ directories with. Since the data stored here is public, it should be
+ world readable. */
+#define NETSNMP_PUBLIC_DIRECTORY_MODE 0755
/* MAX_PERSISTENT_BACKUPS:
* The maximum number of persistent backups the library will try to
diff --git a/include/net-snmp/net-snmp-config.h.in b/include/net-snmp/net-snmp-config.h.in
index 726a515..c9df593 100644
--- a/include/net-snmp/net-snmp-config.h.in
+++ b/include/net-snmp/net-snmp-config.h.in
@@ -1681,8 +1678,14 @@
/* AGENT_DIRECTORY_MODE: the mode the agents should use to create
directories with. Since the data stored here is probably sensitive, it
- probably should be read-only by root/administrator. */
-#define NETSNMP_AGENT_DIRECTORY_MODE 0700
+ probably should be read-only by root/administrator, and executable by
+ group/world (for access to public subdirs). */
+#define NETSNMP_AGENT_DIRECTORY_MODE 0711
+
+/* PUBLIC_DIRECTORY_MODE: the mode the library should use to create public
+ directories with. Since the data stored here is public, it should be
+ world readable. */
+#define NETSNMP_PUBLIC_DIRECTORY_MODE 0755
/* MAX_PERSISTENT_BACKUPS:
* The maximum number of persistent backups the library will try to
diff --git a/snmplib/cert_util.c b/snmplib/cert_util.c
index 6d9efe5..94df9e7 100644
--- a/snmplib/cert_util.c
+++ b/snmplib/cert_util.c
@@ -783,7 +783,7 @@ _certindexes_load( void )
if ( dir == NULL ) {
DEBUGMSGT(("cert:index:load",
"creating new cert_indexes directory\n"));
- mkdirhier( filename, NETSNMP_AGENT_DIRECTORY_MODE, 0);
+ mkdirhier( filename, NETSNMP_PUBLIC_DIRECTORY_MODE, 0);
return;
}
diff --git a/snmplib/mib.c b/snmplib/mib.c
index 7fb7986..a3364a6 100644
--- a/snmplib/mib.c
+++ b/snmplib/mib.c
@@ -2784,7 +2784,7 @@ netsnmp_mibindex_load( void )
dir = opendir( tmpbuf );
if ( dir == NULL ) {
DEBUGMSGTL(("mibindex", "load: (new)\n"));
- mkdirhier( tmpbuf, NETSNMP_AGENT_DIRECTORY_MODE, 0);
+ mkdirhier( tmpbuf, NETSNMP_PUBLIC_DIRECTORY_MODE, 0);
return;
}
diff --git a/snmplib/snmp_api.c b/snmplib/snmp_api.c
index df44d75..cf98d72 100644
--- a/snmplib/snmp_api.c
+++ b/snmplib/snmp_api.c
@@ -95,6 +95,9 @@ SOFTWARE.
#include <sys/net/if_dl.h>
#endif
#endif
+#if HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
#include <errno.h>
#if HAVE_LOCALE_H
@@ -788,6 +791,17 @@ register_default_handlers(void)
netsnmp_register_service_handlers();
}
+static void
+netsnmp_init_persistent_dir(void)
+{
+ struct stat statbuf;
+
+ if (stat(get_persistent_directory(), &statbuf) != 0)
+ mkdirhier(get_persistent_directory(), NETSNMP_AGENT_DIRECTORY_MODE, 0);
+
+ return;
+}
+
static int init_snmp_init_done = 0; /* To prevent double init's. */
/**
* Calls the functions to do config file loading and mib module parsing
@@ -848,6 +862,7 @@ init_snmp(const char *type)
#endif
read_premib_configs();
+ netsnmp_init_persistent_dir();
#ifndef NETSNMP_DISABLE_MIB_LOADING
netsnmp_init_mib();
#endif /* NETSNMP_DISABLE_MIB_LOADING */
------------------------------------------------------------------------------
Got Input? Slashdot Needs You.
Take our quick survey online. Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders