[sysadmin-bin] Minor fixes for py3 migration
- From: Andrea Veri <averi src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Minor fixes for py3 migration
- Date: Thu, 12 Nov 2020 18:40:36 +0000 (UTC)
commit 84afe3932f26a9ec391c6e740c4fbeceb8a6f15f
Author: Andrea Veri <averi redhat com>
Date: Thu Nov 12 19:40:28 2020 +0100
Minor fixes for py3 migration
reset-my-password.py | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/reset-my-password.py b/reset-my-password.py
index 870fc8c..1fac1a0 100755
--- a/reset-my-password.py
+++ b/reset-my-password.py
@@ -12,7 +12,7 @@ exec(open('/home/admin/secret/freeipa_rw_resets').read())
glu = Glu.Gnome_ldap_utils(LDAP_GROUP_BASE, LDAP_HOST, LDAP_USER_BASE, LDAP_USER, LDAP_PASSWORD)
-def gen_passwd(length=12, chars=string.letters + string.digits):
+def gen_passwd(length=12, chars=string.ascii_letters + string.digits):
urandom = open("/dev/urandom")
# ensure even distribution of randomly selected characters
m = 255 - 255 % len(chars)
@@ -22,8 +22,9 @@ def gen_passwd(length=12, chars=string.letters + string.digits):
pwd = ''
while len(pwd) < length:
if pos == len(buf):
- buf = urandom.read(length * 2)
- pos = 0
+ with open("/dev/urandom", 'rb') as fd:
+ buf = repr(fd.read(length * 2))
+ pos = 0
v = ord(buf[pos])
pos += 1
@@ -52,10 +53,10 @@ def check_existing_password(userid):
def update_password(userid):
- getattr_name = glu.get_attributes_from_ldap(userid, 'cn')
- getattr_mail = glu.get_attributes_from_ldap(userid, 'mail')
+ getattr_name = glu.get_attributes_from_ldap(userid, 'cn').decode('utf-8')
+ getattr_mail = glu.get_attributes_from_ldap(userid, 'mail').decode('utf-8')
- newpassword = {'userPassword': gen_passwd()}
+ newpassword = {'userPassword': gen_passwd().encode()}
glu.replace_ldap_password(userid, newpassword['userPassword'])
@@ -74,19 +75,20 @@ toggles a timer (1h) that has to expire before another reset can occur).
With cordiality,
-the GNOME Accounts Team""" % (name, password)
+the GNOME Accounts Team"""
try:
msg = MIMEText(form_letter)
msg['Subject'] = "Your GNOME password has been reset"
msg['From'] = "noreply gnome org"
- msg['To'] = "%s" % (email)
+ msg['To'] = f"{ email }"
msg['Reply-To'] = "accounts gnome org"
server = smtplib.SMTP("localhost")
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
print(f"Successfully sent your password to the registered email address being { email }")
- except smtplib.SMTPException:
+ except smtplib.SMTPException as e:
+ print(e)
print("ERROR: I wasn't able to send the email correctly, please check /var/log/maillog!")
my_userid = os.getenv('SUDO_USER')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]