--- ../2/poppassd.c 2006-11-09 21:17:07.000000000 +0530 +++ poppassd.c 2007-01-16 19:59:06.000000000 +0530 @@ -88,7 +88,6 @@ #define POP_OLDPASS 0 #define POP_NEWPASS 1 #define POP_SKIPASS 2 -short int pop_state = POP_OLDPASS; void WriteToClient (char *fmt, ...) { @@ -116,6 +115,30 @@ line[BUFSIZE-1] = '\0'; } +static inline int getstate(const char *msg) +{ + /* Interpret possible PAM messages (not including errors) */ + if(!strcmp(msg, "Password: ")) + return POP_OLDPASS; + if(!strcmp(msg, "Enter login(LDAP) password: ")) + return POP_OLDPASS; + + if(!strcmp(msg, "New password: ")) + return POP_NEWPASS; + if(!strcmp(msg, "Re-enter new password: ")) + return POP_NEWPASS; + if(!strcmp(msg, "Enter new UNIX password: ")) + return POP_NEWPASS; + if(!strcmp(msg, "Retype new UNIX password: ")) + return POP_NEWPASS; + if(!strcmp(msg, "New UNIX password: ")) + return POP_NEWPASS; + + WriteToClient("Unknown PAM Message: %s", msg); // We should not ever reach here. + + return POP_SKIPASS; +} + int poppassd_conv(num_msg, msg, resp, appdata_ptr) int num_msg; const struct pam_message **msg; @@ -147,7 +170,7 @@ if(msg[i]->msg_style == PAM_PROMPT_ECHO_OFF || msg[i]->msg_style == PAM_PROMPT_ECHO_ON) { - switch(pop_state) { + switch(getstate(msg[i]->msg)) { case POP_OLDPASS: r[i].resp = strdup(oldpass); break; @@ -158,7 +181,7 @@ r[i].resp = NULL; break; default: - syslog(LOG_ERR, "PAM error: too many switches (state=%d)", pop_state); + syslog(LOG_ERR, "PAM error: too many switches"); } } else { @@ -235,8 +258,6 @@ exit(1); } - pop_state = POP_NEWPASS; - WriteToClient ("200 Your new password please."); ReadFromClient (line); sscanf (line, "newpass %" MAX_LEN_PASS "c", newpass);