Update vendor/libarchive to git e92cb619661b5b52da63867305442e22892a503d

Vendor changes (FreeBSD-related):
- store extended attributes with extattr_set_link() if no fd is provided
- add extended attribute tests to libarchive and bsdtar
- support the UF_HIDDEN file flag
This commit is contained in:
Martin Matuska 2017-03-23 23:44:31 +00:00
parent 22d7a1bf74
commit 854870e4b3
18 changed files with 982 additions and 304 deletions

View File

@ -552,6 +552,7 @@ LA_CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
# Alphabetize the rest unless there's a compelling reason
LA_CHECK_INCLUDE_FILE("acl/libacl.h" HAVE_ACL_LIBACL_H)
LA_CHECK_INCLUDE_FILE("attr/xattr.h" HAVE_ATTR_XATTR_H)
LA_CHECK_INCLUDE_FILE("ctype.h" HAVE_CTYPE_H)
LA_CHECK_INCLUDE_FILE("copyfile.h" HAVE_COPYFILE_H)
LA_CHECK_INCLUDE_FILE("direct.h" HAVE_DIRECT_H)
@ -597,6 +598,7 @@ LA_CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
LA_CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
LA_CHECK_INCLUDE_FILE("sys/acl.h" HAVE_SYS_ACL_H)
LA_CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H)
LA_CHECK_INCLUDE_FILE("sys/extattr.h" HAVE_SYS_EXTATTR_H)
LA_CHECK_INCLUDE_FILE("sys/ioctl.h" HAVE_SYS_IOCTL_H)
LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H)
LA_CHECK_INCLUDE_FILE("sys/mount.h" HAVE_SYS_MOUNT_H)
@ -612,6 +614,7 @@ LA_CHECK_INCLUDE_FILE("sys/utime.h" HAVE_SYS_UTIME_H)
LA_CHECK_INCLUDE_FILE("sys/utsname.h" HAVE_SYS_UTSNAME_H)
LA_CHECK_INCLUDE_FILE("sys/vfs.h" HAVE_SYS_VFS_H)
LA_CHECK_INCLUDE_FILE("sys/wait.h" HAVE_SYS_WAIT_H)
LA_CHECK_INCLUDE_FILE("sys/xattr.h" HAVE_SYS_XATTR_H)
LA_CHECK_INCLUDE_FILE("time.h" HAVE_TIME_H)
LA_CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
LA_CHECK_INCLUDE_FILE("utime.h" HAVE_UTIME_H)
@ -1532,60 +1535,105 @@ CHECK_FILE_OFFSET_BITS()
# Check for Extended Attribute libraries, headers, and functions
#
IF(ENABLE_XATTR)
LA_CHECK_INCLUDE_FILE(attr/xattr.h HAVE_ATTR_XATTR_H)
LA_CHECK_INCLUDE_FILE(sys/xattr.h HAVE_SYS_XATTR_H)
LA_CHECK_INCLUDE_FILE(sys/extattr.h HAVE_SYS_EXTATTR_H)
CHECK_LIBRARY_EXISTS(attr "setxattr" "" HAVE_LIBATTR)
IF(HAVE_LIBATTR)
SET(CMAKE_REQUIRED_LIBRARIES "attr")
ENDIF(HAVE_LIBATTR)
CHECK_SYMBOL_EXISTS(EXTATTR_NAMESPACE_USER "sys/types.h;sys/extattr.h" HAVE_DECL_EXTATTR_NAMESPACE_USER)
CHECK_FUNCTION_EXISTS_GLIBC(extattr_get_file HAVE_EXTATTR_GET_FILE)
CHECK_FUNCTION_EXISTS_GLIBC(extattr_list_file HAVE_EXTATTR_LIST_FILE)
CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_fd HAVE_EXTATTR_SET_FD)
CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_file HAVE_EXTATTR_SET_FILE)
CHECK_FUNCTION_EXISTS_GLIBC(fgetxattr HAVE_FGETXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(flistxattr HAVE_FLISTXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(fsetxattr HAVE_FSETXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(getxattr HAVE_GETXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(lgetxattr HAVE_LGETXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(listxattr HAVE_LISTXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(llistxattr HAVE_LLISTXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(lsetxattr HAVE_LSETXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(fgetea HAVE_FGETEA)
CHECK_FUNCTION_EXISTS_GLIBC(flistea HAVE_FLISTEA)
CHECK_FUNCTION_EXISTS_GLIBC(fsetea HAVE_FSETEA)
CHECK_FUNCTION_EXISTS_GLIBC(getea HAVE_GETEA)
CHECK_FUNCTION_EXISTS_GLIBC(lgetea HAVE_LGETEA)
CHECK_FUNCTION_EXISTS_GLIBC(listea HAVE_LISTEA)
CHECK_FUNCTION_EXISTS_GLIBC(llistea HAVE_LLISTEA)
CHECK_FUNCTION_EXISTS_GLIBC(lsetea HAVE_LSETEA)
CHECK_SYMBOL_EXISTS(XATTR_NOFOLLOW "sys/xattr.h" HAVE_DECL_XATTR_NOFOLLOW)
IF(HAVE_SYS_XATTR_H AND HAVE_DECL_XATTR_NOFOLLOW)
CHECK_FUNCTION_EXISTS(fgetxattr HAVE_FGETXATTR)
CHECK_FUNCTION_EXISTS(flistxattr HAVE_FLISTXATTR)
CHECK_FUNCTION_EXISTS(fsetxattr HAVE_FSETXATTR)
CHECK_FUNCTION_EXISTS(getxattr HAVE_GETXATTR)
CHECK_FUNCTION_EXISTS(listxattr HAVE_LISTXATTR)
CHECK_FUNCTION_EXISTS(setxattr HAVE_SETXATTR)
IF(HAVE_FGETXATTR AND
HAVE_FLISTXATTR AND
HAVE_FSETXATTR AND
HAVE_GETXATTR AND
HAVE_LISTXATTR AND
HAVE_SETXATTR)
SET(ARCHIVE_XATTR_DARWIN TRUE)
ENDIF()
ELSEIF(HAVE_SYS_EXTATTR_H AND HAVE_DECL_EXTATTR_NAMESPACE_USER)
# FreeBSD xattr support
CHECK_FUNCTION_EXISTS(extattr_get_fd HAVE_EXTATTR_GET_FD)
CHECK_FUNCTION_EXISTS(extattr_get_file HAVE_EXTATTR_GET_FILE)
CHECK_FUNCTION_EXISTS(extattr_get_link HAVE_EXTATTR_GET_LINK)
CHECK_FUNCTION_EXISTS(extattr_list_fd HAVE_EXTATTR_LIST_FD)
CHECK_FUNCTION_EXISTS(extattr_list_file HAVE_EXTATTR_LIST_FILE)
CHECK_FUNCTION_EXISTS(extattr_list_link HAVE_EXTATTR_LIST_LINK)
CHECK_FUNCTION_EXISTS(extattr_set_fd HAVE_EXTATTR_SET_FD)
CHECK_FUNCTION_EXISTS(extattr_set_link HAVE_EXTATTR_SET_LINK)
IF(HAVE_EXTATTR_GET_FD AND
HAVE_EXTATTR_GET_FILE AND
HAVE_EXTATTR_GET_LINK AND
HAVE_EXTATTR_LIST_FD AND
HAVE_EXTATTR_LIST_FILE AND
HAVE_EXTATTR_LIST_LINK AND
HAVE_EXTATTR_SET_FD AND
HAVE_EXTATTR_SET_LINK)
SET(ARCHIVE_XATTR_FREEBSD TRUE)
ENDIF()
ELSEIF(HAVE_SYS_XATTR_H OR HAVE_ATTR_XATTR_H)
# Linux xattr support
CHECK_FUNCTION_EXISTS_GLIBC(fgetxattr HAVE_FGETXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(flistxattr HAVE_FLISTXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(fsetxattr HAVE_FSETXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(getxattr HAVE_GETXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(lgetxattr HAVE_LGETXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(listxattr HAVE_LISTXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(llistxattr HAVE_LLISTXATTR)
CHECK_FUNCTION_EXISTS_GLIBC(lsetxattr HAVE_LSETXATTR)
IF(HAVE_FGETXATTR AND
HAVE_FLISTXATTR AND
HAVE_FSETXATTR AND
HAVE_GETXATTR AND
HAVE_LGETXATTR AND
HAVE_LISTXATTR AND
HAVE_LLISTXATTR AND
HAVE_LSETXATTR)
SET(ARCHIVE_XATTR_LINUX TRUE)
ENDIF()
ELSEIF(HAVE_SYS_EA_H)
# AIX xattr support
CHECK_FUNCTION_EXISTS(fgetea HAVE_FGETEA)
CHECK_FUNCTION_EXISTS(flistea HAVE_FLISTEA)
CHECK_FUNCTION_EXISTS(fsetea HAVE_FSETEA)
CHECK_FUNCTION_EXISTS(getea HAVE_GETEA)
CHECK_FUNCTION_EXISTS(lgetea HAVE_LGETEA)
CHECK_FUNCTION_EXISTS(listea HAVE_LISTEA)
CHECK_FUNCTION_EXISTS(llistea HAVE_LLISTEA)
CHECK_FUNCTION_EXISTS(lsetea HAVE_LSETEA)
IF(HAVE_FGETEA AND
HAVE_FLISTEA AND
HAVE_FSETEA AND
HAVE_GETEA AND
HAVE_LGETEA AND
HAVE_LISTEA AND
HAVE_LLISTEA AND
HAVE_LSETEA)
SET(ARCHIVE_XATTR_AIX TRUE)
ENDIF()
ENDIF()
IF(ARCHIVE_XATTR_DARWIN)
MESSAGE(STATUS "Extended attributes support: Darwin")
ELSEIF(ARCHIVE_XATTR_FREEBSD)
MESSAGE(STATUS "Extended attributes support: FreeBSD")
ELSEIF(ARCHIVE_XATTR_LINUX)
MESSAGE(STATUS "Extended attributes support: Linux")
ELSEIF(ARCHIVE_XATTR_AIX)
MESSAGE(STATUS "Extended attributes support: AIX")
ELSE()
MESSAGE(STATUS "Extended attributes support: none")
ENDIF()
ELSE(ENABLE_XATTR)
SET(HAVE_ATTR_LIB FALSE)
SET(HAVE_ATTR_XATTR_H FALSE)
SET(HAVE_DECL_EXTATTR_NAMESPACE_USER FALSE)
SET(HAVE_EXTATTR_GET_FILE FALSE)
SET(HAVE_EXTATTR_LIST_FILE FALSE)
SET(HAVE_EXTATTR_SET_FD FALSE)
SET(HAVE_EXTATTR_SET_FILE FALSE)
SET(HAVE_FGETEA FALSE)
SET(HAVE_FGETXATTR FALSE)
SET(HAVE_FLISTEA FALSE)
SET(HAVE_FLISTXATTR FALSE)
SET(HAVE_FSETEA FALSE)
SET(HAVE_FSETXATTR FALSE)
SET(HAVE_GETEA FALSE)
SET(HAVE_GETXATTR FALSE)
SET(HAVE_LGETEA FALSE)
SET(HAVE_LGETXATTR FALSE)
SET(HAVE_LISTEA FALSE)
SET(HAVE_LISTXATTR FALSE)
SET(HAVE_LLISTEA FALSE)
SET(HAVE_LLISTXATTR FALSE)
SET(HAVE_LSETEA FALSE)
SET(HAVE_LSETXATTR FALSE)
SET(HAVE_SYS_EXTATTR_H FALSE)
SET(HAVE_SYS_XATTR_H FALSE)
SET(ARCHIVE_XATTR_DARWIN FALSE)
SET(ARCHIVE_XATTR_FREEBSD FALSE)
SET(ARCHIVE_XATTR_LINUX FALSE)
SET(ARCHIVE_XATTR_AIX FALSE)
ENDIF(ENABLE_XATTR)
#

View File

@ -128,6 +128,7 @@ libarchive_la_SOURCES= \
libarchive/archive_pathmatch.h \
libarchive/archive_platform.h \
libarchive/archive_platform_acl.h \
libarchive/archive_platform_xattr.h \
libarchive/archive_ppmd_private.h \
libarchive/archive_ppmd7.c \
libarchive/archive_ppmd7_private.h \
@ -618,6 +619,7 @@ libarchive_test_SOURCES= \
libarchive/test/test_write_format_zip_zip64.c \
libarchive/test/test_write_open_memory.c \
libarchive/test/test_write_read_format_zip.c \
libarchive/test/test_xattr_platform.c \
libarchive/test/test_zip_filename_encoding.c
libarchive_test_CPPFLAGS= \
@ -1009,6 +1011,7 @@ bsdtar_test_SOURCES= \
tar/test/test_option_s.c \
tar/test/test_option_uid_uname.c \
tar/test/test_option_uuencode.c \
tar/test/test_option_xattrs.c \
tar/test/test_option_xz.c \
tar/test/test_option_z.c \
tar/test/test_patterns.c \

View File

@ -302,6 +302,18 @@ typedef uint64_t uintmax_t;
/* SHA512 via ARCHIVE_CRYPTO_SHA512_WIN supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA512_WIN 1
/* AIX xattr support */
#cmakedefine ARCHIVE_XATTR_AIX 1
/* Darwin xattr support */
#cmakedefine ARCHIVE_XATTR_DARWIN 1
/* FreeBSD xattr support */
#cmakedefine ARCHIVE_XATTR_FREEBSD 1
/* Linux xattr support */
#cmakedefine ARCHIVE_XATTR_LINUX 1
/* Version number of bsdcpio */
#cmakedefine BSDCPIO_VERSION_STRING "${BSDCPIO_VERSION_STRING}"
@ -463,6 +475,10 @@ typedef uint64_t uintmax_t;
don't. */
#cmakedefine HAVE_DECL_UINTMAX_MAX 1
/* Define to 1 if you have the declaration of `XATTR_NOFOLLOW', and to 0 if
you don't. */
#cmakedefine HAVE_DECL_XATTR_NOFOLLOW 1
/* Define to 1 if you have the <direct.h> header file. */
#cmakedefine HAVE_DIRECT_H 1

View File

@ -253,7 +253,7 @@ esac
# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([acl/libacl.h])
AC_CHECK_HEADERS([acl/libacl.h attr/xattr.h])
AC_CHECK_HEADERS([copyfile.h ctype.h])
AC_CHECK_HEADERS([errno.h ext2fs/ext2_fs.h fcntl.h grp.h])
@ -287,11 +287,11 @@ AS_VAR_IF([ac_cv_have_decl_FS_IOC_GETFLAGS], [yes],
AC_CHECK_HEADERS([locale.h membership.h paths.h poll.h pthread.h pwd.h])
AC_CHECK_HEADERS([readpassphrase.h signal.h spawn.h])
AC_CHECK_HEADERS([stdarg.h stdint.h stdlib.h string.h])
AC_CHECK_HEADERS([sys/acl.h sys/cdefs.h sys/extattr.h])
AC_CHECK_HEADERS([sys/acl.h sys/cdefs.h sys/ea.h sys/extattr.h])
AC_CHECK_HEADERS([sys/ioctl.h sys/mkdev.h sys/mount.h])
AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/richacl.h])
AC_CHECK_HEADERS([sys/select.h sys/statfs.h sys/statvfs.h])
AC_CHECK_HEADERS([sys/time.h sys/utime.h sys/utsname.h sys/vfs.h])
AC_CHECK_HEADERS([sys/time.h sys/utime.h sys/utsname.h sys/vfs.h sys/xattr.h])
AC_CHECK_HEADERS([time.h unistd.h utime.h wchar.h wctype.h])
AC_CHECK_HEADERS([windows.h])
# check windows.h first; the other headers require it.
@ -675,18 +675,108 @@ AC_ARG_ENABLE([xattr],
[Disable Extended Attributes support (default: check)]))
if test "x$enable_xattr" != "xno"; then
AC_CHECK_HEADERS([attr/xattr.h])
AC_CHECK_HEADERS([sys/xattr.h sys/ea.h])
AC_SEARCH_LIBS([setxattr], [attr])
AC_CHECK_FUNCS([extattr_get_file extattr_list_file])
AC_CHECK_FUNCS([extattr_set_fd extattr_set_file])
AC_CHECK_FUNCS([fgetxattr flistxattr fsetxattr getxattr])
AC_CHECK_FUNCS([lgetxattr listxattr llistxattr lsetxattr])
AC_CHECK_FUNCS([fgetea flistea fsetea getea])
AC_CHECK_FUNCS([lgetea listea llistea lsetea])
AC_CHECK_DECLS([EXTATTR_NAMESPACE_USER], [], [], [#include <sys/types.h>
AC_SEARCH_LIBS([setxattr], [attr])
AC_CHECK_DECLS([EXTATTR_NAMESPACE_USER], [], [], [#include <sys/types.h>
#include <sys/extattr.h>
])
AC_CHECK_DECLS([XATTR_NOFOLLOW], [], [], [#include <sys/xattr.h>
])
if test "x$ac_cv_header_sys_xattr_h" = "xyes" \
-a "x$ac_cv_have_decl_XATTR_NOFOLLOW" = "xyes"; then
# Darwin extended attributes support
AC_CACHE_VAL([ac_cv_archive_xattr_darwin],
[AC_CHECK_FUNCS(fgetxattr \
flistxattr \
fsetxattr \
getxattr \
listxattr \
setxattr,
[ac_cv_archive_xattr_darwin=yes],
[ac_cv_archive_xattr_darwin=no],
[#include <sys/xattr.h>
])
]
)
elif test "x$ac_cv_header_sys_extattr_h" = "xyes" \
-a "x$ac_cv_have_decl_EXTATTR_NAMESPACE_USER" = "xyes"; then
# FreeBSD extended attributes support
AC_CACHE_VAL([ac_cv_archive_xattr_freebsd],
[AC_CHECK_FUNCS(extattr_get_fd \
extattr_get_file \
extattr_get_link \
extattr_list_fd \
extattr_list_file \
extattr_list_link \
extattr_set_fd \
extattr_set_link,
[ac_cv_archive_xattr_freebsd=yes],
[ac_cv_archive_xattr_freebsd=no],
[#include <sys/types.h>
#include <sys/extattr.h>
])
]
)
elif test "x$ac_cv_header_sys_xattr_h" = "xyes" \
-o "x$ac_cv_header_attr_xattr_h" = "xyes"; then
# Linux extended attributes support
AC_CACHE_VAL([ac_cv_archive_xattr_linux],
[AC_CHECK_FUNCS(fgetxattr \
flistxattr \
fsetxattr \
getxattr \
lgetxattr \
listxattr \
llistxattr \
lsetxattr,
[ac_cv_archive_xattr_linux=yes],
[ac_cv_archive_xattr_linux=no],
[#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#endif
#if HAVE_ATTR_XATTR_H
#include <attr/xatr.h>
#endif
])
]
)
elif test "x$ac_cv_header_sys_ea_h" = "xyes"; then
# AIX extended attributes support
AC_CACHE_VAL([ac_cv_archive_xattr_aix],
[AC_CHECK_FUNCS(fgetea \
flistea \
fsetea \
getea \
lgetea \
listea \
llistea \
lsetea,
[ac_cv_archive_xattr_aix=yes],
[ac_cv_archive_xattr_aix=no],
[#include <sys/ea.h>
])
]
)
fi
AC_MSG_CHECKING([for extended attributes support])
if test "x$ac_cv_archive_xattr_linux" = "xyes"; then
AC_DEFINE([ARCHIVE_XATTR_LINUX], [1], [Linux xattr support])
AC_MSG_RESULT([Linux])
elif test "x$ac_cv_archive_xattr_darwin" = "xyes"; then
AC_DEFINE([ARCHIVE_XATTR_DARWIN], [1], [Darwin xattr support])
AC_MSG_RESULT([Darwin])
elif test "x$ac_cv_archive_xattr_freebsd" = "xyes"; then
AC_DEFINE([ARCHIVE_XATTR_FREEBSD], [1], [FreeBSD xattr support])
AC_MSG_RESULT([FreeBSD])
elif test "x$ac_cv_archive_xattr_aix" = "xyes"; then
AC_DEFINE([ARCHIVE_XATTR_AIX], [1], [AIX xattr support])
AC_MSG_RESULT([AIX])
else
AC_MSG_RESULT([none])
fi
fi
# Check for ACL support

View File

@ -49,6 +49,7 @@ SET(libarchive_SOURCES
archive_pathmatch.h
archive_platform.h
archive_platform_acl.h
archive_platform_xattr.h
archive_ppmd_private.h
archive_ppmd7.c
archive_ppmd7_private.h

View File

@ -1708,6 +1708,9 @@ static struct flag {
#ifdef UF_COMPRESSED
{ "nocompressed",L"nocompressed", UF_COMPRESSED, 0 },
#endif
#ifdef UF_HIDDEN
{ "nohidden", L"nohidden", UF_HIDDEN, 0 },
#endif
#if defined(FS_UNRM_FL)
{ "nouunlink", L"nouunlink", FS_UNRM_FL, 0},
#elif defined(EXT2_UNRM_FL)

View File

@ -0,0 +1,41 @@
/*-
* Copyright (c) 2017 Martin Matuska
* 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$
*/
/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */
#ifndef ARCHIVE_PLATFORM_XATTR_H_INCLUDED
#define ARCHIVE_PLATFORM_XATTR_H_INCLUDED
/*
* Determine if we support extended attributes
*/
#if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_FREEBSD || \
ARCHIVE_XATTR_AIX
#define ARCHIVE_XATTR_SUPPORT 1
#endif
#endif /* ARCHIVE_PLATFORM_XATTR_H_INCLUDED */

View File

@ -423,12 +423,10 @@ setup_mac_metadata(struct archive_read_disk *a,
}
#endif
#if (HAVE_FGETXATTR && HAVE_FLISTXATTR && HAVE_LISTXATTR && \
HAVE_LLISTXATTR && HAVE_GETXATTR && HAVE_LGETXATTR) || \
(HAVE_FGETEA && HAVE_FLISTEA && HAVE_LISTEA)
#if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_AIX
/*
* Linux and AIX extended attribute support.
* Linux, Darwin and AIX extended attribute support.
*
* TODO: By using a stack-allocated buffer for the first
* call to getxattr(), we might be able to avoid the second
@ -446,21 +444,32 @@ setup_xattr(struct archive_read_disk *a,
ssize_t size;
void *value = NULL;
#if HAVE_FGETXATTR
if (fd >= 0)
if (fd >= 0) {
#if ARCHIVE_XATTR_LINUX
size = fgetxattr(fd, name, NULL, 0);
else if (!a->follow_symlinks)
size = lgetxattr(accpath, name, NULL, 0);
else
size = getxattr(accpath, name, NULL, 0);
#elif HAVE_FGETEA
if (fd >= 0)
#elif ARCHIVE_XATTR_DARWIN
size = fgetxattr(fd, name, NULL, 0, 0, 0);
#elif ARCHIVE_XATTR_AIX
size = fgetea(fd, name, NULL, 0);
else if (!a->follow_symlinks)
#endif
} else if (!a->follow_symlinks) {
#if ARCHIVE_XATTR_LINUX
size = lgetxattr(accpath, name, NULL, 0);
#elif ARCHIVE_XATTR_DARWIN
size = getxattr(accpath, name, NULL, 0, 0, XATTR_NOFOLLOW);
#elif ARCHIVE_XATTR_AIX
size = lgetea(accpath, name, NULL, 0);
else
#endif
} else {
#if ARCHIVE_XATTR_LINUX
size = getxattr(accpath, name, NULL, 0);
#elif ARCHIVE_XATTR_DARWIN
size = getxattr(accpath, name, NULL, 0, 0, 0);
#elif ARCHIVE_XATTR_AIX
size = getea(accpath, name, NULL, 0);
#endif
}
if (size == -1) {
archive_set_error(&a->archive, errno,
@ -473,21 +482,32 @@ setup_xattr(struct archive_read_disk *a,
return (ARCHIVE_FATAL);
}
#if HAVE_FGETXATTR
if (fd >= 0)
if (fd >= 0) {
#if ARCHIVE_XATTR_LINUX
size = fgetxattr(fd, name, value, size);
else if (!a->follow_symlinks)
size = lgetxattr(accpath, name, value, size);
else
size = getxattr(accpath, name, value, size);
#elif HAVE_FGETEA
if (fd >= 0)
#elif ARCHIVE_XATTR_DARWIN
size = fgetxattr(fd, name, value, size, 0, 0);
#elif ARCHIVE_XATTR_AIX
size = fgetea(fd, name, value, size);
else if (!a->follow_symlinks)
#endif
} else if (!a->follow_symlinks) {
#if ARCHIVE_XATTR_LINUX
size = lgetxattr(accpath, name, value, size);
#elif ARCHIVE_XATTR_DARWIN
size = getxattr(accpath, name, value, size, 0, XATTR_NOFOLLOW);
#elif ARCHIVE_XATTR_AIX
size = lgetea(accpath, name, value, size);
else
#endif
} else {
#if ARCHIVE_XATTR_LINUX
size = getxattr(accpath, name, value, size);
#elif ARCHIVE_XATTR_DARWIN
size = getxattr(accpath, name, value, size, 0, 0);
#elif ARCHIVE_XATTR_AIX
size = getea(accpath, name, value, size);
#endif
}
if (size == -1) {
archive_set_error(&a->archive, errno,
@ -517,21 +537,31 @@ setup_xattrs(struct archive_read_disk *a,
return (ARCHIVE_WARN);
}
#if HAVE_FLISTXATTR
if (*fd >= 0)
if (*fd >= 0) {
#if ARCHIVE_XATTR_LINUX
list_size = flistxattr(*fd, NULL, 0);
else if (!a->follow_symlinks)
list_size = llistxattr(path, NULL, 0);
else
list_size = listxattr(path, NULL, 0);
#elif HAVE_FLISTEA
if (*fd >= 0)
#elif ARCHIVE_XATTR_DARWIN
list_size = flistxattr(*fd, NULL, 0, 0);
#elif ARCHIVE_XATTR_AIX
list_size = flistea(*fd, NULL, 0);
else if (!a->follow_symlinks)
#endif
} else if (!a->follow_symlinks) {
#if ARCHIVE_XATTR_LINUX
list_size = llistxattr(path, NULL, 0);
#elif ARCHIVE_XATTR_DARWIN
list_size = listxattr(path, NULL, 0, XATTR_NOFOLLOW);
#elif ARCHIVE_XATTR_AIX
list_size = llistea(path, NULL, 0);
else
#endif
} else {
#if ARCHIVE_XATTR_LINUX
list_size = listxattr(path, NULL, 0);
#elif ARCHIVE_XATTR_DARWIN
list_size = listxattr(path, NULL, 0, 0);
#elif ARCHIVE_XATTR_AIX
list_size = listea(path, NULL, 0);
#endif
}
if (list_size == -1) {
if (errno == ENOTSUP || errno == ENOSYS)
@ -549,21 +579,31 @@ setup_xattrs(struct archive_read_disk *a,
return (ARCHIVE_FATAL);
}
#if HAVE_FLISTXATTR
if (*fd >= 0)
if (*fd >= 0) {
#if ARCHIVE_XATTR_LINUX
list_size = flistxattr(*fd, list, list_size);
else if (!a->follow_symlinks)
list_size = llistxattr(path, list, list_size);
else
list_size = listxattr(path, list, list_size);
#elif HAVE_FLISTEA
if (*fd >= 0)
#elif ARCHIVE_XATTR_DARWIN
list_size = flistxattr(*fd, list, list_size, 0);
#elif ARCHIVE_XATTR_AIX
list_size = flistea(*fd, list, list_size);
else if (!a->follow_symlinks)
#endif
} else if (!a->follow_symlinks) {
#if ARCHIVE_XATTR_LINUX
list_size = llistxattr(path, list, list_size);
#elif ARCHIVE_XATTR_DARWIN
list_size = listxattr(path, list, list_size, XATTR_NOFOLLOW);
#elif ARCHIVE_XATTR_AIX
list_size = llistea(path, list, list_size);
else
#endif
} else {
#if ARCHIVE_XATTR_LINUX
list_size = listxattr(path, list, list_size);
#elif ARCHIVE_XATTR_DARWIN
list_size = listxattr(path, list, list_size, 0);
#elif ARCHIVE_XATTR_AIX
list_size = listea(path, list, list_size);
#endif
}
if (list_size == -1) {
archive_set_error(&a->archive, errno,
@ -583,8 +623,7 @@ setup_xattrs(struct archive_read_disk *a,
return (ARCHIVE_OK);
}
#elif HAVE_EXTATTR_GET_FILE && HAVE_EXTATTR_LIST_FILE && \
HAVE_DECL_EXTATTR_NAMESPACE_USER
#elif ARCHIVE_XATTR_FREEBSD
/*
* FreeBSD extattr interface.

View File

@ -39,9 +39,9 @@ __FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_EXTATTR_H
#include <sys/extattr.h>
#endif
#if defined(HAVE_SYS_XATTR_H)
#if HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#elif defined(HAVE_ATTR_XATTR_H)
#elif HAVE_ATTR_XATTR_H
#include <attr/xattr.h>
#endif
#ifdef HAVE_SYS_EA_H
@ -664,8 +664,21 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry)
}
#endif
if (a->flags & ARCHIVE_EXTRACT_XATTR)
if (a->flags & ARCHIVE_EXTRACT_XATTR) {
#if ARCHIVE_XATTR_DARWIN
/*
* On MacOS, extended attributes get stored in mac_metadata,
* too. If we intend to extract mac_metadata and it is present
* we skip extracting extended attributes.
*/
size_t metadata_size;
if ((a->flags & ARCHIVE_EXTRACT_MAC_METADATA) == 0 ||
archive_entry_mac_metadata(a->entry,
&metadata_size) == NULL || metadata_size == 0)
#endif
a->todo |= TODO_XATTR;
}
if (a->flags & ARCHIVE_EXTRACT_FFLAGS)
a->todo |= TODO_FFLAGS;
if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) {
@ -4070,9 +4083,9 @@ fixup_appledouble(struct archive_write_disk *a, const char *pathname)
}
#endif
#if HAVE_LSETXATTR || HAVE_LSETEA
#if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_AIX
/*
* Restore extended attributes - Linux and AIX implementations:
* Restore extended attributes - Linux, Darwin and AIX implementations:
* AIX' ea interface is syntaxwise identical to the Linux xattr interface.
*/
static int
@ -4092,20 +4105,22 @@ set_xattrs(struct archive_write_disk *a)
strncmp(name, "xfsroot.", 8) != 0 &&
strncmp(name, "system.", 7) != 0) {
int e;
#if HAVE_FSETXATTR
if (a->fd >= 0)
if (a->fd >= 0) {
#if ARCHIVE_XATTR_LINUX
e = fsetxattr(a->fd, name, value, size, 0);
else
#elif HAVE_FSETEA
if (a->fd >= 0)
#elif ARCHIVE_XATTR_DARWIN
e = fsetxattr(a->fd, name, value, size, 0, 0);
#elif ARCHIVE_XATTR_AIX
e = fsetea(a->fd, name, value, size, 0);
else
#endif
{
#if HAVE_LSETXATTR
} else {
#if ARCHIVE_XATTR_LINUX
e = lsetxattr(archive_entry_pathname(entry),
name, value, size, 0);
#elif HAVE_LSETEA
#elif ARCHIVE_XATTR_DARWIN
e = setxattr(archive_entry_pathname(entry),
name, value, size, 0, XATTR_NOFOLLOW);
#elif ARCHIVE_XATTR_AIX
e = lsetea(archive_entry_pathname(entry),
name, value, size, 0);
#endif
@ -4134,7 +4149,7 @@ set_xattrs(struct archive_write_disk *a)
}
return (ret);
}
#elif HAVE_EXTATTR_SET_FILE && HAVE_DECL_EXTATTR_NAMESPACE_USER
#elif ARCHIVE_XATTR_FREEBSD
/*
* Restore extended attributes - FreeBSD implementation
*/
@ -4169,15 +4184,12 @@ set_xattrs(struct archive_write_disk *a)
continue;
}
errno = 0;
#if HAVE_EXTATTR_SET_FD
if (a->fd >= 0)
if (a->fd >= 0) {
e = extattr_set_fd(a->fd, namespace, name,
value, size);
else
#endif
/* TODO: should we use extattr_set_link() instead? */
{
e = extattr_set_file(
} else {
e = extattr_set_link(
archive_entry_pathname(entry), namespace,
name, value, size);
}

View File

@ -25,138 +25,235 @@
* $FreeBSD$
*/
/* FreeBSD 5.0 and later have ACL and extattr support. */
#include <osreldate.h>
/* FreeBSD 5.0 and later has ACL and extattr support. */
#if __FreeBSD__ > 4
#define HAVE_ACL_CREATE_ENTRY 1
#define HAVE_ACL_GET_FD_NP 1
#define HAVE_ACL_GET_LINK_NP 1
#define HAVE_ACL_GET_PERM_NP 1
#define HAVE_ACL_INIT 1
#define HAVE_ACL_SET_FD 1
#define HAVE_ACL_SET_FD_NP 1
#define HAVE_ACL_SET_FILE 1
#define HAVE_ACL_USER 1
#define HAVE_EXTATTR_GET_FILE 1
#define HAVE_EXTATTR_LIST_FILE 1
#define HAVE_EXTATTR_SET_FD 1
#define HAVE_EXTATTR_SET_FILE 1
#define HAVE_STRUCT_XVFSCONF 1
#define HAVE_SYS_ACL_H 1
#define HAVE_SYS_EXTATTR_H 1
#endif
#define ARCHIVE_ACL_FREEBSD 1
#define HAVE_ACL_GET_PERM_NP 1
#define HAVE_ARC4RANDOM_BUF 1
#define HAVE_EXTATTR_GET_FILE 1
#define HAVE_EXTATTR_LIST_FILE 1
#define HAVE_EXTATTR_SET_FD 1
#define HAVE_EXTATTR_SET_FILE 1
#define HAVE_STRUCT_XVFSCONF 1
#define HAVE_SYS_ACL_H 1
#define HAVE_SYS_EXTATTR_H 1
#if __FreeBSD__ > 7
/* FreeBSD 8.0 and later has NFSv4 ACL support */
#define ARCHIVE_ACL_FREEBSD_NFS4 1
#define HAVE_ACL_GET_LINK_NP 1
#define HAVE_ACL_IS_TRIVIAL_NP 1
#define HAVE_ACL_SET_LINK_NP 1
#endif /* __FreeBSD__ > 7 */
#endif /* __FreeBSD__ > 4 */
#ifdef WITH_OPENSSL
#define HAVE_OPENSSL_MD5_H 1
#define HAVE_OPENSSL_RIPEMD_H 1
#define HAVE_OPENSSL_SHA_H 1
#define HAVE_SHA384 1
#define HAVE_SHA512 1
#define HAVE_LIBCRYPTO 1
#define HAVE_OPENSSL_EVP_H 1
#define HAVE_OPENSSL_MD5_H 1
#define HAVE_OPENSSL_RIPEMD_H 1
#define HAVE_OPENSSL_SHA_H 1
#define HAVE_OPENSSL_SHA256_INIT 1
#define HAVE_OPENSSL_SHA384_INIT 1
#define HAVE_OPENSSL_SHA512_INIT 1
#define HAVE_PKCS5_PBKDF2_HMAC_SHA1 1
#define HAVE_SHA256 1
#define HAVE_SHA384 1
#define HAVE_SHA512 1
#else
#define HAVE_LIBMD 1
#define HAVE_MD5_H 1
#define HAVE_MD5INIT 1
#define HAVE_RIPEMD_H 1
#define HAVE_SHA_H 1
#define HAVE_SHA1 1
#define HAVE_SHA1_INIT 1
#define HAVE_SHA256 1
#define HAVE_SHA256_H 1
#define HAVE_SHA256_INIT 1
#define HAVE_SHA512 1
#define HAVE_SHA512_H 1
#define HAVE_SHA512_INIT 1
#endif
#define HAVE_BSDXML_H 1
#define HAVE_BZLIB_H 1
#define HAVE_CHFLAGS 1
#define HAVE_CHOWN 1
#define HAVE_DECL_INT64_MAX 1
#define HAVE_DECL_INT64_MIN 1
#define HAVE_DECL_SIZE_MAX 1
#define HAVE_DECL_SSIZE_MAX 1
#define HAVE_DECL_STRERROR_R 1
#define HAVE_DECL_UINT32_MAX 1
#define HAVE_DECL_UINT64_MAX 1
#define HAVE_DIRENT_H 1
#define HAVE_EFTYPE 1
#define HAVE_EILSEQ 1
#define HAVE_ERRNO_H 1
#define HAVE_FCHDIR 1
#define HAVE_FCHFLAGS 1
#define HAVE_FCHMOD 1
#define HAVE_FCHOWN 1
#define HAVE_FCNTL 1
#define HAVE_FCNTL_H 1
#define HAVE_FSEEKO 1
#define HAVE_FSTAT 1
#define HAVE_FTRUNCATE 1
#define HAVE_FUTIMES 1
#define HAVE_GETEUID 1
#define HAVE_GETGRGID_R 1
#define HAVE_GETPID 1
#define HAVE_GETPWUID_R 1
#define HAVE_GRP_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_LCHFLAGS 1
#define HAVE_LCHMOD 1
#define HAVE_LCHOWN 1
#define HAVE_LIMITS_H 1
#define HAVE_LINK 1
#define HAVE_LSTAT 1
#define HAVE_LUTIMES 1
#define HAVE_MALLOC 1
#define HAVE_MD5 1
#define HAVE_MD5_H 1
#define HAVE_MEMMOVE 1
#define HAVE_MKDIR 1
#define HAVE_MKFIFO 1
#define HAVE_MKNOD 1
#define HAVE_PIPE 1
#define HAVE_POLL 1
#define HAVE_POLL_H 1
#define HAVE_PWD_H 1
#define HAVE_READLINK 1
#define HAVE_RMD160 1
#define HAVE_SELECT 1
#define HAVE_SETENV 1
#define HAVE_SHA_H 1
#define HAVE_SHA1 1
#define HAVE_SHA256 1
#define HAVE_SHA256_H 1
#define HAVE_SIGNAL_H 1
#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRCHR 1
#define HAVE_STRDUP 1
#define HAVE_STRERROR 1
#define HAVE_STRERROR_R 1
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_STRRCHR 1
#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1
#define HAVE_STRUCT_STAT_ST_FLAGS 1
#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
#define HAVE_STRUCT_TM_TM_GMTOFF 1
#define HAVE_SYMLINK 1
#define HAVE_SYS_CDEFS_H 1
#define HAVE_SYS_IOCTL_H 1
#define HAVE_SYS_MOUNT_H 1
#define HAVE_SYS_PARAM_H 1
#define HAVE_SYS_SELECT_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TYPES_H 1
#undef HAVE_SYS_UTIME_H
#define HAVE_SYS_UTSNAME_H 1
#define HAVE_SYS_WAIT_H 1
#define HAVE_TIMEGM 1
#define HAVE_TZSET 1
#define HAVE_UNISTD_H 1
#define HAVE_UNSETENV 1
#define HAVE_UTIME 1
#define HAVE_UTIMES 1
#define HAVE_UTIME_H 1
#define HAVE_VFORK 1
#define HAVE_WCHAR_H 1
#define HAVE_WCSCPY 1
#define HAVE_WCSLEN 1
#define HAVE_WCTOMB 1
#define HAVE_WMEMCMP 1
#define HAVE_WMEMCPY 1
#define HAVE_ZLIB_H 1
#define TIME_WITH_SYS_TIME 1
#define HAVE_BSDXML_H 1
#define HAVE_BZLIB_H 1
#define HAVE_CHFLAGS 1
#define HAVE_CHOWN 1
#define HAVE_CHROOT 1
#define HAVE_CTIME_R 1
#define HAVE_CTYPE_H 1
#define HAVE_DECL_EXTATTR_NAMESPACE_USER 1
#define HAVE_DECL_INT32_MAX 1
#define HAVE_DECL_INT32_MIN 1
#define HAVE_DECL_INT64_MAX 1
#define HAVE_DECL_INT64_MIN 1
#define HAVE_DECL_INTMAX_MAX 1
#define HAVE_DECL_INTMAX_MIN 1
#define HAVE_DECL_SIZE_MAX 1
#define HAVE_DECL_SSIZE_MAX 1
#define HAVE_DECL_STRERROR_R 1
#define HAVE_DECL_UINT32_MAX 1
#define HAVE_DECL_UINT64_MAX 1
#define HAVE_DECL_UINTMAX_MAX 1
#define HAVE_DIRENT_H 1
#define HAVE_DLFCN_H 1
#define HAVE_D_MD_ORDER 1
#define HAVE_EFTYPE 1
#define HAVE_EILSEQ 1
#define HAVE_ERRNO_H 1
#define HAVE_FCHDIR 1
#define HAVE_FCHFLAGS 1
#define HAVE_FCHMOD 1
#define HAVE_FCHOWN 1
#define HAVE_FCNTL 1
#define HAVE_FCNTL_H 1
#define HAVE_FDOPENDIR 1
#define HAVE_FORK 1
#define HAVE_FSEEKO 1
#define HAVE_FSTAT 1
#define HAVE_FSTATAT 1
#define HAVE_FSTATFS 1
#define HAVE_FSTATVFS 1
#define HAVE_FTRUNCATE 1
#define HAVE_FUTIMES 1
#define HAVE_FUTIMESAT 1
#define HAVE_GETEUID 1
#define HAVE_GETGRGID_R 1
#define HAVE_GETGRNAM_R 1
#define HAVE_GETPID 1
#define HAVE_GETPWNAM_R 1
#define HAVE_GETPWUID_R 1
#define HAVE_GETVFSBYNAME 1
#define HAVE_GMTIME_R 1
#define HAVE_GRP_H 1
#define HAVE_INTMAX_T 1
#define HAVE_INTTYPES_H 1
#define HAVE_LANGINFO_H 1
#define HAVE_LCHFLAGS 1
#define HAVE_LCHMOD 1
#define HAVE_LCHOWN 1
#define HAVE_LIBZ 1
#define HAVE_LIMITS_H 1
#define HAVE_LINK 1
#define HAVE_LOCALE_H 1
#define HAVE_LOCALTIME_R 1
#define HAVE_LONG_LONG_INT 1
#define HAVE_LSTAT 1
#define HAVE_LUTIMES 1
#define HAVE_MBRTOWC 1
#define HAVE_MEMMOVE 1
#define HAVE_MEMORY_H 1
#define HAVE_MEMSET 1
#define HAVE_MKDIR 1
#define HAVE_MKFIFO 1
#define HAVE_MKNOD 1
#define HAVE_MKSTEMP 1
#define HAVE_NL_LANGINFO 1
#define HAVE_OPENAT 1
#define HAVE_PATHS_H 1
#define HAVE_PIPE 1
#define HAVE_POLL 1
#define HAVE_POLL_H 1
#define HAVE_POSIX_SPAWNP 1
#define HAVE_PTHREAD_H 1
#define HAVE_PWD_H 1
#define HAVE_READDIR_R 1
#define HAVE_READLINK 1
#define HAVE_READLINKAT 1
#define HAVE_READPASSPHRASE 1
#define HAVE_READPASSPHRASE_H 1
#define HAVE_REGEX_H 1
#define HAVE_SELECT 1
#define HAVE_SETENV 1
#define HAVE_SETLOCALE 1
#define HAVE_SIGACTION 1
#define HAVE_SIGNAL_H 1
#define HAVE_SPAWN_H 1
#define HAVE_STATFS 1
#define HAVE_STATVFS 1
#define HAVE_STDARG_H 1
#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRCHR 1
#define HAVE_STRDUP 1
#define HAVE_STRERROR 1
#define HAVE_STRERROR_R 1
#define HAVE_STRFTIME 1
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_STRRCHR 1
#define HAVE_STRUCT_STATFS_F_NAMEMAX 1
#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1
#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
#define HAVE_STRUCT_STAT_ST_FLAGS 1
#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
#define HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 1
#define HAVE_STRUCT_TM_TM_GMTOFF 1
#define HAVE_SYMLINK 1
#define HAVE_SYS_CDEFS_H 1
#define HAVE_SYS_IOCTL_H 1
#define HAVE_SYS_MOUNT_H 1
#define HAVE_SYS_PARAM_H 1
#define HAVE_SYS_POLL_H 1
#define HAVE_SYS_SELECT_H 1
#define HAVE_SYS_STATVFS_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_UTSNAME_H 1
#define HAVE_SYS_WAIT_H 1
#define HAVE_TIMEGM 1
#define HAVE_TIME_H 1
#define HAVE_TZSET 1
#define HAVE_UINTMAX_T 1
#define HAVE_UNISTD_H 1
#define HAVE_UNSETENV 1
#define HAVE_UNSIGNED_LONG_LONG 1
#define HAVE_UNSIGNED_LONG_LONG_INT 1
#define HAVE_UTIME 1
#define HAVE_UTIMES 1
#define HAVE_UTIME_H 1
#define HAVE_VFORK 1
#define HAVE_VPRINTF 1
#define HAVE_WCHAR_H 1
#define HAVE_WCHAR_T 1
#define HAVE_WCRTOMB 1
#define HAVE_WCSCMP 1
#define HAVE_WCSCPY 1
#define HAVE_WCSLEN 1
#define HAVE_WCTOMB 1
#define HAVE_WCTYPE_H 1
#define HAVE_WMEMCMP 1
#define HAVE_WMEMCPY 1
#define HAVE_WMEMMOVE 1
#define HAVE_ZLIB_H 1
#define TIME_WITH_SYS_TIME 1
#if __FreeBSD_version >= 1100056
#define HAVE_FUTIMENS 1
#define HAVE_UTIMENSAT 1
#endif
/* FreeBSD 4 and earlier lack intmax_t/uintmax_t */
#if __FreeBSD__ < 5
#define intmax_t int64_t
#define uintmax_t uint64_t
#define intmax_t int64_t
#define uintmax_t uint64_t
#endif
/* FreeBSD defines for archive_hash.h */
#ifdef WITH_OPENSSL
#define ARCHIVE_CRYPTO_MD5_OPENSSL 1
#define ARCHIVE_CRYPTO_RMD160_OPENSSL 1
#define ARCHIVE_CRYPTO_SHA1_OPENSSL
#define ARCHIVE_CRYPTO_SHA256_OPENSSL 1
#define ARCHIVE_CRYPTO_SHA384_OPENSSL 1
#define ARCHIVE_CRYPTO_SHA512_OPENSSL 1
#else
#define ARCHIVE_CRYPTO_MD5_LIBMD 1
#define ARCHIVE_CRYPTO_SHA1_LIBMD 1
#define ARCHIVE_CRYPTO_SHA256_LIBMD 1
#define ARCHIVE_CRYPTO_SHA512_LIBMD 1
#endif

View File

@ -270,6 +270,7 @@ IF(ENABLE_TEST)
test_write_format_zip_zip64.c
test_write_open_memory.c
test_write_read_format_zip.c
test_xattr_platform.c
test_zip_filename_encoding.c
)

View File

@ -0,0 +1,102 @@
/*-
* Copyright (c) 2003-2010 Tim Kientzle
* Copyright (c) 2017 Martin Matuska
* 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_xattr_platform)
{
#if !ARCHIVE_XATTR_SUPPORT
skipping("Extended attributes are not supported on this platform");
#else /* ARCHIVE_XATTR_SUPPORT */
struct archive *a;
struct archive_entry *ae;
const char *name;
const void *value;
size_t size, insize;
int e, r;
const char *attrname = "user.libarchive.test";
const char *readval = "readval";
const char *writeval = "writeval";
assertMakeFile("readtest", 0644, "a");
if (!setXattr("readtest", attrname, readval, strlen(readval) + 1)) {
skipping("Extended attributes are not supported on this "
"filesystem");
return;
}
/* Read test */
assert(NULL != (a = archive_read_disk_new()));
ae = archive_entry_new();
assert(ae != NULL);
archive_entry_set_pathname(ae, "readtest");
assertEqualInt(ARCHIVE_OK,
archive_read_disk_entry_from_file(a, ae, -1, NULL));
e = archive_entry_xattr_reset(ae);
assert(e > 0);
r = 0;
while (archive_entry_xattr_next(ae, &name, &value,
&size) == ARCHIVE_OK) {
if (name != NULL && value != NULL && size > 0 &&
strcmp(name, attrname) == 0) {
failure("Attribute value does not match");
assertEqualString((const char *)value, readval);
r = 1;
break;
}
}
failure("Attribute not found: %s", attrname);
assertEqualInt(r, 1);
archive_entry_free(ae);
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
assert(NULL != (a = archive_write_disk_new()));
archive_write_disk_set_options(a, ARCHIVE_EXTRACT_TIME |
ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_XATTR);
/* Write test */
ae = archive_entry_new();
assert(ae != NULL);
archive_entry_set_pathname(ae, "writetest");
archive_entry_set_filetype(ae, AE_IFREG);
archive_entry_set_perm(ae, 0654);
archive_entry_set_mtime(ae, 123456, 7890);
archive_entry_set_size(ae, 0);
archive_entry_xattr_add_entry(ae, attrname, writeval,
strlen(writeval) + 1);
assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
archive_entry_free(ae);
assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
value = getXattr("writetest", attrname, &insize);
if (assertEqualInt(insize, strlen(writeval) + 1) != 0)
assertEqualMem(value, writeval, insize);
#endif
}

View File

@ -169,7 +169,7 @@ restricted pax format and bzip2 compression.
(c, r, u, x modes only)
Archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of
.Fl Fl no-acls
and the default behavior in c, r, and u modes (except Mac OS X) or if
and the default behavior in c, r, and u modes (except on Mac OS X) or if
.Nm
is run in x mode as root. On Mac OS X this option translates extended ACLs
to NFSv4 ACLs. To store extended ACLs the
@ -396,7 +396,7 @@ except it compares mtime entries instead of ctime entries.
Honor the nodump file flag by skipping this file.
.It Fl Fl nopreserveHFSCompression
(x mode only)
Mac OS X specific(v10.6 or later). Do not compress extracted regular files
Mac OS X specific (v10.6 or later). Do not compress extracted regular files
which were compressed with HFS+ compression before archived.
By default, compress the regular files again with HFS+ compression.
.It Fl Fl null
@ -416,7 +416,7 @@ Do not archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of
.Fl Fl acls
and the default behavior if
.Nm
is run as non-root in x mode (on Mac OS X also in c, r and u modes).
is run as non-root in x mode (on Mac OS X as any user in c, r, u and x modes).
.It Fl Fl no-fflags
(c, r, u, x modes only)
Do not archive or extract file flags. This is the reverse of

View File

@ -58,6 +58,7 @@ IF(ENABLE_TAR AND ENABLE_TEST)
test_option_s.c
test_option_uid_uname.c
test_option_uuencode.c
test_option_xattrs.c
test_option_xz.c
test_option_z.c
test_patterns.c

View File

@ -25,9 +25,9 @@
#include "test.h"
__FBSDID("$FreeBSD$");
#if HAVE_POSIX_ACL || HAVE_DARWIN_ACL
#if ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBACL
static const acl_perm_t acl_perms[] = {
#if HAVE_DARWIN_ACL
#if ARCHIVE_ACL_DARWIN
ACL_READ_DATA,
ACL_LIST_DIRECTORY,
ACL_WRITE_DATA,
@ -46,11 +46,11 @@ static const acl_perm_t acl_perms[] = {
ACL_WRITE_SECURITY,
ACL_CHANGE_OWNER,
ACL_SYNCHRONIZE
#else /* !HAVE_DARWIN_ACL */
#else /* !ARCHIVE_ACL_DARWIN */
ACL_EXECUTE,
ACL_WRITE,
ACL_READ,
#if HAVE_FREEBSD_NFS4_ACL
#if ARCHIVE_ACL_FREEBSD_NFS4
ACL_READ_DATA,
ACL_LIST_DIRECTORY,
ACL_WRITE_DATA,
@ -67,18 +67,18 @@ static const acl_perm_t acl_perms[] = {
ACL_WRITE_ACL,
ACL_WRITE_OWNER,
ACL_SYNCHRONIZE
#endif /* HAVE_FREEBSD_NFS4_ACL */
#endif /* !HAVE_DARWIN_ACL */
#endif /* ARCHIVE_ACL_FREEBSD_NFS4 */
#endif /* !ARCHIVE_ACL_DARWIN */
};
#if HAVE_DARWIN_ACL || HAVE_FREEBSD_NFS4_ACL
#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD_NFS4
static const acl_flag_t acl_flags[] = {
#if HAVE_DARWIN_ACL
#if ARCHIVE_ACL_DARWIN
ACL_ENTRY_INHERITED,
ACL_ENTRY_FILE_INHERIT,
ACL_ENTRY_DIRECTORY_INHERIT,
ACL_ENTRY_LIMIT_INHERIT,
ACL_ENTRY_ONLY_INHERIT
#else /* HAVE_FREEBSD_NFS4_ACL */
#else /* ARCHIVE_ACL_FREEBSD_NFS4 */
ACL_ENTRY_FILE_INHERIT,
ACL_ENTRY_DIRECTORY_INHERIT,
ACL_ENTRY_NO_PROPAGATE_INHERIT,
@ -86,9 +86,9 @@ static const acl_flag_t acl_flags[] = {
ACL_ENTRY_SUCCESSFUL_ACCESS,
ACL_ENTRY_FAILED_ACCESS,
ACL_ENTRY_INHERITED
#endif /* HAVE_FREEBSD_NFS4_ACL */
#endif /* ARCHIVE_ACL_FREEBSD_NFS4 */
};
#endif /* HAVE_DARWIN_ACL || HAVE_FREEBSD_NFS4_ACL */
#endif /* ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD_NFS4 */
/*
* Compare two ACL entries on FreeBSD or on Mac OS X
@ -100,10 +100,10 @@ compare_acl_entry(acl_entry_t ae_a, acl_entry_t ae_b, int is_nfs4)
acl_permset_t permset_a, permset_b;
int perm_a, perm_b, perm_start, perm_end;
void *qual_a, *qual_b;
#if HAVE_FREEBSD_NFS4_ACL
#if ARCHIVE_ACL_FREEBSD_NFS4
acl_entry_type_t type_a, type_b;
#endif
#if HAVE_FREEBSD_NFS4_ACL || HAVE_DARWIN_ACL
#if ARCHIVE_ACL_FREEBSD_NFS4 || ARCHIVE_ACL_DARWIN
acl_flagset_t flagset_a, flagset_b;
int flag_a, flag_b;
#endif
@ -123,7 +123,7 @@ compare_acl_entry(acl_entry_t ae_a, acl_entry_t ae_b, int is_nfs4)
return (0);
/* Compare ACL qualifier */
#if HAVE_DARWIN_ACL
#if ARCHIVE_ACL_DARWIN
if (tag_a == ACL_EXTENDED_ALLOW || tag_b == ACL_EXTENDED_DENY)
#else
if (tag_a == ACL_USER || tag_a == ACL_GROUP)
@ -139,7 +139,7 @@ compare_acl_entry(acl_entry_t ae_a, acl_entry_t ae_b, int is_nfs4)
acl_free(qual_a);
return (-1);
}
#if HAVE_DARWIN_ACL
#if ARCHIVE_ACL_DARWIN
if (memcmp(((guid_t *)qual_a)->g_guid,
((guid_t *)qual_b)->g_guid, KAUTH_GUID_SIZE) != 0)
#else
@ -157,7 +157,7 @@ compare_acl_entry(acl_entry_t ae_a, acl_entry_t ae_b, int is_nfs4)
acl_free(qual_b);
}
#if HAVE_FREEBSD_NFS4_ACL
#if ARCHIVE_ACL_FREEBSD_NFS4
if (is_nfs4) {
/* Compare NFS4 ACL type */
r = acl_get_entry_type_np(ae_a, &type_a);
@ -185,7 +185,7 @@ compare_acl_entry(acl_entry_t ae_a, acl_entry_t ae_b, int is_nfs4)
perm_start = 0;
perm_end = (int)(sizeof(acl_perms) / sizeof(acl_perms[0]));
#if HAVE_FREEBSD_NFS4_ACL
#if ARCHIVE_ACL_FREEBSD_NFS4
if (is_nfs4)
perm_start = 3;
else
@ -193,7 +193,7 @@ compare_acl_entry(acl_entry_t ae_a, acl_entry_t ae_b, int is_nfs4)
#endif
/* Cycle through all perms and compare their value */
for (i = perm_start; i < perm_end; i++) {
#if HAVE_LIBACL
#if ARCHIVE_ACL_LIBACL
perm_a = acl_get_perm(permset_a, acl_perms[i]);
perm_b = acl_get_perm(permset_b, acl_perms[i]);
#else
@ -206,7 +206,7 @@ compare_acl_entry(acl_entry_t ae_a, acl_entry_t ae_b, int is_nfs4)
return (0);
}
#if HAVE_FREEBSD_NFS4_ACL || HAVE_DARWIN_ACL
#if ARCHIVE_ACL_FREEBSD_NFS4 || ARCHIVE_ACL_DARWIN
if (is_nfs4) {
r = acl_get_flagset_np(ae_a, &flagset_a);
failure("acl_get_flagset_np() error: %s", strerror(errno));
@ -227,14 +227,14 @@ compare_acl_entry(acl_entry_t ae_a, acl_entry_t ae_b, int is_nfs4)
return (0);
}
}
#else /* HAVE_FREEBSD_NFS4_ACL || HAVE_DARWIN_ACL*/
#else /* ARCHIVE_ACL_FREEBSD_NFS4 || ARCHIVE_ACL_DARWIN */
(void)is_nfs4; /* UNUSED */
#endif
return (1);
}
#endif /* HAVE_POSIX_ACL || HAVE_DARWIN_ACL */
#endif /* ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBACL */
#if HAVE_SUN_ACL || HAVE_DARWIN_ACL || HAVE_POSIX_ACL
#if ARCHIVE_ACL_SUPPORT
/*
* Clear default ACLs or inheritance flags
*/
@ -243,15 +243,17 @@ clear_inheritance_flags(const char *path, int type)
{
switch (type) {
case ARCHIVE_TEST_ACL_TYPE_POSIX1E:
#if HAVE_POSIX_ACL
#if ARCHIVE_ACL_POSIX1E
#if !ARCHIVE_ACL_SUNOS
acl_delete_def_file(path);
#else
/* Solaris */
setTestAcl(path);
#endif
#endif /* ARCHIVE_ACL_POSIX1E */
break;
case ARCHIVE_TEST_ACL_TYPE_NFS4:
#if HAVE_NFS4_ACL
#if ARCHIVE_ACL_NFS4
setTestAcl(path);
#endif
break;
@ -266,31 +268,40 @@ compare_acls(const char *path_a, const char *path_b)
{
int ret = 1;
int is_nfs4 = 0;
#if HAVE_SUN_ACL
#if ARCHIVE_ACL_SUNOS
void *acl_a, *acl_b;
int aclcnt_a, aclcnt_b;
aclent_t *aclent_a, *aclent_b;
ace_t *ace_a, *ace_b;
int e;
#else
#elif ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_LIBACL
acl_t acl_a, acl_b;
acl_entry_t aclent_a, aclent_b;
int a, b, r;
#endif
#if ARCHIVE_ACL_LIBRICHACL
struct richacl *richacl_a, *richacl_b;
richacl_a = NULL;
richacl_b = NULL;
#endif
#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_LIBACL || \
ARCHIVE_ACL_SUNOS
acl_a = NULL;
acl_b = NULL;
#if HAVE_SUN_ACL
#endif
#if ARCHIVE_ACL_SUNOS
acl_a = sunacl_get(GETACL, &aclcnt_a, 0, path_a);
if (acl_a == NULL) {
#if HAVE_SUN_NFS4_ACL
#if ARCHIVE_ACL_SUNOS_NFS4
is_nfs4 = 1;
acl_a = sunacl_get(ACE_GETACL, &aclcnt_a, 0, path_a);
#endif
failure("acl_get() error: %s", strerror(errno));
if (assert(acl_a != NULL) == 0)
return (-1);
#if HAVE_SUN_NFS4_ACL
#if ARCHIVE_ACL_SUNOS_NFS4
acl_b = sunacl_get(ACE_GETACL, &aclcnt_b, 0, path_b);
#endif
} else
@ -321,7 +332,7 @@ compare_acls(const char *path_a, const char *path_b)
goto exit_free;
}
}
#if HAVE_SUN_NFS4_ACL
#if ARCHIVE_ACL_SUNOS_NFS4
else {
ace_a = &((ace_t *)acl_a)[e];
ace_b = &((ace_t *)acl_b)[e];
@ -335,30 +346,57 @@ compare_acls(const char *path_a, const char *path_b)
}
#endif
}
#else /* !HAVE_SUN_ACL */
#if HAVE_DARWIN_ACL
#else /* !ARCHIVE_ACL_SUNOS */
#if ARCHIVE_ACL_LIBRICHACL
richacl_a = richacl_get_file(path_a);
#if !ARCHIVE_ACL_LIBACL
if (richacl_a == NULL &&
(errno == ENODATA || errno == ENOTSUP || errno == ENOSYS))
return (0);
failure("richacl_get_file() error: %s (%s)", path_a, strerror(errno));
if (assert(richacl_a != NULL) == 0)
return (-1);
#endif
if (richacl_a != NULL) {
richacl_b = richacl_get_file(path_b);
if (richacl_b == NULL &&
(errno == ENODATA || errno == ENOTSUP || errno == ENOSYS))
return (0);
failure("richacl_get_file() error: %s (%s)", path_b,
strerror(errno));
if (assert(richacl_b != NULL) == 0) {
richacl_free(richacl_a);
return (-1);
}
if (richacl_compare(richacl_a, richacl_b) == 0)
ret = 0;
richacl_free(richacl_a);
richacl_free(richacl_b);
return (ret);
}
#endif /* ARCHIVE_ACL_LIBRICHACL */
#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_LIBACL
#if ARCHIVE_ACL_DARWIN
is_nfs4 = 1;
acl_a = acl_get_file(path_a, ACL_TYPE_EXTENDED);
#elif HAVE_FREEBSD_NFS4_ACL
#elif ARCHIVE_ACL_FREEBSD_NFS4
acl_a = acl_get_file(path_a, ACL_TYPE_NFS4);
if (acl_a != NULL)
is_nfs4 = 1;
#endif
#if !HAVE_DARWIN_ACL
if (acl_a == NULL)
acl_a = acl_get_file(path_a, ACL_TYPE_ACCESS);
#endif
failure("acl_get_file() error: %s (%s)", path_a, strerror(errno));
if (assert(acl_a != NULL) == 0)
return (-1);
#if HAVE_DARWIN_ACL
#if ARCHIVE_ACL_DARWIN
acl_b = acl_get_file(path_b, ACL_TYPE_EXTENDED);
#elif HAVE_FREEBSD_NFS4_ACL
#elif ARCHIVE_ACL_FREEBSD_NFS4
acl_b = acl_get_file(path_b, ACL_TYPE_NFS4);
#endif
#if !HAVE_DARWIN_ACL
#if !ARCHIVE_ACL_DARWIN
if (acl_b == NULL) {
#if HAVE_FREEBSD_NFS4_ACL
#if ARCHIVE_ACL_FREEBSD_NFS4
if (is_nfs4) {
acl_free(acl_a);
return (0);
@ -382,7 +420,7 @@ compare_acls(const char *path_a, const char *path_b)
ret = 0;
goto exit_free;
}
#if HAVE_DARWIN_ACL
#if ARCHIVE_ACL_DARWIN
while (a == 0 && b == 0)
#else /* FreeBSD, Linux */
while (a == 1 && b == 1)
@ -399,9 +437,10 @@ compare_acls(const char *path_a, const char *path_b)
/* Entry count must match */
if (a != b)
ret = 0;
#endif /* !HAVE_SUN_ACL */
#endif /* ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_LIBACL */
#endif /* !ARCHIVE_ACL_SUNOS */
exit_free:
#if HAVE_SUN_ACL
#if ARCHIVE_ACL_SUNOS
free(acl_a);
free(acl_b);
#else
@ -410,13 +449,13 @@ compare_acls(const char *path_a, const char *path_b)
#endif
return (ret);
}
#endif /* HAVE_SUN_ACL || HAVE_DARWIN_ACL || HAVE_POSIX_ACL */
#endif /* ARCHIVE_ACL_SUPPORT */
DEFINE_TEST(test_option_acls)
{
#if !HAVE_SUN_ACL && !HAVE_DARWIN_ACL && !HAVE_POSIX_ACL
#if !ARCHIVE_ACL_SUPPORT
skipping("ACLs are not supported on this platform");
#else /* HAVE_SUN_ACL || HAVE_DARWIN_ACL || HAVE_POSIX_ACL */
#else /* ARCHIVE_ACL_SUPPORT */
int acltype, r;
assertMakeFile("f", 0644, "a");
@ -465,5 +504,5 @@ DEFINE_TEST(test_option_acls)
assertEqualInt(r, 0);
r = compare_acls("f", "noacls_noacls/f");
assertEqualInt(r, 0);
#endif /* HAVE_SUN_ACL || HAVE_DARWIN_ACL || HAVE_POSIX_ACL */
#endif /* ARCHIVE_ACL_SUPPORT */
}

View File

@ -0,0 +1,87 @@
/*-
* Copyright (c) 2017 Martin Matuska
* 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_xattrs)
{
#if !ARCHIVE_XATTR_SUPPORT
skipping("Extended atributes are not supported on this platform");
#else /* ARCHIVE_XATTR_SUPPORT */
const char *testattr = "user.libarchive.test";
const char *testval = "testval";
const void *readval;
size_t size;
int r;
/* Create a file. */
assertMakeFile("f", 0644, "a");
if (!setXattr("f", "user.libarchive.test", testval,
strlen(testval) + 1)) {
skipping("Can't set user extended attributes on this "
"filesystem");
return;
}
/* Archive with xattrs */
r = systemf("%s -c --no-mac-metadata --xattrs -f xattrs.tar f >xattrs.out 2>xattrs.err", testprog);
assertEqualInt(r, 0);
/* Archive without xattrs */
r = systemf("%s -c --no-mac-metadata --no-xattrs -f noxattrs.tar f >noxattrs.out 2>noxattrs.err", testprog);
assertEqualInt(r, 0);
/* Extract xattrs with xattrs */
assertMakeDir("xattrs_xattrs", 0755);
r = systemf("%s -x -C xattrs_xattrs --no-same-permissions --xattrs -f xattrs.tar >xattrs_xattrs.out 2>xattrs_xattrs.err", testprog);
assertEqualInt(r, 0);
readval = getXattr("xattrs_xattrs/f", testattr, &size);
if(assertEqualInt(size, strlen(testval) + 1) != 0)
assertEqualMem(readval, testval, size);
/* Extract xattrs without xattrs */
assertMakeDir("xattrs_noxattrs", 0755);
r = systemf("%s -x -C xattrs_noxattrs -p --no-xattrs -f xattrs.tar >xattrs_noxattrs.out 2>xattrs_noxattrs.err", testprog);
assertEqualInt(r, 0);
readval = getXattr("xattrs_noxattrs/f", testattr, &size);
assert(readval == NULL);
/* Extract noxattrs with xattrs */
assertMakeDir("noxattrs_xattrs", 0755);
r = systemf("%s -x -C noxattrs_xattrs --no-same-permissions --xattrs -f noxattrs.tar >noxattrs_xattrs.out 2>noxattrs_xattrs.err", testprog);
assertEqualInt(r, 0);
readval = getXattr("noxattrs_xattrs/f", testattr, &size);
assert(readval == NULL);
/* Extract noxattrs with noxattrs */
assertMakeDir("noxattrs_noxattrs", 0755);
r = systemf("%s -x -C noxattrs_noxattrs -p --no-xattrs -f noxattrs.tar >noxattrs_noxattrs.out 2>noxattrs_noxattrs.err", testprog);
assertEqualInt(r, 0);
readval = getXattr("noxattrs_noxattrs/f", testattr, &size);
assert(readval == NULL);
#endif /* ARCHIVE_XATTR_SUPPORT */
}

View File

@ -79,6 +79,9 @@
#ifdef HAVE_SYS_ACL_H
#include <sys/acl.h>
#endif
#ifdef HAVE_SYS_RICHACL_H
#include <sys/richacl.h>
#endif
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
@ -131,6 +134,7 @@
#define ARCHIVE_TEST_ACL_TYPE_POSIX1E 1
#define ARCHIVE_TEST_ACL_TYPE_NFS4 2
#include "archive_platform_xattr.h"
/*
* Redefine DEFINE_TEST for use in defining the test functions.
@ -343,6 +347,12 @@ int canNodump(void);
/* Set test ACLs */
int setTestAcl(const char *path);
/* Get extended attribute */
const void *getXattr(const char *, const char *, size_t *);
/* Set extended attribute */
int setXattr(const char *, const char *, const void *, size_t);
/* Return true if the file has large i-node number(>0xffffffff). */
int is_LargeInode(const char *);

View File

@ -67,6 +67,17 @@
#ifdef HAVE_SYS_ACL_H
#include <sys/acl.h>
#endif
#ifdef HAVE_SYS_EA_H
#include <sys/ea.h>
#endif
#ifdef HAVE_SYS_EXTATTR_H
#include <sys/extattr.h>
#endif
#if HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#elif HAVE_ATTR_XATTR_H
#include <attr/xattr.h>
#endif
#ifdef HAVE_SYS_RICHACL_H
#include <sys/richacl.h>
#endif
@ -2440,6 +2451,83 @@ canNodump(void)
return (0);
}
/* Get extended attribute from a path */
const void *
getXattr(const char *path, const char *name, size_t *sizep)
{
void *value = NULL;
#if ARCHIVE_XATTR_SUPPORT
ssize_t size;
#if ARCHIVE_XATTR_LINUX
size = lgetxattr(path, name, NULL, 0);
#elif ARCHIVE_XATTR_DARWIN
size = getxattr(path, name, NULL, 0, 0, XATTR_NOFOLLOW);
#elif ARCHIVE_XATTR_AIX
size = lgetea(path, name, NULL, 0);
#elif ARCHIVE_XATTR_FREEBSD
size = extattr_get_link(path, EXTATTR_NAMESPACE_USER, name + 5,
NULL, 0);
#endif
if (size >= 0) {
value = malloc(size);
#if ARCHIVE_XATTR_LINUX
size = lgetxattr(path, name, value, size);
#elif ARCHIVE_XATTR_DARWIN
size = getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
#elif ARCHIVE_XATTR_AIX
size = lgetea(path, name, value, size);
#elif ARCHIVE_XATTR_FREEBSD
size = extattr_get_link(path, EXTATTR_NAMESPACE_USER, name + 5,
value, size);
#endif
if (size < 0) {
free(value);
value = NULL;
}
}
if (size < 0)
*sizep = 0;
else
*sizep = (size_t)size;
#else /* !ARCHIVE_XATTR_SUPPORT */
(void)path; /* UNUSED */
(void)name; /* UNUSED */
*sizep = 0;
#endif /* !ARCHIVE_XATTR_SUPPORT */
return (value);
}
/*
* Set extended attribute on a path
* Returns 0 on error, 1 on success
*/
int
setXattr(const char *path, const char *name, const void *value, size_t size)
{
#if ARCHIVE_XATTR_SUPPORT
#if ARCHIVE_XATTR_LINUX
if (lsetxattr(path, name, value, size, 0) == 0)
#elif ARCHIVE_XATTR_DARWIN
if (setxattr(path, name, value, size, 0, XATTR_NOFOLLOW) == 0)
#elif ARCHIVE_XATTR_AIX
if (lsetea(path, name, value, size, 0) == 0)
#elif ARCHIVE_XATTR_FREEBSD
if (extattr_set_link(path, EXTATTR_NAMESPACE_USER, name + 5, value,
size) > -1)
#else
if (0)
#endif
return (1);
#else /* !ARCHIVE_XATTR_SUPPORT */
(void)path; /* UNUSED */
(void)name; /* UNUSED */
(void)value; /* UNUSED */
(void)size; /* UNUSED */
#endif /* !ARCHIVE_XATTR_SUPPORT */
return (0);
}
#if ARCHIVE_ACL_SUNOS
/* Fetch ACLs on Solaris using acl() or facl() */
void *