| 1 |
# serial 7 -*- Autoconf -*- |
| 2 |
# Copyright (C) 2006-2007, 2009-2023 Free Software Foundation, Inc. |
| 3 |
# This file is free software; the Free Software Foundation |
| 4 |
# gives unlimited permission to copy and/or distribute it, |
| 5 |
# with or without modifications, as long as this notice is preserved. |
| 6 |
|
| 7 |
# From Jim Meyering |
| 8 |
# Provide <selinux/selinux.h>, if necessary. |
| 9 |
# If it is already present, provide wrapper functions to guard against |
| 10 |
# misbehavior from getfilecon, lgetfilecon, and fgetfilecon. |
| 11 |
|
| 12 |
AC_DEFUN([gl_HEADERS_SELINUX_SELINUX_H], |
| 13 |
[ |
| 14 |
AC_REQUIRE([gl_LIBSELINUX]) |
| 15 |
if test "$with_selinux" != no; then |
| 16 |
AC_CHECK_HEADERS([selinux/selinux.h]) |
| 17 |
|
| 18 |
if test $ac_cv_header_selinux_selinux_h = yes; then |
| 19 |
HAVE_SELINUX_SELINUX_H=1 |
| 20 |
else |
| 21 |
HAVE_SELINUX_SELINUX_H=0 |
| 22 |
fi |
| 23 |
|
| 24 |
if test "$ac_cv_header_selinux_selinux_h" = yes; then |
| 25 |
# We do have <selinux/selinux.h>, so do compile getfilecon.c |
| 26 |
# and arrange to use its wrappers. |
| 27 |
gl_CHECK_NEXT_HEADERS([selinux/selinux.h]) |
| 28 |
AC_DEFINE([getfilecon], [rpl_getfilecon], |
| 29 |
[Always use our getfilecon wrapper.]) |
| 30 |
AC_DEFINE([lgetfilecon], [rpl_lgetfilecon], |
| 31 |
[Always use our lgetfilecon wrapper.]) |
| 32 |
AC_DEFINE([fgetfilecon], [rpl_fgetfilecon], |
| 33 |
[Always use our fgetfilecon wrapper.]) |
| 34 |
fi |
| 35 |
|
| 36 |
case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in |
| 37 |
no:*) # already warned |
| 38 |
;; |
| 39 |
*:no) |
| 40 |
AC_MSG_WARN([libselinux was found but selinux/selinux.h is missing.]) |
| 41 |
AC_MSG_WARN([AC_PACKAGE_NAME will be compiled without SELinux support.]) |
| 42 |
esac |
| 43 |
else |
| 44 |
# Do as if <selinux/selinux.h> does not exist, even if |
| 45 |
# AC_CHECK_HEADERS_ONCE has already determined that it exists. |
| 46 |
HAVE_SELINUX_SELINUX_H=0 |
| 47 |
fi |
| 48 |
AC_SUBST([HAVE_SELINUX_SELINUX_H]) |
| 49 |
]) |
| 50 |
|
| 51 |
AC_DEFUN([gl_LIBSELINUX], |
| 52 |
[ |
| 53 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 54 |
AC_REQUIRE([AC_CANONICAL_BUILD]) |
| 55 |
|
| 56 |
AC_ARG_WITH([selinux], |
| 57 |
AS_HELP_STRING([[--without-selinux]], [do not use SELinux, even on systems with SELinux]), |
| 58 |
[], [with_selinux=maybe]) |
| 59 |
|
| 60 |
LIB_SELINUX= |
| 61 |
if test "$with_selinux" != no; then |
| 62 |
gl_save_LIBS=$LIBS |
| 63 |
AC_SEARCH_LIBS([setfilecon], [selinux], |
| 64 |
[test "$ac_cv_search_setfilecon" = "none required" || |
| 65 |
LIB_SELINUX=$ac_cv_search_setfilecon]) |
| 66 |
LIBS=$gl_save_LIBS |
| 67 |
fi |
| 68 |
AC_SUBST([LIB_SELINUX]) |
| 69 |
|
| 70 |
# Warn if SELinux is found but libselinux is absent; |
| 71 |
if test "$ac_cv_search_setfilecon" = no; then |
| 72 |
if test "$host" = "$build" && test -d /selinux; then |
| 73 |
AC_MSG_WARN([This system supports SELinux but libselinux is missing.]) |
| 74 |
AC_MSG_WARN([AC_PACKAGE_NAME will be compiled without SELinux support.]) |
| 75 |
fi |
| 76 |
with_selinux=no |
| 77 |
fi |
| 78 |
]) |