]> git.decadent.org.uk Git - dak.git/commitdiff
Consistently use 4-spaces in add_user.py
authorChris Lamb <lamby@debian.org>
Fri, 30 Oct 2009 11:40:23 +0000 (11:40 +0000)
committerChris Lamb <lamby@debian.org>
Fri, 30 Oct 2009 11:40:23 +0000 (11:40 +0000)
Signed-off-by: Chris Lamb <lamby@debian.org>
dak/add_user.py

index 47c14ee6953685188dad265a46162797f7903308..f6fb645ff5d464dd2a04998b2972e0004e50c965 100755 (executable)
@@ -46,28 +46,28 @@ Adds a new user to the dak databases and keyrings
 # Stolen from userdir-ldap
 # Compute a random password using /dev/urandom.
 def GenPass():
-   # Generate a 10 character random string
-   SaltVals = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/."
-   Rand = open("/dev/urandom")
-   Password = ""
-   for i in range(0,15):
-      Password = Password + SaltVals[ord(Rand.read(1)[0]) % len(SaltVals)]
-   return Password
+    # Generate a 10 character random string
+    SaltVals = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/."
+    Rand = open("/dev/urandom")
+    Password = ""
+    for i in range(0,15):
+        Password = Password + SaltVals[ord(Rand.read(1)[0]) % len(SaltVals)]
+    return Password
 
 # Compute the MD5 crypted version of the given password
 def HashPass(Password):
-   import crypt
-   # Hash it telling glibc to use the MD5 algorithm - if you dont have
-   # glibc then just change Salt = "$1$" to Salt = ""
-   SaltVals = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."
-   Salt  = "$1$"
-   Rand = open("/dev/urandom")
-   for x in range(0,10):
-      Salt = Salt + SaltVals[ord(Rand.read(1)[0]) % len(SaltVals)]
-   Pass = crypt.crypt(Password,Salt)
-   if len(Pass) < 14:
-      raise "Password Error", "MD5 password hashing failed, not changing the password!"
-   return Pass
+    import crypt
+    # Hash it telling glibc to use the MD5 algorithm - if you dont have
+    # glibc then just change Salt = "$1$" to Salt = ""
+    SaltVals = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."
+    Salt  = "$1$"
+    Rand = open("/dev/urandom")
+    for x in range(0,10):
+        Salt = Salt + SaltVals[ord(Rand.read(1)[0]) % len(SaltVals)]
+    Pass = crypt.crypt(Password,Salt)
+    if len(Pass) < 14:
+        raise "Password Error", "MD5 password hashing failed, not changing the password!"
+    return Pass
 
 ################################################################################
 
@@ -174,70 +174,69 @@ def main():
     yn = utils.our_raw_input(prompt).lower()
 
     if yn == "y":
