1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-21 09:34:19 +03:00

samba-tool user: use _glue.crypt, not crypt.crypt

Because we know we have _glue.crypt, and we know it raises exceptions
rather than returning None, we can simplify the checks.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15756

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
Douglas Bagnall 2024-12-11 15:54:48 +13:00 committed by Andreas Schneider
parent 5636d30c09
commit 405187d2ef

View File

@ -37,6 +37,7 @@ from samba.netcmd import Command, CommandError
from samba.samdb import SamDB
from samba.nt_time import timedelta_from_nt_time_delta, nt_time_from_datetime
from samba.gkdi import MAX_CLOCK_SKEW
from samba._glue import crypt
# python[3]-gpgme is abandoned since ubuntu 1804 and debian 9
# have to use python[3]-gpg instead
@ -132,9 +133,7 @@ def get_crypt_value(alg, utf8pw, rounds=0):
else:
crypt_salt = "$%s$%s$" % (alg, b64salt)
crypt_value = crypt.crypt(utf8pw, crypt_salt)
if crypt_value is None:
raise NotImplementedError("crypt.crypt(%s) returned None" % (crypt_salt))
crypt_value = crypt(utf8pw, crypt_salt)
expected_len = len(crypt_salt) + algs[alg]["length"]
if len(crypt_value) != expected_len:
raise NotImplementedError("crypt.crypt(%s) returned a value with length %d, expected length is %d" % (
@ -156,21 +155,13 @@ except ImportError as e:
for (alg, attr) in [("5", "virtualCryptSHA256"), ("6", "virtualCryptSHA512")]:
try:
import crypt
get_crypt_value(alg, "")
virtual_attributes[attr] = {
}
except ImportError as e:
reason = "crypt"
reason += " required"
except (ValueError, OSError):
disabled_virtual_attributes[attr] = {
"reason": reason,
}
except NotImplementedError as e:
reason = "modern '$%s$' salt in crypt(3) required" % (alg)
disabled_virtual_attributes[attr] = {
"reason": reason,
"reason": f"modern '${alg}$' salt in crypt(3) required"
}
continue
virtual_attributes[attr] = {}
# Add the wDigest virtual attributes, virtualWDigest01 to virtualWDigest29
for x in range(1, 30):