From e569991ba841802b12acb7dab34945dca805e9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 24 Jul 2012 20:46:21 -0400 Subject: [PATCH] libfreerdp-core: add support for loading server settings from registry --- libfreerdp-core/settings.c | 42 ++++++++++++++++++++++++++++++++-- server/Windows/wfreerdp.c | 4 ---- winpr/sspi/NTLM/ntlm.c | 6 ++++- winpr/sspi/NTLM/ntlm_compute.c | 10 ++++++++ winpr/utils/sam.c | 25 ++++++++++++++++---- 5 files changed, 76 insertions(+), 11 deletions(-) diff --git a/libfreerdp-core/settings.c b/libfreerdp-core/settings.c index 4540ed91c..30b6114a9 100644 --- a/libfreerdp-core/settings.c +++ b/libfreerdp-core/settings.c @@ -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; diff --git a/server/Windows/wfreerdp.c b/server/Windows/wfreerdp.c index 9d62f4957..f7ab60864 100644 --- a/server/Windows/wfreerdp.c +++ b/server/Windows/wfreerdp.c @@ -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; diff --git a/winpr/sspi/NTLM/ntlm.c b/winpr/sspi/NTLM/ntlm.c index 0577e5318..29bc7dba8 100644 --- a/winpr/sspi/NTLM/ntlm.c +++ b/winpr/sspi/NTLM/ntlm.c @@ -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); diff --git a/winpr/sspi/NTLM/ntlm_compute.c b/winpr/sspi/NTLM/ntlm_compute.c index 6f4b674d0..7823751f6 100644 --- a/winpr/sspi/NTLM/ntlm_compute.c +++ b/winpr/sspi/NTLM/ntlm_compute.c @@ -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, diff --git a/winpr/utils/sam.c b/winpr/utils/sam.c index f93ed0e3e..c8c3a751e 100644 --- a/winpr/utils/sam.c +++ b/winpr/utils/sam.c @@ -25,7 +25,11 @@ #include #include +#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';