diff options
author | Sumit Bose <sbose@redhat.com> | 2012-11-26 12:33:11 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-01-08 14:42:56 +0100 |
commit | 12bfb1b3c9683ccc9972749772a6e6be495c0769 (patch) | |
tree | 3a39c3acfce04fff47b4d4a01a65bae3a8206f27 /src | |
parent | 8d371b14623e1dced3ddc885ff7d8cd2cbf50604 (diff) | |
download | sssd-12bfb1b3c9683ccc9972749772a6e6be495c0769.tar.gz sssd-12bfb1b3c9683ccc9972749772a6e6be495c0769.tar.bz2 sssd-12bfb1b3c9683ccc9972749772a6e6be495c0769.zip |
Add find_domain_by_id()
Currently domains can only be searched by name in the global domain
list. To make it easier to find the domain for a given SID
find_domain_by_id() which returns a pointer to the domain or subdomain
entry in the global domain list if a matching id was found.
Diffstat (limited to 'src')
-rw-r--r-- | src/responder/pac/pacsrv.h | 3 | ||||
-rw-r--r-- | src/responder/pac/pacsrv_utils.c | 39 | ||||
-rw-r--r-- | src/tests/pac_responder-tests.c | 49 |
3 files changed, 91 insertions, 0 deletions
diff --git a/src/responder/pac/pacsrv.h b/src/responder/pac/pacsrv.h index 8cd49284..4d3a3164 100644 --- a/src/responder/pac/pacsrv.h +++ b/src/responder/pac/pacsrv.h @@ -125,4 +125,7 @@ errno_t diff_gid_lists(TALLOC_CTX *mem_ctx, struct pac_grp **_add_gid_list, size_t *_del_gid_num, struct grp_info ***_del_gid_list); + +struct sss_domain_info *find_domain_by_id(struct sss_domain_info *domains, + const char *id_str); #endif /* __PACSRV_H__ */ diff --git a/src/responder/pac/pacsrv_utils.c b/src/responder/pac/pacsrv_utils.c index 6e0f4bfa..d79adb1f 100644 --- a/src/responder/pac/pacsrv_utils.c +++ b/src/responder/pac/pacsrv_utils.c @@ -71,6 +71,45 @@ errno_t local_sid_to_id(struct local_mapping_ranges *map, struct dom_sid *sid, return EOK; } +struct sss_domain_info *find_domain_by_id(struct sss_domain_info *domains, + const char *id_str) +{ + struct sss_domain_info *dom; + struct sss_domain_info *ret_dom = NULL; + size_t c; + + if (id_str == NULL) { + DEBUG(SSSDBG_OP_FAILURE, ("Missing domain id.\n")); + return NULL; + } + + for (dom = domains; dom; dom = dom->next) { + if (dom->domain_id == NULL) { + continue; + } + + if (strcasecmp(dom->domain_id, id_str) == 0) { + ret_dom = dom; + break; + } + + for (c = 0; c < dom->subdomain_count; c++) { + if (strcasecmp(dom->subdomains[c]->domain_id, id_str) == 0) { + ret_dom = dom->subdomains[c]; + break; + } + } + + } + + if (!ret_dom) { + DEBUG(SSSDBG_OP_FAILURE, ("No domain with domain ID [%s] found", + id_str)); + } + + return ret_dom; +} + /** * Add a new remote domain and the corresponding ID range to the context of * the libsss_idmap. Without this it is not possible to find the Posix UID for diff --git a/src/tests/pac_responder-tests.c b/src/tests/pac_responder-tests.c index 11870ce4..81cee3c1 100644 --- a/src/tests/pac_responder-tests.c +++ b/src/tests/pac_responder-tests.c @@ -177,6 +177,54 @@ START_TEST(pac_test_get_gids_to_add_and_remove) } END_TEST +#define NUM_DOMAINS 10 +START_TEST(pac_test_find_domain_by_id) +{ + struct sss_domain_info *dom; + struct sss_domain_info **domains; + size_t c; + char *id; + + dom = find_domain_by_id(NULL, NULL); + fail_unless(dom == NULL, "Domain returned without any input."); + + dom = find_domain_by_id(NULL, "id"); + fail_unless(dom == NULL, "Domain returned without domain list."); + + domains = talloc_zero_array(global_talloc_context, struct sss_domain_info *, + NUM_DOMAINS); + for (c = 0; c < NUM_DOMAINS; c++) { + domains[c] = talloc_zero(domains, struct sss_domain_info); + fail_unless(domains[c] != NULL, "talloc_zero failed."); + + domains[c]->domain_id = talloc_asprintf(domains[c], + "ID-of-domains-%zu", c); + fail_unless(domains[c]->domain_id != NULL, "talloc_asprintf failed."); + if (c > 0) { + domains[c-1]->next = domains[c]; + } + } + + dom = find_domain_by_id(domains[0], NULL); + fail_unless(dom == NULL, "Domain returned without search domain."); + + dom = find_domain_by_id(domains[0], "DOES-NOT_EXISTS"); + fail_unless(dom == NULL, "Domain returned with non existing id."); + + for (c = 0; c < NUM_DOMAINS; c++) { + id = talloc_asprintf(global_talloc_context, "ID-of-domains-%zu", c); + fail_unless(id != NULL, "talloc_asprintf failed.\n"); + + dom = find_domain_by_id(domains[0], id); + fail_unless(dom == domains[c], "Wrong domain returned for id [%s].", + id); + + talloc_free(id); + } + + talloc_free(domains); +} +END_TEST Suite *idmap_test_suite (void) { @@ -190,6 +238,7 @@ Suite *idmap_test_suite (void) tcase_add_test(tc_pac, pac_test_local_sid_to_id); tcase_add_test(tc_pac, pac_test_seondary_local_sid_to_id); tcase_add_test(tc_pac, pac_test_get_gids_to_add_and_remove); + tcase_add_test(tc_pac, pac_test_find_domain_by_id); suite_add_tcase(s, tc_pac); |