#include "StdAfx.h"
#include ".\impersonator.h"

Impersonator::Impersonator(void)
{
	//m_hToken = NULL;
	memset(m_lpszServer, 0, MAX_PATH + 1);
}

Impersonator::~Impersonator(void)
{
	StopImpersonation();
}

bool Impersonator::BeginImpersonation(LPCTSTR lpszServer, LPCTSTR lpszUserName, LPCTSTR lpszPassword)
{
	if (!m_objNetUse.Connect(lpszServer, lpszUserName, lpszPassword) == true)
	{
		//::ErrorHandler("NetUse", "Connect", GetLastError());
		return false;
	}

	memcpy(m_lpszServer, lpszServer, strlen(lpszServer));

	return true;
}

bool Impersonator::StopImpersonation()
{
	if (*m_lpszServer == 0)
		return false;

	if (!m_objNetUse.Disconnect(m_lpszServer) == true)
	{
		memset(m_lpszServer, 0, MAX_PATH + 1);
		//::ErrorHandler("NetUse", "Disconnect", GetLastError());
		return false;
	}

	memset(m_lpszServer, 0, MAX_PATH + 1);
	return true;
}
