1 /*- 2 * Copyright (c) 2003-2007 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 /* 30 PLEASE use latest cdrtools at least mkisofs version is 2.01.01a63 or later. 31 Old version mkisofs made wrong "SL" System Use Entry of RRIP. 32 33 Execute the following command to rebuild the data for this program: 34 tail -n +34 test_read_format_isorr_new_bz2.c | /bin/sh 35 36 rm -rf /tmp/iso 37 mkdir /tmp/iso 38 mkdir /tmp/iso/dir 39 echo "hello" >/tmp/iso/file 40 dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file 41 ln /tmp/iso/file /tmp/iso/hardlink 42 (cd /tmp/iso; ln -s file symlink) 43 (cd /tmp/iso; ln -s /tmp/ symlink2) 44 (cd /tmp/iso; ln -s /tmp/../ symlink3) 45 (cd /tmp/iso; ln -s .././../tmp/ symlink4) 46 (cd /tmp/iso; ln -s .///file symlink5) 47 (cd /tmp/iso; ln -s /tmp//../ symlink6) 48 TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir 49 TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink 50 F=test_read_format_iso_rockridge_new.iso.Z 51 mkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F 52 uuencode $F $F > $F.uu 53 exit 1 54 */ 55 56 DEFINE_TEST(test_read_format_isorr_new_bz2) 57 { 58 const char *refname = "test_read_format_iso_rockridge_new.iso.Z"; 59 struct archive_entry *ae; 60 struct archive *a; 61 const void *p; 62 size_t size; 63 int64_t offset; 64 int i; 65 66 extract_reference_file(refname); 67 assert((a = archive_read_new()) != NULL); 68 assertEqualInt(0, archive_read_support_filter_all(a)); 69 assertEqualInt(0, archive_read_support_format_all(a)); 70 assertEqualInt(ARCHIVE_OK, 71 archive_read_open_filename(a, refname, 10240)); 72 73 /* Retrieve each of the 8 files on the ISO image and 74 * verify that each one is what we expect. */ 75 for (i = 0; i < 10; ++i) { 76 assertEqualInt(0, archive_read_next_header(a, &ae)); 77 78 assertEqualInt(archive_entry_is_encrypted(ae), 0); 79 assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 80 81 if (strcmp(".", archive_entry_pathname(ae)) == 0) { 82 /* '.' root directory. */ 83 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 84 assertEqualInt(2048, archive_entry_size(ae)); 85 /* Now, we read timestamp recorded by RRIP "TF". */ 86 assertEqualInt(86401, archive_entry_mtime(ae)); 87 assertEqualInt(0, archive_entry_mtime_nsec(ae)); 88 /* Now, we read links recorded by RRIP "PX". */ 89 assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 90 assertEqualInt(1, archive_entry_uid(ae)); 91 assertEqualIntA(a, ARCHIVE_EOF, 92 archive_read_data_block(a, &p, &size, &offset)); 93 assertEqualInt((int)size, 0); 94 } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { 95 /* A directory. */ 96 assertEqualString("dir", archive_entry_pathname(ae)); 97 assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 98 assertEqualInt(2048, archive_entry_size(ae)); 99 assertEqualInt(86401, archive_entry_mtime(ae)); 100 assertEqualInt(86401, archive_entry_atime(ae)); 101 assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 102 assertEqualInt(1, archive_entry_uid(ae)); 103 assertEqualInt(2, archive_entry_gid(ae)); 104 } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { 105 /* A regular file. */ 106 assertEqualString("file", archive_entry_pathname(ae)); 107 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 108 assertEqualInt(12345684, archive_entry_size(ae)); 109 assertEqualInt(0, 110 archive_read_data_block(a, &p, &size, &offset)); 111 assertEqualInt(0, offset); 112 assertEqualMem(p, "hello\n", 6); 113 assertEqualInt(86401, archive_entry_mtime(ae)); 114 assertEqualInt(86401, archive_entry_atime(ae)); 115 assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 116 assertEqualInt(1, archive_entry_uid(ae)); 117 assertEqualInt(2, archive_entry_gid(ae)); 118 } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { 119 /* A hardlink to the regular file. */ 120 /* Note: If "hardlink" gets returned before "file", 121 * then "hardlink" will get returned as a regular file 122 * and "file" will get returned as the hardlink. 123 * This test should tolerate that, since it's a 124 * perfectly permissible thing for libarchive to do. */ 125 assertEqualString("hardlink", archive_entry_pathname(ae)); 126 assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 127 assertEqualString("file", archive_entry_hardlink(ae)); 128 assertEqualInt(0, archive_entry_size_is_set(ae)); 129 assertEqualInt(0, archive_entry_size(ae)); 130 assertEqualInt(86401, archive_entry_mtime(ae)); 131 assertEqualInt(86401, archive_entry_atime(ae)); 132 assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 133 assertEqualInt(1, archive_entry_uid(ae)); 134 assertEqualInt(2, archive_entry_gid(ae)); 135 } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { 136 /* A symlink to the regular file. */ 137 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 138 assertEqualString("file", archive_entry_symlink(ae)); 139 assertEqualInt(0, archive_entry_size(ae)); 140 assertEqualInt(172802, archive_entry_mtime(ae)); 141 assertEqualInt(172802, archive_entry_atime(ae)); 142 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 143 assertEqualInt(1, archive_entry_uid(ae)); 144 assertEqualInt(2, archive_entry_gid(ae)); 145 } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { 146 /* A symlink to /tmp/ (an absolute path) */ 147 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 148 assertEqualString("/tmp/", archive_entry_symlink(ae)); 149 assertEqualInt(0, archive_entry_size(ae)); 150 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 151 assertEqualInt(1, archive_entry_uid(ae)); 152 assertEqualInt(2, archive_entry_gid(ae)); 153 } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { 154 /* A symlink to /tmp/../ (with a ".." component) */ 155 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 156 assertEqualString("/tmp/../", archive_entry_symlink(ae)); 157 assertEqualInt(0, archive_entry_size(ae)); 158 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 159 assertEqualInt(1, archive_entry_uid(ae)); 160 assertEqualInt(2, archive_entry_gid(ae)); 161 } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { 162 /* A symlink to a path with ".." and "." components */ 163 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 164 assertEqualString(".././../tmp/", 165 archive_entry_symlink(ae)); 166 assertEqualInt(0, archive_entry_size(ae)); 167 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 168 assertEqualInt(1, archive_entry_uid(ae)); 169 assertEqualInt(2, archive_entry_gid(ae)); 170 } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { 171 /* A symlink to the regular file with "/" components. */ 172 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 173 assertEqualString(".///file", archive_entry_symlink(ae)); 174 assertEqualInt(0, archive_entry_size(ae)); 175 assertEqualInt(172802, archive_entry_mtime(ae)); 176 assertEqualInt(172802, archive_entry_atime(ae)); 177 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 178 assertEqualInt(1, archive_entry_uid(ae)); 179 assertEqualInt(2, archive_entry_gid(ae)); 180 } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { 181 /* A symlink to /tmp//../ 182 * (with "/" and ".." components) */ 183 assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 184 assertEqualString("/tmp//../", archive_entry_symlink(ae)); 185 assertEqualInt(0, archive_entry_size(ae)); 186 assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 187 assertEqualInt(1, archive_entry_uid(ae)); 188 assertEqualInt(2, archive_entry_gid(ae)); 189 } else { 190 failure("Saw a file that shouldn't have been there"); 191 assertEqualString(archive_entry_pathname(ae), ""); 192 } 193 } 194 195 /* End of archive. */ 196 assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 197 198 /* Verify archive format. */ 199 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS); 200 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 201 202 /* Close the archive. */ 203 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 204 assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 205 } 206 207 208