FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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 { "restricted-admin", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
66 "Restricted Admin" },
67 { "vmconnect", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse,
68 NULL, -1, NULL, "Hyper-V console server (bind on vsock://1)" },
69 { "may-view", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
70 "Clients may view without prompt" },
71 { "may-interact", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
72 "Clients may interact without prompt" },
73 { "sec", COMMAND_LINE_VALUE_REQUIRED, "<rdp|tls|nla|ext>", NULL, NULL, -1, NULL,
74 "force specific protocol security" },
75 { "sec-rdp", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
76 "rdp protocol security" },
77 { "sec-tls", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
78 "tls protocol security" },
79 { "sec-nla", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
80 "nla protocol security" },
81 { "sec-ext", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL,
82 "nla extended protocol security" },
83 { "sam-file", COMMAND_LINE_VALUE_REQUIRED, "<file>", NULL, NULL, -1, NULL,
84 "NTLM SAM file for NLA authentication" },
85 { "keytab", COMMAND_LINE_VALUE_REQUIRED, "<file>", NULL, NULL, -1, NULL,
86 "Kerberos keytab file for NLA authentication" },
87 { "ccache", COMMAND_LINE_VALUE_REQUIRED, "<file>", NULL, NULL, -1, NULL,
88 "Kerberos host ccache file for NLA authentication" },
89 { "tls-secrets-file", COMMAND_LINE_VALUE_REQUIRED, "<file>", NULL, NULL, -1, NULL,
90 "file where tls secrets shall be stored" },
91 { "nsc", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "Allow NSC codec" },
92 { "rfx", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
93 "Allow RFX surface bits" },
94 { "gfx", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
95 "Allow GFX pipeline" },
96 { "gfx-progressive", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
97 "Allow GFX progressive codec" },
98 { "gfx-rfx", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
99 "Allow GFX RFX codec" },
100 { "gfx-planar", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
101 "Allow GFX planar codec" },
102 { "gfx-avc420", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
103 "Allow GFX AVC420 codec" },
104 { "gfx-avc444", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
105 "Allow GFX AVC444 codec" },
106 { "bitmap-compat", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL,
107 "Limit BitmapUpdate to 1 rectangle (fixes broken windows 11 24H2 clients)" },
108 { "version", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_VERSION, NULL, NULL, NULL, -1,
109 NULL, "Print version" },
110 { "buildconfig", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_BUILDCONFIG, NULL, NULL, NULL,
111 -1, NULL, "Print the build configuration" },
112 { "help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, NULL, NULL, NULL, -1, "?",
113 "Print help" },
114 { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
115 };
116
117 shadow_subsystem_set_entry_builtin(NULL);
118
119 rdpShadowServer* server = shadow_server_new();
120
121 if (!server)
122 {
123 status = -1;
124 WLog_ERR(TAG, "Server new failed");
125 goto fail;
126 }
127
128 rdpSettings* settings = server->settings;
129 WINPR_ASSERT(settings);
130
131 if (!freerdp_settings_set_bool(settings, FreeRDP_NlaSecurity, TRUE) ||
132 !freerdp_settings_set_bool(settings, FreeRDP_TlsSecurity, TRUE) ||
133 !freerdp_settings_set_bool(settings, FreeRDP_RdpSecurity, TRUE))
134 goto fail;
135
136 /* By default allow all GFX modes.
137 * This can be changed with command line flags [+|-]gfx-CODEC
138 */
139 if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 32) ||
140 !freerdp_settings_set_bool(settings, FreeRDP_NSCodec, TRUE) ||
141 !freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE) ||
142 !freerdp_settings_set_bool(settings, FreeRDP_RemoteFxImageCodec, TRUE) ||
143 !freerdp_settings_set_uint32(settings, FreeRDP_RemoteFxRlgrMode, RLGR3) ||
144 !freerdp_settings_set_bool(settings, FreeRDP_GfxH264, TRUE) ||
145 !freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444, TRUE) ||
146 !freerdp_settings_set_bool(settings, FreeRDP_GfxAVC444v2, TRUE) ||
147 !freerdp_settings_set_bool(settings, FreeRDP_GfxProgressive, TRUE) ||
148 !freerdp_settings_set_bool(settings, FreeRDP_GfxProgressiveV2, TRUE))
149 goto fail;
150
151 if (!freerdp_settings_set_bool(settings, FreeRDP_MouseUseRelativeMove, FALSE) ||
152 !freerdp_settings_set_bool(settings, FreeRDP_HasRelativeMouseEvent, FALSE))
153 goto fail;
154
155 if ((status = shadow_server_parse_command_line(server, argc, argv, shadow_args)) < 0)
156 {
157 status = shadow_server_command_line_status_print(server, argc, argv, status, shadow_args);
158 goto fail;
159 }
160
161 if ((status = shadow_server_init(server)) < 0)
162 {
163 WLog_ERR(TAG, "Server initialization failed.");
164 goto fail;
165 }
166
167 if ((status = shadow_server_start(server)) < 0)
168 {
169 WLog_ERR(TAG, "Failed to start server.");
170 goto fail;
171 }
172
173#ifdef _WIN32
174 {
175 MSG msg = { 0 };
176 while (GetMessage(&msg, 0, 0, 0))
177 {
178 TranslateMessage(&msg);
179 DispatchMessage(&msg);
180 }
181 }
182#endif
183
184 (void)WaitForSingleObject(server->thread, INFINITE);
185
186 if (!GetExitCodeThread(server->thread, &dwExitCode))
187 status = -1;
188 else
189 status = (int)dwExitCode;
190
191fail:
192 shadow_server_uninit(server);
193 shadow_server_free(server);
194 return status;
195}
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.