Blame SOURCES/0113-IPA-Write-SELinux-usernames-in-the-right-case.patch

2fc102
From 12fa74c860993f154d1eb1585b4a735ca3684565 Mon Sep 17 00:00:00 2001
2fc102
From: Jakub Hrozek <jhrozek@redhat.com>
2fc102
Date: Wed, 12 Mar 2014 15:19:02 +0100
2fc102
Subject: [PATCH 113/113] IPA: Write SELinux usernames in the right case
2fc102
MIME-Version: 1.0
2fc102
Content-Type: text/plain; charset=UTF-8
2fc102
Content-Transfer-Encoding: 8bit
2fc102
2fc102
https://fedorahosted.org/sssd/ticket/2282
2fc102
2fc102
Reviewed-by: Michal Židek <mzidek@redhat.com>
2fc102
---
2fc102
 src/providers/ipa/ipa_selinux.c | 26 +++++++++++++++++++++-----
2fc102
 1 file changed, 21 insertions(+), 5 deletions(-)
2fc102
2fc102
diff --git a/src/providers/ipa/ipa_selinux.c b/src/providers/ipa/ipa_selinux.c
2fc102
index 4ec5a64159de139f9ba5b30bf1f1a56baf32a52f..7f59161918a04ff8c994a0ce0fe55924ff09eda7 100644
2fc102
--- a/src/providers/ipa/ipa_selinux.c
2fc102
+++ b/src/providers/ipa/ipa_selinux.c
2fc102
@@ -225,6 +225,7 @@ static errno_t create_order_array(TALLOC_CTX *mem_ctx, const char *map_order,
2fc102
                                   char ***_order_array, size_t *_order_count);
2fc102
 static errno_t choose_best_seuser(struct sysdb_attrs **usermaps,
2fc102
                                   struct pam_data *pd,
2fc102
+                                  struct sss_domain_info *user_domain,
2fc102
                                   char **order_array, int order_count,
2fc102
                                   const char *default_user);
2fc102
 
2fc102
@@ -311,8 +312,8 @@ static void ipa_selinux_handler_done(struct tevent_req *req)
2fc102
         goto fail;
2fc102
     }
2fc102
 
2fc102
-    ret = choose_best_seuser(best_match_maps, pd, order_array, order_count,
2fc102
-                             default_user);
2fc102
+    ret = choose_best_seuser(best_match_maps, pd, op_ctx->user_domain,
2fc102
+                             order_array, order_count, default_user);
2fc102
     if (ret != EOK) {
2fc102
         DEBUG(SSSDBG_CRIT_FAILURE,
2fc102
               ("Failed to evaluate ordered SELinux users array.\n"));
2fc102
@@ -601,13 +602,16 @@ done:
2fc102
     return ret;
2fc102
 }
2fc102
 
2fc102
-static errno_t write_selinux_login_file(const char *username, char *string);
2fc102
+static errno_t write_selinux_login_file(const char *orig_name,
2fc102
+                                        struct sss_domain_info *dom,
2fc102
+                                        char *string);
2fc102
 static errno_t remove_selinux_login_file(const char *username);
2fc102
 
2fc102
 /* Choose best selinux user based on given order and write
2fc102
  * the user to selinux login file. */
2fc102
 static errno_t choose_best_seuser(struct sysdb_attrs **usermaps,
2fc102
                                   struct pam_data *pd,
2fc102
+                                  struct sss_domain_info *user_domain,
2fc102
                                   char **order_array, int order_count,
2fc102
                                   const char *default_user)
2fc102
 {
2fc102
@@ -662,7 +666,7 @@ static errno_t choose_best_seuser(struct sysdb_attrs **usermaps,
2fc102
         }
2fc102
     }
2fc102
 
2fc102
-    ret = write_selinux_login_file(pd->user, file_content);
2fc102
+    ret = write_selinux_login_file(pd->user, user_domain, file_content);
2fc102
 done:
2fc102
     if (!file_content) {
2fc102
         err = remove_selinux_login_file(pd->user);
2fc102
@@ -673,7 +677,9 @@ done:
2fc102
     return ret;
2fc102
 }
2fc102
 
2fc102
-static errno_t write_selinux_login_file(const char *username, char *string)
2fc102
+static errno_t write_selinux_login_file(const char *orig_name,
2fc102
+                                        struct sss_domain_info *dom,
2fc102
+                                        char *string)
2fc102
 {
2fc102
     char *path = NULL;
2fc102
     char *tmp_path = NULL;
2fc102
@@ -685,6 +691,7 @@ static errno_t write_selinux_login_file(const char *username, char *string)
2fc102
     char *full_string = NULL;
2fc102
     int enforce;
2fc102
     errno_t ret = EOK;
2fc102
+    const char *username;
2fc102
 
2fc102
     len = strlen(string);
2fc102
     if (len == 0) {
2fc102
@@ -697,6 +704,15 @@ static errno_t write_selinux_login_file(const char *username, char *string)
2fc102
         return ENOMEM;
2fc102
     }
2fc102
 
2fc102
+    /* pam_selinux needs the username in the same format getpwnam() would
2fc102
+     * return it
2fc102
+     */
2fc102
+    username = sss_get_cased_name(tmp_ctx, orig_name, dom->case_sensitive);
2fc102
+    if (username == NULL) {
2fc102
+        ret = ENOMEM;
2fc102
+        goto done;
2fc102
+    }
2fc102
+
2fc102
     path = selogin_path(tmp_ctx, username);
2fc102
     if (path == NULL) {
2fc102
         ret = ENOMEM;
2fc102
-- 
2fc102
1.8.5.3
2fc102