Browse Source

Revert "Remove upstream source"

This reverts commit d752e778fe.
tags/debian/0.9.0_20160601+git703fedd-1
Dominik George 5 years ago
parent
commit
5380d5b614
No known key found for this signature in database GPG Key ID: B79A3C16A0C4F296
100 changed files with 34289 additions and 0 deletions
  1. +176
    -0
      COPYING
  2. BIN
      Coding_Style.odt
  3. +30
    -0
      Makefile.am
  4. +59
    -0
      astyle_config.as
  5. +37
    -0
      bootstrap
  6. +43
    -0
      common/Makefile.am
  7. +108
    -0
      common/arch.h
  8. +510
    -0
      common/d3des.c
  9. +56
    -0
      common/d3des.h
  10. +104
    -0
      common/defines.h
  11. +393
    -0
      common/file.c
  12. +37
    -0
      common/file.h
  13. +44
    -0
      common/file_loc.h
  14. +226
    -0
      common/list.c
  15. +57
    -0
      common/list.h
  16. +647
    -0
      common/log.c
  17. +193
    -0
      common/log.h
  18. +3179
    -0
      common/os_calls.c
  19. +168
    -0
      common/os_calls.h
  20. +460
    -0
      common/parse.h
  21. +147
    -0
      common/rail.h
  22. +524
    -0
      common/ssl_calls.c
  23. +83
    -0
      common/ssl_calls.h
  24. +210
    -0
      common/thread_calls.c
  25. +49
    -0
      common/thread_calls.h
  26. +630
    -0
      common/trans.c
  27. +98
    -0
      common/trans.h
  28. +126
    -0
      common/xrdp_client_info.h
  29. +596
    -0
      common/xrdp_constants.h
  30. +147
    -0
      common/xrdp_rail.h
  31. +176
    -0
      configure.ac
  32. +1
    -0
      description-pak
  33. +35
    -0
      design.txt
  34. +3
    -0
      docs/Makefile.am
  35. +17
    -0
      docs/man/Makefile.am
  36. +181
    -0
      docs/man/sesman.ini.5
  37. +46
    -0
      docs/man/xrdp-chansrv.8
  38. +23
    -0
      docs/man/xrdp-dis.1
  39. +67
    -0
      docs/man/xrdp-genkeymap.8
  40. +40
    -0
      docs/man/xrdp-keygen.8
  41. +57
    -0
      docs/man/xrdp-sesadmin.8
  42. +47
    -0
      docs/man/xrdp-sesman.8
  43. +50
    -0
      docs/man/xrdp-sesrun.8
  44. +26
    -0
      docs/man/xrdp-sessvc.8
  45. +14
    -0
      docs/man/xrdp-xcon.8
  46. +46
    -0
      docs/man/xrdp.8
  47. +240
    -0
      docs/man/xrdp.ini.5
  48. +24
    -0
      faq-compile.txt
  49. +22
    -0
      faq-general.txt
  50. +63
    -0
      file-loc.txt
  51. +17
    -0
      fontdump/Makefile
  52. +534
    -0
      fontdump/fontdump.c
  53. +9
    -0
      genkeymap/Makefile.am
  54. +35
    -0
      genkeymap/dump-keymaps.sh
  55. +127
    -0
      genkeymap/genkeymap.c
  56. +35
    -0
      genkeymap/readme.txt
  57. +54
    -0
      install.txt
  58. +32
    -0
      instfiles/Makefile.am
  59. +3
    -0
      instfiles/default/Makefile.am
  60. +5
    -0
      instfiles/default/xrdp
  61. +4
    -0
      instfiles/init.d/Makefile.am
  62. +187
    -0
      instfiles/init.d/xrdp
  63. +659
    -0
      instfiles/km-0407.ini
  64. +659
    -0
      instfiles/km-0409.ini
  65. +659
    -0
      instfiles/km-040c.ini
  66. +659
    -0
      instfiles/km-0410.ini
  67. +659
    -0
      instfiles/km-0414.ini
  68. +659
    -0
      instfiles/km-0416.ini
  69. +659
    -0
      instfiles/km-0419.ini
  70. +659
    -0
      instfiles/km-041d.ini
  71. +659
    -0
      instfiles/km-0807.ini
  72. +659
    -0
      instfiles/km-080c.ini
  73. +659
    -0
      instfiles/km-0813.ini
  74. +659
    -0
      instfiles/km-0816.ini
  75. +20
    -0
      instfiles/pam.d/Makefile.am
  76. +5
    -0
      instfiles/pam.d/xrdp-sesman
  77. +4
    -0
      instfiles/pam.d/xrdp-sesman.other
  78. +14
    -0
      instfiles/xrdp-sesman.service
  79. +14
    -0
      instfiles/xrdp.service
  80. +153
    -0
      instfiles/xrdp.sh
  81. +17
    -0
      keygen/Makefile.am
  82. +499
    -0
      keygen/keygen.c
  83. +69
    -0
      libxrdp/Makefile.am
  84. +1081
    -0
      libxrdp/libxrdp.c
  85. +531
    -0
      libxrdp/libxrdp.h
  86. +228
    -0
      libxrdp/libxrdpinc.h
  87. +32
    -0
      libxrdp/xrdp_bitmap32_compress.c
  88. +1572
    -0
      libxrdp/xrdp_bitmap_compress.c
  89. +198
    -0
      libxrdp/xrdp_channel.c
  90. +209
    -0
      libxrdp/xrdp_fastpath.c
  91. +417
    -0
      libxrdp/xrdp_iso.c
  92. +424
    -0
      libxrdp/xrdp_jpeg_compress.c
  93. +1005
    -0
      libxrdp/xrdp_mcs.c
  94. +1070
    -0
      libxrdp/xrdp_mppc_enc.c
  95. +2927
    -0
      libxrdp/xrdp_orders.c
  96. +704
    -0
      libxrdp/xrdp_orders_rail.c
  97. +50
    -0
      libxrdp/xrdp_orders_rail.h
  98. +1739
    -0
      libxrdp/xrdp_rdp.c
  99. +1878
    -0
      libxrdp/xrdp_sec.c
  100. +164
    -0
      libxrdp/xrdp_surface.c

+ 176
- 0
COPYING View File

@@ -0,0 +1,176 @@
Apache License, Version 2.0

Version 2.0, January 2004

