From 6d5facec4c5728f71f345f6e4e7b6738ea66888b Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 4 Nov 2018 20:43:29 +0000 Subject: [PATCH] su/sudo: fallout from previous commits issue #418 and FD cleanup work. --- mitogen/su.py | 4 +++- mitogen/sudo.py | 10 ++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mitogen/su.py b/mitogen/su.py index 65357a3e..9faee2d4 100644 --- a/mitogen/su.py +++ b/mitogen/su.py @@ -88,6 +88,8 @@ class Stream(mitogen.parent.Stream): password_required_msg = 'su password is required' def _connect_input_loop(self, it): + password_sent = False + for buf in it: LOG.debug('%r: received %r', self, buf) if buf.endswith(self.EC0_MARKER): @@ -106,10 +108,10 @@ class Stream(mitogen.parent.Stream): mitogen.core.to_text(self.password + '\n').encode('utf-8') ) password_sent = True + raise mitogen.core.StreamError('bootstrap failed') def _connect_bootstrap(self): - password_sent = False it = mitogen.parent.iter_read( fds=[self.receive_side.fd], deadline=self.connect_deadline, diff --git a/mitogen/sudo.py b/mitogen/sudo.py index 68b27fec..cf8a44d9 100644 --- a/mitogen/sudo.py +++ b/mitogen/sudo.py @@ -116,10 +116,6 @@ class Stream(mitogen.parent.Stream): create_child = staticmethod(mitogen.parent.hybrid_tty_create_child) child_is_immediate_subprocess = False - #: Once connected, points to the corresponding DiagLogStream, allowing it to - #: be disconnected at the same time this stream is being torn down. - tty_stream = None - sudo_path = 'sudo' username = 'root' password = None @@ -174,6 +170,8 @@ class Stream(mitogen.parent.Stream): password_required_msg = 'sudo password is required' def _connect_input_loop(self, it): + password_sent = False + for buf in it: LOG.debug('%r: received %r', self, buf) if buf.endswith(self.EC0_MARKER): @@ -184,10 +182,11 @@ class Stream(mitogen.parent.Stream): raise PasswordError(self.password_required_msg) if password_sent: raise PasswordError(self.password_incorrect_msg) - self.tty_stream.transmit_side.write( + self.diag_stream.transmit_side.write( mitogen.core.to_text(self.password + '\n').encode('utf-8') ) password_sent = True + raise mitogen.core.StreamError('bootstrap failed') def _connect_bootstrap(self): @@ -195,7 +194,6 @@ class Stream(mitogen.parent.Stream): if self.diag_stream is not None: fds.append(self.diag_stream.receive_side.fd) - password_sent = False it = mitogen.parent.iter_read( fds=fds, deadline=self.connect_deadline,