Skip to content

Commit

Permalink
Workaround when sudo prints text to standard out
Browse files Browse the repository at this point in the history
When we use sudo and start the firewall process, we should be able to
read standard in and find the string "READY". However, some
administrators use a wrapper around sudo to print warning messages
(instead of sudo's lecture feature) to standard out. This commit reads
up to 100 lines looking for "READY" instead of expecting it on the
first line.

I believe this should fix issue #916.
  • Loading branch information
skuhl authored and brianmay committed Jan 1, 2024
1 parent 59b6777 commit b4e4680
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion sshuttle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,28 @@ def setup():
'%r returned %d' % (self.argv, rv))
continue

# Normally, READY will be the first text on the first
# line. However, if an administrator replaced sudo with a
# shell script that echos a message to stdout and then
# runs sudo, READY won't be on the first line. To
# workaround this problem, we read a limited number of
# lines until we encounter "READY". Store all of the text
# we skipped in case we need it for an error message.
#
# A proper way to print a sudo warning message is to use
# sudo's lecture feature. sshuttle works correctly without
# this hack if sudo's lecture feature is used instead.
skipped_text = line
for i in range(100):
if line[0:5] == b'READY':
break
line = self.pfile.readline()
skipped_text += line

if line[0:5] != b'READY':
debug1('Unable to start firewall manager. '
'Expected READY, got %r. '
'Command=%r' % (line, self.argv))
'Command=%r' % (skipped_text, self.argv))
continue

method_name = line[6:-1]
Expand Down

0 comments on commit b4e4680

Please sign in to comment.