>From 2f8c9faa430815ba7b2eb4484b0a3f9eee005b66 Mon Sep 17 00:00:00 2001
From: Rich Megginson <rmeggins@redhat.com>
Date: Thu, 8 Oct 2009 15:51:23 -0600
Subject: [PATCH] Move mod_admserv and mod_restartd into adminserver
 mod_admserv and mod_restartd are only ever used and built in conjunction
 with the admin server, so they should be part of the admin server source
 tree, and built and installed as part of the main admin server build.
 The only files we need from the old CVS mod_admserv and mod_restartd
 repos are the source files.  The rest of the configure and makefile
 code has been merged in with the main admin server configure.ac
 and Makefile.am and httpd.m4.

---
 Makefile.am                     |   36 +-
 Makefile.in                     |  414 +++---
 configure                       |  340 +----
 configure.ac                    |   25 +-
 m4/httpd.m4                     |   24 +-
 mod_admserv/LICENSE             |  202 +++
 mod_admserv/README              |    3 +
 mod_admserv/mod_admserv.c       | 3025 +++++++++++++++++++++++++++++++++++++++
 mod_admserv/mod_admserv.h       |  156 ++
 mod_restartd/LICENSE            |   62 +
 mod_restartd/README             |   29 +
 mod_restartd/mod_include-2.2.h  |  160 ++
 mod_restartd/mod_include.h      |  240 ++++
 mod_restartd/mod_restartd-2.2.c | 1866 ++++++++++++++++++++++++
 mod_restartd/mod_restartd.c     | 1837 ++++++++++++++++++++++++
 mod_restartd/mod_suexec-2.2.h   |   77 +
 mod_restartd/mod_suexec.h       |   66 +
 17 files changed, 8050 insertions(+), 512 deletions(-)
 create mode 100644 mod_admserv/LICENSE
 create mode 100644 mod_admserv/README
 create mode 100644 mod_admserv/mod_admserv.c
 create mode 100644 mod_admserv/mod_admserv.h
 create mode 100644 mod_restartd/LICENSE
 create mode 100644 mod_restartd/README
 create mode 100644 mod_restartd/mod_include-2.2.h
 create mode 100644 mod_restartd/mod_include.h
 create mode 100644 mod_restartd/mod_restartd-2.2.c
 create mode 100644 mod_restartd/mod_restartd.c
 create mode 100644 mod_restartd/mod_suexec-2.2.h
 create mode 100644 mod_restartd/mod_suexec.h

diff --git a/Makefile.am b/Makefile.am
index 35f5e5d..c5b16f3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,20 +35,6 @@ PATH_DEFINES = -DINITCONFIGDIR="\"$(initconfigdir)\""
 # look for included m4 files in the ./m4/ directory
 ACLOCAL_AMFLAGS = -I m4
 
-# passed to the mod subdirs - so they know they are being
-# built as part of admin server and not standalone
-AM_MAKEFLAGS = ADMINSERVER=1
-
-if MOD_ADMSERV
-  MOD_ADMSERV_SUB = mod_admserv
-endif
-
-if MOD_RESTARTD
-  MOD_RESTARTD_SUB = mod_restartd
-endif
-
-SUBDIRS = $(MOD_ADMSERV_SUB) $(MOD_RESTARTD_SUB)
-
 install-data-hook:
 	@for file in $(RESOURCE_BUNDLES_ROOT) ; do \
 	  progdir=`dirname $$file` ; \
@@ -125,16 +111,21 @@ if HPUX
 AM_LDFLAGS = -lpthread
 endif
 
+# CGI shared library
 lib_LTLIBRARIES = libds-admin-serv.la
 
+# CGI static library
 noinst_LIBRARIES = libdsa.a
 
+# Apache modules
+admmod_LTLIBRARIES = mod_admserv.la mod_restartd.la
+
 LIBSOCKET=@LIBSOCKET@
 LIBNSL=@LIBNSL@
 LIBCSTD=@LIBCSTD@
 LIBCRUN=@LIBCRUN@
 
