Skip to content

Commit b6186ea

Browse files
Simul PiscatorSimul Piscator
Simul Piscator
authored and
Simul Piscator
committed
Initial commit
1 parent 8255add commit b6186ea

12 files changed

+1529
-0
lines changed

CMakeLists.txt

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# RDPShare: Windows Desktop Sharing remote control interface
3+
#
4+
# Copyright 2016 Simul Piscator
5+
#
6+
# RDPShare is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# RDPShare is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with RDPShare. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
cmake_minimum_required( VERSION 3.0 )
20+
cmake_policy( VERSION 3.0 )
21+
22+
project( RDPShare VERSION 0.1.0 )
23+
24+
add_definitions( -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE )
25+
foreach(flag_var
26+
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
27+
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
28+
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
29+
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
30+
)
31+
if(${flag_var} MATCHES "/MD")
32+
string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
33+
endif()
34+
endforeach()
35+
36+
add_executable( RDPShare WIN32
37+
RDPShare.cpp
38+
Guids.cpp
39+
Sharer.cpp
40+
Sharer.h
41+
RDPSessionEvents.h
42+
Utils.cpp
43+
Utils.h
44+
RDPFile.cpp
45+
RDPFile.h
46+
Server.cpp
47+
Server.h
48+
)
49+
target_link_libraries( RDPShare ws2_32 shlwapi )

Guids.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* RDPShare: Windows Desktop Sharing remote control interface
3+
*
4+
* Copyright 2016 Simul Piscator
5+
*
6+
* RDPShare is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* RDPShare is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with RDPShare. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include <Windows.h>
20+
#include <RdpEncomAPI.h>
21+
22+
#include <initguid.h>
23+
DEFINE_GUID(CLSID_RDPSession, 0x9B78F0E6, 0x3E05, 0x4A5B, 0xB2, 0xE8, 0xE7, 0x43, 0xA8, 0x95, 0x6B, 0x65);
24+
DEFINE_GUID(DIID__IRDPSessionEvents, 0x98a97042, 0x6698, 0x40e9, 0x8e, 0xfd, 0xb3, 0x20, 0x09, 0x90, 0x00, 0x4b);
25+
DEFINE_GUID(IID_IRDPSRAPISharingSession, 0xeeb20886, 0xe470, 0x4cf6, 0x84, 0x2b, 0x27, 0x39, 0xc0, 0xec, 0x5c, 0xfb);
26+
DEFINE_GUID(IID_IRDPSRAPIAttendee, 0xec0671b3, 0x1b78, 0x4b80, 0xa4, 0x64, 0x91, 0x32, 0x24, 0x75, 0x43, 0xe3);
27+
DEFINE_GUID(IID_IRDPSRAPIAttendeeManager, 0xba3a37e8, 0x33da, 0x4749, 0x8d, 0xa0, 0x07, 0xfa, 0x34, 0xda, 0x79, 0x44);
28+
DEFINE_GUID(IID_IRDPSRAPISessionProperties, 0x339b24f2, 0x9bc0, 0x4f16, 0x9a, 0xac, 0xf1, 0x65, 0x43, 0x3d, 0x13, 0xd4);
29+
DEFINE_GUID(CLSID_RDPSRAPIApplicationFilter, 0xe35ace89, 0xc7e8, 0x427e, 0xa4, 0xf9, 0xb9, 0xda, 0x07, 0x28, 0x26, 0xbd);
30+
DEFINE_GUID(CLSID_RDPSRAPIInvitationManager, 0x53d9c9db, 0x75ab, 0x4271, 0x94, 0x8a, 0x4c, 0x4e, 0xb3, 0x6a, 0x8f, 0x2b);

