vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jan F faae1e
diff -up openssh-5.6p1/audit-bsm.c.audit openssh-5.6p1/audit-bsm.c
Jan F faae1e
--- openssh-5.6p1/audit-bsm.c.audit	2008-02-25 11:05:04.000000000 +0100
Jan F faae1e
+++ openssh-5.6p1/audit-bsm.c	2010-09-25 16:07:42.000000000 +0200
Jan F faae1e
@@ -305,13 +305,13 @@ audit_run_command(const char *command)
Jan F faae1e
 }
Jan F faae1e
 
Jan F faae1e
 void
Jan F faae1e
-audit_session_open(const char *ttyn)
Jan F faae1e
+audit_session_open(struct logininfo *li)
Jan F faae1e
 {
Jan F faae1e
 	/* not implemented */
Jan F faae1e
 }
Jan F faae1e
 
Jan F faae1e
 void
Jan F faae1e
-audit_session_close(const char *ttyn)
Jan F faae1e
+audit_session_close(struct logininfo *li)
Jan F faae1e
 {
Jan F faae1e
 	/* not implemented */
Jan F faae1e
 }
Jan F faae1e
diff -up openssh-5.6p1/audit.c.audit openssh-5.6p1/audit.c
Jan F faae1e
--- openssh-5.6p1/audit.c.audit	2006-09-01 07:38:36.000000000 +0200
Jan F faae1e
+++ openssh-5.6p1/audit.c	2010-09-25 16:07:42.000000000 +0200
Jan F faae1e
@@ -147,9 +147,9 @@ audit_event(ssh_audit_event_t event)
Jan F faae1e
  * within a single connection.
Jan F faae1e
  */
Jan F faae1e
 void
