Patchwork [2/2] useradd-staticids: Adjust USERADD_ERROR_DYNAMIC condition and error message

login
register
mail settings
Submitter Mark Hatle
Date Feb. 10, 2014, 7:28 p.m.
Message ID <d6db736c28f68632eb05d94f254bcd0ca465a977.1392060196.git.mark.hatle@windriver.com>
Download mbox | patch
Permalink /patch/66539/
State New
Headers show

Comments

Mark Hatle - Feb. 10, 2014, 7:28 p.m.
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(-)

Patch

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...