afb096a
Index: modules/pam_selinux/pam_selinux.8.xml
afb096a
===================================================================
afb096a
RCS file: /cvsroot/pam/Linux-PAM/modules/pam_selinux/pam_selinux.8.xml,v
afb096a
retrieving revision 1.2
afb096a
diff -u -p -r1.2 pam_selinux.8.xml
afb096a
--- modules/pam_selinux/pam_selinux.8.xml	15 Jun 2007 10:17:22 -0000	1.2
afb096a
+++ modules/pam_selinux/pam_selinux.8.xml	19 May 2008 15:44:08 -0000
afb096a
@@ -37,6 +37,9 @@
afb096a
 	select_context
afb096a
       </arg>
afb096a
       <arg choice="opt">
afb096a
+	env_params
afb096a
+      </arg>
afb096a
+      <arg choice="opt">
afb096a
 	use_current_range
afb096a
       </arg>
afb096a
     </cmdsynopsis>
afb096a
@@ -137,12 +140,30 @@
afb096a
       </varlistentry>
afb096a
       <varlistentry>
afb096a
         <term>
afb096a
+          <option>env_params</option>
afb096a
+        </term>
afb096a
+        <listitem>
afb096a
+          <para>
afb096a
+            Attempt to obtain a custom security context role from PAM environment.
afb096a
+            If MLS is on obtain also sensitivity level. This option and the
afb096a
+            select_context option are mutually exclusive. The respective PAM
afb096a
+            environment variables are <emphasis>SELINUX_ROLE_REQUESTED</emphasis>,
afb096a
+            <emphasis>SELINUX_LEVEL_REQUESTED</emphasis>, and
afb096a
+            <emphasis>SELINUX_USE_CURRENT_RANGE</emphasis>. The first two variables
afb096a
+            are self describing and the last one if set to 1 makes the PAM module behave as
afb096a
+            if the use_current_range was specified on the command line of the module.
afb096a
+          </para>
afb096a
+        </listitem>
afb096a
+      </varlistentry>
afb096a
+      <varlistentry>
afb096a
+        <term>
afb096a
           <option>use_current_range</option>
afb096a
         </term>
afb096a
         <listitem>
afb096a
           <para>
afb096a
-            Use the sensitivity range of the process for the user context.
afb096a
-            This option and the select_context option are mutually exclusive.
afb096a
+            Use the sensitivity level of the current process for the user context
afb096a
+            instead of the default level. Also supresses asking of the
afb096a
+            sensitivity level from the user or obtaining it from PAM environment.
afb096a
           </para>
afb096a
         </listitem>
afb096a
       </varlistentry>
afb096a
Index: modules/pam_selinux/pam_selinux.c
afb096a
===================================================================
afb096a
RCS file: /cvsroot/pam/Linux-PAM/modules/pam_selinux/pam_selinux.c,v
afb096a
retrieving revision 1.16
afb096a
diff -u -p -r1.16 pam_selinux.c
afb096a
--- modules/pam_selinux/pam_selinux.c	22 Apr 2008 19:21:37 -0000	1.16
afb096a
+++ modules/pam_selinux/pam_selinux.c	19 May 2008 15:44:08 -0000
afb096a
@@ -2,8 +2,9 @@
afb096a
  * A module for Linux-PAM that will set the default security context after login
afb096a
  * via PAM.
afb096a
  *
afb096a
- * Copyright (c) 2003 Red Hat, Inc.
afb096a
+ * Copyright (c) 2003-2008 Red Hat, Inc.
afb096a
  * Written by Dan Walsh <dwalsh@redhat.com>
afb096a
+ * Additional improvements by Tomas Mraz <tmraz@redhat.com>
afb096a
  *
afb096a
  * Redistribution and use in source and binary forms, with or without
afb096a
  * modification, are permitted provided that the following conditions
