[PATCH] Make "ssh" try different configuration filenames

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

 



To provide a bit more backwards-compatible (which is nice for eg. NFS-
shared /home directories) try a few version-number based names.

Eg., for "OpenSSH_7.3" the strings that are tried after "~/.ssh/config"
are "_7.3", "_7", and "".
---
 ssh.c | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/ssh.c b/ssh.c
index 03a23fb..25359fe 100644
--- a/ssh.c
+++ b/ssh.c
@@ -464,7 +464,8 @@ static void
 process_config_files(const char *host_arg, struct passwd *pw, int post_canon)
 {
 	char buf[PATH_MAX];
-	int r;
+	char *version_postfix;
+	int r, len;
 
 	if (config != NULL) {
 		if (strcasecmp(config, "none") != 0 &&
@@ -473,12 +474,34 @@ process_config_files(const char *host_arg, struct passwd *pw, int post_canon)
 			fatal("Can't open user config file %.100s: "
 			    "%.100s", config, strerror(errno));
 	} else {
-		r = snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir,
-		    _PATH_SSH_USER_CONFFILE);
-		if (r > 0 && (size_t)r < sizeof(buf))
-			(void)read_config_file(buf, pw, host, host_arg,
-			    &options, SSHCONF_CHECKPERM | SSHCONF_USERCONF |
-			    (post_canon ? SSHCONF_POSTCANON : 0));
+		version_postfix = strchr(SSH_VERSION, '_');
+		if (!version_postfix)
+			version_postfix = "";
+
+		/* Find the best fitting config file,
+		 * Ie. try "_7.3", "_7", and "". */
+		len = strlen(version_postfix);
+		while (1) {
+			r = snprintf(buf, sizeof buf, "%s/%s%.*s", pw->pw_dir,
+					_PATH_SSH_USER_CONFFILE,
+					len, version_postfix);
+			if (r > 0 && (size_t)r < sizeof(buf))
+				if (read_config_file(buf, pw, host, host_arg,
+							&options, SSHCONF_CHECKPERM | SSHCONF_USERCONF |
+							(post_canon ? SSHCONF_POSTCANON : 0)))
+					break;
+
+			/* Nothing to look at */
+			if (!len)
+				break;
+
+			/* Try a smaller fit; skip last digits, then non-digits. */
+			len--;
+			while (len &&  isdigit(version_postfix[len-1]))
+				len--;
+			while (len && !isdigit(version_postfix[len-1]))
+				len--;
+		}
 
 		/* Read systemwide configuration file after user config. */
 		(void)read_config_file(_PATH_HOST_CONFIG_FILE, pw,
-- 
2.9.3

_______________________________________________
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