/* $Id$ */
/** @file
* VBoxGINA - Windows Logon DLL for VirtualBox, Dialog Code.
*/
/*
*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <windows.h>
#include <stdio.h> /* Needed for swprintf() */
#include <VBox/VBoxGuestLib.h>
#include "Dialog.h"
#include "WinWlx.h"
#include "Helper.h"
#include "VBoxGINA.h"
/*
* Dialog IDs for legacy Windows OSes (e.g. NT 4.0).
*/
/** Change password dialog: To change the current
* account password. */
/** Security dialog: To lock the workstation, log off
* change password, ... */
/** Locked dialog: To unlock the currently lockted
* workstation. */
/** Shutdown dialog: To either restart, logoff current
* user or shutdown the workstation. */
/** Logoff dialog: "Do you really want to logoff?". */
/*
* Dialog IDs for Windows 2000 and up.
*/
/** Change password dialog: To change the current
* account password. */
/** Locked dialog: To unlock the currently lockted
* workstation. */
/*
* Control IDs.
*/
/*
* Own IDs.
*/
{
if (!pWinlogonFunctions) /* Needed for testcase. */
return;
VBoxGINAVerbose(0, "VBoxGINA::hookDialogBoxes\n");
/* this is version dependent */
switch (dwWlxVersion)
{
case WLX_VERSION_1_0:
{
break;
}
case WLX_VERSION_1_1:
{
break;
}
case WLX_VERSION_1_2:
{
break;
}
case WLX_VERSION_1_3:
{
break;
}
case WLX_VERSION_1_4:
{
break;
}
default:
{
VBoxGINAVerbose(0, "VBoxGINA::hookDialogBoxes: unrecognized version '%d', nothing hooked!\n", dwWlxVersion);
/* not good, don't do anything */
break;
}
}
}
/**
* Enters credentials into the given text fields.
*
* @return IPRT status code.
* @param hwndDlg Handle of dialog to enter credentials into.
* @param hwndUserId Handle of username text field. Optional.
* @param hwndPassword Handle of password text field. Optional.
* @param hwndDomain Handle of domain text field. Optional.
* @param pwszUser Username to enter into username text field.
* @param pwszPassword Password to enter into password text field.
* @param pwszDomain Domain to enter into domain text field.
*/
{
if (hwndDomain)
{
/* search the domain combo box for our required domain and select it */
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Trying to find domain entry in combo box ...\n");
0, (LPARAM)pwszDomain);
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Found domain at combo box pos %ld\n", dwIndex);
}
else
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain not found in combo box ...\n");
/* If the domain value has a dot (.) in it, it is a FQDN (Fully Qualified Domain Name)
* which will not work with the combo box selection because Windows only keeps the
* NETBIOS names to the left most part of the domain name there. Of course a FQDN
* then will not be found by the search in the block above.
*
* To solve this problem the FQDN domain value will be appended at the user name value
* (Kerberos style) using an "@", e.g. "<user-name>@full.qualified.domain".
*
*/
if (l > 255)
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Warning! FQDN (domain) is too long (max 255 bytes), will be truncated!\n");
{
if (l > 16) /* Domain name is longer than 16 chars, cannot be a NetBIOS name anymore */
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain seems to be a FQDN (length)!\n");
}
else if ( l > 0
&& wcsstr(pwszDomain, L".") != NULL) /* if we found a dot (.) in the domain name, this has to be a FQDN */
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: Domain seems to be a FQDN (dot)!\n");
}
if (bIsFQDN)
{
}
}
}
}
if (hwndUserId)
{
if (!bIsFQDN)
else
}
if (hwndPassword)
return VINF_SUCCESS; /** @todo */
}
/**
* Tries to retrieve credentials and enters them into the specified windows,
*
* @return IPRT status code.
* @param hwndDlg Handle of dialog to enter credentials into.
* @param hwndUserId Handle of username text field. Optional.
* @param hwndPassword Handle of password text field. Optional.
* @param hwndDomain Handle of domain text field. Optional.
* @param wButtonToPress Button ID of dialog to press after successful
* retrieval + storage. If set to 0 no button will
* be pressed.
*/
{
if (!VBoxGINAHandleCurrentSession())
rc = VERR_NOT_FOUND;
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
{
if (rc != VERR_NOT_FOUND)
}
}
if (RT_SUCCESS(rc))
{
VBoxGINAVerbose(0, "VBoxGINA::credentialsHandle: credentials available\n");
/*
* Set status to "terminating" to let the host know this module now
* tries to receive and use passed credentials so that credentials from
* the host won't be sent twice.
*/
if (RT_SUCCESS(rc))
{
#ifdef DEBUG
VBoxGINAVerbose(0, "VBoxGINA::credentialsHandle: retrieved credentials: user=%ls, password=%ls, domain=%ls\n",
#else
VBoxGINAVerbose(0, "VBoxGINA::credentialsHandle: retrieved credentials: user=%ls, password=XXX, domain=%ls\n",
#endif
/* Fill in credentials to appropriate UI elements. */
if (RT_SUCCESS(rc))
{
if (wButtonToPress)
{
}
}
3 /* Passes */);
}
}
#ifdef DEBUG
#endif
return rc;
}
{
/*VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc\n");*/
//
// Pass on to MSGINA first.
//
//
// We are only interested in the WM_INITDIALOG message.
//
switch (uMsg)
{
case WM_INITDIALOG:
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: got WM_INITDIALOG\n");
/* get the entry fields */
if (!s_hwndUserId)
if (!s_hwndPassword)
if (!s_hwndDomain)
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: hwndUserId: %x, hwndPassword: %d, hwndDomain: %d\n",
/* terminate the credentials poller thread, it's done is job */
IDOK /* Button */);
if (RT_FAILURE(rc))
{
/*
* The dialog is there but we don't have any credentials.
* Create a timer and poll for them.
*/
if (!uTimer)
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLoggedOutSASDlgProc: failed creating timer! Last error: %ld\n",
GetLastError());
}
break;
}
case WM_TIMER:
{
/* is it our credentials poller timer? */
if (wParam == IDT_LOGGEDONDLG_POLL)
{
IDOK /* Button */);
if (RT_SUCCESS(rc))
{
/* we don't need the timer any longer */
}
}
break;
}
case WM_DESTROY:
break;
}
return bResult;
}
{
/*VBoxGINAVerbose(0, "VBoxGINA::MyWlxLockedSASDlgProc\n");*/
//
// Pass on to MSGINA first.
//
//
// We are only interested in the WM_INITDIALOG message.
//
switch (uMsg)
{
case WM_INITDIALOG:
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLockedSASDlgProc: WM_INITDIALOG\n");
/* get the entry fields */
/* terminate the credentials poller thread, it's done is job */
IDOK /* Button */);
if (RT_FAILURE(rc))
{
/*
* The dialog is there but we don't have any credentials.
* Create a timer and poll for them.
*/
if (!uTimer)
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLockedSASDlgProc: failed creating timer! Last error: %ld\n",
GetLastError());
}
break;
}
case WM_TIMER:
{
/* is it our credentials poller timer? */
if (wParam == IDT_LOCKEDDLG_POLL)
{
IDOK /* Button */);
if (RT_SUCCESS(rc))
{
/* we don't need the timer any longer */
}
}
break;
}
case WM_DESTROY:
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxLockedSASDlgProc: WM_DESTROY\n");
/* Because this is the only point where we know within our module that the locked
* dialog has been closed by a valid unlock password we have to set the appropriate
* facility status here. */
break;
}
}
return bResult;
}
{
//
// We only know MSGINA dialogs by identifiers.
//
if (!HIWORD((int)(void*)lpszTemplate))
{
//
// Hook appropriate dialog boxes as necessary.
//
switch ((DWORD) lpszTemplate)
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: SAS notice dialog displayed; not handled\n");
break;
case IDD_WLXLOGGEDOUTSAS_DIALOG: /* Windows NT 4.0. */
case IDD_WLXLOGGEDOUTSAS_DIALOG2: /* Windows 2000 and up. */
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: returning hooked SAS logged out dialog\n");
}
case IDD_SECURITY_DIALOG:
VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: Security dialog displayed; not handled\n");
break;
case IDD_WLXWKSTALOCKEDSAS_DIALOG: /* Windows NT 4.0. */
case IDD_WLXWKSTALOCKEDSAS_DIALOG2: /* Windows 2000 and up. */
{
VBoxGINAVerbose(0, "VBoxGINA::MyWlxDialogBoxParam: returning hooked SAS locked dialog\n");
}
/** @todo Add other hooking stuff here. */
default:
break;
}
}
/* The rest will be redirected. */
}