mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Add DHCP support to windows password manager
This commit is contained in:
parent
d764bf245b
commit
a9bf3959ba
@ -12,6 +12,8 @@
|
||||
#include "ThreadUtil.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <IPHlpApi.h>
|
||||
#include <list>
|
||||
|
||||
namespace VMOps {
|
||||
|
||||
@ -35,6 +37,7 @@ public :
|
||||
|
||||
public :
|
||||
HERROR SetPassword(LPCTSTR lpszUserName, LPCTSTR lpszPassword);
|
||||
HERROR GetNextPasswordProvider(LPSTR lpszBuf, LPDWORD pdwLength);
|
||||
HERROR GetDefaultGateway(LPSTR lpszBuf, LPDWORD pdwLength);
|
||||
HERROR SimpleHttpGet(LPCTSTR lpszUrl, LPCTSTR lpszHeaders,
|
||||
LPVOID pOutputBuffer, DWORD dwBytesToRead, DWORD* pdwBytesRead);
|
||||
@ -44,6 +47,8 @@ public :
|
||||
|
||||
protected :
|
||||
CVMOpsStartupWatcher* m_pWatcher;
|
||||
|
||||
std::list<IP_ADDRESS_STRING> m_lstProviders;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -62,7 +67,7 @@ protected :
|
||||
virtual DWORD ThreadRun();
|
||||
|
||||
BOOL DoStartupConfig();
|
||||
BOOL GetDomRUrl(LPTSTR lpszUrl);
|
||||
BOOL GetPasswordProviderUrl(LPTSTR lpszUrl);
|
||||
|
||||
protected :
|
||||
CVMOpsServiceProvider* m_pProvider;
|
||||
|
||||
@ -14,9 +14,47 @@
|
||||
#include <iptypes.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <wininet.h>
|
||||
#include <list>
|
||||
|
||||
using namespace VMOps;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Helpers
|
||||
//
|
||||
bool IsAddressAlreadyInList(const IP_ADDRESS_STRING& addr, std::list<IP_ADDRESS_STRING>& listDhCPServers)
|
||||
{
|
||||
for(std::list<IP_ADDRESS_STRING>::iterator it = listDhCPServers.begin(); it != listDhCPServers.end(); it++)
|
||||
{
|
||||
if(strcmpi(addr.String, (*it).String) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GetDHCPServers(std::list<IP_ADDRESS_STRING>& listDhCPServers)
|
||||
{
|
||||
ULONG ulSize = 0;
|
||||
GetAdaptersInfo(NULL, &ulSize);
|
||||
|
||||
PIP_ADAPTER_INFO pHead = (PIP_ADAPTER_INFO)new BYTE[ulSize];
|
||||
PIP_ADAPTER_INFO pAdapterInfo = pHead;
|
||||
GetAdaptersInfo(pAdapterInfo, &ulSize);
|
||||
|
||||
while(pAdapterInfo->Next != NULL)
|
||||
{
|
||||
if(pAdapterInfo->DhcpEnabled && !IsAddressAlreadyInList(pAdapterInfo->DhcpServer.IpAddress, listDhCPServers))
|
||||
listDhCPServers.push_back(pAdapterInfo->DhcpServer.IpAddress);
|
||||
|
||||
pAdapterInfo = pAdapterInfo->Next;
|
||||
}
|
||||
|
||||
delete [](LPBYTE)pHead;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CVMOpsServiceProvider
|
||||
//
|
||||
CVMOpsServiceProvider::CVMOpsServiceProvider()
|
||||
{
|
||||
m_pWatcher = NULL;
|
||||
@ -86,6 +124,35 @@ HERROR CVMOpsServiceProvider::SetPassword(LPCTSTR lpszUserName, LPCTSTR lpszPass
|
||||
return HERROR_SUCCESS;
|
||||
}
|
||||
|
||||
HERROR CVMOpsServiceProvider::GetNextPasswordProvider(LPSTR lpszBuf, LPDWORD pdwLength)
|
||||
{
|
||||
if(m_lstProviders.size() == 0)
|
||||
{
|
||||
IP_ADDRESS_STRING addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
DWORD dwLength = sizeof(addr.String);
|
||||
GetDefaultGateway(addr.String, &dwLength);
|
||||
|
||||
if(addr.String[0] != 0)
|
||||
m_lstProviders.push_back(addr);
|
||||
|
||||
GetDHCPServers(m_lstProviders);
|
||||
}
|
||||
|
||||
if(m_lstProviders.size() > 0)
|
||||
{
|
||||
strcpy(lpszBuf, (*(m_lstProviders.begin())).String);
|
||||
m_lstProviders.pop_front();
|
||||
}
|
||||
else
|
||||
{
|
||||
lpszBuf[0] = 0;
|
||||
}
|
||||
|
||||
return HERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
HERROR CVMOpsServiceProvider::GetDefaultGateway(LPSTR lpszBuf, LPDWORD pdwLength)
|
||||
{
|
||||
_ASSERTE(pdwLength);
|
||||
|
||||
@ -74,13 +74,13 @@ DWORD CVMOpsStartupWatcher::ThreadRun()
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL CVMOpsStartupWatcher::GetDomRUrl(LPTSTR lpszUrl)
|
||||
BOOL CVMOpsStartupWatcher::GetPasswordProviderUrl(LPTSTR lpszUrl)
|
||||
{
|
||||
// asumming we have enough space in lpszUrl
|
||||
char achBuf[256];
|
||||
achBuf[0] = 0;
|
||||
DWORD dwLength = sizeof(achBuf);
|
||||
if(m_pProvider->GetDefaultGateway(achBuf, &dwLength) == HERROR_SUCCESS)
|
||||
if(m_pProvider->GetNextPasswordProvider(achBuf, &dwLength) == HERROR_SUCCESS)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
|
||||
@ -93,6 +93,7 @@ BOOL CVMOpsStartupWatcher::GetDomRUrl(LPTSTR lpszUrl)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
BOOL CVMOpsStartupWatcher::DoStartupConfig()
|
||||
{
|
||||
USES_CONVERSION;
|
||||
@ -107,7 +108,7 @@ BOOL CVMOpsStartupWatcher::DoStartupConfig()
|
||||
char achResult[256];
|
||||
|
||||
memset(achUrl, 0, sizeof(achUrl));
|
||||
GetDomRUrl(achUrl);
|
||||
GetPasswordProviderUrl(achUrl);
|
||||
|
||||
if(achUrl[0] != 0)
|
||||
{
|
||||
@ -120,7 +121,7 @@ BOOL CVMOpsStartupWatcher::DoStartupConfig()
|
||||
achResult, dwBytesToRead, &dwBytesRead) == HERROR_SUCCESS)
|
||||
{
|
||||
achResult[dwBytesRead] = 0;
|
||||
//Trim whitespace at tail
|
||||
// Trim whitespace at tail
|
||||
int nPos = strlen(achResult) - 1;
|
||||
while(nPos > 0)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user