summaryrefslogtreecommitdiff
path: root/sshconnect.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-11-16 06:17:38 +0000
committerDamien Miller <djm@mindrot.org>2018-11-16 17:18:29 +1100
commitccef7c4faf914993b53035cd2b25ce02ab039c9d (patch)
tree15fd42720b91c50da4cd09c27956356d7a7562d7 /sshconnect.c
parent15182fd96845a03216d7ac5a2cf31c4e77e406e3 (diff)
upstream: redirect stderr of ProxyCommands to /dev/null when ssh is
started with ControlPersist; based on patch from Steffen Prohaska OpenBSD-Commit-ID: 1bcaa14a03ae80369d31021271ec75dce2597957
Diffstat (limited to 'sshconnect.c')
-rw-r--r--sshconnect.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/sshconnect.c b/sshconnect.c
index 52c328111..a700f467f 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect.c,v 1.306 2018/10/15 11:28:50 florian Exp $ */ 1/* $OpenBSD: sshconnect.c,v 1.307 2018/11/16 06:17:38 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
@@ -78,6 +78,7 @@ static int matching_host_key_dns = 0;
78static pid_t proxy_command_pid = 0; 78static pid_t proxy_command_pid = 0;
79 79
80/* import */ 80/* import */
81extern int debug_flag;
81extern Options options; 82extern Options options;
82extern char *__progname; 83extern char *__progname;
83 84
@@ -99,6 +100,24 @@ expand_proxy_command(const char *proxy_command, const char *user,
99 return ret; 100 return ret;
100} 101}
101 102
103static void
104stderr_null(void)
105{
106 int devnull;
107
108 if ((devnull = open(_PATH_DEVNULL, O_WRONLY)) == -1) {
109 error("Can't open %s for stderr redirection: %s",
110 _PATH_DEVNULL, strerror(errno));
111 return;
112 }
113 if (devnull == STDERR_FILENO)
114 return;
115 if (dup2(devnull, STDERR_FILENO) == -1)
116 error("Cannot redirect stderr to %s", _PATH_DEVNULL);
117 if (devnull > STDERR_FILENO)
118 close(devnull);
119}
120
102/* 121/*
103 * Connect to the given ssh server using a proxy command that passes a 122 * Connect to the given ssh server using a proxy command that passes a
104 * a connected fd back to us. 123 * a connected fd back to us.
@@ -141,9 +160,12 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port,
141 close(sp[0]); 160 close(sp[0]);
142 161
143 /* 162 /*
144 * Stderr is left as it is so that error messages get 163 * Stderr is left for non-ControlPersist connections is so
145 * printed on the user's terminal. 164 * error messages may be printed on the user's terminal.
146 */ 165 */
166 if (debug_flag || !options.control_persist)
167 stderr_null();
168
147 argv[0] = shell; 169 argv[0] = shell;
148 argv[1] = "-c"; 170 argv[1] = "-c";
149 argv[2] = command_string; 171 argv[2] = command_string;
@@ -219,8 +241,13 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port,
219 /* Cannot be 1 because pin allocated two descriptors. */ 241 /* Cannot be 1 because pin allocated two descriptors. */
220 close(pout[1]); 242 close(pout[1]);
221 243
222 /* Stderr is left as it is so that error messages get 244 /*
223 printed on the user's terminal. */ 245 * Stderr is left for non-ControlPersist connections is so
246 * error messages may be printed on the user's terminal.
247 */
248 if (debug_flag || !options.control_persist)
249 stderr_null();
250
224 argv[0] = shell; 251 argv[0] = shell;
225 argv[1] = "-c"; 252 argv[1] = "-c";
226 argv[2] = command_string; 253 argv[2] = command_string;