Merge branch 'master' of git://github.com/awakecoding/FreeRDP

This commit is contained in:
Benoît LeBlanc 2013-11-18 11:34:32 -05:00
commit 184ee149f6
16 changed files with 235 additions and 41 deletions

View File

@ -312,6 +312,11 @@ if(NOT IOS AND NOT ANDROID)
find_package(Threads REQUIRED)
endif()
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_library_exists(pthread pthread_tryjoin_np "" HAVE_PTHREAD_GNU_EXT)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
if(UNIX OR CYGWIN)
check_include_files(sys/eventfd.h HAVE_AIO_H)
check_include_files(sys/eventfd.h HAVE_EVENTFD_H)

View File

@ -54,6 +54,7 @@ COMMAND_LINE_ARGUMENT_A args[] =
{ "admin", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, "console", "Admin (or console) session" },
{ "restricted-admin", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, "restrictedAdmin", "Restricted admin mode" },
{ "pth", COMMAND_LINE_VALUE_REQUIRED, "<password hash>", NULL, NULL, -1, "pass-the-hash", "Pass the hash (restricted admin mode)" },
{ "client-hostname", COMMAND_LINE_VALUE_REQUIRED, "<name>", NULL, NULL, -1, NULL, "Client Hostname to send to server" },
{ "multimon", COMMAND_LINE_VALUE_OPTIONAL, NULL, NULL, NULL, -1, NULL, "Use multiple monitors" },
{ "workarea", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Use available work area" },
{ "monitors", COMMAND_LINE_VALUE_REQUIRED, "<0,1,2...>", NULL, NULL, -1, NULL, "Select monitors to use" },
@ -1244,6 +1245,10 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
settings->RestrictedAdminModeRequired = TRUE;
settings->PasswordHash = _strdup(arg->Value);
}
CommandLineSwitchCase(arg, "client-hostname")
{
settings->ClientHostname = _strdup(arg->Value);
}
CommandLineSwitchCase(arg, "kbd")
{
int id;

View File

@ -500,6 +500,7 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
CommandLineSwitchCase(arg, "n")
{
settings->ClientHostname = _strdup(arg->Value);
fprintf(stderr, "-n -> /client-hostname:%s\n", arg->Value);
}
CommandLineSwitchCase(arg, "o")
{

View File

@ -12,6 +12,7 @@
#import "TSXAdditions.h"
#import <freerdp/input.h>
#import <freerdp/version.h>
#import "config.h"
#include <sys/types.h>

View File

@ -279,10 +279,10 @@ static UIFont *buttonFont = nil;
button.frame = CGRectMake(xOffset, _height, width, kAlertButtonHeight);
button.titleLabel.font = buttonFont;
if (IOS_LESS_THAN_6) {
#pragma clan diagnostic push
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
button.titleLabel.minimumFontSize = 10;
#pragma clan diagnostic pop
#pragma clang diagnostic pop
}
else {
button.titleLabel.adjustsFontSizeToFitWidth = YES;

View File

@ -24,6 +24,7 @@
#cmakedefine HAVE_TIMERFD_H
#cmakedefine HAVE_TM_GMTOFF
#cmakedefine HAVE_AIO_H
#cmakedefine HAVE_PTHREAD_GNU_EXT
/* Options */

View File

@ -818,6 +818,54 @@ BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channel_id)
return (status < 0) ? FALSE : TRUE;
}
/**
* Receive MCS Disconnect Provider Ultimatum PDU.\n
* @param mcs mcs module
*/
BOOL mcs_recv_disconnect_provider_ultimatum(rdpMcs* mcs, wStream* s, int* reason)
{
BYTE b1, b2;
/*
* http://msdn.microsoft.com/en-us/library/cc240872.aspx:
*
* PER encoded (ALIGNED variant of BASIC-PER) PDU contents:
* 21 80
*
* 0x21:
* 0 - --\
* 0 - |
* 1 - | CHOICE: From DomainMCSPDU select disconnectProviderUltimatum (8)
* 0 - | of type DisconnectProviderUltimatum
* 0 - |
* 0 - --/
* 0 - --\
* 1 - |
* | DisconnectProviderUltimatum::reason = rn-user-requested (3)
* 0x80: |
* 1 - --/
* 0 - padding
* 0 - padding
* 0 - padding
* 0 - padding
* 0 - padding
* 0 - padding
* 0 - padding
*/
if (Stream_GetRemainingLength(s) < 1)
return FALSE;
Stream_Rewind_UINT8(s);
Stream_Read_UINT8(s, b1);
Stream_Read_UINT8(s, b2);
*reason = ((b1 & 0x01) << 1) | (b2 >> 7);
return TRUE;
}
/**
* Send MCS Disconnect Provider Ultimatum PDU.\n
* @param mcs mcs module

View File

@ -20,6 +20,8 @@
#ifndef __MCS_H
#define __MCS_H
typedef struct rdp_mcs rdpMcs;
#include "transport.h"
#include <freerdp/crypto/ber.h>
@ -52,6 +54,15 @@ enum MCS_Result
MCS_Result_enum_length = 16
};
enum MCS_Reason
{
MCS_Reason_domain_disconnected = 0,
MCS_Reason_provider_initiated = 1,
MCS_Reason_token_purged = 2,
MCS_Reason_user_requested = 3,
MCS_Reason_channel_purged = 4
};
enum DomainMCSPDU
{
DomainMCSPDU_PlumbDomainIndication = 0,
@ -115,7 +126,7 @@ typedef struct
struct rdp_mcs
{
UINT16 user_id;
struct rdp_transport* transport;
rdpTransport* transport;
DomainParameters domainParameters;
DomainParameters targetParameters;
DomainParameters minimumParameters;
@ -124,7 +135,6 @@ struct rdp_mcs
BOOL user_channel_joined;
BOOL global_channel_joined;
};
typedef struct rdp_mcs rdpMcs;
#define MCS_SEND_DATA_HEADER_MAX_LENGTH 8
@ -148,6 +158,7 @@ BOOL mcs_recv_channel_join_request(rdpMcs* mcs, wStream* s, UINT16* channel_id);
BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channel_id);
BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channel_id);
BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channel_id);
BOOL mcs_recv_disconnect_provider_ultimatum(rdpMcs* mcs, wStream* s, int* reason);
BOOL mcs_send_disconnect_provider_ultimatum(rdpMcs* mcs);
BOOL mcs_read_domain_mcspdu_header(wStream* s, enum DomainMCSPDU* domainMCSPDU, UINT16* length);
void mcs_write_domain_mcspdu_header(wStream* s, enum DomainMCSPDU domainMCSPDU, UINT16 length, BYTE options);

View File

@ -229,6 +229,25 @@ wStream* rdp_data_pdu_init(rdpRdp* rdp)
return s;
}
BOOL rdp_set_error_info(rdpRdp* rdp, UINT32 errorInfo)
{
rdp->errorInfo = errorInfo;
if (rdp->errorInfo != ERRINFO_SUCCESS)
{
ErrorInfoEventArgs e;
rdpContext* context = rdp->instance->context;
rdp_print_errinfo(rdp->errorInfo);
EventArgsInit(&e, "freerdp");
e.code = rdp->errorInfo;
PubSub_OnErrorInfo(context->pubSub, context, &e);
}
return TRUE;
}
/**
* Read an RDP packet header.\n
* @param rdp rdp module
@ -256,12 +275,30 @@ BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId)
if (MCSPDU == DomainMCSPDU_DisconnectProviderUltimatum)
{
BYTE reason;
int reason = 0;
TerminateEventArgs e;
rdpContext* context = rdp->instance->context;
(void) per_read_enumerated(s, &reason, 0);
DEBUG_RDP("DisconnectProviderUltimatum from server, reason code 0x%02x\n", reason);
if (!mcs_recv_disconnect_provider_ultimatum(rdp->mcs, s, &reason))
return FALSE;
if (rdp->errorInfo == ERRINFO_SUCCESS)
{
/**
* Some servers like Windows Server 2008 R2 do not send the error info pdu
* when the user logs off like they should. Map DisconnectProviderUltimatum
* to a ERRINFO_LOGOFF_BY_USER when the errinfo code is ERRINFO_SUCCESS.
*/
if (reason == MCS_Reason_provider_initiated)
rdp_set_error_info(rdp, ERRINFO_RPC_INITIATED_DISCONNECT);
else if (reason == MCS_Reason_user_requested)
rdp_set_error_info(rdp, ERRINFO_LOGOFF_BY_USER);
else
rdp_set_error_info(rdp, ERRINFO_RPC_INITIATED_DISCONNECT);
}
fprintf(stderr, "DisconnectProviderUltimatum: reason: %d\n", reason);
rdp->disconnect = TRUE;
@ -503,22 +540,14 @@ BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id)
BOOL rdp_recv_set_error_info_data_pdu(rdpRdp* rdp, wStream* s)
{
UINT32 errorInfo;
if (Stream_GetRemainingLength(s) < 4)
return FALSE;
Stream_Read_UINT32(s, rdp->errorInfo); /* errorInfo (4 bytes) */
Stream_Read_UINT32(s, errorInfo); /* errorInfo (4 bytes) */
if (rdp->errorInfo != ERRINFO_SUCCESS)
{
ErrorInfoEventArgs e;
rdpContext* context = rdp->instance->context;
rdp_print_errinfo(rdp->errorInfo);
EventArgsInit(&e, "freerdp");
e.code = rdp->errorInfo;
PubSub_OnErrorInfo(context->pubSub, context, &e);
}
rdp_set_error_info(rdp, errorInfo);
return TRUE;
}

