>From 0b76f0e7e94b3eefa69f46adc52e175689bf276c Mon Sep 17 00:00:00 2001
From: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Date: Wed, 4 Nov 2015 19:52:10 +0200
Subject: [PATCH 2/6] intg: Add socket_wrapper

Add socket_wrapper to integration tests setup. This is required for
Samba setup in integration tests.

Switch to using SYSV-version of fakeroot, "fakeroot-sysv", as
socket_wrapper doesn't support listening on unbound TCP sockets - a
thing which faked-tcp (a part of standard, TCP-version of fakeroot,
"fakeroot-tcp") does. A fix for this is available in socket_wrapper's
"master-fix" branch ATM, but using fakeroot-sysv seems a better idea
anyway.
---
 configure.ac               |  1 +
 contrib/ci/deps.sh         |  2 ++
 src/external/cwrap.m4      |  5 +++++
 src/external/intgcheck.m4  |  5 +++--
 src/tests/intg/Makefile.am | 15 +++++++++++----
 5 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/configure.ac b/configure.ac
index c457879..836cb76 100644
--- a/configure.ac
+++ b/configure.ac
@@ -410,6 +410,7 @@ AM_CONDITIONAL([HAVE_CHECK], [test x$have_check != x])
 AM_CHECK_CMOCKA
 AM_CHECK_UID_WRAPPER
 AM_CHECK_NSS_WRAPPER
+AM_CHECK_SOCKET_WRAPPER
 
 SSS_ENABLE_INTGCHECK_REQS
 
diff --git a/contrib/ci/deps.sh b/contrib/ci/deps.sh
index c9a8a63..dc41ab3 100644
--- a/contrib/ci/deps.sh
+++ b/contrib/ci/deps.sh
@@ -43,6 +43,7 @@ if [[ "$DISTRO_BRANCH" == -redhat-* ]]; then
         pytest
         python-ldap
         rpm-build
+        socket_wrapper
         uid_wrapper
     )
     _DEPS_LIST_SPEC=`
@@ -109,6 +110,7 @@ if [[ "$DISTRO_BRANCH" == -debian-* ]]; then
         libssl-dev
         fakeroot
         libnss-wrapper
+        libsocket-wrapper
         libuid-wrapper
         python-pytest
         python-ldap
diff --git a/src/external/cwrap.m4 b/src/external/cwrap.m4
index b8489cc..1ee0934 100644
--- a/src/external/cwrap.m4
+++ b/src/external/cwrap.m4
@@ -28,3 +28,8 @@ AC_DEFUN([AM_CHECK_NSS_WRAPPER],
 [
     AM_CHECK_WRAPPER(nss_wrapper, HAVE_NSS_WRAPPER)
 ])
+
+AC_DEFUN([AM_CHECK_SOCKET_WRAPPER],
+[
+    AM_CHECK_WRAPPER(socket_wrapper, HAVE_SOCKET_WRAPPER)
+])
diff --git a/src/external/intgcheck.m4 b/src/external/intgcheck.m4
index 80d41b5..91bcde1 100644
--- a/src/external/intgcheck.m4
+++ b/src/external/intgcheck.m4
@@ -1,4 +1,4 @@
-AC_CHECK_PROG([HAVE_FAKEROOT], [fakeroot], [yes], [no])
+AC_CHECK_PROG([HAVE_FAKEROOT_SYSV], [fakeroot-sysv], [yes], [no])
 
 AC_PATH_PROG([PYTEST], [py.test])
 AS_IF([test -n "$PYTEST"], [HAVE_PYTEST=yes], [HAVE_PYTEST=no])
@@ -22,9 +22,10 @@ AC_DEFUN([SSS_ENABLE_INTGCHECK_REQS], [
     if test x"$enable_intgcheck_reqs" = xyes; then
         SSS_INTGCHECK_REQ([HAVE_UID_WRAPPER], [uid_wrapper])
         SSS_INTGCHECK_REQ([HAVE_NSS_WRAPPER], [nss_wrapper])
+        SSS_INTGCHECK_REQ([HAVE_SOCKET_WRAPPER], [socket_wrapper])
         SSS_INTGCHECK_REQ([HAVE_SLAPD], [slapd])
         SSS_INTGCHECK_REQ([HAVE_LDAPMODIFY], [ldapmodify])
-        SSS_INTGCHECK_REQ([HAVE_FAKEROOT], [fakeroot])
+        SSS_INTGCHECK_REQ([HAVE_FAKEROOT_SYSV], [fakeroot-sysv])
         SSS_INTGCHECK_REQ([HAVE_PYTHON2], [python2])
         SSS_INTGCHECK_REQ([HAVE_PYTEST], [pytest])
         SSS_INTGCHECK_REQ([HAVE_PY2MOD_LDAP], [python-ldap])
diff --git a/src/tests/intg/Makefile.am b/src/tests/intg/Makefile.am
index 12a4fc2..efaf1b4 100644
--- a/src/tests/intg/Makefile.am
+++ b/src/tests/intg/Makefile.am
@@ -32,12 +32,16 @@ passwd: root
 group:
 	echo "root:x:0:" > $@
 
+sockets:
+	: Create directory for socket_wrapper sockets
+	mkdir sockets
+
 CLEANFILES=config.py config.pyc passwd group
 
 clean-local:
-	rm -Rf root
+	rm -Rf root sockets
 
-intgcheck-installed: config.py passwd group
+intgcheck-installed: config.py passwd group sockets
 	pipepath="$(DESTDIR)$(pipepath)"; \
 	if test $${#pipepath} -gt 80; then \
 	    echo "error: Pipe directory path too long," \
@@ -48,17 +52,20 @@ intgcheck-installed: config.py passwd group
 	cd "$(abs_srcdir)"; \
 	nss_wrapper=$$(pkg-config --libs nss_wrapper); \
 	uid_wrapper=$$(pkg-config --libs uid_wrapper); \
+	socket_wrapper=$$(pkg-config --libs socket_wrapper); \
 	PATH="$$(dirname -- $(SLAPD)):$$PATH" \
 	PATH="$(DESTDIR)$(sbindir):$(DESTDIR)$(bindir):$$PATH" \
 	PATH="$(abs_builddir):$(abs_srcdir):$$PATH" \
 	PYTHONPATH="$(abs_builddir):$(abs_srcdir)" \
 	LDB_MODULES_PATH="$(DESTDIR)$(ldblibdir)" \
-	LD_PRELOAD="$$nss_wrapper $$uid_wrapper" \
+	LD_PRELOAD="$$nss_wrapper $$uid_wrapper $$socket_wrapper" \
 	NSS_WRAPPER_PASSWD="$(abs_builddir)/passwd" \
 	NSS_WRAPPER_GROUP="$(abs_builddir)/group" \
 	NSS_WRAPPER_MODULE_SO_PATH="$(DESTDIR)$(nsslibdir)/libnss_sss.so.2" \
 	NSS_WRAPPER_MODULE_FN_PREFIX="sss" \
 	UID_WRAPPER=1 \
 	UID_WRAPPER_ROOT=1 \
-	    fakeroot $(PYTHON2) $(PYTEST) -v --tb=native $(INTGCHECK_PYTEST_ARGS) .
+	SOCKET_WRAPPER_DEFAULT_IFACE=2 \
+	SOCKET_WRAPPER_DIR="$(abs_builddir)/sockets" \
+	    fakeroot-sysv $(PYTHON2) $(PYTEST) -v --tb=native $(INTGCHECK_PYTEST_ARGS) .
 	rm -f $(DESTDIR)$(logpath)/*
-- 
2.6.2

