PHP_FUNCTION(realpath)
{
zval **path;
- char resolved_path[MAXPATHLEN];
+ char resolved_path_buff[MAXPATHLEN];
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &path) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(path);
- if (php_realpath((*path)->value.str.val, resolved_path)) {
- RETURN_STRING(resolved_path, 1);
+
+ if (V_REALPATH((*path)->value.str.val, resolved_path_buff)) {
+ RETURN_STRING(resolved_path_buff, 1);
} else {
RETURN_FALSE;
}
if (php_check_open_basedir((*filename)->value.str.val))
RETURN_FALSE;
- ret = chown((*filename)->value.str.val, -1, gid);
+ ret = V_CHOWN((*filename)->value.str.val, -1, gid);
if (ret == -1) {
php_error(E_WARNING, "chgrp failed: %s", strerror(errno));
RETURN_FALSE;
if (php_check_open_basedir((*filename)->value.str.val))
RETURN_FALSE;
- ret = chown((*filename)->value.str.val, uid, -1);
+ ret = V_CHOWN((*filename)->value.str.val, uid, -1);
if (ret == -1) {
php_error(E_WARNING, "chown failed: %s", strerror(errno));
RETURN_FALSE;
if(PG(safe_mode))
imode &= 0777;
- ret = chmod((*filename)->value.str.val, imode);
+ ret = V_CHMOD((*filename)->value.str.val, imode);
if (ret == -1) {
php_error(E_WARNING, "chmod failed: %s", strerror(errno));
RETURN_FALSE;
fclose(file);
}
- ret = utime((*filename)->value.str.val, newtime);
+ ret = V_UTIME((*filename)->value.str.val, newtime);
if (newtime) efree(newtime);
if (ret == -1) {
php_error(E_WARNING, "utime failed: %s", strerror(errno));
}
/* Resolve the real path into resolved_name */
- if ((php_realpath(path, resolved_name) != NULL) && (php_realpath(local_open_basedir, resolved_basedir) != NULL)) {
+ if ((V_REALPATH(path, resolved_name) != NULL) && (V_REALPATH(local_open_basedir, resolved_basedir) != NULL)) {
/* Check the path */
#ifdef PHP_WIN32
if (strncasecmp(resolved_basedir, resolved_name, strlen(resolved_basedir)) == 0) {
#define V_CHDIR(path) virtual_chdir(path)
#define V_CHDIR_FILE(path) virtual_chdir_file(path)
#define V_GETWD(buf)
+#define V_REALPATH(path,realpath) virtual_realpath(path,realpath)
#define V_STAT(path, buff) virtual_stat(path, buff)
#ifdef PHP_WIN32
#define V_LSTAT(path, buff) virtual_stat(path, buff)
#define V_RMDIR(pathname) virtual_rmdir(pathname)
#define V_OPENDIR(pathname) virtual_opendir(pathname)
#define V_POPEN(command, type) virtual_popen(command, type)
-
+#if HAVE_UTIME
+#define V_UTIME(path,time) virtual_utime(path,time)
+#endif
+#define V_CHMOD(path,mode) virtual_chmod(path,mode)
+#ifndef PHP_WIN32
+#define V_CHOWN(path,owner,group) virtual_chown(path,owner,group)
+#endif
#else
#define V_GETCWD(buff, size) getcwd(buff,size)
#define V_RMDIR(pathname) rmdir(pathname)
#define V_OPENDIR(pathname) opendir(pathname)
#define V_POPEN(command, type) popen(command, type)
-
+#define V_REALPATH(path,realpath) realpath(path,realpath)
+#if HAVE_UTIME
+#define V_UTIME(path,time) utime(path,time)
+#endif
+#define V_CHMOD(path,mode) chmod(path,mode)
+#ifndef PHP_WIN32
+#define V_CHOWN(path,owner,group) chown(path,owner,group)
+#endif
#endif
#include "zend_constants.h"
#include "win95nt.h"
#endif
+#if HAVE_UTIME
+# ifdef PHP_WIN32
+# include <sys/utime.h>
+# else
+# include <utime.h>
+# endif
+#endif
+
+
#include "php_virtual_cwd.h"
#include "php_reentrancy.h" /* for php_strtok_r */
ret = 1;
} else {
CWD_STATE_FREE(old_state);
+ ret = (verify_path)? 0:1;
}
free(old_state);
return retval;
}
+CWD_API char *virtual_realpath(char *path, char *real_path)
+{
+ cwd_state new_state;
+ int retval;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ retval = virtual_file_ex(&new_state, path, NULL);
+
+ if(retval) {
+ int len = min(MAXPATHLEN-1,new_state.cwd_length);
+ memcpy(real_path, new_state.cwd, len);
+ real_path[len] = '\0';
+ return real_path;
+ }
+
+ return NULL;
+}
CWD_API int virtual_filepath(char *path, char **filepath)
{
return f;
}
+#if HAVE_UTIME
+CWD_API int virtual_utime(const char *filename, struct utimbuf *buf)
+{
+ cwd_state new_state;
+ int ret;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ virtual_file_ex(&new_state, filename, NULL);
+
+ ret = utime(new_state.cwd, buf);
+
+ CWD_STATE_FREE(&new_state);
+ return ret;
+}
+#endif
+
+CWD_API int virtual_chmod(const char *filename, mode_t mode)
+{
+ cwd_state new_state;
+ int ret;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ virtual_file_ex(&new_state, filename, NULL);
+
+ ret = chmod(new_state.cwd, mode);
+
+ CWD_STATE_FREE(&new_state);
+ return ret;
+}
+
+#ifndef PHP_WIN32
+CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group)
+{
+ cwd_state new_state;
+ int ret;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ virtual_file_ex(&new_state, filename, NULL);
+
+ ret = chown(new_state.cwd, owner, group);
+
+ CWD_STATE_FREE(&new_state);
+ return ret;
+}
+#endif
+
CWD_API int virtual_open(const char *path, int flags, ...)
{
cwd_state new_state;
CWD_API int virtual_chdir(char *path);
CWD_API int virtual_chdir_file(char *path);
CWD_API int virtual_filepath(char *path, char **filepath);
+CWD_API char *virtual_realpath(char *path, char *real_path);
CWD_API FILE *virtual_fopen(const char *path, const char *mode);
CWD_API int virtual_open(const char *path, int flags, ...);
CWD_API int virtual_creat(const char *path, mode_t mode);
CWD_API int virtual_rmdir(const char *pathname);
CWD_API DIR *virtual_opendir(const char *pathname);
CWD_API FILE *virtual_popen(const char *command, const char *type);
+#if HAVE_UTIME
+CWD_API int virtual_utime(const char *filename, struct utimbuf *buf);
+#endif
+CWD_API int virtual_chmod(const char *filename, mode_t mode);
+#ifndef PHP_WIN32
+CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group);
+#endif
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path);