Add options to handle xattr at compile time.

Swupd used to use a sorted blob of extended file attributes as part of
the data that was used to verify the contents. This caused problems if
extra attributes were added. In particular if a clearlinux system was
being run in a container that had selinux enabled in the base OS.

Add a configure option to allow the attributes to be considered or
not. Based on advice, the default is to ignore them, as this is what
everyone expects.

Tidied up passing a --selinux flag to tar, this is also handled by a new
config option.

Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
This commit is contained in:
Icarus Sparry
2016-11-08 17:44:02 -08:00
committed by tmarcu
parent 8300b1c4a9
commit fc0f570d20
4 changed files with 47 additions and 8 deletions
+27 -3
View File
@@ -126,8 +126,31 @@ AC_ARG_ENABLE(
AS_HELP_STRING([--enable-bsdtar], [Use alternative bsdtar command (uses tar by default)]) AS_HELP_STRING([--enable-bsdtar], [Use alternative bsdtar command (uses tar by default)])
) )
AS_IF([test "x$enable_bsdtar" = "xyes" ], AS_IF([test "x$enable_bsdtar" = "xyes" ],
[AC_DEFINE(SWUPD_WITH_BSDTAR, 1, [Use bsdtar])], [AC_DEFINE(SWUPD_WITH_BSDTAR, 1, [Use bsdtar])]
[AC_DEFINE(SWUPD_WITHOUT_BSDTAR, 1, [Use default tar])] )
dnl Enable extended attribute support
XATTR="yes"
AC_ARG_ENABLE(
[xattr],
AS_HELP_STRING([--enable-xattr],[Use extended file attributes (unused by default)])
)
AS_IF([test "x$enable_xattr" = "xyes"],
[AC_DEFINE(SWUPD_WITH_XATTRS,1,[Use extended file attributes])
AS_IF(test "x$enable_bsdtar" = "xyes",
echo "Options --enable-bsdtar and --enable-xattr are incompatible" >&2
AS_EXIT(1))],
[XATTR=no]
)
TARSELINUX="yes"
AC_ARG_ENABLE([tar-selinux],
AS_HELP_STRING([--enable-tar-selinux],[give --selinux option to tar])
)
AS_IF([test "x$enable_tar_selinux" = "xyes"],
[AC_DEFINE(SWUPD_TAR_SELINUX,1,[give --selinux option to tar])
AS_IF(test "x$enable_xattr" = "xyes",,
echo "Must have --enable-xattr to have --enable-tar-selinux" >&2
AS_EXIT(1))],
[TARSELINUX=no]
) )
AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR], AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
@@ -165,7 +188,6 @@ certs_path="/usr/share/clear/update-ca"
AH_TEMPLATE([SWUPD_LINUX_ROOTFS],[Enable Linux rootfs build variant]) AH_TEMPLATE([SWUPD_LINUX_ROOTFS],[Enable Linux rootfs build variant])
## (2) variant features ## (2) variant features
AH_TEMPLATE([SWUPD_WITH_BINDMNTS],[cope with bind mounts over rootfs]) AH_TEMPLATE([SWUPD_WITH_BINDMNTS],[cope with bind mounts over rootfs])
AH_TEMPLATE([SWUPD_WITH_SELINUX],[handle selinux attributes])
## (3) variant extra options ## (3) variant extra options
AH_TEMPLATE([MOUNT_POINT],[The mount point]) AH_TEMPLATE([MOUNT_POINT],[The mount point])
AH_TEMPLATE([STATE_DIR],[The state directory for swupd content]) AH_TEMPLATE([STATE_DIR],[The state directory for swupd content])
@@ -209,4 +231,6 @@ Configuration to build swupd-client:
SSL Certificate file: ${SWUPDCERT} SSL Certificate file: ${SWUPDCERT}
Use bzip compression: ${BZIP} Use bzip compression: ${BZIP}
Run Tests: ${TESTS} Run Tests: ${TESTS}
Use extended file attributes ${XATTR}
Use --selinux option for tar ${TARSELINUX}
]) ])
+8 -3
View File
@@ -13,13 +13,18 @@
#define TAR_XATTR_ARGS "" #define TAR_XATTR_ARGS ""
#else #else
#define TAR_COMMAND "tar" #define TAR_COMMAND "tar"
/* configure.ac ensures a sensible configuration of bsdtar/selinux/xattr */
#ifdef SWUPD_TAR_SELINUX
#define TAR_XATTR_ARGS "--xattrs --xattrs-include='*' --selinux"
#else
#define TAR_XATTR_ARGS "--xattrs --xattrs-include='*'" #define TAR_XATTR_ARGS "--xattrs --xattrs-include='*'"
#endif #endif
#endif
#ifdef SWUPD_WITH_SELINUX #ifdef SWUPD_WITH_XATTRS
#define TAR_PERM_ATTR_ARGS "--preserve-permissions --selinux " TAR_XATTR_ARGS
#else /* SWUPD_WITHOUT_SELINUX */
#define TAR_PERM_ATTR_ARGS "--preserve-permissions " TAR_XATTR_ARGS #define TAR_PERM_ATTR_ARGS "--preserve-permissions " TAR_XATTR_ARGS
#else /* SWUPD_WITHOUT_XATTRS */
#define TAR_PERM_ATTR_ARGS "--preserve-permissions "
#endif #endif
#endif #endif
+4 -2
View File
@@ -16,8 +16,10 @@ void xattrs_copy(const char *src_filename, const char *dst_filename);
/* /*
* Attempt to pack into a data blob the extended attributes of the given file. * Attempt to pack into a data blob the extended attributes of the given file.
* The data blob will be allocated and possibly filled with first the list * The data blob will be allocated and possibly filled with first the sorted
* of all the extended attributes names, and then their values. * list of all the extended attributes names, and then their values.
* The values will be NUL terminated, but the encoding is not reversable so
* is only suitable to use as input to a hashing function.
* @param filename - The file from which the extended attributes will be * @param filename - The file from which the extended attributes will be
* read and packed into the data blob. * read and packed into the data blob.
* @param blob - The data blob pointer into which the extended attributes will * @param blob - The data blob pointer into which the extended attributes will
+8
View File
@@ -37,6 +37,14 @@ enum xattrs_action_type_t_ {
typedef enum xattrs_action_type_t_ xattrs_action_type_t; typedef enum xattrs_action_type_t_ xattrs_action_type_t;
/* If SWUPD_WITH_XATTRS is not defined, create functions to override
* glibc's interface to the system calls
*/
#ifndef SWUPD_WITH_XATTRS
#define lgetxattr(p,n,b,l) (-1)
#define llistxattr(p,b,l) (0)
#endif
static int xattr_get_value(const char *path, const char *name, char **blob, static int xattr_get_value(const char *path, const char *name, char **blob,
size_t *blob_len, xattrs_action_type_t action) size_t *blob_len, xattrs_action_type_t action)
{ {