summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-08-15 12:06:59 +1000
committerAndrew Tridgell <tridge@samba.org>2011-08-18 09:26:59 +1000
commit75a90a952b8d65329c7f8cb055b5bb685d4e0b7d (patch)
tree79caba208216c079463b620e20ed9d9365be39c0 /source4/scripting
parent8c52caa83c3487463e3457e96bd4f600c0ef87fc (diff)
downloadsamba-75a90a952b8d65329c7f8cb055b5bb685d4e0b7d.tar.gz
samba-75a90a952b8d65329c7f8cb055b5bb685d4e0b7d.tar.bz2
samba-75a90a952b8d65329c7f8cb055b5bb685d4e0b7d.zip
s4-samdb: added deleteuser() to samdb
This is similar to deletegroup()
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/python/samba/samdb.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index 70f73da6f4..f8369d6c5a 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -393,6 +393,29 @@ member: %s
else:
self.transaction_commit()
+
+ def deleteuser(self, username):
+ """Deletes a user
+
+ :param username: Name of the target user
+ """
+
+ filter = "(&(sAMAccountName=%s)(objectCategory=%s,%s))" % (ldb.binary_encode(username), "CN=Person,CN=Schema,CN=Configuration", self.domain_dn())
+ self.transaction_start()
+ try:
+ target = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
+ expression=filter, attrs=[])
+ if len(target) == 0:
+ raise Exception('Unable to find user "%s"' % username)
+ assert(len(target) == 1)
+ self.delete(target[0].dn)
+ except Exception:
+ self.transaction_cancel()
+ raise
+ else:
+ self.transaction_commit()
+
+
def setpassword(self, search_filter, password,
force_change_at_next_login=False, username=None):
"""Sets the password for a user