Skip to contentSkip to conversation

libselinux: Add support for pcre2 to pkgconfig definition

PATCH Applied Petr Lautrbach 2 participants 3 messages Oct 11, 2017 – Oct 16, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: Add support for pcre2 to pkgconfig definition

When libselinux is built using USE_PCRE2 libselinux.pc needs to require libpcre2-8 instead of libpcre.

---
 libselinux/Makefile             | 11 ++++++-----
 libselinux/src/Makefile         |  2 +-
 libselinux/src/libselinux.pc.in |  2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)
libselinux/Makefile +6 -5
index 1ecab178..16531fe9 100644
@@ -21,13 +21,14 @@ export DISABLE_SETRANS DISABLE_RPM DISABLE_FLAGS ANDROID_HOST
 
 USE_PCRE2 ?= n
 ifeq ($(USE_PCRE2),y)
-	PCRE_CFLAGS := -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8 $(shell $(PKG_CONFIG) --cflags libpcre2-8)
-	PCRE_LDLIBS := $(shell $(PKG_CONFIG) --libs libpcre2-8)
+	PCRE_MODULE := libpcre2-8
+	PCRE_CFLAGS := -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8
 else
-	PCRE_CFLAGS := $(shell $(PKG_CONFIG) --cflags libpcre)
-	PCRE_LDLIBS := $(shell $(PKG_CONFIG) --libs libpcre)
+	PCRE_MODULE := libpcre
 endif
-export PCRE_CFLAGS PCRE_LDLIBS
+PCRE_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(PCRE_MODULE))
+PCRE_LDLIBS := $(shell $(PKG_CONFIG) --libs $(PCRE_MODULE))
+export PCRE_MODULE PCRE_CFLAGS PCRE_LDLIBS
 
 OS := $(shell uname)
 export OS
libselinux/src/Makefile +1 -1
index 2408faea..18df75c8 100644
@@ -148,7 +148,7 @@ $(LIBSO): $(LOBJS)
 	ln -sf $@ $(TARGET)
 
 $(LIBPC): $(LIBPC).in ../VERSION
-	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
+	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
 
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
 	bash -e exception.sh > $@ || (rm -f $@ ; false)
libselinux/src/libselinux.pc.in +1 -1
index 2cd04d38..2e90a844 100644
@@ -7,6 +7,6 @@ Name: libselinux
 Description: SELinux utility library
 Version: @VERSION@
 URL: http://userspace.selinuxproject.org/
-Requires.private: libsepol libpcre
+Requires.private: libsepol @PCRE_MODULE@
 Libs: -L${libdir} -lselinux
 Cflags: -I${includedir}
Signature · 1 line
2.14.2
#1 lore raw
Quoted 7 lines · Petr Lautrbach

When libselinux is built using USE_PCRE2 libselinux.pc needs to require
libpcre2-8 instead of libpcre.

Thanks, applied.

We still need to revisit the value proposition of file_contexts.bin after the move to pcre2, given the large increase in file size and the runtime overhead. We can add -r to the sefcontext_compile args via semanage.conf, but then I'm wondering whether it is worth having file_contexts.bin at all.

Quoted 61 lines

---
 libselinux/Makefile             | 11 ++++++-----
 libselinux/src/Makefile         |  2 +-
 libselinux/src/libselinux.pc.in |  2 +-

 3 files changed, 8 insertions(+), 7 deletions(-)
libselinux/Makefile +0 -0
index 1ecab178..16531fe9 100644
@@ -21,13 +21,14 @@ export DISABLE_SETRANS DISABLE_RPM DISABLE_FLAGS

ANDROID_HOST

 USE_PCRE2 ?= n
 ifeq ($(USE_PCRE2),y)

libselinux/Makefile +0 -1
-	PCRE_CFLAGS := -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8 $(shell

$(PKG_CONFIG) --cflags libpcre2-8)

libselinux/Makefile +2 -1
-	PCRE_LDLIBS := $(shell $(PKG_CONFIG) --libs libpcre2-8)
+	PCRE_MODULE := libpcre2-8
+	PCRE_CFLAGS := -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8

 else

libselinux/Makefile +1 -2
-	PCRE_CFLAGS := $(shell $(PKG_CONFIG) --cflags libpcre)
-	PCRE_LDLIBS := $(shell $(PKG_CONFIG) --libs libpcre)
+	PCRE_MODULE := libpcre

 endif

libselinux/Makefile +3 -1
-export PCRE_CFLAGS PCRE_LDLIBS
+PCRE_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(PCRE_MODULE))
+PCRE_LDLIBS := $(shell $(PKG_CONFIG) --libs $(PCRE_MODULE))
+export PCRE_MODULE PCRE_CFLAGS PCRE_LDLIBS


 OS := $(shell uname)
 export OS

libselinux/src/Makefile +0 -0
index 2408faea..18df75c8 100644
@@ -148,7 +148,7 @@ $(LIBSO): $(LOBJS)
  	ln -sf $@ $(TARGET)


 $(LIBPC): $(LIBPC).in ../VERSION

libselinux/src/Makefile +0 -1
-	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):;

s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@

libselinux/src/Makefile +1 -0
+	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):;

s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@

 selinuxswig_python_exception.i: ../include/selinux/selinux.h bash -e exception.sh > $@ || (rm -f $@ ; false)

libselinux/src/libselinux.pc.in +0 -0
index 2cd04d38..2e90a844 100644
@@ -7,6 +7,6 @@ Name: libselinux

 Description: SELinux utility library
 Version: @VERSION@
 URL: http://userspace.selinuxproject.org/

libselinux/src/libselinux.pc.in +1 -1
-Requires.private: libsepol libpcre
+Requires.private: libsepol @PCRE_MODULE@

 Libs: -L${libdir} -lselinux
 Cflags: -I${includedir}

#2 lore raw

Value of file_contexts.bin after the move to pcre2

Quoted 5 lines · Stephen Smalley

We still need to revisit the value proposition of file_contexts.bin after the move to pcre2, given the large increase in file size and the runtime overhead. We can add -r to the sefcontext_compile args via semanage.conf, but then I'm wondering whether it is worth having file_contexts.bin at all.

We already use -r in Fedora 27 by default.

Jan Zarsky did some investigation related to file_contexts.bin [1] and according to his results, we it looks like we can simply drop file_contexts.bin completely.

But there were some bugs in past which prevented Anaconda and systems based on OSTree to work when there was no such file in selinux-policy-targeted package. Therefore we need to confirm that if we drop it in Fedora it wouldn't affect them.

Using this configuration in semanage.conf we can avoid creating such files without any change in the code:

[sefcontext_compile]
path = /bin/true
[end]

[1] https://janzarskyblog.wordpress.com/2017/09/06/why-we-dont-need-to-ship-file_contexts-bin-with-selinux-policy/

Petr