27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech Petr Čech <pcech@redhat.com>
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech Copyright (C) 2016 Red Hat
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech This program is free software; you can redistribute it and/or modify
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech it under the terms of the GNU General Public License as published by
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech the Free Software Foundation; either version 3 of the License, or
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech (at your option) any later version.
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech This program is distributed in the hope that it will be useful,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech but WITHOUT ANY WARRANTY; without even the implied warranty of
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech GNU General Public License for more details.
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech You should have received a copy of the GNU General Public License
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech along with this program. If not, see <http://www.gnu.org/licenses/>.
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech} rules[] = { { "test_rule1", "test_host1.test_domain.test", "root" },
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech { "test_rule2", "test_host2.test_domain.test", "root" },
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech { "test_rule3", "test_host3.test_domain.test", "root" } };
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cechstatic void create_groups(struct sss_domain_info *domain)
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_add_group(domain, TEST_GROUP_NAME, TEST_GID,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cechstatic void create_users(struct sss_domain_info *domain)
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech for (int i = 0; i < 3; i++) {
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_add_user(domain, users[i].name, users[i].uid, gid,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cechstatic void create_rule_attrs(struct sysdb_attrs *rule, int i)
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_CN,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_HOST,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_RUNASUSER,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_USER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čechstatic void create_rule_attrs_multiple_sudoUser(struct sysdb_attrs *rule)
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_CN,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_HOST,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_RUNASUSER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech for (int i = 0; i < 3; i++ ) {
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_USER,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cechstatic int get_stored_rules_count(struct sysdb_test_ctx *test_ctx)
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, NULL };
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech "(objectClass=sudoRule)",
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech test_ctx = talloc_zero(global_talloc_context, struct sysdb_test_ctx);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech test_ctx = talloc_get_type_abort(*state, struct sysdb_test_ctx);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek test_ctx = talloc_zero(global_talloc_context, struct sysdb_test_ctx);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_update_view_name(test_ctx->tctx->dom->sysdb, SYSDB_LOCAL_VIEW_NAME);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek sysdb_master_domain_update(test_ctx->tctx->dom);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozekstatic int test_sysdb_views_teardown(void **state)
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek test_ctx = talloc_get_type_abort(*state, struct sysdb_test_ctx);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, SYSDB_SUDO_CACHE_AT_HOST,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
61913b8f0d1ba54d82640500d7486fac5f72b030Pavel Březina filter = sysdb_sudo_filter_user(test_ctx, users[0].name, NULL, 0);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom, filter,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_CN, NULL);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_HOST,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_RUNASUSER,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, SYSDB_SUDO_CACHE_AT_HOST,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech const char *lowered_name = sss_tc_utf8_str_tolower(test_ctx, users[0].name);
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech filter = sysdb_sudo_filter_user(test_ctx, users[0].name, NULL, 0);
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom, filter,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_CN, NULL);
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_HOST,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_RUNASUSER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech element = ldb_msg_find_element(msgs[0], SYSDB_SUDO_CACHE_AT_USER);
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čechvoid test_store_sudo_case_insensitive(void **state)
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, SYSDB_SUDO_CACHE_AT_HOST,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech const char *lowered_name = sss_tc_utf8_str_tolower(test_ctx, users[0].name);
a5ecc93abb01cece628fdef04ebad43bba267419Jakub Hrozek ret = sysdb_attrs_add_lower_case_string(rule, false,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech filter = sysdb_sudo_filter_user(test_ctx, users[0].name, NULL, 0);
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom, filter,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_CN, NULL);
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_HOST,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_RUNASUSER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech for (int i = 0; i < 3; i++) {
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech /* test there is no duplication of lowercase forms */
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech element = ldb_msg_find_element(msgs[0], SYSDB_SUDO_CACHE_AT_USER);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 1);
61913b8f0d1ba54d82640500d7486fac5f72b030Pavel Březina delete_filter = sysdb_sudo_filter_user(test_ctx, users[0].name, NULL, 0);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_purge(test_ctx->tctx->dom, delete_filter, NULL, 0);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 0);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_purge(test_ctx->tctx->dom, NULL, &rule, 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 0);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cechvoid test_sudo_set_get_last_full_refresh(void **state)
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_set_last_full_refresh(test_ctx->tctx->dom, now);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_get_last_full_refresh(test_ctx->tctx->dom, &loaded_time);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech /* User 1 has group. */
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_get_sudo_user_info(test_ctx, test_ctx->tctx->dom, users[1].name,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_string_equal(groupnames[0], TEST_GROUP_NAME);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek assert_string_equal(orig_username, users[1].name);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozekvoid test_get_overriden_sudo_user_info(void **state)
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek /* Override user's name and primary UID */
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek user_fqname = sss_create_internal_fqname(test_ctx,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ldb_dn = sysdb_user_dn(attrs, test_ctx->tctx->dom, users[1].name);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek strdn = sysdb_user_strdn(attrs, test_ctx->tctx->dom->name, users[1].name);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_dn_sanitize(attrs, strdn, &safe_dn);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek anchor = talloc_asprintf(attrs, ":%s:%s", SYSDB_LOCAL_VIEW_NAME, safe_dn);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID, anchor);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, user_fqname);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_attrs_add_uint32(attrs, SYSDB_UIDNUM, OVERRIDE_UID);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_store_override(test_ctx->tctx->dom, SYSDB_LOCAL_VIEW_NAME,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek /* Override user's secondary group name */
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek group_fqname = sss_create_internal_fqname(test_ctx,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ldb_dn = sysdb_group_dn(attrs, test_ctx->tctx->dom, TEST_GROUP_NAME);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek strdn = sysdb_group_strdn(attrs, test_ctx->tctx->dom->name, TEST_GROUP_NAME);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_dn_sanitize(attrs, strdn, &safe_dn);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek anchor = talloc_asprintf(attrs, ":%s:%s", SYSDB_LOCAL_VIEW_NAME, safe_dn);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID, anchor);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, group_fqname);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_store_override(test_ctx->tctx->dom, SYSDB_LOCAL_VIEW_NAME,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek /* User must be searchable by their overriden name */
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_get_sudo_user_info(test_ctx, test_ctx->tctx->dom, user_fqname,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek /* sysdb_get_sudo_user_info must return the original values, not the
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek * overriden one */
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek assert_string_equal(groupnames[0], TEST_GROUP_NAME);
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek assert_string_equal(orig_username, users[1].name);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech /* User 0 hasn't group. */
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek ret = sysdb_get_sudo_user_info(test_ctx, test_ctx->tctx->dom, users[0].name,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek assert_string_equal(orig_username, users[0].name);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_get_sudo_user_info(test_ctx, test_ctx->tctx->dom,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, SYSDB_SUDO_CACHE_AT_COMMAND,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string(new_rule, SYSDB_SUDO_CACHE_AT_COMMAND,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech "test_command");
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_set_sudo_rule_attr(test_ctx->tctx->dom, rules[0].name,
61913b8f0d1ba54d82640500d7486fac5f72b030Pavel Březina filter = sysdb_sudo_filter_user(test_ctx, users[0].name, NULL, 0);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom, filter,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_CN, NULL);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_COMMAND,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, SYSDB_CACHE_EXPIRE, NULL };
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_time_t(new_rule, SYSDB_CACHE_EXPIRE, 10);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_set_sudo_rule_attr(test_ctx->tctx->dom, rules[0].name,
61913b8f0d1ba54d82640500d7486fac5f72b030Pavel Březina filter = sysdb_sudo_filter_user(test_ctx, users[0].name, NULL, 0);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom, filter,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_CN, NULL);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_CACHE_EXPIRE, NULL);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, SYSDB_SUDO_CACHE_AT_HOST,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 1);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string(new_rule, SYSDB_SUDO_CACHE_AT_HOST,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_set_sudo_rule_attr(test_ctx->tctx->dom, rules[0].name,
61913b8f0d1ba54d82640500d7486fac5f72b030Pavel Březina filter = sysdb_sudo_filter_user(test_ctx, users[0].name, NULL, 0);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom, filter,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_CN, NULL);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_HOST,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_store(test_ctx->tctx->dom, tmp_rules, 2);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 2);
61913b8f0d1ba54d82640500d7486fac5f72b030Pavel Březina filter = "(objectClass=" SYSDB_SUDO_CACHE_OC ")";
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom, filter,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech for (int i = 0; i < num_rules; ++i) {
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech db_results[i] = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_string_not_equal(db_results[0], db_results[1]);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_true(are_values_in_array(rule_names, num_rules,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, SYSDB_SUDO_CACHE_AT_HOST,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_store(test_ctx->tctx->dom, tmp_rules, 2);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 2);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech * We hit DST issue of time functions,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech * so we use big time shift to avoid this.
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech strftime(buff, 20, "%Y%m%d%H%M%S%z", localtime(&cur_time));
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string(tmp_attr, SYSDB_SUDO_CACHE_AT_NOTBEFORE, buff);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech strftime(buff, 20, "%Y%m%d%H%M%S%z", localtime(&cur_time));
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string(tmp_attr, SYSDB_SUDO_CACHE_AT_NOTAFTER, buff);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_set_sudo_rule_attr(test_ctx->tctx->dom, rules[0].name,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech strftime(buff, 20, "%Y%m%d%H%M%S%z", localtime(&cur_time));
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string(tmp_attr, SYSDB_SUDO_CACHE_AT_NOTBEFORE, buff);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech strftime(buff, 20, "%Y%m%d%H%M%S%z", localtime(&cur_time));
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_attrs_add_string(tmp_attr, SYSDB_SUDO_CACHE_AT_NOTAFTER, buff);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_set_sudo_rule_attr(test_ctx->tctx->dom, rules[1].name,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech assert_int_equal(get_stored_rules_count(test_ctx), 2);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech "(objectClass=sudoRule)",
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_msg2attrs(test_ctx, 2, msgs, &loaded_rules);
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech ret = sysdb_sudo_filter_rules_by_time(test_ctx, 2, loaded_rules, 0,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech /* sysdb_sudo_store() */
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech cmocka_unit_test_setup_teardown(test_store_sudo_case_sensitive,
23637e2fd2b1fe42bdd2335893a11ac8016f56bcPetr Čech cmocka_unit_test_setup_teardown(test_store_sudo_case_insensitive,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech /* sysdb_sudo_purge() */
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_sudo_purge_by_filter,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_sudo_purge_by_rules,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech * sysdb_sudo_set_last_full_refresh()
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech * sysdb_sudo_get_last_full_refresh()
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_sudo_set_get_last_full_refresh,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech /* sysdb_get_sudo_user_info() */
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_get_sudo_user_info,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_get_sudo_user_info_nogroup,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_get_sudo_nouser,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek /* The override tests use a different setup/teardown because loading
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek * the view allocates some data on the confdb and domain pointers,
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek * which would confuse the leak check
dee665060ba71ff61ad223e755ae61441118fbbaJakub Hrozek cmocka_unit_test_setup_teardown(test_get_overriden_sudo_user_info,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech /* sysdb_set_sudo_rule_attr() */
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_set_sudo_rule_attr_add,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_set_sudo_rule_attr_replace,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_set_sudo_rule_attr_delete,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech /* sysdb_search_sudo_rules() */
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_search_sudo_rules,
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech /* sysdb_sudo_filter_rules_by_time() */
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech cmocka_unit_test_setup_teardown(test_filter_rules_by_time,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
27a7dedb0ee4d4b51ca4c196aa894ad30cb3e821Petr Cech pc = poptGetContext(argv[0], argc, argv, long_options, 0);