HardenedBSD src tree
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.0KB

  1. /*-
  2. * Copyright (c) 2019 Martin Matuska
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "test.h"
  26. __FBSDID("$FreeBSD$");
  27. static struct archive_entry*
  28. create_archive_entry(void) {
  29. struct archive_entry *ae;
  30. assert((ae = archive_entry_new()) != NULL);
  31. archive_entry_set_atime(ae, 2, 20);
  32. archive_entry_set_ctime(ae, 4, 40);
  33. archive_entry_set_mtime(ae, 5, 50);
  34. archive_entry_copy_pathname(ae, "file");
  35. archive_entry_set_mode(ae, AE_IFREG | 0755);
  36. archive_entry_set_nlink(ae, 2);
  37. archive_entry_set_size(ae, 8);
  38. archive_entry_xattr_add_entry(ae, "user.data1", "ABCDEFG", 7);
  39. archive_entry_xattr_add_entry(ae, "user.data2", "XYZ", 3);
  40. return (ae);
  41. }
  42. DEFINE_TEST(test_pax_xattr_header)
  43. {
  44. static const char *reffiles[] = {
  45. "test_pax_xattr_header_all.tar",
  46. "test_pax_xattr_header_libarchive.tar",
  47. "test_pax_xattr_header_schily.tar",
  48. NULL
  49. };
  50. struct archive *a;
  51. struct archive_entry *ae;
  52. extract_reference_files(reffiles);
  53. /* First archive, no options */
  54. assert((a = archive_write_new()) != NULL);
  55. assertEqualIntA(a, 0, archive_write_set_format_pax(a));
  56. assertEqualIntA(a, 0, archive_write_add_filter_none(a));
  57. assertEqualInt(0,
  58. archive_write_open_filename(a, "test1.tar"));
  59. ae = create_archive_entry();
  60. assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
  61. archive_entry_free(ae);
  62. assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9));
  63. assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
  64. assertEqualIntA(a, ARCHIVE_OK, archive_write_free(a));
  65. assertEqualFile("test1.tar","test_pax_xattr_header_all.tar");
  66. /* Second archive, xattrheader=SCHILY */
  67. assert((a = archive_write_new()) != NULL);
  68. assertEqualIntA(a, 0, archive_write_set_format_pax(a));
  69. assertEqualIntA(a, 0, archive_write_add_filter_none(a));
  70. assertEqualIntA(a, 0, archive_write_set_options(a,
  71. "xattrheader=SCHILY"));
  72. assertEqualInt(0,
  73. archive_write_open_filename(a, "test2.tar"));
  74. ae = create_archive_entry();
  75. assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
  76. archive_entry_free(ae);
  77. assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9));
  78. assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
  79. assertEqualIntA(a, ARCHIVE_OK, archive_write_free(a));
  80. assertEqualFile("test2.tar","test_pax_xattr_header_schily.tar");
  81. /* Third archive, xattrheader=LIBARCHIVE */
  82. assert((a = archive_write_new()) != NULL);
  83. assertEqualIntA(a, 0, archive_write_set_format_pax(a));
  84. assertEqualIntA(a, 0, archive_write_add_filter_none(a));
  85. assertEqualIntA(a, 0, archive_write_set_options(a,
  86. "xattrheader=LIBARCHIVE"));
  87. assertEqualInt(0,
  88. archive_write_open_filename(a, "test3.tar"));
  89. ae = create_archive_entry();
  90. assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
  91. archive_entry_free(ae);
  92. assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9));
  93. assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
  94. assertEqualIntA(a, ARCHIVE_OK, archive_write_free(a));
  95. assertEqualFile("test3.tar","test_pax_xattr_header_libarchive.tar");
  96. /* Fourth archive, xattrheader=ALL */
  97. assert((a = archive_write_new()) != NULL);
  98. assertEqualIntA(a, 0, archive_write_set_format_pax(a));
  99. assertEqualIntA(a, 0, archive_write_add_filter_none(a));
  100. assertEqualIntA(a, 0, archive_write_set_options(a, "xattrheader=ALL"));
  101. assertEqualInt(0,
  102. archive_write_open_filename(a, "test4.tar"));
  103. ae = create_archive_entry();
  104. assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
  105. archive_entry_free(ae);
  106. assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9));
  107. assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
  108. assertEqualIntA(a, ARCHIVE_OK, archive_write_free(a));
  109. assertEqualFile("test4.tar","test_pax_xattr_header_all.tar");
  110. }