diff mbox series

[1/7] package/skeleton-init-common: add /bin/sh to /etc/shells

Message ID 1515963815-5843-2-git-send-email-romain.naour@smile.fr
State Changes Requested
Headers show
Series Add /etc/shells handling | expand

Commit Message

Romain Naour Jan. 14, 2018, 9:03 p.m. UTC
Add the default shell /bin/sh to /etc/shells only if BR2_SYSTEM_BIN_SH_NONE
is not selected.

Add an empty /etc/shells in the rootfs skeleton.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
---
 package/skeleton-init-common/skeleton-init-common.mk | 7 +++++++
 system/skeleton/etc/shells                           | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 system/skeleton/etc/shells

Comments

Yann E. MORIN Jan. 14, 2018, 10:51 p.m. UTC | #1
On 2018-01-14 22:03 +0100, Romain Naour spake thusly:
> Add the default shell /bin/sh to /etc/shells only if BR2_SYSTEM_BIN_SH_NONE
> is not selected.
> 
> Add an empty /etc/shells in the rootfs skeleton.
> 
> Signed-off-by: Romain Naour <romain.naour@smile.fr>
> ---
>  package/skeleton-init-common/skeleton-init-common.mk | 7 +++++++
>  system/skeleton/etc/shells                           | 1 +
>  2 files changed, 8 insertions(+)
>  create mode 100644 system/skeleton/etc/shells
> 
> diff --git a/package/skeleton-init-common/skeleton-init-common.mk b/package/skeleton-init-common/skeleton-init-common.mk
> index 8228a81..707f1aa 100644
> --- a/package/skeleton-init-common/skeleton-init-common.mk
> +++ b/package/skeleton-init-common/skeleton-init-common.mk
> @@ -79,6 +79,12 @@ define SKELETON_INIT_COMMON_SET_BIN_SH
>  	rm -f $(TARGET_DIR)/bin/sh
>  endef
>  else
> +# Add /bin/sh to /etc/shells otherwise some login tools like dropbear
> +# can reject the user connexion. See man shells.
> +define SKELETON_INIT_COMMON_ADD_SH_TO_SHELLS
> +	grep -qsE '^/bin/sh' $(TARGET_DIR)/etc/shells \
> +		|| echo "/bin/sh" >> $(TARGET_DIR)/etc/shells
> +endef
>  ifneq ($(SKELETON_INIT_COMMON_BIN_SH),)
>  define SKELETON_INIT_COMMON_SET_BIN_SH
>  	ln -sf $(SKELETON_INIT_COMMON_BIN_SH) $(TARGET_DIR)/bin/sh
> @@ -86,5 +92,6 @@ endef
>  endif
>  endif
>  SKELETON_INIT_COMMON_TARGET_FINALIZE_HOOKS += SKELETON_INIT_COMMON_SET_BIN_SH
> +SKELETON_INIT_COMMON_POST_INSTALL_TARGET_HOOKS += SKELETON_INIT_COMMON_ADD_SH_TO_SHELLS

Rgister your new hook right after it's defined.

The existing one is registered after the if-block, becasue it is the
same hook-name for the two cases of the condition, b ut your new hook is
only defined in the else case, so register it there.

Regards,
Yann E. MORIN.

>  $(eval $(generic-package))
> diff --git a/system/skeleton/etc/shells b/system/skeleton/etc/shells
> new file mode 100644
> index 0000000..b5fd584
> --- /dev/null
> +++ b/system/skeleton/etc/shells
> @@ -0,0 +1 @@
> +# /etc/shells: valid login shells
> -- 
> 2.7.4
> 
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
Peter Korsgaard Jan. 15, 2018, 2:41 p.m. UTC | #2
>>>>> "Romain" == Romain Naour <romain.naour@smile.fr> writes:

 > Add the default shell /bin/sh to /etc/shells only if BR2_SYSTEM_BIN_SH_NONE
 > is not selected.

 > Add an empty /etc/shells in the rootfs skeleton.

Is there any specific reason to have an empty /etc/shells?

It is a bit noisy to have this extra file in the BIN_SH_NONE case, and
it afaik changes behaviour (E.G. getusershell() will return default
values if there is no /etc/shells, but will now presumably return the
empty string).
Yann E. MORIN Jan. 15, 2018, 5:06 p.m. UTC | #3
Peter, All,

On 2018-01-15 15:41 +0100, Peter Korsgaard spake thusly:
> >>>>> "Romain" == Romain Naour <romain.naour@smile.fr> writes:
>  > Add the default shell /bin/sh to /etc/shells only if BR2_SYSTEM_BIN_SH_NONE
>  > is not selected.
> 
>  > Add an empty /etc/shells in the rootfs skeleton.
> 
> Is there any specific reason to have an empty /etc/shells?

In fact, I don't see the point of an empty one, indeed...

> It is a bit noisy to have this extra file in the BIN_SH_NONE case, and
> it afaik changes behaviour (E.G. getusershell() will return default
> values if there is no /etc/shells, but will now presumably return the
> empty string).

Woah.. I did not know about getusershell(), but its API is ugly... :-/

Regards,
Yann E. MORIN.
diff mbox series

Patch

diff --git a/package/skeleton-init-common/skeleton-init-common.mk b/package/skeleton-init-common/skeleton-init-common.mk
index 8228a81..707f1aa 100644
--- a/package/skeleton-init-common/skeleton-init-common.mk
+++ b/package/skeleton-init-common/skeleton-init-common.mk
@@ -79,6 +79,12 @@  define SKELETON_INIT_COMMON_SET_BIN_SH
 	rm -f $(TARGET_DIR)/bin/sh
 endef
 else
+# Add /bin/sh to /etc/shells otherwise some login tools like dropbear
+# can reject the user connexion. See man shells.
+define SKELETON_INIT_COMMON_ADD_SH_TO_SHELLS
+	grep -qsE '^/bin/sh' $(TARGET_DIR)/etc/shells \
+		|| echo "/bin/sh" >> $(TARGET_DIR)/etc/shells
+endef
 ifneq ($(SKELETON_INIT_COMMON_BIN_SH),)
 define SKELETON_INIT_COMMON_SET_BIN_SH
 	ln -sf $(SKELETON_INIT_COMMON_BIN_SH) $(TARGET_DIR)/bin/sh
@@ -86,5 +92,6 @@  endef
 endif
 endif
 SKELETON_INIT_COMMON_TARGET_FINALIZE_HOOKS += SKELETON_INIT_COMMON_SET_BIN_SH
+SKELETON_INIT_COMMON_POST_INSTALL_TARGET_HOOKS += SKELETON_INIT_COMMON_ADD_SH_TO_SHELLS
 
 $(eval $(generic-package))
diff --git a/system/skeleton/etc/shells b/system/skeleton/etc/shells
new file mode 100644
index 0000000..b5fd584
--- /dev/null
+++ b/system/skeleton/etc/shells
@@ -0,0 +1 @@ 
+# /etc/shells: valid login shells