diff -ruU 3 suphp-0.5.2/configure.ac suphp-0.5.2-rl/configure.ac --- suphp-0.5.2/configure.ac Tue Jul 13 11:43:40 2004 +++ suphp-0.5.2-rl/configure.ac Tue Dec 14 00:00:00 2004 @@ -205,6 +205,41 @@ AC_DEFINE_UNQUOTED(OPT_LOGFILE, "/var/log/httpd/suphp_log", [Defines path to logfile]) ]) +AC_ARG_WITH([rlimit-cpu], + AC_HELP_STRING([--with-rlimit-cpu=SECONDS], + [limit cpu time with setrlimit]), + [ + if test "$withval" -a ! "$withval" = "yes" ; then + AC_DEFINE_UNQUOTED(OPT_RLIMIT_CPU, $withval, [Defines max cpu time]) + fi + ]) + +AC_ARG_WITH([rlimit-as], + AC_HELP_STRING([--with-rlimit-as=BYTES], + [limit total available memory with setrlimit]), + [ + if test "$withval" -a ! "$withval" = "yes" ; then + AC_DEFINE_UNQUOTED(OPT_RLIMIT_AS, $withval, [Defines total available memory]) + fi + ]) + +AC_ARG_WITH([rlimit-nproc], + AC_HELP_STRING([--with-rlimit-nproc=COUNT], + [limit number of processes with setrlimit]), + [ + if test "$withval" -a ! "$withval" = "yes" ; then + AC_DEFINE_UNQUOTED(OPT_RLIMIT_NPROC, $withval, [Defines max number of processes]) + fi + ]) + +AC_ARG_WITH([rlimit-nofile], + AC_HELP_STRING([--with-rlimit-nofile=COUNT], + [limit number of open files with setrlimit]), + [ + if test "$withval" -a ! "$withval" = "yes" ; then + AC_DEFINE_UNQUOTED(OPT_RLIMIT_NOFILE, $withval, [Defines max number of open files]) + fi + ]) # Checks for libraries. diff -ruU 3 suphp-0.5.2/src/suphp.c suphp-0.5.2-rl/src/suphp.c --- suphp-0.5.2/src/suphp.c Tue Jul 13 11:43:41 2004 +++ suphp-0.5.2-rl/src/suphp.c Tue Dec 14 00:01:22 2004 @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include "suphp.h" @@ -148,6 +150,7 @@ struct group targetgroup; struct passwd *ptruser = NULL; struct group *ptrgroup = NULL; + struct rlimit reslim; #if (defined(OPT_USERGROUP_FORCE) || defined(OPT_USERGROUP_PARANOID)) char *envusername = NULL; @@ -546,12 +549,57 @@ #endif +#ifdef OPT_RLIMIT_CPU + //set ressource limits CPU + reslim.rlim_cur = OPT_RLIMIT_CPU; + reslim.rlim_max = OPT_RLIMIT_CPU; + if (setrlimit(RLIMIT_CPU, &reslim)) + { + suphp_log_error("Could not change cpu limit"); + error_sysmsg_exit(ERRCODE_UNKNOWN, "setrlimit(RLIMIT_CPU,...) failed", __FILE__, __LINE__); + } +#endif + +#ifdef OPT_RLIMIT_AS + //set ressource limits AS + reslim.rlim_cur = OPT_RLIMIT_AS; + reslim.rlim_max = OPT_RLIMIT_AS; + if (setrlimit(RLIMIT_AS, &reslim)) + { + suphp_log_error("Could not change as limit"); + error_sysmsg_exit(ERRCODE_UNKNOWN, "setrlimit(RLIMIT_AS,...) failed", __FILE__, __LINE__); + } +#endif + +#ifdef OPT_RLIMIT_NPROC + //set ressource limits NPROC + reslim.rlim_cur = OPT_RLIMIT_NPROC; + reslim.rlim_max = OPT_RLIMIT_NPROC; + if (setrlimit(RLIMIT_NPROC, &reslim)) + { + suphp_log_error("Could not change nproc limit"); + error_sysmsg_exit(ERRCODE_UNKNOWN, "setrlimit(RLIMIT_NPROC,...) failed", __FILE__, __LINE__); + } +#endif + +#ifdef OPT_RLIMIT_NOFILE + //set ressource limits NOFILE + reslim.rlim_cur = OPT_RLIMIT_NOFILE; + reslim.rlim_max = OPT_RLIMIT_NOFILE; + if (setrlimit(RLIMIT_NOFILE, &reslim)) + { + suphp_log_error("Could not change nofiles limit"); + error_sysmsg_exit(ERRCODE_UNKNOWN, "setrlimit(RLIMIT_NOFILE,...) failed", __FILE__, __LINE__); + } +#endif + + if (setuid(targetuser.pw_uid)) { suphp_log_error("Could not change UID to %d (%s)", targetuser.pw_uid, targetuser.pw_name); error_sysmsg_exit(ERRCODE_UNKNOWN, "setuid() failed", __FILE__, __LINE__); } - + // Execute the script with PHP exec_script(path_translated);