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
This commit is contained in:
@@ -1,372 +1,176 @@
|
|||||||
|
Apache License, Version 2.0
|
||||||
|
|
||||||
special clause for libxrdp and librdp, both based on rdesktop
|
Version 2.0, January 2004
|
||||||
these libraries link to openssl
|
|
||||||
|
|
||||||
This software is released under the GNU General Public License
|
http://www.apache.org/licenses/
|
||||||
(reproduced below) with the additional exemption that compiling,
|
|
||||||
linking, and/or using OpenSSL together with this software is
|
|
||||||
allowed.
|
|
||||||
|
|
||||||
---
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
special clause for xrdp, that main executable
|
1. Definitions.
|
||||||
for linking with proprietary modules
|
|
||||||
|
|
||||||
Linking this library statically or dynamically with other modules
|
"License" shall mean the terms and conditions for use, reproduction, and
|
||||||
is making a combined work based on this library. Thus, the terms
|
distribution as defined by Sections 1 through 9 of this document.
|
||||||
and conditions of the GNU General Public License cover the whole
|
|
||||||
combination.
|
|
||||||
|
|
||||||
As a special exception, the copyright holders of this library
|
"Licensor" shall mean the copyright owner or entity authorized by the
|
||||||
give you permission to link this library with independent modules
|
copyright owner that is granting the License.
|
||||||
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.
|
|
||||||
|
|
||||||
---
|
"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.
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||||
Version 2, June 1991
|
permissions granted by this License.
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
675 Mass Ave, Cambridge, MA 02139, USA
|
including but not limited to software source code, documentation source,
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
and configuration files.
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
"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.
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
"Work" shall mean the work of authorship, whether in Source or Object form,
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
made available under the License, as indicated by a copyright notice that is
|
||||||
License is intended to guarantee your freedom to share and change free
|
included in or attached to the work (an example is provided in the Appendix below).
|
||||||
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
|
"Derivative Works" shall mean any work, whether in Source or Object form,
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
that is based on (or derived from) the Work and for which the editorial
|
||||||
have the freedom to distribute copies of free software (and charge for
|
revisions, annotations, elaborations, or other modifications represent, as a
|
||||||
this service if you wish), that you receive source code or can get it
|
whole, an original work of authorship. For the purposes of this License,
|
||||||
if you want it, that you can change the software or use pieces of it
|
Derivative Works shall not include works that remain separable from, or
|
||||||
in new free programs; and that you know you can do these things.
|
merely link (or bind by name) to the interfaces of, the Work and
|
||||||
|
Derivative Works thereof.
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
"Contribution" shall mean any work of authorship, including the original
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
version of the Work and any modifications or additions to that Work or Derivative
|
||||||
These restrictions translate to certain responsibilities for you if you
|
Works thereof, that is intentionally submitted to Licensor for inclusion in the
|
||||||
distribute copies of the software, or if you modify it.
|
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."
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||||
gratis or for a fee, you must give the recipients all the rights that
|
of whom a Contribution has been received by Licensor and subsequently incorporated
|
||||||
you have. You must make sure that they, too, receive or can get the
|
within the Work.
|
||||||
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. Grant of Copyright License. Subject to the terms and conditions of this License,
|
||||||
(2) offer you this license which gives you legal permission to copy,
|
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
||||||
distribute and/or modify the software.
|
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.
|
||||||
|
|
||||||
Also, for each author's protection and ours, we want to make certain
|
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
||||||
that everyone understands that there is no warranty for this free
|
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
||||||
software. If the software is modified by someone else and passed on, we
|
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
||||||
want its recipients to know that what they have is not the original, so
|
license to make, have made, use, offer to sell, sell, import, and otherwise transfer
|
||||||
that any problems introduced by others will not reflect on the original
|
the Work, where such license applies only to those patent claims licensable by such
|
||||||
authors' reputations.
|
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.
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative
|
||||||
patents. We wish to avoid the danger that redistributors of a free
|
Works thereof in any medium, with or without modifications, and in Source or Object
|
||||||
program will individually obtain patent licenses, in effect making the
|
form, provided that You meet the following conditions:
|
||||||
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
|
You must give any other recipients of the Work or Derivative Works a copy of this
|
||||||
modification follow.
|
License; and
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
You must cause any modified files to carry prominent notices stating that You changed
|
||||||
a notice placed by the copyright holder saying it may be distributed
|
the files; and
|
||||||
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
|
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||||
covered by this License; they are outside its scope. The act of
|
all copyright, patent, trademark, and attribution notices from the Source form of the Work,
|
||||||
running the Program is not restricted, and the output from the Program
|
excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||||
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
|
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||||
source code as you receive it, in any medium, provided that you
|
Derivative Works that You distribute must include a readable copy of the attribution
|
||||||
conspicuously and appropriately publish on each copy an appropriate
|
notices contained within such NOTICE file, excluding those notices that do not pertain
|
||||||
copyright notice and disclaimer of warranty; keep intact all the
|
to any part of the Derivative Works, in at least one of the following places: within a
|
||||||
notices that refer to this License and to the absence of any warranty;
|
NOTICE text file distributed as part of the Derivative Works; within the Source form or
|
||||||
and give any other recipients of the Program a copy of this License
|
documentation, if provided along with the Derivative Works; or, within a display
|
||||||
along with the Program.
|
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.
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy, and
|
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution
|
||||||
you may at your option offer warranty protection in exchange for a fee.
|
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.
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Program or any portion
|
6. Trademarks. This License does not grant permission to use the trade names, trademarks,
|
||||||
of it, thus forming a work based on the Program, and copy and
|
service marks, or product names of the Licensor, except as required for reasonable and
|
||||||
distribute such modifications or work under the terms of Section 1
|
customary use in describing the origin of the Work and reproducing the content of
|
||||||
above, provided that you also meet all of these conditions:
|
the NOTICE file.
|
||||||
|
|
||||||
a) You must cause the modified files to carry prominent notices
|
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing,
|
||||||
stating that you changed the files and the date of any change.
|
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.
|
||||||
|
|
||||||
b) You must cause any work that you distribute or publish, that in
|
8. Limitation of Liability. In no event and under no legal theory, whether in tort
|
||||||
whole or in part contains or is derived from the Program or any
|
(including negligence), contract, or otherwise, unless required by applicable law
|
||||||
part thereof, to be licensed as a whole at no charge to all third
|
(such as deliberate and grossly negligent acts) or agreed to in writing, shall any
|
||||||
parties under the terms of this License.
|
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.
|
||||||
|
|
||||||
c) If the modified program normally reads commands interactively
|
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
||||||
when run, you must cause it, when started running for such
|
Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance
|
||||||
interactive use in the most ordinary way, to print or display an
|
of support, warranty, indemnity, or other liability obligations and/or rights consistent
|
||||||
announcement including an appropriate copyright notice and a
|
with this License. However, in accepting such obligations, You may act only on Your
|
||||||
notice that there is no warranty (or else, saying that you provide
|
own behalf and on Your sole responsibility, not on behalf of any other Contributor,
|
||||||
a warranty) and that users may redistribute the program under
|
and only if You agree to indemnify, defend, and hold each Contributor harmless for any
|
||||||
these conditions, and telling the user how to view a copy of this
|
liability incurred by, or claims asserted against, such Contributor by reason of your
|
||||||
License. (Exception: if the Program itself is interactive but
|
accepting any such warranty or additional liability.
|
||||||
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
|
END OF TERMS AND CONDITIONS
|
||||||
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
|
APPENDIX: How to apply the Apache License to your work
|
||||||
with the Program (or with a work based on the Program) on a volume of
|
To apply the Apache License to your work, attach the following boilerplate notice,
|
||||||
a storage or distribution medium does not bring the other work under
|
with the fields enclosed by brackets "[]" replaced with your own identifying
|
||||||
the scope of this License.
|
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.
|
||||||
|
|
||||||
3. You may copy and distribute the Program (or a work based on it,
|
Copyright [yyyy] [name of copyright owner]
|
||||||
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
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
source code, which must be distributed under the terms of Sections
|
you may not use this file except in compliance with the License.
|
||||||
1 and 2 above on a medium customarily used for software interchange; or,
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
b) Accompany it with a written offer, valid for at least three
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
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
|
Unless required by applicable law or agreed to in writing, software
|
||||||
to distribute corresponding source code. (This alternative is
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
allowed only for noncommercial distribution and only if you
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
received the program in object code or executable form with such
|
See the License for the specific language governing permissions and
|
||||||
an offer, in accord with Subsection b above.)
|
limitations under the License.
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
+17
-22
@@ -1,25 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2004-2010 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
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.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(ARCH_H)
|
#if !defined(ARCH_H)
|
||||||
#define ARCH_H
|
#define ARCH_H
|
||||||
|
|||||||
+405
-327
@@ -38,393 +38,471 @@ static unsigned long KnL[32] = { 0L };
|
|||||||
static unsigned long KnR[32] = { 0L };
|
static unsigned long KnR[32] = { 0L };
|
||||||
static unsigned long Kn3[32] = { 0L };
|
static unsigned long Kn3[32] = { 0L };
|
||||||
static unsigned char Df_Key[24] = {
|
static unsigned char Df_Key[24] = {
|
||||||
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
|
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
|
||||||
0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
|
0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
|
||||||
0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67 };
|
0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67 };
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static unsigned short bytebit[8] = {
|
static unsigned short bytebit[8] =
|
||||||
01, 02, 04, 010, 020, 040, 0100, 0200 };
|
{
|
||||||
|
01, 02, 04, 010, 020, 040, 0100, 0200
|
||||||
|
};
|
||||||
|
|
||||||
static unsigned long bigbyte[24] = {
|
static unsigned long bigbyte[24] =
|
||||||
0x800000L, 0x400000L, 0x200000L, 0x100000L,
|
{
|
||||||
0x80000L, 0x40000L, 0x20000L, 0x10000L,
|
0x800000L, 0x400000L, 0x200000L, 0x100000L,
|
||||||
0x8000L, 0x4000L, 0x2000L, 0x1000L,
|
0x80000L, 0x40000L, 0x20000L, 0x10000L,
|
||||||
0x800L, 0x400L, 0x200L, 0x100L,
|
0x8000L, 0x4000L, 0x2000L, 0x1000L,
|
||||||
0x80L, 0x40L, 0x20L, 0x10L,
|
0x800L, 0x400L, 0x200L, 0x100L,
|
||||||
0x8L, 0x4L, 0x2L, 0x1L };
|
0x80L, 0x40L, 0x20L, 0x10L,
|
||||||
|
0x8L, 0x4L, 0x2L, 0x1L
|
||||||
|
};
|
||||||
|
|
||||||
/* Use the key schedule specified in the Standard (ANSI X3.92-1981). */
|
/* Use the key schedule specified in the Standard (ANSI X3.92-1981). */
|
||||||
|
|
||||||
static unsigned char pc1[56] = {
|
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,
|
56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
|
||||||
62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21,
|
9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
|
||||||
13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 };
|
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] = {
|
static unsigned char totrot[16] =
|
||||||
1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 };
|
{
|
||||||
|
1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28
|
||||||
|
};
|
||||||
|
|
||||||
static unsigned char pc2[48] = {
|
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,
|
13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9,
|
||||||
40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
|
22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,
|
||||||
43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };
|
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! */
|
/* Thanks to James Gillogly & Phil Karn! */
|
||||||
void rfbDesKey(unsigned char *key, int edf)
|
void rfbDesKey(unsigned char *key, int edf)
|
||||||
{
|
{
|
||||||
register int i, j, l, m, n;
|
register int i, j, l, m, n;
|
||||||
unsigned char pc1m[56], pcr[56];
|
unsigned char pc1m[56], pcr[56];
|
||||||
unsigned long kn[32];
|
unsigned long kn[32];
|
||||||
|
|
||||||
for ( j = 0; j < 56; j++ ) {
|
for ( j = 0; j < 56; j++ )
|
||||||
l = pc1[j];
|
{
|
||||||
m = l & 07;
|
l = pc1[j];
|
||||||
pc1m[j] = (key[l >> 3] & bytebit[m]) ? 1 : 0;
|
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;
|
for ( i = 0; i < 16; i++ )
|
||||||
n = m + 1;
|
{
|
||||||
kn[m] = kn[n] = 0L;
|
if ( edf == DE1 )
|
||||||
for( j = 0; j < 28; j++ ) {
|
{
|
||||||
l = j + totrot[i];
|
m = (15 - i) << 1;
|
||||||
if( l < 28 ) pcr[j] = pc1m[l];
|
}
|
||||||
else pcr[j] = pc1m[l - 28];
|
else
|
||||||
}
|
{
|
||||||
for( j = 28; j < 56; j++ ) {
|
m = i << 1;
|
||||||
l = j + totrot[i];
|
}
|
||||||
if( l < 56 ) pcr[j] = pc1m[l];
|
|
||||||
else pcr[j] = pc1m[l - 28];
|
n = m + 1;
|
||||||
}
|
kn[m] = kn[n] = 0L;
|
||||||
for( j = 0; j < 24; j++ ) {
|
|
||||||
if( pcr[pc2[j]] ) kn[m] |= bigbyte[j];
|
for ( j = 0; j < 28; j++ )
|
||||||
if( pcr[pc2[j+24]] ) kn[n] |= bigbyte[j];
|
{
|
||||||
}
|
l = j + totrot[i];
|
||||||
}
|
|
||||||
cookey(kn);
|
if ( l < 28 )
|
||||||
return;
|
{
|
||||||
}
|
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)
|
static void cookey(register unsigned long *raw1)
|
||||||
{
|
{
|
||||||
register unsigned long *cook, *raw0;
|
register unsigned long *cook, *raw0;
|
||||||
unsigned long dough[32];
|
unsigned long dough[32];
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
cook = dough;
|
cook = dough;
|
||||||
for( i = 0; i < 16; i++, raw1++ ) {
|
|
||||||
raw0 = raw1++;
|
for ( i = 0; i < 16; i++, raw1++ )
|
||||||
*cook = (*raw0 & 0x00fc0000L) << 6;
|
{
|
||||||
*cook |= (*raw0 & 0x00000fc0L) << 10;
|
raw0 = raw1++;
|
||||||
*cook |= (*raw1 & 0x00fc0000L) >> 10;
|
*cook = (*raw0 & 0x00fc0000L) << 6;
|
||||||
*cook++ |= (*raw1 & 0x00000fc0L) >> 6;
|
*cook |= (*raw0 & 0x00000fc0L) << 10;
|
||||||
*cook = (*raw0 & 0x0003f000L) << 12;
|
*cook |= (*raw1 & 0x00fc0000L) >> 10;
|
||||||
*cook |= (*raw0 & 0x0000003fL) << 16;
|
*cook++ |= (*raw1 & 0x00000fc0L) >> 6;
|
||||||
*cook |= (*raw1 & 0x0003f000L) >> 4;
|
*cook = (*raw0 & 0x0003f000L) << 12;
|
||||||
*cook++ |= (*raw1 & 0x0000003fL);
|
*cook |= (*raw0 & 0x0000003fL) << 16;
|
||||||
}
|
*cook |= (*raw1 & 0x0003f000L) >> 4;
|
||||||
rfbUseKey(dough);
|
*cook++ |= (*raw1 & 0x0000003fL);
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
rfbUseKey(dough);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void rfbCPKey(register unsigned long *into)
|
void rfbCPKey(register unsigned long *into)
|
||||||
{
|
{
|
||||||
register unsigned long *from, *endp;
|
register unsigned long *from, *endp;
|
||||||
|
|
||||||
from = KnL, endp = &KnL[32];
|
from = KnL, endp = &KnL[32];
|
||||||
while( from < endp ) *into++ = *from++;
|
|
||||||
return;
|
while ( from < endp )
|
||||||
}
|
{
|
||||||
|
*into++ = *from++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void rfbUseKey(register unsigned long *from)
|
void rfbUseKey(register unsigned long *from)
|
||||||
{
|
{
|
||||||
register unsigned long *to, *endp;
|
register unsigned long *to, *endp;
|
||||||
|
|
||||||
to = KnL, endp = &KnL[32];
|
to = KnL, endp = &KnL[32];
|
||||||
while( to < endp ) *to++ = *from++;
|
|
||||||
return;
|
while ( to < endp )
|
||||||
}
|
{
|
||||||
|
*to++ = *from++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void rfbDes(unsigned char *inblock, unsigned char *outblock)
|
void rfbDes(unsigned char *inblock, unsigned char *outblock)
|
||||||
{
|
{
|
||||||
unsigned long work[2];
|
unsigned long work[2];
|
||||||
|
|
||||||
scrunch(inblock, work);
|
scrunch(inblock, work);
|
||||||
desfunc(work, KnL);
|
desfunc(work, KnL);
|
||||||
unscrun(work, outblock);
|
unscrun(work, outblock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scrunch(register unsigned char *outof, register unsigned long *into)
|
static void scrunch(register unsigned char *outof, register unsigned long *into)
|
||||||
{
|
{
|
||||||
*into = (*outof++ & 0xffL) << 24;
|
*into = (*outof++ & 0xffL) << 24;
|
||||||
*into |= (*outof++ & 0xffL) << 16;
|
*into |= (*outof++ & 0xffL) << 16;
|
||||||
*into |= (*outof++ & 0xffL) << 8;
|
*into |= (*outof++ & 0xffL) << 8;
|
||||||
*into++ |= (*outof++ & 0xffL);
|
*into++ |= (*outof++ & 0xffL);
|
||||||
*into = (*outof++ & 0xffL) << 24;
|
*into = (*outof++ & 0xffL) << 24;
|
||||||
*into |= (*outof++ & 0xffL) << 16;
|
*into |= (*outof++ & 0xffL) << 16;
|
||||||
*into |= (*outof++ & 0xffL) << 8;
|
*into |= (*outof++ & 0xffL) << 8;
|
||||||
*into |= (*outof & 0xffL);
|
*into |= (*outof & 0xffL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unscrun(register unsigned long *outof, register unsigned char *into)
|
static void unscrun(register unsigned long *outof, register unsigned char *into)
|
||||||
{
|
{
|
||||||
*into++ = (unsigned char)((*outof >> 24) & 0xffL);
|
*into++ = (unsigned char)((*outof >> 24) & 0xffL);
|
||||||
*into++ = (unsigned char)((*outof >> 16) & 0xffL);
|
*into++ = (unsigned char)((*outof >> 16) & 0xffL);
|
||||||
*into++ = (unsigned char)((*outof >> 8) & 0xffL);
|
*into++ = (unsigned char)((*outof >> 8) & 0xffL);
|
||||||
*into++ = (unsigned char)( *outof++ & 0xffL);
|
*into++ = (unsigned char)( *outof++ & 0xffL);
|
||||||
*into++ = (unsigned char)((*outof >> 24) & 0xffL);
|
*into++ = (unsigned char)((*outof >> 24) & 0xffL);
|
||||||
*into++ = (unsigned char)((*outof >> 16) & 0xffL);
|
*into++ = (unsigned char)((*outof >> 16) & 0xffL);
|
||||||
*into++ = (unsigned char)((*outof >> 8) & 0xffL);
|
*into++ = (unsigned char)((*outof >> 8) & 0xffL);
|
||||||
*into = (unsigned char)( *outof & 0xffL);
|
*into = (unsigned char)( *outof & 0xffL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long SP1[64] = {
|
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;
|
0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L,
|
||||||
register int round;
|
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
|
||||||
|
};
|
||||||
|
|
||||||
leftt = block[0];
|
static unsigned long SP2[64] =
|
||||||
right = block[1];
|
{
|
||||||
work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
|
0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L,
|
||||||
right ^= work;
|
0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L,
|
||||||
leftt ^= (work << 4);
|
0x80000020L, 0x80108020L, 0x80108000L, 0x80000000L,
|
||||||
work = ((leftt >> 16) ^ right) & 0x0000ffffL;
|
0x80008000L, 0x00100000L, 0x00000020L, 0x80100020L,
|
||||||
right ^= work;
|
0x00108000L, 0x00100020L, 0x80008020L, 0x00000000L,
|
||||||
leftt ^= (work << 16);
|
0x80000000L, 0x00008000L, 0x00108020L, 0x80100000L,
|
||||||
work = ((right >> 2) ^ leftt) & 0x33333333L;
|
0x00100020L, 0x80000020L, 0x00000000L, 0x00108000L,
|
||||||
leftt ^= work;
|
0x00008020L, 0x80108000L, 0x80100000L, 0x00008020L,
|
||||||
right ^= (work << 2);
|
0x00000000L, 0x00108020L, 0x80100020L, 0x00100000L,
|
||||||
work = ((right >> 8) ^ leftt) & 0x00ff00ffL;
|
0x80008020L, 0x80100000L, 0x80108000L, 0x00008000L,
|
||||||
leftt ^= work;
|
0x80100000L, 0x80008000L, 0x00000020L, 0x80108020L,
|
||||||
right ^= (work << 8);
|
0x00108020L, 0x00000020L, 0x00008000L, 0x80000000L,
|
||||||
right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL;
|
0x00008020L, 0x80108000L, 0x00100000L, 0x80000020L,
|
||||||
work = (leftt ^ right) & 0xaaaaaaaaL;
|
0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L,
|
||||||
leftt ^= work;
|
0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L,
|
||||||
right ^= work;
|
0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L
|
||||||
leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;
|
};
|
||||||
|
|
||||||
for( round = 0; round < 8; round++ ) {
|
static unsigned long SP3[64] =
|
||||||
work = (right << 28) | (right >> 4);
|
{
|
||||||
work ^= *keys++;
|
0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L,
|
||||||
fval = SP7[ work & 0x3fL];
|
0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L,
|
||||||
fval |= SP5[(work >> 8) & 0x3fL];
|
0x00020008L, 0x08000008L, 0x08000008L, 0x00020000L,
|
||||||
fval |= SP3[(work >> 16) & 0x3fL];
|
0x08020208L, 0x00020008L, 0x08020000L, 0x00000208L,
|
||||||
fval |= SP1[(work >> 24) & 0x3fL];
|
0x08000000L, 0x00000008L, 0x08020200L, 0x00000200L,
|
||||||
work = right ^ *keys++;
|
0x00020200L, 0x08020000L, 0x08020008L, 0x00020208L,
|
||||||
fval |= SP8[ work & 0x3fL];
|
0x08000208L, 0x00020200L, 0x00020000L, 0x08000208L,
|
||||||
fval |= SP6[(work >> 8) & 0x3fL];
|
0x00000008L, 0x08020208L, 0x00000200L, 0x08000000L,
|
||||||
fval |= SP4[(work >> 16) & 0x3fL];
|
0x08020200L, 0x08000000L, 0x00020008L, 0x00000208L,
|
||||||
fval |= SP2[(work >> 24) & 0x3fL];
|
0x00020000L, 0x08020200L, 0x08000200L, 0x00000000L,
|
||||||
leftt ^= fval;
|
0x00000200L, 0x00020008L, 0x08020208L, 0x08000200L,
|
||||||
work = (leftt << 28) | (leftt >> 4);
|
0x08000008L, 0x00000200L, 0x00000000L, 0x08020008L,
|
||||||
work ^= *keys++;
|
0x08000208L, 0x00020000L, 0x08000000L, 0x08020208L,
|
||||||
fval = SP7[ work & 0x3fL];
|
0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L,
|
||||||
fval |= SP5[(work >> 8) & 0x3fL];
|
0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L,
|
||||||
fval |= SP3[(work >> 16) & 0x3fL];
|
0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L
|
||||||
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);
|
static unsigned long SP4[64] =
|
||||||
work = (leftt ^ right) & 0xaaaaaaaaL;
|
{
|
||||||
leftt ^= work;
|
0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
|
||||||
right ^= work;
|
0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L,
|
||||||
leftt = (leftt << 31) | (leftt >> 1);
|
0x00000000L, 0x00802000L, 0x00802000L, 0x00802081L,
|
||||||
work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
|
0x00000081L, 0x00000000L, 0x00800080L, 0x00800001L,
|
||||||
right ^= work;
|
0x00000001L, 0x00002000L, 0x00800000L, 0x00802001L,
|
||||||
leftt ^= (work << 8);
|
0x00000080L, 0x00800000L, 0x00002001L, 0x00002080L,
|
||||||
work = ((leftt >> 2) ^ right) & 0x33333333L;
|
0x00800081L, 0x00000001L, 0x00002080L, 0x00800080L,
|
||||||
right ^= work;
|
0x00002000L, 0x00802080L, 0x00802081L, 0x00000081L,
|
||||||
leftt ^= (work << 2);
|
0x00800080L, 0x00800001L, 0x00802000L, 0x00802081L,
|
||||||
work = ((right >> 16) ^ leftt) & 0x0000ffffL;
|
0x00000081L, 0x00000000L, 0x00000000L, 0x00802000L,
|
||||||
leftt ^= work;
|
0x00002080L, 0x00800080L, 0x00800081L, 0x00000001L,
|
||||||
right ^= (work << 16);
|
0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,
|
||||||
work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;
|
0x00802081L, 0x00000081L, 0x00000001L, 0x00002000L,
|
||||||
leftt ^= work;
|
0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L,
|
||||||
right ^= (work << 4);
|
0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L,
|
||||||
*block++ = right;
|
0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L
|
||||||
*block = leftt;
|
};
|
||||||
return;
|
|
||||||
}
|
static unsigned long SP5[64] =
|
||||||
|
{
|
||||||
|
0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L,
|
||||||
|
0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L,
|
||||||
|
0x40080100L, 0x00080000L, 0x02000100L, 0x40080100L,
|
||||||
|
0x42000100L, 0x42080000L, 0x00080100L, 0x40000000L,
|
||||||
|
0x02000000L, 0x40080000L, 0x40080000L, 0x00000000L,
|
||||||
|
0x40000100L, 0x42080100L, 0x42080100L, 0x02000100L,
|
||||||
|
0x42080000L, 0x40000100L, 0x00000000L, 0x42000000L,
|
||||||
|
0x02080100L, 0x02000000L, 0x42000000L, 0x00080100L,
|
||||||
|
0x00080000L, 0x42000100L, 0x00000100L, 0x02000000L,
|
||||||
|
0x40000000L, 0x02080000L, 0x42000100L, 0x40080100L,
|
||||||
|
0x02000100L, 0x40000000L, 0x42080000L, 0x02080100L,
|
||||||
|
0x40080100L, 0x00000100L, 0x02000000L, 0x42080000L,
|
||||||
|
0x42080100L, 0x00080100L, 0x42000000L, 0x42080100L,
|
||||||
|
0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L,
|
||||||
|
0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L,
|
||||||
|
0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L
|
||||||
|
};
|
||||||
|
|
||||||
|
static unsigned long SP6[64] =
|
||||||
|
{
|
||||||
|
0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L,
|
||||||
|
0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L,
|
||||||
|
0x20004000L, 0x00404010L, 0x00400000L, 0x20000010L,
|
||||||
|
0x00400010L, 0x20004000L, 0x20000000L, 0x00004010L,
|
||||||
|
0x00000000L, 0x00400010L, 0x20004010L, 0x00004000L,
|
||||||
|
0x00404000L, 0x20004010L, 0x00000010L, 0x20400010L,
|
||||||
|
0x20400010L, 0x00000000L, 0x00404010L, 0x20404000L,
|
||||||
|
0x00004010L, 0x00404000L, 0x20404000L, 0x20000000L,
|
||||||
|
0x20004000L, 0x00000010L, 0x20400010L, 0x00404000L,
|
||||||
|
0x20404010L, 0x00400000L, 0x00004010L, 0x20000010L,
|
||||||
|
0x00400000L, 0x20004000L, 0x20000000L, 0x00004010L,
|
||||||
|
0x20000010L, 0x20404010L, 0x00404000L, 0x20400000L,
|
||||||
|
0x00404010L, 0x20404000L, 0x00000000L, 0x20400010L,
|
||||||
|
0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L,
|
||||||
|
0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L,
|
||||||
|
0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L
|
||||||
|
};
|
||||||
|
|
||||||
|
static unsigned long SP7[64] =
|
||||||
|
{
|
||||||
|
0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,
|
||||||
|
0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,
|
||||||
|
0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L,
|
||||||
|
0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L,
|
||||||
|
0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L,
|
||||||
|
0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L,
|
||||||
|
0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L,
|
||||||
|
0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L,
|
||||||
|
0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L,
|
||||||
|
0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L,
|
||||||
|
0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L,
|
||||||
|
0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L,
|
||||||
|
0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L,
|
||||||
|
0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,
|
||||||
|
0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,
|
||||||
|
0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L
|
||||||
|
};
|
||||||
|
|
||||||
|
static unsigned long SP8[64] =
|
||||||
|
{
|
||||||
|
0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,
|
||||||
|
0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,
|
||||||
|
0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L,
|
||||||
|
0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L,
|
||||||
|
0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L,
|
||||||
|
0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L,
|
||||||
|
0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L,
|
||||||
|
0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L,
|
||||||
|
0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L,
|
||||||
|
0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L,
|
||||||
|
0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L,
|
||||||
|
0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L,
|
||||||
|
0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L,
|
||||||
|
0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L,
|
||||||
|
0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L,
|
||||||
|
0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L
|
||||||
|
};
|
||||||
|
|
||||||
|
static void desfunc(register unsigned long *block, register unsigned long *keys)
|
||||||
|
{
|
||||||
|
register unsigned long fval, work, right, leftt;
|
||||||
|
register int round;
|
||||||
|
|
||||||
|
leftt = block[0];
|
||||||
|
right = block[1];
|
||||||
|
work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;
|
||||||
|
right ^= work;
|
||||||
|
leftt ^= (work << 4);
|
||||||
|
work = ((leftt >> 16) ^ right) & 0x0000ffffL;
|
||||||
|
right ^= work;
|
||||||
|
leftt ^= (work << 16);
|
||||||
|
work = ((right >> 2) ^ leftt) & 0x33333333L;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= (work << 2);
|
||||||
|
work = ((right >> 8) ^ leftt) & 0x00ff00ffL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= (work << 8);
|
||||||
|
right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL;
|
||||||
|
work = (leftt ^ right) & 0xaaaaaaaaL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= work;
|
||||||
|
leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;
|
||||||
|
|
||||||
|
for ( round = 0; round < 8; round++ )
|
||||||
|
{
|
||||||
|
work = (right << 28) | (right >> 4);
|
||||||
|
work ^= *keys++;
|
||||||
|
fval = SP7[ work & 0x3fL];
|
||||||
|
fval |= SP5[(work >> 8) & 0x3fL];
|
||||||
|
fval |= SP3[(work >> 16) & 0x3fL];
|
||||||
|
fval |= SP1[(work >> 24) & 0x3fL];
|
||||||
|
work = right ^ *keys++;
|
||||||
|
fval |= SP8[ work & 0x3fL];
|
||||||
|
fval |= SP6[(work >> 8) & 0x3fL];
|
||||||
|
fval |= SP4[(work >> 16) & 0x3fL];
|
||||||
|
fval |= SP2[(work >> 24) & 0x3fL];
|
||||||
|
leftt ^= fval;
|
||||||
|
work = (leftt << 28) | (leftt >> 4);
|
||||||
|
work ^= *keys++;
|
||||||
|
fval = SP7[ work & 0x3fL];
|
||||||
|
fval |= SP5[(work >> 8) & 0x3fL];
|
||||||
|
fval |= SP3[(work >> 16) & 0x3fL];
|
||||||
|
fval |= SP1[(work >> 24) & 0x3fL];
|
||||||
|
work = leftt ^ *keys++;
|
||||||
|
fval |= SP8[ work & 0x3fL];
|
||||||
|
fval |= SP6[(work >> 8) & 0x3fL];
|
||||||
|
fval |= SP4[(work >> 16) & 0x3fL];
|
||||||
|
fval |= SP2[(work >> 24) & 0x3fL];
|
||||||
|
right ^= fval;
|
||||||
|
}
|
||||||
|
|
||||||
|
right = (right << 31) | (right >> 1);
|
||||||
|
work = (leftt ^ right) & 0xaaaaaaaaL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= work;
|
||||||
|
leftt = (leftt << 31) | (leftt >> 1);
|
||||||
|
work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
|
||||||
|
right ^= work;
|
||||||
|
leftt ^= (work << 8);
|
||||||
|
work = ((leftt >> 2) ^ right) & 0x33333333L;
|
||||||
|
right ^= work;
|
||||||
|
leftt ^= (work << 2);
|
||||||
|
work = ((right >> 16) ^ leftt) & 0x0000ffffL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= (work << 16);
|
||||||
|
work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;
|
||||||
|
leftt ^= work;
|
||||||
|
right ^= (work << 4);
|
||||||
|
*block++ = right;
|
||||||
|
*block = leftt;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Validation sets:
|
/* Validation sets:
|
||||||
*
|
*
|
||||||
* Single-length key, single-length plaintext -
|
* Single-length key, single-length plaintext -
|
||||||
* Key : 0123 4567 89ab cdef
|
* Key : 0123 4567 89ab cdef
|
||||||
* Plain : 0123 4567 89ab cde7
|
* Plain : 0123 4567 89ab cde7
|
||||||
* Cipher : c957 4425 6a5e d31d
|
* Cipher : c957 4425 6a5e d31d
|
||||||
*
|
*
|
||||||
* Double-length key, single-length plaintext -
|
* 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
|
* Plain : 0123 4567 89ab cde7
|
||||||
* Cipher : 7f1d 0a77 826b 8aff
|
* Cipher : 7f1d 0a77 826b 8aff
|
||||||
*
|
*
|
||||||
* Double-length key, double-length plaintext -
|
* 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
|
* Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
|
||||||
* Cipher : 27a0 8440 406a df60 278f 47cf 42d6 15d7
|
* Cipher : 27a0 8440 406a df60 278f 47cf 42d6 15d7
|
||||||
*
|
*
|
||||||
* Triple-length key, single-length plaintext -
|
* 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
|
* Plain : 0123 4567 89ab cde7
|
||||||
* Cipher : de0b 7c06 ae5e 0ed5
|
* Cipher : de0b 7c06 ae5e 0ed5
|
||||||
*
|
*
|
||||||
* Triple-length key, double-length plaintext -
|
* 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
|
* Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff
|
||||||
* Cipher : ad0d 1b30 ac17 cf07 0ed1 1c63 81e4 4de5
|
* Cipher : ad0d 1b30 ac17 cf07 0ed1 1c63 81e4 4de5
|
||||||
*
|
*
|
||||||
|
|||||||
+19
-21
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2004-2009
|
*
|
||||||
|
* main define/macro file
|
||||||
main define/macro file
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DEFINES_H
|
#ifndef DEFINES_H
|
||||||
#define DEFINES_H
|
#define DEFINES_H
|
||||||
|
|||||||
+297
-267
@@ -1,26 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2004-2012 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* read a config file
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
read a config file
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "os_calls.h"
|
#include "os_calls.h"
|
||||||
@@ -33,250 +29,276 @@
|
|||||||
returns 0 if everything is ok
|
returns 0 if everything is ok
|
||||||
returns 1 if problem reading file */
|
returns 1 if problem reading file */
|
||||||
static int APP_CC
|
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;
|
struct stream *s;
|
||||||
char text[256];
|
char text[256];
|
||||||
char c;
|
char c;
|
||||||
int in_it;
|
int in_it;
|
||||||
int in_it_index;
|
int in_it_index;
|
||||||
int len;
|
int len;
|
||||||
int index;
|
int index;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
rv = 0;
|
rv = 0;
|
||||||
g_file_seek(fd, 0);
|
g_file_seek(fd, 0);
|
||||||
in_it_index = 0;
|
in_it_index = 0;
|
||||||
in_it = 0;
|
in_it = 0;
|
||||||
g_memset(text, 0, 256);
|
g_memset(text, 0, 256);
|
||||||
list_clear(names);
|
list_clear(names);
|
||||||
make_stream(s);
|
make_stream(s);
|
||||||
init_stream(s, max_file_size);
|
init_stream(s, max_file_size);
|
||||||
len = g_file_read(fd, s->data, max_file_size);
|
len = g_file_read(fd, s->data, max_file_size);
|
||||||
if (len > 0)
|
|
||||||
{
|
if (len > 0)
|
||||||
s->end = s->p + len;
|
|
||||||
for (index = 0; index < len; index++)
|
|
||||||
{
|
{
|
||||||
in_uint8(s, c);
|
s->end = s->p + len;
|
||||||
if (c == '[')
|
|
||||||
{
|
for (index = 0; index < len; index++)
|
||||||
in_it = 1;
|
{
|
||||||
}
|
in_uint8(s, c);
|
||||||
else if (c == ']')
|
|
||||||
{
|
if (c == '[')
|
||||||
list_add_item(names, (tbus)g_strdup(text));
|
{
|
||||||
in_it = 0;
|
in_it = 1;
|
||||||
in_it_index = 0;
|
}
|
||||||
g_memset(text, 0, 256);
|
else if (c == ']')
|
||||||
}
|
{
|
||||||
else if (in_it)
|
list_add_item(names, (tbus)g_strdup(text));
|
||||||
{
|
in_it = 0;
|
||||||
text[in_it_index] = c;
|
in_it_index = 0;
|
||||||
in_it_index++;
|
g_memset(text, 0, 256);
|
||||||
}
|
}
|
||||||
|
else if (in_it)
|
||||||
|
{
|
||||||
|
text[in_it_index] = c;
|
||||||
|
in_it_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (len < 0)
|
||||||
else if (len < 0)
|
{
|
||||||
{
|
rv = 1;
|
||||||
rv = 1;
|
}
|
||||||
}
|
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
file_read_line(struct stream* s, char* text)
|
file_read_line(struct stream *s, char *text)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int skip_to_end;
|
int skip_to_end;
|
||||||
int at_end;
|
int at_end;
|
||||||
char c;
|
char c;
|
||||||
char* hold;
|
char *hold;
|
||||||
|
|
||||||
skip_to_end = 0;
|
skip_to_end = 0;
|
||||||
if (!s_check_rem(s, 1))
|
|
||||||
{
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!skip_to_end)
|
|
||||||
|
hold = s->p;
|
||||||
|
i = 0;
|
||||||
|
in_uint8(s, c);
|
||||||
|
|
||||||
|
while (c != 10 && c != 13)
|
||||||
{
|
{
|
||||||
text[i] = c;
|
if (c == '#' || c == '!' || c == ';')
|
||||||
i++;
|
{
|
||||||
|
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 (s_check_rem(s, 1))
|
|
||||||
|
if (c == 10 || c == 13)
|
||||||
{
|
{
|
||||||
in_uint8(s, c);
|
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--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
text[i] = 0;
|
||||||
|
|
||||||
|
if (text[0] == '[')
|
||||||
{
|
{
|
||||||
c = 0;
|
s->p = hold;
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (c == 10 || c == 13)
|
return 0;
|
||||||
{
|
|
||||||
at_end = 0;
|
|
||||||
while (c == 10 || c == 13)
|
|
||||||
{
|
|
||||||
if (s_check_rem(s, 1))
|
|
||||||
{
|
|
||||||
in_uint8(s, c);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
at_end = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!at_end)
|
|
||||||
{
|
|
||||||
s->p--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
text[i] = 0;
|
|
||||||
if (text[0] == '[')
|
|
||||||
{
|
|
||||||
s->p = hold;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
static int APP_CC
|
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 len;
|
||||||
int i;
|
int i;
|
||||||
int value_index;
|
int value_index;
|
||||||
int name_index;
|
int name_index;
|
||||||
int on_to;
|
int on_to;
|
||||||
|
|
||||||
value_index = 0;
|
value_index = 0;
|
||||||
name_index = 0;
|
name_index = 0;
|
||||||
on_to = 0;
|
on_to = 0;
|
||||||
name[0] = 0;
|
name[0] = 0;
|
||||||
value[0] = 0;
|
value[0] = 0;
|
||||||
len = g_strlen(text);
|
len = g_strlen(text);
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
{
|
for (i = 0; i < len; i++)
|
||||||
if (text[i] == '=')
|
|
||||||
{
|
{
|
||||||
on_to = 1;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (on_to)
|
|
||||||
{
|
g_strtrim(name, 3); /* trim both right and left */
|
||||||
value[value_index] = text[i];
|
g_strtrim(value, 3); /* trim both right and left */
|
||||||
value_index++;
|
return 0;
|
||||||
value[value_index] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
name[name_index] = text[i];
|
|
||||||
name_index++;
|
|
||||||
name[name_index] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_strtrim(name, 3); /* trim both right and left */
|
|
||||||
g_strtrim(value, 3); /* trim both right and left */
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
l_file_read_section(int fd, int max_file_size, const char* section,
|
l_file_read_section(int fd, int max_file_size, const char *section,
|
||||||
struct list* names, struct list* values)
|
struct list *names, struct list *values)
|
||||||
{
|
{
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
char text[512];
|
char text[512];
|
||||||
char name[512];
|
char name[512];
|
||||||
char value[512];
|
char value[512];
|
||||||
char* lvalue;
|
char *lvalue;
|
||||||
char c;
|
char c;
|
||||||
int in_it;
|
int in_it;
|
||||||
int in_it_index;
|
int in_it_index;
|
||||||
int len;
|
int len;
|
||||||
int index;
|
int index;
|
||||||
int file_size;
|
int file_size;
|
||||||
|
|
||||||
file_size = 32 * 1024; /* 32 K file size limit */
|
file_size = 32 * 1024; /* 32 K file size limit */
|
||||||
g_file_seek(fd, 0);
|
g_file_seek(fd, 0);
|
||||||
in_it_index = 0;
|
in_it_index = 0;
|
||||||
in_it = 0;
|
in_it = 0;
|
||||||
g_memset(text, 0, 512);
|
g_memset(text, 0, 512);
|
||||||
list_clear(names);
|
list_clear(names);
|
||||||
list_clear(values);
|
list_clear(values);
|
||||||
make_stream(s);
|
make_stream(s);
|
||||||
init_stream(s, file_size);
|
init_stream(s, file_size);
|
||||||
len = g_file_read(fd, s->data, file_size);
|
len = g_file_read(fd, s->data, file_size);
|
||||||
if (len > 0)
|
|
||||||
{
|
if (len > 0)
|
||||||
s->end = s->p + len;
|
|
||||||
for (index = 0; index < len; index++)
|
|
||||||
{
|
{
|
||||||
in_uint8(s, c);
|
s->end = s->p + len;
|
||||||
if (c == '[')
|
|
||||||
{
|
for (index = 0; index < len; index++)
|
||||||
in_it = 1;
|
|
||||||
}
|
|
||||||
else if (c == ']')
|
|
||||||
{
|
|
||||||
if (g_strcasecmp(section, text) == 0)
|
|
||||||
{
|
{
|
||||||
file_read_line(s, text);
|
in_uint8(s, c);
|
||||||
while (file_read_line(s, text) == 0)
|
|
||||||
{
|
if (c == '[')
|
||||||
if (g_strlen(text) > 0)
|
|
||||||
{
|
{
|
||||||
file_split_name_value(text, name, value);
|
in_it = 1;
|
||||||
list_add_item(names, (tbus)g_strdup(name));
|
}
|
||||||
if (value[0] == '$')
|
else if (c == ']')
|
||||||
{
|
{
|
||||||
lvalue = g_getenv(value + 1);
|
if (g_strcasecmp(section, text) == 0)
|
||||||
if (lvalue != 0)
|
{
|
||||||
{
|
file_read_line(s, text);
|
||||||
list_add_item(values, (tbus)g_strdup(lvalue));
|
|
||||||
}
|
while (file_read_line(s, text) == 0)
|
||||||
else
|
{
|
||||||
{
|
if (g_strlen(text) > 0)
|
||||||
list_add_item(values, (tbus)g_strdup(""));
|
{
|
||||||
}
|
file_split_name_value(text, name, value);
|
||||||
}
|
list_add_item(names, (tbus)g_strdup(name));
|
||||||
else
|
|
||||||
{
|
if (value[0] == '$')
|
||||||
list_add_item(values, (tbus)g_strdup(value));
|
{
|
||||||
}
|
lvalue = g_getenv(value + 1);
|
||||||
|
|
||||||
|
if (lvalue != 0)
|
||||||
|
{
|
||||||
|
list_add_item(values, (tbus)g_strdup(lvalue));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list_add_item(values, (tbus)g_strdup(""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list_add_item(values, (tbus)g_strdup(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free_stream(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_it = 0;
|
||||||
|
in_it_index = 0;
|
||||||
|
g_memset(text, 0, 512);
|
||||||
|
}
|
||||||
|
else if (in_it)
|
||||||
|
{
|
||||||
|
text[in_it_index] = c;
|
||||||
|
in_it_index++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
free_stream(s);
|
|
||||||
return 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);
|
free_stream(s);
|
||||||
return 1;
|
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 */
|
returns 1 if problem reading file */
|
||||||
/* 32 K file size limit */
|
/* 32 K file size limit */
|
||||||
int APP_CC
|
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
|
/* this function should be prefered over file_read_sections because it can
|
||||||
read any file size */
|
read any file size */
|
||||||
int APP_CC
|
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 fd;
|
||||||
int file_size;
|
int file_size;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
file_size = g_file_get_size(file_name);
|
file_size = g_file_get_size(file_name);
|
||||||
if (file_size < 1)
|
|
||||||
{
|
if (file_size < 1)
|
||||||
return 1;
|
{
|
||||||
}
|
return 1;
|
||||||
fd = g_file_open(file_name);
|
}
|
||||||
if (fd < 1)
|
|
||||||
{
|
fd = g_file_open(file_name);
|
||||||
return 1;
|
|
||||||
}
|
if (fd < 1)
|
||||||
rv = l_file_read_sections(fd, file_size, names);
|
{
|
||||||
g_file_close(fd);
|
return 1;
|
||||||
return rv;
|
}
|
||||||
|
|
||||||
|
rv = l_file_read_sections(fd, file_size, names);
|
||||||
|
g_file_close(fd);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
/* 32 K file size limit */
|
/* 32 K file size limit */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
file_read_section(int fd, const char* section,
|
file_read_section(int fd, const char *section,
|
||||||
struct list* names, struct list* values)
|
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
|
/* this function should be prefered over file_read_section because it can
|
||||||
read any file size */
|
read any file size */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
file_by_name_read_section(const char* file_name, const char* section,
|
file_by_name_read_section(const char *file_name, const char *section,
|
||||||
struct list* names, struct list* values)
|
struct list *names, struct list *values)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int file_size;
|
int file_size;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
file_size = g_file_get_size(file_name);
|
file_size = g_file_get_size(file_name);
|
||||||
if (file_size < 1)
|
|
||||||
{
|
if (file_size < 1)
|
||||||
return 1;
|
{
|
||||||
}
|
return 1;
|
||||||
fd = g_file_open(file_name);
|
}
|
||||||
if (fd < 1)
|
|
||||||
{
|
fd = g_file_open(file_name);
|
||||||
return 1;
|
|
||||||
}
|
if (fd < 1)
|
||||||
rv = l_file_read_section(fd, file_size, section, names, values);
|
{
|
||||||
g_file_close(fd);
|
return 1;
|
||||||
return rv;
|
}
|
||||||
|
|
||||||
|
rv = l_file_read_section(fd, file_size, section, names, values);
|
||||||
|
g_file_close(fd);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-23
@@ -1,26 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2004-2010 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* read a config file
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
read a config file
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(FILE_H)
|
#if !defined(FILE_H)
|
||||||
#define FILE_H
|
#define FILE_H
|
||||||
|
|||||||
+19
-21
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2004-2010
|
*
|
||||||
|
* default file locations for log, config, etc
|
||||||
default file locations for log, config, etc
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(FILE_LOC_H)
|
#if !defined(FILE_LOC_H)
|
||||||
#define FILE_LOC_H
|
#define FILE_LOC_H
|
||||||
|
|||||||
+149
-140
@@ -1,217 +1,226 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2004-2010 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* simple list
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
simple list
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "os_calls.h"
|
#include "os_calls.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct list* APP_CC
|
struct list *APP_CC
|
||||||
list_create(void)
|
list_create(void)
|
||||||
{
|
{
|
||||||
struct list* self;
|
struct list *self;
|
||||||
|
|
||||||
self = (struct list*)g_malloc(sizeof(struct list), 1);
|
self = (struct list *)g_malloc(sizeof(struct list), 1);
|
||||||
self->grow_by = 10;
|
self->grow_by = 10;
|
||||||
self->alloc_size = 10;
|
self->alloc_size = 10;
|
||||||
self->items = (tbus*)g_malloc(sizeof(tbus) * 10, 1);
|
self->items = (tbus *)g_malloc(sizeof(tbus) * 10, 1);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
list_delete(struct list* self)
|
list_delete(struct list *self)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (self == 0)
|
if (self == 0)
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (self->auto_free)
|
|
||||||
{
|
|
||||||
for (i = 0; i < self->count; i++)
|
|
||||||
{
|
{
|
||||||
g_free((void*)self->items[i]);
|
return;
|
||||||
self->items[i] = 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
g_free(self->items);
|
if (self->auto_free)
|
||||||
g_free(self);
|
{
|
||||||
|
for (i = 0; i < self->count; i++)
|
||||||
|
{
|
||||||
|
g_free((void *)self->items[i]);
|
||||||
|
self->items[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free(self->items);
|
||||||
|
g_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
list_add_item(struct list* self, tbus item)
|
list_add_item(struct list *self, tbus item)
|
||||||
{
|
{
|
||||||
tbus* p;
|
tbus *p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (self->count >= self->alloc_size)
|
if (self->count >= self->alloc_size)
|
||||||
{
|
{
|
||||||
i = self->alloc_size;
|
i = self->alloc_size;
|
||||||
self->alloc_size += self->grow_by;
|
self->alloc_size += self->grow_by;
|
||||||
p = (tbus*)g_malloc(sizeof(tbus) * self->alloc_size, 1);
|
p = (tbus *)g_malloc(sizeof(tbus) * self->alloc_size, 1);
|
||||||
g_memcpy(p, self->items, sizeof(tbus) * i);
|
g_memcpy(p, self->items, sizeof(tbus) * i);
|
||||||
g_free(self->items);
|
g_free(self->items);
|
||||||
self->items = p;
|
self->items = p;
|
||||||
}
|
}
|
||||||
self->items[self->count] = item;
|
|
||||||
self->count++;
|
self->items[self->count] = item;
|
||||||
|
self->count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
tbus APP_CC
|
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)
|
if (index < 0 || index >= self->count)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return self->items[index];
|
|
||||||
|
return self->items[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
list_clear(struct list* self)
|
list_clear(struct list *self)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (self->auto_free)
|
if (self->auto_free)
|
||||||
{
|
|
||||||
for (i = 0; i < self->count; i++)
|
|
||||||
{
|
{
|
||||||
g_free((void*)self->items[i]);
|
for (i = 0; i < self->count; i++)
|
||||||
self->items[i] = 0;
|
{
|
||||||
|
g_free((void *)self->items[i]);
|
||||||
|
self->items[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
g_free(self->items);
|
g_free(self->items);
|
||||||
self->count = 0;
|
self->count = 0;
|
||||||
self->grow_by = 10;
|
self->grow_by = 10;
|
||||||
self->alloc_size = 10;
|
self->alloc_size = 10;
|
||||||
self->items = (tbus*)g_malloc(sizeof(tbus) * 10, 1);
|
self->items = (tbus *)g_malloc(sizeof(tbus) * 10, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
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++)
|
for (i = 0; i < self->count; i++)
|
||||||
{
|
|
||||||
if (self->items[i] == item)
|
|
||||||
{
|
{
|
||||||
return i;
|
if (self->items[i] == item)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
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 (index >= 0 && index < self->count)
|
||||||
{
|
|
||||||
if (self->auto_free)
|
|
||||||
{
|
{
|
||||||
g_free((void*)self->items[index]);
|
if (self->auto_free)
|
||||||
self->items[index] = 0;
|
{
|
||||||
|
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
|
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;
|
tbus *p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (index == self->count)
|
if (index == self->count)
|
||||||
{
|
|
||||||
list_add_item(self, item);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (index >= 0 && index < self->count)
|
|
||||||
{
|
|
||||||
self->count++;
|
|
||||||
if (self->count > self->alloc_size)
|
|
||||||
{
|
{
|
||||||
i = self->alloc_size;
|
list_add_item(self, item);
|
||||||
self->alloc_size += self->grow_by;
|
return;
|
||||||
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--)
|
|
||||||
|
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 */
|
/* append one list to another using strdup for each item in the list */
|
||||||
/* begins copy at start_index, a zero based index on the soure list */
|
/* begins copy at start_index, a zero based index on the soure list */
|
||||||
void APP_CC
|
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;
|
int index;
|
||||||
tbus item;
|
tbus item;
|
||||||
char* dup;
|
char *dup;
|
||||||
|
|
||||||
for (index = start_index; index < self->count; index++)
|
for (index = start_index; index < self->count; index++)
|
||||||
{
|
{
|
||||||
item = list_get_item(self, index);
|
item = list_get_item(self, index);
|
||||||
dup = g_strdup((char*)item);
|
dup = g_strdup((char *)item);
|
||||||
list_add_item(dest, (tbus)dup);
|
list_add_item(dest, (tbus)dup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
list_dump_items(struct list* self)
|
list_dump_items(struct list *self)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
if (self->count == 0)
|
if (self->count == 0)
|
||||||
{
|
{
|
||||||
g_writeln("List is empty");
|
g_writeln("List is empty");
|
||||||
}
|
}
|
||||||
for (index = 0; index < self->count; index++)
|
|
||||||
{
|
for (index = 0; index < self->count; index++)
|
||||||
g_writeln("%d: %s", index, list_get_item(self, index));
|
{
|
||||||
}
|
g_writeln("%d: %s", index, list_get_item(self, index));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-23
@@ -1,26 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2004-2010 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* simple list
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
simple list
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(LIST_H)
|
#if !defined(LIST_H)
|
||||||
#define LIST_H
|
#define LIST_H
|
||||||
|
|||||||
+474
-435
File diff suppressed because it is too large
Load Diff
+17
-22
@@ -1,25 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2005-2012 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
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.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LOG_H
|
#ifndef LOG_H
|
||||||
#define LOG_H
|
#define LOG_H
|
||||||
|
|||||||
+1563
-1369
File diff suppressed because it is too large
Load Diff
+19
-23
@@ -1,26 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2004-2012 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* generic operating system calls
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
generic operating system calls
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(OS_CALLS_H)
|
#if !defined(OS_CALLS_H)
|
||||||
#define OS_CALLS_H
|
#define OS_CALLS_H
|
||||||
|
|||||||
+23
-27
@@ -1,30 +1,26 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2004-2010 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* Parsing structs and macros
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*
|
||||||
DEALINGS IN THE SOFTWARE.
|
* based on parse.h from rdesktop
|
||||||
|
* this is a super fast stream method, you bet
|
||||||
Parsing structs and macros
|
* needed functions g_malloc, g_free, g_memset, g_memcpy
|
||||||
|
*/
|
||||||
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)
|
#if !defined(PARSE_H)
|
||||||
#define PARSE_H
|
#define PARSE_H
|
||||||
|
|||||||
+239
-224
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2004-2010
|
*
|
||||||
|
* ssl calls
|
||||||
ssl calls
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h> /* needed for openssl headers */
|
#include <stdlib.h> /* needed for openssl headers */
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
@@ -43,197 +41,200 @@
|
|||||||
int
|
int
|
||||||
ssl_init(void)
|
ssl_init(void)
|
||||||
{
|
{
|
||||||
SSL_load_error_strings();
|
SSL_load_error_strings();
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int
|
int
|
||||||
ssl_finish(void)
|
ssl_finish(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* rc4 stuff */
|
/* rc4 stuff */
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void* APP_CC
|
void *APP_CC
|
||||||
ssl_rc4_info_create(void)
|
ssl_rc4_info_create(void)
|
||||||
{
|
{
|
||||||
return g_malloc(sizeof(RC4_KEY), 1);
|
return g_malloc(sizeof(RC4_KEY), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
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
|
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
|
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 */
|
/* sha1 stuff */
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void* APP_CC
|
void *APP_CC
|
||||||
ssl_sha1_info_create(void)
|
ssl_sha1_info_create(void)
|
||||||
{
|
{
|
||||||
return g_malloc(sizeof(SHA_CTX), 1);
|
return g_malloc(sizeof(SHA_CTX), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
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
|
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
|
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
|
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 */
|
/* md5 stuff */
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void* APP_CC
|
void *APP_CC
|
||||||
ssl_md5_info_create(void)
|
ssl_md5_info_create(void)
|
||||||
{
|
{
|
||||||
return g_malloc(sizeof(MD5_CTX), 1);
|
return g_malloc(sizeof(MD5_CTX), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
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
|
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
|
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
|
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
|
static void APP_CC
|
||||||
ssl_reverse_it(char* p, int len)
|
ssl_reverse_it(char *p, int len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
char temp;
|
char temp;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = len - 1;
|
j = len - 1;
|
||||||
while (i < j)
|
|
||||||
{
|
while (i < j)
|
||||||
temp = p[i];
|
{
|
||||||
p[i] = p[j];
|
temp = p[i];
|
||||||
p[j] = temp;
|
p[i] = p[j];
|
||||||
i++;
|
p[j] = temp;
|
||||||
j--;
|
i++;
|
||||||
}
|
j--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
ssl_mod_exp(char* out, int out_len, char* in, int in_len,
|
ssl_mod_exp(char *out, int out_len, char *in, int in_len,
|
||||||
char* mod, int mod_len, char* exp, int exp_len)
|
char *mod, int mod_len, char *exp, int exp_len)
|
||||||
{
|
{
|
||||||
BN_CTX* ctx;
|
BN_CTX *ctx;
|
||||||
BIGNUM lmod;
|
BIGNUM lmod;
|
||||||
BIGNUM lexp;
|
BIGNUM lexp;
|
||||||
BIGNUM lin;
|
BIGNUM lin;
|
||||||
BIGNUM lout;
|
BIGNUM lout;
|
||||||
int rv;
|
int rv;
|
||||||
char* l_out;
|
char *l_out;
|
||||||
char* l_in;
|
char *l_in;
|
||||||
char* l_mod;
|
char *l_mod;
|
||||||
char* l_exp;
|
char *l_exp;
|
||||||
|
|
||||||
l_out = (char*)g_malloc(out_len, 1);
|
l_out = (char *)g_malloc(out_len, 1);
|
||||||
l_in = (char*)g_malloc(in_len, 1);
|
l_in = (char *)g_malloc(in_len, 1);
|
||||||
l_mod = (char*)g_malloc(mod_len, 1);
|
l_mod = (char *)g_malloc(mod_len, 1);
|
||||||
l_exp = (char*)g_malloc(exp_len, 1);
|
l_exp = (char *)g_malloc(exp_len, 1);
|
||||||
g_memcpy(l_in, in, in_len);
|
g_memcpy(l_in, in, in_len);
|
||||||
g_memcpy(l_mod, mod, mod_len);
|
g_memcpy(l_mod, mod, mod_len);
|
||||||
g_memcpy(l_exp, exp, exp_len);
|
g_memcpy(l_exp, exp, exp_len);
|
||||||
ssl_reverse_it(l_in, in_len);
|
ssl_reverse_it(l_in, in_len);
|
||||||
ssl_reverse_it(l_mod, mod_len);
|
ssl_reverse_it(l_mod, mod_len);
|
||||||
ssl_reverse_it(l_exp, exp_len);
|
ssl_reverse_it(l_exp, exp_len);
|
||||||
ctx = BN_CTX_new();
|
ctx = BN_CTX_new();
|
||||||
BN_init(&lmod);
|
BN_init(&lmod);
|
||||||
BN_init(&lexp);
|
BN_init(&lexp);
|
||||||
BN_init(&lin);
|
BN_init(&lin);
|
||||||
BN_init(&lout);
|
BN_init(&lout);
|
||||||
BN_bin2bn((tui8*)l_mod, mod_len, &lmod);
|
BN_bin2bn((tui8 *)l_mod, mod_len, &lmod);
|
||||||
BN_bin2bn((tui8*)l_exp, exp_len, &lexp);
|
BN_bin2bn((tui8 *)l_exp, exp_len, &lexp);
|
||||||
BN_bin2bn((tui8*)l_in, in_len, &lin);
|
BN_bin2bn((tui8 *)l_in, in_len, &lin);
|
||||||
BN_mod_exp(&lout, &lin, &lexp, &lmod, ctx);
|
BN_mod_exp(&lout, &lin, &lexp, &lmod, ctx);
|
||||||
rv = BN_bn2bin(&lout, (tui8*)l_out);
|
rv = BN_bn2bin(&lout, (tui8 *)l_out);
|
||||||
if (rv <= out_len)
|
|
||||||
{
|
if (rv <= out_len)
|
||||||
ssl_reverse_it(l_out, rv);
|
{
|
||||||
g_memcpy(out, l_out, out_len);
|
ssl_reverse_it(l_out, rv);
|
||||||
}
|
g_memcpy(out, l_out, out_len);
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
rv = 0;
|
{
|
||||||
}
|
rv = 0;
|
||||||
BN_free(&lin);
|
}
|
||||||
BN_free(&lout);
|
|
||||||
BN_free(&lexp);
|
BN_free(&lin);
|
||||||
BN_free(&lmod);
|
BN_free(&lout);
|
||||||
BN_CTX_free(ctx);
|
BN_free(&lexp);
|
||||||
g_free(l_out);
|
BN_free(&lmod);
|
||||||
g_free(l_in);
|
BN_CTX_free(ctx);
|
||||||
g_free(l_mod);
|
g_free(l_out);
|
||||||
g_free(l_exp);
|
g_free(l_in);
|
||||||
return rv;
|
g_free(l_mod);
|
||||||
|
g_free(l_exp);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(OLD_RSA_GEN1)
|
#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
|
generates a new rsa key
|
||||||
exp is passed in and mod and pri are passed out */
|
exp is passed in and mod and pri are passed out */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_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)
|
char *mod, int mod_len, char *pri, int pri_len)
|
||||||
{
|
{
|
||||||
int my_e;
|
int my_e;
|
||||||
RSA* my_key;
|
RSA *my_key;
|
||||||
char* lmod;
|
char *lmod;
|
||||||
char* lpri;
|
char *lpri;
|
||||||
tui8* lexp;
|
tui8 *lexp;
|
||||||
int error;
|
int error;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
|
if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
lmod = (char*)g_malloc(mod_len, 0);
|
|
||||||
lpri = (char*)g_malloc(pri_len, 0);
|
lmod = (char *)g_malloc(mod_len, 0);
|
||||||
lexp = (tui8*)exp;
|
lpri = (char *)g_malloc(pri_len, 0);
|
||||||
my_e = lexp[0];
|
lexp = (tui8 *)exp;
|
||||||
my_e |= lexp[1] << 8;
|
my_e = lexp[0];
|
||||||
my_e |= lexp[2] << 16;
|
my_e |= lexp[1] << 8;
|
||||||
my_e |= lexp[3] << 24;
|
my_e |= lexp[2] << 16;
|
||||||
/* srand is in stdlib.h */
|
my_e |= lexp[3] << 24;
|
||||||
srand(g_time1());
|
/* srand is in stdlib.h */
|
||||||
my_key = RSA_generate_key(key_size_in_bits, my_e, 0, 0);
|
srand(g_time1());
|
||||||
error = my_key == 0;
|
my_key = RSA_generate_key(key_size_in_bits, my_e, 0, 0);
|
||||||
if (error == 0)
|
error = my_key == 0;
|
||||||
{
|
|
||||||
len = BN_num_bytes(my_key->n);
|
if (error == 0)
|
||||||
error = len != mod_len;
|
{
|
||||||
}
|
len = BN_num_bytes(my_key->n);
|
||||||
if (error == 0)
|
error = len != mod_len;
|
||||||
{
|
}
|
||||||
BN_bn2bin(my_key->n, (tui8*)lmod);
|
|
||||||
ssl_reverse_it(lmod, mod_len);
|
if (error == 0)
|
||||||
}
|
{
|
||||||
if (error == 0)
|
BN_bn2bin(my_key->n, (tui8 *)lmod);
|
||||||
{
|
ssl_reverse_it(lmod, mod_len);
|
||||||
len = BN_num_bytes(my_key->d);
|
}
|
||||||
error = len != pri_len;
|
|
||||||
}
|
if (error == 0)
|
||||||
if (error == 0)
|
{
|
||||||
{
|
len = BN_num_bytes(my_key->d);
|
||||||
BN_bn2bin(my_key->d, (tui8*)lpri);
|
error = len != pri_len;
|
||||||
ssl_reverse_it(lpri, pri_len);
|
}
|
||||||
}
|
|
||||||
if (error == 0)
|
if (error == 0)
|
||||||
{
|
{
|
||||||
g_memcpy(mod, lmod, mod_len);
|
BN_bn2bin(my_key->d, (tui8 *)lpri);
|
||||||
g_memcpy(pri, lpri, pri_len);
|
ssl_reverse_it(lpri, pri_len);
|
||||||
}
|
}
|
||||||
RSA_free(my_key);
|
|
||||||
g_free(lmod);
|
if (error == 0)
|
||||||
g_free(lpri);
|
{
|
||||||
return error;
|
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
|
#else
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -304,60 +312,67 @@ ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_len,
|
|||||||
generates a new rsa key
|
generates a new rsa key
|
||||||
exp is passed in and mod and pri are passed out */
|
exp is passed in and mod and pri are passed out */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
ssl_gen_key_xrdp1(int key_size_in_bits, char* exp, int exp_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)
|
char *mod, int mod_len, char *pri, int pri_len)
|
||||||
{
|
{
|
||||||
BIGNUM* my_e;
|
BIGNUM *my_e;
|
||||||
RSA* my_key;
|
RSA *my_key;
|
||||||
char* lexp;
|
char *lexp;
|
||||||
char* lmod;
|
char *lmod;
|
||||||
char* lpri;
|
char *lpri;
|
||||||
int error;
|
int error;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
|
if ((exp_len != 4) || (mod_len != 64) || (pri_len != 64))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
lexp = (char*)g_malloc(exp_len, 0);
|
|
||||||
lmod = (char*)g_malloc(mod_len, 0);
|
lexp = (char *)g_malloc(exp_len, 0);
|
||||||
lpri = (char*)g_malloc(pri_len, 0);
|
lmod = (char *)g_malloc(mod_len, 0);
|
||||||
g_memcpy(lexp, exp, exp_len);
|
lpri = (char *)g_malloc(pri_len, 0);
|
||||||
ssl_reverse_it(lexp, exp_len);
|
g_memcpy(lexp, exp, exp_len);
|
||||||
my_e = BN_new();
|
ssl_reverse_it(lexp, exp_len);
|
||||||
BN_bin2bn((tui8*)lexp, exp_len, my_e);
|
my_e = BN_new();
|
||||||
my_key = RSA_new();
|
BN_bin2bn((tui8 *)lexp, exp_len, my_e);
|
||||||
error = RSA_generate_key_ex(my_key, key_size_in_bits, my_e, 0) == 0;
|
my_key = RSA_new();
|
||||||
if (error == 0)
|
error = RSA_generate_key_ex(my_key, key_size_in_bits, my_e, 0) == 0;
|
||||||
{
|
|
||||||
len = BN_num_bytes(my_key->n);
|
if (error == 0)
|
||||||
error = len != mod_len;
|
{
|
||||||
}
|
len = BN_num_bytes(my_key->n);
|
||||||
if (error == 0)
|
error = len != mod_len;
|
||||||
{
|
}
|
||||||
BN_bn2bin(my_key->n, (tui8*)lmod);
|
|
||||||
ssl_reverse_it(lmod, mod_len);
|
if (error == 0)
|
||||||
}
|
{
|
||||||
if (error == 0)
|
BN_bn2bin(my_key->n, (tui8 *)lmod);
|
||||||
{
|
ssl_reverse_it(lmod, mod_len);
|
||||||
len = BN_num_bytes(my_key->d);
|
}
|
||||||
error = len != pri_len;
|
|
||||||
}
|
if (error == 0)
|
||||||
if (error == 0)
|
{
|
||||||
{
|
len = BN_num_bytes(my_key->d);
|
||||||
BN_bn2bin(my_key->d, (tui8*)lpri);
|
error = len != pri_len;
|
||||||
ssl_reverse_it(lpri, pri_len);
|
}
|
||||||
}
|
|
||||||
if (error == 0)
|
if (error == 0)
|
||||||
{
|
{
|
||||||
g_memcpy(mod, lmod, mod_len);
|
BN_bn2bin(my_key->d, (tui8 *)lpri);
|
||||||
g_memcpy(pri, lpri, pri_len);
|
ssl_reverse_it(lpri, pri_len);
|
||||||
}
|
}
|
||||||
BN_free(my_e);
|
|
||||||
RSA_free(my_key);
|
if (error == 0)
|
||||||
g_free(lexp);
|
{
|
||||||
g_free(lmod);
|
g_memcpy(mod, lmod, mod_len);
|
||||||
g_free(lpri);
|
g_memcpy(pri, lpri, pri_len);
|
||||||
return error;
|
}
|
||||||
|
|
||||||
|
BN_free(my_e);
|
||||||
|
RSA_free(my_key);
|
||||||
|
g_free(lexp);
|
||||||
|
g_free(lmod);
|
||||||
|
g_free(lpri);
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+17
-19
@@ -1,22 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2004-2010
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(SSL_CALLS_H)
|
#if !defined(SSL_CALLS_H)
|
||||||
#define SSL_CALLS_H
|
#define SSL_CALLS_H
|
||||||
|
|||||||
+88
-87
@@ -1,27 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2004-2010 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* thread calls
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
thread calls
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -38,33 +33,36 @@
|
|||||||
/* returns error */
|
/* returns error */
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
int APP_CC
|
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;
|
int rv = 0;
|
||||||
DWORD thread_id = 0;
|
DWORD thread_id = 0;
|
||||||
HANDLE thread = (HANDLE)0;
|
HANDLE thread = (HANDLE)0;
|
||||||
|
|
||||||
/* CreateThread returns handle or zero on error */
|
/* CreateThread returns handle or zero on error */
|
||||||
thread = CreateThread(0, 0, start_routine, arg, 0, &thread_id);
|
thread = CreateThread(0, 0, start_routine, arg, 0, &thread_id);
|
||||||
rv = !thread;
|
rv = !thread;
|
||||||
CloseHandle(thread);
|
CloseHandle(thread);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int APP_CC
|
int APP_CC
|
||||||
tc_thread_create(void* (* start_routine)(void *), void* arg)
|
tc_thread_create(void * (* start_routine)(void *), void *arg)
|
||||||
{
|
{
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
pthread_t thread = (pthread_t)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 */
|
/* pthread_create returns error */
|
||||||
rv = pthread_create(&thread, 0, start_routine, arg);
|
rv = pthread_create(&thread, 0, start_routine, arg);
|
||||||
if (!rv) {
|
|
||||||
rv = pthread_detach(thread);
|
if (!rv)
|
||||||
}
|
{
|
||||||
return rv;
|
rv = pthread_detach(thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -73,9 +71,9 @@ tbus APP_CC
|
|||||||
tc_get_threadid(void)
|
tc_get_threadid(void)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return (tbus)GetCurrentThreadId();
|
return (tbus)GetCurrentThreadId();
|
||||||
#else
|
#else
|
||||||
return (tbus)pthread_self();
|
return (tbus)pthread_self();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,9 +83,9 @@ int APP_CC
|
|||||||
tc_threadid_equal(tbus tid1, tbus tid2)
|
tc_threadid_equal(tbus tid1, tbus tid2)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return tid1 == tid2;
|
return tid1 == tid2;
|
||||||
#else
|
#else
|
||||||
return pthread_equal((pthread_t)tid1, (pthread_t)tid2);
|
return pthread_equal((pthread_t)tid1, (pthread_t)tid2);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,13 +94,13 @@ tbus APP_CC
|
|||||||
tc_mutex_create(void)
|
tc_mutex_create(void)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return (tbus)CreateMutex(0, 0, 0);
|
return (tbus)CreateMutex(0, 0, 0);
|
||||||
#else
|
#else
|
||||||
pthread_mutex_t* lmutex;
|
pthread_mutex_t *lmutex;
|
||||||
|
|
||||||
lmutex = (pthread_mutex_t*)g_malloc(sizeof(pthread_mutex_t), 0);
|
lmutex = (pthread_mutex_t *)g_malloc(sizeof(pthread_mutex_t), 0);
|
||||||
pthread_mutex_init(lmutex, 0);
|
pthread_mutex_init(lmutex, 0);
|
||||||
return (tbus)lmutex;
|
return (tbus)lmutex;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,13 +109,13 @@ void APP_CC
|
|||||||
tc_mutex_delete(tbus mutex)
|
tc_mutex_delete(tbus mutex)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
CloseHandle((HANDLE)mutex);
|
CloseHandle((HANDLE)mutex);
|
||||||
#else
|
#else
|
||||||
pthread_mutex_t* lmutex;
|
pthread_mutex_t *lmutex;
|
||||||
|
|
||||||
lmutex = (pthread_mutex_t*)mutex;
|
lmutex = (pthread_mutex_t *)mutex;
|
||||||
pthread_mutex_destroy(lmutex);
|
pthread_mutex_destroy(lmutex);
|
||||||
g_free(lmutex);
|
g_free(lmutex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,11 +124,11 @@ int APP_CC
|
|||||||
tc_mutex_lock(tbus mutex)
|
tc_mutex_lock(tbus mutex)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
WaitForSingleObject((HANDLE)mutex, INFINITE);
|
WaitForSingleObject((HANDLE)mutex, INFINITE);
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
pthread_mutex_lock((pthread_mutex_t*)mutex);
|
pthread_mutex_lock((pthread_mutex_t *)mutex);
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,15 +136,18 @@ tc_mutex_lock(tbus mutex)
|
|||||||
int APP_CC
|
int APP_CC
|
||||||
tc_mutex_unlock(tbus mutex)
|
tc_mutex_unlock(tbus mutex)
|
||||||
{
|
{
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
ReleaseMutex((HANDLE)mutex);
|
ReleaseMutex((HANDLE)mutex);
|
||||||
#else
|
#else
|
||||||
if (mutex != 0) {
|
|
||||||
rv = pthread_mutex_unlock((pthread_mutex_t *)mutex);
|
if (mutex != 0)
|
||||||
}
|
{
|
||||||
|
rv = pthread_mutex_unlock((pthread_mutex_t *)mutex);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -154,16 +155,16 @@ tbus APP_CC
|
|||||||
tc_sem_create(int init_count)
|
tc_sem_create(int init_count)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
HANDLE sem;
|
HANDLE sem;
|
||||||
|
|
||||||
sem = CreateSemaphore(0, init_count, init_count + 10, 0);
|
sem = CreateSemaphore(0, init_count, init_count + 10, 0);
|
||||||
return (tbus)sem;
|
return (tbus)sem;
|
||||||
#else
|
#else
|
||||||
sem_t * sem = (sem_t *)NULL;
|
sem_t *sem = (sem_t *)NULL;
|
||||||
|
|
||||||
sem = (sem_t *)g_malloc(sizeof(sem_t), 0);
|
sem = (sem_t *)g_malloc(sizeof(sem_t), 0);
|
||||||
sem_init(sem, 0, init_count);
|
sem_init(sem, 0, init_count);
|
||||||
return (tbus)sem;
|
return (tbus)sem;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,13 +173,13 @@ void APP_CC
|
|||||||
tc_sem_delete(tbus sem)
|
tc_sem_delete(tbus sem)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
CloseHandle((HANDLE)sem);
|
CloseHandle((HANDLE)sem);
|
||||||
#else
|
#else
|
||||||
sem_t* lsem;
|
sem_t *lsem;
|
||||||
|
|
||||||
lsem = (sem_t*)sem;
|
lsem = (sem_t *)sem;
|
||||||
sem_destroy(lsem);
|
sem_destroy(lsem);
|
||||||
g_free(lsem);
|
g_free(lsem);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,11 +188,11 @@ int APP_CC
|
|||||||
tc_sem_dec(tbus sem)
|
tc_sem_dec(tbus sem)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
WaitForSingleObject((HANDLE)sem, INFINITE);
|
WaitForSingleObject((HANDLE)sem, INFINITE);
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
sem_wait((sem_t*)sem);
|
sem_wait((sem_t *)sem);
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,10 +201,10 @@ int APP_CC
|
|||||||
tc_sem_inc(tbus sem)
|
tc_sem_inc(tbus sem)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
ReleaseSemaphore((HANDLE)sem, 1, 0);
|
ReleaseSemaphore((HANDLE)sem, 1, 0);
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
sem_post((sem_t*)sem);
|
sem_post((sem_t *)sem);
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-24
@@ -1,27 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2004-2010 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* thread calls
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
thread calls
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(THREAD_CALLS_H)
|
#if !defined(THREAD_CALLS_H)
|
||||||
#define THREAD_CALLS_H
|
#define THREAD_CALLS_H
|
||||||
|
|||||||
+384
-343
@@ -1,27 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2008-2010 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* generic transport
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
generic transport
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "os_calls.h"
|
#include "os_calls.h"
|
||||||
#include "trans.h"
|
#include "trans.h"
|
||||||
@@ -29,394 +24,440 @@
|
|||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct trans* APP_CC
|
struct trans *APP_CC
|
||||||
trans_create(int mode, int in_size, int out_size)
|
trans_create(int mode, int in_size, int out_size)
|
||||||
{
|
{
|
||||||
struct trans* self = (struct trans *)NULL;
|
struct trans *self = (struct trans *)NULL;
|
||||||
|
|
||||||
self = (struct trans*)g_malloc(sizeof(struct trans), 1);
|
self = (struct trans *)g_malloc(sizeof(struct trans), 1);
|
||||||
if (self != NULL) {
|
|
||||||
make_stream(self->in_s);
|
if (self != NULL)
|
||||||
init_stream(self->in_s, in_size);
|
{
|
||||||
make_stream(self->out_s);
|
make_stream(self->in_s);
|
||||||
init_stream(self->out_s, out_size);
|
init_stream(self->in_s, in_size);
|
||||||
self->mode = mode;
|
make_stream(self->out_s);
|
||||||
}
|
init_stream(self->out_s, out_size);
|
||||||
return self;
|
self->mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
trans_delete(struct trans* self)
|
trans_delete(struct trans *self)
|
||||||
{
|
{
|
||||||
if (self == 0)
|
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)
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
in_sck = g_tcp_accept(self->sck);
|
return;
|
||||||
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 /* connected server or client (2 or 3) */
|
free_stream(self->in_s);
|
||||||
{
|
free_stream(self->out_s);
|
||||||
if (g_tcp_can_recv(self->sck, 0))
|
|
||||||
|
if (self->sck > 0)
|
||||||
{
|
{
|
||||||
read_so_far = (int)(self->in_s->end - self->in_s->data);
|
g_tcp_close(self->sck);
|
||||||
to_read = self->header_size - read_so_far;
|
}
|
||||||
if (to_read > 0)
|
|
||||||
{
|
self->sck = 0;
|
||||||
read_bytes = g_tcp_recv(self->sck, self->in_s->end, to_read, 0);
|
|
||||||
if (read_bytes == -1)
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
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 /* connected server or client (2 or 3) */
|
||||||
|
{
|
||||||
|
if (g_tcp_can_recv(self->sck, 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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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 */
|
/* error */
|
||||||
self->status = TRANS_STATUS_DOWN;
|
self->status = TRANS_STATUS_DOWN;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (read_bytes == 0)
|
|
||||||
{
|
|
||||||
/* error */
|
|
||||||
self->status = TRANS_STATUS_DOWN;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
else
|
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
|
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)
|
/*****************************************************************************/
|
||||||
{
|
int APP_CC
|
||||||
return 1;
|
trans_force_write_s(struct trans *self, struct stream *out_s)
|
||||||
}
|
{
|
||||||
while (size > 0)
|
int size;
|
||||||
{
|
int total;
|
||||||
rcvd = g_tcp_recv(self->sck, in_s->end, size, 0);
|
int sent;
|
||||||
if (rcvd == -1)
|
|
||||||
|
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;
|
return 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (rcvd == 0)
|
|
||||||
{
|
|
||||||
/* error */
|
|
||||||
self->status = TRANS_STATUS_DOWN;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
in_s->end += rcvd;
|
|
||||||
size -= rcvd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
size = (int)(out_s->end - out_s->data);
|
||||||
int APP_CC
|
total = 0;
|
||||||
trans_force_read(struct trans* self, int size)
|
|
||||||
{
|
|
||||||
return trans_force_read_s(self, self->in_s, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
while (total < size)
|
||||||
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)
|
|
||||||
{
|
|
||||||
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 (g_tcp_last_error_would_block(self->sck))
|
sent = g_tcp_send(self->sck, out_s->data + total, size - total, 0);
|
||||||
{
|
|
||||||
if (!g_tcp_can_send(self->sck, 10))
|
if (sent == -1)
|
||||||
{
|
{
|
||||||
/* check for term here */
|
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;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* error */
|
|
||||||
self->status = TRANS_STATUS_DOWN;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (sent == 0)
|
|
||||||
{
|
return 0;
|
||||||
/* error */
|
|
||||||
self->status = TRANS_STATUS_DOWN;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
total = total + sent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
trans_force_write(struct trans* self)
|
trans_force_write(struct trans *self)
|
||||||
{
|
{
|
||||||
return trans_force_write_s(self, self->out_s);
|
return trans_force_write_s(self, self->out_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
trans_connect(struct trans* self, const char* server, const char* port,
|
trans_connect(struct trans *self, const char *server, const char *port,
|
||||||
int timeout)
|
int timeout)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (self->sck != 0)
|
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 (g_tcp_can_send(self->sck, timeout))
|
g_tcp_close(self->sck);
|
||||||
{
|
|
||||||
self->status = TRANS_STATUS_UP; /* ok */
|
|
||||||
self->type1 = TRANS_TYPE_CLIENT; /* client */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
}
|
if (self->mode == TRANS_MODE_TCP) /* tcp */
|
||||||
self->status = TRANS_STATUS_UP; /* ok */
|
{
|
||||||
self->type1 = TRANS_TYPE_CLIENT; /* client */
|
self->sck = g_tcp_socket();
|
||||||
return 0;
|
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 (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
|
int APP_CC
|
||||||
trans_listen_address(struct trans* self, char* port, const char* address)
|
trans_listen_address(struct trans *self, char *port, const char *address)
|
||||||
{
|
{
|
||||||
if (self->sck != 0)
|
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 (g_tcp_listen(self->sck) == 0)
|
g_tcp_close(self->sck);
|
||||||
{
|
|
||||||
self->status = TRANS_STATUS_UP; /* ok */
|
|
||||||
self->type1 = TRANS_TYPE_LISTENER; /* listener */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (self->mode == TRANS_MODE_UNIX) /* unix socket */
|
if (self->mode == TRANS_MODE_TCP) /* tcp */
|
||||||
{
|
|
||||||
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);
|
self->sck = g_tcp_socket();
|
||||||
if (g_tcp_listen(self->sck) == 0)
|
g_tcp_set_non_blocking(self->sck);
|
||||||
{
|
|
||||||
g_chmod_hex(port, 0xffff);
|
if (g_tcp_bind_address(self->sck, port, address) == 0)
|
||||||
self->status = TRANS_STATUS_UP; /* ok */
|
{
|
||||||
self->type1 = TRANS_TYPE_LISTENER; /* listener */
|
if (g_tcp_listen(self->sck) == 0)
|
||||||
return 0;
|
{
|
||||||
}
|
self->status = TRANS_STATUS_UP; /* ok */
|
||||||
|
self->type1 = TRANS_TYPE_LISTENER; /* listener */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (self->mode == TRANS_MODE_UNIX) /* unix socket */
|
||||||
return 1;
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
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
|
struct stream *APP_CC
|
||||||
trans_get_in_s(struct trans* self)
|
trans_get_in_s(struct trans *self)
|
||||||
{
|
{
|
||||||
struct stream * rv = (struct stream *)NULL;
|
struct stream *rv = (struct stream *)NULL;
|
||||||
if (self == NULL) {
|
|
||||||
rv = (struct stream *)NULL;
|
if (self == NULL)
|
||||||
}
|
{
|
||||||
else {
|
rv = (struct stream *)NULL;
|
||||||
rv = self->in_s;
|
}
|
||||||
}
|
else
|
||||||
return rv;
|
{
|
||||||
|
rv = self->in_s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct stream* APP_CC
|
struct stream *APP_CC
|
||||||
trans_get_out_s(struct trans* self, int size)
|
trans_get_out_s(struct trans *self, int size)
|
||||||
{
|
{
|
||||||
struct stream * rv = (struct stream *)NULL;
|
struct stream *rv = (struct stream *)NULL;
|
||||||
if (self == NULL) {
|
|
||||||
rv = (struct stream *)NULL;
|
if (self == NULL)
|
||||||
}
|
{
|
||||||
else {
|
rv = (struct stream *)NULL;
|
||||||
init_stream(self->out_s, size);
|
}
|
||||||
rv = self->out_s;
|
else
|
||||||
}
|
{
|
||||||
return rv;
|
init_stream(self->out_s, size);
|
||||||
|
rv = self->out_s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-24
@@ -1,27 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2008-2010 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* generic transport
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
generic transport
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(TRANS_H)
|
#if !defined(TRANS_H)
|
||||||
#define TRANS_H
|
#define TRANS_H
|
||||||
|
|||||||
+19
-24
@@ -1,27 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
Copyright (c) 2012 Jay Sorg
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
copy of this software and associated documentation files (the "Software"),
|
*
|
||||||
to deal in the Software without restriction, including without limitation
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* you may not use this file except in compliance with the License.
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
* You may obtain a copy of the License at
|
||||||
Software is furnished to do so, subject to the following conditions:
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
The above copyright notice and this permission notice shall be included
|
*
|
||||||
in all copies or substantial portions of the Software.
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* See the License for the specific language governing permissions and
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* limitations under the License.
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
*
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
* xrdp / xserver info / caps
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
*/
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
xrdp / xserver info / caps
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(XRDP_CLIENT_INFO_H)
|
#if !defined(XRDP_CLIENT_INFO_H)
|
||||||
#define XRDP_CLIENT_INFO_H
|
#define XRDP_CLIENT_INFO_H
|
||||||
|
|||||||
+435
-359
@@ -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 <windows.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
@@ -25,426 +42,485 @@ static int g_running = 0;
|
|||||||
int
|
int
|
||||||
check_messages(void)
|
check_messages(void)
|
||||||
{
|
{
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
|
||||||
while (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
|
while (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
|
||||||
{
|
{
|
||||||
GetMessage(&msg, NULL, 0, 0);
|
GetMessage(&msg, NULL, 0, 0);
|
||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int
|
static int
|
||||||
msg(char* msg1, ...)
|
msg(char *msg1, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char text1[512];
|
char text1[512];
|
||||||
|
|
||||||
va_start(ap, msg1);
|
va_start(ap, msg1);
|
||||||
vsnprintf(text1, 511, msg1, ap);
|
vsnprintf(text1, 511, msg1, ap);
|
||||||
SendMessageA(g_lb, LB_ADDSTRING, 0, (LPARAM)text1);
|
SendMessageA(g_lb, LB_ADDSTRING, 0, (LPARAM)text1);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int
|
static int
|
||||||
show_last_error(void)
|
show_last_error(void)
|
||||||
{
|
{
|
||||||
LPVOID lpMsgBuf;
|
LPVOID lpMsgBuf;
|
||||||
|
|
||||||
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||||
NULL, GetLastError(),
|
NULL, GetLastError(),
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
(LPSTR)&lpMsgBuf, 0, NULL);
|
(LPSTR)&lpMsgBuf, 0, NULL);
|
||||||
msg("GetLastError - %s", lpMsgBuf);
|
msg("GetLastError - %s", lpMsgBuf);
|
||||||
LocalFree(lpMsgBuf);
|
LocalFree(lpMsgBuf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int
|
static int
|
||||||
font_dump(void)
|
font_dump(void)
|
||||||
{
|
{
|
||||||
HDC dc;
|
HDC dc;
|
||||||
HDC dc1;
|
HDC dc1;
|
||||||
RECT rect;
|
RECT rect;
|
||||||
HBRUSH brush;
|
HBRUSH brush;
|
||||||
HGDIOBJ saved;
|
HGDIOBJ saved;
|
||||||
HBITMAP bitmap;
|
HBITMAP bitmap;
|
||||||
BITMAPINFO bi;
|
BITMAPINFO bi;
|
||||||
char* bits;
|
char *bits;
|
||||||
ABC abc;
|
ABC abc;
|
||||||
SIZE sz;
|
SIZE sz;
|
||||||
char filename[256];
|
char filename[256];
|
||||||
TCHAR text[256];
|
TCHAR text[256];
|
||||||
char zero1;
|
char zero1;
|
||||||
char* bmtext;
|
char *bmtext;
|
||||||
int bmtextindex;
|
int bmtextindex;
|
||||||
int fd;
|
int fd;
|
||||||
int x1;
|
int x1;
|
||||||
int strlen1;
|
int strlen1;
|
||||||
int index1;
|
int index1;
|
||||||
int index2;
|
int index2;
|
||||||
int len;
|
int len;
|
||||||
int pixel;
|
int pixel;
|
||||||
int red;
|
int red;
|
||||||
int green;
|
int green;
|
||||||
int blue;
|
int blue;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int roller;
|
int roller;
|
||||||
int outlen;
|
int outlen;
|
||||||
tui8 b1;
|
tui8 b1;
|
||||||
short x2;
|
short x2;
|
||||||
|
|
||||||
if (g_running)
|
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))
|
|
||||||
{
|
{
|
||||||
show_last_error();
|
return 0;
|
||||||
}
|
}
|
||||||
text[0] = (TCHAR)x1;
|
|
||||||
text[1] = 0;
|
g_running = 1;
|
||||||
if (!GetTextExtentPoint32(dc, text, 1, &sz))
|
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);
|
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);
|
g_file_write(fd, &zero1, 1);
|
||||||
index1++;
|
index1++;
|
||||||
}
|
}
|
||||||
dc = GetWindowDC(g_wnd);
|
|
||||||
rect.left = 50 + abc.abcA;
|
for (x1 = 32; x1 < 0x4e00; x1++)
|
||||||
rect.top = 50;
|
{
|
||||||
rect.right = rect.left + abc.abcB;
|
check_messages();
|
||||||
rect.bottom = rect.top + sz.cy;
|
dc = GetWindowDC(g_wnd);
|
||||||
memset(&bi, 0, sizeof(bi));
|
saved = SelectObject(dc, g_font);
|
||||||
width = (abc.abcB + 7) & (~7);
|
|
||||||
height = sz.cy;
|
if (!GetCharABCWidths(dc, x1, x1, &abc))
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
show_last_error();
|
show_last_error();
|
||||||
}
|
}
|
||||||
bmtext = (char*)g_malloc(width * height + 16, 1);
|
|
||||||
bmtextindex = 0;
|
text[0] = (TCHAR)x1;
|
||||||
for (index1 = (height - 1); index1 >= 0; index1--)
|
text[1] = 0;
|
||||||
|
|
||||||
|
if (!GetTextExtentPoint32(dc, text, 1, &sz))
|
||||||
{
|
{
|
||||||
for (index2 = 0; index2 < width; index2++)
|
show_last_error();
|
||||||
{
|
}
|
||||||
pixel = ((int*)bits)[index1 * width + index2];
|
|
||||||
red = (pixel >> 16) & 0xff;
|
SelectObject(dc, saved);
|
||||||
green = (pixel >> 8) & 0xff;
|
ReleaseDC(g_wnd, dc);
|
||||||
blue = (pixel >> 0) & 0xff;
|
|
||||||
if (red == 0 && green == 0 && blue == 0)
|
if ((sz.cx > 0) && (sz.cy > 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))
|
||||||
{
|
{
|
||||||
bmtext[bmtextindex] = '1';
|
show_last_error();
|
||||||
bmtextindex++;
|
}
|
||||||
|
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
bmtext[bmtextindex] = '0';
|
memset(bits, 0, width * height * 4);
|
||||||
bmtextindex++;
|
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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
if (sz.cx != (long)(abc.abcA + abc.abcB + abc.abcC))
|
||||||
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;
|
msg("error - width not right 1");
|
||||||
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++;
|
brush = CreateSolidBrush(RGB(255, 255, 255));
|
||||||
if (roller == 8)
|
FillRect(dc, &rect, brush);
|
||||||
{
|
DeleteObject(brush);
|
||||||
roller = 0;
|
ReleaseDC(g_wnd, dc);
|
||||||
g_file_write(fd, &b1, 1);
|
|
||||||
outlen++;
|
|
||||||
b1 = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while ((outlen % 4) != 0)
|
else
|
||||||
{
|
{
|
||||||
g_file_write(fd, &zero1, 1);
|
/* write out a blank glyph here */
|
||||||
outlen++;
|
/* 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
|
|
||||||
{
|
g_file_close(fd);
|
||||||
/* write out a blank glyph here */
|
msg("done");
|
||||||
/* width */
|
g_running = 0;
|
||||||
x2 = 1;
|
return 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static LRESULT CALLBACK
|
static LRESULT CALLBACK
|
||||||
wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
HBRUSH brush;
|
HBRUSH brush;
|
||||||
RECT rect;
|
RECT rect;
|
||||||
|
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
BeginPaint(hWnd, &ps);
|
BeginPaint(hWnd, &ps);
|
||||||
brush = CreateSolidBrush(RGB(255, 255, 255));
|
brush = CreateSolidBrush(RGB(255, 255, 255));
|
||||||
rect = ps.rcPaint;
|
rect = ps.rcPaint;
|
||||||
FillRect(ps.hdc, &rect, brush);
|
FillRect(ps.hdc, &rect, brush);
|
||||||
DeleteObject(brush);
|
DeleteObject(brush);
|
||||||
EndPaint(hWnd, &ps);
|
EndPaint(hWnd, &ps);
|
||||||
break;
|
break;
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
DestroyWindow(g_wnd);
|
DestroyWindow(g_wnd);
|
||||||
g_wnd = 0;
|
g_wnd = 0;
|
||||||
break;
|
break;
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
break;
|
break;
|
||||||
case WM_TIMER:
|
case WM_TIMER:
|
||||||
KillTimer(g_wnd, 1);
|
KillTimer(g_wnd, 1);
|
||||||
font_dump();
|
font_dump();
|
||||||
break;
|
break;
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
if ((HWND)lParam == g_exit_button)
|
|
||||||
{
|
if ((HWND)lParam == g_exit_button)
|
||||||
PostMessage(g_wnd, WM_CLOSE, 0, 0);
|
{
|
||||||
}
|
PostMessage(g_wnd, WM_CLOSE, 0, 0);
|
||||||
else if ((HWND)lParam == g_go_button)
|
}
|
||||||
{
|
else if ((HWND)lParam == g_go_button)
|
||||||
while (SendMessage(g_lb, LB_GETCOUNT, 0, 0) > 0)
|
{
|
||||||
{
|
while (SendMessage(g_lb, LB_GETCOUNT, 0, 0) > 0)
|
||||||
SendMessage(g_lb, LB_DELETESTRING, 0, 0);
|
{
|
||||||
}
|
SendMessage(g_lb, LB_DELETESTRING, 0, 0);
|
||||||
SetTimer(g_wnd, 1, 1000, 0);
|
}
|
||||||
}
|
|
||||||
break;
|
SetTimer(g_wnd, 1, 1000, 0);
|
||||||
}
|
}
|
||||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int
|
static int
|
||||||
create_window(void)
|
create_window(void)
|
||||||
{
|
{
|
||||||
WNDCLASS wc;
|
WNDCLASS wc;
|
||||||
DWORD style;
|
DWORD style;
|
||||||
HDC dc;
|
HDC dc;
|
||||||
int height;
|
int height;
|
||||||
int left;
|
int left;
|
||||||
int top;
|
int top;
|
||||||
|
|
||||||
ZeroMemory(&wc, sizeof(wc));
|
ZeroMemory(&wc, sizeof(wc));
|
||||||
wc.lpfnWndProc = wnd_proc; /* points to window procedure */
|
wc.lpfnWndProc = wnd_proc; /* points to window procedure */
|
||||||
/* name of window class */
|
/* name of window class */
|
||||||
wc.lpszClassName = _T("fontdump");
|
wc.lpszClassName = _T("fontdump");
|
||||||
wc.hCursor = LoadCursor(0, IDC_ARROW);
|
wc.hCursor = LoadCursor(0, IDC_ARROW);
|
||||||
/* Register the window class. */
|
|
||||||
if (!RegisterClass(&wc))
|
/* Register the window class. */
|
||||||
{
|
if (!RegisterClass(&wc))
|
||||||
return 0; /* Failed to register window class */
|
{
|
||||||
}
|
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;
|
style = WS_OVERLAPPED | WS_CAPTION | WS_POPUP | WS_MINIMIZEBOX |
|
||||||
top = GetSystemMetrics(SM_CYSCREEN) / 2 - 480 / 2;
|
WS_SYSMENU | WS_SIZEBOX | WS_MAXIMIZEBOX;
|
||||||
g_wnd = CreateWindow(wc.lpszClassName, _T("fontdump"),
|
left = GetSystemMetrics(SM_CXSCREEN) / 2 - 640 / 2;
|
||||||
style, left, top, 640, 480,
|
top = GetSystemMetrics(SM_CYSCREEN) / 2 - 480 / 2;
|
||||||
(HWND) NULL, (HMENU) NULL, g_instance,
|
g_wnd = CreateWindow(wc.lpszClassName, _T("fontdump"),
|
||||||
(LPVOID) NULL);
|
style, left, top, 640, 480,
|
||||||
style = WS_CHILD | WS_VISIBLE | WS_BORDER;
|
(HWND) NULL, (HMENU) NULL, g_instance,
|
||||||
g_lb = CreateWindow(_T("LISTBOX"), _T("LISTBOX1"), style,
|
(LPVOID) NULL);
|
||||||
200, 10, 400, 400, g_wnd, 0, g_instance, 0);
|
style = WS_CHILD | WS_VISIBLE | WS_BORDER;
|
||||||
style = WS_CHILD | WS_VISIBLE;
|
g_lb = CreateWindow(_T("LISTBOX"), _T("LISTBOX1"), style,
|
||||||
g_exit_button = CreateWindow(_T("BUTTON"), _T("Exit"), style,
|
200, 10, 400, 400, g_wnd, 0, g_instance, 0);
|
||||||
540, 410, 75, 25, g_wnd, 0, g_instance, 0);
|
style = WS_CHILD | WS_VISIBLE;
|
||||||
g_go_button = CreateWindow(_T("BUTTON"), _T("Go"), style,
|
g_exit_button = CreateWindow(_T("BUTTON"), _T("Exit"), style,
|
||||||
440, 410, 75, 25, g_wnd, 0, g_instance, 0);
|
540, 410, 75, 25, g_wnd, 0, g_instance, 0);
|
||||||
style = WS_CHILD | WS_VISIBLE | CBS_DROPDOWN;
|
g_go_button = CreateWindow(_T("BUTTON"), _T("Go"), style,
|
||||||
g_font_list = CreateWindow(_T("COMBOBOX"), _T("COMBOBOX1"), style,
|
440, 410, 75, 25, g_wnd, 0, g_instance, 0);
|
||||||
50, 250, 125, 125, g_wnd, 0, g_instance, 0);
|
style = WS_CHILD | WS_VISIBLE | CBS_DROPDOWN;
|
||||||
ShowWindow(g_wnd, SW_SHOWNORMAL);
|
g_font_list = CreateWindow(_T("COMBOBOX"), _T("COMBOBOX1"), style,
|
||||||
PostMessage(g_wnd, WM_SETFONT, (WPARAM)g_font, 0);
|
50, 250, 125, 125, g_wnd, 0, g_instance, 0);
|
||||||
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Tahoma");
|
ShowWindow(g_wnd, SW_SHOWNORMAL);
|
||||||
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"DejaVu Serif");
|
PostMessage(g_wnd, WM_SETFONT, (WPARAM)g_font, 0);
|
||||||
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"DejaVu Sans");
|
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Tahoma");
|
||||||
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Arial");
|
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"DejaVu Serif");
|
||||||
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Comic Sans MS");
|
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"DejaVu Sans");
|
||||||
return 0;
|
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Arial");
|
||||||
|
SendMessageA(g_font_list, CB_ADDSTRING, 0, (LPARAM)"Comic Sans MS");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int
|
static int
|
||||||
main_loop(void)
|
main_loop(void)
|
||||||
{
|
{
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
|
||||||
while (GetMessage(&msg, NULL, 0, 0))
|
while (GetMessage(&msg, NULL, 0, 0))
|
||||||
{
|
{
|
||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
return (int)(msg.wParam);
|
|
||||||
|
return (int)(msg.wParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -452,7 +528,7 @@ int WINAPI
|
|||||||
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
LPSTR lpCmdLine, int nCmdShow)
|
LPSTR lpCmdLine, int nCmdShow)
|
||||||
{
|
{
|
||||||
g_instance = hInstance;
|
g_instance = hInstance;
|
||||||
create_window();
|
create_window();
|
||||||
return main_loop();
|
return main_loop();
|
||||||
}
|
}
|
||||||
|
|||||||
+287
-252
@@ -1,279 +1,314 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2010
|
*
|
||||||
|
* freerdp wrapper
|
||||||
freerdp wrapper
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "xrdp-freerdp.h"
|
#include "xrdp-freerdp.h"
|
||||||
|
|
||||||
char* APP_CC
|
char *APP_CC
|
||||||
convert_bitmap(int in_bpp, int out_bpp, char* bmpdata,
|
convert_bitmap(int in_bpp, int out_bpp, char *bmpdata,
|
||||||
int width, int height, int* palette)
|
int width, int height, int *palette)
|
||||||
{
|
{
|
||||||
char* out;
|
char *out;
|
||||||
char* src;
|
char *src;
|
||||||
char* dst;
|
char *dst;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int red;
|
int red;
|
||||||
int green;
|
int green;
|
||||||
int blue;
|
int blue;
|
||||||
int pixel;
|
int pixel;
|
||||||
|
|
||||||
if ((in_bpp == 8) && (out_bpp == 8))
|
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++)
|
out = (char *)g_malloc(width * height, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui8*)src);
|
dst = out;
|
||||||
pixel = palette[pixel];
|
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
for (i = 0; i < height; i++)
|
||||||
pixel = COLOR8(red, green, blue);
|
{
|
||||||
*dst = pixel;
|
for (j = 0; j < width; j++)
|
||||||
src++;
|
{
|
||||||
dst++;
|
pixel = *((tui8 *)src);
|
||||||
}
|
pixel = palette[pixel];
|
||||||
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
|
pixel = COLOR8(red, green, blue);
|
||||||
|
*dst = pixel;
|
||||||
|
src++;
|
||||||
|
dst++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 8) && (out_bpp == 16))
|
||||||
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++)
|
out = (char *)g_malloc(width * height * 2, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui8*)src);
|
dst = out;
|
||||||
pixel = palette[pixel];
|
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
for (i = 0; i < height; i++)
|
||||||
pixel = COLOR16(red, green, blue);
|
{
|
||||||
*((tui16*)dst) = pixel;
|
for (j = 0; j < width; j++)
|
||||||
src++;
|
{
|
||||||
dst += 2;
|
pixel = *((tui8 *)src);
|
||||||
}
|
pixel = palette[pixel];
|
||||||
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
|
pixel = COLOR16(red, green, blue);
|
||||||
|
*((tui16 *)dst) = pixel;
|
||||||
|
src++;
|
||||||
|
dst += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 8) && (out_bpp == 24))
|
||||||
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++)
|
out = (char *)g_malloc(width * height * 4, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui8*)src);
|
dst = out;
|
||||||
pixel = palette[pixel];
|
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
for (i = 0; i < height; i++)
|
||||||
pixel = COLOR24RGB(red, green, blue);
|
{
|
||||||
*((tui32*)dst) = pixel;
|
for (j = 0; j < width; j++)
|
||||||
src++;
|
{
|
||||||
dst += 4;
|
pixel = *((tui8 *)src);
|
||||||
}
|
pixel = palette[pixel];
|
||||||
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
|
pixel = COLOR24RGB(red, green, blue);
|
||||||
|
*((tui32 *)dst) = pixel;
|
||||||
|
src++;
|
||||||
|
dst += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 15) && (out_bpp == 16))
|
||||||
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++)
|
out = (char *)g_malloc(width * height * 2, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui16*)src);
|
dst = out;
|
||||||
SPLITCOLOR15(red, green, blue, pixel);
|
|
||||||
pixel = COLOR16(red, green, blue);
|
for (i = 0; i < height; i++)
|
||||||
*((tui16*)dst) = pixel;
|
{
|
||||||
src += 2;
|
for (j = 0; j < width; j++)
|
||||||
dst += 2;
|
{
|
||||||
}
|
pixel = *((tui16 *)src);
|
||||||
|
SPLITCOLOR15(red, green, blue, pixel);
|
||||||
|
pixel = COLOR16(red, green, blue);
|
||||||
|
*((tui16 *)dst) = pixel;
|
||||||
|
src += 2;
|
||||||
|
dst += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 15) && (out_bpp == 24))
|
||||||
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++)
|
out = (char *)g_malloc(width * height * 4, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui16*)src);
|
dst = out;
|
||||||
SPLITCOLOR15(red, green, blue, pixel);
|
|
||||||
pixel = COLOR24RGB(red, green, blue);
|
for (i = 0; i < height; i++)
|
||||||
*((tui32*)dst) = pixel;
|
{
|
||||||
src += 2;
|
for (j = 0; j < width; j++)
|
||||||
dst += 4;
|
{
|
||||||
}
|
pixel = *((tui16 *)src);
|
||||||
|
SPLITCOLOR15(red, green, blue, pixel);
|
||||||
|
pixel = COLOR24RGB(red, green, blue);
|
||||||
|
*((tui32 *)dst) = pixel;
|
||||||
|
src += 2;
|
||||||
|
dst += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 16) && (out_bpp == 16))
|
||||||
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++)
|
return bmpdata;
|
||||||
{
|
|
||||||
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 == 16) && (out_bpp == 24))
|
||||||
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++)
|
out = (char *)g_malloc(width * height * 4, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
blue = *((tui8*)src);
|
dst = out;
|
||||||
src++;
|
|
||||||
green = *((tui8*)src);
|
for (i = 0; i < height; i++)
|
||||||
src++;
|
{
|
||||||
red = *((tui8*)src);
|
for (j = 0; j < width; j++)
|
||||||
src++;
|
{
|
||||||
pixel = COLOR24RGB(red, green, blue);
|
pixel = *((tui16 *)src);
|
||||||
*((tui32*)dst) = pixel;
|
SPLITCOLOR16(red, green, blue, pixel);
|
||||||
dst += 4;
|
pixel = COLOR24RGB(red, green, blue);
|
||||||
}
|
*((tui32 *)dst) = pixel;
|
||||||
|
src += 2;
|
||||||
|
dst += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 24) && (out_bpp == 24))
|
||||||
if ((in_bpp == 32) && (out_bpp == 24))
|
{
|
||||||
{
|
out = (char *)g_malloc(width * height * 4, 0);
|
||||||
return bmpdata;
|
src = bmpdata;
|
||||||
}
|
dst = out;
|
||||||
if ((in_bpp == 32) && (out_bpp == 32))
|
|
||||||
{
|
for (i = 0; i < height; i++)
|
||||||
return bmpdata;
|
{
|
||||||
}
|
for (j = 0; j < width; j++)
|
||||||
if ((in_bpp == 15) && (out_bpp == 15))
|
{
|
||||||
{
|
blue = *((tui8 *)src);
|
||||||
return bmpdata;
|
src++;
|
||||||
}
|
green = *((tui8 *)src);
|
||||||
g_writeln("convert_bitmap: error unknown conversion from %d to %d",
|
src++;
|
||||||
in_bpp, out_bpp);
|
red = *((tui8 *)src);
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_writeln("convert_bitmap: error unknown conversion from %d to %d",
|
||||||
|
in_bpp, out_bpp);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns color or 0 */
|
/* returns color or 0 */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
convert_color(int in_bpp, int out_bpp, int in_color, int* palette)
|
convert_color(int in_bpp, int out_bpp, int in_color, int *palette)
|
||||||
{
|
{
|
||||||
int pixel;
|
int pixel;
|
||||||
int red;
|
int red;
|
||||||
int green;
|
int green;
|
||||||
int blue;
|
int blue;
|
||||||
|
|
||||||
if ((in_bpp == 1) && (out_bpp == 24))
|
if ((in_bpp == 1) && (out_bpp == 24))
|
||||||
{
|
{
|
||||||
pixel = in_color == 0 ? 0 : 0xffffff;
|
pixel = in_color == 0 ? 0 : 0xffffff;
|
||||||
return pixel;
|
return pixel;
|
||||||
}
|
}
|
||||||
if ((in_bpp == 8) && (out_bpp == 8))
|
|
||||||
{
|
if ((in_bpp == 8) && (out_bpp == 8))
|
||||||
pixel = palette[in_color];
|
{
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
pixel = palette[in_color];
|
||||||
pixel = COLOR8(red, green, blue);
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
return pixel;
|
pixel = COLOR8(red, green, blue);
|
||||||
}
|
return pixel;
|
||||||
if ((in_bpp == 8) && (out_bpp == 16))
|
}
|
||||||
{
|
|
||||||
pixel = palette[in_color];
|
if ((in_bpp == 8) && (out_bpp == 16))
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
{
|
||||||
pixel = COLOR16(red, green, blue);
|
pixel = palette[in_color];
|
||||||
return pixel;
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
}
|
pixel = COLOR16(red, green, blue);
|
||||||
if ((in_bpp == 8) && (out_bpp == 24))
|
return pixel;
|
||||||
{
|
}
|
||||||
pixel = palette[in_color];
|
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
if ((in_bpp == 8) && (out_bpp == 24))
|
||||||
pixel = COLOR24BGR(red, green, blue);
|
{
|
||||||
return pixel;
|
pixel = palette[in_color];
|
||||||
}
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
if ((in_bpp == 15) && (out_bpp == 16))
|
pixel = COLOR24BGR(red, green, blue);
|
||||||
{
|
return pixel;
|
||||||
pixel = in_color;
|
}
|
||||||
SPLITCOLOR15(red, green, blue, pixel);
|
|
||||||
pixel = COLOR16(red, green, blue);
|
if ((in_bpp == 15) && (out_bpp == 16))
|
||||||
return pixel;
|
{
|
||||||
}
|
pixel = in_color;
|
||||||
if ((in_bpp == 15) && (out_bpp == 24))
|
SPLITCOLOR15(red, green, blue, pixel);
|
||||||
{
|
pixel = COLOR16(red, green, blue);
|
||||||
pixel = in_color;
|
return pixel;
|
||||||
SPLITCOLOR15(red, green, blue, pixel);
|
}
|
||||||
pixel = COLOR24BGR(red, green, blue);
|
|
||||||
return pixel;
|
if ((in_bpp == 15) && (out_bpp == 24))
|
||||||
}
|
{
|
||||||
if ((in_bpp == 16) && (out_bpp == 16))
|
pixel = in_color;
|
||||||
{
|
SPLITCOLOR15(red, green, blue, pixel);
|
||||||
return in_color;
|
pixel = COLOR24BGR(red, green, blue);
|
||||||
}
|
return pixel;
|
||||||
if ((in_bpp == 16) && (out_bpp == 24))
|
}
|
||||||
{
|
|
||||||
pixel = in_color;
|
if ((in_bpp == 16) && (out_bpp == 16))
|
||||||
SPLITCOLOR16(red, green, blue, pixel);
|
{
|
||||||
pixel = COLOR24BGR(red, green, blue);
|
return in_color;
|
||||||
return pixel;
|
}
|
||||||
}
|
|
||||||
if ((in_bpp == 24) && (out_bpp == 24))
|
if ((in_bpp == 16) && (out_bpp == 24))
|
||||||
{
|
{
|
||||||
return in_color;
|
pixel = in_color;
|
||||||
}
|
SPLITCOLOR16(red, green, blue, pixel);
|
||||||
if ((in_bpp == 32) && (out_bpp == 24))
|
pixel = COLOR24BGR(red, green, blue);
|
||||||
{
|
return pixel;
|
||||||
return in_color;
|
}
|
||||||
}
|
|
||||||
if ((in_bpp == 32) && (out_bpp == 32))
|
if ((in_bpp == 24) && (out_bpp == 24))
|
||||||
{
|
{
|
||||||
return in_color;
|
return in_color;
|
||||||
}
|
}
|
||||||
if ((in_bpp == 15) && (out_bpp == 15))
|
|
||||||
{
|
if ((in_bpp == 32) && (out_bpp == 24))
|
||||||
return in_color;
|
{
|
||||||
}
|
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 == 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;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-19
@@ -1,22 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2010
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __XRDP_COLOR_H
|
#ifndef __XRDP_COLOR_H
|
||||||
#define __XRDP_COLOR_H
|
#define __XRDP_COLOR_H
|
||||||
|
|||||||
+672
-643
File diff suppressed because it is too large
Load Diff
+19
-21
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2010
|
*
|
||||||
|
* freerdp wrapper
|
||||||
freerdp wrapper
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* include other h files */
|
/* include other h files */
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
|
|||||||
+268
-231
@@ -19,258 +19,295 @@
|
|||||||
|
|
||||||
#include "xrdp-freerdp.h"
|
#include "xrdp-freerdp.h"
|
||||||
|
|
||||||
char* APP_CC
|
char *APP_CC
|
||||||
convert_bitmap(int in_bpp, int out_bpp, char* bmpdata,
|
convert_bitmap(int in_bpp, int out_bpp, char *bmpdata,
|
||||||
int width, int height, int* palette)
|
int width, int height, int *palette)
|
||||||
{
|
{
|
||||||
char* out;
|
char *out;
|
||||||
char* src;
|
char *src;
|
||||||
char* dst;
|
char *dst;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int red;
|
int red;
|
||||||
int green;
|
int green;
|
||||||
int blue;
|
int blue;
|
||||||
int pixel;
|
int pixel;
|
||||||
|
|
||||||
if ((in_bpp == 8) && (out_bpp == 8))
|
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++)
|
out = (char *)g_malloc(width * height, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui8*)src);
|
dst = out;
|
||||||
pixel = palette[pixel];
|
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
for (i = 0; i < height; i++)
|
||||||
pixel = COLOR8(red, green, blue);
|
{
|
||||||
*dst = pixel;
|
for (j = 0; j < width; j++)
|
||||||
src++;
|
{
|
||||||
dst++;
|
pixel = *((tui8 *)src);
|
||||||
}
|
pixel = palette[pixel];
|
||||||
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
|
pixel = COLOR8(red, green, blue);
|
||||||
|
*dst = pixel;
|
||||||
|
src++;
|
||||||
|
dst++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 8) && (out_bpp == 16))
|
||||||
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++)
|
out = (char *)g_malloc(width * height * 2, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui8*)src);
|
dst = out;
|
||||||
pixel = palette[pixel];
|
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
for (i = 0; i < height; i++)
|
||||||
pixel = COLOR16(red, green, blue);
|
{
|
||||||
*((tui16*)dst) = pixel;
|
for (j = 0; j < width; j++)
|
||||||
src++;
|
{
|
||||||
dst += 2;
|
pixel = *((tui8 *)src);
|
||||||
}
|
pixel = palette[pixel];
|
||||||
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
|
pixel = COLOR16(red, green, blue);
|
||||||
|
*((tui16 *)dst) = pixel;
|
||||||
|
src++;
|
||||||
|
dst += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 8) && (out_bpp == 24))
|
||||||
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++)
|
out = (char *)g_malloc(width * height * 4, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui8*)src);
|
dst = out;
|
||||||
pixel = palette[pixel];
|
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
for (i = 0; i < height; i++)
|
||||||
pixel = COLOR24RGB(red, green, blue);
|
{
|
||||||
*((tui32*)dst) = pixel;
|
for (j = 0; j < width; j++)
|
||||||
src++;
|
{
|
||||||
dst += 4;
|
pixel = *((tui8 *)src);
|
||||||
}
|
pixel = palette[pixel];
|
||||||
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
|
pixel = COLOR24RGB(red, green, blue);
|
||||||
|
*((tui32 *)dst) = pixel;
|
||||||
|
src++;
|
||||||
|
dst += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 15) && (out_bpp == 16))
|
||||||
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++)
|
out = (char *)g_malloc(width * height * 2, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui16*)src);
|
dst = out;
|
||||||
SPLITCOLOR15(red, green, blue, pixel);
|
|
||||||
pixel = COLOR16(red, green, blue);
|
for (i = 0; i < height; i++)
|
||||||
*((tui16*)dst) = pixel;
|
{
|
||||||
src += 2;
|
for (j = 0; j < width; j++)
|
||||||
dst += 2;
|
{
|
||||||
}
|
pixel = *((tui16 *)src);
|
||||||
|
SPLITCOLOR15(red, green, blue, pixel);
|
||||||
|
pixel = COLOR16(red, green, blue);
|
||||||
|
*((tui16 *)dst) = pixel;
|
||||||
|
src += 2;
|
||||||
|
dst += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 15) && (out_bpp == 24))
|
||||||
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++)
|
out = (char *)g_malloc(width * height * 4, 0);
|
||||||
{
|
src = bmpdata;
|
||||||
pixel = *((tui16*)src);
|
dst = out;
|
||||||
SPLITCOLOR15(red, green, blue, pixel);
|
|
||||||
pixel = COLOR24RGB(red, green, blue);
|
for (i = 0; i < height; i++)
|
||||||
*((tui32*)dst) = pixel;
|
{
|
||||||
src += 2;
|
for (j = 0; j < width; j++)
|
||||||
dst += 4;
|
{
|
||||||
}
|
pixel = *((tui16 *)src);
|
||||||
|
SPLITCOLOR15(red, green, blue, pixel);
|
||||||
|
pixel = COLOR24RGB(red, green, blue);
|
||||||
|
*((tui32 *)dst) = pixel;
|
||||||
|
src += 2;
|
||||||
|
dst += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
if ((in_bpp == 15) && (out_bpp == 15))
|
||||||
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++)
|
return bmpdata;
|
||||||
{
|
|
||||||
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 == 16) && (out_bpp == 16))
|
||||||
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++)
|
return bmpdata;
|
||||||
{
|
|
||||||
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 == 16) && (out_bpp == 24))
|
||||||
if ((in_bpp == 32) && (out_bpp == 24))
|
{
|
||||||
{
|
out = (char *)g_malloc(width * height * 4, 0);
|
||||||
return bmpdata;
|
src = bmpdata;
|
||||||
}
|
dst = out;
|
||||||
if ((in_bpp == 32) && (out_bpp == 32))
|
|
||||||
{
|
for (i = 0; i < height; i++)
|
||||||
return bmpdata;
|
{
|
||||||
}
|
for (j = 0; j < width; j++)
|
||||||
g_writeln("convert_bitmap: error unknown conversion from %d to %d",
|
{
|
||||||
in_bpp, out_bpp);
|
pixel = *((tui16 *)src);
|
||||||
return 0;
|
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 */
|
/* returns color or 0 */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
convert_color(int in_bpp, int out_bpp, int in_color, int* palette)
|
convert_color(int in_bpp, int out_bpp, int in_color, int *palette)
|
||||||
{
|
{
|
||||||
int pixel;
|
int pixel;
|
||||||
int red;
|
int red;
|
||||||
int green;
|
int green;
|
||||||
int blue;
|
int blue;
|
||||||
|
|
||||||
if ((in_bpp == 1) && (out_bpp == 24))
|
if ((in_bpp == 1) && (out_bpp == 24))
|
||||||
{
|
{
|
||||||
pixel = in_color == 0 ? 0 : 0xffffff;
|
pixel = in_color == 0 ? 0 : 0xffffff;
|
||||||
return pixel;
|
return pixel;
|
||||||
}
|
}
|
||||||
if ((in_bpp == 8) && (out_bpp == 8))
|
|
||||||
{
|
if ((in_bpp == 8) && (out_bpp == 8))
|
||||||
pixel = palette[in_color];
|
{
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
pixel = palette[in_color];
|
||||||
pixel = COLOR8(red, green, blue);
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
return pixel;
|
pixel = COLOR8(red, green, blue);
|
||||||
}
|
return pixel;
|
||||||
if ((in_bpp == 8) && (out_bpp == 16))
|
}
|
||||||
{
|
|
||||||
pixel = palette[in_color];
|
if ((in_bpp == 8) && (out_bpp == 16))
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
{
|
||||||
pixel = COLOR16(red, green, blue);
|
pixel = palette[in_color];
|
||||||
return pixel;
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
}
|
pixel = COLOR16(red, green, blue);
|
||||||
if ((in_bpp == 8) && (out_bpp == 24))
|
return pixel;
|
||||||
{
|
}
|
||||||
pixel = palette[in_color];
|
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
if ((in_bpp == 8) && (out_bpp == 24))
|
||||||
pixel = COLOR24BGR(red, green, blue);
|
{
|
||||||
return pixel;
|
pixel = palette[in_color];
|
||||||
}
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
if ((in_bpp == 15) && (out_bpp == 16))
|
pixel = COLOR24BGR(red, green, blue);
|
||||||
{
|
return pixel;
|
||||||
pixel = in_color;
|
}
|
||||||
SPLITCOLOR15(red, green, blue, pixel);
|
|
||||||
pixel = COLOR16(red, green, blue);
|
if ((in_bpp == 15) && (out_bpp == 16))
|
||||||
return pixel;
|
{
|
||||||
}
|
pixel = in_color;
|
||||||
if ((in_bpp == 15) && (out_bpp == 24))
|
SPLITCOLOR15(red, green, blue, pixel);
|
||||||
{
|
pixel = COLOR16(red, green, blue);
|
||||||
pixel = in_color;
|
return pixel;
|
||||||
SPLITCOLOR15(red, green, blue, pixel);
|
}
|
||||||
pixel = COLOR24BGR(red, green, blue);
|
|
||||||
return pixel;
|
if ((in_bpp == 15) && (out_bpp == 24))
|
||||||
}
|
{
|
||||||
if ((in_bpp == 15) && (out_bpp == 15))
|
pixel = in_color;
|
||||||
{
|
SPLITCOLOR15(red, green, blue, pixel);
|
||||||
return in_color;
|
pixel = COLOR24BGR(red, green, blue);
|
||||||
}
|
return pixel;
|
||||||
if ((in_bpp == 16) && (out_bpp == 16))
|
}
|
||||||
{
|
|
||||||
return in_color;
|
if ((in_bpp == 15) && (out_bpp == 15))
|
||||||
}
|
{
|
||||||
if ((in_bpp == 16) && (out_bpp == 24))
|
return in_color;
|
||||||
{
|
}
|
||||||
pixel = in_color;
|
|
||||||
SPLITCOLOR16(red, green, blue, pixel);
|
if ((in_bpp == 16) && (out_bpp == 16))
|
||||||
pixel = COLOR24BGR(red, green, blue);
|
{
|
||||||
return pixel;
|
return in_color;
|
||||||
}
|
}
|
||||||
if ((in_bpp == 24) && (out_bpp == 24))
|
|
||||||
{
|
if ((in_bpp == 16) && (out_bpp == 24))
|
||||||
return in_color;
|
{
|
||||||
}
|
pixel = in_color;
|
||||||
if ((in_bpp == 32) && (out_bpp == 24))
|
SPLITCOLOR16(red, green, blue, pixel);
|
||||||
{
|
pixel = COLOR24BGR(red, green, blue);
|
||||||
return in_color;
|
return pixel;
|
||||||
}
|
}
|
||||||
if ((in_bpp == 32) && (out_bpp == 32))
|
|
||||||
{
|
if ((in_bpp == 24) && (out_bpp == 24))
|
||||||
return in_color;
|
{
|
||||||
}
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
+1528
-1452
File diff suppressed because it is too large
Load Diff
+81
-69
@@ -41,75 +41,87 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char* programname;
|
const char *programname;
|
||||||
char text[256];
|
char text[256];
|
||||||
char* displayname = NULL;
|
char *displayname = NULL;
|
||||||
char* outfname;
|
char *outfname;
|
||||||
char* sections[5] = {"noshift", "shift", "altgr", "capslock", "shiftcapslock"};
|
char *sections[5] = {"noshift", "shift", "altgr", "capslock", "shiftcapslock"};
|
||||||
int states[5] = {0, 1, 0x80, 2, 3};
|
int states[5] = {0, 1, 0x80, 2, 3};
|
||||||
int i;
|
int i;
|
||||||
int idx;
|
int idx;
|
||||||
int char_count;
|
int char_count;
|
||||||
int nbytes = 0;
|
int nbytes = 0;
|
||||||
int unicode;
|
int unicode;
|
||||||
Display* dpy;
|
Display *dpy;
|
||||||
KeySym ks;
|
KeySym ks;
|
||||||
FILE* outf;
|
FILE *outf;
|
||||||
XKeyPressedEvent e;
|
XKeyPressedEvent e;
|
||||||
wchar_t wtext[256];
|
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 */
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
XCloseDisplay(dpy);
|
||||||
return 1;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+384
-358
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2007-2010
|
*
|
||||||
|
* rsa key generator for xrdp
|
||||||
rsa key generator for xrdp
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
references:
|
references:
|
||||||
@@ -37,74 +35,74 @@
|
|||||||
|
|
||||||
static tui8 g_exponent[4] =
|
static tui8 g_exponent[4] =
|
||||||
{
|
{
|
||||||
0x01, 0x00, 0x01, 0x00
|
0x01, 0x00, 0x01, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
static tui8 g_ppk_e[4] =
|
static tui8 g_ppk_e[4] =
|
||||||
{
|
{
|
||||||
0x5B, 0x7B, 0x88, 0xC0
|
0x5B, 0x7B, 0x88, 0xC0
|
||||||
};
|
};
|
||||||
|
|
||||||
static tui8 g_ppk_n[72] =
|
static tui8 g_ppk_n[72] =
|
||||||
{
|
{
|
||||||
0x3D, 0x3A, 0x5E, 0xBD, 0x72, 0x43, 0x3E, 0xC9,
|
0x3D, 0x3A, 0x5E, 0xBD, 0x72, 0x43, 0x3E, 0xC9,
|
||||||
0x4D, 0xBB, 0xC1, 0x1E, 0x4A, 0xBA, 0x5F, 0xCB,
|
0x4D, 0xBB, 0xC1, 0x1E, 0x4A, 0xBA, 0x5F, 0xCB,
|
||||||
0x3E, 0x88, 0x20, 0x87, 0xEF, 0xF5, 0xC1, 0xE2,
|
0x3E, 0x88, 0x20, 0x87, 0xEF, 0xF5, 0xC1, 0xE2,
|
||||||
0xD7, 0xB7, 0x6B, 0x9A, 0xF2, 0x52, 0x45, 0x95,
|
0xD7, 0xB7, 0x6B, 0x9A, 0xF2, 0x52, 0x45, 0x95,
|
||||||
0xCE, 0x63, 0x65, 0x6B, 0x58, 0x3A, 0xFE, 0xEF,
|
0xCE, 0x63, 0x65, 0x6B, 0x58, 0x3A, 0xFE, 0xEF,
|
||||||
0x7C, 0xE7, 0xBF, 0xFE, 0x3D, 0xF6, 0x5C, 0x7D,
|
0x7C, 0xE7, 0xBF, 0xFE, 0x3D, 0xF6, 0x5C, 0x7D,
|
||||||
0x6C, 0x5E, 0x06, 0x09, 0x1A, 0xF5, 0x61, 0xBB,
|
0x6C, 0x5E, 0x06, 0x09, 0x1A, 0xF5, 0x61, 0xBB,
|
||||||
0x20, 0x93, 0x09, 0x5F, 0x05, 0x6D, 0xEA, 0x87,
|
0x20, 0x93, 0x09, 0x5F, 0x05, 0x6D, 0xEA, 0x87,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
static tui8 g_ppk_d[108] =
|
static tui8 g_ppk_d[108] =
|
||||||
{
|
{
|
||||||
0x87, 0xA7, 0x19, 0x32, 0xDA, 0x11, 0x87, 0x55,
|
0x87, 0xA7, 0x19, 0x32, 0xDA, 0x11, 0x87, 0x55,
|
||||||
0x58, 0x00, 0x16, 0x16, 0x25, 0x65, 0x68, 0xF8,
|
0x58, 0x00, 0x16, 0x16, 0x25, 0x65, 0x68, 0xF8,
|
||||||
0x24, 0x3E, 0xE6, 0xFA, 0xE9, 0x67, 0x49, 0x94,
|
0x24, 0x3E, 0xE6, 0xFA, 0xE9, 0x67, 0x49, 0x94,
|
||||||
0xCF, 0x92, 0xCC, 0x33, 0x99, 0xE8, 0x08, 0x60,
|
0xCF, 0x92, 0xCC, 0x33, 0x99, 0xE8, 0x08, 0x60,
|
||||||
0x17, 0x9A, 0x12, 0x9F, 0x24, 0xDD, 0xB1, 0x24,
|
0x17, 0x9A, 0x12, 0x9F, 0x24, 0xDD, 0xB1, 0x24,
|
||||||
0x99, 0xC7, 0x3A, 0xB8, 0x0A, 0x7B, 0x0D, 0xDD,
|
0x99, 0xC7, 0x3A, 0xB8, 0x0A, 0x7B, 0x0D, 0xDD,
|
||||||
0x35, 0x07, 0x79, 0x17, 0x0B, 0x51, 0x9B, 0xB3,
|
0x35, 0x07, 0x79, 0x17, 0x0B, 0x51, 0x9B, 0xB3,
|
||||||
0xC7, 0x10, 0x01, 0x13, 0xE7, 0x3F, 0xF3, 0x5F,
|
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, 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] =
|
static tui8 g_testkey[176] =
|
||||||
{
|
{
|
||||||
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5c, 0x00,
|
0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5c, 0x00,
|
||||||
0x52, 0x53, 0x41, 0x31, 0x48, 0x00, 0x00, 0x00,
|
0x52, 0x53, 0x41, 0x31, 0x48, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x02, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,
|
0x00, 0x02, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,
|
||||||
0x01, 0x00, 0x01, 0x00, 0x79, 0x6f, 0xb4, 0xdf,
|
0x01, 0x00, 0x01, 0x00, 0x79, 0x6f, 0xb4, 0xdf,
|
||||||
0xa6, 0x95, 0xb9, 0xa9, 0x61, 0xe3, 0xc4, 0x5e,
|
0xa6, 0x95, 0xb9, 0xa9, 0x61, 0xe3, 0xc4, 0x5e,
|
||||||
0xff, 0x6b, 0xd8, 0x81, 0x8a, 0x12, 0x4a, 0x93,
|
0xff, 0x6b, 0xd8, 0x81, 0x8a, 0x12, 0x4a, 0x93,
|
||||||
0x42, 0x97, 0x18, 0x93, 0xac, 0xd1, 0x3a, 0x38,
|
0x42, 0x97, 0x18, 0x93, 0xac, 0xd1, 0x3a, 0x38,
|
||||||
0x3c, 0x68, 0x50, 0x19, 0x31, 0xb6, 0x84, 0x51,
|
0x3c, 0x68, 0x50, 0x19, 0x31, 0xb6, 0x84, 0x51,
|
||||||
0x79, 0xfb, 0x1c, 0xe7, 0xe3, 0x99, 0x20, 0xc7,
|
0x79, 0xfb, 0x1c, 0xe7, 0xe3, 0x99, 0x20, 0xc7,
|
||||||
0x84, 0xdf, 0xd1, 0xaa, 0xb5, 0x15, 0xef, 0x47,
|
0x84, 0xdf, 0xd1, 0xaa, 0xb5, 0x15, 0xef, 0x47,
|
||||||
0x7e, 0xfc, 0x88, 0xeb, 0x29, 0xc3, 0x27, 0x5a,
|
0x7e, 0xfc, 0x88, 0xeb, 0x29, 0xc3, 0x27, 0x5a,
|
||||||
0x35, 0xf8, 0xfd, 0xaa, 0x00, 0x00, 0x00, 0x00,
|
0x35, 0xf8, 0xfd, 0xaa, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00,
|
||||||
0x08, 0x00, 0x48, 0x00,
|
0x08, 0x00, 0x48, 0x00,
|
||||||
0x32, 0x3b, 0xde, 0x6f, 0x18, 0x97, 0x1e, 0xc3,
|
0x32, 0x3b, 0xde, 0x6f, 0x18, 0x97, 0x1e, 0xc3,
|
||||||
0x6b, 0x2b, 0x2d, 0xe4, 0xfc, 0x2d, 0xa2, 0x8e,
|
0x6b, 0x2b, 0x2d, 0xe4, 0xfc, 0x2d, 0xa2, 0x8e,
|
||||||
0x32, 0x3c, 0xf3, 0x1b, 0x24, 0x90, 0x57, 0x4d,
|
0x32, 0x3c, 0xf3, 0x1b, 0x24, 0x90, 0x57, 0x4d,
|
||||||
0x8e, 0xe4, 0x69, 0xfc, 0x16, 0x8d, 0x41, 0x92,
|
0x8e, 0xe4, 0x69, 0xfc, 0x16, 0x8d, 0x41, 0x92,
|
||||||
0x78, 0xc7, 0x9c, 0xb4, 0x26, 0xff, 0xe8, 0x3e,
|
0x78, 0xc7, 0x9c, 0xb4, 0x26, 0xff, 0xe8, 0x3e,
|
||||||
0xa1, 0x8a, 0xf5, 0x57, 0xc0, 0x7f, 0x3e, 0x21,
|
0xa1, 0x8a, 0xf5, 0x57, 0xc0, 0x7f, 0x3e, 0x21,
|
||||||
0x17, 0x32, 0x30, 0x6f, 0x79, 0xe1, 0x36, 0xcd,
|
0x17, 0x32, 0x30, 0x6f, 0x79, 0xe1, 0x36, 0xcd,
|
||||||
0xb6, 0x8e, 0xbe, 0x57, 0x57, 0xd2, 0xa9, 0x36
|
0xb6, 0x8e, 0xbe, 0x57, 0x57, 0xd2, 0xa9, 0x36
|
||||||
};
|
};
|
||||||
|
|
||||||
/* this is the installed signature */
|
/* 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,\
|
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,\
|
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,\
|
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
|
static int APP_CC
|
||||||
out_params(void)
|
out_params(void)
|
||||||
{
|
{
|
||||||
g_writeln("");
|
g_writeln("");
|
||||||
g_writeln("xrdp rsa key gen utility examples");
|
g_writeln("xrdp rsa key gen utility examples");
|
||||||
g_writeln(" xrdp-keygen xrdp ['path and file name' | auto]");
|
g_writeln(" xrdp-keygen xrdp ['path and file name' | auto]");
|
||||||
g_writeln(" xrdp-keygen test");
|
g_writeln(" xrdp-keygen test");
|
||||||
g_writeln("");
|
g_writeln("");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* this is the special key signing algorithm */
|
/* this is the special key signing algorithm */
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
sign_key(char* e_data, int e_len, char* n_data, int n_len,
|
sign_key(char *e_data, int e_len, char *n_data, int n_len,
|
||||||
char* sign_data, int sign_len)
|
char *sign_data, int sign_len)
|
||||||
{
|
{
|
||||||
char* key;
|
char *key;
|
||||||
char* md5_final;
|
char *md5_final;
|
||||||
void* md5;
|
void *md5;
|
||||||
|
|
||||||
if ((e_len != 4) || (n_len != 64) || (sign_len != 64))
|
if ((e_len != 4) || (n_len != 64) || (sign_len != 64))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
key = (char*)g_malloc(176, 0);
|
|
||||||
md5_final = (char*)g_malloc(64, 0);
|
key = (char *)g_malloc(176, 0);
|
||||||
md5 = ssl_md5_info_create();
|
md5_final = (char *)g_malloc(64, 0);
|
||||||
/* copy the test key */
|
md5 = ssl_md5_info_create();
|
||||||
g_memcpy(key, g_testkey, 176);
|
/* copy the test key */
|
||||||
/* replace e and n */
|
g_memcpy(key, g_testkey, 176);
|
||||||
g_memcpy(key + 32, e_data, 4);
|
/* replace e and n */
|
||||||
g_memcpy(key + 36, n_data, 64);
|
g_memcpy(key + 32, e_data, 4);
|
||||||
ssl_md5_clear(md5);
|
g_memcpy(key + 36, n_data, 64);
|
||||||
/* the first 108 bytes */
|
ssl_md5_clear(md5);
|
||||||
ssl_md5_transform(md5, key, 108);
|
/* the first 108 bytes */
|
||||||
/* set the whole thing with 0xff */
|
ssl_md5_transform(md5, key, 108);
|
||||||
g_memset(md5_final, 0xff, 64);
|
/* set the whole thing with 0xff */
|
||||||
/* digest 16 bytes */
|
g_memset(md5_final, 0xff, 64);
|
||||||
ssl_md5_complete(md5, md5_final);
|
/* digest 16 bytes */
|
||||||
/* set non 0xff array items */
|
ssl_md5_complete(md5, md5_final);
|
||||||
md5_final[16] = 0;
|
/* set non 0xff array items */
|
||||||
md5_final[62] = 1;
|
md5_final[16] = 0;
|
||||||
md5_final[63] = 0;
|
md5_final[62] = 1;
|
||||||
/* encrypt */
|
md5_final[63] = 0;
|
||||||
ssl_mod_exp(sign_data, 64, md5_final, 64, (char*)g_ppk_n, 64,
|
/* encrypt */
|
||||||
(char*)g_ppk_d, 64);
|
ssl_mod_exp(sign_data, 64, md5_final, 64, (char *)g_ppk_n, 64,
|
||||||
/* cleanup */
|
(char *)g_ppk_d, 64);
|
||||||
ssl_md5_info_delete(md5);
|
/* cleanup */
|
||||||
g_free(key);
|
ssl_md5_info_delete(md5);
|
||||||
g_free(md5_final);
|
g_free(key);
|
||||||
return 0;
|
g_free(md5_final);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
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 max;
|
||||||
int error;
|
int error;
|
||||||
int index;
|
int index;
|
||||||
int data_item;
|
int data_item;
|
||||||
int buf_pos;
|
int buf_pos;
|
||||||
char* buf;
|
char *buf;
|
||||||
char* text;
|
char *text;
|
||||||
|
|
||||||
text = (char*)g_malloc(256, 0);
|
text = (char *)g_malloc(256, 0);
|
||||||
max = len;
|
max = len;
|
||||||
max = max * 10;
|
max = max * 10;
|
||||||
buf_pos = g_strlen(name);
|
buf_pos = g_strlen(name);
|
||||||
max = max + buf_pos + 16;
|
max = max + buf_pos + 16;
|
||||||
buf = (char*)g_malloc(max, 0);
|
buf = (char *)g_malloc(max, 0);
|
||||||
g_strncpy(buf, name, max - 1);
|
g_strncpy(buf, name, max - 1);
|
||||||
buf[buf_pos] = '=';
|
buf[buf_pos] = '=';
|
||||||
buf_pos++;
|
buf_pos++;
|
||||||
for (index = 0; index < len; index++)
|
|
||||||
{
|
for (index = 0; index < len; index++)
|
||||||
data_item = (tui8)(data[index]);
|
|
||||||
g_snprintf(text, 255, "0x%2.2x", data_item);
|
|
||||||
if (index != 0)
|
|
||||||
{
|
{
|
||||||
buf[buf_pos] = ',';
|
data_item = (tui8)(data[index]);
|
||||||
buf_pos++;
|
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[buf_pos] = '\n';
|
||||||
buf_pos++;
|
buf_pos++;
|
||||||
buf[buf_pos] = text[1];
|
buf[buf_pos] = 0;
|
||||||
buf_pos++;
|
error = g_file_write(fd, buf, buf_pos) == -1;
|
||||||
buf[buf_pos] = text[2];
|
g_free(buf);
|
||||||
buf_pos++;
|
g_free(text);
|
||||||
buf[buf_pos] = text[3];
|
return error;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
save_all(char* e_data, int e_len, char* n_data, int n_len,
|
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,
|
char *d_data, int d_len, char *sign_data, int sign_len,
|
||||||
const char* path_and_file_name)
|
const char *path_and_file_name)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char filename[256];
|
char filename[256];
|
||||||
|
|
||||||
if (path_and_file_name == 0)
|
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)
|
|
||||||
{
|
{
|
||||||
g_writeln("problem deleting %s, maybe no rights", filename);
|
g_strncpy(filename, "rsakeys.ini", 255);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
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);
|
g_strncpy(filename, path_and_file_name, 255);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
g_writeln("saving to %s", filename);
|
||||||
static int APP_CC
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
g_writeln("error %d in key_gen, ssl_gen_key_xrdp1", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (error == 0)
|
|
||||||
{
|
|
||||||
g_writeln("ssl_gen_key_xrdp1 ok");
|
|
||||||
g_writeln("");
|
g_writeln("");
|
||||||
error = sign_key(e_data, e_len, n_data, n_len, sign_data, sign_len);
|
|
||||||
if (error != 0)
|
if (g_file_exist(filename))
|
||||||
{
|
{
|
||||||
g_writeln("error %d in key_gen, sign_key", error);
|
if (g_file_delete(filename) == 0)
|
||||||
|
{
|
||||||
|
g_writeln("problem deleting %s, maybe no rights", filename);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (error == 0)
|
fd = g_file_open(filename);
|
||||||
{
|
|
||||||
error = save_all(e_data, e_len, n_data, n_len, d_data, d_len,
|
if (fd > 0)
|
||||||
sign_data, sign_len, path_and_file_name);
|
|
||||||
if (error != 0)
|
|
||||||
{
|
{
|
||||||
g_writeln("error %d in key_gen, save_all", error);
|
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_free(n_data);
|
{
|
||||||
g_free(d_data);
|
g_writeln("problem opening %s, maybe no rights", filename);
|
||||||
g_free(sign_data);
|
return 1;
|
||||||
return error;
|
}
|
||||||
|
|
||||||
|
g_file_close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
g_writeln("error %d in key_gen, save_all", 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
|
static int APP_CC
|
||||||
key_gen_run_it(void)
|
key_gen_run_it(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int index;
|
int index;
|
||||||
int rv;
|
int rv;
|
||||||
struct list* names;
|
struct list *names;
|
||||||
struct list* values;
|
struct list *values;
|
||||||
char* name;
|
char *name;
|
||||||
char* value;
|
char *value;
|
||||||
|
|
||||||
if (!g_file_exist("/etc/xrdp/rsakeys.ini"))
|
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++)
|
|
||||||
{
|
{
|
||||||
name = (char*)list_get_item(names, index);
|
return 1;
|
||||||
value = (char*)list_get_item(values, index);
|
|
||||||
if (g_strcasecmp(name, "pub_sig") == 0)
|
|
||||||
{
|
|
||||||
if (g_strcasecmp(value, inst_pub_sig) == 0)
|
|
||||||
{
|
|
||||||
rv = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
if (g_file_get_size("/etc/xrdp/rsakeys.ini") < 10)
|
||||||
{
|
{
|
||||||
g_writeln("error reading keys section of rsakeys.ini");
|
return 1;
|
||||||
}
|
}
|
||||||
list_delete(names);
|
|
||||||
list_delete(values);
|
fd = g_file_open("/etc/xrdp/rsakeys.ini");
|
||||||
g_file_close(fd);
|
|
||||||
return rv;
|
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++)
|
||||||
|
{
|
||||||
|
name = (char *)list_get_item(names, index);
|
||||||
|
value = (char *)list_get_item(values, index);
|
||||||
|
|
||||||
|
if (g_strcasecmp(name, "pub_sig") == 0)
|
||||||
|
{
|
||||||
|
if (g_strcasecmp(value, inst_pub_sig) == 0)
|
||||||
|
{
|
||||||
|
rv = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_writeln("error reading keys section of rsakeys.ini");
|
||||||
|
}
|
||||||
|
|
||||||
|
list_delete(names);
|
||||||
|
list_delete(values);
|
||||||
|
g_file_close(fd);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
key_gen_auto(void)
|
key_gen_auto(void)
|
||||||
{
|
{
|
||||||
if (key_gen_run_it())
|
if (key_gen_run_it())
|
||||||
{
|
{
|
||||||
return key_gen("/etc/xrdp/rsakeys.ini");
|
return key_gen("/etc/xrdp/rsakeys.ini");
|
||||||
}
|
}
|
||||||
g_writeln("xrdp-keygen does not need to run");
|
|
||||||
return 0;
|
g_writeln("xrdp-keygen does not need to run");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
key_test(void)
|
key_test(void)
|
||||||
{
|
{
|
||||||
char* md5_final;
|
char *md5_final;
|
||||||
char* sig;
|
char *sig;
|
||||||
void* md5;
|
void *md5;
|
||||||
|
|
||||||
md5_final = (char*)g_malloc(64, 0);
|
md5_final = (char *)g_malloc(64, 0);
|
||||||
sig = (char*)g_malloc(64, 0);
|
sig = (char *)g_malloc(64, 0);
|
||||||
md5 = ssl_md5_info_create();
|
md5 = ssl_md5_info_create();
|
||||||
g_writeln("original key is:");
|
g_writeln("original key is:");
|
||||||
g_hexdump((char*)g_testkey, 176);
|
g_hexdump((char *)g_testkey, 176);
|
||||||
g_writeln("original exponent is:");
|
g_writeln("original exponent is:");
|
||||||
g_hexdump((char*)g_testkey + 32, 4);
|
g_hexdump((char *)g_testkey + 32, 4);
|
||||||
g_writeln("original modulus is:");
|
g_writeln("original modulus is:");
|
||||||
g_hexdump((char*)g_testkey + 36, 64);
|
g_hexdump((char *)g_testkey + 36, 64);
|
||||||
g_writeln("original signature is:");
|
g_writeln("original signature is:");
|
||||||
g_hexdump((char*)g_testkey + 112, 64);
|
g_hexdump((char *)g_testkey + 112, 64);
|
||||||
ssl_md5_clear(md5);
|
ssl_md5_clear(md5);
|
||||||
ssl_md5_transform(md5, (char*)g_testkey, 108);
|
ssl_md5_transform(md5, (char *)g_testkey, 108);
|
||||||
g_memset(md5_final, 0xff, 64);
|
g_memset(md5_final, 0xff, 64);
|
||||||
ssl_md5_complete(md5, md5_final);
|
ssl_md5_complete(md5, md5_final);
|
||||||
g_writeln("md5 hash of first 108 bytes of this key is:");
|
g_writeln("md5 hash of first 108 bytes of this key is:");
|
||||||
g_hexdump(md5_final, 16);
|
g_hexdump(md5_final, 16);
|
||||||
md5_final[16] = 0;
|
md5_final[16] = 0;
|
||||||
md5_final[62] = 1;
|
md5_final[62] = 1;
|
||||||
md5_final[63] = 0;
|
md5_final[63] = 0;
|
||||||
ssl_mod_exp(sig, 64, md5_final, 64, (char*)g_ppk_n, 64, (char*)g_ppk_d, 64);
|
ssl_mod_exp(sig, 64, md5_final, 64, (char *)g_ppk_n, 64, (char *)g_ppk_d, 64);
|
||||||
g_writeln("produced signature(this should match original \
|
g_writeln("produced signature(this should match original \
|
||||||
signature above) is:");
|
signature above) is:");
|
||||||
g_hexdump(sig, 64);
|
g_hexdump(sig, 64);
|
||||||
g_memset(md5_final, 0, 64);
|
g_memset(md5_final, 0, 64);
|
||||||
ssl_mod_exp(md5_final, 64, (char*)g_testkey + 112, 64, (char*)g_ppk_n, 64,
|
ssl_mod_exp(md5_final, 64, (char *)g_testkey + 112, 64, (char *)g_ppk_n, 64,
|
||||||
(char*)g_ppk_e, 4);
|
(char *)g_ppk_e, 4);
|
||||||
g_writeln("decrypted hash of first 108 bytes of this key is:");
|
g_writeln("decrypted hash of first 108 bytes of this key is:");
|
||||||
g_hexdump(md5_final, 64);
|
g_hexdump(md5_final, 64);
|
||||||
ssl_md5_info_delete(md5);
|
ssl_md5_info_delete(md5);
|
||||||
g_free(md5_final);
|
g_free(md5_final);
|
||||||
g_free(sig);
|
g_free(sig);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
main(int argc, char** argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
|
||||||
if (g_strcasecmp(argv[1], "xrdp") == 0)
|
|
||||||
{
|
{
|
||||||
if (argc > 2)
|
if (g_strcasecmp(argv[1], "xrdp") == 0)
|
||||||
{
|
|
||||||
if (g_strcasecmp(argv[2], "auto") == 0)
|
|
||||||
{
|
{
|
||||||
if (g_getuid() != 0)
|
if (argc > 2)
|
||||||
{
|
{
|
||||||
g_writeln("must run as root");
|
if (g_strcasecmp(argv[2], "auto") == 0)
|
||||||
return 0;
|
{
|
||||||
}
|
if (g_getuid() != 0)
|
||||||
return key_gen_auto();
|
{
|
||||||
|
g_writeln("must run as root");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return key_gen_auto();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return key_gen(argv[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return key_gen(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (g_strcasecmp(argv[1], "test") == 0)
|
||||||
{
|
{
|
||||||
return key_gen(argv[2]);
|
return key_test();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return key_gen(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (g_strcasecmp(argv[1], "test") == 0)
|
|
||||||
{
|
out_params();
|
||||||
return key_test();
|
return 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
out_params();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+680
-615
File diff suppressed because it is too large
Load Diff
+19
-21
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2010
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2004-2010
|
*
|
||||||
|
* libxrdp header
|
||||||
libxrdp header
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(LIBXRDP_H)
|
#if !defined(LIBXRDP_H)
|
||||||
#define LIBXRDP_H
|
#define LIBXRDP_H
|
||||||
|
|||||||
+19
-21
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2010
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2004-2010
|
*
|
||||||
|
* header file for use with libxrdp.so / xrdp.dll
|
||||||
header file for use with libxrdp.so / xrdp.dll
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBXRDPINC_H
|
#ifndef LIBXRDPINC_H
|
||||||
#define LIBXRDPINC_H
|
#define LIBXRDPINC_H
|
||||||
|
|||||||
+1356
-1260
File diff suppressed because it is too large
Load Diff
+129
-117
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2006-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2006-2010
|
*
|
||||||
|
* channel layer
|
||||||
channel layer
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libxrdp.h"
|
#include "libxrdp.h"
|
||||||
|
|
||||||
@@ -31,86 +29,96 @@
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns pointer or nil on error */
|
/* returns pointer or nil on error */
|
||||||
static struct mcs_channel_item* APP_CC
|
static struct mcs_channel_item *APP_CC
|
||||||
xrdp_channel_get_item(struct xrdp_channel* self, int channel_id)
|
xrdp_channel_get_item(struct xrdp_channel *self, int channel_id)
|
||||||
{
|
{
|
||||||
struct mcs_channel_item* channel;
|
struct mcs_channel_item *channel;
|
||||||
if(self->mcs_layer->channel_list==NULL)
|
|
||||||
{
|
if (self->mcs_layer->channel_list == NULL)
|
||||||
g_writeln("xrdp_channel_get_item - No channel initialized");
|
{
|
||||||
return NULL ;
|
g_writeln("xrdp_channel_get_item - No channel initialized");
|
||||||
}
|
return NULL ;
|
||||||
channel = (struct mcs_channel_item*)
|
}
|
||||||
list_get_item(self->mcs_layer->channel_list, channel_id);
|
|
||||||
return channel;
|
channel = (struct mcs_channel_item *)
|
||||||
|
list_get_item(self->mcs_layer->channel_list, channel_id);
|
||||||
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct xrdp_channel* APP_CC
|
struct xrdp_channel *APP_CC
|
||||||
xrdp_channel_create(struct xrdp_sec* owner, struct xrdp_mcs* mcs_layer)
|
xrdp_channel_create(struct xrdp_sec *owner, struct xrdp_mcs *mcs_layer)
|
||||||
{
|
{
|
||||||
struct xrdp_channel* self;
|
struct xrdp_channel *self;
|
||||||
|
|
||||||
self = (struct xrdp_channel*)g_malloc(sizeof(struct xrdp_channel), 1);
|
self = (struct xrdp_channel *)g_malloc(sizeof(struct xrdp_channel), 1);
|
||||||
self->sec_layer = owner;
|
self->sec_layer = owner;
|
||||||
self->mcs_layer = mcs_layer;
|
self->mcs_layer = mcs_layer;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
void APP_CC
|
void APP_CC
|
||||||
xrdp_channel_delete(struct xrdp_channel* self)
|
xrdp_channel_delete(struct xrdp_channel *self)
|
||||||
{
|
{
|
||||||
if (self == 0)
|
if (self == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g_memset(self,0,sizeof(struct xrdp_channel));
|
|
||||||
g_free(self);
|
g_memset(self, 0, sizeof(struct xrdp_channel));
|
||||||
|
g_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_channel_init(struct xrdp_channel* self, struct stream* s)
|
xrdp_channel_init(struct xrdp_channel *self, struct stream *s)
|
||||||
{
|
{
|
||||||
if (xrdp_sec_init(self->sec_layer, s) != 0)
|
if (xrdp_sec_init(self->sec_layer, s) != 0)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
s_push_layer(s, channel_hdr, 8);
|
|
||||||
return 0;
|
s_push_layer(s, channel_hdr, 8);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
/* This sends data out to the secure layer. */
|
/* This sends data out to the secure layer. */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_channel_send(struct xrdp_channel* self, struct stream* s, int channel_id,
|
xrdp_channel_send(struct xrdp_channel *self, struct stream *s, int channel_id,
|
||||||
int total_data_len, int flags)
|
int total_data_len, int flags)
|
||||||
{
|
{
|
||||||
struct mcs_channel_item* channel;
|
struct mcs_channel_item *channel;
|
||||||
|
|
||||||
channel = xrdp_channel_get_item(self, channel_id);
|
channel = xrdp_channel_get_item(self, channel_id);
|
||||||
if (channel == NULL)
|
|
||||||
{
|
if (channel == NULL)
|
||||||
g_writeln("xrdp_channel_send - no such channel");
|
{
|
||||||
return 1;
|
g_writeln("xrdp_channel_send - no such channel");
|
||||||
}
|
return 1;
|
||||||
s_pop_layer(s, channel_hdr);
|
}
|
||||||
out_uint32_le(s, total_data_len);
|
|
||||||
if (channel->flags & XR_CHANNEL_OPTION_SHOW_PROTOCOL)
|
s_pop_layer(s, channel_hdr);
|
||||||
{
|
out_uint32_le(s, total_data_len);
|
||||||
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
|
|
||||||
}
|
if (channel->flags & XR_CHANNEL_OPTION_SHOW_PROTOCOL)
|
||||||
out_uint32_le(s, flags);
|
{
|
||||||
if (xrdp_sec_send(self->sec_layer, s, channel->chanid) != 0)
|
flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
|
||||||
{
|
}
|
||||||
g_writeln("xrdp_channel_send - failure sending data");
|
|
||||||
return 1;
|
out_uint32_le(s, flags);
|
||||||
}
|
|
||||||
return 0;
|
if (xrdp_sec_send(self->sec_layer, s, channel->chanid) != 0)
|
||||||
|
{
|
||||||
|
g_writeln("xrdp_channel_send - failure sending data");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -118,36 +126,38 @@ xrdp_channel_send(struct xrdp_channel* self, struct stream* s, int channel_id,
|
|||||||
/* this will inform the callback, whatever it is that some channel data is
|
/* this will inform the callback, whatever it is that some channel data is
|
||||||
ready. the default for this is a call to xrdp_wm.c. */
|
ready. the default for this is a call to xrdp_wm.c. */
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
xrdp_channel_call_callback(struct xrdp_channel* self, struct stream* s,
|
xrdp_channel_call_callback(struct xrdp_channel *self, struct stream *s,
|
||||||
int channel_id,
|
int channel_id,
|
||||||
int total_data_len, int flags)
|
int total_data_len, int flags)
|
||||||
{
|
{
|
||||||
struct xrdp_session* session;
|
struct xrdp_session *session;
|
||||||
int rv;
|
int rv;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
rv = 0;
|
rv = 0;
|
||||||
session = self->sec_layer->rdp_layer->session;
|
session = self->sec_layer->rdp_layer->session;
|
||||||
if (session != 0)
|
|
||||||
{
|
if (session != 0)
|
||||||
if (session->callback != 0)
|
|
||||||
{
|
{
|
||||||
size = (int)(s->end - s->p);
|
if (session->callback != 0)
|
||||||
/* in xrdp_wm.c */
|
{
|
||||||
rv = session->callback(session->id, 0x5555,
|
size = (int)(s->end - s->p);
|
||||||
MAKELONG(channel_id, flags),
|
/* in xrdp_wm.c */
|
||||||
size, (tbus)(s->p), total_data_len);
|
rv = session->callback(session->id, 0x5555,
|
||||||
|
MAKELONG(channel_id, flags),
|
||||||
|
size, (tbus)(s->p), total_data_len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_writeln("in xrdp_channel_call_callback, session->callback is nil");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_writeln("in xrdp_channel_call_callback, session->callback is nil");
|
g_writeln("in xrdp_channel_call_callback, session is nil");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
return rv;
|
||||||
{
|
|
||||||
g_writeln("in xrdp_channel_call_callback, session is nil");
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -157,30 +167,32 @@ xrdp_channel_call_callback(struct xrdp_channel* self, struct stream* s,
|
|||||||
'chanid' passed in here is the mcs channel id so it MCS_GLOBAL_CHANNEL
|
'chanid' passed in here is the mcs channel id so it MCS_GLOBAL_CHANNEL
|
||||||
plus something. */
|
plus something. */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_channel_process(struct xrdp_channel* self, struct stream* s,
|
xrdp_channel_process(struct xrdp_channel *self, struct stream *s,
|
||||||
int chanid)
|
int chanid)
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
int flags;
|
int flags;
|
||||||
int rv;
|
int rv;
|
||||||
int channel_id;
|
int channel_id;
|
||||||
struct mcs_channel_item* channel;
|
struct mcs_channel_item *channel;
|
||||||
|
|
||||||
|
|
||||||
/* this assumes that the channels are in order of chanid(mcs channel id)
|
/* this assumes that the channels are in order of chanid(mcs channel id)
|
||||||
but they should be, see xrdp_sec_process_mcs_data_channels
|
but they should be, see xrdp_sec_process_mcs_data_channels
|
||||||
the first channel should be MCS_GLOBAL_CHANNEL + 1, second
|
the first channel should be MCS_GLOBAL_CHANNEL + 1, second
|
||||||
one should be MCS_GLOBAL_CHANNEL + 2, and so on */
|
one should be MCS_GLOBAL_CHANNEL + 2, and so on */
|
||||||
channel_id = (chanid - MCS_GLOBAL_CHANNEL) - 1;
|
channel_id = (chanid - MCS_GLOBAL_CHANNEL) - 1;
|
||||||
channel = xrdp_channel_get_item(self, channel_id);
|
channel = xrdp_channel_get_item(self, channel_id);
|
||||||
if (channel == NULL)
|
|
||||||
{
|
if (channel == NULL)
|
||||||
g_writeln("xrdp_channel_process, channel not found");
|
{
|
||||||
return 1;
|
g_writeln("xrdp_channel_process, channel not found");
|
||||||
}
|
return 1;
|
||||||
rv = 0;
|
}
|
||||||
in_uint32_le(s, length);
|
|
||||||
in_uint32_le(s, flags);
|
rv = 0;
|
||||||
rv = xrdp_channel_call_callback(self, s, channel_id, length, flags);
|
in_uint32_le(s, length);
|
||||||
return rv;
|
in_uint32_le(s, flags);
|
||||||
|
rv = xrdp_channel_call_callback(self, s, channel_id, length, flags);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
+147
-134
@@ -20,177 +20,190 @@
|
|||||||
#include "libxrdp.h"
|
#include "libxrdp.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct xrdp_fastpath* APP_CC
|
struct xrdp_fastpath *APP_CC
|
||||||
xrdp_fastpath_create(struct xrdp_session* session)
|
xrdp_fastpath_create(struct xrdp_session *session)
|
||||||
{
|
{
|
||||||
struct xrdp_fastpath* self;
|
struct xrdp_fastpath *self;
|
||||||
|
|
||||||
self = (struct xrdp_fastpath*)g_malloc(sizeof(struct xrdp_fastpath), 1);
|
self = (struct xrdp_fastpath *)g_malloc(sizeof(struct xrdp_fastpath), 1);
|
||||||
self->tcp_layer =
|
self->tcp_layer =
|
||||||
((struct xrdp_rdp*)session->rdp)->sec_layer->
|
((struct xrdp_rdp *)session->rdp)->sec_layer->
|
||||||
mcs_layer->iso_layer->tcp_layer;
|
mcs_layer->iso_layer->tcp_layer;
|
||||||
make_stream(self->out_s);
|
make_stream(self->out_s);
|
||||||
init_stream(self->out_s, FASTPATH_MAX_PACKET_SIZE);
|
init_stream(self->out_s, FASTPATH_MAX_PACKET_SIZE);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
xrdp_fastpath_delete(struct xrdp_fastpath* self)
|
xrdp_fastpath_delete(struct xrdp_fastpath *self)
|
||||||
{
|
{
|
||||||
if (self == 0)
|
if (self == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
free_stream(self->out_s);
|
|
||||||
g_free(self);
|
free_stream(self->out_s);
|
||||||
|
g_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_fastpath_reset(struct xrdp_fastpath* self)
|
xrdp_fastpath_reset(struct xrdp_fastpath *self)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_fastpath_init(struct xrdp_fastpath* self)
|
xrdp_fastpath_init(struct xrdp_fastpath *self)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_fastpath_send_update_pdu(struct xrdp_fastpath* self, tui8 updateCode,
|
xrdp_fastpath_send_update_pdu(struct xrdp_fastpath *self, tui8 updateCode,
|
||||||
struct stream* s)
|
struct stream *s)
|
||||||
{
|
{
|
||||||
tui16 len;
|
tui16 len;
|
||||||
tui16 maxLen;
|
tui16 maxLen;
|
||||||
tui32 payloadLeft;
|
tui32 payloadLeft;
|
||||||
tui8 fragment;
|
tui8 fragment;
|
||||||
struct stream* s_send;
|
struct stream *s_send;
|
||||||
int compression;
|
int compression;
|
||||||
int i;
|
int i;
|
||||||
int i32;
|
int i32;
|
||||||
|
|
||||||
compression = 0;
|
compression = 0;
|
||||||
s_send = self->out_s;
|
s_send = self->out_s;
|
||||||
maxLen = FASTPATH_MAX_PACKET_SIZE - 6; /* 6 bytes for header */
|
maxLen = FASTPATH_MAX_PACKET_SIZE - 6; /* 6 bytes for header */
|
||||||
payloadLeft = (s->end - s->data);
|
payloadLeft = (s->end - s->data);
|
||||||
for (i = 0; payloadLeft > 0; i++)
|
|
||||||
{
|
for (i = 0; payloadLeft > 0; i++)
|
||||||
if (payloadLeft > maxLen)
|
|
||||||
{
|
{
|
||||||
len = maxLen;
|
if (payloadLeft > maxLen)
|
||||||
|
{
|
||||||
|
len = maxLen;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = payloadLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadLeft -= len;
|
||||||
|
|
||||||
|
if (payloadLeft == 0)
|
||||||
|
{
|
||||||
|
fragment = i ? FASTPATH_FRAGMENT_LAST : FASTPATH_FRAGMENT_SINGLE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fragment = i ? FASTPATH_FRAGMENT_NEXT : FASTPATH_FRAGMENT_FIRST;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_stream(s_send, 0);
|
||||||
|
out_uint8(s_send, 0); /* fOutputHeader */
|
||||||
|
i32 = ((len + 6) >> 8) | 0x80;
|
||||||
|
out_uint8(s_send, i32); /* use 2 bytes for length even length < 128 ??? */
|
||||||
|
i32 = (len + 6) & 0xff;
|
||||||
|
out_uint8(s_send, i32);
|
||||||
|
i32 = (updateCode & 0x0f) | ((fragment & 0x03) << 4) |
|
||||||
|
((compression & 0x03) << 6);
|
||||||
|
out_uint8(s_send, i32);
|
||||||
|
out_uint16_le(s_send, len);
|
||||||
|
s_copy(s_send, s, len);
|
||||||
|
s_mark_end(s_send);
|
||||||
|
|
||||||
|
if (xrdp_tcp_send(self->tcp_layer, s_send) != 0)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return 0;
|
||||||
len = payloadLeft;
|
|
||||||
}
|
|
||||||
payloadLeft -= len;
|
|
||||||
if (payloadLeft == 0)
|
|
||||||
{
|
|
||||||
fragment = i ? FASTPATH_FRAGMENT_LAST : FASTPATH_FRAGMENT_SINGLE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fragment = i ? FASTPATH_FRAGMENT_NEXT : FASTPATH_FRAGMENT_FIRST;
|
|
||||||
}
|
|
||||||
init_stream(s_send, 0);
|
|
||||||
out_uint8(s_send, 0); /* fOutputHeader */
|
|
||||||
i32 = ((len + 6) >> 8) | 0x80;
|
|
||||||
out_uint8(s_send, i32); /* use 2 bytes for length even length < 128 ??? */
|
|
||||||
i32 = (len + 6) & 0xff;
|
|
||||||
out_uint8(s_send, i32);
|
|
||||||
i32 = (updateCode & 0x0f) | ((fragment & 0x03) << 4) |
|
|
||||||
((compression & 0x03) << 6);
|
|
||||||
out_uint8(s_send, i32);
|
|
||||||
out_uint16_le(s_send, len);
|
|
||||||
s_copy(s_send, s, len);
|
|
||||||
s_mark_end(s_send);
|
|
||||||
if (xrdp_tcp_send(self->tcp_layer, s_send) != 0)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int
|
int
|
||||||
xrdp_fastpath_process_update(struct xrdp_fastpath* self, tui8 updateCode,
|
xrdp_fastpath_process_update(struct xrdp_fastpath *self, tui8 updateCode,
|
||||||
tui32 size, struct stream* s)
|
tui32 size, struct stream *s)
|
||||||
{
|
{
|
||||||
switch (updateCode)
|
switch (updateCode)
|
||||||
{
|
{
|
||||||
case FASTPATH_UPDATETYPE_ORDERS:
|
case FASTPATH_UPDATETYPE_ORDERS:
|
||||||
case FASTPATH_UPDATETYPE_BITMAP:
|
case FASTPATH_UPDATETYPE_BITMAP:
|
||||||
case FASTPATH_UPDATETYPE_PALETTE:
|
case FASTPATH_UPDATETYPE_PALETTE:
|
||||||
case FASTPATH_UPDATETYPE_SYNCHRONIZE:
|
case FASTPATH_UPDATETYPE_SYNCHRONIZE:
|
||||||
case FASTPATH_UPDATETYPE_SURFCMDS:
|
case FASTPATH_UPDATETYPE_SURFCMDS:
|
||||||
case FASTPATH_UPDATETYPE_PTR_NULL:
|
case FASTPATH_UPDATETYPE_PTR_NULL:
|
||||||
case FASTPATH_UPDATETYPE_PTR_DEFAULT:
|
case FASTPATH_UPDATETYPE_PTR_DEFAULT:
|
||||||
case FASTPATH_UPDATETYPE_PTR_POSITION:
|
case FASTPATH_UPDATETYPE_PTR_POSITION:
|
||||||
case FASTPATH_UPDATETYPE_COLOR:
|
case FASTPATH_UPDATETYPE_COLOR:
|
||||||
case FASTPATH_UPDATETYPE_CACHED:
|
case FASTPATH_UPDATETYPE_CACHED:
|
||||||
case FASTPATH_UPDATETYPE_POINTER:
|
case FASTPATH_UPDATETYPE_POINTER:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
g_writeln("xrdp_fastpath_process_update: unknown updateCode 0x%X",
|
g_writeln("xrdp_fastpath_process_update: unknown updateCode 0x%X",
|
||||||
updateCode);
|
updateCode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_fastpath_process_data(struct xrdp_fastpath* self, struct stream* s,
|
xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s,
|
||||||
tui8 header)
|
tui8 header)
|
||||||
{
|
{
|
||||||
tui8 encryptionFlags;
|
tui8 encryptionFlags;
|
||||||
tui8 numberEvents;
|
tui8 numberEvents;
|
||||||
tui8 length2;
|
tui8 length2;
|
||||||
tui8 updateHeader;
|
tui8 updateHeader;
|
||||||
tui8 updateCode;
|
tui8 updateCode;
|
||||||
tui8 updateFrag;
|
tui8 updateFrag;
|
||||||
tui8 updateComp;
|
tui8 updateComp;
|
||||||
tui16 length;
|
tui16 length;
|
||||||
tui32 size;
|
tui32 size;
|
||||||
|
|
||||||
encryptionFlags = (header & 0xc0) >> 6;
|
encryptionFlags = (header & 0xc0) >> 6;
|
||||||
numberEvents = (header & 0x3c) >> 2;
|
numberEvents = (header & 0x3c) >> 2;
|
||||||
xrdp_tcp_recv(self->tcp_layer, s, 1);
|
|
||||||
in_uint8(s, length);
|
|
||||||
if (length & 0x80)
|
|
||||||
{
|
|
||||||
xrdp_tcp_recv(self->tcp_layer, s, 1);
|
xrdp_tcp_recv(self->tcp_layer, s, 1);
|
||||||
in_uint8(s, length2);
|
in_uint8(s, length);
|
||||||
length = (length & 0x7f) << 8 + length2 - 3;
|
|
||||||
}
|
if (length & 0x80)
|
||||||
else
|
{
|
||||||
{
|
xrdp_tcp_recv(self->tcp_layer, s, 1);
|
||||||
length -= 2;
|
in_uint8(s, length2);
|
||||||
}
|
length = (length & 0x7f) << 8 + length2 - 3;
|
||||||
xrdp_tcp_recv(self->tcp_layer, s, length);
|
}
|
||||||
if (encryptionFlags != 0)
|
else
|
||||||
{
|
{
|
||||||
/* TODO decryption ...*/
|
length -= 2;
|
||||||
}
|
}
|
||||||
/* parse updateHeader */
|
|
||||||
in_uint8(s, updateHeader);
|
xrdp_tcp_recv(self->tcp_layer, s, length);
|
||||||
updateCode = (updateHeader & 0x0f);
|
|
||||||
updateFrag = (updateHeader & 0x30) >> 4;
|
if (encryptionFlags != 0)
|
||||||
updateComp = (updateHeader & 0xc0) >> 6;
|
{
|
||||||
if (updateFrag && updateComp)
|
/* TODO decryption ...*/
|
||||||
{
|
}
|
||||||
/* TODO */
|
|
||||||
g_writeln("xrdp_fastpath_process_data: updateFrag=%d, updateComp=%d",
|
/* parse updateHeader */
|
||||||
updateFrag,updateComp);
|
in_uint8(s, updateHeader);
|
||||||
return 1;
|
updateCode = (updateHeader & 0x0f);
|
||||||
}
|
updateFrag = (updateHeader & 0x30) >> 4;
|
||||||
in_uint16_le(s, size);
|
updateComp = (updateHeader & 0xc0) >> 6;
|
||||||
return xrdp_fastpath_process_update(self, updateCode, size, s);
|
|
||||||
|
if (updateFrag && updateComp)
|
||||||
|
{
|
||||||
|
/* TODO */
|
||||||
|
g_writeln("xrdp_fastpath_process_data: updateFrag=%d, updateComp=%d",
|
||||||
|
updateFrag, updateComp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_le(s, size);
|
||||||
|
return xrdp_fastpath_process_update(self, updateCode, size, s);
|
||||||
}
|
}
|
||||||
|
|||||||
+163
-144
@@ -1,197 +1,216 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2004-2010
|
*
|
||||||
|
* iso layer
|
||||||
iso layer
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libxrdp.h"
|
#include "libxrdp.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct xrdp_iso* APP_CC
|
struct xrdp_iso *APP_CC
|
||||||
xrdp_iso_create(struct xrdp_mcs* owner, struct trans* trans)
|
xrdp_iso_create(struct xrdp_mcs *owner, struct trans *trans)
|
||||||
{
|
{
|
||||||
struct xrdp_iso* self;
|
struct xrdp_iso *self;
|
||||||
|
|
||||||
DEBUG((" in xrdp_iso_create"));
|
DEBUG((" in xrdp_iso_create"));
|
||||||
self = (struct xrdp_iso*)g_malloc(sizeof(struct xrdp_iso), 1);
|
self = (struct xrdp_iso *)g_malloc(sizeof(struct xrdp_iso), 1);
|
||||||
self->mcs_layer = owner;
|
self->mcs_layer = owner;
|
||||||
self->tcp_layer = xrdp_tcp_create(self, trans);
|
self->tcp_layer = xrdp_tcp_create(self, trans);
|
||||||
DEBUG((" out xrdp_iso_create"));
|
DEBUG((" out xrdp_iso_create"));
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
xrdp_iso_delete(struct xrdp_iso* self)
|
xrdp_iso_delete(struct xrdp_iso *self)
|
||||||
{
|
{
|
||||||
if (self == 0)
|
if (self == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xrdp_tcp_delete(self->tcp_layer);
|
|
||||||
g_free(self);
|
xrdp_tcp_delete(self->tcp_layer);
|
||||||
|
g_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
xrdp_iso_recv_msg(struct xrdp_iso* self, struct stream* s, int* code)
|
xrdp_iso_recv_msg(struct xrdp_iso *self, struct stream *s, int *code)
|
||||||
{
|
{
|
||||||
int ver;
|
int ver;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
*code = 0;
|
||||||
|
|
||||||
|
if (xrdp_tcp_recv(self->tcp_layer, s, 4) != 0)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint8(s, ver);
|
||||||
|
|
||||||
|
if (ver != 3)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
*code = 0;
|
|
||||||
if (xrdp_tcp_recv(self->tcp_layer, s, 4) != 0)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
in_uint8(s, ver);
|
|
||||||
if (ver != 3)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
in_uint8s(s, 1);
|
|
||||||
in_uint16_be(s, len);
|
|
||||||
if (xrdp_tcp_recv(self->tcp_layer, s, len - 4) != 0)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
in_uint8s(s, 1);
|
|
||||||
in_uint8(s, *code);
|
|
||||||
if (*code == ISO_PDU_DT)
|
|
||||||
{
|
|
||||||
in_uint8s(s, 1);
|
in_uint8s(s, 1);
|
||||||
}
|
in_uint16_be(s, len);
|
||||||
else
|
|
||||||
{
|
if (xrdp_tcp_recv(self->tcp_layer, s, len - 4) != 0)
|
||||||
in_uint8s(s, 5);
|
{
|
||||||
}
|
return 1;
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
in_uint8s(s, 1);
|
||||||
|
in_uint8(s, *code);
|
||||||
|
|
||||||
|
if (*code == ISO_PDU_DT)
|
||||||
|
{
|
||||||
|
in_uint8s(s, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in_uint8s(s, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_iso_recv(struct xrdp_iso* self, struct stream* s)
|
xrdp_iso_recv(struct xrdp_iso *self, struct stream *s)
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
|
|
||||||
DEBUG((" in xrdp_iso_recv"));
|
DEBUG((" in xrdp_iso_recv"));
|
||||||
if (xrdp_iso_recv_msg(self, s, &code) != 0)
|
|
||||||
{
|
if (xrdp_iso_recv_msg(self, s, &code) != 0)
|
||||||
DEBUG((" out xrdp_iso_recv xrdp_iso_recv_msg return non zero"));
|
{
|
||||||
return 1;
|
DEBUG((" out xrdp_iso_recv xrdp_iso_recv_msg return non zero"));
|
||||||
}
|
return 1;
|
||||||
if (code != ISO_PDU_DT)
|
}
|
||||||
{
|
|
||||||
DEBUG((" out xrdp_iso_recv code != ISO_PDU_DT"));
|
if (code != ISO_PDU_DT)
|
||||||
return 1;
|
{
|
||||||
}
|
DEBUG((" out xrdp_iso_recv code != ISO_PDU_DT"));
|
||||||
DEBUG((" out xrdp_iso_recv"));
|
return 1;
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
DEBUG((" out xrdp_iso_recv"));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
xrdp_iso_send_msg(struct xrdp_iso* self, struct stream* s, int code)
|
xrdp_iso_send_msg(struct xrdp_iso *self, struct stream *s, int code)
|
||||||
{
|
{
|
||||||
if (xrdp_tcp_init(self->tcp_layer, s) != 0)
|
if (xrdp_tcp_init(self->tcp_layer, s) != 0)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
out_uint8(s, 3);
|
|
||||||
out_uint8(s, 0);
|
out_uint8(s, 3);
|
||||||
out_uint16_be(s, 11); /* length */
|
out_uint8(s, 0);
|
||||||
out_uint8(s, 6);
|
out_uint16_be(s, 11); /* length */
|
||||||
out_uint8(s, code);
|
out_uint8(s, 6);
|
||||||
out_uint16_le(s, 0);
|
out_uint8(s, code);
|
||||||
out_uint16_le(s, 0);
|
out_uint16_le(s, 0);
|
||||||
out_uint8(s, 0);
|
out_uint16_le(s, 0);
|
||||||
s_mark_end(s);
|
out_uint8(s, 0);
|
||||||
if (xrdp_tcp_send(self->tcp_layer, s) != 0)
|
s_mark_end(s);
|
||||||
{
|
|
||||||
return 1;
|
if (xrdp_tcp_send(self->tcp_layer, s) != 0)
|
||||||
}
|
{
|
||||||
return 0;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_iso_incoming(struct xrdp_iso* self)
|
xrdp_iso_incoming(struct xrdp_iso *self)
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
|
|
||||||
make_stream(s);
|
make_stream(s);
|
||||||
init_stream(s, 8192);
|
init_stream(s, 8192);
|
||||||
DEBUG((" in xrdp_iso_incoming"));
|
DEBUG((" in xrdp_iso_incoming"));
|
||||||
if (xrdp_iso_recv_msg(self, s, &code) != 0)
|
|
||||||
{
|
if (xrdp_iso_recv_msg(self, s, &code) != 0)
|
||||||
|
{
|
||||||
|
free_stream(s);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code != ISO_PDU_CR)
|
||||||
|
{
|
||||||
|
free_stream(s);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xrdp_iso_send_msg(self, s, ISO_PDU_CC) != 0)
|
||||||
|
{
|
||||||
|
free_stream(s);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG((" out xrdp_iso_incoming"));
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
return 1;
|
return 0;
|
||||||
}
|
|
||||||
if (code != ISO_PDU_CR)
|
|
||||||
{
|
|
||||||
free_stream(s);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (xrdp_iso_send_msg(self, s, ISO_PDU_CC) != 0)
|
|
||||||
{
|
|
||||||
free_stream(s);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
DEBUG((" out xrdp_iso_incoming"));
|
|
||||||
free_stream(s);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_iso_init(struct xrdp_iso* self, struct stream* s)
|
xrdp_iso_init(struct xrdp_iso *self, struct stream *s)
|
||||||
{
|
{
|
||||||
xrdp_tcp_init(self->tcp_layer, s);
|
xrdp_tcp_init(self->tcp_layer, s);
|
||||||
s_push_layer(s, iso_hdr, 7);
|
s_push_layer(s, iso_hdr, 7);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_iso_send(struct xrdp_iso* self, struct stream* s)
|
xrdp_iso_send(struct xrdp_iso *self, struct stream *s)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
DEBUG((" in xrdp_iso_send"));
|
DEBUG((" in xrdp_iso_send"));
|
||||||
s_pop_layer(s, iso_hdr);
|
s_pop_layer(s, iso_hdr);
|
||||||
len = s->end - s->p;
|
len = s->end - s->p;
|
||||||
out_uint8(s, 3);
|
out_uint8(s, 3);
|
||||||
out_uint8(s, 0);
|
out_uint8(s, 0);
|
||||||
out_uint16_be(s, len);
|
out_uint16_be(s, len);
|
||||||
out_uint8(s, 2);
|
out_uint8(s, 2);
|
||||||
out_uint8(s, ISO_PDU_DT);
|
out_uint8(s, ISO_PDU_DT);
|
||||||
out_uint8(s, 0x80);
|
out_uint8(s, 0x80);
|
||||||
if (xrdp_tcp_send(self->tcp_layer, s) != 0)
|
|
||||||
{
|
if (xrdp_tcp_send(self->tcp_layer, s) != 0)
|
||||||
return 1;
|
{
|
||||||
}
|
return 1;
|
||||||
DEBUG((" out xrdp_iso_send"));
|
}
|
||||||
return 0;
|
|
||||||
|
DEBUG((" out xrdp_iso_send"));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+160
-153
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2012
|
*
|
||||||
|
* jpeg compressor
|
||||||
jpeg compressor
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libxrdp.h"
|
#include "libxrdp.h"
|
||||||
|
|
||||||
@@ -33,10 +31,10 @@
|
|||||||
|
|
||||||
struct mydata_comp
|
struct mydata_comp
|
||||||
{
|
{
|
||||||
char* cb;
|
char *cb;
|
||||||
int cb_bytes;
|
int cb_bytes;
|
||||||
int total_done;
|
int total_done;
|
||||||
int overwrite;
|
int overwrite;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -44,13 +42,13 @@ struct mydata_comp
|
|||||||
static void DEFAULT_CC
|
static void DEFAULT_CC
|
||||||
my_init_destination(j_compress_ptr cinfo)
|
my_init_destination(j_compress_ptr cinfo)
|
||||||
{
|
{
|
||||||
struct mydata_comp* md;
|
struct mydata_comp *md;
|
||||||
|
|
||||||
md = (struct mydata_comp*)(cinfo->client_data);
|
md = (struct mydata_comp *)(cinfo->client_data);
|
||||||
md->total_done = 0;
|
md->total_done = 0;
|
||||||
md->overwrite = 0;
|
md->overwrite = 0;
|
||||||
cinfo->dest->next_output_byte = md->cb;
|
cinfo->dest->next_output_byte = md->cb;
|
||||||
cinfo->dest->free_in_buffer = md->cb_bytes;
|
cinfo->dest->free_in_buffer = md->cb_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -58,16 +56,16 @@ my_init_destination(j_compress_ptr cinfo)
|
|||||||
static int DEFAULT_CC
|
static int DEFAULT_CC
|
||||||
my_empty_output_buffer(j_compress_ptr cinfo)
|
my_empty_output_buffer(j_compress_ptr cinfo)
|
||||||
{
|
{
|
||||||
struct mydata_comp* md;
|
struct mydata_comp *md;
|
||||||
int chunk_bytes;
|
int chunk_bytes;
|
||||||
|
|
||||||
md = (struct mydata_comp*)(cinfo->client_data);
|
md = (struct mydata_comp *)(cinfo->client_data);
|
||||||
chunk_bytes = md->cb_bytes;
|
chunk_bytes = md->cb_bytes;
|
||||||
md->total_done += chunk_bytes;
|
md->total_done += chunk_bytes;
|
||||||
cinfo->dest->next_output_byte = md->cb;
|
cinfo->dest->next_output_byte = md->cb;
|
||||||
cinfo->dest->free_in_buffer = md->cb_bytes;
|
cinfo->dest->free_in_buffer = md->cb_bytes;
|
||||||
md->overwrite = 1;
|
md->overwrite = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -75,149 +73,158 @@ my_empty_output_buffer(j_compress_ptr cinfo)
|
|||||||
static void DEFAULT_CC
|
static void DEFAULT_CC
|
||||||
my_term_destination(j_compress_ptr cinfo)
|
my_term_destination(j_compress_ptr cinfo)
|
||||||
{
|
{
|
||||||
struct mydata_comp* md;
|
struct mydata_comp *md;
|
||||||
int chunk_bytes;
|
int chunk_bytes;
|
||||||
|
|
||||||
md = (struct mydata_comp*)(cinfo->client_data);
|
md = (struct mydata_comp *)(cinfo->client_data);
|
||||||
chunk_bytes = md->cb_bytes - cinfo->dest->free_in_buffer;
|
chunk_bytes = md->cb_bytes - cinfo->dest->free_in_buffer;
|
||||||
md->total_done += chunk_bytes;
|
md->total_done += chunk_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
jp_do_compress(char* data, int width, int height, int bpp, int quality,
|
jp_do_compress(char *data, int width, int height, int bpp, int quality,
|
||||||
char* comp_data, int* comp_data_bytes)
|
char *comp_data, int *comp_data_bytes)
|
||||||
{
|
{
|
||||||
struct jpeg_compress_struct cinfo;
|
struct jpeg_compress_struct cinfo;
|
||||||
struct jpeg_error_mgr jerr;
|
struct jpeg_error_mgr jerr;
|
||||||
struct jpeg_destination_mgr dst_mgr;
|
struct jpeg_destination_mgr dst_mgr;
|
||||||
struct mydata_comp md;
|
struct mydata_comp md;
|
||||||
JSAMPROW row_pointer[4];
|
JSAMPROW row_pointer[4];
|
||||||
int Bpp;
|
int Bpp;
|
||||||
|
|
||||||
Bpp = (bpp + 7) / 8;
|
Bpp = (bpp + 7) / 8;
|
||||||
memset(&cinfo, 0, sizeof(cinfo));
|
memset(&cinfo, 0, sizeof(cinfo));
|
||||||
cinfo.err = jpeg_std_error(&jerr);
|
cinfo.err = jpeg_std_error(&jerr);
|
||||||
jpeg_create_compress(&cinfo);
|
jpeg_create_compress(&cinfo);
|
||||||
memset(&md, 0, sizeof(md));
|
memset(&md, 0, sizeof(md));
|
||||||
md.cb = comp_data,
|
md.cb = comp_data,
|
||||||
md.cb_bytes = *comp_data_bytes;
|
md.cb_bytes = *comp_data_bytes;
|
||||||
cinfo.client_data = &md;
|
cinfo.client_data = &md;
|
||||||
memset(&dst_mgr, 0, sizeof(dst_mgr));
|
memset(&dst_mgr, 0, sizeof(dst_mgr));
|
||||||
dst_mgr.init_destination = my_init_destination;
|
dst_mgr.init_destination = my_init_destination;
|
||||||
dst_mgr.empty_output_buffer = my_empty_output_buffer;
|
dst_mgr.empty_output_buffer = my_empty_output_buffer;
|
||||||
dst_mgr.term_destination = my_term_destination;
|
dst_mgr.term_destination = my_term_destination;
|
||||||
cinfo.dest = &dst_mgr;
|
cinfo.dest = &dst_mgr;
|
||||||
cinfo.image_width = width;
|
cinfo.image_width = width;
|
||||||
cinfo.image_height = height;
|
cinfo.image_height = height;
|
||||||
cinfo.input_components = Bpp;
|
cinfo.input_components = Bpp;
|
||||||
cinfo.in_color_space = JCS_RGB;
|
cinfo.in_color_space = JCS_RGB;
|
||||||
jpeg_set_defaults(&cinfo);
|
jpeg_set_defaults(&cinfo);
|
||||||
cinfo.num_components = 3;
|
cinfo.num_components = 3;
|
||||||
cinfo.dct_method = JDCT_FLOAT;
|
cinfo.dct_method = JDCT_FLOAT;
|
||||||
jpeg_set_quality(&cinfo, quality, 1);
|
jpeg_set_quality(&cinfo, quality, 1);
|
||||||
jpeg_start_compress(&cinfo, 1);
|
jpeg_start_compress(&cinfo, 1);
|
||||||
while (cinfo.next_scanline + 3 < cinfo.image_height)
|
|
||||||
{
|
while (cinfo.next_scanline + 3 < cinfo.image_height)
|
||||||
row_pointer[0] = data;
|
{
|
||||||
data += width * Bpp;
|
row_pointer[0] = data;
|
||||||
row_pointer[1] = data;
|
data += width * Bpp;
|
||||||
data += width * Bpp;
|
row_pointer[1] = data;
|
||||||
row_pointer[2] = data;
|
data += width * Bpp;
|
||||||
data += width * Bpp;
|
row_pointer[2] = data;
|
||||||
row_pointer[3] = data;
|
data += width * Bpp;
|
||||||
data += width * Bpp;
|
row_pointer[3] = data;
|
||||||
jpeg_write_scanlines(&cinfo, row_pointer, 4);
|
data += width * Bpp;
|
||||||
}
|
jpeg_write_scanlines(&cinfo, row_pointer, 4);
|
||||||
while (cinfo.next_scanline < cinfo.image_height)
|
}
|
||||||
{
|
|
||||||
row_pointer[0] = data;
|
while (cinfo.next_scanline < cinfo.image_height)
|
||||||
data += width * Bpp;
|
{
|
||||||
jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
row_pointer[0] = data;
|
||||||
}
|
data += width * Bpp;
|
||||||
jpeg_finish_compress(&cinfo);
|
jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||||
*comp_data_bytes = md.total_done;
|
}
|
||||||
jpeg_destroy_compress(&cinfo);
|
|
||||||
if (md.overwrite)
|
jpeg_finish_compress(&cinfo);
|
||||||
{
|
*comp_data_bytes = md.total_done;
|
||||||
return 1;
|
jpeg_destroy_compress(&cinfo);
|
||||||
}
|
|
||||||
return 0;
|
if (md.overwrite)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
jpeg_compress(char* in_data, int width, int height,
|
jpeg_compress(char *in_data, int width, int height,
|
||||||
struct stream* s, struct stream* temp_s, int bpp,
|
struct stream *s, struct stream *temp_s, int bpp,
|
||||||
int byte_limit, int e, int quality)
|
int byte_limit, int e, int quality)
|
||||||
{
|
{
|
||||||
char* data;
|
char *data;
|
||||||
tui32* src32;
|
tui32 *src32;
|
||||||
tui16* src16;
|
tui16 *src16;
|
||||||
tui8* dst8;
|
tui8 *dst8;
|
||||||
tui32 pixel;
|
tui32 pixel;
|
||||||
int red;
|
int red;
|
||||||
int blue;
|
int blue;
|
||||||
int green;
|
int green;
|
||||||
int j;
|
int j;
|
||||||
int i;
|
int i;
|
||||||
int cdata_bytes;
|
int cdata_bytes;
|
||||||
|
|
||||||
data = temp_s->data;
|
data = temp_s->data;
|
||||||
dst8 = data;
|
dst8 = data;
|
||||||
if (bpp == 24)
|
|
||||||
{
|
if (bpp == 24)
|
||||||
src32 = (tui32*)in_data;
|
|
||||||
for (j = 0; j < height; j++)
|
|
||||||
{
|
{
|
||||||
for (i = 0; i < width; i++)
|
src32 = (tui32 *)in_data;
|
||||||
{
|
|
||||||
pixel = src32[i + j * width];
|
for (j = 0; j < height; j++)
|
||||||
SPLITCOLOR32(red, green, blue, pixel);
|
{
|
||||||
*(dst8++)= blue;
|
for (i = 0; i < width; i++)
|
||||||
*(dst8++)= green;
|
{
|
||||||
*(dst8++)= red;
|
pixel = src32[i + j * width];
|
||||||
}
|
SPLITCOLOR32(red, green, blue, pixel);
|
||||||
for (i = 0; i < e; i++)
|
*(dst8++) = blue;
|
||||||
{
|
*(dst8++) = green;
|
||||||
*(dst8++) = blue;
|
*(dst8++) = red;
|
||||||
*(dst8++) = green;
|
}
|
||||||
*(dst8++) = red;
|
|
||||||
}
|
for (i = 0; i < e; i++)
|
||||||
|
{
|
||||||
|
*(dst8++) = blue;
|
||||||
|
*(dst8++) = green;
|
||||||
|
*(dst8++) = red;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
g_writeln("bpp wrong %d", bpp);
|
||||||
g_writeln("bpp wrong %d", bpp);
|
}
|
||||||
}
|
|
||||||
cdata_bytes = byte_limit;
|
cdata_bytes = byte_limit;
|
||||||
jp_do_compress(data, width + e, height, 24, quality, s->p, &cdata_bytes);
|
jp_do_compress(data, width + e, height, 24, quality, s->p, &cdata_bytes);
|
||||||
s->p += cdata_bytes;
|
s->p += cdata_bytes;
|
||||||
return cdata_bytes;
|
return cdata_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_jpeg_compress(char* in_data, int width, int height,
|
xrdp_jpeg_compress(char *in_data, int width, int height,
|
||||||
struct stream* s, int bpp, int byte_limit,
|
struct stream *s, int bpp, int byte_limit,
|
||||||
int start_line, struct stream* temp_s,
|
int start_line, struct stream *temp_s,
|
||||||
int e, int quality)
|
int e, int quality)
|
||||||
{
|
{
|
||||||
jpeg_compress(in_data, width, height, s, temp_s, bpp, byte_limit,
|
jpeg_compress(in_data, width, height, s, temp_s, bpp, byte_limit,
|
||||||
e, quality);
|
e, quality);
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_jpeg_compress(char* in_data, int width, int height,
|
xrdp_jpeg_compress(char *in_data, int width, int height,
|
||||||
struct stream* s, int bpp, int byte_limit,
|
struct stream *s, int bpp, int byte_limit,
|
||||||
int start_line, struct stream* temp_s,
|
int start_line, struct stream *temp_s,
|
||||||
int e, int quality)
|
int e, int quality)
|
||||||
{
|
{
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+697
-604
File diff suppressed because it is too large
Load Diff
+2072
-1779
File diff suppressed because it is too large
Load Diff
+552
-494
File diff suppressed because it is too large
Load Diff
+1338
-1257
File diff suppressed because it is too large
Load Diff
+951
-848
File diff suppressed because it is too large
Load Diff
+98
-95
@@ -21,141 +21,144 @@
|
|||||||
#include "freerdp/codec/rfx.h"
|
#include "freerdp/codec/rfx.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct xrdp_surface* APP_CC
|
struct xrdp_surface *APP_CC
|
||||||
xrdp_surface_create(struct xrdp_session* session, struct xrdp_fastpath* fastpath)
|
xrdp_surface_create(struct xrdp_session *session, struct xrdp_fastpath *fastpath)
|
||||||
{
|
{
|
||||||
struct xrdp_surface* self;
|
struct xrdp_surface *self;
|
||||||
|
|
||||||
self = (struct xrdp_surface*)g_malloc(sizeof(struct xrdp_surface), 1);
|
self = (struct xrdp_surface *)g_malloc(sizeof(struct xrdp_surface), 1);
|
||||||
self->session = session;
|
self->session = session;
|
||||||
self->fastpath = fastpath;
|
self->fastpath = fastpath;
|
||||||
self->rfx_context = rfx_context_new();
|
self->rfx_context = rfx_context_new();
|
||||||
self->s = stream_new(16384);
|
self->s = stream_new(16384);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
xrdp_surface_delete(struct xrdp_surface* self)
|
xrdp_surface_delete(struct xrdp_surface *self)
|
||||||
{
|
{
|
||||||
STREAM* s;
|
STREAM *s;
|
||||||
RFX_CONTEXT* rfx_context;
|
RFX_CONTEXT *rfx_context;
|
||||||
|
|
||||||
if (self == 0)
|
if (self == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s = (STREAM*)(self->s);
|
|
||||||
rfx_context = (RFX_CONTEXT*)(self->rfx_context);
|
s = (STREAM *)(self->s);
|
||||||
free_stream(self->out_s);
|
rfx_context = (RFX_CONTEXT *)(self->rfx_context);
|
||||||
stream_free(s);
|
free_stream(self->out_s);
|
||||||
rfx_context_free(rfx_context);
|
stream_free(s);
|
||||||
g_free(self);
|
rfx_context_free(rfx_context);
|
||||||
|
g_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_surface_reset(struct xrdp_surface* self)
|
xrdp_surface_reset(struct xrdp_surface *self)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_surface_init(struct xrdp_surface* self)
|
xrdp_surface_init(struct xrdp_surface *self)
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
RFX_CONTEXT* rfx_context;
|
RFX_CONTEXT *rfx_context;
|
||||||
|
|
||||||
rfx_context = (RFX_CONTEXT*)(self->rfx_context);
|
rfx_context = (RFX_CONTEXT *)(self->rfx_context);
|
||||||
width = self->session->client_info->width;
|
width = self->session->client_info->width;
|
||||||
height= self->session->client_info->height;
|
height = self->session->client_info->height;
|
||||||
|
|
||||||
rfx_context->mode = self->session->client_info->rfx_entropy;
|
rfx_context->mode = self->session->client_info->rfx_entropy;
|
||||||
rfx_context->width = width;
|
rfx_context->width = width;
|
||||||
rfx_context->height= height;
|
rfx_context->height = height;
|
||||||
|
|
||||||
make_stream(self->out_s);
|
make_stream(self->out_s);
|
||||||
init_stream(self->out_s, 2 * 3 * width * height + 22);
|
init_stream(self->out_s, 2 * 3 * width * height + 22);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_surface_send_surface_bits(struct xrdp_surface* self,int bpp, char* data,
|
xrdp_surface_send_surface_bits(struct xrdp_surface *self, int bpp, char *data,
|
||||||
int x, int y, int cx, int cy)
|
int x, int y, int cx, int cy)
|
||||||
{
|
{
|
||||||
RFX_RECT rect;
|
RFX_RECT rect;
|
||||||
char* buf;
|
char *buf;
|
||||||
int Bpp;
|
int Bpp;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int codecId;
|
int codecId;
|
||||||
uint32 bitmapDataLength;
|
uint32 bitmapDataLength;
|
||||||
STREAM* s;
|
STREAM *s;
|
||||||
RFX_CONTEXT* rfx_context;
|
RFX_CONTEXT *rfx_context;
|
||||||
|
|
||||||
s = (STREAM*)(self->s);
|
s = (STREAM *)(self->s);
|
||||||
rfx_context = (RFX_CONTEXT*)(self->rfx_context);
|
rfx_context = (RFX_CONTEXT *)(self->rfx_context);
|
||||||
if ((bpp == 24) || (bpp == 32))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_writeln("bpp = %d is not supported\n", bpp);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Bpp = 4;
|
|
||||||
|
|
||||||
rect.x = 0;
|
if ((bpp == 24) || (bpp == 32))
|
||||||
rect.y = 0;
|
{
|
||||||
rect.width = cx;
|
}
|
||||||
rect.height = cy;
|
else
|
||||||
|
{
|
||||||
|
g_writeln("bpp = %d is not supported\n", bpp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
init_stream(self->out_s, 0);
|
Bpp = 4;
|
||||||
|
|
||||||
stream_set_pos(s, 0);
|
rect.x = 0;
|
||||||
rfx_compose_message(rfx_context, s, &rect, 1, data, cx, cy, Bpp * cx);
|
rect.y = 0;
|
||||||
|
rect.width = cx;
|
||||||
|
rect.height = cy;
|
||||||
|
|
||||||
codecId = self->session->client_info->rfx_codecId;
|
init_stream(self->out_s, 0);
|
||||||
/* surface_bits_command */
|
|
||||||
out_uint16_le(self->out_s, CMDTYPE_STREAM_SURFACE_BITS); /* cmdType */
|
|
||||||
out_uint16_le(self->out_s, x); /* destLeft */
|
|
||||||
out_uint16_le(self->out_s, y); /* destTop */
|
|
||||||
out_uint16_le(self->out_s, x + cx); /* destRight */
|
|
||||||
out_uint16_le(self->out_s, y + cy); /* destBottom */
|
|
||||||
out_uint8(self->out_s, 32); /* bpp */
|
|
||||||
out_uint8(self->out_s, 0); /* reserved1 */
|
|
||||||
out_uint8(self->out_s, 0); /* reserved2 */
|
|
||||||
out_uint8(self->out_s, codecId); /* codecId */
|
|
||||||
out_uint16_le(self->out_s, cx); /* width */
|
|
||||||
out_uint16_le(self->out_s, cy); /* height */
|
|
||||||
bitmapDataLength = stream_get_length(s);
|
|
||||||
out_uint32_le(self->out_s, bitmapDataLength); /* bitmapDataLength */
|
|
||||||
|
|
||||||
/* rfx bit stream */
|
stream_set_pos(s, 0);
|
||||||
out_uint8p(self->out_s, s->data, bitmapDataLength);
|
rfx_compose_message(rfx_context, s, &rect, 1, data, cx, cy, Bpp * cx);
|
||||||
|
|
||||||
s_mark_end(self->out_s);
|
codecId = self->session->client_info->rfx_codecId;
|
||||||
return xrdp_fastpath_send_update_pdu(self->fastpath,
|
/* surface_bits_command */
|
||||||
FASTPATH_UPDATETYPE_SURFCMDS,
|
out_uint16_le(self->out_s, CMDTYPE_STREAM_SURFACE_BITS); /* cmdType */
|
||||||
self->out_s);
|
out_uint16_le(self->out_s, x); /* destLeft */
|
||||||
|
out_uint16_le(self->out_s, y); /* destTop */
|
||||||
|
out_uint16_le(self->out_s, x + cx); /* destRight */
|
||||||
|
out_uint16_le(self->out_s, y + cy); /* destBottom */
|
||||||
|
out_uint8(self->out_s, 32); /* bpp */
|
||||||
|
out_uint8(self->out_s, 0); /* reserved1 */
|
||||||
|
out_uint8(self->out_s, 0); /* reserved2 */
|
||||||
|
out_uint8(self->out_s, codecId); /* codecId */
|
||||||
|
out_uint16_le(self->out_s, cx); /* width */
|
||||||
|
out_uint16_le(self->out_s, cy); /* height */
|
||||||
|
bitmapDataLength = stream_get_length(s);
|
||||||
|
out_uint32_le(self->out_s, bitmapDataLength); /* bitmapDataLength */
|
||||||
|
|
||||||
|
/* rfx bit stream */
|
||||||
|
out_uint8p(self->out_s, s->data, bitmapDataLength);
|
||||||
|
|
||||||
|
s_mark_end(self->out_s);
|
||||||
|
return xrdp_fastpath_send_update_pdu(self->fastpath,
|
||||||
|
FASTPATH_UPDATETYPE_SURFCMDS,
|
||||||
|
self->out_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_surface_send_frame_marker(struct xrdp_surface* self,
|
xrdp_surface_send_frame_marker(struct xrdp_surface *self,
|
||||||
uint16 frameAction, uint32 frameId)
|
uint16 frameAction, uint32 frameId)
|
||||||
{
|
{
|
||||||
init_stream(self->out_s, 0);
|
init_stream(self->out_s, 0);
|
||||||
out_uint16_le(self->out_s, CMDTYPE_FRAME_MARKER);
|
out_uint16_le(self->out_s, CMDTYPE_FRAME_MARKER);
|
||||||
out_uint16_le(self->out_s, frameAction);
|
out_uint16_le(self->out_s, frameAction);
|
||||||
out_uint32_le(self->out_s, frameId);
|
out_uint32_le(self->out_s, frameId);
|
||||||
s_mark_end(self->out_s);
|
s_mark_end(self->out_s);
|
||||||
return xrdp_fastpath_send_update_pdu(self->fastpath,
|
return xrdp_fastpath_send_update_pdu(self->fastpath,
|
||||||
FASTPATH_UPDATETYPE_SURFCMDS,
|
FASTPATH_UPDATETYPE_SURFCMDS,
|
||||||
self->out_s);
|
self->out_s);
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-56
@@ -1,87 +1,89 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004 - 2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2004-2010
|
*
|
||||||
|
* tcp layer
|
||||||
tcp layer
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libxrdp.h"
|
#include "libxrdp.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct xrdp_tcp* APP_CC
|
struct xrdp_tcp *APP_CC
|
||||||
xrdp_tcp_create(struct xrdp_iso* owner, struct trans* trans)
|
xrdp_tcp_create(struct xrdp_iso *owner, struct trans *trans)
|
||||||
{
|
{
|
||||||
struct xrdp_tcp* self;
|
struct xrdp_tcp *self;
|
||||||
|
|
||||||
DEBUG((" in xrdp_tcp_create"));
|
DEBUG((" in xrdp_tcp_create"));
|
||||||
self = (struct xrdp_tcp*)g_malloc(sizeof(struct xrdp_tcp), 1);
|
self = (struct xrdp_tcp *)g_malloc(sizeof(struct xrdp_tcp), 1);
|
||||||
self->iso_layer = owner;
|
self->iso_layer = owner;
|
||||||
self->trans = trans;
|
self->trans = trans;
|
||||||
DEBUG((" out xrdp_tcp_create"));
|
DEBUG((" out xrdp_tcp_create"));
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
xrdp_tcp_delete(struct xrdp_tcp* self)
|
xrdp_tcp_delete(struct xrdp_tcp *self)
|
||||||
{
|
{
|
||||||
g_free(self);
|
g_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* get out stream ready for data */
|
/* get out stream ready for data */
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_tcp_init(struct xrdp_tcp* self, struct stream* s)
|
xrdp_tcp_init(struct xrdp_tcp *self, struct stream *s)
|
||||||
{
|
{
|
||||||
init_stream(s, 8192);
|
init_stream(s, 8192);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_tcp_recv(struct xrdp_tcp* self, struct stream* s, int len)
|
xrdp_tcp_recv(struct xrdp_tcp *self, struct stream *s, int len)
|
||||||
{
|
{
|
||||||
DEBUG((" in xrdp_tcp_recv, gota get %d bytes", len));
|
DEBUG((" in xrdp_tcp_recv, gota get %d bytes", len));
|
||||||
init_stream(s, len);
|
init_stream(s, len);
|
||||||
if (trans_force_read_s(self->trans, s, len) != 0)
|
|
||||||
{
|
if (trans_force_read_s(self->trans, s, len) != 0)
|
||||||
DEBUG((" error in trans_force_read_s"));
|
{
|
||||||
return 1;
|
DEBUG((" error in trans_force_read_s"));
|
||||||
}
|
return 1;
|
||||||
DEBUG((" out xrdp_tcp_recv"));
|
}
|
||||||
return 0;
|
|
||||||
|
DEBUG((" out xrdp_tcp_recv"));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xrdp_tcp_send(struct xrdp_tcp* self, struct stream* s)
|
xrdp_tcp_send(struct xrdp_tcp *self, struct stream *s)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
len = s->end - s->data;
|
len = s->end - s->data;
|
||||||
DEBUG((" in xrdp_tcp_send, gota send %d bytes", len));
|
DEBUG((" in xrdp_tcp_send, gota send %d bytes", len));
|
||||||
if (trans_force_write_s(self->trans, s) != 0)
|
|
||||||
{
|
if (trans_force_write_s(self->trans, s) != 0)
|
||||||
DEBUG((" error in trans_force_write_s"));
|
{
|
||||||
return 1;
|
DEBUG((" error in trans_force_write_s"));
|
||||||
}
|
return 1;
|
||||||
DEBUG((" out xrdp_tcp_send, sent %d bytes ok", len));
|
}
|
||||||
return 0;
|
|
||||||
|
DEBUG((" out xrdp_tcp_send, sent %d bytes ok", len));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,114 +1,113 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2007-2010
|
*
|
||||||
|
* media center
|
||||||
media center
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mc.h"
|
#include "mc.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_start(struct mod* mod, int w, int h, int bpp)
|
lib_mod_start(struct mod *mod, int w, int h, int bpp)
|
||||||
{
|
{
|
||||||
LIB_DEBUG(mod, "in lib_mod_start");
|
LIB_DEBUG(mod, "in lib_mod_start");
|
||||||
mod->width = w;
|
mod->width = w;
|
||||||
mod->height = h;
|
mod->height = h;
|
||||||
mod->bpp = bpp;
|
mod->bpp = bpp;
|
||||||
LIB_DEBUG(mod, "out lib_mod_start");
|
LIB_DEBUG(mod, "out lib_mod_start");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_connect(struct mod* mod)
|
lib_mod_connect(struct mod *mod)
|
||||||
{
|
{
|
||||||
LIB_DEBUG(mod, "in lib_mod_connect");
|
LIB_DEBUG(mod, "in lib_mod_connect");
|
||||||
LIB_DEBUG(mod, "out lib_mod_connect");
|
LIB_DEBUG(mod, "out lib_mod_connect");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_event(struct mod* mod, int msg, long param1, long param2,
|
lib_mod_event(struct mod *mod, int msg, long param1, long param2,
|
||||||
long param3, long param4)
|
long param3, long param4)
|
||||||
{
|
{
|
||||||
LIB_DEBUG(mod, "in lib_mod_event");
|
LIB_DEBUG(mod, "in lib_mod_event");
|
||||||
LIB_DEBUG(mod, "out lib_mod_event");
|
LIB_DEBUG(mod, "out lib_mod_event");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_signal(struct mod* mod)
|
lib_mod_signal(struct mod *mod)
|
||||||
{
|
{
|
||||||
LIB_DEBUG(mod, "in lib_mod_signal");
|
LIB_DEBUG(mod, "in lib_mod_signal");
|
||||||
LIB_DEBUG(mod, "out lib_mod_signal");
|
LIB_DEBUG(mod, "out lib_mod_signal");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_end(struct mod* mod)
|
lib_mod_end(struct mod *mod)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_set_param(struct mod* mod, char* name, char* value)
|
lib_mod_set_param(struct mod *mod, char *name, char *value)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
struct mod* EXPORT_CC
|
struct mod *EXPORT_CC
|
||||||
mod_init(void)
|
mod_init(void)
|
||||||
{
|
{
|
||||||
struct mod* mod;
|
struct mod *mod;
|
||||||
|
|
||||||
mod = (struct mod*)g_malloc(sizeof(struct mod), 1);
|
mod = (struct mod *)g_malloc(sizeof(struct mod), 1);
|
||||||
mod->size = sizeof(struct mod);
|
mod->size = sizeof(struct mod);
|
||||||
mod->version = CURRENT_MOD_VER;
|
mod->version = CURRENT_MOD_VER;
|
||||||
mod->handle = (long)mod;
|
mod->handle = (long)mod;
|
||||||
mod->mod_connect = lib_mod_connect;
|
mod->mod_connect = lib_mod_connect;
|
||||||
mod->mod_start = lib_mod_start;
|
mod->mod_start = lib_mod_start;
|
||||||
mod->mod_event = lib_mod_event;
|
mod->mod_event = lib_mod_event;
|
||||||
mod->mod_signal = lib_mod_signal;
|
mod->mod_signal = lib_mod_signal;
|
||||||
mod->mod_end = lib_mod_end;
|
mod->mod_end = lib_mod_end;
|
||||||
mod->mod_set_param = lib_mod_set_param;
|
mod->mod_set_param = lib_mod_set_param;
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int EXPORT_CC
|
int EXPORT_CC
|
||||||
mod_exit(struct mod* mod)
|
mod_exit(struct mod *mod)
|
||||||
{
|
{
|
||||||
if (mod == 0)
|
if (mod == 0)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free(mod);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
g_free(mod);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2007-2010
|
*
|
||||||
|
* media center
|
||||||
media center
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* include other h files */
|
/* include other h files */
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
|
|||||||
@@ -1,333 +1,352 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*
|
||||||
|
* librdp main file
|
||||||
librdp main file
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "rdp.h"
|
#include "rdp.h"
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_start(struct mod* mod, int w, int h, int bpp)
|
lib_mod_start(struct mod *mod, int w, int h, int bpp)
|
||||||
{
|
{
|
||||||
DEBUG(("in lib_mod_start"));
|
DEBUG(("in lib_mod_start"));
|
||||||
mod->width = w;
|
mod->width = w;
|
||||||
mod->height = h;
|
mod->height = h;
|
||||||
mod->rdp_bpp = bpp;
|
mod->rdp_bpp = bpp;
|
||||||
mod->xrdp_bpp = bpp;
|
mod->xrdp_bpp = bpp;
|
||||||
mod->keylayout = 0x409;
|
mod->keylayout = 0x409;
|
||||||
g_strncpy(mod->port, "3389", 255); /* default */
|
g_strncpy(mod->port, "3389", 255); /* default */
|
||||||
DEBUG(("out lib_mod_start"));
|
DEBUG(("out lib_mod_start"));
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
/* return error */
|
|
||||||
int DEFAULT_CC
|
|
||||||
lib_mod_connect(struct mod* mod)
|
|
||||||
{
|
|
||||||
DEBUG(("in lib_mod_connect"));
|
|
||||||
/* clear screen */
|
|
||||||
mod->server_begin_update(mod);
|
|
||||||
mod->server_set_fgcolor(mod, 0);
|
|
||||||
mod->server_fill_rect(mod, 0, 0, mod->width, mod->height);
|
|
||||||
mod->server_end_update(mod);
|
|
||||||
/* connect */
|
|
||||||
if (rdp_rdp_connect(mod->rdp_layer, mod->ip, mod->port) == 0)
|
|
||||||
{
|
|
||||||
mod->sck = mod->rdp_layer->sec_layer->mcs_layer->iso_layer->tcp_layer->sck;
|
|
||||||
g_tcp_set_non_blocking(mod->sck);
|
|
||||||
g_tcp_set_no_delay(mod->sck);
|
|
||||||
mod->sck_obj = g_create_wait_obj_from_socket(mod->sck, 0);
|
|
||||||
DEBUG(("out lib_mod_connect"));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
DEBUG(("out lib_mod_connect error"));
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_event(struct mod* mod, int msg, long param1, long param2,
|
lib_mod_connect(struct mod *mod)
|
||||||
|
{
|
||||||
|
DEBUG(("in lib_mod_connect"));
|
||||||
|
/* clear screen */
|
||||||
|
mod->server_begin_update(mod);
|
||||||
|
mod->server_set_fgcolor(mod, 0);
|
||||||
|
mod->server_fill_rect(mod, 0, 0, mod->width, mod->height);
|
||||||
|
mod->server_end_update(mod);
|
||||||
|
|
||||||
|
/* connect */
|
||||||
|
if (rdp_rdp_connect(mod->rdp_layer, mod->ip, mod->port) == 0)
|
||||||
|
{
|
||||||
|
mod->sck = mod->rdp_layer->sec_layer->mcs_layer->iso_layer->tcp_layer->sck;
|
||||||
|
g_tcp_set_non_blocking(mod->sck);
|
||||||
|
g_tcp_set_no_delay(mod->sck);
|
||||||
|
mod->sck_obj = g_create_wait_obj_from_socket(mod->sck, 0);
|
||||||
|
DEBUG(("out lib_mod_connect"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG(("out lib_mod_connect error"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/* return error */
|
||||||
|
int DEFAULT_CC
|
||||||
|
lib_mod_event(struct mod *mod, int msg, long param1, long param2,
|
||||||
long param3, long param4)
|
long param3, long param4)
|
||||||
{
|
{
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
|
|
||||||
if (!mod->up_and_running)
|
if (!mod->up_and_running)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG(("in lib_mod_event"));
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, 8192 * 2);
|
||||||
|
|
||||||
|
switch (msg)
|
||||||
|
{
|
||||||
|
case 15:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_SCANCODE,
|
||||||
|
param4, param3, 0);
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_SCANCODE,
|
||||||
|
param4, param3, 0);
|
||||||
|
break;
|
||||||
|
case 17:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_SYNCHRONIZE,
|
||||||
|
param4, param3, 0);
|
||||||
|
break;
|
||||||
|
case 100:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_MOVE, param1, param2);
|
||||||
|
break;
|
||||||
|
case 101:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON1, param1, param2);
|
||||||
|
break;
|
||||||
|
case 102:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON1 | MOUSE_FLAG_DOWN,
|
||||||
|
param1, param2);
|
||||||
|
break;
|
||||||
|
case 103:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON2, param1, param2);
|
||||||
|
break;
|
||||||
|
case 104:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON2 | MOUSE_FLAG_DOWN,
|
||||||
|
param1, param2);
|
||||||
|
break;
|
||||||
|
case 105:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON3, param1, param2);
|
||||||
|
break;
|
||||||
|
case 106:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON3 | MOUSE_FLAG_DOWN,
|
||||||
|
param1, param2);
|
||||||
|
break;
|
||||||
|
case 107:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON4, param1, param2);
|
||||||
|
break;
|
||||||
|
case 108:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON4 | MOUSE_FLAG_DOWN,
|
||||||
|
param1, param2);
|
||||||
|
break;
|
||||||
|
case 109:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON5, param1, param2);
|
||||||
|
break;
|
||||||
|
case 110:
|
||||||
|
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
||||||
|
MOUSE_FLAG_BUTTON5 | MOUSE_FLAG_DOWN,
|
||||||
|
param1, param2);
|
||||||
|
break;
|
||||||
|
case 200:
|
||||||
|
rdp_rdp_send_invalidate(mod->rdp_layer, s,
|
||||||
|
(param1 >> 16) & 0xffff, param1 & 0xffff,
|
||||||
|
(param2 >> 16) & 0xffff, param2 & 0xffff);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free_stream(s);
|
||||||
|
DEBUG(("out lib_mod_event"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
DEBUG(("in lib_mod_event"));
|
|
||||||
make_stream(s);
|
|
||||||
init_stream(s, 8192 * 2);
|
|
||||||
switch (msg)
|
|
||||||
{
|
|
||||||
case 15:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_SCANCODE,
|
|
||||||
param4, param3, 0);
|
|
||||||
break;
|
|
||||||
case 16:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_SCANCODE,
|
|
||||||
param4, param3, 0);
|
|
||||||
break;
|
|
||||||
case 17:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_SYNCHRONIZE,
|
|
||||||
param4, param3, 0);
|
|
||||||
break;
|
|
||||||
case 100:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_MOVE, param1, param2);
|
|
||||||
break;
|
|
||||||
case 101:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON1, param1, param2);
|
|
||||||
break;
|
|
||||||
case 102:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON1 | MOUSE_FLAG_DOWN,
|
|
||||||
param1, param2);
|
|
||||||
break;
|
|
||||||
case 103:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON2, param1, param2);
|
|
||||||
break;
|
|
||||||
case 104:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON2 | MOUSE_FLAG_DOWN,
|
|
||||||
param1, param2);
|
|
||||||
break;
|
|
||||||
case 105:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON3, param1, param2);
|
|
||||||
break;
|
|
||||||
case 106:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON3 | MOUSE_FLAG_DOWN,
|
|
||||||
param1, param2);
|
|
||||||
break;
|
|
||||||
case 107:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON4, param1, param2);
|
|
||||||
break;
|
|
||||||
case 108:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON4 | MOUSE_FLAG_DOWN,
|
|
||||||
param1, param2);
|
|
||||||
break;
|
|
||||||
case 109:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON5, param1, param2);
|
|
||||||
break;
|
|
||||||
case 110:
|
|
||||||
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
|
|
||||||
MOUSE_FLAG_BUTTON5 | MOUSE_FLAG_DOWN,
|
|
||||||
param1, param2);
|
|
||||||
break;
|
|
||||||
case 200:
|
|
||||||
rdp_rdp_send_invalidate(mod->rdp_layer, s,
|
|
||||||
(param1 >> 16) & 0xffff, param1 & 0xffff,
|
|
||||||
(param2 >> 16) & 0xffff, param2 & 0xffff);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
free_stream(s);
|
|
||||||
DEBUG(("out lib_mod_event"));
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_signal(struct mod* mod)
|
lib_mod_signal(struct mod *mod)
|
||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
int cont;
|
int cont;
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
|
|
||||||
DEBUG(("in lib_mod_signal"));
|
DEBUG(("in lib_mod_signal"));
|
||||||
if (mod->in_s == 0)
|
|
||||||
{
|
if (mod->in_s == 0)
|
||||||
make_stream(mod->in_s);
|
|
||||||
}
|
|
||||||
s = mod->in_s;
|
|
||||||
init_stream(s, 8192 * 2);
|
|
||||||
cont = 1;
|
|
||||||
while (cont)
|
|
||||||
{
|
|
||||||
type = 0;
|
|
||||||
if (rdp_rdp_recv(mod->rdp_layer, s, &type) != 0)
|
|
||||||
{
|
{
|
||||||
DEBUG(("out lib_mod_signal error rdp_rdp_recv failed"));
|
make_stream(mod->in_s);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
DEBUG(("lib_mod_signal type %d", type));
|
|
||||||
switch (type)
|
s = mod->in_s;
|
||||||
|
init_stream(s, 8192 * 2);
|
||||||
|
cont = 1;
|
||||||
|
|
||||||
|
while (cont)
|
||||||
{
|
{
|
||||||
case RDP_PDU_DATA:
|
type = 0;
|
||||||
rdp_rdp_process_data_pdu(mod->rdp_layer, s);
|
|
||||||
break;
|
if (rdp_rdp_recv(mod->rdp_layer, s, &type) != 0)
|
||||||
case RDP_PDU_DEMAND_ACTIVE:
|
{
|
||||||
rdp_rdp_process_demand_active(mod->rdp_layer, s);
|
DEBUG(("out lib_mod_signal error rdp_rdp_recv failed"));
|
||||||
mod->up_and_running = 1;
|
return 1;
|
||||||
break;
|
}
|
||||||
case RDP_PDU_DEACTIVATE:
|
|
||||||
mod->up_and_running = 0;
|
DEBUG(("lib_mod_signal type %d", type));
|
||||||
break;
|
|
||||||
case RDP_PDU_REDIRECT:
|
switch (type)
|
||||||
break;
|
{
|
||||||
case 0:
|
case RDP_PDU_DATA:
|
||||||
break;
|
rdp_rdp_process_data_pdu(mod->rdp_layer, s);
|
||||||
default:
|
break;
|
||||||
break;
|
case RDP_PDU_DEMAND_ACTIVE:
|
||||||
|
rdp_rdp_process_demand_active(mod->rdp_layer, s);
|
||||||
|
mod->up_and_running = 1;
|
||||||
|
break;
|
||||||
|
case RDP_PDU_DEACTIVATE:
|
||||||
|
mod->up_and_running = 0;
|
||||||
|
break;
|
||||||
|
case RDP_PDU_REDIRECT:
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cont = s->next_packet < s->end;
|
||||||
}
|
}
|
||||||
cont = s->next_packet < s->end;
|
|
||||||
}
|
DEBUG(("out lib_mod_signal"));
|
||||||
DEBUG(("out lib_mod_signal"));
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_end(struct mod* mod)
|
lib_mod_end(struct mod *mod)
|
||||||
{
|
{
|
||||||
rdp_rdp_delete(mod->rdp_layer);
|
rdp_rdp_delete(mod->rdp_layer);
|
||||||
mod->rdp_layer = 0;
|
mod->rdp_layer = 0;
|
||||||
free_stream(mod->in_s);
|
free_stream(mod->in_s);
|
||||||
mod->in_s = 0;
|
mod->in_s = 0;
|
||||||
if (mod->sck_obj != 0)
|
|
||||||
{
|
|
||||||
g_delete_wait_obj_from_socket(mod->sck_obj);
|
|
||||||
mod->sck_obj = 0;
|
|
||||||
}
|
|
||||||
if (mod->sck != 0)
|
|
||||||
{
|
|
||||||
g_tcp_close(mod->sck);
|
|
||||||
mod->sck = 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
/* return error */
|
|
||||||
int DEFAULT_CC
|
|
||||||
lib_mod_set_param(struct mod* mod, char* name, char* value)
|
|
||||||
{
|
|
||||||
if (g_strncasecmp(name, "ip", 255) == 0)
|
|
||||||
{
|
|
||||||
g_strncpy(mod->ip, value, 255);
|
|
||||||
}
|
|
||||||
else if (g_strncasecmp(name, "port", 255) == 0)
|
|
||||||
{
|
|
||||||
g_strncpy(mod->port, value, 255);
|
|
||||||
}
|
|
||||||
else if (g_strncasecmp(name, "username", 255) == 0)
|
|
||||||
{
|
|
||||||
g_strncpy(mod->username, value, 255);
|
|
||||||
}
|
|
||||||
else if (g_strncasecmp(name, "password", 255) == 0)
|
|
||||||
{
|
|
||||||
g_strncpy(mod->password, value, 255);
|
|
||||||
}
|
|
||||||
else if (g_strncasecmp(name, "hostname", 255) == 0)
|
|
||||||
{
|
|
||||||
g_strncpy(mod->hostname, value, 255);
|
|
||||||
}
|
|
||||||
else if (g_strncasecmp(name, "keylayout", 255) == 0)
|
|
||||||
{
|
|
||||||
mod->keylayout = g_atoi(value);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
/* return error */
|
|
||||||
int DEFAULT_CC
|
|
||||||
lib_mod_get_wait_objs(struct mod* mod, tbus* read_objs, int* rcount,
|
|
||||||
tbus* write_objs, int* wcount, int* timeout)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = *rcount;
|
|
||||||
if (mod != 0)
|
|
||||||
{
|
|
||||||
if (mod->sck_obj != 0)
|
if (mod->sck_obj != 0)
|
||||||
{
|
{
|
||||||
read_objs[i++] = mod->sck_obj;
|
g_delete_wait_obj_from_socket(mod->sck_obj);
|
||||||
|
mod->sck_obj = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*rcount = i;
|
if (mod->sck != 0)
|
||||||
return 0;
|
{
|
||||||
|
g_tcp_close(mod->sck);
|
||||||
|
mod->sck = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* return error */
|
/* return error */
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
lib_mod_check_wait_objs(struct mod* mod)
|
lib_mod_set_param(struct mod *mod, char *name, char *value)
|
||||||
{
|
{
|
||||||
int rv;
|
if (g_strncasecmp(name, "ip", 255) == 0)
|
||||||
|
|
||||||
rv = 0;
|
|
||||||
if (mod != 0)
|
|
||||||
{
|
|
||||||
if (mod->sck_obj != 0)
|
|
||||||
{
|
{
|
||||||
if (g_is_wait_obj_set(mod->sck_obj))
|
g_strncpy(mod->ip, value, 255);
|
||||||
{
|
|
||||||
rv = lib_mod_signal(mod);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
else if (g_strncasecmp(name, "port", 255) == 0)
|
||||||
return rv;
|
{
|
||||||
|
g_strncpy(mod->port, value, 255);
|
||||||
|
}
|
||||||
|
else if (g_strncasecmp(name, "username", 255) == 0)
|
||||||
|
{
|
||||||
|
g_strncpy(mod->username, value, 255);
|
||||||
|
}
|
||||||
|
else if (g_strncasecmp(name, "password", 255) == 0)
|
||||||
|
{
|
||||||
|
g_strncpy(mod->password, value, 255);
|
||||||
|
}
|
||||||
|
else if (g_strncasecmp(name, "hostname", 255) == 0)
|
||||||
|
{
|
||||||
|
g_strncpy(mod->hostname, value, 255);
|
||||||
|
}
|
||||||
|
else if (g_strncasecmp(name, "keylayout", 255) == 0)
|
||||||
|
{
|
||||||
|
mod->keylayout = g_atoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
struct mod* EXPORT_CC
|
/* return error */
|
||||||
|
int DEFAULT_CC
|
||||||
|
lib_mod_get_wait_objs(struct mod *mod, tbus *read_objs, int *rcount,
|
||||||
|
tbus *write_objs, int *wcount, int *timeout)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = *rcount;
|
||||||
|
|
||||||
|
if (mod != 0)
|
||||||
|
{
|
||||||
|
if (mod->sck_obj != 0)
|
||||||
|
{
|
||||||
|
read_objs[i++] = mod->sck_obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*rcount = i;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/* return error */
|
||||||
|
int DEFAULT_CC
|
||||||
|
lib_mod_check_wait_objs(struct mod *mod)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv = 0;
|
||||||
|
|
||||||
|
if (mod != 0)
|
||||||
|
{
|
||||||
|
if (mod->sck_obj != 0)
|
||||||
|
{
|
||||||
|
if (g_is_wait_obj_set(mod->sck_obj))
|
||||||
|
{
|
||||||
|
rv = lib_mod_signal(mod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
struct mod *EXPORT_CC
|
||||||
mod_init(void)
|
mod_init(void)
|
||||||
{
|
{
|
||||||
struct mod* mod;
|
struct mod *mod;
|
||||||
|
|
||||||
DEBUG(("in mod_init"));
|
DEBUG(("in mod_init"));
|
||||||
mod = (struct mod*)g_malloc(sizeof(struct mod), 1);
|
mod = (struct mod *)g_malloc(sizeof(struct mod), 1);
|
||||||
mod->size = sizeof(struct mod);
|
mod->size = sizeof(struct mod);
|
||||||
mod->version = CURRENT_MOD_VER;
|
mod->version = CURRENT_MOD_VER;
|
||||||
mod->handle = (long)mod;
|
mod->handle = (long)mod;
|
||||||
mod->mod_connect = lib_mod_connect;
|
mod->mod_connect = lib_mod_connect;
|
||||||
mod->mod_start = lib_mod_start;
|
mod->mod_start = lib_mod_start;
|
||||||
mod->mod_event = lib_mod_event;
|
mod->mod_event = lib_mod_event;
|
||||||
mod->mod_signal = lib_mod_signal;
|
mod->mod_signal = lib_mod_signal;
|
||||||
mod->mod_end = lib_mod_end;
|
mod->mod_end = lib_mod_end;
|
||||||
mod->mod_set_param = lib_mod_set_param;
|
mod->mod_set_param = lib_mod_set_param;
|
||||||
mod->mod_get_wait_objs = lib_mod_get_wait_objs;
|
mod->mod_get_wait_objs = lib_mod_get_wait_objs;
|
||||||
mod->mod_check_wait_objs = lib_mod_check_wait_objs;
|
mod->mod_check_wait_objs = lib_mod_check_wait_objs;
|
||||||
mod->rdp_layer = rdp_rdp_create(mod);
|
mod->rdp_layer = rdp_rdp_create(mod);
|
||||||
DEBUG(("out mod_init"));
|
DEBUG(("out mod_init"));
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int EXPORT_CC
|
int EXPORT_CC
|
||||||
mod_exit(struct mod* mod)
|
mod_exit(struct mod *mod)
|
||||||
{
|
{
|
||||||
DEBUG(("in mod_exit"));
|
DEBUG(("in mod_exit"));
|
||||||
g_free(mod);
|
g_free(mod);
|
||||||
DEBUG(("out mod_exit"));
|
DEBUG(("out mod_exit"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*
|
||||||
|
* librdp main header file
|
||||||
librdp main header file
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* include other h files */
|
/* include other h files */
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
|
|||||||
+903
-832
File diff suppressed because it is too large
Load Diff
+184
-164
@@ -1,219 +1,239 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*
|
||||||
|
* librdp iso layer
|
||||||
librdp iso layer
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "rdp.h"
|
#include "rdp.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct rdp_iso* APP_CC
|
struct rdp_iso *APP_CC
|
||||||
rdp_iso_create(struct rdp_mcs* owner)
|
rdp_iso_create(struct rdp_mcs *owner)
|
||||||
{
|
{
|
||||||
struct rdp_iso* self;
|
struct rdp_iso *self;
|
||||||
|
|
||||||
self = (struct rdp_iso*)g_malloc(sizeof(struct rdp_iso), 1);
|
self = (struct rdp_iso *)g_malloc(sizeof(struct rdp_iso), 1);
|
||||||
self->mcs_layer = owner;
|
self->mcs_layer = owner;
|
||||||
self->tcp_layer = rdp_tcp_create(self);
|
self->tcp_layer = rdp_tcp_create(self);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
rdp_iso_delete(struct rdp_iso* self)
|
rdp_iso_delete(struct rdp_iso *self)
|
||||||
{
|
{
|
||||||
if (self == 0)
|
if (self == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rdp_tcp_delete(self->tcp_layer);
|
|
||||||
g_free(self);
|
rdp_tcp_delete(self->tcp_layer);
|
||||||
|
g_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
rdp_iso_recv_msg(struct rdp_iso* self, struct stream* s, int* code)
|
rdp_iso_recv_msg(struct rdp_iso *self, struct stream *s, int *code)
|
||||||
{
|
{
|
||||||
int ver;
|
int ver;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
*code = 0;
|
||||||
|
|
||||||
|
if (rdp_tcp_recv(self->tcp_layer, s, 4) != 0)
|
||||||
|
{
|
||||||
|
DEBUG((" out rdp_iso_recv_msg error rdp_tcp_recv 1 failed"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint8(s, ver);
|
||||||
|
|
||||||
|
if (ver != 3)
|
||||||
|
{
|
||||||
|
DEBUG((" out rdp_iso_recv_msg error ver != 3"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
*code = 0;
|
|
||||||
if (rdp_tcp_recv(self->tcp_layer, s, 4) != 0)
|
|
||||||
{
|
|
||||||
DEBUG((" out rdp_iso_recv_msg error rdp_tcp_recv 1 failed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
in_uint8(s, ver);
|
|
||||||
if (ver != 3)
|
|
||||||
{
|
|
||||||
DEBUG((" out rdp_iso_recv_msg error ver != 3"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
in_uint8s(s, 1);
|
|
||||||
in_uint16_be(s, len);
|
|
||||||
if (rdp_tcp_recv(self->tcp_layer, s, len - 4) != 0)
|
|
||||||
{
|
|
||||||
DEBUG((" out rdp_iso_recv_msg error rdp_tcp_recv 2 failed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
in_uint8s(s, 1);
|
|
||||||
in_uint8(s, *code);
|
|
||||||
if (*code == ISO_PDU_DT)
|
|
||||||
{
|
|
||||||
in_uint8s(s, 1);
|
in_uint8s(s, 1);
|
||||||
}
|
in_uint16_be(s, len);
|
||||||
else
|
|
||||||
{
|
if (rdp_tcp_recv(self->tcp_layer, s, len - 4) != 0)
|
||||||
in_uint8s(s, 5);
|
{
|
||||||
}
|
DEBUG((" out rdp_iso_recv_msg error rdp_tcp_recv 2 failed"));
|
||||||
return 0;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint8s(s, 1);
|
||||||
|
in_uint8(s, *code);
|
||||||
|
|
||||||
|
if (*code == ISO_PDU_DT)
|
||||||
|
{
|
||||||
|
in_uint8s(s, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in_uint8s(s, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
rdp_iso_send_msg(struct rdp_iso* self, struct stream* s, int code)
|
rdp_iso_send_msg(struct rdp_iso *self, struct stream *s, int code)
|
||||||
{
|
{
|
||||||
if (rdp_tcp_init(self->tcp_layer, s) != 0)
|
if (rdp_tcp_init(self->tcp_layer, s) != 0)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
out_uint8(s, 3);
|
|
||||||
out_uint8(s, 0);
|
out_uint8(s, 3);
|
||||||
out_uint16_be(s, 11); /* length */
|
out_uint8(s, 0);
|
||||||
out_uint8(s, 6);
|
out_uint16_be(s, 11); /* length */
|
||||||
out_uint8(s, code);
|
out_uint8(s, 6);
|
||||||
out_uint16_le(s, 0);
|
out_uint8(s, code);
|
||||||
out_uint16_le(s, 0);
|
out_uint16_le(s, 0);
|
||||||
out_uint8(s, 0);
|
out_uint16_le(s, 0);
|
||||||
s_mark_end(s);
|
out_uint8(s, 0);
|
||||||
if (rdp_tcp_send(self->tcp_layer, s) != 0)
|
s_mark_end(s);
|
||||||
{
|
|
||||||
return 1;
|
if (rdp_tcp_send(self->tcp_layer, s) != 0)
|
||||||
}
|
{
|
||||||
return 0;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
rdp_iso_recv(struct rdp_iso* self, struct stream* s)
|
rdp_iso_recv(struct rdp_iso *self, struct stream *s)
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
|
|
||||||
if (rdp_iso_recv_msg(self, s, &code) != 0)
|
if (rdp_iso_recv_msg(self, s, &code) != 0)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (code != ISO_PDU_DT)
|
|
||||||
{
|
if (code != ISO_PDU_DT)
|
||||||
return 1;
|
{
|
||||||
}
|
return 1;
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
rdp_iso_init(struct rdp_iso* self, struct stream* s)
|
rdp_iso_init(struct rdp_iso *self, struct stream *s)
|
||||||
{
|
{
|
||||||
rdp_tcp_init(self->tcp_layer, s);
|
rdp_tcp_init(self->tcp_layer, s);
|
||||||
s_push_layer(s, iso_hdr, 7);
|
s_push_layer(s, iso_hdr, 7);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
rdp_iso_send(struct rdp_iso* self, struct stream* s)
|
rdp_iso_send(struct rdp_iso *self, struct stream *s)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
s_pop_layer(s, iso_hdr);
|
s_pop_layer(s, iso_hdr);
|
||||||
len = s->end - s->p;
|
len = s->end - s->p;
|
||||||
out_uint8(s, 3);
|
out_uint8(s, 3);
|
||||||
out_uint8(s, 0);
|
out_uint8(s, 0);
|
||||||
out_uint16_be(s, len);
|
out_uint16_be(s, len);
|
||||||
out_uint8(s, 2);
|
out_uint8(s, 2);
|
||||||
out_uint8(s, ISO_PDU_DT);
|
out_uint8(s, ISO_PDU_DT);
|
||||||
out_uint8(s, 0x80);
|
out_uint8(s, 0x80);
|
||||||
if (rdp_tcp_send(self->tcp_layer, s) != 0)
|
|
||||||
{
|
if (rdp_tcp_send(self->tcp_layer, s) != 0)
|
||||||
return 1;
|
{
|
||||||
}
|
return 1;
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
rdp_iso_connect(struct rdp_iso* self, char* ip, char* port)
|
rdp_iso_connect(struct rdp_iso *self, char *ip, char *port)
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
|
|
||||||
|
DEBUG((" in rdp_iso_connect"));
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, 8192);
|
||||||
|
|
||||||
|
if (rdp_tcp_connect(self->tcp_layer, ip, port) != 0)
|
||||||
|
{
|
||||||
|
free_stream(s);
|
||||||
|
DEBUG((" out rdp_iso_connect error rdp_tcp_connect failed"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rdp_iso_send_msg(self, s, ISO_PDU_CR) != 0)
|
||||||
|
{
|
||||||
|
free_stream(s);
|
||||||
|
rdp_tcp_disconnect(self->tcp_layer);
|
||||||
|
DEBUG((" out rdp_iso_connect error rdp_iso_send_msg failed"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_stream(s, 8192);
|
||||||
|
|
||||||
|
if (rdp_iso_recv_msg(self, s, &code) != 0)
|
||||||
|
{
|
||||||
|
free_stream(s);
|
||||||
|
rdp_tcp_disconnect(self->tcp_layer);
|
||||||
|
DEBUG((" out rdp_iso_connect error rdp_iso_recv_msg failed"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code != ISO_PDU_CC)
|
||||||
|
{
|
||||||
|
free_stream(s);
|
||||||
|
rdp_tcp_disconnect(self->tcp_layer);
|
||||||
|
DEBUG((" out rdp_iso_connect error code != ISO_PDU_CC"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG((" in rdp_iso_connect"));
|
|
||||||
make_stream(s);
|
|
||||||
init_stream(s, 8192);
|
|
||||||
if (rdp_tcp_connect(self->tcp_layer, ip, port) != 0)
|
|
||||||
{
|
|
||||||
free_stream(s);
|
|
||||||
DEBUG((" out rdp_iso_connect error rdp_tcp_connect failed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (rdp_iso_send_msg(self, s, ISO_PDU_CR) != 0)
|
|
||||||
{
|
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
|
DEBUG((" out rdp_iso_connect"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
rdp_iso_disconnect(struct rdp_iso *self)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, 8192);
|
||||||
|
rdp_iso_send_msg(self, s, ISO_PDU_DR);
|
||||||
rdp_tcp_disconnect(self->tcp_layer);
|
rdp_tcp_disconnect(self->tcp_layer);
|
||||||
DEBUG((" out rdp_iso_connect error rdp_iso_send_msg failed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
init_stream(s, 8192);
|
|
||||||
if (rdp_iso_recv_msg(self, s, &code) != 0)
|
|
||||||
{
|
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
rdp_tcp_disconnect(self->tcp_layer);
|
return 0;
|
||||||
DEBUG((" out rdp_iso_connect error rdp_iso_recv_msg failed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (code != ISO_PDU_CC)
|
|
||||||
{
|
|
||||||
free_stream(s);
|
|
||||||
rdp_tcp_disconnect(self->tcp_layer);
|
|
||||||
DEBUG((" out rdp_iso_connect error code != ISO_PDU_CC"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
free_stream(s);
|
|
||||||
DEBUG((" out rdp_iso_connect"));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int APP_CC
|
|
||||||
rdp_iso_disconnect(struct rdp_iso* self)
|
|
||||||
{
|
|
||||||
struct stream* s;
|
|
||||||
|
|
||||||
make_stream(s);
|
|
||||||
init_stream(s, 8192);
|
|
||||||
rdp_iso_send_msg(self, s, ISO_PDU_DR);
|
|
||||||
rdp_tcp_disconnect(self->tcp_layer);
|
|
||||||
free_stream(s);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+285
-274
@@ -1,358 +1,369 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*
|
||||||
|
* licence
|
||||||
licence
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "rdp.h"
|
#include "rdp.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct rdp_lic* APP_CC
|
struct rdp_lic *APP_CC
|
||||||
rdp_lic_create(struct rdp_sec* owner)
|
rdp_lic_create(struct rdp_sec *owner)
|
||||||
{
|
{
|
||||||
struct rdp_lic* self;
|
struct rdp_lic *self;
|
||||||
|
|
||||||
self = (struct rdp_lic*)g_malloc(sizeof(struct rdp_lic), 1);
|
self = (struct rdp_lic *)g_malloc(sizeof(struct rdp_lic), 1);
|
||||||
self->sec_layer = owner;
|
self->sec_layer = owner;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
rdp_lic_delete(struct rdp_lic* self)
|
rdp_lic_delete(struct rdp_lic *self)
|
||||||
{
|
{
|
||||||
if (self == 0)
|
if (self == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g_free(self);
|
|
||||||
|
g_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Generate a session key and RC4 keys, given client and server randoms */
|
/* Generate a session key and RC4 keys, given client and server randoms */
|
||||||
static void APP_CC
|
static void APP_CC
|
||||||
rdp_lic_generate_keys(struct rdp_lic* self, char* client_random,
|
rdp_lic_generate_keys(struct rdp_lic *self, char *client_random,
|
||||||
char* server_random, char* pre_master_secret)
|
char *server_random, char *pre_master_secret)
|
||||||
{
|
{
|
||||||
char master_secret[48];
|
char master_secret[48];
|
||||||
char key_block[48];
|
char key_block[48];
|
||||||
|
|
||||||
/* Generate master secret and then key material */
|
/* Generate master secret and then key material */
|
||||||
rdp_sec_hash_48(master_secret, pre_master_secret, client_random,
|
rdp_sec_hash_48(master_secret, pre_master_secret, client_random,
|
||||||
server_random, 65);
|
server_random, 65);
|
||||||
rdp_sec_hash_48(key_block, master_secret, server_random,
|
rdp_sec_hash_48(key_block, master_secret, server_random,
|
||||||
client_random, 65);
|
client_random, 65);
|
||||||
/* Store first 16 bytes of session key as MAC secret */
|
/* Store first 16 bytes of session key as MAC secret */
|
||||||
g_memcpy(self->licence_sign_key, key_block, 16);
|
g_memcpy(self->licence_sign_key, key_block, 16);
|
||||||
/* Generate RC4 key from next 16 bytes */
|
/* Generate RC4 key from next 16 bytes */
|
||||||
rdp_sec_hash_16(self->licence_key, key_block + 16, client_random,
|
rdp_sec_hash_16(self->licence_key, key_block + 16, client_random,
|
||||||
server_random);
|
server_random);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static void APP_CC
|
static void APP_CC
|
||||||
rdp_lic_generate_hwid(struct rdp_lic* self, char* hwid)
|
rdp_lic_generate_hwid(struct rdp_lic *self, char *hwid)
|
||||||
{
|
{
|
||||||
rdp_sec_buf_out_uint32(hwid, 2);
|
rdp_sec_buf_out_uint32(hwid, 2);
|
||||||
g_strncpy(hwid + 4, self->sec_layer->rdp_layer->mod->hostname,
|
g_strncpy(hwid + 4, self->sec_layer->rdp_layer->mod->hostname,
|
||||||
LICENCE_HWID_SIZE - 4);
|
LICENCE_HWID_SIZE - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Present an existing licence to the server */
|
/* Present an existing licence to the server */
|
||||||
static void APP_CC
|
static void APP_CC
|
||||||
rdp_lic_present(struct rdp_lic* self, char* client_random, char* rsa_data,
|
rdp_lic_present(struct rdp_lic *self, char *client_random, char *rsa_data,
|
||||||
char* licence_data, int licence_size, char* hwid,
|
char *licence_data, int licence_size, char *hwid,
|
||||||
char* signature)
|
char *signature)
|
||||||
{
|
{
|
||||||
int sec_flags;
|
int sec_flags;
|
||||||
int length;
|
int length;
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
|
|
||||||
sec_flags = SEC_LICENCE_NEG;
|
sec_flags = SEC_LICENCE_NEG;
|
||||||
length = 16 + SEC_RANDOM_SIZE + SEC_MODULUS_SIZE + SEC_PADDING_SIZE +
|
length = 16 + SEC_RANDOM_SIZE + SEC_MODULUS_SIZE + SEC_PADDING_SIZE +
|
||||||
licence_size + LICENCE_HWID_SIZE + LICENCE_SIGNATURE_SIZE;
|
licence_size + LICENCE_HWID_SIZE + LICENCE_SIGNATURE_SIZE;
|
||||||
make_stream(s);
|
make_stream(s);
|
||||||
init_stream(s, 8192);
|
init_stream(s, 8192);
|
||||||
rdp_sec_init(self->sec_layer, s, sec_flags);
|
rdp_sec_init(self->sec_layer, s, sec_flags);
|
||||||
out_uint8(s, LICENCE_TAG_PRESENT);
|
out_uint8(s, LICENCE_TAG_PRESENT);
|
||||||
out_uint8(s, 2); /* version */
|
out_uint8(s, 2); /* version */
|
||||||
out_uint16_le(s, length);
|
out_uint16_le(s, length);
|
||||||
out_uint32_le(s, 1);
|
out_uint32_le(s, 1);
|
||||||
out_uint16_le(s, 0);
|
out_uint16_le(s, 0);
|
||||||
out_uint16_le(s, 0x0201);
|
out_uint16_le(s, 0x0201);
|
||||||
out_uint8p(s, client_random, SEC_RANDOM_SIZE);
|
out_uint8p(s, client_random, SEC_RANDOM_SIZE);
|
||||||
out_uint16_le(s, 0);
|
out_uint16_le(s, 0);
|
||||||
out_uint16_le(s, (SEC_MODULUS_SIZE + SEC_PADDING_SIZE));
|
out_uint16_le(s, (SEC_MODULUS_SIZE + SEC_PADDING_SIZE));
|
||||||
out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
|
out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
|
||||||
out_uint8s(s, SEC_PADDING_SIZE);
|
out_uint8s(s, SEC_PADDING_SIZE);
|
||||||
out_uint16_le(s, 1);
|
out_uint16_le(s, 1);
|
||||||
out_uint16_le(s, licence_size);
|
out_uint16_le(s, licence_size);
|
||||||
out_uint8p(s, licence_data, licence_size);
|
out_uint8p(s, licence_data, licence_size);
|
||||||
out_uint16_le(s, 1);
|
out_uint16_le(s, 1);
|
||||||
out_uint16_le(s, LICENCE_HWID_SIZE);
|
out_uint16_le(s, LICENCE_HWID_SIZE);
|
||||||
out_uint8p(s, hwid, LICENCE_HWID_SIZE);
|
out_uint8p(s, hwid, LICENCE_HWID_SIZE);
|
||||||
out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
|
out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
|
||||||
s_mark_end(s);
|
s_mark_end(s);
|
||||||
rdp_sec_send(self->sec_layer, s, sec_flags);
|
rdp_sec_send(self->sec_layer, s, sec_flags);
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Send a licence request packet */
|
/* Send a licence request packet */
|
||||||
static void APP_CC
|
static void APP_CC
|
||||||
rdp_lic_send_request(struct rdp_lic* self, char* client_random,
|
rdp_lic_send_request(struct rdp_lic *self, char *client_random,
|
||||||
char* rsa_data, char* user, char* host)
|
char *rsa_data, char *user, char *host)
|
||||||
{
|
{
|
||||||
int sec_flags;
|
int sec_flags;
|
||||||
int userlen;
|
int userlen;
|
||||||
int hostlen;
|
int hostlen;
|
||||||
int length;
|
int length;
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
|
|
||||||
sec_flags = SEC_LICENCE_NEG;
|
sec_flags = SEC_LICENCE_NEG;
|
||||||
userlen = g_strlen(user) + 1;
|
userlen = g_strlen(user) + 1;
|
||||||
hostlen = g_strlen(host) + 1;
|
hostlen = g_strlen(host) + 1;
|
||||||
length = 128 + userlen + hostlen;
|
length = 128 + userlen + hostlen;
|
||||||
make_stream(s);
|
make_stream(s);
|
||||||
init_stream(s, 8192);
|
init_stream(s, 8192);
|
||||||
rdp_sec_init(self->sec_layer, s, sec_flags);
|
rdp_sec_init(self->sec_layer, s, sec_flags);
|
||||||
out_uint8(s, LICENCE_TAG_REQUEST);
|
out_uint8(s, LICENCE_TAG_REQUEST);
|
||||||
out_uint8(s, 2); /* version */
|
out_uint8(s, 2); /* version */
|
||||||
out_uint16_le(s, length);
|
out_uint16_le(s, length);
|
||||||
out_uint32_le(s, 1);
|
out_uint32_le(s, 1);
|
||||||
out_uint16_le(s, 0);
|
out_uint16_le(s, 0);
|
||||||
out_uint16_le(s, 0xff01);
|
out_uint16_le(s, 0xff01);
|
||||||
out_uint8p(s, client_random, SEC_RANDOM_SIZE);
|
out_uint8p(s, client_random, SEC_RANDOM_SIZE);
|
||||||
out_uint16_le(s, 0);
|
out_uint16_le(s, 0);
|
||||||
out_uint16_le(s, (SEC_MODULUS_SIZE + SEC_PADDING_SIZE));
|
out_uint16_le(s, (SEC_MODULUS_SIZE + SEC_PADDING_SIZE));
|
||||||
out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
|
out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
|
||||||
out_uint8s(s, SEC_PADDING_SIZE);
|
out_uint8s(s, SEC_PADDING_SIZE);
|
||||||
out_uint16_le(s, LICENCE_TAG_USER);
|
out_uint16_le(s, LICENCE_TAG_USER);
|
||||||
out_uint16_le(s, userlen);
|
out_uint16_le(s, userlen);
|
||||||
out_uint8p(s, user, userlen);
|
out_uint8p(s, user, userlen);
|
||||||
out_uint16_le(s, LICENCE_TAG_HOST);
|
out_uint16_le(s, LICENCE_TAG_HOST);
|
||||||
out_uint16_le(s, hostlen);
|
out_uint16_le(s, hostlen);
|
||||||
out_uint8p(s, host, hostlen);
|
out_uint8p(s, host, hostlen);
|
||||||
s_mark_end(s);
|
s_mark_end(s);
|
||||||
rdp_sec_send(self->sec_layer, s, sec_flags);
|
rdp_sec_send(self->sec_layer, s, sec_flags);
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Process a licence demand packet */
|
/* Process a licence demand packet */
|
||||||
static void APP_CC
|
static void APP_CC
|
||||||
rdp_lic_process_demand(struct rdp_lic* self, struct stream* s)
|
rdp_lic_process_demand(struct rdp_lic *self, struct stream *s)
|
||||||
{
|
{
|
||||||
char null_data[SEC_MODULUS_SIZE];
|
char null_data[SEC_MODULUS_SIZE];
|
||||||
char* server_random;
|
char *server_random;
|
||||||
char signature[LICENCE_SIGNATURE_SIZE];
|
char signature[LICENCE_SIGNATURE_SIZE];
|
||||||
char hwid[LICENCE_HWID_SIZE];
|
char hwid[LICENCE_HWID_SIZE];
|
||||||
char* licence_data;
|
char *licence_data;
|
||||||
int licence_size;
|
int licence_size;
|
||||||
void* crypt_key;
|
void *crypt_key;
|
||||||
|
|
||||||
licence_data = 0;
|
licence_data = 0;
|
||||||
/* Retrieve the server random from the incoming packet */
|
/* Retrieve the server random from the incoming packet */
|
||||||
in_uint8p(s, server_random, SEC_RANDOM_SIZE);
|
in_uint8p(s, server_random, SEC_RANDOM_SIZE);
|
||||||
/* We currently use null client keys. This is a bit naughty but, hey,
|
/* We currently use null client keys. This is a bit naughty but, hey,
|
||||||
the security of licence negotiation isn't exactly paramount. */
|
the security of licence negotiation isn't exactly paramount. */
|
||||||
g_memset(null_data, 0, sizeof(null_data));
|
g_memset(null_data, 0, sizeof(null_data));
|
||||||
rdp_lic_generate_keys(self, null_data, server_random, null_data);
|
rdp_lic_generate_keys(self, null_data, server_random, null_data);
|
||||||
licence_size = 0; /* todo load_licence(&licence_data); */
|
licence_size = 0; /* todo load_licence(&licence_data); */
|
||||||
if (licence_size > 0)
|
|
||||||
{
|
if (licence_size > 0)
|
||||||
/* Generate a signature for the HWID buffer */
|
{
|
||||||
rdp_lic_generate_hwid(self, hwid);
|
/* Generate a signature for the HWID buffer */
|
||||||
rdp_sec_sign(signature, 16, self->licence_sign_key, 16,
|
rdp_lic_generate_hwid(self, hwid);
|
||||||
hwid, sizeof(hwid));
|
rdp_sec_sign(signature, 16, self->licence_sign_key, 16,
|
||||||
/* Now encrypt the HWID */
|
hwid, sizeof(hwid));
|
||||||
crypt_key = ssl_rc4_info_create();
|
/* Now encrypt the HWID */
|
||||||
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
|
crypt_key = ssl_rc4_info_create();
|
||||||
ssl_rc4_crypt(crypt_key, hwid, sizeof(hwid));
|
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
|
||||||
ssl_rc4_info_delete(crypt_key);
|
ssl_rc4_crypt(crypt_key, hwid, sizeof(hwid));
|
||||||
rdp_lic_present(self, null_data, null_data, licence_data,
|
ssl_rc4_info_delete(crypt_key);
|
||||||
licence_size, hwid, signature);
|
rdp_lic_present(self, null_data, null_data, licence_data,
|
||||||
g_free(licence_data);
|
licence_size, hwid, signature);
|
||||||
return;
|
g_free(licence_data);
|
||||||
}
|
return;
|
||||||
rdp_lic_send_request(self, null_data, null_data,
|
}
|
||||||
self->sec_layer->rdp_layer->mod->username,
|
|
||||||
self->sec_layer->rdp_layer->mod->hostname);
|
rdp_lic_send_request(self, null_data, null_data,
|
||||||
|
self->sec_layer->rdp_layer->mod->username,
|
||||||
|
self->sec_layer->rdp_layer->mod->hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Send an authentication response packet */
|
/* Send an authentication response packet */
|
||||||
static void APP_CC
|
static void APP_CC
|
||||||
rdp_lic_send_authresp(struct rdp_lic* self, char* token, char* crypt_hwid,
|
rdp_lic_send_authresp(struct rdp_lic *self, char *token, char *crypt_hwid,
|
||||||
char* signature)
|
char *signature)
|
||||||
{
|
{
|
||||||
int sec_flags;
|
int sec_flags;
|
||||||
int length;
|
int length;
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
|
|
||||||
sec_flags = SEC_LICENCE_NEG;
|
sec_flags = SEC_LICENCE_NEG;
|
||||||
length = 58;
|
length = 58;
|
||||||
make_stream(s);
|
make_stream(s);
|
||||||
init_stream(s, 8192);
|
init_stream(s, 8192);
|
||||||
rdp_sec_init(self->sec_layer, s, sec_flags);
|
rdp_sec_init(self->sec_layer, s, sec_flags);
|
||||||
out_uint8(s, LICENCE_TAG_AUTHRESP);
|
out_uint8(s, LICENCE_TAG_AUTHRESP);
|
||||||
out_uint8(s, 2); /* version */
|
out_uint8(s, 2); /* version */
|
||||||
out_uint16_le(s, length);
|
out_uint16_le(s, length);
|
||||||
out_uint16_le(s, 1);
|
out_uint16_le(s, 1);
|
||||||
out_uint16_le(s, LICENCE_TOKEN_SIZE);
|
out_uint16_le(s, LICENCE_TOKEN_SIZE);
|
||||||
out_uint8p(s, token, LICENCE_TOKEN_SIZE);
|
out_uint8p(s, token, LICENCE_TOKEN_SIZE);
|
||||||
out_uint16_le(s, 1);
|
out_uint16_le(s, 1);
|
||||||
out_uint16_le(s, LICENCE_HWID_SIZE);
|
out_uint16_le(s, LICENCE_HWID_SIZE);
|
||||||
out_uint8p(s, crypt_hwid, LICENCE_HWID_SIZE);
|
out_uint8p(s, crypt_hwid, LICENCE_HWID_SIZE);
|
||||||
out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
|
out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
|
||||||
s_mark_end(s);
|
s_mark_end(s);
|
||||||
rdp_sec_send(self->sec_layer, s, sec_flags);
|
rdp_sec_send(self->sec_layer, s, sec_flags);
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Parse an authentication request packet */
|
/* Parse an authentication request packet */
|
||||||
/* returns boolean */
|
/* returns boolean */
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
rdp_lic_parse_authreq(struct rdp_lic* self, struct stream* s,
|
rdp_lic_parse_authreq(struct rdp_lic *self, struct stream *s,
|
||||||
char** token, char** signature)
|
char **token, char **signature)
|
||||||
{
|
{
|
||||||
int tokenlen;
|
int tokenlen;
|
||||||
|
|
||||||
in_uint8s(s, 6); /* unknown: f8 3d 15 00 04 f6 */
|
in_uint8s(s, 6); /* unknown: f8 3d 15 00 04 f6 */
|
||||||
in_uint16_le(s, tokenlen);
|
in_uint16_le(s, tokenlen);
|
||||||
if (tokenlen != LICENCE_TOKEN_SIZE)
|
|
||||||
{
|
if (tokenlen != LICENCE_TOKEN_SIZE)
|
||||||
/* error("token len %d\n", tokenlen); */
|
{
|
||||||
return 0;
|
/* error("token len %d\n", tokenlen); */
|
||||||
}
|
return 0;
|
||||||
in_uint8p(s, *token, tokenlen);
|
}
|
||||||
in_uint8p(s, *signature, LICENCE_SIGNATURE_SIZE);
|
|
||||||
return s_check_end(s);
|
in_uint8p(s, *token, tokenlen);
|
||||||
|
in_uint8p(s, *signature, LICENCE_SIGNATURE_SIZE);
|
||||||
|
return s_check_end(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Process an authentication request packet */
|
/* Process an authentication request packet */
|
||||||
static void APP_CC
|
static void APP_CC
|
||||||
rdp_lic_process_authreq(struct rdp_lic* self, struct stream* s)
|
rdp_lic_process_authreq(struct rdp_lic *self, struct stream *s)
|
||||||
{
|
{
|
||||||
char* in_token;
|
char *in_token;
|
||||||
char* in_sig;
|
char *in_sig;
|
||||||
char out_token[LICENCE_TOKEN_SIZE];
|
char out_token[LICENCE_TOKEN_SIZE];
|
||||||
char decrypt_token[LICENCE_TOKEN_SIZE];
|
char decrypt_token[LICENCE_TOKEN_SIZE];
|
||||||
char hwid[LICENCE_HWID_SIZE];
|
char hwid[LICENCE_HWID_SIZE];
|
||||||
char crypt_hwid[LICENCE_HWID_SIZE];
|
char crypt_hwid[LICENCE_HWID_SIZE];
|
||||||
char sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE];
|
char sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE];
|
||||||
char out_sig[LICENCE_SIGNATURE_SIZE];
|
char out_sig[LICENCE_SIGNATURE_SIZE];
|
||||||
void* crypt_key;
|
void *crypt_key;
|
||||||
|
|
||||||
in_token = 0;
|
in_token = 0;
|
||||||
in_sig = 0;
|
in_sig = 0;
|
||||||
/* Parse incoming packet and save the encrypted token */
|
/* Parse incoming packet and save the encrypted token */
|
||||||
rdp_lic_parse_authreq(self, s, &in_token, &in_sig);
|
rdp_lic_parse_authreq(self, s, &in_token, &in_sig);
|
||||||
g_memcpy(out_token, in_token, LICENCE_TOKEN_SIZE);
|
g_memcpy(out_token, in_token, LICENCE_TOKEN_SIZE);
|
||||||
/* Decrypt the token. It should read TEST in Unicode. */
|
/* Decrypt the token. It should read TEST in Unicode. */
|
||||||
crypt_key = ssl_rc4_info_create();
|
crypt_key = ssl_rc4_info_create();
|
||||||
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
|
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
|
||||||
g_memcpy(decrypt_token, in_token, LICENCE_TOKEN_SIZE);
|
g_memcpy(decrypt_token, in_token, LICENCE_TOKEN_SIZE);
|
||||||
ssl_rc4_crypt(crypt_key, decrypt_token, LICENCE_TOKEN_SIZE);
|
ssl_rc4_crypt(crypt_key, decrypt_token, LICENCE_TOKEN_SIZE);
|
||||||
/* Generate a signature for a buffer of token and HWID */
|
/* Generate a signature for a buffer of token and HWID */
|
||||||
rdp_lic_generate_hwid(self, hwid);
|
rdp_lic_generate_hwid(self, hwid);
|
||||||
g_memcpy(sealed_buffer, decrypt_token, LICENCE_TOKEN_SIZE);
|
g_memcpy(sealed_buffer, decrypt_token, LICENCE_TOKEN_SIZE);
|
||||||
g_memcpy(sealed_buffer + LICENCE_TOKEN_SIZE, hwid, LICENCE_HWID_SIZE);
|
g_memcpy(sealed_buffer + LICENCE_TOKEN_SIZE, hwid, LICENCE_HWID_SIZE);
|
||||||
rdp_sec_sign(out_sig, 16, self->licence_sign_key, 16, sealed_buffer,
|
rdp_sec_sign(out_sig, 16, self->licence_sign_key, 16, sealed_buffer,
|
||||||
sizeof(sealed_buffer));
|
sizeof(sealed_buffer));
|
||||||
/* Now encrypt the HWID */
|
/* Now encrypt the HWID */
|
||||||
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
|
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
|
||||||
g_memcpy(crypt_hwid, hwid, LICENCE_HWID_SIZE);
|
g_memcpy(crypt_hwid, hwid, LICENCE_HWID_SIZE);
|
||||||
ssl_rc4_crypt(crypt_key, crypt_hwid, LICENCE_HWID_SIZE);
|
ssl_rc4_crypt(crypt_key, crypt_hwid, LICENCE_HWID_SIZE);
|
||||||
rdp_lic_send_authresp(self, out_token, crypt_hwid, out_sig);
|
rdp_lic_send_authresp(self, out_token, crypt_hwid, out_sig);
|
||||||
ssl_rc4_info_delete(crypt_key);
|
ssl_rc4_info_delete(crypt_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Process an licence issue packet */
|
/* Process an licence issue packet */
|
||||||
static void APP_CC
|
static void APP_CC
|
||||||
rdp_lic_process_issue(struct rdp_lic* self, struct stream* s)
|
rdp_lic_process_issue(struct rdp_lic *self, struct stream *s)
|
||||||
{
|
{
|
||||||
void* crypt_key;
|
void *crypt_key;
|
||||||
int length;
|
int length;
|
||||||
int check;
|
int check;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
in_uint8s(s, 2); /* 3d 45 - unknown */
|
||||||
|
in_uint16_le(s, length);
|
||||||
|
|
||||||
in_uint8s(s, 2); /* 3d 45 - unknown */
|
|
||||||
in_uint16_le(s, length);
|
|
||||||
if (!s_check_rem(s, length))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
crypt_key = ssl_rc4_info_create();
|
|
||||||
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
|
|
||||||
ssl_rc4_crypt(crypt_key, s->p, length);
|
|
||||||
ssl_rc4_info_delete(crypt_key);
|
|
||||||
in_uint16_le(s, check);
|
|
||||||
if (check != 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self->licence_issued = 1;
|
|
||||||
in_uint8s(s, 2); /* pad */
|
|
||||||
/* advance to fourth string */
|
|
||||||
length = 0;
|
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
in_uint8s(s, length);
|
|
||||||
in_uint32_le(s, length);
|
|
||||||
if (!s_check_rem(s, length))
|
if (!s_check_rem(s, length))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/* todo save_licence(s->p, length); */
|
crypt_key = ssl_rc4_info_create();
|
||||||
|
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
|
||||||
|
ssl_rc4_crypt(crypt_key, s->p, length);
|
||||||
|
ssl_rc4_info_delete(crypt_key);
|
||||||
|
in_uint16_le(s, check);
|
||||||
|
|
||||||
|
if (check != 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->licence_issued = 1;
|
||||||
|
in_uint8s(s, 2); /* pad */
|
||||||
|
/* advance to fourth string */
|
||||||
|
length = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
in_uint8s(s, length);
|
||||||
|
in_uint32_le(s, length);
|
||||||
|
|
||||||
|
if (!s_check_rem(s, length))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* todo save_licence(s->p, length); */
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* Process a licence packet */
|
/* Process a licence packet */
|
||||||
void APP_CC
|
void APP_CC
|
||||||
rdp_lic_process(struct rdp_lic* self, struct stream* s)
|
rdp_lic_process(struct rdp_lic *self, struct stream *s)
|
||||||
{
|
{
|
||||||
int tag;
|
int tag;
|
||||||
|
|
||||||
in_uint8(s, tag);
|
in_uint8(s, tag);
|
||||||
in_uint8s(s, 3); /* version, length */
|
in_uint8s(s, 3); /* version, length */
|
||||||
switch (tag)
|
|
||||||
{
|
switch (tag)
|
||||||
case LICENCE_TAG_DEMAND:
|
{
|
||||||
rdp_lic_process_demand(self, s);
|
case LICENCE_TAG_DEMAND:
|
||||||
break;
|
rdp_lic_process_demand(self, s);
|
||||||
case LICENCE_TAG_AUTHREQ:
|
break;
|
||||||
rdp_lic_process_authreq(self, s);
|
case LICENCE_TAG_AUTHREQ:
|
||||||
break;
|
rdp_lic_process_authreq(self, s);
|
||||||
case LICENCE_TAG_ISSUE:
|
break;
|
||||||
rdp_lic_process_issue(self, s);
|
case LICENCE_TAG_ISSUE:
|
||||||
break;
|
rdp_lic_process_issue(self, s);
|
||||||
case LICENCE_TAG_REISSUE:
|
break;
|
||||||
case LICENCE_TAG_RESULT:
|
case LICENCE_TAG_REISSUE:
|
||||||
break;
|
case LICENCE_TAG_RESULT:
|
||||||
default:
|
break;
|
||||||
break;
|
default:
|
||||||
/* todo unimpl("licence tag 0x%x\n", tag); */
|
break;
|
||||||
}
|
/* todo unimpl("licence tag 0x%x\n", tag); */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+593
-527
File diff suppressed because it is too large
Load Diff
+1454
-1294
File diff suppressed because it is too large
Load Diff
+904
-826
File diff suppressed because it is too large
Load Diff
+562
-504
File diff suppressed because it is too large
Load Diff
+146
-136
@@ -1,178 +1,188 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*
|
||||||
|
* librdp tcp layer
|
||||||
librdp tcp layer
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "rdp.h"
|
#include "rdp.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct rdp_tcp* APP_CC
|
struct rdp_tcp *APP_CC
|
||||||
rdp_tcp_create(struct rdp_iso* owner)
|
rdp_tcp_create(struct rdp_iso *owner)
|
||||||
{
|
{
|
||||||
struct rdp_tcp* self;
|
struct rdp_tcp *self;
|
||||||
|
|
||||||
self = (struct rdp_tcp*)g_malloc(sizeof(struct rdp_tcp), 1);
|
self = (struct rdp_tcp *)g_malloc(sizeof(struct rdp_tcp), 1);
|
||||||
self->iso_layer = owner;
|
self->iso_layer = owner;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void APP_CC
|
void APP_CC
|
||||||
rdp_tcp_delete(struct rdp_tcp* self)
|
rdp_tcp_delete(struct rdp_tcp *self)
|
||||||
{
|
{
|
||||||
g_free(self);
|
g_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* get out stream ready for data */
|
/* get out stream ready for data */
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
rdp_tcp_init(struct rdp_tcp* self, struct stream* s)
|
rdp_tcp_init(struct rdp_tcp *self, struct stream *s)
|
||||||
{
|
{
|
||||||
init_stream(s, 8192);
|
init_stream(s, 8192);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
rdp_tcp_recv(struct rdp_tcp* self, struct stream* s, int len)
|
rdp_tcp_recv(struct rdp_tcp *self, struct stream *s, int len)
|
||||||
{
|
{
|
||||||
int rcvd;
|
int rcvd;
|
||||||
|
|
||||||
DEBUG((" in rdp_tcp_recv gota get %d bytes on sck %d",
|
DEBUG((" in rdp_tcp_recv gota get %d bytes on sck %d",
|
||||||
len, self->sck));
|
len, self->sck));
|
||||||
if (self->sck_closed)
|
|
||||||
{
|
if (self->sck_closed)
|
||||||
DEBUG((" out rdp_tcp_recv error sck closed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
init_stream(s, len);
|
|
||||||
while (len > 0)
|
|
||||||
{
|
|
||||||
rcvd = g_tcp_recv(self->sck, s->end, len, 0);
|
|
||||||
if (rcvd == -1)
|
|
||||||
{
|
{
|
||||||
if (g_tcp_last_error_would_block(self->sck))
|
DEBUG((" out rdp_tcp_recv error sck closed"));
|
||||||
{
|
|
||||||
g_tcp_can_recv(self->sck, 10);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
self->sck_closed = 1;
|
|
||||||
DEBUG((" out rdp_tcp_recv error unknown"));
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (rcvd == 0)
|
|
||||||
|
init_stream(s, len);
|
||||||
|
|
||||||
|
while (len > 0)
|
||||||
{
|
{
|
||||||
self->sck_closed = 1;
|
rcvd = g_tcp_recv(self->sck, s->end, len, 0);
|
||||||
DEBUG((" out rdp_tcp_recv error connection dropped"));
|
|
||||||
return 1;
|
if (rcvd == -1)
|
||||||
|
{
|
||||||
|
if (g_tcp_last_error_would_block(self->sck))
|
||||||
|
{
|
||||||
|
g_tcp_can_recv(self->sck, 10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self->sck_closed = 1;
|
||||||
|
DEBUG((" out rdp_tcp_recv error unknown"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (rcvd == 0)
|
||||||
|
{
|
||||||
|
self->sck_closed = 1;
|
||||||
|
DEBUG((" out rdp_tcp_recv error connection dropped"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s->end += rcvd;
|
||||||
|
len -= rcvd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* returns error */
|
||||||
|
int APP_CC
|
||||||
|
rdp_tcp_send(struct rdp_tcp *self, struct stream *s)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
int total;
|
||||||
|
int sent;
|
||||||
|
|
||||||
|
if (self->sck_closed)
|
||||||
|
{
|
||||||
|
DEBUG((" out rdp_tcp_send error sck closed"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = s->end - s->data;
|
||||||
|
DEBUG((" in rdp_tcp_send gota send %d bytes on sck %d", len,
|
||||||
|
self->sck));
|
||||||
|
total = 0;
|
||||||
|
|
||||||
|
while (total < len)
|
||||||
|
{
|
||||||
|
sent = g_tcp_send(self->sck, s->data + total, len - total, 0);
|
||||||
|
|
||||||
|
if (sent == -1)
|
||||||
|
{
|
||||||
|
if (g_tcp_last_error_would_block(self->sck))
|
||||||
|
{
|
||||||
|
g_tcp_can_send(self->sck, 10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self->sck_closed = 1;
|
||||||
|
DEBUG((" out rdp_tcp_send error unknown"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sent == 0)
|
||||||
|
{
|
||||||
|
self->sck_closed = 1;
|
||||||
|
DEBUG((" out rdp_tcp_send error connection dropped"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
total = total + sent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* returns error */
|
||||||
|
int APP_CC
|
||||||
|
rdp_tcp_connect(struct rdp_tcp *self, char *ip, char *port)
|
||||||
|
{
|
||||||
|
DEBUG((" in rdp_tcp_connect ip %s port %s", ip, port));
|
||||||
|
self->sck = g_tcp_socket();
|
||||||
|
|
||||||
|
if (g_tcp_connect(self->sck, ip, port) == 0)
|
||||||
|
{
|
||||||
|
g_tcp_set_non_blocking(self->sck);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s->end += rcvd;
|
DEBUG((" out rdp_tcp_connect error g_tcp_connect failed"));
|
||||||
len -= rcvd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* returns error */
|
|
||||||
int APP_CC
|
|
||||||
rdp_tcp_send(struct rdp_tcp* self, struct stream* s)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
int total;
|
|
||||||
int sent;
|
|
||||||
|
|
||||||
if (self->sck_closed)
|
|
||||||
{
|
|
||||||
DEBUG((" out rdp_tcp_send error sck closed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
len = s->end - s->data;
|
|
||||||
DEBUG((" in rdp_tcp_send gota send %d bytes on sck %d", len,
|
|
||||||
self->sck));
|
|
||||||
total = 0;
|
|
||||||
while (total < len)
|
|
||||||
{
|
|
||||||
sent = g_tcp_send(self->sck, s->data + total, len - total, 0);
|
|
||||||
if (sent == -1)
|
|
||||||
{
|
|
||||||
if (g_tcp_last_error_would_block(self->sck))
|
|
||||||
{
|
|
||||||
g_tcp_can_send(self->sck, 10);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
self->sck_closed = 1;
|
|
||||||
DEBUG((" out rdp_tcp_send error unknown"));
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (sent == 0)
|
|
||||||
{
|
DEBUG((" out rdp_tcp_connect"));
|
||||||
self->sck_closed = 1;
|
return 0;
|
||||||
DEBUG((" out rdp_tcp_send error connection dropped"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
total = total + sent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns error */
|
/* returns error */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
rdp_tcp_connect(struct rdp_tcp* self, char* ip, char* port)
|
rdp_tcp_disconnect(struct rdp_tcp *self)
|
||||||
{
|
{
|
||||||
DEBUG((" in rdp_tcp_connect ip %s port %s", ip, port));
|
if (self->sck != 0)
|
||||||
self->sck = g_tcp_socket();
|
{
|
||||||
if (g_tcp_connect(self->sck, ip, port) == 0)
|
g_tcp_close(self->sck);
|
||||||
{
|
}
|
||||||
g_tcp_set_non_blocking(self->sck);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DEBUG((" out rdp_tcp_connect error g_tcp_connect failed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
DEBUG((" out rdp_tcp_connect"));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
self->sck = 0;
|
||||||
/* returns error */
|
return 0;
|
||||||
int APP_CC
|
|
||||||
rdp_tcp_disconnect(struct rdp_tcp* self)
|
|
||||||
{
|
|
||||||
if (self->sck != 0)
|
|
||||||
{
|
|
||||||
g_tcp_close(self->sck);
|
|
||||||
}
|
|
||||||
self->sck = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -35,4 +35,4 @@ make install
|
|||||||
|
|
||||||
see file-loc.txt to see what files are installed where
|
see file-loc.txt to see what files are installed where
|
||||||
|
|
||||||
Jay
|
Jay Sorg
|
||||||
|
|||||||
+102
-103
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -27,102 +26,102 @@
|
|||||||
|
|
||||||
#include "sesman.h"
|
#include "sesman.h"
|
||||||
|
|
||||||
extern struct config_sesman* g_cfg; /* in sesman.c */
|
extern struct config_sesman *g_cfg; /* in sesman.c */
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
access_login_allowed(char* user)
|
access_login_allowed(char *user)
|
||||||
{
|
{
|
||||||
int gid;
|
int gid;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
|
if ((0 == g_strncmp(user, "root", 5)) && (0 == g_cfg->sec.allow_root))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING,
|
||||||
|
"ROOT login attempted, but root login is disabled");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == g_cfg->sec.ts_users_enable)
|
||||||
|
{
|
||||||
|
LOG_DBG("Terminal Server Users group is disabled, allowing authentication",
|
||||||
|
1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != g_getuser_info(user, &gid, 0, 0, 0, 0))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_ERROR, "Cannot read user info! - login denied");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_cfg->sec.ts_users == gid)
|
||||||
|
{
|
||||||
|
LOG_DBG("ts_users is user's primary group");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != g_check_user_in_group(user, g_cfg->sec.ts_users, &ok))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_ERROR, "Cannot read group info! - login denied");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message(LOG_LEVEL_INFO, "login denied for user %s", user);
|
||||||
|
|
||||||
if ((0 == g_strncmp(user, "root", 5)) && (0 == g_cfg->sec.allow_root))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING,
|
|
||||||
"ROOT login attempted, but root login is disabled");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == g_cfg->sec.ts_users_enable)
|
|
||||||
{
|
|
||||||
LOG_DBG("Terminal Server Users group is disabled, allowing authentication",
|
|
||||||
1);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 != g_getuser_info(user, &gid, 0, 0, 0, 0))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_ERROR, "Cannot read user info! - login denied");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_cfg->sec.ts_users == gid)
|
|
||||||
{
|
|
||||||
LOG_DBG("ts_users is user's primary group");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 != g_check_user_in_group(user, g_cfg->sec.ts_users, &ok))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_ERROR, "Cannot read group info! - login denied");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message(LOG_LEVEL_INFO, "login denied for user %s", user);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
access_login_mng_allowed(char* user)
|
access_login_mng_allowed(char *user)
|
||||||
{
|
{
|
||||||
int gid;
|
int gid;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
|
if ((0 == g_strncmp(user, "root", 5)) && (0 == g_cfg->sec.allow_root))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING,
|
||||||
|
"[MNG] ROOT login attempted, but root login is disabled");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == g_cfg->sec.ts_admins_enable)
|
||||||
|
{
|
||||||
|
LOG_DBG("[MNG] Terminal Server Admin group is disabled,"
|
||||||
|
"allowing authentication", 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != g_getuser_info(user, &gid, 0, 0, 0, 0))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_ERROR, "[MNG] Cannot read user info! - login denied");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_cfg->sec.ts_admins == gid)
|
||||||
|
{
|
||||||
|
LOG_DBG("[MNG] ts_users is user's primary group");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != g_check_user_in_group(user, g_cfg->sec.ts_admins, &ok))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_ERROR, "[MNG] Cannot read group info! - login denied");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message(LOG_LEVEL_INFO, "[MNG] login denied for user %s", user);
|
||||||
|
|
||||||
if ((0 == g_strncmp(user, "root", 5)) && (0 == g_cfg->sec.allow_root))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING,
|
|
||||||
"[MNG] ROOT login attempted, but root login is disabled");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == g_cfg->sec.ts_admins_enable)
|
|
||||||
{
|
|
||||||
LOG_DBG("[MNG] Terminal Server Admin group is disabled,"
|
|
||||||
"allowing authentication",1);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 != g_getuser_info(user, &gid, 0, 0, 0, 0))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_ERROR, "[MNG] Cannot read user info! - login denied");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_cfg->sec.ts_admins == gid)
|
|
||||||
{
|
|
||||||
LOG_DBG("[MNG] ts_users is user's primary group");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 != g_check_user_in_group(user, g_cfg->sec.ts_admins, &ok))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_ERROR, "[MNG] Cannot read group info! - login denied");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message(LOG_LEVEL_INFO, "[MNG] login denied for user %s", user);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-18
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
+17
-18
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
+915
-807
File diff suppressed because it is too large
Load Diff
+1113
-994
File diff suppressed because it is too large
Load Diff
@@ -26,34 +26,34 @@ extern int g_rdpdr_chan_id; /* in chansrv.c */
|
|||||||
int APP_CC
|
int APP_CC
|
||||||
dev_redir_init(void)
|
dev_redir_init(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
dev_redir_deinit(void)
|
dev_redir_deinit(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
dev_redir_data_in(struct stream* s, int chan_id, int chan_flags, int length,
|
dev_redir_data_in(struct stream *s, int chan_id, int chan_flags, int length,
|
||||||
int total_length)
|
int total_length)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
dev_redir_get_wait_objs(tbus* objs, int* count, int* timeout)
|
dev_redir_get_wait_objs(tbus *objs, int *count, int *timeout)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
dev_redir_check_wait_objs(void)
|
dev_redir_check_wait_objs(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+439
-415
File diff suppressed because it is too large
Load Diff
+399
-369
@@ -28,100 +28,100 @@ static int g_training_sent_time = 0;
|
|||||||
static int g_cBlockNo = 0;
|
static int g_cBlockNo = 0;
|
||||||
|
|
||||||
#if defined(XRDP_SIMPLESOUND)
|
#if defined(XRDP_SIMPLESOUND)
|
||||||
static void* DEFAULT_CC
|
static void *DEFAULT_CC
|
||||||
read_raw_audio_data(void* arg);
|
read_raw_audio_data(void *arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
sound_send_server_formats(void)
|
sound_send_server_formats(void)
|
||||||
{
|
{
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
int bytes;
|
int bytes;
|
||||||
char* size_ptr;
|
char *size_ptr;
|
||||||
|
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
make_stream(s);
|
make_stream(s);
|
||||||
init_stream(s, 8182);
|
init_stream(s, 8182);
|
||||||
out_uint16_le(s, SNDC_FORMATS);
|
out_uint16_le(s, SNDC_FORMATS);
|
||||||
size_ptr = s->p;
|
size_ptr = s->p;
|
||||||
out_uint16_le(s, 0); /* size, set later */
|
out_uint16_le(s, 0); /* size, set later */
|
||||||
out_uint32_le(s, 0); /* dwFlags */
|
out_uint32_le(s, 0); /* dwFlags */
|
||||||
out_uint32_le(s, 0); /* dwVolume */
|
out_uint32_le(s, 0); /* dwVolume */
|
||||||
out_uint32_le(s, 0); /* dwPitch */
|
out_uint32_le(s, 0); /* dwPitch */
|
||||||
out_uint16_le(s, 0); /* wDGramPort */
|
out_uint16_le(s, 0); /* wDGramPort */
|
||||||
out_uint16_le(s, 1); /* wNumberOfFormats */
|
out_uint16_le(s, 1); /* wNumberOfFormats */
|
||||||
out_uint8(s, g_cBlockNo); /* cLastBlockConfirmed */
|
out_uint8(s, g_cBlockNo); /* cLastBlockConfirmed */
|
||||||
out_uint16_le(s, 2); /* wVersion */
|
out_uint16_le(s, 2); /* wVersion */
|
||||||
out_uint8(s, 0); /* bPad */
|
out_uint8(s, 0); /* bPad */
|
||||||
|
|
||||||
/* sndFormats */
|
/* sndFormats */
|
||||||
/*
|
/*
|
||||||
wFormatTag 2 byte offset 0
|
wFormatTag 2 byte offset 0
|
||||||
nChannels 2 byte offset 2
|
nChannels 2 byte offset 2
|
||||||
nSamplesPerSec 4 byte offset 4
|
nSamplesPerSec 4 byte offset 4
|
||||||
nAvgBytesPerSec 4 byte offset 8
|
nAvgBytesPerSec 4 byte offset 8
|
||||||
nBlockAlign 2 byte offset 12
|
nBlockAlign 2 byte offset 12
|
||||||
wBitsPerSample 2 byte offset 14
|
wBitsPerSample 2 byte offset 14
|
||||||
cbSize 2 byte offset 16
|
cbSize 2 byte offset 16
|
||||||
data variable offset 18
|
data variable offset 18
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* examples
|
/* examples
|
||||||
01 00 02 00 44 ac 00 00 10 b1 02 00 04 00 10 00 ....D...........
|
01 00 02 00 44 ac 00 00 10 b1 02 00 04 00 10 00 ....D...........
|
||||||
00 00
|
00 00
|
||||||
01 00 02 00 22 56 00 00 88 58 01 00 04 00 10 00 ...."V...X......
|
01 00 02 00 22 56 00 00 88 58 01 00 04 00 10 00 ...."V...X......
|
||||||
00 00
|
00 00
|
||||||
*/
|
*/
|
||||||
|
|
||||||
out_uint16_le(s, 1); // wFormatTag - WAVE_FORMAT_PCM
|
out_uint16_le(s, 1); // wFormatTag - WAVE_FORMAT_PCM
|
||||||
out_uint16_le(s, 2); // num of channels
|
out_uint16_le(s, 2); // num of channels
|
||||||
out_uint32_le(s, 44100); // samples per sec
|
out_uint32_le(s, 44100); // samples per sec
|
||||||
out_uint32_le(s, 176400); // avg bytes per sec
|
out_uint32_le(s, 176400); // avg bytes per sec
|
||||||
out_uint16_le(s, 4); // block align
|
out_uint16_le(s, 4); // block align
|
||||||
out_uint16_le(s, 16); // bits per sample
|
out_uint16_le(s, 16); // bits per sample
|
||||||
out_uint16_le(s, 0); // size
|
out_uint16_le(s, 0); // size
|
||||||
|
|
||||||
s_mark_end(s);
|
s_mark_end(s);
|
||||||
bytes = (int)((s->end - s->data) - 4);
|
bytes = (int)((s->end - s->data) - 4);
|
||||||
size_ptr[0] = bytes;
|
size_ptr[0] = bytes;
|
||||||
size_ptr[1] = bytes >> 8;
|
size_ptr[1] = bytes >> 8;
|
||||||
bytes = (int)(s->end - s->data);
|
bytes = (int)(s->end - s->data);
|
||||||
send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
|
send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int
|
static int
|
||||||
sound_send_training(void)
|
sound_send_training(void)
|
||||||
{
|
{
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
int bytes;
|
int bytes;
|
||||||
int time;
|
int time;
|
||||||
char* size_ptr;
|
char *size_ptr;
|
||||||
|
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
make_stream(s);
|
make_stream(s);
|
||||||
init_stream(s, 8182);
|
init_stream(s, 8182);
|
||||||
out_uint16_le(s, SNDC_TRAINING);
|
out_uint16_le(s, SNDC_TRAINING);
|
||||||
size_ptr = s->p;
|
size_ptr = s->p;
|
||||||
out_uint16_le(s, 0); /* size, set later */
|
out_uint16_le(s, 0); /* size, set later */
|
||||||
time = g_time2();
|
time = g_time2();
|
||||||
g_training_sent_time = time;
|
g_training_sent_time = time;
|
||||||
out_uint16_le(s, time);
|
out_uint16_le(s, time);
|
||||||
out_uint16_le(s, 1024);
|
out_uint16_le(s, 1024);
|
||||||
out_uint8s(s, (1024 - 4));
|
out_uint8s(s, (1024 - 4));
|
||||||
s_mark_end(s);
|
s_mark_end(s);
|
||||||
bytes = (int)((s->end - s->data) - 4);
|
bytes = (int)((s->end - s->data) - 4);
|
||||||
size_ptr[0] = bytes;
|
size_ptr[0] = bytes;
|
||||||
size_ptr[1] = bytes >> 8;
|
size_ptr[1] = bytes >> 8;
|
||||||
bytes = (int)(s->end - s->data);
|
bytes = (int)(s->end - s->data);
|
||||||
send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
|
send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -132,318 +132,339 @@ sound_send_training(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
sound_process_formats(struct stream* s, int size)
|
sound_process_formats(struct stream *s, int size)
|
||||||
{
|
{
|
||||||
int num_formats;
|
int num_formats;
|
||||||
|
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
LOG(0, ("sound_process_formats:"));
|
LOG(0, ("sound_process_formats:"));
|
||||||
if (size < 16)
|
|
||||||
{
|
if (size < 16)
|
||||||
return 1;
|
{
|
||||||
}
|
return 1;
|
||||||
in_uint8s(s, 14);
|
}
|
||||||
in_uint16_le(s, num_formats);
|
|
||||||
if (num_formats > 0)
|
in_uint8s(s, 14);
|
||||||
{
|
in_uint16_le(s, num_formats);
|
||||||
sound_send_training();
|
|
||||||
}
|
if (num_formats > 0)
|
||||||
return 0;
|
{
|
||||||
|
sound_send_training();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int
|
static int
|
||||||
sound_send_wave_data(char* data, int data_bytes)
|
sound_send_wave_data(char *data, int data_bytes)
|
||||||
{
|
{
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
int bytes;
|
int bytes;
|
||||||
int time;
|
int time;
|
||||||
char* size_ptr;
|
char *size_ptr;
|
||||||
|
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
if ((data_bytes < 4) || (data_bytes > 32 * 1024))
|
if ((data_bytes < 4) || (data_bytes > 32 * 1024))
|
||||||
{
|
{
|
||||||
LOG(0, ("sound_send_wave_data: bad data_bytes %d", data_bytes));
|
LOG(0, ("sound_send_wave_data: bad data_bytes %d", data_bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* part one of 2 PDU wave info */
|
/* part one of 2 PDU wave info */
|
||||||
|
|
||||||
LOG(10, ("sound_send_wave_data: sending %d bytes", data_bytes));
|
LOG(10, ("sound_send_wave_data: sending %d bytes", data_bytes));
|
||||||
|
|
||||||
make_stream(s);
|
make_stream(s);
|
||||||
init_stream(s, data_bytes);
|
init_stream(s, data_bytes);
|
||||||
out_uint16_le(s, SNDC_WAVE);
|
out_uint16_le(s, SNDC_WAVE);
|
||||||
size_ptr = s->p;
|
size_ptr = s->p;
|
||||||
out_uint16_le(s, 0); /* size, set later */
|
out_uint16_le(s, 0); /* size, set later */
|
||||||
time = g_time2();
|
time = g_time2();
|
||||||
out_uint16_le(s, time);
|
out_uint16_le(s, time);
|
||||||
out_uint16_le(s, 0); /* wFormatNo */
|
out_uint16_le(s, 0); /* wFormatNo */
|
||||||
g_cBlockNo++;
|
g_cBlockNo++;
|
||||||
out_uint8(s, g_cBlockNo);
|
out_uint8(s, g_cBlockNo);
|
||||||
|
|
||||||
LOG(10, ("sound_send_wave_data: sending time %d, g_cBlockNo %d",
|
LOG(10, ("sound_send_wave_data: sending time %d, g_cBlockNo %d",
|
||||||
time & 0xffff, g_cBlockNo & 0xff));
|
time & 0xffff, g_cBlockNo & 0xff));
|
||||||
|
|
||||||
out_uint8s(s, 3);
|
out_uint8s(s, 3);
|
||||||
out_uint8a(s, data, 4);
|
out_uint8a(s, data, 4);
|
||||||
s_mark_end(s);
|
s_mark_end(s);
|
||||||
bytes = (int)((s->end - s->data) - 4);
|
bytes = (int)((s->end - s->data) - 4);
|
||||||
bytes += data_bytes;
|
bytes += data_bytes;
|
||||||
bytes -= 4;
|
bytes -= 4;
|
||||||
size_ptr[0] = bytes;
|
size_ptr[0] = bytes;
|
||||||
size_ptr[1] = bytes >> 8;
|
size_ptr[1] = bytes >> 8;
|
||||||
bytes = (int)(s->end - s->data);
|
bytes = (int)(s->end - s->data);
|
||||||
send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
|
send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
|
||||||
|
|
||||||
/* part two of 2 PDU wave info */
|
/* part two of 2 PDU wave info */
|
||||||
init_stream(s, data_bytes);
|
init_stream(s, data_bytes);
|
||||||
out_uint32_le(s, 0);
|
out_uint32_le(s, 0);
|
||||||
out_uint8a(s, data + 4, data_bytes - 4);
|
out_uint8a(s, data + 4, data_bytes - 4);
|
||||||
s_mark_end(s);
|
s_mark_end(s);
|
||||||
bytes = (int)(s->end - s->data);
|
bytes = (int)(s->end - s->data);
|
||||||
send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
|
send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
|
||||||
free_stream(s);
|
free_stream(s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
sound_process_training(struct stream* s, int size)
|
sound_process_training(struct stream *s, int size)
|
||||||
{
|
{
|
||||||
int time_diff;
|
int time_diff;
|
||||||
|
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
time_diff = g_time2() - g_training_sent_time;
|
time_diff = g_time2() - g_training_sent_time;
|
||||||
LOG(0, ("sound_process_training: round trip time %u", time_diff));
|
LOG(0, ("sound_process_training: round trip time %u", time_diff));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
sound_process_wave_confirm(struct stream* s, int size)
|
sound_process_wave_confirm(struct stream *s, int size)
|
||||||
{
|
{
|
||||||
int wTimeStamp;
|
int wTimeStamp;
|
||||||
int cConfirmedBlockNo;
|
int cConfirmedBlockNo;
|
||||||
|
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
in_uint16_le(s, wTimeStamp);
|
in_uint16_le(s, wTimeStamp);
|
||||||
in_uint8(s, cConfirmedBlockNo);
|
in_uint8(s, cConfirmedBlockNo);
|
||||||
|
|
||||||
LOG(10, ("sound_process_wave_confirm: wTimeStamp %d, cConfirmedBlockNo %d",
|
LOG(10, ("sound_process_wave_confirm: wTimeStamp %d, cConfirmedBlockNo %d",
|
||||||
wTimeStamp, cConfirmedBlockNo));
|
wTimeStamp, cConfirmedBlockNo));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int APP_CC
|
static int APP_CC
|
||||||
process_pcm_message(int id, int size, struct stream* s)
|
process_pcm_message(int id, int size, struct stream *s)
|
||||||
{
|
{
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
sound_send_wave_data(s->p, size);
|
sound_send_wave_data(s->p, size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* data coming in from audio source, eg pulse, alsa */
|
/* data coming in from audio source, eg pulse, alsa */
|
||||||
static int DEFAULT_CC
|
static int DEFAULT_CC
|
||||||
sound_trans_audio_data_in(struct trans* trans)
|
sound_trans_audio_data_in(struct trans *trans)
|
||||||
{
|
{
|
||||||
struct stream *s;
|
struct stream *s;
|
||||||
int id;
|
int id;
|
||||||
int size;
|
int size;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (trans == 0)
|
if (trans == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (trans != g_audio_c_trans)
|
|
||||||
{
|
if (trans != g_audio_c_trans)
|
||||||
return 1;
|
{
|
||||||
}
|
return 1;
|
||||||
s = trans_get_in_s(trans);
|
}
|
||||||
in_uint32_le(s, id);
|
|
||||||
in_uint32_le(s, size);
|
s = trans_get_in_s(trans);
|
||||||
if ((id != 0) || (size > 32 * 1024 + 8) || (size < 1))
|
in_uint32_le(s, id);
|
||||||
{
|
in_uint32_le(s, size);
|
||||||
LOG(0, ("sound_trans_audio_data_in: bad message id %d size %d", id, size));
|
|
||||||
return 1;
|
if ((id != 0) || (size > 32 * 1024 + 8) || (size < 1))
|
||||||
}
|
{
|
||||||
error = trans_force_read(trans, size - 8);
|
LOG(0, ("sound_trans_audio_data_in: bad message id %d size %d", id, size));
|
||||||
if (error == 0)
|
return 1;
|
||||||
{
|
}
|
||||||
/* here, the entire message block is read in, process it */
|
|
||||||
error = process_pcm_message(id, size - 8, s);
|
error = trans_force_read(trans, size - 8);
|
||||||
}
|
|
||||||
return error;
|
if (error == 0)
|
||||||
|
{
|
||||||
|
/* here, the entire message block is read in, process it */
|
||||||
|
error = process_pcm_message(id, size - 8, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int DEFAULT_CC
|
static int DEFAULT_CC
|
||||||
sound_trans_audio_conn_in(struct trans *trans, struct trans *new_trans)
|
sound_trans_audio_conn_in(struct trans *trans, struct trans *new_trans)
|
||||||
{
|
{
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
if (trans == 0)
|
if (trans == 0)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (trans != g_audio_l_trans)
|
|
||||||
{
|
if (trans != g_audio_l_trans)
|
||||||
return 1;
|
{
|
||||||
}
|
return 1;
|
||||||
if (g_audio_c_trans != 0) /* if already set, error */
|
}
|
||||||
{
|
|
||||||
return 1;
|
if (g_audio_c_trans != 0) /* if already set, error */
|
||||||
}
|
{
|
||||||
if (new_trans == 0)
|
return 1;
|
||||||
{
|
}
|
||||||
return 1;
|
|
||||||
}
|
if (new_trans == 0)
|
||||||
g_audio_c_trans = new_trans;
|
{
|
||||||
g_audio_c_trans->trans_data_in = sound_trans_audio_data_in;
|
return 1;
|
||||||
g_audio_c_trans->header_size = 8;
|
}
|
||||||
trans_delete(g_audio_l_trans);
|
|
||||||
g_audio_l_trans = 0;
|
g_audio_c_trans = new_trans;
|
||||||
return 0;
|
g_audio_c_trans->trans_data_in = sound_trans_audio_data_in;
|
||||||
|
g_audio_c_trans->header_size = 8;
|
||||||
|
trans_delete(g_audio_l_trans);
|
||||||
|
g_audio_l_trans = 0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
sound_init(void)
|
sound_init(void)
|
||||||
{
|
{
|
||||||
char port[256];
|
char port[256];
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
print_got_here();
|
print_got_here();
|
||||||
LOG(0, ("sound_init:"));
|
LOG(0, ("sound_init:"));
|
||||||
|
|
||||||
sound_send_server_formats();
|
sound_send_server_formats();
|
||||||
g_audio_l_trans = trans_create(2, 33 * 1024, 8192);
|
g_audio_l_trans = trans_create(2, 33 * 1024, 8192);
|
||||||
g_snprintf(port, 255, "/tmp/xrdp_chansrv_audio_socket_%d", g_display_num);
|
g_snprintf(port, 255, "/tmp/xrdp_chansrv_audio_socket_%d", g_display_num);
|
||||||
g_audio_l_trans->trans_conn_in = sound_trans_audio_conn_in;
|
g_audio_l_trans->trans_conn_in = sound_trans_audio_conn_in;
|
||||||
error = trans_listen(g_audio_l_trans, port);
|
error = trans_listen(g_audio_l_trans, port);
|
||||||
if (error != 0)
|
|
||||||
{
|
if (error != 0)
|
||||||
LOG(0, ("sound_init: trans_listen failed"));
|
{
|
||||||
}
|
LOG(0, ("sound_init: trans_listen failed"));
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(XRDP_SIMPLESOUND)
|
#if defined(XRDP_SIMPLESOUND)
|
||||||
|
|
||||||
/* start thread to read raw audio data from pulseaudio device */
|
/* start thread to read raw audio data from pulseaudio device */
|
||||||
tc_thread_create(read_raw_audio_data, 0);
|
tc_thread_create(read_raw_audio_data, 0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
sound_deinit(void)
|
sound_deinit(void)
|
||||||
{
|
{
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
if (g_audio_l_trans != 0)
|
if (g_audio_l_trans != 0)
|
||||||
{
|
{
|
||||||
trans_delete(g_audio_l_trans);
|
trans_delete(g_audio_l_trans);
|
||||||
g_audio_l_trans = 0;
|
g_audio_l_trans = 0;
|
||||||
}
|
}
|
||||||
if (g_audio_c_trans != 0)
|
|
||||||
{
|
|
||||||
trans_delete(g_audio_c_trans);
|
|
||||||
g_audio_l_trans = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
if (g_audio_c_trans != 0)
|
||||||
|
{
|
||||||
|
trans_delete(g_audio_c_trans);
|
||||||
|
g_audio_l_trans = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* data in from client ( clinet -> xrdp -> chansrv ) */
|
/* data in from client ( clinet -> xrdp -> chansrv ) */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
sound_data_in(struct stream* s, int chan_id, int chan_flags, int length,
|
sound_data_in(struct stream *s, int chan_id, int chan_flags, int length,
|
||||||
int total_length)
|
int total_length)
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
print_got_here();
|
print_got_here();
|
||||||
|
|
||||||
in_uint8(s, code);
|
in_uint8(s, code);
|
||||||
in_uint8s(s, 1);
|
in_uint8s(s, 1);
|
||||||
in_uint16_le(s, size);
|
in_uint16_le(s, size);
|
||||||
switch (code)
|
|
||||||
{
|
|
||||||
case SNDC_WAVECONFIRM:
|
|
||||||
sound_process_wave_confirm(s, size);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SNDC_TRAINING:
|
switch (code)
|
||||||
sound_process_training(s, size);
|
{
|
||||||
break;
|
case SNDC_WAVECONFIRM:
|
||||||
|
sound_process_wave_confirm(s, size);
|
||||||
|
break;
|
||||||
|
|
||||||
case SNDC_FORMATS:
|
case SNDC_TRAINING:
|
||||||
sound_process_formats(s, size);
|
sound_process_training(s, size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case SNDC_FORMATS:
|
||||||
LOG(0, ("sound_data_in: unknown code %d size %d", code, size));
|
sound_process_formats(s, size);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
return 0;
|
default:
|
||||||
|
LOG(0, ("sound_data_in: unknown code %d size %d", code, size));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
sound_get_wait_objs(tbus* objs, int* count, int* timeout)
|
sound_get_wait_objs(tbus *objs, int *count, int *timeout)
|
||||||
{
|
{
|
||||||
int lcount;
|
int lcount;
|
||||||
|
|
||||||
lcount = *count;
|
lcount = *count;
|
||||||
if (g_audio_l_trans != 0)
|
|
||||||
{
|
if (g_audio_l_trans != 0)
|
||||||
objs[lcount] = g_audio_l_trans->sck;
|
{
|
||||||
lcount++;
|
objs[lcount] = g_audio_l_trans->sck;
|
||||||
}
|
lcount++;
|
||||||
if (g_audio_c_trans != 0)
|
}
|
||||||
{
|
|
||||||
objs[lcount] = g_audio_c_trans->sck;
|
if (g_audio_c_trans != 0)
|
||||||
lcount++;
|
{
|
||||||
}
|
objs[lcount] = g_audio_c_trans->sck;
|
||||||
*count = lcount;
|
lcount++;
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
*count = lcount;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
sound_check_wait_objs(void)
|
sound_check_wait_objs(void)
|
||||||
{
|
{
|
||||||
if (g_audio_l_trans != 0)
|
if (g_audio_l_trans != 0)
|
||||||
{
|
{
|
||||||
trans_check_wait_objs(g_audio_l_trans);
|
trans_check_wait_objs(g_audio_l_trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_audio_c_trans != 0)
|
if (g_audio_c_trans != 0)
|
||||||
{
|
{
|
||||||
trans_check_wait_objs(g_audio_c_trans);
|
trans_check_wait_objs(g_audio_c_trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(XRDP_SIMPLESOUND)
|
#if defined(XRDP_SIMPLESOUND)
|
||||||
|
|
||||||
static int DEFAULT_CC
|
static int DEFAULT_CC
|
||||||
sttrans_data_in(struct trans* self)
|
sttrans_data_in(struct trans *self)
|
||||||
{
|
{
|
||||||
LOG(0, ("sttrans_data_in:\n"));
|
LOG(0, ("sttrans_data_in:\n"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -451,103 +472,112 @@ sttrans_data_in(struct trans* self)
|
|||||||
* to a unix domain socket on which trans server is listening
|
* to a unix domain socket on which trans server is listening
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void* DEFAULT_CC
|
static void *DEFAULT_CC
|
||||||
read_raw_audio_data(void* arg)
|
read_raw_audio_data(void *arg)
|
||||||
{
|
{
|
||||||
pa_sample_spec samp_spec;
|
pa_sample_spec samp_spec;
|
||||||
pa_simple* simple = NULL;
|
pa_simple *simple = NULL;
|
||||||
uint32_t bytes_read;
|
uint32_t bytes_read;
|
||||||
char* cptr;
|
char *cptr;
|
||||||
int i;
|
int i;
|
||||||
int error;
|
int error;
|
||||||
struct trans* strans;
|
struct trans *strans;
|
||||||
char path[256];
|
char path[256];
|
||||||
struct stream* outs;
|
struct stream *outs;
|
||||||
|
|
||||||
strans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
|
strans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
|
||||||
if (strans == 0)
|
|
||||||
{
|
|
||||||
LOG(0, ("read_raw_audio_data: trans_create failed\n"));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
strans->trans_data_in = sttrans_data_in;
|
|
||||||
g_snprintf(path, 255, "/tmp/xrdp_chansrv_audio_socket_%d", g_display_num);
|
|
||||||
if (trans_connect(strans, "", path, 100) != 0)
|
|
||||||
{
|
|
||||||
LOG(0, ("read_raw_audio_data: trans_connect failed\n"));
|
|
||||||
trans_delete(strans);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* setup audio format */
|
if (strans == 0)
|
||||||
samp_spec.format = PA_SAMPLE_S16LE;
|
|
||||||
samp_spec.rate = 44100;
|
|
||||||
samp_spec.channels = 2;
|
|
||||||
|
|
||||||
/* if we are root, then for first 8 seconds connection to pulseaudo server
|
|
||||||
fails; if we are non-root, then connection succeeds on first attempt;
|
|
||||||
for now we have changed code to be non-root, but this may change in the
|
|
||||||
future - so pretend we are root and try connecting to pulseaudio server
|
|
||||||
for upto one minute */
|
|
||||||
for (i = 0; i < 60; i++)
|
|
||||||
{
|
|
||||||
simple = pa_simple_new(NULL, "xrdp", PA_STREAM_RECORD, NULL,
|
|
||||||
"record", &samp_spec, NULL, NULL, &error);
|
|
||||||
if (simple)
|
|
||||||
{
|
{
|
||||||
/* connected to pulseaudio server */
|
LOG(0, ("read_raw_audio_data: trans_create failed\n"));
|
||||||
LOG(0, ("read_raw_audio_data: connected to pulseaudio server\n"));
|
return 0;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
LOG(0, ("read_raw_audio_data: ERROR creating PulseAudio async interface\n"));
|
|
||||||
LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error)));
|
|
||||||
g_sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 60)
|
strans->trans_data_in = sttrans_data_in;
|
||||||
{
|
g_snprintf(path, 255, "/tmp/xrdp_chansrv_audio_socket_%d", g_display_num);
|
||||||
/* failed to connect to audio server */
|
|
||||||
|
if (trans_connect(strans, "", path, 100) != 0)
|
||||||
|
{
|
||||||
|
LOG(0, ("read_raw_audio_data: trans_connect failed\n"));
|
||||||
|
trans_delete(strans);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* setup audio format */
|
||||||
|
samp_spec.format = PA_SAMPLE_S16LE;
|
||||||
|
samp_spec.rate = 44100;
|
||||||
|
samp_spec.channels = 2;
|
||||||
|
|
||||||
|
/* if we are root, then for first 8 seconds connection to pulseaudo server
|
||||||
|
fails; if we are non-root, then connection succeeds on first attempt;
|
||||||
|
for now we have changed code to be non-root, but this may change in the
|
||||||
|
future - so pretend we are root and try connecting to pulseaudio server
|
||||||
|
for upto one minute */
|
||||||
|
for (i = 0; i < 60; i++)
|
||||||
|
{
|
||||||
|
simple = pa_simple_new(NULL, "xrdp", PA_STREAM_RECORD, NULL,
|
||||||
|
"record", &samp_spec, NULL, NULL, &error);
|
||||||
|
|
||||||
|
if (simple)
|
||||||
|
{
|
||||||
|
/* connected to pulseaudio server */
|
||||||
|
LOG(0, ("read_raw_audio_data: connected to pulseaudio server\n"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(0, ("read_raw_audio_data: ERROR creating PulseAudio async interface\n"));
|
||||||
|
LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error)));
|
||||||
|
g_sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 60)
|
||||||
|
{
|
||||||
|
/* failed to connect to audio server */
|
||||||
|
trans_delete(strans);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* insert header just once */
|
||||||
|
outs = trans_get_out_s(strans, 8192);
|
||||||
|
out_uint32_le(outs, 0);
|
||||||
|
out_uint32_le(outs, AUDIO_BUF_SIZE + 8);
|
||||||
|
cptr = outs->p;
|
||||||
|
out_uint8s(outs, AUDIO_BUF_SIZE);
|
||||||
|
s_mark_end(outs);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* read a block of raw audio data... */
|
||||||
|
g_memset(cptr, 0, 4);
|
||||||
|
bytes_read = pa_simple_read(simple, cptr, AUDIO_BUF_SIZE, &error);
|
||||||
|
|
||||||
|
if (bytes_read < 0)
|
||||||
|
{
|
||||||
|
LOG(0, ("read_raw_audio_data: ERROR reading from pulseaudio stream\n"));
|
||||||
|
LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bug workaround:
|
||||||
|
even when there is no audio data, pulseaudio is returning without
|
||||||
|
errors but the data itself is zero; we use this zero data to
|
||||||
|
determine that there is no audio data present */
|
||||||
|
if (*cptr == 0 && *(cptr + 1) == 0 && *(cptr + 2) == 0 && *(cptr + 3) == 0)
|
||||||
|
{
|
||||||
|
g_sleep(10);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trans_force_write_s(strans, outs) != 0)
|
||||||
|
{
|
||||||
|
LOG(0, ("read_raw_audio_data: ERROR writing audio data to server\n"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_simple_free(simple);
|
||||||
trans_delete(strans);
|
trans_delete(strans);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* insert header just once */
|
|
||||||
outs = trans_get_out_s(strans, 8192);
|
|
||||||
out_uint32_le(outs, 0);
|
|
||||||
out_uint32_le(outs, AUDIO_BUF_SIZE + 8);
|
|
||||||
cptr = outs->p;
|
|
||||||
out_uint8s(outs, AUDIO_BUF_SIZE);
|
|
||||||
s_mark_end(outs);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
/* read a block of raw audio data... */
|
|
||||||
g_memset(cptr, 0, 4);
|
|
||||||
bytes_read = pa_simple_read(simple, cptr, AUDIO_BUF_SIZE, &error);
|
|
||||||
if (bytes_read < 0)
|
|
||||||
{
|
|
||||||
LOG(0, ("read_raw_audio_data: ERROR reading from pulseaudio stream\n"));
|
|
||||||
LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* bug workaround:
|
|
||||||
even when there is no audio data, pulseaudio is returning without
|
|
||||||
errors but the data itself is zero; we use this zero data to
|
|
||||||
determine that there is no audio data present */
|
|
||||||
if (*cptr == 0 && *(cptr + 1) == 0 && *(cptr + 2) == 0 && *(cptr + 3) == 0)
|
|
||||||
{
|
|
||||||
g_sleep(10);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (trans_force_write_s(strans, outs) != 0)
|
|
||||||
{
|
|
||||||
LOG(0, ("read_raw_audio_data: ERROR writing audio data to server\n"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pa_simple_free(simple);
|
|
||||||
trans_delete(strans);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+108
-98
@@ -31,10 +31,10 @@ extern int g_waiting_for_data_response_time; /* in clipboard.c */
|
|||||||
|
|
||||||
extern int g_rail_up; /* in rail.c */
|
extern int g_rail_up; /* in rail.c */
|
||||||
|
|
||||||
Display* g_display = 0;
|
Display *g_display = 0;
|
||||||
int g_x_socket = 0;
|
int g_x_socket = 0;
|
||||||
tbus g_x_wait_obj = 0;
|
tbus g_x_wait_obj = 0;
|
||||||
Screen* g_screen = 0;
|
Screen *g_screen = 0;
|
||||||
int g_screen_num = 0;
|
int g_screen_num = 0;
|
||||||
Window g_root_window = 0;
|
Window g_root_window = 0;
|
||||||
Atom g_wm_delete_window_atom = 0;
|
Atom g_wm_delete_window_atom = 0;
|
||||||
@@ -42,15 +42,15 @@ Atom g_wm_protocols_atom = 0;
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int DEFAULT_CC
|
static int DEFAULT_CC
|
||||||
xcommon_error_handler(Display* dis, XErrorEvent* xer)
|
xcommon_error_handler(Display *dis, XErrorEvent *xer)
|
||||||
{
|
{
|
||||||
char text[256];
|
char text[256];
|
||||||
|
|
||||||
XGetErrorText(dis, xer->error_code, text, 255);
|
XGetErrorText(dis, xer->error_code, text, 255);
|
||||||
LOGM((LOG_LEVEL_ERROR, "X error [%s](%d) opcodes %d/%d "
|
LOGM((LOG_LEVEL_ERROR, "X error [%s](%d) opcodes %d/%d "
|
||||||
"resource 0x%lx", text, xer->error_code,
|
"resource 0x%lx", text, xer->error_code,
|
||||||
xer->request_code, xer->minor_code, xer->resourceid));
|
xer->request_code, xer->minor_code, xer->resourceid));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -58,9 +58,9 @@ xcommon_error_handler(Display* dis, XErrorEvent* xer)
|
|||||||
Do any cleanup that needs to be done on exit, like removing temporary files.
|
Do any cleanup that needs to be done on exit, like removing temporary files.
|
||||||
Don't worry about memory leaks */
|
Don't worry about memory leaks */
|
||||||
static int DEFAULT_CC
|
static int DEFAULT_CC
|
||||||
xcommon_fatal_handler(Display* dis)
|
xcommon_fatal_handler(Display *dis)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -71,7 +71,7 @@ xcommon_fatal_handler(Display* dis)
|
|||||||
int APP_CC
|
int APP_CC
|
||||||
xcommon_get_local_time(void)
|
xcommon_get_local_time(void)
|
||||||
{
|
{
|
||||||
return g_time3();
|
return g_time3();
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@@ -79,42 +79,45 @@ xcommon_get_local_time(void)
|
|||||||
int APP_CC
|
int APP_CC
|
||||||
xcommon_init(void)
|
xcommon_init(void)
|
||||||
{
|
{
|
||||||
if (g_display != 0)
|
if (g_display != 0)
|
||||||
{
|
{
|
||||||
LOG(10, ("xcommon_init: xcommon_init already called"));
|
LOG(10, ("xcommon_init: xcommon_init already called"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_display = XOpenDisplay(0);
|
||||||
|
|
||||||
|
if (g_display == 0)
|
||||||
|
{
|
||||||
|
LOGM((LOG_LEVEL_ERROR, "xcommon_init: error, XOpenDisplay failed"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(0, ("xcommon_init: connected to display ok"));
|
||||||
|
|
||||||
|
/* setting the error handlers can cause problem when shutting down
|
||||||
|
chansrv on some xlibs */
|
||||||
|
XSetErrorHandler(xcommon_error_handler);
|
||||||
|
//XSetIOErrorHandler(xcommon_fatal_handler);
|
||||||
|
|
||||||
|
g_x_socket = XConnectionNumber(g_display);
|
||||||
|
|
||||||
|
if (g_x_socket == 0)
|
||||||
|
{
|
||||||
|
LOGM((LOG_LEVEL_ERROR, "xcommon_init: XConnectionNumber failed"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0);
|
||||||
|
g_screen_num = DefaultScreen(g_display);
|
||||||
|
g_screen = ScreenOfDisplay(g_display, g_screen_num);
|
||||||
|
|
||||||
|
g_root_window = RootWindowOfScreen(g_screen);
|
||||||
|
|
||||||
|
g_wm_delete_window_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", 0);
|
||||||
|
g_wm_protocols_atom = XInternAtom(g_display, "WM_PROTOCOLS", 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
g_display = XOpenDisplay(0);
|
|
||||||
if (g_display == 0)
|
|
||||||
{
|
|
||||||
LOGM((LOG_LEVEL_ERROR, "xcommon_init: error, XOpenDisplay failed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG(0, ("xcommon_init: connected to display ok"));
|
|
||||||
|
|
||||||
/* setting the error handlers can cause problem when shutting down
|
|
||||||
chansrv on some xlibs */
|
|
||||||
XSetErrorHandler(xcommon_error_handler);
|
|
||||||
//XSetIOErrorHandler(xcommon_fatal_handler);
|
|
||||||
|
|
||||||
g_x_socket = XConnectionNumber(g_display);
|
|
||||||
if (g_x_socket == 0)
|
|
||||||
{
|
|
||||||
LOGM((LOG_LEVEL_ERROR, "xcommon_init: XConnectionNumber failed"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0);
|
|
||||||
g_screen_num = DefaultScreen(g_display);
|
|
||||||
g_screen = ScreenOfDisplay(g_display, g_screen_num);
|
|
||||||
|
|
||||||
g_root_window = RootWindowOfScreen(g_screen);
|
|
||||||
|
|
||||||
g_wm_delete_window_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", 0);
|
|
||||||
g_wm_protocols_atom = XInternAtom(g_display, "WM_PROTOCOLS", 0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -122,66 +125,73 @@ xcommon_init(void)
|
|||||||
this is called to get any wait objects for the main loop
|
this is called to get any wait objects for the main loop
|
||||||
timeout can be nil */
|
timeout can be nil */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xcommon_get_wait_objs(tbus* objs, int* count, int* timeout)
|
xcommon_get_wait_objs(tbus *objs, int *count, int *timeout)
|
||||||
{
|
{
|
||||||
int lcount;
|
int lcount;
|
||||||
|
|
||||||
if (((!g_clip_up) && (!g_rail_up)) || (objs == 0) || (count == 0))
|
if (((!g_clip_up) && (!g_rail_up)) || (objs == 0) || (count == 0))
|
||||||
{
|
{
|
||||||
LOG(10, ("xcommon_get_wait_objs: nothing to do"));
|
LOG(10, ("xcommon_get_wait_objs: nothing to do"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lcount = *count;
|
||||||
|
objs[lcount] = g_x_wait_obj;
|
||||||
|
lcount++;
|
||||||
|
*count = lcount;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
lcount = *count;
|
|
||||||
objs[lcount] = g_x_wait_obj;
|
|
||||||
lcount++;
|
|
||||||
*count = lcount;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xcommon_check_wait_objs(void)
|
xcommon_check_wait_objs(void)
|
||||||
{
|
{
|
||||||
XEvent xevent;
|
XEvent xevent;
|
||||||
int time_diff;
|
int time_diff;
|
||||||
int clip_rv;
|
int clip_rv;
|
||||||
int rail_rv;
|
int rail_rv;
|
||||||
|
|
||||||
|
if ((!g_clip_up) && (!g_rail_up))
|
||||||
|
{
|
||||||
|
LOG(10, ("xcommon_check_wait_objs: nothing to do"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_is_wait_obj_set(g_x_wait_obj))
|
||||||
|
{
|
||||||
|
if (XPending(g_display) < 1)
|
||||||
|
{
|
||||||
|
/* something is wrong, should not get here */
|
||||||
|
LOGM((LOG_LEVEL_ERROR, "xcommon_check_wait_objs: sck closed"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_waiting_for_data_response)
|
||||||
|
{
|
||||||
|
time_diff = xcommon_get_local_time() -
|
||||||
|
g_waiting_for_data_response_time;
|
||||||
|
|
||||||
|
if (time_diff > 10000)
|
||||||
|
{
|
||||||
|
LOGM((LOG_LEVEL_ERROR, "xcommon_check_wait_objs: warning, "
|
||||||
|
"waiting for data response too long"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (XPending(g_display) > 0)
|
||||||
|
{
|
||||||
|
g_memset(&xevent, 0, sizeof(xevent));
|
||||||
|
XNextEvent(g_display, &xevent);
|
||||||
|
|
||||||
|
clip_rv = clipboard_xevent(&xevent);
|
||||||
|
rail_rv = rail_xevent(&xevent);
|
||||||
|
|
||||||
|
if ((clip_rv == 1) && (rail_rv == 1))
|
||||||
|
{
|
||||||
|
LOG(10, ("xcommon_check_wait_objs unknown xevent type %d", xevent.type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((!g_clip_up) && (!g_rail_up))
|
|
||||||
{
|
|
||||||
LOG(10, ("xcommon_check_wait_objs: nothing to do"));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
if (g_is_wait_obj_set(g_x_wait_obj))
|
|
||||||
{
|
|
||||||
if (XPending(g_display) < 1)
|
|
||||||
{
|
|
||||||
/* something is wrong, should not get here */
|
|
||||||
LOGM((LOG_LEVEL_ERROR, "xcommon_check_wait_objs: sck closed"));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (g_waiting_for_data_response)
|
|
||||||
{
|
|
||||||
time_diff = xcommon_get_local_time() -
|
|
||||||
g_waiting_for_data_response_time;
|
|
||||||
if (time_diff > 10000)
|
|
||||||
{
|
|
||||||
LOGM((LOG_LEVEL_ERROR, "xcommon_check_wait_objs: warning, "
|
|
||||||
"waiting for data response too long"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (XPending(g_display) > 0)
|
|
||||||
{
|
|
||||||
g_memset(&xevent, 0, sizeof(xevent));
|
|
||||||
XNextEvent(g_display, &xevent);
|
|
||||||
|
|
||||||
clip_rv = clipboard_xevent(&xevent);
|
|
||||||
rail_rv = rail_xevent(&xevent);
|
|
||||||
if ((clip_rv == 1) && (rail_rv == 1))
|
|
||||||
{
|
|
||||||
LOG(10, ("xcommon_check_wait_objs unknown xevent type %d", xevent.type));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+300
-278
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -31,146 +30,153 @@
|
|||||||
#include "sesman.h"
|
#include "sesman.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
extern struct config_sesman* g_cfg; /* in sesman.c */
|
extern struct config_sesman *g_cfg; /* in sesman.c */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
config_read(struct config_sesman* cfg)
|
config_read(struct config_sesman *cfg)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct list* sec;
|
struct list *sec;
|
||||||
struct list* param_n;
|
struct list *param_n;
|
||||||
struct list* param_v;
|
struct list *param_v;
|
||||||
char cfg_file[256];
|
char cfg_file[256];
|
||||||
|
|
||||||
g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH);
|
g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH);
|
||||||
fd = g_file_open(cfg_file);
|
fd = g_file_open(cfg_file);
|
||||||
if (-1 == fd)
|
|
||||||
{
|
if (-1 == fd)
|
||||||
//if (g_cfg->log.fd >= 0)
|
{
|
||||||
//{
|
//if (g_cfg->log.fd >= 0)
|
||||||
/* logging is already active */
|
//{
|
||||||
log_message(LOG_LEVEL_ALWAYS, "error opening %s in \
|
/* logging is already active */
|
||||||
|
log_message(LOG_LEVEL_ALWAYS, "error opening %s in \
|
||||||
config_read", cfg_file);
|
config_read", cfg_file);
|
||||||
//}
|
//}
|
||||||
//else
|
//else
|
||||||
//{
|
//{
|
||||||
g_printf("error opening %s in config_read", cfg_file);
|
g_printf("error opening %s in config_read", cfg_file);
|
||||||
//}
|
//}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
g_memset(cfg, 0, sizeof(struct config_sesman));
|
|
||||||
sec = list_create();
|
|
||||||
sec->auto_free = 1;
|
|
||||||
file_read_sections(fd, sec);
|
|
||||||
param_n = list_create();
|
|
||||||
param_n->auto_free = 1;
|
|
||||||
param_v = list_create();
|
|
||||||
param_v->auto_free = 1;
|
|
||||||
|
|
||||||
/* read global config */
|
g_memset(cfg, 0, sizeof(struct config_sesman));
|
||||||
config_read_globals(fd, cfg, param_n, param_v);
|
sec = list_create();
|
||||||
|
sec->auto_free = 1;
|
||||||
|
file_read_sections(fd, sec);
|
||||||
|
param_n = list_create();
|
||||||
|
param_n->auto_free = 1;
|
||||||
|
param_v = list_create();
|
||||||
|
param_v->auto_free = 1;
|
||||||
|
|
||||||
/* read Xvnc/X11rdp parameter list */
|
/* read global config */
|
||||||
config_read_vnc_params(fd, cfg, param_n, param_v);
|
config_read_globals(fd, cfg, param_n, param_v);
|
||||||
config_read_rdp_params(fd, cfg, param_n, param_v);
|
|
||||||
|
|
||||||
/* read logging config */
|
/* read Xvnc/X11rdp parameter list */
|
||||||
// config_read_logging(fd, &(cfg->log), param_n, param_v);
|
config_read_vnc_params(fd, cfg, param_n, param_v);
|
||||||
|
config_read_rdp_params(fd, cfg, param_n, param_v);
|
||||||
|
|
||||||
/* read security config */
|
/* read logging config */
|
||||||
config_read_security(fd, &(cfg->sec), param_n, param_v);
|
// config_read_logging(fd, &(cfg->log), param_n, param_v);
|
||||||
|
|
||||||
/* read session config */
|
/* read security config */
|
||||||
config_read_sessions(fd, &(cfg->sess), param_n, param_v);
|
config_read_security(fd, &(cfg->sec), param_n, param_v);
|
||||||
|
|
||||||
/* cleanup */
|
/* read session config */
|
||||||
list_delete(sec);
|
config_read_sessions(fd, &(cfg->sess), param_n, param_v);
|
||||||
list_delete(param_v);
|
|
||||||
list_delete(param_n);
|
/* cleanup */
|
||||||
g_file_close(fd);
|
list_delete(sec);
|
||||||
return 0;
|
list_delete(param_v);
|
||||||
|
list_delete(param_n);
|
||||||
|
g_file_close(fd);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
config_read_globals(int file, struct config_sesman* cf, struct list* param_n,
|
config_read_globals(int file, struct config_sesman *cf, struct list *param_n,
|
||||||
struct list* param_v)
|
struct list *param_v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char* buf;
|
char *buf;
|
||||||
|
|
||||||
list_clear(param_v);
|
list_clear(param_v);
|
||||||
list_clear(param_n);
|
list_clear(param_n);
|
||||||
|
|
||||||
/* resetting the struct */
|
/* resetting the struct */
|
||||||
cf->listen_address[0] = '\0';
|
cf->listen_address[0] = '\0';
|
||||||
cf->listen_port[0] = '\0';
|
cf->listen_port[0] = '\0';
|
||||||
cf->enable_user_wm = 0;
|
|
||||||
cf->user_wm[0] = '\0';
|
|
||||||
cf->default_wm[0] = '\0';
|
|
||||||
cf->auth_file_path = 0;
|
|
||||||
|
|
||||||
file_read_section(file, SESMAN_CFG_GLOBALS, param_n, param_v);
|
|
||||||
for (i = 0; i < param_n->count; i++)
|
|
||||||
{
|
|
||||||
buf = (char*)list_get_item(param_n, i);
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_DEFWM))
|
|
||||||
{
|
|
||||||
g_strncpy(cf->default_wm, (char*)list_get_item(param_v, i), 31);
|
|
||||||
}
|
|
||||||
else if (0 == g_strcasecmp(buf, SESMAN_CFG_USERWM))
|
|
||||||
{
|
|
||||||
g_strncpy(cf->user_wm, (char*)list_get_item(param_v, i), 31);
|
|
||||||
}
|
|
||||||
else if (0 == g_strcasecmp(buf, SESMAN_CFG_ENABLE_USERWM))
|
|
||||||
{
|
|
||||||
cf->enable_user_wm = text2bool((char*)list_get_item(param_v, i));
|
|
||||||
}
|
|
||||||
else if (0 == g_strcasecmp(buf, SESMAN_CFG_PORT))
|
|
||||||
{
|
|
||||||
g_strncpy(cf->listen_port, (char*)list_get_item(param_v, i), 15);
|
|
||||||
}
|
|
||||||
else if (0 == g_strcasecmp(buf, SESMAN_CFG_ADDRESS))
|
|
||||||
{
|
|
||||||
g_strncpy(cf->listen_address, (char*)list_get_item(param_v, i), 31);
|
|
||||||
}
|
|
||||||
else if (0 == g_strcasecmp(buf, SESMAN_CFG_AUTH_FILE_PATH))
|
|
||||||
{
|
|
||||||
cf->auth_file_path = g_strdup((char*)list_get_item(param_v, i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* checking for missing required parameters */
|
|
||||||
if ('\0' == cf->listen_address[0])
|
|
||||||
{
|
|
||||||
g_strncpy(cf->listen_address, "0.0.0.0", 8);
|
|
||||||
}
|
|
||||||
if ('\0' == cf->listen_port[0])
|
|
||||||
{
|
|
||||||
g_strncpy(cf->listen_port, "3350", 5);
|
|
||||||
}
|
|
||||||
if ('\0' == cf->user_wm[0])
|
|
||||||
{
|
|
||||||
cf->enable_user_wm = 0;
|
cf->enable_user_wm = 0;
|
||||||
}
|
cf->user_wm[0] = '\0';
|
||||||
if ('\0' == cf->default_wm[0])
|
cf->default_wm[0] = '\0';
|
||||||
{
|
cf->auth_file_path = 0;
|
||||||
g_strncpy(cf->default_wm, "startwm.sh", 11);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* showing read config */
|
file_read_section(file, SESMAN_CFG_GLOBALS, param_n, param_v);
|
||||||
g_printf("sesman config:\r\n");
|
|
||||||
g_printf("\tListenAddress: %s\r\n", cf->listen_address);
|
|
||||||
g_printf("\tListenPort: %s\r\n", cf->listen_port);
|
|
||||||
g_printf("\tEnableUserWindowManager: %i\r\n", cf->enable_user_wm);
|
|
||||||
g_printf("\tUserWindowManager: %s\r\n", cf->user_wm);
|
|
||||||
g_printf("\tDefaultWindowManager: %s\r\n", cf->default_wm);
|
|
||||||
g_printf("\tAuthFilePath: %s\r\n", ((cf->auth_file_path) ? (cf->auth_file_path) : ("disabled")));
|
|
||||||
|
|
||||||
return 0;
|
for (i = 0; i < param_n->count; i++)
|
||||||
|
{
|
||||||
|
buf = (char *)list_get_item(param_n, i);
|
||||||
|
|
||||||
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_DEFWM))
|
||||||
|
{
|
||||||
|
g_strncpy(cf->default_wm, (char *)list_get_item(param_v, i), 31);
|
||||||
|
}
|
||||||
|
else if (0 == g_strcasecmp(buf, SESMAN_CFG_USERWM))
|
||||||
|
{
|
||||||
|
g_strncpy(cf->user_wm, (char *)list_get_item(param_v, i), 31);
|
||||||
|
}
|
||||||
|
else if (0 == g_strcasecmp(buf, SESMAN_CFG_ENABLE_USERWM))
|
||||||
|
{
|
||||||
|
cf->enable_user_wm = text2bool((char *)list_get_item(param_v, i));
|
||||||
|
}
|
||||||
|
else if (0 == g_strcasecmp(buf, SESMAN_CFG_PORT))
|
||||||
|
{
|
||||||
|
g_strncpy(cf->listen_port, (char *)list_get_item(param_v, i), 15);
|
||||||
|
}
|
||||||
|
else if (0 == g_strcasecmp(buf, SESMAN_CFG_ADDRESS))
|
||||||
|
{
|
||||||
|
g_strncpy(cf->listen_address, (char *)list_get_item(param_v, i), 31);
|
||||||
|
}
|
||||||
|
else if (0 == g_strcasecmp(buf, SESMAN_CFG_AUTH_FILE_PATH))
|
||||||
|
{
|
||||||
|
cf->auth_file_path = g_strdup((char *)list_get_item(param_v, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* checking for missing required parameters */
|
||||||
|
if ('\0' == cf->listen_address[0])
|
||||||
|
{
|
||||||
|
g_strncpy(cf->listen_address, "0.0.0.0", 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('\0' == cf->listen_port[0])
|
||||||
|
{
|
||||||
|
g_strncpy(cf->listen_port, "3350", 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('\0' == cf->user_wm[0])
|
||||||
|
{
|
||||||
|
cf->enable_user_wm = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('\0' == cf->default_wm[0])
|
||||||
|
{
|
||||||
|
g_strncpy(cf->default_wm, "startwm.sh", 11);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* showing read config */
|
||||||
|
g_printf("sesman config:\r\n");
|
||||||
|
g_printf("\tListenAddress: %s\r\n", cf->listen_address);
|
||||||
|
g_printf("\tListenPort: %s\r\n", cf->listen_port);
|
||||||
|
g_printf("\tEnableUserWindowManager: %i\r\n", cf->enable_user_wm);
|
||||||
|
g_printf("\tUserWindowManager: %s\r\n", cf->user_wm);
|
||||||
|
g_printf("\tDefaultWindowManager: %s\r\n", cf->default_wm);
|
||||||
|
g_printf("\tAuthFilePath: %s\r\n", ((cf->auth_file_path) ? (cf->auth_file_path) : ("disabled")));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
@@ -230,185 +236,201 @@ config_read_logging(int file, struct log_config* lc, struct list* param_n,
|
|||||||
*/
|
*/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
config_read_security(int file, struct config_security* sc,
|
config_read_security(int file, struct config_security *sc,
|
||||||
struct list* param_n,
|
struct list *param_n,
|
||||||
struct list* param_v)
|
struct list *param_v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int gid;
|
int gid;
|
||||||
char* buf;
|
char *buf;
|
||||||
|
|
||||||
list_clear(param_v);
|
list_clear(param_v);
|
||||||
list_clear(param_n);
|
list_clear(param_n);
|
||||||
|
|
||||||
/* setting defaults */
|
/* setting defaults */
|
||||||
sc->allow_root = 0;
|
sc->allow_root = 0;
|
||||||
sc->login_retry = 3;
|
sc->login_retry = 3;
|
||||||
sc->ts_users_enable = 0;
|
sc->ts_users_enable = 0;
|
||||||
sc->ts_admins_enable = 0;
|
sc->ts_admins_enable = 0;
|
||||||
|
|
||||||
file_read_section(file, SESMAN_CFG_SECURITY, param_n, param_v);
|
file_read_section(file, SESMAN_CFG_SECURITY, param_n, param_v);
|
||||||
for (i = 0; i < param_n->count; i++)
|
|
||||||
{
|
for (i = 0; i < param_n->count; i++)
|
||||||
buf = (char*)list_get_item(param_n, i);
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ALLOW_ROOT))
|
|
||||||
{
|
{
|
||||||
sc->allow_root = text2bool((char*)list_get_item(param_v, i));
|
buf = (char *)list_get_item(param_n, i);
|
||||||
}
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_LOGIN_RETRY))
|
|
||||||
{
|
|
||||||
sc->login_retry = g_atoi((char*)list_get_item(param_v, i));
|
|
||||||
}
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_USR_GROUP))
|
|
||||||
{
|
|
||||||
if (g_getgroup_info((char*)list_get_item(param_v, i), &gid) == 0)
|
|
||||||
{
|
|
||||||
sc->ts_users_enable = 1;
|
|
||||||
sc->ts_users = gid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ADM_GROUP))
|
|
||||||
{
|
|
||||||
if (g_getgroup_info((char*)list_get_item(param_v, i), &gid) == 0)
|
|
||||||
{
|
|
||||||
sc->ts_admins_enable = 1;
|
|
||||||
sc->ts_admins = gid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* printing security config */
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ALLOW_ROOT))
|
||||||
g_printf("security configuration:\r\n");
|
{
|
||||||
g_printf("\tAllowRootLogin: %i\r\n",sc->allow_root);
|
sc->allow_root = text2bool((char *)list_get_item(param_v, i));
|
||||||
g_printf("\tMaxLoginRetry: %i\r\n",sc->login_retry);
|
}
|
||||||
if (sc->ts_users_enable)
|
|
||||||
{
|
|
||||||
g_printf("\tTSUsersGroup: %i\r\n", sc->ts_users);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_printf("\tNo TSUsersGroup defined\r\n");
|
|
||||||
}
|
|
||||||
if (sc->ts_admins_enable)
|
|
||||||
{
|
|
||||||
g_printf("\tTSAdminsGroup: %i\r\n", sc->ts_admins);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_printf("\tNo TSAdminsGroup defined\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_LOGIN_RETRY))
|
||||||
|
{
|
||||||
|
sc->login_retry = g_atoi((char *)list_get_item(param_v, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_USR_GROUP))
|
||||||
|
{
|
||||||
|
if (g_getgroup_info((char *)list_get_item(param_v, i), &gid) == 0)
|
||||||
|
{
|
||||||
|
sc->ts_users_enable = 1;
|
||||||
|
sc->ts_users = gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ADM_GROUP))
|
||||||
|
{
|
||||||
|
if (g_getgroup_info((char *)list_get_item(param_v, i), &gid) == 0)
|
||||||
|
{
|
||||||
|
sc->ts_admins_enable = 1;
|
||||||
|
sc->ts_admins = gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* printing security config */
|
||||||
|
g_printf("security configuration:\r\n");
|
||||||
|
g_printf("\tAllowRootLogin: %i\r\n", sc->allow_root);
|
||||||
|
g_printf("\tMaxLoginRetry: %i\r\n", sc->login_retry);
|
||||||
|
|
||||||
|
if (sc->ts_users_enable)
|
||||||
|
{
|
||||||
|
g_printf("\tTSUsersGroup: %i\r\n", sc->ts_users);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_printf("\tNo TSUsersGroup defined\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sc->ts_admins_enable)
|
||||||
|
{
|
||||||
|
g_printf("\tTSAdminsGroup: %i\r\n", sc->ts_admins);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_printf("\tNo TSAdminsGroup defined\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
config_read_sessions(int file, struct config_sessions* se, struct list* param_n,
|
config_read_sessions(int file, struct config_sessions *se, struct list *param_n,
|
||||||
struct list* param_v)
|
struct list *param_v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char* buf;
|
char *buf;
|
||||||
|
|
||||||
list_clear(param_v);
|
list_clear(param_v);
|
||||||
list_clear(param_n);
|
list_clear(param_n);
|
||||||
|
|
||||||
/* setting defaults */
|
/* setting defaults */
|
||||||
se->x11_display_offset=10;
|
se->x11_display_offset = 10;
|
||||||
se->max_sessions=0;
|
se->max_sessions = 0;
|
||||||
se->max_idle_time=0;
|
se->max_idle_time = 0;
|
||||||
se->max_disc_time=0;
|
se->max_disc_time = 0;
|
||||||
se->kill_disconnected=0;
|
se->kill_disconnected = 0;
|
||||||
|
|
||||||
file_read_section(file, SESMAN_CFG_SESSIONS, param_n, param_v);
|
file_read_section(file, SESMAN_CFG_SESSIONS, param_n, param_v);
|
||||||
for (i = 0; i < param_n->count; i++)
|
|
||||||
{
|
|
||||||
buf = (char*)list_get_item(param_n, i);
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_X11DISPLAYOFFSET))
|
|
||||||
{
|
|
||||||
se->x11_display_offset = g_atoi((char*)list_get_item(param_v, i));
|
|
||||||
}
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_MAX))
|
|
||||||
{
|
|
||||||
se->max_sessions = g_atoi((char*)list_get_item(param_v, i));
|
|
||||||
}
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_KILL_DISC))
|
|
||||||
{
|
|
||||||
se->kill_disconnected = text2bool((char*)list_get_item(param_v, i));
|
|
||||||
}
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_IDLE_LIMIT))
|
|
||||||
{
|
|
||||||
se->max_idle_time=g_atoi((char*)list_get_item(param_v, i));
|
|
||||||
}
|
|
||||||
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_DISC_LIMIT))
|
|
||||||
{
|
|
||||||
se->max_disc_time=g_atoi((char*)list_get_item(param_v, i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* printing security config */
|
for (i = 0; i < param_n->count; i++)
|
||||||
g_printf("session configuration:\r\n");
|
{
|
||||||
g_printf("\tMaxSessions: %i\r\n", se->max_sessions);
|
buf = (char *)list_get_item(param_n, i);
|
||||||
g_printf("\tX11DisplayOffset: %i\r\n", se->x11_display_offset);
|
|
||||||
g_printf("\tKillDisconnected: %i\r\n", se->kill_disconnected);
|
|
||||||
g_printf("\tIdleTimeLimit: %i\r\n", se->max_idle_time);
|
|
||||||
g_printf("\tDisconnectedTimeLimit: %i\r\n", se->max_idle_time);
|
|
||||||
|
|
||||||
return 0;
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_X11DISPLAYOFFSET))
|
||||||
|
{
|
||||||
|
se->x11_display_offset = g_atoi((char *)list_get_item(param_v, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_MAX))
|
||||||
|
{
|
||||||
|
se->max_sessions = g_atoi((char *)list_get_item(param_v, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_KILL_DISC))
|
||||||
|
{
|
||||||
|
se->kill_disconnected = text2bool((char *)list_get_item(param_v, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_IDLE_LIMIT))
|
||||||
|
{
|
||||||
|
se->max_idle_time = g_atoi((char *)list_get_item(param_v, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_DISC_LIMIT))
|
||||||
|
{
|
||||||
|
se->max_disc_time = g_atoi((char *)list_get_item(param_v, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* printing security config */
|
||||||
|
g_printf("session configuration:\r\n");
|
||||||
|
g_printf("\tMaxSessions: %i\r\n", se->max_sessions);
|
||||||
|
g_printf("\tX11DisplayOffset: %i\r\n", se->x11_display_offset);
|
||||||
|
g_printf("\tKillDisconnected: %i\r\n", se->kill_disconnected);
|
||||||
|
g_printf("\tIdleTimeLimit: %i\r\n", se->max_idle_time);
|
||||||
|
g_printf("\tDisconnectedTimeLimit: %i\r\n", se->max_idle_time);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
config_read_rdp_params(int file, struct config_sesman* cs, struct list* param_n,
|
config_read_rdp_params(int file, struct config_sesman *cs, struct list *param_n,
|
||||||
struct list* param_v)
|
struct list *param_v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
list_clear(param_v);
|
list_clear(param_v);
|
||||||
list_clear(param_n);
|
list_clear(param_n);
|
||||||
|
|
||||||
cs->rdp_params=list_create();
|
cs->rdp_params = list_create();
|
||||||
|
|
||||||
file_read_section(file, SESMAN_CFG_RDP_PARAMS, param_n, param_v);
|
file_read_section(file, SESMAN_CFG_RDP_PARAMS, param_n, param_v);
|
||||||
for (i = 0; i < param_n->count; i++)
|
|
||||||
{
|
|
||||||
list_add_item(cs->rdp_params, (long)g_strdup((char*)list_get_item(param_v, i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* printing security config */
|
for (i = 0; i < param_n->count; i++)
|
||||||
g_printf("X11rdp parameters:\r\n");
|
{
|
||||||
for (i = 0; i < cs->rdp_params->count; i++)
|
list_add_item(cs->rdp_params, (long)g_strdup((char *)list_get_item(param_v, i)));
|
||||||
{
|
}
|
||||||
g_printf("\tParameter %02d %s\r\n", i, (char*)list_get_item(cs->rdp_params, i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
/* printing security config */
|
||||||
|
g_printf("X11rdp parameters:\r\n");
|
||||||
|
|
||||||
|
for (i = 0; i < cs->rdp_params->count; i++)
|
||||||
|
{
|
||||||
|
g_printf("\tParameter %02d %s\r\n", i, (char *)list_get_item(cs->rdp_params, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
config_read_vnc_params(int file, struct config_sesman* cs, struct list* param_n,
|
config_read_vnc_params(int file, struct config_sesman *cs, struct list *param_n,
|
||||||
struct list* param_v)
|
struct list *param_v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
list_clear(param_v);
|
list_clear(param_v);
|
||||||
list_clear(param_n);
|
list_clear(param_n);
|
||||||
|
|
||||||
cs->vnc_params=list_create();
|
cs->vnc_params = list_create();
|
||||||
|
|
||||||
file_read_section(file, SESMAN_CFG_VNC_PARAMS, param_n, param_v);
|
file_read_section(file, SESMAN_CFG_VNC_PARAMS, param_n, param_v);
|
||||||
for (i = 0; i < param_n->count; i++)
|
|
||||||
{
|
|
||||||
list_add_item(cs->vnc_params, (long)g_strdup((char*)list_get_item(param_v, i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* printing security config */
|
for (i = 0; i < param_n->count; i++)
|
||||||
g_printf("Xvnc parameters:\r\n");
|
{
|
||||||
for (i = 0; i < cs->vnc_params->count; i++)
|
list_add_item(cs->vnc_params, (long)g_strdup((char *)list_get_item(param_v, i)));
|
||||||
{
|
}
|
||||||
g_printf("\tParameter %02d %s\r\n", i, (char*)list_get_item(cs->vnc_params, i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
/* printing security config */
|
||||||
|
g_printf("Xvnc parameters:\r\n");
|
||||||
|
|
||||||
|
for (i = 0; i < cs->vnc_params->count; i++)
|
||||||
|
{
|
||||||
|
g_printf("\tParameter %02d %s\r\n", i, (char *)list_get_item(cs->vnc_params, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-19
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -296,4 +295,3 @@ config_read_vnc_params(int file, struct config_sesman* cs, struct list* param_n,
|
|||||||
struct list* param_v);
|
struct list* param_v);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+100
-91
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -31,95 +30,105 @@
|
|||||||
#include "grp.h"
|
#include "grp.h"
|
||||||
|
|
||||||
extern unsigned char g_fixedkey[8]; /* in sesman.c */
|
extern unsigned char g_fixedkey[8]; /* in sesman.c */
|
||||||
extern struct config_sesman* g_cfg; /* in sesman.c */
|
extern struct config_sesman *g_cfg; /* in sesman.c */
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
env_check_password_file(char* filename, char* password)
|
env_check_password_file(char *filename, char *password)
|
||||||
{
|
{
|
||||||
char encryptedPasswd[16];
|
char encryptedPasswd[16];
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
g_memset(encryptedPasswd, 0, 16);
|
g_memset(encryptedPasswd, 0, 16);
|
||||||
g_strncpy(encryptedPasswd, password, 8);
|
g_strncpy(encryptedPasswd, password, 8);
|
||||||
rfbDesKey(g_fixedkey, 0);
|
rfbDesKey(g_fixedkey, 0);
|
||||||
rfbDes((unsigned char*)encryptedPasswd, (unsigned char*)encryptedPasswd);
|
rfbDes((unsigned char *)encryptedPasswd, (unsigned char *)encryptedPasswd);
|
||||||
fd = g_file_open(filename);
|
fd = g_file_open(filename);
|
||||||
if (fd == -1)
|
|
||||||
{
|
if (fd == -1)
|
||||||
log_message(LOG_LEVEL_WARNING,
|
{
|
||||||
"can't read vnc password file - %s",
|
log_message(LOG_LEVEL_WARNING,
|
||||||
filename);
|
"can't read vnc password file - %s",
|
||||||
return 1;
|
filename);
|
||||||
}
|
return 1;
|
||||||
g_file_write(fd, encryptedPasswd, 8);
|
}
|
||||||
g_file_close(fd);
|
|
||||||
return 0;
|
g_file_write(fd, encryptedPasswd, 8);
|
||||||
|
g_file_close(fd);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
env_set_user(char* username, char* passwd_file, int display)
|
env_set_user(char *username, char *passwd_file, int display)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
int pw_uid;
|
int pw_uid;
|
||||||
int pw_gid;
|
int pw_gid;
|
||||||
int uid;
|
int uid;
|
||||||
char pw_shell[256];
|
char pw_shell[256];
|
||||||
char pw_dir[256];
|
char pw_dir[256];
|
||||||
char pw_gecos[256];
|
char pw_gecos[256];
|
||||||
char text[256];
|
char text[256];
|
||||||
|
|
||||||
|
error = g_getuser_info(username, &pw_gid, &pw_uid, pw_shell, pw_dir,
|
||||||
|
pw_gecos);
|
||||||
|
|
||||||
error = g_getuser_info(username, &pw_gid, &pw_uid, pw_shell, pw_dir,
|
|
||||||
pw_gecos);
|
|
||||||
if (error == 0)
|
|
||||||
{
|
|
||||||
g_rm_temp_dir();
|
|
||||||
error = g_setgid(pw_gid);
|
|
||||||
if (error == 0)
|
if (error == 0)
|
||||||
{
|
{
|
||||||
error = g_initgroups(username, pw_gid);
|
g_rm_temp_dir();
|
||||||
}
|
error = g_setgid(pw_gid);
|
||||||
if (error == 0)
|
|
||||||
{
|
if (error == 0)
|
||||||
uid = pw_uid;
|
|
||||||
error = g_setuid(uid);
|
|
||||||
}
|
|
||||||
g_mk_temp_dir(0);
|
|
||||||
if (error == 0)
|
|
||||||
{
|
|
||||||
g_clearenv();
|
|
||||||
g_setenv("SHELL", pw_shell, 1);
|
|
||||||
g_setenv("PATH", "/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin", 1);
|
|
||||||
g_setenv("USER", username, 1);
|
|
||||||
g_sprintf(text, "%d", uid);
|
|
||||||
g_setenv("UID", text, 1);
|
|
||||||
g_setenv("HOME", pw_dir, 1);
|
|
||||||
g_set_current_dir(pw_dir);
|
|
||||||
g_sprintf(text, ":%d.0", display);
|
|
||||||
g_setenv("DISPLAY", text, 1);
|
|
||||||
if (passwd_file != 0)
|
|
||||||
{
|
|
||||||
if (0 == g_cfg->auth_file_path)
|
|
||||||
{
|
{
|
||||||
/* if no auth_file_path is set, then we go for
|
error = g_initgroups(username, pw_gid);
|
||||||
$HOME/.vnc/sesman_username_passwd */
|
|
||||||
g_mkdir(".vnc");
|
|
||||||
g_sprintf(passwd_file, "%s/.vnc/sesman_%s_passwd", pw_dir, username);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (error == 0)
|
||||||
{
|
{
|
||||||
/* we use auth_file_path as requested */
|
uid = pw_uid;
|
||||||
g_sprintf(passwd_file, g_cfg->auth_file_path, username);
|
error = g_setuid(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_mk_temp_dir(0);
|
||||||
|
|
||||||
|
if (error == 0)
|
||||||
|
{
|
||||||
|
g_clearenv();
|
||||||
|
g_setenv("SHELL", pw_shell, 1);
|
||||||
|
g_setenv("PATH", "/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin", 1);
|
||||||
|
g_setenv("USER", username, 1);
|
||||||
|
g_sprintf(text, "%d", uid);
|
||||||
|
g_setenv("UID", text, 1);
|
||||||
|
g_setenv("HOME", pw_dir, 1);
|
||||||
|
g_set_current_dir(pw_dir);
|
||||||
|
g_sprintf(text, ":%d.0", display);
|
||||||
|
g_setenv("DISPLAY", text, 1);
|
||||||
|
|
||||||
|
if (passwd_file != 0)
|
||||||
|
{
|
||||||
|
if (0 == g_cfg->auth_file_path)
|
||||||
|
{
|
||||||
|
/* if no auth_file_path is set, then we go for
|
||||||
|
$HOME/.vnc/sesman_username_passwd */
|
||||||
|
g_mkdir(".vnc");
|
||||||
|
g_sprintf(passwd_file, "%s/.vnc/sesman_%s_passwd", pw_dir, username);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* we use auth_file_path as requested */
|
||||||
|
g_sprintf(passwd_file, g_cfg->auth_file_path, username);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DBG("pass file: %s", passwd_file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LOG_DBG("pass file: %s", passwd_file);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
log_message(LOG_LEVEL_ERROR,
|
||||||
log_message(LOG_LEVEL_ERROR,
|
"error getting user info for user %s", username);
|
||||||
"error getting user info for user %s", username);
|
}
|
||||||
}
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-19
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -52,4 +51,3 @@ int DEFAULT_CC
|
|||||||
env_set_user(char* username, char* passwd_file, int display);
|
env_set_user(char* username, char* passwd_file, int display);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+17
-18
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -29,32 +28,32 @@
|
|||||||
|
|
||||||
//extern struct log_config* s_log;
|
//extern struct log_config* s_log;
|
||||||
|
|
||||||
struct SCP_CONNECTION*
|
struct SCP_CONNECTION *
|
||||||
scp_connection_create(int sck)
|
scp_connection_create(int sck)
|
||||||
{
|
{
|
||||||
struct SCP_CONNECTION* conn;
|
struct SCP_CONNECTION *conn;
|
||||||
|
|
||||||
conn = g_malloc(sizeof(struct SCP_CONNECTION), 0);
|
conn = g_malloc(sizeof(struct SCP_CONNECTION), 0);
|
||||||
|
|
||||||
if (0 == conn)
|
if (0 == conn)
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[connection:%d] connection create: malloc error", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[connection:%d] connection create: malloc error", __LINE__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->in_sck=sck;
|
conn->in_sck = sck;
|
||||||
make_stream(conn->in_s);
|
make_stream(conn->in_s);
|
||||||
init_stream(conn->in_s, 8196);
|
init_stream(conn->in_s, 8196);
|
||||||
make_stream(conn->out_s);
|
make_stream(conn->out_s);
|
||||||
init_stream(conn->out_s, 8196);
|
init_stream(conn->out_s, 8196);
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
scp_connection_destroy(struct SCP_CONNECTION* c)
|
scp_connection_destroy(struct SCP_CONNECTION *c)
|
||||||
{
|
{
|
||||||
free_stream(c->in_s);
|
free_stream(c->in_s);
|
||||||
free_stream(c->out_s);
|
free_stream(c->out_s);
|
||||||
g_free(c);
|
g_free(c);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -51,4 +50,3 @@ void
|
|||||||
scp_connection_destroy(struct SCP_CONNECTION* c);
|
scp_connection_destroy(struct SCP_CONNECTION* c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+27
-29
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -33,19 +32,18 @@
|
|||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
scp_init()
|
scp_init()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
if (0 == log)
|
if (0 == log)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//s_log = log;
|
//s_log = log;
|
||||||
|
|
||||||
scp_lock_init();
|
scp_lock_init();
|
||||||
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[init:%d] libscp initialized", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[init:%d] libscp initialized", __LINE__);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-19
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -45,4 +44,3 @@ int DEFAULT_CC
|
|||||||
scp_init();
|
scp_init();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+95
-93
@@ -1,25 +1,23 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*
|
||||||
|
* session manager
|
||||||
session manager
|
* linux only
|
||||||
linux only
|
*/
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libscp_lock.h"
|
#include "libscp_lock.h"
|
||||||
|
|
||||||
@@ -37,110 +35,114 @@ int lock_fork_waiting_count; /* threads suspended until the fork finish
|
|||||||
void DEFAULT_CC
|
void DEFAULT_CC
|
||||||
scp_lock_init(void)
|
scp_lock_init(void)
|
||||||
{
|
{
|
||||||
/* initializing fork lock */
|
/* initializing fork lock */
|
||||||
pthread_mutexattr_init(&lock_fork_attr);
|
pthread_mutexattr_init(&lock_fork_attr);
|
||||||
pthread_mutex_init(&lock_fork, &lock_fork_attr);
|
pthread_mutex_init(&lock_fork, &lock_fork_attr);
|
||||||
sem_init(&lock_fork_req, 0, 0);
|
sem_init(&lock_fork_req, 0, 0);
|
||||||
sem_init(&lock_fork_wait, 0, 0);
|
sem_init(&lock_fork_wait, 0, 0);
|
||||||
|
|
||||||
/* here we don't use locking because lock_init() should be called BEFORE */
|
/* here we don't use locking because lock_init() should be called BEFORE */
|
||||||
/* any thread is created */
|
/* any thread is created */
|
||||||
lock_fork_blockers_count=0;
|
lock_fork_blockers_count = 0;
|
||||||
lock_fork_waiting_count=0;
|
lock_fork_waiting_count = 0;
|
||||||
lock_fork_forkers_count=0;
|
lock_fork_forkers_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
void DEFAULT_CC
|
void DEFAULT_CC
|
||||||
scp_lock_fork_request(void)
|
scp_lock_fork_request(void)
|
||||||
{
|
{
|
||||||
/* lock mutex */
|
/* lock mutex */
|
||||||
pthread_mutex_lock(&lock_fork);
|
pthread_mutex_lock(&lock_fork);
|
||||||
if (lock_fork_blockers_count == 0)
|
|
||||||
{
|
|
||||||
/* if noone is blocking fork(), then we're allowed to fork */
|
|
||||||
sem_post(&lock_fork_req);
|
|
||||||
}
|
|
||||||
lock_fork_forkers_count++;
|
|
||||||
pthread_mutex_unlock(&lock_fork);
|
|
||||||
|
|
||||||
/* we wait to be allowed to fork() */
|
if (lock_fork_blockers_count == 0)
|
||||||
sem_wait(&lock_fork_req);
|
{
|
||||||
|
/* if noone is blocking fork(), then we're allowed to fork */
|
||||||
|
sem_post(&lock_fork_req);
|
||||||
|
}
|
||||||
|
|
||||||
|
lock_fork_forkers_count++;
|
||||||
|
pthread_mutex_unlock(&lock_fork);
|
||||||
|
|
||||||
|
/* we wait to be allowed to fork() */
|
||||||
|
sem_wait(&lock_fork_req);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
void DEFAULT_CC
|
void DEFAULT_CC
|
||||||
scp_lock_fork_release(void)
|
scp_lock_fork_release(void)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&lock_fork);
|
pthread_mutex_lock(&lock_fork);
|
||||||
lock_fork_forkers_count--;
|
lock_fork_forkers_count--;
|
||||||
|
|
||||||
/* if there's someone else that want to fork, we let him fork() */
|
/* if there's someone else that want to fork, we let him fork() */
|
||||||
if (lock_fork_forkers_count > 0)
|
if (lock_fork_forkers_count > 0)
|
||||||
{
|
{
|
||||||
sem_post(&lock_fork_req);
|
sem_post(&lock_fork_req);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;lock_fork_waiting_count > 0; lock_fork_waiting_count--)
|
for (; lock_fork_waiting_count > 0; lock_fork_waiting_count--)
|
||||||
{
|
{
|
||||||
/* waking up the other processes */
|
/* waking up the other processes */
|
||||||
sem_post(&lock_fork_wait);
|
sem_post(&lock_fork_wait);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&lock_fork);
|
|
||||||
|
pthread_mutex_unlock(&lock_fork);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
void DEFAULT_CC
|
void DEFAULT_CC
|
||||||
scp_lock_fork_critical_section_end(int blocking)
|
scp_lock_fork_critical_section_end(int blocking)
|
||||||
{
|
{
|
||||||
//LOG_DBG("lock_fork_critical_secection_end()",0);
|
//LOG_DBG("lock_fork_critical_secection_end()",0);
|
||||||
/* lock mutex */
|
/* lock mutex */
|
||||||
pthread_mutex_lock(&lock_fork);
|
pthread_mutex_lock(&lock_fork);
|
||||||
|
|
||||||
if (blocking == LIBSCP_LOCK_FORK_BLOCKER)
|
if (blocking == LIBSCP_LOCK_FORK_BLOCKER)
|
||||||
{
|
{
|
||||||
lock_fork_blockers_count--;
|
lock_fork_blockers_count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if there's someone who wants to fork and we're the last blocking */
|
/* if there's someone who wants to fork and we're the last blocking */
|
||||||
/* then we let him go */
|
/* then we let him go */
|
||||||
if ((lock_fork_blockers_count == 0) && (lock_fork_forkers_count>0))
|
if ((lock_fork_blockers_count == 0) && (lock_fork_forkers_count > 0))
|
||||||
{
|
{
|
||||||
sem_post(&lock_fork_req);
|
sem_post(&lock_fork_req);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&lock_fork);
|
|
||||||
|
pthread_mutex_unlock(&lock_fork);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
scp_lock_fork_critical_section_start(void)
|
scp_lock_fork_critical_section_start(void)
|
||||||
{
|
{
|
||||||
//LOG_DBG("lock_fork_critical_secection_start()",0);
|
//LOG_DBG("lock_fork_critical_secection_start()",0);
|
||||||
do
|
do
|
||||||
{
|
|
||||||
pthread_mutex_lock(&lock_fork);
|
|
||||||
|
|
||||||
/* someone requested to fork */
|
|
||||||
if (lock_fork_forkers_count > 0)
|
|
||||||
{
|
{
|
||||||
lock_fork_waiting_count++;
|
pthread_mutex_lock(&lock_fork);
|
||||||
pthread_mutex_unlock(&lock_fork);
|
|
||||||
|
|
||||||
/* we wait until the fork finishes */
|
/* someone requested to fork */
|
||||||
sem_wait(&lock_fork_wait);
|
if (lock_fork_forkers_count > 0)
|
||||||
|
{
|
||||||
|
lock_fork_waiting_count++;
|
||||||
|
pthread_mutex_unlock(&lock_fork);
|
||||||
|
|
||||||
|
/* we wait until the fork finishes */
|
||||||
|
sem_wait(&lock_fork_wait);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* no fork, so we can go on... */
|
||||||
|
lock_fork_blockers_count++;
|
||||||
|
pthread_mutex_unlock(&lock_fork);
|
||||||
|
|
||||||
|
return LIBSCP_LOCK_FORK_BLOCKER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
while (1);
|
||||||
{
|
|
||||||
/* no fork, so we can go on... */
|
|
||||||
lock_fork_blockers_count++;
|
|
||||||
pthread_mutex_unlock(&lock_fork);
|
|
||||||
|
|
||||||
return LIBSCP_LOCK_FORK_BLOCKER;
|
/* we'll never get here */
|
||||||
}
|
return LIBSCP_LOCK_FORK_WAITING;
|
||||||
} while (1);
|
|
||||||
|
|
||||||
/* we'll never get here */
|
|
||||||
return LIBSCP_LOCK_FORK_WAITING;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-19
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBSCP_LOCK_H
|
#ifndef LIBSCP_LOCK_H
|
||||||
#define LIBSCP_LOCK_H
|
#define LIBSCP_LOCK_H
|
||||||
@@ -72,4 +71,3 @@ void DEFAULT_CC
|
|||||||
scp_lock_fork_critical_section_end(int blocking);
|
scp_lock_fork_critical_section_end(int blocking);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+368
-323
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -34,379 +33,425 @@
|
|||||||
//extern struct log_config* s_log;
|
//extern struct log_config* s_log;
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
struct SCP_SESSION*
|
struct SCP_SESSION *
|
||||||
scp_session_create()
|
scp_session_create()
|
||||||
{
|
{
|
||||||
struct SCP_SESSION* s;
|
struct SCP_SESSION *s;
|
||||||
|
|
||||||
|
s = (struct SCP_SESSION *)g_malloc(sizeof(struct SCP_SESSION), 1);
|
||||||
|
|
||||||
|
if (0 == s)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] session create: malloc error", __LINE__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
int
|
||||||
|
scp_session_set_type(struct SCP_SESSION *s, tui8 type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case SCP_SESSION_TYPE_XVNC:
|
||||||
|
s->type = SCP_SESSION_TYPE_XVNC;
|
||||||
|
break;
|
||||||
|
case SCP_SESSION_TYPE_XRDP:
|
||||||
|
s->type = SCP_SESSION_TYPE_XRDP;
|
||||||
|
break;
|
||||||
|
case SCP_GW_AUTHENTICATION:
|
||||||
|
s->type = SCP_GW_AUTHENTICATION;
|
||||||
|
break;
|
||||||
|
case SCP_SESSION_TYPE_MANAGE:
|
||||||
|
s->type = SCP_SESSION_TYPE_MANAGE;
|
||||||
|
s->mng = (struct SCP_MNG_DATA *)g_malloc(sizeof(struct SCP_MNG_DATA), 1);
|
||||||
|
|
||||||
|
if (NULL == s->mng)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_ERROR, "[session:%d] set_type: internal error", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_type: unknown type", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
s = (struct SCP_SESSION*)g_malloc(sizeof(struct SCP_SESSION), 1);
|
|
||||||
if (0 == s)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] session create: malloc error", __LINE__);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_type(struct SCP_SESSION* s, tui8 type)
|
scp_session_set_version(struct SCP_SESSION *s, tui32 version)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (version)
|
||||||
{
|
{
|
||||||
case SCP_SESSION_TYPE_XVNC:
|
case 0:
|
||||||
s->type = SCP_SESSION_TYPE_XVNC;
|
s->version = 0;
|
||||||
break;
|
break;
|
||||||
case SCP_SESSION_TYPE_XRDP:
|
case 1:
|
||||||
s->type = SCP_SESSION_TYPE_XRDP;
|
s->version = 1;
|
||||||
break;
|
break;
|
||||||
case SCP_GW_AUTHENTICATION:
|
default:
|
||||||
s->type = SCP_GW_AUTHENTICATION;
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_version: unknown version", __LINE__);
|
||||||
break;
|
return 1;
|
||||||
case SCP_SESSION_TYPE_MANAGE:
|
}
|
||||||
s->type = SCP_SESSION_TYPE_MANAGE;
|
|
||||||
s->mng = (struct SCP_MNG_DATA*)g_malloc(sizeof(struct SCP_MNG_DATA), 1);
|
return 0;
|
||||||
if (NULL == s->mng)
|
}
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_ERROR, "[session:%d] set_type: internal error", __LINE__);
|
/*******************************************************************/
|
||||||
|
int
|
||||||
|
scp_session_set_height(struct SCP_SESSION *s, tui16 h)
|
||||||
|
{
|
||||||
|
s->height = h;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
int
|
||||||
|
scp_session_set_width(struct SCP_SESSION *s, tui16 w)
|
||||||
|
{
|
||||||
|
s->width = w;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
int
|
||||||
|
scp_session_set_bpp(struct SCP_SESSION *s, tui8 bpp)
|
||||||
|
{
|
||||||
|
switch (bpp)
|
||||||
|
{
|
||||||
|
case 8:
|
||||||
|
case 15:
|
||||||
|
case 16:
|
||||||
|
case 24:
|
||||||
|
s->bpp = bpp;
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
int
|
||||||
|
scp_session_set_rsr(struct SCP_SESSION *s, tui8 rsr)
|
||||||
|
{
|
||||||
|
if (s->rsr)
|
||||||
|
{
|
||||||
|
s->rsr = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s->rsr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************/
|
||||||
|
int
|
||||||
|
scp_session_set_locale(struct SCP_SESSION *s, char *str)
|
||||||
|
{
|
||||||
|
if (0 == str)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_locale: null locale", __LINE__);
|
||||||
|
s->locale[0] = '\0';
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
g_strncpy(s->locale, str, 17);
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_type: unknown type", __LINE__);
|
s->locale[17] = '\0';
|
||||||
return 1;
|
return 0;
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_version(struct SCP_SESSION* s, tui32 version)
|
scp_session_set_username(struct SCP_SESSION *s, char *str)
|
||||||
{
|
{
|
||||||
switch (version)
|
if (0 == str)
|
||||||
{
|
{
|
||||||
case 0:
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_username: null username", __LINE__);
|
||||||
s->version = 0;
|
return 1;
|
||||||
break;
|
}
|
||||||
case 1:
|
|
||||||
s->version = 1;
|
if (0 != s->username)
|
||||||
break;
|
{
|
||||||
default:
|
g_free(s->username);
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_version: unknown version", __LINE__);
|
}
|
||||||
return 1;
|
|
||||||
}
|
s->username = g_strdup(str);
|
||||||
return 0;
|
|
||||||
|
if (0 == s->username)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_username: strdup error", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_height(struct SCP_SESSION* s, tui16 h)
|
scp_session_set_password(struct SCP_SESSION *s, char *str)
|
||||||
{
|
{
|
||||||
s->height = h;
|
if (0 == str)
|
||||||
return 0;
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_password: null password", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != s->password)
|
||||||
|
{
|
||||||
|
g_free(s->password);
|
||||||
|
}
|
||||||
|
|
||||||
|
s->password = g_strdup(str);
|
||||||
|
|
||||||
|
if (0 == s->password)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_password: strdup error", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_width(struct SCP_SESSION* s, tui16 w)
|
scp_session_set_domain(struct SCP_SESSION *s, char *str)
|
||||||
{
|
{
|
||||||
s->width = w;
|
if (0 == str)
|
||||||
return 0;
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_domain: null domain", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != s->domain)
|
||||||
|
{
|
||||||
|
g_free(s->domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
s->domain = g_strdup(str);
|
||||||
|
|
||||||
|
if (0 == s->domain)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_domain: strdup error", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_bpp(struct SCP_SESSION* s, tui8 bpp)
|
scp_session_set_program(struct SCP_SESSION *s, char *str)
|
||||||
{
|
{
|
||||||
switch (bpp)
|
if (0 == str)
|
||||||
{
|
{
|
||||||
case 8:
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_program: null program", __LINE__);
|
||||||
case 15:
|
return 1;
|
||||||
case 16:
|
}
|
||||||
case 24:
|
|
||||||
s->bpp = bpp;
|
if (0 != s->program)
|
||||||
default:
|
{
|
||||||
return 1;
|
g_free(s->program);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
s->program = g_strdup(str);
|
||||||
|
|
||||||
|
if (0 == s->program)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_program: strdup error", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_rsr(struct SCP_SESSION* s, tui8 rsr)
|
scp_session_set_directory(struct SCP_SESSION *s, char *str)
|
||||||
{
|
{
|
||||||
if (s->rsr)
|
if (0 == str)
|
||||||
{
|
{
|
||||||
s->rsr = 1;
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_directory: null directory", __LINE__);
|
||||||
}
|
return 1;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
s->rsr = 0;
|
if (0 != s->directory)
|
||||||
}
|
{
|
||||||
return 0;
|
g_free(s->directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
s->directory = g_strdup(str);
|
||||||
|
|
||||||
|
if (0 == s->directory)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_directory: strdup error", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_locale(struct SCP_SESSION* s, char* str)
|
scp_session_set_client_ip(struct SCP_SESSION *s, char *str)
|
||||||
{
|
{
|
||||||
if (0 == str)
|
if (0 == str)
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_locale: null locale", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_client_ip: null ip", __LINE__);
|
||||||
s->locale[0]='\0';
|
return 1;
|
||||||
return 1;
|
}
|
||||||
}
|
|
||||||
g_strncpy(s->locale, str, 17);
|
if (0 != s->client_ip)
|
||||||
s->locale[17]='\0';
|
{
|
||||||
return 0;
|
g_free(s->client_ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
s->client_ip = g_strdup(str);
|
||||||
|
|
||||||
|
if (0 == s->client_ip)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_client_ip: strdup error", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_username(struct SCP_SESSION* s, char* str)
|
scp_session_set_hostname(struct SCP_SESSION *s, char *str)
|
||||||
{
|
{
|
||||||
if (0 == str)
|
if (0 == str)
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_username: null username", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_hostname: null hostname", __LINE__);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (0 != s->username)
|
|
||||||
{
|
if (0 != s->hostname)
|
||||||
g_free(s->username);
|
{
|
||||||
}
|
g_free(s->hostname);
|
||||||
s->username = g_strdup(str);
|
}
|
||||||
if (0 == s->username)
|
|
||||||
{
|
s->hostname = g_strdup(str);
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_username: strdup error", __LINE__);
|
|
||||||
return 1;
|
if (0 == s->hostname)
|
||||||
}
|
{
|
||||||
return 0;
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_hostname: strdup error", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_password(struct SCP_SESSION* s, char* str)
|
scp_session_set_errstr(struct SCP_SESSION *s, char *str)
|
||||||
{
|
{
|
||||||
if (0 == str)
|
if (0 == str)
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_password: null password", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_errstr: null string", __LINE__);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (0 != s->password)
|
|
||||||
{
|
if (0 != s->errstr)
|
||||||
g_free(s->password);
|
{
|
||||||
}
|
g_free(s->errstr);
|
||||||
s->password = g_strdup(str);
|
}
|
||||||
if (0 == s->password)
|
|
||||||
{
|
s->errstr = g_strdup(str);
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_password: strdup error", __LINE__);
|
|
||||||
return 1;
|
if (0 == s->errstr)
|
||||||
}
|
{
|
||||||
return 0;
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_errstr: strdup error", __LINE__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_domain(struct SCP_SESSION* s, char* str)
|
scp_session_set_display(struct SCP_SESSION *s, SCP_DISPLAY display)
|
||||||
{
|
{
|
||||||
if (0 == str)
|
s->display = display;
|
||||||
{
|
return 0;
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_domain: null domain", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (0 != s->domain)
|
|
||||||
{
|
|
||||||
g_free(s->domain);
|
|
||||||
}
|
|
||||||
s->domain = g_strdup(str);
|
|
||||||
if (0 == s->domain)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_domain: strdup error", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
int
|
int
|
||||||
scp_session_set_program(struct SCP_SESSION* s, char* str)
|
scp_session_set_addr(struct SCP_SESSION *s, int type, void *addr)
|
||||||
{
|
{
|
||||||
if (0 == str)
|
struct in_addr ip4;
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_program: null program", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (0 != s->program)
|
|
||||||
{
|
|
||||||
g_free(s->program);
|
|
||||||
}
|
|
||||||
s->program = g_strdup(str);
|
|
||||||
if (0 == s->program)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_program: strdup error", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************/
|
|
||||||
int
|
|
||||||
scp_session_set_directory(struct SCP_SESSION* s, char* str)
|
|
||||||
{
|
|
||||||
if (0 == str)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_directory: null directory", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (0 != s->directory)
|
|
||||||
{
|
|
||||||
g_free(s->directory);
|
|
||||||
}
|
|
||||||
s->directory = g_strdup(str);
|
|
||||||
if (0 == s->directory)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_directory: strdup error", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************/
|
|
||||||
int
|
|
||||||
scp_session_set_client_ip(struct SCP_SESSION* s, char* str)
|
|
||||||
{
|
|
||||||
if (0 == str)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_client_ip: null ip", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (0 != s->client_ip)
|
|
||||||
{
|
|
||||||
g_free(s->client_ip);
|
|
||||||
}
|
|
||||||
s->client_ip = g_strdup(str);
|
|
||||||
if (0 == s->client_ip)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_client_ip: strdup error", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************/
|
|
||||||
int
|
|
||||||
scp_session_set_hostname(struct SCP_SESSION* s, char* str)
|
|
||||||
{
|
|
||||||
if (0 == str)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_hostname: null hostname", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (0 != s->hostname)
|
|
||||||
{
|
|
||||||
g_free(s->hostname);
|
|
||||||
}
|
|
||||||
s->hostname = g_strdup(str);
|
|
||||||
if (0 == s->hostname)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_hostname: strdup error", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************/
|
|
||||||
int
|
|
||||||
scp_session_set_errstr(struct SCP_SESSION* s, char* str)
|
|
||||||
{
|
|
||||||
if (0 == str)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_errstr: null string", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (0 != s->errstr)
|
|
||||||
{
|
|
||||||
g_free(s->errstr);
|
|
||||||
}
|
|
||||||
s->errstr = g_strdup(str);
|
|
||||||
if (0 == s->errstr)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_errstr: strdup error", __LINE__);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************/
|
|
||||||
int
|
|
||||||
scp_session_set_display(struct SCP_SESSION* s, SCP_DISPLAY display)
|
|
||||||
{
|
|
||||||
s->display = display;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************/
|
|
||||||
int
|
|
||||||
scp_session_set_addr(struct SCP_SESSION* s, int type, void* addr)
|
|
||||||
{
|
|
||||||
struct in_addr ip4;
|
|
||||||
#ifdef IN6ADDR_ANY_INIT
|
#ifdef IN6ADDR_ANY_INIT
|
||||||
struct in6_addr ip6;
|
struct in6_addr ip6;
|
||||||
#endif
|
#endif
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case SCP_ADDRESS_TYPE_IPV4:
|
case SCP_ADDRESS_TYPE_IPV4:
|
||||||
/* convert from char to 32bit*/
|
/* convert from char to 32bit*/
|
||||||
ret = inet_pton(AF_INET, addr, &ip4);
|
ret = inet_pton(AF_INET, addr, &ip4);
|
||||||
if (ret == 0)
|
|
||||||
{
|
if (ret == 0)
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__);
|
{
|
||||||
inet_pton(AF_INET, "127.0.0.1", &ip4);
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__);
|
||||||
g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4);
|
inet_pton(AF_INET, "127.0.0.1", &ip4);
|
||||||
return 1;
|
g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4);
|
||||||
}
|
return 1;
|
||||||
g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4);
|
}
|
||||||
break;
|
|
||||||
case SCP_ADDRESS_TYPE_IPV4_BIN:
|
g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4);
|
||||||
g_memcpy(&(s->ipv4addr), addr, 4);
|
break;
|
||||||
break;
|
case SCP_ADDRESS_TYPE_IPV4_BIN:
|
||||||
|
g_memcpy(&(s->ipv4addr), addr, 4);
|
||||||
|
break;
|
||||||
#ifdef IN6ADDR_ANY_INIT
|
#ifdef IN6ADDR_ANY_INIT
|
||||||
case SCP_ADDRESS_TYPE_IPV6:
|
case SCP_ADDRESS_TYPE_IPV6:
|
||||||
/* convert from char to 128bit*/
|
/* convert from char to 128bit*/
|
||||||
ret = inet_pton(AF_INET6, addr, &ip6);
|
ret = inet_pton(AF_INET6, addr, &ip6);
|
||||||
if (ret == 0)
|
|
||||||
{
|
if (ret == 0)
|
||||||
log_message(LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__);
|
{
|
||||||
inet_pton(AF_INET, "::1", &ip6);
|
log_message(LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__);
|
||||||
g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16);
|
inet_pton(AF_INET, "::1", &ip6);
|
||||||
return 1;
|
g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16);
|
||||||
}
|
return 1;
|
||||||
g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16);
|
}
|
||||||
break;
|
|
||||||
case SCP_ADDRESS_TYPE_IPV6_BIN:
|
g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16);
|
||||||
g_memcpy(s->ipv6addr, addr, 16);
|
break;
|
||||||
break;
|
case SCP_ADDRESS_TYPE_IPV6_BIN:
|
||||||
|
g_memcpy(s->ipv6addr, addr, 16);
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
void
|
void
|
||||||
scp_session_destroy(struct SCP_SESSION* s)
|
scp_session_destroy(struct SCP_SESSION *s)
|
||||||
{
|
{
|
||||||
g_free(s->username);
|
g_free(s->username);
|
||||||
g_free(s->password);
|
g_free(s->password);
|
||||||
g_free(s->hostname);
|
g_free(s->hostname);
|
||||||
g_free(s->domain);
|
g_free(s->domain);
|
||||||
g_free(s->program);
|
g_free(s->program);
|
||||||
g_free(s->directory);
|
g_free(s->directory);
|
||||||
g_free(s->client_ip);
|
g_free(s->client_ip);
|
||||||
g_free(s->errstr);
|
g_free(s->errstr);
|
||||||
g_free(s->mng);
|
g_free(s->mng);
|
||||||
g_free(s);
|
g_free(s);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
+91
-91
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -33,102 +32,103 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
extern struct log_config* s_log;
|
extern struct log_config *s_log;
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
scp_tcp_force_recv(int sck, char* data, int len)
|
scp_tcp_force_recv(int sck, char *data, int len)
|
||||||
{
|
{
|
||||||
int rcvd;
|
int rcvd;
|
||||||
int block;
|
int block;
|
||||||
|
|
||||||
LOG_DBG("scp_tcp_force_recv()");
|
LOG_DBG("scp_tcp_force_recv()");
|
||||||
block = scp_lock_fork_critical_section_start();
|
block = scp_lock_fork_critical_section_start();
|
||||||
|
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
{
|
|
||||||
rcvd = g_tcp_recv(sck, data, len, 0);
|
|
||||||
if (rcvd == -1)
|
|
||||||
{
|
{
|
||||||
if (g_tcp_last_error_would_block(sck))
|
rcvd = g_tcp_recv(sck, data, len, 0);
|
||||||
{
|
|
||||||
g_sleep(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
scp_lock_fork_critical_section_end(block);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (rcvd == 0)
|
|
||||||
{
|
|
||||||
scp_lock_fork_critical_section_end(block);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data += rcvd;
|
|
||||||
len -= rcvd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scp_lock_fork_critical_section_end(block);
|
if (rcvd == -1)
|
||||||
|
{
|
||||||
|
if (g_tcp_last_error_would_block(sck))
|
||||||
|
{
|
||||||
|
g_sleep(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scp_lock_fork_critical_section_end(block);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (rcvd == 0)
|
||||||
|
{
|
||||||
|
scp_lock_fork_critical_section_end(block);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data += rcvd;
|
||||||
|
len -= rcvd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
scp_lock_fork_critical_section_end(block);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
scp_tcp_force_send(int sck, char* data, int len)
|
scp_tcp_force_send(int sck, char *data, int len)
|
||||||
{
|
{
|
||||||
int sent;
|
int sent;
|
||||||
int block;
|
int block;
|
||||||
|
|
||||||
LOG_DBG("scp_tcp_force_send()");
|
LOG_DBG("scp_tcp_force_send()");
|
||||||
block = scp_lock_fork_critical_section_start();
|
block = scp_lock_fork_critical_section_start();
|
||||||
|
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
{
|
|
||||||
sent = g_tcp_send(sck, data, len, 0);
|
|
||||||
if (sent == -1)
|
|
||||||
{
|
{
|
||||||
if (g_tcp_last_error_would_block(sck))
|
sent = g_tcp_send(sck, data, len, 0);
|
||||||
{
|
|
||||||
g_sleep(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
scp_lock_fork_critical_section_end(block);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (sent == 0)
|
|
||||||
{
|
|
||||||
scp_lock_fork_critical_section_end(block);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data += sent;
|
|
||||||
len -= sent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scp_lock_fork_critical_section_end(block);
|
if (sent == -1)
|
||||||
|
{
|
||||||
|
if (g_tcp_last_error_would_block(sck))
|
||||||
|
{
|
||||||
|
g_sleep(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scp_lock_fork_critical_section_end(block);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sent == 0)
|
||||||
|
{
|
||||||
|
scp_lock_fork_critical_section_end(block);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data += sent;
|
||||||
|
len -= sent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
scp_lock_fork_critical_section_end(block);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
scp_tcp_bind(int sck, char* addr, char* port)
|
scp_tcp_bind(int sck, char *addr, char *port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in s;
|
struct sockaddr_in s;
|
||||||
|
|
||||||
memset(&s, 0, sizeof(struct sockaddr_in));
|
memset(&s, 0, sizeof(struct sockaddr_in));
|
||||||
s.sin_family = AF_INET;
|
s.sin_family = AF_INET;
|
||||||
s.sin_port = htons(atoi(port));
|
s.sin_port = htons(atoi(port));
|
||||||
s.sin_addr.s_addr = inet_addr(addr);
|
s.sin_addr.s_addr = inet_addr(addr);
|
||||||
return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
|
return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_in));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-18
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
+345
-321
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -29,361 +28,386 @@
|
|||||||
|
|
||||||
#include "os_calls.h"
|
#include "os_calls.h"
|
||||||
|
|
||||||
extern struct log_config* s_log;
|
extern struct log_config *s_log;
|
||||||
|
|
||||||
/* client API */
|
/* client API */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v0c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
scp_v0c_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
|
||||||
{
|
{
|
||||||
tui32 version;
|
tui32 version;
|
||||||
tui32 size;
|
tui32 size;
|
||||||
tui16 sz;
|
tui16 sz;
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
init_stream(c->in_s, c->in_s->size);
|
||||||
init_stream(c->out_s, c->in_s->size);
|
init_stream(c->out_s, c->in_s->size);
|
||||||
|
|
||||||
LOG_DBG("[v0:%d] starting connection", __LINE__);
|
LOG_DBG("[v0:%d] starting connection", __LINE__);
|
||||||
g_tcp_set_non_blocking(c->in_sck);
|
g_tcp_set_non_blocking(c->in_sck);
|
||||||
g_tcp_set_no_delay(c->in_sck);
|
g_tcp_set_no_delay(c->in_sck);
|
||||||
s_push_layer(c->out_s, channel_hdr, 8);
|
s_push_layer(c->out_s, channel_hdr, 8);
|
||||||
|
|
||||||
/* code */
|
/* code */
|
||||||
if (s->type == SCP_SESSION_TYPE_XVNC)
|
if (s->type == SCP_SESSION_TYPE_XVNC)
|
||||||
{
|
{
|
||||||
out_uint16_be(c->out_s, 0);
|
out_uint16_be(c->out_s, 0);
|
||||||
}
|
}
|
||||||
else if (s->type == SCP_SESSION_TYPE_XRDP)
|
else if (s->type == SCP_SESSION_TYPE_XRDP)
|
||||||
{
|
{
|
||||||
out_uint16_be(c->out_s, 10);
|
out_uint16_be(c->out_s, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
||||||
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
||||||
}
|
}
|
||||||
sz = g_strlen(s->username);
|
|
||||||
out_uint16_be(c->out_s, sz);
|
|
||||||
out_uint8a(c->out_s, s->username, sz);
|
|
||||||
|
|
||||||
sz = g_strlen(s->password);
|
sz = g_strlen(s->username);
|
||||||
out_uint16_be(c->out_s,sz);
|
out_uint16_be(c->out_s, sz);
|
||||||
out_uint8a(c->out_s, s->password, sz);
|
out_uint8a(c->out_s, s->username, sz);
|
||||||
out_uint16_be(c->out_s, s->width);
|
|
||||||
out_uint16_be(c->out_s, s->height);
|
|
||||||
out_uint16_be(c->out_s, s->bpp);
|
|
||||||
|
|
||||||
s_mark_end(c->out_s);
|
sz = g_strlen(s->password);
|
||||||
s_pop_layer(c->out_s, channel_hdr);
|
out_uint16_be(c->out_s, sz);
|
||||||
|
out_uint8a(c->out_s, s->password, sz);
|
||||||
|
out_uint16_be(c->out_s, s->width);
|
||||||
|
out_uint16_be(c->out_s, s->height);
|
||||||
|
out_uint16_be(c->out_s, s->bpp);
|
||||||
|
|
||||||
/* version */
|
s_mark_end(c->out_s);
|
||||||
out_uint32_be(c->out_s, 0);
|
s_pop_layer(c->out_s, channel_hdr);
|
||||||
/* size */
|
|
||||||
out_uint32_be(c->out_s, c->out_s->end - c->out_s->data);
|
|
||||||
|
|
||||||
if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
|
/* version */
|
||||||
{
|
out_uint32_be(c->out_s, 0);
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
/* size */
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
out_uint32_be(c->out_s, c->out_s->end - c->out_s->data);
|
||||||
}
|
|
||||||
|
|
||||||
if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_uint32_be(c->in_s, version);
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
||||||
if (0 != version)
|
{
|
||||||
{
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__);
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
return SCP_CLIENT_STATE_VERSION_ERR;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, size);
|
in_uint32_be(c->in_s, version);
|
||||||
if (size < 14)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: packet size error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_SIZE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* getting payload */
|
if (0 != version)
|
||||||
init_stream(c->in_s, c->in_s->size);
|
{
|
||||||
if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__);
|
||||||
{
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
}
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check code */
|
in_uint32_be(c->in_s, size);
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
if (3 != sz)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* message payload */
|
if (size < 14)
|
||||||
in_uint16_be(c->in_s, sz);
|
{
|
||||||
if (1 != sz)
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: packet size error", __LINE__);
|
||||||
{
|
return SCP_CLIENT_STATE_SIZE_ERR;
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: connection denied", __LINE__);
|
}
|
||||||
return SCP_CLIENT_STATE_CONNECTION_DENIED;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, sz);
|
/* getting payload */
|
||||||
s->display = sz;
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
LOG_DBG("[v0:%d] connection terminated", __LINE__);
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
||||||
return SCP_CLIENT_STATE_END;
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check code */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
|
||||||
|
if (3 != sz)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* message payload */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
|
||||||
|
if (1 != sz)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: connection denied", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_CONNECTION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
s->display = sz;
|
||||||
|
|
||||||
|
LOG_DBG("[v0:%d] connection terminated", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* server API */
|
/* server API */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
enum SCP_SERVER_STATES_E
|
enum SCP_SERVER_STATES_E
|
||||||
scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk)
|
scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk)
|
||||||
{
|
{
|
||||||
tui32 version = 0;
|
tui32 version = 0;
|
||||||
tui32 size;
|
tui32 size;
|
||||||
struct SCP_SESSION* session = 0;
|
struct SCP_SESSION *session = 0;
|
||||||
tui16 sz;
|
tui16 sz;
|
||||||
tui32 code = 0;
|
tui32 code = 0;
|
||||||
char buf[257];
|
char buf[257];
|
||||||
|
|
||||||
if (!skipVchk)
|
if (!skipVchk)
|
||||||
{
|
|
||||||
LOG_DBG("[v0:%d] starting connection", __LINE__);
|
|
||||||
if (0 == scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
|
||||||
{
|
{
|
||||||
c->in_s->end = c->in_s->data + 8;
|
LOG_DBG("[v0:%d] starting connection", __LINE__);
|
||||||
in_uint32_be(c->in_s, version);
|
|
||||||
if (version != 0)
|
if (0 == scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__);
|
c->in_s->end = c->in_s->data + 8;
|
||||||
return SCP_SERVER_STATE_VERSION_ERR;
|
in_uint32_be(c->in_s, version);
|
||||||
}
|
|
||||||
|
if (version != 0)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_VERSION_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint32_be(c->in_s, size);
|
||||||
|
|
||||||
|
init_stream(c->in_s, 8196);
|
||||||
|
|
||||||
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
c->in_s->end = c->in_s->data + (size - 8);
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, code);
|
||||||
|
|
||||||
|
if (code == 0 || code == 10)
|
||||||
|
{
|
||||||
|
session = scp_session_create();
|
||||||
|
|
||||||
|
if (0 == session)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
scp_session_set_version(session, version);
|
||||||
|
|
||||||
|
if (code == 0)
|
||||||
|
{
|
||||||
|
scp_session_set_type(session, SCP_SESSION_TYPE_XVNC);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scp_session_set_type(session, SCP_SESSION_TYPE_XRDP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reading username */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
|
||||||
|
if (0 != scp_session_set_username(session, buf))
|
||||||
|
{
|
||||||
|
scp_session_destroy(session);
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reading password */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
|
||||||
|
if (0 != scp_session_set_password(session, buf))
|
||||||
|
{
|
||||||
|
scp_session_destroy(session);
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* width */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
scp_session_set_width(session, sz);
|
||||||
|
/* height */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
scp_session_set_height(session, sz);
|
||||||
|
/* bpp */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
scp_session_set_bpp(session, (tui8)sz);
|
||||||
|
|
||||||
|
if (s_check_rem(c->in_s, 2))
|
||||||
|
{
|
||||||
|
/* reading domain */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
|
||||||
|
if (sz > 0)
|
||||||
|
{
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
scp_session_set_domain(session, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_check_rem(c->in_s, 2))
|
||||||
|
{
|
||||||
|
/* reading program */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
|
||||||
|
if (sz > 0)
|
||||||
|
{
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
scp_session_set_program(session, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_check_rem(c->in_s, 2))
|
||||||
|
{
|
||||||
|
/* reading directory */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
|
||||||
|
if (sz > 0)
|
||||||
|
{
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
scp_session_set_directory(session, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_check_rem(c->in_s, 2))
|
||||||
|
{
|
||||||
|
/* reading client IP address */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
|
||||||
|
if (sz > 0)
|
||||||
|
{
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
scp_session_set_client_ip(session, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (code == SCP_GW_AUTHENTICATION)
|
||||||
|
{
|
||||||
|
/* g_writeln("Command is SCP_GW_AUTHENTICATION"); */
|
||||||
|
session = scp_session_create();
|
||||||
|
|
||||||
|
if (0 == session)
|
||||||
|
{
|
||||||
|
/* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);*/
|
||||||
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
scp_session_set_version(session, version);
|
||||||
|
scp_session_set_type(session, SCP_GW_AUTHENTICATION);
|
||||||
|
/* reading username */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
|
||||||
|
/* g_writeln("Received user name: %s",buf); */
|
||||||
|
if (0 != scp_session_set_username(session, buf))
|
||||||
|
{
|
||||||
|
scp_session_destroy(session);
|
||||||
|
/* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__);*/
|
||||||
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reading password */
|
||||||
|
in_uint16_be(c->in_s, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
|
||||||
|
/* g_writeln("Received password: %s",buf); */
|
||||||
|
if (0 != scp_session_set_password(session, buf))
|
||||||
|
{
|
||||||
|
scp_session_destroy(session);
|
||||||
|
/* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__); */
|
||||||
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__);
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
return SCP_SERVER_STATE_SEQUENCE_ERR;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, size);
|
|
||||||
|
|
||||||
init_stream(c->in_s, 8196);
|
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
c->in_s->end = c->in_s->data + (size - 8);
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, code);
|
|
||||||
|
|
||||||
if (code == 0 || code == 10)
|
|
||||||
{
|
|
||||||
session = scp_session_create();
|
|
||||||
if (0 == session)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scp_session_set_version(session, version);
|
(*s) = session;
|
||||||
if (code == 0)
|
return SCP_SERVER_STATE_OK;
|
||||||
{
|
|
||||||
scp_session_set_type(session, SCP_SESSION_TYPE_XVNC);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
scp_session_set_type(session, SCP_SESSION_TYPE_XRDP);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reading username */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
buf[sz]='\0';
|
|
||||||
in_uint8a(c->in_s, buf, sz);
|
|
||||||
if (0 != scp_session_set_username(session, buf))
|
|
||||||
{
|
|
||||||
scp_session_destroy(session);
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reading password */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
buf[sz]='\0';
|
|
||||||
in_uint8a(c->in_s, buf, sz);
|
|
||||||
if (0 != scp_session_set_password(session, buf))
|
|
||||||
{
|
|
||||||
scp_session_destroy(session);
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* width */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
scp_session_set_width(session, sz);
|
|
||||||
/* height */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
scp_session_set_height(session, sz);
|
|
||||||
/* bpp */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
scp_session_set_bpp(session, (tui8)sz);
|
|
||||||
if (s_check_rem(c->in_s, 2))
|
|
||||||
{
|
|
||||||
/* reading domain */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
if (sz > 0)
|
|
||||||
{
|
|
||||||
in_uint8a(c->in_s, buf, sz);
|
|
||||||
buf[sz] = '\0';
|
|
||||||
scp_session_set_domain(session, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (s_check_rem(c->in_s, 2))
|
|
||||||
{
|
|
||||||
/* reading program */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
if (sz > 0)
|
|
||||||
{
|
|
||||||
in_uint8a(c->in_s, buf, sz);
|
|
||||||
buf[sz] = '\0';
|
|
||||||
scp_session_set_program(session, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (s_check_rem(c->in_s, 2))
|
|
||||||
{
|
|
||||||
/* reading directory */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
if (sz > 0)
|
|
||||||
{
|
|
||||||
in_uint8a(c->in_s, buf, sz);
|
|
||||||
buf[sz] = '\0';
|
|
||||||
scp_session_set_directory(session, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (s_check_rem(c->in_s, 2))
|
|
||||||
{
|
|
||||||
/* reading client IP address */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
if (sz > 0)
|
|
||||||
{
|
|
||||||
in_uint8a(c->in_s, buf, sz);
|
|
||||||
buf[sz] = '\0';
|
|
||||||
scp_session_set_client_ip(session, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (code == SCP_GW_AUTHENTICATION)
|
|
||||||
{
|
|
||||||
/* g_writeln("Command is SCP_GW_AUTHENTICATION"); */
|
|
||||||
session = scp_session_create();
|
|
||||||
if (0 == session)
|
|
||||||
{
|
|
||||||
/* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);*/
|
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
scp_session_set_version(session, version);
|
|
||||||
scp_session_set_type(session, SCP_GW_AUTHENTICATION);
|
|
||||||
/* reading username */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
buf[sz]='\0';
|
|
||||||
in_uint8a(c->in_s, buf, sz);
|
|
||||||
/* g_writeln("Received user name: %s",buf); */
|
|
||||||
if (0 != scp_session_set_username(session, buf))
|
|
||||||
{
|
|
||||||
scp_session_destroy(session);
|
|
||||||
/* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__);*/
|
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reading password */
|
|
||||||
in_uint16_be(c->in_s, sz);
|
|
||||||
buf[sz] = '\0';
|
|
||||||
in_uint8a(c->in_s, buf, sz);
|
|
||||||
/* g_writeln("Received password: %s",buf); */
|
|
||||||
if (0 != scp_session_set_password(session, buf))
|
|
||||||
{
|
|
||||||
scp_session_destroy(session);
|
|
||||||
/* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__); */
|
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*s)=session;
|
|
||||||
return SCP_SERVER_STATE_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
enum SCP_SERVER_STATES_E
|
enum SCP_SERVER_STATES_E
|
||||||
scp_v0s_allow_connection(struct SCP_CONNECTION* c, SCP_DISPLAY d)
|
scp_v0s_allow_connection(struct SCP_CONNECTION *c, SCP_DISPLAY d)
|
||||||
{
|
{
|
||||||
out_uint32_be(c->out_s, 0); /* version */
|
out_uint32_be(c->out_s, 0); /* version */
|
||||||
out_uint32_be(c->out_s, 14); /* size */
|
out_uint32_be(c->out_s, 14); /* size */
|
||||||
out_uint16_be(c->out_s, 3); /* cmd */
|
out_uint16_be(c->out_s, 3); /* cmd */
|
||||||
out_uint16_be(c->out_s, 1); /* data */
|
out_uint16_be(c->out_s, 1); /* data */
|
||||||
out_uint16_be(c->out_s, d); /* data */
|
out_uint16_be(c->out_s, d); /* data */
|
||||||
s_mark_end(c->out_s);
|
s_mark_end(c->out_s);
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DBG("[v0:%d] connection terminated (allowed)", __LINE__);
|
LOG_DBG("[v0:%d] connection terminated (allowed)", __LINE__);
|
||||||
return SCP_SERVER_STATE_OK;
|
return SCP_SERVER_STATE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
enum SCP_SERVER_STATES_E
|
enum SCP_SERVER_STATES_E
|
||||||
scp_v0s_deny_connection(struct SCP_CONNECTION* c)
|
scp_v0s_deny_connection(struct SCP_CONNECTION *c)
|
||||||
{
|
{
|
||||||
out_uint32_be(c->out_s, 0); /* version */
|
out_uint32_be(c->out_s, 0); /* version */
|
||||||
out_uint32_be(c->out_s, 14); /* size */
|
out_uint32_be(c->out_s, 14); /* size */
|
||||||
out_uint16_be(c->out_s, 3); /* cmd */
|
out_uint16_be(c->out_s, 3); /* cmd */
|
||||||
out_uint16_be(c->out_s, 0); /* data = 0 - means NOT ok*/
|
out_uint16_be(c->out_s, 0); /* data = 0 - means NOT ok*/
|
||||||
out_uint16_be(c->out_s, 0); /* reserved for display number*/
|
out_uint16_be(c->out_s, 0); /* reserved for display number*/
|
||||||
s_mark_end(c->out_s);
|
s_mark_end(c->out_s);
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DBG("[v0:%d] connection terminated (denied)", __LINE__);
|
LOG_DBG("[v0:%d] connection terminated (denied)", __LINE__);
|
||||||
return SCP_SERVER_STATE_OK;
|
return SCP_SERVER_STATE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
enum SCP_SERVER_STATES_E
|
enum SCP_SERVER_STATES_E
|
||||||
scp_v0s_replyauthentication(struct SCP_CONNECTION* c, unsigned short int value)
|
scp_v0s_replyauthentication(struct SCP_CONNECTION *c, unsigned short int value)
|
||||||
{
|
{
|
||||||
out_uint32_be(c->out_s, 0); /* version */
|
out_uint32_be(c->out_s, 0); /* version */
|
||||||
out_uint32_be(c->out_s, 14); /* size */
|
out_uint32_be(c->out_s, 14); /* size */
|
||||||
/* cmd SCP_GW_AUTHENTICATION means authentication reply */
|
/* cmd SCP_GW_AUTHENTICATION means authentication reply */
|
||||||
out_uint16_be(c->out_s, SCP_GW_AUTHENTICATION);
|
out_uint16_be(c->out_s, SCP_GW_AUTHENTICATION);
|
||||||
out_uint16_be(c->out_s, value); /* reply code */
|
out_uint16_be(c->out_s, value); /* reply code */
|
||||||
out_uint16_be(c->out_s, 0); /* dummy data */
|
out_uint16_be(c->out_s, 0); /* dummy data */
|
||||||
s_mark_end(c->out_s);
|
s_mark_end(c->out_s);
|
||||||
|
|
||||||
/* g_writeln("Total number of bytes that will be sent %d",c->out_s->end - c->out_s->data);*/
|
/* g_writeln("Total number of bytes that will be sent %d",c->out_s->end - c->out_s->data);*/
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
|
||||||
{
|
{
|
||||||
/* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); */
|
/* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); */
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* until syslog merge LOG_DBG(s_log, "[v0:%d] connection terminated (scp_v0s_deny_authentication)", __LINE__);*/
|
/* until syslog merge LOG_DBG(s_log, "[v0:%d] connection terminated (scp_v0s_deny_authentication)", __LINE__);*/
|
||||||
return SCP_SERVER_STATE_OK;
|
return SCP_SERVER_STATE_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-19
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -83,4 +82,3 @@ enum SCP_SERVER_STATES_E
|
|||||||
scp_v0s_replyauthentication(struct SCP_CONNECTION* c, unsigned short int value);
|
scp_v0s_replyauthentication(struct SCP_CONNECTION* c, unsigned short int value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+408
-375
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -31,443 +30,477 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static enum SCP_CLIENT_STATES_E
|
static enum SCP_CLIENT_STATES_E
|
||||||
_scp_v1c_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s);
|
_scp_v1c_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s);
|
||||||
|
|
||||||
/* client API */
|
/* client API */
|
||||||
/* 001 */
|
/* 001 */
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v1c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
scp_v1c_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
|
||||||
{
|
{
|
||||||
tui8 sz;
|
tui8 sz;
|
||||||
tui32 size;
|
tui32 size;
|
||||||
|
|
||||||
init_stream(c->out_s, c->out_s->size);
|
init_stream(c->out_s, c->out_s->size);
|
||||||
init_stream(c->in_s, c->in_s->size);
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
size = 19 + 17 + 4 + g_strlen(s->hostname) + g_strlen(s->username) +
|
size = 19 + 17 + 4 + g_strlen(s->hostname) + g_strlen(s->username) +
|
||||||
g_strlen(s->password);
|
g_strlen(s->password);
|
||||||
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
|
||||||
{
|
|
||||||
size = size + 4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size = size + 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sending request */
|
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
||||||
|
{
|
||||||
|
size = size + 4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = size + 16;
|
||||||
|
}
|
||||||
|
|
||||||
/* header */
|
/* sending request */
|
||||||
out_uint32_be(c->out_s, 1); /* version */
|
|
||||||
out_uint32_be(c->out_s, size);
|
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
|
|
||||||
out_uint16_be(c->out_s, 1);
|
|
||||||
|
|
||||||
/* body */
|
/* header */
|
||||||
out_uint8(c->out_s, s->type);
|
out_uint32_be(c->out_s, 1); /* version */
|
||||||
out_uint16_be(c->out_s, s->height);
|
out_uint32_be(c->out_s, size);
|
||||||
out_uint16_be(c->out_s, s->width);
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
|
||||||
out_uint8(c->out_s, s->bpp);
|
out_uint16_be(c->out_s, 1);
|
||||||
out_uint8(c->out_s, s->rsr);
|
|
||||||
out_uint8p(c->out_s, s->locale, 17);
|
|
||||||
out_uint8(c->out_s, s->addr_type);
|
|
||||||
|
|
||||||
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
/* body */
|
||||||
{
|
out_uint8(c->out_s, s->type);
|
||||||
out_uint32_be(c->out_s, s->ipv4addr);
|
out_uint16_be(c->out_s, s->height);
|
||||||
}
|
out_uint16_be(c->out_s, s->width);
|
||||||
else if (s->addr_type == SCP_ADDRESS_TYPE_IPV6)
|
out_uint8(c->out_s, s->bpp);
|
||||||
{
|
out_uint8(c->out_s, s->rsr);
|
||||||
out_uint8p(c->out_s, s->ipv6addr, 16);
|
out_uint8p(c->out_s, s->locale, 17);
|
||||||
}
|
out_uint8(c->out_s, s->addr_type);
|
||||||
|
|
||||||
sz = g_strlen(s->hostname);
|
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
||||||
out_uint8(c->out_s, sz);
|
{
|
||||||
out_uint8p(c->out_s, s->hostname, sz);
|
out_uint32_be(c->out_s, s->ipv4addr);
|
||||||
sz = g_strlen(s->username);
|
}
|
||||||
out_uint8(c->out_s, sz);
|
else if (s->addr_type == SCP_ADDRESS_TYPE_IPV6)
|
||||||
out_uint8p(c->out_s, s->username, sz);
|
{
|
||||||
sz = g_strlen(s->password);
|
out_uint8p(c->out_s, s->ipv6addr, 16);
|
||||||
out_uint8(c->out_s, sz);
|
}
|
||||||
out_uint8p(c->out_s, s->password, sz);
|
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
sz = g_strlen(s->hostname);
|
||||||
{
|
out_uint8(c->out_s, sz);
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
out_uint8p(c->out_s, s->hostname, sz);
|
||||||
}
|
sz = g_strlen(s->username);
|
||||||
|
out_uint8(c->out_s, sz);
|
||||||
|
out_uint8p(c->out_s, s->username, sz);
|
||||||
|
sz = g_strlen(s->password);
|
||||||
|
out_uint8(c->out_s, sz);
|
||||||
|
out_uint8p(c->out_s, s->password, sz);
|
||||||
|
|
||||||
/* wait for response */
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
||||||
return _scp_v1c_check_response(c, s);
|
{
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* wait for response */
|
||||||
|
return _scp_v1c_check_response(c, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 004 */
|
/* 004 */
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v1c_resend_credentials(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
scp_v1c_resend_credentials(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
|
||||||
{
|
{
|
||||||
tui8 sz;
|
tui8 sz;
|
||||||
tui32 size;
|
tui32 size;
|
||||||
|
|
||||||
init_stream(c->out_s, c->out_s->size);
|
init_stream(c->out_s, c->out_s->size);
|
||||||
init_stream(c->in_s, c->in_s->size);
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
size = 12 + 2 + g_strlen(s->username) + g_strlen(s->password);
|
size = 12 + 2 + g_strlen(s->username) + g_strlen(s->password);
|
||||||
|
|
||||||
/* sending request */
|
/* sending request */
|
||||||
/* header */
|
/* header */
|
||||||
out_uint32_be(c->out_s, 1); /* version */
|
out_uint32_be(c->out_s, 1); /* version */
|
||||||
out_uint32_be(c->out_s, size);
|
out_uint32_be(c->out_s, size);
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
|
||||||
out_uint16_be(c->out_s, 4);
|
out_uint16_be(c->out_s, 4);
|
||||||
|
|
||||||
/* body */
|
/* body */
|
||||||
sz = g_strlen(s->username);
|
sz = g_strlen(s->username);
|
||||||
out_uint8(c->out_s, sz);
|
out_uint8(c->out_s, sz);
|
||||||
out_uint8p(c->out_s, s->username, sz);
|
out_uint8p(c->out_s, s->username, sz);
|
||||||
sz = g_strlen(s->password);
|
sz = g_strlen(s->password);
|
||||||
out_uint8(c->out_s, sz);
|
out_uint8(c->out_s, sz);
|
||||||
out_uint8p(c->out_s, s->password, sz);
|
out_uint8p(c->out_s, s->password, sz);
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
||||||
{
|
{
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait for response */
|
/* wait for response */
|
||||||
return _scp_v1c_check_response(c, s);
|
return _scp_v1c_check_response(c, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 021 */
|
/* 021 */
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v1c_pwd_change(struct SCP_CONNECTION* c, char* newpass);
|
scp_v1c_pwd_change(struct SCP_CONNECTION *c, char *newpass);
|
||||||
/* 022 */
|
/* 022 */
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v1c_pwd_change_cancel(struct SCP_CONNECTION* c);
|
scp_v1c_pwd_change_cancel(struct SCP_CONNECTION *c);
|
||||||
|
|
||||||
/* 041 */
|
/* 041 */
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v1c_get_session_list(struct SCP_CONNECTION* c, int* scount,
|
scp_v1c_get_session_list(struct SCP_CONNECTION *c, int *scount,
|
||||||
struct SCP_DISCONNECTED_SESSION** s)
|
struct SCP_DISCONNECTED_SESSION **s)
|
||||||
{
|
{
|
||||||
tui32 version = 1;
|
tui32 version = 1;
|
||||||
tui32 size = 12;
|
tui32 size = 12;
|
||||||
tui16 cmd = 41;
|
tui16 cmd = 41;
|
||||||
tui32 sescnt = 0; /* total session number */
|
tui32 sescnt = 0; /* total session number */
|
||||||
tui32 sestmp = 0; /* additional total session number */
|
tui32 sestmp = 0; /* additional total session number */
|
||||||
tui8 pktcnt = 0; /* packet session count */
|
tui8 pktcnt = 0; /* packet session count */
|
||||||
tui32 totalcnt = 0; /* session counter */
|
tui32 totalcnt = 0; /* session counter */
|
||||||
tui8 continued = 0; /* continue flag */
|
tui8 continued = 0; /* continue flag */
|
||||||
int firstpkt = 1; /* "first packet" flag */
|
int firstpkt = 1; /* "first packet" flag */
|
||||||
int idx;
|
int idx;
|
||||||
struct SCP_DISCONNECTED_SESSION* ds = 0;
|
struct SCP_DISCONNECTED_SESSION *ds = 0;
|
||||||
|
|
||||||
init_stream(c->out_s, c->out_s->size);
|
init_stream(c->out_s, c->out_s->size);
|
||||||
|
|
||||||
/* we request session list */
|
/* we request session list */
|
||||||
out_uint32_be(c->out_s, version); /* version */
|
out_uint32_be(c->out_s, version); /* version */
|
||||||
out_uint32_be(c->out_s, size); /* size */
|
out_uint32_be(c->out_s, size); /* size */
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
|
||||||
out_uint16_be(c->out_s, cmd); /* cmd */
|
out_uint16_be(c->out_s, cmd); /* cmd */
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
/* then we wait for server response */
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
|
||||||
{
|
{
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_uint32_be(c->in_s, version);
|
do
|
||||||
if (version != 1)
|
|
||||||
{
|
{
|
||||||
return SCP_CLIENT_STATE_VERSION_ERR;
|
/* then we wait for server response */
|
||||||
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint32_be(c->in_s, version);
|
||||||
|
|
||||||
|
if (version != 1)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint32_be(c->in_s, size);
|
||||||
|
|
||||||
|
if (size < 12)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_SIZE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd != SCP_COMMAND_SET_DEFAULT)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd != 42)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstpkt)
|
||||||
|
{
|
||||||
|
firstpkt = 0;
|
||||||
|
in_uint32_be(c->in_s, sescnt);
|
||||||
|
sestmp = sescnt;
|
||||||
|
|
||||||
|
ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION) * sescnt, 0);
|
||||||
|
|
||||||
|
if (ds == 0)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in_uint32_be(c->in_s, sestmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint8(c->in_s, continued);
|
||||||
|
in_uint8(c->in_s, pktcnt);
|
||||||
|
|
||||||
|
for (idx = 0; idx < pktcnt; idx++)
|
||||||
|
{
|
||||||
|
in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).type);
|
||||||
|
in_uint16_be(c->in_s, (ds[totalcnt]).height);
|
||||||
|
in_uint16_be(c->in_s, (ds[totalcnt]).width);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).bpp);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).idle_days);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).idle_hours);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).idle_minutes);
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, (ds[totalcnt]).conn_year);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).conn_month);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).conn_day);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).conn_hour);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).conn_minute);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).addr_type);
|
||||||
|
|
||||||
|
if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV4)
|
||||||
|
{
|
||||||
|
in_uint32_be(c->in_s, (ds[totalcnt]).ipv4addr);
|
||||||
|
}
|
||||||
|
else if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV6)
|
||||||
|
{
|
||||||
|
in_uint8a(c->in_s, (ds[totalcnt]).ipv6addr, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
totalcnt++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (continued);
|
||||||
|
|
||||||
in_uint32_be(c->in_s, size);
|
printf("fine\n");
|
||||||
if (size < 12)
|
/* return data... */
|
||||||
{
|
(*scount) = sescnt;
|
||||||
return SCP_CLIENT_STATE_SIZE_ERR;
|
(*s) = ds;
|
||||||
}
|
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
return SCP_CLIENT_STATE_LIST_OK;
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
|
||||||
if (cmd != SCP_COMMAND_SET_DEFAULT)
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
|
||||||
if (cmd != 42)
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstpkt)
|
|
||||||
{
|
|
||||||
firstpkt = 0;
|
|
||||||
in_uint32_be(c->in_s, sescnt);
|
|
||||||
sestmp = sescnt;
|
|
||||||
|
|
||||||
ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION) * sescnt, 0);
|
|
||||||
if (ds == 0)
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
in_uint32_be(c->in_s, sestmp);
|
|
||||||
}
|
|
||||||
in_uint8(c->in_s, continued);
|
|
||||||
in_uint8(c->in_s, pktcnt);
|
|
||||||
|
|
||||||
for (idx = 0; idx < pktcnt; idx++)
|
|
||||||
{
|
|
||||||
in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).type);
|
|
||||||
in_uint16_be(c->in_s, (ds[totalcnt]).height);
|
|
||||||
in_uint16_be(c->in_s, (ds[totalcnt]).width);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).bpp);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).idle_days);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).idle_hours);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).idle_minutes);
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, (ds[totalcnt]).conn_year);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).conn_month);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).conn_day);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).conn_hour);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).conn_minute);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).addr_type);
|
|
||||||
if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV4)
|
|
||||||
{
|
|
||||||
in_uint32_be(c->in_s, (ds[totalcnt]).ipv4addr);
|
|
||||||
}
|
|
||||||
else if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV6)
|
|
||||||
{
|
|
||||||
in_uint8a(c->in_s, (ds[totalcnt]).ipv6addr, 16);
|
|
||||||
}
|
|
||||||
totalcnt++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (continued);
|
|
||||||
|
|
||||||
printf("fine\n");
|
|
||||||
/* return data... */
|
|
||||||
(*scount) = sescnt;
|
|
||||||
(*s) = ds;
|
|
||||||
|
|
||||||
return SCP_CLIENT_STATE_LIST_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 043 */
|
/* 043 */
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v1c_select_session(struct SCP_CONNECTION* c, struct SCP_SESSION* s,
|
scp_v1c_select_session(struct SCP_CONNECTION *c, struct SCP_SESSION *s,
|
||||||
SCP_SID sid)
|
SCP_SID sid)
|
||||||
{
|
{
|
||||||
tui32 version = 1;
|
tui32 version = 1;
|
||||||
tui32 size = 16;
|
tui32 size = 16;
|
||||||
tui16 cmd = 43;
|
tui16 cmd = 43;
|
||||||
|
|
||||||
init_stream(c->out_s, c->out_s->size);
|
init_stream(c->out_s, c->out_s->size);
|
||||||
|
|
||||||
/* sending our selection */
|
/* sending our selection */
|
||||||
out_uint32_be(c->out_s, version); /* version */
|
out_uint32_be(c->out_s, version); /* version */
|
||||||
out_uint32_be(c->out_s, size); /* size */
|
out_uint32_be(c->out_s, size); /* size */
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
|
||||||
out_uint16_be(c->out_s, cmd); /* cmd */
|
out_uint16_be(c->out_s, cmd); /* cmd */
|
||||||
|
|
||||||
out_uint32_be(c->out_s, sid);
|
out_uint32_be(c->out_s, sid);
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
||||||
{
|
{
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* waiting for response.... */
|
/* waiting for response.... */
|
||||||
init_stream(c->in_s, c->in_s->size);
|
init_stream(c->in_s, c->in_s->size);
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, version);
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
||||||
if (version != 1)
|
{
|
||||||
{
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
return SCP_CLIENT_STATE_VERSION_ERR;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, size);
|
in_uint32_be(c->in_s, version);
|
||||||
if (size < 12)
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_SIZE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
if (version != 1)
|
||||||
/* read the rest of the packet */
|
{
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
||||||
{
|
}
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
in_uint32_be(c->in_s, size);
|
||||||
if (cmd != SCP_COMMAND_SET_DEFAULT)
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
if (size < 12)
|
||||||
if (cmd != 46)
|
{
|
||||||
{
|
return SCP_CLIENT_STATE_SIZE_ERR;
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* session display */
|
init_stream(c->in_s, c->in_s->size);
|
||||||
in_uint16_be(c->in_s, (s->display));
|
|
||||||
/*we don't need to return any data other than the display */
|
|
||||||
/*because we already sent that */
|
|
||||||
|
|
||||||
return SCP_CLIENT_STATE_OK;
|
/* read the rest of the packet */
|
||||||
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd != SCP_COMMAND_SET_DEFAULT)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd != 46)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* session display */
|
||||||
|
in_uint16_be(c->in_s, (s->display));
|
||||||
|
/*we don't need to return any data other than the display */
|
||||||
|
/*because we already sent that */
|
||||||
|
|
||||||
|
return SCP_CLIENT_STATE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 044 */
|
/* 044 */
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v1c_select_session_cancel(struct SCP_CONNECTION* c)
|
scp_v1c_select_session_cancel(struct SCP_CONNECTION *c)
|
||||||
{
|
{
|
||||||
tui32 version = 1;
|
tui32 version = 1;
|
||||||
tui32 size = 12;
|
tui32 size = 12;
|
||||||
tui16 cmd = 44;
|
tui16 cmd = 44;
|
||||||
|
|
||||||
init_stream(c->out_s, c->out_s->size);
|
init_stream(c->out_s, c->out_s->size);
|
||||||
|
|
||||||
/* sending our selection */
|
/* sending our selection */
|
||||||
out_uint32_be(c->out_s, version); /* version */
|
out_uint32_be(c->out_s, version); /* version */
|
||||||
out_uint32_be(c->out_s, size); /* size */
|
out_uint32_be(c->out_s, size); /* size */
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
|
||||||
out_uint16_be(c->out_s, cmd); /* cmd */
|
out_uint16_be(c->out_s, cmd); /* cmd */
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
||||||
{
|
{
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SCP_CLIENT_STATE_END;
|
return SCP_CLIENT_STATE_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum SCP_CLIENT_STATES_E
|
static enum SCP_CLIENT_STATES_E
|
||||||
_scp_v1c_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
_scp_v1c_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
|
||||||
{
|
{
|
||||||
tui32 version;
|
tui32 version;
|
||||||
tui32 size;
|
tui32 size;
|
||||||
tui16 cmd;
|
tui16 cmd;
|
||||||
tui16 dim;
|
tui16 dim;
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
init_stream(c->in_s, c->in_s->size);
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, version);
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
||||||
if (version != 1)
|
{
|
||||||
{
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
return SCP_CLIENT_STATE_VERSION_ERR;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, size);
|
in_uint32_be(c->in_s, version);
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
if (version != 1)
|
||||||
/* read the rest of the packet */
|
{
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
||||||
{
|
}
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
in_uint32_be(c->in_s, size);
|
||||||
|
|
||||||
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
|
/* read the rest of the packet */
|
||||||
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd != SCP_COMMAND_SET_DEFAULT)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd == 2) /* connection denied */
|
||||||
|
{
|
||||||
|
in_uint16_be(c->in_s, dim);
|
||||||
|
|
||||||
|
if (s->errstr != 0)
|
||||||
|
{
|
||||||
|
g_free(s->errstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
s->errstr = g_malloc(dim + 1, 0);
|
||||||
|
|
||||||
|
if (s->errstr == 0)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint8a(c->in_s, s->errstr, dim);
|
||||||
|
(s->errstr)[dim] = '\0';
|
||||||
|
|
||||||
|
return SCP_CLIENT_STATE_CONNECTION_DENIED;
|
||||||
|
}
|
||||||
|
else if (cmd == 3) /* resend usr/pwd */
|
||||||
|
{
|
||||||
|
in_uint16_be(c->in_s, dim);
|
||||||
|
|
||||||
|
if (s->errstr != 0)
|
||||||
|
{
|
||||||
|
g_free(s->errstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
s->errstr = g_malloc(dim + 1, 0);
|
||||||
|
|
||||||
|
if (s->errstr == 0)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint8a(c->in_s, s->errstr, dim);
|
||||||
|
(s->errstr)[dim] = '\0';
|
||||||
|
|
||||||
|
return SCP_CLIENT_STATE_RESEND_CREDENTIALS;
|
||||||
|
}
|
||||||
|
else if (cmd == 20) /* password change */
|
||||||
|
{
|
||||||
|
in_uint16_be(c->in_s, dim);
|
||||||
|
|
||||||
|
if (s->errstr != 0)
|
||||||
|
{
|
||||||
|
g_free(s->errstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
s->errstr = g_malloc(dim + 1, 0);
|
||||||
|
|
||||||
|
if (s->errstr == 0)
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint8a(c->in_s, s->errstr, dim);
|
||||||
|
(s->errstr)[dim] = '\0';
|
||||||
|
|
||||||
|
return SCP_CLIENT_STATE_PWD_CHANGE_REQ;
|
||||||
|
}
|
||||||
|
else if (cmd == 30) /* display */
|
||||||
|
{
|
||||||
|
in_uint16_be(c->in_s, s->display);
|
||||||
|
|
||||||
|
return SCP_CLIENT_STATE_OK;
|
||||||
|
}
|
||||||
|
//else if (cmd == 31) /* there's a disconnected session */
|
||||||
|
//{
|
||||||
|
// return SCP_CLIENT_STATE_RECONNECT_SINGLE;
|
||||||
|
//}
|
||||||
|
//else if (cmd == 33) /* display of a disconnected session */
|
||||||
|
//{
|
||||||
|
// return SCP_CLIENT_STATE_RECONNECT;
|
||||||
|
//}
|
||||||
|
else if (cmd == 40) /* session list */
|
||||||
|
{
|
||||||
|
return SCP_CLIENT_STATE_SESSION_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
|
||||||
if (cmd != SCP_COMMAND_SET_DEFAULT)
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
|
||||||
if (cmd == 2) /* connection denied */
|
|
||||||
{
|
|
||||||
in_uint16_be(c->in_s, dim);
|
|
||||||
if (s->errstr != 0)
|
|
||||||
{
|
|
||||||
g_free(s->errstr);
|
|
||||||
}
|
|
||||||
s->errstr = g_malloc(dim + 1, 0);
|
|
||||||
if (s->errstr == 0)
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
in_uint8a(c->in_s, s->errstr, dim);
|
|
||||||
(s->errstr)[dim] = '\0';
|
|
||||||
|
|
||||||
return SCP_CLIENT_STATE_CONNECTION_DENIED;
|
|
||||||
}
|
|
||||||
else if (cmd == 3) /* resend usr/pwd */
|
|
||||||
{
|
|
||||||
in_uint16_be(c->in_s, dim);
|
|
||||||
if (s->errstr != 0)
|
|
||||||
{
|
|
||||||
g_free(s->errstr);
|
|
||||||
}
|
|
||||||
s->errstr = g_malloc(dim + 1, 0);
|
|
||||||
if (s->errstr == 0)
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
in_uint8a(c->in_s, s->errstr, dim);
|
|
||||||
(s->errstr)[dim] = '\0';
|
|
||||||
|
|
||||||
return SCP_CLIENT_STATE_RESEND_CREDENTIALS;
|
|
||||||
}
|
|
||||||
else if (cmd == 20) /* password change */
|
|
||||||
{
|
|
||||||
in_uint16_be(c->in_s, dim);
|
|
||||||
if (s->errstr != 0)
|
|
||||||
{
|
|
||||||
g_free(s->errstr);
|
|
||||||
}
|
|
||||||
s->errstr = g_malloc(dim + 1, 0);
|
|
||||||
if (s->errstr == 0)
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
in_uint8a(c->in_s, s->errstr, dim);
|
|
||||||
(s->errstr)[dim] = '\0';
|
|
||||||
|
|
||||||
return SCP_CLIENT_STATE_PWD_CHANGE_REQ;
|
|
||||||
}
|
|
||||||
else if (cmd == 30) /* display */
|
|
||||||
{
|
|
||||||
in_uint16_be(c->in_s, s->display);
|
|
||||||
|
|
||||||
return SCP_CLIENT_STATE_OK;
|
|
||||||
}
|
|
||||||
//else if (cmd == 31) /* there's a disconnected session */
|
|
||||||
//{
|
|
||||||
// return SCP_CLIENT_STATE_RECONNECT_SINGLE;
|
|
||||||
//}
|
|
||||||
//else if (cmd == 33) /* display of a disconnected session */
|
|
||||||
//{
|
|
||||||
// return SCP_CLIENT_STATE_RECONNECT;
|
|
||||||
//}
|
|
||||||
else if (cmd == 40) /* session list */
|
|
||||||
{
|
|
||||||
return SCP_CLIENT_STATE_SESSION_LIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-18
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
+266
-249
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -33,215 +32,228 @@
|
|||||||
//extern struct log_config* s_log;
|
//extern struct log_config* s_log;
|
||||||
|
|
||||||
static enum SCP_CLIENT_STATES_E
|
static enum SCP_CLIENT_STATES_E
|
||||||
_scp_v1c_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s);
|
_scp_v1c_mng_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s);
|
||||||
|
|
||||||
/* client API */
|
/* client API */
|
||||||
/* 001 */
|
/* 001 */
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v1c_mng_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
scp_v1c_mng_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
|
||||||
{
|
{
|
||||||
tui8 sz;
|
tui8 sz;
|
||||||
tui32 size;
|
tui32 size;
|
||||||
|
|
||||||
init_stream(c->out_s, c->out_s->size);
|
init_stream(c->out_s, c->out_s->size);
|
||||||
init_stream(c->in_s, c->in_s->size);
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
size = 12 + 4 + g_strlen(s->hostname) + g_strlen(s->username) +
|
size = 12 + 4 + g_strlen(s->hostname) + g_strlen(s->username) +
|
||||||
g_strlen(s->password);
|
g_strlen(s->password);
|
||||||
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
|
||||||
{
|
|
||||||
size = size + 4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size = size + 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* sending request */
|
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
||||||
|
{
|
||||||
|
size = size + 4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = size + 16;
|
||||||
|
}
|
||||||
|
|
||||||
/* header */
|
/* sending request */
|
||||||
out_uint32_be(c->out_s, 1); /* version */
|
|
||||||
out_uint32_be(c->out_s, size);
|
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
|
|
||||||
out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN);
|
|
||||||
|
|
||||||
/* data */
|
/* header */
|
||||||
sz = g_strlen(s->username);
|
out_uint32_be(c->out_s, 1); /* version */
|
||||||
out_uint8(c->out_s, sz);
|
out_uint32_be(c->out_s, size);
|
||||||
out_uint8p(c->out_s, s->username, sz);
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
|
||||||
sz = g_strlen(s->password);
|
out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN);
|
||||||
out_uint8(c->out_s, sz);
|
|
||||||
out_uint8p(c->out_s, s->password, sz);
|
|
||||||
|
|
||||||
/* address */
|
/* data */
|
||||||
out_uint8(c->out_s, s->addr_type);
|
sz = g_strlen(s->username);
|
||||||
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
out_uint8(c->out_s, sz);
|
||||||
{
|
out_uint8p(c->out_s, s->username, sz);
|
||||||
out_uint32_be(c->out_s, s->ipv4addr);
|
sz = g_strlen(s->password);
|
||||||
}
|
out_uint8(c->out_s, sz);
|
||||||
else
|
out_uint8p(c->out_s, s->password, sz);
|
||||||
{
|
|
||||||
out_uint8p(c->out_s, s->ipv6addr, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* hostname */
|
/* address */
|
||||||
sz = g_strlen(s->hostname);
|
out_uint8(c->out_s, s->addr_type);
|
||||||
out_uint8(c->out_s, sz);
|
|
||||||
out_uint8p(c->out_s, s->hostname, sz);
|
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
out_uint32_be(c->out_s, s->ipv4addr);
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
out_uint8p(c->out_s, s->ipv6addr, 16);
|
||||||
|
}
|
||||||
|
|
||||||
/* wait for response */
|
/* hostname */
|
||||||
return _scp_v1c_mng_check_response(c, s);
|
sz = g_strlen(s->hostname);
|
||||||
|
out_uint8(c->out_s, sz);
|
||||||
|
out_uint8p(c->out_s, s->hostname, sz);
|
||||||
|
|
||||||
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* wait for response */
|
||||||
|
return _scp_v1c_mng_check_response(c, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 004 */
|
/* 004 */
|
||||||
enum SCP_CLIENT_STATES_E
|
enum SCP_CLIENT_STATES_E
|
||||||
scp_v1c_mng_get_session_list(struct SCP_CONNECTION* c, int* scount,
|
scp_v1c_mng_get_session_list(struct SCP_CONNECTION *c, int *scount,
|
||||||
struct SCP_DISCONNECTED_SESSION** s)
|
struct SCP_DISCONNECTED_SESSION **s)
|
||||||
{
|
{
|
||||||
tui32 version = 1;
|
tui32 version = 1;
|
||||||
tui32 size = 12;
|
tui32 size = 12;
|
||||||
tui16 cmd = SCP_CMD_MNG_LIST_REQ; /* request session list */
|
tui16 cmd = SCP_CMD_MNG_LIST_REQ; /* request session list */
|
||||||
tui32 sescnt = 0; /* total session number */
|
tui32 sescnt = 0; /* total session number */
|
||||||
tui32 sestmp = 0; /* additional total session number */
|
tui32 sestmp = 0; /* additional total session number */
|
||||||
tui8 pktcnt = 0; /* packet session count */
|
tui8 pktcnt = 0; /* packet session count */
|
||||||
tui32 totalcnt = 0; /* session counter */
|
tui32 totalcnt = 0; /* session counter */
|
||||||
tui8 continued = 0; /* continue flag */
|
tui8 continued = 0; /* continue flag */
|
||||||
int firstpkt = 1; /* "first packet" flag */
|
int firstpkt = 1; /* "first packet" flag */
|
||||||
int idx;
|
int idx;
|
||||||
struct SCP_DISCONNECTED_SESSION* ds = 0;
|
struct SCP_DISCONNECTED_SESSION *ds = 0;
|
||||||
// tui8 addr[16];
|
// tui8 addr[16];
|
||||||
|
|
||||||
init_stream(c->out_s, c->out_s->size);
|
init_stream(c->out_s, c->out_s->size);
|
||||||
|
|
||||||
/* we request session list */
|
/* we request session list */
|
||||||
out_uint32_be(c->out_s, version); /* version */
|
out_uint32_be(c->out_s, version); /* version */
|
||||||
out_uint32_be(c->out_s, size); /* size */
|
out_uint32_be(c->out_s, size); /* size */
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); /* cmdset */
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); /* cmdset */
|
||||||
out_uint16_be(c->out_s, cmd); /* cmd */
|
out_uint16_be(c->out_s, cmd); /* cmd */
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
/* then we wait for server response */
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_uint32_be(c->in_s, version);
|
do
|
||||||
if (version != 1)
|
|
||||||
{
|
{
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: version error", __LINE__);
|
/* then we wait for server response */
|
||||||
return SCP_CLIENT_STATE_VERSION_ERR;
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint32_be(c->in_s, version);
|
||||||
|
|
||||||
|
if (version != 1)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: version error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint32_be(c->in_s, size);
|
||||||
|
|
||||||
|
if (size < 12)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: size error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_SIZE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd != SCP_COMMAND_SET_MANAGE)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd != SCP_CMD_MNG_LIST) /* session list */
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstpkt)
|
||||||
|
{
|
||||||
|
firstpkt = 0;
|
||||||
|
in_uint32_be(c->in_s, sescnt);
|
||||||
|
sestmp = sescnt;
|
||||||
|
|
||||||
|
if (0 == sescnt)
|
||||||
|
{
|
||||||
|
/* return data... */
|
||||||
|
(*scount) = sescnt;
|
||||||
|
(*s) = NULL;
|
||||||
|
|
||||||
|
LOG_DBG("[v1c_mng] end list - no session on TS");
|
||||||
|
return SCP_CLIENT_STATE_LIST_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION) * sescnt, 0);
|
||||||
|
|
||||||
|
if (ds == 0)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: internal error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in_uint32_be(c->in_s, sestmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint8(c->in_s, continued);
|
||||||
|
in_uint8(c->in_s, pktcnt);
|
||||||
|
|
||||||
|
for (idx = 0; idx < pktcnt; idx++)
|
||||||
|
{
|
||||||
|
in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).type);
|
||||||
|
in_uint16_be(c->in_s, (ds[totalcnt]).height);
|
||||||
|
in_uint16_be(c->in_s, (ds[totalcnt]).width);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).bpp);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).idle_days);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).idle_hours);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).idle_minutes);
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, (ds[totalcnt]).conn_year);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).conn_month);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).conn_day);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).conn_hour);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).conn_minute);
|
||||||
|
in_uint8(c->in_s, (ds[totalcnt]).addr_type);
|
||||||
|
|
||||||
|
if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV4)
|
||||||
|
{
|
||||||
|
in_uint32_be(c->in_s, (ds[totalcnt]).ipv4addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV6)
|
||||||
|
{
|
||||||
|
in_uint8a(c->in_s, (ds[totalcnt]).ipv6addr, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
totalcnt++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (continued);
|
||||||
|
|
||||||
in_uint32_be(c->in_s, size);
|
/* return data... */
|
||||||
if (size < 12)
|
(*scount) = sescnt;
|
||||||
{
|
(*s) = ds;
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: size error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_SIZE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
LOG_DBG("[v1c_mng] end list");
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
return SCP_CLIENT_STATE_LIST_OK;
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
|
||||||
if (cmd != SCP_COMMAND_SET_MANAGE)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
|
||||||
if (cmd != SCP_CMD_MNG_LIST) /* session list */
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstpkt)
|
|
||||||
{
|
|
||||||
firstpkt = 0;
|
|
||||||
in_uint32_be(c->in_s, sescnt);
|
|
||||||
sestmp = sescnt;
|
|
||||||
|
|
||||||
if (0 == sescnt)
|
|
||||||
{
|
|
||||||
/* return data... */
|
|
||||||
(*scount) = sescnt;
|
|
||||||
(*s) = NULL;
|
|
||||||
|
|
||||||
LOG_DBG("[v1c_mng] end list - no session on TS");
|
|
||||||
return SCP_CLIENT_STATE_LIST_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION) * sescnt, 0);
|
|
||||||
if (ds == 0)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: internal error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
in_uint32_be(c->in_s, sestmp);
|
|
||||||
}
|
|
||||||
in_uint8(c->in_s, continued);
|
|
||||||
in_uint8(c->in_s, pktcnt);
|
|
||||||
|
|
||||||
for (idx = 0; idx < pktcnt; idx++)
|
|
||||||
{
|
|
||||||
in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).type);
|
|
||||||
in_uint16_be(c->in_s, (ds[totalcnt]).height);
|
|
||||||
in_uint16_be(c->in_s, (ds[totalcnt]).width);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).bpp);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).idle_days);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).idle_hours);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).idle_minutes);
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, (ds[totalcnt]).conn_year);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).conn_month);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).conn_day);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).conn_hour);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).conn_minute);
|
|
||||||
in_uint8(c->in_s, (ds[totalcnt]).addr_type);
|
|
||||||
if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV4)
|
|
||||||
{
|
|
||||||
in_uint32_be(c->in_s, (ds[totalcnt]).ipv4addr);
|
|
||||||
}
|
|
||||||
if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV6)
|
|
||||||
{
|
|
||||||
in_uint8a(c->in_s, (ds[totalcnt]).ipv6addr, 16);
|
|
||||||
}
|
|
||||||
totalcnt++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (continued);
|
|
||||||
|
|
||||||
/* return data... */
|
|
||||||
(*scount) = sescnt;
|
|
||||||
(*s) = ds;
|
|
||||||
|
|
||||||
LOG_DBG("[v1c_mng] end list");
|
|
||||||
return SCP_CLIENT_STATE_LIST_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 043 * /
|
/* 043 * /
|
||||||
@@ -339,62 +351,67 @@ scp_v1c_select_session_cancel(struct SCP_CONNECTION* c)
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
static enum SCP_CLIENT_STATES_E
|
static enum SCP_CLIENT_STATES_E
|
||||||
_scp_v1c_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
_scp_v1c_mng_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
|
||||||
{
|
{
|
||||||
tui32 version;
|
tui32 version;
|
||||||
tui32 size;
|
tui32 size;
|
||||||
tui16 cmd;
|
tui16 cmd;
|
||||||
tui8 dim;
|
tui8 dim;
|
||||||
char buf[257];
|
char buf[257];
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
init_stream(c->in_s, c->in_s->size);
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, version);
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
||||||
if (version != 1)
|
{
|
||||||
{
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: version error", __LINE__);
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
return SCP_CLIENT_STATE_VERSION_ERR;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, size);
|
in_uint32_be(c->in_s, version);
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
if (version != 1)
|
||||||
/* read the rest of the packet */
|
{
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: version error", __LINE__);
|
||||||
{
|
return SCP_CLIENT_STATE_VERSION_ERR;
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
}
|
||||||
return SCP_CLIENT_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
in_uint32_be(c->in_s, size);
|
||||||
if (cmd != SCP_COMMAND_SET_MANAGE)
|
|
||||||
{
|
init_stream(c->in_s, c->in_s->size);
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__);
|
|
||||||
|
/* read the rest of the packet */
|
||||||
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd != SCP_COMMAND_SET_MANAGE)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd == SCP_CMD_MNG_LOGIN_ALLOW) /* connection ok */
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_INFO, "[v1c_mng:%d] connection ok", __LINE__);
|
||||||
|
return SCP_CLIENT_STATE_OK;
|
||||||
|
}
|
||||||
|
else if (cmd == SCP_CMD_MNG_LOGIN_DENY) /* connection denied */
|
||||||
|
{
|
||||||
|
in_uint8(c->in_s, dim);
|
||||||
|
buf[dim] = '\0';
|
||||||
|
in_uint8a(c->in_s, buf, dim);
|
||||||
|
scp_session_set_errstr(s, buf);
|
||||||
|
|
||||||
|
log_message(LOG_LEVEL_INFO, "[v1c_mng:%d] connection denied: %s", __LINE__ , s->errstr);
|
||||||
|
return SCP_CLIENT_STATE_CONNECTION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1c-mng:%d] connection aborted: sequence error", __LINE__);
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
|
||||||
if (cmd == SCP_CMD_MNG_LOGIN_ALLOW) /* connection ok */
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_INFO, "[v1c_mng:%d] connection ok", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_OK;
|
|
||||||
}
|
|
||||||
else if (cmd == SCP_CMD_MNG_LOGIN_DENY) /* connection denied */
|
|
||||||
{
|
|
||||||
in_uint8(c->in_s, dim);
|
|
||||||
buf[dim]='\0';
|
|
||||||
in_uint8a(c->in_s, buf, dim);
|
|
||||||
scp_session_set_errstr(s, buf);
|
|
||||||
|
|
||||||
log_message(LOG_LEVEL_INFO, "[v1c_mng:%d] connection denied: %s", __LINE__ , s->errstr);
|
|
||||||
return SCP_CLIENT_STATE_CONNECTION_DENIED;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1c-mng:%d] connection aborted: sequence error", __LINE__);
|
|
||||||
return SCP_CLIENT_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
+602
-569
File diff suppressed because it is too large
Load Diff
+17
-18
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
+276
-263
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -33,309 +32,323 @@
|
|||||||
//extern struct log_config* s_log;
|
//extern struct log_config* s_log;
|
||||||
|
|
||||||
static enum SCP_SERVER_STATES_E
|
static enum SCP_SERVER_STATES_E
|
||||||
_scp_v1s_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s);
|
_scp_v1s_mng_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s);
|
||||||
|
|
||||||
/* server API */
|
/* server API */
|
||||||
enum SCP_SERVER_STATES_E
|
enum SCP_SERVER_STATES_E
|
||||||
scp_v1s_mng_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s)
|
scp_v1s_mng_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s)
|
||||||
{
|
{
|
||||||
struct SCP_SESSION* session;
|
struct SCP_SESSION *session;
|
||||||
tui32 ipaddr;
|
tui32 ipaddr;
|
||||||
tui16 cmd;
|
tui16 cmd;
|
||||||
tui8 sz;
|
tui8 sz;
|
||||||
char buf[257];
|
char buf[257];
|
||||||
|
|
||||||
/* reading command */
|
/* reading command */
|
||||||
in_uint16_be(c->in_s, cmd);
|
in_uint16_be(c->in_s, cmd);
|
||||||
if (cmd != 1) /* manager login */
|
|
||||||
{
|
|
||||||
return SCP_SERVER_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
session = scp_session_create();
|
if (cmd != 1) /* manager login */
|
||||||
if (0 == session)
|
{
|
||||||
{
|
return SCP_SERVER_STATE_SEQUENCE_ERR;
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
scp_session_set_version(session, 1);
|
session = scp_session_create();
|
||||||
scp_session_set_type(session, SCP_SESSION_TYPE_MANAGE);
|
|
||||||
|
|
||||||
/* reading username */
|
if (0 == session)
|
||||||
in_uint8(c->in_s, sz);
|
{
|
||||||
buf[sz]='\0';
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
in_uint8a(c->in_s, buf, sz);
|
}
|
||||||
if (0 != scp_session_set_username(session, buf))
|
|
||||||
{
|
|
||||||
scp_session_destroy(session);
|
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reading password */
|
scp_session_set_version(session, 1);
|
||||||
in_uint8(c->in_s, sz);
|
scp_session_set_type(session, SCP_SESSION_TYPE_MANAGE);
|
||||||
buf[sz]='\0';
|
|
||||||
in_uint8a(c->in_s, buf, sz);
|
|
||||||
if (0 != scp_session_set_password(session, buf))
|
|
||||||
{
|
|
||||||
scp_session_destroy(session);
|
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reading remote address */
|
/* reading username */
|
||||||
in_uint8(c->in_s, sz);
|
in_uint8(c->in_s, sz);
|
||||||
if (sz == SCP_ADDRESS_TYPE_IPV4)
|
buf[sz] = '\0';
|
||||||
{
|
in_uint8a(c->in_s, buf, sz);
|
||||||
in_uint32_be(c->in_s, ipaddr);
|
|
||||||
scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &ipaddr);
|
|
||||||
}
|
|
||||||
else if (sz == SCP_ADDRESS_TYPE_IPV6)
|
|
||||||
{
|
|
||||||
in_uint8a(c->in_s, buf, 16);
|
|
||||||
scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV6_BIN, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reading hostname */
|
if (0 != scp_session_set_username(session, buf))
|
||||||
in_uint8(c->in_s, sz);
|
{
|
||||||
buf[sz]='\0';
|
scp_session_destroy(session);
|
||||||
in_uint8a(c->in_s, buf, sz);
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
if (0 != scp_session_set_hostname(session, buf))
|
}
|
||||||
{
|
|
||||||
scp_session_destroy(session);
|
|
||||||
return SCP_SERVER_STATE_INTERNAL_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* returning the struct */
|
/* reading password */
|
||||||
(*s)=session;
|
in_uint8(c->in_s, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
|
||||||
return SCP_SERVER_STATE_START_MANAGE;
|
if (0 != scp_session_set_password(session, buf))
|
||||||
|
{
|
||||||
|
scp_session_destroy(session);
|
||||||
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reading remote address */
|
||||||
|
in_uint8(c->in_s, sz);
|
||||||
|
|
||||||
|
if (sz == SCP_ADDRESS_TYPE_IPV4)
|
||||||
|
{
|
||||||
|
in_uint32_be(c->in_s, ipaddr);
|
||||||
|
scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &ipaddr);
|
||||||
|
}
|
||||||
|
else if (sz == SCP_ADDRESS_TYPE_IPV6)
|
||||||
|
{
|
||||||
|
in_uint8a(c->in_s, buf, 16);
|
||||||
|
scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV6_BIN, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reading hostname */
|
||||||
|
in_uint8(c->in_s, sz);
|
||||||
|
buf[sz] = '\0';
|
||||||
|
in_uint8a(c->in_s, buf, sz);
|
||||||
|
|
||||||
|
if (0 != scp_session_set_hostname(session, buf))
|
||||||
|
{
|
||||||
|
scp_session_destroy(session);
|
||||||
|
return SCP_SERVER_STATE_INTERNAL_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* returning the struct */
|
||||||
|
(*s) = session;
|
||||||
|
|
||||||
|
return SCP_SERVER_STATE_START_MANAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 002 */
|
/* 002 */
|
||||||
enum SCP_SERVER_STATES_E
|
enum SCP_SERVER_STATES_E
|
||||||
scp_v1s_mng_allow_connection(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
scp_v1s_mng_allow_connection(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
|
||||||
{
|
{
|
||||||
init_stream(c->out_s,c->out_s->size);
|
init_stream(c->out_s, c->out_s->size);
|
||||||
|
|
||||||
out_uint32_be(c->out_s, 1);
|
out_uint32_be(c->out_s, 1);
|
||||||
/* packet size: 4 + 4 + 2 + 2 */
|
/* packet size: 4 + 4 + 2 + 2 */
|
||||||
/* version + size + cmdset + cmd */
|
/* version + size + cmdset + cmd */
|
||||||
out_uint32_be(c->out_s, 12);
|
out_uint32_be(c->out_s, 12);
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
|
||||||
out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_ALLOW);
|
out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_ALLOW);
|
||||||
|
|
||||||
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, 12))
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, 12))
|
||||||
{
|
{
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _scp_v1s_mng_check_response(c, s);
|
return _scp_v1s_mng_check_response(c, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 003 */
|
/* 003 */
|
||||||
enum SCP_SERVER_STATES_E
|
enum SCP_SERVER_STATES_E
|
||||||
scp_v1s_mng_deny_connection(struct SCP_CONNECTION* c, char* reason)
|
scp_v1s_mng_deny_connection(struct SCP_CONNECTION *c, char *reason)
|
||||||
{
|
{
|
||||||
int rlen;
|
int rlen;
|
||||||
|
|
||||||
init_stream(c->out_s,c->out_s->size);
|
init_stream(c->out_s, c->out_s->size);
|
||||||
|
|
||||||
/* forcing message not to exceed 64k */
|
/* forcing message not to exceed 64k */
|
||||||
rlen = g_strlen(reason);
|
rlen = g_strlen(reason);
|
||||||
if (rlen > 65535)
|
|
||||||
{
|
|
||||||
rlen = 65535;
|
|
||||||
}
|
|
||||||
|
|
||||||
out_uint32_be(c->out_s, 1);
|
if (rlen > 65535)
|
||||||
/* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/
|
{
|
||||||
/* version + size + cmdset + cmd + msglen + msg */
|
rlen = 65535;
|
||||||
out_uint32_be(c->out_s, rlen+14);
|
}
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
|
|
||||||
out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_DENY);
|
|
||||||
out_uint16_be(c->out_s, rlen);
|
|
||||||
out_uint8p(c->out_s, reason, rlen);
|
|
||||||
|
|
||||||
if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, rlen+14))
|
out_uint32_be(c->out_s, 1);
|
||||||
{
|
/* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
/* version + size + cmdset + cmd + msglen + msg */
|
||||||
}
|
out_uint32_be(c->out_s, rlen + 14);
|
||||||
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
|
||||||
|
out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_DENY);
|
||||||
|
out_uint16_be(c->out_s, rlen);
|
||||||
|
out_uint8p(c->out_s, reason, rlen);
|
||||||
|
|
||||||
return SCP_SERVER_STATE_END;
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, rlen + 14))
|
||||||
|
{
|
||||||
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SCP_SERVER_STATE_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 006 */
|
/* 006 */
|
||||||
enum SCP_SERVER_STATES_E
|
enum SCP_SERVER_STATES_E
|
||||||
scp_v1s_mng_list_sessions(struct SCP_CONNECTION* c, struct SCP_SESSION* s,
|
scp_v1s_mng_list_sessions(struct SCP_CONNECTION *c, struct SCP_SESSION *s,
|
||||||
int sescnt, struct SCP_DISCONNECTED_SESSION* ds)
|
int sescnt, struct SCP_DISCONNECTED_SESSION *ds)
|
||||||
{
|
{
|
||||||
tui32 version = 1;
|
tui32 version = 1;
|
||||||
tui32 size = 12;
|
tui32 size = 12;
|
||||||
tui16 cmd = SCP_CMD_MNG_LIST;
|
tui16 cmd = SCP_CMD_MNG_LIST;
|
||||||
int pktcnt;
|
int pktcnt;
|
||||||
int idx;
|
int idx;
|
||||||
int sidx;
|
int sidx;
|
||||||
int pidx;
|
int pidx;
|
||||||
struct SCP_DISCONNECTED_SESSION* cds;
|
struct SCP_DISCONNECTED_SESSION *cds;
|
||||||
|
|
||||||
/* calculating the number of packets to send */
|
/* calculating the number of packets to send */
|
||||||
pktcnt=sescnt/SCP_SERVER_MAX_LIST_SIZE;
|
pktcnt = sescnt / SCP_SERVER_MAX_LIST_SIZE;
|
||||||
if ((sescnt%SCP_SERVER_MAX_LIST_SIZE)!=0)
|
|
||||||
{
|
|
||||||
pktcnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (idx=0; idx<pktcnt; idx++)
|
if ((sescnt % SCP_SERVER_MAX_LIST_SIZE) != 0)
|
||||||
{
|
|
||||||
/* ok, we send session session list */
|
|
||||||
init_stream(c->out_s, c->out_s->size);
|
|
||||||
|
|
||||||
/* size: ver+size+cmdset+cmd+sescnt+continue+count */
|
|
||||||
size=4+4+2+2+4+1+1;
|
|
||||||
|
|
||||||
/* header */
|
|
||||||
s_push_layer(c->out_s, channel_hdr, 8);
|
|
||||||
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
|
|
||||||
out_uint16_be(c->out_s, cmd);
|
|
||||||
|
|
||||||
/* session count */
|
|
||||||
out_uint32_be(c->out_s, sescnt);
|
|
||||||
|
|
||||||
/* setting the continue flag */
|
|
||||||
if ((idx+1)*SCP_SERVER_MAX_LIST_SIZE >= sescnt)
|
|
||||||
{
|
{
|
||||||
out_uint8(c->out_s, 0);
|
pktcnt++;
|
||||||
/* setting session count for this packet */
|
|
||||||
pidx=sescnt-(idx*SCP_SERVER_MAX_LIST_SIZE);
|
|
||||||
out_uint8(c->out_s, pidx);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
out_uint8(c->out_s, 1);
|
|
||||||
/* setting session count for this packet */
|
|
||||||
pidx=SCP_SERVER_MAX_LIST_SIZE;
|
|
||||||
out_uint8(c->out_s, pidx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* adding session descriptors */
|
for (idx = 0; idx < pktcnt; idx++)
|
||||||
for (sidx=0; sidx<pidx; sidx++)
|
|
||||||
{
|
{
|
||||||
/* shortcut to the current session to send */
|
/* ok, we send session session list */
|
||||||
cds=ds+((idx)*SCP_SERVER_MAX_LIST_SIZE)+sidx;
|
init_stream(c->out_s, c->out_s->size);
|
||||||
|
|
||||||
/* session data */
|
/* size: ver+size+cmdset+cmd+sescnt+continue+count */
|
||||||
out_uint32_be(c->out_s, cds->SID); /* session id */
|
size = 4 + 4 + 2 + 2 + 4 + 1 + 1;
|
||||||
out_uint8(c->out_s, cds->type);
|
|
||||||
out_uint16_be(c->out_s, cds->height);
|
|
||||||
out_uint16_be(c->out_s, cds->width);
|
|
||||||
out_uint8(c->out_s, cds->bpp);
|
|
||||||
out_uint8(c->out_s, cds->idle_days);
|
|
||||||
out_uint8(c->out_s, cds->idle_hours);
|
|
||||||
out_uint8(c->out_s, cds->idle_minutes);
|
|
||||||
size += 13;
|
|
||||||
|
|
||||||
out_uint16_be(c->out_s, cds->conn_year);
|
/* header */
|
||||||
out_uint8(c->out_s, cds->conn_month);
|
s_push_layer(c->out_s, channel_hdr, 8);
|
||||||
out_uint8(c->out_s, cds->conn_day);
|
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
|
||||||
out_uint8(c->out_s, cds->conn_hour);
|
out_uint16_be(c->out_s, cmd);
|
||||||
out_uint8(c->out_s, cds->conn_minute);
|
|
||||||
out_uint8(c->out_s, cds->addr_type);
|
|
||||||
size += 7;
|
|
||||||
|
|
||||||
if (cds->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
/* session count */
|
||||||
{
|
out_uint32_be(c->out_s, sescnt);
|
||||||
in_uint32_be(c->out_s, cds->ipv4addr);
|
|
||||||
size += 4;
|
/* setting the continue flag */
|
||||||
}
|
if ((idx + 1)*SCP_SERVER_MAX_LIST_SIZE >= sescnt)
|
||||||
else if (cds->addr_type == SCP_ADDRESS_TYPE_IPV6)
|
{
|
||||||
{
|
out_uint8(c->out_s, 0);
|
||||||
in_uint8a(c->out_s, cds->ipv6addr, 16);
|
/* setting session count for this packet */
|
||||||
size += 16;
|
pidx = sescnt - (idx * SCP_SERVER_MAX_LIST_SIZE);
|
||||||
}
|
out_uint8(c->out_s, pidx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out_uint8(c->out_s, 1);
|
||||||
|
/* setting session count for this packet */
|
||||||
|
pidx = SCP_SERVER_MAX_LIST_SIZE;
|
||||||
|
out_uint8(c->out_s, pidx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* adding session descriptors */
|
||||||
|
for (sidx = 0; sidx < pidx; sidx++)
|
||||||
|
{
|
||||||
|
/* shortcut to the current session to send */
|
||||||
|
cds = ds + ((idx) * SCP_SERVER_MAX_LIST_SIZE) + sidx;
|
||||||
|
|
||||||
|
/* session data */
|
||||||
|
out_uint32_be(c->out_s, cds->SID); /* session id */
|
||||||
|
out_uint8(c->out_s, cds->type);
|
||||||
|
out_uint16_be(c->out_s, cds->height);
|
||||||
|
out_uint16_be(c->out_s, cds->width);
|
||||||
|
out_uint8(c->out_s, cds->bpp);
|
||||||
|
out_uint8(c->out_s, cds->idle_days);
|
||||||
|
out_uint8(c->out_s, cds->idle_hours);
|
||||||
|
out_uint8(c->out_s, cds->idle_minutes);
|
||||||
|
size += 13;
|
||||||
|
|
||||||
|
out_uint16_be(c->out_s, cds->conn_year);
|
||||||
|
out_uint8(c->out_s, cds->conn_month);
|
||||||
|
out_uint8(c->out_s, cds->conn_day);
|
||||||
|
out_uint8(c->out_s, cds->conn_hour);
|
||||||
|
out_uint8(c->out_s, cds->conn_minute);
|
||||||
|
out_uint8(c->out_s, cds->addr_type);
|
||||||
|
size += 7;
|
||||||
|
|
||||||
|
if (cds->addr_type == SCP_ADDRESS_TYPE_IPV4)
|
||||||
|
{
|
||||||
|
in_uint32_be(c->out_s, cds->ipv4addr);
|
||||||
|
size += 4;
|
||||||
|
}
|
||||||
|
else if (cds->addr_type == SCP_ADDRESS_TYPE_IPV6)
|
||||||
|
{
|
||||||
|
in_uint8a(c->out_s, cds->ipv6addr, 16);
|
||||||
|
size += 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s_pop_layer(c->out_s, channel_hdr);
|
||||||
|
out_uint32_be(c->out_s, version);
|
||||||
|
out_uint32_be(c->out_s, size);
|
||||||
|
|
||||||
|
if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s_pop_layer(c->out_s, channel_hdr);
|
return _scp_v1s_mng_check_response(c, s);
|
||||||
out_uint32_be(c->out_s, version);
|
|
||||||
out_uint32_be(c->out_s, size);
|
|
||||||
|
|
||||||
if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, size))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return _scp_v1s_mng_check_response(c, s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum SCP_SERVER_STATES_E
|
static enum SCP_SERVER_STATES_E
|
||||||
_scp_v1s_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
_scp_v1s_mng_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
|
||||||
{
|
{
|
||||||
tui32 version;
|
tui32 version;
|
||||||
tui32 size;
|
tui32 size;
|
||||||
tui16 cmd;
|
tui16 cmd;
|
||||||
// tui8 dim;
|
// tui8 dim;
|
||||||
// char buf[257];
|
// char buf[257];
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
init_stream(c->in_s, c->in_s->size);
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, version);
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
||||||
if (version != 1)
|
{
|
||||||
{
|
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__);
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: version error", __LINE__);
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
return SCP_SERVER_STATE_VERSION_ERR;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
in_uint32_be(c->in_s, size);
|
in_uint32_be(c->in_s, version);
|
||||||
|
|
||||||
init_stream(c->in_s, c->in_s->size);
|
if (version != 1)
|
||||||
/* read the rest of the packet */
|
{
|
||||||
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: version error", __LINE__);
|
||||||
{
|
return SCP_SERVER_STATE_VERSION_ERR;
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__);
|
}
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
|
||||||
}
|
in_uint32_be(c->in_s, size);
|
||||||
|
|
||||||
|
init_stream(c->in_s, c->in_s->size);
|
||||||
|
|
||||||
|
/* read the rest of the packet */
|
||||||
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd != SCP_COMMAND_SET_MANAGE)
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: sequence error", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_SEQUENCE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_uint16_be(c->in_s, cmd);
|
||||||
|
|
||||||
|
if (cmd == SCP_CMD_MNG_LIST_REQ) /* request session list */
|
||||||
|
{
|
||||||
|
log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] request session list", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_MNG_LISTREQ;
|
||||||
|
}
|
||||||
|
else if (cmd == SCP_CMD_MNG_ACTION) /* execute an action */
|
||||||
|
{
|
||||||
|
/*in_uint8(c->in_s, dim);
|
||||||
|
buf[dim]='\0';
|
||||||
|
in_uint8a(c->in_s, buf, dim);
|
||||||
|
scp_session_set_errstr(s, buf);*/
|
||||||
|
|
||||||
|
log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] action request", __LINE__);
|
||||||
|
return SCP_SERVER_STATE_MNG_ACTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* else if (cmd == 20) / * password change * /
|
||||||
|
{
|
||||||
|
in_uint16_be(c->in_s, s->display);
|
||||||
|
|
||||||
|
return SCP_SERVER_STATE_OK;
|
||||||
|
}
|
||||||
|
else if (cmd == 40) / * session list * /
|
||||||
|
{
|
||||||
|
return SCP_SERVER_STATE_SESSION_LIST;
|
||||||
|
}*/
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
|
||||||
if (cmd != SCP_COMMAND_SET_MANAGE)
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: sequence error", __LINE__);
|
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: sequence error", __LINE__);
|
||||||
return SCP_SERVER_STATE_SEQUENCE_ERR;
|
return SCP_SERVER_STATE_SEQUENCE_ERR;
|
||||||
}
|
|
||||||
|
|
||||||
in_uint16_be(c->in_s, cmd);
|
|
||||||
if (cmd == SCP_CMD_MNG_LIST_REQ) /* request session list */
|
|
||||||
{
|
|
||||||
log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] request session list", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_MNG_LISTREQ;
|
|
||||||
}
|
|
||||||
else if (cmd == SCP_CMD_MNG_ACTION) /* execute an action */
|
|
||||||
{
|
|
||||||
/*in_uint8(c->in_s, dim);
|
|
||||||
buf[dim]='\0';
|
|
||||||
in_uint8a(c->in_s, buf, dim);
|
|
||||||
scp_session_set_errstr(s, buf);*/
|
|
||||||
|
|
||||||
log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] action request", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_MNG_ACTION;
|
|
||||||
}
|
|
||||||
/* else if (cmd == 20) / * password change * /
|
|
||||||
{
|
|
||||||
in_uint16_be(c->in_s, s->display);
|
|
||||||
|
|
||||||
return SCP_SERVER_STATE_OK;
|
|
||||||
}
|
|
||||||
else if (cmd == 40) / * session list * /
|
|
||||||
{
|
|
||||||
return SCP_SERVER_STATE_SESSION_LIST;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: sequence error", __LINE__);
|
|
||||||
return SCP_SERVER_STATE_SEQUENCE_ERR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
+34
-35
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -28,26 +27,26 @@
|
|||||||
#include "libscp_vX.h"
|
#include "libscp_vX.h"
|
||||||
|
|
||||||
/* server API */
|
/* server API */
|
||||||
enum SCP_SERVER_STATES_E scp_vXs_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s)
|
enum SCP_SERVER_STATES_E scp_vXs_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s)
|
||||||
{
|
{
|
||||||
tui32 version;
|
tui32 version;
|
||||||
|
|
||||||
/* reading version and packet size */
|
/* reading version and packet size */
|
||||||
if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
|
||||||
{
|
{
|
||||||
return SCP_SERVER_STATE_NETWORK_ERR;
|
return SCP_SERVER_STATE_NETWORK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_uint32_be(c->in_s, version);
|
in_uint32_be(c->in_s, version);
|
||||||
|
|
||||||
if (version == 0)
|
if (version == 0)
|
||||||
{
|
{
|
||||||
return scp_v0s_accept(c, s, 1);
|
return scp_v0s_accept(c, s, 1);
|
||||||
}
|
}
|
||||||
else if (version == 1)
|
else if (version == 1)
|
||||||
{
|
{
|
||||||
return scp_v1s_accept(c, s, 1);
|
return scp_v1s_accept(c, s, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SCP_SERVER_STATE_VERSION_ERR;
|
return SCP_SERVER_STATE_VERSION_ERR;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-18
@@ -1,21 +1,20 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
it under the terms of the GNU General Public License as published by
|
*
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Copyright (C) Jay Sorg 2004-2012
|
||||||
(at your option) any later version.
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
This program is distributed in the hope that it will be useful,
|
* you may not use this file except in compliance with the License.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* You may obtain a copy of the License at
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
along with this program; if not, write to the Free Software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
xrdp: A Remote Desktop Protocol server.
|
* limitations under the License.
|
||||||
Copyright (C) Jay Sorg 2005-2010
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user