72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek/*
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek Authors:
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek Copyright (C) 2013 Red Hat
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek SSSD tests: AD access control filter tests
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek This program is free software; you can redistribute it and/or modify
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek it under the terms of the GNU General Public License as published by
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek the Free Software Foundation; either version 3 of the License, or
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek (at your option) any later version.
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek This program is distributed in the hope that it will be useful,
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek GNU General Public License for more details.
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek You should have received a copy of the GNU General Public License
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek*/
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include <talloc.h>
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include <tevent.h>
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include <errno.h>
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include <popt.h>
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include <unistd.h>
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include <sys/types.h>
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include <ifaddrs.h>
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include <arpa/inet.h>
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#include "providers/ad/ad_pac.h"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#include "util/crypto/sss_crypto.h"
60e54ce78177b72ae82b8986e37dc4d09fce5681Lukas Slebodnik#ifdef HAVE_NSS
60e54ce78177b72ae82b8986e37dc4d09fce5681Lukas Slebodnik#include "util/crypto/nss/nss_util.h"
60e54ce78177b72ae82b8986e37dc4d09fce5681Lukas Slebodnik#endif
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#include "util/util_sss_idmap.h"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek/* In order to access opaque types */
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include "providers/ad/ad_common.c"
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#include "tests/cmocka/common_mock.h"
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek#include "tests/cmocka/common_mock_krb5.h"
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#define DOMNAME "domname"
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#define SUBDOMNAME "sub."DOMNAME
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#define REALMNAME DOMNAME
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek#define HOST_NAME "ad."REALMNAME
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik#define TESTS_PATH "tp_" BASE_FILE_STEM
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek#define TEST_AUTHID "host/"HOST_NAME
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek#define KEYTAB_TEST_PRINC TEST_AUTHID"@"REALMNAME
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik#define KEYTAB_PATH TESTS_PATH"/keytab_test.keytab"
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek#define ONEWAY_DOMNAME "ONEWAY"
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek#define ONEWAY_HOST_NAME "ad."ONEWAY_DOMNAME
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik#define ONEWAY_KEYTAB_PATH TESTS_PATH"/oneway_test.keytab"
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek#define ONEWAY_AUTHID "host/"ONEWAY_HOST_NAME
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek#define ONEWAY_TEST_PRINC ONEWAY_AUTHID"@"ONEWAY_DOMNAME
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#define TESTS_PATH "tp_" BASE_FILE_STEM
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#define TEST_CONF_DB "test_ad_sysdb.ldb"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#define TEST_ID_PROVIDER "ad"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#define TEST_DOM1_NAME "test_sysdb_subdomains_1"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#define TEST_DOM2_NAME "child2.test_sysdb_subdomains_2"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#define TEST_USER "test_user"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozekstatic bool call_real_sasl_options;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Boseconst char *domains[] = { TEST_DOM1_NAME,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose TEST_DOM2_NAME,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose NULL };
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bosestruct ad_sysdb_test_ctx {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct sss_test_ctx *tctx;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose};
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bosestatic int test_ad_sysdb_setup(void **state)
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose{
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_sysdb_test_ctx *test_ctx;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_true(leak_check_setup());
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ctx = talloc_zero(global_talloc_context,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_sysdb_test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_dom_suite_setup(TESTS_PATH);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose TEST_CONF_DB, domains,
f1e3364a72eb75673d10cf8c97ba8f1d7a385405Petr Čech TEST_ID_PROVIDER, NULL);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(test_ctx->tctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose *state = test_ctx;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose return 0;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose}
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bosestatic int test_ad_sysdb_teardown(void **state)
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose{
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_sysdb_test_ctx *test_ctx =
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_get_type(*state, struct ad_sysdb_test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_true(leak_check_teardown());
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose return 0;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose}
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bosestatic void test_check_if_pac_is_available(void **state)
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose{
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose int ret;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_sysdb_test_ctx *test_ctx =
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_get_type(*state, struct ad_sysdb_test_ctx);
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ldb_message *msg = NULL;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct sysdb_attrs *attrs;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = check_if_pac_is_available(NULL, NULL, NULL, NULL);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EINVAL);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ar = talloc_zero(test_ctx, struct dp_id_data);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(ar);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = check_if_pac_is_available(test_ctx, test_ctx->tctx->dom, ar, &msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EINVAL);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ar->filter_type = BE_FILTER_NAME;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ar->filter_value = discard_const(TEST_USER);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = check_if_pac_is_available(test_ctx, test_ctx->tctx->dom, ar, &msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, ENOENT);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = sysdb_add_user(test_ctx->tctx->dom, TEST_USER, 123, 456, NULL, NULL,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose NULL, NULL, NULL, 0, 0);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = check_if_pac_is_available(test_ctx, test_ctx->tctx->dom, ar, &msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, ENOENT);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose attrs = sysdb_new_attrs(test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(attrs);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_PAC_BLOB, "pac");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = sysdb_set_user_attr(test_ctx->tctx->dom, TEST_USER, attrs,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose SYSDB_MOD_REP);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose /* PAC available but too old */
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = check_if_pac_is_available(test_ctx, test_ctx->tctx->dom, ar, &msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, ENOENT);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(attrs);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose attrs = sysdb_new_attrs(test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(attrs);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = sysdb_attrs_add_time_t(attrs, SYSDB_PAC_BLOB_EXPIRE, 123);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = sysdb_set_user_attr(test_ctx->tctx->dom, TEST_USER, attrs,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose SYSDB_MOD_REP);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose /* PAC available but still too old */
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = check_if_pac_is_available(test_ctx, test_ctx->tctx->dom, ar, &msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, ENOENT);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(attrs);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose attrs = sysdb_new_attrs(test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(attrs);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = sysdb_attrs_add_time_t(attrs, SYSDB_PAC_BLOB_EXPIRE, time(NULL) + 10);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = sysdb_set_user_attr(test_ctx->tctx->dom, TEST_USER, attrs,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose SYSDB_MOD_REP);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose /* PAC available but still too old */
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = check_if_pac_is_available(test_ctx, test_ctx->tctx->dom, ar, &msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_string_equal(ldb_msg_find_attr_as_string(msg, SYSDB_NAME, "x"),
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose TEST_USER);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(attrs);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(ar);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose}
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#define TEST_PAC_BASE64 \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "BQAAAAAAAAABAAAA6AEAAFgAAAAAAAAACgAAABAAAABAAgAAAA" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "AAAAwAAAA4AAAAUAIAAAAAAAAGAAAAFAAAAIgCAAAAAAAABwAA" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "ABQAAACgAgAAAAAAAAEQCADMzMzM2AEAAAAAAAAAAAIA2hr35p" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "Ji0QH/////////f/////////9/4veKrwAP0AHit/TZyQ/QAf//" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "//////9/BgAGAAQAAgAGAAYACAACAAAAAAAMAAIAAAAAABAAAg" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "AAAAAAFAACAAAAAAAYAAIATwAAAFAEAAABAgAABQAAABwAAgAg" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "AAAAAAAAAAAAAAAAAAAAAAAAABIAFAAgAAIABAAGACQAAgAoAA" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "IAAAAAAAAAAAAQAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "AAAAAAEAAAAsAAIAAAAAAAAAAAAAAAAAAwAAAAAAAAADAAAAdA" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "B1ADEAAAADAAAAAAAAAAMAAAB0ACAAdQAAAAAAAAAAAAAAAAAA" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "UAAAD9ogAABwAAAAECAAAHAAAAXAQAAAcAAABWBAAABwAAAImm" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "AAAHAAAACgAAAAAAAAAJAAAAQQBEAC0AUwBFAFIAVgBFAFIAAA" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "ADAAAAAAAAAAIAAABBAEQABAAAAAEEAAAAAAAFFQAAAPgSE9xH" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "8xx2Ry8u1wEAAAAwAAIABwAAAAUAAAABBQAAAAAABRUAAAApyU" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "/ZwjzDeDZVh/hUBAAAgD5SqNxk0QEGAHQAdQAxABgAEAAQACgA" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "AAAAAAAAAAB0AHUAMQBAAGEAZAAuAGQAZQB2AGUAbABBAEQALg" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "BEAEUAVgBFAEwAdv///4yBQZ5ZQnp3qwj2lKGcd0UAAAAAdv//" \
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "/39fn4UneD5l6YxP8w/U0coAAAAA"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bosestatic void test_ad_get_data_from_pac(void **state)
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose{
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose int ret;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct PAC_LOGON_INFO *logon_info;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose uint8_t *test_pac_blob;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose size_t test_pac_blob_size;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_common_test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_pac_blob = sss_base64_decode(test_ctx, TEST_PAC_BASE64,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &test_pac_blob_size);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(test_pac_blob_size);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ad_get_data_from_pac(test_ctx, test_pac_blob, test_pac_blob_size,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &logon_info);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(logon_info);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_string_equal(logon_info->info3.base.account_name.string, "tu1");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_string_equal(logon_info->info3.base.full_name.string, "t u");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(logon_info->info3.base.rid, 1104);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(logon_info->info3.base.primary_gid, 513);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(logon_info->info3.base.groups.count, 5);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_string_equal(logon_info->info3.base.logon_domain.string, "AD");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(logon_info->info3.sidcount, 1);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(test_pac_blob);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(logon_info);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose}
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bosestatic void test_ad_get_sids_from_pac(void **state)
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose{
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose int ret;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct PAC_LOGON_INFO *logon_info;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose uint8_t *test_pac_blob;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose size_t test_pac_blob_size;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose char *user_sid;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose char *primary_group_sid;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose size_t num_sids;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose char **sid_list;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct sss_idmap_ctx *idmap_ctx;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose enum idmap_error_code err;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose size_t c;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose size_t s;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose const char *sid_check_list[] = { "S-1-5-21-3692237560-1981608775-3610128199-513",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-1110",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-1116",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-41725",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-42633",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3645884713-2026060994-4169618742-1108",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose NULL };
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_common_test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose err = sss_idmap_init(sss_idmap_talloc, test_ctx, sss_idmap_talloc_free,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &idmap_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(err, IDMAP_SUCCESS);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_pac_blob = sss_base64_decode(test_ctx, TEST_PAC_BASE64,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &test_pac_blob_size);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(test_pac_blob_size);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ad_get_data_from_pac(test_ctx, test_pac_blob, test_pac_blob_size,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &logon_info);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ad_get_sids_from_pac(test_ctx, idmap_ctx, logon_info, &user_sid,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &primary_group_sid, &num_sids, &sid_list);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_string_equal(user_sid,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-1104");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_string_equal(primary_group_sid,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-513");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(num_sids, 6);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose for (c = 0; sid_check_list[c] != NULL; c++) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose for (s = 0; s < num_sids; s++) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (strcmp(sid_check_list[c], sid_list[s]) == 0) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose break;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (s == num_sids) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose fail_msg("SID [%s] not found in SID list.", sid_check_list[c]);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(test_pac_blob);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(logon_info);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(user_sid);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(primary_group_sid);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(sid_list);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose sss_idmap_free(idmap_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose}
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bosestatic void test_ad_get_pac_data_from_user_entry(void **state)
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose{
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose int ret;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ldb_message *user_msg;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ldb_val val;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ad_common_test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct sss_idmap_ctx *idmap_ctx;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose enum idmap_error_code err;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose char *username;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose char *user_sid;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose char *primary_group_sid;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose size_t num_sids;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose char **sid_list;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose size_t c;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose size_t s;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose const char *sid_check_list[] = { "S-1-5-21-3692237560-1981608775-3610128199-513",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-1110",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-1116",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-41725",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-42633",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3645884713-2026060994-4169618742-1108",
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose NULL };
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose err = sss_idmap_init(sss_idmap_talloc, test_ctx, sss_idmap_talloc_free,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &idmap_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(err, IDMAP_SUCCESS);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose user_msg = ldb_msg_new(test_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_non_null(user_msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ldb_msg_add_string(user_msg, SYSDB_NAME, "username");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose ret = ldb_msg_add_string(user_msg, SYSDB_OBJECTCATEGORY, SYSDB_USER_CLASS);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ldb_msg_add_string(user_msg, SYSDB_PAC_BLOB_EXPIRE, "12345");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose val.data = sss_base64_decode(test_ctx, TEST_PAC_BASE64, &val.length);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ldb_msg_add_value(user_msg, SYSDB_PAC_BLOB, &val, NULL);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ad_get_pac_data_from_user_entry(test_ctx, user_msg, idmap_ctx,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &username, &user_sid,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &primary_group_sid, &num_sids,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose &sid_list);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(ret, EOK);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_string_equal(username, "username");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_string_equal(user_sid,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-1104");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_string_equal(primary_group_sid,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose "S-1-5-21-3692237560-1981608775-3610128199-513");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose assert_int_equal(num_sids, 6);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose for (c = 0; sid_check_list[c] != NULL; c++) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose for (s = 0; s < num_sids; s++) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (strcmp(sid_check_list[c], sid_list[s]) == 0) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose break;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (s == num_sids) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose fail_msg("SID [%s] not found in SID list.", sid_check_list[c]);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(username);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(user_sid);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(primary_group_sid);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(sid_list);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(val.data);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(user_msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose sss_idmap_free(idmap_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose}
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozekkrb5_error_code __wrap_krb5_kt_default(krb5_context context, krb5_keytab *id)
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek{
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek return krb5_kt_resolve(context, KEYTAB_PATH, id);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek}
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozekstruct ad_common_test_ctx {
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_id_ctx *ad_ctx;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_id_ctx *subdom_ad_ctx;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct sss_domain_info *dom;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct sss_domain_info *subdom;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek};
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozekstatic int test_ad_common_setup(void **state)
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek{
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_common_test_ctx *test_ctx;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik test_dom_suite_setup(TESTS_PATH);
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_true(leak_check_setup());
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek test_ctx = talloc_zero(global_talloc_context, struct ad_common_test_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(test_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek test_ctx->dom = talloc_zero(test_ctx, struct sss_domain_info);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(test_ctx->dom);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek test_ctx->dom->name = discard_const(DOMNAME);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek test_ctx->subdom = talloc_zero(test_ctx, struct sss_domain_info);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(test_ctx->subdom);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek test_ctx->subdom->name = discard_const(SUBDOMNAME);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek test_ctx->subdom->parent = test_ctx->dom;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek test_ctx->ad_ctx = talloc_zero(test_ctx, struct ad_id_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_non_null(test_ctx->ad_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek check_leaks_push(test_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek *state = test_ctx;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek return 0;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek}
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozekstatic int test_ad_common_teardown(void **state)
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek{
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik int ret;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek struct ad_common_test_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_non_null(test_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_true(check_leaks_pop(test_ctx) == true);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek talloc_free(test_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_true(leak_check_teardown());
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik ret = rmdir(TESTS_PATH);
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik assert_return_code(ret, errno);
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek return 0;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek}
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozekstatic void test_ad_create_1way_trust_options(void **state)
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek{
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek struct ad_common_test_ctx);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek const char *s;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek call_real_sasl_options = true;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek /* Make sure this is not the keytab that __wrap_krb5_kt_default uses */
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek mock_keytab_with_contents(test_ctx, ONEWAY_KEYTAB_PATH, ONEWAY_TEST_PRINC);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek test_ctx->subdom->name = discard_const(ONEWAY_DOMNAME);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek test_ctx->ad_ctx->ad_options = ad_create_1way_trust_options(
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek test_ctx->ad_ctx,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek NULL,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek NULL,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek NULL,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek test_ctx->subdom,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek ONEWAY_HOST_NAME,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek ONEWAY_KEYTAB_PATH,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek ONEWAY_AUTHID);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_non_null(test_ctx->ad_ctx->ad_options);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_int_equal(test_ctx->ad_ctx->ad_options->id->schema_type,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek SDAP_SCHEMA_AD);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->basic,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek AD_KRB5_REALM);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_non_null(s);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_string_equal(s, ONEWAY_DOMNAME);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->basic,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek AD_DOMAIN);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_non_null(s);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_string_equal(s, ONEWAY_DOMNAME);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->basic,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek AD_HOSTNAME);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_non_null(s);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_string_equal(s, ONEWAY_HOST_NAME);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->basic,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek AD_KEYTAB);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_non_null(s);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_string_equal(s, ONEWAY_KEYTAB_PATH);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek SDAP_KRB5_KEYTAB);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_non_null(s);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek SDAP_SASL_REALM);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_non_null(s);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_string_equal(s, ONEWAY_DOMNAME);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek SDAP_KRB5_REALM);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_non_null(s);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_string_equal(s, ONEWAY_DOMNAME);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek SDAP_SASL_AUTHID);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_non_null(s);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek assert_string_equal(s, ONEWAY_AUTHID);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek talloc_free(test_ctx->ad_ctx->ad_options);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek unlink(ONEWAY_KEYTAB_PATH);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek}
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozekstatic void test_ad_create_2way_trust_options(void **state)
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek{
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek struct ad_common_test_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek const char *s;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek call_real_sasl_options = true;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek mock_keytab_with_contents(test_ctx, KEYTAB_PATH, KEYTAB_TEST_PRINC);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek test_ctx->subdom->name = discard_const(DOMNAME);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek test_ctx->ad_ctx->ad_options = ad_create_2way_trust_options(
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek test_ctx->ad_ctx,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek NULL,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek NULL,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek NULL,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek REALMNAME,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek test_ctx->subdom,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek HOST_NAME,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek NULL);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_non_null(test_ctx->ad_ctx->ad_options);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_int_equal(test_ctx->ad_ctx->ad_options->id->schema_type,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek SDAP_SCHEMA_AD);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->basic,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek AD_KRB5_REALM);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_non_null(s);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_string_equal(s, REALMNAME);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->basic,
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek AD_DOMAIN);
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek assert_non_null(s);
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek assert_string_equal(s, DOMNAME);
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->basic,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek AD_HOSTNAME);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_non_null(s);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_string_equal(s, HOST_NAME);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek SDAP_KRB5_KEYTAB);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_null(s); /* This is the system keytab */
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek SDAP_SASL_REALM);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_non_null(s);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_string_equal(s, REALMNAME);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek SDAP_KRB5_REALM);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_non_null(s);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_string_equal(s, REALMNAME);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek SDAP_SASL_AUTHID);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_non_null(s);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_string_equal(s, TEST_AUTHID);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek talloc_free(test_ctx->ad_ctx->ad_options);
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik unlink(KEYTAB_PATH);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek}
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozekstatic int
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozektest_ldap_conn_setup(void **state)
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek{
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek struct ad_common_test_ctx *test_ctx;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek errno_t ret;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek struct sdap_domain *sdom;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek struct ad_id_ctx *ad_ctx;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek struct ad_id_ctx *subdom_ad_ctx;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek struct sdap_id_conn_ctx *subdom_ldap_ctx;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek ret = test_ad_common_setup((void **) &test_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek assert_int_equal(ret, EOK);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik mock_keytab_with_contents(test_ctx, KEYTAB_PATH, KEYTAB_TEST_PRINC);
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek ad_ctx = test_ctx->ad_ctx;
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek test_ctx->ad_ctx->ad_options = ad_create_2way_trust_options(
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ad_ctx,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek NULL,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek NULL,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek NULL,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek REALMNAME,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek test_ctx->subdom,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek HOST_NAME,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek NULL);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(ad_ctx->ad_options);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek ad_ctx->gc_ctx = talloc_zero(ad_ctx, struct sdap_id_conn_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(ad_ctx->gc_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek ad_ctx->ldap_ctx = talloc_zero(ad_ctx, struct sdap_id_conn_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(ad_ctx->ldap_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek ad_ctx->sdap_id_ctx = talloc_zero(ad_ctx, struct sdap_id_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(ad_ctx->sdap_id_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek ad_ctx->sdap_id_ctx->opts = talloc_zero(ad_ctx->sdap_id_ctx,
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct sdap_options);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(ad_ctx->sdap_id_ctx->opts);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek ret = sdap_domain_add(ad_ctx->sdap_id_ctx->opts, test_ctx->dom, &sdom);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_int_equal(ret, EOK);
e2bd4f8a41b72aea0712ad21ad02ccebb707f536Stephen Gallagher sdom->pvt = ad_ctx;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek subdom_ad_ctx = talloc_zero(test_ctx, struct ad_id_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(subdom_ad_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek subdom_ldap_ctx = talloc_zero(subdom_ad_ctx, struct sdap_id_conn_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(subdom_ldap_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek subdom_ad_ctx->ldap_ctx = subdom_ldap_ctx;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek ret = sdap_domain_add(ad_ctx->sdap_id_ctx->opts, test_ctx->subdom, &sdom);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_int_equal(ret, EOK);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek sdom->pvt = subdom_ad_ctx;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek test_ctx->subdom_ad_ctx = subdom_ad_ctx;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek *state = test_ctx;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek}
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozektest_ldap_conn_teardown(void **state)
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek{
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_common_test_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(test_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik unlink(KEYTAB_PATH);
295c8e301e31f9bf27d921f80c14dfa5864b2383Lukas Slebodnik
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek talloc_free(test_ctx->subdom_ad_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek talloc_free(test_ctx->ad_ctx->ad_options);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek talloc_free(test_ctx->ad_ctx->gc_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek talloc_free(test_ctx->ad_ctx->ldap_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek talloc_free(test_ctx->ad_ctx->sdap_id_ctx);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek test_ad_common_teardown((void **) &test_ctx);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek}
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozekerrno_t
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek__real_sdap_set_sasl_options(struct sdap_options *id_opts,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek char *default_primary,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek char *default_realm,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek const char *keytab_path);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozekerrno_t
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek__wrap_sdap_set_sasl_options(struct sdap_options *id_opts,
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek char *default_primary,
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek char *default_realm,
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek const char *keytab_path)
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek{
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek /* Pretend SASL is fine */
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek if (call_real_sasl_options == true) {
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek return __real_sdap_set_sasl_options(id_opts,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek default_primary,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek default_realm,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek keytab_path);
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek }
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek return EOK;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek}
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozekvoid test_ad_get_dom_ldap_conn(void **state)
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek{
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct sdap_id_conn_ctx *conn;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_common_test_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(test_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek conn = ad_get_dom_ldap_conn(test_ctx->ad_ctx, test_ctx->dom);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_true(conn == test_ctx->ad_ctx->ldap_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek conn = ad_get_dom_ldap_conn(test_ctx->ad_ctx, test_ctx->subdom);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_true(conn == test_ctx->subdom_ad_ctx->ldap_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek}
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozekvoid test_gc_conn_list(void **state)
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek{
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct sdap_id_conn_ctx **conn_list;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_common_test_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(test_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek assert_true(dp_opt_get_bool(test_ctx->ad_ctx->ad_options->basic,
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek AD_ENABLE_GC));
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek conn_list = ad_gc_conn_list(test_ctx, test_ctx->ad_ctx, test_ctx->dom);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(conn_list);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_true(conn_list[0] == test_ctx->ad_ctx->gc_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek /* If there is a fallback, we should ignore the offline mode */
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_true(conn_list[0]->ignore_mark_offline);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_true(conn_list[1] == test_ctx->ad_ctx->ldap_ctx);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_false(conn_list[1]->ignore_mark_offline);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_null(conn_list[2]);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek talloc_free(conn_list);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek conn_list = ad_gc_conn_list(test_ctx, test_ctx->ad_ctx, test_ctx->subdom);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_non_null(conn_list);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek assert_true(conn_list[0] == test_ctx->ad_ctx->gc_ctx);
266110fa0f6eb086f8f88787bb167cea416fe108Jakub Hrozek assert_true(conn_list[0]->ignore_mark_offline);
266110fa0f6eb086f8f88787bb167cea416fe108Jakub Hrozek assert_true(conn_list[1] == test_ctx->subdom_ad_ctx->ldap_ctx);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek /* Subdomain error should not set the backend offline! */
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_true(conn_list[1]->ignore_mark_offline);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek talloc_free(conn_list);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek dp_opt_set_bool(test_ctx->ad_ctx->ad_options->basic, AD_ENABLE_GC, false);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek assert_false(dp_opt_get_bool(test_ctx->ad_ctx->ad_options->basic,
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek AD_ENABLE_GC));
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek conn_list = ad_gc_conn_list(test_ctx, test_ctx->ad_ctx, test_ctx->dom);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek assert_non_null(conn_list);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek assert_true(conn_list[0] == test_ctx->ad_ctx->ldap_ctx);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek assert_false(conn_list[0]->ignore_mark_offline);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek assert_null(conn_list[1]);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek talloc_free(conn_list);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek conn_list = ad_gc_conn_list(test_ctx, test_ctx->ad_ctx, test_ctx->subdom);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek assert_non_null(conn_list);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek
266110fa0f6eb086f8f88787bb167cea416fe108Jakub Hrozek assert_true(conn_list[0] == test_ctx->subdom_ad_ctx->ldap_ctx);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_true(conn_list[0]->ignore_mark_offline);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_null(conn_list[1]);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek talloc_free(conn_list);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek}
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozekvoid test_ldap_conn_list(void **state)
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek{
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek struct sdap_id_conn_ctx **conn_list;
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek struct ad_common_test_ctx);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_non_null(test_ctx);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek conn_list = ad_ldap_conn_list(test_ctx,
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek test_ctx->ad_ctx,
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek test_ctx->dom);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_non_null(conn_list);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_true(conn_list[0] == test_ctx->ad_ctx->ldap_ctx);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_false(conn_list[0]->ignore_mark_offline);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_null(conn_list[1]);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek talloc_free(conn_list);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek conn_list = ad_ldap_conn_list(test_ctx,
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek test_ctx->ad_ctx,
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek test_ctx->subdom);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_non_null(conn_list);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_true(conn_list[0] == test_ctx->subdom_ad_ctx->ldap_ctx);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_true(conn_list[0]->ignore_mark_offline);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek assert_null(conn_list[1]);
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek talloc_free(conn_list);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek}
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozekvoid test_user_conn_list(void **state)
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek{
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek struct sdap_id_conn_ctx **conn_list;
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek struct ad_common_test_ctx);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_non_null(test_ctx);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
e6ad16e05f42a1678a8c6cd14eb54ca75b8d775eSumit Bose conn_list = ad_user_conn_list(test_ctx, test_ctx->ad_ctx,
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek test_ctx->dom);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_non_null(conn_list);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_true(conn_list[0] == test_ctx->ad_ctx->ldap_ctx);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_false(conn_list[0]->ignore_mark_offline);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_null(conn_list[1]);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek talloc_free(conn_list);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
e6ad16e05f42a1678a8c6cd14eb54ca75b8d775eSumit Bose conn_list = ad_user_conn_list(test_ctx, test_ctx->ad_ctx,
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek test_ctx->subdom);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_non_null(conn_list);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_true(conn_list[0] == test_ctx->ad_ctx->gc_ctx);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_true(conn_list[0]->ignore_mark_offline);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_true(conn_list[1] == test_ctx->subdom_ad_ctx->ldap_ctx);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek /* Subdomain error should not set the backend offline! */
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek assert_true(conn_list[1]->ignore_mark_offline);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek talloc_free(conn_list);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek}
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bosevoid test_netlogon_get_domain_info(void **state)
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose{
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose int ret;
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose struct sysdb_attrs *attrs;
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose struct ldb_val val = { 0 };
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose char *flat_name;
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose char *site;
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose char *forest;
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose struct ad_common_test_ctx);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_non_null(test_ctx);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose attrs = sysdb_new_attrs(test_ctx);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_non_null(attrs);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose ret = netlogon_get_domain_info(test_ctx, attrs, false, NULL, NULL, NULL);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_int_equal(ret, ENOENT);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose ret = sysdb_attrs_add_val(attrs, AD_AT_NETLOGON, &val);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_int_equal(ret, EOK);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose ret = netlogon_get_domain_info(test_ctx, attrs, false, NULL, NULL, NULL);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_int_equal(ret, EBADMSG);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(attrs);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose attrs = sysdb_new_attrs(test_ctx);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_non_null(attrs);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose val.data = sss_base64_decode(test_ctx, "FwAAAP0zAABsGcIYI7j2TL97Rd+TvpATAmFkBWRldmVsAMAYCWFkLXNlcnZlcsAYAkFEAAlBRC1TRVJWRVIAABdEZWZhdWx0LUZpcnN0LVNpdGUtTmFtZQDAQAUAAAD/////", &val.length);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_non_null(val.data);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose ret = sysdb_attrs_add_val(attrs, AD_AT_NETLOGON, &val);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_int_equal(ret, EOK);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose ret = netlogon_get_domain_info(test_ctx, attrs, false, &flat_name, &site, &forest);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_int_equal(ret, EOK);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_string_equal(flat_name, "AD");
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_string_equal(site, "Default-First-Site-Name");
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_string_equal(forest, "ad.devel");
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose /* missing site */
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(flat_name);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(site);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(forest);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(val.data);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(attrs);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose attrs = sysdb_new_attrs(test_ctx);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_non_null(attrs);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose val.data = sss_base64_decode(test_ctx, "FwAAAH0zAABsGcIYI7j2TL97Rd+TvpATAmFkBWRldmVsAMAYCWFkLXNlcnZlcsAYAkFEAAlBRC1TRVJWRVIAABdEZWZhdWx0LUZpcnN0LVNpdGUtTmFtZQAABQAAAP////8=", &val.length);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_non_null(val.data);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose ret = sysdb_attrs_add_val(attrs, AD_AT_NETLOGON, &val);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_int_equal(ret, EOK);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose ret = netlogon_get_domain_info(test_ctx, attrs, false, &flat_name, &site, &forest);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_int_equal(ret, EOK);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_string_equal(flat_name, "AD");
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_null(site);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_string_equal(forest, "ad.devel");
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(flat_name);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(site);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(forest);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose ret = netlogon_get_domain_info(test_ctx, attrs, true, &flat_name, &site, &forest);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_int_equal(ret, EOK);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_string_equal(flat_name, "AD");
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_null(site);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose assert_string_equal(forest, "ad.devel");
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(flat_name);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(site);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(forest);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(val.data);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose talloc_free(attrs);
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose}
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozekint main(int argc, const char *argv[])
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek{
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek poptContext pc;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek int opt;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose int ret;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct poptOption long_options[] = {
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek POPT_AUTOHELP
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek SSSD_DEBUG_OPTS
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek POPT_TABLEEND
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek };
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek cmocka_unit_test_setup_teardown(test_ad_create_1way_trust_options,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek test_ad_common_setup,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek test_ad_common_teardown),
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek cmocka_unit_test_setup_teardown(test_ad_create_2way_trust_options,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek test_ad_common_setup,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek test_ad_common_teardown),
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek cmocka_unit_test_setup_teardown(test_ad_get_dom_ldap_conn,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek test_ldap_conn_setup,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek test_ldap_conn_teardown),
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek cmocka_unit_test_setup_teardown(test_gc_conn_list,
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek test_ldap_conn_setup,
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek test_ldap_conn_teardown),
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek cmocka_unit_test_setup_teardown(test_ldap_conn_list,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek test_ldap_conn_setup,
51b5e1475b3e0b7acac34ed382cfaca8411883a4Jakub Hrozek test_ldap_conn_teardown),
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek cmocka_unit_test_setup_teardown(test_user_conn_list,
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek test_ldap_conn_setup,
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek test_ldap_conn_teardown),
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose cmocka_unit_test_setup_teardown(test_check_if_pac_is_available,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ad_sysdb_setup,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ad_sysdb_teardown),
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose cmocka_unit_test_setup_teardown(test_ad_get_data_from_pac,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ad_common_setup,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ad_common_teardown),
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose cmocka_unit_test_setup_teardown(test_ad_get_sids_from_pac,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ad_common_setup,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ad_common_teardown),
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose cmocka_unit_test_setup_teardown(test_ad_get_pac_data_from_user_entry,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ad_common_setup,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose test_ad_common_teardown),
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose cmocka_unit_test_setup_teardown(test_netlogon_get_domain_info,
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose test_ad_common_setup,
7fe7073ad2c84946a699528a3bb79f7803c96b69Sumit Bose test_ad_common_teardown),
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek };
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek debug_level = SSSDBG_INVALID;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek switch(opt) {
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek default:
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek poptPrintUsage(pc, stderr, 0);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek return 1;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek }
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek }
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek poptFreeContext(pc);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug_level);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek tests_set_cwd();
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = cmocka_run_group_tests(tests, NULL, NULL);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#ifdef HAVE_NSS
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Cleanup NSS and NSPR to make Valgrind happy. */
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose nspr_nss_cleanup();
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#endif
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose return ret;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek}