procdify snmpd

This commit is contained in:
Sukru Senli 2015-05-30 18:15:55 +02:00 committed by Martin Schröder
parent 824f729791
commit aeffe553bc
8 changed files with 75 additions and 264 deletions

View file

@ -1,5 +1,5 @@
#
# Copyright (C) 2006-2012 OpenWrt.org
# Copyright (C) 2006-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
@ -8,12 +8,14 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=net-snmp
PKG_VERSION:=5.4.2.1
PKG_RELEASE:=5
PKG_VERSION:=5.4.4
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/net-snmp
PKG_MD5SUM:=984932520143f0c8bf7b7ce1fc9e1da1
PKG_MD5SUM:=95aa054f3c99a1ce242807d7eaf98619
PKG_MAINTAINER:=Jo-Philipp Wich <jow@openwrt.org>
PKG_LICENSE:=MIT BSD-3-Clause-Clear
PKG_FIXUP = patch-libtool
@ -38,7 +40,6 @@ define Package/libnetsnmp
$(call Package/net-snmp/Default)
SECTION:=libs
CATEGORY:=Libraries
DEPENDS:=+libelf +libopenssl
TITLE:=Open source SNMP implementation (libraries)
endef
@ -78,7 +79,6 @@ endef
define Package/snmpd-static
$(call Package/net-snmp/Default)
TITLE:=Open source SNMP implementation (daemon)
DEPENDS:=+libelf
endef
define Package/snmpd-static/description
@ -155,7 +155,7 @@ CONFIGURE_ARGS += \
--enable-mfd-rewrites \
--enable-shared \
--enable-static \
--with-endianness=little \
--with-endianness=$(if $(CONFIG_BIG_ENDIAN),big,little) \
--with-logfile=/var/log/snmpd.log \
--with-persistent-directory=/usr/lib/snmp/ \
--with-default-snmp-version=1 \

View file

