summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiampaolo Lauria <lauria2@yahoo.com>2011-11-08 11:51:42 -0500
committerAndrew Tridgell <tridge@samba.org>2011-11-10 14:24:21 +1100
commit34ff5d29e66eac3041204b9cd481a2e7887b1fc9 (patch)
tree894b1d58a3e7e94adc21f1e3c3a3be56f4d1be03
parentda21ff82a50190da9023ef39046ec967d389ef97 (diff)
downloadsamba-34ff5d29e66eac3041204b9cd481a2e7887b1fc9.tar.gz
samba-34ff5d29e66eac3041204b9cd481a2e7887b1fc9.tar.xz
samba-34ff5d29e66eac3041204b9cd481a2e7887b1fc9.zip
samba-tool: Added "user list" command
-rw-r--r--source4/scripting/python/samba/netcmd/user.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/source4/scripting/python/samba/netcmd/user.py b/source4/scripting/python/samba/netcmd/user.py
index 7072521aed..2ebf0ed315 100644
--- a/source4/scripting/python/samba/netcmd/user.py
+++ b/source4/scripting/python/samba/netcmd/user.py
@@ -26,6 +26,7 @@ from getpass import getpass
from samba.auth import system_session
from samba.samdb import SamDB
from samba import gensec, generate_random_password
+from samba import dsdb
from samba.net import Net
from samba.netcmd import (
@@ -186,6 +187,38 @@ Example2 shows how to delete a user in the domain against the local server. su
self.outf.write("Deleted user %s\n" % username)
+class cmd_user_list(Command):
+ """List all users"""
+
+ synopsis = "%prog [options]"
+
+ takes_options = [
+ Option("-H", "--URL", help="LDB URL for database or target server", type=str,
+ metavar="URL", dest="H"),
+ ]
+
+ def run(self, sambaopts=None, credopts=None, versionopts=None, H=None):
+ 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 = samdb.domain_dn()
+ res = samdb.search(domain_dn, scope=ldb.SCOPE_SUBTREE,
+ expression=("(&(objectClass=user)(userAccountControl:%s:=%u))"
+ % (ldb.OID_COMPARATOR_AND, dsdb.UF_NORMAL_ACCOUNT)),
+ attrs=["name"])
+ if (len(res) == 0):
+ return
+
+ try:
+ for msg in res:
+ self.outf.write("%s\n" % msg["name"][0])
+ except Exception, msg:
+ raise CommandError("Failed to get user list: %s" % msg)
+
+
class cmd_user_enable(Command):
"""Enables a user
@@ -440,6 +473,7 @@ class cmd_user(SuperCommand):
subcommands["create"] = cmd_user_create()
subcommands["delete"] = cmd_user_delete()
subcommands["enable"] = cmd_user_enable()
+ subcommands["list"] = cmd_user_list()
subcommands["setexpiry"] = cmd_user_setexpiry()
subcommands["password"] = cmd_user_password()
subcommands["setpassword"] = cmd_user_setpassword()