chantra / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
5523e9
--- rpm-4.11.3/configure.ac.old	2018-05-25 09:02:29.103209393 +0200
5523e9
+++ rpm-4.11.3/configure.ac	2018-05-28 14:46:27.134913783 +0200
5523e9
@@ -334,6 +334,22 @@
5523e9
 AC_SUBST(WITH_POPT_INCLUDE)
5523e9
 AC_SUBST(WITH_POPT_LIB)
5523e9
 
5523e9
+
5523e9
+#=================
5523e9
+# Check for audit library.
5523e9
+AC_ARG_WITH(audit,
5523e9
+AS_HELP_STRING([--with-audit],[log results using Linux Audit]),
5523e9
+with_audit=$withval,
5523e9
+with_audit=auto)
5523e9
+
5523e9
+WITH_AUDIT_LIB=
5523e9
+AS_IF([test "$with_audit" = auto],[
5523e9
+    AC_SEARCH_LIBS([audit_open],[audit],[WITH_AUDIT_LIB="$ac_res"],
5523e9
+       [AC_MSG_ERROR([missing audit library])
5523e9
+    ])
5523e9
+])
5523e9
+AC_SUBST(WITH_AUDIT_LIB)
5523e9
+
5523e9
 #=================
5523e9
 # Process --with/without-external-db
