mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
samdb: use int for get and set methods instead of digit str
This will make the API work in a nature way. Also, because of a defect in ldb API, code like `res[0]["maxPwdAge"][0]` will return bytes even in Python3, which will cause trouble. By casting the value to int, we avoid the str/bytes issue. Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
f3358f048d
commit
9b164637f0
@ -57,14 +57,14 @@ class inf_to_ldb(gp_ext_setter):
|
||||
old_val = self.ldb.get_minPwdAge()
|
||||
self.logger.info('KDC Minimum Password age was changed from %s to %s' \
|
||||
% (old_val, val))
|
||||
self.gp_db.store(str(self), self.attribute, old_val)
|
||||
self.gp_db.store(str(self), self.attribute, str(old_val))
|
||||
self.ldb.set_minPwdAge(val)
|
||||
|
||||
def ch_maxPwdAge(self, val):
|
||||
old_val = self.ldb.get_maxPwdAge()
|
||||
self.logger.info('KDC Maximum Password age was changed from %s to %s' \
|
||||
% (old_val, val))
|
||||
self.gp_db.store(str(self), self.attribute, old_val)
|
||||
self.gp_db.store(str(self), self.attribute, str(old_val))
|
||||
self.ldb.set_maxPwdAge(val)
|
||||
|
||||
def ch_minPwdLength(self, val):
|
||||
@ -72,14 +72,14 @@ class inf_to_ldb(gp_ext_setter):
|
||||
self.logger.info(
|
||||
'KDC Minimum Password length was changed from %s to %s' \
|
||||
% (old_val, val))
|
||||
self.gp_db.store(str(self), self.attribute, old_val)
|
||||
self.gp_db.store(str(self), self.attribute, str(old_val))
|
||||
self.ldb.set_minPwdLength(val)
|
||||
|
||||
def ch_pwdProperties(self, val):
|
||||
old_val = self.ldb.get_pwdProperties()
|
||||
self.logger.info('KDC Password Properties were changed from %s to %s' \
|
||||
% (old_val, val))
|
||||
self.gp_db.store(str(self), self.attribute, old_val)
|
||||
self.gp_db.store(str(self), self.attribute, str(old_val))
|
||||
self.ldb.set_pwdProperties(val)
|
||||
|
||||
def days2rel_nttime(self):
|
||||
|
@ -917,6 +917,7 @@ schemaUpdateNow: 1
|
||||
return dn
|
||||
|
||||
def set_minPwdAge(self, value):
|
||||
value = str(value).encode('utf8')
|
||||
m = ldb.Message()
|
||||
m.dn = ldb.Dn(self, self.domain_dn())
|
||||
m["minPwdAge"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "minPwdAge")
|
||||
@ -929,9 +930,10 @@ schemaUpdateNow: 1
|
||||
elif not "minPwdAge" in res[0]:
|
||||
return None
|
||||
else:
|
||||
return res[0]["minPwdAge"][0]
|
||||
return int(res[0]["minPwdAge"][0])
|
||||
|
||||
def set_maxPwdAge(self, value):
|
||||
value = str(value).encode('utf8')
|
||||
m = ldb.Message()
|
||||
m.dn = ldb.Dn(self, self.domain_dn())
|
||||
m["maxPwdAge"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "maxPwdAge")
|
||||
@ -945,11 +947,12 @@ schemaUpdateNow: 1
|
||||
elif not "maxPwdAge" in res[0]:
|
||||
return None
|
||||
else:
|
||||
return res[0]["maxPwdAge"][0]
|
||||
return int(res[0]["maxPwdAge"][0])
|
||||
|
||||
|
||||
|
||||
def set_minPwdLength(self, value):
|
||||
value = str(value).encode('utf8')
|
||||
m = ldb.Message()
|
||||
m.dn = ldb.Dn(self, self.domain_dn())
|
||||
m["minPwdLength"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "minPwdLength")
|
||||
@ -962,9 +965,10 @@ schemaUpdateNow: 1
|
||||
elif not "minPwdLength" in res[0]:
|
||||
return None
|
||||
else:
|
||||
return res[0]["minPwdLength"][0]
|
||||
return int(res[0]["minPwdLength"][0])
|
||||
|
||||
def set_pwdProperties(self, value):
|
||||
value = str(value).encode('utf8')
|
||||
m = ldb.Message()
|
||||
m.dn = ldb.Dn(self, self.domain_dn())
|
||||
m["pwdProperties"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "pwdProperties")
|
||||
@ -977,7 +981,7 @@ schemaUpdateNow: 1
|
||||
elif not "pwdProperties" in res[0]:
|
||||
return None
|
||||
else:
|
||||
return res[0]["pwdProperties"][0]
|
||||
return int(res[0]["pwdProperties"][0])
|
||||
|
||||
def set_dsheuristics(self, dsheuristics):
|
||||
m = ldb.Message()
|
||||
|
@ -427,7 +427,7 @@ class PwdSettingsCmdTestCase(SambaToolCmdTest):
|
||||
self.assertCmdSuccess(result, out, err)
|
||||
self.assertEquals(err,"","Shouldn't be any error messages")
|
||||
self.assertIn("successful", out)
|
||||
self.assertEquals(str(new_len), self.ldb.get_minPwdLength())
|
||||
self.assertEquals(new_len, self.ldb.get_minPwdLength())
|
||||
|
||||
# check the updated value is now displayed
|
||||
(result, out, err) = self.runsublevelcmd("domain", ("passwordsettings",
|
||||
|
Loading…
Reference in New Issue
Block a user