git.samba.org
/
metze
/
samba
/
wip.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bug 12293: stop group.py throwing errors if group is unknown
[metze/samba/wip.git]
/
python
/
samba
/
netcmd
/
group.py
diff --git
a/python/samba/netcmd/group.py
b/python/samba/netcmd/group.py
index 722bcc4887fcc15bab7cf8a9eb56e3f1e45d3145..11f87732defe6acbab50ea636b84395dccd7a898 100644
(file)
--- a/
python/samba/netcmd/group.py
+++ b/
python/samba/netcmd/group.py
@@
-169,11
+169,23
@@
Example2 deletes group Group2 from the local server. The command is run under r
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
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)(objectClass=group))" %
+ groupname)
try:
try:
- samdb = SamDB(url=H, session_info=system_session(),
- credentials=creds, lp=lp)
- samdb.deletegroup(groupname)
+ res = samdb.search(base=samdb.domain_dn(),
+ scope=ldb.SCOPE_SUBTREE,
+ expression=filter,
+ attrs=["dn"])
+ group_dn = res[0].dn
+ except IndexError:
+ raise CommandError('Unable to find group "%s"' % (groupname))
+
+ try:
+ samdb.delete(group_dn)
except Exception, e:
# FIXME: catch more specific exception
raise CommandError('Failed to remove group "%s"' % groupname, e)
except Exception, e:
# FIXME: catch more specific exception
raise CommandError('Failed to remove group "%s"' % groupname, e)