From f8f829ff4395409a4bb901cae2128948edf69d16 Mon Sep 17 00:00:00 2001
From: Petr Cech <pcech@redhat.com>
Date: Tue, 23 Aug 2016 10:10:33 +0200
Subject: [PATCH 4/7] SYSDB: ldb_add --> sss_ldb_add in sysdb

Resolves:
https://fedorahosted.org/sssd/ticket/3060
---
 src/db/sysdb.c          |  3 ++-
 src/db/sysdb_autofs.c   |  3 ++-
 src/db/sysdb_gpo.c      |  5 +++--
 src/db/sysdb_idmap.c    |  3 ++-
 src/db/sysdb_init.c     |  9 +++++----
 src/db/sysdb_ops.c      | 13 +++++++------
 src/db/sysdb_ranges.c   |  3 ++-
 src/db/sysdb_selinux.c  |  3 ++-
 src/db/sysdb_services.c |  3 ++-
 src/db/sysdb_sudo.c     |  3 ++-
 src/db/sysdb_upgrade.c  |  7 ++++---
 src/db/sysdb_views.c    |  5 +++--
 12 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index a76e8b47afc902d6c0c0ed5302b7f9231a11ade3..0f490bc301a1a3c34769954dc90a1f901c4b0250 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -24,6 +24,7 @@
 #include "util/strtonum.h"
 #include "util/sss_utf8.h"
 #include "util/crypto/sss_crypto.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 #include "confdb/confdb.h"
 #include "util/probes.h"
