samba-tool: add --full-dn option to user list command
authorJule Anger <ja@sernet.de>
Thu, 22 Aug 2019 07:30:21 +0000 (09:30 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 21 Jan 2020 14:38:44 +0000 (14:38 +0000)
With this option the command lists the users distringuished names
instead of the sAMAccountNames.

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 c66fd98139c0fd5189fae3bcb9bdd8ed1dd74bec..9a1883fea1f4de2abfb6c877f363c52c582edc02 100644 (file)
@@ -481,6 +481,10 @@ 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("--full-dn", dest="full_dn",
+               default=False,
+               action='store_true',
+               help="Display DN instead of the sAMAccountName.")
     ]
 
     takes_optiongroups = {
@@ -489,7 +493,12 @@ class cmd_user_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,
+            full_dn=False):
         lp = sambaopts.get_loadparm()
         creds = credopts.get_credentials(lp, fallback_machine=True)
 
@@ -505,6 +514,10 @@ class cmd_user_list(Command):
             return
 
         for msg in res:
+            if full_dn:
+                self.outf.write("%s\n" % msg.get("dn"))
+                continue
+
             self.outf.write("%s\n" % msg.get("samaccountname", idx=0))