View File

@ -74,6 +74,9 @@ BOOL transport_disconnect(rdpTransport* transport)
{
BOOL status = TRUE;
if (!transport)
return FALSE;
if (transport->layer == TRANSPORT_LAYER_TLS)
status &= tls_disconnect(transport->TlsIn);

View File

@ -360,6 +360,9 @@ BOOL tls_accept(rdpTls* tls, const char* cert_file, const char* privatekey_file)
BOOL tls_disconnect(rdpTls* tls)
{
if (!tls)
return FALSE;
if (tls->ssl)
SSL_shutdown(tls->ssl);

View File

@ -18,13 +18,8 @@
set(MODULE_NAME "winpr-synch")
set(MODULE_PREFIX "WINPR_SYNCH")
INCLUDE (CheckLibraryExists)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_library_exists(pthread pthread_tryjoin_np "" HAVE_PTHREAD_GNU_EXT)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
if(HAVE_PTHREAD_GNU_EXT)
add_definitions(-D_GNU_SOURCE -DHAVE_PTHREAD_GNU_EXT)
add_definitions(-D_GNU_SOURCE)
endif(HAVE_PTHREAD_GNU_EXT)
include_directories(../thread)

View File

@ -9,6 +9,7 @@ set(${MODULE_PREFIX}_TESTS
TestSynchMutex.c
TestSynchCritical.c
TestSynchSemaphore.c
TestSynchThread.c
TestSynchWaitableTimer.c)
create_test_sourcelist(${MODULE_PREFIX}_SRCS

View File

@ -4,16 +4,48 @@
int TestSynchMutex(int argc, char* argv[])
{
DWORD rc;
HANDLE mutex;
mutex = CreateMutex(NULL, FALSE, NULL);
if (!mutex)
{
printf("CreateMutex failure\n");
return -1;
}
/* Lock the mutex */
rc = WaitForSingleObject(mutex, INFINITE);
if (WAIT_OBJECT_0 != rc)
{
printf("WaitForSingleObject on mutex failed with %d\n", rc);
return -2;
}
/* TryLock should now fail. */
rc = WaitForSingleObject(mutex, 0);
if (WAIT_TIMEOUT != rc)
{
printf("Timed WaitForSingleObject on locked mutex failed with %d\n", rc);
return -3;
}
/* Unlock the mutex */
rc = ReleaseMutex(mutex);
if (!rc)
{
printf("ReleaseMutex failed.\n");
return -4;
}
/* TryLock should now succeed. */
rc = WaitForSingleObject(mutex, 0);
if (WAIT_OBJECT_0 != rc)
{
printf("Timed WaitForSingleObject on free mutex failed with %d\n", rc);
return -5;
}
CloseHandle(mutex);
return 0;

View File

@ -0,0 +1,55 @@
#include <winpr/crt.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
static void *test_thread(void *arg)
{
Sleep(1000);
ExitThread(0);
return NULL;
}
int TestSynchThread(int argc, char* argv[])
{
DWORD rc;
HANDLE thread;
thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test_thread,
NULL, 0, NULL);
if (!thread)
{
printf("CreateThread failure\n");
return -1;
}
/* TryJoin should now fail. */
rc = WaitForSingleObject(thread, 0);
if (WAIT_TIMEOUT != rc)
{
printf("Timed WaitForSingleObject on running thread failed with %d\n", rc);
return -3;
}
/* Join the thread */
rc = WaitForSingleObject(thread, INFINITE);
if (WAIT_OBJECT_0 != rc)
{
printf("WaitForSingleObject on thread failed with %d\n", rc);
return -2;
}
/* TimedJoin should now succeed. */
rc = WaitForSingleObject(thread, 0);
if (WAIT_OBJECT_0 != rc)
{
printf("Timed WaitForSingleObject on dead thread failed with %d\n", rc);
return -5;
}
CloseHandle(thread);
return 0;
}

View File

@ -86,10 +86,20 @@ int clock_gettime(int clk_id, struct timespec *t)
*/
#if !defined(HAVE_PTHREAD_GNU_EXT)
#include <pthread.h>
static long long ts_difftime(struct timespec *o,
struct timespec *n)
{
long long old = o->tv_sec * 1000000000LL + o->tv_nsec;
long long new = n->tv_sec * 1000000000LL + n->tv_nsec;
return new - old;
}
static int pthread_timedjoin_np(pthread_t td, void **res,
struct timespec *timeout)
{
struct timeval timenow;
struct timespec timenow;
struct timespec sleepytime;
/* This is just to avoid a completely busy wait */
sleepytime.tv_sec = 0;
@ -101,11 +111,10 @@ static int pthread_timedjoin_np(pthread_t td, void **res,
return pthread_join(td, res);
nanosleep(&sleepytime, NULL);
gettimeofday(&timenow, NULL);
clock_gettime(CLOCK_MONOTONIC, &timenow);
if (timenow.tv_sec >= timeout->tv_sec &&
(timenow.tv_usec * 1000) >= timeout->tv_nsec)
if (ts_difftime(timeout, &timenow) >= 0)
{
return ETIMEDOUT;
}
@ -117,7 +126,7 @@ static int pthread_timedjoin_np(pthread_t td, void **res,
static int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *timeout)
{
struct timeval timenow;
struct timespec timenow;
struct timespec sleepytime;
int retcode;
@ -127,10 +136,9 @@ static int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec
while ((retcode = pthread_mutex_trylock (mutex)) == EBUSY)
{
gettimeofday (&timenow, NULL);
clock_gettime(CLOCK_MONOTONIC, &timenow);
if (timenow.tv_sec >= timeout->tv_sec &&
(timenow.tv_usec * 1000) >= timeout->tv_nsec)
if (ts_difftime(timeout, &timenow) >= 0)
{
return ETIMEDOUT;
}
@ -172,7 +180,6 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
if (thread->started)
{
#ifdef __linux__
if (dwMilliseconds != INFINITE)
{
struct timespec timeout;
@ -182,7 +189,7 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
if (dwMilliseconds == 0)
dwMilliseconds ++;
clock_gettime(CLOCK_REALTIME, &timeout);
clock_gettime(CLOCK_MONOTONIC, &timeout);
ts_add_ms(&timeout, dwMilliseconds);
status = pthread_timedjoin_np(thread->thread, &thread_status, &timeout);
@ -191,7 +198,6 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
return WAIT_TIMEOUT;
}
else
#endif
status = pthread_join(thread->thread, &thread_status);
if (status != 0)
@ -223,13 +229,12 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
mutex = (WINPR_MUTEX*) Object;
#ifdef __linux__
if (dwMilliseconds != INFINITE)
{
int status;
struct timespec timeout;
clock_gettime(CLOCK_REALTIME, &timeout);
clock_gettime(CLOCK_MONOTONIC, &timeout);
ts_add_ms(&timeout, dwMilliseconds);
status = pthread_mutex_timedlock(&mutex->mutex, &timeout);
@ -238,7 +243,6 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
return WAIT_TIMEOUT;
}
else
#endif
pthread_mutex_lock(&mutex->mutex);
}
else if (Type == HANDLE_TYPE_EVENT)