-DEFAULT_LIBS = libds-admin-serv.la @adminutil_lib@ -ladmsslutil@adminutil_ver@ -ladminutil@adminutil_ver@ \
+DEFAULT_LIBS_NOCGI = @adminutil_lib@ -ladmsslutil@adminutil_ver@ -ladminutil@adminutil_ver@ \
 	@icu_lib@ -licui18n -licuuc -licudata \
 	@ldapsdk_lib@ -lssldap60 -lprldap60 -lldap60 -lldif60 \
 	@sasl_lib@ -lsasl2 \
@@ -142,6 +133,8 @@ DEFAULT_LIBS = libds-admin-serv.la @adminutil_lib@ -ladmsslutil@adminutil_ver@ -
 	@nspr_lib@ -lplds4 -lplc4 -lnspr4 \
 	$(LIBNSL) $(LIBSOCKET) $(LIBCSTD) $(LIBCRUN)
 
+DEFAULT_LIBS = libds-admin-serv.la $(DEFAULT_LIBS_NOCGI)
+
 if CXXLINK_REQUIRED
 MYLINK = $(CXXLINK)
 else
@@ -331,6 +324,19 @@ ds_snmpctrl_CPPFLAGS = -I$(srcdir)/include/libdsa $(AM_CPPFLAGS)
 ds_snmpctrl_LDADD = libdsa.a $(DEFAULT_LIBS)
 ds_snmpctrl_LINK = $(MYLINK)
 
+############## mod_admserv ################
+mod_admserv_la_SOURCES = mod_admserv/mod_admserv.c
+mod_admserv_la_CPPFLAGS = -I@apache_inc@ @apr_inc@ $(AM_CPPFLAGS) @extra_cppflags@
+mod_admserv_la_LDFLAGS = -module -avoid-version
+mod_admserv_la_LIBADD = $(DEFAULT_LIBS_NOCGI)
+mod_admserv_la_LINK = $(MYLINK) $(mod_admserv_la_LDFLAGS)
+
+############## mod_restartd ################
+mod_restartd_la_SOURCES = mod_restartd/mod_restartd@ap_ver_suf@.c
+mod_restartd_la_CPPFLAGS = @apr_inc@ -I@apache_inc@ @extra_cppflags@
+mod_restartd_la_LDFLAGS = -module -avoid-version
+mod_restartd_la_LINK = $(MYLINK) $(mod_restartd_la_LDFLAGS)
+
 ############## Data Files ################
 HTMLDIR = admserv/html
 dist_html_DATA = $(HTMLDIR)/htmladmin.html $(HTMLDIR)/monreplication.html $(HTMLDIR)/viewdata.html $(HTMLDIR)/viewlog.html $(HTMLDIR)/admserv.html
diff --git a/configure.ac b/configure.ac
index d403ccc..7327a45 100644
--- a/configure.ac
+++ b/configure.ac
@@ -349,6 +349,15 @@ AC_SUBST(icu_lib)
 AC_SUBST(icu_libdir)
 AC_SUBST(icu_inc)
 AC_SUBST(icu_bin)
+# extra stuff for Apache modules
+AC_SUBST(APXS)
+AC_SUBST(apr_inc)
+AC_SUBST(apache_inc)
+AC_SUBST(apache_conf)
+AC_SUBST(apache_prefix)
+AC_SUBST(apache_bin)
+AC_SUBST(extra_cppflags)
+AC_SUBST(ap_ver_suf)
 
 # write out paths for data/config files
 AC_SUBST(instconfigdir)
@@ -422,20 +431,4 @@ fi
 
 AC_CONFIG_FILES([Makefile])
 
