[v2,1/2] fix group splitting in user creation

Message ID 20230727032415.3366650-1-felix.moessbauer@siemens.com
State Accepted, archived
Headers show
Series [v2,1/2] fix group splitting in user creation | expand

Commit Message

MOESSBAUER, Felix July 27, 2023, 3:24 a.m. UTC
There is a bug when converting the USER_<foo>[groups] configuration
from the bitbake format (space separated) to the format useradd
expects (comma separated). We cannot simply replace spaces with commas,
as then multiple spaces in a row would create multiple commas. Instead,
we need to split it first into the tokens and then join these tokens by
comma.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes/image-account-extension.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Tobias Schaffner Aug. 1, 2023, 7:21 a.m. UTC | #1
On 27.07.23 05:24, MOESSBAUER, Felix (T CED INW-CN) wrote:
> There is a bug when converting the USER_<foo>[groups] configuration
> from the bitbake format (space separated) to the format useradd
> expects (comma separated). We cannot simply replace spaces with commas,
> as then multiple spaces in a row would create multiple commas. Instead,
> we need to split it first into the tokens and then join these tokens by
> comma.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>   meta/classes/image-account-extension.bbclass | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes/image-account-extension.bbclass b/meta/classes/image-account-extension.bbclass
> index e783c135..6f67f459 100644
> --- a/meta/classes/image-account-extension.bbclass
> +++ b/meta/classes/image-account-extension.bbclass
> @@ -98,10 +98,10 @@ def image_create_users(d: "DataSmart") -> None:
>           add_user_option("--comment", "comment")
>           add_user_option("--shell", "shell")
>   
> -        groups = d.getVarFlag(user_entry, "groups") or ""
> +        groups = (d.getVarFlag(user_entry, "groups") or "").split()
>           if groups:
>               args.append("--groups")
> -            args.append(groups.replace(' ', ','))
> +            args.append(','.join(groups))
>   
>           flags = (d.getVarFlag(user_entry, "flags") or "").split()
>   

Acked-by: Tobias Schaffner <tobias.schaffner@siemens.com>
Uladzimir Bely Aug. 2, 2023, 9:31 p.m. UTC | #2
On Thu, 2023-07-27 at 03:24 +0000, 'Felix Moessbauer' via isar-users
wrote:
> There is a bug when converting the USER_<foo>[groups] configuration
> from the bitbake format (space separated) to the format useradd
> expects (comma separated). We cannot simply replace spaces with
> commas,
> as then multiple spaces in a row would create multiple commas.
> Instead,
> we need to split it first into the tokens and then join these tokens
> by
> comma.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  meta/classes/image-account-extension.bbclass | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes/image-account-extension.bbclass
> b/meta/classes/image-account-extension.bbclass
> index e783c135..6f67f459 100644
> --- a/meta/classes/image-account-extension.bbclass
> +++ b/meta/classes/image-account-extension.bbclass
> @@ -98,10 +98,10 @@ def image_create_users(d: "DataSmart") -> None:
>          add_user_option("--comment", "comment")
>          add_user_option("--shell", "shell")
>  
> -        groups = d.getVarFlag(user_entry, "groups") or ""
> +        groups = (d.getVarFlag(user_entry, "groups") or "").split()
>          if groups:
>              args.append("--groups")
> -            args.append(groups.replace(' ', ','))
> +            args.append(','.join(groups))
>  
>          flags = (d.getVarFlag(user_entry, "flags") or "").split()
>  
> -- 
> 2.34.1
> 

Series applied to next, thanks.

Patch

diff --git a/meta/classes/image-account-extension.bbclass b/meta/classes/image-account-extension.bbclass
index e783c135..6f67f459 100644
--- a/meta/classes/image-account-extension.bbclass
+++ b/meta/classes/image-account-extension.bbclass
@@ -98,10 +98,10 @@  def image_create_users(d: "DataSmart") -> None:
         add_user_option("--comment", "comment")
         add_user_option("--shell", "shell")
 
-        groups = d.getVarFlag(user_entry, "groups") or ""
+        groups = (d.getVarFlag(user_entry, "groups") or "").split()
         if groups:
             args.append("--groups")
-            args.append(groups.replace(' ', ','))
+            args.append(','.join(groups))
 
         flags = (d.getVarFlag(user_entry, "flags") or "").split()