X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=loginutils%2Fvlock.c;h=8e3a1ea4b3a0b1646945816f9cc256405521e660;hb=a0898170d876aeeea19eb144556afd05819db450;hp=6f391075b5f9f483680b56c3847c9de727f25805;hpb=dfba741457cc81eb2ed3a9d4c074fbad74aa3249;p=oweals%2Fbusybox.git diff --git a/loginutils/vlock.c b/loginutils/vlock.c index 6f391075b..8e3a1ea4b 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c @@ -1,24 +1,12 @@ /* vi: set sw=4 ts=4: */ + /* * vlock implementation for busybox * * Copyright (C) 2000 by spoon * Written by spoon * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ /* Shoutz to Michael K. Johnson , author of the @@ -28,31 +16,16 @@ /* Fixed by Erik Andersen to do passwords the tinylogin way... * It now works with md5, sha1, etc passwords. */ -#include -#include +#include "libbb.h" #include -#include -#include -#include -#include -#include -#include -#include - -#include "busybox.h" - -static struct passwd *pw; -static struct vt_mode ovtm; -static struct termios oterm; -static int vfd; -static unsigned long o_lock_all; + +enum { vfd = 3 }; + +/* 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, (unsigned long) !option_mask32 /*!o_lock_all*/); } static void acquire_vt(int signo) @@ -60,34 +33,32 @@ static void acquire_vt(int signo) ioctl(vfd, VT_RELDISP, VT_ACKACQ); } -static void restore_terminal(void) -{ - ioctl(vfd, VT_SETMODE, &ovtm); - 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; + struct termios oterm; + struct vt_mode ovtm; + uid_t uid; + struct passwd *pw; + + 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(argv, "a"); - vfd = bb_xopen(CURRENT_TTY, O_RDWR); - - if (ioctl(vfd, VT_GETMODE, &vtm) < 0) { - bb_perror_msg_and_die("VT_GETMODE"); - } + /* Avoid using statics - use constant fd */ + xmove_fd(xopen(CURRENT_TTY, O_RDWR), vfd); + xioctl(vfd, VT_GETMODE, &vtm); /* mask a bunch of signals */ sigprocmask(SIG_SETMASK, NULL, &sig); @@ -130,22 +101,17 @@ 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", + option_mask32 /*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; -} -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/ + ioctl(vfd, VT_SETMODE, &ovtm); + tcsetattr(STDIN_FILENO, TCSANOW, &oterm); + fflush_stdout_and_exit(0); +}