Merge branch 'master' of git://github.com/FreeRDP/xrdp
This commit is contained in:
commit
b86a80aca6
482
COPYING
482
COPYING
@ -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.
|
|
||||||
|
BIN
Coding_Style.odt
Normal file
BIN
Coding_Style.odt
Normal file
Binary file not shown.
@ -6,6 +6,12 @@ else
|
|||||||
FREERDPDIR =
|
FREERDPDIR =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if XRDP_XRDPVR
|
||||||
|
XRDPVRDIR = xrdpvr
|
||||||
|
else
|
||||||
|
XRDPVRDIR =
|
||||||
|
endif
|
||||||
|
|
||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
common \
|
common \
|
||||||
vnc \
|
vnc \
|
||||||
@ -20,4 +26,5 @@ SUBDIRS = \
|
|||||||
docs \
|
docs \
|
||||||
instfiles \
|
instfiles \
|
||||||
genkeymap \
|
genkeymap \
|
||||||
xrdpapi
|
xrdpapi \
|
||||||
|
$(XRDPVRDIR)
|
||||||
|
59
astyle_config.as
Normal file
59
astyle_config.as
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
|
||||||
|
# detached brackets
|
||||||
|
--style=allman
|
||||||
|
|
||||||
|
# 4 spaces, no tabs
|
||||||
|
--indent=spaces=4
|
||||||
|
|
||||||
|
# for C++ files only
|
||||||
|
--indent-classes
|
||||||
|
|
||||||
|
# Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block.
|
||||||
|
# The entire case block is indented.
|
||||||
|
--indent-switches
|
||||||
|
|
||||||
|
# Add extra indentation to namespace blocks. This option has no effect on Java files.
|
||||||
|
--indent-namespaces
|
||||||
|
|
||||||
|
# Converts tabs into spaces in the non-indentation part of the line.
|
||||||
|
--convert-tabs
|
||||||
|
|
||||||
|
# requires --convert-tabs to work properly
|
||||||
|
--indent-preprocessor
|
||||||
|
|
||||||
|
--indent-col1-comments
|
||||||
|
|
||||||
|
--min-conditional-indent=2
|
||||||
|
|
||||||
|
--max-instatement-indent=40
|
||||||
|
|
||||||
|
# Pad empty lines around header blocks (e.g. 'if', 'for', 'while'...).
|
||||||
|
--break-blocks
|
||||||
|
|
||||||
|
# Insert space padding around operators.
|
||||||
|
--pad-oper
|
||||||
|
|
||||||
|
# Insert space padding after paren headers only (e.g. 'if', 'for', 'while'...).
|
||||||
|
--pad-header
|
||||||
|
|
||||||
|
|
||||||
|
# Add brackets to unbracketed one line conditional statements (e.g. 'if', 'for', 'while'...).
|
||||||
|
--add-brackets
|
||||||
|
|
||||||
|
--align-pointer=name
|
||||||
|
|
||||||
|
# Do not retain a backup of the original file. The original file is purged after it is formatted.
|
||||||
|
--suffix=none
|
||||||
|
|
||||||
|
# For each directory in the command line, process all subdirectories recursively.
|
||||||
|
--recursive
|
||||||
|
|
||||||
|
# Preserve the original file's date and time modified.
|
||||||
|
--preserve-date
|
||||||
|
|
||||||
|
# Formatted files display mode. Display only the files that have been formatted.
|
||||||
|
# Do not display files that are unchanged.
|
||||||
|
--formatted
|
||||||
|
|
||||||
|
--lineend=linux
|
||||||
|
|
@ -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
|
||||||
|
732
common/d3des.c
732
common/d3des.c
@ -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
|
||||||
*
|
*
|
||||||
|
@ -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
|
||||||
|
564
common/file.c
564
common/file.c
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
289
common/list.c
289
common/list.c
@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
909
common/log.c
909
common/log.c
File diff suppressed because it is too large
Load Diff
39
common/log.h
39
common/log.h
@ -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
|
||||||
|
2983
common/os_calls.c
2983
common/os_calls.c
File diff suppressed because it is too large
Load Diff
@ -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
|
||||||
@ -137,6 +133,9 @@ g_memcmp(const void* s1, const void* s2, int len);
|
|||||||
int APP_CC
|
int APP_CC
|
||||||
g_file_open(const char* file_name);
|
g_file_open(const char* file_name);
|
||||||
int APP_CC
|
int APP_CC
|
||||||
|
g_file_open_ex(const char *file_name, int aread, int awrite,
|
||||||
|
int acreate, int atrunc);
|
||||||
|
int APP_CC
|
||||||
g_file_close(int fd);
|
g_file_close(int fd);
|
||||||
int APP_CC
|
int APP_CC
|
||||||
g_file_read(int fd, char* ptr, int len);
|
g_file_read(int fd, char* ptr, int len);
|
||||||
@ -241,6 +240,8 @@ g_initgroups(const char* user, int gid);
|
|||||||
int APP_CC
|
int APP_CC
|
||||||
g_getuid(void);
|
g_getuid(void);
|
||||||
int APP_CC
|
int APP_CC
|
||||||
|
g_getgid(void);
|
||||||
|
int APP_CC
|
||||||
g_setuid(int pid);
|
g_setuid(int pid);
|
||||||
int APP_CC
|
int APP_CC
|
||||||
g_waitchild(void);
|
g_waitchild(void);
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
727
common/trans.c
727
common/trans.c
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
17
configure.ac
17
configure.ac
@ -43,6 +43,14 @@ AC_ARG_ENABLE(simplesound, AS_HELP_STRING([--enable-simplesound],
|
|||||||
[Build simple pulse audio interface (default: no)]),
|
[Build simple pulse audio interface (default: no)]),
|
||||||
[simplesound=true], [simplesound=false])
|
[simplesound=true], [simplesound=false])
|
||||||
AM_CONDITIONAL(XRDP_SIMPLESOUND, [test x$simplesound = xtrue])
|
AM_CONDITIONAL(XRDP_SIMPLESOUND, [test x$simplesound = xtrue])
|
||||||
|
AC_ARG_ENABLE(fuse, AS_HELP_STRING([--enable-fuse],
|
||||||
|
[Build fuse(clipboard file / drive redir) (default: no)]),
|
||||||
|
[fuse=true], [fuse=false])
|
||||||
|
AM_CONDITIONAL(XRDP_FUSE, [test x$fuse = xtrue])
|
||||||
|
AC_ARG_ENABLE(xrdpvr, AS_HELP_STRING([--enable-xrdpvr],
|
||||||
|
[Build xrdpvr module (default: no)]),
|
||||||
|
[xrdpvr=true], [xrdpvr=false])
|
||||||
|
AM_CONDITIONAL(XRDP_XRDPVR, [test x$xrdpvr = xtrue])
|
||||||
|
|
||||||
AM_CONDITIONAL(GOT_PREFIX, test "x${prefix}" != "xNONE"])
|
AM_CONDITIONAL(GOT_PREFIX, test "x${prefix}" != "xNONE"])
|
||||||
|
|
||||||
@ -70,6 +78,14 @@ then
|
|||||||
[AC_MSG_ERROR([please install libjpeg-dev or libjpeg-devel])])
|
[AC_MSG_ERROR([please install libjpeg-dev or libjpeg-devel])])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# checking for fuse
|
||||||
|
if ! test -z "$enable_fuse"
|
||||||
|
then
|
||||||
|
AC_CHECK_HEADER([fuse.h], [],
|
||||||
|
[AC_MSG_ERROR([please install libfuse-dev or fuse-devel])],
|
||||||
|
[#define _FILE_OFFSET_BITS 64])
|
||||||
|
fi
|
||||||
|
|
||||||
# checking for libpulse libpulse-simple
|
# checking for libpulse libpulse-simple
|
||||||
if ! test -z "$enable_simplesound"
|
if ! test -z "$enable_simplesound"
|
||||||
then
|
then
|
||||||
@ -110,6 +126,7 @@ AC_CONFIG_FILES([Makefile
|
|||||||
instfiles/pam.d/Makefile
|
instfiles/pam.d/Makefile
|
||||||
genkeymap/Makefile
|
genkeymap/Makefile
|
||||||
xrdpapi/Makefile
|
xrdpapi/Makefile
|
||||||
|
xrdpvr/Makefile
|
||||||
])
|
])
|
||||||
# fontdump/Makefile
|
# fontdump/Makefile
|
||||||
# xrdp/cursors/Makefile
|
# xrdp/cursors/Makefile
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* 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"
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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;
|
|
||||||
}
|
}
|
||||||
|
742
keygen/keygen.c
742
keygen/keygen.c
@ -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;
|
|
||||||
}
|
}
|
||||||
|
1295
libxrdp/libxrdp.c
1295
libxrdp/libxrdp.c
File diff suppressed because it is too large
Load Diff
@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* 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
|
||||||
|
@ -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
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,24 +1,22 @@
|
|||||||
/*
|
/**
|
||||||
This program is free software; you can redistribute it and/or modify
|
* 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;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
1301
libxrdp/xrdp_mcs.c
1301
libxrdp/xrdp_mcs.c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2595
libxrdp/xrdp_rdp.c
2595
libxrdp/xrdp_rdp.c
File diff suppressed because it is too large
Load Diff
1799
libxrdp/xrdp_sec.c
1799
libxrdp/xrdp_sec.c
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
125
mc/mc.c
125
mc/mc.c
@ -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;
|
|
||||||
}
|
}
|
||||||
|
40
mc/mc.h
40
mc/mc.h
@ -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"
|
||||||
|
569
rdp/rdp.c
569
rdp/rdp.c
@ -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;
|
||||||
}
|
}
|
||||||
|
42
rdp/rdp.h
42
rdp/rdp.h
@ -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"
|
||||||
@ -269,7 +267,7 @@ struct mod
|
|||||||
int (*mod_get_wait_objs)(struct mod* v, tbus* read_objs, int* rcount,
|
int (*mod_get_wait_objs)(struct mod* v, tbus* read_objs, int* rcount,
|
||||||
tbus* write_objs, int* wcount, int* timeout);
|
tbus* write_objs, int* wcount, int* timeout);
|
||||||
int (*mod_check_wait_objs)(struct mod* v);
|
int (*mod_check_wait_objs)(struct mod* v);
|
||||||
long mod_dumby[100 - 9]; /* align, 100 minus the number of mod
|
long mod_dumby[100 - 9]; /* align, 100 minus the number of mod
|
||||||
functions above */
|
functions above */
|
||||||
/* server functions */
|
/* server functions */
|
||||||
int (*server_begin_update)(struct mod* v);
|
int (*server_begin_update)(struct mod* v);
|
||||||
|
1735
rdp/rdp_bitmap.c
1735
rdp/rdp_bitmap.c
File diff suppressed because it is too large
Load Diff
348
rdp/rdp_iso.c
348
rdp/rdp_iso.c
@ -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;
|
|
||||||
}
|
}
|
||||||
|
559
rdp/rdp_lic.c
559
rdp/rdp_lic.c
@ -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); */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
1120
rdp/rdp_mcs.c
1120
rdp/rdp_mcs.c
File diff suppressed because it is too large
Load Diff
2748
rdp/rdp_orders.c
2748
rdp/rdp_orders.c
File diff suppressed because it is too large
Load Diff
1730
rdp/rdp_rdp.c
1730
rdp/rdp_rdp.c
File diff suppressed because it is too large
Load Diff
1066
rdp/rdp_sec.c
1066
rdp/rdp_sec.c
File diff suppressed because it is too large
Load Diff
282
rdp/rdp_tcp.c
282
rdp/rdp_tcp.c
@ -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;
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
205
sesman/access.c
205
sesman/access.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
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -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;
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -10,6 +10,11 @@ EXTRA_DEFINES += -DXRDP_SIMPLESOUND
|
|||||||
EXTRA_LIBS += -lpthread -lpulse -lpulse-simple
|
EXTRA_LIBS += -lpthread -lpulse -lpulse-simple
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if XRDP_FUSE
|
||||||
|
EXTRA_DEFINES += -DXRDP_FUSE
|
||||||
|
EXTRA_LIBS += -lfuse
|
||||||
|
endif
|
||||||
|
|
||||||
AM_CFLAGS = \
|
AM_CFLAGS = \
|
||||||
-DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \
|
-DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \
|
||||||
-DXRDP_SBIN_PATH=\"${sbindir}\" \
|
-DXRDP_SBIN_PATH=\"${sbindir}\" \
|
||||||
@ -28,10 +33,12 @@ xrdp_chansrv_SOURCES = \
|
|||||||
chansrv.c \
|
chansrv.c \
|
||||||
sound.c \
|
sound.c \
|
||||||
clipboard.c \
|
clipboard.c \
|
||||||
|
clipboard_file.c \
|
||||||
devredir.c \
|
devredir.c \
|
||||||
rail.c \
|
rail.c \
|
||||||
xcommon.c \
|
xcommon.c \
|
||||||
drdynvc.c
|
drdynvc.c \
|
||||||
|
chansrv_fuse.c
|
||||||
|
|
||||||
xrdp_chansrv_LDFLAGS = \
|
xrdp_chansrv_LDFLAGS = \
|
||||||
$(EXTRA_FLAGS)
|
$(EXTRA_FLAGS)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,7 @@
|
|||||||
* xrdp: A Remote Desktop Protocol server.
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
*
|
*
|
||||||
* Copyright (C) Jay Sorg 2009-2012
|
* Copyright (C) Jay Sorg 2009-2012
|
||||||
|
* Copyright (C) Laxmikant Rashinkar 2009-2012
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -23,56 +24,72 @@
|
|||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
#define MAX_DVC_CHANNELS 32
|
||||||
|
|
||||||
struct chan_out_data
|
struct chan_out_data
|
||||||
{
|
{
|
||||||
struct stream* s;
|
struct stream *s;
|
||||||
struct chan_out_data* next;
|
struct chan_out_data *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct chan_item
|
struct chan_item
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
int flags;
|
int flags;
|
||||||
char name[16];
|
char name[16];
|
||||||
struct chan_out_data* head;
|
struct chan_out_data *head;
|
||||||
struct chan_out_data* tail;
|
struct chan_out_data *tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
int APP_CC
|
/* data in struct trans::callback_data */
|
||||||
send_channel_data(int chan_id, char* data, int size);
|
struct xrdp_api_data
|
||||||
int APP_CC
|
{
|
||||||
main_cleanup(void);
|
int chan_id;
|
||||||
|
char header[64];
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
/* for dynamic virtual channels */
|
||||||
|
struct trans *transp;
|
||||||
|
int dvc_chan_id;
|
||||||
|
int is_connected;
|
||||||
|
};
|
||||||
|
|
||||||
|
int APP_CC send_channel_data(int chan_id, char *data, int size);
|
||||||
|
int APP_CC main_cleanup(void);
|
||||||
|
int APP_CC find_empty_slot_in_dvc_channels();
|
||||||
|
struct xrdp_api_data *APP_CC struct_from_dvc_chan_id(tui32 dvc_chan_id);
|
||||||
|
int remove_struct_with_chan_id(tui32 dvc_chan_id);
|
||||||
|
|
||||||
#define LOG_LEVEL 5
|
#define LOG_LEVEL 5
|
||||||
|
|
||||||
#define LOG(_a, _params) \
|
#define LOG(_a, _params) \
|
||||||
{ \
|
{ \
|
||||||
if (_a < LOG_LEVEL) \
|
if (_a < LOG_LEVEL) \
|
||||||
{ \
|
{ \
|
||||||
g_write("xrdp-chansrv [%10.10u]: ", g_time3()); \
|
g_write("xrdp-chansrv [%10.10u]: ", g_time3()); \
|
||||||
g_writeln _params ; \
|
g_writeln _params ; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOGM(_args) do { log_message _args ; } while (0)
|
#define LOGM(_args) do { log_message _args ; } while (0)
|
||||||
|
|
||||||
#ifndef GSET_UINT8
|
#ifndef GSET_UINT8
|
||||||
#define GSET_UINT8(_ptr, _offset, _data) \
|
#define GSET_UINT8(_ptr, _offset, _data) \
|
||||||
*((unsigned char*) (((unsigned char*)(_ptr)) + (_offset))) = (unsigned char)(_data)
|
*((unsigned char*) (((unsigned char*)(_ptr)) + (_offset))) = (unsigned char)(_data)
|
||||||
#define GGET_UINT8(_ptr, _offset) \
|
#define GGET_UINT8(_ptr, _offset) \
|
||||||
(*((unsigned char*) (((unsigned char*)(_ptr)) + (_offset))))
|
(*((unsigned char*) (((unsigned char*)(_ptr)) + (_offset))))
|
||||||
#define GSET_UINT16(_ptr, _offset, _data) \
|
#define GSET_UINT16(_ptr, _offset, _data) \
|
||||||
GSET_UINT8(_ptr, _offset, _data); \
|
GSET_UINT8(_ptr, _offset, _data); \
|
||||||
GSET_UINT8(_ptr, (_offset) + 1, (_data) >> 8)
|
GSET_UINT8(_ptr, (_offset) + 1, (_data) >> 8)
|
||||||
#define GGET_UINT16(_ptr, _offset) \
|
#define GGET_UINT16(_ptr, _offset) \
|
||||||
(GGET_UINT8(_ptr, _offset)) | \
|
(GGET_UINT8(_ptr, _offset)) | \
|
||||||
((GGET_UINT8(_ptr, (_offset) + 1)) << 8)
|
((GGET_UINT8(_ptr, (_offset) + 1)) << 8)
|
||||||
#define GSET_UINT32(_ptr, _offset, _data) \
|
#define GSET_UINT32(_ptr, _offset, _data) \
|
||||||
GSET_UINT16(_ptr, _offset, _data); \
|
GSET_UINT16(_ptr, _offset, _data); \
|
||||||
GSET_UINT16(_ptr, (_offset) + 2, (_data) >> 16)
|
GSET_UINT16(_ptr, (_offset) + 2, (_data) >> 16)
|
||||||
#define GGET_UINT32(_ptr, _offset) \
|
#define GGET_UINT32(_ptr, _offset) \
|
||||||
(GGET_UINT16(_ptr, _offset)) | \
|
(GGET_UINT16(_ptr, _offset)) | \
|
||||||
((GGET_UINT16(_ptr, (_offset) + 2)) << 16)
|
((GGET_UINT16(_ptr, (_offset) + 2)) << 16)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
715
sesman/chansrv/chansrv_fuse.c
Normal file
715
sesman/chansrv/chansrv_fuse.c
Normal file
@ -0,0 +1,715 @@
|
|||||||
|
/**
|
||||||
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
|
* Copyright (C) Jay Sorg 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef XRDP_FUSE
|
||||||
|
|
||||||
|
#define FUSE_USE_VERSION 26
|
||||||
|
#define _FILE_OFFSET_BITS 64
|
||||||
|
|
||||||
|
#include <fuse/fuse_lowlevel.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "arch.h"
|
||||||
|
#include "parse.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "os_calls.h"
|
||||||
|
#include "chansrv.h"
|
||||||
|
#include "chansrv_fuse.h"
|
||||||
|
#include "clipboard_file.h"
|
||||||
|
|
||||||
|
#define LLOG_LEVEL 1
|
||||||
|
#define LLOGLN(_level, _args) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
if (_level < LLOG_LEVEL) \
|
||||||
|
{ \
|
||||||
|
g_write("chansrv:fuse [%10.10u]: ", g_time3()); \
|
||||||
|
g_writeln _args ; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
|
char g_fuse_root_path[256] = "";
|
||||||
|
|
||||||
|
static struct fuse_chan *g_ch = 0;
|
||||||
|
static struct fuse_session *g_se = 0;
|
||||||
|
static char *g_mountpoint = 0;
|
||||||
|
static tintptr g_bufsize = 0;
|
||||||
|
static char *g_buffer = 0;
|
||||||
|
static int g_fd = 0;
|
||||||
|
static time_t g_time = 0;
|
||||||
|
static int g_uid = 0;
|
||||||
|
static int g_gid = 0;
|
||||||
|
|
||||||
|
/* used for file data request sent to client */
|
||||||
|
struct req_list_item
|
||||||
|
{
|
||||||
|
fuse_req_t req;
|
||||||
|
int stream_id;
|
||||||
|
int lindex;
|
||||||
|
int off;
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
static struct list *g_req_list = 0;
|
||||||
|
|
||||||
|
struct dirbuf
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
int size;
|
||||||
|
int alloc_bytes;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct xfuse_file_info
|
||||||
|
{
|
||||||
|
int ino;
|
||||||
|
int lindex;
|
||||||
|
char pathname[256];
|
||||||
|
char filename[256];
|
||||||
|
int flags;
|
||||||
|
int size;
|
||||||
|
tui64 time;
|
||||||
|
struct xfuse_file_info* child;
|
||||||
|
struct xfuse_file_info* parent;
|
||||||
|
struct xfuse_file_info* next;
|
||||||
|
struct xfuse_file_info* prev;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct xfuse_file_info *g_fuse_files = 0;
|
||||||
|
static struct fuse_lowlevel_ops g_xrdp_ll_oper;
|
||||||
|
static int g_ino = 2;
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static struct xfuse_file_info *APP_CC
|
||||||
|
fuse_find_file_info_by_name(struct xfuse_file_info *ffi, const char *filename)
|
||||||
|
{
|
||||||
|
struct xfuse_file_info *rv;
|
||||||
|
struct xfuse_file_info *rv1;
|
||||||
|
|
||||||
|
rv = ffi;
|
||||||
|
while (rv != 0)
|
||||||
|
{
|
||||||
|
if (g_strcmp(rv->filename, filename) == 0)
|
||||||
|
{
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
if (rv->flags & 1)
|
||||||
|
{
|
||||||
|
rv1 = fuse_find_file_info_by_name(rv->child, filename);
|
||||||
|
if (rv1 != 0)
|
||||||
|
{
|
||||||
|
return rv1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rv = rv->next;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static struct xfuse_file_info *APP_CC
|
||||||
|
fuse_find_file_info_by_ino(struct xfuse_file_info *ffi, int ino)
|
||||||
|
{
|
||||||
|
struct xfuse_file_info *rv;
|
||||||
|
struct xfuse_file_info *rv1;
|
||||||
|
|
||||||
|
rv = ffi;
|
||||||
|
while (rv != 0)
|
||||||
|
{
|
||||||
|
if (rv->ino == ino)
|
||||||
|
{
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
if (rv->flags & 1)
|
||||||
|
{
|
||||||
|
rv1 = fuse_find_file_info_by_ino(rv->child, ino);
|
||||||
|
if (rv1 != 0)
|
||||||
|
{
|
||||||
|
return rv1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rv = rv->next;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
xrdp_ffi2stat(struct xfuse_file_info *ffi, struct stat *stbuf)
|
||||||
|
{
|
||||||
|
stbuf->st_ino = ffi->ino;
|
||||||
|
if (ffi->flags & 1)
|
||||||
|
{
|
||||||
|
stbuf->st_mode = S_IFDIR | 0755;
|
||||||
|
stbuf->st_nlink = 2;
|
||||||
|
stbuf->st_uid = g_uid;
|
||||||
|
stbuf->st_gid = g_gid;
|
||||||
|
stbuf->st_atime = g_time;
|
||||||
|
stbuf->st_mtime = g_time;
|
||||||
|
stbuf->st_ctime = g_time;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stbuf->st_mode = S_IFREG | 0664;
|
||||||
|
stbuf->st_nlink = 1;
|
||||||
|
stbuf->st_size = ffi->size;
|
||||||
|
stbuf->st_uid = g_uid;
|
||||||
|
stbuf->st_gid = g_gid;
|
||||||
|
stbuf->st_atime = g_time;
|
||||||
|
stbuf->st_mtime = g_time;
|
||||||
|
stbuf->st_ctime = g_time;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static void DEFAULT_CC
|
||||||
|
xrdp_ll_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
|
||||||
|
{
|
||||||
|
struct xfuse_file_info *ffi;
|
||||||
|
struct fuse_entry_param e;
|
||||||
|
|
||||||
|
LLOGLN(10, ("xrdp_ll_lookup: name %s", name));
|
||||||
|
if (parent != 1)
|
||||||
|
{
|
||||||
|
fuse_reply_err(req, ENOENT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ffi = fuse_find_file_info_by_name(g_fuse_files, name);
|
||||||
|
if (ffi != 0)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("xrdp_ll_lookup: name %s ino %d", name, ffi->ino));
|
||||||
|
g_memset(&e, 0, sizeof(e));
|
||||||
|
e.ino = ffi->ino;
|
||||||
|
e.attr_timeout = 1.0;
|
||||||
|
e.entry_timeout = 1.0;
|
||||||
|
xrdp_ffi2stat(ffi, &e.attr);
|
||||||
|
fuse_reply_entry(req, &e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fuse_reply_err(req, ENOENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static void DEFAULT_CC
|
||||||
|
xrdp_ll_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
|
||||||
|
{
|
||||||
|
struct stat stbuf;
|
||||||
|
struct xfuse_file_info *ffi;
|
||||||
|
|
||||||
|
LLOGLN(10, ("xrdp_ll_getattr: ino %d", ino));
|
||||||
|
g_memset(&stbuf, 0, sizeof(stbuf));
|
||||||
|
if (ino == 1)
|
||||||
|
{
|
||||||
|
stbuf.st_mode = S_IFDIR | 0755;
|
||||||
|
stbuf.st_nlink = 2;
|
||||||
|
stbuf.st_uid = g_uid;
|
||||||
|
stbuf.st_gid = g_gid;
|
||||||
|
stbuf.st_atime = g_time;
|
||||||
|
stbuf.st_mtime = g_time;
|
||||||
|
stbuf.st_ctime = g_time;
|
||||||
|
fuse_reply_attr(req, &stbuf, 1.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ffi = fuse_find_file_info_by_ino(g_fuse_files, ino);
|
||||||
|
if (ffi == 0)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("xrdp_ll_getattr: fuse_find_file_info_by_ino failed ino %d", ino));
|
||||||
|
fuse_reply_err(req, ENOENT);
|
||||||
|
}
|
||||||
|
else if (xrdp_ffi2stat(ffi, &stbuf) == -1)
|
||||||
|
{
|
||||||
|
fuse_reply_err(req, ENOENT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fuse_reply_attr(req, &stbuf, 1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static void APP_CC
|
||||||
|
dirbuf_add(fuse_req_t req, struct dirbuf *b, const char *name, fuse_ino_t ino)
|
||||||
|
{
|
||||||
|
struct stat stbuf;
|
||||||
|
char *newp;
|
||||||
|
int oldsize;
|
||||||
|
|
||||||
|
oldsize = b->size;
|
||||||
|
b->size += fuse_add_direntry(req, 0, 0, name, 0, 0);
|
||||||
|
LLOGLN(10, ("1 %d %d %d", b->alloc_bytes, b->size, oldsize));
|
||||||
|
if (b->size > b->alloc_bytes)
|
||||||
|
{
|
||||||
|
b->alloc_bytes = (b->size + 1023) & (~1023);
|
||||||
|
LLOGLN(10, ("2 %d %d %d", b->alloc_bytes, b->size, oldsize));
|
||||||
|
newp = g_malloc(b->alloc_bytes, 0);
|
||||||
|
g_memcpy(newp, b->p, oldsize);
|
||||||
|
g_free(b->p);
|
||||||
|
b->p = newp;
|
||||||
|
}
|
||||||
|
g_memset(&stbuf, 0, sizeof(stbuf));
|
||||||
|
stbuf.st_ino = ino;
|
||||||
|
fuse_add_direntry(req, b->p + oldsize, b->size - oldsize, name,
|
||||||
|
&stbuf, b->size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define lmin(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
reply_buf_limited(fuse_req_t req, const char *buf, size_t bufsize,
|
||||||
|
off_t off, size_t maxsize)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("reply_buf_limited: %d", maxsize));
|
||||||
|
if (off < bufsize)
|
||||||
|
{
|
||||||
|
return fuse_reply_buf(req, buf + off,
|
||||||
|
lmin(bufsize - off, maxsize));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return fuse_reply_buf(req, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static void DEFAULT_CC
|
||||||
|
xrdp_ll_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
|
||||||
|
off_t off, struct fuse_file_info *fi)
|
||||||
|
{
|
||||||
|
struct xfuse_file_info *ffi;
|
||||||
|
struct dirbuf b;
|
||||||
|
|
||||||
|
LLOGLN(10, ("xrdp_ll_readdir: ino %d", ino));
|
||||||
|
if (ino != 1)
|
||||||
|
{
|
||||||
|
fuse_reply_err(req, ENOTDIR);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ffi = g_fuse_files;
|
||||||
|
g_memset(&b, 0, sizeof(b));
|
||||||
|
dirbuf_add(req, &b, ".", 1);
|
||||||
|
dirbuf_add(req, &b, "..", 1);
|
||||||
|
while (ffi != 0)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("xrdp_ll_readdir: %s", ffi->filename));
|
||||||
|
dirbuf_add(req, &b, ffi->filename, ffi->ino);
|
||||||
|
ffi = ffi->next;
|
||||||
|
}
|
||||||
|
reply_buf_limited(req, b.p, b.size, off, size);
|
||||||
|
g_free(b.p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static void DEFAULT_CC
|
||||||
|
xrdp_ll_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("xrdp_ll_open: ino %d", (int)ino));
|
||||||
|
if (ino == 1)
|
||||||
|
{
|
||||||
|
fuse_reply_err(req, EISDIR);
|
||||||
|
}
|
||||||
|
else if ((fi->flags & 3) != O_RDONLY)
|
||||||
|
{
|
||||||
|
fuse_reply_err(req, EACCES);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fuse_reply_open(req, fi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static void DEFAULT_CC
|
||||||
|
xrdp_ll_read(fuse_req_t req, fuse_ino_t ino, size_t size,
|
||||||
|
off_t off, struct fuse_file_info *fi)
|
||||||
|
{
|
||||||
|
char *data;
|
||||||
|
int stream_id;
|
||||||
|
struct xfuse_file_info *ffi;
|
||||||
|
struct req_list_item *rli;
|
||||||
|
|
||||||
|
LLOGLN(10, ("xrdp_ll_read: %d %d %d", (int)ino, (int)off, (int)size));
|
||||||
|
ffi = fuse_find_file_info_by_ino(g_fuse_files, ino);
|
||||||
|
if (ffi != 0)
|
||||||
|
{
|
||||||
|
/* reply later */
|
||||||
|
stream_id = 0;
|
||||||
|
rli = (struct req_list_item *)
|
||||||
|
g_malloc(sizeof(struct req_list_item), 1);
|
||||||
|
rli->req = req;
|
||||||
|
rli->stream_id = stream_id;
|
||||||
|
rli->lindex = ffi->lindex;
|
||||||
|
rli->off = off;
|
||||||
|
rli->size = size;
|
||||||
|
list_add_item(g_req_list, (tbus)rli);
|
||||||
|
if (g_req_list->count == 1)
|
||||||
|
{
|
||||||
|
clipboard_request_file_data(rli->stream_id, rli->lindex,
|
||||||
|
rli->off, rli->size);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LLOGLN(0, ("xrdp_ll_read: fuse_find_file_info_by_ino failed ino %d", (int)ino));
|
||||||
|
data = (char *)g_malloc(size, 1);
|
||||||
|
fuse_reply_buf(req, data, size);
|
||||||
|
g_free(data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* returns error */
|
||||||
|
static int APP_CC
|
||||||
|
fuse_init_lib(int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
|
||||||
|
int error;
|
||||||
|
|
||||||
|
error = fuse_parse_cmdline(&args, &g_mountpoint, 0, 0);
|
||||||
|
if (error == -1)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("fuse_init_lib: fuse_parse_cmdline failed"));
|
||||||
|
fuse_opt_free_args(&args);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
g_ch = fuse_mount(g_mountpoint, &args);
|
||||||
|
if (g_ch == 0)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("fuse_init_lib: fuse_mount failed"));
|
||||||
|
fuse_opt_free_args(&args);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
g_se = fuse_lowlevel_new(&args, &g_xrdp_ll_oper,
|
||||||
|
sizeof(g_xrdp_ll_oper), 0);
|
||||||
|
if (g_se == 0)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("fuse_init_lib: fuse_lowlevel_new failed"));
|
||||||
|
fuse_unmount(g_mountpoint, g_ch);
|
||||||
|
g_ch = 0;
|
||||||
|
fuse_opt_free_args(&args);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fuse_opt_free_args(&args);
|
||||||
|
fuse_session_add_chan(g_se, g_ch);
|
||||||
|
g_bufsize = fuse_chan_bufsize(g_ch);
|
||||||
|
g_buffer = g_malloc(g_bufsize, 0);
|
||||||
|
g_fd = fuse_chan_fd(g_ch);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
fuse_delete_dir_items(struct xfuse_file_info *ffi)
|
||||||
|
{
|
||||||
|
struct xfuse_file_info *ffi1;
|
||||||
|
|
||||||
|
while (ffi != 0)
|
||||||
|
{
|
||||||
|
if (ffi->flags & 1)
|
||||||
|
{
|
||||||
|
fuse_delete_dir_items(ffi->child);
|
||||||
|
}
|
||||||
|
ffi1 = ffi;
|
||||||
|
ffi = ffi->next;
|
||||||
|
g_free(ffi1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_clear_clip_dir(void)
|
||||||
|
{
|
||||||
|
fuse_delete_dir_items(g_fuse_files);
|
||||||
|
g_fuse_files = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* returns error */
|
||||||
|
int APP_CC
|
||||||
|
fuse_add_clip_dir_item(char *filename, int flags, int size, int lindex)
|
||||||
|
{
|
||||||
|
struct xfuse_file_info *ffi;
|
||||||
|
struct xfuse_file_info *ffi1;
|
||||||
|
|
||||||
|
LLOGLN(10, ("fuse_add_clip_dir_item: adding %s ino %d", filename, g_ino));
|
||||||
|
ffi = g_fuse_files;
|
||||||
|
if (ffi == 0)
|
||||||
|
{
|
||||||
|
ffi1 = (struct xfuse_file_info *)
|
||||||
|
g_malloc(sizeof(struct xfuse_file_info), 1);
|
||||||
|
ffi1->flags = flags;
|
||||||
|
ffi1->ino = g_ino++;
|
||||||
|
ffi1->lindex = lindex;
|
||||||
|
ffi1->size = size;
|
||||||
|
g_strncpy(ffi1->filename, filename, 255);
|
||||||
|
g_fuse_files = ffi1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
while (ffi->next != 0)
|
||||||
|
{
|
||||||
|
ffi = ffi->next;
|
||||||
|
}
|
||||||
|
ffi1 = (struct xfuse_file_info *)
|
||||||
|
g_malloc(sizeof(struct xfuse_file_info), 1);
|
||||||
|
ffi1->flags = flags;
|
||||||
|
ffi1->ino = g_ino++;
|
||||||
|
ffi1->lindex = lindex;
|
||||||
|
ffi1->size = size;
|
||||||
|
g_strncpy(ffi1->filename, filename, 255);
|
||||||
|
ffi->next = ffi1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_get_wait_objs(tbus *objs, int *count, int *timeout)
|
||||||
|
{
|
||||||
|
int lcount;
|
||||||
|
|
||||||
|
LLOGLN(10, ("fuse_get_wait_objs:"));
|
||||||
|
if (g_ch == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lcount = *count;
|
||||||
|
objs[lcount] = g_fd;
|
||||||
|
lcount++;
|
||||||
|
*count = lcount;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_check_wait_objs(void)
|
||||||
|
{
|
||||||
|
struct fuse_chan *tmpch;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
LLOGLN(10, ("fuse_check_wait_objs:"));
|
||||||
|
if (g_ch == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (g_tcp_select(g_fd, 0) & 1)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("fuse_check_wait_objs: fd is set"));
|
||||||
|
tmpch = g_ch;
|
||||||
|
res = fuse_chan_recv(&tmpch, g_buffer, g_bufsize);
|
||||||
|
if (res == -EINTR)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (res <= 0)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fuse_session_process(g_se, g_buffer, res, tmpch);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* returns error */
|
||||||
|
int APP_CC
|
||||||
|
fuse_init(void)
|
||||||
|
{
|
||||||
|
char *param0 = "xrdp-chansrv";
|
||||||
|
char *argv[4];
|
||||||
|
|
||||||
|
if (g_ch != 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
g_snprintf(g_fuse_root_path, 255, "%s/xrdp_client", g_getenv("HOME"));
|
||||||
|
LLOGLN(0, ("fuse_init: using root_path [%s]", g_fuse_root_path));
|
||||||
|
if (!g_directory_exist(g_fuse_root_path))
|
||||||
|
{
|
||||||
|
if (!g_create_dir(g_fuse_root_path))
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("fuse_init: g_create_dir failed [%s]",
|
||||||
|
g_fuse_root_path));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_time = g_time1();
|
||||||
|
g_uid = g_getuid();
|
||||||
|
g_gid = g_getgid();
|
||||||
|
argv[0] = param0;
|
||||||
|
argv[1] = g_fuse_root_path;
|
||||||
|
argv[2] = 0;
|
||||||
|
|
||||||
|
g_memset(&g_xrdp_ll_oper, 0, sizeof(g_xrdp_ll_oper));
|
||||||
|
g_xrdp_ll_oper.lookup = xrdp_ll_lookup;
|
||||||
|
g_xrdp_ll_oper.getattr = xrdp_ll_getattr;
|
||||||
|
g_xrdp_ll_oper.readdir = xrdp_ll_readdir;
|
||||||
|
g_xrdp_ll_oper.open = xrdp_ll_open;
|
||||||
|
g_xrdp_ll_oper.read = xrdp_ll_read;
|
||||||
|
|
||||||
|
g_req_list = list_create();
|
||||||
|
g_req_list->auto_free = 1;
|
||||||
|
|
||||||
|
return fuse_init_lib(2, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* returns error */
|
||||||
|
int APP_CC
|
||||||
|
fuse_deinit(void)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("fuse_deinit:"));
|
||||||
|
if (g_ch != 0)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("fuse_deinit: calling fuse_unmount"));
|
||||||
|
fuse_session_remove_chan(g_ch);
|
||||||
|
fuse_unmount(g_mountpoint, g_ch);
|
||||||
|
g_ch = 0;
|
||||||
|
}
|
||||||
|
if (g_se != 0)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("fuse_deinit: calling fuse_session_destroy"));
|
||||||
|
fuse_session_destroy(g_se);
|
||||||
|
g_se = 0;
|
||||||
|
}
|
||||||
|
if (g_buffer != 0)
|
||||||
|
{
|
||||||
|
g_free(g_buffer);
|
||||||
|
g_buffer = 0;
|
||||||
|
}
|
||||||
|
if (g_req_list != 0)
|
||||||
|
{
|
||||||
|
list_delete(g_req_list);
|
||||||
|
g_req_list = 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_file_contents_size(int stream_id, int file_size)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("fuse_file_contents_size: file_size %d", file_size));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_file_contents_range(int stream_id, char *data, int data_bytes)
|
||||||
|
{
|
||||||
|
struct req_list_item *rli;
|
||||||
|
|
||||||
|
LLOGLN(10, ("fuse_file_contents_range: data_bytes %d", data_bytes));
|
||||||
|
rli = (struct req_list_item *)list_get_item(g_req_list, 0);
|
||||||
|
if (rli != 0)
|
||||||
|
{
|
||||||
|
fuse_reply_buf(rli->req, data, data_bytes);
|
||||||
|
list_remove_item(g_req_list, 0);
|
||||||
|
if (g_req_list->count > 0)
|
||||||
|
{
|
||||||
|
/* send next request */
|
||||||
|
rli = (struct req_list_item *)list_get_item(g_req_list, 0);
|
||||||
|
if (rli != 0)
|
||||||
|
{
|
||||||
|
clipboard_request_file_data(rli->stream_id, rli->lindex,
|
||||||
|
rli->off, rli->size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("fuse_file_contents_range: error"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("fuse_file_contents_range: error"));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include "arch.h"
|
||||||
|
|
||||||
|
char g_fuse_root_path[256] = "";
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_get_wait_objs(tbus *objs, int *count, int *timeout)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_check_wait_objs(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_init(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_deinit(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_clear_clip_dir(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_add_clip_dir_item(char *filename, int flags, int size, int lindex)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_file_contents_size(int stream_id, int file_size)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
fuse_file_contents_range(int stream_id, char *data, int data_bytes)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
23
sesman/chansrv/chansrv_fuse.h
Normal file
23
sesman/chansrv/chansrv_fuse.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
#if !defined(CHANSRV_FUSE_H)
|
||||||
|
#define CHANSRV_FUSE_H
|
||||||
|
|
||||||
|
int APP_CC
|
||||||
|
fuse_clear_clip_dir(void);
|
||||||
|
int APP_CC
|
||||||
|
fuse_add_clip_dir_item(char *filename, int flags, int size, int lindex);
|
||||||
|
int APP_CC
|
||||||
|
fuse_get_wait_objs(tbus *objs, int *count, int *timeout);
|
||||||
|
int APP_CC
|
||||||
|
fuse_check_wait_objs(void);
|
||||||
|
int APP_CC
|
||||||
|
fuse_init(void);
|
||||||
|
int APP_CC
|
||||||
|
fuse_deinit(void);
|
||||||
|
|
||||||
|
int APP_CC
|
||||||
|
fuse_file_contents_size(int stream_id, int file_size);
|
||||||
|
int APP_CC
|
||||||
|
fuse_file_contents_range(int stream_id, char *data, int data_bytes);
|
||||||
|
|
||||||
|
#endif
|
63
sesman/chansrv/clipboard-notes.txt
Normal file
63
sesman/chansrv/clipboard-notes.txt
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
LOG_LEVEL
|
||||||
|
|
||||||
|
dolphin
|
||||||
|
clipboard_event_selection_owner_notify:
|
||||||
|
clipboard_event_selection_notify: 0x1f7 text/uri-list
|
||||||
|
clipboard_event_selection_notify: 0x1f8 text/x-moz-url
|
||||||
|
clipboard_event_selection_notify: 0x1f3 text/plain
|
||||||
|
clipboard_event_selection_notify: 0xee UTF8_STRING
|
||||||
|
clipboard_event_selection_notify: 0x1f STRING
|
||||||
|
clipboard_event_selection_notify: 0x1a1 TEXT
|
||||||
|
clipboard_event_selection_notify: 0x1a0 COMPOUND_TEXT
|
||||||
|
clipboard_event_selection_notify: 0x1fa application/x-qiconlist
|
||||||
|
clipboard_event_selection_notify: 0xec TARGETS
|
||||||
|
clipboard_event_selection_notify: 0xed MULTIPLE
|
||||||
|
clipboard_event_selection_notify: 0xeb TIMESTAMP
|
||||||
|
clipboard_event_selection_notify: 0x183 SAVE_TARGETS
|
||||||
|
|
||||||
|
thunar
|
||||||
|
clipboard_event_selection_owner_notify:
|
||||||
|
clipboard_event_selection_notify: 0xeb TIMESTAMP
|
||||||
|
clipboard_event_selection_notify: 0xec TARGETS
|
||||||
|
clipboard_event_selection_notify: 0xed MULTIPLE
|
||||||
|
clipboard_event_selection_notify: 0x204 x-special/gnome-copied-files
|
||||||
|
clipboard_event_selection_notify: 0xee UTF8_STRING
|
||||||
|
clipboard_data_in:
|
||||||
|
clipboard_data_in: 3
|
||||||
|
|
||||||
|
pcmanfm
|
||||||
|
clipboard_event_selection_owner_notify:
|
||||||
|
clipboard_event_selection_notify: 0xeb TIMESTAMP
|
||||||
|
clipboard_event_selection_notify: 0xec TARGETS
|
||||||
|
clipboard_event_selection_notify: 0xed MULTIPLE
|
||||||
|
clipboard_event_selection_notify: 0x1f7 text/uri-list
|
||||||
|
clipboard_event_selection_notify: 0x204 x-special/gnome-copied-files
|
||||||
|
clipboard_event_selection_notify: 0x1f9 application/x-kde-cutselection
|
||||||
|
clipboard_event_selection_notify: 0xee UTF8_STRING
|
||||||
|
|
||||||
|
CAJA
|
||||||
|
clipboard_event_selection_notify: 0x141 TIMESTAMP
|
||||||
|
clipboard_event_selection_notify: 0x130 TARGETS
|
||||||
|
clipboard_event_selection_notify: 0x142 MULTIPLE
|
||||||
|
clipboard_event_selection_notify: 0x143 x-special/mate-copied-files
|
||||||
|
clipboard_event_selection_notify: 0x144 text/uri-list
|
||||||
|
clipboard_event_selection_notify: 0x0 (null)
|
||||||
|
clipboard_event_selection_notify: 0x25 WM_ICON_NAME
|
||||||
|
clipboard_event_selection_notify: 0x47524154 (null)
|
||||||
|
clipboard_event_selection_notify: 0x50000078 (null)
|
||||||
|
clipboard_event_selection_notify: 0x0 (null)
|
||||||
|
clipboard_event_selection_notify: 0x25 WM_ICON_NAME
|
||||||
|
|
||||||
|
nautilus
|
||||||
|
clipboard_event_selection_notify: 0x141 TIMESTAMP
|
||||||
|
clipboard_event_selection_notify: 0x130 TARGETS
|
||||||
|
clipboard_event_selection_notify: 0x142 MULTIPLE
|
||||||
|
clipboard_event_selection_notify: 0x154 x-special/gnome-copied-files
|
||||||
|
clipboard_event_selection_notify: 0x144 text/uri-list
|
||||||
|
clipboard_event_selection_notify: 0xfb UTF8_STRING
|
||||||
|
clipboard_event_selection_notify: 0x0 (null)
|
||||||
|
clipboard_event_selection_notify: 0x25 WM_ICON_NAME
|
||||||
|
clipboard_event_selection_notify: 0x47524154 (null)
|
||||||
|
clipboard_event_selection_notify: 0x50000078 (null)
|
||||||
|
clipboard_event_selection_notify: 0x0 (null)
|
||||||
|
clipboard_event_selection_notify: 0x25 WM_ICON_NAME
|
File diff suppressed because it is too large
Load Diff
@ -23,22 +23,6 @@
|
|||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
|
|
||||||
#define CB_FORMAT_LIST 2
|
|
||||||
#define CB_FORMAT_LIST_RESPONSE 3
|
|
||||||
#define CB_FORMAT_DATA_REQUEST 4
|
|
||||||
#define CB_FORMAT_DATA_RESPONSE 5
|
|
||||||
|
|
||||||
/* Clipboard Formats */
|
|
||||||
|
|
||||||
#define CB_FORMAT_RAW 0x0000
|
|
||||||
#define CB_FORMAT_TEXT 0x0001
|
|
||||||
#define CB_FORMAT_DIB 0x0008
|
|
||||||
#define CB_FORMAT_UNICODETEXT 0x000D
|
|
||||||
#define CB_FORMAT_HTML 0xD010
|
|
||||||
#define CB_FORMAT_PNG 0xD011
|
|
||||||
#define CB_FORMAT_JPEG 0xD012
|
|
||||||
#define CB_FORMAT_GIF 0xD013
|
|
||||||
|
|
||||||
int APP_CC
|
int APP_CC
|
||||||
clipboard_init(void);
|
clipboard_init(void);
|
||||||
int APP_CC
|
int APP_CC
|
||||||
|
135
sesman/chansrv/clipboard_common.h
Normal file
135
sesman/chansrv/clipboard_common.h
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/**
|
||||||
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
|
* Copyright (C) Jay Sorg 2012
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(CLIPBOARD_COMMON_H)
|
||||||
|
#define CLIPBOARD_COMMON_H
|
||||||
|
|
||||||
|
#include "arch.h"
|
||||||
|
#include "parse.h"
|
||||||
|
|
||||||
|
#define CB_CAPSTYPE_GENERAL 1
|
||||||
|
|
||||||
|
#define CB_MONITOR_READY 1
|
||||||
|
#define CB_FORMAT_LIST 2
|
||||||
|
#define CB_FORMAT_LIST_RESPONSE 3
|
||||||
|
#define CB_FORMAT_DATA_REQUEST 4
|
||||||
|
#define CB_FORMAT_DATA_RESPONSE 5
|
||||||
|
#define CB_TEMP_DIRECTORY 6
|
||||||
|
#define CB_CLIP_CAPS 7
|
||||||
|
#define CB_FILECONTENTS_REQUEST 8
|
||||||
|
#define CB_FILECONTENTS_RESPONSE 9
|
||||||
|
#define CB_LOCK_CLIPDATA 10
|
||||||
|
#define CB_UNLOCK_CLIPDATA 11
|
||||||
|
|
||||||
|
#define CB_USE_LONG_FORMAT_NAMES 0x00000002
|
||||||
|
#define CB_STREAM_FILECLIP_ENABLED 0x00000004
|
||||||
|
#define CB_FILECLIP_NO_FILE_PATHS 0x00000008
|
||||||
|
#define CB_CAN_LOCK_CLIPDATA 0x00000010
|
||||||
|
|
||||||
|
#define CB_FILECONTENTS_SIZE 0x00000001
|
||||||
|
#define CB_FILECONTENTS_RANGE 0x00000002
|
||||||
|
|
||||||
|
#define CB_FORMAT_RAW 0x0000
|
||||||
|
#define CB_FORMAT_TEXT 0x0001
|
||||||
|
#define CB_FORMAT_DIB 0x0008
|
||||||
|
#define CB_FORMAT_UNICODETEXT 0x000D
|
||||||
|
#define CB_FORMAT_HTML 0xD010
|
||||||
|
#define CB_FORMAT_PNG 0xD011
|
||||||
|
#define CB_FORMAT_JPEG 0xD012
|
||||||
|
#define CB_FORMAT_GIF 0xD013
|
||||||
|
#define CB_FORMAT_FILE 0xC0BC
|
||||||
|
|
||||||
|
/* Used by the Format List Response PDU, Format Data Response PDU, and File
|
||||||
|
Contents Response PDU to indicate that the associated request Format List
|
||||||
|
PDU, Format Data Request PDU, and File Contents Request PDU were processed
|
||||||
|
successfully. */
|
||||||
|
#define CB_RESPONSE_OK 0x0001
|
||||||
|
|
||||||
|
/* Used by the Format List Response PDU, Format Data Response PDU, and File
|
||||||
|
Contents Response PDU to indicate that the associated Format List PDU,
|
||||||
|
Format Data Request PDU, and File Contents Request PDU were not processed
|
||||||
|
successfully. */
|
||||||
|
#define CB_RESPONSE_FAIL 0x0002
|
||||||
|
|
||||||
|
/* Used by the Short Format Name variant of the Format List Response PDU to
|
||||||
|
indicate the format names are in ASCII 8. */
|
||||||
|
#define CB_ASCII_NAMES 0x0004
|
||||||
|
|
||||||
|
/* these are the supported general types */
|
||||||
|
#define XRDP_CB_TEXT 1
|
||||||
|
#define XRDP_CB_BITMAP 2
|
||||||
|
#define XRDP_CB_FILE 3
|
||||||
|
|
||||||
|
#define CB_FD_ATTRIBUTES 0x00000004
|
||||||
|
#define CB_FD_FILESIZE 0x00000040
|
||||||
|
#define CB_FD_WRITESTIME 0x00000020
|
||||||
|
#define CB_FD_PROGRESSUI 0x00004000
|
||||||
|
|
||||||
|
#define CB_FILE_ATTRIBUTE_READONLY 0x00000001
|
||||||
|
#define CB_FILE_ATTRIBUTE_HIDDEN 0x00000002
|
||||||
|
#define CB_FILE_ATTRIBUTE_SYSTEM 0x00000004
|
||||||
|
#define CB_FILE_ATTRIBUTE_DIRECTORY 0x00000010
|
||||||
|
#define CB_FILE_ATTRIBUTE_ARCHIVE 0x00000020
|
||||||
|
#define CB_FILE_ATTRIBUTE_NORMAL 0x00000080
|
||||||
|
|
||||||
|
struct clip_s2c /* server to client, pasting from linux app to mstsc */
|
||||||
|
{
|
||||||
|
int incr_in_progress;
|
||||||
|
int total_bytes;
|
||||||
|
char *data;
|
||||||
|
Atom type; /* UTF8_STRING, image/bmp, ... */
|
||||||
|
Atom property; /* XRDP_CLIP_PROPERTY_ATOM, _QT_SELECTION, ... */
|
||||||
|
int xrdp_clip_type; /* XRDP_CB_TEXT, XRDP_CB_BITMAP, XRDP_CB_FILE, ... */
|
||||||
|
int converted;
|
||||||
|
Time clip_time;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct clip_c2s /* client to server, pasting from mstsc to linux app */
|
||||||
|
{
|
||||||
|
int incr_in_progress;
|
||||||
|
int incr_bytes_done;
|
||||||
|
int read_bytes_done;
|
||||||
|
int total_bytes;
|
||||||
|
char *data;
|
||||||
|
Atom type; /* UTF8_STRING, image/bmp, ... */
|
||||||
|
Atom property; /* XRDP_CLIP_PROPERTY_ATOM, _QT_SELECTION, ... */
|
||||||
|
Window window; /* Window used in INCR transfer */
|
||||||
|
int xrdp_clip_type; /* XRDP_CB_TEXT, XRDP_CB_BITMAP, XRDP_CB_FILE, ... */
|
||||||
|
int converted;
|
||||||
|
int in_request; /* a data request has been sent to client */
|
||||||
|
int doing_response_ss; /* doing response short circuit */
|
||||||
|
Time clip_time;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct clip_file_desc /* CLIPRDR_FILEDESCRIPTOR */
|
||||||
|
{
|
||||||
|
tui32 flags;
|
||||||
|
tui32 fileAttributes;
|
||||||
|
tui32 lastWriteTimeLow;
|
||||||
|
tui32 lastWriteTimeHigh;
|
||||||
|
tui32 fileSizeHigh;
|
||||||
|
tui32 fileSizeLow;
|
||||||
|
char cFileName[256];
|
||||||
|
};
|
||||||
|
|
||||||
|
int APP_CC
|
||||||
|
clipboard_out_unicode(struct stream *s, char *text, int num_chars);
|
||||||
|
int APP_CC
|
||||||
|
clipboard_in_unicode(struct stream *s, char *text, int *num_chars);
|
||||||
|
|
||||||
|
#endif
|
635
sesman/chansrv/clipboard_file.c
Normal file
635
sesman/chansrv/clipboard_file.c
Normal file
@ -0,0 +1,635 @@
|
|||||||
|
/**
|
||||||
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
|
* Copyright (C) Jay Sorg 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* MS-RDPECLIP
|
||||||
|
* http://msdn.microsoft.com/en-us/library/cc241066%28prot.20%29.aspx
|
||||||
|
*
|
||||||
|
* CLIPRDR_FILEDESCRIPTOR
|
||||||
|
* http://msdn.microsoft.com/en-us/library/ff362447%28prot.20%29.aspx */
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xatom.h>
|
||||||
|
#include <X11/extensions/Xfixes.h>
|
||||||
|
#include "arch.h"
|
||||||
|
#include "parse.h"
|
||||||
|
#include "os_calls.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "chansrv.h"
|
||||||
|
#include "clipboard.h"
|
||||||
|
#include "clipboard_file.h"
|
||||||
|
#include "clipboard_common.h"
|
||||||
|
#include "xcommon.h"
|
||||||
|
#include "chansrv_fuse.h"
|
||||||
|
|
||||||
|
#define LLOG_LEVEL 1
|
||||||
|
#define LLOGLN(_level, _args) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
if (_level < LLOG_LEVEL) \
|
||||||
|
{ \
|
||||||
|
g_write("chansrv:clip [%10.10u]: ", g_time3()); \
|
||||||
|
g_writeln _args ; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
|
extern int g_cliprdr_chan_id; /* in chansrv.c */
|
||||||
|
|
||||||
|
extern struct clip_s2c g_clip_s2c; /* in clipboard.c */
|
||||||
|
extern struct clip_c2s g_clip_c2s; /* in clipboard.c */
|
||||||
|
|
||||||
|
extern char g_fuse_root_path[]; /* in chansrv_fuse.c */
|
||||||
|
|
||||||
|
struct cb_file_info
|
||||||
|
{
|
||||||
|
char pathname[256];
|
||||||
|
char filename[256];
|
||||||
|
int flags;
|
||||||
|
int size;
|
||||||
|
tui64 time;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct list *g_files_list = 0;
|
||||||
|
|
||||||
|
/* used when server is asking for file info from the client */
|
||||||
|
static int g_file_request_sent_type = 0;
|
||||||
|
|
||||||
|
/* number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC */
|
||||||
|
#define CB_EPOCH_DIFF 11644473600LL
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static tui64 APP_CC
|
||||||
|
timeval2wintime(struct timeval *tv)
|
||||||
|
{
|
||||||
|
tui64 result;
|
||||||
|
|
||||||
|
result = CB_EPOCH_DIFF;
|
||||||
|
result += tv->tv_sec;
|
||||||
|
result *= 10000000LL;
|
||||||
|
result += tv->tv_usec * 10;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* this will replace %20 or any hex with the space or correct char
|
||||||
|
* returns error */
|
||||||
|
static int APP_CC
|
||||||
|
clipboard_check_file(char *filename)
|
||||||
|
{
|
||||||
|
char lfilename[256];
|
||||||
|
char jchr[8];
|
||||||
|
int lindex;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
g_memset(lfilename, 0, 256);
|
||||||
|
lindex = 0;
|
||||||
|
index = 0;
|
||||||
|
while (filename[index] != 0)
|
||||||
|
{
|
||||||
|
if (filename[index] == '%')
|
||||||
|
{
|
||||||
|
jchr[0] = filename[index + 1];
|
||||||
|
jchr[1] = filename[index + 2];
|
||||||
|
jchr[2] = 0;
|
||||||
|
index += 3;
|
||||||
|
lfilename[lindex] = g_htoi(jchr);
|
||||||
|
lindex++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lfilename[lindex] = filename[index];
|
||||||
|
lindex++;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LLOGLN(10, ("[%s] [%s]", filename, lfilename));
|
||||||
|
g_strcpy(filename, lfilename);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
clipboard_get_file(char* file, int bytes)
|
||||||
|
{
|
||||||
|
int sindex;
|
||||||
|
int pindex;
|
||||||
|
int flags;
|
||||||
|
char full_fn[256]; /* /etc/xrdp/xrdp.ini */
|
||||||
|
char filename[256]; /* xrdp.ini */
|
||||||
|
char pathname[256]; /* /etc/xrdp */
|
||||||
|
struct cb_file_info *cfi;
|
||||||
|
|
||||||
|
/* x-special/gnome-copied-files */
|
||||||
|
if ((g_strncmp(file, "copy", 4) == 0) && (bytes == 4))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ((g_strncmp(file, "cut", 3) == 0) && (bytes == 3))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
sindex = 0;
|
||||||
|
flags = CB_FILE_ATTRIBUTE_ARCHIVE;
|
||||||
|
/* text/uri-list */
|
||||||
|
/* x-special/gnome-copied-files */
|
||||||
|
if (g_strncmp(file, "file://", 7) == 0)
|
||||||
|
{
|
||||||
|
sindex = 7;
|
||||||
|
}
|
||||||
|
pindex = bytes;
|
||||||
|
while (pindex > sindex)
|
||||||
|
{
|
||||||
|
if (file[pindex] == '/')
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pindex--;
|
||||||
|
}
|
||||||
|
g_memset(pathname, 0, 256);
|
||||||
|
g_memset(filename, 0, 256);
|
||||||
|
g_memcpy(pathname, file + sindex, pindex - sindex);
|
||||||
|
if (pathname[0] == 0)
|
||||||
|
{
|
||||||
|
pathname[0] = '/';
|
||||||
|
}
|
||||||
|
g_memcpy(filename, file + pindex + 1, (bytes - 1) - pindex);
|
||||||
|
/* this should replace %20 with space */
|
||||||
|
clipboard_check_file(filename);
|
||||||
|
g_snprintf(full_fn, 255, "%s/%s", pathname, filename);
|
||||||
|
if (g_directory_exist(full_fn))
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("clipboard_get_file: file [%s] is a directory, "
|
||||||
|
"not supported", full_fn));
|
||||||
|
flags |= CB_FILE_ATTRIBUTE_DIRECTORY;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!g_file_exist(full_fn))
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("clipboard_get_file: file [%s] does not exist",
|
||||||
|
full_fn));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cfi = (struct cb_file_info*)g_malloc(sizeof(struct cb_file_info), 1);
|
||||||
|
list_add_item(g_files_list, (tintptr)cfi);
|
||||||
|
g_strcpy(cfi->filename, filename);
|
||||||
|
g_strcpy(cfi->pathname, pathname);
|
||||||
|
cfi->size = g_file_get_size(full_fn);
|
||||||
|
cfi->flags = flags;
|
||||||
|
cfi->time = (g_time1() + CB_EPOCH_DIFF) * 10000000LL;
|
||||||
|
LLOGLN(10, ("ok filename [%s] pathname [%s] size [%d]",
|
||||||
|
cfi->filename, cfi->pathname, cfi->size));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
clipboard_get_files(char *files, int bytes)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
int file_index;
|
||||||
|
char file[512];
|
||||||
|
|
||||||
|
file_index = 0;
|
||||||
|
for (index = 0; index < bytes; index++)
|
||||||
|
{
|
||||||
|
if (files[index] == '\n' || files[index] == '\r')
|
||||||
|
{
|
||||||
|
if (file_index > 0)
|
||||||
|
{
|
||||||
|
if (clipboard_get_file(file, file_index) == 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
file_index = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file[file_index] = files[index];
|
||||||
|
file_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file_index > 0)
|
||||||
|
{
|
||||||
|
if (clipboard_get_file(file, file_index) == 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (g_files_list->count < 1)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* server to client */
|
||||||
|
/* response to client asking for clipboard contents that is file list */
|
||||||
|
int APP_CC
|
||||||
|
clipboard_send_data_response_for_file(char *data, int data_size)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
int size;
|
||||||
|
int rv;
|
||||||
|
int bytes_after_header;
|
||||||
|
int cItems;
|
||||||
|
int flags;
|
||||||
|
int index;
|
||||||
|
tui32 ui32;
|
||||||
|
char fn[256];
|
||||||
|
struct cb_file_info *cfi;
|
||||||
|
|
||||||
|
LLOGLN(10, ("clipboard_send_data_response_for_file: data_size %d",
|
||||||
|
data_size));
|
||||||
|
//g_hexdump(data, data_size);
|
||||||
|
if (g_files_list == 0)
|
||||||
|
{
|
||||||
|
g_files_list = list_create();
|
||||||
|
g_files_list->auto_free = 1;
|
||||||
|
}
|
||||||
|
list_clear(g_files_list);
|
||||||
|
clipboard_get_files(data, data_size);
|
||||||
|
cItems = g_files_list->count;
|
||||||
|
bytes_after_header = cItems * 592 + 4;
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, 64 + bytes_after_header);
|
||||||
|
out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */
|
||||||
|
out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */
|
||||||
|
out_uint32_le(s, bytes_after_header);
|
||||||
|
out_uint32_le(s, cItems);
|
||||||
|
for (index = 0; index < cItems; index++)
|
||||||
|
{
|
||||||
|
cfi = (struct cb_file_info *)list_get_item(g_files_list, index);
|
||||||
|
flags = CB_FD_ATTRIBUTES | CB_FD_FILESIZE | CB_FD_WRITESTIME | CB_FD_PROGRESSUI;
|
||||||
|
out_uint32_le(s, flags);
|
||||||
|
out_uint8s(s, 32); /* reserved1 */
|
||||||
|
flags = cfi->flags;
|
||||||
|
out_uint32_le(s, flags);
|
||||||
|
out_uint8s(s, 16); /* reserved2 */
|
||||||
|
/* file time */
|
||||||
|
/* 100-nanoseconds intervals since 1 January 1601 */
|
||||||
|
//out_uint32_le(s, 0x2c305d08); /* 25 October 2009, 21:17 */
|
||||||
|
//out_uint32_le(s, 0x01ca55f3);
|
||||||
|
ui32 = cfi->time & 0xffffffff;
|
||||||
|
out_uint32_le(s, ui32);
|
||||||
|
ui32 = cfi->time >> 32;
|
||||||
|
out_uint32_le(s, ui32);
|
||||||
|
/* file size */
|
||||||
|
out_uint32_le(s, 0);
|
||||||
|
out_uint32_le(s, cfi->size);
|
||||||
|
g_snprintf(fn, 255, "%s", cfi->filename);
|
||||||
|
clipboard_out_unicode(s, fn, 256);
|
||||||
|
out_uint8s(s, 8); /* pad */
|
||||||
|
}
|
||||||
|
out_uint32_le(s, 0);
|
||||||
|
s_mark_end(s);
|
||||||
|
size = (int)(s->end - s->data);
|
||||||
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
||||||
|
free_stream(s);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* send the file size from server to the client */
|
||||||
|
static int APP_CC
|
||||||
|
clipboard_send_file_size(int streamId, int lindex)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
int size;
|
||||||
|
int rv;
|
||||||
|
int file_size;
|
||||||
|
struct cb_file_info *cfi;
|
||||||
|
|
||||||
|
if (g_files_list == 0)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("clipboard_send_file_size: error g_files_list is nil"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex);
|
||||||
|
if (cfi == 0)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("clipboard_send_file_size: error cfi is nil"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
file_size = cfi->size;
|
||||||
|
LLOGLN(10, ("clipboard_send_file_size: streamId %d file_size %d",
|
||||||
|
streamId, file_size));
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, 8192);
|
||||||
|
out_uint16_le(s, CB_FILECONTENTS_RESPONSE); /* 9 */
|
||||||
|
out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */
|
||||||
|
out_uint32_le(s, 12);
|
||||||
|
out_uint32_le(s, streamId);
|
||||||
|
out_uint32_le(s, file_size);
|
||||||
|
out_uint32_le(s, 0);
|
||||||
|
out_uint32_le(s, 0);
|
||||||
|
s_mark_end(s);
|
||||||
|
size = (int)(s->end - s->data);
|
||||||
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
||||||
|
free_stream(s);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* ask the client to send the file size */
|
||||||
|
int APP_CC
|
||||||
|
clipboard_request_file_size(int stream_id, int lindex)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
int size;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
LLOGLN(10, ("clipboard_request_file_size:"));
|
||||||
|
if (g_file_request_sent_type != 0)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("clipboard_request_file_size: warning, still waiting "
|
||||||
|
"for CB_FILECONTENTS_RESPONSE"));
|
||||||
|
}
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, 8192);
|
||||||
|
out_uint16_le(s, CB_FILECONTENTS_REQUEST); /* 8 */
|
||||||
|
out_uint16_le(s, 0);
|
||||||
|
out_uint32_le(s, 28);
|
||||||
|
out_uint32_le(s, stream_id);
|
||||||
|
out_uint32_le(s, lindex);
|
||||||
|
out_uint32_le(s, CB_FILECONTENTS_SIZE);
|
||||||
|
out_uint32_le(s, 0); /* nPositionLow */
|
||||||
|
out_uint32_le(s, 0); /* nPositionHigh */
|
||||||
|
out_uint32_le(s, 0); /* cbRequested */
|
||||||
|
out_uint32_le(s, 0); /* clipDataId */
|
||||||
|
out_uint32_le(s, 0);
|
||||||
|
s_mark_end(s);
|
||||||
|
size = (int)(s->end - s->data);
|
||||||
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
||||||
|
free_stream(s);
|
||||||
|
g_file_request_sent_type = CB_FILECONTENTS_SIZE;
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* send a chunk of the file from server to client */
|
||||||
|
static int APP_CC
|
||||||
|
clipboard_send_file_data(int streamId, int lindex,
|
||||||
|
int nPositionLow, int cbRequested)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
int size;
|
||||||
|
int rv;
|
||||||
|
int fd;
|
||||||
|
char full_fn[256];
|
||||||
|
struct cb_file_info *cfi;
|
||||||
|
|
||||||
|
if (g_files_list == 0)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("clipboard_send_file_data: error g_files_list is nil"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex);
|
||||||
|
if (cfi == 0)
|
||||||
|
{
|
||||||
|
LLOGLN(10, ("clipboard_send_file_data: error cfi is nil"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
LLOGLN(10, ("clipboard_send_file_data: streamId %d lindex %d "
|
||||||
|
"nPositionLow %d cbRequested %d", streamId, lindex,
|
||||||
|
nPositionLow, cbRequested));
|
||||||
|
g_snprintf(full_fn, 255, "%s/%s", cfi->pathname, cfi->filename);
|
||||||
|
fd = g_file_open_ex(full_fn, 1, 0, 0, 0);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("clipboard_send_file_data: file open [%s] failed",
|
||||||
|
full_fn));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
g_file_seek(fd, nPositionLow);
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, cbRequested + 64);
|
||||||
|
size = g_file_read(fd, s->data + 12, cbRequested);
|
||||||
|
if (size < 1)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("clipboard_send_file_data: read error, want %d got %d",
|
||||||
|
cbRequested, size));
|
||||||
|
free_stream(s);
|
||||||
|
g_file_close(fd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
out_uint16_le(s, CB_FILECONTENTS_RESPONSE); /* 9 */
|
||||||
|
out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */
|
||||||
|
out_uint32_le(s, size + 4);
|
||||||
|
out_uint32_le(s, streamId);
|
||||||
|
s->p += size;
|
||||||
|
out_uint32_le(s, 0);
|
||||||
|
s_mark_end(s);
|
||||||
|
size = (int)(s->end - s->data);
|
||||||
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
||||||
|
free_stream(s);
|
||||||
|
g_file_close(fd);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* ask the client to send the file size */
|
||||||
|
int APP_CC
|
||||||
|
clipboard_request_file_data(int stream_id, int lindex, int offset,
|
||||||
|
int request_bytes)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
int size;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
LLOGLN(10, ("clipboard_request_file_data:"));
|
||||||
|
if (g_file_request_sent_type != 0)
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("clipboard_request_file_data: warning, still waiting "
|
||||||
|
"for CB_FILECONTENTS_RESPONSE"));
|
||||||
|
}
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, 8192);
|
||||||
|
out_uint16_le(s, CB_FILECONTENTS_REQUEST); /* 8 */
|
||||||
|
out_uint16_le(s, 0);
|
||||||
|
out_uint32_le(s, 28);
|
||||||
|
out_uint32_le(s, stream_id);
|
||||||
|
out_uint32_le(s, lindex);
|
||||||
|
out_uint32_le(s, CB_FILECONTENTS_RANGE);
|
||||||
|
out_uint32_le(s, offset); /* nPositionLow */
|
||||||
|
out_uint32_le(s, 0); /* nPositionHigh */
|
||||||
|
out_uint32_le(s, request_bytes); /* cbRequested */
|
||||||
|
out_uint32_le(s, 0); /* clipDataId */
|
||||||
|
out_uint32_le(s, 0);
|
||||||
|
s_mark_end(s);
|
||||||
|
size = (int)(s->end - s->data);
|
||||||
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
||||||
|
free_stream(s);
|
||||||
|
g_file_request_sent_type = CB_FILECONTENTS_RANGE;
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* client is asking from info about a file */
|
||||||
|
int APP_CC
|
||||||
|
clipboard_process_file_request(struct stream *s, int clip_msg_status,
|
||||||
|
int clip_msg_len)
|
||||||
|
{
|
||||||
|
int streamId;
|
||||||
|
int lindex;
|
||||||
|
int dwFlags;
|
||||||
|
int nPositionLow;
|
||||||
|
int nPositionHigh;
|
||||||
|
int cbRequested;
|
||||||
|
//int clipDataId;
|
||||||
|
|
||||||
|
LLOGLN(10, ("clipboard_process_file_request:"));
|
||||||
|
//g_hexdump(s->p, clip_msg_len);
|
||||||
|
in_uint32_le(s, streamId);
|
||||||
|
in_uint32_le(s, lindex);
|
||||||
|
in_uint32_le(s, dwFlags);
|
||||||
|
in_uint32_le(s, nPositionLow);
|
||||||
|
in_uint32_le(s, nPositionHigh);
|
||||||
|
in_uint32_le(s, cbRequested);
|
||||||
|
//in_uint32_le(s, clipDataId); /* options, used when locking */
|
||||||
|
if (dwFlags & CB_FILECONTENTS_SIZE)
|
||||||
|
{
|
||||||
|
clipboard_send_file_size(streamId, lindex);
|
||||||
|
}
|
||||||
|
if (dwFlags & CB_FILECONTENTS_RANGE)
|
||||||
|
{
|
||||||
|
clipboard_send_file_data(streamId, lindex, nPositionLow, cbRequested);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* server requested info about the file and this is the responce
|
||||||
|
it's either the file size or file data */
|
||||||
|
int APP_CC
|
||||||
|
clipboard_process_file_response(struct stream *s, int clip_msg_status,
|
||||||
|
int clip_msg_len)
|
||||||
|
{
|
||||||
|
int streamId;
|
||||||
|
int file_size;
|
||||||
|
|
||||||
|
LLOGLN(10, ("clipboard_process_file_response:"));
|
||||||
|
if (g_file_request_sent_type == CB_FILECONTENTS_SIZE)
|
||||||
|
{
|
||||||
|
g_file_request_sent_type = 0;
|
||||||
|
in_uint32_le(s, streamId);
|
||||||
|
in_uint32_le(s, file_size);
|
||||||
|
LLOGLN(10, ("clipboard_process_file_response: streamId %d "
|
||||||
|
"file_size %d", streamId, file_size));
|
||||||
|
fuse_file_contents_size(streamId, file_size);
|
||||||
|
}
|
||||||
|
else if (g_file_request_sent_type == CB_FILECONTENTS_RANGE)
|
||||||
|
{
|
||||||
|
g_file_request_sent_type = 0;
|
||||||
|
in_uint32_le(s, streamId);
|
||||||
|
fuse_file_contents_range(streamId, s->p, clip_msg_len - 4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("clipboard_process_file_response: error"));
|
||||||
|
g_file_request_sent_type = 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* read in CLIPRDR_FILEDESCRIPTOR */
|
||||||
|
static int APP_CC
|
||||||
|
clipboard_c2s_in_file_info(struct stream *s, struct clip_file_desc *cfd)
|
||||||
|
{
|
||||||
|
int num_chars;
|
||||||
|
int ex_bytes;
|
||||||
|
|
||||||
|
in_uint32_le(s, cfd->flags);
|
||||||
|
in_uint8s(s, 32); /* reserved1 */
|
||||||
|
in_uint32_le(s, cfd->fileAttributes);
|
||||||
|
in_uint8s(s, 16); /* reserved2 */
|
||||||
|
in_uint32_le(s, cfd->lastWriteTimeLow);
|
||||||
|
in_uint32_le(s, cfd->lastWriteTimeHigh);
|
||||||
|
in_uint32_le(s, cfd->fileSizeHigh);
|
||||||
|
in_uint32_le(s, cfd->fileSizeLow);
|
||||||
|
num_chars = 256;
|
||||||
|
clipboard_in_unicode(s, cfd->cFileName, &num_chars);
|
||||||
|
ex_bytes = 512 - num_chars * 2;
|
||||||
|
ex_bytes -= 2;
|
||||||
|
in_uint8s(s, ex_bytes);
|
||||||
|
in_uint8s(s, 8); /* pad */
|
||||||
|
LLOGLN(10, ("clipboard_c2s_in_file_info:"));
|
||||||
|
LLOGLN(10, (" flags 0x%8.8x", cfd->flags));
|
||||||
|
LLOGLN(10, (" fileAttributes 0x%8.8x", cfd->fileAttributes));
|
||||||
|
LLOGLN(10, (" lastWriteTime 0x%8.8x%8.8x", cfd->lastWriteTimeHigh,
|
||||||
|
cfd->lastWriteTimeLow));
|
||||||
|
LLOGLN(10, (" fileSize 0x%8.8x%8.8x", cfd->fileSizeHigh,
|
||||||
|
cfd->fileSizeLow));
|
||||||
|
LLOGLN(10, (" num_chars %d cFileName [%s]", num_chars, cfd->cFileName));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
clipboard_c2s_in_files(struct stream *s, char *file_list)
|
||||||
|
{
|
||||||
|
int cItems;
|
||||||
|
int lindex;
|
||||||
|
int str_len;
|
||||||
|
struct clip_file_desc *cfd;
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
in_uint32_le(s, cItems);
|
||||||
|
fuse_clear_clip_dir();
|
||||||
|
LLOGLN(10, ("clipboard_c2s_in_files: cItems %d", cItems));
|
||||||
|
cfd = (struct clip_file_desc *)
|
||||||
|
g_malloc(sizeof(struct clip_file_desc), 0);
|
||||||
|
ptr = file_list;
|
||||||
|
for (lindex = 0; lindex < cItems; lindex++)
|
||||||
|
{
|
||||||
|
g_memset(cfd, 0, sizeof(struct clip_file_desc));
|
||||||
|
clipboard_c2s_in_file_info(s, cfd);
|
||||||
|
if ((g_pos(cfd->cFileName, "\\") >= 0) ||
|
||||||
|
(cfd->fileAttributes & CB_FILE_ATTRIBUTE_DIRECTORY))
|
||||||
|
{
|
||||||
|
LLOGLN(0, ("clipboard_c2s_in_files: skipping directory not "
|
||||||
|
"supported [%s]", cfd->cFileName));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fuse_add_clip_dir_item(cfd->cFileName, 0, cfd->fileSizeLow, lindex);
|
||||||
|
|
||||||
|
g_strcpy(ptr, "file://");
|
||||||
|
ptr += 7;
|
||||||
|
|
||||||
|
str_len = g_strlen(g_fuse_root_path);
|
||||||
|
g_strcpy(ptr, g_fuse_root_path);
|
||||||
|
ptr += str_len;
|
||||||
|
|
||||||
|
*ptr = '/';
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
str_len = g_strlen(cfd->cFileName);
|
||||||
|
g_strcpy(ptr, cfd->cFileName);
|
||||||
|
ptr += str_len;
|
||||||
|
|
||||||
|
*ptr = '\n';
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
*ptr = 0;
|
||||||
|
g_free(cfd);
|
||||||
|
return 0;
|
||||||
|
}
|
42
sesman/chansrv/clipboard_file.h
Normal file
42
sesman/chansrv/clipboard_file.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
|
*
|
||||||
|
* Copyright (C) Jay Sorg 2012
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(CLIPBOARD_FILE_H)
|
||||||
|
#define CLIPBOARD_FILE_H
|
||||||
|
|
||||||
|
#include "arch.h"
|
||||||
|
#include "parse.h"
|
||||||
|
|
||||||
|
int APP_CC
|
||||||
|
clipboard_send_data_response_for_file(char *data, int data_size);
|
||||||
|
int APP_CC
|
||||||
|
clipboard_process_file_request(struct stream *s, int clip_msg_status,
|
||||||
|
int clip_msg_len);
|
||||||
|
int APP_CC
|
||||||
|
clipboard_process_file_response(struct stream *s, int clip_msg_status,
|
||||||
|
int clip_msg_len);
|
||||||
|
int APP_CC
|
||||||
|
clipboard_c2s_in_files(struct stream *s, char *file_list);
|
||||||
|
|
||||||
|
int APP_CC
|
||||||
|
clipboard_request_file_size(int stream_id, int lindex);
|
||||||
|
int APP_CC
|
||||||
|
clipboard_request_file_data(int stream_id, int lindex, int offset,
|
||||||
|
int request_bytes);
|
||||||
|
|
||||||
|
#endif
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* xrdp: A Remote Desktop Protocol server.
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
*
|
*
|
||||||
* Copyright (C) Jay Sorg 2012
|
* Copyright (C) Laxmikant Rashinkar 2012 LK.Rashinkar@gmail.com
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -15,3 +15,502 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "drdynvc.h"
|
||||||
|
|
||||||
|
int g_drdynvc_chan_id;
|
||||||
|
int g_drdynvc_inited = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bring up dynamic virtual channel
|
||||||
|
*
|
||||||
|
* @return 0 on success, -1 on response
|
||||||
|
******************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
drdynvc_init(void)
|
||||||
|
{
|
||||||
|
/* bring up X11 */
|
||||||
|
xcommon_init();
|
||||||
|
|
||||||
|
/* let client know what version of DVC we support */
|
||||||
|
drdynvc_send_capability_request(2);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* let DVC Manager on client end know what version of protocol we support
|
||||||
|
* client will respond with version that it supports
|
||||||
|
*
|
||||||
|
* @return 0 on success, -1 on response
|
||||||
|
******************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
drdynvc_send_capability_request(uint16_t version)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
int bytes_in_stream;
|
||||||
|
|
||||||
|
/* setup stream */
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, MAX_PDU_SIZE);
|
||||||
|
|
||||||
|
out_uint8(s, 0x50); /* insert cmd */
|
||||||
|
out_uint8(s, 0x00); /* insert padding */
|
||||||
|
out_uint16_le(s, version); /* insert version */
|
||||||
|
|
||||||
|
/* channel priority unused for now */
|
||||||
|
out_uint16_le(s, 0x0000); /* priority charge 0 */
|
||||||
|
out_uint16_le(s, 0x0000); /* priority charge 1 */
|
||||||
|
out_uint16_le(s, 0x0000); /* priority charge 2 */
|
||||||
|
out_uint16_le(s, 0x0000); /* priority charge 3 */
|
||||||
|
|
||||||
|
/* send command to client */
|
||||||
|
bytes_in_stream = stream_length_before_p(s);
|
||||||
|
send_channel_data(g_drdynvc_chan_id, s->data, bytes_in_stream);
|
||||||
|
free_stream(s);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* process capability response received from DVC manager at client end
|
||||||
|
*
|
||||||
|
* @param s stream containing client response
|
||||||
|
*
|
||||||
|
* @return 0 on success, -1 on failure
|
||||||
|
******************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
drdynvc_process_capability_response(struct stream *s, unsigned char cmd)
|
||||||
|
{
|
||||||
|
int cap_version;
|
||||||
|
|
||||||
|
/* skip padding */
|
||||||
|
in_uint8s(s, 1);
|
||||||
|
|
||||||
|
/* read client's version */
|
||||||
|
in_uint16_le(s, cap_version);
|
||||||
|
|
||||||
|
if (cap_version != 2)
|
||||||
|
{
|
||||||
|
LOG(0, ("drdynvc_process_capability_response: incompatible DVC version %d detected", cap_version));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(0, ("drdynvc_process_capability_response: DVC version 2 selected"));
|
||||||
|
g_drdynvc_inited = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create a new dynamic virtual channel
|
||||||
|
*
|
||||||
|
* @pram channel_id channel id number
|
||||||
|
* @pram channel_name name of channel
|
||||||
|
*
|
||||||
|
* @return 0 on success, -1 on failure
|
||||||
|
******************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
drdynvc_send_open_channel_request(int chan_pri, unsigned int chan_id,
|
||||||
|
char *chan_name)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
int bytes_in_stream;
|
||||||
|
int cbChId;
|
||||||
|
int name_length;
|
||||||
|
|
||||||
|
if ((chan_name == NULL) || (strlen(chan_name) == 0))
|
||||||
|
{
|
||||||
|
LOG(0, ("drdynvc_send_open_channel_request: bad channel name specified"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, MAX_PDU_SIZE);
|
||||||
|
|
||||||
|
name_length = strlen(chan_name);
|
||||||
|
|
||||||
|
/* dummy command for now */
|
||||||
|
out_uint8(s, 0);
|
||||||
|
|
||||||
|
/* insert channel id */
|
||||||
|
cbChId = drdynvc_insert_uint_124(s, chan_id);
|
||||||
|
|
||||||
|
/* insert channel name */
|
||||||
|
out_uint8a(s, chan_name, name_length + 1);
|
||||||
|
|
||||||
|
/* insert command */
|
||||||
|
s->data[0] = CMD_DVC_OPEN_CHANNEL | ((chan_pri << 2) & 0x0c) | cbChId;
|
||||||
|
|
||||||
|
/* send command */
|
||||||
|
bytes_in_stream = stream_length_before_p(s);
|
||||||
|
send_channel_data(g_drdynvc_chan_id, s->data, bytes_in_stream);
|
||||||
|
free_stream(s);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int APP_CC
|
||||||
|
drdynvc_process_open_channel_response(struct stream *s, unsigned char cmd)
|
||||||
|
{
|
||||||
|
struct xrdp_api_data *adp;
|
||||||
|
|
||||||
|
uint32_t chan_id;
|
||||||
|
int creation_status;
|
||||||
|
|
||||||
|
drdynvc_get_chan_id(s, cmd, &chan_id);
|
||||||
|
in_uint32_le(s, creation_status);
|
||||||
|
|
||||||
|
/* LK_TODO now do something using useful! */
|
||||||
|
|
||||||
|
if (creation_status < 0)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* get struct xrdp_api_data containing this channel id */
|
||||||
|
if ((adp = struct_from_dvc_chan_id(chan_id)) == NULL)
|
||||||
|
{
|
||||||
|
LOG(0, ("drdynvc_process_open_channel_response: error : "
|
||||||
|
"could not find xrdp_api_data containing chan_id %d", chan_id));
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
adp->is_connected = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int APP_CC
|
||||||
|
drdynvc_send_close_channel_request(unsigned int chan_id)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
int bytes_in_stream;
|
||||||
|
int cbChId;
|
||||||
|
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, MAX_PDU_SIZE);
|
||||||
|
|
||||||
|
/* insert dummy cmd for now */
|
||||||
|
out_uint8(s, 0);
|
||||||
|
|
||||||
|
/* insert channel id */
|
||||||
|
cbChId = drdynvc_insert_uint_124(s, chan_id);
|
||||||
|
|
||||||
|
/* insert command */
|
||||||
|
s->data[0] = CMD_DVC_CLOSE_CHANNEL | cbChId;
|
||||||
|
|
||||||
|
/* send command */
|
||||||
|
bytes_in_stream = stream_length_before_p(s);
|
||||||
|
send_channel_data(g_drdynvc_chan_id, s->data, bytes_in_stream);
|
||||||
|
|
||||||
|
free_stream(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int APP_CC
|
||||||
|
drdynvc_process_close_channel_response(struct stream *s, unsigned char cmd)
|
||||||
|
{
|
||||||
|
uint32_t chan_id;
|
||||||
|
|
||||||
|
drdynvc_get_chan_id(s, cmd, &chan_id);
|
||||||
|
|
||||||
|
/* LK_TODO now do something using useful! */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* send data to client
|
||||||
|
*
|
||||||
|
* @param chan_id the virtual channel to write to
|
||||||
|
* @param data data to write
|
||||||
|
* @param data_size number of bytes to write
|
||||||
|
*
|
||||||
|
* @return 0 on success, -1 on failure
|
||||||
|
******************************************************************************/
|
||||||
|
int APP_CC drdynvc_write_data(uint32_t chan_id, char *data, int data_size)
|
||||||
|
{
|
||||||
|
struct stream *s;
|
||||||
|
char *saved_ptr;
|
||||||
|
int cbChId;
|
||||||
|
int Len;
|
||||||
|
int bytes_in_stream;
|
||||||
|
int frag_size;
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
{
|
||||||
|
LOG(0, ("drdynvc_write_data: data is NULL\n"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data_size <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
make_stream(s);
|
||||||
|
init_stream(s, MAX_PDU_SIZE);
|
||||||
|
|
||||||
|
/* this is a dummy write */
|
||||||
|
out_uint8(s, 0);
|
||||||
|
|
||||||
|
/* insert channel id */
|
||||||
|
cbChId = drdynvc_insert_uint_124(s, chan_id);
|
||||||
|
|
||||||
|
/* will data fit into one pkt? */
|
||||||
|
bytes_in_stream = stream_length_before_p(s);
|
||||||
|
|
||||||
|
if ((bytes_in_stream + data_size) <= MAX_PDU_SIZE)
|
||||||
|
{
|
||||||
|
/* yes it will - insert data */
|
||||||
|
out_uint8p(s, data, data_size);
|
||||||
|
|
||||||
|
/* insert command */
|
||||||
|
s->data[0] = CMD_DVC_DATA | cbChId;
|
||||||
|
|
||||||
|
/* write data to client */
|
||||||
|
bytes_in_stream = stream_length_before_p(s);
|
||||||
|
send_channel_data(g_drdynvc_chan_id, s->data, bytes_in_stream);
|
||||||
|
free_stream(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* no it won't - fragment it */
|
||||||
|
|
||||||
|
saved_ptr = s->p;
|
||||||
|
|
||||||
|
/* let client know how much data to expect */
|
||||||
|
Len = drdynvc_insert_uint_124(s, data_size);
|
||||||
|
|
||||||
|
/* insert data into first fragment */
|
||||||
|
frag_size = MAX_PDU_SIZE - stream_length_before_p(s);
|
||||||
|
out_uint8p(s, data, frag_size);
|
||||||
|
|
||||||
|
/* insert command */
|
||||||
|
s->data[0] = CMD_DVC_DATA_FIRST | Len << 2 | cbChId;
|
||||||
|
|
||||||
|
/* write first fragment to client */
|
||||||
|
bytes_in_stream = stream_length_before_p(s);
|
||||||
|
send_channel_data(g_drdynvc_chan_id, s->data, bytes_in_stream);
|
||||||
|
data_size -= frag_size;
|
||||||
|
data += frag_size;
|
||||||
|
s->data[0] = CMD_DVC_DATA | cbChId;
|
||||||
|
s->p = saved_ptr;
|
||||||
|
|
||||||
|
/* now send rest of the data using CMD_DVC_DATA */
|
||||||
|
while (data_size > 0)
|
||||||
|
{
|
||||||
|
frag_size = MAX_PDU_SIZE - stream_length_before_p(s);
|
||||||
|
|
||||||
|
if (frag_size > data_size)
|
||||||
|
{
|
||||||
|
frag_size = data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
out_uint8p(s, data, frag_size);
|
||||||
|
bytes_in_stream = stream_length_before_p(s);
|
||||||
|
send_channel_data(g_drdynvc_chan_id, s->data, bytes_in_stream);
|
||||||
|
data_size -= frag_size;
|
||||||
|
data += frag_size;
|
||||||
|
s->p = saved_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
free_stream(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int APP_CC
|
||||||
|
drdynvc_process_data_first(struct stream *s, unsigned char cmd)
|
||||||
|
{
|
||||||
|
struct xrdp_api_data *adp;
|
||||||
|
struct stream *ls;
|
||||||
|
|
||||||
|
uint32_t chan_id;
|
||||||
|
int bytes_in_stream;
|
||||||
|
int data_len;
|
||||||
|
int Len;
|
||||||
|
|
||||||
|
drdynvc_get_chan_id(s, cmd, &chan_id);
|
||||||
|
|
||||||
|
Len = (cmd >> 2) & 0x03;
|
||||||
|
|
||||||
|
if (Len == 0)
|
||||||
|
{
|
||||||
|
in_uint8(s, data_len);
|
||||||
|
}
|
||||||
|
else if (Len == 1)
|
||||||
|
{
|
||||||
|
in_uint16_le(s, data_len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in_uint32_le(s, data_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes_in_stream = stream_length_after_p(s);
|
||||||
|
|
||||||
|
/* get struct xrdp_api_data containing this channel id */
|
||||||
|
if ((adp = struct_from_dvc_chan_id(chan_id)) == NULL)
|
||||||
|
{
|
||||||
|
LOG(0, ("drdynvc_process_data_first: error : "
|
||||||
|
"could not find xrdp_api_data containing chan_id %d", chan_id));
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ls = trans_get_out_s(adp->transp, MAX_PDU_SIZE);
|
||||||
|
out_uint8p(ls, s->p, bytes_in_stream);
|
||||||
|
s_mark_end(ls);
|
||||||
|
trans_force_write(adp->transp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int APP_CC
|
||||||
|
drdynvc_process_data(struct stream *s, unsigned char cmd)
|
||||||
|
{
|
||||||
|
struct xrdp_api_data *adp;
|
||||||
|
struct stream *ls;
|
||||||
|
|
||||||
|
uint32_t chan_id;
|
||||||
|
int bytes_in_stream;
|
||||||
|
|
||||||
|
drdynvc_get_chan_id(s, cmd, &chan_id);
|
||||||
|
bytes_in_stream = stream_length_after_p(s);
|
||||||
|
|
||||||
|
/* get struct xrdp_api_data containing this channel id */
|
||||||
|
if ((adp = struct_from_dvc_chan_id(chan_id)) == NULL)
|
||||||
|
{
|
||||||
|
LOG(0, ("drdynvc_process_data: error : "
|
||||||
|
"could not find xrdp_api_data containing chan_id %d", chan_id));
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ls = trans_get_out_s(adp->transp, MAX_PDU_SIZE);
|
||||||
|
out_uint8p(ls, s->p, bytes_in_stream);
|
||||||
|
s_mark_end(ls);
|
||||||
|
trans_force_write(adp->transp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* process incoming data on a dynamic virtual channel
|
||||||
|
*
|
||||||
|
* @pram s stream containing the incoming data
|
||||||
|
* @pram chand_id LK_TODO
|
||||||
|
* @pram chan_flags LK_TODO
|
||||||
|
* @pram length LK_TODO
|
||||||
|
* @pram total_length LK_TODO
|
||||||
|
*
|
||||||
|
* @return 0 on success, -1 on failure
|
||||||
|
******************************************************************************/
|
||||||
|
int APP_CC
|
||||||
|
drdynvc_data_in(struct stream *s, int chan_id, int chan_flags, int length,
|
||||||
|
int total_length)
|
||||||
|
{
|
||||||
|
unsigned char cmd;
|
||||||
|
|
||||||
|
in_uint8(s, cmd); /* read command */
|
||||||
|
|
||||||
|
switch (cmd & 0xf0)
|
||||||
|
{
|
||||||
|
case CMD_DVC_CAPABILITY:
|
||||||
|
drdynvc_process_capability_response(s, cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_DVC_OPEN_CHANNEL:
|
||||||
|
drdynvc_process_open_channel_response(s, cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_DVC_CLOSE_CHANNEL:
|
||||||
|
drdynvc_process_close_channel_response(s, cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_DVC_DATA_FIRST:
|
||||||
|
drdynvc_process_data_first(s, cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_DVC_DATA:
|
||||||
|
drdynvc_process_data(s, cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
LOG(0, ("drdynvc_data_in: got unknown command 0x%x", cmd));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* insert a byte, short or 32bit value into specified stream
|
||||||
|
*
|
||||||
|
* @param s stream used for insertion
|
||||||
|
* @param val value to insert
|
||||||
|
*
|
||||||
|
* @return 0 for byte insertions
|
||||||
|
* @return 1 for short insertion
|
||||||
|
* @return 2 for uint32_t insertions
|
||||||
|
******************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
drdynvc_insert_uint_124(struct stream *s, uint32_t val)
|
||||||
|
{
|
||||||
|
int ret_val;
|
||||||
|
|
||||||
|
if (val <= 0xff)
|
||||||
|
{
|
||||||
|
out_uint8(s, val);
|
||||||
|
ret_val = 0;
|
||||||
|
}
|
||||||
|
else if (val <= 0xffff)
|
||||||
|
{
|
||||||
|
out_uint16_le(s, val);
|
||||||
|
ret_val = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out_uint32_le(s, val);
|
||||||
|
ret_val = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* extract channel id from stream
|
||||||
|
*
|
||||||
|
* @param s stream containing channel id
|
||||||
|
* @param cmd first byte in stream
|
||||||
|
* @param chan_id return channel id here
|
||||||
|
******************************************************************************/
|
||||||
|
static int APP_CC
|
||||||
|
drdynvc_get_chan_id(struct stream *s, char cmd, uint32_t *chan_id_p)
|
||||||
|
{
|
||||||
|
int cbChId;
|
||||||
|
int chan_id;
|
||||||
|
|
||||||
|
cbChId = cmd & 0x03;
|
||||||
|
|
||||||
|
if (cbChId == 0)
|
||||||
|
{
|
||||||
|
in_uint8(s, chan_id);
|
||||||
|
}
|
||||||
|
else if (cbChId == 1)
|
||||||
|
{
|
||||||
|
in_uint16_le(s, chan_id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in_uint32_le(s, chan_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
*chan_id_p = chan_id;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* xrdp: A Remote Desktop Protocol server.
|
* xrdp: A Remote Desktop Protocol server.
|
||||||
*
|
*
|
||||||
* Copyright (C) Jay Sorg 2012
|
* Copyright (C) Laxmikant Rashinkar 2012 LK.Rashinkar@gmail.com
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -16,10 +16,72 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(DRDYNVC_H)
|
#ifndef _DRDYNVC_H_
|
||||||
#define DRDYNVC_H
|
#define _DRDYNVC_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "parse.h"
|
#include "chansrv.h"
|
||||||
|
#include "xcommon.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "os_calls.h"
|
||||||
|
#include "trans.h"
|
||||||
|
|
||||||
|
/* move this to tsmf.c */
|
||||||
|
#define TSMF_CHAN_ID 0x1000
|
||||||
|
|
||||||
|
/* get number of bytes in stream before s->p */
|
||||||
|
#define stream_length_before_p(s) (int) ((s)->p - (s)->data)
|
||||||
|
|
||||||
|
/* get number of bytes in stream after s->p */
|
||||||
|
#define stream_length_after_p(s) (int) ((s)->end - (s)->p)
|
||||||
|
|
||||||
|
#define rewind_stream(s) do \
|
||||||
|
{ \
|
||||||
|
(s)->p = (s)->data; \
|
||||||
|
(s)->end = (s)->data; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* max number of bytes we can send in one pkt */
|
||||||
|
#define MAX_PDU_SIZE 1600
|
||||||
|
|
||||||
|
/* commands used to manage dynamic virtual channels */
|
||||||
|
#define CMD_DVC_OPEN_CHANNEL 0x10
|
||||||
|
#define CMD_DVC_DATA_FIRST 0x20
|
||||||
|
#define CMD_DVC_DATA 0x30
|
||||||
|
#define CMD_DVC_CLOSE_CHANNEL 0x40
|
||||||
|
#define CMD_DVC_CAPABILITY 0x50
|
||||||
|
|
||||||
|
int APP_CC drdynvc_init(void);
|
||||||
|
|
||||||
|
static int APP_CC drdynvc_send_capability_request(uint16_t version);
|
||||||
|
static int APP_CC drdynvc_process_capability_response(struct stream* s,
|
||||||
|
unsigned char cmd);
|
||||||
|
|
||||||
|
int APP_CC drdynvc_send_open_channel_request(int chan_pri, unsigned int chan_id,
|
||||||
|
char *chan_name);
|
||||||
|
|
||||||
|
static int APP_CC drdynvc_process_open_channel_response(struct stream *s,
|
||||||
|
unsigned char cmd);
|
||||||
|
|
||||||
|
int APP_CC drdynvc_send_close_channel_request(unsigned int chan_id);
|
||||||
|
|
||||||
|
static int APP_CC drdynvc_process_close_channel_response(struct stream *s,
|
||||||
|
unsigned char cmd);
|
||||||
|
|
||||||
|
int APP_CC drdynvc_write_data(uint32_t chan_id, char *data, int data_size);
|
||||||
|
|
||||||
|
int APP_CC drdynvc_data_in(struct stream* s, int chan_id, int chan_flags,
|
||||||
|
int length, int total_length);
|
||||||
|
|
||||||
|
static int APP_CC drdynvc_process_data_first(struct stream* s, unsigned char cmd);
|
||||||
|
static int APP_CC drdynvc_process_data(struct stream* s, unsigned char cmd);
|
||||||
|
|
||||||
|
static int APP_CC drdynvc_insert_uint_124(struct stream *s, uint32_t val);
|
||||||
|
static int APP_CC drdynvc_get_chan_id(struct stream *s, char cmd, uint32_t *chan_id_p);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
||||||
|
@ -25,16 +25,17 @@
|
|||||||
#include "clipboard.h"
|
#include "clipboard.h"
|
||||||
#include "rail.h"
|
#include "rail.h"
|
||||||
|
|
||||||
|
#undef LOG_LEVEL
|
||||||
|
#define LOG_LEVEL 11
|
||||||
|
|
||||||
extern int g_clip_up; /* in clipboard.c */
|
extern int g_clip_up; /* in clipboard.c */
|
||||||
extern int g_waiting_for_data_response; /* in clipboard.c */
|
|
||||||
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 +43,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 +59,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 +72,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 +80,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 +126,44 @@ 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"));
|
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 clip_rv;
|
||||||
int clip_rv;
|
int rail_rv;
|
||||||
int rail_rv;
|
|
||||||
|
|
||||||
if ((!g_clip_up) && (!g_rail_up))
|
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 */
|
return 0;
|
||||||
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)
|
while (XPending(g_display) > 0)
|
||||||
{
|
{
|
||||||
g_memset(&xevent, 0, sizeof(xevent));
|
g_memset(&xevent, 0, sizeof(xevent));
|
||||||
XNextEvent(g_display, &xevent);
|
XNextEvent(g_display, &xevent);
|
||||||
|
clip_rv = clipboard_xevent(&xevent);
|
||||||
clip_rv = clipboard_xevent(&xevent);
|
rail_rv = rail_xevent(&xevent);
|
||||||
rail_rv = rail_xevent(&xevent);
|
if ((clip_rv == 1) && (rail_rv == 1))
|
||||||
if ((clip_rv == 1) && (rail_rv == 1))
|
{
|
||||||
{
|
LOG(10, ("xcommon_check_wait_objs unknown xevent type %d",
|
||||||
LOG(10, ("xcommon_check_wait_objs unknown xevent type %d", xevent.type));
|
xevent.type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
|
|
||||||
|
/* 32 implies long */
|
||||||
|
#define FORMAT_TO_BYTES(_format) \
|
||||||
|
(_format) == 32 ? sizeof(long) : (_format) / 8
|
||||||
|
|
||||||
int APP_CC
|
int APP_CC
|
||||||
xcommon_get_local_time(void);
|
xcommon_get_local_time(void);
|
||||||
int APP_CC
|
int APP_CC
|
||||||
|
580
sesman/config.c
580
sesman/config.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
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
@ -184,7 +190,7 @@ config_read_logging(int file, struct log_config* lc, struct list* param_n,
|
|||||||
list_clear(param_v);
|
list_clear(param_v);
|
||||||
list_clear(param_n);
|
list_clear(param_n);
|
||||||
|
|
||||||
// setting defaults
|
// setting defaults
|
||||||
lc->program_name = g_strdup("sesman");
|
lc->program_name = g_strdup("sesman");
|
||||||
lc->log_file = 0;
|
lc->log_file = 0;
|
||||||
lc->fd = 0;
|
lc->fd = 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
193
sesman/env.c
193
sesman/env.c
@ -1,28 +1,27 @@
|
|||||||
/*
|
/**
|
||||||
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
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @file env.c
|
* @file env.c
|
||||||
* @brief User environment handling code
|
* @brief User environment handling code
|
||||||
* @author Jay Sorg
|
* @author Jay Sorg
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sesman.h"
|
#include "sesman.h"
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
40
sesman/env.h
40
sesman/env.h
@ -1,28 +1,27 @@
|
|||||||
/*
|
/**
|
||||||
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
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @file env.h
|
* @file env.h
|
||||||
* @brief User environment handling code declarations
|
* @brief User environment handling code declarations
|
||||||
* @author Jay Sorg
|
* @author Jay Sorg
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ENV_H
|
#ifndef ENV_H
|
||||||
@ -42,7 +41,7 @@ env_check_password_file(char* filename, char* password);
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @brief Sets user environment ($PATH, $HOME, $UID, and others)
|
* @brief Sets user environment ($PATH, $HOME, $UID, and others)
|
||||||
* @param username Username
|
* @param username Username
|
||||||
* @param passwd_file VNC password file
|
* @param passwd_file VNC password file
|
||||||
* @param display The session display
|
* @param display The session display
|
||||||
* @return 0 on success, g_getuser_info() error codes on error
|
* @return 0 on success, g_getuser_info() error codes on error
|
||||||
@ -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
|
||||||
|
|
||||||
|
@ -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,28 +1,27 @@
|
|||||||
/*
|
/**
|
||||||
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
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @file libscp_connection.h
|
* @file libscp_connection.h
|
||||||
* @brief SCP_CONNECTION handling code
|
* @brief SCP_CONNECTION handling code
|
||||||
* @author Simone Fedele
|
* @author Simone Fedele
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBSCP_CONNECTION_H
|
#ifndef LIBSCP_CONNECTION_H
|
||||||
@ -37,7 +36,7 @@
|
|||||||
*
|
*
|
||||||
* @return a struct SCP_CONNECTION* object on success, NULL otherwise
|
* @return a struct SCP_CONNECTION* object on success, NULL otherwise
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
struct SCP_CONNECTION*
|
struct SCP_CONNECTION*
|
||||||
scp_connection_create(int sck);
|
scp_connection_create(int sck);
|
||||||
|
|
||||||
@ -45,10 +44,9 @@ scp_connection_create(int sck);
|
|||||||
*
|
*
|
||||||
* @brief destroys a struct SCP_CONNECTION* object
|
* @brief destroys a struct SCP_CONNECTION* object
|
||||||
* @param c the object to be destroyed
|
* @param c the object to be destroyed
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
scp_connection_destroy(struct SCP_CONNECTION* c);
|
scp_connection_destroy(struct SCP_CONNECTION* c);
|
||||||
|
|
||||||
#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
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
/*
|
/**
|
||||||
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
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @file libscp_init.h
|
* @file libscp_init.h
|
||||||
* @brief libscp initialization code header
|
* @brief libscp initialization code header
|
||||||
* @author Simone Fedele
|
* @author Simone Fedele
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBSCP_INIT_H
|
#ifndef LIBSCP_INIT_H
|
||||||
@ -41,8 +40,7 @@
|
|||||||
* It this memory needs to be g_free()d
|
* It this memory needs to be g_free()d
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int DEFAULT_CC
|
int DEFAULT_CC
|
||||||
scp_init();
|
scp_init();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
Loading…
Reference in New Issue
Block a user