5523e9
 AC_ARG_WITH(external_db, [AS_HELP_STRING([--with-external-db],[build against an external Berkeley db])],
5523e9
--- rpm-4.11.3/lib/Makefile.am.old	2014-09-05 13:51:05.000000000 +0200
5523e9
+++ rpm-4.11.3/lib/Makefile.am	2018-05-28 13:24:17.309657132 +0200
5523e9
@@ -47,6 +47,7 @@
5523e9
 	@WITH_SELINUX_LIB@ \
5523e9
 	@WITH_CAP_LIB@ \
5523e9
 	@WITH_ACL_LIB@ \
5523e9
+	@WITH_AUDIT_LIB@ \
5523e9
 	@LIBINTL@
5523e9
 
5523e9
 if WITH_LUA
5523e9
--- rpm-4.11.3/lib/rpmte.c.old	2018-05-25 09:02:29.173209513 +0200
5523e9
+++ rpm-4.11.3/lib/rpmte.c	2018-06-18 10:38:02.929670757 +0200
5523e9
@@ -3,6 +3,7 @@
5523e9
  * Routine(s) to handle an "rpmte"  transaction element.
5523e9
  */
5523e9
 #include "system.h"
5523e9
+#include <libaudit.h>
5523e9
 
5523e9
 #include <rpm/rpmtypes.h>
5523e9
 #include <rpm/rpmlib.h>		/* RPM_MACHTABLE_* */
5523e9
@@ -22,6 +23,16 @@
5523e9
 
5523e9
 #include "debug.h"
5523e9
 
5523e9
+#ifndef AUDIT_SOFTWARE_UPDATE
5523e9
+#define AUDIT_SOFTWARE_UPDATE   1138
5523e9
+#endif
5523e9
+
5523e9
+RPM_GNUC_INTERNAL
5523e9
+int auditEnabled = 0;
5523e9
+
5523e9
+RPM_GNUC_INTERNAL
5523e9
+int auditGpgResult = 0;
5523e9
+
5523e9
 /** \ingroup rpmte
5523e9
  * A single package instance to be installed/removed atomically.
5523e9
  */
5523e9
@@ -698,7 +709,15 @@
5523e9
 
5523e9
     switch (rpmteType(te)) {
5523e9
     case TR_ADDED:
5523e9
-	h = rpmteDBInstance(te) ? rpmteDBHeader(te) : rpmteFDHeader(te);
5523e9
+	if (rpmteDBInstance(te)) {
5523e9
+	    h = rpmteDBHeader(te);
5523e9
+	} else {
5523e9
+	    if (reload_fi) {
5523e9
+		auditEnabled = 1;
5523e9
+		auditGpgResult = 0;
5523e9
+	    }
5523e9
+	    h = rpmteFDHeader(te);
5523e9
+	}
5523e9
 	break;
5523e9
     case TR_REMOVED:
5523e9
 	h = rpmteDBHeader(te);
5523e9
@@ -904,6 +923,41 @@
5523e9
     return rc;
5523e9
 }
5523e9
 
5523e9
+/*
5523e9
+ * Input variables:
5523e9
+ *      te - transaction element
5523e9
+ *      keyEnforcement - gpg key enforcement status: 1 enforced, 0 not enforced
5523e9
+ *      gpgResult - results of gpg signature check: 1 verified, 0 otherwise
5523e9
+ *      result - overall result of installing the rpm: 1 success, 0 failure
5523e9
+ */
5523e9
+static void audit_rpm_install(rpmte te, unsigned int keyEnforcement,
5523e9
+                unsigned int gpgResult, int result)
5523e9
+{
5523e9
+    int auditFd;
5523e9
+    char eventTxt[128], *packageField, *dirField;
5523e9
+    const char *dir;
5523e9
+
5523e9
+    auditFd = audit_open();
5523e9
+    if (auditFd < 0)
5523e9
+	return;
5523e9
+
5523e9
+    packageField = audit_encode_nv_string("sw", te->NEVRA, strlen(te->NEVRA));
5523e9
+    dir = rpmtsRootDir(te->ts);
5523e9
+    dirField = audit_encode_nv_string("root_dir", dir, strlen(dir));
5523e9
+
5523e9
+    snprintf(eventTxt, sizeof(eventTxt),
5523e9
+	"%s sw_type=rpm key_enforce=%u gpg_res=%u %s",
5523e9
+	packageField, keyEnforcement, gpgResult, dirField);
5523e9
+    audit_log_user_comm_message(auditFd, AUDIT_SOFTWARE_UPDATE, eventTxt,
5523e9
+	NULL, NULL, NULL, NULL, result);
5523e9
+
5523e9
+    free(packageField);
5523e9
+    free(dirField);
5523e9
+    audit_close(auditFd);
5523e9
+
5523e9
+    return;
5523e9
+}
5523e9
+
5523e9
 static rpmRC rpmteRunAllCollections(rpmte te, rpmPluginHook hook)
5523e9
 {
5523e9
     ARGV_const_t colls;
5523e9
@@ -977,5 +1031,10 @@
5523e9
 	failed = rpmteMarkFailed(te);
5523e9
     }
5523e9
 
5523e9
+    if (auditEnabled) {
5523e9
+	audit_rpm_install(te, 0, auditGpgResult, failed ? 0 : 1);
5523e9
+	auditEnabled = 0;
5523e9
+    }
5523e9
+
5523e9
     return failed;
5523e9
 }
5523e9
--- rpm-4.11.3/lib/package.c.old	2018-05-25 09:02:29.132209443 +0200
5523e9
+++ rpm-4.11.3/lib/package.c	2018-06-15 12:11:58.996022237 +0200
5523e9
@@ -25,6 +25,9 @@
5523e9
 static unsigned int nextkeyid  = 0;
5523e9
 static unsigned int * keyids;
5523e9
 
5523e9
+extern int auditGpgResult;
5523e9
+extern int auditEnabled;
5523e9
+
5523e9
 /** \ingroup header
5523e9
  * Translate and merge legacy signature tags into header.
5523e9
  * @param h		header (dest)
5523e9
@@ -646,7 +649,10 @@
5523e9
 
5523e9
     /** @todo Implement disable/enable/warn/error/anal policy. */
5523e9
     rc = rpmVerifySignature(keyring, &sigtd, sig, ctx, &msg;;
5523e9
-	
5523e9
+
5523e9
+    if (auditEnabled && (sig != NULL))
5523e9
+	auditGpgResult = (rc == 0);
5523e9
+
5523e9
     switch (rc) {
5523e9
     case RPMRC_OK:		/* Signature is OK. */
5523e9
 	rpmlog(RPMLOG_DEBUG, "%s: %s", fn, msg);