VBoxCredPoller.cpp revision fcae7923a3c756b333f1e33eba002edf4448fb54
/* $Id$ */
/** @file
* VBoxCredPoller - Thread for retrieving user credentials.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#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;
}