36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce/*
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce SSSD
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce debug-tests.c
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce Authors:
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce Simo Sorce <simo@redhat.com>
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce Copyright (C) 2013 Red Hat
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce This program is free software; you can redistribute it and/or modify
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce it under the terms of the GNU General Public License as published by
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce the Free Software Foundation; either version 3 of the License, or
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce (at your option) any later version.
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce This program is distributed in the hope that it will be useful,
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce but WITHOUT ANY WARRANTY; without even the implied warranty of
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce GNU General Public License for more details.
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce You should have received a copy of the GNU General Public License
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce along with this program. If not, see <http://www.gnu.org/licenses/>.
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce*/
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
bacc66dc6f446d47be18b61d569721481d70386bLukas Slebodnik#include "config.h"
bacc66dc6f446d47be18b61d569721481d70386bLukas Slebodnik
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#include <stdbool.h>
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#include <dlfcn.h>
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#include <stdio.h>
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#include <stdlib.h>
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#include <limits.h>
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#include <check.h>
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik#include <dirent.h>
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#include "tests/common.h"
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
bacc66dc6f446d47be18b61d569721481d70386bLukas Slebodnik#define LIBPFX ABS_BUILD_DIR "/" LT_OBJDIR
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorcestruct so {
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce const char *name;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce const char *libs[6];
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce} so[] = {
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_debug.so", { LIBPFX"libsss_debug.so", NULL } },
42ec8af02ecf1937e4db9b1ecc6216022634f0f9Michal Zidek { "libsss_semanage.so", { LIBPFX"libsss_semanage.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libipa_hbac.so", { LIBPFX"libipa_hbac.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_idmap.so", { LIBPFX"libsss_idmap.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_nss_idmap.so", { LIBPFX"libsss_nss_idmap.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libnss_sss.so", { LIBPFX"libnss_sss.so", NULL } },
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose { "libsss_certmap.so", { LIBPFX"libsss_certmap.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "pam_sss.so", { LIBPFX"pam_sss.so", NULL } },
25cd72fd477acaecbb827b68f0a425ccb79c184cSumit Bose#ifdef BUILD_LIBWBCLIENT
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose { "libwbclient.so", { LIBPFX"libwbclient.so", NULL } },
25cd72fd477acaecbb827b68f0a425ccb79c184cSumit Bose#endif /* BUILD_LIBWBCLIENT */
7a6a7db9a535d6cceb61c080594c67feccbcea12Lukas Slebodnik#ifdef BUILD_IFP
7a6a7db9a535d6cceb61c080594c67feccbcea12Lukas Slebodnik { "libsss_simpleifp.so", { LIBPFX"libsss_simpleifp.so", NULL } },
7a6a7db9a535d6cceb61c080594c67feccbcea12Lukas Slebodnik#endif /* BUILD_IFP */
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#ifdef BUILD_SUDO
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_sudo.so", { LIBPFX"libsss_sudo.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#endif
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#ifdef BUILD_AUTOFS
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_autofs.so", { LIBPFX"libsss_autofs.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#endif
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#ifdef HAVE_KRB5_LOCATOR_PLUGIN
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "sssd_krb5_locator_plugin.so", { LIBPFX"sssd_krb5_locator_plugin.so",
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#endif
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose#ifdef HAVE_KRB5_LOCALAUTH_PLUGIN
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose { "sssd_krb5_localauth_plugin.so", { LIBPFX"sssd_krb5_localauth_plugin.so",
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose NULL } },
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose#endif
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#ifdef HAVE_PAC_RESPONDER
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "sssd_pac_plugin.so", { LIBPFX"sssd_pac_plugin.so", NULL } },
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke#endif
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke#ifdef HAVE_CIFS_IDMAP_PLUGIN
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke { "cifs_idmap_sss.so", { LIBPFX"cifs_idmap_sss.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#endif
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "memberof.so", { LIBPFX"memberof.so", NULL } },
5a05b6127064c74349f1edae32e5e13032c386feLukas Slebodnik { "libsss_child.so", { LIBPFX"libsss_util.so",
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce LIBPFX"libsss_child.so", NULL } },
5a05b6127064c74349f1edae32e5e13032c386feLukas Slebodnik { "libsss_crypt.so", { LIBPFX"libsss_crypt.so", NULL } },
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik { "libsss_cert.so", { LIBPFX"libsss_cert.so", NULL } },
5a05b6127064c74349f1edae32e5e13032c386feLukas Slebodnik { "libsss_util.so", { LIBPFX"libsss_util.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_simple.so", { LIBPFX"libdlopen_test_providers.so",
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce LIBPFX"libsss_simple.so", NULL } },
c71e0a6710418991d759a329b8dcb77c7ad3e16eJakub Hrozek { "libsss_files.so", { LIBPFX"libdlopen_test_providers.so",
c71e0a6710418991d759a329b8dcb77c7ad3e16eJakub Hrozek LIBPFX"libsss_files.so", NULL } },
a2e417f38c57ed87c956ddcecf4dafca93842b65Lukas Slebodnik#ifdef BUILD_SAMBA
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_ad.so", { LIBPFX"libdlopen_test_providers.so",
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce LIBPFX"libsss_ad.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_ipa.so", { LIBPFX"libdlopen_test_providers.so",
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce LIBPFX"libsss_ipa.so", NULL } },
d708e53d0df0c1ed4cc0097bebfa2a84d7b20fadLukas Slebodnik { "winbind_idmap_sss.so", { LIBPFX"libdlopen_test_winbind_idmap.so",
d708e53d0df0c1ed4cc0097bebfa2a84d7b20fadLukas Slebodnik LIBPFX"winbind_idmap_sss.so", NULL } },
a2e417f38c57ed87c956ddcecf4dafca93842b65Lukas Slebodnik#endif /* BUILD_SAMBA */
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_krb5.so", { LIBPFX"libdlopen_test_providers.so",
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce LIBPFX"libsss_krb5.so", NULL } },
a25942bc2f6ac9b3b2817ede35fa2b445373c6e4Lukas Slebodnik { "libsss_krb5_common.so", { LIBPFX"libdlopen_test_providers.so",
a25942bc2f6ac9b3b2817ede35fa2b445373c6e4Lukas Slebodnik LIBPFX"libsss_krb5_common.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_ldap.so", { LIBPFX"libdlopen_test_providers.so",
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce LIBPFX"libsss_ldap.so", NULL } },
a25942bc2f6ac9b3b2817ede35fa2b445373c6e4Lukas Slebodnik { "libsss_ldap_common.so", { LIBPFX"libdlopen_test_providers.so",
a25942bc2f6ac9b3b2817ede35fa2b445373c6e4Lukas Slebodnik LIBPFX"libsss_ldap_common.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { "libsss_proxy.so", { LIBPFX"libdlopen_test_providers.so",
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce LIBPFX"libsss_proxy.so", NULL } },
8a681cc41672afd1532b4a0c7e9da3a4eb2014a7Fabiano Fidêncio#ifdef HAVE_PYTHON2_BINDINGS
889706cbc739358c2a0aac2ba6bc054fdc8e048bLukas Slebodnik { "_py2hbac.so", { LIBPFX"_py2hbac.so", NULL } },
889706cbc739358c2a0aac2ba6bc054fdc8e048bLukas Slebodnik { "_py2sss.so", { LIBPFX"_py2sss.so", NULL } },
889706cbc739358c2a0aac2ba6bc054fdc8e048bLukas Slebodnik { "_py2sss_murmur.so", { LIBPFX"_py2sss_murmur.so", NULL } },
889706cbc739358c2a0aac2ba6bc054fdc8e048bLukas Slebodnik { "_py2sss_nss_idmap.so", { LIBPFX"_py2sss_nss_idmap.so", NULL } },
889706cbc739358c2a0aac2ba6bc054fdc8e048bLukas Slebodnik#endif
8a681cc41672afd1532b4a0c7e9da3a4eb2014a7Fabiano Fidêncio#ifdef HAVE_PYTHON3_BINDINGS
889706cbc739358c2a0aac2ba6bc054fdc8e048bLukas Slebodnik { "_py3hbac.so", { LIBPFX"_py3hbac.so", NULL } },
889706cbc739358c2a0aac2ba6bc054fdc8e048bLukas Slebodnik { "_py3sss.so", { LIBPFX"_py3sss.so", NULL } },
889706cbc739358c2a0aac2ba6bc054fdc8e048bLukas Slebodnik { "_py3sss_murmur.so", { LIBPFX"_py3sss_murmur.so", NULL } },
889706cbc739358c2a0aac2ba6bc054fdc8e048bLukas Slebodnik { "_py3sss_nss_idmap.so", { LIBPFX"_py3sss_nss_idmap.so", NULL } },
3fc158e59eebbc2f538fe0076a03928d0d4eab9fPavel Březina#endif
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik#ifdef BUILD_NFS_IDMAP
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik { "sss.so", { LIBPFX"sss.so", NULL } },
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik#endif
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik /* for testing purposes */
d708e53d0df0c1ed4cc0097bebfa2a84d7b20fadLukas Slebodnik { "libdlopen_test_providers.so", { LIBPFX"libdlopen_test_providers.so",
d708e53d0df0c1ed4cc0097bebfa2a84d7b20fadLukas Slebodnik NULL } },
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik { "libsss_nss_idmap_tests.so", { LIBPFX"libsss_nss_idmap_tests.so",
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik NULL } },
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik#ifdef BUILD_SAMBA
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik { "libdlopen_test_winbind_idmap.so",
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik { LIBPFX"libdlopen_test_winbind_idmap.so", NULL } },
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik { "libsss_ad_tests.so", { LIBPFX"libdlopen_test_providers.so",
558b8f3cd2439c01e139cf5f812aea9409fe776aLukas Slebodnik LIBPFX"libsss_ad_tests.so", NULL } },
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce#endif
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce { NULL }
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce};
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorcestatic bool recursive_dlopen(const char **name, int round, char **errmsg)
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce{
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce void *handle;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce bool ok;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce *errmsg = NULL;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce handle = dlopen(name[round], RTLD_GLOBAL|RTLD_NOW);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce if (!handle) {
569bbc59e4060160a986d0fea31601a7b7d998feBenjamin Franzke if (asprintf(errmsg, "dlopen() failed: %s", dlerror()) == -1)
569bbc59e4060160a986d0fea31601a7b7d998feBenjamin Franzke *errmsg = NULL;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce return false;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce }
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce round++;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce if (name[round]) {
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce ok = recursive_dlopen(name, round, errmsg);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce } else {
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce ok = true;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce }
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce dlclose(handle);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce return ok;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce}
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnikstatic int file_so_filter(const struct dirent *ent)
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik{
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik char *suffix;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik suffix = rindex(ent->d_name, '.');
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik if (suffix != NULL
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik && strcmp(suffix, ".so") == 0
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik && suffix[3] == '\0') {
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik return 1;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik }
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik return 0;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik}
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnikstatic char **get_so_files(size_t *_list_size)
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik{
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik int n;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik struct dirent **namelist;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik char **libraries;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik n = scandir(LIBPFX, &namelist, file_so_filter, alphasort);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik fail_unless(n > 0);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik libraries = calloc(n + 1, sizeof(char *));
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik for (int i = 0; i < n; ++i) {
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik libraries[i] = strdup(namelist[i]->d_name);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik fail_if(libraries[i] == NULL);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik free(namelist[i]);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik }
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik free(namelist);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik *_list_size = (size_t)n;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik return libraries;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik}
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnikstatic void remove_library_from_list(const char *library, char **list,
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik size_t list_size)
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik{
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik for (size_t i = 0; i < list_size; ++i) {
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik if (list[i] != NULL && strcmp(library, list[i]) == 0) {
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik /* found library need to be removed from list */
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik free(list[i]);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik list[i] = NULL;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik return;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik }
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik }
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik ck_abort_msg("Cannot find expected library: %s", library);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik}
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo SorceSTART_TEST(test_dlopen_base)
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce{
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce char *errmsg;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce bool ok;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce int i;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik size_t found_libraries_size;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik char **found_libraries = get_so_files(&found_libraries_size);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik bool unchecked_library = false;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce for (i = 0; so[i].name != NULL; i++) {
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce ok = recursive_dlopen(so[i].libs, 0, &errmsg);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce fail_unless(ok, "Error opening %s: [%s]", so[i].name, errmsg);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik remove_library_from_list(so[i].name, found_libraries,
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik found_libraries_size);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce }
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik for (i = 0; i < found_libraries_size; ++i) {
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik if (found_libraries[i] != NULL) {
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik printf("Unchecked library found: %s\n", found_libraries[i]);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik unchecked_library = true;
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik }
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik }
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik free(found_libraries);
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik
c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9Lukas Slebodnik fail_if(unchecked_library);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce}
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo SorceEND_TEST
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo SorceSuite *dlopen_suite(void)
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce{
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce Suite *s = suite_create("dlopen");
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce TCase *tc_dlopen = tcase_create("dlopen");
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce tcase_add_test(tc_dlopen, test_dlopen_base);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce tcase_set_timeout(tc_dlopen, 10);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce suite_add_tcase(s, tc_dlopen);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce return s;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce}
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorceint main(int argc, const char *argv[])
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce{
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce int number_failed;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce Suite *s = dlopen_suite();
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce SRunner *sr = srunner_create(s);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce srunner_run_all(sr, CK_NORMAL);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce number_failed = srunner_ntests_failed(sr);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce srunner_free(sr);
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce if (number_failed == 0)
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce return EXIT_SUCCESS;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce return EXIT_FAILURE;
36ccdecd053a9ad88dce86b8c84770dc2aa11d21Simo Sorce}