Branch data Line data Source code
1 : : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 : : *
3 : : * Copyright © 2019 Endless Mobile, Inc.
4 : : *
5 : : * SPDX-License-Identifier: LGPL-2.1-or-later
6 : : *
7 : : * This library is free software; you can redistribute it and/or
8 : : * modify it under the terms of the GNU Lesser General Public
9 : : * License as published by the Free Software Foundation; either
10 : : * version 2.1 of the License, or (at your option) any later version.
11 : : *
12 : : * This library is distributed in the hope that it will be useful,
13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : : * Lesser General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU Lesser General Public
18 : : * License along with this library; if not, write to the Free Software
19 : : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 : : *
21 : : * Authors:
22 : : * - Philip Withnall <withnall@endlessm.com>
23 : : */
24 : :
25 : : #include <dlfcn.h>
26 : : #include <glib.h>
27 : : #include <locale.h>
28 : : #include <stdlib.h>
29 : : #include "config.h"
30 : :
31 : : /* Test that the `pam_malcontent.so` module can be loaded using dlopen() and
32 : : * that it exports the appropriate symbols for PAM to be able to use it. */
33 : : static void
34 : 1 : test_pam_malcontent_dlopen (void)
35 : : {
36 : 1 : g_autofree gchar *module_path = NULL;
37 : : void *handle;
38 : : int retval;
39 : : void *fn;
40 : :
41 : 1 : module_path = g_test_build_filename (G_TEST_BUILT, "..", "pam_malcontent.so", NULL);
42 : :
43 : : /* Installed tests version. */
44 [ - + ]: 1 : if (!g_file_test (module_path, G_FILE_TEST_EXISTS))
45 : : {
46 : 0 : g_free (module_path);
47 : 0 : module_path = g_build_filename (PAMLIBDIR, "pam_malcontent.so", NULL);
48 : : }
49 : :
50 : : /* Check the module can be loaded. */
51 : 1 : handle = dlopen (module_path, RTLD_NOW);
52 : 1 : g_assert_nonnull (handle);
53 : :
54 : : /* Check the appropriate symbols exist. */
55 : 1 : fn = dlsym (handle, "pam_sm_acct_mgmt");
56 : 1 : g_assert_nonnull (fn);
57 : :
58 : 1 : retval = dlclose (handle);
59 : 1 : g_assert_cmpint (retval, ==, 0);
60 : 1 : }
61 : :
62 : : int
63 : 1 : main (int argc,
64 : : char **argv)
65 : : {
66 : 1 : setlocale (LC_ALL, "");
67 : 1 : g_test_init (&argc, &argv, NULL);
68 : :
69 : 1 : g_test_add_func ("/pam_malcontent/dlopen", test_pam_malcontent_dlopen);
70 : :
71 : 1 : return g_test_run ();
72 : : }
|