1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-20 22:50:26 +03:00

samdb: add prepare_attr_replace() method

Add a method to prepare a given Message to replace the given attribute.
If the given new value is None or the old value and the new value are
the same, do nothing.
If the new value is empty, prepare to replace the given attribute with
[].
Else prepare to replace the given attribute with the new value.

Use this for samdb.modify(msg).

Signed-off-by: Jule Anger <ja@sernet.de>
Reviewed-by: Björn Baumbach <bb@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
Jule Anger 2020-08-24 16:34:35 +02:00 committed by Douglas Bagnall
parent 88663eb949
commit a22a80ed6e

View File

@ -392,6 +392,29 @@ member: %s
else:
self.transaction_commit()
def prepare_attr_replace(self, msg, old, attr_name, value):
"""Changes the MessageElement with the given attr_name of the
given Message. If the value is "" set an empty value and the flag
FLAG_MOD_DELETE, otherwise set the new value and FLAG_MOD_REPLACE.
If the value is None or the Message contains the attr_name with this
value, nothing will changed."""
# skip unchanged attribute
if value is None:
return
if attr_name in old and str(value) == str(old[attr_name]):
return
# remove attribute
if len(value) == 0:
if attr_name in old:
el = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, attr_name)
msg.add(el)
return
# change attribute
el = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, attr_name)
msg.add(el)
def newuser(self, username, password,
force_password_change_at_next_login_req=False,
useusernameascn=False, userou=None, surname=None, givenname=None,