From 322b2f423f3c6a1d81aa611d7b74b401cce388b0 Mon Sep 17 00:00:00 2001 From: William Brown Date: Wed, 15 Nov 2017 15:41:06 +1000 Subject: [PATCH 2/2] Ticket 49453 - passwd.py to use pwdhash defaults. Bug Description: pwdhash now uses the defaults from libslapd, so we do not need to code this into passwd.py Fix Description: Change the default args for passwd.py to simplify the call. https://pagure.io/389-ds-base/issue/49453 Author: wibrown Review by: ??? --- src/lib389/lib389/passwd.py | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/lib389/lib389/passwd.py b/src/lib389/lib389/passwd.py index f36d73e..e422735 100644 --- a/src/lib389/lib389/passwd.py +++ b/src/lib389/lib389/passwd.py @@ -15,37 +15,20 @@ import subprocess import random import string import os -import sys - -BESTSCHEME = 'SSHA512' -MAJOR, MINOR, _, _, _ = sys.version_info - -# We need a dict of the schemes I think .... -PWSCHEMES = [ - 'SHA1', - 'SHA256', - 'SHA512', - 'SSHA', - 'SSHA256', - 'SSHA512', -] - # How do we feed our prefix into this? -def password_hash(pw, scheme=BESTSCHEME, bin_dir='/bin'): +def password_hash(pw, scheme=None, bin_dir='/bin'): # Check that the binary exists - assert(scheme in PWSCHEMES) pwdhashbin = os.path.join(bin_dir, 'pwdhash') assert(os.path.isfile(pwdhashbin)) - h = subprocess.check_output([pwdhashbin, '-s', scheme, pw]).strip() + if scheme is None: + h = subprocess.check_output([pwdhashbin, pw]).strip() + else: + h = subprocess.check_output([pwdhashbin, '-s', scheme, pw]).strip() return h.decode('utf-8') def password_generate(length=64): - pw = None - if MAJOR >= 3: - pw = [random.choice(string.ascii_letters) for x in range(length - 1)] - else: - pw = [random.choice(string.letters) for x in xrange(length - 1)] + pw = [random.choice(string.ascii_letters) for x in range(length - 1)] pw.append('%s' % random.randint(0, 9)) return "".join(pw) -- 1.8.3.1