mirror of https://github.com/FreeRDP/FreeRDP
Merge pull request #4325 from akallabeth/fixes_com
Fixes serial redirection name check and SAM file parser
This commit is contained in:
commit
19a00f2099
|
@ -375,8 +375,8 @@ static UINT parallel_free(DEVICE* device)
|
|||
UINT error;
|
||||
PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device;
|
||||
|
||||
if (MessageQueue_PostQuit(parallel->queue, 0)
|
||||
&& (WaitForSingleObject(parallel->thread, INFINITE) == WAIT_FAILED))
|
||||
if (!MessageQueue_PostQuit(parallel->queue, 0)
|
||||
|| (WaitForSingleObject(parallel->thread, INFINITE) == WAIT_FAILED))
|
||||
{
|
||||
error = GetLastError();
|
||||
WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"!", error);
|
||||
|
@ -405,7 +405,7 @@ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
|||
{
|
||||
char* name;
|
||||
char* path;
|
||||
int i;
|
||||
size_t i;
|
||||
size_t length;
|
||||
RDPDR_PARALLEL* device;
|
||||
PARALLEL_DEVICE* parallel;
|
||||
|
@ -414,10 +414,10 @@ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
|||
name = device->Name;
|
||||
path = device->Path;
|
||||
|
||||
if (!name || (name[0] == '*'))
|
||||
if (!name || (name[0] == '*') || !path)
|
||||
{
|
||||
/* TODO: implement auto detection of parallel ports */
|
||||
return CHANNEL_RC_OK;
|
||||
return CHANNEL_RC_INITIALIZATION_ERROR;
|
||||
}
|
||||
|
||||
if (name[0] && path[0])
|
||||
|
|
|
@ -146,7 +146,7 @@ BOOL freerdp_client_print_command_line_help_ex(int argc, char** argv,
|
|||
printf("Smartcard Redirection: /smartcard:<device>\n");
|
||||
printf("Serial Port Redirection: /serial:<name>,<device>,[SerCx2|SerCx|Serial],[permissive]\n");
|
||||
printf("Serial Port Redirection: /serial:COM1,/dev/ttyS0\n");
|
||||
printf("Parallel Port Redirection: /parallel:<device>\n");
|
||||
printf("Parallel Port Redirection: /parallel:<name>,<device>\n");
|
||||
printf("Printer Redirection: /printer:<device>,<driver>\n");
|
||||
printf("\n");
|
||||
printf("Audio Output Redirection: /sound:sys:oss,dev:1,format:1\n");
|
||||
|
|
|
@ -1065,7 +1065,7 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName,
|
|||
|
||||
if (_tcsncmp(lpDeviceName, _T("\\\\.\\"), 4) != 0)
|
||||
{
|
||||
if (!_IsReservedCommDeviceName(lpDeviceName))
|
||||
if (_IsReservedCommDeviceName(lpDeviceName))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_DATA);
|
||||
goto error_handle;
|
||||
|
@ -1470,9 +1470,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess,
|
|||
|
||||
return (HANDLE)pComm;
|
||||
error_handle:
|
||||
|
||||
CloseHandle(pComm);
|
||||
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,9 @@ WINPR_SAM* SamOpen(const char* filename, BOOL readOnly)
|
|||
else
|
||||
{
|
||||
WLog_DBG(TAG, "Could not open SAM file!");
|
||||
fclose(fp);
|
||||
free(sam);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return sam;
|
||||
|
@ -89,6 +92,9 @@ static BOOL SamLookupStart(WINPR_SAM* sam)
|
|||
size_t readSize;
|
||||
INT64 fileSize;
|
||||
|
||||
if (!sam || !sam->fp)
|
||||
return FALSE;
|
||||
|
||||
_fseeki64(sam->fp, 0, SEEK_END);
|
||||
fileSize = _ftelli64(sam->fp);
|
||||
_fseeki64(sam->fp, 0, SEEK_SET);
|
||||
|
@ -119,7 +125,6 @@ static BOOL SamLookupStart(WINPR_SAM* sam)
|
|||
sam->buffer[fileSize] = '\n';
|
||||
sam->buffer[fileSize + 1] = '\0';
|
||||
sam->line = strtok(sam->buffer, "\n");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -153,55 +158,74 @@ static void HexStrToBin(char* str, BYTE* bin, int length)
|
|||
}
|
||||
}
|
||||
|
||||
BOOL SamReadEntry(WINPR_SAM *sam, WINPR_SAM_ENTRY *entry)
|
||||
BOOL SamReadEntry(WINPR_SAM* sam, WINPR_SAM_ENTRY* entry)
|
||||
{
|
||||
char* p[7];
|
||||
int LmHashLength;
|
||||
int NtHashLength;
|
||||
char* p[5];
|
||||
size_t LmHashLength;
|
||||
size_t NtHashLength;
|
||||
size_t count = 0;
|
||||
char* cur;
|
||||
|
||||
if (!sam || !entry || !sam->line)
|
||||
return FALSE;
|
||||
|
||||
cur = sam->line;
|
||||
|
||||
while ((cur = strchr(cur, ':')) != NULL)
|
||||
{
|
||||
count++;
|
||||
cur++;
|
||||
}
|
||||
|
||||
if (count < 4)
|
||||
return FALSE;
|
||||
|
||||
p[0] = sam->line;
|
||||
p[1] = strchr(p[0], ':') + 1;
|
||||
p[2] = strchr(p[1], ':') + 1;
|
||||
p[3] = strchr(p[2], ':') + 1;
|
||||
p[4] = strchr(p[3], ':') + 1;
|
||||
p[5] = strchr(p[4], ':') + 1;
|
||||
p[6] = p[0] + strlen(p[0]);
|
||||
LmHashLength = (p[3] - p[2] - 1);
|
||||
NtHashLength = (p[4] - p[3] - 1);
|
||||
|
||||
if ((LmHashLength != 0) && (LmHashLength != 32))
|
||||
return FALSE;
|
||||
|
||||
if ((NtHashLength != 0) && (NtHashLength != 32))
|
||||
return FALSE;
|
||||
|
||||
entry->UserLength = (UINT32)(p[1] - p[0] - 1);
|
||||
entry->User = (LPSTR) malloc(entry->UserLength + 1);
|
||||
|
||||
if (!entry->User)
|
||||
return FALSE;
|
||||
|
||||
entry->User[entry->UserLength] = '\0';
|
||||
entry->DomainLength = (UINT32)(p[2] - p[1] - 1);
|
||||
LmHashLength = (int)(p[3] - p[2] - 1);
|
||||
NtHashLength = (int)(p[4] - p[3] - 1);
|
||||
memcpy(entry->User, p[0], entry->UserLength);
|
||||
|
||||
if (entry->DomainLength > 0)
|
||||
{
|
||||
entry->Domain = (LPSTR) malloc(entry->DomainLength + 1);
|
||||
|
||||
if (!entry->Domain)
|
||||
{
|
||||
free(entry->User);
|
||||
entry->User = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memcpy(entry->Domain, p[1], entry->DomainLength);
|
||||
entry->Domain[entry->DomainLength] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
entry->Domain = NULL;
|
||||
}
|
||||
|
||||
if (LmHashLength == 32)
|
||||
{
|
||||
HexStrToBin(p[2], (BYTE*) entry->LmHash, 16);
|
||||
}
|
||||
|
||||
if (NtHashLength == 32)
|
||||
{
|
||||
HexStrToBin(p[3], (BYTE*) entry->NtHash, 16);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -241,12 +265,12 @@ void SamResetEntry(WINPR_SAM_ENTRY* entry)
|
|||
ZeroMemory(entry->NtHash, sizeof(entry->NtHash));
|
||||
}
|
||||
|
||||
WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, LPSTR Domain, UINT32 DomainLength)
|
||||
WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, LPSTR Domain,
|
||||
UINT32 DomainLength)
|
||||
{
|
||||
int length;
|
||||
size_t length;
|
||||
BOOL found = FALSE;
|
||||
WINPR_SAM_ENTRY* entry;
|
||||
|
||||
entry = (WINPR_SAM_ENTRY*) calloc(1, sizeof(WINPR_SAM_ENTRY));
|
||||
|
||||
if (!entry)
|
||||
|
@ -260,7 +284,7 @@ WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, L
|
|||
|
||||
while (sam->line != NULL)
|
||||
{
|
||||
length = (int) strlen(sam->line);
|
||||
length = strlen(sam->line);
|
||||
|
||||
if (length > 1)
|
||||
{
|
||||
|
@ -278,6 +302,7 @@ WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, L
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
SamResetEntry(entry);
|
||||
sam->line = strtok(NULL, "\n");
|
||||
}
|
||||
|
@ -294,9 +319,10 @@ out_fail:
|
|||
return entry;
|
||||
}
|
||||
|
||||
WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength, LPWSTR Domain, UINT32 DomainLength)
|
||||
WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength, LPWSTR Domain,
|
||||
UINT32 DomainLength)
|
||||
{
|
||||
int length;
|
||||
size_t length;
|
||||
BOOL Found = FALSE;
|
||||
BOOL UserMatch;
|
||||
BOOL DomainMatch;
|
||||
|
@ -317,7 +343,7 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength,
|
|||
|
||||
while (sam->line != NULL)
|
||||
{
|
||||
length = (int) strlen(sam->line);
|
||||
length = strlen(sam->line);
|
||||
|
||||
if (length > 1)
|
||||
{
|
||||
|
@ -325,6 +351,7 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength,
|
|||
{
|
||||
DomainMatch = 0;
|
||||
UserMatch = 0;
|
||||
|
||||
if (!SamReadEntry(sam, entry))
|
||||
goto out_fail;
|
||||
|
||||
|
@ -334,10 +361,12 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength,
|
|||
{
|
||||
EntryDomainLength = (UINT32) strlen(entry->Domain) * 2;
|
||||
EntryDomain = (LPWSTR) malloc(EntryDomainLength + 2);
|
||||
|
||||
if (!EntryDomain)
|
||||
goto out_fail;
|
||||
|
||||
MultiByteToWideChar(CP_ACP, 0, entry->Domain, EntryDomainLength / 2,
|
||||
(LPWSTR) EntryDomain, EntryDomainLength / 2);
|
||||
(LPWSTR) EntryDomain, EntryDomainLength / 2);
|
||||
|
||||
if (DomainLength == EntryDomainLength)
|
||||
{
|
||||
|
@ -363,10 +392,12 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPWSTR User, UINT32 UserLength,
|
|||
{
|
||||
EntryUserLength = (UINT32) strlen(entry->User) * 2;
|
||||
EntryUser = (LPWSTR) malloc(EntryUserLength + 2);
|
||||
|
||||
if (!EntryUser)
|
||||
goto out_fail;
|
||||
|
||||
MultiByteToWideChar(CP_ACP, 0, entry->User, EntryUserLength / 2,
|
||||
(LPWSTR) EntryUser, EntryUserLength / 2);
|
||||
(LPWSTR) EntryUser, EntryUserLength / 2);
|
||||
|
||||
if (UserLength == EntryUserLength)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue