lib/replace: add a replacement for openat2() that returns ENOSYS
authorStefan Metzmacher <metze@samba.org>
Mon, 8 Aug 2022 13:23:29 +0000 (15:23 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 15 Aug 2022 15:03:36 +0000 (15:03 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/replace/replace.c
lib/replace/system/filesys.h
lib/replace/wscript

index 0652cb4e6d62e055731d7c789c1130c242f11201..763afec78c5268884cdeaa1fa8f16914b3015a7c 100644 (file)
@@ -1081,3 +1081,12 @@ ssize_t rep_copy_file_range(int fd_in,
        return -1;
 }
 #endif /* HAVE_COPY_FILE_RANGE */
+
+#ifndef HAVE_OPENAT2
+long rep_openat2(int dirfd, const char *pathname,
+                struct open_how *how, size_t size)
+{
+       errno = ENOSYS;
+       return -1;
+}
+#endif /* !HAVE_OPENAT2 */
index bb9482c69afd120bb38dfe60ebc22ebef374b2f8..8005b18780f9f799323319f395318f96f30fd3b3 100644 (file)
@@ -243,4 +243,39 @@ int rep_fsetxattr (int filedes, const char *name, const void *value, size_t size
 
 #endif /* !defined(HAVE_XATTR_XATTR) || defined(XATTR_ADDITIONAL_OPTIONS) */
 
+#ifdef HAVE_LINUX_OPENAT2_H
+#include <linux/openat2.h>
+#else /* ! HAVE_LINUX_OPENAT2_H */
+/* how->resolve flags for openat2(2). */
+#define RESOLVE_NO_XDEV                0x01 /* Block mount-point crossings
+                                       (includes bind-mounts). */
+#define RESOLVE_NO_MAGICLINKS  0x02 /* Block traversal through procfs-style
+                                       "magic-links". */
+#define RESOLVE_NO_SYMLINKS    0x04 /* Block traversal through all symlinks
+                                       (implies OEXT_NO_MAGICLINKS) */
+#define RESOLVE_BENEATH                0x08 /* Block "lexical" trickery like
+                                       "..", symlinks, and absolute
+                                       paths which escape the dirfd. */
+#define RESOLVE_IN_ROOT                0x10 /* Make all jumps to "/" and ".."
+                                       be scoped inside the dirfd
+                                       (similar to chroot(2)). */
+#define RESOLVE_CACHED         0x20 /* Only complete if resolution can be
+                                       completed through cached lookup. May
+                                       return -EAGAIN if that's not
+                                       possible. */
+struct __rep_open_how {
+       uint64_t flags;
+       uint64_t mode;
+       uint64_t resolve;
+};
+#define open_how __rep_open_how
+#endif /* ! HAVE_LINUX_OPENAT2_H */
+
+#ifndef HAVE_OPENAT2
+long rep_openat2(int dirfd, const char *pathname,
+                struct open_how *how, size_t size);
+#define openat2(dirfd, pathname, how, size) \
+       rep_openat2(dirfd, pathname, how, size)
+#endif /* !HAVE_OPENAT2 */
+
 #endif
index dd9b19219a1507483d2c67c6c601f688c9dadc64..2f179992c82ae7f2e014ff3e43f907bf21bf2678 100644 (file)
@@ -66,6 +66,7 @@ def configure(conf):
     conf.CHECK_HEADERS('errno.h')
     conf.CHECK_HEADERS('getopt.h iconv.h')
     conf.CHECK_HEADERS('memory.h nss.h sasl/sasl.h')
+    conf.CHECK_HEADERS('linux/openat2.h')
 
     conf.CHECK_FUNCS_IN('inotify_init', 'inotify', checklibc=True,
                         headers='sys/inotify.h')