2015-03-27 18:59:29 -05:00
|
|
|
|
#include "_cgo_export.h"
|
|
|
|
|
|
#include <security/pam_appl.h>
|
2015-03-31 12:19:55 -05:00
|
|
|
|
#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);
|
2015-03-31 12:19:55 -05:00
|
|
|
|
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) {
|
2015-03-31 12:19:55 -05:00
|
|
|
|
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) {
|
2015-03-31 12:19:55 -05:00
|
|
|
|
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
|
|
|
|
}
|
2015-03-31 12:19:55 -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
|
|
|
|
}
|
2022-09-16 08:09:26 +02:00
|
|
|
|
|
|
|
|
|
|
// pam_start_confdir is a recent PAM api to declare a confdir (mostly for tests)
|
|
|
|
|
|
// weaken the linking dependency to detect if it’s present.
|
|
|
|
|
|
int pam_start_confdir(const char *service_name, const char *user, const struct pam_conv *pam_conversation, const char *confdir, pam_handle_t **pamh) __attribute__ ((weak));
|
|
|
|
|
|
int check_pam_start_confdir(void) {
|
|
|
|
|
|
if (pam_start_confdir == NULL)
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|