Linux console tools development discussion
 help / color / mirror / Atom feed
* [kbd] [Enhancement] Add hostname to message on locked screen
@ 2017-06-01 14:54 Vladimir Lomov
  2017-06-02  5:23 ` Vladimir Lomov
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Lomov @ 2017-06-01 14:54 UTC (permalink / raw)
  To: kbd

[-- Attachment #1: Type: text/plain, Size: 417 bytes --]

Hello,

I'd like to propose small enhancement: to add to the message on locked
screen information about current host. May be it is worth to store the
same information in syslog, I don't have any opinion.

I attached small patch that works (basically) on my system (Archlinux
x86_64).

---
WBR, Vladimir Lomov

-- 
I can give you my word, but I know what it's worth and you don't.
		-- Nero Wolfe, "Over My Dead Body"

[-- Attachment #2: kbd-vlock.patch --]
[-- Type: text/x-diff, Size: 829 bytes --]

diff --git a/src/vlock/auth.c b/src/vlock/auth.c
index 25efb5e..f0200eb 100644
--- a/src/vlock/auth.c
+++ b/src/vlock/auth.c
@@ -60,6 +60,7 @@ do_account_password_management(pam_handle_t *pamh)
 int get_password(pam_handle_t *pamh, const char *username, const char *tty)
 {
 	uid_t uid = getuid();
+	char *hostname = getenv("HOSTNAME");
 
 	for (;;) {
 		int rc;
@@ -83,8 +84,8 @@ int get_password(pam_handle_t *pamh, const char *username, const char *tty)
 			printf(_("The entire console display is now completely locked by %s.\n"),
 			       username);
 		} else {
-			printf(_("The %s is now locked by %s.\n"), tty,
-			       username);
+			printf(_("The %s is now locked by %s on %s.\n"), tty,
+			       username, hostname);
 			if (is_vt)
 				puts(_("Use Alt-function keys to switch to other virtual consoles."));
 		}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [kbd] [Enhancement] Add hostname to message on locked screen
  2017-06-01 14:54 [kbd] [Enhancement] Add hostname to message on locked screen Vladimir Lomov
@ 2017-06-02  5:23 ` Vladimir Lomov
  0 siblings, 0 replies; 2+ messages in thread
From: Vladimir Lomov @ 2017-06-02  5:23 UTC (permalink / raw)
  To: kbd

[-- Attachment #1: Type: text/plain, Size: 792 bytes --]

Hello,
** Vladimir Lomov [2017-06-01 22:54:47 +0800]:

> Hello,
> 
> I'd like to propose small enhancement: to add to the message on locked
> screen information about current host. May be it is worth to store the
> same information in syslog, I don't have any opinion.
> 
> I attached small patch that works (basically) on my system (Archlinux
> x86_64).

I was too optimistic. On one host patched vlock works as expected but on
other one it output (null) instead of host name. Seems that my
assumption that env. variable HOSTNAME is always set is wrong, esp.
according to environ(7). I prepared another patch that should work in
most cases.

---
WBR, Vladimir Lomov

-- 
[Wisdom] is a tree of life to those laying
hold of her, making happy each one holding her fast.
		-- Proverbs 3:18, NSV

[-- Attachment #2: vlock-message.patch --]
[-- Type: text/x-diff, Size: 1137 bytes --]

diff --git a/src/vlock/auth.c b/src/vlock/auth.c
index 25efb5e..cb8f057 100644
--- a/src/vlock/auth.c
+++ b/src/vlock/auth.c
@@ -37,6 +37,8 @@
 #define LONG_DELAY 10
 /* Delay after other PAM errors, in seconds. */
 #define SHORT_DELAY 1
+/* Max length of hostname. */
+#define HOSTNAME_MAX 256
 
 static int
 do_account_password_management(pam_handle_t *pamh)
@@ -60,6 +62,9 @@ do_account_password_management(pam_handle_t *pamh)
 int get_password(pam_handle_t *pamh, const char *username, const char *tty)
 {
 	uid_t uid = getuid();
+	char hostname[HOSTNAME_MAX];
+	hostname[HOSTNAME_MAX - 1] = '\0';
+	gethostname(hostname, HOSTNAME_MAX - 1);
 
 	for (;;) {
 		int rc;
@@ -83,8 +88,8 @@ int get_password(pam_handle_t *pamh, const char *username, const char *tty)
 			printf(_("The entire console display is now completely locked by %s.\n"),
 			       username);
 		} else {
-			printf(_("The %s is now locked by %s.\n"), tty,
-			       username);
+			printf(_("The %s on %s is now locked by %s.\n"), tty,
+			       hostname, username);
 			if (is_vt)
 				puts(_("Use Alt-function keys to switch to other virtual consoles."));
 		}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-02  5:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-01 14:54 [kbd] [Enhancement] Add hostname to message on locked screen Vladimir Lomov
2017-06-02  5:23 ` Vladimir Lomov

Linux console tools development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/kbd/0 kbd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kbd kbd/ http://lore.altlinux.org/kbd \
		kbd@lists.altlinux.org kbd@lists.altlinux.ru kbd@lists.altlinux.com
	public-inbox-index kbd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.kbd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git