Author: Dharanendiran <dharanendiran@timesys.com>
Date: Thu, 20 Nov 2025 17:22:46 +0530


---
 src/common/cockpitjsonprint.c | 34 ++++++++++++++++++++++++++++++++++
 src/common/cockpitmemfdread.c | 13 +++++++++++++
 src/common/cockpitmemory.c    | 11 +++++++++++
 src/tls/client-certificate.c  | 22 ++++++++++++++++++++++
 4 files changed, 80 insertions(+)

diff --git a/src/common/cockpitjsonprint.c b/src/common/cockpitjsonprint.c
index 08d250a..a0acf0d 100644
--- a/src/common/cockpitjsonprint.c
+++ b/src/common/cockpitjsonprint.c
@@ -28,6 +28,40 @@
 #include <string.h>
 #include <sys/mman.h>
 
+#if (defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 27))
+#include <unistd.h>
+#include <sys/syscall.h>
+
+static inline int
+memfd_create(const char *name, unsigned int flags)
+{
+   return syscall(SYS_memfd_create, name, flags);
+}
+#endif
+
+#ifndef F_ADD_SEALS
+# define F_ADD_SEALS 1033
+#endif
+
+#ifndef F_GET_SEALS
+# define F_GET_SEALS 1034
+#endif
+
+#ifndef F_SEAL_SHRINK
+# define F_SEAL_SEAL     0x0001
+# define F_SEAL_SHRINK   0x0002
+# define F_SEAL_GROW     0x0004
+# define F_SEAL_WRITE    0x0008
+#endif
+
+#ifndef MFD_CLOEXEC
+# define MFD_CLOEXEC       0x0001U
+#endif
+
+#ifndef MFD_ALLOW_SEALING
+# define MFD_ALLOW_SEALING 0x0002U
+#endif
+
 static bool
 char_needs_json_escape (unsigned char c)
 {
diff --git a/src/common/cockpitmemfdread.c b/src/common/cockpitmemfdread.c
index cecd29d..aee4f86 100644
--- a/src/common/cockpitmemfdread.c
+++ b/src/common/cockpitmemfdread.c
@@ -29,6 +29,19 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#ifndef F_GET_SEALS
+# define F_GET_SEALS 1034
+#endif
+
+#ifndef F_SEAL_SHRINK
+# define F_SEAL_SEAL     0x0001
+# define F_SEAL_SHRINK   0x0002
+# define F_SEAL_GROW     0x0004
+# define F_SEAL_WRITE    0x0008
+#endif
+
+
+
 gchar *
 cockpit_memfd_read (int      fd,
                     GError **error)
diff --git a/src/common/cockpitmemory.c b/src/common/cockpitmemory.c
index f92c1e3..520b3e2 100644
--- a/src/common/cockpitmemory.c
+++ b/src/common/cockpitmemory.c
@@ -28,6 +28,17 @@
 #include <string.h>
 #include <errno.h>
 
+#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 25)
+static void explicit_bzero(void *p, size_t len)
+{
+    volatile unsigned char *vp = p;
+    while (len--) {
+        *vp++ = 0;
+    }
+}
+#endif
+
+
 /**
  * cockpit_memory_clear:
  *
diff --git a/src/tls/client-certificate.c b/src/tls/client-certificate.c
index 2c0d69c..6d115c5 100644
--- a/src/tls/client-certificate.c
+++ b/src/tls/client-certificate.c
@@ -51,9 +51,31 @@
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
+#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 25
 #include <sys/random.h>
+#endif
 #include <unistd.h>
 
+#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 25)
+#if defined(__x86_64__)
+# define SYS_getrandom 318
+#elif defined(__i386__)
+# define SYS_getrandom 355
+#elif defined(__arm__)
+# define SYS_getrandom 384
+#elif defined(__aarch64__)
+# define SYS_getrandom 278
+#elif defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) || defined(__ppc64__)
+# define SYS_getrandom 359
+#else
+# error "SYS_getrandom syscall number unknown for this architecture"
+#endif
+
+static inline ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
+{
+    return syscall(SYS_getrandom, buf, buflen, flags);
+}
+#endif
 
 /**
  * client_certificate_verify: Custom client certificate validation function
-- 
2.34.1

