nixos/sshd: fix socket activated ports when using ListenAddress

Noticed that issue while reviewing #275633: when declaring
`ListenAddress host` without a port, all ports declared by
`Port`/`cfg.ports` will be used with `host` according to
`sshd_config(5)`.

However, if this is done and socket activation is used, only a socket
for port 22 is created instead of a sockets for each port from
`Port`/`cfg.ports`. This patch corrects that behavior.

Also added a regression test for this case.
This commit is contained in:
Maximilian Bosch
2024-01-03 19:36:51 +01:00
parent cb274aea01
commit 7e45990c06
2 changed files with 32 additions and 2 deletions

View File

@@ -600,7 +600,11 @@ in
{ description = "SSH Socket";
wantedBy = [ "sockets.target" ];
socketConfig.ListenStream = if cfg.listenAddresses != [] then
map (l: "${l.addr}:${toString (if l.port != null then l.port else 22)}") cfg.listenAddresses
concatMap
({ addr, port }:
if port != null then [ "${addr}:${toString port}" ]
else map (p: "${addr}:${toString p}") cfg.ports)
cfg.listenAddresses
else
cfg.ports;
socketConfig.Accept = true;