RDPFile.cpp

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* RDPShare: Windows Desktop Sharing remote control interface
3+
*
4+
* Copyright 2016 Simul Piscator
5+
*
6+
* RDPShare is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* RDPShare is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with RDPShare. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "RDPFile.h"
20+
#include "Utils.h"
21+
#include <vector>
22+
#include <sstream>
23+
#include <ctime>
24+
25+
static void ParseConnectionString(
26+
const std::string& s,
27+
std::string& RASpecificParams,
28+
std::string& RASessionID,
29+
std::vector<std::pair<std::string,std::string>>& Addresses
30+
)
31+
{
32+
size_t begin = s.find("KH=\""), end = begin;
33+
if (begin != s.npos)
34+
{
35+
begin = s.find('"', begin) + 1;
36+
end = s.find('"', begin);
37+
RASpecificParams = s.substr(begin, end - begin);
38+
}
39+
begin = s.find("ID=\""), end = begin;
40+
if (begin != s.npos)
41+
{
42+
begin = s.find('"', begin) + 1;
43+
end = s.find('"', begin);
44+
RASessionID = s.substr(begin, end - begin);
45+
}
46+
begin = 0, end = 0;
47+
while ((begin = s.find("<L P=\"", end)) != s.npos)
48+
{
49+
begin = s.find('"', begin) + 1;
50+
end = s.find('"', begin);
51+
std::string port = s.substr(begin, end - begin);
52+
begin = s.find("N=\"", end);
53+
if (begin != s.npos)
54+
{
55+
begin = s.find('"', begin) + 1;
56+
end = s.find('"', begin);
57+
Addresses.push_back( std::make_pair(s.substr(begin, end - begin),port) );
58+
}
59+
}
60+
if (RASpecificParams.empty() || RASessionID.empty() || Addresses.empty())
61+
throw std::string("Failed to parse connection string");
62+
}
63+
64+
bool
65+
ParseConnectionString(const std::string& inString, RemoteAssistanceInfo& outInfo)
66+
{
67+
std::string RASpecificParams;
68+
std::vector<std::pair<std::string, std::string>> Addresses;
69+
ParseConnectionString(inString, RASpecificParams, outInfo.SessionID, Addresses);
70+
outInfo.IP = Addresses.back().first;
71+
outInfo.Port = Addresses.back().second;
72+
return true;
73+
}
74+
75+
#if 0
76+
std::string
77+
CreateRdpFile(const std::string& s, int width, int height, bool freerdpworkaround)
78+
{
79+
std::string RASessionID, RASpecificParams;
80+
std::vector<std::pair<std::string,std::string>> Addresses;
81+
ParseConnectionString(s, RASpecificParams, RASessionID, Addresses);
82+
83+
std::ostringstream rdpfile;
84+
if (freerdpworkaround)
85+
rdpfile
86+
// including port into full address triggers a bug in FreeRDP 1.1, so always use server port field for port
87+
<< "full address:s:" << Addresses.back().first << "\n"
88+
<< "server port:i:" << Addresses.back().second << "\n";
89+
else // ms clients seem to ignore server port field if full address is given
90+
rdpfile
91+
<< "full address:s:" << Addresses.back().first << ":" << Addresses.back().second << "\n";
92+
rdpfile
93+
<< "alternate shell:s:\n"
94+
<< "shell working directory:s:" << RASessionID << "\n"
95+
<< "authentication level:i:0\n"
96+
<< "audiomode:i:2\n"
97+
<< "prompt for credentials on client:i:0\n";
98+
if (freerdpworkaround)
99+
rdpfile
100+
<< "smart sizing:i:0\n"; // 1 doesn't work properly with FreeRDP 1.1
101+
else
102+
rdpfile
103+
<< "smart sizing:i:1\n";
104+
rdpfile
105+
<< "screen mode id:i:1\n" // window
106+
<< "username:s:rdpshare\n" // we don't care
107+
<< "desktopwidth:i:" << width << "\n"
108+
<< "desktopheight:i:" << height << "\n";
109+
;
110+
return rdpfile.str();
111+
}
112+
113+
std::string RdpFileToUri(const std::string& s)
114+
{
115+
std::string uri = "rdp://";
116+
std::istringstream iss(s);
117+
std::string line;
118+
while(getline(iss, line))
119+
{
120+
size_t pos1 = line.find(':'), pos2 = line.find(':', pos1 + 1);
121+
uri += UrlEscape_(line.substr(0,pos1));
122+
uri += "=";
123+
uri += line.substr(pos1 + 1, pos2 - pos1);
124+
uri += UrlEscape_(line.substr(pos2 + 1),".:=");
125+
uri += "&";
126+
}
127+
uri.pop_back();
128+
return uri;
129+
}
130+
131+
std::string RdpFileToCmdline(const std::string& s)
132+
{
133+
std::string cmd;
134+
std::istringstream iss(s);
135+
std::string line;
136+
while (getline(iss, line))
137+
{
138+
size_t pos1 = line.find(':'), pos2 = line.find(':', pos1 + 1);
139+
std::string var = line.substr(0, pos1), val = line.substr(pos2 + 1);
140+
if (var == "full address")
141+
cmd += "\"/v:" + val + "\" ";
142+
else if( var == "shell working directory")
143+
cmd += "\"/shell-dir:" + val + "\" ";
144+
}
145+
return cmd;
146+
}
147+
148+
std::string CreateTicket(const std::string& s)
149+
{
150+
std::string RASessionID, RASpecificParams, AddressList;
151+
std::vector<std::pair<std::string, std::string>> Addresses;
152+
ParseConnectionString(s, RASpecificParams, RASessionID, Addresses);
153+
for (const auto& address : Addresses)
154+
AddressList += ";" + address.first + ":" + address.second;
155+
156+
std::ostringstream ticket;
157+
ticket << "<?xml version=\"1.0\"?>\r\n"
158+
<< "<UPLOADINFO TYPE=\"Escalated\"> "
159+
<< "<UPLOADDATA USERNAME=\"rdpshare\" "
160+
<< "RCTICKET=\"65538,1,"
161+
<< AddressList.substr(1) << ",*," << RASessionID << ",*,*," << RASpecificParams << "\" "
162+
<< "RCTICKETENCRYPTED=\"0\" "
163+
<< "DtStart=\"" << ::time(nullptr) << "\" "
164+
<< "DtLength=\"" << INT32_MAX << "\" "
165+
<< "L=\"0\""
166+
<< "/>"
167+
<< "</UPLOADINFO>\r\n";
168+
return ticket.str();
169+
}
170+
171+
#endif

RDPFile.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* RDPShare: Windows Desktop Sharing remote control interface
3+
*
4+
* Copyright 2016 Simul Piscator
5+
*
6+
* RDPShare is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* RDPShare is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with RDPShare. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#ifndef RDP_FILE_H
20+
#define RDP_FILE_H
21+
22+
#include<string>
23+
24+
struct RemoteAssistanceInfo
25+
{
26+
std::string IP, Port, SessionID;
27+
};
28+
29+
bool ParseConnectionString(const std::string&, RemoteAssistanceInfo&);
30+
std::string CreateTicket(const std::string& connectionString);
31+
std::string CreateRdpFile(const std::string&, int, int, bool freerdpworkaround);
32+
std::string RdpFileToUri(const std::string&);
33+
34+
#endif // RDP_FILE_H

0 commit comments

Comments
 (0)