From 0365df93e61b44cbdd7270c48495a6b4ac251677 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 3 Jul 2012 14:17:48 +1000 Subject: samba-tool: gpo: Use utility function dc_url() to set the connection url In create and fetch subcommands, we also need to know DC hostname. So first find a DC and use DC hostname to construct connection url. If ldap:// url is specified with -H, then use that to construct DC hostname. --- source4/scripting/python/samba/netcmd/gpo.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'source4/scripting/python') diff --git a/source4/scripting/python/samba/netcmd/gpo.py b/source4/scripting/python/samba/netcmd/gpo.py index cbddcc5a8d..86c5465bb5 100644 --- a/source4/scripting/python/samba/netcmd/gpo.py +++ b/source4/scripting/python/samba/netcmd/gpo.py @@ -672,11 +672,11 @@ class cmd_getinheritance(Command): def run(self, container_dn, H=None, sambaopts=None, credopts=None, versionopts=None): - self.url = H self.lp = sambaopts.get_loadparm() - self.creds = credopts.get_credentials(self.lp, fallback_machine=True) + self.url = dc_url(self.lp, self.creds, H) + samdb_connect(self) try: @@ -723,13 +723,12 @@ class cmd_setinheritance(Command): else: raise CommandError("Unknown inheritance state (%s)" % inherit_state) - self.url = H self.lp = sambaopts.get_loadparm() - self.creds = credopts.get_credentials(self.lp, fallback_machine=True) - samdb_connect(self) + self.url = dc_url(self.lp, self.creds, H) + samdb_connect(self) try: msg = self.samdb.search(base=container_dn, scope=ldb.SCOPE_BASE, expression="(objectClass=*)", @@ -774,8 +773,13 @@ class cmd_fetch(Command): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp, fallback_machine=True) - dc_hostname = netcmd_finddc(self.lp, self.creds) - self.url = dc_url(self.lp, self.creds, H, dc=dc_hostname) + # We need to know writable DC to setup SMB connection + if H and H.startswith('ldap://'): + dc_hostname = H[7:] + self.url = H + else: + dc_hostname = netcmd_finddc(self.lp, self.creds) + self.url = dc_url(self.lp, self.creds, dc=dc_hostname) samdb_connect(self) try: @@ -843,9 +847,14 @@ class cmd_create(Command): self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp, fallback_machine=True) - self.url = dc_url(self.lp, self.creds, url=H) + # We need to know writable DC to setup SMB connection + if H and H.startswith('ldap://'): + dc_hostname = H[7:] + self.url = H + else: + dc_hostname = netcmd_finddc(self.lp, self.creds) + self.url = dc_url(self.lp, self.creds, dc=dc_hostname) - dc_hostname = netcmd_finddc(self.lp, self.creds) samdb_connect(self) msg = get_gpo_info(self.samdb, displayname=displayname) -- cgit