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
31 #include<help/afsplhlp.h>
34 /* disable the 'name was marked as deprecated' warnings. These get
35 issued for Str?Cat? and Str?Cpy? functions. We don't use those
38 #pragma warning(disable: 4995)
45 typedef struct tag_afs_ids_dlg_data
{
46 khui_config_init_data cfg
;
48 khm_boolean afs_enabled
;
52 afs_cfg_ids_proc(HWND hwnd
,
57 afs_ids_dlg_data
* d
= NULL
;
64 d
= PMALLOC(sizeof(*d
));
65 ZeroMemory(d
, sizeof(*d
));
68 #pragma warning(disable: 4244)
69 SetWindowLongPtr(hwnd
, DWLP_USER
, (LONG_PTR
) d
);
72 d
->cfg
= *((khui_config_init_data
*) lParam
);
74 khc_read_int32(csp_params
, L
"AFSEnabled", &t
);
78 CheckDlgButton(hwnd
, IDC_CFG_OBTAIN
,
79 (d
->afs_enabled
)? BST_CHECKED
: BST_UNCHECKED
);
85 d
= (afs_ids_dlg_data
*) (LONG_PTR
)
86 GetWindowLongPtr(hwnd
, DWLP_USER
);
90 SetWindowLongPtr(hwnd
, DWLP_USER
, 0);
97 d
= (afs_ids_dlg_data
*) (LONG_PTR
)
98 GetWindowLongPtr(hwnd
, DWLP_USER
);
103 if (wParam
== MAKEWPARAM(IDC_CFG_OBTAIN
, BN_CLICKED
)) {
105 (IsDlgButtonChecked(hwnd
, IDC_CFG_OBTAIN
) ==
107 khui_cfg_set_flags_inst(&d
->cfg
, KHUI_CNFLAG_MODIFIED
,
108 KHUI_CNFLAG_MODIFIED
);
114 case KHUI_WM_CFG_NOTIFY
:
116 d
= (afs_ids_dlg_data
*) (LONG_PTR
)
117 GetWindowLongPtr(hwnd
, DWLP_USER
);
122 if (HIWORD(wParam
) == WMCFG_APPLY
) {
125 if (KHM_FAILED(khc_read_int32(csp_params
,
126 L
"AFSEnabled", &t
)) ||
127 !!t
!= !!d
->afs_enabled
) {
128 khc_write_int32(csp_params
, L
"AFSEnabled",
131 khui_cfg_set_flags_inst(&d
->cfg
,
133 KHUI_CNFLAG_APPLIED
|
134 KHUI_CNFLAG_MODIFIED
);
136 khui_cfg_set_flags_inst(&d
->cfg
,
138 KHUI_CNFLAG_MODIFIED
);
149 afs_cfg_id_proc(HWND hwnd
,
160 wchar_t idname
[KCDB_IDENT_MAXCCH_NAME
];
163 rv
= afs_dlg_proc(hwnd
, uMsg
, wParam
, 0);
165 d
= (afs_dlg_data
*) (LONG_PTR
) GetWindowLongPtr(hwnd
, DWLP_USER
);
172 d
->cfg
= *((khui_config_init_data
*) lParam
);
176 khui_cfg_get_name(d
->cfg
.ctx_node
, idname
, &cb
);
179 kcdb_identity_create(idname
, 0, &d
->ident
);
185 d
->config_dlg
= TRUE
;
187 afs_cred_get_identity_creds(&d
->creds
, d
->ident
, &d
->afs_enabled
);
189 afs_dlg_proc(hwnd
, KHUI_WM_NC_NOTIFY
,
190 MAKEWPARAM(0, WMNC_DIALOG_SETUP
), 0);
194 break; /* not reached */
200 d
= (afs_dlg_data
*) (LONG_PTR
) GetWindowLongPtr(hwnd
, DWLP_USER
);
202 assert(d
&& d
->ident
);
205 kcdb_identity_release(d
->ident
);
208 return afs_dlg_proc(hwnd
, uMsg
, wParam
, lParam
);
210 break; /* not reached */
212 case KHUI_WM_CFG_NOTIFY
:
216 d
= (afs_dlg_data
*) (LONG_PTR
) GetWindowLongPtr(hwnd
, DWLP_USER
);
221 if (HIWORD(wParam
) == WMCFG_APPLY
) {
222 afs_cred_write_ident_data(d
);
228 return afs_dlg_proc(hwnd
, uMsg
, wParam
, lParam
);
233 set_service_status(HWND hwnd
) {
234 static DWORD wait_start
= 0;
238 wchar_t status_strings_csv
[1024];
239 wchar_t status_strings_ms
[1024];
243 GetServiceStatus(NULL
,
245 &status
, &wait_hint
);
247 LoadString(hResModule
, IDS_CFG_SVCSTATUS
,
248 status_strings_csv
, ARRAYLENGTH(status_strings_csv
));
250 cb
= sizeof(status_strings_ms
);
251 csv_to_multi_string(status_strings_ms
, &cb
, status_strings_csv
);
253 for(i
=0, t
= status_strings_ms
; t
&& *t
&& *t
!= L
' ';
254 t
= multi_string_next(t
), i
++) {
260 t
= status_strings_ms
; /* the first one is "unknown". */
262 SetDlgItemText(hwnd
, IDC_CFG_STATUS
, t
);
264 if (status
!= SERVICE_RUNNING
) {
267 hw
= GetDlgItem(hwnd
, IDC_CFG_STOP
);
268 if (hw
== GetFocus())
269 SetFocus(GetNextDlgTabItem(hwnd
, hw
, FALSE
));
271 EnableWindow(hw
, FALSE
);
273 EnableWindow(GetDlgItem(hwnd
, IDC_CFG_STOP
), TRUE
);
276 if (status
!= SERVICE_STOPPED
&&
277 status
!= SERVICE_PAUSED
) {
280 hw
= GetDlgItem(hwnd
, IDC_CFG_START
);
281 if (hw
== GetFocus())
282 SetFocus(GetNextDlgTabItem(hwnd
, hw
, FALSE
));
284 EnableWindow(hw
, FALSE
);
286 EnableWindow(GetDlgItem(hwnd
, IDC_CFG_START
), TRUE
);
289 if (status
== SERVICE_START_PENDING
||
290 status
== SERVICE_STOP_PENDING
) {
295 hw
= GetDlgItem(hwnd
, IDC_CFG_PROGRESS
);
299 if (!IsWindowVisible(hw
))
300 ShowWindow(hw
, SW_SHOW
);
303 wait_start
= GetTickCount();
305 now
= GetTickCount();
307 if (now
+ wait_hint
!= wait_start
)
308 progress
= (now
- wait_start
) * 100 /
309 (now
+ wait_hint
- wait_start
);
313 SendMessage(hw
, PBM_SETPOS
, progress
, 0);
315 SetTimer(hwnd
, 1, 500, NULL
);
319 hw
= GetDlgItem(hwnd
, IDC_CFG_PROGRESS
);
324 if (IsWindowVisible(hw
))
325 ShowWindow(hw
, SW_HIDE
);
330 afs_cfg_show_last_error(HWND hwnd
, wchar_t * prefix
, DWORD code
) {
332 wchar_t * err_desc
= NULL
;
337 r
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
338 FORMAT_MESSAGE_IGNORE_INSERTS
|
339 FORMAT_MESSAGE_FROM_SYSTEM
,
347 if (r
== 0 || err_desc
== NULL
)
350 LoadString(hResModule
, IDS_PLUGIN_DESC
,
351 title
, ARRAYLENGTH(title
));
354 else if (IS_INTRESOURCE(prefix
))
355 LoadString(hResModule
, (UINT
)(UINT_PTR
) prefix
,
356 tmp
, ARRAYLENGTH(tmp
));
358 StringCbCopy(tmp
, sizeof(tmp
), prefix
);
360 StringCbPrintf(msg
, sizeof(msg
), L
"%s%s",
363 MessageBox(hwnd
, msg
, title
, MB_OK
| MB_APPLMODAL
);
368 #define SCNAME_AFSCREDS L"AFS Credentials.lnk"
371 afs_cfg_get_afscreds_shortcut(wchar_t * wpath
) {
373 BOOL shortcut_found
= FALSE
;
375 hr
= SHGetFolderPath(NULL
, CSIDL_COMMON_STARTUP
,
376 NULL
, SHGFP_TYPE_CURRENT
,
381 if (!PathAppend(wpath
, SCNAME_AFSCREDS
)) {
385 if (PathFileExists(wpath
)) {
386 shortcut_found
= TRUE
;
391 return shortcut_found
;
395 afs_cfg_main_proc(HWND hwnd
,
402 wchar_t imagepath
[MAX_PATH
];
403 wchar_t blockname
[MAX_PATH
];
411 struct LANGANDCODEPATH
{
416 #pragma warning(push)
417 #pragma warning(disable: 4244)
418 SetWindowLongPtr(hwnd
, DWLP_USER
, (DWORD_PTR
) lParam
);
421 /* Try to figure out if afscreds.exe is on the startup
422 group for all users. */
424 khm_handle csp_afscred
= NULL
;
425 khm_int32 disable
= FALSE
;
427 if (KHM_SUCCEEDED(kmm_get_plugin_config(AFS_PLUGIN_NAME
,
431 khc_read_int32(csp_afscred
, L
"Disableafscreds",
434 khc_close_space(csp_afscred
);
438 CheckDlgButton(hwnd
, IDC_CFG_STARTAFSCREDS
,
441 CheckDlgButton(hwnd
, IDC_CFG_STARTAFSCREDS
,
446 l
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
447 L
"SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon",
452 if (l
!= ERROR_SUCCESS
)
455 cb
= sizeof(imagepath
);
456 l
= RegQueryValueEx(service_key
,
461 if (l
!= ERROR_SUCCESS
)
464 PathUnquoteSpaces(imagepath
);
467 cb
= GetFileVersionInfoSize(imagepath
, &dummy
);
468 if (cb
== 0 || dummy
)
471 ver_info
= malloc(cb
);
478 if (!GetFileVersionInfo(imagepath
,
483 if (!VerQueryValue(ver_info
,
484 L
"\\VarFileInfo\\Translation",
485 (LPVOID
*) &translations
,
490 StringCbPrintf(blockname
, sizeof(blockname
),
491 L
"\\StringFileInfo\\%04x%04x\\FileVersion",
492 translations
[0].wLanguage
,
493 translations
[0].wCodePage
);
495 if (!VerQueryValue(ver_info
,
502 SetDlgItemText(hwnd
, IDC_CFG_VERSION
, value
);
504 StringCbPrintf(blockname
, sizeof(blockname
),
505 L
"\\StringFileInfo\\%04x%04x\\CompanyName",
506 translations
[0].wLanguage
,
507 translations
[0].wCodePage
);
509 if (!VerQueryValue(ver_info
,
516 SetDlgItemText(hwnd
, IDC_CFG_COMPANY
, value
);
521 RegCloseKey(service_key
);
523 set_service_status(hwnd
);
529 case MAKEWPARAM(IDC_CFG_STOP
, BN_CLICKED
):
533 r
= ServiceControl(NULL
, TRANSARCAFSDAEMON
, SERVICE_STOPPED
);
536 afs_cfg_show_last_error(hwnd
,
537 MAKEINTRESOURCE(IDS_CFG_CANTSTOP
),
540 set_service_status(hwnd
);
544 case MAKEWPARAM(IDC_CFG_START
,BN_CLICKED
):
547 r
= ServiceControl(NULL
, TRANSARCAFSDAEMON
, SERVICE_RUNNING
);
550 afs_cfg_show_last_error(hwnd
,
551 MAKEINTRESOURCE(IDS_CFG_CANTSTART
),
554 set_service_status(hwnd
);
558 case MAKEWPARAM(IDC_CFG_CPL
, BN_CLICKED
):
559 if (32 >= (LRESULT
) ShellExecute (NULL
, NULL
,
560 L
"AFS_CONFIG.EXE", NULL
,
563 L
"Can't find file AFS_CONFIG.EXE",
568 case MAKEWPARAM(IDC_CFG_STARTAFSCREDS
, BN_CLICKED
):
570 khui_config_node node
;
572 node
= (khui_config_node
) (DWORD_PTR
)
573 GetWindowLongPtr(hwnd
, DWLP_USER
);
576 khui_cfg_set_flags(node
,
577 KHUI_CNFLAG_MODIFIED
,
578 KHUI_CNFLAG_MODIFIED
);
585 case KHUI_WM_CFG_NOTIFY
:
587 if (HIWORD(wParam
) == WMCFG_APPLY
) {
588 wchar_t wpath
[MAX_PATH
];
590 khui_config_node node
;
591 khm_handle csp_afscred
= NULL
;
592 khm_int32 disable
= FALSE
;
594 node
= (khui_config_node
) (DWORD_PTR
)
595 GetWindowLongPtr(hwnd
, DWLP_USER
);
598 assert(node
!= NULL
);
603 kmm_get_plugin_config(AFS_PLUGIN_NAME
, KHM_PERM_WRITE
,
607 khc_read_int32(csp_afscred
, L
"Disableafscreds",
610 dlg_state
= IsDlgButtonChecked(hwnd
, IDC_CFG_STARTAFSCREDS
);
613 (dlg_state
== BST_CHECKED
)) {
615 khc_write_int32(csp_afscred
,
617 (dlg_state
== BST_CHECKED
));
619 khui_cfg_set_flags(node
,
621 KHUI_CNFLAG_MODIFIED
|
622 KHUI_CNFLAG_APPLIED
);
624 khui_cfg_set_flags(node
, 0,
625 KHUI_CNFLAG_MODIFIED
);
628 if (dlg_state
== BST_CHECKED
&&
629 afs_cfg_get_afscreds_shortcut(wpath
)) {
640 set_service_status(hwnd
);
649 static const DWORD ctx_help
[] = {
650 IDC_CFG_STATUS
, IDH_SVCSTATUS
,
651 IDC_CFG_STOP
, IDH_SVCSTOP
,
652 IDC_CFG_START
, IDH_SVCSTART
,
653 IDC_CFG_VERSION
, IDH_SVCVERSION
,
654 IDC_CFG_COMPANY
, IDH_SVCCOMPANY
,
655 IDC_CFG_CPL
, IDH_SVCCPL
,
656 IDC_CFG_STARTAFSCREDS
, IDH_STARTAFSCREDS
,
662 hlp
= (LPHELPINFO
) lParam
;
664 if (hlp
->iContextType
!= HELPINFO_WINDOW
)
667 afs_html_help(hlp
->hItemHandle
, L
"::/popups_cfg.txt",
668 HH_TP_HELP_WM_HELP
, (DWORD_PTR
) ctx_help
);