>From a584c8b0d46c7ad7b8907c4739c8cd69ef47a6b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Thu, 5 Mar 2015 15:40:41 +0100
Subject: [PATCH 8/8] sysdb: use sysdb_user/group_dn

---
 src/db/sysdb_ops.c        | 15 +++++----------
 src/db/sysdb_search.c     | 24 ++++++++----------------
 src/db/sysdb_upgrade.c    |  9 +++------
 src/tools/sss_groupshow.c |  8 ++------
 4 files changed, 18 insertions(+), 38 deletions(-)

diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 6085762dcc5585114dd3049dd3a365856cb6b190..acdc8415b122a99909d54c2ee650b3cd41377e02 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -423,8 +423,7 @@ int sysdb_search_user_by_uid(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
-    basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                            SYSDB_TMPL_USER_BASE, domain->name);
+    basedn = sysdb_user_base_dn(tmp_ctx, domain);
     if (!basedn) {
         ret = ENOMEM;
         goto done;
@@ -494,8 +493,7 @@ int sysdb_search_user_by_upn(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
-    basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                            SYSDB_TMPL_USER_BASE, domain->name);
+    basedn = sysdb_user_base_dn(tmp_ctx, domain);
     if (basedn == NULL) {
         ret = ENOMEM;
         goto done;
@@ -564,8 +562,7 @@ int sysdb_search_group_by_gid(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
-    basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                            SYSDB_TMPL_GROUP_BASE, domain->name);
+    basedn = sysdb_group_base_dn(tmp_ctx, domain);
     if (!basedn) {
         ret = ENOMEM;
         goto done;
@@ -2629,8 +2626,7 @@ int sysdb_search_users(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
-    basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                            SYSDB_TMPL_USER_BASE, domain->name);
+    basedn = sysdb_user_base_dn(tmp_ctx, domain);
     if (!basedn) {
         DEBUG(SSSDBG_OP_FAILURE, "Failed to build base dn\n");
         ret = ENOMEM;
@@ -2791,8 +2787,7 @@ int sysdb_search_groups(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
-    basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                            SYSDB_TMPL_GROUP_BASE, domain->name);
+    basedn = sysdb_group_base_dn(tmp_ctx, domain);
     if (!basedn) {
         DEBUG(SSSDBG_OP_FAILURE, "Failed to build base dn\n");
         ret = ENOMEM;
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c
index 677257405fae51774d4cd0c17516238e74fb7592..7acefcedd5c32ad0f3b12d3a9c32f20ea8c9f890 100644
--- a/src/db/sysdb_search.c
+++ b/src/db/sysdb_search.c
@@ -46,8 +46,7 @@ int sysdb_getpwnam(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
-    base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                             SYSDB_TMPL_USER_BASE, domain->name);
+    base_dn = sysdb_user_base_dn(tmp_ctx, domain);
     if (!base_dn) {
         ret = ENOMEM;
         goto done;
@@ -168,8 +167,7 @@ int sysdb_getpwuid(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
-    base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                             SYSDB_TMPL_USER_BASE, domain->name);
+    base_dn = sysdb_user_base_dn(tmp_ctx, domain);
     if (!base_dn) {
         ret = ENOMEM;
         goto done;
@@ -272,8 +270,7 @@ int sysdb_enumpwent(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
-    base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                             SYSDB_TMPL_USER_BASE, domain->name);
+    base_dn = sysdb_user_base_dn(tmp_ctx, domain);
     if (!base_dn) {
         ret = ENOMEM;
         goto done;
@@ -489,8 +486,7 @@ int sysdb_getgrnam(TALLOC_CTX *mem_ctx,
                                  SYSDB_DOM_BASE, domain->name);
     } else {
         fmt_filter = SYSDB_GRNAM_FILTER;
-        base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                                 SYSDB_TMPL_GROUP_BASE, domain->name);
+        base_dn = sysdb_group_base_dn(tmp_ctx, domain);
     }
     if (!base_dn) {
         ret = ENOMEM;
@@ -640,8 +636,7 @@ int sysdb_getgrgid(TALLOC_CTX *mem_ctx,
                                  SYSDB_DOM_BASE, domain->name);
     } else {
         fmt_filter = SYSDB_GRGID_FILTER;
-        base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                                 SYSDB_TMPL_GROUP_BASE, domain->name);
+        base_dn = sysdb_group_base_dn(tmp_ctx, domain);
     }
     if (!base_dn) {
         ret = ENOMEM;
@@ -689,8 +684,7 @@ int sysdb_enumgrent(TALLOC_CTX *mem_ctx,
                                  SYSDB_DOM_BASE, domain->name);
     } else {
         fmt_filter = SYSDB_GRENT_FILTER;
-        base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                                 SYSDB_TMPL_GROUP_BASE, domain->name);
+        base_dn = sysdb_group_base_dn(tmp_ctx, domain);
     }
     if (!base_dn) {
         ret = ENOMEM;
@@ -998,8 +992,7 @@ int sysdb_get_user_attr(TALLOC_CTX *mem_ctx,
         return ENOMEM;
     }
 
-    base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
-                             SYSDB_TMPL_USER_BASE, domain->name);
+    base_dn = sysdb_user_base_dn(tmp_ctx, domain);
     if (!base_dn) {
         ret = ENOMEM;
         goto done;
@@ -1530,8 +1523,7 @@ errno_t sysdb_get_direct_parents(TALLOC_CTX *mem_ctx,
         goto done;
     }
 
-    basedn = ldb_dn_new_fmt(tmp_ctx, sysdb_ctx_get_ldb(dom->sysdb),
-                            SYSDB_TMPL_GROUP_BASE, dom->name);
+    basedn = sysdb_group_base_dn(tmp_ctx, dom);
     if (!basedn) {
         ret = ENOMEM;
         goto done;
diff --git a/src/db/sysdb_upgrade.c b/src/db/sysdb_upgrade.c
index 558b4f5205c333e7a2b60d0a8e11589f122c385a..6cebc877b86df7a8035bf95cfa51aa4dae464372 100644
--- a/src/db/sysdb_upgrade.c
+++ b/src/db/sysdb_upgrade.c
@@ -443,14 +443,12 @@ int sysdb_check_upgrade_02(struct sss_domain_info *domains,
             goto done;
         }
 
-        users_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
-                                 SYSDB_TMPL_USER_BASE, dom->name);
+        users_dn = sysdb_user_base_dn(tmp_ctx, dom);
         if (!users_dn) {
             ret = ENOMEM;
             goto done;
         }
-        groups_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
-                                   SYSDB_TMPL_GROUP_BASE, dom->name);
+        groups_dn = sysdb_group_base_dn(tmp_ctx, dom);
         if (!groups_dn) {
             ret = ENOMEM;
             goto done;
@@ -1047,8 +1045,7 @@ int sysdb_upgrade_10(struct sysdb_ctx *sysdb, struct sss_domain_info *domain,
         return ret;
     }
 
-    basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
-                            SYSDB_TMPL_USER_BASE, domain->name);
+    basedn = sysdb_user_base_dn(tmp_ctx, domain);
     if (basedn == NULL) {
         ret = EIO;
         goto done;
diff --git a/src/tools/sss_groupshow.c b/src/tools/sss_groupshow.c
index 251e71b15d312822b4b8925b5b3063870c0147db..41d7475cef1093a4cb214ec4b017db59e6c26fe2 100644
--- a/src/tools/sss_groupshow.c
+++ b/src/tools/sss_groupshow.c
@@ -111,12 +111,8 @@ static int parse_members(TALLOC_CTX *mem_ctx,
         goto fail;
     }
 
-    user_basedn = ldb_dn_new_fmt(tmp_ctx, ldb,
-                                 SYSDB_TMPL_USER_BASE,
-                                 domain->name);
-    group_basedn = ldb_dn_new_fmt(tmp_ctx, ldb,
-                                  SYSDB_TMPL_GROUP_BASE,
-                                  domain->name);
+    user_basedn = sysdb_user_base_dn(tmp_ctx, domain);
+    group_basedn = sysdb_group_base_dn(tmp_ctx, domain);
     if (!user_basedn || !group_basedn) {
         ret = ENOMEM;
         goto fail;
-- 
1.9.3

