[PATCH] Expand %n in User parameters

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

 



This patch adds expansion of the %n token to "User"-parameters in ssh_config
files, allowing configurations like:

  Host service1 service2
      HostName services.example.com
  Host service1
      User service1
  Host service2
      User service2

... to be expressed more tersely:

  Host service1 service2
    HostName services.example.com
    User %n
---
 ssh.c        | 7 ++++++-
 ssh_config.5 | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ssh.c b/ssh.c
index 849fae35..3202697d 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1266,8 +1266,13 @@ main(int ac, char **av)
        seed_rng();
-       if (options.user == NULL)
+       if (options.user == NULL) {
                options.user = xstrdup(pw->pw_name);
+       } else {
+               cp = options.user;
+               options.user = percent_expand(cp, "n", host_arg, (char *)NULL);
+               free(cp);
+       }
        /* Set up strings used to percent_expand() arguments */
        if (gethostname(thishost, sizeof(thishost)) == -1)
diff --git a/ssh_config.5 b/ssh_config.5
index 27136dbd..1f0c368c 100644
--- a/ssh_config.5
+++ b/ssh_config.5
@@ -1761,6 +1761,9 @@ accepts the tokens %%, %C, %h, %i, %L, %l, %n, %p, %r, and %u.
 .Cm HostName
 accepts the tokens %% and %h.
 .Pp
+.Cm User
+accepts the tokens %% and %n.
+.Pp
 .Cm IdentityAgent
 and
 .Cm IdentityFile
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@xxxxxxxxxxx
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev




[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux