Windows: Enable weak crypto by default
[heimdal.git] / lib / krb5 / lsacache.c
blob21f05f1a12186b740c5cf5c442f263959b3732ce
1 /*
2 */
4 #include "krb5_locl.h"
5 #ifdef HAVE_DLFCN_H
6 #include <dlfcn.h>
7 #endif
8 #include <assert.h>
10 static HEIMDAL_MUTEX lsacc_mutex = HEIMDAL_MUTEX_INITIALIZER;
11 const krb5_cc_ops * lsacc_ops = NULL;
13 static void *lsacc_handle;
15 krb5_error_code
16 _krb5_mslsa_register_cc_ops(krb5_context context, krb5_boolean override)
18 const char *lib = NULL;
20 HEIMDAL_MUTEX_lock(&lsacc_mutex);
21 if (lsacc_ops) {
22 HEIMDAL_MUTEX_unlock(&lsacc_mutex);
23 if (context) {
24 krb5_clear_error_message(context);
25 krb5_cc_register(context, lsacc_ops, override);
27 return 0;
30 if (context)
31 lib = krb5_config_get_string(context, NULL,
32 "libdefaults", "mslsa_library",
33 NULL);
34 if (lib == NULL) {
35 lib = "%{LIBDIR}/mslsa_cc.dll";
39 char * explib = NULL;
40 if (_krb5_expand_path_tokens(context, lib, &explib) == 0) {
41 lsacc_handle = dlopen(explib, RTLD_LAZY|RTLD_LOCAL);
42 free(explib);
46 if (lsacc_handle == NULL) {
47 HEIMDAL_MUTEX_unlock(&lsacc_mutex);
48 if (context)
49 krb5_set_error_message(context, KRB5_CC_NOSUPP,
50 N_("Failed to load MSLSA cache module %s", "file"),
51 lib);
52 return KRB5_CC_NOSUPP;
56 krb5_error_code ret = 0;
57 krb5_error_code (KRB5_CALLCONV *lsacc_get_ops)(const krb5_cc_ops ** ops);
59 lsacc_get_ops = (krb5_error_code (KRB5_CALLCONV *)(const krb5_cc_ops **))
60 dlsym(lsacc_handle, "lsacc_get_ops");
62 if (lsacc_get_ops) {
63 ret = (*lsacc_get_ops)(&lsacc_ops);
66 HEIMDAL_MUTEX_unlock(&lsacc_mutex);
68 if (ret != 0) {
69 if (context)
70 krb5_set_error_message(context, KRB5_CC_NOSUPP,
71 N_("LSA cache initialization failed (%d)",
72 "error"), ret);
73 dlclose(lsacc_handle);
74 return KRB5_CC_NOSUPP;
77 if (lsacc_get_ops == NULL) {
78 if (context)
79 krb5_set_error_message(context, KRB5_CC_NOSUPP,
80 N_("Failed to find lsacc_get_ops"
81 "in %s: %s", "file, error"), lib, dlerror());
82 dlclose(lsacc_handle);
83 return KRB5_CC_NOSUPP;
87 assert(lsacc_ops != NULL);
89 if (context)
90 return krb5_cc_register(context, lsacc_ops, override);
91 return 0;