From 41575a7f6ea9c889b0ce627a38211d33fd68c0ac Mon Sep 17 00:00:00 2001 From: Sumit Bose 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