a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose SSSD - Test for idmap library
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose Sumit Bose <sbose@redhat.com>
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose Copyright (C) 2012 Red Hat
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose This program is free software; you can redistribute it and/or modify
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose it under the terms of the GNU General Public License as published by
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose the Free Software Foundation; either version 3 of the License, or
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose (at your option) any later version.
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose This program is distributed in the hope that it will be useful,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose GNU General Public License for more details.
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose You should have received a copy of the GNU General Public License
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Boseconst char test_sid[] = "S-1-5-21-2127521184-1604012920-1887927527-72713";
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Boseuint8_t test_bin_sid[] = {0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose 0x00, 0x00, 0x00, 0xA0, 0x65, 0xCF, 0x7E, 0x78, 0x4B,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose 0x9B, 0x5F, 0xE7, 0x7C, 0x87, 0x70, 0x09, 0x1C, 0x01,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bosesize_t test_bin_sid_length = sizeof(test_bin_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bosestruct dom_sid test_smb_sid = {1, 5, {0, 0, 0, 0, 0, 5}, {21, 2127521184, 1604012920, 1887927527, 72713, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Boseconst char large_sid[] = "S-1-5-21-1-2-4294967295-1000";
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Boseconst char too_large_sid[] = "S-1-5-21-1-2-4294967296-1000";
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bosestatic void idmap_talloc_free(void *ptr, void *pvt)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_init(idmap_talloc, global_talloc_context, idmap_talloc_free,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(idmap_ctx != NULL, "sss_idmap_init returned NULL.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlvoid idmap_ctx_setup_additional_seconary_slices(void)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_init(idmap_talloc, global_talloc_context, idmap_talloc_free,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(idmap_ctx != NULL, "sss_idmap_init returned NULL.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_free failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose struct sss_idmap_range range = {IDMAP_RANGE_MIN, IDMAP_RANGE_MAX};
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom", "S-1-5-21-1-2-3", &range);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_domain failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlvoid idmap_add_domain_with_sec_slices_setup(void)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN + idmap_ctx->idmap_opts.rangesize - 1,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_add_auto_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-3",
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_auto_domain_ex failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlvoid idmap_add_domain_with_sec_slices_setup_cb_fail(void)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN + idmap_ctx->idmap_opts.rangesize - 1,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_add_auto_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-3",
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_auto_domain_ex failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl char *p = (char*)pvt;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl len = snprintf(p, MAX, "%s, %s %s, %"PRIu32", %"PRIu32", %" PRIu32,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl dom_name, dom_sid, range_id, min_id, max_id, first_rid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlvoid idmap_add_domain_with_sec_slices_setup_cb_ok(void)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN + idmap_ctx->idmap_opts.rangesize - 1,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_add_auto_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-3",
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_auto_domain_ex failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "S-1-2-3-4-5-6",
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "S-1-5-21-1",
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "S-1-5-21-1-2-123456789012345678",
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "S-1-5-21-1+2+3",
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "S-1-5-21-a-b-c",
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "S-1-5-21-1-2-3-4",
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_if(is_domain_sid(NULL), "is_domain_sid() returned true for [NULL]");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "is_domain_sid() returned true for [%s]", invalid[c]);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "is_domain_sid() returned true for [S-1-5-21-1-2-3]");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(ctx != NULL, "sss_idmap_init returned NULL.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_free failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_init(idmap_talloc, global_talloc_context, idmap_talloc_free,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(ctx != NULL, "sss_idmap_init returned NULL.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_free failed.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose struct sss_idmap_range range = {IDMAP_RANGE_MIN, IDMAP_RANGE_MAX};
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose struct sss_idmap_range range2 = {IDMAP_RANGE_MIN2, IDMAP_RANGE_MAX2};
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom", "S-1-5-21-1-2-3", &range);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_domain failed.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same name.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom2", "S-1-5-21-1-2-3",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same SID.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom2", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same range.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom2", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain failed to add second domain.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit BoseSTART_TEST(idmap_test_add_domain_collisions_ext_mapping)
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose struct sss_idmap_range range = {IDMAP_RANGE_MIN, IDMAP_RANGE_MAX};
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose struct sss_idmap_range range2 = {IDMAP_RANGE_MIN2, IDMAP_RANGE_MAX2};
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-3",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_domain failed.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same name.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx, "test.dom2", "S-1-5-21-1-2-3",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same SID.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx, "test.dom2", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain failed to add second domain with " \
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "external mapping and the same range.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3333-1000", &id);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_sid_to_unix did not detect "
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "unknown domain");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-10000", &id);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_NO_RANGE, "sss_idmap_sid_to_unix did not detect "
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "RID out of range");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-1000", &id);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_sid_to_unix failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "sss_idmap_sid_to_unix returned wrong id, "
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3333-1000", &id);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_sid_to_unix did not detect "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "unknown domain");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* RID out of primary and secondary range */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-4000000", &id);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_sid_to_unix failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_sid_to_unix returned wrong id, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-1000", &id);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_sid_to_unix failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_sid_to_unix returned wrong id, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-210000", &id);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_sid_to_unix failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_sid_to_unix returned wrong id, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_unix_to_sid(idmap_ctx, exp_id, &sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_sid did not detect "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "id out of range");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* RID out of primary and secondary range */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-4000000", &id);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_sid_to_unix failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_sid_to_unix returned wrong id, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Secondary ranges were expanded by sid_to_unix call */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_unix_to_sid(idmap_ctx, exp_id, &sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_unix_to_sid failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(strcmp(sid, "S-1-5-21-1-2-3-4000000") == 0,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_unix_to_sid returned wrong SID, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "expected [%s], got [%s].", "S-1-5-21-1-2-3-4000000", sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_unix_to_sid(idmap_ctx, exp_id, &sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_sid did not detect "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "id out of range");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* RID out of primary and secondary range */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-4000000", &id);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_ERROR, "sss_idmap_sid_to_unix failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const char *exp_stored_data = "test.dom, S-1-5-21-1-2-3 S-1-5-21-1-2-3-4000000, 351800000, 351999999, 4000000";
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_unix_to_sid(idmap_ctx, exp_id, &sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_sid did not detect "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "id out of range");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* RID out of primary and secondary range */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-4000000", &id);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_sid_to_unix failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "Storing dynamic domains idmapping failed: "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "expected [%s] but got [%s].", exp_stored_data, data);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlSTART_TEST(idmap_test_sid2uid_additional_secondary_slices)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(tmp_ctx != NULL, "Out of memory.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl for (unsigned int i = 0; i < max_rid + 1; i++) {
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl sids[i] = talloc_asprintf(tmp_ctx, "%s-%u", dom_prefix, i);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_sid_to_unix(idmap_ctx, sids[i], &ids[i]);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_sid_to_unix failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl for (unsigned int i = 0; i < max_rid + 1; i++) {
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_unix_to_sid(idmap_ctx, ids[i], &sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_sid_to_unix failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_unix_to_sid returned wrong sid, "
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_sid_to_bin_sid(idmap_ctx, "S-1-5-21-1-2-3-1000",
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS, "Failed to convert SID to binary SID");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_bin_sid_to_unix(idmap_ctx, bin_sid, length , &id);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_bin_sid_to_unix failed.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "sss_idmap_bin_sid_to_unix returned wrong id, "
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_sid_to_dom_sid(idmap_ctx, "S-1-5-21-1-2-3-1000", &dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS, "Failed to convert SID to SID structure");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_dom_sid_to_unix(idmap_ctx, dom_sid, &id);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_dom_sid_to_unix failed.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "sss_idmap_dom_sid_to_unix returned wrong id, "
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_unix_to_sid(idmap_ctx, 10000, &sid);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_sid did not detect "
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "id out of range");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_unix_to_sid(idmap_ctx, 2234, &sid);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_unix_to_sid failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(strcmp(sid, "S-1-5-21-1-2-3-1000") == 0,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "sss_idmap_unix_to_sid returned wrong SID, "
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "expected [%s], got [%s].", "S-1-5-21-1-2-3-1000", sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN + idmap_ctx->idmap_opts.rangesize + 1,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_sid did not detect "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "id out of range");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_unix_to_sid(idmap_ctx, 2234, &sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_unix_to_sid failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(strcmp(sid, "S-1-5-21-1-2-3-1000") == 0,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_unix_to_sid returned wrong SID, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "expected [%s], got [%s].", "S-1-5-21-1-2-3-1000", sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Secondary ranges */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_unix_to_sid failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(strcmp(sid, "S-1-5-21-1-2-3-400000") == 0,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_unix_to_sid returned wrong SID, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "expected [%s], got [%s].", "S-1-5-21-1-2-3-400000", sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_unix_to_dom_sid(idmap_ctx, 10000, &dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_dom_sid did not detect "
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "id out of range");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_unix_to_dom_sid(idmap_ctx, 2234, &dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_unix_to_dom_sid failed.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_dom_sid_to_sid(idmap_ctx, dom_sid, &sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_dom_sid_to_sid failed.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(strcmp(sid, "S-1-5-21-1-2-3-1000") == 0,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "sss_idmap_unix_to_dom_sid returned wrong SID, "
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "expected [%s], got [%s].", "S-1-5-21-1-2-3-1000", sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_unix_to_bin_sid(idmap_ctx, 10000, &bin_sid, &length);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_bin_sid did not detect "
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "id out of range");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_unix_to_bin_sid(idmap_ctx, 2234, &bin_sid, &length);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_unix_to_bin_sid failed.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_bin_sid_to_sid(idmap_ctx, bin_sid, length, &sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_bin_sid_to_sid failed.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(strcmp(sid, "S-1-5-21-1-2-3-1000") == 0,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "sss_idmap_unix_to_bin_sid returned wrong SID, "
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "expected [%s], got [%s].", "S-1-5-21-1-2-3-1000", sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_bin_sid_to_dom_sid(idmap_ctx, test_bin_sid,
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose "Failed to convert binary SID to struct sss_dom_sid.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_dom_sid_to_bin_sid(idmap_ctx, dom_sid, &new_bin_sid,
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose "Failed to convert struct sss_dom_sid to binary SID.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(new_bin_sid_length == test_bin_sid_length,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Length of binary SIDs do not match.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(memcmp(test_bin_sid, new_bin_sid, test_bin_sid_length) == 0,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Binary SIDs do not match.");
6469f42ca80bb9b955875d590485b0d9366491dfPavel Březina sss_idmap_free_bin_sid(idmap_ctx, new_bin_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_sid_to_dom_sid(idmap_ctx, "S-1-5-21-1-2-3-1000", &dom_sid);
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose "Failed to convert SID string to struct sss_dom_sid.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_dom_sid_to_sid(idmap_ctx, dom_sid, &new_sid);
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose "Failed to convert struct sss_dom_sid to SID string.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(new_sid != NULL, "SID string not set");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(strlen("S-1-5-21-1-2-3-1000") == strlen(new_sid),
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Length of SID strings do not match.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(strcmp("S-1-5-21-1-2-3-1000", new_sid) == 0,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "SID strings do not match.");
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose err = sss_idmap_sid_to_dom_sid(idmap_ctx, large_sid, &dom_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "Failed to convert SID string with a UINT32_MAX component "
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "to struct sss_dom_sid.");
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose err = sss_idmap_dom_sid_to_sid(idmap_ctx, dom_sid, &new_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "Failed to convert struct sss_dom_sid to SID string.");
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose fail_unless(new_sid != NULL, "SID string not set");
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose fail_unless(strlen(large_sid) == strlen(new_sid),
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "Length of SID strings do not match.");
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "SID strings do not match, expected [%s], got [%s]",
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose err = sss_idmap_sid_to_dom_sid(idmap_ctx, too_large_sid, &dom_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "Trying to convert a SID with a too large component "
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "did not return IDMAP_SID_INVALID");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_sid_to_bin_sid(idmap_ctx, test_sid, &bin_sid, &length);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Failed to convert SID string to binary sid.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Size of binary SIDs do not match, got [%d], expected [%d]",
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(memcmp(bin_sid, test_bin_sid, test_bin_sid_length) == 0,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Binary SIDs do not match");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_bin_sid_to_sid(idmap_ctx, test_bin_sid, test_bin_sid_length,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Failed to convert binary SID to SID string.");
9fd2775fe1ced6ff6a9a3ff7db124fcb52dade5dSumit Bose fail_unless(strcmp(sid, test_sid) == 0, "SID strings do not match, "
9fd2775fe1ced6ff6a9a3ff7db124fcb52dade5dSumit Bose "expected [%s], get [%s]",
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_smb_sid_to_dom_sid(idmap_ctx, &test_smb_sid, &dom_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Failed to convert samba dom_sid to struct sss_dom_sid.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_dom_sid_to_smb_sid(idmap_ctx, dom_sid, &new_smb_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Failed to convert struct sss_dom_sid to samba dom_sid.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(memcmp(&test_smb_sid, new_smb_sid, sizeof(struct dom_sid)) == 0,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Samba dom_sid-s do not match.");
89fdf07e77054b2931673bd1f082cb459607c0ecPavel Březina sss_idmap_free_smb_sid(idmap_ctx, new_smb_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_smb_sid_to_bin_sid(idmap_ctx, &test_smb_sid,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Failed to convert samba dom_sid to binary sid.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Size of binary SIDs do not match, got [%d], expected [%d]",
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(memcmp(bin_sid, test_bin_sid, test_bin_sid_length) == 0,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Binary SIDs do not match.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_bin_sid_to_smb_sid(idmap_ctx, test_bin_sid,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Failed to convert binary sid to samba dom_sid.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(memcmp(&test_smb_sid, smb_sid, sizeof(struct dom_sid)) == 0,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Samba dom_sid structs do not match.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_smb_sid_to_sid(idmap_ctx, &test_smb_sid, &sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Failed to convert samba dom_sid to sid string.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(strcmp(sid, test_sid) == 0, "SID strings do not match, "
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "expected [%s], get [%s]",
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_sid_to_smb_sid(idmap_ctx, test_sid, &smb_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Failed to convert binary sid to samba dom_sid.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(memcmp(&test_smb_sid, smb_sid, sizeof(struct dom_sid)) == 0,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Samba dom_sid structs do not match.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose TCase *tc_init = tcase_create("IDMAP init tests");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_test(tc_init, idmap_test_is_domain_sid);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose TCase *tc_dom = tcase_create("IDMAP domain tests");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose tcase_add_test(tc_dom, idmap_test_add_domain_collisions);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose tcase_add_test(tc_dom, idmap_test_add_domain_collisions_ext_mapping);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose TCase *tc_conv = tcase_create("IDMAP SID conversion tests");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose tcase_add_test(tc_conv, idmap_test_bin_sid2dom_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose tcase_add_test(tc_conv, idmap_test_smb_sid2dom_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose tcase_add_test(tc_conv, idmap_test_smb_sid2bin_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose tcase_add_test(tc_conv, idmap_test_bin_sid2smb_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose tcase_add_test(tc_conv, idmap_test_large_and_too_large_sid);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose TCase *tc_map = tcase_create("IDMAP mapping tests");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Test secondary slices */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl TCase *tc_map_ss = tcase_create("IDMAP mapping tests");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_test(tc_map_ss, idmap_test_sid2uid_ss);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_test(tc_map_ss, idmap_test_uid2sid_ss);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_test(tc_map_ss, idmap_test_sid2uid_ext_sec_slices);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Test secondary slices - callback to store failed. */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl TCase *tc_map_cb_fail = tcase_create("IDMAP mapping tests - store fail");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_add_domain_with_sec_slices_setup_cb_fail,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_test(tc_map_cb_fail, idmap_test_dyn_dom_store_cb_fail);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Test secondary slices - callback to store passed. */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl TCase *tc_map_cb_ok = tcase_create("IDMAP mapping tests");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_test(tc_map_cb_ok, idmap_test_dyn_dom_store_cb_ok);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Test additional secondary slices */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_create("IDMAP additional secondary slices");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_additional_secondary_slices,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_additional_secondary_slices,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_additional_secondary_slices,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_test(tc_map_additional_secondary_slices,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_test_sid2uid_additional_secondary_slices);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl suite_add_tcase(s, tc_map_additional_secondary_slices);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;