Debian Codegraph @

m4/fchownat.m4

raw
1 # fchownat.m4 serial 7
2 dnl Copyright (C) 2004-2023 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 # Written by Jim Meyering.
8
9 # If we have the fchownat function, and it has the bug (in glibc-2.4)
10 # that it dereferences symlinks even with AT_SYMLINK_NOFOLLOW, then
11 # use the replacement function.
12 # Also if the fchownat function, like chown, has the trailing slash bug,
13 # use the replacement function.
14 # Also use the replacement function if fchownat is simply not available.
15 AC_DEFUN([gl_FUNC_FCHOWNAT],
16 [
17 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
18 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
19 AC_REQUIRE([gl_FUNC_CHOWN])
20 AC_CHECK_FUNC([fchownat],
21 [gl_FUNC_FCHOWNAT_DEREF_BUG(
22 [REPLACE_FCHOWNAT=1
23 AC_DEFINE([FCHOWNAT_NOFOLLOW_BUG], [1],
24 [Define to 1 if your platform has fchownat, but it cannot
25 perform lchown tasks.])
26 ])
27 gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG(
28 [REPLACE_FCHOWNAT=1
29 AC_DEFINE([FCHOWNAT_EMPTY_FILENAME_BUG], [1],
30 [Define to 1 if your platform has fchownat, but it does
31 not reject an empty file name.])
32 ])
33 if test $REPLACE_CHOWN = 1; then
34 REPLACE_FCHOWNAT=1
35 fi],
36 [HAVE_FCHOWNAT=0])
37 ])
38
39 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
40 AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG],
41 [
42 dnl Persuade glibc's <unistd.h> to declare fchownat().
43 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
44
45 AC_CACHE_CHECK([whether fchownat works with AT_SYMLINK_NOFOLLOW],
46 [gl_cv_func_fchownat_nofollow_works],
47 [
48 gl_dangle=conftest.dangle
49 # Remove any remnants of a previous test.
50 rm -f $gl_dangle
51 # Arrange for deletion of the temporary file this test creates.
52 ac_clean_files="$ac_clean_files $gl_dangle"
53 ln -s conftest.no-such $gl_dangle
54 AC_RUN_IFELSE(
55 [AC_LANG_SOURCE(
56 [[
57 #include <fcntl.h>
58 #include <unistd.h>
59 /* Android 4.3 declares fchownat() in <sys/stat.h> instead. */
60 #include <sys/stat.h>
61 #include <stdlib.h>
62 #include <errno.h>
63 #include <sys/types.h>
64 int
65 main ()
66 {
67 return (fchownat (AT_FDCWD, "$gl_dangle", (uid_t)(-1), getgid (),
68 AT_SYMLINK_NOFOLLOW) != 0
69 && errno == ENOENT);
70 }
71 ]])],
72 [gl_cv_func_fchownat_nofollow_works=yes],
73 [gl_cv_func_fchownat_nofollow_works=no],
74 [gl_cv_func_fchownat_nofollow_works="$gl_cross_guess_normal"])
75 ])
76 AS_IF([test "$gl_cv_func_fchownat_nofollow_works" != yes], [$1], [$2])
77 ])
78
79 # gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])
80 AC_DEFUN([gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG],
81 [
82 dnl Persuade glibc's <unistd.h> to declare fchownat().
83 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
84
85 AC_CACHE_CHECK([whether fchownat works with an empty file name],
86 [gl_cv_func_fchownat_empty_filename_works],
87 [AC_RUN_IFELSE(
88 [AC_LANG_PROGRAM(
89 [[#include <unistd.h>
90 #include <fcntl.h>
91 /* Android 4.3 declares fchownat() in <sys/stat.h> instead. */
92 #include <sys/stat.h>
93 ]GL_MDA_DEFINES],
94 [[int fd;
95 int ret;
96 if (mkdir ("conftestdir", 0700) < 0)
97 return 2;
98 fd = open ("conftestdir", O_RDONLY);
99 if (fd < 0)
100 return 3;
101 ret = fchownat (fd, "", (uid_t)(-1), (gid_t)(-1), 0);
102 close (fd);
103 rmdir ("conftestdir");
104 return ret == 0;
105 ]])],
106 [gl_cv_func_fchownat_empty_filename_works=yes],
107 [gl_cv_func_fchownat_empty_filename_works=no],
108 [gl_cv_func_fchownat_empty_filename_works="$gl_cross_guess_normal"])
109 ])
110 AS_IF([test "$gl_cv_func_fchownat_empty_filename_works" != yes], [$1], [$2])
111 ])