From: Jule Anger Date: Mon, 26 Aug 2019 08:25:18 +0000 (+0200) Subject: samba-tool: add -b/--base-dn option to OUs list command X-Git-Tag: samba-4.12.0rc1~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2186c5a6a4c6de16a0371289832ca99bbc5bc3c2;p=thirdparty%2Fsamba.git samba-tool: add -b/--base-dn option to OUs list command With this option it's e.g. possible to list the OUs which are located under a different specific place in the AD. Signed-off-by: Jule Anger Reviewed-by: Björn Baumbach Reviewed-by: Ralph Boehme --- diff --git a/python/samba/netcmd/ou.py b/python/samba/netcmd/ou.py index a715a5bee13..f68cd2f7af2 100644 --- a/python/samba/netcmd/ou.py +++ b/python/samba/netcmd/ou.py @@ -298,6 +298,9 @@ class cmd_list(Command): takes_options = [ Option("-H", "--URL", help="LDB URL for database or target server", type=str, metavar="URL", dest="H"), + Option("-b", "--base-dn", + help="Specify base DN to use.", + type=str), Option("--full-dn", dest="full_dn", default=False, action='store_true', help="Display DNs including the base DN."), ] @@ -308,15 +311,24 @@ class cmd_list(Command): "versionopts": options.VersionOptions, } - def run(self, sambaopts=None, credopts=None, versionopts=None, H=None, + def run(self, + sambaopts=None, + credopts=None, + versionopts=None, + H=None, + base_dn=None, full_dn=False): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) - domain_dn = ldb.Dn(samdb, samdb.domain_dn()) - res = samdb.search(domain_dn, scope=ldb.SCOPE_SUBTREE, + search_dn = ldb.Dn(samdb, samdb.domain_dn()) + if base_dn: + search_dn = samdb.normalize_dn_in_domain(base_dn) + + res = samdb.search(search_dn, + scope=ldb.SCOPE_SUBTREE, expression="(objectClass=organizationalUnit)", attrs=[]) if (len(res) == 0): @@ -324,6 +336,7 @@ class cmd_list(Command): for msg in sorted(res, key=attrgetter('dn')): if not full_dn: + domain_dn = ldb.Dn(samdb, samdb.domain_dn()) msg.dn.remove_base_components(len(domain_dn)) self.outf.write("%s\n" % str(msg.dn))