From 8c5423f070b42df1eb6408227a2ffd14230728fb Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Thu, 17 Mar 2011 17:54:06 +0100
Subject: [PATCH 1/2] Add originalDN to fake groups

---
 src/db/sysdb.h                           |    3 ++-
 src/db/sysdb_ops.c                       |    8 +++++++-
 src/providers/ldap/sdap_async_accounts.c |   11 ++++++++++-
 src/tests/sysdb-tests.c                  |    4 ++--
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index e984265..971a35f 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -496,7 +496,8 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx,
 int sysdb_add_incomplete_group(struct sysdb_ctx *ctx,
                                struct sss_domain_info *domain,
                                const char *name,
-                               gid_t gid);
+                               gid_t gid,
+                               const char *original_dn);
 
 /* Add netgroup (only basic attrs and w/o checks) */
 int sysdb_add_basic_netgroup(struct sysdb_ctx *ctx,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index e60af71..ba1f667 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1147,7 +1147,8 @@ done:
 int sysdb_add_incomplete_group(struct sysdb_ctx *ctx,
                                struct sss_domain_info *domain,
                                const char *name,
-                               gid_t gid)
+                               gid_t gid,
+                               const char *original_dn)
 {
     TALLOC_CTX *tmpctx;
     time_t now;
@@ -1178,6 +1179,11 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *ctx,
                                  now-1);
     if (ret) goto done;
 
+    if (original_dn) {
+        ret = sysdb_attrs_add_string(attrs, SYSDB_ORIG_DN, original_dn);
+        if (ret) goto done;
+    }
+
     ret = sysdb_set_group_attr(tmpctx, ctx,
                                domain, name, attrs, SYSDB_MOD_REP);
 
diff --git a/src/providers/ldap/sdap_async_accounts.c b/src/providers/ldap/sdap_async_accounts.c
index ff3b4bd..705bf2b 100644
--- a/src/providers/ldap/sdap_async_accounts.c
+++ b/src/providers/ldap/sdap_async_accounts.c
@@ -1860,6 +1860,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
     struct ldb_message *msg;
     int i, mi, ai;
     const char *name;
+    const char *original_dn;
     char **missing;
     gid_t gid;
     int ret;
@@ -1931,9 +1932,17 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
                     goto fail;
                 }
 
+                ret = sysdb_attrs_get_string(ldap_groups[ai],
+                                             SYSDB_ORIG_DN,
+                                             &original_dn);
+                if (ret) {
+                    DEBUG(5, ("The group has no name original DN\n"));
+                    original_dn = NULL;
+                }
 
                 DEBUG(8, ("Adding fake group %s to sysdb\n", name));
-                ret = sysdb_add_incomplete_group(sysdb, dom, name, gid);
+                ret = sysdb_add_incomplete_group(sysdb, dom, name,
+                                                 gid, original_dn);
                 if (ret != EOK) {
                     goto fail;
                 }
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index eada9a3..b856c09 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -268,7 +268,7 @@ static int test_add_incomplete_group(struct test_data *data)
     int ret;
 
     ret = sysdb_add_incomplete_group(data->ctx->sysdb, data->ctx->domain,
-                                     data->groupname, data->gid);
+                                     data->groupname, data->gid, NULL);
     return ret;
 }
 
@@ -2743,7 +2743,7 @@ START_TEST(test_odd_characters)
 
     /* Add */
     ret = sysdb_add_incomplete_group(test_ctx->sysdb, test_ctx->domain,
-                                     odd_groupname, 20000);
+                                     odd_groupname, 20000, NULL);
     fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]",
                             ret, strerror(ret));
 
-- 
1.7.4

