All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] Fix for useradd-staticids.bbclass
@ 2015-10-23 10:38 Peter Kjellerstedt
  2015-10-23 10:38 ` [PATCH 1/1] useradd-staticids.bbclass: Do not require trailing colons Peter Kjellerstedt
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Kjellerstedt @ 2015-10-23 10:38 UTC (permalink / raw)
  To: openembedded-core

This change corrects useradd-staticids.bbclass to allow user and group
files without trailing colons. Previously one had to write:

foo::123::::

in the group file to define the static UID for a user or one would
receive a Python exception. With this change applied one can instead
write:

foo::123

The change is of course backwards compatible so the old format is
still valid.

//Peter

The following changes since commit 505a82673ac2487df5ea343a6422c2fc47018831:

  build-appliance-image: Update to jethro head revision (2015-10-21 23:13:11 +0100)

are available in the git repository at:

  git://git.yoctoproject.org/poky-contrib pkj/useradd_skip_colons
  http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=pkj/useradd_skip_colons

Peter Kjellerstedt (1):
  useradd-staticids.bbclass: Do not require trailing colons

 meta/classes/useradd-staticids.bbclass | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

-- 
2.1.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/1] useradd-staticids.bbclass: Do not require trailing colons
  2015-10-23 10:38 [PATCH 0/1] Fix for useradd-staticids.bbclass Peter Kjellerstedt
@ 2015-10-23 10:38 ` Peter Kjellerstedt
  2015-10-23 15:20   ` Burton, Ross
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Kjellerstedt @ 2015-10-23 10:38 UTC (permalink / raw)
  To: openembedded-core

Before, the users and groups specified in the passwd file and the
groups file had to have trailing colons to make sure there were enough
elements in the definitions, or bitbake would thow a Python exception.
After this change one can omit the trailing colons, which especially
simplifies passwd files used only to specify static UIDs.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---
 meta/classes/useradd-staticids.bbclass | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass
index 421a70a..aa1b15b 100644
--- a/meta/classes/useradd-staticids.bbclass
+++ b/meta/classes/useradd-staticids.bbclass
@@ -84,7 +84,11 @@ def update_useradd_static_config(d):
                     for line in f:
                         if line.startswith('#'):
                             continue
-                        field = line.rstrip().split(":")
+                        # Make sure there always are at least seven elements in
+                        # the field list. This allows for leaving out trailing
+                        # colons in the passwd file.
+                        line = line.rstrip() + "::::::"
+                        field = line.split(":")
                         if field[0] == uaargs.LOGIN:
                             if uaargs.uid and field[2] and (uaargs.uid != field[2]):
                                 bb.warn("%s: Changing username %s's uid from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), uaargs.LOGIN, uaargs.uid, field[2]))
@@ -220,7 +224,11 @@ def update_useradd_static_config(d):
                     for line in f:
                         if line.startswith('#'):
                             continue
-                        field = line.rstrip().split(":")
+                        # Make sure there always are at least four elements in
+                        # the field list. This allows for leaving out trailing
+                        # colons in the group file.
+                        line = line.rstrip() + ":::"
+                        field = line.split(":")
                         if field[0] == gaargs.GROUP and field[2]:
                             if gaargs.gid and (gaargs.gid != field[2]):
                                 bb.warn("%s: Changing groupname %s's gid from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), gaargs.GROUP, gaargs.gid, field[2]))
-- 
2.1.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] useradd-staticids.bbclass: Do not require trailing colons
  2015-10-23 10:38 ` [PATCH 1/1] useradd-staticids.bbclass: Do not require trailing colons Peter Kjellerstedt
@ 2015-10-23 15:20   ` Burton, Ross
  2015-10-23 15:52     ` Christopher Larson
  0 siblings, 1 reply; 5+ messages in thread
From: Burton, Ross @ 2015-10-23 15:20 UTC (permalink / raw)
  To: Peter Kjellerstedt; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]

On 23 October 2015 at 11:38, Peter Kjellerstedt <peter.kjellerstedt@axis.com
> wrote:

> -                        field = line.rstrip().split(":")
> +                        # Make sure there always are at least seven
> elements in
> +                        # the field list. This allows for leaving out
> trailing
> +                        # colons in the passwd file.
> +                        line = line.rstrip() + "::::::"
> +                        field = line.split(":")
>

It's a stylist thing but I prefer padding the field list instead of
manipulating the input string. Something like

  field = line.strip().split(":")
  field += [''] * (7 - len(field))

