Browse Source

Imported Upstream version 0.9.0~20160601+git703fedd

tags/upstream/0.9.0_20160601+git703fedd^0
Dominik George 5 years ago
parent
commit
8457b7d6ce
No known key found for this signature in database GPG Key ID: B79A3C16A0C4F296
100 changed files with 9395 additions and 1169 deletions
  1. BIN
      Coding_Style.odt
  2. +5
    -1
      Makefile.am
  3. +0
    -6
      bootstrap
  4. +195
    -0
      coding_style.md
  5. +23
    -25
      common/Makefile.am
  6. +1
    -1
      common/arch.h
  7. +64
    -82
      common/file.c
  8. +2
    -2
      common/file_loc.h
  9. +2
    -2
      common/list.c
  10. +9
    -2
      common/log.c
  11. +1
    -1
      common/log.h
  12. +242
    -286
      common/os_calls.c
  13. +55
    -30
      common/os_calls.h
  14. +22
    -14
      common/ssl_calls.c
  15. +15
    -0
      common/thread_calls.c
  16. +22
    -15
      common/trans.c
  17. +1
    -0
      common/xrdp_client_info.h
  18. +6
    -6
      common/xrdp_constants.h
  19. +34
    -14
      configure.ac
  20. +1
    -1
      design.txt
  21. +2
    -2
      docs/man/Makefile.am
  22. +1
    -1
      docs/man/xrdp-sessvc.8
  23. +4
    -0
      docs/man/xrdp.ini.5
  24. +1
    -0
      fontdump/.gitignore
  25. +0
    -0
      fontdump/Makefile
  26. +0
    -0
      fontdump/fontdump.c
  27. +5
    -2
      genkeymap/Makefile.am
  28. +8
    -8
      genkeymap/genkeymap.c
  29. +3
    -3
      install.txt
  30. +18
    -21
      instfiles/Makefile.am
  31. +2
    -3
      instfiles/default/Makefile.am
  32. +2
    -4
      instfiles/init.d/Makefile.am
  33. +2
    -15
      instfiles/init.d/xrdp
  34. +16
    -16
      instfiles/km-0411.ini
  35. +659
    -0
      instfiles/km-100c.ini
  36. +16
    -16
      instfiles/km-e0010411.ini
  37. +16
    -16
      instfiles/km-e0200411.ini
  38. +16
    -16
      instfiles/km-e0210411.ini
  39. +19
    -2
      instfiles/pam.d/Makefile.am
  40. +0
    -1
      instfiles/pam.d/xrdp-sesman.common
  41. +4
    -0
      instfiles/pam.d/xrdp-sesman.password-auth
  42. +2
    -3
      instfiles/pulse/Makefile.am
  43. +2
    -4
      instfiles/rc.d/Makefile.am
  44. +23
    -4
      instfiles/rc.d/xrdp
  45. +2
    -1
      instfiles/xrdp-sesman.service
  46. +3
    -2
      instfiles/xrdp.service
  47. +11
    -4
      keygen/Makefile.am
  48. +10
    -11
      keygen/keygen.c
  49. +31
    -0
      librfxcodec/.gitignore
  50. +0
    -12
      librfxcodec/Makefile
  51. +6
    -0
      librfxcodec/Makefile.am
  52. +137
    -0
      librfxcodec/acinclude.m4
  53. +36
    -0
      librfxcodec/bootstrap
  54. +55
    -0
      librfxcodec/configure.ac
  55. +40
    -0
      librfxcodec/include/rfxcodec_common.h
  56. +13
    -36
      librfxcodec/include/rfxcodec_decode.h
  57. +19
    -23
      librfxcodec/include/rfxcodec_encode.h
  58. +0
    -48
      librfxcodec/src/Makefile
  59. +55
    -0
      librfxcodec/src/Makefile.am
  60. +7
    -3
      librfxcodec/src/amd64/cpuid_amd64.asm
  61. +31
    -5
      librfxcodec/src/amd64/funcs_amd64.h
  62. +33
    -0
      librfxcodec/src/amd64/rfxcodec_encode_diff_rlgr1_amd64_sse2.asm
  63. +26
    -0
      librfxcodec/src/amd64/rfxcodec_encode_diff_rlgr3_amd64_sse2.asm
  64. +1499
    -0
      librfxcodec/src/amd64/rfxcodec_encode_dwt_shift_amd64_sse2.asm
  65. +1367
    -0
      librfxcodec/src/amd64/rfxcodec_encode_dwt_shift_amd64_sse41.asm
  66. +0
    -22
      librfxcodec/src/amd64/rfxdwt_amd64_sse2.asm
  67. +0
    -21
      librfxcodec/src/amd64/rfxrlgr1_amd64.asm
  68. +0
    -21
      librfxcodec/src/amd64/rfxrlgr3_amd64.asm
  69. +57
    -0
      librfxcodec/src/nasm_lt.sh
  70. +3
    -1
      librfxcodec/src/rfxcommon.h
  71. +211
    -58
      librfxcodec/src/rfxcompose.c
  72. +4
    -4
      librfxcodec/src/rfxcompose.h
  73. +1
    -0
      librfxcodec/src/rfxconstants.h
  74. +122
    -19
      librfxcodec/src/rfxencode.c
  75. +13
    -10
      librfxcodec/src/rfxencode.h
  76. +279
    -0
      librfxcodec/src/rfxencode_alpha.c
  77. +28
    -0
      librfxcodec/src/rfxencode_alpha.h
  78. +20
    -7
      librfxcodec/src/rfxencode_dwt.c
  79. +1
    -1
      librfxcodec/src/rfxencode_dwt.h
  80. +47
    -13
      librfxcodec/src/rfxencode_quantization.c
  81. +1
    -1
      librfxcodec/src/rfxencode_quantization.h
  82. +3
    -1
      librfxcodec/src/rfxencode_rlgr1.c
  83. +1
    -1
      librfxcodec/src/rfxencode_rlgr1.h
  84. +3
    -1
      librfxcodec/src/rfxencode_rlgr3.c
  85. +1
    -1
      librfxcodec/src/rfxencode_rlgr3.h
  86. +562
    -65
      librfxcodec/src/rfxencode_tile.c
  87. +48
    -21
      librfxcodec/src/rfxencode_tile.h
  88. +4
    -0
      librfxcodec/src/x86/cpuid_x86.asm
  89. +26
    -5
      librfxcodec/src/x86/funcs_x86.h
  90. +0
    -0
      librfxcodec/src/x86/readme.txt
  91. +30
    -0
      librfxcodec/src/x86/rfxcodec_encode_diff_rlgr1_x86_sse2.asm
  92. +30
    -0
      librfxcodec/src/x86/rfxcodec_encode_diff_rlgr3_x86_sse2.asm
  93. +1529
    -0
      librfxcodec/src/x86/rfxcodec_encode_dwt_shift_x86_sse2.asm
  94. +1397
    -0
      librfxcodec/src/x86/rfxcodec_encode_dwt_shift_x86_sse41.asm
  95. +0
    -26
      librfxcodec/src/x86/rfxdwt_x86_sse2.asm
  96. +0
    -25
      librfxcodec/src/x86/rfxrlgr1_x86.asm
  97. +0
    -25
      librfxcodec/src/x86/rfxrlgr3_x86.asm
  98. +0
    -22
      librfxcodec/tests/Makefile
  99. +25
    -0
      librfxcodec/tests/Makefile.am
  100. +47
    -28
      librfxcodec/tests/rfxcodectest.c