http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by the
copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all other
entities that control, are controlled by, or are under common control
with that entity. For the purposes of this definition, "control" means
(i) the power, direct or indirect, to cause the direction or management
of such entity, whether by contract or otherwise, or (ii) ownership of
fifty percent (50%) or more of the outstanding shares, or
(iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity exercising
permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation source,
and configuration files.

"Object" form shall mean any form resulting from mechanical transformation
or translation of a Source form, including but not limited to compiled
object code, generated documentation, and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or Object form,
made available under the License, as indicated by a copyright notice that is
included in or attached to the work (an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object form,
that is based on (or derived from) the Work and for which the editorial
revisions, annotations, elaborations, or other modifications represent, as a
whole, an original work of authorship. For the purposes of this License,
Derivative Works shall not include works that remain separable from, or
merely link (or bind by name) to the interfaces of, the Work and
Derivative Works thereof.

"Contribution" shall mean any work of authorship, including the original
version of the Work and any modifications or additions to that Work or Derivative
Works thereof, that is intentionally submitted to Licensor for inclusion in the
Work by the copyright owner or by an individual or Legal Entity authorized to
submit on behalf of the copyright owner. For the purposes of this definition,
"submitted" means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems, and
issue tracking systems that are managed by, or on behalf of, the Licensor for
the purpose of discussing and improving the Work, but excluding communication
that is conspicuously marked or otherwise designated in writing by the copyright
owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
of whom a Contribution has been received by Licensor and subsequently incorporated
within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of this License,
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable copyright license to reproduce, prepare
Derivative Works of, publicly display, publicly perform, sublicense, and distribute
the Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of this License,
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section) patent
license to make, have made, use, offer to sell, sell, import, and otherwise transfer
the Work, where such license applies only to those patent claims licensable by such
Contributor that are necessarily infringed by their Contribution(s) alone or by
combination of their Contribution(s) with the Work to which such Contribution(s) was
submitted. If You institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution
incorporated within the Work constitutes direct or contributory patent infringement,
then any patent licenses granted to You under this License for that Work shall
terminate as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the Work or Derivative
Works thereof in any medium, with or without modifications, and in Source or Object
form, provided that You meet the following conditions:

You must give any other recipients of the Work or Derivative Works a copy of this
License; and

You must cause any modified files to carry prominent notices stating that You changed
the files; and

You must retain, in the Source form of any Derivative Works that You distribute,
all copyright, patent, trademark, and attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of the Derivative Works; and

If the Work includes a "NOTICE" text file as part of its distribution, then any
Derivative Works that You distribute must include a readable copy of the attribution
notices contained within such NOTICE file, excluding those notices that do not pertain
to any part of the Derivative Works, in at least one of the following places: within a
NOTICE text file distributed as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or, within a display
generated by the Derivative Works, if and wherever such third-party notices normally
appear. The contents of the NOTICE file are for informational purposes only and do not
modify the License. You may add Your own attribution notices within Derivative Works
that You distribute, alongside or as an addendum to the NOTICE text from the Work,
provided that such additional attribution notices cannot be construed as modifying
the License. You may add Your own copyright statement to Your modifications and may
provide additional or different license terms and conditions for use, reproduction,
or distribution of Your modifications, or for any such Derivative Works as a whole,
provided Your use, reproduction, and distribution of the Work otherwise complies
with the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution
intentionally submitted for inclusion in the Work by You to the Licensor shall be under
the terms and conditions of this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify the terms of any
separate license agreement you may have executed with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade names, trademarks,
service marks, or product names of the Licensor, except as required for reasonable and
customary use in describing the origin of the Work and reproducing the content of
the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing,
Licensor provides the Work (and each Contributor provides its Contributions) on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
determining the appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory, whether in tort
(including negligence), contract, or otherwise, unless required by applicable law
(such as deliberate and grossly negligent acts) or agreed to in writing, shall any
Contributor be liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a result of this
License or out of the use or inability to use the Work (including but not limited to
damages for loss of goodwill, work stoppage, computer failure or malfunction, or any
and all other commercial damages or losses), even if such Contributor has been advised
of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing the Work or
Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance
of support, warranty, indemnity, or other liability obligations and/or rights consistent
with this License. However, in accepting such obligations, You may act only on Your
own behalf and on Your sole responsibility, not on behalf of any other Contributor,
and only if You agree to indemnify, defend, and hold each Contributor harmless for any
liability incurred by, or claims asserted against, such Contributor by reason of your
accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work
To apply the Apache License to your work, attach the following boilerplate notice,
with the fields enclosed by brackets "[]" replaced with your own identifying
information. (Don't include the brackets!) The text should be enclosed in the
appropriate comment syntax for the file format. We also recommend that a file or class
name and description of purpose be included on the same "printed page" as the
copyright notice for easier identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


BIN
Coding_Style.odt View File


+ 30
- 0
Makefile.am View File

@@ -0,0 +1,30 @@
EXTRA_DIST = bootstrap COPYING design.txt faq-compile.txt faq-general.txt file-loc.txt install.txt prog_std.txt readme.txt

if XRDP_NEUTRINORDP
NEUTRINORDPDIR = neutrinordp
else
NEUTRINORDPDIR =
endif

if XRDP_XRDPVR
XRDPVRDIR = xrdpvr
else
XRDPVRDIR =
endif

SUBDIRS = \
common \
vnc \
rdp \
xup \
mc \
$(NEUTRINORDPDIR) \
libxrdp \
xrdp \
sesman \
keygen \
docs \
instfiles \
genkeymap \
xrdpapi \
$(XRDPVRDIR)

+ 59
- 0
astyle_config.as View File

@@ -0,0 +1,59 @@

# detached brackets
--style=allman

# 4 spaces, no tabs
--indent=spaces=4

# for C++ files only
--indent-classes

# Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block.
# The entire case block is indented.
--indent-switches

# Add extra indentation to namespace blocks. This option has no effect on Java files.
--indent-namespaces

# Converts tabs into spaces in the non-indentation part of the line.
--convert-tabs

# requires --convert-tabs to work properly
--indent-preprocessor

--indent-col1-comments

--min-conditional-indent=2

--max-instatement-indent=40

# Pad empty lines around header blocks (e.g. 'if', 'for', 'while'...).
--break-blocks

# Insert space padding around operators.
--pad-oper

# Insert space padding after paren headers only (e.g. 'if', 'for', 'while'...).
--pad-header


# Add brackets to unbracketed one line conditional statements (e.g. 'if', 'for', 'while'...).
--add-brackets

--align-pointer=name

# Do not retain a backup of the original file. The original file is purged after it is formatted.
--suffix=none

# For each directory in the command line, process all subdirectories recursively.
--recursive

# Preserve the original file's date and time modified.
--preserve-date

# Formatted files display mode. Display only the files that have been formatted.
# Do not display files that are unchanged.
--formatted

--lineend=linux


+ 37
- 0
bootstrap View File

@@ -0,0 +1,37 @@
#!/bin/sh

which autoconf
if ! test $? -eq 0
then
echo "error, install autoconf"
exit 1
fi

which automake
if ! test $? -eq 0
then
echo "error, install automake"
exit 1
fi

which libtool
if ! test $? -eq 0
then
echo "error, install libtool"
exit 1
fi

which pkg-config
if ! test $? -eq 0
then
echo "error, install pkg-config"
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

+ 43
- 0
common/Makefile.am View File

@@ -0,0 +1,43 @@
EXTRA_DIST = \
arch.h \
d3des.h \
defines.h \
file.h \
file_loc.h \
list.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

AM_CFLAGS = \
-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 = \
libcommon.la

libcommon_la_SOURCES = \
d3des.c \
file.c \
list.c \
log.c \
os_calls.c \
ssl_calls.c \
thread_calls.c \
trans.c

libcommon_la_LIBADD = \
-lcrypto \
-lssl \
-lpthread

+ 108
- 0
common/arch.h View File

@@ -0,0 +1,108 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#if !defined(ARCH_H)
#define ARCH_H

#if !(defined(L_ENDIAN) || defined(B_ENDIAN))
/* check endianess */
#if defined(__sparc__) || defined(__PPC__) || defined(__ppc__) || \
defined(__hppa__)
#define B_ENDIAN
#else
#define L_ENDIAN
#endif
/* check if we need to align data */
#if defined(__sparc__) || defined(__alpha__) || defined(__hppa__) || \
defined(__AIX__) || defined(__PPC__) || defined(__mips__) || \
defined(__ia64__) || defined(__ppc__) || defined(__arm__)
#define NEED_ALIGN
#elif defined(__x86__) || defined(__x86_64__) || \
defined(__AMD64__) || defined(_M_IX86) || \
defined(__i386__)
#define NO_NEED_ALIGN
#else
#warning unknown arch
#endif
#endif

/* defines for thread creation factory functions */
#if defined(_WIN32)
#define THREAD_RV unsigned long
#define THREAD_CC __stdcall
#else
#define THREAD_RV void*
#define THREAD_CC
#endif

#if defined(__BORLANDC__) || defined(_WIN32)
#define APP_CC __fastcall
#define DEFAULT_CC __cdecl
#else
#define APP_CC
#define DEFAULT_CC
#endif

#if defined(_WIN32)
#if defined(__BORLANDC__)
#define EXPORT_CC _export __cdecl
#else
#define EXPORT_CC
#endif
#else
#define EXPORT_CC
#endif

#ifndef DEFINED_Ts
#define DEFINED_Ts
typedef char ti8;
typedef unsigned char tui8;
typedef signed char tsi8;
typedef short ti16;
typedef unsigned short tui16;
typedef signed short tsi16;
typedef int ti32;
typedef unsigned int tui32;
typedef signed int tsi32;
typedef int tbool;
#if defined(_WIN64)
/* Microsoft's VC++ compiler uses the more backwards-compatible LLP64 model.
Most other 64 bit compilers(Solaris, AIX, HP, Linux, Mac OS X) use
the LP64 model.
long is 32 bits in LLP64 model, 64 bits in LP64 model. */
typedef __int64 tbus;
#else
typedef long tbus;
#endif
typedef tbus thandle;
typedef tbus tintptr;
/* wide char, socket */
#if defined(_WIN32)
typedef unsigned short twchar;
typedef unsigned int tsock;
typedef unsigned __int64 tui64;
typedef signed __int64 tsi64;
#else
typedef int twchar;
typedef int tsock;
typedef unsigned long long tui64;
typedef signed long long tsi64;
#endif
#endif /* DEFINED_Ts */

#endif

+ 510
- 0
common/d3des.c View File

@@ -0,0 +1,510 @@
/*
* This is D3DES (V5.09) by Richard Outerbridge with the double and
* triple-length support removed for use in VNC. Also the bytebit[] array
* has been reversed so that the most significant bit in each byte of the
* key is ignored, not the least significant.
*
* These changes are:
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

/* D3DES (V5.09) -
*
* A portable, public domain, version of the Data Encryption Standard.
*
* Written with Symantec's THINK (Lightspeed) C by Richard Outerbridge.
* Thanks to: Dan Hoey for his excellent Initial and Inverse permutation
* code; Jim Gillogly & Phil Karn for the DES key schedule code; Dennis
* Ferguson, Eric Young and Dana How for comparing notes; and Ray Lau,
* for humouring me on.
*
* Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge.
* (GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992.
*/

#include "d3des.h"

static void scrunch(unsigned char *, unsigned long *);
static void unscrun(unsigned long *, unsigned char *);
static void desfunc(unsigned long *, unsigned long *);
static void cookey(unsigned long *);

static unsigned long KnL[32] = { 0L };
/*
static unsigned long KnR[32] = { 0L };
static unsigned long Kn3[32] = { 0L };
static unsigned char Df_Key[24] = {
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67 };
*/

static unsigned short bytebit[8] =
{
01, 02, 04, 010, 020, 040, 0100, 0200
};

static unsigned long bigbyte[24] =
{
0x800000L, 0x400000L, 0x200000L, 0x100000L,
0x80000L, 0x40000L, 0x20000L, 0x10000L,
0x8000L, 0x4000L, 0x2000L, 0x1000L,
0x800L, 0x400L, 0x200L, 0x100L,
0x80L, 0x40L, 0x20L, 0x10L,
0x8L, 0x4L, 0x2L, 0x1L
};

/* Use the key schedule specified in the Standard (ANSI X3.92-1981). */

static unsigned char pc1[56] =
{
56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21,
13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3
};

static unsigned char totrot[16] =
{
1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28
};

static unsigned char pc2[48] =
{
13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9,
22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,
40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31
};

/* Thanks to James Gillogly & Phil Karn! */
void rfbDesKey(unsigned char *key, int edf)
{
register int i, j, l, m, n;
unsigned char pc1m[56], pcr[56];
unsigned long kn[32];

for ( j = 0; j < 56; j++ )
{
l = pc1[j];
m = l & 07;
pc1m[j] = (key[l >> 3] & bytebit[m]) ? 1 : 0;
}

for ( i = 0; i < 16; i++ )
{
if ( edf == DE1 )
{
m = (15 - i) << 1;
}
else
{
m = i << 1;
}

n = m + 1;
kn[m] = kn[n] = 0L;

for ( j = 0; j < 28; j++ )
{
l = j + totrot[i];

if ( l < 28 )
{
pcr[j] = pc1m[l];
}
else
{
pcr[j] = pc1m[l - 28];
}
}

for ( j = 28; j < 56; j++ )
{
l = j + totrot[i];

if ( l < 56 )
{
pcr[j] = pc1m[l];
}
else
{
pcr[j] = pc1m[l - 28];
}
}

for ( j = 0; j < 24; j++ )
{
if ( pcr[pc2[j]] )
{
kn[m] |= bigbyte[j];
}

if ( pcr[pc2[j + 24]] )
{
kn[n] |= bigbyte[j];
}
}
}

cookey(kn);
return;
}

static void cookey(register unsigned long *raw1)
{
register unsigned long *cook, *raw0;
unsigned long dough[32];
register int i;

cook = dough;

for ( i = 0; i < 16; i++, raw1++ )
{
raw0 = raw1++;
*cook = (*raw0 & 0x00fc0000L) << 6;
*cook |= (*raw0 & 0x00000fc0L) << 10;
*cook |= (*raw1 & 0x00fc0000L) >> 10;
*cook++ |= (*raw1 & 0x00000fc0L) >> 6;
*cook = (*raw0 & 0x0003f000L) << 12;
*cook |= (*raw0 & 0x0000003fL) << 16;
*cook |= (*raw1 & 0x0003f000L) >> 4;
*cook++ |= (*raw1 & 0x0000003fL);
}

rfbUseKey(dough);
return;
}

void rfbCPKey(register unsigned long *into)
{
register unsigned long *from, *endp;

from = KnL, endp = &KnL[32];

while ( from < endp )
{
*into++ = *from++;
}

return;
}

void rfbUseKey(register unsigned long *from)
{
register unsigned long *to, *endp;

to = KnL, endp = &KnL[32];

while ( to < endp )
{
*to++ = *from++;
}

return;
}

void rfbDes(unsigned char *inblock, unsigned char *outblock)
{
unsigned long work[2];

scrunch(inblock, work);
desfunc(work, KnL);
unscrun(work, outblock);
return;
}

static void scrunch(register unsigned char *outof, register unsigned long *into)
{
*into = (*outof++ & 0xffL) << 24;
*into |= (*outof++ & 0xffL) << 16;
*into |= (*outof++ & 0xffL) << 8;
*into++ |= (*outof++ & 0xffL);
*into = (*outof++ & 0xffL) << 24;
*into |= (*outof++ & 0xffL) << 16;
*into |= (*outof++ & 0xffL) << 8;
*into |= (*outof & 0xffL);
return;
}

static void unscrun(register unsigned long *outof, register unsigned char *into)
{
*into++ = (unsigned char)((*outof >> 24) & 0xffL);
*into++ = (unsigned char)((*outof >> 16) & 0xffL);
*into++ = (unsigned char)((*outof >> 8) & 0xffL);
*into++ = (unsigned char)( *outof++ & 0xffL);
*into++ = (unsigned char)((*outof >> 24) & 0xffL);
*into++ = (unsigned char)((*outof >> 16) & 0xffL);
*into++ = (unsigned char)((*outof >> 8) & 0xffL);
*into = (unsigned char)( *outof & 0xffL);
return;
}

static unsigned long SP1[64] =
{
0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L,
0x01010004L, 0x00010404L, 0x00000004L, 0x00010000L,
0x00000400L, 0x01010400L, 0x01010404L, 0x00000400L,
0x01000404L, 0x01010004L, 0x01000000L, 0x00000004L,
0x00000404L, 0x01000400L, 0x01000400L, 0x00010400L,
0x00010400L, 0x01010000L, 0x01010000L, 0x01000404L,
0x00010004L, 0x01000004L, 0x01000004L, 0x00010004L,
0x00000000L, 0x00000404L, 0x00010404L, 0x01000000L,
0x00010000L, 0x01010404L, 0x00000004L, 0x01010000L,
0x01010400L, 0x01000000L, 0x01000000L, 0x00000400L,
0x01010004L, 0x00010000L, 0x00010400L, 0x01000004L,
0x00000400L, 0x00000004L, 0x01000404L, 0x00010404L,
0x01010404L, 0x00010004L, 0x01010000L, 0x01000404L,
0x01000004L, 0x00000404L, 0x00010404L, 0x01010400L,
0x00000404L, 0x01000400L, 0x01000400L, 0x00000000L,
0x00010004L, 0x00010400L, 0x00000000L, 0x01010004L
};

static unsigned long SP2[64] =
{
0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L,
0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L,
0x80000020L, 0x80108020L, 0x80108000L, 0x80000000L,
0x80008000L, 0x00100000L, 0x00000020L, 0x80100020L,
0x00108000L, 0x00100020L, 0x80008020L, 0x00000000L,
0x80000000L, 0x00008000L, 0x00108020L, 0x80100000L,
0x00100020L, 0x80000020L, 0x00000000L, 0x00108000L,
0x00008020L, 0x80108000L, 0x80100000L, 0x00008020L,
0x00000000L, 0x00108020L, 0x80100020L, 0x00100000L,
0x80008020L, 0x80100000L, 0x80108000L, 0x00008000L,
0x80100000L, 0x80008000L, 0x00000020L, 0x80108020L,
0x00108020L, 0x00000020L, 0x00008000L, 0x80000000L,
0x00008020L, 0x80108000L, 0x00100000L, 0x80000020L,
0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L,
0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L,
0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L
};

static unsigned long SP3[64] =
{
0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L,
0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L,
0x00020008L, 0x08000008L, 0x08000008L, 0x00020000L,
0x08020208L, 0x00020008L, 0x08020000L, 0x00000208L,
0x08000000L, 0x00000008L, 0x08020200L, 0x00000200L,
0x00020200L, 0x08020000L, 0x08020008L, 0x00020208L,
0x08000208L, 0x00020200L, 0x00020000L, 0x08000208L,
0x00000008L, 0x08020208L, 0x00000200L, 0x08000000L,
0x08020200L, 0x08000000L, 0x00020008L, 0x00000208L,
0x00020000L, 0x08020200L, 0x08000200L, 0x00000000L,
0x00000200L, 0x00020008L, 0x08020208L, 0x08000200L,
0x08000008L, 0x00000200L, 0x00000000L, 0x08020008L,
0x08000208L, 0x00020000L, 0x08000000L, 0x08020208L,
0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L,
0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L,
0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L
};

static unsigned long SP4[64] =
{
0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L,
0x00000000L, 0x00802000L, 0x00802000L, 0x00802081L,
0x00000081L, 0x00000000L, 0x00800080L, 0x00800001L,
0x00000001L, 0x00002000L, 0x00800000L, 0x00802001L,
0x00000080L, 0x00800000L, 0x00002001L, 0x00002080L,
0x00800081L, 0x00000001L, 0x00002080L, 0x00800080L,
0x00002000L, 0x00802080L, 0x00802081L, 0x00000081L,
0x00800080L, 0x00800001L, 0x00802000L, 0x00802081L,
0x00000081L, 0x00000000L, 0x00000000L, 0x00802000L,
0x00002080L, 0x00800080L, 0x00800081L, 0x00000001L,
0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
0x00802081L, 0x00000081L, 0x00000001L, 0x00002000L,
0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L,
0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L,
0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L
};

static unsigned long SP5[64] =
{
0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L,
0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L,
0x40080100L, 0x00080000L, 0x02000100L, 0x40080100L,
0x42000100L, 0x42080000L, 0x00080100L, 0x40000000L,
0x02000000L, 0x40080000L, 0x40080000L, 0x00000000L,
0x40000100L, 0x42080100L, 0x42080100L, 0x02000100L,
0x42080000L, 0x40000100L, 0x00000000L, 0x42000000L,
0x02080100L, 0x02000000L, 0x42000000L, 0x00080100L,
0x00080000L, 0x42000100L, 0x00000100L, 0x02000000L,
0x40000000L, 0x02080000L, 0x42000100L, 0x40080100L,
0x02000100L, 0x40000000L, 0x42080000L, 0x02080100L,
0x40080100L, 0x00000100L, 0x02000000L, 0x42080000L,
0x42080100L, 0x00080100L, 0x42000000L, 0x42080100L,
0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L,
0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L,
0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L
};

static unsigned long SP6[64] =
{
0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L,
0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L,
0x20004000L, 0x00404010L, 0x00400000L, 0x20000010L,
0x00400010L, 0x20004000L, 0x20000000L, 0x00004010L,
0x00000000L, 0x00400010L, 0x20004010L, 0x00004000L,
0x00404000L, 0x20004010L, 0x00000010L, 0x20400010L,
0x20400010L, 0x00000000L, 0x00404010L, 0x20404000L,
0x00004010L, 0x00404000L, 0x20404000L, 0x20000000L,
0x20004000L, 0x00000010L, 0x20400010L, 0x00404000L,
0x20404010L, 0x00400000L, 0x00004010L, 0x20000010L,
0x00400000L, 0x20004000L, 0x20000000L, 0x00004010L,
0x20000010L, 0x20404010L, 0x00404000L, 0x20400000L,
0x00404010L, 0x20404000L, 0x00000000L, 0x20400010L,
0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L,
0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L,
0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L
};

static unsigned long SP7[64] =
{
0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,
0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,
0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L,
0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L,
0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L,
0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L,
0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L,
0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L,
0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L,
0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L,
0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L,
0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L,
0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L,
0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,
0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,
0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L
};

static unsigned long SP8[64] =
{
0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,
0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,
0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L,
0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L,
0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L,
0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L,
0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L,
0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L,
0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L,
0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L,
0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L,
0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L,
0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L,
0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L,
0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L,
0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L
};

static void desfunc(register unsigned long *block, register unsigned long *keys)
{
register unsigned long fval, work, right, leftt;
register int round;

leftt = block[0];
right = block[1];
work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
right ^= work;
leftt ^= (work << 4);
work = ((leftt >> 16) ^ right) & 0x0000ffffL;
right ^= work;
leftt ^= (work << 16);
work = ((right >> 2) ^ leftt) & 0x33333333L;
leftt ^= work;
right ^= (work << 2);
work = ((right >> 8) ^ leftt) & 0x00ff00ffL;
leftt ^= work;
right ^= (work << 8);
right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL;
work = (leftt ^ right) & 0xaaaaaaaaL;
leftt ^= work;
right ^= work;
leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;

for ( round = 0; round < 8; round++ )
{
work = (right << 28) | (right >> 4);
work ^= *keys++;
fval = SP7[ work & 0x3fL];
fval |= SP5[(work >> 8) & 0x3fL];
fval |= SP3[(work >> 16) & 0x3fL];
fval |= SP1[(work >> 24) & 0x3fL];
work = right ^ *keys++;
fval |= SP8[ work & 0x3fL];
fval |= SP6[(work >> 8) & 0x3fL];
fval |= SP4[(work >> 16) & 0x3fL];
fval |= SP2[(work >> 24) & 0x3fL];
leftt ^= fval;
work = (leftt << 28) | (leftt >> 4);
work ^= *keys++;
fval = SP7[ work & 0x3fL];
fval |= SP5[(work >> 8) & 0x3fL];
fval |= SP3[(work >> 16) & 0x3fL];
fval |= SP1[(work >> 24) & 0x3fL];
work = leftt ^ *keys++;
fval |= SP8[ work & 0x3fL];
fval |= SP6[(work >> 8) & 0x3fL];
fval |= SP4[(work >> 16) & 0x3fL];
fval |= SP2[(work >> 24) & 0x3fL];
right ^= fval;
}

right = (right << 31) | (right >> 1);
work = (leftt ^ right) & 0xaaaaaaaaL;
leftt ^= work;
right ^= work;
leftt = (leftt << 31) | (leftt >> 1);
work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
right ^= work;
leftt ^= (work << 8);
work = ((leftt >> 2) ^ right) & 0x33333333L;
right ^= work;
leftt ^= (work << 2);
work = ((right >> 16) ^ leftt) & 0x0000ffffL;
leftt ^= work;
right ^= (work << 16);
work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;
leftt ^= work;
right ^= (work << 4);
*block++ = right;
*block = leftt;
return;
}

/* Validation sets:
*
* Single-length key, single-length plaintext -
* Key : 0123 4567 89ab cdef
* Plain : 0123 4567 89ab cde7
* Cipher : c957 4425 6a5e d31d
*
* Double-length key, single-length plaintext -
* Key : 0123 4567 89ab cdef fedc ba98 7654 3210
* Plain : 0123 4567 89ab cde7
* Cipher : 7f1d 0a77 826b 8aff
*
* Double-length key, double-length plaintext -
* Key : 0123 4567 89ab cdef fedc ba98 7654 3210
* Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
* Cipher : 27a0 8440 406a df60 278f 47cf 42d6 15d7
*
* Triple-length key, single-length plaintext -
* Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
* Plain : 0123 4567 89ab cde7
* Cipher : de0b 7c06 ae5e 0ed5
*
* Triple-length key, double-length plaintext -
* Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567
* Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
* Cipher : ad0d 1b30 ac17 cf07 0ed1 1c63 81e4 4de5
*
* d3des V5.0a rwo 9208.07 18:44 Graven Imagery
**********************************************************************/

+ 56
- 0
common/d3des.h View File

@@ -0,0 +1,56 @@
#ifndef D3DES_H
#define D3DES_H

/*
* This is D3DES (V5.09) by Richard Outerbridge with the double and
* triple-length support removed for use in VNC.
*
* These changes are:
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

/* d3des.h -
*
* Headers and defines for d3des.c
* Graven Imagery, 1992.
*
* Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge
* (GEnie : OUTER; CIS : [71755,204])
*/

#define EN0 0 /* MODE == encrypt */
#define DE1 1 /* MODE == decrypt */

extern void rfbDesKey(unsigned char *, int);
/* hexkey[8] MODE
* Sets the internal key register according to the hexadecimal
* key contained in the 8 bytes of hexkey, according to the DES,
* for encryption or decryption according to MODE.
*/

extern void rfbUseKey(unsigned long *);
/* cookedkey[32]
* Loads the internal key register with the data in cookedkey.
*/

extern void rfbCPKey(unsigned long *);
/* cookedkey[32]
* Copies the contents of the internal key register into the storage
* located at &cookedkey[0].
*/

extern void rfbDes(unsigned char *, unsigned char *);
/* from[8] to[8]
* Encrypts/Decrypts (according to the key currently loaded in the
* internal key register) one block of eight bytes at address 'from'
* into the block at address 'to'. They can be the same.
*/

/* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery
********************************************************************/

#endif

+ 104
- 0
common/defines.h View File

@@ -0,0 +1,104 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2012
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* main define/macro file
*/

#ifndef DEFINES_H
#define DEFINES_H

/* check for debug */
#ifdef XRDP_DEBUG
#define DEBUG(args) g_writeln args;
#define LIB_DEBUG(_mod, _text) _mod->server_msg(_mod, _text, 1);
#else
#define DEBUG(args)
#define LIB_DEBUG(_mod, _text)
#endif
/* other macros */
#undef MIN
#define MIN(x1, x2) ((x1) < (x2) ? (x1) : (x2))
#undef MAX
#define MAX(x1, x2) ((x1) > (x2) ? (x1) : (x2))
#undef HIWORD
#define HIWORD(in) (((in) & 0xffff0000) >> 16)
#undef LOWORD
#define LOWORD(in) ((in) & 0x0000ffff)
#undef MAKELONG
#define MAKELONG(lo, hi) ((((hi) & 0xffff) << 16) | ((lo) & 0xffff))
#define MAKERECT(r, x, y, cx, cy) \
{ (r).left = x; (r).top = y; (r).right = (x) + (cx); (r).bottom = (y) + (cy); }
#define ISRECTEMPTY(r) (((r).right <= (r).left) || ((r).bottom <= (r).top))
#define RECTOFFSET(r, dx, dy) \
{ (r).left += dx; (r).top += dy; (r).right += dx; (r).bottom += dy; }
#define GETPIXEL8(d, x, y, w) (*(((unsigned char*)d) + ((y) * (w) + (x))))
#define GETPIXEL16(d, x, y, w) (*(((unsigned short*)d) + ((y) * (w) + (x))))
#define GETPIXEL32(d, x, y, w) (*(((unsigned int*)d) + ((y) * (w) + (x))))
#define SETPIXEL8(d, x, y, w, v) \
(*(((unsigned char*)d) + ((y) * (w) + (x))) = (v))
#define SETPIXEL16(d, x, y, w, v) \
(*(((unsigned short*)d) + ((y) * (w) + (x))) = (v))
#define SETPIXEL32(d, x, y, w, v) \
(*(((unsigned int*)d) + ((y) * (w) + (x))) = (v))
#define COLOR8(r, g, b) \
( \
(((r) >> 5) << 0) | \
(((g) >> 5) << 3) | \
(((b) >> 6) << 6) \
)
#define COLOR15(r, g, b) ((((r) >> 3) << 10) | (((g) >> 3) << 5) | ((b) >> 3))
#define COLOR16(r, g, b) ((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3))
#define COLOR24RGB(r, g, b) (((r) << 16) | ((g) << 8) | (b))
#define COLOR24BGR(r, g, b) (((b) << 16) | ((g) << 8) | (r))
#define HRED(c) ((c & 0xff0000) >> 16)
#define HGREEN(c) ((c & 0x00ff00) >> 8)
#define HBLUE(c) ((c & 0x0000ff))
#define HCOLOR(bpp,c) \
( \
(bpp==8?COLOR8(HRED(c),HGREEN(c),HBLUE(c)): \
(bpp==15?COLOR15(HRED(c),HGREEN(c),HBLUE(c)): \
(bpp==16?COLOR16(HRED(c),HGREEN(c),HBLUE(c)): \
(bpp==24?COLOR24BGR(HRED(c),HGREEN(c),HBLUE(c)):c) \
) \
) \
) \
)
#define SPLITCOLOR15(r, g, b, c) \
{ \
r = (((c) >> 7) & 0xf8) | (((c) >> 12) & 0x7); \
g = (((c) >> 2) & 0xf8) | (((c) >> 8) & 0x7); \
b = (((c) << 3) & 0xf8) | (((c) >> 2) & 0x7); \
}
#define SPLITCOLOR16(r, g, b, c) \
{ \
r = (((c) >> 8) & 0xf8) | (((c) >> 13) & 0x7); \
g = (((c) >> 3) & 0xfc) | (((c) >> 9) & 0x3); \
b = (((c) << 3) & 0xf8) | (((c) >> 2) & 0x7); \
}
#define SPLITCOLOR32(r, g, b, c) \
{ \
r = ((c) >> 16) & 0xff; \
g = ((c) >> 8) & 0xff; \
b = (c) & 0xff; \
}
/* font macros */
#define FONT_DATASIZE(f) \
((((f)->height * (((f)->width + 7) / 8)) + 3) & ~3);
/* use crc for bitmap cache lookups */
#define USE_CRC

#endif

+ 393
- 0
common/file.c View File

@@ -0,0 +1,393 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* read a config file
*/

#include "arch.h"
#include "os_calls.h"
#include "list.h"
#include "file.h"
#include "parse.h"

/*****************************************************************************/
/* returns error
returns 0 if everything is ok
returns 1 if problem reading file */
static int APP_CC
l_file_read_sections(int fd, int max_file_size, struct list *names)
{
struct stream *s;
char text[256];
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, 256);
list_clear(names);
make_stream(s);
init_stream(s, max_file_size);
len = g_file_read(fd, s->data, max_file_size);

if (len > 0)
{
s->end = s->p + len;

for (index = 0; index < len; index++)
{
in_uint8(s, c);

if (c == '[')
{
in_it = 1;
}
else if (c == ']')
{
list_add_item(names, (tbus)g_strdup(text));
in_it = 0;
in_it_index = 0;
g_memset(text, 0, 256);
}
else if (in_it)
{
text[in_it_index] = c;
in_it_index++;
}
}
}
else if (len < 0)
{
rv = 1;
}

free_stream(s);
return rv;
}

/*****************************************************************************/
static int APP_CC
file_read_line(struct stream *s, char *text)
{
int i;
int skip_to_end;
int at_end;
char c;
char *hold;

skip_to_end = 0;

if (!s_check_rem(s, 1))
{
return 1;
}

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

while (c != 10 && c != 13)
{
if (c == '#' || c == '!' || c == ';')
{
skip_to_end = 1;
}

if (!skip_to_end)
{
text[i] = c;
i++;
}

if (s_check_rem(s, 1))
{
in_uint8(s, c);
}
else
{
c = 0;
break;
}
}

if (c == 10 || c == 13)
{
at_end = 0;

while (c == 10 || c == 13)
{
if (s_check_rem(s, 1))
{
in_uint8(s, c);
}
else
{
at_end = 1;
break;
}
}

if (!at_end)
{
s->p--;
}
}

text[i] = 0;

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

return 0;
}

/*****************************************************************************/
/* returns error */
static int APP_CC
file_split_name_value(char *text, char *name, char *value)
{
int len;
int i;
int value_index;
int name_index;
int on_to;

value_index = 0;
name_index = 0;
on_to = 0;
name[0] = 0;
value[0] = 0;
len = g_strlen(text);

for (i = 0; i < len; i++)
{
if (text[i] == '=')
{
on_to = 1;
}
else if (on_to)
{
value[value_index] = text[i];
value_index++;
value[value_index] = 0;
}
else
{
name[name_index] = text[i];
name_index++;
name[name_index] = 0;
}
}

g_strtrim(name, 3); /* trim both right and left */
g_strtrim(value, 3); /* trim both right and left */
return 0;
}

/*****************************************************************************/
/* return error */
static int APP_CC
l_file_read_section(int fd, int max_file_size, const char *section,
struct list *names, struct list *values)
{
struct stream *s;
char text[512];
char name[512];
char value[512];
char *lvalue;
char c;
int in_it;
int in_it_index;
int len;
int index;
int file_size;

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, 512);
list_clear(names);
list_clear(values);
make_stream(s);
init_stream(s, file_size);
len = g_file_read(fd, s->data, file_size);

if (len > 0)
{
s->end = s->p + len;

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;
}
else if (c == ']')
{
if (g_strcasecmp(section, text) == 0)
{
file_read_line(s, text);
while (file_read_line(s, text) == 0)
{
if (g_strlen(text) > 0)
{
file_split_name_value(text, name, value);
list_add_item(names, (tbus)g_strdup(name));

if (value[0] == '$')
{
lvalue = g_getenv(value + 1);

if (lvalue != 0)
{
list_add_item(values, (tbus)g_strdup(lvalue));
}
else
{
list_add_item(values, (tbus)g_strdup(""));
}
}
else
{
list_add_item(values, (tbus)g_strdup(value));
}
}
}

free_stream(s);
return 0;
}

in_it = 0;
in_it_index = 0;
g_memset(text, 0, 512);
}
else if (in_it)
{
text[in_it_index] = c;
in_it_index++;
}
}
}
free_stream(s);
return 1;
}

