vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jan F. Chadima 411b91
diff -up openssh-5.5p1/channels.c.stderr openssh-5.5p1/channels.c
Jan F. Chadima 411b91
--- openssh-5.5p1/channels.c.stderr	2010-06-23 15:20:30.000000000 +0200
Jan F. Chadima 411b91
+++ openssh-5.5p1/channels.c	2010-06-23 15:23:06.000000000 +0200
Jan F. Chadima 411b91
@@ -838,8 +838,9 @@ channel_pre_open(Channel *c, fd_set *rea
Jan F. Chadima 411b91
 		if (c->extended_usage == CHAN_EXTENDED_WRITE &&
Jan F. Chadima 411b91
 		    buffer_len(&c->extended) > 0)
Jan F. Chadima 411b91
 			FD_SET(c->efd, writeset);
Jan F. Chadima 411b91
-		else if (!(c->flags & CHAN_EOF_SENT) &&
Jan F. Chadima 411b91
-		    c->extended_usage == CHAN_EXTENDED_READ &&
Jan F. Chadima 411b91
+		else if (c->efd != -1 && !(c->flags & CHAN_EOF_SENT) &&
Jan F. Chadima 411b91
+		    (c->extended_usage == CHAN_EXTENDED_READ ||
Jan F. Chadima 411b91
+		    c->extended_usage == CHAN_EXTENDED_IGNORE) &&
Jan F. Chadima 411b91
 		    buffer_len(&c->extended) < c->remote_window)
Jan F. Chadima 411b91
 			FD_SET(c->efd, readset);
Jan F. Chadima 411b91
 	}
Jan F. Chadima 411b91
@@ -1759,7 +1760,9 @@ channel_handle_efd(Channel *c, fd_set *r
Jan F. Chadima 411b91
 				buffer_consume(&c->extended, len);
Jan F. Chadima 411b91
 				c->local_consumed += len;
Jan F. Chadima 411b91
 			}
Jan F. Chadima 411b91
-		} else if (c->extended_usage == CHAN_EXTENDED_READ &&
Jan F. Chadima 411b91
+		} else if (c->efd != -1 &&
Jan F. Chadima 411b91
+		    (c->extended_usage == CHAN_EXTENDED_READ ||
Jan F. Chadima 411b91
+		    c->extended_usage == CHAN_EXTENDED_IGNORE) &&
Jan F. Chadima 411b91
 		    (c->detach_close || FD_ISSET(c->efd, readset))) {
Jan F. Chadima 411b91
 			len = read(c->efd, buf, sizeof(buf));
Jan F. Chadima 411b91
 			debug2("channel %d: read %d from efd %d",
Jan F. Chadima 411b91
@@ -1772,7 +1775,11 @@ channel_handle_efd(Channel *c, fd_set *r
Jan F. Chadima 411b91
 				    c->self, c->efd);
Jan F. Chadima 411b91
 				channel_close_fd(&c->efd);
Jan F. Chadima 411b91
 			} else {
Jan F. Chadima 411b91
-				buffer_append(&c->extended, buf, len);
Jan F. Chadima 411b91
+				if (c->extended_usage == CHAN_EXTENDED_IGNORE) {
Jan F. Chadima 411b91
+					debug3("channel %d: discard efd",
Jan F. Chadima 411b91
+					    c->self);
Jan F. Chadima 411b91
+				} else
Jan F. Chadima 411b91
+					buffer_append(&c->extended, buf, len);
Jan F. Chadima 411b91
 			}
Jan F. Chadima 411b91
 		}
Jan F. Chadima 411b91
 	}
Jan F. Chadima 3fdf10
diff -up openssh-5.5p1/session.c.stderr openssh-5.5p1/session.c
Jan F. Chadima 411b91
--- openssh-5.5p1/session.c.stderr	2010-06-23 15:20:29.000000000 +0200
Jan F. Chadima 411b91
+++ openssh-5.5p1/session.c	2010-06-23 15:23:55.000000000 +0200
Jan F. Chadima 3fdf10
@@ -47,6 +47,7 @@
Jan F. Chadima 3fdf10
 #include <arpa/inet.h>
Jan F. Chadima 3fdf10
 
Jan F. Chadima 3fdf10
 #include <errno.h>
Jan F. Chadima 3fdf10
+#include <fcntl.h>
Jan F. Chadima 3fdf10
 #include <grp.h>
Jan F. Chadima 3fdf10
 #ifdef HAVE_PATHS_H
Jan F. Chadima 3fdf10
 #include <paths.h>
Jan F. Chadima 411b91
@@ -104,7 +105,7 @@
Jan F. Chadima 411b91
 /* func */
