X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=loginutils%2Fvlock.c;h=06a7169d9b5e444c7b790cfd6e1bb77b2cb60e4d;hb=794687947fe9eb15b2512a0d9645d827348c5f6f;hp=a35f9e0ecbd1ab25d59eb072960001d68643408a;hpb=801ab140132a111e9524371c9b8d425579692389;p=oweals%2Fbusybox.git diff --git a/loginutils/vlock.c b/loginutils/vlock.c index a35f9e0ec..06a7169d9 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c @@ -16,18 +16,8 @@ /* Fixed by Erik Andersen to do passwords the tinylogin way... * It now works with md5, sha1, etc passwords. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "busybox.h" +#include static struct passwd *pw; static struct vt_mode ovtm; @@ -37,10 +27,7 @@ static unsigned long o_lock_all; static void release_vt(int signo) { - if (!o_lock_all) - ioctl(vfd, VT_RELDISP, 1); - else - ioctl(vfd, VT_RELDISP, 0); + ioctl(vfd, VT_RELDISP, !o_lock_all); } static void acquire_vt(int signo) @@ -54,24 +41,26 @@ static void restore_terminal(void) tcsetattr(STDIN_FILENO, TCSANOW, &oterm); } +int vlock_main(int argc, char **argv); int vlock_main(int argc, char **argv) { sigset_t sig; struct sigaction sa; struct vt_mode vtm; struct termios term; + uid_t uid = getuid(); + + pw = getpwuid(uid); + if (pw == NULL) + bb_error_msg_and_die("unknown uid %d", uid); if (argc > 2) { bb_show_usage(); } - o_lock_all = bb_getopt_ulflags (argc, argv, "a"); - - if((pw = getpwuid(getuid())) == NULL) { - bb_error_msg_and_die("Unknown uid %d", getuid()); - } + o_lock_all = getopt32(argc, argv, "a"); - vfd = bb_xopen(CURRENT_TTY, O_RDWR); + vfd = xopen(CURRENT_TTY, O_RDWR); if (ioctl(vfd, VT_GETMODE, &vtm) < 0) { bb_perror_msg_and_die("VT_GETMODE"); @@ -118,14 +107,13 @@ int vlock_main(int argc, char **argv) tcsetattr(STDIN_FILENO, TCSANOW, &term); do { - printf("Virtual Console%s locked.\n%s's ", (o_lock_all) ? "s" : "", pw->pw_name); - fflush(stdout); - if (correct_password (pw)) { + printf("Virtual Console%s locked by %s.\n", (o_lock_all) ? "s" : "", pw->pw_name); + if (correct_password(pw)) { break; } bb_do_delay(FAIL_DELAY); - puts("Password incorrect."); + puts("Password incorrect"); } while (1); restore_terminal(); - return 0; + fflush_stdout_and_exit(0); }