From: Andrew Bartlett Date: Fri, 6 Apr 2018 04:21:15 +0000 (+1200) Subject: samba-tool: Use same method for removing trailing $ as elsewhere in the tool X-Git-Tag: ldb-1.4.0~685 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=95cad5cab30fb0cc54a730a8bbef88c34d6ed875;p=thirdparty%2Fsamba.git samba-tool: Use same method for removing trailing $ as elsewhere in the tool Signed-off-by: Andrew Bartlett Reviewed-by: Douglas Bagnall Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Fri Apr 6 09:30:14 CEST 2018 on sn-devel-144 --- diff --git a/python/samba/netcmd/computer.py b/python/samba/netcmd/computer.py index 8462379e4ed..3b130b1fa25 100644 --- a/python/samba/netcmd/computer.py +++ b/python/samba/netcmd/computer.py @@ -24,6 +24,7 @@ import samba.getopt as options import ldb import socket import samba +import re from samba import sd_utils from samba.dcerpc import dnsserver, dnsp, security from samba.dnsserver import ARecord, AAAARecord @@ -266,8 +267,13 @@ Example3 shows how to create a new computer in the OrgUnit organizational unit. if ip_address_list: # if ip_address_list provided, then we need to create DNS # records for this computer. + + hostname = re.sub(r"\$$", "", computername) + if hostname.count('$'): + raise CommandError('Illegal computername "%s"' % computername) + filters = '(&(sAMAccountName={}$)(objectclass=computer))'.format( - ldb.binary_encode(computername.rstrip('$'))) + ldb.binary_encode(hostname)) recs = samdb.search( base=samdb.domain_dn(), @@ -289,7 +295,7 @@ Example3 shows how to create a new computer in the OrgUnit organizational unit. ) add_dns_records( - samdb, computername.rstrip('$'), dns_conn, + samdb, hostname, dns_conn, change_owner_sd, samdb.host_dns_name(), ip_address_list, self.get_logger()) except Exception, e: