*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Copyright 2000 The FreeRADIUS server project
* Copyright 1997 Jeph Blaize <jblaize@kiva.net>
const struct pam_message **msg,
struct pam_response **resp,
void *appdata_ptr) {
- int count = 0, replies = 0;
- struct pam_response *reply = NULL;
- int size = sizeof(struct pam_response);
+ int count;
+ struct pam_response *reply;
my_PAM *pam_config = (my_PAM *) appdata_ptr;
-#define GET_MEM if (reply) realloc(reply, size); else reply = rad_malloc(size); \
- size += sizeof(struct pam_response)
+/* strdup(NULL) doesn't work on some platforms */
#define COPY_STRING(s) ((s) ? strdup(s) : NULL)
+ reply = rad_malloc(num_msg * sizeof(struct pam_response));
+ memset(reply, 0, num_msg * sizeof(struct pam_response));
for (count = 0; count < num_msg; count++) {
switch (msg[count]->msg_style) {
case PAM_PROMPT_ECHO_ON:
- GET_MEM;
- reply[replies].resp_retcode = PAM_SUCCESS;
- reply[replies++].resp = COPY_STRING(pam_config->username);
- /* PAM frees resp */
+ reply[count].resp_retcode = PAM_SUCCESS;
+ reply[count].resp = COPY_STRING(pam_config->username);
break;
case PAM_PROMPT_ECHO_OFF:
- GET_MEM;
- reply[replies].resp_retcode = PAM_SUCCESS;
- reply[replies++].resp = COPY_STRING(pam_config->password);
- /* PAM frees resp */
+ reply[count].resp_retcode = PAM_SUCCESS;
+ reply[count].resp = COPY_STRING(pam_config->password);
break;
case PAM_TEXT_INFO:
/* ignore it... */
case PAM_ERROR_MSG:
default:
/* Must be an error of some sort... */
- free (reply);
+ for (count = 0; count < num_msg; count++) {
+ if (reply[count].resp) {
+ /* could be a password, let's be sanitary */
+ memset(reply[count].resp, 0, strlen(reply[count].resp));
+ free(reply[count].resp);
+ }
+ }
+ free(reply);
pam_config->error = 1;
return PAM_CONV_ERR;
}
}
- if (reply) *resp = reply;
+ *resp = reply;
+ /* PAM frees reply (including reply[].resp) */
return PAM_SUCCESS;
}