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
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
* filemap_xattr.c
*
* Copyright (C) 2022 David Oberhollenzer <goliath@infraroot.at>
*/
#include "config.h"
#include "util/test.h"
#include "mkfs.h"
static const char *dev_selinux = "system_u:object_r:device_t:s0";
static const char *zero_selinux = "system_u:object_r:zero_device_t:s0";
static const char *rfkill_selinux = "system_u:object_r:wireless_device_t:s0";
static const sqfs_u8 rfkill_acl[] = {
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00,
0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x06, 0x00,
0xe8, 0x03, 0x00, 0x00, 0x04, 0x00, 0x06, 0x00,
0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x06, 0x00,
0xff, 0xff, 0xff, 0xff, 0x20, 0x00, 0x04, 0x00,
0xff, 0xff, 0xff, 0xff
};
int main(int argc, char **argv)
{
struct XattrMapPattern *pat;
struct XattrMapEntry *ent;
struct XattrMap *map;
int ret;
(void)argc; (void)argv;
map = xattr_open_map_file(TEST_PATH);
TEST_NOT_NULL(map);
/* the third pattern */
pat = map->patterns;
TEST_NOT_NULL(pat);
TEST_STR_EQUAL(pat->path, "dev/rfkill");
ent = pat->entries;
TEST_NOT_NULL(ent);
TEST_STR_EQUAL(ent->key, "system.posix_acl_access");
TEST_EQUAL_UI(ent->value_len, sizeof(rfkill_acl));
ret = memcmp(ent->value, rfkill_acl, ent->value_len);
TEST_EQUAL_I(ret, 0);
ent = ent->next;
TEST_NOT_NULL(ent);
TEST_STR_EQUAL(ent->key, "security.selinux");
TEST_EQUAL_UI(ent->value_len, strlen(rfkill_selinux));
ret = memcmp(ent->value, rfkill_selinux, ent->value_len);
TEST_EQUAL_I(ret, 0);
ent = ent->next;
TEST_NULL(ent);
/* the second pattern */
pat = pat->next;
TEST_NOT_NULL(pat);
TEST_STR_EQUAL(pat->path, "dev/zero");
ent = pat->entries;
TEST_NOT_NULL(ent);
TEST_STR_EQUAL(ent->key, "security.selinux");
TEST_EQUAL_UI(ent->value_len, strlen(zero_selinux));
ret = memcmp(ent->value, zero_selinux, ent->value_len);
TEST_EQUAL_I(ret, 0);
ent = ent->next;
TEST_NULL(ent);
/* the first pattern */
pat = pat->next;
TEST_NOT_NULL(pat);
TEST_STR_EQUAL(pat->path, "dev");
ent = pat->entries;
TEST_NOT_NULL(ent);
TEST_STR_EQUAL(ent->key, "security.selinux");
TEST_EQUAL_UI(ent->value_len, strlen(dev_selinux));
ret = memcmp(ent->value, dev_selinux, ent->value_len);
TEST_EQUAL_I(ret, 0);
ent = ent->next;
TEST_NULL(ent);
/* no more patterns */
pat = pat->next;
TEST_NULL(pat);
xattr_close_map_file(map);
return EXIT_SUCCESS;
}
|