mirror of
https://github.com/sheumann/hush.git
synced 2024-11-05 06:07:00 +00:00
82b1429966
function old new delta bb_ask - 355 +355 mkpasswd_main - 296 +296 .rodata 121746 121847 +101 packed_usage 24632 24689 +57 static.methods - 21 +21 gmatch 229 248 +19 bb_ask_stdin - 11 +11 applet_names 1949 1958 +9 applet_main 1172 1176 +4 sulogin_main 503 505 +2 applet_nameofs 586 588 +2 sha256_hash 329 327 -2 correct_password 208 206 -2 parse_command 1442 1439 -3 get_cred_or_die 145 141 -4 passwd_main 1054 1044 -10 bb_askpass 348 - -348 ------------------------------------------------------------------------------ (add/remove: 4/1 grow/shrink: 7/5 up/down: 877/-369) Total: 508 bytes
80 lines
1.7 KiB
C
80 lines
1.7 KiB
C
/* vi: set sw=4 ts=4: */
|
|
/*
|
|
* Ask for a password
|
|
* I use a static buffer in this function. Plan accordingly.
|
|
*
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
|
*
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
|
*/
|
|
|
|
#include "libbb.h"
|
|
|
|
/* do nothing signal handler */
|
|
static void askpass_timeout(int UNUSED_PARAM ignore)
|
|
{
|
|
}
|
|
|
|
char* FAST_FUNC bb_ask_stdin(const char *prompt)
|
|
{
|
|
return bb_ask(STDIN_FILENO, 0, prompt);
|
|
}
|
|
char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
|
|
{
|
|
/* Was static char[BIGNUM] */
|
|
enum { sizeof_passwd = 128 };
|
|
static char *passwd;
|
|
|
|
char *ret;
|
|
int i;
|
|
struct sigaction sa, oldsa;
|
|
struct termios tio, oldtio;
|
|
|
|
if (!passwd)
|
|
passwd = xmalloc(sizeof_passwd);
|
|
memset(passwd, 0, sizeof_passwd);
|
|
|
|
tcgetattr(fd, &oldtio);
|
|
tcflush(fd, TCIFLUSH);
|
|
tio = oldtio;
|
|
tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
|
|
tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP);
|
|
tcsetattr_stdin_TCSANOW(&tio);
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
/* sa.sa_flags = 0; - no SA_RESTART! */
|
|
/* SIGINT and SIGALRM will interrupt read below */
|
|
sa.sa_handler = askpass_timeout;
|
|
sigaction(SIGINT, &sa, &oldsa);
|
|
if (timeout) {
|
|
sigaction_set(SIGALRM, &sa);
|
|
alarm(timeout);
|
|
}
|
|
|
|
fputs(prompt, stdout);
|
|
fflush(stdout);
|
|
ret = NULL;
|
|
/* On timeout or Ctrl-C, read will hopefully be interrupted,
|
|
* and we return NULL */
|
|
if (read(fd, passwd, sizeof_passwd - 1) > 0) {
|
|
ret = passwd;
|
|
i = 0;
|
|
/* Last byte is guaranteed to be 0
|
|
(read did not overwrite it) */
|
|
do {
|
|
if (passwd[i] == '\r' || passwd[i] == '\n')
|
|
passwd[i] = '\0';
|
|
} while (passwd[i++]);
|
|
}
|
|
|
|
if (timeout) {
|
|
alarm(0);
|
|
}
|
|
sigaction_set(SIGINT, &oldsa);
|
|
|
|
tcsetattr_stdin_TCSANOW(&oldtio);
|
|
bb_putchar('\n');
|
|
fflush(stdout);
|
|
return ret;
|
|
}
|