BIN
Coding_Style.odt View File


+ 5
- 1
Makefile.am View File

@@ -1,4 +1,8 @@
EXTRA_DIST = bootstrap COPYING design.txt faq-compile.txt faq-general.txt file-loc.txt install.txt prog_std.txt readme.txt
ACLOCAL_AMFLAGS = -I m4
AM_DISTCHECK_CONFIGURE_FLAGS = --without-systemdsystemunitdir

EXTRA_DIST = bootstrap COPYING coding_style.md design.txt faq-compile.txt \
faq-general.txt file-loc.txt install.txt m4 prog_std.txt readme.txt

if XRDP_NEUTRINORDP
NEUTRINORDPDIR = neutrinordp


+ 0
- 6
bootstrap View File

@@ -28,10 +28,4 @@ then
exit 1
fi

touch configure.ac
touch NEWS
touch AUTHORS
touch README
touch ChangeLog
ln -s ../config.c $PWD/sesman/tools/config.c
autoreconf -fvi

+ 195
- 0
coding_style.md View File

@@ -0,0 +1,195 @@
XRdp Coding Style
=================

The coding style used by XRdp is described below.

The XRdp project uses astyle (artistic style) to format the code. Astyle
requires a configuration file that describes how you want your code
formatted. This file is present in the XRdp root directory and is named
`astyle_config.as`.

Here is how we run the astyle command:

astyle --options=/path/to/file/astyle_config.as "*.c"

This coding style is a work in progress and is still evolving.


Indentation
-----------

* 4 spaces per indent
* No tabs for any indents


if (fd < 0)
{
return -1;
}


Line wrapping
-------------

* Keep lines shorter than 80 chars
* Align wrapped argument to the first argument


log_message("connection aborted: error %d",
ret);


Variable names
--------------

* Use lowercase with underscores as needed
* Don't use camelCase


int fd;
int bytes_in_stream;


Variable declaration
--------------------

* Each variable is declared on a separate line


int i;
int j;


Whitespace
----------

* Use blank lines to group statements
* Use at most one empty line between statements
* For pointers and references, use a single space before * or & but not after
* Use one space after a cast
* No space before square brackets


char *cptr;
int *iptr;
cptr = (char *) malloc(1024);

write(fd, &buf[12], 16);


Function declarations
---------------------

* Use newline before function name


static int
value_ok(int val)
{
return (val >= 0);
}


Braces
------

* Opening brace is always on a separate line
* Align braces with the line preceding the opening brace


struct stream
{
int flags;
char *data;
};

void
process_data(struct stream *s)
{
if (stream == NULL)
{
return;
}
}


`if` statements
---------------

* Always use braces
* Put both braces on separate lines


if (val <= 0xff)
{
out_uint8(s, val);
}
else if (val <= 0xffff)
{
out_uint16_le(s, val);
}
else
{
out_uint32_le(s, val);
}


`for` statements
----------------

* Always use braces
* Put both braces on separate lines


for (i = 0; i < 10; i++)
{
printf("i = %d\n", i);
}


`while` and `do while` statements
---------------------------------

* Always use braces
* `while` after the closing brace is on the same line


while (cptr)
{
cptr—;
}

do
{
cptr--;
} while (cptr);


`switch` statements
-------------------

* Indent `case` once
* Indent statements under `case` one more time
* Put both braces on separate lines


switch (cmd)
{
case READ:
read(fd, buf, 1024);
break;

default:
printf("bad cmd\n");
}

+ 23
- 25
common/Makefile.am View File

@@ -1,44 +1,42 @@
EXTRA_DIST = \
arch.h \
defines.h \
file.h \
file_loc.h \
list.h \
list16.h \
fifo.h \
log.h \
os_calls.h \
os_calls.h \
parse.h \
rail.h \
ssl_calls.h \
thread_calls.h \
trans.h \
xrdp_client_info.h \
xrdp_constants.h \
xrdp_rail.h \
crc16.h

AM_CFLAGS = \
AM_CPPFLAGS = \
-DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \
-DXRDP_SBIN_PATH=\"${sbindir}\" \
-DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \
-DXRDP_PID_PATH=\"${localstatedir}/run\" \
-DXRDP_LOG_PATH=\"${localstatedir}/log\"

lib_LTLIBRARIES = \
module_LTLIBRARIES = \
libcommon.la

libcommon_la_SOURCES = \
arch.h \
crc16.h \
defines.h \
fifo.c \
fifo.h \
file.c \
file.h \
file_loc.h \
list.c \
list.h \
list16.c \
fifo.c \
list16.h \
log.c \
log.h \
os_calls.c \
os_calls.h \
os_calls.h \
parse.h \
rail.h \
ssl_calls.c \
ssl_calls.h \
thread_calls.c \
trans.c
thread_calls.h \
trans.c \
trans.h \
xrdp_client_info.h \
xrdp_constants.h \
xrdp_rail.h

libcommon_la_LIBADD = \
-lcrypto \


+ 1
- 1
common/arch.h View File

@@ -22,7 +22,7 @@
/* you can define L_ENDIAN or B_ENDIAN and NEED_ALIGN or NO_NEED_ALIGN
in the makefile to override */

/* check endianess */
/* check endianness */
#if !(defined(L_ENDIAN) || defined(B_ENDIAN))
#if !defined(__BYTE_ORDER) && defined(__linux__)
#include <endian.h>


+ 64
- 82
common/file.c View File

@@ -26,6 +26,48 @@

#define FILE_MAX_LINE_BYTES 2048

static int APP_CC
file_read_ini_line(struct stream *s, char *text, int text_bytes);

/*****************************************************************************/
/* look up for a section name within str (i.e. pattern [section_name])
* if a section name is found, this function return 1 and copy the section
* inplace of str. */
static int APP_CC
line_lookup_for_section_name(char *str, int str_bytes)
{
int name_index_start;
int index;
char c;

name_index_start = -1;
index = 0;
while ((c = str[index]) != 0)
{
if (c == '[')
{
name_index_start = index + 1;
}
else if (c == ']' && name_index_start > 0)
{
if (name_index_start + index >= str_bytes)
{
return 0;
}
for (index = index - name_index_start; index > 0; index--)
{
str[0] = str[name_index_start];
str++;
}
str[0] = 0;
return 1;
}
++index;
}
return 0;
}


