Add/remove error tables in library initialization/termination, not per context.
[krb5.git] / src / lib / krb5 / krb5_libinit.c
1 #include <assert.h>
2
3 #include "autoconf.h"
4 #include "com_err.h"
5 #include "krb5.h"
6 #include "krb5_err.h"
7 #include "kv5m_err.h"
8 #include "asn1_err.h"
9 #include "kdb5_err.h"
10
11 #if defined(_WIN32) || defined(USE_CCAPI)
12 #include "stdcc.h"
13 #endif
14
15 #include "krb5_libinit.h"
16 #include "k5-platform.h"
17 #include "cc-int.h"
18 #include "kt-int.h"
19 #include "rc-int.h"
20
21 /*
22  * Initialize the Kerberos v5 library.
23  */
24
25 MAKE_INIT_FUNCTION(krb5int_lib_init);
26 MAKE_FINI_FUNCTION(krb5int_lib_fini);
27
28 /* Possibly load-time initialization -- mutexes, etc.  */
29 int krb5int_lib_init(void)
30 {
31     int err;
32
33 #if !USE_BUNDLE_ERROR_STRINGS
34     add_error_table(&et_krb5_error_table);
35     add_error_table(&et_kv5m_error_table);
36     add_error_table(&et_kdb5_error_table);
37     add_error_table(&et_asn1_error_table);
38 #endif
39
40     err = krb5int_rc_finish_init();
41     if (err)
42         return err;
43     err = krb5int_kt_initialize();
44     if (err)
45         return err;
46     err = krb5int_cc_initialize();
47     if (err)
48         return err;
49     return 0;
50 }
51
52 /* Always-delayed initialization -- error table linkage, etc.  */
53 krb5_error_code krb5int_initialize_library (void)
54 {
55     return CALL_INIT_FUNCTION(krb5int_lib_init);
56 }
57
58 /*
59  * Clean up the Kerberos v5 library state
60  */
61
62 void krb5int_lib_fini(void)
63 {
64     if (!INITIALIZER_RAN(krb5int_lib_init) || PROGRAM_EXITING())
65         return;
66
67     krb5int_rc_terminate();
68     krb5int_kt_finalize();
69     krb5int_cc_finalize();
70
71 #if defined(_WIN32) || defined(USE_CCAPI)
72     krb5_stdcc_shutdown();
73 #endif
74
75 #if !USE_BUNDLE_ERROR_STRINGS
76     remove_error_table(&et_krb5_error_table);
77     remove_error_table(&et_kv5m_error_table);
78     remove_error_table(&et_kdb5_error_table);
79     remove_error_table(&et_asn1_error_table);
80 #endif
81 }
82
83 /* Still exists because it went into the export list on Windows.  But
84    since the above function should be invoked at unload time, we don't
85    actually want to do anything here.  */
86 void krb5int_cleanup_library (void)
87 {
88 }