Skip to content

Commit afffa89

Browse files
authored
ssh: Fix environment variable parsing (#177503)
From systemctl(1)'s `show-environment`: [...] If no special characters or whitespace is present in the variable values, no escaping is performed, and the assignments have the form "VARIABLE=value". If whitespace or characters which have special meaning to the shell are present, dollar-single-quote escaping is used, and assignments have the form "VARIABLE=$'value'". [...] `DISPLAY` is unlikely to require such escaping, but is still broken and overly complicated. Just rely on the fact that systemctl outputs line that are safe to be interpreted by the shell. Filter for `DISPLAY` and `eval` the output instead of trying to parse just the value part and reassign it again.
1 parent d361bb4 commit afffa89

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

nixos/modules/programs/ssh.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ let
1313

1414
askPasswordWrapper = pkgs.writeScript "ssh-askpass-wrapper" ''
1515
#! ${pkgs.runtimeShell} -e
16-
export DISPLAY="$(systemctl --user show-environment | ${pkgs.gnused}/bin/sed 's/^DISPLAY=\(.*\)/\1/; t; d')"
17-
export XAUTHORITY="$(systemctl --user show-environment | ${pkgs.gnused}/bin/sed 's/^XAUTHORITY=\(.*\)/\1/; t; d')"
18-
export WAYLAND_DISPLAY="$(systemctl --user show-environment | ${pkgs.gnused}/bin/sed 's/^WAYLAND_DISPLAY=\(.*\)/\1/; t; d')"
16+
eval export $(systemctl --user show-environment | ${pkgs.coreutils}/bin/grep -E '^(DISPLAY|WAYLAND_DISPLAY|XAUTHORITY)=')
1917
exec ${cfg.askPassword} "$@"
2018
'';
2119

0 commit comments

Comments
 (0)