2015-03-27 18:59:29 -05:00
|
|
|
|
#include "_cgo_export.h"
|
|
|
|
|
|
#include <security/pam_appl.h>
|
2023-09-19 20:04:06 +02:00
|
|
|
|
#include <stdint.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
|
|
|
|
|
|
|
2023-09-21 08:11:19 -05:00
|
|
|
|
int cb_pam_conv(int num_msg, PAM_CONST struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
|
2015-03-27 18:59:29 -05:00
|
|
|
|
{
|
2023-09-21 08:11:19 -05:00
|
|
|
|
if (num_msg <= 0 || num_msg > PAM_MAX_NUM_MSG)
|
2015-03-31 12:19:55 -05:00
|
|
|
|
return PAM_CONV_ERR;
|
2023-09-21 08:11:19 -05:00
|
|
|
|
|
2023-09-21 08:12:18 -05:00
|
|
|
|
*resp = calloc(num_msg, sizeof **resp);
|
2023-09-21 08:11:19 -05:00
|
|
|
|
if (!*resp)
|
2015-03-27 18:59:29 -05:00
|
|
|
|
return PAM_BUF_ERR;
|
2023-09-21 08:11:19 -05:00
|
|
|
|
|
2015-03-27 18:59:29 -05:00
|
|
|
|
for (size_t i = 0; i < num_msg; ++i) {
|
2023-09-21 08:11:19 -05:00
|
|
|
|
struct cbPAMConv_return result = cbPAMConv(msg[i]->msg_style, (char *)msg[i]->msg, (uintptr_t)appdata_ptr);
|
|
|
|
|
|
if (result.r1 != PAM_SUCCESS)
|
2015-03-27 18:59:29 -05:00
|
|
|
|
goto error;
|
2023-09-21 08:11:19 -05:00
|
|
|
|
|
2015-03-27 18:59:29 -05:00
|
|
|
|
(*resp)[i].resp = result.r0;
|
|
|
|
|
|
}
|
2023-09-21 08:11:19 -05:00
|
|
|
|
|
2015-03-27 18:59:29 -05:00
|
|
|
|
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
|
|
|
|
}
|
2023-09-21 08:11:19 -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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-19 20:04:06 +02:00
|
|
|
|
void init_pam_conv(struct pam_conv *conv, uintptr_t appdata)
|
2015-03-27 18:59:29 -05:00
|
|
|
|
{
|
|
|
|
|
|
conv->conv = cb_pam_conv;
|
2023-09-19 20:04:06 +02:00
|
|
|
|
conv->appdata_ptr = (void *)appdata;
|
2015-03-27 18:59:29 -05:00
|
|
|
|
}
|
2022-09-16 08:09:26 +02:00
|
|
|
|
|
2023-09-21 08:11:19 -05: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)
|
|
|
|
|
|
{
|
2022-09-16 08:09:26 +02:00
|
|
|
|
if (pam_start_confdir == NULL)
|
|
|
|
|
|
return 1;
|
2023-09-21 08:11:19 -05:00
|
|
|
|
|
2022-09-16 08:09:26 +02:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|