Skip to content

Commit 100914a

Browse files
authored
WSLGd: don't allow arbitrary settings for shell (#1379)
1 parent f6a2fd1 commit 100914a

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

WSLGd/main.cpp

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ constexpr auto c_systemDistroEnvSection = "system-distro-env";
3636

3737
constexpr auto c_windowsSystem32 = "/mnt/c/Windows/System32";
3838

39-
constexpr auto c_westonShellOverrideEnv = "WSL2_WESTON_SHELL_OVERRIDE";
39+
constexpr auto c_westonShellDesktopEnv = "WSL2_WESTON_SHELL_DESKTOP";
40+
4041
constexpr auto c_westonRdprailShell = "rdprail-shell";
42+
constexpr auto c_westonRdpdesktopShell = "desktop-shell";
4143

42-
constexpr auto c_rdpFileOverrideEnv = "WSL2_RDP_CONFIG_OVERRIDE";
43-
constexpr auto c_rdpFile = "wslg.rdp";
44+
constexpr auto c_rdpRailFile = "wslg.rdp";
45+
constexpr auto c_rdpDesktopFile = "wslg_desktop.rdp";
4446

4547
void LogPrint(int level, const char *func, int line, const char *fmt, ...) noexcept
4648
{
@@ -368,16 +370,13 @@ try {
368370

369371
// Check if weston shell override is specified.
370372
// Otherwise, default shell is 'rdprail-shell'.
371-
bool isRdprailShell;
373+
// Alternatively, it can be 'desktop-shell'.
374+
bool isRdpDesktopShell = GetEnvBool(c_westonShellDesktopEnv, false);
372375
std::string westonShellName;
373-
auto westonShellEnv = getenv(c_westonShellOverrideEnv);
374-
if (!westonShellEnv) {
376+
if (isRdpDesktopShell)
377+
westonShellName = c_westonRdpdesktopShell;
378+
else
375379
westonShellName = c_westonRdprailShell;
376-
isRdprailShell = true;
377-
} else {
378-
westonShellName = westonShellEnv;
379-
isRdprailShell = (westonShellName.compare(c_westonRdprailShell) == 0);
380-
}
381380

382381
// Construct shell option string.
383382
std::string westonShellOption("--shell=");
@@ -397,7 +396,7 @@ try {
397396
// By default, enable standard log and rdp-backend.
398397
std::string westonLoggerOption("--logger-scopes=log,rdp-backend");
399398
// If rdprail-shell is used, enable logger for that.
400-
if (isRdprailShell) {
399+
if (!isRdpDesktopShell) {
401400
westonLoggerOption += ",";
402401
westonLoggerOption += c_westonRdprailShell;
403402
}
@@ -490,19 +489,11 @@ try {
490489
wslDvcPlugin = "/plugin:WSLDVC";
491490

492491
std::string rdpFilePathArg(wslInstallPath);
493-
auto rdpFile = getenv(c_rdpFileOverrideEnv);
494-
if (rdpFile) {
495-
if (strstr(rdpFile, "..\\") || strstr(rdpFile, "../")) {
496-
LOG_ERROR("RDP file must not contain relative path (%s)", rdpFile);
497-
rdpFile = nullptr;
498-
}
499-
}
500492
rdpFilePathArg += "\\"; // Windows-style path
501-
if (rdpFile) {
502-
rdpFilePathArg += rdpFile;
503-
} else {
504-
rdpFilePathArg += c_rdpFile;
505-
}
493+
if (isRdpDesktopShell)
494+
rdpFilePathArg += c_rdpDesktopFile;
495+
else
496+
rdpFilePathArg += c_rdpRailFile;
506497

507498
monitor.LaunchProcess(std::vector<std::string>{
508499
"/init",

0 commit comments

Comments
 (0)