2007-03-15 01:56:27 +01:00
|
|
|
# add support for Linux audit (FATE #120269)
|
2007-08-28 19:18:04 +02:00
|
|
|
================================================================================
|
2011-02-04 14:58:22 +01:00
|
|
|
Index: openssh-5.8p1/Makefile.in
|
2010-03-26 16:29:14 +01:00
|
|
|
===================================================================
|
2011-02-04 14:58:22 +01:00
|
|
|
--- openssh-5.8p1.orig/Makefile.in
|
|
|
|
+++ openssh-5.8p1/Makefile.in
|
|
|
|
@@ -47,6 +47,7 @@ CFLAGS=@CFLAGS@
|
2007-03-15 01:56:27 +01:00
|
|
|
CPPFLAGS=-I. -I$(srcdir) @CPPFLAGS@ $(PATHS) @DEFS@
|
|
|
|
LIBS=@LIBS@
|
2011-02-04 14:58:22 +01:00
|
|
|
SSHLIBS=@SSHLIBS@
|
2007-03-15 01:56:27 +01:00
|
|
|
+LIBAUDIT=@LIBAUDIT@
|
|
|
|
SSHDLIBS=@SSHDLIBS@
|
|
|
|
LIBEDIT=@LIBEDIT@
|
2007-12-06 16:29:46 +01:00
|
|
|
AR=@AR@
|
2011-02-04 14:58:22 +01:00
|
|
|
@@ -146,7 +147,7 @@ ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SS
|
|
|
|
$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHLIBS) $(LIBS)
|
2007-03-15 01:56:27 +01:00
|
|
|
|
|
|
|
sshd$(EXEEXT): libssh.a $(LIBCOMPAT) $(SSHDOBJS)
|
2007-12-06 16:29:46 +01:00
|
|
|
- $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS)
|
|
|
|
+ $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS) $(LIBAUDIT)
|
2007-03-15 01:56:27 +01:00
|
|
|
|
|
|
|
scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o
|
|
|
|
$(LD) -o $@ scp.o progressmeter.o bufaux.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
|
2011-02-04 14:58:22 +01:00
|
|
|
Index: openssh-5.8p1/auth.c
|
2010-03-26 16:29:14 +01:00
|
|
|
===================================================================
|
2011-02-04 14:58:22 +01:00
|
|
|
--- openssh-5.8p1.orig/auth.c
|
|
|
|
+++ openssh-5.8p1/auth.c
|
2010-03-26 16:29:14 +01:00
|
|
|
@@ -293,6 +293,12 @@ auth_log(Authctxt *authctxt, int authent
|
2007-03-15 01:56:27 +01:00
|
|
|
get_canonical_hostname(options.use_dns), "ssh", &loginmsg);
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
+#if HAVE_LINUX_AUDIT
|
|
|
|
+ if (authenticated == 0 && !authctxt->postponed) {
|
|
|
|
+ linux_audit_record_event(-1, authctxt->user, NULL,
|
|
|
|
+ get_remote_ipaddr(), "sshd", 0);
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
#ifdef SSH_AUDIT_EVENTS
|
|
|
|
if (authenticated == 0 && !authctxt->postponed)
|
|
|
|
audit_event(audit_classify_auth(method));
|
2011-01-31 13:24:57 +01:00
|
|
|
@@ -592,6 +598,10 @@ getpwnamallow(const char *user)
|
2007-03-15 01:56:27 +01:00
|
|
|
record_failed_login(user,
|
|
|
|
get_canonical_hostname(options.use_dns), "ssh");
|
|
|
|
#endif
|
|
|
|
+#ifdef HAVE_LINUX_AUDIT
|
|
|
|
+ linux_audit_record_event(-1, user, NULL, get_remote_ipaddr(),
|
|
|
|
+ "sshd", 0);
|
|
|
|
+#endif
|
|
|
|
#ifdef SSH_AUDIT_EVENTS
|
|
|
|
audit_event(SSH_INVALID_USER);
|
|
|
|
#endif /* SSH_AUDIT_EVENTS */
|
2011-02-04 14:58:22 +01:00
|
|
|
Index: openssh-5.8p1/config.h.in
|
2010-03-26 16:29:14 +01:00
|
|
|
===================================================================
|
2011-02-04 14:58:22 +01:00
|
|
|
--- openssh-5.8p1.orig/config.h.in
|
|
|
|
+++ openssh-5.8p1/config.h.in
|
2011-01-31 13:24:57 +01:00
|
|
|
@@ -1460,6 +1460,9 @@
|
2007-03-15 01:56:27 +01:00
|
|
|
/* Define if you want SELinux support. */
|
|
|
|
#undef WITH_SELINUX
|
|
|
|
|
|
|
|
+/* Define if you want Linux audit support. */
|
|
|
|
+#undef HAVE_LINUX_AUDIT
|
|
|
|
+
|
2011-10-19 04:18:13 +02:00
|
|
|
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
|
|
|
significant byte first (like Motorola and SPARC, unlike Intel). */
|
|
|
|
#if defined AC_APPLE_UNIVERSAL_BUILD
|
2011-02-04 14:58:22 +01:00
|
|
|
Index: openssh-5.8p1/configure.ac
|
2010-03-26 16:29:14 +01:00
|
|
|
===================================================================
|
2011-02-04 14:58:22 +01:00
|
|
|
--- openssh-5.8p1.orig/configure.ac
|
|
|
|
+++ openssh-5.8p1/configure.ac
|
|
|
|
@@ -3522,6 +3522,20 @@ AC_ARG_WITH(selinux,
|
2011-10-19 04:18:13 +02:00
|
|
|
AC_SUBST([SSHLIBS])
|
|
|
|
AC_SUBST([SSHDLIBS])
|
2007-03-15 01:56:27 +01:00
|
|
|
|
|
|
|
+# Check whether user wants Linux audit support
|
|
|
|
+LINUX_AUDIT_MSG="no"
|
|
|
|
+LIBAUDIT=""
|
2011-10-19 04:18:13 +02:00
|
|
|
+AC_ARG_WITH([linux-audit],
|
2007-03-15 01:56:27 +01:00
|
|
|
+ [ --with-linux-audit Enable Linux audit support],
|
|
|
|
+ [ if test "x$withval" != "xno" ; then
|
2011-10-19 04:18:13 +02:00
|
|
|
+ AC_DEFINE([HAVE_LINUX_AUDIT],[1],[Define if you want Linux audit support.])
|
2007-03-15 01:56:27 +01:00
|
|
|
+ LINUX_AUDIT_MSG="yes"
|
2011-10-19 04:18:13 +02:00
|
|
|
+ AC_CHECK_HEADERS([libaudit.h])
|
2007-03-15 01:56:27 +01:00
|
|
|
+ LIBAUDIT="-laudit"
|
|
|
|
+ fi
|
|
|
|
+ ])
|
2011-10-19 04:18:13 +02:00
|
|
|
+AC_SUBST([LIBAUDIT])
|
2007-03-15 01:56:27 +01:00
|
|
|
+
|
|
|
|
# Check whether user wants Kerberos 5 support
|
|
|
|
KRB5_MSG="no"
|
2011-10-19 04:18:13 +02:00
|
|
|
AC_ARG_WITH([kerberos5],
|
2011-02-04 14:58:22 +01:00
|
|
|
@@ -4316,6 +4330,7 @@ echo " PAM support
|
2007-03-15 01:56:27 +01:00
|
|
|
echo " OSF SIA support: $SIA_MSG"
|
|
|
|
echo " KerberosV support: $KRB5_MSG"
|
|
|
|
echo " SELinux support: $SELINUX_MSG"
|
|
|
|
+echo " Linux audit support: $LINUX_AUDIT_MSG"
|
|
|
|
echo " Smartcard support: $SCARD_MSG"
|
|
|
|
echo " S/KEY support: $SKEY_MSG"
|
|
|
|
echo " TCP Wrappers support: $TCPW_MSG"
|
2011-02-04 14:58:22 +01:00
|
|
|
Index: openssh-5.8p1/loginrec.c
|
2010-03-26 16:29:14 +01:00
|
|
|
===================================================================
|
2011-02-04 14:58:22 +01:00
|
|
|
--- openssh-5.8p1.orig/loginrec.c
|
|
|
|
+++ openssh-5.8p1/loginrec.c
|
2007-12-06 16:29:46 +01:00
|
|
|
@@ -176,6 +176,10 @@
|
2007-03-01 22:07:15 +01:00
|
|
|
#include "auth.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
|
|
|
|
+#ifdef HAVE_LINUX_AUDIT
|
|
|
|
+# include <libaudit.h>
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
#ifdef HAVE_UTIL_H
|
|
|
|
# include <util.h>
|
|
|
|
#endif
|
2010-02-25 14:23:54 +01:00
|
|
|
@@ -202,6 +206,9 @@ int utmp_write_entry(struct logininfo *l
|
2007-03-01 22:07:15 +01:00
|
|
|
int utmpx_write_entry(struct logininfo *li);
|
|
|
|
int wtmp_write_entry(struct logininfo *li);
|
|
|
|
int wtmpx_write_entry(struct logininfo *li);
|
|
|
|
+#ifdef HAVE_LINUX_AUDIT
|
|
|
|
+int linux_audit_write_entry(struct logininfo *li);
|
|
|
|
+#endif
|
|
|
|
int lastlog_write_entry(struct logininfo *li);
|
|
|
|
int syslogin_write_entry(struct logininfo *li);
|
|
|
|
|
2011-01-31 13:24:57 +01:00
|
|
|
@@ -442,6 +449,10 @@ login_write(struct logininfo *li)
|
2007-03-01 22:07:15 +01:00
|
|
|
|
|
|
|
/* set the timestamp */
|
|
|
|
login_set_current_time(li);
|
|
|
|
+#ifdef HAVE_LINUX_AUDIT
|
|
|
|
+ if (linux_audit_write_entry(li) == 0)
|
|
|
|
+ fatal("linux_audit_write_entry failed: %s", strerror(errno));
|
|
|
|
+#endif
|
|
|
|
#ifdef USE_LOGIN
|
|
|
|
syslogin_write_entry(li);
|
|
|
|
#endif
|
2011-01-31 13:24:57 +01:00
|
|
|
@@ -1406,6 +1417,87 @@ wtmpx_get_entry(struct logininfo *li)
|
2007-03-01 22:07:15 +01:00
|
|
|
}
|
|
|
|
#endif /* USE_WTMPX */
|
|
|
|
|
|
|
|
+#ifdef HAVE_LINUX_AUDIT
|
2010-02-25 14:23:54 +01:00
|
|
|
+static void
|
|
|
|
+_audit_hexscape(const char *what, char *where, unsigned int size)
|
|
|
|
+{
|
|
|
|
+ const char *ptr = what;
|
|
|
|
+ const char *hex = "0123456789ABCDEF";
|
|
|
|
+
|
|
|
|
+ while (*ptr) {
|
|
|
|
+ if (*ptr == '"' || *ptr < 0x21 || *ptr > 0x7E) {
|
|
|
|
+ unsigned int i;
|
|
|
|
+ ptr = what;
|
|
|
|
+ for (i = 0; *ptr && i+2 < size; i += 2) {
|
|
|
|
+ where[i] = hex[((unsigned)*ptr & 0xF0)>>4]; /* Upper nibble */
|
|
|
|
+ where[i+1] = hex[(unsigned)*ptr & 0x0F]; /* Lower nibble */
|
|
|
|
+ ptr++;
|
|
|
|
+ }
|
|
|
|
+ where[i] = '\0';
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ ptr++;
|
|
|
|
+ }
|
|
|
|
+ where[0] = '"';
|
|
|
|
+ if ((unsigned)(ptr - what) < size - 3)
|
|
|
|
+ {
|
|
|
|
+ size = ptr - what + 3;
|
|
|
|
+ }
|
|
|
|
+ strncpy(where + 1, what, size - 3);
|
|
|
|
+ where[size-2] = '"';
|
|
|
|
+ where[size-1] = '\0';
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#define AUDIT_LOG_SIZE 128
|
|
|
|
+#define AUDIT_ACCT_SIZE (AUDIT_LOG_SIZE - 8)
|
|
|
|
+
|
2007-03-01 22:07:15 +01:00
|
|
|
+int
|
|
|
|
+linux_audit_record_event(int uid, const char *username,
|
|
|
|
+ const char *hostname, const char *ip, const char *ttyn, int success)
|
|
|
|
+{
|
2010-02-25 14:23:54 +01:00
|
|
|
+ char buf[AUDIT_LOG_SIZE];
|
2007-03-01 22:07:15 +01:00
|
|
|
+ int audit_fd, rc;
|
|
|
|
+
|
|
|
|
+ audit_fd = audit_open();
|
|
|
|
+ if (audit_fd < 0) {
|
|
|
|
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
|
|
+ errno == EAFNOSUPPORT)
|
|
|
|
+ return 1; /* No audit support in kernel */
|
|
|
|
+ else
|
|
|
|
+ return 0; /* Must prevent login */
|
|
|
|
+ }
|
|
|
|
+ if (username == NULL)
|
|
|
|
+ snprintf(buf, sizeof(buf), "uid=%d", uid);
|
2010-02-25 14:23:54 +01:00
|
|
|
+ else {
|
|
|
|
+ char encoded[AUDIT_ACCT_SIZE];
|
|
|
|
+ _audit_hexscape(username, encoded, sizeof(encoded));
|
|
|
|
+ snprintf(buf, sizeof(buf), "acct=%s", encoded);
|
|
|
|
+ }
|
2007-03-01 22:07:15 +01:00
|
|
|
+ rc = audit_log_user_message(audit_fd, AUDIT_USER_LOGIN,
|
|
|
|
+ buf, hostname, ip, ttyn, success);
|
|
|
|
+ close(audit_fd);
|
|
|
|
+ if (rc >= 0)
|
|
|
|
+ return 1;
|
|
|
|
+ else
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int
|
|
|
|
+linux_audit_write_entry(struct logininfo *li)
|
|
|
|
+{
|
|
|
|
+ switch(li->type) {
|
|
|
|
+ case LTYPE_LOGIN:
|
|
|
|
+ return (linux_audit_record_event(li->uid, NULL, li->hostname,
|
|
|
|
+ NULL, li->line, 1));
|
|
|
|
+ case LTYPE_LOGOUT:
|
|
|
|
+ return (1); /* We only care about logins */
|
|
|
|
+ default:
|
|
|
|
+ logit("%s: invalid type field", __func__);
|
|
|
|
+ return (0);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+#endif /* HAVE_LINUX_AUDIT */
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
** Low-level libutil login() functions
|
|
|
|
**/
|
2011-02-04 14:58:22 +01:00
|
|
|
Index: openssh-5.8p1/loginrec.h
|
2010-03-26 16:29:14 +01:00
|
|
|
===================================================================
|
2011-02-04 14:58:22 +01:00
|
|
|
--- openssh-5.8p1.orig/loginrec.h
|
|
|
|
+++ openssh-5.8p1/loginrec.h
|
2010-03-26 16:29:14 +01:00
|
|
|
@@ -127,5 +127,9 @@ char *line_stripname(char *dst, const ch
|
2007-03-01 22:07:15 +01:00
|
|
|
char *line_abbrevname(char *dst, const char *src, int dstsize);
|
|
|
|
|
|
|
|
void record_failed_login(const char *, const char *, const char *);
|
|
|
|
+#ifdef HAVE_LINUX_AUDIT
|
|
|
|
+int linux_audit_record_event(int uid, const char *username,
|
|
|
|
+ const char *hostname, const char *ip, const char *ttyn, int success);
|
|
|
|
+#endif /* HAVE_LINUX_AUDIT */
|
|
|
|
|
|
|
|
#endif /* _HAVE_LOGINREC_H_ */
|