support/mkusers: Preserve group members
PATCH 1/1 support/mkusers: Preserve group members
When the function add_one_group is called on an existing group, make sure the members of this group are not removed in the process of deleting then re-adding the group.
--- support/scripts/mkusers | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
support/scripts/mkusers +11 -2
@@ -75,6 +75,14 @@ get_gid() { '$1 == group { printf( "%d\n", $3 ); }' "${GROUP}" } +#---------------------------------------------------------------------------- +get_members() { + local group="${1}" + + awk -F: -v group="${group}" \ + '$1 == group { printf( "%s\n", $4 ); }' "${GROUP}" +} + #---------------------------------------------------------------------------- get_username() { local uid="${1}"
@@ -211,16 +219,17 @@ generate_gid() { add_one_group() { local group="${1}" local gid="${2}" - local _f + local members # Generate a new GID if needed if [ ${gid} -eq -1 ]; then gid="$( generate_gid "${group}" )" fi + members=$(get_members "$group") # Remove any previous instance of this group, and re-add the new one sed -i --follow-symlinks -e '/^'"${group}"':.*/d;' "${GROUP}" - printf "%s:x:%d:\n" "${group}" "${gid}" >>"${GROUP}" + printf "%s:x:%d:%s\n" "${group}" "${gid}" "$members" >>"${GROUP}" # Ditto for /etc/gshadow if it exists if [ -f "${GSHADOW}" ]; then
Signature · 1 line
2.17.1
PATCH 1/1 support/mkusers: Preserve group members
Johan, All,
On 2018-09-03 15:11 +0200, Johan Oudinet spake thusly:
Quoted 5 lines
When the function
add_one_groupis called on an existing group, make sure the members of this group are not removed in the process of deleting then re-adding the group.Signed-off-by Johan Oudinet <[email protected]>
Regards,
Yann E. MORIN.
Quoted 50 lines
--- support/scripts/mkusers | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)support/scripts/mkusers +11
-2@@ -75,6 +75,14 @@ get_gid() { '$1 == group { printf( "%d\n", $3 ); }' "${GROUP}" } +#---------------------------------------------------------------------------- +get_members() { + local group="${1}" + + awk -F: -v group="${group}" \ + '$1 == group { printf( "%s\n", $4 ); }' "${GROUP}" +} + #---------------------------------------------------------------------------- get_username() { local uid="${1}"@@ -211,16 +219,17 @@ generate_gid() { add_one_group() { local group="${1}" local gid="${2}" - local _f + local members # Generate a new GID if needed if [ ${gid} -eq -1 ]; then gid="$( generate_gid "${group}" )" fi + members=$(get_members "$group") # Remove any previous instance of this group, and re-add the new one sed -i --follow-symlinks -e '/^'"${group}"':.*/d;' "${GROUP}" - printf "%s:x:%d:\n" "${group}" "${gid}" >>"${GROUP}" + printf "%s:x:%d:%s\n" "${group}" "${gid}" "$members" >>"${GROUP}" # Ditto for /etc/gshadow if it exists if [ -f "${GSHADOW}" ]; thenSignature · 6 lines
2.17.1 _______________________________________________ buildroot mailing list buildroot at busybox.net http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 1/1 support/mkusers: Preserve group members
In reply to Johan OudinetJohan, All,
On 2018-09-03 15:11 +0200, Johan Oudinet spake thusly:
Quoted 5 lines
When the function
add_one_groupis called on an existing group, make sure the members of this group are not removed in the process of deleting then re-adding the group.Signed-off-by Johan Oudinet <[email protected]>
[--SNIP--]
support/scripts/mkusers generate_gid() { · line 232
Quoted 5 lines
support/scripts/mkusers +2
-1+ members=$(get_members "$group") # Remove any previous instance of this group, and re-add the new one sed -i --follow-symlinks -e '/^'"${group}"':.*/d;' "${GROUP}" - printf "%s:x:%d:\n" "${group}" "${gid}" >>"${GROUP}" + printf "%s:x:%d:%s\n" "${group}" "${gid}" "$members" >>"${GROUP}"
The variables should all be derefernced with accolades: $(members)
With that fixed when applying, my previous reviewed-by stands.
Regards,
Yann E. MORIN.
Quoted 10 lines
# Ditto for
/etc/gshadowif it exists
if [ -f "${GSHADOW}" ]; thenSignature · 6 lines
2.17.1 _______________________________________________ buildroot mailing list buildroot at busybox.net http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
Thomas Petazzoni
AppliedPATCH 1/1 support/mkusers: Preserve group members
In reply to Johan OudinetHello,
Quoted 8 lines · Johan Oudinet
When the function
add_one_groupis called on an existing group, make sure the members of this group are not removed in the process of deleting then re-adding the group.Signed-off-by Johan Oudinet <[email protected]>--- support/scripts/mkusers | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
Applied to master after referencing the ${members} variable using curly braces, as suggested by Yann.
Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
PATCH 1/1 support/mkusers: Preserve group members
In reply to Johan OudinetQuoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Johan" == Johan Oudinet <[email protected]> writes:
When the function
add_one_groupis called on an existing group, make sure the members of this group are not removed in the process of deleting then re-adding the group.Signed-off-by Johan Oudinet <[email protected]>
Committed to 2018.02.x, 2018.05.x and 2018.08.x, thanks.
Signature · 1 line
Bye, Peter Korsgaard