VBoxCredPoller.cpp revision d2236df2116a3cbe8b17c567f4a9c2281733a956
/* $Id$ */
/** @file
* VBoxCredPoller - Thread for retrieving user credentials.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* Sun Microsystems, Inc. confidential
* All rights reserved
*/
#include <windows.h>
#include <VBox/VBoxGuest.h>
#include <VBox/VBoxGuestLib.h>
#include "dll.h"
#include "VBoxCredProv.h"
#include "VBoxCredential.h"
#include "VBoxCredPoller.h"
{
m_pszDomain = NULL;
}
{
Shutdown();
}
{
Log(("VBoxCredPoller::Initialize\n"));
/* don't create more than one of them */
if (m_hThreadPoller != NIL_RTTHREAD)
{
Log(("VBoxCredPoller::Initialize: Thread already running, returning!\n"));
return false;
}
if (RT_FAILURE(rc))
/* create the poller thread */
rc = RTThreadCreate(&m_hThreadPoller, VBoxCredPoller::threadPoller, this, 0, RTTHREADTYPE_INFREQUENT_POLLER,
RTTHREADFLAGS_WAITABLE, "creds");
if (RT_FAILURE(rc))
{
return false;
}
return true;
}
bool VBoxCredPoller::Shutdown(void)
{
Log(("VBoxCredPoller::Shutdown\n"));
if (m_hThreadPoller == NIL_RTTHREAD)
{
Log(("VBoxCredPoller::Shutdown: Either thread or exit sem is NULL!\n"));
return false;
}
/* Post termination event semaphore */
if (RT_SUCCESS(rc))
{
Log(("VBoxCredPoller::Shutdown: 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. */
}
{
}
return true;
}
int VBoxCredPoller::credentialsRetrieve(void)
{
/* get credentials */
if (RT_SUCCESS(rc))
{
Log(("VBoxCredPoller::credentialsRetrieve: Credentials retrieved (user=%s, pw=%s, domain=%s)\n",
/* allocated but empty? delete and re-fill with default value in block below. */
if (strlen(m_pszDomain) == 0)
{
m_pszDomain = NULL;
}
/* if we don't have a domain specified, fill in a dot (".") specifying the
* local computer. */
if (m_pszDomain == NULL)
{
if (RT_FAILURE(rc))
else
Log(("VBoxCredPoller::credentialsRetrieve: No domain name given, set default value to: %s\n", m_pszDomain));
}
}
/* if all went fine, notify parent */
if (RT_SUCCESS(rc))
{
}
return rc;
}
{
return bRet;
}
void VBoxCredPoller::credentialsReset(void)
{
if (m_pszUser)
if (m_pszPw)
if (m_pszDomain)
m_pszDomain = NULL;
}
{
Log(("VBoxCredPoller::threadPoller\n"));
do
{
int rc;
{
Log(("VBoxCredPoller::threadPoller: Credentials available.\n"));
}
/* wait a bit */
{
Log(("VBoxCredPoller::threadPoller: Terminating\n"));
/* we were asked to terminate, do that instantly! */
return 0;
}
}
while (1);
return 0;
}