From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1496381000; bh=vVUVJTmWUAQMKOihZIErWo8R6/3qmzkiWYV3AE/+LXo=; h=Date:From:To:Subject:Message-ID:References:In-Reply-To; b=TBqCcIbwVegF/EUBysrb4x4JR98f4OmkGA5cQVpJbJdRc/U0La8Ik7yPDIqpdjO4x Qf9nDQFxn+D5SpHf7jcNGN+bW/bz+0zA+aj3nxnyKSg2gx2+6hVxH6devXp7vGvKCg om15VOnLAykxuyUNH9N5mdL91WiWgBEPcpLqIb6Y= Authentication-Results: smtp1p.mail.yandex.net; dkim=pass header.i=@yandex.ru X-Yandex-Suid-Status: 1 0 Date: Fri, 2 Jun 2017 13:23:19 +0800 From: Vladimir Lomov To: kbd@lists.altlinux.org Message-ID: <20170602052319.GB703@smoon.vl-lomov.ru> References: <20170601145447.GA703@smoon.vl-lomov.ru> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="rJwd6BRFiFCcLxzm" Content-Disposition: inline In-Reply-To: <20170601145447.GA703@smoon.vl-lomov.ru> User-Agent: Mutt/1.8.3 (2017-05-23) X-Mailman-Approved-At: Sat, 03 Jun 2017 02:32:47 +0300 Subject: Re: [kbd] [Enhancement] Add hostname to message on locked screen X-BeenThere: kbd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Linux console tools development discussion List-Id: Linux console tools development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Jun 2017 05:23:24 -0000 Archived-At: List-Archive: --rJwd6BRFiFCcLxzm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --rJwd6BRFiFCcLxzm Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="vlock-message.patch" 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.")); } --rJwd6BRFiFCcLxzm--