diff options
| author | Ken Raeburn <raeburn@mit.edu> | 2004-04-24 21:09:44 +0000 |
|---|---|---|
| committer | Ken Raeburn <raeburn@mit.edu> | 2004-04-24 21:09:44 +0000 |
| commit | fcf02bef88a17724aa230547459a9eaf1159d6c1 (patch) | |
| tree | 7f9dd998b8e7baf61111f6bf0428da47de1291eb /src/lib | |
| parent | 3b4d753fc5169469da270c831654a8fae407cfdf (diff) | |
Added support for library initialization and finalization, and verification
that the initializer completed successfully. Delay initialization on POSIX
until the first "verification" call. Currently specific to a few platforms,
but should still build on others without thread support enabled.
Use it to finish creating (if necessary) and destroy mutexes, and free some
other storage "permanently" allocated by libraries (currently, libkrb5
cache/keytab type registries only). Change initialization of static mutexes to
a two-step operation, a static "partial" initializer and a "finish_init"
routine called from a thread-safe environment like library initialization is
assumed to be. POSIX will use the former, Windows will use the latter, and the
debug support will check that *both* have been used.
Added init/fini functions to com_err, profile, krb5, and gssapi libraries.
(The profile library one may need to be removed later.) The existing ones, not
thread-safe, are still around.
Use weak symbol support if available to figure out if the pthread library has
been linked in, and avoid calling certain routines if the C library stubs are
known not to exist or work.
Stub declarations for thread-specific data.
Minor bugfixes, whitespace changes.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16268 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/gssapi/ChangeLog | 8 | ||||
| -rw-r--r-- | src/lib/gssapi/generic/ChangeLog | 5 | ||||
| -rw-r--r-- | src/lib/gssapi/generic/gssapiP_generic.h | 2 | ||||
| -rw-r--r-- | src/lib/gssapi/gss_libinit.c | 28 | ||||
| -rw-r--r-- | src/lib/gssapi/krb5/ChangeLog | 3 | ||||
| -rw-r--r-- | src/lib/gssapi/krb5/krb5_gss_glue.c | 10 | ||||
| -rw-r--r-- | src/lib/krb5/ChangeLog | 11 | ||||
| -rw-r--r-- | src/lib/krb5/ccache/ChangeLog | 8 | ||||
| -rw-r--r-- | src/lib/krb5/ccache/ccbase.c | 20 | ||||
| -rw-r--r-- | src/lib/krb5/keytab/ChangeLog | 9 | ||||
| -rw-r--r-- | src/lib/krb5/keytab/ktbase.c | 19 | ||||
| -rw-r--r-- | src/lib/krb5/krb/ChangeLog | 9 | ||||
| -rw-r--r-- | src/lib/krb5/krb/init_ctx.c | 4 | ||||
| -rw-r--r-- | src/lib/krb5/krb5_libinit.c | 76 | ||||
| -rw-r--r-- | src/lib/krb5/rcache/ChangeLog | 8 | ||||
| -rw-r--r-- | src/lib/krb5/rcache/rc_base.c | 16 |
16 files changed, 199 insertions, 37 deletions
diff --git a/src/lib/gssapi/ChangeLog b/src/lib/gssapi/ChangeLog index e33541574..0c2d0ec16 100644 --- a/src/lib/gssapi/ChangeLog +++ b/src/lib/gssapi/ChangeLog @@ -1,3 +1,11 @@ +2004-04-24 Ken Raeburn <raeburn@mit.edu> + + * gss_libinit.c: Include k5-platform.h. + (gssint_lib_init, gssint_lib_fini): New init/fini functions. + Create and clean up the mutex in kg_vdb. + (gssint_initialize_library): Verify the library initializer has + run successfully. + 2004-04-22 Ken Raeburn <raeburn@mit.edu> * libgssapi_krb5.exports: New file. diff --git a/src/lib/gssapi/generic/ChangeLog b/src/lib/gssapi/generic/ChangeLog index 563eb2f06..a9f93eb14 100644 --- a/src/lib/gssapi/generic/ChangeLog +++ b/src/lib/gssapi/generic/ChangeLog @@ -1,3 +1,8 @@ +2004-04-24 Ken Raeburn <raeburn@mit.edu> + + * gssapiP_generic.h (G_SET_INIT): Use the new mutex partial + initializer now. + 2004-03-14 Ken Raeburn <raeburn@mit.edu> * gssapiP_generic.h (struct _g_set_elt, g_set_elt): Renamed from diff --git a/src/lib/gssapi/generic/gssapiP_generic.h b/src/lib/gssapi/generic/gssapiP_generic.h index 30afc5264..e297862fe 100644 --- a/src/lib/gssapi/generic/gssapiP_generic.h +++ b/src/lib/gssapi/generic/gssapiP_generic.h @@ -139,7 +139,7 @@ typedef struct { k5_mutex_t mutex; void *data; } g_set; -#define G_SET_INIT { K5_MUTEX_INITIALIZER, 0 } +#define G_SET_INIT { K5_MUTEX_PARTIAL_INITIALIZER, 0 } int g_set_init (g_set_elt *s); int g_set_destroy (g_set_elt *s); diff --git a/src/lib/gssapi/gss_libinit.c b/src/lib/gssapi/gss_libinit.c index 0568f2964..fb80c8946 100644 --- a/src/lib/gssapi/gss_libinit.c +++ b/src/lib/gssapi/gss_libinit.c @@ -5,6 +5,7 @@ #include "gssapiP_krb5.h" #include "gss_libinit.h" +#include "k5-platform.h" static int initialized = 0; @@ -12,19 +13,33 @@ static int initialized = 0; * Initialize the GSSAPI library. */ +MAKE_INIT_FUNCTION(gssint_lib_init); +MAKE_FINI_FUNCTION(gssint_lib_fini); + +int gssint_lib_init(void) +{ + return k5_mutex_finish_init(&kg_vdb.mutex); +} + +void gssint_lib_fini(void) +{ + if (!INITIALIZER_RAN(gssint_lib_init) || PROGRAM_EXITING()) + return; + k5_mutex_destroy(&kg_vdb.mutex); +} + OM_uint32 gssint_initialize_library (void) { - if (!initialized) { #if !USE_BUNDLE_ERROR_STRINGS add_error_table(&et_k5g_error_table); add_error_table(&et_ggss_error_table); #endif - initialized = 1; + initialized = 1; } - - return 0; + + return CALL_INIT_FUNCTION(gssint_lib_init); } /* @@ -33,13 +48,12 @@ OM_uint32 gssint_initialize_library (void) void gssint_cleanup_library (void) { - assert (initialized); - + #if !USE_BUNDLE_ERROR_STRINGS remove_error_table(&et_k5g_error_table); remove_error_table(&et_ggss_error_table); #endif - + initialized = 0; } diff --git a/src/lib/gssapi/krb5/ChangeLog b/src/lib/gssapi/krb5/ChangeLog index f55b779da..1be0a67a7 100644 --- a/src/lib/gssapi/krb5/ChangeLog +++ b/src/lib/gssapi/krb5/ChangeLog @@ -5,6 +5,9 @@ (kg_set_ccache_name): Likewise. Return after an error rather than continuing. + * krb5_gss_glue.c (gss_import_name): Call + gssint_initialize_library and check the return status. + 2004-04-13 Jeffrey Altman <jaltman@mit.edu> * k5unseal.c: gss_krb5int_unseal_token_v3() takes a pointer to diff --git a/src/lib/gssapi/krb5/krb5_gss_glue.c b/src/lib/gssapi/krb5/krb5_gss_glue.c index 540652ad8..583881d8e 100644 --- a/src/lib/gssapi/krb5/krb5_gss_glue.c +++ b/src/lib/gssapi/krb5/krb5_gss_glue.c @@ -211,8 +211,14 @@ gss_import_name(minor_status, input_name_buffer, input_name_type, output_name) gss_OID input_name_type; gss_name_t *output_name; { - return(krb5_gss_import_name(minor_status, input_name_buffer, - input_name_type, output_name)); + OM_uint32 err; + err = gssint_initialize_library(); + if (err) { + *minor_status = err; + return GSS_S_FAILURE; + } + return(krb5_gss_import_name(minor_status, input_name_buffer, + input_name_type, output_name)); } /* V2 */ diff --git a/src/lib/krb5/ChangeLog b/src/lib/krb5/ChangeLog index 35be9e437..7695a5e32 100644 --- a/src/lib/krb5/ChangeLog +++ b/src/lib/krb5/ChangeLog @@ -1,3 +1,14 @@ +2004-04-24 Ken Raeburn <raeburn@mit.edu> + + * krb5_libinit.c: Include k5-platform.h. + (krb5int_lib_init, krb5int_lib_fini): New init/fini functions. + Call the corresponding functions for the ccache, keytab, and + rcache code. Incorporate the finalization code from + krb5int_cleanup_library. + (krb5int_initialize_library): Make sure the init function runs + successfully. + (krb5int_cleanup_library): Now empty. + 2004-04-22 Ken Raeburn <raeburn@mit.edu> * libkrb5.exports: New file. diff --git a/src/lib/krb5/ccache/ChangeLog b/src/lib/krb5/ccache/ChangeLog index 5ab9d75a3..aacadc5ae 100644 --- a/src/lib/krb5/ccache/ChangeLog +++ b/src/lib/krb5/ccache/ChangeLog @@ -1,3 +1,11 @@ +2004-04-24 Ken Raeburn <raeburn@mit.edu> + + * ccbase.c: Include ctype.h. + (cc_typelist_lock): Use the new partial initializer. + (krb5int_cc_initialize): New function; finish the initialization. + (krb5int_cc_finalize): New function; destroy the mutex and free + any storage for registered types. + 2004-04-13 Jeffrey Altman <jaltman@mit.edu> * ccbase.c: diff --git a/src/lib/krb5/ccache/ccbase.c b/src/lib/krb5/ccache/ccbase.c index 4fb5f8360..f635147c2 100644 --- a/src/lib/krb5/ccache/ccbase.c +++ b/src/lib/krb5/ccache/ccbase.c @@ -50,7 +50,24 @@ static struct krb5_cc_typelist cc_fcc_entry = { &krb5_cc_file_ops, &cc_mcc_entry }; static struct krb5_cc_typelist *cc_typehead = &cc_fcc_entry; -static k5_mutex_t cc_typelist_lock = K5_MUTEX_INITIALIZER; +static k5_mutex_t cc_typelist_lock = K5_MUTEX_PARTIAL_INITIALIZER; + +int +krb5int_cc_initialize(void) +{ + return k5_mutex_finish_init(&cc_typelist_lock); +} + +void +krb5int_cc_finalize(void) +{ + struct krb5_cc_typelist *t, *t_next; + k5_mutex_destroy(&cc_typelist_lock); + for (t = cc_typehead; t != &cc_fcc_entry; t = t_next) { + t_next = t->next; + free(t); + } +} /* @@ -100,6 +117,7 @@ krb5_cc_register(krb5_context context, krb5_cc_ops *ops, krb5_boolean override) * particular cache type. */ +#include <ctype.h> krb5_error_code KRB5_CALLCONV krb5_cc_resolve (krb5_context context, const char *name, krb5_ccache *cache) { diff --git a/src/lib/krb5/keytab/ChangeLog b/src/lib/krb5/keytab/ChangeLog index a261bf901..48855a6b7 100644 --- a/src/lib/krb5/keytab/ChangeLog +++ b/src/lib/krb5/keytab/ChangeLog @@ -1,3 +1,12 @@ +2004-04-24 Ken Raeburn <raeburn@mit.edu> + + * ktbase.c: Include ctype.h. + (k5_typehead_lock): Use new partial initializer. + (krb5int_kt_initialize): New function; finish mutex + initialization. + (krb5int_kt_finalize): New function; destroy the mutex and free + storage associated with registered types. + 2004-04-13 Jeffrey Altman <jaltman@mit.edu> * ktbase.c: diff --git a/src/lib/krb5/keytab/ktbase.c b/src/lib/krb5/keytab/ktbase.c index 79c20ece9..74ff20cf6 100644 --- a/src/lib/krb5/keytab/ktbase.c +++ b/src/lib/krb5/keytab/ktbase.c @@ -52,7 +52,23 @@ const static struct krb5_kt_typelist krb5_kt_typelist_srvtab = { }; static const struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_srvtab; /* Lock for protecting the type list. */ -static k5_mutex_t kt_typehead_lock = K5_MUTEX_INITIALIZER; +static k5_mutex_t kt_typehead_lock = K5_MUTEX_PARTIAL_INITIALIZER; + +int krb5int_kt_initialize(void) +{ + return k5_mutex_finish_init(&kt_typehead_lock); +} + +void +krb5int_kt_finalize(void) +{ + struct krb5_kt_typelist *t, *t_next; + k5_mutex_destroy(&kt_typehead_lock); + for (t = kt_typehead; t != &krb5_kt_typelist_srvtab; t = t_next) { + t_next = t->next; + free(t); + } +} /* @@ -97,6 +113,7 @@ krb5_kt_register(krb5_context context, const krb5_kt_ops *ops) * particular keytab type. */ +#include <ctype.h> krb5_error_code KRB5_CALLCONV krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid) { diff --git a/src/lib/krb5/krb/ChangeLog b/src/lib/krb5/krb/ChangeLog index e36fced37..2d4ef8bef 100644 --- a/src/lib/krb5/krb/ChangeLog +++ b/src/lib/krb5/krb/ChangeLog @@ -1,7 +1,12 @@ -2004-04-16 Sam Hartman <hartmans@mit.edu> +2004-04-24 Ken Raeburn <raeburn@mit.edu> + + * init_ctx.c (init_common): In UNIX case, check the return value + from krb5int_initialize_library. +2004-04-16 Sam Hartman <hartmans@mit.edu> - * gic_pwd.c (krb5int_populate_gic_opt): Take credentials and populate lifetime options based on them. + * gic_pwd.c (krb5int_populate_gic_opt): Take credentials and + populate lifetime options based on them. * gic_keytab.c gic_pwd.c : update callers diff --git a/src/lib/krb5/krb/init_ctx.c b/src/lib/krb5/krb/init_ctx.c index 2740d8361..de6b22d50 100644 --- a/src/lib/krb5/krb/init_ctx.c +++ b/src/lib/krb5/krb/init_ctx.c @@ -128,7 +128,9 @@ init_common (krb5_context *context, krb5_boolean secure) if (retval) return retval; #else /* assume UNIX for now */ - krb5int_initialize_library (); + retval = krb5int_initialize_library (); + if (retval) + return retval; #endif *context = 0; diff --git a/src/lib/krb5/krb5_libinit.c b/src/lib/krb5/krb5_libinit.c index 3e2890896..6b7bf23ef 100644 --- a/src/lib/krb5/krb5_libinit.c +++ b/src/lib/krb5/krb5_libinit.c @@ -13,6 +13,7 @@ #endif #include "krb5_libinit.h" +#include "k5-platform.h" static int initialized = 0; @@ -20,41 +21,74 @@ static int initialized = 0; * Initialize the Kerberos v5 library. */ +MAKE_INIT_FUNCTION(krb5int_lib_init); +MAKE_FINI_FUNCTION(krb5int_lib_fini); + +/* Possibly load-time initialization -- mutexes, etc. */ +int krb5int_lib_init(void) +{ + int err; + err = krb5int_rc_finish_init(); + if (err) + return err; + err = krb5int_kt_initialize(); + if (err) + return err; + err = krb5int_cc_initialize(); + if (err) + return err; + return 0; +} + +/* Always-delayed initialization -- error table linkage, etc. */ krb5_error_code krb5int_initialize_library (void) { - - if (!initialized) { + int err; + + if (!initialized) { #if !USE_BUNDLE_ERROR_STRINGS - add_error_table(&et_krb5_error_table); - add_error_table(&et_kv5m_error_table); - add_error_table(&et_kdb5_error_table); - add_error_table(&et_asn1_error_table); + add_error_table(&et_krb5_error_table); + add_error_table(&et_kv5m_error_table); + add_error_table(&et_kdb5_error_table); + add_error_table(&et_asn1_error_table); #endif + initialized = 1; + } - initialized = 1; - } - - return 0; + return CALL_INIT_FUNCTION(krb5int_lib_init); } /* - * Clean up the Kerberos v5 lirbary state + * Clean up the Kerberos v5 library state */ -void krb5int_cleanup_library (void) +void krb5int_lib_fini(void) { - assert (initialized); + if (!INITIALIZER_RAN(krb5int_lib_init) || PROGRAM_EXITING()) + return; + + krb5int_rc_terminate(); + krb5int_kt_finalize(); + krb5int_cc_finalize(); + + if (!initialized) + return; #if defined(_WIN32) || defined(USE_CCAPI) - krb5_stdcc_shutdown(); + krb5_stdcc_shutdown(); #endif - + #if !USE_BUNDLE_ERROR_STRINGS - remove_error_table(&et_krb5_error_table); - remove_error_table(&et_kv5m_error_table); - remove_error_table(&et_kdb5_error_table); - remove_error_table(&et_asn1_error_table); + remove_error_table(&et_krb5_error_table); + remove_error_table(&et_kv5m_error_table); + remove_error_table(&et_kdb5_error_table); + remove_error_table(&et_asn1_error_table); #endif - - initialized = 0; +} + +/* Still exists because it went into the export list on Windows. But + since the above function should be invoked at unload time, we don't + actually want to do anything here. */ +void krb5int_cleanup_library (void) +{ } diff --git a/src/lib/krb5/rcache/ChangeLog b/src/lib/krb5/rcache/ChangeLog index a096114f2..870054477 100644 --- a/src/lib/krb5/rcache/ChangeLog +++ b/src/lib/krb5/rcache/ChangeLog @@ -1,3 +1,11 @@ +2004-04-24 Ken Raeburn <raeburn@mit.edu> + + * rc_base.c (rc_typelist_lock): Use new partial initializer. + (krb5int_rc_finish_init): New function, finish the mutex + initialization. + (krb5int_rc_terminate): New function, destroy the mutex and free + storage associated with registered types. + 2004-03-05 Ken Raeburn <raeburn@mit.edu> * rc_base.c: Include k5-thread.h. diff --git a/src/lib/krb5/rcache/rc_base.c b/src/lib/krb5/rcache/rc_base.c index 5758c20bc..f26b359a9 100644 --- a/src/lib/krb5/rcache/rc_base.c +++ b/src/lib/krb5/rcache/rc_base.c @@ -22,7 +22,21 @@ struct krb5_rc_typelist { }; static struct krb5_rc_typelist krb5_rc_typelist_dfl = { &krb5_rc_dfl_ops, 0 }; static struct krb5_rc_typelist *typehead = &krb5_rc_typelist_dfl; -static k5_mutex_t rc_typelist_lock = K5_MUTEX_INITIALIZER; +static k5_mutex_t rc_typelist_lock = K5_MUTEX_PARTIAL_INITIALIZER; + +int krb5int_rc_finish_init(void) +{ + return k5_mutex_finish_init(&rc_typelist_lock); +} +void krb5int_rc_terminate(void) +{ + struct krb5_rc_typelist *t, *t_next; + k5_mutex_destroy(&rc_typelist_lock); + for (t = typehead; t != &krb5_rc_typelist_dfl; t = t_next) { + t_next = t->next; + free(t); + } +} krb5_error_code krb5_rc_register_type(krb5_context context, const krb5_rc_ops *ops) |
