1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <attr/xattr.h>
#include <errno.h>
#include <string.h>
int
main (int argc, char *argv[])
{
int ret = -1;
int fd = 0;
char *filename = NULL;
struct stat stbuf = {0,};
if (argc > 1)
filename = argv[1];
if (!filename)
filename = "temp-xattr-test-file";
fd = open (filename, O_RDWR|O_CREAT);
if (fd < 0) {
fd = 0;
fprintf (stderr, "open failed : %s\n", strerror (errno));
goto out;
}
ret = unlink (filename);
if (ret < 0) {
fprintf (stderr, "unlink failed : %s\n", strerror (errno));
goto out;
}
ret = ftruncate (fd, 0);
if (ret < 0) {
fprintf (stderr, "ftruncate failed : %s\n", strerror (errno));
goto out;
}
ret = fstat (fd, &stbuf);
if (ret < 0) {
fprintf (stderr, "fstat failed : %s\n", strerror (errno));
goto out;
}
ret = fchmod (fd, 0640);
if (ret < 0) {
fprintf (stderr, "fchmod failed : %s\n", strerror (errno));
goto out;
}
ret = fchown (fd, 10001, 10001);
if (ret < 0) {
fprintf (stderr, "fchown failed : %s\n", strerror (errno));
goto out;
}
ret = fsync (fd);
if (ret < 0) {
fprintf (stderr, "fsync failed : %s\n", strerror (errno));
goto out;
}
ret = fsetxattr (fd, "trusted.xattr-test", "working", 8, 0);
if (ret < 0) {
fprintf (stderr, "fsetxattr failed : %s\n", strerror (errno));
goto out;
}
ret = fdatasync (fd);
if (ret < 0) {
fprintf (stderr, "fdatasync failed : %s\n", strerror (errno));
goto out;
}
ret = flistxattr (fd, NULL, 0);
if (ret <= 0) {
ret = -1;
fprintf (stderr, "flistxattr failed : %s\n", strerror (errno));
goto out;
}
ret = fgetxattr (fd, "trusted.xattr-test", NULL, 0);
if (ret <= 0) {
ret = -1;
fprintf (stderr, "fgetxattr failed : %s\n", strerror (errno));
goto out;
}
ret = fremovexattr (fd, "trusted.xattr-test");
if (ret < 0) {
fprintf (stderr, "fremovexattr failed : %s\n", strerror (errno));
goto out;
}
ret = 0;
out:
if (fd)
close (fd);
return ret;
}
|