/*****************************************************************************/
/* returns error
returns 0 if everything is ok
returns 1 if problem reading file */
/* 32 K file size limit */
int APP_CC
file_read_sections(int fd, struct list *names)
{
return l_file_read_sections(fd, 32 * 1024, names);
}

/*****************************************************************************/
/* return error */
/* this function should be prefered 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)
{
int fd;
int file_size;
int rv;

file_size = g_file_get_size(file_name);

if (file_size < 1)
{
return 1;
}

fd = g_file_open(file_name);

if (fd < 1)
{
return 1;
}

rv = l_file_read_sections(fd, file_size, names);
g_file_close(fd);
return rv;
}

/*****************************************************************************/
/* return error */
/* 32 K file size limit */
int APP_CC
file_read_section(int fd, const char *section,
struct list *names, struct list *values)
{
return l_file_read_section(fd, 32 * 1024, section, names, values);
}

/*****************************************************************************/
/* return error */
/* this function should be prefered 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,
struct list *names, struct list *values)
{
int fd;
int file_size;
int rv;

file_size = g_file_get_size(file_name);

if (file_size < 1)
{
return 1;
}

fd = g_file_open(file_name);

if (fd < 1)
{
return 1;
}

rv = l_file_read_section(fd, file_size, section, names, values);
g_file_close(fd);
return rv;
}

+ 37
- 0
common/file.h View File

@@ -0,0 +1,37 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* read a config file
*/

