summaryrefslogtreecommitdiffstats
path: root/users.py
diff options
context:
space:
mode:
authorChris Lumens <clumens@redhat.com>2009-07-01 13:31:47 -0400
committerChris Lumens <clumens@redhat.com>2009-07-02 09:52:32 -0400
commitac59ddaeaa3f89774ffde2a6abe5db757d94ba45 (patch)
treefa27af935def4dd3c8e355f7e9aae4c0efd72e3a /users.py
parent8b2477c29748728f883b37a3fd62ce9fa43e5d98 (diff)
downloadanaconda-ac59ddaeaa3f89774ffde2a6abe5db757d94ba45.tar.gz
anaconda-ac59ddaeaa3f89774ffde2a6abe5db757d94ba45.tar.xz
anaconda-ac59ddaeaa3f89774ffde2a6abe5db757d94ba45.zip
Allow creating new groups through kickstart.
This is executed before users are created, so new users may be added to the new groups immediately.
Diffstat (limited to 'users.py')
-rw-r--r--users.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/users.py b/users.py
index ec9aa051f..6534a0003 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"):