Re: [PATCH] Allow creating new groups through kickstart.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Looks ok to me,

Regards,

Hans


On 07/01/2009 07:34 PM, Chris Lumens wrote:
This is executed before users are created, so new users may be added to
the new groups immediately.
---
  instdata.py  |    6 ++++++
  kickstart.py |    1 +
  users.py     |   35 +++++++++++++++++++++++++++++++++++
  3 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/instdata.py b/instdata.py
index 07984d5..7e44177 100644
--- a/instdata.py
+++ b/instdata.py
@@ -182,6 +182,12 @@ class InstallData:
                                         stdout="/dev/tty5", stderr="/dev/tty5",
                                         root=self.anaconda.rootPath)

+            for gd in self.ksdata.group.groupList:
+                if not self.users.createGroup(name=gd.name,
+                                              gid=gd.gid,
+                                              root=self.anaconda.rootPath):
+                    log.error("Group %s already exists, not creating." % gd.name)
+
              for ud in self.ksdata.user.userList:
                  if not self.users.createUser(name=ud.name,
                                               password=ud.password,
diff --git a/kickstart.py b/kickstart.py
index ce99855..5147fa5 100644
--- a/kickstart.py
+++ b/kickstart.py
@@ -985,6 +985,7 @@ commandMap = {
          "firewall": Firewall,
          "firstboot": Firstboot,
          "graphical": commands.displaymode.FC3_DisplayMode,
+        "group": commands.group.F12_Group,
          "halt": Reboot,
          "harddrive": commands.method.FC6_Method,
          "ignoredisk": IgnoreDisk,
diff --git a/users.py b/users.py
index ec9aa05..6534a00 100644
--- a/users.py
+++ b/users.py
@@ -84,6 +84,41 @@ class Users:
      def __init__ (self):
          self.admin = libuser.admin()

+    def createGroup (self, name=None, gid=None, root="/mnt/sysimage"):
+        childpid = os.fork()
+
+        if not childpid:
+            os.chroot(root)
+
+            del(os.environ["LIBUSER_CONF"])
+            self.admin = libuser.admin()
+
+            try:
+                if self.admin.lookupGroupByName(name):
+                    os._exit(1)
+
+                groupEnt = self.admin.initGroup(name)
+
+                if gid>= 0:
+                    groupEnt.set(libuser.GIDNUMBER, gid)
+
+                self.admin.addGroup(groupEnt)
+                os._exit(0)
+            except Exception, e:
+                log.critical("Error when creating new group: %s" % str(e))
+                os._exit(1)
+
+        try:
+            (pid, status) = os.waitpid(childpid, 0)
+        except OSError as e:
+            log.critical("exception from waitpid while creating a group: %s %s" % (e.errno, e.strerror))
+            return False
+
+        if os.WIFEXITED(status) and (os.WEXITSTATUS(status) == 0):
+            return True
+        else:
+            return False
+
      def createUser (self, name=None, password=None, isCrypted=False, groups=[],
                      homedir=None, shell=None, uid=None, algo=None, lock=False,
                      root="/mnt/sysimage"):

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux