annotate tests/test-chown.h @ 17249:e542fd46ad6f

maint: update all copyright year number ranges Run "make update-copyright". Compare to commit 1602f0a from last year. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Tue, 01 Jan 2013 00:50:58 +0000
parents 8250f2777afc
children 7266df63bb4d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Tests of chown.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 Copyright (C) 2009-2013 Free Software Foundation, Inc.
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
12469
8b48f88c47f1 test-utimens: avoid spurious failure
Eric Blake <ebb9@byu.net>
parents: 12397
diff changeset
19 #include "nap.h"
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #if !HAVE_GETEGID
12381
e63e3a5265e5 mgetgroups: avoid argument promotion issues with -1
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
22 # define getegid() ((gid_t) -1)
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
23 #endif
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
24
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25 /* This file is designed to test chown(n,o,g) and
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 chownat(AT_FDCWD,n,o,g,0). FUNC is the function to test. Assumes
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27 that BASE and ASSERT are already defined, and that appropriate
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
28 headers are already included. If PRINT, warn before skipping
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 symlink tests with status 77. */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 static int
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32 test_chown (int (*func) (char const *, uid_t, gid_t), bool print)
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33 {
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34 struct stat st1;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 struct stat st2;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36 gid_t *gids = NULL;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 int gids_count;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38 int result;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 /* Solaris 8 is interesting - if the current process belongs to
14569
ea9f5df77acd maint: remove doubled words in comments, e.g., s/a a/a/
Jim Meyering <meyering@redhat.com>
parents: 14568
diff changeset
41 multiple groups, the current directory is owned by a group that
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 the current process belongs to but different than getegid(), and
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 the current directory does not have the S_ISGID bit, then regular
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 files created in the directory belong to the directory's group,
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 but symlinks belong to the current effective group id. If
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 S_ISGID is set, then both files and symlinks belong to the
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47 directory's group. However, it is possible to run the testsuite
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 from within a directory owned by a group we don't belong to, in
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49 which case all things that we create belong to the current
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 effective gid. So, work around the issues by creating a
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 subdirectory (we are guaranteed that the subdirectory will be
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52 owned by one of our current groups), change ownership of that
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 directory to the current effective gid (which will thus succeed),
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 then create all other files within that directory (eliminating
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 questions on whether inheritance or current id triumphs, since
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 the two methods resolve to the same gid). */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 ASSERT (mkdir (BASE "dir", 0700) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 ASSERT (stat (BASE "dir", &st1) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 /* Filter out mingw, which has no concept of groups. */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 result = func (BASE "dir", st1.st_uid, getegid ());
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 if (result == -1 && errno == ENOSYS)
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
63 {
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 ASSERT (rmdir (BASE "dir") == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65 if (print)
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 fputs ("skipping test: no support for ownership\n", stderr);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 return 77;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 }
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
69 ASSERT (result == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
70
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
71 ASSERT (close (creat (BASE "dir/file", 0600)) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
72 ASSERT (stat (BASE "dir/file", &st1) == 0);
12381
e63e3a5265e5 mgetgroups: avoid argument promotion issues with -1
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
73 ASSERT (st1.st_uid != (uid_t) -1);
14568
9633c7e65d40 test-chown.h: correct a cast
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
74 ASSERT (st1.st_gid != (gid_t) -1);
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 ASSERT (st1.st_gid == getegid ());
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 /* Sanity check of error cases. */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
78 errno = 0;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
79 ASSERT (func ("", -1, -1) == -1);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
80 ASSERT (errno == ENOENT);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
81 errno = 0;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
82 ASSERT (func ("no_such", -1, -1) == -1);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83 ASSERT (errno == ENOENT);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 errno = 0;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
85 ASSERT (func ("no_such/", -1, -1) == -1);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
86 ASSERT (errno == ENOENT);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 errno = 0;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
88 ASSERT (func (BASE "dir/file/", -1, -1) == -1);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 ASSERT (errno == ENOTDIR);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
90
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
91 /* Check that -1 does not alter ownership. */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
92 ASSERT (func (BASE "dir/file", -1, st1.st_gid) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
93 ASSERT (func (BASE "dir/file", st1.st_uid, -1) == 0);
12381
e63e3a5265e5 mgetgroups: avoid argument promotion issues with -1
Eric Blake <ebb9@byu.net>
parents: 12316
diff changeset
94 ASSERT (func (BASE "dir/file", (uid_t) -1, (gid_t) -1) == 0);
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
95 ASSERT (stat (BASE "dir/file", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
96 ASSERT (st1.st_uid == st2.st_uid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
97 ASSERT (st1.st_gid == st2.st_gid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
98
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
99 /* Even if the values aren't changing, ctime is required to change
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
100 if at least one argument is not -1. */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
101 nap ();
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
102 ASSERT (func (BASE "dir/file", st1.st_uid, st1.st_gid) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
103 ASSERT (stat (BASE "dir/file", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
104 ASSERT (st1.st_ctime < st2.st_ctime
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
105 || (st1.st_ctime == st2.st_ctime
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
106 && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2)));
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
107
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
108 /* Test symlink behavior. */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
109 if (symlink ("link", BASE "dir/link2"))
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
110 {
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
111 ASSERT (unlink (BASE "dir/file") == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
112 ASSERT (rmdir (BASE "dir") == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
113 if (print)
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
114 fputs ("skipping test: symlinks not supported on this file system\n",
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
115 stderr);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
116 return 77;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
117 }
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
118 errno = 0;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
119 ASSERT (func (BASE "dir/link2", -1, -1) == -1);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
120 ASSERT (errno == ENOENT);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
121 errno = 0;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
122 ASSERT (func (BASE "dir/link2/", st1.st_uid, st1.st_gid) == -1);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
123 ASSERT (errno == ENOENT);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
124 ASSERT (symlink ("file", BASE "dir/link") == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
125
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
126 /* For non-privileged users, chown can only portably succeed at
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
127 changing group ownership of a file we own. If we belong to at
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
128 least two groups, then verifying the correct change is simple.
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
129 But if we belong to only one group, then we fall back on the
12397
799c920db2a5 mgetgroups: reduce duplicate listings
Eric Blake <ebb9@byu.net>
parents: 12381
diff changeset
130 other observable effect of chown: the ctime must be updated. */
799c920db2a5 mgetgroups: reduce duplicate listings
Eric Blake <ebb9@byu.net>
parents: 12381
diff changeset
131 gids_count = mgetgroups (NULL, st1.st_gid, &gids);
799c920db2a5 mgetgroups: reduce duplicate listings
Eric Blake <ebb9@byu.net>
parents: 12381
diff changeset
132 if (1 < gids_count)
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
133 {
12397
799c920db2a5 mgetgroups: reduce duplicate listings
Eric Blake <ebb9@byu.net>
parents: 12381
diff changeset
134 ASSERT (gids[1] != st1.st_gid);
799c920db2a5 mgetgroups: reduce duplicate listings
Eric Blake <ebb9@byu.net>
parents: 12381
diff changeset
135 ASSERT (gids[1] != (gid_t) -1);
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
136 ASSERT (lstat (BASE "dir/link", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
137 ASSERT (st1.st_uid == st2.st_uid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
138 ASSERT (st1.st_gid == st2.st_gid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
139 ASSERT (lstat (BASE "dir/link2", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
140 ASSERT (st1.st_uid == st2.st_uid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
141 ASSERT (st1.st_gid == st2.st_gid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
142
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
143 errno = 0;
12397
799c920db2a5 mgetgroups: reduce duplicate listings
Eric Blake <ebb9@byu.net>
parents: 12381
diff changeset
144 ASSERT (func (BASE "dir/link2/", -1, gids[1]) == -1);
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
145 ASSERT (errno == ENOTDIR);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
146 ASSERT (stat (BASE "dir/file", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
147 ASSERT (st1.st_uid == st2.st_uid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
148 ASSERT (st1.st_gid == st2.st_gid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
149 ASSERT (lstat (BASE "dir/link", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
150 ASSERT (st1.st_uid == st2.st_uid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
151 ASSERT (st1.st_gid == st2.st_gid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
152 ASSERT (lstat (BASE "dir/link2", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
153 ASSERT (st1.st_uid == st2.st_uid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
154 ASSERT (st1.st_gid == st2.st_gid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
155
12397
799c920db2a5 mgetgroups: reduce duplicate listings
Eric Blake <ebb9@byu.net>
parents: 12381
diff changeset
156 ASSERT (func (BASE "dir/link2", -1, gids[1]) == 0);
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
157 ASSERT (stat (BASE "dir/file", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
158 ASSERT (st1.st_uid == st2.st_uid);
12397
799c920db2a5 mgetgroups: reduce duplicate listings
Eric Blake <ebb9@byu.net>
parents: 12381
diff changeset
159 ASSERT (gids[1] == st2.st_gid);
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
160 ASSERT (lstat (BASE "dir/link", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
161 ASSERT (st1.st_uid == st2.st_uid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
162 ASSERT (st1.st_gid == st2.st_gid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
163 ASSERT (lstat (BASE "dir/link2", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
164 ASSERT (st1.st_uid == st2.st_uid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
165 ASSERT (st1.st_gid == st2.st_gid);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
166 }
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
167 else
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
168 {
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
169 struct stat l1;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
170 struct stat l2;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
171 ASSERT (stat (BASE "dir/file", &st1) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
172 ASSERT (lstat (BASE "dir/link", &l1) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
173 ASSERT (lstat (BASE "dir/link2", &l2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
174
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
175 nap ();
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
176 errno = 0;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
177 ASSERT (func (BASE "dir/link2/", -1, st1.st_gid) == -1);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
178 ASSERT (errno == ENOTDIR);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
179 ASSERT (stat (BASE "dir/file", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
180 ASSERT (st1.st_ctime == st2.st_ctime);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
181 ASSERT (get_stat_ctime_ns (&st1) == get_stat_ctime_ns (&st2));
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
182 ASSERT (lstat (BASE "dir/link", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
183 ASSERT (l1.st_ctime == st2.st_ctime);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
184 ASSERT (get_stat_ctime_ns (&l1) == get_stat_ctime_ns (&st2));
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
185 ASSERT (lstat (BASE "dir/link2", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
186 ASSERT (l2.st_ctime == st2.st_ctime);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
187 ASSERT (get_stat_ctime_ns (&l2) == get_stat_ctime_ns (&st2));
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
188
12397
799c920db2a5 mgetgroups: reduce duplicate listings
Eric Blake <ebb9@byu.net>
parents: 12381
diff changeset
189 ASSERT (func (BASE "dir/link2", -1, st1.st_gid) == 0);
12289
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
190 ASSERT (stat (BASE "dir/file", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
191 ASSERT (st1.st_ctime < st2.st_ctime
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
192 || (st1.st_ctime == st2.st_ctime
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
193 && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2)));
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
194 ASSERT (lstat (BASE "dir/link", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
195 ASSERT (l1.st_ctime == st2.st_ctime);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
196 ASSERT (get_stat_ctime_ns (&l1) == get_stat_ctime_ns (&st2));
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
197 ASSERT (lstat (BASE "dir/link2", &st2) == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
198 ASSERT (l2.st_ctime == st2.st_ctime);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
199 ASSERT (get_stat_ctime_ns (&l2) == get_stat_ctime_ns (&st2));
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
200 }
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
201
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
202 /* Cleanup. */
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
203 free (gids);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
204 ASSERT (unlink (BASE "dir/file") == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
205 ASSERT (unlink (BASE "dir/link") == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
206 ASSERT (unlink (BASE "dir/link2") == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
207 ASSERT (rmdir (BASE "dir") == 0);
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
208 return 0;
e973be2fb39f chown: detect Solaris and FreeBSD bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
209 }