afb096a
@@ -138,15 +139,22 @@ send_text (pam_handle_t *pamh, const cha
afb096a
  */
afb096a
 static int
afb096a
 query_response (pam_handle_t *pamh, const char *text, const char *def,
afb096a
-		char **responses, int debug)
afb096a
+		char **response, int debug)
afb096a
 {
afb096a
   int rc;
afb096a
   if (def) 
afb096a
-    rc = pam_prompt (pamh, PAM_PROMPT_ECHO_ON, responses, "%s [%s] ", text, def);
afb096a
+    rc = pam_prompt (pamh, PAM_PROMPT_ECHO_ON, response, "%s [%s] ", text, def);
afb096a
   else
afb096a
-    rc = pam_prompt (pamh, PAM_PROMPT_ECHO_ON, responses, "%s ", text);
afb096a
-  if (debug)
afb096a
-    pam_syslog(pamh, LOG_NOTICE, "%s %s", text, responses[0]);
afb096a
+    rc = pam_prompt (pamh, PAM_PROMPT_ECHO_ON, response, "%s ", text);
afb096a
+
afb096a
+  if (*response == NULL) {
afb096a
+    rc = PAM_CONV_ERR;
afb096a
+  }
afb096a
+  
afb096a
+  if (rc != PAM_SUCCESS) {
afb096a
+    pam_syslog(pamh, LOG_WARNING, "No response to query: %s", text);
afb096a
+  } else  if (debug)
afb096a
+    pam_syslog(pamh, LOG_NOTICE, "%s %s", text, *response);
afb096a
   return rc;
afb096a
 }
afb096a
 
