summaryrefslogtreecommitdiff
path: root/main/safe_mode.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/safe_mode.c')
-rw-r--r--main/safe_mode.c58
1 files changed, 46 insertions, 12 deletions
diff --git a/main/safe_mode.c b/main/safe_mode.c
index 8b9886374..0c8fde9ce 100644
--- a/main/safe_mode.c
+++ b/main/safe_mode.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: safe_mode.c,v 1.62.2.1.2.2 2006/07/01 11:35:34 nlopess Exp $ */
+/* $Id: safe_mode.c,v 1.62.2.1.2.8 2007/01/12 12:11:18 bjori Exp $ */
#include "php.h"
@@ -55,6 +55,8 @@ PHPAPI int php_checkuid_ex(const char *filename, const char *fopen_mode, int mod
php_stream_wrapper *wrapper = NULL;
TSRMLS_FETCH();
+ path[0] = '\0';
+
if (!filename) {
return 0; /* path must be provided */
}
@@ -84,7 +86,7 @@ PHPAPI int php_checkuid_ex(const char *filename, const char *fopen_mode, int mod
* If that fails, passthrough and check directory...
*/
if (mode != CHECKUID_ALLOW_ONLY_DIR) {
- VCWD_REALPATH(filename, path);
+ expand_filepath(filename, path TSRMLS_CC);
ret = VCWD_STAT(path, &sb);
if (ret < 0) {
if (mode == CHECKUID_DISALLOW_FILE_NOT_EXISTS) {
@@ -197,7 +199,6 @@ PHPAPI int php_checkuid(const char *filename, const char *fopen_mode, int mode)
PHPAPI char *php_get_current_user()
{
- struct passwd *pwd;
struct stat *pstat;
TSRMLS_FETCH();
@@ -213,15 +214,48 @@ PHPAPI char *php_get_current_user()
if (!pstat) {
return "";
- }
+ } else {
+#ifdef PHP_WIN32
+ char name[256];
+ DWORD len = sizeof(name)-1;
- if ((pwd=getpwuid(pstat->st_uid))==NULL) {
- return "";
- }
- SG(request_info).current_user_length = strlen(pwd->pw_name);
- SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
-
- return SG(request_info).current_user;
+ if (!GetUserName(name, &len)) {
+ return "";
+ }
+ name[len] = '\0';
+ SG(request_info).current_user_length = len;
+ SG(request_info).current_user = estrndup(name, len);
+ return SG(request_info).current_user;
+#else
+ struct passwd *pwd;
+#if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
+ struct passwd _pw;
+ struct passwd *retpwptr = NULL;
+ int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+ char *pwbuf;
+
+ if (pwbuflen < 1) {
+ return "";
+ }
+ pwbuf = emalloc(pwbuflen);
+ if (getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr) != 0) {
+ efree(pwbuf);
+ return "";
+ }
+ pwd = &_pw;
+#else
+ if ((pwd=getpwuid(pstat->st_uid))==NULL) {
+ return "";
+ }
+#endif
+ SG(request_info).current_user_length = strlen(pwd->pw_name);
+ SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
+#if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
+ efree(pwbuf);
+#endif
+ return SG(request_info).current_user;
+#endif
+ }
}
/*