#if !defined(FILE_H)
#define FILE_H

#include "arch.h"

int APP_CC
file_read_sections(int fd, struct list* names);
int APP_CC
file_by_name_read_sections(const char* file_name, struct list* names);
int APP_CC
file_read_section(int fd, const char* section,
struct list* names, struct list* values);
int APP_CC
file_by_name_read_section(const char* file_name, const char* section,
struct list* names, struct list* values);

#endif

+ 44
- 0
common/file_loc.h View File

@@ -0,0 +1,44 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2012
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* default file locations for log, config, etc
*/

#if !defined(FILE_LOC_H)
#define FILE_LOC_H

#if !defined(XRDP_CFG_PATH)
#define XRDP_CFG_PATH "/etc/xrdp"
#endif

#if !defined(XRDP_PID_PATH)
#define XRDP_PID_PATH "/var/run"
#endif

#if !defined(XRDP_SBIN_PATH)
#define XRDP_SBIN_PATH "/usr/local/sbin"
#endif

#if !defined(XRDP_SHARE_PATH)
#define XRDP_SHARE_PATH "/usr/local/share/xrdp"
#endif

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

#endif

+ 226
- 0
common/list.c View File

@@ -0,0 +1,226 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* simple list
*/

#include "arch.h"
#include "os_calls.h"
#include "list.h"

