Blame SOURCES/0008-SYSDB-Prevent-users-and-groups-ID-collision-in-MPG-d.patch

9f2ebf
From d75b796151973a5d94a79f5577c15cda6eecb5ee Mon Sep 17 00:00:00 2001
9f2ebf
From: Jakub Hrozek <jhrozek@redhat.com>
9f2ebf
Date: Thu, 19 Oct 2017 17:18:15 +0200
9f2ebf
Subject: [PATCH 08/21] SYSDB: Prevent users and groups ID collision in MPG
9f2ebf
 domains except for id_provider=local
9f2ebf
MIME-Version: 1.0
9f2ebf
Content-Type: text/plain; charset=UTF-8
9f2ebf
Content-Transfer-Encoding: 8bit
9f2ebf
9f2ebf
This commit makes the check when adding an object in a MPG domain
9f2ebf
stricter in the sense that not only same names are allowed in a MPG
9f2ebf
domain, but also the same groups are not allowed either.
9f2ebf
9f2ebf
This commit is a backwards-incompatible change, but one that is needed,
9f2ebf
otherwise requesting the duplicate group first and then requesting the
9f2ebf
user entry would yield two object when searching by GID.
9f2ebf
9f2ebf
In order to keep backwards-compatibility, this uniqueness is NOT
9f2ebf
enforced with id_provider=local. This constraint can be removed in
9f2ebf
the future (or the local provider can be dropped altogether)
9f2ebf
9f2ebf
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
9f2ebf
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
9f2ebf
(cherry picked from commit ac962e2b286988d8666b3b81bf8b55b1705b9ac0)
9f2ebf
---
9f2ebf
 src/db/sysdb_ops.c | 41 ++++++++++++++++++++++++++++++++++++++---
9f2ebf
 1 file changed, 38 insertions(+), 3 deletions(-)
9f2ebf
9f2ebf
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
9f2ebf
index 0e39a629a5823ff49ed02ec4c08a21b66119f06f..2f8e36c6c9a2c2cefe4af5fb78957763304d989a 100644
9f2ebf
--- a/src/db/sysdb_ops.c
9f2ebf
+++ b/src/db/sysdb_ops.c
9f2ebf
@@ -1960,16 +1960,34 @@ int sysdb_add_user(struct sss_domain_info *domain,
9f2ebf
     }
9f2ebf
 
9f2ebf
     if (domain->mpg) {
9f2ebf
-        /* In MPG domains you can't have groups with the same name as users,
9f2ebf
-         * search if a group with the same name exists.
9f2ebf
+        /* In MPG domains you can't have groups with the same name or GID
9f2ebf
+         * as users, search if a group with the same name exists.
9f2ebf
          * Don't worry about users, if we try to add a user with the same
9f2ebf
          * name the operation will fail */
9f2ebf
 
9f2ebf
         ret = sysdb_search_group_by_name(tmp_ctx, domain, name, NULL, &msg;;
9f2ebf
         if (ret != ENOENT) {
9f2ebf
-            if (ret == EOK) ret = EEXIST;
9f2ebf
+            if (ret == EOK) {
9f2ebf
+                DEBUG(SSSDBG_OP_FAILURE,
9f2ebf
+                      "Group named %s already exists in an MPG domain\n",
9f2ebf
+                      name);
9f2ebf
+                ret = EEXIST;
9f2ebf
+            }
9f2ebf
             goto done;
9f2ebf
         }
9f2ebf
+
9f2ebf
+        if (strcasecmp(domain->provider, "local") != 0) {
9f2ebf
+            ret = sysdb_search_group_by_gid(tmp_ctx, domain, uid, NULL, &msg;;
9f2ebf
+            if (ret != ENOENT) {
9f2ebf
+                if (ret == EOK) {
9f2ebf
+                    DEBUG(SSSDBG_OP_FAILURE,
9f2ebf
+                        "Group with GID [%"SPRIgid"] already exists in an "
9f2ebf
+                        "MPG domain\n", gid);
9f2ebf
+                    ret = EEXIST;
9f2ebf
+                }
9f2ebf
+                goto done;
9f2ebf
+            }
9f2ebf
+        }
9f2ebf
     }
9f2ebf
 
9f2ebf
     /* check no other user with the same uid exist */
9f2ebf
@@ -2177,6 +2195,23 @@ int sysdb_add_group(struct sss_domain_info *domain,
9f2ebf
             }
9f2ebf
             goto done;
9f2ebf
         }
9f2ebf
+
9f2ebf
+        if (strcasecmp(domain->provider, "local") != 0) {
9f2ebf
+            ret = sysdb_search_user_by_uid(tmp_ctx, domain, gid, NULL, &msg;;
9f2ebf
+            if (ret != ENOENT) {
9f2ebf
+                if (ret == EOK) {
9f2ebf
+                    DEBUG(SSSDBG_TRACE_LIBS,
9f2ebf
+                          "User with the same UID exists in MPG domain: "
9f2ebf
+                          "[%"SPRIgid"].\n", gid);
9f2ebf
+                    ret = EEXIST;
9f2ebf
+                } else {
9f2ebf
+                    DEBUG(SSSDBG_TRACE_LIBS,
9f2ebf
+                          "sysdb_search_user_by_uid failed for gid: "
9f2ebf
+                          "[%"SPRIgid"].\n", gid);
9f2ebf
+                }
9f2ebf
+                goto done;
9f2ebf
+            }
9f2ebf
+        }
9f2ebf
     }
9f2ebf
 
9f2ebf
     /* check no other groups with the same gid exist */
9f2ebf
-- 
9f2ebf
2.13.5
9f2ebf