[SSSD] [PATCH] Add sysdb_attrs_get_string_array()

Sumit Bose sbose at redhat.com
Fri May 28 13:12:53 UTC 2010


Hi,

there is a change in libldb of f13 which makes the IPA access provider
fail if there a no memberof attributes in a host entry. I think this is
also the reason for #499. The first patch adds a new sysdb_attrs call
which does not create an empty element and the second patch add this
call to the IPA access provider.

For your convenience I have add patches against 1.2 and master.

bye,
Sumit
-------------- next part --------------
From 90c521f7050953a365532f622cd81385f7dcc229 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Fri, 28 May 2010 14:28:06 +0200
Subject: [PATCH 1/2] Add sysdb_attrs_get_string_array()

---
 src/db/sysdb.c |   33 +++++++++++++++++++++++++++++++++
 src/db/sysdb.h |    2 ++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 21e69c0..41e1756 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -140,6 +140,39 @@ int sysdb_attrs_get_string(struct sysdb_attrs *attrs, const char *name,
     return EOK;
 }
 
+int sysdb_attrs_get_string_array(struct sysdb_attrs *attrs, const char *name,
+                                 TALLOC_CTX *mem_ctx, const char ***string)
+{
+    struct ldb_message_element *el;
+    int ret;
+    unsigned int u;
+    const char **a;
+
+    ret = sysdb_attrs_get_el_int(attrs, name, false, &el);
+    if (ret) {
+        return ret;
+    }
+
+    a = talloc_array(mem_ctx, const char *, el->num_values + 1);
+    if (a == NULL) {
+        return ENOMEM;
+    }
+
+    memset(a, 0, sizeof(const char *) * (el->num_values + 1));
+
+    for(u = 0; u < el->num_values; u++) {
+        a[u] = talloc_strndup(a, (const char *)el->values[u].data,
+                              el->values[u].length);
+        if (a[u] == NULL) {
+            talloc_free(a);
+            return ENOMEM;
+        }
+    }
+
+    *string = a;
+    return EOK;
+}
+
 int sysdb_attrs_add_val(struct sysdb_attrs *attrs,
                         const char *name, const struct ldb_val *val)
 {
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index fcdb90e..50427d6 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -176,6 +176,8 @@ int sysdb_attrs_steal_string(struct sysdb_attrs *attrs,
                              const char *name, char *str);
 int sysdb_attrs_get_string(struct sysdb_attrs *attrs, const char *name,
                            const char **string);
+int sysdb_attrs_get_string_array(struct sysdb_attrs *attrs, const char *name,
+                                 TALLOC_CTX *mem_ctx, const char ***string);
 
 int sysdb_attrs_replace_name(struct sysdb_attrs *attrs, const char *oldname,
                                  const char *newname);
-- 
1.7.0.1

-------------- next part --------------
From ddd4a62bd502ab8c931d02ddb40231dcbe69f119 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Fri, 28 May 2010 14:29:15 +0200
Subject: [PATCH 2/2] Use sysdb_attrs_get_string_array() instead of sysdb_attrs_get_el()

sysdb_attrs_get_el() creates an empty element in the sysdb_attrs
structure if the requested element does not exist. Recent versions of
libldb do not accept empty elements when writing new objects to disk.
sysdb_attrs_get_string_array() does not create an empty element but
returns ENOENT.
---
 src/providers/ipa/ipa_access.c |   35 ++++++++++++-----------------------
 1 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c
index 9d639e6..a4dc531 100644
--- a/src/providers/ipa/ipa_access.c
+++ b/src/providers/ipa/ipa_access.c
@@ -1180,7 +1180,6 @@ static void hbac_get_host_memberof_done(struct tevent_req *subreq)
                                                struct hbac_get_host_info_state);
     int ret;
     int i;
-    int v;
     struct ldb_message_element *el;
     struct hbac_host_info **hhi;
     struct ldb_message **msgs;
@@ -1286,33 +1285,23 @@ static void hbac_get_host_memberof_done(struct tevent_req *subreq)
             goto fail;
         }
 
-        ret = sysdb_attrs_get_el(state->host_reply_list[i],
-                                 state->offline ? SYSDB_ORIG_MEMBEROF :
-                                                  IPA_MEMBEROF,
-                                 &el);
+        ret = sysdb_attrs_get_string_array(state->host_reply_list[i],
+                                          state->offline ? SYSDB_ORIG_MEMBEROF :
+                                                           IPA_MEMBEROF,
+                                          hhi, &(hhi[i]->memberof));
         if (ret != EOK) {
-            DEBUG(1, ("sysdb_attrs_get_el failed.\n"));
-            goto fail;
-        }
-
-        hhi[i]->memberof = talloc_array(hhi, const char *, el->num_values + 1);
-        if (hhi[i]->memberof == NULL) {
-            ret = ENOMEM;
-            goto fail;
-        }
-        memset(hhi[i]->memberof, 0,
-               sizeof(const char *) * (el->num_values + 1));
+            if (ret != ENOENT) {
+                DEBUG(1, ("sysdb_attrs_get_string_array failed.\n"));
+                goto fail;
+            }
 
-        for(v = 0; v < el->num_values; v++) {
-            DEBUG(9, ("%s: [%.*s].\n", IPA_MEMBEROF, el->values[v].length,
-                                     (const char *)el->values[v].data));
-            hhi[i]->memberof[v] = talloc_strndup(hhi,
-                                               (const char *)el->values[v].data,
-                                               el->values[v].length);
-            if (hhi[i]->memberof[v] == NULL) {
+            hhi[i]->memberof = talloc_array(hhi, const char *, 1);
+            if (hhi[i]->memberof == NULL) {
+                DEBUG(1, ("talloc_array failed.\n"));
                 ret = ENOMEM;
                 goto fail;
             }
+            hhi[i]->memberof[0] = NULL;
         }
     }
 
