This commit is contained in:
Mario Fetka
2013-10-31 09:47:02 +01:00
parent 785ec3de78
commit e7d5b0a814
16 changed files with 3597 additions and 2 deletions

View File

@@ -0,0 +1,159 @@
Submitted By: Mario Fetka (mario dot fetka at gmail dot com)
Date: 2011-11-21
Initial Package Version: 1.4.5
Origin: http://privsep.org/patches/2.3.0-dev/xattr-patches/apr-xattr-build.patch
Upstream Status: unknown
Description: build infrastructure
diff -Naur apr-1.4.5.orig/build.conf apr-1.4.5/build.conf
--- apr-1.4.5.orig/build.conf 2011-11-21 18:38:28.659217726 +0000
+++ apr-1.4.5/build.conf 2011-11-21 18:39:17.735760998 +0000
@@ -13,7 +13,7 @@
# directories that have platform-specific code in them. the resulting
# pattern will be: SUBDIR/PLATFORM/*.c
platform_dirs =
- dso file_io locks memory misc mmap network_io poll random
+ dso file_io locks memory misc mmap network_io poll random xattr
shmem support threadproc time user atomic
# all the public headers
diff -Naur apr-1.4.5.orig/configure.in apr-1.4.5/configure.in
--- apr-1.4.5.orig/configure.in 2011-11-21 18:38:28.985607639 +0000
+++ apr-1.4.5/configure.in 2011-11-21 18:43:25.981912296 +0000
@@ -197,7 +197,7 @@
DEFAULT_OSDIR="unix"
echo "(Default will be ${DEFAULT_OSDIR})"
-apr_modules="file_io network_io threadproc misc locks time mmap shmem user memory atomic poll support random"
+apr_modules="file_io network_io threadproc misc locks time mmap shmem user memory atomic poll support random xattr"
dnl Checks for programs.
AC_PROG_MAKE_SET
@@ -1466,7 +1466,9 @@
sys/types.h \
sys/uio.h \
sys/un.h \
- sys/wait.h)
+ sys/wait.h \
+ sys/xattr.h \
+ sys/extattr.h)
# IRIX 6.5 has a problem in <netinet/tcp.h> which prevents it from
# being included by itself. Check for <netinet/tcp.h> manually,
@@ -1518,6 +1520,8 @@
AC_SUBST(unistdh)
AC_SUBST(signalh)
AC_SUBST(sys_waith)
+AC_SUBST(sys_xattrh)
+AC_SUBST(sys_extattrh)
AC_SUBST(processh)
AC_SUBST(pthreadh)
AC_SUBST(semaphoreh)
@@ -2472,6 +2476,87 @@
APR_CHECK_DIRENT_INODE
APR_CHECK_DIRENT_TYPE
+dnl ----------------------------- Checking for Extended Attributes Support
+echo "${nl}Checking for Extended Attributes Support..."
+
+# Check whether Extended Attributes have explicitly been disabled
+AC_ARG_ENABLE(xattr,
+ [ --disable-xattr Disable Extended Attributes support in APR.],
+ [ if test "$enableval" = "no"; then
+ user_disabled_xattr=1
+ fi ],
+ [ user_disabled_xattr=0 ] )
+
+xattrdarwin="0"
+xattrlinux="0"
+xattrfreebsd="0"
+xattrsolaris="0"
+if test "$user_disabled_xattr" = 1; then
+ echo "no -- disabled by user"
+else
+ AC_CHECK_FUNCS([fgetxattr fsetxattr flistxattr fremovexattr lgetxattr \
+ extattr_get_fd extattr_set_fd extattr_list_fd \
+ extattr_delete_fd openat unlinkat])
+ APR_CHECK_DEFINE(O_XATTR, sys/fcntl.h)
+ APR_CHECK_DEFINE(XATTR_NOFOLLOW, sys/xattr.h)
+ APR_CHECK_DEFINE(XATTR_CREATE, sys/xattr.h)
+ APR_CHECK_DEFINE(XATTR_REPLACE, sys/xattr.h)
+ APR_CHECK_DEFINE(XATTR_NAME_MAX, linux/limits.h)
+ APR_CHECK_DEFINE(XATTR_SIZE_MAX, linux/limits.h)
+ APR_CHECK_DEFINE(XATTR_LIST_MAX, linux/limits.h)
+ APR_CHECK_DEFINE(XATTR_MAXNAMELEN, sys/xattr.h)
+ APR_CHECK_DEFINE(EXTATTR_NAMESPACE_USER, sys/extattr.h)
+ APR_CHECK_DEFINE(EXTATTR_NAMESPACE_SYSTEM, sys/extattr.h)
+ APR_CHECK_DEFINE(EXTATTR_MAXNAMELEN, sys/extattr.h)
+
+ APR_BEGIN_DECISION([xattr attribute system interface])
+ APR_IFALLYES(header:sys/xattr.h dnl
+ define:XATTR_NOFOLLOW dnl
+ func:fgetxattr dnl
+ func:fsetxattr dnl
+ func:flistxattr dnl
+ func:fremovexattr,
+ [xattrdarwin="1"
+ APR_DECIDE(USE_XATTR_DARWIN, [xattr (Darwin)])])
+
+ APR_IFALLYES(header:sys/xattr.h dnl
+ func:lgetxattr dnl
+ func:fgetxattr dnl
+ func:fsetxattr dnl
+ func:flistxattr dnl
+ func:fremovexattr,
+ [xattrlinux="1"
+ APR_DECIDE(USE_XATTR_LINUX, [xattr (Linux)])])
+
+ APR_IFALLYES(header:sys/extattr.h dnl
+ func:extattr_set_fd dnl
+ func:func:extattr_get_fd dnl
+ func:extattr_list_fd dnl
+ func:func:extattr_delete_fd,
+ [xattrfreebsd="1"
+ APR_DECIDE(USE_XATTR_FREEBSD, [extattr (FreeBSD)])])
+
+ APR_IFALLYES(define:O_XATTR dnl
+ func:openat dnl
+ func:unlinkat,
+ [xattrsolaris="1"
+ APR_DECIDE(USE_XATTR_SOLARIS, [attropen (Solaris)])])
+
+ if test "x$ac_decision" = "x"; then
+ ac_decision="USE_XATTR_NONE"
+ ac_decision_msg="no xattr interface available"
+ fi
+ APR_END_DECISION
+ AC_DEFINE_UNQUOTED($ac_decision)
+fi
+
+if test "$xattrdarwin$xattrlinux$xattrfreebsd$xattrsolaris" = "0000"; then
+ xattr="0"
+else
+ xattr="1"
+fi
+AC_SUBST(xattr)
+
dnl ----------------------------- Checking for UUID Support
echo "${nl}Checking for OS UUID Support..."
diff -Naur apr-1.4.5.orig/include/apr.h.in apr-1.4.5/include/apr.h.in
--- apr-1.4.5.orig/include/apr.h.in 2011-11-21 18:38:28.661532544 +0000
+++ apr-1.4.5/include/apr.h.in 2011-11-21 18:40:23.666523955 +0000
@@ -104,6 +104,8 @@
#define APR_HAVE_SYS_UIO_H @sys_uioh@
#define APR_HAVE_SYS_UN_H @sys_unh@
#define APR_HAVE_SYS_WAIT_H @sys_waith@
+#define APR_HAVE_SYS_XATTR_H @sys_xattrh@
+#define APR_HAVE_SYS_EXTATTR_H @sys_extattrh@
#define APR_HAVE_TIME_H @timeh@
#define APR_HAVE_UNISTD_H @unistdh@
#define APR_HAVE_WINDOWS_H @windowsh@
@@ -276,6 +278,7 @@
#define APR_HAS_UNICODE_FS @have_unicode_fs@
#define APR_HAS_PROC_INVOKED @have_proc_invoked@
#define APR_HAS_USER @apr_has_user@
+#define APR_HAS_XATTR @xattr@
#define APR_HAS_LARGE_FILES @aprlfs@
#define APR_HAS_XTHREAD_FILES @apr_has_xthread_files@
#define APR_HAS_OS_UUID @osuuid@

