You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

95 lines
2.7 KiB

--- netkit-rsh-0.17/rexecd/rexecd.c.pam-conv 2005-10-13 18:42:54.000000000 +0200
+++ netkit-rsh-0.17/rexecd/rexecd.c 2005-10-13 18:45:30.000000000 +0200
@@ -178,47 +178,51 @@
static char *PAM_username;
static char *PAM_password;
-static int PAM_conv (int num_msg,
- 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);
-
- #define GET_MEM if (reply) realloc(reply, size); else reply = malloc(size); \
- if (!reply) return PAM_CONV_ERR; \
- size += sizeof(struct pam_response)
- #define COPY_STRING(s) (s) ? strdup(s) : NULL
-
- for (count = 0; count < num_msg; count++) {
- GET_MEM;
- switch (msg[count]->msg_style) {
- case PAM_PROMPT_ECHO_ON:
- reply[replies].resp_retcode = PAM_SUCCESS;
- reply[replies++].resp = COPY_STRING(PAM_username);
- /* PAM frees resp */
- break;
- case PAM_PROMPT_ECHO_OFF:
- reply[replies].resp_retcode = PAM_SUCCESS;
- reply[replies++].resp = COPY_STRING(PAM_password);
- /* PAM frees resp */
- break;
- case PAM_TEXT_INFO:
- reply[replies].resp_retcode = PAM_SUCCESS;
- reply[replies++].resp = NULL;
- /* ignore it... */
- break;
- case PAM_ERROR_MSG:
- reply[replies].resp_retcode = PAM_SUCCESS;
- reply[replies++].resp = NULL;
- /* Must be an error of some sort... */
- default:
- return PAM_CONV_ERR;
- }
- }
- if (reply) *resp = reply;
- return PAM_SUCCESS;
+static int
+PAM_conv(int num_msg, const struct pam_message **msg,
+ struct pam_response **response, void *appdata_ptr)
+{
+ struct pam_response *pr;
+ const struct pam_message *pm;
+ int n;
+
+ if ((*response = malloc(num_msg * sizeof(struct pam_response))) == NULL)
+ return(PAM_CONV_ERR);
+ memset(*response, 0, num_msg * sizeof(struct pam_response));
+
+ for (pr = *response, pm = *msg, n = num_msg; n--; pr++, pm++)
+ {
+ switch (pm->msg_style) {
+ case PAM_PROMPT_ECHO_ON:
+ /* XXX: why not pam_set_item(PAM_RUSER) ? */
+ pr->resp_retcode = PAM_SUCCESS;
+ pr->resp = PAM_username ? strdup(PAM_username) : NULL;
+ /* PAM frees resp */
+ break;
+ case PAM_PROMPT_ECHO_OFF:
+ pr->resp_retcode = PAM_SUCCESS;
+ pr->resp = PAM_password ? strdup(PAM_password) : NULL;
+ /* PAM frees resp */
+ break;
+ case PAM_TEXT_INFO:
+ case PAM_ERROR_MSG:
+ /* ignore it... */
+ pr->resp_retcode = PAM_SUCCESS;
+ pr->resp = NULL;
+ break;
+ default:
+ /* Zero and free allocated memory and return an error. */
+ for (pr = *response, n = num_msg; n--; pr++)
+ {
+ if (pr->resp)
+ free(pr->resp);
+ }
+ free(*response);
+ *response = NULL;
+ return(PAM_CONV_ERR);
+ }
+ }
+ return PAM_SUCCESS;
}
static struct pam_conv PAM_conversation = {