From ba9bf5016669e0b940243c51c62236968119313a Mon Sep 17 00:00:00 2001 From: "Andrew G. Morgan" Date: Wed, 19 Sep 2001 06:18:46 +0000 Subject: Relevant BUGIDs: 449203 Purpose of commit: new support Commit summary: --------------- Include some BSD changes (to the conversation function) and fix a few gcc warnings. --- libpam_misc/misc_conv.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'libpam_misc') diff --git a/libpam_misc/misc_conv.c b/libpam_misc/misc_conv.c index 7d4b1b99..fbde3735 100644 --- a/libpam_misc/misc_conv.c +++ b/libpam_misc/misc_conv.c @@ -57,7 +57,7 @@ void (*pam_binary_handler_free)(void *appdata, pamc_bp_t *prompt_p) /* the following code is used to get text input */ -volatile static int expired=0; +static volatile int expired=0; /* return to the previous signal handling */ static void reset_alarm(struct sigaction *o_ptr) @@ -130,10 +130,11 @@ static int get_delay(void) static char *read_string(int echo, const char *prompt) { struct termios term_before, term_tmp; - char line[INPUTSIZE]; + char line[INPUTSIZE], *input; struct sigaction old_sig; int delay, nc, have_term=0; - + sigset_t oset, nset; + D(("called with echo='%s', prompt='%s'.", echo ? "ON":"OFF" , prompt)); if (isatty(STDIN_FILENO)) { /* terminal state */ @@ -149,6 +150,16 @@ static char *read_string(int echo, const char *prompt) } have_term = 1; + /* + * We make a simple attempt to block TTY signals from terminating + * the conversation without giving PAM a chance to clean up. + */ + + sigemptyset(&nset); + sigaddset(&nset, SIGINT); + sigaddset(&nset, SIGTSTP); + (void) sigprocmask(SIG_BLOCK, &nset, &oset); + } else if (!echo) { D(("")); } @@ -180,7 +191,6 @@ static char *read_string(int echo, const char *prompt) if (expired) { delay = get_delay(); } else if (nc > 0) { /* we got some user input */ - char *input; if (nc > 0 && line[nc-1] == '\n') { /* terminate */ line[--nc] = '\0'; @@ -190,25 +200,46 @@ static char *read_string(int echo, const char *prompt) input = x_strdup(line); _pam_overwrite(line); - return input; /* return malloc()ed string */ + 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"); - break; + goto cleanexit; /* return malloc()ed "" */ } } } /* getting here implies that the timer expired */ - if (have_term) + input = NULL; + _pam_overwrite(line); + + cleanexit: + + if (have_term) { + (void) sigprocmask(SIG_SETMASK, &oset, NULL); (void) tcsetattr(STDIN_FILENO, TCSADRAIN, &term_before); + } - memset(line, 0, INPUTSIZE); /* clean up */ return NULL; } /* end of read_string functions */ +/* + * This conversation function is supposed to be a generic PAM one. + * Unfortunately, it is _not_ completely compatible with the Solaris PAM + * codebase. + * + * Namely, for msgm's that contain multiple prompts, this function + * interprets "const struct pam_message **msgm" as equivalent to + * "const struct pam_message *msgm[]". The Solaris module + * implementation interprets the **msgm object as a pointer to a + * pointer to an array of "struct pam_message" objects (that is, a + * confusing amount of pointer indirection). + */ + int misc_conv(int num_msg, const struct pam_message **msgm, struct pam_response **response, void *appdata_ptr) { -- cgit v1.2.3