1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* tests/gssapi/reload.c - test loading libgssapi_krb5 twice */
3 /*
4 * Copyright (C) 2020 by the Massachusetts Institute of Technology.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * This is a regression test for ticket #8614. It ensures that libgssapi_krb5
35 * can be loaded multiple times in the same process when libkrb5support is held
36 * open by another library.
37 */
38
39 #include <gssapi/gssapi.h>
40 #include <stdio.h>
41 #include <dlfcn.h>
42 #include <assert.h>
43
44 /* Load libgssapi_krb5, briefly use it (to force the initializer to run), and
45 * close it. */
46 static void
load_gssapi(void)47 load_gssapi(void)
48 {
49 void *gssapi;
50 OM_uint32 (*indmechs)(OM_uint32 *, gss_OID_set *);
51 OM_uint32 (*reloidset)(OM_uint32 *, gss_OID_set *);
52 OM_uint32 major, minor;
53 gss_OID_set mechs;
54
55 gssapi = dlopen("libgssapi_krb5.so", RTLD_NOW | RTLD_LOCAL);
56 assert(gssapi != NULL);
57 indmechs = dlsym(gssapi, "gss_indicate_mechs");
58 reloidset = dlsym(gssapi, "gss_release_oid_set");
59 assert(indmechs != NULL && reloidset != NULL);
60 major = (*indmechs)(&minor, &mechs);
61 assert(major == 0);
62 (*reloidset)(&minor, &mechs);
63 dlclose(gssapi);
64 }
65
66 int
main(void)67 main(void)
68 {
69 void *support;
70
71 /* Hold open libkrb5support to ensure that thread-local state remains */
72 support = dlopen("libkrb5support.so", RTLD_NOW | RTLD_LOCAL);
73 if (support == NULL) {
74 fprintf(stderr, "Error loading libkrb5support: %s\n", dlerror());
75 return 1;
76 }
77
78 load_gssapi();
79 load_gssapi();
80
81 dlclose(support);
82 return 0;
83 }
84