summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/SAPI.c19
-rw-r--r--main/SAPI.h3
-rw-r--r--main/safe_mode.c14
-rw-r--r--sapi/aolserver/aolserver.c1
-rw-r--r--sapi/apache/mod_php4.c7
-rw-r--r--sapi/cgi/cgi_main.c2
-rw-r--r--sapi/isapi/php4isapi.c1
-rw-r--r--sapi/phttpd/phttpd.c1
-rw-r--r--sapi/roxen/roxen.c1
-rw-r--r--sapi/servlet/servlet.c1
-rw-r--r--sapi/thttpd/thttpd.c1
11 files changed, 40 insertions, 11 deletions
diff --git a/main/SAPI.c b/main/SAPI.c
index d1c684f1e1..e1b329daee 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -19,6 +19,7 @@
*/
#include <ctype.h>
+#include <sys/stat.h>
#include "php.h"
#include "SAPI.h"
@@ -383,3 +384,21 @@ SAPI_API int sapi_flush()
return FAILURE;
}
}
+
+SAPI_API int sapi_get_uid()
+{
+ SLS_FETCH();
+
+ if (sapi_module.get_uid) {
+ return sapi_module.get_uid(SLS_C);
+ } else {
+ struct stat statbuf;
+
+ if (!SG(request_info).path_translated || (stat(SG(request_info).path_translated, &statbuf)==-1)) {
+ return -1;
+ }
+
+ stat(SG(request_info).path_translated, &statbuf);
+ return statbuf.st_uid;
+ }
+}
diff --git a/main/SAPI.h b/main/SAPI.h
index 2b7053aea7..2b65a1a7a7 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -127,7 +127,7 @@ SAPI_API void sapi_unregister_post_reader(sapi_post_content_type_reader *post_co
SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(char *content_type_dup SLS_DC));
SAPI_API int sapi_flush();
-
+SAPI_API int sapi_get_uid();
struct _sapi_module_struct {
char *name;
@@ -140,6 +140,7 @@ struct _sapi_module_struct {
int (*ub_write)(const char *str, unsigned int str_length);
void (*flush)(void *server_context);
+ int (*get_uid)(SLS_D);
void (*sapi_error)(int type, const char *error_msg, ...);
diff --git a/main/safe_mode.c b/main/safe_mode.c
index 9704d856f9..fea75ed5c8 100644
--- a/main/safe_mode.c
+++ b/main/safe_mode.c
@@ -110,9 +110,6 @@ PHPAPI int php_checkuid(const char *fn, int mode) {
PHPAPI char *php_get_current_user()
{
-#if CGI_BINARY || USE_SAPI || FHTTPD
- struct stat statbuf;
-#endif
struct passwd *pwd;
int uid;
SLS_FETCH();
@@ -124,15 +121,12 @@ PHPAPI char *php_get_current_user()
/* FIXME: I need to have this somehow handled if
USE_SAPI is defined, because cgi will also be
interfaced in USE_SAPI */
-#if CGI_BINARY || USE_SAPI || FHTTPD
- if (!SG(request_info).path_translated || (stat(SG(request_info).path_translated,&statbuf)==-1)) {
+
+ uid = sapi_get_uid();
+
+ if (uid==-1) {
return empty_string;
}
- uid = statbuf.st_uid;
-#endif
-#if APACHE
- uid = ((request_rec *) SG(server_context))->finfo.st_uid;
-#endif
if ((pwd=getpwuid(uid))==NULL) {
return empty_string;
diff --git a/sapi/aolserver/aolserver.c b/sapi/aolserver/aolserver.c
index 7ba56d4e68..d1b5dc86d8 100644
--- a/sapi/aolserver/aolserver.c
+++ b/sapi/aolserver/aolserver.c
@@ -302,6 +302,7 @@ static sapi_module_struct sapi_module = {
php_ns_sapi_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
diff --git a/sapi/apache/mod_php4.c b/sapi/apache/mod_php4.c
index 5d05e01f52..edf848dd6a 100644
--- a/sapi/apache/mod_php4.c
+++ b/sapi/apache/mod_php4.c
@@ -300,6 +300,12 @@ static int php_apache_sapi_activate(SLS_D)
}
+static int php_apache_get_uid(SLS_D)
+{
+ return ((request_rec *) SG(server_context))->finfo.st_uid;
+}
+
+
static sapi_module_struct sapi_module = {
"Apache", /* name */
@@ -311,6 +317,7 @@ static sapi_module_struct sapi_module = {
sapi_apache_ub_write, /* unbuffered write */
sapi_apache_flush, /* flush */
+ php_apache_get_uid, /* get uid */
php_error, /* error handler */
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index c036b8c2f1..bf6138cd3c 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -176,6 +176,7 @@ static int sapi_cgi_deactivate(SLS_D)
}
+
static sapi_module_struct sapi_module = {
"CGI", /* name */
@@ -187,6 +188,7 @@ static sapi_module_struct sapi_module = {
sapi_cgibin_ub_write, /* unbuffered write */
sapi_cgibin_flush, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
diff --git a/sapi/isapi/php4isapi.c b/sapi/isapi/php4isapi.c
index 9ef51cbb1f..8c4ff5c695 100644
--- a/sapi/isapi/php4isapi.c
+++ b/sapi/isapi/php4isapi.c
@@ -350,6 +350,7 @@ static sapi_module_struct sapi_module = {
sapi_isapi_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
diff --git a/sapi/phttpd/phttpd.c b/sapi/phttpd/phttpd.c
index 7c98cd70a3..76184a7e7a 100644
--- a/sapi/phttpd/phttpd.c
+++ b/sapi/phttpd/phttpd.c
@@ -172,6 +172,7 @@ static sapi_module_struct sapi_module = {
php_phttpd_sapi_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
diff --git a/sapi/roxen/roxen.c b/sapi/roxen/roxen.c
index cff4324f9d..1d4f920e44 100644
--- a/sapi/roxen/roxen.c
+++ b/sapi/roxen/roxen.c
@@ -526,6 +526,7 @@ static sapi_module_struct sapi_module = {
php_roxen_sapi_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
diff --git a/sapi/servlet/servlet.c b/sapi/servlet/servlet.c
index 645528b86c..4ba10f9d13 100644
--- a/sapi/servlet/servlet.c
+++ b/sapi/servlet/servlet.c
@@ -221,6 +221,7 @@ static sapi_module_struct sapi_module = {
sapi_servlet_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c
index 2a39f189a4..4fab0c2abf 100644
--- a/sapi/thttpd/thttpd.c
+++ b/sapi/thttpd/thttpd.c
@@ -112,6 +112,7 @@ static sapi_module_struct sapi_module = {
sapi_thttpd_ub_write,
NULL,
+ NULL, /* get uid */
php_error,