1228753Smm/*- 2228753Smm * Copyright (c) 2003-2007 Tim Kientzle 3228753Smm * All rights reserved. 4228753Smm * 5228753Smm * Redistribution and use in source and binary forms, with or without 6228753Smm * modification, are permitted provided that the following conditions 7228753Smm * are met: 8228753Smm * 1. Redistributions of source code must retain the above copyright 9228753Smm * notice, this list of conditions and the following disclaimer. 10228753Smm * 2. Redistributions in binary form must reproduce the above copyright 11228753Smm * notice, this list of conditions and the following disclaimer in the 12228753Smm * documentation and/or other materials provided with the distribution. 13228753Smm * 14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24228753Smm */ 25228753Smm#include "test.h" 26228763Smm__FBSDID("$FreeBSD: stable/10/contrib/libarchive/libarchive/test/test_read_format_isorr_bz2.c 313571 2017-02-11 00:56:18Z mm $"); 27228753Smm 28228753Smm/* 29313571SmmPLEASE use old cdrtools; mkisofs version is 2.01. 30228753SmmThis version mkisofs made wrong "SL" System Use Entry of RRIP. 31228753Smm 32228753SmmExecute the following command to rebuild the data for this program: 33228753Smm tail -n +34 test_read_format_isorr_bz2.c | /bin/sh 34228753Smm 35228753Smmrm -rf /tmp/iso 36228753Smmmkdir /tmp/iso 37228753Smmmkdir /tmp/iso/dir 38228753Smmecho "hello" >/tmp/iso/file 39228753Smmdd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file 40228753Smmln /tmp/iso/file /tmp/iso/hardlink 41228753Smm(cd /tmp/iso; ln -s file symlink) 42228753Smm(cd /tmp/iso; ln -s /tmp/ symlink2) 43228753Smm(cd /tmp/iso; ln -s /tmp/../ symlink3) 44228753Smm(cd /tmp/iso; ln -s .././../tmp/ symlink4) 45228753Smm(cd /tmp/iso; ln -s .///file symlink5) 46228753Smm(cd /tmp/iso; ln -s /tmp//../ symlink6) 47228753SmmTZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir 48228753SmmTZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink /tmp/iso/symlink5 49228753SmmF=test_read_format_iso_rockridge.iso.Z 50228753Smmmkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F 51228753Smmuuencode $F $F > $F.uu 52228753Smmexit 1 53228753Smm */ 54228753Smm 55228753SmmDEFINE_TEST(test_read_format_isorr_bz2) 56228753Smm{ 57228753Smm const char *refname = "test_read_format_iso_rockridge.iso.Z"; 58228753Smm struct archive_entry *ae; 59228753Smm struct archive *a; 60228753Smm const void *p; 61228753Smm size_t size; 62232153Smm int64_t offset; 63228753Smm int i; 64228753Smm 65228753Smm extract_reference_file(refname); 66228753Smm assert((a = archive_read_new()) != NULL); 67232153Smm assertEqualInt(0, archive_read_support_filter_all(a)); 68228753Smm assertEqualInt(0, archive_read_support_format_all(a)); 69228753Smm assertEqualInt(ARCHIVE_OK, 70228753Smm archive_read_open_filename(a, refname, 10240)); 71228753Smm 72228753Smm /* Retrieve each of the 8 files on the ISO image and 73228753Smm * verify that each one is what we expect. */ 74228753Smm for (i = 0; i < 10; ++i) { 75228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 76302001Smm 77302001Smm assertEqualInt(archive_entry_is_encrypted(ae), 0); 78302001Smm assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 79228753Smm 80228753Smm if (strcmp(".", archive_entry_pathname(ae)) == 0) { 81228753Smm /* '.' root directory. */ 82228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 83228753Smm assertEqualInt(2048, archive_entry_size(ae)); 84228753Smm /* Now, we read timestamp recorded by RRIP "TF". */ 85228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 86228753Smm assertEqualInt(0, archive_entry_mtime_nsec(ae)); 87228753Smm /* Now, we read links recorded by RRIP "PX". */ 88228753Smm assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 89228753Smm assertEqualInt(1, archive_entry_uid(ae)); 90228753Smm assertEqualIntA(a, ARCHIVE_EOF, 91228753Smm archive_read_data_block(a, &p, &size, &offset)); 92228753Smm assertEqualInt((int)size, 0); 93228753Smm } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { 94228753Smm /* A directory. */ 95228753Smm assertEqualString("dir", archive_entry_pathname(ae)); 96228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 97228753Smm assertEqualInt(2048, archive_entry_size(ae)); 98228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 99228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 100228753Smm assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 101228753Smm assertEqualInt(1, archive_entry_uid(ae)); 102228753Smm assertEqualInt(2, archive_entry_gid(ae)); 103228753Smm } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { 104228753Smm /* A regular file. */ 105228753Smm assertEqualString("file", archive_entry_pathname(ae)); 106228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 107228753Smm assertEqualInt(12345684, archive_entry_size(ae)); 108228753Smm assertEqualInt(0, 109228753Smm archive_read_data_block(a, &p, &size, &offset)); 110228753Smm assertEqualInt(0, offset); 111228753Smm assertEqualMem(p, "hello\n", 6); 112228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 113228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 114228753Smm assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 115228753Smm assertEqualInt(1, archive_entry_uid(ae)); 116228753Smm assertEqualInt(2, archive_entry_gid(ae)); 117228753Smm } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { 118228753Smm /* A hardlink to the regular file. */ 119228753Smm /* Note: If "hardlink" gets returned before "file", 120228753Smm * then "hardlink" will get returned as a regular file 121228753Smm * and "file" will get returned as the hardlink. 122228753Smm * This test should tolerate that, since it's a 123228753Smm * perfectly permissible thing for libarchive to do. */ 124228753Smm assertEqualString("hardlink", archive_entry_pathname(ae)); 125228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 126228753Smm assertEqualString("file", archive_entry_hardlink(ae)); 127228753Smm assertEqualInt(0, archive_entry_size_is_set(ae)); 128228753Smm assertEqualInt(0, archive_entry_size(ae)); 129228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 130228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 131228753Smm assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 132228753Smm assertEqualInt(1, archive_entry_uid(ae)); 133228753Smm assertEqualInt(2, archive_entry_gid(ae)); 134228753Smm } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { 135228753Smm /* A symlink to the regular file. */ 136228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 137228753Smm assertEqualString("file", archive_entry_symlink(ae)); 138228753Smm assertEqualInt(0, archive_entry_size(ae)); 139228753Smm assertEqualInt(172802, archive_entry_mtime(ae)); 140228753Smm assertEqualInt(172802, archive_entry_atime(ae)); 141228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 142228753Smm assertEqualInt(1, archive_entry_uid(ae)); 143228753Smm assertEqualInt(2, archive_entry_gid(ae)); 144228753Smm } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { 145228753Smm /* A symlink to /tmp (an absolute path) */ 146228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 147228753Smm assertEqualString("/tmp", archive_entry_symlink(ae)); 148228753Smm assertEqualInt(0, archive_entry_size(ae)); 149228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 150228753Smm assertEqualInt(1, archive_entry_uid(ae)); 151228753Smm assertEqualInt(2, archive_entry_gid(ae)); 152228753Smm } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { 153228753Smm /* A symlink to /tmp/.. (with a ".." component) */ 154228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 155228753Smm assertEqualString("/tmp/..", archive_entry_symlink(ae)); 156228753Smm assertEqualInt(0, archive_entry_size(ae)); 157228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 158228753Smm assertEqualInt(1, archive_entry_uid(ae)); 159228753Smm assertEqualInt(2, archive_entry_gid(ae)); 160228753Smm } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { 161228753Smm /* A symlink to a path with ".." and "." components */ 162228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 163228753Smm assertEqualString(".././../tmp", 164228753Smm archive_entry_symlink(ae)); 165228753Smm assertEqualInt(0, archive_entry_size(ae)); 166228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 167228753Smm assertEqualInt(1, archive_entry_uid(ae)); 168228753Smm assertEqualInt(2, archive_entry_gid(ae)); 169228753Smm } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { 170228753Smm /* A symlink to the regular file with "/" components. */ 171228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 172228753Smm assertEqualString(".///file", archive_entry_symlink(ae)); 173228753Smm assertEqualInt(0, archive_entry_size(ae)); 174228753Smm assertEqualInt(172802, archive_entry_mtime(ae)); 175228753Smm assertEqualInt(172802, archive_entry_atime(ae)); 176228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 177228753Smm assertEqualInt(1, archive_entry_uid(ae)); 178228753Smm assertEqualInt(2, archive_entry_gid(ae)); 179228753Smm } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { 180228753Smm /* A symlink to /tmp//.. 181228753Smm * (with "/" and ".." components) */ 182228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 183228753Smm assertEqualString("/tmp//..", archive_entry_symlink(ae)); 184228753Smm assertEqualInt(0, archive_entry_size(ae)); 185228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 186228753Smm assertEqualInt(1, archive_entry_uid(ae)); 187228753Smm assertEqualInt(2, archive_entry_gid(ae)); 188228753Smm } else { 189228753Smm failure("Saw a file that shouldn't have been there"); 190228753Smm assertEqualString(archive_entry_pathname(ae), ""); 191228753Smm } 192228753Smm } 193228753Smm 194228753Smm /* End of archive. */ 195228753Smm assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 196228753Smm 197228753Smm /* Verify archive format. */ 198248616Smm assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS); 199228753Smm assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 200228753Smm 201228753Smm /* Close the archive. */ 202232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 203232153Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 204228753Smm} 205228753Smm 206228753Smm 207