From: Theodore Tso Date: Wed, 31 Mar 1999 05:11:39 +0000 (+0000) Subject: winccld.c, winccld.h, stdcc.c: Add files to dynamically load X-Git-Tag: krb5-1.1-beta1~251 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ccda4601762304ffc41f81715de641b92130bdf1;p=krb5.git winccld.c, winccld.h, stdcc.c: Add files to dynamically load krbcc32.dll, so that we can fall back and use the built-in file ccache type if krbcc32.dll doesn't exist. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11331 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/ccache/ccapi/ChangeLog b/src/lib/krb5/ccache/ccapi/ChangeLog index a8a4bda50..02eff3878 100644 --- a/src/lib/krb5/ccache/ccapi/ChangeLog +++ b/src/lib/krb5/ccache/ccapi/ChangeLog @@ -1,3 +1,9 @@ +1999-03-31 Theodore Ts'o + + * winccld.c, winccld.h, stdcc.c: Add files to dynamically load + krbcc32.dll, so that we can fall back and use the built-in + file ccache type if krbcc32.dll doesn't exist. + 1998-11-13 Theodore Ts'o * Makefile.in: Set the myfulldir and mydir variables (which are diff --git a/src/lib/krb5/ccache/ccapi/Makefile.in b/src/lib/krb5/ccache/ccapi/Makefile.in index 649983fe5..47919920a 100644 --- a/src/lib/krb5/ccache/ccapi/Makefile.in +++ b/src/lib/krb5/ccache/ccapi/Makefile.in @@ -13,11 +13,12 @@ CFLAGS = $(CCOPTS) $(DEFS) $(WIN_INCLUDES) STLIBOBJS = \ stdcc.o \ - stdcc_util.o + stdcc_util.o \ + winccld.o -OBJS = stdcc.$(OBJEXT) stdcc_util.$(OBJEXT) +OBJS = stdcc.$(OBJEXT) stdcc_util.$(OBJEXT) winccld.$(OBJEXT) -SRCS = $(srcdir)/stdcc.c $(srcdir)/stdcc_util.c +SRCS = $(srcdir)/stdcc.c $(srcdir)/stdcc_util.c $(srcdir)/winccld.c ##DOS##LIBOBJS = $(OBJS) diff --git a/src/lib/krb5/ccache/ccapi/stdcc.c b/src/lib/krb5/ccache/ccapi/stdcc.c index 411e62005..c55a7073b 100644 --- a/src/lib/krb5/ccache/ccapi/stdcc.c +++ b/src/lib/krb5/ccache/ccapi/stdcc.c @@ -33,6 +33,10 @@ apiCB *gCntrlBlock = NULL; +#if defined(_MSDOS) || defined(_WIN32) +#include "winccld.h" +#endif + #if !defined(_MSDOS) && !defined(_WIN32) #define CC_API_VER2 #endif @@ -179,6 +183,12 @@ static krb5_error_code stdcc_setup(krb5_context context, return cc_err_xlate(err); } +void krb5_stdcc_shutdown() +{ + if (gCntrlBlock) + cc_shutdown(&gCntrlBlock); + gCntrlBlock = 0; +} /* * -- generate_new -------------------------------- diff --git a/src/lib/krb5/ccache/ccapi/winccld.c b/src/lib/krb5/ccache/ccapi/winccld.c new file mode 100644 index 000000000..a3e4473eb --- /dev/null +++ b/src/lib/krb5/ccache/ccapi/winccld.c @@ -0,0 +1,89 @@ +/* + * winccld.c --- routine for dynamically loading the ccache DLL if + * it's present. + */ + +#include +#include +#include "stdcc.h" + +#define KRB5_WINCCLD_C_ +#include "winccld.h" + +static int krb5_win_ccdll_loaded = 0; + +extern void krb5_win_ccdll_load(); +extern int krb5_is_ccdll_loaded(); + +/* + * return codes + */ +#define LF_OK 0 +#define LF_NODLL 1 +#define LF_NOFUNC 2 + +#define KRBCC_DLL "krbcc32.dll" + +static int LoadFuncs(const char* dll_name, FUNC_INFO fi[], + HINSTANCE* ph, int debug); + +static int LoadFuncs(const char* dll_name, FUNC_INFO fi[], + HINSTANCE* ph, int debug) +{ + HINSTANCE h; + int i, n; + int error = 0; + + if (ph) *ph = 0; + + for (n = 0; fi[n].func_ptr_var; n++) { + *(fi[n].func_ptr_var) = 0; + } + + if (!(h = LoadLibrary(dll_name))) { + return LF_NODLL; + } + + if (debug) + printf("Loaded %s\n", dll_name); + for (i = 0; !error && (i < n); i++) { + void* p = (void*)GetProcAddress(h, fi[i].func_name); + if (!p) { + if (debug) + printf("Could not get function: %s\n", fi[i].func_name); + error = 1; + } else { + *(fi[i].func_ptr_var) = p; + if (debug) + printf("Loaded function %s at 0x%08X\n", fi[i].func_name, p); + } + } + if (error) { + for (i = 0; i < n; i++) { + *(fi[i].func_ptr_var) = 0; + } + FreeLibrary(h); + return LF_NOFUNC; + } + if (ph) *ph = h; + return LF_OK; +} + +void krb5_win_ccdll_load() +{ + if (krb5_win_ccdll_loaded) + return; + if (LoadFuncs(KRBCC_DLL, krbcc_fi, 0, 0)) + return; /* Error, give up */ + krb5_win_ccdll_loaded = 1; + krb5_cc_dfl_ops = &krb5_cc_stdcc_ops; /* Use stdcc! */ +} + +int krb5_is_ccdll_loaded() +{ + return krb5_win_ccdll_loaded; +} + + + + diff --git a/src/lib/krb5/ccache/ccapi/winccld.h b/src/lib/krb5/ccache/ccapi/winccld.h new file mode 100644 index 000000000..30de8196a --- /dev/null +++ b/src/lib/krb5/ccache/ccapi/winccld.h @@ -0,0 +1,142 @@ +/* + * winccld.h -- the dynamic loaded version of the ccache DLL + */ + + +#ifndef KRB5_WINCCLD_H_ +#define KRB5_WINCCLD_H_ + +#include "cacheapi.h" + +typedef cc_int32 (*FP_cc_initialize)(apiCB**, const cc_int32, + cc_int32*, const char**); +typedef cc_int32 (*FP_cc_shutdown)(apiCB**); +typedef cc_int32 (*FP_cc_get_change_time)(apiCB*, cc_time_t*); +typedef cc_int32 (*FP_cc_create)(apiCB*, const char*, const char*, + const enum cc_cred_vers, const cc_int32, ccache_p**); +typedef cc_int32 (*FP_cc_open)(apiCB*, const char*, const enum cc_cred_vers, + const cc_int32, ccache_p**); +typedef cc_int32 (*FP_cc_close)(apiCB*, ccache_p**); +typedef cc_int32 (*FP_cc_destroy)(apiCB*, ccache_p**); +typedef cc_int32 (*FP_cc_seq_fetch_NCs)(apiCB*, ccache_p**, ccache_cit**); +typedef cc_int32 (*FP_cc_get_NC_info)(apiCB*, struct _infoNC***); +typedef cc_int32 (*FP_cc_free_NC_info)(apiCB*, struct _infoNC***); +typedef cc_int32 (*FP_cc_get_name)(apiCB*, const ccache_p*, char**); +typedef cc_int32 (*FP_cc_set_principal)(apiCB*, const ccache_p*, + const enum cc_cred_vers, const char*); +typedef cc_int32 (*FP_cc_get_principal)(apiCB*, ccache_p*, char**); +typedef cc_int32 (*FP_cc_set_instance)(apiCB*, const char*); +typedef cc_int32 (*FP_cc_get_instance)(apiCB*, char**); +typedef cc_int32 (*FP_cc_get_cred_version)(apiCB*, const ccache_p*, + enum cc_cred_vers*); +typedef cc_int32 (*FP_cc_lock_request)(apiCB*, const ccache_p*, + const cc_int32); +typedef cc_int32 (*FP_cc_store)(apiCB*, const ccache_p*, const cred_union); +typedef cc_int32 (*FP_cc_remove_cred)(apiCB*, const ccache_p*, + const cred_union); +typedef cc_int32 (*FP_cc_seq_fetch_creds)(apiCB*, const ccache_p*, + cred_union**, ccache_cit**); +typedef cc_int32 (*FP_cc_free_principal)(apiCB*, char**); +typedef cc_int32 (*FP_cc_free_instance)(apiCB*, char**); +typedef cc_int32 (*FP_cc_free_name)(apiCB*, char** name); +typedef cc_int32 (*FP_cc_free_creds)(apiCB*, cred_union** pCred); + +#ifdef KRB5_WINCCLD_C_ +typedef struct _FUNC_INFO { + void** func_ptr_var; + char* func_name; +} FUNC_INFO; + +#define DECL_FUNC_PTR(x) FP_##x p##x +#define MAKE_FUNC_INFO(x) { (void**) &p##x, #x } +#define END_FUNC_INFO { 0, 0 } +#else +#define DECL_FUNC_PTR(x) extern FP_##x p##x +#endif + +DECL_FUNC_PTR(cc_initialize); +DECL_FUNC_PTR(cc_shutdown); +DECL_FUNC_PTR(cc_get_change_time); +DECL_FUNC_PTR(cc_create); +DECL_FUNC_PTR(cc_open); +DECL_FUNC_PTR(cc_close); +DECL_FUNC_PTR(cc_destroy); +DECL_FUNC_PTR(cc_seq_fetch_NCs); +DECL_FUNC_PTR(cc_get_NC_info); +DECL_FUNC_PTR(cc_free_NC_info); +DECL_FUNC_PTR(cc_get_name); +DECL_FUNC_PTR(cc_set_principal); +DECL_FUNC_PTR(cc_get_principal); +DECL_FUNC_PTR(cc_set_instance); +DECL_FUNC_PTR(cc_get_instance); +DECL_FUNC_PTR(cc_get_cred_version); +DECL_FUNC_PTR(cc_lock_request); +DECL_FUNC_PTR(cc_store); +DECL_FUNC_PTR(cc_remove_cred); +DECL_FUNC_PTR(cc_seq_fetch_creds); +DECL_FUNC_PTR(cc_free_principal); +DECL_FUNC_PTR(cc_free_instance); +DECL_FUNC_PTR(cc_free_name); +DECL_FUNC_PTR(cc_free_creds); + +#ifdef KRB5_WINCCLD_C_ +FUNC_INFO krbcc_fi[] = { + MAKE_FUNC_INFO(cc_initialize), + MAKE_FUNC_INFO(cc_shutdown), + MAKE_FUNC_INFO(cc_get_change_time), + MAKE_FUNC_INFO(cc_create), + MAKE_FUNC_INFO(cc_open), + MAKE_FUNC_INFO(cc_close), + MAKE_FUNC_INFO(cc_destroy), + MAKE_FUNC_INFO(cc_seq_fetch_NCs), + MAKE_FUNC_INFO(cc_get_NC_info), + MAKE_FUNC_INFO(cc_free_NC_info), + MAKE_FUNC_INFO(cc_get_name), + MAKE_FUNC_INFO(cc_set_principal), + MAKE_FUNC_INFO(cc_get_principal), + MAKE_FUNC_INFO(cc_set_instance), + MAKE_FUNC_INFO(cc_get_instance), + MAKE_FUNC_INFO(cc_get_cred_version), + MAKE_FUNC_INFO(cc_lock_request), + MAKE_FUNC_INFO(cc_store), + MAKE_FUNC_INFO(cc_remove_cred), + MAKE_FUNC_INFO(cc_seq_fetch_creds), + MAKE_FUNC_INFO(cc_free_principal), + MAKE_FUNC_INFO(cc_free_instance), + MAKE_FUNC_INFO(cc_free_name), + MAKE_FUNC_INFO(cc_free_creds), + END_FUNC_INFO +}; +#undef MAKE_FUNC_INFO +#undef END_FUNC_INFO +#else + +#define cc_initialize pcc_initialize +#define cc_shutdown pcc_shutdown +#define cc_get_change_time pcc_get_change_time +#define cc_creat pcc_creat +#define cc_open pcc_open +#define cc_close pcc_close +#define cc_destroy pcc_destroy +#define cc_seq_fetch_NCs pcc_seq_fetch_NCs +#define cc_get_NC_info pcc_get_NC_info +#define cc_free_NC_info pcc_free_NC_info +#define cc_get_name pcc_get_name +#define cc_set_principal pcc_set_principal +#define cc_get_principal pcc_get_principal +#define cc_set_instance pcc_set_instance +#define cc_get_instance pcc_get_instance +#define cc_get_cred_version pcc_get_cred_version +#define cc_lock_request pcc_lock_request +#define cc_store pcc_store +#define cc_remove_cred pcc_remove_cred +#define cc_seq_fetch_creds pcc_seq_fetch_creds +#define cc_free_principal pcc_free_principal +#define cc_free_instance pcc_free_instance +#define cc_free_name pcc_free_name +#define cc_free_creds pcc_free_creds +#endif + +#undef DECL_FUNC_PTR + +#endif /* KRB5_WINCCLD_H_ */