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

The suEXEC wrapper will write log information

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

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

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