samba-tool: add -b/--base-dn option to contacts list command
authorJule Anger <ja@sernet.de>
Mon, 26 Aug 2019 07:33:24 +0000 (09:33 +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 contacts of a
specify OU or contacts 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/contact.py

index b35f3f16a88056e048dcecebe52c877b07010048..73b7d141af6241257a475ed0efa1a199cc4b5857 100644 (file)
@@ -254,6 +254,9 @@ class cmd_list(Command):
                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,
@@ -272,6 +275,7 @@ class cmd_list(Command):
             credopts=None,
             versionopts=None,
             H=None,
+            base_dn=None,
             full_dn=False):
         lp = sambaopts.get_loadparm()
         creds = credopts.get_credentials(lp, fallback_machine=True)
@@ -281,8 +285,11 @@ class cmd_list(Command):
                       credentials=creds,
                       lp=lp)
 
-        domain_dn = samdb.domain_dn()
-        res = samdb.search(domain_dn,
+        search_dn = 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=contact)",
                            attrs=["name"])