From: Andrew Bartlett Date: Fri, 6 Apr 2018 04:20:22 +0000 (+1200) Subject: samba-tool: Escape username and computername in ldb search filter X-Git-Tag: ldb-1.4.0~686 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a6c2ac88f8c2423ffbb7cdf2624ca5d95cb3d30;p=thirdparty%2Fsamba.git samba-tool: Escape username and computername in ldb search filter Signed-off-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/netcmd/computer.py b/python/samba/netcmd/computer.py index 17ae581441f..8462379e4ed 100644 --- a/python/samba/netcmd/computer.py +++ b/python/samba/netcmd/computer.py @@ -360,7 +360,8 @@ sudo is used so a computer may run the command as root. samaccountname = "%s$" % computername filter = ("(&(sAMAccountName=%s)(sAMAccountType=%u))" % - (samaccountname, dsdb.ATYPE_WORKSTATION_TRUST)) + (ldb.binary_encode(samaccountname), + dsdb.ATYPE_WORKSTATION_TRUST)) try: res = samdb.search(base=samdb.domain_dn(), scope=ldb.SCOPE_SUBTREE, @@ -544,7 +545,8 @@ class cmd_computer_move(Command): samaccountname = "%s$" % computername filter = ("(&(sAMAccountName=%s)(sAMAccountType=%u))" % - (samaccountname, dsdb.ATYPE_WORKSTATION_TRUST)) + (ldb.binary_encode(samaccountname), + dsdb.ATYPE_WORKSTATION_TRUST)) try: res = samdb.search(base=domain_dn, expression=filter, diff --git a/python/samba/netcmd/user.py b/python/samba/netcmd/user.py index 6eebf927613..dfe167d8c7d 100644 --- a/python/samba/netcmd/user.py +++ b/python/samba/netcmd/user.py @@ -440,7 +440,7 @@ Example2 shows how to delete a user in the domain against the local server. su credentials=creds, lp=lp) filter = ("(&(sAMAccountName=%s)(sAMAccountType=805306368))" % - username) + ldb.binary_encode(username)) try: res = samdb.search(base=samdb.domain_dn(),