Skip to content

Commit 9b6200a

Browse files
committed
LDAP: Add sanity checks to group modification functions
1 parent 23f3a6d commit 9b6200a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

conditional/util/ldap.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def __ldap_is_member_of_group__(username, group):
8989

9090
@ldap_init_required
9191
def __ldap_add_member_to_group__(username, group):
92+
if read_only:
93+
print("LDAP: Adding user %s to group %s" % (username, group))
94+
return
95+
if __ldap_is_member_of_group__(username, group):
96+
return
9297
ldap_results = ldap_conn.search_s(group_search_ou, ldap.SCOPE_SUBTREE,
9398
"(cn=%s)" % group)
9499
if len(ldap_results) != 1:
@@ -105,6 +110,11 @@ def __ldap_add_member_to_group__(username, group):
105110

106111

107112
def __ldap_remove_member_from_group__(username, group):
113+
if read_only:
114+
print("LDAP: Removing user %s from group %s" % (username, group))
115+
return
116+
if not __ldap_is_member_of_group__(username, group):
117+
return
108118
ldap_results = ldap_conn.search_s(group_search_ou, ldap.SCOPE_SUBTREE,
109119
"(cn=%s)" % group)
110120
if len(ldap_results) != 1:

0 commit comments

Comments
 (0)