Line data Source code
1 : /*
2 : SSSD
3 :
4 : debug-tests.c
5 :
6 : Authors:
7 : Simo Sorce <simo@redhat.com>
8 :
9 : Copyright (C) 2013 Red Hat
10 :
11 : This program is free software; you can redistribute it and/or modify
12 : it under the terms of the GNU General Public License as published by
13 : the Free Software Foundation; either version 3 of the License, or
14 : (at your option) any later version.
15 :
16 : This program is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : GNU General Public License for more details.
20 :
21 : You should have received a copy of the GNU General Public License
22 : along with this program. If not, see <http://www.gnu.org/licenses/>.
23 : */
24 :
25 : #define _GNU_SOURCE
26 : #include <stdbool.h>
27 : #include <dlfcn.h>
28 : #include <stdio.h>
29 : #include <stdlib.h>
30 : #include <limits.h>
31 : #include <check.h>
32 : #include "tests/common.h"
33 :
34 : #define LIBPFX ABS_BUILD_DIR"/.libs/"
35 :
36 : struct so {
37 : const char *name;
38 : const char *libs[6];
39 : } so[] = {
40 : { "libsss_debug.so", { LIBPFX"libsss_debug.so", NULL } },
41 : { "libsss_semanage.so", { LIBPFX"libsss_semanage.so", NULL } },
42 : { "libipa_hbac.so", { LIBPFX"libipa_hbac.so", NULL } },
43 : { "libsss_idmap.so", { LIBPFX"libsss_idmap.so", NULL } },
44 : { "libsss_nss_idmap.so", { LIBPFX"libsss_nss_idmap.so", NULL } },
45 : { "libnss_sss.so", { LIBPFX"libnss_sss.so", NULL } },
46 : { "pam_sss.so", { LIBPFX"pam_sss.so", NULL } },
47 : #ifdef BUILD_LIBWBCLIENT
48 : { "libwbclient.so", { LIBPFX"libwbclient.so", NULL } },
49 : #endif /* BUILD_LIBWBCLIENT */
50 : #ifdef BUILD_IFP
51 : { "libsss_simpleifp.so", { LIBPFX"libsss_simpleifp.so", NULL } },
52 : #endif /* BUILD_IFP */
53 : #ifdef BUILD_SUDO
54 : { "libsss_sudo.so", { LIBPFX"libsss_sudo.so", NULL } },
55 : #endif
56 : #ifdef BUILD_AUTOFS
57 : { "libsss_autofs.so", { LIBPFX"libsss_autofs.so", NULL } },
58 : #endif
59 : #ifdef HAVE_KRB5_LOCATOR_PLUGIN
60 : { "sssd_krb5_locator_plugin.so", { LIBPFX"sssd_krb5_locator_plugin.so",
61 : NULL } },
62 : #endif
63 : #ifdef HAVE_KRB5_LOCALAUTH_PLUGIN
64 : { "sssd_krb5_localauth_plugin.so", { LIBPFX"sssd_krb5_localauth_plugin.so",
65 : NULL } },
66 : #endif
67 : #ifdef HAVE_PAC_RESPONDER
68 : { "sssd_pac_plugin.so", { LIBPFX"sssd_pac_plugin.so", NULL } },
69 : #endif
70 : #ifdef HAVE_CIFS_IDMAP_PLUGIN
71 : { "cifs_idmap_sss.so", { LIBPFX"cifs_idmap_sss.so", NULL } },
72 : #endif
73 : { "memberof.so", { LIBPFX"memberof.so", NULL } },
74 : { "libsss_child.so", { LIBPFX"libsss_util.so",
75 : LIBPFX"libsss_child.so", NULL } },
76 : { "libsss_crypt.so", { LIBPFX"libsss_crypt.so", NULL } },
77 : { "libsss_util.so", { LIBPFX"libsss_util.so", NULL } },
78 : { "libsss_simple.so", { LIBPFX"libdlopen_test_providers.so",
79 : LIBPFX"libsss_simple.so", NULL } },
80 : #ifdef BUILD_SAMBA
81 : { "libsss_ad.so", { LIBPFX"libdlopen_test_providers.so",
82 : LIBPFX"libsss_ad.so", NULL } },
83 : { "libsss_ipa.so", { LIBPFX"libdlopen_test_providers.so",
84 : LIBPFX"libsss_ipa.so", NULL } },
85 : #endif /* BUILD_SAMBA */
86 : { "libsss_krb5.so", { LIBPFX"libdlopen_test_providers.so",
87 : LIBPFX"libsss_krb5.so", NULL } },
88 : { "libsss_krb5_common.so", { LIBPFX"libdlopen_test_providers.so",
89 : LIBPFX"libsss_krb5_common.so", NULL } },
90 : { "libsss_ldap.so", { LIBPFX"libdlopen_test_providers.so",
91 : LIBPFX"libsss_ldap.so", NULL } },
92 : { "libsss_ldap_common.so", { LIBPFX"libdlopen_test_providers.so",
93 : LIBPFX"libsss_ldap_common.so", NULL } },
94 : { "libsss_proxy.so", { LIBPFX"libdlopen_test_providers.so",
95 : LIBPFX"libsss_proxy.so", NULL } },
96 : { "libdlopen_test_providers.so", { LIBPFX"libdlopen_test_providers.so",
97 : NULL } },
98 : #ifdef HAVE_PYTHON_BINDINGS
99 : { "_py2hbac.so", { LIBPFX"_py2hbac.so", NULL } },
100 : { "_py2sss.so", { LIBPFX"_py2sss.so", NULL } },
101 : { "_py2sss_murmur.so", { LIBPFX"_py2sss_murmur.so", NULL } },
102 : { "_py2sss_nss_idmap.so", { LIBPFX"_py2sss_nss_idmap.so", NULL } },
103 : #endif
104 : #ifdef HAVE_PYTHON_BINDINGS
105 : { "_py3hbac.so", { LIBPFX"_py3hbac.so", NULL } },
106 : { "_py3sss.so", { LIBPFX"_py3sss.so", NULL } },
107 : { "_py3sss_murmur.so", { LIBPFX"_py3sss_murmur.so", NULL } },
108 : { "_py3sss_nss_idmap.so", { LIBPFX"_py3sss_nss_idmap.so", NULL } },
109 : #endif
110 : #ifdef HAVE_CONFIG_LIB
111 : { "libsss_config.so", { LIBPFX"libsss_config.so", NULL } },
112 : #endif
113 : { NULL }
114 : };
115 :
116 38 : static bool recursive_dlopen(const char **name, int round, char **errmsg)
117 : {
118 : void *handle;
119 : bool ok;
120 :
121 38 : *errmsg = NULL;
122 :
123 38 : handle = dlopen(name[round], RTLD_GLOBAL|RTLD_NOW);
124 38 : if (!handle) {
125 0 : if (asprintf(errmsg, "dlopen() failed: %s", dlerror()) == -1)
126 0 : *errmsg = NULL;
127 0 : return false;
128 : }
129 :
130 38 : round++;
131 38 : if (name[round]) {
132 9 : ok = recursive_dlopen(name, round, errmsg);
133 : } else {
134 29 : ok = true;
135 : }
136 :
137 38 : dlclose(handle);
138 38 : return ok;
139 : }
140 :
141 1 : START_TEST(test_dlopen_base)
142 : {
143 : char *errmsg;
144 : bool ok;
145 : int i;
146 :
147 30 : for (i = 0; so[i].name != NULL; i++) {
148 29 : ok = recursive_dlopen(so[i].libs, 0, &errmsg);
149 29 : fail_unless(ok, "Error opening %s: [%s]", so[i].name, errmsg);
150 : }
151 : }
152 1 : END_TEST
153 :
154 1 : Suite *dlopen_suite(void)
155 : {
156 1 : Suite *s = suite_create("dlopen");
157 :
158 1 : TCase *tc_dlopen = tcase_create("dlopen");
159 :
160 1 : tcase_add_test(tc_dlopen, test_dlopen_base);
161 1 : tcase_set_timeout(tc_dlopen, 10);
162 :
163 1 : suite_add_tcase(s, tc_dlopen);
164 :
165 1 : return s;
166 : }
167 :
168 1 : int main(int argc, const char *argv[])
169 : {
170 : int number_failed;
171 :
172 1 : Suite *s = dlopen_suite();
173 1 : SRunner *sr = srunner_create(s);
174 :
175 1 : srunner_run_all(sr, CK_NORMAL);
176 1 : number_failed = srunner_ntests_failed(sr);
177 1 : srunner_free(sr);
178 :
179 1 : if (number_failed == 0)
180 1 : return EXIT_SUCCESS;
181 :
182 0 : return EXIT_FAILURE;
183 : }
|