sss_idmap-tests.c revision 2998435fcc95857b73049b3955af9889ab595f24
7fb4c0766e858653c9776474005a6ae6d94828afgryzor SSSD - Test for idmap library
7fb4c0766e858653c9776474005a6ae6d94828afgryzor Sumit Bose <sbose@redhat.com>
7fb4c0766e858653c9776474005a6ae6d94828afgryzor Copyright (C) 2012 Red Hat
7fb4c0766e858653c9776474005a6ae6d94828afgryzor This program is free software; you can redistribute it and/or modify
7fb4c0766e858653c9776474005a6ae6d94828afgryzor it under the terms of the GNU General Public License as published by
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen the Free Software Foundation; either version 3 of the License, or
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen (at your option) any later version.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen This program is distributed in the hope that it will be useful,
7fb4c0766e858653c9776474005a6ae6d94828afgryzor but WITHOUT ANY WARRANTY; without even the implied warranty of
7fb4c0766e858653c9776474005a6ae6d94828afgryzor MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7fb4c0766e858653c9776474005a6ae6d94828afgryzor GNU General Public License for more details.
7fb4c0766e858653c9776474005a6ae6d94828afgryzor You should have received a copy of the GNU General Public License
7fb4c0766e858653c9776474005a6ae6d94828afgryzor along with this program. If not, see <http://www.gnu.org/licenses/>.
f9442c8a9869d3525a1ae6ed3e85c65d408e8a70sfconst char test_sid[] = "S-1-5-21-2127521184-1604012920-1887927527-72713";
f9442c8a9869d3525a1ae6ed3e85c65d408e8a70sfuint8_t test_bin_sid[] = {0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15,
7fb4c0766e858653c9776474005a6ae6d94828afgryzorstruct 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}};
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd err = sss_idmap_init(idmap_talloc, global_talloc_context, idmap_talloc_free,
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
f9442c8a9869d3525a1ae6ed3e85c65d408e8a70sf fail_unless(idmap_ctx != NULL, "sss_idmap_init returned NULL.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_free failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor struct sss_idmap_range range = {IDMAP_RANGE_MIN, IDMAP_RANGE_MAX};
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_add_domain(idmap_ctx, "test.dom", "S-1-5-21-1-2-3", &range);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_add_domain failed.");
9534272616b71aaea50aeec4162e749a96aebd7fsf "S-1-2-3-4-5-6",
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "S-1-5-21-1",
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "S-1-5-21-1-2-123456789012345678",
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "S-1-5-21-1+2+3",
e7eb98e34575dcf6536530bcf08e00d7ab3d3124gryzor "S-1-5-21-a-b-c",
9534272616b71aaea50aeec4162e749a96aebd7fsf "S-1-5-21-1-2-3-4",
9534272616b71aaea50aeec4162e749a96aebd7fsf fail_if(is_domain_sid(NULL), "is_domain_sid() returned true for [NULL]");
e7eb98e34575dcf6536530bcf08e00d7ab3d3124gryzor "is_domain_sid() returned true for [S-1-5-21-1-2-3]");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(ctx != NULL, "sss_idmap_init returned NULL.");
c2ed7ae314df26c4cd9e3a7224dabc6baa3f4dceigalic fail_unless(err == IDMAP_SUCCESS, "sss_idmap_free failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_init(idmap_talloc, global_talloc_context, idmap_talloc_free,
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_init failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(ctx != NULL, "sss_idmap_init returned NULL.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_free failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3333-1000", &id);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_sid_to_unix did not detect "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "unknown domain");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-10000", &id);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_NO_RANGE, "sss_idmap_sid_to_unix did not detect "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "RID out of range");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_sid_to_unix(idmap_ctx, "S-1-5-21-1-2-3-1000", &id);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_sid_to_unix failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "sss_idmap_sid_to_unix returned wrong id, "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_sid_to_bin_sid(idmap_ctx, "S-1-5-21-1-2-3-1000",
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "Failed to convert SID to binary SID");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_bin_sid_to_unix(idmap_ctx, bin_sid, length , &id);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_bin_sid_to_unix failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "sss_idmap_bin_sid_to_unix returned wrong id, "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_sid_to_dom_sid(idmap_ctx, "S-1-5-21-1-2-3-1000", &dom_sid);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "Failed to convert SID to SID structure");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_dom_sid_to_unix(idmap_ctx, dom_sid, &id);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_dom_sid_to_unix failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "sss_idmap_dom_sid_to_unix returned wrong id, "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "got [%d], expected [%d].", id, 1000 + IDMAP_RANGE_MIN);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_sid did not detect "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "id out of range");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_unix_to_sid failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "sss_idmap_unix_to_sid returned wrong SID, "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "expected [%s], got [%s].", "S-1-5-21-1-2-3-1000", sid);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_unix_to_dom_sid(idmap_ctx, 10000, &dom_sid);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_dom_sid did not detect "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "id out of range");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_unix_to_dom_sid(idmap_ctx, 2234, &dom_sid);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_unix_to_dom_sid failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_dom_sid_to_sid(idmap_ctx, dom_sid, &sid);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_dom_sid_to_sid failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "sss_idmap_unix_to_dom_sid returned wrong SID, "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "expected [%s], got [%s].", "S-1-5-21-1-2-3-1000", sid);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_unix_to_bin_sid(idmap_ctx, 10000, &bin_sid, &length);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_NO_DOMAIN, "sss_idmap_unix_to_bin_sid did not detect "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "id out of range");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_unix_to_bin_sid(idmap_ctx, 2234, &bin_sid, &length);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_unix_to_bin_sid failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_bin_sid_to_sid(idmap_ctx, bin_sid, length, &sid);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(err == IDMAP_SUCCESS, "sss_idmap_bin_sid_to_sid failed.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "sss_idmap_unix_to_bin_sid returned wrong SID, "
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "expected [%s], got [%s].", "S-1-5-21-1-2-3-1000", sid);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_bin_sid_to_dom_sid(idmap_ctx, test_bin_sid,
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "Failed to convert binary SID to struct sss_dom_sid.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_dom_sid_to_bin_sid(idmap_ctx, dom_sid, &new_bin_sid,
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "Failed to convert struct sss_dom_sid to binary SID.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(new_bin_sid_length == test_bin_sid_length,
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "Length of binary SIDs do not match.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor fail_unless(memcmp(test_bin_sid, new_bin_sid, test_bin_sid_length) == 0,
0236ede61169f34359c234625a1d792b97d7db12nd "Binary SIDs do not match.");
7fb4c0766e858653c9776474005a6ae6d94828afgryzor err = sss_idmap_sid_to_dom_sid(idmap_ctx, "S-1-5-21-1-2-3-1000", &dom_sid);
7fb4c0766e858653c9776474005a6ae6d94828afgryzor "Failed to convert SID string to struct sss_dom_sid.");
b03f9485e6dfcf9326e6122f91eaa1ced8939818jim err = sss_idmap_dom_sid_to_sid(idmap_ctx, dom_sid, &new_sid);
b03f9485e6dfcf9326e6122f91eaa1ced8939818jim "Failed to convert struct sss_dom_sid to SID string.");
b03f9485e6dfcf9326e6122f91eaa1ced8939818jim fail_unless(strlen("S-1-5-21-1-2-3-1000") == strlen(new_sid),
b03f9485e6dfcf9326e6122f91eaa1ced8939818jim "Length of SID strings do not match.");
b03f9485e6dfcf9326e6122f91eaa1ced8939818jim fail_unless(strcmp("S-1-5-21-1-2-3-1000", new_sid) == 0,
b03f9485e6dfcf9326e6122f91eaa1ced8939818jim "SID strings do not match.");
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd err = sss_idmap_sid_to_bin_sid(idmap_ctx, test_sid, &bin_sid, &length);
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd "Failed to convert SID string to binary sid.");
&sid);
NULL);
int number_failed;