Blame SOURCES/sudo-1.8.6p7-ldapsearchuidfix.patch

0e1944
From b1f3fcf8d6e9a8e5326771a12fac8e08ed81f766 Mon Sep 17 00:00:00 2001
0e1944
From: Tomas Sykora <tosykora@redhat.com>
0e1944
Date: Fri, 19 Aug 2016 10:21:27 +0200
0e1944
Subject: [PATCH] Sudo with ldap doesn't work with 'user id'
0e1944
0e1944
in sudoUser option.
0e1944
0e1944
Rebased from:
0e1944
Patch39: sudo-1.8.6p7-ldapsearchuidfix.patch
0e1944
0e1944
Resolves:
0e1944
rhbz#1135539
0e1944
---
0e1944
 plugins/sudoers/def_data.c  |  4 ++++
0e1944
 plugins/sudoers/def_data.h  |  2 ++
0e1944
 plugins/sudoers/def_data.in |  3 +++
0e1944
 plugins/sudoers/defaults.c  |  2 ++
0e1944
 plugins/sudoers/ldap.c      | 10 ++++++++--
0e1944
 plugins/sudoers/sudoers.c   |  4 ++++
0e1944
 6 files changed, 23 insertions(+), 2 deletions(-)
0e1944
0e1944
diff --git a/plugins/sudoers/def_data.c b/plugins/sudoers/def_data.c
0e1944
index d8b1ada..3926fed 100644
0e1944
--- a/plugins/sudoers/def_data.c
0e1944
+++ b/plugins/sudoers/def_data.c
0e1944
@@ -439,6 +439,10 @@ struct sudo_defs_types sudo_defs_table[] = {
0e1944
 	N_("Don't fork and wait for the command to finish, just exec it"),
0e1944
 	NULL,
0e1944
     }, {
0e1944
+	"legacy_group_processing", T_FLAG,
0e1944
+	N_("Don't pre-resolve all group names"),
0e1944
+	NULL,
0e1944
+    }, {
0e1944
 	NULL, 0, NULL
0e1944
     }
0e1944
 };
0e1944
diff --git a/plugins/sudoers/def_data.h b/plugins/sudoers/def_data.h
0e1944
index 1b6be3d..5246e41 100644
0e1944
--- a/plugins/sudoers/def_data.h
0e1944
+++ b/plugins/sudoers/def_data.h
0e1944
@@ -206,6 +206,8 @@
0e1944
 #define def_iolog_mode          (sudo_defs_table[I_IOLOG_MODE].sd_un.mode)
0e1944
 #define I_CMND_NO_WAIT          103
0e1944
 #define def_cmnd_no_wait        (sudo_defs_table[I_CMND_NO_WAIT].sd_un.flag)
0e1944
+#define I_LEGACY_GROUP_PROCESSING 104
0e1944
+#define def_legacy_group_processing (sudo_defs_table[I_LEGACY_GROUP_PROCESSING].sd_un.flag)
0e1944
 
0e1944
 enum def_tuple {
0e1944
 	never,
0e1944
diff --git a/plugins/sudoers/def_data.in b/plugins/sudoers/def_data.in
0e1944
index 5200fe3..f1c9265 100644
0e1944
--- a/plugins/sudoers/def_data.in
0e1944
+++ b/plugins/sudoers/def_data.in
0e1944
@@ -325,3 +325,6 @@ iolog_mode
0e1944
 cmnd_no_wait
0e1944
 	T_FLAG
0e1944
 	"Don't fork and wait for the command to finish, just exec it"
0e1944
+legacy_group_processing
0e1944
+	T_FLAG
0e1944
+	"Don't pre-resolve all group names"
0e1944
diff --git a/plugins/sudoers/defaults.c b/plugins/sudoers/defaults.c
0e1944
index 5eaf8ea..9e60d94 100644
0e1944
--- a/plugins/sudoers/defaults.c
0e1944
+++ b/plugins/sudoers/defaults.c
0e1944
@@ -450,6 +450,8 @@ init_defaults(void)
0e1944
     }
0e1944
 
0e1944
     /* First initialize the flags. */
0e1944
+    def_legacy_group_processing = true;
0e1944
+    def_match_group_by_gid = true;
0e1944
 #ifdef LONG_OTP_PROMPT
0e1944
     def_long_otp_prompt = true;
0e1944
 #endif
0e1944
diff --git a/plugins/sudoers/ldap.c b/plugins/sudoers/ldap.c
0e1944
index 3fe27c7..96a0709 100644
0e1944
--- a/plugins/sudoers/ldap.c
0e1944
+++ b/plugins/sudoers/ldap.c
0e1944
@@ -1666,8 +1666,8 @@ sudo_ldap_build_pass1(LDAP *ld, struct passwd *pw)
72fdaf
     if (ldap_conf.search_filter)
72fdaf
 	sz += strlen(ldap_conf.search_filter);
72fdaf
 
72fdaf
-    /* Then add (|(sudoUser=USERNAME)(sudoUser=ALL)) + NUL */
72fdaf
-    sz += 29 + sudo_ldap_value_len(pw->pw_name);
72fdaf
+    /* Then add (|(sudoUser=USERNAME)(sudoUser=#uid)(sudoUser=ALL)) + NUL */
72fdaf
+    sz += 29 + (12 + MAX_UID_T_LEN) + sudo_ldap_value_len(pw->pw_name);
72fdaf
 
72fdaf
     /* Add space for primary and supplementary groups and gids */
72fdaf
     if ((grp = sudo_getgrgid(pw->pw_gid)) != NULL) {
0e1944
@@ -1730,6 +1730,12 @@ sudo_ldap_build_pass1(LDAP *ld, struct passwd *pw)
0e1944
     CHECK_LDAP_VCAT(buf, pw->pw_name, sz);
0e1944
     CHECK_STRLCAT(buf, ")", sz);
72fdaf
 
72fdaf
+    /* Append user uid */
72fdaf
+    (void) snprintf(gidbuf, sizeof(gidbuf), "%u", (unsigned int)pw->pw_uid);
72fdaf
+    (void) strlcat(buf, "(sudoUser=#", sz);
72fdaf
+    (void) strlcat(buf, gidbuf, sz);
72fdaf
+    (void) strlcat(buf, ")", sz);
72fdaf
+
72fdaf
     /* Append primary group and gid */
72fdaf
     if (grp != NULL) {
0e1944
 	CHECK_STRLCAT(buf, "(sudoUser=%", sz);
0e1944
diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c
0e1944
index 539177a..673ee5d 100644
0e1944
--- a/plugins/sudoers/sudoers.c
0e1944
+++ b/plugins/sudoers/sudoers.c
0e1944
@@ -208,6 +208,10 @@ sudoers_policy_init(void *info, char * const envp[])
0e1944
     if (set_loginclass(runas_pw ? runas_pw : sudo_user.pw))
0e1944
 	ret = true;
0e1944
 
0e1944
+    if (!def_match_group_by_gid || !def_legacy_group_processing) {
0e1944
+        def_match_group_by_gid = false;
0e1944
+	def_legacy_group_processing = false;
0e1944
+    }
0e1944
 cleanup:
0e1944
     if (!restore_perms())
0e1944
 	ret = -1;
0e1944
-- 
0e1944
2.7.4
0e1944