From b292a266a8db3e5fbe67cd14c0167869efba2705 Mon Sep 17 00:00:00 2001 From: Jule Anger Date: Mon, 26 Aug 2019 08:46:24 +0200 Subject: samba-tool: add -b/--base-dn option to computer list command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this option it's e.g. possible to list the computers of a specify OU or computers 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 --- python/samba/netcmd/computer.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/samba/netcmd/computer.py b/python/samba/netcmd/computer.py index 6988b6dffe3..d48a3e732fd 100644 --- a/python/samba/netcmd/computer.py +++ b/python/samba/netcmd/computer.py @@ -527,6 +527,9 @@ class cmd_computer_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", @@ -544,6 +547,7 @@ class cmd_computer_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) @@ -553,8 +557,12 @@ class cmd_computer_list(Command): filter = "(sAMAccountType=%u)" % (dsdb.ATYPE_WORKSTATION_TRUST) - 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=filter, attrs=["samaccountname"]) if (len(res) == 0): -- cgit v1.2.1