1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-20 22:50:26 +03:00

samba-tool: improved error handling in user setexpiry

This commit is contained in:
Andrew Tridgell 2011-06-01 14:46:04 +10:00
parent 7b3d8b6c90
commit 1bc1ac0d08
2 changed files with 9 additions and 1 deletions

View File

@ -151,7 +151,11 @@ class cmd_user_setexpiry(Command):
samdb = SamDB(url=H, session_info=system_session(),
credentials=creds, lp=lp)
samdb.setexpiry(filter, days*24*3600, no_expiry_req=noexpiry)
try:
samdb.setexpiry(filter, days*24*3600, no_expiry_req=noexpiry)
except Exception, msg:
raise CommandError("Failed to set expiry for user %s: %s" % (username or filter, msg))
print("Set expiry for user %s to %u days" % (username or filter, days))
class cmd_user(SuperCommand):
"""User management [server connection needed]"""

View File

@ -108,6 +108,8 @@ userAccountControl: %u
"""
res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
expression=search_filter, attrs=[])
if len(res) == 0:
raise Exception('Unable to find user "%s"' % search_filter)
assert(len(res) == 1)
user_dn = res[0].dn
@ -411,6 +413,8 @@ unicodePwd:: %s
res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
expression=search_filter,
attrs=["userAccountControl", "accountExpires"])
if len(res) == 0:
raise Exception('Unable to find user "%s"' % search_filter)
assert(len(res) == 1)
user_dn = res[0].dn