2 * Copyright (c) 2016 IBM Corporation
3 * Copyright (c) 2003-2007 Tim Kientzle
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * This test case's code has been derived from test_entry.c
31 DEFINE_TEST(test_schily_xattr_pax)
34 struct archive_entry *ae;
35 const char *refname = "test_read_pax_schily_xattr.tar";
36 const char *xname; /* For xattr tests. */
37 const void *xval; /* For xattr tests. */
38 size_t xsize; /* For xattr tests. */
39 const char *string, *array;
41 assert((a = archive_read_new()) != NULL);
42 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
43 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
45 extract_reference_file(refname);
46 assertEqualIntA(a, ARCHIVE_OK,
47 archive_read_open_filename(a, refname, 10240));
49 assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae));
50 assertEqualInt(2, archive_entry_xattr_count(ae));
51 assertEqualInt(2, archive_entry_xattr_reset(ae));
53 assertEqualInt(0, archive_entry_xattr_next(ae, &xname, &xval, &xsize));
54 assertEqualString(xname, "security.selinux");
55 string = "system_u:object_r:unlabeled_t:s0";
56 assertEqualString(xval, string);
57 /* the xattr's value also contains the terminating \0 */
58 assertEqualInt((int)xsize, strlen(string) + 1);
60 assertEqualInt(0, archive_entry_xattr_next(ae, &xname, &xval, &xsize));
61 assertEqualString(xname, "security.ima");
62 assertEqualInt((int)xsize, 265);
63 /* we only compare the first 12 bytes */
64 array = "\x03\x02\x04\xb0\xe9\xd6\x79\x01\x00\x2b\xad\x1e";
65 assertEqualMem(xval, array, 12);
67 /* Close the archive. */
68 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
69 assertEqualInt(ARCHIVE_OK, archive_read_free(a));