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