This source file includes following definitions.
- lchown
- rpl_lchown
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <config.h>
22
23 #include <unistd.h>
24
25 #include <errno.h>
26 #include <stdbool.h>
27 #include <string.h>
28 #include <sys/stat.h>
29
30 #if !HAVE_LCHOWN
31
32
33
34 # if CHOWN_MODIFIES_SYMLINK
35 # undef chown
36 # endif
37
38
39
40
41
42
43 int
44 lchown (const char *file, uid_t uid, gid_t gid)
45 {
46 # if HAVE_CHOWN
47 # if ! CHOWN_MODIFIES_SYMLINK
48 struct stat stats;
49
50 if (lstat (file, &stats) == 0 && S_ISLNK (stats.st_mode))
51 {
52 errno = EOPNOTSUPP;
53 return -1;
54 }
55 # endif
56
57 return chown (file, uid, gid);
58
59 # else
60 errno = ENOSYS;
61 return -1;
62 # endif
63 }
64
65 #else
66
67 # undef lchown
68
69
70 int
71 rpl_lchown (const char *file, uid_t uid, gid_t gid)
72 {
73 bool stat_valid = false;
74 int result;
75
76 # if CHOWN_CHANGE_TIME_BUG
77 struct stat st;
78
79 if (gid != (gid_t) -1 || uid != (uid_t) -1)
80 {
81 if (lstat (file, &st))
82 return -1;
83 stat_valid = true;
84 if (!S_ISLNK (st.st_mode))
85 return chown (file, uid, gid);
86 }
87 # endif
88
89 # if CHOWN_TRAILING_SLASH_BUG
90 if (!stat_valid)
91 {
92 size_t len = strlen (file);
93 if (len && file[len - 1] == '/')
94 return chown (file, uid, gid);
95 }
96 # endif
97
98 result = lchown (file, uid, gid);
99
100 # if CHOWN_CHANGE_TIME_BUG && HAVE_LCHMOD
101 if (result == 0 && stat_valid
102 && (uid == st.st_uid || uid == (uid_t) -1)
103 && (gid == st.st_gid || gid == (gid_t) -1))
104 {
105
106
107
108
109 result = lchmod (file, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO
110 | S_ISUID | S_ISGID | S_ISVTX));
111 }
112 # endif
113
114 return result;
115 }
116
117 #endif