wuyuoss / rpms / rpm

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