su/sudo: fallout from previous commits

issue #418 and FD cleanup work.
issue510
David Wilson 6 years ago
parent e180d310b5
commit 6d5facec4c

@ -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,

@ -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,

Loading…
Cancel
Save