/*****************************************************************************/
struct list *APP_CC
list_create(void)
{
struct list *self;

self = (struct list *)g_malloc(sizeof(struct list), 1);
self->grow_by = 10;
self->alloc_size = 10;
self->items = (tbus *)g_malloc(sizeof(tbus) * 10, 1);
return self;
}

/*****************************************************************************/
void APP_CC
list_delete(struct list *self)
{
int i;

if (self == 0)
{
return;
}

if (self->auto_free)
{
for (i = 0; i < self->count; i++)
{
g_free((void *)self->items[i]);
self->items[i] = 0;
}
}

g_free(self->items);
g_free(self);
}

/*****************************************************************************/
void APP_CC
list_add_item(struct list *self, tbus item)
{
tbus *p;
int i;

if (self->count >= self->alloc_size)
{
i = self->alloc_size;
self->alloc_size += self->grow_by;
p = (tbus *)g_malloc(sizeof(tbus) * self->alloc_size, 1);
g_memcpy(p, self->items, sizeof(tbus) * i);
g_free(self->items);
self->items = p;
}

self->items[self->count] = item;
self->count++;
}

/*****************************************************************************/
tbus APP_CC
list_get_item(struct list *self, int index)
{
if (index < 0 || index >= self->count)
{
return 0;
}

return self->items[index];
}

