@papyrus-sdk/engine-native 0.2.22-beta.9.epub.1 → 0.2.22-beta.9.epub.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/android/build.gradle +0 -1
  2. package/android/src/main/cpp/CMakeLists.txt +0 -137
  3. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +35 -305
  4. package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +1 -3
  5. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +5 -195
  6. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +1 -20
  7. package/dist/index.d.mts +4 -614
  8. package/dist/index.d.ts +4 -614
  9. package/dist/index.js +8 -484
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +7 -477
  12. package/dist/index.mjs.map +1 -1
  13. package/ios/PapyrusEngineStore.h +0 -3
  14. package/ios/PapyrusEngineStore.m +6 -32
  15. package/ios/PapyrusNativeEngine.m +5 -684
  16. package/ios/PapyrusNativeEngine.podspec +15 -0
  17. package/ios/PapyrusPageView.m +11 -38
  18. package/package.json +8 -10
  19. package/react-native.config.js +1 -1
  20. package/PapyrusNativeEngine.podspec +0 -45
  21. package/android/src/main/cpp/PapyrusComicArchiveJni.cpp +0 -68
  22. package/android/src/main/cpp/PapyrusComicArchiveTest.cpp +0 -55
  23. package/android/src/main/cpp/papyrus_outline_loader_test.cpp +0 -240
  24. package/android/src/main/cpp/papyrus_text_word_test.cpp +0 -72
  25. package/android/src/main/java/com/papyrus/engine/PapyrusComicArchiveNative.java +0 -14
  26. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +0 -491
  27. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentViewManager.java +0 -32
  28. package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +0 -38
  29. package/android/src/main/java/com/papyrus/engine/PapyrusNativeTextModel.java +0 -195
  30. package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +0 -48
  31. package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +0 -22
  32. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +0 -661
  33. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +0 -49
  34. package/android/src/main/java/com/papyrus/engine/PapyrusTextStore.java +0 -43
  35. package/ios/PapyrusComicDocumentView.h +0 -21
  36. package/ios/PapyrusComicDocumentView.m +0 -554
  37. package/ios/PapyrusComicDocumentViewManager.m +0 -23
  38. package/ios/PapyrusPageRotationRegistry.h +0 -29
  39. package/ios/PapyrusPageRotationRegistry.m +0 -179
  40. package/ios/PapyrusPdfDocumentView.h +0 -55
  41. package/ios/PapyrusPdfDocumentView.m +0 -2339
  42. package/ios/PapyrusPdfDocumentViewManager.m +0 -61
  43. package/ios/PapyrusPdfPageTheme.h +0 -15
  44. package/ios/PapyrusPdfPageTheme.m +0 -218
  45. package/ios/PapyrusSelectionMenu.h +0 -27
  46. package/ios/PapyrusTextAnnotationRange.h +0 -2
  47. package/ios/PapyrusTextAnnotationRange.m +0 -29
  48. package/ios/PapyrusTextDocumentView.h +0 -32
  49. package/ios/PapyrusTextDocumentView.m +0 -518
  50. package/ios/PapyrusTextDocumentViewManager.m +0 -34
  51. package/ios/PapyrusTextStore.h +0 -13
  52. package/ios/PapyrusTextStore.m +0 -73
  53. package/third_party_licenses/BLAKE2-NOTICE.txt +0 -11
  54. package/third_party_licenses/libarchive-COPYING +0 -65
  55. package/vendor/libarchive/PapyrusComicArchive.cpp +0 -376
  56. package/vendor/libarchive/PapyrusComicArchive.h +0 -30
  57. package/vendor/libarchive/README.papyrus.md +0 -15
  58. package/vendor/libarchive/android.h +0 -192
  59. package/vendor/libarchive/config/PapyrusArchiveConfig.h +0 -71
  60. package/vendor/libarchive/libarchive/CMakeLists.txt +0 -293
  61. package/vendor/libarchive/libarchive/android_lf.h +0 -36
  62. package/vendor/libarchive/libarchive/archive.h +0 -1266
  63. package/vendor/libarchive/libarchive/archive_acl.c +0 -2025
  64. package/vendor/libarchive/libarchive/archive_acl_private.h +0 -85
  65. package/vendor/libarchive/libarchive/archive_blake2.h +0 -197
  66. package/vendor/libarchive/libarchive/archive_blake2_impl.h +0 -161
  67. package/vendor/libarchive/libarchive/archive_blake2s_ref.c +0 -369
  68. package/vendor/libarchive/libarchive/archive_blake2sp_ref.c +0 -361
  69. package/vendor/libarchive/libarchive/archive_check_magic.c +0 -183
  70. package/vendor/libarchive/libarchive/archive_cmdline.c +0 -211
  71. package/vendor/libarchive/libarchive/archive_cmdline_private.h +0 -45
  72. package/vendor/libarchive/libarchive/archive_crc32.h +0 -123
  73. package/vendor/libarchive/libarchive/archive_cryptor.c +0 -534
  74. package/vendor/libarchive/libarchive/archive_cryptor_private.h +0 -199
  75. package/vendor/libarchive/libarchive/archive_digest.c +0 -1584
  76. package/vendor/libarchive/libarchive/archive_digest_private.h +0 -431
  77. package/vendor/libarchive/libarchive/archive_disk_acl_darwin.c +0 -558
  78. package/vendor/libarchive/libarchive/archive_disk_acl_freebsd.c +0 -712
  79. package/vendor/libarchive/libarchive/archive_disk_acl_linux.c +0 -760
  80. package/vendor/libarchive/libarchive/archive_disk_acl_sunos.c +0 -824
  81. package/vendor/libarchive/libarchive/archive_endian.h +0 -234
  82. package/vendor/libarchive/libarchive/archive_entry.3 +0 -147
  83. package/vendor/libarchive/libarchive/archive_entry.c +0 -2297
  84. package/vendor/libarchive/libarchive/archive_entry.h +0 -763
  85. package/vendor/libarchive/libarchive/archive_entry_acl.3 +0 -458
  86. package/vendor/libarchive/libarchive/archive_entry_copy_bhfi.c +0 -55
  87. package/vendor/libarchive/libarchive/archive_entry_copy_stat.c +0 -82
  88. package/vendor/libarchive/libarchive/archive_entry_link_resolver.c +0 -472
  89. package/vendor/libarchive/libarchive/archive_entry_linkify.3 +0 -224
  90. package/vendor/libarchive/libarchive/archive_entry_locale.h +0 -90
  91. package/vendor/libarchive/libarchive/archive_entry_misc.3 +0 -63
  92. package/vendor/libarchive/libarchive/archive_entry_paths.3 +0 -153
  93. package/vendor/libarchive/libarchive/archive_entry_perms.3 +0 -210
  94. package/vendor/libarchive/libarchive/archive_entry_private.h +0 -205
  95. package/vendor/libarchive/libarchive/archive_entry_sparse.c +0 -156
  96. package/vendor/libarchive/libarchive/archive_entry_stat.3 +0 -274
  97. package/vendor/libarchive/libarchive/archive_entry_stat.c +0 -121
  98. package/vendor/libarchive/libarchive/archive_entry_strmode.c +0 -69
  99. package/vendor/libarchive/libarchive/archive_entry_time.3 +0 -127
  100. package/vendor/libarchive/libarchive/archive_entry_xattr.c +0 -155
  101. package/vendor/libarchive/libarchive/archive_hmac.c +0 -345
  102. package/vendor/libarchive/libarchive/archive_hmac_private.h +0 -119
  103. package/vendor/libarchive/libarchive/archive_integer.h +0 -267
  104. package/vendor/libarchive/libarchive/archive_match.c +0 -1869
  105. package/vendor/libarchive/libarchive/archive_openssl_evp_private.h +0 -54
  106. package/vendor/libarchive/libarchive/archive_openssl_hmac_private.h +0 -54
  107. package/vendor/libarchive/libarchive/archive_options.c +0 -219
  108. package/vendor/libarchive/libarchive/archive_options_private.h +0 -49
  109. package/vendor/libarchive/libarchive/archive_pack_dev.c +0 -330
  110. package/vendor/libarchive/libarchive/archive_pack_dev.h +0 -49
  111. package/vendor/libarchive/libarchive/archive_parse_date.c +0 -1173
  112. package/vendor/libarchive/libarchive/archive_pathmatch.c +0 -480
  113. package/vendor/libarchive/libarchive/archive_pathmatch.h +0 -50
  114. package/vendor/libarchive/libarchive/archive_platform.h +0 -213
  115. package/vendor/libarchive/libarchive/archive_platform_acl.h +0 -53
  116. package/vendor/libarchive/libarchive/archive_platform_stat.h +0 -45
  117. package/vendor/libarchive/libarchive/archive_platform_xattr.h +0 -45
  118. package/vendor/libarchive/libarchive/archive_ppmd7.c +0 -1173
  119. package/vendor/libarchive/libarchive/archive_ppmd7_private.h +0 -119
  120. package/vendor/libarchive/libarchive/archive_ppmd8.c +0 -1293
  121. package/vendor/libarchive/libarchive/archive_ppmd8_private.h +0 -123
  122. package/vendor/libarchive/libarchive/archive_ppmd_private.h +0 -159
  123. package/vendor/libarchive/libarchive/archive_private.h +0 -209
  124. package/vendor/libarchive/libarchive/archive_random.c +0 -274
  125. package/vendor/libarchive/libarchive/archive_random_private.h +0 -36
  126. package/vendor/libarchive/libarchive/archive_rb.c +0 -709
  127. package/vendor/libarchive/libarchive/archive_rb.h +0 -113
  128. package/vendor/libarchive/libarchive/archive_read.3 +0 -250
  129. package/vendor/libarchive/libarchive/archive_read.c +0 -1814
  130. package/vendor/libarchive/libarchive/archive_read_add_passphrase.3 +0 -72
  131. package/vendor/libarchive/libarchive/archive_read_add_passphrase.c +0 -189
  132. package/vendor/libarchive/libarchive/archive_read_append_filter.c +0 -209
  133. package/vendor/libarchive/libarchive/archive_read_data.3 +0 -128
  134. package/vendor/libarchive/libarchive/archive_read_data_into_fd.c +0 -207
  135. package/vendor/libarchive/libarchive/archive_read_disk.3 +0 -422
  136. package/vendor/libarchive/libarchive/archive_read_disk_entry_from_file.c +0 -1086
  137. package/vendor/libarchive/libarchive/archive_read_disk_posix.c +0 -2639
  138. package/vendor/libarchive/libarchive/archive_read_disk_private.h +0 -97
  139. package/vendor/libarchive/libarchive/archive_read_disk_set_standard_lookup.c +0 -315
  140. package/vendor/libarchive/libarchive/archive_read_disk_windows.c +0 -2603
  141. package/vendor/libarchive/libarchive/archive_read_extract.3 +0 -135
  142. package/vendor/libarchive/libarchive/archive_read_extract.c +0 -59
  143. package/vendor/libarchive/libarchive/archive_read_extract2.c +0 -154
  144. package/vendor/libarchive/libarchive/archive_read_filter.3 +0 -163
  145. package/vendor/libarchive/libarchive/archive_read_format.3 +0 -190
  146. package/vendor/libarchive/libarchive/archive_read_free.3 +0 -91
  147. package/vendor/libarchive/libarchive/archive_read_header.3 +0 -89
  148. package/vendor/libarchive/libarchive/archive_read_new.3 +0 -57
  149. package/vendor/libarchive/libarchive/archive_read_open.3 +0 -247
  150. package/vendor/libarchive/libarchive/archive_read_open_fd.c +0 -236
  151. package/vendor/libarchive/libarchive/archive_read_open_file.c +0 -257
  152. package/vendor/libarchive/libarchive/archive_read_open_filename.c +0 -652
  153. package/vendor/libarchive/libarchive/archive_read_open_memory.c +0 -188
  154. package/vendor/libarchive/libarchive/archive_read_private.h +0 -274
  155. package/vendor/libarchive/libarchive/archive_read_set_format.c +0 -116
  156. package/vendor/libarchive/libarchive/archive_read_set_options.3 +0 -290
  157. package/vendor/libarchive/libarchive/archive_read_set_options.c +0 -132
  158. package/vendor/libarchive/libarchive/archive_read_support_filter_all.c +0 -84
  159. package/vendor/libarchive/libarchive/archive_read_support_filter_by_code.c +0 -68
  160. package/vendor/libarchive/libarchive/archive_read_support_filter_bzip2.c +0 -360
  161. package/vendor/libarchive/libarchive/archive_read_support_filter_compress.c +0 -457
  162. package/vendor/libarchive/libarchive/archive_read_support_filter_grzip.c +0 -108
  163. package/vendor/libarchive/libarchive/archive_read_support_filter_gzip.c +0 -538
  164. package/vendor/libarchive/libarchive/archive_read_support_filter_lrzip.c +0 -119
  165. package/vendor/libarchive/libarchive/archive_read_support_filter_lz4.c +0 -829
  166. package/vendor/libarchive/libarchive/archive_read_support_filter_lzop.c +0 -493
  167. package/vendor/libarchive/libarchive/archive_read_support_filter_none.c +0 -51
  168. package/vendor/libarchive/libarchive/archive_read_support_filter_program.c +0 -497
  169. package/vendor/libarchive/libarchive/archive_read_support_filter_rpm.c +0 -249
  170. package/vendor/libarchive/libarchive/archive_read_support_filter_uu.c +0 -739
  171. package/vendor/libarchive/libarchive/archive_read_support_filter_xz.c +0 -792
  172. package/vendor/libarchive/libarchive/archive_read_support_filter_zstd.c +0 -356
  173. package/vendor/libarchive/libarchive/archive_read_support_format_7zip.c +0 -4650
  174. package/vendor/libarchive/libarchive/archive_read_support_format_all.c +0 -88
  175. package/vendor/libarchive/libarchive/archive_read_support_format_ar.c +0 -597
  176. package/vendor/libarchive/libarchive/archive_read_support_format_by_code.c +0 -76
  177. package/vendor/libarchive/libarchive/archive_read_support_format_cab.c +0 -3410
  178. package/vendor/libarchive/libarchive/archive_read_support_format_cpio.c +0 -1152
  179. package/vendor/libarchive/libarchive/archive_read_support_format_empty.c +0 -95
  180. package/vendor/libarchive/libarchive/archive_read_support_format_iso9660.c +0 -3516
  181. package/vendor/libarchive/libarchive/archive_read_support_format_lha.c +0 -2931
  182. package/vendor/libarchive/libarchive/archive_read_support_format_mtree.c +0 -2113
  183. package/vendor/libarchive/libarchive/archive_read_support_format_rar.c +0 -3932
  184. package/vendor/libarchive/libarchive/archive_read_support_format_rar5.c +0 -4501
  185. package/vendor/libarchive/libarchive/archive_read_support_format_raw.c +0 -194
  186. package/vendor/libarchive/libarchive/archive_read_support_format_tar.c +0 -3785
  187. package/vendor/libarchive/libarchive/archive_read_support_format_warc.c +0 -875
  188. package/vendor/libarchive/libarchive/archive_read_support_format_xar.c +0 -3770
  189. package/vendor/libarchive/libarchive/archive_read_support_format_zip.c +0 -4710
  190. package/vendor/libarchive/libarchive/archive_string.c +0 -4391
  191. package/vendor/libarchive/libarchive/archive_string.h +0 -244
  192. package/vendor/libarchive/libarchive/archive_string_composition.h +0 -2289
  193. package/vendor/libarchive/libarchive/archive_string_sprintf.c +0 -200
  194. package/vendor/libarchive/libarchive/archive_time.c +0 -168
  195. package/vendor/libarchive/libarchive/archive_time_private.h +0 -47
  196. package/vendor/libarchive/libarchive/archive_util.3 +0 -239
  197. package/vendor/libarchive/libarchive/archive_util.c +0 -668
  198. package/vendor/libarchive/libarchive/archive_version_details.c +0 -516
  199. package/vendor/libarchive/libarchive/archive_virtual.c +0 -162
  200. package/vendor/libarchive/libarchive/archive_windows.c +0 -1035
  201. package/vendor/libarchive/libarchive/archive_windows.h +0 -332
  202. package/vendor/libarchive/libarchive/archive_write.3 +0 -266
  203. package/vendor/libarchive/libarchive/archive_write.c +0 -896
  204. package/vendor/libarchive/libarchive/archive_write_add_filter.c +0 -71
  205. package/vendor/libarchive/libarchive/archive_write_add_filter_b64encode.c +0 -329
  206. package/vendor/libarchive/libarchive/archive_write_add_filter_by_name.c +0 -76
  207. package/vendor/libarchive/libarchive/archive_write_add_filter_bzip2.c +0 -411
  208. package/vendor/libarchive/libarchive/archive_write_add_filter_compress.c +0 -459
  209. package/vendor/libarchive/libarchive/archive_write_add_filter_grzip.c +0 -143
  210. package/vendor/libarchive/libarchive/archive_write_add_filter_gzip.c +0 -493
  211. package/vendor/libarchive/libarchive/archive_write_add_filter_lrzip.c +0 -214
  212. package/vendor/libarchive/libarchive/archive_write_add_filter_lz4.c +0 -710
  213. package/vendor/libarchive/libarchive/archive_write_add_filter_lzop.c +0 -500
  214. package/vendor/libarchive/libarchive/archive_write_add_filter_none.c +0 -42
  215. package/vendor/libarchive/libarchive/archive_write_add_filter_program.c +0 -398
  216. package/vendor/libarchive/libarchive/archive_write_add_filter_uuencode.c +0 -320
  217. package/vendor/libarchive/libarchive/archive_write_add_filter_xz.c +0 -547
  218. package/vendor/libarchive/libarchive/archive_write_add_filter_zstd.c +0 -608
  219. package/vendor/libarchive/libarchive/archive_write_blocksize.3 +0 -112
  220. package/vendor/libarchive/libarchive/archive_write_data.3 +0 -88
  221. package/vendor/libarchive/libarchive/archive_write_disk.3 +0 -360
  222. package/vendor/libarchive/libarchive/archive_write_disk_posix.c +0 -4789
  223. package/vendor/libarchive/libarchive/archive_write_disk_private.h +0 -43
  224. package/vendor/libarchive/libarchive/archive_write_disk_set_standard_lookup.c +0 -265
  225. package/vendor/libarchive/libarchive/archive_write_disk_windows.c +0 -2952
  226. package/vendor/libarchive/libarchive/archive_write_filter.3 +0 -140
  227. package/vendor/libarchive/libarchive/archive_write_finish_entry.3 +0 -77
  228. package/vendor/libarchive/libarchive/archive_write_format.3 +0 -187
  229. package/vendor/libarchive/libarchive/archive_write_free.3 +0 -94
  230. package/vendor/libarchive/libarchive/archive_write_header.3 +0 -71
  231. package/vendor/libarchive/libarchive/archive_write_new.3 +0 -56
  232. package/vendor/libarchive/libarchive/archive_write_open.3 +0 -270
  233. package/vendor/libarchive/libarchive/archive_write_open_fd.c +0 -141
  234. package/vendor/libarchive/libarchive/archive_write_open_file.c +0 -102
  235. package/vendor/libarchive/libarchive/archive_write_open_filename.c +0 -272
  236. package/vendor/libarchive/libarchive/archive_write_open_memory.c +0 -110
  237. package/vendor/libarchive/libarchive/archive_write_private.h +0 -166
  238. package/vendor/libarchive/libarchive/archive_write_set_format.c +0 -124
  239. package/vendor/libarchive/libarchive/archive_write_set_format_7zip.c +0 -2571
  240. package/vendor/libarchive/libarchive/archive_write_set_format_ar.c +0 -540
  241. package/vendor/libarchive/libarchive/archive_write_set_format_by_name.c +0 -93
  242. package/vendor/libarchive/libarchive/archive_write_set_format_cpio.c +0 -11
  243. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_binary.c +0 -618
  244. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_newc.c +0 -457
  245. package/vendor/libarchive/libarchive/archive_write_set_format_cpio_odc.c +0 -508
  246. package/vendor/libarchive/libarchive/archive_write_set_format_filter_by_ext.c +0 -141
  247. package/vendor/libarchive/libarchive/archive_write_set_format_gnutar.c +0 -790
  248. package/vendor/libarchive/libarchive/archive_write_set_format_iso9660.c +0 -8216
  249. package/vendor/libarchive/libarchive/archive_write_set_format_mtree.c +0 -2307
  250. package/vendor/libarchive/libarchive/archive_write_set_format_pax.c +0 -2249
  251. package/vendor/libarchive/libarchive/archive_write_set_format_private.h +0 -40
  252. package/vendor/libarchive/libarchive/archive_write_set_format_raw.c +0 -123
  253. package/vendor/libarchive/libarchive/archive_write_set_format_shar.c +0 -650
  254. package/vendor/libarchive/libarchive/archive_write_set_format_ustar.c +0 -768
  255. package/vendor/libarchive/libarchive/archive_write_set_format_v7tar.c +0 -648
  256. package/vendor/libarchive/libarchive/archive_write_set_format_warc.c +0 -491
  257. package/vendor/libarchive/libarchive/archive_write_set_format_xar.c +0 -3799
  258. package/vendor/libarchive/libarchive/archive_write_set_format_zip.c +0 -2548
  259. package/vendor/libarchive/libarchive/archive_write_set_options.3 +0 -779
  260. package/vendor/libarchive/libarchive/archive_write_set_options.c +0 -129
  261. package/vendor/libarchive/libarchive/archive_write_set_passphrase.3 +0 -72
  262. package/vendor/libarchive/libarchive/archive_write_set_passphrase.c +0 -95
  263. package/vendor/libarchive/libarchive/archive_xxhash.h +0 -48
  264. package/vendor/libarchive/libarchive/config_freebsd.h +0 -275
  265. package/vendor/libarchive/libarchive/cpio.5 +0 -389
  266. package/vendor/libarchive/libarchive/filter_fork.h +0 -44
  267. package/vendor/libarchive/libarchive/filter_fork_posix.c +0 -269
  268. package/vendor/libarchive/libarchive/filter_fork_windows.c +0 -270
  269. package/vendor/libarchive/libarchive/libarchive-formats.5 +0 -478
  270. package/vendor/libarchive/libarchive/libarchive.3 +0 -297
  271. package/vendor/libarchive/libarchive/libarchive_changes.3 +0 -339
  272. package/vendor/libarchive/libarchive/libarchive_internals.3 +0 -363
  273. package/vendor/libarchive/libarchive/module.modulemap +0 -34
  274. package/vendor/libarchive/libarchive/mtree.5 +0 -323
  275. package/vendor/libarchive/libarchive/tar.5 +0 -947
  276. package/vendor/libarchive/libarchive/xxhash.c +0 -531
