[elbe-devel] [PATCH 3/4] finetuning: add options to adduser and addgroup
Torben Hohn
torben.hohn at linutronix.de
Thu Apr 26 17:01:48 CEST 2018
add gid="" and system="True" options to finetuning add_group
also add uid, gid, home, systems="True", create_home="False" and
create_group="False" to adduser.
rework the generation of the options a bit, so that it handles many
options more elegantly.
add the new options to dbsfed.xsd.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
elbepack/finetuning.py | 58 ++++++++++++++++++++++++++++++++++++--------------
schema/dbsfed.xsd | 44 ++++++++++++++++++++++++++++++++------
2 files changed, 80 insertions(+), 22 deletions(-)
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index eba35068..069d22f8 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -262,23 +262,41 @@ class AddUserAction(FinetuningAction):
def execute(self, log, buildenv, target):
with target:
- if 'groups' in self.node.et.attrib:
- log.chroot(
- target.path,
- '/usr/sbin/useradd -U -m -G "%s" -s "%s" "%s"' %
- (self.node.et.attrib['groups'],
- self.node.et.attrib['shell'],
- self.node.et.text))
+ att = self.node.et.attrib
+ options = ""
+ if 'groups' in att:
+ options += '-G "%s" ' % att['groups']
+ if 'shell' in att:
+ options += '-s "%s" ' % att['shell']
+ if 'uid' in att:
+ options += '-u "%s" ' % att['uid']
+ if 'gid' in att:
+ options += '-g "%s" ' % att['gid']
+ if 'home' in att:
+ options += '-d "%s" ' % att['home']
+ if 'system' in att and att['system'] == 'True':
+ options += '-r'
+ if 'create_home' in att and att['create_home'] == 'False':
+ options += '-M '
else:
- log.chroot(
- target.path, '/usr/sbin/useradd -U -m -s "%s" "%s"' %
- (self.node.et.attrib['shell'], self.node.et.text))
+ options += '-m '
+ if 'create_group' in att and att['create_group'] == 'False':
+ options += '-N '
+ else:
+ options += '-U '
+
+ log.chroot(
+ target.path,
+ '/usr/sbin/useradd %s "%s"' %
+ (options,
+ self.node.et.text))
- log.chroot(target.path,
- """/bin/sh -c 'echo "%s\\n%s\\n" | passwd %s'""" % (
- self.node.et.attrib['passwd'],
- self.node.et.attrib['passwd'],
- self.node.et.text))
+ if 'passwd' in att:
+ log.chroot(target.path,
+ """/bin/sh -c 'echo "%s\\n%s\\n" | passwd %s'""" % (
+ att['passwd'],
+ att['passwd'],
+ self.node.et.text))
FinetuningAction.register(AddUserAction)
@@ -293,7 +311,15 @@ class AddGroupAction(FinetuningAction):
def execute(self, log, buildenv, target):
with target:
- log.chroot(target.path, "/usr/sbin/groupadd -f %s" % (
+ att = self.node.et.attrib
+ # we use -f always
+ options = "-f "
+ if 'gid' in att:
+ options += '-g "%s" ' % att['gid']
+ if 'system' in att and att['system'] == 'True':
+ options += '-r'
+ log.chroot(target.path, '/usr/sbin/groupadd %s "%s"' % (
+ options,
self.node.et.text))
diff --git a/schema/dbsfed.xsd b/schema/dbsfed.xsd
index d87967de..ae9756dc 100644
--- a/schema/dbsfed.xsd
+++ b/schema/dbsfed.xsd
@@ -1634,7 +1634,7 @@
</documentation>
</annotation>
<choice>
- <element name="addgroup" type="rfs:string" minOccurs="0">
+ <element name="addgroup" type="rfs:addgroup" minOccurs="0">
<annotation>
<documentation>
add a group by name
@@ -1771,21 +1771,53 @@
</choice>
</group>
+ <complexType name="addgroup">
+ <annotation>
+ <documentation>
+ describes an additional user group to be created. the following parameters are
+ available:
+ 'gid' - group id.
+ 'system = "True" - system group.
+ The value of the tag describes the group name name
+ for the account.
+ </documentation>
+ </annotation>
+ <simpleContent>
+ <extension base="rfs:string">
+ <attribute name="gid" type="string" use="optional" />
+ <attribute name="system" type="boolean" use="optional">
+ </extension>
+ </simpleContent>
+ </complexType>
+
<complexType name="adduser">
<annotation>
<documentation>
describes an additional user account, the following parameters are
- available: 'shell' - the login shell for the user, 'passwd' - the
- password for the user and 'groups' - a comma separated list of groups
- the user is member of. The value of the tag describes the login name
- for the account.
+ available:
+ 'shell' - the login shell for the user.
+ 'passwd' - the (optional) password for the user.
+ 'groups' - a comma separated list of groups the user is member of.
+ 'uid' - (optional) user of the user.
+ 'gid' - (optional) primary group, may be numeric or a name.
+ 'home' - home directory.
+ 'system="True"' - system user.
+ 'create_home="False"' - do not create the home directory.
+ 'create_group = "False"' - Do not create the primary group.
+ The value of the tag describes the login name for the account.
</documentation>
</annotation>
<simpleContent>
<extension base="rfs:string">
<attribute name="shell" type="string" use="required" />
- <attribute name="passwd" type="string" use="required" />
+ <attribute name="passwd" type="string" use="optional" />
<attribute name="groups" type="string" use="optional" />
+ <attribute name="uid" type="string" use="optional" />
+ <attribute name="gid" type="string" use="optional" />
+ <attribute name="home" type="string" use="optional" />
+ <attribute name="system" type="boolean" use="optional">
+ <attribute name="create_home" type="boolean" use="optional">
+ <attribute name="create_group" type="boolean" use="optional">
</extension>
</simpleContent>
</complexType>
--
2.11.0
More information about the elbe-devel
mailing list