summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/krb5_libinit.c
blob: f83d25b1cf5b0326835ba640a8a47b36bcdca928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <assert.h>

#include "autoconf.h"
#include "com_err.h"
#include "k5-int.h"

#if defined(_WIN32) || defined(USE_CCAPI)
#include "stdcc.h"
#endif

#include "krb5_libinit.h"
#include "k5-platform.h"
#include "cc-int.h"
#include "kt-int.h"
#include "rc-int.h"
#include "os-proto.h"

/*
 * Initialize the Kerberos v5 library.
 */

MAKE_INIT_FUNCTION(krb5int_lib_init);
MAKE_FINI_FUNCTION(krb5int_lib_fini);

/* Possibly load-time initialization -- mutexes, etc.  */
int krb5int_lib_init(void)
{
    int err;

    k5_set_error_info_callout_fn(error_message);

#ifdef SHOW_INITFINI_FUNCS
    printf("krb5int_lib_init\n");
#endif

    add_error_table(&et_krb5_error_table);
    add_error_table(&et_k5e1_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_k524_error_table);

    bindtextdomain(KRB5_TEXTDOMAIN, LOCALEDIR);

    err = krb5int_rc_finish_init();
    if (err)
        return err;
#ifndef LEAN_CLIENT
    err = krb5int_kt_initialize();
    if (err)
        return err;
#endif /* LEAN_CLIENT */
    err = krb5int_cc_initialize();
    if (err)
        return err;
    err = k5_mutex_finish_init(&krb5int_us_time_mutex);
    if (err)
        return err;

    return 0;
}

/* Always-delayed initialization -- error table linkage, etc.  */
krb5_error_code krb5int_initialize_library (void)
{
    return CALL_INIT_FUNCTION(krb5int_lib_init);
}

/*
 * Clean up the Kerberos v5 library state
 */

void krb5int_lib_fini(void)
{
    if (!INITIALIZER_RAN(krb5int_lib_init) || PROGRAM_EXITING()) {
#ifdef SHOW_INITFINI_FUNCS
        printf("krb5int_lib_fini: skipping\n");
#endif
        return;
    }

#ifdef SHOW_INITFINI_FUNCS
    printf("krb5int_lib_fini\n");
#endif

    k5_mutex_destroy(&krb5int_us_time_mutex);

    krb5int_cc_finalize();
#ifndef LEAN_CLIENT
    krb5int_kt_finalize();
#endif /* LEAN_CLIENT */
    krb5int_rc_terminate();

#if defined(_WIN32) || defined(USE_CCAPI)
    krb5_stdcc_shutdown();
#endif

    remove_error_table(&et_krb5_error_table);
    remove_error_table(&et_k5e1_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_k524_error_table);

    k5_set_error_info_callout_fn(NULL);
}

/* Still exists because it went into the export list on Windows.  But
   since the above function should be invoked at unload time, we don't
   actually want to do anything here.  */
void krb5int_cleanup_library (void)
{
}