xref: /freebsd/contrib/libarchive/libarchive/test/test_compat_solaris_tar_acl.c (revision 5ae59dec60e3815b621ae87f74a377cf3449ca55)
1 /*-
2  * Copyright (c) 2003-2009 Tim Kientzle
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 #include "test.h"
26 __FBSDID("$FreeBSD$");
27 
28 /*
29  * Exercise support for reading Solaris-style ACL data
30  * from tar archives.
31  *
32  * This should work on all systems, regardless of whether local
33  * filesystems support ACLs or not.
34  */
35 
36 DEFINE_TEST(test_compat_solaris_tar_acl)
37 {
38 	struct archive *a;
39 	struct archive_entry *ae;
40 	const char *reference1 = "test_compat_solaris_tar_acl.tar";
41 	int type, permset, tag, qual;
42 	const char *name;
43 
44 	/* Sample file generated on Solaris 10 */
45 	extract_reference_file(reference1);
46 	assert(NULL != (a = archive_read_new()));
47 	assertA(0 == archive_read_support_format_all(a));
48 	assertA(0 == archive_read_support_filter_all(a));
49 	assertA(0 == archive_read_open_filename(a, reference1, 512));
50 
51 	/* Archive has 1 entry with some ACLs set on it. */
52 	assertA(0 == archive_read_next_header(a, &ae));
53 	failure("Basic ACLs should set mode to 0644, not %04o",
54 	    archive_entry_mode(ae)&0777);
55 	assertEqualInt((archive_entry_mode(ae) & 0777), 0644);
56 	assertEqualInt(7, archive_entry_acl_reset(ae,
57 		ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
58 	assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae,
59 		ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
60 		&type, &permset, &tag, &qual, &name));
61 	assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type);
62 	assertEqualInt(006, permset);
63 	assertEqualInt(ARCHIVE_ENTRY_ACL_USER_OBJ, tag);
64 	assertEqualInt(-1, qual);
65 	assert(name == NULL);
66 
67 	assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae,
68 		ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
69 		&type, &permset, &tag, &qual, &name));
70 	assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type);
71 	assertEqualInt(004, permset);
72 	assertEqualInt(ARCHIVE_ENTRY_ACL_GROUP_OBJ, tag);
73 	assertEqualInt(-1, qual);
74 	assert(name == NULL);
75 
76 	assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae,
77 		ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
78 		&type, &permset, &tag, &qual, &name));
79 	assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type);
80 	assertEqualInt(004, permset);
81 	assertEqualInt(ARCHIVE_ENTRY_ACL_OTHER, tag);
82 	assertEqualInt(-1, qual);
83 	assert(name == NULL);
84 
85 	assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae,
86 		ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
87 		&type, &permset, &tag, &qual, &name));
88 	assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type);
89 	assertEqualInt(001, permset);
90 	assertEqualInt(ARCHIVE_ENTRY_ACL_USER, tag);
91 	assertEqualInt(71, qual);
92 	assertEqualString(name, "lp");
93 
94 	assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae,
95 		ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
96 		&type, &permset, &tag, &qual, &name));
97 	assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type);
98 	assertEqualInt(004, permset);
99 	assertEqualInt(ARCHIVE_ENTRY_ACL_USER, tag);
100 	assertEqualInt(666, qual);
101 	assertEqualString(name, "666");
102 
103 	assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae,
104 		ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
105 		&type, &permset, &tag, &qual, &name));
106 	assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type);
107 	assertEqualInt(007, permset);
108 	assertEqualInt(ARCHIVE_ENTRY_ACL_USER, tag);
109 	assertEqualInt(1000, qual);
110 	assertEqualString(name, "trasz");
111 
112 	assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae,
113 		ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
114 		&type, &permset, &tag, &qual, &name));
115 	assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type);
116 	assertEqualInt(004, permset);
117 	assertEqualInt(ARCHIVE_ENTRY_ACL_MASK, tag);
118 	assertEqualInt(-1, qual);
119 	assertEqualString(name, NULL);
120 
121 	assertEqualInt(ARCHIVE_EOF, archive_entry_acl_next(ae,
122 		ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
123 		&type, &permset, &tag, &qual, &name));
124 
125 	/* Close the archive. */
126 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
127 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
128 }
129