1 /* 2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 #pragma ident "%Z%%M% %I% %E% SMI" 7 8 #include <assert.h> 9 10 #include "autoconf.h" 11 #include "com_err.h" 12 #include "krb5.h" 13 #if 0 /* SUNW14resync */ 14 #include "krb5_err.h" 15 #include "kv5m_err.h" 16 #include "asn1_err.h" 17 #include "kdb5_err.h" 18 #endif 19 20 #if defined(_WIN32) || defined(USE_CCAPI) 21 #include "stdcc.h" 22 #endif 23 24 #include "krb5_libinit.h" 25 #include "k5-platform.h" 26 #include "cc-int.h" 27 #include "kt-int.h" 28 #include "rc-int.h" 29 #include "os-proto.h" 30 31 /* 32 * Initialize the Kerberos v5 library. 33 */ 34 35 MAKE_INIT_FUNCTION(krb5int_lib_init); 36 MAKE_FINI_FUNCTION(krb5int_lib_fini); 37 38 /* Possibly load-time initialization -- mutexes, etc. */ 39 int krb5int_lib_init(void) 40 { 41 int err; 42 43 #if !USE_BUNDLE_ERROR_STRINGS 44 add_error_table(&et_krb5_error_table); 45 add_error_table(&et_kv5m_error_table); 46 add_error_table(&et_kdb5_error_table); 47 add_error_table(&et_asn1_error_table); 48 add_error_table(&et_k524_error_table); 49 #endif 50 51 err = krb5int_rc_finish_init(); 52 if (err) 53 return err; 54 err = krb5int_kt_initialize(); 55 if (err) 56 return err; 57 err = krb5int_cc_initialize(); 58 if (err) 59 return err; 60 err = k5_mutex_finish_init(&krb5int_us_time_mutex); 61 if (err) 62 return err; 63 return 0; 64 } 65 66 /* Always-delayed initialization -- error table linkage, etc. */ 67 krb5_error_code krb5int_initialize_library (void) 68 { 69 return CALL_INIT_FUNCTION(krb5int_lib_init); 70 } 71 72 /* 73 * Clean up the Kerberos v5 library state 74 */ 75 76 void krb5int_lib_fini(void) 77 { 78 if (!INITIALIZER_RAN(krb5int_lib_init) || PROGRAM_EXITING()) 79 return; 80 81 krb5int_rc_terminate(); 82 krb5int_kt_finalize(); 83 krb5int_cc_finalize(); 84 85 #if defined(_WIN32) || defined(USE_CCAPI) 86 krb5_stdcc_shutdown(); 87 #endif 88 89 #if !USE_BUNDLE_ERROR_STRINGS 90 remove_error_table(&et_krb5_error_table); 91 remove_error_table(&et_kv5m_error_table); 92 remove_error_table(&et_kdb5_error_table); 93 remove_error_table(&et_asn1_error_table); 94 remove_error_table(&et_k524_error_table); 95 #endif 96 } 97 98 /* Still exists because it went into the export list on Windows. But 99 since the above function should be invoked at unload time, we don't 100 actually want to do anything here. */ 101 void krb5int_cleanup_library (void) 102 { 103 } 104