/*****************************************************************************/
void APP_CC
list_clear(struct list *self)
{
int i;

if (self->auto_free)
{
for (i = 0; i < self->count; i++)
{
g_free((void *)self->items[i]);
self->items[i] = 0;
}
}

g_free(self->items);
self->count = 0;
self->grow_by = 10;
self->alloc_size = 10;
self->items = (tbus *)g_malloc(sizeof(tbus) * 10, 1);
}

/*****************************************************************************/
int APP_CC
list_index_of(struct list *self, tbus item)
{
int i;

for (i = 0; i < self->count; i++)
{
if (self->items[i] == item)
{
return i;
}
}

return -1;
}

/*****************************************************************************/
void APP_CC
list_remove_item(struct list *self, int index)
{
int i;

if (index >= 0 && index < self->count)
{
if (self->auto_free)
{
g_free((void *)self->items[index]);
self->items[index] = 0;
}

for (i = index; i < (self->count - 1); i++)
{
self->items[i] = self->items[i + 1];
}

self->count--;
}
}

/*****************************************************************************/
void APP_CC
list_insert_item(struct list *self, int index, tbus item)
{
tbus *p;
int i;

if (index == self->count)
{
list_add_item(self, item);
return;
}

if (index >= 0 && index < self->count)
{
self->count++;

if (self->count > self->alloc_size)
{
i = self->alloc_size;
self->alloc_size += self->grow_by;
p = (tbus *)g_malloc(sizeof(tbus) * self->alloc_size, 1);
g_memcpy(p, self->items, sizeof(tbus) * i);
g_free(self->items);
self->items = p;
}

for (i = (self->count - 2); i >= index; i--)
{
self->items[i + 1] = self->items[i];
}

self->items[index] = 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 */
void APP_CC
list_append_list_strdup(struct list *self, struct list *dest, int start_index)
{
int index;
tbus item;
char *dup;

for (index = start_index; index < self->count; index++)
{
item = list_get_item(self, index);
dup = g_strdup((char *)item);
list_add_item(dest, (tbus)dup);
}
}

/*****************************************************************************/
void APP_CC
list_dump_items(struct list *self)
{
int index;

if (self->count == 0)
{
g_writeln("List is empty");
}

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

+ 57
- 0
common/list.h View File

@@ -0,0 +1,57 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* simple list
*/

#if !defined(LIST_H)
#define LIST_H

#include "arch.h"

/* list */
struct list
{
tbus* items;
int count;
int alloc_size;
int grow_by;
int auto_free;
};

struct list* APP_CC
list_create(void);
void APP_CC
list_delete(struct list* self);
void APP_CC
list_add_item(struct list* self, tbus item);
tbus APP_CC
list_get_item(struct list* self, int index);
void APP_CC
list_clear(struct list* self);
int APP_CC
list_index_of(struct list* self, tbus item);
void APP_CC
list_remove_item(struct list* self, int index);
void APP_CC
list_insert_item(struct list* self, int index, tbus item);
void APP_CC
list_append_list_strdup(struct list* self, struct list* dest, int start_index);
void APP_CC
list_dump_items(struct list* self);

#endif

+ 647
- 0
common/log.c View File

@@ -0,0 +1,647 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <syslog.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include "list.h"
#include "file.h"
#include "os_calls.h"
#include "thread_calls.h"

/* Add a define here so that the log.h will hold more information
* when compiled from this C file.
* When compiled normally the log.h file only contain the public parts
* of the operators in this file. */
#define LOGINTERNALSTUFF
#include "log.h"

/* Here we store the current state and configuration of the log */
static struct log_config *staticLogConfig = NULL;

/* This file first start with all private functions.
In the end of the file the public functions is defined */

/**
*
* @brief Opens log file
* @param fname log file name
* @return see open(2) return values
*
*/
int DEFAULT_CC
internal_log_file_open(const char *fname)
{
int ret = -1;

if (fname != NULL)
{
ret = open(fname, O_WRONLY | O_CREAT | O_APPEND | O_SYNC,
S_IRUSR | S_IWUSR);
}

return ret;
}

/**
*
* @brief Converts xrdp log level to syslog logging level
* @param xrdp logging level
* @return syslog equivalent logging level
*
*/
int DEFAULT_CC
internal_log_xrdp2syslog(const enum logLevels lvl)
{
switch (lvl)
{
case LOG_LEVEL_ALWAYS:
return LOG_CRIT;
case LOG_LEVEL_ERROR:
return LOG_ERR;
case LOG_LEVEL_WARNING:
return LOG_WARNING;
case LOG_LEVEL_INFO:
return LOG_INFO;
case LOG_LEVEL_DEBUG:
return LOG_DEBUG;
default:
g_writeln("Undefined log level - programming error");
return LOG_DEBUG;
}
}

/**
* @brief Converts xrdp log levels to textual logging levels
* @param lvl logging level
* @param str pointer to a string, must be allocated before
* @return The log string in str pointer.
*
*/
void DEFAULT_CC
internal_log_lvl2str(const enum logLevels lvl, char *str)
{
switch (lvl)
{
case LOG_LEVEL_ALWAYS:
snprintf(str, 9, "%s", "[CORE ] ");
break;
case LOG_LEVEL_ERROR:
snprintf(str, 9, "%s", "[ERROR] ");
break;
case LOG_LEVEL_WARNING:
snprintf(str, 9, "%s", "[WARN ] ");
break;
case LOG_LEVEL_INFO:
snprintf(str, 9, "%s", "[INFO ] ");
break;
case LOG_LEVEL_DEBUG:
snprintf(str, 9, "%s", "[DEBUG] ");
break;
default:
snprintf(str, 9, "%s", "PRG ERR!");
g_writeln("Programming error - undefined log level!!!");
}
}

/******************************************************************************/
enum logReturns DEFAULT_CC
internal_log_start(struct log_config *l_cfg)
{
enum logReturns ret = LOG_GENERAL_ERROR;

if (0 == l_cfg)
{
ret = LOG_ERROR_MALLOC;
return ret;
}

/* if logfile is NULL, we return error */
if (0 == l_cfg->log_file)
{
g_writeln("log_file not properly assigned");
return ret;
}

/* if progname is NULL, we ureturn error */
if (0 == l_cfg->program_name)
{
g_writeln("program_name not properly assigned");
return ret;
}

/* open file */
l_cfg->fd = internal_log_file_open(l_cfg->log_file);

if (-1 == l_cfg->fd)
{
return LOG_ERROR_FILE_OPEN;
}

/* if syslog is enabled, open it */
if (l_cfg->enable_syslog)
{
openlog(l_cfg->program_name, LOG_CONS | LOG_PID, LOG_DAEMON);
}

#ifdef LOG_ENABLE_THREAD
pthread_mutexattr_init(&(l_cfg->log_lock_attr));
pthread_mutex_init(&(l_cfg->log_lock), &(l_cfg->log_lock_attr));
#endif

return LOG_STARTUP_OK;
}

/******************************************************************************/