altarch-user / rpms / httpd

Forked from rpms/httpd 2 years ago
Clone

Blame SOURCES/httpd-2.4.4-r1337344+.patch

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

The suEXEC wrapper will write log information

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

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

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