From 543adbed3a3a783ed36434adafbc258b6bde442d Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Tue, 1 May 2012 01:56:44 +0200 Subject: [PATCH] libarchive import . clean and nbsd_ports managed import . also makes it shared --- Makefile | 1 + common/include/sys/Makefile.inc | 2 +- external/bsd/libarchive/Makefile | 5 + external/bsd/libarchive/Makefile.inc | 15 + external/bsd/libarchive/bin/Makefile | 11 + external/bsd/libarchive/bin/Makefile.inc | 13 + external/bsd/libarchive/bin/cpio/Makefile | 19 + external/bsd/libarchive/bin/tar/Makefile | 19 + external/bsd/libarchive/dist/COPYING | 60 + external/bsd/libarchive/dist/NEWS | 545 ++++ external/bsd/libarchive/dist/README | 137 + external/bsd/libarchive/dist/cpio/bsdcpio.1 | 405 +++ external/bsd/libarchive/dist/cpio/cmdline.c | 369 +++ external/bsd/libarchive/dist/cpio/cpio.c | 1267 ++++++++++ external/bsd/libarchive/dist/cpio/cpio.h | 109 + .../bsd/libarchive/dist/cpio/cpio_platform.h | 77 + .../bsd/libarchive/dist/cpio/cpio_windows.c | 338 +++ .../bsd/libarchive/dist/cpio/cpio_windows.h | 72 + .../libarchive/dist/cpio/test/CMakeLists.txt | 79 + external/bsd/libarchive/dist/cpio/test/list.h | 27 + external/bsd/libarchive/dist/cpio/test/main.c | 2140 ++++++++++++++++ external/bsd/libarchive/dist/cpio/test/test.h | 285 +++ .../bsd/libarchive/dist/cpio/test/test_0.c | 67 + .../libarchive/dist/cpio/test/test_basic.c | 173 ++ .../libarchive/dist/cpio/test/test_cmdline.c | 107 + .../dist/cpio/test/test_format_newc.c | 294 +++ .../dist/cpio/test/test_gcpio_compat.c | 108 + .../cpio/test/test_gcpio_compat_ref.bin.uu | 16 + .../cpio/test/test_gcpio_compat_ref.crc.uu | 27 + .../cpio/test/test_gcpio_compat_ref.newc.uu | 27 + .../cpio/test/test_gcpio_compat_ref.ustar.uu | 84 + .../test/test_gcpio_compat_ref_nosym.bin.uu | 15 + .../test/test_gcpio_compat_ref_nosym.crc.uu | 15 + .../test/test_gcpio_compat_ref_nosym.newc.uu | 15 + .../test/test_gcpio_compat_ref_nosym.ustar.uu | 72 + .../dist/cpio/test/test_option_B_upper.c | 52 + .../dist/cpio/test/test_option_C_upper.c | 62 + .../dist/cpio/test/test_option_J_upper.c | 56 + .../dist/cpio/test/test_option_L_upper.c | 101 + .../dist/cpio/test/test_option_Z_upper.c | 56 + .../libarchive/dist/cpio/test/test_option_a.c | 154 ++ .../libarchive/dist/cpio/test/test_option_c.c | 221 ++ .../libarchive/dist/cpio/test/test_option_d.c | 64 + .../libarchive/dist/cpio/test/test_option_f.c | 76 + .../dist/cpio/test/test_option_f.cpio.uu | 16 + .../dist/cpio/test/test_option_help.c | 84 + .../libarchive/dist/cpio/test/test_option_l.c | 50 + .../dist/cpio/test/test_option_lzma.c | 56 + .../libarchive/dist/cpio/test/test_option_m.c | 63 + .../dist/cpio/test/test_option_m.cpio.uu | 16 + .../libarchive/dist/cpio/test/test_option_t.c | 95 + .../dist/cpio/test/test_option_t.cpio.uu | 16 + .../dist/cpio/test/test_option_t.stdout.uu | 5 + .../dist/cpio/test/test_option_tv.stdout.uu | 6 + .../libarchive/dist/cpio/test/test_option_u.c | 81 + .../dist/cpio/test/test_option_version.c | 109 + .../libarchive/dist/cpio/test/test_option_y.c | 57 + .../libarchive/dist/cpio/test/test_option_z.c | 56 + .../dist/cpio/test/test_owner_parse.c | 122 + .../dist/cpio/test/test_passthrough_dotdot.c | 76 + .../dist/cpio/test/test_passthrough_reverse.c | 85 + .../dist/cpio/test/test_pathmatch.c | 243 ++ .../bsd/libarchive/dist}/libarchive/archive.h | 32 +- .../dist}/libarchive/archive_check_magic.c | 2 +- .../dist}/libarchive/archive_crc32.h | 0 .../dist}/libarchive/archive_endian.h | 47 +- .../dist}/libarchive/archive_entry.3 | 4 +- .../dist}/libarchive/archive_entry.c | 23 - .../dist}/libarchive/archive_entry.h | 17 - .../libarchive/archive_entry_copy_bhfi.c | 0 .../libarchive/archive_entry_copy_stat.c | 0 .../libarchive/archive_entry_link_resolver.c | 27 - .../dist}/libarchive/archive_entry_private.h | 26 +- .../dist}/libarchive/archive_entry_stat.c | 5 - .../dist}/libarchive/archive_entry_strmode.c | 0 .../dist}/libarchive/archive_entry_xattr.c | 0 .../dist}/libarchive/archive_hash.h | 165 +- .../dist}/libarchive/archive_platform.h | 2 - .../dist}/libarchive/archive_private.h | 10 +- .../dist}/libarchive/archive_read.3 | 42 +- .../dist}/libarchive/archive_read.c | 136 - .../libarchive/archive_read_data_into_fd.c | 0 .../dist}/libarchive/archive_read_disk.3 | 20 +- .../dist}/libarchive/archive_read_disk.c | 0 .../archive_read_disk_entry_from_file.c | 3 +- .../libarchive/archive_read_disk_private.h | 2 +- .../archive_read_disk_set_standard_lookup.c | 41 +- .../dist}/libarchive/archive_read_extract.c | 0 .../dist}/libarchive/archive_read_open_fd.c | 12 +- .../dist}/libarchive/archive_read_open_file.c | 0 .../libarchive/archive_read_open_filename.c | 20 +- .../libarchive/archive_read_open_memory.c | 0 .../dist}/libarchive/archive_read_private.h | 14 - .../archive_read_support_compression_all.c | 3 +- .../archive_read_support_compression_bzip2.c | 8 +- ...rchive_read_support_compression_compress.c | 0 .../archive_read_support_compression_gzip.c | 4 - .../archive_read_support_compression_none.c | 0 ...archive_read_support_compression_program.c | 0 .../archive_read_support_compression_rpm.c | 287 +++ .../archive_read_support_compression_uu.c | 4 - .../archive_read_support_compression_xz.c | 10 - .../archive_read_support_format_all.c | 4 +- .../archive_read_support_format_ar.c | 95 - .../archive_read_support_format_cpio.c | 777 ++++++ .../archive_read_support_format_empty.c | 0 .../archive_read_support_format_iso9660.c | 6 +- .../archive_read_support_format_mtree.c | 123 +- .../archive_read_support_format_raw.c | 8 - .../archive_read_support_format_tar.c | 338 +-- .../archive_read_support_format_xar.c | 13 +- .../archive_read_support_format_zip.c | 29 +- .../dist}/libarchive/archive_string.c | 7 +- .../dist}/libarchive/archive_string.h | 0 .../dist}/libarchive/archive_string_sprintf.c | 0 .../dist}/libarchive/archive_util.3 | 0 .../dist}/libarchive/archive_util.c | 19 +- .../dist}/libarchive/archive_virtual.c | 0 .../dist/libarchive/archive_windows.c | 1236 +++++++++ .../dist/libarchive/archive_windows.h | 347 +++ .../dist}/libarchive/archive_write.3 | 32 +- .../dist}/libarchive/archive_write.c | 12 +- .../dist}/libarchive/archive_write_disk.3 | 6 +- .../dist}/libarchive/archive_write_disk.c | 15 +- .../libarchive/archive_write_disk_private.h | 0 .../archive_write_disk_set_standard_lookup.c | 30 +- .../dist}/libarchive/archive_write_open_fd.c | 0 .../libarchive/archive_write_open_file.c | 0 .../libarchive/archive_write_open_filename.c | 0 .../libarchive/archive_write_open_memory.c | 0 .../dist}/libarchive/archive_write_private.h | 5 +- .../archive_write_set_compression_bzip2.c | 8 +- .../archive_write_set_compression_compress.c | 0 .../archive_write_set_compression_gzip.c | 4 - .../archive_write_set_compression_none.c | 0 .../archive_write_set_compression_program.c | 0 .../archive_write_set_compression_xz.c | 0 .../libarchive/archive_write_set_format.c | 2 - .../libarchive/archive_write_set_format_ar.c | 99 +- .../archive_write_set_format_by_name.c | 4 +- .../archive_write_set_format_cpio.c | 344 +++ .../archive_write_set_format_cpio_newc.c | 295 +++ .../archive_write_set_format_mtree.c | 12 - .../libarchive/archive_write_set_format_pax.c | 115 +- .../archive_write_set_format_shar.c | 0 .../archive_write_set_format_ustar.c | 2 +- .../libarchive/archive_write_set_format_zip.c | 16 +- .../bsd/libarchive/dist/libarchive/cpio.5 | 325 +++ .../libarchive/dist}/libarchive/filter_fork.c | 10 +- .../libarchive/dist}/libarchive/filter_fork.h | 0 .../dist/libarchive/filter_fork_windows.c | 113 + .../dist}/libarchive/libarchive-formats.5 | 0 .../libarchive/dist}/libarchive/libarchive.3 | 0 .../dist}/libarchive/libarchive_internals.3 | 1 - .../bsd/libarchive/dist}/libarchive/mtree.5 | 0 .../bsd/libarchive/dist}/libarchive/tar.5 | 0 .../dist/libarchive/test/CMakeLists.txt | 158 ++ .../libarchive/dist/libarchive/test/README | 63 + .../libarchive/dist/libarchive/test/list.h | 106 + .../libarchive/dist/libarchive/test/main.c | 2130 ++++++++++++++++ .../dist/libarchive/test/read_open_memory.c | 167 ++ .../libarchive/dist/libarchive/test/test.h | 302 +++ .../dist/libarchive/test/test_acl_basic.c | 229 ++ .../dist/libarchive/test/test_acl_freebsd.c | 255 ++ .../dist/libarchive/test/test_acl_pax.c | 517 ++++ .../test/test_archive_api_feature.c | 76 + .../dist/libarchive/test/test_bad_fd.c | 41 + .../dist/libarchive/test/test_compat_bzip2.c | 85 + .../test/test_compat_bzip2_1.tbz.uu | 24 + .../test/test_compat_bzip2_2.tbz.uu | 11 + .../dist/libarchive/test/test_compat_cpio.c | 106 + .../test/test_compat_cpio_1.cpio.uu | 19 + .../dist/libarchive/test/test_compat_gtar.c | 119 + .../libarchive/test/test_compat_gtar_1.tar.uu | 232 ++ .../dist/libarchive/test/test_compat_gzip.c | 97 + .../libarchive/test/test_compat_gzip_1.tgz.uu | 24 + .../libarchive/test/test_compat_gzip_2.tgz.uu | 11 + .../dist/libarchive/test/test_compat_lzma.c | 155 ++ .../libarchive/test/test_compat_lzma_1.tlz.uu | 10 + .../libarchive/test/test_compat_lzma_2.tlz.uu | 9 + .../libarchive/test/test_compat_lzma_3.tlz.uu | 9 + .../test/test_compat_solaris_tar_acl.c | 128 + .../test/test_compat_solaris_tar_acl.tar.uu | 61 + .../test/test_compat_tar_hardlink.c | 108 + .../test/test_compat_tar_hardlink_1.tar.uu | 39 + .../dist/libarchive/test/test_compat_xz.c | 84 + .../libarchive/test/test_compat_xz_1.txz.uu | 13 + .../dist/libarchive/test/test_compat_zip.c | 80 + .../libarchive/test/test_compat_zip_1.zip.uu | 15 + .../dist/libarchive/test/test_empty_write.c | 120 + .../dist/libarchive/test/test_entry.c | 903 +++++++ .../dist/libarchive/test/test_entry_strmode.c | 71 + .../libarchive/test/test_extattr_freebsd.c | 172 ++ .../dist/libarchive/test/test_fuzz.c | 166 ++ .../dist/libarchive/test/test_fuzz_1.iso.Z.uu | 495 ++++ .../dist/libarchive/test/test_link_resolver.c | 205 ++ .../dist/libarchive/test/test_open_fd.c | 128 + .../dist/libarchive/test/test_open_file.c | 108 + .../dist/libarchive/test/test_open_filename.c | 109 + .../test/test_pax_filename_encoding.c | 333 +++ .../test/test_pax_filename_encoding.tar.uu | 118 + .../test/test_read_compress_program.c | 84 + .../libarchive/test/test_read_data_large.c | 125 + .../dist/libarchive/test/test_read_disk.c | 172 ++ .../test/test_read_disk_entry_from_file.c | 80 + .../dist/libarchive/test/test_read_extract.c | 168 ++ .../test/test_read_file_nonexistent.c | 37 + .../libarchive/test/test_read_format_ar.ar.uu | 12 + .../libarchive/test/test_read_format_ar.c | 87 + .../test/test_read_format_cpio_bin.c | 64 + .../test/test_read_format_cpio_bin_Z.c | 61 + .../test/test_read_format_cpio_bin_be.c | 55 + .../test/test_read_format_cpio_bin_be.cpio.uu | 8 + .../test/test_read_format_cpio_bin_bz2.c | 58 + .../test/test_read_format_cpio_bin_gz.c | 61 + .../test/test_read_format_cpio_bin_lzma.c | 60 + .../test/test_read_format_cpio_bin_xz.c | 70 + .../test/test_read_format_cpio_odc.c | 68 + .../test_read_format_cpio_svr4_bzip2_rpm.c | 127 + ...est_read_format_cpio_svr4_bzip2_rpm.rpm.uu | 47 + .../test/test_read_format_cpio_svr4_gzip.c | 61 + .../test_read_format_cpio_svr4_gzip_rpm.c | 127 + ...test_read_format_cpio_svr4_gzip_rpm.rpm.uu | 46 + .../test/test_read_format_cpio_svr4c_Z.c | 62 + .../libarchive/test/test_read_format_empty.c | 47 + .../test/test_read_format_gtar_gz.c | 60 + .../test/test_read_format_gtar_lzma.c | 78 + .../test/test_read_format_gtar_sparse.c | 318 +++ .../test_read_format_gtar_sparse_1_13.tar.uu | 1370 ++++++++++ .../test_read_format_gtar_sparse_1_17.tar.uu | 1370 ++++++++++ ...ead_format_gtar_sparse_1_17_posix00.tar.uu | 1597 ++++++++++++ ...ead_format_gtar_sparse_1_17_posix01.tar.uu | 1370 ++++++++++ ...ead_format_gtar_sparse_1_17_posix10.tar.uu | 1370 ++++++++++ ...t_gtar_sparse_1_17_posix10_modified.tar.uu | 1370 ++++++++++ .../test/test_read_format_iso.iso.Z.uu | 26 + .../libarchive/test/test_read_format_iso_gz.c | 52 + .../test/test_read_format_iso_joliet.iso.Z.uu | 66 + .../test_read_format_iso_joliet_long.iso.Z.uu | 71 + ..._read_format_iso_joliet_rockridge.iso.Z.uu | 68 + .../test/test_read_format_iso_multi_extent.c | 94 + ...test_read_format_iso_multi_extent.iso.Z.uu | 67 + .../test_read_format_iso_rockridge.iso.Z.uu | 206 ++ ...test_read_format_iso_rockridge_ce.iso.Z.uu | 63 + ...est_read_format_iso_rockridge_new.iso.Z.uu | 208 ++ ...ead_format_iso_rockridge_rr_moved.iso.Z.uu | 304 +++ .../test/test_read_format_iso_zisofs.iso.Z.uu | 63 + .../test/test_read_format_isojoliet_bz2.c | 134 + .../test/test_read_format_isojoliet_long.c | 141 ++ .../test/test_read_format_isojoliet_rr.c | 159 ++ .../test/test_read_format_isorr_bz2.c | 203 ++ .../test/test_read_format_isorr_ce.c | 223 ++ .../test/test_read_format_isorr_new_bz2.c | 204 ++ .../test/test_read_format_isorr_rr_moved.c | 270 ++ .../test/test_read_format_isozisofs_bz2.c | 187 ++ .../libarchive/test/test_read_format_mtree.c | 143 ++ .../test/test_read_format_mtree.mtree.uu | 13 + .../test/test_read_format_pax_bz2.c | 66 + .../libarchive/test/test_read_format_raw.c | 89 + .../test/test_read_format_raw.data.Z.uu | 5 + .../test/test_read_format_raw.data.uu | 5 + .../libarchive/test/test_read_format_tar.c | 480 ++++ .../test_read_format_tar_empty_filename.c | 66 + ...test_read_format_tar_empty_filename.tar.uu | 39 + .../libarchive/test/test_read_format_tbz.c | 59 + .../libarchive/test/test_read_format_tgz.c | 60 + .../libarchive/test/test_read_format_tlz.c | 60 + .../libarchive/test/test_read_format_txz.c | 63 + .../libarchive/test/test_read_format_tz.c | 61 + .../libarchive/test/test_read_format_xar.c | 697 +++++ .../libarchive/test/test_read_format_zip.c | 92 + .../test/test_read_format_zip.zip.uu | 14 + .../dist/libarchive/test/test_read_large.c | 93 + .../libarchive/test/test_read_pax_truncated.c | 288 +++ .../dist/libarchive/test/test_read_position.c | 94 + .../libarchive/test/test_read_truncated.c | 149 ++ .../dist/libarchive/test/test_read_uu.c | 134 + .../dist/libarchive/test/test_tar_filenames.c | 186 ++ .../dist/libarchive/test/test_tar_large.c | 312 +++ .../libarchive/test/test_ustar_filenames.c | 191 ++ .../libarchive/test/test_write_compress.c | 102 + .../test/test_write_compress_bzip2.c | 228 ++ .../test/test_write_compress_gzip.c | 252 ++ .../test/test_write_compress_lzma.c | 245 ++ .../test/test_write_compress_program.c | 118 + .../libarchive/test/test_write_compress_xz.c | 253 ++ .../dist/libarchive/test/test_write_disk.c | 332 +++ .../test/test_write_disk_failures.c | 72 + .../test/test_write_disk_hardlink.c | 219 ++ .../libarchive/test/test_write_disk_perms.c | 457 ++++ .../libarchive/test/test_write_disk_secure.c | 215 ++ .../libarchive/test/test_write_disk_sparse.c | 280 ++ .../libarchive/test/test_write_disk_symlink.c | 117 + .../libarchive/test/test_write_disk_times.c | 167 ++ .../libarchive/test/test_write_format_ar.c | 209 ++ .../libarchive/test/test_write_format_cpio.c | 194 ++ .../test/test_write_format_cpio_empty.c | 75 + .../test/test_write_format_cpio_newc.c | 214 ++ .../test/test_write_format_cpio_odc.c | 241 ++ .../libarchive/test/test_write_format_mtree.c | 155 ++ .../libarchive/test/test_write_format_pax.c | 146 ++ .../test/test_write_format_shar_empty.c | 58 + .../libarchive/test/test_write_format_tar.c | 114 + .../test/test_write_format_tar_empty.c | 92 + .../test/test_write_format_tar_ustar.c | 347 +++ .../libarchive/test/test_write_format_zip.c | 180 ++ .../test/test_write_format_zip_empty.c | 56 + .../test_write_format_zip_no_compression.c | 304 +++ .../libarchive/test/test_write_open_memory.c | 76 + .../bsd/libarchive/dist/libarchive_fe/err.c | 74 + .../bsd/libarchive/dist/libarchive_fe/err.h | 41 + .../dist/libarchive_fe/lafe_platform.h | 55 + .../dist/libarchive_fe/line_reader.c | 171 ++ .../dist/libarchive_fe/line_reader.h | 35 + .../libarchive/dist/libarchive_fe/matching.c | 284 +++ .../libarchive/dist/libarchive_fe/matching.h | 46 + .../libarchive/dist/libarchive_fe/pathmatch.c | 255 ++ .../libarchive/dist/libarchive_fe/pathmatch.h | 42 + external/bsd/libarchive/dist/tar/bsdtar.1 | 921 +++++++ external/bsd/libarchive/dist/tar/bsdtar.c | 734 ++++++ external/bsd/libarchive/dist/tar/bsdtar.h | 158 ++ .../bsd/libarchive/dist/tar/bsdtar_platform.h | 132 + .../bsd/libarchive/dist/tar/bsdtar_windows.c | 298 +++ .../bsd/libarchive/dist/tar/bsdtar_windows.h | 60 + external/bsd/libarchive/dist/tar/cmdline.c | 381 +++ external/bsd/libarchive/dist/tar/getdate.c | 1037 ++++++++ external/bsd/libarchive/dist/tar/read.c | 437 ++++ external/bsd/libarchive/dist/tar/subst.c | 289 +++ .../libarchive/dist/tar/test/CMakeLists.txt | 67 + external/bsd/libarchive/dist/tar/test/list.h | 16 + external/bsd/libarchive/dist/tar/test/main.c | 2242 +++++++++++++++++ external/bsd/libarchive/dist/tar/test/test.h | 288 +++ .../bsd/libarchive/dist/tar/test/test_0.c | 67 + .../bsd/libarchive/dist/tar/test/test_basic.c | 115 + .../bsd/libarchive/dist/tar/test/test_copy.c | 372 +++ .../dist/tar/test/test_empty_mtree.c | 45 + .../libarchive/dist/tar/test/test_getdate.c | 80 + .../bsd/libarchive/dist/tar/test/test_help.c | 84 + .../dist/tar/test/test_option_T_upper.c | 188 ++ .../libarchive/dist/tar/test/test_option_q.c | 129 + .../libarchive/dist/tar/test/test_option_r.c | 117 + .../libarchive/dist/tar/test/test_option_s.c | 107 + .../libarchive/dist/tar/test/test_patterns.c | 184 ++ .../dist/tar/test/test_patterns_2.tar.uu | 231 ++ .../dist/tar/test/test_patterns_3.tar.uu | 231 ++ .../dist/tar/test/test_patterns_4.tar.uu | 641 +++++ .../bsd/libarchive/dist/tar/test/test_stdio.c | 125 + .../dist/tar/test/test_strip_components.c | 109 + .../dist/tar/test/test_symlink_dir.c | 160 ++ .../libarchive/dist/tar/test/test_version.c | 97 + .../libarchive/dist/tar/test/test_windows.c | 323 +++ external/bsd/libarchive/dist/tar/tree.c | 821 ++++++ external/bsd/libarchive/dist/tar/tree.h | 141 ++ external/bsd/libarchive/dist/tar/util.c | 559 ++++ external/bsd/libarchive/dist/tar/write.c | 1138 +++++++++ .../bsd/libarchive/include/config_netbsd.h | 256 +- external/bsd/libarchive/lib/Makefile | 5 + external/bsd/libarchive/lib/Makefile.inc | 3 + .../bsd/libarchive/lib/libarchive/Makefile | 265 ++ .../libarchive/lib/libarchive/shlib_version | 6 + .../bsd/libarchive/lib/libarchive_fe/Makefile | 13 + external/bsd/libarchive/prepare-import.sh | 22 + include/sys/extattr.h | 111 + lib/Makefile | 3 +- lib/libarchive/Makefile | 72 - lib/libarchive/README | 24 - share/mk/bsd.own.mk | 2 +- tools/nbsd_ports | 1 + 367 files changed, 58690 insertions(+), 1618 deletions(-) create mode 100644 external/bsd/libarchive/Makefile create mode 100644 external/bsd/libarchive/Makefile.inc create mode 100644 external/bsd/libarchive/bin/Makefile create mode 100644 external/bsd/libarchive/bin/Makefile.inc create mode 100644 external/bsd/libarchive/bin/cpio/Makefile create mode 100644 external/bsd/libarchive/bin/tar/Makefile create mode 100644 external/bsd/libarchive/dist/COPYING create mode 100644 external/bsd/libarchive/dist/NEWS create mode 100644 external/bsd/libarchive/dist/README create mode 100644 external/bsd/libarchive/dist/cpio/bsdcpio.1 create mode 100644 external/bsd/libarchive/dist/cpio/cmdline.c create mode 100644 external/bsd/libarchive/dist/cpio/cpio.c create mode 100644 external/bsd/libarchive/dist/cpio/cpio.h create mode 100644 external/bsd/libarchive/dist/cpio/cpio_platform.h create mode 100644 external/bsd/libarchive/dist/cpio/cpio_windows.c create mode 100644 external/bsd/libarchive/dist/cpio/cpio_windows.h create mode 100644 external/bsd/libarchive/dist/cpio/test/CMakeLists.txt create mode 100644 external/bsd/libarchive/dist/cpio/test/list.h create mode 100644 external/bsd/libarchive/dist/cpio/test/main.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test.h create mode 100644 external/bsd/libarchive/dist/cpio/test/test_0.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_basic.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_cmdline.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_format_newc.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_gcpio_compat.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref.bin.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref.crc.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref.newc.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref.ustar.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref_nosym.bin.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref_nosym.crc.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref_nosym.newc.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref_nosym.ustar.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_B_upper.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_C_upper.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_J_upper.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_L_upper.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_Z_upper.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_a.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_c.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_d.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_f.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_f.cpio.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_help.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_l.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_lzma.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_m.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_m.cpio.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_t.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_t.cpio.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_t.stdout.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_tv.stdout.uu create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_u.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_version.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_y.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_option_z.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_owner_parse.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_passthrough_dotdot.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_passthrough_reverse.c create mode 100644 external/bsd/libarchive/dist/cpio/test/test_pathmatch.c rename {lib => external/bsd/libarchive/dist}/libarchive/archive.h (97%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_check_magic.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_crc32.h (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_endian.h (82%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry.3 (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry.h (98%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry_copy_bhfi.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry_copy_stat.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry_link_resolver.c (96%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry_private.h (94%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry_stat.c (98%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry_strmode.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_entry_xattr.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_hash.h (52%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_platform.h (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_private.h (96%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read.3 (96%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read.c (90%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_data_into_fd.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_disk.3 (96%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_disk.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_disk_entry_from_file.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_disk_private.h (97%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_disk_set_standard_lookup.c (94%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_extract.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_open_fd.c (95%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_open_file.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_open_filename.c (95%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_open_memory.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_private.h (94%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_compression_all.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_compression_bzip2.c (97%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_compression_compress.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_compression_gzip.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_compression_none.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_compression_program.c (100%) create mode 100644 external/bsd/libarchive/dist/libarchive/archive_read_support_compression_rpm.c rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_compression_uu.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_compression_xz.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_format_all.c (98%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_format_ar.c (88%) create mode 100644 external/bsd/libarchive/dist/libarchive/archive_read_support_format_cpio.c rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_format_empty.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_format_iso9660.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_format_mtree.c (93%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_format_raw.c (97%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_format_tar.c (91%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_format_xar.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_read_support_format_zip.c (97%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_string.c (98%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_string.h (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_string_sprintf.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_util.3 (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_util.c (97%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_virtual.c (100%) create mode 100644 external/bsd/libarchive/dist/libarchive/archive_windows.c create mode 100644 external/bsd/libarchive/dist/libarchive/archive_windows.h rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write.3 (97%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write.c (97%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_disk.3 (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_disk.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_disk_private.h (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_disk_set_standard_lookup.c (94%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_open_fd.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_open_file.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_open_filename.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_open_memory.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_private.h (98%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_compression_bzip2.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_compression_compress.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_compression_gzip.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_compression_none.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_compression_program.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_compression_xz.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_format.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_format_ar.c (89%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_format_by_name.c (99%) create mode 100644 external/bsd/libarchive/dist/libarchive/archive_write_set_format_cpio.c create mode 100644 external/bsd/libarchive/dist/libarchive/archive_write_set_format_cpio_newc.c rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_format_mtree.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_format_pax.c (94%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_format_shar.c (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_format_ustar.c (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/archive_write_set_format_zip.c (98%) create mode 100644 external/bsd/libarchive/dist/libarchive/cpio.5 rename {lib => external/bsd/libarchive/dist}/libarchive/filter_fork.c (95%) rename {lib => external/bsd/libarchive/dist}/libarchive/filter_fork.h (100%) create mode 100644 external/bsd/libarchive/dist/libarchive/filter_fork_windows.c rename {lib => external/bsd/libarchive/dist}/libarchive/libarchive-formats.5 (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/libarchive.3 (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/libarchive_internals.3 (99%) rename {lib => external/bsd/libarchive/dist}/libarchive/mtree.5 (100%) rename {lib => external/bsd/libarchive/dist}/libarchive/tar.5 (100%) create mode 100644 external/bsd/libarchive/dist/libarchive/test/CMakeLists.txt create mode 100644 external/bsd/libarchive/dist/libarchive/test/README create mode 100644 external/bsd/libarchive/dist/libarchive/test/list.h create mode 100644 external/bsd/libarchive/dist/libarchive/test/main.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/read_open_memory.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test.h create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_acl_basic.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_acl_freebsd.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_acl_pax.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_archive_api_feature.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_bad_fd.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2_1.tbz.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2_2.tbz.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_cpio.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_cpio_1.cpio.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_gtar.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_gtar_1.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_gzip.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_gzip_1.tgz.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_gzip_2.tgz.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_lzma.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_lzma_1.tlz.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_lzma_2.tlz.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_lzma_3.tlz.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_solaris_tar_acl.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_solaris_tar_acl.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_tar_hardlink.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_tar_hardlink_1.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_xz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_xz_1.txz.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_zip.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_compat_zip_1.zip.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_empty_write.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_entry.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_entry_strmode.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_extattr_freebsd.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_fuzz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_fuzz_1.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_link_resolver.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_open_fd.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_open_file.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_open_filename.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_pax_filename_encoding.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_pax_filename_encoding.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_compress_program.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_data_large.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_disk.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_disk_entry_from_file.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_extract.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_file_nonexistent.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_ar.ar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_ar.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_bin.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_bin_Z.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_bin_be.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_bin_be.cpio.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_bin_bz2.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_bin_gz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_bin_lzma.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_bin_xz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_odc.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_gzip.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4c_Z.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_empty.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_gz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_lzma.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse_1_17.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse_1_17_posix00.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse_1_17_posix01.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse_1_17_posix10.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse_1_17_posix10_modified.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_gz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet_rockridge.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_multi_extent.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_multi_extent.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge_ce.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge_new.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge_rr_moved.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_zisofs.iso.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_bz2.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_long.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_rr.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_bz2.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_ce.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_new_bz2.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_rr_moved.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_isozisofs_bz2.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_mtree.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_mtree.mtree.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_pax_bz2.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_raw.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_raw.data.Z.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_raw.data.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_tar.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_tar_empty_filename.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_tar_empty_filename.tar.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_tbz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_tgz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_tlz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_txz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_tz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_xar.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_zip.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_format_zip.zip.uu create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_large.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_pax_truncated.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_position.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_truncated.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_read_uu.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_tar_filenames.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_tar_large.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_ustar_filenames.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_compress.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_compress_bzip2.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_compress_gzip.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_compress_lzma.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_compress_program.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_compress_xz.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_disk.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_disk_failures.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_disk_hardlink.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_disk_perms.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_disk_secure.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_disk_sparse.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_disk_symlink.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_disk_times.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_ar.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_empty.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_newc.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_odc.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_mtree.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_pax.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_shar_empty.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_tar.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_tar_empty.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_tar_ustar.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_zip.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_zip_empty.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_format_zip_no_compression.c create mode 100644 external/bsd/libarchive/dist/libarchive/test/test_write_open_memory.c create mode 100644 external/bsd/libarchive/dist/libarchive_fe/err.c create mode 100644 external/bsd/libarchive/dist/libarchive_fe/err.h create mode 100644 external/bsd/libarchive/dist/libarchive_fe/lafe_platform.h create mode 100644 external/bsd/libarchive/dist/libarchive_fe/line_reader.c create mode 100644 external/bsd/libarchive/dist/libarchive_fe/line_reader.h create mode 100644 external/bsd/libarchive/dist/libarchive_fe/matching.c create mode 100644 external/bsd/libarchive/dist/libarchive_fe/matching.h create mode 100644 external/bsd/libarchive/dist/libarchive_fe/pathmatch.c create mode 100644 external/bsd/libarchive/dist/libarchive_fe/pathmatch.h create mode 100644 external/bsd/libarchive/dist/tar/bsdtar.1 create mode 100644 external/bsd/libarchive/dist/tar/bsdtar.c create mode 100644 external/bsd/libarchive/dist/tar/bsdtar.h create mode 100644 external/bsd/libarchive/dist/tar/bsdtar_platform.h create mode 100644 external/bsd/libarchive/dist/tar/bsdtar_windows.c create mode 100644 external/bsd/libarchive/dist/tar/bsdtar_windows.h create mode 100644 external/bsd/libarchive/dist/tar/cmdline.c create mode 100644 external/bsd/libarchive/dist/tar/getdate.c create mode 100644 external/bsd/libarchive/dist/tar/read.c create mode 100644 external/bsd/libarchive/dist/tar/subst.c create mode 100644 external/bsd/libarchive/dist/tar/test/CMakeLists.txt create mode 100644 external/bsd/libarchive/dist/tar/test/list.h create mode 100644 external/bsd/libarchive/dist/tar/test/main.c create mode 100644 external/bsd/libarchive/dist/tar/test/test.h create mode 100644 external/bsd/libarchive/dist/tar/test/test_0.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_basic.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_copy.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_empty_mtree.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_getdate.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_help.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_option_T_upper.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_option_q.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_option_r.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_option_s.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_patterns.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_patterns_2.tar.uu create mode 100644 external/bsd/libarchive/dist/tar/test/test_patterns_3.tar.uu create mode 100644 external/bsd/libarchive/dist/tar/test/test_patterns_4.tar.uu create mode 100644 external/bsd/libarchive/dist/tar/test/test_stdio.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_strip_components.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_symlink_dir.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_version.c create mode 100644 external/bsd/libarchive/dist/tar/test/test_windows.c create mode 100644 external/bsd/libarchive/dist/tar/tree.c create mode 100644 external/bsd/libarchive/dist/tar/tree.h create mode 100644 external/bsd/libarchive/dist/tar/util.c create mode 100644 external/bsd/libarchive/dist/tar/write.c rename lib/libarchive/config.h => external/bsd/libarchive/include/config_netbsd.h (82%) create mode 100644 external/bsd/libarchive/lib/Makefile create mode 100644 external/bsd/libarchive/lib/Makefile.inc create mode 100644 external/bsd/libarchive/lib/libarchive/Makefile create mode 100644 external/bsd/libarchive/lib/libarchive/shlib_version create mode 100644 external/bsd/libarchive/lib/libarchive_fe/Makefile create mode 100644 external/bsd/libarchive/prepare-import.sh create mode 100644 include/sys/extattr.h delete mode 100644 lib/libarchive/Makefile delete mode 100644 lib/libarchive/README diff --git a/Makefile b/Makefile index cb4e7cc60..c79fe86ed 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,7 @@ includes: .PHONY .MAKE ${MAKEDIRTARGET} include includes ${MAKEDIRTARGET} lib includes ${MAKEDIRTARGET} sys includes + ${MAKEDIRTARGET} external includes .for dir in lib lib/csu lib/libc do-${dir:S/\//-/g}: .PHONY .MAKE diff --git a/common/include/sys/Makefile.inc b/common/include/sys/Makefile.inc index 5394cd6d5..702d7d343 100644 --- a/common/include/sys/Makefile.inc +++ b/common/include/sys/Makefile.inc @@ -7,4 +7,4 @@ INCS+= elf64.h elf_common.h elf_generic.h \ ioc_memory.h ioc_sound.h ioc_tty.h \ kbdio.h mtio.h svrctl.h video.h vm.h procfs.h elf_core.h exec_elf.h \ disk.h dkio.h ioccom.h mutex.h iostat.h disklabel.h disklabel_gpt.h \ - bootblock.h dkbad.h + bootblock.h dkbad.h extattr.h diff --git a/external/bsd/libarchive/Makefile b/external/bsd/libarchive/Makefile new file mode 100644 index 000000000..22e5c412b --- /dev/null +++ b/external/bsd/libarchive/Makefile @@ -0,0 +1,5 @@ +# $NetBSD: Makefile,v 1.1 2008/09/19 22:01:25 joerg Exp $ + +SUBDIR= lib .WAIT bin + +.include diff --git a/external/bsd/libarchive/Makefile.inc b/external/bsd/libarchive/Makefile.inc new file mode 100644 index 000000000..e884e1ad5 --- /dev/null +++ b/external/bsd/libarchive/Makefile.inc @@ -0,0 +1,15 @@ +# $NetBSD: Makefile.inc,v 1.2 2010/02/20 02:55:53 joerg Exp $ + +.include + +USE_FORT?= yes # complex string handling + +LIBARCHIVEDIR= ${NETBSDSRCDIR}/external/bsd/libarchive/dist + +CPPFLAGS+= -I${NETBSDSRCDIR}/external/bsd/libarchive/include +CPPFLAGS+= -DPLATFORM_CONFIG_H=\"config_netbsd.h\" + +LIBARCHIVE_FE_DIR!= cd ${.PARSEDIR}/lib/libarchive_fe && ${PRINTOBJDIR} +LIBARCHIVE_FE= ${LIBARCHIVE_FE_DIR}/libarchive_fe.a + +WARNS?= 4 diff --git a/external/bsd/libarchive/bin/Makefile b/external/bsd/libarchive/bin/Makefile new file mode 100644 index 000000000..37f95b8c5 --- /dev/null +++ b/external/bsd/libarchive/bin/Makefile @@ -0,0 +1,11 @@ +# $NetBSD: Makefile,v 1.2 2010/04/23 19:41:03 joerg Exp $ + +.include + +SUBDIR= + +.if ${MKBSDTAR} == "yes" +SUBDIR+= cpio tar +.endif + +.include diff --git a/external/bsd/libarchive/bin/Makefile.inc b/external/bsd/libarchive/bin/Makefile.inc new file mode 100644 index 000000000..7f1fd73d3 --- /dev/null +++ b/external/bsd/libarchive/bin/Makefile.inc @@ -0,0 +1,13 @@ +# $NetBSD: Makefile.inc,v 1.3 2010/11/02 19:14:53 joerg Exp $ + +.include "../Makefile.inc" + +BINDIR= /bin + +.if (${MKDYNAMICROOT} == "no") +LDSTATIC?= -static +.endif + +DPADD= ${LIBARCHIVE_FE} ${LIBARCHIVE} ${LIBBZ2} ${LIBLZMA} ${LIBZ} +LDADD= -L${LIBARCHIVE_FE_DIR} -larchive_fe -larchive -lbz2 -llzma -lz +CPPFLAGS+= -I${LIBARCHIVEDIR}/libarchive_fe diff --git a/external/bsd/libarchive/bin/cpio/Makefile b/external/bsd/libarchive/bin/cpio/Makefile new file mode 100644 index 000000000..0dcbf1465 --- /dev/null +++ b/external/bsd/libarchive/bin/cpio/Makefile @@ -0,0 +1,19 @@ +# $NetBSD: Makefile,v 1.6 2011/09/19 01:45:15 christos Exp $ + +PROG= cpio +SRCS= cmdline.c cpio.c + +.include + +.PATH: ${LIBARCHIVEDIR}/cpio + +CLEANFILES+= cpio.1 + +cpio.1: ${LIBARCHIVEDIR}/cpio/bsdcpio.1 + ${TOOL_CAT} ${LIBARCHIVEDIR}/cpio/bsdcpio.1 > $@ + +SYMLINKS+=${BINDIR}/cpio /usr/bin/cpio + +COPTS.cpio.c += -Wno-format-nonliteral + +.include diff --git a/external/bsd/libarchive/bin/tar/Makefile b/external/bsd/libarchive/bin/tar/Makefile new file mode 100644 index 000000000..3e331a8ea --- /dev/null +++ b/external/bsd/libarchive/bin/tar/Makefile @@ -0,0 +1,19 @@ +# $NetBSD: Makefile,v 1.4 2011/09/09 12:43:14 christos Exp $ + +PROG= tar +SRCS= bsdtar.c cmdline.c getdate.c read.c subst.c tree.c util.c write.c + +.include + +.PATH: ${LIBARCHIVEDIR}/tar + +CLEANFILES+= tar.1 + +tar.1: ${LIBARCHIVEDIR}/tar/bsdtar.1 + ${TOOL_CAT} ${LIBARCHIVEDIR}/tar/bsdtar.1 > $@ + +SYMLINKS+=${BINDIR}/tar /usr/bin/tar + +COPTS.read.c += -Wno-format-nonliteral + +.include diff --git a/external/bsd/libarchive/dist/COPYING b/external/bsd/libarchive/dist/COPYING new file mode 100644 index 000000000..9dbf49dbf --- /dev/null +++ b/external/bsd/libarchive/dist/COPYING @@ -0,0 +1,60 @@ +The libarchive distribution as a whole is Copyright by Tim Kientzle +and is subject to the copyright notice reproduced at the bottom of +this file. + +Each individual file in this distribution should have a clear +copyright/licensing statement at the beginning of the file. If any do +not, please let me know and I will rectify it. The following is +intended to summarize the copyright status of the individual files; +the actual statements in the files are controlling. + +* Except as listed below, all C sources (including .c and .h files) + and documentation files are subject to the copyright notice reproduced + at the bottom of this file. + +* The following source files are also subject in whole or in part to + a 3-clause UC Regents copyright; please read the individual source + files for details: + libarchive/archive_entry.c + libarchive/archive_read_support_compression_compress.c + libarchive/archive_write_set_compression_compress.c + libarchive/mtree.5 + tar/matching.c + +* The following source files are in the public domain: + tar/getdate.c + +* The build files---including Makefiles, configure scripts, + and auxiliary scripts used as part of the compile process---have + widely varying licensing terms. Please check individual files before + distributing them to see if those restrictions apply to you. + +I intend for all new source code to use the license below and hope over +time to replace code with other licenses with new implementations that +do use the license below. The varying licensing of the build scripts +seems to be an unavoidable mess. + + +Copyright (c) 2003-2009 +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer + in this position and unchanged. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/external/bsd/libarchive/dist/NEWS b/external/bsd/libarchive/dist/NEWS new file mode 100644 index 000000000..b1d83e302 --- /dev/null +++ b/external/bsd/libarchive/dist/NEWS @@ -0,0 +1,545 @@ +Jun 30, 2010: libarchive 2.8.4 released +Jun 30, 2010: Improved reliability of hash function detection +Jun 30, 2010: Fix issues on ancient FreeBSD, QNX, ancient NetBSD and Minux + +Mar 14, 2010: libarchive 2.8.3 released +Mar 14, 2010: Symlink dereference fix for Linux broke the build there; corrected. + +Mar 14, 2010: libarchive 2.8.2 released +Mar 12, 2010: Fix NULL deference for short self-extracting zip archives. +Mar 12, 2010: Don't dereference symlinks on Linux when reading ACLs. +Mar 07, 2010: Better detection of SHA2 support for old OpenSSL versions. +Mar 07, 2010: Fix parsing of input files for bsdtar -T. +Mar 07, 2010: Do not leak setup_xattr into the global namespace. + +Mar 06, 2010: libarchive 2.8.1 released +Mar 06, 2010: Fix build when an older libarchive is already installed +Mar 03, 2010: Use O_BINARY opening files in bsdtar +Mar 02, 2010: Include missing archive_crc32.h +Mar 01, 2010: Correctly include iconv.h required by libxml2. + +Feb 04, 2010: libarchive 2.8.0 released +Jan 17, 2010: Fix error handling for 'echo nonexistent | cpio -o' +Jan 17, 2010: Don't use futimes() on Cygwin + +Jan 02, 2010: libarchive 2.7.902a released (test release for 2.8) +Jan 02, 2010: Fix tar/test/test_windows on MinGW +Jan 02, 2010: Fix memory leaks in libarchive tests +Jan 01, 2010: Fix memory leak when filter startup fails + +Dec 27, 2009: libarchive 2.7.901a released (test release for 2.8) + +Aug 04, 2009: libarchive 2.7.1 released +Jul 20, 2009: Suppress bogus warning about unxz +Jul 19, 2009: Support Cygwin 1.7 +Jun 11, 2009: Support lzma/xz files compressed with larger buffer sizes. +May 24, 2009: Handle gzip files signed with OpenBSD "gzsig" program. +May 07, 2009: Avoid false failures when reading from pipe. + +Apr 16, 2009: libarchive 2.7.0 released + +Apr 10, 2009: libarchive 2.6.992a released +Apr 09, 2009: Fix SIGPIPE issue building with MSVC. +Apr 09, 2009: Fix several minor memory leaks in libarchive and libarchive_test + +Apr 08, 2009: libarchive 2.6.991a released +Apr 07, 2009: Additional tests added to bsdcpio_test + +Apr 01, 2009: libarchive 2.6.990a released +Apr 01, 2009: Use command-line gunzip, bunzip2, unxz, unlzma for + decompression if the library is built without suitable + libraries. The setup functions return ARCHIVE_WARN + in this case so clients can adapt if necessary. +Apr 01, 2009: Use getpw*_r and getgr*_r functions for thread-safety. +Mar 24, 2009: Add archive_read_next_header2(), which is up to 25% + more efficient for some clients; from Brian Harring. +Mar 22, 2009: PDF versions of manpages are now included in the distribution. +Mar, 2009: Major work to improve Cygwin build by Charles Wilson. +Feb/Mar, 2009: Major work on cmake build support, mostly by Michihiro NAKAJIMA. +Feb/Mar, 2009: Major work on Visual Studio support by Michihiro NAKAJIMA. + All tests now pass. +Feb 25, 2009: Fix Debian Bug #516577 +Feb 21, 2009: Yacc is no longer needed to build; date parser rewritten in C. +Jan/Feb, 2009: Mtree work by Michihiro. +Feb, 2009: Joliet support by Andreas Henriksson. +Jan/Feb, 2009: New options framework by Michihiro. +Feb, 2009: High-res timestamps on Tru64, AIX, and GNU Hurd, by Björn Jacke. +Jan 18, 2009: Extended attributes work on FreeBSD and Linux now with pax format. +Jan 07, 2009: New archive_read_disk_entry_from_file() knows about ACLs, + extended attributes, etc so that bsdtar and bsdcpio don't require + such system-specific knowledge. +Jan 03, 2009: Read filter system extensively refactored. In particular, + read filter pipelines are now built out automatically and individual + filters should be much easier to implement. Documentation on the + Googlecode Wiki explains how to implement new filters. +Dec 28, 2008: Many Windows/Visual Studio fixes from Michihiro NAKAJIMA. + +Dec 28, 2008: Main libarchive development moved from FreeBSD Perforce + server to Google Code. This should make it easier for more + people to participate in libarchive development. + +Dec 28, 2008: libarchive 2.6.0 released +Dec 25, 2008: libarchive 2.5.905a released +Dec 10, 2008: libarchive 2.5.904a released +Dec 04, 2008: libarchive 2.5.903a released +Nov 09, 2008: libarchive 2.5.902a released +Nov 08, 2008: libarchive 2.5.901a released +Nov 08, 2008: Start of pre-release testing for libarchive 2.6 + +Nov 07, 2008: Read filter refactor: The decompression routines just + consume and produce arbitrarily-sized blocks. The reblocking + from read_support_compression_none() has been pulled into the + read core. Also, the decompression bid now makes multiple + passes and stacks read filters. +Oct 21, 2008: bsdcpio: New command-line parser. +Oct 19, 2008: Internal read_ahead change: short reads are now an error +Oct 06, 2008: bsdtar: option parser no longer uses getopt_long(), + gives consistent option parsing on all platforms. +Sep 19, 2008: Jaakko Heinonen: shar utility built on libarchive +Sep 17, 2008: Pedro Giffuni: birthtime support +Sep 17, 2008: Miklos Vajna: lzma reader and test. Note: I still have + some concerns about the auto-detection (LZMA file format + doesn't support auto-detection well), so this is not yet + enabled under archive_read_support_compression_all(). For + now, you must call archive_read_support_compression_lzma() if + you want LZMA read support. +Sep 11, 2008: Ivailo Petrov: Many fixes to Windows build, new solution files +Jul 26, 2008: archive_entry now tracks which values have not been set. + This helps zip extraction (file size is often "unknown") and + time restores (tar usually doesn't know atime). +Jul 26, 2008: Joerg Sonnenberger: Performance improvements to shar writer +Jul 25, 2008: Joerg Sonnenberger: mtree write support + +Jul 02, 2008: libarchive 2.5.5 released + +Jul 02, 2008: libarchive 2.5.5b released +Jul 01, 2008: bsdcpio is being used by enough people, we can call it 1.0.0 now +Jun 20, 2008: bsdcpio: If a -l link fails with EXDEV, copy the file instead +Jun 19, 2008: bsdcpio: additional long options for better GNU cpio compat +Jun 15, 2008: Many small portability and bugfixes since 2.5.4b. + +May 25, 2008: libarchive 2.5.4b released +May 21, 2008: Joerg Sonnenberger: fix bsdtar hardlink handling for newc format + +May 21, 2008: More progress on Windows building. Thanks to "Scott" + for the Windows makefiles, thanks to Kees Zeelenberg for + code contributions. + +May 21, 2008: Fix a number of non-exploitable integer and buffer overflows, + thanks to David Remahl at Apple for pointing these out. + +May 21, 2008: Colin Percival: SIGINFO or SIGUSR1 to bsdtar prints progress info + +May 16, 2008: bsdtar's test harness no longer depends on file ordering. + This was causing spurious test failures on a lot of systems. + Thanks to Bernhard R. Link for the diagnosis. + +May 14, 2008: Joerg Sonnenberger: -s substitution support for bsdtar + +May 13, 2008: Joerg Sonnenberger: Many mtree improvements + +May 11, 2008: Joerg Sonnenberger: fix hardlink extraction when + hardlinks have different permissions from original file + +April 30, 2008: Primary libarchive work has been moved into the FreeBSD + project's Perforce repository: http://perforce.freebsd.org/ + The libarchive project can be browsed at + //depot/user/kientzle/libarchive-portable + Direct link: http://preview.tinyurl.com/46mdgr + +May 04, 2008: libarchive 2.5.3b released + * libarchive: Several fixes to link resolver to address bsdcpio crashes + * bsdcpio: -p hardlink handling fixes + * tar/pax: Ensure ustar dirnames end in '/'; be more careful about + measuring filenames when deciding what pathname fields to use + * libarchive: Mark which entry strings are set; be accurate about + distinguishing empty strings ("") from unset ones (NULL) + * tar: Don't crash reading entries with empty filenames + * libarchive_test, bsdtar_test, bsdcpio_test: Better detaults: + run all tests, delete temp dirs, summarize repeated failures + * -no-undefined to libtool for Cygwin + * libarchive_test: Skip large file tests on systems with 32-bit off_t + * iso9660: Don't bother trying to find the body of an empty file; + this works around strange behavior from some ISO9660 writers + * tar: allow -r -T to be used together + * tar: allow --format with -r or -u + * libarchive: Don't build archive.h + +May 04, 2008: Simplified building: archive.h is no longer constructed + This may require additional #if conditionals on some platforms. + +Mar 30, 2008: libarchive 2.5.1b released + +Mar 15, 2008: libarchive 2.5.0b released +Mar 15, 2008: bsdcpio now seems to correctly write hardlinks into newc, + ustar, and old cpio archives. Just a little more testing before + bsdcpio 1.0 becomes a reality. +Mar 15, 2008: I think the new linkify() interface is finally handling + all known hardlink strategies. +Mar 15, 2008: Mtree read fixes from Joerg Sonnenberger. +Mar 15, 2008: Many new bsdtar and bsdcpio options from Joerg Sonnenberger. +Mar 15, 2008: test harnesses no longer require uudecode; they + now have built-in decoding logic that decodes the reference + files as they are needed. + +Mar 14, 2008: libarchive 2.4.14 released; identical to 2.4.13 except for + a point fix for gname/uname mixup in pax format that was introduced + with the UTF-8 fixes. + +Feb 26, 2008: libarchive 2.4.13 released +Feb 25, 2008: Handle path, linkname, gname, or uname that can't be converted + to/from UTF-8. Implement "hdrcharset" attribute from SUS-2008. +Feb 25, 2008: Fix name clash on NetBSD. +Feb 18, 2008: Fix writing empty 'ar' archives, per Kai Wang +Feb 18, 2008: [bsdtar] Permit appending on block devices. +Feb 09, 2008: New "linkify" resolver to help with newc hardlink writing; + bsdcpio still needs to be converted to use this. +Feb 02, 2008: Windows compatibility fixes from Ivailo Petrov, Kees Zeelenberg +Jan 30, 2008: Ignore hardlink size for non-POSIX tar archives. + +Jan 22, 2008: libarchive 2.4.12 released +Jan 22, 2008: Fix bad padding when writing symlinks to newc cpio archives. +Jan 22, 2008: Verify bsdcpio_test by getting it to work against GNU cpio 2.9. + bsdcpio_test complains about missing options (-y and -z), format + of informational messages (--version, --help), and a minor formatting + issue in odc format output. After this update, bsdcpio_test uncovered + several more cosmetic issues in bsdcpio, all now fixed. +Jan 22, 2008: Experimental support for self-extracting Zip archives. +Jan 22, 2008: Extend hardlink restore strategy to work correctly with + hardlinks extracted from newc cpio files. (Which store the body + only with the last occurrence of a link.) + +Dec 30, 2007: libarchive 2.4.11 released +Dec 30, 2007: Fixed a compile error in bsdcpio on some systems. + +Dec 29, 2007: libarchive 2.4.10 released +Dec 29, 2007: bsdcpio 0.9.0 is ready for wider use. +Dec 29, 2007: Completed initial test harness for bsdcpio. + +Dec 22, 2007: libarchive 2.4.9 released +Dec 22, 2007: Implement the remaining options for bsdcpio: -a, -q, -L, -f, + pattern selection for -i and -it. + +Dec 13, 2007: libarchive 2.4.8 released +Dec 13, 2007: gzip and bzip2 compression now handle zero-byte writes correctly, + Thanks to Damien Golding for bringing this to my attention. + +Dec 12, 2007: libarchive 2.4.7 released + +Dec 10, 2007: libarchive 2.4.6 released +Dec 09, 2007: tar/test/test_copy.c verifies "tar -c | tar -x" copy pipeline +Dec 07, 2007: Fix a couple of minor memory leaks. + +Dec 04, 2007: libarchive 2.4.5 released +Dec 04, 2007: Fix cpio/test/test_write_odc by setting the umask first. + +Dec 03, 2007: libarchive 2.4.4 released +Dec 03, 2007: New configure options --disable-xattr and --disable-acl, + thanks to Samuli Suominen. + +Dec 03, 2007: libarchive 2.4.3 released +Dec 03, 2007: Thanks to Lapo Luchini for sending me a ZIP file that + libarchive couldn't handle. Fixed a bug in handling of + "length at end" flags in ZIP files. +Dec 03, 2007: Fixed bsdcpio -help, bsdtar -help tests. +Dec 02, 2007: First cut at real bsdtar test harness. + +Dec 02, 2007: libarchive 2.4.2 released + +Dec 02, 2007: libarchive 2.4.1 released +Dec 02, 2007: Minor fixes, rough cut of mdoc-to-man conversion for + man pages. + +Oct 30, 2007: libarchive 2.4.0 released +Oct 30, 2007: Minor compile fix thanks to Joerg Schilling. +Oct 30, 2007: Only run the format auction once at the beginning of the + archive. This is simpler and supports better error recovery. +Oct 29, 2007: Test support for very large entries in tar archives: + libarchive_test now exercises entries from 2GB up to 1TB. + +Oct 27, 2007: libarchive 2.3.5 released +Oct 27, 2007: Correct some unnecessary internal data copying in the + "compression none" reader and writer; this reduces user time + by up to 2/3 in some tests. (Thanks to Jan Psota for + publishing his performance test results to GNU tar's bug-tar + mailing list; those results pointed me towards this problem.) +Oct 27, 2007: Fix for skipping archive entries that are exactly + a multiple of 4G on 32-bit platforms. +Oct 25, 2007: Fix for reading very large (>8G) tar archives; this was + broken when I put in support for new GNU tar sparse formats. +Oct 20, 2007: Initial work on new pattern-matching code for cpio; I + hope this eventually replaces the code currently in bsdtar. + +Oct 08, 2007: libarchive 2.3.4 released +Oct 05, 2007: Continuing work on bsdcpio test suite. +Oct 05, 2007: New cpio.5 manpage, updates to "History" of bsdcpio.1 and + bsdtar.1 manpages. +Oct 05, 2007: Fix zip reader to immediately return EOF if you try + to read body of non-regular file. In particular, this fixes + bsdtar extraction of zip archives. + +Sep 30, 2007: libarchive 2.3.3 released +Sep 26, 2007: Rework Makefile.am so that the enable/disable options + actually do the right things. +Sep 26, 2007: cpio-odc and cpio-newc archives no longer write bodies + for non-regular files. +Sep 26, 2007: Test harness for bsdcpio is in place, needs more tests written. + This is much nicer than the ragtag collection of test scripts + that bsdtar has. + +Sep 20, 2007: libarchive 2.3.2 released +Sep 20, 2007: libarchive 2.3.1 broke bsdtar because the archive_write_data() + fix was implemented incorrectly. + +Sep 16, 2007: libarchive 2.3.1 released +Sep 16, 2007: Many fixes to bsdcpio 0.3: handle hardlinks with -p, recognize + block size on writing, fix a couple of segfaults. +Sep 16, 2007: Fixed return value from archive_write_data() when used + with archive_write_disk() to match the documentation and other + instances of this same function. +Sep 15, 2007: Add archive_entry_link_resolver, archive_entry_strmode + +Sep 11, 2007: libarchive 2.2.8 released +Sep 09, 2007: bsdcpio 0.2 supports most (not yet all) of the old POSIX spec. + +Sep 01, 2007: libarchive 2.2.7 released +Aug 31, 2007: Support for reading mtree files, including an mtree.5 manpage + (A little experimental still.) +Aug 18, 2007: Read gtar 1.17 --posix --sparse entries. +Aug 13, 2007: Refined suid/sgid restore handling; it is no longer + an error if suid/sgid bits are dropped when you request + perm restore but don't request owner restore. +Aug 06, 2007: Use --enable-bsdcpio if you want to try bsdcpio + +Aug 05, 2007: libarchive 2.2.6 released +Aug 05, 2007: New configure option --disable-bsdtar, thanks to Joerg + Sonnenberger. +Aug 05, 2007: Several bug fixes from FreeBSD CVS repo. + +Jul 13, 2007: libarchive 2.2.5 released + +Jul 12, 2007: libarchive 2.2.4 released +Jul 12, 2007: Thanks to Colin Percival's help in diagnosing and + fixing several critical security bugs. Details available at + http://security.freebsd.org/advisories/FreeBSD-SA-07:05.libarchive.asc + +May 26, 2007: libarchive 2.2.3 released +May 26, 2007: Fix memory leaks in ZIP reader and shar writer, add some + missing system headers to archive_entry.h, dead code cleanup + from Colin Percival, more tests for gzip/bzip2, fix an + EOF anomaly in bzip2 decompression. + +May 12, 2007: libarchive 2.2.2 released +May 12, 2007: Fix archive_write_disk permission restore by cloning + entry passed into write_header so that permission info is + still available at finish_entry time. (archive_read_extract() + worked okay because it held onto the passed-in entry, but + direct consumers of archive_write_disk would break). This + required fixing archive_entry_clone(), which now works and has + a reasonably complete test case. +May 10, 2007: Skeletal cpio implementation. + +May 06, 2007: libarchive 2.2.1 released +May 06, 2007: Flesh out a lot more of test_entry.c so as to catch + problems such as the device node breakage before releasing . +May 05, 2007: Fix a bad bug introduced in 2.1.9 that broke device + node entries in tar archives. +May 03, 2007: Move 'struct stat' out of archive_entry core as well. + This removes some portability headaches and fixes a bunch + of corner cases that arise when manipulating archives on + dissimilar systems. + +Apr 30, 2007: libarchive 2.1.10 released +Apr 31, 2007: Minor code cleanup. + +Apr 24, 2007: libarchive 2.1.9 released +Apr 24, 2007: Fix some recently-introduced problems with libraries + (Just let automake handle it and it all works much better.) + Finish isolating major()/minor()/makedev() in archive_entry.c. + +Apr 23, 2007: libarchive 2.1.8 released +Apr 23, 2007: Minor fixes found from building on MacOS X + +Apr 22, 2007: libarchive 2.1.7 released +Apr 22, 2007: Eliminated all uses of 'struct stat' from the + format readers/writers. This should improve portability; + 'struct stat' is now only used in archive_entry and in + code that actually touches the disk. + +Apr 17, 2007: libarchive 2.1.6 released + Libarchive now compiles and passes all tests on Interix. + +Apr 16, 2007: libarchive 2.1.5 released + +Apr 15, 2007: libarchive 2.1b2 released +Apr 15, 2007: New libarchive_internals.3 documentation of internal APIs. + Not complete, but should prove helpful. +Apr 15, 2007: Experimental "read_compress_program" and "write_compress_program" + for using libarchive with external compression. Not yet + well tested, and likely has portability issues. Feedback + appreciated. + +Apr 14, 2007: libarchive 2.0.31 released +Apr 14, 2007: More fixes for Interix, more 'ar' work + +Apr 14, 2007: libarchive 2.0.30 released +Apr 13, 2007: libarchive now enforces trailing '/' on dirs + written to tar archives + +Apr 11, 2007: libarchive 2.0.29 released +Apr 11, 2007: Make it easier to statically configure for different platforms. +Apr 11, 2007: Updated config.guess, config.sub, libtool + +Apr 06, 2007: libarchive 2.0.28 released +Apr 06, 2007: 'ar' format read/write support thanks to Kai Wang. + +Apr 01, 2007: libarchive 2.0.27 released +Mar 31, 2007: Several minor fixes from Colin Percival and Joerg Sonnenberger. + +Mar 12, 2007: libarchive 2.0.25 released +Mar 12, 2007: Fix broken --unlink flag. + +Mar 11, 2007: libarchive 2.0.24 released +Mar 10, 2007: Correct an ACL blunder that causes any ACL with an entry + that refers to a non-existent user or group to not be restored correctly. + The fix both makes the parser more tolerant (so that archives created + with the buggy ACLs can be read now) and corrects the ACL formatter. +Mar 10, 2007: More work on test portability to Linux. + +Mar 10, 2007: libarchive 2.0.22 released +Mar 10, 2007: Header cleanups; added linux/fs.h, removed + some unnecessary headers, added #include guards in bsdtar. + If you see any obvious compile failures from this, let me know. +Mar 10, 2007: Work on bsdtar test scripts: not yet robust enough + to enable as part of "make check", but getting better. +Mar 10, 2007: libarchive now returns ARCHIVE_FAILED when + a header write fails in a way that only affects this item. + Less bad than ARCHIVE_FATAL, but worse than ARCHIVE_WARN. + +Mar 07, 2007: libarchive 2.0.21 released +Mar 07, 2007: Add some ACL tests (only for the system-independent + portion of the ACL support for now). +Mar 07, 2007: tar's ability to read ACLs off disk got + turned off for FreeBSD; re-enable it. (ACL restores and + libarchive support for storing/reading ACLs from pax + archives was unaffected.) + +Mar 02, 2007: libarchive 2.0.20 released +Mar 2, 2007: It's not perfect, but it's pretty good. + Libarchive 2.0 is officially out of beta. + +Feb 28, 2007: libarchive 2.0b17 released +Feb 27, 2007: Make the GID restore checks more robust by checking + whether the current user has too few or too many privileges. + +Feb 26, 2007: libarchive 2.0b15 released +Feb 26, 2007: Don't lose symlinks when extracting from ISOs. + Thanks to Diego "Flameeyes" Pettenò for telling me about the + broken testcase on Gentoo that (finally!) led me to the cause + of this long-standing bug. + +Feb 26, 2007: libarchive 2.0b14 released +Feb 26, 2007: Fix a broken test on platforms that lack lchmod(). + +Feb 25, 2007: libarchive 2.0b13 released +Feb 25, 2007: Empty archives were being written as empty files, + without a proper end-of-archive marker. Fixed. + +Feb 23, 2007: libarchive 2.0b12 released +Feb 22, 2007: Basic security checks added: _EXTRACT_SECURE_NODOTDOT + and _EXTRACT_SECURE_SYMLINK. These checks used to be in bsdtar, + but they belong down in libarchive where they can be used by + other tools and where they can be better optimized. + +Feb 11, 2007: libarchive 2.0b11 released +Feb 10, 2007: Fixed a bunch of errors in libarchive's handling + of EXTRACT_PERM and EXTRACT_OWNER, especially relating + to SUID and SGID bits. + +Jan 31, 2007: libarchive 2.0b9 released +Jan 31, 2007: Added read support for "empty" archives as a + distinct archive format. Bsdtar uses this to handle, e.g., + "touch foo.tar; tar -rf foo.tar" + +Jan 22, 2007: libarchive 2.0b6 released +Jan 22, 2007: archive_write_disk API is now in place. It provides + a finer-grained interface than archive_read_extract. In particular, + you can use it to create objects on disk without having an archive + around (just feed it archive_entry objects describing what you + want to create), you can override the uname/gname-to-uid/gid lookups + (minitar uses this to avoid getpwXXX() and getgrXXX() bloat). + +Jan 09, 2007: libarchive 2.0a3 released +Jan 9, 2007: archive_extract is now much better; it handles the + most common cases with a minimal number of system calls. + Some features still need a lot of testing, especially corner + cases involving objects that already exist on disk. I expect + the next round of API overhaul will simplify building test cases. +Jan 9, 2007: a number of fixes thanks to Colin Percival, especially + corrections to the skip() framework and handling of large files. +Jan 9, 2007: Fixes for large ISOs. The code should correctly handle + very large ISOs with entries up to 4G. Thanks to Robert Sciuk + for pointing out these issues. + +Sep 05, 2006: libarchive 1.3.1 released +Sep 5, 2006: Bump version to 1.3 for new I/O wrappers. +Sep 4, 2006: New memory and FILE read/write wrappers. +Sep 4, 2006: libarchive test harness is now minimally functional; + it's located a few minor bugs in error-handling logic + +Aug 17, 2006: libarchive 1.2.54 released +Aug 17, 2006: Outline ABI changes for libarchive 2.0; these + are protected behind #ifdef's until I think I've found everything + that needs to change. +Aug 17, 2006: Fix error-handling in archive_read/write_close() + They weren't returning any errors before. +Aug 17, 2006: Fix recursive-add logic to not trigger if it's not set + Fixes a bug adding files when writing archive to pipe or when + using archive_write_open() directly. +Jul 2006: New "skip" handling improves performance extracting + single files from large uncompressed archives. + +Mar 21, 2006: 1.2.52 released +Mar 21, 2006: Fix -p on platforms that don't have platform-specific + extended attribute code. +Mar 20, 2006: Add NEWS file; fill in some older history from other + files. I'll try to keep this file up-to-date from now on. + +OLDER NEWS SUMMARIES + +Mar 19, 2006: libarchive 1.2.51 released +Mar 18, 2006: Many fixes to extended attribute support, including a redesign + of the storage format to simplify debugging. +Mar 12, 2006: Remove 'tp' support; it was a fun idea, but not worth + spending much time on. +Mar 11, 2006: Incorporated Jaakko Heinonen's still-experimental support + for extended attributes (Currently Linux-only.). +Mar 11, 2006: Reorganized distribution package: There is now one tar.gz + file that builds both libarchive and bsdtar. +Feb 13, 2006: Minor bug fixes: correctly read cpio device entries, write + Pax attribute entry names. +Nov 7, 2005: Experimental 'tp' format support in libarchive. Feedback + appreciated; this is not enabled by archive_read_support_format_all() + yet as I'm not quite content with the format detection heuristics. +Nov 7, 2005: Some more portability improvements thanks to Darin Broady, + minor bugfixes. +Oct 12, 2005: Use GNU libtool to build shared libraries on many systems. +Aug 9, 2005: Correctly detect that MacOS X does not have POSIX ACLs. +Apr 17, 2005: Kees Zeelenberg has ported libarchive and bsdtar to Windows: + http://gnuwin32.sourceforge.net/ +Apr 11, 2005: Extended Zip/Zip64 support thanks to Dan Nelson. -L/-h + fix from Jaakko Heinonen. +Mar 12, 2005: archive_read_extract can now handle very long + pathnames (I've tested with pathnames up to 1MB). +Mar 12, 2005: Marcus Geiger has written an article about libarchive + http://xsnil.antbear.org/2005/02/05/archive-mit-libarchive-verarbeiten/ + including examples of using it from Objective-C. His MoinX + http://moinx.antbear.org/ desktop Wiki uses + libarchive for archiving and restoring Wiki pages. +Jan 22, 2005: Preliminary ZIP extraction support, + new directory-walking code for bsdtar. +Jan 16, 2005: ISO9660 extraction code added; manpage corrections. +May 22, 2004: Many gtar-compatible long options have been added; almost + all FreeBSD ports extract correctly with bsdtar. +May 18, 2004: bsdtar can read Solaris, HP-UX, Unixware, star, gtar, + and pdtar archives. diff --git a/external/bsd/libarchive/dist/README b/external/bsd/libarchive/dist/README new file mode 100644 index 000000000..03e47e854 --- /dev/null +++ b/external/bsd/libarchive/dist/README @@ -0,0 +1,137 @@ +README for libarchive bundle. + +Questions? Issues? + * http://libarchive.googlecode.com/ is the home for ongoing + libarchive development, including issue tracker, additional + documentation, and links to the libarchive mailing lists. + +This distribution bundle includes the following components: + * libarchive: a library for reading and writing streaming archives + * tar: the 'bsdtar' program is a full-featured 'tar' + replacement built on libarchive + * cpio: the 'bsdcpio' program is a different interface to + essentially the same functionality + * examples: Some small example programs that you may find useful. + * examples/minitar: a compact sample demonstrating use of libarchive. + I use this for testing link pollution; it should produce a very + small executable file on most systems. + * contrib: Various items sent to me by third parties; + please contact the authors with any questions. + +The top-level directory contains the following information files: + * NEWS - highlights of recent changes + * COPYING - what you can do with this + * INSTALL - installation instructions + * README - this file + * configure - configuration script, see INSTALL for details. + * CMakeLists.txt - input for "cmake" build tool, see INSTALL + +The following files in the top-level directory are used by the +'configure' script: + * Makefile.am, aclocal.m4, configure.ac + - used to build this distribution, only needed by maintainers + * Makefile.in, config.h.in + - templates used by configure script + +Guide to Documentation installed by this system: + * bsdtar.1 explains the use of the bsdtar program + * bsdcpio.1 explains the use of the bsdcpio program + * libarchive.3 gives an overview of the library as a whole + * archive_read.3, archive_write.3, archive_write_disk.3, and + archive_read_disk.3 provide detailed calling sequences for the read + and write APIs + * archive_entry.3 details the "struct archive_entry" utility class + * archive_internals.3 provides some insight into libarchive's + internal structure and operation. + * libarchive-formats.5 documents the file formats supported by the library + * cpio.5, mtree.5, and tar.5 provide detailed information about these + popular archive formats, including hard-to-find details about + modern cpio and tar variants. +The manual pages above are provided in the 'doc' directory in +a number of different formats. + +You should also read the copious comments in "archive.h" and the +source code for the sample programs for more details. Please let me +know about any errors or omissions you find. + +Currently, the library automatically detects and reads the following: + * gzip compression + * bzip2 compression + * compress/LZW compression + * lzma and xz compression + * GNU tar format (including GNU long filenames, long link names, and + sparse files) + * Solaris 9 extended tar format (including ACLs) + * Old V7 tar archives + * POSIX ustar + * POSIX pax interchange format + * POSIX octet-oriented cpio + * SVR4 ASCII cpio + * POSIX octet-oriented cpio + * Binary cpio (big-endian or little-endian) + * ISO9660 CD-ROM images (with optional Rockridge or Joliet extensions) + * ZIP archives (with uncompressed or "deflate" compressed entries) + * GNU and BSD 'ar' archives + * 'mtree' format + +The library can write: + * gzip compression + * bzip2 compression + * compress/LZW compression + * lzma and xz compression + * POSIX ustar + * POSIX pax interchange format + * "restricted" pax format, which will create ustar archives except for + entries that require pax extensions (for long filenames, ACLs, etc). + * POSIX octet-oriented cpio + * SVR4 "newc" cpio + * shar archives + * ZIP archives (with uncompressed or "deflate" compressed entries) + * GNU and BSD 'ar' archives + * 'mtree' format + +Notes about the library architecture: + + * This is a heavily stream-oriented system. There is no direct + support for in-place modification or random access. + + * The library is designed to be extended with new compression and + archive formats. The only requirement is that the format be + readable or writable as a stream and that each archive entry be + independent. There are articles on the libarchive Wiki explaining + how to extend libarchive. + + * On read, compression and format are always detected automatically. + + * I've attempted to minimize static link pollution. If you don't + explicitly invoke a particular feature (such as support for a + particular compression or format), it won't get pulled in. + In particular, if you don't explicitly enable a particular + compression or decompression support, you won't need to link + against the corresponding compression or decompression libraries. + This also reduces the size of statically-linked binaries in + environments where that matters. + + * On read, the library accepts whatever blocks you hand it. + Your read callback is free to pass the library a byte at a time + or mmap the entire archive and give it to the library at once. + On write, the library always produces correctly-blocked output. + + * The object-style approach allows you to have multiple archive streams + open at once. bsdtar uses this in its "@archive" extension. + + * The archive itself is read/written using callback functions. + You can read an archive directly from an in-memory buffer or + write it to a socket, if you wish. There are some utility + functions to provide easy-to-use "open file," etc, capabilities. + + * The read/write APIs are designed to allow individual entries + to be read or written to any data source: You can create + a block of data in memory and add it to a tar archive without + first writing a temporary file. You can also read an entry from + an archive and write the data directly to a socket. If you want + to read/write entries to disk, there are convenience functions to + make this especially easy. + + * Note: "pax interchange format" is really an extended tar format, + despite what the name says. diff --git a/external/bsd/libarchive/dist/cpio/bsdcpio.1 b/external/bsd/libarchive/dist/cpio/bsdcpio.1 new file mode 100644 index 000000000..79b6997ef --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/bsdcpio.1 @@ -0,0 +1,405 @@ +.\" Copyright (c) 2003-2007 Tim Kientzle +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd December 21, 2007 +.Dt BSDCPIO 1 +.Os +.Sh NAME +.Nm cpio +.Nd copy files to and from archives +.Sh SYNOPSIS +.Nm +.Brq Fl i +.Op Ar options +.Op Ar pattern ... +.Op Ar < archive +.Nm +.Brq Fl o +.Op Ar options +.Ar < name-list +.Op Ar > archive +.Nm +.Brq Fl p +.Op Ar options +.Ar dest-dir +.Ar < name-list +.Sh DESCRIPTION +.Nm +copies files between archives and directories. +This implementation can extract from tar, pax, cpio, zip, jar, ar, +and ISO 9660 cdrom images and can create tar, pax, cpio, ar, +and shar archives. +.Pp +The first option to +.Nm +is a mode indicator from the following list: +.Bl -tag -compact -width indent +.It Fl i +Input. +Read an archive from standard input (unless overriden) and extract the +contents to disk or (if the +.Fl t +option is specified) +list the contents to standard output. +If one or more file patterns are specified, only files matching +one of the patterns will be extracted. +.It Fl o +Output. +Read a list of filenames from standard input and produce a new archive +on standard output (unless overriden) containing the specified items. +.It Fl p +Pass-through. +Read a list of filenames from standard input and copy the files to the +specified directory. +.El +.Pp +.Sh OPTIONS +Unless specifically stated otherwise, options are applicable in +all operating modes. +.Bl -tag -width indent +.It Fl 0 +Read filenames separated by NUL characters instead of newlines. +This is necessary if any of the filenames being read might contain newlines. +.It Fl A +(o mode only) +Append to the specified archive. +(Not yet implemented.) +.It Fl a +(o and p modes) +Reset access times on files after they are read. +.It Fl B +(o mode only) +Block output to records of 5120 bytes. +.It Fl C Ar size +(o mode only) +Block output to records of +.Ar size +bytes. +.It Fl c +(o mode only) +Use the old POSIX portable character format. +Equivalent to +.Fl -format Ar odc . +.It Fl d +(i and p modes) +Create directories as necessary. +.It Fl E Ar file +(i mode only) +Read list of file name patterns from +.Ar file +to list and extract. +.It Fl F Ar file +Read archive from or write archive to +.Ar file . +.It Fl f Ar pattern +(i mode only) +Ignore files that match +.Ar pattern . +.It Fl -format Ar format +(o mode only) +Produce the output archive in the specified format. +Supported formats include: +.Pp +.Bl -tag -width "iso9660" -compact +.It Ar cpio +Synonym for +.Ar odc . +.It Ar newc +The SVR4 portable cpio format. +.It Ar odc +The old POSIX.1 portable octet-oriented cpio format. +.It Ar pax +The POSIX.1 pax format, an extension of the ustar format. +.It Ar ustar +The POSIX.1 tar format. +.El +.Pp +The default format is +.Ar odc . +See +.Xr libarchive_formats 5 +for more complete information about the +formats currently supported by the underlying +.Xr libarchive 3 +library. +.It Fl H Ar format +Synonym for +.Fl -format . +.It Fl h , Fl -help +Print usage information. +.It Fl I Ar file +Read archive from +.Ar file . +.It Fl i +Input mode. +See above for description. +.It Fl -insecure +(i and p mode only) +Disable security checks during extraction or copying. +This allows extraction via symbolic links and path names containing +.Sq .. +in the name. +.It Fl J +(o mode only) +Compress the file with xz-compatible compression before writing it. +In input mode, this option is ignored; xz compression is recognized +automatically on input. +.It Fl j +Synonym for +.Fl y . +.It Fl L +(o and p modes) +All symbolic links will be followed. +Normally, symbolic links are archived and copied as symbolic links. +With this option, the target of the link will be archived or copied instead. +.It Fl l +(p mode only) +Create links from the target directory to the original files, +instead of copying. +.It Fl lzma +(o mode only) +Compress the file with lzma-compatible compression before writing it. +In input mode, this option is ignored; lzma compression is recognized +automatically on input. +.It Fl m +(i and p modes) +Set file modification time on created files to match +those in the source. +.It Fl n +(i mode, only with +.Fl t ) +Display numeric uid and gid. +By default, +.Nm +displays the user and group names when they are provided in the +archive, or looks up the user and group names in the system +password database. +.It Fl no-preserve-owner +(i mode only) +Do not attempt to restore file ownership. +This is the default when run by non-root users. +.It Fl O Ar file +Write archive to +.Ar file . +.It Fl o +Output mode. +See above for description. +.It Fl p +Pass-through mode. +See above for description. +.It Fl preserve-owner +(i mode only) +Restore file ownership. +This is the default when run by the root user. +.It Fl -quiet +Suppress unnecessary messages. +.It Fl R Oo user Oc Ns Oo : Oc Ns Oo group Oc +Set the owner and/or group on files in the output. +If group is specified with no user +(for example, +.Fl R Ar :wheel ) +then the group will be set but not the user. +If the user is specified with a trailing colon and no group +(for example, +.Fl R Ar root: ) +then the group will be set to the user's default group. +If the user is specified with no trailing colon, then +the user will be set but not the group. +In +.Fl i +and +.Fl p +modes, this option can only be used by the super-user. +(For compatibility, a period can be used in place of the colon.) +.It Fl r +(All modes.) +Rename files interactively. +For each file, a prompt is written to +.Pa /dev/tty +containing the name of the file and a line is read from +.Pa /dev/tty . +If the line read is blank, the file is skipped. +If the line contains a single period, the file is processed normally. +Otherwise, the line is taken to be the new name of the file. +.It Fl t +(i mode only) +List the contents of the archive to stdout; +do not restore the contents to disk. +.It Fl u +(i and p modes) +Unconditionally overwrite existing files. +Ordinarily, an older file will not overwrite a newer file on disk. +.It Fl v +Print the name of each file to stderr as it is processed. +With +.Fl t , +provide a detailed listing of each file. +.It Fl -version +Print the program version information and exit. +.It Fl y +(o mode only) +Compress the archive with bzip2-compatible compression before writing it. +In input mode, this option is ignored; +bzip2 compression is recognized automatically on input. +.It Fl Z +(o mode only) +Compress the archive with compress-compatible compression before writing it. +In input mode, this option is ignored; +compression is recognized automatically on input. +.It Fl z +(o mode only) +Compress the archive with gzip-compatible compression before writing it. +In input mode, this option is ignored; +gzip compression is recognized automatically on input. +.El +.Sh ENVIRONMENT +The following environment variables affect the execution of +.Nm : +.Bl -tag -width ".Ev BLOCKSIZE" +.It Ev LANG +The locale to use. +See +.Xr environ 7 +for more information. +.It Ev TZ +The timezone to use when displaying dates. +See +.Xr environ 7 +for more information. +.El +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +The +.Nm +command is traditionally used to copy file heirarchies in conjunction +with the +.Xr find 1 +command. +The first example here simply copies all files from +.Pa src +to +.Pa dest : +.Dl Nm find Pa src | Nm Fl pmud Pa dest +.Pp +By carefully selecting options to the +.Xr find 1 +command and combining it with other standard utilities, +it is possible to exercise very fine control over which files are copied. +This next example copies files from +.Pa src +to +.Pa dest +that are more than 2 days old and whose names match a particular pattern: +.Dl Nm find Pa src Fl mtime Ar +2 | Nm grep foo[bar] | Nm Fl pdmu Pa dest +.Pp +This example copies files from +.Pa src +to +.Pa dest +that are more than 2 days old and which contain the word +.Do foobar Dc : +.Dl Nm find Pa src Fl mtime Ar +2 | Nm xargs Nm grep -l foobar | Nm Fl pdmu Pa dest +.Sh COMPATIBILITY +The mode options i, o, and p and the options +a, B, c, d, f, l, m, r, t, u, and v comply with SUSv2. +.Pp +The old POSIX.1 standard specified that only +.Fl i , +.Fl o , +and +.Fl p +were interpreted as command-line options. +Each took a single argument of a list of modifier +characters. +For example, the standard syntax allows +.Fl imu +but does not support +.Fl miu +or +.Fl i Fl m Fl u , +since +.Ar m +and +.Ar u +are only modifiers to +.Fl i , +they are not command-line options in their own right. +The syntax supported by this implementation is backwards-compatible +with the standard. +For best compatibility, scripts should limit themselves to the +standard syntax. +.Sh SEE ALSO +.Xr bzip2 1 , +.Xr tar 1 , +.Xr gzip 1 , +.Xr mt 1 , +.Xr pax 1 , +.Xr libarchive 3 , +.Xr cpio 5 , +.Xr libarchive-formats 5 , +.Xr tar 5 +.Sh STANDARDS +There is no current POSIX standard for the cpio command; it appeared +in +.St -p1003.1-96 +but was dropped from +.St -p1003.1-2001 . +.Pp +The cpio, ustar, and pax interchange file formats are defined by +.St -p1003.1-2001 +for the pax command. +.Sh HISTORY +The original +.Nm cpio +and +.Nm find +utilities were written by Dick Haight +while working in AT&T's Unix Support Group. +They first appeared in 1977 in PWB/UNIX 1.0, the +.Dq Programmer's Work Bench +system developed for use within AT&T. +They were first released outside of AT&T as part of System III Unix in 1981. +As a result, +.Nm cpio +actually predates +.Nm tar , +even though it was not well-known outside of AT&T until some time later. +.Pp +This is a complete re-implementation based on the +.Xr libarchive 3 +library. +.Sh BUGS +The cpio archive format has several basic limitations: +It does not store user and group names, only numbers. +As a result, it cannot be reliably used to transfer +files between systems with dissimilar user and group numbering. +Older cpio formats limit the user and group numbers to +16 or 18 bits, which is insufficient for modern systems. +The cpio archive formats cannot support files over 4 gigabytes, +except for the +.Dq odc +variant, which can support files up to 8 gigabytes. diff --git a/external/bsd/libarchive/dist/cpio/cmdline.c b/external/bsd/libarchive/dist/cpio/cmdline.c new file mode 100644 index 000000000..2223798c1 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/cmdline.c @@ -0,0 +1,369 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "cpio_platform.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/cmdline.c,v 1.5 2008/12/06 07:30:40 kientzle Exp $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_GRP_H +#include +#endif +#ifdef HAVE_PWD_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "cpio.h" +#include "err.h" + +/* + * Short options for cpio. Please keep this sorted. + */ +static const char *short_options = "0AaBC:cdE:F:f:H:hI:iJjLlmnO:opR:rtuvW:yZz"; + +/* + * Long options for cpio. Please keep this sorted. + */ +static const struct option { + const char *name; + int required; /* 1 if this option requires an argument */ + int equivalent; /* Equivalent short option. */ +} cpio_longopts[] = { + { "create", 0, 'o' }, + { "extract", 0, 'i' }, + { "file", 1, 'F' }, + { "format", 1, 'H' }, + { "help", 0, 'h' }, + { "insecure", 0, OPTION_INSECURE }, + { "link", 0, 'l' }, + { "list", 0, 't' }, + { "lzma", 0, OPTION_LZMA }, + { "make-directories", 0, 'd' }, + { "no-preserve-owner", 0, OPTION_NO_PRESERVE_OWNER }, + { "null", 0, '0' }, + { "numeric-uid-gid", 0, 'n' }, + { "owner", 1, 'R' }, + { "pass-through", 0, 'p' }, + { "preserve-modification-time", 0, 'm' }, + { "preserve-owner", 0, OPTION_PRESERVE_OWNER }, + { "quiet", 0, OPTION_QUIET }, + { "unconditional", 0, 'u' }, + { "verbose", 0, 'v' }, + { "version", 0, OPTION_VERSION }, + { "xz", 0, 'J' }, + { NULL, 0, 0 } +}; + +/* + * I used to try to select platform-provided getopt() or + * getopt_long(), but that caused a lot of headaches. In particular, + * I couldn't consistently use long options in the test harness + * because not all platforms have getopt_long(). That in turn led to + * overuse of the -W hack in the test harness, which made it rough to + * run the test harness against GNU cpio. (I periodically run the + * test harness here against GNU cpio as a sanity-check. Yes, + * I've found a couple of bugs in GNU cpio that way.) + */ +int +cpio_getopt(struct cpio *cpio) +{ + enum { state_start = 0, state_next_word, state_short, state_long }; + static int state = state_start; + static char *opt_word; + + const struct option *popt, *match = NULL, *match2 = NULL; + const char *p, *long_prefix = "--"; + size_t optlength; + int opt = '?'; + int required = 0; + + cpio->optarg = NULL; + + /* First time through, initialize everything. */ + if (state == state_start) { + /* Skip program name. */ + ++cpio->argv; + --cpio->argc; + state = state_next_word; + } + + /* + * We're ready to look at the next word in argv. + */ + if (state == state_next_word) { + /* No more arguments, so no more options. */ + if (cpio->argv[0] == NULL) + return (-1); + /* Doesn't start with '-', so no more options. */ + if (cpio->argv[0][0] != '-') + return (-1); + /* "--" marks end of options; consume it and return. */ + if (strcmp(cpio->argv[0], "--") == 0) { + ++cpio->argv; + --cpio->argc; + return (-1); + } + /* Get next word for parsing. */ + opt_word = *cpio->argv++; + --cpio->argc; + if (opt_word[1] == '-') { + /* Set up long option parser. */ + state = state_long; + opt_word += 2; /* Skip leading '--' */ + } else { + /* Set up short option parser. */ + state = state_short; + ++opt_word; /* Skip leading '-' */ + } + } + + /* + * We're parsing a group of POSIX-style single-character options. + */ + if (state == state_short) { + /* Peel next option off of a group of short options. */ + opt = *opt_word++; + if (opt == '\0') { + /* End of this group; recurse to get next option. */ + state = state_next_word; + return cpio_getopt(cpio); + } + + /* Does this option take an argument? */ + p = strchr(short_options, opt); + if (p == NULL) + return ('?'); + if (p[1] == ':') + required = 1; + + /* If it takes an argument, parse that. */ + if (required) { + /* If arg is run-in, opt_word already points to it. */ + if (opt_word[0] == '\0') { + /* Otherwise, pick up the next word. */ + opt_word = *cpio->argv; + if (opt_word == NULL) { + lafe_warnc(0, + "Option -%c requires an argument", + opt); + return ('?'); + } + ++cpio->argv; + --cpio->argc; + } + if (opt == 'W') { + state = state_long; + long_prefix = "-W "; /* For clearer errors. */ + } else { + state = state_next_word; + cpio->optarg = opt_word; + } + } + } + + /* We're reading a long option, including -W long=arg convention. */ + if (state == state_long) { + /* After this long option, we'll be starting a new word. */ + state = state_next_word; + + /* Option name ends at '=' if there is one. */ + p = strchr(opt_word, '='); + if (p != NULL) { + optlength = (size_t)(p - opt_word); + cpio->optarg = (char *)(uintptr_t)(p + 1); + } else { + optlength = strlen(opt_word); + } + + /* Search the table for an unambiguous match. */ + for (popt = cpio_longopts; popt->name != NULL; popt++) { + /* Short-circuit if first chars don't match. */ + if (popt->name[0] != opt_word[0]) + continue; + /* If option is a prefix of name in table, record it.*/ + if (strncmp(opt_word, popt->name, optlength) == 0) { + match2 = match; /* Record up to two matches. */ + match = popt; + /* If it's an exact match, we're done. */ + if (strlen(popt->name) == optlength) { + match2 = NULL; /* Forget the others. */ + break; + } + } + } + + /* Fail if there wasn't a unique match. */ + if (match == NULL) { + lafe_warnc(0, + "Option %s%s is not supported", + long_prefix, opt_word); + return ('?'); + } + if (match2 != NULL) { + lafe_warnc(0, + "Ambiguous option %s%s (matches --%s and --%s)", + long_prefix, opt_word, match->name, match2->name); + return ('?'); + } + + /* We've found a unique match; does it need an argument? */ + if (match->required) { + /* Argument required: get next word if necessary. */ + if (cpio->optarg == NULL) { + cpio->optarg = *cpio->argv; + if (cpio->optarg == NULL) { + lafe_warnc(0, + "Option %s%s requires an argument", + long_prefix, match->name); + return ('?'); + } + ++cpio->argv; + --cpio->argc; + } + } else { + /* Argument forbidden: fail if there is one. */ + if (cpio->optarg != NULL) { + lafe_warnc(0, + "Option %s%s does not allow an argument", + long_prefix, match->name); + return ('?'); + } + } + return (match->equivalent); + } + + return (opt); +} + + +/* + * Parse the argument to the -R or --owner flag. + * + * The format is one of the following: + * - Override user but not group + * : - Override both, group is user's default group + * : - Override user but not group + * : - Override both + * : - Override group but not user + * + * Where uid/gid are decimal representations and groupname/username + * are names to be looked up in system database. Note that we try + * to look up an argument as a name first, then try numeric parsing. + * + * A period can be used instead of the colon. + * + * Sets uid/gid return as appropriate, -1 indicates uid/gid not specified. + * + * Returns NULL if no error, otherwise returns error string for display. + * + */ +const char * +owner_parse(const char *spec, int *uid, int *gid) +{ + static char errbuff[128]; + const char *u, *ue, *g; + + *uid = -1; + *gid = -1; + + if (spec[0] == '\0') + return ("Invalid empty user/group spec"); + + /* + * Split spec into [user][:.][group] + * u -> first char of username, NULL if no username + * ue -> first char after username (colon, period, or \0) + * g -> first char of group name + */ + if (*spec == ':' || *spec == '.') { + /* If spec starts with ':' or '.', then just group. */ + ue = u = NULL; + g = spec + 1; + } else { + /* Otherwise, [user] or [user][:] or [user][:][group] */ + ue = u = spec; + while (*ue != ':' && *ue != '.' && *ue != '\0') + ++ue; + g = ue; + if (*g != '\0') /* Skip : or . to find first char of group. */ + ++g; + } + + if (u != NULL) { + /* Look up user: ue is first char after end of user. */ + char *user; + struct passwd *pwent; + + user = (char *)malloc(ue - u + 1); + if (user == NULL) + return ("Couldn't allocate memory"); + memcpy(user, u, ue - u); + user[ue - u] = '\0'; + if ((pwent = getpwnam(user)) != NULL) { + *uid = pwent->pw_uid; + if (*ue != '\0') + *gid = pwent->pw_gid; + } else { + char *end; + errno = 0; + *uid = strtoul(user, &end, 10); + if (errno || *end != '\0') { + snprintf(errbuff, sizeof(errbuff), + "Couldn't lookup user ``%s''", user); + errbuff[sizeof(errbuff) - 1] = '\0'; + return (errbuff); + } + } + free(user); + } + + if (*g != '\0') { + struct group *grp; + if ((grp = getgrnam(g)) != NULL) { + *gid = grp->gr_gid; + } else { + char *end; + errno = 0; + *gid = strtoul(g, &end, 10); + if (errno || *end != '\0') { + snprintf(errbuff, sizeof(errbuff), + "Couldn't lookup group ``%s''", g); + errbuff[sizeof(errbuff) - 1] = '\0'; + return (errbuff); + } + } + } + return (NULL); +} diff --git a/external/bsd/libarchive/dist/cpio/cpio.c b/external/bsd/libarchive/dist/cpio/cpio.c new file mode 100644 index 000000000..7d5031bbc --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/cpio.c @@ -0,0 +1,1267 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "cpio_platform.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/cpio.c,v 1.15 2008/12/06 07:30:40 kientzle Exp $"); + +#include +#include +#include + +#ifdef HAVE_SYS_MKDEV_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_GRP_H +#include +#endif +#ifdef HAVE_PWD_H +#include +#endif +#ifdef HAVE_STDARG_H +#include +#endif +#ifdef HAVE_STDINT_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_TIME_H +#include +#endif + +#include "cpio.h" +#include "err.h" +#include "line_reader.h" +#include "matching.h" + +/* Fixed size of uname/gname caches. */ +#define name_cache_size 101 + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +struct name_cache { + int probes; + int hits; + size_t size; + struct { + id_t id; + char *name; + } cache[name_cache_size]; +}; + +static int extract_data(struct archive *, struct archive *); +const char * cpio_i64toa(int64_t); +static const char *cpio_rename(const char *name); +static int entry_to_archive(struct cpio *, struct archive_entry *); +static int file_to_archive(struct cpio *, const char *); +static void free_cache(struct name_cache *cache); +static void list_item_verbose(struct cpio *, struct archive_entry *); +static void long_help(void); +static const char *lookup_gname(struct cpio *, gid_t gid); +static int lookup_gname_helper(struct cpio *, + const char **name, id_t gid); +static const char *lookup_uname(struct cpio *, uid_t uid); +static int lookup_uname_helper(struct cpio *, + const char **name, id_t uid); +static void mode_in(struct cpio *); +static void mode_list(struct cpio *); +static void mode_out(struct cpio *); +static void mode_pass(struct cpio *, const char *); +static int restore_time(struct cpio *, struct archive_entry *, + const char *, int fd); +static void usage(void); +static void version(void); + +int +main(int argc, char *argv[]) +{ + static char buff[16384]; + struct cpio _cpio; /* Allocated on stack. */ + struct cpio *cpio; + const char *errmsg; + int uid, gid; + int opt; + + cpio = &_cpio; + memset(cpio, 0, sizeof(*cpio)); + cpio->buff = buff; + cpio->buff_size = sizeof(buff); + + /* Need lafe_progname before calling lafe_warnc. */ + if (*argv == NULL) + lafe_progname = "bsdcpio"; + else { +#if defined(_WIN32) && !defined(__CYGWIN__) + lafe_progname = strrchr(*argv, '\\'); +#else + lafe_progname = strrchr(*argv, '/'); +#endif + if (lafe_progname != NULL) + lafe_progname++; + else + lafe_progname = *argv; + } + + cpio->uid_override = -1; + cpio->gid_override = -1; + cpio->argv = argv; + cpio->argc = argc; + cpio->mode = '\0'; + cpio->verbose = 0; + cpio->compress = '\0'; + cpio->extract_flags = ARCHIVE_EXTRACT_NO_AUTODIR; + cpio->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; + cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_SYMLINKS; + cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NODOTDOT; + cpio->extract_flags |= ARCHIVE_EXTRACT_PERM; + cpio->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; + cpio->extract_flags |= ARCHIVE_EXTRACT_ACL; +#if !defined(_WIN32) && !defined(__CYGWIN__) + if (geteuid() == 0) + cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER; +#endif + cpio->bytes_per_block = 512; + cpio->filename = NULL; + + while ((opt = cpio_getopt(cpio)) != -1) { + switch (opt) { + case '0': /* GNU convention: --null, -0 */ + cpio->option_null = 1; + break; + case 'A': /* NetBSD/OpenBSD */ + cpio->option_append = 1; + break; + case 'a': /* POSIX 1997 */ + cpio->option_atime_restore = 1; + break; + case 'B': /* POSIX 1997 */ + cpio->bytes_per_block = 5120; + break; + case 'C': /* NetBSD/OpenBSD */ + cpio->bytes_per_block = atoi(cpio->optarg); + if (cpio->bytes_per_block <= 0) + lafe_errc(1, 0, "Invalid blocksize %s", cpio->optarg); + break; + case 'c': /* POSIX 1997 */ + cpio->format = "odc"; + break; + case 'd': /* POSIX 1997 */ + cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_AUTODIR; + break; + case 'E': /* NetBSD/OpenBSD */ + lafe_include_from_file(&cpio->matching, + cpio->optarg, cpio->option_null); + break; + case 'F': /* NetBSD/OpenBSD/GNU cpio */ + cpio->filename = cpio->optarg; + break; + case 'f': /* POSIX 1997 */ + lafe_exclude(&cpio->matching, cpio->optarg); + break; + case 'H': /* GNU cpio (also --format) */ + cpio->format = cpio->optarg; + break; + case 'h': + long_help(); + break; + case 'I': /* NetBSD/OpenBSD */ + cpio->filename = cpio->optarg; + break; + case 'i': /* POSIX 1997 */ + if (cpio->mode != '\0') + lafe_errc(1, 0, + "Cannot use both -i and -%c", cpio->mode); + cpio->mode = opt; + break; + case 'J': /* GNU tar, others */ + cpio->compress = opt; + break; + case 'j': /* GNU tar, others */ + cpio->compress = opt; + break; + case OPTION_INSECURE: + cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_SYMLINKS; + cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; + break; + case 'L': /* GNU cpio */ + cpio->option_follow_links = 1; + break; + case 'l': /* POSIX 1997 */ + cpio->option_link = 1; + break; + case OPTION_LZMA: /* GNU tar, others */ + cpio->compress = opt; + break; + case 'm': /* POSIX 1997 */ + cpio->extract_flags |= ARCHIVE_EXTRACT_TIME; + break; + case 'n': /* GNU cpio */ + cpio->option_numeric_uid_gid = 1; + break; + case OPTION_NO_PRESERVE_OWNER: /* GNU cpio */ + cpio->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; + break; + case 'O': /* GNU cpio */ + cpio->filename = cpio->optarg; + break; + case 'o': /* POSIX 1997 */ + if (cpio->mode != '\0') + lafe_errc(1, 0, + "Cannot use both -o and -%c", cpio->mode); + cpio->mode = opt; + break; + case 'p': /* POSIX 1997 */ + if (cpio->mode != '\0') + lafe_errc(1, 0, + "Cannot use both -p and -%c", cpio->mode); + cpio->mode = opt; + cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; + break; + case OPTION_PRESERVE_OWNER: + cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER; + break; + case OPTION_QUIET: /* GNU cpio */ + cpio->quiet = 1; + break; + case 'R': /* GNU cpio, also --owner */ + errmsg = owner_parse(cpio->optarg, &uid, &gid); + if (errmsg) { + lafe_warnc(-1, "%s", errmsg); + usage(); + } + if (uid != -1) + cpio->uid_override = uid; + if (gid != -1) + cpio->gid_override = gid; + break; + case 'r': /* POSIX 1997 */ + cpio->option_rename = 1; + break; + case 't': /* POSIX 1997 */ + cpio->option_list = 1; + break; + case 'u': /* POSIX 1997 */ + cpio->extract_flags + &= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; + break; + case 'v': /* POSIX 1997 */ + cpio->verbose++; + break; + case OPTION_VERSION: /* GNU convention */ + version(); + break; +#if 0 + /* + * cpio_getopt() handles -W specially, so it's not + * available here. + */ + case 'W': /* Obscure, but useful GNU convention. */ + break; +#endif + case 'y': /* tar convention */ + cpio->compress = opt; + break; + case 'Z': /* tar convention */ + cpio->compress = opt; + break; + case 'z': /* tar convention */ + cpio->compress = opt; + break; + default: + usage(); + } + } + + /* + * Sanity-check args, error out on nonsensical combinations. + */ + /* -t implies -i if no mode was specified. */ + if (cpio->option_list && cpio->mode == '\0') + cpio->mode = 'i'; + /* -t requires -i */ + if (cpio->option_list && cpio->mode != 'i') + lafe_errc(1, 0, "Option -t requires -i"); + /* -n requires -it */ + if (cpio->option_numeric_uid_gid && !cpio->option_list) + lafe_errc(1, 0, "Option -n requires -it"); + /* Can only specify format when writing */ + if (cpio->format != NULL && cpio->mode != 'o') + lafe_errc(1, 0, "Option --format requires -o"); + /* -l requires -p */ + if (cpio->option_link && cpio->mode != 'p') + lafe_errc(1, 0, "Option -l requires -p"); + /* TODO: Flag other nonsensical combinations. */ + + switch (cpio->mode) { + case 'o': + /* TODO: Implement old binary format in libarchive, + use that here. */ + if (cpio->format == NULL) + cpio->format = "odc"; /* Default format */ + + mode_out(cpio); + break; + case 'i': + while (*cpio->argv != NULL) { + lafe_include(&cpio->matching, *cpio->argv); + --cpio->argc; + ++cpio->argv; + } + if (cpio->option_list) + mode_list(cpio); + else + mode_in(cpio); + break; + case 'p': + if (*cpio->argv == NULL || **cpio->argv == '\0') + lafe_errc(1, 0, + "-p mode requires a target directory"); + mode_pass(cpio, *cpio->argv); + break; + default: + lafe_errc(1, 0, + "Must specify at least one of -i, -o, or -p"); + } + + free_cache(cpio->gname_cache); + free_cache(cpio->uname_cache); + return (cpio->return_value); +} + +static void +usage(void) +{ + const char *p; + + p = lafe_progname; + + fprintf(stderr, "Brief Usage:\n"); + fprintf(stderr, " List: %s -it < archive\n", p); + fprintf(stderr, " Extract: %s -i < archive\n", p); + fprintf(stderr, " Create: %s -o < filenames > archive\n", p); + fprintf(stderr, " Help: %s --help\n", p); + exit(1); +} + +static const char *long_help_msg = + "First option must be a mode specifier:\n" + " -i Input -o Output -p Pass\n" + "Common Options:\n" + " -v Verbose\n" + "Create: %p -o [options] < [list of files] > [archive]\n" + " -J,-y,-z,--lzma Compress archive with xz/bzip2/gzip/lzma\n" + " --format {odc|newc|ustar} Select archive format\n" + "List: %p -it < [archive]\n" + "Extract: %p -i [options] < [archive]\n"; + + +/* + * Note that the word 'bsdcpio' will always appear in the first line + * of output. + * + * In particular, /bin/sh scripts that need to test for the presence + * of bsdcpio can use the following template: + * + * if (cpio --help 2>&1 | grep bsdcpio >/dev/null 2>&1 ) then \ + * echo bsdcpio; else echo not bsdcpio; fi + */ +static void +long_help(void) +{ + const char *prog; + const char *p; + + prog = lafe_progname; + + fflush(stderr); + + p = (strcmp(prog,"bsdcpio") != 0) ? "(bsdcpio)" : ""; + printf("%s%s: manipulate archive files\n", prog, p); + + for (p = long_help_msg; *p != '\0'; p++) { + if (*p == '%') { + if (p[1] == 'p') { + fputs(prog, stdout); + p++; + } else + putchar('%'); + } else + putchar(*p); + } + version(); +} + +static void +version(void) +{ + fprintf(stdout,"bsdcpio %s -- %s\n", + BSDCPIO_VERSION_STRING, + archive_version()); + exit(0); +} + +static void +mode_out(struct cpio *cpio) +{ + struct archive_entry *entry, *spare; + struct lafe_line_reader *lr; + const char *p; + int r; + + if (cpio->option_append) + lafe_errc(1, 0, "Append mode not yet supported."); + + cpio->archive_read_disk = archive_read_disk_new(); + if (cpio->archive_read_disk == NULL) + lafe_errc(1, 0, "Failed to allocate archive object"); + if (cpio->option_follow_links) + archive_read_disk_set_symlink_logical(cpio->archive_read_disk); + else + archive_read_disk_set_symlink_physical(cpio->archive_read_disk); + archive_read_disk_set_standard_lookup(cpio->archive_read_disk); + + cpio->archive = archive_write_new(); + if (cpio->archive == NULL) + lafe_errc(1, 0, "Failed to allocate archive object"); + switch (cpio->compress) { + case 'J': + r = archive_write_set_compression_xz(cpio->archive); + break; + case OPTION_LZMA: + r = archive_write_set_compression_lzma(cpio->archive); + break; + case 'j': case 'y': + r = archive_write_set_compression_bzip2(cpio->archive); + break; + case 'z': + r = archive_write_set_compression_gzip(cpio->archive); + break; + case 'Z': + r = archive_write_set_compression_compress(cpio->archive); + break; + default: + r = archive_write_set_compression_none(cpio->archive); + break; + } + if (r < ARCHIVE_WARN) + lafe_errc(1, 0, "Requested compression not available"); + r = archive_write_set_format_by_name(cpio->archive, cpio->format); + if (r != ARCHIVE_OK) + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); + archive_write_set_bytes_per_block(cpio->archive, cpio->bytes_per_block); + cpio->linkresolver = archive_entry_linkresolver_new(); + archive_entry_linkresolver_set_strategy(cpio->linkresolver, + archive_format(cpio->archive)); + + /* + * The main loop: Copy each file into the output archive. + */ + r = archive_write_open_file(cpio->archive, cpio->filename); + if (r != ARCHIVE_OK) + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); + lr = lafe_line_reader("-", cpio->option_null); + while ((p = lafe_line_reader_next(lr)) != NULL) + file_to_archive(cpio, p); + lafe_line_reader_free(lr); + + /* + * The hardlink detection may have queued up a couple of entries + * that can now be flushed. + */ + entry = NULL; + archive_entry_linkify(cpio->linkresolver, &entry, &spare); + while (entry != NULL) { + entry_to_archive(cpio, entry); + archive_entry_free(entry); + entry = NULL; + archive_entry_linkify(cpio->linkresolver, &entry, &spare); + } + + r = archive_write_close(cpio->archive); + if (r != ARCHIVE_OK) + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); + + if (!cpio->quiet) { + int64_t blocks = + (archive_position_uncompressed(cpio->archive) + 511) + / 512; + fprintf(stderr, "%lu %s\n", (unsigned long)blocks, + blocks == 1 ? "block" : "blocks"); + } + archive_write_finish(cpio->archive); +} + +/* + * This is used by both out mode (to copy objects from disk into + * an archive) and pass mode (to copy objects from disk to + * an archive_write_disk "archive"). + */ +static int +file_to_archive(struct cpio *cpio, const char *srcpath) +{ + const char *destpath; + struct archive_entry *entry, *spare; + size_t len; + const char *p; + int r; + + /* + * Create an archive_entry describing the source file. + * + */ + entry = archive_entry_new(); + if (entry == NULL) + lafe_errc(1, 0, "Couldn't allocate entry"); + archive_entry_copy_sourcepath(entry, srcpath); + r = archive_read_disk_entry_from_file(cpio->archive_read_disk, + entry, -1, NULL); + if (r < ARCHIVE_FAILED) + lafe_errc(1, 0, "%s", + archive_error_string(cpio->archive_read_disk)); + if (r < ARCHIVE_OK) + lafe_warnc(0, "%s", + archive_error_string(cpio->archive_read_disk)); + if (r <= ARCHIVE_FAILED) { + cpio->return_value = 1; + return (r); + } + + if (cpio->uid_override >= 0) + archive_entry_set_uid(entry, cpio->uid_override); + if (cpio->gid_override >= 0) + archive_entry_set_gid(entry, cpio->gid_override); + + /* + * Generate a destination path for this entry. + * "destination path" is the name to which it will be copied in + * pass mode or the name that will go into the archive in + * output mode. + */ + destpath = srcpath; + if (cpio->destdir) { + len = strlen(cpio->destdir) + strlen(srcpath) + 8; + if (len >= cpio->pass_destpath_alloc) { + while (len >= cpio->pass_destpath_alloc) { + cpio->pass_destpath_alloc += 512; + cpio->pass_destpath_alloc *= 2; + } + free(cpio->pass_destpath); + cpio->pass_destpath = malloc(cpio->pass_destpath_alloc); + if (cpio->pass_destpath == NULL) + lafe_errc(1, ENOMEM, + "Can't allocate path buffer"); + } + strcpy(cpio->pass_destpath, cpio->destdir); + p = srcpath; + while (p[0] == '/') + ++p; + strcat(cpio->pass_destpath, p); + destpath = cpio->pass_destpath; + } + if (cpio->option_rename) + destpath = cpio_rename(destpath); + if (destpath == NULL) + return (0); + archive_entry_copy_pathname(entry, destpath); + + /* + * If we're trying to preserve hardlinks, match them here. + */ + spare = NULL; + if (cpio->linkresolver != NULL + && archive_entry_filetype(entry) != AE_IFDIR) { + archive_entry_linkify(cpio->linkresolver, &entry, &spare); + } + + if (entry != NULL) { + r = entry_to_archive(cpio, entry); + archive_entry_free(entry); + if (spare != NULL) { + if (r == 0) + r = entry_to_archive(cpio, spare); + archive_entry_free(spare); + } + } + return (r); +} + +static int +entry_to_archive(struct cpio *cpio, struct archive_entry *entry) +{ + const char *destpath = archive_entry_pathname(entry); + const char *srcpath = archive_entry_sourcepath(entry); + int fd = -1; + ssize_t bytes_read; + int r; + + /* Print out the destination name to the user. */ + if (cpio->verbose) + fprintf(stderr,"%s", destpath); + + /* + * Option_link only makes sense in pass mode and for + * regular files. Also note: if a link operation fails + * because of cross-device restrictions, we'll fall back + * to copy mode for that entry. + * + * TODO: Test other cpio implementations to see if they + * hard-link anything other than regular files here. + */ + if (cpio->option_link + && archive_entry_filetype(entry) == AE_IFREG) + { + struct archive_entry *t; + /* Save the original entry in case we need it later. */ + t = archive_entry_clone(entry); + if (t == NULL) + lafe_errc(1, ENOMEM, "Can't create link"); + /* Note: link(2) doesn't create parent directories, + * so we use archive_write_header() instead as a + * convenience. */ + archive_entry_set_hardlink(t, srcpath); + /* This is a straight link that carries no data. */ + archive_entry_set_size(t, 0); + r = archive_write_header(cpio->archive, t); + archive_entry_free(t); + if (r != ARCHIVE_OK) + lafe_warnc(archive_errno(cpio->archive), + "%s", archive_error_string(cpio->archive)); + if (r == ARCHIVE_FATAL) + exit(1); +#ifdef EXDEV + if (r != ARCHIVE_OK && archive_errno(cpio->archive) == EXDEV) { + /* Cross-device link: Just fall through and use + * the original entry to copy the file over. */ + lafe_warnc(0, "Copying file instead"); + } else +#endif + return (0); + } + + /* + * Make sure we can open the file (if necessary) before + * trying to write the header. + */ + if (archive_entry_filetype(entry) == AE_IFREG) { + if (archive_entry_size(entry) > 0) { + fd = open(srcpath, O_RDONLY | O_BINARY); + if (fd < 0) { + lafe_warnc(errno, + "%s: could not open file", srcpath); + goto cleanup; + } + } + } else { + archive_entry_set_size(entry, 0); + } + + r = archive_write_header(cpio->archive, entry); + + if (r != ARCHIVE_OK) + lafe_warnc(archive_errno(cpio->archive), + "%s: %s", + srcpath, + archive_error_string(cpio->archive)); + + if (r == ARCHIVE_FATAL) + exit(1); + + if (r >= ARCHIVE_WARN && fd >= 0) { + bytes_read = read(fd, cpio->buff, cpio->buff_size); + while (bytes_read > 0) { + r = archive_write_data(cpio->archive, + cpio->buff, bytes_read); + if (r < 0) + lafe_errc(1, archive_errno(cpio->archive), + "%s", archive_error_string(cpio->archive)); + if (r < bytes_read) { + lafe_warnc(0, + "Truncated write; file may have grown while being archived."); + } + bytes_read = read(fd, cpio->buff, cpio->buff_size); + } + } + + fd = restore_time(cpio, entry, srcpath, fd); + +cleanup: + if (cpio->verbose) + fprintf(stderr,"\n"); + if (fd >= 0) + close(fd); + return (0); +} + +static int +restore_time(struct cpio *cpio, struct archive_entry *entry, + const char *name, int fd) +{ +#ifndef HAVE_UTIMES + static int warned = 0; + + (void)cpio; /* UNUSED */ + (void)entry; /* UNUSED */ + (void)name; /* UNUSED */ + + if (!warned) + lafe_warnc(0, "Can't restore access times on this platform"); + warned = 1; + return (fd); +#else +#if defined(_WIN32) && !defined(__CYGWIN__) + struct __timeval times[2]; +#else + struct timeval times[2]; +#endif + + if (!cpio->option_atime_restore) + return (fd); + + times[1].tv_sec = archive_entry_mtime(entry); + times[1].tv_usec = archive_entry_mtime_nsec(entry) / 1000; + + times[0].tv_sec = archive_entry_atime(entry); + times[0].tv_usec = archive_entry_atime_nsec(entry) / 1000; + +#if defined(HAVE_FUTIMES) && !defined(__CYGWIN__) + if (fd >= 0 && futimes(fd, times) == 0) + return (fd); +#endif + /* + * Some platform cannot restore access times if the file descriptor + * is still opened. + */ + if (fd >= 0) { + close(fd); + fd = -1; + } + +#ifdef HAVE_LUTIMES + if (lutimes(name, times) != 0) +#else + if ((AE_IFLNK != archive_entry_filetype(entry)) + && utimes(name, times) != 0) +#endif + lafe_warnc(errno, "Can't update time for %s", name); +#endif + return (fd); +} + + +static void +mode_in(struct cpio *cpio) +{ + struct archive *a; + struct archive_entry *entry; + struct archive *ext; + const char *destpath; + int r; + + ext = archive_write_disk_new(); + if (ext == NULL) + lafe_errc(1, 0, "Couldn't allocate restore object"); + r = archive_write_disk_set_options(ext, cpio->extract_flags); + if (r != ARCHIVE_OK) + lafe_errc(1, 0, "%s", archive_error_string(ext)); + a = archive_read_new(); + if (a == NULL) + lafe_errc(1, 0, "Couldn't allocate archive object"); + archive_read_support_compression_all(a); + archive_read_support_format_all(a); + + if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) + lafe_errc(1, archive_errno(a), + "%s", archive_error_string(a)); + for (;;) { + r = archive_read_next_header(a, &entry); + if (r == ARCHIVE_EOF) + break; + if (r != ARCHIVE_OK) { + lafe_errc(1, archive_errno(a), + "%s", archive_error_string(a)); + } + if (lafe_excluded(cpio->matching, archive_entry_pathname(entry))) + continue; + if (cpio->option_rename) { + destpath = cpio_rename(archive_entry_pathname(entry)); + archive_entry_set_pathname(entry, destpath); + } else + destpath = archive_entry_pathname(entry); + if (destpath == NULL) + continue; + if (cpio->verbose) + fprintf(stdout, "%s\n", destpath); + if (cpio->uid_override >= 0) + archive_entry_set_uid(entry, cpio->uid_override); + if (cpio->gid_override >= 0) + archive_entry_set_gid(entry, cpio->gid_override); + r = archive_write_header(ext, entry); + if (r != ARCHIVE_OK) { + fprintf(stderr, "%s: %s\n", + archive_entry_pathname(entry), + archive_error_string(ext)); + } else if (archive_entry_size(entry) > 0) { + r = extract_data(a, ext); + if (r != ARCHIVE_OK) + cpio->return_value = 1; + } + } + r = archive_read_close(a); + if (r != ARCHIVE_OK) + lafe_errc(1, 0, "%s", archive_error_string(a)); + r = archive_write_close(ext); + if (r != ARCHIVE_OK) + lafe_errc(1, 0, "%s", archive_error_string(ext)); + if (!cpio->quiet) { + int64_t blocks = (archive_position_uncompressed(a) + 511) + / 512; + fprintf(stderr, "%lu %s\n", (unsigned long)blocks, + blocks == 1 ? "block" : "blocks"); + } + archive_read_finish(a); + archive_write_finish(ext); + exit(cpio->return_value); +} + +/* + * Exits if there's a fatal error. Returns ARCHIVE_OK + * if everything is kosher. + */ +static int +extract_data(struct archive *ar, struct archive *aw) +{ + int r; + size_t size; + const void *block; + off_t offset; + + for (;;) { + r = archive_read_data_block(ar, &block, &size, &offset); + if (r == ARCHIVE_EOF) + return (ARCHIVE_OK); + if (r != ARCHIVE_OK) { + lafe_warnc(archive_errno(ar), + "%s", archive_error_string(ar)); + exit(1); + } + r = archive_write_data_block(aw, block, size, offset); + if (r != ARCHIVE_OK) { + lafe_warnc(archive_errno(aw), + "%s", archive_error_string(aw)); + return (r); + } + } +} + +static void +mode_list(struct cpio *cpio) +{ + struct archive *a; + struct archive_entry *entry; + int r; + + a = archive_read_new(); + if (a == NULL) + lafe_errc(1, 0, "Couldn't allocate archive object"); + archive_read_support_compression_all(a); + archive_read_support_format_all(a); + + if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) + lafe_errc(1, archive_errno(a), + "%s", archive_error_string(a)); + for (;;) { + r = archive_read_next_header(a, &entry); + if (r == ARCHIVE_EOF) + break; + if (r != ARCHIVE_OK) { + lafe_errc(1, archive_errno(a), + "%s", archive_error_string(a)); + } + if (lafe_excluded(cpio->matching, archive_entry_pathname(entry))) + continue; + if (cpio->verbose) + list_item_verbose(cpio, entry); + else + fprintf(stdout, "%s\n", archive_entry_pathname(entry)); + } + r = archive_read_close(a); + if (r != ARCHIVE_OK) + lafe_errc(1, 0, "%s", archive_error_string(a)); + if (!cpio->quiet) { + int64_t blocks = (archive_position_uncompressed(a) + 511) + / 512; + fprintf(stderr, "%lu %s\n", (unsigned long)blocks, + blocks == 1 ? "block" : "blocks"); + } + archive_read_finish(a); + exit(0); +} + +/* + * Display information about the current file. + * + * The format here roughly duplicates the output of 'ls -l'. + * This is based on SUSv2, where 'tar tv' is documented as + * listing additional information in an "unspecified format," + * and 'pax -l' is documented as using the same format as 'ls -l'. + */ +static void +list_item_verbose(struct cpio *cpio, struct archive_entry *entry) +{ + char size[32]; + char date[32]; + char uids[16], gids[16]; + const char *uname, *gname; + FILE *out = stdout; + const char *fmt; + time_t mtime; + static time_t now; + + if (!now) + time(&now); + + if (cpio->option_numeric_uid_gid) { + /* Format numeric uid/gid for display. */ + strcpy(uids, cpio_i64toa(archive_entry_uid(entry))); + uname = uids; + strcpy(gids, cpio_i64toa(archive_entry_gid(entry))); + gname = gids; + } else { + /* Use uname if it's present, else lookup name from uid. */ + uname = archive_entry_uname(entry); + if (uname == NULL) + uname = lookup_uname(cpio, archive_entry_uid(entry)); + /* Use gname if it's present, else lookup name from gid. */ + gname = archive_entry_gname(entry); + if (gname == NULL) + gname = lookup_gname(cpio, archive_entry_gid(entry)); + } + + /* Print device number or file size. */ + if (archive_entry_filetype(entry) == AE_IFCHR + || archive_entry_filetype(entry) == AE_IFBLK) { + snprintf(size, sizeof(size), "%lu,%lu", + (unsigned long)archive_entry_rdevmajor(entry), + (unsigned long)archive_entry_rdevminor(entry)); + } else { + strcpy(size, cpio_i64toa(archive_entry_size(entry))); + } + + /* Format the time using 'ls -l' conventions. */ + mtime = archive_entry_mtime(entry); +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Windows' strftime function does not support %e format. */ + if (mtime - now > 365*86400/2 + || mtime - now < -365*86400/2) + fmt = cpio->day_first ? "%d %b %Y" : "%b %d %Y"; + else + fmt = cpio->day_first ? "%d %b %H:%M" : "%b %d %H:%M"; +#else + if (abs(mtime - now) > (365/2)*86400) + fmt = cpio->day_first ? "%e %b %Y" : "%b %e %Y"; + else + fmt = cpio->day_first ? "%e %b %H:%M" : "%b %e %H:%M"; +#endif + strftime(date, sizeof(date), fmt, localtime(&mtime)); + + fprintf(out, "%s%3d %-8s %-8s %8s %12s %s", + archive_entry_strmode(entry), + archive_entry_nlink(entry), + uname, gname, size, date, + archive_entry_pathname(entry)); + + /* Extra information for links. */ + if (archive_entry_hardlink(entry)) /* Hard link */ + fprintf(out, " link to %s", archive_entry_hardlink(entry)); + else if (archive_entry_symlink(entry)) /* Symbolic link */ + fprintf(out, " -> %s", archive_entry_symlink(entry)); + fprintf(out, "\n"); +} + +static void +mode_pass(struct cpio *cpio, const char *destdir) +{ + struct lafe_line_reader *lr; + const char *p; + int r; + + /* Ensure target dir has a trailing '/' to simplify path surgery. */ + cpio->destdir = malloc(strlen(destdir) + 8); + strcpy(cpio->destdir, destdir); + if (destdir[strlen(destdir) - 1] != '/') + strcat(cpio->destdir, "/"); + + cpio->archive = archive_write_disk_new(); + if (cpio->archive == NULL) + lafe_errc(1, 0, "Failed to allocate archive object"); + r = archive_write_disk_set_options(cpio->archive, cpio->extract_flags); + if (r != ARCHIVE_OK) + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); + cpio->linkresolver = archive_entry_linkresolver_new(); + archive_write_disk_set_standard_lookup(cpio->archive); + + cpio->archive_read_disk = archive_read_disk_new(); + if (cpio->archive_read_disk == NULL) + lafe_errc(1, 0, "Failed to allocate archive object"); + if (cpio->option_follow_links) + archive_read_disk_set_symlink_logical(cpio->archive_read_disk); + else + archive_read_disk_set_symlink_physical(cpio->archive_read_disk); + archive_read_disk_set_standard_lookup(cpio->archive_read_disk); + + lr = lafe_line_reader("-", cpio->option_null); + while ((p = lafe_line_reader_next(lr)) != NULL) + file_to_archive(cpio, p); + lafe_line_reader_free(lr); + + archive_entry_linkresolver_free(cpio->linkresolver); + r = archive_write_close(cpio->archive); + if (r != ARCHIVE_OK) + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); + + if (!cpio->quiet) { + int64_t blocks = + (archive_position_uncompressed(cpio->archive) + 511) + / 512; + fprintf(stderr, "%lu %s\n", (unsigned long)blocks, + blocks == 1 ? "block" : "blocks"); + } + + archive_write_finish(cpio->archive); +} + +/* + * Prompt for a new name for this entry. Returns a pointer to the + * new name or NULL if the entry should not be copied. This + * implements the semantics defined in POSIX.1-1996, which specifies + * that an input of '.' means the name should be unchanged. GNU cpio + * treats '.' as a literal new name. + */ +static const char * +cpio_rename(const char *name) +{ + static char buff[1024]; + FILE *t; + char *p, *ret; + + t = fopen("/dev/tty", "r+"); + if (t == NULL) + return (name); + fprintf(t, "%s (Enter/./(new name))? ", name); + fflush(t); + + p = fgets(buff, sizeof(buff), t); + fclose(t); + if (p == NULL) + /* End-of-file is a blank line. */ + return (NULL); + + while (*p == ' ' || *p == '\t') + ++p; + if (*p == '\n' || *p == '\0') + /* Empty line. */ + return (NULL); + if (*p == '.' && p[1] == '\n') + /* Single period preserves original name. */ + return (name); + ret = p; + /* Trim the final newline. */ + while (*p != '\0' && *p != '\n') + ++p; + /* Overwrite the final \n with a null character. */ + *p = '\0'; + return (ret); +} + +static void +free_cache(struct name_cache *cache) +{ + size_t i; + + if (cache != NULL) { + for (i = 0; i < cache->size; i++) + free(cache->cache[i].name); + free(cache); + } +} + +/* + * Lookup uname/gname from uid/gid, return NULL if no match. + */ +static const char * +lookup_name(struct cpio *cpio, struct name_cache **name_cache_variable, + int (*lookup_fn)(struct cpio *, const char **, id_t), id_t id) +{ + char asnum[16]; + struct name_cache *cache; + const char *name; + int slot; + + + if (*name_cache_variable == NULL) { + *name_cache_variable = malloc(sizeof(struct name_cache)); + if (*name_cache_variable == NULL) + lafe_errc(1, ENOMEM, "No more memory"); + memset(*name_cache_variable, 0, sizeof(struct name_cache)); + (*name_cache_variable)->size = name_cache_size; + } + + cache = *name_cache_variable; + cache->probes++; + + slot = id % cache->size; + if (cache->cache[slot].name != NULL) { + if (cache->cache[slot].id == id) { + cache->hits++; + return (cache->cache[slot].name); + } + free(cache->cache[slot].name); + cache->cache[slot].name = NULL; + } + + if (lookup_fn(cpio, &name, id) == 0) { + if (name == NULL || name[0] == '\0') { + /* If lookup failed, format it as a number. */ + snprintf(asnum, sizeof(asnum), "%u", (unsigned)id); + name = asnum; + } + cache->cache[slot].name = strdup(name); + if (cache->cache[slot].name != NULL) { + cache->cache[slot].id = id; + return (cache->cache[slot].name); + } + /* + * Conveniently, NULL marks an empty slot, so + * if the strdup() fails, we've just failed to + * cache it. No recovery necessary. + */ + } + return (NULL); +} + +static const char * +lookup_uname(struct cpio *cpio, uid_t uid) +{ + return (lookup_name(cpio, &cpio->uname_cache, + &lookup_uname_helper, (id_t)uid)); +} + +static int +lookup_uname_helper(struct cpio *cpio, const char **name, id_t id) +{ + struct passwd *pwent; + + (void)cpio; /* UNUSED */ + + errno = 0; + pwent = getpwuid((uid_t)id); + if (pwent == NULL) { + *name = NULL; + if (errno != 0 && errno != ENOENT) + lafe_warnc(errno, "getpwuid(%d) failed", id); + return (errno); + } + + *name = pwent->pw_name; + return (0); +} + +static const char * +lookup_gname(struct cpio *cpio, gid_t gid) +{ + return (lookup_name(cpio, &cpio->gname_cache, + &lookup_gname_helper, (id_t)gid)); +} + +static int +lookup_gname_helper(struct cpio *cpio, const char **name, id_t id) +{ + struct group *grent; + + (void)cpio; /* UNUSED */ + + errno = 0; + grent = getgrgid((gid_t)id); + if (grent == NULL) { + *name = NULL; + if (errno != 0) + lafe_warnc(errno, "getgrgid(%d) failed", id); + return (errno); + } + + *name = grent->gr_name; + return (0); +} + +/* + * It would be nice to just use printf() for formatting large numbers, + * but the compatibility problems are a big headache. Hence the + * following simple utility function. + */ +const char * +cpio_i64toa(int64_t n0) +{ + // 2^64 =~ 1.8 * 10^19, so 20 decimal digits suffice. + // We also need 1 byte for '-' and 1 for '\0'. + static char buff[22]; + int64_t n = n0 < 0 ? -n0 : n0; + char *p = buff + sizeof(buff); + + *--p = '\0'; + do { + *--p = '0' + (int)(n % 10); + n /= 10; + } while (n > 0); + if (n0 < 0) + *--p = '-'; + return p; +} diff --git a/external/bsd/libarchive/dist/cpio/cpio.h b/external/bsd/libarchive/dist/cpio/cpio.h new file mode 100644 index 000000000..3eed83494 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/cpio.h @@ -0,0 +1,109 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/usr.bin/cpio/cpio.h,v 1.7 2008/12/06 07:30:40 kientzle Exp $ + */ + +#ifndef CPIO_H_INCLUDED +#define CPIO_H_INCLUDED + +#include "cpio_platform.h" +#include + +#include "matching.h" + +/* + * The internal state for the "cpio" program. + * + * Keeping all of the state in a structure like this simplifies memory + * leak testing (at exit, anything left on the heap is suspect). A + * pointer to this structure is passed to most cpio internal + * functions. + */ +struct cpio { + /* Option parsing */ + const char *optarg; + + /* Options */ + const char *filename; + char mode; /* -i -o -p */ + char compress; /* -j, -y, or -z */ + const char *format; /* -H format */ + int bytes_per_block; /* -b block_size */ + int verbose; /* -v */ + int quiet; /* --quiet */ + int extract_flags; /* Flags for extract operation */ + char symlink_mode; /* H or L, per BSD conventions */ + const char *compress_program; + int option_append; /* -A, only relevant for -o */ + int option_atime_restore; /* -a */ + int option_follow_links; /* -L */ + int option_link; /* -l */ + int option_list; /* -t */ + char option_null; /* --null */ + int option_numeric_uid_gid; /* -n */ + int option_rename; /* -r */ + char *destdir; + size_t pass_destpath_alloc; + char *pass_destpath; + int uid_override; + int gid_override; + int day_first; /* true if locale prefers day/mon */ + + /* If >= 0, then close this when done. */ + int fd; + + /* Miscellaneous state information */ + struct archive *archive; + struct archive *archive_read_disk; + int argc; + char **argv; + int return_value; /* Value returned by main() */ + struct archive_entry_linkresolver *linkresolver; + + struct name_cache *uname_cache; + struct name_cache *gname_cache; + + /* Work data. */ + struct lafe_matching *matching; + char *buff; + size_t buff_size; +}; + +const char *owner_parse(const char *, int *, int *); + + +/* Fake short equivalents for long options that otherwise lack them. */ +enum { + OPTION_INSECURE = 1, + OPTION_LZMA, + OPTION_NO_PRESERVE_OWNER, + OPTION_PRESERVE_OWNER, + OPTION_QUIET, + OPTION_VERSION +}; + +int cpio_getopt(struct cpio *cpio); + +#endif diff --git a/external/bsd/libarchive/dist/cpio/cpio_platform.h b/external/bsd/libarchive/dist/cpio/cpio_platform.h new file mode 100644 index 000000000..31d9a738f --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/cpio_platform.h @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/usr.bin/cpio/cpio_platform.h,v 1.2 2008/12/06 07:15:42 kientzle Exp $ + */ + +/* + * This header is the first thing included in any of the cpio + * source files. As far as possible, platform-specific issues should + * be dealt with here and not within individual source files. + */ + +#ifndef CPIO_PLATFORM_H_INCLUDED +#define CPIO_PLATFORM_H_INCLUDED + +#if defined(PLATFORM_CONFIG_H) +/* Use hand-built config.h in environments that need it. */ +#include PLATFORM_CONFIG_H +#else +/* Read config.h or die trying. */ +#include "config.h" +#endif + +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID +#define __FBSDID(a) struct _undefined_hack +#endif + +#ifdef HAVE_LIBARCHIVE +/* If we're using the platform libarchive, include system headers. */ +#include +#include +#else +/* Otherwise, include user headers. */ +#include "archive.h" +#include "archive_entry.h" +#endif + +/* How to mark functions that don't return. */ +#if defined(__GNUC__) && (__GNUC__ > 2 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_DEAD __attribute__((__noreturn__)) +#else +#define __LA_DEAD +#endif + +#if defined(_WIN32) && !defined(__CYGWIN__) +#include "cpio_windows.h" +#endif + +#endif /* !CPIO_PLATFORM_H_INCLUDED */ diff --git a/external/bsd/libarchive/dist/cpio/cpio_windows.c b/external/bsd/libarchive/dist/cpio/cpio_windows.c new file mode 100644 index 000000000..420e01d5e --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/cpio_windows.c @@ -0,0 +1,338 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#if defined(_WIN32) && !defined(__CYGWIN__) + +#include "cpio_platform.h" +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_UTIME_H +#include +#endif +#include +#include +#include +#include +#include +#include + +#include "cpio.h" +#include "err.h" + +#define EPOC_TIME (116444736000000000ULL) + +static void cpio_dosmaperr(unsigned long); + +/* + * Prepend "\\?\" to the path name and convert it to unicode to permit + * an extended-length path for a maximum total path length of 32767 + * characters. + * see also http://msdn.microsoft.com/en-us/library/aa365247.aspx + */ +static wchar_t * +permissive_name(const char *name) +{ + wchar_t *wn, *wnp; + wchar_t *ws, *wsp; + DWORD l, len, slen, alloclen; + int unc; + + len = (DWORD)strlen(name); + wn = malloc((len + 1) * sizeof(wchar_t)); + if (wn == NULL) + return (NULL); + l = MultiByteToWideChar(CP_ACP, 0, name, len, wn, len); + if (l == 0) { + free(wn); + return (NULL); + } + wn[l] = L'\0'; + + /* Get a full path names */ + l = GetFullPathNameW(wn, 0, NULL, NULL); + if (l == 0) { + free(wn); + return (NULL); + } + wnp = malloc(l * sizeof(wchar_t)); + if (wnp == NULL) { + free(wn); + return (NULL); + } + len = GetFullPathNameW(wn, l, wnp, NULL); + free(wn); + wn = wnp; + + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'?' && wnp[3] == L'\\') + /* We have already permissive names. */ + return (wn); + + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'.' && wnp[3] == L'\\') { + /* Device names */ + if (((wnp[4] >= L'a' && wnp[4] <= L'z') || + (wnp[4] >= L'A' && wnp[4] <= L'Z')) && + wnp[5] == L':' && wnp[6] == L'\\') + wnp[2] = L'?';/* Not device names. */ + return (wn); + } + + unc = 0; + if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') { + wchar_t *p = &wnp[2]; + + /* Skip server-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\') { + wchar_t *rp = ++p; + /* Skip share-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\' && p != rp) { + /* Now, match patterns such as + * "\\server-name\share-name\" */ + wnp += 2; + len -= 2; + unc = 1; + } + } + } + + alloclen = slen = 4 + (unc * 4) + len + 1; + ws = wsp = malloc(slen * sizeof(wchar_t)); + if (ws == NULL) { + free(wn); + return (NULL); + } + /* prepend "\\?\" */ + wcsncpy(wsp, L"\\\\?\\", 4); + wsp += 4; + slen -= 4; + if (unc) { + /* append "UNC\" ---> "\\?\UNC\" */ + wcsncpy(wsp, L"UNC\\", 4); + wsp += 4; + slen -= 4; + } + wcsncpy(wsp, wnp, slen); + free(wn); + ws[alloclen - 1] = L'\0'; + return (ws); +} + +static HANDLE +cpio_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) +{ + wchar_t *wpath; + HANDLE handle; + + handle = CreateFileA(path, dwDesiredAccess, dwShareMode, + lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, + hTemplateFile); + if (handle != INVALID_HANDLE_VALUE) + return (handle); + if (GetLastError() != ERROR_PATH_NOT_FOUND) + return (handle); + wpath = permissive_name(path); + if (wpath == NULL) + return (handle); + handle = CreateFileW(wpath, dwDesiredAccess, dwShareMode, + lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, + hTemplateFile); + free(wpath); + return (handle); +} + +#define WINTIME(sec, usec) ((Int32x32To64(sec, 10000000) + EPOC_TIME) + (usec * 10)) +static int +__hutimes(HANDLE handle, const struct __timeval *times) +{ + ULARGE_INTEGER wintm; + FILETIME fatime, fmtime; + + wintm.QuadPart = WINTIME(times[0].tv_sec, times[0].tv_usec); + fatime.dwLowDateTime = wintm.LowPart; + fatime.dwHighDateTime = wintm.HighPart; + wintm.QuadPart = WINTIME(times[1].tv_sec, times[1].tv_usec); + fmtime.dwLowDateTime = wintm.LowPart; + fmtime.dwHighDateTime = wintm.HighPart; + if (SetFileTime(handle, NULL, &fatime, &fmtime) == 0) { + errno = EINVAL; + return (-1); + } + return (0); +} + +int +futimes(int fd, const struct __timeval *times) +{ + + return (__hutimes((HANDLE)_get_osfhandle(fd), times)); +} + +int +utimes(const char *name, const struct __timeval *times) +{ + int ret; + HANDLE handle; + + handle = cpio_CreateFile(name, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (handle == INVALID_HANDLE_VALUE) { + cpio_dosmaperr(GetLastError()); + return (-1); + } + ret = __hutimes(handle, times); + CloseHandle(handle); + return (ret); +} + +/* + * The following function was modified from PostgreSQL sources and is + * subject to the copyright below. + */ +/*------------------------------------------------------------------------- + * + * win32error.c + * Map win32 error codes to errno values + * + * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +/* +PostgreSQL Database Management System +(formerly known as Postgres, then as Postgres95) + +Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group + +Portions Copyright (c) 1994, The Regents of the University of California + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose, without fee, and without a written agreement +is hereby granted, provided that the above copyright notice and this +paragraph and the following two paragraphs appear in all copies. + +IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR +DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING +LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO +PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. +*/ + +static const struct { + DWORD winerr; + int doserr; +} doserrors[] = +{ + { ERROR_INVALID_FUNCTION, EINVAL }, + { ERROR_FILE_NOT_FOUND, ENOENT }, + { ERROR_PATH_NOT_FOUND, ENOENT }, + { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, + { ERROR_ACCESS_DENIED, EACCES }, + { ERROR_INVALID_HANDLE, EBADF }, + { ERROR_ARENA_TRASHED, ENOMEM }, + { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, + { ERROR_INVALID_BLOCK, ENOMEM }, + { ERROR_BAD_ENVIRONMENT, E2BIG }, + { ERROR_BAD_FORMAT, ENOEXEC }, + { ERROR_INVALID_ACCESS, EINVAL }, + { ERROR_INVALID_DATA, EINVAL }, + { ERROR_INVALID_DRIVE, ENOENT }, + { ERROR_CURRENT_DIRECTORY, EACCES }, + { ERROR_NOT_SAME_DEVICE, EXDEV }, + { ERROR_NO_MORE_FILES, ENOENT }, + { ERROR_LOCK_VIOLATION, EACCES }, + { ERROR_SHARING_VIOLATION, EACCES }, + { ERROR_BAD_NETPATH, ENOENT }, + { ERROR_NETWORK_ACCESS_DENIED, EACCES }, + { ERROR_BAD_NET_NAME, ENOENT }, + { ERROR_FILE_EXISTS, EEXIST }, + { ERROR_CANNOT_MAKE, EACCES }, + { ERROR_FAIL_I24, EACCES }, + { ERROR_INVALID_PARAMETER, EINVAL }, + { ERROR_NO_PROC_SLOTS, EAGAIN }, + { ERROR_DRIVE_LOCKED, EACCES }, + { ERROR_BROKEN_PIPE, EPIPE }, + { ERROR_DISK_FULL, ENOSPC }, + { ERROR_INVALID_TARGET_HANDLE, EBADF }, + { ERROR_INVALID_HANDLE, EINVAL }, + { ERROR_WAIT_NO_CHILDREN, ECHILD }, + { ERROR_CHILD_NOT_COMPLETE, ECHILD }, + { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, + { ERROR_NEGATIVE_SEEK, EINVAL }, + { ERROR_SEEK_ON_DEVICE, EACCES }, + { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, + { ERROR_NOT_LOCKED, EACCES }, + { ERROR_BAD_PATHNAME, ENOENT }, + { ERROR_MAX_THRDS_REACHED, EAGAIN }, + { ERROR_LOCK_FAILED, EACCES }, + { ERROR_ALREADY_EXISTS, EEXIST }, + { ERROR_FILENAME_EXCED_RANGE, ENOENT }, + { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, + { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } +}; + +static void +cpio_dosmaperr(unsigned long e) +{ + int i; + + if (e == 0) { + errno = 0; + return; + } + + for (i = 0; i < sizeof(doserrors); i++) { + if (doserrors[i].winerr == e) { + errno = doserrors[i].doserr; + return; + } + } + + /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */ + errno = EINVAL; + return; +} +#endif diff --git a/external/bsd/libarchive/dist/cpio/cpio_windows.h b/external/bsd/libarchive/dist/cpio/cpio_windows.h new file mode 100644 index 000000000..105bf6999 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/cpio_windows.h @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef CPIO_WINDOWS_H +#define CPIO_WINDOWS_H 1 + +#include +#include + +#define getgrgid(id) NULL +#define getgrnam(name) NULL +#define getpwnam(name) NULL +#define getpwuid(id) NULL + +#ifdef _MSC_VER +#define snprintf sprintf_s +#define strdup _strdup +#define open _open +#define read _read +#define close _close +#endif + +struct passwd { + char *pw_name; + uid_t pw_uid; + gid_t pw_gid; +}; + +struct group { + char *gr_name; + gid_t gr_gid; +}; + +struct _timeval64i32 { + time_t tv_sec; + long tv_usec; +}; +#define __timeval _timeval64i32 + +extern int futimes(int fd, const struct __timeval *times); +#ifndef HAVE_FUTIMES +#define HAVE_FUTIMES 1 +#endif +extern int utimes(const char *name, const struct __timeval *times); +#ifndef HAVE_UTIMES +#define HAVE_UTIMES 1 +#endif + +#endif /* CPIO_WINDOWS_H */ diff --git a/external/bsd/libarchive/dist/cpio/test/CMakeLists.txt b/external/bsd/libarchive/dist/cpio/test/CMakeLists.txt new file mode 100644 index 000000000..a822bcdfb --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/CMakeLists.txt @@ -0,0 +1,79 @@ +############################################ +# +# How to build bsdcpio_test +# +############################################ +IF(ENABLE_CPIO AND ENABLE_TEST) + SET(bsdcpio_test_SOURCES + ../cmdline.c + ../../libarchive_fe/err.c + ../../libarchive_fe/pathmatch.c + main.c + test.h + test_0.c + test_basic.c + test_cmdline.c + test_format_newc.c + test_gcpio_compat.c + test_option_B_upper.c + test_option_C_upper.c + test_option_J_upper.c + test_option_L_upper.c + test_option_Z_upper.c + test_option_a.c + test_option_c.c + test_option_d.c + test_option_f.c + test_option_help.c + test_option_l.c + test_option_lzma.c + test_option_m.c + test_option_t.c + test_option_u.c + test_option_version.c + test_option_y.c + test_option_z.c + test_owner_parse.c + test_passthrough_dotdot.c + test_passthrough_reverse.c + test_pathmatch.c + ) + IF(WIN32 AND NOT CYGWIN) + LIST(APPEND bsdcpio_test_SOURCES ../cpio_windows.h) + ENDIF(WIN32 AND NOT CYGWIN) + + # + # Register target + # + ADD_EXECUTABLE(bsdcpio_test ${bsdcpio_test_SOURCES}) + SET_PROPERTY(TARGET bsdcpio_test PROPERTY COMPILE_DEFINITIONS LIST_H) + + # + # Generate list.h by grepping DEFINE_TEST() lines out of the C sources. + # + GENERATE_LIST_H(${CMAKE_CURRENT_BINARY_DIR}/list.h + ${CMAKE_CURRENT_LIST_FILE} ${bsdcpio_test_SOURCES}) + SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_BINARY_DIR}) + + # list.h has a line DEFINE_TEST(testname) for every + # test. We can use that to define the tests for cmake by + # defining a DEFINE_TEST macro and reading list.h in. + MACRO (DEFINE_TEST _testname) + ADD_TEST_28( + NAME bsdcpio_${_testname} + COMMAND bsdcpio_test -vv + -p $ + -r ${CMAKE_CURRENT_SOURCE_DIR} + ${_testname}) + ENDMACRO (DEFINE_TEST _testname) + + INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h) + + # Experimental new test handling + ADD_CUSTOM_TARGET(run_bsdcpio_test + COMMAND bsdcpio_test -p ${BSDCPIO} -r ${CMAKE_CURRENT_SOURCE_DIR}) + ADD_DEPENDENCIES(run_bsdcpio_test bsdcpio) + ADD_DEPENDENCIES(run_all_tests run_bsdcpio_test) +ENDIF(ENABLE_CPIO AND ENABLE_TEST) + diff --git a/external/bsd/libarchive/dist/cpio/test/list.h b/external/bsd/libarchive/dist/cpio/test/list.h new file mode 100644 index 000000000..55968c363 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/list.h @@ -0,0 +1,27 @@ +DEFINE_TEST(test_0) +DEFINE_TEST(test_basic) +DEFINE_TEST(test_cmdline) +DEFINE_TEST(test_format_newc) +DEFINE_TEST(test_gcpio_compat) +DEFINE_TEST(test_option_B_upper) +DEFINE_TEST(test_option_C_upper) +DEFINE_TEST(test_option_J_upper) +DEFINE_TEST(test_option_L_upper) +DEFINE_TEST(test_option_Z_upper) +DEFINE_TEST(test_option_a) +DEFINE_TEST(test_option_c) +DEFINE_TEST(test_option_d) +DEFINE_TEST(test_option_f) +DEFINE_TEST(test_option_help) +DEFINE_TEST(test_option_l) +DEFINE_TEST(test_option_lzma) +DEFINE_TEST(test_option_m) +DEFINE_TEST(test_option_t) +DEFINE_TEST(test_option_u) +DEFINE_TEST(test_option_version) +DEFINE_TEST(test_option_y) +DEFINE_TEST(test_option_z) +DEFINE_TEST(test_owner_parse) +DEFINE_TEST(test_passthrough_dotdot) +DEFINE_TEST(test_passthrough_reverse) +DEFINE_TEST(test_pathmatch) diff --git a/external/bsd/libarchive/dist/cpio/test/main.c b/external/bsd/libarchive/dist/cpio/test/main.c new file mode 100644 index 000000000..90336a9e6 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/main.c @@ -0,0 +1,2140 @@ +/* + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +#include +#include +#include +#include + +/* + * This same file is used pretty much verbatim for all test harnesses. + * + * The next few lines are the only differences. + * TODO: Move this into a separate configuration header, have all test + * suites share one copy of this file. + */ +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/main.c,v 1.3 2008/08/24 04:58:22 kientzle Exp $"); +#define KNOWNREF "test_option_f.cpio.uu" +#define ENVBASE "BSDCPIO" /* Prefix for environment variables. */ +#define PROGRAM "bsdcpio" /* Name of program being tested. */ +#undef LIBRARY /* Not testing a library. */ +#undef EXTRA_DUMP /* How to dump extra data */ +/* How to generate extra version info. */ +#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "") + +/* + * + * Windows support routines + * + * Note: Configuration is a tricky issue. Using HAVE_* feature macros + * in the test harness is dangerous because they cover up + * configuration errors. The classic example of this is omitting a + * configure check. If libarchive and libarchive_test both look for + * the same feature macro, such errors are hard to detect. Platform + * macros (e.g., _WIN32 or __GNUC__) are a little better, but can + * easily lead to very messy code. It's best to limit yourself + * to only the most generic programming techniques in the test harness + * and thus avoid conditionals altogether. Where that's not possible, + * try to minimize conditionals by grouping platform-specific tests in + * one place (e.g., test_acl_freebsd) or by adding new assert() + * functions (e.g., assertMakeHardlink()) to cover up platform + * differences. Platform-specific coding in libarchive_test is often + * a symptom that some capability is missing from libarchive itself. + */ +#if defined(_WIN32) && !defined(__CYGWIN__) +#include +#include +#ifndef F_OK +#define F_OK (0) +#endif +#ifndef S_ISDIR +#define S_ISDIR(m) ((m) & _S_IFDIR) +#endif +#ifndef S_ISREG +#define S_ISREG(m) ((m) & _S_IFREG) +#endif +#if !defined(__BORLANDC__) +#define access _access +#define chdir _chdir +#endif +#ifndef fileno +#define fileno _fileno +#endif +/*#define fstat _fstat64*/ +#if !defined(__BORLANDC__) +#define getcwd _getcwd +#endif +#define lstat stat +/*#define lstat _stat64*/ +/*#define stat _stat64*/ +#define rmdir _rmdir +#if !defined(__BORLANDC__) +#define strdup _strdup +#define umask _umask +#endif +#define int64_t __int64 +#endif + +#if defined(HAVE__CrtSetReportMode) +# include +#endif + +#if defined(_WIN32) && !defined(__CYGWIN__) +void *GetFunctionKernel32(const char *name) +{ + static HINSTANCE lib; + static int set; + if (!set) { + set = 1; + lib = LoadLibrary("kernel32.dll"); + } + if (lib == NULL) { + fprintf(stderr, "Can't load kernel32.dll?!\n"); + exit(1); + } + return (void *)GetProcAddress(lib, name); +} + +static int +my_CreateSymbolicLinkA(const char *linkname, const char *target, int flags) +{ + static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD); + static int set; + if (!set) { + set = 1; + f = GetFunctionKernel32("CreateSymbolicLinkA"); + } + return f == NULL ? 0 : (*f)(linkname, target, flags); +} + +static int +my_CreateHardLinkA(const char *linkname, const char *target) +{ + static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); + static int set; + if (!set) { + set = 1; + f = GetFunctionKernel32("CreateHardLinkA"); + } + return f == NULL ? 0 : (*f)(linkname, target, NULL); +} + +int +my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) +{ + HANDLE h; + int r; + + memset(bhfi, 0, sizeof(*bhfi)); + h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) + return (0); + r = GetFileInformationByHandle(h, bhfi); + CloseHandle(h); + return (r); +} +#endif + +#if defined(HAVE__CrtSetReportMode) +static void +invalid_parameter_handler(const wchar_t * expression, + const wchar_t * function, const wchar_t * file, + unsigned int line, uintptr_t pReserved) +{ + /* nop */ +} +#endif + +/* + * + * OPTIONS FLAGS + * + */ + +/* Enable core dump on failure. */ +static int dump_on_failure = 0; +/* Default is to remove temp dirs and log data for successful tests. */ +static int keep_temp_files = 0; +/* Default is to just report pass/fail for each test. */ +static int verbosity = 0; +#define VERBOSITY_SUMMARY_ONLY -1 /* -q */ +#define VERBOSITY_PASSFAIL 0 /* Default */ +#define VERBOSITY_LIGHT_REPORT 1 /* -v */ +#define VERBOSITY_FULL 2 /* -vv */ +/* A few places generate even more output for verbosity > VERBOSITY_FULL, + * mostly for debugging the test harness itself. */ +/* Cumulative count of assertion failures. */ +static int failures = 0; +/* Cumulative count of reported skips. */ +static int skips = 0; +/* Cumulative count of assertions checked. */ +static int assertions = 0; + +/* Directory where uuencoded reference files can be found. */ +static const char *refdir; + +/* + * Report log information selectively to console and/or disk log. + */ +static int log_console = 0; +static FILE *logfile; +static void +vlogprintf(const char *fmt, va_list ap) +{ +#ifdef va_copy + va_list lfap; + va_copy(lfap, ap); +#endif + if (log_console) + vfprintf(stdout, fmt, ap); + if (logfile != NULL) +#ifdef va_copy + vfprintf(logfile, fmt, lfap); + va_end(lfap); +#else + vfprintf(logfile, fmt, ap); +#endif +} + +static void +logprintf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vlogprintf(fmt, ap); + va_end(ap); +} + +/* Set up a message to display only if next assertion fails. */ +static char msgbuff[4096]; +static const char *msg, *nextmsg; +void +failure(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vsprintf(msgbuff, fmt, ap); + va_end(ap); + nextmsg = msgbuff; +} + +/* + * Copy arguments into file-local variables. + * This was added to permit vararg assert() functions without needing + * variadic wrapper macros. Turns out that the vararg capability is almost + * never used, so almost all of the vararg assertions can be simplified + * by removing the vararg capability and reworking the wrapper macro to + * pass __FILE__, __LINE__ directly into the function instead of using + * this hook. I suspect this machinery is used so rarely that we + * would be better off just removing it entirely. That would simplify + * the code here noticably. + */ +static const char *test_filename; +static int test_line; +static void *test_extra; +void assertion_setup(const char *filename, int line) +{ + test_filename = filename; + test_line = line; +} + +/* Called at the beginning of each assert() function. */ +static void +assertion_count(const char *file, int line) +{ + (void)file; /* UNUSED */ + (void)line; /* UNUSED */ + ++assertions; + /* Proper handling of "failure()" message. */ + msg = nextmsg; + nextmsg = NULL; + /* Uncomment to print file:line after every assertion. + * Verbose, but occasionally useful in tracking down crashes. */ + /* printf("Checked %s:%d\n", file, line); */ +} + +/* + * For each test source file, we remember how many times each + * assertion was reported. Cleared before each new test, + * used by test_summarize(). + */ +static struct line { + int count; + int skip; +} failed_lines[10000]; + +/* Count this failure, setup up log destination and handle initial report. */ +static void +failure_start(const char *filename, int line, const char *fmt, ...) +{ + va_list ap; + + /* Record another failure for this line. */ + ++failures; + /* test_filename = filename; */ + failed_lines[line].count++; + + /* Determine whether to log header to console. */ + switch (verbosity) { + case VERBOSITY_FULL: + log_console = 1; + break; + case VERBOSITY_LIGHT_REPORT: + log_console = (failed_lines[line].count < 2); + break; + default: + log_console = 0; + } + + /* Log file:line header for this failure */ + va_start(ap, fmt); +#if _MSC_VER + logprintf("%s(%d): ", filename, line); +#else + logprintf("%s:%d: ", filename, line); +#endif + vlogprintf(fmt, ap); + va_end(ap); + logprintf("\n"); + + if (msg != NULL && msg[0] != '\0') { + logprintf(" Description: %s\n", msg); + msg = NULL; + } + + /* Determine whether to log details to console. */ + if (verbosity == VERBOSITY_LIGHT_REPORT) + log_console = 0; +} + +/* Complete reporting of failed tests. */ +/* + * The 'extra' hook here is used by libarchive to include libarchive + * error messages with assertion failures. It could also be used + * to add strerror() output, for example. Just define the EXTRA_DUMP() + * macro appropriately. + */ +static void +failure_finish(void *extra) +{ + (void)extra; /* UNUSED (maybe) */ +#ifdef EXTRA_DUMP + if (extra != NULL) + logprintf(" detail: %s\n", EXTRA_DUMP(extra)); +#endif + + if (dump_on_failure) { + fprintf(stderr, + " *** forcing core dump so failure can be debugged ***\n"); + *(char *)(NULL) = 0; + exit(1); + } +} + +/* Inform user that we're skipping some checks. */ +void +test_skipping(const char *fmt, ...) +{ + char buff[1024]; + va_list ap; + + va_start(ap, fmt); + vsprintf(buff, fmt, ap); + va_end(ap); + /* failure_start() isn't quite right, but is awfully convenient. */ + failure_start(test_filename, test_line, "SKIPPING: %s", buff); + --failures; /* Undo failures++ in failure_start() */ + /* Don't failure_finish() here. */ + /* Mark as skip, so doesn't count as failed test. */ + failed_lines[test_line].skip = 1; + ++skips; +} + +/* + * + * ASSERTIONS + * + */ + +/* Generic assert() just displays the failed condition. */ +int +assertion_assert(const char *file, int line, int value, + const char *condition, void *extra) +{ + assertion_count(file, line); + if (!value) { + failure_start(file, line, "Assertion failed: %s", condition); + failure_finish(extra); + } + return (value); +} + +/* chdir() and report any errors */ +int +assertion_chdir(const char *file, int line, const char *pathname) +{ + assertion_count(file, line); + if (chdir(pathname) == 0) + return (1); + failure_start(file, line, "chdir(\"%s\")", pathname); + failure_finish(NULL); + return (0); + +} + +/* Verify two integers are equal. */ +int +assertion_equal_int(const char *file, int line, + long long v1, const char *e1, long long v2, const char *e2, void *extra) +{ + assertion_count(file, line); + if (v1 == v2) + return (1); + failure_start(file, line, "%s != %s", e1, e2); + logprintf(" %s=%lld (0x%llx, 0%llo)\n", e1, v1, v1, v1); + logprintf(" %s=%lld (0x%llx, 0%llo)\n", e2, v2, v2, v2); + failure_finish(extra); + return (0); +} + +static void strdump(const char *e, const char *p) +{ + const char *q = p; + + logprintf(" %s = ", e); + if (p == NULL) { + logprintf("NULL"); + return; + } + logprintf("\""); + while (*p != '\0') { + unsigned int c = 0xff & *p++; + switch (c) { + case '\a': printf("\a"); break; + case '\b': printf("\b"); break; + case '\n': printf("\n"); break; + case '\r': printf("\r"); break; + default: + if (c >= 32 && c < 127) + logprintf("%c", c); + else + logprintf("\\x%02X", c); + } + } + logprintf("\""); + logprintf(" (length %d)\n", q == NULL ? -1 : (int)strlen(q)); +} + +/* Verify two strings are equal, dump them if not. */ +int +assertion_equal_string(const char *file, int line, + const char *v1, const char *e1, + const char *v2, const char *e2, + void *extra) +{ + assertion_count(file, line); + if (v1 == v2 || (v1 != NULL && v2 != NULL && strcmp(v1, v2) == 0)) + return (1); + failure_start(file, line, "%s != %s", e1, e2); + strdump(e1, v1); + strdump(e2, v2); + failure_finish(extra); + return (0); +} + +static void +wcsdump(const char *e, const wchar_t *w) +{ + logprintf(" %s = ", e); + if (w == NULL) { + logprintf("(null)"); + return; + } + logprintf("\""); + while (*w != L'\0') { + unsigned int c = *w++; + if (c >= 32 && c < 127) + logprintf("%c", c); + else if (c < 256) + logprintf("\\x%02X", c); + else if (c < 0x10000) + logprintf("\\u%04X", c); + else + logprintf("\\U%08X", c); + } + logprintf("\"\n"); +} + +#ifndef HAVE_WCSCMP +static int +wcscmp(const wchar_t *s1, const wchar_t *s2) +{ + + while (*s1 == *s2++) { + if (*s1++ == L'\0') + return 0; + } + if (*s1 > *--s2) + return 1; + else + return -1; +} +#endif + +/* Verify that two wide strings are equal, dump them if not. */ +int +assertion_equal_wstring(const char *file, int line, + const wchar_t *v1, const char *e1, + const wchar_t *v2, const char *e2, + void *extra) +{ + assertion_count(file, line); + if (v1 == v2 || wcscmp(v1, v2) == 0) + return (1); + failure_start(file, line, "%s != %s", e1, e2); + wcsdump(e1, v1); + wcsdump(e2, v2); + failure_finish(extra); + return (0); +} + +/* + * Pretty standard hexdump routine. As a bonus, if ref != NULL, then + * any bytes in p that differ from ref will be highlighted with '_' + * before and after the hex value. + */ +static void +hexdump(const char *p, const char *ref, size_t l, size_t offset) +{ + size_t i, j; + char sep; + + if (p == NULL) { + logprintf("(null)\n"); + return; + } + for(i=0; i < l; i+=16) { + logprintf("%04x", (unsigned)(i + offset)); + sep = ' '; + for (j = 0; j < 16 && i + j < l; j++) { + if (ref != NULL && p[i + j] != ref[i + j]) + sep = '_'; + logprintf("%c%02x", sep, 0xff & (int)p[i+j]); + if (ref != NULL && p[i + j] == ref[i + j]) + sep = ' '; + } + for (; j < 16; j++) { + logprintf("%c ", sep); + sep = ' '; + } + logprintf("%c", sep); + for (j=0; j < 16 && i + j < l; j++) { + int c = p[i + j]; + if (c >= ' ' && c <= 126) + logprintf("%c", c); + else + logprintf("."); + } + logprintf("\n"); + } +} + +/* Verify that two blocks of memory are the same, display the first + * block of differences if they're not. */ +int +assertion_equal_mem(const char *file, int line, + const void *_v1, const char *e1, + const void *_v2, const char *e2, + size_t l, const char *ld, void *extra) +{ + const char *v1 = (const char *)_v1; + const char *v2 = (const char *)_v2; + size_t offset; + + assertion_count(file, line); + if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0)) + return (1); + + failure_start(file, line, "%s != %s", e1, e2); + logprintf(" size %s = %d\n", ld, (int)l); + /* Dump 48 bytes (3 lines) so that the first difference is + * in the second line. */ + offset = 0; + while (l > 64 && memcmp(v1, v2, 32) == 0) { + /* Two lines agree, so step forward one line. */ + v1 += 16; + v2 += 16; + l -= 16; + offset += 16; + } + logprintf(" Dump of %s\n", e1); + hexdump(v1, v2, l < 64 ? l : 64, offset); + logprintf(" Dump of %s\n", e2); + hexdump(v2, v1, l < 64 ? l : 64, offset); + logprintf("\n"); + failure_finish(extra); + return (0); +} + +/* Verify that the named file exists and is empty. */ +int +assertion_empty_file(const char *f1fmt, ...) +{ + char buff[1024]; + char f1[1024]; + struct stat st; + va_list ap; + ssize_t s; + FILE *f; + + assertion_count(test_filename, test_line); + va_start(ap, f1fmt); + vsprintf(f1, f1fmt, ap); + va_end(ap); + + if (stat(f1, &st) != 0) { + failure_start(test_filename, test_line, "Stat failed: %s", f1); + failure_finish(NULL); + return (0); + } + if (st.st_size == 0) + return (1); + + failure_start(test_filename, test_line, "File should be empty: %s", f1); + logprintf(" File size: %d\n", (int)st.st_size); + logprintf(" Contents:\n"); + f = fopen(f1, "rb"); + if (f == NULL) { + logprintf(" Unable to open %s\n", f1); + } else { + s = ((off_t)sizeof(buff) < st.st_size) ? + (ssize_t)sizeof(buff) : (ssize_t)st.st_size; + s = fread(buff, 1, s, f); + hexdump(buff, NULL, s, 0); + fclose(f); + } + failure_finish(NULL); + return (0); +} + +/* Verify that the named file exists and is not empty. */ +int +assertion_non_empty_file(const char *f1fmt, ...) +{ + char f1[1024]; + struct stat st; + va_list ap; + + assertion_count(test_filename, test_line); + va_start(ap, f1fmt); + vsprintf(f1, f1fmt, ap); + va_end(ap); + + if (stat(f1, &st) != 0) { + failure_start(test_filename, test_line, "Stat failed: %s", f1); + failure_finish(NULL); + return (0); + } + if (st.st_size == 0) { + failure_start(test_filename, test_line, "File empty: %s", f1); + failure_finish(NULL); + return (0); + } + return (1); +} + +/* Verify that two files have the same contents. */ +/* TODO: hexdump the first bytes that actually differ. */ +int +assertion_equal_file(const char *fn1, const char *f2pattern, ...) +{ + char fn2[1024]; + va_list ap; + char buff1[1024]; + char buff2[1024]; + FILE *f1, *f2; + int n1, n2; + + assertion_count(test_filename, test_line); + va_start(ap, f2pattern); + vsprintf(fn2, f2pattern, ap); + va_end(ap); + + f1 = fopen(fn1, "rb"); + f2 = fopen(fn2, "rb"); + for (;;) { + n1 = fread(buff1, 1, sizeof(buff1), f1); + n2 = fread(buff2, 1, sizeof(buff2), f2); + if (n1 != n2) + break; + if (n1 == 0 && n2 == 0) { + fclose(f1); + fclose(f2); + return (1); + } + if (memcmp(buff1, buff2, n1) != 0) + break; + } + fclose(f1); + fclose(f2); + failure_start(test_filename, test_line, "Files not identical"); + logprintf(" file1=\"%s\"\n", fn1); + logprintf(" file2=\"%s\"\n", fn2); + failure_finish(test_extra); + return (0); +} + +/* Verify that the named file does exist. */ +int +assertion_file_exists(const char *fpattern, ...) +{ + char f[1024]; + va_list ap; + + assertion_count(test_filename, test_line); + va_start(ap, fpattern); + vsprintf(f, fpattern, ap); + va_end(ap); + +#if defined(_WIN32) && !defined(__CYGWIN__) + if (!_access(f, 0)) + return (1); +#else + if (!access(f, F_OK)) + return (1); +#endif + failure_start(test_filename, test_line, "File should exist: %s", f); + failure_finish(test_extra); + return (0); +} + +/* Verify that the named file doesn't exist. */ +int +assertion_file_not_exists(const char *fpattern, ...) +{ + char f[1024]; + va_list ap; + + assertion_count(test_filename, test_line); + va_start(ap, fpattern); + vsprintf(f, fpattern, ap); + va_end(ap); + +#if defined(_WIN32) && !defined(__CYGWIN__) + if (_access(f, 0)) + return (1); +#else + if (access(f, F_OK)) + return (1); +#endif + failure_start(test_filename, test_line, "File should not exist: %s", f); + failure_finish(test_extra); + return (0); +} + +/* Compare the contents of a file to a block of memory. */ +int +assertion_file_contents(const void *buff, int s, const char *fpattern, ...) +{ + char fn[1024]; + va_list ap; + char *contents; + FILE *f; + int n; + + assertion_count(test_filename, test_line); + va_start(ap, fpattern); + vsprintf(fn, fpattern, ap); + va_end(ap); + + f = fopen(fn, "rb"); + if (f == NULL) { + failure_start(test_filename, test_line, + "File should exist: %s", fn); + failure_finish(test_extra); + return (0); + } + contents = malloc(s * 2); + n = fread(contents, 1, s * 2, f); + fclose(f); + if (n == s && memcmp(buff, contents, s) == 0) { + free(contents); + return (1); + } + failure_start(test_filename, test_line, "File contents don't match"); + logprintf(" file=\"%s\"\n", fn); + if (n > 0) + hexdump(contents, buff, n > 512 ? 512 : n, 0); + else { + logprintf(" File empty, contents should be:\n"); + hexdump(buff, NULL, s > 512 ? 512 : n, 0); + } + failure_finish(test_extra); + free(contents); + return (0); +} + +/* Check the contents of a text file, being tolerant of line endings. */ +int +assertion_text_file_contents(const char *buff, const char *fn) +{ + char *contents; + const char *btxt, *ftxt; + FILE *f; + int n, s; + + assertion_count(test_filename, test_line); + f = fopen(fn, "r"); + if (f == NULL) { + failure_start(test_filename, test_line, + "File doesn't exist: %s", fn); + failure_finish(test_extra); + return (0); + } + s = strlen(buff); + contents = malloc(s * 2 + 128); + n = fread(contents, 1, s * 2 + 128 - 1, f); + if (n >= 0) + contents[n] = '\0'; + fclose(f); + /* Compare texts. */ + btxt = buff; + ftxt = (const char *)contents; + while (*btxt != '\0' && *ftxt != '\0') { + if (*btxt == *ftxt) { + ++btxt; + ++ftxt; + continue; + } + if (btxt[0] == '\n' && ftxt[0] == '\r' && ftxt[1] == '\n') { + /* Pass over different new line characters. */ + ++btxt; + ftxt += 2; + continue; + } + break; + } + if (*btxt == '\0' && *ftxt == '\0') { + free(contents); + return (1); + } + failure_start(test_filename, test_line, "Contents don't match"); + logprintf(" file=\"%s\"\n", fn); + if (n > 0) + hexdump(contents, buff, n, 0); + else { + logprintf(" File empty, contents should be:\n"); + hexdump(buff, NULL, s, 0); + } + failure_finish(test_extra); + free(contents); + return (0); +} + +/* Test that two paths point to the same file. */ +/* As a side-effect, asserts that both files exist. */ +static int +is_hardlink(const char *file, int line, + const char *path1, const char *path2) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2; + int r; + + assertion_count(file, line); + r = my_GetFileInformationByName(path1, &bhfi1); + if (r == 0) { + failure_start(file, line, "File %s can't be inspected?", path1); + failure_finish(NULL); + return (0); + } + r = my_GetFileInformationByName(path2, &bhfi2); + if (r == 0) { + failure_start(file, line, "File %s can't be inspected?", path2); + failure_finish(NULL); + return (0); + } + return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber + && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh + && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow); +#else + struct stat st1, st2; + int r; + + assertion_count(file, line); + r = lstat(path1, &st1); + if (r != 0) { + failure_start(file, line, "File should exist: %s", path1); + failure_finish(NULL); + return (0); + } + r = lstat(path2, &st2); + if (r != 0) { + failure_start(file, line, "File should exist: %s", path2); + failure_finish(NULL); + return (0); + } + return (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev); +#endif +} + +int +assertion_is_hardlink(const char *file, int line, + const char *path1, const char *path2) +{ + if (is_hardlink(file, line, path1, path2)) + return (1); + failure_start(file, line, + "Files %s and %s are not hardlinked", path1, path2); + failure_finish(NULL); + return (0); +} + +int +assertion_is_not_hardlink(const char *file, int line, + const char *path1, const char *path2) +{ + if (!is_hardlink(file, line, path1, path2)) + return (1); + failure_start(file, line, + "Files %s and %s should not be hardlinked", path1, path2); + failure_finish(NULL); + return (0); +} + +/* Verify a/b/mtime of 'pathname'. */ +/* If 'recent', verify that it's within last 10 seconds. */ +static int +assertion_file_time(const char *file, int line, + const char *pathname, long t, long nsec, char type, int recent) +{ + long long filet, filet_nsec; + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) +#define EPOC_TIME (116444736000000000ULL) + FILETIME ftime, fbirthtime, fatime, fmtime; + ULARGE_INTEGER wintm; + HANDLE h; + ftime.dwLowDateTime = 0; + ftime.dwHighDateTime = 0; + + assertion_count(file, line); + h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + failure_start(file, line, "Can't access %s\n", pathname); + failure_finish(NULL); + return (0); + } + r = GetFileTime(h, &fbirthtime, &fatime, &fmtime); + switch (type) { + case 'a': ftime = fatime; break; + case 'b': ftime = fbirthtime; break; + case 'm': ftime = fmtime; break; + } + CloseHandle(h); + if (r == 0) { + failure_start(file, line, "Can't GetFileTime %s\n", pathname); + failure_finish(NULL); + return (0); + } + wintm.LowPart = ftime.dwLowDateTime; + wintm.HighPart = ftime.dwHighDateTime; + filet = (wintm.QuadPart - EPOC_TIME) / 10000000; + filet_nsec = ((wintm.QuadPart - EPOC_TIME) % 10000000) * 100; + nsec = (nsec / 100) * 100; /* Round the request */ +#else + struct stat st; + + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0) { + failure_start(file, line, "Can't stat %s\n", pathname); + failure_finish(NULL); + return (0); + } + switch (type) { + case 'a': filet = st.st_atime; break; + case 'm': filet = st.st_mtime; break; + case 'b': filet = 0; break; + default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); + exit(1); + } +#if defined(__FreeBSD__) + switch (type) { + case 'a': filet_nsec = st.st_atimespec.tv_nsec; break; + case 'b': filet = st.st_birthtime; + filet_nsec = st.st_birthtimespec.tv_nsec; break; + case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break; + default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); + exit(1); + } + /* FreeBSD generally only stores to microsecond res, so round. */ + filet_nsec = (filet_nsec / 1000) * 1000; + nsec = (nsec / 1000) * 1000; +#else + filet_nsec = nsec = 0; /* Generic POSIX only has whole seconds. */ + if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */ +#if defined(__HAIKU__) + if (type == 'a') return (1); /* Haiku doesn't have atime. */ +#endif +#endif +#endif + if (recent) { + /* Check that requested time is up-to-date. */ + time_t now = time(NULL); + if (filet < now - 10 || filet > now + 1) { + failure_start(file, line, + "File %s has %ctime %ld, %ld seconds ago\n", + pathname, type, filet, now - filet); + failure_finish(NULL); + return (0); + } + } else if (filet != t || filet_nsec != nsec) { + failure_start(file, line, + "File %s has %ctime %ld.%09ld, expected %ld.%09ld", + pathname, type, filet, filet_nsec, t, nsec); + failure_finish(NULL); + return (0); + } + return (1); +} + +/* Verify atime of 'pathname'. */ +int +assertion_file_atime(const char *file, int line, + const char *pathname, long t, long nsec) +{ + return assertion_file_time(file, line, pathname, t, nsec, 'a', 0); +} + +/* Verify atime of 'pathname' is up-to-date. */ +int +assertion_file_atime_recent(const char *file, int line, const char *pathname) +{ + return assertion_file_time(file, line, pathname, 0, 0, 'a', 1); +} + +/* Verify birthtime of 'pathname'. */ +int +assertion_file_birthtime(const char *file, int line, + const char *pathname, long t, long nsec) +{ + return assertion_file_time(file, line, pathname, t, nsec, 'b', 0); +} + +/* Verify birthtime of 'pathname' is up-to-date. */ +int +assertion_file_birthtime_recent(const char *file, int line, + const char *pathname) +{ + return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); +} + +/* Verify mtime of 'pathname'. */ +int +assertion_file_mtime(const char *file, int line, + const char *pathname, long t, long nsec) +{ + return assertion_file_time(file, line, pathname, t, nsec, 'm', 0); +} + +/* Verify mtime of 'pathname' is up-to-date. */ +int +assertion_file_mtime_recent(const char *file, int line, const char *pathname) +{ + return assertion_file_time(file, line, pathname, 0, 0, 'm', 1); +} + +/* Verify number of links to 'pathname'. */ +int +assertion_file_nlinks(const char *file, int line, + const char *pathname, int nlinks) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + BY_HANDLE_FILE_INFORMATION bhfi; + int r; + + assertion_count(file, line); + r = my_GetFileInformationByName(pathname, &bhfi); + if (r != 0 && bhfi.nNumberOfLinks == (DWORD)nlinks) + return (1); + failure_start(file, line, "File %s has %d links, expected %d", + pathname, bhfi.nNumberOfLinks, nlinks); + failure_finish(NULL); + return (0); +#else + struct stat st; + int r; + + assertion_count(file, line); + r = lstat(pathname, &st); + if (r == 0 && st.st_nlink == nlinks) + return (1); + failure_start(file, line, "File %s has %d links, expected %d", + pathname, st.st_nlink, nlinks); + failure_finish(NULL); + return (0); +#endif +} + +/* Verify size of 'pathname'. */ +int +assertion_file_size(const char *file, int line, const char *pathname, long size) +{ + int64_t filesize; + int r; + + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + { + BY_HANDLE_FILE_INFORMATION bhfi; + r = !my_GetFileInformationByName(pathname, &bhfi); + filesize = ((int64_t)bhfi.nFileSizeHigh << 32) + bhfi.nFileSizeLow; + } +#else + { + struct stat st; + r = lstat(pathname, &st); + filesize = st.st_size; + } +#endif + if (r == 0 && filesize == size) + return (1); + failure_start(file, line, "File %s has size %ld, expected %ld", + pathname, (long)filesize, (long)size); + failure_finish(NULL); + return (0); +} + +/* Assert that 'pathname' is a dir. If mode >= 0, verify that too. */ +int +assertion_is_dir(const char *file, int line, const char *pathname, int mode) +{ + struct stat st; + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)mode; /* UNUSED */ +#endif + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0) { + failure_start(file, line, "Dir should exist: %s", pathname); + failure_finish(NULL); + return (0); + } + if (!S_ISDIR(st.st_mode)) { + failure_start(file, line, "%s is not a dir", pathname); + failure_finish(NULL); + return (0); + } +#if !defined(_WIN32) || defined(__CYGWIN__) + /* Windows doesn't handle permissions the same way as POSIX, + * so just ignore the mode tests. */ + /* TODO: Can we do better here? */ + if (mode >= 0 && mode != (st.st_mode & 07777)) { + failure_start(file, line, "Dir %s has wrong mode", pathname); + logprintf(" Expected: 0%3o\n", mode); + logprintf(" Found: 0%3o\n", st.st_mode & 07777); + failure_finish(NULL); + return (0); + } +#endif + return (1); +} + +/* Verify that 'pathname' is a regular file. If 'mode' is >= 0, + * verify that too. */ +int +assertion_is_reg(const char *file, int line, const char *pathname, int mode) +{ + struct stat st; + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)mode; /* UNUSED */ +#endif + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0 || !S_ISREG(st.st_mode)) { + failure_start(file, line, "File should exist: %s", pathname); + failure_finish(NULL); + return (0); + } +#if !defined(_WIN32) || defined(__CYGWIN__) + /* Windows doesn't handle permissions the same way as POSIX, + * so just ignore the mode tests. */ + /* TODO: Can we do better here? */ + if (mode >= 0 && mode != (st.st_mode & 07777)) { + failure_start(file, line, "File %s has wrong mode", pathname); + logprintf(" Expected: 0%3o\n", mode); + logprintf(" Found: 0%3o\n", st.st_mode & 07777); + failure_finish(NULL); + return (0); + } +#endif + return (1); +} + +/* Check whether 'pathname' is a symbolic link. If 'contents' is + * non-NULL, verify that the symlink has those contents. */ +static int +is_symlink(const char *file, int line, + const char *pathname, const char *contents) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)pathname; /* UNUSED */ + (void)contents; /* UNUSED */ + assertion_count(file, line); + /* Windows sort-of has real symlinks, but they're only usable + * by privileged users and are crippled even then, so there's + * really not much point in bothering with this. */ + return (0); +#else + char buff[300]; + struct stat st; + ssize_t linklen; + int r; + + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0) { + failure_start(file, line, + "Symlink should exist: %s", pathname); + failure_finish(NULL); + return (0); + } + if (!S_ISLNK(st.st_mode)) + return (0); + if (contents == NULL) + return (1); + linklen = readlink(pathname, buff, sizeof(buff)); + if (linklen < 0) { + failure_start(file, line, "Can't read symlink %s", pathname); + failure_finish(NULL); + return (0); + } + buff[linklen] = '\0'; + if (strcmp(buff, contents) != 0) + return (0); + return (1); +#endif +} + +/* Assert that path is a symlink that (optionally) contains contents. */ +int +assertion_is_symlink(const char *file, int line, + const char *path, const char *contents) +{ + if (is_symlink(file, line, path, contents)) + return (1); + if (contents) + failure_start(file, line, "File %s is not a symlink to %s", + path, contents); + else + failure_start(file, line, "File %s is not a symlink", path); + failure_finish(NULL); + return (0); +} + + +/* Create a directory and report any errors. */ +int +assertion_make_dir(const char *file, int line, const char *dirname, int mode) +{ + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)mode; /* UNUSED */ + if (0 == _mkdir(dirname)) + return (1); +#else + if (0 == mkdir(dirname, mode)) + return (1); +#endif + failure_start(file, line, "Could not create directory %s", dirname); + failure_finish(NULL); + return(0); +} + +/* Create a file with the specified contents and report any failures. */ +int +assertion_make_file(const char *file, int line, + const char *path, int mode, const char *contents) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + /* TODO: Rework this to set file mode as well. */ + FILE *f; + (void)mode; /* UNUSED */ + assertion_count(file, line); + f = fopen(path, "wb"); + if (f == NULL) { + failure_start(file, line, "Could not create file %s", path); + failure_finish(NULL); + return (0); + } + if (contents != NULL) { + if (strlen(contents) + != fwrite(contents, 1, strlen(contents), f)) { + fclose(f); + failure_start(file, line, + "Could not write file %s", path); + failure_finish(NULL); + return (0); + } + } + fclose(f); + return (1); +#else + int fd; + assertion_count(file, line); + fd = open(path, O_CREAT | O_WRONLY, mode >= 0 ? mode : 0644); + if (fd < 0) { + failure_start(file, line, "Could not create %s", path); + failure_finish(NULL); + return (0); + } + if (contents != NULL) { + if ((ssize_t)strlen(contents) + != write(fd, contents, strlen(contents))) { + close(fd); + failure_start(file, line, "Could not write to %s", path); + failure_finish(NULL); + return (0); + } + } + close(fd); + return (1); +#endif +} + +/* Create a hardlink and report any failures. */ +int +assertion_make_hardlink(const char *file, int line, + const char *newpath, const char *linkto) +{ + int succeeded; + + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + succeeded = my_CreateHardLinkA(newpath, linkto); +#elif HAVE_LINK + succeeded = !link(linkto, newpath); +#else + succeeded = 0; +#endif + if (succeeded) + return (1); + failure_start(file, line, "Could not create hardlink"); + logprintf(" New link: %s\n", newpath); + logprintf(" Old name: %s\n", linkto); + failure_finish(NULL); + return(0); +} + +/* Create a symlink and report any failures. */ +int +assertion_make_symlink(const char *file, int line, + const char *newpath, const char *linkto) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + int targetIsDir = 0; /* TODO: Fix this */ + assertion_count(file, line); + if (my_CreateSymbolicLinkA(newpath, linkto, targetIsDir)) + return (1); +#elif HAVE_SYMLINK + assertion_count(file, line); + if (0 == symlink(linkto, newpath)) + return (1); +#endif + failure_start(file, line, "Could not create symlink"); + logprintf(" New link: %s\n", newpath); + logprintf(" Old name: %s\n", linkto); + failure_finish(NULL); + return(0); +} + +/* Set umask, report failures. */ +int +assertion_umask(const char *file, int line, int mask) +{ + assertion_count(file, line); + (void)file; /* UNUSED */ + (void)line; /* UNUSED */ + umask(mask); + return (1); +} + +/* + * + * UTILITIES for use by tests. + * + */ + +/* + * Check whether platform supports symlinks. This is intended + * for tests to use in deciding whether to bother testing symlink + * support; if the platform doesn't support symlinks, there's no point + * in checking whether the program being tested can create them. + * + * Note that the first time this test is called, we actually go out to + * disk to create and verify a symlink. This is necessary because + * symlink support is actually a property of a particular filesystem + * and can thus vary between directories on a single system. After + * the first call, this returns the cached result from memory, so it's + * safe to call it as often as you wish. + */ +int +canSymlink(void) +{ + /* Remember the test result */ + static int value = 0, tested = 0; + if (tested) + return (value); + + ++tested; + assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a"); + /* Note: Cygwin has its own symlink() emulation that does not + * use the Win32 CreateSymbolicLink() function. */ +#if defined(_WIN32) && !defined(__CYGWIN__) + value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0) + && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0"); +#elif HAVE_SYMLINK + value = (0 == symlink("canSymlink.0", "canSymlink.1")) + && is_symlink(__FILE__, __LINE__, "canSymlink.1","canSymlink.0"); +#endif + return (value); +} + +/* + * Can this platform run the gzip program? + */ +/* Platform-dependent options for hiding the output of a subcommand. */ +#if defined(_WIN32) && !defined(__CYGWIN__) +static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ +#else +static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ +#endif +int +canGzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("gzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the gunzip program? + */ +int +canGunzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("gunzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Sleep as needed; useful for verifying disk timestamp changes by + * ensuring that the wall-clock time has actually changed before we + * go back to re-read something from disk. + */ +void +sleepUntilAfter(time_t t) +{ + while (t >= time(NULL)) +#if defined(_WIN32) && !defined(__CYGWIN__) + Sleep(500); +#else + sleep(1); +#endif +} + +/* + * Call standard system() call, but build up the command line using + * sprintf() conventions. + */ +int +systemf(const char *fmt, ...) +{ + char buff[8192]; + va_list ap; + int r; + + va_start(ap, fmt); + vsprintf(buff, fmt, ap); + if (verbosity > VERBOSITY_FULL) + logprintf("Cmd: %s\n", buff); + r = system(buff); + va_end(ap); + return (r); +} + +/* + * Slurp a file into memory for ease of comparison and testing. + * Returns size of file in 'sizep' if non-NULL, null-terminates + * data in memory for ease of use. + */ +char * +slurpfile(size_t * sizep, const char *fmt, ...) +{ + char filename[8192]; + struct stat st; + va_list ap; + char *p; + ssize_t bytes_read; + FILE *f; + int r; + + va_start(ap, fmt); + vsprintf(filename, fmt, ap); + va_end(ap); + + f = fopen(filename, "rb"); + if (f == NULL) { + /* Note: No error; non-existent file is okay here. */ + return (NULL); + } + r = fstat(fileno(f), &st); + if (r != 0) { + logprintf("Can't stat file %s\n", filename); + fclose(f); + return (NULL); + } + p = malloc((size_t)st.st_size + 1); + if (p == NULL) { + logprintf("Can't allocate %ld bytes of memory to read file %s\n", + (long int)st.st_size, filename); + fclose(f); + return (NULL); + } + bytes_read = fread(p, 1, (size_t)st.st_size, f); + if (bytes_read < st.st_size) { + logprintf("Can't read file %s\n", filename); + fclose(f); + free(p); + return (NULL); + } + p[st.st_size] = '\0'; + if (sizep != NULL) + *sizep = (size_t)st.st_size; + fclose(f); + return (p); +} + +/* Read a uuencoded file from the reference directory, decode, and + * write the result into the current directory. */ +#define UUDECODE(c) (((c) - 0x20) & 0x3f) +void +extract_reference_file(const char *name) +{ + char buff[1024]; + FILE *in, *out; + + sprintf(buff, "%s/%s.uu", refdir, name); + in = fopen(buff, "r"); + failure("Couldn't open reference file %s", buff); + assert(in != NULL); + if (in == NULL) + return; + /* Read up to and including the 'begin' line. */ + for (;;) { + if (fgets(buff, sizeof(buff), in) == NULL) { + /* TODO: This is a failure. */ + return; + } + if (memcmp(buff, "begin ", 6) == 0) + break; + } + /* Now, decode the rest and write it. */ + /* Not a lot of error checking here; the input better be right. */ + out = fopen(name, "wb"); + while (fgets(buff, sizeof(buff), in) != NULL) { + char *p = buff; + int bytes; + + if (memcmp(buff, "end", 3) == 0) + break; + + bytes = UUDECODE(*p++); + while (bytes > 0) { + int n = 0; + /* Write out 1-3 bytes from that. */ + if (bytes > 0) { + n = UUDECODE(*p++) << 18; + n |= UUDECODE(*p++) << 12; + fputc(n >> 16, out); + --bytes; + } + if (bytes > 0) { + n |= UUDECODE(*p++) << 6; + fputc((n >> 8) & 0xFF, out); + --bytes; + } + if (bytes > 0) { + n |= UUDECODE(*p++); + fputc(n & 0xFF, out); + --bytes; + } + } + } + fclose(out); + fclose(in); +} + +/* + * + * TEST management + * + */ + +/* + * "list.h" is simply created by "grep DEFINE_TEST test_*.c"; it has + * a line like + * DEFINE_TEST(test_function) + * for each test. + */ + +/* Use "list.h" to declare all of the test functions. */ +#undef DEFINE_TEST +#define DEFINE_TEST(name) void name(void); +#include "list.h" + +/* Use "list.h" to create a list of all tests (functions and names). */ +#undef DEFINE_TEST +#define DEFINE_TEST(n) { n, #n, 0 }, +struct { void (*func)(void); const char *name; int failures; } tests[] = { + #include "list.h" +}; + +/* + * Summarize repeated failures in the just-completed test. + */ +static void +test_summarize(const char *filename, int failed) +{ + unsigned int i; + + switch (verbosity) { + case VERBOSITY_SUMMARY_ONLY: + printf(failed ? "E" : "."); + fflush(stdout); + break; + case VERBOSITY_PASSFAIL: + printf(failed ? "FAIL\n" : "ok\n"); + break; + } + + log_console = (verbosity == VERBOSITY_LIGHT_REPORT); + + for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { + if (failed_lines[i].count > 1 && !failed_lines[i].skip) + logprintf("%s:%d: Summary: Failed %d times\n", + filename, i, failed_lines[i].count); + } + /* Clear the failure history for the next file. */ + memset(failed_lines, 0, sizeof(failed_lines)); +} + +/* + * Actually run a single test, with appropriate setup and cleanup. + */ +static int +test_run(int i, const char *tmpdir) +{ + char logfilename[64]; + int failures_before = failures; + int oldumask; + + switch (verbosity) { + case VERBOSITY_SUMMARY_ONLY: /* No per-test reports at all */ + break; + case VERBOSITY_PASSFAIL: /* rest of line will include ok/FAIL marker */ + printf("%3d: %-50s", i, tests[i].name); + fflush(stdout); + break; + default: /* Title of test, details will follow */ + printf("%3d: %s\n", i, tests[i].name); + } + + /* Chdir to the top-level work directory. */ + if (!assertChdir(tmpdir)) { + fprintf(stderr, + "ERROR: Can't chdir to top work dir %s\n", tmpdir); + exit(1); + } + /* Create a log file for this test. */ + sprintf(logfilename, "%s.log", tests[i].name); + logfile = fopen(logfilename, "w"); + fprintf(logfile, "%s\n\n", tests[i].name); + /* Chdir() to a work dir for this specific test. */ + if (!assertMakeDir(tests[i].name, 0755) + || !assertChdir(tests[i].name)) { + fprintf(stderr, + "ERROR: Can't chdir to work dir %s/%s\n", + tmpdir, tests[i].name); + exit(1); + } + /* Explicitly reset the locale before each test. */ + setlocale(LC_ALL, "C"); + /* Record the umask before we run the test. */ + umask(oldumask = umask(0)); + /* + * Run the actual test. + */ + (*tests[i].func)(); + /* + * Clean up and report afterwards. + */ + /* Restore umask */ + umask(oldumask); + /* Reset locale. */ + setlocale(LC_ALL, "C"); + /* Reset directory. */ + if (!assertChdir(tmpdir)) { + fprintf(stderr, "ERROR: Couldn't chdir to temp dir %s\n", + tmpdir); + exit(1); + } + /* Report per-test summaries. */ + tests[i].failures = failures - failures_before; + test_summarize(test_filename, tests[i].failures); + /* Close the per-test log file. */ + fclose(logfile); + logfile = NULL; + /* If there were no failures, we can remove the work dir and logfile. */ + if (tests[i].failures == 0) { + if (!keep_temp_files && assertChdir(tmpdir)) { +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Make sure not to leave empty directories. + * Sometimes a processing of closing files used by tests + * is not done, then rmdir will be failed and it will + * leave a empty test directory. So we should wait a few + * seconds and retry rmdir. */ + int r, t; + for (t = 0; t < 10; t++) { + if (t > 0) + Sleep(1000); + r = systemf("rmdir /S /Q %s", tests[i].name); + if (r == 0) + break; + } + systemf("del %s", logfilename); +#else + systemf("rm -rf %s", tests[i].name); + systemf("rm %s", logfilename); +#endif + } + } + /* Return appropriate status. */ + return (tests[i].failures); +} + +/* + * + * + * MAIN and support routines. + * + * + */ + +static void +usage(const char *program) +{ + static const int limit = sizeof(tests) / sizeof(tests[0]); + int i; + + printf("Usage: %s [options] ...\n", program); + printf("Default is to run all tests.\n"); + printf("Otherwise, specify the numbers of the tests you wish to run.\n"); + printf("Options:\n"); + printf(" -d Dump core after any failure, for debugging.\n"); + printf(" -k Keep all temp files.\n"); + printf(" Default: temp files for successful tests deleted.\n"); +#ifdef PROGRAM + printf(" -p Path to executable to be tested.\n"); + printf(" Default: path taken from " ENVBASE " environment variable.\n"); +#endif + printf(" -q Quiet.\n"); + printf(" -r Path to dir containing reference files.\n"); + printf(" Default: Current directory.\n"); + printf(" -v Verbose.\n"); + printf("Available tests:\n"); + for (i = 0; i < limit; i++) + printf(" %d: %s\n", i, tests[i].name); + exit(1); +} + +static char * +get_refdir(const char *d) +{ + char tried[512] = { '\0' }; + char buff[128]; + char *pwd, *p; + + /* If a dir was specified, try that */ + if (d != NULL) { + pwd = NULL; + snprintf(buff, sizeof(buff), "%s", d); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + goto failure; + } + + /* Get the current dir. */ + pwd = getcwd(NULL, 0); + while (pwd[strlen(pwd) - 1] == '\n') + pwd[strlen(pwd) - 1] = '\0'; + + /* Look for a known file. */ + snprintf(buff, sizeof(buff), "%s", pwd); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + + snprintf(buff, sizeof(buff), "%s/test", pwd); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + +#if defined(LIBRARY) + snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY); +#else + snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM); +#endif + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + + if (memcmp(pwd, "/usr/obj", 8) == 0) { + snprintf(buff, sizeof(buff), "%s", pwd + 8); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + + snprintf(buff, sizeof(buff), "%s/test", pwd + 8); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + } + +failure: + printf("Unable to locate known reference file %s\n", KNOWNREF); + printf(" Checked following directories:\n%s\n", tried); +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) + DebugBreak(); +#endif + exit(1); + +success: + free(p); + free(pwd); + return strdup(buff); +} + +int +main(int argc, char **argv) +{ + static const int limit = sizeof(tests) / sizeof(tests[0]); + int i, tests_run = 0, tests_failed = 0, option; + time_t now; + char *refdir_alloc = NULL; + const char *progname; + const char *tmp, *option_arg, *p; + char tmpdir[256]; + char tmpdir_timestamp[256]; + + (void)argc; /* UNUSED */ + +#if defined(HAVE__CrtSetReportMode) + /* To stop to run the default invalid parameter handler. */ + _set_invalid_parameter_handler(invalid_parameter_handler); + /* Disable annoying assertion message box. */ + _CrtSetReportMode(_CRT_ASSERT, 0); +#endif + + /* + * Name of this program, used to build root of our temp directory + * tree. + */ + progname = p = argv[0]; + while (*p != '\0') { + /* Support \ or / dir separators for Windows compat. */ + if (*p == '/' || *p == '\\') + progname = p + 1; + ++p; + } + +#ifdef PROGRAM + /* Get the target program from environment, if available. */ + testprogfile = getenv(ENVBASE); +#endif + + if (getenv("TMPDIR") != NULL) + tmp = getenv("TMPDIR"); + else if (getenv("TMP") != NULL) + tmp = getenv("TMP"); + else if (getenv("TEMP") != NULL) + tmp = getenv("TEMP"); + else if (getenv("TEMPDIR") != NULL) + tmp = getenv("TEMPDIR"); + else + tmp = "/tmp"; + + /* Allow -d to be controlled through the environment. */ + if (getenv(ENVBASE "_DEBUG") != NULL) + dump_on_failure = 1; + + /* Get the directory holding test files from environment. */ + refdir = getenv(ENVBASE "_TEST_FILES"); + + /* + * Parse options, without using getopt(), which isn't available + * on all platforms. + */ + ++argv; /* Skip program name */ + while (*argv != NULL) { + if (**argv != '-') + break; + p = *argv++; + ++p; /* Skip '-' */ + while (*p != '\0') { + option = *p++; + option_arg = NULL; + /* If 'opt' takes an argument, parse that. */ + if (option == 'p' || option == 'r') { + if (*p != '\0') + option_arg = p; + else if (*argv == NULL) { + fprintf(stderr, + "Option -%c requires argument.\n", + option); + usage(progname); + } else + option_arg = *argv++; + p = ""; /* End of this option word. */ + } + + /* Now, handle the option. */ + switch (option) { + case 'd': + dump_on_failure = 1; + break; + case 'k': + keep_temp_files = 1; + break; + case 'p': +#ifdef PROGRAM + testprogfile = option_arg; +#else + usage(progname); +#endif + break; + case 'q': + verbosity--; + break; + case 'r': + refdir = option_arg; + break; + case 'v': + verbosity++; + break; + default: + usage(progname); + } + } + } + + /* + * Sanity-check that our options make sense. + */ +#ifdef PROGRAM + if (testprogfile == NULL) + usage(progname); + { + char *testprg; +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Command.com sometimes rejects '/' separators. */ + testprg = strdup(testprogfile); + for (i = 0; testprg[i] != '\0'; i++) { + if (testprg[i] == '/') + testprg[i] = '\\'; + } + testprogfile = testprg; +#endif + /* Quote the name that gets put into shell command lines. */ + testprg = malloc(strlen(testprogfile) + 3); + strcpy(testprg, "\""); + strcat(testprg, testprogfile); + strcat(testprg, "\""); + testprog = testprg; + } +#endif + + /* + * Create a temp directory for the following tests. + * Include the time the tests started as part of the name, + * to make it easier to track the results of multiple tests. + */ + now = time(NULL); + for (i = 0; ; i++) { + strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), + "%Y-%m-%dT%H.%M.%S", + localtime(&now)); + sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname, + tmpdir_timestamp, i); + if (assertMakeDir(tmpdir,0755)) + break; + if (i >= 999) { + fprintf(stderr, + "ERROR: Unable to create temp directory %s\n", + tmpdir); + exit(1); + } + } + + /* + * If the user didn't specify a directory for locating + * reference files, try to find the reference files in + * the "usual places." + */ + refdir = refdir_alloc = get_refdir(refdir); + + /* + * Banner with basic information. + */ + printf("\n"); + printf("If tests fail or crash, details will be in:\n"); + printf(" %s\n", tmpdir); + printf("\n"); + if (verbosity > VERBOSITY_SUMMARY_ONLY) { + printf("Reference files will be read from: %s\n", refdir); +#ifdef PROGRAM + printf("Running tests on: %s\n", testprog); +#endif + printf("Exercising: "); + fflush(stdout); + printf("%s\n", EXTRA_VERSION); + } else { + printf("Running "); + fflush(stdout); + } + + /* + * Run some or all of the individual tests. + */ + if (*argv == NULL) { + /* Default: Run all tests. */ + for (i = 0; i < limit; i++) { + if (test_run(i, tmpdir)) + tests_failed++; + tests_run++; + } + } else { + while (*(argv) != NULL) { + if (**argv >= '0' && **argv <= '9') { + i = atoi(*argv); + if (i < 0 || i >= limit) { + printf("*** INVALID Test %s\n", *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } + } else { + for (i = 0; i < limit; ++i) { + if (strcmp(*argv, tests[i].name) == 0) + break; + } + if (i >= limit) { + printf("*** INVALID Test ``%s''\n", + *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } + } + if (test_run(i, tmpdir)) + tests_failed++; + tests_run++; + argv++; + } + } + + /* + * Report summary statistics. + */ + if (verbosity > VERBOSITY_SUMMARY_ONLY) { + printf("\n"); + printf("Totals:\n"); + printf(" Tests run: %8d\n", tests_run); + printf(" Tests failed: %8d\n", tests_failed); + printf(" Assertions checked:%8d\n", assertions); + printf(" Assertions failed: %8d\n", failures); + printf(" Skips reported: %8d\n", skips); + } + if (failures) { + printf("\n"); + printf("Failing tests:\n"); + for (i = 0; i < limit; ++i) { + if (tests[i].failures) + printf(" %d: %s (%d failures)\n", i, + tests[i].name, tests[i].failures); + } + printf("\n"); + printf("Details for failing tests: %s\n", tmpdir); + printf("\n"); + } else { + if (verbosity == VERBOSITY_SUMMARY_ONLY) + printf("\n"); + printf("%d tests passed, no failures\n", tests_run); + } + + free(refdir_alloc); + + /* If the final tmpdir is empty, we can remove it. */ + /* This should be the usual case when all tests succeed. */ + assertChdir(".."); + rmdir(tmpdir); + + return (tests_failed ? 1 : 0); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test.h b/external/bsd/libarchive/dist/cpio/test/test.h new file mode 100644 index 000000000..2d68f3104 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test.h @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2003-2006 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/usr.bin/cpio/test/test.h,v 1.2 2008/06/21 02:17:18 kientzle Exp $ + */ + +/* Every test program should #include "test.h" as the first thing. */ + +/* + * The goal of this file (and the matching test.c) is to + * simplify the very repetitive test-*.c test programs. + */ +#if defined(HAVE_CONFIG_H) +/* Most POSIX platforms use the 'configure' script to build config.h */ +#include "config.h" +#elif defined(__FreeBSD__) +/* Building as part of FreeBSD system requires a pre-built config.h. */ +#include "config_freebsd.h" +#elif defined(_WIN32) && !defined(__CYGWIN__) +/* Win32 can't run the 'configure' script. */ +#include "config_windows.h" +#else +/* Warn if the library hasn't been (automatically or manually) configured. */ +#error Oops: No config.h and no pre-built configuration in test.h. +#endif + +#include /* Windows requires this before sys/stat.h */ +#include + +#ifdef USE_DMALLOC +#include +#endif +#if HAVE_DIRENT_H +#include +#endif +#ifdef HAVE_DIRECT_H +#include +#define dirent direct +#endif +#include +#include +#ifdef HAVE_IO_H +#include +#endif +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#ifdef HAVE_WINDOWS_H +#include +#endif + +/* + * System-specific tweaks. We really want to minimize these + * as much as possible, since they make it harder to understand + * the mainline code. + */ + +/* Windows (including Visual Studio and MinGW but not Cygwin) */ +#if defined(_WIN32) && !defined(__CYGWIN__) +#include "../cpio_windows.h" +#if !defined(__BORLANDC__) +#define strdup _strdup +#endif +#define LOCALE_DE "deu" +#else +#define LOCALE_DE "de_DE.UTF-8" +#endif + +/* Visual Studio */ +#ifdef _MSC_VER +#define snprintf sprintf_s +#endif + +/* Cygwin */ +#if defined(__CYGWIN__) +/* Cygwin-1.7.x is lazy about populating nlinks, so don't + * expect it to be accurate. */ +# define NLINKS_INACCURATE_FOR_DIRS +#endif + +#if defined(__HAIKU__) || defined(__QNXNTO__) +/* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */ +#include +#endif + +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID +#define __FBSDID(a) struct _undefined_hack +#endif + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +/* + * Redefine DEFINE_TEST for use in defining the test functions. + */ +#undef DEFINE_TEST +#define DEFINE_TEST(name) void name(void); void name(void) + +/* An implementation of the standard assert() macro */ +#define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL) +/* chdir() and error if it fails */ +#define assertChdir(path) \ + assertion_chdir(__FILE__, __LINE__, path) +/* Assert two integers are the same. Reports value of each one if not. */ +#define assertEqualInt(v1,v2) \ + assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) +/* Assert two strings are the same. Reports value of each one if not. */ +#define assertEqualString(v1,v2) \ + assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) +/* As above, but v1 and v2 are wchar_t * */ +#define assertEqualWString(v1,v2) \ + assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) +/* As above, but raw blocks of bytes. */ +#define assertEqualMem(v1, v2, l) \ + assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL) +/* Assert two files are the same; allow printf-style expansion of second name. + * See below for comments about variable arguments here... + */ +#define assertEqualFile \ + assertion_setup(__FILE__, __LINE__);assertion_equal_file +/* Assert that a file is empty; supports printf-style arguments. */ +#define assertEmptyFile \ + assertion_setup(__FILE__, __LINE__);assertion_empty_file +/* Assert that a file is not empty; supports printf-style arguments. */ +#define assertNonEmptyFile \ + assertion_setup(__FILE__, __LINE__);assertion_non_empty_file +#define assertFileAtime(pathname, sec, nsec) \ + assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec) +#define assertFileAtimeRecent(pathname) \ + assertion_file_atime_recent(__FILE__, __LINE__, pathname) +#define assertFileBirthtime(pathname, sec, nsec) \ + assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec) +#define assertFileBirthtimeRecent(pathname) \ + assertion_file_birthtime_recent(__FILE__, __LINE__, pathname) +/* Assert that a file exists; supports printf-style arguments. */ +#define assertFileExists \ + assertion_setup(__FILE__, __LINE__);assertion_file_exists +/* Assert that a file exists; supports printf-style arguments. */ +#define assertFileNotExists \ + assertion_setup(__FILE__, __LINE__);assertion_file_not_exists +/* Assert that file contents match a string; supports printf-style arguments. */ +#define assertFileContents \ + assertion_setup(__FILE__, __LINE__);assertion_file_contents +#define assertFileMtime(pathname, sec, nsec) \ + assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec) +#define assertFileMtimeRecent(pathname) \ + assertion_file_mtime_recent(__FILE__, __LINE__, pathname) +#define assertFileNLinks(pathname, nlinks) \ + assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks) +#define assertFileSize(pathname, size) \ + assertion_file_size(__FILE__, __LINE__, pathname, size) +#define assertTextFileContents \ + assertion_setup(__FILE__, __LINE__);assertion_text_file_contents +#define assertIsDir(pathname, mode) \ + assertion_is_dir(__FILE__, __LINE__, pathname, mode) +#define assertIsHardlink(path1, path2) \ + assertion_is_hardlink(__FILE__, __LINE__, path1, path2) +#define assertIsNotHardlink(path1, path2) \ + assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2) +#define assertIsReg(pathname, mode) \ + assertion_is_reg(__FILE__, __LINE__, pathname, mode) +#define assertIsSymlink(pathname, contents) \ + assertion_is_symlink(__FILE__, __LINE__, pathname, contents) +/* Create a directory, report error if it fails. */ +#define assertMakeDir(dirname, mode) \ + assertion_make_dir(__FILE__, __LINE__, dirname, mode) +#define assertMakeFile(path, mode, contents) \ + assertion_make_file(__FILE__, __LINE__, path, mode, contents) +#define assertMakeHardlink(newfile, oldfile) \ + assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile) +#define assertMakeSymlink(newfile, linkto) \ + assertion_make_symlink(__FILE__, __LINE__, newfile, linkto) +#define assertUmask(mask) \ + assertion_umask(__FILE__, __LINE__, mask) + +/* + * This would be simple with C99 variadic macros, but I don't want to + * require that. Instead, I insert a function call before each + * skipping() call to pass the file and line information down. Crude, + * but effective. + */ +#define skipping \ + assertion_setup(__FILE__, __LINE__);test_skipping + +/* Function declarations. These are defined in test_utility.c. */ +void failure(const char *fmt, ...); +int assertion_assert(const char *, int, int, const char *, void *); +int assertion_chdir(const char *, int, const char *); +int assertion_empty_file(const char *, ...); +int assertion_equal_file(const char *, const char *, ...); +int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *); +int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *); +int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *); +int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); +int assertion_file_atime(const char *, int, const char *, long, long); +int assertion_file_atime_recent(const char *, int, const char *); +int assertion_file_birthtime(const char *, int, const char *, long, long); +int assertion_file_birthtime_recent(const char *, int, const char *); +int assertion_file_contents(const void *, int, const char *, ...); +int assertion_file_exists(const char *, ...); +int assertion_file_mtime(const char *, int, const char *, long, long); +int assertion_file_mtime_recent(const char *, int, const char *); +int assertion_file_nlinks(const char *, int, const char *, int); +int assertion_file_not_exists(const char *, ...); +int assertion_file_size(const char *, int, const char *, long); +int assertion_is_dir(const char *, int, const char *, int); +int assertion_is_hardlink(const char *, int, const char *, const char *); +int assertion_is_not_hardlink(const char *, int, const char *, const char *); +int assertion_is_reg(const char *, int, const char *, int); +int assertion_is_symlink(const char *, int, const char *, const char *); +int assertion_make_dir(const char *, int, const char *, int); +int assertion_make_file(const char *, int, const char *, int, const char *); +int assertion_make_hardlink(const char *, int, const char *newpath, const char *); +int assertion_make_symlink(const char *, int, const char *newpath, const char *); +int assertion_non_empty_file(const char *, ...); +int assertion_text_file_contents(const char *buff, const char *f); +int assertion_umask(const char *, int, int); +void assertion_setup(const char *, int); + +void test_skipping(const char *fmt, ...); + +/* Like sprintf, then system() */ +int systemf(const char * fmt, ...); + +/* Delay until time() returns a value after this. */ +void sleepUntilAfter(time_t); + +/* Return true if this platform can create symlinks. */ +int canSymlink(void); + +/* Return true if this platform can run the "gzip" program. */ +int canGzip(void); + +/* Return true if this platform can run the "gunzip" program. */ +int canGunzip(void); + +/* Suck file into string allocated via malloc(). Call free() when done. */ +/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ +char *slurpfile(size_t *, const char *fmt, ...); + +/* Extracts named reference file to the current directory. */ +void extract_reference_file(const char *); + +/* + * Special interfaces for program test harness. + */ + +/* Pathname of exe to be tested. */ +const char *testprogfile; +/* Name of exe to use in printf-formatted command strings. */ +/* On Windows, this includes leading/trailing quotes. */ +const char *testprog; diff --git a/external/bsd/libarchive/dist/cpio/test/test_0.c b/external/bsd/libarchive/dist/cpio/test/test_0.c new file mode 100644 index 000000000..75a1437fd --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_0.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +/* + * This first test does basic sanity checks on the environment. For + * most of these, we just exit on failure. + */ +#if !defined(_WIN32) || defined(__CYGWIN__) +#define DEV_NULL "/dev/null" +#else +#define DEV_NULL "NUL" +#endif + +DEFINE_TEST(test_0) +{ + struct stat st; + + failure("File %s does not exist?!", testprogfile); + if (!assertEqualInt(0, stat(testprogfile, &st))) + exit(1); + + failure("%s is not executable?!", testprogfile); + if (!assert((st.st_mode & 0111) != 0)) + exit(1); + + /* + * Try to succesfully run the program; this requires that + * we know some option that will succeed. + */ + if (0 == systemf("%s --version >" DEV_NULL, testprog)) { + /* This worked. */ + } else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) { + /* This worked. */ + } else { + failure("Unable to successfully run any of the following:\n" + " * %s --version\n" + " * %s -W version\n", + testprog, testprog); + assert(0); + } + + /* TODO: Ensure that our reference files are available. */ +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_basic.c b/external/bsd/libarchive/dist/cpio/test/test_basic.c new file mode 100644 index 000000000..852b069a1 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_basic.c @@ -0,0 +1,173 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_basic.c,v 1.4 2008/08/25 06:39:29 kientzle Exp $"); + +static void +verify_files(const char *msg) +{ + /* + * Verify unpacked files. + */ + + /* Regular file with 2 links. */ + assertIsReg("file", 0644); + failure(msg); + assertFileSize("file", 10); + assertFileNLinks("file", 2); + + /* Another name for the same file. */ + assertIsHardlink("linkfile", "file"); + + /* Symlink */ + if (canSymlink()) + assertIsSymlink("symlink", "file"); + + /* Another file with 1 link and different permissions. */ + assertIsReg("file2", 0777); + assertFileSize("file2", 10); + assertFileNLinks("file2", 1); + + /* dir */ + assertIsDir("dir", 0775); +} + +static void +basic_cpio(const char *target, + const char *pack_options, + const char *unpack_options, + const char *se) +{ + int r; + + if (!assertMakeDir(target, 0775)) + return; + + /* Use the cpio program to create an archive. */ + r = systemf("%s -o %s < filelist >%s/archive 2>%s/pack.err", + testprog, pack_options, target, target); + failure("Error invoking %s -o %s", testprog, pack_options); + assertEqualInt(r, 0); + + assertChdir(target); + + /* Verify stderr. */ + failure("Expected: %s, options=%s", se, pack_options); + assertTextFileContents(se, "pack.err"); + + /* + * Use cpio to unpack the archive into another directory. + */ + r = systemf("%s -i %s< archive >unpack.out 2>unpack.err", + testprog, unpack_options); + failure("Error invoking %s -i %s", testprog, unpack_options); + assertEqualInt(r, 0); + + /* Verify stderr. */ + failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target); + assertTextFileContents(se, "unpack.err"); + + verify_files(pack_options); + + assertChdir(".."); +} + +static void +passthrough(const char *target) +{ + int r; + + if (!assertMakeDir(target, 0775)) + return; + + /* + * Use cpio passthrough mode to copy files to another directory. + */ + r = systemf("%s -p %s %s/stdout 2>%s/stderr", + testprog, target, target, target); + failure("Error invoking %s -p", testprog); + assertEqualInt(r, 0); + + assertChdir(target); + + /* Verify stderr. */ + failure("Error invoking %s -p in dir %s", + testprog, target); + assertTextFileContents("1 block\n", "stderr"); + + verify_files("passthrough"); + assertChdir(".."); +} + +DEFINE_TEST(test_basic) +{ + FILE *filelist; + const char *msg; + + assertUmask(0); + + /* + * Create an assortment of files on disk. + */ + filelist = fopen("filelist", "w"); + + /* File with 10 bytes content. */ + assertMakeFile("file", 0644, "1234567890"); + fprintf(filelist, "file\n"); + + /* hardlink to above file. */ + assertMakeHardlink("linkfile", "file"); + fprintf(filelist, "linkfile\n"); + + /* Symlink to above file. */ + if (canSymlink()) { + assertMakeSymlink("symlink", "file"); + fprintf(filelist, "symlink\n"); + } + + /* Another file with different permissions. */ + assertMakeFile("file2", 0777, "1234567890"); + fprintf(filelist, "file2\n"); + + /* Directory. */ + assertMakeDir("dir", 0775); + fprintf(filelist, "dir\n"); + /* All done. */ + fclose(filelist); + + assertUmask(022); + + /* Archive/dearchive with a variety of options. */ + msg = canSymlink() ? "2 blocks\n" : "1 block\n"; + basic_cpio("copy", "", "", msg); + basic_cpio("copy_odc", "--format=odc", "", msg); + basic_cpio("copy_newc", "-H newc", "", "2 blocks\n"); + basic_cpio("copy_cpio", "-H odc", "", msg); + msg = canSymlink() ? "9 blocks\n" : "8 blocks\n"; + basic_cpio("copy_ustar", "-H ustar", "", msg); + + /* Copy in one step using -p */ + passthrough("passthrough"); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_cmdline.c b/external/bsd/libarchive/dist/cpio/test/test_cmdline.c new file mode 100644 index 000000000..2dd7d651d --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_cmdline.c @@ -0,0 +1,107 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +/* + * Test the command-line parsing. + */ + +DEFINE_TEST(test_cmdline) +{ + FILE *f; + + /* Create an empty file. */ + f = fopen("empty", "wb"); + assert(f != NULL); + fclose(f); + + failure("-Q is an invalid option on every cpio program I know of"); + assert(0 != systemf("%s -i -Q 1.out 2>1.err", testprog)); + assertEmptyFile("1.out"); + + failure("-f requires an argument"); + assert(0 != systemf("%s -if 2.out 2>2.err", testprog)); + assertEmptyFile("2.out"); + + failure("-f requires an argument"); + assert(0 != systemf("%s -i -f 3.out 2>3.err", testprog)); + assertEmptyFile("3.out"); + + failure("--format requires an argument"); + assert(0 != systemf("%s -i --format 4.out 2>4.err", testprog)); + assertEmptyFile("4.out"); + + failure("--badopt is an invalid option"); + assert(0 != systemf("%s -i --badop 5.out 2>5.err", testprog)); + assertEmptyFile("5.out"); + + failure("--badopt is an invalid option"); + assert(0 != systemf("%s -i --badopt 6.out 2>6.err", testprog)); + assertEmptyFile("6.out"); + + failure("--n is ambiguous"); + assert(0 != systemf("%s -i --n 7.out 2>7.err", testprog)); + assertEmptyFile("7.out"); + + failure("--create forbids an argument"); + assert(0 != systemf("%s --create=arg 8.out 2>8.err", testprog)); + assertEmptyFile("8.out"); + + failure("-i with empty input should succeed"); + assert(0 == systemf("%s -i 9.out 2>9.err", testprog)); + assertEmptyFile("9.out"); + + failure("-o with empty input should succeed"); + assert(0 == systemf("%s -o 10.out 2>10.err", testprog)); + + failure("-i -p is nonsense"); + assert(0 != systemf("%s -i -p 11.out 2>11.err", testprog)); + assertEmptyFile("11.out"); + + failure("-p -i is nonsense"); + assert(0 != systemf("%s -p -i 12.out 2>12.err", testprog)); + assertEmptyFile("12.out"); + + failure("-i -o is nonsense"); + assert(0 != systemf("%s -i -o 13.out 2>13.err", testprog)); + assertEmptyFile("13.out"); + + failure("-o -i is nonsense"); + assert(0 != systemf("%s -o -i 14.out 2>14.err", testprog)); + assertEmptyFile("14.out"); + + failure("-o -p is nonsense"); + assert(0 != systemf("%s -o -p 15.out 2>15.err", testprog)); + assertEmptyFile("15.out"); + + failure("-p -o is nonsense"); + assert(0 != systemf("%s -p -o 16.out 2>16.err", testprog)); + assertEmptyFile("16.out"); + + failure("-p with empty input should fail"); + assert(0 != systemf("%s -p 17.out 2>17.err", testprog)); + assertEmptyFile("17.out"); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_format_newc.c b/external/bsd/libarchive/dist/cpio/test/test_format_newc.c new file mode 100644 index 000000000..06749a2f9 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_format_newc.c @@ -0,0 +1,294 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_format_newc.c,v 1.2 2008/08/22 02:09:10 kientzle Exp $"); + +/* Number of bytes needed to pad 'n' to multiple of 'block', assuming + * that 'block' is a power of two. This trick can be more easily + * remembered as -n & (block - 1), but many compilers quite reasonably + * warn about "-n" when n is an unsigned value. (~(n) + 1) is the + * same thing, but written in a way that won't offend anyone. */ +#define PAD(n, block) ((~(n) + 1) & ((block) - 1)) + +static int +is_hex(const char *p, size_t l) +{ + while (l > 0) { + if ((*p >= '0' && *p <= '9') + || (*p >= 'a' && *p <= 'f') + || (*p >= 'A' && *p <= 'F')) + { + --l; + ++p; + } else + return (0); + + } + return (1); +} + +static int +from_hex(const char *p, size_t l) +{ + int r = 0; + + while (l > 0) { + r *= 16; + if (*p >= 'a' && *p <= 'f') + r += *p + 10 - 'a'; + else if (*p >= 'A' && *p <= 'F') + r += *p + 10 - 'A'; + else + r += *p - '0'; + --l; + ++p; + } + return (r); +} + +DEFINE_TEST(test_format_newc) +{ + FILE *list; + int r; + int devmajor, devminor, ino, gid; + int uid = -1; + time_t t, t2, now; + char *p, *e; + size_t s, fs, ns; + + assertUmask(0); + +#if !defined(_WIN32) + uid = getuid(); +#endif + + /* + * Create an assortment of files. + * TODO: Extend this to cover more filetypes. + */ + list = fopen("list", "w"); + + /* "file1" */ + assertMakeFile("file1", 0644, "1234567890"); + fprintf(list, "file1\n"); + + /* "hardlink" */ + assertMakeHardlink("hardlink", "file1"); + fprintf(list, "hardlink\n"); + + /* Another hardlink, but this one won't be archived. */ + assertMakeHardlink("hardlink2", "file1"); + + /* "symlink" */ + if (canSymlink()) { + assertMakeSymlink("symlink", "file1"); + fprintf(list, "symlink\n"); + } + + /* "dir" */ + assertMakeDir("dir", 0775); + fprintf(list, "dir\n"); + + /* Record some facts about what we just created: */ + now = time(NULL); /* They were all created w/in last two seconds. */ + + /* Use the cpio program to create an archive. */ + fclose(list); + r = systemf("%s -o --format=newc newc.out 2>newc.err", + testprog); + if (!assertEqualInt(r, 0)) + return; + + /* Verify that nothing went to stderr. */ + if (canSymlink()) { + assertTextFileContents("2 blocks\n", "newc.err"); + } else { + assertTextFileContents("1 block\n", "newc.err"); + } + + /* Verify that stdout is a well-formed cpio file in "newc" format. */ + p = slurpfile(&s, "newc.out"); + assertEqualInt(s, canSymlink() ? 1024 : 512); + e = p; + + /* + * Some of these assertions could be stronger, but it's + * a little tricky because they depend on the local environment. + */ + + /* First entry is "file1" */ + assert(is_hex(e, 110)); /* Entire header is octal digits. */ + assertEqualMem(e + 0, "070701", 6); /* Magic */ + ino = from_hex(e + 6, 8); /* ino */ +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Group members bits and others bits do not work. */ + assertEqualInt(0x8180, from_hex(e + 14, 8) & 0xffc0); /* Mode */ +#else + assertEqualInt(0x81a4, from_hex(e + 14, 8)); /* Mode */ +#endif + if (uid < 0) + uid = from_hex(e + 22, 8); + assertEqualInt(from_hex(e + 22, 8), uid); /* uid */ + gid = from_hex(e + 30, 8); /* gid */ + assertEqualMem(e + 38, "00000003", 8); /* nlink */ + t = from_hex(e + 46, 8); /* mtime */ + failure("t=0x%08x now=0x%08x=%d", t, now, now); + assert(t <= now); /* File wasn't created in future. */ + failure("t=0x%08x now - 2=0x%08x = %d", t, now - 2, now - 2); + assert(t >= now - 2); /* File was created w/in last 2 secs. */ + failure("newc format stores body only with last appearance of a link\n" + " first appearance should be empty, so this file size\n" + " field should be zero"); + assertEqualInt(0, from_hex(e + 54, 8)); /* File size */ + fs = from_hex(e + 54, 8); + fs += PAD(fs, 4); + devmajor = from_hex(e + 62, 8); /* devmajor */ + devminor = from_hex(e + 70, 8); /* devminor */ + assert(is_hex(e + 78, 8)); /* rdevmajor */ + assert(is_hex(e + 86, 8)); /* rdevminor */ + assertEqualMem(e + 94, "00000006", 8); /* Name size */ + ns = from_hex(e + 94, 8); + ns += PAD(ns + 2, 4); + assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ + assertEqualMem(e + 110, "file1\0", 6); /* Name contents */ + /* Since there's another link, no file contents here. */ + /* But add in file size so that an error here doesn't cascade. */ + e += 110 + fs + ns; + + if (canSymlink()) { + /* "symlink" pointing to "file1" */ + assert(is_hex(e, 110)); + assertEqualMem(e + 0, "070701", 6); /* Magic */ + assert(is_hex(e + 6, 8)); /* ino */ + assertEqualInt(0xa1ff, from_hex(e + 14, 8)); /* Mode */ + assertEqualInt(from_hex(e + 22, 8), uid); /* uid */ + assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ + assertEqualMem(e + 38, "00000001", 8); /* nlink */ + t2 = from_hex(e + 46, 8); /* mtime */ + failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); + assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ + assertEqualMem(e + 54, "00000005", 8); /* File size */ + fs = from_hex(e + 54, 8); + fs += PAD(fs, 4); + assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ + assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ + assert(is_hex(e + 78, 8)); /* rdevmajor */ + assert(is_hex(e + 86, 8)); /* rdevminor */ + assertEqualMem(e + 94, "00000008", 8); /* Name size */ + ns = from_hex(e + 94, 8); + ns += PAD(ns + 2, 4); + assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ + assertEqualMem(e + 110, "symlink\0\0\0", 10); /* Name contents */ + assertEqualMem(e + 110 + ns, "file1\0\0\0", 8); /* symlink target */ + e += 110 + fs + ns; + } + + /* "dir" */ + assert(is_hex(e, 110)); + assertEqualMem(e + 0, "070701", 6); /* Magic */ + assert(is_hex(e + 6, 8)); /* ino */ +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Group members bits and others bits do not work. */ + assertEqualInt(0x41c0, from_hex(e + 14, 8) & 0xffc0); /* Mode */ +#else + /* Mode: sgid bit sometimes propagates from parent dirs, ignore it. */ + assertEqualInt(040775, from_hex(e + 14, 8) & ~02000); +#endif + assertEqualInt(from_hex(e + 22, 8), uid); /* uid */ + assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ +#ifndef NLINKS_INACCURATE_FOR_DIRS + assertEqualMem(e + 38, "00000002", 8); /* nlink */ +#endif + t2 = from_hex(e + 46, 8); /* mtime */ + failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); + assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ + assertEqualMem(e + 54, "00000000", 8); /* File size */ + fs = from_hex(e + 54, 8); + fs += PAD(fs, 4); + assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ + assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ + assert(is_hex(e + 78, 8)); /* rdevmajor */ + assert(is_hex(e + 86, 8)); /* rdevminor */ + assertEqualMem(e + 94, "00000004", 8); /* Name size */ + ns = from_hex(e + 94, 8); + ns += PAD(ns + 2, 4); + assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ + assertEqualMem(e + 110, "dir\0\0\0", 6); /* Name contents */ + e += 110 + fs + ns; + + /* Hardlink identical to "file1" */ + /* Since we only wrote two of the three links to this + * file, this link should get deferred by the hardlink logic. */ + assert(is_hex(e, 110)); + assertEqualMem(e + 0, "070701", 6); /* Magic */ + failure("If these aren't the same, then the hardlink detection failed to match them."); + assertEqualInt(ino, from_hex(e + 6, 8)); /* ino */ +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Group members bits and others bits do not work. */ + assertEqualInt(0x8180, from_hex(e + 14, 8) & 0xffc0); /* Mode */ +#else + assertEqualInt(0x81a4, from_hex(e + 14, 8)); /* Mode */ +#endif + assertEqualInt(from_hex(e + 22, 8), uid); /* uid */ + assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ + assertEqualMem(e + 38, "00000003", 8); /* nlink */ + t2 = from_hex(e + 46, 8); /* mtime */ + failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); + assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ + assertEqualInt(10, from_hex(e + 54, 8)); /* File size */ + fs = from_hex(e + 54, 8); + fs += PAD(fs, 4); + assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ + assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ + assert(is_hex(e + 78, 8)); /* rdevmajor */ + assert(is_hex(e + 86, 8)); /* rdevminor */ + assertEqualMem(e + 94, "00000009", 8); /* Name size */ + ns = from_hex(e + 94, 8); + ns += PAD(ns + 2, 4); + assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ + assertEqualMem(e + 110, "hardlink\0\0", 10); /* Name contents */ + assertEqualMem(e + 110 + ns, "1234567890\0\0", 12); /* File contents */ + e += 110 + ns + fs; + + /* Last entry is end-of-archive marker. */ + assert(is_hex(e, 110)); + assertEqualMem(e + 0, "070701", 6); /* Magic */ + assertEqualMem(e + 8, "00000000", 8); /* ino */ + assertEqualMem(e + 14, "00000000", 8); /* mode */ + assertEqualMem(e + 22, "00000000", 8); /* uid */ + assertEqualMem(e + 30, "00000000", 8); /* gid */ + assertEqualMem(e + 38, "00000001", 8); /* nlink */ + assertEqualMem(e + 46, "00000000", 8); /* mtime */ + assertEqualMem(e + 54, "00000000", 8); /* size */ + assertEqualMem(e + 62, "00000000", 8); /* devmajor */ + assertEqualMem(e + 70, "00000000", 8); /* devminor */ + assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ + assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ + assertEqualInt(11, from_hex(e + 94, 8)); /* name size */ + assertEqualMem(e + 102, "00000000", 8); /* check field */ + assertEqualMem(e + 110, "TRAILER!!!\0\0", 12); /* Name */ + + free(p); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_gcpio_compat.c b/external/bsd/libarchive/dist/cpio/test/test_gcpio_compat.c new file mode 100644 index 000000000..461e427c2 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_gcpio_compat.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_gcpio_compat.c,v 1.2 2008/08/22 02:27:06 kientzle Exp $"); + +static void +unpack_test(const char *from, const char *options, const char *se) +{ + int r; + + /* Create a work dir named after the file we're unpacking. */ + assertMakeDir(from, 0775); + assertChdir(from); + + /* + * Use cpio to unpack the sample archive + */ + extract_reference_file(from); + r = systemf("%s -i %s < %s >unpack.out 2>unpack.err", + testprog, options, from); + failure("Error invoking %s -i %s < %s", + testprog, options, from); + assertEqualInt(r, 0); + + /* Verify that nothing went to stderr. */ + if (canSymlink()) { + failure("Error invoking %s -i %s < %s", + testprog, options, from); + assertTextFileContents(se, "unpack.err"); + } + + /* + * Verify unpacked files. + */ + + /* Regular file with 2 links. */ + assertIsReg("file", 0644); + failure("%s", from); + assertFileSize("file", 10); + assertFileSize("linkfile", 10); + failure("%s", from); + assertFileNLinks("file", 2); + + /* Another name for the same file. */ + failure("%s", from); + assertIsHardlink("linkfile", "file"); + assertFileSize("file", 10); + assertFileSize("linkfile", 10); + + /* Symlink */ + if (canSymlink()) + assertIsSymlink("symlink", "file"); + + /* dir */ + assertIsDir("dir", 0775); + + assertChdir(".."); +} + +DEFINE_TEST(test_gcpio_compat) +{ + assertUmask(0); + + /* Dearchive sample files with a variety of options. */ + if (canSymlink()) { + unpack_test("test_gcpio_compat_ref.bin", + "--no-preserve-owner", "1 block\n"); + unpack_test("test_gcpio_compat_ref.crc", + "--no-preserve-owner", "2 blocks\n"); + unpack_test("test_gcpio_compat_ref.newc", + "--no-preserve-owner", "2 blocks\n"); + /* gcpio-2.9 only reads 6 blocks here */ + unpack_test("test_gcpio_compat_ref.ustar", + "--no-preserve-owner", "7 blocks\n"); + } else { + unpack_test("test_gcpio_compat_ref_nosym.bin", + "--no-preserve-owner", "1 block\n"); + unpack_test("test_gcpio_compat_ref_nosym.crc", + "--no-preserve-owner", "2 blocks\n"); + unpack_test("test_gcpio_compat_ref_nosym.newc", + "--no-preserve-owner", "2 blocks\n"); + /* gcpio-2.9 only reads 6 blocks here */ + unpack_test("test_gcpio_compat_ref_nosym.ustar", + "--no-preserve-owner", "7 blocks\n"); + } +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref.bin.uu b/external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref.bin.uu new file mode 100644 index 000000000..745d8ab78 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_gcpio_compat_ref.bin.uu @@ -0,0 +1,16 @@ +$FreeBSD$ +begin 644 test_gcpio_compat_ref.bin +MQW%9`*IWI('H`^@#`@````U'=YD%````"@!F:6QE```Q,C,T-38W.#D*QW%9 +M`*IWI('H`^@#`@````U'=YD)````"@!L:6YK9FEL90``,3(S-#4V-S@Y"L=Q +M60"K=^VAZ`/H`P$````-1X29"`````0` small.cpio 2>small.err", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "small.err"); + assertEqualInt(0, stat("small.cpio", &st)); + assertEqualInt(512, st.st_size); + + /* Create an archive with -B; this should be 5120 bytes. */ + r = systemf("echo file | %s -oB > large.cpio 2>large.err", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "large.err"); + assertEqualInt(0, stat("large.cpio", &st)); + assertEqualInt(5120, st.st_size); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_C_upper.c b/external/bsd/libarchive/dist/cpio/test/test_option_C_upper.c new file mode 100644 index 000000000..c8e63fd34 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_C_upper.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + + +DEFINE_TEST(test_option_C_upper) +{ + int r; + + /* + * Create a file on disk. + */ + assertMakeFile("file", 0644, NULL); + + /* Create an archive without -C; this should be 512 bytes. */ + r = systemf("echo file | %s -o > small.cpio 2>small.err", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "small.err"); + assertFileSize("small.cpio", 512); + + /* Create an archive with -C 513; this should be 513 bytes. */ + r = systemf("echo file | %s -o -C 513 > 513.cpio 2>513.err", + testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "513.err"); + assertFileSize("513.cpio", 513); + + /* Create an archive with -C 12345; this should be 12345 bytes. */ + r = systemf("echo file | %s -o -C12345 > 12345.cpio 2>12345.err", + testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "12345.err"); + assertFileSize("12345.cpio", 12345); + + /* Create an archive with invalid -C request */ + assert(0 != systemf("echo file | %s -o -C > bad.cpio 2>bad.err", + testprog)); + assertEmptyFile("bad.cpio"); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_J_upper.c b/external/bsd/libarchive/dist/cpio/test/test_option_J_upper.c new file mode 100644 index 000000000..532aacf39 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_J_upper.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_J_upper) +{ + char *p; + int r; + size_t s; + + /* Create a file. */ + assertMakeFile("f", 0644, "a"); + + /* Archive it with xz compression. */ + r = systemf("echo f | %s -o -J >archive.out 2>archive.err", + testprog); + p = slurpfile(&s, "archive.err"); + p[s] = '\0'; + if (r != 0) { + if (strstr(p, "compression not available") != NULL) { + skipping("This version of bsdcpio was compiled " + "without xz support"); + return; + } + failure("-J option is broken"); + assertEqualInt(r, 0); + return; + } + /* Check that the archive file has an xz signature. */ + p = slurpfile(&s, "archive.out"); + assert(s > 2); + assertEqualMem(p, "\3757zXZ", 5); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_L_upper.c b/external/bsd/libarchive/dist/cpio/test/test_option_L_upper.c new file mode 100644 index 000000000..1774343f6 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_L_upper.c @@ -0,0 +1,101 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_L.c,v 1.2 2008/08/24 06:21:00 kientzle Exp $"); + +/* This is a little pointless, as Windows doesn't support symlinks + * (except for the seriously crippled CreateSymbolicLink API) so these + * tests won't run on Windows. */ +#if defined(_WIN32) && !defined(__CYGWIN__) +#define CAT "type" +#else +#define CAT "cat" +#endif + +DEFINE_TEST(test_option_L_upper) +{ + FILE *filelist; + int r; + + if (!canSymlink()) { + skipping("Symlink tests"); + return; + } + + filelist = fopen("filelist", "w"); + + /* Create a file and a symlink to the file. */ + assertMakeFile("file", 0644, "1234567890"); + fprintf(filelist, "file\n"); + + /* Symlink to above file. */ + assertMakeSymlink("symlink", "file"); + fprintf(filelist, "symlink\n"); + + fclose(filelist); + + r = systemf(CAT " filelist | %s -pd copy >copy.out 2>copy.err", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "copy.err"); + + failure("Regular -p without -L should preserve symlinks."); + assertIsSymlink("copy/symlink", NULL); + + r = systemf(CAT " filelist | %s -pd -L copy-L >copy-L.out 2>copy-L.err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("copy-L.out"); + assertTextFileContents("1 block\n", "copy-L.err"); + failure("-pdL should dereference symlinks and turn them into files."); + assertIsReg("copy-L/symlink", -1); + + r = systemf(CAT " filelist | %s -o >archive.out 2>archive.err", testprog); + failure("Error invoking %s -o ", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "archive.err"); + + assertMakeDir("unpack", 0755); + assertChdir("unpack"); + r = systemf(CAT " ../archive.out | %s -i >unpack.out 2>unpack.err", testprog); + failure("Error invoking %s -i", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "unpack.err"); + assertChdir(".."); + + assertIsSymlink("unpack/symlink", NULL); + + r = systemf(CAT " filelist | %s -oL >archive-L.out 2>archive-L.err", testprog); + failure("Error invoking %s -oL", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "archive-L.err"); + + assertMakeDir("unpack-L", 0755); + assertChdir("unpack-L"); + r = systemf(CAT " ../archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog); + failure("Error invoking %s -i < archive-L.out", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "unpack-L.err"); + assertChdir(".."); + assertIsReg("unpack-L/symlink", -1); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_Z_upper.c b/external/bsd/libarchive/dist/cpio/test/test_option_Z_upper.c new file mode 100644 index 000000000..936ce0c2d --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_Z_upper.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_Z_upper) +{ + char *p; + int r; + size_t s; + + /* Create a file. */ + assertMakeFile("f", 0644, "a"); + + /* Archive it with compress compression. */ + r = systemf("echo f | %s -oZ >archive.out 2>archive.err", + testprog); + p = slurpfile(&s, "archive.err"); + p[s] = '\0'; + if (r != 0) { + if (strstr(p, "compression not available") != NULL) { + skipping("This version of bsdcpio was compiled " + "without compress support"); + return; + } + failure("-Z option is broken"); + assertEqualInt(r, 0); + return; + } + /* Check that the archive file has a compress signature. */ + p = slurpfile(&s, "archive.out"); + assert(s > 2); + assertEqualMem(p, "\x1f\x9d", 2); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_a.c b/external/bsd/libarchive/dist/cpio/test/test_option_a.c new file mode 100644 index 000000000..606de606e --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_a.c @@ -0,0 +1,154 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +#if defined(HAVE_UTIME_H) +#include +#elif defined(HAVE_SYS_UTIME_H) +#include +#endif +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_a.c,v 1.3 2008/08/24 06:21:00 kientzle Exp $"); + +static struct { + const char *name; + time_t atime_sec; +} files[] = { + { "f0", 0 }, + { "f1", 0 }, + { "f2", 0 }, + { "f3", 0 }, + { "f4", 0 }, + { "f5", 0 } +}; + +/* + * Create a bunch of test files and record their atimes. + * For the atime preserve/change tests, the files must have + * atimes in the past. We can accomplish this by explicitly invoking + * utime() on platforms that support it or by simply sleeping + * for a second after creating the files. (Creating all of the files + * at once means we only need to sleep once.) + */ +static void +test_create(void) +{ + struct stat st; + struct utimbuf times; + static const int numfiles = sizeof(files) / sizeof(files[0]); + int i; + + for (i = 0; i < numfiles; ++i) { + /* + * Note: Have to write at least one byte to the file. + * cpio doesn't bother reading the file if it's zero length, + * so the atime never gets changed in that case, which + * makes the tests below rather pointless. + */ + assertMakeFile(files[i].name, 0644, "a"); + + /* If utime() isn't supported on your platform, just + * #ifdef this section out. Most of the test below is + * still valid. */ + memset(×, 0, sizeof(times)); + times.actime = 1; + times.modtime = 3; + assertEqualInt(0, utime(files[i].name, ×)); + + /* Record whatever atime the file ended up with. */ + /* If utime() is available, this should be 1, but there's + * no harm in being careful. */ + assertEqualInt(0, stat(files[i].name, &st)); + files[i].atime_sec = st.st_atime; + } + + /* Wait until the atime on the last file is actually in the past. */ + sleepUntilAfter(files[numfiles - 1].atime_sec); +} + +DEFINE_TEST(test_option_a) +{ + struct stat st; + int r; + char *p; + + /* Create all of the test files. */ + test_create(); + + /* Sanity check; verify that atimes really do get modified. */ + assert((p = slurpfile(NULL, "f0")) != NULL); + free(p); + assertEqualInt(0, stat("f0", &st)); + if (st.st_atime == files[0].atime_sec) { + skipping("Cannot verify -a option\n" + " Your system appears to not support atime."); + } + else + { + /* + * If this disk is mounted noatime, then we can't + * verify correct operation without -a. + */ + + /* Copy the file without -a; should change the atime. */ + r = systemf("echo %s | %s -pd copy-no-a > copy-no-a.out 2>copy-no-a.err", files[1].name, testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "copy-no-a.err"); + assertEmptyFile("copy-no-a.out"); + assertEqualInt(0, stat(files[1].name, &st)); + failure("Copying file without -a should have changed atime."); + assert(st.st_atime != files[1].atime_sec); + + /* Archive the file without -a; should change the atime. */ + r = systemf("echo %s | %s -o > archive-no-a.out 2>archive-no-a.err", files[2].name, testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "copy-no-a.err"); + assertEqualInt(0, stat(files[2].name, &st)); + failure("Archiving file without -a should have changed atime."); + assert(st.st_atime != files[2].atime_sec); + } + + /* + * We can, of course, still verify that the atime is unchanged + * when using the -a option. + */ + + /* Copy the file with -a; should not change the atime. */ + r = systemf("echo %s | %s -pad copy-a > copy-a.out 2>copy-a.err", + files[3].name, testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "copy-a.err"); + assertEmptyFile("copy-a.out"); + assertEqualInt(0, stat(files[3].name, &st)); + failure("Copying file with -a should not have changed atime."); + assertEqualInt(st.st_atime, files[3].atime_sec); + + /* Archive the file with -a; should not change the atime. */ + r = systemf("echo %s | %s -oa > archive-a.out 2>archive-a.err", + files[4].name, testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "copy-a.err"); + assertEqualInt(0, stat(files[4].name, &st)); + failure("Archiving file with -a should not have changed atime."); + assertEqualInt(st.st_atime, files[4].atime_sec); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_c.c b/external/bsd/libarchive/dist/cpio/test/test_option_c.c new file mode 100644 index 000000000..241bcf67b --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_c.c @@ -0,0 +1,221 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +static int +is_octal(const char *p, size_t l) +{ + while (l > 0) { + if (*p < '0' || *p > '7') + return (0); + --l; + ++p; + } + return (1); +} + +static int +from_octal(const char *p, size_t l) +{ + int r = 0; + + while (l > 0) { + r *= 8; + r += *p - '0'; + --l; + ++p; + } + return (r); +} + +DEFINE_TEST(test_option_c) +{ + FILE *filelist; + int r; + int uid = -1; + int dev, ino, gid; + time_t t, now; + char *p, *e; + size_t s; + + assertUmask(0); + +#if !defined(_WIN32) + uid = getuid(); +#endif + + /* + * Create an assortment of files. + * TODO: Extend this to cover more filetypes. + */ + filelist = fopen("filelist", "w"); + + /* "file" */ + assertMakeFile("file", 0644, "1234567890"); + fprintf(filelist, "file\n"); + + /* "symlink" */ + if (canSymlink()) { + assertMakeSymlink("symlink", "file"); + fprintf(filelist, "symlink\n"); + } + + /* "dir" */ + assertMakeDir("dir", 0775); + /* Record some facts about what we just created: */ + now = time(NULL); /* They were all created w/in last two seconds. */ + fprintf(filelist, "dir\n"); + + /* Use the cpio program to create an archive. */ + fclose(filelist); + r = systemf("%s -oc basic.out 2>basic.err", testprog); + /* Verify that nothing went to stderr. */ + assertTextFileContents("1 block\n", "basic.err"); + + /* Assert that the program finished. */ + failure("%s -oc crashed", testprog); + if (!assertEqualInt(r, 0)) + return; + + /* Verify that stdout is a well-formed cpio file in "odc" format. */ + p = slurpfile(&s, "basic.out"); + assertEqualInt(s, 512); + e = p; + + /* + * Some of these assertions could be stronger, but it's + * a little tricky because they depend on the local environment. + */ + + /* First entry is "file" */ + assert(is_octal(e, 76)); /* Entire header is octal digits. */ + assertEqualMem(e + 0, "070707", 6); /* Magic */ + assert(is_octal(e + 6, 6)); /* dev */ + dev = from_octal(e + 6, 6); + assert(is_octal(e + 12, 6)); /* ino */ + ino = from_octal(e + 12, 6); +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Group members bits and others bits do not work. */ + assertEqualMem(e + 18, "100666", 6); /* Mode */ +#else + assertEqualMem(e + 18, "100644", 6); /* Mode */ +#endif + if (uid < 0) + uid = from_octal(e + 24, 6); + assertEqualInt(from_octal(e + 24, 6), uid); /* uid */ + assert(is_octal(e + 30, 6)); /* gid */ + gid = from_octal(e + 30, 6); + assertEqualMem(e + 36, "000001", 6); /* nlink */ + failure("file entries should not have rdev set (dev field was 0%o)", + dev); + assertEqualMem(e + 42, "000000", 6); /* rdev */ + t = from_octal(e + 48, 11); /* mtime */ + assert(t <= now); /* File wasn't created in future. */ + assert(t >= now - 2); /* File was created w/in last 2 secs. */ + assertEqualMem(e + 59, "000005", 6); /* Name size */ + assertEqualMem(e + 65, "00000000012", 11); /* File size */ + assertEqualMem(e + 76, "file\0", 5); /* Name contents */ + assertEqualMem(e + 81, "1234567890", 10); /* File contents */ + e += 91; + + /* "symlink" pointing to "file" */ + if (canSymlink()) { + assert(is_octal(e, 76)); /* Entire header is octal digits. */ + assertEqualMem(e + 0, "070707", 6); /* Magic */ + assertEqualInt(dev, from_octal(e + 6, 6)); /* dev */ + assert(ino != from_octal(e + 12, 6)); /* ino */ +#if !defined(_WIN32) || defined(__CYGWIN__) + /* On Windows, symbolic link and group members bits and + * others bits do not work. */ + assertEqualMem(e + 18, "120777", 6); /* Mode */ +#endif + assertEqualInt(from_octal(e + 24, 6), uid); /* uid */ + assertEqualInt(gid, from_octal(e + 30, 6)); /* gid */ + assertEqualMem(e + 36, "000001", 6); /* nlink */ + failure("file entries should have rdev == 0 (dev was 0%o)", + from_octal(e + 6, 6)); + assertEqualMem(e + 42, "000000", 6); /* rdev */ + t = from_octal(e + 48, 11); /* mtime */ + assert(t <= now); /* File wasn't created in future. */ + assert(t >= now - 2); /* File was created w/in last 2 secs. */ + assertEqualMem(e + 59, "000010", 6); /* Name size */ + assertEqualMem(e + 65, "00000000004", 11); /* File size */ + assertEqualMem(e + 76, "symlink\0", 8); /* Name contents */ + assertEqualMem(e + 84, "file", 4); /* Symlink target. */ + e += 88; + } + + /* "dir" */ + assert(is_octal(e, 76)); + assertEqualMem(e + 0, "070707", 6); /* Magic */ + /* Dev should be same as first entry. */ + assert(is_octal(e + 6, 6)); /* dev */ + assertEqualInt(dev, from_octal(e + 6, 6)); + /* Ino must be different from first entry. */ + assert(is_octal(e + 12, 6)); /* ino */ + assert(dev != from_octal(e + 12, 6)); +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Group members bits and others bits do not work. */ + assertEqualMem(e + 18, "040777", 6); /* Mode */ +#else + /* Accept 042775 to accomodate systems where sgid bit propagates. */ + if (memcmp(e + 18, "042775", 6) != 0) + assertEqualMem(e + 18, "040775", 6); /* Mode */ +#endif + assertEqualInt(from_octal(e + 24, 6), uid); /* uid */ + /* Gid should be same as first entry. */ + assert(is_octal(e + 30, 6)); /* gid */ + assertEqualInt(gid, from_octal(e + 30, 6)); +#ifndef NLINKS_INACCURATE_FOR_DIRS + assertEqualMem(e + 36, "000002", 6); /* Nlink */ +#endif + t = from_octal(e + 48, 11); /* mtime */ + assert(t <= now); /* File wasn't created in future. */ + assert(t >= now - 2); /* File was created w/in last 2 secs. */ + assertEqualMem(e + 59, "000004", 6); /* Name size */ + assertEqualMem(e + 65, "00000000000", 11); /* File size */ + assertEqualMem(e + 76, "dir\0", 4); /* name */ + e += 80; + + /* TODO: Verify other types of entries. */ + + /* Last entry is end-of-archive marker. */ + assert(is_octal(e, 76)); + assertEqualMem(e + 0, "070707", 6); /* Magic */ + assertEqualMem(e + 6, "000000", 6); /* dev */ + assertEqualMem(e + 12, "000000", 6); /* ino */ + assertEqualMem(e + 18, "000000", 6); /* Mode */ + assertEqualMem(e + 24, "000000", 6); /* uid */ + assertEqualMem(e + 30, "000000", 6); /* gid */ + assertEqualMem(e + 36, "000001", 6); /* Nlink */ + assertEqualMem(e + 42, "000000", 6); /* rdev */ + assertEqualMem(e + 48, "00000000000", 11); /* mtime */ + assertEqualMem(e + 59, "000013", 6); /* Name size */ + assertEqualMem(e + 65, "00000000000", 11); /* File size */ + assertEqualMem(e + 76, "TRAILER!!!\0", 11); /* Name */ + + free(p); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_d.c b/external/bsd/libarchive/dist/cpio/test/test_option_d.c new file mode 100644 index 000000000..9ff145396 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_d.c @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + + +DEFINE_TEST(test_option_d) +{ + int r; + + /* + * Create a file in a directory. + */ + assertMakeDir("dir", 0755); + assertMakeFile("dir/file", 0644, NULL); + + /* Create an archive. */ + r = systemf("echo dir/file | %s -o > archive.cpio 2>archive.err", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "archive.err"); + assertFileSize("archive.cpio", 512); + + /* Dearchive without -d, this should fail. */ + assertMakeDir("without-d", 0755); + assertChdir("without-d"); + r = systemf("%s -i < ../archive.cpio >out 2>err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("out"); + /* And the file should not be restored. */ + assertFileNotExists("dir/file"); + + /* Dearchive with -d, this should succeed. */ + assertChdir(".."); + assertMakeDir("with-d", 0755); + assertChdir("with-d"); + r = systemf("%s -id < ../archive.cpio >out 2>err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("out"); + assertTextFileContents("1 block\n", "err"); + /* And the file should be restored. */ + assertFileExists("dir/file"); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_f.c b/external/bsd/libarchive/dist/cpio/test/test_option_f.c new file mode 100644 index 000000000..784e08584 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_f.c @@ -0,0 +1,76 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +/* + * Unpack the archive in a new dir. + */ +static void +unpack(const char *dirname, const char *option) +{ + int r; + + assertMakeDir(dirname, 0755); + assertChdir(dirname); + extract_reference_file("test_option_f.cpio"); + r = systemf("%s -i %s < test_option_f.cpio > copy-no-a.out 2>copy-no-a.err", testprog, option); + assertEqualInt(0, r); + assertChdir(".."); +} + +DEFINE_TEST(test_option_f) +{ + /* Calibrate: No -f option, so everything should be extracted. */ + unpack("t0", "--no-preserve-owner"); + assertFileExists("t0/a123"); + assertFileExists("t0/a234"); + assertFileExists("t0/b123"); + assertFileExists("t0/b234"); + + /* Don't extract 'a*' files. */ +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Single quotes isn't used by command.exe. */ + unpack("t1", "--no-preserve-owner -f a*"); +#else + unpack("t1", "--no-preserve-owner -f 'a*'"); +#endif + assertFileNotExists("t1/a123"); + assertFileNotExists("t1/a234"); + assertFileExists("t1/b123"); + assertFileExists("t1/b234"); + + /* Don't extract 'b*' files. */ +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Single quotes isn't used by command.exe. */ + unpack("t2", "--no-preserve-owner -f b*"); +#else + unpack("t2", "--no-preserve-owner -f 'b*'"); +#endif + assertFileExists("t2/a123"); + assertFileExists("t2/a234"); + assertFileNotExists("t2/b123"); + assertFileNotExists("t2/b234"); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_f.cpio.uu b/external/bsd/libarchive/dist/cpio/test/test_option_f.cpio.uu new file mode 100644 index 000000000..42c63c396 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_f.cpio.uu @@ -0,0 +1,16 @@ +$FreeBSD$ +begin 644 test_option_f.cpio +M,#help.stdout 2>help.stderr", testprog); + assertEqualInt(r, 0); + failure("--help should generate nothing to stderr."); + assertEmptyFile("help.stderr"); + /* Help message should start with name of program. */ + p = slurpfile(&plen, "help.stdout"); + failure("Help output should be long enough."); + assert(plen >= 7); + failure("First line of help output should contain string 'bsdcpio'"); + assert(in_first_line(p, "bsdcpio")); + /* + * TODO: Extend this check to further verify that --help output + * looks approximately right. + */ + free(p); + + /* -h option should generate the same output. */ + r = systemf("%s -h >h.stdout 2>h.stderr", testprog); + assertEqualInt(r, 0); + failure("-h should generate nothing to stderr."); + assertEmptyFile("h.stderr"); + failure("stdout should be same for -h and --help"); + assertEqualFile("h.stdout", "help.stdout"); + + /* -W help should be another synonym. */ + r = systemf("%s -W help >Whelp.stdout 2>Whelp.stderr", testprog); + assertEqualInt(r, 0); + failure("-W help should generate nothing to stderr."); + assertEmptyFile("Whelp.stderr"); + failure("stdout should be same for -W help and --help"); + assertEqualFile("Whelp.stdout", "help.stdout"); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_l.c b/external/bsd/libarchive/dist/cpio/test/test_option_l.c new file mode 100644 index 000000000..5c76e688e --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_l.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_l) +{ + int r; + + /* Create a file. */ + assertMakeFile("f", 0644, "a"); + + /* Copy the file to the "copy" dir. */ + r = systemf("echo f | %s -pd copy >copy.out 2>copy.err", + testprog); + assertEqualInt(r, 0); + + /* Check that the copy is a true copy and not a link. */ + assertIsNotHardlink("f", "copy/f"); + + /* Copy the file to the "link" dir with the -l option. */ + r = systemf("echo f | %s -pld link >link.out 2>link.err", + testprog); + assertEqualInt(r, 0); + + /* Check that this is a link and not a copy. */ + assertIsHardlink("f", "link/f"); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_lzma.c b/external/bsd/libarchive/dist/cpio/test/test_option_lzma.c new file mode 100644 index 000000000..c6e335301 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_lzma.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_lzma) +{ + char *p; + int r; + size_t s; + + /* Create a file. */ + assertMakeFile("f", 0644, "a"); + + /* Archive it with lzma compression. */ + r = systemf("echo f | %s -o --lzma >archive.out 2>archive.err", + testprog); + p = slurpfile(&s, "archive.err"); + p[s] = '\0'; + if (r != 0) { + if (strstr(p, "compression not available") != NULL) { + skipping("This version of bsdcpio was compiled " + "without lzma support"); + return; + } + failure("--lzma option is broken"); + assertEqualInt(r, 0); + return; + } + /* Check that the archive file has an lzma signature. */ + p = slurpfile(&s, "archive.out"); + assert(s > 2); + assertEqualMem(p, "\x5d\00\00", 3); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_m.c b/external/bsd/libarchive/dist/cpio/test/test_option_m.c new file mode 100644 index 000000000..de880b288 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_m.c @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + + +DEFINE_TEST(test_option_m) +{ + int r; + + /* + * The reference archive has one file with an mtime in 1970, 1 + * second after the start of the epoch. + */ + + /* Restored without -m, the result should have a current mtime. */ + assertMakeDir("without-m", 0755); + assertChdir("without-m"); + extract_reference_file("test_option_m.cpio"); + r = systemf("%s --no-preserve-owner -i < test_option_m.cpio >out 2>err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("out"); + assertTextFileContents("1 block\n", "err"); + /* Should have been created within the last few seconds. */ + assertFileMtimeRecent("file"); + + /* With -m, it should have an mtime in 1970. */ + assertChdir(".."); + assertMakeDir("with-m", 0755); + assertChdir("with-m"); + extract_reference_file("test_option_m.cpio"); + r = systemf("%s --no-preserve-owner -im < test_option_m.cpio >out 2>err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("out"); + assertTextFileContents("1 block\n", "err"); + /* + * mtime in reference archive is '1' == 1 second after + * midnight Jan 1, 1970 UTC. + */ + assertFileMtime("file", 1, 0); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_m.cpio.uu b/external/bsd/libarchive/dist/cpio/test/test_option_m.cpio.uu new file mode 100644 index 000000000..3d2002355 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_m.cpio.uu @@ -0,0 +1,16 @@ +$FreeBSD$ +begin 644 test_option_m.cpio +M,#it.out 2>it.err", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "it.err"); + extract_reference_file("test_option_t.stdout"); + p = slurpfile(NULL, "test_option_t.stdout"); + assertTextFileContents(p, "it.out"); + free(p); + + /* We accept plain "-t" as a synonym for "-it" */ + r = systemf("%s -t < test_option_t.cpio >t.out 2>t.err", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "t.err"); + extract_reference_file("test_option_t.stdout"); + p = slurpfile(NULL, "test_option_t.stdout"); + assertTextFileContents(p, "t.out"); + free(p); + + /* But "-ot" is an error. */ + assert(0 != systemf("%s -ot < test_option_t.cpio >ot.out 2>ot.err", + testprog)); + assertEmptyFile("ot.out"); + + /* List reference archive verbosely, make sure the TOC is correct. */ + r = systemf("%s -itv < test_option_t.cpio >tv.out 2>tv.err", testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "tv.err"); + extract_reference_file("test_option_tv.stdout"); + + /* This doesn't work because the usernames on different systems + * are different and cpio now looks up numeric UIDs on + * the local system. */ + /* assertEqualFile("tv.out", "test_option_tv.stdout"); */ + + /* List reference archive with numeric IDs, verify TOC is correct. */ + r = systemf("%s -itnv < test_option_t.cpio >itnv.out 2>itnv.err", + testprog); + assertEqualInt(r, 0); + assertTextFileContents("1 block\n", "itnv.err"); + p = slurpfile(NULL, "itnv.out"); + /* Since -n uses numeric UID/GID, this part should be the + * same on every system. */ + assertEqualMem(p, "-rw-r--r-- 1 1000 1000 0 ",42); + /* Date varies depending on local timezone. */ + if (memcmp(p + 42, "Dec 31 1969", 12) == 0) { + /* East of Greenwich we get Dec 31, 1969. */ + } else { + /* West of Greenwich get Jan 1, 1970 */ + assertEqualMem(p + 42, "Jan ", 4); + /* Some systems format "Jan 01", some "Jan 1" */ + assert(p[46] == ' ' || p[46] == '0'); + assertEqualMem(p + 47, "1 1970 ", 8); + } + assertEqualMem(p + 54, " file", 5); + free(p); + + /* But "-n" without "-t" is an error. */ + assert(0 != systemf("%s -in < test_option_t.cpio >in.out 2>in.err", + testprog)); + assertEmptyFile("in.out"); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_t.cpio.uu b/external/bsd/libarchive/dist/cpio/test/test_option_t.cpio.uu new file mode 100644 index 000000000..055fe747d --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_t.cpio.uu @@ -0,0 +1,16 @@ +$FreeBSD$ +begin 644 test_option_t.cpio +M,# +#elif defined(HAVE_SYS_UTIME_H) +#include +#endif +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_u) +{ + struct utimbuf times; + char *p; + size_t s; + int r; + + /* Create a file. */ + assertMakeFile("f", 0644, "a"); + + /* Copy the file to the "copy" dir. */ + r = systemf("echo f | %s -pd copy >copy.out 2>copy.err", + testprog); + assertEqualInt(r, 0); + + /* Check that the file contains only a single "a" */ + p = slurpfile(&s, "copy/f"); + assertEqualInt(s, 1); + assertEqualMem(p, "a", 1); + + /* Recreate the file with a single "b" */ + assertMakeFile("f", 0644, "b"); + + /* Set the mtime to the distant past. */ + memset(×, 0, sizeof(times)); + times.actime = 1; + times.modtime = 3; + assertEqualInt(0, utime("f", ×)); + + /* Copy the file to the "copy" dir. */ + r = systemf("echo f | %s -pd copy >copy.out 2>copy.err", + testprog); + assertEqualInt(r, 0); + + /* Verify that the file hasn't changed (it wasn't overwritten) */ + p = slurpfile(&s, "copy/f"); + assertEqualInt(s, 1); + assertEqualMem(p, "a", 1); + + /* Copy the file to the "copy" dir with -u (force) */ + r = systemf("echo f | %s -pud copy >copy.out 2>copy.err", + testprog); + assertEqualInt(r, 0); + + /* Verify that the file has changed (it was overwritten) */ + p = slurpfile(&s, "copy/f"); + assertEqualInt(s, 1); + assertEqualMem(p, "b", 1); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_version.c b/external/bsd/libarchive/dist/cpio/test/test_option_version.c new file mode 100644 index 000000000..7345da1e5 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_version.c @@ -0,0 +1,109 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +/* + * Test that --version option works and generates reasonable output. + */ + +static void +verify(const char *p, size_t s) +{ + const char *q = p; + + /* Version message should start with name of program, then space. */ + failure("version message too short:", p); + if (!assert(s > 6)) + return; + failure("Version message should begin with 'bsdcpio': %s", p); + if (!assertEqualMem(q, "bsdcpio ", 8)) + /* If we're not testing bsdcpio, don't keep going. */ + return; + q += 8; s -= 8; + /* Version number is a series of digits and periods. */ + while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) { + ++q; + --s; + } + /* Version number terminated by space. */ + failure("Version: %s", p); + assert(s > 1); + /* Skip a single trailing a,b,c, or d. */ + if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd') + ++q; + failure("Version: %s", p); + assert(*q == ' '); + ++q; --s; + /* Separator. */ + failure("Version: %s", p); + assertEqualMem(q, "-- ", 3); + q += 3; s -= 3; + /* libarchive name and version number */ + assert(s > 11); + failure("Version: %s", p); + assertEqualMem(q, "libarchive ", 11); + q += 11; s -= 11; + /* Version number is a series of digits and periods. */ + while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) { + ++q; + --s; + } + /* Skip a single trailing a,b,c, or d. */ + if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd') + ++q; + /* All terminated by end-of-line: \r, \r\n, or \n */ + assert(s >= 1); + failure("Version: %s", p); + if (*q == '\x0d') { + if (q[1] != '\0') + assertEqualMem(q, "\x0d\x0a", 2); + } else + assertEqualMem(q, "\x0a", 1); +} + + +DEFINE_TEST(test_option_version) +{ + int r; + char *p; + size_t s; + + r = systemf("%s --version >version.stdout 2>version.stderr", testprog); + if (r != 0) + r = systemf("%s -W version >version.stdout 2>version.stderr", + testprog); + failure("Unable to run either %s --version or %s -W version", + testprog, testprog); + if (!assert(r == 0)) + return; + + /* --version should generate nothing to stderr. */ + assertEmptyFile("version.stderr"); + /* Verify format of version message. */ + p = slurpfile(&s, "version.stdout"); + verify(p, s); + free(p); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_y.c b/external/bsd/libarchive/dist/cpio/test/test_option_y.c new file mode 100644 index 000000000..58734966c --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_y.c @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_y.c,v 1.2 2008/08/24 06:21:00 kientzle Exp $"); + +DEFINE_TEST(test_option_y) +{ + char *p; + int r; + size_t s; + + /* Create a file. */ + assertMakeFile("f", 0644, "a"); + + /* Archive it with bzip2 compression. */ + r = systemf("echo f | %s -oy >archive.out 2>archive.err", + testprog); + p = slurpfile(&s, "archive.err"); + p[s] = '\0'; + if (r != 0) { + if (strstr(p, "compression not available") != NULL) { + skipping("This version of bsdcpio was compiled " + "without bzip2 support"); + return; + } + failure("-y option is broken"); + assertEqualInt(r, 0); + return; + } + assertTextFileContents("1 block\n", "archive.err"); + /* Check that the archive file has a bzip2 signature. */ + p = slurpfile(&s, "archive.out"); + assert(s > 2); + assertEqualMem(p, "BZh9", 4); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_option_z.c b/external/bsd/libarchive/dist/cpio/test/test_option_z.c new file mode 100644 index 000000000..91d37ac19 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_option_z.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +DEFINE_TEST(test_option_z) +{ + char *p; + int r; + size_t s; + + /* Create a file. */ + assertMakeFile("f", 0644, "a"); + + /* Archive it with gzip compression. */ + r = systemf("echo f | %s -oz >archive.out 2>archive.err", + testprog); + p = slurpfile(&s, "archive.err"); + p[s] = '\0'; + if (r != 0) { + if (strstr(p, "compression not available") != NULL) { + skipping("This version of bsdcpio was compiled " + "without gzip support"); + return; + } + failure("-z option is broken"); + assertEqualInt(r, 0); + return; + } + /* Check that the archive file has a gzip signature. */ + p = slurpfile(&s, "archive.out"); + assert(s > 4); + assertEqualMem(p, "\x1f\x8b\x08\x00", 4); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_owner_parse.c b/external/bsd/libarchive/dist/cpio/test/test_owner_parse.c new file mode 100644 index 000000000..d07724e0e --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_owner_parse.c @@ -0,0 +1,122 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +#include "../cpio.h" +#include "err.h" + +#if !defined(_WIN32) +#define ROOT "root" +static int root_uids[] = { 0 }; +/* Solaris 9 root has gid 1 (other) */ +static int root_gids[] = { 0, 1 }; +#elif defined(__CYGWIN__) +/* On cygwin, the Administrator user most likely exists (unless + * it has been renamed or is in a non-English localization), but + * its primary group membership depends on how the user set up + * their /etc/passwd. Likely values are 513 (None), 545 (Users), + * or 544 (Administrators). Just check for one of those... + * TODO: Handle non-English localizations...e.g. French 'Administrateur' + * Use CreateWellKnownSID() and LookupAccountName()? + */ +#define ROOT "Administrator" +static int root_uids[] = { 500 }; +static int root_gids[] = { 513, 545, 544 }; +#endif + +#if defined(ROOT) +static int +int_in_list(int i, int *l, size_t n) +{ + while (n-- > 0) + if (*l++ == i) + return (1); + failure("%d", i); + return (0); +} +#endif + +DEFINE_TEST(test_owner_parse) +{ +#if !defined(ROOT) + skipping("No uid/gid configuration for this OS"); +#else + int uid, gid; + + assert(NULL == owner_parse(ROOT, &uid, &gid)); + assert(int_in_list(uid, root_uids, + sizeof(root_uids)/sizeof(root_uids[0]))); + assertEqualInt(-1, gid); + + + assert(NULL == owner_parse(ROOT ":", &uid, &gid)); + assert(int_in_list(uid, root_uids, + sizeof(root_uids)/sizeof(root_uids[0]))); + assert(int_in_list(gid, root_gids, + sizeof(root_gids)/sizeof(root_gids[0]))); + + assert(NULL == owner_parse(ROOT ".", &uid, &gid)); + assert(int_in_list(uid, root_uids, + sizeof(root_uids)/sizeof(root_uids[0]))); + assert(int_in_list(gid, root_gids, + sizeof(root_gids)/sizeof(root_gids[0]))); + + assert(NULL == owner_parse("111", &uid, &gid)); + assertEqualInt(111, uid); + assertEqualInt(-1, gid); + + assert(NULL == owner_parse("112:", &uid, &gid)); + assertEqualInt(112, uid); + /* Can't assert gid, since we don't know gid for user #112. */ + + assert(NULL == owner_parse("113.", &uid, &gid)); + assertEqualInt(113, uid); + /* Can't assert gid, since we don't know gid for user #113. */ + + assert(NULL == owner_parse(":114", &uid, &gid)); + assertEqualInt(-1, uid); + assertEqualInt(114, gid); + + assert(NULL == owner_parse(".115", &uid, &gid)); + assertEqualInt(-1, uid); + assertEqualInt(115, gid); + + assert(NULL == owner_parse("116:117", &uid, &gid)); + assertEqualInt(116, uid); + assertEqualInt(117, gid); + + /* + * TODO: Lookup current user/group name, build strings and + * use those to verify username/groupname lookups for ordinary + * users. + */ + + assert(NULL != owner_parse(":nonexistentgroup", &uid, &gid)); + assert(NULL != owner_parse(ROOT ":nonexistentgroup", &uid, &gid)); + assert(NULL != + owner_parse("nonexistentuser:nonexistentgroup", &uid, &gid)); +#endif +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_passthrough_dotdot.c b/external/bsd/libarchive/dist/cpio/test/test_passthrough_dotdot.c new file mode 100644 index 000000000..bb04341a4 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_passthrough_dotdot.c @@ -0,0 +1,76 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_passthrough_dotdot.c,v 1.4 2008/08/24 06:21:00 kientzle Exp $"); + +/* + * Verify that "cpio -p .." works. + */ + +DEFINE_TEST(test_passthrough_dotdot) +{ + int r; + FILE *filelist; + + assertUmask(0); + + /* + * Create an assortment of files on disk. + */ + filelist = fopen("filelist", "w"); + + /* Directory. */ + assertMakeDir("dir", 0755); + assertChdir("dir"); + + fprintf(filelist, ".\n"); + + /* File with 10 bytes content. */ + assertMakeFile("file", 0642, "1234567890"); + fprintf(filelist, "file\n"); + + /* All done. */ + fclose(filelist); + + + /* + * Use cpio passthrough mode to copy files to another directory. + */ + r = systemf("%s -pdvm .. <../filelist >../stdout 2>../stderr", + testprog); + failure("Error invoking %s -pd ..", testprog); + assertEqualInt(r, 0); + + assertChdir(".."); + + /* Verify stderr and stdout. */ + assertTextFileContents("../.\n../file\n1 block\n", "stderr"); + assertEmptyFile("stdout"); + + /* Regular file. */ + assertIsReg("file", 0642); + assertFileSize("file", 10); + assertFileNLinks("file", 1); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_passthrough_reverse.c b/external/bsd/libarchive/dist/cpio/test/test_passthrough_reverse.c new file mode 100644 index 000000000..674e52bc0 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_passthrough_reverse.c @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_passthrough_reverse.c,v 1.2 2008/08/24 06:21:00 kientzle Exp $"); + +/* + * As reported by Bernd Walter: Some people are in the habit of + * using "find -d" to generate a list for cpio -p because that + * copies the top-level dir last, which preserves owner and mode + * information. That's not necessary for bsdcpio (libarchive defers + * restoring directory information), but bsdcpio should still generate + * the correct results with this usage. + */ + +DEFINE_TEST(test_passthrough_reverse) +{ + int r; + FILE *filelist; + + assertUmask(0); + + /* + * Create an assortment of files on disk. + */ + filelist = fopen("filelist", "w"); + + /* Directory. */ + assertMakeDir("dir", 0743); + + /* File with 10 bytes content. */ + assertMakeFile("dir/file", 0644, "1234567890"); + fprintf(filelist, "dir/file\n"); + + /* Write dir last. */ + fprintf(filelist, "dir\n"); + + /* All done. */ + fclose(filelist); + + + /* + * Use cpio passthrough mode to copy files to another directory. + */ + r = systemf("%s -pdvm out stdout 2>stderr", testprog); + failure("Error invoking %s -pd out", testprog); + assertEqualInt(r, 0); + + assertChdir("out"); + + /* Verify stderr and stdout. */ + assertTextFileContents("out/dir/file\nout/dir\n1 block\n", + "../stderr"); + assertEmptyFile("../stdout"); + + /* dir */ + assertIsDir("dir", 0743); + + + /* Regular file. */ + assertIsReg("dir/file", 0644); + assertFileSize("dir/file", 10); + assertFileNLinks("dir/file", 1); +} diff --git a/external/bsd/libarchive/dist/cpio/test/test_pathmatch.c b/external/bsd/libarchive/dist/cpio/test/test_pathmatch.c new file mode 100644 index 000000000..177c2bcc4 --- /dev/null +++ b/external/bsd/libarchive/dist/cpio/test/test_pathmatch.c @@ -0,0 +1,243 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +#include "pathmatch.h" + +/* + * Verify that the pattern matcher implements the wildcard logic specified + * in SUSv2 for the cpio command. This is essentially the + * shell glob syntax: + * * - matches any sequence of chars, including '/' + * ? - matches any single char, including '/' + * [...] - matches any of a set of chars, '-' specifies a range, + * initial '!' is undefined + * + * The specification in SUSv2 is a bit incomplete, I assume the following: + * Trailing '-' in [...] is not special. + * + * TODO: Figure out if there's a good way to extend this to handle + * Windows paths that use '\' as a path separator. + */ + +DEFINE_TEST(test_pathmatch) +{ + assertEqualInt(1, lafe_pathmatch("a/b/c", "a/b/c", 0)); + assertEqualInt(0, lafe_pathmatch("a/b/", "a/b/c", 0)); + assertEqualInt(0, lafe_pathmatch("a/b", "a/b/c", 0)); + assertEqualInt(0, lafe_pathmatch("a/b/c", "a/b/", 0)); + assertEqualInt(0, lafe_pathmatch("a/b/c", "a/b", 0)); + + /* Empty pattern only matches empty string. */ + assertEqualInt(1, lafe_pathmatch("","", 0)); + assertEqualInt(0, lafe_pathmatch("","a", 0)); + assertEqualInt(1, lafe_pathmatch("*","", 0)); + assertEqualInt(1, lafe_pathmatch("*","a", 0)); + assertEqualInt(1, lafe_pathmatch("*","abcd", 0)); + /* SUSv2: * matches / */ + assertEqualInt(1, lafe_pathmatch("*","abcd/efgh/ijkl", 0)); + assertEqualInt(1, lafe_pathmatch("abcd*efgh/ijkl","abcd/efgh/ijkl", 0)); + assertEqualInt(1, lafe_pathmatch("abcd***efgh/ijkl","abcd/efgh/ijkl", 0)); + assertEqualInt(1, lafe_pathmatch("abcd***/efgh/ijkl","abcd/efgh/ijkl", 0)); + assertEqualInt(0, lafe_pathmatch("?", "", 0)); + assertEqualInt(0, lafe_pathmatch("?", "\0", 0)); + assertEqualInt(1, lafe_pathmatch("?", "a", 0)); + assertEqualInt(0, lafe_pathmatch("?", "ab", 0)); + assertEqualInt(1, lafe_pathmatch("?", ".", 0)); + assertEqualInt(1, lafe_pathmatch("?", "?", 0)); + assertEqualInt(1, lafe_pathmatch("a", "a", 0)); + assertEqualInt(0, lafe_pathmatch("a", "ab", 0)); + assertEqualInt(0, lafe_pathmatch("a", "ab", 0)); + assertEqualInt(1, lafe_pathmatch("a?c", "abc", 0)); + /* SUSv2: ? matches / */ + assertEqualInt(1, lafe_pathmatch("a?c", "a/c", 0)); + assertEqualInt(1, lafe_pathmatch("a?*c*", "a/c", 0)); + assertEqualInt(1, lafe_pathmatch("*a*", "a/c", 0)); + assertEqualInt(1, lafe_pathmatch("*a*", "/a/c", 0)); + assertEqualInt(1, lafe_pathmatch("*a*", "defaaaaaaa", 0)); + assertEqualInt(0, lafe_pathmatch("a*", "defghi", 0)); + assertEqualInt(0, lafe_pathmatch("*a*", "defghi", 0)); + + /* Character classes */ + assertEqualInt(1, lafe_pathmatch("abc[def", "abc[def", 0)); + assertEqualInt(0, lafe_pathmatch("abc[def]", "abc[def", 0)); + assertEqualInt(0, lafe_pathmatch("abc[def", "abcd", 0)); + assertEqualInt(1, lafe_pathmatch("abc[def]", "abcd", 0)); + assertEqualInt(1, lafe_pathmatch("abc[def]", "abce", 0)); + assertEqualInt(1, lafe_pathmatch("abc[def]", "abcf", 0)); + assertEqualInt(0, lafe_pathmatch("abc[def]", "abcg", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d*f]", "abcd", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d*f]", "abc*", 0)); + assertEqualInt(0, lafe_pathmatch("abc[d*f]", "abcdefghi", 0)); + assertEqualInt(0, lafe_pathmatch("abc[d*", "abcdefghi", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d*", "abc[defghi", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-f]", "abcd", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-f]", "abce", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-f]", "abcf", 0)); + assertEqualInt(0, lafe_pathmatch("abc[d-f]", "abcg", 0)); + assertEqualInt(0, lafe_pathmatch("abc[d-fh-k]", "abca", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abcd", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abce", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abcf", 0)); + assertEqualInt(0, lafe_pathmatch("abc[d-fh-k]", "abcg", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abch", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abci", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abcj", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abck", 0)); + assertEqualInt(0, lafe_pathmatch("abc[d-fh-k]", "abcl", 0)); + assertEqualInt(0, lafe_pathmatch("abc[d-fh-k]", "abc-", 0)); + + /* [] matches nothing, [!] is the same as ? */ + assertEqualInt(0, lafe_pathmatch("abc[]efg", "abcdefg", 0)); + assertEqualInt(0, lafe_pathmatch("abc[]efg", "abcqefg", 0)); + assertEqualInt(0, lafe_pathmatch("abc[]efg", "abcefg", 0)); + assertEqualInt(1, lafe_pathmatch("abc[!]efg", "abcdefg", 0)); + assertEqualInt(1, lafe_pathmatch("abc[!]efg", "abcqefg", 0)); + assertEqualInt(0, lafe_pathmatch("abc[!]efg", "abcefg", 0)); + + /* I assume: Trailing '-' is non-special. */ + assertEqualInt(0, lafe_pathmatch("abc[d-fh-]", "abcl", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-]", "abch", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-]", "abc-", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-fh-]", "abc-", 0)); + + /* ']' can be backslash-quoted within a character class. */ + assertEqualInt(1, lafe_pathmatch("abc[\\]]", "abc]", 0)); + assertEqualInt(1, lafe_pathmatch("abc[\\]d]", "abc]", 0)); + assertEqualInt(1, lafe_pathmatch("abc[\\]d]", "abcd", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d\\]]", "abc]", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d\\]]", "abcd", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d]e]", "abcde]", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d\\]e]", "abc]", 0)); + assertEqualInt(0, lafe_pathmatch("abc[d\\]e]", "abcd]e", 0)); + assertEqualInt(0, lafe_pathmatch("abc[d]e]", "abc]", 0)); + + /* backslash-quoted chars can appear as either end of a range. */ + assertEqualInt(1, lafe_pathmatch("abc[\\d-f]gh", "abcegh", 0)); + assertEqualInt(0, lafe_pathmatch("abc[\\d-f]gh", "abcggh", 0)); + assertEqualInt(0, lafe_pathmatch("abc[\\d-f]gh", "abc\\gh", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d-\\f]gh", "abcegh", 0)); + assertEqualInt(1, lafe_pathmatch("abc[\\d-\\f]gh", "abcegh", 0)); + assertEqualInt(1, lafe_pathmatch("abc[\\d-\\f]gh", "abcegh", 0)); + /* backslash-quoted '-' isn't special. */ + assertEqualInt(0, lafe_pathmatch("abc[d\\-f]gh", "abcegh", 0)); + assertEqualInt(1, lafe_pathmatch("abc[d\\-f]gh", "abc-gh", 0)); + + /* Leading '!' negates a character class. */ + assertEqualInt(0, lafe_pathmatch("abc[!d]", "abcd", 0)); + assertEqualInt(1, lafe_pathmatch("abc[!d]", "abce", 0)); + assertEqualInt(1, lafe_pathmatch("abc[!d]", "abcc", 0)); + assertEqualInt(0, lafe_pathmatch("abc[!d-z]", "abcq", 0)); + assertEqualInt(1, lafe_pathmatch("abc[!d-gi-z]", "abch", 0)); + assertEqualInt(1, lafe_pathmatch("abc[!fgijkl]", "abch", 0)); + assertEqualInt(0, lafe_pathmatch("abc[!fghijkl]", "abch", 0)); + + /* Backslash quotes next character. */ + assertEqualInt(0, lafe_pathmatch("abc\\[def]", "abc\\d", 0)); + assertEqualInt(1, lafe_pathmatch("abc\\[def]", "abc[def]", 0)); + assertEqualInt(0, lafe_pathmatch("abc\\\\[def]", "abc[def]", 0)); + assertEqualInt(0, lafe_pathmatch("abc\\\\[def]", "abc\\[def]", 0)); + assertEqualInt(1, lafe_pathmatch("abc\\\\[def]", "abc\\d", 0)); + assertEqualInt(1, lafe_pathmatch("abcd\\", "abcd\\", 0)); + assertEqualInt(0, lafe_pathmatch("abcd\\", "abcd\\[", 0)); + assertEqualInt(0, lafe_pathmatch("abcd\\", "abcde", 0)); + assertEqualInt(0, lafe_pathmatch("abcd\\[", "abcd\\", 0)); + + /* + * Because '.' and '/' have special meanings, we can + * identify many equivalent paths even if they're expressed + * differently. (But quoting a character with '\\' suppresses + * special meanings!) + */ + assertEqualInt(0, lafe_pathmatch("a/b/", "a/bc", 0)); + assertEqualInt(1, lafe_pathmatch("a/./b", "a/b", 0)); + assertEqualInt(0, lafe_pathmatch("a\\/./b", "a/b", 0)); + assertEqualInt(0, lafe_pathmatch("a/\\./b", "a/b", 0)); + assertEqualInt(0, lafe_pathmatch("a/.\\/b", "a/b", 0)); + assertEqualInt(0, lafe_pathmatch("a\\/\\.\\/b", "a/b", 0)); + assertEqualInt(1, lafe_pathmatch("./abc/./def/", "abc/def/", 0)); + assertEqualInt(1, lafe_pathmatch("abc/def", "./././abc/./def", 0)); + assertEqualInt(1, lafe_pathmatch("abc/def/././//", "./././abc/./def/", 0)); + assertEqualInt(1, lafe_pathmatch(".////abc/.//def", "./././abc/./def", 0)); + assertEqualInt(1, lafe_pathmatch("./abc?def/", "abc/def/", 0)); + failure("\"?./\" is not the same as \"/./\""); + assertEqualInt(0, lafe_pathmatch("./abc?./def/", "abc/def/", 0)); + failure("Trailing '/' should match no trailing '/'"); + assertEqualInt(1, lafe_pathmatch("./abc/./def/", "abc/def", 0)); + failure("Trailing '/./' is still the same directory."); + assertEqualInt(1, lafe_pathmatch("./abc/./def/./", "abc/def", 0)); + failure("Trailing '/.' is still the same directory."); + assertEqualInt(1, lafe_pathmatch("./abc/./def/.", "abc/def", 0)); + assertEqualInt(1, lafe_pathmatch("./abc/./def", "abc/def/", 0)); + failure("Trailing '/./' is still the same directory."); + assertEqualInt(1, lafe_pathmatch("./abc/./def", "abc/def/./", 0)); + failure("Trailing '/.' is still the same directory."); + assertEqualInt(1, lafe_pathmatch("./abc*/./def", "abc/def/.", 0)); + + /* Matches not anchored at beginning. */ + assertEqualInt(0, + lafe_pathmatch("bcd", "abcd", PATHMATCH_NO_ANCHOR_START)); + assertEqualInt(1, + lafe_pathmatch("abcd", "abcd", PATHMATCH_NO_ANCHOR_START)); + assertEqualInt(0, + lafe_pathmatch("^bcd", "abcd", PATHMATCH_NO_ANCHOR_START)); + assertEqualInt(1, + lafe_pathmatch("b/c/d", "a/b/c/d", PATHMATCH_NO_ANCHOR_START)); + assertEqualInt(0, + lafe_pathmatch("b/c", "a/b/c/d", PATHMATCH_NO_ANCHOR_START)); + assertEqualInt(0, + lafe_pathmatch("^b/c", "a/b/c/d", PATHMATCH_NO_ANCHOR_START)); + + /* Matches not anchored at end. */ + assertEqualInt(0, + lafe_pathmatch("bcd", "abcd", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + lafe_pathmatch("abcd", "abcd", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + lafe_pathmatch("abcd", "abcd/", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + lafe_pathmatch("abcd", "abcd/.", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(0, + lafe_pathmatch("abc", "abcd", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + lafe_pathmatch("a/b/c", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(0, + lafe_pathmatch("a/b/c$", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + lafe_pathmatch("a/b/c$", "a/b/c", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + lafe_pathmatch("a/b/c$", "a/b/c/", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + lafe_pathmatch("a/b/c/", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(0, + lafe_pathmatch("a/b/c/$", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + lafe_pathmatch("a/b/c/$", "a/b/c/", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + lafe_pathmatch("a/b/c/$", "a/b/c", PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(0, + lafe_pathmatch("b/c", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); +} diff --git a/lib/libarchive/archive.h b/external/bsd/libarchive/dist/libarchive/archive.h similarity index 97% rename from lib/libarchive/archive.h rename to external/bsd/libarchive/dist/libarchive/archive.h index 9e585bab8..211b73ce6 100644 --- a/lib/libarchive/archive.h +++ b/external/bsd/libarchive/dist/libarchive/archive.h @@ -66,11 +66,6 @@ # define __LA_UID_T short # define __LA_GID_T short # endif -#elif defined(__minix) -#include /* ssize_t, uid_t, and gid_t */ -#define __LA_SSIZE_T ssize_t -#define __LA_UID_T uid_t -#define __LA_GID_T gid_t #else #include /* ssize_t, uid_t, and gid_t */ #define __LA_INT64_T int64_t @@ -134,13 +129,13 @@ extern "C" { * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000) * #endif */ -#define ARCHIVE_VERSION_NUMBER 2008003 +#define ARCHIVE_VERSION_NUMBER 2008004 __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_STRING "libarchive 2.8.3" +#define ARCHIVE_VERSION_STRING "libarchive 2.8.4" __LA_DECL const char * archive_version_string(void); #if ARCHIVE_VERSION_NUMBER < 3000000 @@ -268,14 +263,12 @@ typedef int archive_close_callback(struct archive *, void *_client_data); * entry to be in a different format.) */ #define ARCHIVE_FORMAT_BASE_MASK 0xff0000 -#ifndef __minix #define ARCHIVE_FORMAT_CPIO 0x10000 #define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1) #define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2) #define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3) #define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4) #define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5) -#endif #define ARCHIVE_FORMAT_SHAR 0x20000 #define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1) #define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2) @@ -328,17 +321,13 @@ __LA_DECL int archive_read_support_compression_program_signature (struct archive *, const char *, const void * /* match */, size_t); -#ifndef __minix __LA_DECL int archive_read_support_compression_rpm(struct archive *); -#endif __LA_DECL int archive_read_support_compression_uu(struct archive *); __LA_DECL int archive_read_support_compression_xz(struct archive *); __LA_DECL int archive_read_support_format_all(struct archive *); __LA_DECL int archive_read_support_format_ar(struct archive *); -#ifndef __minix __LA_DECL int archive_read_support_format_cpio(struct archive *); -#endif __LA_DECL int archive_read_support_format_empty(struct archive *); __LA_DECL int archive_read_support_format_gnutar(struct archive *); __LA_DECL int archive_read_support_format_iso9660(struct archive *); @@ -393,12 +382,7 @@ __LA_DECL int archive_read_next_header2(struct archive *, * Retrieve the byte offset in UNCOMPRESSED data where last-read * header started. */ -#ifndef __minix __LA_DECL __LA_INT64_T archive_read_header_position(struct archive *); -#else -__LA_DECL off_t archive_read_header_position(struct archive *); -#endif - /* Read data from the body of an entry. Similar to read(2). */ __LA_DECL __LA_SSIZE_T archive_read_data(struct archive *, @@ -553,10 +537,8 @@ __LA_DECL int archive_write_set_format_by_name(struct archive *, /* To minimize link pollution, use one or more of the following. */ __LA_DECL int archive_write_set_format_ar_bsd(struct archive *); __LA_DECL int archive_write_set_format_ar_svr4(struct archive *); -#ifndef __minix __LA_DECL int archive_write_set_format_cpio(struct archive *); __LA_DECL int archive_write_set_format_cpio_newc(struct archive *); -#endif __LA_DECL int archive_write_set_format_mtree(struct archive *); /* TODO: int archive_write_set_format_old_tar(struct archive *); */ __LA_DECL int archive_write_set_format_pax(struct archive *); @@ -724,17 +706,10 @@ __LA_DECL int archive_read_disk_set_uname_lookup(struct archive *, * Accessor functions to read/set various information in * the struct archive object: */ -#ifndef __minix /* Bytes written after compression or read before decompression. */ __LA_DECL __LA_INT64_T archive_position_compressed(struct archive *); /* Bytes written to compressor or read from decompressor. */ __LA_DECL __LA_INT64_T archive_position_uncompressed(struct archive *); -#else -/* Bytes written after compression or read before decompression. */ -__LA_DECL off_t archive_position_compressed(struct archive *); -/* Bytes written to compressor or read from decompressor. */ -__LA_DECL off_t archive_position_uncompressed(struct archive *); -#endif __LA_DECL const char *archive_compression_name(struct archive *); __LA_DECL int archive_compression(struct archive *); @@ -744,7 +719,8 @@ __LA_DECL const char *archive_format_name(struct archive *); __LA_DECL int archive_format(struct archive *); __LA_DECL void archive_clear_error(struct archive *); __LA_DECL void archive_set_error(struct archive *, int _err, - const char *fmt, ...); + const char *fmt, ...) + __attribute__((__format__(__printf__,3,4))); __LA_DECL void archive_copy_error(struct archive *dest, struct archive *src); __LA_DECL int archive_file_count(struct archive *); diff --git a/lib/libarchive/archive_check_magic.c b/external/bsd/libarchive/dist/libarchive/archive_check_magic.c similarity index 99% rename from lib/libarchive/archive_check_magic.c rename to external/bsd/libarchive/dist/libarchive/archive_check_magic.c index e27e5d827..a3e44f1c0 100644 --- a/lib/libarchive/archive_check_magic.c +++ b/external/bsd/libarchive/dist/libarchive/archive_check_magic.c @@ -62,7 +62,7 @@ errmsg(const char *m) } } -static void +__dead static void diediedie(void) { #if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) diff --git a/lib/libarchive/archive_crc32.h b/external/bsd/libarchive/dist/libarchive/archive_crc32.h similarity index 100% rename from lib/libarchive/archive_crc32.h rename to external/bsd/libarchive/dist/libarchive/archive_crc32.h diff --git a/lib/libarchive/archive_endian.h b/external/bsd/libarchive/dist/libarchive/archive_endian.h similarity index 82% rename from lib/libarchive/archive_endian.h rename to external/bsd/libarchive/dist/libarchive/archive_endian.h index 30577d1f5..edc90ee6a 100644 --- a/lib/libarchive/archive_endian.h +++ b/external/bsd/libarchive/dist/libarchive/archive_endian.h @@ -45,16 +45,12 @@ * - SGI MIPSpro * - Microsoft Visual C++ 6.0 (supposedly newer versions too) */ -#if defined(__WATCOMC__) || defined(__sgi) || defined(__hpux) || defined(__BORLANDC__) || defined(__ACK__) +#if defined(__WATCOMC__) || defined(__sgi) || defined(__hpux) || defined(__BORLANDC__) #define inline #elif defined(_MSC_VER) #define inline __inline #endif -#ifdef __minix -#include -#endif - /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ static inline uint16_t @@ -73,7 +69,6 @@ archive_be32dec(const void *pp) return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); } -#ifndef __minix static inline uint64_t archive_be64dec(const void *pp) { @@ -81,15 +76,6 @@ archive_be64dec(const void *pp) return (((uint64_t)archive_be32dec(p) << 32) | archive_be32dec(p + 4)); } -#else -static inline u64_t -archive_be64dec(const void *pp) -{ - unsigned char const *p = (unsigned char const *)pp; - - return make64(archive_be32dec(p + 4), archive_be32dec(p)); -} -#endif static inline uint16_t archive_le16dec(const void *pp) @@ -107,7 +93,6 @@ archive_le32dec(const void *pp) return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); } -#ifndef __minix static inline uint64_t archive_le64dec(const void *pp) { @@ -115,15 +100,6 @@ archive_le64dec(const void *pp) return (((uint64_t)archive_le32dec(p + 4) << 32) | archive_le32dec(p)); } -#else -static inline u64_t -archive_le64dec(const void *pp) -{ - unsigned char const *p = (unsigned char const *)pp; - - return make64(archive_le32dec(p), archive_le32dec(p + 4)); -} -#endif static inline void archive_be16enc(void *pp, uint16_t u) @@ -145,7 +121,6 @@ archive_be32enc(void *pp, uint32_t u) p[3] = u & 0xff; } -#ifndef __minix static inline void archive_be64enc(void *pp, uint64_t u) { @@ -154,16 +129,6 @@ archive_be64enc(void *pp, uint64_t u) archive_be32enc(p, u >> 32); archive_be32enc(p + 4, u & 0xffffffff); } -#else -static inline void -archive_be64enc(void *pp, u64_t u) -{ - unsigned char *p = (unsigned char *)pp; - - archive_be32enc(p, ex64hi(u)); - archive_be32enc(p + 4, ex64lo(u)); -} -#endif static inline void archive_le16enc(void *pp, uint16_t u) @@ -185,7 +150,6 @@ archive_le32enc(void *pp, uint32_t u) p[3] = (u >> 24) & 0xff; } -#ifndef __minix static inline void archive_le64enc(void *pp, uint64_t u) { @@ -194,14 +158,5 @@ archive_le64enc(void *pp, uint64_t u) archive_le32enc(p, u & 0xffffffff); archive_le32enc(p + 4, u >> 32); } -#else -static inline void -archive_le64enc(void *pp, u64_t u) -{ - unsigned char *p = (unsigned char *)pp; - archive_le32enc(p, ex64lo(u)); - archive_le32enc(p + 4, ex64hi(u)); -} -#endif #endif diff --git a/lib/libarchive/archive_entry.3 b/external/bsd/libarchive/dist/libarchive/archive_entry.3 similarity index 99% rename from lib/libarchive/archive_entry.3 rename to external/bsd/libarchive/dist/libarchive/archive_entry.3 index 9ceb18b7a..ae2aa192c 100644 --- a/lib/libarchive/archive_entry.3 +++ b/external/bsd/libarchive/dist/libarchive/archive_entry.3 @@ -336,11 +336,11 @@ Returns the specified data. In the case of strings, a const-qualified pointer to the string is returned. .El -String data can be set or accessed as wide character strings +String data can be set or accessed as wide-character strings or normal .Va char strings. -The functions that use wide character strings are suffixed with +The functions that use wide-character strings are suffixed with .Cm _w . Note that these are different representations of the same data: For example, if you store a narrow string and read the corresponding diff --git a/lib/libarchive/archive_entry.c b/external/bsd/libarchive/dist/libarchive/archive_entry.c similarity index 99% rename from lib/libarchive/archive_entry.c rename to external/bsd/libarchive/dist/libarchive/archive_entry.c index a2364c05a..f734b8c4f 100644 --- a/lib/libarchive/archive_entry.c +++ b/external/bsd/libarchive/dist/libarchive/archive_entry.c @@ -625,14 +625,11 @@ archive_entry_ino(struct archive_entry *entry) return (entry->ae_stat.aest_ino); } -#ifndef __minix int64_t archive_entry_ino64(struct archive_entry *entry) { return (entry->ae_stat.aest_ino); } -#endif - mode_t archive_entry_mode(struct archive_entry *entry) @@ -704,19 +701,11 @@ archive_entry_rdevminor(struct archive_entry *entry) return minor(entry->ae_stat.aest_rdev); } -#ifndef __minix int64_t archive_entry_size(struct archive_entry *entry) { return (entry->ae_stat.aest_size); } -#else -ssize_t -archive_entry_size(struct archive_entry *entry) -{ - return (entry->ae_stat.aest_size); -} -#endif int archive_entry_size_is_set(struct archive_entry *entry) @@ -841,14 +830,12 @@ archive_entry_set_ino(struct archive_entry *entry, unsigned long ino) entry->ae_stat.aest_ino = ino; } -#ifndef __minix void archive_entry_set_ino64(struct archive_entry *entry, int64_t ino) { entry->stat_valid = 0; entry->ae_stat.aest_ino = ino; } -#endif void archive_entry_set_hardlink(struct archive_entry *entry, const char *target) @@ -1087,7 +1074,6 @@ archive_entry_set_rdevminor(struct archive_entry *entry, dev_t m) entry->ae_stat.aest_rdevminor = m; } -#ifndef __minix void archive_entry_set_size(struct archive_entry *entry, int64_t s) { @@ -1095,15 +1081,6 @@ archive_entry_set_size(struct archive_entry *entry, int64_t s) entry->ae_stat.aest_size = s; entry->ae_set |= AE_SET_SIZE; } -#else -void -archive_entry_set_size(struct archive_entry *entry, ssize_t s) -{ - entry->stat_valid = 0; - entry->ae_stat.aest_size = s; - entry->ae_set |= AE_SET_SIZE; -} -#endif void archive_entry_unset_size(struct archive_entry *entry) diff --git a/lib/libarchive/archive_entry.h b/external/bsd/libarchive/dist/libarchive/archive_entry.h similarity index 98% rename from lib/libarchive/archive_entry.h rename to external/bsd/libarchive/dist/libarchive/archive_entry.h index 12b224416..d5728179e 100644 --- a/lib/libarchive/archive_entry.h +++ b/external/bsd/libarchive/dist/libarchive/archive_entry.h @@ -59,11 +59,6 @@ # define __LA_DEV_T unsigned int # define __LA_MODE_T unsigned short # endif -#elif defined(__minix) -#define __LA_UID_T uid_t -#define __LA_GID_T gid_t -#define __LA_DEV_T dev_t -#define __LA_MODE_T mode_t #else #include #define __LA_INT64_T int64_t @@ -210,9 +205,7 @@ __LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *); __LA_DECL const char *archive_entry_hardlink(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *); __LA_DECL __LA_INO_T archive_entry_ino(struct archive_entry *); -#ifndef __minix __LA_DECL __LA_INT64_T archive_entry_ino64(struct archive_entry *); -#endif __LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *); __LA_DECL time_t archive_entry_mtime(struct archive_entry *); __LA_DECL long archive_entry_mtime_nsec(struct archive_entry *); @@ -224,11 +217,7 @@ __LA_DECL dev_t archive_entry_rdev(struct archive_entry *); __LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *); __LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *); __LA_DECL const char *archive_entry_sourcepath(struct archive_entry *); -#ifndef __minix __LA_DECL __LA_INT64_T archive_entry_size(struct archive_entry *); -#else -__LA_DECL ssize_t archive_entry_size(struct archive_entry *); -#endif __LA_DECL int archive_entry_size_is_set(struct archive_entry *); __LA_DECL const char *archive_entry_strmode(struct archive_entry *); __LA_DECL const char *archive_entry_symlink(struct archive_entry *); @@ -285,9 +274,7 @@ __LA_DECL void archive_entry_set_ino(struct archive_entry *, __LA_INT64_T); #else __LA_DECL void archive_entry_set_ino(struct archive_entry *, unsigned long); #endif -#ifndef __minix __LA_DECL void archive_entry_set_ino64(struct archive_entry *, __LA_INT64_T); -#endif __LA_DECL void archive_entry_set_link(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *); @@ -304,11 +291,7 @@ __LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T); __LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t); __LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t); __LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t); -#ifndef __minix __LA_DECL void archive_entry_set_size(struct archive_entry *, __LA_INT64_T); -#else -__LA_DECL void archive_entry_set_size(struct archive_entry *, ssize_t); -#endif __LA_DECL void archive_entry_unset_size(struct archive_entry *); __LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *); __LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *); diff --git a/lib/libarchive/archive_entry_copy_bhfi.c b/external/bsd/libarchive/dist/libarchive/archive_entry_copy_bhfi.c similarity index 100% rename from lib/libarchive/archive_entry_copy_bhfi.c rename to external/bsd/libarchive/dist/libarchive/archive_entry_copy_bhfi.c diff --git a/lib/libarchive/archive_entry_copy_stat.c b/external/bsd/libarchive/dist/libarchive/archive_entry_copy_stat.c similarity index 100% rename from lib/libarchive/archive_entry_copy_stat.c rename to external/bsd/libarchive/dist/libarchive/archive_entry_copy_stat.c diff --git a/lib/libarchive/archive_entry_link_resolver.c b/external/bsd/libarchive/dist/libarchive/archive_entry_link_resolver.c similarity index 96% rename from lib/libarchive/archive_entry_link_resolver.c rename to external/bsd/libarchive/dist/libarchive/archive_entry_link_resolver.c index 808d0a6bf..3b13e19c8 100644 --- a/lib/libarchive/archive_entry_link_resolver.c +++ b/external/bsd/libarchive/dist/libarchive/archive_entry_link_resolver.c @@ -61,10 +61,8 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_link_resolver.c 201100 200 /* Users pass us a format code, we translate that into a strategy here. */ #define ARCHIVE_ENTRY_LINKIFY_LIKE_TAR 0 #define ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE 1 -#ifndef __minix #define ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO 2 #define ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO 3 -#endif /* Initial size of link cache. */ #define links_cache_initial_size 1024 @@ -122,7 +120,6 @@ archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *res, int fmtbase = fmt & ARCHIVE_FORMAT_BASE_MASK; switch (fmtbase) { -#ifndef __minix case ARCHIVE_FORMAT_CPIO: switch (fmt) { case ARCHIVE_FORMAT_CPIO_SVR4_NOCRC: @@ -134,7 +131,6 @@ archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *res, break; } break; -#endif case ARCHIVE_FORMAT_MTREE: res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE; break; @@ -169,9 +165,7 @@ archive_entry_linkify(struct archive_entry_linkresolver *res, struct archive_entry **e, struct archive_entry **f) { struct links_entry *le; -#ifndef __minix struct archive_entry *t; -#endif *f = NULL; /* Default: Don't return a second entry. */ @@ -211,7 +205,6 @@ archive_entry_linkify(struct archive_entry_linkresolver *res, } else insert_entry(res, *e); return; -#ifndef __minix case ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO: /* This one is trivial. */ return; @@ -245,7 +238,6 @@ archive_entry_linkify(struct archive_entry_linkresolver *res, *e = NULL; } return; -#endif default: break; } @@ -259,11 +251,7 @@ find_entry(struct archive_entry_linkresolver *res, struct links_entry *le; int hash, bucket; dev_t dev; -#ifndef __minix int64_t ino; -#else - int32_t ino; -#endif /* Free a held entry. */ if (res->spare != NULL) { @@ -278,25 +266,15 @@ find_entry(struct archive_entry_linkresolver *res, return (NULL); dev = archive_entry_dev(entry); -#ifndef __minix ino = archive_entry_ino64(entry); -#else - ino = archive_entry_ino(entry); -#endif hash = (int)(dev ^ ino); /* Try to locate this entry in the links cache. */ bucket = hash % res->number_buckets; for (le = res->buckets[bucket]; le != NULL; le = le->next) { -#ifndef __minix if (le->hash == hash && dev == archive_entry_dev(le->canonical) && ino == archive_entry_ino64(le->canonical)) { -#else - if (le->hash == hash - && dev == archive_entry_dev(le->canonical) - && ino == archive_entry_ino(le->canonical)) { -#endif /* * Decrement link count each time and release * the entry if it hits zero. This saves @@ -322,7 +300,6 @@ find_entry(struct archive_entry_linkresolver *res, return (NULL); } - static struct links_entry * next_entry(struct archive_entry_linkresolver *res) { @@ -375,11 +352,7 @@ insert_entry(struct archive_entry_linkresolver *res, if (res->number_entries > res->number_buckets * 2) grow_hash(res); -#ifndef __minix hash = archive_entry_dev(entry) ^ archive_entry_ino64(entry); -#else - hash = ((int)archive_entry_dev(entry)) ^ ((int)archive_entry_ino(entry)); -#endif bucket = hash % res->number_buckets; /* If we could allocate the entry, record it. */ diff --git a/lib/libarchive/archive_entry_private.h b/external/bsd/libarchive/dist/libarchive/archive_entry_private.h similarity index 94% rename from lib/libarchive/archive_entry_private.h rename to external/bsd/libarchive/dist/libarchive/archive_entry_private.h index 75df4a5e8..5ab4f75f0 100644 --- a/lib/libarchive/archive_entry_private.h +++ b/external/bsd/libarchive/dist/libarchive/archive_entry_private.h @@ -110,43 +110,19 @@ struct archive_entry { int stat_valid; /* Set to 0 whenever a field in aest changes. */ struct aest { -#ifndef __minix - uint64_t aest_atime; -#else - time_t aest_atime; -#endif + int64_t aest_atime; uint32_t aest_atime_nsec; -#ifndef __minix int64_t aest_ctime; -#else - time_t aest_ctime; -#endif uint32_t aest_ctime_nsec; -#ifndef __minix int64_t aest_mtime; -#else - time_t aest_mtime; -#endif uint32_t aest_mtime_nsec; -#ifndef __minix int64_t aest_birthtime; -#else - time_t aest_birthtime; -#endif uint32_t aest_birthtime_nsec; gid_t aest_gid; -#ifndef __minix int64_t aest_ino; -#else - ino_t aest_ino; -#endif mode_t aest_mode; uint32_t aest_nlink; -#ifndef __minix uint64_t aest_size; -#else - size_t aest_size; -#endif uid_t aest_uid; /* * Because converting between device codes and diff --git a/lib/libarchive/archive_entry_stat.c b/external/bsd/libarchive/dist/libarchive/archive_entry_stat.c similarity index 98% rename from lib/libarchive/archive_entry_stat.c rename to external/bsd/libarchive/dist/libarchive/archive_entry_stat.c index 13371566d..ad772c956 100644 --- a/lib/libarchive/archive_entry_stat.c +++ b/external/bsd/libarchive/dist/libarchive/archive_entry_stat.c @@ -72,12 +72,7 @@ archive_entry_stat(struct archive_entry *entry) st->st_dev = archive_entry_dev(entry); st->st_gid = archive_entry_gid(entry); st->st_uid = archive_entry_uid(entry); -#ifndef __minix st->st_ino = archive_entry_ino64(entry); -#else - st->st_ino = archive_entry_ino(entry); -#endif - st->st_nlink = archive_entry_nlink(entry); st->st_rdev = archive_entry_rdev(entry); st->st_size = archive_entry_size(entry); diff --git a/lib/libarchive/archive_entry_strmode.c b/external/bsd/libarchive/dist/libarchive/archive_entry_strmode.c similarity index 100% rename from lib/libarchive/archive_entry_strmode.c rename to external/bsd/libarchive/dist/libarchive/archive_entry_strmode.c diff --git a/lib/libarchive/archive_entry_xattr.c b/external/bsd/libarchive/dist/libarchive/archive_entry_xattr.c similarity index 100% rename from lib/libarchive/archive_entry_xattr.c rename to external/bsd/libarchive/dist/libarchive/archive_entry_xattr.c diff --git a/lib/libarchive/archive_hash.h b/external/bsd/libarchive/dist/libarchive/archive_hash.h similarity index 52% rename from lib/libarchive/archive_hash.h rename to external/bsd/libarchive/dist/libarchive/archive_hash.h index 1a3b3344d..b180da671 100644 --- a/lib/libarchive/archive_hash.h +++ b/external/bsd/libarchive/dist/libarchive/archive_hash.h @@ -29,6 +29,10 @@ #error This header is only to be used internally to libarchive. #endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif + /* * Hash function support in various Operating Systems: * @@ -44,40 +48,68 @@ * - MD5 and SHA1 in libmd: without _ after algorithm name * - SHA256: with _ after algorithm name * + * Mac OS X (10.4 and later): + * - MD5, SHA1 and SHA2 in libSystem: with CC_ prefix and _ after algorithm name + * * OpenSSL: * - MD5, SHA1 and SHA2 in libcrypto: with _ after algorithm name + * + * Windows: + * - MD5, SHA1 and SHA2 in archive_windows.c: without algorithm name + * and with __la_ prefix. */ +#if defined(ARCHIVE_HASH_MD5_WIN) ||\ + defined(ARCHIVE_HASH_SHA1_WIN) || defined(ARCHIVE_HASH_SHA256_WIN) ||\ + defined(ARCHIVE_HASH_SHA384_WIN) || defined(ARCHIVE_HASH_SHA512_WIN) +#include +typedef struct { + int valid; + HCRYPTPROV cryptProv; + HCRYPTHASH hash; +} Digest_CTX; +extern void __la_hash_Init(Digest_CTX *, ALG_ID); +extern void __la_hash_Final(unsigned char *, size_t, Digest_CTX *); +extern void __la_hash_Update(Digest_CTX *, const unsigned char *, size_t); +#endif -#if defined(HAVE_MD5_H) && defined(HAVE_MD5INIT) +#if defined(ARCHIVE_HASH_MD5_LIBC) # include # define ARCHIVE_HAS_MD5 typedef MD5_CTX archive_md5_ctx; # define archive_md5_init(ctx) MD5Init(ctx) # define archive_md5_final(ctx, buf) MD5Final(buf, ctx) # define archive_md5_update(ctx, buf, n) MD5Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_MD5_H) +#elif defined(ARCHIVE_HASH_MD5_LIBSYSTEM) +# include +# define ARCHIVE_HAS_MD5 +typedef CC_MD5_CTX archive_md5_ctx; +# define archive_md5_init(ctx) CC_MD5_Init(ctx) +# define archive_md5_final(ctx, buf) CC_MD5_Final(buf, ctx) +# define archive_md5_update(ctx, buf, n) CC_MD5_Update(ctx, buf, n) +#elif defined(ARCHIVE_HASH_MD5_OPENSSL) # include # define ARCHIVE_HAS_MD5 typedef MD5_CTX archive_md5_ctx; # define archive_md5_init(ctx) MD5_Init(ctx) # define archive_md5_final(ctx, buf) MD5_Final(buf, ctx) # define archive_md5_update(ctx, buf, n) MD5_Update(ctx, buf, n) -#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_MD5) +#elif defined(ARCHIVE_HASH_MD5_WIN) # define ARCHIVE_HAS_MD5 -typedef MD5_CTX archive_md5_ctx; -# define archive_md5_init(ctx) MD5_Init(ctx) -# define archive_md5_final(ctx, buf) MD5_Final(buf, ctx) -# define archive_md5_update(ctx, buf, n) MD5_Update(ctx, buf, n) +# define MD5_DIGEST_LENGTH 16 +typedef Digest_CTX archive_md5_ctx; +# define archive_md5_init(ctx) __la_hash_Init(ctx, CALG_MD5) +# define archive_md5_final(ctx, buf) __la_hash_Final(buf, MD5_DIGEST_LENGTH, ctx) +# define archive_md5_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) #endif -#if defined(HAVE_RMD160_H) && defined(HAVE_RMD160INIT) +#if defined(ARCHIVE_HASH_RMD160_LIBC) # include # define ARCHIVE_HAS_RMD160 typedef RMD160_CTX archive_rmd160_ctx; # define archive_rmd160_init(ctx) RMD160Init(ctx) # define archive_rmd160_final(ctx, buf) RMD160Final(buf, ctx) # define archive_rmd160_update(ctx, buf, n) RMD160Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_RIPEMD_H) +#elif defined(ARCHIVE_HASH_RMD160_OPENSSL) # include # define ARCHIVE_HAS_RMD160 typedef RIPEMD160_CTX archive_rmd160_ctx; @@ -86,111 +118,164 @@ typedef RIPEMD160_CTX archive_rmd160_ctx; # define archive_rmd160_update(ctx, buf, n) RIPEMD160_Update(ctx, buf, n) #endif -#if defined(HAVE_SHA1_H) && defined(HAVE_SHA1INIT) +#if defined(ARCHIVE_HASH_SHA1_LIBC) # include # define ARCHIVE_HAS_SHA1 typedef SHA1_CTX archive_sha1_ctx; # define archive_sha1_init(ctx) SHA1Init(ctx) # define archive_sha1_final(ctx, buf) SHA1Final(buf, ctx) # define archive_sha1_update(ctx, buf, n) SHA1Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) +#elif defined(ARCHIVE_HASH_SHA1_LIBSYSTEM) +# include +# define ARCHIVE_HAS_SHA1 +typedef CC_SHA1_CTX archive_sha1_ctx; +# define archive_sha1_init(ctx) CC_SHA1_Init(ctx) +# define archive_sha1_final(ctx, buf) CC_SHA1_Final(buf, ctx) +# define archive_sha1_update(ctx, buf, n) CC_SHA1_Update(ctx, buf, n) +#elif defined(ARCHIVE_HASH_SHA1_OPENSSL) # include # define ARCHIVE_HAS_SHA1 typedef SHA_CTX archive_sha1_ctx; # define archive_sha1_init(ctx) SHA1_Init(ctx) # define archive_sha1_final(ctx, buf) SHA1_Final(buf, ctx) # define archive_sha1_update(ctx, buf, n) SHA1_Update(ctx, buf, n) -#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA1) +#elif defined(ARCHIVE_HASH_SHA1_WIN) # define ARCHIVE_HAS_SHA1 -typedef SHA1_CTX archive_sha1_ctx; -# define archive_sha1_init(ctx) SHA1_Init(ctx) -# define archive_sha1_final(ctx, buf) SHA1_Final(buf, ctx) -# define archive_sha1_update(ctx, buf, n) SHA1_Update(ctx, buf, n) +# define SHA1_DIGEST_LENGTH 20 +typedef Digest_CTX archive_sha1_ctx; +# define archive_sha1_init(ctx) __la_hash_Init(ctx, CALG_SHA1) +# define archive_sha1_final(ctx, buf) __la_hash_Final(buf, SHA1_DIGEST_LENGTH, ctx) +# define archive_sha1_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) #endif -#if defined(HAVE_SHA2_H) && defined(HAVE_SHA256_INIT) +#if defined(ARCHIVE_HASH_SHA256_LIBC) # include # define ARCHIVE_HAS_SHA256 typedef SHA256_CTX archive_sha256_ctx; # define archive_sha256_init(ctx) SHA256_Init(ctx) # define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx) # define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n) -#elif defined(HAVE_SHA2_H) && defined(HAVE_SHA256INIT) +#elif defined(ARCHIVE_HASH_SHA256_LIBC2) # include # define ARCHIVE_HAS_SHA256 typedef SHA256_CTX archive_sha256_ctx; # define archive_sha256_init(ctx) SHA256Init(ctx) # define archive_sha256_final(ctx, buf) SHA256Final(buf, ctx) # define archive_sha256_update(ctx, buf, n) SHA256Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_OPENSSL_SHA256_INIT) +#elif defined(ARCHIVE_HASH_SHA256_LIBC3) +# include +# define ARCHIVE_HAS_SHA256 +typedef SHA2_CTX archive_sha256_ctx; +# define archive_sha256_init(ctx) SHA256Init(ctx) +# define archive_sha256_final(ctx, buf) SHA256Final(buf, ctx) +# define archive_sha256_update(ctx, buf, n) SHA256Update(ctx, buf, n) +#elif defined(ARCHIVE_HASH_SHA256_LIBSYSTEM) +# include +# define ARCHIVE_HAS_SHA256 +typedef CC_SHA256_CTX archive_shs256_ctx; +# define archive_shs256_init(ctx) CC_SHA256_Init(ctx) +# define archive_shs256_final(ctx, buf) CC_SHA256_Final(buf, ctx) +# define archive_shs256_update(ctx, buf, n) CC_SHA256_Update(ctx, buf, n) +#elif defined(ARCHIVE_HASH_SHA256_OPENSSL) # include # define ARCHIVE_HAS_SHA256 typedef SHA256_CTX archive_sha256_ctx; # define archive_sha256_init(ctx) SHA256_Init(ctx) # define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx) # define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n) -#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA_256) +#elif defined(ARCHIVE_HASH_SHA256_WIN) # define ARCHIVE_HAS_SHA256 -typedef SHA256_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) SHA256_Init(ctx) -# define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx) -# define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n) +# define SHA256_DIGEST_LENGTH 32 +typedef Digest_CTX archive_sha256_ctx; +# define archive_sha256_init(ctx) __la_hash_Init(ctx, CALG_SHA_256) +# define archive_sha256_final(ctx, buf) __la_hash_Final(buf, SHA256_DIGEST_LENGTH, ctx) +# define archive_sha256_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) #endif -#if defined(HAVE_SHA2_H) && defined(HAVE_SHA384_INIT) +#if defined(ARCHIVE_HASH_SHA384_LIBC) # include # define ARCHIVE_HAS_SHA384 typedef SHA384_CTX archive_sha384_ctx; # define archive_sha384_init(ctx) SHA384_Init(ctx) # define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx) # define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n) -#elif defined(HAVE_SHA2_H) && defined(HAVE_SHA384INIT) +#elif defined(ARCHIVE_HASH_SHA384_LIBC2) # include # define ARCHIVE_HAS_SHA384 typedef SHA384_CTX archive_sha384_ctx; # define archive_sha384_init(ctx) SHA384Init(ctx) # define archive_sha384_final(ctx, buf) SHA384Final(buf, ctx) # define archive_sha384_update(ctx, buf, n) SHA384Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_OPENSSL_SHA384_INIT) +#elif defined(ARCHIVE_HASH_SHA384_LIBC3) +# include +# define ARCHIVE_HAS_SHA384 +typedef SHA2_CTX archive_sha384_ctx; +# define archive_sha384_init(ctx) SHA384Init(ctx) +# define archive_sha384_final(ctx, buf) SHA384Final(buf, ctx) +# define archive_sha384_update(ctx, buf, n) SHA384Update(ctx, buf, n) +#elif defined(ARCHIVE_HASH_SHA384_LIBSYSTEM) +# include +# define ARCHIVE_HAS_SHA384 +typedef CC_SHA512_CTX archive_shs384_ctx; +# define archive_shs384_init(ctx) CC_SHA384_Init(ctx) +# define archive_shs384_final(ctx, buf) CC_SHA384_Final(buf, ctx) +# define archive_shs384_update(ctx, buf, n) CC_SHA384_Update(ctx, buf, n) +#elif defined(ARCHIVE_HASH_SHA384_OPENSSL) # include # define ARCHIVE_HAS_SHA384 typedef SHA512_CTX archive_sha384_ctx; # define archive_sha384_init(ctx) SHA384_Init(ctx) # define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx) # define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n) -#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA_384) +#elif defined(ARCHIVE_HASH_SHA384_WIN) # define ARCHIVE_HAS_SHA384 -typedef SHA512_CTX archive_sha384_ctx; -# define archive_sha384_init(ctx) SHA384_Init(ctx) -# define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx) -# define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n) +# define SHA384_DIGEST_LENGTH 48 +typedef Digest_CTX archive_sha384_ctx; +# define archive_sha384_init(ctx) __la_hash_Init(ctx, CALG_SHA_384) +# define archive_sha384_final(ctx, buf) __la_hash_Final(buf, SHA384_DIGEST_LENGTH, ctx) +# define archive_sha384_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) #endif -#if defined(HAVE_SHA2_H) && defined(HAVE_SHA512_INIT) +#if defined(ARCHIVE_HASH_SHA512_LIBC) # include # define ARCHIVE_HAS_SHA512 typedef SHA512_CTX archive_sha512_ctx; # define archive_sha512_init(ctx) SHA512_Init(ctx) # define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx) # define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n) -#elif defined(HAVE_SHA2_H) && defined(HAVE_SHA512INIT) +#elif defined(ARCHIVE_HASH_SHA512_LIBC2) # include # define ARCHIVE_HAS_SHA512 typedef SHA512_CTX archive_sha512_ctx; # define archive_sha512_init(ctx) SHA512Init(ctx) # define archive_sha512_final(ctx, buf) SHA512Final(buf, ctx) # define archive_sha512_update(ctx, buf, n) SHA512Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_OPENSSL_SHA512_INIT) +#elif defined(ARCHIVE_HASH_SHA512_LIBC3) +# include +# define ARCHIVE_HAS_SHA512 +typedef SHA2_CTX archive_sha512_ctx; +# define archive_sha512_init(ctx) SHA512Init(ctx) +# define archive_sha512_final(ctx, buf) SHA512Final(buf, ctx) +# define archive_sha512_update(ctx, buf, n) SHA512Update(ctx, buf, n) +#elif defined(ARCHIVE_HASH_SHA512_LIBSYSTEM) +# include +# define ARCHIVE_HAS_SHA512 +typedef CC_SHA512_CTX archive_shs512_ctx; +# define archive_shs512_init(ctx) CC_SHA512_Init(ctx) +# define archive_shs512_final(ctx, buf) CC_SHA512_Final(buf, ctx) +# define archive_shs512_update(ctx, buf, n) CC_SHA512_Update(ctx, buf, n) +#elif defined(ARCHIVE_HASH_SHA512_OPENSSL) # include # define ARCHIVE_HAS_SHA512 typedef SHA512_CTX archive_sha512_ctx; # define archive_sha512_init(ctx) SHA512_Init(ctx) # define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx) # define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n) -#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA_512) +#elif defined(ARCHIVE_HASH_SHA512_WIN) # define ARCHIVE_HAS_SHA512 -typedef SHA512_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) SHA512_Init(ctx) -# define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx) -# define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n) +# define SHA512_DIGEST_LENGTH 64 +typedef Digest_CTX archive_sha512_ctx; +# define archive_sha512_init(ctx) __la_hash_Init(ctx, CALG_SHA_512) +# define archive_sha512_final(ctx, buf) __la_hash_Final(buf, SHA512_DIGEST_LENGTH, ctx) +# define archive_sha512_update(ctx, buf, n) __la_hash_Update(ctx, buf, n) #endif diff --git a/lib/libarchive/archive_platform.h b/external/bsd/libarchive/dist/libarchive/archive_platform.h similarity index 99% rename from lib/libarchive/archive_platform.h rename to external/bsd/libarchive/dist/libarchive/archive_platform.h index 625296e16..ce2f482ba 100644 --- a/lib/libarchive/archive_platform.h +++ b/external/bsd/libarchive/dist/libarchive/archive_platform.h @@ -105,7 +105,6 @@ #endif /* Some platforms lack the standard *_MAX definitions. */ -#ifndef __minix #if !HAVE_DECL_SIZE_MAX #define SIZE_MAX (~(size_t)0) #endif @@ -124,7 +123,6 @@ #if !HAVE_DECL_INT64_MIN #define INT64_MIN ((int64_t)(~INT64_MAX)) #endif -#endif /* * If this platform has , acl_create(), acl_init(), diff --git a/lib/libarchive/archive_private.h b/external/bsd/libarchive/dist/libarchive/archive_private.h similarity index 96% rename from lib/libarchive/archive_private.h rename to external/bsd/libarchive/dist/libarchive/archive_private.h index 88a32ea87..63384b82f 100644 --- a/lib/libarchive/archive_private.h +++ b/external/bsd/libarchive/dist/libarchive/archive_private.h @@ -90,19 +90,13 @@ struct archive { int compression_code; /* Currently active compression. */ const char *compression_name; -#ifndef __minix /* Position in UNCOMPRESSED data stream. */ int64_t file_position; /* Position in COMPRESSED data stream. */ int64_t raw_position; -#else - /* Position in UNCOMPRESSED data stream. */ - off_t file_position; - /* Position in COMPRESSED data stream. */ - off_t raw_position; -#endif - int file_count; /* Number of file entries processed. */ + int file_count; + int archive_error_number; const char *error; struct archive_string error_string; diff --git a/lib/libarchive/archive_read.3 b/external/bsd/libarchive/dist/libarchive/archive_read.3 similarity index 96% rename from lib/libarchive/archive_read.3 rename to external/bsd/libarchive/dist/libarchive/archive_read.3 index 43f3c7632..5dfd48b9c 100644 --- a/lib/libarchive/archive_read.3 +++ b/external/bsd/libarchive/dist/libarchive/archive_read.3 @@ -211,14 +211,12 @@ order they would be used: Allocates and initializes a .Tn struct archive object suitable for reading from an archive. -.It Xo -.Fn archive_read_support_compression_bzip2 , -.Fn archive_read_support_compression_compress , -.Fn archive_read_support_compression_gzip , -.Fn archive_read_support_compression_lzma , -.Fn archive_read_support_compression_none , -.Fn archive_read_support_compression_xz -.Xc +.It Fn archive_read_support_compression_bzip2 , \ +Fn archive_read_support_compression_compress , \ +Fn archive_read_support_compression_gzip , \ +Fn archive_read_support_compression_lzma , \ +Fn archive_read_support_compression_none , \ +Fn archive_read_support_compression_xz Enables auto-detection code and decompression support for the specified compression. Returns @@ -242,16 +240,14 @@ decompression option. This feeds data through the specified external program but only if the initial bytes of the data match the specified signature value. -.It Xo -.Fn archive_read_support_format_all , -.Fn archive_read_support_format_ar , -.Fn archive_read_support_format_cpio , -.Fn archive_read_support_format_empty , -.Fn archive_read_support_format_iso9660 , -.Fn archive_read_support_format_mtree , -.Fn archive_read_support_format_tar , -.Fn archive_read_support_format_zip -.Xc +.It Fn archive_read_support_format_all , \ +Fn archive_read_support_format_ar , \ +Fn archive_read_support_format_cpio , \ +Fn archive_read_support_format_empty , \ +Fn archive_read_support_format_iso9660 , \ +Fn archive_read_support_format_mtree , \ +Fn archive_read_support_format_tar , \ +Fn archive_read_support_format_zip Enables support---including auto-detection code---for the specified archive format. For example, @@ -273,11 +269,9 @@ all other entry fields are unset. This is not enabled by .Fn archive_read_support_format_all in order to avoid erroneous handling of damaged archives. -.It Xo -.Fn archive_read_set_filter_options , -.Fn archive_read_set_format_options , -.Fn archive_read_set_options -.Xc +.It Fn archive_read_set_filter_options , \ +Fn archive_read_set_format_options , \ +Fn archive_read_set_options Specifies options that will be passed to currently-registered filters (including decompression filters) and/or format readers. The argument is a comma-separated list of individual options. @@ -597,7 +591,7 @@ list_archive(const char *name) archive_read_support_format_all(a); archive_read_open(a, mydata, myopen, myread, myclose); while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { - printf("%s\\n",archive_entry_pathname(entry)); + printf("%s\en",archive_entry_pathname(entry)); archive_read_data_skip(a); } archive_read_finish(a); diff --git a/lib/libarchive/archive_read.c b/external/bsd/libarchive/dist/libarchive/archive_read.c similarity index 90% rename from lib/libarchive/archive_read.c rename to external/bsd/libarchive/dist/libarchive/archive_read.c index c03a5a168..f39f5cec2 100644 --- a/lib/libarchive/archive_read.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read.c @@ -249,7 +249,6 @@ client_read_proxy(struct archive_read_filter *self, const void **buff) return (r); } -#ifndef __minix static int64_t client_skip_proxy(struct archive_read_filter *self, int64_t request) { @@ -274,32 +273,6 @@ client_skip_proxy(struct archive_read_filter *self, int64_t request) total += get; } } -#else -static ssize_t -client_skip_proxy(struct archive_read_filter *self, ssize_t request) -{ - size_t ask, get, total; - /* Limit our maximum seek request to 1GB on platforms - * with 32-bit off_t (such as Windows). */ - size_t skip_limit = ((size_t)1) << (sizeof(off_t) * 8 - 2); - - if (self->archive->client.skipper == NULL) - return (0); - total = 0; - for (;;) { - ask = request; - if (ask > skip_limit) - ask = skip_limit; - get = (self->archive->client.skipper)(&self->archive->archive, - self->data, ask); - if (get == 0) - return (total); - request -= get; - self->archive->archive.raw_position += get; - total += get; - } -} -#endif static int client_close_proxy(struct archive_read_filter *self) @@ -574,7 +547,6 @@ choose_format(struct archive_read *a) * Return the file offset (within the uncompressed data stream) where * the last header started. */ -#ifndef __minix int64_t archive_read_header_position(struct archive *_a) { @@ -583,16 +555,6 @@ archive_read_header_position(struct archive *_a) ARCHIVE_STATE_ANY, "archive_read_header_position"); return (a->header_position); } -#else -off_t -archive_read_header_position(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_ANY, "archive_read_header_position"); - return (a->header_position); -} -#endif /* * Read data from an archive entry, using a read(2)-style interface. @@ -1194,7 +1156,6 @@ __archive_read_filter_consume(struct archive_read_filter * filter, * isn't feasible, this at least pushes the read-and-discard loop * down closer to the data source. */ -#ifndef __minix int64_t __archive_read_skip(struct archive_read *a, int64_t request) { @@ -1210,25 +1171,7 @@ __archive_read_skip(struct archive_read *a, int64_t request) (intmax_t)request, (intmax_t)skipped); return (ARCHIVE_FATAL); } -#else -ssize_t -__archive_read_skip(struct archive_read *a, ssize_t request) -{ - ssize_t skipped = __archive_read_skip_lenient(a, request); - if (skipped == request) - return (skipped); - /* We hit EOF before we satisfied the skip request. */ - if (skipped < 0) /* Map error code to 0 for error message below. */ - skipped = 0; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Truncated input file (needed %jd bytes, only %jd available)", - (intmax_t)request, (intmax_t)skipped); - return (ARCHIVE_FATAL); -} -#endif -#ifndef __minix int64_t __archive_read_skip_lenient(struct archive_read *a, int64_t request) { @@ -1237,18 +1180,7 @@ __archive_read_skip_lenient(struct archive_read *a, int64_t request) a->archive.file_position += skipped; return (skipped); } -#else -ssize_t -__archive_read_skip_lenient(struct archive_read *a, ssize_t request) -{ - size_t skipped = __archive_read_filter_skip(a->filter, request); - if (skipped > 0) - a->archive.file_position += skipped; - return (skipped); -} -#endif -#ifndef __minix int64_t __archive_read_filter_skip(struct archive_read_filter *filter, int64_t request) { @@ -1315,71 +1247,3 @@ __archive_read_filter_skip(struct archive_read_filter *filter, int64_t request) } return (total_bytes_skipped); } -#else -ssize_t -__archive_read_filter_skip(struct archive_read_filter *filter, ssize_t request) -{ - ssize_t bytes_skipped, total_bytes_skipped = 0; - size_t min; - - if (filter->fatal) - return (-1); - /* - * If there is data in the buffers already, use that first. - */ - if (filter->avail > 0) { - min = minimum(request, (off_t)filter->avail); - bytes_skipped = __archive_read_filter_consume(filter, min); - request -= bytes_skipped; - total_bytes_skipped += bytes_skipped; - } - if (filter->client_avail > 0) { - min = minimum(request, (off_t)filter->client_avail); - bytes_skipped = __archive_read_filter_consume(filter, min); - request -= bytes_skipped; - total_bytes_skipped += bytes_skipped; - } - if (request == 0) - return (total_bytes_skipped); - /* - * If a client_skipper was provided, try that first. - */ -#if ARCHIVE_API_VERSION < 2 - if ((filter->skip != NULL) && (request < SSIZE_MAX)) { -#else - if (filter->skip != NULL) { -#endif - bytes_skipped = (filter->skip)(filter, request); - if (bytes_skipped < 0) { /* error */ - filter->client_total = filter->client_avail = 0; - filter->client_next = filter->client_buff = NULL; - filter->fatal = 1; - return (bytes_skipped); - } - total_bytes_skipped += bytes_skipped; - request -= bytes_skipped; - filter->client_next = filter->client_buff; - filter->client_avail = filter->client_total = 0; - } - /* - * Note that client_skipper will usually not satisfy the - * full request (due to low-level blocking concerns), - * so even if client_skipper is provided, we may still - * have to use ordinary reads to finish out the request. - */ - while (request > 0) { - ssize_t bytes_read; - (void)__archive_read_filter_ahead(filter, 1, &bytes_read); - if (bytes_read < 0) - return (bytes_read); - if (bytes_read == 0) { - return (total_bytes_skipped); - } - min = (size_t)(minimum(bytes_read, request)); - bytes_read = __archive_read_filter_consume(filter, min); - total_bytes_skipped += bytes_read; - request -= bytes_read; - } - return (total_bytes_skipped); -} -#endif diff --git a/lib/libarchive/archive_read_data_into_fd.c b/external/bsd/libarchive/dist/libarchive/archive_read_data_into_fd.c similarity index 100% rename from lib/libarchive/archive_read_data_into_fd.c rename to external/bsd/libarchive/dist/libarchive/archive_read_data_into_fd.c diff --git a/lib/libarchive/archive_read_disk.3 b/external/bsd/libarchive/dist/libarchive/archive_read_disk.3 similarity index 96% rename from lib/libarchive/archive_read_disk.3 rename to external/bsd/libarchive/dist/libarchive/archive_read_disk.3 index b3a09b528..7ada50020 100644 --- a/lib/libarchive/archive_read_disk.3 +++ b/external/bsd/libarchive/dist/libarchive/archive_read_disk.3 @@ -93,11 +93,9 @@ objects. Allocates and initializes a .Tn struct archive object suitable for reading object information from disk. -.It Xo -.Fn archive_read_disk_set_symlink_logical , -.Fn archive_read_disk_set_symlink_physical , -.Fn archive_read_disk_set_symlink_hybrid -.Xc +.It Fn archive_read_disk_set_symlink_logical , \ +Fn archive_read_disk_set_symlink_physical , \ +Fn archive_read_disk_set_symlink_hybrid This sets the mode used for handling symbolic links. The .Dq logical @@ -110,16 +108,12 @@ The mode currently behaves identically to the .Dq logical mode. -.It Xo -.Fn archive_read_disk_gname , -.Fn archive_read_disk_uname -.Xc +.It Fn archive_read_disk_gname , \ +Fn archive_read_disk_uname Returns a user or group name given a gid or uid value. By default, these always return a NULL string. -.It Xo -.Fn archive_read_disk_set_gname_lookup , -.Fn archive_read_disk_set_uname_lookup -.Xc +.It Fn archive_read_disk_set_gname_lookup , \ +Fn archive_read_disk_set_uname_lookup These allow you to override the functions used for user and group name lookups. You may also provide a diff --git a/lib/libarchive/archive_read_disk.c b/external/bsd/libarchive/dist/libarchive/archive_read_disk.c similarity index 100% rename from lib/libarchive/archive_read_disk.c rename to external/bsd/libarchive/dist/libarchive/archive_read_disk.c diff --git a/lib/libarchive/archive_read_disk_entry_from_file.c b/external/bsd/libarchive/dist/libarchive/archive_read_disk_entry_from_file.c similarity index 99% rename from lib/libarchive/archive_read_disk_entry_from_file.c rename to external/bsd/libarchive/dist/libarchive/archive_read_disk_entry_from_file.c index 6acc09662..7473c506e 100644 --- a/lib/libarchive/archive_read_disk_entry_from_file.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_disk_entry_from_file.c @@ -425,7 +425,8 @@ setup_xattrs(struct archive_read_disk *a, return (ARCHIVE_OK); } -#elif HAVE_EXTATTR_GET_FILE && HAVE_EXTATTR_LIST_FILE +#elif HAVE_EXTATTR_GET_FILE && HAVE_EXTATTR_LIST_FILE && \ + HAVE_DECL_EXTATTR_NAMESPACE_USER /* * FreeBSD extattr interface. diff --git a/lib/libarchive/archive_read_disk_private.h b/external/bsd/libarchive/dist/libarchive/archive_read_disk_private.h similarity index 97% rename from lib/libarchive/archive_read_disk_private.h rename to external/bsd/libarchive/dist/libarchive/archive_read_disk_private.h index 77bae39ef..b674b7106 100644 --- a/lib/libarchive/archive_read_disk_private.h +++ b/external/bsd/libarchive/dist/libarchive/archive_read_disk_private.h @@ -54,7 +54,7 @@ struct archive_read_disk { const char * (*lookup_gname)(void *private, gid_t gid); void (*cleanup_gname)(void *private); void *lookup_gname_data; - const char * (*lookup_uname)(void *private, uid_t gid); + const char * (*lookup_uname)(void *private, gid_t gid); void (*cleanup_uname)(void *private); void *lookup_uname_data; }; diff --git a/lib/libarchive/archive_read_disk_set_standard_lookup.c b/external/bsd/libarchive/dist/libarchive/archive_read_disk_set_standard_lookup.c similarity index 94% rename from lib/libarchive/archive_read_disk_set_standard_lookup.c rename to external/bsd/libarchive/dist/libarchive/archive_read_disk_set_standard_lookup.c index 5c4a0c4b6..97a568e05 100644 --- a/lib/libarchive/archive_read_disk_set_standard_lookup.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_disk_set_standard_lookup.c @@ -182,6 +182,7 @@ lookup_uname(void *data, uid_t uid) &lookup_uname_helper, (id_t)uid)); } +#if HAVE_GETPWUID_R static const char * lookup_uname_helper(struct name_cache *cache, id_t id) { @@ -196,13 +197,8 @@ lookup_uname_helper(struct name_cache *cache, id_t id) return (NULL); for (;;) { result = &pwent; /* Old getpwuid_r ignores last arg. */ -#if defined(HAVE_GETPWUID_R) r = getpwuid_r((uid_t)id, &pwent, cache->buff, cache->buff_size, &result); -#else - result = getpwuid((uid_t)id); - r = errno; -#endif if (r == 0) break; if (r != ERANGE) @@ -227,6 +223,20 @@ lookup_uname_helper(struct name_cache *cache, id_t id) return strdup(result->pw_name); } +#else +static const char * +lookup_uname_helper(struct name_cache *cache, id_t id) +{ + struct passwd *result; + + result = getpwuid((uid_t)id); + + if (result == NULL) + return (NULL); + + return strdup(result->pw_name); +} +#endif static const char * lookup_gname(void *data, gid_t gid) @@ -236,6 +246,7 @@ lookup_gname(void *data, gid_t gid) &lookup_gname_helper, (id_t)gid)); } +#if HAVE_GETGRGID_R static const char * lookup_gname_helper(struct name_cache *cache, id_t id) { @@ -250,13 +261,8 @@ lookup_gname_helper(struct name_cache *cache, id_t id) return (NULL); for (;;) { result = &grent; /* Old getgrgid_r ignores last arg. */ -#if defined(HAVE_GETGRGID_R) r = getgrgid_r((gid_t)id, &grent, cache->buff, cache->buff_size, &result); -#else - result = getgrgid((gid_t)id); - r = errno; -#endif if (r == 0) break; if (r != ERANGE) @@ -279,4 +285,19 @@ lookup_gname_helper(struct name_cache *cache, id_t id) return strdup(result->gr_name); } +#else +static const char * +lookup_gname_helper(struct name_cache *cache, id_t id) +{ + struct group *result; + + result = getgrgid((gid_t)id); + + if (result == NULL) + return (NULL); + + return strdup(result->gr_name); +} +#endif + #endif /* ! (_WIN32 && !__CYGWIN__) */ diff --git a/lib/libarchive/archive_read_extract.c b/external/bsd/libarchive/dist/libarchive/archive_read_extract.c similarity index 100% rename from lib/libarchive/archive_read_extract.c rename to external/bsd/libarchive/dist/libarchive/archive_read_extract.c diff --git a/lib/libarchive/archive_read_open_fd.c b/external/bsd/libarchive/dist/libarchive/archive_read_open_fd.c similarity index 95% rename from lib/libarchive/archive_read_open_fd.c rename to external/bsd/libarchive/dist/libarchive/archive_read_open_fd.c index 33b7cba1b..9660da8f9 100644 --- a/lib/libarchive/archive_read_open_fd.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_open_fd.c @@ -116,11 +116,15 @@ file_read(struct archive *a, void *client_data, const void **buff) ssize_t bytes_read; *buff = mine->buffer; - bytes_read = read(mine->fd, mine->buffer, mine->block_size); - if (bytes_read < 0) { - archive_set_error(a, errno, "Error reading fd %d", mine->fd); + for (;;) { + bytes_read = read(mine->fd, mine->buffer, mine->block_size); + if (bytes_read < 0) { + if (errno == EINTR) + continue; + archive_set_error(a, errno, "Error reading fd %d", mine->fd); + } + return (bytes_read); } - return (bytes_read); } #if ARCHIVE_API_VERSION < 2 diff --git a/lib/libarchive/archive_read_open_file.c b/external/bsd/libarchive/dist/libarchive/archive_read_open_file.c similarity index 100% rename from lib/libarchive/archive_read_open_file.c rename to external/bsd/libarchive/dist/libarchive/archive_read_open_file.c diff --git a/lib/libarchive/archive_read_open_filename.c b/external/bsd/libarchive/dist/libarchive/archive_read_open_filename.c similarity index 95% rename from lib/libarchive/archive_read_open_filename.c rename to external/bsd/libarchive/dist/libarchive/archive_read_open_filename.c index 607b80c56..74f3e60c4 100644 --- a/lib/libarchive/archive_read_open_filename.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_open_filename.c @@ -160,15 +160,19 @@ file_read(struct archive *a, void *client_data, const void **buff) ssize_t bytes_read; *buff = mine->buffer; - bytes_read = read(mine->fd, mine->buffer, mine->block_size); - if (bytes_read < 0) { - if (mine->filename[0] == '\0') - archive_set_error(a, errno, "Error reading stdin"); - else - archive_set_error(a, errno, "Error reading '%s'", - mine->filename); + for (;;) { + bytes_read = read(mine->fd, mine->buffer, mine->block_size); + if (bytes_read < 0) { + if (errno == EINTR) + continue; + else if (mine->filename[0] == '\0') + archive_set_error(a, errno, "Error reading stdin"); + else + archive_set_error(a, errno, "Error reading '%s'", + mine->filename); + } + return (bytes_read); } - return (bytes_read); } #if ARCHIVE_API_VERSION < 2 diff --git a/lib/libarchive/archive_read_open_memory.c b/external/bsd/libarchive/dist/libarchive/archive_read_open_memory.c similarity index 100% rename from lib/libarchive/archive_read_open_memory.c rename to external/bsd/libarchive/dist/libarchive/archive_read_open_memory.c diff --git a/lib/libarchive/archive_read_private.h b/external/bsd/libarchive/dist/libarchive/archive_read_private.h similarity index 94% rename from lib/libarchive/archive_read_private.h rename to external/bsd/libarchive/dist/libarchive/archive_read_private.h index ab7759a0b..5a8501890 100644 --- a/lib/libarchive/archive_read_private.h +++ b/external/bsd/libarchive/dist/libarchive/archive_read_private.h @@ -79,11 +79,7 @@ struct archive_read_filter { /* Return next block. */ ssize_t (*read)(struct archive_read_filter *, const void **); /* Skip forward this many bytes. */ -#ifndef __minix int64_t (*skip)(struct archive_read_filter *self, int64_t request); -#else - ssize_t (*skip)(struct archive_read_filter *self, ssize_t request); -#endif /* Close (just this filter) and free(self). */ int (*close)(struct archive_read_filter *self); /* My private data. */ @@ -101,11 +97,7 @@ struct archive_read_filter { size_t client_total; const char *client_next; size_t client_avail; -#ifndef __minix int64_t position; -#else - off_t position; -#endif char end_of_file; char fatal; }; @@ -200,14 +192,8 @@ const void *__archive_read_filter_ahead(struct archive_read_filter *, size_t, ssize_t *); ssize_t __archive_read_consume(struct archive_read *, size_t); ssize_t __archive_read_filter_consume(struct archive_read_filter *, size_t); -#ifndef __minix int64_t __archive_read_skip(struct archive_read *, int64_t); int64_t __archive_read_skip_lenient(struct archive_read *, int64_t); int64_t __archive_read_filter_skip(struct archive_read_filter *, int64_t); -#else -ssize_t __archive_read_skip(struct archive_read *, ssize_t); -ssize_t __archive_read_skip_lenient(struct archive_read *, ssize_t); -ssize_t __archive_read_filter_skip(struct archive_read_filter *, ssize_t); -#endif /* __minix */ int __archive_read_program(struct archive_read_filter *, const char *); #endif diff --git a/lib/libarchive/archive_read_support_compression_all.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_all.c similarity index 99% rename from lib/libarchive/archive_read_support_compression_all.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_compression_all.c index 38d3c81db..a6db7364d 100644 --- a/lib/libarchive/archive_read_support_compression_all.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_all.c @@ -47,9 +47,8 @@ archive_read_support_compression_all(struct archive *a) /* The decode code doesn't use an outside library. */ archive_read_support_compression_uu(a); /* The decode code doesn't use an outside library. */ -#ifndef __minix archive_read_support_compression_rpm(a); -#endif + /* Note: We always return ARCHIVE_OK here, even if some of the * above return ARCHIVE_WARN. The intent here is to enable * "as much as possible." Clients who need specific diff --git a/lib/libarchive/archive_read_support_compression_bzip2.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_bzip2.c similarity index 97% rename from lib/libarchive/archive_read_support_compression_bzip2.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_compression_bzip2.c index 1e45f2202..8381c9a57 100644 --- a/lib/libarchive/archive_read_support_compression_bzip2.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_bzip2.c @@ -48,7 +48,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_compression_bzip2.c #include "archive_private.h" #include "archive_read_private.h" -#if HAVE_BZLIB_H +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) struct private_data { bz_stream stream; char *out_block; @@ -86,7 +86,7 @@ archive_read_support_compression_bzip2(struct archive *_a) reader->init = bzip2_reader_init; reader->options = NULL; reader->free = bzip2_reader_free; -#if HAVE_BZLIB_H +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) return (ARCHIVE_OK); #else archive_set_error(_a, ARCHIVE_ERRNO_MISC, @@ -146,7 +146,7 @@ bzip2_reader_bid(struct archive_read_filter_bidder *self, struct archive_read_fi return (bits_checked); } -#ifndef HAVE_BZLIB_H +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) /* * If we don't have the library on this system, we can't actually do the @@ -350,4 +350,4 @@ bzip2_filter_close(struct archive_read_filter *self) return (ret); } -#endif /* HAVE_BZLIB_H */ +#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */ diff --git a/lib/libarchive/archive_read_support_compression_compress.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_compress.c similarity index 100% rename from lib/libarchive/archive_read_support_compression_compress.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_compression_compress.c diff --git a/lib/libarchive/archive_read_support_compression_gzip.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_gzip.c similarity index 99% rename from lib/libarchive/archive_read_support_compression_gzip.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_compression_gzip.c index c8af1eef6..8cc924c9f 100644 --- a/lib/libarchive/archive_read_support_compression_gzip.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_gzip.c @@ -54,11 +54,7 @@ struct private_data { char in_stream; unsigned char *out_block; size_t out_block_size; -#ifndef __minix int64_t total_out; -#else - int32_t total_out; -#endif unsigned long crc; char eof; /* True = found end of compressed data. */ }; diff --git a/lib/libarchive/archive_read_support_compression_none.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_none.c similarity index 100% rename from lib/libarchive/archive_read_support_compression_none.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_compression_none.c diff --git a/lib/libarchive/archive_read_support_compression_program.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_program.c similarity index 100% rename from lib/libarchive/archive_read_support_compression_program.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_compression_program.c diff --git a/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_rpm.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_rpm.c new file mode 100644 index 000000000..051baa5e1 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_rpm.c @@ -0,0 +1,287 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif + +#include "archive.h" +#include "archive_endian.h" +#include "archive_private.h" +#include "archive_read_private.h" + +struct rpm { + int64_t total_in; + size_t hpos; + size_t hlen; + unsigned char header[16]; + enum { + ST_LEAD, /* Skipping 'Lead' section. */ + ST_HEADER, /* Reading 'Header' section; + * first 16 bytes. */ + ST_HEADER_DATA, /* Skipping 'Header' section. */ + ST_PADDING, /* Skipping padding data after the + * 'Header' section. */ + ST_ARCHIVE /* Reading 'Archive' section. */ + } state; + int first_header; +}; +#define RPM_LEAD_SIZE 96 /* Size of 'Lead' section. */ + +static int rpm_bidder_bid(struct archive_read_filter_bidder *, + struct archive_read_filter *); +static int rpm_bidder_init(struct archive_read_filter *); + +static ssize_t rpm_filter_read(struct archive_read_filter *, + const void **); +static int rpm_filter_close(struct archive_read_filter *); + +int +archive_read_support_compression_rpm(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + + bidder = __archive_read_get_bidder(a); + archive_clear_error(_a); + if (bidder == NULL) + return (ARCHIVE_FATAL); + + bidder->data = NULL; + bidder->bid = rpm_bidder_bid; + bidder->init = rpm_bidder_init; + bidder->options = NULL; + bidder->free = NULL; + return (ARCHIVE_OK); +} + +static int +rpm_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *filter) +{ + const unsigned char *b; + ssize_t avail; + int bits_checked; + + (void)self; /* UNUSED */ + + b = __archive_read_filter_ahead(filter, 8, &avail); + if (b == NULL) + return (0); + + bits_checked = 0; + /* + * Verify Header Magic Bytes : 0xed 0xab 0xee 0xdb + */ + if (b[0] != 0xed) + return (0); + bits_checked += 8; + if (b[1] != 0xab) + return (0); + bits_checked += 8; + if (b[2] != 0xee) + return (0); + bits_checked += 8; + if (b[3] != 0xdb) + return (0); + bits_checked += 8; + /* + * Check major version. + */ + if (b[4] != 3 && b[4] != 4) + return (0); + bits_checked += 8; + /* + * Check package type; binary or source. + */ + if (b[6] != 0) + return (0); + bits_checked += 8; + if (b[7] != 0 && b[7] != 1) + return (0); + bits_checked += 8; + + return (bits_checked); +} + +static int +rpm_bidder_init(struct archive_read_filter *self) +{ + struct rpm *rpm; + + self->code = ARCHIVE_COMPRESSION_RPM; + self->name = "rpm"; + self->read = rpm_filter_read; + self->skip = NULL; /* not supported */ + self->close = rpm_filter_close; + + rpm = (struct rpm *)calloc(sizeof(*rpm), 1); + if (rpm == NULL) { + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate data for rpm"); + return (ARCHIVE_FATAL); + } + + self->data = rpm; + rpm->state = ST_LEAD; + + return (ARCHIVE_OK); +} + +static ssize_t +rpm_filter_read(struct archive_read_filter *self, const void **buff) +{ + struct rpm *rpm; + const unsigned char *b; + ssize_t avail_in, total; + size_t used, n; + uint32_t section; + uint32_t bytes; + + rpm = (struct rpm *)self->data; + *buff = NULL; + total = avail_in = 0; + b = NULL; + used = 0; + do { + if (b == NULL) { + b = __archive_read_filter_ahead(self->upstream, 1, + &avail_in); + if (b == NULL) { + if (avail_in < 0) + return (ARCHIVE_FATAL); + else + break; + } + } + + switch (rpm->state) { + case ST_LEAD: + if (rpm->total_in + avail_in < RPM_LEAD_SIZE) + used += avail_in; + else { + n = RPM_LEAD_SIZE - rpm->total_in; + used += n; + b += n; + rpm->state = ST_HEADER; + rpm->hpos = 0; + rpm->hlen = 0; + rpm->first_header = 1; + } + break; + case ST_HEADER: + n = 16 - rpm->hpos; + if (n > avail_in - used) + n = avail_in - used; + memcpy(rpm->header+rpm->hpos, b, n); + b += n; + used += n; + rpm->hpos += n; + + if (rpm->hpos == 16) { + if (rpm->header[0] != 0x8e || + rpm->header[1] != 0xad || + rpm->header[2] != 0xe8 || + rpm->header[3] != 0x01) { + if (rpm->first_header) { + archive_set_error( + &self->archive->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unrecoginized rpm header"); + return (ARCHIVE_FATAL); + } + rpm->state = ST_ARCHIVE; + *buff = rpm->header; + total = rpm->hpos; + break; + } + /* Calculate 'Header' length. */ + section = archive_be32dec(rpm->header+8); + bytes = archive_be32dec(rpm->header+12); + rpm->hlen = 16 + section * 16 + bytes; + rpm->state = ST_HEADER_DATA; + rpm->first_header = 0; + } + break; + case ST_HEADER_DATA: + n = rpm->hlen - rpm->hpos; + if (n > avail_in - used) + n = avail_in - used; + b += n; + used += n; + rpm->hpos += n; + if (rpm->hpos == rpm->hlen) + rpm->state = ST_PADDING; + break; + case ST_PADDING: + while (used < (size_t)avail_in) { + if (*b != 0) { + /* Read next header. */ + rpm->state = ST_HEADER; + rpm->hpos = 0; + rpm->hlen = 0; + break; + } + b++; + used++; + } + break; + case ST_ARCHIVE: + *buff = b; + total = avail_in; + used = avail_in; + break; + } + if (used == (size_t)avail_in) { + rpm->total_in += used; + __archive_read_filter_consume(self->upstream, used); + b = NULL; + used = 0; + } + } while (total == 0 && avail_in > 0); + + if (used > 0 && b != NULL) { + rpm->total_in += used; + __archive_read_filter_consume(self->upstream, used); + } + return (total); +} + +static int +rpm_filter_close(struct archive_read_filter *self) +{ + struct rpm *rpm; + + rpm = (struct rpm *)self->data; + free(rpm); + + return (ARCHIVE_OK); +} + diff --git a/lib/libarchive/archive_read_support_compression_uu.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_uu.c similarity index 99% rename from lib/libarchive/archive_read_support_compression_uu.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_compression_uu.c index df6390a9b..1e3052097 100644 --- a/lib/libarchive/archive_read_support_compression_uu.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_uu.c @@ -41,11 +41,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_compression_uu.c 20 #include "archive_read_private.h" struct uudecode { -#ifndef __minix int64_t total; -#else - int32_t total; -#endif unsigned char *in_buff; #define IN_BUFF_SIZE (1024) int in_cnt; diff --git a/lib/libarchive/archive_read_support_compression_xz.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_xz.c similarity index 99% rename from lib/libarchive/archive_read_support_compression_xz.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_compression_xz.c index 198d6b96e..28c4e2d9f 100644 --- a/lib/libarchive/archive_read_support_compression_xz.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_compression_xz.c @@ -207,12 +207,7 @@ lzma_bidder_bid(struct archive_read_filter_bidder *self, const unsigned char *buffer; ssize_t avail; uint32_t dicsize; -#ifndef __minix uint64_t uncompressed_size; -#else - u64_t uncompressed_size; -#endif - int bits_checked; (void)self; /* UNUSED */ @@ -249,13 +244,8 @@ lzma_bidder_bid(struct archive_read_filter_bidder *self, * size is unknown and lzma of XZ Utils always records `-1' * in this field. */ uncompressed_size = archive_le64dec(buffer+5); -#ifndef __minix if (uncompressed_size == (uint64_t)ARCHIVE_LITERAL_LL(-1)) bits_checked += 64; -#else - if (cmp64(uncompressed_size, make64(ULONG_MAX, ULONG_MAX)) == 0) - bits_checked += 64; -#endif /* Second through fifth bytes are dictionary size, stored in * little-endian order. The minimum dictionary size is diff --git a/lib/libarchive/archive_read_support_format_all.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_all.c similarity index 98% rename from lib/libarchive/archive_read_support_format_all.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_format_all.c index fdd52fb07..967783885 100644 --- a/lib/libarchive/archive_read_support_format_all.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_all.c @@ -32,11 +32,9 @@ int archive_read_support_format_all(struct archive *a) { archive_read_support_format_ar(a); + archive_read_support_format_cpio(a); archive_read_support_format_empty(a); -#ifndef __minix archive_read_support_format_iso9660(a); - archive_read_support_format_cpio(a); -#endif archive_read_support_format_mtree(a); archive_read_support_format_tar(a); archive_read_support_format_xar(a); diff --git a/lib/libarchive/archive_read_support_format_ar.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_ar.c similarity index 88% rename from lib/libarchive/archive_read_support_format_ar.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_format_ar.c index 84eabb10e..7c1ca3a0c 100644 --- a/lib/libarchive/archive_read_support_format_ar.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_ar.c @@ -82,14 +82,8 @@ static int archive_read_format_ar_read_data(struct archive_read *a, static int archive_read_format_ar_skip(struct archive_read *a); static int archive_read_format_ar_read_header(struct archive_read *a, struct archive_entry *e); -#ifndef __minix static uint64_t ar_atol8(const char *p, unsigned char_cnt); static uint64_t ar_atol10(const char *p, unsigned char_cnt); -#else -static uint32_t ar_atol8(const char *p, unsigned char_cnt); -static uint32_t ar_atol10(const char *p, unsigned char_cnt); -#endif - static int ar_parse_gnu_filename_table(struct archive_read *a); static int ar_parse_common_header(struct ar *ar, struct archive_entry *, const char *h); @@ -168,11 +162,7 @@ archive_read_format_ar_read_header(struct archive_read *a, { char filename[AR_name_size + 1]; struct ar *ar; -#ifndef __minix uint64_t number; /* Used to hold parsed numbers before validation. */ -#else - uint32_t number; /* Used to hold parsed numbers before validation. */ -#endif ssize_t bytes_read; size_t bsd_name_length, entry_size; char *p, *st; @@ -276,23 +266,11 @@ archive_read_format_ar_read_header(struct archive_read *a, archive_entry_set_filetype(entry, AE_IFREG); /* Get the size of the filename table. */ number = ar_atol10(h + AR_size_offset, AR_size_size); -#ifndef __minix if (number > SIZE_MAX) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Filename table too large"); return (ARCHIVE_FATAL); } -#else - /* The above won't work for us as UINT32_MAX == SIZE_MAX on Minix - * We simply decrease the maximum allowed filename table size - * to SIZE_MAX - 1 - */ - if (number == SIZE_MAX) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Filename table too large"); - return (ARCHIVE_FATAL); - } -#endif entry_size = (size_t)number; if (entry_size == 0) { archive_set_error(&a->archive, EINVAL, @@ -368,26 +346,12 @@ archive_read_format_ar_read_header(struct archive_read *a, /* Guard against the filename + trailing NUL * overflowing a size_t and against the filename size * being larger than the entire entry. */ -#ifndef __minix if (number > (uint64_t)(bsd_name_length + 1) || (off_t)bsd_name_length > ar->entry_bytes_remaining) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Bad input file size"); return (ARCHIVE_FATAL); } -#else - /* The above way won't work for us as we use uint32_t for number - * and not uint64_t. We decrease the maximum allowed name - * length to UINT32_MAX - 1 (which is what ar_atol10 will return - * in case of an overflow). - */ - if (number == UINT32_MAX - || (off_t)bsd_name_length > ar->entry_bytes_remaining) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Bad input file size"); - return (ARCHIVE_FATAL); - } -#endif ar->entry_bytes_remaining -= bsd_name_length; /* Adjust file size reported to client. */ archive_entry_set_size(entry, ar->entry_bytes_remaining); @@ -448,11 +412,7 @@ static int ar_parse_common_header(struct ar *ar, struct archive_entry *entry, const char *h) { -#ifndef __minix uint64_t n; -#else - uint32_t n; -#endif /* Copy remaining header */ archive_entry_set_mtime(entry, @@ -572,7 +532,6 @@ bad_string_table: return (ARCHIVE_WARN); } -#ifndef __minix static uint64_t ar_atol8(const char *p, unsigned char_cnt) { @@ -598,35 +557,7 @@ ar_atol8(const char *p, unsigned char_cnt) } return (l); } -#else -static uint32_t -ar_atol8(const char *p, unsigned char_cnt) -{ - uint32_t l, limit, last_digit_limit; - unsigned int digit, base; - - base = 8; - limit = UINT32_MAX / base; - last_digit_limit = UINT32_MAX % base; - - while ((*p == ' ' || *p == '\t') && char_cnt-- > 0) - p++; - - l = 0; - digit = *p - '0'; - while (*p >= '0' && digit < base && char_cnt-- > 0) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = UINT32_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (l); -} -#endif -#ifndef __minix static uint64_t ar_atol10(const char *p, unsigned char_cnt) { @@ -651,29 +582,3 @@ ar_atol10(const char *p, unsigned char_cnt) } return (l); } -#else -static uint32_t -ar_atol10(const char *p, unsigned char_cnt) -{ - uint32_t l, limit, last_digit_limit; - unsigned int base, digit; - - base = 10; - limit = UINT32_MAX / base; - last_digit_limit = UINT32_MAX % base; - - while ((*p == ' ' || *p == '\t') && char_cnt-- > 0) - p++; - l = 0; - digit = *p - '0'; - while (*p >= '0' && digit < base && char_cnt-- > 0) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = UINT32_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (l); -} -#endif diff --git a/external/bsd/libarchive/dist/libarchive/archive_read_support_format_cpio.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_cpio.c new file mode 100644 index 000000000..1def0006a --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_cpio.c @@ -0,0 +1,777 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_cpio.c 201163 2009-12-29 05:50:34Z kientzle $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +/* #include */ /* See archive_platform.h */ +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "archive.h" +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_read_private.h" + +struct cpio_bin_header { + unsigned char c_magic[2]; + unsigned char c_dev[2]; + unsigned char c_ino[2]; + unsigned char c_mode[2]; + unsigned char c_uid[2]; + unsigned char c_gid[2]; + unsigned char c_nlink[2]; + unsigned char c_rdev[2]; + unsigned char c_mtime[4]; + unsigned char c_namesize[2]; + unsigned char c_filesize[4]; +}; + +struct cpio_odc_header { + char c_magic[6]; + char c_dev[6]; + char c_ino[6]; + char c_mode[6]; + char c_uid[6]; + char c_gid[6]; + char c_nlink[6]; + char c_rdev[6]; + char c_mtime[11]; + char c_namesize[6]; + char c_filesize[11]; +}; + +struct cpio_newc_header { + char c_magic[6]; + char c_ino[8]; + char c_mode[8]; + char c_uid[8]; + char c_gid[8]; + char c_nlink[8]; + char c_mtime[8]; + char c_filesize[8]; + char c_devmajor[8]; + char c_devminor[8]; + char c_rdevmajor[8]; + char c_rdevminor[8]; + char c_namesize[8]; + char c_crc[8]; +}; + +struct links_entry { + struct links_entry *next; + struct links_entry *previous; + int links; + dev_t dev; + int64_t ino; + char *name; +}; + +#define CPIO_MAGIC 0x13141516 +struct cpio { + int magic; + int (*read_header)(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); + struct links_entry *links_head; + struct archive_string entry_name; + struct archive_string entry_linkname; + off_t entry_bytes_remaining; + off_t entry_offset; + off_t entry_padding; +}; + +static int64_t atol16(const char *, unsigned); +static int64_t atol8(const char *, unsigned); +static int archive_read_format_cpio_bid(struct archive_read *); +static int archive_read_format_cpio_cleanup(struct archive_read *); +static int archive_read_format_cpio_read_data(struct archive_read *, + const void **, size_t *, off_t *); +static int archive_read_format_cpio_read_header(struct archive_read *, + struct archive_entry *); +static int be4(const unsigned char *); +static int find_odc_header(struct archive_read *); +static int find_newc_header(struct archive_read *); +static int header_bin_be(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); +static int header_bin_le(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); +static int header_newc(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); +static int header_odc(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); +static int is_octal(const char *, size_t); +static int is_hex(const char *, size_t); +static int le4(const unsigned char *); +static void record_hardlink(struct cpio *cpio, struct archive_entry *entry); + +int +archive_read_support_format_cpio(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct cpio *cpio; + int r; + + cpio = (struct cpio *)malloc(sizeof(*cpio)); + if (cpio == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); + return (ARCHIVE_FATAL); + } + memset(cpio, 0, sizeof(*cpio)); + cpio->magic = CPIO_MAGIC; + + r = __archive_read_register_format(a, + cpio, + "cpio", + archive_read_format_cpio_bid, + NULL, + archive_read_format_cpio_read_header, + archive_read_format_cpio_read_data, + NULL, + archive_read_format_cpio_cleanup); + + if (r != ARCHIVE_OK) + free(cpio); + return (ARCHIVE_OK); +} + + +static int +archive_read_format_cpio_bid(struct archive_read *a) +{ + const void *h; + const unsigned char *p; + struct cpio *cpio; + int bid; + + cpio = (struct cpio *)(a->format->data); + + if ((h = __archive_read_ahead(a, 6, NULL)) == NULL) + return (-1); + + p = (const unsigned char *)h; + bid = 0; + if (memcmp(p, "070707", 6) == 0) { + /* ASCII cpio archive (odc, POSIX.1) */ + cpio->read_header = header_odc; + bid += 48; + /* + * XXX TODO: More verification; Could check that only octal + * digits appear in appropriate header locations. XXX + */ + } else if (memcmp(p, "070701", 6) == 0) { + /* ASCII cpio archive (SVR4 without CRC) */ + cpio->read_header = header_newc; + bid += 48; + /* + * XXX TODO: More verification; Could check that only hex + * digits appear in appropriate header locations. XXX + */ + } else if (memcmp(p, "070702", 6) == 0) { + /* ASCII cpio archive (SVR4 with CRC) */ + /* XXX TODO: Flag that we should check the CRC. XXX */ + cpio->read_header = header_newc; + bid += 48; + /* + * XXX TODO: More verification; Could check that only hex + * digits appear in appropriate header locations. XXX + */ + } else if (p[0] * 256 + p[1] == 070707) { + /* big-endian binary cpio archives */ + cpio->read_header = header_bin_be; + bid += 16; + /* Is more verification possible here? */ + } else if (p[0] + p[1] * 256 == 070707) { + /* little-endian binary cpio archives */ + cpio->read_header = header_bin_le; + bid += 16; + /* Is more verification possible here? */ + } else + return (ARCHIVE_WARN); + + return (bid); +} + +static int +archive_read_format_cpio_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + struct cpio *cpio; + const void *h; + size_t namelength; + size_t name_pad; + int r; + + cpio = (struct cpio *)(a->format->data); + r = (cpio->read_header(a, cpio, entry, &namelength, &name_pad)); + + if (r < ARCHIVE_WARN) + return (r); + + /* Read name from buffer. */ + h = __archive_read_ahead(a, namelength + name_pad, NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + __archive_read_consume(a, namelength + name_pad); + archive_strncpy(&cpio->entry_name, (const char *)h, namelength); + archive_entry_set_pathname(entry, cpio->entry_name.s); + cpio->entry_offset = 0; + + /* If this is a symlink, read the link contents. */ + if (archive_entry_filetype(entry) == AE_IFLNK) { + h = __archive_read_ahead(a, cpio->entry_bytes_remaining, NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + __archive_read_consume(a, cpio->entry_bytes_remaining); + archive_strncpy(&cpio->entry_linkname, (const char *)h, + cpio->entry_bytes_remaining); + archive_entry_set_symlink(entry, cpio->entry_linkname.s); + cpio->entry_bytes_remaining = 0; + } + + /* XXX TODO: If the full mode is 0160200, then this is a Solaris + * ACL description for the following entry. Read this body + * and parse it as a Solaris-style ACL, then read the next + * header. XXX */ + + /* Compare name to "TRAILER!!!" to test for end-of-archive. */ + if (namelength == 11 && strcmp((const char *)h, "TRAILER!!!") == 0) { + /* TODO: Store file location of start of block. */ + archive_set_error(&a->archive, 0, NULL); + return (ARCHIVE_EOF); + } + + /* Detect and record hardlinks to previously-extracted entries. */ + record_hardlink(cpio, entry); + + return (r); +} + +static int +archive_read_format_cpio_read_data(struct archive_read *a, + const void **buff, size_t *size, off_t *offset) +{ + ssize_t bytes_read; + struct cpio *cpio; + + cpio = (struct cpio *)(a->format->data); + if (cpio->entry_bytes_remaining > 0) { + *buff = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read <= 0) + return (ARCHIVE_FATAL); + if (bytes_read > cpio->entry_bytes_remaining) + bytes_read = cpio->entry_bytes_remaining; + *size = bytes_read; + *offset = cpio->entry_offset; + cpio->entry_offset += bytes_read; + cpio->entry_bytes_remaining -= bytes_read; + __archive_read_consume(a, bytes_read); + return (ARCHIVE_OK); + } else { + while (cpio->entry_padding > 0) { + *buff = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read <= 0) + return (ARCHIVE_FATAL); + if (bytes_read > cpio->entry_padding) + bytes_read = cpio->entry_padding; + __archive_read_consume(a, bytes_read); + cpio->entry_padding -= bytes_read; + } + *buff = NULL; + *size = 0; + *offset = cpio->entry_offset; + return (ARCHIVE_EOF); + } +} + +/* + * Skip forward to the next cpio newc header by searching for the + * 07070[12] string. This should be generalized and merged with + * find_odc_header below. + */ +static int +is_hex(const char *p, size_t len) +{ + while (len-- > 0) { + if ((*p >= '0' && *p <= '9') + || (*p >= 'a' && *p <= 'f') + || (*p >= 'A' && *p <= 'F')) + ++p; + else + return (0); + } + return (1); +} + +static int +find_newc_header(struct archive_read *a) +{ + const void *h; + const char *p, *q; + size_t skip, skipped = 0; + ssize_t bytes; + + for (;;) { + h = __archive_read_ahead(a, sizeof(struct cpio_newc_header), &bytes); + if (h == NULL) + return (ARCHIVE_FATAL); + p = h; + q = p + bytes; + + /* Try the typical case first, then go into the slow search.*/ + if (memcmp("07070", p, 5) == 0 + && (p[5] == '1' || p[5] == '2') + && is_hex(p, sizeof(struct cpio_newc_header))) + return (ARCHIVE_OK); + + /* + * Scan ahead until we find something that looks + * like an odc header. + */ + while (p + sizeof(struct cpio_newc_header) <= q) { + switch (p[5]) { + case '1': + case '2': + if (memcmp("07070", p, 5) == 0 + && is_hex(p, sizeof(struct cpio_newc_header))) { + skip = p - (const char *)h; + __archive_read_consume(a, skip); + skipped += skip; + if (skipped > 0) { + archive_set_error(&a->archive, + 0, + "Skipped %d bytes before " + "finding valid header", + (int)skipped); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); + } + p += 2; + break; + case '0': + p++; + break; + default: + p += 6; + break; + } + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + skipped += skip; + } +} + +static int +header_newc(struct archive_read *a, struct cpio *cpio, + struct archive_entry *entry, size_t *namelength, size_t *name_pad) +{ + const void *h; + const struct cpio_newc_header *header; + int r; + + r = find_newc_header(a); + if (r < ARCHIVE_WARN) + return (r); + + /* Read fixed-size portion of header. */ + h = __archive_read_ahead(a, sizeof(struct cpio_newc_header), NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + __archive_read_consume(a, sizeof(struct cpio_newc_header)); + + /* Parse out hex fields. */ + header = (const struct cpio_newc_header *)h; + + if (memcmp(header->c_magic, "070701", 6) == 0) { + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC; + a->archive.archive_format_name = "ASCII cpio (SVR4 with no CRC)"; + } else if (memcmp(header->c_magic, "070702", 6) == 0) { + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_CRC; + a->archive.archive_format_name = "ASCII cpio (SVR4 with CRC)"; + } else { + /* TODO: Abort here? */ + } + + archive_entry_set_devmajor(entry, atol16(header->c_devmajor, sizeof(header->c_devmajor))); + archive_entry_set_devminor(entry, atol16(header->c_devminor, sizeof(header->c_devminor))); + archive_entry_set_ino(entry, atol16(header->c_ino, sizeof(header->c_ino))); + archive_entry_set_mode(entry, atol16(header->c_mode, sizeof(header->c_mode))); + archive_entry_set_uid(entry, atol16(header->c_uid, sizeof(header->c_uid))); + archive_entry_set_gid(entry, atol16(header->c_gid, sizeof(header->c_gid))); + archive_entry_set_nlink(entry, atol16(header->c_nlink, sizeof(header->c_nlink))); + archive_entry_set_rdevmajor(entry, atol16(header->c_rdevmajor, sizeof(header->c_rdevmajor))); + archive_entry_set_rdevminor(entry, atol16(header->c_rdevminor, sizeof(header->c_rdevminor))); + archive_entry_set_mtime(entry, atol16(header->c_mtime, sizeof(header->c_mtime)), 0); + *namelength = atol16(header->c_namesize, sizeof(header->c_namesize)); + /* Pad name to 2 more than a multiple of 4. */ + *name_pad = (2 - *namelength) & 3; + + /* + * Note: entry_bytes_remaining is at least 64 bits and + * therefore guaranteed to be big enough for a 33-bit file + * size. + */ + cpio->entry_bytes_remaining = + atol16(header->c_filesize, sizeof(header->c_filesize)); + archive_entry_set_size(entry, cpio->entry_bytes_remaining); + /* Pad file contents to a multiple of 4. */ + cpio->entry_padding = 3 & -cpio->entry_bytes_remaining; + return (r); +} + +/* + * Skip forward to the next cpio odc header by searching for the + * 070707 string. This is a hand-optimized search that could + * probably be easily generalized to handle all character-based + * cpio variants. + */ +static int +is_octal(const char *p, size_t len) +{ + while (len-- > 0) { + if (*p < '0' || *p > '7') + return (0); + ++p; + } + return (1); +} + +static int +find_odc_header(struct archive_read *a) +{ + const void *h; + const char *p, *q; + size_t skip, skipped = 0; + ssize_t bytes; + + for (;;) { + h = __archive_read_ahead(a, sizeof(struct cpio_odc_header), &bytes); + if (h == NULL) + return (ARCHIVE_FATAL); + p = h; + q = p + bytes; + + /* Try the typical case first, then go into the slow search.*/ + if (memcmp("070707", p, 6) == 0 + && is_octal(p, sizeof(struct cpio_odc_header))) + return (ARCHIVE_OK); + + /* + * Scan ahead until we find something that looks + * like an odc header. + */ + while (p + sizeof(struct cpio_odc_header) <= q) { + switch (p[5]) { + case '7': + if (memcmp("070707", p, 6) == 0 + && is_octal(p, sizeof(struct cpio_odc_header))) { + skip = p - (const char *)h; + __archive_read_consume(a, skip); + skipped += skip; + if (skipped > 0) { + archive_set_error(&a->archive, + 0, + "Skipped %d bytes before " + "finding valid header", + (int)skipped); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); + } + p += 2; + break; + case '0': + p++; + break; + default: + p += 6; + break; + } + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + skipped += skip; + } +} + +static int +header_odc(struct archive_read *a, struct cpio *cpio, + struct archive_entry *entry, size_t *namelength, size_t *name_pad) +{ + const void *h; + int r; + const struct cpio_odc_header *header; + + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX; + a->archive.archive_format_name = "POSIX octet-oriented cpio"; + + /* Find the start of the next header. */ + r = find_odc_header(a); + if (r < ARCHIVE_WARN) + return (r); + + /* Read fixed-size portion of header. */ + h = __archive_read_ahead(a, sizeof(struct cpio_odc_header), NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + __archive_read_consume(a, sizeof(struct cpio_odc_header)); + + /* Parse out octal fields. */ + header = (const struct cpio_odc_header *)h; + + archive_entry_set_dev(entry, atol8(header->c_dev, sizeof(header->c_dev))); + archive_entry_set_ino(entry, atol8(header->c_ino, sizeof(header->c_ino))); + archive_entry_set_mode(entry, atol8(header->c_mode, sizeof(header->c_mode))); + archive_entry_set_uid(entry, atol8(header->c_uid, sizeof(header->c_uid))); + archive_entry_set_gid(entry, atol8(header->c_gid, sizeof(header->c_gid))); + archive_entry_set_nlink(entry, atol8(header->c_nlink, sizeof(header->c_nlink))); + archive_entry_set_rdev(entry, atol8(header->c_rdev, sizeof(header->c_rdev))); + archive_entry_set_mtime(entry, atol8(header->c_mtime, sizeof(header->c_mtime)), 0); + *namelength = atol8(header->c_namesize, sizeof(header->c_namesize)); + *name_pad = 0; /* No padding of filename. */ + + /* + * Note: entry_bytes_remaining is at least 64 bits and + * therefore guaranteed to be big enough for a 33-bit file + * size. + */ + cpio->entry_bytes_remaining = + atol8(header->c_filesize, sizeof(header->c_filesize)); + archive_entry_set_size(entry, cpio->entry_bytes_remaining); + cpio->entry_padding = 0; + return (r); +} + +static int +header_bin_le(struct archive_read *a, struct cpio *cpio, + struct archive_entry *entry, size_t *namelength, size_t *name_pad) +{ + const void *h; + const struct cpio_bin_header *header; + + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_LE; + a->archive.archive_format_name = "cpio (little-endian binary)"; + + /* Read fixed-size portion of header. */ + h = __archive_read_ahead(a, sizeof(struct cpio_bin_header), NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + __archive_read_consume(a, sizeof(struct cpio_bin_header)); + + /* Parse out binary fields. */ + header = (const struct cpio_bin_header *)h; + + archive_entry_set_dev(entry, header->c_dev[0] + header->c_dev[1] * 256); + archive_entry_set_ino(entry, header->c_ino[0] + header->c_ino[1] * 256); + archive_entry_set_mode(entry, header->c_mode[0] + header->c_mode[1] * 256); + archive_entry_set_uid(entry, header->c_uid[0] + header->c_uid[1] * 256); + archive_entry_set_gid(entry, header->c_gid[0] + header->c_gid[1] * 256); + archive_entry_set_nlink(entry, header->c_nlink[0] + header->c_nlink[1] * 256); + archive_entry_set_rdev(entry, header->c_rdev[0] + header->c_rdev[1] * 256); + archive_entry_set_mtime(entry, le4(header->c_mtime), 0); + *namelength = header->c_namesize[0] + header->c_namesize[1] * 256; + *name_pad = *namelength & 1; /* Pad to even. */ + + cpio->entry_bytes_remaining = le4(header->c_filesize); + archive_entry_set_size(entry, cpio->entry_bytes_remaining); + cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */ + return (ARCHIVE_OK); +} + +static int +header_bin_be(struct archive_read *a, struct cpio *cpio, + struct archive_entry *entry, size_t *namelength, size_t *name_pad) +{ + const void *h; + const struct cpio_bin_header *header; + + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_BE; + a->archive.archive_format_name = "cpio (big-endian binary)"; + + /* Read fixed-size portion of header. */ + h = __archive_read_ahead(a, sizeof(struct cpio_bin_header), NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + __archive_read_consume(a, sizeof(struct cpio_bin_header)); + + /* Parse out binary fields. */ + header = (const struct cpio_bin_header *)h; + archive_entry_set_dev(entry, header->c_dev[0] * 256 + header->c_dev[1]); + archive_entry_set_ino(entry, header->c_ino[0] * 256 + header->c_ino[1]); + archive_entry_set_mode(entry, header->c_mode[0] * 256 + header->c_mode[1]); + archive_entry_set_uid(entry, header->c_uid[0] * 256 + header->c_uid[1]); + archive_entry_set_gid(entry, header->c_gid[0] * 256 + header->c_gid[1]); + archive_entry_set_nlink(entry, header->c_nlink[0] * 256 + header->c_nlink[1]); + archive_entry_set_rdev(entry, header->c_rdev[0] * 256 + header->c_rdev[1]); + archive_entry_set_mtime(entry, be4(header->c_mtime), 0); + *namelength = header->c_namesize[0] * 256 + header->c_namesize[1]; + *name_pad = *namelength & 1; /* Pad to even. */ + + cpio->entry_bytes_remaining = be4(header->c_filesize); + archive_entry_set_size(entry, cpio->entry_bytes_remaining); + cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */ + return (ARCHIVE_OK); +} + +static int +archive_read_format_cpio_cleanup(struct archive_read *a) +{ + struct cpio *cpio; + + cpio = (struct cpio *)(a->format->data); + /* Free inode->name map */ + while (cpio->links_head != NULL) { + struct links_entry *lp = cpio->links_head->next; + + if (cpio->links_head->name) + free(cpio->links_head->name); + free(cpio->links_head); + cpio->links_head = lp; + } + archive_string_free(&cpio->entry_name); + free(cpio); + (a->format->data) = NULL; + return (ARCHIVE_OK); +} + +static int +le4(const unsigned char *p) +{ + return ((p[0]<<16) + (p[1]<<24) + (p[2]<<0) + (p[3]<<8)); +} + + +static int +be4(const unsigned char *p) +{ + return ((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + (p[3])); +} + +/* + * Note that this implementation does not (and should not!) obey + * locale settings; you cannot simply substitute strtol here, since + * it does obey locale. + */ +static int64_t +atol8(const char *p, unsigned char_cnt) +{ + int64_t l; + int digit; + + l = 0; + while (char_cnt-- > 0) { + if (*p >= '0' && *p <= '7') + digit = *p - '0'; + else + return (l); + p++; + l <<= 3; + l |= digit; + } + return (l); +} + +static int64_t +atol16(const char *p, unsigned char_cnt) +{ + int64_t l; + int digit; + + l = 0; + while (char_cnt-- > 0) { + if (*p >= 'a' && *p <= 'f') + digit = *p - 'a' + 10; + else if (*p >= 'A' && *p <= 'F') + digit = *p - 'A' + 10; + else if (*p >= '0' && *p <= '9') + digit = *p - '0'; + else + return (l); + p++; + l <<= 4; + l |= digit; + } + return (l); +} + +static void +record_hardlink(struct cpio *cpio, struct archive_entry *entry) +{ + struct links_entry *le; + dev_t dev; + int64_t ino; + + if (archive_entry_nlink(entry) <= 1) + return; + + dev = archive_entry_dev(entry); + ino = archive_entry_ino64(entry); + + /* + * First look in the list of multiply-linked files. If we've + * already dumped it, convert this entry to a hard link entry. + */ + for (le = cpio->links_head; le; le = le->next) { + if (le->dev == dev && le->ino == ino) { + archive_entry_copy_hardlink(entry, le->name); + + if (--le->links <= 0) { + if (le->previous != NULL) + le->previous->next = le->next; + if (le->next != NULL) + le->next->previous = le->previous; + if (cpio->links_head == le) + cpio->links_head = le->next; + free(le->name); + free(le); + } + + return; + } + } + + le = (struct links_entry *)malloc(sizeof(struct links_entry)); + if (le == NULL) + __archive_errx(1, "Out of memory adding file to list"); + if (cpio->links_head != NULL) + cpio->links_head->previous = le; + le->next = cpio->links_head; + le->previous = NULL; + cpio->links_head = le; + le->dev = dev; + le->ino = ino; + le->links = archive_entry_nlink(entry) - 1; + le->name = strdup(archive_entry_pathname(entry)); + if (le->name == NULL) + __archive_errx(1, "Out of memory adding file to list"); +} diff --git a/lib/libarchive/archive_read_support_format_empty.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_empty.c similarity index 100% rename from lib/libarchive/archive_read_support_format_empty.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_format_empty.c diff --git a/lib/libarchive/archive_read_support_format_iso9660.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_iso9660.c similarity index 99% rename from lib/libarchive/archive_read_support_format_iso9660.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_format_iso9660.c index 0c640c88e..4be672db6 100644 --- a/lib/libarchive/archive_read_support_format_iso9660.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_iso9660.c @@ -919,7 +919,7 @@ read_children(struct archive_read *a, struct file_info *parent) if (parent->offset + parent->size > iso9660->volume_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Directory is beyond end-of-media: %s", - parent->name); + parent->name.s); return (ARCHIVE_WARN); } if (iso9660->current_position < parent->offset) { @@ -1215,7 +1215,7 @@ archive_read_format_iso9660_read_header(struct archive_read *a, if (file->offset + file->size > iso9660->volume_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "File is beyond end-of-media: %s", file->name); + "File is beyond end-of-media: %s", file->name.s); iso9660->entry_bytes_remaining = 0; iso9660->entry_sparse_offset = 0; return (ARCHIVE_WARN); @@ -1274,7 +1274,7 @@ archive_read_format_iso9660_read_header(struct archive_read *a, if ((file->mode & AE_IFMT) != AE_IFDIR && file->offset < iso9660->current_position) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring out-of-order file @%x (%s) %jd < %jd", + "Ignoring out-of-order file @%p (%s) %jd < %jd", file, iso9660->pathname.s, file->offset, iso9660->current_position); diff --git a/lib/libarchive/archive_read_support_format_mtree.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_mtree.c similarity index 93% rename from lib/libarchive/archive_read_support_format_mtree.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_format_mtree.c index 6c35298e2..21d421e31 100644 --- a/lib/libarchive/archive_read_support_format_mtree.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_mtree.c @@ -116,15 +116,9 @@ static ssize_t readline(struct archive_read *, struct mtree *, char **, ssize_t) static int skip(struct archive_read *a); static int read_header(struct archive_read *, struct archive_entry *); -#ifndef __minix static int64_t mtree_atol10(char **); static int64_t mtree_atol8(char **); static int64_t mtree_atol(char **); -#else -static int32_t mtree_atol10(char **); -static int32_t mtree_atol8(char **); -static int32_t mtree_atol(char **); -#endif static void free_options(struct mtree_option *head) @@ -376,7 +370,7 @@ process_add_entry(struct archive_read *a, struct mtree *mtree, line = next; next = line + strcspn(line, " \t\r\n"); eq = strchr(line, '='); - if (eq > next) + if (eq == NULL || eq > next) len = next - line; else len = eq - line; @@ -1113,7 +1107,6 @@ parse_escapes(char *src, struct mtree_entry *mentry) * locale settings; you cannot simply substitute strtol here, since * it does obey locale. */ -#ifndef __minix static int64_t mtree_atol8(char **p) { @@ -1136,37 +1129,12 @@ mtree_atol8(char **p) } return (l); } -#else -static int32_t -mtree_atol8(char **p) -{ - int32_t l, limit, last_digit_limit; - int digit, base; - - base = 8; - limit = INT32_MAX / base; - last_digit_limit = INT32_MAX % base; - - l = 0; - digit = **p - '0'; - while (digit >= 0 && digit < base) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = INT32_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++(*p) - '0'; - } - return (l); -} -#endif /* * Note that this implementation does not (and should not!) obey * locale settings; you cannot simply substitute strtol here, since * it does obey locale. */ -#ifndef __minix static int64_t mtree_atol10(char **p) { @@ -1195,42 +1163,12 @@ mtree_atol10(char **p) } return (sign < 0) ? -l : l; } -#else -static int32_t -mtree_atol10(char **p) -{ - int32_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 10; - limit = INT32_MAX / base; - last_digit_limit = INT32_MAX % base; - - if (**p == '-') { - sign = -1; - ++(*p); - } else - sign = 1; - l = 0; - digit = **p - '0'; - while (digit >= 0 && digit < base) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = INT32_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++(*p) - '0'; - } - return (sign < 0) ? -l : l; -} -#endif /* * Note that this implementation does not (and should not!) obey * locale settings; you cannot simply substitute strtol here, since * it does obey locale. */ -#ifndef __minix static int64_t mtree_atol16(char **p) { @@ -1273,52 +1211,7 @@ mtree_atol16(char **p) } return (sign < 0) ? -l : l; } -#else -static int32_t -mtree_atol16(char **p) -{ - int32_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 16; - limit = INT32_MAX / base; - last_digit_limit = INT32_MAX % base; - - if (**p == '-') { - sign = -1; - ++(*p); - } else - sign = 1; - - l = 0; - if (**p >= '0' && **p <= '9') - digit = **p - '0'; - else if (**p >= 'a' && **p <= 'f') - digit = **p - 'a' + 10; - else if (**p >= 'A' && **p <= 'F') - digit = **p - 'A' + 10; - else - digit = -1; - while (digit >= 0 && digit < base) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = INT32_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - if (**p >= '0' && **p <= '9') - digit = **p - '0'; - else if (**p >= 'a' && **p <= 'f') - digit = **p - 'a' + 10; - else if (**p >= 'A' && **p <= 'F') - digit = **p - 'A' + 10; - else - digit = -1; - } - return (sign < 0) ? -l : l; -} -#endif -#ifndef __minix static int64_t mtree_atol(char **p) { @@ -1330,19 +1223,7 @@ mtree_atol(char **p) } return mtree_atol8(p); } -#else -static int32_t -mtree_atol(char **p) -{ - if (**p != '0') - return mtree_atol10(p); - if ((*p)[1] == 'x' || (*p)[1] == 'X') { - *p += 2; - return mtree_atol16(p); - } - return mtree_atol8(p); -} -#endif + /* * Returns length of line (including trailing newline) * or negative on error. 'start' argument is updated to diff --git a/lib/libarchive/archive_read_support_format_raw.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_raw.c similarity index 97% rename from lib/libarchive/archive_read_support_format_raw.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_format_raw.c index 818b64c9e..7a8481bf2 100644 --- a/lib/libarchive/archive_read_support_format_raw.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_raw.c @@ -39,11 +39,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_raw.c 201107 #include "archive_read_private.h" struct raw_info { -#ifndef __minix int64_t offset; /* Current position in the file. */ -#else - off_t offset; -#endif int end_of_file; }; @@ -159,11 +155,7 @@ archive_read_format_raw_read_data_skip(struct archive_read *a) { struct raw_info *info; off_t bytes_skipped; -#ifndef __minix int64_t request = 1024 * 1024 * 1024UL; /* Skip 1 GB at a time. */ -#else - int32_t request = 1024 * 1024 * 1024UL; /* Skip 1 GB at a time. */ -#endif info = (struct raw_info *)(a->format->data); if (info->end_of_file) diff --git a/lib/libarchive/archive_read_support_format_tar.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_tar.c similarity index 91% rename from lib/libarchive/archive_read_support_format_tar.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_format_tar.c index f93c164f4..dae13dc6e 100644 --- a/lib/libarchive/archive_read_support_format_tar.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_tar.c @@ -26,9 +26,6 @@ #include "archive_platform.h" __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_tar.c 201161 2009-12-29 05:44:39Z kientzle $"); -#include -#include - #ifdef HAVE_ERRNO_H #include #endif @@ -162,26 +159,14 @@ struct tar { wchar_t *pax_entry; size_t pax_entry_length; int header_recursion_depth; -#ifndef __minix int64_t entry_bytes_remaining; int64_t entry_offset; int64_t entry_padding; int64_t realsize; -#else - int32_t entry_bytes_remaining; - off_t entry_offset; - off_t entry_padding; - int32_t realsize; -#endif struct sparse_block *sparse_list; struct sparse_block *sparse_last; -#ifndef __minix int64_t sparse_offset; int64_t sparse_numbytes; -#else - off_t sparse_offset; - size_t sparse_numbytes; -#endif int sparse_gnu_major; int sparse_gnu_minor; char sparse_gnu_pending; @@ -231,26 +216,15 @@ static int pax_attribute(struct tar *, struct archive_entry *, char *key, char *value); static int pax_header(struct archive_read *, struct tar *, struct archive_entry *, char *attr); -#ifndef __minix static void pax_time(const char *, int64_t *sec, long *nanos); -#else -static void pax_time(const char *, time_t *sec, long *nanos); -#endif static ssize_t readline(struct archive_read *, struct tar *, const char **, ssize_t limit); static int read_body_to_string(struct archive_read *, struct tar *, struct archive_string *, const void *h); -#ifndef __minix static int64_t tar_atol(const char *, unsigned); static int64_t tar_atol10(const char *, unsigned); static int64_t tar_atol256(const char *, unsigned); static int64_t tar_atol8(const char *, unsigned); -#else -static int32_t tar_atol(const char *, unsigned); -static int32_t tar_atol10(const char *, unsigned); -static int32_t tar_atol256(const char *, unsigned); -static int32_t tar_atol8(const char *, unsigned); -#endif static int tar_read_header(struct archive_read *, struct tar *, struct archive_entry *); static int tohex(int c); @@ -535,11 +509,7 @@ archive_read_format_tar_read_data(struct archive_read *a, static int archive_read_format_tar_skip(struct archive_read *a) { -#ifndef __minix int64_t bytes_skipped; -#else - int32_t bytes_skipped; -#endif struct tar* tar; tar = (struct tar *)(a->format->data); @@ -762,11 +732,7 @@ header_Solaris_ACL(struct archive_read *a, struct tar *tar, const struct archive_entry_header_ustar *header; size_t size; int err; -#ifndef __minix int64_t type; -#else - int32_t type; -#endif char *acl, *p; wchar_t *wp; @@ -951,11 +917,8 @@ static int header_common(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { - int err = ARCHIVE_OK; const struct archive_entry_header_ustar *header; char tartype; - uid_t uid; - gid_t gid; (void)a; /* UNUSED */ @@ -968,85 +931,8 @@ header_common(struct archive_read *a, struct tar *tar, /* Parse out the numeric fields (all are octal) */ archive_entry_set_mode(entry, tar_atol(header->mode, sizeof(header->mode))); - - uid = (uid_t) tar_atol(header->uid, sizeof(header->uid)); - - /* Sanity check: uid overflow. Some systems have a limited uid_t. - * For example, Minix 3.2.0 has 16-bit uids. - */ - if (uid != tar_atol(header->uid, sizeof(header->uid))) { - - /* This isn't a fatal error, so we try to set the uid to - * the uid of the "nobody" user or 99. - */ - - static int warned = 0; - static struct passwd *nobodyuser = NULL; - - if (nobodyuser == NULL) { - nobodyuser = getpwnam("nobody"); - } - - if (nobodyuser != NULL) { - uid = nobodyuser->pw_uid; - } else { - uid = (uid_t) 99; - } - - if (warned == 0) { - archive_set_error(&a->archive, EINVAL, - "uid %ld out of range; will be extracted as %d.", - tar_atol(header->uid, sizeof(header->uid)), - uid); - - warned = 1; /* only warn once about invalid uid */ - err = ARCHIVE_WARN; - } - } - - archive_entry_set_uid(entry, uid); - - gid = (gid_t) tar_atol(header->gid, sizeof(header->gid)); - - /* Sanity check: gid overflow. Some systems have a limited gid_t. - * For example, Minix 3.2.0 has 8-bit gids. - */ - if (gid != tar_atol(header->gid, sizeof(header->gid))) { - - /* This isn't a fatal error, so we try to set the gid to - * the gid of the "nobody" or "nogroup" group or 99. - */ - - static int warned = 0; - static struct group *nobodygroup = NULL; - - if (nobodygroup == NULL) { - - nobodygroup = getgrnam("nobody"); - if (nobodygroup == NULL) { - nobodygroup = getgrnam("nogroup"); - } - } - - if (nobodygroup != NULL) { - gid = nobodygroup->gr_gid; - } else { - gid = (gid_t) 99; - } - - if (warned == 0) { - archive_set_error(&a->archive, EINVAL, - "gid %ld out of range; will be extracted as %d", - tar_atol(header->gid, sizeof(header->gid)), - gid); - - warned = 1; /* only warn once about invalid gid */ - err = ARCHIVE_WARN; - } - } - - archive_entry_set_gid(entry, gid); - + archive_entry_set_uid(entry, tar_atol(header->uid, sizeof(header->uid))); + archive_entry_set_gid(entry, tar_atol(header->gid, sizeof(header->gid))); tar->entry_bytes_remaining = tar_atol(header->size, sizeof(header->size)); tar->realsize = tar->entry_bytes_remaining; archive_entry_set_size(entry, tar->entry_bytes_remaining); @@ -1177,8 +1063,7 @@ header_common(struct archive_read *a, struct tar *tar, archive_entry_set_filetype(entry, AE_IFREG); break; } - - return err; + return (0); } /* @@ -1188,7 +1073,6 @@ static int header_old_tar(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { - int err; const struct archive_entry_header_ustar *header; /* Copy filename over (to ensure null termination). */ @@ -1197,10 +1081,10 @@ header_old_tar(struct archive_read *a, struct tar *tar, archive_entry_copy_pathname(entry, tar->entry_pathname.s); /* Grab rest of common fields */ - err = header_common(a, tar, entry, h); + header_common(a, tar, entry, h); tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - return err; + return (0); } /* @@ -1259,7 +1143,6 @@ static int header_ustar(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { - int err; const struct archive_entry_header_ustar *header; struct archive_string *as; @@ -1278,7 +1161,7 @@ header_ustar(struct archive_read *a, struct tar *tar, archive_entry_copy_pathname(entry, as->s); /* Handle rest of common fields. */ - err = header_common(a, tar, entry, h); + header_common(a, tar, entry, h); /* Handle POSIX ustar fields. */ archive_strncpy(&(tar->entry_uname), header->uname, @@ -1299,7 +1182,7 @@ header_ustar(struct archive_read *a, struct tar *tar, tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - return err; + return (0); } @@ -1515,11 +1398,7 @@ static int pax_attribute(struct tar *tar, struct archive_entry *entry, char *key, char *value) { -#ifndef __minix int64_t s; -#else - time_t s; -#endif long n; wchar_t *wp; @@ -1729,7 +1608,6 @@ pax_attribute(struct tar *tar, struct archive_entry *entry, /* * parse a decimal time value, which may include a fractional portion */ -#ifndef __minix static void pax_time(const char *p, int64_t *ps, long *pn) { @@ -1776,54 +1654,7 @@ pax_time(const char *p, int64_t *ps, long *pn) break; } while (l /= 10); } -#else -static void -pax_time(const char *p, time_t *ps, long *pn) -{ - char digit; - time_t s; - unsigned long l; - int sign; - int32_t limit, last_digit_limit; - - limit = INT32_MAX / 10; - last_digit_limit = INT32_MAX % 10; - - s = 0; - sign = 1; - if (*p == '-') { - sign = -1; - p++; - } - while (*p >= '0' && *p <= '9') { - digit = *p - '0'; - if (s > limit || - (s == limit && digit > last_digit_limit)) { - s = INT32_MAX; - break; - } - s = (s * 10) + digit; - ++p; - } - *ps = s * sign; - - /* Calculate nanoseconds. */ - *pn = 0; - - if (*p != '.') - return; - - l = 100000000UL; - do { - ++p; - if (*p >= '0' && *p <= '9') - *pn += (*p - '0') * l; - else - break; - } while (l /= 10); -} -#endif /* * Parse GNU tar header */ @@ -1831,7 +1662,6 @@ static int header_gnutar(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { - int err; const struct archive_entry_header_gnutar *header; (void)a; @@ -1843,7 +1673,7 @@ header_gnutar(struct archive_read *a, struct tar *tar, */ /* Grab fields common to all tar variants. */ - err = header_common(a, tar, entry, h); + header_common(a, tar, entry, h); /* Copy filename over (to ensure null termination). */ header = (const struct archive_entry_header_gnutar *)h; @@ -1893,7 +1723,7 @@ header_gnutar(struct archive_read *a, struct tar *tar, } } - return err; + return (0); } static void @@ -2067,7 +1897,6 @@ gnu_sparse_01_parse(struct tar *tar, const char *p) * integer followed by '\n'. Returns positive integer value or * negative on error. */ -#ifndef __minix static int64_t gnu_sparse_10_atol(struct archive_read *a, struct tar *tar, ssize_t *remaining) @@ -2109,49 +1938,7 @@ gnu_sparse_10_atol(struct archive_read *a, struct tar *tar, /* TODO: Error message. */ return (ARCHIVE_WARN); } -#else -static int32_t -gnu_sparse_10_atol(struct archive_read *a, struct tar *tar, - ssize_t *remaining) -{ - int32_t l, limit, last_digit_limit; - const char *p; - ssize_t bytes_read; - int base, digit; - - base = 10; - limit = INT32_MAX / base; - last_digit_limit = INT32_MAX % base; - - /* - * Skip any lines starting with '#'; GNU tar specs - * don't require this, but they should. - */ - do { - bytes_read = readline(a, tar, &p, tar_min(*remaining, 100)); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - *remaining -= bytes_read; - } while (p[0] == '#'); - l = 0; - while (bytes_read > 0) { - if (*p == '\n') - return (l); - if (*p < '0' || *p >= '0' + base) - return (ARCHIVE_WARN); - digit = *p - '0'; - if (l > limit || (l == limit && digit > last_digit_limit)) - l = INT32_MAX; /* Truncate on overflow. */ - else - l = (l * base) + digit; - p++; - bytes_read--; - } - /* TODO: Error message. */ - return (ARCHIVE_WARN); -} -#endif /* * Returns length (in bytes) of the sparse data description * that was read. @@ -2209,7 +1996,6 @@ gnu_sparse_10_read(struct archive_read *a, struct tar *tar) * * On read, this implementation supports both extensions. */ -#ifndef __minix static int64_t tar_atol(const char *p, unsigned char_cnt) { @@ -2221,26 +2007,12 @@ tar_atol(const char *p, unsigned char_cnt) return (tar_atol256(p, char_cnt)); return (tar_atol8(p, char_cnt)); } -#else -static int32_t -tar_atol(const char *p, unsigned char_cnt) -{ - /* - * Technically, GNU tar considers a field to be in base-256 - * only if the first byte is 0xff or 0x80. - */ - if (*p & 0x80) - return (tar_atol256(p, char_cnt)); - return (tar_atol8(p, char_cnt)); -} -#endif /* * Note that this implementation does not (and should not!) obey * locale settings; you cannot simply substitute strtol here, since * it does obey locale. */ -#ifndef __minix static int64_t tar_atol8(const char *p, unsigned char_cnt) { @@ -2271,44 +2043,12 @@ tar_atol8(const char *p, unsigned char_cnt) } return (sign < 0) ? -l : l; } -#else -static int32_t -tar_atol8(const char *p, unsigned char_cnt) -{ - int32_t l, limit, last_digit_limit; - int digit, sign, base; - base = 8; - limit = INT32_MAX / base; - last_digit_limit = INT32_MAX % base; - - while (*p == ' ' || *p == '\t') - p++; - if (*p == '-') { - sign = -1; - p++; - } else - sign = 1; - - l = 0; - digit = *p - '0'; - while (digit >= 0 && digit < base && char_cnt-- > 0) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = INT32_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (sign < 0) ? -l : l; -} -#endif /* * Note that this implementation does not (and should not!) obey * locale settings; you cannot simply substitute strtol here, since * it does obey locale. */ -#ifndef __minix static int64_t tar_atol10(const char *p, unsigned char_cnt) { @@ -2339,44 +2079,12 @@ tar_atol10(const char *p, unsigned char_cnt) } return (sign < 0) ? -l : l; } -#else -static int32_t -tar_atol10(const char *p, unsigned char_cnt) -{ - int32_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 10; - limit = INT32_MAX / base; - last_digit_limit = INT32_MAX % base; - - while (*p == ' ' || *p == '\t') - p++; - if (*p == '-') { - sign = -1; - p++; - } else - sign = 1; - l = 0; - digit = *p - '0'; - while (digit >= 0 && digit < base && char_cnt-- > 0) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = INT32_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (sign < 0) ? -l : l; -} -#endif /* * Parse a base-256 integer. This is just a straight signed binary * value in big-endian order, except that the high-order bit is * ignored. */ -#ifndef __minix static int64_t tar_atol256(const char *_p, unsigned char_cnt) { @@ -2404,35 +2112,7 @@ tar_atol256(const char *_p, unsigned char_cnt) } return (l); } -#else -static int32_t -tar_atol256(const char *_p, unsigned char_cnt) -{ - int32_t l, upper_limit, lower_limit; - const unsigned char *p = (const unsigned char *)_p; - upper_limit = INT32_MAX / 256; - lower_limit = INT32_MIN / 256; - - /* Pad with 1 or 0 bits, depending on sign. */ - if ((0x40 & *p) == 0x40) - l = (int32_t)-1; - else - l = 0; - l = (l << 6) | (0x3f & *p++); - while (--char_cnt > 0) { - if (l > upper_limit) { - l = INT32_MAX; /* Truncate on overflow */ - break; - } else if (l < lower_limit) { - l = INT32_MIN; - break; - } - l = (l << 8) | (0xff & (int32_t)*p++); - } - return (l); -} -#endif /* * Returns length of line (including trailing newline) * or negative on error. 'start' argument is updated to diff --git a/lib/libarchive/archive_read_support_format_xar.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_xar.c similarity index 99% rename from lib/libarchive/archive_read_support_format_xar.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_format_xar.c index b91497542..e6ce6b516 100644 --- a/lib/libarchive/archive_read_support_format_xar.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_xar.c @@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include #endif +#include #ifdef HAVE_STDLIB_H #include #endif @@ -323,7 +324,7 @@ struct xar { enum enctype rd_encoding; z_stream stream; int stream_valid; -#ifdef HAVE_BZLIB_H +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) bz_stream bzstream; int bzstream_valid; #endif @@ -1323,7 +1324,7 @@ decompression_init(struct archive_read *a, enum enctype encoding) xar->stream.total_in = 0; xar->stream.total_out = 0; break; -#ifdef HAVE_BZLIB_H +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) case BZIP2: if (xar->bzstream_valid) { BZ2_bzDecompressEnd(&(xar->bzstream)); @@ -1436,7 +1437,7 @@ decompression_init(struct archive_read *a, enum enctype encoding) * Unsupported compression. */ default: -#ifndef HAVE_BZLIB_H +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) case BZIP2: #endif #if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA) @@ -1496,7 +1497,7 @@ decompress(struct archive_read *a, const void **buff, size_t *outbytes, *used = avail_in - xar->stream.avail_in; *outbytes = avail_out - xar->stream.avail_out; break; -#ifdef HAVE_BZLIB_H +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) case BZIP2: xar->bzstream.next_in = (char *)(uintptr_t)b; xar->bzstream.avail_in = avail_in; @@ -1587,7 +1588,7 @@ decompress(struct archive_read *a, const void **buff, size_t *outbytes, *outbytes = avail_out - xar->lzstream.avail_out; break; #endif -#ifndef HAVE_BZLIB_H +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) case BZIP2: #endif #if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA) @@ -1630,7 +1631,7 @@ decompression_cleanup(struct archive_read *a) r = ARCHIVE_FATAL; } } -#ifdef HAVE_BZLIB_H +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) if (xar->bzstream_valid) { if (BZ2_bzDecompressEnd(&(xar->bzstream)) != BZ_OK) { archive_set_error(&a->archive, diff --git a/lib/libarchive/archive_read_support_format_zip.c b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_zip.c similarity index 97% rename from lib/libarchive/archive_read_support_format_zip.c rename to external/bsd/libarchive/dist/libarchive/archive_read_support_format_zip.c index 8cf7f0dcf..207915708 100644 --- a/lib/libarchive/archive_read_support_format_zip.c +++ b/external/bsd/libarchive/dist/libarchive/archive_read_support_format_zip.c @@ -50,21 +50,13 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_zip.c 201102 struct zip { /* entry_bytes_remaining is the number of bytes we expect. */ -#ifndef __minix int64_t entry_bytes_remaining; int64_t entry_offset; -#else - size_t entry_bytes_remaining; - off_t entry_offset; -#endif + /* These count the number of bytes actually read for the entry. */ -#ifndef __minix int64_t entry_compressed_bytes_read; int64_t entry_uncompressed_bytes_read; -#else - size_t entry_compressed_bytes_read; - size_t entry_uncompressed_bytes_read; -#endif + /* Running CRC32 of the decompressed data */ unsigned long entry_crc32; @@ -87,13 +79,9 @@ struct zip { unsigned long crc32; ssize_t filename_length; ssize_t extra_length; -#ifndef __minix int64_t uncompressed_size; int64_t compressed_size; -#else - size_t uncompressed_size; - size_t compressed_size; -#endif + unsigned char *uncompressed_buffer; size_t uncompressed_buffer_size; #ifdef HAVE_ZLIB_H @@ -845,22 +833,11 @@ process_extra(const void* extra, struct zip* zip) switch (headerid) { case 0x0001: /* Zip64 extended information extra field. */ -#ifndef __minix if (datasize >= 8) zip->uncompressed_size = archive_le64dec(p + offset); if (datasize >= 16) zip->compressed_size = archive_le64dec(p + offset + 8); break; -#else - /* Minix file system does not support sizes that require 64 bit - * support so we can safely down cast this - */ - if (datasize >= 8) - zip->uncompressed_size = cv64ul(archive_le64dec(p + offset)); - if (datasize >= 16) - zip->compressed_size = cv64ul(archive_le64dec(p + offset + 8)); - break; -#endif case 0x5455: { /* Extended time field "UT". */ diff --git a/lib/libarchive/archive_string.c b/external/bsd/libarchive/dist/libarchive/archive_string.c similarity index 98% rename from lib/libarchive/archive_string.c rename to external/bsd/libarchive/dist/libarchive/archive_string.c index ce97e4d91..4e57d62e1 100644 --- a/lib/libarchive/archive_string.c +++ b/external/bsd/libarchive/dist/libarchive/archive_string.c @@ -291,13 +291,8 @@ __archive_string_utf8_w(struct archive_string *as) int wc, wc2;/* Must be large enough for a 21-bit Unicode code point. */ const char *src; int n; - size_t size; - /* be pessimistic; UCS4 always takes up four bytes per char while - * UTF-16 may takes four bytes per char (except the 0 terminator) - */ - size = as->length * 4 + sizeof(wchar_t); - ws = (wchar_t *)malloc(size); + ws = (wchar_t *)malloc((as->length + 1) * sizeof(wchar_t)); if (ws == NULL) __archive_errx(1, "Out of memory"); dest = ws; diff --git a/lib/libarchive/archive_string.h b/external/bsd/libarchive/dist/libarchive/archive_string.h similarity index 100% rename from lib/libarchive/archive_string.h rename to external/bsd/libarchive/dist/libarchive/archive_string.h diff --git a/lib/libarchive/archive_string_sprintf.c b/external/bsd/libarchive/dist/libarchive/archive_string_sprintf.c similarity index 100% rename from lib/libarchive/archive_string_sprintf.c rename to external/bsd/libarchive/dist/libarchive/archive_string_sprintf.c diff --git a/lib/libarchive/archive_util.3 b/external/bsd/libarchive/dist/libarchive/archive_util.3 similarity index 100% rename from lib/libarchive/archive_util.3 rename to external/bsd/libarchive/dist/libarchive/archive_util.3 diff --git a/lib/libarchive/archive_util.c b/external/bsd/libarchive/dist/libarchive/archive_util.c similarity index 97% rename from lib/libarchive/archive_util.c rename to external/bsd/libarchive/dist/libarchive/archive_util.c index be78d4cd9..c945d5fa7 100644 --- a/lib/libarchive/archive_util.c +++ b/external/bsd/libarchive/dist/libarchive/archive_util.c @@ -135,36 +135,21 @@ archive_compression_name(struct archive *a) /* * Return a count of the number of compressed bytes processed. */ -#ifndef __minix int64_t archive_position_compressed(struct archive *a) { return (a->raw_position); } -#else -off_t -archive_position_compressed(struct archive *a) -{ - return (a->raw_position); -} -#endif /* * Return a count of the number of uncompressed bytes processed. */ -#ifndef __minix int64_t archive_position_uncompressed(struct archive *a) { return (a->file_position); } -#else -off_t -archive_position_uncompressed(struct archive *a) -{ - return (a->file_position); -} -#endif + void archive_clear_error(struct archive *a) { @@ -257,7 +242,7 @@ __archive_parse_options(const char *p, const char *fn, int keysize, char *key, * (already detected format/filter-name) */ F_NAME, /* Getting option-value. */ - G_VALUE + G_VALUE, } state; p_org = p; diff --git a/lib/libarchive/archive_virtual.c b/external/bsd/libarchive/dist/libarchive/archive_virtual.c similarity index 100% rename from lib/libarchive/archive_virtual.c rename to external/bsd/libarchive/dist/libarchive/archive_virtual.c diff --git a/external/bsd/libarchive/dist/libarchive/archive_windows.c b/external/bsd/libarchive/dist/libarchive/archive_windows.c new file mode 100644 index 000000000..d9f29b72a --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/archive_windows.c @@ -0,0 +1,1236 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2007 Kees Zeelenberg + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * A set of compatibility glue for building libarchive on Windows platforms. + * + * Originally created as "libarchive-nonposix.c" by Kees Zeelenberg + * for the GnuWin32 project, trimmed significantly by Tim Kientzle. + * + * Much of the original file was unnecessary for libarchive, because + * many of the features it emulated were not strictly necessary for + * libarchive. I hope for this to shrink further as libarchive + * internals are gradually reworked to sit more naturally on both + * POSIX and Windows. Any ideas for this are greatly appreciated. + * + * The biggest remaining issue is the dev/ino emulation; libarchive + * has a couple of public APIs that rely on dev/ino uniquely + * identifying a file. This doesn't match well with Windows. I'm + * considering alternative APIs. + */ + +#if defined(_WIN32) && !defined(__CYGWIN__) + +#include "archive_platform.h" +#include "archive_private.h" +#include "archive_hash.h" +#include +#include +#include +#ifdef HAVE_SYS_UTIME_H +#include +#endif +#include +#include +#include +#include +#include + +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) + +#if defined(_MSC_VER) && _MSC_VER < 1300 +/* VS 6 does not provide SetFilePointerEx, so define it here. */ +static BOOL SetFilePointerEx(HANDLE hFile, + LARGE_INTEGER liDistanceToMove, + PLARGE_INTEGER lpNewFilePointer, + DWORD dwMoveMethod) +{ + LARGE_INTEGER li; + li.QuadPart = liDistanceToMove.QuadPart; + li.LowPart = SetFilePointer( + hFile, li.LowPart, &li.HighPart, dwMoveMethod); + if(lpNewFilePointer) { + lpNewFilePointer->QuadPart = li.QuadPart; + } + return li.LowPart != -1 || GetLastError() == NO_ERROR; +} +#endif + +struct ustat { + int64_t st_atime; + uint32_t st_atime_nsec; + int64_t st_ctime; + uint32_t st_ctime_nsec; + int64_t st_mtime; + uint32_t st_mtime_nsec; + gid_t st_gid; + /* 64bits ino */ + int64_t st_ino; + mode_t st_mode; + uint32_t st_nlink; + uint64_t st_size; + uid_t st_uid; + dev_t st_dev; + dev_t st_rdev; +}; + +/* Local replacement for undocumented Windows CRT function. */ +static void la_dosmaperr(unsigned long e); + +/* Transform 64-bits ino into 32-bits by hashing. + * You do not forget that really unique number size is 64-bits. + */ +#define INOSIZE (8*sizeof(ino_t)) /* 32 */ +static __inline ino_t +getino(struct ustat *ub) +{ + ULARGE_INTEGER ino64; + ino64.QuadPart = ub->st_ino; + /* I don't know this hashing is correct way */ + return (ino64.LowPart ^ (ino64.LowPart >> INOSIZE)); +} + +/* + * Prepend "\\?\" to the path name and convert it to unicode to permit + * an extended-length path for a maximum total path length of 32767 + * characters. + * see also http://msdn.microsoft.com/en-us/library/aa365247.aspx + */ +static wchar_t * +permissive_name(const char *name) +{ + wchar_t *wn, *wnp; + wchar_t *ws, *wsp; + DWORD l, len, slen; + int unc; + + len = (DWORD)strlen(name); + wn = malloc((len + 1) * sizeof(wchar_t)); + if (wn == NULL) + return (NULL); + l = MultiByteToWideChar(CP_ACP, 0, name, (int)len, wn, (int)len); + if (l == 0) { + free(wn); + return (NULL); + } + wn[l] = L'\0'; + + /* Get a full path names */ + l = GetFullPathNameW(wn, 0, NULL, NULL); + if (l == 0) { + free(wn); + return (NULL); + } + wnp = malloc(l * sizeof(wchar_t)); + if (wnp == NULL) { + free(wn); + return (NULL); + } + len = GetFullPathNameW(wn, l, wnp, NULL); + free(wn); + wn = wnp; + + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'?' && wnp[3] == L'\\') + /* We have already permissive names. */ + return (wn); + + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'.' && wnp[3] == L'\\') { + /* Device names */ + if (((wnp[4] >= L'a' && wnp[4] <= L'z') || + (wnp[4] >= L'A' && wnp[4] <= L'Z')) && + wnp[5] == L':' && wnp[6] == L'\\') + wnp[2] = L'?';/* Not device names. */ + return (wn); + } + + unc = 0; + if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') { + wchar_t *p = &wnp[2]; + + /* Skip server-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\') { + wchar_t *rp = ++p; + /* Skip share-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\' && p != rp) { + /* Now, match patterns such as + * "\\server-name\share-name\" */ + wnp += 2; + len -= 2; + unc = 1; + } + } + } + + slen = 4 + (unc * 4) + len + 1; + ws = wsp = malloc(slen * sizeof(wchar_t)); + if (ws == NULL) { + free(wn); + return (NULL); + } + /* prepend "\\?\" */ + wcsncpy(wsp, L"\\\\?\\", 4); + wsp += 4; + slen -= 4; + if (unc) { + /* append "UNC\" ---> "\\?\UNC\" */ + wcsncpy(wsp, L"UNC\\", 4); + wsp += 4; + slen -= 4; + } + wcsncpy(wsp, wnp, slen); + wsp[slen - 1] = L'\0'; /* Ensure null termination. */ + free(wn); + return (ws); +} + +static HANDLE +la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) +{ + wchar_t *wpath; + HANDLE handle; + + handle = CreateFileA(path, dwDesiredAccess, dwShareMode, + lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, + hTemplateFile); + if (handle != INVALID_HANDLE_VALUE) + return (handle); + if (GetLastError() != ERROR_PATH_NOT_FOUND) + return (handle); + wpath = permissive_name(path); + if (wpath == NULL) + return (handle); + handle = CreateFileW(wpath, dwDesiredAccess, dwShareMode, + lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, + hTemplateFile); + free(wpath); + return (handle); +} + +static void * +la_GetFunctionKernel32(const char *name) +{ + static HINSTANCE lib; + static int set; + if (!set) { + set = 1; + lib = LoadLibrary("kernel32.dll"); + } + if (lib == NULL) { + fprintf(stderr, "Can't load kernel32.dll?!\n"); + exit(1); + } + return (void *)GetProcAddress(lib, name); +} + +static int +la_CreateHardLinkW(wchar_t *linkname, wchar_t *target) +{ + static BOOLEAN (WINAPI *f)(LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES); + static int set; + if (!set) { + set = 1; + f = la_GetFunctionKernel32("CreateHardLinkW"); + } + return f == NULL ? 0 : (*f)(linkname, target, NULL); +} + + +/* Make a link to src called dst. */ +static int +__link(const char *src, const char *dst) +{ + wchar_t *wsrc, *wdst; + int res, retval; + DWORD attr; + + if (src == NULL || dst == NULL) { + set_errno (EINVAL); + return -1; + } + + wsrc = permissive_name(src); + wdst = permissive_name(dst); + if (wsrc == NULL || wdst == NULL) { + free(wsrc); + free(wdst); + set_errno (EINVAL); + return -1; + } + + if ((attr = GetFileAttributesW(wsrc)) != (DWORD)-1) { + res = la_CreateHardLinkW(wdst, wsrc); + } else { + /* wsrc does not exist; try src prepend it with the dirname of wdst */ + wchar_t *wnewsrc, *slash; + int i, n, slen, wlen; + + if (strlen(src) >= 3 && isalpha((unsigned char)src[0]) && + src[1] == ':' && src[2] == '\\') { + /* Original src name is already full-path */ + retval = -1; + goto exit; + } + if (src[0] == '\\') { + /* Original src name is almost full-path + * (maybe src name is without drive) */ + retval = -1; + goto exit; + } + + wnewsrc = malloc ((wcslen(wsrc) + wcslen(wdst) + 1) * sizeof(wchar_t)); + if (wnewsrc == NULL) { + errno = ENOMEM; + retval = -1; + goto exit; + } + /* Copying a dirname of wdst */ + wcscpy(wnewsrc, wdst); + slash = wcsrchr(wnewsrc, L'\\'); + if (slash != NULL) + *++slash = L'\0'; + else + wcscat(wnewsrc, L"\\"); + /* Converting multi-byte src to wide-char src */ + wlen = (int)wcslen(wsrc); + slen = (int)strlen(src); + n = MultiByteToWideChar(CP_ACP, 0, src, slen, wsrc, wlen); + if (n == 0) { + free (wnewsrc); + retval = -1; + goto exit; + } + for (i = 0; i < n; i++) + if (wsrc[i] == L'/') + wsrc[i] = L'\\'; + wcsncat(wnewsrc, wsrc, n); + /* Check again */ + attr = GetFileAttributesW(wnewsrc); + if (attr == (DWORD)-1 || (attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { + if (attr == (DWORD)-1) + la_dosmaperr(GetLastError()); + else + errno = EPERM; + free (wnewsrc); + retval = -1; + goto exit; + } + res = la_CreateHardLinkW(wdst, wnewsrc); + free (wnewsrc); + } + if (res == 0) { + la_dosmaperr(GetLastError()); + retval = -1; + } else + retval = 0; +exit: + free(wsrc); + free(wdst); + return (retval); +} + +/* Make a hard link to src called dst. */ +int +__la_link(const char *src, const char *dst) +{ + return __link(src, dst); +} + +int +__la_ftruncate(int fd, off_t length) +{ + LARGE_INTEGER distance; + HANDLE handle; + + if (fd < 0) { + errno = EBADF; + return (-1); + } + handle = (HANDLE)_get_osfhandle(fd); + if (GetFileType(handle) != FILE_TYPE_DISK) { + errno = EBADF; + return (-1); + } + distance.QuadPart = length; + if (!SetFilePointerEx(handle, distance, NULL, FILE_BEGIN)) { + la_dosmaperr(GetLastError()); + return (-1); + } + if (!SetEndOfFile(handle)) { + la_dosmaperr(GetLastError()); + return (-1); + } + return (0); +} + +#define WINTIME(sec, usec) ((Int32x32To64(sec, 10000000) + EPOC_TIME) + (usec * 10)) +static int +__hutimes(HANDLE handle, const struct __timeval *times) +{ + ULARGE_INTEGER wintm; + FILETIME fatime, fmtime; + + wintm.QuadPart = WINTIME(times[0].tv_sec, times[0].tv_usec); + fatime.dwLowDateTime = wintm.LowPart; + fatime.dwHighDateTime = wintm.HighPart; + wintm.QuadPart = WINTIME(times[1].tv_sec, times[1].tv_usec); + fmtime.dwLowDateTime = wintm.LowPart; + fmtime.dwHighDateTime = wintm.HighPart; + if (SetFileTime(handle, NULL, &fatime, &fmtime) == 0) { + errno = EINVAL; + return (-1); + } + return (0); +} + +int +__la_futimes(int fd, const struct __timeval *times) +{ + + return (__hutimes((HANDLE)_get_osfhandle(fd), times)); +} + +int +__la_utimes(const char *name, const struct __timeval *times) +{ + int ret; + HANDLE handle; + + handle = la_CreateFile(name, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (handle == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); + return (-1); + } + ret = __hutimes(handle, times); + CloseHandle(handle); + return (ret); +} + +int +__la_chdir(const char *path) +{ + wchar_t *ws; + int r; + + r = SetCurrentDirectoryA(path); + if (r == 0) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) { + la_dosmaperr(GetLastError()); + return (-1); + } + } else + return (0); + ws = permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + r = SetCurrentDirectoryW(ws); + free(ws); + if (r == 0) { + la_dosmaperr(GetLastError()); + return (-1); + } + return (0); +} + +int +__la_chmod(const char *path, mode_t mode) +{ + wchar_t *ws; + DWORD attr; + BOOL r; + + ws = NULL; + attr = GetFileAttributesA(path); + if (attr == (DWORD)-1) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) { + la_dosmaperr(GetLastError()); + return (-1); + } + ws = permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + attr = GetFileAttributesW(ws); + if (attr == (DWORD)-1) { + free(ws); + la_dosmaperr(GetLastError()); + return (-1); + } + } + if (mode & _S_IWRITE) + attr &= ~FILE_ATTRIBUTE_READONLY; + else + attr |= FILE_ATTRIBUTE_READONLY; + if (ws == NULL) + r = SetFileAttributesA(path, attr); + else { + r = SetFileAttributesW(ws, attr); + free(ws); + } + if (r == 0) { + la_dosmaperr(GetLastError()); + return (-1); + } + return (0); +} + +/* + * This fcntl is limited implemention. + */ +int +__la_fcntl(int fd, int cmd, int val) +{ + HANDLE handle; + + handle = (HANDLE)_get_osfhandle(fd); + if (GetFileType(handle) == FILE_TYPE_PIPE) { + if (cmd == F_SETFL && val == 0) { + DWORD mode = PIPE_WAIT; + if (SetNamedPipeHandleState( + handle, &mode, NULL, NULL) != 0) + return (0); + } + } + errno = EINVAL; + return (-1); +} + +__int64 +__la_lseek(int fd, __int64 offset, int whence) +{ + LARGE_INTEGER distance; + LARGE_INTEGER newpointer; + HANDLE handle; + + if (fd < 0) { + errno = EBADF; + return (-1); + } + handle = (HANDLE)_get_osfhandle(fd); + if (GetFileType(handle) != FILE_TYPE_DISK) { + errno = EBADF; + return (-1); + } + distance.QuadPart = offset; + if (!SetFilePointerEx(handle, distance, &newpointer, whence)) { + DWORD lasterr; + + lasterr = GetLastError(); + if (lasterr == ERROR_BROKEN_PIPE) + return (0); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + return (-1); + } + return (newpointer.QuadPart); +} + +int +__la_mkdir(const char *path, mode_t mode) +{ + wchar_t *ws; + int r; + + (void)mode;/* UNUSED */ + r = CreateDirectoryA(path, NULL); + if (r == 0) { + DWORD lasterr = GetLastError(); + if (lasterr != ERROR_FILENAME_EXCED_RANGE && + lasterr != ERROR_PATH_NOT_FOUND) { + la_dosmaperr(GetLastError()); + return (-1); + } + } else + return (0); + ws = permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + r = CreateDirectoryW(ws, NULL); + free(ws); + if (r == 0) { + la_dosmaperr(GetLastError()); + return (-1); + } + return (0); +} + +/* Windows' mbstowcs is differrent error handling from other unix mbstowcs. + * That one is using MultiByteToWideChar function with MB_PRECOMPOSED and + * MB_ERR_INVALID_CHARS flags. + * This implements for only to pass libarchive_test. + */ +size_t +__la_mbstowcs(wchar_t *wcstr, const char *mbstr, size_t nwchars) +{ + + return (MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, + mbstr, (int)strlen(mbstr), wcstr, + (int)nwchars)); +} + +int +__la_open(const char *path, int flags, ...) +{ + va_list ap; + wchar_t *ws; + int r, pmode; + DWORD attr; + + va_start(ap, flags); + pmode = va_arg(ap, int); + va_end(ap); + ws = NULL; + if ((flags & ~O_BINARY) == O_RDONLY) { + /* + * When we open a directory, _open function returns + * "Permission denied" error. + */ + attr = GetFileAttributesA(path); + if (attr == (DWORD)-1 && GetLastError() == ERROR_PATH_NOT_FOUND) { + ws = permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + attr = GetFileAttributesW(ws); + } + if (attr == (DWORD)-1) { + la_dosmaperr(GetLastError()); + free(ws); + return (-1); + } + if (attr & FILE_ATTRIBUTE_DIRECTORY) { + HANDLE handle; + + if (ws != NULL) + handle = CreateFileW(ws, 0, 0, NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | + FILE_ATTRIBUTE_READONLY, + NULL); + else + handle = CreateFileA(path, 0, 0, NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | + FILE_ATTRIBUTE_READONLY, + NULL); + free(ws); + if (handle == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); + return (-1); + } + r = _open_osfhandle((intptr_t)handle, _O_RDONLY); + return (r); + } + } + if (ws == NULL) { +#if defined(__BORLANDC__) + /* Borland has no mode argument. + TODO: Fix mode of new file. */ + r = _open(path, flags); +#else + r = _open(path, flags, pmode); +#endif + if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) { + /* simular other POSIX system action to pass a test */ + attr = GetFileAttributesA(path); + if (attr == (DWORD)-1) + la_dosmaperr(GetLastError()); + else if (attr & FILE_ATTRIBUTE_DIRECTORY) + errno = EISDIR; + else + errno = EACCES; + return (-1); + } + if (r >= 0 || errno != ENOENT) + return (r); + ws = permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + } + r = _wopen(ws, flags, pmode); + if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) { + /* simular other POSIX system action to pass a test */ + attr = GetFileAttributesW(ws); + if (attr == (DWORD)-1) + la_dosmaperr(GetLastError()); + else if (attr & FILE_ATTRIBUTE_DIRECTORY) + errno = EISDIR; + else + errno = EACCES; + } + free(ws); + return (r); +} + +ssize_t +__la_read(int fd, void *buf, size_t nbytes) +{ + HANDLE handle; + DWORD bytes_read, lasterr; + int r; + +#ifdef _WIN64 + if (nbytes > UINT32_MAX) + nbytes = UINT32_MAX; +#endif + if (fd < 0) { + errno = EBADF; + return (-1); + } + handle = (HANDLE)_get_osfhandle(fd); + if (GetFileType(handle) == FILE_TYPE_PIPE) { + DWORD sta; + if (GetNamedPipeHandleState( + handle, &sta, NULL, NULL, NULL, NULL, 0) != 0 && + (sta & PIPE_NOWAIT) == 0) { + DWORD avail = -1; + int cnt = 3; + + while (PeekNamedPipe( + handle, NULL, 0, NULL, &avail, NULL) != 0 && + avail == 0 && --cnt) + Sleep(100); + if (avail == 0) + return (0); + } + } + r = ReadFile(handle, buf, (uint32_t)nbytes, + &bytes_read, NULL); + if (r == 0) { + lasterr = GetLastError(); + if (lasterr == ERROR_NO_DATA) { + errno = EAGAIN; + return (-1); + } + if (lasterr == ERROR_BROKEN_PIPE) + return (0); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + return (-1); + } + return ((ssize_t)bytes_read); +} + +/* Remove directory */ +int +__la_rmdir(const char *path) +{ + wchar_t *ws; + int r; + + r = _rmdir(path); + if (r >= 0 || errno != ENOENT) + return (r); + ws = permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + r = _wrmdir(ws); + free(ws); + return (r); +} + +/* Convert Windows FILETIME to UTC */ +__inline static void +fileTimeToUTC(const FILETIME *filetime, time_t *time, long *ns) +{ + ULARGE_INTEGER utc; + + utc.HighPart = filetime->dwHighDateTime; + utc.LowPart = filetime->dwLowDateTime; + if (utc.QuadPart >= EPOC_TIME) { + utc.QuadPart -= EPOC_TIME; + *time = (time_t)(utc.QuadPart / 10000000); /* milli seconds base */ + *ns = (long)(utc.QuadPart % 10000000) * 100;/* nano seconds base */ + } else { + *time = 0; + *ns = 0; + } +} + +/* Stat by handle + * Windows' stat() does not accept path which is added "\\?\" especially "?" + * character. + * It means we cannot access a long name path(which is longer than MAX_PATH). + * So I've implemented simular Windows' stat() to access the long name path. + * And I've added some feature. + * 1. set st_ino by nFileIndexHigh and nFileIndexLow of + * BY_HANDLE_FILE_INFORMATION. + * 2. set st_nlink by nNumberOfLinks of BY_HANDLE_FILE_INFORMATION. + * 3. set st_dev by dwVolumeSerialNumber by BY_HANDLE_FILE_INFORMATION. + */ +static int +__hstat(HANDLE handle, struct ustat *st) +{ + BY_HANDLE_FILE_INFORMATION info; + ULARGE_INTEGER ino64; + DWORD ftype; + mode_t mode; + time_t time; + long ns; + + switch (ftype = GetFileType(handle)) { + case FILE_TYPE_UNKNOWN: + errno = EBADF; + return (-1); + case FILE_TYPE_CHAR: + case FILE_TYPE_PIPE: + if (ftype == FILE_TYPE_CHAR) { + st->st_mode = S_IFCHR; + st->st_size = 0; + } else { + DWORD avail; + + st->st_mode = S_IFIFO; + if (PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL)) + st->st_size = avail; + else + st->st_size = 0; + } + st->st_atime = 0; + st->st_atime_nsec = 0; + st->st_mtime = 0; + st->st_mtime_nsec = 0; + st->st_ctime = 0; + st->st_ctime_nsec = 0; + st->st_ino = 0; + st->st_nlink = 1; + st->st_uid = 0; + st->st_gid = 0; + st->st_rdev = 0; + st->st_dev = 0; + return (0); + case FILE_TYPE_DISK: + break; + default: + /* This ftype is undocumented type. */ + la_dosmaperr(GetLastError()); + return (-1); + } + + ZeroMemory(&info, sizeof(info)); + if (!GetFileInformationByHandle (handle, &info)) { + la_dosmaperr(GetLastError()); + return (-1); + } + + mode = S_IRUSR | S_IRGRP | S_IROTH; + if ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0) + mode |= S_IWUSR | S_IWGRP | S_IWOTH; + if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + else + mode |= S_IFREG; + st->st_mode = mode; + + fileTimeToUTC(&info.ftLastAccessTime, &time, &ns); + st->st_atime = time; + st->st_atime_nsec = ns; + fileTimeToUTC(&info.ftLastWriteTime, &time, &ns); + st->st_mtime = time; + st->st_mtime_nsec = ns; + fileTimeToUTC(&info.ftCreationTime, &time, &ns); + st->st_ctime = time; + st->st_ctime_nsec = ns; + st->st_size = + ((int64_t)(info.nFileSizeHigh) * ((int64_t)MAXDWORD + 1)) + + (int64_t)(info.nFileSizeLow); +#ifdef SIMULATE_WIN_STAT + st->st_ino = 0; + st->st_nlink = 1; + st->st_dev = 0; +#else + /* Getting FileIndex as i-node. We have to remove a sequence which + * is high-16-bits of nFileIndexHigh. */ + ino64.HighPart = info.nFileIndexHigh & 0x0000FFFFUL; + ino64.LowPart = info.nFileIndexLow; + st->st_ino = ino64.QuadPart; + st->st_nlink = info.nNumberOfLinks; + if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + ++st->st_nlink;/* Add parent directory. */ + st->st_dev = info.dwVolumeSerialNumber; +#endif + st->st_uid = 0; + st->st_gid = 0; + st->st_rdev = 0; + return (0); +} + +static void +copy_stat(struct stat *st, struct ustat *us) +{ + st->st_atime = us->st_atime; + st->st_ctime = us->st_ctime; + st->st_mtime = us->st_mtime; + st->st_gid = us->st_gid; + st->st_ino = getino(us); + st->st_mode = us->st_mode; + st->st_nlink = us->st_nlink; + st->st_size = us->st_size; + st->st_uid = us->st_uid; + st->st_dev = us->st_dev; + st->st_rdev = us->st_rdev; +} + +int +__la_fstat(int fd, struct stat *st) +{ + struct ustat u; + int ret; + + if (fd < 0) { + errno = EBADF; + return (-1); + } + ret = __hstat((HANDLE)_get_osfhandle(fd), &u); + if (ret >= 0) { + copy_stat(st, &u); + if (u.st_mode & (S_IFCHR | S_IFIFO)) { + st->st_dev = fd; + st->st_rdev = fd; + } + } + return (ret); +} + +int +__la_stat(const char *path, struct stat *st) +{ + HANDLE handle; + struct ustat u; + int ret; + + handle = la_CreateFile(path, 0, 0, NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_READONLY, + NULL); + if (handle == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); + return (-1); + } + ret = __hstat(handle, &u); + CloseHandle(handle); + if (ret >= 0) { + char *p; + + copy_stat(st, &u); + p = strrchr(path, '.'); + if (p != NULL && strlen(p) == 4) { + char exttype[4]; + + ++ p; + exttype[0] = toupper(*p++); + exttype[1] = toupper(*p++); + exttype[2] = toupper(*p++); + exttype[3] = '\0'; + if (!strcmp(exttype, "EXE") || !strcmp(exttype, "CMD") || + !strcmp(exttype, "BAT") || !strcmp(exttype, "COM")) + st->st_mode |= S_IXUSR | S_IXGRP | S_IXOTH; + } + } + return (ret); +} + +int +__la_unlink(const char *path) +{ + wchar_t *ws; + int r; + + r = _unlink(path); + if (r >= 0 || errno != ENOENT) + return (r); + ws = permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + r = _wunlink(ws); + free(ws); + return (r); +} + +/* + * This waitpid is limited implemention. + */ +pid_t +__la_waitpid(pid_t wpid, int *status, int option) +{ + HANDLE child; + DWORD cs, ret; + + (void)option;/* UNUSED */ + child = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, wpid); + if (child == NULL) { + la_dosmaperr(GetLastError()); + return (-1); + } + ret = WaitForSingleObject(child, INFINITE); + if (ret == WAIT_FAILED) { + CloseHandle(child); + la_dosmaperr(GetLastError()); + return (-1); + } + if (GetExitCodeProcess(child, &cs) == 0) { + CloseHandle(child); + la_dosmaperr(GetLastError()); + return (-1); + } + if (cs == STILL_ACTIVE) + *status = 0x100; + else + *status = (int)(cs & 0xff); + CloseHandle(child); + return (wpid); +} + +ssize_t +__la_write(int fd, const void *buf, size_t nbytes) +{ + DWORD bytes_written; + +#ifdef _WIN64 + if (nbytes > UINT32_MAX) + nbytes = UINT32_MAX; +#endif + if (fd < 0) { + errno = EBADF; + return (-1); + } + if (!WriteFile((HANDLE)_get_osfhandle(fd), buf, (uint32_t)nbytes, + &bytes_written, NULL)) { + DWORD lasterr; + + lasterr = GetLastError(); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + return (-1); + } + return (bytes_written); +} + +/* + * The following function was modified from PostgreSQL sources and is + * subject to the copyright below. + */ +/*------------------------------------------------------------------------- + * + * win32error.c + * Map win32 error codes to errno values + * + * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +/* +PostgreSQL Database Management System +(formerly known as Postgres, then as Postgres95) + +Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group + +Portions Copyright (c) 1994, The Regents of the University of California + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose, without fee, and without a written agreement +is hereby granted, provided that the above copyright notice and this +paragraph and the following two paragraphs appear in all copies. + +IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR +DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING +LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO +PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. +*/ + +static const struct { + DWORD winerr; + int doserr; +} doserrors[] = +{ + { ERROR_INVALID_FUNCTION, EINVAL }, + { ERROR_FILE_NOT_FOUND, ENOENT }, + { ERROR_PATH_NOT_FOUND, ENOENT }, + { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, + { ERROR_ACCESS_DENIED, EACCES }, + { ERROR_INVALID_HANDLE, EBADF }, + { ERROR_ARENA_TRASHED, ENOMEM }, + { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, + { ERROR_INVALID_BLOCK, ENOMEM }, + { ERROR_BAD_ENVIRONMENT, E2BIG }, + { ERROR_BAD_FORMAT, ENOEXEC }, + { ERROR_INVALID_ACCESS, EINVAL }, + { ERROR_INVALID_DATA, EINVAL }, + { ERROR_INVALID_DRIVE, ENOENT }, + { ERROR_CURRENT_DIRECTORY, EACCES }, + { ERROR_NOT_SAME_DEVICE, EXDEV }, + { ERROR_NO_MORE_FILES, ENOENT }, + { ERROR_LOCK_VIOLATION, EACCES }, + { ERROR_SHARING_VIOLATION, EACCES }, + { ERROR_BAD_NETPATH, ENOENT }, + { ERROR_NETWORK_ACCESS_DENIED, EACCES }, + { ERROR_BAD_NET_NAME, ENOENT }, + { ERROR_FILE_EXISTS, EEXIST }, + { ERROR_CANNOT_MAKE, EACCES }, + { ERROR_FAIL_I24, EACCES }, + { ERROR_INVALID_PARAMETER, EINVAL }, + { ERROR_NO_PROC_SLOTS, EAGAIN }, + { ERROR_DRIVE_LOCKED, EACCES }, + { ERROR_BROKEN_PIPE, EPIPE }, + { ERROR_DISK_FULL, ENOSPC }, + { ERROR_INVALID_TARGET_HANDLE, EBADF }, + { ERROR_INVALID_HANDLE, EINVAL }, + { ERROR_WAIT_NO_CHILDREN, ECHILD }, + { ERROR_CHILD_NOT_COMPLETE, ECHILD }, + { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, + { ERROR_NEGATIVE_SEEK, EINVAL }, + { ERROR_SEEK_ON_DEVICE, EACCES }, + { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, + { ERROR_NOT_LOCKED, EACCES }, + { ERROR_BAD_PATHNAME, ENOENT }, + { ERROR_MAX_THRDS_REACHED, EAGAIN }, + { ERROR_LOCK_FAILED, EACCES }, + { ERROR_ALREADY_EXISTS, EEXIST }, + { ERROR_FILENAME_EXCED_RANGE, ENOENT }, + { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, + { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } +}; + +static void +la_dosmaperr(unsigned long e) +{ + int i; + + if (e == 0) + { + errno = 0; + return; + } + + for (i = 0; i < sizeof(doserrors); i++) + { + if (doserrors[i].winerr == e) + { + errno = doserrors[i].doserr; + return; + } + } + + /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */ + errno = EINVAL; + return; +} + +#if defined(ARCHIVE_HASH_MD5_WIN) ||\ + defined(ARCHIVE_HASH_SHA1_WIN) || defined(ARCHIVE_HASH_SHA256_WIN) ||\ + defined(ARCHIVE_HASH_SHA384_WIN) || defined(ARCHIVE_HASH_SHA512_WIN) +/* + * Message digest functions. + */ +void +__la_hash_Init(Digest_CTX *ctx, ALG_ID algId) +{ + + ctx->valid = 0; + if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, + PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { + if (GetLastError() != (DWORD)NTE_BAD_KEYSET) + return; + if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, + PROV_RSA_FULL, CRYPT_NEWKEYSET)) + return; + } + + if (!CryptCreateHash(ctx->cryptProv, algId, 0, 0, &ctx->hash)) { + CryptReleaseContext(ctx->cryptProv, 0); + return; + } + + ctx->valid = 1; +} + +void +__la_hash_Update(Digest_CTX *ctx, const unsigned char *buf, size_t len) +{ + + if (!ctx->valid) + return; + + CryptHashData(ctx->hash, + (unsigned char *)(uintptr_t)buf, + (DWORD)len, 0); +} + +void +__la_hash_Final(unsigned char *buf, size_t bufsize, Digest_CTX *ctx) +{ + DWORD siglen = bufsize; + + if (!ctx->valid) + return; + + CryptGetHashParam(ctx->hash, HP_HASHVAL, buf, &siglen, 0); + CryptDestroyHash(ctx->hash); + CryptReleaseContext(ctx->cryptProv, 0); + ctx->valid = 0; +} + +#endif /* defined(ARCHIVE_HASH_*_WIN) */ + +#endif /* _WIN32 && !__CYGWIN__ */ diff --git a/external/bsd/libarchive/dist/libarchive/archive_windows.h b/external/bsd/libarchive/dist/libarchive/archive_windows.h new file mode 100644 index 000000000..86c9f4f6b --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/archive_windows.h @@ -0,0 +1,347 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2006 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __LIBARCHIVE_BUILD +#error This header is only to be used internally to libarchive. +#endif + +/* + * TODO: A lot of stuff in here isn't actually used by libarchive and + * can be trimmed out. Note that this file is used by libarchive and + * libarchive_test but nowhere else. (But note that it gets compiled + * with many different Windows environments, including MinGW, Visual + * Studio, and Cygwin. Significant changes should be tested in all three.) + */ + +/* + * TODO: Don't use off_t in here. Use __int64 instead. Note that + * Visual Studio and the Windows SDK define off_t as 32 bits; Win32's + * more modern file handling APIs all use __int64 instead of off_t. + */ + +#ifndef LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED +#define LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED + +/* Start of configuration for native Win32 */ + +#include +#define set_errno(val) ((errno)=val) +#include +#include //brings in NULL +#if defined(HAVE_STDINT_H) +#include +#endif +#include +#include +#include +#include +#include +#define NOCRYPT +#include +//#define EFTYPE 7 + +#if !defined(STDIN_FILENO) +#define STDIN_FILENO 0 +#endif + +#if !defined(STDOUT_FILENO) +#define STDOUT_FILENO 1 +#endif + +#if !defined(STDERR_FILENO) +#define STDERR_FILENO 2 +#endif + + +#if defined(_MSC_VER) +/* TODO: Fix the code, don't suppress the warnings. */ +#pragma warning(disable:4244) /* 'conversion' conversion from 'type1' to 'type2', possible loss of data */ +#endif +#if defined(__BORLANDC__) +#pragma warn -8068 /* Constant out of range in comparison. */ +#pragma warn -8072 /* Suspicious pointer arithmetic. */ +#endif + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +/* Alias the Windows _function to the POSIX equivalent. */ +#define access _access +#define chdir __la_chdir +#define chmod __la_chmod +#define close _close +#define fcntl __la_fcntl +#ifndef fileno +#define fileno _fileno +#endif +#define fstat __la_fstat +#define ftruncate __la_ftruncate +#define futimes __la_futimes +#define getcwd _getcwd +#define link __la_link +#define lseek __la_lseek +#define lstat __la_stat +#define mbstowcs __la_mbstowcs +#define mkdir(d,m) __la_mkdir(d, m) +#define mktemp _mktemp +#define open __la_open +#define read __la_read +#define rmdir __la_rmdir +#if !defined(__BORLANDC__) +#define setmode _setmode +#endif +#define stat(path,stref) __la_stat(path,stref) +#if !defined(__BORLANDC__) +#define strdup _strdup +#endif +#define tzset _tzset +#if !defined(__BORLANDC__) +#define umask _umask +#endif +#define unlink __la_unlink +#define utimes __la_utimes +#define waitpid __la_waitpid +#define write __la_write + +#ifndef O_RDONLY +#define O_RDONLY _O_RDONLY +#define O_WRONLY _O_WRONLY +#define O_TRUNC _O_TRUNC +#define O_CREAT _O_CREAT +#define O_EXCL _O_EXCL +#define O_BINARY _O_BINARY +#endif + +#ifndef _S_IFIFO + #define _S_IFIFO 0010000 /* pipe */ +#endif +#ifndef _S_IFCHR + #define _S_IFCHR 0020000 /* character special */ +#endif +#ifndef _S_IFDIR + #define _S_IFDIR 0040000 /* directory */ +#endif +#ifndef _S_IFBLK + #define _S_IFBLK 0060000 /* block special */ +#endif +#ifndef _S_IFLNK + #define _S_IFLNK 0120000 /* symbolic link */ +#endif +#ifndef _S_IFSOCK + #define _S_IFSOCK 0140000 /* socket */ +#endif +#ifndef _S_IFREG + #define _S_IFREG 0100000 /* regular */ +#endif +#ifndef _S_IFMT + #define _S_IFMT 0170000 /* file type mask */ +#endif + +#ifndef S_IFIFO +#define S_IFIFO _S_IFIFO +#endif +//#define S_IFCHR _S_IFCHR +//#define S_IFDIR _S_IFDIR +#ifndef S_IFBLK +#define S_IFBLK _S_IFBLK +#endif +#ifndef S_IFLNK +#define S_IFLNK _S_IFLNK +#endif +#ifndef S_IFSOCK +#define S_IFSOCK _S_IFSOCK +#endif +//#define S_IFREG _S_IFREG +//#define S_IFMT _S_IFMT + +#ifndef S_ISBLK +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) /* block special */ +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) /* fifo or socket */ +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) /* char special */ +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) /* directory */ +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) /* regular file */ +#endif +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) /* Symbolic link */ +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) /* Socket */ + +#define _S_ISUID 0004000 /* set user id on execution */ +#define _S_ISGID 0002000 /* set group id on execution */ +#define _S_ISVTX 0001000 /* save swapped text even after use */ + +#define S_ISUID _S_ISUID +#define S_ISGID _S_ISGID +#define S_ISVTX _S_ISVTX + +#define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) +#define _S_IXUSR _S_IEXEC /* read permission, user */ +#define _S_IWUSR _S_IWRITE /* write permission, user */ +#define _S_IRUSR _S_IREAD /* execute/search permission, user */ +#define _S_IRWXG (_S_IRWXU >> 3) +#define _S_IXGRP (_S_IXUSR >> 3) /* read permission, group */ +#define _S_IWGRP (_S_IWUSR >> 3) /* write permission, group */ +#define _S_IRGRP (_S_IRUSR >> 3) /* execute/search permission, group */ +#define _S_IRWXO (_S_IRWXG >> 3) +#define _S_IXOTH (_S_IXGRP >> 3) /* read permission, other */ +#define _S_IWOTH (_S_IWGRP >> 3) /* write permission, other */ +#define _S_IROTH (_S_IRGRP >> 3) /* execute/search permission, other */ + +#ifndef S_IRWXU +#define S_IRWXU _S_IRWXU +#define S_IXUSR _S_IXUSR +#define S_IWUSR _S_IWUSR +#define S_IRUSR _S_IRUSR +#endif +#define S_IRWXG _S_IRWXG +#define S_IXGRP _S_IXGRP +#define S_IWGRP _S_IWGRP +#define S_IRGRP _S_IRGRP +#define S_IRWXO _S_IRWXO +#define S_IXOTH _S_IXOTH +#define S_IWOTH _S_IWOTH +#define S_IROTH _S_IROTH + +#define F_DUPFD 0 /* Duplicate file descriptor. */ +#define F_GETFD 1 /* Get file descriptor flags. */ +#define F_SETFD 2 /* Set file descriptor flags. */ +#define F_GETFL 3 /* Get file status flags. */ +#define F_SETFL 4 /* Set file status flags. */ +#define F_GETOWN 5 /* Get owner (receiver of SIGIO). */ +#define F_SETOWN 6 /* Set owner (receiver of SIGIO). */ +#define F_GETLK 7 /* Get record locking info. */ +#define F_SETLK 8 /* Set record locking info (non-blocking). */ +#define F_SETLKW 9 /* Set record locking info (blocking). */ + +/* XXX missing */ +#define F_GETLK64 7 /* Get record locking info. */ +#define F_SETLK64 8 /* Set record locking info (non-blocking). */ +#define F_SETLKW64 9 /* Set record locking info (blocking). */ + +/* File descriptor flags used with F_GETFD and F_SETFD. */ +#define FD_CLOEXEC 1 /* Close on exec. */ + +//NOT SURE IF O_NONBLOCK is OK here but at least the 0x0004 flag is not used by anything else... +#define O_NONBLOCK 0x0004 /* Non-blocking I/O. */ +//#define O_NDELAY O_NONBLOCK + +/* Symbolic constants for the access() function */ +#if !defined(F_OK) + #define R_OK 4 /* Test for read permission */ + #define W_OK 2 /* Test for write permission */ + #define X_OK 1 /* Test for execute permission */ + #define F_OK 0 /* Test for existence of file */ +#endif + + +#ifdef _LARGEFILE_SOURCE +# define __USE_LARGEFILE 1 /* declare fseeko and ftello */ +#endif + +#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 +# define __USE_FILE_OFFSET64 1 /* replace 32-bit functions by 64-bit ones */ +#endif + +#if __USE_LARGEFILE && __USE_FILE_OFFSET64 +/* replace stat and seek by their large-file equivalents */ +#undef stat +#define stat _stati64 + +#undef lseek +#define lseek _lseeki64 +#define lseek64 _lseeki64 +#define tell _telli64 +#define tell64 _telli64 + +#ifdef __MINGW32__ +# define fseek fseeko64 +# define fseeko fseeko64 +# define ftell ftello64 +# define ftello ftello64 +# define ftell64 ftello64 +#endif /* __MINGW32__ */ +#endif /* LARGE_FILES */ + +#ifdef USE_WINSOCK_TIMEVAL +/* Winsock timeval has long size tv_sec. */ +#define __timeval timeval +#else +struct _timeval64i32 { + time_t tv_sec; + long tv_usec; +}; +#define __timeval _timeval64i32 +#endif + +/* End of Win32 definitions. */ + +/* Tell libarchive code that we have simulations for these. */ +#ifndef HAVE_FTRUNCATE +#define HAVE_FTRUNCATE 1 +#endif +#ifndef HAVE_FUTIMES +#define HAVE_FUTIMES 1 +#endif +#ifndef HAVE_UTIMES +#define HAVE_UTIMES 1 +#endif +#ifndef HAVE_LINK +#define HAVE_LINK 1 +#endif + +/* Replacement POSIX function */ +extern int __la_chdir(const char *path); +extern int __la_chmod(const char *path, mode_t mode); +extern int __la_fcntl(int fd, int cmd, int val); +extern int __la_fstat(int fd, struct stat *st); +extern int __la_ftruncate(int fd, off_t length); +extern int __la_futimes(int fd, const struct __timeval *times); +extern int __la_link(const char *src, const char *dst); +extern __int64 __la_lseek(int fd, __int64 offset, int whence); +extern size_t __la_mbstowcs(wchar_t *wcstr, const char *mbstr, size_t nwchars); +extern int __la_mkdir(const char *path, mode_t mode); +extern int __la_open(const char *path, int flags, ...); +extern ssize_t __la_read(int fd, void *buf, size_t nbytes); +extern int __la_rmdir(const char *path); +extern int __la_stat(const char *path, struct stat *st); +extern int __la_unlink(const char *path); +extern int __la_utimes(const char *name, const struct __timeval *times); +extern pid_t __la_waitpid(pid_t wpid, int *status, int option); +extern ssize_t __la_write(int fd, const void *buf, size_t nbytes); + +#define _stat64i32(path, st) __la_stat(path, st) +#define _stat64(path, st) __la_stat(path, st) +/* for status returned by la_waitpid */ +#define WIFEXITED(sts) ((sts & 0x100) == 0) +#define WEXITSTATUS(sts) (sts & 0x0FF) + +#endif /* LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED */ diff --git a/lib/libarchive/archive_write.3 b/external/bsd/libarchive/dist/libarchive/archive_write.3 similarity index 97% rename from lib/libarchive/archive_write.3 rename to external/bsd/libarchive/dist/libarchive/archive_write.3 index ffe0c9b45..2c0c89dd9 100644 --- a/lib/libarchive/archive_write.3 +++ b/external/bsd/libarchive/dist/libarchive/archive_write.3 @@ -173,14 +173,12 @@ functions, this function can be called after the archive is opened. .It Fn archive_write_get_bytes_in_last_block Retrieve the currently-set value for last block size. A value of -1 here indicates that the library should use default values. -.It Xo -.Fn archive_write_set_format_cpio , -.Fn archive_write_set_format_pax , -.Fn archive_write_set_format_pax_restricted , -.Fn archive_write_set_format_shar , -.Fn archive_write_set_format_shar_binary , -.Fn archive_write_set_format_ustar -.Xc +.It Fn archive_write_set_format_cpio , \ +Fn archive_write_set_format_pax , \ +Fn archive_write_set_format_pax_restricted , \ +Fn archive_write_set_format_shar , \ +Fn archive_write_set_format_shar_binary , \ +Fn archive_write_set_format_ustar Sets the format that will be used for the archive. The library can write POSIX octet-oriented cpio format archives, @@ -204,23 +202,19 @@ filenames, linknames, uids, sizes, etc. is the library default; this is the same as pax format, but suppresses the pax extended header for most normal files. In most cases, this will result in ordinary ustar archives. -.It Xo -.Fn archive_write_set_compression_bzip2 , -.Fn archive_write_set_compression_compress , -.Fn archive_write_set_compression_gzip , -.Fn archive_write_set_compression_none -.Xc +.It Fn archive_write_set_compression_bzip2 , \ +Fn archive_write_set_compression_compress , \ +Fn archive_write_set_compression_gzip , \ +Fn archive_write_set_compression_none The resulting archive will be compressed as specified. Note that the compressed output is always properly blocked. .It Fn archive_write_set_compression_program The archive will be fed into the specified compression program. The output of that program is blocked and written to the client write callbacks. -.It Xo -.Fn archive_write_set_compressor_options , -.Fn archive_write_set_format_options , -.Fn archive_write_set_options -.Xc +.It Fn archive_write_set_compressor_options , \ +Fn archive_write_set_format_options , \ +Fn archive_write_set_options Specifies options that will be passed to the currently-enabled compressor and/or format writer. The argument is a comma-separated list of individual options. diff --git a/lib/libarchive/archive_write.c b/external/bsd/libarchive/dist/libarchive/archive_write.c similarity index 97% rename from lib/libarchive/archive_write.c rename to external/bsd/libarchive/dist/libarchive/archive_write.c index 8ed71de59..e0d942b07 100644 --- a/lib/libarchive/archive_write.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write.c @@ -419,7 +419,6 @@ _archive_write_header(struct archive *_a, struct archive_entry *entry) if (ret < ARCHIVE_OK && ret != ARCHIVE_WARN) return (ret); -#ifndef __minix if (a->skip_file_dev != 0 && archive_entry_dev(entry) == a->skip_file_dev && a->skip_file_ino != 0 && @@ -428,16 +427,7 @@ _archive_write_header(struct archive *_a, struct archive_entry *entry) "Can't add archive to itself"); return (ARCHIVE_FAILED); } -#else - if (a->skip_file_dev != 0 && - archive_entry_dev(entry) == a->skip_file_dev && - a->skip_file_ino != 0 && - archive_entry_ino(entry) == a->skip_file_ino) { - archive_set_error(&a->archive, 0, - "Can't add archive to itself"); - return (ARCHIVE_FAILED); - } -#endif + /* Format and write header. */ r2 = ((a->format_write_header)(a, entry)); if (r2 < ret) diff --git a/lib/libarchive/archive_write_disk.3 b/external/bsd/libarchive/dist/libarchive/archive_write_disk.3 similarity index 99% rename from lib/libarchive/archive_write_disk.3 rename to external/bsd/libarchive/dist/libarchive/archive_write_disk.3 index 5ed4a5038..c258eeb73 100644 --- a/lib/libarchive/archive_write_disk.3 +++ b/external/bsd/libarchive/dist/libarchive/archive_write_disk.3 @@ -174,10 +174,8 @@ Scan data for blocks of NUL bytes and try to recreate them with holes. This results in sparse files, independent of whether the archive format supports or uses them. .El -.It Xo -.Fn archive_write_disk_set_group_lookup , -.Fn archive_write_disk_set_user_lookup -.Xc +.It Fn archive_write_disk_set_group_lookup , \ +Fn archive_write_disk_set_user_lookup The .Tn struct archive_entry objects contain both names and ids that can be used to identify users diff --git a/lib/libarchive/archive_write_disk.c b/external/bsd/libarchive/dist/libarchive/archive_write_disk.c similarity index 99% rename from lib/libarchive/archive_write_disk.c rename to external/bsd/libarchive/dist/libarchive/archive_write_disk.c index 20d7b7452..b6b23d2e6 100644 --- a/lib/libarchive/archive_write_disk.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_disk.c @@ -108,15 +108,9 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_disk.c 201159 2009-12-29 0 struct fixup_entry { struct fixup_entry *next; mode_t mode; -#ifndef __minix int64_t atime; int64_t birthtime; int64_t mtime; -#else - time_t atime; - time_t birthtime; - time_t mtime; -#endif unsigned long atime_nanos; unsigned long birthtime_nanos; unsigned long mtime_nanos; @@ -165,7 +159,7 @@ struct archive_write_disk { gid_t (*lookup_gid)(void *private, const char *gname, gid_t gid); void (*cleanup_gid)(void *private); void *lookup_gid_data; - uid_t (*lookup_uid)(void *private, const char *uname, uid_t uid); + uid_t (*lookup_uid)(void *private, const char *gname, gid_t gid); void (*cleanup_uid)(void *private); void *lookup_uid_data; @@ -551,11 +545,7 @@ archive_write_disk_set_skip_file(struct archive *_a, dev_t d, ino_t i) static ssize_t write_data_block(struct archive_write_disk *a, const char *buff, size_t size) { -#ifndef __minix uint64_t start_size = size; -#else - size_t start_size = size; -#endif ssize_t bytes_written = 0; ssize_t block_size = 0, bytes_to_write; @@ -1739,7 +1729,6 @@ create_dir(struct archive_write_disk *a, char *path) } if (unlink(path) != 0) { archive_set_error(&a->archive, errno, - "Can't create directory '%s': " "Conflicting file cannot be removed"); return (ARCHIVE_FAILED); } @@ -2487,7 +2476,7 @@ set_xattrs(struct archive_write_disk *a) } return (ret); } -#elif HAVE_EXTATTR_SET_FILE +#elif HAVE_EXTATTR_SET_FILE && HAVE_DECL_EXTATTR_NAMESPACE_USER /* * Restore extended attributes - FreeBSD implementation */ diff --git a/lib/libarchive/archive_write_disk_private.h b/external/bsd/libarchive/dist/libarchive/archive_write_disk_private.h similarity index 100% rename from lib/libarchive/archive_write_disk_private.h rename to external/bsd/libarchive/dist/libarchive/archive_write_disk_private.h diff --git a/lib/libarchive/archive_write_disk_set_standard_lookup.c b/external/bsd/libarchive/dist/libarchive/archive_write_disk_set_standard_lookup.c similarity index 94% rename from lib/libarchive/archive_write_disk_set_standard_lookup.c rename to external/bsd/libarchive/dist/libarchive/archive_write_disk_set_standard_lookup.c index 8f8260f07..cbc31a6f4 100644 --- a/lib/libarchive/archive_write_disk_set_standard_lookup.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_disk_set_standard_lookup.c @@ -117,6 +117,7 @@ lookup_gid(void *private_data, const char *gname, gid_t gid) /* Note: If strdup fails, that's okay; we just won't cache. */ b->hash = h; #if HAVE_GRP_H +# if HAVE_GETGRNAM_R { char _buffer[128]; size_t bufsize = 128; @@ -126,12 +127,7 @@ lookup_gid(void *private_data, const char *gname, gid_t gid) for (;;) { result = &grent; /* Old getgrnam_r ignores last arg. */ -#if defined(HAVE_GETGRNAM_R) r = getgrnam_r(gname, &grent, buffer, bufsize, &result); -#else - result = getgrnam(gname); - r = errno; -#endif if (r == 0) break; if (r != ERANGE) @@ -148,6 +144,15 @@ lookup_gid(void *private_data, const char *gname, gid_t gid) if (buffer != _buffer) free(buffer); } +# else /* HAVE_GETGRNAM_R */ + { + struct group *result; + + result = getgrnam(gname); + if (result != NULL) + gid = result->gr_gid; + } +# endif /* HAVE_GETGRNAM_R */ #elif defined(_WIN32) && !defined(__CYGWIN__) /* TODO: do a gname->gid lookup for Windows. */ #else @@ -182,6 +187,7 @@ lookup_uid(void *private_data, const char *uname, uid_t uid) /* Note: If strdup fails, that's okay; we just won't cache. */ b->hash = h; #if HAVE_PWD_H +# if HAVE_GETPWNAM_R { char _buffer[128]; size_t bufsize = 128; @@ -191,12 +197,7 @@ lookup_uid(void *private_data, const char *uname, uid_t uid) for (;;) { result = &pwent; /* Old getpwnam_r ignores last arg. */ -#if defined(HAVE_GETPWNAM_R) r = getpwnam_r(uname, &pwent, buffer, bufsize, &result); -#else - result = getpwnam(uname); - r = errno; -#endif if (r == 0) break; if (r != ERANGE) @@ -213,6 +214,15 @@ lookup_uid(void *private_data, const char *uname, uid_t uid) if (buffer != _buffer) free(buffer); } +# else /* HAVE_GETPWNAM_R */ + { + struct passwd *result; + + result = getpwnam(uname); + if (result != NULL) + uid = result->pw_uid; + } +#endif /* HAVE_GETPWNAM_R */ #elif defined(_WIN32) && !defined(__CYGWIN__) /* TODO: do a uname->uid lookup for Windows. */ #else diff --git a/lib/libarchive/archive_write_open_fd.c b/external/bsd/libarchive/dist/libarchive/archive_write_open_fd.c similarity index 100% rename from lib/libarchive/archive_write_open_fd.c rename to external/bsd/libarchive/dist/libarchive/archive_write_open_fd.c diff --git a/lib/libarchive/archive_write_open_file.c b/external/bsd/libarchive/dist/libarchive/archive_write_open_file.c similarity index 100% rename from lib/libarchive/archive_write_open_file.c rename to external/bsd/libarchive/dist/libarchive/archive_write_open_file.c diff --git a/lib/libarchive/archive_write_open_filename.c b/external/bsd/libarchive/dist/libarchive/archive_write_open_filename.c similarity index 100% rename from lib/libarchive/archive_write_open_filename.c rename to external/bsd/libarchive/dist/libarchive/archive_write_open_filename.c diff --git a/lib/libarchive/archive_write_open_memory.c b/external/bsd/libarchive/dist/libarchive/archive_write_open_memory.c similarity index 100% rename from lib/libarchive/archive_write_open_memory.c rename to external/bsd/libarchive/dist/libarchive/archive_write_open_memory.c diff --git a/lib/libarchive/archive_write_private.h b/external/bsd/libarchive/dist/libarchive/archive_write_private.h similarity index 98% rename from lib/libarchive/archive_write_private.h rename to external/bsd/libarchive/dist/libarchive/archive_write_private.h index cc7ad6ad1..f9b656555 100644 --- a/lib/libarchive/archive_write_private.h +++ b/external/bsd/libarchive/dist/libarchive/archive_write_private.h @@ -41,11 +41,8 @@ struct archive_write { /* Dev/ino of the archive being written. */ dev_t skip_file_dev; -#ifndef __minix int64_t skip_file_ino; -#else - ino_t skip_file_ino; -#endif + /* Utility: Pointer to a block of nulls. */ const unsigned char *nulls; size_t null_length; diff --git a/lib/libarchive/archive_write_set_compression_bzip2.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_compression_bzip2.c similarity index 99% rename from lib/libarchive/archive_write_set_compression_bzip2.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_compression_bzip2.c index 3aa2a8365..626bbbc16 100644 --- a/lib/libarchive/archive_write_set_compression_bzip2.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_compression_bzip2.c @@ -45,7 +45,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_bzip2.c 20 #include "archive_private.h" #include "archive_write_private.h" -#ifndef HAVE_BZLIB_H +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) int archive_write_set_compression_bzip2(struct archive *a) { @@ -58,11 +58,7 @@ archive_write_set_compression_bzip2(struct archive *a) struct private_data { bz_stream stream; -#ifndef __minix int64_t total_in; -#else - ssize_t total_in; -#endif char *compressed; size_t compressed_buffer_size; }; @@ -409,4 +405,4 @@ drive_compressor(struct archive_write *a, struct private_data *state, int finish } } -#endif /* HAVE_BZLIB_H */ +#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */ diff --git a/lib/libarchive/archive_write_set_compression_compress.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_compression_compress.c similarity index 100% rename from lib/libarchive/archive_write_set_compression_compress.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_compression_compress.c diff --git a/lib/libarchive/archive_write_set_compression_gzip.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_compression_gzip.c similarity index 99% rename from lib/libarchive/archive_write_set_compression_gzip.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_compression_gzip.c index edc1a8e99..f0176e25f 100644 --- a/lib/libarchive/archive_write_set_compression_gzip.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_compression_gzip.c @@ -58,11 +58,7 @@ archive_write_set_compression_gzip(struct archive *a) struct private_data { z_stream stream; -#ifndef __minix int64_t total_in; -#else - ssize_t total_in; -#endif unsigned char *compressed; size_t compressed_buffer_size; unsigned long crc; diff --git a/lib/libarchive/archive_write_set_compression_none.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_compression_none.c similarity index 100% rename from lib/libarchive/archive_write_set_compression_none.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_compression_none.c diff --git a/lib/libarchive/archive_write_set_compression_program.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_compression_program.c similarity index 100% rename from lib/libarchive/archive_write_set_compression_program.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_compression_program.c diff --git a/lib/libarchive/archive_write_set_compression_xz.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_compression_xz.c similarity index 100% rename from lib/libarchive/archive_write_set_compression_xz.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_compression_xz.c diff --git a/lib/libarchive/archive_write_set_format.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format.c similarity index 99% rename from lib/libarchive/archive_write_set_format.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_format.c index 848064856..b1593fbe6 100644 --- a/lib/libarchive/archive_write_set_format.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_format.c @@ -41,11 +41,9 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format.c 201168 2009-1 static struct { int code; int (*setter)(struct archive *); } codes[] = { -#ifndef __minix { ARCHIVE_FORMAT_CPIO, archive_write_set_format_cpio }, { ARCHIVE_FORMAT_CPIO_SVR4_NOCRC, archive_write_set_format_cpio_newc }, { ARCHIVE_FORMAT_CPIO_POSIX, archive_write_set_format_cpio }, -#endif { ARCHIVE_FORMAT_MTREE, archive_write_set_format_mtree }, { ARCHIVE_FORMAT_SHAR, archive_write_set_format_shar }, { ARCHIVE_FORMAT_SHAR_BASE, archive_write_set_format_shar }, diff --git a/lib/libarchive/archive_write_set_format_ar.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ar.c similarity index 89% rename from lib/libarchive/archive_write_set_format_ar.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_format_ar.c index 54d297b0e..8d863198d 100644 --- a/lib/libarchive/archive_write_set_format_ar.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ar.c @@ -43,7 +43,6 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_ar.c 201108 200 #include "archive_private.h" #include "archive_write_private.h" -#ifndef __minix struct ar_w { uint64_t entry_bytes_remaining; uint64_t entry_padding; @@ -51,15 +50,7 @@ struct ar_w { int has_strtab; char *strtab; }; -#else -struct ar_w { - size_t entry_bytes_remaining; - size_t entry_padding; - int is_strtab; - int has_strtab; - char *strtab; -}; -#endif + /* * Define structure of the "ar" header. */ @@ -87,13 +78,8 @@ static int archive_write_ar_destroy(struct archive_write *); static int archive_write_ar_finish(struct archive_write *); static int archive_write_ar_finish_entry(struct archive_write *); static const char *ar_basename(const char *path); -#ifndef __minix static int format_octal(int64_t v, char *p, int s); static int format_decimal(int64_t v, char *p, int s); -#else -static int format_octal(int32_t v, char *p, int s); -static int format_decimal(int32_t v, char *p, int s); -#endif int archive_write_set_format_ar_bsd(struct archive *_a) @@ -157,11 +143,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) struct ar_w *ar; const char *pathname; const char *filename; -#ifndef __minix int64_t size; -#else - ssize_t size; -#endif append_fn = 0; ar = (struct ar_w *)a->format_data; @@ -457,8 +439,8 @@ archive_write_ar_finish_entry(struct archive_write *a) if (ar->entry_padding != 1) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Padding wrong size: %d should be 1 or 0", - ar->entry_padding); + "Padding wrong size: %lld should be 1 or 0", + (long long)ar->entry_padding); return (ARCHIVE_WARN); } @@ -471,7 +453,6 @@ archive_write_ar_finish_entry(struct archive_write *a) * NB: This version is slightly different from the one in * _ustar.c */ -#ifndef __minix static int format_octal(int64_t v, char *p, int s) { @@ -507,48 +488,10 @@ format_octal(int64_t v, char *p, int s) return (-1); } -#else -static int -format_octal(int32_t v, char *p, int s) -{ - int len; - char *h; - - len = s; - h = p; - - /* Octal values can't be negative, so use 0. */ - if (v < 0) { - while (len-- > 0) - *p++ = '0'; - return (-1); - } - - p += s; /* Start at the end and work backwards. */ - do { - *--p = (char)('0' + (v & 7)); - v >>= 3; - } while (--s > 0 && v > 0); - - if (v == 0) { - memmove(h, p, len - s); - p = h + len - s; - while (s-- > 0) - *p++ = ' '; - return (0); - } - /* If it overflowed, fill field with max value. */ - while (len-- > 0) - *p++ = '7'; - - return (-1); -} -#endif /* * Format a number into the specified field using base-10. */ -#ifndef __minix static int format_decimal(int64_t v, char *p, int s) { @@ -584,43 +527,7 @@ format_decimal(int64_t v, char *p, int s) return (-1); } -#else -static int -format_decimal(int32_t v, char *p, int s) -{ - int len; - char *h; - - len = s; - h = p; - - /* Negative values in ar header are meaningless , so use 0. */ - if (v < 0) { - while (len-- > 0) - *p++ = '0'; - return (-1); - } - p += s; - do { - *--p = (char)('0' + (v % 10)); - v /= 10; - } while (--s > 0 && v > 0); - - if (v == 0) { - memmove(h, p, len - s); - p = h + len - s; - while (s-- > 0) - *p++ = ' '; - return (0); - } - /* If it overflowed, fill field with max value. */ - while (len-- > 0) - *p++ = '9'; - - return (-1); -} -#endif static const char * ar_basename(const char *path) { diff --git a/lib/libarchive/archive_write_set_format_by_name.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_by_name.c similarity index 99% rename from lib/libarchive/archive_write_set_format_by_name.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_format_by_name.c index 783a907a4..a0921199c 100644 --- a/lib/libarchive/archive_write_set_format_by_name.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_by_name.c @@ -48,12 +48,10 @@ struct { const char *name; int (*setter)(struct archive *); } names[] = { "arbsd", archive_write_set_format_ar_bsd }, { "argnu", archive_write_set_format_ar_svr4 }, { "arsvr4", archive_write_set_format_ar_svr4 }, - { "mtree", archive_write_set_format_mtree }, -#ifndef __minix { "cpio", archive_write_set_format_cpio }, + { "mtree", archive_write_set_format_mtree }, { "newc", archive_write_set_format_cpio_newc }, { "odc", archive_write_set_format_cpio }, -#endif { "pax", archive_write_set_format_pax }, { "posix", archive_write_set_format_pax }, { "shar", archive_write_set_format_shar }, diff --git a/external/bsd/libarchive/dist/libarchive/archive_write_set_format_cpio.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_cpio.c new file mode 100644 index 000000000..4e8e1e0bd --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_cpio.c @@ -0,0 +1,344 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio.c 201170 2009-12-29 06:34:23Z kientzle $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "archive.h" +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_write_private.h" + +static ssize_t archive_write_cpio_data(struct archive_write *, + const void *buff, size_t s); +static int archive_write_cpio_finish(struct archive_write *); +static int archive_write_cpio_destroy(struct archive_write *); +static int archive_write_cpio_finish_entry(struct archive_write *); +static int archive_write_cpio_header(struct archive_write *, + struct archive_entry *); +static int format_octal(int64_t, void *, int); +static int64_t format_octal_recursive(int64_t, char *, int); + +struct cpio { + uint64_t entry_bytes_remaining; + + int64_t ino_next; + + struct { int64_t old; int new;} *ino_list; + size_t ino_list_size; + size_t ino_list_next; +}; + +struct cpio_header { + char c_magic[6]; + char c_dev[6]; + char c_ino[6]; + char c_mode[6]; + char c_uid[6]; + char c_gid[6]; + char c_nlink[6]; + char c_rdev[6]; + char c_mtime[11]; + char c_namesize[6]; + char c_filesize[11]; +}; + +/* + * Set output format to 'cpio' format. + */ +int +archive_write_set_format_cpio(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct cpio *cpio; + + /* If someone else was already registered, unregister them. */ + if (a->format_destroy != NULL) + (a->format_destroy)(a); + + cpio = (struct cpio *)malloc(sizeof(*cpio)); + if (cpio == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); + return (ARCHIVE_FATAL); + } + memset(cpio, 0, sizeof(*cpio)); + a->format_data = cpio; + + a->pad_uncompressed = 1; + a->format_name = "cpio"; + a->format_write_header = archive_write_cpio_header; + a->format_write_data = archive_write_cpio_data; + a->format_finish_entry = archive_write_cpio_finish_entry; + a->format_finish = archive_write_cpio_finish; + a->format_destroy = archive_write_cpio_destroy; + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX; + a->archive.archive_format_name = "POSIX cpio"; + return (ARCHIVE_OK); +} + +/* + * Ino values are as long as 64 bits on some systems; cpio format + * only allows 18 bits and relies on the ino values to identify hardlinked + * files. So, we can't merely "hash" the ino numbers since collisions + * would corrupt the archive. Instead, we generate synthetic ino values + * to store in the archive and maintain a map of original ino values to + * synthetic ones so we can preserve hardlink information. + * + * TODO: Make this more efficient. It's not as bad as it looks (most + * files don't have any hardlinks and we don't do any work here for those), + * but it wouldn't be hard to do better. + * + * TODO: Work with dev/ino pairs here instead of just ino values. + */ +static int +synthesize_ino_value(struct cpio *cpio, struct archive_entry *entry) +{ + int64_t ino = archive_entry_ino64(entry); + int ino_new; + size_t i; + + /* + * If no index number was given, don't assign one. In + * particular, this handles the end-of-archive marker + * correctly by giving it a zero index value. (This is also + * why we start our synthetic index numbers with one below.) + */ + if (ino == 0) + return (0); + + /* Don't store a mapping if we don't need to. */ + if (archive_entry_nlink(entry) < 2) { + return ++cpio->ino_next; + } + + /* Look up old ino; if we have it, this is a hardlink + * and we reuse the same value. */ + for (i = 0; i < cpio->ino_list_next; ++i) { + if (cpio->ino_list[i].old == ino) + return (cpio->ino_list[i].new); + } + + /* Assign a new index number. */ + ino_new = ++cpio->ino_next; + + /* Ensure space for the new mapping. */ + if (cpio->ino_list_size <= cpio->ino_list_next) { + size_t newsize = cpio->ino_list_size < 512 + ? 512 : cpio->ino_list_size * 2; + void *newlist = realloc(cpio->ino_list, + sizeof(cpio->ino_list[0]) * newsize); + if (newlist == NULL) + return (-1); + + cpio->ino_list_size = newsize; + cpio->ino_list = newlist; + } + + /* Record and return the new value. */ + cpio->ino_list[cpio->ino_list_next].old = ino; + cpio->ino_list[cpio->ino_list_next].new = ino_new; + ++cpio->ino_list_next; + return (ino_new); +} + +static int +archive_write_cpio_header(struct archive_write *a, struct archive_entry *entry) +{ + struct cpio *cpio; + const char *p, *path; + int pathlength, ret, ret2; + int64_t ino; + struct cpio_header h; + + cpio = (struct cpio *)a->format_data; + ret2 = ARCHIVE_OK; + + path = archive_entry_pathname(entry); + pathlength = (int)strlen(path) + 1; /* Include trailing null. */ + + memset(&h, 0, sizeof(h)); + format_octal(070707, &h.c_magic, sizeof(h.c_magic)); + format_octal(archive_entry_dev(entry), &h.c_dev, sizeof(h.c_dev)); + + ino = synthesize_ino_value(cpio, entry); + if (ino < 0) { + archive_set_error(&a->archive, ENOMEM, + "No memory for ino translation table"); + return (ARCHIVE_FATAL); + } else if (ino > 0777777) { + archive_set_error(&a->archive, ERANGE, + "Too many files for this cpio format"); + return (ARCHIVE_FATAL); + } + format_octal(ino & 0777777, &h.c_ino, sizeof(h.c_ino)); + + format_octal(archive_entry_mode(entry), &h.c_mode, sizeof(h.c_mode)); + format_octal(archive_entry_uid(entry), &h.c_uid, sizeof(h.c_uid)); + format_octal(archive_entry_gid(entry), &h.c_gid, sizeof(h.c_gid)); + format_octal(archive_entry_nlink(entry), &h.c_nlink, sizeof(h.c_nlink)); + if (archive_entry_filetype(entry) == AE_IFBLK + || archive_entry_filetype(entry) == AE_IFCHR) + format_octal(archive_entry_dev(entry), &h.c_rdev, sizeof(h.c_rdev)); + else + format_octal(0, &h.c_rdev, sizeof(h.c_rdev)); + format_octal(archive_entry_mtime(entry), &h.c_mtime, sizeof(h.c_mtime)); + format_octal(pathlength, &h.c_namesize, sizeof(h.c_namesize)); + + /* Non-regular files don't store bodies. */ + if (archive_entry_filetype(entry) != AE_IFREG) + archive_entry_set_size(entry, 0); + + /* Symlinks get the link written as the body of the entry. */ + p = archive_entry_symlink(entry); + if (p != NULL && *p != '\0') + format_octal(strlen(p), &h.c_filesize, sizeof(h.c_filesize)); + else + format_octal(archive_entry_size(entry), + &h.c_filesize, sizeof(h.c_filesize)); + + ret = (a->compressor.write)(a, &h, sizeof(h)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + ret = (a->compressor.write)(a, path, pathlength); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + cpio->entry_bytes_remaining = archive_entry_size(entry); + + /* Write the symlink now. */ + if (p != NULL && *p != '\0') + ret = (a->compressor.write)(a, p, strlen(p)); + + if (ret == ARCHIVE_OK) + ret = ret2; + return (ret); +} + +static ssize_t +archive_write_cpio_data(struct archive_write *a, const void *buff, size_t s) +{ + struct cpio *cpio; + int ret; + + cpio = (struct cpio *)a->format_data; + if (s > cpio->entry_bytes_remaining) + s = cpio->entry_bytes_remaining; + + ret = (a->compressor.write)(a, buff, s); + cpio->entry_bytes_remaining -= s; + if (ret >= 0) + return (s); + else + return (ret); +} + +/* + * Format a number into the specified field. + */ +static int +format_octal(int64_t v, void *p, int digits) +{ + int64_t max; + int ret; + + max = (((int64_t)1) << (digits * 3)) - 1; + if (v >= 0 && v <= max) { + format_octal_recursive(v, (char *)p, digits); + ret = 0; + } else { + format_octal_recursive(max, (char *)p, digits); + ret = -1; + } + return (ret); +} + +static int64_t +format_octal_recursive(int64_t v, char *p, int s) +{ + if (s == 0) + return (v); + v = format_octal_recursive(v, p+1, s-1); + *p = '0' + (v & 7); + return (v >> 3); +} + +static int +archive_write_cpio_finish(struct archive_write *a) +{ + int er; + struct archive_entry *trailer; + + trailer = archive_entry_new(); + /* nlink = 1 here for GNU cpio compat. */ + archive_entry_set_nlink(trailer, 1); + archive_entry_set_pathname(trailer, "TRAILER!!!"); + er = archive_write_cpio_header(a, trailer); + archive_entry_free(trailer); + return (er); +} + +static int +archive_write_cpio_destroy(struct archive_write *a) +{ + struct cpio *cpio; + + cpio = (struct cpio *)a->format_data; + free(cpio->ino_list); + free(cpio); + a->format_data = NULL; + return (ARCHIVE_OK); +} + +static int +archive_write_cpio_finish_entry(struct archive_write *a) +{ + struct cpio *cpio; + size_t to_write; + int ret; + + cpio = (struct cpio *)a->format_data; + ret = ARCHIVE_OK; + while (cpio->entry_bytes_remaining > 0) { + to_write = cpio->entry_bytes_remaining < a->null_length ? + cpio->entry_bytes_remaining : a->null_length; + ret = (a->compressor.write)(a, a->nulls, to_write); + if (ret != ARCHIVE_OK) + return (ret); + cpio->entry_bytes_remaining -= to_write; + } + return (ret); +} diff --git a/external/bsd/libarchive/dist/libarchive/archive_write_set_format_cpio_newc.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_cpio_newc.c new file mode 100644 index 000000000..0af089095 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_cpio_newc.c @@ -0,0 +1,295 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2006 Rudolf Marek SYSGO s.r.o. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio_newc.c 201160 2009-12-29 05:41:57Z kientzle $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "archive.h" +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_write_private.h" + +static ssize_t archive_write_newc_data(struct archive_write *, + const void *buff, size_t s); +static int archive_write_newc_finish(struct archive_write *); +static int archive_write_newc_destroy(struct archive_write *); +static int archive_write_newc_finish_entry(struct archive_write *); +static int archive_write_newc_header(struct archive_write *, + struct archive_entry *); +static int format_hex(int64_t, void *, int); +static int64_t format_hex_recursive(int64_t, char *, int); + +struct cpio { + uint64_t entry_bytes_remaining; + int padding; +}; + +struct cpio_header_newc { + char c_magic[6]; + char c_ino[8]; + char c_mode[8]; + char c_uid[8]; + char c_gid[8]; + char c_nlink[8]; + char c_mtime[8]; + char c_filesize[8]; + char c_devmajor[8]; + char c_devminor[8]; + char c_rdevmajor[8]; + char c_rdevminor[8]; + char c_namesize[8]; + char c_checksum[8]; +}; + +/* Logic trick: difference between 'n' and next multiple of 4 */ +#define PAD4(n) (3 & (1 + ~(n))) + +/* + * Set output format to 'cpio' format. + */ +int +archive_write_set_format_cpio_newc(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct cpio *cpio; + + /* If someone else was already registered, unregister them. */ + if (a->format_destroy != NULL) + (a->format_destroy)(a); + + cpio = (struct cpio *)malloc(sizeof(*cpio)); + if (cpio == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); + return (ARCHIVE_FATAL); + } + memset(cpio, 0, sizeof(*cpio)); + a->format_data = cpio; + + a->pad_uncompressed = 1; + a->format_name = "cpio"; + a->format_write_header = archive_write_newc_header; + a->format_write_data = archive_write_newc_data; + a->format_finish_entry = archive_write_newc_finish_entry; + a->format_finish = archive_write_newc_finish; + a->format_destroy = archive_write_newc_destroy; + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC; + a->archive.archive_format_name = "SVR4 cpio nocrc"; + return (ARCHIVE_OK); +} + +static int +archive_write_newc_header(struct archive_write *a, struct archive_entry *entry) +{ + int64_t ino; + struct cpio *cpio; + const char *p, *path; + int pathlength, ret, ret2; + struct cpio_header_newc h; + int pad; + + cpio = (struct cpio *)a->format_data; + ret2 = ARCHIVE_OK; + + path = archive_entry_pathname(entry); + pathlength = (int)strlen(path) + 1; /* Include trailing null. */ + + memset(&h, 0, sizeof(h)); + format_hex(0x070701, &h.c_magic, sizeof(h.c_magic)); + format_hex(archive_entry_devmajor(entry), &h.c_devmajor, + sizeof(h.c_devmajor)); + format_hex(archive_entry_devminor(entry), &h.c_devminor, + sizeof(h.c_devminor)); + + ino = archive_entry_ino64(entry); + if (ino > 0xffffffff) { + archive_set_error(&a->archive, ERANGE, + "large inode number truncated"); + ret2 = ARCHIVE_WARN; + } + + format_hex(ino & 0xffffffff, &h.c_ino, sizeof(h.c_ino)); + format_hex(archive_entry_mode(entry), &h.c_mode, sizeof(h.c_mode)); + format_hex(archive_entry_uid(entry), &h.c_uid, sizeof(h.c_uid)); + format_hex(archive_entry_gid(entry), &h.c_gid, sizeof(h.c_gid)); + format_hex(archive_entry_nlink(entry), &h.c_nlink, sizeof(h.c_nlink)); + if (archive_entry_filetype(entry) == AE_IFBLK + || archive_entry_filetype(entry) == AE_IFCHR) { + format_hex(archive_entry_rdevmajor(entry), &h.c_rdevmajor, sizeof(h.c_rdevmajor)); + format_hex(archive_entry_rdevminor(entry), &h.c_rdevminor, sizeof(h.c_rdevminor)); + } else { + format_hex(0, &h.c_rdevmajor, sizeof(h.c_rdevmajor)); + format_hex(0, &h.c_rdevminor, sizeof(h.c_rdevminor)); + } + format_hex(archive_entry_mtime(entry), &h.c_mtime, sizeof(h.c_mtime)); + format_hex(pathlength, &h.c_namesize, sizeof(h.c_namesize)); + format_hex(0, &h.c_checksum, sizeof(h.c_checksum)); + + /* Non-regular files don't store bodies. */ + if (archive_entry_filetype(entry) != AE_IFREG) + archive_entry_set_size(entry, 0); + + /* Symlinks get the link written as the body of the entry. */ + p = archive_entry_symlink(entry); + if (p != NULL && *p != '\0') + format_hex(strlen(p), &h.c_filesize, sizeof(h.c_filesize)); + else + format_hex(archive_entry_size(entry), + &h.c_filesize, sizeof(h.c_filesize)); + + ret = (a->compressor.write)(a, &h, sizeof(h)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Pad pathname to even length. */ + ret = (a->compressor.write)(a, path, pathlength); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + pad = PAD4(pathlength + sizeof(struct cpio_header_newc)); + if (pad) + ret = (a->compressor.write)(a, "\0\0\0", pad); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + cpio->entry_bytes_remaining = archive_entry_size(entry); + cpio->padding = PAD4(cpio->entry_bytes_remaining); + + /* Write the symlink now. */ + if (p != NULL && *p != '\0') { + ret = (a->compressor.write)(a, p, strlen(p)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + pad = PAD4(strlen(p)); + ret = (a->compressor.write)(a, "\0\0\0", pad); + } + + if (ret == ARCHIVE_OK) + ret = ret2; + return (ret); +} + +static ssize_t +archive_write_newc_data(struct archive_write *a, const void *buff, size_t s) +{ + struct cpio *cpio; + int ret; + + cpio = (struct cpio *)a->format_data; + if (s > cpio->entry_bytes_remaining) + s = cpio->entry_bytes_remaining; + + ret = (a->compressor.write)(a, buff, s); + cpio->entry_bytes_remaining -= s; + if (ret >= 0) + return (s); + else + return (ret); +} + +/* + * Format a number into the specified field. + */ +static int +format_hex(int64_t v, void *p, int digits) +{ + int64_t max; + int ret; + + max = (((int64_t)1) << (digits * 4)) - 1; + if (v >= 0 && v <= max) { + format_hex_recursive(v, (char *)p, digits); + ret = 0; + } else { + format_hex_recursive(max, (char *)p, digits); + ret = -1; + } + return (ret); +} + +static int64_t +format_hex_recursive(int64_t v, char *p, int s) +{ + if (s == 0) + return (v); + v = format_hex_recursive(v, p+1, s-1); + *p = "0123456789abcdef"[v & 0xf]; + return (v >> 4); +} + +static int +archive_write_newc_finish(struct archive_write *a) +{ + int er; + struct archive_entry *trailer; + + trailer = archive_entry_new(); + archive_entry_set_nlink(trailer, 1); + archive_entry_set_pathname(trailer, "TRAILER!!!"); + er = archive_write_newc_header(a, trailer); + archive_entry_free(trailer); + return (er); +} + +static int +archive_write_newc_destroy(struct archive_write *a) +{ + struct cpio *cpio; + + cpio = (struct cpio *)a->format_data; + free(cpio); + a->format_data = NULL; + return (ARCHIVE_OK); +} + +static int +archive_write_newc_finish_entry(struct archive_write *a) +{ + struct cpio *cpio; + size_t to_write; + int ret; + + cpio = (struct cpio *)a->format_data; + while (cpio->entry_bytes_remaining > 0) { + to_write = cpio->entry_bytes_remaining < a->null_length ? + cpio->entry_bytes_remaining : a->null_length; + ret = (a->compressor.write)(a, a->nulls, to_write); + if (ret != ARCHIVE_OK) + return (ret); + cpio->entry_bytes_remaining -= to_write; + } + ret = (a->compressor.write)(a, a->nulls, cpio->padding); + return (ret); +} diff --git a/lib/libarchive/archive_write_set_format_mtree.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_mtree.c similarity index 99% rename from lib/libarchive/archive_write_set_format_mtree.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_format_mtree.c index 15c5cb789..7feeca92e 100644 --- a/lib/libarchive/archive_write_set_format_mtree.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_mtree.c @@ -49,11 +49,7 @@ struct mtree_writer { struct archive_string ebuf; struct archive_string buf; int first; -#ifndef __minix uint64_t entry_bytes_remaining; -#else - size_t entry_bytes_remaining; -#endif struct { int output; int processed; @@ -69,11 +65,7 @@ struct mtree_writer { /* chekc sum */ int compute_sum; uint32_t crc; -#ifndef __minix uint64_t crc_len; -#else - uint32_t crc_len; -#endif #ifdef ARCHIVE_HAS_MD5 archive_md5_ctx md5ctx; #endif @@ -760,11 +752,7 @@ archive_write_mtree_finish_entry(struct archive_write *a) } if (mtree->compute_sum & F_CKSUM) { -#ifndef __minix uint64_t len; -#else - uint32_t len; -#endif /* Include the length of the file. */ for (len = mtree->crc_len; len != 0; len >>= 8) COMPUTE_CRC(mtree->crc, len & 0xff); diff --git a/lib/libarchive/archive_write_set_format_pax.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_pax.c similarity index 94% rename from lib/libarchive/archive_write_set_format_pax.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_format_pax.c index eab20c2b2..00c3f3f08 100644 --- a/lib/libarchive/archive_write_set_format_pax.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_pax.c @@ -41,34 +41,19 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_pax.c 201162 20 #include "archive_private.h" #include "archive_write_private.h" -#ifndef __minix struct pax { uint64_t entry_bytes_remaining; uint64_t entry_padding; struct archive_string pax_header; }; -#else -struct pax { - size_t entry_bytes_remaining; - off_t entry_padding; - struct archive_string pax_header; -}; -#endif + static void add_pax_attr(struct archive_string *, const char *key, const char *value); -#ifndef __minix static void add_pax_attr_int(struct archive_string *, const char *key, int64_t value); static void add_pax_attr_time(struct archive_string *, const char *key, int64_t sec, unsigned long nanos); -#else -static void add_pax_attr_int(struct archive_string *, - const char *key, int32_t value); -static void add_pax_attr_time(struct archive_string *, - const char *key, time_t sec, - unsigned long nanos); -#endif static void add_pax_attr_w(struct archive_string *, const char *key, const wchar_t *wvalue); static ssize_t archive_write_pax_data(struct archive_write *, @@ -82,11 +67,7 @@ static char *base64_encode(const char *src, size_t len); static char *build_pax_attribute_name(char *dest, const char *src); static char *build_ustar_entry_name(char *dest, const char *src, size_t src_length, const char *insert); -#ifndef __minix static char *format_int(char *dest, int64_t); -#else -static char *format_int(char *dest, int32_t); -#endif static int has_non_ASCII(const wchar_t *); static char *url_encode(const char *in); static int write_nulls(struct archive_write *, size_t); @@ -148,7 +129,6 @@ archive_write_set_format_pax(struct archive *_a) * unlikely to encounter many real files created before Jan 1, 1970, * much less ones with timestamps recorded to sub-second resolution. */ -#ifndef __minix static void add_pax_attr_time(struct archive_string *as, const char *key, int64_t sec, unsigned long nanos) @@ -184,45 +164,7 @@ add_pax_attr_time(struct archive_string *as, const char *key, add_pax_attr(as, key, t); } -#else -static void -add_pax_attr_time(struct archive_string *as, const char *key, - time_t sec, unsigned long nanos) -{ - int digit, i; - char *t; - /* - * Note that each byte contributes fewer than 3 base-10 - * digits, so this will always be big enough. - */ - char tmp[1 + 3*sizeof(sec) + 1 + 3*sizeof(nanos)]; - - tmp[sizeof(tmp) - 1] = 0; - t = tmp + sizeof(tmp) - 1; - - /* Skip trailing zeros in the fractional part. */ - for (digit = 0, i = 10; i > 0 && digit == 0; i--) { - digit = nanos % 10; - nanos /= 10; - } - - /* Only format the fraction if it's non-zero. */ - if (i > 0) { - while (i > 0) { - *--t = "0123456789"[digit]; - digit = nanos % 10; - nanos /= 10; - i--; - } - *--t = '.'; - } - t = format_int(t, sec); - - add_pax_attr(as, key, t); -} -#endif -#ifndef __minix static char * format_int(char *t, int64_t i) { @@ -241,28 +183,7 @@ format_int(char *t, int64_t i) *--t = '-'; return (t); } -#else -static char * -format_int(char *t, int32_t i) -{ - int sign; - - if (i < 0) { - sign = -1; - i = -i; - } else - sign = 1; - - do { - *--t = "0123456789"[i % 10]; - } while (i /= 10); - if (sign < 0) - *--t = '-'; - return (t); -} -#endif -#ifndef __minix static void add_pax_attr_int(struct archive_string *as, const char *key, int64_t value) { @@ -271,16 +192,6 @@ add_pax_attr_int(struct archive_string *as, const char *key, int64_t value) tmp[sizeof(tmp) - 1] = 0; add_pax_attr(as, key, format_int(tmp + sizeof(tmp) - 1, value)); } -#else -static void -add_pax_attr_int(struct archive_string *as, const char *key, int32_t value) -{ - char tmp[1 + 3 * sizeof(value)]; - - tmp[sizeof(tmp) - 1] = 0; - add_pax_attr(as, key, format_int(tmp + sizeof(tmp) - 1, value)); -} -#endif static char * utf8_encode(const wchar_t *wval) @@ -706,18 +617,12 @@ archive_write_pax_header(struct archive_write *a, } } -#ifndef __minix /* If file size is too large, add 'size' to pax extended attrs. */ if (archive_entry_size(entry_main) >= (((int64_t)1) << 33)) { add_pax_attr_int(&(pax->pax_header), "size", archive_entry_size(entry_main)); need_extension = 1; } -#else - /* This is not happening on Minix, as the size of anything - * on minix fits in 32 bits - */ -#endif /* If numeric GID is too large, add 'gid' to pax extended attrs. */ if ((unsigned int)archive_entry_gid(entry_main) >= (1 << 18)) { @@ -913,13 +818,8 @@ archive_write_pax_header(struct archive_write *a, * major/minor portions of "SCHILY.dev". */ add_pax_attr_int(&(pax->pax_header), "SCHILY.dev", archive_entry_dev(entry_main)); -#ifndef __minix add_pax_attr_int(&(pax->pax_header), "SCHILY.ino", archive_entry_ino64(entry_main)); -#else - add_pax_attr_int(&(pax->pax_header), "SCHILY.ino", - archive_entry_ino(entry_main)); -#endif add_pax_attr_int(&(pax->pax_header), "SCHILY.nlink", archive_entry_nlink(entry_main)); @@ -996,16 +896,12 @@ archive_write_pax_header(struct archive_write *a, archive_strlen(&(pax->pax_header))); /* Copy uid/gid (but clip to ustar limits). */ uid = archive_entry_uid(entry_main); -#ifndef __minix /* Does not happen on minix as sizeof(uid_t) == 2 */ if ((unsigned int)uid >= 1 << 18) uid = (uid_t)(1 << 18) - 1; -#endif archive_entry_set_uid(pax_attr_entry, uid); gid = archive_entry_gid(entry_main); -#ifndef __minix /* Does not happen on minix as sizeof(gid_t) == 1 */ if ((unsigned int)gid >= 1 << 18) gid = (gid_t)(1 << 18) - 1; -#endif archive_entry_set_gid(pax_attr_entry, gid); /* Copy mode over (but not setuid/setgid bits) */ mode = archive_entry_mode(entry_main); @@ -1059,11 +955,8 @@ archive_write_pax_header(struct archive_write *a, } pax->entry_bytes_remaining = archive_strlen(&(pax->pax_header)); -#ifndef __minix pax->entry_padding = 0x1ff & (-(int64_t)pax->entry_bytes_remaining); -#else - pax->entry_padding = 0x1ff & (-(int32_t)pax->entry_bytes_remaining); -#endif + r = (a->compressor.write)(a, pax->pax_header.s, archive_strlen(&(pax->pax_header))); if (r != ARCHIVE_OK) { @@ -1091,11 +984,7 @@ archive_write_pax_header(struct archive_write *a, */ archive_entry_set_size(entry_original, archive_entry_size(entry_main)); pax->entry_bytes_remaining = archive_entry_size(entry_main); -#ifndef __minix pax->entry_padding = 0x1ff & (-(int64_t)pax->entry_bytes_remaining); -#else - pax->entry_padding = 0x1ff & (-(int32_t)pax->entry_bytes_remaining); -#endif archive_entry_free(entry_main); return (ret); diff --git a/lib/libarchive/archive_write_set_format_shar.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_shar.c similarity index 100% rename from lib/libarchive/archive_write_set_format_shar.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_format_shar.c diff --git a/lib/libarchive/archive_write_set_format_ustar.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ustar.c similarity index 99% rename from lib/libarchive/archive_write_set_format_ustar.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_format_ustar.c index 1de273fc2..4755a2384 100644 --- a/lib/libarchive/archive_write_set_format_ustar.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_ustar.c @@ -168,7 +168,7 @@ archive_write_set_format_ustar(struct archive *_a) /* Basic internal sanity test. */ if (sizeof(template_header) != 512) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %d should be 512", sizeof(template_header)); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %zd should be 512", sizeof(template_header)); return (ARCHIVE_FATAL); } diff --git a/lib/libarchive/archive_write_set_format_zip.c b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_zip.c similarity index 98% rename from lib/libarchive/archive_write_set_format_zip.c rename to external/bsd/libarchive/dist/libarchive/archive_write_set_format_zip.c index ca51e72b9..14cc6697d 100644 --- a/lib/libarchive/archive_write_set_format_zip.c +++ b/external/bsd/libarchive/dist/libarchive/archive_write_set_format_zip.c @@ -174,15 +174,9 @@ struct zip { struct zip_data_descriptor data_descriptor; struct zip_file_header_link *central_directory; struct zip_file_header_link *central_directory_end; -#ifndef __minix int64_t offset; int64_t written_bytes; int64_t remaining_data_bytes; -#else - off_t offset; - size_t written_bytes; - size_t remaining_data_bytes; -#endif enum compression compression; #ifdef HAVE_ZLIB_H @@ -288,11 +282,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) struct zip_data_descriptor *d; struct zip_file_header_link *l; int ret; -#ifndef __minix int64_t size; -#else - ssize_t size; -#endif mode_t type; /* Entries other than a regular file or a folder are skipped. */ @@ -409,13 +399,9 @@ archive_write_zip_data(struct archive_write *a, const void *buff, size_t s) struct zip *zip = a->format_data; struct zip_file_header_link *l = zip->central_directory_end; -#ifndef __minix if ((int64_t)s > zip->remaining_data_bytes) s = (size_t)zip->remaining_data_bytes; -#else - if (s > zip->remaining_data_bytes) - s = (size_t)zip->remaining_data_bytes; -#endif + if (s == 0) return 0; switch (zip->compression) { diff --git a/external/bsd/libarchive/dist/libarchive/cpio.5 b/external/bsd/libarchive/dist/libarchive/cpio.5 new file mode 100644 index 000000000..f54462818 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/cpio.5 @@ -0,0 +1,325 @@ +.\" Copyright (c) 2007 Tim Kientzle +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/libarchive/cpio.5,v 1.2 2008/05/26 17:00:23 kientzle Exp $ +.\" +.Dd October 5, 2007 +.Dt CPIO 5 +.Os +.Sh NAME +.Nm cpio +.Nd format of cpio archive files +.Sh DESCRIPTION +The +.Nm +archive format collects any number of files, directories, and other +file system objects (symbolic links, device nodes, etc.) into a single +stream of bytes. +.Ss General Format +Each file system object in a +.Nm +archive comprises a header record with basic numeric metadata +followed by the full pathname of the entry and the file data. +The header record stores a series of integer values that generally +follow the fields in +.Va struct stat . +(See +.Xr stat 2 +for details.) +The variants differ primarily in how they store those integers +(binary, octal, or hexadecimal). +The header is followed by the pathname of the +entry (the length of the pathname is stored in the header) +and any file data. +The end of the archive is indicated by a special record with +the pathname +.Dq TRAILER!!! . +.Ss PWB format +XXX Any documentation of the original PWB/UNIX 1.0 format? XXX +.Ss Old Binary Format +The old binary +.Nm +format stores numbers as 2-byte and 4-byte binary values. +Each entry begins with a header in the following format: +.Bd -literal -offset indent +struct header_old_cpio { + unsigned short c_magic; + unsigned short c_dev; + unsigned short c_ino; + unsigned short c_mode; + unsigned short c_uid; + unsigned short c_gid; + unsigned short c_nlink; + unsigned short c_rdev; + unsigned short c_mtime[2]; + unsigned short c_namesize; + unsigned short c_filesize[2]; +}; +.Ed +.Pp +The +.Va unsigned short +fields here are 16-bit integer values; the +.Va unsigned int +fields are 32-bit integer values. +The fields are as follows +.Bl -tag -width indent +.It Va magic +The integer value octal 070707. +This value can be used to determine whether this archive is +written with little-endian or big-endian integers. +.It Va dev , Va ino +The device and inode numbers from the disk. +These are used by programs that read +.Nm +archives to determine when two entries refer to the same file. +Programs that synthesize +.Nm +archives should be careful to set these to distinct values for each entry. +.It Va mode +The mode specifies both the regular permissions and the file type. +It consists of several bit fields as follows: +.Bl -tag -width "MMMMMMM" -compact +.It 0170000 +This masks the file type bits. +.It 0140000 +File type value for sockets. +.It 0120000 +File type value for symbolic links. +For symbolic links, the link body is stored as file data. +.It 0100000 +File type value for regular files. +.It 0060000 +File type value for block special devices. +.It 0040000 +File type value for directories. +.It 0020000 +File type value for character special devices. +.It 0010000 +File type value for named pipes or FIFOs. +.It 0004000 +SUID bit. +.It 0002000 +SGID bit. +.It 0001000 +Sticky bit. +On some systems, this modifies the behavior of executables and/or directories. +.It 0000777 +The lower 9 bits specify read/write/execute permissions +for world, group, and user following standard POSIX conventions. +.El +.It Va uid , Va gid +The numeric user id and group id of the owner. +.It Va nlink +The number of links to this file. +Directories always have a value of at least two here. +Note that hardlinked files include file data with every copy in the archive. +.It Va rdev +For block special and character special entries, +this field contains the associated device number. +For all other entry types, it should be set to zero by writers +and ignored by readers. +.It Va mtime +Modification time of the file, indicated as the number +of seconds since the start of the epoch, +00:00:00 UTC January 1, 1970. +The four-byte integer is stored with the most-significant 16 bits first +followed by the least-significant 16 bits. +Each of the two 16 bit values are stored in machine-native byte order. +.It Va namesize +The number of bytes in the pathname that follows the header. +This count includes the trailing NUL byte. +.It Va filesize +The size of the file. +Note that this archive format is limited to +four gigabyte file sizes. +See +.Va mtime +above for a description of the storage of four-byte integers. +.El +.Pp +The pathname immediately follows the fixed header. +If the +.Cm namesize +is odd, an additional NUL byte is added after the pathname. +The file data is then appended, padded with NUL +bytes to an even length. +.Pp +Hardlinked files are not given special treatment; +the full file contents are included with each copy of the +file. +.Ss Portable ASCII Format +.St -susv2 +standardized an ASCII variant that is portable across all +platforms. +It is commonly known as the +.Dq old character +format or as the +.Dq odc +format. +It stores the same numeric fields as the old binary format, but +represents them as 6-character or 11-character octal values. +.Bd -literal -offset indent +struct cpio_odc_header { + char c_magic[6]; + char c_dev[6]; + char c_ino[6]; + char c_mode[6]; + char c_uid[6]; + char c_gid[6]; + char c_nlink[6]; + char c_rdev[6]; + char c_mtime[11]; + char c_namesize[6]; + char c_filesize[11]; +}; +.Ed +.Pp +The fields are identical to those in the old binary format. +The name and file body follow the fixed header. +Unlike the old binary format, there is no additional padding +after the pathname or file contents. +If the files being archived are themselves entirely ASCII, then +the resulting archive will be entirely ASCII, except for the +NUL byte that terminates the name field. +.Ss New ASCII Format +The "new" ASCII format uses 8-byte hexadecimal fields for +all numbers and separates device numbers into separate fields +for major and minor numbers. +.Bd -literal -offset indent +struct cpio_newc_header { + char c_magic[6]; + char c_ino[8]; + char c_mode[8]; + char c_uid[8]; + char c_gid[8]; + char c_nlink[8]; + char c_mtime[8]; + char c_filesize[8]; + char c_devmajor[8]; + char c_devminor[8]; + char c_rdevmajor[8]; + char c_rdevminor[8]; + char c_namesize[8]; + char c_check[8]; +}; +.Ed +.Pp +Except as specified below, the fields here match those specified +for the old binary format above. +.Bl -tag -width indent +.It Va magic +The string +.Dq 070701 . +.It Va check +This field is always set to zero by writers and ignored by readers. +See the next section for more details. +.El +.Pp +The pathname is followed by NUL bytes so that the total size +of the fixed header plus pathname is a multiple of four. +Likewise, the file data is padded to a multiple of four bytes. +Note that this format supports only 4 gigabyte files (unlike the +older ASCII format, which supports 8 gigabyte files). +.Pp +In this format, hardlinked files are handled by setting the +filesize to zero for each entry except the last one that +appears in the archive. +.Ss New CRC Format +The CRC format is identical to the new ASCII format described +in the previous section except that the magic field is set +to +.Dq 070702 +and the +.Va check +field is set to the sum of all bytes in the file data. +This sum is computed treating all bytes as unsigned values +and using unsigned arithmetic. +Only the least-significant 32 bits of the sum are stored. +.Ss HP variants +The +.Nm cpio +implementation distributed with HPUX used XXXX but stored +device numbers differently XXX. +.Ss Other Extensions and Variants +Sun Solaris uses additional file types to store extended file +data, including ACLs and extended attributes, as special +entries in cpio archives. +.Pp +XXX Others? XXX +.Sh BUGS +The +.Dq CRC +format is mis-named, as it uses a simple checksum and +not a cyclic redundancy check. +.Pp +The old binary format is limited to 16 bits for user id, +group id, device, and inode numbers. +It is limited to 4 gigabyte file sizes. +.Pp +The old ASCII format is limited to 18 bits for +the user id, group id, device, and inode numbers. +It is limited to 8 gigabyte file sizes. +.Pp +The new ASCII format is limited to 4 gigabyte file sizes. +.Pp +None of the cpio formats store user or group names, +which are essential when moving files between systems with +dissimilar user or group numbering. +.Pp +Especially when writing older cpio variants, it may be necessary +to map actual device/inode values to synthesized values that +fit the available fields. +With very large filesystems, this may be necessary even for +the newer formats. +.Sh SEE ALSO +.Xr cpio 1 , +.Xr tar 5 +.Sh STANDARDS +The +.Nm cpio +utility is no longer a part of POSIX or the Single Unix Standard. +It last appeared in +.St -susv2 . +It has been supplanted in subsequent standards by +.Xr pax 1 . +The portable ASCII format is currently part of the specification for the +.Xr pax 1 +utility. +.Sh HISTORY +The original cpio utility was written by Dick Haight +while working in AT&T's Unix Support Group. +It appeared in 1977 as part of PWB/UNIX 1.0, the +.Dq Programmer's Work Bench +derived from +.At v6 +that was used internally at AT&T. +Both the old binary and old character formats were in use +by 1980, according to the System III source released +by SCO under their +.Dq Ancient Unix +license. +The character format was adopted as part of +.St -p1003.1-88 . +XXX when did "newc" appear? Who invented it? When did HP come out with their variant? When did Sun introduce ACLs and extended attributes? XXX diff --git a/lib/libarchive/filter_fork.c b/external/bsd/libarchive/dist/libarchive/filter_fork.c similarity index 95% rename from lib/libarchive/filter_fork.c rename to external/bsd/libarchive/dist/libarchive/filter_fork.c index 7b278c794..d160524b0 100644 --- a/lib/libarchive/filter_fork.c +++ b/external/bsd/libarchive/dist/libarchive/filter_fork.c @@ -31,17 +31,13 @@ __FBSDID("$FreeBSD: head/lib/libarchive/filter_fork.c 182958 2008-09-12 05:33:00Z kientzle $"); -#if defined(HAVE_POLL) +#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H)) # if defined(HAVE_POLL_H) # include # elif defined(HAVE_SYS_POLL_H) # include -# else -# undef HAVE_POLL # endif -#endif - -#if defined(HAVE_SELECT) && !defined(HAVE_POLL) +#elif defined(HAVE_SELECT) # if defined(HAVE_SYS_SELECT_H) # include # elif defined(HAVE_UNISTD_H) @@ -125,7 +121,7 @@ state_allocated: void __archive_check_child(int in, int out) { -#if defined(HAVE_POLL) +#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H)) struct pollfd fds[2]; int idx; diff --git a/lib/libarchive/filter_fork.h b/external/bsd/libarchive/dist/libarchive/filter_fork.h similarity index 100% rename from lib/libarchive/filter_fork.h rename to external/bsd/libarchive/dist/libarchive/filter_fork.h diff --git a/external/bsd/libarchive/dist/libarchive/filter_fork_windows.c b/external/bsd/libarchive/dist/libarchive/filter_fork_windows.c new file mode 100644 index 000000000..38b7097ee --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/filter_fork_windows.c @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "archive_platform.h" + +#if defined(_WIN32) && !defined(__CYGWIN__) + +#include "filter_fork.h" + +pid_t +__archive_create_child(const char *path, int *child_stdin, int *child_stdout) +{ + HANDLE childStdout[2], childStdin[2], childStdinWr, childStdoutRd; + SECURITY_ATTRIBUTES secAtts; + STARTUPINFO staInfo; + PROCESS_INFORMATION childInfo; + char cmd[MAX_PATH]; + DWORD mode; + + secAtts.nLength = sizeof(SECURITY_ATTRIBUTES); + secAtts.bInheritHandle = TRUE; + secAtts.lpSecurityDescriptor = NULL; + if (CreatePipe(&childStdout[0], &childStdout[1], &secAtts, 0) == 0) + goto fail; + if (DuplicateHandle(GetCurrentProcess(), childStdout[0], + GetCurrentProcess(), &childStdoutRd, 0, FALSE, + DUPLICATE_SAME_ACCESS) == 0) { + CloseHandle(childStdout[0]); + CloseHandle(childStdout[1]); + goto fail; + } + CloseHandle(childStdout[0]); + + if (CreatePipe(&childStdin[0], &childStdin[1], &secAtts, 0) == 0) { + CloseHandle(childStdoutRd); + CloseHandle(childStdout[1]); + goto fail; + } + + if (DuplicateHandle(GetCurrentProcess(), childStdin[1], + GetCurrentProcess(), &childStdinWr, 0, FALSE, + DUPLICATE_SAME_ACCESS) == 0) { + CloseHandle(childStdoutRd); + CloseHandle(childStdout[1]); + CloseHandle(childStdin[0]); + CloseHandle(childStdin[1]); + goto fail; + } + CloseHandle(childStdin[1]); + + memset(&staInfo, 0, sizeof(staInfo)); + staInfo.cb = sizeof(staInfo); + staInfo.hStdOutput = childStdout[1]; + staInfo.hStdInput = childStdin[0]; + staInfo.wShowWindow = SW_HIDE; + staInfo.dwFlags = STARTF_USEFILLATTRIBUTE | STARTF_USECOUNTCHARS | + STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; + strncpy(cmd, path, sizeof(cmd)-1); + cmd[sizeof(cmd)-1] = '\0'; + if (CreateProcessA(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, + &staInfo, &childInfo) == 0) { + CloseHandle(childStdoutRd); + CloseHandle(childStdout[1]); + CloseHandle(childStdin[0]); + CloseHandle(childStdinWr); + goto fail; + } + WaitForInputIdle(childInfo.hProcess, INFINITE); + CloseHandle(childInfo.hProcess); + CloseHandle(childInfo.hThread); + + mode = PIPE_NOWAIT; + SetNamedPipeHandleState(childStdoutRd, &mode, NULL, NULL); + *child_stdout = _open_osfhandle((intptr_t)childStdoutRd, _O_RDONLY); + *child_stdin = _open_osfhandle((intptr_t)childStdinWr, _O_WRONLY); + + return (childInfo.dwProcessId); + +fail: + return (-1); +} + +void +__archive_check_child(int in, int out) +{ + (void)in; /* UNSED */ + (void)out; /* UNSED */ + Sleep(100); +} + +#endif /* _WIN32 && !__CYGWIN__ */ diff --git a/lib/libarchive/libarchive-formats.5 b/external/bsd/libarchive/dist/libarchive/libarchive-formats.5 similarity index 100% rename from lib/libarchive/libarchive-formats.5 rename to external/bsd/libarchive/dist/libarchive/libarchive-formats.5 diff --git a/lib/libarchive/libarchive.3 b/external/bsd/libarchive/dist/libarchive/libarchive.3 similarity index 100% rename from lib/libarchive/libarchive.3 rename to external/bsd/libarchive/dist/libarchive/libarchive.3 diff --git a/lib/libarchive/libarchive_internals.3 b/external/bsd/libarchive/dist/libarchive/libarchive_internals.3 similarity index 99% rename from lib/libarchive/libarchive_internals.3 rename to external/bsd/libarchive/dist/libarchive/libarchive_internals.3 index 9a42b76d4..50ddef3bb 100644 --- a/lib/libarchive/libarchive_internals.3 +++ b/external/bsd/libarchive/dist/libarchive/libarchive_internals.3 @@ -363,4 +363,3 @@ The .Nm libarchive library was written by .An Tim Kientzle Aq kientzle@acm.org . -.Sh BUGS diff --git a/lib/libarchive/mtree.5 b/external/bsd/libarchive/dist/libarchive/mtree.5 similarity index 100% rename from lib/libarchive/mtree.5 rename to external/bsd/libarchive/dist/libarchive/mtree.5 diff --git a/lib/libarchive/tar.5 b/external/bsd/libarchive/dist/libarchive/tar.5 similarity index 100% rename from lib/libarchive/tar.5 rename to external/bsd/libarchive/dist/libarchive/tar.5 diff --git a/external/bsd/libarchive/dist/libarchive/test/CMakeLists.txt b/external/bsd/libarchive/dist/libarchive/test/CMakeLists.txt new file mode 100644 index 000000000..626340a41 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/CMakeLists.txt @@ -0,0 +1,158 @@ +############################################ +# +# How to build libarchive_test +# +############################################ +IF(ENABLE_TEST) + FOREACH (_src ${libarchive_SOURCES}) + LIST(APPEND parent_libarchive_SOURCES "../${_src}") + ENDFOREACH(_src) + + SET(libarchive_test_SOURCES + ${parent_libarchive_SOURCES} + main.c + read_open_memory.c + test.h + test_acl_basic.c + test_acl_freebsd.c + test_acl_pax.c + test_archive_api_feature.c + test_bad_fd.c + test_compat_bzip2.c + test_compat_cpio.c + test_compat_gtar.c + test_compat_gzip.c + test_compat_lzma.c + test_compat_solaris_tar_acl.c + test_compat_tar_hardlink.c + test_compat_xz.c + test_compat_zip.c + test_empty_write.c + test_entry.c + test_entry_strmode.c + test_extattr_freebsd.c + test_fuzz.c + test_link_resolver.c + test_open_fd.c + test_open_file.c + test_open_filename.c + test_pax_filename_encoding.c + test_read_compress_program.c + test_read_data_large.c + test_read_disk.c + test_read_disk_entry_from_file.c + test_read_extract.c + test_read_file_nonexistent.c + test_read_format_ar.c + test_read_format_cpio_bin.c + test_read_format_cpio_bin_Z.c + test_read_format_cpio_bin_be.c + test_read_format_cpio_bin_bz2.c + test_read_format_cpio_bin_gz.c + test_read_format_cpio_bin_lzma.c + test_read_format_cpio_bin_xz.c + test_read_format_cpio_odc.c + test_read_format_cpio_svr4_bzip2_rpm.c + test_read_format_cpio_svr4_gzip.c + test_read_format_cpio_svr4_gzip_rpm.c + test_read_format_cpio_svr4c_Z.c + test_read_format_empty.c + test_read_format_gtar_gz.c + test_read_format_gtar_lzma.c + test_read_format_gtar_sparse.c + test_read_format_iso_gz.c + test_read_format_iso_multi_extent.c + test_read_format_isojoliet_bz2.c + test_read_format_isojoliet_long.c + test_read_format_isojoliet_rr.c + test_read_format_isorr_bz2.c + test_read_format_isorr_ce.c + test_read_format_isorr_new_bz2.c + test_read_format_isorr_rr_moved.c + test_read_format_isozisofs_bz2.c + test_read_format_mtree.c + test_read_format_pax_bz2.c + test_read_format_raw.c + test_read_format_tar.c + test_read_format_tar_empty_filename.c + test_read_format_tbz.c + test_read_format_tgz.c + test_read_format_tlz.c + test_read_format_txz.c + test_read_format_tz.c + test_read_format_xar.c + test_read_format_zip.c + test_read_large.c + test_read_pax_truncated.c + test_read_position.c + test_read_truncated.c + test_read_uu.c + test_tar_filenames.c + test_tar_large.c + test_ustar_filenames.c + test_write_compress.c + test_write_compress_bzip2.c + test_write_compress_gzip.c + test_write_compress_lzma.c + test_write_compress_program.c + test_write_compress_xz.c + test_write_disk.c + test_write_disk_failures.c + test_write_disk_hardlink.c + test_write_disk_perms.c + test_write_disk_secure.c + test_write_disk_sparse.c + test_write_disk_symlink.c + test_write_disk_times.c + test_write_format_ar.c + test_write_format_cpio.c + test_write_format_cpio_empty.c + test_write_format_cpio_odc.c + test_write_format_cpio_newc.c + test_write_format_mtree.c + test_write_format_pax.c + test_write_format_shar_empty.c + test_write_format_tar.c + test_write_format_tar_empty.c + test_write_format_tar_ustar.c + test_write_format_zip.c + test_write_format_zip_empty.c + test_write_format_zip_no_compression.c + test_write_open_memory.c + ) + + # + # Register target + # + ADD_EXECUTABLE(libarchive_test ${libarchive_test_SOURCES}) + TARGET_LINK_LIBRARIES(libarchive_test ${ADDITIONAL_LIBS}) + SET_PROPERTY(TARGET libarchive_test PROPERTY COMPILE_DEFINITIONS + LIBARCHIVE_STATIC LIST_H) + + # + # Generate list.h by grepping DEFINE_TEST() lines out of the C sources. + # + GENERATE_LIST_H(${CMAKE_CURRENT_BINARY_DIR}/list.h + ${CMAKE_CURRENT_LIST_FILE} ${libarchive_test_SOURCES}) + SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_BINARY_DIR}) + + # list.h has a line DEFINE_TEST(testname) for every + # test. We can use that to define the tests for cmake by + # defining a DEFINE_TEST macro and reading list.h in. + MACRO (DEFINE_TEST _testname) + ADD_TEST_28( + NAME libarchive_${_testname} + COMMAND libarchive_test -vv + -r ${CMAKE_CURRENT_SOURCE_DIR} + ${_testname}) + ENDMACRO (DEFINE_TEST _testname) + + INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h) + + # Experimental new test handling + ADD_CUSTOM_TARGET(run_libarchive_test + COMMAND libarchive_test -r ${CMAKE_CURRENT_SOURCE_DIR}) + ADD_DEPENDENCIES(run_all_tests run_libarchive_test) +ENDIF(ENABLE_TEST) + diff --git a/external/bsd/libarchive/dist/libarchive/test/README b/external/bsd/libarchive/dist/libarchive/test/README new file mode 100644 index 000000000..235a70b02 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/README @@ -0,0 +1,63 @@ +$FreeBSD: src/lib/libarchive/test/README,v 1.3 2008/01/01 22:28:04 kientzle Exp $ + +This is the test harness for libarchive. + +It compiles into a single program "libarchive_test" that is intended +to exercise as much of the library as possible. It is, of course, +very much a work in progress. + +Each test is a function named test_foo in a file named test_foo.c. +Note that the file name is the same as the function name. +Each file must start with this line: + + #include "test.h" + +The test function must be declared with a line of this form + + DEFINE_TEST(test_foo) + +Nothing else should appear on that line. + +When you add a test, please update the Makefile to add your +file to the list of tests. The Makefile and main.c use various +macro trickery to automatically collect a list of test functions +to be invoked. + +Each test function can rely on the following: + + * The current directory will be a freshly-created empty directory + suitable for that test. (The top-level main() creates a + directory for each separate test and chdir()s to that directory + before running the test.) + + * The test function should use assert(), assertA() and similar macros + defined in test.h. If you need to add new macros of this form, feel + free to do so. The current macro set includes assertEqualInt() and + assertEqualString() that print out additional detail about their + arguments if the assertion does fail. 'A' versions also accept + a struct archive * and display any error message from there on + failure. + + * You are encouraged to document each assertion with a failure() call + just before the assert. The failure() function is a printf-like + function whose text is displayed only if the assertion fails. It + can be used to display additional information relevant to the failure: + + failure("The data read from file %s did not match the data written to that file.", filename); + assert(strcmp(buff1, buff2) == 0); + + * Tests are encouraged to be economical with their memory and disk usage, + though this is not essential. The test is occasionally run under + a memory debugger to try to locate memory leaks in the library; + as a result, tests should be careful to release any memory they + allocate. + + * Disable tests on specific platforms as necessary. Please don't + use config.h to adjust feature requirements, as I want the tests + to also serve as a check on the configure process. The following + form is appropriate: + +#if !defined(__PLATFORM) && !defined(__Platform2__) + assert(xxxx) +#endif + diff --git a/external/bsd/libarchive/dist/libarchive/test/list.h b/external/bsd/libarchive/dist/libarchive/test/list.h new file mode 100644 index 000000000..10efb873a --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/list.h @@ -0,0 +1,106 @@ +DEFINE_TEST(test_acl_basic) +DEFINE_TEST(test_acl_freebsd) +DEFINE_TEST(test_acl_pax) +DEFINE_TEST(test_archive_api_feature) +DEFINE_TEST(test_bad_fd) +DEFINE_TEST(test_compat_bzip2) +DEFINE_TEST(test_compat_cpio) +DEFINE_TEST(test_compat_gtar) +DEFINE_TEST(test_compat_gzip) +DEFINE_TEST(test_compat_lzma) +DEFINE_TEST(test_compat_solaris_tar_acl) +DEFINE_TEST(test_compat_tar_hardlink) +DEFINE_TEST(test_compat_xz) +DEFINE_TEST(test_compat_zip) +DEFINE_TEST(test_empty_write) +DEFINE_TEST(test_entry) +DEFINE_TEST(test_entry_strmode) +DEFINE_TEST(test_extattr_freebsd) +DEFINE_TEST(test_fuzz) +DEFINE_TEST(test_link_resolver) +DEFINE_TEST(test_open_fd) +DEFINE_TEST(test_open_file) +DEFINE_TEST(test_open_filename) +DEFINE_TEST(test_pax_filename_encoding) +DEFINE_TEST(test_read_compress_program) +DEFINE_TEST(test_read_data_large) +DEFINE_TEST(test_read_disk) +DEFINE_TEST(test_read_disk_entry_from_file) +DEFINE_TEST(test_read_extract) +DEFINE_TEST(test_read_file_nonexistent) +DEFINE_TEST(test_read_format_ar) +DEFINE_TEST(test_read_format_cpio_bin) +DEFINE_TEST(test_read_format_cpio_bin_Z) +DEFINE_TEST(test_read_format_cpio_bin_be) +DEFINE_TEST(test_read_format_cpio_bin_bz2) +DEFINE_TEST(test_read_format_cpio_bin_gz) +DEFINE_TEST(test_read_format_cpio_bin_lzma) +DEFINE_TEST(test_read_format_cpio_bin_xz) +DEFINE_TEST(test_read_format_cpio_odc) +DEFINE_TEST(test_read_format_cpio_svr4_bzip2_rpm) +DEFINE_TEST(test_read_format_cpio_svr4_gzip) +DEFINE_TEST(test_read_format_cpio_svr4_gzip_rpm) +DEFINE_TEST(test_read_format_cpio_svr4c_Z) +DEFINE_TEST(test_read_format_empty) +DEFINE_TEST(test_read_format_gtar_gz) +DEFINE_TEST(test_read_format_gtar_lzma) +DEFINE_TEST(test_read_format_gtar_sparse) +DEFINE_TEST(test_read_format_iso_gz) +DEFINE_TEST(test_read_format_iso_multi_extent) +DEFINE_TEST(test_read_format_isojoliet_bz2) +DEFINE_TEST(test_read_format_isojoliet_long) +DEFINE_TEST(test_read_format_isojoliet_rr) +DEFINE_TEST(test_read_format_isorr_bz2) +DEFINE_TEST(test_read_format_isorr_ce) +DEFINE_TEST(test_read_format_isorr_new_bz2) +DEFINE_TEST(test_read_format_isorr_rr_moved) +DEFINE_TEST(test_read_format_isozisofs_bz2) +DEFINE_TEST(test_read_format_mtree) +DEFINE_TEST(test_read_format_pax_bz2) +DEFINE_TEST(test_read_format_raw) +DEFINE_TEST(test_read_format_tar) +DEFINE_TEST(test_read_format_tar_empty_filename) +DEFINE_TEST(test_read_format_tbz) +DEFINE_TEST(test_read_format_tgz) +DEFINE_TEST(test_read_format_tlz) +DEFINE_TEST(test_read_format_txz) +DEFINE_TEST(test_read_format_tz) +DEFINE_TEST(test_read_format_xar) +DEFINE_TEST(test_read_format_zip) +DEFINE_TEST(test_read_large) +DEFINE_TEST(test_read_pax_truncated) +DEFINE_TEST(test_read_position) +DEFINE_TEST(test_read_truncated) +DEFINE_TEST(test_read_uu) +DEFINE_TEST(test_tar_filenames) +DEFINE_TEST(test_tar_large) +DEFINE_TEST(test_ustar_filenames) +DEFINE_TEST(test_write_compress) +DEFINE_TEST(test_write_compress_bzip2) +DEFINE_TEST(test_write_compress_gzip) +DEFINE_TEST(test_write_compress_lzma) +DEFINE_TEST(test_write_compress_program) +DEFINE_TEST(test_write_compress_xz) +DEFINE_TEST(test_write_disk) +DEFINE_TEST(test_write_disk_failures) +DEFINE_TEST(test_write_disk_hardlink) +DEFINE_TEST(test_write_disk_perms) +DEFINE_TEST(test_write_disk_secure) +DEFINE_TEST(test_write_disk_sparse) +DEFINE_TEST(test_write_disk_symlink) +DEFINE_TEST(test_write_disk_times) +DEFINE_TEST(test_write_format_ar) +DEFINE_TEST(test_write_format_cpio) +DEFINE_TEST(test_write_format_cpio_empty) +DEFINE_TEST(test_write_format_cpio_newc) +DEFINE_TEST(test_write_format_cpio_odc) +DEFINE_TEST(test_write_format_mtree) +DEFINE_TEST(test_write_format_pax) +DEFINE_TEST(test_write_format_shar_empty) +DEFINE_TEST(test_write_format_tar) +DEFINE_TEST(test_write_format_tar_empty) +DEFINE_TEST(test_write_format_tar_ustar) +DEFINE_TEST(test_write_format_zip) +DEFINE_TEST(test_write_format_zip_empty) +DEFINE_TEST(test_write_format_zip_no_compression) +DEFINE_TEST(test_write_open_memory) diff --git a/external/bsd/libarchive/dist/libarchive/test/main.c b/external/bsd/libarchive/dist/libarchive/test/main.c new file mode 100644 index 000000000..f67bbc354 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/main.c @@ -0,0 +1,2130 @@ +/* + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +#include +#include +#include +#include + +/* + * This same file is used pretty much verbatim for all test harnesses. + * + * The next few lines are the only differences. + * TODO: Move this into a separate configuration header, have all test + * suites share one copy of this file. + */ +__FBSDID("$FreeBSD: head/lib/libarchive/test/main.c 201247 2009-12-30 05:59:21Z kientzle $"); +#define KNOWNREF "test_compat_gtar_1.tar.uu" +#define ENVBASE "LIBARCHIVE" /* Prefix for environment variables. */ +#undef PROGRAM /* Testing a library, not a program. */ +#define LIBRARY "libarchive" +#define EXTRA_DUMP(x) archive_error_string((struct archive *)(x)) +#define EXTRA_VERSION archive_version() + +/* + * + * Windows support routines + * + * Note: Configuration is a tricky issue. Using HAVE_* feature macros + * in the test harness is dangerous because they cover up + * configuration errors. The classic example of this is omitting a + * configure check. If libarchive and libarchive_test both look for + * the same feature macro, such errors are hard to detect. Platform + * macros (e.g., _WIN32 or __GNUC__) are a little better, but can + * easily lead to very messy code. It's best to limit yourself + * to only the most generic programming techniques in the test harness + * and thus avoid conditionals altogether. Where that's not possible, + * try to minimize conditionals by grouping platform-specific tests in + * one place (e.g., test_acl_freebsd) or by adding new assert() + * functions (e.g., assertMakeHardlink()) to cover up platform + * differences. Platform-specific coding in libarchive_test is often + * a symptom that some capability is missing from libarchive itself. + */ +#if defined(_WIN32) && !defined(__CYGWIN__) +#include +#include +#ifndef F_OK +#define F_OK (0) +#endif +#ifndef S_ISDIR +#define S_ISDIR(m) ((m) & _S_IFDIR) +#endif +#ifndef S_ISREG +#define S_ISREG(m) ((m) & _S_IFREG) +#endif +#if !defined(__BORLANDC__) +#define access _access +#define chdir _chdir +#endif +#ifndef fileno +#define fileno _fileno +#endif +/*#define fstat _fstat64*/ +#if !defined(__BORLANDC__) +#define getcwd _getcwd +#endif +#define lstat stat +/*#define lstat _stat64*/ +/*#define stat _stat64*/ +#define rmdir _rmdir +#if !defined(__BORLANDC__) +#define strdup _strdup +#define umask _umask +#endif +#define int64_t __int64 +#endif + +#if defined(HAVE__CrtSetReportMode) +# include +#endif + +#if defined(_WIN32) && !defined(__CYGWIN__) +void *GetFunctionKernel32(const char *name) +{ + static HINSTANCE lib; + static int set; + if (!set) { + set = 1; + lib = LoadLibrary("kernel32.dll"); + } + if (lib == NULL) { + fprintf(stderr, "Can't load kernel32.dll?!\n"); + exit(1); + } + return (void *)GetProcAddress(lib, name); +} + +static int +my_CreateSymbolicLinkA(const char *linkname, const char *target, int flags) +{ + static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD); + static int set; + if (!set) { + set = 1; + f = GetFunctionKernel32("CreateSymbolicLinkA"); + } + return f == NULL ? 0 : (*f)(linkname, target, flags); +} + +static int +my_CreateHardLinkA(const char *linkname, const char *target) +{ + static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); + static int set; + if (!set) { + set = 1; + f = GetFunctionKernel32("CreateHardLinkA"); + } + return f == NULL ? 0 : (*f)(linkname, target, NULL); +} + +int +my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) +{ + HANDLE h; + int r; + + memset(bhfi, 0, sizeof(*bhfi)); + h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) + return (0); + r = GetFileInformationByHandle(h, bhfi); + CloseHandle(h); + return (r); +} +#endif + +#if defined(HAVE__CrtSetReportMode) +static void +invalid_parameter_handler(const wchar_t * expression, + const wchar_t * function, const wchar_t * file, + unsigned int line, uintptr_t pReserved) +{ + /* nop */ +} +#endif + +/* + * + * OPTIONS FLAGS + * + */ + +/* Enable core dump on failure. */ +static int dump_on_failure = 0; +/* Default is to remove temp dirs and log data for successful tests. */ +static int keep_temp_files = 0; +/* Default is to just report pass/fail for each test. */ +static int verbosity = 0; +#define VERBOSITY_SUMMARY_ONLY -1 /* -q */ +#define VERBOSITY_PASSFAIL 0 /* Default */ +#define VERBOSITY_LIGHT_REPORT 1 /* -v */ +#define VERBOSITY_FULL 2 /* -vv */ +/* A few places generate even more output for verbosity > VERBOSITY_FULL, + * mostly for debugging the test harness itself. */ +/* Cumulative count of assertion failures. */ +static int failures = 0; +/* Cumulative count of reported skips. */ +static int skips = 0; +/* Cumulative count of assertions checked. */ +static int assertions = 0; + +/* Directory where uuencoded reference files can be found. */ +static const char *refdir; + +/* + * Report log information selectively to console and/or disk log. + */ +static int log_console = 0; +static FILE *logfile; +static void +vlogprintf(const char *fmt, va_list ap) +{ +#ifdef va_copy + va_list lfap; + va_copy(lfap, ap); +#endif + if (log_console) + vfprintf(stdout, fmt, ap); + if (logfile != NULL) +#ifdef va_copy + vfprintf(logfile, fmt, lfap); + va_end(lfap); +#else + vfprintf(logfile, fmt, ap); +#endif +} + +static void +logprintf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vlogprintf(fmt, ap); + va_end(ap); +} + +/* Set up a message to display only if next assertion fails. */ +static char msgbuff[4096]; +static const char *msg, *nextmsg; +void +failure(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vsprintf(msgbuff, fmt, ap); + va_end(ap); + nextmsg = msgbuff; +} + +/* + * Copy arguments into file-local variables. + * This was added to permit vararg assert() functions without needing + * variadic wrapper macros. Turns out that the vararg capability is almost + * never used, so almost all of the vararg assertions can be simplified + * by removing the vararg capability and reworking the wrapper macro to + * pass __FILE__, __LINE__ directly into the function instead of using + * this hook. I suspect this machinery is used so rarely that we + * would be better off just removing it entirely. That would simplify + * the code here noticably. + */ +static const char *test_filename; +static int test_line; +static void *test_extra; +void assertion_setup(const char *filename, int line) +{ + test_filename = filename; + test_line = line; +} + +/* Called at the beginning of each assert() function. */ +static void +assertion_count(const char *file, int line) +{ + (void)file; /* UNUSED */ + (void)line; /* UNUSED */ + ++assertions; + /* Proper handling of "failure()" message. */ + msg = nextmsg; + nextmsg = NULL; + /* Uncomment to print file:line after every assertion. + * Verbose, but occasionally useful in tracking down crashes. */ + /* printf("Checked %s:%d\n", file, line); */ +} + +/* + * For each test source file, we remember how many times each + * assertion was reported. Cleared before each new test, + * used by test_summarize(). + */ +static struct line { + int count; + int skip; +} failed_lines[10000]; + +/* Count this failure, setup up log destination and handle initial report. */ +static void +failure_start(const char *filename, int line, const char *fmt, ...) +{ + va_list ap; + + /* Record another failure for this line. */ + ++failures; + /* test_filename = filename; */ + failed_lines[line].count++; + + /* Determine whether to log header to console. */ + switch (verbosity) { + case VERBOSITY_LIGHT_REPORT: + log_console = (failed_lines[line].count < 2); + break; + default: + log_console = (verbosity >= VERBOSITY_FULL); + } + + /* Log file:line header for this failure */ + va_start(ap, fmt); +#if _MSC_VER + logprintf("%s(%d): ", filename, line); +#else + logprintf("%s:%d: ", filename, line); +#endif + vlogprintf(fmt, ap); + va_end(ap); + logprintf("\n"); + + if (msg != NULL && msg[0] != '\0') { + logprintf(" Description: %s\n", msg); + msg = NULL; + } + + /* Determine whether to log details to console. */ + if (verbosity == VERBOSITY_LIGHT_REPORT) + log_console = 0; +} + +/* Complete reporting of failed tests. */ +/* + * The 'extra' hook here is used by libarchive to include libarchive + * error messages with assertion failures. It could also be used + * to add strerror() output, for example. Just define the EXTRA_DUMP() + * macro appropriately. + */ +static void +failure_finish(void *extra) +{ + (void)extra; /* UNUSED (maybe) */ +#ifdef EXTRA_DUMP + if (extra != NULL) + logprintf(" detail: %s\n", EXTRA_DUMP(extra)); +#endif + + if (dump_on_failure) { + fprintf(stderr, + " *** forcing core dump so failure can be debugged ***\n"); + abort(); + exit(1); + } +} + +/* Inform user that we're skipping some checks. */ +void +test_skipping(const char *fmt, ...) +{ + char buff[1024]; + va_list ap; + + va_start(ap, fmt); + vsprintf(buff, fmt, ap); + va_end(ap); + /* failure_start() isn't quite right, but is awfully convenient. */ + failure_start(test_filename, test_line, "SKIPPING: %s", buff); + --failures; /* Undo failures++ in failure_start() */ + /* Don't failure_finish() here. */ + /* Mark as skip, so doesn't count as failed test. */ + failed_lines[test_line].skip = 1; + ++skips; +} + +/* + * + * ASSERTIONS + * + */ + +/* Generic assert() just displays the failed condition. */ +int +assertion_assert(const char *file, int line, int value, + const char *condition, void *extra) +{ + assertion_count(file, line); + if (!value) { + failure_start(file, line, "Assertion failed: %s", condition); + failure_finish(extra); + } + return (value); +} + +/* chdir() and report any errors */ +int +assertion_chdir(const char *file, int line, const char *pathname) +{ + assertion_count(file, line); + if (chdir(pathname) == 0) + return (1); + failure_start(file, line, "chdir(\"%s\")", pathname); + failure_finish(NULL); + return (0); + +} + +/* Verify two integers are equal. */ +int +assertion_equal_int(const char *file, int line, + long long v1, const char *e1, long long v2, const char *e2, void *extra) +{ + assertion_count(file, line); + if (v1 == v2) + return (1); + failure_start(file, line, "%s != %s", e1, e2); + logprintf(" %s=%lld (0x%llx, 0%llo)\n", e1, v1, v1, v1); + logprintf(" %s=%lld (0x%llx, 0%llo)\n", e2, v2, v2, v2); + failure_finish(extra); + return (0); +} + +static void strdump(const char *e, const char *p) +{ + const char *q = p; + + logprintf(" %s = ", e); + if (p == NULL) { + logprintf("NULL"); + return; + } + logprintf("\""); + while (*p != '\0') { + unsigned int c = 0xff & *p++; + switch (c) { + case '\a': printf("\a"); break; + case '\b': printf("\b"); break; + case '\n': printf("\n"); break; + case '\r': printf("\r"); break; + default: + if (c >= 32 && c < 127) + logprintf("%c", c); + else + logprintf("\\x%02X", c); + } + } + logprintf("\""); + logprintf(" (length %d)\n", q == NULL ? -1 : (int)strlen(q)); +} + +/* Verify two strings are equal, dump them if not. */ +int +assertion_equal_string(const char *file, int line, + const char *v1, const char *e1, + const char *v2, const char *e2, + void *extra) +{ + assertion_count(file, line); + if (v1 == v2 || (v1 != NULL && v2 != NULL && strcmp(v1, v2) == 0)) + return (1); + failure_start(file, line, "%s != %s", e1, e2); + strdump(e1, v1); + strdump(e2, v2); + failure_finish(extra); + return (0); +} + +static void +wcsdump(const char *e, const wchar_t *w) +{ + logprintf(" %s = ", e); + if (w == NULL) { + logprintf("(null)"); + return; + } + logprintf("\""); + while (*w != L'\0') { + unsigned int c = *w++; + if (c >= 32 && c < 127) + logprintf("%c", c); + else if (c < 256) + logprintf("\\x%02X", c); + else if (c < 0x10000) + logprintf("\\u%04X", c); + else + logprintf("\\U%08X", c); + } + logprintf("\"\n"); +} + +#ifndef HAVE_WCSCMP +static int +wcscmp(const wchar_t *s1, const wchar_t *s2) +{ + + while (*s1 == *s2++) { + if (*s1++ == L'\0') + return 0; + } + if (*s1 > *--s2) + return 1; + else + return -1; +} +#endif + +/* Verify that two wide strings are equal, dump them if not. */ +int +assertion_equal_wstring(const char *file, int line, + const wchar_t *v1, const char *e1, + const wchar_t *v2, const char *e2, + void *extra) +{ + assertion_count(file, line); + if (v1 == v2 || wcscmp(v1, v2) == 0) + return (1); + failure_start(file, line, "%s != %s", e1, e2); + wcsdump(e1, v1); + wcsdump(e2, v2); + failure_finish(extra); + return (0); +} + +/* + * Pretty standard hexdump routine. As a bonus, if ref != NULL, then + * any bytes in p that differ from ref will be highlighted with '_' + * before and after the hex value. + */ +static void +hexdump(const char *p, const char *ref, size_t l, size_t offset) +{ + size_t i, j; + char sep; + + if (p == NULL) { + logprintf("(null)\n"); + return; + } + for(i=0; i < l; i+=16) { + logprintf("%04x", (unsigned)(i + offset)); + sep = ' '; + for (j = 0; j < 16 && i + j < l; j++) { + if (ref != NULL && p[i + j] != ref[i + j]) + sep = '_'; + logprintf("%c%02x", sep, 0xff & (int)p[i+j]); + if (ref != NULL && p[i + j] == ref[i + j]) + sep = ' '; + } + for (; j < 16; j++) { + logprintf("%c ", sep); + sep = ' '; + } + logprintf("%c", sep); + for (j=0; j < 16 && i + j < l; j++) { + int c = p[i + j]; + if (c >= ' ' && c <= 126) + logprintf("%c", c); + else + logprintf("."); + } + logprintf("\n"); + } +} + +/* Verify that two blocks of memory are the same, display the first + * block of differences if they're not. */ +int +assertion_equal_mem(const char *file, int line, + const void *_v1, const char *e1, + const void *_v2, const char *e2, + size_t l, const char *ld, void *extra) +{ + const char *v1 = (const char *)_v1; + const char *v2 = (const char *)_v2; + size_t offset; + + assertion_count(file, line); + if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0)) + return (1); + + failure_start(file, line, "%s != %s", e1, e2); + logprintf(" size %s = %d\n", ld, (int)l); + /* Dump 48 bytes (3 lines) so that the first difference is + * in the second line. */ + offset = 0; + while (l > 64 && memcmp(v1, v2, 32) == 0) { + /* Two lines agree, so step forward one line. */ + v1 += 16; + v2 += 16; + l -= 16; + offset += 16; + } + logprintf(" Dump of %s\n", e1); + hexdump(v1, v2, l < 64 ? l : 64, offset); + logprintf(" Dump of %s\n", e2); + hexdump(v2, v1, l < 64 ? l : 64, offset); + logprintf("\n"); + failure_finish(extra); + return (0); +} + +/* Verify that the named file exists and is empty. */ +int +assertion_empty_file(const char *f1fmt, ...) +{ + char buff[1024]; + char f1[1024]; + struct stat st; + va_list ap; + ssize_t s; + FILE *f; + + assertion_count(test_filename, test_line); + va_start(ap, f1fmt); + vsprintf(f1, f1fmt, ap); + va_end(ap); + + if (stat(f1, &st) != 0) { + failure_start(test_filename, test_line, "Stat failed: %s", f1); + failure_finish(NULL); + return (0); + } + if (st.st_size == 0) + return (1); + + failure_start(test_filename, test_line, "File should be empty: %s", f1); + logprintf(" File size: %d\n", (int)st.st_size); + logprintf(" Contents:\n"); + f = fopen(f1, "rb"); + if (f == NULL) { + logprintf(" Unable to open %s\n", f1); + } else { + s = ((off_t)sizeof(buff) < st.st_size) ? + (ssize_t)sizeof(buff) : (ssize_t)st.st_size; + s = fread(buff, 1, s, f); + hexdump(buff, NULL, s, 0); + fclose(f); + } + failure_finish(NULL); + return (0); +} + +/* Verify that the named file exists and is not empty. */ +int +assertion_non_empty_file(const char *f1fmt, ...) +{ + char f1[1024]; + struct stat st; + va_list ap; + + assertion_count(test_filename, test_line); + va_start(ap, f1fmt); + vsprintf(f1, f1fmt, ap); + va_end(ap); + + if (stat(f1, &st) != 0) { + failure_start(test_filename, test_line, "Stat failed: %s", f1); + failure_finish(NULL); + return (0); + } + if (st.st_size == 0) { + failure_start(test_filename, test_line, "File empty: %s", f1); + failure_finish(NULL); + return (0); + } + return (1); +} + +/* Verify that two files have the same contents. */ +/* TODO: hexdump the first bytes that actually differ. */ +int +assertion_equal_file(const char *fn1, const char *f2pattern, ...) +{ + char fn2[1024]; + va_list ap; + char buff1[1024]; + char buff2[1024]; + FILE *f1, *f2; + int n1, n2; + + assertion_count(test_filename, test_line); + va_start(ap, f2pattern); + vsprintf(fn2, f2pattern, ap); + va_end(ap); + + f1 = fopen(fn1, "rb"); + f2 = fopen(fn2, "rb"); + for (;;) { + n1 = fread(buff1, 1, sizeof(buff1), f1); + n2 = fread(buff2, 1, sizeof(buff2), f2); + if (n1 != n2) + break; + if (n1 == 0 && n2 == 0) { + fclose(f1); + fclose(f2); + return (1); + } + if (memcmp(buff1, buff2, n1) != 0) + break; + } + fclose(f1); + fclose(f2); + failure_start(test_filename, test_line, "Files not identical"); + logprintf(" file1=\"%s\"\n", fn1); + logprintf(" file2=\"%s\"\n", fn2); + failure_finish(test_extra); + return (0); +} + +/* Verify that the named file does exist. */ +int +assertion_file_exists(const char *fpattern, ...) +{ + char f[1024]; + va_list ap; + + assertion_count(test_filename, test_line); + va_start(ap, fpattern); + vsprintf(f, fpattern, ap); + va_end(ap); + +#if defined(_WIN32) && !defined(__CYGWIN__) + if (!_access(f, 0)) + return (1); +#else + if (!access(f, F_OK)) + return (1); +#endif + failure_start(test_filename, test_line, "File should exist: %s", f); + failure_finish(test_extra); + return (0); +} + +/* Verify that the named file doesn't exist. */ +int +assertion_file_not_exists(const char *fpattern, ...) +{ + char f[1024]; + va_list ap; + + assertion_count(test_filename, test_line); + va_start(ap, fpattern); + vsprintf(f, fpattern, ap); + va_end(ap); + +#if defined(_WIN32) && !defined(__CYGWIN__) + if (_access(f, 0)) + return (1); +#else + if (access(f, F_OK)) + return (1); +#endif + failure_start(test_filename, test_line, "File should not exist: %s", f); + failure_finish(test_extra); + return (0); +} + +/* Compare the contents of a file to a block of memory. */ +int +assertion_file_contents(const void *buff, int s, const char *fpattern, ...) +{ + char fn[1024]; + va_list ap; + char *contents; + FILE *f; + int n; + + assertion_count(test_filename, test_line); + va_start(ap, fpattern); + vsprintf(fn, fpattern, ap); + va_end(ap); + + f = fopen(fn, "rb"); + if (f == NULL) { + failure_start(test_filename, test_line, + "File should exist: %s", fn); + failure_finish(test_extra); + return (0); + } + contents = malloc(s * 2); + n = fread(contents, 1, s * 2, f); + fclose(f); + if (n == s && memcmp(buff, contents, s) == 0) { + free(contents); + return (1); + } + failure_start(test_filename, test_line, "File contents don't match"); + logprintf(" file=\"%s\"\n", fn); + if (n > 0) + hexdump(contents, buff, n > 512 ? 512 : n, 0); + else { + logprintf(" File empty, contents should be:\n"); + hexdump(buff, NULL, s > 512 ? 512 : n, 0); + } + failure_finish(test_extra); + free(contents); + return (0); +} + +/* Check the contents of a text file, being tolerant of line endings. */ +int +assertion_text_file_contents(const char *buff, const char *fn) +{ + char *contents; + const char *btxt, *ftxt; + FILE *f; + int n, s; + + assertion_count(test_filename, test_line); + f = fopen(fn, "r"); + s = strlen(buff); + contents = malloc(s * 2 + 128); + n = fread(contents, 1, s * 2 + 128 - 1, f); + if (n >= 0) + contents[n] = '\0'; + fclose(f); + /* Compare texts. */ + btxt = buff; + ftxt = (const char *)contents; + while (*btxt != '\0' && *ftxt != '\0') { + if (*btxt == *ftxt) { + ++btxt; + ++ftxt; + continue; + } + if (btxt[0] == '\n' && ftxt[0] == '\r' && ftxt[1] == '\n') { + /* Pass over different new line characters. */ + ++btxt; + ftxt += 2; + continue; + } + break; + } + if (*btxt == '\0' && *ftxt == '\0') { + free(contents); + return (1); + } + failure_start(test_filename, test_line, "Contents don't match"); + logprintf(" file=\"%s\"\n", fn); + if (n > 0) + hexdump(contents, buff, n, 0); + else { + logprintf(" File empty, contents should be:\n"); + hexdump(buff, NULL, s, 0); + } + failure_finish(test_extra); + free(contents); + return (0); +} + +/* Test that two paths point to the same file. */ +/* As a side-effect, asserts that both files exist. */ +static int +is_hardlink(const char *file, int line, + const char *path1, const char *path2) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2; + int r; + + assertion_count(file, line); + r = my_GetFileInformationByName(path1, &bhfi1); + if (r == 0) { + failure_start(file, line, "File %s can't be inspected?", path1); + failure_finish(NULL); + return (0); + } + r = my_GetFileInformationByName(path2, &bhfi2); + if (r == 0) { + failure_start(file, line, "File %s can't be inspected?", path2); + failure_finish(NULL); + return (0); + } + return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber + && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh + && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow); +#else + struct stat st1, st2; + int r; + + assertion_count(file, line); + r = lstat(path1, &st1); + if (r != 0) { + failure_start(file, line, "File should exist: %s", path1); + failure_finish(NULL); + return (0); + } + r = lstat(path2, &st2); + if (r != 0) { + failure_start(file, line, "File should exist: %s", path2); + failure_finish(NULL); + return (0); + } + return (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev); +#endif +} + +int +assertion_is_hardlink(const char *file, int line, + const char *path1, const char *path2) +{ + if (is_hardlink(file, line, path1, path2)) + return (1); + failure_start(file, line, + "Files %s and %s are not hardlinked", path1, path2); + failure_finish(NULL); + return (0); +} + +int +assertion_is_not_hardlink(const char *file, int line, + const char *path1, const char *path2) +{ + if (!is_hardlink(file, line, path1, path2)) + return (1); + failure_start(file, line, + "Files %s and %s should not be hardlinked", path1, path2); + failure_finish(NULL); + return (0); +} + +/* Verify a/b/mtime of 'pathname'. */ +/* If 'recent', verify that it's within last 10 seconds. */ +static int +assertion_file_time(const char *file, int line, + const char *pathname, long t, long nsec, char type, int recent) +{ + long long filet, filet_nsec; + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) +#define EPOC_TIME (116444736000000000ULL) + FILETIME ftime, fbirthtime, fatime, fmtime; + ULARGE_INTEGER wintm; + HANDLE h; + ftime.dwLowDateTime = 0; + ftime.dwHighDateTime = 0; + + assertion_count(file, line); + h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + failure_start(file, line, "Can't access %s\n", pathname); + failure_finish(NULL); + return (0); + } + r = GetFileTime(h, &fbirthtime, &fatime, &fmtime); + switch (type) { + case 'a': ftime = fatime; break; + case 'b': ftime = fbirthtime; break; + case 'm': ftime = fmtime; break; + } + CloseHandle(h); + if (r == 0) { + failure_start(file, line, "Can't GetFileTime %s\n", pathname); + failure_finish(NULL); + return (0); + } + wintm.LowPart = ftime.dwLowDateTime; + wintm.HighPart = ftime.dwHighDateTime; + filet = (wintm.QuadPart - EPOC_TIME) / 10000000; + filet_nsec = ((wintm.QuadPart - EPOC_TIME) % 10000000) * 100; + nsec = (nsec / 100) * 100; /* Round the request */ +#else + struct stat st; + + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0) { + failure_start(file, line, "Can't stat %s\n", pathname); + failure_finish(NULL); + return (0); + } + switch (type) { + case 'a': filet = st.st_atime; break; + case 'm': filet = st.st_mtime; break; + case 'b': filet = 0; break; + default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); + exit(1); + } +#if defined(__FreeBSD__) + switch (type) { + case 'a': filet_nsec = st.st_atimespec.tv_nsec; break; + case 'b': filet = st.st_birthtime; + filet_nsec = st.st_birthtimespec.tv_nsec; break; + case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break; + default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); + exit(1); + } + /* FreeBSD generally only stores to microsecond res, so round. */ + filet_nsec = (filet_nsec / 1000) * 1000; + nsec = (nsec / 1000) * 1000; +#else + filet_nsec = nsec = 0; /* Generic POSIX only has whole seconds. */ + if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */ +#if defined(__HAIKU__) + if (type == 'a') return (1); /* Haiku doesn't have atime. */ +#endif +#endif +#endif + if (recent) { + /* Check that requested time is up-to-date. */ + time_t now = time(NULL); + if (filet < now - 10 || filet > now + 1) { + failure_start(file, line, + "File %s has %ctime %ld, %ld seconds ago\n", + pathname, type, filet, now - filet); + failure_finish(NULL); + return (0); + } + } else if (filet != t || filet_nsec != nsec) { + failure_start(file, line, + "File %s has %ctime %ld.%09ld, expected %ld.%09ld", + pathname, type, filet, filet_nsec, t, nsec); + failure_finish(NULL); + return (0); + } + return (1); +} + +/* Verify atime of 'pathname'. */ +int +assertion_file_atime(const char *file, int line, + const char *pathname, long t, long nsec) +{ + return assertion_file_time(file, line, pathname, t, nsec, 'a', 0); +} + +/* Verify atime of 'pathname' is up-to-date. */ +int +assertion_file_atime_recent(const char *file, int line, const char *pathname) +{ + return assertion_file_time(file, line, pathname, 0, 0, 'a', 1); +} + +/* Verify birthtime of 'pathname'. */ +int +assertion_file_birthtime(const char *file, int line, + const char *pathname, long t, long nsec) +{ + return assertion_file_time(file, line, pathname, t, nsec, 'b', 0); +} + +/* Verify birthtime of 'pathname' is up-to-date. */ +int +assertion_file_birthtime_recent(const char *file, int line, + const char *pathname) +{ + return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); +} + +/* Verify mtime of 'pathname'. */ +int +assertion_file_mtime(const char *file, int line, + const char *pathname, long t, long nsec) +{ + return assertion_file_time(file, line, pathname, t, nsec, 'm', 0); +} + +/* Verify mtime of 'pathname' is up-to-date. */ +int +assertion_file_mtime_recent(const char *file, int line, const char *pathname) +{ + return assertion_file_time(file, line, pathname, 0, 0, 'm', 1); +} + +/* Verify number of links to 'pathname'. */ +int +assertion_file_nlinks(const char *file, int line, + const char *pathname, int nlinks) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + BY_HANDLE_FILE_INFORMATION bhfi; + int r; + + assertion_count(file, line); + r = my_GetFileInformationByName(pathname, &bhfi); + if (r != 0 && bhfi.nNumberOfLinks == (DWORD)nlinks) + return (1); + failure_start(file, line, "File %s has %d links, expected %d", + pathname, bhfi.nNumberOfLinks, nlinks); + failure_finish(NULL); + return (0); +#else + struct stat st; + int r; + + assertion_count(file, line); + r = lstat(pathname, &st); + if (r == 0 && st.st_nlink == nlinks) + return (1); + failure_start(file, line, "File %s has %d links, expected %d", + pathname, st.st_nlink, nlinks); + failure_finish(NULL); + return (0); +#endif +} + +/* Verify size of 'pathname'. */ +int +assertion_file_size(const char *file, int line, const char *pathname, long size) +{ + int64_t filesize; + int r; + + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + { + BY_HANDLE_FILE_INFORMATION bhfi; + r = !my_GetFileInformationByName(pathname, &bhfi); + filesize = ((int64_t)bhfi.nFileSizeHigh << 32) + bhfi.nFileSizeLow; + } +#else + { + struct stat st; + r = lstat(pathname, &st); + filesize = st.st_size; + } +#endif + if (r == 0 && filesize == size) + return (1); + failure_start(file, line, "File %s has size %ld, expected %ld", + pathname, (long)filesize, (long)size); + failure_finish(NULL); + return (0); +} + +/* Assert that 'pathname' is a dir. If mode >= 0, verify that too. */ +int +assertion_is_dir(const char *file, int line, const char *pathname, int mode) +{ + struct stat st; + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)mode; /* UNUSED */ +#endif + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0) { + failure_start(file, line, "Dir should exist: %s", pathname); + failure_finish(NULL); + return (0); + } + if (!S_ISDIR(st.st_mode)) { + failure_start(file, line, "%s is not a dir", pathname); + failure_finish(NULL); + return (0); + } +#if !defined(_WIN32) || defined(__CYGWIN__) + /* Windows doesn't handle permissions the same way as POSIX, + * so just ignore the mode tests. */ + /* TODO: Can we do better here? */ + if (mode >= 0 && mode != (st.st_mode & 07777)) { + failure_start(file, line, "Dir %s has wrong mode", pathname); + logprintf(" Expected: 0%3o\n", mode); + logprintf(" Found: 0%3o\n", st.st_mode & 07777); + failure_finish(NULL); + return (0); + } +#endif + return (1); +} + +/* Verify that 'pathname' is a regular file. If 'mode' is >= 0, + * verify that too. */ +int +assertion_is_reg(const char *file, int line, const char *pathname, int mode) +{ + struct stat st; + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)mode; /* UNUSED */ +#endif + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0 || !S_ISREG(st.st_mode)) { + failure_start(file, line, "File should exist: %s", pathname); + failure_finish(NULL); + return (0); + } +#if !defined(_WIN32) || defined(__CYGWIN__) + /* Windows doesn't handle permissions the same way as POSIX, + * so just ignore the mode tests. */ + /* TODO: Can we do better here? */ + if (mode >= 0 && mode != (st.st_mode & 07777)) { + failure_start(file, line, "File %s has wrong mode", pathname); + logprintf(" Expected: 0%3o\n", mode); + logprintf(" Found: 0%3o\n", st.st_mode & 07777); + failure_finish(NULL); + return (0); + } +#endif + return (1); +} + +/* Check whether 'pathname' is a symbolic link. If 'contents' is + * non-NULL, verify that the symlink has those contents. */ +static int +is_symlink(const char *file, int line, + const char *pathname, const char *contents) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)pathname; /* UNUSED */ + (void)contents; /* UNUSED */ + assertion_count(file, line); + /* Windows sort-of has real symlinks, but they're only usable + * by privileged users and are crippled even then, so there's + * really not much point in bothering with this. */ + return (0); +#else + char buff[300]; + struct stat st; + ssize_t linklen; + int r; + + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0) { + failure_start(file, line, + "Symlink should exist: %s", pathname); + failure_finish(NULL); + return (0); + } + if (!S_ISLNK(st.st_mode)) + return (0); + if (contents == NULL) + return (1); + linklen = readlink(pathname, buff, sizeof(buff)); + if (linklen < 0) { + failure_start(file, line, "Can't read symlink %s", pathname); + failure_finish(NULL); + return (0); + } + buff[linklen] = '\0'; + if (strcmp(buff, contents) != 0) + return (0); + return (1); +#endif +} + +/* Assert that path is a symlink that (optionally) contains contents. */ +int +assertion_is_symlink(const char *file, int line, + const char *path, const char *contents) +{ + if (is_symlink(file, line, path, contents)) + return (1); + if (contents) + failure_start(file, line, "File %s is not a symlink to %s", + path, contents); + else + failure_start(file, line, "File %s is not a symlink", path); + failure_finish(NULL); + return (0); +} + + +/* Create a directory and report any errors. */ +int +assertion_make_dir(const char *file, int line, const char *dirname, int mode) +{ + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)mode; /* UNUSED */ + if (0 == _mkdir(dirname)) + return (1); +#else + if (0 == mkdir(dirname, mode)) + return (1); +#endif + failure_start(file, line, "Could not create directory %s", dirname); + failure_finish(NULL); + return(0); +} + +/* Create a file with the specified contents and report any failures. */ +int +assertion_make_file(const char *file, int line, + const char *path, int mode, const char *contents) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + /* TODO: Rework this to set file mode as well. */ + FILE *f; + (void)mode; /* UNUSED */ + assertion_count(file, line); + f = fopen(path, "wb"); + if (f == NULL) { + failure_start(file, line, "Could not create file %s", path); + failure_finish(NULL); + return (0); + } + if (contents != NULL) { + if (strlen(contents) + != fwrite(contents, 1, strlen(contents), f)) { + fclose(f); + failure_start(file, line, + "Could not write file %s", path); + failure_finish(NULL); + return (0); + } + } + fclose(f); + return (1); +#else + int fd; + assertion_count(file, line); + fd = open(path, O_CREAT | O_WRONLY, mode >= 0 ? mode : 0644); + if (fd < 0) { + failure_start(file, line, "Could not create %s", path); + failure_finish(NULL); + return (0); + } + if (contents != NULL) { + if ((ssize_t)strlen(contents) + != write(fd, contents, strlen(contents))) { + close(fd); + failure_start(file, line, "Could not write to %s", path); + failure_finish(NULL); + return (0); + } + } + close(fd); + return (1); +#endif +} + +/* Create a hardlink and report any failures. */ +int +assertion_make_hardlink(const char *file, int line, + const char *newpath, const char *linkto) +{ + int succeeded; + + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + succeeded = my_CreateHardLinkA(newpath, linkto); +#elif HAVE_LINK + succeeded = !link(linkto, newpath); +#else + succeeded = 0; +#endif + if (succeeded) + return (1); + failure_start(file, line, "Could not create hardlink"); + logprintf(" New link: %s\n", newpath); + logprintf(" Old name: %s\n", linkto); + failure_finish(NULL); + return(0); +} + +/* Create a symlink and report any failures. */ +int +assertion_make_symlink(const char *file, int line, + const char *newpath, const char *linkto) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + int targetIsDir = 0; /* TODO: Fix this */ + assertion_count(file, line); + if (my_CreateSymbolicLinkA(newpath, linkto, targetIsDir)) + return (1); +#elif HAVE_SYMLINK + assertion_count(file, line); + if (0 == symlink(linkto, newpath)) + return (1); +#endif + failure_start(file, line, "Could not create symlink"); + logprintf(" New link: %s\n", newpath); + logprintf(" Old name: %s\n", linkto); + failure_finish(NULL); + return(0); +} + +/* Set umask, report failures. */ +int +assertion_umask(const char *file, int line, int mask) +{ + assertion_count(file, line); + (void)file; /* UNUSED */ + (void)line; /* UNUSED */ + umask(mask); + return (1); +} + +/* + * + * UTILITIES for use by tests. + * + */ + +/* + * Check whether platform supports symlinks. This is intended + * for tests to use in deciding whether to bother testing symlink + * support; if the platform doesn't support symlinks, there's no point + * in checking whether the program being tested can create them. + * + * Note that the first time this test is called, we actually go out to + * disk to create and verify a symlink. This is necessary because + * symlink support is actually a property of a particular filesystem + * and can thus vary between directories on a single system. After + * the first call, this returns the cached result from memory, so it's + * safe to call it as often as you wish. + */ +int +canSymlink(void) +{ + /* Remember the test result */ + static int value = 0, tested = 0; + if (tested) + return (value); + + ++tested; + assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a"); + /* Note: Cygwin has its own symlink() emulation that does not + * use the Win32 CreateSymbolicLink() function. */ +#if defined(_WIN32) && !defined(__CYGWIN__) + value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0) + && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0"); +#elif HAVE_SYMLINK + value = (0 == symlink("canSymlink.0", "canSymlink.1")) + && is_symlink(__FILE__, __LINE__, "canSymlink.1","canSymlink.0"); +#endif + return (value); +} + +/* + * Can this platform run the gzip program? + */ +/* Platform-dependent options for hiding the output of a subcommand. */ +#if defined(_WIN32) && !defined(__CYGWIN__) +static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ +#else +static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ +#endif +int +canGzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("gzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the gunzip program? + */ +int +canGunzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("gunzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Sleep as needed; useful for verifying disk timestamp changes by + * ensuring that the wall-clock time has actually changed before we + * go back to re-read something from disk. + */ +void +sleepUntilAfter(time_t t) +{ + while (t >= time(NULL)) +#if defined(_WIN32) && !defined(__CYGWIN__) + Sleep(500); +#else + sleep(1); +#endif +} + +/* + * Call standard system() call, but build up the command line using + * sprintf() conventions. + */ +int +systemf(const char *fmt, ...) +{ + char buff[8192]; + va_list ap; + int r; + + va_start(ap, fmt); + vsprintf(buff, fmt, ap); + if (verbosity > VERBOSITY_FULL) + logprintf("Cmd: %s\n", buff); + r = system(buff); + va_end(ap); + return (r); +} + +/* + * Slurp a file into memory for ease of comparison and testing. + * Returns size of file in 'sizep' if non-NULL, null-terminates + * data in memory for ease of use. + */ +char * +slurpfile(size_t * sizep, const char *fmt, ...) +{ + char filename[8192]; + struct stat st; + va_list ap; + char *p; + ssize_t bytes_read; + FILE *f; + int r; + + va_start(ap, fmt); + vsprintf(filename, fmt, ap); + va_end(ap); + + f = fopen(filename, "rb"); + if (f == NULL) { + /* Note: No error; non-existent file is okay here. */ + return (NULL); + } + r = fstat(fileno(f), &st); + if (r != 0) { + logprintf("Can't stat file %s\n", filename); + fclose(f); + return (NULL); + } + p = malloc((size_t)st.st_size + 1); + if (p == NULL) { + logprintf("Can't allocate %ld bytes of memory to read file %s\n", + (long int)st.st_size, filename); + fclose(f); + return (NULL); + } + bytes_read = fread(p, 1, (size_t)st.st_size, f); + if (bytes_read < st.st_size) { + logprintf("Can't read file %s\n", filename); + fclose(f); + free(p); + return (NULL); + } + p[st.st_size] = '\0'; + if (sizep != NULL) + *sizep = (size_t)st.st_size; + fclose(f); + return (p); +} + +/* Read a uuencoded file from the reference directory, decode, and + * write the result into the current directory. */ +#define UUDECODE(c) (((c) - 0x20) & 0x3f) +void +extract_reference_file(const char *name) +{ + char buff[1024]; + FILE *in, *out; + + sprintf(buff, "%s/%s.uu", refdir, name); + in = fopen(buff, "r"); + failure("Couldn't open reference file %s", buff); + assert(in != NULL); + if (in == NULL) + return; + /* Read up to and including the 'begin' line. */ + for (;;) { + if (fgets(buff, sizeof(buff), in) == NULL) { + /* TODO: This is a failure. */ + return; + } + if (memcmp(buff, "begin ", 6) == 0) + break; + } + /* Now, decode the rest and write it. */ + /* Not a lot of error checking here; the input better be right. */ + out = fopen(name, "wb"); + while (fgets(buff, sizeof(buff), in) != NULL) { + char *p = buff; + int bytes; + + if (memcmp(buff, "end", 3) == 0) + break; + + bytes = UUDECODE(*p++); + while (bytes > 0) { + int n = 0; + /* Write out 1-3 bytes from that. */ + if (bytes > 0) { + n = UUDECODE(*p++) << 18; + n |= UUDECODE(*p++) << 12; + fputc(n >> 16, out); + --bytes; + } + if (bytes > 0) { + n |= UUDECODE(*p++) << 6; + fputc((n >> 8) & 0xFF, out); + --bytes; + } + if (bytes > 0) { + n |= UUDECODE(*p++); + fputc(n & 0xFF, out); + --bytes; + } + } + } + fclose(out); + fclose(in); +} + +/* + * + * TEST management + * + */ + +/* + * "list.h" is simply created by "grep DEFINE_TEST test_*.c"; it has + * a line like + * DEFINE_TEST(test_function) + * for each test. + */ + +/* Use "list.h" to declare all of the test functions. */ +#undef DEFINE_TEST +#define DEFINE_TEST(name) void name(void); +#include "list.h" + +/* Use "list.h" to create a list of all tests (functions and names). */ +#undef DEFINE_TEST +#define DEFINE_TEST(n) { n, #n, 0 }, +struct { void (*func)(void); const char *name; int failures; } tests[] = { + #include "list.h" +}; + +/* + * Summarize repeated failures in the just-completed test. + */ +static void +test_summarize(const char *filename, int failed) +{ + unsigned int i; + + switch (verbosity) { + case VERBOSITY_SUMMARY_ONLY: + printf(failed ? "E" : "."); + fflush(stdout); + break; + case VERBOSITY_PASSFAIL: + printf(failed ? "FAIL\n" : "ok\n"); + break; + } + + log_console = (verbosity == VERBOSITY_LIGHT_REPORT); + + for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { + if (failed_lines[i].count > 1 && !failed_lines[i].skip) + logprintf("%s:%d: Summary: Failed %d times\n", + filename, i, failed_lines[i].count); + } + /* Clear the failure history for the next file. */ + memset(failed_lines, 0, sizeof(failed_lines)); +} + +/* + * Actually run a single test, with appropriate setup and cleanup. + */ +static int +test_run(int i, const char *tmpdir) +{ + char logfilename[64]; + int failures_before = failures; + int oldumask; + + switch (verbosity) { + case VERBOSITY_SUMMARY_ONLY: /* No per-test reports at all */ + break; + case VERBOSITY_PASSFAIL: /* rest of line will include ok/FAIL marker */ + printf("%3d: %-50s", i, tests[i].name); + fflush(stdout); + break; + default: /* Title of test, details will follow */ + printf("%3d: %s\n", i, tests[i].name); + } + + /* Chdir to the top-level work directory. */ + if (!assertChdir(tmpdir)) { + fprintf(stderr, + "ERROR: Can't chdir to top work dir %s\n", tmpdir); + exit(1); + } + /* Create a log file for this test. */ + sprintf(logfilename, "%s.log", tests[i].name); + logfile = fopen(logfilename, "w"); + fprintf(logfile, "%s\n\n", tests[i].name); + /* Chdir() to a work dir for this specific test. */ + if (!assertMakeDir(tests[i].name, 0755) + || !assertChdir(tests[i].name)) { + fprintf(stderr, + "ERROR: Can't chdir to work dir %s/%s\n", + tmpdir, tests[i].name); + exit(1); + } + /* Explicitly reset the locale before each test. */ + setlocale(LC_ALL, "C"); + /* Record the umask before we run the test. */ + umask(oldumask = umask(0)); + /* + * Run the actual test. + */ + (*tests[i].func)(); + /* + * Clean up and report afterwards. + */ + /* Restore umask */ + umask(oldumask); + /* Reset locale. */ + setlocale(LC_ALL, "C"); + /* Reset directory. */ + if (!assertChdir(tmpdir)) { + fprintf(stderr, "ERROR: Couldn't chdir to temp dir %s\n", + tmpdir); + exit(1); + } + /* Report per-test summaries. */ + tests[i].failures = failures - failures_before; + test_summarize(test_filename, tests[i].failures); + /* Close the per-test log file. */ + fclose(logfile); + logfile = NULL; + /* If there were no failures, we can remove the work dir and logfile. */ + if (tests[i].failures == 0) { + if (!keep_temp_files && assertChdir(tmpdir)) { +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Make sure not to leave empty directories. + * Sometimes a processing of closing files used by tests + * is not done, then rmdir will be failed and it will + * leave a empty test directory. So we should wait a few + * seconds and retry rmdir. */ + int r, t; + for (t = 0; t < 10; t++) { + if (t > 0) + Sleep(1000); + r = systemf("rmdir /S /Q %s", tests[i].name); + if (r == 0) + break; + } + systemf("del %s", logfilename); +#else + systemf("rm -rf %s", tests[i].name); + systemf("rm %s", logfilename); +#endif + } + } + /* Return appropriate status. */ + return (tests[i].failures); +} + +/* + * + * + * MAIN and support routines. + * + * + */ + +static void +usage(const char *program) +{ + static const int limit = sizeof(tests) / sizeof(tests[0]); + int i; + + printf("Usage: %s [options] ...\n", program); + printf("Default is to run all tests.\n"); + printf("Otherwise, specify the numbers of the tests you wish to run.\n"); + printf("Options:\n"); + printf(" -d Dump core after any failure, for debugging.\n"); + printf(" -k Keep all temp files.\n"); + printf(" Default: temp files for successful tests deleted.\n"); +#ifdef PROGRAM + printf(" -p Path to executable to be tested.\n"); + printf(" Default: path taken from " ENVBASE " environment variable.\n"); +#endif + printf(" -q Quiet.\n"); + printf(" -r Path to dir containing reference files.\n"); + printf(" Default: Current directory.\n"); + printf(" -v Verbose.\n"); + printf("Available tests:\n"); + for (i = 0; i < limit; i++) + printf(" %d: %s\n", i, tests[i].name); + exit(1); +} + +static char * +get_refdir(const char *d) +{ + char tried[512] = { '\0' }; + char buff[128]; + char *pwd, *p; + + /* If a dir was specified, try that */ + if (d != NULL) { + pwd = NULL; + snprintf(buff, sizeof(buff), "%s", d); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + goto failure; + } + + /* Get the current dir. */ + pwd = getcwd(NULL, 0); + while (pwd[strlen(pwd) - 1] == '\n') + pwd[strlen(pwd) - 1] = '\0'; + + /* Look for a known file. */ + snprintf(buff, sizeof(buff), "%s", pwd); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + + snprintf(buff, sizeof(buff), "%s/test", pwd); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + +#if defined(LIBRARY) + snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY); +#else + snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM); +#endif + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + + if (memcmp(pwd, "/usr/obj", 8) == 0) { + snprintf(buff, sizeof(buff), "%s", pwd + 8); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + + snprintf(buff, sizeof(buff), "%s/test", pwd + 8); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + } + +failure: + printf("Unable to locate known reference file %s\n", KNOWNREF); + printf(" Checked following directories:\n%s\n", tried); +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) + DebugBreak(); +#endif + exit(1); + +success: + free(p); + free(pwd); + return strdup(buff); +} + +int +main(int argc, char **argv) +{ + static const int limit = sizeof(tests) / sizeof(tests[0]); + int i, tests_run = 0, tests_failed = 0, option; + time_t now; + char *refdir_alloc = NULL; + const char *progname; + const char *tmp, *option_arg, *p; + char tmpdir[256]; + char tmpdir_timestamp[256]; + + (void)argc; /* UNUSED */ + +#if defined(HAVE__CrtSetReportMode) + /* To stop to run the default invalid parameter handler. */ + _set_invalid_parameter_handler(invalid_parameter_handler); + /* Disable annoying assertion message box. */ + _CrtSetReportMode(_CRT_ASSERT, 0); +#endif + + /* + * Name of this program, used to build root of our temp directory + * tree. + */ + progname = p = argv[0]; + while (*p != '\0') { + /* Support \ or / dir separators for Windows compat. */ + if (*p == '/' || *p == '\\') + progname = p + 1; + ++p; + } + +#ifdef PROGRAM + /* Get the target program from environment, if available. */ + testprogfile = getenv(ENVBASE); +#endif + + if (getenv("TMPDIR") != NULL) + tmp = getenv("TMPDIR"); + else if (getenv("TMP") != NULL) + tmp = getenv("TMP"); + else if (getenv("TEMP") != NULL) + tmp = getenv("TEMP"); + else if (getenv("TEMPDIR") != NULL) + tmp = getenv("TEMPDIR"); + else + tmp = "/tmp"; + + /* Allow -d to be controlled through the environment. */ + if (getenv(ENVBASE "_DEBUG") != NULL) + dump_on_failure = 1; + + /* Get the directory holding test files from environment. */ + refdir = getenv(ENVBASE "_TEST_FILES"); + + /* + * Parse options, without using getopt(), which isn't available + * on all platforms. + */ + ++argv; /* Skip program name */ + while (*argv != NULL) { + if (**argv != '-') + break; + p = *argv++; + ++p; /* Skip '-' */ + while (*p != '\0') { + option = *p++; + option_arg = NULL; + /* If 'opt' takes an argument, parse that. */ + if (option == 'p' || option == 'r') { + if (*p != '\0') + option_arg = p; + else if (*argv == NULL) { + fprintf(stderr, + "Option -%c requires argument.\n", + option); + usage(progname); + } else + option_arg = *argv++; + p = ""; /* End of this option word. */ + } + + /* Now, handle the option. */ + switch (option) { + case 'd': + dump_on_failure = 1; + break; + case 'k': + keep_temp_files = 1; + break; + case 'p': +#ifdef PROGRAM + testprogfile = option_arg; +#else + usage(progname); +#endif + break; + case 'q': + verbosity--; + break; + case 'r': + refdir = option_arg; + break; + case 'v': + verbosity++; + break; + default: + usage(progname); + } + } + } + + /* + * Sanity-check that our options make sense. + */ +#ifdef PROGRAM + if (testprogfile == NULL) + usage(progname); + { + char *testprg; +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Command.com sometimes rejects '/' separators. */ + testprg = strdup(testprogfile); + for (i = 0; testprg[i] != '\0'; i++) { + if (testprg[i] == '/') + testprg[i] = '\\'; + } + testprogfile = testprg; +#endif + /* Quote the name that gets put into shell command lines. */ + testprg = malloc(strlen(testprogfile) + 3); + strcpy(testprg, "\""); + strcat(testprg, testprogfile); + strcat(testprg, "\""); + testprog = testprg; + } +#endif + + /* + * Create a temp directory for the following tests. + * Include the time the tests started as part of the name, + * to make it easier to track the results of multiple tests. + */ + now = time(NULL); + for (i = 0; ; i++) { + strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), + "%Y-%m-%dT%H.%M.%S", + localtime(&now)); + sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname, + tmpdir_timestamp, i); + if (assertMakeDir(tmpdir,0755)) + break; + if (i >= 999) { + fprintf(stderr, + "ERROR: Unable to create temp directory %s\n", + tmpdir); + exit(1); + } + } + + /* + * If the user didn't specify a directory for locating + * reference files, try to find the reference files in + * the "usual places." + */ + refdir = refdir_alloc = get_refdir(refdir); + + /* + * Banner with basic information. + */ + printf("\n"); + printf("If tests fail or crash, details will be in:\n"); + printf(" %s\n", tmpdir); + printf("\n"); + if (verbosity > VERBOSITY_SUMMARY_ONLY) { + printf("Reference files will be read from: %s\n", refdir); +#ifdef PROGRAM + printf("Running tests on: %s\n", testprog); +#endif + printf("Exercising: "); + fflush(stdout); + printf("%s\n", EXTRA_VERSION); + } else { + printf("Running "); + fflush(stdout); + } + + /* + * Run some or all of the individual tests. + */ + if (*argv == NULL) { + /* Default: Run all tests. */ + for (i = 0; i < limit; i++) { + if (test_run(i, tmpdir)) + tests_failed++; + tests_run++; + } + } else { + while (*(argv) != NULL) { + if (**argv >= '0' && **argv <= '9') { + i = atoi(*argv); + if (i < 0 || i >= limit) { + printf("*** INVALID Test %s\n", *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } + } else { + for (i = 0; i < limit; ++i) { + if (strcmp(*argv, tests[i].name) == 0) + break; + } + if (i >= limit) { + printf("*** INVALID Test ``%s''\n", + *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } + } + if (test_run(i, tmpdir)) + tests_failed++; + tests_run++; + argv++; + } + } + + /* + * Report summary statistics. + */ + if (verbosity > VERBOSITY_SUMMARY_ONLY) { + printf("\n"); + printf("Totals:\n"); + printf(" Tests run: %8d\n", tests_run); + printf(" Tests failed: %8d\n", tests_failed); + printf(" Assertions checked:%8d\n", assertions); + printf(" Assertions failed: %8d\n", failures); + printf(" Skips reported: %8d\n", skips); + } + if (failures) { + printf("\n"); + printf("Failing tests:\n"); + for (i = 0; i < limit; ++i) { + if (tests[i].failures) + printf(" %d: %s (%d failures)\n", i, + tests[i].name, tests[i].failures); + } + printf("\n"); + printf("Details for failing tests: %s\n", tmpdir); + printf("\n"); + } else { + if (verbosity == VERBOSITY_SUMMARY_ONLY) + printf("\n"); + printf("%d tests passed, no failures\n", tests_run); + } + + free(refdir_alloc); + + /* If the final tmpdir is empty, we can remove it. */ + /* This should be the usual case when all tests succeed. */ + assertChdir(".."); + rmdir(tmpdir); + + return (tests_failed ? 1 : 0); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/read_open_memory.c b/external/bsd/libarchive/dist/libarchive/test/read_open_memory.c new file mode 100644 index 000000000..e4e911c2f --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/read_open_memory.c @@ -0,0 +1,167 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/read_open_memory.c 191183 2009-04-17 01:06:31Z kientzle $"); + +#include +#include +#include + +/* + * Read an archive from a block of memory. + * + * This is identical to archive_read_open_memory(), except + * that it goes out of its way to be a little bit unpleasant, + * in order to better test the libarchive internals. + */ + +struct read_memory_data { + unsigned char *buffer; + unsigned char *end; + size_t read_size; + size_t copy_buff_size; + size_t copy_buff_offset; + char *copy_buff; +}; + +static int memory_read_close(struct archive *, void *); +static int memory_read_open(struct archive *, void *); +static off_t memory_read_skip(struct archive *, void *, off_t request); +static ssize_t memory_read(struct archive *, void *, const void **buff); +static int read_open_memory_internal(struct archive *a, void *buff, + size_t size, size_t read_size, int fullapi); + + +int +read_open_memory(struct archive *a, void *buff, size_t size, size_t read_size) +{ + return read_open_memory_internal(a, buff, size, read_size, 1); +} + +/* + * As above, but don't register any optional part of the API, to verify + * that internals work correctly with just the minimal entry points. + */ +int +read_open_memory2(struct archive *a, void *buff, size_t size, size_t read_size) +{ + return read_open_memory_internal(a, buff, size, read_size, 0); +} + +static int +read_open_memory_internal(struct archive *a, void *buff, + size_t size, size_t read_size, int fullapi) +{ + struct read_memory_data *mine; + + mine = (struct read_memory_data *)malloc(sizeof(*mine)); + if (mine == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + return (ARCHIVE_FATAL); + } + memset(mine, 0, sizeof(*mine)); + mine->buffer = (unsigned char *)buff; + mine->end = mine->buffer + size; + mine->read_size = read_size; + mine->copy_buff_offset = 32; + mine->copy_buff_size = read_size + mine->copy_buff_offset * 2; + mine->copy_buff = malloc(mine->copy_buff_size); + memset(mine->copy_buff, 0xA5, mine->copy_buff_size); + if (fullapi) + return (archive_read_open2(a, mine, memory_read_open, + memory_read, memory_read_skip, memory_read_close)); + else + return (archive_read_open2(a, mine, NULL, + memory_read, NULL, memory_read_close)); +} + +/* + * There's nothing to open. + */ +static int +memory_read_open(struct archive *a, void *client_data) +{ + (void)a; /* UNUSED */ + (void)client_data; /* UNUSED */ + return (ARCHIVE_OK); +} + +/* + * In order to exercise libarchive's internal read-combining logic, + * we deliberately copy data for each read to a separate buffer. + * That way, code that runs off the end of the provided data + * will screw up. + */ +static ssize_t +memory_read(struct archive *a, void *client_data, const void **buff) +{ + struct read_memory_data *mine = (struct read_memory_data *)client_data; + size_t size; + + (void)a; /* UNUSED */ + size = mine->end - mine->buffer; + if (size > mine->read_size) + size = mine->read_size; + else + memset(mine->copy_buff, 0xA5, mine->copy_buff_size); + memcpy(mine->copy_buff + mine->copy_buff_offset, mine->buffer, size); + *buff = mine->copy_buff + mine->copy_buff_offset; + + mine->buffer += size; + return ((ssize_t)size); +} + +/* + * How mean can a skip() routine be? Let's try to find out. + */ +static off_t +memory_read_skip(struct archive *a, void *client_data, off_t skip) +{ + struct read_memory_data *mine = (struct read_memory_data *)client_data; + + (void)a; /* UNUSED */ + /* We can't skip by more than is available. */ + if ((off_t)skip > (off_t)(mine->end - mine->buffer)) + skip = mine->end - mine->buffer; + /* Always do small skips by prime amounts. */ + if (skip > 71) + skip = 71; + mine->buffer += skip; + return (skip); +} + +/* + * Close is just cleaning up our one small bit of data. + */ +static int +memory_read_close(struct archive *a, void *client_data) +{ + struct read_memory_data *mine = (struct read_memory_data *)client_data; + (void)a; /* UNUSED */ + free(mine->copy_buff); + free(mine); + return (ARCHIVE_OK); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test.h b/external/bsd/libarchive/dist/libarchive/test/test.h new file mode 100644 index 000000000..40c31e13d --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test.h @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2003-2006 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: head/lib/libarchive/test/test.h 201247 2009-12-30 05:59:21Z kientzle $ + */ + +/* Every test program should #include "test.h" as the first thing. */ + +/* + * The goal of this file (and the matching test.c) is to + * simplify the very repetitive test-*.c test programs. + */ +#if defined(HAVE_CONFIG_H) +/* Most POSIX platforms use the 'configure' script to build config.h */ +#include "config.h" +#elif defined(__FreeBSD__) +/* Building as part of FreeBSD system requires a pre-built config.h. */ +#include "config_freebsd.h" +#elif defined(_WIN32) && !defined(__CYGWIN__) +/* Win32 can't run the 'configure' script. */ +#include "config_windows.h" +#else +/* Warn if the library hasn't been (automatically or manually) configured. */ +#error Oops: No config.h and no pre-built configuration in test.h. +#endif + +#include /* Windows requires this before sys/stat.h */ +#include + +#if HAVE_DIRENT_H +#include +#endif +#ifdef HAVE_DIRECT_H +#include +#define dirent direct +#endif +#include +#include +#ifdef HAVE_IO_H +#include +#endif +#ifdef HAVE_STDINT_H +#include +#endif +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#ifdef HAVE_WINDOWS_H +#include +#endif + +/* + * System-specific tweaks. We really want to minimize these + * as much as possible, since they make it harder to understand + * the mainline code. + */ + +/* Windows (including Visual Studio and MinGW but not Cygwin) */ +#if defined(_WIN32) && !defined(__CYGWIN__) +#if !defined(__BORLANDC__) +#define strdup _strdup +#endif +#define LOCALE_UTF8 NULL +#else +#define LOCALE_UTF8 "de_DE.UTF-8" +#endif + +/* Visual Studio */ +#ifdef _MSC_VER +#define snprintf sprintf_s +#endif + +#if defined(__BORLANDC__) +#pragma warn -8068 /* Constant out of range in comparison. */ +#endif + +/* Cygwin */ +#if defined(__CYGWIN__) +/* Cygwin-1.7.x is lazy about populating nlinks, so don't + * expect it to be accurate. */ +# define NLINKS_INACCURATE_FOR_DIRS +#endif + +/* Haiku OS */ +#if defined(__HAIKU__) +/* Haiku has typedefs in stdint.h (needed for int64_t) */ +#include +#endif + +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID +#define __FBSDID(a) struct _undefined_hack +#endif + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +/* + * Redefine DEFINE_TEST for use in defining the test functions. + */ +#undef DEFINE_TEST +#define DEFINE_TEST(name) void name(void); void name(void) + +/* An implementation of the standard assert() macro */ +#define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL) +/* chdir() and error if it fails */ +#define assertChdir(path) \ + assertion_chdir(__FILE__, __LINE__, path) +/* Assert two integers are the same. Reports value of each one if not. */ +#define assertEqualInt(v1,v2) \ + assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) +/* Assert two strings are the same. Reports value of each one if not. */ +#define assertEqualString(v1,v2) \ + assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) +/* As above, but v1 and v2 are wchar_t * */ +#define assertEqualWString(v1,v2) \ + assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) +/* As above, but raw blocks of bytes. */ +#define assertEqualMem(v1, v2, l) \ + assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL) +/* Assert two files are the same; allow printf-style expansion of second name. + * See below for comments about variable arguments here... + */ +#define assertEqualFile \ + assertion_setup(__FILE__, __LINE__);assertion_equal_file +/* Assert that a file is empty; supports printf-style arguments. */ +#define assertEmptyFile \ + assertion_setup(__FILE__, __LINE__);assertion_empty_file +/* Assert that a file is not empty; supports printf-style arguments. */ +#define assertNonEmptyFile \ + assertion_setup(__FILE__, __LINE__);assertion_non_empty_file +#define assertFileAtime(pathname, sec, nsec) \ + assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec) +#define assertFileAtimeRecent(pathname) \ + assertion_file_atime_recent(__FILE__, __LINE__, pathname) +#define assertFileBirthtime(pathname, sec, nsec) \ + assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec) +#define assertFileBirthtimeRecent(pathname) \ + assertion_file_birthtime_recent(__FILE__, __LINE__, pathname) +/* Assert that a file exists; supports printf-style arguments. */ +#define assertFileExists \ + assertion_setup(__FILE__, __LINE__);assertion_file_exists +/* Assert that a file exists; supports printf-style arguments. */ +#define assertFileNotExists \ + assertion_setup(__FILE__, __LINE__);assertion_file_not_exists +/* Assert that file contents match a string; supports printf-style arguments. */ +#define assertFileContents \ + assertion_setup(__FILE__, __LINE__);assertion_file_contents +#define assertFileMtime(pathname, sec, nsec) \ + assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec) +#define assertFileMtimeRecent(pathname) \ + assertion_file_mtime_recent(__FILE__, __LINE__, pathname) +#define assertFileNLinks(pathname, nlinks) \ + assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks) +#define assertFileSize(pathname, size) \ + assertion_file_size(__FILE__, __LINE__, pathname, size) +#define assertTextFileContents \ + assertion_setup(__FILE__, __LINE__);assertion_text_file_contents +#define assertIsDir(pathname, mode) \ + assertion_is_dir(__FILE__, __LINE__, pathname, mode) +#define assertIsHardlink(path1, path2) \ + assertion_is_hardlink(__FILE__, __LINE__, path1, path2) +#define assertIsNotHardlink(path1, path2) \ + assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2) +#define assertIsReg(pathname, mode) \ + assertion_is_reg(__FILE__, __LINE__, pathname, mode) +#define assertIsSymlink(pathname, contents) \ + assertion_is_symlink(__FILE__, __LINE__, pathname, contents) +/* Create a directory, report error if it fails. */ +#define assertMakeDir(dirname, mode) \ + assertion_make_dir(__FILE__, __LINE__, dirname, mode) +#define assertMakeFile(path, mode, contents) \ + assertion_make_file(__FILE__, __LINE__, path, mode, contents) +#define assertMakeHardlink(newfile, oldfile) \ + assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile) +#define assertMakeSymlink(newfile, linkto) \ + assertion_make_symlink(__FILE__, __LINE__, newfile, linkto) +#define assertUmask(mask) \ + assertion_umask(__FILE__, __LINE__, mask) + +/* + * This would be simple with C99 variadic macros, but I don't want to + * require that. Instead, I insert a function call before each + * skipping() call to pass the file and line information down. Crude, + * but effective. + */ +#define skipping \ + assertion_setup(__FILE__, __LINE__);test_skipping + +/* Function declarations. These are defined in test_utility.c. */ +void failure(const char *fmt, ...); +int assertion_assert(const char *, int, int, const char *, void *); +int assertion_chdir(const char *, int, const char *); +int assertion_empty_file(const char *, ...); +int assertion_equal_file(const char *, const char *, ...); +int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *); +int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *); +int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *); +int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); +int assertion_file_atime(const char *, int, const char *, long, long); +int assertion_file_atime_recent(const char *, int, const char *); +int assertion_file_birthtime(const char *, int, const char *, long, long); +int assertion_file_birthtime_recent(const char *, int, const char *); +int assertion_file_contents(const void *, int, const char *, ...); +int assertion_file_exists(const char *, ...); +int assertion_file_mtime(const char *, int, const char *, long, long); +int assertion_file_mtime_recent(const char *, int, const char *); +int assertion_file_nlinks(const char *, int, const char *, int); +int assertion_file_not_exists(const char *, ...); +int assertion_file_size(const char *, int, const char *, long); +int assertion_is_dir(const char *, int, const char *, int); +int assertion_is_hardlink(const char *, int, const char *, const char *); +int assertion_is_not_hardlink(const char *, int, const char *, const char *); +int assertion_is_reg(const char *, int, const char *, int); +int assertion_is_symlink(const char *, int, const char *, const char *); +int assertion_make_dir(const char *, int, const char *, int); +int assertion_make_file(const char *, int, const char *, int, const char *); +int assertion_make_hardlink(const char *, int, const char *newpath, const char *); +int assertion_make_symlink(const char *, int, const char *newpath, const char *); +int assertion_non_empty_file(const char *, ...); +int assertion_text_file_contents(const char *buff, const char *f); +int assertion_umask(const char *, int, int); +void assertion_setup(const char *, int); + +void test_skipping(const char *fmt, ...); + +/* Like sprintf, then system() */ +int systemf(const char * fmt, ...); + +/* Delay until time() returns a value after this. */ +void sleepUntilAfter(time_t); + +/* Return true if this platform can create symlinks. */ +int canSymlink(void); + +/* Return true if this platform can run the "gzip" program. */ +int canGzip(void); + +/* Return true if this platform can run the "gunzip" program. */ +int canGunzip(void); + +/* Suck file into string allocated via malloc(). Call free() when done. */ +/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ +char *slurpfile(size_t *, const char *fmt, ...); + +/* Extracts named reference file to the current directory. */ +void extract_reference_file(const char *); + +/* + * Special interfaces for libarchive test harness. + */ + +#include "archive.h" +#include "archive_entry.h" + +/* Special customized read-from-memory interface. */ +int read_open_memory(struct archive *, void *, size_t, size_t); +/* "2" version exercises a slightly different set of libarchive APIs. */ +int read_open_memory2(struct archive *, void *, size_t, size_t); + +/* Versions of above that accept an archive argument for additional info. */ +#define assertA(e) assertion_assert(__FILE__, __LINE__, (e), #e, (a)) +#define assertEqualIntA(a,v1,v2) \ + assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a)) +#define assertEqualStringA(a,v1,v2) \ + assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a)) + +#ifdef USE_DMALLOC +#include +#endif diff --git a/external/bsd/libarchive/dist/libarchive/test/test_acl_basic.c b/external/bsd/libarchive/dist/libarchive/test/test_acl_basic.c new file mode 100644 index 000000000..f66014cdd --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_acl_basic.c @@ -0,0 +1,229 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/lib/libarchive/test/test_acl_basic.c,v 1.6 2008/10/19 00:13:57 kientzle Exp $"); + +/* + * Exercise the system-independent portion of the ACL support. + * Check that archive_entry objects can save and restore ACL data. + * + * This should work on all systems, regardless of whether local + * filesystems support ACLs or not. + */ + +struct acl_t { + int type; /* Type of ACL: "access" or "default" */ + int permset; /* Permissions for this class of users. */ + int tag; /* Owner, User, Owning group, group, other, etc. */ + int qual; /* GID or UID of user/group, depending on tag. */ + const char *name; /* Name of user/group, depending on tag. */ +}; + +static struct acl_t acls0[] = { + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, + ARCHIVE_ENTRY_ACL_USER_OBJ, 0, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, + ARCHIVE_ENTRY_ACL_OTHER, 0, "" }, +}; + +static struct acl_t acls1[] = { + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, + ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, + ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, +}; + +static struct acl_t acls2[] = { + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, + ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, + ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, + ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, +}; + +static void +set_acls(struct archive_entry *ae, struct acl_t *acls, int n) +{ + int i; + + archive_entry_acl_clear(ae); + for (i = 0; i < n; i++) { + archive_entry_acl_add_entry(ae, + acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, + acls[i].name); + } +} + +static int +acl_match(struct acl_t *acl, int type, int permset, int tag, int qual, const char *name) +{ + if (type != acl->type) + return (0); + if (permset != acl->permset) + return (0); + if (tag != acl->tag) + return (0); + if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) + return (1); + if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) + return (1); + if (tag == ARCHIVE_ENTRY_ACL_OTHER) + return (1); + if (qual != acl->qual) + return (0); + if (name == NULL) { + if (acl->name == NULL || acl->name[0] == '\0') + return (1); + } + if (acl->name == NULL) { + if (name[0] == '\0') + return (1); + } + return (0 == strcmp(name, acl->name)); +} + +static void +compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode) +{ + int *marker = malloc(sizeof(marker[0]) * n); + int i; + int r; + int type, permset, tag, qual; + int matched; + const char *name; + + for (i = 0; i < n; i++) + marker[i] = i; + + while (0 == (r = archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name))) { + for (i = 0, matched = 0; i < n && !matched; i++) { + if (acl_match(&acls[marker[i]], type, permset, + tag, qual, name)) { + /* We found a match; remove it. */ + marker[i] = marker[n - 1]; + n--; + matched = 1; + } + } + if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) { + if (!matched) printf("No match for user_obj perm\n"); + failure("USER_OBJ permset (%02o) != user mode (%02o)", + permset, 07 & (mode >> 6)); + assert((permset << 6) == (mode & 0700)); + } else if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) { + if (!matched) printf("No match for group_obj perm\n"); + failure("GROUP_OBJ permset %02o != group mode %02o", + permset, 07 & (mode >> 3)); + assert((permset << 3) == (mode & 0070)); + } else if (tag == ARCHIVE_ENTRY_ACL_OTHER) { + if (!matched) printf("No match for other perm\n"); + failure("OTHER permset (%02o) != other mode (%02o)", + permset, mode & 07); + assert((permset << 0) == (mode & 0007)); + } else { + failure("Could not find match for ACL " + "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", + type, permset, tag, qual, name); + assert(matched == 1); + } + } +#if ARCHIVE_VERSION_NUMBER < 1009000 + /* Known broken before 1.9.0. */ + skipping("archive_entry_acl_next() exits with ARCHIVE_EOF"); +#else + assertEqualInt(ARCHIVE_EOF, r); +#endif + assert((mode & 0777) == (archive_entry_mode(ae) & 0777)); + failure("Could not find match for ACL " + "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", + acls[marker[0]].type, acls[marker[0]].permset, + acls[marker[0]].tag, acls[marker[0]].qual, acls[marker[0]].name); + assert(n == 0); /* Number of ACLs not matched should == 0 */ + free(marker); +} + +DEFINE_TEST(test_acl_basic) +{ + struct archive_entry *ae; + + /* Create a simple archive_entry. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0777); + + /* Basic owner/owning group should just update mode bits. */ + set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); + failure("Basic ACLs shouldn't be stored as extended ACLs"); + assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + failure("Basic ACLs should set mode to 0142, not %04o", + archive_entry_mode(ae)&0777); + assert((archive_entry_mode(ae) & 0777) == 0142); + + + /* With any extended ACL entry, we should read back a full set. */ + set_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0])); + failure("One extended ACL should flag all ACLs to be returned."); + assert(4 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + compare_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0]), 0142); + failure("Basic ACLs should set mode to 0142, not %04o", + archive_entry_mode(ae)&0777); + assert((archive_entry_mode(ae) & 0777) == 0142); + + + /* A more extensive set of ACLs. */ + set_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0])); + assertEqualInt(6, archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + compare_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0]), 0543); + failure("Basic ACLs should set mode to 0543, not %04o", + archive_entry_mode(ae)&0777); + assert((archive_entry_mode(ae) & 0777) == 0543); + + /* + * Check that clearing ACLs gets rid of them all by repeating + * the first test. + */ + set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); + failure("Basic ACLs shouldn't be stored as extended ACLs"); + assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + failure("Basic ACLs should set mode to 0142, not %04o", + archive_entry_mode(ae)&0777); + assert((archive_entry_mode(ae) & 0777) == 0142); + archive_entry_free(ae); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_acl_freebsd.c b/external/bsd/libarchive/dist/libarchive/test/test_acl_freebsd.c new file mode 100644 index 000000000..be502067f --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_acl_freebsd.c @@ -0,0 +1,255 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_acl_freebsd.c 189427 2009-03-06 04:21:23Z kientzle $"); + +#if defined(__FreeBSD__) && __FreeBSD__ > 4 +#include + +struct myacl_t { + int type; /* Type of ACL: "access" or "default" */ + int permset; /* Permissions for this class of users. */ + int tag; /* Owner, User, Owning group, group, other, etc. */ + int qual; /* GID or UID of user/group, depending on tag. */ + const char *name; /* Name of user/group, depending on tag. */ +}; + +static struct myacl_t acls2[] = { + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, + ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, + ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, + ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_READ | ARCHIVE_ENTRY_ACL_EXECUTE, + ARCHIVE_ENTRY_ACL_MASK, -1, "" }, + { 0, 0, 0, 0, NULL } +}; + +static void +set_acls(struct archive_entry *ae, struct myacl_t *acls) +{ + int i; + + archive_entry_acl_clear(ae); + for (i = 0; acls[i].name != NULL; i++) { + archive_entry_acl_add_entry(ae, + acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, + acls[i].name); + } +} + +static int +acl_match(acl_entry_t aclent, struct myacl_t *myacl) +{ + gid_t g, *gp; + uid_t u, *up; + acl_tag_t tag_type; + acl_permset_t opaque_ps; + int permset = 0; + + acl_get_tag_type(aclent, &tag_type); + + /* translate the silly opaque permset to a bitmap */ + acl_get_permset(aclent, &opaque_ps); + if (acl_get_perm_np(opaque_ps, ACL_EXECUTE)) + permset |= ARCHIVE_ENTRY_ACL_EXECUTE; + if (acl_get_perm_np(opaque_ps, ACL_WRITE)) + permset |= ARCHIVE_ENTRY_ACL_WRITE; + if (acl_get_perm_np(opaque_ps, ACL_READ)) + permset |= ARCHIVE_ENTRY_ACL_READ; + + if (permset != myacl->permset) + return (0); + + switch (tag_type) { + case ACL_USER_OBJ: + if (myacl->tag != ARCHIVE_ENTRY_ACL_USER_OBJ) return (0); + break; + case ACL_USER: + if (myacl->tag != ARCHIVE_ENTRY_ACL_USER) + return (0); + up = acl_get_qualifier(aclent); + u = *up; + acl_free(up); + if ((uid_t)myacl->qual != u) + return (0); + break; + case ACL_GROUP_OBJ: + if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP_OBJ) return (0); + break; + case ACL_GROUP: + if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP) + return (0); + gp = acl_get_qualifier(aclent); + g = *gp; + acl_free(gp); + if ((gid_t)myacl->qual != g) + return (0); + break; + case ACL_MASK: + if (myacl->tag != ARCHIVE_ENTRY_ACL_MASK) return (0); + break; + case ACL_OTHER: + if (myacl->tag != ARCHIVE_ENTRY_ACL_OTHER) return (0); + break; + } + return (1); +} + +static void +compare_acls(acl_t acl, struct myacl_t *myacls) +{ + int *marker; + int entry_id = ACL_FIRST_ENTRY; + int matched; + int i, n; + acl_entry_t acl_entry; + + /* Count ACL entries in myacls array and allocate an indirect array. */ + for (n = 0; myacls[n].name != NULL; ++n) + continue; + marker = malloc(sizeof(marker[0]) * n); + for (i = 0; i < n; i++) + marker[i] = i; + + /* + * Iterate over acls in system acl object, try to match each + * one with an item in the myacls array. + */ + while (1 == acl_get_entry(acl, entry_id, &acl_entry)) { + /* After the first time... */ + entry_id = ACL_NEXT_ENTRY; + + /* Search for a matching entry (tag and qualifier) */ + for (i = 0, matched = 0; i < n && !matched; i++) { + if (acl_match(acl_entry, &myacls[marker[i]])) { + /* We found a match; remove it. */ + marker[i] = marker[n - 1]; + n--; + matched = 1; + } + } + + /* TODO: Print out more details in this case. */ + failure("ACL entry on file that shouldn't be there"); + assert(matched == 1); + } + + /* Dump entries in the myacls array that weren't in the system acl. */ + for (i = 0; i < n; ++i) { + failure(" ACL entry missing from file: " + "type=%d,permset=%d,tag=%d,qual=%d,name=``%s''\n", + myacls[marker[i]].type, myacls[marker[i]].permset, + myacls[marker[i]].tag, myacls[marker[i]].qual, + myacls[marker[i]].name); + assert(0); /* Record this as a failure. */ + } + free(marker); +} + +#endif + + +/* + * Verify ACL restore-to-disk. This test is FreeBSD-specific. + */ + +DEFINE_TEST(test_acl_freebsd) +{ +#if !defined(__FreeBSD__) + skipping("FreeBSD-specific ACL restore test"); +#elif __FreeBSD__ < 5 + skipping("ACL restore supported only on FreeBSD 5.0 and later"); +#else + struct stat st; + struct archive *a; + struct archive_entry *ae; + int n, fd; + acl_t acl; + + /* + * First, do a quick manual set/read of ACL data to + * verify that the local filesystem does support ACLs. + * If it doesn't, we'll simply skip the remaining tests. + */ + acl = acl_from_text("u::rwx,u:1:rw,g::rwx,g:15:rx,o::rwx,m::rwx"); + assert((void *)acl != NULL); + /* Create a test file and try to set an ACL on it. */ + fd = open("pretest", O_WRONLY | O_CREAT | O_EXCL, 0777); + failure("Could not create test file?!"); + if (!assert(fd >= 0)) { + acl_free(acl); + return; + } + + n = acl_set_fd(fd, acl); + acl_free(acl); + if (n != 0 && errno == EOPNOTSUPP) { + close(fd); + skipping("ACL tests require that ACL support be enabled on the filesystem"); + return; + } + failure("acl_set_fd(): errno = %d (%s)", + errno, strerror(errno)); + assertEqualInt(0, n); + close(fd); + + /* Create a write-to-disk object. */ + assert(NULL != (a = archive_write_disk_new())); + archive_write_disk_set_options(a, + ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL); + + /* Populate an archive entry with some metadata, including ACL info */ + ae = archive_entry_new(); + assert(ae != NULL); + archive_entry_set_pathname(ae, "test0"); + archive_entry_set_mtime(ae, 123456, 7890); + archive_entry_set_size(ae, 0); + set_acls(ae, acls2); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* Verify the data on disk. */ + assertEqualInt(0, stat("test0", &st)); + assertEqualInt(st.st_mtime, 123456); + acl = acl_get_file("test0", ACL_TYPE_ACCESS); + assert(acl != (acl_t)NULL); + compare_acls(acl, acls2); + acl_free(acl); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_acl_pax.c b/external/bsd/libarchive/dist/libarchive/test/test_acl_pax.c new file mode 100644 index 000000000..1f0468ca1 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_acl_pax.c @@ -0,0 +1,517 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_acl_pax.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* + * Exercise the system-independent portion of the ACL support. + * Check that pax archive can save and restore ACL data. + * + * This should work on all systems, regardless of whether local + * filesystems support ACLs or not. + */ + +static unsigned char buff[16384]; + +static unsigned char reference[] = { +'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ',0,'0','0', +'0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','6','2',' ','0', +'0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','6','7',0,' ', +'x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r', +0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', +'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=','0',10, +'1','6',' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1','8',' ', +'S','C','H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ',0,'0','0', +'0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','0', +'0','0','0','0','0','0','0','0','0','0',' ','0','1','0','0','0','6',0,' ', +'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r', +0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', +'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ', +0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','1','7','2', +' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','7','1', +0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', +'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', +'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,'7','2',' ','S','C','H','I','L','Y','.','a','c','l','.', +'a','c','c','e','s','s','=','u','s','e','r',':',':','-','-','x',',','g','r', +'o','u','p',':',':','r','-','-',',','o','t','h','e','r',':',':','-','w','-', +',','u','s','e','r',':','u','s','e','r','7','7',':','r','-','-',':','7','7', +10,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=','0',10,'1','6', +' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1','8',' ','S','C', +'H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ',0,'0','0','0', +'0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','0','0', +'0','0','0','0','0','0','0','0','0',' ','0','1','0','0','0','6',0,' ','0', +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0, +'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', +'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,'0','0','0','5','4','3',' ',0,'0','0','0','0','0','0',' ', +0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','2','4','3', +' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','7','5', +0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', +'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', +'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,'1','1','3',' ','S','C','H','I','L','Y','.','a','c','l', +'.','a','c','c','e','s','s','=','u','s','e','r',':',':','r','-','x',',','g', +'r','o','u','p',':',':','r','-','-',',','o','t','h','e','r',':',':','-','w', +'x',',','u','s','e','r',':','u','s','e','r','7','7',':','r','-','-',':','7', +'7',',','u','s','e','r',':','u','s','e','r','7','8',':','-','-','-',':','7', +'8',',','g','r','o','u','p',':','g','r','o','u','p','7','8',':','r','w','x', +':','7','8',10,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=','0', +10,'1','6',' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1','8', +' ','S','C','H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,'0','0','0','5','4','3',' ',0,'0','0','0','0','0','0',' ',0,'0','0', +'0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','0', +'0','0','0','0','0','0','0','0','0','0',' ','0','1','0','0','1','3',0,' ', +'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r', +0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', +'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ', +0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','6','2', +' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','6','7', +0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', +'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', +'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=', +'0',10,'1','6',' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1', +'8',' ','S','C','H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ', +0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0', +' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','0','0','0','6', +0,' ','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', +'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', +'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + + +struct acl_t { + int type; /* Type of ACL: "access" or "default" */ + int permset; /* Permissions for this class of users. */ + int tag; /* Owner, User, Owning group, group, other, etc. */ + int qual; /* GID or UID of user/group, depending on tag. */ + const char *name; /* Name of user/group, depending on tag. */ +}; + +static struct acl_t acls0[] = { + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, + ARCHIVE_ENTRY_ACL_USER_OBJ, 0, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, + ARCHIVE_ENTRY_ACL_OTHER, 0, "" }, +}; + +static struct acl_t acls1[] = { + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, + ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, + ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, +}; + +static struct acl_t acls2[] = { + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, + ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, + ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, + ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, + { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, + ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, +}; + +static void +set_acls(struct archive_entry *ae, struct acl_t *acls, int n) +{ + int i; + + archive_entry_acl_clear(ae); + for (i = 0; i < n; i++) { + archive_entry_acl_add_entry(ae, + acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, + acls[i].name); + } +} + +static int +acl_match(struct acl_t *acl, int type, int permset, int tag, int qual, const char *name) +{ + if (type != acl->type) + return (0); + if (permset != acl->permset) + return (0); + if (tag != acl->tag) + return (0); + if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) + return (1); + if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) + return (1); + if (tag == ARCHIVE_ENTRY_ACL_OTHER) + return (1); + if (qual != acl->qual) + return (0); + if (name == NULL) + return (acl->name == NULL || acl->name[0] == '\0'); + if (acl->name == NULL) + return (name == NULL || name[0] == '\0'); + return (0 == strcmp(name, acl->name)); +} + +static void +compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode) +{ + int *marker = malloc(sizeof(marker[0]) * n); + int i; + int r; + int type, permset, tag, qual; + int matched; + const char *name; + + for (i = 0; i < n; i++) + marker[i] = i; + + while (0 == (r = archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name))) { + for (i = 0, matched = 0; i < n && !matched; i++) { + if (acl_match(&acls[marker[i]], type, permset, + tag, qual, name)) { + /* We found a match; remove it. */ + marker[i] = marker[n - 1]; + n--; + matched = 1; + } + } + if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) { + if (!matched) printf("No match for user_obj perm\n"); + failure("USER_OBJ permset (%02o) != user mode (%02o)", + permset, 07 & (mode >> 6)); + assert((permset << 6) == (mode & 0700)); + } else if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) { + if (!matched) printf("No match for group_obj perm\n"); + failure("GROUP_OBJ permset %02o != group mode %02o", + permset, 07 & (mode >> 3)); + assert((permset << 3) == (mode & 0070)); + } else if (tag == ARCHIVE_ENTRY_ACL_OTHER) { + if (!matched) printf("No match for other perm\n"); + failure("OTHER permset (%02o) != other mode (%02o)", + permset, mode & 07); + assert((permset << 0) == (mode & 0007)); + } else { + failure("Could not find match for ACL " + "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", + type, permset, tag, qual, name); + assert(matched == 1); + } + } +#if ARCHIVE_VERSION_NUMBER < 1009000 + /* Known broken before 1.9.0. */ + skipping("archive_entry_acl_next() exits with ARCHIVE_EOF"); +#else + assertEqualInt(ARCHIVE_EOF, r); +#endif + assert((mode & 0777) == (archive_entry_mode(ae) & 0777)); + failure("Could not find match for ACL " + "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", + acls[marker[0]].type, acls[marker[0]].permset, + acls[marker[0]].tag, acls[marker[0]].qual, acls[marker[0]].name); + assert(n == 0); /* Number of ACLs not matched should == 0 */ + free(marker); +} + +DEFINE_TEST(test_acl_pax) +{ + struct archive *a; + struct archive_entry *ae; + size_t used; + FILE *f; + + /* Write an archive to memory. */ + assert(NULL != (a = archive_write_new())); + assertA(0 == archive_write_set_format_pax(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_set_bytes_per_block(a, 1)); + assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* Write a series of files to the archive with different ACL info. */ + + /* Create a simple archive_entry. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0777); + + /* Basic owner/owning group should just update mode bits. */ + set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); + assertA(0 == archive_write_header(a, ae)); + + /* With any extended ACL entry, we should read back a full set. */ + set_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0])); + assertA(0 == archive_write_header(a, ae)); + + + /* A more extensive set of ACLs. */ + set_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0])); + assertA(0 == archive_write_header(a, ae)); + + /* + * Check that clearing ACLs gets rid of them all by repeating + * the first test. + */ + set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + + /* Write out the data we generated to a file for manual inspection. */ + assert(NULL != (f = fopen("testout", "wb"))); + assertEqualInt(used, (size_t)fwrite(buff, 1, (unsigned int)used, f)); + fclose(f); + + /* Write out the reference data to a file for manual inspection. */ + assert(NULL != (f = fopen("reference", "wb"))); + assert(sizeof(reference) == fwrite(reference, 1, sizeof(reference), f)); + fclose(f); + + /* Assert that the generated data matches the built-in reference data.*/ + failure("Generated pax archive does not match reference; check 'testout' and 'reference' files."); + assertEqualMem(buff, reference, sizeof(reference)); + failure("Generated pax archive does not match reference; check 'testout' and 'reference' files."); + assertEqualInt((int)used, sizeof(reference)); + + /* Read back each entry and check that the ACL data is right. */ + assert(NULL != (a = archive_read_new())); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used)); + + /* First item has no ACLs */ + assertA(0 == archive_read_next_header(a, &ae)); + failure("Basic ACLs shouldn't be stored as extended ACLs"); + assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + failure("Basic ACLs should set mode to 0142, not %04o", + archive_entry_mode(ae)&0777); + assert((archive_entry_mode(ae) & 0777) == 0142); + + /* Second item has a few ACLs */ + assertA(0 == archive_read_next_header(a, &ae)); + failure("One extended ACL should flag all ACLs to be returned."); + assert(4 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + compare_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0]), 0142); + failure("Basic ACLs should set mode to 0142, not %04o", + archive_entry_mode(ae)&0777); + assert((archive_entry_mode(ae) & 0777) == 0142); + + /* Third item has pretty extensive ACLs */ + assertA(0 == archive_read_next_header(a, &ae)); + assertEqualInt(6, archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + compare_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0]), 0543); + failure("Basic ACLs should set mode to 0543, not %04o", + archive_entry_mode(ae)&0777); + assert((archive_entry_mode(ae) & 0777) == 0543); + + /* Fourth item has no ACLs */ + assertA(0 == archive_read_next_header(a, &ae)); + failure("Basic ACLs shouldn't be stored as extended ACLs"); + assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + failure("Basic ACLs should set mode to 0142, not %04o", + archive_entry_mode(ae)&0777); + assert((archive_entry_mode(ae) & 0777) == 0142); + + /* Close the archive. */ + assertA(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertA(0 == archive_read_finish(a)); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_archive_api_feature.c b/external/bsd/libarchive/dist/libarchive/test/test_archive_api_feature.c new file mode 100644 index 000000000..23a7083c0 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_archive_api_feature.c @@ -0,0 +1,76 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/lib/libarchive/test/test_archive_api_feature.c,v 1.5 2008/05/26 17:00:24 kientzle Exp $"); + +DEFINE_TEST(test_archive_api_feature) +{ + char buff[128]; + const char *p; + + /* This is the (hopefully) final versioning API. */ + assertEqualInt(ARCHIVE_VERSION_NUMBER, archive_version_number()); + sprintf(buff, "libarchive %d.%d.%d", + archive_version_number() / 1000000, + (archive_version_number() / 1000) % 1000, + archive_version_number() % 1000); + failure("Version string is: %s, computed is: %s", + archive_version_string(), buff); + assert(memcmp(buff, archive_version_string(), strlen(buff)) == 0); + if (strlen(buff) < strlen(archive_version_string())) { + p = archive_version_string() + strlen(buff); + failure("Version string is: %s", archive_version_string()); + assert(*p == 'a' || *p == 'b' || *p == 'c' || *p == 'd'); + ++p; + failure("Version string is: %s", archive_version_string()); + assert(*p == '\0'); + } + +/* This is all scheduled to disappear in libarchive 3.0 */ +#if ARCHIVE_VERSION_NUMBER < 3000000 + assertEqualInt(ARCHIVE_VERSION_STAMP, ARCHIVE_VERSION_NUMBER); + assertEqualInt(ARCHIVE_API_FEATURE, archive_api_feature()); + assertEqualInt(ARCHIVE_API_VERSION, archive_api_version()); + /* + * Even though ARCHIVE_VERSION_STAMP only appears in + * archive.h after 1.9.0 and 2.2.3, the macro is synthesized + * in test.h, so this test is always valid. + */ + assertEqualInt(ARCHIVE_VERSION_STAMP / 1000, ARCHIVE_API_VERSION * 1000 + ARCHIVE_API_FEATURE); + /* + * The function, however, isn't always available. It appeared + * sometime in the middle of 2.2.3, but the synthesized value + * never has a release version, so the following conditional + * exactly determines whether the current library has the + * function. + */ +#if ARCHIVE_VERSION_STAMP / 1000 == 1009 || ARCHIVE_VERSION_STAMP > 2002000 + assertEqualInt(ARCHIVE_VERSION_STAMP, archive_version_stamp()); +#else + skipping("archive_version_stamp()"); +#endif + assertEqualString(ARCHIVE_LIBRARY_VERSION, archive_version()); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_bad_fd.c b/external/bsd/libarchive/dist/libarchive/test/test_bad_fd.c new file mode 100644 index 000000000..3ea7daacf --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_bad_fd.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/lib/libarchive/test/test_bad_fd.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); + +/* Verify that attempting to open an invalid fd returns correct error. */ +DEFINE_TEST(test_bad_fd) +{ + struct archive *a; + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_compression_all(a)); + assertA(ARCHIVE_FATAL == archive_read_open_fd(a, -1, 1024)); + assertA(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertA(0 == archive_read_finish(a)); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2.c b/external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2.c new file mode 100644 index 000000000..343f451ae --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2.c @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_compat_bzip2.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* + * Verify our ability to read sample files compatibly with bunzip2. + * + * In particular: + * * bunzip2 will read multiple bzip2 streams, concatenating the output + * * bunzip2 will stop at the end of a stream if the following data + * doesn't start with a bzip2 signature. + */ + +/* + * All of the sample files have the same contents; they're just + * compressed in different ways. + */ +static void +compat_bzip2(const char *name) +{ + const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; + struct archive_entry *ae; + struct archive *a; + int i; + + assert((a = archive_read_new()) != NULL); + if (ARCHIVE_OK != archive_read_support_compression_bzip2(a)) { + skipping("Unsupported bzip2"); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + extract_reference_file(name); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); + + /* Read entries, match up names with list above. */ + for (i = 0; i < 6; ++i) { + failure("Could not read file %d (%s) from %s", i, n[i], name); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString(n[i], archive_entry_pathname(ae)); + } + + /* Verify the end-of-archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify that the format detection worked. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); + assertEqualString(archive_compression_name(a), "bzip2"); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + + +DEFINE_TEST(test_compat_bzip2) +{ + compat_bzip2("test_compat_bzip2_1.tbz"); + compat_bzip2("test_compat_bzip2_2.tbz"); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2_1.tbz.uu b/external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2_1.tbz.uu new file mode 100644 index 000000000..989af82b2 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2_1.tbz.uu @@ -0,0 +1,24 @@ +$FreeBSD: head/lib/libarchive/test/test_compat_bzip2_1.tbz.uu 185683 2008-12-06 07:08:08Z kientzle $ + +begin 644 test_compat_bzip2_1.tbz +M0EIH.3%!62936;12^)(``#-;D=$00`!_@``!8RT>$`0`$```""``5#5/*'J> +MD#(&30_5!H4_5-ZH`T``327U4@&L('"(9-%8<7&$I,`:7FXH+*\GV#JF<`PK29-8'OPDG36S\7HR&C(T:/U0:$U'I +MJ!ZC0`#VECO\[$10H'-Z@F*:6A1$H$V("2G0Q(U0(8=(7AK$S04#!)RXOAP% +MP:D%#Q;NO)\4UL23'2[\7````6YC1 +M$$`$?X```6,M'A`$`!````@@`'4-4S*,U!HT!HT?J@T)E-I--!H`![60EIH.3%!629364RNM^,```#?L-$00`#_@`0```AG +M+1X0`!`$```((`!U#5-,:1IH`TT,1^J#)&H]3U`T``!CX[_.[`F40.64EC"D +M()+?KX6,VP?6Y;F%5$XR[Y/D#*9),K3^+N2*<*$@9@ +MX6(`0EIH.3%!62936>ZM4*4```);D-$00`#O@``(9ST>$`0```@@`'0:IFC2 +M&F@!B:/U0:$R&H:&@`"KS^U=Y`BC`#FY2*9-8%%&13E$@%8ZF(&J!##]!#E` +MKVL'2LUW2.*C08`$)::#DQ05DF +?4UDI/)=P````0!!```0`(``A`(*#%W)%.%"0*3R7<``` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2_2.tbz.uu b/external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2_2.tbz.uu new file mode 100644 index 000000000..9ba63e877 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_bzip2_2.tbz.uu @@ -0,0 +1,11 @@ +$FreeBSD: head/lib/libarchive/test/test_compat_bzip2_2.tbz.uu 185683 2008-12-06 07:08:08Z kientzle $ + +begin 644 test_compat_bzip2_2.tbz +M0EIH.3%!629361HI1P<``4#;D-$00`#_@``)9RT>$`0``!@P`/@#&$Q,F`F` +M`,83$R8"8``1133"1/2-J-#$/U3@;XVF9V'`Y3882XA$*KO6\WTL`]QU&J"8 +M$-=*Q$\@=`=QJ,TQ;3UH,NPT$-(!"HV&!ZO5D&@P-1D&1@'L<8&209QV9'G` +MW&PRZ0Q(-BT%&DG*DE.!U*#J.P]*#%-P9G`W9+34:#S&M`;@^1R^![C]:Y)U +MDF9/(\AR/@?P@^@I_B[DBG"A(#12C@X!3;VUE(&UOV=QL!06ER26`1T2G9F:EY)54XJ +MN>9`/*(`IX<(2#/D&F@GC`(Z``#S57',@'E&`TT,$I!EQ +M#;031@$5`0`Q!<\4Z`,``!^+"`B8OB))``-T97-T+7-P;&ET+G1A$0!3@\1D&;,-=!.&`5D``#7L]HO +MZ`,``!^+"`B8OB))``-T97-T+7-P;&ET+G1A57',@'E&`TT,$I!ER#;031@$>``"Y*#OBZ`,``!^+"`B8 +MOB))``-T97-T+7-P;&ET+G1A@ALXPP`]CXF=Q&A<:-UX>EN)C5M,AL;P +MO@V[0A=_.E39F2.B'*.?5QX2?Z\?XGE&27)F]L0)V>E_'7YY07\>OZ)Y1W6Q\!-J3!?H^Z_J7TG]%_"QK0?\]4[/>HZS^_^T\! +M_;>@@OY[=N2]6E\!JOH/P])_2OC^-X'YOV]+_]97@*K^A4K_C/Y;P/S?MZ5_ +MZRM`7?]<^L?_OR8P_P,`].D%,XR2*0`<``!4:&ES(&ES('5N $dir/f1 +echo "f2" > $dir/f2 +echo "f3" > $dir/f3 +mkdir $dir/d1 +echo "f1" > $dir/d1/f1 +echo "f2" > $dir/d1/f2 +echo "f3" > $dir/d1/f3 +(cd $dir; tar cf ../$name.tar f1 f2 f3 d1/f1 d1/f2 d1/f3) +rm -r $dir +} +mktarfile +$zcmd $name.tar +mv $name.tar.$zsuffix $name.$ztar_suffix +echo "This is unrelated junk data at the end of the file" >> $name.$ztar_suffix +uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu +rm -f $name.$ztar_suffix +# +# Use option -e +# +name=test_compat_lzma_2 +dir="$name`date +%Y%m%d%H%M%S`.$USER" +mktarfile +$zcmd -e $name.tar +mv $name.tar.$zsuffix $name.$ztar_suffix +uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu +rm -f $name.$ztar_suffix +# +# Use lzma command of LZMA SDK with option -d12. +# +name=test_compat_lzma_3 +zcmd=lzmasdk # Change this path to use lzma of LZMA SDK. +dir="$name`date +%Y%m%d%H%M%S`.$USER" +mktarfile +$zcmd e -d12 $name.tar $name.$ztar_suffix +rm -f $name.tar +uuencode $name.$ztar_suffix $name.$ztar_suffix > $name.$ztar_suffix.uu +rm -f $name.$ztar_suffix + +exit 0 +*/ + +/* + * Verify our ability to read sample files compatibly with unlzma. + * + * In particular: + * * unlzma will read multiple lzma streams, concatenating the output + * * unlzma will read lzma streams which is made by lzma with option -e, + * concatenating the output + * + * Verify our ability to read sample files compatibly with lzma of + * LZMA SDK. + * * lzma will read lzma streams which is made by lzma with option -d12, + * concatenating the output + */ + +/* + * All of the sample files have the same contents; they're just + * compressed in different ways. + */ +static void +compat_lzma(const char *name) +{ + const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; + struct archive_entry *ae; + struct archive *a; + int i, r; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("lzma reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + extract_reference_file(name); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); + + /* Read entries, match up names with list above. */ + for (i = 0; i < 6; ++i) { + failure("Could not read file %d (%s) from %s", i, n[i], name); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString(n[i], archive_entry_pathname(ae)); + } + + /* Verify the end-of-archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify that the format detection worked. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_LZMA); + assertEqualString(archive_compression_name(a), "lzma"); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + + +DEFINE_TEST(test_compat_lzma) +{ + /* This sample has been added junk datas to its tail. */ + compat_lzma("test_compat_lzma_1.tlz"); + /* This sample has been made by lzma with option -e, + * the first byte of which is 0x5e. + * Not supported in libarchive 2.7.* and earlier */ + compat_lzma("test_compat_lzma_2.tlz"); + /* This sample has been made by lzma of LZMA SDK with + * option -d12, second byte and third byte of which is + * not zero. + * Not supported in libarchive 2.7.* and earlier */ + compat_lzma("test_compat_lzma_3.tlz"); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_lzma_1.tlz.uu b/external/bsd/libarchive/dist/libarchive/test/test_compat_lzma_1.tlz.uu new file mode 100644 index 000000000..57fa501f0 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_lzma_1.tlz.uu @@ -0,0 +1,10 @@ +$FreeBSD: head/lib/libarchive/test/test_compat_lzma_1.tlz.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_compat_lzma_1.tlz +M70``@`#__________P`S##P;IXPT!HUK`DO\DC[V2OB%Z^'=ZT59ANYMTD(/ +M^W;\8!%O7<+P&=#(9W<_!$Z.7/Y<&\(8+E0^,_-\Z"D^P'N0J^4-UH"WMJ<& +MV-P6=Y[-FY$IFNZ="RF24TO.B7EP[F]BGMJSP[]OZ_P9/#J'T=;7E&&A@J<[ +MA^C'Q*/Y&I)2^T930'MJTK-98U0D9R*-X2^5__6H:+A4:&ES(&ES('5N`W2"/3R1F1:P:&Q9A +MGH2JJI9$C?8.=WTE:O<1WA@X>DK-Y#SW;I2!P;NYG^2"-(D9/E(D_0XK_H,\ +95*/V"T#E9ZO][@'R,6E&^A([.##_\M#YU@`` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_lzma_3.tlz.uu b/external/bsd/libarchive/dist/libarchive/test/test_compat_lzma_3.tlz.uu new file mode 100644 index 000000000..bee82897b --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_lzma_3.tlz.uu @@ -0,0 +1,9 @@ +$FreeBSD: head/lib/libarchive/test/test_compat_lzma_3.tlz.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_compat_lzma_3.tlz +M70`0````'``````````S##P;IXPT!HUK`DO\DC[V2OB%Z^'=ZT59ANYMTD(1 +M$Y^=;\4%U_CXKQ*F$OFZKEQUG)1U8="](V<2K"U1\Z6%H(UNQ[Y3.=D'>_G- +MCO71X+M*7WH7$D1&E9Y$XHW,(`[X";GGTO+,'&1?F%<@`.$-OV;8P1?*M$A" +:MA+1XONREMK,1('455L=X1>WC#1YW"('I@`` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_solaris_tar_acl.c b/external/bsd/libarchive/dist/libarchive/test/test_compat_solaris_tar_acl.c new file mode 100644 index 000000000..ca1506a35 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_solaris_tar_acl.c @@ -0,0 +1,128 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_compat_solaris_tar_acl.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* + * Exercise support for reading Solaris-style ACL data + * from tar archives. + * + * This should work on all systems, regardless of whether local + * filesystems support ACLs or not. + */ + +DEFINE_TEST(test_compat_solaris_tar_acl) +{ + struct archive *a; + struct archive_entry *ae; + const char *reference1 = "test_compat_solaris_tar_acl.tar"; + int type, permset, tag, qual; + const char *name; + + /* Sample file generated on Solaris 10 */ + extract_reference_file(reference1); + assert(NULL != (a = archive_read_new())); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_filename(a, reference1, 512)); + + /* Archive has 1 entry with some ACLs set on it. */ + assertA(0 == archive_read_next_header(a, &ae)); + failure("Basic ACLs should set mode to 0644, not %04o", + archive_entry_mode(ae)&0777); + assertEqualInt((archive_entry_mode(ae) & 0777), 0644); + assertEqualInt(7, archive_entry_acl_reset(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); + assertEqualInt(006, permset); + assertEqualInt(ARCHIVE_ENTRY_ACL_USER_OBJ, tag); + assertEqualInt(-1, qual); + assert(name == NULL); + + assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); + assertEqualInt(004, permset); + assertEqualInt(ARCHIVE_ENTRY_ACL_GROUP_OBJ, tag); + assertEqualInt(-1, qual); + assert(name == NULL); + + assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); + assertEqualInt(004, permset); + assertEqualInt(ARCHIVE_ENTRY_ACL_OTHER, tag); + assertEqualInt(-1, qual); + assert(name == NULL); + + assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); + assertEqualInt(001, permset); + assertEqualInt(ARCHIVE_ENTRY_ACL_USER, tag); + assertEqualInt(71, qual); + assertEqualString(name, "lp"); + + assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); + assertEqualInt(004, permset); + assertEqualInt(ARCHIVE_ENTRY_ACL_USER, tag); + assertEqualInt(666, qual); + assertEqualString(name, "666"); + + assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); + assertEqualInt(007, permset); + assertEqualInt(ARCHIVE_ENTRY_ACL_USER, tag); + assertEqualInt(1000, qual); + assertEqualString(name, "trasz"); + + assertEqualInt(ARCHIVE_OK, archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(ARCHIVE_ENTRY_ACL_TYPE_ACCESS, type); + assertEqualInt(004, permset); + assertEqualInt(ARCHIVE_ENTRY_ACL_MASK, tag); + assertEqualInt(-1, qual); + assertEqualString(name, NULL); + + assertEqualInt(ARCHIVE_EOF, archive_entry_acl_next(ae, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + + /* Close the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_solaris_tar_acl.tar.uu b/external/bsd/libarchive/dist/libarchive/test/test_compat_solaris_tar_acl.tar.uu new file mode 100644 index 000000000..54aabc2dd --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_solaris_tar_acl.tar.uu @@ -0,0 +1,61 @@ +$FreeBSD: head/lib/libarchive/test/test_compat_solaris_tar_acl.tar.uu 191576 2009-04-27 18:27:54Z kientzle $ +begin 644 test_acl_solaris.tar +M9FEL92UW:71H+7!O#HW,2QU#HQ,#`P+&=R;W5P.CIR+2TL;6%S:SIR+69I;&4M=VET:"UP +M;W-I>"UA8VQS```````````````````````````````````````````````` +M```````````````````````````````````````````````````````````P +M,#`P-C0T`#`P,#$W-3``,#`P,#`P,``P,#`P,#`P,#`P,``Q,3$W-#8P-#$U +M-P`P,#$U,30T`#`````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M````````````````````````````=7-T87(`,#!T@`````````````` +M`````````````````````')O;W0````````````````````````````````` +M````,#`P,#(Q,``P,#`P,#$P```````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +H```````````````````````````````````````````````````````` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_tar_hardlink.c b/external/bsd/libarchive/dist/libarchive/test/test_compat_tar_hardlink.c new file mode 100644 index 000000000..30785d1fb --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_tar_hardlink.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/lib/libarchive/test/test_compat_tar_hardlink.c,v 1.3 2008/08/11 01:19:36 kientzle Exp $"); + +/* + * Background: There are two written standards for the tar file format. + * The first is the POSIX 1988 "ustar" format, the second is the 2001 + * "pax extended" format that builds on the "ustar" format by adding + * support for generic additional attributes. Buried in the details + * is one frustrating incompatibility: The 1988 standard says that + * tar readers MUST ignore the size field on hardlink entries; the + * 2001 standard says that tar readers MUST obey the size field on + * hardlink entries. libarchive tries to navigate this particular + * minefield by using auto-detect logic to guess whether it should + * or should not obey the size field. + * + * This test tries to probe the boundaries of such handling; the test + * archives here were adapted from real archives created by real + * tar implementations that are (as of early 2008) apparently still + * in use. + */ + +static void +test_compat_tar_hardlink_1(void) +{ + char name[] = "test_compat_tar_hardlink_1.tar"; + struct archive_entry *ae; + struct archive *a; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + extract_reference_file(name); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); + + /* Read first entry, which is a regular file. */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("xmcd-3.3.2/docs_d/READMf", + archive_entry_pathname(ae)); + assertEqualString(NULL, archive_entry_hardlink(ae)); + assertEqualInt(321, archive_entry_size(ae)); + assertEqualInt(1082575645, archive_entry_mtime(ae)); + assertEqualInt(1851, archive_entry_uid(ae)); + assertEqualInt(3, archive_entry_gid(ae)); + assertEqualInt(0100444, archive_entry_mode(ae)); + + /* Read second entry, which is a hard link at the end of archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("xmcd-3.3.2/README", + archive_entry_pathname(ae)); + assertEqualString( + "xmcd-3.3.2/docs_d/READMf", + archive_entry_hardlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1082575645, archive_entry_mtime(ae)); + assertEqualInt(1851, archive_entry_uid(ae)); + assertEqualInt(3, archive_entry_gid(ae)); + assertEqualInt(0100444, archive_entry_mode(ae)); + + /* Verify the end-of-archive. */ + /* + * This failed in libarchive 2.4.12 because the tar reader + * tried to obey the size field for the hard link and ended + * up running past the end of the file. + */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify that the format detection worked. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); + + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +#endif +} + +DEFINE_TEST(test_compat_tar_hardlink) +{ + test_compat_tar_hardlink_1(); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_tar_hardlink_1.tar.uu b/external/bsd/libarchive/dist/libarchive/test/test_compat_tar_hardlink_1.tar.uu new file mode 100644 index 000000000..95dba54c2 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_tar_hardlink_1.tar.uu @@ -0,0 +1,39 @@ +$FreeBSD: src/lib/libarchive/test/test_compat_tar_hardlink_1.tar.uu,v 1.1 2008/01/31 07:47:38 kientzle Exp $ +begin 644 test_compat_tar_hardlink_1.tar +M>&UC9"TS+C,N,B]D;V-S7V0O4D5!1$UF```````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````"`@(#0T-"``("`S-#'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX +M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX +M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX +M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX +M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX +M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX +M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX +M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'@````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````````````````````````````````````'AM8V0M,RXS+C(O +M4D5!1$U%```````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````@ +M("`T-#0@`"`@,S0W,R``("`@("`S(``@("`@("`@(#4P,2`Q,#`T,34T-30S +M-2`@,3(R,#<`(#%X;6-D+3,N,RXR+V1O8W-?9"]214%$368````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +&```````` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_xz.c b/external/bsd/libarchive/dist/libarchive/test/test_compat_xz.c new file mode 100644 index 000000000..c3b790ffb --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_xz.c @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_compat_xz.c 191183 2009-04-17 01:06:31Z kientzle $"); + +/* + * Verify our ability to read sample files compatibly with unxz. + * + * In particular: + * * unxz will read multiple xz streams, concatenating the output + */ + +/* + * All of the sample files have the same contents; they're just + * compressed in different ways. + */ +static void +compat_xz(const char *name) +{ + const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; + struct archive_entry *ae; + struct archive *a; + int i, r; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + extract_reference_file(name); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); + + /* Read entries, match up names with list above. */ + for (i = 0; i < 6; ++i) { + failure("Could not read file %d (%s) from %s", i, n[i], name); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString(n[i], archive_entry_pathname(ae)); + } + + /* Verify the end-of-archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify that the format detection worked. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); + assertEqualString(archive_compression_name(a), "xz"); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + + +DEFINE_TEST(test_compat_xz) +{ + compat_xz("test_compat_xz_1.txz"); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_compat_xz_1.txz.uu b/external/bsd/libarchive/dist/libarchive/test/test_compat_xz_1.txz.uu new file mode 100644 index 000000000..9d4b8e8ee --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_compat_xz_1.txz.uu @@ -0,0 +1,13 @@ +$FreeBSD: head/lib/libarchive/test/test_compat_xz_1.txz.uu 191183 2009-04-17 01:06:31Z kientzle $ +begin 644 test_compat_gzip_1.txz +M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`^?`(-=`#,,/!NGC#0&C6L"2_R2 +M/O9*^(7KX=WM^(=KA(RH"\09$$)!Q_+JUHQ*`]R;ITL_F3/I6:^Q0550A&)B +MHS@=K]7@K1-9FOIP#PU!I?E5&IHH&Q=N>_C&G +M-$G]+L[\,B<7%8&$NO5K31*Y>"D^*ZG,Z=H```"KU50H$1^1S``!GP&@'P`` +MLZ042+'$9_L"``````196OTW>EA:```$YM:T1@(`(0$6````="_EH^`,7P!I +M70``;IBIKOMK%/A?-TZV0266G?2,[/?\,JE6` +M__C/SA[W1?*2J9Z!O$&YKI)!H8*&L&E>0J^FIJ\7+Q<`%!+!PAHTY\490```'$```!02P,$%``(``@`"(2# +M-P````````````````D```!T;7`N8VQA"%3```%!+!P@+ +M(*8V:````'8```!02P$"%``4``@`"``(A(,W:-.?%&4```!Q````%``````` +M````````````````345402U)3D8O34%.249%4U0N34902P$"%``4``@`"``( +MA(,W"R"F-F@```!V````"0````````````````"G````=&UP+F-L87-S4$L% +J!@`````"``(`>0```$8!```7`%!R;T=U87)D+"!V97)S:6]N(#0N,"XQ +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_empty_write.c b/external/bsd/libarchive/dist/libarchive/test/test_empty_write.c new file mode 100644 index 000000000..0523ec362 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_empty_write.c @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_empty_write.c 189308 2009-03-03 17:02:51Z kientzle $"); + +DEFINE_TEST(test_empty_write) +{ + char buff[32768]; + struct archive_entry *ae; + struct archive *a; + size_t used; + int r; + + /* + * Exercise a zero-byte write to a gzip-compressed archive. + */ + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_gzip(a); + if (r == ARCHIVE_FATAL) { + skipping("Empty write to gzip-compressed archive"); + } else { + assertEqualIntA(a, ARCHIVE_OK, r); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_open_memory(a, buff, sizeof(buff), &used)); + /* Write a file to it. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 0); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + + /* THE TEST: write zero bytes to this entry. */ + /* This used to crash. */ + assertEqualIntA(a, 0, archive_write_data(a, "", 0)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); + assertA(0 == archive_write_finish(a)); + } + + /* + * Again, with bzip2 compression. + */ + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_bzip2(a); + if (r == ARCHIVE_FATAL) { + skipping("Empty write to bzip2-compressed archive"); + } else { + assertEqualIntA(a, ARCHIVE_OK, r); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_open_memory(a, buff, sizeof(buff), &used)); + /* Write a file to it. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 0); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + + /* THE TEST: write zero bytes to this entry. */ + assertEqualIntA(a, 0, archive_write_data(a, "", 0)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); + assertA(0 == archive_write_finish(a)); + } + + /* + * For good measure, one more time with no compression. + */ + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + /* Write a file to it. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 0); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + + /* THE TEST: write zero bytes to this entry. */ + assertEqualIntA(a, 0, archive_write_data(a, "", 0)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); + assertA(0 == archive_write_finish(a)); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_entry.c b/external/bsd/libarchive/dist/libarchive/test/test_entry.c new file mode 100644 index 000000000..bf36cbe3f --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_entry.c @@ -0,0 +1,903 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_entry.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#include + +#ifndef HAVE_WCSCPY +static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2) +{ + wchar_t *dest = s1; + while ((*s1 = *s2) != L'\0') + ++s1, ++s2; + return dest; +} +#endif + +/* + * Most of these tests are system-independent, though a few depend on + * features of the local system. Such tests are conditionalized on + * the platform name. On unsupported platforms, only the + * system-independent features will be tested. + * + * No, I don't want to use config.h in the test files because I want + * the tests to also serve as a check on the correctness of config.h. + * A mis-configured library build should cause tests to fail. + */ + +DEFINE_TEST(test_entry) +{ + char buff[128]; + wchar_t wbuff[128]; + struct stat st; + struct archive_entry *e, *e2; + const struct stat *pst; + unsigned long set, clear; /* For fflag testing. */ + int type, permset, tag, qual; /* For ACL testing. */ + const char *name; /* For ACL testing. */ + const char *xname; /* For xattr tests. */ + const void *xval; /* For xattr tests. */ + size_t xsize; /* For xattr tests. */ + wchar_t wc; + long l; + + assert((e = archive_entry_new()) != NULL); + + /* + * Verify that the AE_IF* defines match S_IF* defines + * on this platform. See comments in archive_entry.h. + */ +#ifdef S_IFREG + assertEqualInt(S_IFREG, AE_IFREG); +#endif +#ifdef S_IFLNK + assertEqualInt(S_IFLNK, AE_IFLNK); +#endif +#ifdef S_IFSOCK + assertEqualInt(S_IFSOCK, AE_IFSOCK); +#endif +#ifdef S_IFCHR + assertEqualInt(S_IFCHR, AE_IFCHR); +#endif +/* Work around MinGW, which defines S_IFBLK wrong. */ +/* sourceforge.net/tracker/?func=detail&atid=102435&aid=1942809&group_id=2435 */ +#if defined(S_IFBLK) && !defined(_WIN32) + assertEqualInt(S_IFBLK, AE_IFBLK); +#endif +#ifdef S_IFDIR + assertEqualInt(S_IFDIR, AE_IFDIR); +#endif +#ifdef S_IFIFO + assertEqualInt(S_IFIFO, AE_IFIFO); +#endif + + /* + * Basic set/read tests for all fields. + * We should be able to set any field and read + * back the same value. + * + * For methods that "copy" a string, we should be able + * to overwrite the original passed-in string without + * changing the value in the entry. + * + * The following tests are ordered alphabetically by the + * name of the field. + */ + + /* atime */ + archive_entry_set_atime(e, 13579, 24680); + assertEqualInt(archive_entry_atime(e), 13579); + assertEqualInt(archive_entry_atime_nsec(e), 24680); + archive_entry_unset_atime(e); + assertEqualInt(archive_entry_atime(e), 0); + assertEqualInt(archive_entry_atime_nsec(e), 0); + assert(!archive_entry_atime_is_set(e)); + + /* birthtime */ + archive_entry_set_birthtime(e, 17579, 24990); + assertEqualInt(archive_entry_birthtime(e), 17579); + assertEqualInt(archive_entry_birthtime_nsec(e), 24990); + archive_entry_unset_birthtime(e); + assertEqualInt(archive_entry_birthtime(e), 0); + assertEqualInt(archive_entry_birthtime_nsec(e), 0); + assert(!archive_entry_birthtime_is_set(e)); + + /* ctime */ + archive_entry_set_ctime(e, 13580, 24681); + assertEqualInt(archive_entry_ctime(e), 13580); + assertEqualInt(archive_entry_ctime_nsec(e), 24681); + archive_entry_unset_ctime(e); + assertEqualInt(archive_entry_ctime(e), 0); + assertEqualInt(archive_entry_ctime_nsec(e), 0); + assert(!archive_entry_ctime_is_set(e)); + +#if ARCHIVE_VERSION_NUMBER >= 1009000 + /* dev */ + archive_entry_set_dev(e, 235); + assertEqualInt(archive_entry_dev(e), 235); +#else + skipping("archive_entry_dev()"); +#endif + /* devmajor/devminor are tested specially below. */ + +#if ARCHIVE_VERSION_NUMBER >= 1009000 + /* filetype */ + archive_entry_set_filetype(e, AE_IFREG); + assertEqualInt(archive_entry_filetype(e), AE_IFREG); +#else + skipping("archive_entry_filetype()"); +#endif + + /* fflags are tested specially below */ + + /* gid */ + archive_entry_set_gid(e, 204); + assertEqualInt(archive_entry_gid(e), 204); + + /* gname */ + archive_entry_set_gname(e, "group"); + assertEqualString(archive_entry_gname(e), "group"); + wcscpy(wbuff, L"wgroup"); + archive_entry_copy_gname_w(e, wbuff); + assertEqualWString(archive_entry_gname_w(e), L"wgroup"); + memset(wbuff, 0, sizeof(wbuff)); + assertEqualWString(archive_entry_gname_w(e), L"wgroup"); + + /* hardlink */ + archive_entry_set_hardlink(e, "hardlinkname"); + assertEqualString(archive_entry_hardlink(e), "hardlinkname"); + strcpy(buff, "hardlinkname2"); + archive_entry_copy_hardlink(e, buff); + assertEqualString(archive_entry_hardlink(e), "hardlinkname2"); + memset(buff, 0, sizeof(buff)); + assertEqualString(archive_entry_hardlink(e), "hardlinkname2"); + archive_entry_copy_hardlink(e, NULL); + assertEqualString(archive_entry_hardlink(e), NULL); + assertEqualWString(archive_entry_hardlink_w(e), NULL); + wcscpy(wbuff, L"whardlink"); + archive_entry_copy_hardlink_w(e, wbuff); + assertEqualWString(archive_entry_hardlink_w(e), L"whardlink"); + memset(wbuff, 0, sizeof(wbuff)); + assertEqualWString(archive_entry_hardlink_w(e), L"whardlink"); + archive_entry_copy_hardlink_w(e, NULL); + assertEqualString(archive_entry_hardlink(e), NULL); + assertEqualWString(archive_entry_hardlink_w(e), NULL); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + /* ino */ + archive_entry_set_ino(e, 8593); + assertEqualInt(archive_entry_ino(e), 8593); +#else + skipping("archive_entry_ino()"); +#endif + + /* link */ + archive_entry_set_hardlink(e, "hardlinkname"); + archive_entry_set_symlink(e, NULL); + archive_entry_set_link(e, "link"); + assertEqualString(archive_entry_hardlink(e), "link"); + assertEqualString(archive_entry_symlink(e), NULL); + archive_entry_copy_link(e, "link2"); + assertEqualString(archive_entry_hardlink(e), "link2"); + assertEqualString(archive_entry_symlink(e), NULL); + archive_entry_copy_link_w(e, L"link3"); + assertEqualString(archive_entry_hardlink(e), "link3"); + assertEqualString(archive_entry_symlink(e), NULL); + archive_entry_set_hardlink(e, NULL); + archive_entry_set_symlink(e, "symlink"); + archive_entry_set_link(e, "link"); + assertEqualString(archive_entry_hardlink(e), NULL); + assertEqualString(archive_entry_symlink(e), "link"); + archive_entry_copy_link(e, "link2"); + assertEqualString(archive_entry_hardlink(e), NULL); + assertEqualString(archive_entry_symlink(e), "link2"); + archive_entry_copy_link_w(e, L"link3"); + assertEqualString(archive_entry_hardlink(e), NULL); + assertEqualString(archive_entry_symlink(e), "link3"); + /* Arbitrarily override symlink if both hardlink and symlink set. */ + archive_entry_set_hardlink(e, "hardlink"); + archive_entry_set_symlink(e, "symlink"); + archive_entry_set_link(e, "link"); + assertEqualString(archive_entry_hardlink(e), "hardlink"); + assertEqualString(archive_entry_symlink(e), "link"); + + /* mode */ + archive_entry_set_mode(e, 0123456); + assertEqualInt(archive_entry_mode(e), 0123456); + + /* mtime */ + archive_entry_set_mtime(e, 13581, 24682); + assertEqualInt(archive_entry_mtime(e), 13581); + assertEqualInt(archive_entry_mtime_nsec(e), 24682); + archive_entry_unset_mtime(e); + assertEqualInt(archive_entry_mtime(e), 0); + assertEqualInt(archive_entry_mtime_nsec(e), 0); + assert(!archive_entry_mtime_is_set(e)); + +#if ARCHIVE_VERSION_NUMBER >= 1009000 + /* nlink */ + archive_entry_set_nlink(e, 736); + assertEqualInt(archive_entry_nlink(e), 736); +#else + skipping("archive_entry_nlink()"); +#endif + + /* pathname */ + archive_entry_set_pathname(e, "path"); + assertEqualString(archive_entry_pathname(e), "path"); + archive_entry_set_pathname(e, "path"); + assertEqualString(archive_entry_pathname(e), "path"); + strcpy(buff, "path2"); + archive_entry_copy_pathname(e, buff); + assertEqualString(archive_entry_pathname(e), "path2"); + memset(buff, 0, sizeof(buff)); + assertEqualString(archive_entry_pathname(e), "path2"); + wcscpy(wbuff, L"wpath"); + archive_entry_copy_pathname_w(e, wbuff); + assertEqualWString(archive_entry_pathname_w(e), L"wpath"); + memset(wbuff, 0, sizeof(wbuff)); + assertEqualWString(archive_entry_pathname_w(e), L"wpath"); + +#if ARCHIVE_VERSION_NUMBER >= 1009000 + /* rdev */ + archive_entry_set_rdev(e, 532); + assertEqualInt(archive_entry_rdev(e), 532); +#else + skipping("archive_entry_rdev()"); +#endif + /* rdevmajor/rdevminor are tested specially below. */ + + /* size */ + archive_entry_set_size(e, 987654321); + assertEqualInt(archive_entry_size(e), 987654321); + archive_entry_unset_size(e); + assertEqualInt(archive_entry_size(e), 0); + assert(!archive_entry_size_is_set(e)); + + /* sourcepath */ + archive_entry_copy_sourcepath(e, "path1"); + assertEqualString(archive_entry_sourcepath(e), "path1"); + + /* symlink */ + archive_entry_set_symlink(e, "symlinkname"); + assertEqualString(archive_entry_symlink(e), "symlinkname"); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + strcpy(buff, "symlinkname2"); + archive_entry_copy_symlink(e, buff); + assertEqualString(archive_entry_symlink(e), "symlinkname2"); + memset(buff, 0, sizeof(buff)); + assertEqualString(archive_entry_symlink(e), "symlinkname2"); +#endif + archive_entry_copy_symlink_w(e, NULL); + assertEqualWString(archive_entry_symlink_w(e), NULL); + assertEqualString(archive_entry_symlink(e), NULL); + archive_entry_copy_symlink_w(e, L"wsymlink"); + assertEqualWString(archive_entry_symlink_w(e), L"wsymlink"); + archive_entry_copy_symlink(e, NULL); + assertEqualWString(archive_entry_symlink_w(e), NULL); + assertEqualString(archive_entry_symlink(e), NULL); + + /* uid */ + archive_entry_set_uid(e, 83); + assertEqualInt(archive_entry_uid(e), 83); + + /* uname */ + archive_entry_set_uname(e, "user"); + assertEqualString(archive_entry_uname(e), "user"); + wcscpy(wbuff, L"wuser"); + archive_entry_copy_gname_w(e, wbuff); + assertEqualWString(archive_entry_gname_w(e), L"wuser"); + memset(wbuff, 0, sizeof(wbuff)); + assertEqualWString(archive_entry_gname_w(e), L"wuser"); + + /* Test fflags interface. */ + archive_entry_set_fflags(e, 0x55, 0xAA); + archive_entry_fflags(e, &set, &clear); + failure("Testing set/get of fflags data."); + assertEqualInt(set, 0x55); + failure("Testing set/get of fflags data."); + assertEqualInt(clear, 0xAA); +#ifdef __FreeBSD__ + /* Converting fflags bitmap to string is currently system-dependent. */ + /* TODO: Make this system-independent. */ + assertEqualString(archive_entry_fflags_text(e), + "uappnd,nouchg,nodump,noopaque,uunlnk"); + /* Test archive_entry_copy_fflags_text_w() */ + archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,uunlnk"); + archive_entry_fflags(e, &set, &clear); + assertEqualInt(16, set); + assertEqualInt(7, clear); + /* Test archive_entry_copy_fflags_text() */ + archive_entry_copy_fflags_text(e, " ,nouappnd, nouchg, dump,uunlnk"); + archive_entry_fflags(e, &set, &clear); + assertEqualInt(16, set); + assertEqualInt(7, clear); +#endif + + /* See test_acl_basic.c for tests of ACL set/get consistency. */ + + /* Test xattrs set/get consistency. */ + archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12); + assertEqualInt(1, archive_entry_xattr_reset(e)); + assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize)); + assertEqualString(xname, "xattr1"); + assertEqualString(xval, "xattrvalue1"); + assertEqualInt((int)xsize, 12); + assertEqualInt(1, archive_entry_xattr_count(e)); + assertEqualInt(ARCHIVE_WARN, + archive_entry_xattr_next(e, &xname, &xval, &xsize)); + assertEqualString(xname, NULL); + assertEqualString(xval, NULL); + assertEqualInt((int)xsize, 0); + archive_entry_xattr_clear(e); + assertEqualInt(0, archive_entry_xattr_reset(e)); + assertEqualInt(ARCHIVE_WARN, + archive_entry_xattr_next(e, &xname, &xval, &xsize)); + assertEqualString(xname, NULL); + assertEqualString(xval, NULL); + assertEqualInt((int)xsize, 0); + archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12); + assertEqualInt(1, archive_entry_xattr_reset(e)); + archive_entry_xattr_add_entry(e, "xattr2", "xattrvalue2", 12); + assertEqualInt(2, archive_entry_xattr_reset(e)); + assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize)); + assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize)); + assertEqualInt(ARCHIVE_WARN, + archive_entry_xattr_next(e, &xname, &xval, &xsize)); + assertEqualString(xname, NULL); + assertEqualString(xval, NULL); + assertEqualInt((int)xsize, 0); + + + /* + * Test clone() implementation. + */ + + /* Set values in 'e' */ + archive_entry_clear(e); + archive_entry_set_atime(e, 13579, 24680); + archive_entry_set_birthtime(e, 13779, 24990); + archive_entry_set_ctime(e, 13580, 24681); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_dev(e, 235); +#endif + archive_entry_set_fflags(e, 0x55, 0xAA); + archive_entry_set_gid(e, 204); + archive_entry_set_gname(e, "group"); + archive_entry_set_hardlink(e, "hardlinkname"); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_ino(e, 8593); +#endif + archive_entry_set_mode(e, 0123456); + archive_entry_set_mtime(e, 13581, 24682); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_nlink(e, 736); +#endif + archive_entry_set_pathname(e, "path"); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_rdev(e, 532); +#endif + archive_entry_set_size(e, 987654321); + archive_entry_copy_sourcepath(e, "source"); + archive_entry_set_symlink(e, "symlinkname"); + archive_entry_set_uid(e, 83); + archive_entry_set_uname(e, "user"); + /* Add an ACL entry. */ + archive_entry_acl_add_entry(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + ARCHIVE_ENTRY_ACL_READ, ARCHIVE_ENTRY_ACL_USER, 77, "user77"); + /* Add an extended attribute. */ + archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue", 11); + + /* Make a clone. */ + e2 = archive_entry_clone(e); + + /* Clone should have same contents. */ + assertEqualInt(archive_entry_atime(e2), 13579); + assertEqualInt(archive_entry_atime_nsec(e2), 24680); + assertEqualInt(archive_entry_birthtime(e2), 13779); + assertEqualInt(archive_entry_birthtime_nsec(e2), 24990); + assertEqualInt(archive_entry_ctime(e2), 13580); + assertEqualInt(archive_entry_ctime_nsec(e2), 24681); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_dev(e2), 235); +#endif + archive_entry_fflags(e, &set, &clear); + assertEqualInt(clear, 0xAA); + assertEqualInt(set, 0x55); + assertEqualInt(archive_entry_gid(e2), 204); + assertEqualString(archive_entry_gname(e2), "group"); + assertEqualString(archive_entry_hardlink(e2), "hardlinkname"); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_ino(e2), 8593); +#endif + assertEqualInt(archive_entry_mode(e2), 0123456); + assertEqualInt(archive_entry_mtime(e2), 13581); + assertEqualInt(archive_entry_mtime_nsec(e2), 24682); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_nlink(e2), 736); +#endif + assertEqualString(archive_entry_pathname(e2), "path"); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_rdev(e2), 532); +#endif + assertEqualInt(archive_entry_size(e2), 987654321); + assertEqualString(archive_entry_sourcepath(e2), "source"); + assertEqualString(archive_entry_symlink(e2), "symlinkname"); + assertEqualInt(archive_entry_uid(e2), 83); + assertEqualString(archive_entry_uname(e2), "user"); +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("ACL preserved by archive_entry_clone()"); +#else + /* Verify ACL was copied. */ + assertEqualInt(4, archive_entry_acl_reset(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + /* First three are standard permission bits. */ + assertEqualInt(0, archive_entry_acl_next(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + assertEqualInt(permset, 4); + assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ); + assertEqualInt(qual, -1); + assertEqualString(name, NULL); + assertEqualInt(0, archive_entry_acl_next(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + assertEqualInt(permset, 5); + assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ); + assertEqualInt(qual, -1); + assertEqualString(name, NULL); + assertEqualInt(0, archive_entry_acl_next(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + assertEqualInt(permset, 6); + assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER); + assertEqualInt(qual, -1); + assertEqualString(name, NULL); + /* Fourth is custom one. */ + assertEqualInt(0, archive_entry_acl_next(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ); + assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER); + assertEqualInt(qual, 77); + assertEqualString(name, "user77"); +#endif +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("xattr data preserved by archive_entry_clone"); +#else + /* Verify xattr was copied. */ + assertEqualInt(1, archive_entry_xattr_reset(e2)); + assertEqualInt(0, archive_entry_xattr_next(e2, &xname, &xval, &xsize)); + assertEqualString(xname, "xattr1"); + assertEqualString(xval, "xattrvalue"); + assertEqualInt((int)xsize, 11); + assertEqualInt(ARCHIVE_WARN, + archive_entry_xattr_next(e2, &xname, &xval, &xsize)); + assertEqualString(xname, NULL); + assertEqualString(xval, NULL); + assertEqualInt((int)xsize, 0); +#endif + + /* Change the original */ + archive_entry_set_atime(e, 13580, 24690); + archive_entry_set_birthtime(e, 13980, 24999); + archive_entry_set_ctime(e, 13590, 24691); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_dev(e, 245); +#endif + archive_entry_set_fflags(e, 0x85, 0xDA); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_filetype(e, AE_IFLNK); +#endif + archive_entry_set_gid(e, 214); + archive_entry_set_gname(e, "grouper"); + archive_entry_set_hardlink(e, "hardlinkpath"); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_ino(e, 8763); +#endif + archive_entry_set_mode(e, 0123654); + archive_entry_set_mtime(e, 18351, 28642); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_nlink(e, 73); +#endif + archive_entry_set_pathname(e, "pathest"); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_rdev(e, 132); +#endif + archive_entry_set_size(e, 987456321); + archive_entry_copy_sourcepath(e, "source2"); + archive_entry_set_symlink(e, "symlinkpath"); + archive_entry_set_uid(e, 93); + archive_entry_set_uname(e, "username"); + archive_entry_acl_clear(e); + archive_entry_xattr_clear(e); + + /* Clone should still have same contents. */ + assertEqualInt(archive_entry_atime(e2), 13579); + assertEqualInt(archive_entry_atime_nsec(e2), 24680); + assertEqualInt(archive_entry_birthtime(e2), 13779); + assertEqualInt(archive_entry_birthtime_nsec(e2), 24990); + assertEqualInt(archive_entry_ctime(e2), 13580); + assertEqualInt(archive_entry_ctime_nsec(e2), 24681); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_dev(e2), 235); +#endif + archive_entry_fflags(e2, &set, &clear); + assertEqualInt(clear, 0xAA); + assertEqualInt(set, 0x55); + assertEqualInt(archive_entry_gid(e2), 204); + assertEqualString(archive_entry_gname(e2), "group"); + assertEqualString(archive_entry_hardlink(e2), "hardlinkname"); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_ino(e2), 8593); +#endif + assertEqualInt(archive_entry_mode(e2), 0123456); + assertEqualInt(archive_entry_mtime(e2), 13581); + assertEqualInt(archive_entry_mtime_nsec(e2), 24682); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_nlink(e2), 736); +#endif + assertEqualString(archive_entry_pathname(e2), "path"); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_rdev(e2), 532); +#endif + assertEqualInt(archive_entry_size(e2), 987654321); + assertEqualString(archive_entry_sourcepath(e2), "source"); + assertEqualString(archive_entry_symlink(e2), "symlinkname"); + assertEqualInt(archive_entry_uid(e2), 83); + assertEqualString(archive_entry_uname(e2), "user"); +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("ACL held by clone of archive_entry"); +#else + /* Verify ACL was unchanged. */ + assertEqualInt(4, archive_entry_acl_reset(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); + /* First three are standard permission bits. */ + assertEqualInt(0, archive_entry_acl_next(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + assertEqualInt(permset, 4); + assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ); + assertEqualInt(qual, -1); + assertEqualString(name, NULL); + assertEqualInt(0, archive_entry_acl_next(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + assertEqualInt(permset, 5); + assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ); + assertEqualInt(qual, -1); + assertEqualString(name, NULL); + assertEqualInt(0, archive_entry_acl_next(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + assertEqualInt(permset, 6); + assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER); + assertEqualInt(qual, -1); + assertEqualString(name, NULL); + /* Fourth is custom one. */ + assertEqualInt(0, archive_entry_acl_next(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ); + assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER); + assertEqualInt(qual, 77); + assertEqualString(name, "user77"); + assertEqualInt(1, archive_entry_acl_next(e2, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + &type, &permset, &tag, &qual, &name)); + assertEqualInt(type, 0); + assertEqualInt(permset, 0); + assertEqualInt(tag, 0); + assertEqualInt(qual, -1); + assertEqualString(name, NULL); +#endif +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("xattr preserved in archive_entry copy"); +#else + /* Verify xattr was unchanged. */ + assertEqualInt(1, archive_entry_xattr_reset(e2)); +#endif + + /* Release clone. */ + archive_entry_free(e2); + + /* + * Test clear() implementation. + */ + archive_entry_clear(e); + assertEqualInt(archive_entry_atime(e), 0); + assertEqualInt(archive_entry_atime_nsec(e), 0); + assertEqualInt(archive_entry_birthtime(e), 0); + assertEqualInt(archive_entry_birthtime_nsec(e), 0); + assertEqualInt(archive_entry_ctime(e), 0); + assertEqualInt(archive_entry_ctime_nsec(e), 0); + assertEqualInt(archive_entry_dev(e), 0); + archive_entry_fflags(e, &set, &clear); + assertEqualInt(clear, 0); + assertEqualInt(set, 0); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_filetype(e), 0); +#endif + assertEqualInt(archive_entry_gid(e), 0); + assertEqualString(archive_entry_gname(e), NULL); + assertEqualString(archive_entry_hardlink(e), NULL); + assertEqualInt(archive_entry_ino(e), 0); + assertEqualInt(archive_entry_mode(e), 0); + assertEqualInt(archive_entry_mtime(e), 0); + assertEqualInt(archive_entry_mtime_nsec(e), 0); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_nlink(e), 0); +#endif + assertEqualString(archive_entry_pathname(e), NULL); + assertEqualInt(archive_entry_rdev(e), 0); + assertEqualInt(archive_entry_size(e), 0); + assertEqualString(archive_entry_symlink(e), NULL); + assertEqualInt(archive_entry_uid(e), 0); + assertEqualString(archive_entry_uname(e), NULL); + /* ACLs should be cleared. */ + assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS), 0); + assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT), 0); + /* Extended attributes should be cleared. */ + assertEqualInt(archive_entry_xattr_count(e), 0); + + /* + * Test archive_entry_copy_stat(). + */ + memset(&st, 0, sizeof(st)); + /* Set all of the standard 'struct stat' fields. */ + st.st_atime = 456789; + st.st_ctime = 345678; + st.st_dev = 123; + st.st_gid = 34; + st.st_ino = 234; + st.st_mode = 077777; + st.st_mtime = 234567; + st.st_nlink = 345; + st.st_size = 123456789; + st.st_uid = 23; +#ifdef __FreeBSD__ + /* On FreeBSD, high-res timestamp data should come through. */ + st.st_atimespec.tv_nsec = 6543210; + st.st_ctimespec.tv_nsec = 5432109; + st.st_mtimespec.tv_nsec = 3210987; + st.st_birthtimespec.tv_nsec = 7459386; +#endif + /* Copy them into the entry. */ + archive_entry_copy_stat(e, &st); + /* Read each one back separately and compare. */ + assertEqualInt(archive_entry_atime(e), 456789); + assertEqualInt(archive_entry_ctime(e), 345678); + assertEqualInt(archive_entry_dev(e), 123); + assertEqualInt(archive_entry_gid(e), 34); + assertEqualInt(archive_entry_ino(e), 234); + assertEqualInt(archive_entry_mode(e), 077777); + assertEqualInt(archive_entry_mtime(e), 234567); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(archive_entry_nlink(e), 345); +#endif + assertEqualInt(archive_entry_size(e), 123456789); + assertEqualInt(archive_entry_uid(e), 23); +#if __FreeBSD__ + /* On FreeBSD, high-res timestamp data should come through. */ + assertEqualInt(archive_entry_atime_nsec(e), 6543210); + assertEqualInt(archive_entry_ctime_nsec(e), 5432109); + assertEqualInt(archive_entry_mtime_nsec(e), 3210987); + assertEqualInt(archive_entry_birthtime_nsec(e), 7459386); +#endif + + /* + * Test archive_entry_stat(). + */ + /* First, clear out any existing stat data. */ + memset(&st, 0, sizeof(st)); + archive_entry_copy_stat(e, &st); + /* Set a bunch of fields individually. */ + archive_entry_set_atime(e, 456789, 321); + archive_entry_set_ctime(e, 345678, 432); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_dev(e, 123); +#endif + archive_entry_set_gid(e, 34); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_ino(e, 234); +#endif + archive_entry_set_mode(e, 012345); + archive_entry_set_mode(e, 012345); + archive_entry_set_mtime(e, 234567, 543); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_nlink(e, 345); +#endif + archive_entry_set_size(e, 123456789); + archive_entry_set_uid(e, 23); + /* Retrieve a stat structure. */ + assert((pst = archive_entry_stat(e)) != NULL); + /* Check that the values match. */ + assertEqualInt(pst->st_atime, 456789); + assertEqualInt(pst->st_ctime, 345678); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(pst->st_dev, 123); +#endif + assertEqualInt(pst->st_gid, 34); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(pst->st_ino, 234); +#endif + assertEqualInt(pst->st_mode, 012345); + assertEqualInt(pst->st_mtime, 234567); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + assertEqualInt(pst->st_nlink, 345); +#endif + assertEqualInt(pst->st_size, 123456789); + assertEqualInt(pst->st_uid, 23); +#ifdef __FreeBSD__ + /* On FreeBSD, high-res timestamp data should come through. */ + assertEqualInt(pst->st_atimespec.tv_nsec, 321); + assertEqualInt(pst->st_ctimespec.tv_nsec, 432); + assertEqualInt(pst->st_mtimespec.tv_nsec, 543); +#endif + + /* Changing any one value should update struct stat. */ + archive_entry_set_atime(e, 456788, 0); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_atime, 456788); + archive_entry_set_ctime(e, 345677, 431); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_ctime, 345677); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_dev(e, 122); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_dev, 122); +#endif + archive_entry_set_gid(e, 33); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_gid, 33); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_ino(e, 233); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_ino, 233); +#endif + archive_entry_set_mode(e, 012344); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_mode, 012344); + archive_entry_set_mtime(e, 234566, 542); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_mtime, 234566); +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_nlink(e, 344); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_nlink, 344); +#endif + archive_entry_set_size(e, 123456788); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_size, 123456788); + archive_entry_set_uid(e, 22); + assert((pst = archive_entry_stat(e)) != NULL); + assertEqualInt(pst->st_uid, 22); + /* We don't need to check high-res fields here. */ + + /* + * Test dev/major/minor interfaces. Setting 'dev' or 'rdev' + * should change the corresponding major/minor values, and + * vice versa. + * + * The test here is system-specific because it assumes that + * makedev(), major(), and minor() are defined in sys/stat.h. + * I'm not too worried about it, though, because the code is + * simple. If it works on FreeBSD, it's unlikely to be broken + * anywhere else. Note: The functionality is present on every + * platform even if these tests only run some places; + * libarchive's more extensive configuration logic should find + * the necessary definitions on every platform. + */ +#if __FreeBSD__ +#if ARCHIVE_VERSION_NUMBER >= 1009000 + archive_entry_set_dev(e, 0x12345678); + assertEqualInt(archive_entry_devmajor(e), major(0x12345678)); + assertEqualInt(archive_entry_devminor(e), minor(0x12345678)); + assertEqualInt(archive_entry_dev(e), 0x12345678); + archive_entry_set_devmajor(e, 0xfe); + archive_entry_set_devminor(e, 0xdcba98); + assertEqualInt(archive_entry_devmajor(e), 0xfe); + assertEqualInt(archive_entry_devminor(e), 0xdcba98); + assertEqualInt(archive_entry_dev(e), makedev(0xfe, 0xdcba98)); + archive_entry_set_rdev(e, 0x12345678); + assertEqualInt(archive_entry_rdevmajor(e), major(0x12345678)); + assertEqualInt(archive_entry_rdevminor(e), minor(0x12345678)); + assertEqualInt(archive_entry_rdev(e), 0x12345678); + archive_entry_set_rdevmajor(e, 0xfe); + archive_entry_set_rdevminor(e, 0xdcba98); + assertEqualInt(archive_entry_rdevmajor(e), 0xfe); + assertEqualInt(archive_entry_rdevminor(e), 0xdcba98); + assertEqualInt(archive_entry_rdev(e), makedev(0xfe, 0xdcba98)); +#endif +#endif + + /* + * Exercise the character-conversion logic, if we can. + */ + if (NULL == LOCALE_UTF8 || NULL == setlocale(LC_ALL, LOCALE_UTF8)) { + skipping("Can't exercise charset-conversion logic without" + " a suitable locale."); + } else { + /* A filename that cannot be converted to wide characters. */ + archive_entry_copy_pathname(e, "abc\314\214mno\374xyz"); + failure("Converting invalid chars to Unicode should fail."); + assert(NULL == archive_entry_pathname_w(e)); + //failure("Converting invalid chars to UTF-8 should fail."); + //assert(NULL == archive_entry_pathname_utf8(e)); + + /* A group name that cannot be converted. */ + archive_entry_copy_gname(e, "abc\314\214mno\374xyz"); + failure("Converting invalid chars to Unicode should fail."); + assert(NULL == archive_entry_gname_w(e)); + + /* A user name that cannot be converted. */ + archive_entry_copy_uname(e, "abc\314\214mno\374xyz"); + failure("Converting invalid chars to Unicode should fail."); + assert(NULL == archive_entry_uname_w(e)); + + /* A hardlink target that cannot be converted. */ + archive_entry_copy_hardlink(e, "abc\314\214mno\374xyz"); + failure("Converting invalid chars to Unicode should fail."); + assert(NULL == archive_entry_hardlink_w(e)); + + /* A symlink target that cannot be converted. */ + archive_entry_copy_symlink(e, "abc\314\214mno\374xyz"); + failure("Converting invalid chars to Unicode should fail."); + assert(NULL == archive_entry_symlink_w(e)); + } + +#if HAVE_WCSCPY + l = 0x12345678L; + wc = (wchar_t)l; /* Wide character too big for UTF-8. */ + if (NULL == setlocale(LC_ALL, "C") || (long)wc != l) { + skipping("Testing charset conversion failure requires 32-bit wchar_t and support for \"C\" locale."); + } else { + /* + * Build the string L"xxx\U12345678yyy\u5678zzz" without + * using C99 \u#### syntax, which isn't uniformly + * supported. (GCC 3.4.6, for instance, defaults to + * "c89 plus GNU extensions.") + */ + wcscpy(wbuff, L"xxxAyyyBzzz"); + wbuff[3] = (wchar_t)0x12345678; + wbuff[7] = (wchar_t)0x5678; + /* A wide filename that cannot be converted to narrow. */ + archive_entry_copy_pathname_w(e, wbuff); + failure("Converting wide characters from Unicode should fail."); + assertEqualString(NULL, archive_entry_pathname(e)); + } +#endif + + /* Release the experimental entry. */ + archive_entry_free(e); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_entry_strmode.c b/external/bsd/libarchive/dist/libarchive/test/test_entry_strmode.c new file mode 100644 index 000000000..ba183db02 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_entry_strmode.c @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_entry_strmode.c 201247 2009-12-30 05:59:21Z kientzle $"); + +DEFINE_TEST(test_entry_strmode) +{ + struct archive_entry *entry; + + assert((entry = archive_entry_new()) != NULL); + + archive_entry_set_mode(entry, AE_IFREG | 0642); + assertEqualString(archive_entry_strmode(entry), "-rw-r---w- "); + + /* Regular file + hardlink still shows as regular file. */ + archive_entry_set_mode(entry, AE_IFREG | 0644); + archive_entry_set_hardlink(entry, "link"); + assertEqualString(archive_entry_strmode(entry), "-rw-r--r-- "); + + archive_entry_set_mode(entry, 0640); + archive_entry_set_hardlink(entry, "link"); + assertEqualString(archive_entry_strmode(entry), "hrw-r----- "); + archive_entry_set_hardlink(entry, NULL); + + archive_entry_set_mode(entry, AE_IFDIR | 0777); + assertEqualString(archive_entry_strmode(entry), "drwxrwxrwx "); + + archive_entry_set_mode(entry, AE_IFBLK | 03642); + assertEqualString(archive_entry_strmode(entry), "brw-r-S-wT "); + + archive_entry_set_mode(entry, AE_IFCHR | 05777); + assertEqualString(archive_entry_strmode(entry), "crwsrwxrwt "); + + archive_entry_set_mode(entry, AE_IFSOCK | 0222); + assertEqualString(archive_entry_strmode(entry), "s-w--w--w- "); + + archive_entry_set_mode(entry, AE_IFIFO | 0444); + assertEqualString(archive_entry_strmode(entry), "pr--r--r-- "); + + archive_entry_set_mode(entry, AE_IFLNK | 04000); + assertEqualString(archive_entry_strmode(entry), "l--S------ "); + + archive_entry_acl_add_entry(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + 0007, ARCHIVE_ENTRY_ACL_GROUP, 78, "group78"); + assertEqualString(archive_entry_strmode(entry), "l--S------+"); + + /* Release the experimental entry. */ + archive_entry_free(entry); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_extattr_freebsd.c b/external/bsd/libarchive/dist/libarchive/test/test_extattr_freebsd.c new file mode 100644 index 000000000..4b19d2762 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_extattr_freebsd.c @@ -0,0 +1,172 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_extattr_freebsd.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#if defined(__FreeBSD__) && __FreeBSD__ > 4 +#include +#endif + +/* + * Verify extended attribute restore-to-disk. This test is FreeBSD-specific. + */ + +DEFINE_TEST(test_extattr_freebsd) +{ +#if !defined(__FreeBSD__) + skipping("FreeBSD-specific extattr restore test"); +#elif __FreeBSD__ < 5 + skipping("extattr restore supported only on FreeBSD 5.0 and later"); +#else + char buff[64]; + const char *xname; + const void *xval; + size_t xsize; + struct stat st; + struct archive *a; + struct archive_entry *ae; + int n, fd; + int extattr_privilege_bug = 0; + + /* + * First, do a quick manual set/read of an extended attribute + * to verify that the local filesystem does support it. If it + * doesn't, we'll simply skip the remaining tests. + */ + /* Create a test file and try to set an ACL on it. */ + fd = open("pretest", O_RDWR | O_CREAT, 0777); + failure("Could not create test file?!"); + if (!assert(fd >= 0)) + return; + + errno = 0; + n = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, "testattr", "1234", 4); + if (n != 4 && errno == EOPNOTSUPP) { + close(fd); + skipping("extattr tests require that extattr support be enabled on the filesystem"); + return; + } + failure("extattr_set_fd(): errno=%d (%s)", errno, strerror(errno)); + assertEqualInt(4, n); + close(fd); + + /* + * Repeat the above, but with file permissions set to 0000. + * This should work (extattr_set_fd() should follow fd + * permissions, not file permissions), but is known broken on + * some versions of FreeBSD. + */ + fd = open("pretest2", O_RDWR | O_CREAT, 00000); + failure("Could not create test file?!"); + if (!assert(fd >= 0)) + return; + + n = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, "testattr", "1234", 4); + if (n != 4) { + skipping("Restoring xattr to an unwritable file seems to be broken on this platform"); + extattr_privilege_bug = 1; + } + close(fd); + + /* Create a write-to-disk object. */ + assert(NULL != (a = archive_write_disk_new())); + archive_write_disk_set_options(a, + ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_XATTR); + + /* Populate an archive entry with an extended attribute. */ + ae = archive_entry_new(); + assert(ae != NULL); + archive_entry_set_pathname(ae, "test0"); + archive_entry_set_mtime(ae, 123456, 7890); + archive_entry_set_size(ae, 0); + archive_entry_set_mode(ae, 0755); + archive_entry_xattr_add_entry(ae, "user.foo", "12345", 5); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Another entry; similar but with mode = 0. */ + ae = archive_entry_new(); + assert(ae != NULL); + archive_entry_set_pathname(ae, "test1"); + archive_entry_set_mtime(ae, 12345678, 7890); + archive_entry_set_size(ae, 0); + archive_entry_set_mode(ae, 0); + archive_entry_xattr_add_entry(ae, "user.bar", "123456", 6); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close the archive. */ + if (extattr_privilege_bug) + /* If the bug is here, write_close will return warning. */ + assertEqualIntA(a, ARCHIVE_WARN, archive_write_close(a)); + else + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* Verify the data on disk. */ + assertEqualInt(0, stat("test0", &st)); + assertEqualInt(st.st_mtime, 123456); + /* Verify extattr */ + n = extattr_get_file("test0", EXTATTR_NAMESPACE_USER, + "foo", buff, sizeof(buff)); + if (assertEqualInt(n, 5)) { + buff[n] = '\0'; + assertEqualString(buff, "12345"); + } + + /* Verify the data on disk. */ + assertEqualInt(0, stat("test1", &st)); + assertEqualInt(st.st_mtime, 12345678); + /* Verify extattr */ + n = extattr_get_file("test1", EXTATTR_NAMESPACE_USER, + "bar", buff, sizeof(buff)); + if (extattr_privilege_bug) { + /* If we have the bug, the extattr won't have been written. */ + assertEqualInt(n, -1); + } else { + if (assertEqualInt(n, 6)) { + buff[n] = '\0'; + assertEqualString(buff, "123456"); + } + } + + /* Use libarchive APIs to read the file back into an entry and + * verify that the extattr was read correctly. */ + assert((a = archive_read_disk_new()) != NULL); + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_pathname(ae, "test0"); + assertEqualInt(ARCHIVE_OK, + archive_read_disk_entry_from_file(a, ae, -1, NULL)); + assertEqualInt(1, archive_entry_xattr_reset(ae)); + assertEqualInt(ARCHIVE_OK, + archive_entry_xattr_next(ae, &xname, &xval, &xsize)); + assertEqualString(xname, "user.foo"); + assertEqualInt(xsize, 5); + assertEqualMem(xval, "12345", xsize); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + archive_entry_free(ae); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_fuzz.c b/external/bsd/libarchive/dist/libarchive/test/test_fuzz.c new file mode 100644 index 000000000..e5dede932 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_fuzz.c @@ -0,0 +1,166 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_fuzz.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* + * This was inspired by an ISO fuzz tester written by Michal Zalewski + * and posted to the "vulnwatch" mailing list on March 17, 2005: + * http://seclists.org/vulnwatch/2005/q1/0088.html + * + * This test simply reads each archive image into memory, pokes + * random values into it and runs it through libarchive. It tries + * to damage about 1% of each file and repeats the exercise 100 times + * with each file. + * + * Unlike most other tests, this test does not verify libarchive's + * responses other than to ensure that libarchive doesn't crash. + * + * Due to the deliberately random nature of this test, it may be hard + * to reproduce failures. Because this test deliberately attempts to + * induce crashes, there's little that can be done in the way of + * post-failure diagnostics. + */ + +/* Because this works for any archive, we can just re-use the archives + * developed for other tests. */ +static struct { + int uncompress; /* If 1, decompress the file before fuzzing. */ + const char *name; +} files[] = { + {0, "test_fuzz_1.iso.Z"}, /* Exercise compress decompressor. */ + {1, "test_fuzz_1.iso.Z"}, + {0, "test_compat_bzip2_1.tbz"}, /* Exercise bzip2 decompressor. */ + {1, "test_compat_bzip2_1.tbz"}, + {0, "test_compat_gtar_1.tar"}, + {0, "test_compat_gzip_1.tgz"}, /* Exercise gzip decompressor. */ + {0, "test_compat_gzip_2.tgz"}, /* Exercise gzip decompressor. */ + {0, "test_compat_tar_hardlink_1.tar"}, + {0, "test_compat_xz_1.txz"}, /* Exercise xz decompressor. */ + {0, "test_compat_zip_1.zip"}, + {0, "test_read_format_ar.ar"}, + {0, "test_read_format_cpio_bin_be.cpio"}, + {0, "test_read_format_cpio_svr4_gzip_rpm.rpm"}, /* Test RPM unwrapper */ + {0, "test_read_format_gtar_sparse_1_17_posix10_modified.tar"}, + {0, "test_read_format_mtree.mtree"}, + {0, "test_read_format_tar_empty_filename.tar"}, + {0, "test_read_format_zip.zip"}, + {1, NULL} +}; + +DEFINE_TEST(test_fuzz) +{ + const void *blk; + size_t blk_size; + off_t blk_offset; + int n; + + for (n = 0; files[n].name != NULL; ++n) { + const size_t buffsize = 30000000; + const char *filename = files[n].name; + struct archive_entry *ae; + struct archive *a; + char *rawimage, *image; + size_t size; + int i; + + extract_reference_file(filename); + if (files[n].uncompress) { + int r; + /* Use format_raw to decompress the data. */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_raw(a)); + r = archive_read_open_filename(a, filename, 16384); + if (r != ARCHIVE_OK) { + archive_read_finish(a); + skipping("Cannot uncompress %s", filename); + continue; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + rawimage = malloc(buffsize); + size = archive_read_data(a, rawimage, buffsize); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_next_header(a, &ae)); + assertEqualInt(ARCHIVE_OK, + archive_read_finish(a)); + assert(size > 0); + failure("Internal buffer is not big enough for " + "uncompressed test file: %s", filename); + if (!assert(size < buffsize)) { + free(rawimage); + continue; + } + } else { + rawimage = slurpfile(&size, filename); + if (!assert(rawimage != NULL)) + continue; + } + image = malloc(size); + assert(image != NULL); + srand((unsigned)time(NULL)); + + for (i = 0; i < 100; ++i) { + FILE *f; + int j, numbytes; + + /* Fuzz < 1% of the bytes in the archive. */ + memcpy(image, rawimage, size); + numbytes = (int)(rand() % (size / 100)); + for (j = 0; j < numbytes; ++j) + image[rand() % size] = (char)rand(); + + /* Save the messed-up image to a file. + * If we crash, that file will be useful. */ + f = fopen("after.test.failure.send.this.file." + "to.libarchive.maintainers.with.system.details", "wb"); + fwrite(image, 1, (size_t)size, f); + fclose(f); + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + + if (0 == archive_read_open_memory(a, image, size)) { + while(0 == archive_read_next_header(a, &ae)) { + while (0 == archive_read_data_block(a, + &blk, &blk_size, &blk_offset)) + continue; + } + archive_read_close(a); + } + archive_read_finish(a); + } + free(image); + free(rawimage); + } +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_fuzz_1.iso.Z.uu b/external/bsd/libarchive/dist/libarchive/test/test_fuzz_1.iso.Z.uu new file mode 100644 index 000000000..07a3e934d --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_fuzz_1.iso.Z.uu @@ -0,0 +1,495 @@ +$FreeBSD: head/lib/libarchive/test/test_fuzz_1.iso.Z.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_fuzz_1.iso.Z +M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1GA0%`(,)$`4'QT(0``F'H@``@"(PJ)`"(A"04(6#"0" +M`!P4E..+`;'(Q@(6),!``^"$>&)`*`+0X9),-NGDDU!&*>645%9IY9589JGE +MEEQ>V<0224SQA!%3@!#F$R#D8(,-,+R`!)D@&)$$$T5,D<445!2AH1!5S$E$ +M$5*`8`((%Q8QQ!-2/"A@"U*\0(05BDI11!!4(`H""D.D`$(,.>0P`PA%N)#% +M$U4X<0010=!Y:::;=GH#"$JX`,6D4HCIQ`NQ3C$$$G,RD82I708K;+`R$(A# +M##'(4&P.R<8P`X'@%`O#L,L<,Y`&"#VP#``,`7`"!A=L(.`SPV +M$P"4G'`69%/1=\8,'UR%V`#PO7#)%CML`L,3+VQQR1-C;/'"$E/<0L5S4VP% +MQ9E/#D`074-=^M2G,QTNLN.6>VZVJU=+[K70>FO[MN`:R[JUYF(+3KKV!B_\ +M\,07;_SQR",K`QD.-`Z!A(B#`%B'0`800A3Z\(_\A4#DAM%<""0&[YR%0&3PSE8(!)D8/85` +MM(K14`BD!N_AM%*".0&[WR$0'#PSD0(I&T8'81`K(K1/@AD!^^\@T!X +M\,XX"*0'[UR#0'SP3H(%Y)<8I5M`I(I1P`6$=!A-6$`.AE&-!61B&#V"0!:& +M4=(%I&08A>V_WHG9@$@7HX`-B-TPF@*!C`VCYA"($MZ)U8"$#:/>$`C?,(H- +M@6@,H](0B!/>R0R!8`RCQA`(%-X)#(&0"*.Z$(C%,$H+@20,HZX0B.`PB@J! +M'`ZCHA#(YS#*"8&D$J.6$(A0,0H)@0`.HXH0B!;>20B!;.&=?A`(%]Z)!X&4 +M$J,,!(!/,.>2`A.&=*PZ(&-XIN("$$J/[#8A.,6JW@!`, +MHP<+2)`Q2MN`G.&=;PL(&MXIMX!T$J-L#8A-,7H.@>@6HUP-2(\Q^@V!M.&= +MV1"(&]XY#8%D$J/-$(A,,7H,@=@6H\$0B,`PN@N!S.&=M1`('=[Y"H%4$J.I +M$(A+,3H*@<@6HYT02(TQ>@F!Y.&=D1"('MZY"(%$$J.%$(A*,?H'@;@6HZ<. +M2(PQ^NB`U!JC=PX((-[YY8`T$J-'#HA),?KB@*@6HX<+2(LQBK&`Q!JC8PN( +M(=XYL8`D$J.X#8A(,0K:@)@6HX@-2(HQ"M>`M!JCZ!`((][YN(`4$J/@$(A' +M,:H-@8@6H]002(DQZ@R!I!JCR!"()-XI#($$$J.\$(A&,6H+@7@6H[`02(@Q +MJ@J!E!JCI!`()M[I"8'T$:,C#TA%,;KP@&@6H_,.2( +M@$@6HPL+2(4QRMN`9!JCI`U(QS'*V(#$$:-T#4A"K3O!NMO][GC/>WBDAZ,C +M^3T@&0P`#@7R0<%_\_`CS-E/3]3"%\9PA@.IH0`&'Q`=#@#QF/\[`(9(`-(5 +M42!)[#P3!^)$T1?H\P&9HNFM.!`LFGZ+`^FBZ;\XD#":?HP#*:/ISSB0-)I^ +MC0-IH^G?.)`XFGZ.`ZFCZ>\XD#R:?H\#Z:/I_SB00)I^D`,II.D/.9!$FGZ1 +M`VFDZ1\YD$B:?I(#J:3I+SF03)I^DP/II.D_.9!0FGZ4`RFEZ4\YD%2:?I4# +M02*F)TL#$3:FATL#43*FUTL#\4NF%TP#T3:F9TP#@4RFITP#L3FF]TP#$4VF +M-TT#44T%0'D`H$T&@'F(IWDW<@`8)1#GE``M&!#LI``Q"$\`L``U6$\,4(/Y +MU``UV$\.4(,!]0`U6%`04(,)%0$UV%`24(,1-0$U6%$44(,:50$UZ%$64(,B +M=0$U:%(84(,JE0$UZ%(:4(,RM0$U:%,<4(,ZU0$UZ%,>4(-"]0$UV#@UR#90(U*%8G4(-FA0(U2%4J4(-NM0(U*%=0,U*%HX4(.FE0,UJ%HZ4(.NM0,U*%L\4(.VU0,UJ%L^4(,$\P,U2#=` +M4(,G5H,)(P0UJ#%#4(/2A2J:1SJ3HGFP900UB%E'4(.`A00U6%Y)4(/II00U +MB%5+4(/QQ00U6%]-4(/YY00UV%]/4(,!!@4U6&!14(,))@4UV&!34(,11@4U +M6&%54(,99@4UV&%74(,AA@4U6&)94(,II@4UV&);4(,QQ@4U6&-=4(,"XP4U +MV&-?4(-!!@8U.&1A4(,K)@8U*#AC4(/[108U:#=E4(,'8P8U2%MG4(-O@P8U +M*#=I4(-LI08UV&9K4(-+4(/QQ@@U^#B-4(/YY@@UV&^/4(,!!PDU +M6'"14(,))PDUV'"34(,11PDU6'&54(,99PDUV'&74(,AAPDU6'*94(,CIPDU +MN'";4(/SQ@DUN&V=4(/#Y@DUN&J?4(.3!@HUN&>A4(-C)@HUN&2C4(,S1@HU +M^#FE4(,#9@HUN%ZG4(,+@PHUR%NI4(.DI0HUR%BK4(-TQ0ITIW<8FJ$:NJ$< +MRAL'4C,7!``A`@LH,SK#=@LEBEQ&I*(LNJ(NVJ(P^J(R&J,T.J,V6J,X>J,Z +M&@0A$@LF8B1!,&RX8"(\M*-&FJ-(>J1*FJ1,NJ0K&B*R8"*?%Z0`D`LF^J0`,`LFPDVC$R*T8"(OPJ,`4`LFPC)E"@"V8"+N]*;O($_' +M%2+P8$]W"@#QH$][*@_^M*?S(%![2@\&M:?UH%![:@\.M:?W(%%[B@\6M:?Y +ML%%[J@\?M:?[,%)[R@\GM:?]L%)[Z@\OM:?_,%-[ZG<6I*9)`@`\]:8"8"(K +M]*8#8"(=]*8$$#1[6@`F,D1O:@`F(DYJ>@`FHE9JB@`FTEYJF@`F$F=JJ@`F +M4F]JN@`F$DUOR@`F(E9OV@`F4EYOZ@`FDF9J^@`FTFYJ"@$F$G=J&@$FPDQJ +M*@$FXE5O.@$F$EYJ2@$F4F9J6@$FDFYJ:@$FTG9J>@$F@DQOB@$FHE5OF@$F +MTEUJJ@$F$F9JN@$F4FYJR@$FDG9JV@$F,DQJZ@$F8E5O^@$FHEUJ"@(FTF5J +M&@(F$FYJ*@(F4G9J.@(F\DMO2@(F(E5O6@(F8EUJ:@(FDF5J>@(FTFUJB@(F +M$G9JF@(FHDMJJ@(FXE1JN@(F(EUOR@(F4F5JV@(FDFUJZ@(FTG5J^@(F0DMJ +M"@,FHE1JZB^$\Z8R8")1IJ8S8"+5IJ8T8")9IZ8U8"*MI*8V8")&I:8W8"+* +MI:8X8")-IJ8Y8"+1IJ8Z8")5IZ8[8"*I]*8\8")"]:8]8"+&I:8^8"))IJ8_ +M8"+-IJ9`8")1IZ9!8"*E]*9"8"(^]:9#8"+"I:9$8")%IJ9%8"+)IJ9&8")- +MIZ9'8"*A]*9(8"(Z]:9)8"*^I:9*8")!]J9+8"+%IJ9,8"))IZ9-8"*=]*9. +M8"(V]:9/8"*Z]:908"(]]J918"+!IJ928")%IZ938"*9]*948"(R]:958"*V +M]:8@&#![>@4FTFMJB@4F$G1JF@4F4DEOJ@4FXE)ON@4F(EMOR@4F4F-OV@4F +MDFMJZ@4FTG-J^@4F$DEO"@8FHE)O&@8FXEIO*@8F$F-O.@8F4FMO"GD`D'-J +M6@8FTDAO:@8F8E)O>@8FHEIOB@8FTF)OF@8F$FMOJ@8F4G-JN@8FDDAOR@8F +M(E)OV@8F8EIOZ@8FDF)O^@8FTFIO"@@@@FTFEOB@@F$G)OF@@F4D=OJ@@F +MTE!ON@@F(EEOR@@F4F%OV@@FDFEOZ@@FTG%O^@@F$D=O"@DFDE!O&@DFXEAO +M*@DF$F%O.@DF4FEO2@DFDG%O6@DFTD9O:@DF4E!O>@DFHEAOB@DFTF!OF@DF +M$FEOJ@DF4G%ON@DFDD9OR@DF$E!OV@DF8EAOZ@DFDF!O^@DFTFAO"@HF$G%O +M&@HF4D9O*@HFTD]O.@HF(EAO2@HF4F!O6@HFDFAO:@HFTG!O>@HF$D9OB@HF +MDD]OF@HFXE=OJ@HF$F!ON@HF4FAOR@HFDG!OV@HFTD5OZ@HF4D]O^@HFHE=& +MU*%F?=9HG=;LP7$K=>%?=@WRMD^DW:?[1-J`^D^D/:@#1=J&>E"DG:@+1=J,^E"D_:@3 +M1=J2>E%\#0"5RE&DC:D@-=R;2E*D[:DH-=RARE*D3:HP-=RG2E.=;2(XI=@' +MPE/9'2)`I=@\1%2*741(I=C7Q%2*S4U0I=CD1%79S2)8E=TLPU79[4Y@I=CS +M1%:*?4]HI=C[5%[9_4]LE=T#!5?9?5!TE=T+A5>*_5!\I=@3!5C9/2.$I=@< +MA5C972.,E=TD!5F*#3.4I=@LA5G9+3.*+3B#IMB'H3.L'\] +M(_\!C0````4@`32`"%`!%H0&^``!0`0\"!30`G9`#0@#B<00U!D`((,0A`R" +M,^H?S\!_%P1%!($:&``2@1-H`L!J=-S``'``!T("[($0T`$.A!\X`2M@`+B` +M19`(/D$UF`$!@*3Z(`3A@S3!%[@&9>")H$,HZ)M002O8!`2:X06P4,%[()9<@6S$I>L`VHE8$P`L3@#D$'KC`,!L$S.`1K81IT?[@P%^K" +MQG`%W5@W*83`,!@*PQ&R!;N@0/B"!2$"]D`R6!!F(1I<@[9P#>[":4@-JZ$U +MO(8X(HX$3$@AOD(OK#X180!,!&9(8$X1TBQ)VX!D7B@9@T3H0@.)&46`>C +MH.E!+"Z1(L;$T#C0T02NZ2,:V'2L+'LDR.9(^/HD621/+)(9/@BT>-:5(_L\3^* +M2+@(`*A8]VF2%Q)@K,C\:!ZKY)"\DC(R2Q[)$)&Z$)79C3OY&.VDE!X).Q(YJTCTRL/3C)T_$^K&//E)* +MDDD.22C/I*%DBXA22]9(+EF_VD^C#`#O!U)&R049)!LD1_R0$+(P6I'):ITC@>QLK5?Y(E#-@OS))2OL([>2FQI*;$E5FQE00@:VDY +MH&2LG)2E,E@^2SQ)+%5E5J0E!HPXF1EUT4)"Q#T8*=$FQUR70K-=2L.E23@+I^$\G)DAR-Q- +M@7`C\B:*I)K[T&^>S+E9,PVFFI2'FZ<@0$T8(37UY@RLFANR7D+,CADX/V;/ +M0()J,R!0%<=Y"04/WQR5H?-J:L2L63DG)HA$G+@S=^K.W=D8@DSJ!`"K,VK> +MQA,A#B-G['R86)-@UDZ5>3L59T%HG,)S;)X,?6@#C^??I)D`P&9>SEO88]K+ +M0,`JK#,<1D1>Q0?/)9U$GK-3>69/RZDO;R'O?)_P,W[*S[D09+SG5?F4Q;-Z +MRLKK23G7I^V$C0#`=ZI#_$D]`P`_1)>R,SB23JTI.-M@CXDS`X&KA$^R.3Y! +M(>S,0))6$(Z@^*2"F:!O6L\BVC:/:,\8`G$S`.S,L=)$^Z@?_:.`M",$F3T: +M$*+)#P4:)U1RVE`SFD/;H,#PF@``;%9"Z2E&>=79/)Z_HZT&@E@YI,2S@@K1'SDH1^<579Y;T#0[2@F!(P>C4K*0&5)&646#:2$]GC_%6`Z&\H%(I^#K-9RM- +MGA$3EC;0TWE+NZDW_::!-,A`4X$@38VIYR2>B72.+E)FVDF%*0#0I0'AE)K3 +MQXE,4>@U39_9U'\R3P#:8]+,0&`KT]1U!E$Y2D9=*?;DI+<3G"K4A0 +M\:<"`:#.T]:93@LJ-EV@VC2+YAMQ6A#**><!=2>`LME6E*;J1;M,7%G(-`5EEI-A^@]M:('E7VV4VYZ4[NJ5_VJZR_( +M1-6YPE.3J3IEJD#5I`I5E%H05NI$#8=)59D:U!NJ56]G&EVC!\&-4E`XZE)' +M*EHMG3(U`^)1;.4R[PI8/:R(-;%FCR!36`/"Y@BH%=6G_E4L&EA/YR,M")+4 +M&W9.>HI4S2;:S*1L,ZTZ57#P20/`6`T(=*7'R*N!X%6HZD"]H))UKC+2K:I% +M%:MMO:VX-3\$F=6Z5\JJ4FV6LI6=-D\`T%B)*P$5J5DQX&0B` +MQ;62S[Z:7&FG/HVE:C*W:M?MREWM0Y!YKG_%M\K5B_I*K^LV7:N\-2"TUK=* +M-N/J60VN396V-M>X41#DAG2UH-9TJ<)7T2I?NZM__:\`UCP$F3(S$.PK>X6< +M/=6O[M?EJE8W*@``KP$ANA[8>CI>\2E&-:\:%0FFFX&`6.[K*I64"I:\9M7_ +MR34#K(D]L2BV.@29#7M8Q.M[%;%TE<3*T@%;7X]K+PVQ%K:\(E1^"BX*`F/Q +ML-15O\+8V9I04ZR1/;)(EC@$F;8S$'[LA$6GR%7(YM@1NT^YYHHM"!WVR8;4 +M&UM=-VE=!:!W=2`$`#9*$/0J$.55<12VXEBL&F.K[(PF<[K:?]M(D3`%#:R>)B+>J4;;/8]5MN43T+`/BL +MEBV;7%;*LEDBRV.[RT#`+)!NYUJK*6N5*69FKL/VVX#;<&H8@8VTW +MR[%=L]PVHU;6M5IL`P*N?;9^5ELF6_YZ.WM,N1D(H"7;LM)MVVB_K*\5MP`W +MX`I<^@D`[NUG.;>9]L)NVNQ*;@L"MH6WL7;72EMERV/3SD`@+?H6Q"9<'>MO +M.>W`_;@@-^22A2!C<4<+PN6W7E;&,MR"6Q#R+<1-L!N7RJ9:(PD`PJP&(;,# +MP5I$KM$]NDA7*009HAL0VD:?C;@_=^+26T$; +M23&KH0V;F[5U%E!%2T49;HS(&@A6)>-66*G+8$=KTGV[ +M<#?NZH0@L*MJ):_K?;VPMR0$&=,[6RZOZ)RW;;>_4MZ"D'@_[]K-O*.7YO:8 +M<#,0<$OJ1;:,=^HZWMC+?)NO\XT(08;XWA;;FT"!+^NEN;.W(*!>W[MXV6ZW +M;;!(L.P,!-YR?-'MZIVY>O7YJM_URWX'0I`1O[N%^E91ZXM^;V'T+0C&E_NJ +MWJ];?]$H`%"C8A;G"@2=FTKY*J9%N9I6\WY+.*LP!4(#;K\0.`(?W2#S@`'` +M+WFZ,!&WZ)<(_),@/A +M8$!A,CR$,^P5?L-P&-P&&30L$-0P$(ZWMS?YYM[AFOZ,2$"%MDF8_IIA`-!M +M!L+$6,.AMPWOW3C,B!NQIPTRA5@@'.([#'7SL!+6N]YV#A<$.VQ41?"6'<.) +M&`5?WR/88\+.0%@8B-@2"V(W[(A;L2M&L4'&%$^7+0Q3]S``A<0%81)WXC`Z +M@D&Q*B[#&=;F(@D!+&[9<"`1J_XFE,C6]JD)'& +M@P,#!]Y`#(P7L0?FAE@7I,):2_I9U>$JWKNE518'A(718YS*0``8J;CZ=F-O +M6XWKL3U>J$'&'0L$>$R)?;$\5L29>'`0A)+QA_'P/V;&@]AJ#03I$H_G[SP& +MO_!L+882<8?-Q0>#'N_B8]F*-3(-[K2SM,55F(-B- +MALR%E:_'G<@P.2;7TB"3D@7"2L[(H/<7`V3P6Y$+`D8.R>?T$Y/D*"QS!W&V +M&0AC@R77XN_K=F6R4W[*?33('&7S0HM_JBVVLG6C(-QDH,Q9A7)./L@;>`KK +M4`#0=0;">E'*5IDI]U>HS);;L@<-,F59O53ER;J$>3+B(`A)&0EOY+`\BF^A +M,#X1Q'BS@I`"_`F3\;Y=QGRY&=_1/`HO!4)C=LN0.3)?PR#SF`%`V-#&7]DA +M[V2W^XV_)@C6K.)XZY9C@J!).3(ZSJ-Q.2"LEQZC5`8"WT#+=!D30V3)3)MK +MS:8YS+0-`8L)DWU^6F;)N;LW.>AD'& +M.-N7W8Q[>_,M3AP%X34'9Z)<@S-LCXDR`V&_).?JO)S7\G,^S^A9_049\*Q? +MJ+,>MLY863H'!.2\G1&S%.[+8[G:#`2,,9[?*[/H3@Q#^*L,Q`&3'].T!PX_0[H#]N_/&;SJC'>N0;8YZ9H":U1X:RX-#`=.D?K:/\09&YT0"`1 +MF/GW/F3.7'4)[6>^NJ'9LV)2],-@A"PK#231I`;^DY3:?I0Y!1 +M+@/A38?I[GNEW6Z7+@A@FBMK78.LF54T^.TQ3<90XL^6>H#5='=>Q'4Z4DMJ +M]Q!D$K6$$=%Q^CKC:0>#IC-S2[[*)QD`1)N!<#C@])B6TY,Z5:OJ\!!D1K6% +MP=2G^CI;ZIK9J<6TH7:[/:;J#(3/8:IOM7E>U<`Z6&N'(*.K-0RL]M7#U54' +MA%*-HL'R?5;,6I1%!V8"3$T+T$P[(`QMJAV;%?01E-8N +M>J8>8\.L<;GSV1Z"91L!X09TV-BUT#P*5Q[.'MMO\VY._>XU3$%`7/OZ<+]L,ETX`8` +M@YMM*V?9#+&%RT"@&YF["V=7STV[:_=B"#*NV\>8;%H(,_Q8(_MM]"V?9K6K5=T%HW_5[AE9B9XVSP2_< +M-@C46J"BV6L=H>$WZ+M(?F%TK +M;I',N)`=P$T[$B[A3"#(^7"``<05NMWDW +MYDSA*WQ[^^?\S6-]RT`@&$&QR.%^0)[K`).<1..@-A +MS"CR#,W('[DI/^4V(QE!WL)+MUW]OW@5@[]HPKS! +M&[4EO]MI$,ZR2H$PS%&Y,3_F(B'(%',`T$E8^/NNX_U572?NK"N\27#C7IOH +M>D:6UE4N9I!@^!H(-F64BV4DBLS+N3G?"$'FFPN$<.[**?@E)]/+O)E+<0P] +MSD]J^1H(ND6NO]-7SHWC +MKU5&NW-@/E/_N46_Z!0AR#CT`4S0R;=!%^@!(9_/@+O*`+7P!0=`;"GDGI%]NE"_6A#L=[NIZ9 +MZ4+R+O(4" +M@,`>$/1Z8G?AH3K'*!J(/EU]^2O'Z@!TLJOV[<#]D0>9W>YH,#LIU^RN'8!MKY6B7M`Z.VX/:Z#65P>@.,V.9_;'/RT._=;"6<7 +MI:6Q[O!]@`<9]QX0*DEL+^.S_19*\R,]PX,R6W?K?1&NH_9'FT>S>T"8-#T& +M@@T$ES+=[7A\?_"V.\@H>$VSW??YZ9SO!<&^A_(KN0`%`KAD(IZ;&IW8U.!TV:[3WS9YO[GFG:NB=],^T;6\,\96 +M?-+5B/D]'[.#3)X/")'DOO]R.V]9T;IGEN'4W'Y; +M@\(&@DKY\B^9SVMZ5&_YO%[F^>>`("%#037@NF'^*9_ +M]1H[R*AZ6P/J`[*G#PB7/LOG][$,PP9"C&GUFQO6"WN,'61ZO4#X]5*>>!/V +ME3OK`P*KU_6G?BS3L(%0:X`]S1WVV%Y@!YEI+Q"J?;+'WYG=G1I[75/J!_VN +M+_)R32`,&VNOH;.]NP?602;="YM:;Y>YO:\I]^J=RD?K-S^,XWQMW:O6FLY/ +M>4+O`?-HFQ0(!__=*_P<'602/@!H)((^WQ/\?+/?$7V27O2+EDDK]D>?1^7] +M#4."0&P@F!1V7\H7OLD/T`RO((S\;U^UE[U!=_@0']J;=5(,`(C80%`M)+^B +MG_R=KZ6#C,T7"#B?Y;?MX^Y.0[Y`6/D1G,*R<="^V)'80&@Q.9^?\_RIS_`! +M@-,7"%!?Z*_N<%_E?[ZSP?=U_MR?5"8V$&)-U.>J5#_M;^@@0_8%@MG7^MR; +MZZ_5JR]MP/[`%_M/%0#4G(&P;<[^OU?[@#\]!YF]+Q#Z/MR?XG+?P;9]:V/W +ME7WBM_(`&,[K^D2RMA%_;($$L-A!$BM]?Z:`_]\/D($/[!8+M/_STW,*OU=&? +M2)9[FC;WT;[(<[&!8%INO^Y__I(YR"Q_@=#\@3])Q\J]7]PT?G"?^?,^&!L( +M*<;Y0__QSY:#S/<7".'?^COZ!3W]S0L8'0:L0_^;__,3G(S'^! +M4/_5O^O'G.>?NO'^#7WNA:.N6O_W36G.EU_VEP>]0`&!/-&CP''#`0>A0)X`@Z!$EB0\0/J&Q'@ +M<*4"LH`R'TVWT]$Q`X%H(002@53@&Q9D0('^1A)XG1V!`4$0V`0F=3L='C,0 +ME!A38!5H!N9@0888*'!H@5@9%A@02(%?H,NWT_$Q`T&J40:>@7A@^Q5DT($& +M!QOHA:F!`0$9&`?&?P!`RS$0+!QW8!ZH"#I?088AJ'#X@2L7'Q@0V(&#X`4( +M^>5R4AWEQ\MU@`(?YE<`PEDWDL.Q"(Z"D5>0$0H&!(%$"WCW@8!:5,4W`WIB +M-2#K=P.N?RH8MN((!@0+1X^!R`P$&D4B2`K^@B!7D+$+2AR0H$%W"@(`J6`E +M6``B08S,0.!9^(+`8#3X=@49S:#%40PN:,-@0-`+*H/"WWP%R0P$(08T*`V. +M@R)7D/$-:AS7(.94#08$SR`WJ.+U&)3,0%!JB(/D8#TH<`49\:#'D0Z><>=@ +M0!`.NH.#6,HQ$(P<]*`]:!#*80"`0"AR[(.:73X8$,R#`&$PQN\!9O[>2C?G +M77[81Y5()L=!Z!$&6T$&1Q@0]!&JH"?8#79-5I?%1P.*9K(@\(0#AEUY +ME$(8$(P%.Z!0F64&&4B@0,(5!86Z'E?F$*H=1B/@AA0``*C,0=!A-X5,H%L)B +M76%!`!96A>(=5B85NAQ:8?#W#@(`K,Q`$&J$A6-A7?A?!1EQH4`P%Z*%'-[* +MY14*!&=ATC>2>6H9X4G88\`R`T')01?:A8RA=A5D((8"@6+(%\)X*U=>:'.T +MA2^AJI4!YEP;(,_E`:Z"+^`:!&=-2`(!:=@8GH:X59!A&@(`>41)6!BJ>*Z@ +M6D?#Q8(9WPU'"Z9!I15DJ',@0;C,0!!1+(:H87`(3@49O:%`\!M.AOJ>@[4: +MMH81X2+68_`R`X%E`1P*A]2A315D0(<"@72('$Y\6U1Q*'1@AK?A6`;,#`09 +MQG18'9Z'^%B+4!"4A]LAWN=@88=&!WCX_Z%ZQ,Q`T&F8A^AA?MA-!1GUH4!P +M'[:'K*"#-1X*!.RA8.B5V6I68:B&S`P$(0=^J!\^B+-4D+$@"@0-(H`8&KI3 +M_:'3(1\*A3379CB`=88QFC*&_%V((>"`)!"8B!!BBFA+!1DH(@!01[B&\)\E +M&!N"9BNADE8;-GKSH2>51TV(4@<2!,T,!`V%@Z@B#HF\4Y#Q(PH$0:*%Z`1B +M3BWBB]@<,F$``#4S$$@60B*1:"6^95%B04`E*HE@(.9T)&H=&V*"N-AA,P-! +MA5$E7HEH(OP49)")`H&9R"7*@9B3E"@0;(D&(EM'&,:(RV"/P*;^/BMB06!FU@G`F(+77*(!($S`T''X2<"BI1BX11D0(H" +M@:1H*%J"@F)!4"@NBO<;GG@2>HC%F"9(U7&"&*&HJ-+!6?"10-`J5HJP8I'X +M'A4$<02,2`">A#-BNP8+LH0W8NO'(=:"`0"FJ'8@0>C,0)!03(JQ8K(85@$` +MQ:)`<"QNBLM@D/$JSHK&WYUX*[Z%[,Q`X%@@B\IBM[@+!1G9HD"P+4*+)V&0 +MT2S*'6%B6ABJP3,#083!+7J+\&+[$V2PBP*!NT@NJGC@8D$P+H**G)Q)^!;2 +M,P-!I?$NQHL$8UH39`",`H'`>"_Z>```O1@0V(O\(G/G+PYBC9!`D'$,C`5C +MQLBA!!D58T!P,2Z,(1O"&!`HC!'C\2?QN8>78'DW^9UWE5]5)R*>C`$BG,4= +M"00SH\9H,]YF`$#-F#,RA(Y4##C-77RK7Z\X"^:(&5!IU3$"`!E'CP'0#`0% +M!<9X,SZ-UD.0L30*!$TCR!CJZ8QM1+6((*J+BQU!,Q`H%DXCU"@V0A!!AMF8.6)REF-`@#DJ +MCDN?F*@93H0MVLHHY[6,J.++&#IVB<%<'H4<"03#8^IH/$X004;Q"`"D$;8B +MW(@K^HRHW^<(X#E%`AYER/%A*ZQC0%!Q]!@8S4`04)R.QV/XN!X$&=VC0/`] +MOHYDFO+(/#Z)A1Q',Q`8%N"C^"@_,$V2'BCM,:B&CY^8Z@H>AXYP4`M)%`$$2ND$2D;@4`#)%'9`?9"D*/*N&N +M:"-V71K?KX@;YE$N9$`04<:='1D0&!'\I%L'HF8]_$T`T&B,4@6DICD)#E?`34#0<-Q26:2K*1Q$&2@D@*!*OE)8DZ< +M9$#@29*2(Z(/>3J1BH+9&[5#SG$PHRD)9WE&`@$QV4H>DZP:`&!,*I-*),7' +M1+Z":QVO"$7:AD1CSU!:P9(!0 +M!]4,!`&&/$E/'I2S09`Q4`H$!:4^Z4[=DP%!/OE/_HYP(JI'U0P$A89!B5!N +ME*Y!D'%1"@09I4-9Y2V4`4%#.5'VD'YDD8?5#`0)AT;)4;Z4J4&0L5(*!"VE +M2+E6?90!04AY4DZ,$F'DU^_ICO_>165!P%<*EJKB(!9H$`2!!F*I6&Z6 +MD4&0<5D.!)DE9`D`-)8"P6-)6>:-;%K!01`4')HE9^E:,@9!AFHY$+"6HN5G +M*1"$EJ>E\ZCB\9(9G&?8"0Z6-5H>)1>U'J]E<5D;!!G#I4!`%_65N6)_UY71 +MAM,DCBA%ZHC8BFPI$!0E=IF\VR'8)52*7!<%RF5L>A7&C +M74$0V!7=Y7?I7OH%089Z.1"PEZ*E=CD0<)?L(\267Q`$^45[^5[^EWE!D+%? +M#@3]I6@I7PH$].5YN17&C7T&0=!G^)<`9H1)%P09#>9`\&"*E@.F0%!@*IAN +MX2`6$*6&.F&]!D/%A#@0AIFA980H$%R:'F1G>D#XE10A46H2\(]VV +M.*J1>%L>M14-!#LFB>EC:@9!1H^9>D"5S67JEVC9@"YA>%@TYE$GID`07$$0R!54II5I9H8%08:8 +M.1"0F:)EEBD0;)DNII)Y4M47!$%]46:>F7@F5Q!DT)D#@9TI6JJ9`@&;&6=6 +MDWE?GD$0Y!EW9IZI:%X%08:A.1`@FJ(EGRD0^)F#YG19Y/4;!$&_D6@NFIRF +M5!!D8)H#@:8I6CJ:`@&D66EBE6Y>C)D[9H(LXR9H8]:08*9HF$<%1:1'IVEK +M%@9!!JTI$`Q%S.4S*1OZ=]*D54E-6IK69!X%:@H$_4:/<4X0!.?$IGEK/IL] +M09"Q;`X$S:9HJ6L&!+SFJ6E#TGQN!4'@5CB;T&:X210$&=WF0/!MBI;3I@OR +M9>*8J%Y\01#$%^"FN"EO_@1!AKLY$,";HF6Y*1"HF7@*1`,GF4G7`D`M!D$09O1 +M>#Z>H&=&MWD6!)ZG:"EY"@249^89(")! +MJJ71SE-2T7L:7PV!4$&'#00R$%.)SWD5N9`4V=` +M$!`1FUJ4I*)#$`0ZQ#2%!PU#C)H?Q'U^G^!G^%D('4(!@#I0$)B?!L'1>#0> +MGW=E+[1!B)_P9_QI0MR8CB+[:7]F!T'&]3D09)^BI?))>*R;CJ*D<@(-!-J$ +M]@E^OD[>I_RI@"Z@\"?YR0X4!`]H^ED0K)_WYU+I?OY"#&@&"@RA33AGU:GS +M5:`@:-)9@IA`\E<'JG,Z6/JG0,!_YIX!I=$9@KZ@KL&-`*(,!#<#$":#V@P$ +M%%9!HHA9'Z.!>$.HARB*F+4^&H@'#V5CA$HV2*B3`H,NH7+!C5"G$`1U"F1U +M(\0I8I;KN"AB%7D*09"G3%,_*!/JA4H0-T(6.A!LH39H:5,01*'/%E;1IQ`$ +M?0H76M9\H7!H`W$CK*$#01M:AHJA`@$9>H4"`(`*00"HN*%]6!PJB#8/-T(? +M.A#\H64H'2H0V*%[Z*!"$`PJ@.@@*HE2#S>"(SH00*)EJ"$J$""B>ZBA0A`8 +M*I'H)"J*X@LW@B@L*HS:!S>"+SH0`*-EJ"TJ$."B>^BC0A`\*L'H,"J- +MQ@@X*H^>!S>".SH0P*-EJ#DJ$*"C>RBF0A!@*O'H/"J0B@VBH0A"$*B'I2"J33@E0*I4F +M!S>"4SH00*5EJ%$J$""E>ZCF@:9H65WH5"J6/@?BQ`CD`@F.56E!@)7NH:T* +M(A65CJ5P*7!P([2EZ)04&J+X'7\85A&KB%DAPEL:E_ZEN\&-L)=J$'UI&4J7 +M)@EYJ0\T`O$0?BE@ZIC:!C="K2)F,:9EZ&"*)!2F>^A(I$$4$8WI8^J9Q@8W +M@F:*&YE0D>EBFH,"`+R*F'5-=*:?:6O*&MP(J:D&L9J6H:*IHW2:9D$:!#?! +MFKJFO.EI<"/@IDB";EJ&QJ9(PFRZAQ(K8A8YL9OVILRI:+""C$#*:1D*G)X( +MPND>BJR(62S"=0>,T`F6G92ARJD%$IWLHLR)FL0S:*7>JGF(&-X)Y +MJD&@IV7H=:I!@*=[*+0B9KD3Z>EZJI].!C>"?:I!X*=EJ'N*),"G>RBU(F;- +M$_GI?JJ@.@8W@H&J02"H9:A_BB0`J'LHMB)FW1,)ZH*JH28&-X*%JD%@J&6H +M@XHD0*A[J"BD0>P3&>J&JJ(2!C>"B8HDH*AEJ(>*)("H>RBX(F;]$RGJBJJC +M_@4W@HVJ0>"H9:B+>B+`J'LHN2)F#10YZHZJI.H%-X*1JD$@J66HCXHD`*E[ +M*+HB9AT42>J2JJ76!3>"E:I!8*EEJ).*)$"I>RB[(F8M%%GJEJJFP@4W@IFJ +M0:"I9:B7BB2`J7LHO")F/11IZIJJIZX%-X*=JD'@J66HFXHDP*E[*+TB9DT4 +M>>J>JJB:!3>"H:I!(*IEJ)^*)`"J>RB^(F;-"(GJHJJIA@4W@J6J06"J9:BC +MBB1`JGLHOR)F<129ZJ:JJG(%-X*IJD&@JF6HIXHD@*I[*,`B9M4(J>JJJJM> +M!3>"K:I!X*IEJ*N*),"J>RC!(F:1%+GJKJJL2@4W@K&J02"K9:BOBB0`JWLH +MPB)FP0S)ZK*JK38%-X*UJD%@JV6HLXHD0*M[*,,B9K$4V>JVJJXB!3>"N:I! +MH*MEJ+>*)("K>RC$(F;)#.GJNJJO#@4W@KVJ0>"K9:B[BB3`JWLHQ2)FT13Y +MZKZJL/H$-X+!JD$@K&6HOXHD`*Q[*,8B9D6=GJ.[%I8NK!RK5W`C6*P:!,9J +M#]&``$##.@)!K'LHQR)F\10):\?JLM8$-X+*JD&PK&4HR(HDB*R,D<^)58`L +M8M8*T;*^K$`K3'`C\*P:A,]:ALJL2`+-NH>2+&)6!_&S!JU0ZTIP(S"M&H33 +M6H82K4B"T;J'HBQBEL/PM$:M8*M)<"-PK1J$UUJ&4JU(@M6ZA[(L8M;FE+%Z +M8AMKV"JW)@4W`MNJ0;BM(RLL6+(J"2.0V;J'PBQB%O3D@[ZA&O."FQB%32+F!4\#:Z!J.&JN3*LP-,(=+DRKK/AWIJX +M(@F+:]X:36(5.(N8!4-AKIMKZQH4W`BIJP:QNH*N_MW>6KEJ$)^KZ:JSPA.\CVL:R*`LIILW#`"9;*,+%*%5;PM8I:3%\LB";FL+XLB8!5WBYCE;`VSQ.PD>R-$ +MLQK$-)O*'K,:1#+KS.ZQ>XN8]6Y1L]4L('LCA+,:Q#B;RF*S2((V^\UB%7^+ +MF/5PD;/EK!M[(\2S&L0\F\JBLTB".OO.%EPCD,M%S]:S7.R-,+B(60)M*HO/ +M(@GZ[#][N(A9&-<62]`2LS?"0ZM!1+3;ZT&K022T_^SB(F;]70/M1'O#W@@> +MK08!TJ:R%BV2@-'JL5C%XR)F>5XAK4A+PMX(+JT&`=.FLB4MDG#2_K.3BYC5 +M>\6T,NT#>R/TM!K$3YO*UK1(PDW[SUXN8M;V!=0&M?CKC<#4:A!.;2I+U"() +M1NT_N[F(6?G74PO5DJ\WPE:K072UJ>Q4BR14M?_LYR)FD5\2[5<;R`(Y(Q!; +MN[V*M4@"6?O/CBYBUA'FU;JUU>N-@-=J$'IM*JO6:A!R+4O[A8U`/]A>R]<" +MKS?"Z2)F);:I[%^+)`2V_^SJ(F8]86WM8MO%0A4C$&:[O3JV&@1D^\^^+F(6 +M)W;&-K":[4AK,(Q`IJTSN[=:MAJ$9VO8SBYBEBYVVHJPJ:T->R/0MAJ$;>O: +MW@BDK0;1V@JQ&^SM(F:A8IEM;JO:&K<:!'*[O?*V2()O2]RV5UC%[B)F$63) +MK7([T_8-(Q!VN[TRMTB"B.0MQJ$>?O;,0%N9?7O?ZK8#KIA5X+ZW +M^BV2P-\&N(VLV#`"Y66*[8$+MMX(RXN81>&FLL>+@GN:/B]BUEF6W5JX8"U9 +M-@*)N-MKAJM!;+C_[/0B9@%G%2Z)&[3>""ZN!@'CIK(@K@:!XAJVUXN8I9W% +MN#+NRWHC]+@:Q(^;RM:X2,*-^\]N+V(6?0;D!KD=ZXW`Y&H03FXJ2^0B"4;N +M/_N]B%D/VI,+Y2ZL-\*6JT%TN:GLE(LD5+G_[/@B9IUH7NZ7NZ_>"&JN!L'F +MIK)B+I)`YOZSYXN89:&-N&YNZWHCY+D:Q)Z[O<:Y2,*<^\^N+V(6D,;G]KF: +MZXV`Z&H0BN[V"N@B"8*N8?N^B%F!FH'+Z`:O-\*EJT%DNN_MHXLD1+J&[?PB +M9NEI;>ZFJZW>"*:N!H'JIK*>+I(`ZD*XKFSV-`()#E^KJKNDW@CWBYB%ZY:A +MK2Z2\.K^L_N+F,6LI;JZ[JYZ(Q2[&L2QF\KVNAK$K[N'_B](`J^VZ":[%RX` +M0.V>"-;N]LKL(@G.[C\KP(A9#!NRB^VJJC?"N*M!E+NI[+8;`'2[AJT!(V:5 +M;.;NN:NIW@CRK@9![Z:RZBZ2P.[^LPJ,F,6SU;OVKJ)Z(P2\&L3`F\KFNTC" +MOOO/.C!BUM1&\!:\>NJ-`/%J$!)O*HOP(@D*[S\KP8A9:]O$2_&JJ3?"QZM! +MA+RI[,6+)&2\_ZP%(V9M;=?NR!OE8FTC$,R[O9J\2`+*^\]J,&)6ZB;RRKR[ +M+NHV`OF\J:S+JT'8O(:M!R-F`6^:+M`+M=X(2J\&P?2^MSRO!D'T_K,BC)BE +MO?V\3J^.>B-DO1K$UIO*1KU(PM1+Z_ZR)HR81;\UO5VOD`L`I+T:Q-K[WH*] +M2(+8^\^J,&(6!,?VMKTS+]ZK0>B][RWZ@1(V:UL`8!`I>A +M%C"2@`'_LUJ,F-742<`B\%]Z([3`&L0+G,J6P$C"";R'>C%BUD\7\\;`!B]/ +M-P+YP-LK#8PDV,#_K!@C9B%V,#`0/);>"$JP!L$$I[(\L`9!!!NV9HR8Y=DU +MP4[P5'HC9,$:Q!:+)/>"(:P!H$( +MI[)^,.-QFMHQ8I9TIP(61I>(HP)3Z0W +MPBBL093"J>PFC"1TPH:M'R-FN7BF\"D\D-X(LK`&00NGLJHPDL`*_[."C)@E +MY-7"MO`\>B,$PQK$,)S*YL)(PB[\SQHR8A:61PP7P^/HC0`-:Q#2<"J+#",) +MRO`_J\B(65'>-$P-3Z,WPC>L083#J>PUC"1DP_^L(R-F>7F7\#B\H-X([K`& +M`0]OK^8PDH`._[.2C)@5Z,7#\O!^>B/TPQK$/[R]UL-(PCULV%HR8E:N)PX' +MQ+/HC<`0:Q`.<2I+$",)!K%AJ\F(6<_>0PP1CZ(WPD:L073$J>Q$C"14Q/^L +M)R-F(7L>\4<\B=X(*K$&P1*GLB(QDD`2_[.BC)CE[;7$+O$@>B/DQ!K$3IS* +MQL1(PDS\SYHR8M:Z!Q#WQ-CO#3,"*<7;*U",)`C%_ZPJ(V;%?#PQ4PR'W@A6 +ML0:!%:>R2+$&`14;MJZ,F(7T[;U:\3P,`)3%&L19_-YVQ4C"5_S/RC)B5M"7 +M%:?%3.B-0!=K$'9Q*LL6(PEN<>6+5=@R8E;6=Q?CQ3#HC4`8:Q"&<2J[%R,) +M??$_J\N(66_?88P8AZ`WPF2L053&J>QBC"0TQO^L+R-F&7Z6\65<@=X(HK$& +M01JGLIHQDL`9_[/"C)A5_"W%IC$%W"6-0+/Q]IH:(PFK\3]KS(A9OU]I7!NS +MGS?";ZQ!!,>I;&RL0>3&AJTR(V95?\+Q<&Q\W@C.L08!':>RQC&2@!S_L\Z, +MF)7^1QY(W3'&L1WG,I6QTC"=?S/2C-B5O\''H?'H.>-P!YK$.YQ*DL> +M(PGF\3]KS8A9"2!M#!\_P0#`?JQ!],?;ZWR,)-3'_ZPV(V8Q@>_Q?^QWW@@* +ML@;!(*>R`C*20"`;MMZ,F.4%-L@.-@")K$"IR*@LB(PDB\C]KSHA9@N"*S"(CG3?"C:Q!Y,BI[(N,),3( +M_ZPZ(V91@CKRCAQSW@A&L@:!)*>R/C*2`"3_L^Z,F(4(^L=*\B)<"(Y`5_+V +MVB0C"4_R/RO/B%G)8)*<)5N<-\*8K$&4R:ELE:Q!=,F&K3TC9FV#9O*93'#> +M"'*R!D$GI[)J,I+`)O^S^HR8U0[6R7:RO'DC!,H:Q*"_,_Z,V+6 +M/T@H%\KAYHT`*6L0DG(JBR@C"8KR/RO0B%D0X:1,*3^;-\*GK$&$RJGLI8PD +M9,K_K$$C9A&$6/*H;`PGA",0K+R]FLI(`JK\SRHT8A9)&"O+RM4PB30"^RO+(&02P;MA*-F$45-LO.LJ)Y +M(V3+&L2VG,I&RTC"M/S/6C1B5F"(%G?+0NF-@"YK$.KR>PLN(PGB\C^KT8A9 +M>R&WS"Z?F3?"O:Q!Y,NI[+N,),3+@C$`X-&(69*AOKPO6YDWPL&L023,J:R_ +MC"0`S/^L2"-F,8<*\\+\8]X(%K,&@3&GL@XSD@`Q_[,FC9AU'&;,&C.)>2.4 +MS!K$R9S*=LQ(PL?\SZHT8I9VB#*GS!+FC4`S:Q`VR=C.2@#?_LT*-F$4G&LV",SD< +M)8Y`C_-[6S@C"8?S/VO4B%F*(N0<.0^C-\+FK$%TSN]MXZQ!5,X%LU(C9GV* +MGO/G'!$#`*JS!L$ZO[>B,Y)`.A?,3HV8I2D&SJZS8GDCY,X:Q.Z".:S!H$^O[?>,Y(`/O^S7HV8!3&FS^JS +M('HCU,\:Q/W\WK;/2,+[7#"+-6(6R8@_Y\];,0!`0&L0!O1[RS\C"?YSY8M` +MZ[Y(XPC4@Z:R,ZA`4(/NH3Z*F)4U+L\3M/UY(W30&L0'O;WNH&_-:1JEB%EM +MXP$=0C?/`,`*K4&TT.\M"8TDF-"&K9@B9B6.+O0+_8+>"#JT!L%#O[]M%JU!A-$%\Q,Z$*"AVC,; +M/4_>"$&H!C&$8M`XZ!^680PI8A;_>,86H4EH(GV$+M(QBAXM-MX(A+0&84B_ +MMWTTDO!'?[,9AI4B9D&0AS0C[4DKTJ`T;NM(%XPW@B:M07#2[VTDC21,TA+T +M*/V8`@KM0`"@`%`!P@P`E`1``5\`I\`L4`I(0!$``F`(0\`2\$LG`43`$>!+ +M_PIY@A2P*P0!IH(O#05@")7"H<`$@`#/]!-@!1#3=4+W4`5``5``HD`%Q`F6 +M0C<]!20!6$"<,"?XTG8"GJ`G=`]Z`C--!20!0\`4`#=-"E.`+WTH.`$.R1#P +M31,!8<(00$U7`4*`KS`%]-*!@A%@*N5*_]1`=5`M5`_51'51;50? +MU4AU4JU4+]5,=5/M5#_54'54+55/U51U56U57]58=5:M56_57'57[55_U6!U +M6"U6C]5D=5EM5I_5:'5:K5:OU6QU6^U6O]5P=5PM5\_5='5=;5??U7AU7JU7 +M[]5\=5_M5__5@'5@+5@/UH1U86U8']:(=6*M6"_6C'5C[5@_UI!U9"U93]:4 +M=65M65_6F'5FK5EOUIQU9^U9?]:@=6@M6H_6I'5I;5J?UJAU:JU:K]:L=6OM +M6K_6L'5L+5O/UK1U;6U;W]:X=6ZM6^_6O'5O[5O_UL!U<"U<#]?$=7%M7!_7 +MR'5RK5POU\QU<^U6U>G]?H=7JM7J_7['5[[5Z_U_!U?"U?S]?T=7UM7]_7^'5^K5_O +MU_QU?^U?_]<`=H`M8`_8!':!;6`?V`AV@JU@+]@,=H/M8#_8$':$+6%/V!1V +MA6UA7]@8=H:M86_8'':'[6%_V"!VB"UBC]@D=HEM8I_8*':*K6*OV"QVB^UB +4O]@P=HPM8\_8-':-;6/?V#BVW0$` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_link_resolver.c b/external/bsd/libarchive/dist/libarchive/test/test_link_resolver.c new file mode 100644 index 000000000..8332c4f98 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_link_resolver.c @@ -0,0 +1,205 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/lib/libarchive/test/test_link_resolver.c,v 1.2 2008/06/15 04:31:43 kientzle Exp $"); + +static void test_linkify_tar(void) +{ + struct archive_entry *entry, *e2; + struct archive_entry_linkresolver *resolver; + + /* Initialize the resolver. */ + assert(NULL != (resolver = archive_entry_linkresolver_new())); + archive_entry_linkresolver_set_strategy(resolver, + ARCHIVE_FORMAT_TAR_USTAR); + + /* Create an entry with only 1 link and try to linkify it. */ + assert(NULL != (entry = archive_entry_new())); + archive_entry_set_pathname(entry, "test1"); + archive_entry_set_ino(entry, 1); + archive_entry_set_dev(entry, 2); + archive_entry_set_nlink(entry, 1); + archive_entry_set_size(entry, 10); + archive_entry_linkify(resolver, &entry, &e2); + + /* Shouldn't have been changed. */ + assert(e2 == NULL); + assertEqualInt(10, archive_entry_size(entry)); + assertEqualString("test1", archive_entry_pathname(entry)); + + /* Now, try again with an entry that has 2 links. */ + archive_entry_set_pathname(entry, "test2"); + archive_entry_set_nlink(entry, 2); + archive_entry_set_ino(entry, 2); + archive_entry_linkify(resolver, &entry, &e2); + /* Shouldn't be altered, since it wasn't seen before. */ + assert(e2 == NULL); + assertEqualString("test2", archive_entry_pathname(entry)); + assertEqualString(NULL, archive_entry_hardlink(entry)); + assertEqualInt(10, archive_entry_size(entry)); + + /* Match again and make sure it does get altered. */ + archive_entry_linkify(resolver, &entry, &e2); + assert(e2 == NULL); + assertEqualString("test2", archive_entry_pathname(entry)); + assertEqualString("test2", archive_entry_hardlink(entry)); + assertEqualInt(0, archive_entry_size(entry)); + + + /* Dirs should never be matched as hardlinks, regardless. */ + archive_entry_set_pathname(entry, "test3"); + archive_entry_set_nlink(entry, 2); + archive_entry_set_filetype(entry, AE_IFDIR); + archive_entry_set_ino(entry, 3); + archive_entry_set_hardlink(entry, NULL); + archive_entry_linkify(resolver, &entry, &e2); + /* Shouldn't be altered, since it wasn't seen before. */ + assert(e2 == NULL); + assertEqualString("test3", archive_entry_pathname(entry)); + assertEqualString(NULL, archive_entry_hardlink(entry)); + + /* Dir, so it shouldn't get matched. */ + archive_entry_linkify(resolver, &entry, &e2); + assert(e2 == NULL); + assertEqualString("test3", archive_entry_pathname(entry)); + assertEqualString(NULL, archive_entry_hardlink(entry)); + + archive_entry_free(entry); + archive_entry_linkresolver_free(resolver); +} + +static void test_linkify_old_cpio(void) +{ + struct archive_entry *entry, *e2; + struct archive_entry_linkresolver *resolver; + + /* Initialize the resolver. */ + assert(NULL != (resolver = archive_entry_linkresolver_new())); + archive_entry_linkresolver_set_strategy(resolver, + ARCHIVE_FORMAT_CPIO_POSIX); + + /* Create an entry with 2 link and try to linkify it. */ + assert(NULL != (entry = archive_entry_new())); + archive_entry_set_pathname(entry, "test1"); + archive_entry_set_ino(entry, 1); + archive_entry_set_dev(entry, 2); + archive_entry_set_nlink(entry, 2); + archive_entry_set_size(entry, 10); + archive_entry_linkify(resolver, &entry, &e2); + + /* Shouldn't have been changed. */ + assert(e2 == NULL); + assertEqualInt(10, archive_entry_size(entry)); + assertEqualString("test1", archive_entry_pathname(entry)); + + /* Still shouldn't be matched. */ + archive_entry_linkify(resolver, &entry, &e2); + assert(e2 == NULL); + assertEqualString("test1", archive_entry_pathname(entry)); + assertEqualString(NULL, archive_entry_hardlink(entry)); + assertEqualInt(10, archive_entry_size(entry)); + + archive_entry_free(entry); + archive_entry_linkresolver_free(resolver); +} + +static void test_linkify_new_cpio(void) +{ + struct archive_entry *entry, *e2; + struct archive_entry_linkresolver *resolver; + + /* Initialize the resolver. */ + assert(NULL != (resolver = archive_entry_linkresolver_new())); + archive_entry_linkresolver_set_strategy(resolver, + ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); + + /* Create an entry with only 1 link and try to linkify it. */ + assert(NULL != (entry = archive_entry_new())); + archive_entry_set_pathname(entry, "test1"); + archive_entry_set_ino(entry, 1); + archive_entry_set_dev(entry, 2); + archive_entry_set_nlink(entry, 1); + archive_entry_set_size(entry, 10); + archive_entry_linkify(resolver, &entry, &e2); + + /* Shouldn't have been changed. */ + assert(e2 == NULL); + assertEqualInt(10, archive_entry_size(entry)); + assertEqualString("test1", archive_entry_pathname(entry)); + + /* Now, try again with an entry that has 3 links. */ + archive_entry_set_pathname(entry, "test2"); + archive_entry_set_nlink(entry, 3); + archive_entry_set_ino(entry, 2); + archive_entry_linkify(resolver, &entry, &e2); + + /* First time, it just gets swallowed. */ + assert(entry == NULL); + assert(e2 == NULL); + + /* Match again. */ + assert(NULL != (entry = archive_entry_new())); + archive_entry_set_pathname(entry, "test3"); + archive_entry_set_ino(entry, 2); + archive_entry_set_dev(entry, 2); + archive_entry_set_nlink(entry, 2); + archive_entry_set_size(entry, 10); + archive_entry_linkify(resolver, &entry, &e2); + + /* Should get back "test2" and nothing else. */ + assertEqualString("test2", archive_entry_pathname(entry)); + assertEqualInt(0, archive_entry_size(entry)); + archive_entry_free(entry); + assert(NULL == e2); + archive_entry_free(e2); /* This should be a no-op. */ + + /* Match a third time. */ + assert(NULL != (entry = archive_entry_new())); + archive_entry_set_pathname(entry, "test4"); + archive_entry_set_ino(entry, 2); + archive_entry_set_dev(entry, 2); + archive_entry_set_nlink(entry, 3); + archive_entry_set_size(entry, 10); + archive_entry_linkify(resolver, &entry, &e2); + + /* Should get back "test3". */ + assertEqualString("test3", archive_entry_pathname(entry)); + assertEqualInt(0, archive_entry_size(entry)); + + /* Since "test4" was the last link, should get it back also. */ + assertEqualString("test4", archive_entry_pathname(e2)); + assertEqualInt(10, archive_entry_size(e2)); + + archive_entry_free(entry); + archive_entry_free(e2); + archive_entry_linkresolver_free(resolver); +} + +DEFINE_TEST(test_link_resolver) +{ + test_linkify_tar(); + test_linkify_old_cpio(); + test_linkify_new_cpio(); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_open_fd.c b/external/bsd/libarchive/dist/libarchive/test/test_open_fd.c new file mode 100644 index 000000000..5e118ad8f --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_open_fd.c @@ -0,0 +1,128 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_open_fd.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#if defined(_WIN32) && !defined(__CYGWIN__) +#define open _open +#if !defined(__BORLANDC__) +#define lseek _lseek +#endif +#define close _close +#endif + +DEFINE_TEST(test_open_fd) +{ + char buff[64]; + struct archive_entry *ae; + struct archive *a; + int fd; + +#if defined(__BORLANDC__) + fd = open("test.tar", O_RDWR | O_CREAT | O_BINARY); +#else + fd = open("test.tar", O_RDWR | O_CREAT | O_BINARY, 0777); +#endif + assert(fd >= 0); + if (fd < 0) + return; + + /* Write an archive through this fd. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_open_fd(a, fd)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 0); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * Write a second file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 819200); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Now, read the data back. + */ + assert(lseek(fd, 0, SEEK_SET) == 0); + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_fd(a, fd, 512)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); + assertEqualMem(buff, "12345678", 8); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(819200, archive_entry_size(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); + + /* Verify the end of the archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + close(fd); + + + /* + * Verify some of the error handling. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + /* FD 100 shouldn't be open. */ + assertEqualIntA(a, ARCHIVE_FATAL, + archive_read_open_fd(a, 100, 512)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_open_file.c b/external/bsd/libarchive/dist/libarchive/test/test_open_file.c new file mode 100644 index 000000000..871249d87 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_open_file.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_open_file.c 201247 2009-12-30 05:59:21Z kientzle $"); + +DEFINE_TEST(test_open_file) +{ + char buff[64]; + struct archive_entry *ae; + struct archive *a; + FILE *f; + + f = fopen("test.tar", "wb"); + assert(f != NULL); + if (f == NULL) + return; + + /* Write an archive through this FILE *. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_open_FILE(a, f)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 0); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * Write a second file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 819200); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + fclose(f); + + /* + * Now, read the data back. + */ + f = fopen("test.tar", "rb"); + assert(f != NULL); + if (f == NULL) + return; + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_FILE(a, f)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); + assertEqualMem(buff, "12345678", 8); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(819200, archive_entry_size(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); + + /* Verify the end of the archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + fclose(f); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_open_filename.c b/external/bsd/libarchive/dist/libarchive/test/test_open_filename.c new file mode 100644 index 000000000..07224cde1 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_open_filename.c @@ -0,0 +1,109 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_open_filename.c 191183 2009-04-17 01:06:31Z kientzle $"); + +DEFINE_TEST(test_open_filename) +{ + char buff[64]; + struct archive_entry *ae; + struct archive *a; + + /* Write an archive through this FILE *. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_open_filename(a, "test.tar")); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 0); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * Write a second file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 819200); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Now, read the data back. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, "test.tar", 512)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); + assertEqualMem(buff, "12345678", 8); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(819200, archive_entry_size(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); + + /* Verify the end of the archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Verify some of the error handling. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_FATAL, + archive_read_open_filename(a, "nonexistent.tar", 512)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_pax_filename_encoding.c b/external/bsd/libarchive/dist/libarchive/test/test_pax_filename_encoding.c new file mode 100644 index 000000000..5f1ac935c --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_pax_filename_encoding.c @@ -0,0 +1,333 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_pax_filename_encoding.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#include + +/* + * Pax interchange is supposed to encode filenames into + * UTF-8. Of course, that's not always possible. This + * test is intended to verify that filenames always get + * stored and restored correctly, regardless of the encodings. + */ + +/* + * Read a manually-created archive that has filenames that are + * stored in binary instead of UTF-8 and verify that we get + * the right filename returned and that we get a warning only + * if the header isn't marked as binary. + */ +static void +test_pax_filename_encoding_1(void) +{ + static const char testname[] = "test_pax_filename_encoding.tar"; + /* + * \314\214 is a valid 2-byte UTF-8 sequence. + * \374 is invalid in UTF-8. + */ + char filename[] = "abc\314\214mno\374xyz"; + struct archive *a; + struct archive_entry *entry; + + /* + * Read an archive that has non-UTF8 pax filenames in it. + */ + extract_reference_file(testname); + a = archive_read_new(); + assertEqualInt(ARCHIVE_OK, archive_read_support_format_tar(a)); + assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, testname, 10240)); + /* + * First entry in this test archive has an invalid UTF-8 sequence + * in it, but the header is not marked as hdrcharset=BINARY, so that + * requires a warning. + */ + failure("Invalid UTF8 in a pax archive pathname should cause a warning"); + assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); + assertEqualString(filename, archive_entry_pathname(entry)); + /* + * Second entry is identical except that it does have + * hdrcharset=BINARY, so no warning should be generated. + */ + failure("A pathname with hdrcharset=BINARY can have invalid UTF8\n" + " characters in it without generating a warning"); + assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &entry)); + assertEqualString(filename, archive_entry_pathname(entry)); + archive_read_finish(a); +} + +/* + * Set the locale and write a pathname containing invalid characters. + * This should work; the underlying implementation should automatically + * fall back to storing the pathname in binary. + */ +static void +test_pax_filename_encoding_2(void) +{ + char filename[] = "abc\314\214mno\374xyz"; + struct archive *a; + struct archive_entry *entry; + char buff[65536]; + char longname[] = "abc\314\214mno\374xyz" + "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" + "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" + "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" + "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" + "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" + "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" + ; + size_t used; + + /* + * We need a starting locale which has invalid sequences. + * de_DE.UTF-8 seems to be commonly supported. + */ + /* If it doesn't exist, just warn and return. */ + if (LOCALE_UTF8 == NULL + || NULL == setlocale(LC_ALL, LOCALE_UTF8)) { + skipping("invalid encoding tests require a suitable locale;" + " %s not available on this system", LOCALE_UTF8); + return; + } + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, 0, archive_write_set_format_pax(a)); + assertEqualIntA(a, 0, archive_write_set_compression_none(a)); + assertEqualIntA(a, 0, archive_write_set_bytes_per_block(a, 0)); + assertEqualInt(0, + archive_write_open_memory(a, buff, sizeof(buff), &used)); + + assert((entry = archive_entry_new()) != NULL); + /* Set pathname, gname, uname, hardlink to nonconvertible values. */ + archive_entry_copy_pathname(entry, filename); + archive_entry_copy_gname(entry, filename); + archive_entry_copy_uname(entry, filename); + archive_entry_copy_hardlink(entry, filename); + archive_entry_set_filetype(entry, AE_IFREG); + failure("This should generate a warning for nonconvertible names."); + assertEqualInt(ARCHIVE_WARN, archive_write_header(a, entry)); + archive_entry_free(entry); + + assert((entry = archive_entry_new()) != NULL); + /* Set path, gname, uname, and symlink to nonconvertible values. */ + archive_entry_copy_pathname(entry, filename); + archive_entry_copy_gname(entry, filename); + archive_entry_copy_uname(entry, filename); + archive_entry_copy_symlink(entry, filename); + archive_entry_set_filetype(entry, AE_IFLNK); + failure("This should generate a warning for nonconvertible names."); + assertEqualInt(ARCHIVE_WARN, archive_write_header(a, entry)); + archive_entry_free(entry); + + assert((entry = archive_entry_new()) != NULL); + /* Set pathname to a very long nonconvertible value. */ + archive_entry_copy_pathname(entry, longname); + archive_entry_set_filetype(entry, AE_IFREG); + failure("This should generate a warning for nonconvertible names."); + assertEqualInt(ARCHIVE_WARN, archive_write_header(a, entry)); + archive_entry_free(entry); + + assertEqualInt(0, archive_write_close(a)); + assertEqualInt(0, archive_write_finish(a)); + + /* + * Now read the entries back. + */ + + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_format_tar(a)); + assertEqualInt(0, archive_read_open_memory(a, buff, used)); + + assertEqualInt(0, archive_read_next_header(a, &entry)); + assertEqualString(filename, archive_entry_pathname(entry)); + assertEqualString(filename, archive_entry_gname(entry)); + assertEqualString(filename, archive_entry_uname(entry)); + assertEqualString(filename, archive_entry_hardlink(entry)); + + assertEqualInt(0, archive_read_next_header(a, &entry)); + assertEqualString(filename, archive_entry_pathname(entry)); + assertEqualString(filename, archive_entry_gname(entry)); + assertEqualString(filename, archive_entry_uname(entry)); + assertEqualString(filename, archive_entry_symlink(entry)); + + assertEqualInt(0, archive_read_next_header(a, &entry)); + assertEqualString(longname, archive_entry_pathname(entry)); + + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + +/* + * Create an entry starting from a wide-character Unicode pathname, + * read it back into "C" locale, which doesn't support the name. + * TODO: Figure out the "right" behavior here. + */ +static void +test_pax_filename_encoding_3(void) +{ + wchar_t badname[] = L"xxxAyyyBzzz"; + const char badname_utf8[] = "xxx\xE1\x88\xB4yyy\xE5\x99\xB8zzz"; + struct archive *a; + struct archive_entry *entry; + char buff[65536]; + size_t used; + + badname[3] = 0x1234; + badname[7] = 0x5678; + + /* If it doesn't exist, just warn and return. */ + if (NULL == setlocale(LC_ALL, "C")) { + skipping("Can't set \"C\" locale, so can't exercise " + "certain character-conversion failures"); + return; + } + + /* If wctomb is broken, warn and return. */ + if (wctomb(buff, 0x1234) > 0) { + skipping("Cannot test conversion failures because \"C\" " + "locale on this system has no invalid characters."); + return; + } + + /* If wctomb is broken, warn and return. */ + if (wctomb(buff, 0x1234) > 0) { + skipping("Cannot test conversion failures because \"C\" " + "locale on this system has no invalid characters."); + return; + } + + /* Skip test if archive_entry_update_pathname_utf8() is broken. */ + /* In particular, this is currently broken on Win32 because + * setlocale() does not set the default encoding for CP_ACP. */ + entry = archive_entry_new(); + if (archive_entry_update_pathname_utf8(entry, badname_utf8)) { + archive_entry_free(entry); + skipping("Cannot test conversion failures."); + return; + } + archive_entry_free(entry); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, 0, archive_write_set_format_pax(a)); + assertEqualIntA(a, 0, archive_write_set_compression_none(a)); + assertEqualIntA(a, 0, archive_write_set_bytes_per_block(a, 0)); + assertEqualInt(0, + archive_write_open_memory(a, buff, sizeof(buff), &used)); + + assert((entry = archive_entry_new()) != NULL); + /* Set pathname to non-convertible wide value. */ + archive_entry_copy_pathname_w(entry, badname); + archive_entry_set_filetype(entry, AE_IFREG); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); + archive_entry_free(entry); + + assert((entry = archive_entry_new()) != NULL); + archive_entry_copy_pathname_w(entry, L"abc"); + /* Set gname to non-convertible wide value. */ + archive_entry_copy_gname_w(entry, badname); + archive_entry_set_filetype(entry, AE_IFREG); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); + archive_entry_free(entry); + + assert((entry = archive_entry_new()) != NULL); + archive_entry_copy_pathname_w(entry, L"abc"); + /* Set uname to non-convertible wide value. */ + archive_entry_copy_uname_w(entry, badname); + archive_entry_set_filetype(entry, AE_IFREG); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); + archive_entry_free(entry); + + assert((entry = archive_entry_new()) != NULL); + archive_entry_copy_pathname_w(entry, L"abc"); + /* Set hardlink to non-convertible wide value. */ + archive_entry_copy_hardlink_w(entry, badname); + archive_entry_set_filetype(entry, AE_IFREG); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); + archive_entry_free(entry); + + assert((entry = archive_entry_new()) != NULL); + archive_entry_copy_pathname_w(entry, L"abc"); + /* Set symlink to non-convertible wide value. */ + archive_entry_copy_symlink_w(entry, badname); + archive_entry_set_filetype(entry, AE_IFLNK); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); + archive_entry_free(entry); + + assertEqualInt(0, archive_write_close(a)); + assertEqualInt(0, archive_write_finish(a)); + + /* + * Now read the entries back. + */ + + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_format_tar(a)); + assertEqualInt(0, archive_read_open_memory(a, buff, used)); + + failure("A non-convertible pathname should cause a warning."); + assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); + assertEqualWString(badname, archive_entry_pathname_w(entry)); + failure("If native locale can't convert, we should get UTF-8 back."); + assertEqualString(badname_utf8, archive_entry_pathname(entry)); + + failure("A non-convertible gname should cause a warning."); + assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); + assertEqualWString(badname, archive_entry_gname_w(entry)); + failure("If native locale can't convert, we should get UTF-8 back."); + assertEqualString(badname_utf8, archive_entry_gname(entry)); + + failure("A non-convertible uname should cause a warning."); + assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); + assertEqualWString(badname, archive_entry_uname_w(entry)); + failure("If native locale can't convert, we should get UTF-8 back."); + assertEqualString(badname_utf8, archive_entry_uname(entry)); + + failure("A non-convertible hardlink should cause a warning."); + assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); + assertEqualWString(badname, archive_entry_hardlink_w(entry)); + failure("If native locale can't convert, we should get UTF-8 back."); + assertEqualString(badname_utf8, archive_entry_hardlink(entry)); + + failure("A non-convertible symlink should cause a warning."); + assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); + assertEqualWString(badname, archive_entry_symlink_w(entry)); + assertEqualWString(NULL, archive_entry_hardlink_w(entry)); + failure("If native locale can't convert, we should get UTF-8 back."); + assertEqualString(badname_utf8, archive_entry_symlink(entry)); + + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &entry)); + + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + +DEFINE_TEST(test_pax_filename_encoding) +{ + test_pax_filename_encoding_1(); + test_pax_filename_encoding_2(); + test_pax_filename_encoding_3(); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_pax_filename_encoding.tar.uu b/external/bsd/libarchive/dist/libarchive/test/test_pax_filename_encoding.tar.uu new file mode 100644 index 000000000..47db18915 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_pax_filename_encoding.tar.uu @@ -0,0 +1,118 @@ +$FreeBSD: head/lib/libarchive/test/test_pax_filename_encoding.tar.uu 191183 2009-04-17 01:06:31Z kientzle $ +begin 644 test_pax_filename_encoding.tar +M4&%X2&5A9&5R+V%B8\R,;6YO6'AY>@`````````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````#`P,#8T-"``,#`Q-S4P(``P,#$W-3`@`#`P,#`P,#`P,38V +M(#$P-S8V-C`W,#,V(#`Q-3,P-@`@>``````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````!U@HR,"!C=&EM +M93TQ,C`U-3,X-C@U"C(P(&%T:6UE/3$R,#4U,S@V,C8*,3<@4T-(24Q9+F1E +M=CTX.`HR,B!30TA)3%DN:6YO/30S,34T-#D*,3@@4T-(24Q9+FYL:6YK/3$* +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````````````````````````````````````&%B8\R,;6YO6'AY +M>@`````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````P +M,#`V-#0@`#`P,3'EZ +M```````````````````````````````````````````````````````````` +M````````````````````````````````````````````,#`P-C0T(``P,#$W +M-3`@`#`P,3'EZ"C(P(&-T:6UE +M/3$R,#4U-#$W,S4*,C`@871I;64],3(P-34S.#8R-@HQ-R!30TA)3%DN9&5V +M/3@X"C(R(%-#2$E,62YI;F\]-#,Q-3$R-@HQ."!30TA)3%DN;FQI;FL],0H` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M````````````````86)CS(QM;F_\>'EZ```````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````````````````````#`P,#8T-"``,#`Q-S4P(``P,#$W-3`@ +M`#`P,#`P,#`P,#`U(#$P-S8V-C`W,#,V(#`Q,S4W,0`@,``````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````````````````````!U +M7ET='1S ${TMPRPM}/BUILD/file1 +echo "hello" > ${TMPRPM}/BUILD/file2 +echo "hello" > ${TMPRPM}/BUILD/file3 +cat > ${TMPRPM}/SPECS/${NAME}.spec < ${F}.uu + +rm -rf ${TMPRPM} +exit 1 +*/ + +DEFINE_TEST(test_read_format_cpio_svr4_bzip2_rpm) +{ + struct archive_entry *ae; + struct archive *a; + const char *name = "test_read_format_cpio_svr4_bzip2_rpm.rpm"; + int r; + + assert((a = archive_read_new()) != NULL); + r = archive_read_support_compression_bzip2(a); + if (r == ARCHIVE_WARN) { + skipping("bzip2 reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, r); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_rpm(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + extract_reference_file(name); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("./etc/file1", archive_entry_pathname(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("./etc/file2", archive_entry_pathname(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("./etc/file3", archive_entry_pathname(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + + /* Verify the end-of-archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify that the format detection worked. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); + assertEqualString(archive_compression_name(a), "bzip2"); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); + + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu new file mode 100644 index 000000000..884ca9487 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_bzip2_rpm.rpm.uu @@ -0,0 +1,47 @@ +begin 644 test_read_format_cpio_svr4_bzip2_rpm.rpm +M[:ONVP,``````7)P;7-A;7!L92TQ+C`N,"TQ```````````````````````` +M```````````````````````````````````````````!``4````````````` +M````````CJWH`0`````````%````5````#X````'````1````!````$-```` +M!@`````````!```#Z`````0````L`````0```^P````'````,````!````/O +M````!````$`````!,F4X-3)F-39E,#,W83EE.61A9C`````$```1F````!@```GX````!```$;``` +M``8```*``````0``!'0````$```"E`````,```1U````!````J`````#```$ +M=@````@```*L`````P``!'<````$```"Q`````,```1X````!````M`````# +M0P!R<&US86UP;&4`,2XP+C``,0!386UP;&4@9&%T82!O9B!24$T@9FEL=&5R +M(&]F(&QI8F%R8VAI=F4`4V%M<&QE(&1A=&$N`````$L)MWQC=64M9&5S:W1O +M<``````20E-$`%5NFEP,@`Y`&YO87)C:"UR<&TM;&EN=7@````````````````````````` +M`0````$````!`$%30TE)('1E>'0`9&ER96-T;W)Y```````````````````` +M````````````````````/P````?___SP````$$)::#DQ05DF4UFX89DX``!= +M?X!,$`@`*`'_X"(D%``[9(0`(`"2B/50T#0#0`](9!%(C1,0&GJ`R`M@PQRG +M ${TMPRPM}/BUILD/file1 +echo "hello" > ${TMPRPM}/BUILD/file2 +echo "hello" > ${TMPRPM}/BUILD/file3 +cat > ${TMPRPM}/SPECS/${NAME}.spec < ${F}.uu + +rm -rf ${TMPRPM} +exit 1 +*/ + +DEFINE_TEST(test_read_format_cpio_svr4_gzip_rpm) +{ + struct archive_entry *ae; + struct archive *a; + const char *name = "test_read_format_cpio_svr4_gzip_rpm.rpm"; + int r; + + assert((a = archive_read_new()) != NULL); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, r); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_rpm(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + extract_reference_file(name); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("./etc/file1", archive_entry_pathname(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("./etc/file2", archive_entry_pathname(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("./etc/file3", archive_entry_pathname(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + + /* Verify the end-of-archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify that the format detection worked. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_GZIP); + assertEqualString(archive_compression_name(a), "gzip"); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); + + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu new file mode 100644 index 000000000..54d305b77 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4_gzip_rpm.rpm.uu @@ -0,0 +1,46 @@ +begin 644 test_read_format_cpio_svr4_gzip_rpm.rpm +M[:ONVP,``````7)P;7-A;7!L92TQ+C`N,"TQ```````````````````````` +M```````````````````````````````````````````!``4````````````` +M````````CJWH`0`````````%````5````#X````'````1````!````$-```` +M!@`````````!```#Z`````0````L`````0```^P````'````,````!````/O +M````!````$`````!9&9E8V,W,#4T,C@X,V1D-&8P-6%E.#4Y,S6QO861&:6QE +MFEP`#D`;F]A``````````````` +M```````!`````0````$`05-#24D@=&5X=`!D:7)E8W1O@$!@"1O'?9"`(````` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4c_Z.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4c_Z.c new file mode 100644 index 000000000..d3f086bbd --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_cpio_svr4c_Z.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_cpio_svr4c_Z.c 189381 2009-03-05 00:31:48Z kientzle $"); + +static unsigned char archive[] = { +31,157,144,'0','n',4,132,'!',3,6,140,26,'8','n',228,16,19,195,160,'A',26, +'1',202,144,'q','h','p','F',25,28,20,'a','X',196,152,145,' ',141,25,2,'k', +192,160,'A',163,163,201,135,29,'c',136,'<',201,'2','c','A',147,'.',0,12,20, +248,178,165,205,155,20,27,226,220,201,243,166,152,147,'T',164,4,'I',194,164, +136,148,16,'H',1,'(',']',202,180,169,211,167,'P',163,'J',157,'J',181,170, +213,171,'X',179,'j',221,202,181,171,215,175,'L',1}; + +DEFINE_TEST(test_read_format_cpio_svr4c_Z) +{ + struct archive_entry *ae; + struct archive *a; +/* printf("Archive address: start=%X, end=%X\n", archive, archive+sizeof(archive)); */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + failure("archive_compression_name(a)=\"%s\"", + archive_compression_name(a)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + failure("archive_format_name(a)=\"%s\"", archive_format_name(a)); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_CRC); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +#endif +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_empty.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_empty.c new file mode 100644 index 000000000..98cfdfa26 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_empty.c @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_empty.c 189308 2009-03-03 17:02:51Z kientzle $"); + +static unsigned char archive[] = { 0 }; + +DEFINE_TEST(test_read_format_empty) +{ + struct archive_entry *ae; + struct archive *a; + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_open_memory(a, archive, 0)); + assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); + assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE); + assertA(archive_format(a) == ARCHIVE_FORMAT_EMPTY); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_gz.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_gz.c new file mode 100644 index 000000000..3071b1d0b --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_gz.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_gtar_gz.c 191183 2009-04-17 01:06:31Z kientzle $"); + +static unsigned char archive[] = { +31,139,8,0,'+','e',217,'D',0,3,211,211,'g',160,'9','0',0,2,'s','S','S',16, +'m','h','n','j',128,'L',195,0,131,161,129,177,177,137,129,137,185,185,161, +'!',131,129,161,129,153,161,'9',131,130,')',237,157,198,192,'P','Z','\\', +146,'X',164,160,192,'P',146,153,139,'W',29,'!','y',152,'G','`',244,'(',24, +5,163,'`',20,12,'r',0,0,226,234,'6',162,0,6,0,0}; + +DEFINE_TEST(test_read_format_gtar_gz) +{ + struct archive_entry *ae; + struct archive *a; + int r; + + assert((a = archive_read_new()) != NULL); + assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_GZIP); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_lzma.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_lzma.c new file mode 100644 index 000000000..0e8ff32e5 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_lzma.c @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2008 Miklos Vajna + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_gtar_lzma.c 191183 2009-04-17 01:06:31Z kientzle $"); + +static unsigned char archive[] = { +0x5d, 0x0, 0x0, 0x80, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +0x17, 0xb, 0xbc, 0x1c, 0x7d, 0x1, 0x95, 0xc0, 0x1d, 0x4a, 0x46, 0x9c, +0x1c, 0xc5, 0x8, 0x82, 0x10, 0xed, 0x84, 0xf6, 0xea, 0x7a, 0xfe, 0x63, +0x5a, 0x34, 0x5e, 0xf7, 0xc, 0x60, 0xd6, 0x8b, 0xc1, 0x47, 0xaf, 0x11, +0x6f, 0x18, 0x94, 0x81, 0x74, 0x8a, 0xf8, 0x47, 0xcc, 0xdd, 0xc0, 0xd9, +0x40, 0xa, 0xc3, 0xac, 0x43, 0x47, 0xb5, 0xac, 0x2b, 0x31, 0xd3, 0x6, +0xa4, 0x2c, 0x44, 0x80, 0x24, 0x4b, 0xfe, 0x43, 0x22, 0x4e, 0x14, 0x30, +0x7a, 0xef, 0x99, 0x6e, 0xf, 0x8b, 0xc1, 0x79, 0x93, 0x88, 0x54, 0x73, +0x59, 0x3f, 0xc, 0xfb, 0xee, 0x9c, 0x83, 0x49, 0x93, 0x33, 0xad, 0x44, +0xbe, 0x0}; + +DEFINE_TEST(test_read_format_gtar_lzma) +{ + int r; + + struct archive_entry *ae; + struct archive *a; + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("lzma reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + + assertEqualIntA(a, ARCHIVE_OK, r); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + r = archive_read_open_memory2(a, archive, sizeof(archive), 3); + if (r != ARCHIVE_OK) { + skipping("Skipping LZMA compression check: %s", + archive_error_string(a)); + goto finish; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_LZMA); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); +finish: +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +#endif +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse.c new file mode 100644 index 000000000..d055fc249 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse.c @@ -0,0 +1,318 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_gtar_sparse.c 189308 2009-03-03 17:02:51Z kientzle $"); + + +struct contents { + off_t o; + size_t s; + const char *d; +}; + +struct contents archive_contents_sparse[] = { + { 1000000, 1, "a" }, + { 2000000, 1, "a" }, + { 3145728, 0, NULL } +}; + +struct contents archive_contents_sparse2[] = { + { 1000000, 1, "a" }, + { 2000000, 1, "a" }, + { 3000000, 1, "a" }, + { 4000000, 1, "a" }, + { 5000000, 1, "a" }, + { 6000000, 1, "a" }, + { 7000000, 1, "a" }, + { 8000000, 1, "a" }, + { 9000000, 1, "a" }, + { 10000000, 1, "a" }, + { 11000000, 1, "a" }, + { 12000000, 1, "a" }, + { 13000000, 1, "a" }, + { 14000000, 1, "a" }, + { 15000000, 1, "a" }, + { 16000000, 1, "a" }, + { 17000000, 1, "a" }, + { 18000000, 1, "a" }, + { 19000000, 1, "a" }, + { 20000000, 1, "a" }, + { 21000000, 1, "a" }, + { 22000000, 1, "a" }, + { 23000000, 1, "a" }, + { 24000000, 1, "a" }, + { 25000000, 1, "a" }, + { 26000000, 1, "a" }, + { 27000000, 1, "a" }, + { 28000000, 1, "a" }, + { 29000000, 1, "a" }, + { 30000000, 1, "a" }, + { 31000000, 1, "a" }, + { 32000000, 1, "a" }, + { 33000000, 1, "a" }, + { 34000000, 1, "a" }, + { 35000000, 1, "a" }, + { 36000000, 1, "a" }, + { 37000000, 1, "a" }, + { 38000000, 1, "a" }, + { 39000000, 1, "a" }, + { 40000000, 1, "a" }, + { 41000000, 1, "a" }, + { 42000000, 1, "a" }, + { 43000000, 1, "a" }, + { 44000000, 1, "a" }, + { 45000000, 1, "a" }, + { 46000000, 1, "a" }, + { 47000000, 1, "a" }, + { 48000000, 1, "a" }, + { 49000000, 1, "a" }, + { 50000000, 1, "a" }, + { 51000000, 1, "a" }, + { 52000000, 1, "a" }, + { 53000000, 1, "a" }, + { 54000000, 1, "a" }, + { 55000000, 1, "a" }, + { 56000000, 1, "a" }, + { 57000000, 1, "a" }, + { 58000000, 1, "a" }, + { 59000000, 1, "a" }, + { 60000000, 1, "a" }, + { 61000000, 1, "a" }, + { 62000000, 1, "a" }, + { 63000000, 1, "a" }, + { 64000000, 1, "a" }, + { 65000000, 1, "a" }, + { 66000000, 1, "a" }, + { 67000000, 1, "a" }, + { 68000000, 1, "a" }, + { 69000000, 1, "a" }, + { 70000000, 1, "a" }, + { 71000000, 1, "a" }, + { 72000000, 1, "a" }, + { 73000000, 1, "a" }, + { 74000000, 1, "a" }, + { 75000000, 1, "a" }, + { 76000000, 1, "a" }, + { 77000000, 1, "a" }, + { 78000000, 1, "a" }, + { 79000000, 1, "a" }, + { 80000000, 1, "a" }, + { 81000000, 1, "a" }, + { 82000000, 1, "a" }, + { 83000000, 1, "a" }, + { 84000000, 1, "a" }, + { 85000000, 1, "a" }, + { 86000000, 1, "a" }, + { 87000000, 1, "a" }, + { 88000000, 1, "a" }, + { 89000000, 1, "a" }, + { 90000000, 1, "a" }, + { 91000000, 1, "a" }, + { 92000000, 1, "a" }, + { 93000000, 1, "a" }, + { 94000000, 1, "a" }, + { 95000000, 1, "a" }, + { 96000000, 1, "a" }, + { 97000000, 1, "a" }, + { 98000000, 1, "a" }, + { 99000000, 1, "a" }, + { 99000001, 0, NULL } +}; + +struct contents archive_contents_nonsparse[] = { + { 0, 1, "a" }, + { 1, 0, NULL } +}; + +/* + * Describe an archive with three entries: + * + * File 1: named "sparse" + * * a length of 3145728 bytes (3MiB) + * * a single 'a' byte at offset 1000000 + * * a single 'a' byte at offset 2000000 + * File 2: named "sparse2" + * * a single 'a' byte at offset 1,000,000, 2,000,000, ..., 99,000,000 + * * length of 99,000,001 + * File 3: named 'non-sparse' + * * length of 1 byte + * * contains a single byte 'a' + */ + +struct archive_contents { + const char *filename; + struct contents *contents; +} files[] = { + { "sparse", archive_contents_sparse }, + { "sparse2", archive_contents_sparse2 }, + { "non-sparse", archive_contents_nonsparse }, + { NULL, NULL } +}; + +static void +verify_archive_file(const char *name, struct archive_contents *ac) +{ + struct archive_entry *ae; + int err; + /* data, size, offset of next expected block. */ + struct contents expect; + /* data, size, offset of block read from archive. */ + struct contents actual; + const void *p; + struct archive *a; + + extract_reference_file(name); + + assert((a = archive_read_new()) != NULL); + assert(0 == archive_read_support_compression_all(a)); + assert(0 == archive_read_support_format_tar(a)); + failure("Can't open %s", name); + assert(0 == archive_read_open_filename(a, name, 3)); + + while (ac->filename != NULL) { + struct contents *cts = ac->contents; + + if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) { + assert(0 == archive_read_finish(a)); + return; + } + failure("Name mismatch in archive %s", name); + assertEqualString(ac->filename, archive_entry_pathname(ae)); + + expect = *cts++; + while (0 == (err = archive_read_data_block(a, + &p, &actual.s, &actual.o))) { + actual.d = p; + while (actual.s > 0) { + char c = *actual.d; + if(actual.o < expect.o) { + /* + * Any byte before the expected + * data must be NULL. + */ + failure("%s: pad at offset %d " + "should be zero", name, actual.o); + assertEqualInt(c, 0); + } else if (actual.o == expect.o) { + /* + * Data at matching offsets must match. + */ + assertEqualInt(c, *expect.d); + expect.d++; + expect.o++; + expect.s--; + /* End of expected? step to next expected. */ + if (expect.s <= 0) + expect = *cts++; + } else { + /* + * We found data beyond that expected. + */ + failure("%s: Unexpected trailing data", + name); + assert(actual.o <= expect.o); + archive_read_finish(a); + return; + } + actual.d++; + actual.o++; + actual.s--; + } + } + failure("%s: should be end of entry", name); + assertEqualIntA(a, err, ARCHIVE_EOF); + failure("%s: Size returned at EOF must be zero", name); + assertEqualInt((int)actual.s, 0); +#if ARCHIVE_VERSION_NUMBER < 1009000 + /* libarchive < 1.9 doesn't get this right */ + skipping("offset of final sparse chunk"); +#else + failure("%s: Offset of final empty chunk must be same as file size", name); + assertEqualInt(actual.o, expect.o); +#endif + /* Step to next file description. */ + ++ac; + } + + err = archive_read_next_header(a, &ae); + assertEqualIntA(a, ARCHIVE_EOF, err); + + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif +} + + +DEFINE_TEST(test_read_format_gtar_sparse) +{ + /* Two archives that use the "GNU tar sparse format". */ + verify_archive_file("test_read_format_gtar_sparse_1_13.tar", files); + verify_archive_file("test_read_format_gtar_sparse_1_17.tar", files); + + /* + * libarchive < 1.9 doesn't support the newer --posix sparse formats + * from GNU tar 1.15 and later. + */ +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("read support for GNUtar --posix sparse formats"); +#else + /* + * An archive created by GNU tar 1.17 using --posix --sparse-format=0.1 + */ + verify_archive_file( + "test_read_format_gtar_sparse_1_17_posix00.tar", + files); + /* + * An archive created by GNU tar 1.17 using --posix --sparse-format=0.1 + */ + verify_archive_file( + "test_read_format_gtar_sparse_1_17_posix01.tar", + files); + /* + * An archive created by GNU tar 1.17 using --posix --sparse-format=1.0 + */ + verify_archive_file( + "test_read_format_gtar_sparse_1_17_posix10.tar", + files); + /* + * The last test archive here is a little odd. First, it's + * uncompressed, because that exercises some of the block + * reassembly code a little harder. Second, it includes some + * leading comments prior to the sparse block description. + * GNU tar doesn't do this, but I think it should, so I want + * to ensure that libarchive correctly ignores such comments. + * Dump the file, looking for "#!gnu-sparse-format" starting + * at byte 0x600. + */ + verify_archive_file( + "test_read_format_gtar_sparse_1_17_posix10_modified.tar", + files); +#endif +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu new file mode 100644 index 000000000..86a59ffa4 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu @@ -0,0 +1,1370 @@ +$FreeBSD: head/lib/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu 191183 2009-04-17 01:06:31Z kientzle $ +begin 644 test_read_format_gtar_sparse_1_13.tar +M``````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````!UF4],S$T-371E71E71E71E$AE861E``````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````!UF4],S$T-3$AE861E``````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````!U``````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````````````````````!U +MF4].3DP,#`P,#$*,C`@ +M871I;64],3$Y.#(Y,S8P,PHR,"!C=&EM93TQ,3DX,CDS-C`Q"@`````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M`"XO1TY54W!A``````````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````!U``````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````!U``````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````````````````````!U +MF4].3DP,#`P,#$*,C`@ +M871I;64],3$Y.#(Y,S8P,PHR,"!C=&EM93TQ,3DX,CDS-C`Q"@`````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M`"XO1TY54W!A``````````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````!U/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1G@0#`6!Z-&!``1`XH$((`"``@4I,$%"%0PD`@`7%%2C +MB@*IF,8"!UR``0O@"!#0B0=V:.212":IY)),-NGDDU!&*>645%9IY952-K%$ +M$E,\8<04('#Y!`@YV&`##"\@\24(1B3!1!%39#$%%45H*$05;A)1A!0@F`#" +MA44,\804#PK8@A0O$&%%H5(4$005@X*`PA`I@!!##CG,`$(1+F3Q1!5.'$%$ +M$&]*2JFEF-X`@A(N0.&H%%TZ\0*K4PR!A)M,)!$JEKSVRJL,!-800PPPW"## +M##+04,,-!((#+`S"$FLLLLHR"P,X!&:K[;8$`O!LM,4>F^RRS1;IZ[GHIJON +MNNRVZ^Z[\,8K+Y/_U;O8/P(2:*"]_/;K[[\`!UR=EDF`T,0;;H#@Q!MV0*CJ +ML3HDJ\.R('RK0!MKI#''&V;,4;$+,+B@:0MO@$!'&7/0T8*"89#QA1EOR-%& +M&'2XH'')80BL\\X\]^SSSV<=6..00!=M]-%()ZWTTDPW[?334$?=&XD!U4BU +MU%AGK?767'?M]==@ARWVV%K/./1`-PZD(X\^`BEDB4,>:+:-`.`8T-H]_A@D +MT26:2/;?@`N^>:<=^[Y +MYZ"'+OKHI)=N^NFHIZ[ZZJRW[OKKL,O_/+,-^_\\]!'+_WTU%=O_?789Z_]]MQW[_WWX(BGK_[Z[+?O_OOPQR___/37;__]^.>O__[\]^___P`,H``'2,`"&O"`]`,` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_gz.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_gz.c new file mode 100644 index 000000000..822b969e3 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_gz.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_iso_gz.c 201247 2009-12-30 05:59:21Z kientzle $"); + +DEFINE_TEST(test_read_format_iso_gz) +{ + struct archive_entry *ae; + struct archive *a; + const char *name = "test_read_format_iso.iso.Z"; + + extract_reference_file(name); + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, name, 512)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet.iso.Z.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet.iso.Z.uu new file mode 100644 index 000000000..4642fece1 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet.iso.Z.uu @@ -0,0 +1,66 @@ +$FreeBSD: head/lib/libarchive/test/test_read_format_iso_joliet.iso.Z.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_read_format_iso_joliet.iso.Z +M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$PDX4056(#@X(,01BBA +MA`)*\403$V:HX8,'X5*0AQX="$``(AZ(``(`6%"0!10DI*)`(@#`04$SHB@0 +MBD8$(,"!`1`@0$`E'KCAD$06:>212":IY)),-NGDDU!&*>645#YY1!%.)#'% +M$TDT$<25(&CY!`@YV&`##"\@8<04(!B1!!-%3)'%%%04@>$04A01!!5/2`$" +M"D.D`$(,.>0P`PA%N)#%$U4X<0010<#Y9Z"#%GI#"S(0:`,(2K@`A9Y2;.G$ +M"YU.,002;R;HZ*2"9@J##9@2>`,(%2Z1!!4@U!D$AE7VZJN3KN8`0Z8TR!!# +M#3+,0`.!!`0[+`S%'IOLLC`00."UV&9+(`#.$FLLLLHR*^2OY)9K[KGHIJON +MNNRVZ^Z[2?XG[V(""$B@@0$Q`4`2`#@!0!4`8`$`"`,73/#!!B=,\!``$`&` +M%``\`4`3"E>,\,4=?EC""T5P%"20`)P(``8%84`R0AH,%*,'!;%L8T`XZLBC +MCR"/*"+&.%NL<\X\[^QSST#_+'301`]M=-%('ZUTTDPO[7334#\M-<9'`-"Q +MO_Q.$?&^$P,0!`!5=TQPUEL3G`,`-J`-``P`?`$`$@`8`8#6!,O-K[X=:YW% +MW`!08777"S_\]]=^2PPQP2@`P'`*!<<`P-EGSU!PQRX`L+?$`/M;M<-?XSVU +MT9\7';K0W4+[[;3,EAXMN-1:J^WKVZI^>KC5C@OO[;CGKOONO/?N^^]'SBO\ +M8?_86Z"(PR>O_/+,-^_\\]!'+_WTU%=O?50'SE@S``,`T(%`!Q*1!,37EV_^ +M^>BGK_[Z[+?O_OOPQT\8\C*.&%#W`GT?@/CDR^___P`,H``'2,`"&O"`"$Q@ +M>P[$LNT9```?`%]`R`"`-`!`#@K,H`8WR,$.>O"#(`RA"$=(PJ'0CV4B>J!` +M(G@@"EH0@R6,H0QG2,,:VO"&.,RA#G<('D34CR`U&DC,=C0BFMG/9G.#P@$" +MX(MW/$P*!0A`(*"`!1($H!U?$T@0VH&_@0R`?D#Z$4$$0`4C:"``#L@1$7ND +MQIFU00`$J``-1$"`(12!`P$@&$'T6)!V]-$,/QQ($&\4-YD548Q!"H`4H"A% +M*EH1BP/98A<%\L6"Z*@@9#0C&MM81$[VZ(UQG",!```'[Q7D>R\+62'7:,02 +M#8!_BXQB(IS0!`2T,`UR<.05LQB0+8IQ($0DR"7'6,8SIM&0;$0F`4`I1SH" +M@`\`"$%!0J#"@1@@1Y6$HP1'M``D!$$*1%#5$ERP@QC$,@"S;$(##H2&,,B! +M#&Q(@QO6H$M2!&(@@2#%+P42S($,$YC%W&0`LDD`;!X(CLP4I26B.L_^"+H$<5EG<6O=`"0N@@2)8"J'^%F*/M"%%^060PE"S8)`E*#;#``$`(`& +M`(0AO11D0P4!X`8`K`$`7ECO0-I+D/=*-+X\`(!^W\!?`)P!`"T`@!H`P&#] +M6K`,`*`#A&6[7_UB.,+]O6\;`(#ARFD8PWC(,(V2NTOD*EOY +MREB67A&DT(X`*(`*A]AM$J#P!4+E(`9[0D(10&"A(2R!S4D@`I@45"J9"$(4P!"G`*PA36[&^F0406&&C56C" +MFI5M*FE#@4^S=G2I3YWJ9]/:2YR^:.6RS.YVN_O=2D%#&=A@4@7`^][XSK>^ +M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W +MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U +MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ +M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ +M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ +MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` +M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ +M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ +MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: +MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X +MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 +M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT +M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 +M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P +(&(_R.(_T:!4` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu new file mode 100644 index 000000000..030dd3cb2 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu @@ -0,0 +1,71 @@ +$FreeBSD: head/lib/libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_read_format_iso_joliet_long.iso.Z +M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1GA0+@6!Z-&!``1`XH$((`"`!@5I0$%"%@PD`@`<%%2C +MB@*I:$0``B10(@D"!'3B@1T6:>212":IY)),-NGDDU!&*>645%9I991-+)'$ +M%$\8,04(6SX!0@XVV`##"TAX"8(123!1Q!193$%%$1H*446;1!0A!0@F@'!A +M$4,\(<6#`K8@Q0M$6$&H%$4$086@(*`P1`H@Q)!##C.`4(0+63Q1A1-'$!&$ +MFY%.6NFE-X"@A`M0-"H%ETZ\L.H40R#1)A-)@'KEKKSN*@.!.<1`(`XPX!!# +M##7D0"`)O\(0[+#%'IOLL@16:^VU!`+0[+/%1HNLLC"00&2OY)9K[KGHIJON +MNNRVZ^Z[2_XG[V(""$B@@0$9`8`<`)31+P!"`#`%`$0``(+!"!^L<,((#T$P +M`%(`\`0`33"\\,46(VR0B`/E4L(+17`TI)``I`@`.`6!@T%"+`HTXP<%P8QC +M0#KRZ&,`0))<(HD8]YRQST#_+'301`]M=-%('ZUTTDPO[7334#\M==143VUU +MU557O`0`20@L,8)>']SUP!,?G`,`-J`-``P`?`$`$F`/?+"^73,!0,@#9^$U +M%7=3C'#`57`-@-T%AQSQP28T_'#$(3L\<<0%'^QPP2U`W/;#5CPLN>4A!W&U +MU)\W';K3VPK;K;'?+ELZM*A/&RZVL%>K+;"F$]LZN.(:#._NO/?N^^_`!R_\ +M\$K.:_QA_]A;((G'-^_\\]!'+WUQ628!`A5HU`'"$V/0`2$.(!2KP[$Z)`O" +MM@K(X$*!Z\<0A@V9MJ`$""VH\08;:91!1PMLO.'&&?2K0QK(4"GZG6&`YP.! +M"Q;X@C3,X0W3BZ`$)TC!"EK0*;B8P8%JI+.2`<`#`CE0#&0P`QK4P`8WP,$% +M5\C"%KKPA3",H0QG2,,:VO"&CF$>C4I$LX&`,``C+.$)4XC#(AKQB$A,HA*7 +MR,0F.O&)4+S/@6#606=HC(<`B(&V`#`#`-```#50VPT`H,*SL4V+,N"B%\$H +M1C("P(Q9W&(7OQC&M(VQC&N+8QKGR$8[NA&.:%0C'=N(QS/*<8UU!,`=WYC' +M0/(QD8L$Y"$'Z<="ZE&0?53D'QLYR4Q&,H]D`$`:]A7%4IKRE*A,I2I7R%[4@SE"D,WLJ3,3!4`*`1UH00^:T($PU*$$@6A!>%20BMHHHQOM +MZ$Y!*E($D-2D5;TJ`'#QP8*`<&8>].C-M=\RK$M/)UKG@MD%[]*MB^TK6P@/WK7A&[6#*D00XJ96D' +M"C)9@^B+(/K2!0!F1!`1&*`@!A#KCT(HI`78-:TNV$$,UAJ`MKXUKH8-[&D/ +M.UO9#I:VM[5M;!5+V-KR%K>[+6QD`U#9@73@L@,Q`G(%HB]";+8@G@6M:'%& +MVA(M``E!&!2NG+"$U*XVJ*YMP('0$`8YD`%_;EC#4`-`BD`,)!"DF*A`!!#1 +M$LDW(`+@K(R@RM'IDL"_)[5J2=M)X`*+<[U%76@[[@L`^BZ5P0(`(4$\P%^I +M?O2_4\4J2DFPWO:^-[Y-K2]3"9)?Z%;8OP#.ZH`-S.(6N_C%\JJIA'V(TQ[Z +M]YXC8RU!#8I0A0:$H1`6,81G+!`*:[2_&0[P594\X)I:5"#RS.F->VHB'2/8 +MQP`XZD.%W-0G!P2C1[;P6)FL80&3`,9H3K.:UYR9E\6LQF'-,(Z%="`W$T1F +M\]3IA>>\LP#`X[F=_2Q!0IOAZ@;`BMNL)C2I.4QM1O.8S!2F-(.I3$A/4]*6 +MIC0VNWE-;EHST8V.=*6S*6H`_/E@!#D86.DY5CX?NM.*=C2C)PWK4%]ZU)P& +M-:UUG>E:[_K1I+[UIC\-;$Y_DY1IU*_+!#T00E_8T!```!H`$`92AI(-H@1` +M3=?`YFY[^]M!"("YFI,4:A4$4!T<"AAZ5*"8 +M``*,/\$*#7\3"*90!2A`05!46!.D3CZ%)&!A36TZ.)SD1*>1TZGB5$C"$*8` +M!3<%80H'#Y03J!"$(:2<"%L:0L>K(`1<3<'@>S("I'@.J"2P:0B.2L(3G#!R +M3TU\4Q`"^L69[G2H@RE/0[=Z$O0$)JYC/`E-R&X60&"%)S"A"DTX>)YH]6\H +M/"KJD!(ZT8W>=JE+(>XYW[H+[,WXQCO^\4%!0QG8T#\%0/[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ +M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ +MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` +M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ +M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ +MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: +MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X +MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 +M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT +M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 +M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P +M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. +M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L +MV9(N^9(P&9,R.9,T69,V>9,XF9,ZN9,\V9,^^9-`&91".91$691&>91(F91* +MN91,V91.^910&952.9546956>958F95:N95^95@&99B.99D699F>99H +MF99JN99LV99N^99P&9=R.9=T69=V>9=XF9=ZN9=\V9=^^9>`&9B".9B$69B& +4>9B(F9B*N9B,V9B.^9B0&9F2J90` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet_rockridge.iso.Z.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet_rockridge.iso.Z.uu new file mode 100644 index 000000000..9f1dd09c7 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_joliet_rockridge.iso.Z.uu @@ -0,0 +1,68 @@ +$FreeBSD: head/lib/libarchive/test/test_read_format_iso_joliet_rockridge.iso.Z.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_read_format_iso_joliet_rockridge.iso.Z +M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1G@0+@6!Z-&!``1`XH$((`"`!0590$%"+`HD`@`<%%2C +MB@*I:$0``B10(@D"!'3B@1T6:>212":IY)),-NGDDU!&*>645%9I991-+)'$ +M%$\8,04(6SX!0@XVV`##"TAX"8(123!1Q!193$%%$1H*446;1!0A!0@F@'!A +M$4,\(<6#`K8@Q0M$6$&H%$4$086@(*`P1`H@Q)!##C.`4(0+63Q1A1-'$!&$ +MFY%.6NFE-X"@A`M0-"H%ETZ\L.H40R#1)A-)@'KEKKSN*@.!.<1`(`XQU""# +M##340"`)O\(0[+#%'IOLL@16:^VU!`+0[+,P$&LLLLK"0`*1O99K[KGHIJON +MNNRVZ^Z[\"[YW[R+"2`@@08&9`0`<@!0AK\`"`'`%``0`0`(!R>,\,(*)SQ$ +MP0!(`<`3`#31,,,87YRP02(.A$L)+Q3!T9!"`I`B`!@4A$'*"&DPT(P>%!0S +MC@'IR*./`0!927BQP$ +MUE.#[K3H3V\K;+?1@KNLZ=!^.ZVXV,9>K;;`GNZMM.&.>W"\O/?N^^_`!R_\ +M\,0K2>_QA_US;X$D(N_\\]!'+_WTQ669!`A4H%$'"$^,00>$.%1:@P['ZI`L +M"-LJ((,+!;(?0Q@V9-J"$B"T4$<:9%1:_QGXHP^""P!\01KF\`;J&?"`"$R@ +M`A>X%5QHX$`UVAD`!@"`#@CD0$1(@L08R,$.>O"#(`RA"$=(PA*:\(0HE$SS +M:%2B@%!0(!8,0`8WF,(:VO"&.,RA#G?(PQ[Z\(=`U,^!8B9!`P#@`Q<,"!D` +MD`9^!?&)4(RB%*=(Q2I:\8I8S*(6H;+"F)'(B`)!XH&6V,1^;?&,:$RC&M?( +MQC:Z\8UPC"-[(,%"@MQH(#;KT8^"U$*>#0P*!PB`+]X1,2D4(`"!@`(66!"` +M=GQ.($%HQPL',H`5"HF/`Q%`!`?"`2H8X8$.V)$><]8&!2#@`19H`0E*>!``!!&$%H6I!VW=$,=.6DR/"+H9GO1)4(H29ZLT)2I5R*A@02Q(LUY>,YA]#,``9EC,0R;" +M"4U`P!C3(`=D-O*1`8DD)@4B`$N6:)\!$8`%"=*!:@8@E,#,V3E)J4U7`H`0 +M``A!04(`QH$88*'?%.8"D!"$0>'*"4MPP0YBT,X`O+,)#3@0&L(@!S*P(0UN +M6(,]21&(@02"%``%0#^AF5,!2)0@(3`H0D=)`HQVTY6>B.A$*RJ0BR8TH^ET +M`!.>`*HO*.$)3'#!G+`PTD*Z$YXC.!`;WN"&,[1`#6]X:1GHT`(SI($-96B! +M&\+0AC*X@`YEP`,=W`K7F=94(#?MJ3^C21"?3E2HJ0U6)"@#`XQ^0C2P\ +M#H+1))9(`7!JPD=#VM62-@*>##C0'/+0AI?&U)[M",5`0M&.P0ZVIX^-+&3A +M,04FE(!$'AAK6<^:UC2LM:UOC>M2A.[,$PN48_*S<5^4Y>;%,@=<_1+ +MHG972";Z+FKQ"0!F%N29!"%L)N,;D$Y^\J"*C2YTO5G=!COXP1!N#8!YHP06:VW:?>EV6N]S$+[/-L;*=+66?6F,'`&`. +M`,@#`,A\92`#0,@1#K2@!TWHHPJ"`%74TCUGHP`J6\#*@EL&H*C +MDD!58WO*UIN"T+AU[6YXRQM,>3(WOI.@)S`Y`=BB;D)'LP`"*V"U"DU0=9YH +M)6HH/&K>D"KWN=/M<'I+0>+I8S[K6M\[U +MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ +M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ +M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ +MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` +M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ +M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ +MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: +MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X +MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 +M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT +M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 +M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P +M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. +M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L +.V9(N^9(P&9,R.9,T^8(` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_multi_extent.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_multi_extent.c new file mode 100644 index 000000000..3ec472dab --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_multi_extent.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_iso_multi_extent.c 201247 2009-12-30 05:59:21Z kientzle $"); + +DEFINE_TEST(test_read_format_iso_multi_extent) +{ + const char *refname = "test_read_format_iso_multi_extent.iso.Z"; + struct archive_entry *ae; + struct archive *a; + const void *p; + size_t size; + off_t offset; + int i; + + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_compression_all(a)); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* Retrieve each of the 2 files on the ISO image and + * verify that each one is what we expect. */ + for (i = 0; i < 2; ++i) { + assertEqualInt(0, archive_read_next_header(a, &ae)); + + if (strcmp(".", archive_entry_pathname(ae)) == 0) { + /* '.' root directory. */ + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt((int)size, 0); + } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { + /* A regular file. */ + assertEqualString("file", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(262280, archive_entry_size(ae)); + assertEqualInt(0, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(0, offset); + assertEqualMem(p, "head--head--head", 16); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else { + failure("Saw a file that shouldn't have been there"); + assertEqualString(archive_entry_pathname(ae), ""); + } + } + + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify archive format. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); + + /* Close the archive. */ + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_multi_extent.iso.Z.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_multi_extent.iso.Z.uu new file mode 100644 index 000000000..79100f077 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_multi_extent.iso.Z.uu @@ -0,0 +1,67 @@ +$FreeBSD: head/lib/libarchive/test/test_read_format_iso_multi_extent.iso.Z.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_read_format_iso_multi_extent.iso.Z +M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1GB0#0<*%(`-'X48@(D`((````H4I``%"5DPD`@`<%"0 +MC2L*M*(1`0B0```!D"!`0"8>V.&12":IY)),-NGDDU!&*>645%9IY9583LE$ +M$D($(<402"1A11$@)#'%$R#D8(,-,(!@1!),%#%%%E-0482&5TB1A)U29.GG +MGX`&*FB2,A"80PP%WD!@#&PJ"@,)A<)P:**+-DH@"01FJNFF!`(0Z:0Q.,HH +M#(Z28.2@J*:JZJJLMNKJJ[#&*FN5_]6ZF``"+AJB$0#(`4`9OP(@!`!3`$`$ +M`"`@JVRRS"ZK[!#&`B`%`$\`T(2SS6:+K;(&@3C0B"6\4`1'11*9XHHM$J0` +M!@EI,",`'104;XX![=CCCT$."221(6KK[[;_!@SPP`(73/#!!B>,\,(*-\SP +MPPY'#/'$$E=,\<466\P$`$D("T`0T@(`+1(<`V`%`.,FVW&QU2:;`P`DD@B# +MLKQVO/&XQ69!+`!4H&RMLE>$W''/XTZ;,<9('ZUMT@\SK?"GB(9:*:F70DUI +M@98^RNG6F7IJ:-2B9FTJLK.6;?;9:*>M]MILIVWKVX?]DVN!(<)M]]UXYZWW +MWL4EX801:$X1!AT@/#$&X:&"0*`.C.I`*@B?*L!&&F*$(<<8:*1A1QF0NW"# +M"SD0&`8(:O_/+,-^_\\]"#5G>-^T9O_?789Z_]]MQW[_WWX(>O]X'Q#B_^ +M^>BGK_[Z[+?O_OOPQR__5]/'._W\^.>O__[\]^___P`,H`#S`PGJ$01'`[&7 +MCX`DI.&=B%A0.$``?/$.:4FA``$(!!2PP((`M`%D`@E"&_0U$`'<#T@D%(@` +MA#<0#E#!"!H(@`-XM,`@T1!?)&B#`B(```@<@`1#*`('`N"!@A31(.TH2#O< +M8,`6IBB!"+H7`_55I`!(X8(9W&`'/S@0$:8P("8L2(\*LL(;O3"&,Y2B#=68 +MPQWV\(<`X`,`/E`0.N+#1/B(8@U)``@''N!-<7+!#F)P10PFP@E-2,"!S)"& +MU&DQ2($82"#&1I`'5O*+`!``'0GR@3/*\(8,!&60=,A#'Y)`CEXH2"KO2*0\ +MBI*/?@1D$01)2"P>,I&+;&09'DF"2`IDDB>TY+> +M$@"=*$@G$`&!@4``$:\4$9'^"*=9#K*0`;BE(@'`2$=R$)*2I.2W@DG,:!*D +M$\E\)3/=:,H!VO.>^'P+C,(0GL`$KV+("DD@@IQ`,(4J0`$*3Y`" +M%=P45Z\^80I)P(*;NLE6.ME)0U.XTU:ID(0A3`$*<0I"8$$P5B=0(0A#F"L1 +MS#0$KU9!"%N:@E/[!+@^';8(0TC"FX;`U"0\P0EL?4(5OC1+"`663%"X;&8W +M6R:U.E:T2?!IF5#[U20TP4M9`($5R%J%)I!)K5,8@E'#RMFZ-O:QD=UM9W]+ +MV-.Z@*?8S:YVM]L7-)0A#&1H00N\"U[QDC>\X_TN>L]K7O6&X;WPC:]\YTO? +M^7+WOOC-KW[WR]_^^O>_``ZP@`=,X`(;^,`(3K""%\S@!COXP1".L(0G3.$* +M6_C"&,ZPAC?,X0Y[^,,@#K&(1TSB$IOXQ"A.L8I7S.(6N_C%,(ZQC&=,XQK; +M^,8XSK&.=\SC'OOXQT`.LI"'3.0B&_G(2$ZRDI?,Y"8[^_G+8`ZSF,=,YC*;^,ZSGO?,YS[[^<^`#K2@!TWH0AOZT(A.M*(7S>A&._K1D(ZTI"=-Z4I;^M*8 +MSK2F-\WI3GOZTZ`.M:A'3>I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. +MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV +MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ +M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W +MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U +MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ +M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ +M]\`/?FOJ2_SBTY<.86BD>)&O_!8PGPW+3S[TG2_]Z#=2^-C/OO:WS_WN>__[ +MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` +M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ +M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ +MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: +MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X +MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 +M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT +M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 +M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P +M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. +0^9`0&9$2.9$469$6>9%O"``` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge.iso.Z.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge.iso.Z.uu new file mode 100644 index 000000000..5f06cb3ab --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge.iso.Z.uu @@ -0,0 +1,206 @@ +$FreeBSD: head/lib/libarchive/test/test_read_format_iso_rockridge.iso.Z.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_read_format_iso_rockridge.iso.Z +M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1GA0#Q@,A$$/'QT(0``F'H@``@!84)`%$R14P4`B`'!! +M03>R*!"+1@0@0`(GDB!`0"D>V.&12":IY)),-NGDDU!&*>645%9IY9583MG$ +M$DE,\8014X#0Y1,@Y&"##3"\@`28(!B1!!-%3)'%%%04H:$05;Q)1!%2@&`" +M"!<6,<034CPH8`M2O$"$%89*44005!`*`@I#I`!"##GD,`,(1;B0Q1-5.'$$ +M$4'`.6FEEV9Z`PA*N`#%HU)XZ<0+K4XQ!!)O,I&$J%GVZFNO,A"8`PPYR'`# +MIC'4,$.P,)#`[+#%'IM#LLL22`*!V&:K+8$`/$NLL<@JRRP)1OYJ[KGHIJON +MNNRVZ^Z[\,;;Y'_T+O:/@`0:6.^^_/;K[[\`5[=E$B!,48<;!9-B(TX`J!C0#SZ"&0`0NY\XH%30'%` +M`+Z\`X`44A000"!08$%N.T$,%$0[5P\TP-0"^5B0`%08H4$`#O3X8Y!M)+#! +M!`^`0$+GGX=.PA!%2)1*((N."$&QX` +MXHHS7M#C!4E.$.668Z[YW*-[#KKHI$]/`@!P^%Q0B&^[C:#<0>Z>X@!;_QY` +M(DXT@<"!9*0A1^&')R[0XKL/)`#D1-8O$/.79PX^W<_CG/1,!P`Z`$`#!=$` +M%<+`BX#P(@R5^]_U[!:``[@)3B[800S,A[XF).!`9D@#&\H`OP"0(A`#"00I +M]!>0^R6/A0#@G_,D&$"Z5<]T?#A@`A?80``\,(*YFR#O3K0`)`2A4+IRPA(R +MN,'`G2]]#3@0&L(@!S*P(0UN6$,)3YC"%4X.?R>"H0S]%\0:1J]THC,$`$ZA +M,ZJ=XB!FC!R1%""G)B1QB1K\FQ,;D3X&'&@.>6C#%;-8PG:$8B"A:`<84?3" +MR4V!"0LP$0%".,+*]:]'`P"2`$B`24V>T7IK8^-`+O!&@]Q0='(D8AWO*`,F +MFH^/38@B```I2"RN00:%/*1`$KG(18KQD7[T'@`&0(X3B'P,YR#7,()>(5&3R?.E()CA` +M10$AIC$)``!D.D"9^!R@Z!CQS%%*DR#*3&4`MID%.W:3!N`4'"QE20Z#G,8AZS>??4YS*I)U)']%,@I(2C!`5*4(,JL08) +M#`&8'3:KAU7MFY.O= +M`F"^X,6O>(WC65D-"U(S)I:``(3JM`$V^[)5JZ%0J3Z*ZGWQG>^&?:O%#I\W@.[ +MP+0XSK&.=QPS-)2!#6QX@P)X3.0B&_G(2$ZRDI?,Y"8[^_G+8`ZSF,=,YC*;^,ZSGO?,YS[[^<^`#K2@!TWH0AOZT(A.M*(7S>A&._K1D(ZTI"=-Z4I;^M*8 +MSK2F-\WI3GOZTZ`.M:A'3>I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. +MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV +MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ +M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W +MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U +MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ +M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ +M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ +MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` +M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ +M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ +MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: +MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X +MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 +M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT +M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 +M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P +M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. +M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L +MV9(N^9(P&9,R.9,T69,V>9,XF9,ZN9,\V9,^^9-`&91".91$691&>91(F91* +MN91,V91.^910&952.9546956>958F95:N95^95@&99B.99D699F>99H +MF99JN99LV99N^99P&9=R.9=T69=V>9=XF9=ZN9=\V9=^^9>`&9B".9B$69B& +M>9B(F9B*N9B,V9B.^9B0&9F2.9F469F6>9F8F9F:N9F^9F@&9JB.9JD +M69JF>9JHF9JJN9JLV9JN^9JP&9NR.9NT69NV>9NXF9NZN9N\V9N^^9O`&9S" +M.9S$69S&>9S(F9S*N9S,V9S.^9S0&9W2.9W469W6>9W8F9W:N9W^9W@ +M&9[B.9[D69[F>9[HF9[JN9[LV9[N^9[P&9_R.9_T69_V>9_XF9_ZN9_\V9_^ +M^9\`&J`".J`$6J`&>J`(FJ`*NJ`,VJ`.^J`0&J$2.J$46J$6>J$8FJ$:NJ$< +MVJ$>^J$@&J(B.J(D6J(F>J(HFJ(JNJ(LVJ(N^J(P&J,R.J,T6J,V>J,XFJ,Z +MNJ,\VJ,^^J-`&J1".J1$6J1&>J1(FJ1*NJ1,VJ1.^J10&J52.J546J56>J58 +MFJ5:NJ5^J5@&J9B.J9D6J9F>J9HFJ9JNJ9LVJ9N^J9P&J=R.J=T6J=V +M>J=XFJ=ZNJ=\VJ=^^J>`&JB".JB$6JB&>JB(FJB*NJB,VJB.^JB0&JF2.JF4 +M6JF6>JF8FJF:NJF^JF@&JJB.JJD6JJF>JJHFJJJNJJLVJJN^JJP&JNR +M.JNT6JNV>JNXFJNZNJN\VJN^^JO`&JS".JS$6JS&>JS(FJS*NJS,VJS.^JS0 +M&JW2.JW46JW6>JW8FJW:NJW^JW@&J[B.J[D6J[F>J[HFJ[JNJ[LVJ[N +M^J[P&J_R.J_T6J_V>J_XFJ_ZNJ_\VJ_^^J\`&[`".[`$6[`&>[`(F[`*N[`, +MV[`.^[`0&[$2.[$46[$6>[$8F[$:N[$^[$@&[(B.[(D6[(F>[(HF[(J +MN[(LV[(N^[(P&[,R.[,T6[,V>[,XF[,ZN[,\V[,^^[-`&[1".[1$6[1&>[1( +MF[1*N[1,V[1.^[10&[52.[546[56>[58F[5:N[5^[5@&[9B.[9D6[9F +M>[9HF[9JN[9LV[9N^[9P&[=R.[=T6[=V>[=XF[=ZN[=\V[=^^[>`&[B".[B$ +M6[B&>[B(F[B*N[B,V[B.^[B0&[F2.[F46[F6>[F8F[F:N[F^[F@&[JB +M.[JD6[JF>[JHF[JJN[JLV[JN^[JP&[NR.[NT6[NV>[NXF[NZN[N\V[N^^[O` +M&[S".[S$6[S&>[S(F[S*N[S,V[S.^[S0&[W2.[W46[W6>[W8F[W:N[W +M^[W@&[[B.[[D6[[F>[[HF[[JN[[LV[[N^[[P&[_R.[_T6[_V>[_XF[_ZN[_\ +MV[_^^[\`',`"/,`$7,`&?,`(G,`*O,`,W,`._,`0',$2/,$47,$6?,$8G,$: +MO,$_,$@',(B/,(D7,(F?,(HG,(JO,(LW,(N_,(P',,R/,,T7,,V?,,X +MG,,ZO,,\W,,^_,-`',1"/,1$7,1&?,1(G,1*O,1,W,1._,10',52/,547,56 +M?,58G,5:O,5_,5@',9B/,9D7,9F?,9HG,9JO,9LW,9N_,9P',=R/,=T +M7,=V?,=XG,=ZO,=\W,=^_,>`',B"/,B$7,B&?,B(G,B*O,B,W,B._,B0',F2 +M/,F47,F6?,F8G,F:O,F_,F@',JB/,JD7,JF?,JHG,JJO,JLW,JN_,JP +M',NR/,NT7,NV?,NXG,NZO,N\W,N^_,O`',S"/,S$7,S&?,S(G,S*O,S,W,S. +M_,S0',W2/,W47,W6?,W8G,W:O,W_,W@',[B/,[D7,[F?,[HG,[JO,[L +MW,[N_,[P',_R/,_T7,_V?,_XG,_ZO,_\W,_^_,\`'=`"/=`$7=`&?=`(G=`* +MO=`,W=`._=`0'=$2/=$47=$6?=$8G=$:O=$_=$@'=(B/=(D7=(F?=(H +MG=(JO=(LW=(N_=(P'=,R/=,T7=,V?=,XG=,ZO=,\W=,^_=-`'=1"/=1$7=1& +M?=1(G=1*O=1,W=1._=10'=52/=547=56?=58G=5:O=5_=5@'=9B/=9D +M7=9F?=9HG=9JO=9LW=9N_=9P'==R/==T7==V?==XG==ZO==\W==^_=>`'=B" +M/=B$7=B&?=B(G=B*O=B,W=B._=B0'=F2/=F47=F6?=F8G=F:O=F_=F@ +M'=JB/=JD7=JF?=JHG=JJO=JLW=JN_=JP'=NR/=NT7=NV?=NXG=NZO=N\W=N^ +M_=O`'=S"/=S$7=S&?=S(G=S*O=S,W=S._=S0'=W2/=W47=W6?=W8G=W:O=W< +MW=W>_=W@'=[B/=[D7=[F?=[HG=[JO=[LW=[N_=[P'=_R/=_T7=_V?=_XG=_Z +MO=_\W=_^_=\`'N`"/N`$7N`&?N`(GN`*ON`,WN`._N`0'N$2/N$47N$6?N$8 +MGN$:ON$_N$@'N(B/N(D7N(F?N(HGN(JON(LWN(N_N(P'N,R/N,T7N,V +M?N,XGN,ZON,\WN,^_N-`'N1"/N1$7N1&?N1(GN1*ON1,WN1._N10'N52/N54 +M7N56?N58GN5:ON5_N5@'N9B/N9D7N9F?N9HGN9JON9LWN9N_N9P'N=R +M/N=T7N=V?N=XGN=ZON=\WN=^_N>`'NB"/NB$7NB&?NB(GNB*ONB,WNB._NB0 +M'NF2/NF47NF6?NF8GNF:ONF_NF@'NJB/NJD7NJF?NJHGNJJONJLWNJN +M_NJP'NNR/NNT7NNV?NNXGNNZONN\WNN^_NO`'NS"/NS$7NS&?NS(GNS*ONS, +MWNS._NS0'NW2/NW47NW6?NW8GNW:ONW_NW@'N[B/N[D7N[F?N[HGN[J +MON[LWN[N_N[P'N_R/N_T7N_V?N_XGN_ZON_\WN_^_N\`'_`"/_`$7_`&?_`( +MG_`*O_`,W_`.__`0'_$2/_$47_$6?_$8G_$:O_$__$@'_(B/_(D7_(F +M?_(HG_(JO_(LW_(N__(P'_,R/_,T7_,V?_,XG_,ZO_,\W_,^__-`'_1"/_1$ +M7_1&?_1(G_1*O_1,W_1.__10'_52/_547_56?_58G_5:O_5__5@'_9B +M/_9D7_9F?_9HG_9JO_9LW_9N__9P'_=R/_=T7_=V?_=XG_=ZO_=\W_=^__>` +M'_B"/_B$7_B&?_B(G_B*O_B,W_B.__B0'_F2/_F47_F6?_F8G_F:O_F +M__F@'_JB/_JD7_JF?_JHG_JJO_JLW_JN__JP'_NR/_NT7_NV?_NXG_NZO_N\ +MW_N^__O`'_S"/_S$7_S&?_S(G_S*O_S,W_S.__S0'_W2/_W47_W6?_W8G_W: +MO_W__W@'_[B/_[D7_[F?_[HG_[JO_[LW_[N__[P'__R/__T7__V?__X +MG__ZO__\W__^__\`,``*P`%(``N@`3R`"#`!*L`%R``;H`-\@!`P`DK`"4@! +M*Z`%O(`8,`-JP`W(`3N@!_R`(#`$BL`12`)+H`D\@2@P!:K`%<@"6Z`+?($P +M,`;*P!E(`VN@#;R!.#`'ZL`=R`-[H`_\@4`P"`K!(4@$BZ`1/()(,`DJP27( +M!)N@$WR"4#`*2L$I2`6KH!6\@E@P"VK!+<@%NZ`7_()@,`R*P3%(!LN@&3R# +M:#`-JL$UR`;;H!M\@W`P#LK!.4@'ZZ`=O(-X,`_JP3W(!_N@'_R#@#`0"L)! +M2`@+H2$\A(@P$2K"1<@(&Z$C?(20,!)*PDE("2NA);R$F#`3:L)-R`D[H2?\ +MA*`P%(K"44@*2Z$I/(6H,!6JPE7("ENA*WR%L#`6RL)92`MKH2V\A;@P%^K" +M7<@+>Z$O_(7`,!@*PV%(#(NA,3R&R#`9*L-ER`R;H3-\AM`P&DK#:4@-JZ$U +MO(;8,!MJPVW(#;NA-_R&X#`3R/Z#$]JL?U +MR![;HWM\C_`Q/LK'^4@?ZZ-]O(_X,3_JQ_W('_NC?_R/`#)`"L@!22`+I($\ +MD`@R02K(!Z2/ +M_)%`,D@*R2%))(NDD3R22#))*LDER22;I)-\DE`R2DK)*4DEJZ25O))8,DMJ +MR2W));NDE_R28#),BLDQ22;+I)D\DV@R3:K)-#)/ZLD]R2?[I)_\DX`R4`K*04DH"Z6A/)2(,E$JRD7)*!NEHWR4D#)2 +M2LI)22DKI:6\E)@R4VK*3RLMY22_KI;V\E_@R7^K+?Z?O_)W`,W@* +MS^%)/(NG\3R>R#-Y*L_ER3R;I_-\GM`S>DK/Z4D]JZ?UO)[8,WMJS^W)/;NG +M]_R>X#-\BL_Q23[+I_D\G^@S?:K/]4I/ZZD]O:?X-)_JTWW*3_NI/_VG`#6@"M2!2E`+JD$]J`@UH2K4AZI/_:E`-:@*U:%*5(NJ +M43VJ2#6I*M6ERE2;JE-]JE`UJDK5J4I5JZI5O:I8-:MJU:W*5;NJ5_VJ8#6L +MBM6Q2E;+JED]JV@UK:K5M#6OZM6]RE?[ +MJE_]JX`UL`K6P4I8"ZMA/:R(-;$JUL7*6!NK8WVLD#6R2M;)2EDKJV6]K)@U +MLVK6SRZMY/:_H-;VJU_7* +M7MNK>WVO\#6^RM?Y2E_KJWV]K_@UO^K7_ZVO_;7`-M@*VV%+;(NML3VVR#;9 +M*MMERVR;K;-]MM`VVDK;:4MMJZVUO;;8-MMJVVW+;;NMM_VVX#;`NOX3V\B#?Q*M[% +MRW@;K^-]O)`W\DK>R4MY*Z_EO;R8-_-JWLW+>3NOY_V\H#?TBM[12WI+K^D] +MO:@W]:K>UVNO[;V]N#?WZM[=RWM[K^_]O<`W^`K? +MX4M\BZ_Q/;[(-_DJW^7+?)NO\WV^T#?Z2M_I2WVKK_6]OM@W^VK?[[`/_L%`.`@+X2%,A(NP$3["2#@)*^$ES(2; +ML!-^PE`X"DOA*4R%J[`5OL)8.`MKX2W,A;NP%_["8#@,B^$Q3(;+L!D^PV@X +M#:OA-#@/Z^$]S(?[L!_^PX`X$`OB04R( +M"[$A/L2(.!$KXD7,B!NQ(W[$D#@22^))3(DKL26^Q)@X$VOB3/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1GC0+06!Z-&!``1`XH$((`"`!059,$%"%0PD`@`7%%2C +MB@*I:$0``B10(@D"!'3B@1T6:>212":IY)),-NGDDU!&*>645%9I991-+)'$ +M%$\8,04(6SX!0@XVV`##"TAX"8(123!1Q!193$%%$1H*446;1!0A!0@F@'!A +M$4,\(<6#`K8@Q0M$6$&H%$4$086@(*`P1`H@Q)!##C.`4(0+63Q1A1-'$!&$ +MFY%.6NFE-X"@A`M0-"H%ETZ\L.H40R#1)A-)@'KEKKSN*@.!.<10H`PQR%## +MKV;"0,*O,`0[;+''PI`L"016:^VU!`+`K+/%0HLL@200V>NXY)9K[KGHIJON +MNNRVZ^Z2_\6[V#\"$FB@O/CFJ^^^_/9;799)@-#$&VZ`\,08=%0J@\(Z'*N# +MM"!LJX`,+A18<0QAV)"IH2"T4$<:9%3:\1D@1PR""RB_D,8<;_CK\LLPQRSS +MS&G=0L^!-0HIT```9"#0@40D(07-1!=M]-%()ZWTTDPW[?334+]&8D`UDLBS +M0#X'$/3047?M]==@ARWVV&27;?;9:"<-"8TV`H!C0#KRZ&,`0.I,&VP3=.%#EQSHAT0^3IKJL!'X2\"!YI"'-L3`CH@+Q4!"T0X_ +MFJ@@/"J(`"(Y24G"8PI,$(.)`K`%*_KREV'`(@3I41!Z=*$@77CD.VHI2;\9 +MY)+KTV06FD"Q^=4/E$T0)0!(V089H+(=JA0(*UWI2D`"0`#+9.8[<*E+$_42 +MF/"4HC`)@L/(!<\+!?'"(]W!S'^XPY)IQ*0TFS`#3PH.F]KDY@R^&!``40E*0(QD$"0@IRP +M-*<`P$>0#1B2>KTC@2*UISK\+0"E_U,I2P7B4I@2)):4NR!!.G!31>Z4D:8# +M`/X4`-3^";6E+X5H3&4)1()\H*EI?&KJ3(?+(9"(!QJ5(5@'X",!+'*L;]T> +M`'!)!!+U(*UJU=PA`\#6<\95=3PEJYM(Y`.\YG5Z.^JK6P/[UZB2]+&0C:QD +M$W*[00ZDC+M#8TY_)Z0#U8]X=SQ>0!@GTXA2SK)8`VM.&*B1A"'ES4Q"FP-U` +M.8$*01B"?X-&*_E600BXFL)V]V0$2.4-4$E@TQ`+ISB).@)3"]N;Q*:$`0I9`$$5G@"$ZK0!.[FB592J.ZC2`PI"V-8 +MPT`NL12([&`7NZ"Y8`ZSF,>L'S24@0UL>$.E:C`#!9#YS7".LYSG3.,[S>\R,9C7'X%ANUK.@!TWH0AOZT(A.M*(7S6BO\#G-:XY!H!M-Z4I;^M*8 +MSK2F-\WI3GOZTZ`.M:A'3>I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. +MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV +MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ +M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W +MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U +MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ +M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ +M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ +MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` +M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ +M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ +MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: +MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X +MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 +(>(F8F(F:^!,` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge_new.iso.Z.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge_new.iso.Z.uu new file mode 100644 index 000000000..3ef253b5b --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_rockridge_new.iso.Z.uu @@ -0,0 +1,208 @@ +$FreeBSD: head/lib/libarchive/test/test_read_format_iso_rockridge_new.iso.Z.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_read_format_iso_rockridge_new.iso.Z +M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1GA0#Q@,A$$/'QT(0``F'H@``@!84)`%$R14P4`B`'!! +M03>R*!"+1@0@0`(GDB!`0"D>V.&12":IY)),-NGDDU!&*>645%9IY9583MG$ +M$DE,\8014X#0Y1,@Y&"##3"\@`28(!B1!!-%3)'%%%04H:$05;Q)1!%2@&`" +M"!<6,<034CPH8`M2O$"$%89*44005!`*`@I#I`!"##GD,`,(1;B0Q1-5.'$$ +M$4'`.6FEEV9Z`PA*N`#%HU)XZ<0+K4XQ!!)O,I&$J%GVZFNO,A"8`PPYR'"# +M##/$,,.R!)(0++'$&HNLLLS"0`*!V&:K+8$`/#MLL<M]MI,0V(CC@#H&!"//@(9@)`^GWC@ +M%%`<$(`O[P`@A10%!!`(%%BP$$`[00P41#M:#S2`U0+Y6)``/0]T`15&:!"` +M`SW^&&0;"6QP00,AD$"ZZ:B3,$01'`2004&S&]1.0>VX\39!.0Y$M^AW#WDB +MD2@.7OCAB2_>N$"/1_XSY40*/Q#F.'+N.>AUCU[ZZ:FOSCT)`.`1=$$ARATW +M@MD'GW<``WAM?`").-$$`@>2D88B1:`A"`42E=.6`()34@X^,FO`0="0QCD0`8VI,$-:X"A#&EH +MP\L%<(?3\^%`@'@](C+0@T9,G2,``(]_^/&/\#B('2M')`7(J0E8U&()!=?% +M1LB/`0>:0Q[:8$8TPK`=H1A(*-KQQC?>4`!]_*,?X3$%)BS`1`1@H0L1B+T! +M`$D`=W0E#E6WO=9)`@#O$*4?`V<0(X(@BBE:P"$3B;$2OL^130`C`"1)R3.N +M00:7S*1`-ME)'7XRE[I\1RD=H**`#(`.;8!#0%B91UH^T)S?HP0`W*'+?[CC +M(*3#@`,*<`)@$DF864#DKI8P@RT>\XN1G&0EUS"#:&J2DSKTY.78J4MWE!(" +MW03`-\-)`(&0LY;=PR@Z6V<)`+2CG;?K92U_2<@I#G.?-/!G(P&Z3($ZDP8& +MG29""8(B:U[NH[IL1RDE<*"*#JFB$@6G.`%PT7.6LYP=94<[V2%(#Y8T`/C4 +M9Q9KH-+"(5.9S!QH#6(:$&HFU*8\5*HNV5'*"!SHAJEL81E8V2-9PK*MK]PH +M!#NZCG:N`YX)D"<][6G2?";2!E4-P%4#VDPTVH"K`/`J317*P[KJA$ +MAPI4H@;1`4?5:#G9AA[=&7!KY]L1^J`HO"(Q\GB77%Y`'O=)QD[OLP'!`%OQ +MJ%F-`D!WF1-([T1KQ](2+P#O0Y[^5`N`YA5DHVA$^<5``5#@%<*20!"E_`5`YB`"DD%`$$&!K"$M";!"(>5$YWL9#`[ +MU9<*21@"W^`4A"F<=U!.H$(0AH!@HMFJOU40@JZF8-X^&4%2?!-4$MPT!$@E +MX0E.,!BHYMLI"'GXOBE><8O%M*<0SS@)?!)3CO&;A"98,0L@L,(3F%"%)IQW +M3[;R+A0BY6))@5C$)%;RBZ7@9`SCV`763;.:U\SFFZ&A#&Q@PQL4T.8ZV_G. +M>,ZSGO?,YS[[^<^`#K2@!TWH0AOZT(A.M*(7S>A&._K1D(ZTI"=-Z4I;^M*8 +MSK2F-\WI3GOZTZ`.M:A'3>I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. +MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV +MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ +M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W +MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U +MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ +M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ +M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ +MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` +M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ +M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ +MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: +MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X +MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 +M>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN(JLV(JN^(JP&(NR.(NT +M6(NV>(NXF(NZN(N\V(N^^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 +M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P +M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. +M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L +MV9(N^9(P&9,R.9,T69,V>9,XF9,ZN9,\V9,^^9-`&91".91$691&>91(F91* +MN91,V91.^910&952.9546956>958F95:N95^95@&99B.99D699F>99H +MF99JN99LV99N^99P&9=R.9=T69=V>9=XF9=ZN9=\V9=^^9>`&9B".9B$69B& +M>9B(F9B*N9B,V9B.^9B0&9F2.9F469F6>9F8F9F:N9F^9F@&9JB.9JD +M69JF>9JHF9JJN9JLV9JN^9JP&9NR.9NT69NV>9NXF9NZN9N\V9N^^9O`&9S" +M.9S$69S&>9S(F9S*N9S,V9S.^9S0&9W2.9W469W6>9W8F9W:N9W^9W@ +M&9[B.9[D69[F>9[HF9[JN9[LV9[N^9[P&9_R.9_T69_V>9_XF9_ZN9_\V9_^ +M^9\`&J`".J`$6J`&>J`(FJ`*NJ`,VJ`.^J`0&J$2.J$46J$6>J$8FJ$:NJ$< +MVJ$>^J$@&J(B.J(D6J(F>J(HFJ(JNJ(LVJ(N^J(P&J,R.J,T6J,V>J,XFJ,Z +MNJ,\VJ,^^J-`&J1".J1$6J1&>J1(FJ1*NJ1,VJ1.^J10&J52.J546J56>J58 +MFJ5:NJ5^J5@&J9B.J9D6J9F>J9HFJ9JNJ9LVJ9N^J9P&J=R.J=T6J=V +M>J=XFJ=ZNJ=\VJ=^^J>`&JB".JB$6JB&>JB(FJB*NJB,VJB.^JB0&JF2.JF4 +M6JF6>JF8FJF:NJF^JF@&JJB.JJD6JJF>JJHFJJJNJJLVJJN^JJP&JNR +M.JNT6JNV>JNXFJNZNJN\VJN^^JO`&JS".JS$6JS&>JS(FJS*NJS,VJS.^JS0 +M&JW2.JW46JW6>JW8FJW:NJW^JW@&J[B.J[D6J[F>J[HFJ[JNJ[LVJ[N +M^J[P&J_R.J_T6J_V>J_XFJ_ZNJ_\VJ_^^J\`&[`".[`$6[`&>[`(F[`*N[`, +MV[`.^[`0&[$2.[$46[$6>[$8F[$:N[$^[$@&[(B.[(D6[(F>[(HF[(J +MN[(LV[(N^[(P&[,R.[,T6[,V>[,XF[,ZN[,\V[,^^[-`&[1".[1$6[1&>[1( +MF[1*N[1,V[1.^[10&[52.[546[56>[58F[5:N[5^[5@&[9B.[9D6[9F +M>[9HF[9JN[9LV[9N^[9P&[=R.[=T6[=V>[=XF[=ZN[=\V[=^^[>`&[B".[B$ +M6[B&>[B(F[B*N[B,V[B.^[B0&[F2.[F46[F6>[F8F[F:N[F^[F@&[JB +M.[JD6[JF>[JHF[JJN[JLV[JN^[JP&[NR.[NT6[NV>[NXF[NZN[N\V[N^^[O` +M&[S".[S$6[S&>[S(F[S*N[S,V[S.^[S0&[W2.[W46[W6>[W8F[W:N[W +M^[W@&[[B.[[D6[[F>[[HF[[JN[[LV[[N^[[P&[_R.[_T6[_V>[_XF[_ZN[_\ +MV[_^^[\`',`"/,`$7,`&?,`(G,`*O,`,W,`._,`0',$2/,$47,$6?,$8G,$: +MO,$_,$@',(B/,(D7,(F?,(HG,(JO,(LW,(N_,(P',,R/,,T7,,V?,,X +MG,,ZO,,\W,,^_,-`',1"/,1$7,1&?,1(G,1*O,1,W,1._,10',52/,547,56 +M?,58G,5:O,5_,5@',9B/,9D7,9F?,9HG,9JO,9LW,9N_,9P',=R/,=T +M7,=V?,=XG,=ZO,=\W,=^_,>`',B"/,B$7,B&?,B(G,B*O,B,W,B._,B0',F2 +M/,F47,F6?,F8G,F:O,F_,F@',JB/,JD7,JF?,JHG,JJO,JLW,JN_,JP +M',NR/,NT7,NV?,NXG,NZO,N\W,N^_,O`',S"/,S$7,S&?,S(G,S*O,S,W,S. +M_,S0',W2/,W47,W6?,W8G,W:O,W_,W@',[B/,[D7,[F?,[HG,[JO,[L +MW,[N_,[P',_R/,_T7,_V?,_XG,_ZO,_\W,_^_,\`'=`"/=`$7=`&?=`(G=`* +MO=`,W=`._=`0'=$2/=$47=$6?=$8G=$:O=$_=$@'=(B/=(D7=(F?=(H +MG=(JO=(LW=(N_=(P'=,R/=,T7=,V?=,XG=,ZO=,\W=,^_=-`'=1"/=1$7=1& +M?=1(G=1*O=1,W=1._=10'=52/=547=56?=58G=5:O=5_=5@'=9B/=9D +M7=9F?=9HG=9JO=9LW=9N_=9P'==R/==T7==V?==XG==ZO==\W==^_=>`'=B" +M/=B$7=B&?=B(G=B*O=B,W=B._=B0'=F2/=F47=F6?=F8G=F:O=F_=F@ +M'=JB/=JD7=JF?=JHG=JJO=JLW=JN_=JP'=NR/=NT7=NV?=NXG=NZO=N\W=N^ +M_=O`'=S"/=S$7=S&?=S(G=S*O=S,W=S._=S0'=W2/=W47=W6?=W8G=W:O=W< +MW=W>_=W@'=[B/=[D7=[F?=[HG=[JO=[LW=[N_=[P'=_R/=_T7=_V?=_XG=_Z +MO=_\W=_^_=\`'N`"/N`$7N`&?N`(GN`*ON`,WN`._N`0'N$2/N$47N$6?N$8 +MGN$:ON$_N$@'N(B/N(D7N(F?N(HGN(JON(LWN(N_N(P'N,R/N,T7N,V +M?N,XGN,ZON,\WN,^_N-`'N1"/N1$7N1&?N1(GN1*ON1,WN1._N10'N52/N54 +M7N56?N58GN5:ON5_N5@'N9B/N9D7N9F?N9HGN9JON9LWN9N_N9P'N=R +M/N=T7N=V?N=XGN=ZON=\WN=^_N>`'NB"/NB$7NB&?NB(GNB*ONB,WNB._NB0 +M'NF2/NF47NF6?NF8GNF:ONF_NF@'NJB/NJD7NJF?NJHGNJJONJLWNJN +M_NJP'NNR/NNT7NNV?NNXGNNZONN\WNN^_NO`'NS"/NS$7NS&?NS(GNS*ONS, +MWNS._NS0'NW2/NW47NW6?NW8GNW:ONW_NW@'N[B/N[D7N[F?N[HGN[J +MON[LWN[N_N[P'N_R/N_T7N_V?N_XGN_ZON_\WN_^_N\`'_`"/_`$7_`&?_`( +MG_`*O_`,W_`.__`0'_$2/_$47_$6?_$8G_$:O_$__$@'_(B/_(D7_(F +M?_(HG_(JO_(LW_(N__(P'_,R/_,T7_,V?_,XG_,ZO_,\W_,^__-`'_1"/_1$ +M7_1&?_1(G_1*O_1,W_1.__10'_52/_547_56?_58G_5:O_5__5@'_9B +M/_9D7_9F?_9HG_9JO_9LW_9N__9P'_=R/_=T7_=V?_=XG_=ZO_=\W_=^__>` +M'_B"/_B$7_B&?_B(G_B*O_B,W_B.__B0'_F2/_F47_F6?_F8G_F:O_F +M__F@'_JB/_JD7_JF?_JHG_JJO_JLW_JN__JP'_NR/_NT7_NV?_NXG_NZO_N\ +MW_N^__O`'_S"/_S$7_S&?_S(G_S*O_S,W_S.__S0'_W2/_W47_W6?_W8G_W: +MO_W__W@'_[B/_[D7_[F?_[HG_[JO_[LW_[N__[P'__R/__T7__V?__X +MG__ZO__\W__^__\`,``*P`%(``N@`3R`"#`!*L`%R``;H`-\@!`P`DK`"4@! +M*Z`%O(`8,`-JP`W(`3N@!_R`(#`$BL`12`)+H`D\@2@P!:K`%<@"6Z`+?($P +M,`;*P!E(`VN@#;R!.#`'ZL`=R`-[H`_\@4`P"`K!(4@$BZ`1/()(,`DJP27( +M!)N@$WR"4#`*2L$I2`6KH!6\@E@P"VK!+<@%NZ`7_()@,`R*P3%(!LN@&3R# +M:#`-JL$UR`;;H!M\@W`P#LK!.4@'ZZ`=O(-X,`_JP3W(!_N@'_R#@#`0"L)! +M2`@+H2$\A(@P$2K"1<@(&Z$C?(20,!)*PDE("2NA);R$F#`3:L)-R`D[H2?\ +MA*`P%(K"44@*2Z$I/(6H,!6JPE7("ENA*WR%L#`6RL)92`MKH2V\A;@P%^K" +M7<@+>Z$O_(7`,!@*PV%(#(NA,3R&R#`9*L-ER`R;H3-\AM`P&DK#:4@-JZ$U +MO(;8,!MJPVW(#;NA-_R&X#`3R/Z#$]JL?U +MR![;HWM\C_`Q/LK'^4@?ZZ-]O(_X,3_JQ_W('_NC?_R/`#)`"L@!22`+I($\ +MD`@R02K(!Z2/ +M_)%`,D@*R2%))(NDD3R22#))*LDER22;I)-\DE`R2DK)*4DEJZ25O))8,DMJ +MR2W));NDE_R28#),BLDQ22;+I)D\DV@R3:K)-#)/ZLD]R2?[I)_\DX`R4`K*04DH"Z6A/)2(,E$JRD7)*!NEHWR4D#)2 +M2LI)22DKI:6\E)@R4VK*3RLMY22_KI;V\E_@R7^K+?Z?O_)W`,W@* +MS^%)/(NG\3R>R#-Y*L_ER3R;I_-\GM`S>DK/Z4D]JZ?UO)[8,WMJS^W)/;NG +M]_R>X#-\BL_Q23[+I_D\G^@S?:K/]4I/ZZD]O:?X-)_JTWW*3_NI/_VG`#6@"M2!2E`+JD$]J`@UH2K4AZI/_:E`-:@*U:%*5(NJ +M43VJ2#6I*M6ERE2;JE-]JE`UJDK5J4I5JZI5O:I8-:MJU:W*5;NJ5_VJ8#6L +MBM6Q2E;+JED]JV@UK:K5M#6OZM6]RE?[ +MJE_]JX`UL`K6P4I8"ZMA/:R(-;$JUL7*6!NK8WVLD#6R2M;)2EDKJV6]K)@U +MLVK6SRZMY/:_H-;VJU_7* +M7MNK>WVO\#6^RM?Y2E_KJWV]K_@UO^K7_ZVO_;7`-M@*VV%+;(NML3VVR#;9 +M*MMERVR;K;-]MM`VVDK;:4MMJZVUO;;8-MMJVVW+;;NMM_VVX#;`NOX3V\B#?Q*M[% +MRW@;K^-]O)`W\DK>R4MY*Z_EO;R8-_-JWLW+>3NOY_V\H#?TBM[12WI+K^D] +MO:@W]:K>UVNO[;V]N#?WZM[=RWM[K^_]O<`W^`K? +MX4M\BZ_Q/;[(-_DJW^7+?)NO\WV^T#?Z2M_I2WVKK_6]OM@W^VK?[[`/_L%`.`@+X2%,A(NP$3["2#@)*^$ES(2; +ML!-^PE`X"DOA*4R%J[`5OL)8.`MKX2W,A;NP%_["8#@,B^$Q3(;+L!D^PV@X +M#:OA-#@/Z^$]S(?[L!_^PX`X$`OB04R( +M"[$A/L2(.!$KXD7,B!NQ(W[$D#@22^))3(DKL26^Q)@X$VOB3/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1G@0-2\,]`(U'QT(0``F'H@``@!04A`E$R14P4`B`'!! +M03>R*!"+1@0@0`(GDB!`0"D>V.&12":IY)),-NGDDU!&*>645%9IY9583MG$ +M$DE,\8014X#0Y1,@Y&"##3"\@`28(!B1!!-%3)'%%%04H:$05;Q)1!%2@&`" +M"!<6,<034CPH8`M2O$"$%89*44005!`*`@I#I`!"##GD,`,(1;B0Q1-5.'$$ +M$4'`.6FEEV9Z`PA*N`#%HU)XZ<0+K4XQ!!)O,I&$J%GVZFNO,A"80PP%RA`# +M#C/0(`,-!)(0+`S#%GMLLLLV2^"UV&9+(`#/1AN#L<@JRRP,)!CYZ[GHIJON +MNNRVZ^Z[\,8K;Y/_U;O8/P(2:*"]_/;K[[\`!US=EDF`T,0;;H#PQ!AT7"K# +MI3CHD*P.RX+0K0(RN%"@QC&$8<.FB(+00AUID'&IR&>4;#$(+K3\0AISO"'P +MS#37;//-.*>5BR8'WDBD0`0`P(%`!Q*1A!0QL(@!T0!((<4733QA11%$!-V! +M0$,:+84,06<@T```:(U#T!X`'?;1,P2M@4`%G"U%#D%_()`!;M/0]@8"'>`V +ML0`$#<*.;M<0=`@"*>"V#4'7&-`";M^0\^.01R[YY)17;OGEF&>N^>8PF1C0 +MC28&+=#0`6B=]$!+!^`TU%)3+7I`5PN@-=<#>3V`V*\#4#8!6J<]T-H%:`WW +M0'(;H+7=`^%]@.DP]#W0WPAH+?A`A"N@->(T`K"`UHYS[OWWX(BG;QDD-N((@(X!\>@CD`$(^?.)!TX!Q0$!^/).TU(H0``"`04LL"``[0C" +M0(+0#K`19`">(]J0""(`GPWD`E0P@@8"X(`>_2A(;5```R0@`@R0((0C+"$) +MAE`$#@1@!`6!H4':49!VN*%]!,G10.3WP?I-L$BJ"^``"WC`!"ZP@06!8$%\ +M5)`*XBB#&^S@_$`H0A*:$(56)`$`]""T@@P-?N]#T!1]>+\`\.YH,0"@`!/A +MA"8DX$!D2(,<8D!$!"I0(`QTX$"42!`F4G!H!.$`%#GH0?J1H)!43*$)^0`` +M+1*$!%0(`R\"PHLP9'",CCP1D0[@)CBY8`8(^,QG.D?C`AC81I[6+ +M:2\Q.<\BK%2?6,VJ5K?ZFAM"52`Z!:A'!XJB@B;5I'ED*$N?6I`,2+6'\*3I +M.[`!OX +MREC.LI;+`V]<2V]/+H,KQEM\'KW*D3?6I?$ +M*>V;DXFKT<^QV<4TI>O5"'*U.(MYO4"5P69).5\9C#BM9Q9N$P<]D`[XM\59 +MW+*F-\WI3D/EAI062*'#'"2]/KBD9LXNFK$6:MC].8O,[6(@GQL_,E>-Y'<`8M*8E$GY;#0!+SSN1L'8M%^5&$+DI&]T_/9ZSBRQ'&D@;X-5F./&T +M/>Q,A_OC(`^YR#MR0XT+Q.'G]JDLU7UG2*M:TA0T>4`^\&IYNEEW!3&WOB$N +MRWY?G->GI2"\=5?S*RH<`'\C"/123E:@UF#B\ZW!S]L==%LF_7DW1\[U +MKGO]ZP.YX=4%LO2=JYR@N5[W=3&^:I>./2`@*'I<,UWR@J#<["&N\]1?[NZ8 +MVUWN<^4BX0A"N(>?W8S7@[IGY6B#O9L8YK88$4 +MGNECUGN9V!O_G:DTSJ,E^5WVEL^[=)6N_5Q/[ARB3U>+D)6 +M(#4R?-.YI_C/WL#QU&X[<7\?$!%0?O<>U[STIT]]V-Z0^0`(/NC3/?M_`UW@ +M3<2^\W4_=YO;&P"H1__K>7AH7(M>UVO_/BV;F'[5DU_#6A0F//[!__[#XR`> +MM6.(=S1"Q5>9P&B+)P=(-7KQ1W7@1T'[UW_\!P_/5WXF-`2-%0#<=5/5UX$> +M^(&:PR?M$``*0`6'$$1)``5?@"G#`BE(4`0@@"%#L`0QF`1$<`0PN"MU(@6W +M$@2B`H-0@"&1,BA,``)!*#4V&"<@,`55``500"A4T":2\H13D`18T"9O`H-R +M0B=VLH1VXH-4D`1#H#]P$@13`(.#X@14$`1#$(5&8RM&6`5"H"M3\()]8@22 +MHC^"D@1N,@20D@1/X`1+""H\V"D0V(@4I&"EW*"EIN(9M.(EX*`67&(:!Z`(@.(NT +M6(NVF!%H4`9LP`9O8#BW^(O`&(S".(S$6(S&>(S(F(S*N(S,V(S.^(S0&(W2 +M.(W46(W6>(W8F(W:N(W^(W@&([B.([D6([F>([HF([JN([LV([N^([P +M&(_R.(_T6(_V>(_XF(_ZN(_\V(_^^(\`&9`".9`$69`&>9`(F9`*N9`,V9`. +M^9`0&9$2.9$469$6>9$8F9$:N9$^9$@&9(B.9(D69(F>9(HF9(JN9(L +MV9(N^9(P&9,R.9,T69,V>9,XF9,ZN9,\V9,^^9-`&91".91$691&>91(F91* +MN91,V91.^910&952.9546956>958F95:N95^95@&99B.99D699F>99H +MF99JN99LV99N^99P&9=R.9=T69=V>9=XF9=ZN9=\V9=^^9>`&9B".9B$69B& +M>9B(F9B*N9B,V9B.^9B0&9F2.9F469F6>9F8F9F:N9F^9F@&9JB.9JD +M69JF>9JHF9JJN9JLV9JN^9JP&9NR.9NT69NV>9NXF9NZN9N\V9N^^9O`&9S" +M.9S$69S&>9S(F9S*N9S,V9S.^9S0&9W2.9W469W6>9W8F9W:N9W^9W@ +M&9[B.9[D69[F>9[HF9[JN9[LV9[N^9[P&9_R.9_T69_V>9_XF9_ZN9_\V9_^ +M^9\`&J`".J`$6J`&>J`(FJ`*NJ`,VJ`.^J`0&J$2.J$46J$6>J$8FJ$:NJ$< +MVJ$>^J$@&J(B.J(D6J(F>J(HFJ(JNJ(LVJ(N^J(P&J,R.J,T6J,V>J,XFJ,Z +MNJ,\VJ,^^J-`&J1".J1$6J1&>J1(FJ1*NJ1,VJ1.^J10&J52.J546J56>J58 +MFJ5:NJ5^J5@&J9B.J9D6J9F>J9HFJ9JNJ9LVJ9N^J9P&J=R.J=T6J=V +M>J=XFJ=ZNJ=\VJ=^^J>`&JB".JB$6JB&>JB(FJB*NJB,VJB.^JB0&JF2.JF4 +M6JF6>JF8FJF:NJF^JF@&JJB.JJD6JJF>JJHFJJJNJJLVJJN^JJP&JNR +M.JNT6JNV>JNXFJNZNJN\VJN^^JO`&JS".JS$6JS&>JS(FJS*NJS,VJS.^JS0 +M&JW2.JW46JW6>JW8FJW:NJW^JW@&J[B.J[D6J[F>J[HFJ[JNJ[LVJ[N +M^J[P&J_R.J_T6J_V>J_XFJ_ZNJ_\VJ_^^J\`&[`".[`$6[`&>[`(F[`*N[`, +MV[`.^[`0&[$2.[$46[$6>[$8F[$:N[$^[$@&[(B.[(D6[(F>[(HF[(J +MN[(LV[(N^[(P&[,R.[,T6[,V>[,XF[,ZN[,\V[,^^[-`&[1".[1$6[1&>[1( +MF[1*N[1,V[1.^[10&[52.[546[56>[58F[5:N[5^[5@&[9B.[9D6[9F +M>[9HF[9JN[9LV[9N^[9P&[=R.[=T6[=V>[=XF[=ZN[=\V[=^^[>`&[B".[B$ +M6[B&>[B(F[B*N[B,V[B.^[B0&[F2.[F46[F6>[F8F[F:N[F^[F@&[JB +M.[JD6[JF>[JHF[JJN[JLV[JN^[JP&[NR.[NT6[NV>[NXF[NZN[N\V[N^^[O` +M&[S".[S$6[S&>[S(F[S*N[S,V[S.^[S0&[W2.[W46[W6>[W8F[W:N[W +M^[W@&[[B.[[D6[[F>[[HF[[JN[[LV[[N^[[P&[_R.[_T6[_V>[_XF[_ZN[_\ +MV[_^^[\`',`"/,`$7,`&?,`(G,`*O,`,W,`._,`0',$2/,$47,$6?,$8G,$: +MO,$_,$@',(B/,(D7,(F?,(HG,(JO,(LW,(N_,(P',,R/,,T7,,V?,,X +MG,,ZO,,\W,,^_,-`',1"/,1$7,1&?,1(G,1*O,1,W,1._,10',52/,547,56 +M?,58G,5:O,5_,5@',9B/,9D7,9F?,9HG,9JO,9LW,9N_,9P',=R/,=T +M7,=V?,=XG,=ZO,=\W,=^_,>`',B"/,B$7,B&?,B(G,B*O,B,W,B._,B0',F2 +M/,F47,F6?,F8G,F:O,F_,F@',JB/,JD7,JF?,JHG,JJO,JLW,JN_,JP +M',NR/,NT7,NV?,NXG,NZO,N\W,N^_,O`',S"/,S$7,S&?,S(G,S*O,S,W,S. +M_,S0',W2/,W47,W6?,W8G,W:O,W_,W@',[B/,[D7,[F?,[HG,[JO,[L +MW,[N_,[P',_R/,_T7,_V?,_XG,_ZO,_\W,_^_,\`'=`"/=`$7=`&?=`(G=`* +MO=`,W=`._=`0'=$2/=$47=$6?=$8G=$:O=$_=$@'=(B/=(D7=(F?=(H +MG=(JO=(LW=(N_=(P'=,R/=,T7=,V?=,XG=,ZO=,\W=,^_=-`'=1"/=1$7=1& +M?=1(G=1*O=1,W=1._=10'=52/=547=56?=58G=5:O=5_=5@'=9B/=9D +M7=9F?=9HG=9JO=9LW=9N_=9P'==R/==T7==V?==XG==ZO==\W==^_=>`'=B" +M/=B$7=B&?=B(G=B*O=B,W=B._=B0'=F2/=F47=F6?=F8G=F:O=F_=F@ +M'=JB/=JD7=JF?=JHG=JJO=JLW=JN_=JP'=NR/=NT7=NV?=NXG=NZO=N\W=N^ +M_=O`'=S"/=S$7=S&?=S(G=S*O=S,W=S._=S0'=W2/=W47=W6?=W8G=W:O=W< +MW=W>_=W@'=[B/=[D7=[F?=[HG=[JO=[LW=[N_=[P'=_R/=_T7=_V?=_XG=_Z +MO=_\W=_^_=\`'N`"/N`$7N`&?N`(GN`*ON`,WN`._N`0'N$2/N$47N$6?N$8 +MGN$:ON$_N$@'N(B/N(D7N(F?N(HGN(JON(LWN(N_N(P'N,R/N,T7N,V +M?N,XGN,ZON,\WN,^_N-`'N1"/N1$7N1&?N1(GN1*ON1,WN1._N10'N52/N54 +M7N56?N58GN5:ON5_N5@'N9B/N9D7N9F?N9HGN9JON9LWN9N_N9P'N=R +M/N=T7N=V?N=XGN=ZON=\WN=^_N>`'NB"/NB$7NB&?NB(GNB*ONB,WNB._NB0 +M'NF2/NF47NF6?NF8GNF:ONF_NF@'NJB/NJD7NJF?NJHGNJJONJLWNJN +M_NJP'NNR/NNT7NNV?NNXGNNZONN\WNN^_NO`'NS"/NS$7NS&?NS(GNS*ONS, +MWNS._NS0'NW2/NW47NW6?NW8GNW:ONW_NW@'N[B/N[D7N[F?N[HGN[J +MON[LWN[N_N[P'N_R/N_T7N_V?N_XGN_ZON_\WN_^_N\`'_`"/_`$7_`&?_`( +MG_`*O_`,W_`.__`0'_$2/_$47_$6?_$8G_$:O_$__$@'_(B/_(D7_(F +M?_(HG_(JO_(LW_(N__(P'_,R/_,T7_,V?_,XG_,ZO_,\W_,^__-`'_1"/_1$ +M7_1&?_1(G_1*O_1,W_1.__10'_52/_547_56?_58G_5:O_5__5@'_9B +M/_9D7_9F?_9HG_9JO_9LW_9N__9P'_=R/_=T7_=V?_=XG_=ZO_=\W_=^__>` +M'_B"/_B$7_B&?_B(G_B*O_B,W_B.__B0'_F2/_F47_F6?_F8G_F:O_F +M__F@'_JB/_JD7_JF?_JHG_JJO_JLW_JN__JP'_NR/_NT7_NV?_NXG_NZO_N\ +MW_N^__O`'_S"/_S$7_S&?_S(G_S*O_S,W_S.__S0'_W2/_W47_W6?_W8G_W: +MO_W__W@'_[B/_[D7_[F?_[HG_[JO_[LW_[N__[P'__R/__T7__V?__X +MG__ZO__\W__^__\`,``*P`%(``N@`3R`"#`!*L`%R``;H`-\@!`P`DK`"4@! +M*Z`%O(`8,`-JP`W(`3N@!_R`(#`$BL`12`)+H`D\@2@P!:K`%<@"6Z`+?($P +M,`;*P!E(`VN@#;R!.#`'ZL`=R`-[H`_\@4`P"`K!(4@$BZ`1/()(,`DJP27( +M!)N@$WR"4#`*2L$I2`6KH!6\@E@P"VK!+<@%NZ`7_()@,`R*P3%(!LN@&3R# +M:#`-JL$UR`;;H!M\@W`P#LK!.4@'ZZ`=O(-X,`_JP3W(!_N@'_R#@#`0"L)! +M2`@+H2$\A(@P$2K"1<@(&Z$C?(20,!)*PDE("2NA);R$F#`3:L)-R`D[H2?\ +MA*`P%(K"44@*2Z$I/(6H,!6JPE7("ENA*WR%L#`6RL)92`MKH2V\A;@P%^K" +M7<@+>Z$O_(7`,!@*PV%(#(NA,3R&R#`9*L-ER`R;H3-\AM`P&DK#:4@-JZ$U +MO(;8,!MJPVW(#;NA-_R&X#`3R/Z#$]JL?U +MR![;HWM\C_`Q/LK'^4@?ZZ-]O(_X,3_JQ_W('_NC?_R/`#)`"L@!22`+I($\ +MD`@R02K(!Z2/ +M_)%`,D@*R2%))(NDD3R22#))*LDER22;I)-\DE`R2DK)*4DEJZ25O))8,DMJ +MR2W));NDE_R28#),BLDQ22;+I)D\DV@R3:K)-#)/ZLD]R2?[I)_\DX`R4`K*04DH"Z6A/)2(,E$JRD7)*!NEHWR4D#)2 +M2LI)22DKI:6\E)@R4VK*3RLMY22_KI;V\E_@R7^K+?Z?O_)W`,W@* +MS^%)/(NG\3R>R#-Y*L_ER3R;I_-\GM`S>DK/Z4D]JZ?UO)[8,WMJS^W)/;NG +M]_R>X#-\BL_Q23[+I_D\G^@S?:K/]4I/ZZD]O:?X-)_JTWW*3_NI/_VG`#6@"M2!2E`+JD$]J`@UH2K4AZI/_:E`-:@*U:%*5(NJ +M43VJ2#6I*M6ERE2;JE-]JE`UJDK5J4I5JZI5O:I8-:MJU:W*5;NJ5_VJ8#6L +MBM6Q2E;+JED]JV@UK:K5M#6OZM6]RE?[ +MJE_]JX`UL`K6P4I8"ZMA/:R(-;$JUL7*6!NK8WVLD#6R2M;)2EDKJV6]K)@U +MLVK6SRZMY/:_H-;VJU_7* +M7MNK>WVO\#6^RM?Y2E_KJWV]K_@UO^K7_ZVO_;7`-M@*VV%+;(NML3VVR#;9 +M*MMERVR;K;-]MM`VVDK;:4MMJZVUO;;8-MMJVVW+;;NMM_VVX#;`NOX3V\B#?Q*M[% +MRW@;K^-]O)`W\DK>R4MY*Z_EO;R8-_-JWLW+>3NOY_V\H#?TBM[12WI+K^D] +MO:@W]:K>UVNO[;V]N#?WZM[=RWM[K^_]O<`W^`K? +MX4M\BZ_Q/;[(-_DJW^7+?)NO\WV^T#?Z2M_I2WVKK_6]OM@W^VK?[[`/_L%`.`@+X2%,A(NP$3["2#@)*^$ES(2; +ML!-^PE`X"DOA*4R%J[`5OL)8.`MKX2W,A;NP%_["8#@,B^$Q3(;+L!D^PV@X +M#:OA-#@/Z^$]S(?[L!_^PX`X$`OB04R( +M"[$A/L2(.!$KXD7,B!NQ(W[$D#@22^))3(DKL26^Q)@X$VOB3R^-Y +M3(_KL3V^Q_@X'^OC?[-O_LW`.3@+Y^%,G(NS<3[.R#DY*^?ES)R;LW-^SM`Y +M.DOGZ4R=J[-UOL[8.3MKY^W,G;NS=_[.X#D\B^?Q3)[+LWD^S^@Y/:OG] +MV[-[?L_P.3[+Y_E,G^NS?;[/^#D_Z^?]S)_[LW_^SP`Z0`OH`4V@"[2!/M`( +M.D$KZ`7-H!NT@W[0$#I"2^@)3:$KM(6^T!@Z0VOH#4VOZ[6]OM?X.E_KZWW-K_NUO_[7`#M@ +M"^R!3;`+ML$^V`@[82OLA[;/_ME`.V@+[:%-M(NVT3[:2#MI*^VES;2;MM-^VE`[:DOMJ4VU +MJ[;5OMI8.VMK[:W-M;NVU_[:8#MLB^VQ3;;+MMD^VV@[;:OMM#MOZ^V]S;?[MM_^VX`[<`ONP4VX"[?A/MR(.W$K[L7- +MN!NWXW[2OOYV#M[:^_MS;V[M_?^ +MWN`[?(OO\4V^R[?Y/M_H.WVK[_7-OMNW^W[?\#M^R^_Y3;_KM_V^W_@[?^OO +M_[DO_^7`/)@+\V%.S(NY,3_FR#R9*_-ESLR;N3-_YM`\FDOS:4[-J[DUO^;8 +M/)MK\VW.S;NY-__FX#R3_OZ#V]J_?USM[; +MNWM_[_`]OLOW^4[?Z[M]O^_X/;_K]_W.W_N[?__O`#[`"_@!3^`+O($_\`@^ +MP2OX!<_@&[R#?_`0/L)+^`E/X2N\A;_P&#[#:_@-S^$[O(?_\"`^Q(OX$4_B +M2[R)/_$H/L6K^!7/XEN\BW_Q,#[&R_@93^-KO(V_\3@^Q^OX'<_C>[R/__%` +M/L@+^2%/Y(N\D3_R2#[)*_DES^2;O)-_\E`^RDOY*4_EJ[R5O_)8/LMK^2W/ +MY;N\E__R8#[,B_DQ3^;+O)D_\V@^S:OY-<_FV[R;?_-P/L[+^3E/Y^N\G;_S +M>#[/Z_D]S^?[O)__\X`^T`OZ04_H"[VA/_2(/M$K^D7/Z!N]HW_TD#[22_I) +M3^DKO:6_])@^TVOZ3<_I.[VG__2@/M2+^E%/ZDN]J3_UJ#[5J_I5S^I;O:M_ +M];`^ULOZ64_K:[VMO_6X/M?K^EW/ZWN]K__UP#[8"_MA3^R+O;$_]L@^V2O[ +M9<_LF[VS?_;0/MI+^VE/[:N]M;_VV#[;:_MMS^V[O;?_]N`^W(O[<4_NR[VY +M/_?H/MVK^W7/[MN]NW_W\#[>R_MY3^_KO;V_]_@^W^O[?<_O^[V___<`/^`+ +M_(%/\`N^P3_X"#_A*_R%S_`;OL-_^!`_XDO\B4_Q*[[%O_@8/^-K_(W/\3N^ +MQ__X(#_DB_R13_)+OLD_^2@_Y:O\E<_R6[[+?_DP/^;+_)E/\VN^S;_Y.#_G +MZ_R=S_-[OL__^4`_Z`O]H4_TB[[1/_I(/^DK_:7/])N^TW_Z4#_J2_VI3_6K +MOM6_^E@_ZVO]K<_UN[[7__I@/^R+_;%/]LN^V3_[:#_MJ_VUS_;;OMM_^W`_ +M[LO]N4_WZ[[=O_MX/^_K_;W/]_N^W__[@#_P"_[!3_@+O^$__(@_\2O^Q<_X +M&[_C?_R0/_)+_LE/^2N_Y;_\F#_S:_[-S_D[O^?__*`_](O^T4_Z2[_I/_VH +M/_6K_M7/^EN_ZW_]L#_VR_[93_MKO^V__;@_]^O^W<_[>[_O__W`/_@+_^%/ +M_(N_\3_^R#_Y*__ES_R;O_-__M`_^DO_Z4_]J[_UO_[8/_MK_^W/_;N_]__^ +MX#_\B__Q3_[+O_D__^@__:O_]<_^V[_[?__P/_[+__E/_^N__;__^#__Z__] +MS__[O____P!@`"@`#H`$8`%H`!Z`"&`"J``N@`Q@`^@`/H`08`0H`4Z`%&`% +M:`%>@!A@!J@!;H`<8`?H`7Z`(&`(*`*.@"1@"6@"GH`H8`JH`JZ`+&`+Z`*^ +M@#!@#"@#SH`T8`UH`]Z`.&`.J`/N@#Q@#^@#_H!`8!`H!`Z!1&`1:`0>@4A@ +M$J@$+H%,8!/H!#Z!4&`4*`5.@51@%6@%7H%88!:H!6Z!7&`7Z`5^@6!@&"@& +MCH%D8!EH!IZ!:&`:J`:N@6Q@&^@&OH%P8!PH!\Z!=&`=:`?>@7A@'J@'[H%\ +M8!_H!_Z!@&`@*`@.@H1@(6@('H*(8"*H""Z"C&`CZ`@^@I!@)"@)3H*48"5H +M"5Z"F&`FJ`EN@IQ@)^@)?H*@8"@H"HZ"I&`I:`J>@JA@*J@*KH*L8"OH"KZ" +ML&`L*`O.@K1@+6@+WH*X8"ZH"^Z"O&`OZ`O^@L!@,"@,#H/$8#%H#!Z#R&`R +MJ`PN@\Q@,^@,/H/08#0H#4Z#U&`U:`U>@]A@-J@-;H/<8#?H#7Z#X&`X*`Z. +M@^1@.6@.GH/H8#JH#JZ#[&`[Z`Z^@_!@/"@/SH/T8#UH#]Z#^&`^J`_N@_Q@ +M/^@/_H,`84`H$`Z$!&%!:!`>A`AA0J@0+H0,84/H$#Z$$&%$*!%.A!1A16@1 +M7H0884:H$6Z$'&%'Z!%^A"!A2"@2CH0D84EH$IZ$*&%*J!*NA"QA2^@2OH0P +M84PH$\Z$-&%-:!/>A#AA3J@3[H0\84_H$_Z$0&%0*!0.A41A46@4'H5(85*H +M%"Z%3&%3Z!0^A5!A5"@53H54855H%5Z%6&%6J!5NA5QA5^@5?H5@85@H%HZ% +M9&%9:!:>A6AA6J@6KH5L85OH%KZ%<&%<*!?.A71A76@7WH5X85ZH%^Z%?&%? +MZ!?^A8!A8"@8#H:$86%H&!Z&B&%BJ!@NAHQA8^@8/H:0860H&4Z&E&%E:!E> +MAIAA9J@9;H:<86?H&7Z&H&%H*!J.AJ1A:6@:GH:H86JH&JZ&K&%KZ!J^AK!A +M;"@;SH:T86UH&]Z&N&%NJ!ONAKQA;^@;_H;`87`H'`Z'Q&%Q:!P>A\AA"@>CH?D +M87EH'IZ'Z&%ZJ!ZNA^QA>^@>OH?P87PH'\Z']&%]:!_>A_AA?J@?[H?\87_H +M'_Z'`&*`*"`.B`1B@6@@'H@(8H*H("Z(#&*#Z"`^B!!BA"@A3H@48H5H(5Z( +M&&*&J"%NB!QBA^@A?H@@8H@H(HZ()&*):"*>B"ABBJ@BKH@L8HOH(KZ(,&*, +M*"/.B#1BC6@CWH@X8HZH(^Z(/&*/Z"/^B$!BD"@D#HE$8I%H)!Z)2&*2J"0N +MB4QBD^@D/HE08I0H)4Z)5&*5:"5>B5ABEJ@E;HE<8I?H)7Z)8&*8*":.B61B +MF6@FGHEH8IJH)JZ);&*;Z":^B7!BG"@GSHET8IUH)]Z)>&*>J"?NB7QBG^@G +M_HF`8J`H*`Z*A&*A:"@>BHABHJ@H+HJ,8J/H*#Z*D&*D*"E.BI1BI6@I7HJ8 +M8J:H*6Z*G&*GZ"E^BJ!BJ"@JCHJD8JEH*IZ*J&*JJ"JNBJQBJ^@JOHJP8JPH +M*\Z*M&*M:"O>BKABKJ@K[HJ\8J_H*_Z*P&*P*"P.B\1BL6@L'HO(8K*H+"Z+ +MS&*SZ"P^B]!BM"@M3HO48K5H+5Z+V&*VJ"UNB]QBM^@M?HO@8K@H+HZ+Y&*Y +M:"Z>B^ABNJ@NKHOL8KOH+KZ+\&*\*"_.B_1BO6@OWHOX8KZH+^Z+_&*_Z"_^ +'BP!CP+@7`0`` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_zisofs.iso.Z.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_zisofs.iso.Z.uu new file mode 100644 index 000000000..ef54ca6c7 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_iso_zisofs.iso.Z.uu @@ -0,0 +1,63 @@ +$FreeBSD: head/lib/libarchive/test/test_read_format_iso_zisofs.iso.Z.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_read_format_iso_zisofs.iso.Z +M'YV0``(*'$BPH,&#"!,J7,BPH<.'$"-*G$BQHL6+&#-JW,BQH\>/($.*'$FR +MI,F3*%.J7,FRIO8,.*'4NVK-FS:-.J7//JW/'D"-+GDRYLN7+F#-KWLRY +ML^?/H$.+'DVZM.G3J%.K7LVZM>O7L&/+GDV[MNW;N'/KWLV[M^_?P(,+'TZ\ +MN/'CR),K7\Z\N?/GT*-+GTZ]NO7KV+-KW\Z]N_?OX,.+'T^^O/GSZ-.K7\^^ +MO?OW\./+GT^_OOW[^//KW\^_O_^_`0Q!!`PPQ!```$;(44890DQ!!`@01BCA +MA!1***`43S11X88<1GA0+`6!Z-&!``1`XH$((`"`!059,$%"%0PD`@`7%%2C +MB@*I:$0``B10(@D"!'3B@1T6:>212":IY)),-NGDDU!&*>645%9I991-+)'$ +M%$\8,04(6SX!0@XVV`##"TAX"8(123!1Q!193$%%$1H*446;1!0A!0@F@'!A +M$4,\(<6#`K8@Q0M$6$&H%$4$086@(*`P1`H@Q)!##C.`4(0+63Q1A1-'$!&$ +MFY%.6NFE-X"@A`M0-"H%ETZ\L.H40R#1)A-)@'KEKKSN*@.!.<`0K`PRQ$!# +M#300"`,)OPKK++'&(JLL"NXY)9K[KGHIJON +MNNRVZ^Z2_\6[V#\"$FB@O/CFJ^^^_/9;799)@'!%&62`,$49<$`H`PC%ZG"L +MPS`P#*P";:R1QAQOF#$'PRX4"(*A']>11L$Q?'S&R`Q_K`<(+K3\@AX7O^'O +MS#37;//-.)=U8(U""C0``!@(="`124B1\]%()ZWTTDPW[?334$M]MI,(T*CC0#@&)".//H8`)`]EWC@ +M%%`<$(`O[P`@A10%!!`(%%B$VTX0`P71CM8##6"UT$$2)``51F@0@`,[]OAC +M&PD(4$$+*)``NNBDDS!$$1P$D$%!KQO43D'MF/$V03<.1+?G=U<^9`"#%WYX +MX@$LWOCC!4E>$(\%79[YYIW;;7KHHY=^>O4D```'T`4%+7?<"-;]H^]"#N!U +M\`$DXD03"!Q(1AIR(*XXXP(Y7OE``DPNY/T".:\YY^*[6_0^1[W4`8`0`-!` +M031@`P,,Q``V&.#=A":D`[#)32[800S0I[XF).!`9D@#&\H@OP"0(A`#"00I +M^!>0_"V/A0#P'_0"2`()3@]UI=."$2`0`#CH@0`/H$(8>!$07H2!"HQ(X`(; +M^,`(TI"")5H`$H(P*%PY80D9W"#ATK>^!AP(#6&0`QG8D`8WK*&$)TSA"ING +MOQ+!4(8`Y-T-L7>]U.F0ASX$HA")"``C4L$0`-A`001I$!M",0`*@%,3K(A% +M#0INBXU8'P,.-(<\M(&,9BPA,$(QD%``HXTF>F'SIL"$!9"(`"$<(>;^MZ,! +M^$@`-0R`*V,XQ]2YC9`#P25!ZEBZ0RY`D8R401;1%\DF>!$`E;QD&=<@`TUR +M4B">!"4HWTC*28(/``.@0QO@L,K-\;*6UBM@Z101R$$>Y'0%^%GV\A:`7V9A +MD;E:P@R&"%HA4`^+TK&A-JUK7:A$]M0.15#B$ +M5I,`A2]8*@C``IO@$J"6P:@J.2\`0G&,Q3B-T4A&;+ +M6-\"5[A@RI-MD9L$/8')N8U-0A.HF`406.$)3*A"$_B:)UI)@:Z/&BZD:GO; +MW'Z7N%(8;VN;ZP*V^O>_``[PS&Y`CBE8(AG;L,8!]JC2!P0$'P4("!,!,.$* +M.Y#"%[:PA#/,X0U[&,,?UC"(1RSB$G>8Q"9 +MRE>VQG+7]8RF,I2F_K4J$ZUJE?-ZE:[^M6PCK6L9TWK6MOZUKC. +MM:YWS>M>^_K7P`ZVL(=-[&(;^]C(3K:RE\WL9CO[V=".MK2G3>UJ6_O:V,ZV +MMK?-[6Y[^]O@#K>XQTWNYVN_O=\(ZWO.=-[WK;^][XSK>^ +M]\WO?OO[WP`/N,`'3O""&_S@"$^XPA?.\(8[_.$0C[C$)T[QBEO\XAC/N,8W +MSO&.>_SC(`^YR$=.\I*;_.0H3[G*5\[REKO\Y3"/NI8S[K6M\[U +MKGO]ZV`/N]C'3O:RF_WL:$^[VM?.]K:[_>UPC[O^ +M^_WO@`^\X`=/^,(;_O"(3[SB%\_XQCO^\9"/O.0G3_G*6_[RF,^\YC?/^I7S_K6N_[UL(^][&=/^]K;_O:XS[WN=\_[WOO^ +M]\`/OO"'3_SB&__XR$^^\I?/_.8[__G0C[[TIT_]ZEO_^MC/OO:WS_WN>__[ +MX`^_^,=/_O*;__SH3[_ZU\_^]KO__?"/O_SG3__ZV__^^,^__O?/__[[__\` +M&(`".(`$6(`&>(`(F(`*N(`,V(`.^(`0&($2.($46($6>($8F($:N($ +M^($@&((B.((D6((F>((HF((JN((LV((N^((P&(,R.(,T6(,V>(,XF(,ZN(,\ +MV(,^^(-`&(1".(1$6(1&>(1(F(1*N(1,V(1.^(10&(52.(546(56>(58F(5: +MN(5^(5@&(9B.(9D6(9F>(9HF(9JN(9LV(9N^(9P&(=R.(=T6(=V>(=X +MF(=ZN(=\V(=^^(>`&(B".(B$6(B&>(B(F(B*N(B,V(B.^(B0&(F2.(F46(F6 +@>(F8F(F:N(F^(F@&(JB.(JD6(JF>(JHF(JJN'`` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_bz2.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_bz2.c new file mode 100644 index 000000000..a2c5307b7 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_bz2.c @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Based on libarchive/test/test_read_format_isorr_bz2.c with + * bugs introduced by Andreas Henriksson for + * testing ISO9660 image with Joliet extension. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isojoliet_bz2.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* +Execute the following to rebuild the data for this program: + tail -n +35 test_read_format_isojoliet_bz2.c | /bin/sh + +rm -rf /tmp/iso +mkdir /tmp/iso +mkdir /tmp/iso/dir +echo "hello" >/tmp/iso/long-joliet-file-name.textfile +ln /tmp/iso/long-joliet-file-name.textfile /tmp/iso/hardlink +(cd /tmp/iso; ln -s long-joliet-file-name.textfile symlink) +if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h +TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir +TZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink +else +TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir +TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink +fi +F=test_read_format_iso_joliet.iso.Z +mkhybrid -J -uid 1 -gid 2 /tmp/iso | compress > $F +uuencode $F $F > $F.uu +exit 1 + */ + +DEFINE_TEST(test_read_format_isojoliet_bz2) +{ + const char *refname = "test_read_format_iso_joliet.iso.Z"; + struct archive_entry *ae; + struct archive *a; + const void *p; + size_t size; + off_t offset; + + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_compression_all(a)); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_set_options(a, "iso9660:!rockridge")); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* First entry is '.' root directory. */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString(".", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(86401, archive_entry_ctime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(0, archive_entry_uid(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt((int)size, 0); + + /* A directory. */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString("dir", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + + /* A regular file with two names ("hardlink" gets returned + * first, so it's not marked as a hardlink). */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString("long-joliet-file-name.textfile", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assert(archive_entry_hardlink(ae) == NULL); + assertEqualInt(6, archive_entry_size(ae)); + assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(6, (int)size); + assertEqualInt(0, offset); + assertEqualInt(0, memcmp(p, "hello\n", 6)); + + /* Second name for the same regular file (this happens to be + * returned second, so does get marked as a hardlink). */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString("hardlink", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualString("long-joliet-file-name.textfile", + archive_entry_hardlink(ae)); + assert(!archive_entry_size_is_set(ae)); + + /* A symlink to the regular file. */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString("symlink", archive_entry_pathname(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(172802, archive_entry_atime(ae)); + + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify archive format. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + + /* Close the archive. */ + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_long.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_long.c new file mode 100644 index 000000000..765cf37f1 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_long.c @@ -0,0 +1,141 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isojoliet_long.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* +Execute the following to rebuild the data for this program: + tail -n +35 test_read_format_isojoliet_long.c | /bin/sh + +rm -rf /tmp/iso +mkdir /tmp/iso +num=0 +file=""; +while [ $num -lt 100 ] +do + num=$((num+10)) + file="${file}1234567890" +done +dir="${file}dir" +mkdir /tmp/iso/${dir} +file="${file}123" +echo "hello" > /tmp/iso/${file} +ln /tmp/iso/${file} /tmp/iso/hardlink +if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h +TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir} +else +TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir} +fi +F=test_read_format_iso_joliet_long.iso.Z +mkhybrid -J -joliet-long -uid 1 -gid 2 /tmp/iso | compress > $F +uuencode $F $F > $F.uu +rm -rf /tmp/iso +exit 1 + */ + +DEFINE_TEST(test_read_format_isojoliet_long) +{ + const char *refname = "test_read_format_iso_joliet_long.iso.Z"; + char pathname[104]; + struct archive_entry *ae; + struct archive *a; + const void *p; + size_t size; + off_t offset; + int i; + + for (i = 0; i < 100; i++) + pathname[i] = '0' + ((i+1) % 10); + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_compression_all(a)); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_set_options(a, "iso9660:!rockridge")); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* First entry is '.' root directory. */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString(".", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(86401, archive_entry_ctime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(0, archive_entry_uid(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt((int)size, 0); + + /* A directory. */ + pathname[100] = 'd'; + pathname[101] = 'i'; + pathname[102] = 'r'; + pathname[103] = '\0'; + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString(pathname, archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + + /* A regular file with two names (pathname gets returned + * first, so it's not marked as a hardlink). */ + pathname[100] = '1'; + pathname[101] = '2'; + pathname[102] = '3'; + pathname[103] = '\0'; + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString(pathname, archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assert(archive_entry_hardlink(ae) == NULL); + assertEqualInt(6, archive_entry_size(ae)); + assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(6, (int)size); + assertEqualInt(0, offset); + assertEqualInt(0, memcmp(p, "hello\n", 6)); + + /* Second name for the same regular file (this happens to be + * returned second, so does get marked as a hardlink). */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString("hardlink", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualString(pathname, archive_entry_hardlink(ae)); + assert(!archive_entry_size_is_set(ae)); + + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify archive format. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + + /* Close the archive. */ + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_rr.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_rr.c new file mode 100644 index 000000000..365f8e7a8 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isojoliet_rr.c @@ -0,0 +1,159 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Based on libarchive/test/test_read_format_isorr_bz2.c with + * bugs introduced by Andreas Henriksson for + * testing ISO9660 image with Joliet extension. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isojoliet_rr.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* +Execute the following to rebuild the data for this program: + tail -n +35 test_read_format_isojoliet_rr.c | /bin/sh + +rm -rf /tmp/iso +mkdir /tmp/iso +mkdir /tmp/iso/dir +file="long-joliet-file-name.textfile" +echo "hello" >/tmp/iso/$file +ln /tmp/iso/$file /tmp/iso/hardlink +(cd /tmp/iso; ln -s $file symlink) +if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h +TZ=utc touch -afm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir +TZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink +TZ=utc touch -afm -t 197001020000.01 /tmp/iso +else +TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir +TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink +TZ=utc touch -afhm -t 197001020000.01 /tmp/iso +fi +F=test_read_format_iso_joliet_rockridge.iso.Z +mkhybrid -J -uid 1 -gid 2 /tmp/iso | compress > $F +uuencode $F $F > $F.uu +exit 1 + */ + +DEFINE_TEST(test_read_format_isojoliet_rr) +{ + const char *refname = "test_read_format_iso_joliet_rockridge.iso.Z"; + struct archive_entry *ae; + struct archive *a; + const void *p; + size_t size; + off_t offset; + + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_compression_all(a)); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* First entry is '.' root directory. */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString(".", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt((int)size, 0); + + /* A directory. */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString("dir", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + + /* A regular file with two names ("hardlink" gets returned + * first, so it's not marked as a hardlink). */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString("long-joliet-file-name.textfile", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assert(archive_entry_hardlink(ae) == NULL); + assertEqualInt(6, archive_entry_size(ae)); + assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(6, (int)size); + assertEqualInt(0, offset); + assertEqualInt(0, memcmp(p, "hello\n", 6)); + assertEqualInt(86401, archive_entry_mtime(ae)); + /* mkisofs records their access time. */ + /*assertEqualInt(86401, archive_entry_atime(ae));*/ + /* TODO: Actually, libarchive should be able to + * compute nlinks correctly even without RR + * extensions. See comments in libarchive source. */ + assertEqualInt(2, archive_entry_nlink(ae)); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + + /* Second name for the same regular file (this happens to be + * returned second, so does get marked as a hardlink). */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString("hardlink", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualString("long-joliet-file-name.textfile", + archive_entry_hardlink(ae)); + assert(!archive_entry_size_is_set(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + /* TODO: See above. */ + assertEqualInt(2, archive_entry_nlink(ae)); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + + /* A symlink to the regular file. */ + assertEqualInt(0, archive_read_next_header(a, &ae)); + assertEqualString("symlink", archive_entry_pathname(ae)); + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("long-joliet-file-name.textfile", + archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(172802, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_nlink(ae)); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify archive format. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); + + /* Close the archive. */ + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_bz2.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_bz2.c new file mode 100644 index 000000000..cb5a969d6 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_bz2.c @@ -0,0 +1,203 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isorr_bz2.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* +PLEASE use old cdrtools; mkisofs verion is 2.01. +This version mkisofs made wrong "SL" System Use Entry of RRIP. + +Execute the following command to rebuild the data for this program: + tail -n +34 test_read_format_isorr_bz2.c | /bin/sh + +rm -rf /tmp/iso +mkdir /tmp/iso +mkdir /tmp/iso/dir +echo "hello" >/tmp/iso/file +dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file +ln /tmp/iso/file /tmp/iso/hardlink +(cd /tmp/iso; ln -s file symlink) +(cd /tmp/iso; ln -s /tmp/ symlink2) +(cd /tmp/iso; ln -s /tmp/../ symlink3) +(cd /tmp/iso; ln -s .././../tmp/ symlink4) +(cd /tmp/iso; ln -s .///file symlink5) +(cd /tmp/iso; ln -s /tmp//../ symlink6) +TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir +TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink /tmp/iso/symlink5 +F=test_read_format_iso_rockridge.iso.Z +mkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F +uuencode $F $F > $F.uu +exit 1 + */ + +DEFINE_TEST(test_read_format_isorr_bz2) +{ + const char *refname = "test_read_format_iso_rockridge.iso.Z"; + struct archive_entry *ae; + struct archive *a; + const void *p; + size_t size; + off_t offset; + int i; + + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_compression_all(a)); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* Retrieve each of the 8 files on the ISO image and + * verify that each one is what we expect. */ + for (i = 0; i < 10; ++i) { + assertEqualInt(0, archive_read_next_header(a, &ae)); + + if (strcmp(".", archive_entry_pathname(ae)) == 0) { + /* '.' root directory. */ + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + /* Now, we read timestamp recorded by RRIP "TF". */ + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + /* Now, we read links recorded by RRIP "PX". */ + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt((int)size, 0); + } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { + /* A regular file. */ + assertEqualString("hardlink", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(12345684, archive_entry_size(ae)); + assertEqualInt(0, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(0, offset); + assertEqualMem(p, "hello\n", 6); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { + /* A hardlink to the regular file. */ + /* Note: If "hardlink" gets returned before "file", + * then "hardlink" will get returned as a regular file + * and "file" will get returned as the hardlink. + * This test should tolerate that, since it's a + * perfectly permissible thing for libarchive to do. */ + assertEqualString("file", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualString("hardlink", archive_entry_hardlink(ae)); + assertEqualInt(0, archive_entry_size_is_set(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { + /* A symlink to the regular file. */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("file", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(172802, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { + /* A symlink to /tmp (an absolute path) */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("/tmp", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { + /* A symlink to /tmp/.. (with a ".." component) */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("/tmp/..", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { + /* A symlink to a path with ".." and "." components */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString(".././../tmp", + archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { + /* A symlink to the regular file with "/" components. */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString(".///file", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(172802, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { + /* A symlink to /tmp//.. + * (with "/" and ".." components) */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("/tmp//..", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else { + failure("Saw a file that shouldn't have been there"); + assertEqualString(archive_entry_pathname(ae), ""); + } + } + + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify archive format. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); + + /* Close the archive. */ + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_ce.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_ce.c new file mode 100644 index 000000000..71bce93df --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_ce.c @@ -0,0 +1,223 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isorr_ce.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* +Execute the following command to rebuild the data for this program: + tail -n +32 test_read_format_isorr_ce.c | /bin/sh + +dirname=/tmp/iso +# +rm -rf $dirname +mkdir $dirname +# +num=0 +file="" +while [ $num -lt 150 ] +do + num=$((num+1)) + file="a$file" +done +# +num=0 +while [ $num -lt 3 ] +do + num=$((num+1)) + file="a$file" + echo "hello $((num+150))" > $dirname/$file + dd if=/dev/zero count=1 bs=4080 >> $dirname/$file + (cd $dirname; ln -s $file sym$num) +done +# +mkdir $dirname/dir +# +time1="197001020000.01" +time2="197001030000.02" +TZ=utc touch -afhm -t $time1 $dirname/dir $dirname/aaaa* +TZ=utc touch -afhm -t $time2 $dirname/sym* +TZ=utc touch -afhm -t $time1 $dirname +# +F=test_read_format_iso_rockridge_ce.iso.Z +mkisofs -R -uid 1 -gid 2 $dirname | compress > $F +uuencode $F $F > $F.uu +rm -rf $dirname +exit 1 + */ + +/* + * Test reading SUSP "CE" extension is works fine. + */ + +static void +mkpath(char *p, int len) +{ + int i; + + for (i = 0; i < len; i++) + p[i] = 'a'; + p[len] = '\0'; +} + +DEFINE_TEST(test_read_format_isorr_ce) +{ + const char *refname = "test_read_format_iso_rockridge_ce.iso.Z"; + char path1[160]; + char path2[160]; + char path3[160]; + struct archive_entry *ae; + struct archive *a; + const void *p; + size_t size; + off_t offset; + int i; + + mkpath(path1, 151); + mkpath(path2, 152); + mkpath(path3, 153); + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_compression_all(a)); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* Retrieve each of the 8 files on the ISO image and + * verify that each one is what we expect. */ + for (i = 0; i < 8; ++i) { + assertEqualInt(0, archive_read_next_header(a, &ae)); + + if (strcmp(".", archive_entry_pathname(ae)) == 0) { + /* '.' root directory. */ + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + /* Now, we read timestamp recorded by RRIP "TF". */ + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + /* Now, we read links recorded by RRIP "PX". */ + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt((int)size, 0); + } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp(path1, archive_entry_pathname(ae)) == 0) { + /* A regular file. */ + assertEqualString(path1, archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(4090, archive_entry_size(ae)); + assertEqualInt(0, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(0, offset); + assertEqualMem(p, "hello 151\n", 10); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp(path2, archive_entry_pathname(ae)) == 0) { + /* A regular file. */ + assertEqualString(path2, archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(4090, archive_entry_size(ae)); + assertEqualInt(0, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(0, offset); + assertEqualMem(p, "hello 152\n", 10); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp(path3, archive_entry_pathname(ae)) == 0) { + /* A regular file. */ + assertEqualString(path3, archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(4090, archive_entry_size(ae)); + assertEqualInt(0, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(0, offset); + assertEqualMem(p, "hello 153\n", 10); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("sym1", archive_entry_pathname(ae)) == 0) { + /* A symlink to the regular file. */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString(path1, archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("sym2", archive_entry_pathname(ae)) == 0) { + /* A symlink to the regular file. */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString(path2, archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("sym3", archive_entry_pathname(ae)) == 0) { + /* A symlink to the regular file. */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString(path3, archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else { + failure("Saw a file that shouldn't have been there"); + assertEqualString(archive_entry_pathname(ae), ""); + } + } + + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify archive format. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); + + /* Close the archive. */ + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_new_bz2.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_new_bz2.c new file mode 100644 index 000000000..633959af9 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_new_bz2.c @@ -0,0 +1,204 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isorr_new_bz2.c 201247 2009-12-30 05:59:21Z kientzle $"); + + +/* +PLEASE use latest cdrtools at least mkisofs version is 2.01.01a63 or later. +Old version mkisofs made wrong "SL" System Use Entry of RRIP. + +Execute the following command to rebuild the data for this program: + tail -n +34 test_read_format_isorr_new_bz2.c | /bin/sh + +rm -rf /tmp/iso +mkdir /tmp/iso +mkdir /tmp/iso/dir +echo "hello" >/tmp/iso/file +dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file +ln /tmp/iso/file /tmp/iso/hardlink +(cd /tmp/iso; ln -s file symlink) +(cd /tmp/iso; ln -s /tmp/ symlink2) +(cd /tmp/iso; ln -s /tmp/../ symlink3) +(cd /tmp/iso; ln -s .././../tmp/ symlink4) +(cd /tmp/iso; ln -s .///file symlink5) +(cd /tmp/iso; ln -s /tmp//../ symlink6) +TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir +TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink +F=test_read_format_iso_rockridge_new.iso.Z +mkhybrid -R -uid 1 -gid 2 /tmp/iso | compress > $F +uuencode $F $F > $F.uu +exit 1 + */ + +DEFINE_TEST(test_read_format_isorr_new_bz2) +{ + const char *refname = "test_read_format_iso_rockridge_new.iso.Z"; + struct archive_entry *ae; + struct archive *a; + const void *p; + size_t size; + off_t offset; + int i; + + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_compression_all(a)); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* Retrieve each of the 8 files on the ISO image and + * verify that each one is what we expect. */ + for (i = 0; i < 10; ++i) { + assertEqualInt(0, archive_read_next_header(a, &ae)); + + if (strcmp(".", archive_entry_pathname(ae)) == 0) { + /* '.' root directory. */ + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + /* Now, we read timestamp recorded by RRIP "TF". */ + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + /* Now, we read links recorded by RRIP "PX". */ + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt((int)size, 0); + } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { + /* A regular file. */ + assertEqualString("hardlink", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(12345684, archive_entry_size(ae)); + assertEqualInt(0, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(0, offset); + assertEqualMem(p, "hello\n", 6); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { + /* A hardlink to the regular file. */ + /* Note: If "hardlink" gets returned before "file", + * then "hardlink" will get returned as a regular file + * and "file" will get returned as the hardlink. + * This test should tolerate that, since it's a + * perfectly permissible thing for libarchive to do. */ + assertEqualString("file", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualString("hardlink", archive_entry_hardlink(ae)); + assertEqualInt(0, archive_entry_size_is_set(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { + /* A symlink to the regular file. */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("file", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(172802, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { + /* A symlink to /tmp/ (an absolute path) */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("/tmp/", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { + /* A symlink to /tmp/../ (with a ".." component) */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("/tmp/../", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { + /* A symlink to a path with ".." and "." components */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString(".././../tmp/", + archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { + /* A symlink to the regular file with "/" components. */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString(".///file", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(172802, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { + /* A symlink to /tmp//../ + * (with "/" and ".." components) */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("/tmp//../", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else { + failure("Saw a file that shouldn't have been there"); + assertEqualString(archive_entry_pathname(ae), ""); + } + } + + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify archive format. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); + + /* Close the archive. */ + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_rr_moved.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_rr_moved.c new file mode 100644 index 000000000..d59b34640 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isorr_rr_moved.c @@ -0,0 +1,270 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isorr_rr_moved.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* +Execute the following command to rebuild the data for this program: + tail -n +32 test_read_format_isorr_rr_moved.c | /bin/sh + +dirname=/tmp/iso +rm -rf $dirname +mkdir -p $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10 +echo "hello" >$dirname/file +dd if=/dev/zero count=1 bs=12345678 >>$dirname/file +deepfile=$dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/deep +echo "hello" >$deepfile +dd if=/dev/zero count=1 bs=12345678 >>$deepfile +time="197001020000.01" +TZ=utc touch -afhm -t $time $deepfile +TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10 +TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9 +TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8 +TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7 +TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6 +TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5 +TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4 +TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3 +TZ=utc touch -afhm -t $time $dirname/dir1/dir2 +TZ=utc touch -afhm -t $time $dirname/dir1 +TZ=utc touch -afhm -t $time $dirname/file +TZ=utc touch -afhm -t $time $dirname +F=test_read_format_isorr_rockridge_moved.iso.Z +mkhybrid -R -uid 1 -gid 2 $dirname | compress > $F +uuencode $F $F > $F.uu +exit 1 + */ + +DEFINE_TEST(test_read_format_isorr_rr_moved) +{ + const char *refname = "test_read_format_iso_rockridge_rr_moved.iso.Z"; + struct archive_entry *ae; + struct archive *a; + const void *p; + size_t size; + off_t offset; + int i; + + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_compression_all(a)); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* Retrieve each of the 8 files on the ISO image and + * verify that each one is what we expect. */ + for (i = 0; i < 13; ++i) { + assertEqualInt(0, archive_read_next_header(a, &ae)); + + if (strcmp(".", archive_entry_pathname(ae)) == 0) { + /* '.' root directory. */ + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + /* Now, we read timestamp recorded by RRIP "TF". */ + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + /* Now, we read links recorded by RRIP "PX". */ + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt((int)size, 0); + } else if (strcmp("dir1", archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2", + archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1/dir2", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2/dir3", + archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1/dir2/dir3", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2/dir3/dir4", + archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1/dir2/dir3/dir4", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2/dir3/dir4/dir5", + archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1/dir2/dir3/dir4/dir5", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6", + archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7", + archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7" + "/dir8", + archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7" + "/dir8", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7" + "/dir8/dir9", + archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7" + "/dir8/dir9", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7" + "/dir8/dir9/dir10", + archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7" + "/dir8/dir9/dir10", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { + /* A regular file. */ + assertEqualString("file", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(12345684, archive_entry_size(ae)); + assertEqualInt(0, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(0, offset); + assertEqualMem(p, "hello\n", 6); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7" + "/dir8/dir9/dir10/deep", + archive_entry_pathname(ae)) == 0) { + /* A regular file. */ + assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7" + "/dir8/dir9/dir10/deep", + archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(12345684, archive_entry_size(ae)); + assertEqualInt(0, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt(0, offset); + assertEqualMem(p, "hello\n", 6); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else { + failure("Saw a file that shouldn't have been there"); + assertEqualString(archive_entry_pathname(ae), ""); + } + } + + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify archive format. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); + + /* Close the archive. */ + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_isozisofs_bz2.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isozisofs_bz2.c new file mode 100644 index 000000000..05271cdd8 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_isozisofs_bz2.c @@ -0,0 +1,187 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_isozisofs_bz2.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* +Execute the following command to rebuild the data for this program: + tail -n +32 test_read_format_isozisofs_bz2.c | /bin/sh + +rm -rf /tmp/iso /tmp/ziso +mkdir /tmp/iso +mkdir /tmp/iso/dir +echo "hello" >/tmp/iso/file +dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file +ln /tmp/iso/file /tmp/iso/hardlink +(cd /tmp/iso; ln -s file symlink) +(cd /tmp/iso; ln -s /tmp/ symlink2) +(cd /tmp/iso; ln -s /tmp/../ symlink3) +(cd /tmp/iso; ln -s .././../tmp/ symlink4) +TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir +TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink +mkzftree /tmp/iso /tmp/ziso +TZ=utc touch -afhm -t 197001020000.01 /tmp/ziso /tmp/ziso/file /tmp/ziso/dir +TZ=utc touch -afhm -t 197001030000.02 /tmp/ziso/symlink +F=test_read_format_iso_zisofs.iso.Z +mkhybrid -R -uid 1 -gid 2 -z /tmp/ziso | compress > $F +uuencode $F $F > $F.uu +exit 1 + + */ + +DEFINE_TEST(test_read_format_isozisofs_bz2) +{ + const char *refname = "test_read_format_iso_zisofs.iso.Z"; + struct archive_entry *ae; + struct archive *a; + const void *p; + size_t size; + off_t offset; + int i; + + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(0, archive_read_support_compression_all(a)); + assertEqualInt(0, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* Retrieve each of the 8 files on the ISO image and + * verify that each one is what we expect. */ + for (i = 0; i < 8; ++i) { + assertEqualInt(0, archive_read_next_header(a, &ae)); + + if (strcmp(".", archive_entry_pathname(ae)) == 0) { + /* '.' root directory. */ + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + /* Now, we read timestamp recorded by RRIP "TF". */ + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + /* Now, we read links recorded by RRIP "PX". */ + assertEqualInt(3, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &p, &size, &offset)); + assertEqualInt((int)size, 0); + } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { + /* A directory. */ + assertEqualString("dir", archive_entry_pathname(ae)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + assertEqualInt(2048, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { + int r; + /* A regular file. */ + assertEqualString("hardlink", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(12345684, archive_entry_size(ae)); + r = archive_read_data_block(a, &p, &size, &offset); + if (r == ARCHIVE_FAILED) { + skipping("Can't read body of ZISOFS entry."); + } else { + assertEqualInt(ARCHIVE_OK, r); + assertEqualInt(0, offset); + assertEqualMem(p, "hello\n", 6); + } + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { + /* A hardlink to the regular file. */ + /* Note: If "hardlink" gets returned before "file", + * then "hardlink" will get returned as a regular file + * and "file" will get returned as the hardlink. + * This test should tolerate that, since it's a + * perfectly permissible thing for libarchive to do. */ + assertEqualString("file", archive_entry_pathname(ae)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualString("hardlink", archive_entry_hardlink(ae)); + assertEqualInt(0, archive_entry_size_is_set(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(86401, archive_entry_mtime(ae)); + assertEqualInt(86401, archive_entry_atime(ae)); + assertEqualInt(2, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { + /* A symlink to the regular file. */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("file", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(172802, archive_entry_mtime(ae)); + assertEqualInt(172802, archive_entry_atime(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { + /* A symlink to /tmp (an absolute path) */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("/tmp", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { + /* A symlink to /tmp/.. (with a ".." component) */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString("/tmp/..", archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { + /* A symlink to a path with ".." and "." components */ + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); + assertEqualString(".././../tmp", + archive_entry_symlink(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualInt(1, archive_entry_stat(ae)->st_nlink); + assertEqualInt(1, archive_entry_uid(ae)); + assertEqualInt(2, archive_entry_gid(ae)); + } else { + failure("Saw a file that shouldn't have been there"); + assertEqualString(archive_entry_pathname(ae), ""); + } + } + + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Verify archive format. */ + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); + + /* Close the archive. */ + assertEqualInt(0, archive_read_close(a)); + assertEqualInt(0, archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_mtree.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_mtree.c new file mode 100644 index 000000000..ce6e92086 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_mtree.c @@ -0,0 +1,143 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_mtree.c 201247 2009-12-30 05:59:21Z kientzle $"); + +static void +test_read_format_mtree1(void) +{ + const char reffile[] = "test_read_format_mtree.mtree"; + char buff[16]; + struct archive_entry *ae; + struct archive *a; + FILE *f; + + extract_reference_file(reffile); + + /* + * An access error occurred on some platform when mtree + * format handling open a directory. It is for through + * the routine which open a directory that we create + * "dir" and "dir2" directories. + */ + assertMakeDir("dir", 0775); + assertMakeDir("dir2", 0775); + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_file(a, reffile, 11)); + + /* + * Read "file", whose data is available on disk. + */ + f = fopen("file", "wb"); + assert(f != NULL); + assertEqualInt(3, fwrite("hi\n", 1, 3, f)); + fclose(f); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); + assertEqualString(archive_entry_pathname(ae), "file"); + assertEqualInt(archive_entry_uid(ae), 18); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); + assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123); + assertEqualInt(archive_entry_size(ae), 3); + assertEqualInt(3, archive_read_data(a, buff, 3)); + assertEqualMem(buff, "hi\n", 3); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir"); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir/file with space"); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "file with space"); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2"); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/dir3a"); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a"); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/fullindir2"); + assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/indir2"); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/dir3b"); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b"); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "notindir"); + + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + +static void +test_read_format_mtree2(void) +{ + static char archive[] = + "#mtree\n" + "d type=dir content=.\n"; + struct archive_entry *ae; + struct archive *a; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); + assertEqualString(archive_entry_pathname(ae), "d"); + assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + + + +DEFINE_TEST(test_read_format_mtree) +{ + test_read_format_mtree1(); + test_read_format_mtree2(); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_mtree.mtree.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_mtree.mtree.uu new file mode 100644 index 000000000..1634d0015 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_mtree.mtree.uu @@ -0,0 +1,13 @@ +$FreeBSD: head/lib/libarchive/test/test_read_format_mtree.mtree.uu 201247 2009-12-30 05:59:21Z kientzle $ + +begin 644 test_read_format_mtree.mtree +M(VUT7!E/61I<@H@9FEL95PP-#!W:71H7#`T,'-P86-E('1Y<&4]9FEL +M92!U:60],3@*("XN"F9I;&5<,#0P=VET:%PP-#!S<&%C92!T>7!E/69I;&4* +M9&ER,B!T>7!E/61I<@H@9&ER,V$@='EP93UD:7(*("!I;F1I7!E/61I<@H@(&EN9&ER,V(@ +M='EP93UF:6QE"B`@+BX*("XN"FYO=&EN9&ER('1Y<&4]9FEL90ID:7(R+V9U +3;&QI;F1I',205,'f',29,170,227,'[',179,139, +'\'','L','o',211,':',178,'0',162,134,'*','>','8',24,153,230,147,'R','?',23, +'r','E','8','P',144,237,7,140,'W'}; + +DEFINE_TEST(test_read_format_tbz) +{ + struct archive_entry *ae; + struct archive *a; + int r; + + assert((a = archive_read_new()) != NULL); + r = archive_read_support_compression_bzip2(a); + if (r != ARCHIVE_OK) { + skipping("Bzip2 support"); + archive_read_finish(a); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_tgz.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_tgz.c new file mode 100644 index 000000000..f411b4338 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_tgz.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_tgz.c 191183 2009-04-17 01:06:31Z kientzle $"); + +static unsigned char archive[] = { +31,139,8,0,222,'C','p','C',0,3,211,'c',160,'=','0','0','0','0','7','5','U', +0,210,134,230,166,6,200,'4',28,'(',24,26,24,27,155,24,152,24,154,27,155,')', +24,24,26,152,154,25,'2','(',152,210,193,'m',12,165,197,'%',137,'E','@',167, +148,'d',230,226,'U','G','H',30,234,15,'8','=',10,'F',193,'(',24,5,131,28, +0,0,29,172,5,240,0,6,0,0}; + +DEFINE_TEST(test_read_format_tgz) +{ + struct archive_entry *ae; + struct archive *a; + int r; + + assert((a = archive_read_new()) != NULL); + assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualInt(ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_GZIP); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK,archive_read_finish(a)); +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_tlz.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_tlz.c new file mode 100644 index 000000000..7dd09a0c5 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_tlz.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_tlz.c 201247 2009-12-30 05:59:21Z kientzle $"); + +static unsigned char archive[] = { + 93, 0, 0,128, 0,255,255,255,255,255,255,255,255, 0, 23, 0, + 51, 80, 24,164,204,238, 45, 77, 28,191, 13,144, 8, 10, 70, 5, +173,215, 47,132,237,145,162, 96, 6,131,168,152, 8,135,161,189, + 73,110,132, 27,195, 52,109,203, 22, 17,168,211, 18,181, 76, 93, +120, 88,154,155,244,141,193,206,170,224, 80,137,134, 67, 1, 9, +123,121,189, 74,137,197, 63,255,214, 55,119, 0 +}; + +DEFINE_TEST(test_read_format_tlz) +{ + struct archive_entry *ae; + struct archive *a; + int r; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("lzma reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_LZMA); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_txz.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_txz.c new file mode 100644 index 000000000..acff175c5 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_txz.c @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_txz.c 191183 2009-04-17 01:06:31Z kientzle $"); + +static unsigned char archive[] = { +253, 55,122, 88, 90, 0, 0, 4,230,214,180, 70, 2, 0, 33, 1, + 22, 0, 0, 0,116, 47,229,163,224, 5,255, 0, 73, 93, 0, 23, + 0, 51, 80, 24,164,204,238, 45, 77, 28,191, 13,144, 8, 10, 70, + 5,173,215, 47,132,237,145,162, 96, 6,131,168,152, 8,135,161, +189, 73,110,132, 27,195, 52,109,203, 22, 17,168,211, 18,181, 76, + 93,120, 88,154,155,244,141,193,206,170,224, 80,137,134, 67, 1, + 9,123,121,188,247, 28,139, 0, 0, 0, 0, 0,112,184, 17, 5, +103, 16, 8, 73, 0, 1,101,128, 12, 0, 0, 0, 30, 69, 92, 96, +177,196,103,251, 2, 0, 0, 0, 0, 4, 89, 90 +}; + +DEFINE_TEST(test_read_format_txz) +{ + struct archive_entry *ae; + struct archive *a; + int r; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_tz.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_tz.c new file mode 100644 index 000000000..eb0660138 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_tz.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_tz.c 189381 2009-03-05 00:31:48Z kientzle $"); + +static unsigned char archive[] = { +31,157,144,'.',0,8,28,'H',176,160,193,131,8,19,'*','\\',200,176,'!','B',24, +16,'o',212,168,1,2,0,196,24,18,'a','T',188,152,'q','#',196,143,' ','5',198, +128,'1','c',6,13,24,'4','0',206,176,1,2,198,200,26,'6','b',0,0,'Q',195,161, +205,155,'8','s',234,4,'P','g',14,157,'0','r',',',194,160,147,166,205,206, +132,'D',141,30,'=',24,'R',163,'P',144,21,151,'J',157,'J',181,170,213,171, +'X',179,'j',221,202,181,171,215,175,'`',195,138,29,'K',182,172,217,179,'h', +211,170,']',203,182,173,219,183,'g',1}; + +DEFINE_TEST(test_read_format_tz) +{ + struct archive_entry *ae; + struct archive *a; + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + failure("archive_compression_name(a)=\"%s\"", + archive_compression_name(a)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); + failure("archive_format_name(a)=\"%s\"", archive_format_name(a)); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +#endif +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_xar.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_xar.c new file mode 100644 index 000000000..a69667760 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_xar.c @@ -0,0 +1,697 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +#define UID 1001 +#define UNAME "cue" +#define GID 1001 +#define GNAME "cue" + +/* Verify that a file records with hardlink. +#How to make +echo "hellohellohello" > f1 +chown $UNAME:$GNAME f1 +chmod 0644 f1 +ln f1 hardlink +chown $UNAME:$GNAME hardlink +chmod 0644 hardlink +env TZ=utc touch -afm -t 197001020000.01 f1 hardlink +xar -cf archive1.xar f1 hardlink +od -t x1 archive1.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive1.xar.txt +*/ +static unsigned char archive1[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xc6, +0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x70,0x00,0x00,0x00,0x01,0x78,0xda,0xc4,0x54, +0xc9,0x6e,0xdb,0x30,0x14,0xbc,0xe7,0x2b,0x08,0xdd,0x55,0xae,0xb6,0x45,0x83,0x56, +0xd0,0x4b,0xd1,0x7b,0xd3,0x4b,0x6f,0x34,0x17,0x89,0x88,0x36,0x48,0x54,0xe0,0xe4, +0xeb,0x4b,0x52,0x52,0x0c,0xa7,0x71,0x6f,0x45,0x01,0x01,0x1a,0x0e,0x87,0xa3,0xa7, +0xf7,0x06,0x14,0x8f,0x97,0xb6,0x01,0x2f,0x66,0x9c,0x5c,0xdf,0x9d,0x32,0xfc,0x05, +0x65,0xc0,0x74,0xaa,0xd7,0xae,0xab,0x4e,0xd9,0xcf,0xa7,0x6f,0x79,0x91,0x3d,0x96, +0x0f,0xe2,0x22,0xc7,0xf2,0x01,0x08,0xdf,0xab,0xf0,0x02,0x42,0x8d,0x46,0xfa,0x70, +0x22,0xf7,0xae,0x35,0x25,0x41,0x88,0xe7,0x98,0xe4,0x88,0x3c,0x61,0x7a,0xa4,0xe8, +0x48,0xb9,0x80,0xb7,0x92,0x74,0xa8,0x36,0xea,0x79,0x9a,0x5b,0x30,0xf9,0xd7,0xc6, +0x9c,0xb2,0xa9,0x96,0x38,0x8b,0x3b,0x40,0xf4,0xd6,0x4e,0xc6,0x97,0x48,0xc0,0x15, +0x25,0x76,0x72,0x6f,0xd1,0x5c,0xc0,0x04,0xa2,0x05,0xdc,0x3c,0xd2,0xca,0xba,0xc6, +0x00,0xa7,0x4f,0x19,0x59,0x6d,0xd4,0x9d,0x72,0xd8,0xaf,0x70,0x72,0xab,0x03,0x88, +0x36,0x41,0xcc,0x0f,0x28,0x47,0x38,0xca,0x10,0x3a,0xc6,0x07,0x07,0x59,0x7b,0x95, +0xc9,0x7b,0x3f,0x17,0x64,0xf2,0x2a,0xab,0xc6,0x7e,0x1e,0x4a,0x35,0x1b,0x01,0x17, +0xb8,0xb0,0x4e,0x97,0x18,0x21,0x1c,0xc8,0x80,0x12,0x35,0x4f,0x66,0x5c,0x74,0x09, +0x2d,0xdc,0xbb,0x6c,0xde,0x64,0x6d,0xaf,0x4d,0x89,0xf6,0x8c,0x85,0x62,0x22,0x4c, +0xa4,0x7f,0x1d,0x0c,0x68,0x5c,0xf7,0x1c,0x66,0x94,0x95,0xb5,0x1c,0x75,0x5c,0x08, +0x18,0xf9,0x45,0xd1,0xc9,0x50,0xd0,0x75,0x23,0x2d,0x53,0xcb,0x62,0x97,0x6e,0xdb, +0xb5,0x75,0x5d,0x4b,0x2f,0x13,0x02,0xa2,0x31,0x5d,0xe5,0xeb,0x92,0x50,0x01,0x57, +0xb8,0xf0,0xeb,0x38,0xc8,0xed,0x64,0xd6,0xd1,0xe0,0xfd,0x75,0x34,0x81,0xdb,0x72, +0xb3,0xcd,0x57,0x0e,0x43,0xe3,0x54,0x0a,0x01,0xbc,0xe4,0xd5,0x9b,0x1b,0x32,0xb8, +0x4a,0xe5,0xa8,0x6a,0xf7,0x62,0x74,0xfe,0x31,0x13,0x3f,0xbe,0x7f,0x0d,0xd5,0xd9, +0x82,0x52,0x4d,0xac,0x56,0x98,0x53,0xc6,0xa9,0x3c,0xb3,0x82,0x4b,0x2d,0x09,0xb5, +0x85,0x3d,0x70,0x6c,0xf7,0xc4,0x2a,0xba,0xe7,0x45,0x98,0xc3,0x47,0xa3,0xad,0x96, +0x8b,0x1f,0xa5,0xf2,0x77,0xbf,0xb0,0xd3,0x07,0x76,0x56,0x67,0x75,0xe0,0x9a,0x5a, +0x7e,0xb6,0x4c,0xda,0xe0,0xcd,0x8a,0xa2,0x40,0x86,0xed,0xc8,0x7e,0xc7,0xac,0x41, +0x8a,0x87,0x1c,0xff,0xe9,0xb4,0x34,0x0f,0xbe,0x77,0xef,0x9f,0xc4,0xee,0x73,0xd9, +0x7f,0x8c,0x5d,0x3f,0xba,0xca,0x75,0xb2,0xf9,0x4b,0xfa,0x2c,0xfe,0x24,0x77,0x41, +0x15,0x2f,0x0d,0x01,0xd3,0x15,0xf2,0x1b,0x00,0x00,0xff,0xff,0x03,0x00,0x88,0x32, +0x49,0x7b,0x67,0xbf,0xc6,0x01,0x29,0xf2,0x1c,0x40,0x05,0x3c,0x49,0x25,0x9f,0xab, +0x7c,0x8e,0xc5,0xa5,0x79,0xe0,0x78,0xda,0xca,0x48,0xcd,0xc9,0xc9,0xcf,0x80,0x13, +0x5c,0x00,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7,0x06,0x47 +}; + +static void verify0(struct archive *a, struct archive_entry *ae) +{ + const void *p; + size_t size; + off_t offset; + + assert(archive_entry_filetype(ae) == AE_IFREG); + assertEqualInt(archive_entry_mode(ae) & 0777, 0644); + assertEqualInt(archive_entry_uid(ae), UID); + assertEqualInt(archive_entry_gid(ae), GID); + assertEqualString(archive_entry_uname(ae), UNAME); + assertEqualString(archive_entry_gname(ae), GNAME); + assertEqualString(archive_entry_pathname(ae), "f1"); + assert(archive_entry_hardlink(ae) == NULL); + assert(archive_entry_symlink(ae) == NULL); + assertEqualInt(archive_entry_mtime(ae), 86401); + assertEqualInt(archive_entry_size(ae), 16); + assertEqualInt(archive_read_data_block(a, &p, &size, &offset), 0); + assertEqualInt((int)size, 16); + assertEqualInt((int)offset, 0); + assertEqualInt(memcmp(p, "hellohellohello\n", 16), 0); +} + +static void verify1(struct archive *a, struct archive_entry *ae) +{ + (void)a; /* UNUSED */ + /* A hardlink is not a symlink. */ + assert(archive_entry_filetype(ae) != AE_IFLNK); + /* Nor is it a directory. */ + assert(archive_entry_filetype(ae) != AE_IFDIR); + assertEqualInt(archive_entry_mode(ae) & 0777, 0644); + assertEqualInt(archive_entry_uid(ae), UID); + assertEqualInt(archive_entry_gid(ae), GID); + assertEqualString(archive_entry_uname(ae), UNAME); + assertEqualString(archive_entry_gname(ae), GNAME); + assertEqualString(archive_entry_pathname(ae), "hardlink"); + assertEqualString(archive_entry_hardlink(ae), "f1"); + assert(archive_entry_symlink(ae) == NULL); + assertEqualInt(archive_entry_mtime(ae), 86401); + assertEqualInt(archive_entry_nlink(ae), 2); +} + +/* Verify that symlinks are read correctly. +#How to make +echo "hellohellohello" > f1 +chown $UNAME:$GNAME f1 +chmod 0644 f1 +ln -s f1 symlink +chown $UNAME:$GNAME symlink +chmod 0644 symlink +env TZ=utc touch -afm -t 197001020000.01 f1 symlink +xar -cf archive2.xar f1 symlink +od -t x1 archive2.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive2.xar.txt +*/ +static unsigned char archive2[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xe8, +0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x84,0x00,0x00,0x00,0x01,0x78,0xda,0xb4,0x54, +0xcb,0x6e,0xa3,0x30,0x14,0xdd,0xf7,0x2b,0x90,0xf7,0x8c,0x1f,0x40,0x82,0x23,0xe3, +0xaa,0x9b,0x6a,0xf6,0xd3,0xd9,0xcc,0xce,0xf1,0x83,0x58,0xe5,0x25,0x70,0xaa,0xa4, +0x5f,0x3f,0xb6,0x09,0x4d,0xd3,0x30,0xdd,0x8d,0x84,0xc4,0xf5,0xf1,0xb9,0xc7,0x97, +0x7b,0x0f,0x66,0x8f,0xa7,0xb6,0x49,0xde,0xf4,0x38,0xd9,0xbe,0xab,0x00,0xfe,0x81, +0x40,0xa2,0x3b,0xd9,0x2b,0xdb,0xd5,0x15,0xf8,0xfd,0xf2,0x9c,0x96,0xe0,0x91,0x3f, +0xb0,0x93,0x18,0xf9,0x43,0xc2,0x5c,0x2f,0xfd,0x2b,0x61,0x72,0xd4,0xc2,0xf9,0x8c, +0xd4,0xd9,0x56,0x73,0x82,0x10,0x4d,0x31,0x49,0x11,0x79,0xc1,0xd9,0x2e,0x2b,0x76, +0xb8,0x60,0xf0,0x96,0x12,0x93,0x0e,0x5a,0xbe,0x4e,0xc7,0x36,0x99,0xdc,0xb9,0xd1, +0x15,0x98,0x0e,0x02,0x83,0xb0,0x93,0xb0,0xde,0x98,0x49,0x3b,0x8e,0x18,0xbc,0x44, +0x11,0x9d,0xec,0x7b,0x10,0x67,0x30,0x06,0x41,0x02,0x2e,0x1a,0x71,0x65,0x6c,0xa3, +0x13,0xab,0x2a,0x40,0x2e,0x32,0xf2,0xae,0x1c,0xb4,0xcb,0xd1,0x0e,0xd1,0x3f,0x3e, +0x73,0xa9,0x23,0x61,0xed,0x37,0xb4,0xf6,0x4a,0x13,0xdf,0xd0,0xc4,0x95,0x56,0x8f, +0xfd,0x71,0xe0,0xf2,0xa8,0x19,0x9c,0xc3,0x19,0xb5,0x8a,0x63,0x84,0xb0,0x07,0x7d, +0x14,0xa1,0xe3,0xa4,0xc7,0x99,0x17,0xa3,0x19,0xfb,0xa0,0x1d,0x17,0x5a,0xdb,0x2b, +0xcd,0xd1,0xb6,0xf0,0x3d,0x8c,0x61,0x04,0x1b,0xdb,0xbd,0x26,0xee,0x3c,0xf8,0xb6, +0x85,0xaf,0x06,0xdc,0xf8,0x94,0x00,0xce,0xdb,0x61,0x87,0x4f,0xe7,0x36,0x20,0x0c, +0xc6,0x55,0xc4,0x3b,0xd1,0x7e,0xc2,0xe3,0x2a,0xb6,0x31,0x68,0xdc,0xb6,0x70,0x99, +0x84,0x12,0x4e,0xc4,0xc8,0x9f,0xa9,0xbb,0xda,0x1d,0x38,0xc9,0xfc,0x49,0x73,0x38, +0xe3,0x97,0x11,0x91,0xdb,0x69,0x5d,0xc6,0x85,0x37,0xd7,0x71,0x79,0x6c,0xf1,0xd2, +0x32,0x73,0x31,0x0c,0x8d,0x95,0xd1,0x18,0xf0,0x94,0xd6,0xef,0x76,0x00,0xf0,0x42, +0x15,0xa3,0x3c,0xd8,0x37,0xad,0xd2,0xaf,0x3e,0xf9,0xf5,0xf3,0xc9,0x57,0x67,0xca, +0x2c,0x53,0xc4,0x28,0x89,0x69,0x96,0xd3,0x4c,0xec,0xf3,0x92,0x0a,0x25,0x48,0x66, +0x4a,0xb3,0xa5,0xd8,0x6c,0x88,0x91,0xd9,0x86,0x96,0x7e,0x36,0x5f,0x85,0x96,0x5a, +0x4e,0x6e,0x14,0xd2,0xfd,0xf3,0x84,0x42,0x6d,0xf3,0xbd,0xdc,0xcb,0x2d,0x55,0x99, +0xa1,0x7b,0x93,0x0b,0xe3,0xb5,0xf3,0xb2,0x2c,0x91,0xce,0x0b,0xb2,0x29,0x72,0xa3, +0x91,0xa4,0x94,0xc1,0x7b,0xa5,0xb9,0x79,0xf0,0xa3,0x7b,0x2b,0x56,0x9c,0xff,0x0c, +0xb2,0x66,0x45,0x4c,0xb7,0x28,0x45,0x38,0xd0,0x90,0x37,0x98,0x7f,0xf0,0x9a,0x15, +0xd7,0x69,0xff,0xdd,0x8a,0x9b,0x3c,0xff,0x6c,0xc5,0xe0,0xae,0x24,0x18,0xaa,0x02, +0xfd,0x68,0x6b,0xdb,0x89,0x06,0xf0,0x83,0x18,0xd5,0xaa,0xf9,0x82,0x4f,0xef,0x7c, +0xe7,0x59,0xe1,0x22,0x61,0x30,0x5e,0x2b,0x7f,0x01,0x00,0x00,0xff,0xff,0x03,0x00, +0x2b,0xab,0x4f,0xf9,0xbb,0xf7,0x90,0xb5,0x34,0x8f,0x7c,0xae,0x72,0xa0,0x80,0xd2, +0x69,0xc7,0xa2,0xe7,0x44,0x53,0xeb,0x75,0x78,0xda,0xca,0x48,0xcd,0xc9,0xc9,0xcf, +0x80,0x13,0x5c,0x00,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7,0x06,0x47 +}; + +static void verify2(struct archive *a, struct archive_entry *ae) +{ + (void)a; /* UNUSED */ + assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); + assertEqualInt(archive_entry_mode(ae) & 0777, 0755); + assertEqualInt(archive_entry_uid(ae), UID); + assertEqualInt(archive_entry_gid(ae), GID); + assertEqualString(archive_entry_uname(ae), UNAME); + assertEqualString(archive_entry_gname(ae), GNAME); + assertEqualString(archive_entry_pathname(ae), "symlink"); + assertEqualString(archive_entry_symlink(ae), "f1"); + assert(archive_entry_hardlink(ae) == NULL); +} + +/* Character device node. +#How to make +mknod devchar c 0 30 +chown $UNAME:$GNAME devchar +chmod 0644 devchar +env TZ=utc touch -afm -t 197001020000.01 devchar +xar -cf archive3.xar devchar +od -t x1 archive3.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive3.xar.txt +*/ +static unsigned char archive3[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x38, +0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x3b,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x92, +0x4d,0x6e,0xc3,0x20,0x10,0x85,0xf7,0x39,0x05,0xf2,0xde,0x05,0x9c,0x9f,0x36,0xd6, +0x84,0xec,0x7a,0x82,0x74,0xd3,0x1d,0xc2,0x93,0x98,0xd4,0x36,0x11,0xe0,0x28,0xe9, +0xe9,0x0b,0xe3,0xa4,0x69,0xa5,0xaa,0x92,0x25,0x1e,0x8f,0xef,0x8d,0x86,0xc1,0xb0, +0xbd,0xf4,0x1d,0x3b,0xa3,0x0f,0xd6,0x0d,0x9b,0x42,0x3e,0x89,0x82,0xe1,0x60,0x5c, +0x63,0x87,0xc3,0xa6,0x78,0xdb,0xbd,0x96,0x2f,0xc5,0x56,0xcd,0xe0,0xa2,0xbd,0x9a, +0x31,0x88,0xce,0xa4,0x85,0x81,0xf1,0xa8,0x63,0x4a,0x94,0xd1,0xf6,0xa8,0x2a,0x21, +0xd6,0xa5,0xac,0x4a,0x51,0xed,0xa4,0xa8,0xab,0x79,0x2d,0x57,0xc0,0x7f,0x23,0x14, +0x6a,0xd1,0x7c,0x84,0xb1,0x67,0x21,0x5e,0x3b,0xdc,0x14,0xa1,0xd5,0xb2,0xc8,0x27, +0x0c,0xdc,0x7e,0x1f,0x30,0x2a,0x01,0xfc,0xa6,0xc8,0x0d,0xf6,0x33,0x17,0x07,0x4e, +0x22,0x97,0xe0,0xf7,0x1a,0xb4,0xdb,0xdb,0x0e,0x99,0x6d,0x52,0xdb,0xb7,0x32,0xe6, +0xaf,0x76,0xaa,0x7a,0xb9,0x7c,0x4f,0xc9,0x7b,0x1f,0x0c,0x7a,0x92,0x72,0xfd,0x2c, +0x4a,0x21,0x33,0x26,0x44,0x9d,0x3f,0x99,0xb0,0xfe,0x81,0xe9,0x7f,0x30,0xfd,0xc0, +0x0e,0xde,0x8d,0x27,0x65,0x46,0x04,0x3e,0xc9,0xc9,0xb5,0x8d,0x92,0x42,0xc8,0x64, +0x26,0x45,0xd6,0x18,0xd0,0x4f,0x1c,0xa9,0xc9,0xfb,0xc6,0xc6,0x3b,0xd6,0xbb,0x06, +0x95,0x58,0x2d,0x16,0xa9,0x99,0x2c,0xc9,0x6c,0xf0,0x6c,0xcd,0xa4,0x13,0x61,0x07, +0xe7,0xd5,0x3c,0x0d,0x66,0x52,0x37,0x57,0x1f,0x93,0xce,0x26,0x09,0x8a,0xf1,0x1f, +0x39,0x88,0xd7,0x13,0x2a,0xd3,0x6a,0xaf,0x4d,0x44,0xcf,0xc2,0x09,0x8d,0xd5,0x1d, +0x70,0xf2,0x89,0x18,0x74,0xba,0x54,0x8a,0x64,0x08,0x38,0xed,0x68,0xea,0x79,0xd0, +0xf9,0xf9,0x39,0xbd,0x3f,0x70,0xfa,0x1b,0xbe,0x00,0x00,0x00,0xff,0xff,0x03,0x00, +0xab,0x43,0xa3,0xac,0x76,0x40,0x1e,0x8b,0x95,0x0d,0x28,0x79,0x79,0x43,0x49,0x4e, +0x16,0xa1,0x56,0x99,0x1f,0x83,0x77,0x41 +}; + +static void verify3(struct archive *a, struct archive_entry *ae) +{ + (void)a; /* UNUSED */ + assertEqualInt(archive_entry_filetype(ae), AE_IFCHR); + assertEqualInt(archive_entry_mode(ae) & 0777, 0644); + assertEqualInt(archive_entry_uid(ae), UID); + assertEqualInt(archive_entry_gid(ae), GID); + assertEqualString(archive_entry_uname(ae), UNAME); + assertEqualString(archive_entry_gname(ae), GNAME); + assertEqualString(archive_entry_pathname(ae), "devchar"); + assert(archive_entry_symlink(ae) == NULL); + assert(archive_entry_hardlink(ae) == NULL); + assertEqualInt(archive_entry_mtime(ae), 86401); +} + +/* Block device node. +#How to make +mknod devblock b 0 30 +chown $UNAME:$GNAME devblock +chmod 0644 devblock +env TZ=utc touch -afm -t 197001020000.01 devblock +xar -cf archive4.xar devblock +od -t x1 archive4.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive4.xar.txt +*/ +static unsigned char archive4[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x34, +0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x38,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x92, +0xc1,0x6e,0xc2,0x30,0x0c,0x86,0xef,0x3c,0x45,0xd4,0x7b,0x17,0x07,0xd0,0x0a,0x95, +0x09,0xb7,0x3d,0x01,0xbb,0xec,0x96,0xa5,0x06,0x32,0xda,0xa6,0x6a,0x5a,0x04,0x7b, +0xfa,0x25,0x2e,0x8c,0x4d,0x9a,0x26,0x55,0xea,0x97,0x3f,0x9f,0x2d,0x37,0x29,0x6e, +0x2f,0x4d,0x2d,0xce,0xd4,0x07,0xe7,0xdb,0x4d,0xa6,0x9e,0x20,0x13,0xd4,0x5a,0x5f, +0xb9,0xf6,0xb0,0xc9,0x5e,0x77,0x2f,0xf9,0x2a,0xdb,0xea,0x19,0x5e,0x4c,0xaf,0x67, +0x02,0x07,0x6f,0xe3,0x4b,0xa0,0xed,0xc9,0x0c,0xb1,0x22,0x1f,0x5c,0x43,0x7a,0x0e, +0xb0,0xce,0xd5,0x3c,0x87,0xf9,0x4e,0x41,0xb9,0x58,0x95,0xaa,0x40,0xf9,0x5b,0xe1, +0xa2,0x23,0xd9,0x53,0x18,0x1b,0x11,0x86,0x6b,0x4d,0x9b,0x2c,0x1c,0x8d,0xca,0xd2, +0x8e,0x40,0xbf,0xdf,0x07,0x1a,0x34,0xa0,0xbc,0x11,0xa7,0xc1,0x7d,0xa6,0xe6,0x28, +0x19,0x52,0x0b,0x79,0xef,0xc1,0xab,0xbd,0xab,0x49,0xb8,0x2a,0x8e,0x7d,0x6b,0x63, +0xff,0x1e,0x07,0x8a,0xb7,0x58,0x79,0x9f,0x43,0x60,0xc3,0xa8,0xd6,0x05,0xe4,0xa0, +0x92,0x06,0x50,0xa6,0x47,0x45,0xad,0x79,0x68,0xe6,0x1f,0xcd,0x3c,0xb4,0x43,0xef, +0xc7,0x4e,0xdb,0x91,0x50,0x4e,0x38,0xa5,0xae,0xd2,0x0a,0x40,0xc5,0x30,0x12,0x47, +0x63,0xa0,0x7e,0xf2,0x98,0xa6,0xec,0x5b,0x1b,0xef,0x5a,0xe3,0x2b,0xd2,0xf0,0xbc, +0x5c,0xc6,0x61,0x12,0x72,0x58,0xd1,0xd9,0xd9,0x89,0xa3,0xe1,0x5a,0xdf,0xeb,0x45, +0x3c,0x98,0x89,0x6e,0xa9,0xf9,0x88,0x9c,0x42,0x06,0x2e,0x93,0x3f,0xea,0x70,0xb8, +0x76,0xa4,0xdf,0x6b,0x6f,0x4f,0x22,0x74,0x64,0x9d,0xa9,0x51,0x72,0xc6,0xbb,0xad, +0x89,0x1f,0x14,0x75,0x16,0x50,0xf2,0x92,0x8f,0x3c,0x9d,0x72,0xba,0x7b,0xc9,0x97, +0x8f,0x92,0x7f,0x85,0x2f,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0xbe,0x66,0xa2,0x82, +0x3a,0x54,0xd3,0x61,0xaa,0x8e,0x30,0x4c,0xc8,0x36,0x3b,0x7a,0xa4,0xb9,0xef,0xfc, +0x7a,0x5d,0x21,0xde +}; + +static void verify4(struct archive *a, struct archive_entry *ae) +{ + (void)a; /* UNUSED */ + assertEqualInt(archive_entry_filetype(ae), AE_IFBLK); + assertEqualInt(archive_entry_mode(ae) & 0777, 0644); + assertEqualInt(archive_entry_uid(ae), UID); + assertEqualInt(archive_entry_gid(ae), GID); + assertEqualString(archive_entry_uname(ae), UNAME); + assertEqualString(archive_entry_gname(ae), GNAME); + assertEqualString(archive_entry_pathname(ae), "devblock"); + assert(archive_entry_symlink(ae) == NULL); + assert(archive_entry_hardlink(ae) == NULL); + assertEqualInt(archive_entry_mtime(ae), 86401); +} + +/* Directory. +#How to make +mkdir dir1 +chown $UNAME:$GNAME dir1 +chmod 0755 dir1 +env TZ=utc touch -afm -t 197001020000.01 dir1 +xar -cf archive5.xar dir1 +od -t x1 archive5.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive5.xar.txt +*/ +static unsigned char archive5[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x16, +0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xec,0x00,0x00,0x00,0x01,0x78,0xda,0x74,0x91, +0xc1,0x6e,0xc2,0x30,0x0c,0x86,0xef,0x3c,0x45,0xd4,0x7b,0x17,0xa7,0x83,0x31,0xaa, +0x34,0xdc,0xf6,0x04,0xec,0xb2,0x5b,0x95,0x1a,0x88,0x68,0x1a,0x94,0xa4,0x13,0xdd, +0xd3,0x2f,0x71,0xe9,0xd0,0xa4,0x4d,0xaa,0xd4,0x3f,0xbf,0x3f,0xff,0xb2,0x6c,0xb9, +0xbf,0xd9,0x9e,0x7d,0xa2,0x0f,0xc6,0x0d,0x4d,0x21,0x9e,0xa0,0x60,0x38,0x68,0xd7, +0x99,0xe1,0xd4,0x14,0xef,0x87,0xb7,0xf2,0xb5,0xd8,0xab,0x95,0xbc,0xb5,0x5e,0xad, +0x98,0x8c,0x4e,0xa7,0x1f,0x93,0xda,0x63,0x1b,0x53,0x47,0x19,0x8d,0x45,0x55,0x01, +0xec,0x4a,0x51,0x95,0x50,0x1d,0x04,0xd4,0x6b,0x51,0xaf,0x37,0x92,0xff,0x46,0xa8, +0xe9,0x8c,0xfa,0x12,0x46,0xcb,0x42,0x9c,0x7a,0x6c,0x8a,0x70,0x6e,0x45,0x91,0x2b, +0x4c,0xba,0xe3,0x31,0x60,0x54,0x20,0xf9,0x5d,0x91,0x1b,0xcc,0x57,0x0e,0x97,0x9c, +0x44,0x8e,0xe0,0x4b,0x06,0xbd,0x8e,0xa6,0x47,0x66,0xba,0x34,0xf6,0x3d,0x46,0xff, +0x3d,0xce,0x33,0x7c,0xa4,0xce,0x65,0x0e,0x26,0x2d,0x49,0xb1,0xdb,0x42,0x09,0x22, +0x63,0x00,0x75,0xfe,0x44,0xc2,0xec,0x03,0x6b,0xff,0x49,0x7b,0x49,0x58,0xfb,0xc0, +0x4e,0xde,0x8d,0x57,0xa5,0x47,0x94,0x7c,0x96,0xb3,0x6b,0x3a,0x25,0x00,0x44,0x32, +0x93,0x22,0x6b,0x0c,0xe8,0x67,0x8e,0xd4,0xec,0xfd,0x60,0xe3,0x82,0x59,0xd7,0xa1, +0x82,0xed,0x26,0xed,0x90,0x24,0x99,0x71,0xba,0xa2,0xea,0x8c,0x47,0x1d,0x9d,0x9f, +0x24,0xa7,0x37,0x55,0x86,0xd6,0x52,0x25,0x45,0x90,0xa4,0x35,0xe5,0xcd,0xe4,0x7b, +0x71,0x3a,0x98,0xe4,0x74,0xbe,0x6f,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x23,0x7a, +0x8c,0x2f,0x78,0xe9,0x69,0x28,0x93,0x14,0x72,0x68,0x8d,0xeb,0x42,0x7b,0xf6,0x0f, +0x70,0x64,0xa3,0xff,0xb9,0x35 +}; + +static void verify5(struct archive *a, struct archive_entry *ae) +{ + (void)a; /* UNUSED */ + assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); + assertEqualInt(archive_entry_mtime(ae), 86401); + assertEqualInt(archive_entry_mode(ae) & 0777, 0755); + assertEqualInt(archive_entry_uid(ae), UID); + assertEqualInt(archive_entry_gid(ae), GID); + assertEqualString(archive_entry_uname(ae), UNAME); + assertEqualString(archive_entry_gname(ae), GNAME); +} + +/* fifo +#How to make +mkfifo -m 0755 fifo +chown $UNAME:$GNAME fifo +env TZ=utc touch -afm -t 197001020000.01 fifo +xar -cf archive6.xar fifo +od -t x1 archive6.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive6.xar.txt +*/ +static unsigned char archive6[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0e, +0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xe7,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x91, +0xc1,0x6e,0xc3,0x20,0x0c,0x86,0xef,0x7d,0x0a,0xc4,0x3d,0xc3,0x64,0xab,0xda,0x46, +0x94,0xde,0xf6,0x04,0xdd,0x65,0x37,0x44,0x9c,0x16,0x2d,0x84,0x2a,0x90,0xa9,0xdd, +0xd3,0x0f,0x9c,0x66,0xd5,0xa4,0x69,0x12,0x52,0xbe,0xfc,0x7c,0xb6,0x2c,0xac,0x0e, +0x57,0xdf,0xb3,0x4f,0x1c,0xa3,0x0b,0xc3,0x9e,0xcb,0x27,0xe0,0x0c,0x07,0x1b,0x5a, +0x37,0x9c,0xf6,0xfc,0xed,0xf8,0x5a,0x6d,0xf9,0x41,0xaf,0xd4,0xd5,0x8c,0x7a,0xc5, +0x54,0x0a,0x36,0x7f,0x98,0xb2,0x23,0x9a,0x94,0x2b,0xaa,0xe4,0x3c,0xea,0x1a,0x60, +0x57,0xc9,0xba,0x82,0xfa,0x28,0x65,0xf3,0x02,0x4d,0xbd,0x55,0xe2,0xb7,0x42,0x45, +0x67,0xb4,0x1f,0x71,0xf2,0x2c,0xa6,0x5b,0x8f,0x7b,0x1e,0xcf,0x46,0xf2,0x72,0xc3, +0x54,0xe8,0xba,0x88,0x49,0x83,0x12,0x77,0xa2,0x34,0xba,0xaf,0xd2,0x5c,0x09,0x82, +0xd2,0x42,0x2c,0x3d,0xe8,0xaf,0x73,0x3d,0x32,0xd7,0xe6,0xb1,0xef,0x6d,0xec,0xdf, +0xe3,0xc8,0xe7,0xf7,0x5c,0xb9,0xcc,0xc1,0x94,0x27,0x94,0xbb,0x0d,0x54,0x20,0x8b, +0x06,0xd0,0x94,0x23,0xb3,0xe6,0x1f,0x9a,0xf9,0x47,0x33,0x0f,0xed,0x34,0x86,0xe9, +0xa2,0xed,0x84,0x4a,0xcc,0x38,0xa7,0xae,0xd5,0x12,0x40,0xe6,0x30,0x13,0x45,0x53, +0xc4,0x71,0xf6,0x88,0xe6,0xec,0x47,0x9b,0x16,0xcd,0x87,0x16,0x35,0x6c,0xd6,0xeb, +0x3c,0x4c,0x41,0x0a,0xd3,0xed,0x82,0xba,0x73,0x5d,0x50,0x82,0x90,0xc2,0xc1,0xf8, +0x25,0x24,0xa4,0x17,0x2a,0x8f,0x52,0x56,0x25,0x68,0x57,0x4a,0xd0,0xe6,0xbe,0x01, +0x00,0x00,0xff,0xff,0x03,0x00,0x44,0x19,0x8a,0x2a,0x82,0xbc,0x8c,0xae,0x97,0xa7, +0x7d,0x65,0xa5,0x82,0xdb,0xaa,0xc2,0xcb,0xbe,0xf0,0x1f,0xd1,0xf9,0x56 +}; + +static void verify6(struct archive *a, struct archive_entry *ae) +{ + (void)a; /* UNUSED */ + assertEqualInt(archive_entry_filetype(ae), AE_IFIFO); + assertEqualInt(archive_entry_mode(ae) & 0777, 0755); + assertEqualInt(archive_entry_uid(ae), UID); + assertEqualInt(archive_entry_gid(ae), GID); + assertEqualString(archive_entry_uname(ae), UNAME); + assertEqualString(archive_entry_gname(ae), GNAME); + assertEqualString(archive_entry_pathname(ae), "fifo"); + assert(archive_entry_symlink(ae) == NULL); + assert(archive_entry_hardlink(ae) == NULL); + assertEqualInt(archive_entry_mtime(ae), 86401); +} + +/* Verify that a file records with directory name. +#How to make +mkdir dir1 +echo "hellohellohello" > dir1/f1 +chown $UNAME:$GNAME dir1/f1 +chmod 0644 dir1/f1 +env TZ=utc touch -afm -t 197001020000.01 dir1/f1 +xar -cf archive7.xar dir1/f1 +od -t x1 archive7.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive7.xar.txt +*/ + +static unsigned char archive7[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xbb, +0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x8a,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x53, +0xc9,0x6e,0xdb,0x30,0x14,0xbc,0xe7,0x2b,0x04,0xdd,0x55,0x2e,0xa2,0x16,0x1a,0xb4, +0x82,0x5e,0x8a,0xdc,0x93,0x5e,0x7a,0xa3,0xb9,0xd8,0x44,0xb5,0x41,0xa2,0x02,0x3b, +0x5f,0x5f,0x92,0xa2,0x1c,0xbb,0x59,0x00,0x01,0x1a,0x3e,0xce,0x1b,0x0d,0x9f,0x86, +0xec,0xf1,0xdc,0xb5,0xc9,0xab,0x9a,0x66,0x33,0xf4,0xfb,0x14,0xfd,0x80,0x69,0xa2, +0x7a,0x31,0x48,0xd3,0x1f,0xf7,0xe9,0xef,0x97,0x5f,0x59,0x9d,0x3e,0x36,0x0f,0xec, +0xcc,0xa7,0xe6,0x21,0x61,0x76,0x10,0xee,0x95,0x30,0x31,0x29,0x6e,0x5d,0x47,0x66, +0x4d,0xa7,0x1a,0x0c,0x21,0xcd,0x10,0xce,0x20,0x7e,0x41,0x68,0x57,0xe0,0x5d,0x51, +0x31,0x70,0x4f,0x09,0x4d,0x27,0x25,0xfe,0xce,0x4b,0x97,0xcc,0xf6,0xd2,0xaa,0x7d, +0x3a,0x9f,0x38,0x4a,0xfd,0x4e,0xc2,0x06,0xad,0x67,0x65,0x1b,0xc8,0x40,0x44,0xa1, +0x3a,0x9b,0x37,0x2f,0xce,0x40,0x00,0x5e,0x02,0x6c,0x1a,0x61,0xa5,0x4d,0xab,0x12, +0x23,0x9d,0xed,0x28,0x63,0x2f,0xa3,0x6a,0xa4,0x99,0x94,0xb0,0xc3,0x74,0x61,0x20, +0xac,0xc3,0x4e,0xcf,0xbb,0xb0,0x83,0x18,0x08,0x30,0x14,0xaf,0xfd,0x78,0xed,0x4f, +0x98,0xe4,0x96,0xaf,0x30,0x61,0xad,0xea,0x8f,0xf6,0xd4,0xe0,0x9c,0x81,0x08,0xe3, +0x46,0xb4,0x88,0xef,0xdd,0x6e,0x7e,0x51,0xf9,0xee,0xd7,0x17,0xb7,0x69,0x6e,0xa7, +0xe6,0xe3,0xd8,0x1a,0x11,0x46,0x03,0xce,0xd9,0xf1,0xcd,0x8c,0x29,0xd8,0xb8,0x7c, +0x12,0x27,0xf3,0xaa,0x64,0xf6,0xff,0xa8,0x9e,0x9f,0x7e,0xba,0x33,0xea,0x3a,0xcf, +0x25,0xd6,0x52,0x20,0x9a,0x13,0x9a,0xf3,0x03,0xa9,0x29,0x97,0x1c,0xe7,0xba,0xd6, +0x15,0x45,0xba,0xc4,0x5a,0xe4,0x25,0xad,0x19,0xf8,0x20,0x74,0x75,0x73,0xb6,0x13, +0x17,0xf6,0xcb,0x4f,0x14,0xb2,0x22,0x07,0x71,0x10,0x15,0x95,0xb9,0xa6,0x07,0x4d, +0xb8,0x76,0xe2,0xa4,0xae,0x6b,0xa8,0x48,0x81,0xcb,0x82,0x68,0x05,0x05,0xa5,0x0c, +0x7c,0x54,0x8a,0x33,0x04,0xef,0x43,0x64,0xe2,0xf3,0x7c,0x90,0xfa,0x8f,0xfb,0x95, +0x5b,0x30,0x1c,0xaf,0x0b,0x18,0xd1,0x0a,0x66,0x10,0x79,0x1e,0x84,0x3b,0xff,0x20, +0xc7,0xeb,0x6e,0x78,0xfc,0x1b,0x1e,0xbf,0xe1,0x1d,0xa7,0x61,0x19,0x1b,0xb1,0x28, +0x06,0x56,0x18,0xcb,0x46,0x36,0x08,0x42,0x17,0x02,0x8f,0xd6,0xda,0x32,0xab,0x69, +0x65,0x06,0x14,0x8b,0x57,0xe2,0x72,0x25,0x76,0x83,0x54,0x0d,0x2c,0x09,0x71,0x96, +0x3c,0x5c,0xab,0x21,0x62,0x3e,0x48,0x37,0x69,0x8b,0x71,0xd3,0x77,0x61,0x03,0x9e, +0xb4,0x86,0x38,0x22,0xd7,0xe1,0xaf,0x13,0x03,0xe1,0x72,0xfd,0x03,0x00,0x00,0xff, +0xff,0x03,0x00,0x8d,0xb1,0x06,0x76,0xa6,0x7a,0xc3,0xbb,0x13,0x3d,0x45,0xe2,0x2b, +0x3b,0xd0,0x88,0xc7,0x58,0x7b,0xbd,0x30,0x9d,0x01,0x44,0x78,0xda,0xca,0x48,0xcd, +0xc9,0xc9,0xcf,0x80,0x13,0x5c,0x00,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7, +0x06,0x47 +}; + +static void verify7(struct archive *a, struct archive_entry *ae) +{ + (void)a; /* UNUSED */ + assert(archive_entry_filetype(ae) == AE_IFREG); + assertEqualInt(archive_entry_mode(ae) & 0777, 0644); + assertEqualInt(archive_entry_uid(ae), UID); + assertEqualInt(archive_entry_gid(ae), GID); + assertEqualString(archive_entry_uname(ae), UNAME); + assertEqualString(archive_entry_gname(ae), GNAME); + assertEqualString(archive_entry_pathname(ae), "dir1/f1"); + assert(archive_entry_hardlink(ae) == NULL); + assert(archive_entry_symlink(ae) == NULL); + assertEqualInt(archive_entry_mtime(ae), 86401); +} + +/* Verify that a file records with bzip2 compression +#How to make +echo "hellohellohello" > f1 +chown $UNAME:$GNAME f1 +chmod 0644 f1 +env TZ=utc touch -afm -t 197001020000.01 f1 +xar --compression bzip2 -cf archive8.xar f1 +od -t x1 archive8.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive8.xar.txt +*/ + +static unsigned char archive8[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xb1, +0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x42,0x00,0x00,0x00,0x01,0x78,0xda,0x7c,0x53, +0xcb,0x6e,0xdc,0x20,0x14,0xdd,0xe7,0x2b,0x90,0xf7,0x0e,0x60,0xe3,0x07,0x23,0x86, +0xa8,0x9b,0xa8,0xfb,0x4e,0x37,0xdd,0x61,0x1e,0x63,0x14,0xbf,0x64,0xe3,0x68,0x92, +0xaf,0x2f,0x60,0x3b,0xa3,0x34,0x6d,0x25,0x4b,0x3e,0x1c,0x0e,0xe7,0x5e,0xee,0xe5, +0xb2,0xa7,0x5b,0xdf,0x81,0x57,0x3d,0x2f,0x76,0x1c,0xce,0x09,0x7e,0x44,0x09,0xd0, +0x83,0x1c,0x95,0x1d,0xae,0xe7,0xe4,0xe7,0xe5,0x39,0xad,0x93,0x27,0xfe,0xc0,0x6e, +0x62,0xe6,0x0f,0x80,0xb9,0x51,0xfa,0x1f,0x60,0x72,0xd6,0xc2,0xf9,0x13,0xa9,0xb3, +0xbd,0xe6,0x19,0x42,0x34,0xc5,0x59,0x8a,0xc8,0x05,0xd1,0x13,0xc6,0x27,0x9c,0x33, +0xf8,0x59,0x12,0x0f,0xb5,0x5a,0xbe,0x2c,0x6b,0x0f,0x16,0xf7,0xd6,0xe9,0x73,0xb2, +0xb4,0x02,0x27,0x61,0x07,0xb0,0xd1,0x98,0x45,0x3b,0x8e,0x18,0xdc,0x51,0x64,0x17, +0xfb,0x1e,0xcc,0x19,0x8c,0x20,0x58,0xc0,0xc3,0x23,0xae,0x8c,0xed,0x34,0xb0,0xca, +0xa7,0xbd,0xdb,0x28,0xe1,0x44,0x44,0x80,0x75,0x7a,0xb8,0xba,0x96,0x13,0xc2,0xe0, +0x0e,0x37,0x7e,0xf7,0xcf,0x3e,0x87,0xda,0x63,0xe1,0xf2,0x1e,0xcb,0x73,0x47,0x21, +0x8e,0x84,0xc5,0x34,0x75,0x56,0xc6,0x5b,0xc1,0x5b,0xda,0xbc,0xdb,0x29,0x4b,0xe0, +0xae,0x15,0xb3,0x6c,0xed,0xab,0x56,0xe9,0x9f,0xb7,0xfc,0xf1,0xfd,0x9b,0x4f,0xcf, +0xe4,0xa4,0x28,0x4a,0x94,0xcb,0x3a,0xcf,0x9b,0x26,0x93,0xaa,0x92,0xba,0x29,0xa8, +0x2a,0x89,0x29,0xa8,0x50,0x22,0x97,0x45,0xa1,0x71,0xe5,0xeb,0xf6,0xc5,0xe8,0x48, +0xe6,0xe6,0x66,0x21,0xdd,0x3f,0x23,0x14,0xaa,0x22,0x8d,0x6c,0x64,0x45,0x55,0x6e, +0x68,0x63,0x88,0x30,0xa6,0x36,0xa4,0xae,0x6b,0xa4,0x49,0x91,0x95,0x05,0x31,0x1a, +0x49,0x4a,0x19,0xfc,0xea,0xb4,0x55,0x0f,0x7e,0x94,0x8f,0xc9,0xbf,0xf7,0x15,0xd5, +0xbf,0x7c,0x0b,0x8e,0x86,0x02,0xd6,0x47,0x88,0x69,0x85,0x52,0x84,0x53,0x94,0x5d, +0x10,0x3a,0x85,0x0f,0x7b,0x59,0x7f,0x97,0x89,0xff,0xc8,0xc4,0x5d,0x76,0x9d,0xc7, +0x75,0xe2,0x72,0xd5,0x0c,0x6e,0x70,0x63,0xad,0xe2,0x18,0x21,0xec,0x49,0x8f,0x22, +0xb5,0x2e,0x7a,0xde,0x74,0x11,0x6d,0xdc,0x87,0x6c,0x3d,0x64,0xfd,0xa8,0x34,0x47, +0x65,0x78,0x02,0x11,0x46,0xd2,0xbd,0x4d,0x1a,0x74,0x76,0x78,0x39,0x27,0xe3,0x6c, +0xaf,0x76,0x10,0x5d,0xc2,0x5b,0x31,0xab,0xc0,0x31,0x18,0xb6,0x37,0xe1,0x20,0x7c, +0x5e,0xc6,0xfb,0x45,0x10,0x1f,0x5f,0x78,0x6f,0x61,0x0a,0x60,0x1c,0x03,0x06,0xe3, +0x50,0xfc,0x06,0x00,0x00,0xff,0xff,0x03,0x00,0x19,0xcf,0xf5,0xc0,0xf9,0x65,0xe8, +0x78,0xc3,0xfa,0x5f,0x0a,0xf6,0x09,0x17,0xd8,0xb0,0x54,0xb9,0x02,0x8d,0x91,0x31, +0x9c,0x42,0x5a,0x68,0x39,0x31,0x41,0x59,0x26,0x53,0x59,0xc1,0x52,0x36,0xf7,0x00, +0x00,0x03,0x41,0x00,0x00,0x10,0x02,0x44,0xa0,0x00,0x21,0xb4,0x01,0x9a,0x0d,0x46, +0xa5,0x32,0x38,0xbb,0x92,0x29,0xc2,0x84,0x86,0x0a,0x91,0xb7,0xb8 +}; + +/* Verify that a file records with no compression +#How to make +echo "hellohellohello" > f1 +chown $UNAME:$GNAME f1 +chmod 0644 f1 +env TZ=utc touch -afm -t 197001020000.01 f1 +xar --compression none -cf archive9.xar f1 +od -t x1 archive9.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive9.xar.txt +*/ + +static unsigned char archive9[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x98, +0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x47,0x00,0x00,0x00,0x01,0x78,0xda,0xa4,0x53, +0x4d,0x6f,0xe3,0x20,0x14,0xbc,0xf7,0x57,0x20,0xee,0x5e,0xc0,0x25,0x89,0x1d,0x11, +0xaa,0x5e,0xaa,0xbd,0x6f,0xf6,0xb2,0x37,0x02,0x8f,0x18,0xc5,0x1f,0x11,0xc6,0x55, +0xba,0xbf,0x7e,0x01,0xdb,0xad,0xba,0x55,0x7b,0xa9,0x64,0xc9,0xe3,0x61,0xde,0x78, +0x78,0xf0,0xc4,0xc3,0xad,0x6b,0xd1,0x33,0xf8,0xd1,0x0d,0xfd,0x01,0xb3,0x1f,0x14, +0x23,0xe8,0xf5,0x60,0x5c,0x7f,0x3e,0xe0,0xdf,0xc7,0xa7,0xa2,0xc2,0x0f,0xf2,0x4e, +0xdc,0x94,0x97,0x77,0x48,0x84,0x41,0xc7,0x17,0x12,0xda,0x83,0x0a,0xb1,0xa2,0x08, +0xae,0x03,0x59,0x52,0x5a,0x17,0xac,0x2c,0x28,0x3f,0xd2,0x7a,0xcf,0xaa,0x3d,0xaf, +0x05,0x79,0x2f,0xc9,0x45,0x0d,0xe8,0xcb,0x38,0x75,0x68,0x0c,0x2f,0x2d,0x1c,0xf0, +0xd8,0x28,0x86,0xd3,0x0a,0x12,0x83,0xb5,0x23,0x04,0x49,0x05,0x59,0x50,0x66,0x47, +0xf7,0x37,0x99,0x0b,0x92,0x41,0xb2,0x20,0xab,0x47,0xfe,0xb2,0xae,0x05,0xe4,0x4c, +0x8c,0xbd,0xd8,0x18,0x15,0x54,0x46,0x48,0xb4,0xd0,0x9f,0x43,0x23,0xd9,0x56,0x90, +0x05,0xce,0xfc,0xba,0xb9,0x35,0x84,0xba,0x5e,0x5b,0xa7,0x73,0x52,0x32,0xe8,0x00, +0xa1,0x18,0x43,0x4c,0xde,0x61,0xb2,0x14,0x2c,0x81,0xca,0xf7,0xd9,0x96,0x70,0xc9, +0x7e,0x0d,0x17,0x39,0xe5,0x75,0xe3,0x9e,0xc1,0x14,0xff,0x6f,0xf5,0xd7,0xcf,0xc7, +0x98,0x71,0x63,0x76,0xfc,0xa4,0x4f,0x7a,0x57,0x9b,0x7b,0x5b,0x9f,0x2c,0x57,0xd6, +0x56,0x96,0x57,0x55,0x45,0x81,0x6f,0xca,0xed,0x86,0x5b,0xa0,0xba,0x8e,0xcd,0xfb, +0x60,0xb4,0xa6,0xbf,0x05,0xaf,0x62,0xca,0xef,0xff,0xe1,0xa3,0xd3,0xdc,0x42,0xf2, +0xda,0x43,0xa1,0x3f,0x39,0xdc,0xed,0x9f,0x78,0x0e,0xeb,0xa9,0x22,0xd1,0x65,0xc8, +0xea,0x1d,0x2d,0x28,0x2b,0x68,0x79,0xa4,0x74,0x9f,0x1e,0x16,0x65,0xdd,0x9b,0x4c, +0x7d,0x21,0x53,0x6f,0xb2,0xb3,0x1f,0xa6,0xab,0xd4,0x13,0x08,0x32,0xc3,0x99,0x75, +0x46,0x32,0x4a,0x59,0x24,0x23,0xca,0xd4,0x34,0x82,0x9f,0x75,0x19,0xcd,0xdc,0xab, +0x6c,0x5a,0x65,0xdd,0x60,0x40,0xd2,0x2d,0xe7,0x31,0x4c,0x82,0x99,0x0c,0x2f,0x57, +0x40,0xad,0xeb,0x2f,0x07,0x3c,0x78,0x77,0x76,0xbd,0x6a,0xb1,0x6c,0x94,0x37,0x89, +0x13,0x24,0x2d,0xcf,0xc2,0x5e,0xc5,0x5c,0x36,0xfa,0x65,0x90,0x6f,0x60,0xba,0x74, +0x69,0x14,0x48,0x9e,0x05,0x41,0xf2,0x64,0xfc,0x03,0x00,0x00,0xff,0xff,0x03,0x00, +0xee,0x8e,0xf8,0x75,0xa1,0xaf,0x74,0x71,0x3f,0x40,0x08,0xab,0x13,0x7d,0xc0,0x82, +0x3a,0x56,0xeb,0x4e,0x35,0xf1,0x35,0xb7,0x68,0x65,0x6c,0x6c,0x6f,0x68,0x65,0x6c, +0x6c,0x6f,0x68,0x65,0x6c,0x6c,0x6f,0x0a +}; + +/* Verify that a file records with md5 hashing algorithm +#How to make +echo "hellohellohello" > f1 +chown $UNAME:$GNAME f1 +chmod 0644 f1 +env TZ=utc touch -afm -t 197001020000.01 f1 +xar --toc-cksum md5 -cf archive10.xar f1 +od -t x1 archive10.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive10.xar.txt +*/ + +static unsigned char archive10[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xaf, +0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x40,0x00,0x00,0x00,0x02,0x78,0xda,0x7c,0x53, +0x4d,0x6f,0xdc,0x20,0x10,0xbd,0xe7,0x57,0x20,0xee,0x0e,0x60,0xb3,0xb6,0x59,0xb1, +0x44,0xbd,0x44,0xbd,0x77,0x7b,0xe9,0x8d,0xe5,0xc3,0x8b,0xe2,0x2f,0x61,0x1c,0x6d, +0xf2,0xeb,0x8b,0xb1,0x9d,0xb4,0x4d,0x52,0xc9,0x92,0x1f,0x8f,0xc7,0x9b,0x61,0x86, +0xe1,0x0f,0xb7,0xae,0x05,0xcf,0xc6,0x4f,0x6e,0xe8,0x4f,0x90,0xdc,0x63,0x08,0x4c, +0xaf,0x06,0xed,0xfa,0xe6,0x04,0x7f,0x9e,0x1f,0xb3,0x1a,0x3e,0x88,0x3b,0x7e,0x93, +0x5e,0xdc,0x01,0x1e,0x06,0x15,0x7f,0x80,0x2b,0x6f,0x64,0x88,0x27,0xb2,0xe0,0x3a, +0x23,0x72,0x8c,0x59,0x46,0xf2,0x0c,0xd3,0x33,0x66,0xc7,0x02,0x1f,0x69,0xcd,0xd1, +0xdf,0x92,0x74,0xe8,0x6a,0xd4,0xd3,0x34,0x77,0x60,0x0a,0x2f,0xad,0x39,0xc1,0x4e, +0x1f,0xe0,0xb2,0x01,0xf8,0x60,0xed,0x64,0x82,0xc0,0x1c,0x6d,0x28,0xb1,0x93,0x7b, +0x35,0x82,0x94,0x1c,0x25,0xb0,0x38,0xa0,0xdd,0x22,0xad,0xac,0x6b,0x0d,0x70,0x3a, +0x66,0xbd,0xd9,0x68,0x19,0x64,0x42,0x80,0xb7,0xa6,0x6f,0xc2,0x55,0xe4,0x05,0x47, +0x1b,0x5c,0xf9,0xcd,0x7f,0x71,0xfd,0x23,0xd4,0x27,0xb1,0x22,0xb7,0xd7,0x61,0xcf, +0x57,0x8e,0x63,0xeb,0x54,0xba,0x14,0xba,0x65,0xcd,0xab,0x1b,0x21,0xda,0xa4,0xd2, +0xab,0xab,0x7b,0x36,0x3a,0xfb,0xf7,0x8e,0x3f,0xbe,0x7f,0x8b,0xd9,0xd9,0xba,0x28, +0x74,0x6e,0xb5,0x22,0xac,0xa0,0xac,0x90,0x17,0x5a,0x33,0xa9,0x65,0x5e,0xd8,0xda, +0x56,0x8c,0xd8,0x32,0xb7,0xaa,0x28,0x59,0xac,0xda,0x07,0xa3,0x3d,0x97,0x5b,0xf0, +0x52,0x85,0x2f,0x23,0x1c,0x74,0x45,0x2f,0xea,0xa2,0x2a,0xa6,0x0b,0xcb,0x2e,0x96, +0x4a,0x1b,0xbd,0x69,0x5d,0xd7,0xd8,0xd0,0x43,0x5e,0x1e,0xa8,0x35,0x58,0x31,0xc6, +0xd1,0x47,0xa7,0xb5,0x78,0xe8,0xad,0x7a,0x5c,0x7d,0xd1,0xd5,0xea,0x57,0xec,0xc0, +0xde,0x4e,0xc0,0xbb,0x04,0x09,0xab,0x70,0x86,0x49,0x86,0xf3,0x33,0xc6,0xc7,0xe5, +0x23,0x51,0xd6,0xbd,0xcb,0xe4,0x7f,0x64,0xf2,0x5d,0xd6,0xf8,0x61,0x1e,0x85,0x9a, +0x0d,0x47,0x2b,0x5c,0x59,0xa7,0x05,0xc1,0x98,0x44,0x32,0xa2,0x44,0xcd,0x93,0xf1, +0xab,0x2e,0xa1,0x95,0x7b,0x93,0xcd,0xbb,0xac,0x1b,0xb4,0x11,0xb8,0xa4,0x34,0x26, +0xb3,0xc0,0x44,0x86,0x97,0xd1,0x80,0xd6,0xf5,0x4f,0x27,0x38,0x78,0xd7,0xb8,0x5e, +0xb6,0x50,0x5c,0xa5,0xd7,0x0b,0xc7,0xd1,0xb2,0xbd,0x0a,0x7b,0x19,0xf3,0xb2,0xd1, +0x2f,0x81,0xf4,0xf6,0x96,0xe7,0xb6,0xcc,0x00,0x4a,0x43,0xc0,0x51,0x1a,0x89,0xdf, +0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x27,0xf8,0xf5,0x28,0x87,0x01,0xb1,0xb7,0x18, +0xe8,0x34,0x20,0x06,0x5c,0x66,0x9a,0x43,0x26,0xe7,0x94,0x78,0xda,0xca,0x48,0xcd, +0xc9,0xc9,0xcf,0x80,0x13,0x5c,0x00,0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7, +0x06,0x47 +}; + +/* Verify that a file records with no hashing algorithm +#How to make +echo "hellohellohello" > f1 +chown $UNAME:$GNAME f1 +chmod 0644 f1 +env TZ=utc touch -afm -t 197001020000.01 f1 +xar --toc-cksum none -cf archive11.xar f1 +od -t x1 archive11.xar | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D' > archive11.xar.txt +*/ + +static unsigned char archive11[] = { +0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x98, +0x00,0x00,0x00,0x00,0x00,0x00,0x02,0xef,0x00,0x00,0x00,0x00,0x78,0xda,0x7c,0x52, +0xcb,0x6e,0xeb,0x20,0x14,0xdc,0xf7,0x2b,0x10,0x7b,0x17,0xb0,0x89,0x63,0x22,0x42, +0x75,0x37,0x55,0xf7,0xcd,0xdd,0x74,0x47,0x78,0x38,0xa8,0x7e,0xc9,0xc6,0x55,0xda, +0xaf,0xbf,0x3c,0xe2,0x56,0x55,0xd5,0x2b,0x21,0x79,0x3c,0xcc,0x39,0x67,0x74,0x18, +0xfe,0x70,0xed,0x3b,0xf0,0x66,0xe6,0xc5,0x8d,0xc3,0x11,0x92,0x7b,0x0c,0x81,0x19, +0xd4,0xa8,0xdd,0xd0,0x1e,0xe1,0xdf,0xd3,0x63,0xd1,0xc0,0x07,0x71,0xc7,0xaf,0x72, +0x16,0x77,0x80,0xfb,0x51,0x85,0x0f,0xe0,0x6a,0x36,0xd2,0x87,0x8a,0xc2,0xbb,0xde, +0x88,0x12,0x63,0x56,0x90,0xb2,0xc0,0xf4,0x44,0xf0,0x81,0x54,0x07,0x5a,0x73,0xf4, +0x5d,0x12,0x8b,0xac,0xeb,0x0c,0x70,0x3a,0x4c,0x81,0xf1,0x1f,0x70,0x2d,0xbd,0x4c, +0x08,0xf0,0xce,0x0c,0xad,0xbf,0x88,0xb2,0xe2,0xe8,0x06,0x33,0x3f,0x5a,0xbb,0x18, +0x2f,0x30,0x47,0x37,0x94,0xe9,0xc5,0x7d,0x18,0x41,0xc2,0x94,0x04,0x32,0xb7,0xd9, +0x06,0x8b,0x7f,0xef,0xcc,0x11,0xca,0x69,0xea,0x9c,0x4a,0x1e,0xd0,0xb5,0x68,0x3f, +0xdc,0x04,0xd1,0x4d,0x2a,0x67,0x75,0x71,0x6f,0x46,0x17,0xea,0x62,0xd4,0xeb,0xb2, +0xf6,0x5b,0xcd,0xf3,0xd3,0x9f,0x60,0xce,0x36,0x55,0xa5,0x4b,0xab,0x15,0x61,0x15, +0x65,0x95,0x3c,0xd3,0x86,0x49,0x2d,0xcb,0xca,0x36,0x76,0xcf,0x88,0xad,0x4b,0xab, +0xaa,0x9a,0x35,0x1c,0xfd,0x68,0xb4,0x79,0xb9,0xfa,0x59,0x2a,0xff,0xeb,0x84,0x9d, +0xde,0xd3,0xb3,0x3a,0xab,0x3d,0xd3,0x95,0x65,0x67,0x4b,0xa5,0x0d,0xbd,0x69,0xd3, +0x34,0xd8,0xd0,0x5d,0x59,0xef,0xa8,0x35,0x58,0x31,0xc6,0xd1,0xcf,0x4e,0x79,0x77, +0xe8,0x73,0x79,0x5c,0xfd,0xf2,0x08,0xe4,0x25,0xbc,0xc2,0xb6,0x7d,0xc0,0xfb,0x04, +0x09,0xdb,0xe3,0x02,0x93,0x02,0x97,0x27,0x8c,0x0f,0xf1,0x44,0x59,0xff,0x25,0x93, +0xff,0x91,0xc9,0x2f,0x59,0x3b,0x8f,0xeb,0x24,0xd4,0x6a,0x38,0xca,0x30,0xb3,0x4e, +0x0b,0x82,0x31,0x09,0x64,0x40,0x89,0x5a,0x17,0x33,0x67,0x5d,0x42,0x99,0xfb,0x94, +0xad,0x9b,0xac,0x1f,0xb5,0x11,0xb8,0xa6,0x34,0x98,0x89,0x30,0x91,0xfe,0x7d,0x32, +0xa0,0x73,0xc3,0xeb,0x11,0x8e,0xb3,0x6b,0xdd,0x20,0x3b,0x28,0x2e,0x72,0xd6,0x91, +0xe3,0x28,0x5e,0x67,0xe1,0x20,0x83,0x2f,0x1b,0xfa,0x25,0x10,0xc3,0x86,0x62,0xda, +0x62,0x64,0x51,0xca,0x2c,0x47,0x29,0xc1,0xff,0x00,0x00,0x00,0xff,0xff,0x03,0x00, +0xf1,0x18,0xdc,0x71,0x78,0xda,0xca,0x48,0xcd,0xc9,0xc9,0xcf,0x80,0x13,0x5c,0x00, +0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7,0x06,0x47 +}; + +enum enc { + GZIP, + BZIP2 +}; + +static void verify(unsigned char *d, size_t s, + void (*f1)(struct archive *, struct archive_entry *), + void (*f2)(struct archive *, struct archive_entry *), + enum enc etype) +{ + struct archive_entry *ae; + struct archive *a; + unsigned char *buff; + int r; + + assert((a = archive_read_new()) != NULL); + switch (etype) { + case BZIP2: + /* This is only check whether bzip is supported or not. + * This filter won't be used this test. */ + if (ARCHIVE_OK != archive_read_support_compression_bzip2(a)) { + skipping("Unsupported bzip2"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + break; + case GZIP: + /* This gzip must be needed. archive_read_support_format_xar() + * will return a warning if gzip is unsupported. */ + break; + } + assertA(0 == archive_read_support_compression_all(a)); + r = archive_read_support_format_xar(a); + if (r == ARCHIVE_WARN) { + skipping("xar reading not fully supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assert((buff = malloc(100000)) != NULL); + if (buff == NULL) + return; + memcpy(buff, d, s); + memset(buff + s, 0, 2048); + + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_open_memory(a, buff, s + 1024)); + assertA(0 == archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_XAR); + /* Verify the only entry. */ + f1(a, ae); + if (f2) { + assertA(0 == archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_XAR); + /* Verify the only entry. */ + f2(a, ae); + } + /* End of archive. */ + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + assertA(0 == archive_read_close(a)); + assertA(0 == archive_read_finish(a)); + free(buff); +} + +DEFINE_TEST(test_read_format_xar) +{ + verify(archive1, sizeof(archive1), verify0, verify1, GZIP); + verify(archive2, sizeof(archive2), verify0, verify2, GZIP); + verify(archive3, sizeof(archive3), verify3, NULL, GZIP); + verify(archive4, sizeof(archive4), verify4, NULL, GZIP); + verify(archive5, sizeof(archive5), verify5, NULL, GZIP); + verify(archive6, sizeof(archive6), verify6, NULL, GZIP); + verify(archive7, sizeof(archive7), verify7, NULL, GZIP); + verify(archive8, sizeof(archive8), verify0, NULL, BZIP2); + verify(archive9, sizeof(archive9), verify0, NULL, GZIP); + verify(archive10, sizeof(archive10), verify0, NULL, GZIP); + verify(archive11, sizeof(archive11), verify0, NULL, GZIP); +} + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip.c b/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip.c new file mode 100644 index 000000000..680e7ede3 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip.c @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_format_zip.c 189482 2009-03-07 03:30:35Z kientzle $"); + +/* + * The reference file for this has been manually tweaked so that: + * * file2 has length-at-end but file1 does not + * * file2 has an invalid CRC + */ + +DEFINE_TEST(test_read_format_zip) +{ + const char *refname = "test_read_format_zip.zip"; + struct archive_entry *ae; + struct archive *a; + char *buff[128]; + const void *pv; + size_t s; + off_t o; + int r; + + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_open_filename(a, refname, 10240)); + assertA(0 == archive_read_next_header(a, &ae)); + assertEqualString("dir/", archive_entry_pathname(ae)); + assertEqualInt(1179604249, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_data_block(a, &pv, &s, &o)); + assertEqualInt((int)s, 0); + assertA(0 == archive_read_next_header(a, &ae)); + assertEqualString("file1", archive_entry_pathname(ae)); + assertEqualInt(1179604289, archive_entry_mtime(ae)); + assertEqualInt(18, archive_entry_size(ae)); + failure("archive_read_data() returns number of bytes read"); + r = archive_read_data(a, buff, 19); + if (r < ARCHIVE_OK) { + if (strcmp(archive_error_string(a), + "libarchive compiled without deflate support (no libz)") == 0) { + skipping("Skipping ZIP compression check: %s", + archive_error_string(a)); + goto finish; + } + } + assertEqualInt(18, r); + assert(0 == memcmp(buff, "hello\nhello\nhello\n", 18)); + assertA(0 == archive_read_next_header(a, &ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assertEqualInt(1179605932, archive_entry_mtime(ae)); + failure("file2 has length-at-end, so we shouldn't see a valid size"); + assertEqualInt(0, archive_entry_size_is_set(ae)); + failure("file2 has a bad CRC, so reading to end should fail"); + assertEqualInt(ARCHIVE_WARN, archive_read_data(a, buff, 19)); + assert(0 == memcmp(buff, "hello\nhello\nhello\n", 18)); + assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE); + assertA(archive_format(a) == ARCHIVE_FORMAT_ZIP); + assert(0 == archive_read_close(a)); +finish: +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif +} + + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip.zip.uu b/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip.zip.uu new file mode 100644 index 000000000..b1f04c4fe --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_format_zip.zip.uu @@ -0,0 +1,14 @@ +$FreeBSD: src/lib/libarchive/test/test_read_format_zip.zip.uu,v 1.3 2008/10/21 05:08:35 kientzle Exp $ +begin 644 test_read_format_zip.zip +M4$L#!`H`"````%EFLS8````````````````$`!4`9&ER+U54"0`#&55/1M19 +M_4A5>`0`Z`/H`U!+!P@```````````````!02P,$%`````@`;V:S-CHW9CT* +M````$@````4`%0!F:6QE,554"0`#055/1L!9_4A5>`0`Z`/H`\M(S`0`Z`/H`\M(S```4$L!`A<#%``(``@`;V:S-CHW9CT*````$@````4`#0`` +M`````0```.V!1P```&9I;&4Q550%``-!54]&57@``%!+`0(7`Q0`"``(`%IJ +MLS8Z-V8]"@```!(````%``T```````$```#M@8D```!F:6QE,E54!0`#K%M/ +;1E5X``!02P4&``````,``P"_````VP`````` +` +end diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_large.c b/external/bsd/libarchive/dist/libarchive/test/test_read_large.c new file mode 100644 index 000000000..a2be60178 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_large.c @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_large.c 201247 2009-12-30 05:59:21Z kientzle $"); + +static unsigned char testdata[10 * 1024 * 1024]; +static unsigned char testdatacopy[10 * 1024 * 1024]; +static unsigned char buff[11 * 1024 * 1024]; + +#if defined(_WIN32) && !defined(__CYGWIN__) +#define open _open +#define close _close +#endif + +/* Check correct behavior on large reads. */ +DEFINE_TEST(test_read_large) +{ + unsigned int i; + int tmpfilefd; + char tmpfilename[] = "test-read_large.XXXXXX"; + size_t used; + struct archive *a; + struct archive_entry *entry; + FILE *f; + + for (i = 0; i < sizeof(testdata); i++) + testdata[i] = (unsigned char)(rand()); + + assert(NULL != (a = archive_write_new())); + assertA(0 == archive_write_set_format_ustar(a)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + assert(NULL != (entry = archive_entry_new())); + archive_entry_set_size(entry, sizeof(testdata)); + archive_entry_set_mode(entry, S_IFREG | 0777); + archive_entry_set_pathname(entry, "test"); + assertA(0 == archive_write_header(a, entry)); + archive_entry_free(entry); + assertA((int)sizeof(testdata) == archive_write_data(a, testdata, sizeof(testdata))); + assertA(0 == archive_write_finish(a)); + + assert(NULL != (a = archive_read_new())); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, sizeof(buff))); + assertA(0 == archive_read_next_header(a, &entry)); + assertA(0 == archive_read_data_into_buffer(a, testdatacopy, sizeof(testdatacopy))); + assertA(0 == archive_read_finish(a)); + assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata))); + + + assert(NULL != (a = archive_read_new())); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, sizeof(buff))); + assertA(0 == archive_read_next_header(a, &entry)); +#if defined(__BORLANDC__) + tmpfilefd = open(tmpfilename, O_WRONLY | O_CREAT | O_BINARY); +#else + tmpfilefd = open(tmpfilename, O_WRONLY | O_CREAT | O_BINARY, 0755); +#endif + assert(0 < tmpfilefd); + assertA(0 == archive_read_data_into_fd(a, tmpfilefd)); + close(tmpfilefd); + assertA(0 == archive_read_finish(a)); + + f = fopen(tmpfilename, "rb"); + assertEqualInt(sizeof(testdatacopy), + fread(testdatacopy, 1, sizeof(testdatacopy), f)); + fclose(f); + assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata))); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_pax_truncated.c b/external/bsd/libarchive/dist/libarchive/test/test_read_pax_truncated.c new file mode 100644 index 000000000..4e2a8134e --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_pax_truncated.c @@ -0,0 +1,288 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_pax_truncated.c 189483 2009-03-07 03:34:34Z kientzle $"); + +DEFINE_TEST(test_read_pax_truncated) +{ + struct archive_entry *ae; + struct archive *a; + size_t used, i, buff_size = 1000000; + size_t filedata_size = 100000; + char *buff = malloc(buff_size); + char *buff2 = malloc(buff_size); + char *filedata = malloc(filedata_size); + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_pax(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_open_memory(a, buff, buff_size, &used)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + for (i = 0; i < filedata_size; i++) + filedata[i] = (unsigned char)rand(); + archive_entry_set_atime(ae, 1, 2); + archive_entry_set_ctime(ae, 3, 4); + archive_entry_set_mtime(ae, 5, 6); + archive_entry_set_size(ae, filedata_size); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assertA((ssize_t)filedata_size + == archive_write_data(a, filedata, filedata_size)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + + /* Now, read back a truncated version of the archive and + * verify that we get an appropriate error. */ + for (i = 1; i < used + 100; i += 100) { + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == read_open_memory2(a, buff, i, 13)); + + if (i < 1536) { + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); + goto wrap_up; + } else { + failure("Archive truncated to %d bytes", i); + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + } + + if (i < 1536 + filedata_size) { + assertA(ARCHIVE_FATAL == archive_read_data(a, filedata, filedata_size)); + goto wrap_up; + } else { + failure("Archive truncated to %d bytes", i); + assertEqualIntA(a, filedata_size, + archive_read_data(a, filedata, filedata_size)); + } + + /* Verify the end of the archive. */ + /* Archive must be long enough to capture a 512-byte + * block of zeroes after the entry. (POSIX requires a + * second block of zeros to be written but libarchive + * does not return an error if it can't consume + * it.) */ + if (i < 1536 + 512*((filedata_size + 511)/512) + 512) { + failure("i=%d minsize=%d", i, + 1536 + 512*((filedata_size + 511)/512) + 512); + assertEqualIntA(a, ARCHIVE_FATAL, + archive_read_next_header(a, &ae)); + } else { + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_next_header(a, &ae)); + } + wrap_up: + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + } + + + + /* Same as above, except skip the body instead of reading it. */ + for (i = 1; i < used + 100; i += 100) { + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == read_open_memory(a, buff, i, 7)); + + if (i < 1536) { + assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + goto wrap_up2; + } else { + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + } + + if (i < 1536 + 512*((filedata_size+511)/512)) { + assertA(ARCHIVE_FATAL == archive_read_data_skip(a)); + goto wrap_up2; + } else { + assertA(ARCHIVE_OK == archive_read_data_skip(a)); + } + + /* Verify the end of the archive. */ + /* Archive must be long enough to capture a 512-byte + * block of zeroes after the entry. (POSIX requires a + * second block of zeros to be written but libarchive + * does not return an error if it can't consume + * it.) */ + if (i < 1536 + 512*((filedata_size + 511)/512) + 512) { + assertEqualIntA(a, ARCHIVE_FATAL, + archive_read_next_header(a, &ae)); + } else { + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_next_header(a, &ae)); + } + wrap_up2: + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + } + + /* Now, damage the archive in various ways and test the responses. */ + + /* Damage the first size field in the pax attributes. */ + memcpy(buff2, buff, buff_size); + buff2[512] = '9'; + buff2[513] = '9'; + buff2[514] = 'A'; /* Non-digit in size. */ + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + + /* Damage the size field in the pax attributes. */ + memcpy(buff2, buff, buff_size); + buff2[512] = 'A'; /* First character not a digit. */ + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + + /* Damage the size field in the pax attributes. */ + memcpy(buff2, buff, buff_size); + for (i = 512; i < 520; i++) /* Size over 999999. */ + buff2[i] = '9'; + buff2[i] = ' '; + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + + /* Damage the size field in the pax attributes. */ + memcpy(buff2, buff, buff_size); + buff2[512] = '9'; /* Valid format, but larger than attribute area. */ + buff2[513] = '9'; + buff2[514] = '9'; + buff2[515] = ' '; + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + + /* Damage the size field in the pax attributes. */ + memcpy(buff2, buff, buff_size); + buff2[512] = '1'; /* Too small. */ + buff2[513] = ' '; + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + + /* Damage the size field in the pax attributes. */ + memcpy(buff2, buff, buff_size); + buff2[512] = ' '; /* No size given. */ + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + + /* Damage the ustar header. */ + memcpy(buff2, buff, buff_size); + buff2[1024]++; /* Break the checksum. */ + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + + /* + * TODO: Damage the ustar header in various ways and fixup the + * checksum in order to test boundary cases in the innermost + * ustar header parsing. + */ + + free(buff); + free(buff2); + free(filedata); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_position.c b/external/bsd/libarchive/dist/libarchive/test/test_read_position.c new file mode 100644 index 000000000..85b796721 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_position.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_position.c 189389 2009-03-05 02:19:42Z kientzle $"); + +static unsigned char nulls[10000]; +static unsigned char buff[10000000]; + +/* Check that header_position tracks correctly on read. */ +DEFINE_TEST(test_read_position) +{ + struct archive *a; + struct archive_entry *ae; + size_t write_pos; + intmax_t read_position; + size_t i, j; + size_t data_sizes[] = {0, 5, 511, 512, 513}; + + /* Sanity test */ + assert(sizeof(nulls) + 512 + 1024 <= sizeof(buff)); + + /* Create an archive. */ + assert(NULL != (a = archive_write_new())); + assertA(0 == archive_write_set_format_pax_restricted(a)); + assertA(0 == archive_write_set_bytes_per_block(a, 512)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &write_pos)); + + for (i = 0; i < sizeof(data_sizes)/sizeof(data_sizes[0]); ++i) { + /* Create a simple archive_entry. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_pathname(ae, "testfile"); + archive_entry_set_mode(ae, S_IFREG); + archive_entry_set_size(ae, data_sizes[i]); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assertA(data_sizes[i] + == (size_t)archive_write_data(a, nulls, sizeof(nulls))); + } + assertA(0 == archive_write_close(a)); + assertA(0 == archive_write_finish(a)); + + /* Read the archive back. */ + assert(NULL != (a = archive_read_new())); + assertA(0 == archive_read_support_format_tar(a)); + assertA(0 == archive_read_open_memory2(a, buff, sizeof(buff), 512)); + + read_position = 0; + /* Initial header position is zero. */ + assert(read_position == (intmax_t)archive_read_header_position(a)); + for (j = 0; j < i; ++j) { + assertA(0 == archive_read_next_header(a, &ae)); + assert(read_position + == (intmax_t)archive_read_header_position(a)); + /* Every other entry: read, then skip */ + if (j & 1) + assertEqualInt(ARCHIVE_OK, + archive_read_data_into_buffer(a, buff, 1)); + assertA(0 == archive_read_data_skip(a)); + /* read_data_skip() doesn't change header_position */ + assert(read_position + == (intmax_t)archive_read_header_position(a)); + + read_position += 512; /* Size of header. */ + read_position += (data_sizes[j] + 511) & ~511; + } + + assertA(1 == archive_read_next_header(a, &ae)); + assert(read_position == (intmax_t)archive_read_header_position(a)); + assertA(0 == archive_read_close(a)); + assert(read_position == (intmax_t)archive_read_header_position(a)); + archive_read_finish(a); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_truncated.c b/external/bsd/libarchive/dist/libarchive/test/test_read_truncated.c new file mode 100644 index 000000000..9b26b5981 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_truncated.c @@ -0,0 +1,149 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_truncated.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $"); + +char buff[1000000]; +char buff2[100000]; + +DEFINE_TEST(test_read_truncated) +{ + struct archive_entry *ae; + struct archive *a; + unsigned int i; + size_t used; + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + for (i = 0; i < sizeof(buff2); i++) + buff2[i] = (unsigned char)rand(); + archive_entry_set_size(ae, sizeof(buff2)); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assertA((int)sizeof(buff2) == archive_write_data(a, buff2, sizeof(buff2))); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + + /* Now, read back a truncated version of the archive and + * verify that we get an appropriate error. */ + for (i = 1; i < used + 100; i += 100) { + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, i)); + + if (i < 512) { + assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + goto wrap_up; + } else { + assertA(0 == archive_read_next_header(a, &ae)); + } + + if (i < 512 + sizeof(buff2)) { + assertA(ARCHIVE_FATAL == archive_read_data(a, buff2, sizeof(buff2))); + goto wrap_up; + } else { + assertA((int)sizeof(buff2) == archive_read_data(a, buff2, sizeof(buff2))); + } + + /* Verify the end of the archive. */ + /* Archive must be long enough to capture a 512-byte + * block of zeroes after the entry. (POSIX requires a + * second block of zeros to be written but libarchive + * does not return an error if it can't consume + * it.) */ + if (i < 512 + 512*((sizeof(buff2) + 511)/512) + 512) { + assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + } else { + assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); + } + wrap_up: + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + } + + + + /* Same as above, except skip the body instead of reading it. */ + for (i = 1; i < used + 100; i += 100) { + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, i)); + + if (i < 512) { + assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + goto wrap_up2; + } else { + assertA(0 == archive_read_next_header(a, &ae)); + } + + if (i < 512 + 512*((sizeof(buff2)+511)/512)) { + assertA(ARCHIVE_FATAL == archive_read_data_skip(a)); + goto wrap_up2; + } else { + assertA(ARCHIVE_OK == archive_read_data_skip(a)); + } + + /* Verify the end of the archive. */ + /* Archive must be long enough to capture a 512-byte + * block of zeroes after the entry. (POSIX requires a + * second block of zeros to be written but libarchive + * does not return an error if it can't consume + * it.) */ + if (i < 512 + 512*((sizeof(buff2) + 511)/512) + 512) { + assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + } else { + assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); + } + wrap_up2: + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + } +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_read_uu.c b/external/bsd/libarchive/dist/libarchive/test/test_read_uu.c new file mode 100644 index 000000000..a5de09af7 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_read_uu.c @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_uu.c 201248 2009-12-30 06:12:03Z kientzle $"); + +static const char archive[] = { +"begin 644 test_read_uu.Z\n" +"M'YV0+@`('$BPH,&#\"!,J7,BP(4(8$&_4J`$\"`,08$F%4O)AQ(\\2/(#7&@#%C\n" +"M!@T8-##.L`$\"QL@:-F(``%'#H/1A2\n" +"IHU\"0%9=*G4JUJM6K6+-JWO8,.*'4NVK-FS:-.J7\n" +"Received: from libarchive (localhost [127.0.0.1])\n" +" by libarchive (8.14.2/8.14.2) with ESMTP id m5233UT1006448\n" +" for ; Mon, 2 Jun 2008 03:03:31 GMT\n" +" (envelope-from uudecode@libarchive)\n" +"Received: (from uudecode@localhost)\n" +" by libarchive (8.14.2/8.14.2/Submit) id m5233U3e006406\n" +" for uudecode; Mon, 2 Jun 2008 03:03:30 GMT\n" +" (envelope-from root)\n" +"Date: Mon, 2 Jun 2008 03:03:30 GMT\n" +"From: Libarchive Test \n" +"Message-Id: <200806020303.m5233U3e006406@libarchive>\n" +"To: uudecode@libarchive\n" +"Subject: Libarchive uudecode test\n" +"\n" +"* Redistribution and use in source and binary forms, with or without\n" +"* modification, are permitted provided that the following conditions\n" +"* are met:\n" +"\n" +"01234567890abcdeghijklmnopqrstuvwxyz\n" +"01234567890ABCEFGHIJKLMNOPQRSTUVWXYZ\n" +"\n" +}; + +static void +test_read_uu_sub(const char *uudata, size_t uusize) +{ + struct archive_entry *ae; + struct archive *a; + char *buff; + int extra; + + assert(NULL != (buff = malloc(uusize + 64 * 1024))); + if (buff == NULL) + return; + for (extra = 0; extra <= 64; extra = extra==0?1:extra*2) { + size_t size = extra * 1024; + char *p = buff; + + /* Add extra text size of which is from 1K bytes to + * 64Kbytes before uuencoded data. */ + while (size) { + if (size > sizeof(extradata)-1) { + memcpy(p, extradata, sizeof(extradata)-1); + p += sizeof(extradata)-1; + size -= sizeof(extradata)-1; + } else { + memcpy(p, extradata, size-1); + p += size-1; + *p++ = '\n';/* the last of extra text must have + * '\n' character. */ + break; + } + } + memcpy(p, uudata, uusize); + size = extra * 1024 + uusize; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + read_open_memory(a, buff, size, 2)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + failure("archive_compression_name(a)=\"%s\"", + archive_compression_name(a)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_COMPRESS); + failure("archive_format_name(a)=\"%s\"", + archive_format_name(a)); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + } + free(buff); +} + +DEFINE_TEST(test_read_uu) +{ + /* Read the traditional uuencoded data. */ + test_read_uu_sub(archive, sizeof(archive)-1); + /* Read the Base64 uuencoded data. */ + test_read_uu_sub(archive64, sizeof(archive64)-1); +} + diff --git a/external/bsd/libarchive/dist/libarchive/test/test_tar_filenames.c b/external/bsd/libarchive/dist/libarchive/test/test_tar_filenames.c new file mode 100644 index 000000000..b08373819 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_tar_filenames.c @@ -0,0 +1,186 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/lib/libarchive/test/test_tar_filenames.c,v 1.10 2008/09/01 05:38:33 kientzle Exp $"); + +/* + * Exercise various lengths of filenames in tar archives, + * especially around the magic sizes where ustar breaks + * filenames into prefix/suffix. + */ + +static void +test_filename(const char *prefix, int dlen, int flen) +{ + char buff[8192]; + char filename[400]; + char dirname[400]; + struct archive_entry *ae; + struct archive *a; + size_t used; + char *p; + int i; + + p = filename; + if (prefix) { + strcpy(filename, prefix); + p += strlen(p); + } + if (dlen > 0) { + for (i = 0; i < dlen; i++) + *p++ = 'a'; + *p++ = '/'; + } + for (i = 0; i < flen; i++) + *p++ = 'b'; + *p = '\0'; + + strcpy(dirname, filename); + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_pax_restricted(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_set_bytes_per_block(a,0)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, filename); + archive_entry_set_mode(ae, S_IFREG | 0755); + failure("Pathname %d/%d", dlen, flen); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + + /* + * Write a dir to it (without trailing '/'). + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, dirname); + archive_entry_set_mode(ae, S_IFDIR | 0755); + failure("Dirname %d/%d", dlen, flen); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Tar adds a '/' to directory names. */ + strcat(dirname, "/"); + + /* + * Write a dir to it (with trailing '/'). + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, dirname); + archive_entry_set_mode(ae, S_IFDIR | 0755); + failure("Dirname %d/%d", dlen, flen); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + + /* + * Now, read the data back. + */ + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used)); + + /* Read the file and check the filename. */ + assertA(0 == archive_read_next_header(a, &ae)); +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("Leading '/' preserved on long filenames"); +#else + assertEqualString(filename, archive_entry_pathname(ae)); +#endif + assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); + + /* + * Read the two dirs and check the names. + * + * Both dirs should read back with the same name, since + * tar should add a trailing '/' to any dir that doesn't + * already have one. We only report the first such failure + * here. + */ + assertA(0 == archive_read_next_header(a, &ae)); +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("Trailing '/' preserved on dirnames"); +#else + assertEqualString(dirname, archive_entry_pathname(ae)); +#endif + assert((S_IFDIR | 0755) == archive_entry_mode(ae)); + + assertA(0 == archive_read_next_header(a, &ae)); +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("Trailing '/' added to dir names"); +#else + assertEqualString(dirname, archive_entry_pathname(ae)); +#endif + assert((S_IFDIR | 0755) == archive_entry_mode(ae)); + + /* Verify the end of the archive. */ + assert(1 == archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif +} + +DEFINE_TEST(test_tar_filenames) +{ + int dlen, flen; + + /* Repeat the following for a variety of dir/file lengths. */ + for (dlen = 45; dlen < 55; dlen++) { + for (flen = 45; flen < 55; flen++) { + test_filename(NULL, dlen, flen); + test_filename("/", dlen, flen); + } + } + + for (dlen = 0; dlen < 140; dlen += 10) { + for (flen = 98; flen < 102; flen++) { + test_filename(NULL, dlen, flen); + test_filename("/", dlen, flen); + } + } + + for (dlen = 140; dlen < 160; dlen++) { + for (flen = 95; flen < 105; flen++) { + test_filename(NULL, dlen, flen); + test_filename("/", dlen, flen); + } + } +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_tar_large.c b/external/bsd/libarchive/dist/libarchive/test/test_tar_large.c new file mode 100644 index 000000000..adc81551c --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_tar_large.c @@ -0,0 +1,312 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_tar_large.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#include +#include +#include + +/* + * This is a somewhat tricky test that verifies the ability to + * write and read very large entries to tar archives. It + * writes entries from 2GB up to 1TB to an archive in memory. + * The memory storage here carefully avoids actually storing + * any part of the file bodies, so it runs very quickly and requires + * very little memory. If you're willing to wait a few minutes, + * you should be able to exercise petabyte entries with this code. + */ + +/* + * Each file is built up by duplicating the following block. + */ +static size_t filedatasize; +static void *filedata; + +/* + * We store the archive as blocks of data generated by libarchive, + * each possibly followed by bytes of file data. + */ +struct memblock { + struct memblock *next; + size_t size; + void *buff; + int64_t filebytes; +}; + +/* + * The total memory store is just a list of memblocks plus + * some accounting overhead. + */ +struct memdata { + int64_t filebytes; + void *buff; + struct memblock *first; + struct memblock *last; +}; + +/* The following size definitions simplify things below. */ +#define KB ((int64_t)1024) +#define MB ((int64_t)1024 * KB) +#define GB ((int64_t)1024 * MB) +#define TB ((int64_t)1024 * GB) + +#if ARCHIVE_VERSION_NUMBER < 2000000 +static ssize_t memory_read_skip(struct archive *, void *, size_t request); +#else +static off_t memory_read_skip(struct archive *, void *, off_t request); +#endif +static ssize_t memory_read(struct archive *, void *, const void **buff); +static ssize_t memory_write(struct archive *, void *, const void *, size_t); + + +static ssize_t +memory_write(struct archive *a, void *_private, const void *buff, size_t size) +{ + struct memdata *private = _private; + struct memblock *block; + + (void)a; + + /* + * Since libarchive tries to behave in a zero-copy manner, if + * you give a pointer to filedata to the library, a pointer + * into that data will (usually) pop out here. This way, we + * can tell the difference between filedata and library header + * and metadata. + */ + if ((const char *)filedata <= (const char *)buff + && (const char *)buff < (const char *)filedata + filedatasize) { + /* We don't need to store a block of file data. */ + private->last->filebytes += (int64_t)size; + } else { + /* Yes, we're assuming the very first write is metadata. */ + /* It's header or metadata, copy and save it. */ + block = (struct memblock *)malloc(sizeof(*block)); + memset(block, 0, sizeof(*block)); + block->size = size; + block->buff = malloc(size); + memcpy(block->buff, buff, size); + if (private->last == NULL) { + private->first = private->last = block; + } else { + private->last->next = block; + private->last = block; + } + block->next = NULL; + } + return ((long)size); +} + +static ssize_t +memory_read(struct archive *a, void *_private, const void **buff) +{ + struct memdata *private = _private; + struct memblock *block; + ssize_t size; + + (void)a; + + free(private->buff); + private->buff = NULL; + if (private->first == NULL) { + private->last = NULL; + return (ARCHIVE_EOF); + } + if (private->filebytes > 0) { + /* + * We're returning file bytes, simulate it by + * passing blocks from the template data. + */ + if (private->filebytes > (int64_t)filedatasize) + size = (ssize_t)filedatasize; + else + size = (ssize_t)private->filebytes; + private->filebytes -= size; + *buff = filedata; + } else { + /* + * We need to get some real data to return. + */ + block = private->first; + private->first = block->next; + size = (ssize_t)block->size; + if (block->buff != NULL) { + private->buff = block->buff; + *buff = block->buff; + } else { + private->buff = NULL; + *buff = filedata; + } + private->filebytes = block->filebytes; + free(block); + } + return (size); +} + + +#if ARCHIVE_VERSION_NUMBER < 2000000 +static ssize_t +memory_read_skip(struct archive *a, void *private, size_t skip) +{ + (void)a; /* UNUSED */ + (void)private; /* UNUSED */ + (void)skip; /* UNUSED */ + return (0); +} +#else +static off_t +memory_read_skip(struct archive *a, void *_private, off_t skip) +{ + struct memdata *private = _private; + + (void)a; + + if (private->first == NULL) { + private->last = NULL; + return (0); + } + if (private->filebytes > 0) { + if (private->filebytes < skip) + skip = (off_t)private->filebytes; + private->filebytes -= skip; + } else { + skip = 0; + } + return (skip); +} +#endif + +DEFINE_TEST(test_tar_large) +{ + /* The sizes of the entries we're going to generate. */ + static int64_t tests[] = { + /* Test for 32-bit signed overflow. */ + 2 * GB - 1, 2 * GB, 2 * GB + 1, + /* Test for 32-bit unsigned overflow. */ + 4 * GB - 1, 4 * GB, 4 * GB + 1, + /* 8GB is the "official" max for ustar. */ + 8 * GB - 1, 8 * GB, 8 * GB + 1, + /* Bend ustar a tad and you can get 64GB (12 octal digits). */ + 64 * GB - 1, 64 * GB, + /* And larger entries that require non-ustar extensions. */ + 256 * GB, 1 * TB, 0 }; + int i; + char namebuff[64]; + struct memdata memdata; + struct archive_entry *ae; + struct archive *a; + int64_t filesize; + size_t writesize; + + filedatasize = (size_t)(1 * MB); + filedata = malloc(filedatasize); + memset(filedata, 0xAA, filedatasize); + memset(&memdata, 0, sizeof(memdata)); + + /* + * Open an archive for writing. + */ + a = archive_write_new(); + archive_write_set_format_pax_restricted(a); + archive_write_set_bytes_per_block(a, 0); /* No buffering. */ + archive_write_open(a, &memdata, NULL, memory_write, NULL); + + /* + * Write a series of large files to it. + */ + for (i = 0; tests[i] != 0; i++) { + assert((ae = archive_entry_new()) != NULL); + sprintf(namebuff, "file_%d", i); + archive_entry_copy_pathname(ae, namebuff); + archive_entry_set_mode(ae, S_IFREG | 0755); + filesize = tests[i]; + + archive_entry_set_size(ae, filesize); + + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + + /* + * Write the actual data to the archive. + */ + while (filesize > 0) { + writesize = filedatasize; + if ((int64_t)writesize > filesize) + writesize = (size_t)filesize; + assertA((int)writesize + == archive_write_data(a, filedata, writesize)); + filesize -= writesize; + } + } + + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "lastfile"); + archive_entry_set_mode(ae, S_IFREG | 0755); + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + + /* + * Open the same archive for reading. + */ + a = archive_read_new(); + archive_read_support_format_tar(a); + archive_read_open2(a, &memdata, NULL, + memory_read, memory_read_skip, NULL); + + /* + * Read entries back. + */ + for (i = 0; tests[i] > 0; i++) { + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + sprintf(namebuff, "file_%d", i); + assertEqualString(namebuff, archive_entry_pathname(ae)); + assert(tests[i] == archive_entry_size(ae)); + } + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + assertEqualString("lastfile", archive_entry_pathname(ae)); + + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + + /* Close out the archive. */ + assertA(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertA(0 == archive_read_finish(a)); +#endif + + free(memdata.buff); + free(filedata); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_ustar_filenames.c b/external/bsd/libarchive/dist/libarchive/test/test_ustar_filenames.c new file mode 100644 index 000000000..e3ebf3c92 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_ustar_filenames.c @@ -0,0 +1,191 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_ustar_filenames.c 189308 2009-03-03 17:02:51Z kientzle $"); + +/* + * Exercise various lengths of filenames in ustar archives. + */ + +static void +test_filename(const char *prefix, int dlen, int flen) +{ + char buff[8192]; + char filename[400]; + char dirname[400]; + struct archive_entry *ae; + struct archive *a; + size_t used; + int separator = 0; + int i = 0; + + if (prefix != NULL) { + strcpy(filename, prefix); + i = (int)strlen(prefix); + } + if (dlen > 0) { + for (; i < dlen; i++) + filename[i] = 'a'; + filename[i++] = '/'; + separator = 1; + } + for (; i < dlen + flen + separator; i++) + filename[i] = 'b'; + filename[i] = '\0'; + + strcpy(dirname, filename); + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_set_bytes_per_block(a,0)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, filename); + archive_entry_set_mode(ae, S_IFREG | 0755); + failure("dlen=%d, flen=%d", dlen, flen); + if (flen > 100) { + assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); + } else { + assertEqualIntA(a, 0, archive_write_header(a, ae)); + } + archive_entry_free(ae); + + /* + * Write a dir to it (without trailing '/'). + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, dirname); + archive_entry_set_mode(ae, S_IFDIR | 0755); + failure("dlen=%d, flen=%d", dlen, flen); + if (flen >= 100) { + assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); + } else { + assertEqualIntA(a, 0, archive_write_header(a, ae)); + } + archive_entry_free(ae); + + /* Tar adds a '/' to directory names. */ + strcat(dirname, "/"); + + /* + * Write a dir to it (with trailing '/'). + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, dirname); + archive_entry_set_mode(ae, S_IFDIR | 0755); + failure("dlen=%d, flen=%d", dlen, flen); + if (flen >= 100) { + assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); + } else { + assertEqualIntA(a, 0, archive_write_header(a, ae)); + } + archive_entry_free(ae); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertEqualInt(0, archive_write_finish(a)); +#endif + + /* + * Now, read the data back. + */ + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used)); + + if (flen <= 100) { + /* Read the file and check the filename. */ + assertA(0 == archive_read_next_header(a, &ae)); + failure("dlen=%d, flen=%d", dlen, flen); + assertEqualString(filename, archive_entry_pathname(ae)); + assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); + } + + /* + * Read the two dirs and check the names. + * + * Both dirs should read back with the same name, since + * tar should add a trailing '/' to any dir that doesn't + * already have one. + */ + if (flen <= 99) { + assertA(0 == archive_read_next_header(a, &ae)); + assert((S_IFDIR | 0755) == archive_entry_mode(ae)); + failure("dlen=%d, flen=%d", dlen, flen); + assertEqualString(dirname, archive_entry_pathname(ae)); + } + + if (flen <= 99) { + assertA(0 == archive_read_next_header(a, &ae)); + assert((S_IFDIR | 0755) == archive_entry_mode(ae)); + assertEqualString(dirname, archive_entry_pathname(ae)); + } + + /* Verify the end of the archive. */ + failure("This fails if entries were written that should not have been written. dlen=%d, flen=%d", dlen, flen); + assertEqualInt(1, archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(0, archive_read_finish(a)); +#endif +} + +DEFINE_TEST(test_ustar_filenames) +{ + int dlen, flen; + + /* Try a bunch of different file/dir lengths that add up + * to just a little less or a little more than 100 bytes. + * This exercises the code that splits paths between ustar + * filename and prefix fields. + */ + for (dlen = 5; dlen < 70; dlen += 5) { + for (flen = 100 - dlen - 5; flen < 100 - dlen + 5; flen++) { + test_filename(NULL, dlen, flen); + test_filename("/", dlen, flen); + } + } + + /* Probe the 100-char limit for paths with no '/'. */ + for (flen = 90; flen < 110; flen++) { + test_filename(NULL, 0, flen); + test_filename("/", dlen, flen); + } + + /* XXXX TODO Probe the 100-char limit with a dir prefix. */ + /* XXXX TODO Probe the 255-char total limit. */ +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_compress.c b/external/bsd/libarchive/dist/libarchive/test/test_write_compress.c new file mode 100644 index 000000000..aa590de8a --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_compress.c @@ -0,0 +1,102 @@ +/*- + * Copyright (c) 2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress.c 189308 2009-03-03 17:02:51Z kientzle $"); + +/* + * A basic exercise of compress reading and writing. + * + * TODO: Add a reference file and make sure we can decompress that. + */ + +DEFINE_TEST(test_write_compress) +{ + struct archive_entry *ae; + struct archive* a; + char *buff, *data; + size_t buffsize, datasize; + char path[16]; + size_t used; + int i; + + buffsize = 1000000; + assert(NULL != (buff = (char *)malloc(buffsize))); + + datasize = 10000; + assert(NULL != (data = (char *)malloc(datasize))); + memset(data, 0, datasize); + + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertA(0 == archive_write_set_compression_compress(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); + + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize == (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + + + archive_write_close(a); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assert(0 == archive_write_finish(a)); +#endif + + /* + * Now, read the data back. + */ + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used)); + + + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(0, archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + + free(data); + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_compress_bzip2.c b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_bzip2.c new file mode 100644 index 000000000..ee6954022 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_bzip2.c @@ -0,0 +1,228 @@ +/*- + * Copyright (c) 2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_bzip2.c 191183 2009-04-17 01:06:31Z kientzle $"); + +/* + * A basic exercise of bzip2 reading and writing. + * + * TODO: Add a reference file and make sure we can decompress that. + */ + +DEFINE_TEST(test_write_compress_bzip2) +{ + struct archive_entry *ae; + struct archive* a; + char *buff, *data; + size_t buffsize, datasize; + char path[16]; + size_t used1, used2; + int i, r; + + buffsize = 2000000; + assert(NULL != (buff = (char *)malloc(buffsize))); + + datasize = 10000; + assert(NULL != (data = (char *)malloc(datasize))); + memset(data, 0, datasize); + + /* + * Write a 100 files and read them all back. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_bzip2(a); + if (r == ARCHIVE_FATAL) { + skipping("bzip2 writing not supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); + assertEqualString("bzip2", archive_compression_name(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); + assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); + assertEqualString("bzip2", archive_compression_name(a)); + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, datasize); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + archive_entry_copy_pathname(ae, path); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize + == (size_t)archive_write_data(a, data, datasize)); + } + archive_entry_free(ae); + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used1)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(0, archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assert(0 == archive_read_close(a)); + assert(0 == archive_read_finish(a)); + + /* + * Repeat the cycle again, this time setting some compression + * options. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_bzip2(a)); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "nonexistent-option=0")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=abc")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=99")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=9")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize == (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Curiously, this test fails; the test data above compresses + * better at default compression than at level 9. */ + /* + failure("compression-level=9 wrote %d bytes, default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 < used1); + */ + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(0, archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assert(0 == archive_read_close(a)); + assert(0 == archive_read_finish(a)); + + /* + * Repeat again, with much lower compression. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_bzip2(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=1")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + failure("Writing file %s", path); + assertEqualIntA(a, datasize, + (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Level 0 really does result in larger data. */ + failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 > used1); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 999; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(0, archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assert(0 == archive_read_close(a)); + assert(0 == archive_read_finish(a)); + + /* + * Test various premature shutdown scenarios to make sure we + * don't crash or leak memory. + */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Clean up. + */ + free(data); + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_compress_gzip.c b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_gzip.c new file mode 100644 index 000000000..ec55c8db6 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_gzip.c @@ -0,0 +1,252 @@ +/*- + * Copyright (c) 2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_gzip.c 191183 2009-04-17 01:06:31Z kientzle $"); + +/* + * A basic exercise of gzip reading and writing. + * + * TODO: Add a reference file and make sure we can decompress that. + */ + +DEFINE_TEST(test_write_compress_gzip) +{ + struct archive_entry *ae; + struct archive* a; + char *buff, *data; + size_t buffsize, datasize; + char path[16]; + size_t used1, used2; + int i, r; + + buffsize = 2000000; + assert(NULL != (buff = (char *)malloc(buffsize))); + + datasize = 10000; + assert(NULL != (data = (char *)malloc(datasize))); + memset(data, 0, datasize); + + /* + * Write a 100 files and read them all back. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_gzip(a); + if (r == ARCHIVE_FATAL) { + skipping("gzip writing not supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); + assertEqualString("gzip", archive_compression_name(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); + assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); + assertEqualString("gzip", archive_compression_name(a)); + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, datasize); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + archive_entry_copy_pathname(ae, path); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize + == (size_t)archive_write_data(a, data, datasize)); + } + archive_entry_free(ae); + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("Can't verify gzip writing by reading back;" + " gzip reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used1)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat the cycle again, this time setting some compression + * options. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_gzip(a)); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "nonexistent-option=0")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=abc")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=99")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=9")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize == (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Curiously, this test fails; the test data above compresses + * better at default compression than at level 9. */ + /* + failure("compression-level=9 wrote %d bytes, default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 < used1); + */ + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat again, with much lower compression. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_gzip(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=0")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + failure("Writing file %s", path); + assertEqualIntA(a, datasize, + (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Level 0 really does result in larger data. */ + failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 > used1); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + if (r == ARCHIVE_WARN) { + skipping("gzip reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Test various premature shutdown scenarios to make sure we + * don't crash or leak memory. + */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Clean up. + */ + free(data); + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_compress_lzma.c b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_lzma.c new file mode 100644 index 000000000..0b456910d --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_lzma.c @@ -0,0 +1,245 @@ +/*- + * Copyright (c) 2007-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_lzma.c 191183 2009-04-17 01:06:31Z kientzle $"); + +/* + * A basic exercise of lzma reading and writing. + * + */ + +DEFINE_TEST(test_write_compress_lzma) +{ + struct archive_entry *ae; + struct archive* a; + char *buff, *data; + size_t buffsize, datasize; + char path[16]; + size_t used1, used2; + int i, r; + + buffsize = 2000000; + assert(NULL != (buff = (char *)malloc(buffsize))); + + datasize = 10000; + assert(NULL != (data = (char *)malloc(datasize))); + memset(data, 0, datasize); + + /* + * Write a 100 files and read them all back. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_lzma(a); + if (r == ARCHIVE_FATAL) { + skipping("lzma writing not supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); + assertEqualString("lzma", archive_compression_name(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); + assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); + assertEqualString("lzma", archive_compression_name(a)); + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, datasize); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + archive_entry_copy_pathname(ae, path); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize + == (size_t)archive_write_data(a, data, datasize)); + } + archive_entry_free(ae); + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("Can't verify lzma writing by reading back;" + " lzma reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used1)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat the cycle again, this time setting some compression + * options. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_lzma(a)); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "nonexistent-option=0")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=abc")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=99")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=9")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize == (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("lzma reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + failure("Trying to read %s", path); + if (!assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat again, with much lower compression. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_lzma(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=0")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + failure("Writing file %s", path); + assertEqualIntA(a, datasize, + (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Level 0 really does result in larger data. */ + failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 > used1); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + r = archive_read_support_compression_lzma(a); + if (r == ARCHIVE_WARN) { + skipping("lzma reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Test various premature shutdown scenarios to make sure we + * don't crash or leak memory. + */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Clean up. + */ + free(data); + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_compress_program.c b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_program.c new file mode 100644 index 000000000..bae77e534 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_program.c @@ -0,0 +1,118 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_program.c 201247 2009-12-30 05:59:21Z kientzle $"); + +char buff[1000000]; +char buff2[64]; + +DEFINE_TEST(test_write_compress_program) +{ +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("archive_write_set_compress_program()"); +#else + struct archive_entry *ae; + struct archive *a; + size_t used; + int blocksize = 1024; + int r; + + if (!canGzip()) { + skipping("Cannot run 'gzip'"); + return; + } + + /* Create a new archive in memory. */ + /* Write it through an external "gzip" program. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_program(a, "gzip"); + if (r == ARCHIVE_FATAL) { + skipping("Write compression via external " + "program unsupported on this platform"); + archive_write_finish(a); + return; + } + assertA(0 == archive_write_set_bytes_per_block(a, blocksize)); + assertA(0 == archive_write_set_bytes_in_last_block(a, blocksize)); + assertA(blocksize == archive_write_get_bytes_in_last_block(a)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + assertA(blocksize == archive_write_get_bytes_in_last_block(a)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 10); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assertA(8 == archive_write_data(a, "12345678", 9)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); + assertA(0 == archive_write_finish(a)); + + /* + * Now, read the data back through the built-in gzip support. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + r = archive_read_support_compression_gzip(a); + /* The compression_gzip() handler will fall back to gunzip + * automatically, but if we know gunzip isn't available, then + * skip the rest. */ + if (r != ARCHIVE_OK && !canGunzip()) { + skipping("No libz and no gunzip program, " + "unable to verify gzip compression"); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); + + if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) { + archive_read_finish(a); + return; + } + + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); + assertEqualMem(buff2, "12345678", 8); + + /* Verify the end of the archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_compress_xz.c b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_xz.c new file mode 100644 index 000000000..88db2e668 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_compress_xz.c @@ -0,0 +1,253 @@ +/*- + * Copyright (c) 2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_compress_xz.c 191183 2009-04-17 01:06:31Z kientzle $"); + +/* + * A basic exercise of xz reading and writing. + * + * TODO: Add a reference file and make sure we can decompress that. + */ + +DEFINE_TEST(test_write_compress_xz) +{ + struct archive_entry *ae; + struct archive* a; + char *buff, *data; + size_t buffsize, datasize; + char path[16]; + size_t used1, used2; + int i, r; + + buffsize = 2000000; + assert(NULL != (buff = (char *)malloc(buffsize))); + + datasize = 10000; + assert(NULL != (data = (char *)malloc(datasize))); + memset(data, 0, datasize); + + /* + * Write a 100 files and read them all back. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + r = archive_write_set_compression_xz(a); + if (r == ARCHIVE_FATAL) { + skipping("xz writing not supported on this platform"); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + return; + } + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); + assertEqualString("xz", archive_compression_name(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); + assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); + assertEqualString("xz", archive_compression_name(a)); + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, datasize); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + archive_entry_copy_pathname(ae, path); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize + == (size_t)archive_write_data(a, data, datasize)); + } + archive_entry_free(ae); + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("Can't verify xz writing by reading back;" + " xz reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used1)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat the cycle again, this time setting some compression + * options. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_xz(a)); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "nonexistent-option=0")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=abc")); + assertEqualIntA(a, ARCHIVE_WARN, + archive_write_set_compressor_options(a, "compression-level=99")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=9")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + assertA(datasize == (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Curiously, this test fails; the test data above compresses + * better at default compression than at level 9. */ + /* + failure("compression-level=9 wrote %d bytes, default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 < used1); + */ + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + failure("Trying to read %s", path); + if (!assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Repeat again, with much lower compression. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 10)); + assertA(0 == archive_write_set_compression_xz(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_compressor_options(a, "compression-level=0")); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, path); + archive_entry_set_size(ae, datasize); + archive_entry_set_filetype(ae, AE_IFREG); + assertA(0 == archive_write_header(a, ae)); + failure("Writing file %s", path); + assertEqualIntA(a, datasize, + (size_t)archive_write_data(a, data, datasize)); + archive_entry_free(ae); + } + archive_write_close(a); + assert(0 == archive_write_finish(a)); + + /* Level 0 really does result in larger data. */ + failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", + (int)used2, (int)used1); + assert(used2 > used1); + + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + r = archive_read_support_compression_xz(a); + if (r == ARCHIVE_WARN) { + skipping("xz reading not fully supported on this platform"); + } else { + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used2)); + for (i = 0; i < 100; i++) { + sprintf(path, "file%03d", i); + if (!assertEqualInt(ARCHIVE_OK, + archive_read_next_header(a, &ae))) + break; + assertEqualString(path, archive_entry_pathname(ae)); + assertEqualInt((int)datasize, archive_entry_size(ae)); + } + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + } + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + + /* + * Test various premature shutdown scenarios to make sure we + * don't crash or leak memory. + */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Clean up. + */ + free(data); + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_disk.c b/external/bsd/libarchive/dist/libarchive/test/test_write_disk.c new file mode 100644 index 000000000..169f4f239 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_disk.c @@ -0,0 +1,332 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_disk.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#if ARCHIVE_VERSION_NUMBER >= 1009000 + +#define UMASK 022 +/* + * When comparing mode values, ignore high-order bits + * that are set on some OSes. This should cover the bits + * we're interested in (standard mode bits + file type bits) + * while ignoring extra markers such as Haiku/BeOS index + * flags. + */ +#define MODE_MASK 0777777 + +static void create(struct archive_entry *ae, const char *msg) +{ + struct archive *ad; + struct stat st; + + /* Write the entry to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + failure("%s", msg); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(ad); +#else + assertEqualInt(0, archive_write_finish(ad)); +#endif + /* Test the entries on disk. */ + assert(0 == stat(archive_entry_pathname(ae), &st)); + failure("%s", msg); + +#if !defined(_WIN32) || defined(__CYGWIN__) + /* When verifying a dir, ignore the S_ISGID bit, as some systems set + * that automatically. */ + if (archive_entry_filetype(ae) == AE_IFDIR) + st.st_mode &= ~S_ISGID; + assertEqualInt(st.st_mode & MODE_MASK, + archive_entry_mode(ae) & ~UMASK & MODE_MASK); +#endif +} + +static void create_reg_file(struct archive_entry *ae, const char *msg) +{ + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct archive *ad; + + /* Write the entry to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME); + failure("%s", msg); + /* + * A touchy API design issue: archive_write_data() does (as of + * 2.4.12) enforce the entry size as a limit on the data + * written to the file. This was not enforced prior to + * 2.4.12. The change was prompted by the refined + * hardlink-restore semantics introduced at that time. In + * short, libarchive needs to know whether a "hardlink entry" + * is going to overwrite the contents so that it can know + * whether or not to open the file for writing. This implies + * that there is a fundamental semantic difference between an + * entry with a zero size and one with a non-zero size in the + * case of hardlinks and treating the hardlink case + * differently from the regular file case is just asking for + * trouble. So, a zero size must always mean that no data + * will be accepted, which is consistent with the file size in + * the entry being a maximum size. + */ + archive_entry_set_size(ae, sizeof(data)); + archive_entry_set_mtime(ae, 123456789, 0); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(ad); +#else + assertEqualInt(0, archive_write_finish(ad)); +#endif + /* Test the entries on disk. */ + assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777); + assertFileSize(archive_entry_pathname(ae), sizeof(data)); + /* test_write_disk_times has more detailed tests of this area. */ + assertFileMtime(archive_entry_pathname(ae), 123456789, 0); + failure("No atime given, so atime should get set to current time"); + assertFileAtimeRecent(archive_entry_pathname(ae)); +} + +static void create_reg_file2(struct archive_entry *ae, const char *msg) +{ + const int datasize = 100000; + char *data; + struct archive *ad; + int i; + + data = malloc(datasize); + for (i = 0; i < datasize; i++) + data[i] = (char)(i % 256); + + /* Write the entry to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + failure("%s", msg); + /* + * See above for an explanation why this next call + * is necessary. + */ + archive_entry_set_size(ae, datasize); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + for (i = 0; i < datasize - 999; i += 1000) { + assertEqualIntA(ad, ARCHIVE_OK, + archive_write_data_block(ad, data + i, 1000, i)); + } + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + assertEqualInt(0, archive_write_finish(ad)); + + /* Test the entries on disk. */ + assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777); + assertFileSize(archive_entry_pathname(ae), i); + assertFileContents(data, datasize, archive_entry_pathname(ae)); + free(data); +} + +static void create_reg_file3(struct archive_entry *ae, const char *msg) +{ + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct archive *ad; + struct stat st; + + /* Write the entry to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + failure("%s", msg); + /* Set the size smaller than the data and verify the truncation. */ + archive_entry_set_size(ae, 5); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(5, archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(ad); +#else + assertEqualInt(0, archive_write_finish(ad)); +#endif + /* Test the entry on disk. */ + assert(0 == stat(archive_entry_pathname(ae), &st)); + failure("st.st_mode=%o archive_entry_mode(ae)=%o", + st.st_mode, archive_entry_mode(ae)); +#if !defined(_WIN32) || defined(__CYGWIN__) + assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK)); +#endif + assertEqualInt(st.st_size, 5); +} + + +static void create_reg_file4(struct archive_entry *ae, const char *msg) +{ + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct archive *ad; + struct stat st; + + /* Write the entry to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + /* Leave the size unset. The data should not be truncated. */ + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(ARCHIVE_OK, + archive_write_data_block(ad, data, sizeof(data), 0)); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(ad); +#else + assertEqualInt(0, archive_write_finish(ad)); +#endif + /* Test the entry on disk. */ + assert(0 == stat(archive_entry_pathname(ae), &st)); + failure("st.st_mode=%o archive_entry_mode(ae)=%o", + st.st_mode, archive_entry_mode(ae)); +#if !defined(_WIN32) || defined(__CYGWIN__) + assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK)); +#endif + failure(msg); + assertEqualInt(st.st_size, sizeof(data)); +} + +#if defined(_WIN32) && !defined(__CYGWIN__) +static void create_reg_file_win(struct archive_entry *ae, const char *msg) +{ + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct archive *ad; + struct stat st; + char *p, *fname; + size_t l; + + /* Write the entry to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME); + failure("%s", msg); + archive_entry_set_size(ae, sizeof(data)); + archive_entry_set_mtime(ae, 123456789, 0); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(ad); +#else + assertEqualInt(0, archive_write_finish(ad)); +#endif + /* Test the entries on disk. */ + l = strlen(archive_entry_pathname(ae)); + fname = malloc(l + 1); + assert(NULL != fname); + strcpy(fname, archive_entry_pathname(ae)); + /* Replace unusable characters in Windows to '_' */ + for (p = fname; *p != '\0'; p++) + if (*p == ':' || *p == '*' || *p == '?' || + *p == '"' || *p == '<' || *p == '>' || *p == '|') + *p = '_'; + assert(0 == stat(fname, &st)); + failure("st.st_mode=%o archive_entry_mode(ae)=%o", + st.st_mode, archive_entry_mode(ae)); + assertEqualInt(st.st_size, sizeof(data)); +} +#endif /* _WIN32 && !__CYGWIN__ */ +#endif + +DEFINE_TEST(test_write_disk) +{ +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("archive_write_disk interface"); +#else + struct archive_entry *ae; + + /* Force the umask to something predictable. */ + assertUmask(UMASK); + + /* A regular file. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + create_reg_file(ae, "Test creating a regular file"); + archive_entry_free(ae); + + /* Another regular file. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + create_reg_file2(ae, "Test creating another regular file"); + archive_entry_free(ae); + + /* A regular file with a size restriction */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file3"); + archive_entry_set_mode(ae, S_IFREG | 0755); + create_reg_file3(ae, "Regular file with size restriction"); + archive_entry_free(ae); + + /* A regular file with an unspecified size */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file3"); + archive_entry_set_mode(ae, S_IFREG | 0755); + create_reg_file4(ae, "Regular file with unspecified size"); + archive_entry_free(ae); + + /* A regular file over an existing file */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0724); + create(ae, "Test creating a file over an existing file."); + archive_entry_free(ae); + + /* A directory. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "dir"); + archive_entry_set_mode(ae, S_IFDIR | 0555); + create(ae, "Test creating a regular dir."); + archive_entry_free(ae); + + /* A directory over an existing file. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFDIR | 0742); + create(ae, "Test creating a dir over an existing file."); + archive_entry_free(ae); + + /* A file over an existing dir. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0744); + create(ae, "Test creating a file over an existing dir."); + archive_entry_free(ae); + +#if defined(_WIN32) && !defined(__CYGWIN__) + /* A file with unusable characters in its file name. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "f:i*l?e\"fl|e"); + archive_entry_set_mode(ae, S_IFREG | 0755); + create_reg_file_win(ae, "Test creating a regular file" + " with unusable characters in its file name"); + archive_entry_free(ae); + + /* A file with unusable characters in its directory name. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "d:i*r?e\"co|ry/file1"); + archive_entry_set_mode(ae, S_IFREG | 0755); + create_reg_file_win(ae, "Test creating a regular file" + " with unusable characters in its file name"); + archive_entry_free(ae); +#endif /* _WIN32 && !__CYGWIN__ */ +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_disk_failures.c b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_failures.c new file mode 100644 index 000000000..991fa3d4f --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_failures.c @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_disk_failures.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#if ARCHIVE_VERSION_NUMBER >= 1009000 + +#define UMASK 022 + + +#endif + +DEFINE_TEST(test_write_disk_failures) +{ +#if ARCHIVE_VERSION_NUMBER < 1009000 || (defined(_WIN32) && !defined(__CYGWIN__)) + skipping("archive_write_disk interface"); +#else + struct archive_entry *ae; + struct archive *a; + int fd; + + /* Force the umask to something predictable. */ + assertUmask(UMASK); + + /* A directory that we can't write to. */ + assertMakeDir("dir", 0555); + + /* Can we? */ + fd = open("dir/testfile", O_WRONLY | O_CREAT | O_BINARY, 0777); + if (fd >= 0) { + /* Apparently, we can, so the test below won't work. */ + close(fd); + skipping("Can't test writing to non-writable directory"); + return; + } + + /* Try to extract a regular file into the directory above. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "dir/file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assert((a = archive_write_disk_new()) != NULL); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_TIME); + archive_entry_set_mtime(ae, 123456789, 0); + assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); + assertEqualIntA(a, 0, archive_write_finish_entry(a)); + assertEqualInt(0, archive_write_finish(a)); + archive_entry_free(ae); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_disk_hardlink.c b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_hardlink.c new file mode 100644 index 000000000..934aa08d5 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_hardlink.c @@ -0,0 +1,219 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_disk_hardlink.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#if defined(_WIN32) && !defined(__CYGWIN__) +/* Execution bits, Group members bits and others bits do not work. */ +#define UMASK 0177 +#define E_MASK (~0177) +#else +#define UMASK 022 +#define E_MASK (~0) +#endif + +/* + * Exercise hardlink recreation. + * + * File permissions are chosen so that the authoritive entry + * has the correct permission and the non-authoritive versions + * are just writeable files. + */ +DEFINE_TEST(test_write_disk_hardlink) +{ +#if defined(__HAIKU__) + skipping("archive_write_disk_hardlink; hardlinks are not supported on bfs"); +#else + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct archive *ad; + struct archive_entry *ae; + int r; + + /* Force the umask to something predictable. */ + assertUmask(UMASK); + + /* Write entries to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + + /* + * First, use a tar-like approach; a regular file, then + * a separate "hardlink" entry. + */ + + /* Regular file. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link1a"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, sizeof(data)); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(sizeof(data), + archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + archive_entry_free(ae); + + /* Link. Size of zero means this doesn't carry data. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link1b"); + archive_entry_set_mode(ae, S_IFREG | 0642); + archive_entry_set_size(ae, 0); + archive_entry_copy_hardlink(ae, "link1a"); + assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); + if (r >= ARCHIVE_WARN) { + assertEqualInt(ARCHIVE_WARN, + archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + } + archive_entry_free(ae); + + /* + * Repeat tar approach test, but use unset to mark the + * hardlink as having no data. + */ + + /* Regular file. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link2a"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, sizeof(data)); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(sizeof(data), + archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + archive_entry_free(ae); + + /* Link. Unset size means this doesn't carry data. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link2b"); + archive_entry_set_mode(ae, S_IFREG | 0642); + archive_entry_unset_size(ae); + archive_entry_copy_hardlink(ae, "link2a"); + assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); + if (r >= ARCHIVE_WARN) { + assertEqualInt(ARCHIVE_WARN, + archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + } + archive_entry_free(ae); + + /* + * Second, try an old-cpio-like approach; a regular file, then + * another identical one (which has been marked hardlink). + */ + + /* Regular file. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link3a"); + archive_entry_set_mode(ae, S_IFREG | 0600); + archive_entry_set_size(ae, sizeof(data)); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + archive_entry_free(ae); + + /* Link. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link3b"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, sizeof(data)); + archive_entry_copy_hardlink(ae, "link3a"); + assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); + if (r > ARCHIVE_WARN) { + assertEqualInt(sizeof(data), + archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + } + archive_entry_free(ae); + + /* + * Finally, try a new-cpio-like approach, where the initial + * regular file is empty and the hardlink has the data. + */ + + /* Regular file. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link4a"); + archive_entry_set_mode(ae, S_IFREG | 0600); + archive_entry_set_size(ae, 0); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); +#if ARCHIVE_VERSION_NUMBER < 3000000 + assertEqualInt(ARCHIVE_WARN, archive_write_data(ad, data, 1)); +#else + assertEqualInt(-1, archive_write_data(ad, data, 1)); +#endif + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + archive_entry_free(ae); + + /* Link. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link4b"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, sizeof(data)); + archive_entry_copy_hardlink(ae, "link4a"); + assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); + if (r > ARCHIVE_FAILED) { + assertEqualInt(sizeof(data), + archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + } + archive_entry_free(ae); + assertEqualInt(0, archive_write_finish(ad)); + + /* Test the entries on disk. */ + + /* Test #1 */ + /* If the hardlink was successfully created and the archive + * doesn't carry data for it, we consider it to be + * non-authoritive for meta data as well. This is consistent + * with GNU tar and BSD pax. */ + assertIsReg("link1a", 0755 & ~UMASK); + assertFileSize("link1a", sizeof(data)); + assertFileNLinks("link1a", 2); + assertIsHardlink("link1a", "link1b"); + + /* Test #2: Should produce identical results to test #1 */ + /* Note that marking a hardlink with size = 0 is treated the + * same as having an unset size. This is partly for backwards + * compatibility (we used to not have unset tracking, so + * relied on size == 0) and partly to match the model used by + * common file formats that store a size of zero for + * hardlinks. */ + assertIsReg("link2a", 0755 & ~UMASK); + assertFileSize("link2a", sizeof(data)); + assertFileNLinks("link2a", 2); + assertIsHardlink("link2a", "link2b"); + + /* Test #3 */ + assertIsReg("link3a", 0755 & ~UMASK); + assertFileSize("link3a", sizeof(data)); + assertFileNLinks("link3a", 2); + assertIsHardlink("link3a", "link3b"); + + /* Test #4 */ + assertIsReg("link4a", 0755 & ~UMASK); + assertFileNLinks("link4a", 2); + assertFileSize("link4a", sizeof(data)); + assertIsHardlink("link4a", "link4b"); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_disk_perms.c b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_perms.c new file mode 100644 index 000000000..207444833 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_perms.c @@ -0,0 +1,457 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_disk_perms.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#if ARCHIVE_VERSION_NUMBER >= 1009000 && (!defined(_WIN32) || defined(__CYGWIN__)) + +#define UMASK 022 + +static long _default_gid = -1; +static long _invalid_gid = -1; +static long _alt_gid = -1; + +/* + * To fully test SGID restores, we need three distinct GIDs to work + * with: + * * the GID that files are created with by default (for the + * current user in the current directory) + * * An "alt gid" that this user can create files with + * * An "invalid gid" that this user is not permitted to create + * files with. + * The second fails if this user doesn't belong to at least two groups; + * the third fails if the current user is root. + */ +static void +searchgid(void) +{ + static int _searched = 0; + uid_t uid = getuid(); + gid_t gid = 0; + unsigned int n; + struct stat st; + int fd; + + /* If we've already looked this up, we're done. */ + if (_searched) + return; + _searched = 1; + + /* Create a file on disk in the current default dir. */ + fd = open("test_gid", O_CREAT | O_BINARY, 0664); + failure("Couldn't create a file for gid testing."); + assert(fd > 0); + + /* See what GID it ended up with. This is our "valid" GID. */ + assert(fstat(fd, &st) == 0); + _default_gid = st.st_gid; + + /* Find a GID for which fchown() fails. This is our "invalid" GID. */ + _invalid_gid = -1; + /* This loop stops when we wrap the gid or examine 10,000 gids. */ + for (gid = 1, n = 1; gid == n && n < 10000 ; n++, gid++) { + if (fchown(fd, uid, gid) != 0) { + _invalid_gid = gid; + break; + } + } + + /* + * Find a GID for which fchown() succeeds, but which isn't the + * default. This is the "alternate" gid. + */ + _alt_gid = -1; + for (gid = 0, n = 0; gid == n && n < 10000 ; n++, gid++) { + /* _alt_gid must be different than _default_gid */ + if (gid == (gid_t)_default_gid) + continue; + if (fchown(fd, uid, gid) == 0) { + _alt_gid = gid; + break; + } + } + close(fd); +} + +static int +altgid(void) +{ + searchgid(); + return (_alt_gid); +} + +static int +invalidgid(void) +{ + searchgid(); + return (_invalid_gid); +} + +static int +defaultgid(void) +{ + searchgid(); + return (_default_gid); +} +#endif + +/* + * Exercise permission and ownership restores. + * In particular, try to exercise a bunch of border cases related + * to files/dirs that already exist, SUID/SGID bits, etc. + */ + +DEFINE_TEST(test_write_disk_perms) +{ +#if ARCHIVE_VERSION_NUMBER < 1009000 || (defined(_WIN32) && !defined(__CYGWIN__)) + skipping("archive_write_disk interface"); +#else + struct archive *a; + struct archive_entry *ae; + struct stat st; + + assertUmask(UMASK); + + /* + * Set ownership of the current directory to the group of this + * process. Otherwise, the SGID tests below fail if the + * /tmp directory is owned by a group to which we don't belong + * and we're on a system where group ownership is inherited. + * (Because we're not allowed to SGID files with defaultgid().) + */ + assertEqualInt(0, chown(".", getuid(), getgid())); + + /* Create an archive_write_disk object. */ + assert((a = archive_write_disk_new()) != NULL); + + /* Write a regular file to it. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file_0755"); + archive_entry_set_mode(ae, S_IFREG | 0777); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + archive_entry_free(ae); + + /* Write a regular file, then write over it. */ + /* For files, the perms should get updated. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file_overwrite_0144"); + archive_entry_set_mode(ae, S_IFREG | 0777); + assert(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assert(0 == archive_write_finish_entry(a)); + /* Check that file was created with different perms. */ + assert(0 == stat("file_overwrite_0144", &st)); + failure("file_overwrite_0144: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) != 0144); + /* Overwrite, this should change the perms. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file_overwrite_0144"); + archive_entry_set_mode(ae, S_IFREG | 0144); + assert(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assert(0 == archive_write_finish_entry(a)); + + /* Write a regular dir. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "dir_0514"); + archive_entry_set_mode(ae, S_IFDIR | 0514); + assert(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assert(0 == archive_write_finish_entry(a)); + + /* Overwrite an existing dir. */ + /* For dir, the first perms should get left. */ + assertMakeDir("dir_overwrite_0744", 0744); + /* Check original perms. */ + assert(0 == stat("dir_overwrite_0744", &st)); + failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 0777) == 0744); + /* Overwrite shouldn't edit perms. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "dir_overwrite_0744"); + archive_entry_set_mode(ae, S_IFDIR | 0777); + assert(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assert(0 == archive_write_finish_entry(a)); + /* Make sure they're unchanged. */ + assert(0 == stat("dir_overwrite_0744", &st)); + failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 0777) == 0744); + + /* Write a regular file with SUID bit, but don't use _EXTRACT_PERM. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file_no_suid"); + archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0777); + archive_write_disk_set_options(a, 0); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + + /* Write a regular file with ARCHIVE_EXTRACT_PERM. */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_0777"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + + /* Write a regular file with ARCHIVE_EXTRACT_PERM & SUID bit */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_4742"); + archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0742); + archive_entry_set_uid(ae, getuid()); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + + /* + * Write a regular file with ARCHIVE_EXTRACT_PERM & SUID bit, + * but wrong uid. POSIX says you shouldn't restore SUID bit + * unless the UID could be restored. + */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_bad_suid"); + archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0742); + archive_entry_set_uid(ae, getuid() + 1); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); + assertA(0 == archive_write_header(a, ae)); + /* + * Because we didn't ask for owner, the failure to + * restore SUID shouldn't return a failure. + * We check below to make sure SUID really wasn't set. + * See more detailed comments below. + */ + failure("Opportunistic SUID failure shouldn't return error."); + assertEqualInt(0, archive_write_finish_entry(a)); + + if (getuid() != 0) { + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_bad_suid2"); + archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0742); + archive_entry_set_uid(ae, getuid() + 1); + archive_write_disk_set_options(a, + ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_OWNER); + assertA(0 == archive_write_header(a, ae)); + /* Owner change should fail here. */ + failure("Non-opportunistic SUID failure should return error."); + assertEqualInt(ARCHIVE_WARN, archive_write_finish_entry(a)); + } + + /* Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_perm_sgid"); + archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); + archive_entry_set_gid(ae, defaultgid()); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); + assert(0 == archive_write_header(a, ae)); + failure("Setting SGID bit should succeed here."); + assertEqualIntA(a, 0, archive_write_finish_entry(a)); + + if (altgid() == -1) { + /* + * Current user must belong to at least two groups or + * else we can't test setting the GID to another group. + */ + skipping("Current user can't test gid restore: must belong to more than one group."); + } else { + /* + * Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit + * but without ARCHIVE_EXTRACT_OWNER. + */ + /* + * This is a weird case: The user has asked for permissions to + * be restored but not asked for ownership to be restored. As + * a result, the default file creation will create a file with + * the wrong group. There are several possible behaviors for + * libarchive in this scenario: + * = Set the SGID bit. It is wrong and a security hole to + * set SGID with the wrong group. Even POSIX thinks so. + * = Implicitly set the group. I don't like this. + * = drop the SGID bit and warn (the old libarchive behavior) + * = drop the SGID bit and don't warn (the current libarchive + * behavior). + * The current behavior sees SGID/SUID restore when you + * don't ask for owner restore as an "opportunistic" + * action. That is, libarchive should do it if it can, + * but if it can't, it's not an error. + */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_alt_sgid"); + archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); + archive_entry_set_uid(ae, getuid()); + archive_entry_set_gid(ae, altgid()); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); + assert(0 == archive_write_header(a, ae)); + failure("Setting SGID bit should fail because of group mismatch but the failure should be silent because we didn't ask for the group to be set."); + assertEqualIntA(a, 0, archive_write_finish_entry(a)); + + /* + * As above, but add _EXTRACT_OWNER to verify that it + * does succeed. + */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_alt_sgid_owner"); + archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); + archive_entry_set_uid(ae, getuid()); + archive_entry_set_gid(ae, altgid()); + archive_write_disk_set_options(a, + ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_OWNER); + assert(0 == archive_write_header(a, ae)); + failure("Setting SGID bit should succeed here."); + assertEqualIntA(a, ARCHIVE_OK, archive_write_finish_entry(a)); + } + + /* + * Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit, + * but wrong GID. POSIX says you shouldn't restore SGID bit + * unless the GID could be restored. + */ + if (invalidgid() == -1) { + /* This test always fails for root. */ + printf("Running as root: Can't test SGID failures.\n"); + } else { + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_bad_sgid"); + archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); + archive_entry_set_gid(ae, invalidgid()); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); + assertA(0 == archive_write_header(a, ae)); + failure("This SGID restore should fail without an error."); + assertEqualIntA(a, 0, archive_write_finish_entry(a)); + + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_bad_sgid2"); + archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); + archive_entry_set_gid(ae, invalidgid()); + archive_write_disk_set_options(a, + ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_OWNER); + assertA(0 == archive_write_header(a, ae)); + failure("This SGID restore should fail with an error."); + assertEqualIntA(a, ARCHIVE_WARN, archive_write_finish_entry(a)); + } + + /* Set ownership should fail if we're not root. */ + if (getuid() == 0) { + printf("Running as root: Can't test setuid failures.\n"); + } else { + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "file_bad_owner"); + archive_entry_set_mode(ae, S_IFREG | 0744); + archive_entry_set_uid(ae, getuid() + 1); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_OWNER); + assertA(0 == archive_write_header(a, ae)); + assertEqualIntA(a,ARCHIVE_WARN,archive_write_finish_entry(a)); + } + +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assert(0 == archive_write_finish(a)); +#endif + archive_entry_free(ae); + + /* Test the entries on disk. */ + assert(0 == stat("file_0755", &st)); + failure("file_0755: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == 0755); + + assert(0 == stat("file_overwrite_0144", &st)); + failure("file_overwrite_0144: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == 0144); + + assert(0 == stat("dir_0514", &st)); + failure("dir_0514: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == 0514); + + assert(0 == stat("dir_overwrite_0744", &st)); + failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 0777) == 0744); + + assert(0 == stat("file_no_suid", &st)); + failure("file_0755: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == 0755); + + assert(0 == stat("file_0777", &st)); + failure("file_0777: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == 0777); + + /* SUID bit should get set here. */ + assert(0 == stat("file_4742", &st)); + failure("file_4742: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == (S_ISUID | 0742)); + + /* SUID bit should NOT have been set here. */ + assert(0 == stat("file_bad_suid", &st)); + failure("file_bad_suid: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == (0742)); + + /* Some things don't fail if you're root, so suppress this. */ + if (getuid() != 0) { + /* SUID bit should NOT have been set here. */ + assert(0 == stat("file_bad_suid2", &st)); + failure("file_bad_suid2: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == (0742)); + } + + /* SGID should be set here. */ + assert(0 == stat("file_perm_sgid", &st)); + failure("file_perm_sgid: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == (S_ISGID | 0742)); + + if (altgid() != -1) { + /* SGID should not be set here. */ + assert(0 == stat("file_alt_sgid", &st)); + failure("file_alt_sgid: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == (0742)); + + /* SGID should be set here. */ + assert(0 == stat("file_alt_sgid_owner", &st)); + failure("file_alt_sgid: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == (S_ISGID | 0742)); + } + + if (invalidgid() != -1) { + /* SGID should NOT be set here. */ + assert(0 == stat("file_bad_sgid", &st)); + failure("file_bad_sgid: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == (0742)); + /* SGID should NOT be set here. */ + assert(0 == stat("file_bad_sgid2", &st)); + failure("file_bad_sgid2: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == (0742)); + } + + if (getuid() != 0) { + assert(0 == stat("file_bad_owner", &st)); + failure("file_bad_owner: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == (0744)); + failure("file_bad_owner: st.st_uid=%d getuid()=%d", + st.st_uid, getuid()); + /* The entry had getuid()+1, but because we're + * not root, we should not have been able to set that. */ + assert(st.st_uid == getuid()); + } +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_disk_secure.c b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_secure.c new file mode 100644 index 000000000..c14dadccf --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_secure.c @@ -0,0 +1,215 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_disk_secure.c 201247 2009-12-30 05:59:21Z kientzle $"); + +#define UMASK 022 + +/* + * Exercise security checks that should prevent certain + * writes. + */ + +DEFINE_TEST(test_write_disk_secure) +{ +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("archive_write_disk interface"); +#elif !defined(_WIN32) || defined(__CYGWIN__) + struct archive *a; + struct archive_entry *ae; + struct stat st; + + /* Start with a known umask. */ + assertUmask(UMASK); + + /* Create an archive_write_disk object. */ + assert((a = archive_write_disk_new()) != NULL); + + /* Write a regular dir to it. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "dir"); + archive_entry_set_mode(ae, S_IFDIR | 0777); + assert(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assert(0 == archive_write_finish_entry(a)); + + /* Write a symlink to the dir above. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir"); + archive_entry_set_mode(ae, S_IFLNK | 0777); + archive_entry_set_symlink(ae, "dir"); + archive_write_disk_set_options(a, 0); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + + /* + * Without security checks, we should be able to + * extract a file through the link. + */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir/filea"); + archive_entry_set_mode(ae, S_IFREG | 0777); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + + /* But with security checks enabled, this should fail. */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir/fileb"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_SYMLINKS); + failure("Extracting a file through a symlink should fail here."); + assertEqualInt(ARCHIVE_FAILED, archive_write_header(a, ae)); + archive_entry_free(ae); + assert(0 == archive_write_finish_entry(a)); + + /* Create another link. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir2"); + archive_entry_set_mode(ae, S_IFLNK | 0777); + archive_entry_set_symlink(ae, "dir"); + archive_write_disk_set_options(a, 0); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + + /* + * With symlink check and unlink option, it should remove + * the link and create the dir. + */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir2/filec"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_SYMLINKS | ARCHIVE_EXTRACT_UNLINK); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assert(0 == archive_write_finish_entry(a)); + + /* + * Without security checks, extracting a dir over a link to a + * dir should follow the link. + */ + /* Create a symlink to a dir. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir3"); + archive_entry_set_mode(ae, S_IFLNK | 0777); + archive_entry_set_symlink(ae, "dir"); + archive_write_disk_set_options(a, 0); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + /* Extract a dir whose name matches the symlink. */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir3"); + archive_entry_set_mode(ae, S_IFDIR | 0777); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + /* Verify link was followed. */ + assertEqualInt(0, lstat("link_to_dir3", &st)); + assert(S_ISLNK(st.st_mode)); + archive_entry_free(ae); + + /* + * As above, but a broken link, so the link should get replaced. + */ + /* Create a symlink to a dir. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir4"); + archive_entry_set_mode(ae, S_IFLNK | 0777); + archive_entry_set_symlink(ae, "nonexistent_dir"); + archive_write_disk_set_options(a, 0); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + /* Extract a dir whose name matches the symlink. */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir4"); + archive_entry_set_mode(ae, S_IFDIR | 0777); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + /* Verify link was replaced. */ + assertEqualInt(0, lstat("link_to_dir4", &st)); + assert(S_ISDIR(st.st_mode)); + archive_entry_free(ae); + + /* + * As above, but a link to a non-dir, so the link should get replaced. + */ + /* Create a regular file and a symlink to it */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "non_dir"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_write_disk_set_options(a, 0); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + /* Create symlink to the file. */ + archive_entry_copy_pathname(ae, "link_to_dir5"); + archive_entry_set_mode(ae, S_IFLNK | 0777); + archive_entry_set_symlink(ae, "non_dir"); + archive_write_disk_set_options(a, 0); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + /* Extract a dir whose name matches the symlink. */ + assert(archive_entry_clear(ae) != NULL); + archive_entry_copy_pathname(ae, "link_to_dir5"); + archive_entry_set_mode(ae, S_IFDIR | 0777); + assert(0 == archive_write_header(a, ae)); + assert(0 == archive_write_finish_entry(a)); + /* Verify link was replaced. */ + assertEqualInt(0, lstat("link_to_dir5", &st)); + assert(S_ISDIR(st.st_mode)); + archive_entry_free(ae); + + assert(0 == archive_write_finish(a)); + + /* Test the entries on disk. */ + assert(0 == lstat("dir", &st)); + failure("dir: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 0777) == 0755); + + assert(0 == lstat("link_to_dir", &st)); + failure("link_to_dir: st.st_mode=%o", st.st_mode); + assert(S_ISLNK(st.st_mode)); +#if HAVE_LCHMOD + /* Systems that lack lchmod() can't set symlink perms, so skip this. */ + failure("link_to_dir: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == 0755); +#endif + + assert(0 == lstat("dir/filea", &st)); + failure("dir/filea: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == 0755); + + failure("dir/fileb: This file should not have been created"); + assert(0 != lstat("dir/fileb", &st)); + + assert(0 == lstat("link_to_dir2", &st)); + failure("link_to_dir2 should have been re-created as a true dir"); + assert(S_ISDIR(st.st_mode)); + failure("link_to_dir2: Implicit dir creation should obey umask, but st.st_mode=%o", st.st_mode); + assert((st.st_mode & 0777) == 0755); + + assert(0 == lstat("link_to_dir2/filec", &st)); + assert(S_ISREG(st.st_mode)); + failure("link_to_dir2/filec: st.st_mode=%o", st.st_mode); + assert((st.st_mode & 07777) == 0755); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_disk_sparse.c b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_sparse.c new file mode 100644 index 000000000..638f0a4b2 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_sparse.c @@ -0,0 +1,280 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_disk_sparse.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* + * Write a file using archive_write_data call, read the file + * back and verify the contents. The data written includes large + * blocks of nulls, so it should exercise the sparsification logic + * if ARCHIVE_EXTRACT_SPARSE is enabled. + */ +static void +verify_write_data(struct archive *a, int sparse) +{ + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct stat st; + struct archive_entry *ae; + size_t buff_size = 64 * 1024; + char *buff, *p; + const char *msg = sparse ? "sparse" : "non-sparse"; + FILE *f; + + buff = malloc(buff_size); + assert(buff != NULL); + + ae = archive_entry_new(); + assert(ae != NULL); + archive_entry_set_size(ae, 8 * buff_size); + archive_entry_set_pathname(ae, "test_write_data"); + archive_entry_set_mode(ae, AE_IFREG | 0755); + assertEqualIntA(a, 0, archive_write_header(a, ae)); + + /* Use archive_write_data() to write three relatively sparse blocks. */ + + /* First has non-null data at beginning. */ + memset(buff, 0, buff_size); + memcpy(buff, data, sizeof(data)); + failure("%s", msg); + assertEqualInt(buff_size, archive_write_data(a, buff, buff_size)); + + /* Second has non-null data in the middle. */ + memset(buff, 0, buff_size); + memcpy(buff + buff_size / 2 - 3, data, sizeof(data)); + failure("%s", msg); + assertEqualInt(buff_size, archive_write_data(a, buff, buff_size)); + + /* Third has non-null data at the end. */ + memset(buff, 0, buff_size); + memcpy(buff + buff_size - sizeof(data), data, sizeof(data)); + failure("%s", msg); + assertEqualInt(buff_size, archive_write_data(a, buff, buff_size)); + + failure("%s", msg); + assertEqualIntA(a, 0, archive_write_finish_entry(a)); + + /* Test the entry on disk. */ + assert(0 == stat(archive_entry_pathname(ae), &st)); + assertEqualInt(st.st_size, 8 * buff_size); + f = fopen(archive_entry_pathname(ae), "rb"); + if (!assert(f != NULL)) + return; + + /* Check first block. */ + assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); + failure("%s", msg); + assertEqualMem(buff, data, sizeof(data)); + for (p = buff + sizeof(data); p < buff + buff_size; ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (!assertEqualInt(0, *p)) + break; + } + + /* Check second block. */ + assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); + for (p = buff; p < buff + buff_size; ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (p == buff + buff_size / 2 - 3) { + assertEqualMem(p, data, sizeof(data)); + p += sizeof(data); + } else if (!assertEqualInt(0, *p)) + break; + } + + /* Check third block. */ + assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); + for (p = buff; p < buff + buff_size - sizeof(data); ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (!assertEqualInt(0, *p)) + break; + } + failure("%s", msg); + assertEqualMem(buff + buff_size - sizeof(data), data, sizeof(data)); + + /* XXX more XXX */ + + assertEqualInt(0, fclose(f)); + archive_entry_free(ae); + free(buff); +} + +/* + * As above, but using the archive_write_data_block() call. + */ +static void +verify_write_data_block(struct archive *a, int sparse) +{ + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct stat st; + struct archive_entry *ae; + size_t buff_size = 64 * 1024; + char *buff, *p; + const char *msg = sparse ? "sparse" : "non-sparse"; + FILE *f; + + buff = malloc(buff_size); + assert(buff != NULL); + + ae = archive_entry_new(); + assert(ae != NULL); + archive_entry_set_size(ae, 8 * buff_size); + archive_entry_set_pathname(ae, "test_write_data_block"); + archive_entry_set_mode(ae, AE_IFREG | 0755); + assertEqualIntA(a, 0, archive_write_header(a, ae)); + + /* Use archive_write_data_block() to write three + relatively sparse blocks. */ + + /* First has non-null data at beginning. */ + memset(buff, 0, buff_size); + memcpy(buff, data, sizeof(data)); + failure("%s", msg); + assertEqualInt(ARCHIVE_OK, + archive_write_data_block(a, buff, buff_size, 100)); + + /* Second has non-null data in the middle. */ + memset(buff, 0, buff_size); + memcpy(buff + buff_size / 2 - 3, data, sizeof(data)); + failure("%s", msg); + assertEqualInt(ARCHIVE_OK, + archive_write_data_block(a, buff, buff_size, buff_size + 200)); + + /* Third has non-null data at the end. */ + memset(buff, 0, buff_size); + memcpy(buff + buff_size - sizeof(data), data, sizeof(data)); + failure("%s", msg); + assertEqualInt(ARCHIVE_OK, + archive_write_data_block(a, buff, buff_size, buff_size * 2 + 300)); + + failure("%s", msg); + assertEqualIntA(a, 0, archive_write_finish_entry(a)); + + /* Test the entry on disk. */ + assert(0 == stat(archive_entry_pathname(ae), &st)); + assertEqualInt(st.st_size, 8 * buff_size); + f = fopen(archive_entry_pathname(ae), "rb"); + if (!assert(f != NULL)) + return; + + /* Check 100-byte gap at beginning */ + assertEqualInt(100, fread(buff, 1, 100, f)); + failure("%s", msg); + for (p = buff; p < buff + 100; ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (!assertEqualInt(0, *p)) + break; + } + + /* Check first block. */ + assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); + failure("%s", msg); + assertEqualMem(buff, data, sizeof(data)); + for (p = buff + sizeof(data); p < buff + buff_size; ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (!assertEqualInt(0, *p)) + break; + } + + /* Check 100-byte gap */ + assertEqualInt(100, fread(buff, 1, 100, f)); + failure("%s", msg); + for (p = buff; p < buff + 100; ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (!assertEqualInt(0, *p)) + break; + } + + /* Check second block. */ + assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); + for (p = buff; p < buff + buff_size; ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (p == buff + buff_size / 2 - 3) { + assertEqualMem(p, data, sizeof(data)); + p += sizeof(data); + } else if (!assertEqualInt(0, *p)) + break; + } + + /* Check 100-byte gap */ + assertEqualInt(100, fread(buff, 1, 100, f)); + failure("%s", msg); + for (p = buff; p < buff + 100; ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (!assertEqualInt(0, *p)) + break; + } + + /* Check third block. */ + assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); + for (p = buff; p < buff + buff_size - sizeof(data); ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (!assertEqualInt(0, *p)) + break; + } + failure("%s", msg); + assertEqualMem(buff + buff_size - sizeof(data), data, sizeof(data)); + + /* Check another block size beyond last we wrote. */ + assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); + failure("%s", msg); + for (p = buff; p < buff + buff_size; ++p) { + failure("offset: %d, %s", (int)(p - buff), msg); + if (!assertEqualInt(0, *p)) + break; + } + + + /* XXX more XXX */ + + assertEqualInt(0, fclose(f)); + free(buff); + archive_entry_free(ae); +} + +DEFINE_TEST(test_write_disk_sparse) +{ + struct archive *ad; + + + /* + * The return values, etc, of the write data functions + * shouldn't change regardless of whether we've requested + * sparsification. (The performance and pattern of actual + * write calls to the disk should vary, of course, but the + * client program shouldn't see any difference.) + */ + assert((ad = archive_write_disk_new()) != NULL); + archive_write_disk_set_options(ad, 0); + verify_write_data(ad, 0); + verify_write_data_block(ad, 0); + assertEqualInt(0, archive_write_finish(ad)); + + assert((ad = archive_write_disk_new()) != NULL); + archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_SPARSE); + verify_write_data(ad, 1); + verify_write_data_block(ad, 1); + assertEqualInt(0, archive_write_finish(ad)); + +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_disk_symlink.c b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_symlink.c new file mode 100644 index 000000000..60d0bdcbb --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_symlink.c @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_disk_symlink.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* + * Exercise symlink recreation. + */ +DEFINE_TEST(test_write_disk_symlink) +{ + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct archive *ad; + struct archive_entry *ae; + int r; + + if (!canSymlink()) { + skipping("Symlinks not supported"); + return; + } + + /* Write entries to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + + /* + * First, create a regular file then a symlink to that file. + */ + + /* Regular file: link1a */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link1a"); + archive_entry_set_mode(ae, AE_IFREG | 0755); + archive_entry_set_size(ae, sizeof(data)); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(sizeof(data), + archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + archive_entry_free(ae); + + /* Symbolic Link: link1b -> link1a */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link1b"); + archive_entry_set_mode(ae, AE_IFLNK | 0642); + archive_entry_set_size(ae, 0); + archive_entry_copy_symlink(ae, "link1a"); + assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); + if (r >= ARCHIVE_WARN) + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + archive_entry_free(ae); + + /* + * We should be able to do this in the other order as well, + * of course. + */ + + /* Symbolic link: link2b -> link2a */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link2b"); + archive_entry_set_mode(ae, AE_IFLNK | 0642); + archive_entry_unset_size(ae); + archive_entry_copy_symlink(ae, "link2a"); + assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); + if (r >= ARCHIVE_WARN) { + assertEqualInt(ARCHIVE_WARN, + archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + } + archive_entry_free(ae); + + /* File: link2a */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "link2a"); + archive_entry_set_mode(ae, AE_IFREG | 0755); + archive_entry_set_size(ae, sizeof(data)); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(sizeof(data), + archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); + archive_entry_free(ae); + + assertEqualInt(ARCHIVE_OK, archive_write_finish(ad)); + + /* Test the entries on disk. */ + + /* Test #1 */ + assertIsReg("link1a", -1); + assertFileSize("link1a", sizeof(data)); + assertFileNLinks("link1a", 1); + assertIsSymlink("link1b", "link1a"); + + /* Test #2: Should produce identical results to test #1 */ + assertIsReg("link2a", -1); + assertFileSize("link2a", sizeof(data)); + assertFileNLinks("link2a", 1); + assertIsSymlink("link2b", "link2a"); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_disk_times.c b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_times.c new file mode 100644 index 000000000..9ecbff69b --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_disk_times.c @@ -0,0 +1,167 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_disk_times.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* + * Exercise time restores in archive_write_disk(), including + * correct handling of omitted time values. + * On FreeBSD, we also test birthtime and high-res time restores. + */ + +DEFINE_TEST(test_write_disk_times) +{ + struct archive *a; + struct archive_entry *ae; + + /* Create an archive_write_disk object. */ + assert((a = archive_write_disk_new()) != NULL); + assertEqualInt(ARCHIVE_OK, + archive_write_disk_set_options(a, ARCHIVE_EXTRACT_TIME)); + + /* + * Easy case: mtime and atime both specified. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file1"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_entry_set_atime(ae, 123456, 0); + archive_entry_set_mtime(ae, 234567, 0); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); + archive_entry_free(ae); + /* Verify */ + assertFileAtime("file1", 123456, 0); + assertFileMtime("file1", 234567, 0); + + /* + * mtime specified, but not atime + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_entry_set_mtime(ae, 234567, 0); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); + archive_entry_free(ae); + assertFileMtime("file2", 234567, 0); + assertFileAtimeRecent("file2"); + + /* + * atime specified, but not mtime + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file3"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_entry_set_atime(ae, 345678, 0); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); + archive_entry_free(ae); + /* Verify: Current mtime and atime as specified. */ + assertFileAtime("file3", 345678, 0); + assertFileMtimeRecent("file3"); + + /* + * Neither atime nor mtime specified. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file4"); + archive_entry_set_mode(ae, S_IFREG | 0777); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); + archive_entry_free(ae); + /* Verify: Current mtime and atime. */ + assertFileAtimeRecent("file4"); + assertFileMtimeRecent("file4"); + +#if defined(__FreeBSD__) + /* + * High-res mtime and atime on FreeBSD. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file10"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_entry_set_atime(ae, 1234567, 23456); + archive_entry_set_mtime(ae, 2345678, 4567); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); + archive_entry_free(ae); + /* Verify */ + assertFileMtime("file10", 2345678, 4567); + assertFileAtime("file10", 1234567, 23456); + + /* + * Birthtime, mtime and atime on FreeBSD + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file11"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_entry_set_atime(ae, 1234567, 23456); + archive_entry_set_birthtime(ae, 3456789, 12345); + /* mtime must be later than birthtime! */ + archive_entry_set_mtime(ae, 12345678, 4567); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); + archive_entry_free(ae); + /* Verify */ + assertFileAtime("file11", 1234567, 23456); + assertFileBirthtime("file11", 3456789, 12345); + assertFileMtime("file11", 12345678, 4567); + + /* + * Birthtime only on FreeBSD. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file12"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_entry_set_birthtime(ae, 3456789, 12345); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); + archive_entry_free(ae); + /* Verify */ + assertFileAtimeRecent("file12"); + assertFileBirthtime("file12", 3456789, 12345); + assertFileMtimeRecent("file12"); + + /* + * mtime only on FreeBSD. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "file13"); + archive_entry_set_mode(ae, S_IFREG | 0777); + archive_entry_set_mtime(ae, 4567890, 23456); + assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); + archive_entry_free(ae); + /* Verify */ + assertFileAtimeRecent("file13"); + assertFileBirthtime("file13", 4567890, 23456); + assertFileMtime("file13", 4567890, 23456); +#else + skipping("Platform-specific time restore tests"); +#endif + + archive_write_finish(a); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_ar.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_ar.c new file mode 100644 index 000000000..5822b3f38 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_ar.c @@ -0,0 +1,209 @@ +/*- + * Copyright (c) 2007 Kai Wang + * Copyright (c) 2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_ar.c 189308 2009-03-03 17:02:51Z kientzle $"); + +char buff[4096]; +char buff2[64]; +static char strtab[] = "abcdefghijklmn.o/\nggghhhjjjrrrttt.o/\niiijjjdddsssppp.o/\n"; + +DEFINE_TEST(test_write_format_ar) +{ +#if ARCHIVE_VERSION_NUMBER < 1009000 + skipping("ar write support"); +#else + struct archive_entry *ae; + struct archive* a; + size_t used; + + /* + * First we try to create a SVR4/GNU format archive. + */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ar_svr4(a)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* write the filename table */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "//"); + archive_entry_set_size(ae, strlen(strtab)); + assertA(0 == archive_write_header(a, ae)); + assertA(strlen(strtab) == (size_t)archive_write_data(a, strtab, strlen(strtab))); + archive_entry_free(ae); + + /* write entries */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 0); + assert(1 == archive_entry_mtime(ae)); + archive_entry_set_mode(ae, S_IFREG | 0755); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + archive_entry_copy_pathname(ae, "abcdefghijklmn.o"); + archive_entry_set_size(ae, 8); + assertA(0 == archive_write_header(a, ae)); + assertA(8 == archive_write_data(a, "87654321", 15)); + archive_entry_free(ae); + + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "ggghhhjjjrrrttt.o"); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, 7); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualIntA(a, 7, archive_write_data(a, "7777777", 7)); + archive_entry_free(ae); + + /* test full pathname */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "/usr/home/xx/iiijjjdddsssppp.o"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualIntA(a, 8, archive_write_data(a, "88877766", 8)); + archive_entry_free(ae); + + /* trailing "/" should be rejected */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "/usr/home/xx/iiijjj/"); + archive_entry_set_size(ae, 8); + assertA(0 != archive_write_header(a, ae)); + archive_entry_free(ae); + + /* Non regular file should be rejected */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "gfgh.o"); + archive_entry_set_mode(ae, S_IFDIR | 0755); + archive_entry_set_size(ae, 6); + assertA(0 != archive_write_header(a, ae)); + archive_entry_free(ae); + + archive_write_close(a); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertEqualInt(0, archive_write_finish(a)); +#endif + + /* + * Now, read the data back. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(0, archive_entry_mtime(ae)); + assertEqualString("//", archive_entry_pathname(ae)); + assertEqualInt(0, archive_entry_size(ae)); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualString("abcdefghijklmn.o", archive_entry_pathname(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); + assertEqualMem(buff2, "87654321", 8); + + assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString("ggghhhjjjrrrttt.o", archive_entry_pathname(ae)); + assertEqualInt(7, archive_entry_size(ae)); + assertEqualIntA(a, 7, archive_read_data(a, buff2, 11)); + assertEqualMem(buff2, "7777777", 7); + + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + assertEqualString("iiijjjdddsssppp.o", archive_entry_pathname(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff2, 17)); + assertEqualMem(buff2, "88877766", 8); + + assertEqualIntA(a, 0, archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(0, archive_read_finish(a)); +#endif + + /* + * Then, we try to create a BSD format archive. + */ + memset(buff, 0, sizeof(buff)); + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ar_bsd(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* write a entry need long name extension */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "ttttyyyyuuuuiiii.o"); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, 5); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualInt(5, archive_entry_size(ae)); + assertEqualIntA(a, 5, archive_write_data(a, "12345", 7)); + archive_entry_free(ae); + + /* write a entry with a short name */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "ttyy.o"); + archive_entry_set_filetype(ae, AE_IFREG); + archive_entry_set_size(ae, 6); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + assertEqualIntA(a, 6, archive_write_data(a, "555555", 7)); + archive_entry_free(ae); + archive_write_close(a); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertEqualInt(0, archive_write_finish(a)); +#endif + + /* Now, Read the data back */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); + + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + assertEqualString("ttttyyyyuuuuiiii.o", archive_entry_pathname(ae)); + assertEqualInt(5, archive_entry_size(ae)); + assertEqualIntA(a, 5, archive_read_data(a, buff2, 10)); + assertEqualMem(buff2, "12345", 5); + + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + assertEqualString("ttyy.o", archive_entry_pathname(ae)); + assertEqualInt(6, archive_entry_size(ae)); + assertEqualIntA(a, 6, archive_read_data(a, buff2, 10)); + assertEqualMem(buff2, "555555", 6); + + /* Test EOF */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, 0, archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(0, archive_read_finish(a)); +#endif +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio.c new file mode 100644 index 000000000..7bf2a41a5 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio.c @@ -0,0 +1,194 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_cpio.c 185672 2008-12-06 06:02:26Z kientzle $"); + +/* The version stamp macro was introduced after cpio write support. */ +#if ARCHIVE_VERSION_NUMBER >= 1009000 +static void +test_format(int (*set_format)(struct archive *)) +{ + char filedata[64]; + struct archive_entry *ae; + struct archive *a; + char *p; + size_t used; + size_t buffsize = 1000000; + char *buff; + int damaged = 0; + + buff = malloc(buffsize); + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == (*set_format)(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 10); + assert(1 == archive_entry_mtime(ae)); + assert(10 == archive_entry_mtime_nsec(ae)); + p = strdup("file"); + archive_entry_copy_pathname(ae, p); + strcpy(p, "XXXX"); + free(p); + assertEqualString("file", archive_entry_pathname(ae)); + archive_entry_set_mode(ae, S_IFREG | 0755); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + archive_entry_set_size(ae, 8); + + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assertA(8 == archive_write_data(a, "12345678", 9)); + + /* + * Write another file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 10); + assert(1 == archive_entry_mtime(ae)); + assert(10 == archive_entry_mtime_nsec(ae)); + p = strdup("file2"); + archive_entry_copy_pathname(ae, p); + strcpy(p, "XXXX"); + free(p); + assertEqualString("file2", archive_entry_pathname(ae)); + archive_entry_set_mode(ae, S_IFREG | 0755); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + archive_entry_set_size(ae, 4); + + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assertA(4 == archive_write_data(a, "1234", 5)); + + /* + * Write a directory to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 11, 110); + archive_entry_copy_pathname(ae, "dir"); + archive_entry_set_mode(ae, S_IFDIR | 0755); + archive_entry_set_size(ae, 512); + + assertA(0 == archive_write_header(a, ae)); + assertEqualInt(0, archive_entry_size(ae)); + archive_entry_free(ae); + assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9)); + + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + + /* + * Damage the second entry to test the search-ahead recovery. + * TODO: Move the damage-recovery checking to a separate test; + * it doesn't really belong in this write test. + */ + { + int i; + for (i = 80; i < 150; i++) { + if (memcmp(buff + i, "07070", 5) == 0) { + damaged = 1; + buff[i] = 'X'; + break; + } + } + } + failure("Unable to locate the second header for damage-recovery test."); + assert(damaged == 1); + + /* + * Now, read the data back. + */ + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used)); + + if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) { + archive_read_finish(a); + return; + } + + assertEqualInt(1, archive_entry_mtime(ae)); + /* Not the same as above: cpio doesn't store hi-res times. */ + assert(0 == archive_entry_mtime_nsec(ae)); + assert(0 == archive_entry_atime(ae)); + assert(0 == archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertA(8 == archive_read_data(a, filedata, 10)); + assert(0 == memcmp(filedata, "12345678", 8)); + + /* + * The second file can't be read because we damaged its header. + */ + + /* + * Read the dir entry back. + * ARCHIVE_WARN here because the damaged entry was skipped. + */ + assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); + assertEqualInt(11, archive_entry_mtime(ae)); + assert(0 == archive_entry_mtime_nsec(ae)); + assert(0 == archive_entry_atime(ae)); + assert(0 == archive_entry_ctime(ae)); + assertEqualString("dir", archive_entry_pathname(ae)); + assertEqualInt((S_IFDIR | 0755), archive_entry_mode(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualIntA(a, 0, archive_read_data(a, filedata, 10)); + + /* Verify the end of the archive. */ + assertEqualIntA(a, 1, archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + + free(buff); +} +#endif + +DEFINE_TEST(test_write_format_cpio) +{ +#if ARCHIVE_VERSION_NUMBER >= 1009000 + test_format(archive_write_set_format_cpio); + test_format(archive_write_set_format_cpio_newc); +#else + skipping("cpio write support"); +#endif +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_empty.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_empty.c new file mode 100644 index 000000000..131ac2461 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_empty.c @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_cpio_empty.c 201247 2009-12-30 05:59:21Z kientzle $"); + +/* + * Check that an "empty" cpio archive is correctly created. + */ + +/* Here's what an empty cpio archive should look like. */ +static char ref[] = +"070707" /* Magic number */ +"000000" /* Dev = 0 */ +"000000" /* ino = 0 */ +"000000" /* mode = 0 */ +"000000" /* uid = 0 */ +"000000" /* gid = 0 */ +"000001" /* nlink = 1 */ +"000000" /* rdev = 0 */ +"00000000000" /* mtime = 0 */ +"000013" /* Namesize = 11 */ +"00000000000" /* filesize = 0 */ +"TRAILER!!!\0"; /* Name */ + +DEFINE_TEST(test_write_format_cpio_empty) +{ + struct archive *a; + char buff[2048]; + size_t used; + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_cpio(a)); + assertA(0 == archive_write_set_compression_none(a)); + /* 1-byte block size ensures we see only the required bytes. */ + /* We're not testing the padding here. */ + assertA(0 == archive_write_set_bytes_per_block(a, 1)); + assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + + failure("Empty cpio archive should be exactly 87 bytes, was %d.", used); + assert(used == 87); + failure("Empty cpio archive is incorrectly formatted."); + assertEqualMem(buff, ref, 87); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_newc.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_newc.c new file mode 100644 index 000000000..1c3c330b0 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_newc.c @@ -0,0 +1,214 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_cpio_newc.c 201247 2009-12-30 05:59:21Z kientzle $"); + + +static int +is_hex(const char *p, size_t l) +{ + while (l > 0) { + if (*p >= 0 && *p <= '9') { + /* Ascii digit */ + } else if (*p >= 'a' && *p <= 'f') { + /* lowercase letter a-f */ + } else { + /* Not hex. */ + return (0); + } + --l; + ++p; + } + return (1); +} + +/* + * Detailed verification that cpio 'newc' archives are written with + * the correct format. + */ +DEFINE_TEST(test_write_format_cpio_newc) +{ + struct archive *a; + struct archive_entry *entry; + char *buff, *e, *file; + size_t buffsize = 100000; + size_t used; + + buff = malloc(buffsize); + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, 0, archive_write_set_format_cpio_newc(a)); + assertEqualIntA(a, 0, archive_write_set_compression_none(a)); + assertEqualIntA(a, 0, archive_write_open_memory(a, buff, buffsize, &used)); + + /* + * Add various files to it. + * TODO: Extend this to cover more filetypes. + */ + + /* Regular file */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 1, 10); + archive_entry_set_pathname(entry, "file"); + archive_entry_set_mode(entry, S_IFREG | 0664); + archive_entry_set_size(entry, 10); + archive_entry_set_uid(entry, 80); + archive_entry_set_gid(entry, 90); + archive_entry_set_dev(entry, 12); + archive_entry_set_ino(entry, 89); + archive_entry_set_nlink(entry, 1); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); + + /* Directory */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 2, 20); + archive_entry_set_pathname(entry, "dir"); + archive_entry_set_mode(entry, S_IFDIR | 0775); + archive_entry_set_size(entry, 10); + archive_entry_set_nlink(entry, 2); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); + + /* Symlink */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 3, 30); + archive_entry_set_pathname(entry, "lnk"); + archive_entry_set_mode(entry, 0664); + archive_entry_set_filetype(entry, AE_IFLNK); + archive_entry_set_size(entry, 0); + archive_entry_set_uid(entry, 83); + archive_entry_set_gid(entry, 93); + archive_entry_set_dev(entry, 13); + archive_entry_set_ino(entry, 88); + archive_entry_set_nlink(entry, 1); + archive_entry_set_symlink(entry,"a"); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + + +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assert(0 == archive_write_finish(a)); +#endif + + /* + * Verify the archive format. + */ + e = buff; + + /* First entry is "file" */ + file = e; + assert(is_hex(e, 110)); /* Entire header is hex digits. */ + assertEqualMem(e + 0, "070701", 6); /* Magic */ + assert(memcmp(e + 6, "00000000", 8) != 0); /* ino != 0 */ + assertEqualMem(e + 14, "000081b4", 8); /* Mode */ + assertEqualMem(e + 22, "00000050", 8); /* uid */ + assertEqualMem(e + 30, "0000005a", 8); /* gid */ + assertEqualMem(e + 38, "00000001", 8); /* nlink */ + assertEqualMem(e + 46, "00000001", 8); /* mtime */ + assertEqualMem(e + 54, "0000000a", 8); /* File size */ + assertEqualMem(e + 62, "00000000", 8); /* devmajor */ + assertEqualMem(e + 70, "0000000c", 8); /* devminor */ + assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ + assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ + assertEqualMem(e + 94, "00000005", 8); /* Name size */ + assertEqualMem(e + 102, "00000000", 8); /* CRC */ + assertEqualMem(e + 110, "file\0\0", 6); /* Name contents */ + assertEqualMem(e + 116, "1234567890", 10); /* File body */ + assertEqualMem(e + 126, "\0\0", 2); /* Pad to multiple of 4 */ + e += 128; /* Must be multiple of four here! */ + + /* Second entry is "dir" */ + assert(is_hex(e, 110)); + assertEqualMem(e + 0, "070701", 6); /* Magic */ + assertEqualMem(e + 6, "00000000", 8); /* ino */ + assertEqualMem(e + 14, "000041fd", 8); /* Mode */ + assertEqualMem(e + 22, "00000000", 8); /* uid */ + assertEqualMem(e + 30, "00000000", 8); /* gid */ + assertEqualMem(e + 38, "00000002", 8); /* nlink */ + assertEqualMem(e + 46, "00000002", 8); /* mtime */ + assertEqualMem(e + 54, "00000000", 8); /* File size */ + assertEqualMem(e + 62, "00000000", 8); /* devmajor */ + assertEqualMem(e + 70, "00000000", 8); /* devminor */ + assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ + assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ + assertEqualMem(e + 94, "00000004", 8); /* Name size */ + assertEqualMem(e + 102, "00000000", 8); /* CRC */ + assertEqualMem(e + 110, "dir\0", 4); /* name */ + assertEqualMem(e + 114, "\0\0", 2); /* Pad to multiple of 4 */ + e += 116; /* Must be multiple of four here! */ + + /* Third entry is "lnk" */ + assert(is_hex(e, 110)); /* Entire header is hex digits. */ + assertEqualMem(e + 0, "070701", 6); /* Magic */ + assert(memcmp(e + 6, file + 6, 8) != 0); /* ino != file ino */ + assert(memcmp(e + 6, "00000000", 8) != 0); /* ino != 0 */ + assertEqualMem(e + 14, "0000a1b4", 8); /* Mode */ + assertEqualMem(e + 22, "00000053", 8); /* uid */ + assertEqualMem(e + 30, "0000005d", 8); /* gid */ + assertEqualMem(e + 38, "00000001", 8); /* nlink */ + assertEqualMem(e + 46, "00000003", 8); /* mtime */ + assertEqualMem(e + 54, "00000001", 8); /* File size */ + assertEqualMem(e + 62, "00000000", 8); /* devmajor */ + assertEqualMem(e + 70, "0000000d", 8); /* devminor */ + assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ + assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ + assertEqualMem(e + 94, "00000004", 8); /* Name size */ + assertEqualMem(e + 102, "00000000", 8); /* CRC */ + assertEqualMem(e + 110, "lnk\0\0\0", 6); /* Name contents */ + assertEqualMem(e + 116, "a\0\0\0", 4); /* File body + pad */ + e += 120; /* Must be multiple of four here! */ + + /* TODO: Verify other types of entries. */ + + /* Last entry is end-of-archive marker. */ + assert(is_hex(e, 76)); + assertEqualMem(e + 0, "070701", 6); /* Magic */ + assertEqualMem(e + 6, "00000000", 8); /* ino */ + assertEqualMem(e + 14, "00000000", 8); /* Mode */ + assertEqualMem(e + 22, "00000000", 8); /* uid */ + assertEqualMem(e + 30, "00000000", 8); /* gid */ + assertEqualMem(e + 38, "00000001", 8); /* nlink */ + assertEqualMem(e + 46, "00000000", 8); /* mtime */ + assertEqualMem(e + 54, "00000000", 8); /* File size */ + assertEqualMem(e + 62, "00000000", 8); /* devmajor */ + assertEqualMem(e + 70, "00000000", 8); /* devminor */ + assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ + assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ + assertEqualMem(e + 94, "0000000b", 8); /* Name size */ + assertEqualMem(e + 102, "00000000", 8); /* CRC */ + assertEqualMem(e + 110, "TRAILER!!!\0", 11); /* Name */ + assertEqualMem(e + 121, "\0\0\0", 3); /* Pad to multiple of 4 bytes */ + e += 124; /* Must be multiple of four here! */ + + assertEqualInt((int)used, e - buff); + + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_odc.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_odc.c new file mode 100644 index 000000000..e2136f87c --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_cpio_odc.c @@ -0,0 +1,241 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_cpio_odc.c 201247 2009-12-30 05:59:21Z kientzle $"); + + +static int +is_octal(const char *p, size_t l) +{ + while (l > 0) { + if (*p < '0' || *p > '7') + return (0); + --l; + ++p; + } + return (1); +} + +/* + * Detailed verification that cpio 'odc' archives are written with + * the correct format. + */ +DEFINE_TEST(test_write_format_cpio_odc) +{ + struct archive *a; + struct archive_entry *entry; + char *buff, *e, *file; + size_t buffsize = 100000; + size_t used; + + buff = malloc(buffsize); + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, 0, archive_write_set_format_cpio(a)); + assertEqualIntA(a, 0, archive_write_set_compression_none(a)); + assertEqualIntA(a, 0, archive_write_open_memory(a, buff, buffsize, &used)); + + /* + * Add various files to it. + * TODO: Extend this to cover more filetypes. + */ + + /* "file" with 10 bytes of content */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 1, 10); + archive_entry_set_pathname(entry, "file"); + archive_entry_set_mode(entry, S_IFREG | 0664); + archive_entry_set_size(entry, 10); + archive_entry_set_uid(entry, 80); + archive_entry_set_gid(entry, 90); + archive_entry_set_dev(entry, 12); + archive_entry_set_ino(entry, 89); + archive_entry_set_nlink(entry, 2); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); + + /* Hardlink to "file" with 10 bytes of content */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 1, 10); + archive_entry_set_pathname(entry, "linkfile"); + archive_entry_set_mode(entry, S_IFREG | 0664); + archive_entry_set_size(entry, 10); + archive_entry_set_uid(entry, 80); + archive_entry_set_gid(entry, 90); + archive_entry_set_dev(entry, 12); + archive_entry_set_ino(entry, 89); + archive_entry_set_nlink(entry, 2); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); + + /* "dir" */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 2, 20); + archive_entry_set_pathname(entry, "dir"); + archive_entry_set_mode(entry, S_IFDIR | 0775); + archive_entry_set_size(entry, 10); + archive_entry_set_nlink(entry, 2); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + /* Write of data to dir should fail == zero bytes get written. */ + assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); + + /* "symlink" pointing to "file" */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 3, 30); + archive_entry_set_pathname(entry, "symlink"); + archive_entry_set_mode(entry, 0664); + archive_entry_set_filetype(entry, AE_IFLNK); + archive_entry_set_symlink(entry,"file"); + archive_entry_set_size(entry, 0); + archive_entry_set_uid(entry, 88); + archive_entry_set_gid(entry, 98); + archive_entry_set_dev(entry, 12); + archive_entry_set_ino(entry, 90); + archive_entry_set_nlink(entry, 1); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + /* Write of data to symlink should fail == zero bytes get written. */ + assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); + +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assert(0 == archive_write_finish(a)); +#endif + + /* + * Verify the archive format. + * + * Notes on the ino validation: cpio does not actually require + * that the ino values written to the archive match those read + * from disk. It really requires that: + * * matching non-zero ino values be written as matching + * non-zero values + * * non-matching non-zero ino values be written as non-matching + * non-zero values + * Libarchive further ensures that zero ino values get written + * as zeroes. This allows the cpio writer to generate + * synthetic ino values for the archive that may be different + * than those on disk in order to avoid problems due to truncation. + * This is especially needed for odc (POSIX format) that + * only supports 18-bit ino values. + */ + e = buff; + + /* "file" */ + file = e; /* Remember where this starts... */ + assert(is_octal(e, 76)); /* Entire header is octal digits. */ + assertEqualMem(e + 0, "070707", 6); /* Magic */ + assertEqualMem(e + 6, "000014", 6); /* dev */ + assert(memcmp(e + 12, "000000", 6) != 0); /* ino must be != 0 */ + assertEqualMem(e + 18, "100664", 6); /* Mode */ + assertEqualMem(e + 24, "000120", 6); /* uid */ + assertEqualMem(e + 30, "000132", 6); /* gid */ + assertEqualMem(e + 36, "000002", 6); /* nlink */ + assertEqualMem(e + 42, "000000", 6); /* rdev */ + assertEqualMem(e + 48, "00000000001", 11); /* mtime */ + assertEqualMem(e + 59, "000005", 6); /* Name size */ + assertEqualMem(e + 65, "00000000012", 11); /* File size */ + assertEqualMem(e + 76, "file\0", 5); /* Name contents */ + assertEqualMem(e + 81, "1234567890", 10); /* File contents */ + e += 91; + + /* hardlink to "file" */ + assert(is_octal(e, 76)); /* Entire header is octal digits. */ + assertEqualMem(e + 0, "070707", 6); /* Magic */ + assertEqualMem(e + 6, "000014", 6); /* dev */ + assertEqualMem(e + 12, file + 12, 6); /* ino must match above */ + assertEqualMem(e + 18, "100664", 6); /* Mode */ + assertEqualMem(e + 24, "000120", 6); /* uid */ + assertEqualMem(e + 30, "000132", 6); /* gid */ + assertEqualMem(e + 36, "000002", 6); /* nlink */ + assertEqualMem(e + 42, "000000", 6); /* rdev */ + assertEqualMem(e + 48, "00000000001", 11); /* mtime */ + assertEqualMem(e + 59, "000011", 6); /* Name size */ + assertEqualMem(e + 65, "00000000012", 11); /* File size */ + assertEqualMem(e + 76, "linkfile\0", 9); /* Name contents */ + assertEqualMem(e + 85, "1234567890", 10); /* File contents */ + e += 95; + + /* "dir" */ + assert(is_octal(e, 76)); + assertEqualMem(e + 0, "070707", 6); /* Magic */ + assertEqualMem(e + 6, "000000", 6); /* dev */ + assertEqualMem(e + 12, "000000", 6); /* ino */ + assertEqualMem(e + 18, "040775", 6); /* Mode */ + assertEqualMem(e + 24, "000000", 6); /* uid */ + assertEqualMem(e + 30, "000000", 6); /* gid */ + assertEqualMem(e + 36, "000002", 6); /* Nlink */ + assertEqualMem(e + 42, "000000", 6); /* rdev */ + assertEqualMem(e + 48, "00000000002", 11); /* mtime */ + assertEqualMem(e + 59, "000004", 6); /* Name size */ + assertEqualMem(e + 65, "00000000000", 11); /* File size */ + assertEqualMem(e + 76, "dir\0", 4); /* name */ + e += 80; + + /* "symlink" pointing to "file" */ + assert(is_octal(e, 76)); /* Entire header is octal digits. */ + assertEqualMem(e + 0, "070707", 6); /* Magic */ + assertEqualMem(e + 6, "000014", 6); /* dev */ + assert(memcmp(e + 12, file + 12, 6) != 0); /* ino must != file ino */ + assert(memcmp(e + 12, "000000", 6) != 0); /* ino must != 0 */ + assertEqualMem(e + 18, "120664", 6); /* Mode */ + assertEqualMem(e + 24, "000130", 6); /* uid */ + assertEqualMem(e + 30, "000142", 6); /* gid */ + assertEqualMem(e + 36, "000001", 6); /* nlink */ + assertEqualMem(e + 42, "000000", 6); /* rdev */ + assertEqualMem(e + 48, "00000000003", 11); /* mtime */ + assertEqualMem(e + 59, "000010", 6); /* Name size */ + assertEqualMem(e + 65, "00000000004", 11); /* File size */ + assertEqualMem(e + 76, "symlink\0", 8); /* Name contents */ + assertEqualMem(e + 84, "file", 4); /* File contents == link target */ + e += 88; + + /* TODO: Verify other types of entries. */ + + /* Last entry is end-of-archive marker. */ + assert(is_octal(e, 76)); + assertEqualMem(e + 0, "070707", 6); /* Magic */ + assertEqualMem(e + 6, "000000", 6); /* dev */ + assertEqualMem(e + 12, "000000", 6); /* ino */ + assertEqualMem(e + 18, "000000", 6); /* Mode */ + assertEqualMem(e + 24, "000000", 6); /* uid */ + assertEqualMem(e + 30, "000000", 6); /* gid */ + assertEqualMem(e + 36, "000001", 6); /* Nlink */ + assertEqualMem(e + 42, "000000", 6); /* rdev */ + assertEqualMem(e + 48, "00000000000", 11); /* mtime */ + assertEqualMem(e + 59, "000013", 6); /* Name size */ + assertEqualMem(e + 65, "00000000000", 11); /* File size */ + assertEqualMem(e + 76, "TRAILER!!!\0", 11); /* Name */ + e += 87; + + assertEqualInt((int)used, e - buff); + + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_mtree.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_mtree.c new file mode 100644 index 000000000..e0b78f557 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_mtree.c @@ -0,0 +1,155 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_mtree.c 191183 2009-04-17 01:06:31Z kientzle $"); + +static char buff[4096]; +static struct { + const char *path; + mode_t mode; + time_t mtime; + uid_t uid; + gid_t gid; +} entries[] = { + { "./Makefile", S_IFREG | 0644, 1233041050, 1001, 1001 }, + { "./NEWS", S_IFREG | 0644, 1231975636, 1001, 1001 }, + { "./PROJECTS", S_IFREG | 0644, 1231975636, 1001, 1001 }, + { "./README", S_IFREG | 0644, 1231975636, 1001, 1001 }, + { "./COPYING", S_IFREG | 0644, 1231975636, 1001, 1001 }, + { "./subdir", S_IFDIR | 0755, 1233504586, 1001, 1001 }, + { "./subdir/README", S_IFREG | 0664, 1231975636, 1002, 1001 }, + { "./subdir/config", S_IFREG | 0664, 1232266273, 1003, 1003 }, + { "./subdir2", S_IFDIR | 0755, 1233504586, 1001, 1001 }, + { "./subdir3", S_IFDIR | 0755, 1233504586, 1001, 1001 }, + { "./subdir3/mtree", S_IFREG | 0664, 1232266273, 1003, 1003 }, + { NULL, 0, 0, 0, 0 } +}; + +static void +test_write_format_mtree_sub(int use_set, int dironly) +{ + struct archive_entry *ae; + struct archive* a; + size_t used; + int i; + + /* Create a mtree format archive. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_mtree(a)); + if (use_set) + assertA(0 == archive_write_set_options(a, "use-set")); + if (dironly) + assertA(0 == archive_write_set_options(a, "dironly")); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff)-1, &used)); + + /* Write entries */ + for (i = 0; entries[i].path != NULL; i++) { + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, entries[i].mtime, 0); + assert(entries[i].mtime == archive_entry_mtime(ae)); + archive_entry_set_mode(ae, entries[i].mode); + assert(entries[i].mode == archive_entry_mode(ae)); + archive_entry_set_uid(ae, entries[i].uid); + assert(entries[i].uid == archive_entry_uid(ae)); + archive_entry_set_gid(ae, entries[i].gid); + assert(entries[i].gid == archive_entry_gid(ae)); + archive_entry_copy_pathname(ae, entries[i].path); + if ((entries[i].mode & AE_IFMT) != S_IFDIR) + archive_entry_set_size(ae, 8); + assertA(0 == archive_write_header(a, ae)); + if ((entries[i].mode & AE_IFMT) != S_IFDIR) + assertA(8 == archive_write_data(a, "Hello012", 15)); + archive_entry_free(ae); + } + archive_write_close(a); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertEqualInt(0, archive_write_finish(a)); +#endif + if (use_set) { + const char *p; + + buff[used] = '\0'; + assert(NULL != (p = strstr(buff, "\n/set "))); + if (p != NULL) { + char *r; + const char *o; + p++; + r = strchr(p, '\n'); + if (r != NULL) + *r = '\0'; + if (dironly) + o = "/set type=dir uid=1001 gid=1001 mode=755"; + else + o = "/set type=file uid=1001 gid=1001 mode=644"; + assertEqualString(o, p); + if (r != NULL) + *r = '\n'; + } + } + + /* + * Read the data and check it. + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); + + /* Read entries */ + for (i = 0; entries[i].path != NULL; i++) { + if (dironly && (entries[i].mode & AE_IFMT) != S_IFDIR) + continue; + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(entries[i].mtime, archive_entry_mtime(ae)); + assertEqualInt(entries[i].mode, archive_entry_mode(ae)); + assertEqualInt(entries[i].uid, archive_entry_uid(ae)); + assertEqualInt(entries[i].gid, archive_entry_gid(ae)); + assertEqualString(entries[i].path, archive_entry_pathname(ae)); + if ((entries[i].mode & AE_IFMT) != S_IFDIR) + assertEqualInt(8, archive_entry_size(ae)); + } + assertEqualIntA(a, 0, archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assertEqualInt(0, archive_read_finish(a)); +#endif +} + +DEFINE_TEST(test_write_format_mtree) +{ + /* Default setting */ + test_write_format_mtree_sub(0, 0); + /* Directory only */ + test_write_format_mtree_sub(0, 1); + /* Use /set keyword */ + test_write_format_mtree_sub(1, 0); + /* Use /set keyword with directory only */ + test_write_format_mtree_sub(1, 1); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_pax.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_pax.c new file mode 100644 index 000000000..06cfca6fe --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_pax.c @@ -0,0 +1,146 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +char buff2[64]; + +DEFINE_TEST(test_write_format_pax) +{ + size_t buffsize = 1000000; + char *buff; + struct archive_entry *ae; + struct archive *a; + size_t used; + + buff = malloc(buffsize); /* million bytes of work area */ + assert(buff != NULL); + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_pax(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); + + /* + * "file" has a bunch of attributes and 8 bytes of data. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_atime(ae, 2, 20); + archive_entry_set_birthtime(ae, 3, 30); + archive_entry_set_ctime(ae, 4, 40); + archive_entry_set_mtime(ae, 5, 50); + archive_entry_copy_pathname(ae, "file"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * "file2" is similar but has birthtime later than mtime. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_atime(ae, 2, 20); + archive_entry_set_birthtime(ae, 8, 80); + archive_entry_set_ctime(ae, 4, 40); + archive_entry_set_mtime(ae, 5, 50); + archive_entry_copy_pathname(ae, "file2"); + archive_entry_set_mode(ae, S_IFREG | 0755); + archive_entry_set_size(ae, 8); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); + + /* + * XXX TODO XXX Archive directory, other file types. + * Archive extended attributes, ACLs, other metadata. + * Verify they get read back correctly. + */ + + /* Close out the archive. */ + assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_finish(a)); + + /* + * + * Now, read the data back. + * + */ + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, 0, archive_read_support_format_all(a)); + assertEqualIntA(a, 0, archive_read_support_compression_all(a)); + assertEqualIntA(a, 0, archive_read_open_memory(a, buff, used)); + + /* + * Read "file" + */ + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + assertEqualInt(2, archive_entry_atime(ae)); + assertEqualInt(20, archive_entry_atime_nsec(ae)); + assertEqualInt(3, archive_entry_birthtime(ae)); + assertEqualInt(30, archive_entry_birthtime_nsec(ae)); + assertEqualInt(4, archive_entry_ctime(ae)); + assertEqualInt(40, archive_entry_ctime_nsec(ae)); + assertEqualInt(5, archive_entry_mtime(ae)); + assertEqualInt(50, archive_entry_mtime_nsec(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); + assertEqualMem(buff2, "12345678", 8); + + /* + * Read "file2" + */ + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); + assert(archive_entry_atime_is_set(ae)); + assertEqualInt(2, archive_entry_atime(ae)); + assertEqualInt(20, archive_entry_atime_nsec(ae)); + /* Birthtime > mtime above, so it doesn't get stored at all. */ + assert(!archive_entry_birthtime_is_set(ae)); + assertEqualInt(0, archive_entry_birthtime(ae)); + assertEqualInt(0, archive_entry_birthtime_nsec(ae)); + assert(archive_entry_ctime_is_set(ae)); + assertEqualInt(4, archive_entry_ctime(ae)); + assertEqualInt(40, archive_entry_ctime_nsec(ae)); + assert(archive_entry_mtime_is_set(ae)); + assertEqualInt(5, archive_entry_mtime(ae)); + assertEqualInt(50, archive_entry_mtime_nsec(ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); + assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); + assertEqualMem(buff2, "12345678", 8); + + /* + * Verify the end of the archive. + */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_finish(a)); + + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_shar_empty.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_shar_empty.c new file mode 100644 index 000000000..14ee3889a --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_shar_empty.c @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_shar_empty.c,v 1.3 2008/09/01 05:38:33 kientzle Exp $"); + +/* + * Check that an "empty" shar archive is correctly created as an empty file. + */ + +DEFINE_TEST(test_write_format_shar_empty) +{ + struct archive *a; + char buff[2048]; + size_t used; + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_shar(a)); + assertA(0 == archive_write_set_compression_none(a)); + /* 1-byte block size ensures we see only the required bytes. */ + /* We're not testing the padding here. */ + assertA(0 == archive_write_set_bytes_per_block(a, 1)); + assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + + failure("Empty shar archive should be exactly 0 bytes, was %d.", used); + assert(used == 0); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_tar.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_tar.c new file mode 100644 index 000000000..372fef1f0 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_tar.c @@ -0,0 +1,114 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_tar.c 189308 2009-03-03 17:02:51Z kientzle $"); + +char buff[1000000]; +char buff2[64]; + +DEFINE_TEST(test_write_format_tar) +{ + struct archive_entry *ae; + struct archive *a; + char *p; + size_t used; + size_t blocksize; + + /* Repeat the following for a variety of odd blocksizes. */ + for (blocksize = 1; blocksize < 100000; blocksize += blocksize + 3) { + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_set_bytes_per_block(a, (int)blocksize)); + assertA(0 == archive_write_set_bytes_in_last_block(a, (int)blocksize)); + assertA(blocksize == (size_t)archive_write_get_bytes_in_last_block(a)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + assertA(blocksize == (size_t)archive_write_get_bytes_in_last_block(a)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 10); + assert(1 == archive_entry_mtime(ae)); +#if !defined(__INTERIX) + assert(10 == archive_entry_mtime_nsec(ae)); +#endif + p = strdup("file"); + archive_entry_copy_pathname(ae, p); + strcpy(p, "XXXX"); + free(p); + assertEqualString("file", archive_entry_pathname(ae)); + archive_entry_set_mode(ae, S_IFREG | 0755); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + archive_entry_set_size(ae, 8); + + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assertA(8 == archive_write_data(a, "12345678", 9)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + /* This calculation gives "the smallest multiple of + * the block size that is at least 2048 bytes". */ + assert(((2048 - 1)/blocksize+1)*blocksize == used); + + /* + * Now, read the data back. + */ + assert((a = archive_read_new()) != NULL); + assertA(0 == archive_read_support_format_all(a)); + assertA(0 == archive_read_support_compression_all(a)); + assertA(0 == archive_read_open_memory(a, buff, used)); + + assertA(0 == archive_read_next_header(a, &ae)); + + assert(1 == archive_entry_mtime(ae)); + /* Not the same as above: ustar doesn't store hi-res times. */ + assert(0 == archive_entry_mtime_nsec(ae)); + assert(0 == archive_entry_atime(ae)); + assert(0 == archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assert(8 == archive_entry_size(ae)); + assertA(8 == archive_read_data(a, buff2, 10)); + assert(0 == memcmp(buff2, "12345678", 8)); + + /* Verify the end of the archive. */ + assert(1 == archive_read_next_header(a, &ae)); + assert(0 == archive_read_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_read_finish(a); +#else + assert(0 == archive_read_finish(a)); +#endif + } +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_tar_empty.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_tar_empty.c new file mode 100644 index 000000000..6b40f0767 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_tar_empty.c @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_tar_empty.c 189308 2009-03-03 17:02:51Z kientzle $"); + +/* + * Check that an "empty" tar archive is correctly created. + */ + +DEFINE_TEST(test_write_format_tar_empty) +{ + struct archive *a; + char buff[2048]; + size_t used; + unsigned int i; + + /* USTAR format: Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_set_bytes_per_block(a, 512)); + assertA(0 == archive_write_set_bytes_in_last_block(a, 512)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + +#if ARCHIVE_VERSION_NUMBER < 1009000 + /* Earlier versions wrote 0-length files for empty tar archives. */ + skipping("empty tar archive size"); +#else + assert(used == 1024); +#endif + for (i = 0; i < used; i++) { + failure("Empty tar archive should be all nulls."); + assert(buff[i] == 0); + } + + /* PAX format: Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_pax(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_set_bytes_per_block(a, 512)); + assertA(0 == archive_write_set_bytes_in_last_block(a, 512)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* Close out the archive. */ + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assertA(0 == archive_write_finish(a)); +#endif + +#if ARCHIVE_VERSION_NUMBER < 1009000 + /* Earlier versions wrote 0-length files for empty tar archives. */ + skipping("empty tar archive size"); +#else + assertEqualInt((int)used, 1024); +#endif + for (i = 0; i < used; i++) { + failure("Empty tar archive should be all nulls."); + assert(buff[i] == 0); + } +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_tar_ustar.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_tar_ustar.c new file mode 100644 index 000000000..29968dfb3 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_tar_ustar.c @@ -0,0 +1,347 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_tar_ustar.c 201247 2009-12-30 05:59:21Z kientzle $"); + +static int +is_null(const char *p, size_t l) +{ + while (l > 0) { + if (*p != '\0') + return (0); + --l; + ++p; + } + return (1); +} + +/* Verify the contents, then erase them to NUL bytes. */ +/* Tar requires all "unused" bytes be set to NUL; this allows us + * to easily verify that by invoking is_null() over the entire header + * after verifying each field. */ +#define myAssertEqualMem(a,b,s) assertEqualMem(a, b, s); memset(a, 0, s) + +/* + * Detailed verification that 'ustar' archives are written with + * the correct format. + */ +DEFINE_TEST(test_write_format_tar_ustar) +{ + struct archive *a; + struct archive_entry *entry; + char *buff, *e; + size_t buffsize = 100000; + size_t used; + int i; + char f99[100]; + char f100[101]; + char f256[257]; + + for (i = 0; i < 99; ++i) + f99[i] = 'a' + i % 26; + f99[99] = '\0'; + + for (i = 0; i < 100; ++i) + f100[i] = 'A' + i % 26; + f100[100] = '\0'; + + for (i = 0; i < 256; ++i) + f256[i] = 'A' + i % 26; + f256[155] = '/'; + f256[256] = '\0'; + + buff = malloc(buffsize); + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, 0, archive_write_set_format_ustar(a)); + assertEqualIntA(a, 0, archive_write_set_compression_none(a)); + assertEqualIntA(a, 0, archive_write_open_memory(a, buff, buffsize, &used)); + + /* + * Add various files to it. + * TODO: Extend this to cover more filetypes. + */ + + /* "file" with 10 bytes of content */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 1, 10); + archive_entry_set_pathname(entry, "file"); + archive_entry_set_mode(entry, S_IFREG | 0664); + archive_entry_set_size(entry, 10); + archive_entry_set_uid(entry, 80); + archive_entry_set_gid(entry, 90); + archive_entry_set_dev(entry, 12); + archive_entry_set_ino(entry, 89); + archive_entry_set_nlink(entry, 2); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); + + /* Hardlink to "file" with 10 bytes of content */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 1, 10); + archive_entry_set_pathname(entry, "linkfile"); + archive_entry_set_mode(entry, S_IFREG | 0664); + /* TODO: Put this back and fix the bug. */ + /* archive_entry_set_size(entry, 10); */ + archive_entry_set_uid(entry, 80); + archive_entry_set_gid(entry, 90); + archive_entry_set_dev(entry, 12); + archive_entry_set_ino(entry, 89); + archive_entry_set_nlink(entry, 2); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + /* Write of data to dir should fail == zero bytes get written. */ + assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); + + /* "dir" */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 2, 20); + archive_entry_set_pathname(entry, "dir"); + archive_entry_set_mode(entry, S_IFDIR | 0775); + archive_entry_set_size(entry, 10); + archive_entry_set_nlink(entry, 2); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + /* Write of data to dir should fail == zero bytes get written. */ + assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); + + /* "symlink" pointing to "file" */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 3, 30); + archive_entry_set_pathname(entry, "symlink"); + archive_entry_set_mode(entry, 0664); + archive_entry_set_filetype(entry, AE_IFLNK); + archive_entry_set_symlink(entry,"file"); + archive_entry_set_size(entry, 0); + archive_entry_set_uid(entry, 88); + archive_entry_set_gid(entry, 98); + archive_entry_set_dev(entry, 12); + archive_entry_set_ino(entry, 90); + archive_entry_set_nlink(entry, 1); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + /* Write of data to symlink should fail == zero bytes get written. */ + assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); + + /* file with 99-char filename. */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 1, 10); + archive_entry_set_pathname(entry, f99); + archive_entry_set_mode(entry, S_IFREG | 0664); + archive_entry_set_size(entry, 0); + archive_entry_set_uid(entry, 82); + archive_entry_set_gid(entry, 93); + archive_entry_set_dev(entry, 102); + archive_entry_set_ino(entry, 7); + archive_entry_set_nlink(entry, 1); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + + /* file with 100-char filename. */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 1, 10); + archive_entry_set_pathname(entry, f100); + archive_entry_set_mode(entry, S_IFREG | 0664); + archive_entry_set_size(entry, 0); + archive_entry_set_uid(entry, 82); + archive_entry_set_gid(entry, 93); + archive_entry_set_dev(entry, 102); + archive_entry_set_ino(entry, 7); + archive_entry_set_nlink(entry, 1); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + + /* file with 256-char filename. */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_mtime(entry, 1, 10); + archive_entry_set_pathname(entry, f256); + archive_entry_set_mode(entry, S_IFREG | 0664); + archive_entry_set_size(entry, 0); + archive_entry_set_uid(entry, 82); + archive_entry_set_gid(entry, 93); + archive_entry_set_dev(entry, 102); + archive_entry_set_ino(entry, 7); + archive_entry_set_nlink(entry, 1); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assert(0 == archive_write_finish(a)); +#endif + + /* + * Verify the archive format. + */ + e = buff; + + /* "file" */ + myAssertEqualMem(e + 0, "file", 5); /* Filename */ + myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ + myAssertEqualMem(e + 108, "000120 ", 8); /* uid */ + myAssertEqualMem(e + 116, "000132 ", 8); /* gid */ + myAssertEqualMem(e + 124, "00000000012 ", 12); /* size */ + myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ + myAssertEqualMem(e + 148, "010034\0 ", 8); /* checksum */ + myAssertEqualMem(e + 156, "0", 1); /* linkflag */ + myAssertEqualMem(e + 157, "", 1); /* linkname */ + myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ + myAssertEqualMem(e + 265, "", 1); /* uname */ + myAssertEqualMem(e + 297, "", 1); /* gname */ + myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ + myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ + myAssertEqualMem(e + 345, "", 1); /* prefix */ + assert(is_null(e + 0, 512)); + myAssertEqualMem(e + 512, "1234567890", 10); + assert(is_null(e + 512, 512)); + e += 1024; + + /* hardlink to "file" */ + myAssertEqualMem(e + 0, "linkfile", 9); /* Filename */ + myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ + myAssertEqualMem(e + 108, "000120 ", 8); /* uid */ + myAssertEqualMem(e + 116, "000132 ", 8); /* gid */ + myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ + myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ + myAssertEqualMem(e + 148, "010707\0 ", 8); /* checksum */ + myAssertEqualMem(e + 156, "0", 1); /* linkflag */ + myAssertEqualMem(e + 157, "", 1); /* linkname */ + myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ + myAssertEqualMem(e + 265, "", 1); /* uname */ + myAssertEqualMem(e + 297, "", 1); /* gname */ + myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ + myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ + myAssertEqualMem(e + 345, "", 1); /* prefix */ + assert(is_null(e + 0, 512)); + e += 512; + + /* "dir" */ + myAssertEqualMem(e + 0, "dir/", 4); /* Filename */ + myAssertEqualMem(e + 100, "000775 ", 8); /* mode */ + myAssertEqualMem(e + 108, "000000 ", 8); /* uid */ + myAssertEqualMem(e + 116, "000000 ", 8); /* gid */ + myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ + myAssertEqualMem(e + 136, "00000000002 ", 12); /* mtime */ + myAssertEqualMem(e + 148, "007747\0 ", 8); /* checksum */ + myAssertEqualMem(e + 156, "5", 1); /* typeflag */ + myAssertEqualMem(e + 157, "", 1); /* linkname */ + myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ + myAssertEqualMem(e + 265, "", 1); /* uname */ + myAssertEqualMem(e + 297, "", 1); /* gname */ + myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ + myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ + myAssertEqualMem(e + 345, "", 1); /* prefix */ + assert(is_null(e + 0, 512)); + e += 512; + + /* "symlink" pointing to "file" */ + myAssertEqualMem(e + 0, "symlink", 8); /* Filename */ + myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ + myAssertEqualMem(e + 108, "000130 ", 8); /* uid */ + myAssertEqualMem(e + 116, "000142 ", 8); /* gid */ + myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ + myAssertEqualMem(e + 136, "00000000003 ", 12); /* mtime */ + myAssertEqualMem(e + 148, "011446\0 ", 8); /* checksum */ + myAssertEqualMem(e + 156, "2", 1); /* linkflag */ + myAssertEqualMem(e + 157, "file", 5); /* linkname */ + myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ + myAssertEqualMem(e + 265, "", 1); /* uname */ + myAssertEqualMem(e + 297, "", 1); /* gname */ + myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ + myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ + myAssertEqualMem(e + 345, "", 1); /* prefix */ + assert(is_null(e + 0, 512)); + e += 512; + + /* File with 99-char filename */ + myAssertEqualMem(e + 0, f99, 100); /* Filename */ + myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ + myAssertEqualMem(e + 108, "000122 ", 8); /* uid */ + myAssertEqualMem(e + 116, "000135 ", 8); /* gid */ + myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ + myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ + myAssertEqualMem(e + 148, "034242\0 ", 8); /* checksum */ + myAssertEqualMem(e + 156, "0", 1); /* linkflag */ + myAssertEqualMem(e + 157, "", 1); /* linkname */ + myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ + myAssertEqualMem(e + 265, "", 1); /* uname */ + myAssertEqualMem(e + 297, "", 1); /* gname */ + myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ + myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ + myAssertEqualMem(e + 345, "", 1); /* prefix */ + assert(is_null(e + 0, 512)); + e += 512; + + /* File with 100-char filename */ + myAssertEqualMem(e + 0, f100, 100); /* Filename */ + myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ + myAssertEqualMem(e + 108, "000122 ", 8); /* uid */ + myAssertEqualMem(e + 116, "000135 ", 8); /* gid */ + myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ + myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ + myAssertEqualMem(e + 148, "026230\0 ", 8); /* checksum */ + myAssertEqualMem(e + 156, "0", 1); /* linkflag */ + myAssertEqualMem(e + 157, "", 1); /* linkname */ + myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ + myAssertEqualMem(e + 265, "", 1); /* uname */ + myAssertEqualMem(e + 297, "", 1); /* gname */ + myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ + myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ + myAssertEqualMem(e + 345, "", 1); /* prefix */ + assert(is_null(e + 0, 512)); + e += 512; + + /* File with 256-char filename */ + myAssertEqualMem(e + 0, f256 + 156, 100); /* Filename */ + myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ + myAssertEqualMem(e + 108, "000122 ", 8); /* uid */ + myAssertEqualMem(e + 116, "000135 ", 8); /* gid */ + myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ + myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ + myAssertEqualMem(e + 148, "055570\0 ", 8); /* checksum */ + myAssertEqualMem(e + 156, "0", 1); /* linkflag */ + myAssertEqualMem(e + 157, "", 1); /* linkname */ + myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ + myAssertEqualMem(e + 265, "", 1); /* uname */ + myAssertEqualMem(e + 297, "", 1); /* gname */ + myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ + myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ + myAssertEqualMem(e + 345, f256, 155); /* prefix */ + assert(is_null(e + 0, 512)); + e += 512; + + /* TODO: Verify other types of entries. */ + + /* Last entry is end-of-archive marker. */ + assert(is_null(e, 1024)); + e += 1024; + + assertEqualInt((int)used, e - buff); + + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_zip.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_zip.c new file mode 100644 index 000000000..250ddba91 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_zip.c @@ -0,0 +1,180 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * Copyright (c) 2008 Anselm Strauss + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Development supported by Google Summer of Code 2008. + */ + +/* TODO: reader does not yet restore permissions. */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_zip.c 201247 2009-12-30 05:59:21Z kientzle $"); + +DEFINE_TEST(test_write_format_zip) +{ + char filedata[64]; + struct archive_entry *ae; + struct archive *a; + size_t used; + size_t buffsize = 1000000; + char *buff; + const char *compression_type; + + buff = malloc(buffsize); + + /* Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_zip(a)); +#ifdef HAVE_ZLIB_H + compression_type = "zip:compression=deflate"; +#else + compression_type = "zip:compression=store"; +#endif + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_format_options(a, compression_type)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_open_memory(a, buff, buffsize, &used)); + + /* + * Write a file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 10); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(10, archive_entry_mtime_nsec(ae)); + archive_entry_copy_pathname(ae, "file"); + assertEqualString("file", archive_entry_pathname(ae)); + archive_entry_set_mode(ae, S_IFREG | 0755); + assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); + archive_entry_set_size(ae, 8); + + assertEqualInt(0, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualInt(8, archive_write_data(a, "12345678", 9)); + assertEqualInt(0, archive_write_data(a, "1", 1)); + + /* + * Write another file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 10); + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(10, archive_entry_mtime_nsec(ae)); + archive_entry_copy_pathname(ae, "file2"); + assertEqualString("file2", archive_entry_pathname(ae)); + archive_entry_set_mode(ae, S_IFREG | 0755); + assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); + archive_entry_set_size(ae, 4); + + assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); + archive_entry_free(ae); + assertEqualInt(4, archive_write_data(a, "1234", 5)); + + /* + * Write a directory to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 11, 110); + archive_entry_copy_pathname(ae, "dir"); + archive_entry_set_mode(ae, S_IFDIR | 0755); + archive_entry_set_size(ae, 512); + + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); + failure("size should be zero so that applications know not to write"); + assertEqualInt(0, archive_entry_size(ae)); + archive_entry_free(ae); + assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9)); + + /* Close out the archive. */ + assertEqualInt(ARCHIVE_OK, archive_write_close(a)); + assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); + + /* + * Now, read the data back. + */ + ae = NULL; + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, buff, used)); + + /* + * Read and verify first file. + */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + /* Zip doesn't store high-resolution mtime. */ + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file", archive_entry_pathname(ae)); + //assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualIntA(a, 8, + archive_read_data(a, filedata, sizeof(filedata))); + assertEqualMem(filedata, "12345678", 8); + + + /* + * Read the second file back. + */ + if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))){ + free(buff); + return; + } + assertEqualInt(1, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + //assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualIntA(a, 4, + archive_read_data(a, filedata, sizeof(filedata))); + assertEqualMem(filedata, "1234", 4); + + /* + * Read the dir entry back. + */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(11, archive_entry_mtime(ae)); + assertEqualInt(0, archive_entry_mtime_nsec(ae)); + assertEqualInt(0, archive_entry_atime(ae)); + assertEqualInt(0, archive_entry_ctime(ae)); + assertEqualString("dir/", archive_entry_pathname(ae)); + //assertEqualInt((S_IFDIR | 0755), archive_entry_mode(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualIntA(a, 0, archive_read_data(a, filedata, 10)); + + /* Verify the end of the archive. */ + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + free(buff); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_zip_empty.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_zip_empty.c new file mode 100644 index 000000000..459664e23 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_zip_empty.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2008 Anselm Strauss + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Development supported by Google Summer of Code 2008. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_zip_empty.c 201247 2009-12-30 05:59:21Z kientzle $"); + +DEFINE_TEST(test_write_format_zip_empty) +{ + struct archive *a; + char buff[256]; + size_t used; + + /* Zip format: Create a new archive in memory. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_zip(a)); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_set_bytes_per_block(a, 1)); + assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* Close out the archive without writing anything. */ + assertA(0 == archive_write_close(a)); + assertA(0 == archive_write_finish(a)); + + /* Verify the correct format for an empy Zip archive. */ + assertEqualInt(used, 22); + assertEqualMem(buff, + "PK\005\006\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", + 22); +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_format_zip_no_compression.c b/external/bsd/libarchive/dist/libarchive/test/test_write_format_zip_no_compression.c new file mode 100644 index 000000000..4a61a76eb --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_format_zip_no_compression.c @@ -0,0 +1,304 @@ +/*- + * Copyright (c) 2008 Anselm Strauss + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Development supported by Google Summer of Code 2008. + */ + +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_format_zip_no_compression.c 201247 2009-12-30 05:59:21Z kientzle $"); + +static unsigned long +bitcrc32(unsigned long c, void *_p, size_t s) +{ + /* This is a drop-in replacement for crc32() from zlib. + * Libarchive should be able to correctly generate + * uncompressed zip archives (including correct CRCs) even + * when zlib is unavailable, and this function helps us verify + * that. Yes, this is very, very slow and unsuitable for + * production use, but it's correct, compact, and works well + * enough for this particular usage. Libarchive internally + * uses a much more efficient implementation. */ + const unsigned char *p = _p; + int bitctr; + + if (p == NULL) + return (0); + + for (; s > 0; --s) { + c ^= *p++; + for (bitctr = 8; bitctr > 0; --bitctr) { + if (c & 1) c = (c >> 1); + else c = (c >> 1) ^ 0xedb88320; + c ^= 0x80000000; + } + } + return (c); +} + +/* Quick and dirty: Read 2-byte and 4-byte integers from Zip file. */ +static int i2(const char *p) { return ((p[0] & 0xff) | ((p[1] & 0xff) << 8)); } +static int i4(const char *p) { return (i2(p) | (i2(p + 2) << 16)); } + +DEFINE_TEST(test_write_format_zip_no_compression) +{ + /* Buffer data */ + struct archive *a; + struct archive_entry *entry; + char buff[100000]; + const char *buffend; + /* p is the pointer to walk over the central directory, + * q walks over the local headers, the data and the data descriptors. */ + const char *p, *q; + size_t used; + + /* File data */ + char file_name[] = "file"; + char file_data1[] = {'1', '2', '3', '4', '5'}; + char file_data2[] = {'6', '7', '8', '9', '0'}; + int file_perm = 00644; + short file_uid = 10; + short file_gid = 20; + + /* Folder data */ + char folder_name[] = "folder/"; + int folder_perm = 00755; + short folder_uid = 30; + short folder_gid = 40; + + /* Time data */ + time_t t = time(NULL); + struct tm *tm = localtime(&t); + + /* Misc variables */ + unsigned long crc; + + /* Create new ZIP archive in memory without padding. */ + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_zip(a)); + assertA(0 == archive_write_set_format_options(a, "zip:compression=store")); + assertA(0 == archive_write_set_compression_none(a)); + assertA(0 == archive_write_set_bytes_per_block(a, 1)); + assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); + assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + + /* Write entries. */ + + /* Regular file */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_pathname(entry, file_name); + archive_entry_set_mode(entry, S_IFREG | 0644); + archive_entry_set_size(entry, sizeof(file_data1) + sizeof(file_data2)); + archive_entry_set_uid(entry, file_uid); + archive_entry_set_gid(entry, file_gid); + archive_entry_set_mtime(entry, t, 0); + archive_entry_set_atime(entry, t, 0); + archive_entry_set_ctime(entry, t, 0); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + assertEqualIntA(a, sizeof(file_data1), archive_write_data(a, file_data1, sizeof(file_data1))); + assertEqualIntA(a, sizeof(file_data2), archive_write_data(a, file_data2, sizeof(file_data2))); + archive_entry_free(entry); + + /* Folder */ + assert((entry = archive_entry_new()) != NULL); + archive_entry_set_pathname(entry, folder_name); + archive_entry_set_mode(entry, S_IFDIR | folder_perm); + archive_entry_set_size(entry, 0); + archive_entry_set_uid(entry, folder_uid); + archive_entry_set_gid(entry, folder_gid); + archive_entry_set_mtime(entry, t, 0); + archive_entry_set_atime(entry, t, 0); + archive_entry_set_ctime(entry, t, 0); + assertEqualIntA(a, 0, archive_write_header(a, entry)); + archive_entry_free(entry); + + /* Close the archive . */ + assertA(0 == archive_write_close(a)); + assertA(0 == archive_write_finish(a)); + + /* Remember the end of the archive in memory. */ + buffend = buff + used; + + /* Verify "End of Central Directory" record. */ + /* Get address of end-of-central-directory record. */ + p = buffend - 22; /* Assumes there is no zip comment field. */ + failure("End-of-central-directory begins with PK\\005\\006 signature"); + assertEqualMem(p, "PK\005\006", 4); + failure("This must be disk 0"); + assertEqualInt(i2(p + 4), 0); + failure("Central dir must start on disk 0"); + assertEqualInt(i2(p + 6), 0); + failure("All central dir entries are on this disk"); + assertEqualInt(i2(p + 8), i2(p + 10)); + failure("CD start (%d) + CD length (%d) should == archive size - 22", + i4(p + 12), i4(p + 16)); + assertEqualInt(i4(p + 12) + i4(p + 16), used - 22); + failure("no zip comment"); + assertEqualInt(i2(p + 20), 0); + + /* Get address of first entry in central directory. */ + p = buff + i4(buffend - 6); + failure("Central file record at offset %d should begin with" + " PK\\001\\002 signature", + i4(buffend - 10)); + + /* Verify file entry in central directory. */ + assertEqualMem(p, "PK\001\002", 4); /* Signature */ + assertEqualInt(i2(p + 4), 3 * 256 + 20); /* Version made by */ + assertEqualInt(i2(p + 6), 20); /* Version needed to extract */ + assertEqualInt(i2(p + 8), 8); /* Flags */ + assertEqualInt(i2(p + 10), 0); /* Compression method */ + assertEqualInt(i2(p + 12), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ + assertEqualInt(i2(p + 14), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ + crc = bitcrc32(0, file_data1, sizeof(file_data1)); + crc = bitcrc32(crc, file_data2, sizeof(file_data2)); + assertEqualInt(i4(p + 16), crc); /* CRC-32 */ + assertEqualInt(i4(p + 20), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ + assertEqualInt(i4(p + 24), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ + assertEqualInt(i2(p + 28), strlen(file_name)); /* Pathname length */ + assertEqualInt(i2(p + 30), 13); /* Extra field length */ + assertEqualInt(i2(p + 32), 0); /* File comment length */ + assertEqualInt(i2(p + 34), 0); /* Disk number start */ + assertEqualInt(i2(p + 36), 0); /* Internal file attrs */ + assertEqualInt(i4(p + 38) >> 16 & 01777, file_perm); /* External file attrs */ + assertEqualInt(i4(p + 42), 0); /* Offset of local header */ + assertEqualMem(p + 46, file_name, strlen(file_name)); /* Pathname */ + p = p + 46 + strlen(file_name); + assertEqualInt(i2(p), 0x5455); /* 'UT' extension header */ + assertEqualInt(i2(p + 2), 5); /* 'UT' size */ + assertEqualInt(p[4], 7); /* 'UT' flags */ + assertEqualInt(i4(p + 5), t); /* 'UT' mtime */ + p = p + 9; + assertEqualInt(i2(p), 0x7855); /* 'Ux' extension header */ + assertEqualInt(i2(p + 2), 0); /* 'Ux' size */ + p = p + 4; + + /* Verify local header of file entry. */ + q = buff; + assertEqualMem(q, "PK\003\004", 4); /* Signature */ + assertEqualInt(i2(q + 4), 20); /* Version needed to extract */ + assertEqualInt(i2(q + 6), 8); /* Flags */ + assertEqualInt(i2(q + 8), 0); /* Compression method */ + assertEqualInt(i2(q + 10), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ + assertEqualInt(i2(q + 12), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ + assertEqualInt(i4(q + 14), 0); /* CRC-32 */ + assertEqualInt(i4(q + 18), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ + assertEqualInt(i4(q + 22), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ + assertEqualInt(i2(q + 26), strlen(file_name)); /* Pathname length */ + assertEqualInt(i2(q + 28), 25); /* Extra field length */ + assertEqualMem(q + 30, file_name, strlen(file_name)); /* Pathname */ + q = q + 30 + strlen(file_name); + assertEqualInt(i2(q), 0x5455); /* 'UT' extension header */ + assertEqualInt(i2(q + 2), 13); /* 'UT' size */ + assertEqualInt(q[4], 7); /* 'UT' flags */ + assertEqualInt(i4(q + 5), t); /* 'UT' mtime */ + assertEqualInt(i4(q + 9), t); /* 'UT' atime */ + assertEqualInt(i4(q + 13), t); /* 'UT' ctime */ + q = q + 17; + assertEqualInt(i2(q), 0x7855); /* 'Ux' extension header */ + assertEqualInt(i2(q + 2), 4); /* 'Ux' size */ + assertEqualInt(i2(q + 4), file_uid); /* 'Ux' UID */ + assertEqualInt(i2(q + 6), file_gid); /* 'Ux' GID */ + q = q + 8; + + /* Verify data of file entry. */ + assertEqualMem(q, file_data1, sizeof(file_data1)); + assertEqualMem(q + sizeof(file_data1), file_data2, sizeof(file_data2)); + q = q + sizeof(file_data1) + sizeof(file_data2); + + /* Verify data descriptor of file entry. */ + assertEqualMem(q, "PK\007\010", 4); /* Signature */ + assertEqualInt(i4(q + 4), crc); /* CRC-32 */ + assertEqualInt(i4(q + 8), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ + assertEqualInt(i4(q + 12), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ + q = q + 16; + + /* Verify folder entry in central directory. */ + assertEqualMem(p, "PK\001\002", 4); /* Signature */ + assertEqualInt(i2(p + 4), 3 * 256 + 20); /* Version made by */ + assertEqualInt(i2(p + 6), 20); /* Version needed to extract */ + assertEqualInt(i2(p + 8), 8); /* Flags */ + assertEqualInt(i2(p + 10), 0); /* Compression method */ + assertEqualInt(i2(p + 12), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ + assertEqualInt(i2(p + 14), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ + crc = 0; + assertEqualInt(i4(p + 16), crc); /* CRC-32 */ + assertEqualInt(i4(p + 20), 0); /* Compressed size */ + assertEqualInt(i4(p + 24), 0); /* Uncompressed size */ + assertEqualInt(i2(p + 28), strlen(folder_name)); /* Pathname length */ + assertEqualInt(i2(p + 30), 13); /* Extra field length */ + assertEqualInt(i2(p + 32), 0); /* File comment length */ + assertEqualInt(i2(p + 34), 0); /* Disk number start */ + assertEqualInt(i2(p + 36), 0); /* Internal file attrs */ + assertEqualInt(i4(p + 38) >> 16 & 01777, folder_perm); /* External file attrs */ + assertEqualInt(i4(p + 42), q - buff); /* Offset of local header */ + assertEqualMem(p + 46, folder_name, strlen(folder_name)); /* Pathname */ + p = p + 46 + strlen(folder_name); + assertEqualInt(i2(p), 0x5455); /* 'UT' extension header */ + assertEqualInt(i2(p + 2), 5); /* 'UT' size */ + assertEqualInt(p[4], 7); /* 'UT' flags */ + assertEqualInt(i4(p + 5), t); /* 'UT' mtime */ + p = p + 9; + assertEqualInt(i2(p), 0x7855); /* 'Ux' extension header */ + assertEqualInt(i2(p + 2), 0); /* 'Ux' size */ + p = p + 4; + + /* Verify local header of folder entry. */ + assertEqualMem(q, "PK\003\004", 4); /* Signature */ + assertEqualInt(i2(q + 4), 20); /* Version needed to extract */ + assertEqualInt(i2(q + 6), 8); /* Flags */ + assertEqualInt(i2(q + 8), 0); /* Compression method */ + assertEqualInt(i2(q + 10), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ + assertEqualInt(i2(q + 12), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ + assertEqualInt(i4(q + 14), 0); /* CRC-32 */ + assertEqualInt(i4(q + 18), 0); /* Compressed size */ + assertEqualInt(i4(q + 22), 0); /* Uncompressed size */ + assertEqualInt(i2(q + 26), strlen(folder_name)); /* Pathname length */ + assertEqualInt(i2(q + 28), 25); /* Extra field length */ + assertEqualMem(q + 30, folder_name, strlen(folder_name)); /* Pathname */ + q = q + 30 + strlen(folder_name); + assertEqualInt(i2(q), 0x5455); /* 'UT' extension header */ + assertEqualInt(i2(q + 2), 13); /* 'UT' size */ + assertEqualInt(q[4], 7); /* 'UT' flags */ + assertEqualInt(i4(q + 5), t); /* 'UT' mtime */ + assertEqualInt(i4(q + 9), t); /* 'UT' atime */ + assertEqualInt(i4(q + 13), t); /* 'UT' ctime */ + q = q + 17; + assertEqualInt(i2(q), 0x7855); /* 'Ux' extension header */ + assertEqualInt(i2(q + 2), 4); /* 'Ux' size */ + assertEqualInt(i2(q + 4), folder_uid); /* 'Ux' UID */ + assertEqualInt(i2(q + 6), folder_gid); /* 'Ux' GID */ + q = q + 8; + + /* There should not be any data in the folder entry, + * meaning next is the data descriptor header. */ + + /* Verify data descriptor of folder entry. */ + assertEqualMem(q, "PK\007\010", 4); /* Signature */ + assertEqualInt(i4(q + 4), crc); /* CRC-32 */ + assertEqualInt(i4(q + 8), 0); /* Compressed size */ + assertEqualInt(i4(q + 12), 0); /* Uncompressed size */ + q = q + 16; +} diff --git a/external/bsd/libarchive/dist/libarchive/test/test_write_open_memory.c b/external/bsd/libarchive/dist/libarchive/test/test_write_open_memory.c new file mode 100644 index 000000000..696db6c96 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive/test/test_write_open_memory.c @@ -0,0 +1,76 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_open_memory.c 189308 2009-03-03 17:02:51Z kientzle $"); + +/* Try to force archive_write_open_memory.c to write past the end of an array. */ +static unsigned char buff[16384]; + +DEFINE_TEST(test_write_open_memory) +{ + unsigned int i; + struct archive *a; + struct archive_entry *ae; + const char *name="/tmp/test"; + + /* Create a simple archive_entry. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_pathname(ae, name); + archive_entry_set_mode(ae, S_IFREG); + assertEqualString(archive_entry_pathname(ae), name); + + /* Try writing with different buffer sizes. */ + /* Make sure that we get failure on too-small buffers, success on + * large enough ones. */ + for (i = 100; i < 1600; i++) { + size_t s; + size_t blocksize = 94; + assert((a = archive_write_new()) != NULL); + assertA(0 == archive_write_set_format_ustar(a)); + assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); + assertA(0 == archive_write_set_bytes_per_block(a, (int)blocksize)); + buff[i] = 0xAE; + assertA(0 == archive_write_open_memory(a, buff, i, &s)); + /* If buffer is smaller than a tar header, this should fail. */ + if (i < (511/blocksize)*blocksize) + assertA(ARCHIVE_FATAL == archive_write_header(a,ae)); + else + assertA(0 == archive_write_header(a, ae)); + /* If buffer is smaller than a tar header plus 1024 byte + * end-of-archive marker, then this should fail. */ + if (i < 1536) + assertA(ARCHIVE_FATAL == archive_write_close(a)); + else + assertA(0 == archive_write_close(a)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(a); +#else + assert(0 == archive_write_finish(a)); +#endif + assert(buff[i] == 0xAE); + assert(s <= i); + } + archive_entry_free(ae); +} diff --git a/external/bsd/libarchive/dist/libarchive_fe/err.c b/external/bsd/libarchive/dist/libarchive_fe/err.c new file mode 100644 index 000000000..eb3f9f3eb --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive_fe/err.c @@ -0,0 +1,74 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lafe_platform.h" +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_STDARG_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "err.h" + +const char *lafe_progname; + +static void +lafe_vwarnc(int code, const char *fmt, va_list ap) +{ + fprintf(stderr, "%s: ", lafe_progname); + vfprintf(stderr, fmt, ap); + if (code != 0) + fprintf(stderr, ": %s", strerror(code)); + fprintf(stderr, "\n"); +} + +void +lafe_warnc(int code, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + lafe_vwarnc(code, fmt, ap); + va_end(ap); +} + +void +lafe_errc(int eval, int code, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + lafe_vwarnc(code, fmt, ap); + va_end(ap); + exit(eval); +} diff --git a/external/bsd/libarchive/dist/libarchive_fe/err.h b/external/bsd/libarchive/dist/libarchive_fe/err.h new file mode 100644 index 000000000..dd7944813 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive_fe/err.h @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2009 Joerg Sonnenberger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LAFE_ERR_H +#define LAFE_ERR_H + +#if defined(__GNUC__) && (__GNUC__ > 2 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_DEAD __attribute__((__noreturn__)) +#else +#define __LA_DEAD +#endif + +extern const char *lafe_progname; + +void lafe_warnc(int code, const char *fmt, ...); +void lafe_errc(int eval, int code, const char *fmt, ...) __LA_DEAD; + +#endif diff --git a/external/bsd/libarchive/dist/libarchive_fe/lafe_platform.h b/external/bsd/libarchive/dist/libarchive_fe/lafe_platform.h new file mode 100644 index 000000000..557124b9f --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive_fe/lafe_platform.h @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/usr.bin/cpio/cpio_platform.h,v 1.2 2008/12/06 07:15:42 kientzle Exp $ + */ + +/* + * This header is the first thing included in any of the libarchive_fe + * source files. As far as possible, platform-specific issues should + * be dealt with here and not within individual source files. + */ + +#ifndef LAFE_PLATFORM_H_INCLUDED +#define LAFE_PLATFORM_H_INCLUDED + +#if defined(PLATFORM_CONFIG_H) +/* Use hand-built config.h in environments that need it. */ +#include PLATFORM_CONFIG_H +#else +/* Read config.h or die trying. */ +#include "config.h" +#endif + +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID +#define __FBSDID(a) struct _undefined_hack +#endif + +#endif diff --git a/external/bsd/libarchive/dist/libarchive_fe/line_reader.c b/external/bsd/libarchive/dist/libarchive_fe/line_reader.c new file mode 100644 index 000000000..4af60de4c --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive_fe/line_reader.c @@ -0,0 +1,171 @@ +/*- + * Copyright (c) 2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lafe_platform.h" +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include "err.h" +#include "line_reader.h" + +#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) +#define strdup _strdup +#endif + +/* + * Read lines from file and do something with each one. If option_null + * is set, lines are terminated with zero bytes; otherwise, they're + * terminated with newlines. + * + * This uses a self-sizing buffer to handle arbitrarily-long lines. + */ +struct lafe_line_reader { + FILE *f; + char *buff, *buff_end, *line_start, *line_end, *p; + char *pathname; + size_t buff_length; + int nullSeparator; /* Lines separated by null, not CR/CRLF/etc. */ + int ret; +}; + +struct lafe_line_reader * +lafe_line_reader(const char *pathname, int nullSeparator) +{ + struct lafe_line_reader *lr; + + lr = calloc(1, sizeof(*lr)); + if (lr == NULL) + lafe_errc(1, ENOMEM, "Can't open %s", pathname); + + lr->nullSeparator = nullSeparator; + lr->pathname = strdup(pathname); + + if (strcmp(pathname, "-") == 0) + lr->f = stdin; + else + lr->f = fopen(pathname, "r"); + if (lr->f == NULL) + lafe_errc(1, errno, "Couldn't open %s", pathname); + lr->buff_length = 8192; + lr->buff = malloc(lr->buff_length); + if (lr->buff == NULL) + lafe_errc(1, ENOMEM, "Can't read %s", pathname); + lr->line_start = lr->line_end = lr->buff_end = lr->buff; + + return (lr); +} + +const char * +lafe_line_reader_next(struct lafe_line_reader *lr) +{ + size_t bytes_wanted, bytes_read, new_buff_size; + char *line_start, *p; + + for (;;) { + /* If there's a line in the buffer, return it immediately. */ + while (lr->line_end < lr->buff_end) { + if (lr->nullSeparator) { + if (*lr->line_end == '\0') { + line_start = lr->line_start; + lr->line_start = lr->line_end + 1; + lr->line_end = lr->line_start; + return (line_start); + } + } else if (*lr->line_end == '\x0a' || *lr->line_end == '\x0d') { + *lr->line_end = '\0'; + line_start = lr->line_start; + lr->line_start = lr->line_end + 1; + lr->line_end = lr->line_start; + if (line_start[0] != '\0') + return (line_start); + } + lr->line_end++; + } + + /* If we're at end-of-file, process the final data. */ + if (lr->f == NULL) { + /* If there's more text, return one last line. */ + if (lr->line_end > lr->line_start) { + *lr->line_end = '\0'; + line_start = lr->line_start; + lr->line_start = lr->line_end + 1; + lr->line_end = lr->line_start; + return (line_start); + } + /* Otherwise, we're done. */ + return (NULL); + } + + /* Buffer only has part of a line. */ + if (lr->line_start > lr->buff) { + /* Move a leftover fractional line to the beginning. */ + memmove(lr->buff, lr->line_start, + lr->buff_end - lr->line_start); + lr->buff_end -= lr->line_start - lr->buff; + lr->line_end -= lr->line_start - lr->buff; + lr->line_start = lr->buff; + } else { + /* Line is too big; enlarge the buffer. */ + new_buff_size = lr->buff_length * 2; + if (new_buff_size <= lr->buff_length) + lafe_errc(1, ENOMEM, + "Line too long in %s", lr->pathname); + lr->buff_length = new_buff_size; + p = realloc(lr->buff, new_buff_size); + if (p == NULL) + lafe_errc(1, ENOMEM, + "Line too long in %s", lr->pathname); + lr->buff_end = p + (lr->buff_end - lr->buff); + lr->line_end = p + (lr->line_end - lr->buff); + lr->line_start = lr->buff = p; + } + + /* Get some more data into the buffer. */ + bytes_wanted = lr->buff + lr->buff_length - lr->buff_end; + bytes_read = fread(lr->buff_end, 1, bytes_wanted, lr->f); + lr->buff_end += bytes_read; + + if (ferror(lr->f)) + lafe_errc(1, errno, "Can't read %s", lr->pathname); + if (feof(lr->f)) { + if (lr->f != stdin) + fclose(lr->f); + lr->f = NULL; + } + } +} + +void +lafe_line_reader_free(struct lafe_line_reader *lr) +{ + free(lr->buff); + free(lr->pathname); + free(lr); +} diff --git a/external/bsd/libarchive/dist/libarchive_fe/line_reader.h b/external/bsd/libarchive/dist/libarchive_fe/line_reader.h new file mode 100644 index 000000000..d092c051f --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive_fe/line_reader.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2009 Joerg Sonnenberger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LAFE_LINE_READER_H +#define LAFE_LINE_READER_H + +struct lafe_line_reader; + +struct lafe_line_reader *lafe_line_reader(const char *, int nullSeparator); +const char *lafe_line_reader_next(struct lafe_line_reader *); +void lafe_line_reader_free(struct lafe_line_reader *); + +#endif diff --git a/external/bsd/libarchive/dist/libarchive_fe/matching.c b/external/bsd/libarchive/dist/libarchive_fe/matching.c new file mode 100644 index 000000000..f774ac773 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive_fe/matching.c @@ -0,0 +1,284 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lafe_platform.h" +__FBSDID("$FreeBSD: src/usr.bin/cpio/matching.c,v 1.2 2008/06/21 02:20:20 kientzle Exp $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "err.h" +#include "line_reader.h" +#include "matching.h" +#include "pathmatch.h" + +struct match { + struct match *next; + int matches; + char pattern[1]; +}; + +struct lafe_matching { + struct match *exclusions; + int exclusions_count; + struct match *inclusions; + int inclusions_count; + int inclusions_unmatched_count; +}; + +static void add_pattern(struct match **list, const char *pattern); +static void initialize_matching(struct lafe_matching **); +static int match_exclusion(struct match *, const char *pathname); +static int match_inclusion(struct match *, const char *pathname); + +/* + * The matching logic here needs to be re-thought. I started out to + * try to mimic gtar's matching logic, but it's not entirely + * consistent. In particular 'tar -t' and 'tar -x' interpret patterns + * on the command line as anchored, but --exclude doesn't. + */ + +/* + * Utility functions to manage exclusion/inclusion patterns + */ + +int +lafe_exclude(struct lafe_matching **matching, const char *pattern) +{ + + if (*matching == NULL) + initialize_matching(matching); + add_pattern(&((*matching)->exclusions), pattern); + (*matching)->exclusions_count++; + return (0); +} + +int +lafe_exclude_from_file(struct lafe_matching **matching, const char *pathname) +{ + struct lafe_line_reader *lr; + const char *p; + int ret = 0; + + lr = lafe_line_reader(pathname, 0); + while ((p = lafe_line_reader_next(lr)) != NULL) { + if (lafe_exclude(matching, p) != 0) + ret = -1; + } + lafe_line_reader_free(lr); + return (ret); +} + +int +lafe_include(struct lafe_matching **matching, const char *pattern) +{ + + if (*matching == NULL) + initialize_matching(matching); + add_pattern(&((*matching)->inclusions), pattern); + (*matching)->inclusions_count++; + (*matching)->inclusions_unmatched_count++; + return (0); +} + +int +lafe_include_from_file(struct lafe_matching **matching, const char *pathname, + int nullSeparator) +{ + struct lafe_line_reader *lr; + const char *p; + int ret = 0; + + lr = lafe_line_reader(pathname, nullSeparator); + while ((p = lafe_line_reader_next(lr)) != NULL) { + if (lafe_include(matching, p) != 0) + ret = -1; + } + lafe_line_reader_free(lr); + return (ret); +} + +static void +add_pattern(struct match **list, const char *pattern) +{ + struct match *match; + size_t len; + + len = strlen(pattern); + match = malloc(sizeof(*match) + len + 1); + if (match == NULL) + lafe_errc(1, errno, "Out of memory"); + strcpy(match->pattern, pattern); + /* Both "foo/" and "foo" should match "foo/bar". */ + if (len && match->pattern[len - 1] == '/') + match->pattern[strlen(match->pattern)-1] = '\0'; + match->next = *list; + *list = match; + match->matches = 0; +} + + +int +lafe_excluded(struct lafe_matching *matching, const char *pathname) +{ + struct match *match; + struct match *matched; + + if (matching == NULL) + return (0); + + /* Exclusions take priority */ + for (match = matching->exclusions; match != NULL; match = match->next){ + if (match_exclusion(match, pathname)) + return (1); + } + + /* Then check for inclusions */ + matched = NULL; + for (match = matching->inclusions; match != NULL; match = match->next){ + if (match_inclusion(match, pathname)) { + /* + * If this pattern has never been matched, + * then we're done. + */ + if (match->matches == 0) { + match->matches++; + matching->inclusions_unmatched_count--; + return (0); + } + /* + * Otherwise, remember the match but keep checking + * in case we can tick off an unmatched pattern. + */ + matched = match; + } + } + /* + * We didn't find a pattern that had never been matched, but + * we did find a match, so count it and exit. + */ + if (matched != NULL) { + matched->matches++; + return (0); + } + + /* If there were inclusions, default is to exclude. */ + if (matching->inclusions != NULL) + return (1); + + /* No explicit inclusions, default is to match. */ + return (0); +} + +/* + * This is a little odd, but it matches the default behavior of + * gtar. In particular, 'a*b' will match 'foo/a1111/222b/bar' + * + */ +static int +match_exclusion(struct match *match, const char *pathname) +{ + return (lafe_pathmatch(match->pattern, + pathname, + PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); +} + +/* + * Again, mimic gtar: inclusions are always anchored (have to match + * the beginning of the path) even though exclusions are not anchored. + */ +static int +match_inclusion(struct match *match, const char *pathname) +{ +#if 0 + return (lafe_pathmatch(match->pattern, pathname, 0)); +#else + return (lafe_pathmatch(match->pattern, pathname, PATHMATCH_NO_ANCHOR_END)); +#endif +} + +void +lafe_cleanup_exclusions(struct lafe_matching **matching) +{ + struct match *p, *q; + + if (*matching == NULL) + return; + + for (p = (*matching)->inclusions; p != NULL; ) { + q = p; + p = p->next; + free(q); + } + + for (p = (*matching)->exclusions; p != NULL; ) { + q = p; + p = p->next; + free(q); + } + + free(*matching); + *matching = NULL; +} + +static void +initialize_matching(struct lafe_matching **matching) +{ + *matching = calloc(sizeof(**matching), 1); + if (*matching == NULL) + lafe_errc(1, errno, "No memory"); +} + +int +lafe_unmatched_inclusions(struct lafe_matching *matching) +{ + + if (matching == NULL) + return (0); + return (matching->inclusions_unmatched_count); +} + +int +lafe_unmatched_inclusions_warn(struct lafe_matching *matching, const char *msg) +{ + struct match *p; + + if (matching == NULL) + return (0); + + for (p = matching->inclusions; p != NULL; p = p->next) { + if (p->matches == 0) + lafe_warnc(0, "%s: %s", p->pattern, msg); + } + + return (matching->inclusions_unmatched_count); +} diff --git a/external/bsd/libarchive/dist/libarchive_fe/matching.h b/external/bsd/libarchive/dist/libarchive_fe/matching.h new file mode 100644 index 000000000..f4edebd43 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive_fe/matching.h @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef MATCHING_H +#define MATCHING_H + +struct lafe_matching; + +int lafe_exclude(struct lafe_matching **matching, const char *pattern); +int lafe_exclude_from_file(struct lafe_matching **matching, + const char *pathname); +int lafe_include(struct lafe_matching **matching, const char *pattern); +int lafe_include_from_file(struct lafe_matching **matching, + const char *pathname, int nullSeparator); + +int lafe_excluded(struct lafe_matching *, const char *pathname); +void lafe_cleanup_exclusions(struct lafe_matching **); +int lafe_unmatched_inclusions(struct lafe_matching *); +int lafe_unmatched_inclusions_warn(struct lafe_matching *, const char *msg); + +#endif diff --git a/external/bsd/libarchive/dist/libarchive_fe/pathmatch.c b/external/bsd/libarchive/dist/libarchive_fe/pathmatch.c new file mode 100644 index 000000000..85074bdb3 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive_fe/pathmatch.c @@ -0,0 +1,255 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "lafe_platform.h" +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_STRING_H +#include +#endif + +#include "pathmatch.h" + +/* + * Check whether a character 'c' is matched by a list specification [...]: + * * Leading '!' negates the class. + * * - is a range of characters + * * \ removes any special meaning for + * + * Some interesting boundary cases: + * a-d-e is one range (a-d) followed by two single characters - and e. + * \a-\d is same as a-d + * a\-d is three single characters: a, d, - + * Trailing - is not special (so [a-] is two characters a and -). + * Initial - is not special ([a-] is same as [-a] is same as [\\-a]) + * This function never sees a trailing \. + * [] always fails + * [!] always succeeds + */ +static int +pm_list(const char *start, const char *end, const char c, int flags) +{ + const char *p = start; + char rangeStart = '\0', nextRangeStart; + int match = 1, nomatch = 0; + + /* This will be used soon... */ + (void)flags; /* UNUSED */ + + /* If this is a negated class, return success for nomatch. */ + if (*p == '!' && p < end) { + match = 0; + nomatch = 1; + ++p; + } + + while (p < end) { + nextRangeStart = '\0'; + switch (*p) { + case '-': + /* Trailing or initial '-' is not special. */ + if ((rangeStart == '\0') || (p == end - 1)) { + if (*p == c) + return (match); + } else { + char rangeEnd = *++p; + if (rangeEnd == '\\') + rangeEnd = *++p; + if ((rangeStart <= c) && (c <= rangeEnd)) + return (match); + } + break; + case '\\': + ++p; + /* Fall through */ + default: + if (*p == c) + return (match); + nextRangeStart = *p; /* Possible start of range. */ + } + rangeStart = nextRangeStart; + ++p; + } + return (nomatch); +} + +/* + * If s is pointing to "./", ".//", "./././" or the like, skip it. + */ +static const char * +pm_slashskip(const char *s) { + while ((*s == '/') + || (s[0] == '.' && s[1] == '/') + || (s[0] == '.' && s[1] == '\0')) + ++s; + return (s); +} + +static int +pm(const char *p, const char *s, int flags) +{ + const char *end; + + /* + * Ignore leading './', './/', '././', etc. + */ + if (s[0] == '.' && s[1] == '/') + s = pm_slashskip(s + 1); + if (p[0] == '.' && p[1] == '/') + p = pm_slashskip(p + 1); + + for (;;) { + switch (*p) { + case '\0': + if (s[0] == '/') { + if (flags & PATHMATCH_NO_ANCHOR_END) + return (1); + /* "dir" == "dir/" == "dir/." */ + s = pm_slashskip(s); + } + return (*s == '\0'); + case '?': + /* ? always succeds, unless we hit end of 's' */ + if (*s == '\0') + return (0); + break; + case '*': + /* "*" == "**" == "***" ... */ + while (*p == '*') + ++p; + /* Trailing '*' always succeeds. */ + if (*p == '\0') + return (1); + while (*s) { + if (lafe_pathmatch(p, s, flags)) + return (1); + ++s; + } + return (0); + case '[': + /* + * Find the end of the [...] character class, + * ignoring \] that might occur within the class. + */ + end = p + 1; + while (*end != '\0' && *end != ']') { + if (*end == '\\' && end[1] != '\0') + ++end; + ++end; + } + if (*end == ']') { + /* We found [...], try to match it. */ + if (!pm_list(p + 1, end, *s, flags)) + return (0); + p = end; /* Jump to trailing ']' char. */ + break; + } else + /* No final ']', so just match '['. */ + if (*p != *s) + return (0); + break; + case '\\': + /* Trailing '\\' matches itself. */ + if (p[1] == '\0') { + if (*s != '\\') + return (0); + } else { + ++p; + if (*p != *s) + return (0); + } + break; + case '/': + if (*s != '/' && *s != '\0') + return (0); + /* Note: pattern "/\./" won't match "/"; + * pm_slashskip() correctly stops at backslash. */ + p = pm_slashskip(p); + s = pm_slashskip(s); + if (*p == '\0' && (flags & PATHMATCH_NO_ANCHOR_END)) + return (1); + --p; /* Counteract the increment below. */ + --s; + break; + case '$': + /* '$' is special only at end of pattern and only + * if PATHMATCH_NO_ANCHOR_END is specified. */ + if (p[1] == '\0' && (flags & PATHMATCH_NO_ANCHOR_END)){ + /* "dir" == "dir/" == "dir/." */ + return (*pm_slashskip(s) == '\0'); + } + /* Otherwise, '$' is not special. */ + /* FALL THROUGH */ + default: + if (*p != *s) + return (0); + break; + } + ++p; + ++s; + } +} + +/* Main entry point. */ +int +lafe_pathmatch(const char *p, const char *s, int flags) +{ + /* Empty pattern only matches the empty string. */ + if (p == NULL || *p == '\0') + return (s == NULL || *s == '\0'); + + /* Leading '^' anchors the start of the pattern. */ + if (*p == '^') { + ++p; + flags &= ~PATHMATCH_NO_ANCHOR_START; + } + + if (*p == '/' && *s != '/') + return (0); + + /* Certain patterns and file names anchor implicitly. */ + if (*p == '*' || *p == '/' || *p == '/') { + while (*p == '/') + ++p; + while (*s == '/') + ++s; + return (pm(p, s, flags)); + } + + /* If start is unanchored, try to match start of each path element. */ + if (flags & PATHMATCH_NO_ANCHOR_START) { + for ( ; s != NULL; s = strchr(s, '/')) { + if (*s == '/') + s++; + if (pm(p, s, flags)) + return (1); + } + return (0); + } + + /* Default: Match from beginning. */ + return (pm(p, s, flags)); +} diff --git a/external/bsd/libarchive/dist/libarchive_fe/pathmatch.h b/external/bsd/libarchive/dist/libarchive_fe/pathmatch.h new file mode 100644 index 000000000..a92f3aef2 --- /dev/null +++ b/external/bsd/libarchive/dist/libarchive_fe/pathmatch.h @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef LAFE_PATHMATCH_H +#define LAFE_PATHMATCH_H + +/* Don't anchor at beginning unless the pattern starts with "^" */ +#define PATHMATCH_NO_ANCHOR_START 1 +/* Don't anchor at end unless the pattern ends with "$" */ +#define PATHMATCH_NO_ANCHOR_END 2 + +/* Note that "^" and "$" are not special unless you set the corresponding + * flag above. */ + +int lafe_pathmatch(const char *p, const char *s, int flags); + +#endif diff --git a/external/bsd/libarchive/dist/tar/bsdtar.1 b/external/bsd/libarchive/dist/tar/bsdtar.1 new file mode 100644 index 000000000..74fa1eac8 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/bsdtar.1 @@ -0,0 +1,921 @@ +.\" Copyright (c) 2003-2007 Tim Kientzle +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/usr.bin/tar/bsdtar.1,v 1.46 2008/12/06 07:37:55 kientzle Exp $ +.\" +.Dd Oct 12, 2009 +.Dt BSDTAR 1 +.Os +.Sh NAME +.Nm tar +.Nd manipulate tape archives +.Sh SYNOPSIS +.Nm +.Op Ar bundled-flags Ao args Ac +.Op Ao Ar file Ac | Ao Ar pattern Ac ... +.Nm +.Brq Fl c +.Op Ar options +.Op Ar files | Ar directories +.Nm +.Brq Fl r | Fl u +.Fl f Ar archive-file +.Op Ar options +.Op Ar files | Ar directories +.Nm +.Brq Fl t | Fl x +.Op Ar options +.Op Ar patterns +.Sh DESCRIPTION +.Nm +creates and manipulates streaming archive files. +This implementation can extract from tar, pax, cpio, zip, jar, ar, +and ISO 9660 cdrom images and can create tar, pax, cpio, ar, +and shar archives. +.Pp +The first synopsis form shows a +.Dq bundled +option word. +This usage is provided for compatibility with historical implementations. +See COMPATIBILITY below for details. +.Pp +The other synopsis forms show the preferred usage. +The first option to +.Nm +is a mode indicator from the following list: +.Bl -tag -compact -width indent +.It Fl c +Create a new archive containing the specified items. +.It Fl r +Like +.Fl c , +but new entries are appended to the archive. +Note that this only works on uncompressed archives stored in regular files. +The +.Fl f +option is required. +.It Fl t +List archive contents to stdout. +.It Fl u +Like +.Fl r , +but new entries are added only if they have a modification date +newer than the corresponding entry in the archive. +Note that this only works on uncompressed archives stored in regular files. +The +.Fl f +option is required. +.It Fl x +Extract to disk from the archive. +If a file with the same name appears more than once in the archive, +each copy will be extracted, with later copies overwriting (replacing) +earlier copies. +.El +.Pp +In +.Fl c , +.Fl r , +or +.Fl u +mode, each specified file or directory is added to the +archive in the order specified on the command line. +By default, the contents of each directory are also archived. +.Pp +In extract or list mode, the entire command line +is read and parsed before the archive is opened. +The pathnames or patterns on the command line indicate +which items in the archive should be processed. +Patterns are shell-style globbing patterns as +documented in +.Xr tcsh 1 . +.Sh OPTIONS +Unless specifically stated otherwise, options are applicable in +all operating modes. +.Bl -tag -width indent +.It Cm @ Ns Pa archive +(c and r mode only) +The specified archive is opened and the entries +in it will be appended to the current archive. +As a simple example, +.Dl Nm Fl c Fl f Pa - Pa newfile Cm @ Ns Pa original.tar +writes a new archive to standard output containing a file +.Pa newfile +and all of the entries from +.Pa original.tar . +In contrast, +.Dl Nm Fl c Fl f Pa - Pa newfile Pa original.tar +creates a new archive with only two entries. +Similarly, +.Dl Nm Fl czf Pa - Fl -format Cm pax Cm @ Ns Pa - +reads an archive from standard input (whose format will be determined +automatically) and converts it into a gzip-compressed +pax-format archive on stdout. +In this way, +.Nm +can be used to convert archives from one format to another. +.It Fl b Ar blocksize +Specify the block size, in 512-byte records, for tape drive I/O. +As a rule, this argument is only needed when reading from or writing +to tape drives, and usually not even then as the default block size of +20 records (10240 bytes) is very common. +.It Fl C Ar directory +In c and r mode, this changes the directory before adding +the following files. +In x mode, change directories after opening the archive +but before extracting entries from the archive. +.It Fl -check-links +(c and r modes only) +Issue a warning message unless all links to each file are archived. +.It Fl -chroot +(x mode only) +.Fn chroot +to the current directory after processing any +.Fl C +options and before extracting any files. +.It Fl -exclude Ar pattern +Do not process files or directories that match the +specified pattern. +Note that exclusions take precedence over patterns or filenames +specified on the command line. +.It Fl -format Ar format +(c, r, u mode only) +Use the specified format for the created archive. +Supported formats include +.Dq cpio , +.Dq pax , +.Dq shar , +and +.Dq ustar . +Other formats may also be supported; see +.Xr libarchive-formats 5 +for more information about currently-supported formats. +In r and u modes, when extending an existing archive, the format specified +here must be compatible with the format of the existing archive on disk. +.It Fl f Ar file +Read the archive from or write the archive to the specified file. +The filename can be +.Pa - +for standard input or standard output. +If not specified, the default tape device will be used. +(On +.Fx , +the default tape device is +.Pa /dev/sa0 . ) +.It Fl H +(c and r mode only) +Symbolic links named on the command line will be followed; the +target of the link will be archived, not the link itself. +.It Fl h +(c and r mode only) +Synonym for +.Fl L . +.It Fl I +Synonym for +.Fl T . +.It Fl -include Ar pattern +Process only files or directories that match the specified pattern. +Note that exclusions specified with +.Fl -exclude +take precedence over inclusions. +If no inclusions are explicitly specified, all entries are processed by +default. +The +.Fl -include +option is especially useful when filtering archives. +For example, the command +.Dl Nm Fl c Fl f Pa new.tar Fl -include='*foo*' Cm @ Ns Pa old.tgz +creates a new archive +.Pa new.tar +containing only the entries from +.Pa old.tgz +containing the string +.Sq foo . +.It Fl j +(c mode only) +Compress the resulting archive with +.Xr bzip2 1 . +In extract or list modes, this option is ignored. +Note that, unlike other +.Nm tar +implementations, this implementation recognizes bzip2 compression +automatically when reading archives. +.It Fl k +(x mode only) +Do not overwrite existing files. +In particular, if a file appears more than once in an archive, +later copies will not overwrite earlier copies. +.It Fl -keep-newer-files +(x mode only) +Do not overwrite existing files that are newer than the +versions appearing in the archive being extracted. +.It Fl L +(c and r mode only) +All symbolic links will be followed. +Normally, symbolic links are archived as such. +With this option, the target of the link will be archived instead. +.It Fl l +This is a synonym for the +.Fl -check-links +option. +.It Fl m +(x mode only) +Do not extract modification time. +By default, the modification time is set to the time stored in the archive. +.It Fl n +(c, r, u modes only) +Do not recursively archive the contents of directories. +.It Fl -newer Ar date +(c, r, u modes only) +Only include files and directories newer than the specified date. +This compares ctime entries. +.It Fl -newer-mtime Ar date +(c, r, u modes only) +Like +.Fl -newer , +except it compares mtime entries instead of ctime entries. +.It Fl -newer-than Pa file +(c, r, u modes only) +Only include files and directories newer than the specified file. +This compares ctime entries. +.It Fl -newer-mtime-than Pa file +(c, r, u modes only) +Like +.Fl -newer-than , +except it compares mtime entries instead of ctime entries. +.It Fl -nodump +(c and r modes only) +Honor the nodump file flag by skipping this file. +.It Fl -null +(use with +.Fl I , +.Fl T , +or +.Fl X ) +Filenames or patterns are separated by null characters, +not by newlines. +This is often used to read filenames output by the +.Fl print0 +option to +.Xr find 1 . +.It Fl -numeric-owner +(x mode only) +Ignore symbolic user and group names when restoring archives to disk, +only numeric uid and gid values will be obeyed. +.It Fl O +(x, t modes only) +In extract (-x) mode, files will be written to standard out rather than +being extracted to disk. +In list (-t) mode, the file listing will be written to stderr rather than +the usual stdout. +.It Fl o +(x mode) +Use the user and group of the user running the program rather +than those specified in the archive. +Note that this has no significance unless +.Fl p +is specified, and the program is being run by the root user. +In this case, the file modes and flags from +the archive will be restored, but ACLs or owner information in +the archive will be discarded. +.It Fl o +(c, r, u mode) +A synonym for +.Fl -format Ar ustar +.It Fl -one-file-system +(c, r, and u modes) +Do not cross mount points. +.It Fl -options Ar options +Select optional behaviors for particular modules. +The argument is a text string containing comma-separated +keywords and values. +These are passed to the modules that handle particular +formats to control how those formats will behave. +Each option has one of the following forms: +.Bl -tag -compact -width indent +.It Ar key=value +The key will be set to the specified value in every module that supports it. +Modules that do not support this key will ignore it. +.It Ar key +The key will be enabled in every module that supports it. +This is equivalent to +.Ar key Ns Cm =1 . +.It Ar !key +The key will be disabled in every module that supports it. +.It Ar module:key=value , Ar module:key , Ar module:!key +As above, but the corresponding key and value will be provided +only to modules whose name matches +.Ar module . +.El +The currently supported modules and keys are: +.Bl -tag -compact -width indent +.It Cm iso9660:joliet +Support Joliet extensions. +This is enabled by default, use +.Cm !joliet +or +.Cm iso9660:!joliet +to disable. +.It Cm iso9660:rockridge +Support Rock Ridge extensions. +This is enabled by default, use +.Cm !rockridge +or +.Cm iso9660:!rockridge +to disable. +.It Cm gzip:compression-level +A decimal integer from 0 to 9 specifying the gzip compression level. +.It Cm xz:compression-level +A decimal integer from 0 to 9 specifying the xz compression level. +.It Cm mtree: Ns Ar keyword +The mtree writer module allows you to specify which mtree keywords +will be included in the output. +Supported keywords include: +.Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent , +.Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 , +.Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname . +The default is equivalent to: +.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname . +.It Cm mtree:all +Enables all of the above keywords. +You can also use +.Cm mtree:!all +to disable all keywords. +.It Cm mtree:use-set +Enable generation of +.Cm /set +lines in the output. +.It Cm mtree:indent +Produce human-readable output by indenting options and splitting lines +to fit into 80 columns. +.It Cm zip:compression Ns = Ns Ar type +Use +.Ar type +as compression method. +Supported values are store (uncompressed) and deflate (gzip algorithm). +.El +If a provided option is not supported by any module, that +is a fatal error. +.It Fl P +Preserve pathnames. +By default, absolute pathnames (those that begin with a / +character) have the leading slash removed both when creating archives +and extracting from them. +Also, +.Nm +will refuse to extract archive entries whose pathnames contain +.Pa .. +or whose target directory would be altered by a symlink. +This option suppresses these behaviors. +.It Fl p +(x mode only) +Preserve file permissions. +Attempt to restore the full permissions, including owner, file modes, file +flags and ACLs, if available, for each item extracted from the archive. +By default, newly-created files are owned by the user running +.Nm , +the file mode is restored for newly-created regular files, and +all other types of entries receive default permissions. +If +.Nm +is being run by root, the default is to restore the owner unless the +.Fl o +option is also specified. +.It Fl q ( Fl -fast-read ) +(x and t mode only) +Extract or list only the first archive entry that matches each pattern +or filename operand. +Exit as soon as each specified pattern or filename has been matched. +By default, the archive is always read to the very end, since +there can be multiple entries with the same name and, by convention, +later entries overwrite earlier entries. +This option is provided as a performance optimization. +.It Fl S +(x mode only) +Extract files as sparse files. +For every block on disk, check first if it contains only NULL bytes and seek +over it otherwise. +This works similiar to the conv=sparse option of dd. +.It Fl -strip-components Ar count +(x mode only) +Remove the specified number of leading path elements. +Pathnames with fewer elements will be silently skipped. +Note that the pathname is edited after checking inclusion/exclusion patterns +but before security checks. +.It Fl s Ar pattern +Modify file or archive member names according to +.Pa pattern . +The pattern has the format +.Ar /old/new/ Ns Op gps +where +.Ar old +is a basic regular expression, +.Ar new +is the replacement string of the matched part, +and the optional trailing letters modify +how the replacement is handled. +If +.Ar old +is not matched, the pattern is skipped. +Within +.Ar new , +~ is substituted with the match, \e1 to \e9 with the content of +the corresponding captured group. +The optional trailing g specifies that matching should continue +after the matched part and stopped on the first unmatched pattern. +The optional trailing s specifies that the pattern applies to the value +of symbolic links. +The optional trailing p specifies that after a successful substitution +the original path name and the new path name should be printed to +standard error. +.It Fl T Ar filename +In x or t mode, +.Nm +will read the list of names to be extracted from +.Pa filename . +In c mode, +.Nm +will read names to be archived from +.Pa filename . +The special name +.Dq -C +on a line by itself will cause the current directory to be changed to +the directory specified on the following line. +Names are terminated by newlines unless +.Fl -null +is specified. +Note that +.Fl -null +also disables the special handling of lines containing +.Dq -C . +.It Fl U +(x mode only) +Unlink files before creating them. +Without this option, +.Nm +overwrites existing files, which preserves existing hardlinks. +With this option, existing hardlinks will be broken, as will any +symlink that would affect the location of an extracted file. +.It Fl -use-compress-program Ar program +Pipe the input (in x or t mode) or the output (in c mode) through +.Pa program +instead of using the builtin compression support. +.It Fl v +Produce verbose output. +In create and extract modes, +.Nm +will list each file name as it is read from or written to +the archive. +In list mode, +.Nm +will produce output similar to that of +.Xr ls 1 . +Additional +.Fl v +options will provide additional detail. +.It Fl -version +Print version of +.Nm +and +.Nm libarchive , +and exit. +.It Fl w +Ask for confirmation for every action. +.It Fl X Ar filename +Read a list of exclusion patterns from the specified file. +See +.Fl -exclude +for more information about the handling of exclusions. +.It Fl y +(c mode only) +Compress the resulting archive with +.Xr bzip2 1 . +In extract or list modes, this option is ignored. +Note that, unlike other +.Nm tar +implementations, this implementation recognizes bzip2 compression +automatically when reading archives. +.It Fl z +(c mode only) +Compress the resulting archive with +.Xr gzip 1 . +In extract or list modes, this option is ignored. +Note that, unlike other +.Nm tar +implementations, this implementation recognizes gzip compression +automatically when reading archives. +.It Fl Z +(c mode only) +Compress the resulting archive with +.Xr compress 1 . +In extract or list modes, this option is ignored. +Note that, unlike other +.Nm tar +implementations, this implementation recognizes compress compression +automatically when reading archives. +.El +.Sh EXIT STATUS +.Ex -std +.Sh ENVIRONMENT +The following environment variables affect the execution of +.Nm : +.Bl -tag -width ".Ev BLOCKSIZE" +.It Ev LANG +The locale to use. +See +.Xr environ 7 +for more information. +.It Ev TAPE +The default tape device. +The +.Fl f +option overrides this. +.It Ev TZ +The timezone to use when displaying dates. +See +.Xr environ 7 +for more information. +.El +.Sh FILES +.Bl -tag -width ".Ev BLOCKSIZE" +.It Pa /dev/sa0 +The default tape device, if not overridden by the +.Ev TAPE +environment variable or the +.Fl f +option. +.El +.Sh EXAMPLES +The following creates a new archive +called +.Ar file.tar.gz +that contains two files +.Ar source.c +and +.Ar source.h : +.Dl Nm Fl czf Pa file.tar.gz Pa source.c Pa source.h +.Pp +To view a detailed table of contents for this +archive: +.Dl Nm Fl tvf Pa file.tar.gz +.Pp +To extract all entries from the archive on +the default tape drive: +.Dl Nm Fl x +.Pp +To examine the contents of an ISO 9660 cdrom image: +.Dl Nm Fl tf Pa image.iso +.Pp +To move file hierarchies, invoke +.Nm +as +.Dl Nm Fl cf Pa - Fl C Pa srcdir\ . | Nm Fl xpf Pa - Fl C Pa destdir +or more traditionally +.Dl cd srcdir \&; Nm Fl cf Pa -\ . | ( cd destdir \&; Nm Fl xpf Pa - ) +.Pp +In create mode, the list of files and directories to be archived +can also include directory change instructions of the form +.Cm -C Ns Pa foo/baz +and archive inclusions of the form +.Cm @ Ns Pa archive-file . +For example, the command line +.Dl Nm Fl c Fl f Pa new.tar Pa foo1 Cm @ Ns Pa old.tgz Cm -C Ns Pa /tmp Pa foo2 +will create a new archive +.Pa new.tar . +.Nm +will read the file +.Pa foo1 +from the current directory and add it to the output archive. +It will then read each entry from +.Pa old.tgz +and add those entries to the output archive. +Finally, it will switch to the +.Pa /tmp +directory and add +.Pa foo2 +to the output archive. +.Pp +An input file in +.Xr mtree 5 +format can be used to create an output archive with arbitrary ownership, +permissions, or names that differ from existing data on disk: +.Pp +.Dl $ cat input.mtree +.Dl #mtree +.Dl usr/bin uid=0 gid=0 mode=0755 type=dir +.Dl usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls +.Dl $ tar -cvf output.tar @input.mtree +.Pp +The +.Fl -newer +and +.Fl -newer-mtime +switches accept a variety of common date and time specifications, including +.Dq 12 Mar 2005 7:14:29pm , +.Dq 2005-03-12 19:14 , +.Dq 5 minutes ago , +and +.Dq 19:14 PST May 1 . +.Pp +The +.Fl -options +argument can be used to control various details of archive generation +or reading. +For example, you can generate mtree output which only contains +.Cm type , Cm time , +and +.Cm uid +keywords: +.Dl Nm Fl cf Pa file.tar Fl -format=mtree Fl -options='!all,type,time,uid' Pa dir +or you can set the compression level used by gzip or xz compression: +.Dl Nm Fl czf Pa file.tar Fl -options='compression-level=9' . +For more details, see the explanation of the +.Fn archive_read_set_options +and +.Fn archive_write_set_options +API calls that are described in +.Xr archive_read 3 +and +.Xr archive_write 3 . +.Sh COMPATIBILITY +The bundled-arguments format is supported for compatibility +with historic implementations. +It consists of an initial word (with no leading - character) in which +each character indicates an option. +Arguments follow as separate words. +The order of the arguments must match the order +of the corresponding characters in the bundled command word. +For example, +.Dl Nm Cm tbf 32 Pa file.tar +specifies three flags +.Cm t , +.Cm b , +and +.Cm f . +The +.Cm b +and +.Cm f +flags both require arguments, +so there must be two additional items +on the command line. +The +.Ar 32 +is the argument to the +.Cm b +flag, and +.Ar file.tar +is the argument to the +.Cm f +flag. +.Pp +The mode options c, r, t, u, and x and the options +b, f, l, m, o, v, and w comply with SUSv2. +.Pp +For maximum portability, scripts that invoke +.Nm tar +should use the bundled-argument format above, should limit +themselves to the +.Cm c , +.Cm t , +and +.Cm x +modes, and the +.Cm b , +.Cm f , +.Cm m , +.Cm v , +and +.Cm w +options. +.Pp +Additional long options are provided to improve compatibility with other +tar implementations. +.Sh SECURITY +Certain security issues are common to many archiving programs, including +.Nm . +In particular, carefully-crafted archives can request that +.Nm +extract files to locations outside of the target directory. +This can potentially be used to cause unwitting users to overwrite +files they did not intend to overwrite. +If the archive is being extracted by the superuser, any file +on the system can potentially be overwritten. +There are three ways this can happen. +Although +.Nm +has mechanisms to protect against each one, +savvy users should be aware of the implications: +.Bl -bullet -width indent +.It +Archive entries can have absolute pathnames. +By default, +.Nm +removes the leading +.Pa / +character from filenames before restoring them to guard against this problem. +.It +Archive entries can have pathnames that include +.Pa .. +components. +By default, +.Nm +will not extract files containing +.Pa .. +components in their pathname. +.It +Archive entries can exploit symbolic links to restore +files to other directories. +An archive can restore a symbolic link to another directory, +then use that link to restore a file into that directory. +To guard against this, +.Nm +checks each extracted path for symlinks. +If the final path element is a symlink, it will be removed +and replaced with the archive entry. +If +.Fl U +is specified, any intermediate symlink will also be unconditionally removed. +If neither +.Fl U +nor +.Fl P +is specified, +.Nm +will refuse to extract the entry. +.El +To protect yourself, you should be wary of any archives that +come from untrusted sources. +You should examine the contents of an archive with +.Dl Nm Fl tf Pa filename +before extraction. +You should use the +.Fl k +option to ensure that +.Nm +will not overwrite any existing files or the +.Fl U +option to remove any pre-existing files. +You should generally not extract archives while running with super-user +privileges. +Note that the +.Fl P +option to +.Nm +disables the security checks above and allows you to extract +an archive while preserving any absolute pathnames, +.Pa .. +components, or symlinks to other directories. +.Sh SEE ALSO +.Xr bzip2 1 , +.Xr compress 1 , +.Xr cpio 1 , +.Xr gzip 1 , +.Xr mt 1 , +.Xr pax 1 , +.Xr shar 1 , +.Xr libarchive 3 , +.Xr libarchive-formats 5 , +.Xr tar 5 +.Sh STANDARDS +There is no current POSIX standard for the tar command; it appeared +in +.St -p1003.1-96 +but was dropped from +.St -p1003.1-2001 . +The options used by this implementation were developed by surveying a +number of existing tar implementations as well as the old POSIX specification +for tar and the current POSIX specification for pax. +.Pp +The ustar and pax interchange file formats are defined by +.St -p1003.1-2001 +for the pax command. +.Sh HISTORY +A +.Nm tar +command appeared in Seventh Edition Unix, which was released in January, 1979. +There have been numerous other implementations, +many of which extended the file format. +John Gilmore's +.Nm pdtar +public-domain implementation (circa November, 1987) +was quite influential, and formed the basis of GNU tar. +GNU tar was included as the standard system tar +in +.Fx +beginning with +.Fx 1.0 . +.Pp +This is a complete re-implementation based on the +.Xr libarchive 3 +library. +.Sh BUGS +This program follows +.St -p1003.1-96 +for the definition of the +.Fl l +option. +Note that GNU tar prior to version 1.15 treated +.Fl l +as a synonym for the +.Fl -one-file-system +option. +.Pp +The +.Fl C Pa dir +option may differ from historic implementations. +.Pp +All archive output is written in correctly-sized blocks, even +if the output is being compressed. +Whether or not the last output block is padded to a full +block size varies depending on the format and the +output device. +For tar and cpio formats, the last block of output is padded +to a full block size if the output is being +written to standard output or to a character or block device such as +a tape drive. +If the output is being written to a regular file, the last block +will not be padded. +Many compressors, including +.Xr gzip 1 +and +.Xr bzip2 1 , +complain about the null padding when decompressing an archive created by +.Nm , +although they still extract it correctly. +.Pp +The compression and decompression is implemented internally, so +there may be insignificant differences between the compressed output +generated by +.Dl Nm Fl czf Pa - file +and that generated by +.Dl Nm Fl cf Pa - file | Nm gzip +.Pp +The default should be to read and write archives to the standard I/O paths, +but tradition (and POSIX) dictates otherwise. +.Pp +The +.Cm r +and +.Cm u +modes require that the archive be uncompressed +and located in a regular file on disk. +Other archives can be modified using +.Cm c +mode with the +.Pa @archive-file +extension. +.Pp +To archive a file called +.Pa @foo +or +.Pa -foo +you must specify it as +.Pa ./@foo +or +.Pa ./-foo , +respectively. +.Pp +In create mode, a leading +.Pa ./ +is always removed. +A leading +.Pa / +is stripped unless the +.Fl P +option is specified. +.Pp +There needs to be better support for file selection on both create +and extract. +.Pp +There is not yet any support for multi-volume archives or for archiving +sparse files. +.Pp +Converting between dissimilar archive formats (such as tar and cpio) using the +.Cm @ Ns Pa - +convention can cause hard link information to be lost. +(This is a consequence of the incompatible ways that different archive +formats store hardlink information.) +.Pp +There are alternative long options for many of the short options that +are deliberately not documented. diff --git a/external/bsd/libarchive/dist/tar/bsdtar.c b/external/bsd/libarchive/dist/tar/bsdtar.c new file mode 100644 index 000000000..d8f828684 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/bsdtar.c @@ -0,0 +1,734 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "bsdtar_platform.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/bsdtar.c,v 1.93 2008/11/08 04:43:24 kientzle Exp $"); + +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_LANGINFO_H +#include +#endif +#ifdef HAVE_LOCALE_H +#include +#endif +#ifdef HAVE_PATHS_H +#include +#endif +#ifdef HAVE_SIGNAL_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_TIME_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#if HAVE_ZLIB_H +#include +#endif + +#include "bsdtar.h" +#include "err.h" + +/* + * Per POSIX.1-1988, tar defaults to reading/writing archives to/from + * the default tape device for the system. Pick something reasonable here. + */ +#ifdef __linux +#define _PATH_DEFTAPE "/dev/st0" +#endif +#if defined(_WIN32) && !defined(__CYGWIN__) +#define _PATH_DEFTAPE "\\\\.\\tape0" +#endif + +#ifndef _PATH_DEFTAPE +#define _PATH_DEFTAPE "/dev/tape" +#endif + +#ifdef __MINGW32__ +int _CRT_glob = 0; /* Disable broken CRT globbing. */ +#endif + +static struct bsdtar *_bsdtar; + +#if defined(HAVE_SIGACTION) && (defined(SIGINFO) || defined(SIGUSR1)) +static volatile int siginfo_occurred; + +static void +siginfo_handler(int sig) +{ + (void)sig; /* UNUSED */ + siginfo_occurred = 1; +} + +int +need_report(void) +{ + int r = siginfo_occurred; + siginfo_occurred = 0; + return (r); +} +#else +int +need_report(void) +{ + return (0); +} +#endif + +/* External function to parse a date/time string */ +time_t get_date(time_t, const char *); + +static void long_help(void); +static void only_mode(struct bsdtar *, const char *opt, + const char *valid); +static void set_mode(struct bsdtar *, char opt); +static void version(void); + +/* A basic set of security flags to request from libarchive. */ +#define SECURITY \ + (ARCHIVE_EXTRACT_SECURE_SYMLINKS \ + | ARCHIVE_EXTRACT_SECURE_NODOTDOT) + +int +main(int argc, char **argv) +{ + struct bsdtar *bsdtar, bsdtar_storage; + int opt, t; + char option_o; + char possible_help_request; + char buff[16]; + time_t now; + + /* + * Use a pointer for consistency, but stack-allocated storage + * for ease of cleanup. + */ + _bsdtar = bsdtar = &bsdtar_storage; + memset(bsdtar, 0, sizeof(*bsdtar)); + bsdtar->fd = -1; /* Mark as "unused" */ + option_o = 0; + +#if defined(HAVE_SIGACTION) && (defined(SIGINFO) || defined(SIGUSR1)) + { /* Catch SIGINFO and SIGUSR1, if they exist. */ + struct sigaction sa; + sa.sa_handler = siginfo_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; +#ifdef SIGINFO + if (sigaction(SIGINFO, &sa, NULL)) + lafe_errc(1, errno, "sigaction(SIGINFO) failed"); +#endif +#ifdef SIGUSR1 + /* ... and treat SIGUSR1 the same way as SIGINFO. */ + if (sigaction(SIGUSR1, &sa, NULL)) + lafe_errc(1, errno, "sigaction(SIGUSR1) failed"); +#endif + } +#endif + + + /* Need lafe_progname before calling lafe_warnc. */ + if (*argv == NULL) + lafe_progname = "bsdtar"; + else { +#if defined(_WIN32) && !defined(__CYGWIN__) + lafe_progname = strrchr(*argv, '\\'); +#else + lafe_progname = strrchr(*argv, '/'); +#endif + if (lafe_progname != NULL) + lafe_progname++; + else + lafe_progname = *argv; + } + + time(&now); + +#if HAVE_SETLOCALE + if (setlocale(LC_ALL, "") == NULL) + lafe_warnc(0, "Failed to set default locale"); +#endif +#if defined(HAVE_NL_LANGINFO) && defined(HAVE_D_MD_ORDER) + bsdtar->day_first = (*nl_langinfo(D_MD_ORDER) == 'd'); +#endif + possible_help_request = 0; + + /* Look up uid of current user for future reference */ + bsdtar->user_uid = geteuid(); + + /* Default: open tape drive. */ + bsdtar->filename = getenv("TAPE"); + if (bsdtar->filename == NULL) + bsdtar->filename = _PATH_DEFTAPE; + + /* Default: preserve mod time on extract */ + bsdtar->extract_flags = ARCHIVE_EXTRACT_TIME; + + /* Default: Perform basic security checks. */ + bsdtar->extract_flags |= SECURITY; + +#ifndef _WIN32 + /* On POSIX systems, assume --same-owner and -p when run by + * the root user. This doesn't make any sense on Windows. */ + if (bsdtar->user_uid == 0) { + /* --same-owner */ + bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER; + /* -p */ + bsdtar->extract_flags |= ARCHIVE_EXTRACT_PERM; + bsdtar->extract_flags |= ARCHIVE_EXTRACT_ACL; + bsdtar->extract_flags |= ARCHIVE_EXTRACT_XATTR; + bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; + } +#endif + + bsdtar->argv = argv; + bsdtar->argc = argc; + + /* + * Comments following each option indicate where that option + * originated: SUSv2, POSIX, GNU tar, star, etc. If there's + * no such comment, then I don't know of anyone else who + * implements that option. + */ + while ((opt = bsdtar_getopt(bsdtar)) != -1) { + switch (opt) { + case 'B': /* GNU tar */ + /* libarchive doesn't need this; just ignore it. */ + break; + case 'b': /* SUSv2 */ + t = atoi(bsdtar->optarg); + if (t <= 0 || t > 8192) + lafe_errc(1, 0, + "Argument to -b is out of range (1..8192)"); + bsdtar->bytes_per_block = 512 * t; + break; + case 'C': /* GNU tar */ + set_chdir(bsdtar, bsdtar->optarg); + break; + case 'c': /* SUSv2 */ + set_mode(bsdtar, opt); + break; + case OPTION_CHECK_LINKS: /* GNU tar */ + bsdtar->option_warn_links = 1; + break; + case OPTION_CHROOT: /* NetBSD */ + bsdtar->option_chroot = 1; + break; + case OPTION_EXCLUDE: /* GNU tar */ + if (lafe_exclude(&bsdtar->matching, bsdtar->optarg)) + lafe_errc(1, 0, + "Couldn't exclude %s\n", bsdtar->optarg); + break; + case OPTION_FORMAT: /* GNU tar, others */ + bsdtar->create_format = bsdtar->optarg; + break; + case OPTION_OPTIONS: + bsdtar->option_options = bsdtar->optarg; + break; + case 'f': /* SUSv2 */ + bsdtar->filename = bsdtar->optarg; + if (strcmp(bsdtar->filename, "-") == 0) + bsdtar->filename = NULL; + break; + case 'H': /* BSD convention */ + bsdtar->symlink_mode = 'H'; + break; + case 'h': /* Linux Standards Base, gtar; synonym for -L */ + bsdtar->symlink_mode = 'L'; + /* Hack: -h by itself is the "help" command. */ + possible_help_request = 1; + break; + case OPTION_HELP: /* GNU tar, others */ + long_help(); + exit(0); + break; + case 'I': /* GNU tar */ + /* + * TODO: Allow 'names' to come from an archive, + * not just a text file. Design a good UI for + * allowing names and mode/owner to be read + * from an archive, with contents coming from + * disk. This can be used to "refresh" an + * archive or to design archives with special + * permissions without having to create those + * permissions on disk. + */ + bsdtar->names_from_file = bsdtar->optarg; + break; + case OPTION_INCLUDE: + /* + * Noone else has the @archive extension, so + * noone else needs this to filter entries + * when transforming archives. + */ + if (lafe_include(&bsdtar->matching, bsdtar->optarg)) + lafe_errc(1, 0, + "Failed to add %s to inclusion list", + bsdtar->optarg); + break; + case 'j': /* GNU tar */ + if (bsdtar->create_compression != '\0') + lafe_errc(1, 0, + "Can't specify both -%c and -%c", opt, + bsdtar->create_compression); + bsdtar->create_compression = opt; + break; + case 'J': /* GNU tar 1.21 and later */ + if (bsdtar->create_compression != '\0') + lafe_errc(1, 0, + "Can't specify both -%c and -%c", opt, + bsdtar->create_compression); + bsdtar->create_compression = opt; + break; + case 'k': /* GNU tar */ + bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE; + break; + case OPTION_KEEP_NEWER_FILES: /* GNU tar */ + bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; + break; + case 'L': /* BSD convention */ + bsdtar->symlink_mode = 'L'; + break; + case 'l': /* SUSv2 and GNU tar beginning with 1.16 */ + /* GNU tar 1.13 used -l for --one-file-system */ + bsdtar->option_warn_links = 1; + break; + case OPTION_LZMA: + if (bsdtar->create_compression != '\0') + lafe_errc(1, 0, + "Can't specify both -%c and -%c", opt, + bsdtar->create_compression); + bsdtar->create_compression = opt; + break; + case 'm': /* SUSv2 */ + bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_TIME; + break; + case 'n': /* GNU tar */ + bsdtar->option_no_subdirs = 1; + break; + /* + * Selecting files by time: + * --newer-?time='date' Only files newer than 'date' + * --newer-?time-than='file' Only files newer than time + * on specified file (useful for incremental backups) + * TODO: Add corresponding "older" options to reverse these. + */ + case OPTION_NEWER_CTIME: /* GNU tar */ + bsdtar->newer_ctime_sec = get_date(now, bsdtar->optarg); + break; + case OPTION_NEWER_CTIME_THAN: + { + struct stat st; + if (stat(bsdtar->optarg, &st) != 0) + lafe_errc(1, 0, + "Can't open file %s", bsdtar->optarg); + bsdtar->newer_ctime_sec = st.st_ctime; + bsdtar->newer_ctime_nsec = + ARCHIVE_STAT_CTIME_NANOS(&st); + } + break; + case OPTION_NEWER_MTIME: /* GNU tar */ + bsdtar->newer_mtime_sec = get_date(now, bsdtar->optarg); + break; + case OPTION_NEWER_MTIME_THAN: + { + struct stat st; + if (stat(bsdtar->optarg, &st) != 0) + lafe_errc(1, 0, + "Can't open file %s", bsdtar->optarg); + bsdtar->newer_mtime_sec = st.st_mtime; + bsdtar->newer_mtime_nsec = + ARCHIVE_STAT_MTIME_NANOS(&st); + } + break; + case OPTION_NODUMP: /* star */ + bsdtar->option_honor_nodump = 1; + break; + case OPTION_NO_SAME_OWNER: /* GNU tar */ + bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; + break; + case OPTION_NO_SAME_PERMISSIONS: /* GNU tar */ + bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_PERM; + bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_ACL; + bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_XATTR; + bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_FFLAGS; + break; + case OPTION_NULL: /* GNU tar */ + bsdtar->option_null++; + break; + case OPTION_NUMERIC_OWNER: /* GNU tar */ + bsdtar->option_numeric_owner++; + break; + case 'O': /* GNU tar */ + bsdtar->option_stdout = 1; + break; + case 'o': /* SUSv2 and GNU conflict here, but not fatally */ + option_o = 1; /* Record it and resolve it later. */ + break; + case OPTION_ONE_FILE_SYSTEM: /* GNU tar */ + bsdtar->option_dont_traverse_mounts = 1; + break; +#if 0 + /* + * The common BSD -P option is not necessary, since + * our default is to archive symlinks, not follow + * them. This is convenient, as -P conflicts with GNU + * tar anyway. + */ + case 'P': /* BSD convention */ + /* Default behavior, no option necessary. */ + break; +#endif + case 'P': /* GNU tar */ + bsdtar->extract_flags &= ~SECURITY; + bsdtar->option_absolute_paths = 1; + break; + case 'p': /* GNU tar, star */ + bsdtar->extract_flags |= ARCHIVE_EXTRACT_PERM; + bsdtar->extract_flags |= ARCHIVE_EXTRACT_ACL; + bsdtar->extract_flags |= ARCHIVE_EXTRACT_XATTR; + bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; + break; + case OPTION_POSIX: /* GNU tar */ + bsdtar->create_format = "pax"; + break; + case 'q': /* FreeBSD GNU tar --fast-read, NetBSD -q */ + bsdtar->option_fast_read = 1; + break; + case 'r': /* SUSv2 */ + set_mode(bsdtar, opt); + break; + case 'S': /* NetBSD pax-as-tar */ + bsdtar->extract_flags |= ARCHIVE_EXTRACT_SPARSE; + break; + case 's': /* NetBSD pax-as-tar */ +#if HAVE_REGEX_H + add_substitution(bsdtar, bsdtar->optarg); +#else + lafe_warnc(0, + "-s is not supported by this version of bsdtar"); + usage(); +#endif + break; + case OPTION_SAME_OWNER: /* GNU tar */ + bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER; + break; + case OPTION_STRIP_COMPONENTS: /* GNU tar 1.15 */ + bsdtar->strip_components = atoi(bsdtar->optarg); + break; + case 'T': /* GNU tar */ + bsdtar->names_from_file = bsdtar->optarg; + break; + case 't': /* SUSv2 */ + set_mode(bsdtar, opt); + bsdtar->verbose++; + break; + case OPTION_TOTALS: /* GNU tar */ + bsdtar->option_totals++; + break; + case 'U': /* GNU tar */ + bsdtar->extract_flags |= ARCHIVE_EXTRACT_UNLINK; + bsdtar->option_unlink_first = 1; + break; + case 'u': /* SUSv2 */ + set_mode(bsdtar, opt); + break; + case 'v': /* SUSv2 */ + bsdtar->verbose++; + break; + case OPTION_VERSION: /* GNU convention */ + version(); + break; +#if 0 + /* + * The -W longopt feature is handled inside of + * bsdtar_getopt(), so -W is not available here. + */ + case 'W': /* Obscure GNU convention. */ + break; +#endif + case 'w': /* SUSv2 */ + bsdtar->option_interactive = 1; + break; + case 'X': /* GNU tar */ + if (lafe_exclude_from_file(&bsdtar->matching, bsdtar->optarg)) + lafe_errc(1, 0, + "failed to process exclusions from file %s", + bsdtar->optarg); + break; + case 'x': /* SUSv2 */ + set_mode(bsdtar, opt); + break; + case 'y': /* FreeBSD version of GNU tar */ + if (bsdtar->create_compression != '\0') + lafe_errc(1, 0, + "Can't specify both -%c and -%c", opt, + bsdtar->create_compression); + bsdtar->create_compression = opt; + break; + case 'Z': /* GNU tar */ + if (bsdtar->create_compression != '\0') + lafe_errc(1, 0, + "Can't specify both -%c and -%c", opt, + bsdtar->create_compression); + bsdtar->create_compression = opt; + break; + case 'z': /* GNU tar, star, many others */ + if (bsdtar->create_compression != '\0') + lafe_errc(1, 0, + "Can't specify both -%c and -%c", opt, + bsdtar->create_compression); + bsdtar->create_compression = opt; + break; + case OPTION_USE_COMPRESS_PROGRAM: + bsdtar->compress_program = bsdtar->optarg; + break; + default: + usage(); + } + } + + /* + * Sanity-check options. + */ + + /* If no "real" mode was specified, treat -h as --help. */ + if ((bsdtar->mode == '\0') && possible_help_request) { + long_help(); + exit(0); + } + + /* Otherwise, a mode is required. */ + if (bsdtar->mode == '\0') + lafe_errc(1, 0, + "Must specify one of -c, -r, -t, -u, -x"); + + /* Check boolean options only permitted in certain modes. */ + if (bsdtar->option_dont_traverse_mounts) + only_mode(bsdtar, "--one-file-system", "cru"); + if (bsdtar->option_fast_read) + only_mode(bsdtar, "--fast-read", "xt"); + if (bsdtar->option_honor_nodump) + only_mode(bsdtar, "--nodump", "cru"); + if (option_o > 0) { + switch (bsdtar->mode) { + case 'c': + /* + * In GNU tar, -o means "old format." The + * "ustar" format is the closest thing + * supported by libarchive. + */ + bsdtar->create_format = "ustar"; + /* TODO: bsdtar->create_format = "v7"; */ + break; + case 'x': + /* POSIX-compatible behavior. */ + bsdtar->option_no_owner = 1; + bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; + break; + default: + only_mode(bsdtar, "-o", "xc"); + break; + } + } + if (bsdtar->option_no_subdirs) + only_mode(bsdtar, "-n", "cru"); + if (bsdtar->option_stdout) + only_mode(bsdtar, "-O", "xt"); + if (bsdtar->option_unlink_first) + only_mode(bsdtar, "-U", "x"); + if (bsdtar->option_warn_links) + only_mode(bsdtar, "--check-links", "cr"); + + /* Check other parameters only permitted in certain modes. */ + if (bsdtar->create_compression != '\0') { + strcpy(buff, "-?"); + buff[1] = bsdtar->create_compression; + only_mode(bsdtar, buff, "cxt"); + } + if (bsdtar->create_format != NULL) + only_mode(bsdtar, "--format", "cru"); + if (bsdtar->symlink_mode != '\0') { + strcpy(buff, "-?"); + buff[1] = bsdtar->symlink_mode; + only_mode(bsdtar, buff, "cru"); + } + if (bsdtar->strip_components != 0) + only_mode(bsdtar, "--strip-components", "xt"); + + switch(bsdtar->mode) { + case 'c': + tar_mode_c(bsdtar); + break; + case 'r': + tar_mode_r(bsdtar); + break; + case 't': + tar_mode_t(bsdtar); + break; + case 'u': + tar_mode_u(bsdtar); + break; + case 'x': + tar_mode_x(bsdtar); + break; + } + + lafe_cleanup_exclusions(&bsdtar->matching); +#if HAVE_REGEX_H + cleanup_substitution(bsdtar); +#endif + + if (bsdtar->return_value != 0) + lafe_warnc(0, + "Error exit delayed from previous errors."); + return (bsdtar->return_value); +} + +static void +set_mode(struct bsdtar *bsdtar, char opt) +{ + if (bsdtar->mode != '\0' && bsdtar->mode != opt) + lafe_errc(1, 0, + "Can't specify both -%c and -%c", opt, bsdtar->mode); + bsdtar->mode = opt; +} + +/* + * Verify that the mode is correct. + */ +static void +only_mode(struct bsdtar *bsdtar, const char *opt, const char *valid_modes) +{ + if (strchr(valid_modes, bsdtar->mode) == NULL) + lafe_errc(1, 0, + "Option %s is not permitted in mode -%c", + opt, bsdtar->mode); +} + + +void +usage(void) +{ + const char *p; + + p = lafe_progname; + + fprintf(stderr, "Usage:\n"); + fprintf(stderr, " List: %s -tf \n", p); + fprintf(stderr, " Extract: %s -xf \n", p); + fprintf(stderr, " Create: %s -cf [filenames...]\n", p); + fprintf(stderr, " Help: %s --help\n", p); + exit(1); +} + +static void +version(void) +{ + printf("bsdtar %s - %s\n", + BSDTAR_VERSION_STRING, + archive_version()); + exit(0); +} + +static const char *long_help_msg = + "First option must be a mode specifier:\n" + " -c Create -r Add/Replace -t List -u Update -x Extract\n" + "Common Options:\n" + " -b # Use # 512-byte records per I/O block\n" + " -f Location of archive (default " _PATH_DEFTAPE ")\n" + " -v Verbose\n" + " -w Interactive\n" + "Create: %p -c [options] [ | | @ | -C ]\n" + " , add these items to archive\n" + " -z, -j, -J, --lzma Compress archive with gzip/bzip2/xz/lzma\n" + " --format {ustar|pax|cpio|shar} Select archive format\n" + " --exclude Skip files that match pattern\n" + " -C Change to before processing remaining files\n" + " @ Add entries from to output\n" + "List: %p -t [options] []\n" + " If specified, list only entries that match\n" + "Extract: %p -x [options] []\n" + " If specified, extract only entries that match\n" + " -k Keep (don't overwrite) existing files\n" + " -m Don't restore modification times\n" + " -O Write entries to stdout, don't restore to disk\n" + " -p Restore permissions (including ACLs, owner, file flags)\n"; + + +/* + * Note that the word 'bsdtar' will always appear in the first line + * of output. + * + * In particular, /bin/sh scripts that need to test for the presence + * of bsdtar can use the following template: + * + * if (tar --help 2>&1 | grep bsdtar >/dev/null 2>&1 ) then \ + * echo bsdtar; else echo not bsdtar; fi + */ +static void +long_help(void) +{ + const char *prog; + const char *p; + + prog = lafe_progname; + + fflush(stderr); + + p = (strcmp(prog,"bsdtar") != 0) ? "(bsdtar)" : ""; + printf("%s%s: manipulate archive files\n", prog, p); + + for (p = long_help_msg; *p != '\0'; p++) { + if (*p == '%') { + if (p[1] == 'p') { + fputs(prog, stdout); + p++; + } else + putchar('%'); + } else + putchar(*p); + } + version(); +} diff --git a/external/bsd/libarchive/dist/tar/bsdtar.h b/external/bsd/libarchive/dist/tar/bsdtar.h new file mode 100644 index 000000000..5e8dc7f89 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/bsdtar.h @@ -0,0 +1,158 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/usr.bin/tar/bsdtar.h,v 1.37 2008/12/06 07:37:14 kientzle Exp $ + */ + +#include "bsdtar_platform.h" +#include + +#include "matching.h" + +#define DEFAULT_BYTES_PER_BLOCK (20*512) + +/* + * The internal state for the "bsdtar" program. + * + * Keeping all of the state in a structure like this simplifies memory + * leak testing (at exit, anything left on the heap is suspect). A + * pointer to this structure is passed to most bsdtar internal + * functions. + */ +struct bsdtar { + /* Options */ + const char *filename; /* -f filename */ + const char *create_format; /* -F format */ + char *pending_chdir; /* -C dir */ + const char *names_from_file; /* -T file */ + time_t newer_ctime_sec; /* --newer/--newer-than */ + long newer_ctime_nsec; /* --newer/--newer-than */ + time_t newer_mtime_sec; /* --newer-mtime */ + long newer_mtime_nsec; /* --newer-mtime-than */ + int bytes_per_block; /* -b block_size */ + int verbose; /* -v */ + int extract_flags; /* Flags for extract operation */ + int strip_components; /* Remove this many leading dirs */ + char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */ + char symlink_mode; /* H or L, per BSD conventions */ + char create_compression; /* j, y, or z */ + const char *compress_program; + char option_absolute_paths; /* -P */ + char option_chroot; /* --chroot */ + char option_dont_traverse_mounts; /* --one-file-system */ + char option_fast_read; /* --fast-read */ + const char *option_options; /* --options */ + char option_honor_nodump; /* --nodump */ + char option_interactive; /* -w */ + char option_no_owner; /* -o */ + char option_no_subdirs; /* -n */ + char option_null; /* --null */ + char option_numeric_owner; /* --numeric-owner */ + char option_stdout; /* -O */ + char option_totals; /* --totals */ + char option_unlink_first; /* -U */ + char option_warn_links; /* --check-links */ + char day_first; /* show day before month in -tv output */ + + /* If >= 0, then close this when done. */ + int fd; + + /* Miscellaneous state information */ + int argc; + char **argv; + const char *optarg; + size_t gs_width; /* For 'list_item' in read.c */ + size_t u_width; /* for 'list_item' in read.c */ + uid_t user_uid; /* UID running this program */ + int return_value; /* Value returned by main() */ + char warned_lead_slash; /* Already displayed warning */ + char next_line_is_dir; /* Used for -C parsing in -cT */ + + /* + * Data for various subsystems. Full definitions are located in + * the file where they are used. + */ + struct archive *diskreader; /* for write.c */ + struct archive_entry_linkresolver *resolver; /* for write.c */ + struct archive_dir *archive_dir; /* for write.c */ + struct name_cache *gname_cache; /* for write.c */ + char *buff; /* for write.c */ + struct lafe_matching *matching; /* for matching.c */ + struct security *security; /* for read.c */ + struct name_cache *uname_cache; /* for write.c */ + struct siginfo_data *siginfo; /* for siginfo.c */ + struct substitution *substitution; /* for subst.c */ +}; + +/* Fake short equivalents for long options that otherwise lack them. */ +enum { + OPTION_CHECK_LINKS = 1, + OPTION_CHROOT, + OPTION_EXCLUDE, + OPTION_FORMAT, + OPTION_OPTIONS, + OPTION_HELP, + OPTION_INCLUDE, + OPTION_KEEP_NEWER_FILES, + OPTION_LZMA, + OPTION_NEWER_CTIME, + OPTION_NEWER_CTIME_THAN, + OPTION_NEWER_MTIME, + OPTION_NEWER_MTIME_THAN, + OPTION_NODUMP, + OPTION_NO_SAME_OWNER, + OPTION_NO_SAME_PERMISSIONS, + OPTION_NULL, + OPTION_NUMERIC_OWNER, + OPTION_ONE_FILE_SYSTEM, + OPTION_POSIX, + OPTION_SAME_OWNER, + OPTION_STRIP_COMPONENTS, + OPTION_TOTALS, + OPTION_USE_COMPRESS_PROGRAM, + OPTION_VERSION +}; + + +int bsdtar_getopt(struct bsdtar *); +void do_chdir(struct bsdtar *); +int edit_pathname(struct bsdtar *, struct archive_entry *); +int need_report(void); +int pathcmp(const char *a, const char *b); +void safe_fprintf(FILE *, const char *fmt, ...); +void set_chdir(struct bsdtar *, const char *newdir); +const char *tar_i64toa(int64_t); +void tar_mode_c(struct bsdtar *bsdtar); +void tar_mode_r(struct bsdtar *bsdtar); +void tar_mode_t(struct bsdtar *bsdtar); +void tar_mode_u(struct bsdtar *bsdtar); +void tar_mode_x(struct bsdtar *bsdtar); +void usage(void); +int yes(const char *fmt, ...); + +#if HAVE_REGEX_H +void add_substitution(struct bsdtar *, const char *); +int apply_substitution(struct bsdtar *, const char *, char **, int); +void cleanup_substitution(struct bsdtar *); +#endif diff --git a/external/bsd/libarchive/dist/tar/bsdtar_platform.h b/external/bsd/libarchive/dist/tar/bsdtar_platform.h new file mode 100644 index 000000000..fce9c9981 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/bsdtar_platform.h @@ -0,0 +1,132 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.26 2008/12/06 07:37:14 kientzle Exp $ + */ + +/* + * This header is the first thing included in any of the bsdtar + * source files. As far as possible, platform-specific issues should + * be dealt with here and not within individual source files. + */ + +#ifndef BSDTAR_PLATFORM_H_INCLUDED +#define BSDTAR_PLATFORM_H_INCLUDED + +#if defined(PLATFORM_CONFIG_H) +/* Use hand-built config.h in environments that need it. */ +#include PLATFORM_CONFIG_H +#else +/* Not having a config.h of some sort is a serious problem. */ +#include "config.h" +#endif + +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID +#define __FBSDID(a) struct _undefined_hack +#endif + +#ifdef HAVE_LIBARCHIVE +/* If we're using the platform libarchive, include system headers. */ +#include +#include +#else +/* Otherwise, include user headers. */ +#include "archive.h" +#include "archive_entry.h" +#endif + +#ifdef HAVE_LIBACL +#include +#endif + +/* + * Include "dirent.h" (or it's equivalent on several different platforms). + * + * This is slightly modified from the GNU autoconf recipe. + * In particular, FreeBSD includes d_namlen in it's dirent structure, + * so my configure script includes an explicit test for the d_namlen + * field. + */ +#if HAVE_DIRENT_H +# include +# if HAVE_DIRENT_D_NAMLEN +# define DIRENT_NAMLEN(dirent) (dirent)->d_namlen +# else +# define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name) +# endif +#else +# define dirent direct +# define DIRENT_NAMLEN(dirent) (dirent)->d_namlen +# if HAVE_SYS_NDIR_H +# include +# endif +# if HAVE_SYS_DIR_H +# include +# endif +# if HAVE_NDIR_H +# include +# endif +#endif + +#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC +#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec +#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec +#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC +#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctim.tv_nsec +#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec +#elif HAVE_STRUCT_STAT_ST_MTIME_N +#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_n +#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_n +#elif HAVE_STRUCT_STAT_ST_UMTIME +#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_uctime * 1000 +#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_umtime * 1000 +#elif HAVE_STRUCT_STAT_ST_MTIME_USEC +#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_usec * 1000 +#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_usec * 1000 +#else +#define ARCHIVE_STAT_CTIME_NANOS(st) (0) +#define ARCHIVE_STAT_MTIME_NANOS(st) (0) +#endif + +/* How to mark functions that don't return. */ +/* This facilitates use of some newer static code analysis tools. */ +#undef __LA_DEAD +#if defined(__GNUC__) && (__GNUC__ > 2 || \ + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_DEAD __attribute__((__noreturn__)) +#else +#define __LA_DEAD +#endif + +#if defined(_WIN32) && !defined(__CYGWIN__) +#include "bsdtar_windows.h" +#endif + +#endif /* !BSDTAR_PLATFORM_H_INCLUDED */ diff --git a/external/bsd/libarchive/dist/tar/bsdtar_windows.c b/external/bsd/libarchive/dist/tar/bsdtar_windows.c new file mode 100644 index 000000000..4d1205028 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/bsdtar_windows.c @@ -0,0 +1,298 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#if defined(_WIN32) && !defined(__CYGWIN__) + +#include "bsdtar_platform.h" +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_UTIME_H +#include +#endif +#include +#include +#include +#include +#include +#include + +#include "bsdtar.h" +#include "err.h" + +/* This may actually not be needed anymore. + * TODO: Review the error handling for chdir() failures and + * simply dump this if it's not really needed. */ +static void __tar_dosmaperr(unsigned long); + +/* + * Prepend "\\?\" to the path name and convert it to unicode to permit + * an extended-length path for a maximum total path length of 32767 + * characters. + * see also http://msdn.microsoft.com/en-us/library/aa365247.aspx + */ +static wchar_t * +permissive_name(const char *name) +{ + wchar_t *wn, *wnp; + wchar_t *ws, *wsp; + DWORD l, len, slen, alloclen; + int unc; + + len = (DWORD)strlen(name); + wn = malloc((len + 1) * sizeof(wchar_t)); + if (wn == NULL) + return (NULL); + l = MultiByteToWideChar(CP_ACP, 0, name, len, wn, len); + if (l == 0) { + free(wn); + return (NULL); + } + wn[l] = L'\0'; + + /* Get a full path names */ + l = GetFullPathNameW(wn, 0, NULL, NULL); + if (l == 0) { + free(wn); + return (NULL); + } + wnp = malloc(l * sizeof(wchar_t)); + if (wnp == NULL) { + free(wn); + return (NULL); + } + len = GetFullPathNameW(wn, l, wnp, NULL); + free(wn); + wn = wnp; + + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'?' && wnp[3] == L'\\') + /* We have already permissive names. */ + return (wn); + + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'.' && wnp[3] == L'\\') { + /* Device names */ + if (((wnp[4] >= L'a' && wnp[4] <= L'z') || + (wnp[4] >= L'A' && wnp[4] <= L'Z')) && + wnp[5] == L':' && wnp[6] == L'\\') + wnp[2] = L'?';/* Not device names. */ + return (wn); + } + + unc = 0; + if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') { + wchar_t *p = &wnp[2]; + + /* Skip server-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\') { + wchar_t *rp = ++p; + /* Skip share-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\' && p != rp) { + /* Now, match patterns such as + * "\\server-name\share-name\" */ + wnp += 2; + len -= 2; + unc = 1; + } + } + } + + alloclen = slen = 4 + (unc * 4) + len + 1; + ws = wsp = malloc(slen * sizeof(wchar_t)); + if (ws == NULL) { + free(wn); + return (NULL); + } + /* prepend "\\?\" */ + wcsncpy(wsp, L"\\\\?\\", 4); + wsp += 4; + slen -= 4; + if (unc) { + /* append "UNC\" ---> "\\?\UNC\" */ + wcsncpy(wsp, L"UNC\\", 4); + wsp += 4; + slen -= 4; + } + wcsncpy(wsp, wnp, slen); + free(wn); + ws[alloclen - 1] = L'\0'; + return (ws); +} + +int +__tar_chdir(const char *path) +{ + wchar_t *ws; + int r; + + r = SetCurrentDirectoryA(path); + if (r == 0) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) { + __tar_dosmaperr(GetLastError()); + return (-1); + } + } else + return (0); + ws = permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + r = SetCurrentDirectoryW(ws); + free(ws); + if (r == 0) { + __tar_dosmaperr(GetLastError()); + return (-1); + } + return (0); +} + +/* + * The following function was modified from PostgreSQL sources and is + * subject to the copyright below. + */ +/*------------------------------------------------------------------------- + * + * win32error.c + * Map win32 error codes to errno values + * + * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +/* +PostgreSQL Database Management System +(formerly known as Postgres, then as Postgres95) + +Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group + +Portions Copyright (c) 1994, The Regents of the University of California + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose, without fee, and without a written agreement +is hereby granted, provided that the above copyright notice and this +paragraph and the following two paragraphs appear in all copies. + +IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR +DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING +LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO +PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. +*/ + +static const struct { + DWORD winerr; + int doserr; +} doserrors[] = +{ + { ERROR_INVALID_FUNCTION, EINVAL }, + { ERROR_FILE_NOT_FOUND, ENOENT }, + { ERROR_PATH_NOT_FOUND, ENOENT }, + { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, + { ERROR_ACCESS_DENIED, EACCES }, + { ERROR_INVALID_HANDLE, EBADF }, + { ERROR_ARENA_TRASHED, ENOMEM }, + { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, + { ERROR_INVALID_BLOCK, ENOMEM }, + { ERROR_BAD_ENVIRONMENT, E2BIG }, + { ERROR_BAD_FORMAT, ENOEXEC }, + { ERROR_INVALID_ACCESS, EINVAL }, + { ERROR_INVALID_DATA, EINVAL }, + { ERROR_INVALID_DRIVE, ENOENT }, + { ERROR_CURRENT_DIRECTORY, EACCES }, + { ERROR_NOT_SAME_DEVICE, EXDEV }, + { ERROR_NO_MORE_FILES, ENOENT }, + { ERROR_LOCK_VIOLATION, EACCES }, + { ERROR_SHARING_VIOLATION, EACCES }, + { ERROR_BAD_NETPATH, ENOENT }, + { ERROR_NETWORK_ACCESS_DENIED, EACCES }, + { ERROR_BAD_NET_NAME, ENOENT }, + { ERROR_FILE_EXISTS, EEXIST }, + { ERROR_CANNOT_MAKE, EACCES }, + { ERROR_FAIL_I24, EACCES }, + { ERROR_INVALID_PARAMETER, EINVAL }, + { ERROR_NO_PROC_SLOTS, EAGAIN }, + { ERROR_DRIVE_LOCKED, EACCES }, + { ERROR_BROKEN_PIPE, EPIPE }, + { ERROR_DISK_FULL, ENOSPC }, + { ERROR_INVALID_TARGET_HANDLE, EBADF }, + { ERROR_INVALID_HANDLE, EINVAL }, + { ERROR_WAIT_NO_CHILDREN, ECHILD }, + { ERROR_CHILD_NOT_COMPLETE, ECHILD }, + { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, + { ERROR_NEGATIVE_SEEK, EINVAL }, + { ERROR_SEEK_ON_DEVICE, EACCES }, + { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, + { ERROR_NOT_LOCKED, EACCES }, + { ERROR_BAD_PATHNAME, ENOENT }, + { ERROR_MAX_THRDS_REACHED, EAGAIN }, + { ERROR_LOCK_FAILED, EACCES }, + { ERROR_ALREADY_EXISTS, EEXIST }, + { ERROR_FILENAME_EXCED_RANGE, ENOENT }, + { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, + { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } +}; + +static void +__tar_dosmaperr(unsigned long e) +{ + int i; + + if (e == 0) { + errno = 0; + return; + } + + for (i = 0; i < sizeof(doserrors); i++) { + if (doserrors[i].winerr == e) { + errno = doserrors[i].doserr; + return; + } + } + + /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */ + errno = EINVAL; + return; +} + +#endif diff --git a/external/bsd/libarchive/dist/tar/bsdtar_windows.h b/external/bsd/libarchive/dist/tar/bsdtar_windows.h new file mode 100644 index 000000000..092ea6959 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/bsdtar_windows.h @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef BSDTAR_WINDOWS_H +#define BSDTAR_WINDOWS_H 1 +#include +#include + +#ifndef PRId64 +#define PRId64 "I64" +#endif +#define geteuid() 0 + +#ifndef S_IFIFO +#define S_IFIFO 0010000 /* pipe */ +#endif + +#include /* Must include before redefining 'strdup' */ +#if !defined(__BORLANDC__) +#define strdup _strdup +#endif +#if !defined(__BORLANDC__) +#define getcwd _getcwd +#endif + +#define chdir __tar_chdir +int __tar_chdir(const char *); + +#ifndef S_ISREG +#define S_ISREG(a) (a & _S_IFREG) +#endif +#ifndef S_ISBLK +#define S_ISBLK(a) (0) +#endif + +#endif /* BSDTAR_WINDOWS_H */ diff --git a/external/bsd/libarchive/dist/tar/cmdline.c b/external/bsd/libarchive/dist/tar/cmdline.c new file mode 100644 index 000000000..ba3e8a1b2 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/cmdline.c @@ -0,0 +1,381 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Command line parser for tar. + */ + +#include "bsdtar_platform.h" +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "bsdtar.h" +#include "err.h" + +/* + * Short options for tar. Please keep this sorted. + */ +static const char *short_options + = "Bb:C:cf:HhI:JjkLlmnOoPpqrSs:T:tUuvW:wX:xyZz"; + +/* + * Long options for tar. Please keep this list sorted. + * + * The symbolic names for options that lack a short equivalent are + * defined in bsdtar.h. Also note that so far I've found no need + * to support optional arguments to long options. That would be + * a small change to the code below. + */ + +static struct option { + const char *name; + int required; /* 1 if this option requires an argument. */ + int equivalent; /* Equivalent short option. */ +} tar_longopts[] = { + { "absolute-paths", 0, 'P' }, + { "append", 0, 'r' }, + { "block-size", 1, 'b' }, + { "bunzip2", 0, 'j' }, + { "bzip", 0, 'j' }, + { "bzip2", 0, 'j' }, + { "cd", 1, 'C' }, + { "check-links", 0, OPTION_CHECK_LINKS }, + { "chroot", 0, OPTION_CHROOT }, + { "compress", 0, 'Z' }, + { "confirmation", 0, 'w' }, + { "create", 0, 'c' }, + { "dereference", 0, 'L' }, + { "directory", 1, 'C' }, + { "exclude", 1, OPTION_EXCLUDE }, + { "exclude-from", 1, 'X' }, + { "extract", 0, 'x' }, + { "fast-read", 0, 'q' }, + { "file", 1, 'f' }, + { "files-from", 1, 'T' }, + { "format", 1, OPTION_FORMAT }, + { "options", 1, OPTION_OPTIONS }, + { "gunzip", 0, 'z' }, + { "gzip", 0, 'z' }, + { "help", 0, OPTION_HELP }, + { "include", 1, OPTION_INCLUDE }, + { "interactive", 0, 'w' }, + { "insecure", 0, 'P' }, + { "keep-newer-files", 0, OPTION_KEEP_NEWER_FILES }, + { "keep-old-files", 0, 'k' }, + { "list", 0, 't' }, + { "lzma", 0, OPTION_LZMA }, + { "modification-time", 0, 'm' }, + { "newer", 1, OPTION_NEWER_CTIME }, + { "newer-ctime", 1, OPTION_NEWER_CTIME }, + { "newer-ctime-than", 1, OPTION_NEWER_CTIME_THAN }, + { "newer-mtime", 1, OPTION_NEWER_MTIME }, + { "newer-mtime-than", 1, OPTION_NEWER_MTIME_THAN }, + { "newer-than", 1, OPTION_NEWER_CTIME_THAN }, + { "nodump", 0, OPTION_NODUMP }, + { "norecurse", 0, 'n' }, + { "no-recursion", 0, 'n' }, + { "no-same-owner", 0, OPTION_NO_SAME_OWNER }, + { "no-same-permissions", 0, OPTION_NO_SAME_PERMISSIONS }, + { "null", 0, OPTION_NULL }, + { "numeric-owner", 0, OPTION_NUMERIC_OWNER }, + { "one-file-system", 0, OPTION_ONE_FILE_SYSTEM }, + { "posix", 0, OPTION_POSIX }, + { "preserve-permissions", 0, 'p' }, + { "read-full-blocks", 0, 'B' }, + { "same-owner", 0, OPTION_SAME_OWNER }, + { "same-permissions", 0, 'p' }, + { "strip-components", 1, OPTION_STRIP_COMPONENTS }, + { "to-stdout", 0, 'O' }, + { "totals", 0, OPTION_TOTALS }, + { "uncompress", 0, 'Z' }, + { "unlink", 0, 'U' }, + { "unlink-first", 0, 'U' }, + { "update", 0, 'u' }, + { "use-compress-program", 1, OPTION_USE_COMPRESS_PROGRAM }, + { "verbose", 0, 'v' }, + { "version", 0, OPTION_VERSION }, + { "xz", 0, 'J' }, + { NULL, 0, 0 } +}; + +/* + * This getopt implementation has two key features that common + * getopt_long() implementations lack. Apart from those, it's a + * straightforward option parser, considerably simplified by not + * needing to support the wealth of exotic getopt_long() features. It + * has, of course, been shamelessly tailored for bsdtar. (If you're + * looking for a generic getopt_long() implementation for your + * project, I recommend Gregory Pietsch's public domain getopt_long() + * implementation.) The two additional features are: + * + * Old-style tar arguments: The original tar implementation treated + * the first argument word as a list of single-character option + * letters. All arguments follow as separate words. For example, + * tar xbf 32 /dev/tape + * Here, the "xbf" is three option letters, "32" is the argument for + * "b" and "/dev/tape" is the argument for "f". We support this usage + * if the first command-line argument does not begin with '-'. We + * also allow regular short and long options to follow, e.g., + * tar xbf 32 /dev/tape -P --format=pax + * + * -W long options: There's an obscure GNU convention (only rarely + * supported even there) that allows "-W option=argument" as an + * alternative way to support long options. This was supported in + * early bsdtar as a way to access long options on platforms that did + * not support getopt_long() and is preserved here for backwards + * compatibility. (Of course, if I'd started with a custom + * command-line parser from the beginning, I would have had normal + * long option support on every platform so that hack wouldn't have + * been necessary. Oh, well. Some mistakes you just have to live + * with.) + * + * TODO: We should be able to use this to pull files and intermingled + * options (such as -C) from the command line in write mode. That + * will require a little rethinking of the argument handling in + * bsdtar.c. + * + * TODO: If we want to support arbitrary command-line options from -T + * input (as GNU tar does), we may need to extend this to handle option + * words from sources other than argv/arc. I'm not really sure if I + * like that feature of GNU tar, so it's certainly not a priority. + */ + +int +bsdtar_getopt(struct bsdtar *bsdtar) +{ + enum { state_start = 0, state_old_tar, state_next_word, + state_short, state_long }; + static int state = state_start; + static char *opt_word; + + const struct option *popt, *match = NULL, *match2 = NULL; + const char *p, *long_prefix = "--"; + size_t optlength; + int opt = '?'; + int required = 0; + + bsdtar->optarg = NULL; + + /* First time through, initialize everything. */ + if (state == state_start) { + /* Skip program name. */ + ++bsdtar->argv; + --bsdtar->argc; + if (*bsdtar->argv == NULL) + return (-1); + /* Decide between "new style" and "old style" arguments. */ + if (bsdtar->argv[0][0] == '-') { + state = state_next_word; + } else { + state = state_old_tar; + opt_word = *bsdtar->argv++; + --bsdtar->argc; + } + } + + /* + * We're parsing old-style tar arguments + */ + if (state == state_old_tar) { + /* Get the next option character. */ + opt = *opt_word++; + if (opt == '\0') { + /* New-style args can follow old-style. */ + state = state_next_word; + } else { + /* See if it takes an argument. */ + p = strchr(short_options, opt); + if (p == NULL) + return ('?'); + if (p[1] == ':') { + bsdtar->optarg = *bsdtar->argv; + if (bsdtar->optarg == NULL) { + lafe_warnc(0, + "Option %c requires an argument", + opt); + return ('?'); + } + ++bsdtar->argv; + --bsdtar->argc; + } + } + } + + /* + * We're ready to look at the next word in argv. + */ + if (state == state_next_word) { + /* No more arguments, so no more options. */ + if (bsdtar->argv[0] == NULL) + return (-1); + /* Doesn't start with '-', so no more options. */ + if (bsdtar->argv[0][0] != '-') + return (-1); + /* "--" marks end of options; consume it and return. */ + if (strcmp(bsdtar->argv[0], "--") == 0) { + ++bsdtar->argv; + --bsdtar->argc; + return (-1); + } + /* Get next word for parsing. */ + opt_word = *bsdtar->argv++; + --bsdtar->argc; + if (opt_word[1] == '-') { + /* Set up long option parser. */ + state = state_long; + opt_word += 2; /* Skip leading '--' */ + } else { + /* Set up short option parser. */ + state = state_short; + ++opt_word; /* Skip leading '-' */ + } + } + + /* + * We're parsing a group of POSIX-style single-character options. + */ + if (state == state_short) { + /* Peel next option off of a group of short options. */ + opt = *opt_word++; + if (opt == '\0') { + /* End of this group; recurse to get next option. */ + state = state_next_word; + return bsdtar_getopt(bsdtar); + } + + /* Does this option take an argument? */ + p = strchr(short_options, opt); + if (p == NULL) + return ('?'); + if (p[1] == ':') + required = 1; + + /* If it takes an argument, parse that. */ + if (required) { + /* If arg is run-in, opt_word already points to it. */ + if (opt_word[0] == '\0') { + /* Otherwise, pick up the next word. */ + opt_word = *bsdtar->argv; + if (opt_word == NULL) { + lafe_warnc(0, + "Option -%c requires an argument", + opt); + return ('?'); + } + ++bsdtar->argv; + --bsdtar->argc; + } + if (opt == 'W') { + state = state_long; + long_prefix = "-W "; /* For clearer errors. */ + } else { + state = state_next_word; + bsdtar->optarg = opt_word; + } + } + } + + /* We're reading a long option, including -W long=arg convention. */ + if (state == state_long) { + /* After this long option, we'll be starting a new word. */ + state = state_next_word; + + /* Option name ends at '=' if there is one. */ + p = strchr(opt_word, '='); + if (p != NULL) { + optlength = (size_t)(p - opt_word); + bsdtar->optarg = (char *)(uintptr_t)(p + 1); + } else { + optlength = strlen(opt_word); + } + + /* Search the table for an unambiguous match. */ + for (popt = tar_longopts; popt->name != NULL; popt++) { + /* Short-circuit if first chars don't match. */ + if (popt->name[0] != opt_word[0]) + continue; + /* If option is a prefix of name in table, record it.*/ + if (strncmp(opt_word, popt->name, optlength) == 0) { + match2 = match; /* Record up to two matches. */ + match = popt; + /* If it's an exact match, we're done. */ + if (strlen(popt->name) == optlength) { + match2 = NULL; /* Forget the others. */ + break; + } + } + } + + /* Fail if there wasn't a unique match. */ + if (match == NULL) { + lafe_warnc(0, + "Option %s%s is not supported", + long_prefix, opt_word); + return ('?'); + } + if (match2 != NULL) { + lafe_warnc(0, + "Ambiguous option %s%s (matches --%s and --%s)", + long_prefix, opt_word, match->name, match2->name); + return ('?'); + } + + /* We've found a unique match; does it need an argument? */ + if (match->required) { + /* Argument required: get next word if necessary. */ + if (bsdtar->optarg == NULL) { + bsdtar->optarg = *bsdtar->argv; + if (bsdtar->optarg == NULL) { + lafe_warnc(0, + "Option %s%s requires an argument", + long_prefix, match->name); + return ('?'); + } + ++bsdtar->argv; + --bsdtar->argc; + } + } else { + /* Argument forbidden: fail if there is one. */ + if (bsdtar->optarg != NULL) { + lafe_warnc(0, + "Option %s%s does not allow an argument", + long_prefix, match->name); + return ('?'); + } + } + return (match->equivalent); + } + + return (opt); +} diff --git a/external/bsd/libarchive/dist/tar/getdate.c b/external/bsd/libarchive/dist/tar/getdate.c new file mode 100644 index 000000000..ffaa679ba --- /dev/null +++ b/external/bsd/libarchive/dist/tar/getdate.c @@ -0,0 +1,1037 @@ +/* + * This code is in the public domain and has no copyright. + * + * This is a plain C recursive-descent translation of an old + * public-domain YACC grammar that has been used for parsing dates in + * very many open-source projects. + * + * Since the original authors were generous enough to donate their + * work to the public domain, I feel compelled to match their + * generosity. + * + * Tim Kientzle, February 2009. + */ + +/* + * Header comment from original getdate.y: + */ + +/* +** Originally written by Steven M. Bellovin while +** at the University of North Carolina at Chapel Hill. Later tweaked by +** a couple of people on Usenet. Completely overhauled by Rich $alz +** and Jim Berets in August, 1990; +** +** This grammar has 10 shift/reduce conflicts. +** +** This code is in the public domain and has no copyright. +*/ + +#ifdef __FreeBSD__ +#include +__FBSDID("$FreeBSD$"); +#endif + +#include +#include +#include +#include +#include + +/* This file defines a single public function. */ +time_t get_date(time_t now, char *); + +/* Basic time units. */ +#define EPOCH 1970 +#define MINUTE (60L) +#define HOUR (60L * MINUTE) +#define DAY (24L * HOUR) + +/* Daylight-savings mode: on, off, or not yet known. */ +enum DSTMODE { DSTon, DSToff, DSTmaybe }; +/* Meridian: am or pm. */ +enum { tAM, tPM }; +/* Token types returned by nexttoken() */ +enum { tAGO = 260, tDAY, tDAYZONE, tAMPM, tMONTH, tMONTH_UNIT, tSEC_UNIT, + tUNUMBER, tZONE, tDST }; +struct token { int token; time_t value; }; + +/* + * Parser state. + */ +struct gdstate { + struct token *tokenp; /* Pointer to next token. */ + /* HaveXxxx counts how many of this kind of phrase we've seen; + * it's a fatal error to have more than one time, zone, day, + * or date phrase. */ + int HaveYear; + int HaveMonth; + int HaveDay; + int HaveWeekDay; /* Day of week */ + int HaveTime; /* Hour/minute/second */ + int HaveZone; /* timezone and/or DST info */ + int HaveRel; /* time offset; we can have more than one */ + /* Absolute time values. */ + time_t Timezone; /* Seconds offset from GMT */ + time_t Day; + time_t Hour; + time_t Minutes; + time_t Month; + time_t Seconds; + time_t Year; + /* DST selection */ + enum DSTMODE DSTmode; + /* Day of week accounting, e.g., "3rd Tuesday" */ + time_t DayOrdinal; /* "3" in "3rd Tuesday" */ + time_t DayNumber; /* "Tuesday" in "3rd Tuesday" */ + /* Relative time values: hour/day/week offsets are measured in + * seconds, month/year are counted in months. */ + time_t RelMonth; + time_t RelSeconds; +}; + +/* + * A series of functions that recognize certain common time phrases. + * Each function returns 1 if it managed to make sense of some of the + * tokens, zero otherwise. + */ + +/* + * hour:minute or hour:minute:second with optional AM, PM, or numeric + * timezone offset + */ +static int +timephrase(struct gdstate *gds) +{ + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == ':' + && gds->tokenp[2].token == tUNUMBER + && gds->tokenp[3].token == ':' + && gds->tokenp[4].token == tUNUMBER) { + /* "12:14:18" or "22:08:07" */ + ++gds->HaveTime; + gds->Hour = gds->tokenp[0].value; + gds->Minutes = gds->tokenp[2].value; + gds->Seconds = gds->tokenp[4].value; + gds->tokenp += 5; + } + else if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == ':' + && gds->tokenp[2].token == tUNUMBER) { + /* "12:14" or "22:08" */ + ++gds->HaveTime; + gds->Hour = gds->tokenp[0].value; + gds->Minutes = gds->tokenp[2].value; + gds->Seconds = 0; + gds->tokenp += 3; + } + else if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == tAMPM) { + /* "7" is a time if it's followed by "am" or "pm" */ + ++gds->HaveTime; + gds->Hour = gds->tokenp[0].value; + gds->Minutes = gds->Seconds = 0; + /* We'll handle the AM/PM below. */ + gds->tokenp += 1; + } else { + /* We can't handle this. */ + return 0; + } + + if (gds->tokenp[0].token == tAMPM) { + /* "7:12pm", "12:20:13am" */ + if (gds->Hour == 12) + gds->Hour = 0; + if (gds->tokenp[0].value == tPM) + gds->Hour += 12; + gds->tokenp += 1; + } + if (gds->tokenp[0].token == '+' + && gds->tokenp[1].token == tUNUMBER) { + /* "7:14+0700" */ + gds->HaveZone++; + gds->DSTmode = DSToff; + gds->Timezone = - ((gds->tokenp[1].value / 100) * HOUR + + (gds->tokenp[1].value % 100) * MINUTE); + gds->tokenp += 2; + } + if (gds->tokenp[0].token == '-' + && gds->tokenp[1].token == tUNUMBER) { + /* "19:14:12-0530" */ + gds->HaveZone++; + gds->DSTmode = DSToff; + gds->Timezone = + ((gds->tokenp[1].value / 100) * HOUR + + (gds->tokenp[1].value % 100) * MINUTE); + gds->tokenp += 2; + } + return 1; +} + +/* + * Timezone name, possibly including DST. + */ +static int +zonephrase(struct gdstate *gds) +{ + if (gds->tokenp[0].token == tZONE + && gds->tokenp[1].token == tDST) { + gds->HaveZone++; + gds->Timezone = gds->tokenp[0].value; + gds->DSTmode = DSTon; + gds->tokenp += 1; + return 1; + } + + if (gds->tokenp[0].token == tZONE) { + gds->HaveZone++; + gds->Timezone = gds->tokenp[0].value; + gds->DSTmode = DSToff; + gds->tokenp += 1; + return 1; + } + + if (gds->tokenp[0].token == tDAYZONE) { + gds->HaveZone++; + gds->Timezone = gds->tokenp[0].value; + gds->DSTmode = DSTon; + gds->tokenp += 1; + return 1; + } + return 0; +} + +/* + * Year/month/day in various combinations. + */ +static int +datephrase(struct gdstate *gds) +{ + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == '/' + && gds->tokenp[2].token == tUNUMBER + && gds->tokenp[3].token == '/' + && gds->tokenp[4].token == tUNUMBER) { + gds->HaveYear++; + gds->HaveMonth++; + gds->HaveDay++; + if (gds->tokenp[0].value >= 13) { + /* First number is big: 2004/01/29, 99/02/17 */ + gds->Year = gds->tokenp[0].value; + gds->Month = gds->tokenp[2].value; + gds->Day = gds->tokenp[4].value; + } else if ((gds->tokenp[4].value >= 13) + || (gds->tokenp[2].value >= 13)) { + /* Last number is big: 01/07/98 */ + /* Middle number is big: 01/29/04 */ + gds->Month = gds->tokenp[0].value; + gds->Day = gds->tokenp[2].value; + gds->Year = gds->tokenp[4].value; + } else { + /* No significant clues: 02/03/04 */ + gds->Month = gds->tokenp[0].value; + gds->Day = gds->tokenp[2].value; + gds->Year = gds->tokenp[4].value; + } + gds->tokenp += 5; + return 1; + } + + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == '/' + && gds->tokenp[2].token == tUNUMBER) { + /* "1/15" */ + gds->HaveMonth++; + gds->HaveDay++; + gds->Month = gds->tokenp[0].value; + gds->Day = gds->tokenp[2].value; + gds->tokenp += 3; + return 1; + } + + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == '-' + && gds->tokenp[2].token == tUNUMBER + && gds->tokenp[3].token == '-' + && gds->tokenp[4].token == tUNUMBER) { + /* ISO 8601 format. yyyy-mm-dd. */ + gds->HaveYear++; + gds->HaveMonth++; + gds->HaveDay++; + gds->Year = gds->tokenp[0].value; + gds->Month = gds->tokenp[2].value; + gds->Day = gds->tokenp[4].value; + gds->tokenp += 5; + return 1; + } + + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == '-' + && gds->tokenp[2].token == tMONTH + && gds->tokenp[3].token == '-' + && gds->tokenp[4].token == tUNUMBER) { + gds->HaveYear++; + gds->HaveMonth++; + gds->HaveDay++; + if (gds->tokenp[0].value > 31) { + /* e.g. 1992-Jun-17 */ + gds->Year = gds->tokenp[0].value; + gds->Month = gds->tokenp[2].value; + gds->Day = gds->tokenp[4].value; + } else { + /* e.g. 17-JUN-1992. */ + gds->Day = gds->tokenp[0].value; + gds->Month = gds->tokenp[2].value; + gds->Year = gds->tokenp[4].value; + } + gds->tokenp += 5; + return 1; + } + + if (gds->tokenp[0].token == tMONTH + && gds->tokenp[1].token == tUNUMBER + && gds->tokenp[2].token == ',' + && gds->tokenp[3].token == tUNUMBER) { + /* "June 17, 2001" */ + gds->HaveYear++; + gds->HaveMonth++; + gds->HaveDay++; + gds->Month = gds->tokenp[0].value; + gds->Day = gds->tokenp[1].value; + gds->Year = gds->tokenp[3].value; + gds->tokenp += 4; + return 1; + } + + if (gds->tokenp[0].token == tMONTH + && gds->tokenp[1].token == tUNUMBER) { + /* "May 3" */ + gds->HaveMonth++; + gds->HaveDay++; + gds->Month = gds->tokenp[0].value; + gds->Day = gds->tokenp[1].value; + gds->tokenp += 2; + return 1; + } + + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == tMONTH + && gds->tokenp[2].token == tUNUMBER) { + /* "12 Sept 1997" */ + gds->HaveYear++; + gds->HaveMonth++; + gds->HaveDay++; + gds->Day = gds->tokenp[0].value; + gds->Month = gds->tokenp[1].value; + gds->Year = gds->tokenp[2].value; + gds->tokenp += 3; + return 1; + } + + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == tMONTH) { + /* "12 Sept" */ + gds->HaveMonth++; + gds->HaveDay++; + gds->Day = gds->tokenp[0].value; + gds->Month = gds->tokenp[1].value; + gds->tokenp += 2; + return 1; + } + + return 0; +} + +/* + * Relative time phrase: "tomorrow", "yesterday", "+1 hour", etc. + */ +static int +relunitphrase(struct gdstate *gds) +{ + if (gds->tokenp[0].token == '-' + && gds->tokenp[1].token == tUNUMBER + && gds->tokenp[2].token == tSEC_UNIT) { + /* "-3 hours" */ + gds->HaveRel++; + gds->RelSeconds -= gds->tokenp[1].value * gds->tokenp[2].value; + gds->tokenp += 3; + return 1; + } + if (gds->tokenp[0].token == '+' + && gds->tokenp[1].token == tUNUMBER + && gds->tokenp[2].token == tSEC_UNIT) { + /* "+1 minute" */ + gds->HaveRel++; + gds->RelSeconds += gds->tokenp[1].value * gds->tokenp[2].value; + gds->tokenp += 3; + return 1; + } + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == tSEC_UNIT) { + /* "1 day" */ + gds->HaveRel++; + gds->RelSeconds += gds->tokenp[1].value * gds->tokenp[2].value; + gds->tokenp += 3; + return 1; + } + if (gds->tokenp[0].token == '-' + && gds->tokenp[1].token == tUNUMBER + && gds->tokenp[2].token == tMONTH_UNIT) { + /* "-3 months" */ + gds->HaveRel++; + gds->RelMonth -= gds->tokenp[1].value * gds->tokenp[2].value; + gds->tokenp += 3; + return 1; + } + if (gds->tokenp[0].token == '+' + && gds->tokenp[1].token == tUNUMBER + && gds->tokenp[2].token == tMONTH_UNIT) { + /* "+5 years" */ + gds->HaveRel++; + gds->RelMonth += gds->tokenp[1].value * gds->tokenp[2].value; + gds->tokenp += 3; + return 1; + } + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == tMONTH_UNIT) { + /* "2 years" */ + gds->HaveRel++; + gds->RelMonth += gds->tokenp[0].value * gds->tokenp[1].value; + gds->tokenp += 2; + return 1; + } + if (gds->tokenp[0].token == tSEC_UNIT) { + /* "now", "tomorrow" */ + gds->HaveRel++; + gds->RelSeconds += gds->tokenp[0].value; + ++gds->tokenp; + return 1; + } + if (gds->tokenp[0].token == tMONTH_UNIT) { + /* "month" */ + gds->HaveRel++; + gds->RelMonth += gds->tokenp[0].value; + gds->tokenp += 1; + return 1; + } + return 0; +} + +/* + * Day of the week specification. + */ +static int +dayphrase(struct gdstate *gds) +{ + if (gds->tokenp[0].token == tDAY) { + /* "tues", "wednesday," */ + gds->HaveWeekDay++; + gds->DayOrdinal = 1; + gds->DayNumber = gds->tokenp[0].value; + gds->tokenp += 1; + if (gds->tokenp[0].token == ',') + gds->tokenp += 1; + return 1; + } + if (gds->tokenp[0].token == tUNUMBER + && gds->tokenp[1].token == tDAY) { + /* "second tues" "3 wed" */ + gds->HaveWeekDay++; + gds->DayOrdinal = gds->tokenp[0].value; + gds->DayNumber = gds->tokenp[1].value; + gds->tokenp += 2; + return 1; + } + return 0; +} + +/* + * Try to match a phrase using one of the above functions. + * This layer also deals with a couple of generic issues. + */ +static int +phrase(struct gdstate *gds) +{ + if (timephrase(gds)) + return 1; + if (zonephrase(gds)) + return 1; + if (datephrase(gds)) + return 1; + if (dayphrase(gds)) + return 1; + if (relunitphrase(gds)) { + if (gds->tokenp[0].token == tAGO) { + gds->RelSeconds = -gds->RelSeconds; + gds->RelMonth = -gds->RelMonth; + gds->tokenp += 1; + } + return 1; + } + + /* Bare numbers sometimes have meaning. */ + if (gds->tokenp[0].token == tUNUMBER) { + if (gds->HaveTime && !gds->HaveYear && !gds->HaveRel) { + gds->HaveYear++; + gds->Year = gds->tokenp[0].value; + gds->tokenp += 1; + return 1; + } + + if(gds->tokenp[0].value > 10000) { + /* "20040301" */ + gds->HaveYear++; + gds->HaveMonth++; + gds->HaveDay++; + gds->Day= (gds->tokenp[0].value)%100; + gds->Month= (gds->tokenp[0].value/100)%100; + gds->Year = gds->tokenp[0].value/10000; + gds->tokenp += 1; + return 1; + } + + if (gds->tokenp[0].value < 24) { + gds->HaveTime++; + gds->Hour = gds->tokenp[0].value; + gds->Minutes = 0; + gds->Seconds = 0; + gds->tokenp += 1; + return 1; + } + + if ((gds->tokenp[0].value / 100 < 24) + && (gds->tokenp[0].value % 100 < 60)) { + /* "513" is same as "5:13" */ + gds->Hour = gds->tokenp[0].value / 100; + gds->Minutes = gds->tokenp[0].value % 100; + gds->Seconds = 0; + gds->tokenp += 1; + return 1; + } + } + + return 0; +} + +/* + * A dictionary of time words. + */ +static struct LEXICON { + size_t abbrev; + const char *name; + int type; + time_t value; +} const TimeWords[] = { + /* am/pm */ + { 0, "am", tAMPM, tAM }, + { 0, "pm", tAMPM, tPM }, + + /* Month names. */ + { 3, "january", tMONTH, 1 }, + { 3, "february", tMONTH, 2 }, + { 3, "march", tMONTH, 3 }, + { 3, "april", tMONTH, 4 }, + { 3, "may", tMONTH, 5 }, + { 3, "june", tMONTH, 6 }, + { 3, "july", tMONTH, 7 }, + { 3, "august", tMONTH, 8 }, + { 3, "september", tMONTH, 9 }, + { 3, "october", tMONTH, 10 }, + { 3, "november", tMONTH, 11 }, + { 3, "december", tMONTH, 12 }, + + /* Days of the week. */ + { 2, "sunday", tDAY, 0 }, + { 3, "monday", tDAY, 1 }, + { 2, "tuesday", tDAY, 2 }, + { 3, "wednesday", tDAY, 3 }, + { 2, "thursday", tDAY, 4 }, + { 2, "friday", tDAY, 5 }, + { 2, "saturday", tDAY, 6 }, + + /* Timezones: Offsets are in seconds. */ + { 0, "gmt", tZONE, 0*HOUR }, /* Greenwich Mean */ + { 0, "ut", tZONE, 0*HOUR }, /* Universal (Coordinated) */ + { 0, "utc", tZONE, 0*HOUR }, + { 0, "wet", tZONE, 0*HOUR }, /* Western European */ + { 0, "bst", tDAYZONE, 0*HOUR }, /* British Summer */ + { 0, "wat", tZONE, 1*HOUR }, /* West Africa */ + { 0, "at", tZONE, 2*HOUR }, /* Azores */ + /* { 0, "bst", tZONE, 3*HOUR }, */ /* Brazil Standard: Conflict */ + /* { 0, "gst", tZONE, 3*HOUR }, */ /* Greenland Standard: Conflict*/ + { 0, "nft", tZONE, 3*HOUR+30*MINUTE }, /* Newfoundland */ + { 0, "nst", tZONE, 3*HOUR+30*MINUTE }, /* Newfoundland Standard */ + { 0, "ndt", tDAYZONE, 3*HOUR+30*MINUTE }, /* Newfoundland Daylight */ + { 0, "ast", tZONE, 4*HOUR }, /* Atlantic Standard */ + { 0, "adt", tDAYZONE, 4*HOUR }, /* Atlantic Daylight */ + { 0, "est", tZONE, 5*HOUR }, /* Eastern Standard */ + { 0, "edt", tDAYZONE, 5*HOUR }, /* Eastern Daylight */ + { 0, "cst", tZONE, 6*HOUR }, /* Central Standard */ + { 0, "cdt", tDAYZONE, 6*HOUR }, /* Central Daylight */ + { 0, "mst", tZONE, 7*HOUR }, /* Mountain Standard */ + { 0, "mdt", tDAYZONE, 7*HOUR }, /* Mountain Daylight */ + { 0, "pst", tZONE, 8*HOUR }, /* Pacific Standard */ + { 0, "pdt", tDAYZONE, 8*HOUR }, /* Pacific Daylight */ + { 0, "yst", tZONE, 9*HOUR }, /* Yukon Standard */ + { 0, "ydt", tDAYZONE, 9*HOUR }, /* Yukon Daylight */ + { 0, "hst", tZONE, 10*HOUR }, /* Hawaii Standard */ + { 0, "hdt", tDAYZONE, 10*HOUR }, /* Hawaii Daylight */ + { 0, "cat", tZONE, 10*HOUR }, /* Central Alaska */ + { 0, "ahst", tZONE, 10*HOUR }, /* Alaska-Hawaii Standard */ + { 0, "nt", tZONE, 11*HOUR }, /* Nome */ + { 0, "idlw", tZONE, 12*HOUR }, /* Intl Date Line West */ + { 0, "cet", tZONE, -1*HOUR }, /* Central European */ + { 0, "met", tZONE, -1*HOUR }, /* Middle European */ + { 0, "mewt", tZONE, -1*HOUR }, /* Middle European Winter */ + { 0, "mest", tDAYZONE, -1*HOUR }, /* Middle European Summer */ + { 0, "swt", tZONE, -1*HOUR }, /* Swedish Winter */ + { 0, "sst", tDAYZONE, -1*HOUR }, /* Swedish Summer */ + { 0, "fwt", tZONE, -1*HOUR }, /* French Winter */ + { 0, "fst", tDAYZONE, -1*HOUR }, /* French Summer */ + { 0, "eet", tZONE, -2*HOUR }, /* Eastern Eur, USSR Zone 1 */ + { 0, "bt", tZONE, -3*HOUR }, /* Baghdad, USSR Zone 2 */ + { 0, "it", tZONE, -3*HOUR-30*MINUTE },/* Iran */ + { 0, "zp4", tZONE, -4*HOUR }, /* USSR Zone 3 */ + { 0, "zp5", tZONE, -5*HOUR }, /* USSR Zone 4 */ + { 0, "ist", tZONE, -5*HOUR-30*MINUTE },/* Indian Standard */ + { 0, "zp6", tZONE, -6*HOUR }, /* USSR Zone 5 */ + /* { 0, "nst", tZONE, -6.5*HOUR }, */ /* North Sumatra: Conflict */ + /* { 0, "sst", tZONE, -7*HOUR }, */ /* So Sumatra, USSR 6: Conflict */ + { 0, "wast", tZONE, -7*HOUR }, /* West Australian Standard */ + { 0, "wadt", tDAYZONE, -7*HOUR }, /* West Australian Daylight */ + { 0, "jt", tZONE, -7*HOUR-30*MINUTE },/* Java (3pm in Cronusland!)*/ + { 0, "cct", tZONE, -8*HOUR }, /* China Coast, USSR Zone 7 */ + { 0, "jst", tZONE, -9*HOUR }, /* Japan Std, USSR Zone 8 */ + { 0, "cast", tZONE, -9*HOUR-30*MINUTE },/* Ctrl Australian Std */ + { 0, "cadt", tDAYZONE, -9*HOUR-30*MINUTE },/* Ctrl Australian Daylt */ + { 0, "east", tZONE, -10*HOUR }, /* Eastern Australian Std */ + { 0, "eadt", tDAYZONE, -10*HOUR }, /* Eastern Australian Daylt */ + { 0, "gst", tZONE, -10*HOUR }, /* Guam Std, USSR Zone 9 */ + { 0, "nzt", tZONE, -12*HOUR }, /* New Zealand */ + { 0, "nzst", tZONE, -12*HOUR }, /* New Zealand Standard */ + { 0, "nzdt", tDAYZONE, -12*HOUR }, /* New Zealand Daylight */ + { 0, "idle", tZONE, -12*HOUR }, /* Intl Date Line East */ + + { 0, "dst", tDST, 0 }, + + /* Time units. */ + { 4, "years", tMONTH_UNIT, 12 }, + { 5, "months", tMONTH_UNIT, 1 }, + { 9, "fortnights", tSEC_UNIT, 14 * DAY }, + { 4, "weeks", tSEC_UNIT, 7 * DAY }, + { 3, "days", tSEC_UNIT, DAY }, + { 4, "hours", tSEC_UNIT, HOUR }, + { 3, "minutes", tSEC_UNIT, MINUTE }, + { 3, "seconds", tSEC_UNIT, 1 }, + + /* Relative-time words. */ + { 0, "tomorrow", tSEC_UNIT, DAY }, + { 0, "yesterday", tSEC_UNIT, -DAY }, + { 0, "today", tSEC_UNIT, 0 }, + { 0, "now", tSEC_UNIT, 0 }, + { 0, "last", tUNUMBER, -1 }, + { 0, "this", tSEC_UNIT, 0 }, + { 0, "next", tUNUMBER, 2 }, + { 0, "first", tUNUMBER, 1 }, + { 0, "1st", tUNUMBER, 1 }, +/* { 0, "second", tUNUMBER, 2 }, */ + { 0, "2nd", tUNUMBER, 2 }, + { 0, "third", tUNUMBER, 3 }, + { 0, "3rd", tUNUMBER, 3 }, + { 0, "fourth", tUNUMBER, 4 }, + { 0, "4th", tUNUMBER, 4 }, + { 0, "fifth", tUNUMBER, 5 }, + { 0, "5th", tUNUMBER, 5 }, + { 0, "sixth", tUNUMBER, 6 }, + { 0, "seventh", tUNUMBER, 7 }, + { 0, "eighth", tUNUMBER, 8 }, + { 0, "ninth", tUNUMBER, 9 }, + { 0, "tenth", tUNUMBER, 10 }, + { 0, "eleventh", tUNUMBER, 11 }, + { 0, "twelfth", tUNUMBER, 12 }, + { 0, "ago", tAGO, 1 }, + + /* Military timezones. */ + { 0, "a", tZONE, 1*HOUR }, + { 0, "b", tZONE, 2*HOUR }, + { 0, "c", tZONE, 3*HOUR }, + { 0, "d", tZONE, 4*HOUR }, + { 0, "e", tZONE, 5*HOUR }, + { 0, "f", tZONE, 6*HOUR }, + { 0, "g", tZONE, 7*HOUR }, + { 0, "h", tZONE, 8*HOUR }, + { 0, "i", tZONE, 9*HOUR }, + { 0, "k", tZONE, 10*HOUR }, + { 0, "l", tZONE, 11*HOUR }, + { 0, "m", tZONE, 12*HOUR }, + { 0, "n", tZONE, -1*HOUR }, + { 0, "o", tZONE, -2*HOUR }, + { 0, "p", tZONE, -3*HOUR }, + { 0, "q", tZONE, -4*HOUR }, + { 0, "r", tZONE, -5*HOUR }, + { 0, "s", tZONE, -6*HOUR }, + { 0, "t", tZONE, -7*HOUR }, + { 0, "u", tZONE, -8*HOUR }, + { 0, "v", tZONE, -9*HOUR }, + { 0, "w", tZONE, -10*HOUR }, + { 0, "x", tZONE, -11*HOUR }, + { 0, "y", tZONE, -12*HOUR }, + { 0, "z", tZONE, 0*HOUR }, + + /* End of table. */ + { 0, NULL, 0, 0 } +}; + +/* + * Year is either: + * = A number from 0 to 99, which means a year from 1970 to 2069, or + * = The actual year (>=100). + */ +static time_t +Convert(time_t Month, time_t Day, time_t Year, + time_t Hours, time_t Minutes, time_t Seconds, + time_t Timezone, enum DSTMODE DSTmode) +{ + static int DaysInMonth[12] = { + 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 + }; + time_t Julian; + int i; + + if (Year < 69) + Year += 2000; + else if (Year < 100) + Year += 1900; + DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) + ? 29 : 28; + /* Checking for 2038 bogusly assumes that time_t is 32 bits. But + I'm too lazy to try to check for time_t overflow in another way. */ + if (Year < EPOCH || Year > 2038 + || Month < 1 || Month > 12 + /* Lint fluff: "conversion from long may lose accuracy" */ + || Day < 1 || Day > DaysInMonth[(int)--Month] + || Hours < 0 || Hours > 23 + || Minutes < 0 || Minutes > 59 + || Seconds < 0 || Seconds > 59) + return -1; + + Julian = Day - 1; + for (i = 0; i < Month; i++) + Julian += DaysInMonth[i]; + for (i = EPOCH; i < Year; i++) + Julian += 365 + (i % 4 == 0); + Julian *= DAY; + Julian += Timezone; + Julian += Hours * HOUR + Minutes * MINUTE + Seconds; + if (DSTmode == DSTon + || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst)) + Julian -= HOUR; + return Julian; +} + + +static time_t +DSTcorrect(time_t Start, time_t Future) +{ + time_t StartDay; + time_t FutureDay; + + StartDay = (localtime(&Start)->tm_hour + 1) % 24; + FutureDay = (localtime(&Future)->tm_hour + 1) % 24; + return (Future - Start) + (StartDay - FutureDay) * HOUR; +} + + +static time_t +RelativeDate(time_t Start, time_t zone, int dstmode, + time_t DayOrdinal, time_t DayNumber) +{ + struct tm *tm; + time_t t, now; + + t = Start - zone; + tm = gmtime(&t); + now = Start; + now += DAY * ((DayNumber - tm->tm_wday + 7) % 7); + now += 7 * DAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); + if (dstmode == DSTmaybe) + return DSTcorrect(Start, now); + return now - Start; +} + + +static time_t +RelativeMonth(time_t Start, time_t Timezone, time_t RelMonth) +{ + struct tm *tm; + time_t Month; + time_t Year; + + if (RelMonth == 0) + return 0; + tm = localtime(&Start); + Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth; + Year = Month / 12; + Month = Month % 12 + 1; + return DSTcorrect(Start, + Convert(Month, (time_t)tm->tm_mday, Year, + (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec, + Timezone, DSTmaybe)); +} + +/* + * Tokenizer. + */ +static int +nexttoken(char **in, time_t *value) +{ + char c; + char buff[64]; + + for ( ; ; ) { + while (isspace((unsigned char)**in)) + ++*in; + + /* Skip parenthesized comments. */ + if (**in == '(') { + int Count = 0; + do { + c = *(*in)++; + if (c == '\0') + return c; + if (c == '(') + Count++; + else if (c == ')') + Count--; + } while (Count > 0); + continue; + } + + /* Try the next token in the word table first. */ + /* This allows us to match "2nd", for example. */ + { + char *src = *in; + const struct LEXICON *tp; + unsigned i = 0; + + /* Force to lowercase and strip '.' characters. */ + while (*src != '\0' + && (isalnum((unsigned char)*src) || *src == '.') + && i < sizeof(buff)-1) { + if (*src != '.') { + if (isupper((unsigned char)*src)) + buff[i++] = tolower((unsigned char)*src); + else + buff[i++] = *src; + } + src++; + } + buff[i] = '\0'; + + /* + * Find the first match. If the word can be + * abbreviated, make sure we match at least + * the minimum abbreviation. + */ + for (tp = TimeWords; tp->name; tp++) { + size_t abbrev = tp->abbrev; + if (abbrev == 0) + abbrev = strlen(tp->name); + if (strlen(buff) >= abbrev + && strncmp(tp->name, buff, strlen(buff)) + == 0) { + /* Skip over token. */ + *in = src; + /* Return the match. */ + *value = tp->value; + return tp->type; + } + } + } + + /* + * Not in the word table, maybe it's a number. Note: + * Because '-' and '+' have other special meanings, I + * don't deal with signed numbers here. + */ + if (isdigit((unsigned char)(c = **in))) { + for (*value = 0; isdigit((unsigned char)(c = *(*in)++)); ) + *value = 10 * *value + c - '0'; + (*in)--; + return (tUNUMBER); + } + + return *(*in)++; + } +} + +#define TM_YEAR_ORIGIN 1900 + +/* Yield A - B, measured in seconds. */ +static long +difftm (struct tm *a, struct tm *b) +{ + int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); + int by = b->tm_year + (TM_YEAR_ORIGIN - 1); + int days = ( + /* difference in day of year */ + a->tm_yday - b->tm_yday + /* + intervening leap days */ + + ((ay >> 2) - (by >> 2)) + - (ay/100 - by/100) + + ((ay/100 >> 2) - (by/100 >> 2)) + /* + difference in years * 365 */ + + (long)(ay-by) * 365 + ); + return (days * DAY + (a->tm_hour - b->tm_hour) * HOUR + + (a->tm_min - b->tm_min) * MINUTE + + (a->tm_sec - b->tm_sec)); +} + +/* + * + * The public function. + * + * TODO: tokens[] array should be dynamically sized. + */ +time_t +get_date(time_t now, char *p) +{ + struct token tokens[256]; + struct gdstate _gds; + struct token *lasttoken; + struct gdstate *gds; + struct tm local, *tm; + struct tm gmt, *gmt_ptr; + time_t Start; + time_t tod; + long tzone; + + /* Clear out the parsed token array. */ + memset(tokens, 0, sizeof(tokens)); + /* Initialize the parser state. */ + memset(&_gds, 0, sizeof(_gds)); + gds = &_gds; + + /* Look up the current time. */ + memset(&local, 0, sizeof(local)); + tm = localtime (&now); + if (tm == NULL) + return -1; + local = *tm; + + /* Look up UTC if we can and use that to determine the current + * timezone offset. */ + memset(&gmt, 0, sizeof(gmt)); + gmt_ptr = gmtime (&now); + if (gmt_ptr != NULL) { + /* Copy, in case localtime and gmtime use the same buffer. */ + gmt = *gmt_ptr; + } + if (gmt_ptr != NULL) + tzone = difftm (&gmt, &local); + else + /* This system doesn't understand timezones; fake it. */ + tzone = 0; + if(local.tm_isdst) + tzone += HOUR; + + /* Tokenize the input string. */ + lasttoken = tokens; + while ((lasttoken->token = nexttoken(&p, &lasttoken->value)) != 0) { + ++lasttoken; + if (lasttoken > tokens + 255) + return -1; + } + gds->tokenp = tokens; + + /* Match phrases until we run out of input tokens. */ + while (gds->tokenp < lasttoken) { + if (!phrase(gds)) + return -1; + } + + /* Use current local timezone if none was specified. */ + if (!gds->HaveZone) { + gds->Timezone = tzone; + gds->DSTmode = DSTmaybe; + } + + /* If a timezone was specified, use that for generating the default + * time components instead of the local timezone. */ + if (gds->HaveZone && gmt_ptr != NULL) { + now -= gds->Timezone; + gmt_ptr = gmtime (&now); + if (gmt_ptr != NULL) + local = *gmt_ptr; + now += gds->Timezone; + } + + if (!gds->HaveYear) + gds->Year = local.tm_year + 1900; + if (!gds->HaveMonth) + gds->Month = local.tm_mon + 1; + if (!gds->HaveDay) + gds->Day = local.tm_mday; + /* Note: No default for hour/min/sec; a specifier that just + * gives date always refers to 00:00 on that date. */ + + /* If we saw more than one time, timezone, weekday, year, month, + * or day, then give up. */ + if (gds->HaveTime > 1 || gds->HaveZone > 1 || gds->HaveWeekDay > 1 + || gds->HaveYear > 1 || gds->HaveMonth > 1 || gds->HaveDay > 1) + return -1; + + /* Compute an absolute time based on whatever absolute information + * we collected. */ + if (gds->HaveYear || gds->HaveMonth || gds->HaveDay + || gds->HaveTime || gds->HaveWeekDay) { + Start = Convert(gds->Month, gds->Day, gds->Year, + gds->Hour, gds->Minutes, gds->Seconds, + gds->Timezone, gds->DSTmode); + if (Start < 0) + return -1; + } else { + Start = now; + if (!gds->HaveRel) + Start -= local.tm_hour * HOUR + local.tm_min * MINUTE + + local.tm_sec; + } + + /* Add the relative offset. */ + Start += gds->RelSeconds; + Start += RelativeMonth(Start, gds->Timezone, gds->RelMonth); + + /* Adjust for day-of-week offsets. */ + if (gds->HaveWeekDay + && !(gds->HaveYear || gds->HaveMonth || gds->HaveDay)) { + tod = RelativeDate(Start, gds->Timezone, + gds->DSTmode, gds->DayOrdinal, gds->DayNumber); + Start += tod; + } + + /* -1 is an error indicator, so return 0 instead of -1 if + * that's the actual time. */ + return Start == -1 ? 0 : Start; +} + + +#if defined(TEST) + +/* ARGSUSED */ +int +main(int argc, char **argv) +{ + time_t d; + + while (*++argv != NULL) { + (void)printf("Input: %s\n", *argv); + d = get_date(*argv); + if (d == -1) + (void)printf("Bad format - couldn't convert.\n"); + else + (void)printf("Output: %s\n", ctime(&d)); + } + exit(0); + /* NOTREACHED */ +} +#endif /* defined(TEST) */ diff --git a/external/bsd/libarchive/dist/tar/read.c b/external/bsd/libarchive/dist/tar/read.c new file mode 100644 index 000000000..aaaacac0d --- /dev/null +++ b/external/bsd/libarchive/dist/tar/read.c @@ -0,0 +1,437 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "bsdtar_platform.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/read.c,v 1.40 2008/08/21 06:41:14 kientzle Exp $"); + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_GRP_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_PWD_H +#include +#endif +#ifdef HAVE_STDINT_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_TIME_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif + +#include "bsdtar.h" +#include "err.h" + +struct progress_data { + struct bsdtar *bsdtar; + struct archive *archive; + struct archive_entry *entry; +}; + +static void list_item_verbose(struct bsdtar *, FILE *, + struct archive_entry *); +static void read_archive(struct bsdtar *bsdtar, char mode); + +void +tar_mode_t(struct bsdtar *bsdtar) +{ + read_archive(bsdtar, 't'); + if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0) + bsdtar->return_value = 1; +} + +void +tar_mode_x(struct bsdtar *bsdtar) +{ + read_archive(bsdtar, 'x'); + + if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0) + bsdtar->return_value = 1; +} + +static void +progress_func(void *cookie) +{ + struct progress_data *progress_data = cookie; + struct bsdtar *bsdtar = progress_data->bsdtar; + struct archive *a = progress_data->archive; + struct archive_entry *entry = progress_data->entry; + uint64_t comp, uncomp; + + if (!need_report()) + return; + + if (bsdtar->verbose) + fprintf(stderr, "\n"); + if (a != NULL) { + comp = archive_position_compressed(a); + uncomp = archive_position_uncompressed(a); + fprintf(stderr, + "In: %s bytes, compression %d%%;", + tar_i64toa(comp), (int)((uncomp - comp) * 100 / uncomp)); + fprintf(stderr, " Out: %d files, %s bytes\n", + archive_file_count(a), tar_i64toa(uncomp)); + } + if (entry != NULL) { + safe_fprintf(stderr, "Current: %s", + archive_entry_pathname(entry)); + fprintf(stderr, " (%s bytes)\n", + tar_i64toa(archive_entry_size(entry))); + } +} + +/* + * Handle 'x' and 't' modes. + */ +static void +read_archive(struct bsdtar *bsdtar, char mode) +{ + struct progress_data progress_data; + FILE *out; + struct archive *a; + struct archive_entry *entry; + const struct stat *st; + int r; + + while (*bsdtar->argv) { + lafe_include(&bsdtar->matching, *bsdtar->argv); + bsdtar->argv++; + } + + if (bsdtar->names_from_file != NULL) + lafe_include_from_file(&bsdtar->matching, + bsdtar->names_from_file, bsdtar->option_null); + + a = archive_read_new(); + if (bsdtar->compress_program != NULL) + archive_read_support_compression_program(a, bsdtar->compress_program); + else + archive_read_support_compression_all(a); + archive_read_support_format_all(a); + if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options)) + lafe_errc(1, 0, "%s", archive_error_string(a)); + if (archive_read_open_file(a, bsdtar->filename, + bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block : + DEFAULT_BYTES_PER_BLOCK)) + lafe_errc(1, 0, "Error opening archive: %s", + archive_error_string(a)); + + do_chdir(bsdtar); + + if (mode == 'x') { + /* Set an extract callback so that we can handle SIGINFO. */ + progress_data.bsdtar = bsdtar; + progress_data.archive = a; + archive_read_extract_set_progress_callback(a, progress_func, + &progress_data); + } + + if (mode == 'x' && bsdtar->option_chroot) { +#if HAVE_CHROOT + if (chroot(".") != 0) + lafe_errc(1, errno, "Can't chroot to \".\""); +#else + lafe_errc(1, 0, + "chroot isn't supported on this platform"); +#endif + } + + for (;;) { + /* Support --fast-read option */ + if (bsdtar->option_fast_read && + lafe_unmatched_inclusions(bsdtar->matching) == 0) + break; + + r = archive_read_next_header(a, &entry); + progress_data.entry = entry; + if (r == ARCHIVE_EOF) + break; + if (r < ARCHIVE_OK) + lafe_warnc(0, "%s", archive_error_string(a)); + if (r <= ARCHIVE_WARN) + bsdtar->return_value = 1; + if (r == ARCHIVE_RETRY) { + /* Retryable error: try again */ + lafe_warnc(0, "Retrying..."); + continue; + } + if (r == ARCHIVE_FATAL) + break; + + if (bsdtar->option_numeric_owner) { + archive_entry_set_uname(entry, NULL); + archive_entry_set_gname(entry, NULL); + } + + /* + * Exclude entries that are too old. + */ + st = archive_entry_stat(entry); + if (bsdtar->newer_ctime_sec > 0) { + if (st->st_ctime < bsdtar->newer_ctime_sec) + continue; /* Too old, skip it. */ + if (st->st_ctime == bsdtar->newer_ctime_sec + && ARCHIVE_STAT_CTIME_NANOS(st) + <= bsdtar->newer_ctime_nsec) + continue; /* Too old, skip it. */ + } + if (bsdtar->newer_mtime_sec > 0) { + if (st->st_mtime < bsdtar->newer_mtime_sec) + continue; /* Too old, skip it. */ + if (st->st_mtime == bsdtar->newer_mtime_sec + && ARCHIVE_STAT_MTIME_NANOS(st) + <= bsdtar->newer_mtime_nsec) + continue; /* Too old, skip it. */ + } + + /* + * Note that pattern exclusions are checked before + * pathname rewrites are handled. This gives more + * control over exclusions, since rewrites always lose + * information. (For example, consider a rewrite + * s/foo[0-9]/foo/. If we check exclusions after the + * rewrite, there would be no way to exclude foo1/bar + * while allowing foo2/bar.) + */ + if (lafe_excluded(bsdtar->matching, archive_entry_pathname(entry))) + continue; /* Excluded by a pattern test. */ + + if (mode == 't') { + /* Perversely, gtar uses -O to mean "send to stderr" + * when used with -t. */ + out = bsdtar->option_stdout ? stderr : stdout; + + /* + * TODO: Provide some reasonable way to + * preview rewrites. gtar always displays + * the unedited path in -t output, which means + * you cannot easily preview rewrites. + */ + if (bsdtar->verbose < 2) + safe_fprintf(out, "%s", + archive_entry_pathname(entry)); + else + list_item_verbose(bsdtar, out, entry); + fflush(out); + r = archive_read_data_skip(a); + if (r == ARCHIVE_WARN) { + fprintf(out, "\n"); + lafe_warnc(0, "%s", + archive_error_string(a)); + } + if (r == ARCHIVE_RETRY) { + fprintf(out, "\n"); + lafe_warnc(0, "%s", + archive_error_string(a)); + } + if (r == ARCHIVE_FATAL) { + fprintf(out, "\n"); + lafe_warnc(0, "%s", + archive_error_string(a)); + bsdtar->return_value = 1; + break; + } + fprintf(out, "\n"); + } else { + /* Note: some rewrite failures prevent extraction. */ + if (edit_pathname(bsdtar, entry)) + continue; /* Excluded by a rewrite failure. */ + + if (bsdtar->option_interactive && + !yes("extract '%s'", archive_entry_pathname(entry))) + continue; + + /* + * Format here is from SUSv2, including the + * deferred '\n'. + */ + if (bsdtar->verbose) { + safe_fprintf(stderr, "x %s", + archive_entry_pathname(entry)); + fflush(stderr); + } + + // TODO siginfo_printinfo(bsdtar, 0); + + if (bsdtar->option_stdout) + r = archive_read_data_into_fd(a, 1); + else + r = archive_read_extract(a, entry, + bsdtar->extract_flags); + if (r != ARCHIVE_OK) { + if (!bsdtar->verbose) + safe_fprintf(stderr, "%s", + archive_entry_pathname(entry)); + safe_fprintf(stderr, ": %s", + archive_error_string(a)); + if (!bsdtar->verbose) + fprintf(stderr, "\n"); + bsdtar->return_value = 1; + } + if (bsdtar->verbose) + fprintf(stderr, "\n"); + if (r == ARCHIVE_FATAL) + break; + } + } + + + r = archive_read_close(a); + if (r != ARCHIVE_OK) + lafe_warnc(0, "%s", archive_error_string(a)); + if (r <= ARCHIVE_WARN) + bsdtar->return_value = 1; + + if (bsdtar->verbose > 2) + fprintf(stdout, "Archive Format: %s, Compression: %s\n", + archive_format_name(a), archive_compression_name(a)); + + archive_read_finish(a); +} + + +/* + * Display information about the current file. + * + * The format here roughly duplicates the output of 'ls -l'. + * This is based on SUSv2, where 'tar tv' is documented as + * listing additional information in an "unspecified format," + * and 'pax -l' is documented as using the same format as 'ls -l'. + */ +static void +list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry) +{ + char tmp[100]; + size_t w; + const char *p; + const char *fmt; + time_t tim; + static time_t now; + + /* + * We avoid collecting the entire list in memory at once by + * listing things as we see them. However, that also means we can't + * just pre-compute the field widths. Instead, we start with guesses + * and just widen them as necessary. These numbers are completely + * arbitrary. + */ + if (!bsdtar->u_width) { + bsdtar->u_width = 6; + bsdtar->gs_width = 13; + } + if (!now) + time(&now); + fprintf(out, "%s %d ", + archive_entry_strmode(entry), + archive_entry_nlink(entry)); + + /* Use uname if it's present, else uid. */ + p = archive_entry_uname(entry); + if ((p == NULL) || (*p == '\0')) { + sprintf(tmp, "%lu ", + (unsigned long)archive_entry_uid(entry)); + p = tmp; + } + w = strlen(p); + if (w > bsdtar->u_width) + bsdtar->u_width = w; + fprintf(out, "%-*s ", (int)bsdtar->u_width, p); + + /* Use gname if it's present, else gid. */ + p = archive_entry_gname(entry); + if (p != NULL && p[0] != '\0') { + fprintf(out, "%s", p); + w = strlen(p); + } else { + sprintf(tmp, "%lu", + (unsigned long)archive_entry_gid(entry)); + w = strlen(tmp); + fprintf(out, "%s", tmp); + } + + /* + * Print device number or file size, right-aligned so as to make + * total width of group and devnum/filesize fields be gs_width. + * If gs_width is too small, grow it. + */ + if (archive_entry_filetype(entry) == AE_IFCHR + || archive_entry_filetype(entry) == AE_IFBLK) { + sprintf(tmp, "%lu,%lu", + (unsigned long)archive_entry_rdevmajor(entry), + (unsigned long)archive_entry_rdevminor(entry)); + } else { + strcpy(tmp, tar_i64toa(archive_entry_size(entry))); + } + if (w + strlen(tmp) >= bsdtar->gs_width) + bsdtar->gs_width = w+strlen(tmp)+1; + fprintf(out, "%*s", (int)(bsdtar->gs_width - w), tmp); + + /* Format the time using 'ls -l' conventions. */ + tim = archive_entry_mtime(entry); +#define HALF_YEAR (time_t)365 * 86400 / 2 +#if defined(_WIN32) && !defined(__CYGWIN__) +#define DAY_FMT "%d" /* Windows' strftime function does not support %e format. */ +#else +#define DAY_FMT "%e" /* Day number without leading zeros */ +#endif + if (tim < now - HALF_YEAR || tim > now + HALF_YEAR) + fmt = bsdtar->day_first ? DAY_FMT " %b %Y" : "%b " DAY_FMT " %Y"; + else + fmt = bsdtar->day_first ? DAY_FMT " %b %H:%M" : "%b " DAY_FMT " %H:%M"; + strftime(tmp, sizeof(tmp), fmt, localtime(&tim)); + fprintf(out, " %s ", tmp); + safe_fprintf(out, "%s", archive_entry_pathname(entry)); + + /* Extra information for links. */ + if (archive_entry_hardlink(entry)) /* Hard link */ + safe_fprintf(out, " link to %s", + archive_entry_hardlink(entry)); + else if (archive_entry_symlink(entry)) /* Symbolic link */ + safe_fprintf(out, " -> %s", archive_entry_symlink(entry)); +} diff --git a/external/bsd/libarchive/dist/tar/subst.c b/external/bsd/libarchive/dist/tar/subst.c new file mode 100644 index 000000000..398205419 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/subst.c @@ -0,0 +1,289 @@ +/*- + * Copyright (c) 2008 Joerg Sonnenberger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "bsdtar_platform.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/subst.c,v 1.4 2008/06/15 10:08:16 kientzle Exp $"); + +#if HAVE_REGEX_H +#include "bsdtar.h" + +#include +#include +#include +#include + +#ifndef REG_BASIC +#define REG_BASIC 0 +#endif + +#include "err.h" + +struct subst_rule { + struct subst_rule *next; + regex_t re; + char *result; + unsigned int global:1, print:1, symlink:1; +}; + +struct substitution { + struct subst_rule *first_rule, *last_rule; +}; + +static void +init_substitution(struct bsdtar *bsdtar) +{ + struct substitution *subst; + + bsdtar->substitution = subst = malloc(sizeof(*subst)); + if (subst == NULL) + lafe_errc(1, errno, "Out of memory"); + subst->first_rule = subst->last_rule = NULL; +} + +void +add_substitution(struct bsdtar *bsdtar, const char *rule_text) +{ + struct subst_rule *rule; + struct substitution *subst; + const char *end_pattern, *start_subst; + char *pattern; + int r; + + if ((subst = bsdtar->substitution) == NULL) { + init_substitution(bsdtar); + subst = bsdtar->substitution; + } + + rule = malloc(sizeof(*rule)); + if (rule == NULL) + lafe_errc(1, errno, "Out of memory"); + rule->next = NULL; + + if (subst->last_rule == NULL) + subst->first_rule = rule; + else + subst->last_rule->next = rule; + subst->last_rule = rule; + + if (*rule_text == '\0') + lafe_errc(1, 0, "Empty replacement string"); + end_pattern = strchr(rule_text + 1, *rule_text); + if (end_pattern == NULL) + lafe_errc(1, 0, "Invalid replacement string"); + + pattern = malloc(end_pattern - rule_text); + if (pattern == NULL) + lafe_errc(1, errno, "Out of memory"); + memcpy(pattern, rule_text + 1, end_pattern - rule_text - 1); + pattern[end_pattern - rule_text - 1] = '\0'; + + if ((r = regcomp(&rule->re, pattern, REG_BASIC)) != 0) { + char buf[80]; + regerror(r, &rule->re, buf, sizeof(buf)); + lafe_errc(1, 0, "Invalid regular expression: %s", buf); + } + free(pattern); + + start_subst = end_pattern + 1; + end_pattern = strchr(start_subst, *rule_text); + if (end_pattern == NULL) + lafe_errc(1, 0, "Invalid replacement string"); + + rule->result = malloc(end_pattern - start_subst + 1); + if (rule->result == NULL) + lafe_errc(1, errno, "Out of memory"); + memcpy(rule->result, start_subst, end_pattern - start_subst); + rule->result[end_pattern - start_subst] = '\0'; + + rule->global = 0; + rule->print = 0; + rule->symlink = 0; + + while (*++end_pattern) { + switch (*end_pattern) { + case 'g': + case 'G': + rule->global = 1; + break; + case 'p': + case 'P': + rule->print = 1; + break; + case 's': + case 'S': + rule->symlink = 1; + break; + default: + lafe_errc(1, 0, "Invalid replacement flag %c", *end_pattern); + } + } +} + +static void +realloc_strncat(char **str, const char *append, size_t len) +{ + char *new_str; + size_t old_len; + + if (*str == NULL) + old_len = 0; + else + old_len = strlen(*str); + + new_str = malloc(old_len + len + 1); + if (new_str == NULL) + lafe_errc(1, errno, "Out of memory"); + memcpy(new_str, *str, old_len); + memcpy(new_str + old_len, append, len); + new_str[old_len + len] = '\0'; + free(*str); + *str = new_str; +} + +static void +realloc_strcat(char **str, const char *append) +{ + char *new_str; + size_t old_len; + + if (*str == NULL) + old_len = 0; + else + old_len = strlen(*str); + + new_str = malloc(old_len + strlen(append) + 1); + if (new_str == NULL) + lafe_errc(1, errno, "Out of memory"); + memcpy(new_str, *str, old_len); + strcpy(new_str + old_len, append); + free(*str); + *str = new_str; +} + +int +apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int symlink_only) +{ + const char *path = name; + regmatch_t matches[10]; + size_t i, j; + struct subst_rule *rule; + struct substitution *subst; + int c, got_match, print_match; + + *result = NULL; + + if ((subst = bsdtar->substitution) == NULL) + return 0; + + got_match = 0; + print_match = 0; + + for (rule = subst->first_rule; rule != NULL; rule = rule->next) { + if (symlink_only && !rule->symlink) + continue; + if (regexec(&rule->re, name, 10, matches, 0)) + continue; + + got_match = 1; + print_match |= rule->print; + realloc_strncat(result, name, matches[0].rm_so); + + for (i = 0, j = 0; rule->result[i] != '\0'; ++i) { + if (rule->result[i] == '~') { + realloc_strncat(result, rule->result + j, i - j); + realloc_strncat(result, name, matches[0].rm_eo); + j = i + 1; + continue; + } + if (rule->result[i] != '\\') + continue; + + ++i; + c = rule->result[i]; + switch (c) { + case '~': + case '\\': + realloc_strncat(result, rule->result + j, i - j - 1); + j = i; + break; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + realloc_strncat(result, rule->result + j, i - j - 1); + if ((size_t)(c - '0') > (size_t)(rule->re.re_nsub)) { + free(*result); + *result = NULL; + return -1; + } + realloc_strncat(result, name + matches[c - '0'].rm_so, matches[c - '0'].rm_eo - matches[c - '0'].rm_so); + j = i + 1; + break; + default: + /* Just continue; */ + break; + } + + } + + realloc_strcat(result, rule->result + j); + + name += matches[0].rm_eo; + + if (!rule->global) + break; + } + + if (got_match) + realloc_strcat(result, name); + + if (print_match) + fprintf(stderr, "%s >> %s\n", path, *result); + + return got_match; +} + +void +cleanup_substitution(struct bsdtar *bsdtar) +{ + struct subst_rule *rule; + struct substitution *subst; + + if ((subst = bsdtar->substitution) == NULL) + return; + + while ((rule = subst->first_rule) != NULL) { + subst->first_rule = rule->next; + free(rule->result); + free(rule); + } + free(subst); +} +#endif /* HAVE_REGEX_H */ diff --git a/external/bsd/libarchive/dist/tar/test/CMakeLists.txt b/external/bsd/libarchive/dist/tar/test/CMakeLists.txt new file mode 100644 index 000000000..6064e1424 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/CMakeLists.txt @@ -0,0 +1,67 @@ +############################################ +# +# How to build bsdtar_test +# +############################################ +IF(ENABLE_TAR AND ENABLE_TEST) + SET(bsdtar_test_SOURCES + ../getdate.c + main.c + test.h + test_0.c + test_basic.c + test_copy.c + test_empty_mtree.c + test_getdate.c + test_help.c + test_option_T_upper.c + test_option_q.c + test_option_r.c + test_option_s.c + test_patterns.c + test_stdio.c + test_strip_components.c + test_symlink_dir.c + test_version.c + test_windows.c + ) + IF(WIN32 AND NOT CYGWIN) + LIST(APPEND bsdtar_test_SOURCES ../bsdtar_windows.c) + LIST(APPEND bsdtar_test_SOURCES ../bsdtar_windows.h) + ENDIF(WIN32 AND NOT CYGWIN) + + # + # Register target + # + ADD_EXECUTABLE(bsdtar_test ${bsdtar_test_SOURCES}) + SET_PROPERTY(TARGET bsdtar_test PROPERTY COMPILE_DEFINITIONS LIST_H) + + # + # Generate list.h by grepping DEFINE_TEST() lines out of the C sources. + # + GENERATE_LIST_H(${CMAKE_CURRENT_BINARY_DIR}/list.h + ${CMAKE_CURRENT_LIST_FILE} ${bsdtar_test_SOURCES}) + SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_BINARY_DIR}) + + # list.h has a line DEFINE_TEST(testname) for every + # test. We can use that to define the tests for cmake by + # defining a DEFINE_TEST macro and reading list.h in. + MACRO (DEFINE_TEST _testname) + ADD_TEST_28( + NAME bsdtar_${_testname} + COMMAND bsdtar_test -vv + -p $ + -r ${CMAKE_CURRENT_SOURCE_DIR} + ${_testname}) + ENDMACRO (DEFINE_TEST _testname) + + INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h) + + # Experimental new test handling + ADD_CUSTOM_TARGET(run_bsdtar_test + COMMAND bsdtar_test -p ${BSDTAR} -r ${CMAKE_CURRENT_SOURCE_DIR}) + ADD_DEPENDENCIES(run_bsdtar_test bsdtar) + ADD_DEPENDENCIES(run_all_tests run_bsdtar_test) + +ENDIF (ENABLE_TAR AND ENABLE_TEST) diff --git a/external/bsd/libarchive/dist/tar/test/list.h b/external/bsd/libarchive/dist/tar/test/list.h new file mode 100644 index 000000000..4b91fb684 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/list.h @@ -0,0 +1,16 @@ +DEFINE_TEST(test_0) +DEFINE_TEST(test_basic) +DEFINE_TEST(test_copy) +DEFINE_TEST(test_empty_mtree) +DEFINE_TEST(test_getdate) +DEFINE_TEST(test_help) +DEFINE_TEST(test_option_T_upper) +DEFINE_TEST(test_option_q) +DEFINE_TEST(test_option_r) +DEFINE_TEST(test_option_s) +DEFINE_TEST(test_patterns) +DEFINE_TEST(test_stdio) +DEFINE_TEST(test_strip_components) +DEFINE_TEST(test_symlink_dir) +DEFINE_TEST(test_version) +DEFINE_TEST(test_windows) diff --git a/external/bsd/libarchive/dist/tar/test/main.c b/external/bsd/libarchive/dist/tar/test/main.c new file mode 100644 index 000000000..4f8309e59 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/main.c @@ -0,0 +1,2242 @@ +/* + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +#include +#include +#include +#include + +/* + * This same file is used pretty much verbatim for all test harnesses. + * + * The next few lines are the only differences. + * TODO: Move this into a separate configuration header, have all test + * suites share one copy of this file. + */ +__FBSDID("$FreeBSD: src/usr.bin/tar/test/main.c,v 1.6 2008/11/05 06:40:53 kientzle Exp $"); +#define KNOWNREF "test_patterns_2.tar.uu" +#define ENVBASE "BSDTAR" /* Prefix for environment variables. */ +#define PROGRAM "bsdtar" /* Name of program being tested. */ +#undef LIBRARY /* Not testing a library. */ +#undef EXTRA_DUMP /* How to dump extra data */ +/* How to generate extra version info. */ +#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "") + +/* + * + * Windows support routines + * + * Note: Configuration is a tricky issue. Using HAVE_* feature macros + * in the test harness is dangerous because they cover up + * configuration errors. The classic example of this is omitting a + * configure check. If libarchive and libarchive_test both look for + * the same feature macro, such errors are hard to detect. Platform + * macros (e.g., _WIN32 or __GNUC__) are a little better, but can + * easily lead to very messy code. It's best to limit yourself + * to only the most generic programming techniques in the test harness + * and thus avoid conditionals altogether. Where that's not possible, + * try to minimize conditionals by grouping platform-specific tests in + * one place (e.g., test_acl_freebsd) or by adding new assert() + * functions (e.g., assertMakeHardlink()) to cover up platform + * differences. Platform-specific coding in libarchive_test is often + * a symptom that some capability is missing from libarchive itself. + */ +#if defined(_WIN32) && !defined(__CYGWIN__) +#include +#include +#ifndef F_OK +#define F_OK (0) +#endif +#ifndef S_ISDIR +#define S_ISDIR(m) ((m) & _S_IFDIR) +#endif +#ifndef S_ISREG +#define S_ISREG(m) ((m) & _S_IFREG) +#endif +#if !defined(__BORLANDC__) +#define access _access +#undef chdir +#define chdir _chdir +#endif +#ifndef fileno +#define fileno _fileno +#endif +/*#define fstat _fstat64*/ +#if !defined(__BORLANDC__) +#define getcwd _getcwd +#endif +#define lstat stat +/*#define lstat _stat64*/ +/*#define stat _stat64*/ +#define rmdir _rmdir +#if !defined(__BORLANDC__) +#define strdup _strdup +#define umask _umask +#endif +#define int64_t __int64 +#endif + +#if defined(HAVE__CrtSetReportMode) +# include +#endif + +#if defined(_WIN32) && !defined(__CYGWIN__) +void *GetFunctionKernel32(const char *name) +{ + static HINSTANCE lib; + static int set; + if (!set) { + set = 1; + lib = LoadLibrary("kernel32.dll"); + } + if (lib == NULL) { + fprintf(stderr, "Can't load kernel32.dll?!\n"); + exit(1); + } + return (void *)GetProcAddress(lib, name); +} + +static int +my_CreateSymbolicLinkA(const char *linkname, const char *target, int flags) +{ + static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD); + static int set; + if (!set) { + set = 1; + f = GetFunctionKernel32("CreateSymbolicLinkA"); + } + return f == NULL ? 0 : (*f)(linkname, target, flags); +} + +static int +my_CreateHardLinkA(const char *linkname, const char *target) +{ + static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); + static int set; + if (!set) { + set = 1; + f = GetFunctionKernel32("CreateHardLinkA"); + } + return f == NULL ? 0 : (*f)(linkname, target, NULL); +} + +int +my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) +{ + HANDLE h; + int r; + + memset(bhfi, 0, sizeof(*bhfi)); + h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) + return (0); + r = GetFileInformationByHandle(h, bhfi); + CloseHandle(h); + return (r); +} +#endif + +#if defined(HAVE__CrtSetReportMode) +static void +invalid_parameter_handler(const wchar_t * expression, + const wchar_t * function, const wchar_t * file, + unsigned int line, uintptr_t pReserved) +{ + /* nop */ +} +#endif + +/* + * + * OPTIONS FLAGS + * + */ + +/* Enable core dump on failure. */ +static int dump_on_failure = 0; +/* Default is to remove temp dirs and log data for successful tests. */ +static int keep_temp_files = 0; +/* Default is to just report pass/fail for each test. */ +static int verbosity = 0; +#define VERBOSITY_SUMMARY_ONLY -1 /* -q */ +#define VERBOSITY_PASSFAIL 0 /* Default */ +#define VERBOSITY_LIGHT_REPORT 1 /* -v */ +#define VERBOSITY_FULL 2 /* -vv */ +/* A few places generate even more output for verbosity > VERBOSITY_FULL, + * mostly for debugging the test harness itself. */ +/* Cumulative count of assertion failures. */ +static int failures = 0; +/* Cumulative count of reported skips. */ +static int skips = 0; +/* Cumulative count of assertions checked. */ +static int assertions = 0; + +/* Directory where uuencoded reference files can be found. */ +static const char *refdir; + +/* + * Report log information selectively to console and/or disk log. + */ +static int log_console = 0; +static FILE *logfile; +static void +vlogprintf(const char *fmt, va_list ap) +{ +#ifdef va_copy + va_list lfap; + va_copy(lfap, ap); +#endif + if (log_console) + vfprintf(stdout, fmt, ap); + if (logfile != NULL) +#ifdef va_copy + vfprintf(logfile, fmt, lfap); + va_end(lfap); +#else + vfprintf(logfile, fmt, ap); +#endif +} + +static void +logprintf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vlogprintf(fmt, ap); + va_end(ap); +} + +/* Set up a message to display only if next assertion fails. */ +static char msgbuff[4096]; +static const char *msg, *nextmsg; +void +failure(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vsprintf(msgbuff, fmt, ap); + va_end(ap); + nextmsg = msgbuff; +} + +/* + * Copy arguments into file-local variables. + * This was added to permit vararg assert() functions without needing + * variadic wrapper macros. Turns out that the vararg capability is almost + * never used, so almost all of the vararg assertions can be simplified + * by removing the vararg capability and reworking the wrapper macro to + * pass __FILE__, __LINE__ directly into the function instead of using + * this hook. I suspect this machinery is used so rarely that we + * would be better off just removing it entirely. That would simplify + * the code here noticably. + */ +static const char *test_filename; +static int test_line; +static void *test_extra; +void assertion_setup(const char *filename, int line) +{ + test_filename = filename; + test_line = line; +} + +/* Called at the beginning of each assert() function. */ +static void +assertion_count(const char *file, int line) +{ + (void)file; /* UNUSED */ + (void)line; /* UNUSED */ + ++assertions; + /* Proper handling of "failure()" message. */ + msg = nextmsg; + nextmsg = NULL; + /* Uncomment to print file:line after every assertion. + * Verbose, but occasionally useful in tracking down crashes. */ + /* printf("Checked %s:%d\n", file, line); */ +} + +/* + * For each test source file, we remember how many times each + * assertion was reported. Cleared before each new test, + * used by test_summarize(). + */ +static struct line { + int count; + int skip; +} failed_lines[10000]; + +/* Count this failure, setup up log destination and handle initial report. */ +static void +failure_start(const char *filename, int line, const char *fmt, ...) +{ + va_list ap; + + /* Record another failure for this line. */ + ++failures; + /* test_filename = filename; */ + failed_lines[line].count++; + + /* Determine whether to log header to console. */ + switch (verbosity) { + case VERBOSITY_FULL: + log_console = 1; + break; + case VERBOSITY_LIGHT_REPORT: + log_console = (failed_lines[line].count < 2); + break; + default: + log_console = 0; + } + + /* Log file:line header for this failure */ + va_start(ap, fmt); +#if _MSC_VER + logprintf("%s(%d): ", filename, line); +#else + logprintf("%s:%d: ", filename, line); +#endif + vlogprintf(fmt, ap); + va_end(ap); + logprintf("\n"); + + if (msg != NULL && msg[0] != '\0') { + logprintf(" Description: %s\n", msg); + msg = NULL; + } + + /* Determine whether to log details to console. */ + if (verbosity == VERBOSITY_LIGHT_REPORT) + log_console = 0; +} + +/* Complete reporting of failed tests. */ +/* + * The 'extra' hook here is used by libarchive to include libarchive + * error messages with assertion failures. It could also be used + * to add strerror() output, for example. Just define the EXTRA_DUMP() + * macro appropriately. + */ +static void +failure_finish(void *extra) +{ + (void)extra; /* UNUSED (maybe) */ +#ifdef EXTRA_DUMP + if (extra != NULL) + logprintf(" detail: %s\n", EXTRA_DUMP(extra)); +#endif + + if (dump_on_failure) { + fprintf(stderr, + " *** forcing core dump so failure can be debugged ***\n"); + *(char *)(NULL) = 0; + exit(1); + } +} + +/* Inform user that we're skipping some checks. */ +void +test_skipping(const char *fmt, ...) +{ + char buff[1024]; + va_list ap; + + va_start(ap, fmt); + vsprintf(buff, fmt, ap); + va_end(ap); + /* failure_start() isn't quite right, but is awfully convenient. */ + failure_start(test_filename, test_line, "SKIPPING: %s", buff); + --failures; /* Undo failures++ in failure_start() */ + /* Don't failure_finish() here. */ + /* Mark as skip, so doesn't count as failed test. */ + failed_lines[test_line].skip = 1; + ++skips; +} + +/* + * + * ASSERTIONS + * + */ + +/* Generic assert() just displays the failed condition. */ +int +assertion_assert(const char *file, int line, int value, + const char *condition, void *extra) +{ + assertion_count(file, line); + if (!value) { + failure_start(file, line, "Assertion failed: %s", condition); + failure_finish(extra); + } + return (value); +} + +/* chdir() and report any errors */ +int +assertion_chdir(const char *file, int line, const char *pathname) +{ + assertion_count(file, line); + if (chdir(pathname) == 0) + return (1); + failure_start(file, line, "chdir(\"%s\")", pathname); + failure_finish(NULL); + return (0); + +} + +/* Verify two integers are equal. */ +int +assertion_equal_int(const char *file, int line, + long long v1, const char *e1, long long v2, const char *e2, void *extra) +{ + assertion_count(file, line); + if (v1 == v2) + return (1); + failure_start(file, line, "%s != %s", e1, e2); + logprintf(" %s=%lld (0x%llx, 0%llo)\n", e1, v1, v1, v1); + logprintf(" %s=%lld (0x%llx, 0%llo)\n", e2, v2, v2, v2); + failure_finish(extra); + return (0); +} + +static void strdump(const char *e, const char *p) +{ + const char *q = p; + + logprintf(" %s = ", e); + if (p == NULL) { + logprintf("NULL"); + return; + } + logprintf("\""); + while (*p != '\0') { + unsigned int c = 0xff & *p++; + switch (c) { + case '\a': printf("\a"); break; + case '\b': printf("\b"); break; + case '\n': printf("\n"); break; + case '\r': printf("\r"); break; + default: + if (c >= 32 && c < 127) + logprintf("%c", c); + else + logprintf("\\x%02X", c); + } + } + logprintf("\""); + logprintf(" (length %d)\n", q == NULL ? -1 : (int)strlen(q)); +} + +/* Verify two strings are equal, dump them if not. */ +int +assertion_equal_string(const char *file, int line, + const char *v1, const char *e1, + const char *v2, const char *e2, + void *extra) +{ + assertion_count(file, line); + if (v1 == v2 || (v1 != NULL && v2 != NULL && strcmp(v1, v2) == 0)) + return (1); + failure_start(file, line, "%s != %s", e1, e2); + strdump(e1, v1); + strdump(e2, v2); + failure_finish(extra); + return (0); +} + +static void +wcsdump(const char *e, const wchar_t *w) +{ + logprintf(" %s = ", e); + if (w == NULL) { + logprintf("(null)"); + return; + } + logprintf("\""); + while (*w != L'\0') { + unsigned int c = *w++; + if (c >= 32 && c < 127) + logprintf("%c", c); + else if (c < 256) + logprintf("\\x%02X", c); + else if (c < 0x10000) + logprintf("\\u%04X", c); + else + logprintf("\\U%08X", c); + } + logprintf("\"\n"); +} + +#ifndef HAVE_WCSCMP +static int +wcscmp(const wchar_t *s1, const wchar_t *s2) +{ + + while (*s1 == *s2++) { + if (*s1++ == L'\0') + return 0; + } + if (*s1 > *--s2) + return 1; + else + return -1; +} +#endif + +/* Verify that two wide strings are equal, dump them if not. */ +int +assertion_equal_wstring(const char *file, int line, + const wchar_t *v1, const char *e1, + const wchar_t *v2, const char *e2, + void *extra) +{ + assertion_count(file, line); + if (v1 == v2 || wcscmp(v1, v2) == 0) + return (1); + failure_start(file, line, "%s != %s", e1, e2); + wcsdump(e1, v1); + wcsdump(e2, v2); + failure_finish(extra); + return (0); +} + +/* + * Pretty standard hexdump routine. As a bonus, if ref != NULL, then + * any bytes in p that differ from ref will be highlighted with '_' + * before and after the hex value. + */ +static void +hexdump(const char *p, const char *ref, size_t l, size_t offset) +{ + size_t i, j; + char sep; + + if (p == NULL) { + logprintf("(null)\n"); + return; + } + for(i=0; i < l; i+=16) { + logprintf("%04x", (unsigned)(i + offset)); + sep = ' '; + for (j = 0; j < 16 && i + j < l; j++) { + if (ref != NULL && p[i + j] != ref[i + j]) + sep = '_'; + logprintf("%c%02x", sep, 0xff & (int)p[i+j]); + if (ref != NULL && p[i + j] == ref[i + j]) + sep = ' '; + } + for (; j < 16; j++) { + logprintf("%c ", sep); + sep = ' '; + } + logprintf("%c", sep); + for (j=0; j < 16 && i + j < l; j++) { + int c = p[i + j]; + if (c >= ' ' && c <= 126) + logprintf("%c", c); + else + logprintf("."); + } + logprintf("\n"); + } +} + +/* Verify that two blocks of memory are the same, display the first + * block of differences if they're not. */ +int +assertion_equal_mem(const char *file, int line, + const void *_v1, const char *e1, + const void *_v2, const char *e2, + size_t l, const char *ld, void *extra) +{ + const char *v1 = (const char *)_v1; + const char *v2 = (const char *)_v2; + size_t offset; + + assertion_count(file, line); + if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0)) + return (1); + + failure_start(file, line, "%s != %s", e1, e2); + logprintf(" size %s = %d\n", ld, (int)l); + /* Dump 48 bytes (3 lines) so that the first difference is + * in the second line. */ + offset = 0; + while (l > 64 && memcmp(v1, v2, 32) == 0) { + /* Two lines agree, so step forward one line. */ + v1 += 16; + v2 += 16; + l -= 16; + offset += 16; + } + logprintf(" Dump of %s\n", e1); + hexdump(v1, v2, l < 64 ? l : 64, offset); + logprintf(" Dump of %s\n", e2); + hexdump(v2, v1, l < 64 ? l : 64, offset); + logprintf("\n"); + failure_finish(extra); + return (0); +} + +/* Verify that the named file exists and is empty. */ +int +assertion_empty_file(const char *f1fmt, ...) +{ + char buff[1024]; + char f1[1024]; + struct stat st; + va_list ap; + ssize_t s; + FILE *f; + + assertion_count(test_filename, test_line); + va_start(ap, f1fmt); + vsprintf(f1, f1fmt, ap); + va_end(ap); + + if (stat(f1, &st) != 0) { + failure_start(test_filename, test_line, "Stat failed: %s", f1); + failure_finish(NULL); + return (0); + } + if (st.st_size == 0) + return (1); + + failure_start(test_filename, test_line, "File should be empty: %s", f1); + logprintf(" File size: %d\n", (int)st.st_size); + logprintf(" Contents:\n"); + f = fopen(f1, "rb"); + if (f == NULL) { + logprintf(" Unable to open %s\n", f1); + } else { + s = ((off_t)sizeof(buff) < st.st_size) ? + (ssize_t)sizeof(buff) : (ssize_t)st.st_size; + s = fread(buff, 1, s, f); + hexdump(buff, NULL, s, 0); + fclose(f); + } + failure_finish(NULL); + return (0); +} + +/* Verify that the named file exists and is not empty. */ +int +assertion_non_empty_file(const char *f1fmt, ...) +{ + char f1[1024]; + struct stat st; + va_list ap; + + assertion_count(test_filename, test_line); + va_start(ap, f1fmt); + vsprintf(f1, f1fmt, ap); + va_end(ap); + + if (stat(f1, &st) != 0) { + failure_start(test_filename, test_line, "Stat failed: %s", f1); + failure_finish(NULL); + return (0); + } + if (st.st_size == 0) { + failure_start(test_filename, test_line, "File empty: %s", f1); + failure_finish(NULL); + return (0); + } + return (1); +} + +/* Verify that two files have the same contents. */ +/* TODO: hexdump the first bytes that actually differ. */ +int +assertion_equal_file(const char *fn1, const char *f2pattern, ...) +{ + char fn2[1024]; + va_list ap; + char buff1[1024]; + char buff2[1024]; + FILE *f1, *f2; + int n1, n2; + + assertion_count(test_filename, test_line); + va_start(ap, f2pattern); + vsprintf(fn2, f2pattern, ap); + va_end(ap); + + f1 = fopen(fn1, "rb"); + f2 = fopen(fn2, "rb"); + for (;;) { + n1 = fread(buff1, 1, sizeof(buff1), f1); + n2 = fread(buff2, 1, sizeof(buff2), f2); + if (n1 != n2) + break; + if (n1 == 0 && n2 == 0) { + fclose(f1); + fclose(f2); + return (1); + } + if (memcmp(buff1, buff2, n1) != 0) + break; + } + fclose(f1); + fclose(f2); + failure_start(test_filename, test_line, "Files not identical"); + logprintf(" file1=\"%s\"\n", fn1); + logprintf(" file2=\"%s\"\n", fn2); + failure_finish(test_extra); + return (0); +} + +/* Verify that the named file does exist. */ +int +assertion_file_exists(const char *fpattern, ...) +{ + char f[1024]; + va_list ap; + + assertion_count(test_filename, test_line); + va_start(ap, fpattern); + vsprintf(f, fpattern, ap); + va_end(ap); + +#if defined(_WIN32) && !defined(__CYGWIN__) + if (!_access(f, 0)) + return (1); +#else + if (!access(f, F_OK)) + return (1); +#endif + failure_start(test_filename, test_line, "File should exist: %s", f); + failure_finish(test_extra); + return (0); +} + +/* Verify that the named file doesn't exist. */ +int +assertion_file_not_exists(const char *fpattern, ...) +{ + char f[1024]; + va_list ap; + + assertion_count(test_filename, test_line); + va_start(ap, fpattern); + vsprintf(f, fpattern, ap); + va_end(ap); + +#if defined(_WIN32) && !defined(__CYGWIN__) + if (_access(f, 0)) + return (1); +#else + if (access(f, F_OK)) + return (1); +#endif + failure_start(test_filename, test_line, "File should not exist: %s", f); + failure_finish(test_extra); + return (0); +} + +/* Compare the contents of a file to a block of memory. */ +int +assertion_file_contents(const void *buff, int s, const char *fpattern, ...) +{ + char fn[1024]; + va_list ap; + char *contents; + FILE *f; + int n; + + assertion_count(test_filename, test_line); + va_start(ap, fpattern); + vsprintf(fn, fpattern, ap); + va_end(ap); + + f = fopen(fn, "rb"); + if (f == NULL) { + failure_start(test_filename, test_line, + "File should exist: %s", fn); + failure_finish(test_extra); + return (0); + } + contents = malloc(s * 2); + n = fread(contents, 1, s * 2, f); + fclose(f); + if (n == s && memcmp(buff, contents, s) == 0) { + free(contents); + return (1); + } + failure_start(test_filename, test_line, "File contents don't match"); + logprintf(" file=\"%s\"\n", fn); + if (n > 0) + hexdump(contents, buff, n > 512 ? 512 : n, 0); + else { + logprintf(" File empty, contents should be:\n"); + hexdump(buff, NULL, s > 512 ? 512 : s, 0); + } + failure_finish(test_extra); + free(contents); + return (0); +} + +/* Check the contents of a text file, being tolerant of line endings. */ +int +assertion_text_file_contents(const char *buff, const char *fn) +{ + char *contents; + const char *btxt, *ftxt; + FILE *f; + int n, s; + + assertion_count(test_filename, test_line); + f = fopen(fn, "r"); + s = strlen(buff); + contents = malloc(s * 2 + 128); + n = fread(contents, 1, s * 2 + 128 - 1, f); + if (n >= 0) + contents[n] = '\0'; + fclose(f); + /* Compare texts. */ + btxt = buff; + ftxt = (const char *)contents; + while (*btxt != '\0' && *ftxt != '\0') { + if (*btxt == *ftxt) { + ++btxt; + ++ftxt; + continue; + } + if (btxt[0] == '\n' && ftxt[0] == '\r' && ftxt[1] == '\n') { + /* Pass over different new line characters. */ + ++btxt; + ftxt += 2; + continue; + } + break; + } + if (*btxt == '\0' && *ftxt == '\0') { + free(contents); + return (1); + } + failure_start(test_filename, test_line, "Contents don't match"); + logprintf(" file=\"%s\"\n", fn); + if (n > 0) + hexdump(contents, buff, n, 0); + else { + logprintf(" File empty, contents should be:\n"); + hexdump(buff, NULL, s, 0); + } + failure_finish(test_extra); + free(contents); + return (0); +} + +/* Verify that a text file contains the specified lines, regardless of order */ +/* This could be more efficient if we sorted both sets of lines, etc, but + * since this is used only for testing and only ever deals with a dozen or so + * lines at a time, this relatively crude approach is just fine. */ +int +assertion_file_contains_lines_any_order(const char *file, int line, + const char *pathname, const char *lines[]) +{ + char *buff; + size_t buff_size; + size_t expected_count, actual_count, i, j; + char **expected; + char *p, **actual; + char c; + int expected_failure = 0, actual_failure = 0; + + assertion_count(file, line); + + buff = slurpfile(&buff_size, "%s", pathname); + if (buff == NULL) { + failure_start(pathname, line, "Can't read file: %s", pathname); + failure_finish(NULL); + return (0); + } + + // Make a copy of the provided lines and count up the expected file size. + expected_count = 0; + for (i = 0; lines[i] != NULL; ++i) { + } + expected_count = i; + expected = malloc(sizeof(char *) * expected_count); + for (i = 0; lines[i] != NULL; ++i) { + expected[i] = strdup(lines[i]); + } + + // Break the file into lines + actual_count = 0; + for (c = '\0', p = buff; p < buff + buff_size; ++p) { + if (*p == '\x0d' || *p == '\x0a') + *p = '\0'; + if (c == '\0' && *p != '\0') + ++actual_count; + c = *p; + } + actual = malloc(sizeof(char *) * actual_count); + for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) { + if (*p != '\0') { + actual[j] = p; + ++j; + } + } + + // Erase matching lines from both lists + for (i = 0; i < expected_count; ++i) { + if (expected[i] == NULL) + continue; + for (j = 0; j < actual_count; ++j) { + if (actual[j] == NULL) + continue; + if (strcmp(expected[i], actual[j]) == 0) { + free(expected[i]); + expected[i] = NULL; + actual[j] = NULL; + break; + } + } + } + + // If there's anything left, it's a failure + for (i = 0; i < expected_count; ++i) { + if (expected[i] != NULL) + ++expected_failure; + } + for (j = 0; j < actual_count; ++j) { + if (actual[j] != NULL) + ++actual_failure; + } + if (expected_failure == 0 && actual_failure == 0) { + free(buff); + free(expected); + free(actual); + return (1); + } + failure_start(file, line, "File doesn't match: %s", pathname); + for (i = 0; i < expected_count; ++i) { + if (expected[i] != NULL) { + logprintf(" Expected but not present: %s\n", expected[i]); + free(expected[i]); + } + } + for (j = 0; j < actual_count; ++j) { + if (actual[j] != NULL) + logprintf(" Present but not expected: %s\n", actual[j]); + } + failure_finish(NULL); + free(buff); + free(expected); + free(actual); + return (0); +} + +/* Test that two paths point to the same file. */ +/* As a side-effect, asserts that both files exist. */ +static int +is_hardlink(const char *file, int line, + const char *path1, const char *path2) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2; + int r; + + assertion_count(file, line); + r = my_GetFileInformationByName(path1, &bhfi1); + if (r == 0) { + failure_start(file, line, "File %s can't be inspected?", path1); + failure_finish(NULL); + return (0); + } + r = my_GetFileInformationByName(path2, &bhfi2); + if (r == 0) { + failure_start(file, line, "File %s can't be inspected?", path2); + failure_finish(NULL); + return (0); + } + return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber + && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh + && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow); +#else + struct stat st1, st2; + int r; + + assertion_count(file, line); + r = lstat(path1, &st1); + if (r != 0) { + failure_start(file, line, "File should exist: %s", path1); + failure_finish(NULL); + return (0); + } + r = lstat(path2, &st2); + if (r != 0) { + failure_start(file, line, "File should exist: %s", path2); + failure_finish(NULL); + return (0); + } + return (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev); +#endif +} + +int +assertion_is_hardlink(const char *file, int line, + const char *path1, const char *path2) +{ + if (is_hardlink(file, line, path1, path2)) + return (1); + failure_start(file, line, + "Files %s and %s are not hardlinked", path1, path2); + failure_finish(NULL); + return (0); +} + +int +assertion_is_not_hardlink(const char *file, int line, + const char *path1, const char *path2) +{ + if (!is_hardlink(file, line, path1, path2)) + return (1); + failure_start(file, line, + "Files %s and %s should not be hardlinked", path1, path2); + failure_finish(NULL); + return (0); +} + +/* Verify a/b/mtime of 'pathname'. */ +/* If 'recent', verify that it's within last 10 seconds. */ +static int +assertion_file_time(const char *file, int line, + const char *pathname, long t, long nsec, char type, int recent) +{ + long long filet, filet_nsec; + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) +#define EPOC_TIME (116444736000000000ULL) + FILETIME ftime, fbirthtime, fatime, fmtime; + ULARGE_INTEGER wintm; + HANDLE h; + ftime.dwLowDateTime = 0; + ftime.dwHighDateTime = 0; + + assertion_count(file, line); + h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + failure_start(file, line, "Can't access %s\n", pathname); + failure_finish(NULL); + return (0); + } + r = GetFileTime(h, &fbirthtime, &fatime, &fmtime); + switch (type) { + case 'a': ftime = fatime; break; + case 'b': ftime = fbirthtime; break; + case 'm': ftime = fmtime; break; + } + CloseHandle(h); + if (r == 0) { + failure_start(file, line, "Can't GetFileTime %s\n", pathname); + failure_finish(NULL); + return (0); + } + wintm.LowPart = ftime.dwLowDateTime; + wintm.HighPart = ftime.dwHighDateTime; + filet = (wintm.QuadPart - EPOC_TIME) / 10000000; + filet_nsec = ((wintm.QuadPart - EPOC_TIME) % 10000000) * 100; + nsec = (nsec / 100) * 100; /* Round the request */ +#else + struct stat st; + + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0) { + failure_start(file, line, "Can't stat %s\n", pathname); + failure_finish(NULL); + return (0); + } + switch (type) { + case 'a': filet = st.st_atime; break; + case 'm': filet = st.st_mtime; break; + case 'b': filet = 0; break; + default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); + exit(1); + } +#if defined(__FreeBSD__) + switch (type) { + case 'a': filet_nsec = st.st_atimespec.tv_nsec; break; + case 'b': filet = st.st_birthtime; + filet_nsec = st.st_birthtimespec.tv_nsec; break; + case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break; + default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); + exit(1); + } + /* FreeBSD generally only stores to microsecond res, so round. */ + filet_nsec = (filet_nsec / 1000) * 1000; + nsec = (nsec / 1000) * 1000; +#else + filet_nsec = nsec = 0; /* Generic POSIX only has whole seconds. */ + if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */ +#if defined(__HAIKU__) + if (type == 'a') return (1); /* Haiku doesn't have atime. */ +#endif +#endif +#endif + if (recent) { + /* Check that requested time is up-to-date. */ + time_t now = time(NULL); + if (filet < now - 10 || filet > now + 1) { + failure_start(file, line, + "File %s has %ctime %ld, %ld seconds ago\n", + pathname, type, filet, now - filet); + failure_finish(NULL); + return (0); + } + } else if (filet != t || filet_nsec != nsec) { + failure_start(file, line, + "File %s has %ctime %ld.%09ld, expected %ld.%09ld", + pathname, type, filet, filet_nsec, t, nsec); + failure_finish(NULL); + return (0); + } + return (1); +} + +/* Verify atime of 'pathname'. */ +int +assertion_file_atime(const char *file, int line, + const char *pathname, long t, long nsec) +{ + return assertion_file_time(file, line, pathname, t, nsec, 'a', 0); +} + +/* Verify atime of 'pathname' is up-to-date. */ +int +assertion_file_atime_recent(const char *file, int line, const char *pathname) +{ + return assertion_file_time(file, line, pathname, 0, 0, 'a', 1); +} + +/* Verify birthtime of 'pathname'. */ +int +assertion_file_birthtime(const char *file, int line, + const char *pathname, long t, long nsec) +{ + return assertion_file_time(file, line, pathname, t, nsec, 'b', 0); +} + +/* Verify birthtime of 'pathname' is up-to-date. */ +int +assertion_file_birthtime_recent(const char *file, int line, + const char *pathname) +{ + return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); +} + +/* Verify mtime of 'pathname'. */ +int +assertion_file_mtime(const char *file, int line, + const char *pathname, long t, long nsec) +{ + return assertion_file_time(file, line, pathname, t, nsec, 'm', 0); +} + +/* Verify mtime of 'pathname' is up-to-date. */ +int +assertion_file_mtime_recent(const char *file, int line, const char *pathname) +{ + return assertion_file_time(file, line, pathname, 0, 0, 'm', 1); +} + +/* Verify number of links to 'pathname'. */ +int +assertion_file_nlinks(const char *file, int line, + const char *pathname, int nlinks) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + BY_HANDLE_FILE_INFORMATION bhfi; + int r; + + assertion_count(file, line); + r = my_GetFileInformationByName(pathname, &bhfi); + if (r != 0 && bhfi.nNumberOfLinks == (DWORD)nlinks) + return (1); + failure_start(file, line, "File %s has %d links, expected %d", + pathname, bhfi.nNumberOfLinks, nlinks); + failure_finish(NULL); + return (0); +#else + struct stat st; + int r; + + assertion_count(file, line); + r = lstat(pathname, &st); + if (r == 0 && st.st_nlink == nlinks) + return (1); + failure_start(file, line, "File %s has %d links, expected %d", + pathname, st.st_nlink, nlinks); + failure_finish(NULL); + return (0); +#endif +} + +/* Verify size of 'pathname'. */ +int +assertion_file_size(const char *file, int line, const char *pathname, long size) +{ + int64_t filesize; + int r; + + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + { + BY_HANDLE_FILE_INFORMATION bhfi; + r = !my_GetFileInformationByName(pathname, &bhfi); + filesize = ((int64_t)bhfi.nFileSizeHigh << 32) + bhfi.nFileSizeLow; + } +#else + { + struct stat st; + r = lstat(pathname, &st); + filesize = st.st_size; + } +#endif + if (r == 0 && filesize == size) + return (1); + failure_start(file, line, "File %s has size %ld, expected %ld", + pathname, (long)filesize, (long)size); + failure_finish(NULL); + return (0); +} + +/* Assert that 'pathname' is a dir. If mode >= 0, verify that too. */ +int +assertion_is_dir(const char *file, int line, const char *pathname, int mode) +{ + struct stat st; + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)mode; /* UNUSED */ +#endif + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0) { + failure_start(file, line, "Dir should exist: %s", pathname); + failure_finish(NULL); + return (0); + } + if (!S_ISDIR(st.st_mode)) { + failure_start(file, line, "%s is not a dir", pathname); + failure_finish(NULL); + return (0); + } +#if !defined(_WIN32) || defined(__CYGWIN__) + /* Windows doesn't handle permissions the same way as POSIX, + * so just ignore the mode tests. */ + /* TODO: Can we do better here? */ + if (mode >= 0 && mode != (st.st_mode & 07777)) { + failure_start(file, line, "Dir %s has wrong mode", pathname); + logprintf(" Expected: 0%3o\n", mode); + logprintf(" Found: 0%3o\n", st.st_mode & 07777); + failure_finish(NULL); + return (0); + } +#endif + return (1); +} + +/* Verify that 'pathname' is a regular file. If 'mode' is >= 0, + * verify that too. */ +int +assertion_is_reg(const char *file, int line, const char *pathname, int mode) +{ + struct stat st; + int r; + +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)mode; /* UNUSED */ +#endif + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0 || !S_ISREG(st.st_mode)) { + failure_start(file, line, "File should exist: %s", pathname); + failure_finish(NULL); + return (0); + } +#if !defined(_WIN32) || defined(__CYGWIN__) + /* Windows doesn't handle permissions the same way as POSIX, + * so just ignore the mode tests. */ + /* TODO: Can we do better here? */ + if (mode >= 0 && mode != (st.st_mode & 07777)) { + failure_start(file, line, "File %s has wrong mode", pathname); + logprintf(" Expected: 0%3o\n", mode); + logprintf(" Found: 0%3o\n", st.st_mode & 07777); + failure_finish(NULL); + return (0); + } +#endif + return (1); +} + +/* Check whether 'pathname' is a symbolic link. If 'contents' is + * non-NULL, verify that the symlink has those contents. */ +static int +is_symlink(const char *file, int line, + const char *pathname, const char *contents) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)pathname; /* UNUSED */ + (void)contents; /* UNUSED */ + assertion_count(file, line); + /* Windows sort-of has real symlinks, but they're only usable + * by privileged users and are crippled even then, so there's + * really not much point in bothering with this. */ + return (0); +#else + char buff[300]; + struct stat st; + ssize_t linklen; + int r; + + assertion_count(file, line); + r = lstat(pathname, &st); + if (r != 0) { + failure_start(file, line, + "Symlink should exist: %s", pathname); + failure_finish(NULL); + return (0); + } + if (!S_ISLNK(st.st_mode)) + return (0); + if (contents == NULL) + return (1); + linklen = readlink(pathname, buff, sizeof(buff)); + if (linklen < 0) { + failure_start(file, line, "Can't read symlink %s", pathname); + failure_finish(NULL); + return (0); + } + buff[linklen] = '\0'; + if (strcmp(buff, contents) != 0) + return (0); + return (1); +#endif +} + +/* Assert that path is a symlink that (optionally) contains contents. */ +int +assertion_is_symlink(const char *file, int line, + const char *path, const char *contents) +{ + if (is_symlink(file, line, path, contents)) + return (1); + if (contents) + failure_start(file, line, "File %s is not a symlink to %s", + path, contents); + else + failure_start(file, line, "File %s is not a symlink", path); + failure_finish(NULL); + return (0); +} + + +/* Create a directory and report any errors. */ +int +assertion_make_dir(const char *file, int line, const char *dirname, int mode) +{ + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + (void)mode; /* UNUSED */ + if (0 == _mkdir(dirname)) + return (1); +#else + if (0 == mkdir(dirname, mode)) + return (1); +#endif + failure_start(file, line, "Could not create directory %s", dirname); + failure_finish(NULL); + return(0); +} + +/* Create a file with the specified contents and report any failures. */ +int +assertion_make_file(const char *file, int line, + const char *path, int mode, const char *contents) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + /* TODO: Rework this to set file mode as well. */ + FILE *f; + (void)mode; /* UNUSED */ + assertion_count(file, line); + f = fopen(path, "wb"); + if (f == NULL) { + failure_start(file, line, "Could not create file %s", path); + failure_finish(NULL); + return (0); + } + if (contents != NULL) { + if (strlen(contents) + != fwrite(contents, 1, strlen(contents), f)) { + fclose(f); + failure_start(file, line, + "Could not write file %s", path); + failure_finish(NULL); + return (0); + } + } + fclose(f); + return (1); +#else + int fd; + assertion_count(file, line); + fd = open(path, O_CREAT | O_WRONLY, mode >= 0 ? mode : 0644); + if (fd < 0) { + failure_start(file, line, "Could not create %s", path); + failure_finish(NULL); + return (0); + } + if (contents != NULL) { + if ((ssize_t)strlen(contents) + != write(fd, contents, strlen(contents))) { + close(fd); + failure_start(file, line, "Could not write to %s", path); + failure_finish(NULL); + return (0); + } + } + close(fd); + return (1); +#endif +} + +/* Create a hardlink and report any failures. */ +int +assertion_make_hardlink(const char *file, int line, + const char *newpath, const char *linkto) +{ + int succeeded; + + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + succeeded = my_CreateHardLinkA(newpath, linkto); +#elif HAVE_LINK + succeeded = !link(linkto, newpath); +#else + succeeded = 0; +#endif + if (succeeded) + return (1); + failure_start(file, line, "Could not create hardlink"); + logprintf(" New link: %s\n", newpath); + logprintf(" Old name: %s\n", linkto); + failure_finish(NULL); + return(0); +} + +/* Create a symlink and report any failures. */ +int +assertion_make_symlink(const char *file, int line, + const char *newpath, const char *linkto) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + int targetIsDir = 0; /* TODO: Fix this */ + assertion_count(file, line); + if (my_CreateSymbolicLinkA(newpath, linkto, targetIsDir)) + return (1); +#elif HAVE_SYMLINK + assertion_count(file, line); + if (0 == symlink(linkto, newpath)) + return (1); +#endif + failure_start(file, line, "Could not create symlink"); + logprintf(" New link: %s\n", newpath); + logprintf(" Old name: %s\n", linkto); + failure_finish(NULL); + return(0); +} + +/* Set umask, report failures. */ +int +assertion_umask(const char *file, int line, int mask) +{ + assertion_count(file, line); + (void)file; /* UNUSED */ + (void)line; /* UNUSED */ + umask(mask); + return (1); +} + +/* + * + * UTILITIES for use by tests. + * + */ + +/* + * Check whether platform supports symlinks. This is intended + * for tests to use in deciding whether to bother testing symlink + * support; if the platform doesn't support symlinks, there's no point + * in checking whether the program being tested can create them. + * + * Note that the first time this test is called, we actually go out to + * disk to create and verify a symlink. This is necessary because + * symlink support is actually a property of a particular filesystem + * and can thus vary between directories on a single system. After + * the first call, this returns the cached result from memory, so it's + * safe to call it as often as you wish. + */ +int +canSymlink(void) +{ + /* Remember the test result */ + static int value = 0, tested = 0; + if (tested) + return (value); + + ++tested; + assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a"); + /* Note: Cygwin has its own symlink() emulation that does not + * use the Win32 CreateSymbolicLink() function. */ +#if defined(_WIN32) && !defined(__CYGWIN__) + value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0) + && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0"); +#elif HAVE_SYMLINK + value = (0 == symlink("canSymlink.0", "canSymlink.1")) + && is_symlink(__FILE__, __LINE__, "canSymlink.1","canSymlink.0"); +#endif + return (value); +} + +/* + * Can this platform run the gzip program? + */ +/* Platform-dependent options for hiding the output of a subcommand. */ +#if defined(_WIN32) && !defined(__CYGWIN__) +static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ +#else +static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ +#endif +int +canGzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("gzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Can this platform run the gunzip program? + */ +int +canGunzip(void) +{ + static int tested = 0, value = 0; + if (!tested) { + tested = 1; + if (systemf("gunzip -V %s", redirectArgs) == 0) + value = 1; + } + return (value); +} + +/* + * Sleep as needed; useful for verifying disk timestamp changes by + * ensuring that the wall-clock time has actually changed before we + * go back to re-read something from disk. + */ +void +sleepUntilAfter(time_t t) +{ + while (t >= time(NULL)) +#if defined(_WIN32) && !defined(__CYGWIN__) + Sleep(500); +#else + sleep(1); +#endif +} + +/* + * Call standard system() call, but build up the command line using + * sprintf() conventions. + */ +int +systemf(const char *fmt, ...) +{ + char buff[8192]; + va_list ap; + int r; + + va_start(ap, fmt); + vsprintf(buff, fmt, ap); + if (verbosity > VERBOSITY_FULL) + logprintf("Cmd: %s\n", buff); + r = system(buff); + va_end(ap); + return (r); +} + +/* + * Slurp a file into memory for ease of comparison and testing. + * Returns size of file in 'sizep' if non-NULL, null-terminates + * data in memory for ease of use. + */ +char * +slurpfile(size_t * sizep, const char *fmt, ...) +{ + char filename[8192]; + struct stat st; + va_list ap; + char *p; + ssize_t bytes_read; + FILE *f; + int r; + + va_start(ap, fmt); + vsprintf(filename, fmt, ap); + va_end(ap); + + f = fopen(filename, "rb"); + if (f == NULL) { + /* Note: No error; non-existent file is okay here. */ + return (NULL); + } + r = fstat(fileno(f), &st); + if (r != 0) { + logprintf("Can't stat file %s\n", filename); + fclose(f); + return (NULL); + } + p = malloc((size_t)st.st_size + 1); + if (p == NULL) { + logprintf("Can't allocate %ld bytes of memory to read file %s\n", + (long int)st.st_size, filename); + fclose(f); + return (NULL); + } + bytes_read = fread(p, 1, (size_t)st.st_size, f); + if (bytes_read < st.st_size) { + logprintf("Can't read file %s\n", filename); + fclose(f); + free(p); + return (NULL); + } + p[st.st_size] = '\0'; + if (sizep != NULL) + *sizep = (size_t)st.st_size; + fclose(f); + return (p); +} + +/* Read a uuencoded file from the reference directory, decode, and + * write the result into the current directory. */ +#define UUDECODE(c) (((c) - 0x20) & 0x3f) +void +extract_reference_file(const char *name) +{ + char buff[1024]; + FILE *in, *out; + + sprintf(buff, "%s/%s.uu", refdir, name); + in = fopen(buff, "r"); + failure("Couldn't open reference file %s", buff); + assert(in != NULL); + if (in == NULL) + return; + /* Read up to and including the 'begin' line. */ + for (;;) { + if (fgets(buff, sizeof(buff), in) == NULL) { + /* TODO: This is a failure. */ + return; + } + if (memcmp(buff, "begin ", 6) == 0) + break; + } + /* Now, decode the rest and write it. */ + /* Not a lot of error checking here; the input better be right. */ + out = fopen(name, "wb"); + while (fgets(buff, sizeof(buff), in) != NULL) { + char *p = buff; + int bytes; + + if (memcmp(buff, "end", 3) == 0) + break; + + bytes = UUDECODE(*p++); + while (bytes > 0) { + int n = 0; + /* Write out 1-3 bytes from that. */ + if (bytes > 0) { + n = UUDECODE(*p++) << 18; + n |= UUDECODE(*p++) << 12; + fputc(n >> 16, out); + --bytes; + } + if (bytes > 0) { + n |= UUDECODE(*p++) << 6; + fputc((n >> 8) & 0xFF, out); + --bytes; + } + if (bytes > 0) { + n |= UUDECODE(*p++); + fputc(n & 0xFF, out); + --bytes; + } + } + } + fclose(out); + fclose(in); +} + +/* + * + * TEST management + * + */ + +/* + * "list.h" is simply created by "grep DEFINE_TEST test_*.c"; it has + * a line like + * DEFINE_TEST(test_function) + * for each test. + */ + +/* Use "list.h" to declare all of the test functions. */ +#undef DEFINE_TEST +#define DEFINE_TEST(name) void name(void); +#include "list.h" + +/* Use "list.h" to create a list of all tests (functions and names). */ +#undef DEFINE_TEST +#define DEFINE_TEST(n) { n, #n, 0 }, +struct { void (*func)(void); const char *name; int failures; } tests[] = { + #include "list.h" +}; + +/* + * Summarize repeated failures in the just-completed test. + */ +static void +test_summarize(const char *filename, int failed) +{ + unsigned int i; + + switch (verbosity) { + case VERBOSITY_SUMMARY_ONLY: + printf(failed ? "E" : "."); + fflush(stdout); + break; + case VERBOSITY_PASSFAIL: + printf(failed ? "FAIL\n" : "ok\n"); + break; + } + + log_console = (verbosity == VERBOSITY_LIGHT_REPORT); + + for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { + if (failed_lines[i].count > 1 && !failed_lines[i].skip) + logprintf("%s:%d: Summary: Failed %d times\n", + filename, i, failed_lines[i].count); + } + /* Clear the failure history for the next file. */ + memset(failed_lines, 0, sizeof(failed_lines)); +} + +/* + * Actually run a single test, with appropriate setup and cleanup. + */ +static int +test_run(int i, const char *tmpdir) +{ + char logfilename[64]; + int failures_before = failures; + int oldumask; + + switch (verbosity) { + case VERBOSITY_SUMMARY_ONLY: /* No per-test reports at all */ + break; + case VERBOSITY_PASSFAIL: /* rest of line will include ok/FAIL marker */ + printf("%3d: %-50s", i, tests[i].name); + fflush(stdout); + break; + default: /* Title of test, details will follow */ + printf("%3d: %s\n", i, tests[i].name); + } + + /* Chdir to the top-level work directory. */ + if (!assertChdir(tmpdir)) { + fprintf(stderr, + "ERROR: Can't chdir to top work dir %s\n", tmpdir); + exit(1); + } + /* Create a log file for this test. */ + sprintf(logfilename, "%s.log", tests[i].name); + logfile = fopen(logfilename, "w"); + fprintf(logfile, "%s\n\n", tests[i].name); + /* Chdir() to a work dir for this specific test. */ + if (!assertMakeDir(tests[i].name, 0755) + || !assertChdir(tests[i].name)) { + fprintf(stderr, + "ERROR: Can't chdir to work dir %s/%s\n", + tmpdir, tests[i].name); + exit(1); + } + /* Explicitly reset the locale before each test. */ + setlocale(LC_ALL, "C"); + /* Record the umask before we run the test. */ + umask(oldumask = umask(0)); + /* + * Run the actual test. + */ + (*tests[i].func)(); + /* + * Clean up and report afterwards. + */ + /* Restore umask */ + umask(oldumask); + /* Reset locale. */ + setlocale(LC_ALL, "C"); + /* Reset directory. */ + if (!assertChdir(tmpdir)) { + fprintf(stderr, "ERROR: Couldn't chdir to temp dir %s\n", + tmpdir); + exit(1); + } + /* Report per-test summaries. */ + tests[i].failures = failures - failures_before; + test_summarize(test_filename, tests[i].failures); + /* Close the per-test log file. */ + fclose(logfile); + logfile = NULL; + /* If there were no failures, we can remove the work dir and logfile. */ + if (tests[i].failures == 0) { + if (!keep_temp_files && assertChdir(tmpdir)) { +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Make sure not to leave empty directories. + * Sometimes a processing of closing files used by tests + * is not done, then rmdir will be failed and it will + * leave a empty test directory. So we should wait a few + * seconds and retry rmdir. */ + int r, t; + for (t = 0; t < 10; t++) { + if (t > 0) + Sleep(1000); + r = systemf("rmdir /S /Q %s", tests[i].name); + if (r == 0) + break; + } + systemf("del %s", logfilename); +#else + systemf("rm -rf %s", tests[i].name); + systemf("rm %s", logfilename); +#endif + } + } + /* Return appropriate status. */ + return (tests[i].failures); +} + +/* + * + * + * MAIN and support routines. + * + * + */ + +static void +usage(const char *program) +{ + static const int limit = sizeof(tests) / sizeof(tests[0]); + int i; + + printf("Usage: %s [options] ...\n", program); + printf("Default is to run all tests.\n"); + printf("Otherwise, specify the numbers of the tests you wish to run.\n"); + printf("Options:\n"); + printf(" -d Dump core after any failure, for debugging.\n"); + printf(" -k Keep all temp files.\n"); + printf(" Default: temp files for successful tests deleted.\n"); +#ifdef PROGRAM + printf(" -p Path to executable to be tested.\n"); + printf(" Default: path taken from " ENVBASE " environment variable.\n"); +#endif + printf(" -q Quiet.\n"); + printf(" -r Path to dir containing reference files.\n"); + printf(" Default: Current directory.\n"); + printf(" -v Verbose.\n"); + printf("Available tests:\n"); + for (i = 0; i < limit; i++) + printf(" %d: %s\n", i, tests[i].name); + exit(1); +} + +static char * +get_refdir(const char *d) +{ + char tried[512] = { '\0' }; + char buff[128]; + char *pwd, *p; + + /* If a dir was specified, try that */ + if (d != NULL) { + pwd = NULL; + snprintf(buff, sizeof(buff), "%s", d); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + goto failure; + } + + /* Get the current dir. */ + pwd = getcwd(NULL, 0); + while (pwd[strlen(pwd) - 1] == '\n') + pwd[strlen(pwd) - 1] = '\0'; + + /* Look for a known file. */ + snprintf(buff, sizeof(buff), "%s", pwd); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + + snprintf(buff, sizeof(buff), "%s/test", pwd); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + +#if defined(LIBRARY) + snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY); +#else + snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM); +#endif + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + + if (memcmp(pwd, "/usr/obj", 8) == 0) { + snprintf(buff, sizeof(buff), "%s", pwd + 8); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + + snprintf(buff, sizeof(buff), "%s/test", pwd + 8); + p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); + if (p != NULL) goto success; + strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); + strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); + } + +failure: + printf("Unable to locate known reference file %s\n", KNOWNREF); + printf(" Checked following directories:\n%s\n", tried); +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) + DebugBreak(); +#endif + exit(1); + +success: + free(p); + free(pwd); + return strdup(buff); +} + +int +main(int argc, char **argv) +{ + static const int limit = sizeof(tests) / sizeof(tests[0]); + int i, tests_run = 0, tests_failed = 0, option; + time_t now; + char *refdir_alloc = NULL; + const char *progname; + const char *tmp, *option_arg, *p; + char tmpdir[256]; + char tmpdir_timestamp[256]; + + (void)argc; /* UNUSED */ + +#if defined(HAVE__CrtSetReportMode) + /* To stop to run the default invalid parameter handler. */ + _set_invalid_parameter_handler(invalid_parameter_handler); + /* Disable annoying assertion message box. */ + _CrtSetReportMode(_CRT_ASSERT, 0); +#endif + + /* + * Name of this program, used to build root of our temp directory + * tree. + */ + progname = p = argv[0]; + while (*p != '\0') { + /* Support \ or / dir separators for Windows compat. */ + if (*p == '/' || *p == '\\') + progname = p + 1; + ++p; + } + +#ifdef PROGRAM + /* Get the target program from environment, if available. */ + testprogfile = getenv(ENVBASE); +#endif + + if (getenv("TMPDIR") != NULL) + tmp = getenv("TMPDIR"); + else if (getenv("TMP") != NULL) + tmp = getenv("TMP"); + else if (getenv("TEMP") != NULL) + tmp = getenv("TEMP"); + else if (getenv("TEMPDIR") != NULL) + tmp = getenv("TEMPDIR"); + else + tmp = "/tmp"; + + /* Allow -d to be controlled through the environment. */ + if (getenv(ENVBASE "_DEBUG") != NULL) + dump_on_failure = 1; + + /* Get the directory holding test files from environment. */ + refdir = getenv(ENVBASE "_TEST_FILES"); + + /* + * Parse options, without using getopt(), which isn't available + * on all platforms. + */ + ++argv; /* Skip program name */ + while (*argv != NULL) { + if (**argv != '-') + break; + p = *argv++; + ++p; /* Skip '-' */ + while (*p != '\0') { + option = *p++; + option_arg = NULL; + /* If 'opt' takes an argument, parse that. */ + if (option == 'p' || option == 'r') { + if (*p != '\0') + option_arg = p; + else if (*argv == NULL) { + fprintf(stderr, + "Option -%c requires argument.\n", + option); + usage(progname); + } else + option_arg = *argv++; + p = ""; /* End of this option word. */ + } + + /* Now, handle the option. */ + switch (option) { + case 'd': + dump_on_failure = 1; + break; + case 'k': + keep_temp_files = 1; + break; + case 'p': +#ifdef PROGRAM + testprogfile = option_arg; +#else + fprintf(stderr, "-p option not permitted\n"); + usage(progname); +#endif + break; + case 'q': + verbosity--; + break; + case 'r': + refdir = option_arg; + break; + case 'v': + verbosity++; + break; + default: + fprintf(stderr, "Unrecognized option '%c'\n", + option); + usage(progname); + } + } + } + + /* + * Sanity-check that our options make sense. + */ +#ifdef PROGRAM + if (testprogfile == NULL) { + fprintf(stderr, "Program executable required\n"); + usage(progname); + } + + { + char *testprg; +#if defined(_WIN32) && !defined(__CYGWIN__) + /* Command.com sometimes rejects '/' separators. */ + testprg = strdup(testprogfile); + for (i = 0; testprg[i] != '\0'; i++) { + if (testprg[i] == '/') + testprg[i] = '\\'; + } + testprogfile = testprg; +#endif + /* Quote the name that gets put into shell command lines. */ + testprg = malloc(strlen(testprogfile) + 3); + strcpy(testprg, "\""); + strcat(testprg, testprogfile); + strcat(testprg, "\""); + testprog = testprg; + } +#endif + + /* + * Create a temp directory for the following tests. + * Include the time the tests started as part of the name, + * to make it easier to track the results of multiple tests. + */ + now = time(NULL); + for (i = 0; ; i++) { + strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), + "%Y-%m-%dT%H.%M.%S", + localtime(&now)); + sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname, + tmpdir_timestamp, i); + if (assertMakeDir(tmpdir,0755)) + break; + if (i >= 999) { + fprintf(stderr, + "ERROR: Unable to create temp directory %s\n", + tmpdir); + exit(1); + } + } + + /* + * If the user didn't specify a directory for locating + * reference files, try to find the reference files in + * the "usual places." + */ + refdir = refdir_alloc = get_refdir(refdir); + + /* + * Banner with basic information. + */ + printf("\n"); + printf("If tests fail or crash, details will be in:\n"); + printf(" %s\n", tmpdir); + printf("\n"); + if (verbosity > VERBOSITY_SUMMARY_ONLY) { + printf("Reference files will be read from: %s\n", refdir); +#ifdef PROGRAM + printf("Running tests on: %s\n", testprog); +#endif + printf("Exercising: "); + fflush(stdout); + printf("%s\n", EXTRA_VERSION); + } else { + printf("Running "); + fflush(stdout); + } + + /* + * Run some or all of the individual tests. + */ + if (*argv == NULL) { + /* Default: Run all tests. */ + for (i = 0; i < limit; i++) { + if (test_run(i, tmpdir)) + tests_failed++; + tests_run++; + } + } else { + while (*(argv) != NULL) { + if (**argv >= '0' && **argv <= '9') { + i = atoi(*argv); + if (i < 0 || i >= limit) { + printf("*** INVALID Test %s\n", *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } + } else { + for (i = 0; i < limit; ++i) { + if (strcmp(*argv, tests[i].name) == 0) + break; + } + if (i >= limit) { + printf("*** INVALID Test ``%s''\n", + *argv); + free(refdir_alloc); + usage(progname); + /* usage() never returns */ + } + } + if (test_run(i, tmpdir)) + tests_failed++; + tests_run++; + argv++; + } + } + + /* + * Report summary statistics. + */ + if (verbosity > VERBOSITY_SUMMARY_ONLY) { + printf("\n"); + printf("Totals:\n"); + printf(" Tests run: %8d\n", tests_run); + printf(" Tests failed: %8d\n", tests_failed); + printf(" Assertions checked:%8d\n", assertions); + printf(" Assertions failed: %8d\n", failures); + printf(" Skips reported: %8d\n", skips); + } + if (failures) { + printf("\n"); + printf("Failing tests:\n"); + for (i = 0; i < limit; ++i) { + if (tests[i].failures) + printf(" %d: %s (%d failures)\n", i, + tests[i].name, tests[i].failures); + } + printf("\n"); + printf("Details for failing tests: %s\n", tmpdir); + printf("\n"); + } else { + if (verbosity == VERBOSITY_SUMMARY_ONLY) + printf("\n"); + printf("%d tests passed, no failures\n", tests_run); + } + + free(refdir_alloc); + + /* If the final tmpdir is empty, we can remove it. */ + /* This should be the usual case when all tests succeed. */ + assertChdir(".."); + rmdir(tmpdir); + + return (tests_failed ? 1 : 0); +} diff --git a/external/bsd/libarchive/dist/tar/test/test.h b/external/bsd/libarchive/dist/tar/test/test.h new file mode 100644 index 000000000..d93695925 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test.h @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2003-2006 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/usr.bin/tar/test/test.h,v 1.4 2008/08/21 07:04:57 kientzle Exp $ + */ + +/* Every test program should #include "test.h" as the first thing. */ + +/* + * The goal of this file (and the matching test.c) is to + * simplify the very repetitive test-*.c test programs. + */ +#if defined(HAVE_CONFIG_H) +/* Most POSIX platforms use the 'configure' script to build config.h */ +#include "config.h" +#elif defined(__FreeBSD__) +/* Building as part of FreeBSD system requires a pre-built config.h. */ +#include "config_freebsd.h" +#elif defined(_WIN32) && !defined(__CYGWIN__) +/* Win32 can't run the 'configure' script. */ +#include "config_windows.h" +#else +/* Warn if the library hasn't been (automatically or manually) configured. */ +#error Oops: No config.h and no pre-built configuration in test.h. +#endif + +#include /* Windows requires this before sys/stat.h */ +#include + +#ifdef USE_DMALLOC +#include +#endif +#if HAVE_DIRENT_H +#include +#endif +#ifdef HAVE_DIRECT_H +#include +#define dirent direct +#endif +#include +#include +#ifdef HAVE_IO_H +#include +#endif +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#ifdef HAVE_WINDOWS_H +#include +#endif + +/* + * System-specific tweaks. We really want to minimize these + * as much as possible, since they make it harder to understand + * the mainline code. + */ + +/* Windows (including Visual Studio and MinGW but not Cygwin) */ +#if defined(_WIN32) && !defined(__CYGWIN__) +#include "../bsdtar_windows.h" +#if !defined(__BORLANDC__) +#define strdup _strdup +#endif +#define LOCALE_DE "deu" +#else +#define LOCALE_DE "de_DE.UTF-8" +#endif + +/* Visual Studio */ +#ifdef _MSC_VER +#define snprintf sprintf_s +#endif + +/* Cygwin */ +#if defined(__CYGWIN__) +/* Cygwin-1.7.x is lazy about populating nlinks, so don't + * expect it to be accurate. */ +# define NLINKS_INACCURATE_FOR_DIRS +#endif + +#if defined(__HAIKU__) || defined(__QNXNTO__) +/* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */ +#include +#endif + +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID +#define __FBSDID(a) struct _undefined_hack +#endif + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +/* + * Redefine DEFINE_TEST for use in defining the test functions. + */ +#undef DEFINE_TEST +#define DEFINE_TEST(name) void name(void); void name(void) + +/* An implementation of the standard assert() macro */ +#define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL) +/* chdir() and error if it fails */ +#define assertChdir(path) \ + assertion_chdir(__FILE__, __LINE__, path) +/* Assert two integers are the same. Reports value of each one if not. */ +#define assertEqualInt(v1,v2) \ + assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) +/* Assert two strings are the same. Reports value of each one if not. */ +#define assertEqualString(v1,v2) \ + assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) +/* As above, but v1 and v2 are wchar_t * */ +#define assertEqualWString(v1,v2) \ + assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) +/* As above, but raw blocks of bytes. */ +#define assertEqualMem(v1, v2, l) \ + assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL) +/* Assert two files are the same; allow printf-style expansion of second name. + * See below for comments about variable arguments here... + */ +#define assertEqualFile \ + assertion_setup(__FILE__, __LINE__);assertion_equal_file +/* Assert that a file is empty; supports printf-style arguments. */ +#define assertEmptyFile \ + assertion_setup(__FILE__, __LINE__);assertion_empty_file +/* Assert that a file is not empty; supports printf-style arguments. */ +#define assertNonEmptyFile \ + assertion_setup(__FILE__, __LINE__);assertion_non_empty_file +#define assertFileAtime(pathname, sec, nsec) \ + assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec) +#define assertFileAtimeRecent(pathname) \ + assertion_file_atime_recent(__FILE__, __LINE__, pathname) +#define assertFileBirthtime(pathname, sec, nsec) \ + assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec) +#define assertFileBirthtimeRecent(pathname) \ + assertion_file_birthtime_recent(__FILE__, __LINE__, pathname) +/* Assert that a file exists; supports printf-style arguments. */ +#define assertFileExists \ + assertion_setup(__FILE__, __LINE__);assertion_file_exists +/* Assert that a file exists; supports printf-style arguments. */ +#define assertFileNotExists \ + assertion_setup(__FILE__, __LINE__);assertion_file_not_exists +/* Assert that file contents match a string; supports printf-style arguments. */ +#define assertFileContents \ + assertion_setup(__FILE__, __LINE__);assertion_file_contents +#define assertFileMtime(pathname, sec, nsec) \ + assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec) +#define assertFileMtimeRecent(pathname) \ + assertion_file_mtime_recent(__FILE__, __LINE__, pathname) +#define assertFileNLinks(pathname, nlinks) \ + assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks) +#define assertFileSize(pathname, size) \ + assertion_file_size(__FILE__, __LINE__, pathname, size) +#define assertTextFileContents \ + assertion_setup(__FILE__, __LINE__);assertion_text_file_contents +#define assertFileContainsLinesAnyOrder(pathname, lines) \ + assertion_file_contains_lines_any_order(__FILE__, __LINE__, pathname, lines) +#define assertIsDir(pathname, mode) \ + assertion_is_dir(__FILE__, __LINE__, pathname, mode) +#define assertIsHardlink(path1, path2) \ + assertion_is_hardlink(__FILE__, __LINE__, path1, path2) +#define assertIsNotHardlink(path1, path2) \ + assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2) +#define assertIsReg(pathname, mode) \ + assertion_is_reg(__FILE__, __LINE__, pathname, mode) +#define assertIsSymlink(pathname, contents) \ + assertion_is_symlink(__FILE__, __LINE__, pathname, contents) +/* Create a directory, report error if it fails. */ +#define assertMakeDir(dirname, mode) \ + assertion_make_dir(__FILE__, __LINE__, dirname, mode) +#define assertMakeFile(path, mode, contents) \ + assertion_make_file(__FILE__, __LINE__, path, mode, contents) +#define assertMakeHardlink(newfile, oldfile) \ + assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile) +#define assertMakeSymlink(newfile, linkto) \ + assertion_make_symlink(__FILE__, __LINE__, newfile, linkto) +#define assertUmask(mask) \ + assertion_umask(__FILE__, __LINE__, mask) + +/* + * This would be simple with C99 variadic macros, but I don't want to + * require that. Instead, I insert a function call before each + * skipping() call to pass the file and line information down. Crude, + * but effective. + */ +#define skipping \ + assertion_setup(__FILE__, __LINE__);test_skipping + +/* Function declarations. These are defined in test_utility.c. */ +void failure(const char *fmt, ...); +int assertion_assert(const char *, int, int, const char *, void *); +int assertion_chdir(const char *, int, const char *); +int assertion_empty_file(const char *, ...); +int assertion_equal_file(const char *, const char *, ...); +int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *); +int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *); +int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *); +int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); +int assertion_file_atime(const char *, int, const char *, long, long); +int assertion_file_atime_recent(const char *, int, const char *); +int assertion_file_birthtime(const char *, int, const char *, long, long); +int assertion_file_birthtime_recent(const char *, int, const char *); +int assertion_file_contains_lines_any_order(const char *, int, const char *, const char **); +int assertion_file_contents(const void *, int, const char *, ...); +int assertion_file_exists(const char *, ...); +int assertion_file_mtime(const char *, int, const char *, long, long); +int assertion_file_mtime_recent(const char *, int, const char *); +int assertion_file_nlinks(const char *, int, const char *, int); +int assertion_file_not_exists(const char *, ...); +int assertion_file_size(const char *, int, const char *, long); +int assertion_is_dir(const char *, int, const char *, int); +int assertion_is_hardlink(const char *, int, const char *, const char *); +int assertion_is_not_hardlink(const char *, int, const char *, const char *); +int assertion_is_reg(const char *, int, const char *, int); +int assertion_is_symlink(const char *, int, const char *, const char *); +int assertion_make_dir(const char *, int, const char *, int); +int assertion_make_file(const char *, int, const char *, int, const char *); +int assertion_make_hardlink(const char *, int, const char *newpath, const char *); +int assertion_make_symlink(const char *, int, const char *newpath, const char *); +int assertion_non_empty_file(const char *, ...); +int assertion_text_file_contents(const char *buff, const char *f); +int assertion_umask(const char *, int, int); +void assertion_setup(const char *, int); + +void test_skipping(const char *fmt, ...); + +/* Like sprintf, then system() */ +int systemf(const char * fmt, ...); + +/* Delay until time() returns a value after this. */ +void sleepUntilAfter(time_t); + +/* Return true if this platform can create symlinks. */ +int canSymlink(void); + +/* Return true if this platform can run the "gzip" program. */ +int canGzip(void); + +/* Return true if this platform can run the "gunzip" program. */ +int canGunzip(void); + +/* Suck file into string allocated via malloc(). Call free() when done. */ +/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ +char *slurpfile(size_t *, const char *fmt, ...); + +/* Extracts named reference file to the current directory. */ +void extract_reference_file(const char *); + +/* + * Special interfaces for program test harness. + */ + +/* Pathname of exe to be tested. */ +const char *testprogfile; +/* Name of exe to use in printf-formatted command strings. */ +/* On Windows, this includes leading/trailing quotes. */ +const char *testprog; diff --git a/external/bsd/libarchive/dist/tar/test/test_0.c b/external/bsd/libarchive/dist/tar/test/test_0.c new file mode 100644 index 000000000..c9277da16 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_0.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_0.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); + +/* + * This first test does basic sanity checks on the environment. For + * most of these, we just exit on failure. + */ +#if !defined(_WIN32) || defined(__CYGWIN__) +#define DEV_NULL "/dev/null" +#else +#define DEV_NULL "NUL" +#endif + +DEFINE_TEST(test_0) +{ + struct stat st; + + failure("File %s does not exist?!", testprog); + if (!assertEqualInt(0, stat(testprogfile, &st))) + exit(1); + + failure("%s is not executable?!", testprog); + if (!assert((st.st_mode & 0111) != 0)) + exit(1); + + /* + * Try to succesfully run the program; this requires that + * we know some option that will succeed. + */ + if (0 == systemf("%s --version >" DEV_NULL, testprog)) { + /* This worked. */ + } else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) { + /* This worked. */ + } else { + failure("Unable to successfully run any of the following:\n" + " * %s --version\n" + " * %s -W version\n", + testprog, testprog); + assert(0); + } + + /* TODO: Ensure that our reference files are available. */ +} diff --git a/external/bsd/libarchive/dist/tar/test/test_basic.c b/external/bsd/libarchive/dist/tar/test/test_basic.c new file mode 100644 index 000000000..4dc7cf636 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_basic.c @@ -0,0 +1,115 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_basic.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); + + +static void +basic_tar(const char *target, const char *pack_options, + const char *unpack_options, const char *flist) +{ + int r; + + assertMakeDir(target, 0775); + + /* Use the tar program to create an archive. */ + r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target); + failure("Error invoking %s cf -", testprog, pack_options); + assertEqualInt(r, 0); + + assertChdir(target); + + /* Verify that nothing went to stderr. */ + assertEmptyFile("pack.err"); + + /* + * Use tar to unpack the archive into another directory. + */ + r = systemf("%s xf archive %s >unpack.out 2>unpack.err", testprog, unpack_options); + failure("Error invoking %s xf archive %s", testprog, unpack_options); + assertEqualInt(r, 0); + + /* Verify that nothing went to stderr. */ + assertEmptyFile("unpack.err"); + + /* + * Verify unpacked files. + */ + + /* Regular file with 2 links. */ + assertIsReg("file", -1); + assertFileSize("file", 10); + failure("%s", target); + assertFileNLinks("file", 2); + + /* Another name for the same file. */ + assertIsReg("linkfile", -1); + assertFileSize("linkfile", 10); + assertFileNLinks("linkfile", 2); + assertIsHardlink("file", "linkfile"); + + /* Symlink */ + if (canSymlink()) + assertIsSymlink("symlink", "file"); + + /* dir */ + assertIsDir("dir", 0775); + assertChdir(".."); +} + +DEFINE_TEST(test_basic) +{ + FILE *f; + const char *flist; + + assertUmask(0); + + /* File with 10 bytes content. */ + f = fopen("file", "wb"); + assert(f != NULL); + assertEqualInt(10, fwrite("123456789", 1, 10, f)); + fclose(f); + + /* hardlink to above file. */ + assertMakeHardlink("linkfile", "file"); + assertIsHardlink("file", "linkfile"); + + /* Symlink to above file. */ + if (canSymlink()) + assertMakeSymlink("symlink", "file"); + + /* Directory. */ + assertMakeDir("dir", 0775); + + if (canSymlink()) + flist = "file linkfile symlink dir"; + else + flist = "file linkfile dir"; + /* Archive/dearchive with a variety of options. */ + basic_tar("copy", "", "", flist); + /* tar doesn't handle cpio symlinks correctly */ + /* basic_tar("copy_odc", "--format=odc", ""); */ + basic_tar("copy_ustar", "--format=ustar", "", flist); +} diff --git a/external/bsd/libarchive/dist/tar/test/test_copy.c b/external/bsd/libarchive/dist/tar/test/test_copy.c new file mode 100644 index 000000000..69112900e --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_copy.c @@ -0,0 +1,372 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_copy.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $"); + +#if defined(__CYGWIN__) +# include +# include +#endif + +/* + * Try to figure out how deep we can go in our tests. Assumes that + * the first call to this function has the longest starting cwd (which + * is currently "/original"). This is mostly to work around + * limits in our Win32 support. + * + * Background: On Posix systems, PATH_MAX is merely a limit on the + * length of the string passed into a system call. By repeatedly + * calling chdir(), you can work with arbitrarily long paths on such + * systems. In contrast, Win32 APIs apply PATH_MAX limits to the full + * absolute path, so the permissible length of a system call argument + * varies with the cwd. Some APIs actually enforce limits + * significantly less than PATH_MAX to ensure that you can create + * files within the current working directory. The Win32 limits also + * apply to Cygwin before 1.7. + * + * Someday, I want to convert the Win32 support to use newer + * wide-character paths with '\\?\' prefix, which has a 32k PATH_MAX + * instead of the rather anemic 260 character limit of the older + * system calls. Then we can drop this mess (unless we want to + * continue to special-case Cygwin 1.5 and earlier). + */ +static int +compute_loop_max(void) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + static int LOOP_MAX = 0; + char buf[MAX_PATH]; + size_t cwdlen; + + if (LOOP_MAX == 0) { + assert(_getcwd(buf, MAX_PATH) != NULL); + cwdlen = strlen(buf); + /* 12 characters = length of 8.3 filename */ + /* 4 characters = length of "/../" used in symlink tests */ + /* 1 character = length of extra "/" separator */ + LOOP_MAX = MAX_PATH - (int)cwdlen - 12 - 4 - 1; + } + return LOOP_MAX; +#elif defined(__CYGWIN__) && !defined(HAVE_CYGWIN_CONV_PATH) + static int LOOP_MAX = 0; + if (LOOP_MAX == 0) { + char wbuf[PATH_MAX]; + char pbuf[PATH_MAX]; + size_t wcwdlen; + size_t pcwdlen; + size_t cwdlen; + assert(getcwd(pbuf, PATH_MAX) != NULL); + pcwdlen = strlen(pbuf); + cygwin_conv_to_full_win32_path(pbuf, wbuf); + wcwdlen = strlen(wbuf); + cwdlen = ((wcwdlen > pcwdlen) ? wcwdlen : pcwdlen); + /* Cygwin helper needs an extra few characters. */ + LOOP_MAX = PATH_MAX - (int)cwdlen - 12 - 4 - 4; + } + return LOOP_MAX; +#else + /* cygwin-1.7 ends up here, along with "normal" unix */ + return 200; /* restore pre-r278 depth */ +#endif +} + +/* filenames[i] is a distinctive filename of length i. */ +/* To simplify interpreting failures, each filename ends with a + * decimal integer which is the length of the filename. E.g., A + * filename ending in "_92" is 92 characters long. To detect errors + * which drop or misplace characters, the filenames use a repeating + * "abcdefghijklmnopqrstuvwxyz..." pattern. */ +static char *filenames[201]; + +static void +compute_filenames(void) +{ + char buff[250]; + size_t i,j; + + filenames[0] = strdup(""); + filenames[1] = strdup("1"); + filenames[2] = strdup("a2"); + for (i = 3; i < sizeof(filenames)/sizeof(filenames[0]); ++i) { + /* Fill with "abcdefghij..." */ + for (j = 0; j < i; ++j) + buff[j] = 'a' + (j % 26); + buff[j--] = '\0'; + /* Work from the end to fill in the number portion. */ + buff[j--] = '0' + (i % 10); + if (i > 9) { + buff[j--] = '0' + ((i / 10) % 10); + if (i > 99) + buff[j--] = '0' + (i / 100); + } + buff[j] = '_'; + /* Guard against obvious screwups in the above code. */ + assertEqualInt(strlen(buff), i); + filenames[i] = strdup(buff); + } +} + +static void +create_tree(void) +{ + char buff[260]; + char buff2[260]; + int i; + int LOOP_MAX; + + compute_filenames(); + + /* Log that we'll be omitting some checks. */ + if (!canSymlink()) { + skipping("Symlink checks"); + } + + assertMakeDir("original", 0775); + assertEqualInt(0, chdir("original")); + LOOP_MAX = compute_loop_max(); + + assertMakeDir("f", 0775); + assertMakeDir("l", 0775); + assertMakeDir("m", 0775); + assertMakeDir("s", 0775); + assertMakeDir("d", 0775); + + for (i = 1; i < LOOP_MAX; i++) { + failure("Internal sanity check failed: i = %d", i); + assert(filenames[i] != NULL); + + sprintf(buff, "f/%s", filenames[i]); + assertMakeFile(buff, 0777, buff); + + /* Create a link named "l/abcdef..." to the above. */ + sprintf(buff2, "l/%s", filenames[i]); + assertMakeHardlink(buff2, buff); + + /* Create a link named "m/abcdef..." to the above. */ + sprintf(buff2, "m/%s", filenames[i]); + assertMakeHardlink(buff2, buff); + + if (canSymlink()) { + /* Create a symlink named "s/abcdef..." to the above. */ + sprintf(buff, "s/%s", filenames[i]); + sprintf(buff2, "../f/%s", filenames[i]); + failure("buff=\"%s\" buff2=\"%s\"", buff, buff2); + assertMakeSymlink(buff, buff2); + } + /* Create a dir named "d/abcdef...". */ + buff[0] = 'd'; + failure("buff=\"%s\"", buff); + assertMakeDir(buff, 0775); + } + + assertEqualInt(0, chdir("..")); +} + +#define LIMIT_NONE 200 +#define LIMIT_USTAR 100 + +static void +verify_tree(size_t limit) +{ + char name1[260]; + char name2[260]; + size_t i, LOOP_MAX; + + LOOP_MAX = compute_loop_max(); + + /* Generate the names we know should be there and verify them. */ + for (i = 1; i < LOOP_MAX; i++) { + /* Verify a file named "f/abcdef..." */ + sprintf(name1, "f/%s", filenames[i]); + if (i <= limit) { + assertFileExists(name1); + assertFileContents(name1, strlen(name1), name1); + } + + sprintf(name2, "l/%s", filenames[i]); + if (i + 2 <= limit) { + /* Verify hardlink "l/abcdef..." */ + assertIsHardlink(name1, name2); + /* Verify hardlink "m/abcdef..." */ + name2[0] = 'm'; + assertIsHardlink(name1, name2); + } + + if (canSymlink()) { + /* Verify symlink "s/abcdef..." */ + sprintf(name1, "s/%s", filenames[i]); + sprintf(name2, "../f/%s", filenames[i]); + if (strlen(name2) <= limit) + assertIsSymlink(name1, name2); + } + + /* Verify dir "d/abcdef...". */ + sprintf(name1, "d/%s", filenames[i]); + if (i + 1 <= limit) { /* +1 for trailing slash */ + if (assertIsDir(name1, -1)) { + /* TODO: opendir/readdir this + * directory and make sure + * it's empty. + */ + } + } + } + +#if !defined(_WIN32) || defined(__CYGWIN__) + { + const char *dp; + /* Now make sure nothing is there that shouldn't be. */ + for (dp = "dflms"; *dp != '\0'; ++dp) { + DIR *d; + struct dirent *de; + char dir[2]; + dir[0] = *dp; dir[1] = '\0'; + d = opendir(dir); + failure("Unable to open dir '%s'", dir); + if (!assert(d != NULL)) + continue; + while ((de = readdir(d)) != NULL) { + char *p = de->d_name; + if (p[0] == '.') + continue; + switch(dp[0]) { + case 'l': case 'm': case 'd': + failure("strlen(p)=%d", strlen(p)); + assert(strlen(p) < limit); + assertEqualString(p, + filenames[strlen(p)]); + break; + case 'f': case 's': + failure("strlen(p)=%d", strlen(p)); + assert(strlen(p) < limit + 1); + assertEqualString(p, + filenames[strlen(p)]); + break; + default: + failure("File %s shouldn't be here", p); + assert(0); + } + } + closedir(d); + } + } +#endif +} + +static void +copy_basic(void) +{ + int r; + + /* NOTE: for proper operation on cygwin-1.5 and windows, the + * length of the name of the directory below, "plain", must be + * less than or equal to the lengthe of the name of the original + * directory, "original" This restriction derives from the + * extremely limited pathname lengths on those platforms. + */ + assertMakeDir("plain", 0775); + assertEqualInt(0, chdir("plain")); + + /* + * Use the tar program to create an archive. + */ + r = systemf("%s cf archive -C ../original f d l m s >pack.out 2>pack.err", + testprog); + failure("Error invoking \"%s cf\"", testprog); + assertEqualInt(r, 0); + + /* Verify that nothing went to stdout or stderr. */ + assertEmptyFile("pack.err"); + assertEmptyFile("pack.out"); + + /* + * Use tar to unpack the archive into another directory. + */ + r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog); + failure("Error invoking %s xf archive", testprog); + assertEqualInt(r, 0); + + /* Verify that nothing went to stdout or stderr. */ + assertEmptyFile("unpack.err"); + assertEmptyFile("unpack.out"); + + verify_tree(LIMIT_NONE); + assertEqualInt(0, chdir("..")); +} + +static void +copy_ustar(void) +{ + const char *target = "ustar"; + int r; + + /* NOTE: for proper operation on cygwin-1.5 and windows, the + * length of the name of the directory below, "ustar", must be + * less than or equal to the lengthe of the name of the original + * directory, "original" This restriction derives from the + * extremely limited pathname lengths on those platforms. + */ + assertMakeDir(target, 0775); + assertEqualInt(0, chdir(target)); + + /* + * Use the tar program to create an archive. + */ + r = systemf("%s cf archive --format=ustar -C ../original f d l m s >pack.out 2>pack.err", + testprog); + failure("Error invoking \"%s cf archive --format=ustar\"", testprog); + assertEqualInt(r, 0); + + /* Verify that nothing went to stdout. */ + assertEmptyFile("pack.out"); + /* Stderr is non-empty, since there are a bunch of files + * with filenames too long to archive. */ + + /* + * Use tar to unpack the archive into another directory. + */ + r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog); + failure("Error invoking %s xf archive", testprog); + assertEqualInt(r, 0); + + /* Verify that nothing went to stdout or stderr. */ + assertEmptyFile("unpack.err"); + assertEmptyFile("unpack.out"); + + verify_tree(LIMIT_USTAR); + assertEqualInt(0, chdir("../..")); +} + +DEFINE_TEST(test_copy) +{ + assertUmask(0); + create_tree(); /* Create sample files in "original" dir. */ + + /* Test simple "tar -c | tar -x" pipeline copy. */ + copy_basic(); + + /* Same, but constrain to ustar format. */ + copy_ustar(); +} diff --git a/external/bsd/libarchive/dist/tar/test/test_empty_mtree.c b/external/bsd/libarchive/dist/tar/test/test_empty_mtree.c new file mode 100644 index 000000000..6f8a5e91a --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_empty_mtree.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +/* + * Regression test: We used to get a bogus error message when we + * asked tar to copy entries out of an empty archive. See + * Issue 51 on libarchive.googlecode.com for details. + */ +DEFINE_TEST(test_empty_mtree) +{ + int r; + + assertMakeFile("test1.mtree", 0777, "#mtree\n"); + + r = systemf("%s cf test1.tar @test1.mtree >test1.out 2>test1.err", + testprog); + failure("Error invoking %s cf", testprog); + assertEqualInt(r, 0); + assertEmptyFile("test1.out"); + assertEmptyFile("test1.err"); +} diff --git a/external/bsd/libarchive/dist/tar/test/test_getdate.c b/external/bsd/libarchive/dist/tar/test/test_getdate.c new file mode 100644 index 000000000..eac571049 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_getdate.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_getdate.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); + +#include + +/* + * Verify that the getdate() function works. + */ + +time_t get_date(time_t, const char *); + +DEFINE_TEST(test_getdate) +{ + time_t now = time(NULL); + + assertEqualInt(get_date(now, "Jan 1, 1970 UTC"), 0); + assertEqualInt(get_date(now, "7:12:18-0530 4 May 1983"), 420900138); + assertEqualInt(get_date(now, "2004/01/29 513 mest"), 1075345980); + assertEqualInt(get_date(now, "99/02/17 7pm utc"), 919278000); + assertEqualInt(get_date(now, "02/17/99 7:11am est"), 919253460); + /* It's important that we handle ctime() format. */ + assertEqualInt(get_date(now, "Sun Feb 22 17:38:26 PST 2009"), + 1235353106); + /* Basic relative offsets. */ + /* If we use the actual current time as the reference, then + * these tests break around DST changes, so it's actually + * important to use a specific reference time here. */ + assertEqualInt(get_date(0, "tomorrow"), 24 * 60 * 60); + assertEqualInt(get_date(0, "yesterday"), - 24 * 60 * 60); + assertEqualInt(get_date(0, "now + 1 hour"), 60 * 60); + assertEqualInt(get_date(0, "now + 1 hour + 1 minute"), 60 * 60 + 60); + /* Repeat the above for a different start time. */ + now = 1231113600; /* Jan 5, 2009 00:00 UTC */ + assertEqualInt(get_date(0, "Jan 5, 2009 00:00 UTC"), now); + assertEqualInt(get_date(now, "tomorrow"), now + 24 * 60 * 60); + assertEqualInt(get_date(now, "yesterday"), now - 24 * 60 * 60); + assertEqualInt(get_date(now, "now + 1 hour"), now + 60 * 60); + assertEqualInt(get_date(now, "now + 1 hour + 1 minute"), + now + 60 * 60 + 60); + assertEqualInt(get_date(now, "tomorrow 5:16am UTC"), + now + 24 * 60 * 60 + 5 * 60 * 60 + 16 * 60); + assertEqualInt(get_date(now, "UTC 5:16am tomorrow"), + now + 24 * 60 * 60 + 5 * 60 * 60 + 16 * 60); + + /* Jan 5, 2009 was a Monday. */ + assertEqualInt(get_date(now, "monday UTC"), now); + assertEqualInt(get_date(now, "sunday UTC"), now + 6 * 24 * 60 * 60); + assertEqualInt(get_date(now, "tuesday UTC"), now + 24 * 60 * 60); + /* "next tuesday" is one week after "tuesday" */ + assertEqualInt(get_date(now, "UTC next tuesday"), + now + 8 * 24 * 60 * 60); + /* "last tuesday" is one week before "tuesday" */ + assertEqualInt(get_date(now, "last tuesday UTC"), + now - 6 * 24 * 60 * 60); + /* TODO: Lots more tests here. */ +} diff --git a/external/bsd/libarchive/dist/tar/test/test_help.c b/external/bsd/libarchive/dist/tar/test/test_help.c new file mode 100644 index 000000000..3bb517d00 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_help.c @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_help.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); + +/* + * Test that "--help", "-h", and "-W help" options all work and + * generate reasonable output. + */ + +static int +in_first_line(const char *p, const char *substring) +{ + size_t l = strlen(substring); + + while (*p != '\0' && *p != '\n') { + if (memcmp(p, substring, l) == 0) + return (1); + ++p; + } + return (0); +} + +DEFINE_TEST(test_help) +{ + int r; + char *p; + size_t plen; + + /* Exercise --help option. */ + r = systemf("%s --help >help.stdout 2>help.stderr", testprog); + assertEqualInt(r, 0); + failure("--help should generate nothing to stderr."); + assertEmptyFile("help.stderr"); + /* Help message should start with name of program. */ + p = slurpfile(&plen, "help.stdout"); + failure("Help output should be long enough."); + assert(plen >= 6); + failure("First line of help output should contain 'bsdtar': %s", p); + assert(in_first_line(p, "bsdtar")); + /* + * TODO: Extend this check to further verify that --help output + * looks approximately right. + */ + free(p); + + /* -h option should generate the same output. */ + r = systemf("%s -h >h.stdout 2>h.stderr", testprog); + assertEqualInt(r, 0); + failure("-h should generate nothing to stderr."); + assertEmptyFile("h.stderr"); + failure("stdout should be same for -h and --help"); + assertEqualFile("h.stdout", "help.stdout"); + + /* -W help should be another synonym. */ + r = systemf("%s -W help >Whelp.stdout 2>Whelp.stderr", testprog); + assertEqualInt(r, 0); + failure("-W help should generate nothing to stderr."); + assertEmptyFile("Whelp.stderr"); + failure("stdout should be same for -W help and --help"); + assertEqualFile("Whelp.stdout", "help.stdout"); +} diff --git a/external/bsd/libarchive/dist/tar/test/test_option_T_upper.c b/external/bsd/libarchive/dist/tar/test/test_option_T_upper.c new file mode 100644 index 000000000..3d2a8b1e2 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_option_T_upper.c @@ -0,0 +1,188 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $"); + +static int +touch(const char *fn, int fail) +{ + FILE *f = fopen(fn, "w"); + if (fail) { + failure("Couldn't create file '%s', errno=%d (%s)\n", + fn, errno, strerror(errno)); + if (!assert(f != NULL)) + return (0); /* Failure. */ + } else { + if (f == NULL) + return (0); /* Soft failure. */ + } + fclose(f); + return (1); /* Success */ +} + +DEFINE_TEST(test_option_T_upper) +{ + FILE *f; + int r; + struct stat st; + int gnarlyFilesSupported; + + /* Create a simple dir heirarchy; bail if anything fails. */ + if (!assertMakeDir("d1", 0755)) return; + if (!assertMakeDir("d1/d2", 0755)) return; + if (!touch("f", 1)) return; + if (!touch("d1/f1", 1)) return; + if (!touch("d1/f2", 1)) return; + if (!touch("d1/d2/f3", 1)) return; + if (!touch("d1/d2/f4", 1)) return; + if (!touch("d1/d2/f5", 1)) return; + if (!touch("d1/d2/f6", 1)) return; + /* Some platforms don't permit such things; just skip it. */ + gnarlyFilesSupported = touch("d1/d2/f\x0a", 0); + + /* Populate a file list */ + f = fopen("filelist", "w+"); + if (!assert(f != NULL)) + return; + /* Use a variety of text line endings. */ + fprintf(f, "f\x0d"); /* CR */ + fprintf(f, "d1/f1\x0d\x0a"); /* CRLF */ + fprintf(f, "d1/d2/f4\x0a"); /* NL */ + fprintf(f, "d1/d2/f6"); /* EOF */ + fclose(f); + + /* Populate a second file list */ + f = fopen("filelist2", "w+"); + if (!assert(f != NULL)) + return; + /* Use null-terminated names. */ + fprintf(f, "d1/d2/f3"); + fwrite("\0", 1, 1, f); + fprintf(f, "d1/d2/f5"); + fwrite("\0", 1, 1, f); + if (gnarlyFilesSupported) { + fprintf(f, "d1/d2/f\x0a"); + fwrite("\0", 1, 1, f); + } + fclose(f); + + /* Use -c -T to archive up the files. */ + r = systemf("%s -c -f test1.tar -T filelist > test1.out 2> test1.err", + testprog); + assert(r == 0); + assertEmptyFile("test1.out"); + assertEmptyFile("test1.err"); + + /* Use -x -T to dearchive the files */ + if (!assertMakeDir("test1", 0755)) return; + systemf("%s -x -f test1.tar -T filelist -C test1" + " > test1b.out 2> test1b.err", testprog); + assertEmptyFile("test1b.out"); + assertEmptyFile("test1b.err"); + + /* Verify the files were extracted. */ + assertFileExists("test1/f"); + assertFileExists("test1/d1/f1"); + assertFileNotExists("test1/d1/f2"); + assertFileNotExists("test1/d1/d2/f3"); + assertFileExists("test1/d1/d2/f4"); + assertFileNotExists("test1/d1/d2/f5"); + assertFileExists("test1/d1/d2/f6"); + if (gnarlyFilesSupported) { + assertFileNotExists("test1/d1/d2/f\x0a"); + } + + /* Use -r -T to add more files to the archive. */ + systemf("%s -r -f test1.tar --null -T filelist2 > test2.out 2> test2.err", + testprog); + assertEmptyFile("test2.out"); + assertEmptyFile("test2.err"); + + /* Use -x without -T to dearchive the files (ensure -r worked) */ + if (!assertMakeDir("test3", 0755)) return; + systemf("%s -x -f test1.tar -C test3" + " > test3.out 2> test3.err", testprog); + assertEmptyFile("test3.out"); + assertEmptyFile("test3.err"); + /* Verify the files were extracted.*/ + assertFileExists("test3/f"); + assertFileExists("test3/d1/f1"); + assertFileNotExists("test3/d1/f2"); + assertFileExists("test3/d1/d2/f3"); + assertFileExists("test3/d1/d2/f4"); + assertFileExists("test3/d1/d2/f5"); + assertFileExists("test3/d1/d2/f6"); + if (gnarlyFilesSupported) { + assertFileExists("test3/d1/d2/f\x0a"); + } + + /* Use -x -T to dearchive the files (verify -x -T together) */ + if (!assertMakeDir("test2", 0755)) return; + systemf("%s -x -f test1.tar -T filelist -C test2" + " > test2b.out 2> test2b.err", testprog); + assertEmptyFile("test2b.out"); + assertEmptyFile("test2b.err"); + /* Verify the files were extracted.*/ + assertFileExists("test2/f"); + assertFileExists("test2/d1/f1"); + assertFileNotExists("test2/d1/f2"); + assertFileNotExists("test2/d1/d2/f3"); + assertFileExists("test2/d1/d2/f4"); + assertFileNotExists("test2/d1/d2/f5"); + assertFileExists("test2/d1/d2/f6"); + if (gnarlyFilesSupported) { + assertFileNotExists("test2/d1/d2/f\x0a"); + } + + assertMakeDir("test4", 0755); + assertMakeDir("test4_out", 0755); + assertMakeDir("test4_out2", 0755); + assertMakeDir("test4/d1", 0755); + assertEqualInt(1, touch("test4/d1/foo", 0)); + + /* Does bsdtar support -s option ? */ + systemf("%s -cf - -s /foo/bar/ test4/d1/foo > check.out 2> check.err", + testprog); + assertEqualInt(0, stat("check.err", &st)); + if (st.st_size == 0) { + systemf("%s -cf - -s /foo/bar/ test4/d1/foo | %s -xf - -C test4_out", + testprog, testprog); + assertEmptyFile("test4_out/test4/d1/bar"); + systemf("%s -cf - -s /d1/d2/ test4/d1/foo | %s -xf - -C test4_out", + testprog, testprog); + assertEmptyFile("test4_out/test4/d2/foo"); + systemf("%s -cf - -s ,test4/d1/foo,, test4/d1/foo | %s -tvf - > test4.lst", + testprog, testprog); + assertEmptyFile("test4.lst"); + systemf("%s -cf - test4/d1/foo | %s -xf - -s /foo/bar/ -C test4_out2", + testprog, testprog); + assertEmptyFile("test4_out2/test4/d1/bar"); + } else { + skipping("bsdtar does not support -s option on this platform"); + } + + /* TODO: Include some use of -C directory-changing within the filelist. */ + /* I'm pretty sure -C within the filelist is broken on extract. */ +} diff --git a/external/bsd/libarchive/dist/tar/test/test_option_q.c b/external/bsd/libarchive/dist/tar/test/test_option_q.c new file mode 100644 index 000000000..68867b52a --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_option_q.c @@ -0,0 +1,129 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_q.c,v 1.3 2008/08/22 01:35:08 kientzle Exp $"); + +DEFINE_TEST(test_option_q) +{ + FILE *f; + int r; + + /* + * Create an archive with several different versions of the + * same files. By default, the last version will overwrite + * any earlier versions. The -q/--fast-read option will + * stop early, so we can verify -q/--fast-read by seeing + * which version of each file actually ended up being + * extracted. This also exercises -r mode, since that's + * what we use to build up the test archive. + */ + + f = fopen("foo", "w"); + assert(f != NULL); + fprintf(f, "foo1"); + fclose(f); + + assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog)); + + f = fopen("foo", "w"); + assert(f != NULL); + fprintf(f, "foo2"); + fclose(f); + + assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog)); + + f = fopen("bar", "w"); + assert(f != NULL); + fprintf(f, "bar1"); + fclose(f); + + assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog)); + + f = fopen("foo", "w"); + assert(f != NULL); + fprintf(f, "foo3"); + fclose(f); + + assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog)); + + f = fopen("bar", "w"); + assert(f != NULL); + fprintf(f, "bar2"); + fclose(f); + + assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog)); + + /* + * Now, try extracting from the test archive with various + * combinations of -q. + */ + + /* Test 1: -q foo should only extract the first foo. */ + assertMakeDir("test1", 0755); + assertChdir("test1"); + r = systemf("%s -xf ../archive.tar -q foo >test.out 2>test.err", + testprog); + failure("Fatal error trying to use -q option"); + if (!assertEqualInt(0, r)) + return; + + assertFileContents("foo1", 4, "foo"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 2: -q foo bar should extract up to the first bar. */ + assertMakeDir("test2", 0755); + assertChdir("test2"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -q foo bar >test.out 2>test.err", testprog)); + assertFileContents("foo2", 4, "foo"); + assertFileContents("bar1", 4, "bar"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 3: Same as test 2, but use --fast-read spelling. */ + assertMakeDir("test3", 0755); + assertChdir("test3"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar --fast-read foo bar >test.out 2>test.err", testprog)); + assertFileContents("foo2", 4, "foo"); + assertFileContents("bar1", 4, "bar"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); + + /* Test 4: Without -q, should extract everything. */ + assertMakeDir("test4", 0755); + assertChdir("test4"); + assertEqualInt(0, + systemf("%s -xf ../archive.tar foo bar >test.out 2>test.err", testprog)); + assertFileContents("foo3", 4, "foo"); + assertFileContents("bar2", 4, "bar"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); +} diff --git a/external/bsd/libarchive/dist/tar/test/test_option_r.c b/external/bsd/libarchive/dist/tar/test/test_option_r.c new file mode 100644 index 000000000..516a83079 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_option_r.c @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +/* + * Also see test_option_q for additional validation of -r support. + */ +DEFINE_TEST(test_option_r) +{ + char buff[15]; + char *p0, *p1; + size_t s; + FILE *f; + int r; + + /* Create a file */ + f = fopen("f1", "w"); + if (!assert(f != NULL)) + return; + assertEqualInt(3, fwrite("abc", 1, 3, f)); + fclose(f); + + /* Archive that one file. */ + r = systemf("%s cf archive.tar --format=ustar f1 >step1.out 2>step1.err", testprog); + failure("Error invoking %s cf archive.tar f1", testprog); + assertEqualInt(r, 0); + + /* Verify that nothing went to stdout or stderr. */ + assertEmptyFile("step1.out"); + assertEmptyFile("step1.err"); + + + /* Do some basic validation of the constructed archive. */ + p0 = slurpfile(&s, "archive.tar"); + if (!assert(p0 != NULL)) + return; + if (!assert(s >= 2048)) { + free(p0); + return; + } + assertEqualMem(p0 + 0, "f1", 3); + assertEqualMem(p0 + 512, "abc", 3); + assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8); + assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8); + + /* Edit that file */ + f = fopen("f1", "w"); + if (!assert(f != NULL)) + return; + assertEqualInt(3, fwrite("123", 1, 3, f)); + fclose(f); + + /* Update the archive. */ + r = systemf("%s rf archive.tar --format=ustar f1 >step2.out 2>step2.err", testprog); + failure("Error invoking %s rf archive.tar f1", testprog); + assertEqualInt(r, 0); + + /* Verify that nothing went to stdout or stderr. */ + assertEmptyFile("step2.out"); + assertEmptyFile("step2.err"); + + /* Do some basic validation of the constructed archive. */ + p1 = slurpfile(&s, "archive.tar"); + if (!assert(p1 != NULL)) { + free(p0); + return; + } + assert(s >= 3072); + /* Verify first entry is unchanged. */ + assertEqualMem(p0, p1, 1024); + /* Verify that second entry is correct. */ + assertEqualMem(p1 + 1024, "f1", 3); + assertEqualMem(p1 + 1536, "123", 3); + /* Verify end-of-archive marker. */ + assertEqualMem(p1 + 2048, "\0\0\0\0\0\0\0\0", 8); + assertEqualMem(p1 + 2560, "\0\0\0\0\0\0\0\0", 8); + free(p0); + free(p1); + + /* Unpack both items */ + assertMakeDir("step3", 0775); + assertChdir("step3"); + r = systemf("%s xf ../archive.tar", testprog); + failure("Error invoking %s xf archive.tar", testprog); + assertEqualInt(r, 0); + + /* Verify that the second one overwrote the first. */ + f = fopen("f1", "r"); + if (assert(f != NULL)) { + assertEqualInt(3, fread(buff, 1, 3, f)); + assertEqualMem(buff, "123", 3); + fclose(f); + } +} diff --git a/external/bsd/libarchive/dist/tar/test/test_option_s.c b/external/bsd/libarchive/dist/tar/test/test_option_s.c new file mode 100644 index 000000000..8eb415e1c --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_option_s.c @@ -0,0 +1,107 @@ +/*- + * Copyright (c) 2003-2008 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $"); + +static int +mkfile(const char *fn, const char *contents) +{ + FILE *f = fopen(fn, "w"); + failure("Couldn't create file '%s', errno=%d (%s)\n", + fn, errno, strerror(errno)); + if (!assert(f != NULL)) + return (1); /* Failure. */ + if (contents != NULL) + assertEqualInt(strlen(contents), + fwrite(contents, 1, strlen(contents), f)); + assertEqualInt(0, fclose(f)); + return (0); /* Success */ +} + +DEFINE_TEST(test_option_s) +{ + struct stat st; + + /* Create a sample file heirarchy. */ + assertMakeDir("in", 0755); + assertMakeDir("in/d1", 0755); + assertEqualInt(0, mkfile("in/d1/foo", "foo")); + assertEqualInt(0, mkfile("in/d1/bar", "bar")); + + /* Does bsdtar support -s option ? */ + systemf("%s -cf - -s /foo/bar/ in/d1/foo > NUL 2> check.err", + testprog); + assertEqualInt(0, stat("check.err", &st)); + if (st.st_size != 0) { + skipping("%s does not support -s option on this platform", + testprog); + return; + } + + /* + * Test 1: Filename substitution when creating archives. + */ + assertMakeDir("test1", 0755); + systemf("%s -cf - -s /foo/bar/ in/d1/foo | %s -xf - -C test1", + testprog, testprog); + assertFileContents("foo", 3, "test1/in/d1/bar"); + systemf("%s -cf - -s /d1/d2/ in/d1/foo | %s -xf - -C test1", + testprog, testprog); + assertFileContents("foo", 3, "test1/in/d2/foo"); + + + /* + * Test 2: Basic substitution when extracting archive. + */ + assertMakeDir("test2", 0755); + systemf("%s -cf - in/d1/foo | %s -xf - -s /foo/bar/ -C test2", + testprog, testprog); + assertFileContents("foo", 3, "test2/in/d1/bar"); + + /* + * Test 3: Files with empty names shouldn't be archived. + */ + systemf("%s -cf - -s ,in/d1/foo,, in/d1/foo | %s -tvf - > in.lst", + testprog, testprog); + assertEmptyFile("in.lst"); + + /* + * Test 4: Multiple substitutions when extracting archive. + */ + assertMakeDir("test4", 0755); + systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}baz} -C test4", + testprog, testprog); + assertFileContents("foo", 3, "test4/in/d1/bar"); + assertFileContents("bar", 3, "test4/in/d1/baz"); + + /* + * Test 5: Name-switching substitutions when extracting archive. + */ + assertMakeDir("test5", 0755); + systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}foo} -C test5", + testprog, testprog); + assertFileContents("foo", 3, "test5/in/d1/bar"); + assertFileContents("bar", 3, "test5/in/d1/foo"); +} diff --git a/external/bsd/libarchive/dist/tar/test/test_patterns.c b/external/bsd/libarchive/dist/tar/test/test_patterns.c new file mode 100644 index 000000000..fee98be9b --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_patterns.c @@ -0,0 +1,184 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_patterns.c,v 1.6 2008/08/21 22:28:00 kientzle Exp $"); + +DEFINE_TEST(test_patterns) +{ + FILE *f; + int r; + const char *reffile2 = "test_patterns_2.tar"; + const char *reffile3 = "test_patterns_3.tar"; + const char *reffile4 = "test_patterns_4.tar"; + + const char *tar2aExpected[] = { + "/tmp/foo/bar/", + "/tmp/foo/bar/baz", + NULL + }; + + /* + * Test basic command-line pattern handling. + */ + + /* + * Test 1: Files on the command line that don't get matched + * didn't produce an error. + * + * John Baldwin reported this problem in PR bin/121598 + */ + f = fopen("foo", "w"); + assert(f != NULL); + fclose(f); + r = systemf("%s cfv tar1.tgz foo > tar1a.out 2> tar1a.err", testprog); + assertEqualInt(r, 0); + r = systemf("%s xv --no-same-owner -f tar1.tgz foo bar > tar1b.out 2> tar1b.err", testprog); + failure("tar should return non-zero because a file was given on the command line that's not in the archive"); + assert(r != 0); + + /* + * Test 2: Check basic matching of full paths that start with / + */ + extract_reference_file(reffile2); + + r = systemf("%s tf %s /tmp/foo/bar > tar2a.out 2> tar2a.err", + testprog, reffile2); + assertEqualInt(r, 0); + assertFileContainsLinesAnyOrder("tar2a.out", tar2aExpected); + assertEmptyFile("tar2a.err"); + + /* + * Test 3 archive has some entries starting with '/' and some not. + */ + extract_reference_file(reffile3); + + /* Test 3a: Pattern tmp/foo/bar should not match /tmp/foo/bar */ + r = systemf("%s x --no-same-owner -f %s tmp/foo/bar > tar3a.out 2> tar3a.err", + testprog, reffile3); + assert(r != 0); + assertEmptyFile("tar3a.out"); + + /* Test 3b: Pattern /tmp/foo/baz should not match tmp/foo/baz */ + assertNonEmptyFile("tar3a.err"); + /* Again, with the '/' */ + r = systemf("%s x --no-same-owner -f %s /tmp/foo/baz > tar3b.out 2> tar3b.err", + testprog, reffile3); + assert(r != 0); + assertEmptyFile("tar3b.out"); + assertNonEmptyFile("tar3b.err"); + + /* Test 3c: ./tmp/foo/bar should not match /tmp/foo/bar */ + r = systemf("%s x --no-same-owner -f %s ./tmp/foo/bar > tar3c.out 2> tar3c.err", + testprog, reffile3); + assert(r != 0); + assertEmptyFile("tar3c.out"); + assertNonEmptyFile("tar3c.err"); + + /* Test 3d: ./tmp/foo/baz should match tmp/foo/baz */ + r = systemf("%s x --no-same-owner -f %s ./tmp/foo/baz > tar3d.out 2> tar3d.err", + testprog, reffile3); + assertEqualInt(r, 0); + assertEmptyFile("tar3d.out"); + assertEmptyFile("tar3d.err"); + assertFileExists("tmp/foo/baz/bar"); + + /* + * Test 4 archive has some entries starting with windows drive letters + * such as 'c:\', '//./c:/' or '//?/c:/'. + */ + extract_reference_file(reffile4); + + r = systemf("%s x --no-same-owner -f %s -C tmp > tar4.out 2> tar4.err", + testprog, reffile4); + assert(r != 0); + assertEmptyFile("tar4.out"); + assertNonEmptyFile("tar4.err"); + + for (r = 1; r <= 54; r++) { + char file_a[] = "tmp/fileXX"; + char file_b1[] = "tmp/server/share/fileXX"; + char file_b2[] = "tmp/server\\share\\fileXX"; + char file_c[] = "tmp/../fileXX"; + char *filex; + int xsize; + + switch (r) { + case 15: case 18: + /* + * Including server and share names. + * //?/UNC/server/share/file15 + * //?/unc/server/share/file18 + */ + filex = file_b1; + xsize = sizeof(file_b1); + break; + case 35: case 38: case 52: + /* + * Including server and share names. + * \\?\UNC\server\share\file35 + * \\?\unc\server\share\file38 + * \/?/uNc/server\share\file52 + */ + filex = file_b2; + xsize = sizeof(file_b2); + break; + default: + filex = file_a; + xsize = sizeof(file_a); + break; + } + filex[xsize-3] = '0' + r / 10; + filex[xsize-2] = '0' + r % 10; + switch (r) { + case 5: case 6: case 17: case 20: case 25: + case 26: case 37: case 40: case 43: case 54: + /* + * Not extracted patterns. + * D:../file05 + * c:../../file06 + * //?/UNC/../file17 + * //?/unc/../file20 + * z:..\file25 + * c:..\..\file26 + * \\?\UNC\..\file37 + * \\?\unc\..\file40 + * c:../..\file43 + * \/?\UnC\../file54 + */ + assertFileNotExists(filex); + filex = file_c; + xsize = sizeof(file_c); + filex[xsize-3] = '0' + r / 10; + filex[xsize-2] = '0' + r % 10; + assertFileNotExists(filex); + break; + default: + /* Extracted patterns. */ + assertFileExists(filex); + break; + } + } +} diff --git a/external/bsd/libarchive/dist/tar/test/test_patterns_2.tar.uu b/external/bsd/libarchive/dist/tar/test/test_patterns_2.tar.uu new file mode 100644 index 000000000..eba2daece --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_patterns_2.tar.uu @@ -0,0 +1,231 @@ +begin 644 test_patterns_2.tar +M+W1M<"]F;V\O```````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````#`P,#@`````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````P +M,#`V-#0@`#`P,3@`````````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````````````#`P,#8T-"``,#`Q-S4P(``P,#`P,#`@`#`P,#`P +M,#`P,#`P(#$Q,#4Q,C$R-C4S(#`Q,S8V-P`@,``````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````````````!UCHN+EQF:6QE,C4````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P +M,#`P(#$Q,34P-Ccf.out 2>cf.err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("cf.out"); + assertEmptyFile("cf.err"); + + /* 'cvf' should generate file list on stderr, empty stdout. */ + r = systemf("%s cvf archive f l >cvf.out 2>cvf.err", testprog); + assertEqualInt(r, 0); + failure("'cv' writes filenames to stderr, nothing to stdout (SUSv2)\n" + "Note that GNU tar writes the file list to stdout by default."); + assertEmptyFile("cvf.out"); + /* TODO: Verify cvf.err has file list in SUSv2-prescribed format. */ + + /* 'cvf -' should generate file list on stderr, archive on stdout. */ + r = systemf("%s cvf - f l >cvf-.out 2>cvf-.err", testprog); + assertEqualInt(r, 0); + failure("cvf - should write archive to stdout"); + /* TODO: Verify cvf-.out has archive. */ + failure("cvf - should write file list to stderr (SUSv2)"); + /* TODO: Verify cvf-.err has verbose file list. */ + + /* 'tf' should generate file list on stdout, empty stderr. */ + r = systemf("%s tf archive >tf.out 2>tf.err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("tf.err"); + failure("'t' mode should write results to stdout"); + /* TODO: Verify tf.out has file list. */ + + /* 'tvf' should generate file list on stdout, empty stderr. */ + r = systemf("%s tvf archive >tvf.out 2>tvf.err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("tvf.err"); + failure("'tv' mode should write results to stdout"); + /* TODO: Verify tvf.out has file list. */ + + /* 'tvf -' uses stdin, file list on stdout, empty stderr. */ + r = systemf("%s tvf - < archive >tvf-.out 2>tvf-.err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("tvf-.err"); + /* TODO: Verify tvf-.out has file list. */ + + /* Basic 'xf' should generate no output on stdout or stderr. */ + r = systemf("%s xf archive >xf.out 2>xf.err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("xf.err"); + assertEmptyFile("xf.out"); + + /* 'xvf' should generate list on stderr, empty stdout. */ + r = systemf("%s xvf archive >xvf.out 2>xvf.err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("xvf.out"); + /* TODO: Verify xvf.err */ + + /* 'xvOf' should generate list on stderr, file contents on stdout. */ + r = systemf("%s xvOf archive >xvOf.out 2>xvOf.err", testprog); + assertEqualInt(r, 0); + /* Verify xvOf.out is the file contents */ + p = slurpfile(&s, "xvOf.out"); + assert(s = 3); + assertEqualMem(p, "abc", 3); + /* TODO: Verify xvf.err */ + + /* 'xvf -' should generate list on stderr, empty stdout. */ + r = systemf("%s xvf - < archive >xvf-.out 2>xvf-.err", testprog); + assertEqualInt(r, 0); + assertEmptyFile("xvf-.out"); + /* TODO: Verify xvf-.err */ +} diff --git a/external/bsd/libarchive/dist/tar/test/test_strip_components.c b/external/bsd/libarchive/dist/tar/test/test_strip_components.c new file mode 100644 index 000000000..c9028a4d7 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_strip_components.c @@ -0,0 +1,109 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_strip_components.c,v 1.2 2008/11/10 05:24:13 kientzle Exp $"); + +static int +touch(const char *fn) +{ + FILE *f = fopen(fn, "w"); + failure("Couldn't create file '%s', errno=%d (%s)\n", + fn, errno, strerror(errno)); + if (!assert(f != NULL)) + return (0); /* Failure. */ + fclose(f); + return (1); /* Success */ +} + +DEFINE_TEST(test_strip_components) +{ + assertMakeDir("d0", 0755); + assertChdir("d0"); + assertMakeDir("d1", 0755); + assertMakeDir("d1/d2", 0755); + assertMakeDir("d1/d2/d3", 0755); + assertEqualInt(1, touch("d1/d2/f1")); + assertMakeHardlink("l1", "d1/d2/f1"); + assertMakeHardlink("d1/l2", "d1/d2/f1"); + if (canSymlink()) { + assertMakeSymlink("s1", "d1/d2/f1"); + assertMakeSymlink("d1/s2", "d2/f1"); + } + assertChdir(".."); + + assertEqualInt(0, systemf("%s -cf test.tar d0", testprog)); + + assertMakeDir("target", 0755); + assertEqualInt(0, systemf("%s -x -C target --strip-components 2 " + "-f test.tar", testprog)); + + failure("d0/ is too short and should not get restored"); + assertFileNotExists("target/d0"); + failure("d0/d1/ is too short and should not get restored"); + assertFileNotExists("target/d1"); + failure("d0/d1/s2 is a symlink to something that won't be extracted"); + /* If platform supports symlinks, target/s2 is a broken symlink. */ + /* If platform does not support symlink, target/s2 doesn't exist. */ + assertFileNotExists("target/s2"); + if (canSymlink()) + assertIsSymlink("target/s2", "d2/f1"); + failure("d0/d1/d2 should be extracted"); + assertIsDir("target/d2", -1); + + /* + * This next is a complicated case. d0/l1, d0/d1/l2, and + * d0/d1/d2/f1 are all hardlinks to the same file; d0/l1 can't + * be extracted with --strip-components=2 and the other two + * can. Remember that tar normally stores the first file with + * a body and the other as hardlink entries to the first + * appearance. So the final result depends on the order in + * which these three names get archived. If d0/l1 is first, + * none of the three can be restored. If either of the longer + * names are first, then the two longer ones can both be + * restored. + * + * The tree-walking code used by bsdtar always visits files + * before subdirectories, so bsdtar's behavior is fortunately + * deterministic: d0/l1 will always get stored first and the + * other two will be stored as hardlinks to d0/l1. Since + * d0/l1 can't be extracted, none of these three will be + * extracted. + * + * It may be worth extending this test to force a particular + * archiving order so as to exercise both of the cases described + * above. + * + * Of course, this is all totally different for cpio and newc + * formats because the hardlink management is different. + * TODO: Rename this to test_strip_components_tar and create + * parallel tests for cpio and newc formats. + */ + failure("d0/l1 is too short and should not get restored"); + assertFileNotExists("target/l1"); + failure("d0/d1/l2 is a hardlink to file whose name was too short"); + assertFileNotExists("target/l2"); + failure("d0/d1/d2/f1 is a hardlink to file whose name was too short"); + assertFileNotExists("target/d2/f1"); +} diff --git a/external/bsd/libarchive/dist/tar/test/test_symlink_dir.c b/external/bsd/libarchive/dist/tar/test/test_symlink_dir.c new file mode 100644 index 000000000..aa80ba68e --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_symlink_dir.c @@ -0,0 +1,160 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_symlink_dir.c,v 1.1 2008/09/14 02:16:04 kientzle Exp $"); + +/* + * tar -x -P should follow existing symlinks for dirs, but not other + * content. Plain tar -x should remove symlinks when they're in the + * way of a dir extraction. + */ + +static int +mkfile(const char *name, int mode, const char *contents, size_t size) +{ + FILE *f = fopen(name, "wb"); + size_t written; + + (void)mode; /* UNUSED */ + if (f == NULL) + return (-1); + written = fwrite(contents, 1, size, f); + fclose(f); + if (size != written) + return (-1); + return (0); +} + +DEFINE_TEST(test_symlink_dir) +{ + assertUmask(0); + + assertMakeDir("source", 0755); + assertEqualInt(0, mkfile("source/file", 0755, "a", 1)); + assertEqualInt(0, mkfile("source/file2", 0755, "ab", 2)); + assertMakeDir("source/dir", 0755); + assertMakeDir("source/dir/d", 0755); + assertEqualInt(0, mkfile("source/dir/f", 0755, "abc", 3)); + assertMakeDir("source/dir2", 0755); + assertMakeDir("source/dir2/d2", 0755); + assertEqualInt(0, mkfile("source/dir2/f2", 0755, "abcd", 4)); + assertMakeDir("source/dir3", 0755); + assertMakeDir("source/dir3/d3", 0755); + assertEqualInt(0, mkfile("source/dir3/f3", 0755, "abcde", 5)); + + assertEqualInt(0, + systemf("%s -cf test.tar -C source dir dir2 dir3 file file2", + testprog)); + + /* + * Extract with -x and without -P. + */ + assertMakeDir("dest1", 0755); + /* "dir" is a symlink to an existing "dest1/real_dir" */ + assertMakeDir("dest1/real_dir", 0755); + if (canSymlink()) { + assertMakeSymlink("dest1/dir", "real_dir"); + /* "dir2" is a symlink to a non-existing "real_dir2" */ + assertMakeSymlink("dest1/dir2", "real_dir2"); + } else { + skipping("some symlink checks"); + } + /* "dir3" is a symlink to an existing "non_dir3" */ + assertEqualInt(0, mkfile("dest1/non_dir3", 0755, "abcdef", 6)); + if (canSymlink()) + assertMakeSymlink("dest1/dir3", "non_dir3"); + /* "file" is a symlink to existing "real_file" */ + assertEqualInt(0, mkfile("dest1/real_file", 0755, "abcdefg", 7)); + if (canSymlink()) { + assertMakeSymlink("dest1/file", "real_file"); + /* "file2" is a symlink to non-existing "real_file2" */ + assertMakeSymlink("dest1/file2", "real_file2"); + } + assertEqualInt(0, systemf("%s -xf test.tar -C dest1", testprog)); + + /* dest1/dir symlink should be replaced */ + failure("symlink to dir was followed when it shouldn't be"); + assertIsDir("dest1/dir", -1); + /* dest1/dir2 symlink should be replaced */ + failure("Broken symlink wasn't replaced with dir"); + assertIsDir("dest1/dir2", -1); + /* dest1/dir3 symlink should be replaced */ + failure("Symlink to non-dir wasn't replaced with dir"); + assertIsDir("dest1/dir3", -1); + /* dest1/file symlink should be replaced */ + failure("Symlink to existing file should be replaced"); + assertIsReg("dest1/file", -1); + /* dest1/file2 symlink should be replaced */ + failure("Symlink to non-existing file should be replaced"); + assertIsReg("dest1/file2", -1); + + /* + * Extract with both -x and -P + */ + assertMakeDir("dest2", 0755); + /* "dir" is a symlink to existing "real_dir" */ + assertMakeDir("dest2/real_dir", 0755); + if (canSymlink()) + assertMakeSymlink("dest2/dir", "real_dir"); + /* "dir2" is a symlink to a non-existing "real_dir2" */ + if (canSymlink()) + assertMakeSymlink("dest2/dir2", "real_dir2"); + /* "dir3" is a symlink to an existing "non_dir3" */ + assertEqualInt(0, mkfile("dest2/non_dir3", 0755, "abcdefgh", 8)); + if (canSymlink()) + assertMakeSymlink("dest2/dir3", "non_dir3"); + /* "file" is a symlink to existing "real_file" */ + assertEqualInt(0, mkfile("dest2/real_file", 0755, "abcdefghi", 9)); + if (canSymlink()) + assertMakeSymlink("dest2/file", "real_file"); + /* "file2" is a symlink to non-existing "real_file2" */ + if (canSymlink()) + assertMakeSymlink("dest2/file2", "real_file2"); + assertEqualInt(0, systemf("%s -xPf test.tar -C dest2", testprog)); + + /* dest2/dir symlink should be followed */ + if (canSymlink()) { + assertIsSymlink("dest2/dir", "real_dir"); + assertIsDir("dest2/real_dir", -1); + } + + /* Contents of 'dir' should be restored */ + assertIsDir("dest2/dir/d", -1); + assertIsReg("dest2/dir/f", -1); + assertFileSize("dest2/dir/f", 3); + /* dest2/dir2 symlink should be removed */ + failure("Broken symlink wasn't replaced with dir"); + assertIsDir("dest2/dir2", -1); + /* dest2/dir3 symlink should be removed */ + failure("Symlink to non-dir wasn't replaced with dir"); + assertIsDir("dest2/dir3", -1); + /* dest2/file symlink should be removed; + * even -P shouldn't follow symlinks for files */ + failure("Symlink to existing file should be removed"); + assertIsReg("dest2/file", -1); + /* dest2/file2 symlink should be removed */ + failure("Symlink to non-existing file should be removed"); + assertIsReg("dest2/file2", -1); +} diff --git a/external/bsd/libarchive/dist/tar/test/test_version.c b/external/bsd/libarchive/dist/tar/test/test_version.c new file mode 100644 index 000000000..42472d1bc --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_version.c @@ -0,0 +1,97 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_version.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); + +/* + * Test that --version option works and generates reasonable output. + */ + +DEFINE_TEST(test_version) +{ + int r; + char *p, *q; + size_t s; + + + r = systemf("%s --version >version.stdout 2>version.stderr", testprog); + if (r != 0) + r = systemf("%s -W version >version.stdout 2>version.stderr", + testprog); + failure("Unable to run either %s --version or %s -W version", + testprog, testprog); + if (!assert(r == 0)) + return; + + /* --version should generate nothing to stdout. */ + assertEmptyFile("version.stderr"); + /* Verify format of version message. */ + q = p = slurpfile(&s, "version.stdout"); + /* Version message should start with name of program, then space. */ + assert(s > 6); + failure("Version must start with 'bsdtar': ``%s''", p); + if (!assertEqualMem(q, "bsdtar ", 7)) + return; + q += 7; s -= 7; + /* Version number is a series of digits and periods. */ + while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) { + ++q; + --s; + } + /* Version number terminated by space. */ + failure("No space after bsdtar version: ``%s''", p); + assert(s > 1); + /* Skip a single trailing a,b,c, or d. */ + if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd') + ++q; + failure("No space after bsdtar version: ``%s''", p); + assert(*q == ' '); + ++q; --s; + /* Separator. */ + failure("No `-' between bsdtar and libarchive versions: ``%s''", p); + assertEqualMem(q, "- ", 2); + q += 2; s -= 2; + /* libarchive name and version number */ + failure("Not long enough for libarchive version: ``%s''", p); + assert(s > 11); + failure("Libarchive version must start with `libarchive': ``%s''", p); + assertEqualMem(q, "libarchive ", 11); + q += 11; s -= 11; + /* Version number is a series of digits and periods. */ + while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) { + ++q; + --s; + } + /* Skip a single trailing a,b,c, or d. */ + if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd') + ++q; + /* All terminated by end-of-line. */ + assert(s >= 1); + /* Skip an optional CR character (e.g., Windows) */ + failure("Version output must end with \\n or \\r\\n"); + if (*q == '\r') { ++q; --s; } + assertEqualMem(q, "\n", 1); + free(p); +} diff --git a/external/bsd/libarchive/dist/tar/test/test_windows.c b/external/bsd/libarchive/dist/tar/test/test_windows.c new file mode 100644 index 000000000..a2d0c214b --- /dev/null +++ b/external/bsd/libarchive/dist/tar/test/test_windows.c @@ -0,0 +1,323 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" + +#if defined(_WIN32) && !defined(__CYGWIN__) +#include + +static void +mkfile(const char *name) +{ + FILE *f; + + f = fopen(name, "wb"); + assert(f != NULL); + assertEqualInt(5, fwrite("01234", 1, 5, f)); + fclose(f); +} + +static void +mkfullpath(char **path1, char **path2, const char *tpath, int type) +{ + char *fp1 = NULL, *fp2 = NULL, *p1 = NULL, *p2 = NULL; + size_t l; + + /* + * Get full path name of "tpath" + */ + l = GetFullPathNameA(tpath, 0, NULL, NULL); + assert(0 != l); + fp1 = malloc(l); + assert(NULL != fp1); + fp2 = malloc(l*2); + assert(NULL != fp2); + l = GetFullPathNameA(tpath, l, fp1, NULL); + if ((type & 0x01) == 0) { + for (p1 = fp1; *p1 != '\0'; p1++) + if (*p1 == '\\') + *p1 = '/'; + } + + switch(type) { + case 0: /* start with "/" */ + case 1: /* start with "\" */ + /* strip "c:" */ + memmove(fp1, fp1 + 2, l - 2); + fp1[l -2] = '\0'; + p1 = fp1 + 1; + break; + case 2: /* start with "c:/" */ + case 3: /* start with "c:\" */ + p1 = fp1 + 3; + break; + case 4: /* start with "//./c:/" */ + case 5: /* start with "\\.\c:\" */ + case 6: /* start with "//?/c:/" */ + case 7: /* start with "\\?\c:\" */ + p1 = malloc(l + 4 + 1); + assert(NULL != p1); + if (type & 0x1) + memcpy(p1, "\\\\.\\", 4); + else + memcpy(p1, "//./", 4); + if (type == 6 || type == 7) + p1[2] = '?'; + memcpy(p1 + 4, fp1, l); + p1[l + 4] = '\0'; + free(fp1); + fp1 = p1; + p1 = fp1 + 7; + break; + } + + /* + * Strip leading drive names and converting "\" to "\\" + */ + p2 = fp2; + while (*p1 != '\0') { + if (*p1 == '\\') + *p2 = '/'; + else + *p2 = *p1; + ++p1; + ++p2; + } + *p2++ = '\r'; + *p2++ = '\n'; + *p2 = '\0'; + + *path1 = fp1; + *path2 = fp2; +} + +static const char *list1[] = {"aaa/", "aaa/file1", "aaa/xxa/", "aaa/xxb/", + "aaa/zzc/", "aaa/zzc/file1", "aaa/xxb/file1", "aaa/xxa/file1", + "aab/", "aac/", "abb/", "abc/", "abd/", NULL}; +static const char *list2[] = {"bbb/", "bbb/file1", "bbb/xxa/", "bbb/xxb/", + "bbb/zzc/", "bbb/zzc/file1", "bbb/xxb/file1", "bbb/xxa/file1", "bbc/", + "bbd/", "bcc/", "bcd/", "bce/", NULL}; +static const char *list3[] = {"aac/", "abc/", "bbc/", "bcc/", "ccc/", NULL}; +static const char *list4[] = {"fff/abca", "fff/acca", NULL}; +static const char *list5[] = {"aaa/file1", "aaa/xxa/", "aaa/xxa/file1", + "aaa/xxb/", "aaa/xxb/file1", "aaa/zzc/", "aaa/zzc/file1", NULL}; +static const char *list6[] = {"fff/abca", "fff/acca", "aaa/xxa/", + "aaa/xxa/file1", "aaa/xxb/", "aaa/xxb/file1", NULL}; +#endif /* _WIN32 && !__CYGWIN__ */ + +DEFINE_TEST(test_windows) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + char *fp1, *fp2; + + /* + * Preparre tests. + * Create directories and files. + */ + assertMakeDir("tmp", 0775); + assertChdir("tmp"); + + assertMakeDir("aaa", 0775); + assertMakeDir("aaa/xxa", 0775); + assertMakeDir("aaa/xxb", 0775); + assertMakeDir("aaa/zzc", 0775); + mkfile("aaa/file1"); + mkfile("aaa/xxa/file1"); + mkfile("aaa/xxb/file1"); + mkfile("aaa/zzc/file1"); + assertMakeDir("aab", 0775); + assertMakeDir("aac", 0775); + assertMakeDir("abb", 0775); + assertMakeDir("abc", 0775); + assertMakeDir("abd", 0775); + assertMakeDir("bbb", 0775); + assertMakeDir("bbb/xxa", 0775); + assertMakeDir("bbb/xxb", 0775); + assertMakeDir("bbb/zzc", 0775); + mkfile("bbb/file1"); + mkfile("bbb/xxa/file1"); + mkfile("bbb/xxb/file1"); + mkfile("bbb/zzc/file1"); + assertMakeDir("bbc", 0775); + assertMakeDir("bbd", 0775); + assertMakeDir("bcc", 0775); + assertMakeDir("bcd", 0775); + assertEqualInt(0, _mkdir("bce")); + assertEqualInt(0, _mkdir("ccc")); + assertEqualInt(0, _mkdir("fff")); + mkfile("fff/aaaa"); + mkfile("fff/abba"); + mkfile("fff/abca"); + mkfile("fff/acba"); + mkfile("fff/acca"); + + /* + * Test1: Command line pattern matching. + */ + assertEqualInt(0, + systemf("%s -cf ../archive1.tar a*", testprog)); + assertEqualInt(0, + systemf("%s -tf ../archive1.tar > ../list1", testprog)); + assertFileContainsLinesAnyOrder("../list1", list1); + + assertEqualInt(0, + systemf("%s -cf ../archive2.tar b*", testprog)); + assertEqualInt(0, + systemf("%s -tf ../archive2.tar > ../list2", testprog)); + assertFileContainsLinesAnyOrder("../list2", list2); + + assertEqualInt(0, + systemf("%s -cf ../archive3.tar ??c", testprog)); + assertEqualInt(0, + systemf("%s -tf ../archive3.tar > ../list3", testprog)); + assertFileContainsLinesAnyOrder("../list3", list3); + + assertEqualInt(0, + systemf("%s -cf ../archive3b.tar *c", testprog)); + assertEqualInt(0, + systemf("%s -tf ../archive3b.tar > ../list3b", testprog)); + assertFileContainsLinesAnyOrder("../list3b", list3); + + assertEqualInt(0, + systemf("%s -cf ../archive4.tar fff/a?ca", testprog)); + assertEqualInt(0, + systemf("%s -tf ../archive4.tar > ../list4", testprog)); + assertFileContainsLinesAnyOrder("../list4", list4); + + assertEqualInt(0, + systemf("%s -cf ../archive5.tar aaa\\*", testprog)); + assertEqualInt(0, + systemf("%s -tf ../archive5.tar > ../list5", testprog)); + assertFileContainsLinesAnyOrder("../list5", list5); + + assertEqualInt(0, + systemf("%s -cf ../archive6.tar fff\\a?ca aaa\\xx*", testprog)); + assertEqualInt(0, + systemf("%s -tf ../archive6.tar > ../list6", testprog)); + assertFileContainsLinesAnyOrder("../list6", list6); + + /* + * Test2: Archive the file start with drive letters. + */ + /* Test2a: start with "/" */ + mkfullpath(&fp1, &fp2, "aaa/file1", 0); + assertEqualInt(0, + systemf("%s -cf ../archive10.tar %s > ../out10 2> ../err10", + testprog, fp1)); + assertEqualInt(0, + systemf("%s -tf ../archive10.tar > ../list10", testprog)); + /* Check drive letters have been stripped. */ + assertFileContents(fp2, strlen(fp2), "../list10"); + free(fp1); + free(fp2); + + /* Test2b: start with "\" */ + mkfullpath(&fp1, &fp2, "aaa/file1", 1); + assertEqualInt(0, + systemf("%s -cf ../archive11.tar %s > ../out11 2> ../err11", + testprog, fp1)); + assertEqualInt(0, + systemf("%s -tf ../archive11.tar > ../list11", testprog)); + /* Check drive letters have been stripped. */ + assertFileContents(fp2, strlen(fp2), "../list11"); + free(fp1); + free(fp2); + + /* Test2c: start with "c:/" */ + mkfullpath(&fp1, &fp2, "aaa/file1", 2); + assertEqualInt(0, + systemf("%s -cf ../archive12.tar %s > ../out12 2> ../err12", + testprog, fp1)); + assertEqualInt(0, + systemf("%s -tf ../archive12.tar > ../list12", testprog)); + /* Check drive letters have been stripped. */ + assertFileContents(fp2, strlen(fp2), "../list12"); + free(fp1); + free(fp2); + + /* Test2d: start with "c:\" */ + mkfullpath(&fp1, &fp2, "aaa/file1", 3); + assertEqualInt(0, + systemf("%s -cf ../archive13.tar %s > ../out13 2> ../err13", + testprog, fp1)); + assertEqualInt(0, + systemf("%s -tf ../archive13.tar > ../list13", testprog)); + /* Check drive letters have been stripped. */ + assertFileContents(fp2, strlen(fp2), "../list13"); + free(fp1); + free(fp2); + + /* Test2e: start with "//./c:/" */ + mkfullpath(&fp1, &fp2, "aaa/file1", 4); + assertEqualInt(0, + systemf("%s -cf ../archive14.tar %s > ../out14 2> ../err14", + testprog, fp1)); + assertEqualInt(0, + systemf("%s -tf ../archive14.tar > ../list14", testprog)); + /* Check drive letters have been stripped. */ + assertFileContents(fp2, strlen(fp2), "../list14"); + free(fp1); + free(fp2); + + /* Test2f: start with "\\.\c:\" */ + mkfullpath(&fp1, &fp2, "aaa/file1", 5); + assertEqualInt(0, + systemf("%s -cf ../archive15.tar %s > ../out15 2> ../err15", + testprog, fp1)); + assertEqualInt(0, + systemf("%s -tf ../archive15.tar > ../list15", testprog)); + /* Check drive letters have been stripped. */ + assertFileContents(fp2, strlen(fp2), "../list15"); + free(fp1); + free(fp2); + + /* Test2g: start with "//?/c:/" */ + mkfullpath(&fp1, &fp2, "aaa/file1", 6); + failure("fp1=%s, fp2=%s", fp1, fp2); + assertEqualInt(0, + systemf("%s -cf ../archive16.tar %s > ../out16 2> ../err16", + testprog, fp1)); + assertEqualInt(0, + systemf("%s -tf ../archive16.tar > ../list16", testprog)); + /* Check drive letters have been stripped. */ + assertFileContents(fp2, strlen(fp2), "../list16"); + free(fp1); + free(fp2); + + /* Test2h: start with "\\?\c:\" */ + mkfullpath(&fp1, &fp2, "aaa/file1", 7); + failure("fp1=%s, fp2=%s", fp1, fp2); + assertEqualInt(0, + systemf("%s -cf ../archive17.tar %s > ../out17 2> ../err17", + testprog, fp1)); + assertEqualInt(0, + systemf("%s -tf ../archive17.tar > ../list17", testprog)); + /* Check drive letters have been stripped. */ + assertFileContents(fp2, strlen(fp2), "../list17"); + free(fp1); + free(fp2); +#else + skipping("Windows specific test"); +#endif /* _WIN32 && !__CYGWIN__ */ +} diff --git a/external/bsd/libarchive/dist/tar/tree.c b/external/bsd/libarchive/dist/tar/tree.c new file mode 100644 index 000000000..6504ebf7d --- /dev/null +++ b/external/bsd/libarchive/dist/tar/tree.c @@ -0,0 +1,821 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * This is a new directory-walking system that addresses a number + * of problems I've had with fts(3). In particular, it has no + * pathname-length limits (other than the size of 'int'), handles + * deep logical traversals, uses considerably less memory, and has + * an opaque interface (easier to modify in the future). + * + * Internally, it keeps a single list of "tree_entry" items that + * represent filesystem objects that require further attention. + * Non-directories are not kept in memory: they are pulled from + * readdir(), returned to the client, then freed as soon as possible. + * Any directory entry to be traversed gets pushed onto the stack. + * + * There is surprisingly little information that needs to be kept for + * each item on the stack. Just the name, depth (represented here as the + * string length of the parent directory's pathname), and some markers + * indicating how to get back to the parent (via chdir("..") for a + * regular dir or via fchdir(2) for a symlink). + */ +#include "bsdtar_platform.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/tree.c,v 1.9 2008/11/27 05:49:52 kientzle Exp $"); + +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_DIRECT_H +#include +#endif +#ifdef HAVE_DIRENT_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) +#include +#endif + +#include "tree.h" + +/* + * TODO: + * 1) Loop checking. + * 3) Arbitrary logical traversals by closing/reopening intermediate fds. + */ + +struct tree_entry { + int depth; + struct tree_entry *next; + struct tree_entry *parent; + char *name; + size_t dirname_length; + dev_t dev; + ino_t ino; + int flags; + /* How to return back to the parent of a symlink. */ +#ifdef HAVE_FCHDIR + int symlink_parent_fd; +#elif defined(_WIN32) && !defined(__CYGWIN__) + char *symlink_parent_path; +#else +#error fchdir function required. +#endif +}; + +/* Definitions for tree_entry.flags bitmap. */ +#define isDir 1 /* This entry is a regular directory. */ +#define isDirLink 2 /* This entry is a symbolic link to a directory. */ +#define needsFirstVisit 4 /* This is an initial entry. */ +#define needsDescent 8 /* This entry needs to be previsited. */ +#define needsOpen 16 /* This is a directory that needs to be opened. */ +#define needsAscent 32 /* This entry needs to be postvisited. */ + +/* + * On Windows, "first visit" is handled as a pattern to be handed to + * _findfirst(). This is consistent with Windows conventions that + * file patterns are handled within the application. On Posix, + * "first visit" is just returned to the client. + */ + +/* + * Local data for this package. + */ +struct tree { + struct tree_entry *stack; + struct tree_entry *current; +#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) + HANDLE d; + BY_HANDLE_FILE_INFORMATION fileInfo; +#define INVALID_DIR_HANDLE INVALID_HANDLE_VALUE + WIN32_FIND_DATA _findData; + WIN32_FIND_DATA *findData; +#else + DIR *d; +#define INVALID_DIR_HANDLE NULL + struct dirent *de; +#endif + int flags; + int visit_type; + int tree_errno; /* Error code from last failed operation. */ + + /* Dynamically-sized buffer for holding path */ + char *buff; + size_t buff_length; + + const char *basename; /* Last path element */ + size_t dirname_length; /* Leading dir length */ + size_t path_length; /* Total path length */ + + int depth; + int openCount; + int maxOpenCount; + + struct stat lst; + struct stat st; +}; + +/* Definitions for tree.flags bitmap. */ +#define hasStat 16 /* The st entry is valid. */ +#define hasLstat 32 /* The lst entry is valid. */ +#define hasFileInfo 64 /* The Windows fileInfo entry is valid. */ + +#if defined(_WIN32) && !defined(__CYGWIN__) +static int +tree_dir_next_windows(struct tree *t, const char *pattern); +#else +static int +tree_dir_next_posix(struct tree *t); +#endif + +#ifdef HAVE_DIRENT_D_NAMLEN +/* BSD extension; avoids need for a strlen() call. */ +#define D_NAMELEN(dp) (dp)->d_namlen +#else +#define D_NAMELEN(dp) (strlen((dp)->d_name)) +#endif + +#include +void +tree_dump(struct tree *t, FILE *out) +{ + char buff[300]; + struct tree_entry *te; + + fprintf(out, "\tdepth: %d\n", t->depth); + fprintf(out, "\tbuff: %s\n", t->buff); + fprintf(out, "\tpwd: %s\n", getcwd(buff, sizeof(buff))); + fprintf(out, "\tbasename: %s\n", t->basename); + fprintf(out, "\tstack:\n"); + for (te = t->stack; te != NULL; te = te->next) { + fprintf(out, "\t\t%s%d:\"%s\" %s%s%s%s%s%s\n", + t->current == te ? "*" : " ", + te->depth, + te->name, + te->flags & needsFirstVisit ? "V" : "", + te->flags & needsDescent ? "D" : "", + te->flags & needsOpen ? "O" : "", + te->flags & needsAscent ? "A" : "", + te->flags & isDirLink ? "L" : "", + (t->current == te && t->d) ? "+" : "" + ); + } +} + +/* + * Add a directory path to the current stack. + */ +static void +tree_push(struct tree *t, const char *path) +{ + struct tree_entry *te; + + te = malloc(sizeof(*te)); + memset(te, 0, sizeof(*te)); + te->next = t->stack; + te->parent = t->current; + if (te->parent) + te->depth = te->parent->depth + 1; + t->stack = te; +#ifdef HAVE_FCHDIR + te->symlink_parent_fd = -1; + te->name = strdup(path); +#elif defined(_WIN32) && !defined(__CYGWIN__) + te->symlink_parent_path = NULL; + te->name = strdup(path); +#endif + te->flags = needsDescent | needsOpen | needsAscent; + te->dirname_length = t->dirname_length; +} + +/* + * Append a name to the current dir path. + */ +static void +tree_append(struct tree *t, const char *name, size_t name_length) +{ + char *p; + size_t size_needed; + + if (t->buff != NULL) + t->buff[t->dirname_length] = '\0'; + /* Strip trailing '/' from name, unless entire name is "/". */ + while (name_length > 1 && name[name_length - 1] == '/') + name_length--; + + /* Resize pathname buffer as needed. */ + size_needed = name_length + 1 + t->dirname_length; + if (t->buff_length < size_needed) { + if (t->buff_length < 1024) + t->buff_length = 1024; + while (t->buff_length < size_needed) + t->buff_length *= 2; + t->buff = realloc(t->buff, t->buff_length); + } + if (t->buff == NULL) + abort(); + p = t->buff + t->dirname_length; + t->path_length = t->dirname_length + name_length; + /* Add a separating '/' if it's needed. */ + if (t->dirname_length > 0 && p[-1] != '/') { + *p++ = '/'; + t->path_length ++; + } +#if HAVE_STRNCPY_S + strncpy_s(p, t->buff_length - (p - t->buff), name, name_length); +#else + strncpy(p, name, name_length); +#endif + p[name_length] = '\0'; + t->basename = p; +} + +/* + * Open a directory tree for traversal. + */ +struct tree * +tree_open(const char *path) +{ +#ifdef HAVE_FCHDIR + struct tree *t; + + t = malloc(sizeof(*t)); + memset(t, 0, sizeof(*t)); + /* First item is set up a lot like a symlink traversal. */ + tree_push(t, path); + t->stack->flags = needsFirstVisit | isDirLink | needsAscent; + t->stack->symlink_parent_fd = open(".", O_RDONLY); + t->openCount++; + t->d = INVALID_DIR_HANDLE; + return (t); +#elif defined(_WIN32) && !defined(__CYGWIN__) + struct tree *t; + char *cwd = _getcwd(NULL, 0); + char *pathname = strdup(path), *p, *base; + + if (pathname == NULL) + abort(); + for (p = pathname; *p != '\0'; ++p) { + if (*p == '\\') + *p = '/'; + } + base = pathname; + + t = malloc(sizeof(*t)); + memset(t, 0, sizeof(*t)); + /* First item is set up a lot like a symlink traversal. */ + /* printf("Looking for wildcard in %s\n", path); */ + /* TODO: wildcard detection here screws up on \\?\c:\ UNC names */ + if (strchr(base, '*') || strchr(base, '?')) { + // It has a wildcard in it... + // Separate the last element. + p = strrchr(base, '/'); + if (p != NULL) { + *p = '\0'; + chdir(base); + tree_append(t, base, p - base); + t->dirname_length = t->path_length; + base = p + 1; + } + } + tree_push(t, base); + free(pathname); + t->stack->flags = needsFirstVisit | isDirLink | needsAscent; + t->stack->symlink_parent_path = cwd; + t->d = INVALID_DIR_HANDLE; + return (t); +#endif +} + +/* + * We've finished a directory; ascend back to the parent. + */ +static int +tree_ascend(struct tree *t) +{ + struct tree_entry *te; + int r = 0; + + te = t->stack; + t->depth--; + if (te->flags & isDirLink) { +#ifdef HAVE_FCHDIR + if (fchdir(te->symlink_parent_fd) != 0) { + t->tree_errno = errno; + r = TREE_ERROR_FATAL; + } + close(te->symlink_parent_fd); +#elif defined(_WIN32) && !defined(__CYGWIN__) + if (SetCurrentDirectory(te->symlink_parent_path) == 0) { + t->tree_errno = errno; + r = TREE_ERROR_FATAL; + } + free(te->symlink_parent_path); + te->symlink_parent_path = NULL; +#endif + t->openCount--; + } else { +#if defined(_WIN32) && !defined(__CYGWIN__) + if (SetCurrentDirectory("..") == 0) { +#else + if (chdir("..") != 0) { +#endif + t->tree_errno = errno; + r = TREE_ERROR_FATAL; + } + } + return (r); +} + +/* + * Pop the working stack. + */ +static void +tree_pop(struct tree *t) +{ + struct tree_entry *te; + + if (t->buff) + t->buff[t->dirname_length] = '\0'; + if (t->stack == t->current && t->current != NULL) + t->current = t->current->parent; + te = t->stack; + t->stack = te->next; + t->dirname_length = te->dirname_length; + if (t->buff) { + t->basename = t->buff + t->dirname_length; + while (t->basename[0] == '/') + t->basename++; + } + free(te->name); + free(te); +} + +/* + * Get the next item in the tree traversal. + */ +int +tree_next(struct tree *t) +{ + int r; + + /* If we're called again after a fatal error, that's an API + * violation. Just crash now. */ + if (t->visit_type == TREE_ERROR_FATAL) { + fprintf(stderr, "Unable to continue traversing" + " directory heirarchy after a fatal error."); + abort(); + } + + while (t->stack != NULL) { + /* If there's an open dir, get the next entry from there. */ + if (t->d != INVALID_DIR_HANDLE) { +#if defined(_WIN32) && !defined(__CYGWIN__) + r = tree_dir_next_windows(t, NULL); +#else + r = tree_dir_next_posix(t); +#endif + if (r == 0) + continue; + return (r); + } + + if (t->stack->flags & needsFirstVisit) { +#if defined(_WIN32) && !defined(__CYGWIN__) + char *d = t->stack->name; + t->stack->flags &= ~needsFirstVisit; + if (strchr(d, '*') || strchr(d, '?')) { + r = tree_dir_next_windows(t, d); + if (r == 0) + continue; + return (r); + } + // Not a pattern, handle it as-is... +#endif + /* Top stack item needs a regular visit. */ + t->current = t->stack; + tree_append(t, t->stack->name, strlen(t->stack->name)); + //t->dirname_length = t->path_length; + //tree_pop(t); + t->stack->flags &= ~needsFirstVisit; + return (t->visit_type = TREE_REGULAR); + } else if (t->stack->flags & needsDescent) { + /* Top stack item is dir to descend into. */ + t->current = t->stack; + tree_append(t, t->stack->name, strlen(t->stack->name)); + t->stack->flags &= ~needsDescent; + /* If it is a link, set up fd for the ascent. */ + if (t->stack->flags & isDirLink) { +#ifdef HAVE_FCHDIR + t->stack->symlink_parent_fd = open(".", O_RDONLY); + t->openCount++; + if (t->openCount > t->maxOpenCount) + t->maxOpenCount = t->openCount; +#elif defined(_WIN32) && !defined(__CYGWIN__) + t->stack->symlink_parent_path = _getcwd(NULL, 0); +#endif + } + t->dirname_length = t->path_length; +#if defined(_WIN32) && !defined(__CYGWIN__) + if (t->path_length == 259 || !SetCurrentDirectory(t->stack->name) != 0) +#else + if (chdir(t->stack->name) != 0) +#endif + { + /* chdir() failed; return error */ + tree_pop(t); + t->tree_errno = errno; + return (t->visit_type = TREE_ERROR_DIR); + } + t->depth++; + return (t->visit_type = TREE_POSTDESCENT); + } else if (t->stack->flags & needsOpen) { + t->stack->flags &= ~needsOpen; +#if defined(_WIN32) && !defined(__CYGWIN__) + r = tree_dir_next_windows(t, "*"); +#else + r = tree_dir_next_posix(t); +#endif + if (r == 0) + continue; + return (r); + } else if (t->stack->flags & needsAscent) { + /* Top stack item is dir and we're done with it. */ + r = tree_ascend(t); + tree_pop(t); + t->visit_type = r != 0 ? r : TREE_POSTASCENT; + return (t->visit_type); + } else { + /* Top item on stack is dead. */ + tree_pop(t); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + } + } + return (t->visit_type = 0); +} + +#if defined(_WIN32) && !defined(__CYGWIN__) +static int +tree_dir_next_windows(struct tree *t, const char *pattern) +{ + const char *name; + size_t namelen; + int r; + + for (;;) { + if (pattern != NULL) { + t->d = FindFirstFile(pattern, &t->_findData); + if (t->d == INVALID_DIR_HANDLE) { + r = tree_ascend(t); /* Undo "chdir" */ + tree_pop(t); + t->tree_errno = errno; + t->visit_type = r != 0 ? r : TREE_ERROR_DIR; + return (t->visit_type); + } + t->findData = &t->_findData; + pattern = NULL; + } else if (!FindNextFile(t->d, &t->_findData)) { + FindClose(t->d); + t->d = INVALID_DIR_HANDLE; + t->findData = NULL; + return (0); + } + name = t->findData->cFileName; + namelen = strlen(name); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + if (name[0] == '.' && name[1] == '\0') + continue; + if (name[0] == '.' && name[1] == '.' && name[2] == '\0') + continue; + tree_append(t, name, namelen); + return (t->visit_type = TREE_REGULAR); + } +} +#else +static int +tree_dir_next_posix(struct tree *t) +{ + int r; + const char *name; + size_t namelen; + + if (t->d == NULL) { + if ((t->d = opendir(".")) == NULL) { + r = tree_ascend(t); /* Undo "chdir" */ + tree_pop(t); + t->tree_errno = errno; + t->visit_type = r != 0 ? r : TREE_ERROR_DIR; + return (t->visit_type); + } + } + for (;;) { + t->de = readdir(t->d); + if (t->de == NULL) { + closedir(t->d); + t->d = INVALID_DIR_HANDLE; + return (0); + } + name = t->de->d_name; + namelen = D_NAMELEN(t->de); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + if (name[0] == '.' && name[1] == '\0') + continue; + if (name[0] == '.' && name[1] == '.' && name[2] == '\0') + continue; + tree_append(t, name, namelen); + return (t->visit_type = TREE_REGULAR); + } +} +#endif + +/* + * Return error code. + */ +int +tree_errno(struct tree *t) +{ + return (t->tree_errno); +} + +/* + * Called by the client to mark the directory just returned from + * tree_next() as needing to be visited. + */ +void +tree_descend(struct tree *t) +{ + if (t->visit_type != TREE_REGULAR) + return; + + if (tree_current_is_physical_dir(t)) { + tree_push(t, t->basename); + t->stack->flags |= isDir; + } else if (tree_current_is_dir(t)) { + tree_push(t, t->basename); + t->stack->flags |= isDirLink; + } +} + +/* + * Get the stat() data for the entry just returned from tree_next(). + */ +const struct stat * +tree_current_stat(struct tree *t) +{ + if (!(t->flags & hasStat)) { + if (stat(tree_current_access_path(t), &t->st) != 0) + return NULL; + t->flags |= hasStat; + } + return (&t->st); +} + +#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) +const BY_HANDLE_FILE_INFORMATION * +tree_current_file_information(struct tree *t) +{ + if (!(t->flags & hasFileInfo)) { + HANDLE h = CreateFile(tree_current_access_path(t), + 0, 0, NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, + NULL); + if (h == INVALID_HANDLE_VALUE) + return NULL; + if (!GetFileInformationByHandle(h, &t->fileInfo)) { + CloseHandle(h); + return NULL; + } + CloseHandle(h); + t->flags |= hasFileInfo; + } + return (&t->fileInfo); +} +#endif +/* + * Get the lstat() data for the entry just returned from tree_next(). + */ +const struct stat * +tree_current_lstat(struct tree *t) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + return (tree_current_stat(t)); +#else + if (!(t->flags & hasLstat)) { + if (lstat(tree_current_access_path(t), &t->lst) != 0) + return NULL; + t->flags |= hasLstat; + } + return (&t->lst); +#endif +} + +/* + * Test whether current entry is a dir or link to a dir. + */ +int +tree_current_is_dir(struct tree *t) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + if (t->findData) + return (t->findData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + if (tree_current_file_information(t)) + return (t->fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + return (0); +#else + const struct stat *st; + /* + * If we already have lstat() info, then try some + * cheap tests to determine if this is a dir. + */ + if (t->flags & hasLstat) { + /* If lstat() says it's a dir, it must be a dir. */ + if (S_ISDIR(tree_current_lstat(t)->st_mode)) + return 1; + /* Not a dir; might be a link to a dir. */ + /* If it's not a link, then it's not a link to a dir. */ + if (!S_ISLNK(tree_current_lstat(t)->st_mode)) + return 0; + /* + * It's a link, but we don't know what it's a link to, + * so we'll have to use stat(). + */ + } + + st = tree_current_stat(t); + /* If we can't stat it, it's not a dir. */ + if (st == NULL) + return 0; + /* Use the definitive test. Hopefully this is cached. */ + return (S_ISDIR(st->st_mode)); +#endif +} + +/* + * Test whether current entry is a physical directory. Usually, we + * already have at least one of stat() or lstat() in memory, so we + * use tricks to try to avoid an extra trip to the disk. + */ +int +tree_current_is_physical_dir(struct tree *t) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + if (tree_current_is_physical_link(t)) + return (0); + return (tree_current_is_dir(t)); +#else + const struct stat *st; + + /* + * If stat() says it isn't a dir, then it's not a dir. + * If stat() data is cached, this check is free, so do it first. + */ + if ((t->flags & hasStat) + && (!S_ISDIR(tree_current_stat(t)->st_mode))) + return 0; + + /* + * Either stat() said it was a dir (in which case, we have + * to determine whether it's really a link to a dir) or + * stat() info wasn't available. So we use lstat(), which + * hopefully is already cached. + */ + + st = tree_current_lstat(t); + /* If we can't stat it, it's not a dir. */ + if (st == NULL) + return 0; + /* Use the definitive test. Hopefully this is cached. */ + return (S_ISDIR(st->st_mode)); +#endif +} + +/* + * Test whether current entry is a symbolic link. + */ +int +tree_current_is_physical_link(struct tree *t) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) +#ifndef IO_REPARSE_TAG_SYMLINK +/* Old SDKs do not provide IO_REPARSE_TAG_SYMLINK */ +#define IO_REPARSE_TAG_SYMLINK 0xA000000CL +#endif + if (t->findData) + return ((t->findData->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) + && (t->findData->dwReserved0 == IO_REPARSE_TAG_SYMLINK)); + return (0); +#else + const struct stat *st = tree_current_lstat(t); + if (st == NULL) + return 0; + return (S_ISLNK(st->st_mode)); +#endif +} + +/* + * Return the access path for the entry just returned from tree_next(). + */ +const char * +tree_current_access_path(struct tree *t) +{ + return (t->basename); +} + +/* + * Return the full path for the entry just returned from tree_next(). + */ +const char * +tree_current_path(struct tree *t) +{ + return (t->buff); +} + +/* + * Return the length of the path for the entry just returned from tree_next(). + */ +size_t +tree_current_pathlen(struct tree *t) +{ + return (t->path_length); +} + +/* + * Return the nesting depth of the entry just returned from tree_next(). + */ +int +tree_current_depth(struct tree *t) +{ + return (t->depth); +} + +/* + * Terminate the traversal and release any resources. + */ +void +tree_close(struct tree *t) +{ + /* Release anything remaining in the stack. */ + while (t->stack != NULL) + tree_pop(t); + free(t->buff); + /* TODO: Ensure that premature close() resets cwd */ +#if 0 +#ifdef HAVE_FCHDIR + if (t->initialDirFd >= 0) { + int s = fchdir(t->initialDirFd); + (void)s; /* UNUSED */ + close(t->initialDirFd); + t->initialDirFd = -1; + } +#elif defined(_WIN32) && !defined(__CYGWIN__) + if (t->initialDir != NULL) { + SetCurrentDir(t->initialDir); + free(t->initialDir); + t->initialDir = NULL; + } +#endif +#endif + free(t); +} diff --git a/external/bsd/libarchive/dist/tar/tree.h b/external/bsd/libarchive/dist/tar/tree.h new file mode 100644 index 000000000..9a7e0d307 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/tree.h @@ -0,0 +1,141 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/usr.bin/tar/tree.h,v 1.4 2008/11/27 05:49:52 kientzle Exp $ + */ + +/*- + * A set of routines for traversing directory trees. + * Similar in concept to the fts library, but with a few + * important differences: + * * Uses less memory. In particular, fts stores an entire directory + * in memory at a time. This package only keeps enough subdirectory + * information in memory to track the traversal. Information + * about non-directories is discarded as soon as possible. + * * Supports very deep logical traversals. The fts package + * uses "non-chdir" approach for logical traversals. This + * package does use a chdir approach for logical traversals + * and can therefore handle pathnames much longer than PATH_MAX. + * * Supports deep physical traversals "out of the box." + * Due to the memory optimizations above, there's no need to + * limit dir names to 32k. + */ + +#include +#include + +struct tree; + +/* Initiate/terminate a tree traversal. */ +struct tree *tree_open(const char * /* pathname */); +void tree_close(struct tree *); + +/* + * tree_next() returns Zero if there is no next entry, non-zero if + * there is. Note that directories are visited three times. + * Directories are always visited first as part of enumerating their + * parent; that is a "regular" visit. If tree_descend() is invoked at + * that time, the directory is added to a work list and will + * subsequently be visited two more times: once just after descending + * into the directory ("postdescent") and again just after ascending + * back to the parent ("postascent"). + * + * TREE_ERROR_DIR is returned if the descent failed (because the + * directory couldn't be opened, for instance). This is returned + * instead of TREE_POSTDESCENT/TREE_POSTASCENT. TREE_ERROR_DIR is not a + * fatal error, but it does imply that the relevant subtree won't be + * visited. TREE_ERROR_FATAL is returned for an error that left the + * traversal completely hosed. Right now, this is only returned for + * chdir() failures during ascent. + */ +#define TREE_REGULAR 1 +#define TREE_POSTDESCENT 2 +#define TREE_POSTASCENT 3 +#define TREE_ERROR_DIR -1 +#define TREE_ERROR_FATAL -2 + +int tree_next(struct tree *); + +/* Errno value associated with the last traversal error. */ +int tree_errno(struct tree *); + +/* + * Request that current entry be visited. If you invoke it on every + * directory, you'll get a physical traversal. This is ignored if the + * current entry isn't a directory or a link to a directory. So, if + * you invoke this on every returned path, you'll get a full logical + * traversal. + */ +void tree_descend(struct tree *); + +/* + * Return information about the current entry. + */ + +/* Current depth in the traversal. */ +int tree_current_depth(struct tree *); + +/* + * The current full pathname, length of the full pathname, and a name + * that can be used to access the file. Because tree does use chdir + * extensively, the access path is almost never the same as the full + * current path. + * + * TODO: Flesh out this interface to provide other information. In + * particular, Windows can provide file size, mode, and some permission + * information without invoking stat() at all. + * + * TODO: On platforms that support it, use openat()-style operations + * to eliminate the chdir() operations entirely while still supporting + * arbitrarily deep traversals. This makes access_path troublesome to + * support, of course, which means we'll need a rich enough interface + * that clients can function without it. (In particular, we'll need + * tree_current_open() that returns an open file descriptor.) + * + * TODO: Provide tree_current_archive_entry(). + */ +const char *tree_current_path(struct tree *); +size_t tree_current_pathlen(struct tree *); +const char *tree_current_access_path(struct tree *); + +/* + * Request the lstat() or stat() data for the current path. Since the + * tree package needs to do some of this anyway, and caches the + * results, you should take advantage of it here if you need it rather + * than make a redundant stat() or lstat() call of your own. + */ +const struct stat *tree_current_stat(struct tree *); +const struct stat *tree_current_lstat(struct tree *); + +/* The following functions use tricks to avoid a certain number of + * stat()/lstat() calls. */ +/* "is_physical_dir" is equivalent to S_ISDIR(tree_current_lstat()->st_mode) */ +int tree_current_is_physical_dir(struct tree *); +/* "is_physical_link" is equivalent to S_ISLNK(tree_current_lstat()->st_mode) */ +int tree_current_is_physical_link(struct tree *); +/* "is_dir" is equivalent to S_ISDIR(tree_current_stat()->st_mode) */ +int tree_current_is_dir(struct tree *); + +/* For testing/debugging: Dump the internal status to the given filehandle. */ +void tree_dump(struct tree *, FILE *); diff --git a/external/bsd/libarchive/dist/tar/util.c b/external/bsd/libarchive/dist/tar/util.c new file mode 100644 index 000000000..f7232744e --- /dev/null +++ b/external/bsd/libarchive/dist/tar/util.c @@ -0,0 +1,559 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "bsdtar_platform.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/util.c,v 1.23 2008/12/15 06:00:25 kientzle Exp $"); + +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include /* Linux doesn't define mode_t, etc. in sys/stat.h. */ +#endif +#include +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_IO_H +#include +#endif +#ifdef HAVE_STDARG_H +#include +#endif +#ifdef HAVE_STDINT_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_WCTYPE_H +#include +#else +/* If we don't have wctype, we need to hack up some version of iswprint(). */ +#define iswprint isprint +#endif + +#include "bsdtar.h" +#include "err.h" + +static size_t bsdtar_expand_char(char *, size_t, char); +static const char *strip_components(const char *path, int elements); + +#if defined(_WIN32) && !defined(__CYGWIN__) +#define read _read +#endif + +/* TODO: Hack up a version of mbtowc for platforms with no wide + * character support at all. I think the following might suffice, + * but it needs careful testing. + * #if !HAVE_MBTOWC + * #define mbtowc(wcp, p, n) ((*wcp = *p), 1) + * #endif + */ + +/* + * Print a string, taking care with any non-printable characters. + * + * Note that we use a stack-allocated buffer to receive the formatted + * string if we can. This is partly performance (avoiding a call to + * malloc()), partly out of expedience (we have to call vsnprintf() + * before malloc() anyway to find out how big a buffer we need; we may + * as well point that first call at a small local buffer in case it + * works), but mostly for safety (so we can use this to print messages + * about out-of-memory conditions). + */ + +void +safe_fprintf(FILE *f, const char *fmt, ...) +{ + char fmtbuff_stack[256]; /* Place to format the printf() string. */ + char outbuff[256]; /* Buffer for outgoing characters. */ + char *fmtbuff_heap; /* If fmtbuff_stack is too small, we use malloc */ + char *fmtbuff; /* Pointer to fmtbuff_stack or fmtbuff_heap. */ + int fmtbuff_length; + int length, n; + va_list ap; + const char *p; + unsigned i; + wchar_t wc; + char try_wc; + + /* Use a stack-allocated buffer if we can, for speed and safety. */ + fmtbuff_heap = NULL; + fmtbuff_length = sizeof(fmtbuff_stack); + fmtbuff = fmtbuff_stack; + + /* Try formatting into the stack buffer. */ + va_start(ap, fmt); + length = vsnprintf(fmtbuff, fmtbuff_length, fmt, ap); + va_end(ap); + + /* If the result was too large, allocate a buffer on the heap. */ + if (length >= fmtbuff_length) { + fmtbuff_length = length+1; + fmtbuff_heap = malloc(fmtbuff_length); + + /* Reformat the result into the heap buffer if we can. */ + if (fmtbuff_heap != NULL) { + fmtbuff = fmtbuff_heap; + va_start(ap, fmt); + length = vsnprintf(fmtbuff, fmtbuff_length, fmt, ap); + va_end(ap); + } else { + /* Leave fmtbuff pointing to the truncated + * string in fmtbuff_stack. */ + length = sizeof(fmtbuff_stack) - 1; + } + } + + /* Note: mbrtowc() has a cleaner API, but mbtowc() seems a bit + * more portable, so we use that here instead. */ + n = mbtowc(NULL, NULL, 1); /* Reset the shift state. */ + + /* Write data, expanding unprintable characters. */ + p = fmtbuff; + i = 0; + try_wc = 1; + while (*p != '\0') { + + /* Convert to wide char, test if the wide + * char is printable in the current locale. */ + if (try_wc && (n = mbtowc(&wc, p, length)) != -1) { + length -= n; + if (iswprint(wc) && wc != L'\\') { + /* Printable, copy the bytes through. */ + while (n-- > 0) + outbuff[i++] = *p++; + } else { + /* Not printable, format the bytes. */ + while (n-- > 0) + i += (unsigned)bsdtar_expand_char( + outbuff, i, *p++); + } + } else { + /* After any conversion failure, don't bother + * trying to convert the rest. */ + i += (unsigned)bsdtar_expand_char(outbuff, i, *p++); + try_wc = 0; + } + + /* If our output buffer is full, dump it and keep going. */ + if (i > (sizeof(outbuff) - 20)) { + outbuff[i] = '\0'; + fprintf(f, "%s", outbuff); + i = 0; + } + } + outbuff[i] = '\0'; + fprintf(f, "%s", outbuff); + + /* If we allocated a heap-based formatting buffer, free it now. */ + if (fmtbuff_heap != NULL) + free(fmtbuff_heap); +} + +/* + * Render an arbitrary sequence of bytes into printable ASCII characters. + */ +static size_t +bsdtar_expand_char(char *buff, size_t offset, char c) +{ + size_t i = offset; + + if (isprint((unsigned char)c) && c != '\\') + buff[i++] = c; + else { + buff[i++] = '\\'; + switch (c) { + case '\a': buff[i++] = 'a'; break; + case '\b': buff[i++] = 'b'; break; + case '\f': buff[i++] = 'f'; break; + case '\n': buff[i++] = 'n'; break; +#if '\r' != '\n' + /* On some platforms, \n and \r are the same. */ + case '\r': buff[i++] = 'r'; break; +#endif + case '\t': buff[i++] = 't'; break; + case '\v': buff[i++] = 'v'; break; + case '\\': buff[i++] = '\\'; break; + default: + sprintf(buff + i, "%03o", 0xFF & (int)c); + i += 3; + } + } + + return (i - offset); +} + +int +yes(const char *fmt, ...) +{ + char buff[32]; + char *p; + ssize_t l; + + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, " (y/N)? "); + fflush(stderr); + + l = read(2, buff, sizeof(buff) - 1); + if (l <= 0) + return (0); + buff[l] = 0; + + for (p = buff; *p != '\0'; p++) { + if (isspace((unsigned char)*p)) + continue; + switch(*p) { + case 'y': case 'Y': + return (1); + case 'n': case 'N': + return (0); + default: + return (0); + } + } + + return (0); +} + +/*- + * The logic here for -C attempts to avoid + * chdir() as long as possible. For example: + * "-C /foo -C /bar file" needs chdir("/bar") but not chdir("/foo") + * "-C /foo -C bar file" needs chdir("/foo/bar") + * "-C /foo -C bar /file1" does not need chdir() + * "-C /foo -C bar /file1 file2" needs chdir("/foo/bar") before file2 + * + * The only correct way to handle this is to record a "pending" chdir + * request and combine multiple requests intelligently until we + * need to process a non-absolute file. set_chdir() adds the new dir + * to the pending list; do_chdir() actually executes any pending chdir. + * + * This way, programs that build tar command lines don't have to worry + * about -C with non-existent directories; such requests will only + * fail if the directory must be accessed. + * + * TODO: Make this handle Windows paths correctly. + */ +void +set_chdir(struct bsdtar *bsdtar, const char *newdir) +{ + if (newdir[0] == '/') { + /* The -C /foo -C /bar case; dump first one. */ + free(bsdtar->pending_chdir); + bsdtar->pending_chdir = NULL; + } + if (bsdtar->pending_chdir == NULL) + /* Easy case: no previously-saved dir. */ + bsdtar->pending_chdir = strdup(newdir); + else { + /* The -C /foo -C bar case; concatenate */ + char *old_pending = bsdtar->pending_chdir; + size_t old_len = strlen(old_pending); + bsdtar->pending_chdir = malloc(old_len + strlen(newdir) + 2); + if (old_pending[old_len - 1] == '/') + old_pending[old_len - 1] = '\0'; + if (bsdtar->pending_chdir != NULL) + sprintf(bsdtar->pending_chdir, "%s/%s", + old_pending, newdir); + free(old_pending); + } + if (bsdtar->pending_chdir == NULL) + lafe_errc(1, errno, "No memory"); +} + +void +do_chdir(struct bsdtar *bsdtar) +{ + if (bsdtar->pending_chdir == NULL) + return; + + if (chdir(bsdtar->pending_chdir) != 0) { + lafe_errc(1, 0, "could not chdir to '%s'\n", + bsdtar->pending_chdir); + } + free(bsdtar->pending_chdir); + bsdtar->pending_chdir = NULL; +} + +static const char * +strip_components(const char *p, int elements) +{ + /* Skip as many elements as necessary. */ + while (elements > 0) { + switch (*p++) { + case '/': +#if defined(_WIN32) && !defined(__CYGWIN__) + case '\\': /* Support \ path sep on Windows ONLY. */ +#endif + elements--; + break; + case '\0': + /* Path is too short, skip it. */ + return (NULL); + } + } + + /* Skip any / characters. This handles short paths that have + * additional / termination. This also handles the case where + * the logic above stops in the middle of a duplicate // + * sequence (which would otherwise get converted to an + * absolute path). */ + for (;;) { + switch (*p) { + case '/': +#if defined(_WIN32) && !defined(__CYGWIN__) + case '\\': /* Support \ path sep on Windows ONLY. */ +#endif + ++p; + break; + case '\0': + return (NULL); + default: + return (p); + } + } +} + +/* + * Handle --strip-components and any future path-rewriting options. + * Returns non-zero if the pathname should not be extracted. + * + * TODO: Support pax-style regex path rewrites. + */ +int +edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry) +{ + const char *name = archive_entry_pathname(entry); +#if HAVE_REGEX_H + char *subst_name; + int r; +#endif + +#if HAVE_REGEX_H + r = apply_substitution(bsdtar, name, &subst_name, 0); + if (r == -1) { + lafe_warnc(0, "Invalid substitution, skipping entry"); + return 1; + } + if (r == 1) { + archive_entry_copy_pathname(entry, subst_name); + if (*subst_name == '\0') { + free(subst_name); + return -1; + } else + free(subst_name); + name = archive_entry_pathname(entry); + } + + if (archive_entry_hardlink(entry)) { + r = apply_substitution(bsdtar, archive_entry_hardlink(entry), &subst_name, 1); + if (r == -1) { + lafe_warnc(0, "Invalid substitution, skipping entry"); + return 1; + } + if (r == 1) { + archive_entry_copy_hardlink(entry, subst_name); + free(subst_name); + } + } + if (archive_entry_symlink(entry) != NULL) { + r = apply_substitution(bsdtar, archive_entry_symlink(entry), &subst_name, 1); + if (r == -1) { + lafe_warnc(0, "Invalid substitution, skipping entry"); + return 1; + } + if (r == 1) { + archive_entry_copy_symlink(entry, subst_name); + free(subst_name); + } + } +#endif + + /* Strip leading dir names as per --strip-components option. */ + if (bsdtar->strip_components > 0) { + const char *linkname = archive_entry_hardlink(entry); + + name = strip_components(name, bsdtar->strip_components); + if (name == NULL) + return (1); + + if (linkname != NULL) { + linkname = strip_components(linkname, + bsdtar->strip_components); + if (linkname == NULL) + return (1); + archive_entry_copy_hardlink(entry, linkname); + } + } + + /* By default, don't write or restore absolute pathnames. */ + if (!bsdtar->option_absolute_paths) { + const char *rp, *p = name; + int slashonly = 1; + + /* Remove leading "//./" or "//?/" or "//?/UNC/" + * (absolute path prefixes used by Windows API) */ + if ((p[0] == '/' || p[0] == '\\') && + (p[1] == '/' || p[1] == '\\') && + (p[2] == '.' || p[2] == '?') && + (p[3] == '/' || p[3] == '\\')) + { + if (p[2] == '?' && + (p[4] == 'U' || p[4] == 'u') && + (p[5] == 'N' || p[5] == 'n') && + (p[6] == 'C' || p[6] == 'c') && + (p[7] == '/' || p[7] == '\\')) + p += 8; + else + p += 4; + slashonly = 0; + } + do { + rp = p; + /* Remove leading drive letter from archives created + * on Windows. */ + if (((p[0] >= 'a' && p[0] <= 'z') || + (p[0] >= 'A' && p[0] <= 'Z')) && + p[1] == ':') { + p += 2; + slashonly = 0; + } + /* Remove leading "/../", "//", etc. */ + while (p[0] == '/' || p[0] == '\\') { + if (p[1] == '.' && p[2] == '.' && + (p[3] == '/' || p[3] == '\\')) { + p += 3; /* Remove "/..", leave "/" + * for next pass. */ + slashonly = 0; + } else + p += 1; /* Remove "/". */ + } + } while (rp != p); + + if (p != name && !bsdtar->warned_lead_slash) { + /* Generate a warning the first time this happens. */ + if (slashonly) + lafe_warnc(0, + "Removing leading '%c' from member names", + name[0]); + else + lafe_warnc(0, + "Removing leading drive letter from " + "member names"); + bsdtar->warned_lead_slash = 1; + } + + /* Special case: Stripping everything yields ".". */ + if (*p == '\0') + name = "."; + else + name = p; + } else { + /* Strip redundant leading '/' characters. */ + while (name[0] == '/' && name[1] == '/') + name++; + } + + /* Safely replace name in archive_entry. */ + if (name != archive_entry_pathname(entry)) { + char *q = strdup(name); + archive_entry_copy_pathname(entry, q); + free(q); + } + return (0); +} + +/* + * It would be nice to just use printf() for formatting large numbers, + * but the compatibility problems are quite a headache. Hence the + * following simple utility function. + */ +const char * +tar_i64toa(int64_t n0) +{ + static char buff[24]; + int64_t n = n0 < 0 ? -n0 : n0; + char *p = buff + sizeof(buff); + + *--p = '\0'; + do { + *--p = '0' + (int)(n % 10); + n /= 10; + } while (n > 0); + if (n0 < 0) + *--p = '-'; + return p; +} + +/* + * Like strcmp(), but try to be a little more aware of the fact that + * we're comparing two paths. Right now, it just handles leading + * "./" and trailing '/' specially, so that "a/b/" == "./a/b" + * + * TODO: Make this better, so that "./a//b/./c/" == "a/b/c" + * TODO: After this works, push it down into libarchive. + * TODO: Publish the path normalization routines in libarchive so + * that bsdtar can normalize paths and use fast strcmp() instead + * of this. + * + * Note: This is currently only used within write.c, so should + * not handle \ path separators. + */ + +int +pathcmp(const char *a, const char *b) +{ + /* Skip leading './' */ + if (a[0] == '.' && a[1] == '/' && a[2] != '\0') + a += 2; + if (b[0] == '.' && b[1] == '/' && b[2] != '\0') + b += 2; + /* Find the first difference, or return (0) if none. */ + while (*a == *b) { + if (*a == '\0') + return (0); + a++; + b++; + } + /* + * If one ends in '/' and the other one doesn't, + * they're the same. + */ + if (a[0] == '/' && a[1] == '\0' && b[0] == '\0') + return (0); + if (a[0] == '\0' && b[0] == '/' && b[1] == '\0') + return (0); + /* They're really different, return the correct sign. */ + return (*(const unsigned char *)a - *(const unsigned char *)b); +} diff --git a/external/bsd/libarchive/dist/tar/write.c b/external/bsd/libarchive/dist/tar/write.c new file mode 100644 index 000000000..163611490 --- /dev/null +++ b/external/bsd/libarchive/dist/tar/write.c @@ -0,0 +1,1138 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "bsdtar_platform.h" +__FBSDID("$FreeBSD: src/usr.bin/tar/write.c,v 1.79 2008/11/27 05:49:52 kientzle Exp $"); + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_IOCTL_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_ATTR_XATTR_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_GRP_H +#include +#endif +#ifdef HAVE_IO_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_LINUX_FS_H +#include /* for Linux file flags */ +#endif +/* + * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. + * As the include guards don't agree, the order of include is important. + */ +#ifdef HAVE_LINUX_EXT2_FS_H +#include /* for Linux file flags */ +#endif +#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) +/* This header exists but is broken on Cygwin. */ +#include +#endif +#ifdef HAVE_PWD_H +#include +#endif +#ifdef HAVE_STDINT_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif + +#include "bsdtar.h" +#include "err.h" +#include "line_reader.h" +#include "tree.h" + +/* Size of buffer for holding file data prior to writing. */ +#define FILEDATABUFLEN 65536 + +/* Fixed size of uname/gname caches. */ +#define name_cache_size 101 + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +static const char * const NO_NAME = "(noname)"; + +struct archive_dir_entry { + struct archive_dir_entry *next; + time_t mtime_sec; + int mtime_nsec; + char *name; +}; + +struct archive_dir { + struct archive_dir_entry *head, *tail; +}; + +struct name_cache { + int probes; + int hits; + size_t size; + struct { + id_t id; + const char *name; + } cache[name_cache_size]; +}; + +static void add_dir_list(struct bsdtar *bsdtar, const char *path, + time_t mtime_sec, int mtime_nsec); +static int append_archive(struct bsdtar *, struct archive *, + struct archive *ina); +static int append_archive_filename(struct bsdtar *, + struct archive *, const char *fname); +static void archive_names_from_file(struct bsdtar *bsdtar, + struct archive *a); +static int copy_file_data(struct bsdtar *, struct archive *a, + struct archive *ina, struct archive_entry *); +static int new_enough(struct bsdtar *, const char *path, + const struct stat *); +static void report_write(struct bsdtar *, struct archive *, + struct archive_entry *, int64_t progress); +static void test_for_append(struct bsdtar *); +static void write_archive(struct archive *, struct bsdtar *); +static void write_entry_backend(struct bsdtar *, struct archive *, + struct archive_entry *); +static int write_file_data(struct bsdtar *, struct archive *, + struct archive_entry *, int fd); +static void write_hierarchy(struct bsdtar *, struct archive *, + const char *); + +#if defined(_WIN32) && !defined(__CYGWIN__) +/* Not a full lseek() emulation, but enough for our needs here. */ +static int +seek_file(int fd, int64_t offset, int whence) +{ + LARGE_INTEGER distance; + (void)whence; /* UNUSED */ + distance.QuadPart = offset; + return (SetFilePointerEx((HANDLE)_get_osfhandle(fd), + distance, NULL, FILE_BEGIN) ? 1 : -1); +} +#define open _open +#define close _close +#define read _read +#define lseek seek_file +#endif + +void +tar_mode_c(struct bsdtar *bsdtar) +{ + struct archive *a; + int r; + + if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL) + lafe_errc(1, 0, "no files or directories specified"); + + a = archive_write_new(); + + /* Support any format that the library supports. */ + if (bsdtar->create_format == NULL) { + r = archive_write_set_format_pax_restricted(a); + bsdtar->create_format = "pax restricted"; + } else { + r = archive_write_set_format_by_name(a, bsdtar->create_format); + } + if (r != ARCHIVE_OK) { + fprintf(stderr, "Can't use format %s: %s\n", + bsdtar->create_format, + archive_error_string(a)); + usage(); + } + + /* + * If user explicitly set the block size, then assume they + * want the last block padded as well. Otherwise, use the + * default block size and accept archive_write_open_file()'s + * default padding decisions. + */ + if (bsdtar->bytes_per_block != 0) { + archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block); + archive_write_set_bytes_in_last_block(a, + bsdtar->bytes_per_block); + } else + archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK); + + if (bsdtar->compress_program) { + archive_write_set_compression_program(a, bsdtar->compress_program); + } else { + switch (bsdtar->create_compression) { + case 0: + r = archive_write_set_compression_none(a); + break; + case 'j': case 'y': + r = archive_write_set_compression_bzip2(a); + break; + case 'J': + r = archive_write_set_compression_xz(a); + break; + case OPTION_LZMA: + r = archive_write_set_compression_lzma(a); + break; + case 'z': + r = archive_write_set_compression_gzip(a); + break; + case 'Z': + r = archive_write_set_compression_compress(a); + break; + default: + lafe_errc(1, 0, + "Unrecognized compression option -%c", + bsdtar->create_compression); + } + if (r != ARCHIVE_OK) { + lafe_errc(1, 0, + "Unsupported compression option -%c", + bsdtar->create_compression); + } + } + + if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) + lafe_errc(1, 0, "%s", archive_error_string(a)); + if (ARCHIVE_OK != archive_write_open_file(a, bsdtar->filename)) + lafe_errc(1, 0, "%s", archive_error_string(a)); + write_archive(a, bsdtar); +} + +/* + * Same as 'c', except we only support tar or empty formats in + * uncompressed files on disk. + */ +void +tar_mode_r(struct bsdtar *bsdtar) +{ + int64_t end_offset; + int format; + struct archive *a; + struct archive_entry *entry; + int r; + + /* Sanity-test some arguments and the file. */ + test_for_append(bsdtar); + + format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; + +#if defined(__BORLANDC__) + bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT | O_BINARY); +#else + bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT | O_BINARY, 0666); +#endif + if (bsdtar->fd < 0) + lafe_errc(1, errno, + "Cannot open %s", bsdtar->filename); + + a = archive_read_new(); + archive_read_support_compression_all(a); + archive_read_support_format_tar(a); + archive_read_support_format_gnutar(a); + r = archive_read_open_fd(a, bsdtar->fd, 10240); + if (r != ARCHIVE_OK) + lafe_errc(1, archive_errno(a), + "Can't read archive %s: %s", bsdtar->filename, + archive_error_string(a)); + while (0 == archive_read_next_header(a, &entry)) { + if (archive_compression(a) != ARCHIVE_COMPRESSION_NONE) { + archive_read_finish(a); + close(bsdtar->fd); + lafe_errc(1, 0, + "Cannot append to compressed archive."); + } + /* Keep going until we hit end-of-archive */ + format = archive_format(a); + } + + end_offset = archive_read_header_position(a); + archive_read_finish(a); + + /* Re-open archive for writing */ + a = archive_write_new(); + archive_write_set_compression_none(a); + /* + * Set the format to be used for writing. To allow people to + * extend empty files, we need to allow them to specify the format, + * which opens the possibility that they will specify a format that + * doesn't match the existing format. Hence, the following bit + * of arcane ugliness. + */ + + if (bsdtar->create_format != NULL) { + /* If the user requested a format, use that, but ... */ + archive_write_set_format_by_name(a, + bsdtar->create_format); + /* ... complain if it's not compatible. */ + format &= ARCHIVE_FORMAT_BASE_MASK; + if (format != (int)(archive_format(a) & ARCHIVE_FORMAT_BASE_MASK) + && format != ARCHIVE_FORMAT_EMPTY) { + lafe_errc(1, 0, + "Format %s is incompatible with the archive %s.", + bsdtar->create_format, bsdtar->filename); + } + } else { + /* + * Just preserve the current format, with a little care + * for formats that libarchive can't write. + */ + if (format == ARCHIVE_FORMAT_TAR_GNUTAR) + /* TODO: When gtar supports pax, use pax restricted. */ + format = ARCHIVE_FORMAT_TAR_USTAR; + if (format == ARCHIVE_FORMAT_EMPTY) + format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; + archive_write_set_format(a, format); + } + if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0) + lafe_errc(1, errno, "Could not seek to archive end"); + if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) + lafe_errc(1, 0, "%s", archive_error_string(a)); + if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd)) + lafe_errc(1, 0, "%s", archive_error_string(a)); + + write_archive(a, bsdtar); /* XXX check return val XXX */ + + close(bsdtar->fd); + bsdtar->fd = -1; +} + +void +tar_mode_u(struct bsdtar *bsdtar) +{ + int64_t end_offset; + struct archive *a; + struct archive_entry *entry; + int format; + struct archive_dir_entry *p; + struct archive_dir archive_dir; + + bsdtar->archive_dir = &archive_dir; + memset(&archive_dir, 0, sizeof(archive_dir)); + + format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; + + /* Sanity-test some arguments and the file. */ + test_for_append(bsdtar); + + bsdtar->fd = open(bsdtar->filename, O_RDWR | O_BINARY); + if (bsdtar->fd < 0) + lafe_errc(1, errno, + "Cannot open %s", bsdtar->filename); + + a = archive_read_new(); + archive_read_support_compression_all(a); + archive_read_support_format_tar(a); + archive_read_support_format_gnutar(a); + if (archive_read_open_fd(a, bsdtar->fd, + bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block : + DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { + lafe_errc(1, 0, + "Can't open %s: %s", bsdtar->filename, + archive_error_string(a)); + } + + /* Build a list of all entries and their recorded mod times. */ + while (0 == archive_read_next_header(a, &entry)) { + if (archive_compression(a) != ARCHIVE_COMPRESSION_NONE) { + archive_read_finish(a); + close(bsdtar->fd); + lafe_errc(1, 0, + "Cannot append to compressed archive."); + } + add_dir_list(bsdtar, archive_entry_pathname(entry), + archive_entry_mtime(entry), + archive_entry_mtime_nsec(entry)); + /* Record the last format determination we see */ + format = archive_format(a); + /* Keep going until we hit end-of-archive */ + } + + end_offset = archive_read_header_position(a); + archive_read_finish(a); + + /* Re-open archive for writing. */ + a = archive_write_new(); + archive_write_set_compression_none(a); + /* + * Set format to same one auto-detected above, except that + * we don't write GNU tar format, so use ustar instead. + */ + if (format == ARCHIVE_FORMAT_TAR_GNUTAR) + format = ARCHIVE_FORMAT_TAR_USTAR; + archive_write_set_format(a, format); + if (bsdtar->bytes_per_block != 0) { + archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block); + archive_write_set_bytes_in_last_block(a, + bsdtar->bytes_per_block); + } else + archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK); + if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0) + lafe_errc(1, errno, "Could not seek to archive end"); + if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) + lafe_errc(1, 0, "%s", archive_error_string(a)); + if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd)) + lafe_errc(1, 0, "%s", archive_error_string(a)); + + write_archive(a, bsdtar); + + close(bsdtar->fd); + bsdtar->fd = -1; + + while (bsdtar->archive_dir->head != NULL) { + p = bsdtar->archive_dir->head->next; + free(bsdtar->archive_dir->head->name); + free(bsdtar->archive_dir->head); + bsdtar->archive_dir->head = p; + } + bsdtar->archive_dir->tail = NULL; +} + + +/* + * Write user-specified files/dirs to opened archive. + */ +static void +write_archive(struct archive *a, struct bsdtar *bsdtar) +{ + const char *arg; + struct archive_entry *entry, *sparse_entry; + + /* Allocate a buffer for file data. */ + if ((bsdtar->buff = malloc(FILEDATABUFLEN)) == NULL) + lafe_errc(1, 0, "cannot allocate memory"); + + if ((bsdtar->resolver = archive_entry_linkresolver_new()) == NULL) + lafe_errc(1, 0, "cannot create link resolver"); + archive_entry_linkresolver_set_strategy(bsdtar->resolver, + archive_format(a)); + if ((bsdtar->diskreader = archive_read_disk_new()) == NULL) + lafe_errc(1, 0, "Cannot create read_disk object"); + archive_read_disk_set_standard_lookup(bsdtar->diskreader); + + if (bsdtar->names_from_file != NULL) + archive_names_from_file(bsdtar, a); + + while (*bsdtar->argv) { + arg = *bsdtar->argv; + if (arg[0] == '-' && arg[1] == 'C') { + arg += 2; + if (*arg == '\0') { + bsdtar->argv++; + arg = *bsdtar->argv; + if (arg == NULL) { + lafe_warnc(0, "%s", + "Missing argument for -C"); + bsdtar->return_value = 1; + goto cleanup; + } + } + set_chdir(bsdtar, arg); + } else { + if (*arg != '/' && (arg[0] != '@' || arg[1] != '/')) + do_chdir(bsdtar); /* Handle a deferred -C */ + if (*arg == '@') { + if (append_archive_filename(bsdtar, a, + arg + 1) != 0) + break; + } else + write_hierarchy(bsdtar, a, arg); + } + bsdtar->argv++; + } + + entry = NULL; + archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry); + while (entry != NULL) { + write_entry_backend(bsdtar, a, entry); + archive_entry_free(entry); + entry = NULL; + archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry); + } + + if (archive_write_close(a)) { + lafe_warnc(0, "%s", archive_error_string(a)); + bsdtar->return_value = 1; + } + +cleanup: + /* Free file data buffer. */ + free(bsdtar->buff); + archive_entry_linkresolver_free(bsdtar->resolver); + bsdtar->resolver = NULL; + archive_read_finish(bsdtar->diskreader); + bsdtar->diskreader = NULL; + + if (bsdtar->option_totals) { + fprintf(stderr, "Total bytes written: %s\n", + tar_i64toa(archive_position_compressed(a))); + } + + archive_write_finish(a); +} + +/* + * Archive names specified in file. + * + * Unless --null was specified, a line containing exactly "-C" will + * cause the next line to be a directory to pass to chdir(). If + * --null is specified, then a line "-C" is just another filename. + */ +static void +archive_names_from_file(struct bsdtar *bsdtar, struct archive *a) +{ + struct lafe_line_reader *lr; + const char *line; + + bsdtar->next_line_is_dir = 0; + + lr = lafe_line_reader(bsdtar->names_from_file, bsdtar->option_null); + while ((line = lafe_line_reader_next(lr)) != NULL) { + if (bsdtar->next_line_is_dir) { + set_chdir(bsdtar, line); + bsdtar->next_line_is_dir = 0; + } else if (!bsdtar->option_null && strcmp(line, "-C") == 0) + bsdtar->next_line_is_dir = 1; + else { + if (*line != '/') + do_chdir(bsdtar); /* Handle a deferred -C */ + write_hierarchy(bsdtar, a, line); + } + } + lafe_line_reader_free(lr); + if (bsdtar->next_line_is_dir) + lafe_errc(1, errno, + "Unexpected end of filename list; " + "directory expected after -C"); +} + +/* + * Copy from specified archive to current archive. Returns non-zero + * for write errors (which force us to terminate the entire archiving + * operation). If there are errors reading the input archive, we set + * bsdtar->return_value but return zero, so the overall archiving + * operation will complete and return non-zero. + */ +static int +append_archive_filename(struct bsdtar *bsdtar, struct archive *a, + const char *filename) +{ + struct archive *ina; + int rc; + + if (strcmp(filename, "-") == 0) + filename = NULL; /* Library uses NULL for stdio. */ + + ina = archive_read_new(); + archive_read_support_format_all(ina); + archive_read_support_compression_all(ina); + if (archive_read_open_file(ina, filename, 10240)) { + lafe_warnc(0, "%s", archive_error_string(ina)); + bsdtar->return_value = 1; + return (0); + } + + rc = append_archive(bsdtar, a, ina); + + if (rc != ARCHIVE_OK) { + lafe_warnc(0, "Error reading archive %s: %s", + filename, archive_error_string(ina)); + bsdtar->return_value = 1; + } + archive_read_finish(ina); + + return (rc); +} + +static int +append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina) +{ + struct archive_entry *in_entry; + int e; + + while (0 == archive_read_next_header(ina, &in_entry)) { + if (!new_enough(bsdtar, archive_entry_pathname(in_entry), + archive_entry_stat(in_entry))) + continue; + if (lafe_excluded(bsdtar->matching, archive_entry_pathname(in_entry))) + continue; + if (bsdtar->option_interactive && + !yes("copy '%s'", archive_entry_pathname(in_entry))) + continue; + if (bsdtar->verbose) + safe_fprintf(stderr, "a %s", + archive_entry_pathname(in_entry)); + if (need_report()) + report_write(bsdtar, a, in_entry, 0); + + e = archive_write_header(a, in_entry); + if (e != ARCHIVE_OK) { + if (!bsdtar->verbose) + lafe_warnc(0, "%s: %s", + archive_entry_pathname(in_entry), + archive_error_string(a)); + else + fprintf(stderr, ": %s", archive_error_string(a)); + } + if (e == ARCHIVE_FATAL) + exit(1); + + if (e >= ARCHIVE_WARN) { + if (archive_entry_size(in_entry) == 0) + archive_read_data_skip(ina); + else if (copy_file_data(bsdtar, a, ina, in_entry)) + exit(1); + } + + if (bsdtar->verbose) + fprintf(stderr, "\n"); + } + + /* Note: If we got here, we saw no write errors, so return success. */ + return (0); +} + +/* Helper function to copy data between archives. */ +static int +copy_file_data(struct bsdtar *bsdtar, struct archive *a, + struct archive *ina, struct archive_entry *entry) +{ + ssize_t bytes_read; + ssize_t bytes_written; + int64_t progress = 0; + + bytes_read = archive_read_data(ina, bsdtar->buff, FILEDATABUFLEN); + while (bytes_read > 0) { + if (need_report()) + report_write(bsdtar, a, entry, progress); + + bytes_written = archive_write_data(a, bsdtar->buff, + bytes_read); + if (bytes_written < bytes_read) { + lafe_warnc(0, "%s", archive_error_string(a)); + return (-1); + } + progress += bytes_written; + bytes_read = archive_read_data(ina, bsdtar->buff, + FILEDATABUFLEN); + } + + return (0); +} + +/* + * Add the file or dir hierarchy named by 'path' to the archive + */ +static void +write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) +{ + struct archive_entry *entry = NULL, *spare_entry = NULL; + struct tree *tree; + char symlink_mode = bsdtar->symlink_mode; + dev_t first_dev = 0; + int dev_recorded = 0; + int tree_ret; + + tree = tree_open(path); + + if (!tree) { + lafe_warnc(errno, "%s: Cannot open", path); + bsdtar->return_value = 1; + return; + } + + while ((tree_ret = tree_next(tree)) != 0) { + int r; + const char *name = tree_current_path(tree); + const struct stat *st = NULL; /* info to use for this entry */ + const struct stat *lst = NULL; /* lstat() information */ + int descend; + + if (tree_ret == TREE_ERROR_FATAL) + lafe_errc(1, tree_errno(tree), + "%s: Unable to continue traversing directory tree", + name); + if (tree_ret == TREE_ERROR_DIR) { + lafe_warnc(errno, + "%s: Couldn't visit directory", name); + bsdtar->return_value = 1; + } + if (tree_ret != TREE_REGULAR) + continue; + + /* + * If this file/dir is excluded by a filename + * pattern, skip it. + */ + if (lafe_excluded(bsdtar->matching, name)) + continue; + + /* + * Get lstat() info from the tree library. + */ + lst = tree_current_lstat(tree); + if (lst == NULL) { + /* Couldn't lstat(); must not exist. */ + lafe_warnc(errno, "%s: Cannot stat", name); + /* Return error if files disappear during traverse. */ + bsdtar->return_value = 1; + continue; + } + + /* + * Distinguish 'L'/'P'/'H' symlink following. + */ + switch(symlink_mode) { + case 'H': + /* 'H': After the first item, rest like 'P'. */ + symlink_mode = 'P'; + /* 'H': First item (from command line) like 'L'. */ + /* FALLTHROUGH */ + case 'L': + /* 'L': Do descend through a symlink to dir. */ + descend = tree_current_is_dir(tree); + /* 'L': Follow symlinks to files. */ + archive_read_disk_set_symlink_logical(bsdtar->diskreader); + /* 'L': Archive symlinks as targets, if we can. */ + st = tree_current_stat(tree); + if (st != NULL) + break; + /* If stat fails, we have a broken symlink; + * in that case, don't follow the link. */ + /* FALLTHROUGH */ + default: + /* 'P': Don't descend through a symlink to dir. */ + descend = tree_current_is_physical_dir(tree); + /* 'P': Don't follow symlinks to files. */ + archive_read_disk_set_symlink_physical(bsdtar->diskreader); + /* 'P': Archive symlinks as symlinks. */ + st = lst; + break; + } + + /* + * Are we about to cross to a new filesystem? + */ + if (!dev_recorded) { + /* This is the initial file system. */ + first_dev = lst->st_dev; + dev_recorded = 1; + } else if (lst->st_dev == first_dev) { + /* The starting file system is always acceptable. */ + } else if (descend == 0) { + /* We're not descending, so no need to check. */ + } else if (bsdtar->option_dont_traverse_mounts) { + /* User has asked us not to cross mount points. */ + descend = 0; + } else { + /* We're prepared to cross a mount point. */ + + /* XXX TODO: check whether this filesystem is + * synthetic and/or local. Add a new + * --local-only option to skip non-local + * filesystems. Skip synthetic filesystems + * regardless. + * + * The results should be cached, since + * tree.c doesn't usually visit a directory + * and the directory contents together. A simple + * move-to-front list should perform quite well. + * + * This is going to be heavily OS dependent: + * FreeBSD's statfs() in conjunction with getvfsbyname() + * provides all of this; NetBSD's statvfs() does + * most of it; other systems will vary. + */ + } + + /* + * In -u mode, check that the file is newer than what's + * already in the archive; in all modes, obey --newerXXX flags. + */ + if (!new_enough(bsdtar, name, st)) + continue; + + archive_entry_free(entry); + entry = archive_entry_new(); + + archive_entry_set_pathname(entry, name); + archive_entry_copy_sourcepath(entry, + tree_current_access_path(tree)); + + /* Populate the archive_entry with metadata from the disk. */ + /* XXX TODO: Arrange to open a regular file before + * calling this so we can pass in an fd and shorten + * the race to query metadata. The linkify dance + * makes this more complex than it might sound. */ +#if defined(_WIN32) && !defined(__CYGWIN__) + /* TODO: tree.c uses stat(), which is badly broken + * on Windows. To fix this, we should + * deprecate tree_current_stat() and provide a new + * call tree_populate_entry(t, entry). This call + * would use stat() internally on POSIX and + * GetInfoByFileHandle() internally on Windows. + * This would be another step towards a tree-walker + * that can be integrated deep into libarchive. + * For now, just set st to NULL on Windows; + * archive_read_disk_entry_from_file() should + * be smart enough to use platform-appropriate + * ways to probe file information. + */ + st = NULL; +#endif + r = archive_read_disk_entry_from_file(bsdtar->diskreader, + entry, -1, st); + if (r != ARCHIVE_OK) + lafe_warnc(archive_errno(bsdtar->diskreader), + "%s", archive_error_string(bsdtar->diskreader)); + if (r < ARCHIVE_WARN) + continue; + + /* XXX TODO: Just use flag data from entry; avoid the + * duplicate check here. */ + + /* + * If this file/dir is flagged "nodump" and we're + * honoring such flags, skip this file/dir. + */ +#if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP) + /* BSD systems store flags in struct stat */ + if (bsdtar->option_honor_nodump && + (lst->st_flags & UF_NODUMP)) + continue; +#endif + +#if defined(EXT2_IOC_GETFLAGS) && defined(EXT2_NODUMP_FL) + /* Linux uses ioctl to read flags. */ + if (bsdtar->option_honor_nodump) { + int fd = open(name, O_RDONLY | O_NONBLOCK | O_BINARY); + if (fd >= 0) { + unsigned long fflags; + int r = ioctl(fd, EXT2_IOC_GETFLAGS, &fflags); + close(fd); + if (r >= 0 && (fflags & EXT2_NODUMP_FL)) + continue; + } + } +#endif + + /* + * If the user vetoes this file/directory, skip it. + * We want this to be fairly late; if some other + * check would veto this file, we shouldn't bother + * the user with it. + */ + if (bsdtar->option_interactive && + !yes("add '%s'", name)) + continue; + + /* Note: if user vetoes, we won't descend. */ + if (descend && !bsdtar->option_no_subdirs) + tree_descend(tree); + + /* + * Rewrite the pathname to be archived. If rewrite + * fails, skip the entry. + */ + if (edit_pathname(bsdtar, entry)) + continue; + + /* Display entry as we process it. + * This format is required by SUSv2. */ + if (bsdtar->verbose) + safe_fprintf(stderr, "a %s", + archive_entry_pathname(entry)); + + /* Non-regular files get archived with zero size. */ + if (archive_entry_filetype(entry) != AE_IFREG) + archive_entry_set_size(entry, 0); + + archive_entry_linkify(bsdtar->resolver, &entry, &spare_entry); + + while (entry != NULL) { + write_entry_backend(bsdtar, a, entry); + archive_entry_free(entry); + entry = spare_entry; + spare_entry = NULL; + } + + if (bsdtar->verbose) + fprintf(stderr, "\n"); + } + archive_entry_free(entry); + tree_close(tree); +} + +/* + * Backend for write_entry. + */ +static void +write_entry_backend(struct bsdtar *bsdtar, struct archive *a, + struct archive_entry *entry) +{ + int fd = -1; + int e; + + if (archive_entry_size(entry) > 0) { + const char *pathname = archive_entry_sourcepath(entry); + fd = open(pathname, O_RDONLY | O_BINARY); + if (fd == -1) { + if (!bsdtar->verbose) + lafe_warnc(errno, + "%s: could not open file", pathname); + else + fprintf(stderr, ": %s", strerror(errno)); + return; + } + } + + e = archive_write_header(a, entry); + if (e != ARCHIVE_OK) { + if (!bsdtar->verbose) + lafe_warnc(0, "%s: %s", + archive_entry_pathname(entry), + archive_error_string(a)); + else + fprintf(stderr, ": %s", archive_error_string(a)); + } + + if (e == ARCHIVE_FATAL) + exit(1); + + /* + * If we opened a file earlier, write it out now. Note that + * the format handler might have reset the size field to zero + * to inform us that the archive body won't get stored. In + * that case, just skip the write. + */ + if (e >= ARCHIVE_WARN && fd >= 0 && archive_entry_size(entry) > 0) { + if (write_file_data(bsdtar, a, entry, fd)) + exit(1); + } + + /* + * If we opened a file, close it now even if there was an error + * which made us decide not to write the archive body. + */ + if (fd >= 0) + close(fd); +} + +static void +report_write(struct bsdtar *bsdtar, struct archive *a, + struct archive_entry *entry, int64_t progress) +{ + uint64_t comp, uncomp; + if (bsdtar->verbose) + fprintf(stderr, "\n"); + comp = archive_position_compressed(a); + uncomp = archive_position_uncompressed(a); + fprintf(stderr, "In: %d files, %s bytes;", + archive_file_count(a), tar_i64toa(uncomp)); + fprintf(stderr, + " Out: %s bytes, compression %d%%\n", + tar_i64toa(comp), (int)((uncomp - comp) * 100 / uncomp)); + /* Can't have two calls to tar_i64toa() pending, so split the output. */ + safe_fprintf(stderr, "Current: %s (%s", + archive_entry_pathname(entry), + tar_i64toa(progress)); + fprintf(stderr, "/%s bytes)\n", + tar_i64toa(archive_entry_size(entry))); +} + + +/* Helper function to copy file to archive. */ +static int +write_file_data(struct bsdtar *bsdtar, struct archive *a, + struct archive_entry *entry, int fd) +{ + ssize_t bytes_read; + ssize_t bytes_written; + int64_t progress = 0; + + bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN); + while (bytes_read > 0) { + if (need_report()) + report_write(bsdtar, a, entry, progress); + + bytes_written = archive_write_data(a, bsdtar->buff, + bytes_read); + if (bytes_written < 0) { + /* Write failed; this is bad */ + lafe_warnc(0, "%s", archive_error_string(a)); + return (-1); + } + if (bytes_written < bytes_read) { + /* Write was truncated; warn but continue. */ + lafe_warnc(0, + "%s: Truncated write; file may have grown while being archived.", + archive_entry_pathname(entry)); + return (0); + } + progress += bytes_written; + bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN); + } + return 0; +} + +/* + * Test if the specified file is new enough to include in the archive. + */ +static int +new_enough(struct bsdtar *bsdtar, const char *path, const struct stat *st) +{ + struct archive_dir_entry *p; + + /* + * If this file/dir is excluded by a time comparison, skip it. + */ + if (bsdtar->newer_ctime_sec > 0) { + if (st->st_ctime < bsdtar->newer_ctime_sec) + return (0); /* Too old, skip it. */ + if (st->st_ctime == bsdtar->newer_ctime_sec + && ARCHIVE_STAT_CTIME_NANOS(st) + <= bsdtar->newer_ctime_nsec) + return (0); /* Too old, skip it. */ + } + if (bsdtar->newer_mtime_sec > 0) { + if (st->st_mtime < bsdtar->newer_mtime_sec) + return (0); /* Too old, skip it. */ + if (st->st_mtime == bsdtar->newer_mtime_sec + && ARCHIVE_STAT_MTIME_NANOS(st) + <= bsdtar->newer_mtime_nsec) + return (0); /* Too old, skip it. */ + } + + /* + * In -u mode, we only write an entry if it's newer than + * what was already in the archive. + */ + if (bsdtar->archive_dir != NULL && + bsdtar->archive_dir->head != NULL) { + for (p = bsdtar->archive_dir->head; p != NULL; p = p->next) { + if (pathcmp(path, p->name)==0) + return (p->mtime_sec < st->st_mtime || + (p->mtime_sec == st->st_mtime && + p->mtime_nsec + < ARCHIVE_STAT_MTIME_NANOS(st))); + } + } + + /* If the file wasn't rejected, include it. */ + return (1); +} + +/* + * Add an entry to the dir list for 'u' mode. + * + * XXX TODO: Make this fast. + */ +static void +add_dir_list(struct bsdtar *bsdtar, const char *path, + time_t mtime_sec, int mtime_nsec) +{ + struct archive_dir_entry *p; + + /* + * Search entire list to see if this file has appeared before. + * If it has, override the timestamp data. + */ + p = bsdtar->archive_dir->head; + while (p != NULL) { + if (strcmp(path, p->name)==0) { + p->mtime_sec = mtime_sec; + p->mtime_nsec = mtime_nsec; + return; + } + p = p->next; + } + + p = malloc(sizeof(*p)); + if (p == NULL) + lafe_errc(1, ENOMEM, "Can't read archive directory"); + + p->name = strdup(path); + if (p->name == NULL) + lafe_errc(1, ENOMEM, "Can't read archive directory"); + p->mtime_sec = mtime_sec; + p->mtime_nsec = mtime_nsec; + p->next = NULL; + if (bsdtar->archive_dir->tail == NULL) { + bsdtar->archive_dir->head = bsdtar->archive_dir->tail = p; + } else { + bsdtar->archive_dir->tail->next = p; + bsdtar->archive_dir->tail = p; + } +} + +static void +test_for_append(struct bsdtar *bsdtar) +{ + struct stat s; + + if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL) + lafe_errc(1, 0, "no files or directories specified"); + if (bsdtar->filename == NULL) + lafe_errc(1, 0, "Cannot append to stdout."); + + if (bsdtar->create_compression != 0) + lafe_errc(1, 0, + "Cannot append to %s with compression", bsdtar->filename); + + if (stat(bsdtar->filename, &s) != 0) + return; + + if (!S_ISREG(s.st_mode) && !S_ISBLK(s.st_mode)) + lafe_errc(1, 0, + "Cannot append to %s: not a regular file.", + bsdtar->filename); + +/* Is this an appropriate check here on Windows? */ +/* + if (GetFileType(handle) != FILE_TYPE_DISK) + lafe_errc(1, 0, "Cannot append"); +*/ + +} diff --git a/lib/libarchive/config.h b/external/bsd/libarchive/include/config_netbsd.h similarity index 82% rename from lib/libarchive/config.h rename to external/bsd/libarchive/include/config_netbsd.h index 5770c1ea2..f0432c28d 100644 --- a/lib/libarchive/config.h +++ b/external/bsd/libarchive/include/config_netbsd.h @@ -1,11 +1,80 @@ /* config.h. Generated from config.h.in by configure. */ /* config.h.in. Generated from configure.ac by autoheader. */ +/* MD5 via ARCHIVE_HASH_MD5_LIBC supported. */ +#define ARCHIVE_HASH_MD5_LIBC 1 + +/* MD5 via ARCHIVE_HASH_MD5_LIBSYSTEM supported. */ +/* #undef ARCHIVE_HASH_MD5_LIBSYSTEM */ + +/* MD5 via ARCHIVE_HASH_MD5_OPENSSL supported. */ +/* #undef ARCHIVE_HASH_MD5_OPENSSL */ + +/* RMD160 via ARCHIVE_HASH_RMD160_LIBC supported. */ +#define ARCHIVE_HASH_RMD160_LIBC 1 + +/* RMD160 via ARCHIVE_HASH_RMD160_OPENSSL supported. */ +/* #undef ARCHIVE_HASH_RMD160_OPENSSL */ + +/* SHA1 via ARCHIVE_HASH_SHA1_LIBC supported. */ +#define ARCHIVE_HASH_SHA1_LIBC 1 + +/* SHA1 via ARCHIVE_HASH_SHA1_LIBSYSTEM supported. */ +/* #undef ARCHIVE_HASH_SHA1_LIBSYSTEM */ + +/* SHA1 via ARCHIVE_HASH_SHA1_OPENSSL supported. */ +/* #undef ARCHIVE_HASH_SHA1_OPENSSL */ + +/* SHA256 via ARCHIVE_HASH_SHA256_LIBC supported. */ +#define ARCHIVE_HASH_SHA256_LIBC 1 + +/* SHA256 via ARCHIVE_HASH_SHA256_LIBC2 supported. */ +/* #undef ARCHIVE_HASH_SHA256_LIBC2 */ + +/* SHA256 via ARCHIVE_HASH_SHA256_LIBC3 supported. */ +/* #undef ARCHIVE_HASH_SHA256_LIBC3 */ + +/* SHA256 via ARCHIVE_HASH_SHA256_LIBSYSTEM supported. */ +/* #undef ARCHIVE_HASH_SHA256_LIBSYSTEM */ + +/* SHA256 via ARCHIVE_HASH_SHA256_OPENSSL supported. */ +/* #undef ARCHIVE_HASH_SHA256_OPENSSL */ + +/* SHA384 via ARCHIVE_HASH_SHA384_LIBC supported. */ +#define ARCHIVE_HASH_SHA384_LIBC 1 + +/* SHA384 via ARCHIVE_HASH_SHA384_LIBC2 supported. */ +/* #undef ARCHIVE_HASH_SHA384_LIBC2 */ + +/* SHA384 via ARCHIVE_HASH_SHA384_LIBC3 supported. */ +/* #undef ARCHIVE_HASH_SHA384_LIBC3 */ + +/* SHA384 via ARCHIVE_HASH_SHA384_LIBSYSTEM supported. */ +/* #undef ARCHIVE_HASH_SHA384_LIBSYSTEM */ + +/* SHA384 via ARCHIVE_HASH_SHA384_OPENSSL supported. */ +/* #undef ARCHIVE_HASH_SHA384_OPENSSL */ + +/* SHA512 via ARCHIVE_HASH_SHA512_LIBC supported. */ +#define ARCHIVE_HASH_SHA512_LIBC 1 + +/* SHA512 via ARCHIVE_HASH_SHA512_LIBC2 supported. */ +/* #undef ARCHIVE_HASH_SHA512_LIBC2 */ + +/* SHA512 via ARCHIVE_HASH_SHA512_LIBC3 supported. */ +/* #undef ARCHIVE_HASH_SHA512_LIBC3 */ + +/* SHA512 via ARCHIVE_HASH_SHA512_LIBSYSTEM supported. */ +/* #undef ARCHIVE_HASH_SHA512_LIBSYSTEM */ + +/* SHA512 via ARCHIVE_HASH_SHA512_OPENSSL supported. */ +/* #undef ARCHIVE_HASH_SHA512_OPENSSL */ + /* Version number of bsdcpio */ -#define BSDCPIO_VERSION_STRING "2.8.3" +#define BSDCPIO_VERSION_STRING "2.8.4" /* Version number of bsdtar */ -#define BSDTAR_VERSION_STRING "2.8.3" +#define BSDTAR_VERSION_STRING "2.8.4" /* Define to 1 if you have the `acl_create_entry' function. */ /* #undef HAVE_ACL_CREATE_ENTRY */ @@ -50,7 +119,7 @@ #define HAVE_BZLIB_H 1 /* Define to 1 if you have the `chflags' function. */ -/* #undef HAVE_CHFLAGS */ +/* #define HAVE_CHFLAGS 1 */ /* Define to 1 if you have the `chown' function. */ #define HAVE_CHOWN 1 @@ -64,13 +133,17 @@ /* Define to 1 if you have the `cygwin_conv_path' function. */ /* #undef HAVE_CYGWIN_CONV_PATH */ +/* Define to 1 if you have the declaration of `EXTATTR_NAMESPACE_USER', and to + 0 if you don't. */ +#define HAVE_DECL_EXTATTR_NAMESPACE_USER 1 + /* Define to 1 if you have the declaration of `INT64_MAX', and to 0 if you don't. */ -#define HAVE_DECL_INT64_MAX 0 +#define HAVE_DECL_INT64_MAX 1 /* Define to 1 if you have the declaration of `INT64_MIN', and to 0 if you don't. */ -#define HAVE_DECL_INT64_MIN 0 +#define HAVE_DECL_INT64_MIN 1 /* Define to 1 if you have the declaration of `SIZE_MAX', and to 0 if you don't. */ @@ -78,11 +151,11 @@ /* Define to 1 if you have the declaration of `SSIZE_MAX', and to 0 if you don't. */ -#define HAVE_DECL_SSIZE_MAX 1 +#define HAVE_DECL_SSIZE_MAX 0 /* Define to 1 if you have the declaration of `strerror_r', and to 0 if you don't. */ -#define HAVE_DECL_STRERROR_R 0 +#define HAVE_DECL_STRERROR_R 1 /* Define to 1 if you have the declaration of `UINT32_MAX', and to 0 if you don't. */ @@ -90,23 +163,23 @@ /* Define to 1 if you have the declaration of `UINT64_MAX', and to 0 if you don't. */ -#define HAVE_DECL_UINT64_MAX 0 +#define HAVE_DECL_UINT64_MAX 1 /* Define to 1 if you have the header file, and it defines `DIR'. */ #define HAVE_DIRENT_H 1 /* Define to 1 if you have the header file. */ -/* #undef HAVE_DLFCN_H */ +#define HAVE_DLFCN_H 1 /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ -#define HAVE_DOPRNT 1 +/* #undef HAVE_DOPRNT */ /* Define to 1 if nl_langinfo supports D_MD_ORDER */ /* #undef HAVE_D_MD_ORDER */ /* A possible errno value for invalid file format errors */ -/* #undef HAVE_EFTYPE */ +#define HAVE_EFTYPE 1 /* A possible errno value for invalid file format errors */ #define HAVE_EILSEQ 1 @@ -121,22 +194,22 @@ /* #undef HAVE_EXT2FS_EXT2_FS_H */ /* Define to 1 if you have the `extattr_get_file' function. */ -/* #undef HAVE_EXTATTR_GET_FILE */ +/* #define HAVE_EXTATTR_GET_FILE 1 */ /* Define to 1 if you have the `extattr_list_file' function. */ -/* #undef HAVE_EXTATTR_LIST_FILE */ +/* #define HAVE_EXTATTR_LIST_FILE 1 */ /* Define to 1 if you have the `extattr_set_fd' function. */ -/* #undef HAVE_EXTATTR_SET_FD */ +/* #define HAVE_EXTATTR_SET_FD 1 */ /* Define to 1 if you have the `extattr_set_file' function. */ -/* #undef HAVE_EXTATTR_SET_FILE */ +/* #define HAVE_EXTATTR_SET_FILE 1 */ /* Define to 1 if you have the `fchdir' function. */ #define HAVE_FCHDIR 1 /* Define to 1 if you have the `fchflags' function. */ -/* #undef HAVE_FCHFLAGS */ +/* #define HAVE_FCHFLAGS 1 */ /* Define to 1 if you have the `fchmod' function. */ #define HAVE_FCHMOD 1 @@ -154,7 +227,7 @@ #define HAVE_FORK 1 /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ -/* #undef HAVE_FSEEKO */ +#define HAVE_FSEEKO 1 /* Define to 1 if you have the `fsetxattr' function. */ /* #undef HAVE_FSETXATTR */ @@ -169,25 +242,25 @@ /* #undef HAVE_FUTIMENS */ /* Define to 1 if you have the `futimes' function. */ -/* #undef HAVE_FUTIMES */ +/* #define HAVE_FUTIMES 1 */ /* Define to 1 if you have the `geteuid' function. */ #define HAVE_GETEUID 1 /* Define to 1 if you have the `getgrgid_r' function. */ -/* #undef HAVE_GETGRGID_R */ +#define HAVE_GETGRGID_R 1 /* Define to 1 if you have the `getgrnam_r' function. */ -/* #undef HAVE_GETGRNAM_R */ +#define HAVE_GETGRNAM_R 1 /* Define to 1 if you have the `getpid' function. */ #define HAVE_GETPID 1 /* Define to 1 if you have the `getpwnam_r' function. */ -/* #undef HAVE_GETPWNAM_R */ +#define HAVE_GETPWNAM_R 1 /* Define to 1 if you have the `getpwuid_r' function. */ -/* #undef HAVE_GETPWUID_R */ +#define HAVE_GETPWUID_R 1 /* Define to 1 if you have the `getxattr' function. */ /* #undef HAVE_GETXATTR */ @@ -208,13 +281,13 @@ #define HAVE_LANGINFO_H 1 /* Define to 1 if you have the `lchflags' function. */ -/* #undef HAVE_LCHFLAGS */ +/* #define HAVE_LCHFLAGS 1 */ /* Define to 1 if you have the `lchmod' function. */ -/* #undef HAVE_LCHMOD */ +/* #define HAVE_LCHMOD 1 */ /* Define to 1 if you have the `lchown' function. */ -/* #undef HAVE_LCHOWN */ +/* #define HAVE_LCHOWN 1 */ /* Define to 1 if you have the `lgetxattr' function. */ /* #undef HAVE_LGETXATTR */ @@ -265,7 +338,7 @@ #define HAVE_LOCALE_H 1 /* Define to 1 if the system has the type `long long int'. */ -/* #undef HAVE_LONG_LONG_INT */ +#define HAVE_LONG_LONG_INT 1 /* Define to 1 if you have the `lsetxattr' function. */ /* #undef HAVE_LSETXATTR */ @@ -278,7 +351,7 @@ /* #undef HAVE_LSTAT_EMPTY_STRING_BUG */ /* Define to 1 if you have the `lutimes' function. */ -/* #undef HAVE_LUTIMES */ +/* #define HAVE_LUTIMES 1 */ /* Define to 1 if you have the header file. */ /* #undef HAVE_LZMADEC_H */ @@ -286,17 +359,11 @@ /* Define to 1 if you have the header file. */ #define HAVE_LZMA_H 1 -/* Define to 1 if you have the `MD5Init' function. */ -/* #undef HAVE_MD5INIT */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_MD5_H */ - /* Define to 1 if you have the `memmove' function. */ #define HAVE_MEMMOVE 1 /* Define to 1 if you have the header file. */ -/* #undef HAVE_MEMORY_H */ +#define HAVE_MEMORY_H 1 /* Define to 1 if you have the `memset' function. */ #define HAVE_MEMSET 1 @@ -314,25 +381,7 @@ /* #undef HAVE_NDIR_H */ /* Define to 1 if you have the `nl_langinfo' function. */ -/* #undef HAVE_NL_LANGINFO */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_MD5_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_RIPEMD_H */ - -/* Define to 1 if your openssl has the `SHA256_Init' function. */ -/* #undef HAVE_OPENSSL_SHA256_INIT */ - -/* Define to 1 if your openssl has the `SHA384_Init' function. */ -/* #undef HAVE_OPENSSL_SHA384_INIT */ - -/* Define to 1 if your openssl has the `SHA512_Init' function. */ -/* #undef HAVE_OPENSSL_SHA512_INIT */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_OPENSSL_SHA_H */ +#define HAVE_NL_LANGINFO 1 /* Define to 1 if you have the header file. */ #define HAVE_PATHS_H 1 @@ -341,10 +390,10 @@ #define HAVE_PIPE 1 /* Define to 1 if you have the `poll' function. */ -/* #undef HAVE_POLL */ +#define HAVE_POLL 1 /* Define to 1 if you have the header file. */ -/* #undef HAVE_POLL_H */ +#define HAVE_POLL_H 1 /* Define to 1 if you have the header file. */ #define HAVE_PWD_H 1 @@ -355,15 +404,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_REGEX_H 1 -/* Define to 1 if you have the header file. */ -/* #undef HAVE_RIPEMD_H */ - -/* Define to 1 if you have the `RMD160Init' function. */ -/* #undef HAVE_RMD160INIT */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_RMD160_H */ - /* Define to 1 if you have the `select' function. */ #define HAVE_SELECT 1 @@ -373,39 +413,6 @@ /* Define to 1 if you have the `setlocale' function. */ #define HAVE_SETLOCALE 1 -/* Define to 1 if you have the `SHA1Init' function. */ -/* #undef HAVE_SHA1INIT */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SHA1_H */ - -/* Define to 1 if you have the `SHA256Init' function. */ -/* #undef HAVE_SHA256INIT */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SHA256_H */ - -/* Define to 1 if you have the `SHA256_Init' function. */ -/* #undef HAVE_SHA256_INIT */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SHA2_H */ - -/* Define to 1 if you have the `SHA384Init' function. */ -/* #undef HAVE_SHA384INIT */ - -/* Define to 1 if you have the `SHA384_Init' function. */ -/* #undef HAVE_SHA384_INIT */ - -/* Define to 1 if you have the `SHA512Init' function. */ -/* #undef HAVE_SHA512INIT */ - -/* Define to 1 if you have the `SHA512_Init' function. */ -/* #undef HAVE_SHA512_INIT */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SHA_H */ - /* Define to 1 if you have the `sigaction' function. */ #define HAVE_SIGACTION 1 @@ -435,7 +442,7 @@ #define HAVE_STRERROR 1 /* Define to 1 if you have the `strerror_r' function. */ -/* #undef HAVE_STRERROR_R */ +#define HAVE_STRERROR_R 1 /* Define to 1 if you have the `strftime' function. */ #define HAVE_STRFTIME 1 @@ -453,19 +460,19 @@ #define HAVE_STRRCHR 1 /* Define to 1 if `st_birthtime' is a member of `struct stat'. */ -/* #undef HAVE_STRUCT_STAT_ST_BIRTHTIME */ +#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1 /* Define to 1 if `st_birthtimespec.tv_nsec' is a member of `struct stat'. */ -/* #undef HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC */ +#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1 /* Define to 1 if `st_blksize' is a member of `struct stat'. */ -/* #undef HAVE_STRUCT_STAT_ST_BLKSIZE */ +#define HAVE_STRUCT_STAT_ST_BLKSIZE 1 /* Define to 1 if `st_flags' is a member of `struct stat'. */ -/* #undef HAVE_STRUCT_STAT_ST_FLAGS */ +#define HAVE_STRUCT_STAT_ST_FLAGS 1 /* Define to 1 if `st_mtimespec.tv_nsec' is a member of `struct stat'. */ -/* #undef HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC */ +#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 /* Define to 1 if `st_mtime_n' is a member of `struct stat'. */ /* #undef HAVE_STRUCT_STAT_ST_MTIME_N */ @@ -493,7 +500,7 @@ /* #undef HAVE_SYS_DIR_H */ /* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_EXTATTR_H */ +#define HAVE_SYS_EXTATTR_H 1 /* Define to 1 if you have the header file. */ #define HAVE_SYS_IOCTL_H 1 @@ -509,7 +516,7 @@ #define HAVE_SYS_PARAM_H 1 /* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_POLL_H */ +#define HAVE_SYS_POLL_H 1 /* Define to 1 if you have the header file. */ #define HAVE_SYS_SELECT_H 1 @@ -551,10 +558,10 @@ #define HAVE_UNSETENV 1 /* Define to 1 if the system has the type `unsigned long long'. */ -/* #undef HAVE_UNSIGNED_LONG_LONG */ +#define HAVE_UNSIGNED_LONG_LONG 1 /* Define to 1 if the system has the type `unsigned long long int'. */ -/* #undef HAVE_UNSIGNED_LONG_LONG_INT */ +#define HAVE_UNSIGNED_LONG_LONG_INT 1 /* Define to 1 if you have the `utime' function. */ #define HAVE_UTIME 1 @@ -563,13 +570,13 @@ /* #undef HAVE_UTIMENSAT */ /* Define to 1 if you have the `utimes' function. */ -/* #undef HAVE_UTIMES */ +/* #define HAVE_UTIMES 1 */ /* Define to 1 if you have the header file. */ #define HAVE_UTIME_H 1 /* Define to 1 if you have the `vfork' function. */ -/* #undef HAVE_VFORK */ +#define HAVE_VFORK 1 /* Define to 1 if you have the `vprintf' function. */ #define HAVE_VPRINTF 1 @@ -581,7 +588,10 @@ #define HAVE_WCHAR_T 1 /* Define to 1 if you have the `wcrtomb' function. */ -/* #undef HAVE_WCRTOMB */ +#define HAVE_WCRTOMB 1 + +/* Define to 1 if you have the `wcscmp' function. */ +#define HAVE_WCSCMP 1 /* Define to 1 if you have the `wcscpy' function. */ #define HAVE_WCSCPY 1 @@ -593,7 +603,7 @@ #define HAVE_WCTOMB 1 /* Define to 1 if you have the header file. */ -/* #undef HAVE_WCTYPE_H */ +#define HAVE_WCTYPE_H 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_WINDOWS_H */ @@ -608,10 +618,10 @@ #define HAVE_ZLIB_H 1 /* Version number of libarchive as a single integer */ -#define LIBARCHIVE_VERSION_NUMBER "2008003" +#define LIBARCHIVE_VERSION_NUMBER "2008004" /* Version number of libarchive */ -#define LIBARCHIVE_VERSION_STRING "2.8.3" +#define LIBARCHIVE_VERSION_STRING "2.8.4" /* Define to 1 if `lstat' dereferences a symlink specified with a trailing slash. */ @@ -642,7 +652,7 @@ #define PACKAGE_NAME "libarchive" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "libarchive 2.8.3" +#define PACKAGE_STRING "libarchive 2.8.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "libarchive" @@ -651,10 +661,10 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "2.8.3" +#define PACKAGE_VERSION "2.8.4" /* The size of `wchar_t', as computed by sizeof. */ -#define SIZEOF_WCHAR_T 1 +#define SIZEOF_WCHAR_T 4 /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 @@ -688,7 +698,7 @@ /* Version number of package */ -#define VERSION "2.8.3" +#define VERSION "2.8.4" /* Define to '0x0500' for Windows 2000 APIs. */ /* #undef WINVER */ @@ -703,16 +713,14 @@ /* #undef _LARGE_FILES */ /* Define to 1 if on MINIX. */ -#define _MINIX 1 +/* #undef _MINIX */ /* Define to 2 if the system does not provide POSIX.1 features except with this defined. */ -#define _POSIX_1_SOURCE 2 +/* #undef _POSIX_1_SOURCE */ /* Define to 1 if you need to in order for `stat' and other things to work. */ -#ifndef __NBSD_LIBC -#define _POSIX_SOURCE 1 -#endif +/* #undef _POSIX_SOURCE */ /* Define for Solaris 2.5.1 so the uint64_t typedef from , , or is not used. If the typedef were allowed, the @@ -730,9 +738,7 @@ /* #undef gid_t */ /* Define to `unsigned long' if does not define. */ -#ifndef __NBSD_LIBC -#define id_t unsigned long -#endif +/* #undef id_t */ /* Define to the type of a signed integer type of width exactly 64 bits if such a type exists and the standard includes do not define it. */ diff --git a/external/bsd/libarchive/lib/Makefile b/external/bsd/libarchive/lib/Makefile new file mode 100644 index 000000000..8223cf929 --- /dev/null +++ b/external/bsd/libarchive/lib/Makefile @@ -0,0 +1,5 @@ +# $NetBSD: Makefile,v 1.2 2010/02/20 02:55:53 joerg Exp $ + +SUBDIR+= libarchive libarchive_fe + +.include diff --git a/external/bsd/libarchive/lib/Makefile.inc b/external/bsd/libarchive/lib/Makefile.inc new file mode 100644 index 000000000..5b4d708d2 --- /dev/null +++ b/external/bsd/libarchive/lib/Makefile.inc @@ -0,0 +1,3 @@ +# $NetBSD: Makefile.inc,v 1.1 2010/02/20 02:55:53 joerg Exp $ + +.include "../Makefile.inc" diff --git a/external/bsd/libarchive/lib/libarchive/Makefile b/external/bsd/libarchive/lib/libarchive/Makefile new file mode 100644 index 000000000..a377076dd --- /dev/null +++ b/external/bsd/libarchive/lib/libarchive/Makefile @@ -0,0 +1,265 @@ +# $NetBSD: Makefile,v 1.3 2010/11/02 19:14:54 joerg Exp $ + +.include + +.PATH: ${LIBARCHIVEDIR}/libarchive + +LIB= archive + +LIBDPLIBS+= bz2 ${NETBSDSRCDIR}/lib/libbz2 \ + lzma ${NETBSDSRCDIR}/external/public-domain/xz/lib \ + z ${NETBSDSRCDIR}/lib/libz + +SRCS= archive_check_magic.c \ + archive_entry.c \ + archive_entry_copy_stat.c \ + archive_entry_link_resolver.c \ + archive_entry_stat.c \ + archive_entry_strmode.c \ + archive_entry_xattr.c \ + archive_read.c \ + archive_read_data_into_fd.c \ + archive_read_disk.c \ + archive_read_disk_entry_from_file.c \ + archive_read_disk_set_standard_lookup.c \ + archive_read_extract.c \ + archive_read_open_fd.c \ + archive_read_open_file.c \ + archive_read_open_filename.c \ + archive_read_open_memory.c \ + archive_read_support_compression_all.c \ + archive_read_support_compression_bzip2.c \ + archive_read_support_compression_compress.c \ + archive_read_support_compression_gzip.c \ + archive_read_support_compression_none.c \ + archive_read_support_compression_program.c \ + archive_read_support_compression_rpm.c \ + archive_read_support_compression_uu.c \ + archive_read_support_compression_xz.c \ + archive_read_support_format_all.c \ + archive_read_support_format_ar.c \ + archive_read_support_format_cpio.c \ + archive_read_support_format_empty.c \ + archive_read_support_format_iso9660.c \ + archive_read_support_format_mtree.c \ + archive_read_support_format_raw.c \ + archive_read_support_format_tar.c \ + archive_read_support_format_xar.c \ + archive_read_support_format_zip.c \ + archive_string.c \ + archive_string_sprintf.c \ + archive_util.c \ + archive_virtual.c \ + archive_write.c \ + archive_write_disk.c \ + archive_write_disk_set_standard_lookup.c \ + archive_write_open_fd.c \ + archive_write_open_file.c \ + archive_write_open_filename.c \ + archive_write_open_memory.c \ + archive_write_set_compression_bzip2.c \ + archive_write_set_compression_compress.c \ + archive_write_set_compression_gzip.c \ + archive_write_set_compression_none.c \ + archive_write_set_compression_program.c \ + archive_write_set_compression_xz.c \ + archive_write_set_format.c \ + archive_write_set_format_ar.c \ + archive_write_set_format_by_name.c \ + archive_write_set_format_cpio.c \ + archive_write_set_format_cpio_newc.c \ + archive_write_set_format_mtree.c \ + archive_write_set_format_pax.c \ + archive_write_set_format_shar.c \ + archive_write_set_format_ustar.c \ + archive_write_set_format_zip.c \ + filter_fork.c + +INCS= archive.h archive_entry.h +INCSDIR= /usr/include + +MAN= archive_entry.3 \ + archive_read.3 \ + archive_read_disk.3 \ + archive_util.3 \ + archive_write.3 \ + archive_write_disk.3 \ + cpio.5 \ + libarchive.3 \ + libarchive_internals.3 \ + libarchive-formats.5 \ + mtree.5 \ + tar.5 + +MLINKS+= archive_entry.3 archive_entry_acl_add_entry.3 +MLINKS+= archive_entry.3 archive_entry_acl_add_entry_w.3 +MLINKS+= archive_entry.3 archive_entry_acl_clear.3 +MLINKS+= archive_entry.3 archive_entry_acl_count.3 +MLINKS+= archive_entry.3 archive_entry_acl_next.3 +MLINKS+= archive_entry.3 archive_entry_acl_next_w.3 +MLINKS+= archive_entry.3 archive_entry_acl_reset.3 +MLINKS+= archive_entry.3 archive_entry_acl_text_w.3 +MLINKS+= archive_entry.3 archive_entry_atime.3 +MLINKS+= archive_entry.3 archive_entry_atime_nsec.3 +MLINKS+= archive_entry.3 archive_entry_clear.3 +MLINKS+= archive_entry.3 archive_entry_clone.3 +MLINKS+= archive_entry.3 archive_entry_copy_fflags_text.3 +MLINKS+= archive_entry.3 archive_entry_copy_fflags_text_w.3 +MLINKS+= archive_entry.3 archive_entry_copy_gname.3 +MLINKS+= archive_entry.3 archive_entry_copy_gname_w.3 +MLINKS+= archive_entry.3 archive_entry_copy_hardlink.3 +MLINKS+= archive_entry.3 archive_entry_copy_hardlink_w.3 +MLINKS+= archive_entry.3 archive_entry_copy_link.3 +MLINKS+= archive_entry.3 archive_entry_copy_link_w.3 +MLINKS+= archive_entry.3 archive_entry_copy_pathname_w.3 +MLINKS+= archive_entry.3 archive_entry_copy_sourcepath.3 +MLINKS+= archive_entry.3 archive_entry_copy_stat.3 +MLINKS+= archive_entry.3 archive_entry_copy_symlink.3 +MLINKS+= archive_entry.3 archive_entry_copy_symlink_w.3 +MLINKS+= archive_entry.3 archive_entry_copy_uname.3 +MLINKS+= archive_entry.3 archive_entry_copy_uname_w.3 +MLINKS+= archive_entry.3 archive_entry_dev.3 +MLINKS+= archive_entry.3 archive_entry_devmajor.3 +MLINKS+= archive_entry.3 archive_entry_devminor.3 +MLINKS+= archive_entry.3 archive_entry_filetype.3 +MLINKS+= archive_entry.3 archive_entry_fflags.3 +MLINKS+= archive_entry.3 archive_entry_fflags_text.3 +MLINKS+= archive_entry.3 archive_entry_free.3 +MLINKS+= archive_entry.3 archive_entry_gid.3 +MLINKS+= archive_entry.3 archive_entry_gname.3 +MLINKS+= archive_entry.3 archive_entry_hardlink.3 +MLINKS+= archive_entry.3 archive_entry_ino.3 +MLINKS+= archive_entry.3 archive_entry_mode.3 +MLINKS+= archive_entry.3 archive_entry_mtime.3 +MLINKS+= archive_entry.3 archive_entry_mtime_nsec.3 +MLINKS+= archive_entry.3 archive_entry_nlink.3 +MLINKS+= archive_entry.3 archive_entry_new.3 +MLINKS+= archive_entry.3 archive_entry_pathname.3 +MLINKS+= archive_entry.3 archive_entry_pathname_w.3 +MLINKS+= archive_entry.3 archive_entry_rdev.3 +MLINKS+= archive_entry.3 archive_entry_rdevmajor.3 +MLINKS+= archive_entry.3 archive_entry_rdevminor.3 +MLINKS+= archive_entry.3 archive_entry_set_atime.3 +MLINKS+= archive_entry.3 archive_entry_set_ctime.3 +MLINKS+= archive_entry.3 archive_entry_set_dev.3 +MLINKS+= archive_entry.3 archive_entry_set_devmajor.3 +MLINKS+= archive_entry.3 archive_entry_set_devminor.3 +MLINKS+= archive_entry.3 archive_entry_set_filetype.3 +MLINKS+= archive_entry.3 archive_entry_set_fflags.3 +MLINKS+= archive_entry.3 archive_entry_set_gid.3 +MLINKS+= archive_entry.3 archive_entry_set_gname.3 +MLINKS+= archive_entry.3 archive_entry_set_hardlink.3 +MLINKS+= archive_entry.3 archive_entry_set_link.3 +MLINKS+= archive_entry.3 archive_entry_set_mode.3 +MLINKS+= archive_entry.3 archive_entry_set_mtime.3 +MLINKS+= archive_entry.3 archive_entry_set_pathname.3 +MLINKS+= archive_entry.3 archive_entry_set_rdevmajor.3 +MLINKS+= archive_entry.3 archive_entry_set_rdevminor.3 +MLINKS+= archive_entry.3 archive_entry_set_size.3 +MLINKS+= archive_entry.3 archive_entry_set_symlink.3 +MLINKS+= archive_entry.3 archive_entry_set_uid.3 +MLINKS+= archive_entry.3 archive_entry_set_uname.3 +MLINKS+= archive_entry.3 archive_entry_size.3 +MLINKS+= archive_entry.3 archive_entry_sourcepath.3 +MLINKS+= archive_entry.3 archive_entry_stat.3 +MLINKS+= archive_entry.3 archive_entry_symlink.3 +MLINKS+= archive_entry.3 archive_entry_uid.3 +MLINKS+= archive_entry.3 archive_entry_uname.3 +MLINKS+= archive_read.3 archive_read_close.3 +MLINKS+= archive_read.3 archive_read_data.3 +MLINKS+= archive_read.3 archive_read_data_block.3 +MLINKS+= archive_read.3 archive_read_data_into_buffer.3 +MLINKS+= archive_read.3 archive_read_data_into_fd.3 +MLINKS+= archive_read.3 archive_read_data_skip.3 +MLINKS+= archive_read.3 archive_read_extract.3 +MLINKS+= archive_read.3 archive_read_extract2.3 +MLINKS+= archive_read.3 archive_read_extract_set_progress_callback.3 +MLINKS+= archive_read.3 archive_read_finish.3 +MLINKS+= archive_read.3 archive_read_new.3 +MLINKS+= archive_read.3 archive_read_next_header.3 +MLINKS+= archive_read.3 archive_read_next_header2.3 +MLINKS+= archive_read.3 archive_read_open.3 +MLINKS+= archive_read.3 archive_read_open2.3 +MLINKS+= archive_read.3 archive_read_open_FILE.3 +MLINKS+= archive_read.3 archive_read_open_fd.3 +MLINKS+= archive_read.3 archive_read_open_file.3 +MLINKS+= archive_read.3 archive_read_open_filename.3 +MLINKS+= archive_read.3 archive_read_open_memory.3 +MLINKS+= archive_read.3 archive_read_set_filter_options.3 +MLINKS+= archive_read.3 archive_read_set_format_options.3 +MLINKS+= archive_read.3 archive_read_set_options.3 +MLINKS+= archive_read.3 archive_read_support_compression_all.3 +MLINKS+= archive_read.3 archive_read_support_compression_bzip2.3 +MLINKS+= archive_read.3 archive_read_support_compression_compress.3 +MLINKS+= archive_read.3 archive_read_support_compression_gzip.3 +MLINKS+= archive_read.3 archive_read_support_compression_lzma.3 +MLINKS+= archive_read.3 archive_read_support_compression_none.3 +MLINKS+= archive_read.3 archive_read_support_compression_program.3 +MLINKS+= archive_read.3 archive_read_support_compression_program_signature.3 +MLINKS+= archive_read.3 archive_read_support_compression_xz.3 +MLINKS+= archive_read.3 archive_read_support_format_all.3 +MLINKS+= archive_read.3 archive_read_support_format_ar.3 +MLINKS+= archive_read.3 archive_read_support_format_empty.3 +MLINKS+= archive_read.3 archive_read_support_format_cpio.3 +MLINKS+= archive_read.3 archive_read_support_format_iso9660.3 +MLINKS+= archive_read.3 archive_read_support_format_mtree.3 +MLINKS+= archive_read.3 archive_read_support_format_raw.3 +MLINKS+= archive_read.3 archive_read_support_format_tar.3 +MLINKS+= archive_read.3 archive_read_support_format_zip.3 +MLINKS+= archive_read_disk.3 archive_read_disk_new.3 +MLINKS+= archive_read_disk.3 archive_read_disk_set_symlink_logical.3 +MLINKS+= archive_read_disk.3 archive_read_disk_set_symlink_physical.3 +MLINKS+= archive_read_disk.3 archive_read_disk_set_symlink_hybrid.3 +MLINKS+= archive_read_disk.3 archive_read_disk_set_entry_from_file.3 +MLINKS+= archive_read_disk.3 archive_read_disk_gname.3 +MLINKS+= archive_read_disk.3 archive_read_disk_uname.3 +MLINKS+= archive_read_disk.3 archive_read_disk_set_uname_lookup.3 +MLINKS+= archive_read_disk.3 archive_read_disk_set_gname_lookup.3 +MLINKS+= archive_read_disk.3 archive_read_disk_set_standard_lookup.3 +MLINKS+= archive_util.3 archive_clear_error.3 +MLINKS+= archive_util.3 archive_compression.3 +MLINKS+= archive_util.3 archive_compression_name.3 +MLINKS+= archive_util.3 archive_copy_error.3 +MLINKS+= archive_util.3 archive_errno.3 +MLINKS+= archive_util.3 archive_error_string.3 +MLINKS+= archive_util.3 archive_file_count.3 +MLINKS+= archive_util.3 archive_format.3 +MLINKS+= archive_util.3 archive_format_name.3 +MLINKS+= archive_util.3 archive_set_error.3 +MLINKS+= archive_write.3 archive_write_new.3 +MLINKS+= archive_write.3 archive_write_set_format_cpio.3 +MLINKS+= archive_write.3 archive_write_set_format_pax.3 +MLINKS+= archive_write.3 archive_write_set_format_pax_restricted.3 +MLINKS+= archive_write.3 archive_write_set_format_shar.3 +MLINKS+= archive_write.3 archive_write_set_format_shar_binary.3 +MLINKS+= archive_write.3 archive_write_set_format_ustar.3 +MLINKS+= archive_write.3 archive_write_get_bytes_per_block.3 +MLINKS+= archive_write.3 archive_write_set_bytes_per_block.3 +MLINKS+= archive_write.3 archive_write_set_bytes_in_last_block.3 +MLINKS+= archive_write.3 archive_write_set_compression_bzip2.3 +MLINKS+= archive_write.3 archive_write_set_compression_compress.3 +MLINKS+= archive_write.3 archive_write_set_compression_gzip.3 +MLINKS+= archive_write.3 archive_write_set_compression_none.3 +MLINKS+= archive_write.3 archive_write_set_compression_program.3 +MLINKS+= archive_write.3 archive_write_set_compressor_options.3 +MLINKS+= archive_write.3 archive_write_options.3 +MLINKS+= archive_write.3 archive_write_open.3 +MLINKS+= archive_write.3 archive_write_open_fd.3 +MLINKS+= archive_write.3 archive_write_open_FILE.3 +MLINKS+= archive_write.3 archive_write_open_filename.3 +MLINKS+= archive_write.3 archive_write_open_memory.3 +MLINKS+= archive_write.3 archive_write_header.3 +MLINKS+= archive_write.3 archive_write_data.3 +MLINKS+= archive_write.3 archive_write_finish_entry.3 +MLINKS+= archive_write.3 archive_write_close.3 +MLINKS+= archive_write.3 archive_write_finish.3 +MLINKS+= archive_write.3 archive_write_set_callbacks.3 +MLINKS+= archive_write_disk.3 archive_write_disk_new.3 +MLINKS+= archive_write_disk.3 archive_write_disk_set_options.3 +MLINKS+= archive_write_disk.3 archive_write_disk_set_skip_file.3 +MLINKS+= archive_write_disk.3 archive_write_disk_set_group_lookup.3 +MLINKS+= archive_write_disk.3 archive_write_disk_set_standard_lookup.3 +MLINKS+= archive_write_disk.3 archive_write_disk_set_user_lookup.3 +MLINKS+= libarchive.3 archive.3 + +.include diff --git a/external/bsd/libarchive/lib/libarchive/shlib_version b/external/bsd/libarchive/lib/libarchive/shlib_version new file mode 100644 index 000000000..2a057e08f --- /dev/null +++ b/external/bsd/libarchive/lib/libarchive/shlib_version @@ -0,0 +1,6 @@ +# $NetBSD: shlib_version,v 1.1 2010/02/20 02:55:53 joerg Exp $ +# Remember to update distrib/sets/lists/base/shl.* when changing +# + +major=3 +minor=1 diff --git a/external/bsd/libarchive/lib/libarchive_fe/Makefile b/external/bsd/libarchive/lib/libarchive_fe/Makefile new file mode 100644 index 000000000..93080bb31 --- /dev/null +++ b/external/bsd/libarchive/lib/libarchive_fe/Makefile @@ -0,0 +1,13 @@ +# $NetBSD: Makefile,v 1.1 2010/02/20 02:55:53 joerg Exp $ + +.include + +.PATH: ${LIBARCHIVEDIR}/libarchive_fe + +LIBISPRIVATE= yes + +LIB= archive_fe +SRCS= err.c line_reader.c matching.c pathmatch.c +NOMAN= yes + +.include diff --git a/external/bsd/libarchive/prepare-import.sh b/external/bsd/libarchive/prepare-import.sh new file mode 100644 index 000000000..28e68fd33 --- /dev/null +++ b/external/bsd/libarchive/prepare-import.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# $NetBSD: prepare-import.sh,v 1.2 2010/02/20 02:55:53 joerg Exp $ +# +# Extract the new tarball and rename the libarchive-X.Y.Z directory +# to dist. Run this script and check for additional files and +# directories to prune, only relevant content is included. + +set -e + +mkdir tmp +cd tmp +../dist/configure --without-xml2 --without-expat +mv config.h ../include/config_netbsd.h +cd .. +rm -rf tmp + +cd dist + +rm -rf build contrib doc examples +rm INSTALL Makefile.am Makefile.in aclocal.m4 config.h.in +rm configure configure.ac CMakeLists.txt */CMakeLists.txt */config_freebsd.h + diff --git a/include/sys/extattr.h b/include/sys/extattr.h new file mode 100644 index 000000000..9734b8ecd --- /dev/null +++ b/include/sys/extattr.h @@ -0,0 +1,111 @@ +/* $NetBSD: extattr.h,v 1.7 2011/08/03 04:11:17 manu Exp $ */ + +/*- + * Copyright (c) 1999-2001 Robert N. M. Watson + * All rights reserved. + * + * This software was developed by Robert Watson for the TrustedBSD Project. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * FreeBSD: src/sys/sys/extattr.h,v 1.12 2003/06/04 04:04:24 rwatson Exp + */ + +/* + * Support for file system extended attributes. Originally developed by + * the TrustedBSD Project. For a Linux-compatible interface to the same + * subsystem, see . + */ + +#ifndef _SYS_EXTATTR_H_ +#define _SYS_EXTATTR_H_ + +#include + +#define EXTATTR_NAMESPACE_USER 0x00000001 +#define EXTATTR_NAMESPACE_USER_STRING "user" +#define EXTATTR_NAMESPACE_SYSTEM 0x00000002 +#define EXTATTR_NAMESPACE_SYSTEM_STRING "system" + +/* for sys_extattrctl */ +#define EXTATTR_CMD_START 0x00000001 +#define EXTATTR_CMD_STOP 0x00000002 + +#ifdef _KERNEL + +#include + +/* VOP_LISTEXTATTR flags */ +#define EXTATTR_LIST_LENPREFIX 1 /* names with length prefix */ + +#define EXTATTR_MAXNAMELEN NAME_MAX +struct lwp; +struct vnode; +int extattr_check_cred(struct vnode *, int, kauth_cred_t, + struct lwp *, int); + +#else + +#include +__BEGIN_DECLS +int extattrctl(const char *_path, int _cmd, const char *_filename, + int _attrnamespace, const char *_attrname); + +int extattr_delete_fd(int _fd, int _attrnamespace, const char *_attrname); +int extattr_delete_file(const char *_path, int _attrnamespace, + const char *_attrname); +int extattr_delete_link(const char *_path, int _attrnamespace, + const char *_attrname); +ssize_t extattr_get_fd(int _fd, int _attrnamespace, const char *_attrname, + void *_data, size_t _nbytes); +ssize_t extattr_get_file(const char *_path, int _attrnamespace, + const char *_attrname, void *_data, size_t _nbytes); +ssize_t extattr_get_link(const char *_path, int _attrnamespace, + const char *_attrname, void *_data, size_t _nbytes); +ssize_t extattr_list_fd(int _fd, int _attrnamespace, void *_data, + size_t _nbytes); +ssize_t extattr_list_file(const char *_path, int _attrnamespace, void *_data, + size_t _nbytes); +ssize_t extattr_list_link(const char *_path, int _attrnamespace, void *_data, + size_t _nbytes); +int extattr_set_fd(int _fd, int _attrnamespace, const char *_attrname, + const void *_data, size_t _nbytes); +int extattr_set_file(const char *_path, int _attrnamespace, + const char *_attrname, const void *_data, size_t _nbytes); +int extattr_set_link(const char *_path, int _attrnamespace, + const char *_attrname, const void *_data, size_t _nbytes); + +extern const int extattr_namespaces[]; + +int extattr_namespace_to_string(int, char **); +int extattr_string_to_namespace(const char *, int *); +int extattr_copy_fd(int _from_fd, int _to_fd, int _namespace); +int extattr_copy_file(const char *_from, const char *_to, int _namespace); +int extattr_copy_link(const char *_from, const char *_to, int _namespace); + +int fcpxattr(int _from_fd, int _to_fd); +int cpxattr(const char *_from, const char *_to); +int lcpxattr(const char *_from, const char *_to); +__END_DECLS + +#endif /* !_KERNEL */ +#endif /* !_SYS_EXTATTR_H_ */ diff --git a/lib/Makefile b/lib/Makefile index 83837ccd2..833444d4c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -9,7 +9,7 @@ SUBDIR+= libcompat_minix libc libblockdriver libchardriver \ libl libz libfetch libvtreefs libaudiodriver libmthread \ libexec libdevman libusb libminlib libasyn \ libddekit libminixfs libbdev libelf libminc libcrypt libterminfo \ - libvassert libutil libbz2 libarchive libprop \ + libvassert libutil libbz2 libprop \ libnetsock libpuffs libsffs libhgfs libvboxfs SUBDIR+= ../external/public-domain/xz/lib @@ -17,6 +17,7 @@ SUBDIR+= ../external/public-domain/xz/lib # libraries that follow depend on earlier ones SUBDIR+= .WAIT +SUBDIR+= ../external/bsd/libarchive/lib # depends on libxz SUBDIR+= librefuse SUBDIR+= libcurses diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile deleted file mode 100644 index 8154143f4..000000000 --- a/lib/libarchive/Makefile +++ /dev/null @@ -1,72 +0,0 @@ -LIB= archive -SRCS= archive_check_magic.c \ - archive_entry.c \ - archive_entry_copy_bhfi.c \ - archive_entry_copy_stat.c \ - archive_entry_link_resolver.c \ - archive_entry_stat.c \ - archive_entry_strmode.c \ - archive_entry_xattr.c \ - archive_read.c \ - archive_read_data_into_fd.c \ - archive_read_disk.c \ - archive_read_disk_entry_from_file.c \ - archive_read_disk_set_standard_lookup.c \ - archive_read_extract.c \ - archive_read_open_fd.c \ - archive_read_open_file.c \ - archive_read_open_filename.c \ - archive_read_open_memory.c \ - archive_read_support_compression_all.c \ - archive_read_support_compression_bzip2.c \ - archive_read_support_compression_compress.c \ - archive_read_support_compression_gzip.c \ - archive_read_support_compression_none.c \ - archive_read_support_compression_program.c \ - archive_read_support_compression_uu.c \ - archive_read_support_compression_xz.c \ - archive_read_support_format_all.c \ - archive_read_support_format_ar.c \ - archive_read_support_format_empty.c \ - archive_read_support_format_mtree.c \ - archive_read_support_format_raw.c \ - archive_read_support_format_tar.c \ - archive_read_support_format_xar.c \ - archive_read_support_format_zip.c \ - archive_string.c \ - archive_string_sprintf.c \ - archive_util.c \ - archive_virtual.c \ - archive_write.c \ - archive_write_disk.c \ - archive_write_disk_set_standard_lookup.c \ - archive_write_open_fd.c \ - archive_write_open_file.c \ - archive_write_open_filename.c \ - archive_write_open_memory.c \ - archive_write_set_compression_bzip2.c \ - archive_write_set_compression_compress.c \ - archive_write_set_compression_gzip.c \ - archive_write_set_compression_none.c \ - archive_write_set_compression_program.c \ - archive_write_set_compression_xz.c \ - archive_write_set_format.c \ - archive_write_set_format_ar.c \ - archive_write_set_format_by_name.c \ - archive_write_set_format_mtree.c \ - archive_write_set_format_pax.c \ - archive_write_set_format_shar.c \ - archive_write_set_format_ustar.c \ - archive_write_set_format_zip.c \ - filter_fork.c - -CPPFLAGS+= -DHAVE_CONFIG_H -.if ${NBSD_LIBC} == "yes" -INCSDIR= /usr/include -.else -INCSDIR= /usr/include.ack -.endif -INCS= archive.h \ - archive_entry.h - -.include diff --git a/lib/libarchive/README b/lib/libarchive/README deleted file mode 100644 index cdc8e7346..000000000 --- a/lib/libarchive/README +++ /dev/null @@ -1,24 +0,0 @@ -What's supported, what's not ----------------------------- -This port corresponds to libarchive-2.8.3. The following formats supported -by libarchive are NOT supported in the port: -1) iso9660 -2) various variants of cpio - -In addition though xz and lzma are included, due to the lack of -liblzma and xz utilities on Minix they are of not much use. Of the remaining -formats I know that tar and its variants (tar.gz, tar.bz2 etc) work. - -Notes on the port ------------------ -The cause for all changes is the fact that ACK does not have a 64 bit types. -Most of the changes are 'downsizing' of types from 64 bits to 32 bits. -Also a signed type is used for the measuring sizes so nothing > 2GB will work. - -Most of the changes are repetitive and can be classified into two types: - -1) Changing sizes/offsets/timestamps from 64bit types to size_t, ssize_t, off_t - time_t -2) Changing functions that either decode or encode sizes/offsets/timestamps - from or to archives to use 32 bit types. - diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk index cac9f2290..415982260 100644 --- a/share/mk/bsd.own.mk +++ b/share/mk/bsd.own.mk @@ -788,7 +788,7 @@ _MKVARS.no= \ MKMANDOC MKMANZ MKOBJDIRS \ MKPCC MKPCCCMDS \ MKSOFTFLOAT MKSTRIPIDENT \ - MKUNPRIVED MKUPDATE MKX11 MKZFS + MKUNPRIVED MKUPDATE MKX11 MKZFS MKBSDTAR #MINIX-specific vars _MKVARS.no+= \ MKIMAGEONLY MKSMALL diff --git a/tools/nbsd_ports b/tools/nbsd_ports index eb6bb6871..277c54cdf 100644 --- a/tools/nbsd_ports +++ b/tools/nbsd_ports @@ -2,6 +2,7 @@ # Timestamp in UTC,minixpath,netbsdpath # minixpath: path in Minix source tree (starting from /usr/src/) # netbsdpath: path in BSD source tree (starting from src/) +2012/05/01 16:16:12,external/bsd/libarchive 2012/02/10 16:16:12,usr.sbin/chroot 2011/01/17 18:11:10,usr.bin/ldd 2011/01/17 18:11:10,external/bsd/file -- 2.44.0