blob: c55b6481396c8ea411dbd1648f40ce2ebe4924c3 [file] [log] [blame]
Andrew Geissler706d5aa2021-02-12 15:55:30 -06001From 45d1ed58927593968faead7dbb295f3922f41a2f Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 8 Aug 2015 14:16:43 -0700
4Subject: [PATCH] Add support for defining missing funcitonality
5
6In order to support alternative libc on linux ( musl, bioninc ) etc we
7need to check for glibc-only features and provide alternatives, in this
8list strndupa is first one, when configure detects that its not included
9in system C library then the altrnative implementation from missing.h is
10used
11
12Signed-off-by: Khem Raj <raj.khem@gmail.com>
13---
14Upstream-Status: Pending
15
16 configure.ac | 3 +++
17 libpam/include/missing.h | 12 ++++++++++++
18 modules/pam_exec/pam_exec.c | 1 +
19 3 files changed, 16 insertions(+)
20 create mode 100644 libpam/include/missing.h
21
22diff --git a/configure.ac b/configure.ac
23index 9e1257f..cbed979 100644
24--- a/configure.ac
25+++ b/configure.ac
26@@ -599,6 +599,9 @@ dnl
27 AC_CHECK_DECL(__NR_keyctl, [have_key_syscalls=1],[have_key_syscalls=0],[#include <sys/syscall.h>])
28 AC_CHECK_DECL(ENOKEY, [have_key_errors=1],[have_key_errors=0],[#include <errno.h>])
29
30+# musl and bionic don't have strndupa
31+AC_CHECK_DECLS_ONCE([strndupa])
32+
33 HAVE_KEY_MANAGEMENT=0
34 if test $have_key_syscalls$have_key_errors = 11
35 then
36diff --git a/libpam/include/missing.h b/libpam/include/missing.h
37new file mode 100644
38index 0000000..3cf011c
39--- /dev/null
40+++ b/libpam/include/missing.h
41@@ -0,0 +1,12 @@
42+#pragma once
43+
44+#if !HAVE_DECL_STRNDUPA
45+#define strndupa(s, n) \
46+ ({ \
47+ const char *__old = (s); \
48+ size_t __len = strnlen(__old, (n)); \
49+ char *__new = alloca(__len + 1); \
50+ __new[__len] = '\0'; \
51+ memcpy(__new, __old, __len); \
52+ })
53+#endif
54diff --git a/modules/pam_exec/pam_exec.c b/modules/pam_exec/pam_exec.c
55index 17ba6ca..3aa2694 100644
56--- a/modules/pam_exec/pam_exec.c
57+++ b/modules/pam_exec/pam_exec.c
58@@ -59,6 +59,7 @@
59 #include <security/pam_modutil.h>
60 #include <security/pam_ext.h>
61 #include <security/_pam_macros.h>
62+#include <missing.h>
63
64 #define ENV_ITEM(n) { (n), #n }
65 static struct {
66--
672.1.4
68