Skip to content

Commit

Permalink
Fix special chars filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvanes committed Nov 10, 2023
1 parent a804115 commit 59eab28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plsc_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def create(src, dst):
admin_dn = 'cn=admin,' + service_dn

# find existing services
service_dns = dst.find(dst.basedn, f"(&(objectClass=dcObject)(dc={service}))")
service_dns = dst.find(dst.basedn, f"(&(objectClass=dcObject)(dc={util.escape_filter_chars(service)}))")

# Pivotal 106: If Service does not (yet) exists in LDAP and is not enable for LDAP
# in SBS, do not create it at all. If it does exists in LDAP, that means that
Expand Down
21 changes: 11 additions & 10 deletions util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
import ldap

SPECIAL_DN_CHARACTERS = "\\,+<>;\"= "
SPECIAL_FILTER_CHARACTERS = "\\*()"


def make_secret(password):
import passlib.hash
Expand All @@ -9,16 +12,14 @@ def make_secret(password):


def unescape_dn_chars(s):
s = s.replace(r'\5C', '\\')
s = s.replace(r'\2C', r',')
s = s.replace(r'\23', r'#')
s = s.replace(r'\2B', r'+')
s = s.replace(r'\3C', r'<')
s = s.replace(r'\3E', r'>')
s = s.replace(r'\3B', r';')
s = s.replace(r'\22', r'"')
s = s.replace(r'\3D', r'=')
s = s.replace(r'\00', '\x00')
for c in SPECIAL_DN_CHARACTERS:
s = s.replace("\\" + hex(ord(c))[2:].upper(), c)
return s


def escape_filter_chars(s):
for c in SPECIAL_FILTER_CHARACTERS:
s = s.replace(c, "\\" + hex(ord(c))[2:].upper())
return s


Expand Down

0 comments on commit 59eab28

Please sign in to comment.