o moved from GNU General Public License to Apache License, Version 2.0

o applied new coding standards to all .c files
o moved some files around
ulab-next
Laxmikant Rashinkar 13 years ago
parent 3cedfae76a
commit 1123323fda

@ -1,372 +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.
special clause for libxrdp and librdp, both based on rdesktop
these libraries link to openssl
This software is released under the GNU General Public License
(reproduced below) with the additional exemption that compiling,
linking, and/or using OpenSSL together with this software is
allowed.
---
special clause for xrdp, that main executable
for linking with proprietary modules
Linking this library statically or dynamically with other modules
is making a combined work based on this library. Thus, the terms
and conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library
give you permission to link this library with independent modules
to produce an executable, regardless of the license terms of
these independent modules, and to copy and distribute the resulting
executable under terms of your choice, provided that you also meet,
for each linked independent module, the terms and conditions of the
license of that module. An independent module is a module which is
not derived from or based on this library. If you modify this
library, you may extend this exception to your version of the
library, but you are not obliged to do so. If you do not wish
to do so, delete this exception statement from your version.
---
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

Binary file not shown.

@ -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

@ -1,25 +1,20 @@
/*
Copyright (c) 2004-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/**
* 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.
*/
#if !defined(ARCH_H)
#define ARCH_H

@ -38,393 +38,471 @@ 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 };
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 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 };
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 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 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 };
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;
}
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;
}
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;
register unsigned long *from, *endp;
from = KnL, endp = &KnL[32];
while( from < endp ) *into++ = *from++;
return;
}
from = KnL, endp = &KnL[32];
while ( from < endp )
{
*into++ = *from++;
}
return;
}
void rfbUseKey(register unsigned long *from)
{
register unsigned long *to, *endp;
register unsigned long *to, *endp;
to = KnL, endp = &KnL[32];
while ( to < endp )
{
*to++ = *from++;
}
to = KnL, endp = &KnL[32];
while( to < endp ) *to++ = *from++;
return;
}
return;
}
void rfbDes(unsigned char *inblock, unsigned char *outblock)
{
unsigned long work[2];
unsigned long work[2];
scrunch(inblock, work);
desfunc(work, KnL);
unscrun(work, outblock);
return;
}
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;
}
*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)
*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;
}
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
* 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
* 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
* 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
* 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
* 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
*

@ -1,24 +1,22 @@
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004-2009
main define/macro file
*/
/**
* 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

@ -1,26 +1,22 @@
/*
Copyright (c) 2004-2012 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
read a config file
*/
/**
* 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.
*
* read a config file
*/
#include "arch.h"
#include "os_calls.h"
@ -33,250 +29,276 @@
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)
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++)
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)
{
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++;
}
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;
else if (len < 0)
{
rv = 1;
}
free_stream(s);
return rv;
}
/*****************************************************************************/
static int APP_CC
file_read_line(struct stream* s, char* text)
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))
int i;
int skip_to_end;
int at_end;
char c;
char *hold;
skip_to_end = 0;
if (!s_check_rem(s, 1))
{
in_uint8(s, c);
return 1;
}
else
hold = s->p;
i = 0;
in_uint8(s, c);
while (c != 10 && c != 13)
{
c = 0;
break;
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 (c == 10 || c == 13)
{
if (s_check_rem(s, 1))
{
in_uint8(s, c);
}
else
{
at_end = 1;
break;
}
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--;
}
}
if (!at_end)
text[i] = 0;
if (text[0] == '[')
{
s->p--;
s->p = hold;
return 1;
}
}
text[i] = 0;
if (text[0] == '[')
{
s->p = hold;
return 1;
}
return 0;
return 0;
}
/*****************************************************************************/
/* returns error */
static int APP_CC
file_split_name_value(char* text, char* name, char* value)
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
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++)
{
name[name_index] = text[i];
name_index++;
name[name_index] = 0;
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;
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)
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++)
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)
{
in_uint8(s, c);
if (c == '[')
{
in_it = 1;
}
else if (c == ']')
{
if (g_strcasecmp(section, text) == 0)
s->end = s->p + len;
for (index = 0; index < len; index++)
{
file_read_line(s, text);
while (file_read_line(s, text) == 0)
{
if (g_strlen(text) > 0)
in_uint8(s, c);
if (c == '[')
{
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
in_it = 1;
}
else if (c == ']')
{
if (g_strcasecmp(section, text) == 0)
{
list_add_item(values, (tbus)g_strdup(""));
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;
}
}
else
{
list_add_item(values, (tbus)g_strdup(value));
}
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 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;
free_stream(s);
return 1;
}
/*****************************************************************************/
@ -285,9 +307,9 @@ l_file_read_section(int fd, int max_file_size, const char* section,
returns 1 if problem reading file */
/* 32 K file size limit */
int APP_CC
file_read_sections(int fd, struct list* names)
file_read_sections(int fd, struct list *names)
{
return l_file_read_sections(fd, 32 * 1024, names);
return l_file_read_sections(fd, 32 * 1024, names);
}
/*****************************************************************************/
@ -295,35 +317,39 @@ file_read_sections(int fd, struct list* names)
/* 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)
file_by_name_read_sections(const char *file_name, struct list *names)
{
int fd;
int file_size;
int rv;
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;
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)
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 l_file_read_section(fd, 32 * 1024, section, names, values);
}
/*****************************************************************************/
@ -331,24 +357,28 @@ file_read_section(int fd, const char* section,
/* 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)
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;
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;
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;
}

@ -1,26 +1,22 @@
/*
Copyright (c) 2004-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
read a config file
*/
/**
* 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.
*
* read a config file
*/
#if !defined(FILE_H)
#define FILE_H

@ -1,24 +1,22 @@
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004-2010
default file locations for log, config, etc
*/
/**
* 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

@ -1,217 +1,226 @@
/*
Copyright (c) 2004-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
simple list
*/
/**
* 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.
*
* simple list
*/
#include "arch.h"
#include "os_calls.h"
#include "list.h"
/*****************************************************************************/
struct list* APP_CC
struct list *APP_CC
list_create(void)
{
struct list* self;
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;
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)
list_delete(struct list *self)
{
int i;
if (self == 0)
{
return;
}
if (self->auto_free)
{
for (i = 0; i < self->count; i++)
int i;
if (self == 0)
{
return;
}
if (self->auto_free)
{
g_free((void*)self->items[i]);
self->items[i] = 0;
for (i = 0; i < self->count; i++)
{
g_free((void *)self->items[i]);
self->items[i] = 0;
}
}
}
g_free(self->items);
g_free(self);
g_free(self->items);
g_free(self);
}
/*****************************************************************************/
void APP_CC
list_add_item(struct list* self, tbus item)
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 *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)
list_get_item(struct list *self, int index)
{
if (index < 0 || index >= self->count)
{
return 0;
}
return self->items[index];
if (index < 0 || index >= self->count)
{
return 0;
}
return self->items[index];
}
/*****************************************************************************/
void APP_CC
list_clear(struct list* self)
list_clear(struct list *self)
{
int i;
int i;
if (self->auto_free)
{
for (i = 0; i < self->count; i++)
if (self->auto_free)
{
g_free((void*)self->items[i]);
self->items[i] = 0;
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);
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)
list_index_of(struct list *self, tbus item)
{
int i;
int i;
for (i = 0; i < self->count; i++)
{
if (self->items[i] == item)
for (i = 0; i < self->count; i++)
{
return i;
if (self->items[i] == item)
{
return i;
}
}
}
return -1;
return -1;
}
/*****************************************************************************/
void APP_CC
list_remove_item(struct list* self, int index)
list_remove_item(struct list *self, int index)
{
int i;
int i;
if (index >= 0 && index < self->count)
{
if (self->auto_free)
if (index >= 0 && index < self->count)
{
g_free((void*)self->items[index]);
self->items[index] = 0;
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--;
}
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)
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)
tbus *p;
int i;
if (index == self->count)
{
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;
list_add_item(self, item);
return;
}
for (i = (self->count - 2); i >= index; i--)
if (index >= 0 && index < self->count)
{
self->items[i + 1] = self->items[i];
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;
}
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)
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);
}
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)
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));
}
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));
}
}

@ -1,26 +1,22 @@
/*
Copyright (c) 2004-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
simple list
*/
/**
* 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.
*
* simple list
*/
#if !defined(LIST_H)
#define LIST_H

File diff suppressed because it is too large Load Diff

@ -1,25 +1,20 @@
/*
Copyright (c) 2005-2012 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/**
* 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.
*/
#ifndef LOG_H
#define LOG_H

File diff suppressed because it is too large Load Diff

@ -1,26 +1,22 @@
/*
Copyright (c) 2004-2012 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
generic operating system calls
*/
/**
* 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.
*
* generic operating system calls
*/
#if !defined(OS_CALLS_H)
#define OS_CALLS_H

@ -1,30 +1,26 @@
/*
Copyright (c) 2004-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Parsing structs and macros
based on parse.h from rdesktop
this is a super fast stream method, you bet
needed functions g_malloc, g_free, g_memset, g_memcpy
*/
/**
* 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.
*
* Parsing structs and macros
*
* based on parse.h from rdesktop
* this is a super fast stream method, you bet
* needed functions g_malloc, g_free, g_memset, g_memcpy
*/
#if !defined(PARSE_H)
#define PARSE_H

