Blame SOURCES/httpd-2.4.4-r1337344+.patch

af9b8b
# ./pullrev.sh 1337344 1341905 1342065 1341930
af9b8b
af9b8b
suexec enhancements:
af9b8b
af9b8b
1) use syslog for logging
af9b8b
2) use capabilities not setuid/setgid root binary
af9b8b
af9b8b
http://svn.apache.org/viewvc?view=revision&revision=1337344
af9b8b
http://svn.apache.org/viewvc?view=revision&revision=1341905
af9b8b
http://svn.apache.org/viewvc?view=revision&revision=1342065
af9b8b
http://svn.apache.org/viewvc?view=revision&revision=1341930
af9b8b
af9b8b
--- httpd-2.4.4/configure.in.r1337344+
af9b8b
+++ httpd-2.4.4/configure.in
af9b8b
@@ -734,7 +734,24 @@ APACHE_HELP_STRING(--with-suexec-gidmin,
af9b8b
 
af9b8b
 AC_ARG_WITH(suexec-logfile,
af9b8b
 APACHE_HELP_STRING(--with-suexec-logfile,Set the logfile),[
af9b8b
-  AC_DEFINE_UNQUOTED(AP_LOG_EXEC, "$withval", [SuExec log file] ) ] )
af9b8b
+  if test "x$withval" = "xyes"; then
af9b8b
+    AC_DEFINE_UNQUOTED(AP_LOG_EXEC, "$withval", [SuExec log file])
af9b8b
+  fi
af9b8b
+])
af9b8b
+
af9b8b
+AC_ARG_WITH(suexec-syslog,
af9b8b
+APACHE_HELP_STRING(--with-suexec-syslog,Set the logfile),[
af9b8b
+  if test $withval = "yes"; then
af9b8b
+    if test "x${with_suexec_logfile}" != "xno"; then
af9b8b
+      AC_MSG_NOTICE([hint: use "--without-suexec-logfile --with-suexec-syslog"])
af9b8b
+      AC_MSG_ERROR([suexec does not support both logging to file and syslog])
af9b8b
+    fi
af9b8b
+    AC_CHECK_FUNCS([vsyslog], [], [
af9b8b
+       AC_MSG_ERROR([cannot support syslog from suexec without vsyslog()])])
af9b8b
+    AC_DEFINE(AP_LOG_SYSLOG, 1, [SuExec log to syslog])
af9b8b
+  fi    
af9b8b
+])
af9b8b
+
af9b8b
 