-# if doing a recursive configure, add --with-adminserver
-# to the list of args for the modules
-ac_configure_args="$ac_configure_args --with-adminserver --with-apxs=$APXS --with-apr-config=$APR_CONFIG --with-moddir=$admmoddir"
-
-if test -d $srcdir/mod_admserv ; then
-   AC_CONFIG_SUBDIRS([mod_admserv])
-   MOD_ADMSERV=true
-fi
-AM_CONDITIONAL([MOD_ADMSERV], $MOD_ADMSERV)
-
-if test -d $srcdir/mod_restartd ; then
-   AC_CONFIG_SUBDIRS([mod_restartd])
-   MOD_RESTARTD=true
-fi
-AM_CONDITIONAL([MOD_RESTARTD], $MOD_RESTARTD)
-
 AC_OUTPUT
diff --git a/m4/httpd.m4 b/m4/httpd.m4
index 9c68108..f7d1991 100644
--- a/m4/httpd.m4
+++ b/m4/httpd.m4
@@ -134,7 +134,7 @@ if test -z "$APR_CONFIG" ; then
                       [$PATH:/opt/hpws/apache/bin:/usr/local/apache/bin:/usr/bin])
     fi
     if test -z "$APR_CONFIG" ; then
-        AC_MSG_ERROR([Apache2 apr-config program not found])
+        AC_MSG_ERROR([Apache2 apr-config program not found - please specify with --with-apr-config=/path/to/apr-config])
     fi
 fi
 
@@ -147,3 +147,25 @@ if test -z "$moddir" ; then
         moddir='$(libdir)/httpd/modules'
     fi
 fi
+
+dnl set the variables we need to build modules
+apr_inc=`$APR_CONFIG --includes`
+apache_inc=`$APXS -q INCLUDEDIR`
+apache_conf=`$APXS -q SYSCONFDIR`
+apache_prefix=`$APXS -q PREFIX`
+apache_bin=`$APXS -q SBINDIR`
+extra_cppflags=`$APXS -q EXTRA_CPPFLAGS` 
+
+if ! test -f "$apache_inc/apr.h"; then
+  if test -z "$apr_inc"; then
+    AC_MSG_ERROR([apr.h is not in your Apache include dir as reported by apxs. Use --with-apxs to have apxs tell us where to find it.])
+  fi
+fi
+
+dnl figure out the apr API version
+apr_version=`$APR_CONFIG --version`
+case $apr_version in
+1.*) ap_ver_suf="-2.2" ;;
+0.9*) ap_ver_suf= ;;
+*) AC_MSG_ERROR(APR version $apr_version is not supported by this module) ;;
+esac
diff --git a/mod_admserv/README b/mod_admserv/README
new file mode 100644
index 0000000..7133836
--- /dev/null
+++ b/mod_admserv/README
@@ -0,0 +1,3 @@
+mod_admserv - http://port389.org/wiki/mod_admserv
+
+mod_admserv provides the HTTP functionality associated with the 389 Administration Server http://port389.org/wiki/AdminServer.  It is a standard Apache module and uses standard Apache build tools and configure, built as part of Admin Server.
diff --git a/mod_restartd/README b/mod_restartd/README
new file mode 100644
index 0000000..b249e54
--- /dev/null
+++ b/mod_restartd/README
@@ -0,0 +1,29 @@
+08/15/2005
+
+This is a modified mod_cgid.c from httpd-2.0.46. The changes have
+purposely been kept at a minimum to hopefully reduce patch merge
+issues in the future. This version was chosen to be compatible with
+the Apache shipped on RHEL 3.
+
+PURPOSE
+
+This is needed so we can retain root priviledges when running some
+specific CGIs in the admin server. Caution should be taken when
+configuring your server. RetainPerms must be "on" in order for the
+CGI to be executed by mod_restartd, otherwise this dumps out. It is
+registered to run before mod_cgi so anything not handled here will
+be executed by mod_cgi. You definitely don't want any random CGIs
+executed by mod_restartd.
+
+In order to compile standalone, local copies of mod_suexec.h and
+mod_include.h are needed. They are also from 2.0.46.
+
+BUILDING
+
+This is built as part of the Admin Server build.  It is not intended to
+be built standalone.
+
+INSTALLING
+
+This is installed as part of the Admin Server install.  It is not intended to
+be installed standalone.
