0352c371e743d8dae996123f658b5d32c677614eYassir Elley Yassir Elley <yelley@redhat.com>
0352c371e743d8dae996123f658b5d32c677614eYassir Elley Copyright (C) 2014 Red Hat
0352c371e743d8dae996123f658b5d32c677614eYassir Elley SSSD tests: GPO unit tests
0352c371e743d8dae996123f658b5d32c677614eYassir Elley This program is free software; you can redistribute it and/or modify
0352c371e743d8dae996123f658b5d32c677614eYassir Elley it under the terms of the GNU General Public License as published by
0352c371e743d8dae996123f658b5d32c677614eYassir Elley the Free Software Foundation; either version 3 of the License, or
0352c371e743d8dae996123f658b5d32c677614eYassir Elley (at your option) any later version.
0352c371e743d8dae996123f658b5d32c677614eYassir Elley This program is distributed in the hope that it will be useful,
0352c371e743d8dae996123f658b5d32c677614eYassir Elley but WITHOUT ANY WARRANTY; without even the implied warranty of
0352c371e743d8dae996123f658b5d32c677614eYassir Elley MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0352c371e743d8dae996123f658b5d32c677614eYassir Elley GNU General Public License for more details.
0352c371e743d8dae996123f658b5d32c677614eYassir Elley You should have received a copy of the GNU General Public License
0352c371e743d8dae996123f658b5d32c677614eYassir Elley along with this program. If not, see <http://www.gnu.org/licenses/>.
0352c371e743d8dae996123f658b5d32c677614eYassir Elley/* In order to access opaque types */
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * Test parsing target DN into som components
0352c371e743d8dae996123f658b5d32c677614eYassir Elleystatic void test_populate_som_list(const char *target_dn,
0352c371e743d8dae996123f658b5d32c677614eYassir Elley assert_int_equal(num_soms, expected->num_soms);
0352c371e743d8dae996123f658b5d32c677614eYassir Elley const char *som_dns[] = {"OU=West OU,OU=Sales OU,DC=foo,DC=com",
0352c371e743d8dae996123f658b5d32c677614eYassir Elley "OU=Sales OU,DC=foo,DC=com",
0352c371e743d8dae996123f658b5d32c677614eYassir Elley "DC=foo,DC=com"};
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_populate_som_list("CN=F21-Client,OU=West OU,OU=Sales OU,DC=foo,DC=com",
0352c371e743d8dae996123f658b5d32c677614eYassir Elleyvoid test_populate_som_list_malformed(void **state)
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_populate_som_list("malformed target dn", &expected);
0352c371e743d8dae996123f658b5d32c677614eYassir Elley * Test parsing raw_gplink_value into gplink components
0352c371e743d8dae996123f658b5d32c677614eYassir Elleystatic void test_populate_gplink_list(const char *input_gplink_value,
0352c371e743d8dae996123f658b5d32c677614eYassir Elley char *raw_gplink_value = talloc_strdup(tmp_ctx, input_gplink_value);
0352c371e743d8dae996123f658b5d32c677614eYassir Elley if (gplink_list[i]->enforced != expected->enforced[i])
0352c371e743d8dae996123f658b5d32c677614eYassir Elleyvoid test_populate_gplink_list_plain(void **state)
0352c371e743d8dae996123f658b5d32c677614eYassir Elley const char *gpo_dns[] = {"OU=Sales,DC=FOO,DC=COM", "DC=FOO,DC=COM"};
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_populate_gplink_list("[OU=Sales,DC=FOO,DC=COM;0][DC=FOO,DC=COM;2]",
0352c371e743d8dae996123f658b5d32c677614eYassir Elleyvoid test_populate_gplink_list_with_ignored(void **state)
0352c371e743d8dae996123f658b5d32c677614eYassir Elley const char *gpo_dns[] = {"OU=Sales,DC=FOO,DC=COM"};
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_populate_gplink_list("[OU=Sales,DC=FOO,DC=COM;0][DC=ignored;1]",
0352c371e743d8dae996123f658b5d32c677614eYassir Elleyvoid test_populate_gplink_list_with_allow_enforced(void **state)
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_populate_gplink_list("[OU=Sales,DC=FOO,DC=COM;0][DC=FOO,DC=COM;2]",
0352c371e743d8dae996123f658b5d32c677614eYassir Elleyvoid test_populate_gplink_list_malformed(void **state)
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_populate_gplink_list(NULL, false, &expected);
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_populate_gplink_list("[malformed]", false, &expected);
0352c371e743d8dae996123f658b5d32c677614eYassir Elley /* the GPLinkOptions value (after semicolon) must be between 0 and 3 */
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_populate_gplink_list("[gpo_dn; 4]", false, &expected);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * Test SID-matching logic
0352c371e743d8dae996123f658b5d32c677614eYassir Elleystatic void test_ad_gpo_ace_includes_client_sid(const char *user_sid,
0352c371e743d8dae996123f658b5d32c677614eYassir Elley err = sss_idmap_init(sss_idmap_talloc, tmp_ctx, sss_idmap_talloc_free,
0352c371e743d8dae996123f658b5d32c677614eYassir Elley ret = ad_gpo_ace_includes_client_sid(user_sid, group_sids, group_size,
0352c371e743d8dae996123f658b5d32c677614eYassir Elley assert_int_equal(includes_client_sid, expected);
0352c371e743d8dae996123f658b5d32c677614eYassir Elleyvoid test_ad_gpo_ace_includes_client_sid_true(void **state)
0352c371e743d8dae996123f658b5d32c677614eYassir Elley /* ace_dom_sid represents "S-1-5-21-2-3-4" */
0352c371e743d8dae996123f658b5d32c677614eYassir Elley struct dom_sid ace_dom_sid = {1, 4, {0, 0, 0, 0, 0, 5}, {21, 2, 3, 4}};
0352c371e743d8dae996123f658b5d32c677614eYassir Elley const char *user_sid = "S-1-5-21-1175337206-4250576914-2321192831-1103";
0352c371e743d8dae996123f658b5d32c677614eYassir Elley "S-1-5-21-2-3-5"};
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_ad_gpo_ace_includes_client_sid(user_sid, group_sids, group_size,
0352c371e743d8dae996123f658b5d32c677614eYassir Elleyvoid test_ad_gpo_ace_includes_client_sid_false(void **state)
0352c371e743d8dae996123f658b5d32c677614eYassir Elley /* ace_dom_sid represents "S-1-5-21-2-3-4" */
0352c371e743d8dae996123f658b5d32c677614eYassir Elley struct dom_sid ace_dom_sid = {1, 4, {0, 0, 0, 0, 0, 5}, {21, 2, 3, 4}};
0352c371e743d8dae996123f658b5d32c677614eYassir Elley const char *user_sid = "S-1-5-21-1175337206-4250576914-2321192831-1103";
0352c371e743d8dae996123f658b5d32c677614eYassir Elley "S-1-5-21-2-3-6"};
0352c371e743d8dae996123f658b5d32c677614eYassir Elley test_ad_gpo_ace_includes_client_sid(user_sid, group_sids, group_size,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_populate_som_list_plain,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_populate_som_list_malformed,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_populate_gplink_list_plain,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_populate_gplink_list_with_ignored,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_populate_gplink_list_with_allow_enforced,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_populate_gplink_list_malformed,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_ad_gpo_ace_includes_client_sid_true,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_ad_gpo_ace_includes_client_sid_false,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
0352c371e743d8dae996123f658b5d32c677614eYassir Elley pc = poptGetContext(argv[0], argc, argv, long_options, 0);