Jan F. Chadima 411b91
 
Jan F. Chadima 411b91
 Session *session_new(void);
Jan F. Chadima 411b91
-void	session_set_fds(Session *, int, int, int, int);
Jan F. Chadima 411b91
+void	session_set_fds(Session *, int, int, int, int, int);
Jan F. Chadima 411b91
 void	session_pty_cleanup(Session *);
Jan F. Chadima 411b91
 void	session_proctitle(Session *);
Jan F. Chadima 411b91
 int	session_setup_x11fwd(Session *);
Jan F. Chadima 411b91
@@ -443,10 +444,14 @@ int
Jan F. Chadima 411b91
 do_exec_no_pty(Session *s, const char *command)
Jan F. Chadima 411b91
 {
Jan F. Chadima 411b91
 	pid_t pid;
Jan F. Chadima 411b91
+	int ignore_fderr = 0;
Jan F. Chadima 411b91
 
Jan F. Chadima 3fdf10
 #ifdef USE_PIPES
Jan F. Chadima 3fdf10
 	int pin[2], pout[2], perr[2];
Jan F. Chadima 3fdf10
 
Jan F. Chadima 3fdf10
+	if (s == NULL)
Jan F. Chadima 3fdf10
+		fatal("do_exec_no_pty: no session");
Jan F. Chadima 3fdf10
+
Jan F. Chadima 3fdf10
 	/* Allocate pipes for communicating with the program. */
Jan F. Chadima 3fdf10
 	if (pipe(pin) < 0) {
Jan F. Chadima 3fdf10
 		error("%s: pipe in: %.100s", __func__, strerror(errno));
Jan F. Chadima 411b91
@@ -459,32 +464,38 @@ do_exec_no_pty(Session *s, const char *c
Jan F. Chadima 3fdf10
 		return -1;
Jan F. Chadima 3fdf10
 	}
Jan F. Chadima 411b91
 	if (pipe(perr) < 0) {
Jan F. Chadima 3fdf10
-		error("%s: pipe err: %.100s", __func__, strerror(errno));
Jan F. Chadima 411b91
+		error("%s: pipe err: %.100s", __func__,
Jan F. Chadima 411b91
+		    strerror(errno));
Jan F. Chadima 411b91
 		close(pin[0]);
Jan F. Chadima 411b91
 		close(pin[1]);
Jan F. Chadima 411b91
 		close(pout[0]);
Jan F. Chadima 411b91
 		close(pout[1]);
Jan F. Chadima 411b91
 		return -1;
Jan F. Chadima 3fdf10
 	}
Jan F. Chadima 411b91
+	if (s->is_subsystem)
Jan F. Chadima 411b91
+		ignore_fderr = 1;
Jan F. Chadima 3fdf10
 #else
Jan F. Chadima 3fdf10
 	int inout[2], err[2];
Jan F. Chadima 3fdf10
 
Jan F. Chadima 3fdf10
+	if (s == NULL)
Jan F. Chadima 3fdf10
+		fatal("do_exec_no_pty: no session");
Jan F. Chadima 3fdf10
+
Jan F. Chadima 3fdf10
 	/* Uses socket pairs to communicate with the program. */
Jan F. Chadima 3fdf10
 	if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) < 0) {
Jan F. Chadima 3fdf10
 		error("%s: socketpair #1: %.100s", __func__, strerror(errno));
Jan F. Chadima 3fdf10
 		return -1;
Jan F. Chadima 3fdf10
 	}
Jan F. Chadima 411b91
 	if (socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0) {
Jan F. Chadima 3fdf10
-		error("%s: socketpair #2: %.100s", __func__, strerror(errno));
Jan F. Chadima 411b91
+		error("%s: socketpair #2: %.100s", __func__,
Jan F. Chadima 411b91
+		    strerror(errno));
Jan F. Chadima 411b91
 		close(inout[0]);
Jan F. Chadima 411b91
 		close(inout[1]);
Jan F. Chadima 411b91
 		return -1;
Jan F. Chadima 3fdf10
 	}
Jan F. Chadima 411b91
+	if (s->is_subsystem)
Jan F. Chadima 411b91
+		ignore_fderr = 1;
Jan F. Chadima 3fdf10
 #endif
Jan F. Chadima 3fdf10
 
Jan F. Chadima 3fdf10
-	if (s == NULL)
Jan F. Chadima 3fdf10
-		fatal("do_exec_no_pty: no session");
Jan F. Chadima 3fdf10
-
Jan F. Chadima 3fdf10
 	session_proctitle(s);
Jan F. Chadima 3fdf10
 
