Source: net-snmp
Source-Version: 5.7.3+dfsg-3
Severity: normal
Tags: upstream patch
User: debian-d...@lists.debian.org
Usertags: dpkg-db-access-inert

Hi!

This package contains a MIB implementation for dpkg, with a reference
to the dpkg internal database [M], which it does not use anyway as it
is properly using the «dpkg-query» interface. In addition, the module
seems to be misnamed as swinst_apt instead of swinst_dpkg.

  [M] agent/mibgroup/host/data_access/swinst_apt.c

This a problem for multiple reasons. Even though the layout and format
of the dpkg database is administrator friendly, and it's expected that
those might need to mess with it, in case of emergency, this interface
does not extend to other programs besides the dpkg suite of tools. The
admindir can also be configured differently at dpkg build or run-time.
And finally, the contents and its format, will be changing in the near
future.


Attached an untested patch that should in theory fix this issue.

Thanks,
Guillem
From d87968daef4490f4a54c4b13ad1547fc6b7215c8 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guil...@debian.org>
Date: Wed, 8 Aug 2018 00:23:33 +0200
Subject: [PATCH] swinst: Fix dpkg module

Remove inert code referencing the internal dpkg database. Rename module
and variables from apt to dpkg to match the implementation.
---
 agent/mibgroup/host/data_access/swinst.h               |  2 +-
 .../host/data_access/{swinst_apt.c => swinst_dpkg.c}   | 10 ++++------
 configure                                              |  2 +-
 configure.d/config_os_progs                            |  2 +-
 4 files changed, 7 insertions(+), 9 deletions(-)
 rename agent/mibgroup/host/data_access/{swinst_apt.c => swinst_dpkg.c} (87%)

diff --git a/agent/mibgroup/host/data_access/swinst.h b/agent/mibgroup/host/data_access/swinst.h
index bda3e47..21bae44 100644
--- a/agent/mibgroup/host/data_access/swinst.h
+++ b/agent/mibgroup/host/data_access/swinst.h
@@ -22,7 +22,7 @@ config_exclude(host/hr_swinst)
 #if   defined( darwin )
     config_require(host/data_access/swinst_darwin)
 #elif defined( HAVE_DPKG_QUERY )
-    config_require(host/data_access/swinst_apt)
+    config_require(host/data_access/swinst_dpkg)
 #elif defined( HAVE_LIBRPM ) && defined( linux )
     config_require(host/data_access/swinst_rpm)
 #elif defined( HAVE_PKGLOCS_H ) || defined( hpux9 ) || defined( hpux10 ) || defined( hpux11 ) || defined( freebsd2 ) || defined( linux ) || defined( openbsd )
diff --git a/agent/mibgroup/host/data_access/swinst_apt.c b/agent/mibgroup/host/data_access/swinst_dpkg.c
similarity index 87%
rename from agent/mibgroup/host/data_access/swinst_apt.c
rename to agent/mibgroup/host/data_access/swinst_dpkg.c
index c7606d2..867b521 100644
--- a/agent/mibgroup/host/data_access/swinst_apt.c
+++ b/agent/mibgroup/host/data_access/swinst_dpkg.c
@@ -29,16 +29,14 @@
 #include <net-snmp/library/snmp_debug.h>
 #include <net-snmp/data_access/swinst.h>
 
-char pkg_directory[SNMP_MAXBUF];
-static char apt_fmt[SNMP_MAXBUF];
+static char dpkg_fmt[SNMP_MAXBUF];
 
 /* ---------------------------------------------------------------------
  */
 void
 netsnmp_swinst_arch_init(void)
 {
-    strlcpy(pkg_directory, "/var/lib/dpkg/info", sizeof(pkg_directory));
-    snprintf(apt_fmt, SNMP_MAXBUF, "%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%ds",
+    snprintf(dpkg_fmt, SNMP_MAXBUF, "%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%ds",
 	SNMP_MAXBUF-1, SNMP_MAXBUF-1, SNMP_MAXBUF-1,
 	SNMP_MAXBUF-1, SNMP_MAXBUF-1, SNMP_MAXBUF-1);
 }
@@ -72,13 +70,13 @@ netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags)
     }
 
     while (fgets(buf, BUFSIZ, p)) {
-	DEBUGMSG(("swinst_apt", "entry: %s\n", buf));
+	DEBUGMSG(("swinst_dpkg", "entry: %s\n", buf));
         entry = netsnmp_swinst_entry_create( i++ );
         if (NULL == entry)
             continue;   /* error already logged by function */
         CONTAINER_INSERT(container, entry);
 
-	sscanf(buf, apt_fmt, package, version, section, priority, essential, status);
+	sscanf(buf, dpkg_fmt, package, version, section, priority, essential, status);
 	if (strstr(status, "not-installed"))
 	    continue;
 
diff --git a/configure b/configure
index 433ba5b..6ae420a 100755
--- a/configure
+++ b/configure
@@ -15678,7 +15678,7 @@ $as_echo "no" >&6; }
 esac
 
 
-#       dpkg package (swintst_apt)
+#       dpkg package (swintst_dpkg)
 #	    used in agent only
 #
 # Extract the first word of "dpkg-query", so it can be a program name with args.
diff --git a/configure.d/config_os_progs b/configure.d/config_os_progs
index 160134c..6769896 100644
--- a/configure.d/config_os_progs
+++ b/configure.d/config_os_progs
@@ -418,7 +418,7 @@ case $target_os in
 esac
 
 
-#       dpkg package (swintst_apt)
+#       dpkg package (swintst_dpkg)
 #	    used in agent only
 #
 AC_PATH_PROG([DPKG_QUERY_PATH], dpkg-query)
-- 
2.18.0

Reply via email to