From 405187d2ef4920a9a284649c9c3287f5844d5180 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Wed, 11 Dec 2024 15:54:48 +1300 Subject: [PATCH] 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 Reviewed-by: Andreas Schneider --- .../samba/netcmd/user/readpasswords/common.py | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/python/samba/netcmd/user/readpasswords/common.py b/python/samba/netcmd/user/readpasswords/common.py index 1bf29fe3eca..0e68d042a55 100644 --- a/python/samba/netcmd/user/readpasswords/common.py +++ b/python/samba/netcmd/user/readpasswords/common.py @@ -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):