Helper.cpp revision 3bc80d06b829c4584091b3e192536d6fb8f239c1
/* $Id$ */
/** @file
* VBoxGINA - Windows Logon DLL for VirtualBox, Helper Functions.
*/
/*
* Copyright (C) 2006-2011 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 "winwlx.h"
#include "Helper.h"
#include "VBoxGINA.h"
#include <VBox/VBoxGuest.h>
/* remote session handling */
/* the credentials */
wchar_t g_Username[VMMDEV_CREDENTIALS_SZ_SIZE];
wchar_t g_Password[VMMDEV_CREDENTIALS_SZ_SIZE];
wchar_t g_Domain[VMMDEV_CREDENTIALS_SZ_SIZE];
HANDLE getVBoxDriver(void)
{
if (sVBoxDriver == INVALID_HANDLE_VALUE)
{
NULL,
NULL);
if (sVBoxDriver == INVALID_HANDLE_VALUE)
}
return sVBoxDriver;
}
/**
* Detects whether our process is running in a remote session or not.
*
* @return bool true if running in a remote session, false if not.
*/
bool isRemoteSession(void)
{
return (0 != GetSystemMetrics(SM_REMOTESESSION)) ? true : false;
}
/**
* Loads the global configuration from registry.
*
* @return DWORD Windows error code.
*/
DWORD loadConfiguration(void)
{
/** @todo Add some registry wrapper function(s) as soon as we got more values to retrieve. */
DWORD dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Oracle\\VirtualBox Guest Additions\\AutoLogon",
0L, KEY_QUERY_VALUE, &hKey);
if (dwRet == ERROR_SUCCESS)
{
if ( dwRet == ERROR_SUCCESS
{
}
}
return dwRet;
}
/**
* Determines whether we should handle the current session or not.
*
* @return bool true if we should handle this session, false if not.
*/
bool handleCurrentSession(void)
{
bool fHandle = false;
if (isRemoteSession())
{
if (g_dwHandleRemoteSessions) /* Force remote session handling. */
fHandle = true;
}
else /* No remote session. */
fHandle = true;
return fHandle;
}
void credentialsReset(void)
{
}
bool credentialsAvailable(void)
{
if (!handleCurrentSession())
return false;
if (vboxDriver == INVALID_HANDLE_VALUE)
return false;
/* query the VMMDev whether there are credentials */
if (!DeviceIoControl(vboxDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(vmmreqCredentials)), &vmmreqCredentials, sizeof(vmmreqCredentials),
{
return false;
}
/*Log(("VBoxGINA::credentialsAvailable: fAvailable: %d\n", fAvailable));*/
return fAvailable;
}
bool credentialsRetrieve(void)
{
if (!handleCurrentSession())
return false;
Log(("VBoxGINA::credentialsRetrieve\n"));
if (vboxDriver == INVALID_HANDLE_VALUE)
return false;
/* to be safe, reset the credentials */
/* query the credentials */
if (!DeviceIoControl(vboxDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(vmmreqCredentials)), &vmmreqCredentials, sizeof(vmmreqCredentials),
{
return false;
}
/* convert from UTF-8 to UTF-16 and store in global variables */
{
}
{
}
{
}
Log(("VBoxGINA::credentialsRetrieve: returning user '%s', password '%s', domain '%s'\n",
return true;
}
/* handle of the poller thread */
/**
* Poller thread. Checks periodically whether there are credentials.
*/
{
Log(("VBoxGINA::credentialsPoller\n"));
do
{
if (credentialsAvailable())
{
Log(("VBoxGINA::credentialsPoller: got credentials, simulating C-A-D\n"));
/* tell WinLogon to start the attestation process */
/* time to say goodbye */
return 0;
}
/* wait a bit */
{
Log(("VBoxGINA::credentialsPoller: we were asked to terminate\n"));
/* we were asked to terminate, do that instantly! */
return 0;
}
}
while (1);
return 0;
}
bool credentialsPollerCreate(void)
{
if (!handleCurrentSession())
return false;
Log(("VBoxGINA::credentialsPollerCreate\n"));
/* don't create more than one of them */
if (gThreadPoller != NIL_RTTHREAD)
{
Log(("VBoxGINA::credentialsPollerCreate: thread already running, returning!\n"));
return false;
}
/* create the poller thread */
RTTHREADFLAGS_WAITABLE, "creds");
if (RT_FAILURE(rc))
{
return false;
}
return true;
}
bool credentialsPollerTerminate(void)
{
Log(("VBoxGINA::credentialsPollerTerminate\n"));
if (gThreadPoller == NIL_RTTHREAD)
{
Log(("VBoxGINA::credentialsPollerTerminate: either thread or exit sem is NULL!\n"));
return false;
}
/* post termination event semaphore */
if (RT_SUCCESS(rc))
{
Log(("VBoxGINA::credentialsPollerTerminate: waiting for thread to terminate\n"));
/* wait until the thread has terminated */
}
else
{
/* failed to signal the thread - very unlikely - so no point in waiting long. */
}
/* now cleanup */
return true;
}