From ddd4a62bd502ab8c931d02ddb40231dcbe69f119 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 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