Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow wildcards for passthrough #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
11 changes: 10 additions & 1 deletion pi_ldapproxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import re
import urllib
import fnmatch
from io import BytesIO
from functools import partial

Expand Down Expand Up @@ -272,7 +273,7 @@ def handleBeforeForwardRequest(self, request, controls, reply):
elif self.factory.is_dn_blacklisted(request.dn):
self.send_bind_response((False, 'DN is blacklisted.'), request, reply)
return None
elif request.dn in self.factory.passthrough_binds:
elif self.factory.is_passthrough_dn(request.dn):
log.info('BindRequest for {dn!r}, passing through ...', dn=request.dn)
self.forwarded_passthrough_bind = True
return request, controls
Expand Down Expand Up @@ -463,6 +464,14 @@ def is_dn_blacklisted(self, dn):
"""
return any(pattern.match(dn) for pattern in DN_BLACKLIST)

def is_passthrough_dn(self, dn):
"""
Check whether the given distinguished name is part of our passthrough-binds setting
:param dn: Distinguished Name as string
:return: a boolean
"""
return any(fnmatch.fnmatch(dn, pattern) for pattern in self.passthrough_binds)

def buildProtocol(self, addr):
"""
called by Twisted for each new incoming connection.
Expand Down