[crans_utils] sanitize ldap
This commit is contained in:
parent
94cacc6bdf
commit
229863f4ba
1 changed files with 19 additions and 0 deletions
|
@ -110,3 +110,22 @@ def validate_name(value, more_chars=""):
|
||||||
else:
|
else:
|
||||||
raise ValueError("Nom invalide ('%s')" % value)
|
raise ValueError("Nom invalide ('%s')" % value)
|
||||||
|
|
||||||
|
def ldap_sanitize(s):
|
||||||
|
""" Échappe les caractères spéciaux ldap.
|
||||||
|
(Si vous avez une méthode plus propre pour coder ça, je suis preneur)
|
||||||
|
Todo: rajouter conversion pour caractère utf-8 multioctets ?
|
||||||
|
(cf http://blog.dzhuvinov.com/?p=585 )
|
||||||
|
"""
|
||||||
|
replace = {
|
||||||
|
'*': '\\2a',
|
||||||
|
'(': '\\28',
|
||||||
|
')': '\\29',
|
||||||
|
'\\': '\\5c',
|
||||||
|
'\x00': '\\00'}
|
||||||
|
def conv(c):
|
||||||
|
try: return replace[c]
|
||||||
|
except KeyError: return c
|
||||||
|
return "".join([conv(c) for c in s])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue