>From 127b27aa33b2eaab7f3f856f276d1e8128de7d37 Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Wed, 19 Feb 2014 17:34:05 +0000
Subject: [PATCH] SDAP: augmented logging for group saving

Resolves:
https://fedorahosted.org/sssd/ticket/2239
---
 src/db/sysdb_ops.c                     |  3 +++
 src/providers/ldap/sdap_async_groups.c | 22 +++++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index a5dfd443c84b87609881f9042b3e82958c3b0e5f..95354d98806a13cf142705dc304b7810b8ee82f4 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1926,6 +1926,9 @@ int sysdb_store_group(struct sysdb_ctx *sysdb,
     ret = sysdb_search_group_by_name(tmp_ctx, sysdb, domain,
                                      name, src_attrs, &msg);
     if (ret && ret != ENOENT) {
+        DEBUG(SSSDBG_MINOR_FAILURE,
+              ("sysdb_search_group_by_name failed for %s with: [%d][%s].\n",
+               name, ret, strerror(ret)));
         goto done;
     }
     if (ret == ENOENT) {
diff --git a/src/providers/ldap/sdap_async_groups.c b/src/providers/ldap/sdap_async_groups.c
index ab3691f80aaecca988dcbf0877491a37af3ae49b..129fb3e6cfc31ea0b2b757e3378b1bbd37bbdba2 100644
--- a/src/providers/ldap/sdap_async_groups.c
+++ b/src/providers/ldap/sdap_async_groups.c
@@ -198,6 +198,7 @@ static int sdap_fill_memberships(struct sdap_options *opts,
 
     ret = sysdb_attrs_get_el(group_attrs, SYSDB_MEMBER, &el);
     if (ret) {
+        DEBUG(SSSDBG_MINOR_FAILURE, ("sysdb_attrs_get_el failed\n"));
         goto done;
     }
 
@@ -205,6 +206,7 @@ static int sdap_fill_memberships(struct sdap_options *opts,
     el->values = talloc_realloc(group_attrs, el->values, struct ldb_val,
                                 el->num_values + num_values + nuserdns);
     if (!el->values) {
+        DEBUG(SSSDBG_MINOR_FAILURE, ("No memory to allocate group attrs\n"));
         ret = ENOMEM;
         goto done;
     }
@@ -243,6 +245,9 @@ static int sdap_fill_memberships(struct sdap_options *opts,
                 continue;
             }
             if (ret != EOK) {
+                DEBUG(SSSDBG_MINOR_FAILURE,
+                      ("'sdap_find_entry_by_origDN' failed for member [%s] ",
+                      (char *)values[i].data));
                 goto done;
             }
 
@@ -253,6 +258,8 @@ static int sdap_fill_memberships(struct sdap_options *opts,
             el->values[j].length = strlen((char *)el->values[j].data);
             j++;
         } else if (hret != HASH_SUCCESS) {
+            DEBUG(SSSDBG_MINOR_FAILURE,
+                  ("hash_lookup failed: [%d]: %s\n", hret, strerror(hret)));
             ret = EFAULT;
             goto done;
         }
@@ -755,6 +762,9 @@ static int sdap_save_grpmem(TALLOC_CTX *memctx,
         ret = sdap_dn_by_primary_gid(memctx, attrs, ctx, dom, opts,
                                      &userdns, &nuserdns);
         if (ret != EOK) {
+            DEBUG(SSSDBG_MINOR_FAILURE,
+                  ("sdap_dn_by_primary_gid failed: [%d][%s].\n",
+                   ret, strerror(ret)));
             goto fail;
         }
     }
@@ -762,6 +772,8 @@ static int sdap_save_grpmem(TALLOC_CTX *memctx,
     ret = sysdb_attrs_get_el(attrs,
                     opts->group_map[SDAP_AT_GROUP_MEMBER].sys_name, &el);
     if (ret != EOK) {
+        DEBUG(SSSDBG_MINOR_FAILURE, ("sysdb_attrs_get_el failed: [%d][%s].\n",
+                                     ret, strerror(ret)));
         goto fail;
     }
 
@@ -774,6 +786,7 @@ static int sdap_save_grpmem(TALLOC_CTX *memctx,
 
         group_attrs = sysdb_new_attrs(memctx);
         if (!group_attrs) {
+            DEBUG(SSSDBG_MINOR_FAILURE, ("sysdb_new_attrs failed\n"));
             ret = ENOMEM;
             goto fail;
         }
@@ -782,13 +795,20 @@ static int sdap_save_grpmem(TALLOC_CTX *memctx,
                                     el->values, el->num_values,
                                     userdns, nuserdns);
         if (ret) {
+            DEBUG(SSSDBG_CRIT_FAILURE,
+                  ("sdap_fill_memberships failed with [%d]: %s\n", ret,
+                   strerror(ret)));
             goto fail;
         }
     }
 
     ret = sysdb_store_group(ctx, dom, group_name, 0, group_attrs,
                             dom->group_timeout, now);
-    if (ret) goto fail;
+    if (ret) {
+        DEBUG(SSSDBG_MINOR_FAILURE, ("sysdb_store_group failed: [%d][%s].\n",
+                                     ret, strerror(ret)));
+        goto fail;
+    }
 
     return EOK;
 
-- 
1.8.4.2

