]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: add -b/--base-dn option to users list command
authorJule Anger <ja@sernet.de>
Mon, 26 Aug 2019 07:47:41 +0000 (09:47 +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 users of a
specify OU or users 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/user.py

index b04ee49d018856abeb00e33757394a1c0f343f91..26db3105da0db0237df05b962232c1f3572d781f 100644 (file)
@@ -481,6 +481,9 @@ class cmd_user_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',
@@ -498,6 +501,7 @@ class cmd_user_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)
@@ -505,8 +509,12 @@ class cmd_user_list(Command):
         samdb = SamDB(url=H, session_info=system_session(),
                       credentials=creds, lp=lp)
 
-        domain_dn = samdb.domain_dn()
-        res = samdb.search(domain_dn, scope=ldb.SCOPE_SUBTREE,
+        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=user)(userAccountControl:%s:=%u))"
                                        % (ldb.OID_COMPARATOR_AND, dsdb.UF_NORMAL_ACCOUNT)),
                            attrs=["samaccountname"])