]> granicus.if.org Git - apache/blobdiff - support/suexec.c
More splitting as suggested by minfrin.
[apache] / support / suexec.c
index 1ef4e0928f5f00a00b454aee584c8de6fc9d4e0e..d25ca8430ecbb9bfebff0433f9406a98873db17c 100644 (file)
@@ -46,7 +46,9 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#if APR_HAVE_FCNTL_H
 #include <fcntl.h>
+#endif
 
 #ifdef HAVE_PWD_H
 #include <pwd.h>
@@ -129,7 +131,11 @@ static void err_output(int is_error, const char *fmt, va_list ap)
     struct tm *lt;
 
     if (!log) {
+#if defined(_LARGEFILE64_SOURCE) && HAVE_FOPEN64
+        if ((log = fopen64(AP_LOG_EXEC, "a")) == NULL) {
+#else
         if ((log = fopen(AP_LOG_EXEC, "a")) == NULL) {
+#endif
             fprintf(stderr, "suexec failure: could not open log file\n");
             perror("fopen");
             exit(1);
@@ -575,17 +581,27 @@ int main(int argc, char *argv[])
     umask(AP_SUEXEC_UMASK);
 #endif /* AP_SUEXEC_UMASK */
 
-    /*
-     * ask fcntl(2) to set the FD_CLOEXEC flag on the log file,
-     * so it'll be automagically closed if the exec() call succeeds.
-     */
+    /* Be sure to close the log file so the CGI can't mess with it. */
     if (log != NULL) {
+#if APR_HAVE_FCNTL_H
+        /*
+         * ask fcntl(2) to set the FD_CLOEXEC flag on the log file,
+         * so it'll be automagically closed if the exec() call succeeds.
+         */
         fflush(log);
-        setbuf(log,NULL);
+        setbuf(log, NULL);
         if ((fcntl(fileno(log), F_SETFD, FD_CLOEXEC) == -1)) {
             log_err("error: can't set close-on-exec flag");
             exit(122);
         }
+#else
+        /*
+         * In this case, exec() errors won't be logged because we have already
+         * dropped privileges and won't be able to reopen the log file.
+         */
+        fclose(log);
+        log = NULL;
+#endif
     }
 
     /*