[rsh] rlogind: don't call forkpty()
Michal Sekletar
msekleta at fedoraproject.org
Mon Apr 15 13:19:13 UTC 2013
commit 3c095f9e2ad63c6026f213bc1d0261ae1e2669e4
Author: Michal Sekletar <msekleta at redhat.com>
Date: Thu Apr 11 14:38:27 2013 +0200
rlogind: don't call forkpty()
We can no longer call forkpty (a convenience routine that combines
openpty, fork, and login_tty) because, with forkpty, the slave end of
the pty is open only in the child process. The child process execs
/bin/login which now closes all open file descriptors before doing
a vhangup (see lkml.org/lkml/2012/6/5/145), and this resets packet
mode on the pty, undoing the effect of the ioctl(master, TIOCPKT,
&on) call made by the parent.
Instead, we call openpty, fork, and login_tty individually, so
that we can keep a file descriptor to the slave open in the parent
process, thereby retaining packet mode even when the child closes
file descriptors to call vhangup.
Patch contributed by Philip Spencer, <pspencer at fields.utoronto.ca>.
Resolves RHBZ #947213.
Signed-off-by: Michal Sekletar <msekleta at redhat.com>
netkit-rsh-0.17-rh947213.patch | 65 ++++++++++++++++++++++++++++++++++++++++
rsh.spec | 2 +
2 files changed, 67 insertions(+), 0 deletions(-)
---
diff --git a/netkit-rsh-0.17-rh947213.patch b/netkit-rsh-0.17-rh947213.patch
new file mode 100644
index 0000000..155f873
--- /dev/null
+++ b/netkit-rsh-0.17-rh947213.patch
@@ -0,0 +1,65 @@
+diff -up netkit-rsh-0.17/rlogind/rlogind.c.rh947213 netkit-rsh-0.17/rlogind/rlogind.c
+--- netkit-rsh-0.17/rlogind/rlogind.c.rh947213 2013-04-11 14:18:47.481715853 +0200
++++ netkit-rsh-0.17/rlogind/rlogind.c 2013-04-11 14:32:50.807780164 +0200
+@@ -67,12 +67,13 @@ char rcsid[] =
+ #include <unistd.h>
+ #include <stdlib.h>
+ #include <string.h>
++#include <pty.h>
++#include <utmp.h>
+
+ #include "pathnames.h"
+ #include "logwtmp.h"
+ #include "rlogind.h"
+
+-pid_t forkpty(int *, char *, struct termios *, struct winsize *);
+ int logout(const char *);
+
+ #ifndef TIOCPKT_WINDOW
+@@ -389,7 +390,7 @@ static void getstr(char *buf, int cnt, c
+ }
+
+ static void doit(int netfd) {
+- int master, pid, on = 1;
++ int master, slave, r, pid, on = 1;
+ int authenticated = 0;
+ char *hname;
+ int hostok;
+@@ -421,12 +422,34 @@ static void doit(int netfd) {
+ write(netfd, "rlogind: Host address mismatch.\r\n", 33);
+ }
+
+- pid = forkpty(&master, line, NULL, &win);
+- if (pid < 0) {
++ /* We can no longer call forkpty here (a convenience routine that combines
++ openpty, fork, and login_tty) because, with forkpty, the slave end of
++ the pty is open only in the child process. The child process execs
++ /bin/login which now closes all open file descriptors before doing a
++ vhangup (see lkml.org/lkml/2012/6/5/145), and this resets packet mode
++ on the pty, undoing the effect of the ioctl(master, TIOCPKT, &on) call
++ made by the parent.
++
++ Instead, we call openpty, fork, and login_tty individually, so that we
++ can keep a file descriptor to the slave open in the parent process,
++ thereby retaining packet mode even when the child closes file descriptors
++ to call vhangup. */
++ r = openpty(&master, &slave, line, NULL, &win);
++ if (r < 0) {
+ if (errno == ENOENT) fatal(netfd, "Out of ptys", 0);
+- fatal(netfd, "Forkpty", 1);
++ fatal(netfd, "Openpty", 1);
++ }
++
++ signal(SIGHUP, SIG_IGN);
++
++ pid = fork();
++ if (pid < 0) {
++ fatal(netfd, "Fork", 1);
+ }
++
+ if (pid == 0) {
++ close(master);
++ login_tty(slave);
+ /* netfd should always be 0, but... */
+ if (netfd > 2) close(netfd);
+ child(hname, termtype, lusername, authenticated, rusername);
diff --git a/rsh.spec b/rsh.spec
index 3e8f8ba..82ff227 100644
--- a/rsh.spec
+++ b/rsh.spec
@@ -82,6 +82,7 @@ Patch41: netkit-rsh-0.17-rh650119.patch
Patch42: netkit-rsh-0.17-rh710987.patch
Patch43: netkit-rsh-0.17-rh784467.patch
Patch44: netkit-rsh-0.17-rh896583.patch
+Patch45: netkit-rsh-0.17-rh947213.patch
%description
The rsh package contains a set of programs which allow users to run
@@ -154,6 +155,7 @@ from other machines
%patch42 -p1 -b .rh710987
%patch43 -p1 -b .rh784467
%patch44 -b .rh896583
+%patch45 -p1 -b .rh947213
# No, I don't know what this is doing in the tarball.
rm -f rexec/rexec
More information about the scm-commits
mailing list