-- 
1.7.0.1

-------------- next part --------------
From 898942572925cb5da64e79d70c48dddd9771a6d8 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Fri, 28 May 2010 14:28:06 +0200
Subject: [PATCH 1/2] Add sysdb_attrs_get_string_array()

---
 src/db/sysdb.c |   33 +++++++++++++++++++++++++++++++++
 src/db/sysdb.h |    2 ++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index bfad77d..f784e73 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -130,6 +130,39 @@ int sysdb_attrs_get_string(struct sysdb_attrs *attrs, const char *name,
     return EOK;
 }
 
+int sysdb_attrs_get_string_array(struct sysdb_attrs *attrs, const char *name,
+                                 TALLOC_CTX *mem_ctx, const char ***string)
+{
+    struct ldb_message_element *el;
+    int ret;
+    unsigned int u;
+    const char **a;
+
+    ret = sysdb_attrs_get_el_int(attrs, name, false, &el);
+    if (ret) {
+        return ret;
+    }
+
+    a = talloc_array(mem_ctx, const char *, el->num_values + 1);
+    if (a == NULL) {
+        return ENOMEM;
+    }
+
+    memset(a, 0, sizeof(const char *) * (el->num_values + 1));
+
+    for(u = 0; u < el->num_values; u++) {
+        a[u] = talloc_strndup(a, (const char *)el->values[u].data,
+                              el->values[u].length);
+        if (a[u] == NULL) {
+            talloc_free(a);
+            return ENOMEM;
+        }
+    }
+
+    *string = a;
+    return EOK;
+}
+
 int sysdb_attrs_add_val(struct sysdb_attrs *attrs,
                         const char *name, const struct ldb_val *val)
 {
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index a5413a2..5411945 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -175,6 +175,8 @@ int sysdb_attrs_steal_string(struct sysdb_attrs *attrs,
                              const char *name, char *str);
 int sysdb_attrs_get_string(struct sysdb_attrs *attrs, const char *name,
                            const char **string);
+int sysdb_attrs_get_string_array(struct sysdb_attrs *attrs, const char *name,
+                                 TALLOC_CTX *mem_ctx, const char ***string);
 
 int sysdb_attrs_replace_name(struct sysdb_attrs *attrs, const char *oldname,
                                  const char *newname);
-- 
1.7.0.1

-------------- next part --------------
From 41575a7f6ea9c889b0ce627a38211d33fd68c0ac Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Fri, 28 May 2010 14:29:15 +0200
Subject: [PATCH 2/2] Use sysdb_attrs_get_string_array() instead of sysdb_attrs_get_el()

sysdb_attrs_get_el() creates an empty element in the sysdb_attrs
structure if the requested element does not exist. Recent versions of
libldb do not accept empty elements when writing new objects to disk.
sysdb_attrs_get_string_array() does not create an empty element but
returns ENOENT.
---
 src/providers/ipa/ipa_access.c |   35 ++++++++++++-----------------------
 1 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c
index 590ae78..56bb269 100644
--- a/src/providers/ipa/ipa_access.c
+++ b/src/providers/ipa/ipa_access.c
@@ -431,7 +431,6 @@ static void hbac_get_host_memberof(struct tevent_req *req,
     bool in_transaction = false;
     int ret;
     int i;
-    int v;
     struct ldb_message_element *el;
     struct hbac_host_info **hhi;
     char *object_name;
@@ -524,33 +523,23 @@ static void hbac_get_host_memberof(struct tevent_req *req,
             goto fail;
         }
 
-        ret = sysdb_attrs_get_el(state->host_reply_list[i],
-                                 state->offline ? SYSDB_ORIG_MEMBEROF :
-                                                  IPA_HOST_MEMBEROF,
-                                 &el);
+        ret = sysdb_attrs_get_string_array(state->host_reply_list[i],
+                                          state->offline ? SYSDB_ORIG_MEMBEROF :
+                                                           IPA_MEMBEROF,
+                                          hhi, &(hhi[i]->memberof));
         if (ret != EOK) {
-            DEBUG(1, ("sysdb_attrs_get_el failed.\n"));
-            goto fail;
-        }
+            if (ret != ENOENT) {
+                DEBUG(1, ("sysdb_attrs_get_string_array failed.\n"));
+                goto fail;
+            }
 
-        hhi[i]->memberof = talloc_array(hhi, const char *, el->num_values + 1);
-        if (hhi[i]->memberof == NULL) {
-            ret = ENOMEM;
-            goto fail;
-        }
-        memset(hhi[i]->memberof, 0,
-               sizeof(const char *) * (el->num_values + 1));
-
-        for(v = 0; v < el->num_values; v++) {
-            DEBUG(9, ("%s: [%.*s].\n", IPA_HOST_MEMBEROF, el->values[v].length,
-                                     (const char *)el->values[v].data));
-            hhi[i]->memberof[v] = talloc_strndup(hhi,
-                                               (const char *)el->values[v].data,
-                                               el->values[v].length);
-            if (hhi[i]->memberof[v] == NULL) {
+            hhi[i]->memberof = talloc_array(hhi, const char *, 1);
+            if (hhi[i]->memberof == NULL) {
+                DEBUG(1, ("talloc_array failed.\n"));
                 ret = ENOMEM;
                 goto fail;
             }
+            hhi[i]->memberof[0] = NULL;
         }
     }
 
-- 
1.7.0.1



More information about the sssd-devel mailing list