summaryrefslogtreecommitdiff
path: root/src/compat
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-02-17 06:27:07 +0000
committerLaurent Bercot <ska@appnovation.com>2023-02-17 06:27:07 +0000
commit89da9d1a44aea4e12bcd9ee227bfa3580262243f (patch)
tree500e63599aa3c431e26fe299a2f5a8c247fe2998 /src/compat
parenta3a43adb2111d9a15c8782fccfd7b80d014d2269 (diff)
downloadpamela-89da9d1a44aea4e12bcd9ee227bfa3580262243f.tar.xz
Add compat boilerplate
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/compat')
-rw-r--r--src/compat/deps-lib/pamela-compat3
-rw-r--r--src/compat/misc_conv.c59
-rw-r--r--src/compat/pam_misc_drop_env.c17
-rw-r--r--src/compat/pam_misc_paste_env.c14
4 files changed, 93 insertions, 0 deletions
diff --git a/src/compat/deps-lib/pamela-compat b/src/compat/deps-lib/pamela-compat
new file mode 100644
index 0000000..d6fbe42
--- /dev/null
+++ b/src/compat/deps-lib/pamela-compat
@@ -0,0 +1,3 @@
+misc_conv.o
+pam_misc_drop_env.o
+pam_misc_paste_env.o
diff --git a/src/compat/misc_conv.c b/src/compat/misc_conv.c
new file mode 100644
index 0000000..23d23fb
--- /dev/null
+++ b/src/compat/misc_conv.c
@@ -0,0 +1,59 @@
+/* ISC license. */
+
+#include <string.h>
+#include <stdlib.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/strerr.h>
+#include <skalibs/stralloc.h>
+#include <pamela/pam.h>
+#include <pamela/compat.h>
+
+/*
+static void freeres (struct pam_response *res, unsigned int n)
+{
+ while (n--) free(res[n].resp) ;
+ free(res) ;
+}
+*/
+
+static int getsa (int h, char const *msg, stralloc *sa)
+{
+ /* TODO: complete this */
+ return 0 ;
+}
+
+int misc_conv (int n, struct pam_message const **msg, struct pam_response **resp, void *aux)
+{
+ stralloc sa = STRALLOC_ZERO ;
+ struct pam_response *res ;
+ if (n <= 0) return PAM_CONV_ERR ;
+ res = malloc(n * sizeof(struct pam_response)) ;
+ if (!res) return PAM_CONV_ERR ;
+ for (unsigned int i = 0 ; i < n ; i++)
+ {
+ switch (msg[i]->msg_style)
+ {
+ case PAM_PROMPT_ECHO_OFF :
+ if (getsa(0, msg[i]->msg, &sa)) goto fail ;
+ break ;
+ case PAM_PROMPT_ECHO_ON :
+ if (getsa(1, msg[i]->msg, &sa)) goto fail ;
+ break ;
+ case PAM_ERROR_MSG :
+ strerr_warnw1x(msg[i]->msg) ;
+ break ;
+ case PAM_TEXT_INFO :
+ {
+ size_t len = strlen(msg[i]->msg) ;
+ if (allwrite(1, msg[i]->msg, len) < len) goto fail ;
+ break ;
+ }
+ case PAM_BINARY_PROMPT : /* TODO */
+ break ;
+ }
+ }
+ return 0 ;
+
+ fail: /* TODO: check */
+ return -1 ;
+}
diff --git a/src/compat/pam_misc_drop_env.c b/src/compat/pam_misc_drop_env.c
new file mode 100644
index 0000000..a8a7564
--- /dev/null
+++ b/src/compat/pam_misc_drop_env.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#include <stdlib.h>
+#include <pamela/compat.h>
+
+static inline void env_free (char **envp)
+{
+ char **p = envp ;
+ while (*p) free(*p++) ;
+ free(envp) ;
+}
+
+char **pam_misc_drop_env (char **envp)
+{
+ env_free(envp) ;
+ return 0 ;
+}
diff --git a/src/compat/pam_misc_paste_env.c b/src/compat/pam_misc_paste_env.c
new file mode 100644
index 0000000..b70fd58
--- /dev/null
+++ b/src/compat/pam_misc_paste_env.c
@@ -0,0 +1,14 @@
+/* ISC license. */
+
+#include <pamela/pam.h>
+#include <pamela/compat.h>
+
+int pam_misc_paste_env (pam_handle_t *pamh, char const *const *envp)
+{
+ for (; *envp ; envp++)
+ {
+ int e = pam_putenv(pamh, *envp) ;
+ if (e != PAM_SUCCESS) return e ;
+ }
+ return PAM_SUCCESS ;
+}