2
* Copyright (c) 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
30
/* This file provides the message processing function and the support
31
routines for implementing our plugin. Note that some of the
32
message processing routines have been moved to other source files
36
khm_int32 credtype_id = KCDB_CREDTYPE_INVALID;
37
khm_handle g_credset = NULL;
39
/* Handler for system messages. The only two we handle are
40
KMSG_SYSTEM_INIT and KMSG_SYSTEM_EXIT. */
42
handle_kmsg_system(khm_int32 msg_type,
43
khm_int32 msg_subtype,
46
khm_int32 rv = KHM_ERROR_SUCCESS;
48
switch (msg_subtype) {
50
/* This is the first message that will be received by a
51
plugin. We use it to perform initialization operations
52
such as registering any credential types, data types and
54
case KMSG_SYSTEM_INIT:
57
wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC];
58
wchar_t long_desc[KCDB_MAXCCH_LONG_DESC];
59
khui_config_node cnode;
60
khui_config_node_reg creg;
62
/* First and foremost, we need to register a credential
64
ZeroMemory(&ct, sizeof(ct));
65
ct.id = KCDB_CREDTYPE_AUTO;
66
ct.name = MYCREDTYPE_NAMEW;
68
short_desc[0] = L'\0';
69
LoadString(hResModule, IDS_CT_SHORT_DESC,
70
short_desc, ARRAYLENGTH(short_desc));
73
LoadString(hResModule, IDS_CT_LONG_DESC,
74
long_desc, ARRAYLENGTH(long_desc));
76
ct.icon = NULL; /* We skip the icon for now, but you
77
can assign a handle to an icon
78
here. The icon will be used to
79
represent the credentials type.*/
81
kmq_create_subscription(plugin_msg_proc, &ct.sub);
83
ct.is_equal = cred_is_equal;
85
rv = kcdb_credtype_register(&ct, &credtype_id);
87
/* We create a global credential set that we use in the
88
plug-in thread. This alleviates the need to create one
89
everytime we need one. Keep in mind that this should
90
only be used in the plug-in thread and should not be
91
touched from the UI thread or any other thread. */
92
kcdb_credset_create(&g_credset);
94
/* TODO: Perform additional initialization operations. */
96
/* TODO: Also list out the credentials of this type that
99
/* Now we register our configuration panels. */
102
/* This configuration panel is the one that controls
103
general options. We leave the identity specific and
104
identity defaults for other configuration panels. */
106
ZeroMemory(&creg, sizeof(creg));
108
short_desc[0] = L'\0';
110
LoadString(hResModule, IDS_CFG_SHORT_DESC,
111
short_desc, ARRAYLENGTH(short_desc));
113
long_desc[0] = L'\0';
115
LoadString(hResModule, IDS_CFG_LONG_DESC,
116
long_desc, ARRAYLENGTH(long_desc));
118
creg.name = CONFIGNODE_MAIN;
119
creg.short_desc = short_desc;
120
creg.long_desc = long_desc;
121
creg.h_module = hResModule;
122
creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG);
123
creg.dlg_proc = config_dlgproc;
126
khui_cfg_register(NULL, &creg);
128
/* Now we do the identity specific and identity default
129
configuration panels. "KhmIdentities" is a predefined
130
configuration node under which all the identity spcific
131
configuration is managed. */
133
if (KHM_FAILED(khui_cfg_open(NULL, L"KhmIdentities", &cnode))) {
134
/* this should always work */
136
rv = KHM_ERROR_NOT_FOUND;
140
/* First the tab panel for defaults for all identities */
142
ZeroMemory(&creg, sizeof(creg));
144
short_desc[0] = L'\0';
145
LoadString(hResModule, IDS_CFG_IDS_SHORT_DESC,
146
short_desc, ARRAYLENGTH(short_desc));
147
long_desc[0] = L'\0';
148
LoadString(hResModule, IDS_CFG_IDS_LONG_DESC,
149
long_desc, ARRAYLENGTH(long_desc));
151
creg.name = CONFIGNODE_ALL_ID;
152
creg.short_desc = short_desc;
153
creg.long_desc = long_desc;
154
creg.h_module = hResModule;
155
creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG_IDS);
156
creg.dlg_proc = config_ids_dlgproc;
157
creg.flags = KHUI_CNFLAG_SUBPANEL;
159
khui_cfg_register(cnode, &creg);
161
/* Now the panel for per identity configuration */
163
ZeroMemory(&creg, sizeof(creg));
165
short_desc[0] = L'\0';
166
LoadString(hResModule, IDS_CFG_ID_SHORT_DESC,
167
short_desc, ARRAYLENGTH(short_desc));
168
long_desc[0] = L'\0';
169
LoadString(hResModule, IDS_CFG_ID_LONG_DESC,
170
long_desc, ARRAYLENGTH(long_desc));
172
creg.name = CONFIGNODE_PER_ID;
173
creg.short_desc = short_desc;
174
creg.long_desc = long_desc;
175
creg.h_module = hResModule;
176
creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG_ID);
177
creg.dlg_proc = config_id_dlgproc;
178
creg.flags = KHUI_CNFLAG_SUBPANEL | KHUI_CNFLAG_PLURAL;
180
khui_cfg_register(cnode, &creg);
182
khui_cfg_release(cnode);
186
/* This is the last message that will be received by the
188
case KMSG_SYSTEM_EXIT:
190
khui_config_node cnode;
191
khui_config_node cn_idents;
193
/* It should not be assumed that initialization of the
194
plugin went well at this point since we receive a
195
KMSG_SYSTEM_EXIT even if the initialization failed. */
197
if (credtype_id != KCDB_CREDTYPE_INVALID) {
198
kcdb_credtype_unregister(credtype_id);
199
credtype_id = KCDB_CREDTYPE_INVALID;
203
kcdb_credset_delete(g_credset);
207
/* Now unregister any configuration nodes we registered. */
209
if (KHM_SUCCEEDED(khui_cfg_open(NULL, CONFIGNODE_MAIN, &cnode))) {
210
khui_cfg_remove(cnode);
211
khui_cfg_release(cnode);
214
if (KHM_SUCCEEDED(khui_cfg_open(NULL, L"KhmIdentities", &cn_idents))) {
215
if (KHM_SUCCEEDED(khui_cfg_open(cn_idents,
218
khui_cfg_remove(cnode);
219
khui_cfg_release(cnode);
222
if (KHM_SUCCEEDED(khui_cfg_open(cn_idents,
225
khui_cfg_remove(cnode);
226
khui_cfg_release(cnode);
229
khui_cfg_release(cn_idents);
232
/* TODO: Perform additional uninitialization
241
/* Handler for credentials the refresh message. */
243
handle_kmsg_cred_refresh(void) {
244
/* TODO: Re-enumerate the credentials of our credentials type */
247
Re-enumerating credentials would look something like this:
249
- flush all credentials from g_credset (kcdb_credset_flush())
251
- list out the credentials and add them to g_credset
253
- collect the credentials from g_credset to the root credentials
254
set. (kcdb_credset_collect())
256
Note that when listing credentials, each credential must be
257
populated with enough information to locate the actual
258
credential at a later time.
261
return KHM_ERROR_SUCCESS;
264
/* Handler for destroying credentials */
266
handle_kmsg_cred_destroy_creds(khui_action_context * ctx) {
267
/* TODO: Destroy credentials of our type as specified by the
268
action context passed in through vparam. */
270
/* The credential set in ctx->credset contains the credentials
271
that are to be destroyed. */
273
return KHM_ERROR_SUCCESS;
276
/* Begin a property sheet */
278
handle_kmsg_cred_pp_begin(khui_property_sheet * ps) {
280
/* TODO: Provide the information necessary to show a property
281
page for a credentials belonging to our credential type. */
285
if (ps->credtype == credtype_id &&
287
/* We have been requested to show a property sheet for one of
289
p = malloc(sizeof(*p));
290
ZeroMemory(p, sizeof(*p));
292
p->dwSize = sizeof(*p);
294
p->hInstance = hResModule;
295
p->pszTemplate = MAKEINTRESOURCE(IDD_PP_CRED);
296
p->pfnDlgProc = pp_cred_dlg_proc;
297
p->lParam = (LPARAM) ps;
298
khui_ps_add_page(ps, credtype_id, 0, p, NULL);
301
return KHM_ERROR_SUCCESS;
304
/* End a property sheet */
306
handle_kmsg_cred_pp_end(khui_property_sheet * ps) {
307
/* TODO: Handle the end of a property sheet. */
309
khui_property_page * p = NULL;
311
khui_ps_find_page(ps, credtype_id, &p);
318
return KHM_ERROR_SUCCESS;
321
/* IP address change notification */
323
handle_kmsg_cred_addr_change(void) {
324
/* TODO: Handle this message. */
326
return KHM_ERROR_SUCCESS;
329
/* Message dispatcher for credentials messages. */
331
handle_kmsg_cred(khm_int32 msg_type,
332
khm_int32 msg_subtype,
335
khm_int32 rv = KHM_ERROR_SUCCESS;
337
switch(msg_subtype) {
338
case KMSG_CRED_REFRESH:
339
return handle_kmsg_cred_refresh();
341
case KMSG_CRED_DESTROY_CREDS:
342
return handle_kmsg_cred_destroy_creds((khui_action_context *) vparam);
344
case KMSG_CRED_PP_BEGIN:
345
return handle_kmsg_cred_pp_begin((khui_property_sheet *) vparam);
347
case KMSG_CRED_PP_END:
348
return handle_kmsg_cred_pp_end((khui_property_sheet *) vparam);
350
case KMSG_CRED_ADDR_CHANGE:
351
return handle_kmsg_cred_addr_change();
354
/* Credentials acquisition messages are all handled in a
355
different source file. */
356
if (IS_CRED_ACQ_MSG(msg_subtype))
357
return handle_cred_acq_msg(msg_type, msg_subtype,
365
/* This is the main message handler for our plugin. All the plugin
366
messages end up here where we either handle it directly or dispatch
367
it to other handlers. */
368
khm_int32 KHMAPI plugin_msg_proc(khm_int32 msg_type,
369
khm_int32 msg_subtype,
375
return handle_kmsg_system(msg_type, msg_subtype, uparam, vparam);
378
return handle_kmsg_cred(msg_type, msg_subtype, uparam, vparam);
381
return KHM_ERROR_SUCCESS;