*/
#include <ctype.h>
+#include <sys/stat.h>
#include "php.h"
#include "SAPI.h"
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;
+ }
+}
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;
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, ...);
PHPAPI char *php_get_current_user()
{
-#if CGI_BINARY || USE_SAPI || FHTTPD
- struct stat statbuf;
-#endif
struct passwd *pwd;
int uid;
SLS_FETCH();
/* 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;
php_ns_sapi_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
}
+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 */
sapi_apache_ub_write, /* unbuffered write */
sapi_apache_flush, /* flush */
+ php_apache_get_uid, /* get uid */
php_error, /* error handler */
}
+
static sapi_module_struct sapi_module = {
"CGI", /* name */
sapi_cgibin_ub_write, /* unbuffered write */
sapi_cgibin_flush, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
sapi_isapi_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
php_phttpd_sapi_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
php_roxen_sapi_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
sapi_servlet_ub_write, /* unbuffered write */
NULL, /* flush */
+ NULL, /* get uid */
php_error, /* error handler */
sapi_thttpd_ub_write,
NULL,
+ NULL, /* get uid */
php_error,