summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-08-15 12:07:50 +1000
committerAndrew Tridgell <tridge@samba.org>2011-08-18 09:26:59 +1000
commit23b1d09a5fd9825786343a98f9aab756dd749f95 (patch)
tree998bd4ad7e0c4a449af7634738aa1522fdd1b584
parent75a90a952b8d65329c7f8cb055b5bb685d4e0b7d (diff)
downloadsamba-23b1d09a5fd9825786343a98f9aab756dd749f95.tar.gz
samba-23b1d09a5fd9825786343a98f9aab756dd749f95.tar.bz2
samba-23b1d09a5fd9825786343a98f9aab756dd749f95.zip
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
-rw-r--r--source4/scripting/python/samba/netcmd/user.py26
1 files changed, 17 insertions, 9 deletions
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 <username> [options]"
+ synopsis = "%prog user delete <username>"
- 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):