Jan F. Chadima 3fdf10
 	/* Fork the child. */
Jan F. Chadima 411b91
@@ -595,11 +606,7 @@ do_exec_no_pty(Session *s, const char *c
Jan F. Chadima 3fdf10
 	close(perr[1]);
Jan F. Chadima 3fdf10
 
Jan F. Chadima 3fdf10
 	if (compat20) {
Jan F. Chadima 3fdf10
-		if (s->is_subsystem) {
Jan F. Chadima 3fdf10
-			close(perr[0]);
Jan F. Chadima 3fdf10
-			perr[0] = -1;
Jan F. Chadima 3fdf10
-		}
Jan F. Chadima 411b91
-		session_set_fds(s, pin[1], pout[0], perr[0], 0);
Jan F. Chadima 411b91
+		session_set_fds(s, pin[1], pout[0], perr[0], ignore_fderr, 0);
Jan F. Chadima 3fdf10
 	} else {
Jan F. Chadima 3fdf10
 		/* Enter the interactive session. */
Jan F. Chadima 411b91
 		server_loop(pid, pin[1], pout[0], perr[0]);
Jan F. Chadima 411b91
@@ -615,10 +622,7 @@ do_exec_no_pty(Session *s, const char *c
Jan F. Chadima 3fdf10
 	 * handle the case that fdin and fdout are the same.
Jan F. Chadima 3fdf10
 	 */
Jan F. Chadima 3fdf10
 	if (compat20) {
Jan F. Chadima 3fdf10
-		session_set_fds(s, inout[1], inout[1],
Jan F. Chadima 3fdf10
-		    s->is_subsystem ? -1 : err[1], 0);
Jan F. Chadima 3fdf10
-		if (s->is_subsystem)
Jan F. Chadima 3fdf10
-			close(err[1]);
Jan F. Chadima 411b91
+		session_set_fds(s, inout[1], inout[1], err[1], ignore_fderr, 0);
Jan F. Chadima 3fdf10
 	} else {
Jan F. Chadima 3fdf10
 		server_loop(pid, inout[1], inout[1], err[1]);
Jan F. Chadima 3fdf10
 		/* server_loop has closed inout[1] and err[1]. */
Jan F. Chadima 411b91
@@ -740,7 +744,7 @@ do_exec_pty(Session *s, const char *comm
Jan F. Chadima 411b91
 	s->ptymaster = ptymaster;
Jan F. Chadima 411b91
 	packet_set_interactive(1);
Jan F. Chadima 411b91
 	if (compat20) {
Jan F. Chadima 411b91
-		session_set_fds(s, ptyfd, fdout, -1, 1);
Jan F. Chadima 411b91
+		session_set_fds(s, ptyfd, fdout, -1, 1, 1);
Jan F. Chadima 411b91
 	} else {
Jan F. Chadima 411b91
 		server_loop(pid, ptyfd, fdout, -1);
Jan F. Chadima 411b91
 		/* server_loop _has_ closed ptyfd and fdout. */
Jan F. Chadima 411b91
@@ -2321,7 +2325,8 @@ session_input_channel_req(Channel *c, co
Jan F. Chadima 411b91
 }
Jan F. Chadima 411b91
 
Jan F. Chadima 411b91
 void
Jan F. Chadima 411b91
-session_set_fds(Session *s, int fdin, int fdout, int fderr, int is_tty)
Jan F. Chadima 411b91
+session_set_fds(Session *s, int fdin, int fdout, int fderr, int ignore_fderr,
Jan F. Chadima 411b91
+    int is_tty)
Jan F. Chadima 411b91
 {
Jan F. Chadima 411b91
 	if (!compat20)
Jan F. Chadima 411b91
 		fatal("session_set_fds: called for proto != 2.0");
Jan F. Chadima 411b91
@@ -2333,7 +2338,7 @@ session_set_fds(Session *s, int fdin, in
Jan F. Chadima 411b91
 		fatal("no channel for session %d", s->self);
Jan F. Chadima 411b91
 	channel_set_fds(s->chanid,
Jan F. Chadima 411b91
 	    fdout, fdin, fderr,
Jan F. Chadima 411b91
-	    fderr == -1 ? CHAN_EXTENDED_IGNORE : CHAN_EXTENDED_READ,
Jan F. Chadima 411b91
+	    ignore_fderr ? CHAN_EXTENDED_IGNORE : CHAN_EXTENDED_READ,
Jan F. Chadima 411b91
 	    1, is_tty, CHAN_SES_WINDOW_DEFAULT);
Jan F. Chadima 411b91
 }
Jan F. Chadima 411b91