From 345044121bc4e8977a22d6235d31df4b2114a240 Mon Sep 17 00:00:00 2001 From: "Andrew G. Morgan" Date: Thu, 11 Oct 2001 04:14:30 +0000 Subject: Relevant BUGIDs: 463984 Purpose of commit: bugfix Commit summary: --------------- The last fix to the conversation function was less than marginal: it didn't actually work! This second commit adds the all important 'return the user's input' bit! Also added some more D() stuff to pam_misc to help locate the problem and finally cleaned up the Makefile in the examples/ directory. I used xsh to do the testing. --- libpam_misc/misc_conv.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'libpam_misc') diff --git a/libpam_misc/misc_conv.c b/libpam_misc/misc_conv.c index fbde3735..c58a597a 100644 --- a/libpam_misc/misc_conv.c +++ b/libpam_misc/misc_conv.c @@ -137,6 +137,8 @@ static char *read_string(int echo, const char *prompt) D(("called with echo='%s', prompt='%s'.", echo ? "ON":"OFF" , prompt)); + input = line; + if (isatty(STDIN_FILENO)) { /* terminal state */ /* is a terminal so record settings and flush it */ @@ -191,27 +193,37 @@ static char *read_string(int echo, const char *prompt) if (expired) { delay = get_delay(); } else if (nc > 0) { /* we got some user input */ + D(("we got some user input")); if (nc > 0 && line[nc-1] == '\n') { /* terminate */ line[--nc] = '\0'; } else { + if (echo) { + fprintf(stderr, "\n"); + } line[nc] = '\0'; } input = x_strdup(line); _pam_overwrite(line); goto cleanexit; /* return malloc()ed string */ + } else if (nc == 0) { /* Ctrl-D */ D(("user did not want to type anything")); input = x_strdup(""); - fprintf(stderr, "\n"); + if (echo) { + fprintf(stderr, "\n"); + } goto cleanexit; /* return malloc()ed "" */ } } } /* getting here implies that the timer expired */ + + D(("the timer appears to have expired")); + input = NULL; _pam_overwrite(line); @@ -222,7 +234,9 @@ static char *read_string(int echo, const char *prompt) (void) tcsetattr(STDIN_FILENO, TCSADRAIN, &term_before); } - return NULL; + D(("returning [%s]", input)); + + return input; } /* end of read_string functions */ @@ -325,8 +339,6 @@ int misc_conv(int num_msg, const struct pam_message **msgm, } } - /* New (0.59+) behavior is to always have a reply - this is - compatable with the X/Open (March 1997) spec. */ *response = reply; reply = NULL; @@ -334,6 +346,8 @@ int misc_conv(int num_msg, const struct pam_message **msgm, failed_conversation: + D(("the conversation failed")); + if (reply) { for (count=0; count