diff options
-rw-r--r-- | src/db/sysdb.h | 37 | ||||
-rw-r--r-- | src/db/sysdb_ops.c | 292 | ||||
-rw-r--r-- | src/providers/ipa/ipa_access.c | 102 | ||||
-rw-r--r-- | src/tests/sysdb-tests.c | 169 |
4 files changed, 229 insertions, 371 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h index baa989044..4955ee2ca 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -525,26 +525,23 @@ struct tevent_req *sysdb_store_custom_send(TALLOC_CTX *mem_ctx, struct sysdb_attrs *attrs); int sysdb_store_custom_recv(struct tevent_req *req); -struct tevent_req *sysdb_search_custom_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_ctx *sysdb, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *filter, - const char *subtree_name, - const char **attrs); -struct tevent_req *sysdb_search_custom_by_name_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_ctx *sysdb, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *object_name, - const char *subtree_name, - const char **attrs); -int sysdb_search_custom_recv(struct tevent_req *req, - TALLOC_CTX *mem_ctx, - size_t *msgs_count, - struct ldb_message ***msg); +int sysdb_search_custom(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct sss_domain_info *domain, + const char *filter, + const char *subtree_name, + const char **attrs, + size_t *msgs_count, + struct ldb_message ***msgs); + +int sysdb_search_custom_by_name(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct sss_domain_info *domain, + const char *object_name, + const char *subtree_name, + const char **attrs, + size_t *_count, + struct ldb_message ***_msgs); int sysdb_delete_custom(TALLOC_CTX *mem_ctx, struct sysdb_ctx *ctx, diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index 0ea22f1e7..4a980ab24 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -1543,196 +1543,95 @@ int sysdb_check_handle_recv(struct tevent_req *req, TALLOC_CTX *memctx, } /* =Custom Search================== */ -struct sysdb_search_custom_state { - struct tevent_context *ev; - struct sysdb_handle *handle; - - struct ldb_dn *basedn; - const char **attrs; - const char *filter; - int scope; - bool expect_not_more_than_one; - - size_t msgs_count; - struct ldb_message **msgs; -}; -static void sysdb_search_custom_check_handle_done(struct tevent_req *subreq); - -struct tevent_req *sysdb_search_custom_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_ctx *sysdb, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *filter, - const char *subtree_name, - const char **attrs) +int sysdb_search_custom(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct sss_domain_info *domain, + const char *filter, + const char *subtree_name, + const char **attrs, + size_t *msgs_count, + struct ldb_message ***msgs) { - struct tevent_req *req, *subreq; - struct sysdb_search_custom_state *state; + struct ldb_dn *basedn; int ret; - if (sysdb == NULL && handle == NULL) return NULL; - - if (filter == NULL || subtree_name == NULL) return NULL; - - req = tevent_req_create(mem_ctx, &state, struct sysdb_search_custom_state); - if (req == NULL) { - DEBUG(1, ("tevent_req_create failed.\n")); - return NULL; + if (filter == NULL || subtree_name == NULL) { + return EINVAL; } - state->ev = ev; - state->handle = handle; - state->attrs = attrs; - state->filter = filter; - state->scope = LDB_SCOPE_SUBTREE; - state->expect_not_more_than_one = false; - state->msgs_count = 0; - state->msgs = NULL; - - if (sysdb == NULL) { - sysdb = handle->ctx; - } - state->basedn = sysdb_custom_subtree_dn(sysdb, state, domain->name, - subtree_name); - if (state->basedn == NULL) { + basedn = sysdb_custom_subtree_dn(sysdb, mem_ctx, + domain->name, subtree_name); + if (basedn == NULL) { DEBUG(1, ("sysdb_custom_subtree_dn failed.\n")); - ret = ENOMEM; - goto fail; + return ENOMEM; } - if (!ldb_dn_validate(state->basedn)) { + if (!ldb_dn_validate(basedn)) { DEBUG(1, ("Failed to create DN.\n")); - ret = EINVAL; - goto fail; - } - - subreq = sysdb_check_handle_send(state, state->ev, sysdb, state->handle); - if (!subreq) { - DEBUG(1, ("sysdb_check_handle_send failed.\n")); - ret = ENOMEM; - goto fail; + return EINVAL; } - tevent_req_set_callback(subreq, sysdb_search_custom_check_handle_done, req); - - return req; -fail: - tevent_req_error(req, ret); - tevent_req_post(req, ev); - return req; + ret = sysdb_search_entry(mem_ctx, sysdb, basedn, + LDB_SCOPE_SUBTREE, filter, attrs, + msgs_count, msgs); + return ret; } -struct tevent_req *sysdb_search_custom_by_name_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_ctx *sysdb, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *object_name, - const char *subtree_name, - const char **attrs) +int sysdb_search_custom_by_name(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct sss_domain_info *domain, + const char *object_name, + const char *subtree_name, + const char **attrs, + size_t *_count, + struct ldb_message ***_msgs) { - struct tevent_req *req, *subreq; - struct sysdb_search_custom_state *state; + TALLOC_CTX *tmpctx; + struct ldb_dn *basedn; + struct ldb_message **msgs; + size_t count; int ret; - if (sysdb == NULL && handle == NULL) return NULL; - - if (object_name == NULL || subtree_name == NULL) return NULL; - - req = tevent_req_create(mem_ctx, &state, struct sysdb_search_custom_state); - if (req == NULL) { - DEBUG(1, ("tevent_req_create failed.\n")); - return NULL; + if (object_name == NULL || subtree_name == NULL) { + return EINVAL; } - state->ev = ev; - state->handle = handle; - state->attrs = attrs; - state->filter = NULL; - state->scope = LDB_SCOPE_BASE; - state->expect_not_more_than_one = true; - state->msgs_count = 0; - state->msgs = NULL; - - if (sysdb == NULL) { - sysdb = handle->ctx; + tmpctx = talloc_new(mem_ctx); + if (!tmpctx) { + return ENOMEM; } - state->basedn = sysdb_custom_dn(sysdb, state, domain->name, object_name, - subtree_name); - if (state->basedn == NULL) { + + basedn = sysdb_custom_dn(sysdb, tmpctx, + domain->name, object_name, subtree_name); + if (basedn == NULL) { DEBUG(1, ("sysdb_custom_dn failed.\n")); ret = ENOMEM; - goto fail; + goto done; } - if (!ldb_dn_validate(state->basedn)) { + if (!ldb_dn_validate(basedn)) { DEBUG(1, ("Failed to create DN.\n")); ret = EINVAL; - goto fail; - } - - subreq = sysdb_check_handle_send(state, state->ev, sysdb, state->handle); - if (!subreq) { - DEBUG(1, ("sysdb_check_handle_send failed.\n")); - ret = ENOMEM; - goto fail; - } - tevent_req_set_callback(subreq, sysdb_search_custom_check_handle_done, req); - - return req; - -fail: - tevent_req_error(req, ret); - tevent_req_post(req, ev); - return req; -} - -static void sysdb_search_custom_check_handle_done(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data(subreq, - struct tevent_req); - struct sysdb_search_custom_state *state = tevent_req_data(req, - struct sysdb_search_custom_state); - int ret; - - ret = sysdb_check_handle_recv(subreq, state, &state->handle); - talloc_zfree(subreq); - if (ret != EOK) { - tevent_req_error(req, ret); - return; + goto done; } - ret = sysdb_search_entry(state, state->handle->ctx, state->basedn, - state->scope, state->filter, state->attrs, - &state->msgs_count, &state->msgs); + ret = sysdb_search_entry(tmpctx, sysdb, basedn, + LDB_SCOPE_BASE, NULL, attrs, &count, &msgs); if (ret) { - tevent_req_error(req, ret); - return; + goto done; } - if (state->expect_not_more_than_one && state->msgs_count > 1) { + if (count > 1) { DEBUG(1, ("More than one result found.\n")); - tevent_req_error(req, EFAULT); - return; + ret = EFAULT; + goto done; } - tevent_req_done(req); -} - -int sysdb_search_custom_recv(struct tevent_req *req, - TALLOC_CTX *mem_ctx, - size_t *msgs_count, - struct ldb_message ***msgs) -{ - struct sysdb_search_custom_state *state = tevent_req_data(req, - struct sysdb_search_custom_state); - - TEVENT_REQ_RETURN_ON_ERROR(req); - - *msgs_count = state->msgs_count; - *msgs = talloc_move(mem_ctx, &state->msgs); + *_count = count; + *_msgs = talloc_move(mem_ctx, &msgs); - return EOK; +done: + talloc_zfree(tmpctx); + return ret; } @@ -1750,7 +1649,6 @@ struct sysdb_store_custom_state { struct ldb_message *msg; }; -static void sysdb_store_custom_check_done(struct tevent_req *subreq); static void sysdb_store_custom_done(struct tevent_req *subreq); struct tevent_req *sysdb_store_custom_send(TALLOC_CTX *mem_ctx, @@ -1765,6 +1663,13 @@ struct tevent_req *sysdb_store_custom_send(TALLOC_CTX *mem_ctx, struct sysdb_store_custom_state *state; int ret; const char **search_attrs; + int i; + size_t resp_count = 0; + struct ldb_message **resp; + struct ldb_message *msg; + struct ldb_request *ldbreq; + struct ldb_message_element *el; + bool add_object = false; if (object_name == NULL || subtree_name == NULL) return NULL; @@ -1803,47 +1708,14 @@ struct tevent_req *sysdb_store_custom_send(TALLOC_CTX *mem_ctx, search_attrs[0] = "*"; search_attrs[1] = NULL; - subreq = sysdb_search_custom_by_name_send(state, state->ev, NULL, - state->handle, - state->domain, - state->object_name, - state->subtree_name, - search_attrs); - if (!subreq) { - DEBUG(1, ("sysdb_search_custom_by_name_send failed.\n")); - ret = ENOMEM; - goto fail; - } - tevent_req_set_callback(subreq, sysdb_store_custom_check_done, req); - - return req; -fail: - DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - tevent_req_error(req, ret); - tevent_req_post(req, ev); - return req; -} - -static void sysdb_store_custom_check_done(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data(subreq, - struct tevent_req); - struct sysdb_store_custom_state *state = tevent_req_data(req, - struct sysdb_store_custom_state); - int ret; - int i; - size_t resp_count = 0; - struct ldb_message **resp; - struct ldb_message *msg; - struct ldb_request *ldbreq; - struct ldb_message_element *el; - bool add_object = false; - - ret = sysdb_search_custom_recv(subreq, state, &resp_count, &resp); - talloc_zfree(subreq); + ret = sysdb_search_custom_by_name(state, state->handle->ctx, + state->domain, + state->object_name, + state->subtree_name, + search_attrs, + &resp_count, &resp); if (ret != EOK && ret != ENOENT) { - tevent_req_error(req, ret); - return; + goto fail; } if (ret == ENOENT) { @@ -1852,8 +1724,8 @@ static void sysdb_store_custom_check_done(struct tevent_req *subreq) msg = ldb_msg_new(state); if (msg == NULL) { - tevent_req_error(req, ENOMEM); - return; + ret = ENOMEM; + goto fail; } msg->dn = state->dn; @@ -1861,8 +1733,8 @@ static void sysdb_store_custom_check_done(struct tevent_req *subreq) msg->elements = talloc_array(msg, struct ldb_message_element, state->attrs->num); if (!msg->elements) { - tevent_req_error(req, ENOMEM); - return; + ret = ENOMEM; + goto fail; } for (i = 0; i < state->attrs->num; i++) { @@ -1891,18 +1763,24 @@ static void sysdb_store_custom_check_done(struct tevent_req *subreq) DEBUG(1, ("Failed to build request: %s(%d)[%s]\n", ldb_strerror(ret), ret, ldb_errstring(state->handle->ctx->ldb))); - tevent_req_error(req, sysdb_error_to_errno(ret)); - return; + ret = sysdb_error_to_errno(ret); + goto fail; } subreq = sldb_request_send(state, state->ev, state->handle->ctx->ldb, ldbreq); if (!subreq) { - tevent_req_error(req, ENOMEM); - return; + ret = ENOMEM; + goto fail; } tevent_req_set_callback(subreq, sysdb_store_custom_done, req); - return; + + return req; +fail: + DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); + tevent_req_error(req, ret); + tevent_req_post(req, ev); + return req; } static void sysdb_store_custom_done(struct tevent_req *subreq) diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c index 1ea77b202..cd062095b 100644 --- a/src/providers/ipa/ipa_access.c +++ b/src/providers/ipa/ipa_access.c @@ -283,6 +283,8 @@ struct hbac_get_host_info_state { }; static void hbac_get_host_info_connect_done(struct tevent_req *subreq); +static void hbac_get_host_memberof(struct tevent_req *req, + struct ldb_message **msgs); static void hbac_get_host_memberof_done(struct tevent_req *subreq); static void hbac_get_host_info_sysdb_transaction_started(struct tevent_req *subreq); static void hbac_get_host_info_store_prepare(struct tevent_req *req); @@ -369,18 +371,19 @@ static struct tevent_req *hbac_get_host_info_send(TALLOC_CTX *memctx, state->host_attrs[6] = NULL; if (offline) { - subreq = sysdb_search_custom_send(state, state->ev, state->sysdb, NULL, - state->sdap_ctx->be->domain, - state->host_filter, HBAC_HOSTS_SUBDIR, - state->host_attrs); - if (subreq == NULL) { - DEBUG(1, ("sysdb_search_custom_send.\n")); - ret = ENOMEM; + struct ldb_message **msgs; + + ret = sysdb_search_custom(state, state->sysdb, + state->sdap_ctx->be->domain, + state->host_filter, HBAC_HOSTS_SUBDIR, + state->host_attrs, + &state->host_reply_count, &msgs); + if (ret) { + DEBUG(1, ("sysdb_search_custom failed.\n")); goto fail; } - - tevent_req_set_callback(subreq, hbac_get_host_memberof_done, req); - + hbac_get_host_memberof(req, msgs); + tevent_req_post(req, ev); return req; } @@ -474,25 +477,31 @@ static void hbac_get_host_memberof_done(struct tevent_req *subreq) struct hbac_get_host_info_state *state = tevent_req_data(req, 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; - if (state->offline) { - ret = sysdb_search_custom_recv(subreq, state, &state->host_reply_count, - &msgs); - } else { - ret = sdap_get_generic_recv(subreq, state, &state->host_reply_count, - &state->host_reply_list); - } + ret = sdap_get_generic_recv(subreq, state, + &state->host_reply_count, + &state->host_reply_list); talloc_zfree(subreq); if (ret != EOK) { tevent_req_error(req, ret); return; } + hbac_get_host_memberof(req, NULL); +} + +static void hbac_get_host_memberof(struct tevent_req *req, + struct ldb_message **msgs) +{ + struct hbac_get_host_info_state *state = + tevent_req_data(req, struct hbac_get_host_info_state); + struct tevent_req *subreq; + int ret; + int i; + int v; + struct ldb_message_element *el; + struct hbac_host_info **hhi; + if (state->host_reply_count == 0) { DEBUG(1, ("No hosts not found in IPA server.\n")); ret = ENOENT; @@ -774,6 +783,8 @@ struct hbac_get_rules_state { }; static void hbac_get_rules_connect_done(struct tevent_req *subreq); +static void hbac_rule_get(struct tevent_req *req, + struct ldb_message **msgs); static void hbac_rule_get_done(struct tevent_req *subreq); static void hbac_rule_sysdb_transaction_started(struct tevent_req *subreq); static void hbac_rule_store_prepare(struct tevent_req *req); @@ -877,18 +888,19 @@ static struct tevent_req *hbac_get_rules_send(TALLOC_CTX *memctx, DEBUG(9, ("HBAC rule filter: [%s].\n", state->hbac_filter)); if (offline) { - subreq = sysdb_search_custom_send(state, state->ev, state->sysdb, NULL, - state->sdap_ctx->be->domain, - state->hbac_filter, HBAC_RULES_SUBDIR, - state->hbac_attrs); - if (subreq == NULL) { - DEBUG(1, ("sysdb_search_custom_send failed.\n")); - ret = ENOMEM; + struct ldb_message **msgs; + + ret = sysdb_search_custom(state, state->sysdb, + state->sdap_ctx->be->domain, + state->hbac_filter, HBAC_RULES_SUBDIR, + state->hbac_attrs, + &state->hbac_reply_count, &msgs); + if (ret) { + DEBUG(1, ("sysdb_search_custom failed.\n")); goto fail; } - - tevent_req_set_callback(subreq, hbac_rule_get_done, req); - + hbac_rule_get(req, msgs); + tevent_req_post(req, ev); return req; } @@ -981,23 +993,29 @@ static void hbac_rule_get_done(struct tevent_req *subreq) struct hbac_get_rules_state *state = tevent_req_data(req, struct hbac_get_rules_state); int ret; - int i; - struct ldb_message_element *el; - struct ldb_message **msgs; - if (state->offline) { - ret = sysdb_search_custom_recv(subreq, state, &state->hbac_reply_count, - &msgs); - } else { - ret = sdap_get_generic_recv(subreq, state, &state->hbac_reply_count, - &state->hbac_reply_list); - } + ret = sdap_get_generic_recv(subreq, state, + &state->hbac_reply_count, + &state->hbac_reply_list); talloc_zfree(subreq); if (ret != EOK) { tevent_req_error(req, ret); return; } + hbac_rule_get(req, NULL); +} + +static void hbac_rule_get(struct tevent_req *req, + struct ldb_message **msgs) +{ + struct hbac_get_rules_state *state = + tevent_req_data(req, struct hbac_get_rules_state); + struct tevent_req *subreq; + int ret; + int i; + struct ldb_message_element *el; + if (state->offline) { ret = msgs2attrs_array(state, state->hbac_reply_count, msgs, &state->hbac_reply_list); diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index d1abf82c9..d5ca6e41f 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -1751,7 +1751,6 @@ START_TEST (test_sysdb_search_custom_by_name) { struct sysdb_test_ctx *test_ctx; struct test_data *data; - struct tevent_req *subreq; int ret; char *object_name; @@ -1774,43 +1773,31 @@ START_TEST (test_sysdb_search_custom_by_name) object_name = talloc_asprintf(data, "%s_%d", CUSTOM_TEST_OBJECT, 29010); fail_unless(object_name != NULL, "talloc_asprintf failed"); - subreq = sysdb_search_custom_by_name_send(data, data->ev, - data->ctx->sysdb, NULL, - data->ctx->domain, - object_name, - CUSTOM_TEST_CONTAINER, - data->attrlist); - if (!subreq) { - ret = ENOMEM; - } - - if (ret == EOK) { - tevent_req_set_callback(subreq, test_search_done, data); + ret = sysdb_search_custom_by_name(data, data->ctx->sysdb, + data->ctx->domain, + object_name, + CUSTOM_TEST_CONTAINER, + data->attrlist, + &data->msgs_count, + &data->msgs); - ret = test_loop(data); - - ret = sysdb_search_custom_recv(subreq, data, &data->msgs_count, - &data->msgs); - talloc_zfree(subreq); - fail_unless(ret == EOK, "sysdb_search_custom_by_name_send failed"); + fail_if(ret != EOK, "Could not search custom object"); - fail_unless(data->msgs_count == 1, - "Wrong number of objects, exptected [1] got [%d]", - data->msgs_count); - fail_unless(data->msgs[0]->num_elements == 1, - "Wrong number of results, expected [1] got [%d]", - data->msgs[0]->num_elements); - fail_unless(strcmp(data->msgs[0]->elements[0].name, TEST_ATTR_NAME) == 0, - "Wrong attribute name"); - fail_unless(data->msgs[0]->elements[0].num_values == 1, - "Wrong number of attribute values"); - fail_unless(strncmp((const char *)data->msgs[0]->elements[0].values[0].data, - TEST_ATTR_VALUE, - data->msgs[0]->elements[0].values[0].length) == 0, - "Wrong attribute value"); - } + fail_unless(data->msgs_count == 1, + "Wrong number of objects, exptected [1] got [%d]", + data->msgs_count); + fail_unless(data->msgs[0]->num_elements == 1, + "Wrong number of results, expected [1] got [%d]", + data->msgs[0]->num_elements); + fail_unless(strcmp(data->msgs[0]->elements[0].name, TEST_ATTR_NAME) == 0, + "Wrong attribute name"); + fail_unless(data->msgs[0]->elements[0].num_values == 1, + "Wrong number of attribute values"); + fail_unless(strncmp((const char *)data->msgs[0]->elements[0].values[0].data, + TEST_ATTR_VALUE, + data->msgs[0]->elements[0].values[0].length) == 0, + "Wrong attribute value"); - fail_if(ret != EOK, "Could not search custom object"); talloc_free(test_ctx); } END_TEST @@ -1875,7 +1862,6 @@ START_TEST (test_sysdb_search_custom_update) { struct sysdb_test_ctx *test_ctx; struct test_data *data; - struct tevent_req *subreq; int ret; char *object_name; struct ldb_message_element *el; @@ -1900,52 +1886,44 @@ START_TEST (test_sysdb_search_custom_update) object_name = talloc_asprintf(data, "%s_%d", CUSTOM_TEST_OBJECT, 29010); fail_unless(object_name != NULL, "talloc_asprintf failed"); - subreq = sysdb_search_custom_by_name_send(data, data->ev, - data->ctx->sysdb, NULL, - data->ctx->domain, - object_name, - CUSTOM_TEST_CONTAINER, - data->attrlist); - if (!subreq) { - ret = ENOMEM; - } - - if (ret == EOK) { - tevent_req_set_callback(subreq, test_search_done, data); - - ret = test_loop(data); - - ret = sysdb_search_custom_recv(subreq, data, &data->msgs_count, - &data->msgs); - talloc_zfree(subreq); - fail_unless(ret == EOK, "sysdb_search_custom_by_name_send failed"); + ret = sysdb_search_custom_by_name(data, data->ctx->sysdb, + data->ctx->domain, + object_name, + CUSTOM_TEST_CONTAINER, + data->attrlist, + &data->msgs_count, + &data->msgs); - fail_unless(data->msgs_count == 1, - "Wrong number of objects, exptected [1] got [%d]", - data->msgs_count); - fail_unless(data->msgs[0]->num_elements == 2, - "Wrong number of results, expected [2] got [%d]", - data->msgs[0]->num_elements); + fail_if(ret != EOK, "Could not search custom object"); - el = ldb_msg_find_element(data->msgs[0], TEST_ATTR_NAME); - fail_unless(el != NULL, "Attribute [%s] not found", TEST_ATTR_NAME); - fail_unless(el->num_values == 1, "Wrong number ([%d] instead of 1) " - "of attribute values for [%s]", el->num_values, TEST_ATTR_NAME); - fail_unless(strncmp((const char *) el->values[0].data, TEST_ATTR_UPDATE_VALUE, - el->values[0].length) == 0, - "Wrong attribute value"); + fail_unless(data->msgs_count == 1, + "Wrong number of objects, exptected [1] got [%d]", + data->msgs_count); + fail_unless(data->msgs[0]->num_elements == 2, + "Wrong number of results, expected [2] got [%d]", + data->msgs[0]->num_elements); + + el = ldb_msg_find_element(data->msgs[0], TEST_ATTR_NAME); + fail_unless(el != NULL, "Attribute [%s] not found", TEST_ATTR_NAME); + fail_unless(el->num_values == 1, "Wrong number ([%d] instead of 1) " + "of attribute values for [%s]", el->num_values, + TEST_ATTR_NAME); + fail_unless(strncmp((const char *) el->values[0].data, + TEST_ATTR_UPDATE_VALUE, + el->values[0].length) == 0, + "Wrong attribute value"); + + el = ldb_msg_find_element(data->msgs[0], TEST_ATTR_ADD_NAME); + fail_unless(el != NULL, "Attribute [%s] not found", TEST_ATTR_ADD_NAME); + fail_unless(el->num_values == 1, "Wrong number ([%d] instead of 1) " + "of attribute values for [%s]", el->num_values, + TEST_ATTR_ADD_NAME); + fail_unless(strncmp((const char *) el->values[0].data, + TEST_ATTR_ADD_VALUE, + el->values[0].length) == 0, + "Wrong attribute value"); - el = ldb_msg_find_element(data->msgs[0], TEST_ATTR_ADD_NAME); - fail_unless(el != NULL, "Attribute [%s] not found", TEST_ATTR_ADD_NAME); - fail_unless(el->num_values == 1, "Wrong number ([%d] instead of 1) " - "of attribute values for [%s]", el->num_values, TEST_ATTR_ADD_NAME); - fail_unless(strncmp((const char *) el->values[0].data, TEST_ATTR_ADD_VALUE, - el->values[0].length) == 0, - "Wrong attribute value"); - } - - fail_if(ret != EOK, "Could not search custom object"); talloc_free(test_ctx); } END_TEST @@ -1954,7 +1932,6 @@ START_TEST (test_sysdb_search_custom) { struct sysdb_test_ctx *test_ctx; struct test_data *data; - struct tevent_req *subreq; int ret; const char *filter = "(distinguishedName=*)"; @@ -1975,32 +1952,20 @@ START_TEST (test_sysdb_search_custom) data->attrlist[1] = TEST_ATTR_ADD_NAME; data->attrlist[2] = NULL; - subreq = sysdb_search_custom_send(data, data->ev, - data->ctx->sysdb, NULL, - data->ctx->domain, - filter, - CUSTOM_TEST_CONTAINER, - data->attrlist); - if (!subreq) { - ret = ENOMEM; - } - - if (ret == EOK) { - tevent_req_set_callback(subreq, test_search_done, data); - - ret = test_loop(data); + ret = sysdb_search_custom(data, data->ctx->sysdb, + data->ctx->domain, + filter, + CUSTOM_TEST_CONTAINER, + data->attrlist, + &data->msgs_count, + &data->msgs); - ret = sysdb_search_custom_recv(subreq, data, &data->msgs_count, - &data->msgs); - talloc_zfree(subreq); - fail_unless(ret == EOK, "sysdb_search_custom_send failed"); + fail_if(ret != EOK, "Could not search custom object"); - fail_unless(data->msgs_count == 10, - "Wrong number of objects, exptected [10] got [%d]", - data->msgs_count); - } + fail_unless(data->msgs_count == 10, + "Wrong number of objects, exptected [10] got [%d]", + data->msgs_count); - fail_if(ret != EOK, "Could not search custom object"); talloc_free(test_ctx); } END_TEST |