--- src/main/http_request.c.orig Thu Jan 1 17:06:47 2004 +++ src/main/http_request.c Thu Jan 1 17:09:42 2004 @@ -176,7 +176,7 @@ { char *cp; char *path = r->filename; - char *end = &path[strlen(path)]; + char *end = NULL; char *last_cp = NULL; int rv; #if defined(HAVE_DRIVE_LETTERS) || defined(HAVE_UNC_PATHS) @@ -188,6 +188,9 @@ return OK; } + if (r->execfilename) path = r->execfilename; + end = path + strlen(path); + #ifdef HAVE_DRIVE_LETTERS /* If the directory is x:\, then we don't want to strip * the trailing slash since x: is not a valid directory. @@ -582,6 +585,7 @@ res = ap_parse_htaccess(&htaccess_conf, r, overrides_here, ap_pstrdup(r->pool, test_dirname), sconf->access_name); + if (r->execfilename) r->filename = r->execfilename; if (res) return res; @@ -592,6 +596,7 @@ r->per_dir_config = per_dir_defaults; } } + if (r->execfilename) r->filename = r->execfilename; } /* --- src/include/httpd.h.orig Thu Jan 1 21:05:30 2004 +++ src/include/httpd.h Thu Jan 1 21:05:53 2004 @@ -845,6 +845,8 @@ } ebcdic; #endif + char *execfilename; /* physical filename to exec */ + /* Things placed at the end of the record to avoid breaking binary * compatibility. It would be nice to remember to reorder the entire * record to improve 64bit alignment the next time we need to break --- src/support/suexec.c.orig Wed Mar 17 19:11:18 2004 +++ src/support/suexec.c Wed Mar 17 19:11:38 2004 @@ -88,6 +88,7 @@ #include #include #include +#include #include @@ -179,6 +180,11 @@ "UNIQUE_ID=", "USER_NAME=", "TZ=", + "FPEXE", + "FPUID", + "FPGID", + "FPFD", + "FPEXEDIR", NULL }; @@ -281,6 +287,7 @@ char *cmd; /* command to be executed */ char cwd[AP_MAXPATH]; /* current working directory */ char dwd[AP_MAXPATH]; /* docroot working directory */ + login_cap_t *lc; /* user resource limits */ struct passwd *pw; /* password entry holder */ struct group *gr; /* group entry holder */ struct stat dir_info; /* directory info holder */ @@ -483,6 +490,17 @@ exit(108); } + if ((lc = login_getclassbyname(pw->pw_class, pw)) == NULL) { + log_err("login_getclassbyname() failed\n"); + exit(248); + } + + if ((setusercontext(lc, pw, uid, LOGIN_SETRESOURCES)) != 0) { + log_err("setusercontext() failed\n"); + exit(249); + } + + /* * Change UID/GID here so that the following tests work over NFS. * @@ -502,6 +520,10 @@ exit(110); } +#ifdef FPEXE + if ((strcmp(cmd, FPEXE)) != NULL) { +#endif + /* * Get the current working directory, as well as the proper * document root (dependant upon whether or not it is a @@ -533,12 +555,12 @@ exit(113); } } - +/* if ((strncmp(cwd, dwd, strlen(dwd))) != 0) { log_err("error: command not in docroot (%s/%s)\n", cwd, cmd); exit(114); } - +*/ /* * Stat the cwd and verify it is a directory, or error out. */ @@ -583,7 +605,10 @@ * Error out if the target name/group is different from * the name/group of the cwd or the program. */ - if ((uid != dir_info.st_uid) || +#ifdef SYSTEM_CGI + if (strncmp(cwd, SYSTEM_CGI, strlen(SYSTEM_CGI))) { +#endif + if ((uid != dir_info.st_uid) || (gid != dir_info.st_gid) || (uid != prg_info.st_uid) || (gid != prg_info.st_gid)) { @@ -594,6 +619,9 @@ prg_info.st_uid, prg_info.st_gid); exit(120); } +#ifdef SYSTEM_CGI + } +#endif /* * Error out if the program is not executable for the user. * Otherwise, she won't find any error in the logs except for @@ -614,6 +642,49 @@ } umask(SUEXEC_UMASK); #endif /* SUEXEC_UMASK */ + +#ifdef FPEXE + } + else { + + /* The following taken from mod_frontpage.c to check permissions */ + + /* + * We can't stat the stub dir. Make sure the stub directory is not + * owned by root and not group/world writable + */ + if ((lstat(FPSTUBDIR, &dir_info) == -1 || + dir_info.st_uid || + (dir_info.st_mode & (S_IWGRP | S_IWOTH)) || + (!S_ISDIR(dir_info.st_mode)))) { + /* + * User recovery: set directory to be owned by by root with + * permissions r*x*-x*-x. + */ + log_err("Incorrect permissions on stub directory \"%-.1024s\"", + FPSTUBDIR); + exit (250); + } + + /* + * We can't stat the stub. Make sure the stub is not owned by root, + * set-uid, set-gid, and is not group/world writable or executable. + */ + if ((stat(cmd, &prg_info) == -1 || + prg_info.st_uid || + !(prg_info.st_mode & S_ISUID) || + (prg_info.st_mode & S_ISGID) || + (prg_info.st_mode & (S_IWGRP | S_IWOTH)) || + !(prg_info.st_mode & (S_IXGRP | S_IXOTH)))) { + /* + * User recovery: set stub to be owned by by root with permissions + * r*s*-x*-x. + */ + log_err("Incorrect permissions on stub \"%-.1024s\"", cmd); + exit (251); + } + } +#endif /* * Be sure to close the log file so the CGI can't --- src/support/suexec.h.orig Thu Jan 1 16:37:54 2004 +++ src/support/suexec.h Thu Jan 1 16:41:16 2004 @@ -71,7 +71,7 @@ * this program. */ #ifndef HTTPD_USER -#define HTTPD_USER "www" +#define HTTPD_USER "apache" #endif /* @@ -121,7 +121,7 @@ * debugging purposes. */ #ifndef LOG_EXEC -#define LOG_EXEC "/usr/local/apache/logs/cgi.log" /* Need me? */ +#define LOG_EXEC "/var/log/httpd/suexec_log" #endif /* @@ -130,7 +130,7 @@ * that can be used for suEXEC behavior. */ #ifndef DOC_ROOT -#define DOC_ROOT "/usr/local/apache/htdocs" +#define DOC_ROOT "/var/www/html" #endif /* @@ -139,6 +139,19 @@ */ #ifndef SAFE_PATH #define SAFE_PATH "/usr/local/bin:/usr/bin:/bin" +#endif + +#ifndef FPEXE +#define FPEXE "fpexe" +#endif +#ifndef FPSTUBDIR +#define FPSTUBDIR "/usr/local/frontpage/version5.0/apache-fp/_vti_bin" +#endif +#ifndef FPSTUB +#define FPSTUB FPSTUBDIR "/fpexe" +#endif +#ifndef SYSTEM_CGI +#define SYSTEM_CGI "/var/www/cgi-bin" #endif #endif /* _SUEXEC_H */ --- src/main/util.c.orig Thu Jan 1 17:10:47 2004 +++ src/main/util.c Thu Jan 1 17:11:44 2004 @@ -708,7 +708,7 @@ char *res; for (x = 0; (*line)[x]; x++) { - if (ap_isspace((*line)[x])) { + if (ap_isspace((*line)[x]) && ((*line)[x] & 0x80)==0) { pos = x; break; }