mirror of
https://github.com/moparisthebest/curl
synced 2025-02-28 17:31:46 -05:00
xattr: add configure check and #ifdefs
setxattr is a glibc call to set extended attributes, so configure now checks for it and the code is adapted to only build when the functionality is present.
This commit is contained in:
parent
fbf51696ef
commit
95719fbea6
@ -2349,6 +2349,7 @@ CURL_CHECK_FUNC_LOCALTIME_R
|
||||
CURL_CHECK_FUNC_MEMRCHR
|
||||
CURL_CHECK_FUNC_POLL
|
||||
CURL_CHECK_FUNC_SETSOCKOPT
|
||||
CURL_CHECK_FUNC_SETXATTR
|
||||
CURL_CHECK_FUNC_SIGACTION
|
||||
CURL_CHECK_FUNC_SIGINTERRUPT
|
||||
CURL_CHECK_FUNC_SIGNAL
|
||||
|
@ -5903,3 +5903,87 @@ AC_DEFUN([CURL_CHECK_FUNC_WRITEV], [
|
||||
ac_cv_func_writev="no"
|
||||
fi
|
||||
])
|
||||
|
||||
dnl CURL_CHECK_FUNC_SETXATTR
|
||||
dnl -------------------------------------------------
|
||||
dnl Verify if setxattr is available, prototyped, and
|
||||
dnl can be compiled. If all of these are true, and
|
||||
dnl usage has not been previously disallowed with
|
||||
dnl shell variable curl_disallow_setxattr, then
|
||||
dnl HAVE_SETXATTR will be defined.
|
||||
|
||||
AC_DEFUN([CURL_CHECK_FUNC_SETXATTR], [
|
||||
AC_REQUIRE([CURL_INCLUDES_SYS_UIO])dnl
|
||||
#
|
||||
tst_links_setxattr="unknown"
|
||||
tst_proto_setxattr="unknown"
|
||||
tst_compi_setxattr="unknown"
|
||||
tst_allow_setxattr="unknown"
|
||||
#
|
||||
AC_MSG_CHECKING([if setxattr can be linked])
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_FUNC_LINK_TRY([setxattr])
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
tst_links_setxattr="yes"
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
tst_links_setxattr="no"
|
||||
])
|
||||
#
|
||||
if test "$tst_links_setxattr" = "yes"; then
|
||||
AC_MSG_CHECKING([if setxattr is prototyped])
|
||||
AC_EGREP_CPP([setxattr],[
|
||||
$curl_includes_sys_uio
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
tst_proto_setxattr="yes"
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
tst_proto_setxattr="no"
|
||||
])
|
||||
fi
|
||||
#
|
||||
if test "$tst_proto_setxattr" = "yes"; then
|
||||
AC_MSG_CHECKING([if setxattr is compilable])
|
||||
AC_COMPILE_IFELSE([
|
||||
AC_LANG_PROGRAM([[
|
||||
$curl_includes_sys_uio
|
||||
]],[[
|
||||
if(0 != setxattr(0, 0, 0))
|
||||
return 1;
|
||||
]])
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
tst_compi_setxattr="yes"
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
tst_compi_setxattr="no"
|
||||
])
|
||||
fi
|
||||
#
|
||||
if test "$tst_compi_setxattr" = "yes"; then
|
||||
AC_MSG_CHECKING([if setxattr usage allowed])
|
||||
if test "x$curl_disallow_setxattr" != "xyes"; then
|
||||
AC_MSG_RESULT([yes])
|
||||
tst_allow_setxattr="yes"
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
tst_allow_setxattr="no"
|
||||
fi
|
||||
fi
|
||||
#
|
||||
AC_MSG_CHECKING([if setxattr might be used])
|
||||
if test "$tst_links_setxattr" = "yes" &&
|
||||
test "$tst_proto_setxattr" = "yes" &&
|
||||
test "$tst_compi_setxattr" = "yes" &&
|
||||
test "$tst_allow_setxattr" = "yes"; then
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE_UNQUOTED(HAVE_SETXATTR, 1,
|
||||
[Define to 1 if you have the setxattr function.])
|
||||
ac_cv_func_setxattr="yes"
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
ac_cv_func_setxattr="no"
|
||||
fi
|
||||
])
|
||||
|
@ -5648,12 +5648,10 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
|
||||
}
|
||||
|
||||
if(config->xattr && outs.filename) {
|
||||
char *url = NULL;
|
||||
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
|
||||
int err = write_xattr(curl, outs.filename );
|
||||
if (err) {
|
||||
warnf( config, "Error setting extended attributes: %s\n", strerror(errno) );
|
||||
}
|
||||
if(err)
|
||||
warnf( config, "Error setting extended attributes: %s\n",
|
||||
strerror(errno) );
|
||||
}
|
||||
|
||||
#ifdef HAVE_UTIME
|
||||
|
40
src/xattr.c
40
src/xattr.c
@ -1,9 +1,35 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/xattr.h> /* include header from libc, not from libattr */
|
||||
#include <string.h>
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/* client-local setup.h */
|
||||
#include "setup.h"
|
||||
#include <curl/curl.h>
|
||||
#include "xattr.h"
|
||||
|
||||
#ifdef HAVE_SETXATTR
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <sys/xattr.h> /* include header from libc, not from libattr */
|
||||
|
||||
/* mapping table of curl metadata to extended attribute names */
|
||||
static struct xattr_mapping {
|
||||
char *attr; /* name of the xattr */
|
||||
@ -35,3 +61,11 @@ int write_xattr( CURL *curl, const char *filename )
|
||||
}
|
||||
return err;
|
||||
}
|
||||
#else
|
||||
int write_xattr(CURL *curl, const char *filename)
|
||||
{
|
||||
(void)curl;
|
||||
(void)filename;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
25
src/xattr.h
25
src/xattr.h
@ -1 +1,26 @@
|
||||
#ifndef __XATTR_H
|
||||
#define __XATTR_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
int write_xattr( CURL *curl, const char *filename );
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user