aboutsummaryrefslogtreecommitdiff
path: root/modules/pam_unix/audit.c
diff options
context:
space:
mode:
authorSam Hartman <hartmans@debian.org>2024-12-02 09:55:34 -0700
committerSam Hartman <hartmans@debian.org>2024-12-02 09:55:34 -0700
commit4f3cfaf827bfa42a239c255092a128a3a02198bf (patch)
treeeac7f023f043739b79b2a51bd68c3006acb12964 /modules/pam_unix/audit.c
parent6408d4b1baff9a7e58fd66e1d1c0871be0823777 (diff)
parent7c9fb6472dcfae34ddbf4fbc9ecfafae2cf173c3 (diff)
downloadpam-4f3cfaf827bfa42a239c255092a128a3a02198bf.tar.gz
pam-4f3cfaf827bfa42a239c255092a128a3a02198bf.tar.bz2
pam-4f3cfaf827bfa42a239c255092a128a3a02198bf.zip
Update upstream source from tag 'upstream/1.7.0'
Update to upstream version '1.7.0' with Debian dir 0b3cd490884352e14273caeca2f05c6a525499fa
Diffstat (limited to 'modules/pam_unix/audit.c')
-rw-r--r--modules/pam_unix/audit.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/modules/pam_unix/audit.c b/modules/pam_unix/audit.c
new file mode 100644
index 00000000..9513aaa9
--- /dev/null
+++ b/modules/pam_unix/audit.c
@@ -0,0 +1,44 @@
+#include "config.h"
+
+#ifdef HAVE_LIBAUDIT
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <libaudit.h>
+
+#include <security/_pam_types.h>
+
+#include "audit.h"
+#include "passverify.h"
+
+int audit_log(int type, const char *uname, int retval)
+{
+ int audit_fd, rc;
+
+ audit_fd = audit_open();
+ if (audit_fd < 0) {
+ /* You get these error codes only when the kernel doesn't have
+ * audit compiled in. */
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
+ errno == EAFNOSUPPORT)
+ return PAM_SUCCESS;
+
+ helper_log_err(LOG_CRIT, "audit_open() failed: %m");
+ return PAM_AUTH_ERR;
+ }
+
+
+
+ rc = audit_log_acct_message(audit_fd, type, NULL, "PAM:" HELPER_COMPILE,
+ uname, -1, NULL, NULL, NULL, retval == PAM_SUCCESS);
+ if (rc == -EPERM && geteuid() != 0) {
+ rc = 0;
+ }
+
+ audit_close(audit_fd);
+
+ return rc < 0 ? PAM_AUTH_ERR : PAM_SUCCESS;
+}
+
+#endif /* HAVE_LIBAUDIT */