Merge pull request #673 from FreeRDP/winpr

WinPR: time zone, registry and unicode
This commit is contained in:
Marc-André Moreau 2012-07-28 14:59:49 -07:00
commit f972326782
19 changed files with 1340 additions and 736 deletions

View File

@ -20,13 +20,6 @@
#ifndef WINPR_ASN1_H
#define WINPR_ASN1_H
#ifdef _WIN32
#include <msasn1.h>
#include <msber.h>
#else
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
@ -253,7 +246,7 @@ struct tagASN1module_t
const ASN1FreeFun_t* apfnFreeMemory;
const ASN1uint32_t* acbStructSize;
ASN1BerFunArr_t BER;
}
};
typedef struct tagASN1module_t* ASN1module_t;
struct ASN1encoding_s
@ -289,8 +282,8 @@ struct ASN1decoding_s
enum
{
ASN1FLAGS_NONE = 0x00000000L,
ASN1FLAGS_NOASSERT = 0x00001000L,
ASN1FLAGS_NONE = 0x00000000L,
ASN1FLAGS_NOASSERT = 0x00001000L,
};
enum
@ -350,7 +343,7 @@ enum tagASN1option_e
ASN1OPT_DEL_DECODED_BUFFER = 0x502,
ASN1OPT_GET_DECODED_BUFFER_SIZE = 0x601,
};
typedef enum ASN1option_e;
typedef enum tagASN1option_e ASN1option_e;
struct tagASN1optionparam_t
{
@ -377,7 +370,136 @@ WINPR_API ASN1error_e ASN1_GetEncoderOption(ASN1encoding_t pEncoderInfo, ASN1opt
WINPR_API ASN1error_e ASN1_SetDecoderOption(ASN1decoding_t pDecoderInfo, ASN1optionparam_t* pOptParam);
WINPR_API ASN1error_e ASN1_GetDecoderOption(ASN1decoding_t pDecoderInfo, ASN1optionparam_t* pOptParam);
#endif
WINPR_API void ASN1bitstring_free(ASN1bitstring_t* bitstring);
WINPR_API void ASN1octetstring_free(ASN1octetstring_t* octetstring);
WINPR_API void ASN1objectidentifier_free(ASN1objectidentifier_t* objectidentifier);
WINPR_API void ASN1charstring_free(ASN1charstring_t* charstring);
WINPR_API void ASN1char16string_free(ASN1char16string_t* char16string);
WINPR_API void ASN1char32string_free(ASN1char32string_t* char32string);
WINPR_API void ASN1ztcharstring_free(ASN1ztcharstring_t ztcharstring);
WINPR_API void ASN1ztchar16string_free(ASN1ztchar16string_t ztchar16string);
WINPR_API void ASN1ztchar32string_free(ASN1ztchar32string_t ztchar32string);
WINPR_API void ASN1open_free(ASN1open_t* open);
WINPR_API void ASN1utf8string_free(ASN1wstring_t* utf8string);
WINPR_API LPVOID ASN1DecAlloc(ASN1decoding_t dec, ASN1uint32_t size);
WINPR_API LPVOID ASN1DecRealloc(ASN1decoding_t dec, LPVOID ptr, ASN1uint32_t size);
WINPR_API void ASN1Free(LPVOID ptr);
WINPR_API ASN1error_e ASN1EncSetError(ASN1encoding_t enc, ASN1error_e err);
WINPR_API ASN1error_e ASN1DecSetError(ASN1decoding_t dec, ASN1error_e err);
WINPR_API ASN1uint32_t ASN1intx_uoctets(ASN1intx_t* intx);
WINPR_API void ASN1intx_free(ASN1intx_t* intx);
WINPR_API ASN1int32_t ASN1intx2int32(ASN1intx_t* intx);
WINPR_API ASN1uint32_t ASN1intx2uint32(ASN1intx_t* intx);
WINPR_API int ASN1intxisuint32(ASN1intx_t* intx);
WINPR_API void ASN1intx_setuint32(ASN1intx_t* dst, ASN1uint32_t val);
WINPR_API ASN1uint32_t ASN1uint32_uoctets(ASN1uint32_t val);
WINPR_API int ASN1intx_cmp(ASN1intx_t* intx1, ASN1intx_t* intx2);
WINPR_API int ASN1objectidentifier_cmp(ASN1objectidentifier_t* oid1, ASN1objectidentifier_t* oid2);
WINPR_API int ASN1objectidentifier2_cmp(ASN1objectidentifier2_t* oid1, ASN1objectidentifier2_t* oid2);
WINPR_API int ASN1bitstring_cmp(ASN1bitstring_t* str1, ASN1bitstring_t* str2, int length);
WINPR_API int ASN1octetstring_cmp(ASN1octetstring_t* str1, ASN1octetstring_t* str2);
WINPR_API int ASN1charstring_cmp(ASN1charstring_t* str1, ASN1charstring_t* str2);
WINPR_API int ASN1char16string_cmp(ASN1char16string_t* str1, ASN1char16string_t* str2);
WINPR_API int ASN1char32string_cmp(ASN1char32string_t* str1, ASN1char32string_t* str2);
WINPR_API int ASN1ztcharstring_cmp(ASN1ztcharstring_t str1, ASN1ztcharstring_t str2);
WINPR_API int ASN1ztchar16string_cmp(ASN1ztchar16string_t str1, ASN1ztchar16string_t str2);
WINPR_API int ASN1ztchar32string_cmp(ASN1ztchar32string_t str1, ASN1ztchar32string_t str2);
WINPR_API int ASN1open_cmp(ASN1open_t* open1, ASN1open_t* open2);
WINPR_API int ASN1generalizedtime_cmp(ASN1generalizedtime_t* t1, ASN1generalizedtime_t* t2);
WINPR_API int ASN1utctime_cmp(ASN1utctime_t* t1, ASN1utctime_t* t2);
WINPR_API int ASN1BEREncCharString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t len, ASN1char_t* val);
WINPR_API int ASN1DEREncCharString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t len, ASN1char_t* val);
WINPR_API int ASN1BEREncChar16String(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t len, ASN1char16_t* val);
WINPR_API int ASN1DEREncChar16String(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t len, ASN1char16_t* val);
WINPR_API int ASN1BEREncChar32String(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t len, ASN1char32_t* val);
WINPR_API int ASN1DEREncChar32String(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t len, ASN1char32_t* val);
WINPR_API int ASN1BEREncOctetString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t len, ASN1octet_t* val);
WINPR_API int ASN1DEREncOctetString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t len, ASN1octet_t* val);
WINPR_API int ASN1BEREncBitString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t bitlen, ASN1octet_t* val);
WINPR_API int ASN1DEREncBitString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t bitlen, ASN1octet_t* val);
WINPR_API int ASN1BEREncGeneralizedTime(ASN1encoding_t enc, ASN1uint32_t tag, ASN1generalizedtime_t* val);
WINPR_API int ASN1DEREncGeneralizedTime(ASN1encoding_t enc, ASN1uint32_t tag, ASN1generalizedtime_t* val);
WINPR_API int ASN1BEREncS32(ASN1encoding_t enc, ASN1uint32_t tag, ASN1int32_t val);
WINPR_API int ASN1BEREncSX(ASN1encoding_t enc, ASN1uint32_t tag, ASN1intx_t* val);
WINPR_API int ASN1BEREncZeroMultibyteString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1ztcharstring_t val);
WINPR_API int ASN1DEREncZeroMultibyteString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1ztcharstring_t val);
WINPR_API int ASN1BEREncMultibyteString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1charstring_t* val);
WINPR_API int ASN1DEREncMultibyteString(ASN1encoding_t enc, ASN1uint32_t tag, ASN1charstring_t* val);
WINPR_API int ASN1BEREncNull(ASN1encoding_t enc, ASN1uint32_t tag);
WINPR_API int ASN1BEREncObjectIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, ASN1objectidentifier_t* val);
WINPR_API int ASN1BEREncObjectIdentifier2(ASN1encoding_t enc, ASN1uint32_t tag, ASN1objectidentifier2_t* val);
WINPR_API int ASN1BEREncRemoveZeroBits(ASN1uint32_t* nbits,ASN1octet_t* val);
WINPR_API int ASN1BEREncRemoveZeroBits2(ASN1uint32_t* nbits,ASN1octet_t* val,ASN1uint32_t minlen);
WINPR_API int ASN1BEREncUTCTime(ASN1encoding_t enc, ASN1uint32_t tag, ASN1utctime_t* val);
WINPR_API int ASN1DEREncUTCTime(ASN1encoding_t enc, ASN1uint32_t tag, ASN1utctime_t* val);
WINPR_API int ASN1BEREncFlush(ASN1encoding_t enc);
WINPR_API int ASN1BEREncOpenType(ASN1encoding_t enc, ASN1open_t* val);
WINPR_API int ASN1BERDecExplicitTag(ASN1decoding_t dec, ASN1uint32_t tag, ASN1decoding_t* dd, ASN1octet_t* *ppBufEnd);
WINPR_API int ASN1BERDecEndOfContents(ASN1decoding_t dec, ASN1decoding_t dd, ASN1octet_t* pBufEnd);
WINPR_API int ASN1BERDecOctetString(ASN1decoding_t dec, ASN1uint32_t tag, ASN1octetstring_t* val);
WINPR_API int ASN1BERDecOctetString2(ASN1decoding_t dec, ASN1uint32_t tag, ASN1octetstring_t* val);
WINPR_API int ASN1BERDecBitString(ASN1decoding_t dec, ASN1uint32_t tag, ASN1bitstring_t* val);
WINPR_API int ASN1BERDecBitString2(ASN1decoding_t dec, ASN1uint32_t tag, ASN1bitstring_t* val);
WINPR_API int ASN1BERDecChar16String(ASN1decoding_t dec, ASN1uint32_t tag, ASN1char16string_t* val);
WINPR_API int ASN1BERDecChar32String(ASN1decoding_t dec, ASN1uint32_t tag, ASN1char32string_t* val);
WINPR_API int ASN1BERDecCharString(ASN1decoding_t dec, ASN1uint32_t tag, ASN1charstring_t* val);
WINPR_API int ASN1BERDecGeneralizedTime(ASN1decoding_t dec, ASN1uint32_t tag, ASN1generalizedtime_t* val);
WINPR_API int ASN1BERDecZeroMultibyteString(ASN1decoding_t dec, ASN1uint32_t tag, ASN1ztcharstring_t* val);
WINPR_API int ASN1BERDecMultibyteString(ASN1decoding_t dec, ASN1uint32_t tag, ASN1charstring_t* val);
WINPR_API int ASN1BERDecNull(ASN1decoding_t dec, ASN1uint32_t tag);
WINPR_API int ASN1BERDecObjectIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, ASN1objectidentifier_t* val);
WINPR_API int ASN1BERDecObjectIdentifier2(ASN1decoding_t dec, ASN1uint32_t tag, ASN1objectidentifier2_t* val);
WINPR_API int ASN1BERDecS8Val(ASN1decoding_t dec, ASN1uint32_t tag, ASN1int8_t* val);
WINPR_API int ASN1BERDecS16Val(ASN1decoding_t dec, ASN1uint32_t tag, ASN1int16_t* val);
WINPR_API int ASN1BERDecS32Val(ASN1decoding_t dec, ASN1uint32_t tag, ASN1int32_t* val);
WINPR_API int ASN1BERDecSXVal(ASN1decoding_t dec, ASN1uint32_t tag, ASN1intx_t* val);
WINPR_API int ASN1BERDecU8Val(ASN1decoding_t dec, ASN1uint32_t tag, ASN1uint8_t* val);
WINPR_API int ASN1BERDecU16Val(ASN1decoding_t dec, ASN1uint32_t tag, ASN1uint16_t* val);
WINPR_API int ASN1BERDecU32Val(ASN1decoding_t dec, ASN1uint32_t tag, ASN1uint32_t* val);
WINPR_API int ASN1BERDecUTCTime(ASN1decoding_t dec, ASN1uint32_t tag, ASN1utctime_t* val);
WINPR_API int ASN1BERDecZeroCharString(ASN1decoding_t dec, ASN1uint32_t tag, ASN1ztcharstring_t* val);
WINPR_API int ASN1BERDecZeroChar16String(ASN1decoding_t dec, ASN1uint32_t tag, ASN1ztchar16string_t* val);
WINPR_API int ASN1BERDecZeroChar32String(ASN1decoding_t dec, ASN1uint32_t tag, ASN1ztchar32string_t* val);
WINPR_API int ASN1BERDecSkip(ASN1decoding_t dec);
WINPR_API int ASN1BERDecFlush(ASN1decoding_t dec);
WINPR_API int ASN1BERDecOpenType(ASN1decoding_t dec, ASN1open_t* val);
WINPR_API int ASN1BERDecOpenType2(ASN1decoding_t dec, ASN1open_t* val);
WINPR_API int ASN1BEREncCheck(ASN1encoding_t enc, ASN1uint32_t noctets);
WINPR_API int ASN1BEREncTag(ASN1encoding_t enc, ASN1uint32_t tag);
WINPR_API int ASN1BEREncExplicitTag(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t* pnLenOff);
WINPR_API int ASN1BEREncEndOfContents(ASN1encoding_t enc, ASN1uint32_t nLenOff);
WINPR_API int ASN1BEREncLength(ASN1encoding_t enc, ASN1uint32_t len);
WINPR_API int ASN1BERDecCheck(ASN1decoding_t dec, ASN1uint32_t len);
WINPR_API int ASN1BERDecTag(ASN1decoding_t dec, ASN1uint32_t tag, ASN1uint32_t* constructed);
WINPR_API int ASN1BERDecLength(ASN1decoding_t dec, ASN1uint32_t* len, ASN1uint32_t* infinite);
WINPR_API int ASN1BERDecNotEndOfContents(ASN1decoding_t dec, ASN1octet_t* pBufEnd);
WINPR_API int ASN1BERDecPeekTag(ASN1decoding_t dec, ASN1uint32_t* tag);
WINPR_API int ASN1BEREncU32(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t val);
WINPR_API int ASN1BEREncBool(ASN1encoding_t enc, ASN1uint32_t tag, ASN1bool_t val);
WINPR_API int ASN1BERDecBool(ASN1decoding_t dec, ASN1uint32_t tag, ASN1bool_t* val);
WINPR_API int ASN1BEREncEoid(ASN1encoding_t enc, ASN1uint32_t tag, ASN1encodedOID_t* val);
WINPR_API int ASN1BERDecEoid(ASN1decoding_t dec, ASN1uint32_t tag, ASN1encodedOID_t* val);
WINPR_API int ASN1BERDotVal2Eoid(ASN1encoding_t enc, char* pszDotVal, ASN1encodedOID_t* pOut);
WINPR_API int ASN1BEREoid2DotVal(ASN1decoding_t dec, ASN1encodedOID_t* pIn, char** ppszDotVal);
WINPR_API void ASN1BEREoid_free(ASN1encodedOID_t* val);
WINPR_API int ASN1BEREncUTF8String(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t length, WCHAR* value);
WINPR_API int ASN1DEREncUTF8String(ASN1encoding_t enc, ASN1uint32_t tag, ASN1uint32_t length, WCHAR* value);
WINPR_API int ASN1BERDecUTF8String(ASN1decoding_t dec, ASN1uint32_t tag, ASN1wstring_t* val);
WINPR_API int ASN1DEREncBeginBlk(ASN1encoding_t enc, ASN1blocktype_e eBlkType, void** ppBlk);
WINPR_API int ASN1DEREncNewBlkElement(void* pBlk, ASN1encoding_t* enc2);
WINPR_API int ASN1DEREncFlushBlkElement(void* pBlk);
WINPR_API int ASN1DEREncEndBlk(void* pBlk);
#endif /* WINPR_ASN1_H */