@@ -1162,7 +1163,7 @@ errno_t sysdb_set_bool(struct sysdb_ctx *sysdb,
     if (res->count) {
         lret = ldb_modify(sysdb->ldb, msg);
     } else {
-        lret = ldb_add(sysdb->ldb, msg);
+        lret = sss_ldb_add(sysdb->ldb, msg);
     }
 
     if (lret != LDB_SUCCESS) {
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
index b3e9b4ec83b66ec65a72ab7a3180106e2293d8a5..61ab7cf9efcc0edacd6652b77f45a1e4346e9f8e 100644
--- a/src/db/sysdb_autofs.c
+++ b/src/db/sysdb_autofs.c
@@ -21,6 +21,7 @@
 #include <talloc.h>
 
 #include "db/sysdb.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 #include "db/sysdb_autofs.h"
 
@@ -323,7 +324,7 @@ sysdb_save_autofsentry(struct sss_domain_info *domain,
     msg->elements = attrs->a;
     msg->num_elements = attrs->num;
 
-    ret = ldb_add(domain->sysdb->ldb, msg);
+    ret = sss_ldb_add(domain->sysdb->ldb, msg);
     ret = sysdb_error_to_errno(ret);
 done:
     talloc_free(tmp_ctx);
diff --git a/src/db/sysdb_gpo.c b/src/db/sysdb_gpo.c
index e5af91bd8efd1f953326f8069c5c620ca3692017..170d7b7489704a7e74dea27c3b9c0ce1c1870c1d 100644
--- a/src/db/sysdb_gpo.c
+++ b/src/db/sysdb_gpo.c
@@ -22,6 +22,7 @@
 
 
 #include "db/sysdb.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 
 static struct ldb_dn *
@@ -161,7 +162,7 @@ sysdb_gpo_store_gpo(struct sss_domain_info *domain,
             goto done;
         }
 
-        lret = ldb_add(domain->sysdb->ldb, update_msg);
+        lret = sss_ldb_add(domain->sysdb->ldb, update_msg);
         if (lret != LDB_SUCCESS) {
             DEBUG(SSSDBG_MINOR_FAILURE,
                   "Failed to add GPO: [%s]\n",
@@ -457,7 +458,7 @@ sysdb_gpo_store_gpo_result_setting(struct sss_domain_info *domain,
             }
         }
 
-        lret = ldb_add(domain->sysdb->ldb, update_msg);
+        lret = sss_ldb_add(domain->sysdb->ldb, update_msg);
         if (lret != LDB_SUCCESS) {
             DEBUG(SSSDBG_MINOR_FAILURE,
                   "Failed to add GPO Result: [%s]\n",
diff --git a/src/db/sysdb_idmap.c b/src/db/sysdb_idmap.c
index 2aa00ef83f182a77b0e9b94ba8a80ef71af6518c..f0186760e08470f07f73d4c3563a0097368bb8d6 100644
--- a/src/db/sysdb_idmap.c
+++ b/src/db/sysdb_idmap.c
@@ -22,6 +22,7 @@
 
 
 #include "db/sysdb.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 
 static struct ldb_dn *
@@ -166,7 +167,7 @@ sysdb_idmap_store_mapping(struct sss_domain_info *domain,
             goto done;
         }
 
-        lret = ldb_add(domain->sysdb->ldb, update_msg);
+        lret = sss_ldb_add(domain->sysdb->ldb, update_msg);
         if (lret != LDB_SUCCESS) {
             DEBUG(SSSDBG_MINOR_FAILURE,
                   "Failed to add mapping: [%s]\n",
diff --git a/src/db/sysdb_init.c b/src/db/sysdb_init.c
index 9e3646bfeb9a494ebff2d348ab1c53336f8a5c03..278526f935d3cc391302911a33187c862acf7f4f 100644
--- a/src/db/sysdb_init.c
+++ b/src/db/sysdb_init.c
@@ -23,6 +23,7 @@
 #include "util/util.h"
 #include "util/strtonum.h"
 #include "util/sss_utf8.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 #include "confdb/confdb.h"
 #include "util/probes.h"
@@ -192,7 +193,7 @@ static errno_t sysdb_domain_create_int(struct ldb_context *ldb,
         goto done;
     }
     /* do a synchronous add */
-    ret = ldb_add(ldb, msg);
+    ret = sss_ldb_add(ldb, msg);
     if (ret != LDB_SUCCESS) {
         DEBUG(SSSDBG_FATAL_FAILURE, "Failed to initialize DB (%d, [%s]) "
                                      "for domain %s!\n",
@@ -222,7 +223,7 @@ static errno_t sysdb_domain_create_int(struct ldb_context *ldb,
         goto done;
     }
     /* do a synchronous add */
-    ret = ldb_add(ldb, msg);
+    ret = sss_ldb_add(ldb, msg);
     if (ret != LDB_SUCCESS) {
         DEBUG(SSSDBG_FATAL_FAILURE, "Failed to initialize DB (%d, [%s]) "
                                      "for domain %s!\n",
@@ -252,7 +253,7 @@ static errno_t sysdb_domain_create_int(struct ldb_context *ldb,
         goto done;
     }
     /* do a synchronous add */
-    ret = ldb_add(ldb, msg);
+    ret = sss_ldb_add(ldb, msg);
     if (ret != LDB_SUCCESS) {
         DEBUG(SSSDBG_FATAL_FAILURE, "Failed to initialize DB (%d, [%s]) for "
                                      "domain %s!\n",
@@ -319,7 +320,7 @@ static errno_t sysdb_cache_add_base_ldif(struct ldb_context *ldb,
     struct ldb_ldif *ldif;
 
     while ((ldif = ldb_ldif_read_string(ldb, &base_ldif))) {
-        ret = ldb_add(ldb, ldif->msg);
+        ret = sss_ldb_add(ldb, ldif->msg);
         if (ret != LDB_SUCCESS) {
             DEBUG(SSSDBG_FATAL_FAILURE,
                   "Failed to initialize DB (%d, [%s]) for domain %s!\n",
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index a81840b2515d09f91d1dfa783bcf08f0fad112b4..90614cc7df5336ccba4718d7a5391af7b967075f 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -20,6 +20,7 @@
 */
 
 #include "util/util.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 #include "db/sysdb_services.h"
 #include "db/sysdb_autofs.h"
@@ -846,10 +847,10 @@ static errno_t sysdb_create_ts_entry(struct sysdb_ctx *sysdb,
         goto done;
     }
 
-    lret = ldb_add(sysdb->ldb_ts, msg);
+    lret = sss_ldb_add(sysdb->ldb_ts, msg);
     if (lret != LDB_SUCCESS) {
         DEBUG(SSSDBG_OP_FAILURE,
-              "ldb_add failed: [%s](%d)[%s]\n",
+              "sss_ldb_add failed: [%s](%d)[%s]\n",
               ldb_strerror(lret), lret, ldb_errstring(sysdb->ldb_ts));
     }
 
@@ -1626,7 +1627,7 @@ int sysdb_add_basic_user(struct sss_domain_info *domain,
     ret = sysdb_add_ulong(msg, SYSDB_CREATE_TIME, (unsigned long)time(NULL));
     if (ret) goto done;
 
-    ret = ldb_add(domain->sysdb->ldb, msg);
+    ret = sss_ldb_add(domain->sysdb->ldb, msg);
     ret = sysdb_error_to_errno(ret);
 
 done:
@@ -2023,7 +2024,7 @@ int sysdb_add_basic_group(struct sss_domain_info *domain,
     ret = sysdb_add_ulong(msg, SYSDB_CREATE_TIME, (unsigned long)time(NULL));
     if (ret) goto done;
 
-    ret = ldb_add(domain->sysdb->ldb, msg);
+    ret = sss_ldb_add(domain->sysdb->ldb, msg);
     ret = sysdb_error_to_errno(ret);
 
 done:
@@ -2351,7 +2352,7 @@ int sysdb_add_basic_netgroup(struct sss_domain_info *domain,
     ret = sysdb_add_ulong(msg, SYSDB_CREATE_TIME, (unsigned long) time(NULL));
     if (ret) goto done;
 
-    ret = ldb_add(domain->sysdb->ldb, msg);
+    ret = sss_ldb_add(domain->sysdb->ldb, msg);
     ret = sysdb_error_to_errno(ret);
 
 done:
@@ -3234,7 +3235,7 @@ int sysdb_store_custom(struct sss_domain_info *domain,
     msg->num_elements = attrs->num;
 
     if (add_object) {
-        ret = ldb_add(domain->sysdb->ldb, msg);
+        ret = sss_ldb_add(domain->sysdb->ldb, msg);
     } else {
         ret = ldb_modify(domain->sysdb->ldb, msg);
     }
diff --git a/src/db/sysdb_ranges.c b/src/db/sysdb_ranges.c
index 511e4785d9aa68b2a33b440e1c5ee62e5ccf7ce4..6aa7182387af2604ac4eadcc60516c6b078b0bda 100644
--- a/src/db/sysdb_ranges.c
+++ b/src/db/sysdb_ranges.c
@@ -20,6 +20,7 @@
 */
 
 #include "util/util.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 
 static errno_t find_attr_as_uint32_t(const struct ldb_message *msg,
@@ -239,7 +240,7 @@ errno_t sysdb_range_create(struct sysdb_ctx *sysdb, struct range_info *range)
     ret = sysdb_add_string(msg, SYSDB_ID_RANGE_TYPE, range->range_type);
     if (ret) goto done;
 
-    ret = ldb_add(sysdb->ldb, msg);
+    ret = sss_ldb_add(sysdb->ldb, msg);
     if (ret) goto done;
 
     ret = sysdb_error_to_errno(ret);
diff --git a/src/db/sysdb_selinux.c b/src/db/sysdb_selinux.c
index 2dbbb75b99acff28d1a92e1a2d2ccc22004188cc..0321aa2c48e98fb3c38f01dca781fa91952e3ac9 100644
--- a/src/db/sysdb_selinux.c
+++ b/src/db/sysdb_selinux.c
@@ -21,6 +21,7 @@
 
 #include "util/sss_selinux.h"
 #include "db/sysdb_selinux.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 
 /* Some generic routines */
@@ -69,7 +70,7 @@ sysdb_add_selinux_entity(struct sysdb_ctx *sysdb,
     msg->elements = attrs->a;
     msg->num_elements = attrs->num;
 
-    ret = ldb_add(sysdb->ldb, msg);
+    ret = sss_ldb_add(sysdb->ldb, msg);
     ret = sysdb_error_to_errno(ret);
 
 done:
diff --git a/src/db/sysdb_services.c b/src/db/sysdb_services.c
index 8118fef0004eefa8a65d130a3562a780cc85f372..751f1b12f88f7e38ed250793f867afe8f5f8df09 100644
--- a/src/db/sysdb_services.c
+++ b/src/db/sysdb_services.c
@@ -23,6 +23,7 @@
 
 #include "util/util.h"
 #include "db/sysdb.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 #include "db/sysdb_services.h"
 
@@ -508,7 +509,7 @@ sysdb_svc_add(TALLOC_CTX *mem_ctx,
     ret = sysdb_add_ulong(msg, SYSDB_CREATE_TIME, (unsigned long)time(NULL));
     if (ret) goto done;
 
-    lret = ldb_add(domain->sysdb->ldb, msg);
+    lret = sss_ldb_add(domain->sysdb->ldb, msg);
     ret = sysdb_error_to_errno(lret);
 
     if (ret == EOK && dn) {
diff --git a/src/db/sysdb_sudo.c b/src/db/sysdb_sudo.c
index 601fb63f236a7ed9eede130fd8cf4c3a1559fc4b..b080ddd71e6a3380a50f8b11efcc47fc28ea8677 100644
--- a/src/db/sysdb_sudo.c
+++ b/src/db/sysdb_sudo.c
@@ -24,6 +24,7 @@
 #include <time.h>
 
 #include "db/sysdb.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 #include "db/sysdb_sudo.h"
 
@@ -547,7 +548,7 @@ static errno_t sysdb_sudo_set_refresh_time(struct sss_domain_info *domain,
     if (res->count) {
         lret = ldb_modify(domain->sysdb->ldb, msg);
     } else {
-        lret = ldb_add(domain->sysdb->ldb, msg);
+        lret = sss_ldb_add(domain->sysdb->ldb, msg);
     }
 
     if (lret != LDB_SUCCESS) {
diff --git a/src/db/sysdb_upgrade.c b/src/db/sysdb_upgrade.c
index 4ca8433f9d5430b038f90563c34cede02393b0b0..83d1a531fbf5c93ab6c5db126b20509791b47a95 100644
--- a/src/db/sysdb_upgrade.c
+++ b/src/db/sysdb_upgrade.c
@@ -23,6 +23,7 @@
 */
 
 #include "util/util.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 #include "db/sysdb_autofs.h"
 
@@ -489,7 +490,7 @@ int sysdb_check_upgrade_02(struct sss_domain_info *domains,
                 goto done;
             }
 
-            ret = ldb_add(sysdb->ldb, msg);
+            ret = sss_ldb_add(sysdb->ldb, msg);
             if (ret != LDB_SUCCESS) {
                 DEBUG(SSSDBG_FATAL_FAILURE, "WARNING: Could not add entry %s,"
                           " to new ldb file! (%d [%s])\n",
@@ -715,7 +716,7 @@ int sysdb_upgrade_04(struct sysdb_ctx *sysdb, const char **ver)
         goto done;
     }
 
-    ret = ldb_add(sysdb->ldb, msg);
+    ret = sss_ldb_add(sysdb->ldb, msg);
     if (ret != LDB_SUCCESS) {
         ret = sysdb_error_to_errno(ret);
         goto done;
@@ -1471,7 +1472,7 @@ int sysdb_upgrade_14(struct sysdb_ctx *sysdb, const char **ver)
         goto done;
     }
     /* do a synchronous add */
-    ret = ldb_add(sysdb->ldb, msg);
+    ret = sss_ldb_add(sysdb->ldb, msg);
     if (ret != LDB_SUCCESS) {
         DEBUG(SSSDBG_FATAL_FAILURE,
               "Failed to upgrade DB (%d, [%s])!\n",
diff --git a/src/db/sysdb_views.c b/src/db/sysdb_views.c
index 79f513d13ba41212a6cd84e1d9e609df6acba29c..1706ba2c4c60b18d2368c1eef4e074dbc62a94ee 100644
--- a/src/db/sysdb_views.c
+++ b/src/db/sysdb_views.c
@@ -21,6 +21,7 @@
 
 #include "util/util.h"
 #include "util/cert.h"
+#include "db/sysdb_ldb_wrapper.h"
 #include "db/sysdb_private.h"
 
 /* In general is should not be possible that there is a view container without
@@ -163,7 +164,7 @@ errno_t sysdb_update_view_name(struct sysdb_ctx *sysdb,
     if (view_container_exists) {
         ret = ldb_modify(sysdb->ldb, msg);
     } else {
-        ret = ldb_add(sysdb->ldb, msg);
+        ret = sss_ldb_add(sysdb->ldb, msg);
     }
     if (ret != LDB_SUCCESS) {
         DEBUG(SSSDBG_FATAL_FAILURE,
@@ -568,7 +569,7 @@ errno_t sysdb_store_override(struct sss_domain_info *domain,
             goto done;
         }
 
-        ret = ldb_add(domain->sysdb->ldb, msg);
+        ret = sss_ldb_add(domain->sysdb->ldb, msg);
         if (ret != LDB_SUCCESS) {
             DEBUG(SSSDBG_CRIT_FAILURE,
                   "Failed to store override entry: %s(%d)[%s]\n",
-- 
2.7.4

