a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose/*
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose SSSD - Test for idmap library
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose Authors:
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose Sumit Bose <sbose@redhat.com>
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose Copyright (C) 2012 Red Hat
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
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
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
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/>.
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose*/
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose#include <check.h>
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose#include "lib/idmap/sss_idmap.h"
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose#include "lib/idmap/sss_idmap_private.h"
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek#include "tests/common_check.h"
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose#define IDMAP_RANGE_MIN 1234
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose#define IDMAP_RANGE_MAX 9876
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose#define IDMAP_RANGE_MIN2 11234
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose#define IDMAP_RANGE_MAX2 19876
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose
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 Bose 0x00};
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bosesize_t test_bin_sid_length = sizeof(test_bin_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
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}};
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
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";
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bosestruct sss_idmap_ctx *idmap_ctx;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bosestatic void *idmap_talloc(size_t size, void *pvt)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose return talloc_size(pvt, size);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bosestatic void idmap_talloc_free(void *ptr, void *pvt)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose talloc_free(ptr);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bosevoid idmap_ctx_setup(void)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose enum idmap_error_code err;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_init(idmap_talloc, global_talloc_context, idmap_talloc_free,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose &idmap_ctx);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(idmap_ctx != NULL, "sss_idmap_init returned NULL.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlvoid idmap_ctx_setup_additional_seconary_slices(void)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_init(idmap_talloc, global_talloc_context, idmap_talloc_free,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl &idmap_ctx);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(idmap_ctx != NULL, "sss_idmap_init returned NULL.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx->idmap_opts.rangesize = 10;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx->idmap_opts.extra_slice_init = 5;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bosevoid idmap_ctx_teardown(void)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose enum idmap_error_code err;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_free(idmap_ctx);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_free failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bosevoid idmap_add_domain_setup(void)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose enum idmap_error_code err;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose struct sss_idmap_range range = {IDMAP_RANGE_MIN, IDMAP_RANGE_MAX};
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
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.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlvoid idmap_add_domain_with_sec_slices_setup(void)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl struct sss_idmap_range range = {
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN + idmap_ctx->idmap_opts.rangesize - 1,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl };
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_add_auto_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-3",
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl &range, NULL, 0, false, NULL, NULL);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_auto_domain_ex failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlenum idmap_error_code cb(const char *dom_name,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const char *dom_sid,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const char *range_id,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t min_id,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t max_id,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t first_rid,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl void *pvt)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl return IDMAP_ERROR;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlvoid idmap_add_domain_with_sec_slices_setup_cb_fail(void)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl struct sss_idmap_range range = {
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN + idmap_ctx->idmap_opts.rangesize - 1,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl };
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_add_auto_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-3",
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl &range, NULL, 0, false, cb, NULL);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_auto_domain_ex failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl#define MAX 1000
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlchar data[MAX];
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlenum idmap_error_code cb2(const char *dom_name,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const char *dom_sid,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const char *range_id,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t min_id,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t max_id,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t first_rid,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl void *pvt)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl char *p = (char*)pvt;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl size_t len;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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 Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl if (len >= MAX) {
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl return IDMAP_OUT_OF_MEMORY;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl }
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl return IDMAP_SUCCESS;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichlvoid idmap_add_domain_with_sec_slices_setup_cb_ok(void)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl struct sss_idmap_range range = {
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN + idmap_ctx->idmap_opts.rangesize - 1,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl };
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl void *pvt = (void*) data;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_add_auto_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-3",
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl &range, NULL, 0, false, cb2, pvt);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_auto_domain_ex failed.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseSTART_TEST(idmap_test_is_domain_sid)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose size_t c;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose const char *invalid[] = { "abc",
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 NULL };
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_if(is_domain_sid(NULL), "is_domain_sid() returned true for [NULL]");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose for (c = 0; invalid[c] != NULL; c++) {
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_if(is_domain_sid(invalid[c]),
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "is_domain_sid() returned true for [%s]", invalid[c]);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose }
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(is_domain_sid("S-1-5-21-1-2-3"),
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "is_domain_sid() returned true for [S-1-5-21-1-2-3]");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseEND_TEST
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseSTART_TEST(idmap_test_init_malloc)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose enum idmap_error_code err;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose struct sss_idmap_ctx *ctx = NULL;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_init(NULL, NULL, NULL, &ctx);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(ctx != NULL, "sss_idmap_init returned NULL.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_free(ctx);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_free failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseEND_TEST
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseSTART_TEST(idmap_test_init_talloc)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose enum idmap_error_code err;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose struct sss_idmap_ctx *ctx = NULL;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_init(idmap_talloc, global_talloc_context, idmap_talloc_free,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose &ctx);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(ctx != NULL, "sss_idmap_init returned NULL.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose err = sss_idmap_free(ctx);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_free failed.");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseEND_TEST
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseSTART_TEST(idmap_test_add_domain)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose idmap_add_domain_setup();
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseEND_TEST
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
d9059ad391cc73ad91893c3eab509d08699d5abaSumit BoseSTART_TEST(idmap_test_add_domain_collisions)
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose{
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose enum idmap_error_code err;
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
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
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose &range2);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_COLLISION,
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same name.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom2", "S-1-5-21-1-2-3",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose &range2);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_COLLISION,
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same SID.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom2", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose &range);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_COLLISION,
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same range.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain(idmap_ctx, "test.dom2", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose &range2);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_SUCCESS,
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain failed to add second domain.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose}
d9059ad391cc73ad91893c3eab509d08699d5abaSumit BoseEND_TEST
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose
d9059ad391cc73ad91893c3eab509d08699d5abaSumit BoseSTART_TEST(idmap_test_add_domain_collisions_ext_mapping)
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose{
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose enum idmap_error_code err;
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
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-3",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose &range, NULL, 0, true);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_domain failed.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx, "test.dom", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose &range2, NULL, 0, true);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_COLLISION,
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same name.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx, "test.dom2", "S-1-5-21-1-2-3",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose &range2, NULL, 0, true);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_COLLISION,
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain added domain with the same SID.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx, "test.dom2", "S-1-5-21-1-2-4",
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose &range, NULL, 0, true);
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose fail_unless(err == IDMAP_SUCCESS,
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "sss_idmap_add_domain failed to add second domain with " \
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose "external mapping and the same range.");
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose}
d9059ad391cc73ad91893c3eab509d08699d5abaSumit BoseEND_TEST
d9059ad391cc73ad91893c3eab509d08699d5abaSumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseSTART_TEST(idmap_test_sid2uid)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose enum idmap_error_code err;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose uint32_t id;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
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
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
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 fail_unless(id == (1000 + IDMAP_RANGE_MIN),
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "sss_idmap_sid_to_unix returned wrong id, "
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseEND_TEST
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlSTART_TEST(idmap_test_sid2uid_ss)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t id;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const uint32_t exp_id = 351800000;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const uint32_t exp_id2 = 832610000;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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
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 fail_unless(id == exp_id,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_sid_to_unix returned wrong id, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "got [%d], expected [%d].", id, exp_id);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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 fail_unless(id == (1000 + IDMAP_RANGE_MIN),
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_sid_to_unix returned wrong id, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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 fail_unless(id == exp_id2,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_sid_to_unix returned wrong id, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "got [%d], expected [%d].", id, exp_id2);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlEND_TEST
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlSTART_TEST(idmap_test_sid2uid_ext_sec_slices)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t id;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl char *sid;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const uint32_t exp_id = 351800000;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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
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 fail_unless(id == exp_id,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_sid_to_unix returned wrong id, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "got [%d], expected [%d].", id, exp_id);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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 sss_idmap_free_sid(idmap_ctx, sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlEND_TEST
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlSTART_TEST(idmap_test_dyn_dom_store_cb_fail)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t id;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl char *sid;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const uint32_t exp_id = 351800000;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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
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}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlEND_TEST
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlSTART_TEST(idmap_test_dyn_dom_store_cb_ok)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl uint32_t id;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl char *sid;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const uint32_t exp_id = 351800000;
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
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
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
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(strcmp(data,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl exp_stored_data) == 0,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "Storing dynamic domains idmapping failed: "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "expected [%s] but got [%s].", exp_stored_data, data);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlEND_TEST
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlSTART_TEST(idmap_test_sid2uid_additional_secondary_slices)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl struct TALLOC_CTX *tmp_ctx;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const char *dom_prefix = "S-1-5-21-1-2-3";
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl const int max_rid = 80;
4f3a996561445ba82c854bb2b674f975f596e884Lukas Slebodnik const char *sids[max_rid + 1];
4f3a996561445ba82c854bb2b674f975f596e884Lukas Slebodnik unsigned int ids[max_rid + 1];
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tmp_ctx = talloc_new(NULL);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(tmp_ctx != NULL, "Out of memory.");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(sids[i] != NULL, "Out of memory");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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 }
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl for (unsigned int i = 0; i < max_rid + 1; i++) {
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl char *sid;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl fail_unless(strcmp(sid, sids[i]) == 0,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "sss_idmap_unix_to_sid returned wrong sid, "
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl "got [%s], expected [%s].", sid, sids[i]);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl talloc_free(sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl }
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl talloc_free(tmp_ctx);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlEND_TEST
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseSTART_TEST(idmap_test_bin_sid2uid)
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose{
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose enum idmap_error_code err;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose uint32_t id;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose uint8_t *bin_sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose size_t length;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_sid_to_bin_sid(idmap_ctx, "S-1-5-21-1-2-3-1000",
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose &bin_sid, &length);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS, "Failed to convert SID to binary SID");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
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 fail_unless(id == (1000 + IDMAP_RANGE_MIN),
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "sss_idmap_bin_sid_to_unix returned wrong id, "
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
6469f42ca80bb9b955875d590485b0d9366491dfPavel Březina sss_idmap_free_bin_sid(idmap_ctx, bin_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose}
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseEND_TEST
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseSTART_TEST(idmap_test_dom_sid2uid)
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose{
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose enum idmap_error_code err;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose uint32_t id;
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose struct sss_dom_sid *dom_sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
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
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 fail_unless(id == (1000 + IDMAP_RANGE_MIN),
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "sss_idmap_dom_sid_to_unix returned wrong id, "
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
9e9b2e473ceb93bf3bbf2a6c65eb9c8467ba425aPavel Březina sss_idmap_free_dom_sid(idmap_ctx, dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose}
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseEND_TEST
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseSTART_TEST(idmap_test_uid2sid)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose enum idmap_error_code err;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose char *sid;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
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
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);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
4537e95f6741ae05ec620e5b46ca1d4a3a1ceae5Pavel Březina sss_idmap_free_sid(idmap_ctx, sid);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseEND_TEST
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlSTART_TEST(idmap_test_uid2sid_ss)
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl{
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl enum idmap_error_code err;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl char *sid;
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_unix_to_sid(idmap_ctx,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl IDMAP_RANGE_MIN + idmap_ctx->idmap_opts.rangesize + 1,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl &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
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
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl sss_idmap_free_sid(idmap_ctx, sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Secondary ranges */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl err = sss_idmap_unix_to_sid(idmap_ctx,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl 313800000,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl &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-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);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl sss_idmap_free_sid(idmap_ctx, sid);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl}
8babbeee01e67893af4828ddfc922ecac0be4197Pavel ReichlEND_TEST
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseSTART_TEST(idmap_test_uid2dom_sid)
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose{
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose enum idmap_error_code err;
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose struct sss_dom_sid *dom_sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose char *sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
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
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
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
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
4537e95f6741ae05ec620e5b46ca1d4a3a1ceae5Pavel Březina sss_idmap_free_sid(idmap_ctx, sid);
9e9b2e473ceb93bf3bbf2a6c65eb9c8467ba425aPavel Březina sss_idmap_free_dom_sid(idmap_ctx, dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose}
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseEND_TEST
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseSTART_TEST(idmap_test_uid2bin_sid)
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose{
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose enum idmap_error_code err;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose uint8_t *bin_sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose size_t length;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose char *sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
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
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
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
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
4537e95f6741ae05ec620e5b46ca1d4a3a1ceae5Pavel Březina sss_idmap_free_sid(idmap_ctx, sid);
6469f42ca80bb9b955875d590485b0d9366491dfPavel Březina sss_idmap_free_bin_sid(idmap_ctx, bin_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose}
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseEND_TEST
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseSTART_TEST(idmap_test_bin_sid2dom_sid)
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose{
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose struct sss_dom_sid *dom_sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose enum idmap_error_code err;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose uint8_t *new_bin_sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose size_t new_bin_sid_length;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_bin_sid_to_dom_sid(idmap_ctx, test_bin_sid,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose test_bin_sid_length, &dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS,
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose "Failed to convert binary SID to struct sss_dom_sid.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_dom_sid_to_bin_sid(idmap_ctx, dom_sid, &new_bin_sid,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose &new_bin_sid_length);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS,
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose "Failed to convert struct sss_dom_sid to binary SID.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
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.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
9e9b2e473ceb93bf3bbf2a6c65eb9c8467ba425aPavel Březina sss_idmap_free_dom_sid(idmap_ctx, dom_sid);
6469f42ca80bb9b955875d590485b0d9366491dfPavel Březina sss_idmap_free_bin_sid(idmap_ctx, new_bin_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose}
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseEND_TEST
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseSTART_TEST(idmap_test_sid2dom_sid)
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose{
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose struct sss_dom_sid *dom_sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose enum idmap_error_code err;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose char *new_sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_sid_to_dom_sid(idmap_ctx, "S-1-5-21-1-2-3-1000", &dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS,
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose "Failed to convert SID string to struct sss_dom_sid.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_dom_sid_to_sid(idmap_ctx, dom_sid, &new_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS,
c51a204a40b8f85f7f525edb3e24520916d8b9c7Sumit Bose "Failed to convert struct sss_dom_sid to SID string.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
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.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
9e9b2e473ceb93bf3bbf2a6c65eb9c8467ba425aPavel Březina sss_idmap_free_dom_sid(idmap_ctx, dom_sid);
4537e95f6741ae05ec620e5b46ca1d4a3a1ceae5Pavel Březina sss_idmap_free_sid(idmap_ctx, new_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose}
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseEND_TEST
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit BoseSTART_TEST(idmap_test_large_and_too_large_sid)
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose{
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose struct sss_dom_sid *dom_sid = NULL;
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose enum idmap_error_code err;
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose char *new_sid = NULL;
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose err = sss_idmap_sid_to_dom_sid(idmap_ctx, large_sid, &dom_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose fail_unless(err == IDMAP_SUCCESS,
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "Failed to convert SID string with a UINT32_MAX component "
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "to struct sss_dom_sid.");
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose err = sss_idmap_dom_sid_to_sid(idmap_ctx, dom_sid, &new_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose fail_unless(err == IDMAP_SUCCESS,
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "Failed to convert struct sss_dom_sid to SID string.");
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose
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 fail_unless(strcmp(large_sid, new_sid) == 0,
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "SID strings do not match, expected [%s], got [%s]",
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose large_sid, new_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose err = sss_idmap_sid_to_dom_sid(idmap_ctx, too_large_sid, &dom_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose fail_unless(err == IDMAP_SID_INVALID,
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "Trying to convert a SID with a too large component "
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose "did not return IDMAP_SID_INVALID");
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose
9e9b2e473ceb93bf3bbf2a6c65eb9c8467ba425aPavel Březina sss_idmap_free_dom_sid(idmap_ctx, dom_sid);
4537e95f6741ae05ec620e5b46ca1d4a3a1ceae5Pavel Březina sss_idmap_free_sid(idmap_ctx, new_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose}
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit BoseEND_TEST
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseSTART_TEST(idmap_test_sid2bin_sid)
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose{
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose enum idmap_error_code err;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose size_t length;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose uint8_t *bin_sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_sid_to_bin_sid(idmap_ctx, test_sid, &bin_sid, &length);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Failed to convert SID string to binary sid.");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(length == test_bin_sid_length,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Size of binary SIDs do not match, got [%d], expected [%d]",
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose length, test_bin_sid_length);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(memcmp(bin_sid, test_bin_sid, test_bin_sid_length) == 0,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose "Binary SIDs do not match");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
6469f42ca80bb9b955875d590485b0d9366491dfPavel Březina sss_idmap_free_bin_sid(idmap_ctx, bin_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose}
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseEND_TEST
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseSTART_TEST(idmap_test_bin_sid2sid)
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose{
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose enum idmap_error_code err;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose char *sid = NULL;
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose err = sss_idmap_bin_sid_to_sid(idmap_ctx, test_bin_sid, test_bin_sid_length,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose &sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose fail_unless(err == IDMAP_SUCCESS,
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]",
9fd2775fe1ced6ff6a9a3ff7db124fcb52dade5dSumit Bose test_sid, sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
4537e95f6741ae05ec620e5b46ca1d4a3a1ceae5Pavel Březina sss_idmap_free_sid(idmap_ctx, sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose}
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit BoseEND_TEST
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseSTART_TEST(idmap_test_smb_sid2dom_sid)
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose{
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose struct sss_dom_sid *dom_sid = NULL;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose enum idmap_error_code err;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose struct dom_sid *new_smb_sid = NULL;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_smb_sid_to_dom_sid(idmap_ctx, &test_smb_sid, &dom_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(err == IDMAP_SUCCESS,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Failed to convert samba dom_sid to struct sss_dom_sid.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_dom_sid_to_smb_sid(idmap_ctx, dom_sid, &new_smb_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(err == IDMAP_SUCCESS,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Failed to convert struct sss_dom_sid to samba dom_sid.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
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.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
9e9b2e473ceb93bf3bbf2a6c65eb9c8467ba425aPavel Březina sss_idmap_free_dom_sid(idmap_ctx, dom_sid);
89fdf07e77054b2931673bd1f082cb459607c0ecPavel Březina sss_idmap_free_smb_sid(idmap_ctx, new_smb_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose}
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseEND_TEST
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseSTART_TEST(idmap_test_smb_sid2bin_sid)
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose{
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose enum idmap_error_code err;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose size_t length;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose uint8_t *bin_sid = NULL;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_smb_sid_to_bin_sid(idmap_ctx, &test_smb_sid,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose &bin_sid, &length);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(err == IDMAP_SUCCESS,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Failed to convert samba dom_sid to binary sid.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(length == test_bin_sid_length,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Size of binary SIDs do not match, got [%d], expected [%d]",
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose length, test_bin_sid_length);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(memcmp(bin_sid, test_bin_sid, test_bin_sid_length) == 0,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose "Binary SIDs do not match.");
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
6469f42ca80bb9b955875d590485b0d9366491dfPavel Březina sss_idmap_free_bin_sid(idmap_ctx, bin_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose}
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseEND_TEST
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseSTART_TEST(idmap_test_bin_sid2smb_sid)
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose{
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose enum idmap_error_code err;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose struct dom_sid *smb_sid = NULL;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_bin_sid_to_smb_sid(idmap_ctx, test_bin_sid,
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose test_bin_sid_length, &smb_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(err == IDMAP_SUCCESS,
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
89fdf07e77054b2931673bd1f082cb459607c0ecPavel Březina sss_idmap_free_smb_sid(idmap_ctx, smb_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose}
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseEND_TEST
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseSTART_TEST(idmap_test_smb_sid2sid)
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose{
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose enum idmap_error_code err;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose char *sid = NULL;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_smb_sid_to_sid(idmap_ctx, &test_smb_sid, &sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(err == IDMAP_SUCCESS,
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 test_sid, sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
4537e95f6741ae05ec620e5b46ca1d4a3a1ceae5Pavel Březina sss_idmap_free_sid(idmap_ctx, sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose}
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseEND_TEST
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseSTART_TEST(idmap_test_sid2smb_sid)
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose{
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose enum idmap_error_code err;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose struct dom_sid *smb_sid = NULL;
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose err = sss_idmap_sid_to_smb_sid(idmap_ctx, test_sid, &smb_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose fail_unless(err == IDMAP_SUCCESS,
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
89fdf07e77054b2931673bd1f082cb459607c0ecPavel Březina sss_idmap_free_smb_sid(idmap_ctx, smb_sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose}
2998435fcc95857b73049b3955af9889ab595f24Sumit BoseEND_TEST
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit BoseSuite *idmap_test_suite (void)
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose Suite *s = suite_create ("IDMAP");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose TCase *tc_init = tcase_create("IDMAP init tests");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_checked_fixture(tc_init,
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leak_check_setup,
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leak_check_teardown);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_test(tc_init, idmap_test_init_malloc);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_test(tc_init, idmap_test_init_talloc);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_test(tc_init, idmap_test_is_domain_sid);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose suite_add_tcase(s, tc_init);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose TCase *tc_dom = tcase_create("IDMAP domain tests");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_checked_fixture(tc_dom,
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leak_check_setup,
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leak_check_teardown);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_checked_fixture(tc_dom,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose idmap_ctx_setup,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose idmap_ctx_teardown);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_test(tc_dom, idmap_test_add_domain);
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);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose suite_add_tcase(s, tc_dom);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose TCase *tc_conv = tcase_create("IDMAP SID conversion tests");
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose tcase_add_checked_fixture(tc_conv,
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leak_check_setup,
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leak_check_teardown);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose tcase_add_checked_fixture(tc_conv,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose idmap_ctx_setup,
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose idmap_ctx_teardown);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose tcase_add_test(tc_conv, idmap_test_bin_sid2dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose tcase_add_test(tc_conv, idmap_test_sid2dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose tcase_add_test(tc_conv, idmap_test_sid2bin_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose tcase_add_test(tc_conv, idmap_test_bin_sid2sid);
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);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose tcase_add_test(tc_conv, idmap_test_smb_sid2sid);
2998435fcc95857b73049b3955af9889ab595f24Sumit Bose tcase_add_test(tc_conv, idmap_test_sid2smb_sid);
2d07aa724c93bbaec2cd29470941c0754c74f715Sumit Bose tcase_add_test(tc_conv, idmap_test_large_and_too_large_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose suite_add_tcase(s, tc_conv);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose TCase *tc_map = tcase_create("IDMAP mapping tests");
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_checked_fixture(tc_map,
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leak_check_setup,
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek ck_leak_check_teardown);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_checked_fixture(tc_map,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose idmap_ctx_setup,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose idmap_ctx_teardown);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_checked_fixture(tc_map,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose idmap_add_domain_setup,
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose NULL);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_test(tc_map, idmap_test_sid2uid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose tcase_add_test(tc_map, idmap_test_bin_sid2uid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose tcase_add_test(tc_map, idmap_test_dom_sid2uid);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tcase_add_test(tc_map, idmap_test_uid2sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose tcase_add_test(tc_map, idmap_test_uid2dom_sid);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose tcase_add_test(tc_map, idmap_test_uid2bin_sid);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose suite_add_tcase(s, tc_map);
b6dfbf81c61d4431aaa81687ec53e892f8b71edbSumit Bose
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Test secondary slices */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl TCase *tc_map_ss = tcase_create("IDMAP mapping tests");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_ss,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl ck_leak_check_setup,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl ck_leak_check_teardown);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_ss,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx_setup,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx_teardown);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_ss,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_add_domain_with_sec_slices_setup,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl NULL);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl suite_add_tcase(s, tc_map_ss);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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 tcase_add_checked_fixture(tc_map_cb_fail,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl ck_leak_check_setup,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl ck_leak_check_teardown);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_cb_fail,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx_setup,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx_teardown);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_cb_fail,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_add_domain_with_sec_slices_setup_cb_fail,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl NULL);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_test(tc_map_cb_fail, idmap_test_dyn_dom_store_cb_fail);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl suite_add_tcase(s, tc_map_cb_fail);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
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_checked_fixture(tc_map_cb_ok,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl ck_leak_check_setup,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl ck_leak_check_teardown);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_cb_ok,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx_setup,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx_teardown);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_cb_ok,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_add_domain_with_sec_slices_setup_cb_ok,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl NULL);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_test(tc_map_cb_ok, idmap_test_dyn_dom_store_cb_ok);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl suite_add_tcase(s, tc_map_cb_ok);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Test additional secondary slices */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl TCase *tc_map_additional_secondary_slices = \
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_create("IDMAP additional secondary slices");
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_additional_secondary_slices,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl ck_leak_check_setup,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl ck_leak_check_teardown);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_additional_secondary_slices,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx_setup_additional_seconary_slices,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_ctx_teardown);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_checked_fixture(tc_map_additional_secondary_slices,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_add_domain_with_sec_slices_setup,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl NULL);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl tcase_add_test(tc_map_additional_secondary_slices,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl idmap_test_sid2uid_additional_secondary_slices);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl suite_add_tcase(s, tc_map_additional_secondary_slices);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose return s;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Boseint main(int argc, const char *argv[])
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose{
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose int number_failed;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose tests_set_cwd();
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose Suite *s = idmap_test_suite();
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose SRunner *sr = srunner_create(s);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose srunner_run_all(sr, CK_ENV);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose number_failed = srunner_ntests_failed (sr);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose srunner_free (sr);
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose}