summaryrefslogtreecommitdiff
path: root/src/VBox/Additions/WINNT/VBoxCredProv
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2014-03-26 19:21:20 +0000
committer <>2014-05-08 15:03:54 +0000
commitfb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch)
treec2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Additions/WINNT/VBoxCredProv
parent58ed4748338f9466599adfc8a9171280ed99e23f (diff)
downloadVirtualBox-master.tar.gz
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Additions/WINNT/VBoxCredProv')
-rw-r--r--src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp177
-rw-r--r--src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.h3
-rw-r--r--src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvProvider.cpp59
-rw-r--r--src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvUtils.cpp2
-rw-r--r--src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp216
-rw-r--r--src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.h2
-rw-r--r--src/VBox/Additions/WINNT/VBoxCredProv/testcase/Makefile.kmk22
-rw-r--r--src/VBox/Additions/WINNT/VBoxCredProv/testcase/tstCredentialProvider.cpp4
8 files changed, 300 insertions, 185 deletions
diff --git a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp
index ef3e7264..c373ace7 100644
--- a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp
+++ b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp
@@ -22,6 +22,7 @@
# include <ntstatus.h>
# define WIN32_NO_STATUS
#endif
+#include <intsafe.h>
#include "VBoxCredentialProvider.h"
@@ -37,10 +38,12 @@
+
VBoxCredProvCredential::VBoxCredProvCredential(void) :
m_enmUsageScenario(CPUS_INVALID),
m_cRefs(1),
- m_pEvents(NULL)
+ m_pEvents(NULL),
+ m_fHaveCreds(false)
{
VBoxCredProvVerbose(0, "VBoxCredProvCredential: Created\n");
VBoxCredentialProviderAcquire();
@@ -124,20 +127,33 @@ VBoxCredProvCredential::QueryInterface(REFIID interfaceID, void **ppvInterface)
HRESULT
VBoxCredProvCredential::RTUTF16ToUnicode(PUNICODE_STRING pUnicodeDest, PRTUTF16 pwszSource, bool fCopy)
{
- AssertPtrReturn(pUnicodeDest, VERR_INVALID_POINTER);
- AssertPtrReturn(pwszSource, VERR_INVALID_POINTER);
+ AssertPtrReturn(pUnicodeDest, E_POINTER);
+ AssertPtrReturn(pwszSource, E_POINTER);
size_t cbLen = RTUtf16Len(pwszSource) * sizeof(RTUTF16);
+ AssertReturn(cbLen <= USHORT_MAX, E_INVALIDARG);
- pUnicodeDest->Length = cbLen;
- pUnicodeDest->MaximumLength = pUnicodeDest->Length;
+ HRESULT hr;
if (fCopy)
- memcpy(pUnicodeDest->Buffer, pwszSource, cbLen);
+ {
+ if (cbLen <= pUnicodeDest->MaximumLength)
+ {
+ memcpy(pUnicodeDest->Buffer, pwszSource, cbLen);
+ pUnicodeDest->Length = (USHORT)cbLen;
+ hr = S_OK;
+ }
+ else
+ hr = E_INVALIDARG;
+ }
else /* Just assign the buffer. */
- pUnicodeDest->Buffer = pwszSource;
+ {
+ pUnicodeDest->Buffer = pwszSource;
+ pUnicodeDest->Length = (USHORT)cbLen;
+ hr = S_OK;
+ }
- return S_OK;
+ return hr;
}
@@ -337,6 +353,18 @@ VBoxCredProvCredential::RetrieveCredentials(void)
m_apwszCredentials[VBOXCREDPROV_FIELDID_DOMAINNAME]);
}
}
+
+ m_fHaveCreds = true;
+ }
+ else
+ {
+ /* If credentials already were retrieved by a former call, don't try to retrieve new ones
+ * and just report back the already retrieved ones. */
+ if (m_fHaveCreds)
+ {
+ VBoxCredProvVerbose(0, "VBoxCredProvCredential::RetrieveCredentials: Credentials already retrieved\n");
+ rc = VINF_SUCCESS;
+ }
}
VBoxCredProvVerbose(0, "VBoxCredProvCredential::RetrieveCredentials: Returned rc=%Rrc\n", rc);
@@ -601,7 +629,7 @@ VBoxCredProvCredential::ExtractAccoutData(PWSTR pwszAccountData, PWSTR *ppwszAcc
if ( (pPos = StrChrW(pwszAccountData, L'@')) != NULL
&& pPos != pwszAccountData)
{
- DWORD cbSize = (pPos - pwszAccountData) * sizeof(WCHAR);
+ size_t cbSize = (pPos - pwszAccountData) * sizeof(WCHAR);
LPWSTR pwszName = (LPWSTR)CoTaskMemAlloc(cbSize + sizeof(WCHAR)); /* Space for terminating zero. */
LPWSTR pwszDomain = NULL;
AssertPtr(pwszName);
@@ -869,94 +897,105 @@ VBoxCredProvCredential::GetSerialization(CREDENTIAL_PROVIDER_GET_SERIALIZATION_R
hr = HRESULT_FROM_WIN32(GetLastError());
}
+ /* Fill in the username and password. */
if (SUCCEEDED(hr))
{
- /* Fill in the username and password. */
+ hr = RTUTF16ToUnicode(&pKerberosLogon->UserName,
+ m_apwszCredentials[VBOXCREDPROV_FIELDID_USERNAME],
+ false /* Just assign, no copy */);
if (SUCCEEDED(hr))
{
- hr = RTUTF16ToUnicode(&pKerberosLogon->UserName,
- m_apwszCredentials[VBOXCREDPROV_FIELDID_USERNAME],
+ hr = RTUTF16ToUnicode(&pKerberosLogon->Password,
+ m_apwszCredentials[VBOXCREDPROV_FIELDID_PASSWORD],
false /* Just assign, no copy */);
if (SUCCEEDED(hr))
{
- hr = RTUTF16ToUnicode(&pKerberosLogon->Password,
- m_apwszCredentials[VBOXCREDPROV_FIELDID_PASSWORD],
- false /* Just assign, no copy */);
- if (SUCCEEDED(hr))
+ /* Set credential type according to current usage scenario. */
+ AssertPtr(pKerberosLogon);
+ switch (m_enmUsageScenario)
{
- /* Set credential type according to current usage scenario. */
- AssertPtr(pKerberosLogon);
- switch (m_enmUsageScenario)
- {
- case CPUS_UNLOCK_WORKSTATION:
- pKerberosLogon->MessageType = KerbWorkstationUnlockLogon;
- break;
+ case CPUS_UNLOCK_WORKSTATION:
+ pKerberosLogon->MessageType = KerbWorkstationUnlockLogon;
+ break;
- case CPUS_LOGON:
- pKerberosLogon->MessageType = KerbInteractiveLogon;
- break;
+ case CPUS_LOGON:
+ pKerberosLogon->MessageType = KerbInteractiveLogon;
+ break;
- case CPUS_CREDUI:
- pKerberosLogon->MessageType = (KERB_LOGON_SUBMIT_TYPE)0; /* No message type required here. */
- break;
+ case CPUS_CREDUI:
+ pKerberosLogon->MessageType = (KERB_LOGON_SUBMIT_TYPE)0; /* No message type required here. */
+ break;
- default:
- hr = E_FAIL;
- break;
- }
+ default:
+ hr = E_FAIL;
+ break;
+ }
- if (SUCCEEDED(hr)) /* Build the logon package. */
- hr = AllocateLogonPackage(KerberosUnlockLogon,
- &pcpCredentialSerialization->rgbSerialization,
- &pcpCredentialSerialization->cbSerialization);
+ if (FAILED(hr))
+ VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Unknown usage scenario=%ld\n", m_enmUsageScenario);
- if (SUCCEEDED(hr))
- {
- ULONG ulAuthPackage;
+ if (SUCCEEDED(hr)) /* Build the logon package. */
+ {
+ hr = AllocateLogonPackage(KerberosUnlockLogon,
+ &pcpCredentialSerialization->rgbSerialization,
+ &pcpCredentialSerialization->cbSerialization);
+ if (FAILED(hr))
+ VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Failed to allocate logon package, hr=0x%08x\n", hr);
+ }
- HANDLE hLsa;
- NTSTATUS s = LsaConnectUntrusted(&hLsa);
- if (SUCCEEDED(HRESULT_FROM_NT(s)))
+ if (SUCCEEDED(hr))
+ {
+ ULONG ulAuthPackage;
+
+ HANDLE hLsa;
+ NTSTATUS s = LsaConnectUntrusted(&hLsa);
+ if (SUCCEEDED(HRESULT_FROM_NT(s)))
+ {
+ LSA_STRING lsaszKerberosName;
+ size_t cchKerberosName;
+ hr = StringCchLengthA(NEGOSSP_NAME_A, USHORT_MAX, &cchKerberosName);
+ if (SUCCEEDED(hr))
{
- LSA_STRING lsaszKerberosName;
- size_t cchKerberosName;
- hr = StringCchLengthA(NEGOSSP_NAME_A, USHORT_MAX, &cchKerberosName);
+ USHORT usLength;
+ hr = SizeTToUShort(cchKerberosName, &usLength);
if (SUCCEEDED(hr))
{
- USHORT usLength;
- hr = SizeTToUShort(cchKerberosName, &usLength);
- if (SUCCEEDED(hr))
- {
- lsaszKerberosName.Buffer = (PCHAR)NEGOSSP_NAME_A;
- lsaszKerberosName.Length = usLength;
- lsaszKerberosName.MaximumLength = lsaszKerberosName.Length + 1;
-
- }
- }
+ lsaszKerberosName.Buffer = (PCHAR)NEGOSSP_NAME_A;
+ lsaszKerberosName.Length = usLength;
+ lsaszKerberosName.MaximumLength = lsaszKerberosName.Length + 1;
- if (SUCCEEDED(hr))
- {
- s = LsaLookupAuthenticationPackage(hLsa, &lsaszKerberosName,
- &ulAuthPackage);
- if (FAILED(HRESULT_FROM_NT(s)))
- hr = HRESULT_FROM_NT(s);
}
-
- LsaDeregisterLogonProcess(hLsa);
}
if (SUCCEEDED(hr))
{
- pcpCredentialSerialization->ulAuthenticationPackage = ulAuthPackage;
- pcpCredentialSerialization->clsidCredentialProvider = CLSID_VBoxCredProvider;
-
- /* We're done -- let the logon UI know. */
- *pcpGetSerializationResponse = CPGSR_RETURN_CREDENTIAL_FINISHED;
+ s = LsaLookupAuthenticationPackage(hLsa, &lsaszKerberosName,
+ &ulAuthPackage);
+ if (FAILED(HRESULT_FROM_NT(s)))
+ {
+ hr = HRESULT_FROM_NT(s);
+ VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Failed looking up authentication package, hr=0x%08x\n", hr);
+ }
}
+
+ LsaDeregisterLogonProcess(hLsa);
+ }
+
+ if (SUCCEEDED(hr))
+ {
+ pcpCredentialSerialization->ulAuthenticationPackage = ulAuthPackage;
+ pcpCredentialSerialization->clsidCredentialProvider = CLSID_VBoxCredProvider;
+
+ /* We're done -- let the logon UI know. */
+ *pcpGetSerializationResponse = CPGSR_RETURN_CREDENTIAL_FINISHED;
}
}
}
+ else
+ VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Error copying password, hr=0x%08x\n", hr);
}
+ else
+ VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Error copying user name, hr=0x%08x\n", hr);
}
VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization returned hr=0x%08x\n", hr);
diff --git a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.h b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.h
index 27744465..f5bda6c1 100644
--- a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.h
+++ b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.h
@@ -23,7 +23,6 @@
* Header Files *
*******************************************************************************/
#include <Windows.h>
-#include <intsafe.h>
#include <NTSecAPI.h>
#define SECURITY_WIN32
#include <Security.h>
@@ -110,6 +109,8 @@ private:
PRTUTF16 m_apwszCredentials[VBOXCREDPROV_NUM_FIELDS];
/** Pointer to event handler. */
ICredentialProviderCredentialEvents *m_pEvents;
+ /** Flag indicating whether credentials already were retrieved. */
+ bool m_fHaveCreds;
};
#endif /* !___VBOX_CREDPROV_CREDENTIAL_H___ */
diff --git a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvProvider.cpp b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvProvider.cpp
index 1190c387..994a24da 100644
--- a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvProvider.cpp
+++ b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvProvider.cpp
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (C) 2012 Oracle Corporation
+ * Copyright (C) 2012-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
@@ -18,7 +18,10 @@
/*******************************************************************************
* Header Files *
*******************************************************************************/
+#include <new> /* For bad_alloc. */
+
#include <credentialprovider.h>
+
#include <iprt/err.h>
#include <VBox/VBoxGuestLib.h>
@@ -138,7 +141,7 @@ VBoxCredProvProvider::LoadConfiguration(void)
&& dwType == REG_DWORD
&& dwSize == sizeof(DWORD))
{
- m_fHandleRemoteSessions = true;
+ m_fHandleRemoteSessions = RT_BOOL(dwValue);
}
dwRet = RegQueryValueEx(hKey, L"LoggingEnabled", NULL, &dwType, (LPBYTE)&dwValue, &dwSize);
@@ -235,22 +238,35 @@ VBoxCredProvProvider::SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO enmUsa
if (!m_pPoller)
{
- /** @todo try catch please. */
- m_pPoller = new VBoxCredProvPoller();
- AssertPtr(m_pPoller);
- int rc = m_pPoller->Initialize(this);
- if (RT_FAILURE(rc))
- VBoxCredProvVerbose(0, "VBoxCredProv::SetUsageScenario: Error initializing poller thread, rc=%Rrc\n", rc);
+ try
+ {
+ m_pPoller = new VBoxCredProvPoller();
+ AssertPtr(m_pPoller);
+ int rc = m_pPoller->Initialize(this);
+ if (RT_FAILURE(rc))
+ VBoxCredProvVerbose(0, "VBoxCredProv::SetUsageScenario: Error initializing poller thread, rc=%Rrc\n", rc);
+ }
+ catch (std::bad_alloc &ex)
+ {
+ NOREF(ex);
+ hr = E_OUTOFMEMORY;
+ }
}
- if (!m_pCred)
+ if ( SUCCEEDED(hr)
+ && !m_pCred)
{
- /** @todo try catch please. */
- m_pCred = new VBoxCredProvCredential();
- if (m_pCred)
+ try
+ {
+ m_pCred = new VBoxCredProvCredential();
+ AssertPtr(m_pPoller);
hr = m_pCred->Initialize(m_enmUsageScenario);
- else
+ }
+ catch (std::bad_alloc &ex)
+ {
+ NOREF(ex);
hr = E_OUTOFMEMORY;
+ }
}
else
{
@@ -269,9 +285,9 @@ VBoxCredProvProvider::SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO enmUsa
break;
}
- case CPUS_CHANGE_PASSWORD:
- case CPUS_CREDUI:
- case CPUS_PLAP:
+ case CPUS_CHANGE_PASSWORD: /* Asks us to provide a way to change the password. */
+ case CPUS_CREDUI: /* Displays an own UI. We don't need that. */
+ case CPUS_PLAP: /* See Pre-Logon-Access Provider. Not needed (yet). */
hr = E_NOTIMPL;
break;
@@ -523,15 +539,18 @@ VBoxCredProvProviderCreate(REFIID interfaceID, void **ppvInterface)
{
HRESULT hr;
- /** @todo try-catch. */
- VBoxCredProvProvider *pProvider = new VBoxCredProvProvider();
- if (pProvider)
+ try
{
+ VBoxCredProvProvider *pProvider = new VBoxCredProvProvider();
+ AssertPtr(pProvider);
hr = pProvider->QueryInterface(interfaceID, ppvInterface);
pProvider->Release();
}
- else
+ catch (std::bad_alloc &ex)
+ {
+ NOREF(ex);
hr = E_OUTOFMEMORY;
+ }
return hr;
}
diff --git a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvUtils.cpp b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvUtils.cpp
index 67a98aa1..08f73405 100644
--- a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvUtils.cpp
+++ b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvUtils.cpp
@@ -21,7 +21,7 @@
#include <Windows.h>
#include <iprt/string.h>
#include <VBox/log.h>
-#include <VBox/VboxGuestLib.h>
+#include <VBox/VBoxGuestLib.h>
/*******************************************************************************
diff --git a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp
index 97154d66..8d841301 100644
--- a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp
+++ b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (C) 2012 Oracle Corporation
+ * Copyright (C) 2012-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
@@ -20,6 +20,7 @@
*******************************************************************************/
#include <windows.h>
#include <initguid.h>
+#include <new> /* For bad_alloc. */
#ifdef VBOX_WITH_SENS
# include <eventsys.h>
@@ -40,11 +41,12 @@
/*******************************************************************************
* Global Variables *
*******************************************************************************/
-static LONG g_cDllRefs = 0; /**< Global DLL reference count. */
-static HINSTANCE g_hDllInst = NULL; /**< Global DLL hInstance. */
+static LONG g_cDllRefs = 0; /**< Global DLL reference count. */
+static HINSTANCE g_hDllInst = NULL; /**< Global DLL hInstance. */
#ifdef VBOX_WITH_SENS
-static IEventSystem *g_pIEventSystem; /**< Pointer to IEventSystem interface. */
+static bool g_fSENSEnabled = false;
+static IEventSystem *g_pIEventSystem = NULL; /**< Pointer to IEventSystem interface. */
/**
* Subscribed SENS events.
@@ -179,7 +181,7 @@ protected:
LONG m_cRefs;
};
-static VBoxCredProvSensLogon *g_pISensLogon;
+static VBoxCredProvSensLogon *g_pISensLogon = NULL;
/**
@@ -199,85 +201,104 @@ static HRESULT VBoxCredentialProviderRegisterSENS(void)
return hr;
}
- g_pISensLogon = new VBoxCredProvSensLogon();
- if (!g_pISensLogon)
+ try
{
- VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not create interface instance; out of memory\n");
- return ERROR_OUTOFMEMORY;
+ g_pISensLogon = new VBoxCredProvSensLogon();
+ AssertPtr(g_pISensLogon);
+ }
+ catch (std::bad_alloc &ex)
+ {
+ NOREF(ex);
+ hr = E_OUTOFMEMORY;
}
- IEventSubscription *pIEventSubscription;
- int i;
- for (i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++)
+ if ( SUCCEEDED(hr)
+ && g_pIEventSystem)
{
- VBoxCredProvVerbose(0, "VBoxCredProv: Registering \"%s\" (%s) ...\n",
- g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName);
+ IEventSubscription *pIEventSubscription;
+ int i;
+ for (i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++)
+ {
+ VBoxCredProvVerbose(0, "VBoxCredProv: Registering \"%s\" (%s) ...\n",
+ g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName);
- hr = CoCreateInstance(CLSID_CEventSubscription, 0, CLSCTX_SERVER, IID_IEventSubscription, (LPVOID*)&pIEventSubscription);
- if (FAILED(hr))
- continue;
+ hr = CoCreateInstance(CLSID_CEventSubscription, 0, CLSCTX_SERVER, IID_IEventSubscription, (LPVOID*)&pIEventSubscription);
+ if (FAILED(hr))
+ continue;
- hr = pIEventSubscription->put_EventClassID(L"{d5978630-5b9f-11d1-8dd2-00aa004abd5e}" /* SENSGUID_EVENTCLASS_LOGON */);
- if (FAILED(hr))
- break;
+ hr = pIEventSubscription->put_EventClassID(L"{d5978630-5b9f-11d1-8dd2-00aa004abd5e}" /* SENSGUID_EVENTCLASS_LOGON */);
+ if (FAILED(hr))
+ break;
- hr = pIEventSubscription->put_SubscriberInterface((IUnknown*)g_pISensLogon);
- if (FAILED(hr))
- break;
+ hr = pIEventSubscription->put_SubscriberInterface((IUnknown*)g_pISensLogon);
+ if (FAILED(hr))
+ break;
- PRTUTF16 pwszTemp;
- int rc = RTStrToUtf16(g_aSENSEvents[i].pszMethod, &pwszTemp);
- if (RT_SUCCESS(rc))
- {
- hr = pIEventSubscription->put_MethodName(pwszTemp);
- RTUtf16Free(pwszTemp);
- }
- else
- hr = ERROR_OUTOFMEMORY;
- if (FAILED(hr))
- break;
+ PRTUTF16 pwszTemp;
+ int rc = RTStrToUtf16(g_aSENSEvents[i].pszMethod, &pwszTemp);
+ if (RT_SUCCESS(rc))
+ {
+ hr = pIEventSubscription->put_MethodName(pwszTemp);
+ RTUtf16Free(pwszTemp);
+ }
+ else
+ hr = ERROR_OUTOFMEMORY;
+ if (FAILED(hr))
+ break;
- rc = RTStrToUtf16(g_aSENSEvents[i].pszSubscriptionName, &pwszTemp);
- if (RT_SUCCESS(rc))
- {
- hr = pIEventSubscription->put_SubscriptionName(pwszTemp);
- RTUtf16Free(pwszTemp);
- }
- else
- hr = ERROR_OUTOFMEMORY;
- if (FAILED(hr))
- break;
+ rc = RTStrToUtf16(g_aSENSEvents[i].pszSubscriptionName, &pwszTemp);
+ if (RT_SUCCESS(rc))
+ {
+ hr = pIEventSubscription->put_SubscriptionName(pwszTemp);
+ RTUtf16Free(pwszTemp);
+ }
+ else
+ hr = ERROR_OUTOFMEMORY;
+ if (FAILED(hr))
+ break;
- rc = RTStrToUtf16(g_aSENSEvents[i].pszSubscriptionUUID, &pwszTemp);
- if (RT_SUCCESS(rc))
- {
- hr = pIEventSubscription->put_SubscriptionID(pwszTemp);
- RTUtf16Free(pwszTemp);
- }
- else
- hr = ERROR_OUTOFMEMORY;
- if (FAILED(hr))
- break;
+ rc = RTStrToUtf16(g_aSENSEvents[i].pszSubscriptionUUID, &pwszTemp);
+ if (RT_SUCCESS(rc))
+ {
+ hr = pIEventSubscription->put_SubscriptionID(pwszTemp);
+ RTUtf16Free(pwszTemp);
+ }
+ else
+ hr = ERROR_OUTOFMEMORY;
+ if (FAILED(hr))
+ break;
- hr = pIEventSubscription->put_PerUser(TRUE);
- if (FAILED(hr))
- break;
+ hr = pIEventSubscription->put_PerUser(TRUE);
+ if (FAILED(hr))
+ break;
+
+ hr = g_pIEventSystem->Store(PROGID_EventSubscription, (IUnknown*)pIEventSubscription);
+ if (FAILED(hr))
+ break;
+
+ pIEventSubscription->Release();
+ pIEventSubscription = NULL;
+ }
- hr = g_pIEventSystem->Store(PROGID_EventSubscription, (IUnknown*)pIEventSubscription);
if (FAILED(hr))
- break;
+ VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not register \"%s\" (%s), hr=%Rhrc\n",
+ g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName, hr);
- pIEventSubscription->Release();
- pIEventSubscription = NULL;
+ if (pIEventSubscription != NULL)
+ pIEventSubscription->Release();
}
if (FAILED(hr))
- VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not register \"%s\" (%s), hr=%Rhrc\n",
- g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName, hr);
-
- if (pIEventSubscription != NULL)
- pIEventSubscription->Release();
+ {
+ VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Error registering SENS provider, hr=%Rhrc\n", hr);
+ if (g_pIEventSystem)
+ {
+ g_pIEventSystem->Release();
+ g_pIEventSystem = NULL;
+ }
+ }
+ VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Returning hr=%Rhrc\n", hr);
return hr;
}
@@ -287,12 +308,17 @@ static HRESULT VBoxCredentialProviderRegisterSENS(void)
static void VBoxCredentialProviderUnregisterSENS(void)
{
if (g_pIEventSystem)
+ {
g_pIEventSystem->Release();
+ g_pIEventSystem = NULL;
+ }
/* We need to reconnecto to the event system because we can be called
* in a different context COM can't handle. */
- HRESULT hr = CoCreateInstance(CLSID_CEventSystem, 0, CLSCTX_SERVER, IID_IEventSystem, (void**)&g_pIEventSystem);
- if (SUCCEEDED(hr))
+ HRESULT hr = CoCreateInstance(CLSID_CEventSystem, 0,
+ CLSCTX_SERVER, IID_IEventSystem, (void**)&g_pIEventSystem);
+ if ( SUCCEEDED(hr)
+ && g_pIEventSystem)
{
VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS\n");
@@ -329,10 +355,16 @@ static void VBoxCredentialProviderUnregisterSENS(void)
}
g_pIEventSystem->Release();
+ g_pIEventSystem = NULL;
}
if (g_pISensLogon)
+ {
delete g_pISensLogon;
+ g_pISensLogon = NULL;
+ }
+
+ VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Returning hr=%Rhrc\n", hr);
}
#endif /* VBOX_WITH_SENS */
@@ -347,7 +379,7 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID pReserved)
{
case DLL_PROCESS_ATTACH:
{
- int rc = RTR3InitDll(0 /* Flags */);
+ int rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
if (RT_SUCCESS(rc))
rc = VbglR3Init();
@@ -372,6 +404,9 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID pReserved)
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
+
+ default:
+ break;
}
return TRUE;
@@ -426,7 +461,8 @@ HRESULT __stdcall DllCanUnloadNow(void)
#ifdef VBOX_WITH_SENS
if (!g_cDllRefs)
{
- VBoxCredentialProviderUnregisterSENS();
+ if (g_fSENSEnabled)
+ VBoxCredentialProviderUnregisterSENS();
CoUninitialize();
}
@@ -452,23 +488,55 @@ HRESULT VBoxCredentialProviderCreate(REFCLSID classID, REFIID interfaceID,
HRESULT hr;
if (classID == CLSID_VBoxCredProvider)
{
- VBoxCredProvFactory* pFactory = new VBoxCredProvFactory();
- if (pFactory)
+ try
{
+ VBoxCredProvFactory* pFactory = new VBoxCredProvFactory();
+ AssertPtr(pFactory);
hr = pFactory->QueryInterface(interfaceID,
ppvInterface);
pFactory->Release();
#ifdef VBOX_WITH_SENS
- if (SUCCEEDED(hr))
+ g_fSENSEnabled = true; /* By default SENS support is enabled. */
+
+ HKEY hKey;
+ /** @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)
+ {
+ DWORD dwValue;
+ DWORD dwType = REG_DWORD;
+ DWORD dwSize = sizeof(DWORD);
+
+ dwRet = RegQueryValueEx(hKey, L"HandleSENS", NULL, &dwType, (LPBYTE)&dwValue, &dwSize);
+ if ( dwRet == ERROR_SUCCESS
+ && dwType == REG_DWORD
+ && dwSize == sizeof(DWORD))
+ {
+ g_fSENSEnabled = RT_BOOL(dwValue);
+ }
+
+ RegCloseKey(hKey);
+ }
+
+ VBoxCredProvVerbose(0, "VBoxCredentialProviderCreate: g_fSENSEnabled=%RTbool\n",
+ g_fSENSEnabled);
+ if ( SUCCEEDED(hr)
+ && g_fSENSEnabled)
{
HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
VBoxCredentialProviderRegisterSENS();
}
+#else
+ VBoxCredProvVerbose(0, "VBoxCredentialProviderCreate: SENS support is disabled\n");
#endif
}
- else
+ catch (std::bad_alloc &ex)
+ {
+ NOREF(ex);
hr = E_OUTOFMEMORY;
+ }
}
else
hr = CLASS_E_CLASSNOTAVAILABLE;
diff --git a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.h b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.h
index b40c4bf9..c5e1c027 100644
--- a/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.h
+++ b/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.h
@@ -18,7 +18,7 @@
#ifndef ___VBOX_CREDENTIALPROVIDER_H___
#define ___VBOX_CREDENTIALPROVIDER_H___
-#include <windows.h>
+#include <Windows.h>
#include <credentialprovider.h>
#include "VBoxCredProvUtils.h"
diff --git a/src/VBox/Additions/WINNT/VBoxCredProv/testcase/Makefile.kmk b/src/VBox/Additions/WINNT/VBoxCredProv/testcase/Makefile.kmk
index 9326ee7c..ef282f22 100644
--- a/src/VBox/Additions/WINNT/VBoxCredProv/testcase/Makefile.kmk
+++ b/src/VBox/Additions/WINNT/VBoxCredProv/testcase/Makefile.kmk
@@ -4,7 +4,7 @@
#
#
-# Copyright (C) 2009-2012 Oracle Corporation
+# Copyright (C) 2009-2013 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
@@ -22,21 +22,9 @@ PROGRAMS += tstCredentialProvider
tstCredentialProvider_TEMPLATE = NewVBoxGuestR3Exe
tstCredentialProvider_SOURCES = \
tstCredentialProvider.cpp
-tstCredentialProvider_SDKS.x86 = WINDDK
-
-#
-# Since this is not the default SDK we have to navigate manually to it.
-#
-VBOX_PATH_PSDK_200702 := \
- $(PATH_DEVTOOLS)/win.x86/sdk/x200702/
-
-tstCredentialProvider_INCS := \
- $(VBOX_PATH_PSDK_200702)/Include
-tstCredentialProvider_LIBS.x86 := \
- $(VBOX_PATH_PSDK_200702)/Lib/credui.lib \
- $(VBOX_PATH_PSDK_200702)/Lib/Secur32.Lib
-tstCredentialProvider_LIBS.amd64 := \
- $(VBOX_PATH_PSDK_200702)/Lib/x64/Credui.Lib \
- $(VBOX_PATH_PSDK_200702)/Lib/x64/Secur32.Lib
+tstCredentialProvider_LIBS = \
+ $(PATH_SDK_$(VBOX_WINPSDK_GST_WLH)_LIB)/credui.lib \
+ $(PATH_SDK_$(VBOX_WINPSDK_GST_WLH)_LIB)/Secur32.Lib
include $(FILE_KBUILD_SUB_FOOTER)
+
diff --git a/src/VBox/Additions/WINNT/VBoxCredProv/testcase/tstCredentialProvider.cpp b/src/VBox/Additions/WINNT/VBoxCredProv/testcase/tstCredentialProvider.cpp
index ec1bac1b..689e2937 100644
--- a/src/VBox/Additions/WINNT/VBoxCredProv/testcase/tstCredentialProvider.cpp
+++ b/src/VBox/Additions/WINNT/VBoxCredProv/testcase/tstCredentialProvider.cpp
@@ -19,6 +19,6 @@ int main(int argc, TCHAR* argv[])
DWORD dwErr = CredUIPromptForWindowsCredentials(&(credUiInfo), 0, &(authPackage),
NULL, 0, &authBuffer, &authBufferSize, &(save), 0);
printf("Test returned %ld\n", dwErr);
-
- return dwERR == ERROR_SUCCESS ? 0 : 1;
+
+ return dwErr == ERROR_SUCCESS ? 0 : 1;
}