@ -1,24 +1,22 @@
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004-2010
ssl calls
*/
/**
* 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.
*
* ssl calls
*/
#include <stdlib.h> /* needed for openssl headers */
#include <openssl/ssl.h>
@ -43,197 +41,200 @@
int
ssl_init(void)
{
SSL_load_error_strings();
SSL_library_init();
return 0;
SSL_load_error_strings();
SSL_library_init();
return 0;
}
/*****************************************************************************/
int
ssl_finish(void)
{
return 0;
return 0;
}
/* rc4 stuff */
/*****************************************************************************/
void* APP_CC
void *APP_CC
ssl_rc4_info_create(void)
{
return g_malloc(sizeof(RC4_KEY), 1);
return g_malloc(sizeof(RC4_KEY), 1);
}
/*****************************************************************************/
void APP_CC
ssl_rc4_info_delete(void* rc4_info)
ssl_rc4_info_delete(void *rc4_info)
{
g_free(rc4_info);
g_free(rc4_info);
}
/*****************************************************************************/
void APP_CC
ssl_rc4_set_key(void* rc4_info, char* key, int len)
ssl_rc4_set_key(void *rc4_info, char *key, int len)
{
RC4_set_key((RC4_KEY*)rc4_info, len, (tui8*)key);
RC4_set_key((RC4_KEY *)rc4_info, len, (tui8 *)key);
}
/*****************************************************************************/
void APP_CC
ssl_rc4_crypt(void* rc4_info, char* data, int len)
ssl_rc4_crypt(void *rc4_info, char *data, int len)
{
RC4((RC4_KEY*)rc4_info, len, (tui8*)data, (tui8*)data);
RC4((RC4_KEY *)rc4_info, len, (tui8 *)data, (tui8 *)data);
}
/* sha1 stuff */
/*****************************************************************************/
void* APP_CC
void *APP_CC
ssl_sha1_info_create(void)
{
return g_malloc(sizeof(SHA_CTX), 1);
return g_malloc(sizeof(SHA_CTX), 1);
}
/*****************************************************************************/
void APP_CC
ssl_sha1_info_delete(void* sha1_info)
ssl_sha1_info_delete(void *sha1_info)
{
g_free(sha1_info);
g_free(sha1_info);
}
/*****************************************************************************/
void APP_CC
ssl_sha1_clear(void* sha1_info)
ssl_sha1_clear(void *sha1_info)
{
SHA1_Init((SHA_CTX*)sha1_info);
SHA1_Init((SHA_CTX *)sha1_info);
}
/*****************************************************************************/
void APP_CC
ssl_sha1_transform(void* sha1_info, char* data, int len)
ssl_sha1_transform(void *sha1_info, char *data, int len)
{
SHA1_Update((SHA_CTX*)sha1_info, data, len);
SHA1_Update((SHA_CTX *)sha1_info, data, len);
}
/*****************************************************************************/
void APP_CC
ssl_sha1_complete(void* sha1_info, char* data)
ssl_sha1_complete(void *sha1_info, char *data)
{
SHA1_Final((tui8*)data, (SHA_CTX*)sha1_info);
SHA1_Final((tui8 *)data, (SHA_CTX *)sha1_info);
}
/* md5 stuff */
/*****************************************************************************/
void* APP_CC
void *APP_CC
ssl_md5_info_create(void)
{
return g_malloc(sizeof(MD5_CTX), 1);
return g_malloc(sizeof(MD5_CTX), 1);
}
/*****************************************************************************/
void APP_CC
ssl_md5_info_delete(void* md5_info)
ssl_md5_info_delete(void *md5_info)
{
g_free(md5_info);
g_free(md5_info);
}
/*****************************************************************************/
void APP_CC
ssl_md5_clear(void* md5_info)
ssl_md5_clear(void *md5_info)
{
MD5_Init((MD5_CTX*)md5_info);
MD5_Init((MD5_CTX *)md5_info);
}
/*****************************************************************************/
void APP_CC
ssl_md5_transform(void* md5_info, char* data, int len)
ssl_md5_transform(void *md5_info, char *data, int len)
{
MD5_Update((MD5_CTX*)md5_info, data, len);
MD5_Update((MD5_CTX *)md5_info, data, len);
}
/*****************************************************************************/
void APP_CC
ssl_md5_complete(void* md5_info, char* data)
ssl_md5_complete(void *md5_info, char *data)
{
MD5_Final((tui8*)data, (MD5_CTX*)md5_info);
MD5_Final((tui8 *)data, (MD5_CTX *)md5_info);
}
/*****************************************************************************/
static void APP_CC
ssl_reverse_it(char* p, int len)
ssl_reverse_it(char *p, int len)
{
int i;
int j;
char temp;
i = 0;
j = len - 1;
while (i < j)
{
temp = p[i];
p[i] = p[j];
p[j] = temp;
i++;
j--;
}
int i;
int j;
char temp;
i = 0;
j = len - 1;
while (i < j)
{
temp = p[i];
p[i] = p[j];
p[j] = temp;
i++;
j--;
}
}
/*****************************************************************************/
int APP_CC
ssl_mod_exp(char* out, int out_len, char* in, int in_len,
char* mod, int mod_len, char* exp, int exp_len)
ssl_mod_exp(char *out, int out_len, char *in, int in_len,
char *mod, int mod_len, char *exp, int exp_len)
{
BN_CTX* ctx;
BIGNUM lmod;
BIGNUM lexp;
BIGNUM lin;
BIGNUM lout;
int rv;
char* l_out;
char* l_in;
char* l_mod;
char* l_exp;
l_out = (char*)g_malloc(out_len, 1);
l_in = (char*)g_malloc(in_len, 1);
l_mod = (char*)g_malloc(mod_len, 1);
l_exp = (char*)g_malloc(exp_len, 1);
g_memcpy(l_in, in, in_len);
g_memcpy(l_mod, mod, mod_len);
g_memcpy(l_exp, exp, exp_len);
ssl_reverse_it(l_in, in_len);
ssl_reverse_it(l_mod, mod_len);
ssl_reverse_it(l_exp, exp_len);
ctx = BN_CTX_new();
BN_init(&lmod);
BN_init(&lexp);
BN_init(&lin);
BN_init(&lout);
BN_bin2bn((tui8*)l_mod, mod_len, &lmod);
BN_bin2bn((tui8*)l_exp, exp_len, &lexp);
BN_bin2bn((tui8*)l_in, in_len, &lin);
BN_mod_exp(&lout, &lin, &lexp, &lmod, ctx);
rv = BN_bn2bin(&lout, (tui8*)l_out);
if (rv <= out_len)
{
ssl_reverse_it(l_out, rv);
g_memcpy(out, l_out, out_len);
}
else
{
rv = 0;
}
BN_free(&lin);
BN_free(&lout);
BN_free(&lexp);
BN_free(&lmod);
BN_CTX_free(ctx);
g_free(l_out);
g_free(l_in);
g_free(l_mod);
g_free(l_exp);
return rv;
BN_CTX *ctx;
BIGNUM lmod;
BIGNUM lexp;
BIGNUM lin;
BIGNUM lout;
int rv;
char *l_out;
char *l_in;
char *l_mod;
char *l_exp;
l_out = (char *)g_malloc(out_len, 1);
l_in = (char *)g_malloc(in_len, 1);
l_mod = (char *)g_malloc(mod_len, 1);
l_exp = (char *)g_malloc(exp_len, 1);
g_memcpy(l_in, in, in_len);
g_memcpy(l_mod, mod, mod_len);
g_memcpy(l_exp, exp, exp_len);
ssl_reverse_it(l_in, in_len);
ssl_reverse_it(l_mod, mod_len);
ssl_reverse_it(l_exp, exp_len);
ctx = BN_CTX_new();
BN_init(&lmod);
BN_init(&lexp);
BN_init(&lin);
BN_init(&lout);
BN_bin2bn((tui8 *)l_mod, mod_len, &lmod);
BN_bin2bn((tui8 *)l_exp, exp_len, &lexp);
BN_bin2bn((tui8 *)l_in, in_len, &lin);
BN_mod_exp(&lout, &lin, &lexp, &lmod, ctx);
rv = BN_bn2bin(&lout, (tui8 *)l_out);
if (rv <= out_len)
{
ssl_reverse_it(l_out, rv);
g_memcpy(out, l_out, out_len);
}
else
{
rv = 0;
}
BN_free(&lin);
BN_free(&lout);
BN_free(&lexp);
BN_free(&lmod);
BN_CTX_free(ctx);
g_free(l_out);
g_free(l_in);
g_free(l_mod);
g_free(l_exp);
return rv;
}
#if defined(OLD_RSA_GEN1)
@ -242,61 +243,68 @@ ssl_mod_exp(char* out, int out_len, char* in, int in_len,
generates a new rsa key
exp is passed in and mod and pri are passed out */
int APP_CC
ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_len,
char* mod, int mod_len, char* pri, int pri_len)
ssl_gen_key_xrdp1(int key_size_in_bits, char *exp, int exp_len,
char *mod, int mod_len, char *pri, int pri_len)
{
int my_e;
RSA* my_key;
char* lmod;
char* lpri;
tui8* lexp;
int error;
int len;
if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
{
return 1;
}
lmod = (char*)g_malloc(mod_len, 0);
lpri = (char*)g_malloc(pri_len, 0);
lexp = (tui8*)exp;
my_e = lexp[0];
my_e |= lexp[1] << 8;
my_e |= lexp[2] << 16;
my_e |= lexp[3] << 24;
/* srand is in stdlib.h */
srand(g_time1());
my_key = RSA_generate_key(key_size_in_bits, my_e, 0, 0);
error = my_key == 0;
if (error == 0)
{
len = BN_num_bytes(my_key->n);
error = len != mod_len;
}
if (error == 0)
{
BN_bn2bin(my_key->n, (tui8*)lmod);
ssl_reverse_it(lmod, mod_len);
}
if (error == 0)
{
len = BN_num_bytes(my_key->d);
error = len != pri_len;
}
if (error == 0)
{
BN_bn2bin(my_key->d, (tui8*)lpri);
ssl_reverse_it(lpri, pri_len);
}
if (error == 0)
{
g_memcpy(mod, lmod, mod_len);
g_memcpy(pri, lpri, pri_len);
}
RSA_free(my_key);
g_free(lmod);
g_free(lpri);
return error;
int my_e;
RSA *my_key;
char *lmod;
char *lpri;
tui8 *lexp;
int error;
int len;
if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
{
return 1;
}
lmod = (char *)g_malloc(mod_len, 0);
lpri = (char *)g_malloc(pri_len, 0);
lexp = (tui8 *)exp;
my_e = lexp[0];
my_e |= lexp[1] << 8;
my_e |= lexp[2] << 16;
my_e |= lexp[3] << 24;
/* srand is in stdlib.h */
srand(g_time1());
my_key = RSA_generate_key(key_size_in_bits, my_e, 0, 0);
error = my_key == 0;
if (error == 0)
{
len = BN_num_bytes(my_key->n);
error = len != mod_len;
}
if (error == 0)
{
BN_bn2bin(my_key->n, (tui8 *)lmod);
ssl_reverse_it(lmod, mod_len);
}
if (error == 0)
{
len = BN_num_bytes(my_key->d);
error = len != pri_len;
}
if (error == 0)
{
BN_bn2bin(my_key->d, (tui8 *)lpri);
ssl_reverse_it(lpri, pri_len);
}
if (error == 0)
{
g_memcpy(mod, lmod, mod_len);
g_memcpy(pri, lpri, pri_len);
}
RSA_free(my_key);
g_free(lmod);
g_free(lpri);
return error;
}
#else
/*****************************************************************************/
@ -304,60 +312,67 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_len,
generates a new rsa key
exp is passed in and mod and pri are passed out */
int APP_CC
ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_len,
char* mod, int mod_len, char* pri, int pri_len)
ssl_gen_key_xrdp1(int key_size_in_bits, char *exp, int exp_len,
char *mod, int mod_len, char *pri, int pri_len)
{
BIGNUM* my_e;
RSA* my_key;
char* lexp;
char* lmod;
char* lpri;
int error;
int len;
if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
{
return 1;
}
lexp = (char*)g_malloc(exp_len, 0);
lmod = (char*)g_malloc(mod_len, 0);
lpri = (char*)g_malloc(pri_len, 0);
g_memcpy(lexp, exp, exp_len);
ssl_reverse_it(lexp, exp_len);
my_e = BN_new();
BN_bin2bn((tui8*)lexp, exp_len, my_e);
my_key = RSA_new();
error = RSA_generate_key_ex(my_key, key_size_in_bits, my_e, 0) == 0;
if (error == 0)
{
len = BN_num_bytes(my_key->n);
error = len != mod_len;
}
if (error == 0)
{
BN_bn2bin(my_key->n, (tui8*)lmod);
ssl_reverse_it(lmod, mod_len);
}
if (error == 0)
{
len = BN_num_bytes(my_key->d);
error = len != pri_len;
}
if (error == 0)
{
BN_bn2bin(my_key->d, (tui8*)lpri);
ssl_reverse_it(lpri, pri_len);
}
if (error == 0)
{
g_memcpy(mod, lmod, mod_len);
g_memcpy(pri, lpri, pri_len);
}
BN_free(my_e);
RSA_free(my_key);
g_free(lexp);
g_free(lmod);
g_free(lpri);
return error;
BIGNUM *my_e;
RSA *my_key;
char *lexp;
char *lmod;
char *lpri;
int error;
int len;
if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
{
return 1;
}
lexp = (char *)g_malloc(exp_len, 0);
lmod = (char *)g_malloc(mod_len, 0);
lpri = (char *)g_malloc(pri_len, 0);
g_memcpy(lexp, exp, exp_len);
ssl_reverse_it(lexp, exp_len);
my_e = BN_new();
BN_bin2bn((tui8 *)lexp, exp_len, my_e);
my_key = RSA_new();
error = RSA_generate_key_ex(my_key, key_size_in_bits, my_e, 0) == 0;
if (error == 0)
{
len = BN_num_bytes(my_key->n);
error = len != mod_len;
}
if (error == 0)
{
BN_bn2bin(my_key->n, (tui8 *)lmod);
ssl_reverse_it(lmod, mod_len);
}
if (error == 0)
{
len = BN_num_bytes(my_key->d);
error = len != pri_len;
}
if (error == 0)
{
BN_bn2bin(my_key->d, (tui8 *)lpri);
ssl_reverse_it(lpri, pri_len);
}
if (error == 0)
{
g_memcpy(mod, lmod, mod_len);
g_memcpy(pri, lpri, pri_len);
}
BN_free(my_e);
RSA_free(my_key);
g_free(lexp);
g_free(lmod);
g_free(lpri);
return error;
}
#endif

@ -1,22 +1,20 @@
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004-2010
*/
/**
* 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.
*/
#if !defined(SSL_CALLS_H)
#define SSL_CALLS_H

@ -1,27 +1,22 @@
/*
Copyright (c) 2004-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
thread calls
*/
/**
* 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.
*
* thread calls
*/
#if defined(_WIN32)
#include <windows.h>
@ -38,33 +33,36 @@
/* returns error */
#if defined(_WIN32)
int APP_CC
tc_thread_create(unsigned long (__stdcall * start_routine)(void*), void* arg)
tc_thread_create(unsigned long (__stdcall *start_routine)(void *), void *arg)
{
int rv = 0;
DWORD thread_id = 0;
HANDLE thread = (HANDLE)0;
/* CreateThread returns handle or zero on error */
thread = CreateThread(0, 0, start_routine, arg, 0, &thread_id);
rv = !thread;
CloseHandle(thread);
return rv;
int rv = 0;
DWORD thread_id = 0;
HANDLE thread = (HANDLE)0;
/* CreateThread returns handle or zero on error */
thread = CreateThread(0, 0, start_routine, arg, 0, &thread_id);
rv = !thread;
CloseHandle(thread);
return rv;
}
#else
int APP_CC
tc_thread_create(void* (* start_routine)(void *), void* arg)
tc_thread_create(void * (* start_routine)(void *), void *arg)
{
int rv = 0;
pthread_t thread = (pthread_t)0;
int rv = 0;
pthread_t thread = (pthread_t)0;
g_memset(&thread, 0x00, sizeof(pthread_t));
g_memset(&thread, 0x00, sizeof(pthread_t));
/* pthread_create returns error */
rv = pthread_create(&thread, 0, start_routine, arg);
if (!rv) {
rv = pthread_detach(thread);
}
return rv;
/* pthread_create returns error */
rv = pthread_create(&thread, 0, start_routine, arg);
if (!rv)
{
rv = pthread_detach(thread);
}
return rv;
}
#endif
@ -73,9 +71,9 @@ tbus APP_CC
tc_get_threadid(void)
{
#if defined(_WIN32)
return (tbus)GetCurrentThreadId();
return (tbus)GetCurrentThreadId();
#else
return (tbus)pthread_self();
return (tbus)pthread_self();
#endif
}
@ -85,9 +83,9 @@ int APP_CC
tc_threadid_equal(tbus tid1, tbus tid2)
{
#if defined(_WIN32)
return tid1 == tid2;
return tid1 == tid2;
#else
return pthread_equal((pthread_t)tid1, (pthread_t)tid2);
return pthread_equal((pthread_t)tid1, (pthread_t)tid2);
#endif
}
@ -96,13 +94,13 @@ tbus APP_CC
tc_mutex_create(void)
{
#if defined(_WIN32)
return (tbus)CreateMutex(0, 0, 0);
return (tbus)CreateMutex(0, 0, 0);
#else
pthread_mutex_t* lmutex;
pthread_mutex_t *lmutex;
lmutex = (pthread_mutex_t*)g_malloc(sizeof(pthread_mutex_t), 0);
pthread_mutex_init(lmutex, 0);
return (tbus)lmutex;
lmutex = (pthread_mutex_t *)g_malloc(sizeof(pthread_mutex_t), 0);
pthread_mutex_init(lmutex, 0);
return (tbus)lmutex;
#endif
}
@ -111,13 +109,13 @@ void APP_CC
tc_mutex_delete(tbus mutex)
{
#if defined(_WIN32)
CloseHandle((HANDLE)mutex);
CloseHandle((HANDLE)mutex);
#else
pthread_mutex_t* lmutex;
pthread_mutex_t *lmutex;
lmutex = (pthread_mutex_t*)mutex;
pthread_mutex_destroy(lmutex);
g_free(lmutex);
lmutex = (pthread_mutex_t *)mutex;
pthread_mutex_destroy(lmutex);
g_free(lmutex);
#endif
}
@ -126,11 +124,11 @@ int APP_CC
tc_mutex_lock(tbus mutex)
{
#if defined(_WIN32)
WaitForSingleObject((HANDLE)mutex, INFINITE);
return 0;
WaitForSingleObject((HANDLE)mutex, INFINITE);
return 0;
#else
pthread_mutex_lock((pthread_mutex_t*)mutex);
return 0;
pthread_mutex_lock((pthread_mutex_t *)mutex);
return 0;
#endif
}
@ -138,15 +136,18 @@ tc_mutex_lock(tbus mutex)
int APP_CC
tc_mutex_unlock(tbus mutex)
{
int rv = 0;
int rv = 0;
#if defined(_WIN32)
ReleaseMutex((HANDLE)mutex);
ReleaseMutex((HANDLE)mutex);
#else
if (mutex != 0) {
rv = pthread_mutex_unlock((pthread_mutex_t *)mutex);
}
if (mutex != 0)
{
rv = pthread_mutex_unlock((pthread_mutex_t *)mutex);
}
#endif
return rv;
return rv;
}
/*****************************************************************************/
@ -154,16 +155,16 @@ tbus APP_CC
tc_sem_create(int init_count)
{
#if defined(_WIN32)
HANDLE sem;
HANDLE sem;
sem = CreateSemaphore(0, init_count, init_count + 10, 0);
return (tbus)sem;
sem = CreateSemaphore(0, init_count, init_count + 10, 0);
return (tbus)sem;
#else
sem_t * sem = (sem_t *)NULL;
sem_t *sem = (sem_t *)NULL;
sem = (sem_t *)g_malloc(sizeof(sem_t), 0);
sem_init(sem, 0, init_count);
return (tbus)sem;
sem = (sem_t *)g_malloc(sizeof(sem_t), 0);
sem_init(sem, 0, init_count);
return (tbus)sem;
#endif
}
@ -172,13 +173,13 @@ void APP_CC
tc_sem_delete(tbus sem)
{
#if defined(_WIN32)
CloseHandle((HANDLE)sem);
CloseHandle((HANDLE)sem);
#else
sem_t* lsem;
sem_t *lsem;
lsem = (sem_t*)sem;
sem_destroy(lsem);
g_free(lsem);
lsem = (sem_t *)sem;
sem_destroy(lsem);
g_free(lsem);
#endif
}
@ -187,11 +188,11 @@ int APP_CC
tc_sem_dec(tbus sem)
{
#if defined(_WIN32)
WaitForSingleObject((HANDLE)sem, INFINITE);
return 0;
WaitForSingleObject((HANDLE)sem, INFINITE);
return 0;
#else
sem_wait((sem_t*)sem);
return 0;
sem_wait((sem_t *)sem);
return 0;
#endif
}
@ -200,10 +201,10 @@ int APP_CC
tc_sem_inc(tbus sem)
{
#if defined(_WIN32)
ReleaseSemaphore((HANDLE)sem, 1, 0);
return 0;
ReleaseSemaphore((HANDLE)sem, 1, 0);
return 0;
#else
sem_post((sem_t*)sem);
return 0;
sem_post((sem_t *)sem);
return 0;
#endif
}

