~ubuntu-branches/ubuntu/precise/krb5/precise-updates

« back to all changes in this revision

Viewing changes to src/windows/identity/kmm/kmmmain.c

  • Committer: Package Import Robot
  • Author(s): Sam Hartman
  • Date: 2011-12-01 19:34:41 UTC
  • mfrom: (28.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20111201193441-9tipg3aru1jsidyv
Tags: 1.10+dfsg~alpha1-6
* Fix segfault with unknown hostnames in krb5_sname_to_principal,
  Closes: #650671
* Indicate that this library breaks libsmbclient versions that depend on
  krb5_locate_kdc, Closes: #650603, #650611

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2005 Massachusetts Institute of Technology
3
 
 * Copyright (c) 2007 Secure Endpoints Inc.
4
 
 *
5
 
 * Permission is hereby granted, free of charge, to any person
6
 
 * obtaining a copy of this software and associated documentation
7
 
 * files (the "Software"), to deal in the Software without
8
 
 * restriction, including without limitation the rights to use, copy,
9
 
 * modify, merge, publish, distribute, sublicense, and/or sell copies
10
 
 * of the Software, and to permit persons to whom the Software is
11
 
 * furnished to do so, subject to the following conditions:
12
 
 *
13
 
 * The above copyright notice and this permission notice shall be
14
 
 * included in all copies or substantial portions of the Software.
15
 
 *
16
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
 
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
 
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
 
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 
 * SOFTWARE.
24
 
 */
25
 
 
26
 
/* $Id$ */
27
 
 
28
 
#include<kmminternal.h>
29
 
 
30
 
kmm_module_i * kmm_all_modules = NULL;
31
 
kmm_plugin_i * kmm_listed_plugins = NULL;
32
 
 
33
 
HANDLE ht_registrar = NULL;
34
 
DWORD tid_registrar = 0;
35
 
DWORD tls_kmm = 0;
36
 
 
37
 
#define KMM_HASH_SIZE 31
38
 
hashtable * hash_plugins = NULL;
39
 
hashtable * hash_modules = NULL;
40
 
 
41
 
CRITICAL_SECTION cs_kmm;
42
 
HANDLE evt_startup = NULL;
43
 
HANDLE evt_exit = NULL;
44
 
int ready = 0;
45
 
 
46
 
HINSTANCE kmm_hInstance;
47
 
const wchar_t * kmm_facility = L"KMM";
48
 
 
49
 
KHMEXP void KHMAPI kmm_init(void)
50
 
{
51
 
    DWORD dummy;
52
 
 
53
 
    EnterCriticalSection(&cs_kmm);
54
 
    kmm_all_modules = NULL;
55
 
    kmm_listed_plugins = NULL;
56
 
 
57
 
    tls_kmm = TlsAlloc();
58
 
 
59
 
    hash_plugins = hash_new_hashtable(
60
 
        KMM_HASH_SIZE,
61
 
        hash_string,
62
 
        hash_string_comp,
63
 
        NULL,
64
 
        NULL);
65
 
 
66
 
    hash_modules = hash_new_hashtable(
67
 
        KMM_HASH_SIZE,
68
 
        hash_string,
69
 
        hash_string_comp,
70
 
        NULL,
71
 
        NULL);
72
 
 
73
 
    ht_registrar = CreateThread(
74
 
        NULL,
75
 
        0,
76
 
        kmmint_registrar,
77
 
        NULL,
78
 
        0,
79
 
        &dummy);
80
 
 
81
 
    _WAIT_FOR_START;
82
 
 
83
 
    khc_load_schema(NULL, schema_kmmconfig);
84
 
 
85
 
    LeaveCriticalSection(&cs_kmm);
86
 
}
87
 
 
88
 
KHMEXP void KHMAPI kmm_exit(void)
89
 
{
90
 
    kmm_module_i * m;
91
 
    kmm_plugin_i * p;
92
 
 
93
 
    EnterCriticalSection(&cs_kmm);
94
 
 
95
 
    p = kmm_listed_plugins;
96
 
    while(p) {
97
 
        kmm_plugin_i * pn;
98
 
 
99
 
        pn = LNEXT(p);
100
 
        /* plugins that were never resolved should be kicked off the
101
 
           list.  Flipping the refcount will do that if no other
102
 
           references exist for the plugin.  The plugins that were
103
 
           waiting for unresolved dependencies will automatically get
104
 
           freed when the placeholders and other plugins get freed. */
105
 
        if(p->state == KMM_PLUGIN_STATE_PLACEHOLDER) {
106
 
            kmm_hold_plugin(kmm_handle_from_plugin(p));
107
 
            kmm_release_plugin(kmm_handle_from_plugin(p));
108
 
        }
109
 
 
110
 
        p = pn;
111
 
    }
112
 
 
113
 
    m = kmm_all_modules;
114
 
    while(m) {
115
 
        kmm_unload_module(kmm_handle_from_module(m));
116
 
        m = LNEXT(m);
117
 
    }
118
 
 
119
 
    LeaveCriticalSection(&cs_kmm);
120
 
    WaitForSingleObject(evt_exit, INFINITE);
121
 
 
122
 
    kmq_send_thread_quit_message(tid_registrar, 0);
123
 
 
124
 
    EnterCriticalSection(&cs_kmm);
125
 
 
126
 
    hash_del_hashtable(hash_plugins);
127
 
    hash_del_hashtable(hash_modules);
128
 
 
129
 
    LeaveCriticalSection(&cs_kmm);
130
 
 
131
 
    TlsFree(tls_kmm);
132
 
 
133
 
    tls_kmm = 0;
134
 
}
135
 
 
136
 
void kmm_dll_init(void)
137
 
{
138
 
    InitializeCriticalSection(&cs_kmm);
139
 
    evt_startup = CreateEvent(NULL, TRUE, FALSE, NULL);
140
 
    evt_exit = CreateEvent(NULL, TRUE, TRUE, NULL);
141
 
}
142
 
 
143
 
void kmm_dll_exit(void)
144
 
{
145
 
    DeleteCriticalSection(&cs_kmm);
146
 
    if(evt_startup)
147
 
        CloseHandle(evt_startup);
148
 
    evt_startup = NULL;
149
 
}
150
 
 
151
 
void
152
 
kmm_process_attach(HINSTANCE hinstDLL) {
153
 
    kmm_hInstance = hinstDLL;
154
 
    kmm_dll_init();
155
 
}
156
 
 
157
 
void
158
 
kmm_process_detach(void) {
159
 
    kmm_dll_exit();
160
 
}