0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech/*
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech Authors:
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech Petr Čech <pcech@redhat.com>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech Copyright (C) 2017 Red Hat
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech This program is free software; you can redistribute it and/or modify
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech it under the terms of the GNU General Public License as published by
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech the Free Software Foundation; either version 3 of the License, or
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech (at your option) any later version.
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech This program is distributed in the hope that it will be useful,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech but WITHOUT ANY WARRANTY; without even the implied warranty of
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech GNU General Public License for more details.
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech You should have received a copy of the GNU General Public License
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech along with this program. If not, see <http://www.gnu.org/licenses/>.
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech*/
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <talloc.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <tevent.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <errno.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <popt.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <arpa/inet.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <netinet/in.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <sys/types.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <stdarg.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <stdlib.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include <pwd.h>
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include "tests/cmocka/common_mock.h"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include "tests/cmocka/common_mock_sysdb_objects.h"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include "tests/cmocka/common_mock_sdap.h"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include "providers/ad/ad_common.h"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include "providers/ad/ad_opts.c"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#include "providers/ldap/sdap_async_initgroups.c"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech/* Declarations from providers/ldap/sdap_async_initgroups.c */
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstruct sdap_get_initgr_state;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic int sdap_search_initgr_user_in_batch(struct sdap_get_initgr_state *state,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sysdb_attrs **users,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech size_t count);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define TESTS_PATH "tp_" BASE_FILE_STEM
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define TEST_CONF_DB "test_sdap_initgr_conf.ldb"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define TEST_ID_PROVIDER "ldap"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define TEST_DOM1_NAME "domain.test.com"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define TEST_DOM2_NAME "subdom1.domain.test.com"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define TEST_DOM3_NAME "another_domain.test.com"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define OBJECT_BASE_DN1 "dc=domain,dc=test,dc=com,cn=sysdb"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define OBJECT_BASE_DN2 "dc=subdom1,dc=domain,dc=test,dc=com,cn=sysdb"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define OBJECT_BASE_DN3 "dc=another_domain,dc=test,dc=com,cn=sysdb"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define TEST_USER_1 "test_user_1"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define TEST_USER_2 "test_user_2"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech#define TEST_USER_3 "test_user_3"
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechconst char *domains[] = { TEST_DOM1_NAME,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_DOM2_NAME,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_DOM3_NAME,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech NULL };
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechconst char *object_bases[] = { OBJECT_BASE_DN1,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech OBJECT_BASE_DN2,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech OBJECT_BASE_DN3,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech NULL };
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechconst char *test_users[] = { TEST_USER_1,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_USER_2,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_USER_3,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech NULL };
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech/* ====================== Utilities =============================== */
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstruct test_sdap_initgr_ctx {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_test_ctx *tctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech};
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic struct passwd **get_users(TALLOC_CTX *ctx)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct passwd **passwds = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech char *homedir = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech size_t user_count = 0;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech for (int i = 0; test_users[i] != NULL; i++) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user_count++;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwds = talloc_array(ctx, struct passwd *, user_count);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(passwds);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech for (int i = 0; i < user_count; i++) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwds[i] = talloc(passwds, struct passwd);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(passwds[i]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech homedir = talloc_strdup_append(homedir, "/home/");
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech homedir = talloc_strdup_append(homedir, test_users[i]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwds[i]->pw_name = discard_const(test_users[i]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwds[i]->pw_uid = 567 + i;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwds[i]->pw_gid = 890 + i;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwds[i]->pw_dir = talloc_strdup(passwds[i], homedir);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwds[i]->pw_gecos = discard_const(test_users[i]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwds[i]->pw_shell = discard_const("/bin/sh");
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwds[i]->pw_passwd = discard_const("*");
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(homedir);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return passwds;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic struct sss_test_conf_param **get_params(TALLOC_CTX *ctx)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_test_conf_param **params;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech char *user_base_dn = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech char *group_base_dn = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech size_t base_count = 0;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech for (int i = 0; object_bases[i] != NULL; i++) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech base_count++;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params = talloc_array(ctx, struct sss_test_conf_param *, base_count + 1);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(params);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech for (int i = 0; i < base_count; i++) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i] = talloc(params, struct sss_test_conf_param);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(params[i]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user_base_dn = talloc_strdup_append(user_base_dn, "cn=users,");
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user_base_dn = talloc_strdup_append(user_base_dn, object_bases[i]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech group_base_dn = talloc_strdup_append(group_base_dn, "cn=groups,");
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech group_base_dn = talloc_strdup_append(group_base_dn, object_bases[i]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i] = talloc_array(params[i], struct sss_test_conf_param, 5);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][0].key = "ldap_schema";
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][0].value = "rfc2307bis";
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][1].key = "ldap_search_base";
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][1].value = talloc_strdup(params[i], object_bases[i]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][2].key = "ldap_user_search_base";
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][2].value = talloc_strdup(params[i], user_base_dn);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][3].key = "ldap_group_search_base";
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][3].value = talloc_strdup(params[i], group_base_dn);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][4].key = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params[i][4].value = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(user_base_dn);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(group_base_dn);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return params;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstruct sss_domain_info *get_domain_info(struct sss_domain_info *domain,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const char *domain_name)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_domain_info *dom = domain;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech while(dom != NULL) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech if (strcmp(dom->name, domain_name) == 0) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech break;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech dom = dom->next;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return dom;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstruct sdap_get_initgr_state *prepare_state(struct test_sdap_initgr_ctx *ctx,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const char **domain_names)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sdap_get_initgr_state *state;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_domain_info *dom_info = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_domain_info *recent_dom_info = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech state = talloc_zero(ctx->tctx, struct sdap_get_initgr_state);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(state);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech for (int i=0; domain_names[i] != NULL; i++) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech dom_info = get_domain_info(ctx->tctx->dom, domain_names[i]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(dom_info);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech if (i == 0) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech state->dom = dom_info;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech recent_dom_info = state->dom;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech } else {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech recent_dom_info->next = dom_info;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech recent_dom_info = recent_dom_info->next;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(state->dom);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(recent_dom_info);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech recent_dom_info->next = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech state->opts = mock_sdap_options_ldap(state, state->dom,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ctx->tctx->confdb,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ctx->tctx->conf_dom_path);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(state->opts);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return state;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech/* TODO: This function is copied from test_nss_srv.c
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech * It could be fine move both to one place,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech * for example src/tests/common_sysdb.c
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech */
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic errno_t store_user(TALLOC_CTX *ctx,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_domain_info *dom,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct passwd *user,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sysdb_attrs *attrs,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech time_t cache_update)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech errno_t ret;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech char *fqname;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech fqname = sss_create_internal_fqname(ctx,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user->pw_name,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech dom->name);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech if (fqname == NULL) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return ENOMEM;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech /* Prime the cache with a valid user */
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = sysdb_store_user(dom,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech fqname,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user->pw_passwd,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user->pw_uid,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user->pw_gid,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user->pw_gecos,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user->pw_dir,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech user->pw_shell,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech NULL, attrs,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech NULL, 300, cache_update);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_free(fqname);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return ret;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech/* ====================== Setup =============================== */
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic int test_sdap_initgr_setup_one_domain(void **state)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct test_sdap_initgr_ctx *test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_test_conf_param **params;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_true(leak_check_setup());
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx = talloc_zero(global_talloc_context, struct test_sdap_initgr_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params = get_params(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(params);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_CONF_DB, domains[0],
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_ID_PROVIDER, params[0]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx->tctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech check_leaks_push(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech *state = test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return 0;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic int test_sdap_initgr_setup_multi_domains(void **state)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct test_sdap_initgr_ctx *test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_test_conf_param **params;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_true(leak_check_setup());
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx = talloc_zero(global_talloc_context, struct test_sdap_initgr_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params = get_params(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(params);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_CONF_DB, domains,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_ID_PROVIDER, params);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx->tctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech check_leaks_push(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech *state = test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return 0;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic int test_sdap_initgr_setup_other_multi_domains(void **state)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct test_sdap_initgr_ctx *test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_test_conf_param **params;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const char *domains_vith_other[] = { TEST_DOM1_NAME,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_DOM3_NAME,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech NULL };
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_true(leak_check_setup());
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx = talloc_zero(global_talloc_context, struct test_sdap_initgr_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech params = get_params(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(params);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_CONF_DB, domains_vith_other,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech TEST_ID_PROVIDER, params);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx->tctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech check_leaks_push(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech *state = test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return 0;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic int test_sdap_initgr_teardown(void **state)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct test_sdap_initgr_ctx *test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx = talloc_get_type(*state, struct test_sdap_initgr_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_true(check_leaks_pop(test_ctx) == true);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_free(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_true(leak_check_teardown());
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return 0;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech/* ====================== The tests =============================== */
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic void test_user_is_on_batch(void **state)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct test_sdap_initgr_ctx *test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sdap_get_initgr_state *initgr_state;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const char *domains_set[] = { domains[0], NULL };
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_domain_info *dom1_info = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_domain_info *dom2_info = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct passwd **passwd_users;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sysdb_attrs **users;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const char *user_name;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech errno_t ret;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx = talloc_get_type(*state, struct test_sdap_initgr_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech dom1_info = get_domain_info(test_ctx->tctx->dom, domains[0]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(dom1_info);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech dom2_info = get_domain_info(test_ctx->tctx->dom, domains[1]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(dom2_info);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech initgr_state = prepare_state(test_ctx, domains_set);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(initgr_state);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users = get_users(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(passwd_users);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = store_user(test_ctx, dom1_info, passwd_users[0], NULL, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = store_user(test_ctx, dom2_info, passwd_users[1], NULL, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech users = talloc_array(test_ctx, struct sysdb_attrs *, 2);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech users[0] = mock_sysdb_user(users, object_bases[0],
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users[0]->pw_uid,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users[0]->pw_name);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech users[1] = mock_sysdb_user(users, object_bases[1],
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users[1]->pw_uid,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users[1]->pw_name);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = sdap_search_initgr_user_in_batch(initgr_state, users, 2);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = sysdb_attrs_get_string(initgr_state->orig_user, "name", &user_name);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_string_equal(user_name, passwd_users[0]->pw_name);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(initgr_state);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(passwd_users);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(users);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic void test_user_is_from_subdomain(void **state)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct test_sdap_initgr_ctx *test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sdap_get_initgr_state *initgr_state;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const char *domains_set[] = { domains[0], NULL };
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_domain_info *dom_info = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct passwd **passwd_users;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sysdb_attrs **users;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const char *user_name;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech errno_t ret;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx = talloc_get_type(*state, struct test_sdap_initgr_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech dom_info = get_domain_info(test_ctx->tctx->dom, domains[0]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(dom_info);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech initgr_state = prepare_state(test_ctx, domains_set);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(initgr_state);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users = get_users(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(passwd_users);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = store_user(test_ctx, dom_info, passwd_users[0], NULL, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech users = talloc_array(test_ctx, struct sysdb_attrs *, 1);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech users[0] = mock_sysdb_user(users, object_bases[1],
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users[1]->pw_uid,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users[1]->pw_name);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const char *original_dn = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = sysdb_attrs_get_string(users[0], SYSDB_ORIG_DN, &original_dn);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = sdap_search_initgr_user_in_batch(initgr_state, users, 1);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = sysdb_attrs_get_string(initgr_state->orig_user, "name", &user_name);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_string_equal(user_name, passwd_users[1]->pw_name);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(initgr_state);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(passwd_users);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(users);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechstatic void test_user_is_from_another_domain(void **state)
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct test_sdap_initgr_ctx *test_ctx;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sdap_get_initgr_state *initgr_state;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const char *domains_set[] = { domains[0], domains[2], NULL };
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_domain_info *dom_info = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sss_domain_info *other_dom_info = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sdap_domain *other_sdom = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct passwd **passwd_users;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sysdb_attrs **users;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech errno_t ret;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_ctx = talloc_get_type(*state, struct test_sdap_initgr_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech dom_info = get_domain_info(test_ctx->tctx->dom, domains[0]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(dom_info);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech initgr_state = prepare_state(test_ctx, domains_set);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(initgr_state);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech other_dom_info = get_domain_info(test_ctx->tctx->dom, domains[2]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(other_dom_info);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = sdap_domain_add(initgr_state->opts, other_dom_info, &other_sdom);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, EOK);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(other_sdom->search_bases);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech other_sdom->search_bases = talloc_array(other_sdom,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct sdap_search_base *, 2);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(other_sdom->search_bases);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech other_sdom->search_bases[1] = NULL;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = sdap_create_search_base(other_sdom, object_bases[2],
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech LDAP_SCOPE_SUBTREE, NULL,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech &other_sdom->search_bases[0]);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, EOK);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users = get_users(test_ctx);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_non_null(passwd_users);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = store_user(test_ctx, dom_info, passwd_users[0], NULL, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech users = talloc_array(test_ctx, struct sysdb_attrs *, 1);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech users[0] = mock_sysdb_user(users, object_bases[2],
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users[2]->pw_uid,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech passwd_users[2]->pw_name);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech ret = sdap_search_initgr_user_in_batch(initgr_state, users, 1);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech assert_int_equal(ret, EINVAL);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(initgr_state);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(passwd_users);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech talloc_zfree(users);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čechint main(int argc, const char *argv[])
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech{
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech int rv;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech poptContext pc;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech int opt;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech struct poptOption long_options[] = {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech POPT_AUTOHELP
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech SSSD_DEBUG_OPTS
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech POPT_TABLEEND
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech };
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech const struct CMUnitTest tests[] = {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech cmocka_unit_test_setup_teardown(test_user_is_on_batch,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_sdap_initgr_setup_multi_domains,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_sdap_initgr_teardown),
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech cmocka_unit_test_setup_teardown(test_user_is_from_subdomain,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_sdap_initgr_setup_one_domain,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_sdap_initgr_teardown),
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech cmocka_unit_test_setup_teardown(test_user_is_from_another_domain,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_sdap_initgr_setup_other_multi_domains,
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_sdap_initgr_teardown),
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech };
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech debug_level = SSSDBG_INVALID;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech pc = poptGetContext(argv[0], argc, argv, long_options, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech while((opt = poptGetNextOpt(pc)) != -1) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech switch(opt) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech default:
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech fprintf(stderr, "\nInvalid option %s: %s\n\n",
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech poptBadOption(pc, 0), poptStrerror(opt));
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech poptPrintUsage(pc, stderr, 0);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return 1;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech poptFreeContext(pc);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech DEBUG_CLI_INIT(debug_level);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech tests_set_cwd();
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_dom_suite_setup(TESTS_PATH);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech rv = cmocka_run_group_tests(tests, NULL, NULL);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech if (rv == 0) {
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech }
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech return rv;
0b7ded15e53b3f31f1570c366f04bc41e5761929Petr Čech}