Files
msteinert-go-pam/transaction.c

53 lines
1.0 KiB
C
Raw Normal View History

2015-03-27 18:59:29 -05:00
#include "_cgo_export.h"
#include <security/pam_appl.h>
#include <string.h>
2015-03-27 18:59:29 -05:00
2020-08-07 17:34:46 +01:00
#ifdef __sun
#define PAM_CONST
#else
#define PAM_CONST const
#endif
2015-03-27 18:59:29 -05:00
int cb_pam_conv(
int num_msg,
2020-08-07 17:34:46 +01:00
PAM_CONST struct pam_message **msg,
2015-03-27 18:59:29 -05:00
struct pam_response **resp,
void *appdata_ptr)
{
*resp = calloc(num_msg, sizeof **resp);
if (num_msg <= 0 || num_msg > PAM_MAX_NUM_MSG) {
return PAM_CONV_ERR;
}
2015-03-27 18:59:29 -05:00
if (!*resp) {
return PAM_BUF_ERR;
}
for (size_t i = 0; i < num_msg; ++i) {
struct cbPAMConv_return result = cbPAMConv(
msg[i]->msg_style,
(char *)msg[i]->msg,
2015-12-03 14:59:51 -06:00
(long)appdata_ptr);
2015-03-27 18:59:29 -05:00
if (result.r1 != PAM_SUCCESS) {
goto error;
}
(*resp)[i].resp = result.r0;
}
return PAM_SUCCESS;
error:
for (size_t i = 0; i < num_msg; ++i) {
if ((*resp)[i].resp) {
memset((*resp)[i].resp, 0, strlen((*resp)[i].resp));
free((*resp)[i].resp);
}
2015-03-27 18:59:29 -05:00
}
memset(*resp, 0, num_msg * sizeof *resp);
2015-03-27 18:59:29 -05:00
free(*resp);
*resp = NULL;
return PAM_CONV_ERR;
}
2015-12-03 14:59:51 -06:00
void init_pam_conv(struct pam_conv *conv, long c)
2015-03-27 18:59:29 -05:00
{
conv->conv = cb_pam_conv;
2015-12-03 14:59:51 -06:00
conv->appdata_ptr = (void *)c;
2015-03-27 18:59:29 -05:00
}