]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: Use same method for removing trailing $ as elsewhere in the tool
authorAndrew Bartlett <abartlet@samba.org>
Fri, 6 Apr 2018 04:21:15 +0000 (16:21 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 6 Apr 2018 07:30:14 +0000 (09:30 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Fri Apr  6 09:30:14 CEST 2018 on sn-devel-144

python/samba/netcmd/computer.py

index 8462379e4edabe9531e8c54a8719266b99f6592d..3b130b1fa256b149178352bdd7db788951069d4f 100644 (file)
@@ -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: