Windows: Add a token status icon to the NIM plug-in
[openafs.git] / src / WINNT / netidmgr_plugin / afscred.h
1 /*
2  * Copyright (c) 2005-2008 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 #ifndef __KHIMAIRA_AFSCRED_H
28 #define __KHIMAIRA_AFSCRED_H
29
30 #ifndef _WIN64
31 #define _USE_32BIT_TIME_T 1
32 #endif
33
34 #define _WINSOCKAPI_
35 #include<windows.h>
36 #include<time.h>
37
38 #define KHERR_FACILITY L"AfsCred"
39 #define KHERR_HMODULE hResModule
40 #include<netidmgr.h>
41
42 #include<langres.h>
43
44 #include <afs/stds.h>
45 #include <afs/cm_config.h>
46 #include <afs/auth.h>
47 #include <afs/ptserver.h>
48 #include <afs/ptuser.h>
49
50 #include<afspext.h>
51
52 #include<afsfuncs.h>
53 #include<afsnewcreds.h>
54
55 #ifndef NOSTRSAFE
56 #include<strsafe.h>
57 #endif
58
59 #define AFS_PLUGIN_NAME         L"AfsCred"
60 #define AFS_CREDTYPE_NAME       L"AfsCred"
61
62 #define AFS_PLUGIN_DEPS         L"Krb5Cred\0"
63
64 #define KRB5_CREDTYPE_NAME      L"Krb5Cred"
65 #define KRB4_CREDTYPE_NAME      L"Krb4Cred"
66
67 #define AFS_TYPENAME_PRINCIPAL      L"AFSPrincipal"
68 #define AFS_TYPENAME_METHOD         L"AFSTokenMethod"
69 #define AFS_ATTRNAME_CLIENT_PRINC   L"AFSClientPrinc"
70 #define AFS_ATTRNAME_SERVER_PRINC   L"AFSServerPrinc"
71 #define AFS_ATTRNAME_CELL           L"AFSCell"
72 #define AFS_ATTRNAME_METHOD         L"AFSMethod"
73 #define AFS_ATTRNAME_REALM          L"AFSRealm"
74
75 #define AFS_VALID_CELL_CHARS    L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-"
76 #define AFS_VALID_REALM_CHARS   AFS_VALID_CELL_CHARS
77
78 #define AFS_CONFIG_NODE_IDS     L"AfsIdentities"
79 #define AFS_CONFIG_NODE_ID      L"AfsIdentity"
80 #define AFS_CONFIG_NODE_MAIN    L"AfsOptions"
81
82 #define AFS_HELPFILE            L"afsplhlp.chm"
83
84 /* token acquisition methods provided by extensions begin with this
85    ID */
86 #define AFS_TOKEN_USER          8
87
88 void init_afs();
89 void exit_afs();
90 KHMEXP khm_int32 KHMAPI init_module(kmm_module h_module);
91 KHMEXP khm_int32 KHMAPI exit_module(kmm_module h_module);
92
93 /* globals */
94 extern kmm_module h_khModule;
95 extern HMODULE hResModule;
96 extern HINSTANCE hInstance;
97
98 extern khm_int32 afs_credtype_id;
99 extern khm_int32 krb5_credtype_id;
100 extern khm_int32 krb4_credtype_id;
101 extern khm_int32 afs_msg_type_id;
102 extern khm_handle afs_credset;
103
104 extern khm_int32 afs_type_principal;
105 extern khm_int32 afs_attr_client_princ;
106 extern khm_int32 afs_attr_server_princ;
107 extern khm_int32 afs_attr_cell;
108 extern khm_int32 afs_attr_method;
109 extern khm_int32 afs_attr_realm;
110
111 /* Configuration spaces */
112 #define CSNAME_PLUGINS      L"Plugins"
113 #define CSNAME_AFSCRED      L"AfsCred"
114 #define CSNAME_PARAMS       L"Parameters"
115
116 extern khm_handle csp_plugins;
117 extern khm_handle csp_afscred;
118 extern khm_handle csp_params;
119
120 extern khm_handle afs_sub;
121
122 /* defined in afsconfig.c which is generated from afsconfig.csv */
123 extern kconf_schema schema_afsconfig[];
124
125
126 /* plugin callback procedure */
127 khm_int32 KHMAPI 
128 afs_plugin_cb(khm_int32 msg_type,
129               khm_int32 msg_subtype,
130               khm_ui_4 uparam,
131               void * vparam);
132
133 INT_PTR CALLBACK
134 afs_cfg_ids_proc(HWND hwnd,
135                  UINT uMsg,
136                  WPARAM wParam,
137                  LPARAM lParam);
138
139 INT_PTR CALLBACK
140 afs_cfg_id_proc(HWND hwnd,
141                 UINT uMsg,
142                 WPARAM wParam,
143                 LPARAM lParam);
144
145 INT_PTR CALLBACK
146 afs_cfg_main_proc(HWND hwnd,
147                   UINT uMsg,
148                   WPARAM wParam,
149                   LPARAM lParam);
150
151 HWND
152 afs_html_help(HWND caller,
153               wchar_t * postfix,
154               UINT cmd,
155               DWORD_PTR data);
156
157 /* extensions */
158 typedef afs_msg_announce afs_extension;
159
160 /* not thread safe. only call from the plugin thread */
161 afs_extension *
162 afs_find_extension(const wchar_t * name);
163
164 /* not thread safe. only call from the plugin thread */
165 afs_extension *
166 afs_get_extension(khm_size i);
167
168 /* not thread safe.  only call from the plugin thread */
169 afs_extension *
170 afs_get_next_token_acq(afs_extension * f);
171
172 /* not thread safe.  only call from the plugin thread */
173 khm_boolean
174 afs_is_valid_method_id(afs_tk_method method);
175
176 afs_tk_method
177 afs_get_next_method_id(afs_tk_method method);
178
179 afs_tk_method
180 afs_get_method_id(wchar_t * name);
181
182 khm_boolean
183 afs_get_method_name(afs_tk_method method, wchar_t * buf, khm_size cbbuf);
184
185 afs_extension *
186 afs_get_method_ext(afs_tk_method method);
187
188 khm_boolean
189 afs_method_describe(afs_tk_method method, khm_int32 flags,
190                     wchar_t * wbuf, khm_size cbbuf);
191
192 khm_boolean
193 afs_ext_resolve_token(const wchar_t * cell,
194                       const struct ktc_token * token,
195                       const struct ktc_principal * serverp,
196                       const struct ktc_principal * clientp,
197                       khm_handle * pident,
198                       afs_tk_method * pmethod);
199
200 khm_boolean
201 afs_ext_klog(afs_tk_method method,
202              khm_handle   identity,
203              const char * service,
204              const char * cell,
205              const char * realm,
206              const afs_conf_cell * cell_config,
207              khm_int32    lifetime);
208
209 BOOL
210 afs_cfg_get_afscreds_shortcut(wchar_t * wpath);
211
212 /* Notificaiton icon functions */
213
214 enum notification_icon_state {
215     AFSICON_REPORT_TOKENS,
216     AFSICON_SERVICE_STOPPED,
217     AFSICON_SERVICE_ERROR
218 };
219
220 void
221 afs_icon_set_state(enum notification_icon_state state,
222                    khm_handle credset_with_tokens);
223
224 void
225 afs_remove_icon(void);
226
227
228 /* Compatibility */
229 #if KH_VERSION_API < 7
230
231 #ifdef _WIN64
232 #define NIMDLLNAME L"nidmgr64.dll"
233 #define API_khui_action_lock "khui_action_lock"
234 #define API_khui_action_unlock "khui_action_unlock"
235 #define API_khui_refresh_actions "khui_refresh_actions"
236 #define API_khui_request_UI_callback "khui_request_UI_callback"
237 #else
238 #define NIMDLLNAME L"nidmgr32.dll"
239 #define API_khui_action_lock "_khui_action_lock@0"
240 #define API_khui_action_unlock "_khui_action_unlock@0"
241 #define API_khui_refresh_actions "_khui_refresh_actions@0"
242 #define API_khui_request_UI_callback "_khui_request_UI_callback@8"
243 #endif
244
245 extern void
246 (KHMAPI * pkhui_action_lock)(void);
247
248 extern void
249 (KHMAPI * pkhui_action_unlock)(void);
250
251 extern void
252 (KHMAPI * pkhui_refresh_actions)(void);
253
254 typedef khm_int32
255 (KHMAPI * khm_ui_callback)(HWND hwnd_main_wnd, void * rock);
256
257 extern khm_int32
258 (KHMAPI * pkhui_request_UI_callback)(khm_ui_callback cb,
259                                      void * rock);
260
261 #define khui_action_lock         (*pkhui_action_lock)
262 #define khui_action_unlock       (*pkhui_action_unlock)
263 #define khui_refresh_actions     (*pkhui_refresh_actions)
264 #define khui_request_UI_callback (*pkhui_request_UI_callback)
265
266 #endif
267
268 #endif