View File

@@ -0,0 +1,27 @@
diff -ur apr-1.2.11/build/apr_hints.m4 apr-1.2.11-mint/build/apr_hints.m4
--- apr-1.2.11/build/apr_hints.m4 Tue Jun 26 23:47:46 2007
+++ apr-1.2.11-mint/build/apr_hints.m4 Tue Mar 25 12:00:14 2008
@@ -44,8 +44,9 @@
case "$host" in
*mint)
- APR_ADDTO(CPPFLAGS, [-DMINT])
- APR_ADDTO(LIBS, [-lportlib])
+ APR_ADDTO(CPPFLAGS, [-DMINT -D_GNU_SOURCE])
+ apr_cv_pthreads_cflags="none"
+ apr_cv_pthreads_lib="-lpthread"
;;
*MPE/iX*)
APR_ADDTO(CPPFLAGS, [-DMPE -D_POSIX_SOURCE -D_SOCKET_SOURCE])
diff -ur apr-1.2.11/build/apr_threads.m4 apr-1.2.11-mint/build/apr_threads.m4
--- apr-1.2.11/build/apr_threads.m4 Thu Aug 3 11:05:26 2006
+++ apr-1.2.11-mint/build/apr_threads.m4 Wed Mar 19 08:38:56 2008
@@ -198,7 +198,7 @@
AC_DEFUN(APR_CHECK_SIGWAIT_ONE_ARG,[
AC_CACHE_CHECK(whether sigwait takes one argument,ac_cv_sigwait_one_arg,[
AC_TRY_COMPILE([
-#if defined(__NETBSD__) || defined(DARWIN)
+#if defined(__NETBSD__) || defined(DARWIN) || defined(MINT)
/* When using the unproven-pthreads package, we need to pull in this
* header to get a prototype for sigwait(). Else things will fail later
* on. XXX Should probably be fixed in the unproven-pthreads package.

View File

@@ -0,0 +1,155 @@
Index: include/apr.h.in
===================================================================
--- include/apr.h.in (revision 606453)
+++ include/apr.h.in (working copy)
@@ -103,6 +103,8 @@
#define APR_HAVE_SYS_UIO_H @sys_uioh@
#define APR_HAVE_SYS_UN_H @sys_unh@
#define APR_HAVE_SYS_WAIT_H @sys_waith@
+#define APR_HAVE_SYS_XATTR_H @sys_xattrh@
+#define APR_HAVE_SYS_EXTATTR_H @sys_extattrh@
#define APR_HAVE_TIME_H @timeh@
#define APR_HAVE_UNISTD_H @unistdh@
#define APR_HAVE_WINDOWS_H @windowsh@
@@ -238,6 +240,7 @@
#define APR_HAS_UNICODE_FS @have_unicode_fs@
#define APR_HAS_PROC_INVOKED @have_proc_invoked@
#define APR_HAS_USER 1
+#define APR_HAS_XATTR @xattr@
#define APR_HAS_LARGE_FILES @aprlfs@
#define APR_HAS_XTHREAD_FILES 0
#define APR_HAS_OS_UUID @osuuid@
Index: configure.in
===================================================================
--- configure.in (revision 606453)
+++ configure.in (working copy)
@@ -124,7 +124,7 @@
DEFAULT_OSDIR="unix"
echo "(Default will be ${DEFAULT_OSDIR})"
-apr_modules="file_io network_io threadproc misc locks time mmap shmem user memory atomic poll support random"
+apr_modules="file_io network_io threadproc misc locks time mmap shmem user memory atomic poll support random xattr"
dnl Checks for programs.
AC_PROG_MAKE_SET
@@ -1135,7 +1135,9 @@
sys/types.h \
sys/uio.h \
sys/un.h \
- sys/wait.h)
+ sys/wait.h \
+ sys/xattr.h \
+ sys/extattr.h)
# IRIX 6.5 has a problem in <netinet/tcp.h> which prevents it from
# being included by itself. Check for <netinet/tcp.h> manually,
@@ -1187,6 +1189,8 @@
AC_SUBST(unistdh)
AC_SUBST(signalh)
AC_SUBST(sys_waith)
+AC_SUBST(sys_xattrh)
+AC_SUBST(sys_extattrh)
AC_SUBST(pthreadh)
AC_SUBST(semaphoreh)
AC_SUBST(windowsh)
@@ -2030,6 +2034,87 @@
APR_CHECK_DIRENT_INODE
APR_CHECK_DIRENT_TYPE
+dnl ----------------------------- Checking for Extended Attributes Support
+echo "${nl}Checking for Extended Attributes Support..."
+
+# Check whether Extended Attributes have explicitly been disabled
+AC_ARG_ENABLE(xattr,
+ [ --disable-xattr Disable Extended Attributes support in APR.],
+ [ if test "$enableval" = "no"; then
+ user_disabled_xattr=1
+ fi ],
+ [ user_disabled_xattr=0 ] )
+
+xattrdarwin="0"
+xattrlinux="0"
+xattrfreebsd="0"
+xattrsolaris="0"
+if test "$user_disabled_xattr" = 1; then
+ echo "no -- disabled by user"
+else
+ AC_CHECK_FUNCS([fgetxattr fsetxattr flistxattr fremovexattr lgetxattr \
+ extattr_get_fd extattr_set_fd extattr_list_fd \
+ extattr_delete_fd openat unlinkat])
+ APR_CHECK_DEFINE(O_XATTR, sys/fcntl.h)
+ APR_CHECK_DEFINE(XATTR_NOFOLLOW, sys/xattr.h)
+ APR_CHECK_DEFINE(XATTR_CREATE, sys/xattr.h)
+ APR_CHECK_DEFINE(XATTR_REPLACE, sys/xattr.h)
+ APR_CHECK_DEFINE(XATTR_NAME_MAX, linux/limits.h)
+ APR_CHECK_DEFINE(XATTR_SIZE_MAX, linux/limits.h)
+ APR_CHECK_DEFINE(XATTR_LIST_MAX, linux/limits.h)
+ APR_CHECK_DEFINE(XATTR_MAXNAMELEN, sys/xattr.h)
+ APR_CHECK_DEFINE(EXTATTR_NAMESPACE_USER, sys/extattr.h)
+ APR_CHECK_DEFINE(EXTATTR_NAMESPACE_SYSTEM, sys/extattr.h)
+ APR_CHECK_DEFINE(EXTATTR_MAXNAMELEN, sys/extattr.h)
+
+ APR_BEGIN_DECISION([xattr attribute system interface])
+ APR_IFALLYES(header:sys/xattr.h dnl
+ define:XATTR_NOFOLLOW dnl
+ func:fgetxattr dnl
+ func:fsetxattr dnl
+ func:flistxattr dnl
+ func:fremovexattr,
+ [xattrdarwin="1"
+ APR_DECIDE(USE_XATTR_DARWIN, [xattr (Darwin)])])
+
+ APR_IFALLYES(header:sys/xattr.h dnl
+ func:lgetxattr dnl
+ func:fgetxattr dnl
+ func:fsetxattr dnl
+ func:flistxattr dnl
+ func:fremovexattr,
+ [xattrlinux="1"
+ APR_DECIDE(USE_XATTR_LINUX, [xattr (Linux)])])
+
+ APR_IFALLYES(header:sys/extattr.h dnl
+ func:extattr_set_fd dnl
+ func:func:extattr_get_fd dnl
+ func:extattr_list_fd dnl
+ func:func:extattr_delete_fd,
+ [xattrfreebsd="1"
+ APR_DECIDE(USE_XATTR_FREEBSD, [extattr (FreeBSD)])])
+
+ APR_IFALLYES(define:O_XATTR dnl
+ func:openat dnl
+ func:unlinkat,
+ [xattrsolaris="1"
+ APR_DECIDE(USE_XATTR_SOLARIS, [attropen (Solaris)])])
+
+ if test "x$ac_decision" = "x"; then
+ ac_decision="USE_XATTR_NONE"
+ ac_decision_msg="no xattr interface available"
+ fi
+ APR_END_DECISION
+ AC_DEFINE_UNQUOTED($ac_decision)
+fi
+
+if test "$xattrdarwin$xattrlinux$xattrfreebsd$xattrsolaris" = "0000"; then
+ xattr="0"
+else
+ xattr="1"
+fi
+AC_SUBST(xattr)
+
dnl ----------------------------- Checking for UUID Support
echo "${nl}Checking for OS UUID Support..."
Index: build.conf
===================================================================
--- build.conf (revision 606453)
+++ build.conf (working copy)
@@ -13,7 +13,7 @@
# directories that have platform-specific code in them. the resulting
# pattern will be: SUBDIR/PLATFORM/*.c
platform_dirs =
- dso file_io locks memory misc mmap network_io poll random
+ dso file_io locks memory misc mmap network_io poll random xattr
shmem support threadproc time user atomic
# all the public headers

View File

@@ -0,0 +1,366 @@
Index: include/apr_file_xattr.h
===================================================================
--- include/apr_file_xattr.h (revision 0)
+++ include/apr_file_xattr.h (revision 0)
@@ -0,0 +1,249 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APR_FILE_XATTR_H
+#define APR_FILE_XATTR_H
+
+/**
+ * @file apr_file_xattr.h
+ * @brief APR File Extended Attributes
+ */
+
+#include "apr.h"
+#include "apr_pools.h"
+#include "apr_tables.h"
+#include "apr_file_io.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup apr_xattr File Extended Attribute Functions
+ * @ingroup APR
+ * @{
+ */
+
+/** When setting values, fail if the attribute already exists */
+#define APR_XATTR_CREATE 1
+
+/** When setting values, fail if the attribute does not already exist */
+#define APR_XATTR_REPLACE 2
+
+typedef struct apr_xattr_t apr_xattr_t;
+
+/**
+ * Open a context for access to the extended attributes of a file or
+ * directory specified by a path name
+ *
+ * @param new the context allocated for access to extended attributes
+ * @param pathname the path name of the file or directory
+ * @param p the pool to allocate any memory from
+ * @return the status of the operation:
+ * <PRE>
+ * APR_SUCCESS the path was opened for attribute access
+ * APR_STATUS_IS_ENOENT() the file or directory does not exist
+ * </PRE>
+ * Other operating system dependant error codes may be returned.
+ *
+ * @warning Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_xattr_open_path(apr_xattr_t **new,
+ const char *pathname,
+ apr_pool_t *p);
+
+/**
+ * Open a context for access to the extended attributes of an open file
+ *
+ * @param new the context allocated for access to extended attributes
+ * @param file the open file to access the extended attributes on
+ * @param p the pool to allocate any memory from
+ * @return the status of the operation:
+ * <PRE>
+ * APR_SUCCESS the file was opened for attribute access
+ * </PRE>
+ *
+ * @warning Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_xattr_open_file(apr_xattr_t **new,
+ apr_file_t *file,
+ apr_pool_t *p);
+
+/**
+ * Open a context for access to the extended attributes of an open directory
+ *
+ * @param new the context allocated for access to extended attributes
+ * @param dir the open directory to access the extended attributes on
+ * @param p the pool to allocate any memory from if required
+ * @return the status of the operation:
+ * <PRE>
+ * APR_SUCCESS the directory was opened for attribute access
+ * </PRE>
+ *
+ * @warning Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_xattr_open_dir(apr_xattr_t **new,
+ apr_dir_t *dir,
+ apr_pool_t *p);
+
+/**
+ * Destroy a context used for access to extended attributes
+ *
+ * @param xattr the context to destroy
+ * <PRE>
+ * APR_SUCCESS the context was destroyed
+ * </PRE>
+ *
+ * @warning Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_xattr_destroy(apr_xattr_t *xattr);
+
+/**
+ * Set an extended attribute on a file or directory
+ * @param xattr the opened extended attribute file or directory context
+ * @param name the attribute name to set
+ * @param value the attribute value
+ * @param size the size in bytes of the attribute value
+ * @param flags to control how the attribute is set
+ * <PRE>
+ * APR_XATTR_CREATE return an error if the attribute name
+ * already exists.
+ * APR_XATTR_REPLACE return an error if the attribute name
+ * does not already exist.
+ * </PRE>
+ * @param p the pool to allocate any memory from if required
+ * @return the status of the operation:
+ * <PRE>
+ * APR_SUCCESS the attribute was set
+ * APR_STATUS_IS_EEXIST() create flag and the attribute exists
+ * APR_STATUS_IS_ENOATTR() replace flag and the attribute doesn't exist
+ * </PRE>
+ * Other operating system dependant error codes may be returned
+ * in the cases not listed above.
+ *
+ * @remark if neither flag APR_XATTR_CREATE or APR_XATTR_REPLACE are
+ * given then the attribute will either be created if it does not
+ * already exist or replaced if it does exist.
+ *
+ * @warning Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_xattr_set(const apr_xattr_t *xattr,
+ const char *name,
+ const void *value,
+ apr_size_t size,
+ apr_uint32_t flags);
+
+/**
+ * Get an extended attribute from a file or directory
+ * @param xattr the opened extended attribute file or directory context
+ * @param name the name of the attribute to get
+ * @param value the returned attribute value allocated from the pool
+ * @param size the returned size of the attribute value
+ * @param flags to control how the attribute is got (reserved for future use)
+ * @param p the pool to allocate any memory from if required
+ * @return the status of the operation:
+ * <PRE>
+ * APR_SUCCESS the attribute was retrieved
+ * APR_STATUS_IS_ENOATTR() the attribute does not exist
+ * </PRE>
+ * Other operating system dependant error codes may be returned
+ * in the cases not listed above.
+ *
+ * @warning Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_xattr_get(const apr_xattr_t *xattr,
+ const char *name,
+ void **value,
+ apr_size_t *size,
+ apr_uint32_t flags);
+
+/**
+ * Check for the existence of an extended attribute on a file or directory
+ * @param xattr the opened extended attribute file or directory context
+ * @param name the name of the attribute to get
+ * @param exists the returned value indicating whether the attribute exists
+ * @param flags to control how the attribute is got (reserved for future use)
+ * @param p the pool to allocate any memory from if required
+ * @return the status of the operation:
+ * <PRE>
+ * APR_SUCCESS the existence was successfully tested
+ * </PRE>
+ * Other operating system dependant error codes may be returned
+ * in the cases not listed above.
+ *
+ * @warning Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_xattr_exists(const apr_xattr_t *xattr,
+ const char *name,
+ int *exists,
+ apr_uint32_t flags);
+
+/**
+ * List the extended attributes on a file or directory
+ * @param xattr the opened extended attribute file or directory context
+ * @param list the returned array of attributes names
+ * @param flags to control how the file is listed (reserved for future use)
+ * @param p the pool to allocate any memory from if required
+ * @return the status of the operation:
+ * <PRE>
+ * APR_SUCCESS the attributes were listed
+ * </PRE>
+ * Other operating system dependant error codes may be returned
+ * in the cases not listed above.
+ *
+ * @remark list is an array containing simple null terminated strings.
+ *
+ * @warning Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_xattr_list(const apr_xattr_t *xattr,
+ apr_array_header_t **list,
+ apr_uint32_t flags);
+
+/**
+ * Remove an extended attribute from a file or directory
+ * @param xattr the opened extended attribute file or directory context
+ * @param name the attribute name to remove
+ * @param flags to control how the attribute is removed (reserved for future use)
+ * @param p the pool to allocate any memory from if required
+ * @return the status of the operation:
+ * <PRE>
+ * APR_SUCCESS the attribute was removed
+ * APR_STATUS_IS_ENOATTR() the attribute does not exist
+ * </PRE>
+ * Other operating system dependant error codes may be returned
+ * in the cases not listed above.
+ *
+ * @warning Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_xattr_remove(const apr_xattr_t *xattr,
+ const char *name,
+ apr_uint32_t flags);
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ! APR_FILE_XATTR_H */
Index: include/arch/unix/apr_arch_xattr.h
===================================================================
--- include/arch/unix/apr_arch_xattr.h (revision 0)
+++ include/arch/unix/apr_arch_xattr.h (revision 0)
@@ -0,0 +1,51 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FILE_XATTR_H
+#define FILE_XATTR_H
+
+#if APR_HAVE_CTYPE_H
+#include <ctype.h>
+#endif
+#if APR_HAVA_ERRNO_H
+#include <errno.h>
+#endif
+#if APR_HAVE_SYS_XATTR_H
+#include <sys/xattr.h>
+#endif
+#if APR_HAVE_SYS_EXTATTR_H
+#include <sys/extattr.h>
+#endif
+#if APR_HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#if APR_HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+
+#ifdef _LARGEFILE64_SOURCE
+#define XATTR_OPEN_FLAGS O_RDONLY | O_LARGEFILE
+#else
+#define XATTR_OPEN_FLAGS O_RDONLY
+#endif
+
+struct apr_xattr_t {
+ int fd;
+ apr_uint32_t flags;
+ apr_pool_t *pool;
+};
+
+#endif
Index: include/apr_errno.h
===================================================================
--- include/apr_errno.h (revision 606453)
+++ include/apr_errno.h (working copy)
@@ -851,6 +851,13 @@
#define APR_EAFNOSUPPORT (APR_OS_START_CANONERR + 27)
#endif
+/** @see APR_STATUS_IS_ENOATTR */
+#ifdef ENOATTR
+#define APR_ENOATTR ENOATTR
+#else
+#define APR_ENOATTR (APR_OS_START_CANONERR + 28)
+#endif
+
/** @} */
#if defined(OS2) && !defined(DOXYGEN)
@@ -995,6 +1002,7 @@
|| (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED)
#define APR_STATUS_IS_EAFNOSUPPORT(s) ((s) == APR_AFNOSUPPORT \
|| (s) == APR_OS_START_SYSERR + SOCEAFNOSUPPORT)
+#define APR_STATUS_IS_ENOATTR(s) ((s) == APR_ENOATTR)
/*
Sorry, too tired to wrap this up for OS2... feel free to
@@ -1139,6 +1147,7 @@
|| (s) == APR_OS_START_SYSERR + ERROR_DIR_NOT_EMPTY)
#define APR_STATUS_IS_EAFNOSUPPORT(s) ((s) == APR_EAFNOSUPPORT \
|| (s) == APR_OS_START_SYSERR + WSAEAFNOSUPPORT)
+#define APR_STATUS_IS_ENOATTR(s) ((s) == APR_ENOATTR)
#elif defined(NETWARE) && defined(USE_WINSOCK) && !defined(DOXYGEN) /* !defined(OS2) && !defined(WIN32) */
@@ -1200,6 +1209,7 @@
#define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY)
#define APR_STATUS_IS_EAFNOSUPPORT(s) ((s) == APR_EAFNOSUPPORT \
|| (s) == APR_OS_START_SYSERR + WSAEAFNOSUPPORT)
+#define APR_STATUS_IS_ENOATTR(s) ((s) == APR_ENOATTR)
#else /* !defined(NETWARE) && !defined(OS2) && !defined(WIN32) */
@@ -1319,6 +1329,13 @@
(s) == APR_EEXIST)
/** Address Family not supported */
#define APR_STATUS_IS_EAFNOSUPPORT(s) ((s) == APR_EAFNOSUPPORT)
+/** Attribute does not exists */
+#ifdef ENODATA
+#define APR_STATUS_IS_ENOATTR(s) ((s) == APR_ENOATTR \
+ || (s) == ENODATA)
+#else
+#define APR_STATUS_IS_ENOATTR(s) ((s) == APR_ENOATTR)
+#endif
/** @} */
#endif /* !defined(NETWARE) && !defined(OS2) && !defined(WIN32) */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,542 @@
Index: test/Makefile.in
===================================================================
--- test/Makefile.in (revision 606453)
+++ test/Makefile.in (working copy)
@@ -28,7 +28,7 @@
testhash.lo testargs.lo testnames.lo testuser.lo testpath.lo \
testenv.lo testprocmutex.lo testfnmatch.lo testatomic.lo testflock.lo \
testsock.lo testglobalmutex.lo teststrnatcmp.lo testfilecopy.lo \
- testtemp.lo testlfs.lo testcond.lo
+ testtemp.lo testlfs.lo testcond.lo testxattr.lo
OTHER_PROGRAMS = \
sendfile@EXEEXT@ \
Index: test/testxattr.c
===================================================================
--- test/testxattr.c (revision 0)
+++ test/testxattr.c (revision 0)
@@ -0,0 +1,499 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "apr_file_io.h"
+#include "apr_file_xattr.h"
+#include "apr_errno.h"
+#include "apr_general.h"
+#include "testutil.h"
+
+#if APR_HAS_XATTR
+
+#define DIRNAME "data"
+#define FNAME DIRNAME "/file_xattrfile.txt"
+#define DNAME DIRNAME "/dir_xattrdir"
+
+#define TESTKEY1 "testkey1"
+#define TESTVAL1 "testval1"
+#define TESTKEY2 "testkey2"
+#define TESTVAL2 "testval2"
+
+/* test solaris subfilename escaping */
+#define TESTKEYSPECIAL1 "/testkey2"
+#define TESTKEYSPECIAL2 "%testkey2"
+
+static void test_xattr_file_set(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+static void test_xattr_file_set_create(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1),
+ APR_XATTR_CREATE);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1),
+ APR_XATTR_CREATE);
+ ABTS_TRUE(tc, APR_STATUS_IS_EEXIST(rv));
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+static void test_xattr_file_set_replace(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1),
+ APR_XATTR_REPLACE);
+ ABTS_TRUE(tc, APR_STATUS_IS_ENOATTR(rv));
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1),
+ APR_XATTR_CREATE);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1),
+ APR_XATTR_REPLACE);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+static void test_xattr_file_get(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+ apr_size_t size;
+ char *val = NULL;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_get(xattr, TESTKEY1, (void**)&val, &size, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_INT_EQUAL(tc, strlen(TESTVAL1), size);
+ ABTS_PTR_NOTNULL(tc, val);
+ ABTS_TRUE(tc, strncmp(TESTVAL1, val, strlen(TESTVAL1)) == 0);
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+static void test_xattr_file_get_enoattr(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+ apr_size_t size;
+ char *val = NULL;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_get(xattr, TESTKEY1, (void**)&val, &size, 0);
+ ABTS_TRUE(tc, APR_STATUS_IS_ENOATTR(rv));
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+static void test_xattr_file_exists(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+ apr_size_t size;
+ int exists;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_exists(xattr, TESTKEY1, &exists, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_TRUE(tc, !exists);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_exists(xattr, TESTKEY1, &exists, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_TRUE(tc, exists);
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+static void test_xattr_file_list(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+ apr_array_header_t *list = NULL;
+ int cmp1, cmp2;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ rv = apr_xattr_set(xattr, TESTKEY2, TESTVAL2, strlen(TESTVAL2), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_list(xattr, &list, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_PTR_NOTNULL(tc, list);
+ ABTS_INT_EQUAL(tc, 2, list->nelts);
+ cmp1 = (strcmp(APR_ARRAY_IDX(list, 0, char*), TESTKEY1) == 0) &&
+ (strcmp(APR_ARRAY_IDX(list, 1, char*), TESTKEY2) == 0);
+ cmp2 = (strcmp(APR_ARRAY_IDX(list, 0, char*), TESTKEY2) == 0) &&
+ (strcmp(APR_ARRAY_IDX(list, 1, char*), TESTKEY1) == 0);
+ ABTS_TRUE(tc, cmp1 || cmp2 );
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+static void test_xattr_file_remove(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+ apr_size_t size;
+ char *val = NULL;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_remove(xattr, TESTKEY1, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_get(xattr, TESTKEY1, (void**)&val, &size, 0);
+ ABTS_INT_NEQUAL(tc, APR_SUCCESS, rv);
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+static void test_xattr_file_remove_enoattr(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+ apr_size_t size;
+ char *val = NULL;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_remove(xattr, TESTKEY1, 0);
+ ABTS_TRUE(tc, APR_STATUS_IS_ENOATTR(rv));
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+static void test_xattr_dir_set(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+
+ rv = apr_dir_make(DNAME, APR_OS_DEFAULT, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, DNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ apr_xattr_destroy(xattr);
+ apr_dir_remove(DNAME, p);
+}
+
+static void test_xattr_dir_get(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_size_t size;
+ char *val = NULL;
+
+ rv = apr_dir_make(DNAME, APR_OS_DEFAULT, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, DNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_get(xattr, TESTKEY1, (void**)&val, &size, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_INT_EQUAL(tc, strlen(TESTVAL1), size);
+ ABTS_PTR_NOTNULL(tc, val);
+ ABTS_TRUE(tc, strncmp(TESTVAL1, val, strlen(TESTVAL1)) == 0);
+
+ apr_xattr_destroy(xattr);
+ apr_dir_remove(DNAME, p);
+}
+
+static void test_xattr_dir_exists(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+ apr_size_t size;
+ int exists;
+
+ rv = apr_dir_make(DNAME, APR_OS_DEFAULT, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, DNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_exists(xattr, TESTKEY1, &exists, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_TRUE(tc, !exists);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_exists(xattr, TESTKEY1, &exists, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_TRUE(tc, exists);
+
+ apr_xattr_destroy(xattr);
+ apr_dir_remove(DNAME, p);
+}
+
+static void test_xattr_dir_list(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_array_header_t *list = NULL;
+ int cmp1, cmp2;
+
+ rv = apr_dir_make(DNAME, APR_OS_DEFAULT, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, DNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ rv = apr_xattr_set(xattr, TESTKEY2, TESTVAL2, strlen(TESTVAL2), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_list(xattr, &list, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_PTR_NOTNULL(tc, list);
+ ABTS_INT_EQUAL(tc, 2, list->nelts);
+ cmp1 = (strcmp(APR_ARRAY_IDX(list, 0, char*), TESTKEY1) == 0) &&
+ (strcmp(APR_ARRAY_IDX(list, 1, char*), TESTKEY2) == 0);
+ cmp2 = (strcmp(APR_ARRAY_IDX(list, 0, char*), TESTKEY2) == 0) &&
+ (strcmp(APR_ARRAY_IDX(list, 1, char*), TESTKEY1) == 0);
+ ABTS_TRUE(tc, cmp1 || cmp2 );
+
+ apr_xattr_destroy(xattr);
+ apr_dir_remove(DNAME, p);
+}
+
+static void test_xattr_dir_remove(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_size_t size;
+ char *val = NULL;
+
+ rv = apr_dir_make(DNAME, APR_OS_DEFAULT, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, DNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, TESTKEY1, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_remove(xattr, TESTKEY1, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_get(xattr, TESTKEY1, (void**)&val, &size, 0);
+ ABTS_INT_NEQUAL(tc, APR_SUCCESS, rv);
+
+ apr_xattr_destroy(xattr);
+ apr_dir_remove(DNAME, p);
+}
+
+static void test_xattr_open_path_enoent(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_TRUE(tc, APR_STATUS_IS_ENOENT(rv));
+}
+
+static void test_xattr_file_special_chars(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_xattr_t *xattr;
+ apr_file_t *filetest = NULL;
+ apr_size_t size;
+ const char *name = (const char*)data;
+ char *val = NULL;
+ apr_array_header_t *list = NULL;
+ int cmp1, cmp2;
+
+ rv = apr_file_open(&filetest, FNAME,
+ APR_WRITE | APR_CREATE | APR_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_open_path(&xattr, FNAME, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_set(xattr, name, TESTVAL1, strlen(TESTVAL1), 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_xattr_get(xattr, name, (void**)&val, &size, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_INT_EQUAL(tc, strlen(TESTVAL1), size);
+ ABTS_PTR_NOTNULL(tc, val);
+ ABTS_TRUE(tc, strncmp(TESTVAL1, val, strlen(TESTVAL1)) == 0);
+
+ rv = apr_xattr_list(xattr, &list, 0);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_PTR_NOTNULL(tc, list);
+ ABTS_INT_EQUAL(tc, 1, list->nelts);
+ ABTS_TRUE(tc, strcmp(name, APR_ARRAY_IDX(list, 0, char*)) == 0);
+
+ apr_xattr_destroy(xattr);
+ apr_file_close(filetest);
+}
+
+#else
+
+static void test_xattr_not_impl(abts_case *tc, void *data)
+{
+ ABTS_NOT_IMPL(tc, "xattr not implemented on this platform");
+}
+
+#endif /* APR_HAS_XATTR */
+
+abts_suite *testxattr(abts_suite *suite)
+{
+ suite = ADD_SUITE(suite)
+
+#if !APR_HAS_XATTR
+ abts_run_test(suite, test_xattr_not_impl, NULL);
+#else
+ abts_run_test(suite, test_xattr_file_set, NULL);
+ abts_run_test(suite, test_xattr_file_set_create, NULL);
+ abts_run_test(suite, test_xattr_file_set_replace, NULL);
+ abts_run_test(suite, test_xattr_file_get, NULL);
+ abts_run_test(suite, test_xattr_file_get_enoattr, NULL);
+ abts_run_test(suite, test_xattr_file_exists, NULL);
+ abts_run_test(suite, test_xattr_file_list, NULL);
+ abts_run_test(suite, test_xattr_file_remove, NULL);
+ abts_run_test(suite, test_xattr_file_remove_enoattr, NULL);
+ abts_run_test(suite, test_xattr_dir_set, NULL);
+ abts_run_test(suite, test_xattr_dir_get, NULL);
+ abts_run_test(suite, test_xattr_dir_exists, NULL);
+ abts_run_test(suite, test_xattr_dir_list, NULL);
+ abts_run_test(suite, test_xattr_dir_remove, NULL);
+ abts_run_test(suite, test_xattr_open_path_enoent, NULL);
+ abts_run_test(suite, test_xattr_file_special_chars, TESTKEYSPECIAL1);
+ abts_run_test(suite, test_xattr_file_special_chars, TESTKEYSPECIAL2);
+#endif
+
+ return suite;
+}
Index: test/abts_tests.h
===================================================================
--- test/abts_tests.h (revision 606453)
+++ test/abts_tests.h (working copy)
@@ -66,7 +66,8 @@
{testtime},
{testud},
{testuser},
- {testvsn}
+ {testvsn},
+ {testxattr}
};
#endif /* APR_TEST_INCLUDES */
Index: test/testutil.h
===================================================================
--- test/testutil.h (revision 606453)
+++ test/testutil.h (working copy)
@@ -102,5 +102,6 @@
abts_suite *testud(abts_suite *suite);
abts_suite *testuser(abts_suite *suite);
abts_suite *testvsn(abts_suite *suite);
+abts_suite *testxattr(abts_suite *suite);
#endif /* APR_TEST_INCLUDES */

View File

@@ -0,0 +1,191 @@
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apr.h"
#include "apr_lib.h"
#include "apr_getopt.h"
#include "apr_strings.h"
#include "apr_file_io.h"
#include "apr_file_xattr.h"
#if APR_HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if !APR_HAS_XATTR
#error The APR you are using does not have extended attribute support
#endif
static apr_file_t *errfile;
static const char *shortname = "apxattr";
static void usage(void)
{
apr_file_printf(errfile,
"%s -- Utility to view/modify extended attributes on files." APR_EOL_STR
APR_EOL_STR
"Usage: %s -l FILENAME" APR_EOL_STR
" %s -g attr FILENAME" APR_EOL_STR
" %s -s attr -v value FILENAME" APR_EOL_STR
" %s -r attr FILENAME" APR_EOL_STR
APR_EOL_STR
"Options:" APR_EOL_STR
" -l List attributes" APR_EOL_STR
" -g Get attribute" APR_EOL_STR
" -s Set attribute" APR_EOL_STR
" -r Remove attributes" APR_EOL_STR,
shortname, shortname, shortname, shortname, shortname);
exit(1);
}
int main(int argc, const char * const argv[])
{
apr_file_t * outfile;
apr_file_t * infile;
apr_file_t * thefile;
apr_pool_t * pool;
apr_getopt_t * o;
apr_status_t rv;
const char * arg;
char opt;
int opt_list = 0;
char errmsg[120];
const char * opt_get = NULL, * opt_set = NULL, * opt_value = NULL,
* opt_remove = NULL, * filename = NULL;
if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) {
return 1;
}
atexit(apr_terminate);
if (argc) {
shortname = apr_filepath_name_get(argv[0]);
}
if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
return 1;
}
apr_file_open_stderr(&errfile, pool);
apr_getopt_init(&o, pool, argc, argv);
while (1) {
rv = apr_getopt(o, "lg:s:r:v:", &opt, &arg);
if (rv == APR_EOF) {
break;
}
else if (rv != APR_SUCCESS) {
usage();
}
else {
switch (opt) {
case 'l':
opt_list = 1;
break;
case 's':
if (opt_set || opt_get || opt_list || opt_remove) {
usage();
}
opt_set = apr_pstrdup(pool, arg);
break;
case 'v':
if (opt_value || opt_get || opt_list || opt_remove) {
usage();
}
opt_value = apr_pstrdup(pool, arg);
break;
case 'g':
if (opt_set || opt_get || opt_list || opt_remove) {
usage();
}
opt_get = apr_pstrdup(pool, arg);
break;
case 'r':
if (opt_set || opt_get || opt_list || opt_remove) {
usage();
}
opt_remove = apr_pstrdup(pool, arg);
break;
}
}
}
if ((opt_set && !opt_value) || o->ind != argc - 1) {
usage();
}
filename = argv[o->ind];
apr_file_open_stdout(&outfile, pool);
apr_file_open_stdin(&infile, pool);
rv = apr_file_open(&thefile, filename, APR_READ, 0, pool);
if(rv != APR_SUCCESS) {
apr_file_printf(errfile, "*** Couldn't open %s: %s\n",
filename, apr_strerror(rv, errmsg, sizeof errmsg));
exit(1);
}
if (opt_get) {
void *value;
char *value_str;
apr_size_t size;
rv = apr_file_xattr_get(thefile, opt_get, &value, &size, 0, pool);
if(rv != APR_SUCCESS) {
apr_file_printf(errfile, "*** Couldn't get attribute: %s\n",
apr_strerror(rv, errmsg, sizeof errmsg));
exit(1);
}
else {
value_str = apr_pstrmemdup(pool, value, size);
apr_file_printf(outfile, "%s\n", value_str);
}
}
else if (opt_set) {
apr_size_t size;
rv = apr_file_xattr_set(thefile, opt_set, opt_value,
strlen(opt_value), 0, pool);
if(rv != APR_SUCCESS) {
apr_file_printf(errfile, "*** Couldn't set attribute: %s\n",
apr_strerror(rv, errmsg, sizeof errmsg));
exit(1);
}
}
else if (opt_list) {
apr_array_header_t *list = NULL;
rv = apr_file_xattr_list(thefile, &list, 0, pool);
if(rv != APR_SUCCESS) {
apr_file_printf(errfile, "*** Couldn't list attributes: %s\n",
apr_strerror(rv, errmsg, sizeof errmsg));
exit(1);
}
else {
int i;
for(i = 0; i < list->nelts; i++) {
apr_file_printf(outfile, "%s\n", APR_ARRAY_IDX(list, i, char*));
}
}
}
else if (opt_remove) {
rv = apr_file_xattr_remove(thefile, opt_remove, 0, pool);
if(rv != APR_SUCCESS) {
apr_file_printf(errfile, "*** Couldn't remove attribute: %s\n",
apr_strerror(rv, errmsg, sizeof errmsg));
exit(1);
}
}
apr_file_close(thefile);
return 0;
}

View File

@@ -0,0 +1,25 @@
--- config.layout.orig 2006-07-06 21:44:41.000000000 -0700
+++ config.layout 2006-07-06 21:46:26.000000000 -0700
@@ -229,3 +229,22 @@
infodir: ${exec_prefix}/share/info
libsuffix: -${APR_MAJOR_VERSION}
</Layout>
+
+# Gentoo layout
+<Layout gentoo>
+ prefix: /usr
+ exec_prefix: ${prefix}
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/bin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/modules
+ mandir: ${prefix}/man
+ sysconfdir: ${prefix}/conf
+ datadir: /usr/share/apr-${APR_MAJOR_VERSION}
+ installbuilddir: ${datadir}/build-${APR_MAJOR_VERSION}
+ includedir: ${prefix}/include/apr-${APR_MAJOR_VERSION}
+ localstatedir: ${prefix}
+ libsuffix: -${APR_MAJOR_VERSION}
+</Layout>
+
+