VBoxCredentialProvider.cpp revision 6da8aad9b9f0e2aa239259658e3d82073f5761e4
/* $Id$ */
/** @file
* VBoxCredentialProvider - Main file of the VirtualBox Credential Provider.
*/
/*
* Copyright (C) 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <windows.h>
#include <initguid.h>
#include <iprt/buildconfig.h>
#include <iprt/initterm.h>
#ifdef VBOX_WITH_SENS
#endif
#include <VBox/VBoxGuestLib.h>
#include "VBoxCredentialProvider.h"
#include "VBoxCredProvFactory.h"
#include <eventsys.h>
#include <sens.h>
#include <Sensevts.h>
#include <stdio.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
#ifdef VBOX_WITH_SENS
/**
* Subscribed SENS events.
*/
static struct VBOXCREDPROVSENSEVENTS
{
/** The actual method name the subscription is for. */
char *pszMethod;
/** A friendly name for the subscription. */
char *pszSubscriptionName;
/** The actual subscription UUID.
* Should not be changed. */
char *pszSubscriptionUUID;
} g_aSENSEvents[] = {
{ "Logon", "VBoxCredProv SENS Logon", "{561D0791-47C0-4BC3-87C0-CDC2621EA653}" },
{ "Logoff", "VBoxCredProv SENS Logoff", "{12B618B1-F2E0-4390-BADA-7EB1DC31A70A}" },
{ "StartShell", "VBoxCredProv SENS StartShell", "{5941931D-015A-4F91-98DA-81AAE262D090}" },
{ "DisplayLock", "VBoxCredProv SENS DisplayLock", "{B7E2C510-501A-4961-938F-A458970930D7}" },
{ "DisplayUnlock", "VBoxCredProv SENS DisplayUnlock", "{11305987-8FFC-41AD-A264-991BD5B7488A}" },
{ "StartScreenSaver", "VBoxCredProv SENS StartScreenSaver", "{6E2D26DF-0095-4EC4-AE00-2395F09AF7F2}" },
{ "StopScreenSaver", "VBoxCredProv SENS StopScreenSaver", "{F53426BC-412F-41E8-9A5F-E5FA8A164BD6}" }
};
/**
* Implementation of the ISensLogon interface for getting
* SENS (System Event Notification Service) events. SENS must be up
* and running on this OS!
*/
{
public:
VBoxCredProvSensLogon(void) :
m_cRefs(1)
{
}
{
{
*ppvInterface = this;
AddRef();
return S_OK;
}
*ppvInterface = NULL;
return E_NOINTERFACE;
}
{
return InterlockedIncrement(&m_cRefs);
}
{
return ulTemp;
}
{
return E_NOTIMPL;
}
{
return E_NOTIMPL;
}
{
return E_NOTIMPL;
}
{
return E_NOTIMPL;
}
/* ISensLogon methods */
{
VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: Logon\n");
return S_OK;
}
{
VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: Logoff\n");
return S_OK;
}
{
VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: Logon\n");
return S_OK;
}
{
VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: DisplayLock\n");
return S_OK;
}
{
VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: DisplayUnlock\n");
return S_OK;
}
{
VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: StartScreenSaver\n");
return S_OK;
}
{
VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: StopScreenSaver\n");
return S_OK;
}
protected:
};
static VBoxCredProvSensLogon *g_pISensLogon;
/**
* Register events to be called by SENS.
*
* @return HRESULT
*/
static HRESULT VBoxCredentialProviderRegisterSENS(void)
{
VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS\n");
HRESULT hr = CoCreateInstance(CLSID_CEventSystem, 0, CLSCTX_SERVER, IID_IEventSystem, (void**)&g_pIEventSystem);
{
VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not connect to CEventSystem, hr=%Rhrc\n",
hr);
return hr;
}
g_pISensLogon = new VBoxCredProvSensLogon();
if (!g_pISensLogon)
{
VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not create interface instance; out of memory\n");
return ERROR_OUTOFMEMORY;
}
for (int i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++)
{
VBoxCredProvVerbose(0, "VBoxCredProv: Registering \"%s\" (%s) ...\n",
hr = CoCreateInstance(CLSID_CEventSubscription, 0, CLSCTX_SERVER, IID_IEventSubscription, (LPVOID*)&pIEventSubscription);
continue;
hr = pIEventSubscription->put_EventClassID(L"{d5978630-5b9f-11d1-8dd2-00aa004abd5e}" /* SENSGUID_EVENTCLASS_LOGON */);
break;
break;
if (RT_SUCCESS(rc))
{
}
else
break;
if (RT_SUCCESS(rc))
{
}
else
break;
if (RT_SUCCESS(rc))
{
}
else
break;
break;
break;
}
VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not register \"%s\" (%s), hr=%Rhrc\n",
if (pIEventSubscription != NULL)
return hr;
}
/**
* Unregisters registered SENS events.
*/
static void VBoxCredentialProviderUnregisterSENS(void)
{
if (g_pIEventSystem)
/* 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);
{
VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS\n");
for (int i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++)
{
int iErrorIdX;
char *pszSubToRemove;
{
continue; /* Keep going. */
}
if (RT_SUCCESS(rc2))
{
&iErrorIdX);
}
else
VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Could not unregister \"%s\" (query: %s), hr=%Rhrc (index: %d)\n",
/* Keep going. */
}
}
if (g_pISensLogon)
delete g_pISensLogon;
}
#endif /* VBOX_WITH_SENS */
{
g_hDllInst = hInst;
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{
if (RT_SUCCESS(rc))
rc = VbglR3Init();
if (RT_SUCCESS(rc))
{
VBoxCredProvVerbose(0, "VBoxCredProv: v%s r%s (%s %s) loaded (refs=%ld)\n",
}
break;
}
case DLL_PROCESS_DETACH:
if (!g_cDllRefs)
VbglR3Term();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
/**
* Increments the reference count by one. Must be released
* with VBoxCredentialProviderRelease() when finished.
*/
void VBoxCredentialProviderAcquire(void)
{
VBoxCredProvVerbose(0, "VBoxCredentialProviderAcquire: Increasing global refcount to %ld\n",
}
/**
* Decrements the reference count by one.
*/
void VBoxCredentialProviderRelease(void)
{
VBoxCredProvVerbose(0, "VBoxCredentialProviderRelease: Decreasing global refcount to %ld\n",
}
/**
* Returns the current DLL reference count.
*
* @return LONG The current reference count.
*/
{
return g_cDllRefs;
}
/**
* Entry point for determining whether the credential
* provider DLL can be unloaded or not.
*
* @return HRESULT
*/
{
VBoxCredProvVerbose(0, "DllCanUnloadNow (refs=%ld)\n",
#ifdef VBOX_WITH_SENS
if (!g_cDllRefs)
{
}
#endif
}
/**
* Create the VirtualBox credential provider by creating
* its factory which then in turn can create instances of the
* provider itself.
*
* @return HRESULT
* @param classID The class ID.
* @param interfaceID The interface ID.
* @param ppvInterface Receives the interface pointer on successful
* object creation.
*/
void **ppvInterface)
{
if (classID == CLSID_VBoxCredProvider)
{
if (pFactory)
{
#ifdef VBOX_WITH_SENS
{
}
#endif
}
else
hr = E_OUTOFMEMORY;
}
else
return hr;
}
/**
* Entry point for getting the actual credential provider
* class object.
*
* @return HRESULT
* @param classID The class ID.
* @param interfaceID The interface ID.
* @param ppvInterface Receives the interface pointer on successful
* object creation.
*/
void **ppvInterface)
{
VBoxCredProvVerbose(0, "DllGetClassObject (refs=%ld)\n",
}