c982df026fbf1c460ba816edc6d94a04985bad71
[openafs.git] / src / WINNT / netidmgr_plugin / main.c
1 /*
2  * Copyright (c) 2005,2006 Secure Endpoints Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24
25 /* $Id$ */
26
27 /* Disable the 'macro redefinition' warning which is getting
28    triggerred by a redefinition of the ENCRYPT and DECRYPT macros. */
29 #pragma warning (push)
30 #pragma warning (disable: 4005)
31
32 #include<afscred.h>
33 #include<kmm.h>
34 #include<dynimport.h>
35 #ifdef DEBUG
36 #include<assert.h>
37 #endif
38 #include <krbcompat_delayload.h>
39
40 #pragma warning (pop)
41
42 kmm_module h_khModule; /* KMM's handle to this module */
43 HINSTANCE hInstance;
44 HMODULE hResModule;    /* HMODULE to the resource library */
45
46 khm_handle csp_plugins      = NULL;
47 khm_handle csp_afscred      = NULL;
48 khm_handle csp_params       = NULL;
49
50 kmm_module_locale locales[] = {
51     LOCALE_DEF(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US), L"afscred_en_us.dll", KMM_MLOC_FLAG_DEFAULT),
52     LOCALE_DEF(MAKELANGID(LANG_CZECH,SUBLANG_CZECH_CZECH_REPUBLIC), L"afscred_cs_cz.dll", 0)
53 };
54 int n_locales = ARRAYLENGTH(locales);
55
56 /* These two probably should not do anything */
57 void init_afs() {
58 }
59
60 void exit_afs() {
61 }
62
63 /* called by the NetIDMgr module manager */
64 KHMEXP khm_int32 KHMAPI init_module(kmm_module h_module) {
65     khm_int32 rv = KHM_ERROR_SUCCESS;
66     kmm_plugin_reg pi;
67     wchar_t buf[256];
68
69     h_khModule = h_module;
70
71     rv = kmm_set_locale_info(h_module, locales, n_locales);
72     if(KHM_SUCCEEDED(rv)) {
73         hResModule = kmm_get_resource_hmodule(h_module);
74     } else {
75         goto _exit;
76     }
77
78     DelayLoadHeimdal();
79
80     ZeroMemory(&pi,sizeof(pi));
81
82     pi.msg_proc = afs_plugin_cb;
83     pi.name = AFS_PLUGIN_NAME;
84     pi.type = KHM_PITYPE_CRED;
85     pi.icon = LoadImage(hResModule, MAKEINTRESOURCE(IDI_AFSPLUGIN), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
86     pi.dependencies = AFS_PLUGIN_DEPS;
87     pi.description = buf;
88
89     LoadString(hResModule, IDS_PLUGIN_DESC,
90                buf, ARRAYLENGTH(buf));
91
92     kmm_provide_plugin(h_module, &pi);
93
94     if(KHM_FAILED(rv = init_imports()))
95         goto _exit;
96
97     rv = kmm_get_plugins_config(0, &csp_plugins);
98     if(KHM_FAILED(rv)) goto _exit;
99
100     rv = khc_load_schema(csp_plugins, schema_afsconfig);
101     if(KHM_FAILED(rv)) goto _exit;
102
103     rv = khc_open_space(csp_plugins, CSNAME_AFSCRED, 0, &csp_afscred);
104     if(KHM_FAILED(rv)) goto _exit;
105
106     rv = khc_open_space(csp_afscred, CSNAME_PARAMS, 0, &csp_params);
107     if(KHM_FAILED(rv)) goto _exit;
108
109 _exit:
110     return rv;
111 }
112
113 /* called by the NetIDMgr module manager */
114 KHMEXP khm_int32 KHMAPI exit_module(kmm_module h_module) {
115     exit_imports();
116
117     if(csp_params) {
118         khc_close_space(csp_params);
119         csp_params = NULL;
120     }
121     if(csp_afscred) {
122         khc_close_space(csp_afscred);
123         csp_afscred = NULL;
124     }
125     if(csp_plugins) {
126         khc_unload_schema(csp_plugins, schema_afsconfig);
127         khc_close_space(csp_plugins);
128         csp_plugins = NULL;
129     }
130
131     return KHM_ERROR_SUCCESS; /* the return code is ignored */
132 }
133
134 BOOL WINAPI DllMain(HINSTANCE hinstDLL,
135                     DWORD fdwReason,
136                     LPVOID lpvReserved)
137 {
138     switch(fdwReason) {
139         case DLL_PROCESS_ATTACH:
140             hInstance = hinstDLL;
141             init_afs();
142             break;
143         case DLL_PROCESS_DETACH:
144             exit_afs();
145             break;
146         case DLL_THREAD_ATTACH:
147             break;
148         case DLL_THREAD_DETACH:
149             break;
150     }
151
152     return TRUE;
153 }