From 23b1d09a5fd9825786343a98f9aab756dd749f95 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Aug 2011 12:07:50 +1000 Subject: samba-tool: changed samba-tool user delete to use samdb instead of Net() this makes it possible to use with -H, so you can delete users on remote DCs or against local databases --- source4/scripting/python/samba/netcmd/user.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/netcmd/user.py b/source4/scripting/python/samba/netcmd/user.py index 88d93e3bea..b9c562dbc6 100644 --- a/source4/scripting/python/samba/netcmd/user.py +++ b/source4/scripting/python/samba/netcmd/user.py @@ -106,21 +106,29 @@ class cmd_user_add(Command): class cmd_user_delete(Command): - """Delete a user.""" + """Delete a user""" - synopsis = "%prog user delete [options]" + synopsis = "%prog user delete " - takes_args = ["name"] + takes_options = [ + Option("-H", "--URL", help="LDB URL for database or target server", type=str, + metavar="URL", dest="H"), + ] + + takes_args = ["username"] + + def run(self, username, credopts=None, sambaopts=None, versionopts=None, H=None): - def run(self, name, credopts=None, sambaopts=None, versionopts=None): lp = sambaopts.get_loadparm() creds = credopts.get_credentials(lp, fallback_machine=True) - net = Net(creds, lp, server=credopts.ipaddress) - try: - net.delete_user(name) - except RuntimeError, msg: - raise CommandError("Failed to delete user '%s': %s" % (name, msg)) + try: + samdb = SamDB(url=H, session_info=system_session(), + credentials=creds, lp=lp) + samdb.deleteuser(username) + except Exception, e: + raise CommandError('Failed to remove user "%s"' % username, e) + print("Deleted user %s" % username) class cmd_user_enable(Command): -- cgit