Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] support/mkusers: allow comments in users tables
@ 2015-10-17 15:50 Yann E. MORIN
  2015-10-18 15:55 ` Thomas Petazzoni
  0 siblings, 1 reply; 2+ messages in thread
From: Yann E. MORIN @ 2015-10-17 15:50 UTC (permalink / raw)
  To: buildroot

The format of the users table files is non trivial, so it is sometimes
handy to add comments explaining the syntax (or simply the reason for
the user) inline in the files.

Ignore empty lines and comment lines prefixed with '#' similar to shell
or makedevs files.

Packages that defined no user (the vast majority) would cause an empty
line to be present in the internal users table, hence the reason we
skipped empty usernames. Now that we ignore empty lines, we no longer
need to check for empty usernames.

Reported-by: Peter Korsgaard <jacmet@uclibc.org>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Peter Korsgaard <jacmet@uclibc.org>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 support/scripts/mkusers | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/support/scripts/mkusers b/support/scripts/mkusers
index 9c5c4dc..e2c24c7 100755
--- a/support/scripts/mkusers
+++ b/support/scripts/mkusers
@@ -358,6 +358,8 @@ add_one_user() {
 #----------------------------------------------------------------------------
 main() {
     local username uid group gid passwd home shell groups comment
+    local line
+    local -a LINES
 
     # Some sanity checks
     if [ ${MIN_UID} -le 0 ]; then
@@ -367,36 +369,41 @@ main() {
         fail "MIN_GID must be >0 (currently %d)\n" ${MIN_GID}
     fi
 
+    # Read in all the file in memory, exclude empty lines and comments
+    while read line; do
+        LINES+=( "${line}" )
+    done < <( sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" )
+
     # We first create groups whose gid is not -1, and then we create groups
     # whose gid is -1 (automatic), so that, if a group is defined both with
     # a specified gid and an automatic gid, we ensure the specified gid is
     # used, rather than a different automatic gid is computed.
 
     # First, create all the main groups which gid is *not* automatic
-    while read username uid group gid passwd home shell groups comment; do
-        [ -n "${username}" ] || continue    # Package with no user
-        [ ${gid} -ge 0     ] || continue    # Automatic gid
+    for line in "${LINES[@]}"; do
+        read username uid group gid passwd home shell groups comment <<<"${line}"
+        [ ${gid} -ge 0 ] || continue    # Automatic gid
         add_one_group "${group}" "${gid}"
-    done <"${USERS_TABLE}"
+    done
 
     # Then, create all the main groups which gid *is* automatic
-    while read username uid group gid passwd home shell groups comment; do
-        [ -n "${username}" ] || continue    # Package with no user
-        [ ${gid} -eq -1    ] || continue    # Non-automatic gid
+    for line in "${LINES[@]}"; do
+        read username uid group gid passwd home shell groups comment <<<"${line}"
+        [ ${gid} -eq -1 ] || continue    # Non-automatic gid
         add_one_group "${group}" "${gid}"
-    done <"${USERS_TABLE}"
+    done
 
     # Then, create all the additional groups
     # If any additional group is already a main group, we should use
     # the gid of that main group; otherwise, we can use any gid
-    while read username uid group gid passwd home shell groups comment; do
-        [ -n "${username}" ] || continue    # Package with no user
+    for line in "${LINES[@]}"; do
+        read username uid group gid passwd home shell groups comment <<<"${line}"
         if [ "${groups}" != "-" ]; then
             for g in ${groups//,/ }; do
                 add_one_group "${g}" -1
             done
         fi
-    done <"${USERS_TABLE}"
+    done
 
     # When adding users, we do as for groups, in case two packages create
     # the same user, one with an automatic uid, the other with a specified
@@ -404,22 +411,22 @@ main() {
     # uid be generated.
 
     # Now, add users whose uid is *not* automatic
-    while read username uid group gid passwd home shell groups comment; do
-        [ -n "${username}" ] || continue    # Package with no user
+    for line in "${LINES[@]}"; do
+        read username uid group gid passwd home shell groups comment <<<"${line}"
         [ "${username}" != "-" ] || continue # Magic string to skip user creation
-        [ ${uid} -ge 0     ] || continue    # Automatic uid
+        [ ${uid} -ge 0         ] || continue # Automatic uid
         add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
                      "${home}" "${shell}" "${groups}" "${comment}"
-    done <"${USERS_TABLE}"
+    done
 
     # Finally, add users whose uid *is* automatic
-    while read username uid group gid passwd home shell groups comment; do
-        [ -n "${username}" ] || continue    # Package with no user
+    for line in "${LINES[@]}"; do
+        read username uid group gid passwd home shell groups comment <<<"${line}"
         [ "${username}" != "-" ] || continue # Magic string to skip user creation
-        [ ${uid} -eq -1    ] || continue    # Non-automatic uid
+        [ ${uid} -eq -1        ] || continue # Non-automatic uid
         add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
                      "${home}" "${shell}" "${groups}" "${comment}"
-    done <"${USERS_TABLE}"
+    done
 }
 
 #----------------------------------------------------------------------------
-- 
1.9.1

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

* [Buildroot] [PATCH] support/mkusers: allow comments in users tables
  2015-10-17 15:50 [Buildroot] [PATCH] support/mkusers: allow comments in users tables Yann E. MORIN
@ 2015-10-18 15:55 ` Thomas Petazzoni
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Petazzoni @ 2015-10-18 15:55 UTC (permalink / raw)
  To: buildroot

Dear Yann E. MORIN,

On Sat, 17 Oct 2015 17:50:19 +0200, Yann E. MORIN wrote:
> The format of the users table files is non trivial, so it is sometimes
> handy to add comments explaining the syntax (or simply the reason for
> the user) inline in the files.
> 
> Ignore empty lines and comment lines prefixed with '#' similar to shell
> or makedevs files.
> 
> Packages that defined no user (the vast majority) would cause an empty
> line to be present in the internal users table, hence the reason we
> skipped empty usernames. Now that we ignore empty lines, we no longer
> need to check for empty usernames.
> 
> Reported-by: Peter Korsgaard <jacmet@uclibc.org>
> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> Cc: Peter Korsgaard <jacmet@uclibc.org>
> Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> ---
>  support/scripts/mkusers | 45 ++++++++++++++++++++++++++-------------------
>  1 file changed, 26 insertions(+), 19 deletions(-)

Applied, thanks.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

end of thread, other threads:[~2015-10-18 15:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-17 15:50 [Buildroot] [PATCH] support/mkusers: allow comments in users tables Yann E. MORIN
2015-10-18 15:55 ` Thomas Petazzoni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox