diff options
author | Chris Lumens <clumens@redhat.com> | 2006-05-03 17:44:54 +0000 |
---|---|---|
committer | Chris Lumens <clumens@redhat.com> | 2006-05-03 17:44:54 +0000 |
commit | 422211b0bac84edd23bdff5e79a8011937372d00 (patch) | |
tree | 707646a0cbbb5e42a7b97213e138d9c0653a0b65 | |
parent | e6e28b69681a4d5451119795923538808afa2e9d (diff) | |
download | anaconda-422211b0bac84edd23bdff5e79a8011937372d00.tar.gz anaconda-422211b0bac84edd23bdff5e79a8011937372d00.tar.xz anaconda-422211b0bac84edd23bdff5e79a8011937372d00.zip |
Add support for making users and for enabling/disabling services via
kickstart.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | backend.py | 20 | ||||
-rw-r--r-- | instdata.py | 38 | ||||
-rw-r--r-- | kickstart.py | 8 | ||||
-rw-r--r-- | users.py | 86 |
5 files changed, 135 insertions, 27 deletions
@@ -1,3 +1,13 @@ +2006-05-03 Chris Lumens <clumens@redhat.com> + + * backend.py (AnacondaBackend.doPostInstall): Enable/disable services + and create users after installation. + * instdata.py: Remove password-related code. + * kickcstart.py (AnacondaKSHandlers.doServices, + AnacondaKSHandlers.doUser): Add new command handlers. + * users.py: Added back in code to create users, since kickstart can + do this now. + 2006-05-03 Jeremy Katz <katzj@redhat.com> * isys/isys.c: Don't include kernel fs headers -- the e2fsprogs diff --git a/backend.py b/backend.py index 77344e2c0..912e21409 100644 --- a/backend.py +++ b/backend.py @@ -51,6 +51,26 @@ class AnacondaBackend: if flags.setupFilesystems: syslog.stop() + if id.partitions.isKickstart: + for svc in id.ksdata.services["disabled"]: + iutil.execWithRedirect("/sbin/chkconfig", + ["/sbin/chkconfig", svc, "off"], + stdout="/dev/tty5", stderr="/dev/tty5", + root="/mnt/sysimage") + + for svc in id.ksdata.services["enabled"]: + iutil.execWithRedirect("/sbin/chkconfig", + ["/sbin/chkconfig", svc, "on"], + stdout="/dev/tty5", stderr="/dev/tty5", + root="/mnt/sysimage") + + for ud in id.ksdata.userList: + if id.users.createUser(ud.name, ud.password, ud.isCrypted, + ud.groups, ud.homedir, ud.shell, + ud.uid) == None: + log.error("User %s already exists, not creating." % ud.name) + + def doInstall(self, intf, id, instPath): pass diff --git a/instdata.py b/instdata.py index b33c0e533..4e94eaae8 100644 --- a/instdata.py +++ b/instdata.py @@ -29,7 +29,7 @@ import iscsi import zfcp import urllib import iutil -import libuser +import users from flags import * from constants import * @@ -39,23 +39,6 @@ import rhpl.keyboard as keyboard import logging log = logging.getLogger("anaconda") -def cryptPassword(password, useMD5): - import crypt - import random - - if useMD5: - salt = "$1$" - saltLen = 8 - else: - salt = "" - saltLen = 2 - - for i in range(saltLen): - salt = salt + random.choice (string.letters + - string.digits + './') - - return crypt.crypt (password, salt) - # Collector class for all data related to an install/upgrade. class InstallData: @@ -74,6 +57,7 @@ class InstallData: self.firewall = firewall.Firewall() self.security = security.Security() self.timezone = timezone.Timezone() + self.users = users.Users() self.rootPassword = { "isCrypted": False, "password": "" } self.auth = "--enableshadow --enablemd5" self.desktop = desktop.Desktop() @@ -92,6 +76,9 @@ class InstallData: self.upgradeRemove = [] self.upgradeInfoFound = None self.firstboot = FIRSTBOOT_DEFAULT + # XXX I expect this to die in the future when we have a single data + # class and translate ksdata into that instead. + self.ksdata = None def setInstallProgressClass(self, c): self.instProgress = c @@ -123,6 +110,9 @@ class InstallData: def setHeadless(self, isHeadless): self.isHeadless = isHeadless + def setKsdata(self, ksdata): + self.ksdata = ksdata + # if upgrade is None, it really means False. we use None to help the # installer ui figure out if it's the first time the user has entered # the examine_gui screen. --dcantrell @@ -151,7 +141,7 @@ class InstallData: args = ["/usr/bin/authconfig", "--update", "--nostart"] + self.auth.split() try: - if not flags.test: + if flags.setupFilesystems: iutil.execWithRedirect("/usr/bin/authconfig", args, stdout = None, stderr = None, searchPath = 1, root = instPath) @@ -164,15 +154,9 @@ class InstallData: self.security.write (instPath) # User should already exist, just without a password. - self.luAdmin = libuser.admin() - rootUser = self.luAdmin.lookupUserByName("root") + self.users.setRootPassword(self.rootPassword["password"], + self.rootPassword["isCrypted"], useMD5) - if self.rootPassword["isCrypted"]: - self.luAdmin.setpassUser(rootUser, self.rootPassword["password"], True) - self.luAdmin.modifyUser(rootUser) - else: - self.luAdmin.setpassUser(rootUser, cryptPassword(self.rootPassword["password"], useMD5), True) - self.luAdmin.modifyUser(rootUser) def writeKS(self, filename): if self.auth.find("--enablemd5"): diff --git a/kickstart.py b/kickstart.py index ac8090618..f0a48020d 100644 --- a/kickstart.py +++ b/kickstart.py @@ -524,6 +524,9 @@ class AnacondaKSHandlers(KickstartHandlers): KickstartHandlers.doSELinux(self, args) id.instClass.setSELinux(id, self.ksdata.selinux) + def doServices(self, id, args): + KickstartHandlers.doServices(self, args) + def doSkipX(self, id, args): KickstartHandlers.doSkipX(self, args) self.skipSteps.extend(["checkmonitorok", "setsanex", "videocard", @@ -544,6 +547,9 @@ class AnacondaKSHandlers(KickstartHandlers): KickstartHandlers.doUpgrade(self, args) id.setUpgrade(True) + def doUser(self, id, args): + KickstartHandlers.doUser(self, args) + def doVnc(self, id, args): KickstartHandlers.doVnc(self, args) @@ -811,6 +817,8 @@ class Kickstart(BaseInstallClass): else: raise KickstartError, e + self.id.setKsdata(self.ksdata) + def _havePackages(self): return len(self.ksdata.groupList) > 0 or len(self.ksdata.packageList) > 0 or \ len(self.ksdata.excludedList) > 0 diff --git a/users.py b/users.py new file mode 100644 index 000000000..05c59257a --- /dev/null +++ b/users.py @@ -0,0 +1,86 @@ +# +# users.py: Code for creating user accounts and setting the root password +# +# Chris Lumens <clumens@redhat.com> +# +# Copyright (c) 2006 Red Hat, Inc. +# +# This software may be freely redistributed under the terms of the GNU +# general public license. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +import libuser +import string +import crypt +import random + +def cryptPassword(password, useMD5): + if useMD5: + salt = "$1$" + saltLen = 8 + else: + salt = "" + saltLen = 2 + + for i in range(saltLen): + salt = salt + random.choice (string.letters + + string.digits + './') + + return crypt.crypt (password, salt) + +class Users: + def __init__ (self): + self.admin = libuser.admin() + + def createUser (self, name, password=None, isCrypted=False, groups=[], + homedir=None, shell=None, uid=None): + if self.admin.lookupUserByName(name): + return None + + userEnt = self.admin.initUser(name) + groupEnt = self.admin.initGroup(name) + + gidLst = map(lambda grp: grp.get(libuser.GIDNUMBER)[0], + filter(lambda grp: grp, + map(lambda name: self.admin.lookupGroupByName(name), groups))) + gidLst.extend(groupEnt.get(libuser.GIDNUMBER)) + + userEnt.set(libuser.GIDNUMBER, gidLst) + + if not homedir: + homedir = "/home/" + name + + # Do this to make the user's home dir under the install root. + userEnt.set(libuser.HOMEDIRECTORY, "/mnt/sysimage/" + homedir) + + if shell: + userEnt.set(libuser.LOGINSHELL, shell) + + if uid >= 0: + userEnt.set(libuser.UIDNUMBER, uid) + + self.admin.addUser(userEnt) + self.admin.addGroup(groupEnt) + + if password: + if isCrypted: + self.admin.setpassUser(userEnt, password, isCrypted) + else: + self.admin.setpassUser(userEnt, cryptPassword(password, True), isCrypted) + + # Now set the correct home directory to fix up passwd. + userEnt.set(libuser.HOMEDIRECTORY, homedir) + self.admin.modifyUser(userEnt) + + def setRootPassword(self, password, isCrypted, useMD5): + rootUser = self.admin.lookupUserByName("root") + + if isCrypted: + self.admin.setpassUser(rootUser, password, True) + else: + self.admin.setpassUser(rootUser, cryptPassword(password, useMD5), True) + + self.admin.modifyUser(rootUser) |