vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jan F. Chadima a3ba41
diff -up openssh-5.2p1/auth1.c.selinux openssh-5.2p1/auth1.c
Jan F. Chadima ce94da
--- openssh-5.2p1/auth1.c.selinux	2008-07-09 12:54:05.000000000 +0200
Jan F. Chadima ce94da
+++ openssh-5.2p1/auth1.c	2009-08-11 22:43:07.918183730 +0200
Jan F. Chadima ce94da
@@ -392,6 +392,9 @@ do_authentication(Authctxt *authctxt)
Jan F. Chadima a3ba41
 {
Jan F. Chadima a3ba41
 	u_int ulen;
Jan F. Chadima ce94da
 	char *user, *style = NULL;
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+	char *role=NULL;
Jan F. Chadima ce94da
+#endif
Jan F. Chadima a3ba41
 
Jan F. Chadima a3ba41
 	/* Get the name of the user that we wish to log in as. */
Jan F. Chadima a3ba41
 	packet_read_expect(SSH_CMSG_USER);
Jan F. Chadima ce94da
@@ -400,11 +403,25 @@ do_authentication(Authctxt *authctxt)
Jan F. Chadima a3ba41
 	user = packet_get_string(&ulen);
Jan F. Chadima a3ba41
 	packet_check_eom();
Jan F. Chadima a3ba41
 
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima a3ba41
+	if ((role = strchr(user, '/')) != NULL)
Jan F. Chadima a3ba41
+		*role++ = '\0';
Jan F. Chadima ce94da
+#endif
Jan F. Chadima a3ba41
+
Jan F. Chadima a3ba41
 	if ((style = strchr(user, ':')) != NULL)
Jan F. Chadima a3ba41
 		*style++ = '\0';
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima a3ba41
+	else
Jan F. Chadima a3ba41
+		if (role && (style = strchr(role, ':')) != NULL)
Jan F. Chadima a3ba41
+			*style++ = '\0';
Jan F. Chadima ce94da
+#endif
Jan F. Chadima a3ba41
+			
Jan F. Chadima a3ba41
 
Jan F. Chadima a3ba41
 	authctxt->user = user;
Jan F. Chadima a3ba41
 	authctxt->style = style;
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima a3ba41
+	authctxt->role = role;
Jan F. Chadima ce94da
+#endif
Jan F. Chadima a3ba41
 
Jan F. Chadima a3ba41
 	/* Verify that the user is a valid user. */
Jan F. Chadima a3ba41
 	if ((authctxt->pw = PRIVSEP(getpwnamallow(user))) != NULL)
Jan F. Chadima ce94da
diff -up openssh-5.2p1/auth2.c.selinux openssh-5.2p1/auth2.c
Jan F. Chadima ce94da
--- openssh-5.2p1/auth2.c.selinux	2008-11-05 06:20:46.000000000 +0100
Jan F. Chadima ce94da
+++ openssh-5.2p1/auth2.c	2009-08-11 22:43:07.919756192 +0200
Jan F. Chadima ce94da
@@ -216,6 +216,9 @@ input_userauth_request(int type, u_int32
Jan F. Chadima ce94da
 	Authctxt *authctxt = ctxt;
Jan F. Chadima ce94da
 	Authmethod *m = NULL;
Jan F. Chadima ce94da
 	char *user, *service, *method, *style = NULL;
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+	char *role = NULL;
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
 	int authenticated = 0;
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
 	if (authctxt == NULL)
Jan F. Chadima ce94da
@@ -227,6 +230,11 @@ input_userauth_request(int type, u_int32
Jan F. Chadima ce94da
 	debug("userauth-request for user %s service %s method %s", user, service, method);
Jan F. Chadima ce94da
 	debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+	if ((role = strchr(user, '/')) != NULL)
Jan F. Chadima ce94da
+		*role++ = 0;
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
+
Jan F. Chadima ce94da
 	if ((style = strchr(user, ':')) != NULL)
Jan F. Chadima ce94da
 		*style++ = 0;
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
@@ -252,8 +260,15 @@ input_userauth_request(int type, u_int32
Jan F. Chadima ce94da
 		    use_privsep ? " [net]" : "");
Jan F. Chadima ce94da
 		authctxt->service = xstrdup(service);
Jan F. Chadima ce94da
 		authctxt->style = style ? xstrdup(style) : NULL;
Jan F. Chadima ce94da
-		if (use_privsep)
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+		authctxt->role = role ? xstrdup(role) : NULL;
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
+		if (use_privsep) {
Jan F. Chadima ce94da
 			mm_inform_authserv(service, style);
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+			mm_inform_authrole(role);
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
+		}
Jan F. Chadima ce94da
 		userauth_banner();
Jan F. Chadima ce94da
 	} else if (strcmp(user, authctxt->user) != 0 ||
Jan F. Chadima ce94da
 	    strcmp(service, authctxt->service) != 0) {
Jan F. Chadima ce94da
diff -up openssh-5.2p1/auth2-gss.c.selinux openssh-5.2p1/auth2-gss.c
Jan F. Chadima ce94da
--- openssh-5.2p1/auth2-gss.c.selinux	2007-12-02 12:59:45.000000000 +0100
Jan F. Chadima ce94da
+++ openssh-5.2p1/auth2-gss.c	2009-08-11 22:43:07.921723295 +0200
Jan F. Chadima ce94da
@@ -258,6 +258,7 @@ input_gssapi_mic(int type, u_int32_t ple
Jan F. Chadima ce94da
 	Authctxt *authctxt = ctxt;
Jan F. Chadima ce94da
 	Gssctxt *gssctxt;
Jan F. Chadima ce94da
 	int authenticated = 0;
Jan F. Chadima ce94da
+	char *micuser;
Jan F. Chadima ce94da
 	Buffer b;
Jan F. Chadima ce94da
 	gss_buffer_desc mic, gssbuf;
Jan F. Chadima ce94da
 	u_int len;
Jan F. Chadima ce94da
@@ -270,7 +271,13 @@ input_gssapi_mic(int type, u_int32_t ple
Jan F. Chadima ce94da
 	mic.value = packet_get_string(&len;;
Jan F. Chadima ce94da
 	mic.length = len;
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
-	ssh_gssapi_buildmic(&b, authctxt->user, authctxt->service,
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+	if (authctxt->role && (strlen(authctxt->role) > 0))
Jan F. Chadima ce94da
+		xasprintf(&micuser, "%s/%s", authctxt->user, authctxt->role);
Jan F. Chadima ce94da
+	else
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
+		micuser = authctxt->user;
Jan F. Chadima ce94da
+	ssh_gssapi_buildmic(&b, micuser, authctxt->service,
Jan F. Chadima ce94da
 	    "gssapi-with-mic");
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
 	gssbuf.value = buffer_ptr(&b);
Jan F. Chadima ce94da
@@ -282,6 +289,8 @@ input_gssapi_mic(int type, u_int32_t ple
Jan F. Chadima ce94da
 		logit("GSSAPI MIC check failed");
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
 	buffer_free(&b);
Jan F. Chadima ce94da
+	if (micuser != authctxt->user)
Jan F. Chadima ce94da
+		xfree(micuser);
Jan F. Chadima ce94da
 	xfree(mic.value);
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
 	authctxt->postponed = 0;
Jan F. Chadima ce94da
diff -up openssh-5.2p1/auth2-hostbased.c.selinux openssh-5.2p1/auth2-hostbased.c
Jan F. Chadima ce94da
--- openssh-5.2p1/auth2-hostbased.c.selinux	2008-07-17 10:57:19.000000000 +0200
Jan F. Chadima ce94da
+++ openssh-5.2p1/auth2-hostbased.c	2009-08-11 22:43:07.923721059 +0200
Jan F. Chadima ce94da
@@ -106,7 +106,15 @@ userauth_hostbased(Authctxt *authctxt)
Jan F. Chadima ce94da
 	buffer_put_string(&b, session_id2, session_id2_len);
Jan F. Chadima ce94da
 	/* reconstruct packet */
Jan F. Chadima ce94da
 	buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
Jan F. Chadima ce94da
-	buffer_put_cstring(&b, authctxt->user);
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+	if (authctxt->role) {
Jan F. Chadima ce94da
+		buffer_put_int(&b, strlen(authctxt->user)+strlen(authctxt->role)+1);
Jan F. Chadima ce94da
+		buffer_append(&b, authctxt->user, strlen(authctxt->user));
Jan F. Chadima ce94da
+		buffer_put_char(&b, '/');
Jan F. Chadima ce94da
+		buffer_append(&b, authctxt->role, strlen(authctxt->role));
Jan F. Chadima ce94da
+	} else 
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
+		buffer_put_cstring(&b, authctxt->user);
Jan F. Chadima ce94da
 	buffer_put_cstring(&b, service);
Jan F. Chadima ce94da
 	buffer_put_cstring(&b, "hostbased");
Jan F. Chadima ce94da
 	buffer_put_string(&b, pkalg, alen);
Jan F. Chadima adad2a
diff -up openssh-5.2p1/auth2-pubkey.c.selinux openssh-5.2p1/auth2-pubkey.c
Jan F. Chadima adad2a
--- openssh-5.2p1/auth2-pubkey.c.selinux	2008-07-04 04:54:25.000000000 +0200
Jan F. Chadima ce94da
+++ openssh-5.2p1/auth2-pubkey.c	2009-08-11 22:43:07.925704588 +0200
Jan F. Chadima ce94da
@@ -117,7 +117,15 @@ userauth_pubkey(Authctxt *authctxt)
Jan F. Chadima adad2a
 		}
Jan F. Chadima adad2a
 		/* reconstruct packet */
Jan F. Chadima adad2a
 		buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
Jan F. Chadima adad2a
-		buffer_put_cstring(&b, authctxt->user);
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima adad2a
+		if (authctxt->role) {
Jan F. Chadima adad2a
+			buffer_put_int(&b, strlen(authctxt->user)+strlen(authctxt->role)+1);
Jan F. Chadima adad2a
+			buffer_append(&b, authctxt->user, strlen(authctxt->user));
Jan F. Chadima adad2a
+			buffer_put_char(&b, '/');
Jan F. Chadima adad2a
+			buffer_append(&b, authctxt->role, strlen(authctxt->role));
Jan F. Chadima ce94da
+		} else 
Jan F. Chadima ce94da
+#endif
Jan F. Chadima adad2a
+			buffer_put_cstring(&b, authctxt->user);
Jan F. Chadima adad2a
 		buffer_put_cstring(&b,
Jan F. Chadima adad2a
 		    datafellows & SSH_BUG_PKSERVICE ?
Jan F. Chadima adad2a
 		    "ssh-userauth" :
Jan F. Chadima ce94da
diff -up openssh-5.2p1/auth.h.selinux openssh-5.2p1/auth.h
Jan F. Chadima ce94da
--- openssh-5.2p1/auth.h.selinux	2008-11-05 06:20:46.000000000 +0100
Jan F. Chadima ce94da
+++ openssh-5.2p1/auth.h	2009-08-11 22:43:07.927199901 +0200
Jan F. Chadima ce94da
@@ -58,6 +58,9 @@ struct Authctxt {
Jan F. Chadima ce94da
 	char		*service;
Jan F. Chadima ce94da
 	struct passwd	*pw;		/* set if 'valid' */
Jan F. Chadima ce94da
 	char		*style;
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+	char		*role;
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
 	void		*kbdintctxt;
Jan F. Chadima ce94da
 	void		*jpake_ctx;
Jan F. Chadima ce94da
 #ifdef BSD_AUTH
Jan F. Chadima ce94da
diff -up openssh-5.2p1/configure.ac.selinux openssh-5.2p1/configure.ac
Jan F. Chadima ce94da
--- openssh-5.2p1/configure.ac.selinux	2009-02-16 05:37:03.000000000 +0100
Jan F. Chadima ce94da
+++ openssh-5.2p1/configure.ac	2009-08-11 22:43:07.930259052 +0200
Jan F. Chadima ce94da
@@ -3335,6 +3335,7 @@ AC_ARG_WITH(selinux,
Jan F. Chadima ce94da
 		AC_CHECK_LIB(selinux, setexeccon, [ LIBSELINUX="-lselinux" ],
Jan F. Chadima ce94da
 		    AC_MSG_ERROR(SELinux support requires libselinux library))
Jan F. Chadima ce94da
 		SSHDLIBS="$SSHDLIBS $LIBSELINUX"
Jan F. Chadima ce94da
+		LIBS="$LIBS $LIBSELINUX"
Jan F. Chadima ce94da
 		AC_CHECK_FUNCS(getseuserbyname get_default_context_with_level)
Jan F. Chadima ce94da
 		LIBS="$save_LIBS"
Jan F. Chadima ce94da
 	fi ]
Jan F. Chadima ce94da
diff -up openssh-5.2p1/monitor.c.selinux openssh-5.2p1/monitor.c
Jan F. Chadima ce94da
--- openssh-5.2p1/monitor.c.selinux	2009-02-14 06:33:31.000000000 +0100
Jan F. Chadima ce94da
+++ openssh-5.2p1/monitor.c	2009-08-11 22:43:07.933623092 +0200
Jan F. Chadima ce94da
@@ -135,6 +135,9 @@ int mm_answer_sign(int, Buffer *);
Jan F. Chadima ce94da
 int mm_answer_pwnamallow(int, Buffer *);
Jan F. Chadima ce94da
 int mm_answer_auth2_read_banner(int, Buffer *);
Jan F. Chadima ce94da
 int mm_answer_authserv(int, Buffer *);
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+int mm_answer_authrole(int, Buffer *);
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
 int mm_answer_authpassword(int, Buffer *);
Jan F. Chadima ce94da
 int mm_answer_bsdauthquery(int, Buffer *);
Jan F. Chadima ce94da
 int mm_answer_bsdauthrespond(int, Buffer *);
Jan F. Chadima ce94da
@@ -211,6 +214,9 @@ struct mon_table mon_dispatch_proto20[] 
Jan F. Chadima ce94da
     {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
Jan F. Chadima ce94da
     {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
Jan F. Chadima ce94da
     {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+    {MONITOR_REQ_AUTHROLE, MON_ONCE, mm_answer_authrole},
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
     {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
Jan F. Chadima ce94da
     {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
Jan F. Chadima ce94da
 #ifdef USE_PAM
Jan F. Chadima ce94da
@@ -680,6 +686,9 @@ mm_answer_pwnamallow(int sock, Buffer *m
Jan F. Chadima ce94da
 	else {
Jan F. Chadima ce94da
 		/* Allow service/style information on the auth context */
Jan F. Chadima ce94da
 		monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+		monitor_permit(mon_dispatch, MONITOR_REQ_AUTHROLE, 1);
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
 		monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
Jan F. Chadima ce94da
 	}
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
@@ -724,6 +733,25 @@ mm_answer_authserv(int sock, Buffer *m)
Jan F. Chadima ce94da
 	return (0);
Jan F. Chadima ce94da
 }
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+int
Jan F. Chadima ce94da
+mm_answer_authrole(int sock, Buffer *m)
Jan F. Chadima ce94da
+{
Jan F. Chadima ce94da
+	monitor_permit_authentications(1);
Jan F. Chadima ce94da
+
Jan F. Chadima ce94da
+	authctxt->role = buffer_get_string(m, NULL);
Jan F. Chadima ce94da
+	debug3("%s: role=%s",
Jan F. Chadima ce94da
+	    __func__, authctxt->role);
Jan F. Chadima ce94da
+
Jan F. Chadima ce94da
+	if (strlen(authctxt->role) == 0) {
Jan F. Chadima ce94da
+		xfree(authctxt->role);
Jan F. Chadima ce94da
+		authctxt->role = NULL;
Jan F. Chadima ce94da
+	}
Jan F. Chadima ce94da
+
Jan F. Chadima ce94da
+	return (0);
Jan F. Chadima ce94da
+}
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
+
Jan F. Chadima ce94da
 int
Jan F. Chadima ce94da
 mm_answer_authpassword(int sock, Buffer *m)
Jan F. Chadima ce94da
 {
Jan F. Chadima ce94da
@@ -1102,7 +1130,7 @@ static int
Jan F. Chadima ce94da
 monitor_valid_userblob(u_char *data, u_int datalen)
Jan F. Chadima ce94da
 {
Jan F. Chadima ce94da
 	Buffer b;
Jan F. Chadima ce94da
-	char *p;
Jan F. Chadima ce94da
+	char *p, *r;
Jan F. Chadima ce94da
 	u_int len;
Jan F. Chadima ce94da
 	int fail = 0;
Jan F. Chadima adad2a
 
Jan F. Chadima ce94da
@@ -1128,6 +1156,8 @@ monitor_valid_userblob(u_char *data, u_i
Jan F. Chadima ce94da
 	if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
Jan F. Chadima ce94da
 		fail++;
Jan F. Chadima ce94da
 	p = buffer_get_string(&b, NULL);
Jan F. Chadima ce94da
+	if ((r = strchr(p, '/')) != NULL)
Jan F. Chadima ce94da
+		*r = '\0';
Jan F. Chadima ce94da
 	if (strcmp(authctxt->user, p) != 0) {
Jan F. Chadima ce94da
 		logit("wrong user name passed to monitor: expected %s != %.100s",
Jan F. Chadima ce94da
 		    authctxt->user, p);
Jan F. Chadima ce94da
@@ -1159,7 +1189,7 @@ monitor_valid_hostbasedblob(u_char *data
Jan F. Chadima ce94da
     char *chost)
Jan F. Chadima ce94da
 {
Jan F. Chadima ce94da
 	Buffer b;
Jan F. Chadima ce94da
-	char *p;
Jan F. Chadima ce94da
+	char *p, *r;
Jan F. Chadima ce94da
 	u_int len;
Jan F. Chadima ce94da
 	int fail = 0;
Jan F. Chadima ce94da
 
Jan F. Chadima ce94da
@@ -1176,6 +1206,8 @@ monitor_valid_hostbasedblob(u_char *data
Jan F. Chadima ce94da
 	if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
Jan F. Chadima ce94da
 		fail++;
Jan F. Chadima ce94da
 	p = buffer_get_string(&b, NULL);
Jan F. Chadima ce94da
+	if ((r = strchr(p, '/')) != NULL)
Jan F. Chadima ce94da
+		*r = '\0';
Jan F. Chadima ce94da
 	if (strcmp(authctxt->user, p) != 0) {
Jan F. Chadima ce94da
 		logit("wrong user name passed to monitor: expected %s != %.100s",
Jan F. Chadima ce94da
 		    authctxt->user, p);
Jan F. Chadima ce94da
diff -up openssh-5.2p1/monitor.h.selinux openssh-5.2p1/monitor.h
Jan F. Chadima ce94da
--- openssh-5.2p1/monitor.h.selinux	2008-11-05 06:20:46.000000000 +0100
Jan F. Chadima ce94da
+++ openssh-5.2p1/monitor.h	2009-08-11 22:43:07.935612930 +0200
Jan F. Chadima ce94da
@@ -31,6 +31,9 @@
Jan F. Chadima adad2a
 enum monitor_reqtype {
Jan F. Chadima adad2a
 	MONITOR_REQ_MODULI, MONITOR_ANS_MODULI,
Jan F. Chadima ce94da
 	MONITOR_REQ_FREE, MONITOR_REQ_AUTHSERV,
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+	MONITOR_REQ_AUTHROLE,
Jan F. Chadima ce94da
+#endif
Jan F. Chadima adad2a
 	MONITOR_REQ_SIGN, MONITOR_ANS_SIGN,
Jan F. Chadima adad2a
 	MONITOR_REQ_PWNAM, MONITOR_ANS_PWNAM,
Jan F. Chadima adad2a
 	MONITOR_REQ_AUTH2_READ_BANNER, MONITOR_ANS_AUTH2_READ_BANNER,
Jan F. Chadima adad2a
diff -up openssh-5.2p1/monitor_wrap.c.selinux openssh-5.2p1/monitor_wrap.c
Jan F. Chadima ce94da
--- openssh-5.2p1/monitor_wrap.c.selinux	2008-11-05 06:20:47.000000000 +0100
Jan F. Chadima ce94da
+++ openssh-5.2p1/monitor_wrap.c	2009-08-11 22:43:07.937212340 +0200
Jan F. Chadima ce94da
@@ -297,6 +297,25 @@ mm_inform_authserv(char *service, char *
Jan F. Chadima adad2a
 	buffer_free(&m);
Jan F. Chadima adad2a
 }
Jan F. Chadima a3ba41
 
Jan F. Chadima adad2a
+/* Inform the privileged process about role */
Jan F. Chadima adad2a
+
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima adad2a
+void
Jan F. Chadima adad2a
+mm_inform_authrole(char *role)
Jan F. Chadima adad2a
+{
Jan F. Chadima adad2a
+	Buffer m;
Jan F. Chadima adad2a
+
Jan F. Chadima adad2a
+	debug3("%s entering", __func__);
Jan F. Chadima adad2a
+
Jan F. Chadima adad2a
+	buffer_init(&m);
Jan F. Chadima adad2a
+	buffer_put_cstring(&m, role ? role : "");
Jan F. Chadima adad2a
+
Jan F. Chadima adad2a
+	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHROLE, &m);
Jan F. Chadima adad2a
+
Jan F. Chadima adad2a
+	buffer_free(&m);
Jan F. Chadima adad2a
+}
Jan F. Chadima ce94da
+#endif
Jan F. Chadima adad2a
+
Jan F. Chadima adad2a
 /* Do the password authentication */
Jan F. Chadima adad2a
 int
Jan F. Chadima adad2a
 mm_auth_password(Authctxt *authctxt, char *password)
Jan F. Chadima ce94da
diff -up openssh-5.2p1/monitor_wrap.h.selinux openssh-5.2p1/monitor_wrap.h
Jan F. Chadima ce94da
--- openssh-5.2p1/monitor_wrap.h.selinux	2008-11-05 06:20:47.000000000 +0100
Jan F. Chadima ce94da
+++ openssh-5.2p1/monitor_wrap.h	2009-08-11 22:43:07.938268752 +0200
Jan F. Chadima ce94da
@@ -41,6 +41,9 @@ int mm_is_monitor(void);
Jan F. Chadima ce94da
 DH *mm_choose_dh(int, int, int);
Jan F. Chadima ce94da
 int mm_key_sign(Key *, u_char **, u_int *, u_char *, u_int);
Jan F. Chadima ce94da
 void mm_inform_authserv(char *, char *);
Jan F. Chadima ce94da
+#ifdef WITH_SELINUX
Jan F. Chadima ce94da
+void mm_inform_authrole(char *);
Jan F. Chadima ce94da
+#endif
Jan F. Chadima ce94da
 struct passwd *mm_getpwnamallow(const char *);
Jan F. Chadima ce94da
 char *mm_auth2_read_banner(void);
Jan F. Chadima ce94da
 int mm_auth_password(struct Authctxt *, char *);
Jan F. Chadima adad2a
diff -up openssh-5.2p1/openbsd-compat/port-linux.c.selinux openssh-5.2p1/openbsd-compat/port-linux.c
Jan F. Chadima adad2a
--- openssh-5.2p1/openbsd-compat/port-linux.c.selinux	2008-03-26 21:27:21.000000000 +0100
Jan F. Chadima ce94da
+++ openssh-5.2p1/openbsd-compat/port-linux.c	2009-08-11 22:44:14.529196220 +0200
Jan F. Chadima adad2a
@@ -30,11 +30,16 @@
Jan F. Chadima adad2a
 #ifdef WITH_SELINUX
Jan F. Chadima adad2a
 #include "log.h"
Jan F. Chadima adad2a
 #include "port-linux.h"
Jan F. Chadima adad2a
+#include "key.h"
Jan F. Chadima adad2a
+#include "hostfile.h"
Jan F. Chadima adad2a
+#include "auth.h"
Jan F. Chadima adad2a
 
Jan F. Chadima adad2a
 #include <selinux/selinux.h>
Jan F. Chadima adad2a
 #include <selinux/flask.h>
Jan F. Chadima adad2a
 #include <selinux/get_context_list.h>
Jan F. Chadima adad2a
 
Jan F. Chadima adad2a
+extern Authctxt *the_authctxt;
Jan F. Chadima adad2a
+
Jan F. Chadima adad2a
 /* Wrapper around is_selinux_enabled() to log its return value once only */
Jan F. Chadima adad2a
 int
Jan F. Chadima adad2a
 ssh_selinux_enabled(void)
Jan F. Chadima adad2a
@@ -53,23 +58,36 @@ ssh_selinux_enabled(void)
Jan F. Chadima adad2a
 static security_context_t
Jan F. Chadima adad2a
 ssh_selinux_getctxbyname(char *pwname)
Jan F. Chadima adad2a
 {
Jan F. Chadima adad2a
-	security_context_t sc;
Jan F. Chadima adad2a
-	char *sename = NULL, *lvl = NULL;
Jan F. Chadima adad2a
-	int r;
Jan F. Chadima adad2a
+	security_context_t sc = NULL;
Jan F. Chadima adad2a
+	char *sename, *lvl;
Jan F. Chadima adad2a
+	char *role = NULL;
Jan F. Chadima adad2a
+	int r = 0;
Jan F. Chadima adad2a
 
Jan F. Chadima adad2a
+	if (the_authctxt) 
Jan F. Chadima adad2a
+		role=the_authctxt->role;
Jan F. Chadima adad2a
 #ifdef HAVE_GETSEUSERBYNAME
Jan F. Chadima adad2a
-	if (getseuserbyname(pwname, &sename, &lvl) != 0)
Jan F. Chadima adad2a
-		return NULL;
Jan F. Chadima adad2a
+	if ((r=getseuserbyname(pwname, &sename, &lvl)) != 0) {
Jan F. Chadima adad2a
+		sename = NULL;
Jan F. Chadima adad2a
+		lvl = NULL;
Jan F. Chadima adad2a
+	}
Jan F. Chadima adad2a
 #else
Jan F. Chadima adad2a
 	sename = pwname;
Jan F. Chadima adad2a
 	lvl = NULL;
Jan F. Chadima adad2a
 #endif
Jan F. Chadima adad2a
 
Jan F. Chadima adad2a
+	if (r == 0) {
Jan F. Chadima adad2a
 #ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
Jan F. Chadima adad2a
-	r = get_default_context_with_level(sename, lvl, NULL, &sc);
Jan F. Chadima adad2a
+		if (role != NULL && role[0])
Jan F. Chadima adad2a
+			r = get_default_context_with_rolelevel(sename, role, lvl, NULL, &sc);
Jan F. Chadima adad2a
+		else
Jan F. Chadima adad2a
+			r = get_default_context_with_level(sename, lvl, NULL, &sc);
Jan F. Chadima adad2a
 #else
Jan F. Chadima adad2a
-	r = get_default_context(sename, NULL, &sc);
Jan F. Chadima adad2a
+		if (role != NULL && role[0])
Jan F. Chadima adad2a
+			r = get_default_context_with_role(sename, role, NULL, &sc);
Jan F. Chadima adad2a
+		else
Jan F. Chadima adad2a
+			r = get_default_context(sename, NULL, &sc);
Jan F. Chadima adad2a
 #endif
Jan F. Chadima adad2a
+	}
Jan F. Chadima adad2a
 
Jan F. Chadima adad2a
 	if (r != 0) {
Jan F. Chadima adad2a
 		switch (security_getenforce()) {