dlopen-tests.c revision 889706cbc739358c2a0aac2ba6bc054fdc8e048b
8723ec450f2e7a024230467c0c28a3f154905483cmaeder/*
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder SSSD
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder debug-tests.c
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Authors:
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Simo Sorce <simo@redhat.com>
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder Copyright (C) 2013 Red Hat
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder This program is free software; you can redistribute it and/or modify
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder it under the terms of the GNU General Public License as published by
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder the Free Software Foundation; either version 3 of the License, or
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder (at your option) any later version.
92ae4d5885ea837ffe3dae9b2de742f871229b94Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder This program is distributed in the hope that it will be useful,
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder but WITHOUT ANY WARRANTY; without even the implied warranty of
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8d2321e17a34951fbd52f68e9f9f148f0890e471Christian Maeder GNU General Public License for more details.
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
99b26e2ab8ba89bc9a050c1524137eb6269e2753Christian Maeder You should have received a copy of the GNU General Public License
986888e7f4d8ed681272a79c63f329ce8037063dcmaeder along with this program. If not, see <http://www.gnu.org/licenses/>.
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder*/
8723ec450f2e7a024230467c0c28a3f154905483cmaeder
8723ec450f2e7a024230467c0c28a3f154905483cmaeder#define _GNU_SOURCE
8723ec450f2e7a024230467c0c28a3f154905483cmaeder#include <stdbool.h>
eae0d62755147d991cc3e903f74f98ac31a7cd42Christian Maeder#include <dlfcn.h>
d4263171d0ce2cbc390a7b44bff98e8b3c0f8ce7Christian Maeder#include <stdio.h>
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder#include <stdlib.h>
e84c877ad38ce9312eab222a79f44da2015572d2Christian Maeder#include <limits.h>
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder#include <check.h>
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder#include "tests/common.h"
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian Maeder#define LIBPFX ABS_BUILD_DIR"/.libs/"
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maederstruct so {
945e82ed7877917f3ab1657f555e71991372546aChristian Maeder const char *name;
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder const char *libs[6];
c208973c890b8f993297720fd0247bc7481d4304Christian Maeder} so[] = {
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder { "libsss_debug.so", { LIBPFX"libsss_debug.so", NULL } },
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder { "libsss_semanage.so", { LIBPFX"libsss_semanage.so", NULL } },
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder { "libipa_hbac.so", { LIBPFX"libipa_hbac.so", NULL } },
7c99a6c982aaf61547de8054296c8055c8d1a13aSimon Ulbricht { "libsss_idmap.so", { LIBPFX"libsss_idmap.so", NULL } },
ef1c24c8229ade3ac872febebd18c181e32fb9c4Christian Maeder { "libsss_nss_idmap.so", { LIBPFX"libsss_nss_idmap.so", NULL } },
024703c9d1326c23e307c0b0d453ed3358e87fe4cmaeder { "libnss_sss.so", { LIBPFX"libnss_sss.so", NULL } },
d97700a22b2585ece83b05f3fff945fdfd0c44b4Christian Maeder { "pam_sss.so", { LIBPFX"pam_sss.so", NULL } },
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder#ifdef BUILD_LIBWBCLIENT
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder { "libwbclient.so", { LIBPFX"libwbclient.so", NULL } },
de8eee2014437ec4020be15cd363257f87e79943Christian Maeder#endif /* BUILD_LIBWBCLIENT */
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder#ifdef BUILD_IFP
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder { "libsss_simpleifp.so", { LIBPFX"libsss_simpleifp.so", NULL } },
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder#endif /* BUILD_IFP */
fd94a6f66ccb5cef99aa42069b61e4b8734dbd3fChristian Maeder#ifdef BUILD_SUDO
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder { "libsss_sudo.so", { LIBPFX"libsss_sudo.so", NULL } },
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder#endif
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder#ifdef BUILD_AUTOFS
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder { "libsss_autofs.so", { LIBPFX"libsss_autofs.so", NULL } },
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder#endif
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder#ifdef HAVE_KRB5_LOCATOR_PLUGIN
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder { "sssd_krb5_locator_plugin.so", { LIBPFX"sssd_krb5_locator_plugin.so",
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder NULL } },
6a88f8edd881afaf4b865b01bfbb4faaf0e7a3c9Simon Ulbricht#endif
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder#ifdef HAVE_KRB5_LOCALAUTH_PLUGIN
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder { "sssd_krb5_localauth_plugin.so", { LIBPFX"sssd_krb5_localauth_plugin.so",
844c7d2ec3917393e139e53503757098d568713eSimon Ulbricht NULL } },
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder#endif
734a5ebd38032798f0ab908e2d52862c71b2c127Simon Ulbricht#ifdef HAVE_PAC_RESPONDER
ea5ccb1c6e89486a54e1f4bd95840147e96093edChristian Maeder { "sssd_pac_plugin.so", { LIBPFX"sssd_pac_plugin.so", NULL } },
c8afa08a8bda589ef6670068dff0108464be4da7Christian Maeder#endif
c99b0eb6632087d502dd4269599c5aa68a148eebSimon Ulbricht#ifdef HAVE_CIFS_IDMAP_PLUGIN
024703c9d1326c23e307c0b0d453ed3358e87fe4cmaeder { "cifs_idmap_sss.so", { LIBPFX"cifs_idmap_sss.so", NULL } },
b99c9606f2faafeabb3fa8c596992143a561c787Simon Ulbricht#endif
df67ddf64192bfcae6ece65255ad796a17cbe532Christian Maeder { "memberof.so", { LIBPFX"memberof.so", NULL } },
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder { "libsss_child.so", { LIBPFX"libsss_util.so",
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder LIBPFX"libsss_child.so", NULL } },
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder { "libsss_crypt.so", { LIBPFX"libsss_crypt.so", NULL } },
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder { "libsss_util.so", { LIBPFX"libsss_util.so", NULL } },
473f5af6e4803fbeecc814065952396f2501039bChristian Maeder { "libsss_simple.so", { LIBPFX"libdlopen_test_providers.so",
f675b8f0a612e37472640da57b48d795bef4427eChristian Maeder LIBPFX"libsss_simple.so", NULL } },
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder#ifdef BUILD_SAMBA
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder { "libsss_ad.so", { LIBPFX"libdlopen_test_providers.so",
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder LIBPFX"libsss_ad.so", NULL } },
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder { "libsss_ipa.so", { LIBPFX"libdlopen_test_providers.so",
dae8246f1f55b6a85e946fc1bfb6d32d556395f1Simon Ulbricht LIBPFX"libsss_ipa.so", NULL } },
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder#endif /* BUILD_SAMBA */
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder { "libsss_krb5.so", { LIBPFX"libdlopen_test_providers.so",
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder LIBPFX"libsss_krb5.so", NULL } },
f56cdf11927c31495bae642a9eb383212c90ba61Christian Maeder { "libsss_krb5_common.so", { LIBPFX"libdlopen_test_providers.so",
7710f7c3425e45af11af124ff37bec27229d24f7Christian Maeder LIBPFX"libsss_krb5_common.so", NULL } },
2e2559f894aaa661b199e4fa00609f522bc5482aSimon Ulbricht { "libsss_ldap.so", { LIBPFX"libdlopen_test_providers.so",
df67ddf64192bfcae6ece65255ad796a17cbe532Christian Maeder LIBPFX"libsss_ldap.so", NULL } },
be1ce1c2b2819ef32743136c13101f1927375311Christian Maeder { "libsss_ldap_common.so", { LIBPFX"libdlopen_test_providers.so",
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder LIBPFX"libsss_ldap_common.so", NULL } },
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder { "libsss_proxy.so", { LIBPFX"libdlopen_test_providers.so",
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder LIBPFX"libsss_proxy.so", NULL } },
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder { "libdlopen_test_providers.so", { LIBPFX"libdlopen_test_providers.so",
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder NULL } },
526e7f36639cb58e3c99a54bea082499a6b04a25Christian Maeder#ifdef HAVE_PYTHON_BINDINGS
3e87e1dc85fa76cc6eaeb8eafbc0bea77af939f4Christian Maeder { "_py2hbac.so", { LIBPFX"_py2hbac.so", NULL } },
275698320a734a6fd647ea6a461d6ce38862da1dChristian Maeder { "_py2sss.so", { LIBPFX"_py2sss.so", NULL } },
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder { "_py2sss_murmur.so", { LIBPFX"_py2sss_murmur.so", NULL } },
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder { "_py2sss_nss_idmap.so", { LIBPFX"_py2sss_nss_idmap.so", NULL } },
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder#endif
eca54dc24f2c59cc51645115347a89ba2b40de36cmaeder#ifdef HAVE_PYTHON_BINDINGS
e98c3d3efab62d97ebdeed52f4109d961f6432aaChristian Maeder { "_py3hbac.so", { LIBPFX"_py3hbac.so", NULL } },
eca54dc24f2c59cc51645115347a89ba2b40de36cmaeder { "_py3sss.so", { LIBPFX"_py3sss.so", NULL } },
eca54dc24f2c59cc51645115347a89ba2b40de36cmaeder { "_py3sss_murmur.so", { LIBPFX"_py3sss_murmur.so", NULL } },
eca54dc24f2c59cc51645115347a89ba2b40de36cmaeder { "_py3sss_nss_idmap.so", { LIBPFX"_py3sss_nss_idmap.so", NULL } },
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder#endif
eca54dc24f2c59cc51645115347a89ba2b40de36cmaeder#ifdef HAVE_CONFIG_LIB
26acf851cacd7a31bdc9b25a42af9949942fa7c6Christian Maeder { "libsss_config.so", { LIBPFX"libsss_config.so", NULL } },
26acf851cacd7a31bdc9b25a42af9949942fa7c6Christian Maeder#endif
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder { NULL }
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder};
5896f38ba2934056542cb7cb3e6359e88a622547Christian Maeder
5fb6343a5a2b4bbc67bc83479c84a92d23d30edfChristian Maederstatic bool recursive_dlopen(const char **name, int round, char **errmsg)
eca54dc24f2c59cc51645115347a89ba2b40de36cmaeder{
eca54dc24f2c59cc51645115347a89ba2b40de36cmaeder void *handle;
eca54dc24f2c59cc51645115347a89ba2b40de36cmaeder bool ok;
eca54dc24f2c59cc51645115347a89ba2b40de36cmaeder
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder *errmsg = NULL;
11c3a215d5cf043181e83929f1ce214df65cb587Christian Maeder
18548c6cc2dff13bf9f5f08b3f6cde6ca914df1dChristian Maeder handle = dlopen(name[round], RTLD_GLOBAL|RTLD_NOW);
5fb6343a5a2b4bbc67bc83479c84a92d23d30edfChristian Maeder if (!handle) {
6a6689ad6d4c70af2ce3389f39a50982f20fd939Christian Maeder if (asprintf(errmsg, "dlopen() failed: %s", dlerror()) == -1)
12882fa70d12d9b56cbd850ccb4b724feb3c62d5Christian Maeder *errmsg = NULL;
12882fa70d12d9b56cbd850ccb4b724feb3c62d5Christian Maeder return false;
12882fa70d12d9b56cbd850ccb4b724feb3c62d5Christian Maeder }
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder round++;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder if (name[round]) {
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder ok = recursive_dlopen(name, round, errmsg);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder } else {
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder ok = true;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder }
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder dlclose(handle);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder return ok;
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder}
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian MaederSTART_TEST(test_dlopen_base)
8723ec450f2e7a024230467c0c28a3f154905483cmaeder{
8723ec450f2e7a024230467c0c28a3f154905483cmaeder char *errmsg;
8723ec450f2e7a024230467c0c28a3f154905483cmaeder bool ok;
8723ec450f2e7a024230467c0c28a3f154905483cmaeder int i;
8723ec450f2e7a024230467c0c28a3f154905483cmaeder
8723ec450f2e7a024230467c0c28a3f154905483cmaeder for (i = 0; so[i].name != NULL; i++) {
8723ec450f2e7a024230467c0c28a3f154905483cmaeder ok = recursive_dlopen(so[i].libs, 0, &errmsg);
8723ec450f2e7a024230467c0c28a3f154905483cmaeder fail_unless(ok, "Error opening %s: [%s]", so[i].name, errmsg);
8723ec450f2e7a024230467c0c28a3f154905483cmaeder }
8723ec450f2e7a024230467c0c28a3f154905483cmaeder}
d27b1887e61f1dc53d77c37f59dbf5019242a686Christian MaederEND_TEST
31a81edf1285dc338211bfe86ba50a1f4128d9d2Christian Maeder
31a81edf1285dc338211bfe86ba50a1f4128d9d2Christian MaederSuite *dlopen_suite(void)
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder{
9d50556254571c0811e94b4d948463754812a5aaChristian Maeder Suite *s = suite_create("dlopen");
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder
1f0483f71bad0707f10293d0b4db4649aa93fb35Christian Maeder TCase *tc_dlopen = tcase_create("dlopen");
1f0483f71bad0707f10293d0b4db4649aa93fb35Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder tcase_add_test(tc_dlopen, test_dlopen_base);
c5b8b64377e24bcbf5cc108ca433cfbbd6235ba1Christian Maeder tcase_set_timeout(tc_dlopen, 10);
c5b8b64377e24bcbf5cc108ca433cfbbd6235ba1Christian Maeder
0a26144c20fa9cdcd05011ca5019cbac8e4afae0cmaeder suite_add_tcase(s, tc_dlopen);
9d50556254571c0811e94b4d948463754812a5aaChristian Maeder
c5b8b64377e24bcbf5cc108ca433cfbbd6235ba1Christian Maeder return s;
c5b8b64377e24bcbf5cc108ca433cfbbd6235ba1Christian Maeder}
c5b8b64377e24bcbf5cc108ca433cfbbd6235ba1Christian Maeder
c5b8b64377e24bcbf5cc108ca433cfbbd6235ba1Christian Maederint main(int argc, const char *argv[])
26acf851cacd7a31bdc9b25a42af9949942fa7c6Christian Maeder{
8723ec450f2e7a024230467c0c28a3f154905483cmaeder int number_failed;
8723ec450f2e7a024230467c0c28a3f154905483cmaeder
8723ec450f2e7a024230467c0c28a3f154905483cmaeder Suite *s = dlopen_suite();
1f0483f71bad0707f10293d0b4db4649aa93fb35Christian Maeder SRunner *sr = srunner_create(s);
8723ec450f2e7a024230467c0c28a3f154905483cmaeder
8723ec450f2e7a024230467c0c28a3f154905483cmaeder srunner_run_all(sr, CK_NORMAL);
5d93620c37abd9c665d3fe532d4852d62dff4233Christian Maeder number_failed = srunner_ntests_failed(sr);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder srunner_free(sr);
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder
9f4902edfa3d477e42343e0ec357a2f93b1119d1Christian Maeder if (number_failed == 0)
5d93620c37abd9c665d3fe532d4852d62dff4233Christian Maeder return EXIT_SUCCESS;
5d93620c37abd9c665d3fe532d4852d62dff4233Christian Maeder
232c13ff6847a6f2bac7163392f80ab692cd7774Christian Maeder return EXIT_FAILURE;
12882fa70d12d9b56cbd850ccb4b724feb3c62d5Christian Maeder}
4bd27a2cb9efd5d8ff00b5cf823487403add724ecmaeder