Ross

[-- Attachment #2: Type: text/html, Size: 1381 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] useradd-staticids.bbclass: Do not require trailing colons
  2015-10-23 15:20   ` Burton, Ross
@ 2015-10-23 15:52     ` Christopher Larson
  2015-10-24  9:45       ` Peter Kjellerstedt
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Larson @ 2015-10-23 15:52 UTC (permalink / raw)
  To: Burton, Ross; +Cc: Peter Kjellerstedt, OE-core

[-- Attachment #1: Type: text/plain, Size: 1262 bytes --]

On Fri, Oct 23, 2015 at 8:20 AM, Burton, Ross <ross.burton@intel.com> wrote:

> On 23 October 2015 at 11:38, Peter Kjellerstedt <
> peter.kjellerstedt@axis.com> wrote:
>
>> -                        field = line.rstrip().split(":")
>> +                        # Make sure there always are at least seven
>> elements in
>> +                        # the field list. This allows for leaving out
>> trailing
>> +                        # colons in the passwd file.
>> +                        line = line.rstrip() + "::::::"
>> +                        field = line.split(":")
>>
>
> It's a stylist thing but I prefer padding the field list instead of
> manipulating the input string. Something like
>
>   field = line.strip().split(":")
>   field += [''] * (7 - len(field))
>

Agreed, but I think this is cleaner:

def iter_extend(iterable, length, obj=None):
    """Ensure that iterable is the specified length by extending with obj"""
    return itertools.islice(itertools.chain(iterable,
itertools.repeat(obj)), length)

fields = iter_extend(line.rstrip().split(":"), 7)
-- 
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics

[-- Attachment #2: Type: text/html, Size: 2339 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] useradd-staticids.bbclass: Do not require trailing colons
  2015-10-23 15:52     ` Christopher Larson
@ 2015-10-24  9:45       ` Peter Kjellerstedt
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Kjellerstedt @ 2015-10-24  9:45 UTC (permalink / raw)
  To: 'Christopher Larson', Burton, Ross; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 1967 bytes --]

I changed it to:

    def list_extend(iterable, length, obj = None):
        """Ensure that iterable is the specified length by extending with obj
        and return it as a list"""
        return list(itertools.islice(itertools.chain(iterable, itertools.repeat(obj)), length))

because I got

Exception: TypeError: 'itertools.islice' object has no attribute '__getitem__'

otherwise.

New patch coming up.

//Peter

From: kergoth@gmail.com [mailto:kergoth@gmail.com] On Behalf Of Christopher Larson
Sent: 23 October 2015 17:53
To: Burton, Ross
Cc: Peter Kjellerstedt; OE-core
Subject: Re: [OE-core] [PATCH 1/1] useradd-staticids.bbclass: Do not require trailing colons


On Fri, Oct 23, 2015 at 8:20 AM, Burton, Ross <ross.burton@intel.com<mailto:ross.burton@intel.com>> wrote:
On 23 October 2015 at 11:38, Peter Kjellerstedt <peter.kjellerstedt@axis.com<mailto:peter.kjellerstedt@axis.com>> wrote:
-                        field = line.rstrip().split(":")
+                        # Make sure there always are at least seven elements in
+                        # the field list. This allows for leaving out trailing
+                        # colons in the passwd file.
+                        line = line.rstrip() + "::::::"
+                        field = line.split(":")

It's a stylist thing but I prefer padding the field list instead of manipulating the input string. Something like

  field = line.strip().split(":")
  field += [''] * (7 - len(field))

Agreed, but I think this is cleaner:

def iter_extend(iterable, length, obj=None):
    """Ensure that iterable is the specified length by extending with obj"""
    return itertools.islice(itertools.chain(iterable, itertools.repeat(obj)), length)

fields = iter_extend(line.rstrip().split(":"), 7)
--
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics

[-- Attachment #2: Type: text/html, Size: 7522 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-10-24  9:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-23 10:38 [PATCH 0/1] Fix for useradd-staticids.bbclass Peter Kjellerstedt
2015-10-23 10:38 ` [PATCH 1/1] useradd-staticids.bbclass: Do not require trailing colons Peter Kjellerstedt
2015-10-23 15:20   ` Burton, Ross
2015-10-23 15:52     ` Christopher Larson
2015-10-24  9:45       ` Peter Kjellerstedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.