summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/ssh.c b/ssh.c
index 6625557bd..54f1dbd0a 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.404 2014/06/27 16:41:56 markus Exp $ */ 1/* $OpenBSD: ssh.c,v 1.405 2014/07/03 06:39:19 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -85,6 +85,7 @@
85#include "canohost.h" 85#include "canohost.h"
86#include "compat.h" 86#include "compat.h"
87#include "cipher.h" 87#include "cipher.h"
88#include "digest.h"
88#include "packet.h" 89#include "packet.h"
89#include "buffer.h" 90#include "buffer.h"
90#include "channels.h" 91#include "channels.h"
@@ -424,6 +425,9 @@ main(int ac, char **av)
424 extern char *optarg; 425 extern char *optarg;
425 Forward fwd; 426 Forward fwd;
426 struct addrinfo *addrs = NULL; 427 struct addrinfo *addrs = NULL;
428 struct ssh_digest_ctx *md;
429 u_char conn_hash[SSH_DIGEST_MAX_LENGTH];
430 char *conn_hash_hex;
427 431
428 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ 432 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
429 sanitise_stdfd(); 433 sanitise_stdfd();
@@ -1002,12 +1006,29 @@ main(int ac, char **av)
1002 shorthost[strcspn(thishost, ".")] = '\0'; 1006 shorthost[strcspn(thishost, ".")] = '\0';
1003 snprintf(portstr, sizeof(portstr), "%d", options.port); 1007 snprintf(portstr, sizeof(portstr), "%d", options.port);
1004 1008
1009 if ((md = ssh_digest_start(SSH_DIGEST_SHA1)) == NULL ||
1010 ssh_digest_update(md, thishost, strlen(thishost)) < 0 ||
1011 ssh_digest_update(md, host, strlen(host)) < 0 ||
1012 ssh_digest_update(md, portstr, strlen(portstr)) < 0 ||
1013 ssh_digest_update(md, options.user, strlen(options.user)) < 0 ||
1014 ssh_digest_final(md, conn_hash, sizeof(conn_hash)) < 0)
1015 fatal("%s: mux digest failed", __func__);
1016 ssh_digest_free(md);
1017 conn_hash_hex = tohex(conn_hash, ssh_digest_bytes(SSH_DIGEST_SHA1));
1018
1005 if (options.local_command != NULL) { 1019 if (options.local_command != NULL) {
1006 debug3("expanding LocalCommand: %s", options.local_command); 1020 debug3("expanding LocalCommand: %s", options.local_command);
1007 cp = options.local_command; 1021 cp = options.local_command;
1008 options.local_command = percent_expand(cp, "d", pw->pw_dir, 1022 options.local_command = percent_expand(cp,
1009 "h", host, "l", thishost, "n", host_arg, "r", options.user, 1023 "C", conn_hash_hex,
1010 "p", portstr, "u", pw->pw_name, "L", shorthost, 1024 "L", shorthost,
1025 "d", pw->pw_dir,
1026 "h", host,
1027 "l", thishost,
1028 "n", host_arg,
1029 "p", portstr,
1030 "r", options.user,
1031 "u", pw->pw_name,
1011 (char *)NULL); 1032 (char *)NULL);
1012 debug3("expanded LocalCommand: %s", options.local_command); 1033 debug3("expanded LocalCommand: %s", options.local_command);
1013 free(cp); 1034 free(cp);
@@ -1017,12 +1038,20 @@ main(int ac, char **av)
1017 cp = tilde_expand_filename(options.control_path, 1038 cp = tilde_expand_filename(options.control_path,
1018 original_real_uid); 1039 original_real_uid);
1019 free(options.control_path); 1040 free(options.control_path);
1020 options.control_path = percent_expand(cp, "h", host, 1041 options.control_path = percent_expand(cp,
1021 "l", thishost, "n", host_arg, "r", options.user, 1042 "C", conn_hash_hex,
1022 "p", portstr, "u", pw->pw_name, "L", shorthost, 1043 "L", shorthost,
1044 "h", host,
1045 "l", thishost,
1046 "n", host_arg,
1047 "p", portstr,
1048 "r", options.user,
1049 "u", pw->pw_name,
1023 (char *)NULL); 1050 (char *)NULL);
1024 free(cp); 1051 free(cp);
1025 } 1052 }
1053 free(conn_hash_hex);
1054
1026 if (muxclient_command != 0 && options.control_path == NULL) 1055 if (muxclient_command != 0 && options.control_path == NULL)
1027 fatal("No ControlPath specified for \"-O\" command"); 1056 fatal("No ControlPath specified for \"-O\" command");
1028 if (options.control_path != NULL) 1057 if (options.control_path != NULL)