FreeRDP
Loading...
Searching...
No Matches
shadow.c
1
19#include <freerdp/config.h>
20
21#include <winpr/crt.h>
22#include <winpr/ssl.h>
23#include <winpr/path.h>
24#include <winpr/cmdline.h>
25#include <winpr/winsock.h>
26
27#include <winpr/tools/makecert.h>
28
29#include <freerdp/server/shadow.h>
30#include <freerdp/settings.h>
31
32#include <freerdp/log.h>
33#define TAG SERVER_TAG("shadow")
34
35int main(int argc, char** argv)
36{
37 int status = 0;
38 DWORD dwExitCode = 0;
39 COMMAND_LINE_ARGUMENT_A shadow_args[] = {
40 { "log-filters", COMMAND_LINE_VALUE_REQUIRED, "<tag>:<level>[,<tag>:<level>[,...]]",
41 nullptr, nullptr, -1, nullptr, "Set logger filters, see wLog(7) for details" },
42 { "log-level", COMMAND_LINE_VALUE_REQUIRED, "[OFF|FATAL|ERROR|WARN|INFO|DEBUG|TRACE]",
43 nullptr, nullptr, -1, nullptr, "Set the default log level, see wLog(7) for details" },
44 { "port", COMMAND_LINE_VALUE_REQUIRED, "<number>", nullptr, nullptr, -1, nullptr,
45 "Server port" },
46 { "ipc-socket", COMMAND_LINE_VALUE_REQUIRED, "<ipc-socket>", nullptr, nullptr, -1, nullptr,
47 "Server IPC socket" },
48 { "bind-address", COMMAND_LINE_VALUE_REQUIRED, "<bind-address>[,<another address>, ...]",
49 nullptr, nullptr, -1, nullptr,
50 "An address to bind to. Use '[<ipv6>]' for IPv6 addresses, e.g. '[::1]' for "
51 "localhost" },
52 { "server-side-cursor", COMMAND_LINE_VALUE_BOOL, nullptr, nullptr, nullptr, -1, nullptr,
53 "hide mouse cursor in RDP client." },
54 { "monitors", COMMAND_LINE_VALUE_OPTIONAL, "<0,1,2...>", nullptr, nullptr, -1, nullptr,
55 "Select or list monitors" },
56 { "max-connections", COMMAND_LINE_VALUE_REQUIRED, "<number>", nullptr, nullptr, -1, nullptr,
57 "maximum connections allowed to server, 0 to deactivate" },
58 { "mouse-relative", COMMAND_LINE_VALUE_BOOL, nullptr, nullptr, nullptr, -1, nullptr,
59 "enable support for relative mouse events" },
60 { "rect", COMMAND_LINE_VALUE_REQUIRED, "<x,y,w,h>", nullptr, nullptr, -1, nullptr,
61 "Select rectangle within monitor to share" },
62 { "auth", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
63 "Clients must authenticate" },
64 { "remote-guard", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueFalse, nullptr, -1, nullptr,
65 "Remote credential guard" },
66 { "restricted-admin", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
67 "Restricted Admin" },
68 { "vmconnect", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueFalse,
69 nullptr, -1, nullptr, "Hyper-V console server (bind on vsock://1)" },
70 { "may-view", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
71 "Clients may view without prompt" },
72 { "may-interact", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
73 "Clients may interact without prompt" },
74 { "sec", COMMAND_LINE_VALUE_REQUIRED, "<rdp|tls|nla|ext>", nullptr, nullptr, -1, nullptr,
75 "force specific protocol security" },
76 { "sec-rdp", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
77 "rdp protocol security" },
78 { "sec-tls", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
79 "tls protocol security" },
80 { "sec-nla", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
81 "nla protocol security" },
82 { "sec-ext", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueFalse, nullptr, -1, nullptr,
83 "nla extended protocol security" },
84 { "sam-file", COMMAND_LINE_VALUE_REQUIRED, "<file>", nullptr, nullptr, -1, nullptr,
85 "NTLM SAM file for NLA authentication" },
86 { "keytab", COMMAND_LINE_VALUE_REQUIRED, "<file>", nullptr, nullptr, -1, nullptr,
87 "Kerberos keytab file for NLA authentication" },
88 { "ccache", COMMAND_LINE_VALUE_REQUIRED, "<file>", nullptr, nullptr, -1, nullptr,
89 "Kerberos host ccache file for NLA authentication" },
90 { "tls-secrets-file", COMMAND_LINE_VALUE_REQUIRED, "<file>", nullptr, nullptr, -1, nullptr,
91 "file where tls secrets shall be stored" },
92 { "nsc", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
93 "Allow NSC codec" },
94 { "rfx", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
95 "Allow RFX surface bits" },
96 { "gfx", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
97 "Allow GFX pipeline" },
98#if defined(WITH_GFX_AV1)
99 { "gfx-av1", COMMAND_LINE_VALUE_OPTIONAL, "[:profile:[low|high|0|1]|off]", BoolValueTrue,
100 nullptr, -1, nullptr, "Allow GFX pipeline AV1 codec extension" },
101#endif
102 { "gfx-progressive", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
103 "Allow GFX progressive codec" },
104 { "gfx-rfx", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
105 "Allow GFX RFX codec" },
106 { "gfx-planar", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
107 "Allow GFX planar codec" },
108 { "gfx-avc420", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
109 "Allow GFX AVC420 codec" },
110 { "gfx-avc444", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
111 "Allow GFX AVC444 codec" },
112 { "bitmap-compat", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueFalse, nullptr, -1, nullptr,
113 "Limit BitmapUpdate to 1 rectangle (fixes broken windows 11 24H2 clients)" },
114 { "version", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_VERSION, nullptr, nullptr,
115 nullptr, -1, nullptr, "Print version" },
116 { "buildconfig", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_BUILDCONFIG, nullptr, nullptr,
117 nullptr, -1, nullptr, "Print the build configuration" },
118 { "help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, nullptr, nullptr, nullptr, -1,
119 "?", "Print help" },
120 { nullptr, 0, nullptr, nullptr, nullptr, -1, nullptr, nullptr }
121 };
122
123 shadow_subsystem_set_entry_builtin(nullptr);
124
125 rdpShadowServer* server = shadow_server_new();
126
127 if (!server)
128 {
129 status = -1;
130 WLog_ERR(TAG, "Server new failed");
131 goto fail;
132 }
133
134 {
135 rdpSettings* settings = server->settings;
136 WINPR_ASSERT(settings);
137
138 if (!freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, TRUE) ||
139 !freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE) ||
140 !freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE))
141 goto fail;
142
143 /* By default allow all GFX modes.
144 * This can be changed with command line flags [+|-]gfx-CODEC
145 */
146 if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32) ||
147 !freerdp_settings_set_bool(settings, FreeRDP_NSCodec, TRUE) ||
148 !freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE) ||
149 !freerdp_settings_set_bool(settings, FreeRDP_RemoteFxImageCodec, TRUE) ||
150 !freerdp_settings_set_uint32(settings, FreeRDP_RemoteFxRlgrMode, RLGR3) ||
151 !freerdp_settings_set_bool(settings, FreeRDP_GfxH264, TRUE) ||
152 !freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444, TRUE) ||
153 !freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444v2, TRUE) ||
154 !freerdp_settings_set_bool(settings, FreeRDP_GfxProgressive, TRUE) ||
155 !freerdp_settings_set_bool(settings, FreeRDP_GfxProgressiveV2, TRUE))
156 goto fail;
157
158 if (!freerdp_settings_set_bool(settings, FreeRDP_MouseUseRelativeMove, FALSE) ||
159 !freerdp_settings_set_bool(settings, FreeRDP_HasRelativeMouseEvent, FALSE))
160 goto fail;
161 }
162
163 if ((status = shadow_server_parse_command_line(server, argc, argv, shadow_args)) < 0)
164 {
165 status = shadow_server_command_line_status_print(server, argc, argv, status, shadow_args);
166 goto fail;
167 }
168
169 if ((status = shadow_server_init(server)) < 0)
170 {
171 WLog_ERR(TAG, "Server initialization failed.");
172 goto fail;
173 }
174
175 if ((status = shadow_server_start(server)) < 0)
176 {
177 WLog_ERR(TAG, "Failed to start server.");
178 goto fail;
179 }
180
181#ifdef _WIN32
182 {
183 MSG msg = WINPR_C_ARRAY_INIT;
184 while (GetMessage(&msg, 0, 0, 0))
185 {
186 TranslateMessage(&msg);
187 DispatchMessage(&msg);
188 }
189 }
190#endif
191
192 (void)WaitForSingleObject(server->thread, INFINITE);
193
194 if (!GetExitCodeThread(server->thread, &dwExitCode))
195 status = -1;
196 else
197 status = (int)dwExitCode;
198
199fail:
200 shadow_server_uninit(server);
201 shadow_server_free(server);
202 return status;
203}
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL val)
Sets a BOOL settings value.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 val)
Sets a UINT32 settings value.