From: Werner Fink <werner@suse.de>
To: util-linux@vger.kernel.org
Cc: Karel Zak <kzak@redhat.com>, Werner Fink <werner@suse.de>
Subject: [PATCH 3/5] sulogin: use alarm function to indicate if a timeout occurs
Date: Fri, 7 Dec 2012 09:00:56 +0100 [thread overview]
Message-ID: <1354867258-14206-3-git-send-email-werner@suse.de> (raw)
In-Reply-To: <1354867258-14206-1-git-send-email-werner@suse.de>
A small change to use the alarm handler to indicate if a timeout occurs.
Signed-off-by: Werner Fink <werner@suse.de>
---
login-utils/sulogin.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git login-utils/sulogin.c login-utils/sulogin.c
index db783a2..dbcc855 100644
--- login-utils/sulogin.c
+++ login-utils/sulogin.c
@@ -8,6 +8,7 @@
*
* Copyright (C) 1998-2003 Miquel van Smoorenburg.
* Copyright (C) 2012 Karel Zak <kzak@redhat.com>
+ * Copyright (C) 2012 Werner Fink <werner@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -60,12 +61,15 @@ struct sigaction saved_sigint;
struct sigaction saved_sigtstp;
struct sigaction saved_sigquit;
+static volatile sig_atomic_t alarm_rised;
+
/*
* Called at timeout.
*/
static void alrm_handler(int sig __attribute__((unused)))
{
- return;
+ /* Timeout expired */
+ alarm_rised++;
}
static void mask_signal(int signal, void (*handler)(int),
@@ -594,17 +598,27 @@ int main(int argc, char **argv)
* Ask for the password.
*/
while (pwd) {
+ int failed = 0;
if ((p = getpasswd(pwd->pw_passwd)) == NULL)
break;
if (pwd->pw_passwd[0] == 0 ||
- strcmp(crypt(p, pwd->pw_passwd), pwd->pw_passwd) == 0)
+ strcmp(crypt(p, pwd->pw_passwd), pwd->pw_passwd) == 0) {
sushell(pwd);
+ failed++;
+ }
mask_signal(SIGQUIT, SIG_IGN, &saved_sigquit);
mask_signal(SIGTSTP, SIG_IGN, &saved_sigtstp);
mask_signal(SIGINT, SIG_IGN, &saved_sigint);
- fprintf(stderr, _("Login incorrect\n\n"));
+ if (failed) {
+ fprintf(stderr, _("Can not execute su shell\n\n"));
+ break;
+ } else
+ fprintf(stderr, _("Login incorrect\n\n"));
}
+ if (alarm_rised)
+ fprintf(stderr, _("Timed out\n\n"));
+
/*
* User pressed Control-D.
*/
--
1.7.10.4
next prev parent reply other threads:[~2012-12-07 8:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-07 8:00 [PATCH 1/5] sulogin: use the linked lists from list.h for consoles list Werner Fink
2012-12-07 8:00 ` [PATCH 2/5] sulogin: make usleep() workaround work Werner Fink
2012-12-18 15:07 ` Karel Zak
2012-12-07 8:00 ` Werner Fink [this message]
2012-12-18 15:15 ` [PATCH 3/5] sulogin: use alarm function to indicate if a timeout occurs Karel Zak
2012-12-07 8:00 ` [PATCH 4/5] sulogin: mount temporary /dev and /proc if not found Werner Fink
2012-12-07 14:17 ` Dave Reisner
2012-12-07 15:49 ` [util-linux] " Dr. Werner Fink
2012-12-07 17:01 ` Dave Reisner
2012-12-07 17:25 ` Dr. Werner Fink
2012-12-10 12:27 ` Werner Fink
2012-12-18 15:23 ` Karel Zak
2012-12-23 4:33 ` Dave Reisner
2012-12-23 21:53 ` Karel Zak
2012-12-10 12:27 ` [PATCH 5/5] sulogin: add multi console feature from SysVinit sulogin Werner Fink
2012-12-18 15:18 ` Karel Zak
2012-12-18 15:17 ` [PATCH 4/5] sulogin: mount temporary /dev and /proc if not found Karel Zak
2012-12-07 8:00 ` [PATCH 5/5] sulogin: add multi console feature from SysVinit sulogin Werner Fink
2012-12-07 10:27 ` Dr. Werner Fink
2012-12-18 15:05 ` [PATCH 1/5] sulogin: use the linked lists from list.h for consoles list Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1354867258-14206-3-git-send-email-werner@suse.de \
--to=werner@suse.de \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox