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

The suEXEC wrapper will write log information

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

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

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