Skip to content

Commit

Permalink
Rename wd parameter to cwd in ssh.system and ssh.run_to_end
Browse files Browse the repository at this point in the history
The current working directory should be called the same everywhere.
The `wd` argument is deprecated and `cwd` takes precedence.
  • Loading branch information
peace-maker committed Jul 30, 2023
1 parent b8b29e1 commit 36175d7
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions pwnlib/tubes/ssh.py
Expand Up @@ -1141,8 +1141,8 @@ def which(self, program):

return result

def system(self, process, tty = True, wd = None, env = None, timeout = None, raw = True):
r"""system(process, tty = True, wd = None, env = None, timeout = Timeout.default, raw = True) -> ssh_channel
def system(self, process, tty = True, cwd = None, env = None, timeout = None, raw = True, wd = None):
r"""system(process, tty = True, cwd = None, env = None, timeout = Timeout.default, raw = True) -> ssh_channel
Open a new channel with a specific process inside. If `tty` is True,
then a TTY is requested on the remote server.
Expand All @@ -1162,20 +1162,23 @@ def system(self, process, tty = True, wd = None, env = None, timeout = None, raw
b'4\n'
>>> s.system('env | grep -a AAAA', env={'AAAA': b'\x90'}).recvall()
b'AAAA=\x90\n'
>>> io = s.system('pwd', wd='/tmp')
>>> io = s.system('pwd', cwd='/tmp')
>>> io.recvall()
b'/tmp\n'
>>> io.cwd
'/tmp'
"""

if wd is None:
wd = self.cwd
if wd is not None:
self.warning_once("The 'wd' argument to ssh.system() is deprecated. Use 'cwd' instead.")
if cwd is None:
cwd = wd
if cwd is None:
cwd = self.cwd

if timeout is None:
timeout = self.timeout

return ssh_channel(self, process, tty, wd, env, timeout = timeout, level = self.level, raw = raw)
return ssh_channel(self, process, tty, cwd, env, timeout = timeout, level = self.level, raw = raw)

#: Backward compatibility. Use :meth:`system`
run = system
Expand Down Expand Up @@ -1211,8 +1214,8 @@ def getenv(self, variable, **kwargs):



def run_to_end(self, process, tty = False, wd = None, env = None):
r"""run_to_end(process, tty = False, timeout = Timeout.default, env = None) -> str
def run_to_end(self, process, tty = False, cwd = None, env = None, wd = None):
r"""run_to_end(process, tty = False, cwd = None, env = None, timeout = Timeout.default) -> str
Run a command on the remote server and return a tuple with
(data, exit_status). If `tty` is True, then the command is run inside
Expand All @@ -1224,8 +1227,13 @@ def run_to_end(self, process, tty = False, wd = None, env = None):
(b'Hello\n', 17)
"""

if wd is not None:
self.warning_once("The 'wd' argument to ssh.run_to_end() is deprecated. Use 'cwd' instead.")
if cwd is None:
cwd = wd

with context.local(log_level = 'ERROR'):
c = self.run(process, tty, wd = wd, timeout = Timeout.default)
c = self.run(process, tty, cwd = cwd, env = env, timeout = Timeout.default)
data = c.recvall()
retcode = c.wait()
c.close()
Expand Down Expand Up @@ -1874,7 +1882,7 @@ def set_working_directory(self, wd = None, symlink = False):
wd = packing._need_bytes(wd, 2, 0x80)

if not wd:
wd, status = self.run_to_end('x=$(mktemp -d) && cd $x && chmod +x . && echo $PWD', wd='.')
wd, status = self.run_to_end('x=$(mktemp -d) && cd $x && chmod +x . && echo $PWD', cwd='.')
wd = wd.strip()

if status:
Expand Down

0 comments on commit 36175d7

Please sign in to comment.