@ -2,6 +2,9 @@
# Copyright (C) 2008 OpenWrt.org
START=50
USE_PROCD=1
NAME=snmpd
PROG=/usr/sbin/snmpd
DEFAULT=/etc/default/snmpd
LIB_D=/var/lib/snmp
LOG_D=/var/log
@ -41,6 +44,16 @@ snmpd_com2sec_add() {
[ -n "$community" ] || return 0
echo "com2sec $secname $source $community" >> $RUN_C
}
snmpd_com2sec6_add() {
local cfg="$1"
config_get secname "$cfg" secname
[ -n "$secname" ] || return 0
config_get source "$cfg" source
[ -n "$source" ] || return 0
config_get community "$cfg" community
[ -n "$community" ] || return 0
echo "com2sec6 $secname $source $community" >> $RUN_C
}
snmpd_group_add() {
local cfg="$1"
config_get group "$cfg" group
@ -101,17 +114,20 @@ snmpd_pass_add() {
#snmpd_exec_add() {
# local cfg="$1"
# config_get name "$cfg" name
# [ -n "$name" ] || return 0
# config_get prog "$cfg" prog
# [ -n "$prog" ] || return 0
# config_get args "$cfg" args
# config_get miboid "$cfg" miboid
# echo "exec $miboid $name $prog $args" >> $RUN_C
#}
start() {
config_get name "$cfg" name
[ -n "$name" ] || return 0
config_get prog "$cfg" prog
[ -n "$prog" ] || return 0
config_get args "$cfg" args
config_get miboid "$cfg" miboid
echo "exec $miboid $name $prog $args" >> $RUN_C
}
service_triggers() {
procd_add_reload_trigger snmpd
}
start_service() {
config_load snmpd
config_get enabled daemon enabled
config_get_bool enabled daemon enabled 0
[ "$enabled" == "1" ] || return
@ -123,6 +139,7 @@ start() {
config_foreach snmpd_agent_add agent
config_foreach snmpd_system_add system
config_foreach snmpd_com2sec_add com2sec
config_foreach snmpd_com2sec6_add com2sec6
config_foreach snmpd_group_add group
config_foreach snmpd_view_add view
config_foreach snmpd_access_add access
@ -130,9 +147,12 @@ start() {
# config_foreach snmpd_exec_add exec
[ -f $DEFAULT ] && . $DEFAULT
$DEBUG /usr/sbin/snmpd $OPTIONS
procd_open_instance
procd_set_param command "$PROG" -f $OPTIONS
procd_close_instance
}
stop() {
[ -f $PID_F ] && kill $(cat $PID_F)
stop_service() {
service_stop /usr/sbin/snmpd
[ -f $PID_F ] && rm -f $PID_F
[ -f $RUN_C ] && rm -f $RUN_C
}

View file

@ -1,6 +1,6 @@
--- a/agent/mibgroup/mibII/interfaces.c
+++ b/agent/mibgroup/mibII/interfaces.c
@@ -1550,6 +1550,10 @@ Interface_Scan_Init(void)
@@ -1561,6 +1561,10 @@ Interface_Scan_Init(void)
struct ifnet *nnew;
char *stats, *ifstart = line;
@ -11,7 +11,7 @@
if (line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';
@@ -1583,7 +1587,7 @@ Interface_Scan_Init(void)
@@ -1594,7 +1598,7 @@ Interface_Scan_Init(void)
&coll) != 5)) {
if ((scan_line_to_use == scan_line_2_2)
&& !strstr(line, "No statistics available"))

View file

@ -1,95 +0,0 @@
--- a/FAQ
+++ b/FAQ
@@ -99,7 +99,7 @@ TABLE OF CONTENTS
I don't understand the new access control stuff - what does it mean?
How do I configure SNMPv3 users?
The 'createUser' line disappears when I start the agent. Why?
- What's the difference between /var/net-snmp and /usr/local/share/snmp?
+ What's the difference between /var/lib/snmp and /usr/share/snmp?
My new agent is ignoring the old snmpd.conf file. Why?
Why am I getting "Connection refused"?
Why can't I see values in the UCDavis 'extensible' or 'disk' trees?
@@ -643,7 +643,7 @@ How do I add a MIB to the tools?
There are two steps required to add a new MIB file to the tools.
Firstly, copy the MIB file into the appropiate location:
- cp MY-MIB.txt /usr/local/share/snmp/mibs
+ cp MY-MIB.txt /usr/share/snmp/mibs
(which makes it available to everyone on the system)
or
@@ -1177,7 +1177,7 @@ My traphandler script doesn't work when
If this is the case, then you can specify this interpreter
explicitly as part of the trap handle directive:
- traphandle default /usr/bin/perl /usr/local/bin/log_it
+ traphandle default /usr/bin/perl /usr/bin/log_it
In this case, it's almost certain that you'll also
need to give the full path to the traphandle script (as shown)
@@ -1251,7 +1251,7 @@ OK, what should I put in snmp.conf?
string to use.
Some of these (such as the MIB file location), might be best put in
- a shared snmp.conf file (typically /usr/local/share/snmp/snmp.conf or
+ a shared snmp.conf file (typically /usr/share/snmp/snmp.conf or
/etc/snmp/snmp.conf) to apply to all users of the system. Others
(particularly the SNMPv3 security settings), are more likely to refer
to a particular user, and should go in a personal snmp.conf file
@@ -1476,7 +1476,7 @@ Why aren't my mib files being read in?
Alternatively, the tools may be looking in the wrong place.
- The default location for the mib files is /usr/local/share/snmp/mibs.
+ The default location for the mib files is /usr/share/snmp/mibs.
Again, this is set when the suite is first configured and compiled.
This can be changed using the environmental variable 'MIBDIRS'
or the snmp.conf directive 'mibdirs'.
@@ -2430,7 +2430,7 @@ How do I configure SNMPv3 users?
There are three ways to configure SNMPv3 users:
- 1) Stop the agent, and create a file /var/net-snmp/snmpd.conf,
+ 1) Stop the agent, and create a file /var/lib/snmp/snmpd.conf,
containing the line
createUser {myUser} MD5 {myPassword} DES
@@ -2443,7 +2443,7 @@ How do I configure SNMPv3 users?
net-snmp-config --create-snmpv3-user
and follow the instructions. This will create an entry
- in the /var/net-snmp/snmpd.conf file similar to the above.
+ in the /var/lib/snmp/snmpd.conf file similar to the above.
Then re-start the snmpd agent.
3) Make sure the agent is running, and will respond to a suitable
@@ -2476,16 +2476,16 @@ The 'createUser' line disappears when I
-What's the difference between /var/net-snmp and /usr/local/share/snmp?
----------------------------------------------------------------------
+What's the difference between /var/lib/snmp and /usr/share/snmp?
+----------------------------------------------------------------
- The /var/net-snmp location is primarily used for information set
+ The /var/lib/snmp location is primarily used for information set
during the running of the agent, which needs to be persistent between
one run of the agent and the next. Apart from "createUser" (see
the previous entry), you shouldn't need to touch this file.
All other user-provided configuration should go in the traditional
- location (typically /usr/local/share/snmp/snmpd.conf or /etc/snmp).
+ location (typically /usr/share/snmp or /etc/snmp).
@@ -2498,7 +2498,7 @@ My new agent is ignoring the old snmpd.c
distribution), with the current release installed from the source.
The default location for this file with the basic distribution is
- /usr/local/share/snmp/snmpd.conf (or PREFIX/share/snmp/snmpd.conf).
+ /usr/share/snmp/snmpd.conf (or PREFIX/share/snmp/snmpd.conf).
Ready-installed versions often look for the file as /etc/snmpd.conf,
or /etc/snmp/snmpd.conf. Try moving the old config file to the new
location, and restart the agent.

View file

@ -1,142 +0,0 @@
--- a/EXAMPLE.conf.def
+++ b/EXAMPLE.conf.def
@@ -6,7 +6,7 @@
###############################################################################
#
# This file is intended to only be an example. If, however, you want
-# to use it, it should be placed in SYSCONFDIR/snmp/snmpd.conf.
+# to use it, it should be placed in /etc/snmp/snmpd.conf.
# When the snmpd agent starts up, this is where it will look for it.
#
# You might be interested in generating your own snmpd.conf file using
@@ -58,31 +58,37 @@
# from):
# sec.name source community
-com2sec local localhost COMMUNITY
-com2sec mynetwork NETWORK/24 COMMUNITY
+com2sec paranoid default public
+#com2sec readonly default public
+#com2sec readwrite default private
####
# Second, map the security names into group names:
# sec.model sec.name
-group MyRWGroup v1 local
-group MyRWGroup v2c local
-group MyRWGroup usm local
-group MyROGroup v1 mynetwork
-group MyROGroup v2c mynetwork
-group MyROGroup usm mynetwork
+group MyROSystem v1 paranoid
+group MyROSystem v2c paranoid
+group MyROSystem usm paranoid
+group MyROGroup v1 readonly
+group MyROGroup v2c readonly
+group MyROGroup usm readonly
+group MyRWGroup v1 readwrite
+group MyRWGroup v2c readwrite
+group MyRWGroup usm readwrite
####
# Third, create a view for us to let the groups have rights to:
# incl/excl subtree mask
view all included .1 80
+view system included .iso.org.dod.internet.mgmt.mib-2.system
####
# Finally, grant the 2 groups access to the 1 view with different
# write permissions:
# context sec.model sec.level match read write notif
+access MyROSystem "" any noauth exact system none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
@@ -100,8 +106,8 @@ access MyRWGroup "" any noaut
# value of an object whose value is given here will fail with an error
# status of notWritable.
-syslocation Right here, right now.
-syscontact Me <me@somewhere.org>
+syslocation Unknown (configure /etc/snmp/snmpd.local.conf)
+syscontact Root <root@localhost> (configure /etc/snmp/snmpd.local.conf)
# Example output of snmpwalk:
# % snmpwalk -v 1 -c public localhost system
@@ -135,13 +141,13 @@ syscontact Me <me@somewhere.org>
#
# Make sure mountd is running
-proc mountd
+#proc mountd
# Make sure there are no more than 4 ntalkds running, but 0 is ok too.
-proc ntalkd 4
+#proc ntalkd 4
# Make sure at least one sendmail, but less than or equal to 10 are running.
-proc sendmail 10 1
+#proc sendmail 10 1
# A snmpwalk of the prTable would look something like this:
#
@@ -199,7 +205,7 @@ proc sendmail 10 1
# ARGS: optional arguments to be passed to the program
# a simple hello world
-exec echotest /bin/echo hello world
+#exec echotest /bin/echo hello world
# Run a shell script containing:
#
@@ -250,7 +256,7 @@ exec echotest /bin/echo hello world
# Check the / partition and make sure it contains at least 10 megs.
-disk / 10000
+#disk / 10000
# % snmpwalk -v 1 -c public localhost .EXTENSIBLEDOTMIB.DISKMIBNUM
# enterprises.ucdavis.diskTable.dskEntry.diskIndex.1 = 0
@@ -279,7 +285,7 @@ disk / 10000
# 15MAX: Similar, but for 15 min average.
# Check for loads:
-load 12 14 14
+#load 12 14 14
# % snmpwalk -v 1 -c public localhost .EXTENSIBLEDOTMIB.LOADAVEMIBNUM
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.1 = 1
@@ -365,7 +371,7 @@ load 12 14 14
# (commented out here since it requires that you place the
# script in the right location. (its not installed by default))
-# pass .EXTENSIBLEDOTMIB.255 /bin/sh PREFIX/local/passtest
+# pass .EXTENSIBLEDOTMIB.255 /bin/sh /usr/local/passtest
# % snmpwalk -v 1 -c public localhost .EXTENSIBLEDOTMIB.255
# enterprises.ucdavis.255.1 = "life the universe and everything"
--- /dev/null
+++ b/EXAMPLE-trap.conf
@@ -0,0 +1,18 @@
+###############################################################################
+#
+# EXAMPLE-trap.conf:
+# An example configuration file for configuring the Net-SNMP snmptrapd agent.
+#
+###############################################################################
+#
+# This file is intended to only be an example. If, however, you want
+# to use it, it should be placed in /etc/snmp/snmptrapd.conf.
+# When the snmptrapd agent starts up, this is where it will look for it.
+#
+# All lines beginning with a '#' are comments and are intended for you
+# to read. All other lines are configuration commands for the agent.
+
+#
+# PLEASE: read the snmptrapd.conf(5) manual page as well!
+#
+

View file

@ -1,7 +1,6 @@
diff -urN net-snmp-5.4.2.1/configure net-snmp-5.4.2.1.new/configure
--- net-snmp-5.4.2.1/configure 2008-10-31 16:53:45.000000000 +0100
+++ net-snmp-5.4.2.1.new/configure 2009-08-02 00:46:05.000000000 +0200
@@ -10218,7 +10218,7 @@
--- a/configure
+++ b/configure
@@ -10216,7 +10216,7 @@ linux* | k*bsd*-gnu)
need_version=no
library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
soname_spec='${libname}${release}${shared_ext}$major'

