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$"); 27228753Smm 28228753Smm 29228753Smm/* 30228753SmmPLEASE use latest cdrtools at least mkisofs version is 2.01.01a63 or later. 31228753SmmOld version mkisofs made wrong "SL" System Use Entry of RRIP. 32228753Smm 33228753SmmExecute the following command to rebuild the data for this program: 34228753Smm tail -n +34 test_read_format_isorr_new_bz2.c | /bin/sh 35228753Smm 36228753Smmrm -rf /tmp/iso 37228753Smmmkdir /tmp/iso 38228753Smmmkdir /tmp/iso/dir 39228753Smmecho "hello" >/tmp/iso/file 40228753Smmdd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file 41228753Smmln /tmp/iso/file /tmp/iso/hardlink 42228753Smm(cd /tmp/iso; ln -s file symlink) 43228753Smm(cd /tmp/iso; ln -s /tmp/ symlink2) 44228753Smm(cd /tmp/iso; ln -s /tmp/../ symlink3) 45228753Smm(cd /tmp/iso; ln -s .././../tmp/ symlink4) 46228753Smm(cd /tmp/iso; ln -s .///file symlink5) 47228753Smm(cd /tmp/iso; ln -s /tmp//../ symlink6) 48228753SmmTZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir 49228753SmmTZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink 50228753SmmF=test_read_format_iso_rockridge_new.iso.Z 51228753Smmmkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F 52228753Smmuuencode $F $F > $F.uu 53228753Smmexit 1 54228753Smm */ 55228753Smm 56228753SmmDEFINE_TEST(test_read_format_isorr_new_bz2) 57228753Smm{ 58228753Smm const char *refname = "test_read_format_iso_rockridge_new.iso.Z"; 59228753Smm struct archive_entry *ae; 60228753Smm struct archive *a; 61228753Smm const void *p; 62228753Smm size_t size; 63232153Smm int64_t offset; 64228753Smm int i; 65228753Smm 66228753Smm extract_reference_file(refname); 67228753Smm assert((a = archive_read_new()) != NULL); 68232153Smm assertEqualInt(0, archive_read_support_filter_all(a)); 69228753Smm assertEqualInt(0, archive_read_support_format_all(a)); 70228753Smm assertEqualInt(ARCHIVE_OK, 71228753Smm archive_read_open_filename(a, refname, 10240)); 72228753Smm 73228753Smm /* Retrieve each of the 8 files on the ISO image and 74228753Smm * verify that each one is what we expect. */ 75228753Smm for (i = 0; i < 10; ++i) { 76228753Smm assertEqualInt(0, archive_read_next_header(a, &ae)); 77228753Smm 78228753Smm if (strcmp(".", archive_entry_pathname(ae)) == 0) { 79228753Smm /* '.' root directory. */ 80228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 81228753Smm assertEqualInt(2048, archive_entry_size(ae)); 82228753Smm /* Now, we read timestamp recorded by RRIP "TF". */ 83228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 84228753Smm assertEqualInt(0, archive_entry_mtime_nsec(ae)); 85228753Smm /* Now, we read links recorded by RRIP "PX". */ 86228753Smm assertEqualInt(3, archive_entry_stat(ae)->st_nlink); 87228753Smm assertEqualInt(1, archive_entry_uid(ae)); 88228753Smm assertEqualIntA(a, ARCHIVE_EOF, 89228753Smm archive_read_data_block(a, &p, &size, &offset)); 90228753Smm assertEqualInt((int)size, 0); 91228753Smm } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { 92228753Smm /* A directory. */ 93228753Smm assertEqualString("dir", archive_entry_pathname(ae)); 94228753Smm assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); 95228753Smm assertEqualInt(2048, archive_entry_size(ae)); 96228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 97228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 98228753Smm assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 99228753Smm assertEqualInt(1, archive_entry_uid(ae)); 100228753Smm assertEqualInt(2, archive_entry_gid(ae)); 101228753Smm } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { 102228753Smm /* A regular file. */ 103228753Smm assertEqualString("file", archive_entry_pathname(ae)); 104228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 105228753Smm assertEqualInt(12345684, archive_entry_size(ae)); 106228753Smm assertEqualInt(0, 107228753Smm archive_read_data_block(a, &p, &size, &offset)); 108228753Smm assertEqualInt(0, offset); 109228753Smm assertEqualMem(p, "hello\n", 6); 110228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 111228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 112228753Smm assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 113228753Smm assertEqualInt(1, archive_entry_uid(ae)); 114228753Smm assertEqualInt(2, archive_entry_gid(ae)); 115228753Smm } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { 116228753Smm /* A hardlink to the regular file. */ 117228753Smm /* Note: If "hardlink" gets returned before "file", 118228753Smm * then "hardlink" will get returned as a regular file 119228753Smm * and "file" will get returned as the hardlink. 120228753Smm * This test should tolerate that, since it's a 121228753Smm * perfectly permissible thing for libarchive to do. */ 122228753Smm assertEqualString("hardlink", archive_entry_pathname(ae)); 123228753Smm assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); 124228753Smm assertEqualString("file", archive_entry_hardlink(ae)); 125228753Smm assertEqualInt(0, archive_entry_size_is_set(ae)); 126228753Smm assertEqualInt(0, archive_entry_size(ae)); 127228753Smm assertEqualInt(86401, archive_entry_mtime(ae)); 128228753Smm assertEqualInt(86401, archive_entry_atime(ae)); 129228753Smm assertEqualInt(2, archive_entry_stat(ae)->st_nlink); 130228753Smm assertEqualInt(1, archive_entry_uid(ae)); 131228753Smm assertEqualInt(2, archive_entry_gid(ae)); 132228753Smm } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { 133228753Smm /* A symlink to the regular file. */ 134228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 135228753Smm assertEqualString("file", archive_entry_symlink(ae)); 136228753Smm assertEqualInt(0, archive_entry_size(ae)); 137228753Smm assertEqualInt(172802, archive_entry_mtime(ae)); 138228753Smm assertEqualInt(172802, archive_entry_atime(ae)); 139228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 140228753Smm assertEqualInt(1, archive_entry_uid(ae)); 141228753Smm assertEqualInt(2, archive_entry_gid(ae)); 142228753Smm } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { 143228753Smm /* A symlink to /tmp/ (an absolute path) */ 144228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 145228753Smm assertEqualString("/tmp/", archive_entry_symlink(ae)); 146228753Smm assertEqualInt(0, archive_entry_size(ae)); 147228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 148228753Smm assertEqualInt(1, archive_entry_uid(ae)); 149228753Smm assertEqualInt(2, archive_entry_gid(ae)); 150228753Smm } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { 151228753Smm /* A symlink to /tmp/../ (with a ".." component) */ 152228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 153228753Smm assertEqualString("/tmp/../", archive_entry_symlink(ae)); 154228753Smm assertEqualInt(0, archive_entry_size(ae)); 155228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 156228753Smm assertEqualInt(1, archive_entry_uid(ae)); 157228753Smm assertEqualInt(2, archive_entry_gid(ae)); 158228753Smm } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { 159228753Smm /* A symlink to a path with ".." and "." components */ 160228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 161228753Smm assertEqualString(".././../tmp/", 162228753Smm archive_entry_symlink(ae)); 163228753Smm assertEqualInt(0, archive_entry_size(ae)); 164228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 165228753Smm assertEqualInt(1, archive_entry_uid(ae)); 166228753Smm assertEqualInt(2, archive_entry_gid(ae)); 167228753Smm } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { 168228753Smm /* A symlink to the regular file with "/" components. */ 169228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 170228753Smm assertEqualString(".///file", archive_entry_symlink(ae)); 171228753Smm assertEqualInt(0, archive_entry_size(ae)); 172228753Smm assertEqualInt(172802, archive_entry_mtime(ae)); 173228753Smm assertEqualInt(172802, archive_entry_atime(ae)); 174228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 175228753Smm assertEqualInt(1, archive_entry_uid(ae)); 176228753Smm assertEqualInt(2, archive_entry_gid(ae)); 177228753Smm } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { 178228753Smm /* A symlink to /tmp//../ 179228753Smm * (with "/" and ".." components) */ 180228753Smm assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); 181228753Smm assertEqualString("/tmp//../", archive_entry_symlink(ae)); 182228753Smm assertEqualInt(0, archive_entry_size(ae)); 183228753Smm assertEqualInt(1, archive_entry_stat(ae)->st_nlink); 184228753Smm assertEqualInt(1, archive_entry_uid(ae)); 185228753Smm assertEqualInt(2, archive_entry_gid(ae)); 186228753Smm } else { 187228753Smm failure("Saw a file that shouldn't have been there"); 188228753Smm assertEqualString(archive_entry_pathname(ae), ""); 189228753Smm } 190228753Smm } 191228753Smm 192228753Smm /* End of archive. */ 193228753Smm assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); 194228753Smm 195228753Smm /* Verify archive format. */ 196248616Smm assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS); 197228753Smm assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); 198228753Smm 199228753Smm /* Close the archive. */ 200232153Smm assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); 201232153Smm assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 202228753Smm} 203228753Smm 204228753Smm 205