net-snmp/net-snmp-5.6.1-rpm-modernize.patch

115 lines
4.2 KiB
Diff
Raw Normal View History

From Panu Matilainen: update the code to work with rpm-4.9
I'm waiting for better version from Panu to work with all versions of rpm >= 4.1
and then I'll post it upstream.
diff -up net-snmp-5.6.1/agent/mibgroup/host/data_access/swinst_rpm.c.rpm-sanity net-snmp-5.6.1/agent/mibgroup/host/data_access/swinst_rpm.c
--- net-snmp-5.6.1/agent/mibgroup/host/data_access/swinst_rpm.c.rpm-sanity 2010-11-05 12:00:21.000000000 +0200
+++ net-snmp-5.6.1/agent/mibgroup/host/data_access/swinst_rpm.c 2011-01-18 09:55:44.000000000 +0200
@@ -34,6 +34,7 @@
#endif
#ifdef HAVE_RPM_RPMDB_H
#include <rpm/rpmdb.h>
+#include <rpm/rpmts.h>
#endif
#include <net-snmp/net-snmp-includes.h>
@@ -64,14 +65,8 @@ netsnmp_swinst_arch_init(void)
rpmdbpath = rpmGetPath( "%{_dbpath}", NULL );
dbpath = rpmdbpath;
#else
-#ifdef RPMVAR_DBPATH
- rpmReadConfigFiles( NULL, NULL, NULL, 0 );
- rpmdbpath = rpmGetVar( RPMVAR_DBPATH );
- dbpath = rpmdbpath;
-#else
dbpath = "/var/lib/rpm"; /* Most likely */
#endif
-#endif
snprintf( pkg_directory, SNMP_MAXPATH, "%s/Packages", dbpath );
if (-1 == stat( pkg_directory, &stat_buf ))
@@ -96,32 +91,25 @@ netsnmp_swinst_arch_shutdown(void)
int
netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags)
{
- rpmdb db;
+ rpmts ts;
-#if defined(RPMDBI_PACKAGES)
rpmdbMatchIterator mi;
-#else
- int offset;
-#endif
Header h;
- char *n, *v, *r, *g;
- int32_t *t;
+ char *nvr;
+ const char *g;
time_t install_time;
size_t date_len;
int rc, i = 1;
netsnmp_swinst_entry *entry;
- if (rpmdbOpen("", &db, O_RDONLY, 0644))
- NETSNMP_LOGONCE((LOG_ERR, "rpmdbOpen() failed\n"));
+ ts = rpmtsCreate();
+ rpmtsSetVSFlags( ts, (_RPMVSF_NOSIGNATURES|_RPMVSF_NODIGESTS));
+
+ mi = rpmtsInitIterator( ts, RPMDBI_PACKAGES, NULL, 0);
+ if (mi == NULL)
+ NETSNMP_LOGONCE((LOG_ERR, "rpmdbOpen() failed\n"));
-#if defined(RPMDBI_PACKAGES)
- mi = rpmdbInitIterator( db, RPMDBI_PACKAGES, NULL, 0);
while (NULL != (h = rpmdbNextIterator( mi )))
-#else
- for (offset = rpmdbFirstRecNum( db );
- offset != 0;
- offset = rpmdbNextRecNum( db, offset ))
-#endif
{
entry = netsnmp_swinst_entry_create( i++ );
@@ -129,35 +117,27 @@ netsnmp_swinst_arch_load( netsnmp_contai
continue; /* error already logged by function */
rc = CONTAINER_INSERT(container, entry);
-#if defined(RPMDBI_PACKAGES)
h = headerLink( h );
-#else
- h = rpmdbGetRecord( db, offset );
-#endif
- headerGetEntry( h, RPMTAG_NAME, NULL, (void**)&n, NULL);
- headerGetEntry( h, RPMTAG_VERSION, NULL, (void**)&v, NULL);
- headerGetEntry( h, RPMTAG_RELEASE, NULL, (void**)&r, NULL);
- headerGetEntry( h, RPMTAG_GROUP, NULL, (void**)&g, NULL);
- headerGetEntry( h, RPMTAG_INSTALLTIME, NULL, (void**)&t, NULL);
+ nvr = headerGetAsString( h, RPMTAG_NVR);
+ g = headerGetString( h, RPMTAG_GROUP);
+ install_time = headerGetNumber( h, RPMTAG_INSTALLTIME);
entry->swName_len = snprintf( entry->swName, sizeof(entry->swName),
- "%s-%s-%s", n, v, r);
+ "%s", nvr);
if (entry->swName_len > sizeof(entry->swName))
entry->swName_len = sizeof(entry->swName);
entry->swType = (NULL != strstr( g, "System Environment"))
? 2 /* operatingSystem */
: 4; /* application */
- install_time = *t;
entry->swDate_len = snprintf( entry->swDate, sizeof(entry->swDate),
"%s", date_n_time( &install_time, &date_len ));
headerFree( h );
+ free(nvr);
}
-#if defined(RPMDBI_PACKAGES)
rpmdbFreeIterator( mi );
-#endif
- rpmdbClose( db );
+ rpmtsFree( ts );
DEBUGMSGTL(("swinst:load:arch", "loaded %d entries\n",
(int)CONTAINER_SIZE(container)));