afb096a
@@ -157,13 +165,15 @@ manual_context (pam_handle_t *pamh, cons
afb096a
   context_t new_context;
afb096a
   int mls_enabled = is_selinux_mls_enabled();
afb096a
   char *type=NULL;
afb096a
-  char *responses=NULL;
afb096a
+  char *response=NULL;
afb096a
 
afb096a
   while (1) {
afb096a
-    query_response(pamh,
afb096a
-		   _("Would you like to enter a security context? [N] "), NULL, 
afb096a
-		   &responses,debug);
afb096a
-    if ((responses[0] == 'y') || (responses[0] == 'Y'))
afb096a
+    if (query_response(pamh,
afb096a
+		   _("Would you like to enter a security context? [N] "), NULL,
afb096a
+		   &response, debug) != PAM_SUCCESS)
afb096a
+	return NULL;
afb096a
+
afb096a
+    if ((response[0] == 'y') || (response[0] == 'Y'))
afb096a
       {
afb096a
 	if (mls_enabled)
afb096a
 	  new_context = context_new ("user:role:type:level");
afb096a
@@ -176,26 +186,29 @@ manual_context (pam_handle_t *pamh, cons
afb096a
 	if (context_user_set (new_context, user))
afb096a
               goto fail_set;
afb096a
 
afb096a
-	_pam_drop(responses);
afb096a
+	_pam_drop(response);
afb096a
 	/* Allow the user to enter each field of the context individually */
afb096a
-	query_response(pamh,_("role:"), NULL, &responses,debug);
afb096a
-	if (responses[0] != '\0') {
afb096a
-	   if (context_role_set (new_context, responses)) 
afb096a
+	if (query_response(pamh, _("role:"), NULL, &response, debug) == PAM_SUCCESS &&
afb096a
+	    response[0] != '\0') {
afb096a
+	   if (context_role_set (new_context, response)) 
afb096a
               goto fail_set;
afb096a
-	   if (get_default_type(responses, &type)) 
afb096a
+	   if (get_default_type(response, &type)) 
afb096a
               goto fail_set;
afb096a
 	   if (context_type_set (new_context, type)) 
afb096a
               goto fail_set;
afb096a
 	}
afb096a
-	_pam_drop(responses);
afb096a
+	_pam_drop(response);
afb096a
+
afb096a
 	if (mls_enabled)
afb096a
 	  {
afb096a
-	    query_response(pamh,_("level:"), NULL, &responses,debug);
afb096a
-	    if (responses[0] != '\0') {
afb096a
-	      if (context_range_set (new_context, responses))
afb096a
+	    if (query_response(pamh, _("level:"), NULL, &response, debug) == PAM_SUCCESS &&
afb096a
+		response[0] != '\0') {
afb096a
+	      if (context_range_set (new_context, response))
afb096a
 		goto fail_set;
afb096a
 	    }
afb096a
+	    _pam_drop(response);
afb096a
 	  }
afb096a
+
afb096a
 	/* Get the string value of the context and see if it is valid. */
afb096a
 	if (!security_check_context(context_str(new_context))) {
afb096a
 	  newcon = strdup(context_str(new_context));
afb096a
@@ -204,16 +217,17 @@ manual_context (pam_handle_t *pamh, cons
afb096a
 	}
afb096a
 	else
afb096a
 	  send_text(pamh,_("Not a valid security context"),debug);
afb096a
-	context_free (new_context);
afb096a
+
afb096a
+        context_free (new_context);
afb096a
       }
afb096a
     else {
afb096a
-      _pam_drop(responses);
afb096a
+      _pam_drop(response);
afb096a
       return NULL;
afb096a
     }
afb096a
   } /* end while */
afb096a
  fail_set:
afb096a
   free(type);
afb096a
-  _pam_drop(responses);
afb096a
+  _pam_drop(response);
afb096a
   context_free (new_context);
afb096a
   return NULL;
afb096a
 }
afb096a
@@ -239,69 +253,91 @@ static int mls_range_allowed(pam_handle_
afb096a
 }
afb096a
 
afb096a
 static security_context_t
afb096a
-config_context (pam_handle_t *pamh, security_context_t puser_context, int debug)
afb096a
+config_context (pam_handle_t *pamh, security_context_t defaultcon, int use_current_range, int debug)
afb096a
 {
afb096a
   security_context_t newcon=NULL;
afb096a
   context_t new_context;
afb096a
   int mls_enabled = is_selinux_mls_enabled();
afb096a
-  char *responses=NULL;
afb096a
+  char *response=NULL;
afb096a
   char *type=NULL;
afb096a
   char resp_val = 0;
afb096a
 
afb096a
-  pam_prompt (pamh, PAM_TEXT_INFO, NULL, _("Default Security Context %s\n"), puser_context);
afb096a
+  pam_prompt (pamh, PAM_TEXT_INFO, NULL, _("Default Security Context %s\n"), defaultcon);
afb096a
 
afb096a
   while (1) {
afb096a
-    query_response(pamh,
afb096a
+    if (query_response(pamh,
afb096a
 		   _("Would you like to enter a different role or level?"), "n", 
afb096a
-		   &responses,debug);
afb096a
-
afb096a
-    resp_val = responses[0];
afb096a
-    _pam_drop(responses);
afb096a
+		   &response, debug) == PAM_SUCCESS) {
afb096a
+	resp_val = response[0];
afb096a
+	_pam_drop(response);
afb096a
+    } else {
afb096a
+	resp_val = 'N';
afb096a
+    }
afb096a
     if ((resp_val == 'y') || (resp_val == 'Y'))
afb096a
       {
afb096a
-        new_context = context_new(puser_context);
afb096a
-        
afb096a
+        if ((new_context = context_new(defaultcon)) == NULL)
afb096a
+    	    goto fail_set;
afb096a
+
afb096a
 	/* Allow the user to enter role and level individually */
afb096a
-	query_response(pamh,_("role:"), context_role_get(new_context), 
afb096a
-		       &responses, debug);
afb096a
-	if (responses[0]) {
afb096a
-	  if (get_default_type(responses, &type)) {
afb096a
-	    pam_prompt (pamh, PAM_ERROR_MSG, NULL, _("No default type for role %s\n"), responses);
afb096a
-	    _pam_drop(responses);
afb096a
+	if (query_response(pamh, _("role:"), context_role_get(new_context), 
afb096a
+		       &response, debug) == PAM_SUCCESS && response[0]) {
afb096a
+	  if (get_default_type(response, &type)) {
afb096a
+	    pam_prompt (pamh, PAM_ERROR_MSG, NULL, _("No default type for role %s\n"), response);
afb096a
+	    _pam_drop(response);
afb096a
 	    continue;
afb096a
 	  } else {
afb096a
-	    if (context_role_set(new_context, responses)) 
afb096a
+	    if (context_role_set(new_context, response)) 
afb096a
 	      goto fail_set;
afb096a
 	    if (context_type_set (new_context, type))
afb096a
 	      goto fail_set;
afb096a
 	  } 
afb096a
 	}
afb096a
-	_pam_drop(responses);
afb096a
+	_pam_drop(response);
afb096a
+
afb096a
 	if (mls_enabled)
afb096a
 	  {
afb096a
-	    query_response(pamh,_("level:"), context_range_get(new_context), 
afb096a
-			   &responses, debug);
afb096a
-	    if (responses[0]) {
afb096a
-	      if (context_range_set(new_context, responses))
afb096a
-		goto fail_set;
afb096a
+	    if (use_current_range) {
afb096a
+	        security_context_t mycon = NULL;
afb096a
+	        context_t my_context;
afb096a
+
afb096a
+		if (getcon(&mycon) != 0)
afb096a
+		    goto fail_set;
afb096a
+    		my_context = context_new(mycon);
afb096a
+	        if (my_context == NULL) {
afb096a
+    		    freecon(mycon);
afb096a
+		    goto fail_set;
afb096a
+		}
afb096a
+		freecon(mycon);
afb096a
+		if (context_range_set(new_context, context_range_get(my_context))) {
afb096a
+		    context_free(my_context);
afb096a
+		    goto fail_set;
afb096a
+		}
afb096a
+		context_free(my_context);
afb096a
+	    } else if (query_response(pamh, _("level:"), context_range_get(new_context), 
afb096a
+			   &response, debug) == PAM_SUCCESS && response[0]) {
afb096a
+		if (context_range_set(new_context, response))
afb096a
+		    goto fail_set;
afb096a
 	    } 
afb096a
-	    _pam_drop(responses);
afb096a
+	    _pam_drop(response);
afb096a
 	  }
afb096a
+
afb096a
 	if (debug)
afb096a
 	  pam_syslog(pamh, LOG_NOTICE, "Selected Security Context %s", context_str(new_context));
afb096a
 
afb096a
         /* Get the string value of the context and see if it is valid. */
afb096a
         if (!security_check_context(context_str(new_context))) {
afb096a
 	  newcon = strdup(context_str(new_context));
afb096a
-	  context_free (new_context);
afb096a
+	  if (newcon == NULL)
afb096a
+	    goto fail_set;
afb096a
+	  context_free(new_context);
afb096a
 
afb096a
           /* we have to check that this user is allowed to go into the
afb096a
              range they have specified ... role is tied to an seuser, so that'll
afb096a
              be checked at setexeccon time */
afb096a
-          if (mls_enabled && !mls_range_allowed(pamh, puser_context, newcon, debug)) {
afb096a
-	    pam_syslog(pamh, LOG_NOTICE, "Security context %s is not allowed for %s", puser_context, newcon);
afb096a
+          if (mls_enabled && !mls_range_allowed(pamh, defaultcon, newcon, debug)) {
afb096a
+	    pam_syslog(pamh, LOG_NOTICE, "Security context %s is not allowed for %s", defaultcon, newcon);
afb096a
 
afb096a
-    	    send_audit_message(pamh, 0, puser_context, newcon);
afb096a
+    	    send_audit_message(pamh, 0, defaultcon, newcon);
afb096a
 
afb096a
 	    free(newcon);
afb096a
             goto fail_range;
afb096a
@@ -309,26 +345,120 @@ config_context (pam_handle_t *pamh, secu
afb096a
 	  return newcon;
afb096a
 	}
afb096a
 	else {
afb096a
-	  send_audit_message(pamh, 0, puser_context, context_str(new_context));
afb096a
+	  send_audit_message(pamh, 0, defaultcon, context_str(new_context));
afb096a
 	  send_text(pamh,_("Not a valid security context"),debug);
afb096a
 	}
afb096a
         context_free(new_context); /* next time around allocates another */
afb096a
       }
afb096a
     else
afb096a
-      return strdup(puser_context);
afb096a
+      return strdup(defaultcon);
afb096a
   } /* end while */
afb096a
 
afb096a
   return NULL;
afb096a
 
afb096a
  fail_set:
afb096a
   free(type);
afb096a
-  _pam_drop(responses);
afb096a
+  _pam_drop(response);
afb096a
   context_free (new_context);
afb096a
-  send_audit_message(pamh, 0, puser_context, NULL);
afb096a
+  send_audit_message(pamh, 0, defaultcon, NULL);
afb096a
  fail_range:
afb096a
   return NULL;  
afb096a
 }
afb096a
 
afb096a
+static security_context_t
afb096a
+context_from_env (pam_handle_t *pamh, security_context_t defaultcon, int env_params, int use_current_range, int debug)
afb096a
+{
afb096a
+  security_context_t newcon = NULL;
afb096a
+  context_t new_context;
afb096a
+  context_t my_context = NULL;
afb096a
+  int mls_enabled = is_selinux_mls_enabled();
afb096a
+  const char *env = NULL;
afb096a
+  char *type = NULL;
afb096a
+
afb096a
+  if ((new_context = context_new(defaultcon)) == NULL)
afb096a
+    goto fail_set;
afb096a
+
afb096a
+  if (env_params && (env = pam_getenv(pamh, "SELINUX_ROLE_REQUESTED")) != NULL && env[0] != '\0') {
afb096a
+    if (debug)
afb096a
+	pam_syslog(pamh, LOG_NOTICE, "Requested role: %s", env);
afb096a
+
afb096a
+    if (get_default_type(env, &type)) {
afb096a
+	pam_syslog(pamh, LOG_NOTICE, "No default type for role %s", env);
afb096a
+	goto fail_set;
afb096a
+    } else {
afb096a
+	if (context_role_set(new_context, env)) 
afb096a
+	    goto fail_set;
afb096a
+	if (context_type_set(new_context, type))
afb096a
+	    goto fail_set;
afb096a
+    }
afb096a
+  }
afb096a
+
afb096a
+  if (mls_enabled) {
afb096a
+    if ((env = pam_getenv(pamh, "SELINUX_USE_CURRENT_RANGE")) != NULL && env[0] == '1') {
afb096a
+        if (debug)
afb096a
+	    pam_syslog(pamh, LOG_NOTICE, "SELINUX_USE_CURRENT_RANGE is set");
afb096a
+	use_current_range = 1;
afb096a
+    }
afb096a
+
afb096a
+    if (use_current_range) {
afb096a
+        security_context_t mycon = NULL;
afb096a
+
afb096a
+	if (getcon(&mycon) != 0)
afb096a
+	    goto fail_set;
afb096a
+        my_context = context_new(mycon);
afb096a
+        if (my_context == NULL) {
afb096a
+            freecon(mycon);
afb096a
+	    goto fail_set;
afb096a
+	}
afb096a
+	freecon(mycon);
afb096a
+	env = context_range_get(my_context);
afb096a
+    } else {
afb096a
+        env = pam_getenv(pamh, "SELINUX_LEVEL_REQUESTED");
afb096a
+    }
afb096a
+
afb096a
+    if (env != NULL && env[0] != '\0') {
afb096a
+        if (debug)
afb096a
+	    pam_syslog(pamh, LOG_NOTICE, "Requested level: %s", env);
afb096a
+	if (context_range_set(new_context, env))
afb096a
+	    goto fail_set;
afb096a
+    }
afb096a
+  }
afb096a
+
afb096a
+  newcon = strdup(context_str(new_context));
afb096a
+  if (newcon == NULL)
afb096a
+    goto fail_set;
afb096a
+
afb096a
+  if (debug)
afb096a
+    pam_syslog(pamh, LOG_NOTICE, "Selected Security Context %s", newcon);
afb096a
+  
afb096a
+  /* Get the string value of the context and see if it is valid. */
afb096a
+  if (security_check_context(newcon)) {
afb096a
+    pam_syslog(pamh, LOG_NOTICE, "Not a valid security context %s", newcon);
afb096a
+    send_audit_message(pamh, 0, defaultcon, newcon);
afb096a
+    freecon(newcon);
afb096a
+    newcon = NULL;
afb096a
+
afb096a
+    goto fail_set;
afb096a
+  }
afb096a
+
afb096a
+  /* we have to check that this user is allowed to go into the
afb096a
+     range they have specified ... role is tied to an seuser, so that'll
afb096a
+     be checked at setexeccon time */
afb096a
+  if (mls_enabled && !mls_range_allowed(pamh, defaultcon, newcon, debug)) {
afb096a
+    pam_syslog(pamh, LOG_NOTICE, "Security context %s is not allowed for %s", defaultcon, newcon);
afb096a
+    send_audit_message(pamh, 0, defaultcon, newcon);
afb096a
+    freecon(newcon);
afb096a
+    newcon = NULL;
afb096a
+  }
afb096a
+
afb096a
+ fail_set:
afb096a
+  free(type);
afb096a
+  context_free(my_context);
afb096a
+  context_free(new_context);
afb096a
+  send_audit_message(pamh, 0, defaultcon, NULL);
afb096a
+  return newcon;
afb096a
+}
afb096a
+
afb096a
 static void
afb096a
 security_restorelabel_tty(const pam_handle_t *pamh,
afb096a
 			  const char *tty, security_context_t context)
afb096a
@@ -439,13 +569,14 @@ PAM_EXTERN int
afb096a
 pam_sm_open_session(pam_handle_t *pamh, int flags UNUSED,
afb096a
 		    int argc, const char **argv)
afb096a
 {
afb096a
-  int i, debug = 0, ttys=1, has_tty=isatty(0);
afb096a
+  int i, debug = 0, ttys=1;
afb096a
   int verbose=0, close_session=0;
afb096a
   int select_context = 0;
afb096a
   int use_current_range = 0;
afb096a
   int ret = 0;
afb096a
   security_context_t* contextlist = NULL;
afb096a
   int num_contexts = 0;
afb096a
+  int env_params = 0;
afb096a
   const char *username = NULL;
afb096a
   const void *tty = NULL;
afb096a
   char *seuser=NULL;
afb096a
@@ -472,13 +603,16 @@ pam_sm_open_session(pam_handle_t *pamh, 
afb096a
     if (strcmp(argv[i], "use_current_range") == 0) {
afb096a
       use_current_range = 1;
afb096a
     }
afb096a
+    if (strcmp(argv[i], "env_params") == 0) {
afb096a
+      env_params = 1;
afb096a
+    }
afb096a
   }
afb096a
   
afb096a
   if (debug)
afb096a
     pam_syslog(pamh, LOG_NOTICE, "Open Session");
afb096a
 
afb096a
-  if (select_context && use_current_range) {
afb096a
-    pam_syslog(pamh, LOG_ERR, "select_context cannot be used with use_current_range");
afb096a
+  if (select_context && env_params) {
afb096a
+    pam_syslog(pamh, LOG_ERR, "select_context cannot be used with env_params");
afb096a
     select_context = 0;
afb096a
   }
afb096a
 
afb096a
@@ -510,12 +644,17 @@ pam_sm_open_session(pam_handle_t *pamh, 
afb096a
     freeconary(contextlist);
afb096a
     if (default_user_context == NULL) {
afb096a
 	  pam_syslog(pamh, LOG_ERR, "Out of memory");
afb096a
-          return PAM_AUTH_ERR;
afb096a
+          return PAM_BUF_ERR;
afb096a
     }
afb096a
+
afb096a
     user_context = default_user_context;
afb096a
-    if (select_context && has_tty) {
afb096a
-      user_context = config_context(pamh, default_user_context, debug);
afb096a
-      if (user_context == NULL) {
afb096a
+    if (select_context) {
afb096a
+        user_context = config_context(pamh, default_user_context, use_current_range, debug);
afb096a
+    } else if (env_params || use_current_range) {
afb096a
+        user_context = context_from_env(pamh, default_user_context, env_params, use_current_range, debug);
afb096a
+    }
afb096a
+
afb096a
+    if (user_context == NULL) {
afb096a
 	freecon(default_user_context);
afb096a
 	pam_syslog(pamh, LOG_ERR, "Unable to get valid context for %s",
afb096a
 		    username);
afb096a
@@ -524,11 +663,9 @@ pam_sm_open_session(pam_handle_t *pamh, 
afb096a
           return PAM_AUTH_ERR;
afb096a
         else
afb096a
           return PAM_SUCCESS;
afb096a
-      }
afb096a
-    } 
afb096a
+    }
afb096a
   }
afb096a
   else { 
afb096a
-    if (has_tty) {
afb096a
       user_context = manual_context(pamh,seuser,debug);
afb096a
       if (user_context == NULL) {
afb096a
 	pam_syslog (pamh, LOG_ERR, "Unable to get valid context for %s",
afb096a
@@ -538,59 +675,6 @@ pam_sm_open_session(pam_handle_t *pamh, 
afb096a
         else
afb096a
           return PAM_SUCCESS;
afb096a
       }
afb096a
-    } else {
afb096a
-        pam_syslog (pamh, LOG_ERR,
afb096a
-		    "Unable to get valid context for %s, No valid tty",
afb096a
-		    username);
afb096a
-        if (security_getenforce() == 1)
afb096a
-          return PAM_AUTH_ERR;
afb096a
-        else
afb096a
-          return PAM_SUCCESS;
afb096a
-    }
afb096a
-  }
afb096a
-
afb096a
-  if (use_current_range && is_selinux_mls_enabled()) {
afb096a
-    security_context_t process_context=NULL;    
afb096a
-    if (getcon(&process_context) == 0) {
afb096a
-      context_t pcon, ucon;
afb096a
-      char *process_level=NULL;
afb096a
-      security_context_t orig_context;
afb096a
-      
afb096a
-      if (user_context)
afb096a
-        orig_context = user_context;
afb096a
-      else
afb096a
-        orig_context = default_user_context;
afb096a
-
afb096a
-      pcon = context_new(process_context);
afb096a
-      freecon(process_context);
afb096a
-      process_level = strdup(context_range_get(pcon));
afb096a
-      context_free(pcon);
afb096a
-
afb096a
-      if (debug)
afb096a
-        pam_syslog (pamh, LOG_DEBUG, "process level=%s", process_level);
afb096a
-
afb096a
-      ucon = context_new(orig_context);
afb096a
-
afb096a
-      context_range_set(ucon, process_level);
afb096a
-      free(process_level);
afb096a
-
afb096a
-      if (!mls_range_allowed(pamh, orig_context, context_str(ucon), debug)) {
afb096a
-	send_text(pamh, _("Requested MLS level not in permitted range"), debug);
afb096a
-	/* even if default_user_context is NULL audit that anyway */
afb096a
-	send_audit_message(pamh, 0, default_user_context, context_str(ucon));
afb096a
-	context_free(ucon);
afb096a
-	return PAM_AUTH_ERR;
afb096a
-      }
afb096a
-
afb096a
-      if (debug)
afb096a
-        pam_syslog (pamh, LOG_DEBUG, "adjusted context=%s", context_str(ucon));
afb096a
-
afb096a
-      /* replace the user context with the level adjusted one */
afb096a
-      freecon(user_context);
afb096a
-      user_context = strdup(context_str(ucon));
afb096a
-
afb096a
-      context_free(ucon);
afb096a
-    }
afb096a
   }
afb096a
 
afb096a
   if (getexeccon(&prev_user_context)<0) {
afb096a
@@ -613,7 +697,7 @@ pam_sm_open_session(pam_handle_t *pamh, 
afb096a
       }
afb096a
     }
afb096a
   }
afb096a
-  if(ttys && tty ) {
afb096a
+  if (ttys && tty) {
afb096a
     ttyn=strdup(tty);
afb096a
     ttyn_context=security_label_tty(pamh,ttyn,user_context);
afb096a
   }