@ -1,27 +1,22 @@
/*
Copyright (c) 2004-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
thread calls
*/
/**
* 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.
*
* thread calls
*/
#if !defined(THREAD_CALLS_H)
#define THREAD_CALLS_H

@ -1,27 +1,22 @@
/*
Copyright (c) 2008-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
generic transport
*/
/**
* 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.
*
* generic transport
*/
#include "os_calls.h"
#include "trans.h"
@ -29,394 +24,440 @@
#include "parse.h"
/*****************************************************************************/
struct trans* APP_CC
struct trans *APP_CC
trans_create(int mode, int in_size, int out_size)
{
struct trans* self = (struct trans *)NULL;
self = (struct trans*)g_malloc(sizeof(struct trans), 1);
if (self != NULL) {
make_stream(self->in_s);
init_stream(self->in_s, in_size);
make_stream(self->out_s);
init_stream(self->out_s, out_size);
self->mode = mode;
}
return self;
struct trans *self = (struct trans *)NULL;
self = (struct trans *)g_malloc(sizeof(struct trans), 1);
if (self != NULL)
{
make_stream(self->in_s);
init_stream(self->in_s, in_size);
make_stream(self->out_s);
init_stream(self->out_s, out_size);
self->mode = mode;
}
return self;
}
/*****************************************************************************/
void APP_CC
trans_delete(struct trans* self)
trans_delete(struct trans *self)
{
if (self == 0)
{
return;
}
free_stream(self->in_s);
free_stream(self->out_s);
if (self->sck > 0) {
g_tcp_close(self->sck);
}
self->sck = 0;
if (self->listen_filename != 0)
{
g_file_delete(self->listen_filename);
g_free(self->listen_filename);
}
g_free(self);
if (self == 0)
{
return;
}
free_stream(self->in_s);
free_stream(self->out_s);
if (self->sck > 0)
{
g_tcp_close(self->sck);
}
self->sck = 0;
if (self->listen_filename != 0)
{
g_file_delete(self->listen_filename);
g_free(self->listen_filename);
}
g_free(self);
}
/*****************************************************************************/
int APP_CC
trans_get_wait_objs(struct trans* self, tbus* objs, int* count)
trans_get_wait_objs(struct trans *self, tbus *objs, int *count)
{
if (self == 0)
{
return 1;
}
if (self->status != TRANS_STATUS_UP)
{
return 1;
}
objs[*count] = self->sck;
(*count)++;
return 0;
if (self == 0)
{
return 1;
}
if (self->status != TRANS_STATUS_UP)
{
return 1;
}
objs[*count] = self->sck;
(*count)++;
return 0;
}
/*****************************************************************************/
int APP_CC
trans_check_wait_objs(struct trans* self)
trans_check_wait_objs(struct trans *self)
{
tbus in_sck = (tbus)0;
struct trans* in_trans = (struct trans *)NULL;
int read_bytes = 0;
int to_read = 0;
int read_so_far = 0;
int rv = 0;
if (self == 0)
{
return 1;
}
if (self->status != TRANS_STATUS_UP)
{
return 1;
}
rv = 0;
if (self->type1 == TRANS_TYPE_LISTENER) /* listening */
{
if (g_tcp_can_recv(self->sck, 0))
tbus in_sck = (tbus)0;
struct trans *in_trans = (struct trans *)NULL;
int read_bytes = 0;
int to_read = 0;
int read_so_far = 0;
int rv = 0;
if (self == 0)
{
in_sck = g_tcp_accept(self->sck);
if (in_sck == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
/* ok, but shouldn't happen */
}
else
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
if (in_sck != -1)
{
if (self->trans_conn_in != 0) /* is function assigned */
return 1;
}
if (self->status != TRANS_STATUS_UP)
{
return 1;
}
rv = 0;
if (self->type1 == TRANS_TYPE_LISTENER) /* listening */
{
if (g_tcp_can_recv(self->sck, 0))
{
in_trans = trans_create(self->mode, self->in_s->size,
self->out_s->size);
in_trans->sck = in_sck;
in_trans->type1 = TRANS_TYPE_SERVER;
in_trans->status = TRANS_STATUS_UP;
if (self->trans_conn_in(self, in_trans) != 0)
{
trans_delete(in_trans);
}
in_sck = g_tcp_accept(self->sck);
if (in_sck == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
/* ok, but shouldn't happen */
}
else
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
if (in_sck != -1)
{
if (self->trans_conn_in != 0) /* is function assigned */
{
in_trans = trans_create(self->mode, self->in_s->size,
self->out_s->size);
in_trans->sck = in_sck;
in_trans->type1 = TRANS_TYPE_SERVER;
in_trans->status = TRANS_STATUS_UP;
if (self->trans_conn_in(self, in_trans) != 0)
{
trans_delete(in_trans);
}
}
else
{
g_tcp_close(in_sck);
}
}
}
else
}
else /* connected server or client (2 or 3) */
{
if (g_tcp_can_recv(self->sck, 0))
{
g_tcp_close(in_sck);
read_so_far = (int)(self->in_s->end - self->in_s->data);
to_read = self->header_size - read_so_far;
if (to_read > 0)
{
read_bytes = g_tcp_recv(self->sck, self->in_s->end, to_read, 0);
if (read_bytes == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
/* ok, but shouldn't happen */
}
else
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
else if (read_bytes == 0)
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
else
{
self->in_s->end += read_bytes;
}
}
read_so_far = (int)(self->in_s->end - self->in_s->data);
if (read_so_far == self->header_size)
{
if (self->trans_data_in != 0)
{
rv = self->trans_data_in(self);
init_stream(self->in_s, 0);
}
}
}
}
}
}
else /* connected server or client (2 or 3) */
{
if (g_tcp_can_recv(self->sck, 0))
return rv;
}
/*****************************************************************************/
int APP_CC
trans_force_read_s(struct trans *self, struct stream *in_s, int size)
{
int rcvd;
if (self->status != TRANS_STATUS_UP)
{
return 1;
}
while (size > 0)
{
read_so_far = (int)(self->in_s->end - self->in_s->data);
to_read = self->header_size - read_so_far;
if (to_read > 0)
{
read_bytes = g_tcp_recv(self->sck, self->in_s->end, to_read, 0);
if (read_bytes == -1)
rcvd = g_tcp_recv(self->sck, in_s->end, size, 0);
if (rcvd == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
if (!g_tcp_can_recv(self->sck, 10))
{
/* check for term here */
}
}
else
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
else if (rcvd == 0)
{
if (g_tcp_last_error_would_block(self->sck))
{
/* ok, but shouldn't happen */
}
else
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
else if (read_bytes == 0)
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
else
{
self->in_s->end += read_bytes;
in_s->end += rcvd;
size -= rcvd;
}
}
read_so_far = (int)(self->in_s->end - self->in_s->data);
if (read_so_far == self->header_size)
{
if (self->trans_data_in != 0)
{
rv = self->trans_data_in(self);
init_stream(self->in_s, 0);
}
}
}
}
return rv;
return 0;
}
/*****************************************************************************/
int APP_CC
trans_force_read_s(struct trans* self, struct stream* in_s, int size)
trans_force_read(struct trans *self, int size)
{
int rcvd;
return trans_force_read_s(self, self->in_s, size);
}
if (self->status != TRANS_STATUS_UP)
{
return 1;
}
while (size > 0)
{
rcvd = g_tcp_recv(self->sck, in_s->end, size, 0);
if (rcvd == -1)
/*****************************************************************************/
int APP_CC
trans_force_write_s(struct trans *self, struct stream *out_s)
{
int size;
int total;
int sent;
if (self->status != TRANS_STATUS_UP)
{
if (g_tcp_last_error_would_block(self->sck))
{
if (!g_tcp_can_recv(self->sck, 10))
{
/* check for term here */
}
}
else
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
else if (rcvd == 0)
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
else
size = (int)(out_s->end - out_s->data);
total = 0;
while (total < size)
{
in_s->end += rcvd;
size -= rcvd;
sent = g_tcp_send(self->sck, out_s->data + total, size - total, 0);
if (sent == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
if (!g_tcp_can_send(self->sck, 10))
{
/* check for term here */
}
}
else
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
else if (sent == 0)
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
else
{
total = total + sent;
}
}
}
return 0;
return 0;
}
/*****************************************************************************/
int APP_CC
trans_force_read(struct trans* self, int size)
trans_force_write(struct trans *self)
{
return trans_force_read_s(self, self->in_s, size);
return trans_force_write_s(self, self->out_s);
}
/*****************************************************************************/
int APP_CC
trans_force_write_s(struct trans* self, struct stream* out_s)
trans_connect(struct trans *self, const char *server, const char *port,
int timeout)
{
int size;
int total;
int sent;
int error;
if (self->status != TRANS_STATUS_UP)
{
return 1;
}
size = (int)(out_s->end - out_s->data);
total = 0;
while (total < size)
{
sent = g_tcp_send(self->sck, out_s->data + total, size - total, 0);
if (sent == -1)
if (self->sck != 0)
{
if (g_tcp_last_error_would_block(self->sck))
{
if (!g_tcp_can_send(self->sck, 10))
{
/* check for term here */
}
}
else
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
}
g_tcp_close(self->sck);
}
else if (sent == 0)
if (self->mode == TRANS_MODE_TCP) /* tcp */
{
/* error */
self->status = TRANS_STATUS_DOWN;
return 1;
self->sck = g_tcp_socket();
g_tcp_set_non_blocking(self->sck);
error = g_tcp_connect(self->sck, server, port);
}
else if (self->mode == TRANS_MODE_UNIX) /* unix socket */
{
self->sck = g_tcp_local_socket();
g_tcp_set_non_blocking(self->sck);
error = g_tcp_local_connect(self->sck, port);
}
else
{
total = total + sent;
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
return 0;
}
/*****************************************************************************/
int APP_CC
trans_force_write(struct trans* self)
{
return trans_force_write_s(self, self->out_s);
if (error == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
if (g_tcp_can_send(self->sck, timeout))
{
self->status = TRANS_STATUS_UP; /* ok */
self->type1 = TRANS_TYPE_CLIENT; /* client */
return 0;
}
}
return 1;
}
self->status = TRANS_STATUS_UP; /* ok */
self->type1 = TRANS_TYPE_CLIENT; /* client */
return 0;
}
/*****************************************************************************/
int APP_CC
trans_connect(struct trans* self, const char* server, const char* port,
int timeout)
trans_listen_address(struct trans *self, char *port, const char *address)
{
int error;
if (self->sck != 0)
{
g_tcp_close(self->sck);
}
if (self->mode == TRANS_MODE_TCP) /* tcp */
{
self->sck = g_tcp_socket();
g_tcp_set_non_blocking(self->sck);
error = g_tcp_connect(self->sck, server, port);
}
else if (self->mode == TRANS_MODE_UNIX) /* unix socket */
{
self->sck = g_tcp_local_socket();
g_tcp_set_non_blocking(self->sck);
error = g_tcp_local_connect(self->sck, port);
}
else
{
self->status = TRANS_STATUS_DOWN;
return 1;
}
if (error == -1)
{
if (g_tcp_last_error_would_block(self->sck))
if (self->sck != 0)
{
if (g_tcp_can_send(self->sck, timeout))
{
self->status = TRANS_STATUS_UP; /* ok */
self->type1 = TRANS_TYPE_CLIENT; /* client */
return 0;
}
g_tcp_close(self->sck);
}
return 1;
}
self->status = TRANS_STATUS_UP; /* ok */
self->type1 = TRANS_TYPE_CLIENT; /* client */
return 0;
}
/*****************************************************************************/
int APP_CC
trans_listen_address(struct trans* self, char* port, const char* address)
{
if (self->sck != 0)
{
g_tcp_close(self->sck);
}
if (self->mode == TRANS_MODE_TCP) /* tcp */
{
self->sck = g_tcp_socket();
g_tcp_set_non_blocking(self->sck);
if (g_tcp_bind_address(self->sck, port, address) == 0)
if (self->mode == TRANS_MODE_TCP) /* tcp */
{
if (g_tcp_listen(self->sck) == 0)
{
self->status = TRANS_STATUS_UP; /* ok */
self->type1 = TRANS_TYPE_LISTENER; /* listener */
return 0;
}
self->sck = g_tcp_socket();
g_tcp_set_non_blocking(self->sck);
if (g_tcp_bind_address(self->sck, port, address) == 0)
{
if (g_tcp_listen(self->sck) == 0)
{
self->status = TRANS_STATUS_UP; /* ok */
self->type1 = TRANS_TYPE_LISTENER; /* listener */
return 0;
}
}
}
}
else if (self->mode == TRANS_MODE_UNIX) /* unix socket */
{
g_free(self->listen_filename);
self->listen_filename = 0;
g_file_delete(port);
self->sck = g_tcp_local_socket();
g_tcp_set_non_blocking(self->sck);
if (g_tcp_local_bind(self->sck, port) == 0)
else if (self->mode == TRANS_MODE_UNIX) /* unix socket */
{
self->listen_filename = g_strdup(port);
if (g_tcp_listen(self->sck) == 0)
{
g_chmod_hex(port, 0xffff);
self->status = TRANS_STATUS_UP; /* ok */
self->type1 = TRANS_TYPE_LISTENER; /* listener */
return 0;
}
g_free(self->listen_filename);
self->listen_filename = 0;
g_file_delete(port);
self->sck = g_tcp_local_socket();
g_tcp_set_non_blocking(self->sck);
if (g_tcp_local_bind(self->sck, port) == 0)
{
self->listen_filename = g_strdup(port);
if (g_tcp_listen(self->sck) == 0)
{
g_chmod_hex(port, 0xffff);
self->status = TRANS_STATUS_UP; /* ok */
self->type1 = TRANS_TYPE_LISTENER; /* listener */
return 0;
}
}
}
}
return 1;
return 1;
}
/*****************************************************************************/
int APP_CC
trans_listen(struct trans* self, char* port)
trans_listen(struct trans *self, char *port)
{
return trans_listen_address(self, port, "0.0.0.0");
return trans_listen_address(self, port, "0.0.0.0");
}
/*****************************************************************************/
struct stream* APP_CC
trans_get_in_s(struct trans* self)
struct stream *APP_CC
trans_get_in_s(struct trans *self)
{
struct stream * rv = (struct stream *)NULL;
if (self == NULL) {
rv = (struct stream *)NULL;
}
else {
rv = self->in_s;
}
return rv;
struct stream *rv = (struct stream *)NULL;
if (self == NULL)
{
rv = (struct stream *)NULL;
}
else
{
rv = self->in_s;
}
return rv;
}
/*****************************************************************************/
struct stream* APP_CC
trans_get_out_s(struct trans* self, int size)
struct stream *APP_CC
trans_get_out_s(struct trans *self, int size)
{
struct stream * rv = (struct stream *)NULL;
if (self == NULL) {
rv = (struct stream *)NULL;
}
else {
init_stream(self->out_s, size);
rv = self->out_s;
}
return rv;
struct stream *rv = (struct stream *)NULL;
if (self == NULL)
{
rv = (struct stream *)NULL;
}
else
{
init_stream(self->out_s, size);
rv = self->out_s;
}
return rv;
}

@ -1,27 +1,22 @@
/*
Copyright (c) 2008-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
generic transport
*/
/**
* 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.
*
* generic transport
*/
#if !defined(TRANS_H)
#define TRANS_H

@ -1,27 +1,22 @@
/*
Copyright (c) 2012 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
xrdp / xserver info / caps
*/
/**
* 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.
*
* xrdp / xserver info / caps
*/
#if !defined(XRDP_CLIENT_INFO_H)
#define XRDP_CLIENT_INFO_H

@ -1,3 +1,20 @@
/**
* 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.
*/
#include <windows.h>
#include <tchar.h>
@ -25,426 +42,485 @@ static int g_running = 0;
int
check_messages(void)
{
MSG msg;
while (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
{
GetMessage(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
MSG msg;
while (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
{
GetMessage(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
/*****************************************************************************/
static int
msg(char* msg1, ...)
msg(char *msg1, ...)
{
va_list ap;
char text1[512];
va_start(ap, msg1);
vsnprintf(text1, 511, msg1, ap);
SendMessageA(g_lb, LB_ADDSTRING, 0, (LPARAM)text1);
va_end(ap);
return 0;
va_list ap;
char text1[512];
va_start(ap, msg1);
vsnprintf(text1, 511, msg1, ap);
SendMessageA(g_lb, LB_ADDSTRING, 0, (LPARAM)text1);
va_end(ap);
return 0;
}
/*****************************************************************************/
static int
show_last_error(void)
{
LPVOID lpMsgBuf;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&lpMsgBuf, 0, NULL);
msg("GetLastError - %s", lpMsgBuf);
LocalFree(lpMsgBuf);
return 0;
LPVOID lpMsgBuf;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&lpMsgBuf, 0, NULL);
msg("GetLastError - %s", lpMsgBuf);
LocalFree(lpMsgBuf);
return 0;
}
/*****************************************************************************/
static int
font_dump(void)
{
HDC dc;
HDC dc1;
RECT rect;
HBRUSH brush;
HGDIOBJ saved;
HBITMAP bitmap;
BITMAPINFO bi;
char* bits;
ABC abc;
SIZE sz;
char filename[256];
TCHAR text[256];
char zero1;
char* bmtext;
int bmtextindex;
int fd;
int x1;
int strlen1;
int index1;
int index2;
int len;
int pixel;
int red;
int green;
int blue;
int width;
int height;
int roller;
int outlen;
tui8 b1;
short x2;
if (g_running)
{
return 0;
}
g_running = 1;
msg("starting");
g_font_name[0] = 0;
SendMessageA(g_font_list, WM_GETTEXT, 255, (LPARAM)g_font_name);
if (g_strlen(g_font_name) == 0)
{
msg("error font not set");
g_running = 0;
return 1;
}
dc = GetDC(g_wnd);
height = -MulDiv(g_font_size, GetDeviceCaps(dc, LOGPIXELSY), 72);
g_font = CreateFontA(height, 0, 0, 0, FW_DONTCARE, 0, 0, 0, 0, 0, 0,
0, 0, g_font_name);
ReleaseDC(g_wnd, dc);
if (g_font == 0)
{
msg("error - Font creation failed");
}
zero1 = 0;
g_snprintf(filename, 255, "%s-%d.fv1", g_font_name, g_font_size);
msg("creating file %s", filename);
g_file_delete(filename);
fd = g_file_open(filename);
g_file_write(fd, "FNT1", 4);
strlen1 = g_strlen(g_font_name);
g_file_write(fd, g_font_name, strlen1);
x1 = strlen1;
while (x1 < 32)
{
g_file_write(fd, &zero1, 1);
x1++;
}
x2 = g_font_size; /* font size */
g_file_write(fd, (char*)&x2, 2);
x2 = 1; /* style */
g_file_write(fd, (char*)&x2, 2);
/* pad */
index1 = 0;
while (index1 < 8)
{
g_file_write(fd, &zero1, 1);
index1++;
}
for (x1 = 32; x1 < 0x4e00; x1++)
{
check_messages();
dc = GetWindowDC(g_wnd);
saved = SelectObject(dc, g_font);
if (!GetCharABCWidths(dc, x1, x1, &abc))
HDC dc;
HDC dc1;
RECT rect;
HBRUSH brush;
HGDIOBJ saved;
HBITMAP bitmap;
BITMAPINFO bi;
char *bits;
ABC abc;
SIZE sz;
char filename[256];
TCHAR text[256];
char zero1;
char *bmtext;
int bmtextindex;
int fd;
int x1;
int strlen1;
int index1;
int index2;
int len;
int pixel;
int red;
int green;
int blue;
int width;
int height;
int roller;
int outlen;
tui8 b1;
short x2;
if (g_running)
{
show_last_error();
return 0;
}
text[0] = (TCHAR)x1;
text[1] = 0;
if (!GetTextExtentPoint32(dc, text, 1, &sz))
g_running = 1;
msg("starting");
g_font_name[0] = 0;
SendMessageA(g_font_list, WM_GETTEXT, 255, (LPARAM)g_font_name);
if (g_strlen(g_font_name) == 0)
{
show_last_error();
msg("error font not set");
g_running = 0;
return 1;
}
SelectObject(dc, saved);
dc = GetDC(g_wnd);
height = -MulDiv(g_font_size, GetDeviceCaps(dc, LOGPIXELSY), 72);
g_font = CreateFontA(height, 0, 0, 0, FW_DONTCARE, 0, 0, 0, 0, 0, 0,
0, 0, g_font_name);
ReleaseDC(g_wnd, dc);
if ((sz.cx > 0) && (sz.cy > 0))
if (g_font == 0)
{
msg("error - Font creation failed");
}
zero1 = 0;
g_snprintf(filename, 255, "%s-%d.fv1", g_font_name, g_font_size);
msg("creating file %s", filename);
g_file_delete(filename);
fd = g_file_open(filename);
g_file_write(fd, "FNT1", 4);
strlen1 = g_strlen(g_font_name);
g_file_write(fd, g_font_name, strlen1);
x1 = strlen1;
while (x1 < 32)
{
g_file_write(fd, &zero1, 1);
x1++;
}
x2 = g_font_size; /* font size */
g_file_write(fd, (char *)&x2, 2);
x2 = 1; /* style */
g_file_write(fd, (char *)&x2, 2);
/* pad */
index1 = 0;
while (index1 < 8)
{
dc = GetWindowDC(g_wnd);
saved = SelectObject(dc, g_font);
SetBkColor(dc, RGB(255, 255, 255));
if (!ExtTextOut(dc, 50, 50, ETO_OPAQUE, 0, text, 1, 0))
{
show_last_error();
}
SelectObject(dc, saved);
ReleaseDC(g_wnd, dc);
Sleep(10);
/* width */
x2 = abc.abcB;
g_file_write(fd, (char*)&x2, 2);
/* height */
x2 = sz.cy;
g_file_write(fd, (char*)&x2, 2);
/* baseline */
x2 = -sz.cy;
g_file_write(fd, (char*)&x2, 2);
/* offset */
x2 = abc.abcA;
g_file_write(fd, (char*)&x2, 2);
/* incby */
x2 = sz.cx;
g_file_write(fd, (char*)&x2, 2);
/* pad */
index1 = 0;
while (index1 < 6)
{
g_file_write(fd, &zero1, 1);
index1++;
}
dc = GetWindowDC(g_wnd);
rect.left = 50 + abc.abcA;
rect.top = 50;
rect.right = rect.left + abc.abcB;
rect.bottom = rect.top + sz.cy;
memset(&bi, 0, sizeof(bi));
width = (abc.abcB + 7) & (~7);
height = sz.cy;
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
bi.bmiHeader.biWidth = width;
bi.bmiHeader.biHeight = height;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
bitmap = CreateDIBSection(dc, &bi, DIB_RGB_COLORS, (void*)&bits, 0, 0);
if (bitmap == 0)
{
msg("error - CreateDIBSection failed");
}
else
{
memset(bits, 0, width * height * 4);
dc1 = CreateCompatibleDC(dc);
SelectObject(dc1, bitmap);
if (!BitBlt(dc1, 0, 0, width, height, dc, rect.left, rect.top, SRCCOPY))
}
for (x1 = 32; x1 < 0x4e00; x1++)
{
check_messages();
dc = GetWindowDC(g_wnd);
saved = SelectObject(dc, g_font);
if (!GetCharABCWidths(dc, x1, x1, &abc))
{
show_last_error();
}
text[0] = (TCHAR)x1;
text[1] = 0;
if (!GetTextExtentPoint32(dc, text, 1, &sz))
{
show_last_error();
show_last_error();
}
bmtext = (char*)g_malloc(width * height + 16, 1);
bmtextindex = 0;
for (index1 = (height - 1); index1 >= 0; index1--)
SelectObject(dc, saved);
ReleaseDC(g_wnd, dc);
if ((sz.cx > 0) && (sz.cy > 0))
{
for (index2 = 0; index2 < width; index2++)
{
pixel = ((int*)bits)[index1 * width + index2];
red = (pixel >> 16) & 0xff;
green = (pixel >> 8) & 0xff;
blue = (pixel >> 0) & 0xff;
if (red == 0 && green == 0 && blue == 0)
dc = GetWindowDC(g_wnd);
saved = SelectObject(dc, g_font);
SetBkColor(dc, RGB(255, 255, 255));
if (!ExtTextOut(dc, 50, 50, ETO_OPAQUE, 0, text, 1, 0))
{
show_last_error();
}
SelectObject(dc, saved);
ReleaseDC(g_wnd, dc);
Sleep(10);
/* width */
x2 = abc.abcB;
g_file_write(fd, (char *)&x2, 2);
/* height */
x2 = sz.cy;
g_file_write(fd, (char *)&x2, 2);
/* baseline */
x2 = -sz.cy;
g_file_write(fd, (char *)&x2, 2);
/* offset */
x2 = abc.abcA;
g_file_write(fd, (char *)&x2, 2);
/* incby */
x2 = sz.cx;
g_file_write(fd, (char *)&x2, 2);
/* pad */
index1 = 0;
while (index1 < 6)
{
g_file_write(fd, &zero1, 1);
index1++;
}
dc = GetWindowDC(g_wnd);
rect.left = 50 + abc.abcA;
rect.top = 50;
rect.right = rect.left + abc.abcB;
rect.bottom = rect.top + sz.cy;
memset(&bi, 0, sizeof(bi));
width = (abc.abcB + 7) & (~7);
height = sz.cy;
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
bi.bmiHeader.biWidth = width;
bi.bmiHeader.biHeight = height;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
bitmap = CreateDIBSection(dc, &bi, DIB_RGB_COLORS, (void *)&bits, 0, 0);
if (bitmap == 0)
{
bmtext[bmtextindex] = '1';
bmtextindex++;
msg("error - CreateDIBSection failed");
}
else
{
bmtext[bmtextindex] = '0';
bmtextindex++;
memset(bits, 0, width * height * 4);
dc1 = CreateCompatibleDC(dc);
SelectObject(dc1, bitmap);
if (!BitBlt(dc1, 0, 0, width, height, dc, rect.left, rect.top, SRCCOPY))
{
show_last_error();
}
bmtext = (char *)g_malloc(width * height + 16, 1);
bmtextindex = 0;
for (index1 = (height - 1); index1 >= 0; index1--)
{
for (index2 = 0; index2 < width; index2++)
{
pixel = ((int *)bits)[index1 * width + index2];
red = (pixel >> 16) & 0xff;
green = (pixel >> 8) & 0xff;
blue = (pixel >> 0) & 0xff;
if (red == 0 && green == 0 && blue == 0)
{
bmtext[bmtextindex] = '1';
bmtextindex++;
}
else
{
bmtext[bmtextindex] = '0';
bmtextindex++;
}
}
}
outlen = 0;
b1 = 0;
roller = 0;
len = g_strlen(bmtext);
for (index2 = 0; index2 < len; index2++)
{
if (bmtext[index2] == '1')
{
switch (roller)
{
case 0:
b1 = b1 | 0x80;
break;
case 1:
b1 = b1 | 0x40;
break;
case 2:
b1 = b1 | 0x20;
break;
case 3:
b1 = b1 | 0x10;
break;
case 4:
b1 = b1 | 0x08;
break;
case 5:
b1 = b1 | 0x04;
break;
case 6:
b1 = b1 | 0x02;
break;
case 7:
b1 = b1 | 0x01;
break;
}
}
roller++;
if (roller == 8)
{
roller = 0;
g_file_write(fd, &b1, 1);
outlen++;
b1 = 0;
}
}
while ((outlen % 4) != 0)
{
g_file_write(fd, &zero1, 1);
outlen++;
}
free(bmtext);
DeleteDC(dc1);
DeleteObject(bitmap);
}
}
}
outlen = 0;
b1 = 0;
roller = 0;
len = g_strlen(bmtext);
for (index2 = 0; index2 < len; index2++)
{
if (bmtext[index2] == '1')
{
switch (roller)
if (sz.cx != (long)(abc.abcA + abc.abcB + abc.abcC))
{
case 0: b1 = b1 | 0x80; break;
case 1: b1 = b1 | 0x40; break;
case 2: b1 = b1 | 0x20; break;
case 3: b1 = b1 | 0x10; break;
case 4: b1 = b1 | 0x08; break;
case 5: b1 = b1 | 0x04; break;
case 6: b1 = b1 | 0x02; break;
case 7: b1 = b1 | 0x01; break;
msg("error - width not right 1");
}
}
roller++;
if (roller == 8)
{
roller = 0;
g_file_write(fd, &b1, 1);
outlen++;
b1 = 0;
}
brush = CreateSolidBrush(RGB(255, 255, 255));
FillRect(dc, &rect, brush);
DeleteObject(brush);
ReleaseDC(g_wnd, dc);
}
while ((outlen % 4) != 0)
else
{
g_file_write(fd, &zero1, 1);
outlen++;
/* write out a blank glyph here */
/* width */
x2 = 1;
g_file_write(fd, (char *)&x2, 2);
/* height */
x2 = 1;
g_file_write(fd, (char *)&x2, 2);
/* baseline */
x2 = 0;
g_file_write(fd, (char *)&x2, 2);
/* offset */
x2 = 0;
g_file_write(fd, (char *)&x2, 2);
/* incby */
x2 = 1;
g_file_write(fd, (char *)&x2, 2);
/* pad */
index1 = 0;
while (index1 < 6)
{
g_file_write(fd, &zero1, 1);
index1++;
}
/* blank bitmap */
index1 = 0;
while (index1 < 4)
{
g_file_write(fd, &zero1, 1);
index1++;
}
}
free(bmtext);
DeleteDC(dc1);
DeleteObject(bitmap);
}
if (sz.cx != (long)(abc.abcA + abc.abcB + abc.abcC))
{
msg("error - width not right 1");
}
brush = CreateSolidBrush(RGB(255, 255, 255));
FillRect(dc, &rect, brush);
DeleteObject(brush);
ReleaseDC(g_wnd, dc);
}
else
{
/* write out a blank glyph here */
/* width */
x2 = 1;
g_file_write(fd, (char*)&x2, 2);
/* height */
x2 = 1;
g_file_write(fd, (char*)&x2, 2);
/* baseline */
x2 = 0;
g_file_write(fd, (char*)&x2, 2);
/* offset */
x2 = 0;
g_file_write(fd, (char*)&x2, 2);
/* incby */
x2 = 1;
g_file_write(fd, (char*)&x2, 2);
/* pad */
index1 = 0;
while (index1 < 6)
{
g_file_write(fd, &zero1, 1);
index1++;
}
/* blank bitmap */
index1 = 0;
while (index1 < 4)
{
g_file_write(fd, &zero1, 1);
index1++;
}
}
}
g_file_close(fd);
msg("done");
g_running = 0;
return 0;
g_file_close(fd);
msg("done");
g_running = 0;
return 0;
}
/*****************************************************************************/
static LRESULT CALLBACK
wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HBRUSH brush;
RECT rect;
switch (message)
{
case WM_PAINT:
BeginPaint(hWnd, &ps);
brush = CreateSolidBrush(RGB(255, 255, 255));
rect = ps.rcPaint;
FillRect(ps.hdc, &rect, brush);
DeleteObject(brush);
EndPaint(hWnd, &ps);
break;
case WM_CLOSE:
DestroyWindow(g_wnd);
g_wnd = 0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_TIMER:
KillTimer(g_wnd, 1);
font_dump();
break;
case WM_COMMAND:
if ((HWND)lParam == g_exit_button)
{
PostMessage(g_wnd, WM_CLOSE, 0, 0);
}
else if ((HWND)lParam == g_go_button)
{
while (SendMessage(g_lb, LB_GETCOUNT, 0, 0) > 0)
{
SendMessage(g_lb, LB_DELETESTRING, 0, 0);
}
SetTimer(g_wnd, 1, 1000, 0);
}
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
PAINTSTRUCT ps;
HBRUSH brush;
RECT rect;
switch (message)
{
case WM_PAINT:
BeginPaint(hWnd, &ps);
brush = CreateSolidBrush(RGB(255, 255, 255));
rect = ps.rcPaint;
FillRect(ps.hdc, &rect, brush);
DeleteObject(brush);
EndPaint(hWnd, &ps);
break;
case WM_CLOSE:
DestroyWindow(g_wnd);
g_wnd = 0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_TIMER:
KillTimer(g_wnd, 1);
font_dump();
break;
case WM_COMMAND:
if ((HWND)lParam == g_exit_button)
{
PostMessage(g_wnd, WM_CLOSE, 0, 0);
}
else if ((HWND)lParam == g_go_button)
{
while (SendMessage(g_lb, LB_GETCOUNT, 0, 0) > 0)
{
SendMessage(g_lb, LB_DELETESTRING, 0, 0);
}
SetTimer(g_wnd, 1, 1000, 0);
}
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
/*****************************************************************************/
static int
create_window(void)
{
WNDCLASS wc;
DWORD style;
HDC dc;
int height;
int left;
int top;
ZeroMemory(&wc, sizeof(wc));
wc.lpfnWndProc = wnd_proc; /* points to window procedure */
/* name of window class */
wc.lpszClassName = _T("fontdump");
wc.hCursor = LoadCursor(0, IDC_ARROW);
/* Register the window class. */
if (!RegisterClass(&wc))
{
return 0; /* Failed to register window class */
}
style = WS_OVERLAPPED | WS_CAPTION | WS_POPUP | WS_MINIMIZEBOX |
WS_SYSMENU | WS_SIZEBOX | WS_MAXIMIZEBOX;
left = GetSystemMetrics(SM_CXSCREEN) / 2 - 640 / 2;
top = GetSystemMetrics(SM_CYSCREEN) / 2 - 480 / 2;
g_wnd = CreateWindow(wc.lpszClassName, _T("fontdump"),
style, left, top, 640, 480,
(HWND) NULL, (HMENU) NULL, g_instance,
(LPVOID) NULL);
style = WS_CHILD | WS_VISIBLE | WS_BORDER;
g_lb = CreateWindow(_T("LISTBOX"), _T("LISTBOX1"), style,
200, 10, 400, 400, g_wnd, 0, g_instance, 0);
style = WS_CHILD | WS_VISIBLE;
g_exit_button = CreateWindow(_T("BUTTON"), _T("Exit"), style,
540, 410, 75, 25, g_wnd, 0, g_instance, 0);
g_go_button = CreateWindow(_T("BUTTON"), _T("Go"), style,
440, 410, 75, 25, g_wnd, 0, g_instance, 0);
style = WS_CHILD | WS_VISIBLE | CBS_DROPDOWN;
g_font_list = CreateWindow(_T("COMBOBOX"), _T("COMBOBOX1"), style,
50, 250, 125, 125, g_wnd, 0, g_instance, 0);
ShowWindow(g_wnd, SW_SHOWNORMAL);
PostMessage(g_wnd, WM_SETFONT, (WPARAM)g_font, 0);
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Tahoma");
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"DejaVu Serif");
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"DejaVu Sans");
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Arial");
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Comic Sans MS");
return 0;
WNDCLASS wc;
DWORD style;
HDC dc;
int height;
int left;
int top;
ZeroMemory(&wc, sizeof(wc));
wc.lpfnWndProc = wnd_proc; /* points to window procedure */
/* name of window class */
wc.lpszClassName = _T("fontdump");
wc.hCursor = LoadCursor(0, IDC_ARROW);
/* Register the window class. */
if (!RegisterClass(&wc))
{
return 0; /* Failed to register window class */
}
style = WS_OVERLAPPED | WS_CAPTION | WS_POPUP | WS_MINIMIZEBOX |
WS_SYSMENU | WS_SIZEBOX | WS_MAXIMIZEBOX;
left = GetSystemMetrics(SM_CXSCREEN) / 2 - 640 / 2;
top = GetSystemMetrics(SM_CYSCREEN) / 2 - 480 / 2;
g_wnd = CreateWindow(wc.lpszClassName, _T("fontdump"),
style, left, top, 640, 480,
(HWND) NULL, (HMENU) NULL, g_instance,
(LPVOID) NULL);
style = WS_CHILD | WS_VISIBLE | WS_BORDER;
g_lb = CreateWindow(_T("LISTBOX"), _T("LISTBOX1"), style,
200, 10, 400, 400, g_wnd, 0, g_instance, 0);
style = WS_CHILD | WS_VISIBLE;
g_exit_button = CreateWindow(_T("BUTTON"), _T("Exit"), style,
540, 410, 75, 25, g_wnd, 0, g_instance, 0);
g_go_button = CreateWindow(_T("BUTTON"), _T("Go"), style,
440, 410, 75, 25, g_wnd, 0, g_instance, 0);
style = WS_CHILD | WS_VISIBLE | CBS_DROPDOWN;
g_font_list = CreateWindow(_T("COMBOBOX"), _T("COMBOBOX1"), style,
50, 250, 125, 125, g_wnd, 0, g_instance, 0);
ShowWindow(g_wnd, SW_SHOWNORMAL);
PostMessage(g_wnd, WM_SETFONT, (WPARAM)g_font, 0);
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Tahoma");
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"DejaVu Serif");
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"DejaVu Sans");
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Arial");
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Comic Sans MS");
return 0;
}
/*****************************************************************************/
static int
main_loop(void)
{
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)(msg.wParam);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)(msg.wParam);
}
/*****************************************************************************/
@ -452,7 +528,7 @@ int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
g_instance = hInstance;
create_window();
return main_loop();
g_instance = hInstance;
create_window();
return main_loop();
}

@ -1,279 +1,314 @@
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
/**
* 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.
*
* freerdp wrapper
*/
This program 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. See the
GNU General Public License for more details.
#include "xrdp-freerdp.h"
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
char *APP_CC
convert_bitmap(int in_bpp, int out_bpp, char *bmpdata,
int width, int height, int *palette)
{
char *out;
char *src;
char *dst;
int i;
int j;
int red;
int green;
int blue;
int pixel;
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2010
if ((in_bpp == 8) && (out_bpp == 8))
{
out = (char *)g_malloc(width * height, 0);
src = bmpdata;
dst = out;
freerdp wrapper
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui8 *)src);
pixel = palette[pixel];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR8(red, green, blue);
*dst = pixel;
src++;
dst++;
}
}
*/
return out;
}
#include "xrdp-freerdp.h"
if ((in_bpp == 8) && (out_bpp == 16))
{
out = (char *)g_malloc(width * height * 2, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui8 *)src);
pixel = palette[pixel];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
*((tui16 *)dst) = pixel;
src++;
dst += 2;
}
}
return out;
}
if ((in_bpp == 8) && (out_bpp == 24))
{
out = (char *)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui8 *)src);
pixel = palette[pixel];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32 *)dst) = pixel;
src++;
dst += 4;
}
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 16))
{
out = (char *)g_malloc(width * height * 2, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui16 *)src);
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
*((tui16 *)dst) = pixel;
src += 2;
dst += 2;
}
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 24))
{
out = (char *)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui16 *)src);
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32 *)dst) = pixel;
src += 2;
dst += 4;
}
}
return out;
}
if ((in_bpp == 16) && (out_bpp == 16))
{
return bmpdata;
}
if ((in_bpp == 16) && (out_bpp == 24))
{
out = (char *)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui16 *)src);
SPLITCOLOR16(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32 *)dst) = pixel;
src += 2;
dst += 4;
}
}
return out;
}
if ((in_bpp == 24) && (out_bpp == 24))
{
out = (char *)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
blue = *((tui8 *)src);
src++;
green = *((tui8 *)src);
src++;
red = *((tui8 *)src);
src++;
pixel = COLOR24RGB(red, green, blue);
*((tui32 *)dst) = pixel;
dst += 4;
}
}
return out;
}
if ((in_bpp == 32) && (out_bpp == 24))
{
return bmpdata;
}
if ((in_bpp == 32) && (out_bpp == 32))
{
return bmpdata;
}
if ((in_bpp == 15) && (out_bpp == 15))
{
return bmpdata;
}
char* APP_CC
convert_bitmap(int in_bpp, int out_bpp, char* bmpdata,
int width, int height, int* palette)
g_writeln("convert_bitmap: error unknown conversion from %d to %d",
in_bpp, out_bpp);
return 0;
}
/*****************************************************************************/
/* returns color or 0 */
int APP_CC
convert_color(int in_bpp, int out_bpp, int in_color, int *palette)
{
char* out;
char* src;
char* dst;
int i;
int j;
int red;
int green;
int blue;
int pixel;
if ((in_bpp == 8) && (out_bpp == 8))
{
out = (char*)g_malloc(width * height, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
int pixel;
int red;
int green;
int blue;
if ((in_bpp == 1) && (out_bpp == 24))
{
pixel = in_color == 0 ? 0 : 0xffffff;
return pixel;
}
if ((in_bpp == 8) && (out_bpp == 8))
{
for (j = 0; j < width; j++)
{
pixel = *((tui8*)src);
pixel = palette[pixel];
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR8(red, green, blue);
*dst = pixel;
src++;
dst++;
}
return pixel;
}
return out;
}
if ((in_bpp == 8) && (out_bpp == 16))
{
out = (char*)g_malloc(width * height * 2, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 8) && (out_bpp == 16))
{
for (j = 0; j < width; j++)
{
pixel = *((tui8*)src);
pixel = palette[pixel];
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
*((tui16*)dst) = pixel;
src++;
dst += 2;
}
return pixel;
}
return out;
}
if ((in_bpp == 8) && (out_bpp == 24))
{
out = (char*)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 8) && (out_bpp == 24))
{
for (j = 0; j < width; j++)
{
pixel = *((tui8*)src);
pixel = palette[pixel];
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32*)dst) = pixel;
src++;
dst += 4;
}
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 16))
{
out = (char*)g_malloc(width * height * 2, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 15) && (out_bpp == 16))
{
for (j = 0; j < width; j++)
{
pixel = *((tui16*)src);
pixel = in_color;
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
*((tui16*)dst) = pixel;
src += 2;
dst += 2;
}
return pixel;
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 24))
{
out = (char*)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 15) && (out_bpp == 24))
{
for (j = 0; j < width; j++)
{
pixel = *((tui16*)src);
pixel = in_color;
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32*)dst) = pixel;
src += 2;
dst += 4;
}
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
return out;
}
if ((in_bpp == 16) && (out_bpp == 16))
{
return bmpdata;
}
if ((in_bpp == 16) && (out_bpp == 24))
{
out = (char*)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 16) && (out_bpp == 16))
{
for (j = 0; j < width; j++)
{
pixel = *((tui16*)src);
return in_color;
}
if ((in_bpp == 16) && (out_bpp == 24))
{
pixel = in_color;
SPLITCOLOR16(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32*)dst) = pixel;
src += 2;
dst += 4;
}
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
return out;
}
if ((in_bpp == 24) && (out_bpp == 24))
{
out = (char*)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 24) && (out_bpp == 24))
{
for (j = 0; j < width; j++)
{
blue = *((tui8*)src);
src++;
green = *((tui8*)src);
src++;
red = *((tui8*)src);
src++;
pixel = COLOR24RGB(red, green, blue);
*((tui32*)dst) = pixel;
dst += 4;
}
return in_color;
}
return out;
}
if ((in_bpp == 32) && (out_bpp == 24))
{
return bmpdata;
}
if ((in_bpp == 32) && (out_bpp == 32))
{
return bmpdata;
}
if ((in_bpp == 15) && (out_bpp == 15))
{
return bmpdata;
}
g_writeln("convert_bitmap: error unknown conversion from %d to %d",
in_bpp, out_bpp);
return 0;
}
/*****************************************************************************/
/* returns color or 0 */
int APP_CC
convert_color(int in_bpp, int out_bpp, int in_color, int* palette)
{
int pixel;
int red;
int green;
int blue;
if ((in_bpp == 1) && (out_bpp == 24))
{
pixel = in_color == 0 ? 0 : 0xffffff;
return pixel;
}
if ((in_bpp == 8) && (out_bpp == 8))
{
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR8(red, green, blue);
return pixel;
}
if ((in_bpp == 8) && (out_bpp == 16))
{
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
return pixel;
}
if ((in_bpp == 8) && (out_bpp == 24))
{
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
if ((in_bpp == 15) && (out_bpp == 16))
{
pixel = in_color;
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
return pixel;
}
if ((in_bpp == 15) && (out_bpp == 24))
{
pixel = in_color;
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
if ((in_bpp == 16) && (out_bpp == 16))
{
return in_color;
}
if ((in_bpp == 16) && (out_bpp == 24))
{
pixel = in_color;
SPLITCOLOR16(red, green, blue, pixel);
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
if ((in_bpp == 24) && (out_bpp == 24))
{
return in_color;
}
if ((in_bpp == 32) && (out_bpp == 24))
{
return in_color;
}
if ((in_bpp == 32) && (out_bpp == 32))
{
return in_color;
}
if ((in_bpp == 15) && (out_bpp == 15))
{
return in_color;
}
g_writeln("convert_color: error unknown conversion from %d to %d",
in_bpp, out_bpp);
return 0;
if ((in_bpp == 32) && (out_bpp == 24))
{
return in_color;
}
if ((in_bpp == 32) && (out_bpp == 32))
{
return in_color;
}
if ((in_bpp == 15) && (out_bpp == 15))
{
return in_color;
}
g_writeln("convert_color: error unknown conversion from %d to %d",
in_bpp, out_bpp);
return 0;
}

@ -1,22 +1,20 @@
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2010
*/
/**
* 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.
*/
#ifndef __XRDP_COLOR_H
#define __XRDP_COLOR_H

File diff suppressed because it is too large Load Diff

@ -1,24 +1,22 @@
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2010
freerdp wrapper
*/
/**
* 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.
*
* freerdp wrapper
*/
/* include other h files */
#include "arch.h"

@ -19,258 +19,295 @@
#include "xrdp-freerdp.h"
char* APP_CC
convert_bitmap(int in_bpp, int out_bpp, char* bmpdata,
int width, int height, int* palette)
char *APP_CC
convert_bitmap(int in_bpp, int out_bpp, char *bmpdata,
int width, int height, int *palette)
{
char* out;
char* src;
char* dst;
int i;
int j;
int red;
int green;
int blue;
int pixel;
if ((in_bpp == 8) && (out_bpp == 8))
{
out = (char*)g_malloc(width * height, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
char *out;
char *src;
char *dst;
int i;
int j;
int red;
int green;
int blue;
int pixel;
if ((in_bpp == 8) && (out_bpp == 8))
{
out = (char *)g_malloc(width * height, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui8 *)src);
pixel = palette[pixel];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR8(red, green, blue);
*dst = pixel;
src++;
dst++;
}
}
return out;
}
if ((in_bpp == 8) && (out_bpp == 16))
{
out = (char *)g_malloc(width * height * 2, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui8 *)src);
pixel = palette[pixel];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
*((tui16 *)dst) = pixel;
src++;
dst += 2;
}
}
return out;
}
if ((in_bpp == 8) && (out_bpp == 24))
{
out = (char *)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui8 *)src);
pixel = palette[pixel];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32 *)dst) = pixel;
src++;
dst += 4;
}
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 16))
{
out = (char *)g_malloc(width * height * 2, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui16 *)src);
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
*((tui16 *)dst) = pixel;
src += 2;
dst += 2;
}
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 24))
{
for (j = 0; j < width; j++)
{
pixel = *((tui8*)src);
pixel = palette[pixel];
out = (char *)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui16 *)src);
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32 *)dst) = pixel;
src += 2;
dst += 4;
}
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 15))
{
return bmpdata;
}
if ((in_bpp == 16) && (out_bpp == 16))
{
return bmpdata;
}
if ((in_bpp == 16) && (out_bpp == 24))
{
out = (char *)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
pixel = *((tui16 *)src);
SPLITCOLOR16(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32 *)dst) = pixel;
src += 2;
dst += 4;
}
}
return out;
}
if ((in_bpp == 24) && (out_bpp == 24))
{
out = (char *)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
blue = *((tui8 *)src);
src++;
green = *((tui8 *)src);
src++;
red = *((tui8 *)src);
src++;
pixel = COLOR24RGB(red, green, blue);
*((tui32 *)dst) = pixel;
dst += 4;
}
}
return out;
}
if ((in_bpp == 32) && (out_bpp == 24))
{
return bmpdata;
}
if ((in_bpp == 32) && (out_bpp == 32))
{
return bmpdata;
}
g_writeln("convert_bitmap: error unknown conversion from %d to %d",
in_bpp, out_bpp);
return 0;
}
/*****************************************************************************/
/* returns color or 0 */
int APP_CC
convert_color(int in_bpp, int out_bpp, int in_color, int *palette)
{
int pixel;
int red;
int green;
int blue;
if ((in_bpp == 1) && (out_bpp == 24))
{
pixel = in_color == 0 ? 0 : 0xffffff;
return pixel;
}
if ((in_bpp == 8) && (out_bpp == 8))
{
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR8(red, green, blue);
*dst = pixel;
src++;
dst++;
}
return pixel;
}
return out;
}
if ((in_bpp == 8) && (out_bpp == 16))
{
out = (char*)g_malloc(width * height * 2, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 8) && (out_bpp == 16))
{
for (j = 0; j < width; j++)
{
pixel = *((tui8*)src);
pixel = palette[pixel];
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
*((tui16*)dst) = pixel;
src++;
dst += 2;
}
return pixel;
}
return out;
}
if ((in_bpp == 8) && (out_bpp == 24))
{
out = (char*)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 8) && (out_bpp == 24))
{
for (j = 0; j < width; j++)
{
pixel = *((tui8*)src);
pixel = palette[pixel];
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32*)dst) = pixel;
src++;
dst += 4;
}
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 16))
{
out = (char*)g_malloc(width * height * 2, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 15) && (out_bpp == 16))
{
for (j = 0; j < width; j++)
{
pixel = *((tui16*)src);
pixel = in_color;
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
*((tui16*)dst) = pixel;
src += 2;
dst += 2;
}
return pixel;
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 24))
{
out = (char*)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 15) && (out_bpp == 24))
{
for (j = 0; j < width; j++)
{
pixel = *((tui16*)src);
pixel = in_color;
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32*)dst) = pixel;
src += 2;
dst += 4;
}
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
if ((in_bpp == 15) && (out_bpp == 15))
{
return in_color;
}
if ((in_bpp == 16) && (out_bpp == 16))
{
return in_color;
}
return out;
}
if ((in_bpp == 15) && (out_bpp == 15))
{
return bmpdata;
}
if ((in_bpp == 16) && (out_bpp == 16))
{
return bmpdata;
}
if ((in_bpp == 16) && (out_bpp == 24))
{
out = (char*)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 16) && (out_bpp == 24))
{
for (j = 0; j < width; j++)
{
pixel = *((tui16*)src);
pixel = in_color;
SPLITCOLOR16(red, green, blue, pixel);
pixel = COLOR24RGB(red, green, blue);
*((tui32*)dst) = pixel;
src += 2;
dst += 4;
}
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
return out;
}
if ((in_bpp == 24) && (out_bpp == 24))
{
out = (char*)g_malloc(width * height * 4, 0);
src = bmpdata;
dst = out;
for (i = 0; i < height; i++)
if ((in_bpp == 24) && (out_bpp == 24))
{
for (j = 0; j < width; j++)
{
blue = *((tui8*)src);
src++;
green = *((tui8*)src);
src++;
red = *((tui8*)src);
src++;
pixel = COLOR24RGB(red, green, blue);
*((tui32*)dst) = pixel;
dst += 4;
}
return in_color;
}
return out;
}
if ((in_bpp == 32) && (out_bpp == 24))
{
return bmpdata;
}
if ((in_bpp == 32) && (out_bpp == 32))
{
return bmpdata;
}
g_writeln("convert_bitmap: error unknown conversion from %d to %d",
in_bpp, out_bpp);
return 0;
}
/*****************************************************************************/
/* returns color or 0 */
int APP_CC
convert_color(int in_bpp, int out_bpp, int in_color, int* palette)
{
int pixel;
int red;
int green;
int blue;
if ((in_bpp == 1) && (out_bpp == 24))
{
pixel = in_color == 0 ? 0 : 0xffffff;
return pixel;
}
if ((in_bpp == 8) && (out_bpp == 8))
{
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR8(red, green, blue);
return pixel;
}
if ((in_bpp == 8) && (out_bpp == 16))
{
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
return pixel;
}
if ((in_bpp == 8) && (out_bpp == 24))
{
pixel = palette[in_color];
SPLITCOLOR32(red, green, blue, pixel);
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
if ((in_bpp == 15) && (out_bpp == 16))
{
pixel = in_color;
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR16(red, green, blue);
return pixel;
}
if ((in_bpp == 15) && (out_bpp == 24))
{
pixel = in_color;
SPLITCOLOR15(red, green, blue, pixel);
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
if ((in_bpp == 15) && (out_bpp == 15))
{
return in_color;
}
if ((in_bpp == 16) && (out_bpp == 16))
{
return in_color;
}
if ((in_bpp == 16) && (out_bpp == 24))
{
pixel = in_color;
SPLITCOLOR16(red, green, blue, pixel);
pixel = COLOR24BGR(red, green, blue);
return pixel;
}
if ((in_bpp == 24) && (out_bpp == 24))
{
return in_color;
}
if ((in_bpp == 32) && (out_bpp == 24))
{
return in_color;
}
if ((in_bpp == 32) && (out_bpp == 32))
{
return in_color;
}
g_writeln("convert_color: error unknown conversion from %d to %d",
in_bpp, out_bpp);
return 0;
if ((in_bpp == 32) && (out_bpp == 24))
{
return in_color;
}
if ((in_bpp == 32) && (out_bpp == 32))
{
return in_color;
}
g_writeln("convert_color: error unknown conversion from %d to %d",
in_bpp, out_bpp);
return 0;
}

File diff suppressed because it is too large Load Diff

@ -41,75 +41,87 @@
int main(int argc, char **argv)
{
const char* programname;
char text[256];
char* displayname = NULL;
char* outfname;
char* sections[5] = {"noshift", "shift", "altgr", "capslock", "shiftcapslock"};
int states[5] = {0, 1, 0x80, 2, 3};
int i;
int idx;
int char_count;
int nbytes = 0;
int unicode;
Display* dpy;
KeySym ks;
FILE* outf;
XKeyPressedEvent e;
wchar_t wtext[256];
setlocale(LC_CTYPE, "");
programname = argv[0];
if (argc != 2)
{
fprintf(stderr, "Usage: %s out_filename\n", programname);
fprintf(stderr, "Example: %s /etc/xrdp/km-0409.ini\n", programname);
return 1;
}
outfname = argv[1];
dpy = XOpenDisplay(displayname);
if (!dpy)
{
fprintf(stderr, "%s: unable to open display '%s'\n",
programname, XDisplayName(displayname));
return 1;
}
outf = fopen(outfname, "w");
if (outf == NULL)
{
fprintf(stderr, "%s: unable to create file '%s'\n", programname, outfname);
XCloseDisplay(dpy);
return 1;
}
memset(&e, 0, sizeof(e));
e.type = KeyPress;
e.serial = 16;
e.send_event = True;
e.display = dpy;
e.same_screen = True;
for (idx = 0; idx < 5; idx++) /* Sections and states */
{
fprintf(outf, "[%s]\n", sections[idx]);
e.state = states[idx];
for (i = 8; i <= 137; i++) /* Keycodes */
const char *programname;
char text[256];
char *displayname = NULL;
char *outfname;
char *sections[5] = {"noshift", "shift", "altgr", "capslock", "shiftcapslock"};
int states[5] = {0, 1, 0x80, 2, 3};
int i;
int idx;
int char_count;
int nbytes = 0;
int unicode;
Display *dpy;
KeySym ks;
FILE *outf;
XKeyPressedEvent e;
wchar_t wtext[256];
setlocale(LC_CTYPE, "");
programname = argv[0];
if (argc != 2)
{
fprintf(stderr, "Usage: %s out_filename\n", programname);
fprintf(stderr, "Example: %s /etc/xrdp/km-0409.ini\n", programname);
return 1;
}
outfname = argv[1];
dpy = XOpenDisplay(displayname);
if (!dpy)
{
e.keycode = i;
nbytes = XLookupString(&e, text, 255, &ks, NULL);
text[nbytes] = 0;
char_count = mbstowcs(wtext, text, 255);
unicode = 0;
if (char_count == 1)
{
unicode = wtext[0];
}
fprintf(outf, "Key%d=%d:%d\n", i, (int) ks, unicode);
fprintf(stderr, "%s: unable to open display '%s'\n",
programname, XDisplayName(displayname));
return 1;
}
if (idx != 4)
outf = fopen(outfname, "w");
if (outf == NULL)
{
fprintf(outf, "\n");
fprintf(stderr, "%s: unable to create file '%s'\n", programname, outfname);
XCloseDisplay(dpy);
return 1;
}
}
XCloseDisplay(dpy);
fclose(outf);
return 0;
memset(&e, 0, sizeof(e));
e.type = KeyPress;
e.serial = 16;
e.send_event = True;
e.display = dpy;
e.same_screen = True;
for (idx = 0; idx < 5; idx++) /* Sections and states */
{
fprintf(outf, "[%s]\n", sections[idx]);
e.state = states[idx];
for (i = 8; i <= 137; i++) /* Keycodes */
{
e.keycode = i;
nbytes = XLookupString(&e, text, 255, &ks, NULL);
text[nbytes] = 0;
char_count = mbstowcs(wtext, text, 255);
unicode = 0;
if (char_count == 1)
{
unicode = wtext[0];
}
fprintf(outf, "Key%d=%d:%d\n", i, (int) ks, unicode);
}
if (idx != 4)
{
fprintf(outf, "\n");
}
}
XCloseDisplay(dpy);
fclose(outf);
return 0;
}

@ -1,24 +1,22 @@
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2007-2010
rsa key generator for xrdp
*/
/**
* 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.
*
* rsa key generator for xrdp
*/
/*
references:
@ -37,74 +35,74 @@
static tui8 g_exponent[4] =
{
0x01, 0x00, 0x01, 0x00
0x01, 0x00, 0x01, 0x00
};
static tui8 g_ppk_e[4] =
{
0x5B, 0x7B, 0x88, 0xC0
0x5B, 0x7B, 0x88, 0xC0
};
static tui8 g_ppk_n[72] =
{
0x3D, 0x3A, 0x5E, 0xBD, 0x72, 0x43, 0x3E, 0xC9,
0x4D, 0xBB, 0xC1, 0x1E, 0x4A, 0xBA, 0x5F, 0xCB,
0x3E, 0x88, 0x20, 0x87, 0xEF, 0xF5, 0xC1, 0xE2,
0xD7, 0xB7, 0x6B, 0x9A, 0xF2, 0x52, 0x45, 0x95,
0xCE, 0x63, 0x65, 0x6B, 0x58, 0x3A, 0xFE, 0xEF,
0x7C, 0xE7, 0xBF, 0xFE, 0x3D, 0xF6, 0x5C, 0x7D,
0x6C, 0x5E, 0x06, 0x09, 0x1A, 0xF5, 0x61, 0xBB,
0x20, 0x93, 0x09, 0x5F, 0x05, 0x6D, 0xEA, 0x87,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x3D, 0x3A, 0x5E, 0xBD, 0x72, 0x43, 0x3E, 0xC9,
0x4D, 0xBB, 0xC1, 0x1E, 0x4A, 0xBA, 0x5F, 0xCB,
0x3E, 0x88, 0x20, 0x87, 0xEF, 0xF5, 0xC1, 0xE2,
0xD7, 0xB7, 0x6B, 0x9A, 0xF2, 0x52, 0x45, 0x95,
0xCE, 0x63, 0x65, 0x6B, 0x58, 0x3A, 0xFE, 0xEF,
0x7C, 0xE7, 0xBF, 0xFE, 0x3D, 0xF6, 0x5C, 0x7D,
0x6C, 0x5E, 0x06, 0x09, 0x1A, 0xF5, 0x61, 0xBB,
0x20, 0x93, 0x09, 0x5F, 0x05, 0x6D, 0xEA, 0x87,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static tui8 g_ppk_d[108] =
{
0x87, 0xA7, 0x19, 0x32, 0xDA, 0x11, 0x87, 0x55,
0x58, 0x00, 0x16, 0x16, 0x25, 0x65, 0x68, 0xF8,
0x24, 0x3E, 0xE6, 0xFA, 0xE9, 0x67, 0x49, 0x94,
0xCF, 0x92, 0xCC, 0x33, 0x99, 0xE8, 0x08, 0x60,
0x17, 0x9A, 0x12, 0x9F, 0x24, 0xDD, 0xB1, 0x24,
0x99, 0xC7, 0x3A, 0xB8, 0x0A, 0x7B, 0x0D, 0xDD,
0x35, 0x07, 0x79, 0x17, 0x0B, 0x51, 0x9B, 0xB3,
0xC7, 0x10, 0x01, 0x13, 0xE7, 0x3F, 0xF3, 0x5F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
0x87, 0xA7, 0x19, 0x32, 0xDA, 0x11, 0x87, 0x55,
0x58, 0x00, 0x16, 0x16, 0x25, 0x65, 0x68, 0xF8,
0x24, 0x3E, 0xE6, 0xFA, 0xE9, 0x67, 0x49, 0x94,
0xCF, 0x92, 0xCC, 0x33, 0x99, 0xE8, 0x08, 0x60,
0x17, 0x9A, 0x12, 0x9F, 0x24, 0xDD, 0xB1, 0x24,
0x99, 0xC7, 0x3A, 0xB8, 0x0A, 0x7B, 0x0D, 0xDD,
0x35, 0x07, 0x79, 0x17, 0x0B, 0x51, 0x9B, 0xB3,
0xC7, 0x10, 0x01, 0x13, 0xE7, 0x3F, 0xF3, 0x5F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
static tui8 g_testkey[176] =
{
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5c, 0x00,
0x52, 0x53, 0x41, 0x31, 0x48, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x79, 0x6f, 0xb4, 0xdf,
0xa6, 0x95, 0xb9, 0xa9, 0x61, 0xe3, 0xc4, 0x5e,
0xff, 0x6b, 0xd8, 0x81, 0x8a, 0x12, 0x4a, 0x93,
0x42, 0x97, 0x18, 0x93, 0xac, 0xd1, 0x3a, 0x38,
0x3c, 0x68, 0x50, 0x19, 0x31, 0xb6, 0x84, 0x51,
0x79, 0xfb, 0x1c, 0xe7, 0xe3, 0x99, 0x20, 0xc7,
0x84, 0xdf, 0xd1, 0xaa, 0xb5, 0x15, 0xef, 0x47,
0x7e, 0xfc, 0x88, 0xeb, 0x29, 0xc3, 0x27, 0x5a,
0x35, 0xf8, 0xfd, 0xaa, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x48, 0x00,
0x32, 0x3b, 0xde, 0x6f, 0x18, 0x97, 0x1e, 0xc3,
0x6b, 0x2b, 0x2d, 0xe4, 0xfc, 0x2d, 0xa2, 0x8e,
0x32, 0x3c, 0xf3, 0x1b, 0x24, 0x90, 0x57, 0x4d,
0x8e, 0xe4, 0x69, 0xfc, 0x16, 0x8d, 0x41, 0x92,
0x78, 0xc7, 0x9c, 0xb4, 0x26, 0xff, 0xe8, 0x3e,
0xa1, 0x8a, 0xf5, 0x57, 0xc0, 0x7f, 0x3e, 0x21,
0x17, 0x32, 0x30, 0x6f, 0x79, 0xe1, 0x36, 0xcd,
0xb6, 0x8e, 0xbe, 0x57, 0x57, 0xd2, 0xa9, 0x36
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5c, 0x00,
0x52, 0x53, 0x41, 0x31, 0x48, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x79, 0x6f, 0xb4, 0xdf,
0xa6, 0x95, 0xb9, 0xa9, 0x61, 0xe3, 0xc4, 0x5e,
0xff, 0x6b, 0xd8, 0x81, 0x8a, 0x12, 0x4a, 0x93,
0x42, 0x97, 0x18, 0x93, 0xac, 0xd1, 0x3a, 0x38,
0x3c, 0x68, 0x50, 0x19, 0x31, 0xb6, 0x84, 0x51,
0x79, 0xfb, 0x1c, 0xe7, 0xe3, 0x99, 0x20, 0xc7,
0x84, 0xdf, 0xd1, 0xaa, 0xb5, 0x15, 0xef, 0x47,
0x7e, 0xfc, 0x88, 0xeb, 0x29, 0xc3, 0x27, 0x5a,
0x35, 0xf8, 0xfd, 0xaa, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x48, 0x00,
0x32, 0x3b, 0xde, 0x6f, 0x18, 0x97, 0x1e, 0xc3,
0x6b, 0x2b, 0x2d, 0xe4, 0xfc, 0x2d, 0xa2, 0x8e,
0x32, 0x3c, 0xf3, 0x1b, 0x24, 0x90, 0x57, 0x4d,
0x8e, 0xe4, 0x69, 0xfc, 0x16, 0x8d, 0x41, 0x92,
0x78, 0xc7, 0x9c, 0xb4, 0x26, 0xff, 0xe8, 0x3e,
0xa1, 0x8a, 0xf5, 0x57, 0xc0, 0x7f, 0x3e, 0x21,
0x17, 0x32, 0x30, 0x6f, 0x79, 0xe1, 0x36, 0xcd,
0xb6, 0x8e, 0xbe, 0x57, 0x57, 0xd2, 0xa9, 0x36
};
/* this is the installed signature */
char inst_pub_sig[]="0x6a,0x41,0xb1,0x43,0xcf,0x47,0x6f,0xf1,0xe6,0xcc,0xa1,\
char inst_pub_sig[] = "0x6a,0x41,0xb1,0x43,0xcf,0x47,0x6f,0xf1,0xe6,0xcc,0xa1,\
0x72,0x97,0xd9,0xe1,0x85,0x15,0xb3,0xc2,0x39,0xa0,0xa6,0x26,0x1a,0xb6,\
0x49,0x01,0xfa,0xa6,0xda,0x60,0xd7,0x45,0xf7,0x2c,0xee,0xe4,0x8e,0x64,\
0x2e,0x37,0x49,0xf0,0x4c,0x94,0x6f,0x08,0xf5,0x63,0x4c,0x56,0x29,0x55,\
@ -115,212 +113,230 @@ char inst_pub_sig[]="0x6a,0x41,0xb1,0x43,0xcf,0x47,0x6f,0xf1,0xe6,0xcc,0xa1,\
static int APP_CC
out_params(void)
{
g_writeln("");
g_writeln("xrdp rsa key gen utility examples");
g_writeln(" xrdp-keygen xrdp ['path and file name' | auto]");
g_writeln(" xrdp-keygen test");
g_writeln("");
return 0;
g_writeln("");
g_writeln("xrdp rsa key gen utility examples");
g_writeln(" xrdp-keygen xrdp ['path and file name' | auto]");
g_writeln(" xrdp-keygen test");
g_writeln("");
return 0;
}
/*****************************************************************************/
/* this is the special key signing algorithm */
static int APP_CC
sign_key(char* e_data, int e_len, char* n_data, int n_len,
char* sign_data, int sign_len)
sign_key(char *e_data, int e_len, char *n_data, int n_len,
char *sign_data, int sign_len)
{
char* key;
char* md5_final;
void* md5;
if ((e_len != 4) || (n_len != 64) || (sign_len != 64))
{
return 1;
}
key = (char*)g_malloc(176, 0);
md5_final = (char*)g_malloc(64, 0);
md5 = ssl_md5_info_create();
/* copy the test key */
g_memcpy(key, g_testkey, 176);
/* replace e and n */
g_memcpy(key + 32, e_data, 4);
g_memcpy(key + 36, n_data, 64);
ssl_md5_clear(md5);
/* the first 108 bytes */
ssl_md5_transform(md5, key, 108);
/* set the whole thing with 0xff */
g_memset(md5_final, 0xff, 64);
/* digest 16 bytes */
ssl_md5_complete(md5, md5_final);
/* set non 0xff array items */
md5_final[16] = 0;
md5_final[62] = 1;
md5_final[63] = 0;
/* encrypt */
ssl_mod_exp(sign_data, 64, md5_final, 64, (char*)g_ppk_n, 64,
(char*)g_ppk_d, 64);
/* cleanup */
ssl_md5_info_delete(md5);
g_free(key);
g_free(md5_final);
return 0;
char *key;
char *md5_final;
void *md5;
if ((e_len != 4) || (n_len != 64) || (sign_len != 64))
{
return 1;
}
key = (char *)g_malloc(176, 0);
md5_final = (char *)g_malloc(64, 0);
md5 = ssl_md5_info_create();
/* copy the test key */
g_memcpy(key, g_testkey, 176);
/* replace e and n */
g_memcpy(key + 32, e_data, 4);
g_memcpy(key + 36, n_data, 64);
ssl_md5_clear(md5);
/* the first 108 bytes */
ssl_md5_transform(md5, key, 108);
/* set the whole thing with 0xff */
g_memset(md5_final, 0xff, 64);
/* digest 16 bytes */
ssl_md5_complete(md5, md5_final);
/* set non 0xff array items */
md5_final[16] = 0;
md5_final[62] = 1;
md5_final[63] = 0;
/* encrypt */
ssl_mod_exp(sign_data, 64, md5_final, 64, (char *)g_ppk_n, 64,
(char *)g_ppk_d, 64);
/* cleanup */
ssl_md5_info_delete(md5);
g_free(key);
g_free(md5_final);
return 0;
}
/*****************************************************************************/
static int APP_CC
write_out_line(int fd, char* name, char* data, int len)
write_out_line(int fd, char *name, char *data, int len)
{
int max;
int error;
int index;
int data_item;
int buf_pos;
char* buf;
char* text;
text = (char*)g_malloc(256, 0);
max = len;
max = max * 10;
buf_pos = g_strlen(name);
max = max + buf_pos + 16;
buf = (char*)g_malloc(max, 0);
g_strncpy(buf, name, max - 1);
buf[buf_pos] = '=';
buf_pos++;
for (index = 0; index < len; index++)
{
data_item = (tui8)(data[index]);
g_snprintf(text, 255, "0x%2.2x", data_item);
if (index != 0)
int max;
int error;
int index;
int data_item;
int buf_pos;
char *buf;
char *text;
text = (char *)g_malloc(256, 0);
max = len;
max = max * 10;
buf_pos = g_strlen(name);
max = max + buf_pos + 16;
buf = (char *)g_malloc(max, 0);
g_strncpy(buf, name, max - 1);
buf[buf_pos] = '=';
buf_pos++;
for (index = 0; index < len; index++)
{
buf[buf_pos] = ',';
buf_pos++;
data_item = (tui8)(data[index]);
g_snprintf(text, 255, "0x%2.2x", data_item);
if (index != 0)
{
buf[buf_pos] = ',';
buf_pos++;
}
buf[buf_pos] = text[0];
buf_pos++;
buf[buf_pos] = text[1];
buf_pos++;
buf[buf_pos] = text[2];
buf_pos++;
buf[buf_pos] = text[3];
buf_pos++;
}
buf[buf_pos] = text[0];
buf_pos++;
buf[buf_pos] = text[1];
buf_pos++;
buf[buf_pos] = text[2];
buf_pos++;
buf[buf_pos] = text[3];
buf[buf_pos] = '\n';
buf_pos++;
}
buf[buf_pos] = '\n';
buf_pos++;
buf[buf_pos] = 0;
error = g_file_write(fd, buf, buf_pos) == -1;
g_free(buf);
g_free(text);
return error;
buf[buf_pos] = 0;
error = g_file_write(fd, buf, buf_pos) == -1;
g_free(buf);
g_free(text);
return error;
}
/*****************************************************************************/
static int APP_CC
save_all(char* e_data, int e_len, char* n_data, int n_len,
char* d_data, int d_len, char* sign_data, int sign_len,
const char* path_and_file_name)
save_all(char *e_data, int e_len, char *n_data, int n_len,
char *d_data, int d_len, char *sign_data, int sign_len,
const char *path_and_file_name)
{
int fd;
char filename[256];
if (path_and_file_name == 0)
{
g_strncpy(filename, "rsakeys.ini", 255);
}
else
{
g_strncpy(filename, path_and_file_name, 255);
}
g_writeln("saving to %s", filename);
g_writeln("");
if (g_file_exist(filename))
{
if (g_file_delete(filename) == 0)
int fd;
char filename[256];
if (path_and_file_name == 0)
{
g_writeln("problem deleting %s, maybe no rights", filename);
return 1;
g_strncpy(filename, "rsakeys.ini", 255);
}
}
fd = g_file_open(filename);
if (fd > 0)
{
if (g_file_write(fd, "[keys]\n", 7) == -1)
else
{
g_writeln("problem writing to %s, maybe no rights", filename);
return 1;
g_strncpy(filename, path_and_file_name, 255);
}
write_out_line(fd, "pub_exp", e_data, e_len);
write_out_line(fd, "pub_mod", n_data, n_len);
write_out_line(fd, "pub_sig", sign_data, sign_len);
write_out_line(fd, "pri_exp", d_data, d_len);
}
else
{
g_writeln("problem opening %s, maybe no rights", filename);
return 1;
}
g_file_close(fd);
return 0;
g_writeln("saving to %s", filename);
g_writeln("");
if (g_file_exist(filename))
{
if (g_file_delete(filename) == 0)
{
g_writeln("problem deleting %s, maybe no rights", filename);
return 1;
}
}
fd = g_file_open(filename);
if (fd > 0)
{
if (g_file_write(fd, "[keys]\n", 7) == -1)
{
g_writeln("problem writing to %s, maybe no rights", filename);
return 1;
}
write_out_line(fd, "pub_exp", e_data, e_len);
write_out_line(fd, "pub_mod", n_data, n_len);
write_out_line(fd, "pub_sig", sign_data, sign_len);
write_out_line(fd, "pri_exp", d_data, d_len);
}
else
{
g_writeln("problem opening %s, maybe no rights", filename);
return 1;
}
g_file_close(fd);
return 0;
}
/*****************************************************************************/
static int APP_CC
key_gen(const char* path_and_file_name)
key_gen(const char *path_and_file_name)
{
char* e_data;
char* n_data;
char* d_data;
char* sign_data;
int e_len;
int n_len;
int d_len;
int sign_len;
int error;
e_data = (char*)g_exponent;
n_data = (char*)g_malloc(64, 0);
d_data = (char*)g_malloc(64, 0);
sign_data = (char*)g_malloc(64, 0);
e_len = 4;
n_len = 64;
d_len = 64;
sign_len = 64;
error = 0;
g_writeln("");
g_writeln("Generating %d bit rsa key...", MY_KEY_SIZE);
g_writeln("");
if (error == 0)
{
error = ssl_gen_key_xrdp1(MY_KEY_SIZE, e_data, e_len, n_data, n_len,
d_data, d_len);
if (error != 0)
char *e_data;
char *n_data;
char *d_data;
char *sign_data;
int e_len;
int n_len;
int d_len;
int sign_len;
int error;
e_data = (char *)g_exponent;
n_data = (char *)g_malloc(64, 0);
d_data = (char *)g_malloc(64, 0);
sign_data = (char *)g_malloc(64, 0);
e_len = 4;
n_len = 64;
d_len = 64;
sign_len = 64;
error = 0;
g_writeln("");
g_writeln("Generating %d bit rsa key...", MY_KEY_SIZE);
g_writeln("");
if (error == 0)
{
g_writeln("error %d in key_gen, ssl_gen_key_xrdp1", error);
error = ssl_gen_key_xrdp1(MY_KEY_SIZE, e_data, e_len, n_data, n_len,
d_data, d_len);
if (error != 0)
{
g_writeln("error %d in key_gen, ssl_gen_key_xrdp1", error);
}
}
}
if (error == 0)
{
g_writeln("ssl_gen_key_xrdp1 ok");
g_writeln("");
error = sign_key(e_data, e_len, n_data, n_len, sign_data, sign_len);
if (error != 0)
if (error == 0)
{
g_writeln("error %d in key_gen, sign_key", error);
g_writeln("ssl_gen_key_xrdp1 ok");
g_writeln("");
error = sign_key(e_data, e_len, n_data, n_len, sign_data, sign_len);
if (error != 0)
{
g_writeln("error %d in key_gen, sign_key", error);
}
}
}
if (error == 0)
{
error = save_all(e_data, e_len, n_data, n_len, d_data, d_len,
sign_data, sign_len, path_and_file_name);
if (error != 0)
if (error == 0)
{
g_writeln("error %d in key_gen, save_all", error);
error = save_all(e_data, e_len, n_data, n_len, d_data, d_len,
sign_data, sign_len, path_and_file_name);
if (error != 0)
{
g_writeln("error %d in key_gen, save_all", error);
}
}
}
g_free(n_data);
g_free(d_data);
g_free(sign_data);
return error;
g_free(n_data);
g_free(d_data);
g_free(sign_data);
return error;
}
/*****************************************************************************/
@ -328,146 +344,156 @@ key_gen(const char* path_and_file_name)
static int APP_CC
key_gen_run_it(void)
{
int fd;
int index;
int rv;
struct list* names;
struct list* values;
char* name;
char* value;
if (!g_file_exist("/etc/xrdp/rsakeys.ini"))
{
return 1;
}
if (g_file_get_size("/etc/xrdp/rsakeys.ini") < 10)
{
return 1;
}
fd = g_file_open("/etc/xrdp/rsakeys.ini");
if (fd < 0)
{
return 1;
}
rv = 0;
names = list_create();
names->auto_free = 1;
values = list_create();
values->auto_free = 1;
if (file_read_section(fd, "keys", names, values) == 0)
{
for (index = 0; index < names->count; index++)
int fd;
int index;
int rv;
struct list *names;
struct list *values;
char *name;
char *value;
if (!g_file_exist("/etc/xrdp/rsakeys.ini"))
{
return 1;
}
if (g_file_get_size("/etc/xrdp/rsakeys.ini") < 10)
{
return 1;
}
fd = g_file_open("/etc/xrdp/rsakeys.ini");
if (fd < 0)
{
return 1;
}
rv = 0;
names = list_create();
names->auto_free = 1;
values = list_create();
values->auto_free = 1;
if (file_read_section(fd, "keys", names, values) == 0)
{
name = (char*)list_get_item(names, index);
value = (char*)list_get_item(values, index);
if (</