]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libarchive/libarchive/test/test_read_pax_xattr_rht_security_selinux.c
MFC r368207,368607:
[FreeBSD/stable/10.git] / contrib / libarchive / libarchive / test / test_read_pax_xattr_rht_security_selinux.c
1 /*-
2  * Copyright (c) 2016 IBM Corporation
3  * Copyright (c) 2003-2007 Tim Kientzle
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
15  *
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.
26  *
27  * This test case's code has been derived from test_entry.c
28  */
29 #include "test.h"
30
31 DEFINE_TEST(test_read_pax_xattr_rht_security_selinux)
32 {
33         struct archive *a;
34         struct archive_entry *ae;
35         const char *refname = "test_read_pax_xattr_rht_security_selinux.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;
40
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));
44
45         extract_reference_file(refname);
46         assertEqualIntA(a, ARCHIVE_OK,
47             archive_read_open_filename(a, refname, 10240));
48
49         assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae));
50         assertEqualInt(1, archive_entry_xattr_count(ae));
51         assertEqualInt(1, archive_entry_xattr_reset(ae));
52
53         assertEqualInt(0, archive_entry_xattr_next(ae, &xname, &xval, &xsize));
54         assertEqualString(xname, "security.selinux");
55         string = "system_u:object_r:admin_home_t:s0";
56         assertEqualMem(xval, string, xsize);
57         assertEqualInt((int)xsize, strlen(string));
58
59         /* Close the archive. */
60         assertEqualInt(ARCHIVE_OK, archive_read_close(a));
61         assertEqualInt(ARCHIVE_OK, archive_read_free(a));
62 }