View File

@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/winpr.h>

View File

@ -35,6 +35,10 @@
#define ERROR_SUCCESS 0
#endif
#ifndef ERROR_FILE_NOT_FOUND
#define ERROR_FILE_NOT_FOUND 2
#endif
#define DELETE 0x00010000
#define READ_CONTROL 0x00020000
#define WRITE_DAC 0x00040000

View File

@ -47,6 +47,8 @@
WINPR_API char* _strdup(const char* strSource);
WINPR_API WCHAR* _wcsdup(const WCHAR* strSource);
WINPR_API int _stricmp(const char* string1, const char* string2);
WINPR_API LPSTR CharUpperA(LPSTR lpsz);
WINPR_API LPWSTR CharUpperW(LPWSTR lpsz);

View File

@ -673,7 +673,7 @@ boolean WTSVirtualChannelWrite(
stream_seek_uint8(s);
cbChId = wts_write_variable_uint(s, channel->channel_id);
if (first && Length > stream_get_left(s))
if (first && (Length > (uint32) stream_get_left(s)))
{
cbLen = wts_write_variable_uint(s, Length);
item->buffer[0] = (DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId;

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

@ -106,6 +106,9 @@ boolean rdp_read_client_time_zone(STREAM* s, rdpSettings* settings)
void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings)
{
uint32 bias;
sint32 sbias;
uint32 bias2c;
size_t length;
uint8* standardName;
uint8* daylightName;
@ -128,21 +131,40 @@ void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings)
if (daylightNameLength > 62)
daylightNameLength = 62;
stream_write_uint32(s, clientTimeZone->bias); /* Bias */
/* UTC = LocalTime + Bias <-> Bias = UTC - LocalTime */
bias = 1440 - clientTimeZone->bias;
stream_write_uint32(s, bias); /* Bias */
/* standardName (64 bytes) */
stream_write(s, standardName, standardNameLength);
stream_write_zero(s, 64 - standardNameLength);
rdp_write_system_time(s, &clientTimeZone->standardDate); /* StandardDate */
stream_write_uint32(s, clientTimeZone->standardBias); /* StandardBias */
sbias = clientTimeZone->standardBias - clientTimeZone->bias;
if (sbias < 0)
bias2c = (uint32) sbias;
else
bias2c = ~((uint32) sbias) + 1;
stream_write_uint32(s, bias2c); /* StandardBias */
/* daylightName (64 bytes) */
stream_write(s, daylightName, daylightNameLength);
stream_write_zero(s, 64 - daylightNameLength);
rdp_write_system_time(s, &clientTimeZone->daylightDate); /* DaylightDate */
stream_write_uint32(s, clientTimeZone->daylightBias); /* DaylightBias */
sbias = clientTimeZone->daylightBias - clientTimeZone->bias;
if (sbias < 0)
bias2c = (uint32) sbias;
else
bias2c = ~((uint32) sbias) + 1;
stream_write_uint32(s, bias2c); /* DaylightBias */
xfree(standardName);
xfree(daylightName);

View File

@ -289,7 +289,7 @@ int credssp_client_authenticate(rdpCredssp* credssp)
#ifdef WITH_DEBUG_CREDSSP
printf("Sending Authentication Token\n");
winpr_HexDump(credssp->negoToken.pvBuffer, credssp->negoToken.cbBuffer);
//winpr_HexDump(credssp->negoToken.pvBuffer, credssp->negoToken.cbBuffer);
#endif
credssp_send(credssp);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/**
/**
* FreeRDP: A Remote Desktop Protocol Client
* Time Zone Redirection Table Generator
*
@ -24,224 +24,232 @@ using System.Collections.ObjectModel;
namespace TimeZones
{
struct SYSTEM_TIME_ENTRY
{
public UInt16 wYear;
public UInt16 wMonth;
public UInt16 wDayOfWeek;
public UInt16 wDay;
public UInt16 wHour;
public UInt16 wMinute;
public UInt16 wSecond;
public UInt16 wMilliseconds;
};
struct SYSTEM_TIME_ENTRY
{
public UInt16 wYear;
public UInt16 wMonth;
public UInt16 wDayOfWeek;
public UInt16 wDay;
public UInt16 wHour;
public UInt16 wMinute;
public UInt16 wSecond;
public UInt16 wMilliseconds;
};
struct TIME_ZONE_RULE_ENTRY
{
public long TicksStart;
public long TicksEnd;
public Int32 DaylightDelta;
public SYSTEM_TIME_ENTRY StandardDate;
public SYSTEM_TIME_ENTRY DaylightDate;
};
struct TIME_ZONE_RULE_ENTRY
{
public long TicksStart;
public long TicksEnd;
public Int32 DaylightDelta;
public SYSTEM_TIME_ENTRY StandardDate;
public SYSTEM_TIME_ENTRY DaylightDate;
};
struct TIME_ZONE_ENTRY
{
public string Id;
public UInt32 Bias;
public bool SupportsDST;
public string DisplayName;
public string StandardName;
public string DaylightName;
public string RuleTable;
public UInt32 RuleTableCount;
};
struct TIME_ZONE_ENTRY
{
public string Id;
public UInt32 Bias;
public bool SupportsDST;
public string DisplayName;
public string StandardName;
public string DaylightName;
public string RuleTable;
public UInt32 RuleTableCount;
};
class TimeZones
{
static void Main(string[] args)
{
int i;
UInt32 index;
const string file = @"TimeZones.txt";
TimeZoneInfo.AdjustmentRule[] rules;
StreamWriter stream = new StreamWriter(file, false);
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
class TimeZones
{
static void Main(string[] args)
{
int i;
UInt32 index;
const string file = @"TimeZones.txt";
TimeZoneInfo.AdjustmentRule[] rules;
StreamWriter stream = new StreamWriter(file, false);
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
stream.WriteLine();
stream.WriteLine();
stream.WriteLine("struct _SYSTEM_TIME_ENTRY");
stream.WriteLine("{");
stream.WriteLine("\tuint16 wYear;");
stream.WriteLine("\tuint16 wMonth;");
stream.WriteLine("\tuint16 wDayOfWeek;");
stream.WriteLine("\tuint16 wDay;");
stream.WriteLine("\tuint16 wHour;");
stream.WriteLine("\tuint16 wMinute;");
stream.WriteLine("\tuint16 wSecond;");
stream.WriteLine("\tuint16 wMilliseconds;");
stream.WriteLine("};");
stream.WriteLine("typedef struct _SYSTEM_TIME_ENTRY SYSTEM_TIME_ENTRY;");
stream.WriteLine();
stream.WriteLine("struct _SYSTEM_TIME_ENTRY");
stream.WriteLine("{");
stream.WriteLine("\tuint16 wYear;");
stream.WriteLine("\tuint16 wMonth;");
stream.WriteLine("\tuint16 wDayOfWeek;");
stream.WriteLine("\tuint16 wDay;");
stream.WriteLine("\tuint16 wHour;");
stream.WriteLine("\tuint16 wMinute;");
stream.WriteLine("\tuint16 wSecond;");
stream.WriteLine("\tuint16 wMilliseconds;");
stream.WriteLine("};");
stream.WriteLine("typedef struct _SYSTEM_TIME_ENTRY SYSTEM_TIME_ENTRY;");
stream.WriteLine();
stream.WriteLine("struct _TIME_ZONE_RULE_ENTRY");
stream.WriteLine("{");
stream.WriteLine("\tuint64 TicksStart;");
stream.WriteLine("\tuint64 TicksEnd;");
stream.WriteLine("\tsint32 DaylightDelta;");
stream.WriteLine("\tSYSTEM_TIME_ENTRY StandardDate;");
stream.WriteLine("\tSYSTEM_TIME_ENTRY DaylightDate;");
stream.WriteLine("};");
stream.WriteLine("typedef struct _TIME_ZONE_RULE_ENTRY TIME_ZONE_RULE_ENTRY;");
stream.WriteLine();
stream.WriteLine("struct _TIME_ZONE_RULE_ENTRY");
stream.WriteLine("{");
stream.WriteLine("\tuint64 TicksStart;");
stream.WriteLine("\tuint64 TicksEnd;");
stream.WriteLine("\tsint32 DaylightDelta;");
stream.WriteLine("\tSYSTEM_TIME_ENTRY StandardDate;");
stream.WriteLine("\tSYSTEM_TIME_ENTRY DaylightDate;");
stream.WriteLine("};");
stream.WriteLine("typedef struct _TIME_ZONE_RULE_ENTRY TIME_ZONE_RULE_ENTRY;");
stream.WriteLine();
stream.WriteLine("struct _TIME_ZONE_ENTRY");
stream.WriteLine("{");
stream.WriteLine("\tconst char* Id;");
stream.WriteLine("\tuint32 Bias;");
stream.WriteLine("\tboolean SupportsDST;");
stream.WriteLine("\tconst char* DisplayName;");
stream.WriteLine("\tconst char* StandardName;");
stream.WriteLine("\tconst char* DaylightName;");
stream.WriteLine("\tTIME_ZONE_RULE_ENTRY* RuleTable;");
stream.WriteLine("\tuint32 RuleTableCount;");
stream.WriteLine("};");
stream.WriteLine("typedef struct _TIME_ZONE_ENTRY TIME_ZONE_ENTRY;");
stream.WriteLine();
stream.WriteLine("struct _TIME_ZONE_ENTRY");
stream.WriteLine("{");
stream.WriteLine("\tconst char* Id;");
stream.WriteLine("\tuint32 Bias;");
stream.WriteLine("\tboolean SupportsDST;");
stream.WriteLine("\tconst char* DisplayName;");
stream.WriteLine("\tconst char* StandardName;");
stream.WriteLine("\tconst char* DaylightName;");
stream.WriteLine("\tTIME_ZONE_RULE_ENTRY* RuleTable;");
stream.WriteLine("\tuint32 RuleTableCount;");
stream.WriteLine("};");
stream.WriteLine("typedef struct _TIME_ZONE_ENTRY TIME_ZONE_ENTRY;");
stream.WriteLine();
index = 0;
index = 0;
foreach (TimeZoneInfo timeZone in timeZones)
{
rules = timeZone.GetAdjustmentRules();
foreach (TimeZoneInfo timeZone in timeZones)
{
rules = timeZone.GetAdjustmentRules();
if ((!timeZone.SupportsDaylightSavingTime) || (rules.Length < 1))
{
index++;
continue;
}
if ((!timeZone.SupportsDaylightSavingTime) || (rules.Length < 1))
{
index++;
continue;
}
stream.WriteLine("static const TIME_ZONE_RULE_ENTRY TimeZoneRuleTable_{0}[] =", index);
stream.WriteLine("{");
stream.WriteLine("static const TIME_ZONE_RULE_ENTRY TimeZoneRuleTable_{0}[] =", index);
stream.WriteLine("{");
i = 0;
foreach (TimeZoneInfo.AdjustmentRule rule in rules)
{
DateTime time;
TIME_ZONE_RULE_ENTRY tzr;
TimeZoneInfo.TransitionTime transition;
i = 0;
foreach (TimeZoneInfo.AdjustmentRule rule in rules)
{
DateTime time;
TIME_ZONE_RULE_ENTRY tzr;
TimeZoneInfo.TransitionTime transition;
tzr.TicksStart = rule.DateEnd.ToUniversalTime().Ticks;
tzr.TicksEnd = rule.DateStart.ToUniversalTime().Ticks;
tzr.DaylightDelta = (Int32)rule.DaylightDelta.TotalMinutes;
tzr.TicksStart = rule.DateEnd.ToUniversalTime().Ticks;
tzr.TicksEnd = rule.DateStart.ToUniversalTime().Ticks;
tzr.DaylightDelta = (Int32)rule.DaylightDelta.TotalMinutes;
transition = rule.DaylightTransitionEnd;
time = transition.TimeOfDay;
transition = rule.DaylightTransitionEnd;
time = transition.TimeOfDay;
tzr.StandardDate.wYear = (UInt16)0;
tzr.StandardDate.wMonth = (UInt16)transition.Month;
tzr.StandardDate.wDayOfWeek = (UInt16)transition.DayOfWeek;
tzr.StandardDate.wDay = (UInt16)transition.Day;
tzr.StandardDate.wHour = (UInt16)time.Hour;
tzr.StandardDate.wMinute = (UInt16)time.Minute;
tzr.StandardDate.wSecond = (UInt16)time.Second;
tzr.StandardDate.wMilliseconds = (UInt16)time.Millisecond;
tzr.StandardDate.wYear = (UInt16)0;
tzr.StandardDate.wMonth = (UInt16)transition.Month;
tzr.StandardDate.wDayOfWeek = (UInt16)transition.DayOfWeek;
tzr.StandardDate.wDay = (UInt16)transition.Day;
tzr.StandardDate.wHour = (UInt16)time.Hour;
tzr.StandardDate.wMinute = (UInt16)time.Minute;
tzr.StandardDate.wSecond = (UInt16)time.Second;
tzr.StandardDate.wMilliseconds = (UInt16)time.Millisecond;
transition = rule.DaylightTransitionStart;
time = transition.TimeOfDay;
transition = rule.DaylightTransitionStart;
time = transition.TimeOfDay;
tzr.DaylightDate.wYear = (UInt16)0;
tzr.DaylightDate.wMonth = (UInt16)transition.Month;
tzr.DaylightDate.wDayOfWeek = (UInt16)transition.DayOfWeek;
tzr.DaylightDate.wDay = (UInt16)transition.Day;
tzr.DaylightDate.wHour = (UInt16)time.Hour;
tzr.DaylightDate.wMinute = (UInt16)time.Minute;
tzr.DaylightDate.wSecond = (UInt16)time.Second;
tzr.DaylightDate.wMilliseconds = (UInt16)time.Millisecond;
tzr.DaylightDate.wYear = (UInt16)0;
tzr.DaylightDate.wMonth = (UInt16)transition.Month;
tzr.DaylightDate.wDayOfWeek = (UInt16)transition.DayOfWeek;
tzr.DaylightDate.wDay = (UInt16)transition.Day;
tzr.DaylightDate.wHour = (UInt16)time.Hour;
tzr.DaylightDate.wMinute = (UInt16)time.Minute;
tzr.DaylightDate.wSecond = (UInt16)time.Second;
tzr.DaylightDate.wMilliseconds = (UInt16)time.Millisecond;
stream.Write("\t{");
stream.Write(" {0}ULL, {1}ULL, {2},", tzr.TicksStart, tzr.TicksEnd, tzr.DaylightDelta);
stream.Write("\t{");
stream.Write(" {0}ULL, {1}ULL, {2},", tzr.TicksStart, tzr.TicksEnd, tzr.DaylightDelta);
stream.Write(" { ");
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}",
tzr.StandardDate.wYear, tzr.StandardDate.wMonth, tzr.StandardDate.wDayOfWeek,
tzr.StandardDate.wDay, tzr.StandardDate.wHour, tzr.StandardDate.wMinute,
tzr.StandardDate.wSecond, tzr.StandardDate.wMilliseconds);
stream.Write(" }, ");
stream.Write(" { ");
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}",
tzr.StandardDate.wYear, tzr.StandardDate.wMonth, tzr.StandardDate.wDayOfWeek,
tzr.StandardDate.wDay, tzr.StandardDate.wHour, tzr.StandardDate.wMinute,
tzr.StandardDate.wSecond, tzr.StandardDate.wMilliseconds);
stream.Write(" }, ");
stream.Write("{ ");
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}",
tzr.DaylightDate.wYear, tzr.DaylightDate.wMonth, tzr.DaylightDate.wDayOfWeek,
tzr.DaylightDate.wDay, tzr.DaylightDate.wHour, tzr.DaylightDate.wMinute,
tzr.DaylightDate.wSecond, tzr.DaylightDate.wMilliseconds);
stream.Write(" },");
stream.Write("{ ");
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}",
tzr.DaylightDate.wYear, tzr.DaylightDate.wMonth, tzr.DaylightDate.wDayOfWeek,
tzr.DaylightDate.wDay, tzr.DaylightDate.wHour, tzr.DaylightDate.wMinute,
tzr.DaylightDate.wSecond, tzr.DaylightDate.wMilliseconds);
stream.Write(" },");
if (++i < rules.Length)
stream.WriteLine(" },");
else
stream.WriteLine(" }");
}
if (++i < rules.Length)
stream.WriteLine(" },");
else
stream.WriteLine(" }");
}
stream.WriteLine("};");
stream.WriteLine();
index++;
}
stream.WriteLine("};");
stream.WriteLine();
index++;
}
index = 0;
stream.WriteLine("static const TIME_ZONE_ENTRY TimeZoneTable[] =");
stream.WriteLine("{");
index = 0;
stream.WriteLine("static const TIME_ZONE_ENTRY TimeZoneTable[] =");
stream.WriteLine("{");
foreach (TimeZoneInfo timeZone in timeZones)
{
TIME_ZONE_ENTRY tz;
TimeSpan offset = timeZone.BaseUtcOffset;
foreach (TimeZoneInfo timeZone in timeZones)
{
Int32 sbias;
TIME_ZONE_ENTRY tz;
TimeSpan offset = timeZone.BaseUtcOffset;
rules = timeZone.GetAdjustmentRules();
rules = timeZone.GetAdjustmentRules();
tz.Id = timeZone.Id;
tz.Id = timeZone.Id;
if (offset.Hours >= 0)
tz.Bias = (UInt32)((offset.Hours * 60) + offset.Minutes);
else
tz.Bias = (UInt32)(((-1 * offset.Hours) * 60) + offset.Minutes + 720);
if (offset.Hours >= 0)
{
sbias = (offset.Hours * 60) + offset.Minutes;
tz.Bias = (UInt32) sbias;
}
else
{
sbias = (offset.Hours * 60) + offset.Minutes;
tz.Bias = (UInt32) (1440 + sbias);
}
tz.SupportsDST = timeZone.SupportsDaylightSavingTime;
tz.SupportsDST = timeZone.SupportsDaylightSavingTime;
tz.DisplayName = timeZone.DisplayName;
tz.StandardName = timeZone.StandardName;
tz.DaylightName = timeZone.DaylightName;
tz.DisplayName = timeZone.DisplayName;
tz.StandardName = timeZone.StandardName;
tz.DaylightName = timeZone.DaylightName;
if ((!tz.SupportsDST) || (rules.Length < 1))
{
tz.RuleTableCount = 0;
tz.RuleTable = "NULL";
}
else
{
tz.RuleTableCount = (UInt32)rules.Length;
tz.RuleTable = "&TimeZoneRuleTable_" + index;
tz.RuleTable = "(TIME_ZONE_RULE_ENTRY*) &TimeZoneRuleTable_" + index;
}
if ((!tz.SupportsDST) || (rules.Length < 1))
{
tz.RuleTableCount = 0;
tz.RuleTable = "NULL";
}
else
{
tz.RuleTableCount = (UInt32)rules.Length;
tz.RuleTable = "&TimeZoneRuleTable_" + index;
tz.RuleTable = "(TIME_ZONE_RULE_ENTRY*) &TimeZoneRuleTable_" + index;
}
stream.WriteLine("\t{");
stream.WriteLine("\t{");
stream.WriteLine("\t\t\"{0}\", {1}, {2}, \"{0}\",",
tz.Id, tz.Bias, tz.SupportsDST ? "true" : "false", tz.DisplayName);
stream.WriteLine("\t\t\"{0}\", {1}, {2}, \"{3}\",",
tz.Id, tz.Bias, tz.SupportsDST ? "true" : "false", tz.DisplayName);
stream.WriteLine("\t\t\"{0}\", \"{0}\",", tz.StandardName, tz.DaylightName);
stream.WriteLine("\t\t{0}, {1}", tz.RuleTable, tz.RuleTableCount);
stream.WriteLine("\t\t\"{0}\", \"{1}\",", tz.StandardName, tz.DaylightName);
stream.WriteLine("\t\t{0}, {1}", tz.RuleTable, tz.RuleTableCount);
index++;
index++;
if ((int) index < timeZones.Count)
stream.WriteLine("\t},");
else
stream.WriteLine("\t}");
}
stream.WriteLine("};");
stream.WriteLine();
if ((int)index < timeZones.Count)
stream.WriteLine("\t},");
else
stream.WriteLine("\t}");
}
stream.WriteLine("};");
stream.WriteLine();
stream.Close();
}
}
stream.Close();
}
}
}

View File

@ -22,6 +22,7 @@
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
#include <freerdp/constants.h>
#include <freerdp/utils/sleep.h>
@ -50,6 +51,7 @@ void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)
{
if (context)
{
}
}
@ -167,10 +169,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;
@ -248,6 +246,11 @@ static void wf_server_main_loop(freerdp_listener* instance)
int main(int argc, char* argv[])
{
HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
DWORD dwValue;
int port = 3389;
WSADATA wsa_data;
freerdp_listener* instance;
@ -261,6 +264,16 @@ int main(int argc, char* argv[])
g_done_event = CreateEvent(0, 1, 0, 0);
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status == ERROR_SUCCESS)
{
if (RegQueryValueEx(hKey, _T("DefaultPort"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
port = dwValue;
}
RegCloseKey(hKey);
if (argc == 2)
port = atoi(argv[1]);

View File

@ -25,6 +25,7 @@ add_subdirectory(synch)
add_subdirectory(sysinfo)
add_subdirectory(bcrypt)
add_subdirectory(dsparse)
add_subdirectory(asn1)
add_subdirectory(rpc)
add_subdirectory(sspicli)
add_subdirectory(sspi)

View File

@ -19,9 +19,284 @@
#include <winpr/asn1.h>
#include <winpr/crt.h>
#ifndef _WIN32
ASN1module_t ASN1_CreateModule(ASN1uint32_t nVersion, ASN1encodingrule_e eRule,
ASN1uint32_t dwFlags, ASN1uint32_t cPDU, const ASN1GenericFun_t apfnEncoder[],
const ASN1GenericFun_t apfnDecoder[], const ASN1FreeFun_t apfnFreeMemory[],
const ASN1uint32_t acbStructSize[], ASN1magic_t nModuleName)
{
ASN1module_t module = NULL;
if (!((apfnEncoder) && (apfnDecoder) && (apfnFreeMemory) && (acbStructSize)))
return NULL;
module = (ASN1module_t) malloc(sizeof(struct tagASN1module_t));
ZeroMemory(module, sizeof(struct tagASN1module_t));
if (module)
{
module->nModuleName = nModuleName;
module->dwFlags = dwFlags;
module->eRule = eRule;
module->cPDUs = cPDU;
module->apfnFreeMemory = apfnFreeMemory;
module->acbStructSize = acbStructSize;
if (eRule & ASN1_BER_RULE)
{
module->BER.apfnEncoder = (const ASN1BerEncFun_t*) apfnEncoder;
module->BER.apfnDecoder = (const ASN1BerDecFun_t*) apfnDecoder;
}
}
return module;
}
void ASN1_CloseModule(ASN1module_t pModule)
{
if (!pModule)
free(pModule);
}
ASN1error_e ASN1_CreateEncoder(ASN1module_t pModule, ASN1encoding_t* ppEncoderInfo,
ASN1octet_t* pbBuf, ASN1uint32_t cbBufSize, ASN1encoding_t pParent)
{
ASN1error_e status;
ASN1encoding_t encoder;
ASN1encodingrule_e rule;
if (pModule && ppEncoderInfo)
{
*ppEncoderInfo = 0;
encoder = (ASN1encoding_t) malloc(sizeof(struct ASN1encoding_s));
if (encoder)
{
ZeroMemory(encoder, sizeof(struct ASN1encoding_s));
encoder->magic = 0x44434E45;
encoder->err = 0;
encoder->dwFlags = pModule->dwFlags;
encoder->module = pModule;
if (pbBuf && cbBufSize)
{
encoder->dwFlags |= ASN1ENCODE_SETBUFFER;
encoder->buf = pbBuf;
encoder->pos = pbBuf;
encoder->size = cbBufSize;
}
if (pParent)
{
encoder[1].magic = (ASN1magic_t) pParent;
rule = pParent->eRule;
}
else
{
encoder[1].magic = (ASN1magic_t) encoder;
rule = pModule->eRule;
}
encoder->eRule = rule;
if (encoder->dwFlags & ASN1ENCODE_SETBUFFER)
goto LABEL_SET_BUFFER;
if (!pParent)
{
LABEL_ENCODER_COMPLETE:
*ppEncoderInfo = encoder;
return 0;
}
if (rule & ASN1_BER_RULE)
{
//if (ASN1BEREncCheck(encoder, 1))
{
*encoder->buf = 0;
LABEL_SET_BUFFER:
if (pParent)
pParent[1].version = (ASN1uint32_t) encoder;
goto LABEL_ENCODER_COMPLETE;
}
status = ASN1_ERR_MEMORY;
}
else
{
status = ASN1_ERR_RULE;
}
free(encoder);
}
else
{
status = ASN1_ERR_MEMORY;
}
}
else
{
status = ASN1_ERR_BADARGS;
}
return status;
}
ASN1error_e ASN1_Encode(ASN1encoding_t pEncoderInfo, void* pDataStruct, ASN1uint32_t nPduNum,
ASN1uint32_t dwFlags, ASN1octet_t* pbBuf, ASN1uint32_t cbBufSize)
{
int flags;
ASN1error_e status;
ASN1module_t module;
ASN1BerEncFun_t pfnEncoder;
if (!pEncoderInfo)
return ASN1_ERR_BADARGS;
ASN1EncSetError(pEncoderInfo, ASN1_SUCCESS);
if (dwFlags & 8)
{
pEncoderInfo->dwFlags |= 8;
pEncoderInfo->buf = pbBuf;
pEncoderInfo->pos = pbBuf;
pEncoderInfo->size = cbBufSize;
}
else
{
flags = dwFlags | pEncoderInfo->dwFlags;
if (flags & 0x10)
{
pEncoderInfo->dwFlags &= 0xFFFFFFF7;
pEncoderInfo->buf = 0;
pEncoderInfo->pos = 0;
pEncoderInfo->size = 0;
}
else
{
if (!(dwFlags & ASN1ENCODE_REUSEBUFFER) && (flags & ASN1ENCODE_APPEND))
goto LABEL_MODULE;
pEncoderInfo->pos = pEncoderInfo->buf;
}
}
pEncoderInfo->len = 0;
pEncoderInfo->bit = 0;
LABEL_MODULE:
module = pEncoderInfo->module;
if (nPduNum >= module->cPDUs)
goto LABEL_BAD_PDU;
if (!(pEncoderInfo->eRule & ASN1_BER_RULE))
{
status = ASN1_ERR_RULE;
return ASN1EncSetError(pEncoderInfo, status);
}
pfnEncoder = module->BER.apfnEncoder[nPduNum];
if (!pfnEncoder)
{
LABEL_BAD_PDU:
status = ASN1_ERR_BADPDU;
return ASN1EncSetError(pEncoderInfo, status);
}
if (pfnEncoder(pEncoderInfo, 0, pDataStruct))
{
//ASN1BEREncFlush(pEncoderInfo);
}
else
{
if (pEncoderInfo[1].err >= 0)
ASN1EncSetError(pEncoderInfo, ASN1_ERR_CORRUPT);
}
if (pEncoderInfo[1].err < 0)
{
if (((dwFlags & 0xFF) | (pEncoderInfo->dwFlags & 0xFF)) & 0x10)
{
ASN1_FreeEncoded(pEncoderInfo, pEncoderInfo->buf);
pEncoderInfo->buf = 0;
pEncoderInfo->pos = 0;
pEncoderInfo->bit = 0;
pEncoderInfo->len = 0;
pEncoderInfo->size = 0;
}
}
return pEncoderInfo[1].err;
}
void ASN1_CloseEncoder(ASN1encoding_t pEncoderInfo)
{
ASN1magic_t magic;
if (pEncoderInfo)
{
magic = pEncoderInfo[1].magic;
if (pEncoderInfo != (ASN1encoding_t) magic)
pEncoderInfo[1].version = 0;
free(pEncoderInfo);
}
}
ASN1error_e ASN1EncSetError(ASN1encoding_t enc, ASN1error_e err)
{
ASN1error_e status;
ASN1encoding_t encoder;
ASN1encoding_t nextEncoder;
status = err;
encoder = enc;
while (encoder)
{
nextEncoder = (ASN1encoding_t) &encoder[1];
encoder->err = err;
if (encoder == nextEncoder)
break;
encoder = nextEncoder;
}
return status;
}
ASN1error_e ASN1DecSetError(ASN1decoding_t dec, ASN1error_e err)
{
ASN1error_e status;
ASN1decoding_t decoder;
ASN1decoding_t nextDecoder;
status = err;
decoder = dec;
while (decoder)
{
nextDecoder = (ASN1decoding_t) &decoder[1];
decoder->err = err;
if (decoder == nextDecoder)
break;
decoder = nextDecoder;
}
return status;
}
#endif

View File

@ -65,6 +65,11 @@ WCHAR* _wcsdup(const WCHAR* strSource)
return strDestination;
}
int _stricmp(const char* string1, const char* string2)
{
return strcasecmp(string1, string2);
}
/* Windows API Sets - api-ms-win-core-string-l2-1-0.dll
* http://msdn.microsoft.com/en-us/library/hh802935/
*/

View File

@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include "registry_reg.h"
@ -217,7 +218,7 @@ LONG RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesire
while (pKey != NULL)
{
if (strcmp(pKey->subname, lpSubKey) == 0)
if (_stricmp(pKey->subname, lpSubKey) == 0)
{
*phkResult = pKey;
return ERROR_SUCCESS;
@ -228,7 +229,7 @@ LONG RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesire
*phkResult = NULL;
return 0;
return ERROR_FILE_NOT_FOUND;
}
LONG RegOpenUserClassesRoot(HANDLE hToken, DWORD dwOptions, REGSAM samDesired, PHKEY phkResult)

View File

@ -28,6 +28,7 @@
#include <winpr/sspi.h>
#include <winpr/print.h>
#include <winpr/sysinfo.h>
#include <winpr/registry.h>
#include "ntlm.h"
#include "../sspi.h"
@ -56,7 +57,14 @@ void ntlm_SetContextWorkstation(NTLM_CONTEXT* context, char* Workstation)
free(Workstation);
}
void ntlm_SetContextServicePrincipalName(NTLM_CONTEXT* context, char* ServicePrincipalName)
void ntlm_SetContextServicePrincipalNameW(NTLM_CONTEXT* context, LPWSTR ServicePrincipalName)
{
context->ServicePrincipalName.Length = lstrlenW(ServicePrincipalName) * 2;
context->ServicePrincipalName.Buffer = (PWSTR) malloc(context->ServicePrincipalName.Length);
CopyMemory(context->ServicePrincipalName.Buffer, ServicePrincipalName, context->ServicePrincipalName.Length);
}
void ntlm_SetContextServicePrincipalNameA(NTLM_CONTEXT* context, char* ServicePrincipalName)
{
context->ServicePrincipalName.Length = strlen(ServicePrincipalName) * 2;
context->ServicePrincipalName.Buffer = (PWSTR) malloc(context->ServicePrincipalName.Length);
@ -94,10 +102,33 @@ NTLM_CONTEXT* ntlm_ContextNew()
if (context != NULL)
{
context->NTLMv2 = TRUE;
HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
DWORD dwValue;
context->NTLMv2 = FALSE;
context->UseMIC = FALSE;
context->NegotiateFlags = 0;
context->SendVersionInfo = TRUE;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\WinPR\\NTLM"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status == ERROR_SUCCESS)
{
if (RegQueryValueEx(hKey, _T("NTLMv2"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
context->NTLMv2 = dwValue ? 1 : 0;
if (RegQueryValueEx(hKey, _T("UseMIC"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
context->UseMIC = dwValue ? 1 : 0;
if (RegQueryValueEx(hKey, _T("SendVersionInfo"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
context->SendVersionInfo = dwValue ? 1 : 0;
RegCloseKey(hKey);
}
context->NegotiateFlags = 0;
context->LmCompatibilityLevel = 3;
context->state = NTLM_STATE_INITIAL;
context->SuppressExtendedProtection = FALSE;
@ -142,7 +173,9 @@ 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 != NULL)
CopyMemory(&(credentials->identity), identity, sizeof(SEC_WINNT_AUTH_IDENTITY));
sspi_SecureHandleSetLowerPointer(phCredential, (void*) credentials);
sspi_SecureHandleSetUpperPointer(phCredential, (void*) NTLM_PACKAGE_NAME);
@ -154,7 +187,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);
@ -233,12 +270,7 @@ SECURITY_STATUS SEC_ENTRY ntlm_QueryCredentialsAttributesW(PCredHandle phCredent
SECURITY_STATUS SEC_ENTRY ntlm_QueryCredentialsAttributesA(PCredHandle phCredential, ULONG ulAttribute, void* pBuffer)
{
if (ulAttribute == SECPKG_CRED_ATTR_NAMES)
{
return SEC_E_OK;
}
return SEC_E_UNSUPPORTED_FUNCTION;
return ntlm_QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
}
/**
@ -351,17 +383,6 @@ SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(PCredHandle phCredenti
SEC_WCHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
{
return SEC_E_OK;
}
/**
* @see http://msdn.microsoft.com/en-us/library/windows/desktop/aa375512%28v=vs.85%29.aspx
*/
SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredential, PCtxtHandle phContext,
SEC_CHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
{
NTLM_CONTEXT* context;
SECURITY_STATUS status;
@ -374,6 +395,7 @@ SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredenti
if (!context)
{
context = ntlm_ContextNew();
if (!context)
return SEC_E_INSUFFICIENT_MEMORY;
@ -383,7 +405,7 @@ SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredenti
credentials = (CREDENTIALS*) sspi_SecureHandleGetLowerPointer(phCredential);
ntlm_SetContextWorkstation(context, NULL);
ntlm_SetContextServicePrincipalName(context, pszTargetName);
ntlm_SetContextServicePrincipalNameW(context, pszTargetName);
sspi_CopyAuthIdentity(&context->identity, &credentials->identity);
sspi_SecureHandleSetLowerPointer(phNewContext, context);
@ -455,6 +477,35 @@ SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredenti
return SEC_E_OUT_OF_SEQUENCE;
}
/**
* @see http://msdn.microsoft.com/en-us/library/windows/desktop/aa375512%28v=vs.85%29.aspx
*/
SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredential, PCtxtHandle phContext,
SEC_CHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
{
int length;
SECURITY_STATUS status;
SEC_WCHAR* pszTargetNameW = NULL;
if (pszTargetName != NULL)
{
length = strlen(pszTargetName);
pszTargetNameW = (PWSTR) malloc((length + 1) * 2);
MultiByteToWideChar(CP_ACP, 0, pszTargetName, length, pszTargetNameW, length);
pszTargetNameW[length] = 0;
}
status = ntlm_InitializeSecurityContextW(phCredential, phContext, pszTargetNameW, fContextReq,
Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
if (pszTargetNameW != NULL)
free(pszTargetNameW);
return status;
}
/* http://msdn.microsoft.com/en-us/library/windows/desktop/aa375354 */
SECURITY_STATUS SEC_ENTRY ntlm_DeleteSecurityContext(PCtxtHandle phContext)
@ -474,11 +525,6 @@ SECURITY_STATUS SEC_ENTRY ntlm_DeleteSecurityContext(PCtxtHandle phContext)
/* http://msdn.microsoft.com/en-us/library/windows/desktop/aa379337/ */
SECURITY_STATUS SEC_ENTRY ntlm_QueryContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, void* pBuffer)
{
return SEC_E_OK;
}
SECURITY_STATUS SEC_ENTRY ntlm_QueryContextAttributesA(PCtxtHandle phContext, ULONG ulAttribute, void* pBuffer)
{
if (!phContext)
return SEC_E_INVALID_HANDLE;
@ -501,6 +547,11 @@ SECURITY_STATUS SEC_ENTRY ntlm_QueryContextAttributesA(PCtxtHandle phContext, UL
return SEC_E_UNSUPPORTED_FUNCTION;
}
SECURITY_STATUS SEC_ENTRY ntlm_QueryContextAttributesA(PCtxtHandle phContext, ULONG ulAttribute, void* pBuffer)
{
return ntlm_QueryContextAttributesW(phContext, ulAttribute, pBuffer);
}
SECURITY_STATUS SEC_ENTRY ntlm_RevertSecurityContext(PCtxtHandle phContext)
{
return SEC_E_OK;

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

@ -353,7 +353,7 @@ void sspi_GlobalFinish()
#ifndef WITH_NATIVE_SSPI
SecurityFunctionTableA* sspi_GetSecurityFunctionTableByNameA(const SEC_CHAR* Name)
SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameA(const SEC_CHAR* Name)
{
int index;
UINT32 cPackages;
@ -371,7 +371,12 @@ SecurityFunctionTableA* sspi_GetSecurityFunctionTableByNameA(const SEC_CHAR* Nam
return NULL;
}
SecurityFunctionTableW* sspi_GetSecurityFunctionTableByNameW(const SEC_WCHAR* Name)
SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameW(const SEC_WCHAR* Name)
{
return NULL;
}
SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameW(const SEC_WCHAR* Name)
{
int index;
UINT32 cPackages;
@ -389,6 +394,23 @@ SecurityFunctionTableW* sspi_GetSecurityFunctionTableByNameW(const SEC_WCHAR* Na
return NULL;
}
SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameA(const SEC_CHAR* Name)
{
int length;
SEC_WCHAR* NameW;
SecurityFunctionTableW* table;
length = strlen(Name);
NameW = (SEC_WCHAR*) malloc((length + 1) * 2);
MultiByteToWideChar(CP_ACP, 0, Name, length, (LPWSTR) NameW, length);
NameW[length] = 0;
table = sspi_GetSecurityFunctionTableWByNameW(NameW);
free(NameW);
return table;
}
void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer);
void FreeContextBuffer_QuerySecurityPackageInfo(void* contextBuffer);
@ -599,7 +621,7 @@ SECURITY_STATUS SEC_ENTRY AcquireCredentialsHandleW(SEC_WCHAR* pszPrincipal, SEC
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
{
SECURITY_STATUS status;
SecurityFunctionTableW* table = sspi_GetSecurityFunctionTableByNameW(pszPackage);
SecurityFunctionTableW* table = sspi_GetSecurityFunctionTableWByNameW(pszPackage);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -618,7 +640,7 @@ SECURITY_STATUS SEC_ENTRY AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal, SEC_
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
{
SECURITY_STATUS status;
SecurityFunctionTableA* table = sspi_GetSecurityFunctionTableByNameA(pszPackage);
SecurityFunctionTableA* table = sspi_GetSecurityFunctionTableAByNameA(pszPackage);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -648,7 +670,7 @@ SECURITY_STATUS SEC_ENTRY FreeCredentialsHandle(PCredHandle phCredential)
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -682,7 +704,7 @@ SECURITY_STATUS SEC_ENTRY QueryCredentialsAttributesW(PCredHandle phCredential,
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameW(Name);
table = sspi_GetSecurityFunctionTableWByNameW(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -706,7 +728,7 @@ SECURITY_STATUS SEC_ENTRY QueryCredentialsAttributesA(PCredHandle phCredential,
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -734,7 +756,7 @@ SECURITY_STATUS SEC_ENTRY AcceptSecurityContext(PCredHandle phCredential, PCtxtH
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -769,7 +791,7 @@ SECURITY_STATUS SEC_ENTRY DeleteSecurityContext(PCtxtHandle phContext)
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -811,7 +833,7 @@ SECURITY_STATUS SEC_ENTRY InitializeSecurityContextW(PCredHandle phCredential, P
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = (SecurityFunctionTableW*) sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableWByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -840,7 +862,7 @@ SECURITY_STATUS SEC_ENTRY InitializeSecurityContextA(PCredHandle phCredential, P
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -866,7 +888,7 @@ SECURITY_STATUS SEC_ENTRY QueryContextAttributesW(PCtxtHandle phContext, ULONG u
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = (SecurityFunctionTableW*) sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableWByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -890,7 +912,7 @@ SECURITY_STATUS SEC_ENTRY QueryContextAttributesA(PCtxtHandle phContext, ULONG u
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -931,7 +953,7 @@ SECURITY_STATUS SEC_ENTRY DecryptMessage(PCtxtHandle phContext, PSecBufferDesc p
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -955,7 +977,7 @@ SECURITY_STATUS SEC_ENTRY EncryptMessage(PCtxtHandle phContext, ULONG fQOP, PSec
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -979,7 +1001,7 @@ SECURITY_STATUS SEC_ENTRY MakeSignature(PCtxtHandle phContext, ULONG fQOP, PSecB
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;
@ -1003,7 +1025,7 @@ SECURITY_STATUS SEC_ENTRY VerifySignature(PCtxtHandle phContext, PSecBufferDesc
if (!Name)
return SEC_E_SECPKG_NOT_FOUND;
table = sspi_GetSecurityFunctionTableByNameA(Name);
table = sspi_GetSecurityFunctionTableAByNameA(Name);
if (!table)
return SEC_E_SECPKG_NOT_FOUND;

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';