View file

@ -2,7 +2,7 @@
+++ b/Makefile.top
@@ -81,7 +81,7 @@ LIBCURRENT = 16
LIBAGE = 1
LIBREVISION = 2
LIBREVISION = 3
-LIB_LD_CMD = $(LIBTOOL) --mode=link $(LINKCC) $(CFLAGS) -rpath $(libdir) -version-info $(LIBCURRENT):$(LIBREVISION):$(LIBAGE) -o
+LIB_LD_CMD = $(LIBTOOL) --mode=link $(LINKCC) $(CFLAGS) -rpath $(libdir) $(LDFLAGS) -version-info $(LIBCURRENT):$(LIBREVISION):$(LIBAGE) -o

View file

@ -0,0 +1,29 @@
--- a/agent/mibgroup/host/hr_filesys.c
+++ b/agent/mibgroup/host/hr_filesys.c
@@ -322,13 +322,13 @@ var_hrfilesys(struct variable *vp,
long_return = fsys_idx;
return (u_char *) & long_return;
case HRFSYS_MOUNT:
- snprintf(string, sizeof(string), HRFS_entry->HRFS_mount);
+ snprintf(string, sizeof(string), "%s", HRFS_entry->HRFS_mount);
string[ sizeof(string)-1 ] = 0;
*var_len = strlen(string);
return (u_char *) string;
case HRFSYS_RMOUNT:
if (Check_HR_FileSys_NFS()) {
- snprintf(string, sizeof(string), HRFS_entry->HRFS_name);
+ snprintf(string, sizeof(string), "%s", HRFS_entry->HRFS_name);
string[ sizeof(string)-1 ] = 0;
} else
string[0] = '\0';
--- a/agent/mibgroup/ucd-snmp/extensible.c
+++ b/agent/mibgroup/ucd-snmp/extensible.c
@@ -513,7 +513,7 @@ fixExecError(int action,
}
tmp = *((long *) var_val);
if ((tmp == 1) && (action == COMMIT) && (exten->fixcmd[0] != 0)) {
- sprintf(ex.command, exten->fixcmd);
+ sprintf(ex.command, "%s", exten->fixcmd);
if ((fd = get_exec_output(&ex)) != -1) {
file = fdopen(fd, "r");
while (fgets(ex.output, sizeof(ex.output), file) != NULL);