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 { "gfx-progressive", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
99 "Allow GFX progressive codec" },
100 { "gfx-rfx", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
101 "Allow GFX RFX codec" },
102 { "gfx-planar", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
103 "Allow GFX planar codec" },
104 { "gfx-avc420", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
105 "Allow GFX AVC420 codec" },
106 { "gfx-avc444", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueTrue, nullptr, -1, nullptr,
107 "Allow GFX AVC444 codec" },
108 { "bitmap-compat", COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueFalse, nullptr, -1, nullptr,
109 "Limit BitmapUpdate to 1 rectangle (fixes broken windows 11 24H2 clients)" },
110 { "version", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_VERSION, nullptr, nullptr,
111 nullptr, -1, nullptr, "Print version" },
112 { "buildconfig", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_BUILDCONFIG, nullptr, nullptr,
113 nullptr, -1, nullptr, "Print the build configuration" },
114 { "help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, nullptr, nullptr, nullptr, -1,
115 "?", "Print help" },
116 { nullptr, 0, nullptr, nullptr, nullptr, -1, nullptr, nullptr }
117 };
118
119 shadow_subsystem_set_entry_builtin(nullptr);
120
121 rdpShadowServer* server = shadow_server_new();
122
123 if (!server)
124 {
125 status = -1;
126 WLog_ERR(TAG, "Server new failed");
127 goto fail;
128 }
129
130 {
131 rdpSettings* settings = server->settings;
132 WINPR_ASSERT(settings);
133
134 if (!freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, TRUE) ||
135 !freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE) ||
136 !freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE))
137 goto fail;
138
139 /* By default allow all GFX modes.
140 * This can be changed with command line flags [+|-]gfx-CODEC
141 */
142 if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32) ||
143 !freerdp_settings_set_bool(settings, FreeRDP_NSCodec, TRUE) ||
144 !freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE) ||
145 !freerdp_settings_set_bool(settings, FreeRDP_RemoteFxImageCodec, TRUE) ||
146 !freerdp_settings_set_uint32(settings, FreeRDP_RemoteFxRlgrMode, RLGR3) ||
147 !freerdp_settings_set_bool(settings, FreeRDP_GfxH264, TRUE) ||
148 !freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444, TRUE) ||
149 !freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444v2, TRUE) ||
150 !freerdp_settings_set_bool(settings, FreeRDP_GfxProgressive, TRUE) ||
151 !freerdp_settings_set_bool(settings, FreeRDP_GfxProgressiveV2, TRUE))
152 goto fail;
153
154 if (!freerdp_settings_set_bool(settings, FreeRDP_MouseUseRelativeMove, FALSE) ||
155 !freerdp_settings_set_bool(settings, FreeRDP_HasRelativeMouseEvent, FALSE))
156 goto fail;
157 }
158
159 if ((status = shadow_server_parse_command_line(server, argc, argv, shadow_args)) < 0)
160 {
161 status = shadow_server_command_line_status_print(server, argc, argv, status, shadow_args);
162 goto fail;
163 }
164
165 if ((status = shadow_server_init(server)) < 0)
166 {
167 WLog_ERR(TAG, "Server initialization failed.");
168 goto fail;
169 }
170
171 if ((status = shadow_server_start(server)) < 0)
172 {
173 WLog_ERR(TAG, "Failed to start server.");
174 goto fail;
175 }
176
177#ifdef _WIN32
178 {
179 MSG msg = WINPR_C_ARRAY_INIT;
180 while (GetMessage(&msg, 0, 0, 0))
181 {
182 TranslateMessage(&msg);
183 DispatchMessage(&msg);
184 }
185 }
186#endif
187
188 (void)WaitForSingleObject(server->thread, INFINITE);
189
190 if (!GetExitCodeThread(server->thread, &dwExitCode))
191 status = -1;
192 else
193 status = (int)dwExitCode;
194
195fail:
196 shadow_server_uninit(server);
197 shadow_server_free(server);
198 return status;
199}
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 val)
Sets a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL val)
Sets a BOOL settings value.