diff options
Diffstat (limited to 'source4/scripting')
-rw-r--r-- | source4/scripting/python/samba/netcmd/user.py | 26 |
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): |