]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool user readpasswords: avoid `assert` for validation
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 2 Feb 2024 02:01:21 +0000 (15:01 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 11 Jun 2024 05:32:28 +0000 (05:32 +0000)
`assert` can be optimised away if python is run with `-O`.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue Jun 11 05:32:28 UTC 2024 on atb-devel-224

python/samba/netcmd/user/readpasswords/common.py

index 0aa1f237dc0a7362837bfb22c76428c4d8063675..7944d4e1682b94746762983305eaf92795146933 100644 (file)
@@ -114,7 +114,10 @@ def get_crypt_value(alg, utf8pw, rounds=0):
         "5": {"length": 43},
         "6": {"length": 86},
     }
-    assert alg in algs
+    if alg not in algs:
+        raise ValueError(f"invalid algorithm code: {alg}"
+                         f"(expected one of {','.join(algs.keys())})")
+
     salt = os.urandom(16)
     # The salt needs to be in [A-Za-z0-9./]
     # base64 is close enough and as we had 16