-# Create an account for the user?
-          summary = ""
-          if Cnf.FindB("Add-User::CreateAccount") or Cnf["Add-User::Options::Create"]:
-              password = GenPass()
-              pwcrypt = HashPass(password)
-              if Cnf.has_key("Add-User::GID"):
-                  cmd = "sudo /usr/sbin/useradd -g users -m -p '%s' -c '%s' -G %s %s" \
-                         % (pwcrypt, name, Cnf["Add-User::GID"], uid)
-              else:
-                  cmd = "sudo /usr/sbin/useradd -g users -m -p '%s' -c '%s' %s" \
-                         % (pwcrypt, name, uid)
-              (result, output) = commands.getstatusoutput(cmd)
-              if (result != 0):
-                   utils.fubar("Invocation of '%s' failed:\n%s\n" % (cmd, output), result)
-              try:
-                  summary+=createMail(uid, password, Cnf["Add-User::Options::Key"], Cnf["Dinstall::GPGKeyring"])
-              except:
-                  summary=""
-                  utils.warn("Could not prepare password information for mail, not sending password.")
-
-# Now add user to the database.
-          # Note that we provide a session, so we're responsible for committing
-          uidobj = get_or_set_uid(uid, session=session)
-          uid_id = uidobj.uid_id
-          add_database_user(uid)
-          session.commit()
-# The following two are kicked out in rhona, so we don't set them. kelly adds
-# them as soon as she installs a package with unknown ones, so no problems to expect here.
-# Just leave the comment in, to not think about "Why the hell aren't they added" in
-# a year, if we ever touch uma again.
-#          maint_id = database.get_or_set_maintainer_id(name)
-#          session.execute("INSERT INTO fingerprint (fingerprint, uid) VALUES (:fingerprint, uid)",
-#                          {'fingerprint': primary_key, 'uid': uid_id})
-
-# Lets add user to the email-whitelist file if its configured.
-          if Cnf.has_key("Dinstall::MailWhiteList") and Cnf["Dinstall::MailWhiteList"] != "":
-              file = utils.open_file(Cnf["Dinstall::MailWhiteList"], "a")
-              for mail in emails:
-                  file.write(mail+'\n')
-              file.close()
-
-          print "Added:\nUid:\t %s (ID: %s)\nMaint:\t %s\nFP:\t %s" % (uid, uid_id, \
+        # Create an account for the user?
+        summary = ""
+        if Cnf.FindB("Add-User::CreateAccount") or Cnf["Add-User::Options::Create"]:
+            password = GenPass()
+            pwcrypt = HashPass(password)
+            if Cnf.has_key("Add-User::GID"):
+                cmd = "sudo /usr/sbin/useradd -g users -m -p '%s' -c '%s' -G %s %s" \
+                       % (pwcrypt, name, Cnf["Add-User::GID"], uid)
+            else:
+                cmd = "sudo /usr/sbin/useradd -g users -m -p '%s' -c '%s' %s" \
+                       % (pwcrypt, name, uid)
+            (result, output) = commands.getstatusoutput(cmd)
+            if (result != 0):
+                utils.fubar("Invocation of '%s' failed:\n%s\n" % (cmd, output), result)
+            try:
+                summary+=createMail(uid, password, Cnf["Add-User::Options::Key"], Cnf["Dinstall::GPGKeyring"])
+            except:
+                summary=""
+                utils.warn("Could not prepare password information for mail, not sending password.")
+
+        # Now add user to the database.
+        # Note that we provide a session, so we're responsible for committing
+        uidobj = get_or_set_uid(uid, session=session)
+        uid_id = uidobj.uid_id
+        add_database_user(uid)
+        session.commit()
+
+        # The following two are kicked out in rhona, so we don't set them. kelly adds
+        # them as soon as she installs a package with unknown ones, so no problems to expect here.
+        # Just leave the comment in, to not think about "Why the hell aren't they added" in
+        # a year, if we ever touch uma again.
+        #          maint_id = database.get_or_set_maintainer_id(name)
+        #          session.execute("INSERT INTO fingerprint (fingerprint, uid) VALUES (:fingerprint, uid)",
+        #                          {'fingerprint': primary_key, 'uid': uid_id})
+
+        # Lets add user to the email-whitelist file if its configured.
+        if Cnf.has_key("Dinstall::MailWhiteList") and Cnf["Dinstall::MailWhiteList"] != "":
+            file = utils.open_file(Cnf["Dinstall::MailWhiteList"], "a")
+            for mail in emails:
+                file.write(mail+'\n')
+            file.close()
+
+        print "Added:\nUid:\t %s (ID: %s)\nMaint:\t %s\nFP:\t %s" % (uid, uid_id, \
                      name, primary_key)
 
-# Should we send mail to the newly added user?
-          if Cnf.FindB("Add-User::SendEmail"):
-              mail = name + "<" + emails[0] +">"
-              Subst = {}
-              Subst["__NEW_MAINTAINER__"] = mail
-              Subst["__UID__"] = uid
-              Subst["__KEYID__"] = Cnf["Add-User::Options::Key"]
-              Subst["__PRIMARY_KEY__"] = primary_key
-              Subst["__FROM_ADDRESS__"] = Cnf["Dinstall::MyEmailAddress"]
-              Subst["__HOSTNAME__"] = Cnf["Dinstall::MyHost"]
-              Subst["__SUMMARY__"] = summary
-              new_add_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/add-user.added")
-              utils.send_mail(new_add_message)
+        # Should we send mail to the newly added user?
+        if Cnf.FindB("Add-User::SendEmail"):
+            mail = name + "<" + emails[0] +">"
+            Subst = {}
+            Subst["__NEW_MAINTAINER__"] = mail
+            Subst["__UID__"] = uid
+            Subst["__KEYID__"] = Cnf["Add-User::Options::Key"]
+            Subst["__PRIMARY_KEY__"] = primary_key
+            Subst["__FROM_ADDRESS__"] = Cnf["Dinstall::MyEmailAddress"]
+            Subst["__HOSTNAME__"] = Cnf["Dinstall::MyHost"]
+            Subst["__SUMMARY__"] = summary
+            new_add_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/add-user.added")
+            utils.send_mail(new_add_message)
 
     else:
-          uid = None
-
+        uid = None
 
 #######################################################################################
 
 if __name__ == '__main__':
     main()
-