* [PATCH 0/2] useradd-staticids
@ 2014-02-10 19:28 Mark Hatle
2014-02-10 19:28 ` [PATCH 1/2] useradd-staticids: Fix groupadd when --user-group is selected Mark Hatle
2014-02-10 19:28 ` [PATCH 2/2] useradd-staticids: Adjust USERADD_ERROR_DYNAMIC condition and error message Mark Hatle
0 siblings, 2 replies; 3+ messages in thread
From: Mark Hatle @ 2014-02-10 19:28 UTC (permalink / raw)
To: openembedded-core
Someone found a bug with the code already, see the bug information below:
> I'm testing with our current recipes which creates a user has a uid
> overridden in a configured passwd table file.
>
> Snippet from somepkg.bb:
> USERADD_PACKAGES = "${PN}"
> USERADD_PARAM_${PN} = "--system -s /bin/sh --user-group somename"
>
> It does not contain any GROUPADD_PARAM_${PN}.
> This build fails since when adding the user 'somename', the group
> 'somename' can't be found. Activating some commented debugging in the
> bbclass, you can see these printouts:
>
> WARNING: Before: 'USERADD_PARAM_somepkg' - '--system -s /bin/sh
> --user-group somename'
> WARNING: After: 'USERADD_PARAM_somepkg' - '--gid somename --system
> --shell /bin/sh --uid XX somename'
>
> What can be seen is that the uid is fetched from the static passwd-file
> that is configured, however the --user-group flag is lost and no group
> is created (GROUPADD_PARAM is set to "" (blank) in the
> run.do_install.useradd_sysroot.<pid>).
As noted above the --user-group flag was being cleared, even in cases where
we did not have enough information to properly clear it. Refactor the code
in this section of the class.. (The above was used to verify functionality.)
In addition, a second patch cleaned up the error checking and added an
easier way for a developer of this code to see what is happening during initial
parse.
The following changes since commit b5b4898cd409036161c62891e9618d9ab3f891f9:
python-pycurl: upgrade to 7.19.3 (2014-02-08 21:03:27 +0000)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib mhatle/uidgid
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=mhatle/uidgid
Mark Hatle (2):
useradd-staticids: Fix groupadd when --user-group is selected
useradd-staticids: Adjust USERADD_ERROR_DYNAMIC condition and error
message
meta/classes/useradd-staticids.bbclass | 58 ++++++++++++++++++++--------------
1 file changed, 35 insertions(+), 23 deletions(-)
--
1.8.5.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] useradd-staticids: Fix groupadd when --user-group is selected
2014-02-10 19:28 [PATCH 0/2] useradd-staticids Mark Hatle
@ 2014-02-10 19:28 ` Mark Hatle
2014-02-10 19:28 ` [PATCH 2/2] useradd-staticids: Adjust USERADD_ERROR_DYNAMIC condition and error message Mark Hatle
1 sibling, 0 replies; 3+ messages in thread
From: Mark Hatle @ 2014-02-10 19:28 UTC (permalink / raw)
To: openembedded-core
When --user-group is selected (it's on by default as well) we want
to translate that to a groupname and disable the --user-group. Before
we just disabled --user-group, but didn't always add the group to the
system.
This change ensures that we add the group (as long as we have enough
information to actually add the group), and we disable --user-group
in that case. If a static groupid is not specified we continue to
use the groupname, but via an explicit groupadd.
Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
---
meta/classes/useradd-staticids.bbclass | 50 ++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 20 deletions(-)
diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass
index 689c29c..5897fed 100644
--- a/meta/classes/useradd-staticids.bbclass
+++ b/meta/classes/useradd-staticids.bbclass
@@ -96,27 +96,37 @@ def update_useradd_static_config(d):
# is used, and we disable the user_group option.
#
uaargs.groupname = [uaargs.gid, uaargs.LOGIN][not uaargs.gid or uaargs.user_group]
- uaargs.user_group = False
+ uaargs.groupid = [uaargs.gid, uaargs.groupname][not uaargs.gid]
+ uaargs.groupid = [field[3], uaargs.groupid][not field[3]]
- uaargs.gid = [uaargs.gid, uaargs.groupname][not uaargs.gid]
- uaargs.gid = [field[3], uaargs.gid][not field[3]]
-
- if uaargs.groupname == uaargs.gid:
- # Nothing to do...
- pass
- elif (uaargs.groupname and uaargs.groupname.isdigit()) and (uaargs.gid and uaargs.gid.isdigit()) and (uaargs.groupname != uaargs.gid):
- # We want to add a group, but we don't know it's name... so we can't add the group...
- # We have to assume the group has previously been added or we'll fail on the adduser...
- # Note: specifying the actual gid is very rare in OE, usually the group name is specified.
- bb.warn("%s: Changing gid for login %s from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), uaargs.LOGIN, uaargs.groupname, uaargs.gid))
- elif uaargs.groupname and (uaargs.gid and uaargs.gid.isdigit()):
- bb.debug(1, "Adding group %s gid (%s)!" % (uaargs.groupname, uaargs.gid))
- groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg, True)
- newgroup = "-g %s %s" % (uaargs.gid, uaargs.groupname)
- if groupadd:
- d.setVar("GROUPADD_PARAM_%s" % pkg, "%s ; %s" % (groupadd, newgroup))
- else:
- d.setVar("GROUPADD_PARAM_%s" % pkg, newgroup)
+ if not uaargs.gid or uaargs.gid != uaargs.groupid:
+ if (uaargs.groupid and uaargs.groupid.isdigit()) and (uaargs.groupname and uaargs.groupname.isdigit()) and (uaargs.groupid != uaargs.groupname):
+ # We want to add a group, but we don't know it's name... so we can't add the group...
+ # We have to assume the group has previously been added or we'll fail on the adduser...
+ # Note: specifying the actual gid is very rare in OE, usually the group name is specified.
+ bb.warn("%s: Changing gid for login %s from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), uaargs.LOGIN, uaargs.groupname, uaargs.gid))
+ elif (uaargs.groupid and not uaargs.groupid.isdigit()) and uaargs.groupid == uaargs.groupname:
+ # We don't have a number, so we have to add a name
+ bb.debug(1, "Adding group %s!" % (uaargs.groupname))
+ uaargs.gid = uaargs.groupid
+ uaargs.user_group = False
+ groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg, True)
+ newgroup = "%s %s" % (['', ' --system'][uaargs.system], uaargs.groupname)
+ if groupadd:
+ d.setVar("GROUPADD_PARAM_%s" % pkg, "%s ; %s" % (groupadd, newgroup))
+ else:
+ d.setVar("GROUPADD_PARAM_%s" % pkg, newgroup)
+ elif uaargs.groupname and (uaargs.groupid and uaargs.groupid.isdigit()):
+ # We have a group name and a group number to assign it to
+ bb.debug(1, "Adding group %s gid (%s)!" % (uaargs.groupname, uaargs.groupid))
+ uaargs.gid = uaargs.groupid
+ uaargs.user_group = False
+ groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg, True)
+ newgroup = "-g %s %s" % (uaargs.gid, uaargs.groupname)
+ if groupadd:
+ d.setVar("GROUPADD_PARAM_%s" % pkg, "%s ; %s" % (groupadd, newgroup))
+ else:
+ d.setVar("GROUPADD_PARAM_%s" % pkg, newgroup)
uaargs.comment = ["'%s'" % field[4], uaargs.comment][not field[4]]
uaargs.home_dir = [field[5], uaargs.home_dir][not field[5]]
--
1.8.5.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] useradd-staticids: Adjust USERADD_ERROR_DYNAMIC condition and error message
2014-02-10 19:28 [PATCH 0/2] useradd-staticids Mark Hatle
2014-02-10 19:28 ` [PATCH 1/2] useradd-staticids: Fix groupadd when --user-group is selected Mark Hatle
@ 2014-02-10 19:28 ` Mark Hatle
1 sibling, 0 replies; 3+ messages in thread
From: Mark Hatle @ 2014-02-10 19:28 UTC (permalink / raw)
To: openembedded-core
The USERADD_ERROR_DYNAMIC needs to check that both users and groups that are
defined need to be represented as static ids, or an error should occur.
For the user check, we want to make sure the uid is a numeric value. (The gid
can be name, as the GROUPADD check will validate for a number there -- or
during install useradd will fail if that group is not defined.)
For the group check, we verify that the gid is specified and not left as a name.
Also two statements that can be uncommented for debugging were added so that
future development work on this code would be easier to do.
Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
---
meta/classes/useradd-staticids.bbclass | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass
index 5897fed..3efe2a8 100644
--- a/meta/classes/useradd-staticids.bbclass
+++ b/meta/classes/useradd-staticids.bbclass
@@ -134,8 +134,9 @@ def update_useradd_static_config(d):
break
# Should be an error if a specific option is set...
- if d.getVar('USERADD_ERROR_DYNAMIC', True) == '1' and (not uaargs.uid or not uaargs.gid):
- raise bb.build.FuncFailed("%s - %s: Username %s does not have a static uid/gid defined." % (d.getVar('PN', True), pkg, uaargs.LOGIN))
+ if d.getVar('USERADD_ERROR_DYNAMIC', True) == '1' and not ((uaargs.uid and uaargs.uid.isdigit()) and uaargs.gid):
+ #bb.error("Skipping recipe %s, package %s which adds username %s does not have a static uid defined." % (d.getVar('PN', True), pkg, uaargs.LOGIN))
+ raise bb.build.FuncFailed("%s - %s: Username %s does not have a static uid defined." % (d.getVar('PN', True), pkg, uaargs.LOGIN))
# Reconstruct the args...
newparam = ['', ' --defaults'][uaargs.defaults]
@@ -222,7 +223,8 @@ def update_useradd_static_config(d):
gaargs.gid = field[2]
break
- if d.getVar('USERADD_ERROR_DYNAMIC', True) == '1' and not gaargs.gid:
+ if d.getVar('USERADD_ERROR_DYNAMIC', True) == '1' and not (gaargs.gid and gaargs.gid.isdigit()):
+ #bb.error("Skipping recipe %s, package %s which adds groupname %s does not have a static gid defined." % (d.getVar('PN', True), pkg, gaargs.GROUP))
raise bb.build.FuncFailed("%s - %s: Groupname %s does not have a static gid defined." % (d.getVar('PN', True), pkg, gaargs.GROUP))
# Reconstruct the args...
--
1.8.5.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-02-10 19:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-10 19:28 [PATCH 0/2] useradd-staticids Mark Hatle
2014-02-10 19:28 ` [PATCH 1/2] useradd-staticids: Fix groupadd when --user-group is selected Mark Hatle
2014-02-10 19:28 ` [PATCH 2/2] useradd-staticids: Adjust USERADD_ERROR_DYNAMIC condition and error message Mark Hatle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox