1 /*
2  * Copyright 2007 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     krb5int_set_error_info_callout_fn (error_message);
44 
45 #if !USE_BUNDLE_ERROR_STRINGS
46     add_error_table(&et_krb5_error_table);
47     add_error_table(&et_kv5m_error_table);
48     add_error_table(&et_kdb5_error_table);
49     add_error_table(&et_asn1_error_table);
50     add_error_table(&et_k524_error_table);
51 #endif
52 
53     err = krb5int_rc_finish_init();
54     if (err)
55 	return err;
56     err = krb5int_kt_initialize();
57     if (err)
58 	return err;
59     err = krb5int_cc_initialize();
60     if (err)
61 	return err;
62     err = k5_mutex_finish_init(&krb5int_us_time_mutex);
63     if (err)
64 	return err;
65     return 0;
66 }
67 
68 /* Always-delayed initialization -- error table linkage, etc.  */
69 krb5_error_code krb5int_initialize_library (void)
70 {
71     return CALL_INIT_FUNCTION(krb5int_lib_init);
72 }
73 
74 /*
75  * Clean up the Kerberos v5 library state
76  */
77 
78 void krb5int_lib_fini(void)
79 {
80     if (!INITIALIZER_RAN(krb5int_lib_init) || PROGRAM_EXITING())
81 	return;
82 
83     krb5int_rc_terminate();
84     krb5int_kt_finalize();
85     krb5int_cc_finalize();
86 
87 #if defined(_WIN32) || defined(USE_CCAPI)
88     krb5_stdcc_shutdown();
89 #endif
90 
91 #if !USE_BUNDLE_ERROR_STRINGS
92     remove_error_table(&et_krb5_error_table);
93     remove_error_table(&et_kv5m_error_table);
94     remove_error_table(&et_kdb5_error_table);
95     remove_error_table(&et_asn1_error_table);
96     remove_error_table(&et_k524_error_table);
97 #endif
98     krb5int_set_error_info_callout_fn (0);
99 }
100 
101 /* Still exists because it went into the export list on Windows.  But
102    since the above function should be invoked at unload time, we don't
103    actually want to do anything here.  */
104 void krb5int_cleanup_library (void)
105 {
106 }
107