Ignore the SUDO_CONV_PROMPT_ECHO_OK flag when echo is enabled.

This was preventing a match of SUDO_CONV_PROMPT_ECHO_ON which
resulted in a masked password instead of an echoed one.
This commit is contained in:
Todd C. Miller
2015-10-06 15:21:41 -06:00
parent 2afb2f2048
commit e91a10ce45

View File

@@ -45,28 +45,28 @@ int
sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[], sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
struct sudo_conv_reply replies[], struct sudo_conv_callback *callback) struct sudo_conv_reply replies[], struct sudo_conv_callback *callback)
{ {
struct sudo_conv_reply *repl;
const struct sudo_conv_message *msg;
char *pass; char *pass;
int n, flags = tgetpass_flags; int n;
const int conv_debug_instance = sudo_debug_get_active_instance(); const int conv_debug_instance = sudo_debug_get_active_instance();
sudo_debug_set_active_instance(sudo_debug_instance); sudo_debug_set_active_instance(sudo_debug_instance);
for (n = 0; n < num_msgs; n++) { for (n = 0; n < num_msgs; n++) {
msg = &msgs[n]; const struct sudo_conv_message *msg = &msgs[n];
repl = &replies[n]; struct sudo_conv_reply *repl = &replies[n];
int flags = tgetpass_flags;
switch (msg->msg_type & 0xff) { switch (msg->msg_type & 0xff) {
case SUDO_CONV_PROMPT_ECHO_ON: case SUDO_CONV_PROMPT_ECHO_ON:
SET(flags, TGP_ECHO);
goto read_pass;
case SUDO_CONV_PROMPT_MASK: case SUDO_CONV_PROMPT_MASK:
if (msg->msg_type == SUDO_CONV_PROMPT_ECHO_ON) SET(flags, TGP_MASK);
SET(flags, TGP_ECHO);
else
SET(flags, TGP_MASK);
/* FALLTHROUGH */ /* FALLTHROUGH */
case SUDO_CONV_PROMPT_ECHO_OFF: case SUDO_CONV_PROMPT_ECHO_OFF:
if (ISSET(msg->msg_type, SUDO_CONV_PROMPT_ECHO_OK)) if (ISSET(msg->msg_type, SUDO_CONV_PROMPT_ECHO_OK))
SET(flags, TGP_NOECHO_TRY); SET(flags, TGP_NOECHO_TRY);
read_pass:
/* Read the password unless interrupted. */ /* Read the password unless interrupted. */
pass = tgetpass(msg->msg, msg->timeout, flags, callback); pass = tgetpass(msg->msg, msg->timeout, flags, callback);
if (pass == NULL) if (pass == NULL)
@@ -96,7 +96,7 @@ sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
err: err:
/* Zero and free allocated memory and return an error. */ /* Zero and free allocated memory and return an error. */
do { do {
repl = &replies[n]; struct sudo_conv_reply *repl = &replies[n];
if (repl->reply != NULL) { if (repl->reply != NULL) {
memset_s(repl->reply, SUDO_CONV_REPL_MAX, 0, strlen(repl->reply)); memset_s(repl->reply, SUDO_CONV_REPL_MAX, 0, strlen(repl->reply));
free(repl->reply); free(repl->reply);