summaryrefslogtreecommitdiff
path: root/python/samba/netcmd
diff options
context:
space:
mode:
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>2024-02-02 15:01:21 +1300
committerAndrew Bartlett <abartlet@samba.org>2024-06-11 05:32:28 +0000
commitdb342d86a9ccd15f764cb8e0a91774e1f8fd7858 (patch)
tree9eb030d81159d715ddd5813c54fe3dabcd34b40a /python/samba/netcmd
parentb42c489180474627270e09408f84841baa175157 (diff)
downloadsamba-db342d86a9ccd15f764cb8e0a91774e1f8fd7858.tar.gz
samba-db342d86a9ccd15f764cb8e0a91774e1f8fd7858.tar.bz2
samba-db342d86a9ccd15f764cb8e0a91774e1f8fd7858.zip
samba-tool user readpasswords: avoid `assert` for validation
`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
Diffstat (limited to 'python/samba/netcmd')
-rw-r--r--python/samba/netcmd/user/readpasswords/common.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/python/samba/netcmd/user/readpasswords/common.py b/python/samba/netcmd/user/readpasswords/common.py
index 0aa1f237dc0..7944d4e1682 100644
--- a/python/samba/netcmd/user/readpasswords/common.py
+++ b/python/samba/netcmd/user/readpasswords/common.py
@@ -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