From d0a1bf49e2bcbabba74960027c5e3f75ab27853a Mon Sep 17 00:00:00 2001 From: erkin Date: Tue, 30 Mar 2021 12:31:43 +0300 Subject: T3354: Handle user break and prematurely closed stdin --- src/helpers/strip-private.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/helpers/strip-private.py b/src/helpers/strip-private.py index 023298eec..420a039eb 100755 --- a/src/helpers/strip-private.py +++ b/src/helpers/strip-private.py @@ -79,13 +79,18 @@ def strip_lines(rules: tuple) -> None: """ Read stdin line by line and apply the given stripping rules. """ - for line in sys.stdin: - if not args.keep_address: - line = strip_address(line) - for (condition, regexp, subst) in rules: - if condition: - line = regexp.sub(subst, line) - print(line, end='') + try: + for line in sys.stdin: + if not args.keep_address: + line = strip_address(line) + for (condition, regexp, subst) in rules: + if condition: + line = regexp.sub(subst, line) + print(line, end='') + # stdin can be cut for any reason, such as user interrupt or the pager terminating before the text can be read. + # All we can do is gracefully exit. + except (BrokenPipeError, EOFError, KeyboardInterrupt): + sys.exit(1) if __name__ == "__main__": args = parser.parse_args() -- cgit v1.2.3 From 229a884166946fb2ce1d7854bf62ed6019114915 Mon Sep 17 00:00:00 2001 From: erkin Date: Tue, 30 Mar 2021 15:42:50 +0300 Subject: T3356: Encode strings given to/returned from curl in TFTP transfers --- python/vyos/remote.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/vyos/remote.py b/python/vyos/remote.py index ad9706a82..0c0de8e0f 100644 --- a/python/vyos/remote.py +++ b/python/vyos/remote.py @@ -57,11 +57,11 @@ def download_sftp(local_path, hostname, remote_path,\ def upload_tftp(local_path, hostname, remote_path, port=69): with open(local_path, 'rb') as file: - cmd(f'curl -s -T - tftp://{hostname}:{port}/{remote_path}', stderr=None, input=file.read()) + cmd(f'curl -s -T - tftp://{hostname}:{port}/{remote_path}', stderr=None, input=file.read()).encode() def download_tftp(local_path, hostname, remote_path, port=69): with open(local_path, 'wb') as file: - file.write(cmd(f'curl -s tftp://{hostname}:{port}/{remote_path}', stderr=None)) + file.write(cmd(f'curl -s tftp://{hostname}:{port}/{remote_path}', stderr=None).encode()) def download_http(urlstring, local_path): with open(local_path, 'wb') as file: -- cgit v1.2.3 From a32d5e824df9e16d4e6c9198f093fd9f1baffcc6 Mon Sep 17 00:00:00 2001 From: erkin Date: Tue, 30 Mar 2021 15:43:05 +0300 Subject: Remove SFTP empty password check --- python/vyos/remote.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/python/vyos/remote.py b/python/vyos/remote.py index 0c0de8e0f..18e772cc8 100644 --- a/python/vyos/remote.py +++ b/python/vyos/remote.py @@ -79,10 +79,6 @@ def download(local_path, urlstring): username = url.username if url.username else 'anonymous' download_ftp(local_path, url.hostname, url.path, username, url.password) elif url.scheme == 'sftp' or url.scheme == 'scp': - # None means we don't want to use password authentication. - # An empty string (what urlparse returns when a password doesn't - # exist in the URL) means the password is an empty string. - password = url.password if url.password else None download_sftp(local_path, url.hostname, url.path, url.username, password) elif url.scheme == 'tftp': download_tftp(local_path, url.hostname, url.path) @@ -98,7 +94,6 @@ def upload(local_path, urlstring): username = url.username if url.username else 'anonymous' upload_ftp(local_path, url.hostname, url.path, username, url.password) elif url.scheme == 'sftp' or url.scheme == 'scp': - password = url.password if url.password else None upload_sftp(local_path, url.hostname, url.path, url.username, password) elif url.scheme == 'tftp': upload_tftp(local_path, url.hostname, url.path) -- cgit v1.2.3