[PATCH] Don't print motd if .hushlogin exists

Sören Tempel soeren at soeren-tempel.net
Mon Aug 24 18:50:41 UTC 2015


Hi,

I don't know if you are interested at all in this, but I wrote a little
patch which modifies login(1) to ensure that the message of the day
isn't printed if a file called '.hushlogin' exists in the users home
directory.

This is the default behaviour of many login implementations including
OpenBSDs, FreeBSDs, and pkg-shadows implementation. As I said I don't
know if you are interested in it but I personally find it somewhat
useful.

I am also not particularly good at C but the patch works for me.

Sören.
-------------- next part --------------
>From e15ac2903cc769e17dd2269753ebc08d7cda93c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git at soeren-tempel.net>
Date: Wed, 19 Aug 2015 20:58:06 +0200
Subject: [PATCH 49/53] login: don't print motd if .hushlogin exists in users
 home

The .hushlogin file is already used by a bunch of other implementations
such as pkg-shadow or OpenBSDs and FreeBSDs login implementation.

Its purpose is quite simple, if the file exists the message of the day
isn't printed.
---
 loginutils/login.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/loginutils/login.c b/loginutils/login.c
index b9d9103..7a922fd 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -245,11 +245,13 @@ int login_main(int argc UNUSED_PARAM, char **argv)
 	int run_by_root;
 	unsigned opt;
 	int count = 0;
+	struct stat st;
 	struct passwd *pw;
 	char *opt_host = NULL;
 	char *opt_user = opt_user; /* for compiler */
 	char *full_tty;
 	char *short_tty;
+	char *hushlogin;
 	IF_SELINUX(security_context_t user_sid = NULL;)
 #if ENABLE_PAM
 	int pamret;
@@ -489,7 +491,9 @@ int login_main(int argc UNUSED_PARAM, char **argv)
 	}
 #endif
 
-	motd();
+	hushlogin = concat_path_file(pw->pw_dir, ".hushlogin");
+	if (stat(hushlogin, &st) != 0)
+		motd();
 
 	if (pw->pw_uid == 0)
 		syslog(LOG_INFO, "root login%s", fromhost);
-- 
2.5.0



More information about the busybox mailing list