]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: add -b/--base-dn option to OUs list command
authorJule Anger <ja@sernet.de>
Mon, 26 Aug 2019 08:25:18 +0000 (10:25 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 21 Jan 2020 14:38:45 +0000 (14:38 +0000)
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 <ja@sernet.de>
Reviewed-by: Björn Baumbach <bb@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
python/samba/netcmd/ou.py

index a715a5bee139f86252eb57488d495e699e66e3f1..f68cd2f7af2f68c4d3c9d3fdbd348fc7328468ba 100644 (file)
@@ -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))