libbb: rename bb_ask -> bb_ask_noecho, bb_ask_confirmation -> bb_ask_y_confirmation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
2f094ae821
commit
77cb6b99a4
@ -101,7 +101,7 @@ int mv_main(int argc, char **argv)
|
||||
if (fprintf(stderr, "mv: overwrite '%s'? ", dest) < 0) {
|
||||
goto RET_1; /* Ouch! fprintf failed! */
|
||||
}
|
||||
if (!bb_ask_confirmation()) {
|
||||
if (!bb_ask_y_confirmation()) {
|
||||
goto RET_0;
|
||||
}
|
||||
}
|
||||
|
@ -1408,11 +1408,11 @@ extern int set_loop(char **devname, const char *file, unsigned long long offset,
|
||||
#define BB_LO_FLAGS_READ_ONLY 1
|
||||
#define BB_LO_FLAGS_AUTOCLEAR 4
|
||||
|
||||
/* Like bb_ask below, but asks on stdin with no timeout. */
|
||||
char *bb_ask_stdin(const char * prompt) FAST_FUNC;
|
||||
/* Like bb_ask_noecho below, but asks on stdin with no timeout. */
|
||||
char *bb_ask_noecho_stdin(const char *prompt) FAST_FUNC;
|
||||
//TODO: pass buf pointer or return allocated buf (avoid statics)?
|
||||
char *bb_ask(const int fd, int timeout, const char * prompt) FAST_FUNC;
|
||||
int bb_ask_confirmation(void) FAST_FUNC;
|
||||
char *bb_ask_noecho(const int fd, int timeout, const char *prompt) FAST_FUNC;
|
||||
int bb_ask_y_confirmation(void) FAST_FUNC;
|
||||
|
||||
/* Returns -1 if input is invalid. current_mode is a base for e.g. "u+rw" */
|
||||
int bb_parse_mode(const char* s, unsigned cur_mode) FAST_FUNC;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* bb_ask_confirmation implementation for busybox
|
||||
* bb_ask_y_confirmation implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
|
||||
*
|
||||
@ -11,7 +11,7 @@
|
||||
/* Read a line from stdin. If the first non-whitespace char is 'y' or 'Y',
|
||||
* return 1. Otherwise return 0.
|
||||
*/
|
||||
int FAST_FUNC bb_ask_confirmation(void)
|
||||
int FAST_FUNC bb_ask_y_confirmation(void)
|
||||
{
|
||||
char first = 0;
|
||||
int c;
|
||||
|
@ -13,11 +13,11 @@ static void askpass_timeout(int UNUSED_PARAM ignore)
|
||||
{
|
||||
}
|
||||
|
||||
char* FAST_FUNC bb_ask_stdin(const char *prompt)
|
||||
char* FAST_FUNC bb_ask_noecho_stdin(const char *prompt)
|
||||
{
|
||||
return bb_ask(STDIN_FILENO, 0, prompt);
|
||||
return bb_ask_noecho(STDIN_FILENO, 0, prompt);
|
||||
}
|
||||
char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
|
||||
char* FAST_FUNC bb_ask_noecho(const int fd, int timeout, const char *prompt)
|
||||
{
|
||||
/* Was static char[BIGNUM] */
|
||||
enum { sizeof_passwd = 128 };
|
||||
|
@ -48,7 +48,7 @@ static int ask_and_unlink(const char *dest, int flags)
|
||||
// (No "opening without O_EXCL", no "unlink only if -f")
|
||||
// Or else we will end up having 3 open()s!
|
||||
fprintf(stderr, "%s: overwrite '%s'? ", applet_name, dest);
|
||||
if (!bb_ask_confirmation())
|
||||
if (!bb_ask_y_confirmation())
|
||||
return 0; /* not allowed to overwrite */
|
||||
}
|
||||
if (unlink(dest) < 0) {
|
||||
|
@ -106,7 +106,7 @@ int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw,
|
||||
if (!pw_pass[0]) /* empty password field? */
|
||||
return CHECKPASS_PW_HAS_EMPTY_PASSWORD;
|
||||
|
||||
plaintext = bb_ask(STDIN_FILENO, timeout, prompt);
|
||||
plaintext = bb_ask_noecho(STDIN_FILENO, timeout, prompt);
|
||||
if (!plaintext) {
|
||||
/* EOF (such as ^D) or error (such as ^C) or timeout */
|
||||
return -1;
|
||||
|
@ -41,7 +41,7 @@ int FAST_FUNC remove_file(const char *path, int flags)
|
||||
) {
|
||||
fprintf(stderr, "%s: descend into directory '%s'? ", applet_name,
|
||||
path);
|
||||
if (!bb_ask_confirmation())
|
||||
if (!bb_ask_y_confirmation())
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ int FAST_FUNC remove_file(const char *path, int flags)
|
||||
|
||||
if (flags & FILEUTILS_INTERACTIVE) {
|
||||
fprintf(stderr, "%s: remove directory '%s'? ", applet_name, path);
|
||||
if (!bb_ask_confirmation())
|
||||
if (!bb_ask_y_confirmation())
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ int FAST_FUNC remove_file(const char *path, int flags)
|
||||
|| (flags & FILEUTILS_INTERACTIVE)
|
||||
) {
|
||||
fprintf(stderr, "%s: remove '%s'? ", applet_name, path);
|
||||
if (!bb_ask_confirmation())
|
||||
if (!bb_ask_y_confirmation())
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Only mkpasswd, and only from tty, prompts.
|
||||
* Otherwise it is a plain read. */
|
||||
password = (ENABLE_MKPASSWD && isatty(STDIN_FILENO) && applet_name[0] == 'm')
|
||||
? bb_ask_stdin("Password: ")
|
||||
? bb_ask_noecho_stdin("Password: ")
|
||||
: xmalloc_fgetline(stdin)
|
||||
;
|
||||
/* may still be NULL on EOF/error */
|
||||
|
@ -52,7 +52,7 @@ static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo
|
||||
if (myuid != 0 && pw->pw_passwd[0]) {
|
||||
char *encrypted;
|
||||
|
||||
orig = bb_ask_stdin("Old password: "); /* returns ptr to static */
|
||||
orig = bb_ask_noecho_stdin("Old password: "); /* returns ptr to static */
|
||||
if (!orig)
|
||||
goto err_ret;
|
||||
encrypted = pw_encrypt(orig, pw->pw_passwd, 1); /* returns malloced str */
|
||||
@ -65,11 +65,11 @@ static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(encrypted);
|
||||
}
|
||||
orig = xstrdup(orig); /* or else bb_ask_stdin() will destroy it */
|
||||
newp = bb_ask_stdin("New password: "); /* returns ptr to static */
|
||||
orig = xstrdup(orig); /* or else bb_ask_noecho_stdin() will destroy it */
|
||||
newp = bb_ask_noecho_stdin("New password: "); /* returns ptr to static */
|
||||
if (!newp)
|
||||
goto err_ret;
|
||||
newp = xstrdup(newp); /* we are going to bb_ask_stdin() again, so save it */
|
||||
newp = xstrdup(newp); /* we are going to bb_ask_noecho_stdin() again, so save it */
|
||||
if (ENABLE_FEATURE_PASSWD_WEAK_CHECK
|
||||
&& obscure(orig, newp, pw)
|
||||
&& myuid != 0
|
||||
@ -77,7 +77,7 @@ static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo
|
||||
goto err_ret; /* non-root is not allowed to have weak passwd */
|
||||
}
|
||||
|
||||
cp = bb_ask_stdin("Retype password: ");
|
||||
cp = bb_ask_noecho_stdin("Retype password: ");
|
||||
if (!cp)
|
||||
goto err_ret;
|
||||
if (strcmp(cp, newp) != 0) {
|
||||
|
@ -163,8 +163,8 @@ void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol)
|
||||
void FAST_FUNC get_cred_or_die(int fd)
|
||||
{
|
||||
if (isatty(fd)) {
|
||||
G.user = xstrdup(bb_ask(fd, /* timeout: */ 0, "User: "));
|
||||
G.pass = xstrdup(bb_ask(fd, /* timeout: */ 0, "Password: "));
|
||||
G.user = xstrdup(bb_ask_noecho(fd, /* timeout: */ 0, "User: "));
|
||||
G.pass = xstrdup(bb_ask_noecho(fd, /* timeout: */ 0, "Password: "));
|
||||
} else {
|
||||
G.user = xmalloc_reads(fd, /* maxsize: */ NULL);
|
||||
G.pass = xmalloc_reads(fd, /* maxsize: */ NULL);
|
||||
|
@ -422,7 +422,7 @@ static void confirm_or_abort(void)
|
||||
{
|
||||
fprintf(stderr, "Continue? [y/N] ");
|
||||
fflush_all();
|
||||
if (!bb_ask_confirmation())
|
||||
if (!bb_ask_y_confirmation())
|
||||
bb_error_msg_and_die("aborting");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user