/*****************************************************************************/
/* returns error
returns 0 if everything is ok
@@ -35,17 +77,11 @@ l_file_read_sections(int fd, int max_file_size, struct list *names)
{
struct stream *s;
char text[FILE_MAX_LINE_BYTES];
char c;
int in_it;
int in_it_index;
int len;
int index;
int rv;

rv = 0;
g_file_seek(fd, 0);
in_it_index = 0;
in_it = 0;
g_memset(text, 0, FILE_MAX_LINE_BYTES);
list_clear(names);
make_stream(s);
@@ -55,26 +91,11 @@ l_file_read_sections(int fd, int max_file_size, struct list *names)
if (len > 0)
{
s->end = s->p + len;

for (index = 0; index < len; index++)
while (file_read_ini_line(s, text, FILE_MAX_LINE_BYTES) == 0)
{
in_uint8(s, c);

if (c == '[')
{
in_it = 1;
}
else if (c == ']')
if (line_lookup_for_section_name(text, FILE_MAX_LINE_BYTES) != 0)
{
list_add_item(names, (tbus)g_strdup(text));
in_it = 0;
in_it_index = 0;
g_memset(text, 0, FILE_MAX_LINE_BYTES);
}
else if (in_it)
{
text[in_it_index] = c;
in_it_index++;
}
}
}
@@ -88,15 +109,17 @@ l_file_read_sections(int fd, int max_file_size, struct list *names)
}

/*****************************************************************************/
/* returns error */
/* Read a line in the stream 's', removing comments.
* returns error
* returns 0 if everything is ok
* returns 1 if problem reading file */
static int APP_CC
file_read_line(struct stream *s, char *text, int text_bytes)
file_read_ini_line(struct stream *s, char *text, int text_bytes)
{
int i;
int skip_to_end;
int at_end;
char c;
char *hold;

skip_to_end = 0;

@@ -105,7 +128,6 @@ file_read_line(struct stream *s, char *text, int text_bytes)
return 1;
}

hold = s->p;
i = 0;
in_uint8(s, c);

@@ -163,15 +185,10 @@ file_read_line(struct stream *s, char *text, int text_bytes)

text[i] = 0;

if (text[0] == '[')
{
s->p = hold;
return 1;
}

return 0;
}


