File openssh-9.9p1-custom-1.patch of Package openssh

From 5f52c3436e6fe2460e6d5cbdc4044db3f6864dc4 Mon Sep 17 00:00:00 2001
From: Ciprian Dorin Craciun <ciprian@volution.ro>
Date: Sat, 15 Apr 2017 14:45:36 +0300
Subject: [PATCH 1/3] Add `%I` option to `ProxyCommand` which expands to the
 resolved IP of the remote as resolved from the local machine (thus before
 jumping)

---
 sshconnect.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/sshconnect.c b/sshconnect.c
index 7cf6b6386..419033ee1 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -86,28 +86,62 @@ static void warn_changed_key(struct sshkey *);
 
 /* Expand a proxy command */
 static char *
 expand_proxy_command(const char *proxy_command, const char *user,
     const char *host, const char *host_arg, int port)
 {
 	char *tmp, *ret, strport[NI_MAXSERV];
 	const char *keyalias = options.host_key_alias ?
 	    options.host_key_alias : host_arg;
 
+	char *address, straddr[NI_MAXHOST];
+	struct addrinfo hints, *addressinfo;
+	struct sockaddr_in *sockinfo;
+	int gaierr;
+
+	if (port <= 0)
+		port = default_ssh_port();
 	snprintf(strport, sizeof strport, "%d", port);
+
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = options.address_family == -1 ?
+	    AF_UNSPEC : options.address_family;
+	hints.ai_socktype = SOCK_STREAM;
+	hints.ai_flags = AI_NUMERICSERV;
+	if ((gaierr = getaddrinfo(host, strport, &hints, &addressinfo)) != 0) {
+		debug("%s: could not resolve name %.100s as address: %s",
+		    __func__, host, ssh_gai_strerror(gaierr));
+		addressinfo = NULL;
+	}
+	if (addressinfo != NULL && addressinfo->ai_next != NULL) {
+		debug("%s: getaddrinfo %.100s returned multiple addresses",
+		    __func__, host);
+	}
+
+	if (addressinfo == NULL)
+		address = host;
+	else {
+		sockinfo = (struct sockaddr_in *) addressinfo->ai_addr;
+		address = inet_ntop(sockinfo->sin_family, &sockinfo->sin_addr, straddr, sizeof(straddr));
+		if (address == NULL)
+			address = host;
+		freeaddrinfo(addressinfo);
+	}
+
 	xasprintf(&tmp, "exec %s", proxy_command);
 	ret = percent_expand(tmp,
 	    "h", host,
 	    "k", keyalias,
 	    "n", host_arg,
 	    "p", strport,
 	    "r", options.user,
+	    "I", address,
 	    (char *)NULL);
 	free(tmp);
 	return ret;
 }
 
 /*
  * Connect to the given ssh server using a proxy command that passes a
  * a connected fd back to us.
  */
 static int
-- 
2.47.1

openSUSE Build Service is sponsored by