diff mbox

[1/1] support/scripts/mkusers: allow /etc/shadow to be symlinked

Message ID 20170608152622.30019-1-mail@jens-maus.de
State Superseded
Headers show

Commit Message

Jens Maus June 8, 2017, 3:26 p.m. UTC
This commit fixes a problem where it was not possible to replace
/etc/shadow with a symlink to a e.g. a user partition where the
shadow file is placed. This is required, e.g. for systems where the
rootfs is mounted read-only but users should still be able to be
added. Thus, if within an filesystem overlay setup a user tries
to replace /etc/shadow with a symlink to the real file on a user
partition a buildroot build stops with an error message because
sed is called on the symlink instead of following the symlink.
This commit fixes this shortcoming.

Signed-off-by: Jens Maus <mail@jens-maus.de>
---
 support/scripts/mkusers | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yann E. MORIN June 11, 2017, 1:48 p.m. UTC | #1
Jens, All,

On 2017-06-08 17:26 +0200, Jens Maus spake thusly:
> This commit fixes a problem where it was not possible to replace
> /etc/shadow with a symlink to a e.g. a user partition where the
> shadow file is placed. This is required, e.g. for systems where the
> rootfs is mounted read-only but users should still be able to be
> added. Thus, if within an filesystem overlay setup a user tries
> to replace /etc/shadow with a symlink to the real file on a user
> partition a buildroot build stops with an error message because
> sed is called on the symlink instead of following the symlink.
> This commit fixes this shortcoming.
> 
> Signed-off-by: Jens Maus <mail@jens-maus.de>

Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

It is to be noted that --follow-symlinks was introduced in sed 4.2,
released 2009-05-11, a bit more than 8 years ago, and this is old enough
that we believe all sane distros have it.

Regards,
Yann E. MORIN.

> ---
>  support/scripts/mkusers | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/support/scripts/mkusers b/support/scripts/mkusers
> index 2ac76f986..e83aff6e0 100755
> --- a/support/scripts/mkusers
> +++ b/support/scripts/mkusers
> @@ -303,7 +303,7 @@ add_one_user() {
>  
>      # Remove any previous instance of this user
>      for _f in "${PASSWD}" "${SHADOW}"; do
> -        sed -r -i -e '/^'"${username}"':.*/d;' "${_f}"
> +        sed -r -i --follow-symlinks -e '/^'"${username}"':.*/d;' "${_f}"
>      done
>  
>      _gid="$( get_gid "${group}" )"
> -- 
> 2.11.0
> 
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
Yann E. MORIN June 11, 2017, 1:52 p.m. UTC | #2
Jens, All,

On 2017-06-08 17:26 +0200, Jens Maus spake thusly:
> This commit fixes a problem where it was not possible to replace
> /etc/shadow with a symlink to a e.g. a user partition where the
> shadow file is placed. This is required, e.g. for systems where the
> rootfs is mounted read-only but users should still be able to be
> added. Thus, if within an filesystem overlay setup a user tries
> to replace /etc/shadow with a symlink to the real file on a user
> partition a buildroot build stops with an error message because
> sed is called on the symlink instead of following the symlink.
> This commit fixes this shortcoming.
> 
> Signed-off-by: Jens Maus <mail@jens-maus.de>
> ---
>  support/scripts/mkusers | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/support/scripts/mkusers b/support/scripts/mkusers
> index 2ac76f986..e83aff6e0 100755
> --- a/support/scripts/mkusers
> +++ b/support/scripts/mkusers
> @@ -303,7 +303,7 @@ add_one_user() {
>  
>      # Remove any previous instance of this user
>      for _f in "${PASSWD}" "${SHADOW}"; do
> -        sed -r -i -e '/^'"${username}"':.*/d;' "${_f}"
> +        sed -r -i --follow-symlinks -e '/^'"${username}"':.*/d;' "${_f}"

By the way, you missed a few occurences:
  - line 222
  - line 227
  - line 266

Care to fix those as well and respin, please?

Regards,
Yann E. MORIN.

>      done
>  
>      _gid="$( get_gid "${group}" )"
> -- 
> 2.11.0
> 
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
diff mbox

Patch

diff --git a/support/scripts/mkusers b/support/scripts/mkusers
index 2ac76f986..e83aff6e0 100755
--- a/support/scripts/mkusers
+++ b/support/scripts/mkusers
@@ -303,7 +303,7 @@  add_one_user() {
 
     # Remove any previous instance of this user
     for _f in "${PASSWD}" "${SHADOW}"; do
-        sed -r -i -e '/^'"${username}"':.*/d;' "${_f}"
+        sed -r -i --follow-symlinks -e '/^'"${username}"':.*/d;' "${_f}"
     done
 
     _gid="$( get_gid "${group}" )"