This source file includes following definitions.
- rpl_fchownat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <config.h>
25
26
27 #include <unistd.h>
28
29 #include <errno.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "openat.h"
34
35 #if !HAVE_FCHOWNAT
36
37
38
39
40
41
42
43
44
45 # define AT_FUNC_NAME fchownat
46 # define AT_FUNC_F1 lchown
47 # define AT_FUNC_F2 chown
48 # define AT_FUNC_USE_F1_COND AT_SYMLINK_NOFOLLOW
49 # define AT_FUNC_POST_FILE_PARAM_DECLS , uid_t owner, gid_t group, int flag
50 # define AT_FUNC_POST_FILE_ARGS , owner, group
51 # include "at-func.c"
52 # undef AT_FUNC_NAME
53 # undef AT_FUNC_F1
54 # undef AT_FUNC_F2
55 # undef AT_FUNC_USE_F1_COND
56 # undef AT_FUNC_POST_FILE_PARAM_DECLS
57 # undef AT_FUNC_POST_FILE_ARGS
58
59 #else
60
61 # undef fchownat
62
63 # if FCHOWNAT_NOFOLLOW_BUG
64
65
66
67
68 static int
69 local_lchownat (int fd, char const *file, uid_t owner, gid_t group);
70
71 # define AT_FUNC_NAME local_lchownat
72 # define AT_FUNC_F1 lchown
73 # define AT_FUNC_POST_FILE_PARAM_DECLS , uid_t owner, gid_t group
74 # define AT_FUNC_POST_FILE_ARGS , owner, group
75 # include "at-func.c"
76 # undef AT_FUNC_NAME
77 # undef AT_FUNC_F1
78 # undef AT_FUNC_POST_FILE_PARAM_DECLS
79 # undef AT_FUNC_POST_FILE_ARGS
80
81 # endif
82
83
84
85
86 int
87 rpl_fchownat (int fd, char const *file, uid_t owner, gid_t group, int flag)
88 {
89 # if FCHOWNAT_NOFOLLOW_BUG
90 if (flag == AT_SYMLINK_NOFOLLOW)
91 return local_lchownat (fd, file, owner, group);
92 # endif
93 # if FCHOWNAT_EMPTY_FILENAME_BUG
94 if (file[0] == '\0')
95 {
96 errno = ENOENT;
97 return -1;
98 }
99 # endif
100 # if CHOWN_TRAILING_SLASH_BUG
101 {
102 size_t len = strlen (file);
103 struct stat st;
104 if (len && file[len - 1] == '/')
105 {
106 if (statat (fd, file, &st))
107 return -1;
108 if (flag == AT_SYMLINK_NOFOLLOW)
109 return fchownat (fd, file, owner, group, 0);
110 }
111 }
112 # endif
113 return fchownat (fd, file, owner, group, flag);
114 }
115
116 #endif