annotate tests/test-fchownat.c @ 40196:e63f5d3edab5

relocatable-prog: Update documentation. * doc/relocatable-maint.texi (Supporting Relocation): Update to match the recent changes.
author Bruno Haible <bruno@clisp.org>
date Sun, 24 Feb 2019 01:49:15 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12291
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Tests of fchownat.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
12291
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
12291
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 #include <config.h>
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #include <unistd.h>
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12291
diff changeset
23 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12291
diff changeset
24 SIGNATURE_CHECK (fchownat, int, (int, char const *, uid_t, gid_t, int));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12291
diff changeset
25
12291
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 #include <fcntl.h>
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27 #include <errno.h>
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
28 #include <stdbool.h>
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 #include <stdio.h>
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 #include <stdlib.h>
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 #include <sys/stat.h>
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33 #include "mgetgroups.h"
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34 #include "openat.h"
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 #include "stat-time.h"
12842
b2bf8684a2db tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
36 #include "ignore-value.h"
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
37 #include "macros.h"
12291
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39 #define BASE "test-fchownat.t"
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 #include "test-chown.h"
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 #include "test-lchown.h"
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 static int dfd = AT_FDCWD;
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 /* Wrapper around fchownat to test chown behavior. */
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47 static int
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 do_chown (char const *name, uid_t user, gid_t group)
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49 {
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 return chownat (dfd, name, user, group);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 }
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 /* Wrapper around fchownat to test lchown behavior. */
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 static int
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 do_lchown (char const *name, uid_t user, gid_t group)
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 {
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 return lchownat (dfd, name, user, group);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 }
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 int
15287
223683be3038 openat, fdopendir tests: Fix link errors.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
61 main (int argc _GL_UNUSED, char *argv[])
12291
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 {
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
63 int result1; /* Skip because of no chown/symlink support. */
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 int result2; /* Skip because of no lchown support. */
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 /* Clean up any trash from prior testsuite runs. */
12842
b2bf8684a2db tests: silence warning about system return
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
67 ignore_value (system ("rm -rf " BASE "*"));
12291
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68
15700
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
69 /* Test behaviour for invalid file descriptors. */
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
70 {
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
71 errno = 0;
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
72 ASSERT (fchownat (-1, "foo", getuid (), getgid (), 0) == -1);
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
73 ASSERT (errno == EBADF);
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
74 }
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
75 {
17292
3a09cc104f4c tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
76 close (99);
15700
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
77 errno = 0;
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
78 ASSERT (fchownat (99, "foo", getuid (), getgid (), 0) == -1);
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
79 ASSERT (errno == EBADF);
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
80 }
bbc06c8e298f openat tests: EBADF tests.
Bruno Haible <bruno@clisp.org>
parents: 15287
diff changeset
81
12291
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
82 /* Basic tests. */
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83 result1 = test_chown (do_chown, true);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 result2 = test_lchown (do_lchown, result1 == 0);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
85 dfd = open (".", O_RDONLY);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
86 ASSERT (0 <= dfd);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 ASSERT (test_chown (do_chown, false) == result1);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
88 ASSERT (test_lchown (do_lchown, false) == result2);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 /* We expect 0/0, 0/77, or 77/77, but not 77/0. */
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
90 ASSERT (result1 <= result2);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
91 ASSERT (close (dfd) == 0);
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
92
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
93 /* FIXME - add additional tests of dfd not at current directory. */
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
94 return result1 | result2;
3c66159f6ce1 openat: detect Solaris fchownat bug
Eric Blake <ebb9@byu.net>
parents:
diff changeset
95 }