7
7
* That, in fact, was again based on the original stuff
8
8
* from Jeph Blaize <jblaize@kiva.net> done in May 1997.
10
* Version: $Id: rlm_pam.c,v 1.32 2004/02/26 19:04:33 aland Exp $
10
* Version: $Id: rlm_pam.c,v 1.32.4.2 2006/01/04 05:51:50 fcusack Exp $
12
12
* This program is free software; you can redistribute it and/or modify
13
13
* it under the terms of the GNU General Public License as published by
121
121
const struct pam_message **msg,
122
122
struct pam_response **resp,
123
123
void *appdata_ptr) {
124
int count = 0, replies = 0;
125
struct pam_response *reply = NULL;
126
int size = sizeof(struct pam_response);
125
struct pam_response *reply;
127
126
my_PAM *pam_config = (my_PAM *) appdata_ptr;
129
#define GET_MEM if (reply) realloc(reply, size); else reply = rad_malloc(size); \
130
size += sizeof(struct pam_response)
128
/* strdup(NULL) doesn't work on some platforms */
131
129
#define COPY_STRING(s) ((s) ? strdup(s) : NULL)
131
reply = rad_malloc(num_msg * sizeof(struct pam_response));
132
memset(reply, 0, num_msg * sizeof(struct pam_response));
133
133
for (count = 0; count < num_msg; count++) {
134
134
switch (msg[count]->msg_style) {
135
135
case PAM_PROMPT_ECHO_ON:
137
reply[replies].resp_retcode = PAM_SUCCESS;
138
reply[replies++].resp = COPY_STRING(pam_config->username);
136
reply[count].resp_retcode = PAM_SUCCESS;
137
reply[count].resp = COPY_STRING(pam_config->username);
141
139
case PAM_PROMPT_ECHO_OFF:
143
reply[replies].resp_retcode = PAM_SUCCESS;
144
reply[replies++].resp = COPY_STRING(pam_config->password);
140
reply[count].resp_retcode = PAM_SUCCESS;
141
reply[count].resp = COPY_STRING(pam_config->password);
147
143
case PAM_TEXT_INFO:
148
144
/* ignore it... */
150
146
case PAM_ERROR_MSG:
152
148
/* Must be an error of some sort... */
149
for (count = 0; count < num_msg; count++) {
150
if (reply[count].resp) {
151
/* could be a password, let's be sanitary */
152
memset(reply[count].resp, 0, strlen(reply[count].resp));
153
free(reply[count].resp);
154
157
pam_config->error = 1;
155
158
return PAM_CONV_ERR;
158
if (reply) *resp = reply;
162
/* PAM frees reply (including reply[].resp) */
160
164
return PAM_SUCCESS;