diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-12-08 08:20:54 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-12-08 05:26:05 +0100 |
commit | 545932fda590d4c888c0f60fed7a36c1659f0018 (patch) | |
tree | 18bd10e6237e1c2489f25b4527cbd5bb260381ef /source4/scripting/python/samba/netcmd/drs.py | |
parent | 249afc8906bc33ed1e23f50f5c28a8ba0b8354c9 (diff) | |
download | samba-545932fda590d4c888c0f60fed7a36c1659f0018.tar.gz samba-545932fda590d4c888c0f60fed7a36c1659f0018.tar.bz2 samba-545932fda590d4c888c0f60fed7a36c1659f0018.zip |
samba-tools: more reasonable defaults for samba-tool commands
- fallback to machine account where possible
- default to local hostname where this is reasonable
Diffstat (limited to 'source4/scripting/python/samba/netcmd/drs.py')
-rw-r--r-- | source4/scripting/python/samba/netcmd/drs.py | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/source4/scripting/python/samba/netcmd/drs.py b/source4/scripting/python/samba/netcmd/drs.py index 404084426a..f0cde791c5 100644 --- a/source4/scripting/python/samba/netcmd/drs.py +++ b/source4/scripting/python/samba/netcmd/drs.py @@ -33,7 +33,7 @@ from samba.netcmd import ( from samba.samdb import SamDB from samba import drs_utils, nttime2string, dsdb from samba.dcerpc import drsuapi, misc - +import common def drsuapi_connect(ctx): '''make a DRSUAPI connection to the server''' @@ -94,7 +94,7 @@ class cmd_drs_showrepl(Command): "credopts": options.CredentialsOptions, } - takes_args = ["DC"] + takes_args = ["DC?"] def print_neighbour(self, n): '''print one set of neighbour information''' @@ -127,15 +127,14 @@ class cmd_drs_showrepl(Command): return (info_type, info) - def run(self, DC, sambaopts=None, + def run(self, DC=None, sambaopts=None, credopts=None, versionopts=None, server=None): - self.server = DC self.lp = sambaopts.get_loadparm() - - self.creds = credopts.get_credentials(self.lp) - if not self.creds.authentication_requested(): - self.creds.set_machine_account(self.lp) + if DC is None: + DC = common.netcmd_dnsname(self.lp) + self.server = DC + self.creds = credopts.get_credentials(self.lp, fallback_machine=True) drsuapi_connect(self) samdb_connect(self) @@ -145,7 +144,10 @@ class cmd_drs_showrepl(Command): server_dns = self.samdb.search(base="", scope=ldb.SCOPE_BASE, attrs=["dnsHostName"])[0]['dnsHostName'][0] (site, server) = drs_parse_ntds_dn(ntds_dn) - ntds = self.samdb.search(base=ntds_dn, scope=ldb.SCOPE_BASE, attrs=['options', 'objectGUID', 'invocationId']) + try: + ntds = self.samdb.search(base=ntds_dn, scope=ldb.SCOPE_BASE, attrs=['options', 'objectGUID', 'invocationId']) + except Exception, e: + raise CommandError("Failed to search NTDS DN %s" % ntds_dn) conn = self.samdb.search(base=ntds_dn, expression="(objectClass=nTDSConnection)") print("%s\\%s" % (site, server)) @@ -207,17 +209,17 @@ class cmd_drs_kcc(Command): "credopts": options.CredentialsOptions, } - takes_args = ["DC"] + takes_args = ["DC?"] - def run(self, DC, sambaopts=None, + def run(self, DC=None, sambaopts=None, credopts=None, versionopts=None, server=None): - self.server = DC self.lp = sambaopts.get_loadparm() + if DC is None: + DC = common.netcmd_dnsname(self.lp) + self.server = DC - self.creds = credopts.get_credentials(self.lp) - if not self.creds.authentication_requested(): - self.creds.set_machine_account(self.lp) + self.creds = credopts.get_credentials(self.lp, fallback_machine=True) drsuapi_connect(self) @@ -254,9 +256,7 @@ class cmd_drs_replicate(Command): self.server = DEST_DC self.lp = sambaopts.get_loadparm() - self.creds = credopts.get_credentials(self.lp) - if not self.creds.authentication_requested(): - self.creds.set_machine_account(self.lp) + self.creds = credopts.get_credentials(self.lp, fallback_machine=True) drsuapi_connect(self) samdb_connect(self) @@ -292,7 +292,7 @@ class cmd_drs_replicate(Command): try: self.drsuapi.DsReplicaSync(self.drsuapi_handle, 1, req1) - except Exception, e: + except Exception, estr: raise CommandError("DsReplicaSync failed", estr) print("Replicate from %s to %s was successful." % (SOURCE_DC, DEST_DC)) @@ -309,17 +309,16 @@ class cmd_drs_bind(Command): "credopts": options.CredentialsOptions, } - takes_args = ["DC"] + takes_args = ["DC?"] - def run(self, DC, sambaopts=None, + def run(self, DC=None, sambaopts=None, credopts=None, versionopts=None, server=None): - self.server = DC self.lp = sambaopts.get_loadparm() - - self.creds = credopts.get_credentials(self.lp) - if not self.creds.authentication_requested(): - self.creds.set_machine_account(self.lp) + if DC is None: + DC = common.netcmd_dnsname(self.lp) + self.server = DC + self.creds = credopts.get_credentials(self.lp, fallback_machine=True) drsuapi_connect(self) samdb_connect(self) |