diff --git a/m4/virt-selinux.m4 b/m4/virt-selinux.m4 index abb0d12849374ad2a35677a3c3a8dff70d225fd3..dff1c2813e5da0e208f06ac6575f9a2bed180bee 100644 --- a/m4/virt-selinux.m4 +++ b/m4/virt-selinux.m4 @@ -1,6 +1,6 @@ dnl The libselinux.so library dnl -dnl Copyright (C) 2012-2013 Red Hat, Inc. +dnl Copyright (C) 2012-2014 Red Hat, Inc. dnl dnl This library is free software; you can redistribute it and/or dnl modify it under the terms of the GNU Lesser General Public @@ -27,6 +27,21 @@ AC_DEFUN([LIBVIRT_CHECK_SELINUX],[ [with_selinux_mount=check]) if test "$with_selinux" = "yes"; then + # libselinux changed signatures between 2.2 and 2.3 + AC_CACHE_CHECK([for selinux setcon parameter type], [gt_cv_setcon_param], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +int setcon(const security_context_t context); + ]])], + [gt_cv_setcon_param='security_context_t'], + [gt_cv_setcon_param='const char*'])]) + if test "$gt_cv_setcon_param" = 'const char*'; then + AC_DEFINE_UNQUOTED([SELINUX_CTX_CHAR_PTR], 1, + [SELinux uses newer char * for security context]) + fi + AC_MSG_CHECKING([SELinux mount point]) if test "$with_selinux_mount" = "check" || test -z "$with_selinux_mount"; then if test -d /sys/fs/selinux ; then diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c index a82ca6d7e1843c242c224f6a5723065a9fdad6ce..b10167afbcea72534ce83a06e027b0fe6c1fd94b 100644 --- a/tests/securityselinuxhelper.c +++ b/tests/securityselinuxhelper.c @@ -72,26 +72,42 @@ int getpidcon(pid_t pid, security_context_t *context) return getpidcon_raw(pid, context); } +#ifdef SELINUX_CTX_CHAR_PTR +int setcon_raw(const char *context) +#else int setcon_raw(security_context_t context) +#endif { return setenv("FAKE_CONTEXT", context, 1); } +#ifdef SELINUX_CTX_CHAR_PTR +int setcon(const char *context) +#else int setcon(security_context_t context) +#endif { return setcon_raw(context); } #if WITH_ATTR +# ifdef SELINUX_CTX_CHAR_PTR +int setfilecon_raw(const char *path, const char *con) +# else int setfilecon_raw(const char *path, security_context_t con) +# endif { const char *constr = con; return setxattr(path, "user.libvirt.selinux", constr, strlen(constr), 0); } +#ifdef SELINUX_CTX_CHAR_PTR +int setfilecon(const char *path, const char *con) +#else int setfilecon(const char *path, security_context_t con) +#endif { return setfilecon_raw(path, con); }