s4:samba-tool/gpo: use the dns_domain from the server when creating gpos
authorStefan Metzmacher <metze@samba.org>
Thu, 29 Nov 2012 08:31:12 +0000 (09:31 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 3 Dec 2012 07:46:25 +0000 (08:46 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source4/scripting/python/samba/netcmd/gpo.py

index cc6381990b3dbfa51f0f2d9b84cd975fe57c2a27..5169085635012b35eaf03819929d1617c04dc288 100644 (file)
@@ -42,6 +42,8 @@ from samba import policy
 from samba import smb
 import uuid
 from samba.ntacls import dsacl2fsacl
+from samba.dcerpc import nbt
+from samba.net import Net
 
 
 def samdb_connect(ctx):
@@ -892,12 +894,22 @@ class cmd_create(Command):
         self.lp = sambaopts.get_loadparm()
         self.creds = credopts.get_credentials(self.lp, fallback_machine=True)
 
+        net = Net(creds=self.creds, lp=self.lp)
+
         # We need to know writable DC to setup SMB connection
         if H and H.startswith('ldap://'):
             dc_hostname = H[7:]
             self.url = H
+            flags = (nbt.NBT_SERVER_LDAP |
+                     nbt.NBT_SERVER_DS |
+                     nbt.NBT_SERVER_WRITABLE)
+            cldap_ret = net.finddc(address=dc_hostname, flags=flags)
         else:
-            dc_hostname = netcmd_finddc(self.lp, self.creds)
+            flags = (nbt.NBT_SERVER_LDAP |
+                     nbt.NBT_SERVER_DS |
+                     nbt.NBT_SERVER_WRITABLE)
+            cldap_ret = net.finddc(domain=self.lp.get('realm'), flags=flags)
+            dc_hostname = cldap_ret.pdc_dns_name
             self.url = dc_url(self.lp, self.creds, dc=dc_hostname)
 
         samdb_connect(self)
@@ -909,7 +921,7 @@ class cmd_create(Command):
         # Create new GUID
         guid  = str(uuid.uuid4())
         gpo = "{%s}" % guid.upper()
-        realm = self.lp.get('realm')
+        realm = cldap_ret.dns_domain
         unc_path = "\\\\%s\\sysvol\\%s\\Policies\\%s" % (realm, realm, gpo)
 
         # Create GPT