ad07b99
--- openssh-4.5p1/auth.h.selinux	2006-08-18 16:32:46.000000000 +0200
ad07b99
+++ openssh-4.5p1/auth.h	2006-12-20 22:10:48.000000000 +0100
ad07b99
@@ -58,6 +58,7 @@
ad07b99
 	char		*service;
ad07b99
 	struct passwd	*pw;		/* set if 'valid' */
ad07b99
 	char		*style;
ad07b99
+	char		*role;
ad07b99
 	void		*kbdintctxt;
ad07b99
 #ifdef BSD_AUTH
ad07b99
 	auth_session_t	*as;
ad07b99
--- openssh-4.5p1/auth1.c.selinux	2006-12-20 22:10:35.000000000 +0100
ad07b99
+++ openssh-4.5p1/auth1.c	2006-12-20 22:10:48.000000000 +0100
ad07b99
@@ -388,7 +388,7 @@
ad07b99
 do_authentication(Authctxt *authctxt)
ad07b99
 {
ad07b99
 	u_int ulen;
ad07b99
-	char *user, *style = NULL;
ad07b99
+	char *user, *style = NULL, *role=NULL;
ad07b99
 
ad07b99
 	/* Get the name of the user that we wish to log in as. */
ad07b99
 	packet_read_expect(SSH_CMSG_USER);
ad07b99
@@ -397,11 +397,19 @@
ad07b99
 	user = packet_get_string(&ulen);
ad07b99
 	packet_check_eom();
ad07b99
 
ad07b99
+	if ((role = strchr(user, '/')) != NULL)
ad07b99
+		*role++ = '\0';
ad07b99
+
ad07b99
 	if ((style = strchr(user, ':')) != NULL)
ad07b99
 		*style++ = '\0';
ad07b99
+	else
ad07b99
+		if (role && (style = strchr(role, ':')) != NULL)
ad07b99
+			*style++ = '\0';
ad07b99
+			
ad07b99
 
ad07b99
 	authctxt->user = user;
ad07b99
 	authctxt->style = style;
ad07b99
+	authctxt->role = role;
ad07b99
 
ad07b99
 	/* Verify that the user is a valid user. */
ad07b99
 	if ((authctxt->pw = PRIVSEP(getpwnamallow(user))) != NULL)
ad07b99
--- openssh-4.5p1/monitor.c.selinux	2006-11-07 13:16:08.000000000 +0100
ad07b99
+++ openssh-4.5p1/monitor.c	2006-12-20 22:10:48.000000000 +0100
ad07b99
@@ -133,6 +133,7 @@
ad07b99
 int mm_answer_pwnamallow(int, Buffer *);
ad07b99
 int mm_answer_auth2_read_banner(int, Buffer *);
ad07b99
 int mm_answer_authserv(int, Buffer *);
ad07b99
+int mm_answer_authrole(int, Buffer *);
ad07b99
 int mm_answer_authpassword(int, Buffer *);
ad07b99
 int mm_answer_bsdauthquery(int, Buffer *);
ad07b99
 int mm_answer_bsdauthrespond(int, Buffer *);
ad07b99
@@ -204,6 +205,7 @@
ad07b99
     {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
ad07b99
     {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
ad07b99
     {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
ad07b99
+    {MONITOR_REQ_AUTHROLE, MON_ONCE, mm_answer_authrole},
ad07b99
     {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
ad07b99
     {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
ad07b99
 #ifdef USE_PAM
ad07b99
@@ -653,6 +655,7 @@
ad07b99
 	else {
ad07b99
 		/* Allow service/style information on the auth context */
ad07b99
 		monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
ad07b99
+		monitor_permit(mon_dispatch, MONITOR_REQ_AUTHROLE, 1);
ad07b99
 		monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
ad07b99
 	}
ad07b99
 
ad07b99
@@ -698,6 +701,23 @@
ad07b99
 }
ad07b99
 
ad07b99
 int
ad07b99
+mm_answer_authrole(int sock, Buffer *m)
ad07b99
+{
ad07b99
+	monitor_permit_authentications(1);
ad07b99
+
ad07b99
+	authctxt->role = buffer_get_string(m, NULL);
ad07b99
+	debug3("%s: role=%s",
ad07b99
+	    __func__, authctxt->role);
ad07b99
+
ad07b99
+	if (strlen(authctxt->role) == 0) {
ad07b99
+		xfree(authctxt->role);
ad07b99
+		authctxt->role = NULL;
ad07b99
+	}
ad07b99
+
ad07b99
+	return (0);
ad07b99
+}
ad07b99
+
ad07b99
+int
ad07b99
 mm_answer_authpassword(int sock, Buffer *m)
ad07b99
 {
ad07b99
 	static int call_count;
ad07b99
--- openssh-4.5p1/openbsd-compat/port-linux.c.selinux	2006-09-01 07:38:41.000000000 +0200
ad07b99
+++ openssh-4.5p1/openbsd-compat/port-linux.c	2006-12-21 12:15:59.000000000 +0100
ad07b99
@@ -30,11 +30,16 @@
ad07b99
 #ifdef WITH_SELINUX
ad07b99
 #include "log.h"
ad07b99
 #include "port-linux.h"
ad07b99
+#include "key.h"
ad07b99
+#include "hostfile.h"
ad07b99
+#include "auth.h"
ad07b99
 
ad07b99
 #include <selinux/selinux.h>
ad07b99
 #include <selinux/flask.h>
ad07b99
 #include <selinux/get_context_list.h>
ad07b99
 
ad07b99
+extern Authctxt *the_authctxt;
ad07b99
+
ad07b99
 /* Wrapper around is_selinux_enabled() to log its return value once only */
ad07b99
 static int
ad07b99
 ssh_selinux_enabled(void)
ad07b99
@@ -53,23 +58,36 @@
ad07b99
 static security_context_t
ad07b99
 ssh_selinux_getctxbyname(char *pwname)
ad07b99
 {
ad07b99
-	security_context_t sc;
ad07b99
-	char *sename = NULL, *lvl = NULL;
ad07b99
-	int r;
ad07b99
+	security_context_t sc = NULL;
ad07b99
+	char *sename, *lvl;
ad07b99
+	char *role = NULL;
ad07b99
+	int r = 0;
ad07b99
 
ad07b99
+	if (the_authctxt) 
ad07b99
+		role=the_authctxt->role;
ad07b99
 #ifdef HAVE_GETSEUSERBYNAME
ad07b99
-	if (getseuserbyname(pwname, &sename, &lvl) != 0)
ad07b99
-		return NULL;
73a8557
+	if ((r=getseuserbyname(pwname, &sename, &lvl)) != 0) {
ad07b99
+		sename = NULL;
ad07b99
+		lvl = NULL;
ad07b99
+	}
ad07b99
 #else
ad07b99
 	sename = pwname;
ad07b99
 	lvl = NULL;
ad07b99
 #endif
ad07b99
 
ad07b99
+	if (r == 0) {
ad07b99
 #ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
ad07b99
-	r = get_default_context_with_level(sename, lvl, NULL, &sc);
ad07b99
+		if (role != NULL && role[0])
ad07b99
+			r = get_default_context_with_rolelevel(sename, role, lvl, NULL, &sc);
ad07b99
+		else
ad07b99
+			r = get_default_context_with_level(sename, lvl, NULL, &sc);
ad07b99
 #else
ad07b99
-	r = get_default_context(sename, NULL, &sc);
ad07b99
+		if (role != NULL && role[0])
ad07b99
+			r = get_default_context_with_role(sename, role, NULL, &sc);
ad07b99
+		else
ad07b99
+			r = get_default_context(sename, NULL, &sc);
ad07b99
 #endif
ad07b99
+	}
ad07b99
 
ad07b99
 	if (r != 0) {
ad07b99
 		switch (security_getenforce()) {
ad07b99
--- openssh-4.5p1/configure.ac.selinux	2006-12-20 22:10:35.000000000 +0100
ad07b99
+++ openssh-4.5p1/configure.ac	2006-12-21 11:18:48.000000000 +0100
ad07b99
@@ -3137,8 +3137,16 @@
ad07b99
 SELINUX_MSG="no"
ad07b99
 LIBSELINUX=""
ad07b99
 AC_ARG_WITH(selinux,
ad07b99
-	[  --with-selinux   Enable SELinux support],
ad07b99
+	[  --with-selinux[[=LIBSELINUX-PATH]]   Enable SELinux support],
ad07b99
 	[ if test "x$withval" != "xno" ; then
ad07b99
+		if test "x$withval" != "xyes"; then
ad07b99
+			CPPFLAGS="$CPPFLAGS -I${withval}/include"
ad07b99
+			if test -n "${need_dash_r}"; then
ad07b99
+				LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
ad07b99
+			else
ad07b99
+				LDFLAGS="-L${withval}/lib ${LDFLAGS}"
ad07b99
+			fi
ad07b99
+        	fi 
ad07b99
 		AC_DEFINE(WITH_SELINUX,1,[Define if you want SELinux support.])
ad07b99
 		SELINUX_MSG="yes"
ad07b99
 		AC_CHECK_HEADER([selinux/selinux.h], ,
ad07b99
--- openssh-4.5p1/auth2.c.selinux	2006-08-05 04:39:39.000000000 +0200
ad07b99
+++ openssh-4.5p1/auth2.c	2006-12-20 22:10:48.000000000 +0100
ad07b99
@@ -145,7 +145,7 @@
ad07b99
 {
ad07b99
 	Authctxt *authctxt = ctxt;
ad07b99
 	Authmethod *m = NULL;
ad07b99
-	char *user, *service, *method, *style = NULL;
ad07b99
+	char *user, *service, *method, *style = NULL, *role = NULL;
ad07b99
 	int authenticated = 0;
ad07b99
 
ad07b99
 	if (authctxt == NULL)
ad07b99
@@ -157,6 +157,9 @@
ad07b99
 	debug("userauth-request for user %s service %s method %s", user, service, method);
ad07b99
 	debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
ad07b99
 
ad07b99
+	if ((role = strchr(user, '/')) != NULL)
ad07b99
+		*role++ = 0;
ad07b99
+
ad07b99
 	if ((style = strchr(user, ':')) != NULL)
ad07b99
 		*style++ = 0;
ad07b99
 
ad07b99
@@ -182,8 +185,11 @@
ad07b99
 		    use_privsep ? " [net]" : "");
ad07b99
 		authctxt->service = xstrdup(service);
ad07b99
 		authctxt->style = style ? xstrdup(style) : NULL;
ad07b99
-		if (use_privsep)
ad07b99
+		authctxt->role = role ? xstrdup(role) : NULL;
ad07b99
+		if (use_privsep) {
ad07b99
 			mm_inform_authserv(service, style);
ad07b99
+			mm_inform_authrole(role);
ad07b99
+		}
ad07b99
 	} else if (strcmp(user, authctxt->user) != 0 ||
ad07b99
 	    strcmp(service, authctxt->service) != 0) {
ad07b99
 		packet_disconnect("Change of username or service not allowed: "
ad07b99
--- openssh-4.5p1/monitor_wrap.h.selinux	2006-08-05 04:39:40.000000000 +0200
ad07b99
+++ openssh-4.5p1/monitor_wrap.h	2006-12-20 22:10:48.000000000 +0100
ad07b99
@@ -41,6 +41,7 @@
ad07b99
 DH *mm_choose_dh(int, int, int);
ad07b99
 int mm_key_sign(Key *, u_char **, u_int *, u_char *, u_int);
ad07b99
 void mm_inform_authserv(char *, char *);
ad07b99
+void mm_inform_authrole(char *);
ad07b99
 struct passwd *mm_getpwnamallow(const char *);
ad07b99
 char *mm_auth2_read_banner(void);
ad07b99
 int mm_auth_password(struct Authctxt *, char *);
ad07b99
--- openssh-4.5p1/monitor_wrap.c.selinux	2006-09-01 07:38:37.000000000 +0200
ad07b99
+++ openssh-4.5p1/monitor_wrap.c	2006-12-20 22:10:48.000000000 +0100
ad07b99
@@ -282,6 +282,23 @@
ad07b99
 	buffer_free(&m);
ad07b99
 }
ad07b99
 
ad07b99
+/* Inform the privileged process about role */
ad07b99
+
ad07b99
+void
ad07b99
+mm_inform_authrole(char *role)
ad07b99
+{
ad07b99
+	Buffer m;
ad07b99
+
ad07b99
+	debug3("%s entering", __func__);
ad07b99
+
ad07b99
+	buffer_init(&m);
ad07b99
+	buffer_put_cstring(&m, role ? role : "");
ad07b99
+
ad07b99
+	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHROLE, &m);
ad07b99
+
ad07b99
+	buffer_free(&m);
ad07b99
+}
ad07b99
+
ad07b99
 /* Do the password authentication */
ad07b99
 int
ad07b99
 mm_auth_password(Authctxt *authctxt, char *password)
ad07b99
--- openssh-4.5p1/monitor.h.selinux	2006-03-26 05:30:02.000000000 +0200
ad07b99
+++ openssh-4.5p1/monitor.h	2006-12-20 22:10:35.000000000 +0100
ad07b99
@@ -30,7 +30,7 @@
ad07b99
 
ad07b99
 enum monitor_reqtype {
ad07b99
 	MONITOR_REQ_MODULI, MONITOR_ANS_MODULI,
ad07b99
-	MONITOR_REQ_FREE, MONITOR_REQ_AUTHSERV,
ad07b99
+	MONITOR_REQ_FREE, MONITOR_REQ_AUTHSERV,MONITOR_REQ_AUTHROLE,
ad07b99
 	MONITOR_REQ_SIGN, MONITOR_ANS_SIGN,
ad07b99
 	MONITOR_REQ_PWNAM, MONITOR_ANS_PWNAM,
ad07b99
 	MONITOR_REQ_AUTH2_READ_BANNER, MONITOR_ANS_AUTH2_READ_BANNER,