[30852] | 1 | /* $Id: Dialog.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[30852] | 3 | * VBoxGINA - Windows Logon DLL for VirtualBox, Dialog Code.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[1] | 26 | */
|
---|
| 27 |
|
---|
[95891] | 28 |
|
---|
[95874] | 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[62679] | 32 | #include <iprt/win/windows.h>
|
---|
[36258] | 33 |
|
---|
[50323] | 34 | #include <VBox/VBoxGuestLib.h>
|
---|
[76474] | 35 | #include <iprt/errcore.h>
|
---|
[95874] | 36 | #include <iprt/utf16.h>
|
---|
[40214] | 37 |
|
---|
[1] | 38 | #include "Dialog.h"
|
---|
| 39 | #include "WinWlx.h"
|
---|
| 40 | #include "Helper.h"
|
---|
| 41 | #include "VBoxGINA.h"
|
---|
| 42 |
|
---|
[36258] | 43 |
|
---|
[95874] | 44 | /*********************************************************************************************************************************
|
---|
| 45 | * Defined Constants And Macros *
|
---|
| 46 | *********************************************************************************************************************************/
|
---|
[36258] | 47 | /*
|
---|
| 48 | * Dialog IDs for legacy Windows OSes (e.g. NT 4.0).
|
---|
| 49 | */
|
---|
[1] | 50 | #define IDD_WLXDIAPLAYSASNOTICE_DIALOG 1400
|
---|
| 51 | #define IDD_WLXLOGGEDOUTSAS_DIALOG 1450
|
---|
[36258] | 52 | /** Change password dialog: To change the current
|
---|
| 53 | * account password. */
|
---|
[1] | 54 | #define IDD_CHANGE_PASSWORD_DIALOG 1550
|
---|
| 55 | #define IDD_WLXLOGGEDONSAS_DIALOG 1650
|
---|
[36258] | 56 | /** Security dialog: To lock the workstation, log off
|
---|
| 57 | * change password, ... */
|
---|
| 58 | #define IDD_SECURITY_DIALOG 1800
|
---|
| 59 | /** Locked dialog: To unlock the currently lockted
|
---|
| 60 | * workstation. */
|
---|
[1] | 61 | #define IDD_WLXWKSTALOCKEDSAS_DIALOG 1850
|
---|
[36258] | 62 | /** Shutdown dialog: To either restart, logoff current
|
---|
| 63 | * user or shutdown the workstation. */
|
---|
| 64 | #define IDD_SHUTDOWN_DIALOG 2200
|
---|
| 65 | /** Logoff dialog: "Do you really want to logoff?". */
|
---|
| 66 | #define IDD_LOGOFF_DIALOG 2250
|
---|
[1] | 67 |
|
---|
[36258] | 68 |
|
---|
| 69 | /*
|
---|
| 70 | * Dialog IDs for Windows 2000 and up.
|
---|
| 71 | */
|
---|
| 72 | #define IDD_WLXLOGGEDOUTSAS_DIALOG2 1500
|
---|
| 73 | /** Change password dialog: To change the current
|
---|
| 74 | * account password. */
|
---|
| 75 | #define IDD_CHANGE_PASSWORD_DIALOG2 1700
|
---|
| 76 | /** Locked dialog: To unlock the currently lockted
|
---|
| 77 | * workstation. */
|
---|
| 78 | #define IDD_WLXWKSTALOCKEDSAS_DIALOG2 1950
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | /*
|
---|
| 82 | * Control IDs.
|
---|
| 83 | */
|
---|
[1] | 84 | #define IDC_WLXLOGGEDOUTSAS_USERNAME 1453
|
---|
[5387] | 85 | #define IDC_WLXLOGGEDOUTSAS_USERNAME2 1502
|
---|
[1] | 86 | #define IDC_WLXLOGGEDOUTSAS_PASSWORD 1454
|
---|
[5387] | 87 | #define IDC_WLXLOGGEDOUTSAS_PASSWORD2 1503
|
---|
[1] | 88 | #define IDC_WLXLOGGEDOUTSAS_DOMAIN 1455
|
---|
[5387] | 89 | #define IDC_WLXLOGGEDOUTSAS_DOMAIN2 1504
|
---|
[1] | 90 |
|
---|
[36258] | 91 | #define IDC_WKSTALOCKED_USERNAME 1953
|
---|
| 92 | #define IDC_WKSTALOCKED_PASSWORD 1954
|
---|
| 93 | #define IDC_WKSTALOCKEd_DOMAIN 1856
|
---|
| 94 | #define IDC_WKSTALOCKED_DOMAIN2 1956
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | /*
|
---|
| 98 | * Own IDs.
|
---|
| 99 | */
|
---|
| 100 | #define IDT_BASE WM_USER + 1100 /* Timer ID base. */
|
---|
| 101 | #define IDT_LOGGEDONDLG_POLL IDT_BASE + 1
|
---|
| 102 | #define IDT_LOCKEDDLG_POLL IDT_BASE + 2
|
---|
| 103 |
|
---|
[95874] | 104 |
|
---|
| 105 | /*********************************************************************************************************************************
|
---|
| 106 | * Global Variables *
|
---|
| 107 | *********************************************************************************************************************************/
|
---|
[30852] | 108 | static DLGPROC g_pfnWlxLoggedOutSASDlgProc = NULL;
|
---|
[36258] | 109 | static DLGPROC g_pfnWlxLockedSASDlgProc = NULL;
|
---|
[1] | 110 |
|
---|
[30852] | 111 | static PWLX_DIALOG_BOX_PARAM g_pfnWlxDialogBoxParam = NULL;
|
---|
[1] | 112 |
|
---|
[95874] | 113 |
|
---|
| 114 | /*********************************************************************************************************************************
|
---|
| 115 | * Internal Functions *
|
---|
| 116 | *********************************************************************************************************************************/
|
---|
[1] | 117 | int WINAPI MyWlxDialogBoxParam (HANDLE, HANDLE, LPWSTR, HWND, DLGPROC, LPARAM);
|
---|
| 118 |
|
---|
[95874] | 119 |
|
---|
[1] | 120 | void hookDialogBoxes(PVOID pWinlogonFunctions, DWORD dwWlxVersion)
|
---|
| 121 | {
|
---|
[40214] | 122 | if (!pWinlogonFunctions) /* Needed for testcase. */
|
---|
| 123 | return;
|
---|
[1] | 124 |
|
---|
[40214] | 125 | VBoxGINAVerbose(0, "VBoxGINA::hookDialogBoxes\n");
|
---|
| 126 |
|
---|
[1] | 127 | /* this is version dependent */
|
---|
| 128 | switch (dwWlxVersion)
|
---|
| 129 | {
|
---|
| 130 | case WLX_VERSION_1_0:
|
---|
| 131 | {
|
---|
[30852] | 132 | g_pfnWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_0)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
[1] | 133 | ((PWLX_DISPATCH_VERSION_1_0)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
| 134 | break;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | case WLX_VERSION_1_1:
|
---|
| 138 | {
|
---|
[30852] | 139 | g_pfnWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
[1] | 140 | ((PWLX_DISPATCH_VERSION_1_1)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
| 141 | break;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | case WLX_VERSION_1_2:
|
---|
| 145 | {
|
---|
[30852] | 146 | g_pfnWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_2)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
[1] | 147 | ((PWLX_DISPATCH_VERSION_1_2)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
| 148 | break;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | case WLX_VERSION_1_3:
|
---|
| 152 | {
|
---|
[30852] | 153 | g_pfnWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
[1] | 154 | ((PWLX_DISPATCH_VERSION_1_3)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
| 155 | break;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | case WLX_VERSION_1_4:
|
---|
| 159 | {
|
---|
[30852] | 160 | g_pfnWlxDialogBoxParam = ((PWLX_DISPATCH_VERSION_1_4)pWinlogonFunctions)->WlxDialogBoxParam;
|
---|
[1] | 161 | ((PWLX_DISPATCH_VERSION_1_4)pWinlogonFunctions)->WlxDialogBoxParam = MyWlxDialogBoxParam;
|
---|
| 162 | break;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | default:
|
---|
| 166 | {
|
---|
[40214] | 167 | VBoxGINAVerbose(0, "VBoxGINA::hookDialogBoxes: unrecognized version '%d', nothing hooked!\n", dwWlxVersion);
|
---|
[1] | 168 | /* not good, don't do anything */
|
---|
| 169 | break;
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[40214] | 174 | /**
|
---|
| 175 | * Enters credentials into the given text fields.
|
---|
| 176 | *
|
---|
| 177 | * @return IPRT status code.
|
---|
| 178 | * @param hwndDlg Handle of dialog to enter credentials into.
|
---|
| 179 | * @param hwndUserId Handle of username text field. Optional.
|
---|
| 180 | * @param hwndPassword Handle of password text field. Optional.
|
---|
| 181 | * @param hwndDomain Handle of domain text field. Optional.
|
---|
| 182 | * @param pwszUser Username to enter into username text field.
|
---|
| 183 | * @param pwszPassword Password to enter into password text field.
|
---|
| 184 | * @param pwszDomain Domain to enter into domain text field.
|
---|
| 185 | */
|
---|
| 186 | int credentialsToUI(HWND hwndDlg,
|
---|
| 187 | HWND hwndUserId, HWND hwndPassword, HWND hwndDomain,
|
---|
| 188 | PCRTUTF16 pwszUser, PCRTUTF16 pwszPassword, PCRTUTF16 pwszDomain)
|
---|
[25864] | 189 | {
|
---|
[63093] | 190 | RT_NOREF(hwndDlg);
|
---|
[25864] | 191 | BOOL bIsFQDN = FALSE;
|
---|
| 192 | wchar_t szUserFQDN[512]; /* VMMDEV_CREDENTIALS_STRLEN + 255 bytes max. for FQDN */
|
---|
| 193 | if (hwndDomain)
|
---|
| 194 | {
|
---|
| 195 | /* search the domain combo box for our required domain and select it */
|
---|
[40214] | 196 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Trying to find domain entry in combo box ...\n");
|
---|
[25864] | 197 | DWORD dwIndex = (DWORD) SendMessage(hwndDomain, CB_FINDSTRING,
|
---|
[40214] | 198 | 0, (LPARAM)pwszDomain);
|
---|
[25864] | 199 | if (dwIndex != CB_ERR)
|
---|
| 200 | {
|
---|
[40214] | 201 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Found domain at combo box pos %ld\n", dwIndex);
|
---|
[25864] | 202 | SendMessage(hwndDomain, CB_SETCURSEL, (WPARAM) dwIndex, 0);
|
---|
| 203 | EnableWindow(hwndDomain, FALSE);
|
---|
| 204 | }
|
---|
[25874] | 205 | else
|
---|
[25864] | 206 | {
|
---|
[40214] | 207 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain not found in combo box ...\n");
|
---|
[25864] | 208 |
|
---|
| 209 | /* If the domain value has a dot (.) in it, it is a FQDN (Fully Qualified Domain Name)
|
---|
| 210 | * which will not work with the combo box selection because Windows only keeps the
|
---|
| 211 | * NETBIOS names to the left most part of the domain name there. Of course a FQDN
|
---|
| 212 | * then will not be found by the search in the block above.
|
---|
| 213 | *
|
---|
| 214 | * To solve this problem the FQDN domain value will be appended at the user name value
|
---|
| 215 | * (Kerberos style) using an "@", e.g. "<user-name>@full.qualified.domain".
|
---|
| 216 | *
|
---|
| 217 | */
|
---|
[95874] | 218 | size_t l = RTUtf16Len(pwszDomain);
|
---|
[25864] | 219 | if (l > 255)
|
---|
[40214] | 220 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Warning! FQDN (domain) is too long (max 255 bytes), will be truncated!\n");
|
---|
[25864] | 221 |
|
---|
[95874] | 222 | if (*pwszUser) /* We need a user name that we can use in caes of a FQDN */
|
---|
[25864] | 223 | {
|
---|
[25874] | 224 | if (l > 16) /* Domain name is longer than 16 chars, cannot be a NetBIOS name anymore */
|
---|
| 225 | {
|
---|
[40214] | 226 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain seems to be a FQDN (length)!\n");
|
---|
[25874] | 227 | bIsFQDN = TRUE;
|
---|
| 228 | }
|
---|
| 229 | else if ( l > 0
|
---|
[95874] | 230 | && RTUtf16Chr(pwszDomain, L'.') != NULL) /* if we found a dot (.) in the domain name, this has to be a FQDN */
|
---|
[25874] | 231 | {
|
---|
[40214] | 232 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain seems to be a FQDN (dot)!\n");
|
---|
[25874] | 233 | bIsFQDN = TRUE;
|
---|
| 234 | }
|
---|
[26493] | 235 |
|
---|
[25874] | 236 | if (bIsFQDN)
|
---|
| 237 | {
|
---|
[95874] | 238 | RTUtf16Printf(szUserFQDN, sizeof(szUserFQDN) / sizeof(wchar_t), "%ls@%ls", pwszUser, pwszDomain);
|
---|
[40214] | 239 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: FQDN user name is now: %s!\n", szUserFQDN);
|
---|
[25874] | 240 | }
|
---|
[25864] | 241 | }
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 | if (hwndUserId)
|
---|
| 245 | {
|
---|
| 246 | if (!bIsFQDN)
|
---|
[40214] | 247 | SendMessage(hwndUserId, WM_SETTEXT, 0, (LPARAM)pwszUser);
|
---|
[25864] | 248 | else
|
---|
[25874] | 249 | SendMessage(hwndUserId, WM_SETTEXT, 0, (LPARAM)szUserFQDN);
|
---|
[25864] | 250 | }
|
---|
| 251 | if (hwndPassword)
|
---|
[40214] | 252 | SendMessage(hwndPassword, WM_SETTEXT, 0, (LPARAM)pwszPassword);
|
---|
[25864] | 253 |
|
---|
[40214] | 254 | return VINF_SUCCESS; /** @todo */
|
---|
[25864] | 255 | }
|
---|
| 256 |
|
---|
[40214] | 257 | /**
|
---|
| 258 | * Tries to retrieve credentials and enters them into the specified windows,
|
---|
| 259 | * optionally followed by a button press to confirm/abort the dialog.
|
---|
| 260 | *
|
---|
| 261 | * @return IPRT status code.
|
---|
| 262 | * @param hwndDlg Handle of dialog to enter credentials into.
|
---|
| 263 | * @param hwndUserId Handle of username text field. Optional.
|
---|
| 264 | * @param hwndPassword Handle of password text field. Optional.
|
---|
| 265 | * @param hwndDomain Handle of domain text field. Optional.
|
---|
| 266 | * @param wButtonToPress Button ID of dialog to press after successful
|
---|
| 267 | * retrieval + storage. If set to 0 no button will
|
---|
| 268 | * be pressed.
|
---|
| 269 | */
|
---|
| 270 | int credentialsHandle(HWND hwndDlg,
|
---|
| 271 | HWND hwndUserId, HWND hwndPassword, HWND hwndDomain,
|
---|
| 272 | WORD wButtonToPress)
|
---|
| 273 | {
|
---|
| 274 | int rc = VINF_SUCCESS;
|
---|
| 275 |
|
---|
| 276 | if (!VBoxGINAHandleCurrentSession())
|
---|
| 277 | rc = VERR_NOT_FOUND;
|
---|
| 278 |
|
---|
| 279 | if (RT_SUCCESS(rc))
|
---|
| 280 | {
|
---|
| 281 | rc = VbglR3CredentialsQueryAvailability();
|
---|
| 282 | if (RT_FAILURE(rc))
|
---|
| 283 | {
|
---|
| 284 | if (rc != VERR_NOT_FOUND)
|
---|
| 285 | VBoxGINAVerbose(0, "VBoxGINA::credentialsHandle: error querying for credentials, rc=%Rrc\n", rc);
|
---|
| 286 | }
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | if (RT_SUCCESS(rc))
|
---|
| 290 | {
|
---|
| 291 | VBoxGINAVerbose(0, "VBoxGINA::credentialsHandle: credentials available\n");
|
---|
| 292 |
|
---|
| 293 | /*
|
---|
| 294 | * Set status to "terminating" to let the host know this module now
|
---|
| 295 | * tries to receive and use passed credentials so that credentials from
|
---|
| 296 | * the host won't be sent twice.
|
---|
| 297 | */
|
---|
| 298 | VBoxGINAReportStatus(VBoxGuestFacilityStatus_Terminating);
|
---|
| 299 |
|
---|
| 300 | PRTUTF16 pwszUser, pwszPassword, pwszDomain;
|
---|
| 301 | rc = VbglR3CredentialsRetrieveUtf16(&pwszUser, &pwszPassword, &pwszDomain);
|
---|
| 302 | if (RT_SUCCESS(rc))
|
---|
| 303 | {
|
---|
[40947] | 304 | #ifdef DEBUG
|
---|
[40214] | 305 | VBoxGINAVerbose(0, "VBoxGINA::credentialsHandle: retrieved credentials: user=%ls, password=%ls, domain=%ls\n",
|
---|
| 306 | pwszUser, pwszPassword, pwszDomain);
|
---|
[40947] | 307 | #else
|
---|
[40214] | 308 | VBoxGINAVerbose(0, "VBoxGINA::credentialsHandle: retrieved credentials: user=%ls, password=XXX, domain=%ls\n",
|
---|
| 309 | pwszUser, pwszDomain);
|
---|
[40947] | 310 | #endif
|
---|
[40214] | 311 | /* Fill in credentials to appropriate UI elements. */
|
---|
| 312 | rc = credentialsToUI(hwndDlg,
|
---|
| 313 | hwndUserId, hwndPassword, hwndDomain,
|
---|
| 314 | pwszUser, pwszPassword, pwszDomain);
|
---|
| 315 | if (RT_SUCCESS(rc))
|
---|
| 316 | {
|
---|
| 317 | /* Confirm/cancel the dialog by pressing the appropriate button. */
|
---|
| 318 | if (wButtonToPress)
|
---|
| 319 | {
|
---|
| 320 | WPARAM wParam = MAKEWPARAM(wButtonToPress, BN_CLICKED);
|
---|
| 321 | PostMessage(hwndDlg, WM_COMMAND, wParam, 0);
|
---|
| 322 | }
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | VbglR3CredentialsDestroyUtf16(pwszUser, pwszPassword, pwszDomain,
|
---|
| 326 | 3 /* Passes */);
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 |
|
---|
[40947] | 330 | #ifdef DEBUG
|
---|
[40214] | 331 | VBoxGINAVerbose(3, "VBoxGINA::credentialsHandle: returned with rc=%Rrc\n", rc);
|
---|
[40947] | 332 | #endif
|
---|
[40214] | 333 | return rc;
|
---|
| 334 | }
|
---|
| 335 |
|
---|
[9680] | 336 | INT_PTR CALLBACK MyWlxLoggedOutSASDlgProc(HWND hwndDlg, // handle to dialog box
|
---|
| 337 | UINT uMsg, // message
|
---|
| 338 | WPARAM wParam, // first message parameter
|
---|
| 339 | LPARAM lParam) // second message parameter
|
---|
[1] | 340 | {
|
---|
| 341 | BOOL bResult;
|
---|
[36258] | 342 | static HWND s_hwndUserId, s_hwndPassword, s_hwndDomain = 0;
|
---|
[1] | 343 |
|
---|
[40214] | 344 | /*VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc\n");*/
|
---|
[1] | 345 |
|
---|
| 346 | //
|
---|
| 347 | // Pass on to MSGINA first.
|
---|
| 348 | //
|
---|
[30852] | 349 | bResult = g_pfnWlxLoggedOutSASDlgProc(hwndDlg, uMsg, wParam, lParam);
|
---|
[1] | 350 |
|
---|
| 351 | //
|
---|
| 352 | // We are only interested in the WM_INITDIALOG message.
|
---|
| 353 | //
|
---|
| 354 | switch (uMsg)
|
---|
| 355 | {
|
---|
| 356 | case WM_INITDIALOG:
|
---|
| 357 | {
|
---|
[40214] | 358 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: got WM_INITDIALOG\n");
|
---|
[1] | 359 |
|
---|
| 360 | /* get the entry fields */
|
---|
[36258] | 361 | s_hwndUserId = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_USERNAME);
|
---|
| 362 | if (!s_hwndUserId)
|
---|
| 363 | s_hwndUserId = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_USERNAME2);
|
---|
| 364 | s_hwndPassword = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_PASSWORD);
|
---|
| 365 | if (!s_hwndPassword)
|
---|
| 366 | s_hwndPassword = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_PASSWORD2);
|
---|
| 367 | s_hwndDomain = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_DOMAIN);
|
---|
| 368 | if (!s_hwndDomain)
|
---|
| 369 | s_hwndDomain = GetDlgItem(hwndDlg, IDC_WLXLOGGEDOUTSAS_DOMAIN2);
|
---|
[1] | 370 |
|
---|
[40214] | 371 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: hwndUserId: %x, hwndPassword: %d, hwndDomain: %d\n",
|
---|
| 372 | s_hwndUserId, s_hwndPassword, s_hwndDomain);
|
---|
[1] | 373 |
|
---|
| 374 | /* terminate the credentials poller thread, it's done is job */
|
---|
[40214] | 375 | VBoxGINACredentialsPollerTerminate();
|
---|
[1] | 376 |
|
---|
[40214] | 377 | int rc = credentialsHandle(hwndDlg,
|
---|
| 378 | s_hwndUserId, s_hwndPassword, s_hwndDomain,
|
---|
| 379 | IDOK /* Button */);
|
---|
| 380 | if (RT_FAILURE(rc))
|
---|
[1] | 381 | {
|
---|
| 382 | /*
|
---|
| 383 | * The dialog is there but we don't have any credentials.
|
---|
| 384 | * Create a timer and poll for them.
|
---|
| 385 | */
|
---|
[36258] | 386 | UINT_PTR uTimer = SetTimer(hwndDlg, IDT_LOGGEDONDLG_POLL, 200, NULL);
|
---|
| 387 | if (!uTimer)
|
---|
[40214] | 388 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: failed creating timer! Last error: %ld\n",
|
---|
| 389 | GetLastError());
|
---|
[36258] | 390 | }
|
---|
| 391 | break;
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 | case WM_TIMER:
|
---|
| 395 | {
|
---|
| 396 | /* is it our credentials poller timer? */
|
---|
| 397 | if (wParam == IDT_LOGGEDONDLG_POLL)
|
---|
| 398 | {
|
---|
[40214] | 399 | int rc = credentialsHandle(hwndDlg,
|
---|
| 400 | s_hwndUserId, s_hwndPassword, s_hwndDomain,
|
---|
| 401 | IDOK /* Button */);
|
---|
| 402 | if (RT_SUCCESS(rc))
|
---|
[1] | 403 | {
|
---|
[40214] | 404 | /* we don't need the timer any longer */
|
---|
| 405 | KillTimer(hwndDlg, IDT_LOGGEDONDLG_POLL);
|
---|
[1] | 406 | }
|
---|
| 407 | }
|
---|
| 408 | break;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
[36258] | 411 | case WM_DESTROY:
|
---|
| 412 | KillTimer(hwndDlg, IDT_LOGGEDONDLG_POLL);
|
---|
| 413 | break;
|
---|
| 414 | }
|
---|
| 415 | return bResult;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 |
|
---|
| 419 | INT_PTR CALLBACK MyWlxLockedSASDlgProc(HWND hwndDlg, // handle to dialog box
|
---|
| 420 | UINT uMsg, // message
|
---|
| 421 | WPARAM wParam, // first message parameter
|
---|
| 422 | LPARAM lParam) // second message parameter
|
---|
| 423 | {
|
---|
| 424 | BOOL bResult;
|
---|
| 425 | static HWND s_hwndPassword = 0;
|
---|
| 426 |
|
---|
[40214] | 427 | /*VBoxGINAVerbose(0, "VBoxGINA::MyWlxLockedSASDlgProc\n");*/
|
---|
[36258] | 428 |
|
---|
| 429 | //
|
---|
| 430 | // Pass on to MSGINA first.
|
---|
| 431 | //
|
---|
| 432 | bResult = g_pfnWlxLockedSASDlgProc(hwndDlg, uMsg, wParam, lParam);
|
---|
| 433 |
|
---|
| 434 | //
|
---|
| 435 | // We are only interested in the WM_INITDIALOG message.
|
---|
| 436 | //
|
---|
| 437 | switch (uMsg)
|
---|
| 438 | {
|
---|
| 439 | case WM_INITDIALOG:
|
---|
| 440 | {
|
---|
[40214] | 441 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLockedSASDlgProc: WM_INITDIALOG\n");
|
---|
[36258] | 442 |
|
---|
| 443 | /* get the entry fields */
|
---|
| 444 | s_hwndPassword = GetDlgItem(hwndDlg, IDC_WKSTALOCKED_PASSWORD);
|
---|
[40214] | 445 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLockedSASDlgProc: hwndPassword: %d\n", s_hwndPassword);
|
---|
[36258] | 446 |
|
---|
| 447 | /* terminate the credentials poller thread, it's done is job */
|
---|
[40214] | 448 | VBoxGINACredentialsPollerTerminate();
|
---|
[36258] | 449 |
|
---|
[40214] | 450 | int rc = credentialsHandle(hwndDlg,
|
---|
| 451 | NULL /* Username */, s_hwndPassword, NULL /* Domain */,
|
---|
| 452 | IDOK /* Button */);
|
---|
| 453 | if (RT_FAILURE(rc))
|
---|
[36258] | 454 | {
|
---|
| 455 | /*
|
---|
| 456 | * The dialog is there but we don't have any credentials.
|
---|
| 457 | * Create a timer and poll for them.
|
---|
| 458 | */
|
---|
| 459 | UINT_PTR uTimer = SetTimer(hwndDlg, IDT_LOCKEDDLG_POLL, 200, NULL);
|
---|
| 460 | if (!uTimer)
|
---|
[40214] | 461 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLockedSASDlgProc: failed creating timer! Last error: %ld\n",
|
---|
| 462 | GetLastError());
|
---|
[36258] | 463 | }
|
---|
| 464 | break;
|
---|
| 465 | }
|
---|
| 466 |
|
---|
[1] | 467 | case WM_TIMER:
|
---|
| 468 | {
|
---|
| 469 | /* is it our credentials poller timer? */
|
---|
[36258] | 470 | if (wParam == IDT_LOCKEDDLG_POLL)
|
---|
[1] | 471 | {
|
---|
[40214] | 472 | int rc = credentialsHandle(hwndDlg,
|
---|
| 473 | NULL /* Username */, s_hwndPassword, NULL /* Domain */,
|
---|
| 474 | IDOK /* Button */);
|
---|
| 475 | if (RT_SUCCESS(rc))
|
---|
[1] | 476 | {
|
---|
[40214] | 477 | /* we don't need the timer any longer */
|
---|
| 478 | KillTimer(hwndDlg, IDT_LOCKEDDLG_POLL);
|
---|
[1] | 479 | }
|
---|
| 480 | }
|
---|
| 481 | break;
|
---|
| 482 | }
|
---|
[36258] | 483 |
|
---|
| 484 | case WM_DESTROY:
|
---|
[40214] | 485 | {
|
---|
| 486 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxLockedSASDlgProc: WM_DESTROY\n");
|
---|
| 487 |
|
---|
| 488 | /* Because this is the only point where we know within our module that the locked
|
---|
| 489 | * dialog has been closed by a valid unlock password we have to set the appropriate
|
---|
| 490 | * facility status here. */
|
---|
| 491 | VBoxGINAReportStatus(VBoxGuestFacilityStatus_Terminated);
|
---|
| 492 |
|
---|
[36258] | 493 | KillTimer(hwndDlg, IDT_LOCKEDDLG_POLL);
|
---|
| 494 | break;
|
---|
[40214] | 495 | }
|
---|
[1] | 496 | }
|
---|
| 497 | return bResult;
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 |
|
---|
| 501 | int WINAPI MyWlxDialogBoxParam(HANDLE hWlx,
|
---|
| 502 | HANDLE hInst,
|
---|
[63093] | 503 | LPWSTR pszTemplate,
|
---|
[1] | 504 | HWND hwndOwner,
|
---|
| 505 | DLGPROC dlgprc,
|
---|
| 506 | LPARAM dwInitParam)
|
---|
| 507 | {
|
---|
[63093] | 508 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: pszTemplate=%ls\n", pszTemplate);
|
---|
[1] | 509 |
|
---|
[40214] | 510 | VBoxGINAReportStatus(VBoxGuestFacilityStatus_Active);
|
---|
| 511 |
|
---|
[36258] | 512 | //
|
---|
| 513 | // We only know MSGINA dialogs by identifiers.
|
---|
| 514 | //
|
---|
[63093] | 515 | if (((uintptr_t)pszTemplate >> 16) == 0)
|
---|
[36258] | 516 | {
|
---|
| 517 | //
|
---|
| 518 | // Hook appropriate dialog boxes as necessary.
|
---|
| 519 | //
|
---|
[63093] | 520 | switch ((DWORD)(uintptr_t)pszTemplate)
|
---|
[36258] | 521 | {
|
---|
[40214] | 522 | case IDD_WLXDIAPLAYSASNOTICE_DIALOG:
|
---|
| 523 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: SAS notice dialog displayed; not handled\n");
|
---|
| 524 | break;
|
---|
| 525 |
|
---|
[36258] | 526 | case IDD_WLXLOGGEDOUTSAS_DIALOG: /* Windows NT 4.0. */
|
---|
| 527 | case IDD_WLXLOGGEDOUTSAS_DIALOG2: /* Windows 2000 and up. */
|
---|
| 528 | {
|
---|
[40214] | 529 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: returning hooked SAS logged out dialog\n");
|
---|
[36258] | 530 | g_pfnWlxLoggedOutSASDlgProc = dlgprc;
|
---|
[63093] | 531 | return g_pfnWlxDialogBoxParam(hWlx, hInst, pszTemplate, hwndOwner,
|
---|
[36258] | 532 | MyWlxLoggedOutSASDlgProc, dwInitParam);
|
---|
| 533 | }
|
---|
[1] | 534 |
|
---|
[40214] | 535 | case IDD_SECURITY_DIALOG:
|
---|
| 536 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: Security dialog displayed; not handled\n");
|
---|
| 537 | break;
|
---|
| 538 |
|
---|
[36258] | 539 | case IDD_WLXWKSTALOCKEDSAS_DIALOG: /* Windows NT 4.0. */
|
---|
| 540 | case IDD_WLXWKSTALOCKEDSAS_DIALOG2: /* Windows 2000 and up. */
|
---|
| 541 | {
|
---|
[40214] | 542 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: returning hooked SAS locked dialog\n");
|
---|
[36258] | 543 | g_pfnWlxLockedSASDlgProc = dlgprc;
|
---|
[63093] | 544 | return g_pfnWlxDialogBoxParam(hWlx, hInst, pszTemplate, hwndOwner,
|
---|
[36258] | 545 | MyWlxLockedSASDlgProc, dwInitParam);
|
---|
| 546 | }
|
---|
| 547 |
|
---|
| 548 | /** @todo Add other hooking stuff here. */
|
---|
| 549 |
|
---|
| 550 | default:
|
---|
[63093] | 551 | VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: dialog %p (%u) not handled\n",
|
---|
| 552 | pszTemplate, (DWORD)(uintptr_t)pszTemplate);
|
---|
[36258] | 553 | break;
|
---|
| 554 | }
|
---|
| 555 | }
|
---|
| 556 |
|
---|
[40214] | 557 | /* The rest will be redirected. */
|
---|
[63093] | 558 | return g_pfnWlxDialogBoxParam(hWlx, hInst, pszTemplate, hwndOwner, dlgprc, dwInitParam);
|
---|
[1] | 559 | }
|
---|
[30852] | 560 |
|
---|