Browse Source

termux-tools: do not print motd on OpenSSH login when config PrintMotd=no

Now OpenSSH will not print motd on its own which may result in duplicate.
Instead it will control the login script via environment variable.

Fixes https://github.com/termux/termux-packages/issues/3941.
android-5
Leonid Plyushch 6 years ago
parent
commit
87c257e0c4
  1. 5
      packages/openssh/build.sh
  2. 44
      packages/openssh/session.c.patch
  3. 2
      packages/termux-tools/build.sh
  4. 5
      packages/termux-tools/login

5
packages/openssh/build.sh

@ -2,7 +2,7 @@ TERMUX_PKG_HOMEPAGE=https://www.openssh.com/
TERMUX_PKG_DESCRIPTION="Secure shell for logging into a remote machine" TERMUX_PKG_DESCRIPTION="Secure shell for logging into a remote machine"
TERMUX_PKG_LICENSE="BSD" TERMUX_PKG_LICENSE="BSD"
TERMUX_PKG_VERSION=8.0p1 TERMUX_PKG_VERSION=8.0p1
TERMUX_PKG_REVISION=3 TERMUX_PKG_REVISION=4
TERMUX_PKG_SHA256=bd943879e69498e8031eb6b7f44d08cdc37d59a7ab689aa0b437320c3481fd68 TERMUX_PKG_SHA256=bd943879e69498e8031eb6b7f44d08cdc37d59a7ab689aa0b437320c3481fd68
TERMUX_PKG_SRCURL=https://fastly.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${TERMUX_PKG_VERSION}.tar.gz TERMUX_PKG_SRCURL=https://fastly.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_DEPENDS="libandroid-support, ldns, openssl, libedit, libutil, termux-auth, krb5, zlib" TERMUX_PKG_DEPENDS="libandroid-support, ldns, openssl, libedit, libutil, termux-auth, krb5, zlib"
@ -68,9 +68,8 @@ termux_step_post_configure() {
} }
termux_step_post_make_install() { termux_step_post_make_install() {
# "PrintMotd no" is due to our login program already showing it.
# OpenSSH 7.0 disabled ssh-dss by default, keep it for a while in Termux: # OpenSSH 7.0 disabled ssh-dss by default, keep it for a while in Termux:
echo -e "PrintMotd no\nPasswordAuthentication yes\nPubkeyAcceptedKeyTypes +ssh-dss\nSubsystem sftp $TERMUX_PREFIX/libexec/sftp-server" > $TERMUX_PREFIX/etc/ssh/sshd_config echo -e "PrintMotd yes\nPasswordAuthentication yes\nPubkeyAcceptedKeyTypes +ssh-dss\nSubsystem sftp $TERMUX_PREFIX/libexec/sftp-server" > $TERMUX_PREFIX/etc/ssh/sshd_config
printf "PubkeyAcceptedKeyTypes +ssh-dss\nSendEnv LANG\n" > $TERMUX_PREFIX/etc/ssh/ssh_config printf "PubkeyAcceptedKeyTypes +ssh-dss\nSendEnv LANG\n" > $TERMUX_PREFIX/etc/ssh/ssh_config
install -Dm700 $TERMUX_PKG_BUILDER_DIR/source-ssh-agent.sh $TERMUX_PREFIX/bin/source-ssh-agent install -Dm700 $TERMUX_PKG_BUILDER_DIR/source-ssh-agent.sh $TERMUX_PREFIX/bin/source-ssh-agent
install -Dm700 $TERMUX_PKG_BUILDER_DIR/ssh-with-agent.sh $TERMUX_PREFIX/bin/ssha install -Dm700 $TERMUX_PKG_BUILDER_DIR/ssh-with-agent.sh $TERMUX_PREFIX/bin/ssha

44
packages/openssh/session.c.patch

@ -1,6 +1,6 @@
diff -u -r ../openssh-8.0p1/session.c ./session.c diff -uNr openssh-8.0p1/session.c openssh-8.0p1.mod/session.c
--- ../openssh-8.0p1/session.c 2019-04-17 22:52:57.000000000 +0000 --- openssh-8.0p1/session.c 2019-04-18 01:52:57.000000000 +0300
+++ ./session.c 2019-04-18 06:48:19.351575794 +0000 +++ openssh-8.0p1.mod/session.c 2019-09-06 01:41:30.581023746 +0300
@@ -197,7 +197,7 @@ @@ -197,7 +197,7 @@
temporarily_use_uid(pw); temporarily_use_uid(pw);
@ -19,16 +19,34 @@ diff -u -r ../openssh-8.0p1/session.c ./session.c
if ((fd = mkstemp(auth_info_file)) == -1) { if ((fd = mkstemp(auth_info_file)) == -1) {
error("%s: mkstemp: %s", __func__, strerror(errno)); error("%s: mkstemp: %s", __func__, strerror(errno));
goto out; goto out;
@@ -803,7 +803,7 @@ @@ -799,6 +799,11 @@
char buf[256];
if (options.print_motd) {
+#ifdef __ANDROID__
+ // Normally this environment variable should be already unset, but
+ // doing this anyway.
+ unsetenv("TERMUX_HUSHLOGIN");
+#else
#ifdef HAVE_LOGIN_CAP
f = fopen(login_getcapstr(lc, "welcome", "/etc/motd", f = fopen(login_getcapstr(lc, "welcome", "/etc/motd",
"/etc/motd"), "r"); "/etc/motd"), "r");
#else @@ -810,7 +815,14 @@
- f = fopen("/etc/motd", "r"); fputs(buf, stdout);
+ f = fopen("@TERMUX_PREFIX@/etc/motd", "r"); fclose(f);
#endif }
if (f) { +#endif
while (fgets(buf, sizeof(buf), f)) }
@@ -1052,11 +1052,13 @@ +#ifdef __ANDROID__
+ else {
+ // Tell Termux login script not to display motd.
+ setenv("TERMUX_HUSHLOGIN", "1", 1);
+ }
+#endif
}
@@ -1052,11 +1064,13 @@
# endif /* HAVE_CYGWIN */ # endif /* HAVE_CYGWIN */
#endif /* HAVE_LOGIN_CAP */ #endif /* HAVE_LOGIN_CAP */
@ -42,12 +60,12 @@ diff -u -r ../openssh-8.0p1/session.c ./session.c
/* Normal systems set SHELL by default. */ /* Normal systems set SHELL by default. */
child_set_env(&env, &envsize, "SHELL", shell); child_set_env(&env, &envsize, "SHELL", shell);
@@ -1100,6 +1102,15 @@ @@ -1100,6 +1114,15 @@
auth_sock_name); auth_sock_name);
+#ifdef __ANDROID__ +#ifdef __ANDROID__
+ char const* envs_to_keep[] = {"LD_LIBRARY_PATH", "PATH", "ANDROID_ROOT", "ANDROID_DATA", "EXTERNAL_STORAGE", "LANG", "PREFIX", "TMPDIR"}; + char const* envs_to_keep[] = {"LD_LIBRARY_PATH", "PATH", "ANDROID_ROOT", "ANDROID_DATA", "EXTERNAL_STORAGE", "LANG", "PREFIX", "TERMUX_HUSHLOGIN", "TMPDIR"};
+ for (i = 0; i < (sizeof(envs_to_keep) / sizeof(envs_to_keep[0])); i++) { + for (i = 0; i < (sizeof(envs_to_keep) / sizeof(envs_to_keep[0])); i++) {
+ char const* env_to_keep_name = envs_to_keep[i]; + char const* env_to_keep_name = envs_to_keep[i];
+ char const* env_to_keep_value = getenv(env_to_keep_name); + char const* env_to_keep_value = getenv(env_to_keep_name);

2
packages/termux-tools/build.sh

@ -1,7 +1,7 @@
TERMUX_PKG_HOMEPAGE=https://termux.com/ TERMUX_PKG_HOMEPAGE=https://termux.com/
TERMUX_PKG_DESCRIPTION="Basic system tools for Termux" TERMUX_PKG_DESCRIPTION="Basic system tools for Termux"
TERMUX_PKG_LICENSE="GPL-3.0" TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_VERSION=0.69 TERMUX_PKG_VERSION=0.70
TERMUX_PKG_SKIP_SRC_EXTRACT=true TERMUX_PKG_SKIP_SRC_EXTRACT=true
TERMUX_PKG_PLATFORM_INDEPENDENT=true TERMUX_PKG_PLATFORM_INDEPENDENT=true
TERMUX_PKG_ESSENTIAL=true TERMUX_PKG_ESSENTIAL=true

5
packages/termux-tools/login

@ -1,7 +1,10 @@
#!/data/data/com.termux/files/usr/bin/sh #!/data/data/com.termux/files/usr/bin/sh
if [ $# = 0 ] && [ -f $PREFIX/etc/motd ] && [ ! -f ~/.hushlogin ]; then if [ $# = 0 ] && [ -f $PREFIX/etc/motd ] && [ ! -f ~/.hushlogin ] && [ -z "$TERMUX_HUSHLOGIN" ]; then
cat $PREFIX/etc/motd cat $PREFIX/etc/motd
else
# This variable shouldn't be kept set.
unset TERMUX_HUSHLOGIN
fi fi
if [ -G ~/.termux/shell ]; then if [ -G ~/.termux/shell ]; then

Loading…
Cancel
Save