transaction: Use cgo.Handle to pass callback data to PAM

Go provides a nicer way to handle Go structs lifetime when they
are passed to C now, so use this instead of a custom
implementation that requires to store them in a map
This commit is contained in:
Marco Trevisan (Treviño)
2023-09-19 20:04:06 +02:00
parent a22a1abf3f
commit 8fd6202a7b
4 changed files with 13 additions and 82 deletions

View File

@@ -1,5 +1,6 @@
#include "_cgo_export.h"
#include <security/pam_appl.h>
#include <stdint.h>
#include <string.h>
#ifdef __sun
@@ -25,7 +26,7 @@ int cb_pam_conv(
struct cbPAMConv_return result = cbPAMConv(
msg[i]->msg_style,
(char *)msg[i]->msg,
(long)appdata_ptr);
(uintptr_t)appdata_ptr);
if (result.r1 != PAM_SUCCESS) {
goto error;
}
@@ -45,10 +46,10 @@ error:
return PAM_CONV_ERR;
}
void init_pam_conv(struct pam_conv *conv, long c)
void init_pam_conv(struct pam_conv *conv, uintptr_t appdata)
{
conv->conv = cb_pam_conv;
conv->appdata_ptr = (void *)c;
conv->appdata_ptr = (void *)appdata;
}
// pam_start_confdir is a recent PAM api to declare a confdir (mostly for tests)