summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/file.c15
-rw-r--r--common/file_loc.h4
-rw-r--r--common/os_calls.c301
-rw-r--r--common/os_calls.h10
-rw-r--r--common/parse.h99
-rw-r--r--common/trans.h2
-rw-r--r--common/xrdp_client_info.h6
-rw-r--r--common/xrdp_constants.h1
8 files changed, 376 insertions, 62 deletions
diff --git a/common/file.c b/common/file.c
index c8be7af5..05f243ca 100644
--- a/common/file.c
+++ b/common/file.c
@@ -242,8 +242,19 @@ l_file_read_section(int fd, int max_file_size, const char *section,
for (index = 0; index < len; index++)
{
+ if (!s_check_rem(s, 1))
+ {
+ break;
+ }
in_uint8(s, c);
-
+ if ((c == '#') || (c == ';'))
+ {
+ file_read_line(s, text);
+ in_it = 0;
+ in_it_index = 0;
+ g_memset(text, 0, 512);
+ continue;
+ }
if (c == '[')
{
in_it = 1;
@@ -253,7 +264,6 @@ l_file_read_section(int fd, int max_file_size, const char *section,
if (g_strcasecmp(section, text) == 0)
{
file_read_line(s, text);
-
while (file_read_line(s, text) == 0)
{
if (g_strlen(text) > 0)
@@ -296,7 +306,6 @@ l_file_read_section(int fd, int max_file_size, const char *section,
}
}
}
-
free_stream(s);
return 1;
}
diff --git a/common/file_loc.h b/common/file_loc.h
index db312fb4..c8b3a76f 100644
--- a/common/file_loc.h
+++ b/common/file_loc.h
@@ -37,4 +37,8 @@
#define XRDP_SHARE_PATH "/usr/local/share/xrdp"
#endif
+#if !defined(XRDP_LIB_PATH)
+#define XRDP_LIB_PATH "/usr/local/lib/xrdp"
+#endif
+
#endif
diff --git a/common/os_calls.c b/common/os_calls.c
index 07f378e5..f5f5cd60 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -1,7 +1,7 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
- * Copyright (C) Jay Sorg 2004-2012
+ * Copyright (C) Jay Sorg 2004-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,6 +60,7 @@
#include "os_calls.h"
#include "arch.h"
+#include "log.h"
/* for clearenv() */
#if defined(_WIN32)
@@ -426,29 +427,42 @@ g_tcp_set_keepalive(int sck)
/*****************************************************************************/
/* returns a newly created socket or -1 on error */
+/* in win32 a socket is an unsigned int, in linux, its an int */
int APP_CC
g_tcp_socket(void)
{
-#if defined(_WIN32)
int rv;
int option_value;
+#if defined(_WIN32)
int option_len;
#else
- int rv;
- int option_value;
unsigned int option_len;
#endif
- /* in win32 a socket is an unsigned int, in linux, its an int */
- rv = (int)socket(PF_INET, SOCK_STREAM, 0);
-
+#if 0 && !defined(NO_ARPA_INET_H_IP6)
+ rv = (int)socket(AF_INET6, SOCK_STREAM, 0);
+#else
+ rv = (int)socket(AF_INET, SOCK_STREAM, 0);
+#endif
if (rv < 0)
{
return -1;
}
-
+#if 0 && !defined(NO_ARPA_INET_H_IP6)
+ option_len = sizeof(option_value);
+ if (getsockopt(rv, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&option_value,
+ &option_len) == 0)
+ {
+ if (option_value != 0)
+ {
+ option_value = 0;
+ option_len = sizeof(option_value);
+ setsockopt(rv, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&option_value,
+ option_len);
+ }
+ }
+#endif
option_len = sizeof(option_value);
-
if (getsockopt(rv, SOL_SOCKET, SO_REUSEADDR, (char *)&option_value,
&option_len) == 0)
{
@@ -493,52 +507,109 @@ g_tcp_local_socket(void)
void APP_CC
g_tcp_close(int sck)
{
+ char ip[256];
+
if (sck == 0)
{
return;
}
-
#if defined(_WIN32)
closesocket(sck);
#else
+ g_write_ip_address(sck, ip, 255);
+ log_message(LOG_LEVEL_INFO, "An established connection closed to "
+ "endpoint: %s", ip);
close(sck);
#endif
}
/*****************************************************************************/
/* returns error, zero is good */
+#if 0
int APP_CC
g_tcp_connect(int sck, const char *address, const char *port)
{
- struct sockaddr_in s;
- struct hostent *h;
-
- g_memset(&s, 0, sizeof(struct sockaddr_in));
- s.sin_family = AF_INET;
- s.sin_port = htons((tui16)atoi(port));
- s.sin_addr.s_addr = inet_addr(address);
-
- if (s.sin_addr.s_addr == INADDR_NONE)
+ int res = 0;
+ struct addrinfo p;
+ struct addrinfo *h = (struct addrinfo *)NULL;
+ struct addrinfo *rp = (struct addrinfo *)NULL;
+
+ /* initialize (zero out) local variables: */
+ g_memset(&p, 0, sizeof(struct addrinfo));
+
+ /* in IPv6-enabled environments, set the AI_V4MAPPED
+ * flag in ai_flags and specify ai_family=AF_INET6 in
+ * order to ensure that getaddrinfo() returns any
+ * available IPv4-mapped addresses in case the target
+ * host does not have a true IPv6 address:
+ */
+ p.ai_socktype = SOCK_STREAM;
+ p.ai_protocol = IPPROTO_TCP;
+#if !defined(NO_ARPA_INET_H_IP6)
+ p.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;
+ p.ai_family = AF_INET6;
+ if (g_strcmp(address, "127.0.0.1") == 0)
+ {
+ res = getaddrinfo("::1", port, &p, &h);
+ }
+ else
{
- h = gethostbyname(address);
-
- if (h != 0)
+ res = getaddrinfo(address, port, &p, &h);
+ }
+#else
+ p.ai_flags = AI_ADDRCONFIG;
+ p.ai_family = AF_INET;
+ res = getaddrinfo(address, port, &p, &h);
+#endif
+ if (res > -1)
+ {
+ if (h != NULL)
{
- if (h->h_name != 0)
+ for (rp = h; rp != NULL; rp = rp->ai_next)
{
- if (h->h_addr_list != 0)
+ rp = h;
+ res = connect(sck, (struct sockaddr *)(rp->ai_addr),
+ rp->ai_addrlen);
+ if (res != -1)
{
- if ((*(h->h_addr_list)) != 0)
- {
- s.sin_addr.s_addr = *((int *)(*(h->h_addr_list)));
- }
+ break; /* Success */
}
}
}
}
+ return res;
+}
+#else
+int APP_CC
+g_tcp_connect(int sck, const char* address, const char* port)
+{
+ struct sockaddr_in s;
+ struct hostent* h;
- return connect(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_in));
+ g_memset(&s, 0, sizeof(struct sockaddr_in));
+ s.sin_family = AF_INET;
+ s.sin_port = htons((tui16)atoi(port));
+ s.sin_addr.s_addr = inet_addr(address);
+ if (s.sin_addr.s_addr == INADDR_NONE)
+ {
+ h = gethostbyname(address);
+ if (h != 0)
+ {
+ if (h->h_name != 0)
+ {
+ if (h->h_addr_list != 0)
+ {
+ if ((*(h->h_addr_list)) != 0)
+ {
+ s.sin_addr.s_addr = *((int*)(*(h->h_addr_list)));
+ }
+ }
+ }
+ }
+ }
+ return connect(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
}
+#endif
/*****************************************************************************/
/* returns error, zero is good */
@@ -574,23 +645,133 @@ g_tcp_set_non_blocking(int sck)
return 0;
}
+#if 0
+/*****************************************************************************/
+/* return boolean */
+static int APP_CC
+address_match(const char *address, struct addrinfo *j)
+{
+ struct sockaddr_in *ipv4_in;
+ struct sockaddr_in6 *ipv6_in;
+
+ if (address == 0)
+ {
+ return 1;
+ }
+ if (address[0] == 0)
+ {
+ return 1;
+ }
+ if (g_strcmp(address, "0.0.0.0") == 0)
+ {
+ return 1;
+ }
+ if ((g_strcmp(address, "127.0.0.1") == 0) ||
+ (g_strcmp(address, "::1") == 0) ||
+ (g_strcmp(address, "localhost") == 0))
+ {
+ if (j->ai_addr != 0)
+ {
+ if (j->ai_addr->sa_family == AF_INET)
+ {
+ ipv4_in = (struct sockaddr_in *) (j->ai_addr);
+ if (inet_pton(AF_INET, "127.0.0.1", &(ipv4_in->sin_addr)))
+ {
+ return 1;
+ }
+ }
+ if (j->ai_addr->sa_family == AF_INET6)
+ {
+ ipv6_in = (struct sockaddr_in6 *) (j->ai_addr);
+ if (inet_pton(AF_INET6, "::1", &(ipv6_in->sin6_addr)))
+ {
+ return 1;
+ }
+ }
+ }
+ }
+ if (j->ai_addr != 0)
+ {
+ if (j->ai_addr->sa_family == AF_INET)
+ {
+ ipv4_in = (struct sockaddr_in *) (j->ai_addr);
+ if (inet_pton(AF_INET, address, &(ipv4_in->sin_addr)))
+ {
+ return 1;
+ }
+ }
+ if (j->ai_addr->sa_family == AF_INET6)
+ {
+ ipv6_in = (struct sockaddr_in6 *) (j->ai_addr);
+ if (inet_pton(AF_INET6, address, &(ipv6_in->sin6_addr)))
+ {
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+#endif
+
+#if 0
+/*****************************************************************************/
+/* returns error, zero is good */
+static int APP_CC
+g_tcp_bind_flags(int sck, const char *port, const char *address, int flags)
+{
+ int res;
+ int error;
+ struct addrinfo hints;
+ struct addrinfo *i;
+
+ res = -1;
+ g_memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_flags = flags;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+ error = getaddrinfo(NULL, port, &hints, &i);
+ if (error == 0)
+ {
+ while ((i != 0) && (res < 0))
+ {
+ if (address_match(address, i))
+ {
+ res = bind(sck, i->ai_addr, i->ai_addrlen);
+ }
+ i = i->ai_next;
+ }
+ }
+ return res;
+}
+
/*****************************************************************************/
/* returns error, zero is good */
int APP_CC
-g_tcp_bind(int sck, char *port)
+g_tcp_bind(int sck, const char *port)
{
- struct sockaddr_in s;
+ int flags;
+
+ flags = AI_ADDRCONFIG | AI_PASSIVE;
+ return g_tcp_bind_flags(sck, port, 0, flags);
+}
+#else
+int APP_CC
+g_tcp_bind(int sck, const char* port)
+{
+ struct sockaddr_in s;
- memset(&s, 0, sizeof(struct sockaddr_in));
- s.sin_family = AF_INET;
- s.sin_port = htons((tui16)atoi(port));
- s.sin_addr.s_addr = INADDR_ANY;
- return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_in));
+ memset(&s, 0, sizeof(struct sockaddr_in));
+ s.sin_family = AF_INET;
+ s.sin_port = htons((tui16)atoi(port));
+ s.sin_addr.s_addr = INADDR_ANY;
+ return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
}
+#endif
/*****************************************************************************/
int APP_CC
-g_tcp_local_bind(int sck, char *port)
+g_tcp_local_bind(int sck, const char *port)
{
#if defined(_WIN32)
return -1;
@@ -604,25 +785,34 @@ g_tcp_local_bind(int sck, char *port)
#endif
}
+#if 0
/*****************************************************************************/
/* returns error, zero is good */
int APP_CC
-g_tcp_bind_address(int sck, char *port, const char *address)
+g_tcp_bind_address(int sck, const char *port, const char *address)
{
- struct sockaddr_in s;
-
- memset(&s, 0, sizeof(struct sockaddr_in));
- s.sin_family = AF_INET;
- s.sin_port = htons((tui16)atoi(port));
- s.sin_addr.s_addr = INADDR_ANY;
+ int flags;
- if (inet_aton(address, &s.sin_addr) < 0)
- {
- return -1; /* bad address */
- }
+ flags = AI_ADDRCONFIG | AI_PASSIVE;
+ return g_tcp_bind_flags(sck, port, address, flags);
+}
+#else
+int APP_CC
+g_tcp_bind_address(int sck, const char* port, const char* address)
+{
+ struct sockaddr_in s;
- return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_in));
+ memset(&s, 0, sizeof(struct sockaddr_in));
+ s.sin_family = AF_INET;
+ s.sin_port = htons((tui16)atoi(port));
+ s.sin_addr.s_addr = INADDR_ANY;
+ if (inet_aton(address, &s.sin_addr) < 0)
+ {
+ return -1; /* bad address */
+ }
+ return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
}
+#endif
/*****************************************************************************/
/* returns error, zero is good */
@@ -636,6 +826,8 @@ g_tcp_listen(int sck)
int APP_CC
g_tcp_accept(int sck)
{
+ int ret ;
+ char ipAddr[256] ;
struct sockaddr_in s;
#if defined(_WIN32)
signed int i;
@@ -645,7 +837,14 @@ g_tcp_accept(int sck)
i = sizeof(struct sockaddr_in);
memset(&s, 0, i);
- return accept(sck, (struct sockaddr *)&s, &i);
+ ret = accept(sck, (struct sockaddr *)&s, &i);
+ if(ret>0)
+ {
+ snprintf(ipAddr,255,"A connection received from: %s port %d"
+ ,inet_ntoa(s.sin_addr),ntohs(s.sin_port));
+ log_message(LOG_LEVEL_INFO,ipAddr);
+ }
+ return ret ;
}
/*****************************************************************************/
@@ -2004,7 +2203,7 @@ g_htoi(char *str)
/*****************************************************************************/
int APP_CC
-g_pos(char *str, const char *to_find)
+g_pos(const char *str, const char *to_find)
{
char *pp;
diff --git a/common/os_calls.h b/common/os_calls.h
index d4b86365..5844df27 100644
--- a/common/os_calls.h
+++ b/common/os_calls.h
@@ -1,7 +1,7 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
- * Copyright (C) Jay Sorg 2004-2012
+ * Copyright (C) Jay Sorg 2004-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,11 +78,11 @@ g_tcp_force_recv(int sck, char* data, int len);
int APP_CC
g_tcp_set_non_blocking(int sck);
int APP_CC
-g_tcp_bind(int sck, char* port);
+g_tcp_bind(int sck, const char *port);
int APP_CC
-g_tcp_local_bind(int sck, char* port);
+g_tcp_local_bind(int sck, const char* port);
int APP_CC
-g_tcp_bind_address(int sck, char* port, const char* address);
+g_tcp_bind_address(int sck, const char* port, const char* address);
int APP_CC
g_tcp_listen(int sck);
int APP_CC
@@ -196,7 +196,7 @@ g_atoi(const char* str);
int APP_CC
g_htoi(char* str);
int APP_CC
-g_pos(char* str, const char* to_find);
+g_pos(const char* str, const char* to_find);
int APP_CC
g_mbstowcs(twchar* dest, const char* src, int n);
int APP_CC
diff --git a/common/parse.h b/common/parse.h
index deee7845..49c2fa23 100644
--- a/common/parse.h
+++ b/common/parse.h
@@ -101,7 +101,6 @@ struct stream
#define s_mark_end(s) \
(s)->end = (s)->p
-/******************************************************************************/
#define in_sint8(s, v) do \
{ \
(v) = *((signed char*)((s)->p)); \
@@ -303,4 +302,102 @@ struct stream
(s)->p += (n); \
} while (0)
+/*
+ * @brief allocate a new stream
+ *
+ * @param _s opaque handle to the new stream
+ * @param _l length of new stream
+ ******************************************************************************/
+#define xstream_new(_s, _l) \
+do \
+{ \
+ make_stream((_s)); \
+ init_stream((_s), (_l)); \
+} while (0)
+
+/**
+ * @brief release a previously allocated stream
+ *
+ * @param _s opaque handle returned by stream_new()
+ *****************************************************************************/
+#define xstream_free(_s) free_stream(_s)
+
+#define xstream_rd_u8(_s, _var) in_uint8(_s, _var)
+#define xstream_rd_u16_le(_s, _var) in_uint16_le(_s, _var)
+#define xstream_rd_u32_le(_s, _var) in_uint32_le(_s, _var)
+
+#define xstream_rd_s8_le(_s, _var) in_sint8(_s, _var)
+#define xstream_rd_s16_le(_s, _var) in_sint16_le(_s, _var)
+#define xstream_rd_s32_le(_s, _var) TODO
+
+#define xstream_wr_u8(_s, _var) out_uint8(_s, _var)
+#define xstream_wr_u16_le(_s, _var) out_uint16_le(_s, _var)
+#define xstream_wr_u32_le(_s, _var) out_uint32_le(_s, _var)
+
+#define xstream_wr_s8(_s, _var) TODO
+#define xstream_wr_s16_le(_s, _var) TODO
+#define xstream_wr_s32_le(_s, _var) TODO
+
+#define xstream_rd_u64_le(_s, _v) \
+do \
+{ \
+ _v = \
+ (tui64)(*((unsigned char *)_s->p)) | \
+ (((tui64) (*(((unsigned char *)_s->p) + 1))) << 8) | \
+ (((tui64) (*(((unsigned char *)_s->p) + 2))) << 16) | \
+ (((tui64) (*(((unsigned char *)_s->p) + 3))) << 24) | \
+ (((tui64) (*(((unsigned char *)_s->p) + 4))) << 32) | \
+ (((tui64) (*(((unsigned char *)_s->p) + 5))) << 40) | \
+ (((tui64) (*(((unsigned char *)_s->p) + 6))) << 48) | \
+ (((tui64) (*(((unsigned char *)_s->p) + 7))) << 56); \
+ _s->p += 8; \
+} while (0)
+
+#define xstream_wr_u64_le(_s, _v) \
+do \
+{ \
+ *(((unsigned char *) _s->p) + 0) = (unsigned char) ((_v >> 0) & 0xff); \
+ *(((unsigned char *) _s->p) + 1) = (unsigned char) ((_v >> 8) & 0xff); \
+ *(((unsigned char *) _s->p) + 2) = (unsigned char) ((_v >> 16) & 0xff); \
+ *(((unsigned char *) _s->p) + 3) = (unsigned char) ((_v >> 24) & 0xff); \
+ *(((unsigned char *) _s->p) + 4) = (unsigned char) ((_v >> 32) & 0xff); \
+ *(((unsigned char *) _s->p) + 5) = (unsigned char) ((_v >> 40) & 0xff); \
+ *(((unsigned char *) _s->p) + 6) = (unsigned char) ((_v >> 48) & 0xff); \
+ *(((unsigned char *) _s->p) + 7) = (unsigned char) ((_v >> 56) & 0xff); \
+ _s->p += 8; \
+} while (0)
+
+/* copy data into stream */
+#define xstream_copyin(_s, _dest, _len) \
+do \
+{ \
+ g_memcpy((_s)->p, (_dest), (_len)); \
+ (_s)->p += (_len); \
+} while (0)
+
+/* copy data out of stream */
+#define xstream_copyout(_dest, _s, _len) \
+do \
+{ \
+ g_memcpy((_dest), (_s)->p, (_len)); \
+ (_s)->p += (_len); \
+} while (0)
+
+#define xstream_rd_string(_dest, _s, _len) \
+do \
+{ \
+ g_memcpy((_dest), (_s)->p, (_len)); \
+ (_s)->p += (_len); \
+} while (0)
+
+#define xstream_wr_string(_s, _src, _len) \
+do \
+{ \
+ g_memcpy((_s)->p, (_src), (_len)); \
+ (_s)->p += (_len); \
+} while (0)
+
+#define xstream_len(_s) (int) ((_s)->p - (_s)->data)
+#define xstream_seek(_s, _len) (_s)->p += (_len)
+
#endif
diff --git a/common/trans.h b/common/trans.h
index 36d08a7c..1133477a 100644
--- a/common/trans.h
+++ b/common/trans.h
@@ -41,7 +41,7 @@ typedef int (*ttrans_conn_in)(struct trans* self, struct trans* new_self);
struct trans
{
- tbus sck;
+ tbus sck; /* socket handle */
int mode; /* 1 tcp, 2 unix socket */
int status;
int type1; /* 1 listener 2 server 3 client */
diff --git a/common/xrdp_client_info.h b/common/xrdp_client_info.h
index a364927d..591d49d7 100644
--- a/common/xrdp_client_info.h
+++ b/common/xrdp_client_info.h
@@ -1,7 +1,7 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
- * Copyright (C) Jay Sorg 2004-2012
+ * Copyright (C) Jay Sorg 2004-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -86,7 +86,11 @@ struct xrdp_client_info
int jpeg_prop_len;
char jpeg_prop[64];
int v3_codec_id;
+ int rfx_min_pixel;
+ char orders[32];
+ int order_flags_ex;
int use_bulk_comp;
+ int pointer_flags; /* 0 color, 1 new */
};
#endif
diff --git a/common/xrdp_constants.h b/common/xrdp_constants.h
index 1aa18eb5..d6ea3a96 100644
--- a/common/xrdp_constants.h
+++ b/common/xrdp_constants.h
@@ -126,6 +126,7 @@
#define RDP_POINTER_MOVE 3
#define RDP_POINTER_COLOR 6
#define RDP_POINTER_CACHED 7
+#define RDP_POINTER_POINTER 8
#define RDP_NULL_POINTER 0
#define RDP_DEFAULT_POINTER 0x7F00