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
31 /* This file provides the message processing function and the support
32 routines for implementing our plugin. Note that some of the
33 message processing routines have been moved to other source files
37 khm_int32 msg_type_afs = -1;
38 khm_handle g_credset = NULL;
39 afs_tk_method tk_method = -1;
41 /* Handler for system messages. The only two we handle are
42 KMSG_SYSTEM_INIT and KMSG_SYSTEM_EXIT. */
44 handle_kmsg_system(khm_int32 msg_type,
45 khm_int32 msg_subtype,
48 khm_int32 rv = KHM_ERROR_SUCCESS;
50 switch (msg_subtype) {
52 /* This is the first message that will be received by a
53 plugin. We use it to perform initialization operations
54 such as registering any credential types, data types and
56 case KMSG_SYSTEM_INIT:
58 wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC];
59 wchar_t long_desc[KCDB_MAXCCH_LONG_DESC];
60 #ifdef USE_CONFIGURATION_PANELS
61 khui_config_node_reg creg;
63 afs_msg_announce announce;
65 if (KHM_FAILED(kmq_find_type(AFS_MSG_TYPENAME, &msg_type_afs))) {
66 return KHM_ERROR_UNKNOWN;
69 /* We must first announce our extension plug-in, so that
70 the AFS plug-in will know we exist */
71 announce.cbsize = sizeof(announce);
72 announce.version = AFS_PLUGIN_VERSION;
73 announce.name = MYPLUGIN_NAMEW;
75 kmq_create_subscription(handle_AFS_MSG, &announce.sub);
77 /* Set to TRUE if we are providing a token acquisition
79 announce.provide_token_acq = TRUE;
81 LoadString(hResModule, IDS_TKMETHOD_SHORT_DESC,
82 short_desc, ARRAYLENGTH(short_desc));
84 announce.token_acq.short_desc = short_desc;
86 LoadString(hResModule, IDS_TKMETHOD_LONG_DESC,
87 long_desc, ARRAYLENGTH(long_desc));
89 announce.token_acq.long_desc = long_desc;
91 if (KHM_FAILED(kmq_send_message(msg_type_afs,
92 AFS_MSG_ANNOUNCE, 0, &announce))) {
93 kmq_delete_subscription(announce.sub);
96 return KHM_ERROR_UNKNOWN;
99 tk_method = announce.token_acq.method_id;
101 #ifdef USE_CONFIGURATION_PANELS
103 /* Register our configuration panels. */
105 /* Registering configuration panels is not required for
106 extension plug-in. As such, this bit of code is
107 commented out. However, if you wish to provide a
108 configuration panel, you should uncomment this block
109 and fill in the stub functions in config_main.c */
111 ZeroMemory(&creg, sizeof(creg));
113 short_desc[0] = L'\0';
115 LoadString(hResModule, IDS_CFG_SHORT_DESC,
116 short_desc, ARRAYLENGTH(short_desc));
118 long_desc[0] = L'\0';
120 LoadString(hResModule, IDS_CFG_LONG_DESC,
121 long_desc, ARRAYLENGTH(long_desc));
123 creg.name = CONFIGNODE_MAIN;
124 creg.short_desc = short_desc;
125 creg.long_desc = long_desc;
126 creg.h_module = hResModule;
127 creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG);
128 creg.dlg_proc = config_dlgproc;
131 khui_cfg_register(NULL, &creg);
136 /* This is the last message that will be received by the
138 case KMSG_SYSTEM_EXIT:
140 khui_config_node cnode;
142 /* It should not be assumed that initialization of the
143 plugin went well at this point since we receive a
144 KMSG_SYSTEM_EXIT even if the initialization failed. */
146 /* Now unregister any configuration nodes we registered. */
148 if (KHM_SUCCEEDED(khui_cfg_open(NULL, CONFIGNODE_MAIN, &cnode))) {
149 khui_cfg_remove(cnode);
150 khui_cfg_release(cnode);
153 /* TODO: Perform additional uninitialization
162 /* This is the main message handler for our plugin. All the plugin
163 messages end up here where we either handle it directly or dispatch
164 it to other handlers. */
165 khm_int32 KHMAPI plugin_msg_proc(khm_int32 msg_type,
166 khm_int32 msg_subtype,
172 return handle_kmsg_system(msg_type, msg_subtype, uparam, vparam);
175 if (msg_type == msg_type_afs) {
176 return handle_AFS_MSG(msg_type, msg_subtype, uparam, vparam);
179 return KHM_ERROR_SUCCESS;