base-files: merge /etc/passwd support more than just /rom based installs

Henrique de Moraes Holschuh henrique at nic.br
Fri Nov 27 09:13:56 EST 2020


On 27/11/2020 03:19, Imran K wrote:
> Support more than /rom only when migrating user accounts

This is the kind of thing you must do safely (e.g. using mktemp -dt && 
chmod 0700 <the-mktemp-created-dir> && { ... }), unless you can prove 
there is no way someone might have messed with /tmp before or during the 
script's execution.

And if you can prove it is safe (which it might well be), that 
explanation ought to be in the commit log...

Also, cp -f and rm -f might be better choices.

> diff --git a/package/base-files/files/lib/preinit/80_mount_root
> b/package/base-files/files/lib/preinit/80_mount_root
> index 56d3fa3797..1c5bdbc9d8 100644
> --- a/package/base-files/files/lib/preinit/80_mount_root
> +++ b/package/base-files/files/lib/preinit/80_mount_root
> @@ -20,11 +20,17 @@ do_mount_root() {
>    boot_run_hook preinit_mount_root
>    [ -f /sysupgrade.tgz ] && {
>    echo "- config restore -"
> - cd /
> +         cp /etc/passwd /tmp/
> + cp /etc/group /tmp/
> + cp /etc/shadow /tmp/
> +        cd /
>    tar xzf /sysupgrade.tgz
> - missing_lines /rom/etc/passwd /etc/passwd >> /etc/passwd
> - missing_lines /rom/etc/group /etc/group >> /etc/group
> - missing_lines /rom/etc/shadow /etc/shadow >> /etc/shadow
> + missing_lines /tmp/passwd /etc/passwd >> /etc/passwd
> + missing_lines /tmp/group /etc/group >> /etc/group
> + missing_lines /tmp/shadow /etc/shadow >> /etc/shadow
> +        rm /tmp/shadow 2>/dev/null
> +        rm /tmp/passwd 2>/dev/null
> +        rm /tmp/group 2>/dev/null
>    # Prevent configuration corruption on a power loss
>    sync
>    }


-- 
Henrique de Moraes Holschuh
Analista de Projetos
Centro de Estudos e Pesquisas em Tecnologias de Redes e Operações 
(Ceptro.br)
+55 11 5509-3537 R.:4023
INOC 22548*625
www.nic.br



More information about the openwrt-devel mailing list