[PATCH] fix root password setup (#855481)

Brian C. Lane bcl at redhat.com
Sat Sep 8 04:42:31 UTC 2012


From: "Brian C. Lane" <bcl at redhat.com>

libuser checks the LIBUSER_CONF environmental variable and uses the
temporary config file it points to, but in order for this to work it
must be set before User() is run.
---
 pyanaconda/install.py   |  4 ++--
 pyanaconda/kickstart.py |  7 ++++---
 pyanaconda/users.py     | 31 ++++++++++++++++++-------------
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/pyanaconda/install.py b/pyanaconda/install.py
index b5a6152..acd843f 100644
--- a/pyanaconda/install.py
+++ b/pyanaconda/install.py
@@ -24,7 +24,7 @@ from pyanaconda.constants import ROOT_PATH
 from pyanaconda.storage import turnOnFilesystems
 from pyanaconda.bootloader import writeBootLoader
 from pyanaconda.progress import progress_report
-from pyanaconda.users import createLuserConf, Users
+from pyanaconda.users import createLuserConf, getPassAlgo, Users
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
@@ -87,8 +87,8 @@ def doInstall(storage, payload, ksdata, instClass):
     ksdata.timezone.execute(storage, ksdata, instClass)
 
     # Creating users and groups requires some pre-configuration.
+    createLuserConf(ROOT_PATH, algoname=getPassAlgo(ksdata.authconfig.authconfig))
     u = Users()
-    createLuserConf(ROOT_PATH, algoname=u.getPassAlgo(ksdata.authconfig.authconfig))
     ksdata.rootpw.execute(storage, ksdata, instClass, u)
     ksdata.group.execute(storage, ksdata, instClass, u)
     ksdata.user.execute(storage, ksdata, instClass, u)
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 9753941..6a9d780 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -51,6 +51,7 @@ from pyanaconda import keyboard
 from pyanaconda import ntp
 from pyanaconda import timezone
 from pyanaconda.simpleconfig import SimpleConfigFile
+from pyanaconda.users import getPassAlgo
 
 from pykickstart.base import KickstartCommand
 from pykickstart.constants import *
@@ -461,7 +462,7 @@ class Firstboot(commands.firstboot.FC3_Firstboot):
 
 class Group(commands.group.F12_Group):
     def execute(self, storage, ksdata, instClass, users):
-        algo = users.getPassAlgo(ksdata.authconfig.authconfig)
+        algo = getPassAlgo(ksdata.authconfig.authconfig)
 
         for grp in self.groupList:
             kwargs = grp.__dict__
@@ -1215,7 +1216,7 @@ class RaidData(commands.raid.F15_RaidData):
 
 class RootPw(commands.rootpw.F18_RootPw):
     def execute(self, storage, ksdata, instClass, users):
-        algo = users.getPassAlgo(ksdata.authconfig.authconfig)
+        algo = getPassAlgo(ksdata.authconfig.authconfig)
         users.setRootPassword(self.password, self.isCrypted, self.lock, algo)
 
 class SELinux(commands.selinux.FC3_SELinux):
@@ -1270,7 +1271,7 @@ class Timezone(commands.timezone.F18_Timezone):
 
 class User(commands.user.F12_User):
     def execute(self, storage, ksdata, instClass, users):
-        algo = users.getPassAlgo(ksdata.authconfig.authconfig)
+        algo = getPassAlgo(ksdata.authconfig.authconfig)
 
         for usr in self.userList:
             kwargs = usr.__dict__
diff --git a/pyanaconda/users.py b/pyanaconda/users.py
index 6a9e2b9..c10dd4a 100644
--- a/pyanaconda/users.py
+++ b/pyanaconda/users.py
@@ -33,7 +33,11 @@ import logging
 log = logging.getLogger("anaconda")
 
 def createLuserConf(instPath, algoname='sha512'):
-    """Writes a libuser.conf for instPath."""
+    """ Writes a libuser.conf for instPath.
+
+        This must be called before User() is instantiated the first time
+        so that libuser.admin will use the temporary config file.
+    """
     createTmp = False
     try:
         fn = os.environ["LIBUSER_CONF"]
@@ -71,6 +75,19 @@ directory = %(instPath)s/etc
 
     return fn
 
+def getPassAlgo(authconfigStr):
+    """ Reads the auth string and returns a string indicating our desired
+        password encoding algorithm.
+    """
+    if authconfigStr.find("--enablemd5") != -1 or authconfigStr.find("--passalgo=md5") != -1:
+        return 'md5'
+    elif authconfigStr.find("--passalgo=sha256") != -1:
+        return 'sha256'
+    elif authconfigStr.find("--passalgo=sha512") != -1:
+        return 'sha512'
+    else:
+        return None
+
 # These are explained in crypt/crypt-entry.c in glibc's code.  The prefixes
 # we use for the different crypt salts:
 #     $1$    MD5
@@ -269,18 +286,6 @@ class Users:
         else:
             return False
 
-    # Reads the auth string and returns a string indicating our desired
-    # password encoding algorithm.
-    def getPassAlgo(self, authconfigStr):
-        if authconfigStr.find("--enablemd5") != -1 or authconfigStr.find("--passalgo=md5") != -1:
-            return 'md5'
-        elif authconfigStr.find("--passalgo=sha256") != -1:
-            return 'sha256'
-        elif authconfigStr.find("--passalgo=sha512") != -1:
-            return 'sha512'
-        else:
-            return None
-
     def setUserPassword(self, username, password, isCrypted, lock, algo=None):
         user = self.admin.lookupUserByName(username)
 
-- 
1.7.11.4



More information about the anaconda-patches mailing list