From: Miro Jurisic Date: Sat, 22 Jan 2000 04:04:36 +0000 (+0000) Subject: Moved krb5, gss, and crypto library initialization/cleanup code into new dedicated... X-Git-Tag: krb5-1.2-beta1~157 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3954dd2c1f9919e2ac09f86f022063119b5dd8d3;p=krb5.git Moved krb5, gss, and crypto library initialization/cleanup code into new dedicated functions; added code to release global state allocated in prng.c git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11960 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/ChangeLog b/src/lib/crypto/ChangeLog index 0c4236842..957a0ec31 100644 --- a/src/lib/crypto/ChangeLog +++ b/src/lib/crypto/ChangeLog @@ -1,3 +1,9 @@ +Fri Jan 21 22:47:00 2000 Miro Jurisic + + * Makefile.in: added crypto_libinit.[co] + * crypto_libinit.[ch]: new files, contain library initialization + and cleanup code + 2000-01-21 Ken Raeburn * cksumtypes.c (krb5_cksumtypes_list, krb5_cksumtypes_length): Now diff --git a/src/lib/crypto/Makefile.in b/src/lib/crypto/Makefile.in index d86325bf8..71bddf5c4 100644 --- a/src/lib/crypto/Makefile.in +++ b/src/lib/crypto/Makefile.in @@ -26,6 +26,7 @@ STLIBOBJS=\ cksumtype_to_string.o \ cksumtypes.o \ coll_proof_cksum.o \ + crypto_libinit.o \ decrypt.o \ encrypt.o \ encrypt_length.o \ @@ -53,6 +54,7 @@ OBJS=\ $(OUTPRE)cksumtype_to_string.$(OBJEXT) \ $(OUTPRE)cksumtypes.$(OBJEXT) \ $(OUTPRE)coll_proof_cksum.$(OBJEXT) \ + $(OUTPRE)crypto_libinit.$(OBJEXT) \ $(OUTPRE)decrypt.$(OBJEXT) \ $(OUTPRE)encrypt.$(OBJEXT) \ $(OUTPRE)encrypt_length.$(OBJEXT) \ @@ -80,6 +82,7 @@ SRCS=\ $(subdir)/cksumtype_to_string.c \ $(subdir)/cksumtypes.c \ $(subdir)/coll_proof_cksum.c \ + $(subdir)/crypto_libinit.c \ $(subdir)/decrypt.c \ $(subdir)/encrypt.c \ $(subdir)/encrypt_length.c \ diff --git a/src/lib/crypto/crypto_libinit.c b/src/lib/crypto/crypto_libinit.c new file mode 100644 index 000000000..5ae277e9e --- /dev/null +++ b/src/lib/crypto/crypto_libinit.c @@ -0,0 +1,30 @@ +#include + +static int initialized = false; + +/* + * Initialize the crypto library. + */ + +int cryptoint_initialize_library (void) +{ + + if (!initialized) { + initialized = true; + } + + return 0; +} + +/* + * Clean up the crypto library state + */ + +void cryptoint_cleanup_library (void) +{ + assert (initialized); + + prng_cleanup (); + + initialized = false; +} \ No newline at end of file diff --git a/src/lib/crypto/crypto_libinit.h b/src/lib/crypto/crypto_libinit.h new file mode 100644 index 000000000..3586a63aa --- /dev/null +++ b/src/lib/crypto/crypto_libinit.h @@ -0,0 +1,7 @@ +#ifndef KRB5_LIBINIT_H +#define KRB5_LIBINIT_H + +int cryptoint_initialize_library (void); +void cryptoint_cleanup_library (void); + +#endif /* KRB5_LIBINIT_H */ diff --git a/src/lib/crypto/prng.c b/src/lib/crypto/prng.c index c0f106f0a..6d401a9bf 100644 --- a/src/lib/crypto/prng.c +++ b/src/lib/crypto/prng.c @@ -153,3 +153,9 @@ krb5_c_random_make_octets(krb5_context context, krb5_data *data) return(0); } + +void prng_cleanup (void) +{ + free (random_state); + inited = 0; +} \ No newline at end of file diff --git a/src/lib/gssapi/ChangeLog b/src/lib/gssapi/ChangeLog index 8f794fa71..64f7f5765 100644 --- a/src/lib/gssapi/ChangeLog +++ b/src/lib/gssapi/ChangeLog @@ -1,3 +1,9 @@ +Fri Jan 21 22:47:00 2000 Miro Jurisic + + * Makefile.in: added gss_libinit.[co] + * gss_libinit.[ch]: new files, contain library initialization + and cleanup code + Tue May 18 19:52:56 1999 Danilo Almeida * Makefile.in: Remove - from recursive Win32 make invocation. diff --git a/src/lib/gssapi/Makefile.in b/src/lib/gssapi/Makefile.in index 992615d55..5198aec4b 100644 --- a/src/lib/gssapi/Makefile.in +++ b/src/lib/gssapi/Makefile.in @@ -12,6 +12,12 @@ LOCAL_SUBDIRS= generic krb5 MAC_SUBDIRS = generic krb5 +OBJS=\ + $(OUTPRE)gss_libinit.$(OBJEXT) + +SRCS=\ + $(subdir)/gss_libinit.c + LIB=gssapi_krb5 LIBMAJOR=2 LIBMINOR=1 diff --git a/src/lib/gssapi/gss_libinit.c b/src/lib/gssapi/gss_libinit.c new file mode 100644 index 000000000..ac91b0fa1 --- /dev/null +++ b/src/lib/gssapi/gss_libinit.c @@ -0,0 +1,43 @@ +#include + +#include "gssapi_err_generic.h" +#include "gssapi_err_krb5.h" + +#include "gss_libinit.h" + +static int initialized = false; + +/* + * Initialize the GSSAPI library. + */ + +OM_uint32 gssint_initialize_library (void) +{ + + if (!initialized) { + add_error_table(&et_k5g_error_table); + add_error_table(&et_ggss_error_table); + + initialized = true; + } + + return 0; +} + +/* + * Clean up the Kerberos v5 lirbary state + */ + +void gssint_cleanup_library (void) +{ + OM_uint32 maj_stat, min_stat; + + assert (initialized); + + maj_stat = kg_release_defcred (&min_stat); + + remove_error_table(&et_k5g_error_table); + remove_error_table(&et_ggss_error_table); + + initialized = false; +} \ No newline at end of file diff --git a/src/lib/gssapi/gss_libinit.h b/src/lib/gssapi/gss_libinit.h new file mode 100644 index 000000000..ba89ff397 --- /dev/null +++ b/src/lib/gssapi/gss_libinit.h @@ -0,0 +1,9 @@ +#ifndef KRB5_LIBINIT_H +#define KRB5_LIBINIT_H + +#include "gssapi.h" + +OM_uint32 gssint_initialize_library (void); +void gssint_cleanup_library (void); + +#endif /* KRB5_LIBINIT_H */ diff --git a/src/lib/krb5/ChangeLog b/src/lib/krb5/ChangeLog index b11d3091e..5cb84642b 100644 --- a/src/lib/krb5/ChangeLog +++ b/src/lib/krb5/ChangeLog @@ -1,3 +1,9 @@ +Fri Jan 21 22:47:00 2000 Miro Jurisic + + * Makefile.in: added krb5_libinit.[co] + * krb5_libinit.[ch]: new files, contain library initialization + and cleanup code + 1999-12-01 Ken Raeburn * Makefile.in (LIBMINOR): Update to 2. diff --git a/src/lib/krb5/Makefile.in b/src/lib/krb5/Makefile.in index 4235d7272..b03b623df 100644 --- a/src/lib/krb5/Makefile.in +++ b/src/lib/krb5/Makefile.in @@ -45,6 +45,12 @@ STOBJLISTS= \ posix/OBJS.ST \ $(BUILDTOP)/util/profile/OBJS.ST +OBJS=\ + $(OUTPRE)krb5_libinit.$(OBJEXT) + +SRCS=\ + $(subdir)/krb5_libinit.c + RELDIR=krb5 SHLIB_EXPDEPS = \ $(TOPLIBD)/libk5crypto$(SHLIBEXT) \ diff --git a/src/lib/krb5/krb5_libinit.c b/src/lib/krb5/krb5_libinit.c new file mode 100644 index 000000000..584aa57f5 --- /dev/null +++ b/src/lib/krb5/krb5_libinit.c @@ -0,0 +1,46 @@ +#include + +#include "krb5.h" +#include "krb5_err.h" +#include "kv5m_err.h" +#include "asn1_err.h" +#include "kdb5_err.h" + +static int initialized = false; + +/* + * Initialize the Kerberos v5 library. + */ + +krb5_error_code krb5int_initialize_library (void) +{ + + if (!initialized) { + 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); + + initialized = true; + } + + return 0; +} + +/* + * Clean up the Kerberos v5 lirbary state + */ + +void krb5int_cleanup_library (void) +{ + assert (initialized); + + krb5_stdcc_shutdown(); + + 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); + + initialized = false; +} \ No newline at end of file diff --git a/src/lib/krb5/krb5_libinit.h b/src/lib/krb5/krb5_libinit.h new file mode 100644 index 000000000..11d7248fe --- /dev/null +++ b/src/lib/krb5/krb5_libinit.h @@ -0,0 +1,9 @@ +#ifndef KRB5_LIBINIT_H +#define KRB5_LIBINIT_H + +#include "krb5.h" + +krb5_error_code krb5int_initialize_library (void); +void krb5int_cleanup_library (void); + +#endif /* KRB5_LIBINIT_H */ diff --git a/src/mac/GSS.CFM.c b/src/mac/GSS.CFM.c index a7c7c64ec..985ccd240 100644 --- a/src/mac/GSS.CFM.c +++ b/src/mac/GSS.CFM.c @@ -19,10 +19,7 @@ #include -#include "gssapi_err_generic.h" -#include "gssapi_err_krb5.h" - -#include "gssapi.h" +#include "gss_libinit.h" OSErr __initializeGSS(CFragInitBlockPtr ibp); void __terminateGSS(void); @@ -36,8 +33,7 @@ OSErr __initializeGSS(CFragInitBlockPtr ibp) /* Initialize the error tables */ if (err == noErr) { - add_error_table(&et_k5g_error_table); - add_error_table(&et_ggss_error_table); + err = gssint_initialize_library (); } return err; @@ -45,13 +41,7 @@ OSErr __initializeGSS(CFragInitBlockPtr ibp) void __terminateGSS(void) { - - OM_uint32 maj_stat, min_stat; - - maj_stat = kg_release_defcred (&min_stat); - - remove_error_table(&et_k5g_error_table); - remove_error_table(&et_ggss_error_table); + gssint_cleanup_library (); __terminate(); } diff --git a/src/mac/K5.CFM.c b/src/mac/K5.CFM.c index 57d1fbb26..efb918cfc 100644 --- a/src/mac/K5.CFM.c +++ b/src/mac/K5.CFM.c @@ -19,12 +19,8 @@ #include -#include "krb5_err.h" -#include "kv5m_err.h" -#include "asn1_err.h" -#include "kdb5_err.h" -#include "profile.h" -#include "adm_err.h" +#include "krb5_libinit.h" +#include "crypto_libinit.h" OSErr __initializeK5(CFragInitBlockPtr ibp); @@ -34,17 +30,14 @@ OSErr __initializeK5(CFragInitBlockPtr ibp) { OSErr err = noErr; - /* Do normal init of the shared library */ err = __initialize(); - /* Initialize the error tables */ if (err == noErr) { - 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_prof_error_table); - add_error_table(&et_kadm_error_table); + err = krb5int_initialize_library (); + } + + if (err == noErr) { + err = cryptoint_initialize_library (); } return err; @@ -53,14 +46,8 @@ OSErr __initializeK5(CFragInitBlockPtr ibp) void __terminateK5(void) { - krb5_stdcc_shutdown(); - - 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_prof_error_table); - remove_error_table(&et_kadm_error_table); + cryptoint_cleanup_library (); + krb5int_cleanup_library (); __terminate(); }