/*****************************************************************************/
/* returns error */
static int APP_CC
@@ -227,11 +244,7 @@ l_file_read_section(int fd, int max_file_size, const char *section,
char *name;
char *value;
char *lvalue;
char c;
int in_it;
int in_it_index;
int len;
int index;
int file_size;

data = (char *) g_malloc(FILE_MAX_LINE_BYTES * 3, 0);
@@ -241,8 +254,6 @@ l_file_read_section(int fd, int max_file_size, const char *section,

file_size = 32 * 1024; /* 32 K file size limit */
g_file_seek(fd, 0);
in_it_index = 0;
in_it = 0;
g_memset(text, 0, FILE_MAX_LINE_BYTES);
list_clear(names);
list_clear(values);
@@ -253,36 +264,20 @@ l_file_read_section(int fd, int max_file_size, const char *section,
if (len > 0)
{
s->end = s->p + len;

for (index = 0; index < len; index++)
while (file_read_ini_line(s, text, FILE_MAX_LINE_BYTES) == 0)
{
if (!s_check_rem(s, 1))
{
break;
}
in_uint8(s, c);
if ((c == '#') || (c == ';'))
{
if (file_read_line(s, text, FILE_MAX_LINE_BYTES) != 0)
{
break;
}
in_it = 0;
in_it_index = 0;
g_memset(text, 0, FILE_MAX_LINE_BYTES);
continue;
}
if (c == '[')
{
in_it = 1;
}
else if (c == ']')
if (line_lookup_for_section_name(text, FILE_MAX_LINE_BYTES) != 0)
{
if (g_strcasecmp(section, text) == 0)
{
file_read_line(s, text, FILE_MAX_LINE_BYTES);
while (file_read_line(s, text, FILE_MAX_LINE_BYTES) == 0)
while (file_read_ini_line(s, text,
FILE_MAX_LINE_BYTES) == 0)
{
if (line_lookup_for_section_name(text, FILE_MAX_LINE_BYTES) != 0)
{
break;
}

if (g_strlen(text) > 0)
{
file_split_name_value(text, name, value);
@@ -307,27 +302,14 @@ l_file_read_section(int fd, int max_file_size, const char *section,
}
}
}

free_stream(s);
g_free(data);
return 0;
}

in_it = 0;
in_it_index = 0;
g_memset(text, 0, FILE_MAX_LINE_BYTES);
}
else if (in_it)
{
text[in_it_index] = c;
in_it_index++;
if (in_it_index >= FILE_MAX_LINE_BYTES)
{
break;
}
}
}
}

free_stream(s);
g_free(data);
return 1;
@@ -346,7 +328,7 @@ file_read_sections(int fd, struct list *names)

/*****************************************************************************/
/* return error */
/* this function should be prefered over file_read_sections because it can
/* this function should be preferred over file_read_sections because it can
read any file size */
int APP_CC
file_by_name_read_sections(const char *file_name, struct list *names)
@@ -362,7 +344,7 @@ file_by_name_read_sections(const char *file_name, struct list *names)
return 1;
}

fd = g_file_open(file_name);
fd = g_file_open_ex(file_name, 1, 0, 0, 0);

if (fd < 0)
{
@@ -386,7 +368,7 @@ file_read_section(int fd, const char *section,

/*****************************************************************************/
/* return error */
/* this function should be prefered over file_read_section because it can
/* this function should be preferred over file_read_section because it can
read any file size */
int APP_CC
file_by_name_read_section(const char *file_name, const char *section,
@@ -403,7 +385,7 @@ file_by_name_read_section(const char *file_name, const char *section,
return 1;
}

fd = g_file_open(file_name);
fd = g_file_open_ex(file_name, 1, 0, 0, 0);

if (fd < 0)
{


+ 2
- 2
common/file_loc.h View File

@@ -37,8 +37,8 @@
#define XRDP_SHARE_PATH "/usr/local/share/xrdp"
#endif

#if !defined(XRDP_LIB_PATH)
#define XRDP_LIB_PATH "/usr/local/lib/xrdp"
#if !defined(XRDP_MODULE_PATH)
#define XRDP_MODULE_PATH "/usr/local/lib/xrdp"
#endif

#if !defined(XRDP_LOG_PATH)


+ 2
- 2
common/list.c View File

@@ -192,7 +192,7 @@ list_insert_item(struct list *self, int index, tbus item)

/*****************************************************************************/
/* append one list to another using strdup for each item in the list */
/* begins copy at start_index, a zero based index on the soure list */
/* begins copy at start_index, a zero based index on the source list */
void APP_CC
list_append_list_strdup(struct list *self, struct list *dest, int start_index)
{
@@ -221,6 +221,6 @@ list_dump_items(struct list *self)

for (index = 0; index < self->count; index++)
{
g_writeln("%d: %s", index, list_get_item(self, index));
g_writeln("%d: 0x%lx", index, list_get_item(self, index));
}
}

+ 9
- 2
common/log.c View File

@@ -59,6 +59,13 @@ internal_log_file_open(const char *fname)
S_IRUSR | S_IWUSR);
}

#ifdef FD_CLOEXEC
if (ret != -1)
{
fcntl(ret, F_SETFD, FD_CLOEXEC);
}
#endif

return ret;
}

@@ -142,7 +149,7 @@ internal_log_start(struct log_config *l_cfg)
return ret;
}

/* if progname is NULL, we ureturn error */
/* if progname is NULL, we return error */
if (0 == l_cfg->program_name)
{
g_writeln("program_name not properly assigned");
@@ -186,7 +193,7 @@ internal_log_end(struct log_config *l_cfg)
/* closing log file */
log_message(LOG_LEVEL_ALWAYS, "shutting down log subsystem...");

if (0 > l_cfg->fd)
if (-1 != l_cfg->fd)
{
/* closing logfile... */
g_file_close(l_cfg->fd);


+ 1
- 1
common/log.h View File

@@ -81,7 +81,7 @@ struct log_config
/**
*
* @brief Starts the logging subsystem
* @param l_cfg loggging system configuration
* @param l_cfg logging system configuration
* @return
*
*/


+ 242
- 286
common/os_calls.c View File

@@ -100,23 +100,10 @@ extern char **environ;
#define INADDR_NONE ((unsigned long)-1)
#endif

static char g_temp_base[128] = "";
static char g_temp_base_org[128] = "";

/*****************************************************************************/
int APP_CC
g_rm_temp_dir(void)
{
if (g_temp_base[0] != 0)
{
if (!g_remove_dir(g_temp_base))
{
printf("g_rm_temp_dir: removing temp directory [%s] failed\n", g_temp_base);
}

g_temp_base[0] = 0;
}

return 0;
}

@@ -124,58 +111,19 @@ g_rm_temp_dir(void)
int APP_CC
g_mk_temp_dir(const char *app_name)
{
if (app_name != 0)
if (!g_directory_exist("/tmp/.xrdp"))
{
if (app_name[0] != 0)
if (!g_create_dir("/tmp/.xrdp"))
{
/* if failed, still check if it got created by someone else */
if (!g_directory_exist("/tmp/.xrdp"))
{
if (!g_create_dir("/tmp/.xrdp"))
{
/* if failed, still check if it got created by someone else */
if (!g_directory_exist("/tmp/.xrdp"))
{
printf("g_mk_temp_dir: g_create_dir failed\n");
return 1;
}
}

g_chmod_hex("/tmp/.xrdp", 0x1777);
}

snprintf(g_temp_base, sizeof(g_temp_base),
"/tmp/.xrdp/%s-XXXXXX", app_name);
snprintf(g_temp_base_org, sizeof(g_temp_base_org),
"/tmp/.xrdp/%s-XXXXXX", app_name);

if (mkdtemp(g_temp_base) == 0)
{
printf("g_mk_temp_dir: mkdtemp failed [%s]\n", g_temp_base);
printf("g_mk_temp_dir: g_create_dir failed\n");
return 1;
}
}
else
{
printf("g_mk_temp_dir: bad app name\n");
return 1;
}
}
else
{
if (g_temp_base_org[0] == 0)
{
printf("g_mk_temp_dir: g_temp_base_org not set\n");
return 1;
}

g_strncpy(g_temp_base, g_temp_base_org, 127);

if (mkdtemp(g_temp_base) == 0)
{
printf("g_mk_temp_dir: mkdtemp failed [%s]\n", g_temp_base);
}
g_chmod_hex("/tmp/.xrdp", 0x1777);
}

return 0;
}

@@ -334,7 +282,7 @@ g_hexdump(char *p, int len)
g_printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
}

g_writeln("");
g_writeln("%s", "");
offset += thisline;
line += thisline;
}
@@ -463,7 +411,7 @@ g_tcp_socket(void)
unsigned int option_len;
#endif

#if defined(XRDP_ENABLE_IPV6) && !defined(NO_ARPA_INET_H_IP6)
#if defined(XRDP_ENABLE_IPV6)
rv = (int)socket(AF_INET6, SOCK_STREAM, 0);
#else
rv = (int)socket(AF_INET, SOCK_STREAM, 0);
@@ -472,14 +420,18 @@ g_tcp_socket(void)
{
return -1;
}
#if defined(XRDP_ENABLE_IPV6) && !defined(NO_ARPA_INET_H_IP6)
#if defined(XRDP_ENABLE_IPV6)
option_len = sizeof(option_value);
if (getsockopt(rv, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&option_value,
&option_len) == 0)
{
if (option_value != 0)
{
#if defined(XRDP_ENABLE_IPV6ONLY)
option_value = 1;
#else
option_value = 0;
#endif
option_len = sizeof(option_value);
if (setsockopt(rv, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&option_value,
option_len) < 0)
@@ -617,7 +569,7 @@ g_sck_get_recv_buffer_bytes(int sck, int *bytes)

/*****************************************************************************/
int APP_CC
g_tcp_local_socket(void)
g_sck_local_socket(void)
{
#if defined(_WIN32)
return 0;
@@ -691,7 +643,7 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid)

/*****************************************************************************/
void APP_CC
g_tcp_close(int sck)
g_sck_close(int sck)
{
char ip[256];

@@ -711,11 +663,12 @@ g_tcp_close(int sck)

/*****************************************************************************/
/* returns error, zero is good */
#if defined(XRDP_ENABLE_IPV6) && !defined(NO_ARPA_INET_H_IP6)
#if defined(XRDP_ENABLE_IPV6)
int APP_CC
g_tcp_connect(int sck, const char *address, const char *port)
{
int res = 0;
char errorMsg[256];
struct addrinfo p;
struct addrinfo *h = (struct addrinfo *)NULL;
struct addrinfo *rp = (struct addrinfo *)NULL;
@@ -741,6 +694,12 @@ g_tcp_connect(int sck, const char *address, const char *port)
{
res = getaddrinfo(address, port, &p, &h);
}
if (res != 0)
{
snprintf(errorMsg, 255, "g_tcp_connect: getaddrinfo() failed: %s",
gai_strerror(res));
log_message(LOG_LEVEL_ERROR, errorMsg);
}
if (res > -1)
{
if (h != NULL)
@@ -763,38 +722,38 @@ g_tcp_connect(int sck, const char *address, const char *port)
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)
{
h = gethostbyname(address);
if (h != 0)
{
if (h->h_name != 0)
{
if (h->h_addr_list != 0)
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)
{
h = gethostbyname(address);
if (h != 0)
{
if ((*(h->h_addr_list)) != 0)
{
s.sin_addr.s_addr = *((int*)(*(h->h_addr_list)));
}
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));
return connect(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
}
#endif

/*****************************************************************************/
/* returns error, zero is good */
int APP_CC
g_tcp_local_connect(int sck, const char *port)
g_sck_local_connect(int sck, const char *port)
{
#if defined(_WIN32)
return -1;
@@ -812,7 +771,7 @@ g_tcp_local_connect(int sck, const char *port)

/*****************************************************************************/
int APP_CC
g_tcp_set_non_blocking(int sck)
g_sck_set_non_blocking(int sck)
{
unsigned long i;

@@ -824,7 +783,7 @@ g_tcp_set_non_blocking(int sck)
i = i | O_NONBLOCK;
if (fcntl(sck, F_SETFL, i) < 0)
{
log_message(LOG_LEVEL_ERROR, "g_tcp_set_non_blocking: fcntl() failed\n");
log_message(LOG_LEVEL_ERROR, "g_sck_set_non_blocking: fcntl() failed\n");
}
#endif
return 0;
@@ -944,19 +903,19 @@ g_tcp_bind(int sck, const char *port)
int APP_CC
g_tcp_bind(int sck, const char* port)
{
struct sockaddr_in s;
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, const char *port)
g_sck_local_bind(int sck, const char *port)
{
#if defined(_WIN32)
return -1;
@@ -987,24 +946,24 @@ g_tcp_bind_address(int sck, const char *port, const char *address)
int APP_CC
g_tcp_bind_address(int sck, const char* port, const char* address)
{
struct sockaddr_in s;
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;
if (inet_aton(address, &s.sin_addr) < 0)
{
return -1; /* bad address */
}
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 */
int APP_CC
g_tcp_listen(int sck)
g_sck_listen(int sck)
{
return listen(sck, 2);
}
@@ -1027,8 +986,8 @@ g_tcp_accept(int sck)
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));
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 ;
@@ -1120,7 +1079,7 @@ g_sleep(int msecs)

/*****************************************************************************/
int APP_CC
g_tcp_last_error_would_block(int sck)
g_sck_last_error_would_block(int sck)
{
#if defined(_WIN32)
return WSAGetLastError() == WSAEWOULDBLOCK;
@@ -1131,7 +1090,7 @@ g_tcp_last_error_would_block(int sck)

/*****************************************************************************/
int APP_CC
g_tcp_recv(int sck, void *ptr, int len, int flags)
g_sck_recv(int sck, void *ptr, int len, int flags)
{
#if defined(_WIN32)
return recv(sck, (char *)ptr, len, flags);
@@ -1142,7 +1101,7 @@ g_tcp_recv(int sck, void *ptr, int len, int flags)

/*****************************************************************************/
int APP_CC
g_tcp_send(int sck, const void *ptr, int len, int flags)
g_sck_send(int sck, const void *ptr, int len, int flags)
{
#if defined(_WIN32)
return send(sck, (const char *)ptr, len, flags);
@@ -1154,7 +1113,7 @@ g_tcp_send(int sck, const void *ptr, int len, int flags)
/*****************************************************************************/
/* returns boolean */
int APP_CC
g_tcp_socket_ok(int sck)
g_sck_socket_ok(int sck)
{
#if defined(_WIN32)
int opt;
@@ -1181,7 +1140,7 @@ g_tcp_socket_ok(int sck)
/* wait 'millis' milliseconds for the socket to be able to write */
/* returns boolean */
int APP_CC
g_tcp_can_send(int sck, int millis)
g_sck_can_send(int sck, int millis)
{
fd_set wfds;
struct timeval time;
@@ -1198,7 +1157,7 @@ g_tcp_can_send(int sck, int millis)

if (rv > 0)
{
return g_tcp_socket_ok(sck);
return 1;
}
}

@@ -1209,12 +1168,13 @@ g_tcp_can_send(int sck, int millis)
/* wait 'millis' milliseconds for the socket to be able to receive */
/* returns boolean */
int APP_CC
g_tcp_can_recv(int sck, int millis)
g_sck_can_recv(int sck, int millis)
{
fd_set rfds;
struct timeval time;
int rv;

g_memset(&time, 0, sizeof(time));
time.tv_sec = millis / 1000;
time.tv_usec = (millis * 1000) % 1000000;
FD_ZERO(&rfds);
@@ -1226,7 +1186,7 @@ g_tcp_can_recv(int sck, int millis)

if (rv > 0)
{
return g_tcp_socket_ok(sck);
return 1;
}
}

@@ -1235,18 +1195,14 @@ g_tcp_can_recv(int sck, int millis)

/*****************************************************************************/
int APP_CC
g_tcp_select(int sck1, int sck2)
g_sck_select(int sck1, int sck2)
{
fd_set rfds;
struct timeval time;
int max = 0;
int rv = 0;
int max;
int rv;

g_memset(&rfds, 0, sizeof(fd_set));
g_memset(&time, 0, sizeof(struct timeval));

time.tv_sec = 0;
time.tv_usec = 0;
FD_ZERO(&rfds);

if (sck1 > 0)
@@ -1291,96 +1247,94 @@ g_tcp_select(int sck1, int sck2)
}

/*****************************************************************************/
/* returns 0 on error */
tbus APP_CC
g_create_wait_obj(char *name)
/* returns boolean */
static int APP_CC
g_fd_can_read(int fd)
{
#ifdef _WIN32
tbus obj;

obj = (tbus)CreateEvent(0, 1, 0, name);
return obj;
#else
tbus obj;
struct sockaddr_un sa;
size_t len;
tbus sck;
int i;
int safety;
int unnamed;
fd_set rfds;
struct timeval time;
int rv;

if (g_temp_base[0] == 0)
g_memset(&time, 0, sizeof(time));
FD_ZERO(&rfds);
FD_SET(((unsigned int)fd), &rfds);
rv = select(fd + 1, &rfds, 0, 0, &time);
if (rv == 1)
{
return 0;
return 1;
}
return 0;
}

sck = socket(PF_UNIX, SOCK_DGRAM, 0);
/*****************************************************************************/
/* returns error */
/* O_NONBLOCK = 0x00000800 */
static int APP_CC
g_set_nonblock(int fd)
{
int error;
int flags;

if (sck < 0)
error = fcntl(fd, F_GETFL);
if (error < 0)
{
return 0;
return 1;
}

safety = 0;
g_memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
unnamed = 1;

if (name != 0)
flags = error;
if ((flags & O_NONBLOCK) != O_NONBLOCK)
{
if (name[0] != 0)
flags |= O_NONBLOCK;
error = fcntl(fd, F_SETFL, flags);
if (error < 0)
{
unnamed = 0;
return 1;
}
}
return 0;
}

if (unnamed)
{
do
{
if (safety > 100)
{
break;
}
/*****************************************************************************/
/* returns 0 on error */
tintptr APP_CC
g_create_wait_obj(char *name)
{
#ifdef _WIN32
tintptr obj;

safety++;
g_random((char *)&i, sizeof(i));
len = sizeof(sa.sun_path);
g_snprintf(sa.sun_path, len, "%s/auto_%8.8x", g_temp_base, i);
len = sizeof(sa);
}
while (bind(sck, (struct sockaddr *)&sa, len) < 0);
obj = (tintptr)CreateEvent(0, 1, 0, name);
return obj;
#else
int fds[2];
int error;

error = pipe(fds);
if (error != 0)
{
return 0;
}
else
if (g_set_nonblock(fds[0]) != 0)
{
do
{
if (safety > 100)
{
break;
}

safety++;
g_random((char *)&i, sizeof(i));
len = sizeof(sa.sun_path);
g_snprintf(sa.sun_path, len, "%s/%s_%8.8x", g_temp_base, name, i);
len = sizeof(sa);
}
while (bind(sck, (struct sockaddr *)&sa, len) < 0);
close(fds[0]);
close(fds[1]);
return 0;
}

obj = (tbus)sck;
return obj;
if (g_set_nonblock(fds[1]) != 0)
{
close(fds[0]);
close(fds[1]);
return 0;
}
return (fds[1] << 16) | fds[0];
#endif
}

/*****************************************************************************/
/* returns 0 on error */
tbus APP_CC
g_create_wait_obj_from_socket(tbus socket, int write)
tintptr APP_CC
g_create_wait_obj_from_socket(tintptr socket, int write)
{
#ifdef _WIN32
/* Create and return corresponding event handle for WaitForMultipleObjets */
/* Create and return corresponding event handle for WaitForMultipleObjects */
WSAEVENT event;
long lnetevent = 0;

@@ -1405,7 +1359,7 @@ g_create_wait_obj_from_socket(tbus socket, int write)

/*****************************************************************************/
void APP_CC
g_delete_wait_obj_from_socket(tbus wait_obj)
g_delete_wait_obj_from_socket(tintptr wait_obj)
{
#ifdef _WIN32

@@ -1422,54 +1376,60 @@ g_delete_wait_obj_from_socket(tbus wait_obj)
/*****************************************************************************/
/* returns error */
int APP_CC
g_set_wait_obj(tbus obj)
g_set_wait_obj(tintptr obj)
{
#ifdef _WIN32

if (obj == 0)
{
return 0;
}

SetEvent((HANDLE)obj);
return 0;
#else
socklen_t sa_size;
int s;
struct sockaddr_un sa;
int error;
int fd;
int written;
int to_write;
char buf[4] = "sig";

if (obj == 0)
{
return 0;
}
if (g_tcp_can_recv((int)obj, 0))
fd = obj & 0xffff;
if (g_fd_can_read(fd))
{
/* already signalled */
return 0;
}

sa_size = sizeof(sa);

if (getsockname((int)obj, (struct sockaddr *)&sa, &sa_size) < 0)
{
return 1;
}

s = socket(PF_UNIX, SOCK_DGRAM, 0);

if (s < 0)
{
return 1;
}

if (sendto(s, "sig", 4, 0, (struct sockaddr *)&sa, sa_size) < 0)
fd = obj >> 16;
to_write = 4;
written = 0;
while (written < to_write)
{
close(s);
return 1;
error = write(fd, buf + written, to_write - written);
if (error == -1)
{
error = errno;
if ((error == EAGAIN) || (error == EWOULDBLOCK) ||
(error == EINPROGRESS) || (error == EINTR))
{
/* ok */
}
else
{
return 1;
}
}
else if (error > 0)
{
written += error;
}
else
{
return 1;
}
}

close(s);
return 0;
#endif
}
@@ -1477,30 +1437,46 @@ g_set_wait_obj(tbus obj)
/*****************************************************************************/
/* returns error */
int APP_CC
g_reset_wait_obj(tbus obj)
g_reset_wait_obj(tintptr obj)
{
#ifdef _WIN32

if (obj == 0)
{
return 0;
}

ResetEvent((HANDLE)obj);
return 0;
#else
char buf[64];
char buf[4];
int error;
int fd;

if (obj == 0)
{
return 0;
}
while (g_tcp_can_recv((int)obj, 0))
fd = obj & 0xffff;
while (g_fd_can_read(fd))
{
recvfrom((int)obj, &buf, 64, 0, 0, 0);
error = read(fd, buf, 4);
if (error == -1)
{
error = errno;
if ((error == EAGAIN) || (error == EWOULDBLOCK) ||
(error == EINPROGRESS) || (error == EINTR))
{
/* ok */
}
else
{
return 1;
}
}
else if (error == 0)
{
return 1;
}
}

return 0;
#endif
}
@@ -1508,86 +1484,55 @@ g_reset_wait_obj(tbus obj)
/*****************************************************************************/
/* returns boolean */
int APP_CC
g_is_wait_obj_set(tbus obj)
g_is_wait_obj_set(tintptr obj)
{
#ifdef _WIN32

if (obj == 0)
{
return 0;
}

if (WaitForSingleObject((HANDLE)obj, 0) == WAIT_OBJECT_0)
{
return 1;
}

return 0;
#else

if (obj == 0)
{
return 0;
}

return g_tcp_can_recv((int)obj, 0);
return g_fd_can_read(obj & 0xffff);
#endif
}

/*****************************************************************************/
/* returns error */
int APP_CC
g_delete_wait_obj(tbus obj)
g_delete_wait_obj(tintptr obj)
{
#ifdef _WIN32

if (obj == 0)
{
return 0;
}

/* Close event handle */
CloseHandle((HANDLE)obj);
return 0;
#else
socklen_t sa_size;
struct sockaddr_un sa;

if (obj == 0)
{
return 0;
}

sa_size = sizeof(sa);

if (getsockname((int)obj, (struct sockaddr *)&sa, &sa_size) < 0)
{
return 1;
}

close((int)obj);
unlink(sa.sun_path);
close(obj & 0xffff);
close(obj >> 16);
return 0;
#endif
}

/*****************************************************************************/
/* returns error */
/* close but do not delete the wait obj, used after fork */
int APP_CC
g_close_wait_obj(tbus obj)
{
#ifdef _WIN32
#else
close((int)obj);
#endif
return 0;
}

/*****************************************************************************/
/* returns error */
int APP_CC
g_obj_wait(tbus *read_objs, int rcount, tbus *write_objs, int wcount,
g_obj_wait(tintptr *read_objs, int rcount, tintptr *write_objs, int wcount,
int mstimeout)
{
#ifdef _WIN32
@@ -1627,24 +1572,20 @@ g_obj_wait(tbus *read_objs, int rcount, tbus *write_objs, int wcount,
fd_set rfds;
fd_set wfds;
struct timeval time;
struct timeval *ptime = (struct timeval *)NULL;
struct timeval *ptime;
int i = 0;
int res = 0;
int max = 0;
int sck = 0;

g_memset(&rfds, 0, sizeof(fd_set));
g_memset(&wfds, 0, sizeof(fd_set));
g_memset(&time, 0, sizeof(struct timeval));

max = 0;

if (mstimeout < 1)
{
ptime = (struct timeval *)NULL;
ptime = 0;
}
else
{
g_memset(&time, 0, sizeof(struct timeval));
time.tv_sec = mstimeout / 1000;
time.tv_usec = (mstimeout % 1000) * 1000;
ptime = &time;
@@ -1658,7 +1599,7 @@ g_obj_wait(tbus *read_objs, int rcount, tbus *write_objs, int wcount,
{
for (i = 0; i < rcount; i++)
{
sck = (int)(read_objs[i]);
sck = read_objs[i] & 0xffff;

if (sck > 0)
{
@@ -1869,7 +1810,7 @@ g_file_read(int fd, char *ptr, int len)
}

/*****************************************************************************/
/* write to file, returns the number of bytes writen or -1 on error */
/* write to file, returns the number of bytes written or -1 on error */
int APP_CC
g_file_write(int fd, char *ptr, int len)
{
@@ -2045,7 +1986,7 @@ g_directory_exist(const char *dirname)
{
#if defined(_WIN32)
return 0; // use GetFileAttributes and check return value
// is not -1 and FILE_ATTRIBUT_DIRECTORY bit is set
// is not -1 and FILE_ATTRIBUTE_DIRECTORY bit is set
#else
struct stat st;

@@ -2266,6 +2207,7 @@ g_strdup(const char *in)

return p;
}

/*****************************************************************************/
/* if in = 0, return 0 else return newly alloced copy of input string
* if the input string is larger than maxlen the returned string will be
@@ -2297,6 +2239,7 @@ g_strndup(const char *in, const unsigned int maxlen)

return p;
}

/*****************************************************************************/
int APP_CC
g_strcmp(const char *c1, const char *c2)
@@ -2319,10 +2262,12 @@ g_strncmp_d(const char *s1, const char *s2, const char delim, int n)
char c1;
char c2;

c1 = 0;
c2 = 0;
while (n > 0)
{
c1 = *s1++;
c2 = *s2++;
c1 = *(s1++);
c2 = *(s2++);
if ((c1 == 0) || (c1 != c2) || (c1 == delim) || (c2 == delim))
{
return c1 - c2;
@@ -2780,17 +2725,6 @@ g_signal_user_interrupt(void (*func)(int))
#endif
}

/*****************************************************************************/
/* does not work in win32 */
void APP_CC
g_signal_kill(void (*func)(int))
{
#if defined(_WIN32)
#else
signal(SIGKILL, func);
#endif
}

/*****************************************************************************/
/* does not work in win32 */
void APP_CC
@@ -2909,6 +2843,28 @@ g_setuid(int pid)
#endif
}

/*****************************************************************************/
int APP_CC
g_setsid(void)
{
#if defined(_WIN32)
return -1;
#else
return setsid();
#endif
}

/*****************************************************************************/
int APP_CC
g_setlogin(const char *name)
{
#ifdef BSD
return setlogin(name);
#else
return -1;
#endif
}

/*****************************************************************************/
/* does not work in win32
returns pid of process that exits or zero if signal occurred */


+ 55
- 30
common/os_calls.h View File

@@ -21,23 +21,50 @@
#if !defined(OS_CALLS_H)
#define OS_CALLS_H

#if defined(HAVE_CONFIG_H)
#include "config_ac.h"
#endif

#ifndef NULL
#define NULL 0
#endif

#include "arch.h"

#define g_tcp_can_recv g_sck_can_recv
#define g_tcp_can_send g_sck_can_send
#define g_tcp_recv g_sck_recv
#define g_tcp_send g_sck_send
#define g_tcp_close g_sck_close
#define g_tcp_last_error_would_block g_sck_last_error_would_block
#define g_tcp_set_non_blocking g_sck_set_non_blocking
#define g_tcp_local_socket g_sck_local_socket
#define g_tcp_local_connect g_sck_local_connect
#define g_tcp_listen g_sck_listen
#define g_tcp_local_bind g_sck_local_bind
#define g_tcp_select g_sck_select
#define g_close_wait_obj g_delete_wait_obj

#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
#define printflike(arg_format, arg_first_check) \
__attribute__((__format__(__printf__, arg_format, arg_first_check)))
#else
#define printflike(arg_format, arg_first_check)
#endif

int APP_CC g_rm_temp_dir(void);
int APP_CC g_mk_temp_dir(const char* app_name);
void APP_CC g_init(const char* app_name);
void APP_CC g_deinit(void);
void* APP_CC g_malloc(int size, int zero);
void APP_CC g_free(void* ptr);
void DEFAULT_CC g_printf(const char *format, ...);
void DEFAULT_CC g_sprintf(char* dest, const char* format, ...);
void DEFAULT_CC g_snprintf(char* dest, int len, const char* format, ...);
void DEFAULT_CC g_writeln(const char* format, ...);
void DEFAULT_CC g_write(const char* format, ...);
void DEFAULT_CC g_printf(const char *format, ...) printflike(1, 2);
void DEFAULT_CC g_sprintf(char* dest, const char* format, ...) \
printflike(2, 3);
void DEFAULT_CC g_snprintf(char* dest, int len, const char* format, ...) \
printflike(3, 4);
void DEFAULT_CC g_writeln(const char* format, ...) printflike(1, 2);
void DEFAULT_CC g_write(const char* format, ...) printflike(1, 2);
void APP_CC g_hexdump(char* p, int len);
void APP_CC g_memset(void* ptr, int val, int size);
void APP_CC g_memcpy(void* d_ptr, const void* s_ptr, int size);
@@ -49,39 +76,36 @@ int APP_CC g_sck_set_send_buffer_bytes(int sck, int bytes);
int APP_CC g_sck_get_send_buffer_bytes(int sck, int *bytes);
int APP_CC g_sck_set_recv_buffer_bytes(int sck, int bytes);
int APP_CC g_sck_get_recv_buffer_bytes(int sck, int *bytes);
int APP_CC g_tcp_local_socket(void);
int APP_CC g_sck_local_socket(void);
int APP_CC g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid);
void APP_CC g_tcp_close(int sck);
void APP_CC g_sck_close(int sck);
int APP_CC g_tcp_connect(int sck, const char* address, const char* port);
int APP_CC g_tcp_local_connect(int sck, const char* port);
int APP_CC g_tcp_force_send(int sck, char* data, int len);
int APP_CC g_tcp_force_recv(int sck, char* data, int len);
int APP_CC g_tcp_set_non_blocking(int sck);
int APP_CC g_sck_local_connect(int sck, const char* port);
int APP_CC g_sck_set_non_blocking(int sck);
int APP_CC g_tcp_bind(int sck, const char *port);
int APP_CC g_tcp_local_bind(int sck, const char* port);
int APP_CC g_sck_local_bind(int sck, const char* port);
int APP_CC g_tcp_bind_address(int sck, const char* port, const char* address);
int APP_CC g_tcp_listen(int sck);
int APP_CC g_sck_listen(int sck);
int APP_CC g_tcp_accept(int sck);
int APP_CC g_sck_accept(int sck, char *addr, int addr_bytes,
char *port, int port_bytes);
int APP_CC g_tcp_recv(int sck, void* ptr, int len, int flags);
int APP_CC g_tcp_send(int sck, const void* ptr, int len, int flags);
int APP_CC g_tcp_last_error_would_block(int sck);
int APP_CC g_tcp_socket_ok(int sck);
int APP_CC g_tcp_can_send(int sck, int millis);
int APP_CC g_tcp_can_recv(int sck, int millis);
int APP_CC g_tcp_select(int sck1, int sck2);
int APP_CC g_sck_recv(int sck, void* ptr, int len, int flags);
int APP_CC g_sck_send(int sck, const void* ptr, int len, int flags);
int APP_CC g_sck_last_error_would_block(int sck);
int APP_CC g_sck_socket_ok(int sck);
int APP_CC g_sck_can_send(int sck, int millis);
int APP_CC g_sck_can_recv(int sck, int millis);
int APP_CC g_sck_select(int sck1, int sck2);
void APP_CC g_write_ip_address(int rcv_sck, char* ip_address, int bytes);
void APP_CC g_sleep(int msecs);
tbus APP_CC g_create_wait_obj(char* name);
tbus APP_CC g_create_wait_obj_from_socket(tbus socket, int write);
void APP_CC g_delete_wait_obj_from_socket(tbus wait_obj);
int APP_CC g_set_wait_obj(tbus obj);
int APP_CC g_reset_wait_obj(tbus obj);
int APP_CC g_is_wait_obj_set(tbus obj);
int APP_CC g_delete_wait_obj(tbus obj);
int APP_CC g_close_wait_obj(tbus obj);
int APP_CC g_obj_wait(tbus* read_objs, int rcount, tbus* write_objs,
tintptr APP_CC g_create_wait_obj(char* name);
tintptr APP_CC g_create_wait_obj_from_socket(tintptr socket, int write);
void APP_CC g_delete_wait_obj_from_socket(tintptr wait_obj);
int APP_CC g_set_wait_obj(tintptr obj);
int APP_CC g_reset_wait_obj(tintptr obj);
int APP_CC g_is_wait_obj_set(tintptr obj);
int APP_CC g_delete_wait_obj(tintptr obj);
int APP_CC g_obj_wait(tintptr* read_objs, int rcount, tintptr* write_objs,
int wcount,int mstimeout);
void APP_CC g_random(char* data, int len);
int APP_CC g_abs(int i);
@@ -136,7 +160,6 @@ void APP_CC g_signal_child_stop(void (*func)(int));
void APP_CC g_signal_segfault(void (*func)(int));
void APP_CC g_signal_hang_up(void (*func)(int));
void APP_CC g_signal_user_interrupt(void (*func)(int));
void APP_CC g_signal_kill(void (*func)(int));
void APP_CC g_signal_terminate(void (*func)(int));
void APP_CC g_signal_pipe(void (*func)(int));
void APP_CC g_signal_usr1(void (*func)(int));
@@ -146,6 +169,8 @@ int APP_CC g_initgroups(const char* user, int gid);
int APP_CC g_getuid(void);
int APP_CC g_getgid(void);
int APP_CC g_setuid(int pid);
int APP_CC g_setsid(void);
int APP_CC g_setlogin(const char *name);
int APP_CC g_waitchild(void);
int APP_CC g_waitpid(int pid);
void APP_CC g_clearenv(void);


+ 22
- 14
common/ssl_calls.c View File

@@ -401,6 +401,7 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char *exp, int exp_len,
tui8 *lexp;
int error;
int len;
int diff;

if ((exp_len != 4) || ((mod_len != 64) && (mod_len != 256)) ||
((pri_len != 64) && (pri_len != 256)))
@@ -408,8 +409,9 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char *exp, int exp_len,
return 1;
}

lmod = (char *)g_malloc(mod_len, 0);
lpri = (char *)g_malloc(pri_len, 0);
diff = 0;
lmod = (char *)g_malloc(mod_len, 1);
lpri = (char *)g_malloc(pri_len, 1);
lexp = (tui8 *)exp;
my_e = lexp[0];
my_e |= lexp[1] << 8;
@@ -423,24 +425,26 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char *exp, int exp_len,
if (error == 0)
{
len = BN_num_bytes(my_key->n);
error = len != mod_len;
error = (len < 1) || (len > mod_len);
diff = mod_len - len;
}

if (error == 0)
{
BN_bn2bin(my_key->n, (tui8 *)lmod);
BN_bn2bin(my_key->n, (tui8 *)(lmod + diff));
ssl_reverse_it(lmod, mod_len);
}

if (error == 0)
{
len = BN_num_bytes(my_key->d);
error = len != pri_len;
error = (len < 1) || (len > pri_len);
diff = pri_len - len;
}

if (error == 0)
{
BN_bn2bin(my_key->d, (tui8 *)lpri);
BN_bn2bin(my_key->d, (tui8 *)(lpri + diff));
ssl_reverse_it(lpri, pri_len);
}

@@ -471,6 +475,7 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char *exp, int exp_len,
char *lpri;
int error;
int len;
int diff;

if ((exp_len != 4) || ((mod_len != 64) && (mod_len != 256)) ||
((pri_len != 64) && (pri_len != 256)))
@@ -478,9 +483,10 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char *exp, int exp_len,
return 1;
}

lexp = (char *)g_malloc(exp_len, 0);
lmod = (char *)g_malloc(mod_len, 0);
lpri = (char *)g_malloc(pri_len, 0);
diff = 0;
lexp = (char *)g_malloc(exp_len, 1);
lmod = (char *)g_malloc(mod_len, 1);
lpri = (char *)g_malloc(pri_len, 1);
g_memcpy(lexp, exp, exp_len);
ssl_reverse_it(lexp, exp_len);
my_e = BN_new();
@@ -491,24 +497,26 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char *exp, int exp_len,
if (error == 0)
{
len = BN_num_bytes(my_key->n);
error = len != mod_len;
error = (len < 1) || (len > mod_len);
diff = mod_len - len;
}

if (error == 0)
{
BN_bn2bin(my_key->n, (tui8 *)lmod);
BN_bn2bin(my_key->n, (tui8 *)(lmod + diff));
ssl_reverse_it(lmod, mod_len);
}

if (error == 0)
{
len = BN_num_bytes(my_key->d);
error = len != pri_len;
error = (len < 1) || (len > pri_len);
diff = pri_len - len;
}

if (error == 0)
{
BN_bn2bin(my_key->d, (tui8 *)lpri);
BN_bn2bin(my_key->d, (tui8 *)(lpri + diff));
ssl_reverse_it(lpri, pri_len);
}

@@ -841,6 +849,6 @@ ssl_tls_can_recv(struct ssl_tls *tls, int sck, int millis)
return 1;
}
g_reset_wait_obj(tls->rwo);
return g_tcp_can_recv(sck, millis);
return g_sck_can_recv(sck, millis);
}


+ 15
- 0
common/thread_calls.c View File

@@ -20,6 +20,10 @@

#if defined(_WIN32)
#include <windows.h>
#elif defined(__APPLE__)
#include <pthread.h>
#include <dispatch/dispatch.h>
#include <dispatch/time.h>
#else
#include <pthread.h>
#include <semaphore.h>
@@ -159,6 +163,9 @@ tc_sem_create(int init_count)

sem = CreateSemaphore(0, init_count, init_count + 10, 0);
return (tbus)sem;
#elif defined(__APPLE__)
dispatch_semaphore_t sem = dispatch_semaphore_create(init_count);
return (tbus)sem;
#else
sem_t *sem = (sem_t *)NULL;

@@ -174,6 +181,8 @@ tc_sem_delete(tbus sem)
{
#if defined(_WIN32)
CloseHandle((HANDLE)sem);
#elif defined(__APPLE__)
dispatch_release((dispatch_semaphore_t)sem);
#else
sem_t *lsem;

@@ -190,6 +199,9 @@ tc_sem_dec(tbus sem)
#if defined(_WIN32)
WaitForSingleObject((HANDLE)sem, INFINITE);
return 0;
#elif defined(__APPLE__)
dispatch_semaphore_wait((dispatch_semaphore_t)sem, DISPATCH_TIME_FOREVER);
return 0;
#else
sem_wait((sem_t *)sem);
return 0;
@@ -203,6 +215,9 @@ tc_sem_inc(tbus sem)
#if defined(_WIN32)
ReleaseSemaphore((HANDLE)sem, 1, 0);
return 0;
#elif defined(__APPLE__)
dispatch_semaphore_signal((dispatch_semaphore_t)sem);
return 0;
#else
sem_post((sem_t *)sem);
return 0;


+ 22
- 15
common/trans.c View File

@@ -77,7 +77,7 @@ trans_tcp_send(struct trans *self, const void *data, int len)
int APP_CC
trans_tcp_can_recv(struct trans *self, int sck, int millis)