af9b8b
 AC_ARG_WITH(suexec-safepath,
af9b8b
 APACHE_HELP_STRING(--with-suexec-safepath,Set the safepath),[
af9b8b
@@ -744,6 +761,15 @@ AC_ARG_WITH(suexec-umask,
af9b8b
 APACHE_HELP_STRING(--with-suexec-umask,umask for suexec'd process),[
af9b8b
   AC_DEFINE_UNQUOTED(AP_SUEXEC_UMASK, 0$withval, [umask for suexec'd process] ) ] )
af9b8b
 
af9b8b
+INSTALL_SUEXEC=setuid
af9b8b
+AC_ARG_ENABLE([suexec-capabilities], 
af9b8b
+APACHE_HELP_STRING(--enable-suexec-capabilities,Use Linux capability bits not setuid root suexec), [
af9b8b
+INSTALL_SUEXEC=caps
af9b8b
+AC_DEFINE(AP_SUEXEC_CAPABILITIES, 1, 
af9b8b
+          [Enable if suexec is installed with Linux capabilities, not setuid])
af9b8b
+])
af9b8b
+APACHE_SUBST(INSTALL_SUEXEC)
af9b8b
+
af9b8b
 dnl APR should go after the other libs, so the right symbols can be picked up
af9b8b
 if test x${apu_found} != xobsolete; then
af9b8b
   AP_LIBS="$AP_LIBS `$apu_config --avoid-ldap --link-libtool`"
af9b8b
--- httpd-2.4.4/docs/manual/suexec.html.en.r1337344+
af9b8b
+++ httpd-2.4.4/docs/manual/suexec.html.en
af9b8b
@@ -372,6 +372,21 @@
af9b8b
       together with the --enable-suexec option to let
af9b8b
       APACI accept your request for using the suEXEC feature.
af9b8b
 
af9b8b
+      
--enable-suexec-capabilities
af9b8b
+
af9b8b
+      
Linux specific: Normally,
af9b8b
+      the suexec binary is installed "setuid/setgid
af9b8b
+      root", which allows it to run with the full privileges of the
af9b8b
+      root user.  If this option is used, the suexec
af9b8b
+      binary will instead be installed with only the setuid/setgid
af9b8b
+      "capability" bits set, which is the subset of full root
af9b8b
+      priviliges required for suexec operation.  Note that
af9b8b
+      the suexec binary may not be able to write to a log
af9b8b
+      file in this mode; it is recommended that the
af9b8b
+      --with-suexec-syslog --without-suexec-logfile
af9b8b
+      options are used in conjunction with this mode, so that syslog
af9b8b
+      logging is used instead.
af9b8b
+
af9b8b
       
--with-suexec-bin=PATH
af9b8b
 
af9b8b
       
The path to the suexec binary must be hard-coded
af9b8b
@@ -433,6 +448,12 @@
af9b8b
       "suexec_log" and located in your standard logfile
af9b8b
       directory (--logfiledir).
af9b8b
 
af9b8b
+      
--with-suexec-syslog
af9b8b
+
af9b8b
+      
If defined, suexec will log notices and errors to syslog
af9b8b
+      instead of a logfile.  This option must be combined
af9b8b
+      with --without-suexec-logfile.
af9b8b
+
af9b8b
       
--with-suexec-safepath=PATH
af9b8b
 
af9b8b
       
Define a safe PATH environment to pass to CGI
af9b8b
@@ -550,9 +571,12 @@ Group webgroup
af9b8b
 
af9b8b
     

The suEXEC wrapper will write log information

af9b8b
     to the file defined with the --with-suexec-logfile
af9b8b
-    option as indicated above. If you feel you have configured and
af9b8b
-    installed the wrapper properly, have a look at this log and the
af9b8b
-    error_log for the server to see where you may have gone astray.

af9b8b
+    option as indicated above, or to syslog if --with-suexec-syslog
af9b8b
+    is used. If you feel you have configured and
af9b8b
+    installed the wrapper properly, have a look at the log and the
af9b8b
+    error_log for the server to see where you may have gone astray. 
af9b8b
+    The output of "suexec -V" will show the options
af9b8b
+    used to compile suexec, if using a binary distribution.

af9b8b
 
af9b8b
 
top
af9b8b
 
af9b8b
@@ -640,4 +664,4 @@ if (typeof(prettyPrint) !== 'undefined')
af9b8b
     prettyPrint();
af9b8b
 }
af9b8b
 //--></script>
af9b8b
-</body></html>
af9b8b
\ No newline at end of file
af9b8b
+</body></html>
af9b8b
--- httpd-2.4.4/Makefile.in.r1337344+
af9b8b
+++ httpd-2.4.4/Makefile.in
af9b8b
@@ -238,11 +238,22 @@ install-man:
af9b8b
 	  cd $(DESTDIR)$(manualdir) && find . -name ".svn" -type d -print | xargs rm -rf 2>/dev/null || true; \
af9b8b
 	fi
af9b8b
 
af9b8b
-install-suexec:
af9b8b
+install-suexec: install-suexec-binary install-suexec-$(INSTALL_SUEXEC)
af9b8b
+
af9b8b
+install-suexec-binary:
af9b8b
 	@if test -f $(builddir)/support/suexec; then \
af9b8b
             test -d $(DESTDIR)$(sbindir) || $(MKINSTALLDIRS) $(DESTDIR)$(sbindir); \
af9b8b
             $(INSTALL_PROGRAM) $(top_builddir)/support/suexec $(DESTDIR)$(sbindir); \
af9b8b
-            chmod 4755 $(DESTDIR)$(sbindir)/suexec; \
af9b8b
+	fi
af9b8b
+
af9b8b
+install-suexec-setuid:
af9b8b
+	@if test -f $(builddir)/support/suexec; then \
af9b8b
+	    chmod 4755 $(DESTDIR)$(sbindir)/suexec; \
af9b8b
+	fi
af9b8b
+
af9b8b
+install-suexec-caps:
af9b8b
+	@if test -f $(builddir)/support/suexec; then \
af9b8b
+            setcap 'cap_setuid,cap_setgid+pe' $(DESTDIR)$(sbindir)/suexec; \
af9b8b
 	fi
af9b8b
 
af9b8b
 suexec:
af9b8b
--- httpd-2.4.4/modules/arch/unix/mod_unixd.c.r1337344+
af9b8b
+++ httpd-2.4.4/modules/arch/unix/mod_unixd.c
af9b8b
@@ -284,6 +284,13 @@ unixd_set_suexec(cmd_parms *cmd, void *d
af9b8b
     return NULL;
af9b8b
 }
af9b8b
 
af9b8b
+#ifdef AP_SUEXEC_CAPABILITIES
af9b8b
+/* If suexec is using capabilities, don't test for the setuid bit. */
af9b8b
+#define SETUID_TEST(finfo) (1)
af9b8b
+#else
af9b8b
+#define SETUID_TEST(finfo) (finfo.protection & APR_USETID)
af9b8b
+#endif
af9b8b
+
af9b8b
 static int
af9b8b
 unixd_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
af9b8b
                  apr_pool_t *ptemp)
af9b8b
@@ -300,7 +307,7 @@ unixd_pre_config(apr_pool_t *pconf, apr_
af9b8b
     ap_unixd_config.suexec_enabled = 0;
af9b8b
     if ((apr_stat(&wrapper, SUEXEC_BIN, APR_FINFO_NORM, ptemp))
af9b8b
          == APR_SUCCESS) {
af9b8b
-        if ((wrapper.protection & APR_USETID) && wrapper.user == 0
af9b8b
+        if (SETUID_TEST(wrapper) && wrapper.user == 0
af9b8b
             && (access(SUEXEC_BIN, R_OK|X_OK) == 0)) {
af9b8b
             ap_unixd_config.suexec_enabled = 1;
af9b8b
             ap_unixd_config.suexec_disabled_reason = "";
af9b8b
--- httpd-2.4.4/support/suexec.c.r1337344+
af9b8b
+++ httpd-2.4.4/support/suexec.c
af9b8b
@@ -58,6 +58,10 @@
af9b8b
 #include <grp.h>
af9b8b
 #endif
af9b8b
 
af9b8b
+#ifdef AP_LOG_SYSLOG
af9b8b
+#include <syslog.h>
af9b8b
+#endif
af9b8b
+
af9b8b
 #if defined(PATH_MAX)
af9b8b
 #define AP_MAXPATH PATH_MAX
af9b8b
 #elif defined(MAXPATHLEN)
af9b8b
@@ -69,7 +73,20 @@
af9b8b
 #define AP_ENVBUF 256
af9b8b
 
af9b8b
 extern char **environ;
af9b8b
+
af9b8b
+#ifdef AP_LOG_SYSLOG
af9b8b
+/* Syslog support. */
af9b8b
+#if !defined(AP_LOG_FACILITY) && defined(LOG_AUTHPRIV)
af9b8b
+#define AP_LOG_FACILITY LOG_AUTHPRIV
af9b8b
+#elif !defined(AP_LOG_FACILITY)
af9b8b
+#define AP_LOG_FACILITY LOG_AUTH
af9b8b
+#endif
af9b8b
+
af9b8b
+static int log_open;
af9b8b
+#else
af9b8b
+/* Non-syslog support. */
af9b8b
 static FILE *log = NULL;
af9b8b
+#endif
af9b8b
 
af9b8b
 static const char *const safe_env_lst[] =
af9b8b
 {
af9b8b
@@ -137,7 +154,14 @@ static void err_output(int is_error, con
af9b8b
 
af9b8b
 static void err_output(int is_error, const char *fmt, va_list ap)
af9b8b
 {
af9b8b
-#ifdef AP_LOG_EXEC
af9b8b
+#if defined(AP_LOG_SYSLOG)
af9b8b
+    if (!log_open) {
af9b8b
+        openlog("suexec", LOG_PID, AP_LOG_FACILITY);
af9b8b
+        log_open = 1;
af9b8b
+    }
af9b8b
+
af9b8b
+    vsyslog(is_error ? LOG_ERR : LOG_INFO, fmt, ap);
af9b8b
+#elif defined(AP_LOG_EXEC)
af9b8b
     time_t timevar;
af9b8b
     struct tm *lt;
af9b8b
 
af9b8b
@@ -295,7 +319,9 @@ int main(int argc, char *argv[])
af9b8b
 #ifdef AP_HTTPD_USER
af9b8b
         fprintf(stderr, " -D AP_HTTPD_USER=\"%s\"\n", AP_HTTPD_USER);
af9b8b
 #endif
af9b8b
-#ifdef AP_LOG_EXEC
af9b8b
+#if defined(AP_LOG_SYSLOG)
af9b8b
+        fprintf(stderr, " -D AP_LOG_SYSLOG\n");
af9b8b
+#elif defined(AP_LOG_EXEC)
af9b8b
         fprintf(stderr, " -D AP_LOG_EXEC=\"%s\"\n", AP_LOG_EXEC);
af9b8b
 #endif
af9b8b
 #ifdef AP_SAFE_PATH
af9b8b
@@ -591,6 +617,12 @@ int main(int argc, char *argv[])
af9b8b
 #endif /* AP_SUEXEC_UMASK */
af9b8b
 
af9b8b
     /* Be sure to close the log file so the CGI can't mess with it. */
af9b8b
+#ifdef AP_LOG_SYSLOG
af9b8b
+    if (log_open) {
af9b8b
+        closelog();
af9b8b
+        log_open = 0;
af9b8b
+    }
af9b8b
+#else
af9b8b
     if (log != NULL) {
af9b8b
 #if APR_HAVE_FCNTL_H
af9b8b
         /*
af9b8b
@@ -612,6 +644,7 @@ int main(int argc, char *argv[])
af9b8b
         log = NULL;
af9b8b
 #endif
af9b8b
     }
af9b8b
+#endif
af9b8b
 
af9b8b
     /*
af9b8b
      * Execute the command, replacing our image with its own.