Jan F faae1e
-audit_session_open(const char *ttyn)
Jan F faae1e
+audit_session_open(struct logininfo *li)
Jan F faae1e
 {
Jan F faae1e
-	const char *t = ttyn ? ttyn : "(no tty)";
Jan F faae1e
+	const char *t = li->line ? li->line : "(no tty)";
Jan F faae1e
 
Jan F faae1e
 	debug("audit session open euid %d user %s tty name %s", geteuid(),
Jan F faae1e
 	    audit_username(), t);
Jan F faae1e
@@ -163,9 +163,9 @@ audit_session_open(const char *ttyn)
Jan F faae1e
  * within a single connection.
Jan F faae1e
  */
Jan F faae1e
 void
Jan F faae1e
-audit_session_close(const char *ttyn)
Jan F faae1e
+audit_session_close(struct logininfo *li)
Jan F faae1e
 {
Jan F faae1e
-	const char *t = ttyn ? ttyn : "(no tty)";
Jan F faae1e
+	const char *t = li->line ? li->line : "(no tty)";
Jan F faae1e
 
Jan F faae1e
 	debug("audit session close euid %d user %s tty name %s", geteuid(),
Jan F faae1e
 	    audit_username(), t);
Jan F faae1e
diff -up openssh-5.6p1/audit.h.audit openssh-5.6p1/audit.h
Jan F faae1e
--- openssh-5.6p1/audit.h.audit	2006-08-05 16:05:10.000000000 +0200
Jan F faae1e
+++ openssh-5.6p1/audit.h	2010-09-25 16:07:42.000000000 +0200
Jan F faae1e
@@ -26,6 +26,9 @@
Jan F faae1e
 
Jan F faae1e
 #ifndef _SSH_AUDIT_H
Jan F faae1e
 # define _SSH_AUDIT_H
Jan F faae1e
+
Jan F faae1e
+#include "loginrec.h"
Jan F faae1e
+
Jan F faae1e
 enum ssh_audit_event_type {
Jan F faae1e
 	SSH_LOGIN_EXCEED_MAXTRIES,
Jan F faae1e
 	SSH_LOGIN_ROOT_DENIED,
Jan F faae1e
@@ -46,8 +49,8 @@ typedef enum ssh_audit_event_type ssh_au
Jan F faae1e
 
Jan F faae1e
 void	audit_connection_from(const char *, int);
Jan F faae1e
 void	audit_event(ssh_audit_event_t);
Jan F faae1e
-void	audit_session_open(const char *);
Jan F faae1e
-void	audit_session_close(const char *);
Jan F faae1e
+void	audit_session_open(struct logininfo *);
Jan F faae1e
+void	audit_session_close(struct logininfo *);
Jan F faae1e
 void	audit_run_command(const char *);
Jan F faae1e
 ssh_audit_event_t audit_classify_auth(const char *);
Jan F faae1e
 
Jan F faae1e
diff -up openssh-5.6p1/audit-linux.c.audit openssh-5.6p1/audit-linux.c
Jan F faae1e
--- openssh-5.6p1/audit-linux.c.audit	2010-09-25 16:07:42.000000000 +0200
Jan F faae1e
+++ openssh-5.6p1/audit-linux.c	2010-09-25 16:08:37.000000000 +0200
Jan F faae1e
@@ -0,0 +1,128 @@
Jan F faae1e
+/* $Id: audit-linux.c,v 1.1 jfch Exp $ */
Jan F faae1e
+
Jan F faae1e
+/*
Jan F faae1e
+ * Copyright 2010 Red Hat, Inc.  All rights reserved.
Jan F faae1e
+ * Use is subject to license terms.
Jan F faae1e
+ *
Jan F faae1e
+ * Redistribution and use in source and binary forms, with or without
Jan F faae1e
+ * modification, are permitted provided that the following conditions
Jan F faae1e
+ * are met:
Jan F faae1e
+ * 1. Redistributions of source code must retain the above copyright
Jan F faae1e
+ *    notice, this list of conditions and the following disclaimer.
Jan F faae1e
+ * 2. Redistributions in binary form must reproduce the above copyright
Jan F faae1e
+ *    notice, this list of conditions and the following disclaimer in the
Jan F faae1e
+ *    documentation and/or other materials provided with the distribution.
Jan F faae1e
+ *
Jan F faae1e
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Jan F faae1e
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Jan F faae1e
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Jan F faae1e
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
Jan F faae1e
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Jan F faae1e
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Jan F faae1e
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Jan F faae1e
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Jan F faae1e
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Jan F faae1e
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jan F faae1e
+ *
Jan F faae1e
+ * Red Hat author: Jan F. Chadima <jchadima@redhat.com>
Jan F faae1e
+ */
Jan F faae1e
+/* #pragma ident	"@(#)audit-linux.c	1.1	01/09/17 SMI" */
Jan F faae1e
+
Jan F faae1e
+#include "includes.h"
Jan F faae1e
+#if defined(USE_LINUX_AUDIT)
Jan F faae1e
+#include <libaudit.h>
Jan F faae1e
+#include <unistd.h>
Jan F faae1e
+#include <string.h>
Jan F faae1e
+
Jan F faae1e
+#include "log.h"
Jan F faae1e
+#include "audit.h"
Jan F faae1e
+
Jan F faae1e
+int
Jan F faae1e
+linux_audit_record_event(int uid, const char *username,
Jan F faae1e
+	const char *hostname, const char *ip, const char *ttyn, int success)
Jan F faae1e
+{
Jan F faae1e
+	int audit_fd, rc;
Jan F faae1e
+
Jan F faae1e
+	audit_fd = audit_open();
Jan F faae1e
+	if (audit_fd < 0) {
Jan F faae1e
+		if (errno == EINVAL || errno == EPROTONOSUPPORT ||
Jan F faae1e
+				errno == EAFNOSUPPORT)
Jan F faae1e
+			return 1; /* No audit support in kernel */
Jan F faae1e
+		else
Jan F faae1e
+                        return 0; /* Must prevent login */
Jan F faae1e
+	}
Jan F faae1e
+	rc = audit_log_acct_message(audit_fd, AUDIT_USER_LOGIN,
Jan F faae1e
+		NULL, "login", username ? username : "(unknown)",
Jan F faae1e
+		username == NULL ? uid : -1, hostname, ip, ttyn, success);
Jan F faae1e
+	close(audit_fd);
Jan F faae1e
+	if (rc >= 0)
Jan F faae1e
+		return 1;
Jan F faae1e
+	else
Jan F faae1e
+		return 0;
Jan F faae1e
+}
Jan F faae1e
+
Jan F faae1e
+/* Below is the sshd audit API code */
Jan F faae1e
+
Jan F faae1e
+void
Jan F faae1e
+audit_connection_from(const char *host, int port)
Jan F faae1e
+{
Jan F faae1e
+}
Jan F faae1e
+	/* not implemented */
Jan F faae1e
+
Jan F faae1e
+void
Jan F faae1e
+audit_run_command(const char *command)
Jan F faae1e
+{
Jan F faae1e
+	/* not implemented */
Jan F faae1e
+}
Jan F faae1e
+
Jan F faae1e
+void
Jan F faae1e
+audit_session_open(struct logininfo *li)
Jan F faae1e
+{
Jan F faae1e
+	debug("audit session open euid %d", geteuid());
Jan F faae1e
+	if (linux_audit_record_event(li->uid, NULL, li->hostname,
Jan F faae1e
+		NULL, li->line, 1) == 0)
Jan F faae1e
+	fatal("linux_audit_write_entry failed: %s", strerror(errno));
Jan F faae1e
+}
Jan F faae1e
+
Jan F faae1e
+void
Jan F faae1e
+audit_session_close(struct logininfo *li)
Jan F faae1e
+{
Jan F faae1e
+	/* not implemented */
Jan F faae1e
+}
Jan F faae1e
+
Jan F faae1e
+void
Jan F faae1e
+audit_event(ssh_audit_event_t event)
Jan F faae1e
+{
Jan F faae1e
+	switch(event) {
Jan F faae1e
+//	case SSH_AUTH_SUCCESS:
Jan F faae1e
+//		break;
Jan F faae1e
+//
Jan F faae1e
+//	case SSH_CONNECTION_CLOSE:
Jan F faae1e
+//		break;
Jan F faae1e
+//
Jan F faae1e
+//	case SSH_NOLOGIN:
Jan F faae1e
+//		break;
Jan F faae1e
+//
Jan F faae1e
+//	case SSH_LOGIN_EXCEED_MAXTRIES:
Jan F faae1e
+//		break;
Jan F faae1e
+//
Jan F faae1e
+//	case SSH_LOGIN_ROOT_DENIED:
Jan F faae1e
+//		break;
Jan F faae1e
+
Jan F faae1e
+	case SSH_AUTH_FAIL_NONE:
Jan F faae1e
+	case SSH_AUTH_FAIL_PASSWD:
Jan F faae1e
+	case SSH_AUTH_FAIL_KBDINT:
Jan F faae1e
+	case SSH_AUTH_FAIL_PUBKEY:
Jan F faae1e
+	case SSH_AUTH_FAIL_HOSTBASED:
Jan F faae1e
+	case SSH_AUTH_FAIL_GSSAPI:
Jan F faae1e
+	case SSH_INVALID_USER:
Jan F faae1e
+		linux_audit_record_event(-1, audit_username(), NULL,
Jan F faae1e
+			get_remote_ipaddr(), "sshd", 0);
Jan F faae1e
+		break;
Jan F faae1e
+
Jan F faae1e
+	default:
Jan F faae1e
+		debug("%s: unhandled event %d", __func__, event);
Jan F faae1e
+	}
Jan F faae1e
+}
Jan F faae1e
+
Jan F faae1e
+#endif /* USE_LINUX_AUDIT */
Jan F faae1e
diff -up openssh-5.6p1/configure.ac.audit openssh-5.6p1/configure.ac
Jan F faae1e
--- openssh-5.6p1/configure.ac.audit	2010-08-16 05:15:23.000000000 +0200
Jan F faae1e
+++ openssh-5.6p1/configure.ac	2010-09-25 16:07:42.000000000 +0200
Jan F faae1e
@@ -1308,7 +1308,7 @@ int main(void)
Jan F faae1e
 
Jan F faae1e
 AUDIT_MODULE=none
Jan F faae1e
 AC_ARG_WITH(audit,
Jan F faae1e
-	[  --with-audit=module     Enable EXPERIMENTAL audit support (modules=debug,bsm)],
Jan F faae1e
+	[  --with-audit=module     Enable EXPERIMENTAL audit support (modules=debug,bsm,linux)],
Jan F faae1e
 	[
Jan F faae1e
 	  AC_MSG_CHECKING(for supported audit module)
Jan F faae1e
 	  case "$withval" in
Jan F faae1e
@@ -1332,10 +1332,18 @@ AC_ARG_WITH(audit,
Jan F faae1e
 		AC_CHECK_FUNCS(getaudit_addr aug_get_machine)
Jan F faae1e
 		AC_DEFINE(USE_BSM_AUDIT, 1, [Use BSM audit module])
Jan F faae1e
 		;;
Jan F faae1e
+	  linux)
Jan F faae1e
+		AC_MSG_RESULT(linux)
Jan F faae1e
+		AUDIT_MODULE=linux
Jan F faae1e
+		dnl    Checks for headers, libs and functions
Jan F faae1e
+		AC_CHECK_HEADERS(libaudit.h)
Jan F faae1e
+		SSHDLIBS="$SSHDLIBS -laudit"
Jan F faae1e
+		AC_DEFINE(USE_LINUX_AUDIT, 1, [Use Linux audit module])
Jan F faae1e
+		;;
Jan F faae1e
 	  debug)
Jan F faae1e
 		AUDIT_MODULE=debug
Jan F faae1e
 		AC_MSG_RESULT(debug)
Jan F faae1e
-		AC_DEFINE(SSH_AUDIT_EVENTS, 1, Use audit debugging module)
Jan F faae1e
+		AC_DEFINE(SSH_AUDIT_EVENTS, 1, [Use audit debugging module])
Jan F faae1e
 		;;
Jan F faae1e
 	  no)
Jan F faae1e
 		AC_MSG_RESULT(no)
Jan F faae1e
diff -up openssh-5.6p1/defines.h.audit openssh-5.6p1/defines.h
Jan F faae1e
--- openssh-5.6p1/defines.h.audit	2010-04-09 10:13:27.000000000 +0200
Jan F faae1e
+++ openssh-5.6p1/defines.h	2010-09-25 16:07:42.000000000 +0200
Jan F faae1e
@@ -566,6 +566,11 @@ struct winsize {
Jan F faae1e
 # define CUSTOM_SSH_AUDIT_EVENTS
Jan F faae1e
 #endif
Jan F faae1e
 
Jan F faae1e
+#ifdef USE_LINUX_AUDIT
Jan F faae1e
+# define SSH_AUDIT_EVENTS
Jan F faae1e
+# define CUSTOM_SSH_AUDIT_EVENTS
Jan F faae1e
+#endif
Jan F faae1e
+
Jan F faae1e
 #if !defined(HAVE___func__) && defined(HAVE___FUNCTION__)
Jan F faae1e
 #  define __func__ __FUNCTION__
Jan F faae1e
 #elif !defined(HAVE___func__)
Jan F faae1e
diff -up openssh-5.6p1/loginrec.c.audit openssh-5.6p1/loginrec.c
Jan F faae1e
--- openssh-5.6p1/loginrec.c.audit	2010-04-09 10:13:27.000000000 +0200
Jan F faae1e
+++ openssh-5.6p1/loginrec.c	2010-09-25 16:07:42.000000000 +0200
Jan F faae1e
@@ -468,9 +468,9 @@ login_write(struct logininfo *li)
Jan F faae1e
 #endif
Jan F faae1e
 #ifdef SSH_AUDIT_EVENTS
Jan F faae1e
 	if (li->type == LTYPE_LOGIN)
Jan F faae1e
-		audit_session_open(li->line);
Jan F faae1e
+		audit_session_open(li);
Jan F faae1e
 	else if (li->type == LTYPE_LOGOUT)
Jan F faae1e
-		audit_session_close(li->line);
Jan F faae1e
+		audit_session_close(li);
Jan F faae1e
 #endif
Jan F faae1e
 	return (0);
Jan F faae1e
 }
Jan F faae1e
diff -up openssh-5.6p1/Makefile.in.audit openssh-5.6p1/Makefile.in
Jan F faae1e
--- openssh-5.6p1/Makefile.in.audit	2010-05-12 08:51:39.000000000 +0200
Jan F faae1e
+++ openssh-5.6p1/Makefile.in	2010-09-25 16:07:42.000000000 +0200
Jan F faae1e
@@ -90,7 +90,7 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passw
Jan F faae1e
 	auth-krb5.o \
Jan F faae1e
 	auth2-gss.o gss-serv.o gss-serv-krb5.o \
Jan F faae1e
 	loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
Jan F faae1e
-	audit.o audit-bsm.o platform.o sftp-server.o sftp-common.o \
Jan F faae1e
+	audit.o audit-bsm.o audit-linux.o platform.o sftp-server.o sftp-common.o \
Jan F faae1e
 	roaming_common.o roaming_serv.o
Jan F faae1e
 
Jan F faae1e
 MANPAGES	= moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-rand-helper.8.out ssh-keysign.8.out ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out