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