rdp fixes

This commit is contained in:
crschnick
2026-06-25 18:13:10 +00:00
parent 1887f44f62
commit 036b5f898a
4 changed files with 43 additions and 21 deletions
@@ -1,5 +1,6 @@
package io.xpipe.app.rdp;
import io.xpipe.app.core.AppInstallation;
import io.xpipe.app.issue.ErrorEventFactory;
import io.xpipe.app.process.CommandBuilder;
import io.xpipe.app.process.CommandSupport;
@@ -12,6 +13,8 @@ import lombok.Builder;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;
import java.util.Map;
@JsonTypeName("freeRdp")
@Value
@Jacksonized
@@ -97,22 +100,34 @@ public class FreeRdpClient implements ExternalRdpClient {
.add("-themes")
.add("/size:100%");
if (configuration.getPassword() != null) {
b.add(argument("/p", configuration.getPassword().getSecretValue()));
}
var gateway = configuration.getGateway();
if (gateway != null) {
b.add("/g").addQuoted(gateway.getHost());
if (gateway.getUsername() != null) {
b.add("/gu").addQuoted(gateway.getUsername());
}
if (gateway.getPassword() != null) {
var escapedPw = gateway.getPassword().getSecretValue().replaceAll("'", "\\\\'");
b.add("/gp:'" + escapedPw + "'");
if (exec.isV3()) {
// Horrible quoting rules: https://github.com/FreeRDP/FreeRDP/issues/11396
String s = "g:" + gateway.getHost();
if (gateway.getUsername() != null) {
s += "," + gatewayArgument("u", gateway.getUsername());
}
if (gateway.getPassword() != null) {
s += "," + gatewayArgument("p", gateway.getPassword().getSecretValue());
}
b.add(gatewayArgument("/gateway", s));
} else {
b.add(argument("/g", gateway.getHost()));
if (gateway.getUsername() != null) {
b.add(argument("/gu", gateway.getUsername()));
}
if (gateway.getPassword() != null) {
b.add(argument("/gp", gateway.getPassword().getSecretValue()));
}
}
}
if (configuration.getPassword() != null) {
var escapedPw = configuration.getPassword().getSecretValue().replaceAll("'", "\\\\'");
b.add("/p:'" + escapedPw + "'");
}
b.fixedEnvironment("FREERDP_ASKPASS", AppInstallation.ofCurrent().getCliExecutablePath().toString());
try (var sc = LocalShell.getShell().start()) {
var cmd = sc.getShellDialect().launchAsync(b, true);
@@ -120,6 +135,16 @@ public class FreeRdpClient implements ExternalRdpClient {
}
}
private String gatewayArgument(String key, String value) {
var escaped = value.replaceAll("\"", "\\\\\"");
return "\"" + key + ":" + escaped + "\"";
}
private String argument(String key, String value) {
var escaped = value.replaceAll("'", "\\\\'");
return key + ":'" + escaped + "'";
}
@Override
public boolean supportsPasswordPassing(RdpLaunchConfig config) {
return true;
@@ -26,7 +26,7 @@ public class RdpLaunchConfig {
return Optional.ofNullable(domain);
}
public String getUserWithoutDomain() {
public String getUsernameWithoutDomain() {
if (username.contains("\\")) {
return username.split("\\\\")[1];
} else {
@@ -28,17 +28,14 @@ public class RemminaRdpClient implements ExternalApplicationType.LinuxApplicatio
}
}
var encrypted = RemminaHelper.encryptPassword(configuration.getPassword());
if (encrypted.isPresent()) {
var file = RemminaHelper.writeRemminaRdpConfigFile(configuration);
launch(CommandBuilder.of().add("-c").addFile(file.toString()));
return;
}
var file = RemminaHelper.writeRemminaRdpConfigFile(configuration);
LocalFileTracker.deleteOnExit(file);
launch(CommandBuilder.of().add("-c").addFile(file.toString()));
}
@Override
public boolean supportsPasswordPassing(RdpLaunchConfig config) {
return config.isRemoteApp();
return true;
}
@Override
@@ -95,10 +95,10 @@ public class RemminaHelper {
window_maximize=%s%s
""".formatted(
configuration.getTitle(),
configuration.getUsername(),
configuration.getUsernameWithoutDomain(),
configuration.getDomain().orElse(""),
configuration.getHost(),
configuration.getPassword() != null ? encryptPassword(configuration.getPassword()) : "",
configuration.getPassword() != null ? encryptPassword(configuration.getPassword()).orElse("") : "",
w,
h,
maximize,