mirror of
https://github.com/samba-team/samba.git
synced 2025-01-08 21:18:16 +03:00
bug 12292: stop user.py throwing errors if user is unknown
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12292 Signed-off-by: Rowland Penny <rpenny@samba.org> Reviewed-by: Alexander Bokovoy <ab@samba.org>
This commit is contained in:
parent
1f9501cad6
commit
22da0887b2
@ -406,10 +406,23 @@ Example2 shows how to delete a user in the domain against the local server. su
|
||||
lp = sambaopts.get_loadparm()
|
||||
creds = credopts.get_credentials(lp, fallback_machine=True)
|
||||
|
||||
samdb = SamDB(url=H, session_info=system_session(),
|
||||
credentials=creds, lp=lp)
|
||||
|
||||
filter = ("(&(sAMAccountName=%s)(sAMAccountType=805306368))" %
|
||||
username)
|
||||
|
||||
try:
|
||||
samdb = SamDB(url=H, session_info=system_session(),
|
||||
credentials=creds, lp=lp)
|
||||
samdb.deleteuser(username)
|
||||
res = samdb.search(base=samdb.domain_dn(),
|
||||
scope=ldb.SCOPE_SUBTREE,
|
||||
expression=filter,
|
||||
attrs=["dn"])
|
||||
user_dn = res[0].dn
|
||||
except IndexError:
|
||||
raise CommandError('Unable to find user "%s"' % (username))
|
||||
|
||||
try:
|
||||
samdb.delete(user_dn)
|
||||
except Exception, e:
|
||||
raise CommandError('Failed to remove user "%s"' % username, e)
|
||||
self.outf.write("Deleted user %s\n" % username)
|
||||
|
Loading…
Reference in New Issue
Block a user