LdapServer.update_object(): add relax parameter
This commit is contained in:
parent
45a0b99687
commit
aa2e1ee99f
1 changed files with 8 additions and 2 deletions
|
@ -8,6 +8,7 @@ import dateutil.parser
|
||||||
import dateutil.tz
|
import dateutil.tz
|
||||||
import ldap
|
import ldap
|
||||||
from ldap.controls import SimplePagedResultsControl
|
from ldap.controls import SimplePagedResultsControl
|
||||||
|
from ldap.controls.simple import RelaxRulesControl
|
||||||
import ldap.modlist as modlist
|
import ldap.modlist as modlist
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
|
@ -91,6 +92,7 @@ class LdapServer(object): # pylint: disable=useless-object-inheritance
|
||||||
return result[dn] if dn in result else None
|
return result[dn] if dn in result else None
|
||||||
|
|
||||||
def paged_search(self, basedn, filterstr, attrs, scope='sub', pagesize=500):
|
def paged_search(self, basedn, filterstr, attrs, scope='sub', pagesize=500):
|
||||||
|
assert not self.v2, "Paged search is not available on LDAP version 2"
|
||||||
# Initialize SimplePagedResultsControl object
|
# Initialize SimplePagedResultsControl object
|
||||||
page_control = SimplePagedResultsControl(
|
page_control = SimplePagedResultsControl(
|
||||||
True,
|
True,
|
||||||
|
@ -170,7 +172,8 @@ class LdapServer(object): # pylint: disable=useless-object-inheritance
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def update_object(self, dn, old, new, ignore_attrs=None):
|
def update_object(self, dn, old, new, ignore_attrs=None, relax=False):
|
||||||
|
assert not relax or not self.v2, "Relax modification is not available on LDAP version 2"
|
||||||
ldif = modlist.modifyModlist(
|
ldif = modlist.modifyModlist(
|
||||||
old, new,
|
old, new,
|
||||||
ignore_attr_types=ignore_attrs if ignore_attrs else []
|
ignore_attr_types=ignore_attrs if ignore_attrs else []
|
||||||
|
@ -178,6 +181,9 @@ class LdapServer(object): # pylint: disable=useless-object-inheritance
|
||||||
if ldif == []:
|
if ldif == []:
|
||||||
return True
|
return True
|
||||||
try:
|
try:
|
||||||
|
if relax:
|
||||||
|
self.con.modify_ext_s(dn, ldif, serverctrls=[RelaxRulesControl()])
|
||||||
|
else:
|
||||||
self.con.modify_s(dn, ldif)
|
self.con.modify_s(dn, ldif)
|
||||||
return True
|
return True
|
||||||
except ldap.LDAPError as e: # pylint: disable=no-member
|
except ldap.LDAPError as e: # pylint: disable=no-member
|
||||||
|
|
Loading…
Reference in a new issue