libfreerdp-core: add support for loading server settings from registry

This commit is contained in:
Marc-André Moreau 2012-07-24 20:46:21 -04:00
parent 3d62beb17e
commit e569991ba8
5 changed files with 76 additions and 11 deletions

View File

@ -33,7 +33,7 @@
static const char client_dll[] = "C:\\Windows\\System32\\mstscax.dll";
void settings_load_hkey_local_machine(rdpSettings* settings)
void settings_client_load_hkey_local_machine(rdpSettings* settings)
{
HKEY hKey;
LONG status;
@ -41,7 +41,7 @@ void settings_load_hkey_local_machine(rdpSettings* settings)
DWORD dwSize;
DWORD dwValue;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Client"), 0, KEY_READ, &hKey);
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Client"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status != ERROR_SUCCESS)
return;
@ -76,6 +76,39 @@ void settings_load_hkey_local_machine(rdpSettings* settings)
RegCloseKey(hKey);
}
void settings_server_load_hkey_local_machine(rdpSettings* settings)
{
HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
DWORD dwValue;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status != ERROR_SUCCESS)
return;
if (RegQueryValueEx(hKey, _T("NlaSecurity"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
settings->nla_security = dwValue ? 1 : 0;
if (RegQueryValueEx(hKey, _T("TlsSecurity"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
settings->tls_security = dwValue ? 1 : 0;
if (RegQueryValueEx(hKey, _T("RdpSecurity"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
settings->rdp_security = dwValue ? 1 : 0;
RegCloseKey(hKey);
}
void settings_load_hkey_local_machine(rdpSettings* settings)
{
if (settings->server_mode)
settings_server_load_hkey_local_machine(settings);
else
settings_client_load_hkey_local_machine(settings);
}
rdpSettings* settings_new(void* instance)
{
rdpSettings* settings;
@ -86,6 +119,11 @@ rdpSettings* settings_new(void* instance)
{
settings->instance = instance;
/* Server instances are NULL */
if (!settings->instance)
settings->server_mode = true;
settings->width = 1024;
settings->height = 768;
settings->workarea = false;

View File

@ -167,10 +167,6 @@ static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
client->settings->cert_file = xstrdup("server.crt");
client->settings->privatekey_file = xstrdup("server.key");
client->settings->nla_security = true;
client->settings->tls_security = false;
client->settings->rdp_security = false;
client->PostConnect = wf_peer_post_connect;
client->Activate = wf_peer_activate;

View File

@ -154,7 +154,11 @@ SECURITY_STATUS SEC_ENTRY ntlm_AcquireCredentialsHandleW(SEC_WCHAR* pszPrincipal
credentials = sspi_CredentialsNew();
identity = (SEC_WINNT_AUTH_IDENTITY*) pAuthData;
CopyMemory(&(credentials->identity), identity, sizeof(SEC_WINNT_AUTH_IDENTITY));
if (identity)
CopyMemory(&(credentials->identity), identity, sizeof(SEC_WINNT_AUTH_IDENTITY));
else
ZeroMemory(&(credentials->identity), sizeof(SEC_WINNT_AUTH_IDENTITY));
sspi_SecureHandleSetLowerPointer(phCredential, (void*) credentials);
sspi_SecureHandleSetUpperPointer(phCredential, (void*) NTLM_PACKAGE_NAME);

View File

@ -233,6 +233,11 @@ void ntlm_fetch_ntlm_v2_hash(NTLM_CONTEXT* context, char* hash)
if (entry != NULL)
{
#ifdef WITH_DEBUG_NTLM
printf("NTLM Hash:\n");
winpr_HexDump(entry->NtHash, 16);
#endif
NTOWFv2FromHashW(entry->NtHash,
(LPWSTR) context->identity.User, context->identity.UserLength * 2,
(LPWSTR) context->identity.Domain, context->identity.DomainLength * 2,
@ -249,6 +254,11 @@ void ntlm_fetch_ntlm_v2_hash(NTLM_CONTEXT* context, char* hash)
if (entry != NULL)
{
#ifdef WITH_DEBUG_NTLM
printf("NTLM Hash:\n");
winpr_HexDump(entry->NtHash, 16);
#endif
NTOWFv2FromHashW(entry->NtHash,
(LPWSTR) context->identity.User, context->identity.UserLength * 2,
(LPWSTR) context->identity.Domain, context->identity.DomainLength * 2,

View File

@ -25,7 +25,11 @@
#include <winpr/sam.h>
#include <winpr/print.h>
#ifdef _WIN32
#define WINPR_SAM_FILE "C:\\SAM"
#else
#define WINPR_SAM_FILE "/etc/winpr/SAM"
#endif
WINPR_SAM* SamOpen(BOOL read_only)
{
@ -48,13 +52,17 @@ WINPR_SAM* SamOpen(BOOL read_only)
if (!sam->fp)
sam->fp = fopen(WINPR_SAM_FILE, "w+");
}
if (!(sam->fp))
printf("Could not open SAM file!\n");
}
return sam;
}
void SamLookupStart(WINPR_SAM* sam)
BOOL SamLookupStart(WINPR_SAM* sam)
{
size_t read_size;
long int file_size;
fseek(sam->fp, 0, SEEK_END);
@ -62,14 +70,23 @@ void SamLookupStart(WINPR_SAM* sam)
fseek(sam->fp, 0, SEEK_SET);
if (file_size < 1)
return;
return FALSE;
sam->buffer = (char*) malloc(file_size + 2);
if (fread(sam->buffer, file_size, 1, sam->fp) != 1)
read_size = fread(sam->buffer, file_size, 1, sam->fp);
if (!read_size)
{
if (!ferror(sam->fp))
read_size = file_size;
}
if (read_size < 1)
{
free(sam->buffer);
return;
sam->buffer = NULL;
return FALSE;
}
sam->buffer[file_size] = '\n';