Path: blob/main/crypto/krb5/src/tests/gssapi/reload.c
34889 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/gssapi/reload.c - test loading libgssapi_krb5 twice */2/*3* Copyright (C) 2020 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* * Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12*13* * Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in15* the documentation and/or other materials provided with the16* distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS21* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE22* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,23* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES24* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR25* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,27* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED29* OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132/*33* This is a regression test for ticket #8614. It ensures that libgssapi_krb534* can be loaded multiple times in the same process when libkrb5support is held35* open by another library.36*/3738#include <gssapi/gssapi.h>39#include <stdio.h>40#include <dlfcn.h>41#include <assert.h>4243/* Load libgssapi_krb5, briefly use it (to force the initializer to run), and44* close it. */45static void46load_gssapi(void)47{48void *gssapi;49OM_uint32 (*indmechs)(OM_uint32 *, gss_OID_set *);50OM_uint32 (*reloidset)(OM_uint32 *, gss_OID_set *);51OM_uint32 major, minor;52gss_OID_set mechs;5354gssapi = dlopen("libgssapi_krb5.so", RTLD_NOW | RTLD_LOCAL);55assert(gssapi != NULL);56indmechs = dlsym(gssapi, "gss_indicate_mechs");57reloidset = dlsym(gssapi, "gss_release_oid_set");58assert(indmechs != NULL && reloidset != NULL);59major = (*indmechs)(&minor, &mechs);60assert(major == 0);61(*reloidset)(&minor, &mechs);62dlclose(gssapi);63}6465int66main(void)67{68void *support;6970/* Hold open libkrb5support to ensure that thread-local state remains */71support = dlopen("libkrb5support.so", RTLD_NOW | RTLD_LOCAL);72if (support == NULL) {73fprintf(stderr, "Error loading libkrb5support: %s\n", dlerror());74return 1;75}7677load_gssapi();78load_gssapi();7980dlclose(support);81return 0;82}838485