@@ -1,2025 +0,0 @@
1
- /*-
2
- * Copyright (c) 2003-2010 Tim Kientzle
3
- * Copyright (c) 2016 Martin Matuska
4
- * All rights reserved.
5
- *
6
- * Redistribution and use in source and binary forms, with or without
7
- * modification, are permitted provided that the following conditions
8
- * are met:
9
- * 1. Redistributions of source code must retain the above copyright
10
- * notice, this list of conditions and the following disclaimer.
11
- * 2. Redistributions in binary form must reproduce the above copyright
12
- * notice, this list of conditions and the following disclaimer in the
13
- * documentation and/or other materials provided with the distribution.
14
- *
15
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
- * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
- */
26
-
27
- #include "archive_platform.h"
28
-
29
- #ifdef HAVE_ERRNO_H
30
- #include <errno.h>
31
- #endif
32
- #ifdef HAVE_LIMITS_H
33
- #include <limits.h>
34
- #endif
35
- #ifdef HAVE_WCHAR_H
36
- #include <wchar.h>
37
- #endif
38
-
39
- #include "archive_acl_private.h"
40
- #include "archive_entry.h"
41
- #include "archive_private.h"
42
-
43
- #undef max
44
- #define max(a, b) ((a)>(b)?(a):(b))
45
-
46
- #ifndef HAVE_WMEMCMP
47
- /* Good enough for simple equality testing, but not for sorting. */
48
- #define wmemcmp(a,b,i) memcmp((a), (b), (i) * sizeof(wchar_t))
49
- #endif
50
-
51
- static int acl_special(struct archive_acl *acl,
52
- int type, int permset, int tag);
53
- static struct archive_acl_entry *acl_new_entry(struct archive_acl *acl,
54
- int type, int permset, int tag, int id);
55
- static int archive_acl_add_entry_len_l(struct archive_acl *acl,
56
- int type, int permset, int tag, int id, const char *name,
57
- size_t len, struct archive_string_conv *sc);
58
- static int archive_acl_text_want_type(struct archive_acl *acl, int flags);
59
- static size_t archive_acl_text_empty(struct archive_acl *acl, int want_type);
60
- static int isint_w(const wchar_t *start, const wchar_t *end, int *result);
61
- static int ismode_w(const wchar_t *start, const wchar_t *end, int *result);
62
- static int is_nfs4_flags_w(const wchar_t *start, const wchar_t *end,
63
- int *result);
64
- static int is_nfs4_perms_w(const wchar_t *start, const wchar_t *end,
65
- int *result);
66
- static void next_field_w(const wchar_t **wp, const wchar_t **start,
67
- const wchar_t **end, wchar_t *sep);
68
- static void append_entry_w(struct archive_wstring *ws, const wchar_t *prefix, int type,
69
- int tag, int flags, const wchar_t *wname, int perm, int id);
70
- static void append_id_w(struct archive_wstring *ws, int id);
71
- static int isint(const char *start, const char *end, int *result);
72
- static int ismode(const char *start, const char *end, int *result);
73
- static int is_nfs4_flags(const char *start, const char *end,
74
- int *result);
75
- static int is_nfs4_perms(const char *start, const char *end,
76
- int *result);
77
- static void next_field(const char **p, size_t *l, const char **start,
78
- const char **end, char *sep);
79
- static void append_entry(struct archive_string *s, const char *prefix, int type,
80
- int tag, int flags, const char *name, int perm, int id);
81
- static void append_id(struct archive_string *s, int id);
82
-
83
- static const struct {
84
- const int perm;
85
- const char c;
86
- const wchar_t wc;
87
- } nfsv4_acl_perm_map[] = {
88
- { ARCHIVE_ENTRY_ACL_READ_DATA | ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, 'r',
89
- L'r' },
90
- { ARCHIVE_ENTRY_ACL_WRITE_DATA | ARCHIVE_ENTRY_ACL_ADD_FILE, 'w',
91
- L'w' },
92
- { ARCHIVE_ENTRY_ACL_EXECUTE, 'x', L'x' },
93
- { ARCHIVE_ENTRY_ACL_APPEND_DATA | ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY,
94
- 'p', L'p' },
95
- { ARCHIVE_ENTRY_ACL_DELETE, 'd', L'd' },
96
- { ARCHIVE_ENTRY_ACL_DELETE_CHILD, 'D', L'D' },
97
- { ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, 'a', L'a' },
98
- { ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, 'A', L'A' },
99
- { ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, 'R', L'R' },
100
- { ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, 'W', L'W' },
101
- { ARCHIVE_ENTRY_ACL_READ_ACL, 'c', L'c' },
102
- { ARCHIVE_ENTRY_ACL_WRITE_ACL, 'C', L'C' },
103
- { ARCHIVE_ENTRY_ACL_WRITE_OWNER, 'o', L'o' },
104
- { ARCHIVE_ENTRY_ACL_SYNCHRONIZE, 's', L's' }
105
- };
106
-
107
- static const int nfsv4_acl_perm_map_size = (int)(sizeof(nfsv4_acl_perm_map) /
108
- sizeof(nfsv4_acl_perm_map[0]));
109
-
110
- static const struct {
111
- const int perm;
112
- const char c;
113
- const wchar_t wc;
114
- } nfsv4_acl_flag_map[] = {
115
- { ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, 'f', L'f' },
116
- { ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, 'd', L'd' },
117
- { ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, 'i', L'i' },
118
- { ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, 'n', L'n' },
119
- { ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, 'S', L'S' },
120
- { ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, 'F', L'F' },
121
- { ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, 'I', L'I' }
122
- };
123
-
124
- static const int nfsv4_acl_flag_map_size = (int)(sizeof(nfsv4_acl_flag_map) /
125
- sizeof(nfsv4_acl_flag_map[0]));
126
-
127
- void
128
- archive_acl_clear(struct archive_acl *acl)
129
- {
130
- struct archive_acl_entry *ap;
131
-
132
- while (acl->acl_head != NULL) {
133
- ap = acl->acl_head->next;
134
- archive_mstring_clean(&acl->acl_head->name);
135
- free(acl->acl_head);
136
- acl->acl_head = ap;
137
- }
138
- free(acl->acl_text_w);
139
- acl->acl_text_w = NULL;
140
- free(acl->acl_text);
141
- acl->acl_text = NULL;
142
- acl->acl_p = NULL;
143
- acl->acl_types = 0;
144
- acl->acl_state = 0; /* Not counting. */
145
- }
146
-
147
- void
148
- archive_acl_copy(struct archive_acl *dest, struct archive_acl *src)
149
- {
150
- struct archive_acl_entry *ap, *ap2;
151
-
152
- archive_acl_clear(dest);
153
-
154
- dest->mode = src->mode;
155
- ap = src->acl_head;
156
- while (ap != NULL) {
157
- ap2 = acl_new_entry(dest,
158
- ap->type, ap->permset, ap->tag, ap->id);
159
- if (ap2 != NULL)
160
- archive_mstring_copy(&ap2->name, &ap->name);
161
- ap = ap->next;
162
- }
163
- }
164
-
165
- int
166
- archive_acl_add_entry(struct archive_acl *acl,
167
- int type, int permset, int tag, int id, const char *name)
168
- {
169
- struct archive_acl_entry *ap;
170
-
171
- if (acl_special(acl, type, permset, tag) == 0)
172
- return ARCHIVE_OK;
173
- ap = acl_new_entry(acl, type, permset, tag, id);
174
- if (ap == NULL) {
175
- /* XXX Error XXX */
176
- return ARCHIVE_FAILED;
177
- }
178
- if (name != NULL && *name != '\0')
179
- archive_mstring_copy_mbs(&ap->name, name);
180
- else
181
- archive_mstring_clean(&ap->name);
182
- return ARCHIVE_OK;
183
- }
184
-
185
- int
186
- archive_acl_add_entry_w_len(struct archive_acl *acl,
187
- int type, int permset, int tag, int id, const wchar_t *name, size_t len)
188
- {
189
- struct archive_acl_entry *ap;
190
-
191
- if (acl_special(acl, type, permset, tag) == 0)
192
- return ARCHIVE_OK;
193
- ap = acl_new_entry(acl, type, permset, tag, id);
194
- if (ap == NULL) {
195
- /* XXX Error XXX */
196
- return ARCHIVE_FAILED;
197
- }
198
- if (name != NULL && *name != L'\0' && len > 0)
199
- archive_mstring_copy_wcs_len(&ap->name, name, len);
200
- else
201
- archive_mstring_clean(&ap->name);
202
- return ARCHIVE_OK;
203
- }
204
-
205
- static int
206
- archive_acl_add_entry_len_l(struct archive_acl *acl,
207
- int type, int permset, int tag, int id, const char *name, size_t len,
208
- struct archive_string_conv *sc)
209
- {
210
- struct archive_acl_entry *ap;
211
- int r;
212
-
213
- if (acl_special(acl, type, permset, tag) == 0)
214
- return ARCHIVE_OK;
215
- ap = acl_new_entry(acl, type, permset, tag, id);
216
- if (ap == NULL) {
217
- /* XXX Error XXX */
218
- return ARCHIVE_FAILED;
219
- }
220
- if (name != NULL && *name != '\0' && len > 0) {
221
- r = archive_mstring_copy_mbs_len_l(&ap->name, name, len, sc);
222
- } else {
223
- r = 0;
224
- archive_mstring_clean(&ap->name);
225
- }
226
- if (r == 0)
227
- return (ARCHIVE_OK);
228
- else if (errno == ENOMEM)
229
- return (ARCHIVE_FATAL);
230
- else
231
- return (ARCHIVE_WARN);
232
- }
233
-
234
- /*
235
- * If this ACL entry is part of the standard POSIX permissions set,
236
- * store the permissions in the stat structure and return zero.
237
- */
238
- static int
239
- acl_special(struct archive_acl *acl, int type, int permset, int tag)
240
- {
241
- if (type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS
242
- && ((permset & ~007) == 0)) {
243
- switch (tag) {
244
- case ARCHIVE_ENTRY_ACL_USER_OBJ:
245
- acl->mode &= ~0700;
246
- acl->mode |= (permset & 7) << 6;
247
- return (0);
248
- case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
249
- acl->mode &= ~0070;
250
- acl->mode |= (permset & 7) << 3;
251
- return (0);
252
- case ARCHIVE_ENTRY_ACL_OTHER:
253
- acl->mode &= ~0007;
254
- acl->mode |= permset & 7;
255
- return (0);
256
- }
257
- }
258
- return (1);
259
- }
260
-
261
- /*
262
- * Allocate and populate a new ACL entry with everything but the
263
- * name.
264
- */
265
- static struct archive_acl_entry *
266
- acl_new_entry(struct archive_acl *acl,
267
- int type, int permset, int tag, int id)
268
- {
269
- struct archive_acl_entry *ap, *aq;
270
-
271
- /* Reject an invalid type */
272
- switch (type) {
273
- case ARCHIVE_ENTRY_ACL_TYPE_ACCESS:
274
- case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT:
275
- case ARCHIVE_ENTRY_ACL_TYPE_ALLOW:
276
- case ARCHIVE_ENTRY_ACL_TYPE_DENY:
277
- case ARCHIVE_ENTRY_ACL_TYPE_AUDIT:
278
- case ARCHIVE_ENTRY_ACL_TYPE_ALARM:
279
- break;
280
- default:
281
- return (NULL);
282
- }
283
-
284
- /* Type argument must be a valid NFS4 or POSIX.1e type.
285
- * The type must agree with anything already set and
286
- * the permset must be compatible. */
287
- if (type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
288
- if (acl->acl_types & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
289
- return (NULL);
290
- }
291
- if (permset &
292
- ~(ARCHIVE_ENTRY_ACL_PERMS_NFS4
293
- | ARCHIVE_ENTRY_ACL_INHERITANCE_NFS4)) {
294
- return (NULL);
295
- }
296
- } else if (type & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) {
297
- if (acl->acl_types & ~ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) {
298
- return (NULL);
299
- }
300
- if (permset & ~ARCHIVE_ENTRY_ACL_PERMS_POSIX1E) {
301
- return (NULL);
302
- }
303
- } else {
304
- return (NULL);
305
- }
306
-
307
- /* Verify the tag is valid and compatible with NFS4 or POSIX.1e. */
308
- switch (tag) {
309
- case ARCHIVE_ENTRY_ACL_USER:
310
- case ARCHIVE_ENTRY_ACL_USER_OBJ:
311
- case ARCHIVE_ENTRY_ACL_GROUP:
312
- case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
313
- /* Tags valid in both NFS4 and POSIX.1e */
314
- break;
315
- case ARCHIVE_ENTRY_ACL_MASK:
316
- case ARCHIVE_ENTRY_ACL_OTHER:
317
- /* Tags valid only in POSIX.1e. */
318
- if (type & ~ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) {
319
- return (NULL);
320
- }
321
- break;
322
- case ARCHIVE_ENTRY_ACL_EVERYONE:
323
- /* Tags valid only in NFS4. */
324
- if (type & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
325
- return (NULL);
326
- }
327
- break;
328
- default:
329
- /* No other values are valid. */
330
- return (NULL);
331
- }
332
-
333
- free(acl->acl_text_w);
334
- acl->acl_text_w = NULL;
335
- free(acl->acl_text);
336
- acl->acl_text = NULL;
337
-
338
- /*
339
- * If there's a matching entry already in the list, overwrite it.
340
- * NFSv4 entries may be repeated and are not overwritten.
341
- *
342
- * TODO: compare names of no id is provided (needs more rework)
343
- */
344
- ap = acl->acl_head;
345
- aq = NULL;
346
- while (ap != NULL) {
347
- if (((type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) == 0) &&
348
- ap->type == type && ap->tag == tag && ap->id == id) {
349
- if (id != -1 || (tag != ARCHIVE_ENTRY_ACL_USER &&
350
- tag != ARCHIVE_ENTRY_ACL_GROUP)) {
351
- ap->permset = permset;
352
- return (ap);
353
- }
354
- }
355
- aq = ap;
356
- ap = ap->next;
357
- }
358
-
359
- /* Add a new entry to the end of the list. */
360
- ap = calloc(1, sizeof(*ap));
361
- if (ap == NULL)
362
- return (NULL);
363
- if (aq == NULL)
364
- acl->acl_head = ap;
365
- else
366
- aq->next = ap;
367
- ap->type = type;
368
- ap->tag = tag;
369
- ap->id = id;
370
- ap->permset = permset;
371
- acl->acl_types |= type;
372
- return (ap);
373
- }
374
-
375
- /*
376
- * Return a count of entries matching "want_type".
377
- */
378
- int
379
- archive_acl_count(struct archive_acl *acl, int want_type)
380
- {
381
- int count;
382
- struct archive_acl_entry *ap;
383
-
384
- count = 0;
385
- ap = acl->acl_head;
386
- while (ap != NULL) {
387
- if ((ap->type & want_type) != 0)
388
- count++;
389
- ap = ap->next;
390
- }
391
-
392
- if (count > 0 && ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0))
393
- count += 3;
394
- return (count);
395
- }
396
-
397
- /*
398
- * Return a bitmask of stored ACL types in an ACL list
399
- */
400
- int
401
- archive_acl_types(struct archive_acl *acl)
402
- {
403
- return (acl->acl_types);
404
- }
405
-
406
- /*
407
- * Prepare for reading entries from the ACL data. Returns a count
408
- * of entries matching "want_type", or zero if there are no
409
- * non-extended ACL entries of that type.
410
- */
411
- int
412
- archive_acl_reset(struct archive_acl *acl, int want_type)
413
- {
414
- int count, cutoff;
415
-
416
- count = archive_acl_count(acl, want_type);
417
-
418
- /*
419
- * If the only entries are the three standard ones,
420
- * then don't return any ACL data. (In this case,
421
- * client can just use chmod(2) to set permissions.)
422
- */
423
- if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)
424
- cutoff = 3;
425
- else
426
- cutoff = 0;
427
-
428
- if (count > cutoff)
429
- acl->acl_state = ARCHIVE_ENTRY_ACL_USER_OBJ;
430
- else
431
- acl->acl_state = 0;
432
- acl->acl_p = acl->acl_head;
433
- return (count);
434
- }
435
-
436
-
437
- /*
438
- * Return the next ACL entry in the list. Fake entries for the
439
- * standard permissions and include them in the returned list.
440
- */
441
- int
442
- archive_acl_next(struct archive *a, struct archive_acl *acl, int want_type,
443
- int *type, int *permset, int *tag, int *id, const char **name)
444
- {
445
- *name = NULL;
446
- *id = -1;
447
-
448
- /*
449
- * The acl_state is either zero (no entries available), -1
450
- * (reading from list), or an entry type (retrieve that type
451
- * from ae_stat.aest_mode).
452
- */
453
- if (acl->acl_state == 0)
454
- return (ARCHIVE_WARN);
455
-
456
- /* The first three access entries are special. */
457
- if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) {
458
- switch (acl->acl_state) {
459
- case ARCHIVE_ENTRY_ACL_USER_OBJ:
460
- *permset = (acl->mode >> 6) & 7;
461
- *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
462
- *tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
463
- acl->acl_state = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
464
- return (ARCHIVE_OK);
465
- case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
466
- *permset = (acl->mode >> 3) & 7;
467
- *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
468
- *tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
469
- acl->acl_state = ARCHIVE_ENTRY_ACL_OTHER;
470
- return (ARCHIVE_OK);
471
- case ARCHIVE_ENTRY_ACL_OTHER:
472
- *permset = acl->mode & 7;
473
- *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
474
- *tag = ARCHIVE_ENTRY_ACL_OTHER;
475
- acl->acl_state = -1;
476
- acl->acl_p = acl->acl_head;
477
- return (ARCHIVE_OK);
478
- default:
479
- break;
480
- }
481
- }
482
-
483
- while (acl->acl_p != NULL && (acl->acl_p->type & want_type) == 0)
484
- acl->acl_p = acl->acl_p->next;
485
- if (acl->acl_p == NULL) {
486
- acl->acl_state = 0;
487
- *type = 0;
488
- *permset = 0;
489
- *tag = 0;
490
- *id = -1;
491
- *name = NULL;
492
- return (ARCHIVE_EOF); /* End of ACL entries. */
493
- }
494
- *type = acl->acl_p->type;
495
- *permset = acl->acl_p->permset;
496
- *tag = acl->acl_p->tag;
497
- *id = acl->acl_p->id;
498
- if (archive_mstring_get_mbs(a, &acl->acl_p->name, name) != 0) {
499
- if (errno == ENOMEM)
500
- return (ARCHIVE_FATAL);
501
- *name = NULL;
502
- }
503
- acl->acl_p = acl->acl_p->next;
504
- return (ARCHIVE_OK);
505
- }
506
-
507
- /*
508
- * Determine what type of ACL do we want
509
- */
510
- static int
511
- archive_acl_text_want_type(struct archive_acl *acl, int flags)
512
- {
513
- int want_type;
514
-
515
- /* Check if ACL is NFSv4 */
516
- if ((acl->acl_types & ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) {
517
- /* NFSv4 should never mix with POSIX.1e */
518
- if ((acl->acl_types & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0)
519
- return (0);
520
- else
521
- return (ARCHIVE_ENTRY_ACL_TYPE_NFS4);
522
- }
523
-
524
- /* Now deal with POSIX.1e ACLs */
525
-
526
- want_type = 0;
527
- if ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)
528
- want_type |= ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
529
- if ((flags & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0)
530
- want_type |= ARCHIVE_ENTRY_ACL_TYPE_DEFAULT;
531
-
532
- /* By default we want both access and default ACLs */
533
- if (want_type == 0)
534
- return (ARCHIVE_ENTRY_ACL_TYPE_POSIX1E);
535
-
536
- return (want_type);
537
- }
538
-
539
- /*
540
- * Check if ACL text would be empty
541
- */
542
- static size_t
543
- archive_acl_text_empty(struct archive_acl *acl, int want_type) {
544
- struct archive_acl_entry *ap;
545
-
546
- for (ap = acl->acl_head; ap != NULL; ap = ap->next) {
547
- if ((ap->type & want_type) == 0)
548
- continue;
549
- /*
550
- * Filemode-mapping ACL entries are stored exclusively in
551
- * ap->mode so they should not be in the list
552
- */
553
- if ((ap->type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS)
554
- && (ap->tag == ARCHIVE_ENTRY_ACL_USER_OBJ
555
- || ap->tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ
556
- || ap->tag == ARCHIVE_ENTRY_ACL_OTHER))
557
- continue;
558
-
559
- return (0);
560
- }
561
-
562
- return (1);
563
- }
564
-
565
- /*
566
- * Generate a wide text version of the ACL. The flags parameter controls
567
- * the type and style of the generated ACL.
568
- */
569
- wchar_t *
570
- archive_acl_to_text_w(struct archive_acl *acl, ssize_t *text_len, int flags,
571
- struct archive *a)
572
- {
573
- const wchar_t *wname;
574
- const wchar_t *prefix;
575
- wchar_t separator;
576
- struct archive_acl_entry *ap;
577
- struct archive_wstring ws;
578
- int id, r, want_type;
579
-
580
- want_type = archive_acl_text_want_type(acl, flags);
581
-
582
- /* Both NFSv4 and POSIX.1 types found */
583
- if (want_type == 0)
584
- return (NULL);
585
-
586
- if (want_type == ARCHIVE_ENTRY_ACL_TYPE_POSIX1E)
587
- flags |= ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT;
588
-
589
- if (archive_acl_text_empty(acl, want_type))
590
- return (NULL);
591
-
592
- if (flags & ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA)
593
- separator = L',';
594
- else
595
- separator = L'\n';
596
-
597
- archive_string_init(&ws);
598
-
599
- if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) {
600
- append_entry_w(&ws, NULL, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
601
- ARCHIVE_ENTRY_ACL_USER_OBJ, flags, NULL,
602
- acl->mode & 0700, -1);
603
- archive_wstrappend_wchar(&ws, separator);
604
- append_entry_w(&ws, NULL, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
605
- ARCHIVE_ENTRY_ACL_GROUP_OBJ, flags, NULL,
606
- acl->mode & 0070, -1);
607
- archive_wstrappend_wchar(&ws, separator);
608
- append_entry_w(&ws, NULL, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
609
- ARCHIVE_ENTRY_ACL_OTHER, flags, NULL,
610
- acl->mode & 0007, -1);
611
- }
612
-
613
- for (ap = acl->acl_head; ap != NULL; ap = ap->next) {
614
- if ((ap->type & want_type) == 0)
615
- continue;
616
- /*
617
- * Filemode-mapping ACL entries are stored exclusively in
618
- * ap->mode so they should not be in the list
619
- */
620
- if ((ap->type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS)
621
- && (ap->tag == ARCHIVE_ENTRY_ACL_USER_OBJ
622
- || ap->tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ
623
- || ap->tag == ARCHIVE_ENTRY_ACL_OTHER))
624
- continue;
625
- if (ap->type == ARCHIVE_ENTRY_ACL_TYPE_DEFAULT &&
626
- (flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) != 0)
627
- prefix = L"default:";
628
- else
629
- prefix = NULL;
630
- r = archive_mstring_get_wcs(a, &ap->name, &wname);
631
- if (r == 0) {
632
- if (ws.length > 0)
633
- archive_wstrappend_wchar(&ws, separator);
634
- if ((flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID) ||
635
- wname == NULL)
636
- id = ap->id;
637
- else
638
- id = -1;
639
- append_entry_w(&ws, prefix, ap->type, ap->tag, flags,
640
- wname, ap->permset, id);
641
- } else if (r < 0 && errno == ENOMEM) {
642
- archive_wstring_free(&ws);
643
- return (NULL);
644
- }
645
- }
646
-
647
- if (text_len != NULL)
648
- *text_len = ws.length;
649
-
650
- return (ws.s);
651
- }
652
-
653
- static void
654
- append_id_w(struct archive_wstring *ws, int id)
655
- {
656
- if (id < 0)
657
- id = 0;
658
- if (id > 9)
659
- append_id_w(ws, id / 10);
660
- archive_wstrappend_wchar(ws, L"0123456789"[id % 10]);
661
- }
662
-
663
- static void
664
- append_entry_w(struct archive_wstring *ws, const wchar_t *prefix, int type,
665
- int tag, int flags, const wchar_t *wname, int perm, int id)
666
- {
667
- int i;
668
-
669
- if (prefix != NULL)
670
- archive_wstrcat(ws, prefix);
671
- switch (tag) {
672
- case ARCHIVE_ENTRY_ACL_USER_OBJ:
673
- wname = NULL;
674
- id = -1;
675
- if ((type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) {
676
- archive_wstrcat(ws, L"owner@");
677
- break;
678
- }
679
- /* FALLTHROUGH */
680
- case ARCHIVE_ENTRY_ACL_USER:
681
- archive_wstrcat(ws, L"user");
682
- break;
683
- case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
684
- wname = NULL;
685
- id = -1;
686
- if ((type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) {
687
- archive_wstrcat(ws, L"group@");
688
- break;
689
- }
690
- /* FALLTHROUGH */
691
- case ARCHIVE_ENTRY_ACL_GROUP:
692
- archive_wstrcat(ws, L"group");
693
- break;
694
- case ARCHIVE_ENTRY_ACL_MASK:
695
- archive_wstrcat(ws, L"mask");
696
- wname = NULL;
697
- id = -1;
698
- break;
699
- case ARCHIVE_ENTRY_ACL_OTHER:
700
- archive_wstrcat(ws, L"other");
701
- wname = NULL;
702
- id = -1;
703
- break;
704
- case ARCHIVE_ENTRY_ACL_EVERYONE:
705
- archive_wstrcat(ws, L"everyone@");
706
- wname = NULL;
707
- id = -1;
708
- break;
709
- default:
710
- break;
711
- }
712
- archive_wstrappend_wchar(ws, L':');
713
- if (((type & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) ||
714
- tag == ARCHIVE_ENTRY_ACL_USER ||
715
- tag == ARCHIVE_ENTRY_ACL_GROUP) {
716
- if (wname != NULL) {
717
- archive_wstrcat(ws, wname);
718
- } else if (tag == ARCHIVE_ENTRY_ACL_USER
719
- || tag == ARCHIVE_ENTRY_ACL_GROUP) {
720
- append_id_w(ws, id);
721
- if ((type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) == 0)
722
- id = -1;
723
- }
724
- /* Solaris style has no second colon after other and mask */
725
- if (((flags & ARCHIVE_ENTRY_ACL_STYLE_SOLARIS) == 0)
726
- || (tag != ARCHIVE_ENTRY_ACL_OTHER
727
- && tag != ARCHIVE_ENTRY_ACL_MASK))
728
- archive_wstrappend_wchar(ws, L':');
729
- }
730
- if ((type & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) {
731
- /* POSIX.1e ACL perms */
732
- archive_wstrappend_wchar(ws, (perm & 0444) ? L'r' : L'-');
733
- archive_wstrappend_wchar(ws, (perm & 0222) ? L'w' : L'-');
734
- archive_wstrappend_wchar(ws, (perm & 0111) ? L'x' : L'-');
735
- } else {
736
- /* NFSv4 ACL perms */
737
- for (i = 0; i < nfsv4_acl_perm_map_size; i++) {
738
- if (perm & nfsv4_acl_perm_map[i].perm)
739
- archive_wstrappend_wchar(ws, nfsv4_acl_perm_map[i].wc);
740
- else if ((flags & ARCHIVE_ENTRY_ACL_STYLE_COMPACT) == 0)
741
- archive_wstrappend_wchar(ws, L'-');
742
- }
743
- archive_wstrappend_wchar(ws, L':');
744
- for (i = 0; i < nfsv4_acl_flag_map_size; i++) {
745
- if (perm & nfsv4_acl_flag_map[i].perm)
746
- archive_wstrappend_wchar(ws, nfsv4_acl_flag_map[i].wc);
747
- else if ((flags & ARCHIVE_ENTRY_ACL_STYLE_COMPACT) == 0)
748
- archive_wstrappend_wchar(ws, L'-');
749
- }
750
- archive_wstrappend_wchar(ws, L':');
751
- switch (type) {
752
- case ARCHIVE_ENTRY_ACL_TYPE_ALLOW:
753
- archive_wstrcat(ws, L"allow");
754
- break;
755
- case ARCHIVE_ENTRY_ACL_TYPE_DENY:
756
- archive_wstrcat(ws, L"deny");
757
- break;
758
- case ARCHIVE_ENTRY_ACL_TYPE_AUDIT:
759
- archive_wstrcat(ws, L"audit");
760
- break;
761
- case ARCHIVE_ENTRY_ACL_TYPE_ALARM:
762
- archive_wstrcat(ws, L"alarm");
763
- break;
764
- default:
765
- break;
766
- }
767
- }
768
- if (id != -1) {
769
- archive_wstrappend_wchar(ws, L':');
770
- append_id_w(ws, id);
771
- }
772
- }
773
-
774
- /*
775
- * Generate a text version of the ACL. The flags parameter controls
776
- * the type and style of the generated ACL.
777
- */
778
- char *
779
- archive_acl_to_text_l(struct archive_acl *acl, ssize_t *text_len, int flags,
780
- struct archive_string_conv *sc)
781
- {
782
- size_t len;
783
- const char *name;
784
- const char *prefix;
785
- char separator;
786
- struct archive_acl_entry *ap;
787
- struct archive_string s;
788
- int id, r, want_type;
789
-
790
- want_type = archive_acl_text_want_type(acl, flags);
791
-
792
- /* Both NFSv4 and POSIX.1 types found */
793
- if (want_type == 0)
794
- return (NULL);
795
-
796
- if (want_type == ARCHIVE_ENTRY_ACL_TYPE_POSIX1E)
797
- flags |= ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT;
798
-
799
- if (archive_acl_text_empty(acl, want_type))
800
- return (NULL);
801
-
802
- if (flags & ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA)
803
- separator = ',';
804
- else
805
- separator = '\n';
806
-
807
- archive_string_init(&s);
808
-
809
- if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) {
810
- append_entry(&s, NULL, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
811
- ARCHIVE_ENTRY_ACL_USER_OBJ, flags, NULL,
812
- acl->mode & 0700, -1);
813
- archive_strappend_char(&s, separator);
814
- append_entry(&s, NULL, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
815
- ARCHIVE_ENTRY_ACL_GROUP_OBJ, flags, NULL,
816
- acl->mode & 0070, -1);
817
- archive_strappend_char(&s, separator);
818
- append_entry(&s, NULL, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
819
- ARCHIVE_ENTRY_ACL_OTHER, flags, NULL,
820
- acl->mode & 0007, -1);
821
- }
822
-
823
- for (ap = acl->acl_head; ap != NULL; ap = ap->next) {
824
- if ((ap->type & want_type) == 0)
825
- continue;
826
- /*
827
- * Filemode-mapping ACL entries are stored exclusively in
828
- * ap->mode so they should not be in the list
829
- */
830
- if ((ap->type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS)
831
- && (ap->tag == ARCHIVE_ENTRY_ACL_USER_OBJ
832
- || ap->tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ
833
- || ap->tag == ARCHIVE_ENTRY_ACL_OTHER))
834
- continue;
835
- if (ap->type == ARCHIVE_ENTRY_ACL_TYPE_DEFAULT &&
836
- (flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) != 0)
837
- prefix = "default:";
838
- else
839
- prefix = NULL;
840
- r = archive_mstring_get_mbs_l(
841
- NULL, &ap->name, &name, &len, sc);
842
- if (r != 0) {
843
- archive_string_free(&s);
844
- return (NULL);
845
- }
846
- if (s.length > 0)
847
- archive_strappend_char(&s, separator);
848
- if (name == NULL ||
849
- (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID)) {
850
- id = ap->id;
851
- } else {
852
- id = -1;
853
- }
854
- append_entry(&s, prefix, ap->type, ap->tag, flags, name,
855
- ap->permset, id);
856
- }
857
-
858
- if (text_len != NULL)
859
- *text_len = s.length;
860
-
861
- return (s.s);
862
- }
863
-
864
- static void
865
- append_id(struct archive_string *s, int id)
866
- {
867
- if (id < 0)
868
- id = 0;
869
- if (id > 9)
870
- append_id(s, id / 10);
871
- archive_strappend_char(s, "0123456789"[id % 10]);
872
- }
873
-
874
- static void
875
- append_entry(struct archive_string *s, const char *prefix, int type,
876
- int tag, int flags, const char *name, int perm, int id)
877
- {
878
- int i;
879
-
880
- if (prefix != NULL)
881
- archive_strcat(s, prefix);
882
- switch (tag) {
883
- case ARCHIVE_ENTRY_ACL_USER_OBJ:
884
- name = NULL;
885
- id = -1;
886
- if ((type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) {
887
- archive_strcat(s, "owner@");
888
- break;
889
- }
890
- /* FALLTHROUGH */
891
- case ARCHIVE_ENTRY_ACL_USER:
892
- archive_strcat(s, "user");
893
- break;
894
- case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
895
- name = NULL;
896
- id = -1;
897
- if ((type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) {
898
- archive_strcat(s, "group@");
899
- break;
900
- }
901
- /* FALLTHROUGH */
902
- case ARCHIVE_ENTRY_ACL_GROUP:
903
- archive_strcat(s, "group");
904
- break;
905
- case ARCHIVE_ENTRY_ACL_MASK:
906
- archive_strcat(s, "mask");
907
- name = NULL;
908
- id = -1;
909
- break;
910
- case ARCHIVE_ENTRY_ACL_OTHER:
911
- archive_strcat(s, "other");
912
- name = NULL;
913
- id = -1;
914
- break;
915
- case ARCHIVE_ENTRY_ACL_EVERYONE:
916
- archive_strcat(s, "everyone@");
917
- name = NULL;
918
- id = -1;
919
- break;
920
- default:
921
- break;
922
- }
923
- archive_strappend_char(s, ':');
924
- if (((type & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) ||
925
- tag == ARCHIVE_ENTRY_ACL_USER ||
926
- tag == ARCHIVE_ENTRY_ACL_GROUP) {
927
- if (name != NULL) {
928
- archive_strcat(s, name);
929
- } else if (tag == ARCHIVE_ENTRY_ACL_USER
930
- || tag == ARCHIVE_ENTRY_ACL_GROUP) {
931
- append_id(s, id);
932
- if ((type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) == 0)
933
- id = -1;
934
- }
935
- /* Solaris style has no second colon after other and mask */
936
- if (((flags & ARCHIVE_ENTRY_ACL_STYLE_SOLARIS) == 0)
937
- || (tag != ARCHIVE_ENTRY_ACL_OTHER
938
- && tag != ARCHIVE_ENTRY_ACL_MASK))
939
- archive_strappend_char(s, ':');
940
- }
941
- if ((type & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) {
942
- /* POSIX.1e ACL perms */
943
- archive_strappend_char(s, (perm & 0444) ? 'r' : '-');
944
- archive_strappend_char(s, (perm & 0222) ? 'w' : '-');
945
- archive_strappend_char(s, (perm & 0111) ? 'x' : '-');
946
- } else {
947
- /* NFSv4 ACL perms */
948
- for (i = 0; i < nfsv4_acl_perm_map_size; i++) {
949
- if (perm & nfsv4_acl_perm_map[i].perm)
950
- archive_strappend_char(s, nfsv4_acl_perm_map[i].c);
951
- else if ((flags & ARCHIVE_ENTRY_ACL_STYLE_COMPACT) == 0)
952
- archive_strappend_char(s, '-');
953
- }
954
- archive_strappend_char(s, ':');
955
- for (i = 0; i < nfsv4_acl_flag_map_size; i++) {
956
- if (perm & nfsv4_acl_flag_map[i].perm)
957
- archive_strappend_char(s, nfsv4_acl_flag_map[i].c);
958
- else if ((flags & ARCHIVE_ENTRY_ACL_STYLE_COMPACT) == 0)
959
- archive_strappend_char(s, '-');
960
- }
961
- archive_strappend_char(s, ':');
962
- switch (type) {
963
- case ARCHIVE_ENTRY_ACL_TYPE_ALLOW:
964
- archive_strcat(s, "allow");
965
- break;
966
- case ARCHIVE_ENTRY_ACL_TYPE_DENY:
967
- archive_strcat(s, "deny");
968
- break;
969
- case ARCHIVE_ENTRY_ACL_TYPE_AUDIT:
970
- archive_strcat(s, "audit");
971
- break;
972
- case ARCHIVE_ENTRY_ACL_TYPE_ALARM:
973
- archive_strcat(s, "alarm");
974
- break;
975
- default:
976
- break;
977
- }
978
- }
979
- if (id != -1) {
980
- archive_strappend_char(s, ':');
981
- append_id(s, id);
982
- }
983
- }
984
-
985
- /*
986
- * Parse a wide ACL text string.
987
- *
988
- * The want_type argument may be one of the following:
989
- * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - text is a POSIX.1e ACL of type ACCESS
990
- * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - text is a POSIX.1e ACL of type DEFAULT
991
- * ARCHIVE_ENTRY_ACL_TYPE_NFS4 - text is as a NFSv4 ACL
992
- *
993
- * POSIX.1e ACL entries prefixed with "default:" are treated as
994
- * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT unless type is ARCHIVE_ENTRY_ACL_TYPE_NFS4
995
- */
996
- int
997
- archive_acl_from_text_w(struct archive_acl *acl, const wchar_t *text,
998
- int want_type)
999
- {
1000
- struct {
1001
- const wchar_t *start;
1002
- const wchar_t *end;
1003
- } field[6], name;
1004
-
1005
- const wchar_t *s, *st;
1006
-
1007
- int numfields, fields, n, r, sol, ret;
1008
- int type, types, tag, permset, id;
1009
- size_t len;
1010
- wchar_t sep;
1011
-
1012
- ret = ARCHIVE_OK;
1013
- types = 0;
1014
-
1015
- switch (want_type) {
1016
- case ARCHIVE_ENTRY_ACL_TYPE_POSIX1E:
1017
- want_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
1018
- __LA_FALLTHROUGH;
1019
- case ARCHIVE_ENTRY_ACL_TYPE_ACCESS:
1020
- case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT:
1021
- numfields = 5;
1022
- break;
1023
- case ARCHIVE_ENTRY_ACL_TYPE_NFS4:
1024
- numfields = 6;
1025
- break;
1026
- default:
1027
- return (ARCHIVE_FATAL);
1028
- }
1029
-
1030
- while (text != NULL && *text != L'\0') {
1031
- /*
1032
- * Parse the fields out of the next entry,
1033
- * advance 'text' to start of next entry.
1034
- */
1035
- fields = 0;
1036
- do {
1037
- const wchar_t *start, *end;
1038
- next_field_w(&text, &start, &end, &sep);
1039
- if (fields < numfields) {
1040
- field[fields].start = start;
1041
- field[fields].end = end;
1042
- }
1043
- ++fields;
1044
- } while (sep == L':');
1045
-
1046
- /* Set remaining fields to blank. */
1047
- for (n = fields; n < numfields; ++n)
1048
- field[n].start = field[n].end = NULL;
1049
-
1050
- if (field[0].start == NULL || field[0].end == NULL) {
1051
- /* This should never happen */
1052
- return (ARCHIVE_FATAL);
1053
- }
1054
-
1055
- if (*(field[0].start) == L'#') {
1056
- /* Comment, skip entry */
1057
- continue;
1058
- }
1059
-
1060
- n = 0;
1061
- sol = 0;
1062
- id = -1;
1063
- permset = 0;
1064
- name.start = name.end = NULL;
1065
-
1066
- if (want_type != ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
1067
- /* POSIX.1e ACLs */
1068
- /*
1069
- * Default keyword "default:user::rwx"
1070
- * if found, we have one more field
1071
- *
1072
- * We also support old Solaris extension:
1073
- * "defaultuser::rwx" is the default ACL corresponding
1074
- * to "user::rwx", etc. valid only for first field
1075
- */
1076
- s = field[0].start;
1077
- len = field[0].end - field[0].start;
1078
- if (*s == L'd' && (len == 1 || (len >= 7
1079
- && wmemcmp((s + 1), L"efault", 6) == 0))) {
1080
- type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT;
1081
- if (len > 7)
1082
- field[0].start += 7;
1083
- else
1084
- n = 1;
1085
- } else
1086
- type = want_type;
1087
-
1088
- /* Check for a numeric ID in field n+1 or n+3. */
1089
- if (isint_w(field[n + 1].start, field[n + 1].end,
1090
- &id) < 0) {
1091
- ret = ARCHIVE_WARN;
1092
- continue;
1093
- }
1094
- /* Field n+3 is optional. */
1095
- if (id == -1 && fields > n+3 &&
1096
- isint_w(field[n + 3].start, field[n + 3].end,
1097
- &id) < 0) {
1098
- ret = ARCHIVE_WARN;
1099
- continue;
1100
- }
1101
-
1102
- tag = 0;
1103
- s = field[n].start;
1104
- len = field[n].end - field[n].start;
1105
- if (len == 0) {
1106
- ret = ARCHIVE_WARN;
1107
- continue;
1108
- }
1109
- st = s + 1;
1110
-
1111
- switch (*s) {
1112
- case L'u':
1113
- if (len == 1 || (len == 4
1114
- && wmemcmp(st, L"ser", 3) == 0))
1115
- tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
1116
- break;
1117
- case L'g':
1118
- if (len == 1 || (len == 5
1119
- && wmemcmp(st, L"roup", 4) == 0))
1120
- tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
1121
- break;
1122
- case L'o':
1123
- if (len == 1 || (len == 5
1124
- && wmemcmp(st, L"ther", 4) == 0))
1125
- tag = ARCHIVE_ENTRY_ACL_OTHER;
1126
- break;
1127
- case L'm':
1128
- if (len == 1 || (len == 4
1129
- && wmemcmp(st, L"ask", 3) == 0))
1130
- tag = ARCHIVE_ENTRY_ACL_MASK;
1131
- break;
1132
- default:
1133
- break;
1134
- }
1135
-
1136
- switch (tag) {
1137
- case ARCHIVE_ENTRY_ACL_OTHER:
1138
- case ARCHIVE_ENTRY_ACL_MASK:
1139
- if (fields == (n + 2)
1140
- && field[n + 1].start < field[n + 1].end
1141
- && ismode_w(field[n + 1].start,
1142
- field[n + 1].end, &permset)) {
1143
- /* This is Solaris-style "other:rwx" */
1144
- sol = 1;
1145
- } else if (fields == (n + 3) &&
1146
- field[n + 1].start < field[n + 1].end) {
1147
- /* Invalid mask or other field */
1148
- ret = ARCHIVE_WARN;
1149
- continue;
1150
- }
1151
- break;
1152
- case ARCHIVE_ENTRY_ACL_USER_OBJ:
1153
- case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
1154
- if (id != -1 ||
1155
- field[n + 1].start < field[n + 1].end) {
1156
- name = field[n + 1];
1157
- if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ)
1158
- tag = ARCHIVE_ENTRY_ACL_USER;
1159
- else
1160
- tag = ARCHIVE_ENTRY_ACL_GROUP;
1161
- }
1162
- break;
1163
- default:
1164
- /* Invalid tag, skip entry */
1165
- ret = ARCHIVE_WARN;
1166
- continue;
1167
- }
1168
-
1169
- /*
1170
- * Without "default:" we expect mode in field 2
1171
- * Exception: Solaris other and mask fields
1172
- */
1173
- if (permset == 0 && !ismode_w(field[n + 2 - sol].start,
1174
- field[n + 2 - sol].end, &permset)) {
1175
- /* Invalid mode, skip entry */
1176
- ret = ARCHIVE_WARN;
1177
- continue;
1178
- }
1179
- } else {
1180
- /* NFS4 ACLs */
1181
- s = field[0].start;
1182
- len = field[0].end - field[0].start;
1183
- tag = 0;
1184
-
1185
- switch (len) {
1186
- case 4:
1187
- if (wmemcmp(s, L"user", 4) == 0)
1188
- tag = ARCHIVE_ENTRY_ACL_USER;
1189
- break;
1190
- case 5:
1191
- if (wmemcmp(s, L"group", 5) == 0)
1192
- tag = ARCHIVE_ENTRY_ACL_GROUP;
1193
- break;
1194
- case 6:
1195
- if (wmemcmp(s, L"owner@", 6) == 0)
1196
- tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
1197
- else if (wmemcmp(s, L"group@", len) == 0)
1198
- tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
1199
- break;
1200
- case 9:
1201
- if (wmemcmp(s, L"everyone@", 9) == 0)
1202
- tag = ARCHIVE_ENTRY_ACL_EVERYONE;
1203
- default:
1204
- break;
1205
- }
1206
-
1207
- if (tag == 0) {
1208
- /* Invalid tag, skip entry */
1209
- ret = ARCHIVE_WARN;
1210
- continue;
1211
- } else if (tag == ARCHIVE_ENTRY_ACL_USER ||
1212
- tag == ARCHIVE_ENTRY_ACL_GROUP) {
1213
- n = 1;
1214
- name = field[1];
1215
- if (isint_w(name.start, name.end, &id) < 0) {
1216
- ret = ARCHIVE_WARN;
1217
- continue;
1218
- }
1219
- } else
1220
- n = 0;
1221
-
1222
- if (!is_nfs4_perms_w(field[1 + n].start,
1223
- field[1 + n].end, &permset)) {
1224
- /* Invalid NFSv4 perms, skip entry */
1225
- ret = ARCHIVE_WARN;
1226
- continue;
1227
- }
1228
- if (!is_nfs4_flags_w(field[2 + n].start,
1229
- field[2 + n].end, &permset)) {
1230
- /* Invalid NFSv4 flags, skip entry */
1231
- ret = ARCHIVE_WARN;
1232
- continue;
1233
- }
1234
- s = field[3 + n].start;
1235
- len = field[3 + n].end - field[3 + n].start;
1236
- type = 0;
1237
- if (len == 4) {
1238
- if (wmemcmp(s, L"deny", 4) == 0)
1239
- type = ARCHIVE_ENTRY_ACL_TYPE_DENY;
1240
- } else if (len == 5) {
1241
- if (wmemcmp(s, L"allow", 5) == 0)
1242
- type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW;
1243
- else if (wmemcmp(s, L"audit", 5) == 0)
1244
- type = ARCHIVE_ENTRY_ACL_TYPE_AUDIT;
1245
- else if (wmemcmp(s, L"alarm", 5) == 0)
1246
- type = ARCHIVE_ENTRY_ACL_TYPE_ALARM;
1247
- }
1248
- if (type == 0) {
1249
- /* Invalid entry type, skip entry */
1250
- ret = ARCHIVE_WARN;
1251
- continue;
1252
- }
1253
- if (isint_w(field[4 + n].start, field[4 + n].end,
1254
- &id) < 0) {
1255
- ret = ARCHIVE_WARN;
1256
- continue;
1257
- }
1258
- }
1259
-
1260
- /* Add entry to the internal list. */
1261
- r = archive_acl_add_entry_w_len(acl, type, permset,
1262
- tag, id, name.start, name.end - name.start);
1263
- if (r < ARCHIVE_WARN)
1264
- return (r);
1265
- if (r != ARCHIVE_OK)
1266
- ret = ARCHIVE_WARN;
1267
- types |= type;
1268
- }
1269
-
1270
- /* Reset ACL */
1271
- archive_acl_reset(acl, types);
1272
-
1273
- return (ret);
1274
- }
1275
-
1276
- /*
1277
- * Parse a string to a positive decimal integer. Returns true if
1278
- * the string is non-empty and consists only of decimal digits,
1279
- * false otherwise.
1280
- */
1281
- static int
1282
- isint_w(const wchar_t *start, const wchar_t *end, int *result)
1283
- {
1284
- int n = 0;
1285
- if (start >= end)
1286
- return (0);
1287
- while (start < end) {
1288
- if (*start < L'0' || *start > L'9')
1289
- return (0);
1290
- if (n > (INT_MAX / 10) ||
1291
- (n == INT_MAX / 10 && (*start - L'0') >= INT_MAX % 10)) {
1292
- return (-1);
1293
- } else {
1294
- n *= 10;
1295
- n += *start - L'0';
1296
- }
1297
- start++;
1298
- }
1299
- *result = n;
1300
- return (1);
1301
- }
1302
-
1303
- /*
1304
- * Parse a string as a mode field. Returns true if
1305
- * the string is non-empty and consists only of mode characters,
1306
- * false otherwise.
1307
- */
1308
- static int
1309
- ismode_w(const wchar_t *start, const wchar_t *end, int *permset)
1310
- {
1311
- const wchar_t *p;
1312
-
1313
- if (start >= end)
1314
- return (0);
1315
- p = start;
1316
- *permset = 0;
1317
- while (p < end) {
1318
- switch (*p++) {
1319
- case L'r': case L'R':
1320
- *permset |= ARCHIVE_ENTRY_ACL_READ;
1321
- break;
1322
- case L'w': case L'W':
1323
- *permset |= ARCHIVE_ENTRY_ACL_WRITE;
1324
- break;
1325
- case L'x': case L'X':
1326
- *permset |= ARCHIVE_ENTRY_ACL_EXECUTE;
1327
- break;
1328
- case L'-':
1329
- break;
1330
- default:
1331
- return (0);
1332
- }
1333
- }
1334
- return (1);
1335
- }
1336
-
1337
- /*
1338
- * Parse a string as a NFS4 ACL permission field.
1339
- * Returns true if the string is non-empty and consists only of NFS4 ACL
1340
- * permission characters, false otherwise
1341
- */
1342
- static int
1343
- is_nfs4_perms_w(const wchar_t *start, const wchar_t *end, int *permset)
1344
- {
1345
- const wchar_t *p = start;
1346
-
1347
- while (p < end) {
1348
- switch (*p++) {
1349
- case L'r':
1350
- *permset |= ARCHIVE_ENTRY_ACL_READ_DATA;
1351
- break;
1352
- case L'w':
1353
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_DATA;
1354
- break;
1355
- case L'x':
1356
- *permset |= ARCHIVE_ENTRY_ACL_EXECUTE;
1357
- break;
1358
- case L'p':
1359
- *permset |= ARCHIVE_ENTRY_ACL_APPEND_DATA;
1360
- break;
1361
- case L'D':
1362
- *permset |= ARCHIVE_ENTRY_ACL_DELETE_CHILD;
1363
- break;
1364
- case L'd':
1365
- *permset |= ARCHIVE_ENTRY_ACL_DELETE;
1366
- break;
1367
- case L'a':
1368
- *permset |= ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES;
1369
- break;
1370
- case L'A':
1371
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES;
1372
- break;
1373
- case L'R':
1374
- *permset |= ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS;
1375
- break;
1376
- case L'W':
1377
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS;
1378
- break;
1379
- case L'c':
1380
- *permset |= ARCHIVE_ENTRY_ACL_READ_ACL;
1381
- break;
1382
- case L'C':
1383
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_ACL;
1384
- break;
1385
- case L'o':
1386
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_OWNER;
1387
- break;
1388
- case L's':
1389
- *permset |= ARCHIVE_ENTRY_ACL_SYNCHRONIZE;
1390
- break;
1391
- case L'-':
1392
- break;
1393
- default:
1394
- return(0);
1395
- }
1396
- }
1397
- return (1);
1398
- }
1399
-
1400
- /*
1401
- * Parse a string as a NFS4 ACL flags field.
1402
- * Returns true if the string is non-empty and consists only of NFS4 ACL
1403
- * flag characters, false otherwise
1404
- */
1405
- static int
1406
- is_nfs4_flags_w(const wchar_t *start, const wchar_t *end, int *permset)
1407
- {
1408
- const wchar_t *p = start;
1409
-
1410
- while (p < end) {
1411
- switch(*p++) {
1412
- case L'f':
1413
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT;
1414
- break;
1415
- case L'd':
1416
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT;
1417
- break;
1418
- case L'i':
1419
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY;
1420
- break;
1421
- case L'n':
1422
- *permset |=
1423
- ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT;
1424
- break;
1425
- case L'S':
1426
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS;
1427
- break;
1428
- case L'F':
1429
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS;
1430
- break;
1431
- case L'I':
1432
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_INHERITED;
1433
- break;
1434
- case L'-':
1435
- break;
1436
- default:
1437
- return (0);
1438
- }
1439
- }
1440
- return (1);
1441
- }
1442
-
1443
- /*
1444
- * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *wp is updated
1445
- * to point to just after the separator. *start points to the first
1446
- * character of the matched text and *end just after the last
1447
- * character of the matched identifier. In particular *end - *start
1448
- * is the length of the field body, not including leading or trailing
1449
- * whitespace.
1450
- */
1451
- static void
1452
- next_field_w(const wchar_t **wp, const wchar_t **start,
1453
- const wchar_t **end, wchar_t *sep)
1454
- {
1455
- /* Skip leading whitespace to find start of field. */
1456
- while (**wp == L' ' || **wp == L'\t' || **wp == L'\n') {
1457
- (*wp)++;
1458
- }
1459
- *start = *wp;
1460
-
1461
- /* Scan for the separator. */
1462
- while (**wp != L'\0' && **wp != L',' && **wp != L':' &&
1463
- **wp != L'\n' && **wp != L'#') {
1464
- (*wp)++;
1465
- }
1466
- *sep = **wp;
1467
-
1468
- /* Locate end of field, trim trailing whitespace if necessary */
1469
- if (*wp == *start) {
1470
- *end = *wp;
1471
- } else {
1472
- *end = *wp - 1;
1473
- while (**end == L' ' || **end == L'\t' || **end == L'\n') {
1474
- (*end)--;
1475
- }
1476
- (*end)++;
1477
- }
1478
-
1479
- /* Handle in-field comments */
1480
- if (*sep == L'#') {
1481
- while (**wp != L'\0' && **wp != L',' && **wp != L'\n') {
1482
- (*wp)++;
1483
- }
1484
- *sep = **wp;
1485
- }
1486
-
1487
- /* Adjust scanner location. */
1488
- if (**wp != L'\0')
1489
- (*wp)++;
1490
- }
1491
-
1492
- /*
1493
- * Parse an ACL text string.
1494
- *
1495
- * The want_type argument may be one of the following:
1496
- * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - text is a POSIX.1e ACL of type ACCESS
1497
- * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - text is a POSIX.1e ACL of type DEFAULT
1498
- * ARCHIVE_ENTRY_ACL_TYPE_NFS4 - text is as a NFSv4 ACL
1499
- *
1500
- * POSIX.1e ACL entries prefixed with "default:" are treated as
1501
- * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT unless type is ARCHIVE_ENTRY_ACL_TYPE_NFS4
1502
- */
1503
- int
1504
- archive_acl_from_text_l(struct archive_acl *acl, const char *text,
1505
- int want_type, struct archive_string_conv *sc)
1506
- {
1507
- return archive_acl_from_text_nl(acl, text, strlen(text), want_type, sc);
1508
- }
1509
-
1510
- int
1511
- archive_acl_from_text_nl(struct archive_acl *acl, const char *text,
1512
- size_t length, int want_type, struct archive_string_conv *sc)
1513
- {
1514
- struct {
1515
- const char *start;
1516
- const char *end;
1517
- } field[6], name;
1518
-
1519
- const char *s, *st, *text_end;
1520
- int numfields, fields, n, r, sol, ret;
1521
- int type, types, tag, permset, id;
1522
- size_t len;
1523
- char sep;
1524
-
1525
- switch (want_type) {
1526
- case ARCHIVE_ENTRY_ACL_TYPE_POSIX1E:
1527
- want_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
1528
- __LA_FALLTHROUGH;
1529
- case ARCHIVE_ENTRY_ACL_TYPE_ACCESS:
1530
- case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT:
1531
- numfields = 5;
1532
- break;
1533
- case ARCHIVE_ENTRY_ACL_TYPE_NFS4:
1534
- numfields = 6;
1535
- break;
1536
- default:
1537
- return (ARCHIVE_FATAL);
1538
- }
1539
-
1540
- ret = ARCHIVE_OK;
1541
- types = 0;
1542
- text_end = (text == NULL) ? text : text + length;
1543
-
1544
- while (text != NULL && length > 0 && *text != '\0') {
1545
- /*
1546
- * Parse the fields out of the next entry,
1547
- * advance 'text' to start of next entry.
1548
- */
1549
- fields = 0;
1550
- do {
1551
- const char *start, *end;
1552
- next_field(&text, &length, &start, &end, &sep);
1553
- if (fields < numfields) {
1554
- field[fields].start = start;
1555
- field[fields].end = end;
1556
- }
1557
- ++fields;
1558
- } while (sep == ':');
1559
-
1560
- /* Set remaining fields to blank. */
1561
- for (n = fields; n < numfields; ++n)
1562
- field[n].start = field[n].end = NULL;
1563
-
1564
- if (field[0].start == NULL || field[0].end == NULL) {
1565
- /* This should never happen */
1566
- return (ARCHIVE_FATAL);
1567
- }
1568
-
1569
- if (field[0].start == text_end) {
1570
- /*
1571
- * Empty entry: next_field() consumed the rest of the
1572
- * buffer as separators or whitespace, leaving
1573
- * field[0].start one past the end. 'text' is not
1574
- * guaranteed to be NUL terminated, so the byte after it
1575
- * must not be dereferenced.
1576
- */
1577
- ret = ARCHIVE_WARN;
1578
- continue;
1579
- }
1580
-
1581
- if (*(field[0].start) == '#') {
1582
- /* Comment, skip entry */
1583
- continue;
1584
- }
1585
-
1586
- n = 0;
1587
- sol = 0;
1588
- id = -1;
1589
- permset = 0;
1590
- name.start = name.end = NULL;
1591
-
1592
- if (want_type != ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
1593
- /* POSIX.1e ACLs */
1594
- /*
1595
- * Default keyword "default:user::rwx"
1596
- * if found, we have one more field
1597
- *
1598
- * We also support old Solaris extension:
1599
- * "defaultuser::rwx" is the default ACL corresponding
1600
- * to "user::rwx", etc. valid only for first field
1601
- */
1602
- s = field[0].start;
1603
- len = field[0].end - field[0].start;
1604
- if (*s == 'd' && (len == 1 || (len >= 7
1605
- && memcmp((s + 1), "efault", 6) == 0))) {
1606
- type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT;
1607
- if (len > 7)
1608
- field[0].start += 7;
1609
- else
1610
- n = 1;
1611
- } else
1612
- type = want_type;
1613
-
1614
- /* Check for a numeric ID in field n+1 or n+3. */
1615
- if (isint(field[n + 1].start, field[n + 1].end,
1616
- &id) < 0) {
1617
- ret = ARCHIVE_WARN;
1618
- continue;
1619
- }
1620
- /* Field n+3 is optional. */
1621
- if (id == -1 && fields > (n + 3) &&
1622
- isint(field[n + 3].start, field[n + 3].end,
1623
- &id) < 0) {
1624
- ret = ARCHIVE_WARN;
1625
- continue;
1626
- }
1627
-
1628
- tag = 0;
1629
- s = field[n].start;
1630
- len = field[n].end - field[n].start;
1631
-
1632
- if (len == 0) {
1633
- ret = ARCHIVE_WARN;
1634
- continue;
1635
- }
1636
-
1637
- st = s + 1;
1638
-
1639
- switch (*s) {
1640
- case 'u':
1641
- if (len == 1 || (len == 4
1642
- && memcmp(st, "ser", 3) == 0))
1643
- tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
1644
- break;
1645
- case 'g':
1646
- if (len == 1 || (len == 5
1647
- && memcmp(st, "roup", 4) == 0))
1648
- tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
1649
- break;
1650
- case 'o':
1651
- if (len == 1 || (len == 5
1652
- && memcmp(st, "ther", 4) == 0))
1653
- tag = ARCHIVE_ENTRY_ACL_OTHER;
1654
- break;
1655
- case 'm':
1656
- if (len == 1 || (len == 4
1657
- && memcmp(st, "ask", 3) == 0))
1658
- tag = ARCHIVE_ENTRY_ACL_MASK;
1659
- break;
1660
- default:
1661
- break;
1662
- }
1663
-
1664
- switch (tag) {
1665
- case ARCHIVE_ENTRY_ACL_OTHER:
1666
- case ARCHIVE_ENTRY_ACL_MASK:
1667
- if (fields == (n + 2)
1668
- && field[n + 1].start < field[n + 1].end
1669
- && ismode(field[n + 1].start,
1670
- field[n + 1].end, &permset)) {
1671
- /* This is Solaris-style "other:rwx" */
1672
- sol = 1;
1673
- } else if (fields == (n + 3) &&
1674
- field[n + 1].start < field[n + 1].end) {
1675
- /* Invalid mask or other field */
1676
- ret = ARCHIVE_WARN;
1677
- continue;
1678
- }
1679
- break;
1680
- case ARCHIVE_ENTRY_ACL_USER_OBJ:
1681
- case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
1682
- if (id != -1 ||
1683
- field[n + 1].start < field[n + 1].end) {
1684
- name = field[n + 1];
1685
- if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ)
1686
- tag = ARCHIVE_ENTRY_ACL_USER;
1687
- else
1688
- tag = ARCHIVE_ENTRY_ACL_GROUP;
1689
- }
1690
- break;
1691
- default:
1692
- /* Invalid tag, skip entry */
1693
- ret = ARCHIVE_WARN;
1694
- continue;
1695
- }
1696
-
1697
- /*
1698
- * Without "default:" we expect mode in field 3
1699
- * Exception: Solaris other and mask fields
1700
- */
1701
- if (permset == 0 && !ismode(field[n + 2 - sol].start,
1702
- field[n + 2 - sol].end, &permset)) {
1703
- /* Invalid mode, skip entry */
1704
- ret = ARCHIVE_WARN;
1705
- continue;
1706
- }
1707
- } else {
1708
- /* NFS4 ACLs */
1709
- s = field[0].start;
1710
- len = field[0].end - field[0].start;
1711
- tag = 0;
1712
-
1713
- switch (len) {
1714
- case 4:
1715
- if (memcmp(s, "user", 4) == 0)
1716
- tag = ARCHIVE_ENTRY_ACL_USER;
1717
- break;
1718
- case 5:
1719
- if (memcmp(s, "group", 5) == 0)
1720
- tag = ARCHIVE_ENTRY_ACL_GROUP;
1721
- break;
1722
- case 6:
1723
- if (memcmp(s, "owner@", 6) == 0)
1724
- tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
1725
- else if (memcmp(s, "group@", 6) == 0)
1726
- tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
1727
- break;
1728
- case 9:
1729
- if (memcmp(s, "everyone@", 9) == 0)
1730
- tag = ARCHIVE_ENTRY_ACL_EVERYONE;
1731
- break;
1732
- default:
1733
- break;
1734
- }
1735
-
1736
- if (tag == 0) {
1737
- /* Invalid tag, skip entry */
1738
- ret = ARCHIVE_WARN;
1739
- continue;
1740
- } else if (tag == ARCHIVE_ENTRY_ACL_USER ||
1741
- tag == ARCHIVE_ENTRY_ACL_GROUP) {
1742
- n = 1;
1743
- name = field[1];
1744
- if (isint(name.start, name.end, &id) < 0) {
1745
- ret = ARCHIVE_WARN;
1746
- continue;
1747
- }
1748
- } else
1749
- n = 0;
1750
-
1751
- if (!is_nfs4_perms(field[1 + n].start,
1752
- field[1 + n].end, &permset)) {
1753
- /* Invalid NFSv4 perms, skip entry */
1754
- ret = ARCHIVE_WARN;
1755
- continue;
1756
- }
1757
- if (!is_nfs4_flags(field[2 + n].start,
1758
- field[2 + n].end, &permset)) {
1759
- /* Invalid NFSv4 flags, skip entry */
1760
- ret = ARCHIVE_WARN;
1761
- continue;
1762
- }
1763
- s = field[3 + n].start;
1764
- len = field[3 + n].end - field[3 + n].start;
1765
- type = 0;
1766
- if (len == 4) {
1767
- if (memcmp(s, "deny", 4) == 0)
1768
- type = ARCHIVE_ENTRY_ACL_TYPE_DENY;
1769
- } else if (len == 5) {
1770
- if (memcmp(s, "allow", 5) == 0)
1771
- type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW;
1772
- else if (memcmp(s, "audit", 5) == 0)
1773
- type = ARCHIVE_ENTRY_ACL_TYPE_AUDIT;
1774
- else if (memcmp(s, "alarm", 5) == 0)
1775
- type = ARCHIVE_ENTRY_ACL_TYPE_ALARM;
1776
- }
1777
- if (type == 0) {
1778
- /* Invalid entry type, skip entry */
1779
- ret = ARCHIVE_WARN;
1780
- continue;
1781
- }
1782
- if (isint(field[4 + n].start, field[4 + n].end,
1783
- &id) < 0) {
1784
- ret = ARCHIVE_WARN;
1785
- continue;
1786
- }
1787
- }
1788
-
1789
- /* Add entry to the internal list. */
1790
- r = archive_acl_add_entry_len_l(acl, type, permset,
1791
- tag, id, name.start, name.end - name.start, sc);
1792
- if (r < ARCHIVE_WARN)
1793
- return (r);
1794
- if (r != ARCHIVE_OK)
1795
- ret = ARCHIVE_WARN;
1796
- types |= type;
1797
- }
1798
-
1799
- /* Reset ACL */
1800
- archive_acl_reset(acl, types);
1801
-
1802
- return (ret);
1803
- }
1804
-
1805
- /*
1806
- * Parse a string to a positive decimal integer. Returns true if
1807
- * the string is non-empty and consists only of decimal digits,
1808
- * false otherwise.
1809
- */
1810
- static int
1811
- isint(const char *start, const char *end, int *result)
1812
- {
1813
- int n = 0;
1814
- if (start >= end)
1815
- return (0);
1816
- while (start < end) {
1817
- if (*start < '0' || *start > '9')
1818
- return (0);
1819
- if (n > (INT_MAX / 10) ||
1820
- (n == INT_MAX / 10 && (*start - '0') >= INT_MAX % 10)) {
1821
- return (-1);
1822
- } else {
1823
- n *= 10;
1824
- n += *start - '0';
1825
- }
1826
- start++;
1827
- }
1828
- *result = n;
1829
- return (1);
1830
- }
1831
-
1832
- /*
1833
- * Parse a string as a mode field. Returns true if
1834
- * the string is non-empty and consists only of mode characters,
1835
- * false otherwise.
1836
- */
1837
- static int
1838
- ismode(const char *start, const char *end, int *permset)
1839
- {
1840
- const char *p;
1841
-
1842
- if (start >= end)
1843
- return (0);
1844
- p = start;
1845
- *permset = 0;
1846
- while (p < end) {
1847
- switch (*p++) {
1848
- case 'r': case 'R':
1849
- *permset |= ARCHIVE_ENTRY_ACL_READ;
1850
- break;
1851
- case 'w': case 'W':
1852
- *permset |= ARCHIVE_ENTRY_ACL_WRITE;
1853
- break;
1854
- case 'x': case 'X':
1855
- *permset |= ARCHIVE_ENTRY_ACL_EXECUTE;
1856
- break;
1857
- case '-':
1858
- break;
1859
- default:
1860
- return (0);
1861
- }
1862
- }
1863
- return (1);
1864
- }
1865
-
1866
- /*
1867
- * Parse a string as a NFS4 ACL permission field.
1868
- * Returns true if the string is non-empty and consists only of NFS4 ACL
1869
- * permission characters, false otherwise
1870
- */
1871
- static int
1872
- is_nfs4_perms(const char *start, const char *end, int *permset)
1873
- {
1874
- const char *p = start;
1875
-
1876
- while (p < end) {
1877
- switch (*p++) {
1878
- case 'r':
1879
- *permset |= ARCHIVE_ENTRY_ACL_READ_DATA;
1880
- break;
1881
- case 'w':
1882
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_DATA;
1883
- break;
1884
- case 'x':
1885
- *permset |= ARCHIVE_ENTRY_ACL_EXECUTE;
1886
- break;
1887
- case 'p':
1888
- *permset |= ARCHIVE_ENTRY_ACL_APPEND_DATA;
1889
- break;
1890
- case 'D':
1891
- *permset |= ARCHIVE_ENTRY_ACL_DELETE_CHILD;
1892
- break;
1893
- case 'd':
1894
- *permset |= ARCHIVE_ENTRY_ACL_DELETE;
1895
- break;
1896
- case 'a':
1897
- *permset |= ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES;
1898
- break;
1899
- case 'A':
1900
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES;
1901
- break;
1902
- case 'R':
1903
- *permset |= ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS;
1904
- break;
1905
- case 'W':
1906
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS;
1907
- break;
1908
- case 'c':
1909
- *permset |= ARCHIVE_ENTRY_ACL_READ_ACL;
1910
- break;
1911
- case 'C':
1912
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_ACL;
1913
- break;
1914
- case 'o':
1915
- *permset |= ARCHIVE_ENTRY_ACL_WRITE_OWNER;
1916
- break;
1917
- case 's':
1918
- *permset |= ARCHIVE_ENTRY_ACL_SYNCHRONIZE;
1919
- break;
1920
- case '-':
1921
- break;
1922
- default:
1923
- return(0);
1924
- }
1925
- }
1926
- return (1);
1927
- }
1928
-
1929
- /*
1930
- * Parse a string as a NFS4 ACL flags field.
1931
- * Returns true if the string is non-empty and consists only of NFS4 ACL
1932
- * flag characters, false otherwise
1933
- */
1934
- static int
1935
- is_nfs4_flags(const char *start, const char *end, int *permset)
1936
- {
1937
- const char *p = start;
1938
-
1939
- while (p < end) {
1940
- switch(*p++) {
1941
- case 'f':
1942
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT;
1943
- break;
1944
- case 'd':
1945
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT;
1946
- break;
1947
- case 'i':
1948
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY;
1949
- break;
1950
- case 'n':
1951
- *permset |=
1952
- ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT;
1953
- break;
1954
- case 'S':
1955
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS;
1956
- break;
1957
- case 'F':
1958
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS;
1959
- break;
1960
- case 'I':
1961
- *permset |= ARCHIVE_ENTRY_ACL_ENTRY_INHERITED;
1962
- break;
1963
- case '-':
1964
- break;
1965
- default:
1966
- return (0);
1967
- }
1968
- }
1969
- return (1);
1970
- }
1971
-
1972
- /*
1973
- * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *p is updated
1974
- * to point to just after the separator. *start points to the first
1975
- * character of the matched text and *end just after the last
1976
- * character of the matched identifier. In particular *end - *start
1977
- * is the length of the field body, not including leading or trailing
1978
- * whitespace.
1979
- */
1980
- static void
1981
- next_field(const char **p, size_t *l, const char **start,
1982
- const char **end, char *sep)
1983
- {
1984
- /* Skip leading whitespace to find start of field. */
1985
- while (*l > 0 && (**p == ' ' || **p == '\t' || **p == '\n')) {
1986
- (*p)++;
1987
- (*l)--;
1988
- }
1989
- *start = *p;
1990
-
1991
- /* Locate end of field, trim trailing whitespace if necessary */
1992
- while (*l > 0 && **p != ' ' && **p != '\t' && **p != '\n' && **p != ',' && **p != ':' && **p != '#') {
1993
- (*p)++;
1994
- (*l)--;
1995
- }
1996
- *end = *p;
1997
-
1998
- /* Scan for the separator. */
1999
- while (*l > 0 && **p != ',' && **p != ':' && **p != '\n' && **p != '#') {
2000
- (*p)++;
2001
- (*l)--;
2002
- }
2003
- if (*l > 0)
2004
- *sep = **p;
2005
- else
2006
- *sep = '\0';
2007
-
2008
- /* Handle in-field comments */
2009
- if (*sep == '#') {
2010
- while (*l > 0 && **p != ',' && **p != '\n') {
2011
- (*p)++;
2012
- (*l)--;
2013
- }
2014
- if (*l > 0)
2015
- *sep = **p;
2016
- else
2017
- *sep = '\0';
2018
- }
2019
-
2020
- /* Skip separator. */
2021
- if (*l > 0) {
2022
- (*p)++;
2023
- (*l)--;
2024
- }
2025
- }