This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19 #include <unistd.h>
20
21 #include "signature.h"
22 SIGNATURE_CHECK (access, int, (const char *, int));
23
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <sys/stat.h>
27 #include "root-uid.h"
28 #include "macros.h"
29
30
31 #if !HAVE_GETEUID
32 # define geteuid() ROOT_UID
33 #endif
34
35 #define BASE "test-access.t"
36
37 int
38 main ()
39 {
40
41 unlink (BASE "f");
42 unlink (BASE "f1");
43 chmod (BASE "f2", 0600);
44 unlink (BASE "f2");
45
46 {
47 errno = 0;
48 ASSERT (access (BASE "f", R_OK) == -1);
49 ASSERT (errno == ENOENT);
50
51 errno = 0;
52 ASSERT (access (BASE "f", W_OK) == -1);
53 ASSERT (errno == ENOENT);
54
55 errno = 0;
56 ASSERT (access (BASE "f", X_OK) == -1);
57 ASSERT (errno == ENOENT);
58 }
59 {
60 ASSERT (close (creat (BASE "f1", 0700)) == 0);
61
62 ASSERT (access (BASE "f1", R_OK) == 0);
63 ASSERT (access (BASE "f1", W_OK) == 0);
64 ASSERT (access (BASE "f1", X_OK) == 0);
65 }
66 {
67 ASSERT (close (creat (BASE "f2", 0600)) == 0);
68 ASSERT (chmod (BASE "f2", 0400) == 0);
69
70 ASSERT (access (BASE "f2", R_OK) == 0);
71
72 if (geteuid () != ROOT_UID)
73 {
74 errno = 0;
75 ASSERT (access (BASE "f2", W_OK) == -1);
76 ASSERT (errno == EACCES);
77 }
78
79 #if defined _WIN32 && !defined __CYGWIN__
80
81 ASSERT (access (BASE "f2", X_OK) == 0);
82 #else
83 errno = 0;
84 ASSERT (access (BASE "f2", X_OK) == -1);
85 ASSERT (errno == EACCES);
86 #endif
87 }
88
89
90 ASSERT (unlink (BASE "f1") == 0);
91 ASSERT (chmod (BASE "f2", 0600) == 0);
92 ASSERT (unlink (BASE "f2") == 0);
93
94 return 0;
95 }