Normally, suexec won't execute setuid or setgid CGIs. Add your "safe"
setuid/setgid CGIs to safe_suid_cgis[], recompile suexec, and you're off.

Author: John Morrissey <jwm@horde.net>
This patch is distributed under the same terms as Apache itself.


--- suexec.c.orig	Tue May 21 14:09:24 2002
+++ suexec.c	Tue May 21 14:23:31 2002
@@ -124,6 +124,12 @@
 extern char **environ;
 static FILE *log = NULL;
 
+char *safe_suid_cgis[] =
+{
+	"/usr/local/apache/cgi-bin/test",
+	NULL
+};
+
 char *safe_env_lst[] =
 {
     "AUTH_TYPE",
@@ -548,11 +554,30 @@
     }
 
     /*
-     * Error out if the file is setuid or setgid.
+     * Error out if the file is setuid/setgid and isn't in the "safe" list.
      */
     if ((prg_info.st_mode & S_ISUID) || (prg_info.st_mode & S_ISGID)) {
-	log_err("error: file is either setuid or setgid: (%s/%s)\n", cwd, cmd);
-	exit(119);
+	int i, found = 0;
+	char full_path[AP_MAXPATH] = {'\0'};
+
+	if ((strlen(cwd) + strlen("/") + strlen(cmd) + 1) > sizeof(full_path)) {
+	    log_err("error: path to setuid/setgid file %s/%s is too long to check in safe_suid_cgis list.\n", cwd, cmd);
+	    exit(119);
+	}
+
+	snprintf(full_path, sizeof(full_path), "%s/%s", cwd, cmd);
+
+	for (i = 0; safe_suid_cgis[i]; ++i) {
+	    if (strcmp(full_path, safe_suid_cgis[i]) == 0) {
+		found = 1;
+		break;
+	    }
+	}
+
+	if (found != 1) {
+	    log_err("error: file is either setuid or setgid and is not in safe_suid_cgis list: (%s/%s)\n", cwd, cmd);
+	    exit(119);
+	}
     }
 
     /*
