libfreerdp-core: fix unix domain socket support

This commit is contained in:
Marc-André Moreau 2014-08-06 12:08:00 -04:00
parent 3895c930a3
commit 9838200068
4 changed files with 37 additions and 7 deletions

View File

@ -97,6 +97,7 @@ struct rdp_shadow_server
DWORD port;
BOOL mayView;
BOOL mayInteract;
char* ipcSocket;
char* ConfigPath;
char* CertificateFile;
char* PrivateKeyFile;

View File

@ -496,16 +496,21 @@ BOOL tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout)
return FALSE;
if (hostname[0] == '/')
tcp->ipcSocket = TRUE;
if (tcp->ipcSocket)
{
tcp->sockfd = freerdp_uds_connect(hostname);
if (tcp->sockfd < 0)
return FALSE;
tcp->socketBio = BIO_new_fd(tcp->sockfd, 1);
tcp->socketBio = BIO_new(BIO_s_simple_socket());
if (!tcp->socketBio)
return FALSE;
BIO_set_fd(tcp->socketBio, tcp->sockfd, BIO_CLOSE);
}
else
{
@ -568,7 +573,7 @@ BOOL tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout)
tcp->socketBio = BIO_new(BIO_s_simple_socket());
if (!tcp->socketBio)
return -1;
return FALSE;
BIO_set_fd(tcp->socketBio, tcp->sockfd, BIO_CLOSE);
}
@ -581,8 +586,11 @@ BOOL tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout)
option_value = 1;
option_len = sizeof(option_value);
if (setsockopt(tcp->sockfd, IPPROTO_TCP, TCP_NODELAY, (void*) &option_value, option_len) < 0)
fprintf(stderr, "%s: unable to set TCP_NODELAY\n", __FUNCTION__);
if (!tcp->ipcSocket)
{
if (setsockopt(tcp->sockfd, IPPROTO_TCP, TCP_NODELAY, (void*) &option_value, option_len) < 0)
fprintf(stderr, "%s: unable to set TCP_NODELAY\n", __FUNCTION__);
}
/* receive buffer must be a least 32 K */
if (getsockopt(tcp->sockfd, SOL_SOCKET, SO_RCVBUF, (void*) &option_value, &option_len) == 0)
@ -600,8 +608,11 @@ BOOL tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout)
}
}
if (!tcp_set_keep_alive_mode(tcp))
return FALSE;
if (!tcp->ipcSocket)
{
if (!tcp_set_keep_alive_mode(tcp))
return FALSE;
}
tcp->bufferedBio = BIO_new(BIO_s_buffered_socket());

View File

@ -46,6 +46,7 @@ typedef struct rdp_tcp rdpTcp;
struct rdp_tcp
{
int sockfd;
BOOL ipcSocket;
char ip_address[32];
BYTE mac_address[6];
rdpSettings* settings;

View File

@ -51,6 +51,7 @@ extern rdpShadowSubsystem* Win_ShadowCreateSubsystem(rdpShadowServer* server);
static COMMAND_LINE_ARGUMENT_A shadow_args[] =
{
{ "port", COMMAND_LINE_VALUE_REQUIRED, "<number>", NULL, NULL, -1, NULL, "Server port" },
{ "ipc-socket", COMMAND_LINE_VALUE_REQUIRED, "<ipc-socket>", NULL, NULL, -1, NULL, "Server IPC socket" },
{ "monitors", COMMAND_LINE_VALUE_OPTIONAL, "<0,1,2...>", NULL, NULL, -1, NULL, "Select or list monitors" },
{ "may-view", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "Clients may view without prompt" },
{ "may-interact", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "Clients may interact without prompt" },
@ -175,6 +176,10 @@ int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** a
{
server->port = (DWORD) atoi(arg->Value);
}
CommandLineSwitchCase(arg, "ipc-socket")
{
server->ipcSocket = _strdup(arg->Value);
}
CommandLineSwitchCase(arg, "may-view")
{
server->mayView = arg->Value ? TRUE : FALSE;
@ -312,6 +317,7 @@ void* shadow_server_thread(rdpShadowServer* server)
int shadow_server_start(rdpShadowServer* server)
{
BOOL status;
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
@ -321,7 +327,12 @@ int shadow_server_start(rdpShadowServer* server)
signal(SIGPIPE, SIG_IGN);
#endif
if (server->listener->Open(server->listener, NULL, (UINT16) server->port))
if (!server->ipcSocket)
status = server->listener->Open(server->listener, NULL, (UINT16) server->port);
else
status = server->listener->OpenLocal(server->listener, server->ipcSocket);
if (status)
{
server->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
shadow_server_thread, (void*) server, 0, NULL);
@ -483,6 +494,12 @@ int shadow_server_uninit(rdpShadowServer* server)
server->PrivateKeyFile = NULL;
}
if (server->ipcSocket)
{
free(server->ipcSocket);
server->ipcSocket = NULL;
}
return 1;
}