|
Jan F. Chadima |
3fdf10 |
diff -up openssh-5.5p1/session.c.stderr openssh-5.5p1/session.c
|
|
Jan F. Chadima |
3fdf10 |
--- openssh-5.5p1/session.c.stderr 2010-04-26 10:35:35.000000000 +0200
|
|
Jan F. Chadima |
3fdf10 |
+++ openssh-5.5p1/session.c 2010-04-26 10:41:11.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 |
3fdf10 |
@@ -447,6 +448,9 @@ do_exec_no_pty(Session *s, const char *c
|
|
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 |
3fdf10 |
@@ -458,33 +462,59 @@ do_exec_no_pty(Session *s, const char *c
|
|
Jan F. Chadima |
3fdf10 |
close(pin[1]);
|
|
Jan F. Chadima |
3fdf10 |
return -1;
|
|
Jan F. Chadima |
3fdf10 |
}
|
|
Jan F. Chadima |
3fdf10 |
- if (pipe(perr) < 0) {
|
|
Jan F. Chadima |
3fdf10 |
- error("%s: pipe err: %.100s", __func__, strerror(errno));
|
|
Jan F. Chadima |
3fdf10 |
- close(pin[0]);
|
|
Jan F. Chadima |
3fdf10 |
- close(pin[1]);
|
|
Jan F. Chadima |
3fdf10 |
- close(pout[0]);
|
|
Jan F. Chadima |
3fdf10 |
- close(pout[1]);
|
|
Jan F. Chadima |
3fdf10 |
- return -1;
|
|
Jan F. Chadima |
3fdf10 |
+ if (s->is_subsystem) {
|
|
Jan F. Chadima |
3fdf10 |
+ if ((perr[1] = open(_PATH_DEVNULL, O_WRONLY)) == -1) {
|
|
Jan F. Chadima |
3fdf10 |
+ error("%s: open(%s): %s", __func__, _PATH_DEVNULL,
|
|
Jan F. Chadima |
3fdf10 |
+ strerror(errno));
|
|
Jan F. Chadima |
3fdf10 |
+ close(pin[0]);
|
|
Jan F. Chadima |
3fdf10 |
+ close(pin[1]);
|
|
Jan F. Chadima |
3fdf10 |
+ close(pout[0]);
|
|
Jan F. Chadima |
3fdf10 |
+ close(pout[1]);
|
|
Jan F. Chadima |
3fdf10 |
+ return -1;
|
|
Jan F. Chadima |
3fdf10 |
+ }
|
|
Jan F. Chadima |
3fdf10 |
+ perr[0] = -1;
|
|
Jan F. Chadima |
3fdf10 |
+ } else {
|
|
Jan F. Chadima |
3fdf10 |
+ if (pipe(perr) < 0) {
|
|
Jan F. Chadima |
3fdf10 |
+ error("%s: pipe err: %.100s", __func__,
|
|
Jan F. Chadima |
3fdf10 |
+ strerror(errno));
|
|
Jan F. Chadima |
3fdf10 |
+ close(pin[0]);
|
|
Jan F. Chadima |
3fdf10 |
+ close(pin[1]);
|
|
Jan F. Chadima |
3fdf10 |
+ close(pout[0]);
|
|
Jan F. Chadima |
3fdf10 |
+ close(pout[1]);
|
|
Jan F. Chadima |
3fdf10 |
+ return -1;
|
|
Jan F. Chadima |
3fdf10 |
+ }
|
|
Jan F. Chadima |
3fdf10 |
}
|
|
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 |
3fdf10 |
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0) {
|
|
Jan F. Chadima |
3fdf10 |
- error("%s: socketpair #2: %.100s", __func__, strerror(errno));
|
|
Jan F. Chadima |
3fdf10 |
- close(inout[0]);
|
|
Jan F. Chadima |
3fdf10 |
- close(inout[1]);
|
|
Jan F. Chadima |
3fdf10 |
- return -1;
|
|
Jan F. Chadima |
3fdf10 |
+ if (s->is_subsystem) {
|
|
Jan F. Chadima |
3fdf10 |
+ if ((err[0] = open(_PATH_DEVNULL, O_WRONLY)) == -1) {
|
|
Jan F. Chadima |
3fdf10 |
+ error("%s: open(%s): %s", __func__, _PATH_DEVNULL,
|
|
Jan F. Chadima |
3fdf10 |
+ strerror(errno));
|
|
Jan F. Chadima |
3fdf10 |
+ close(inout[0]);
|
|
Jan F. Chadima |
3fdf10 |
+ close(inout[1]);
|
|
Jan F. Chadima |
3fdf10 |
+ return -1;
|
|
Jan F. Chadima |
3fdf10 |
+ }
|
|
Jan F. Chadima |
3fdf10 |
+ err[1] = -1;
|
|
Jan F. Chadima |
3fdf10 |
+ } else {
|
|
Jan F. Chadima |
3fdf10 |
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0) {
|
|
Jan F. Chadima |
3fdf10 |
+ error("%s: socketpair #2: %.100s", __func__,
|
|
Jan F. Chadima |
3fdf10 |
+ strerror(errno));
|
|
Jan F. Chadima |
3fdf10 |
+ close(inout[0]);
|
|
Jan F. Chadima |
3fdf10 |
+ close(inout[1]);
|
|
Jan F. Chadima |
3fdf10 |
+ return -1;
|
|
Jan F. Chadima |
3fdf10 |
+ }
|
|
Jan F. Chadima |
3fdf10 |
}
|
|
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 |
3fdf10 |
@@ -496,13 +526,15 @@ do_exec_no_pty(Session *s, const char *c
|
|
Jan F. Chadima |
3fdf10 |
close(pin[1]);
|
|
Jan F. Chadima |
3fdf10 |
close(pout[0]);
|
|
Jan F. Chadima |
3fdf10 |
close(pout[1]);
|
|
Jan F. Chadima |
3fdf10 |
- close(perr[0]);
|
|
Jan F. Chadima |
3fdf10 |
+ if (perr[0] != -1)
|
|
Jan F. Chadima |
3fdf10 |
+ close(perr[0]);
|
|
Jan F. Chadima |
3fdf10 |
close(perr[1]);
|
|
Jan F. Chadima |
3fdf10 |
#else
|
|
Jan F. Chadima |
3fdf10 |
close(inout[0]);
|
|
Jan F. Chadima |
3fdf10 |
close(inout[1]);
|
|
Jan F. Chadima |
3fdf10 |
close(err[0]);
|
|
Jan F. Chadima |
3fdf10 |
- close(err[1]);
|
|
Jan F. Chadima |
3fdf10 |
+ if (err[1] != -1)
|
|
Jan F. Chadima |
3fdf10 |
+ close(err[1]);
|
|
Jan F. Chadima |
3fdf10 |
#endif
|
|
Jan F. Chadima |
3fdf10 |
return -1;
|
|
Jan F. Chadima |
3fdf10 |
case 0:
|
|
Jan F. Chadima |
3fdf10 |
@@ -536,7 +568,8 @@ do_exec_no_pty(Session *s, const char *c
|
|
Jan F. Chadima |
3fdf10 |
close(pout[1]);
|
|
Jan F. Chadima |
3fdf10 |
|
|
Jan F. Chadima |
3fdf10 |
/* Redirect stderr. */
|
|
Jan F. Chadima |
3fdf10 |
- close(perr[0]);
|
|
Jan F. Chadima |
3fdf10 |
+ if (perr[0] != -1)
|
|
Jan F. Chadima |
3fdf10 |
+ close(perr[0]);
|
|
Jan F. Chadima |
3fdf10 |
if (dup2(perr[1], 2) < 0)
|
|
Jan F. Chadima |
3fdf10 |
perror("dup2 stderr");
|
|
Jan F. Chadima |
3fdf10 |
close(perr[1]);
|
|
Jan F. Chadima |
3fdf10 |
@@ -547,7 +580,8 @@ do_exec_no_pty(Session *s, const char *c
|
|
Jan F. Chadima |
3fdf10 |
* seem to depend on it.
|
|
Jan F. Chadima |
3fdf10 |
*/
|
|
Jan F. Chadima |
3fdf10 |
close(inout[1]);
|
|
Jan F. Chadima |
3fdf10 |
- close(err[1]);
|
|
Jan F. Chadima |
3fdf10 |
+ if (err[1] != -1)
|
|
Jan F. Chadima |
3fdf10 |
+ close(err[1]);
|
|
Jan F. Chadima |
3fdf10 |
if (dup2(inout[0], 0) < 0) /* stdin */
|
|
Jan F. Chadima |
3fdf10 |
perror("dup2 stdin");
|
|
Jan F. Chadima |
3fdf10 |
if (dup2(inout[0], 1) < 0) /* stdout (same as stdin) */
|
|
Jan F. Chadima |
3fdf10 |
@@ -595,10 +629,6 @@ 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 |
3fdf10 |
session_set_fds(s, pin[1], pout[0], perr[0], 0);
|
|
Jan F. Chadima |
3fdf10 |
} else {
|
|
Jan F. Chadima |
3fdf10 |
/* Enter the interactive session. */
|
|
Jan F. Chadima |
3fdf10 |
@@ -615,10 +645,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 |
3fdf10 |
+ session_set_fds(s, inout[1], inout[1], err[1], 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]. */
|