diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 6f0528a8..90484dc9 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -693,6 +693,7 @@ def run_argparse( ap2.add_argument("--smb1", action="store_true", help="disable SMBv2, only enable SMBv1 (CIFS)") ap2.add_argument("--smb-port", metavar="PORT", type=int, default=445, help="port to listen on -- if you change this value, you must NAT from TCP:445 to this port using iptables or similar") ap2.add_argument("--smb-nwa-1", action="store_true", help="disable impacket#1433 workaround (truncate directory listings to 64kB)") + ap2.add_argument("--smb-nwa-2", action="store_true", help="disable impacket workaround for filecopy globs") ap2.add_argument("--smbv", action="store_true", help="verbose") ap2.add_argument("--smbvv", action="store_true", help="verboser") ap2.add_argument("--smbvvv", action="store_true", help="verbosest") diff --git a/copyparty/smbd.py b/copyparty/smbd.py index 8f9c9ed2..a08bedf6 100644 --- a/copyparty/smbd.py +++ b/copyparty/smbd.py @@ -76,6 +76,9 @@ class SMB(object): fop.isdir = self._p_isdir smbserver.os.path = fop + if not self.args.smb_nwa_2: + fop.join = self._p_join + # other patches smbserver.isInFileJail = self._is_in_file_jail self._disarm() @@ -272,6 +275,12 @@ class SMB(object): except: return False + def _p_join(self, *a) -> str: + # impacket.smbserver reads globs from queryDirectoryRequest['Buffer'] + # where somehow `fds.*` becomes `fds"*` so lets fix that + ret = os.path.join(*a) + return ret.replace('"', ".") # type: ignore + def _hook(self, *a: Any, **ka: Any) -> None: src = inspect.currentframe().f_back.f_code.co_name error("\033[31m%s:hook(%s)\033[0m", src, a)