Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions PyAuthenNTLM2/ntlm_ad_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def __init__(self, ipad, domain, socketFactory=socket, ldapFactory=None, base=''
self.debug = verbose
#self.smbFactory = smbFactory or (lambda: SMB_Context())

def check_membership(self, user, groups, base=None, tabs=0):
def check_membership(self, user, groups, base=None, tabs=0, checked=[]):
"""Check if the given user belong to ANY of the given groups.

@user The sAMAccountName attribute of the user
Expand Down Expand Up @@ -257,6 +257,7 @@ def check_membership(self, user, groups, base=None, tabs=0):
result[resp[1]] = resp[2]
msg = self._transaction('')

checked.append(base);
if result:
assert(len(result)==1)
if self.debug: print '\t'*tabs + "Found entry sAMAccountName:", result.values()[0]['sAMAccountName']
Expand All @@ -266,9 +267,10 @@ def check_membership(self, user, groups, base=None, tabs=0):
# Cycle through all the DNs of the groups this user/group belongs to
topgroups = result.values()[0].get('memberOf', {})
for x in topgroups:
if self.check_membership(None,groups,x, tabs+1):
if self.debug: print '\t'*tabs + "sAMAccountName:", result.values()[0]['sAMAccountName'],"yield a match."
return True
if (x not in checked):
if self.check_membership(None,groups,x, tabs+1, checked):
if self.debug: print '\t'*tabs + "sAMAccountName:", result.values()[0]['sAMAccountName'],"yield a match."
return True

if self.debug: print '\t'*tabs + "sAMAccountName:", result.values()[0]['sAMAccountName'],"did not yield any match."
return False