Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / netidmgr_plugin / main.c
blobb46aa15a6805c54a4656a52da28fd6f2b10f7382
1 /*
2 * Copyright (c) 2005,2006 Secure Endpoints Inc.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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.
25 /* $Id$ */
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)
32 #include<afscred.h>
33 #include<kmm.h>
34 #include<dynimport.h>
35 #ifdef DEBUG
36 #include<assert.h>
37 #endif
39 #pragma warning (pop)
41 kmm_module h_khModule; /* KMM's handle to this module */
42 HINSTANCE hInstance;
43 HMODULE hResModule; /* HMODULE to the resource library */
45 khm_handle csp_plugins = NULL;
46 khm_handle csp_afscred = NULL;
47 khm_handle csp_params = NULL;
49 kmm_module_locale locales[] = {
50 LOCALE_DEF(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US), L"afscred_en_us.dll", KMM_MLOC_FLAG_DEFAULT)
52 int n_locales = ARRAYLENGTH(locales);
54 /* These two probably should not do anything */
55 void init_afs() {
58 void exit_afs() {
61 /* called by the NetIDMgr module manager */
62 KHMEXP khm_int32 KHMAPI init_module(kmm_module h_module) {
63 khm_int32 rv = KHM_ERROR_SUCCESS;
64 kmm_plugin_reg pi;
65 wchar_t buf[256];
67 h_khModule = h_module;
69 rv = kmm_set_locale_info(h_module, locales, n_locales);
70 if(KHM_SUCCEEDED(rv)) {
71 hResModule = kmm_get_resource_hmodule(h_module);
72 } else {
73 goto _exit;
76 ZeroMemory(&pi,sizeof(pi));
78 pi.msg_proc = afs_plugin_cb;
79 pi.name = AFS_PLUGIN_NAME;
80 pi.type = KHM_PITYPE_CRED;
81 pi.icon = LoadImage(hResModule, MAKEINTRESOURCE(IDI_AFSPLUGIN), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
82 pi.dependencies = AFS_PLUGIN_DEPS;
83 pi.description = buf;
85 LoadString(hResModule, IDS_PLUGIN_DESC,
86 buf, ARRAYLENGTH(buf));
88 kmm_provide_plugin(h_module, &pi);
90 if(KHM_FAILED(rv = init_imports()))
91 goto _exit;
93 rv = kmm_get_plugins_config(0, &csp_plugins);
94 if(KHM_FAILED(rv)) goto _exit;
96 rv = khc_load_schema(csp_plugins, schema_afsconfig);
97 if(KHM_FAILED(rv)) goto _exit;
99 rv = khc_open_space(csp_plugins, CSNAME_AFSCRED, 0, &csp_afscred);
100 if(KHM_FAILED(rv)) goto _exit;
102 rv = khc_open_space(csp_afscred, CSNAME_PARAMS, 0, &csp_params);
103 if(KHM_FAILED(rv)) goto _exit;
105 _exit:
106 return rv;
109 /* called by the NetIDMgr module manager */
110 KHMEXP khm_int32 KHMAPI exit_module(kmm_module h_module) {
111 exit_imports();
113 if(csp_params) {
114 khc_close_space(csp_params);
115 csp_params = NULL;
117 if(csp_afscred) {
118 khc_close_space(csp_afscred);
119 csp_afscred = NULL;
121 if(csp_plugins) {
122 khc_unload_schema(csp_plugins, schema_afsconfig);
123 khc_close_space(csp_plugins);
124 csp_plugins = NULL;
127 return KHM_ERROR_SUCCESS; /* the return code is ignored */
130 BOOL WINAPI DllMain(HINSTANCE hinstDLL,
131 DWORD fdwReason,
132 LPVOID lpvReserved)
134 switch(fdwReason) {
135 case DLL_PROCESS_ATTACH:
136 hInstance = hinstDLL;
137 init_afs();
138 break;
139 case DLL_PROCESS_DETACH:
140 exit_afs();
141 break;
142 case DLL_THREAD_ATTACH:
143 break;
144 case DLL_THREAD_DETACH:
145 break;
148 return TRUE;