Mailing List Archive

[PATCH v2] Permit %L and %l percent escapes in Include
This allows the localhost percent-style escapes in arguments to the
Include directive. These are useful for including host-specific ssh
configuration.
---
readconf.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/readconf.c b/readconf.c
index a2282b562df0..ad47d0e9730a 100644
--- a/readconf.c
+++ b/readconf.c
@@ -1030,7 +1030,8 @@ process_config_line_depth(Options *options, struct passwd *pw, const char *host,
const char *original_host, char *line, const char *filename,
int linenum, int *activep, int flags, int *want_final_pass, int depth)
{
- char *str, **charptr, *endofnumber, *keyword, *arg, *arg2, *p;
+ char *str, **charptr, *endofnumber, *keyword, *arg, *arg2, *arg_pre, *p;
+ char thishost[NI_MAXHOST], shorthost[NI_MAXHOST];
char **cpptr, ***cppptr, fwdarg[256];
u_int i, *uintptr, uvalue, max_entries = 0;
int r, oactive, negated, opcode, *intptr, value, value2, cmdline = 0;
@@ -1951,6 +1952,12 @@ parse_pubkey_algos:
"command-line option");
goto out;
}
+
+ if (gethostname(thishost, sizeof(thishost)) == -1)
+ fatal("gethostname: %s", strerror(errno));
+ strlcpy(shorthost, thishost, sizeof(shorthost));
+ shorthost[strcspn(thishost, ".")] = '\0';
+
value = 0;
while ((arg = argv_next(&ac, &av)) != NULL) {
if (*arg == '\0') {
@@ -1971,11 +1978,14 @@ parse_pubkey_algos:
goto out;
}
if (!path_absolute(arg) && *arg != '~') {
- xasprintf(&arg2, "%s/%s",
+ xasprintf(&arg_pre, "%s/%s",
(flags & SSHCONF_USERCONF) ?
"~/" _PATH_SSH_USER_DIR : SSHDIR, arg);
} else
- arg2 = xstrdup(arg);
+ arg_pre = xstrdup(arg);
+ arg2 = percent_expand(arg_pre,
+ "l", thishost, "L", shorthost, (char *) NULL);
+ free(arg_pre);
memset(&gl, 0, sizeof(gl));
r = glob(arg2, GLOB_TILDE, NULL, &gl);
if (r == GLOB_NOMATCH) {

base-commit: 64e0600f23c6dec36c3875392ac95b8a9100c2d6
--
2.42.1

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: [PATCH v2] Permit %L and %l percent escapes in Include [ In reply to ]
On Mon, 13 Nov 2023, Ronan Pigott wrote:

> This allows the localhost percent-style escapes in arguments to the
> Include directive. These are useful for including host-specific ssh
> configuration.
> ---
> readconf.c | 16 +++++++++++++---

This seems quite reasonable but IMO we should do the same for servconf.c
too.

-d
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: [PATCH v2] Permit %L and %l percent escapes in Include [ In reply to ]
November 13, 2023 at 8:08 PM, "Damien Miller" <djm@mindrot.org> wrote:

> This seems quite reasonable but IMO we should do the same for servconf.c
> too.

Okay, I can add that in v3.
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev