I've taken you suggestion about adding an additional parameter to file_ex() to 
address the symlink situation. Attached is a patch that I believe should 
resolve the problem.

Ilia

On November 4, 2002 02:53 pm, Ilia A. wrote:
> On November 4, 2002 03:43 am, Andi Gutmans wrote:
> > At 02:41 PM 11/4/2002 -0500, Ilia A. wrote:
> > >On November 4, 2002 03:36 am, you wrote:
> > > > I'll check it out tomorrow. Your code is problematic in any case as
> > > > you're returning a pointer to the stack which is a no-no in C.
> > > > I'll see if there's a way to do what you need without adding this
> > > > virtual_link function. Can you revert it in the meantime?
> > >
> > >Quite correct, not sure why I missed that and the compiler did not catch
> > >that.
> > >I'll revert the patch momentarily.
> >
> > OK thanks. Will an extra argument to file_ex() telling it not to run
> > realpath() solve your problem? We need realpath() everywhere else but I
> > think it'll be OK for unlink() only.
>
> Actually we need it several other places, originally I've added this code
> due to a bug in symlink/link implementation. The following functions would
> need not to resolve symlinks:
> virtual_rename(), virtual_lstat(), virtual_rmdir(), virtual_unlink(),
> virtual_chown().
>
> Possibly others.
>
> The extra argument for file_ex would solve the problem, however given the
> fact this may be a common function, it may be a good idea to keep it
> seperate.
>
> Ilia
Index: TSRM/tsrm_virtual_cwd.h
===================================================================
RCS file: /repository/TSRM/tsrm_virtual_cwd.h,v
retrieving revision 1.23
diff -u -3 -p -r1.23 tsrm_virtual_cwd.h
--- TSRM/tsrm_virtual_cwd.h     4 Nov 2002 23:24:15 -0000       1.23
+++ TSRM/tsrm_virtual_cwd.h     4 Nov 2002 23:45:11 -0000
@@ -163,7 +163,7 @@ CWD_API int virtual_chmod(const char *fi
 CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_DC);
 #endif
 
-CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func 
verify_path);
+CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func 
+verify_path, int use_realpath);
 
 typedef struct _virtual_cwd_globals {
        cwd_state cwd;
Index: TSRM/tsrm_virtual_cwd.c
===================================================================
RCS file: /repository/TSRM/tsrm_virtual_cwd.c,v
retrieving revision 1.39
diff -u -3 -p -r1.39 tsrm_virtual_cwd.c
--- TSRM/tsrm_virtual_cwd.c     4 Nov 2002 23:24:15 -0000       1.39
+++ TSRM/tsrm_virtual_cwd.c     4 Nov 2002 23:45:12 -0000
@@ -284,7 +284,7 @@ CWD_API char *virtual_getcwd(char *buf, 
 
 /* Resolve path relatively to state and put the real path into state */
 /* returns 0 for ok, 1 for error */
-CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func 
verify_path)
+CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func 
+verify_path, int use_realpath)
 {
        int path_length = strlen(path);
        char *ptr, *path_copy;
@@ -304,7 +304,7 @@ CWD_API int virtual_file_ex(cwd_state *s
 
 #if !defined(TSRM_WIN32) && !defined(NETWARE)
        if (IS_ABSOLUTE_PATH(path, path_length)) {
-               if (realpath(path, resolved_path)) {
+               if (realpath(path, resolved_path) && use_realpath) {
                        path = resolved_path;
                        path_length = strlen(path);
                }
@@ -322,7 +322,7 @@ CWD_API int virtual_file_ex(cwd_state *s
                memcpy(ptr, path, path_length);
                ptr += path_length;
                *ptr = '\0';
-               if (realpath(tmp, resolved_path)) {
+               if (realpath(tmp, resolved_path) && use_realpath) {
                        path = resolved_path;
                        path_length = strlen(path);
                }
@@ -439,7 +439,7 @@ CWD_API int virtual_file_ex(cwd_state *s
 
 CWD_API int virtual_chdir(const char *path TSRMLS_DC)
 {
-       return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok)?-1:0;
+       return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok, 1)?-1:0;
 }
 
 CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path 
TSRMLS_DC) TSRMLS_DC)
@@ -480,7 +480,7 @@ CWD_API char *virtual_realpath(const cha
        int retval;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       retval = virtual_file_ex(&new_state, path, NULL);
+       retval = virtual_file_ex(&new_state, path, NULL, 1);
        
        if (!retval) {
                int len = 
new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length;
@@ -498,7 +498,7 @@ CWD_API int virtual_filepath_ex(const ch
        int retval;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       retval = virtual_file_ex(&new_state, path, verify_path);
+       retval = virtual_file_ex(&new_state, path, verify_path, 1);
 
        *filepath = new_state.cwd;
 
@@ -521,7 +521,7 @@ CWD_API FILE *virtual_fopen(const char *
        }
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, path, NULL);
+       virtual_file_ex(&new_state, path, NULL, 1);
 
        f = fopen(new_state.cwd, mode);
 
@@ -536,7 +536,7 @@ CWD_API int virtual_access(const char *p
        int ret;
        
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, pathname, NULL);
+       virtual_file_ex(&new_state, pathname, NULL, 1);
 
        ret = access(new_state.cwd, mode);
        
@@ -554,7 +554,7 @@ CWD_API int virtual_utime(const char *fi
        int ret;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, filename, NULL);
+       virtual_file_ex(&new_state, filename, NULL, 0);
 
        ret = utime(new_state.cwd, buf);
 
@@ -569,7 +569,7 @@ CWD_API int virtual_chmod(const char *fi
        int ret;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, filename, NULL);
+       virtual_file_ex(&new_state, filename, NULL, 1);
 
        ret = chmod(new_state.cwd, mode);
 
@@ -584,7 +584,7 @@ CWD_API int virtual_chown(const char *fi
        int ret;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, filename, NULL);
+       virtual_file_ex(&new_state, filename, NULL, 0);
 
        ret = chown(new_state.cwd, owner, group);
 
@@ -599,7 +599,7 @@ CWD_API int virtual_open(const char *pat
        int f;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, path, NULL);
+       virtual_file_ex(&new_state, path, NULL, 1);
 
        if (flags & O_CREAT) {
                mode_t mode;
@@ -623,7 +623,7 @@ CWD_API int virtual_creat(const char *pa
        int f;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, path, NULL);
+       virtual_file_ex(&new_state, path, NULL, 1);
 
        f = creat(new_state.cwd,  mode);
 
@@ -638,11 +638,11 @@ CWD_API int virtual_rename(char *oldname
        int retval;
 
        CWD_STATE_COPY(&old_state, &CWDG(cwd));
-       virtual_file_ex(&old_state, oldname, NULL);
+       virtual_file_ex(&old_state, oldname, NULL, 0);
        oldname = old_state.cwd;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, newname, NULL);
+       virtual_file_ex(&new_state, newname, NULL, 0);
        newname = new_state.cwd;
  
        retval = rename(oldname, newname);
@@ -660,7 +660,7 @@ CWD_API int virtual_stat(const char *pat
        int retval;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, path, NULL);
+       virtual_file_ex(&new_state, path, NULL, 1);
 
        retval = stat(new_state.cwd, buf);
 
@@ -674,7 +674,7 @@ CWD_API int virtual_stat(const char *pat
        int retval;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, path, NULL);
+       virtual_file_ex(&new_state, path, NULL, 1);
 
        retval = stat(new_state.cwd, (struct stat*)buf);
 
@@ -690,7 +690,7 @@ CWD_API int virtual_lstat(const char *pa
        int retval;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, path, NULL);
+       virtual_file_ex(&new_state, path, NULL, 0);
 
        retval = lstat(new_state.cwd, buf);
 
@@ -705,7 +705,7 @@ CWD_API int virtual_unlink(const char *p
        int retval;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, path, NULL);
+       virtual_file_ex(&new_state, path, NULL, 0);
 
        retval = unlink(new_state.cwd);
 
@@ -719,7 +719,7 @@ CWD_API int virtual_mkdir(const char *pa
        int retval;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, pathname, NULL);
+       virtual_file_ex(&new_state, pathname, NULL, 1);
 
 #ifdef TSRM_WIN32
        retval = mkdir(new_state.cwd);
@@ -736,7 +736,7 @@ CWD_API int virtual_rmdir(const char *pa
        int retval;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, pathname, NULL);
+       virtual_file_ex(&new_state, pathname, NULL, 0);
 
        retval = rmdir(new_state.cwd);
 
@@ -754,7 +754,7 @@ CWD_API DIR *virtual_opendir(const char 
        DIR *retval;
 
        CWD_STATE_COPY(&new_state, &CWDG(cwd));
-       virtual_file_ex(&new_state, pathname, NULL);
+       virtual_file_ex(&new_state, pathname, NULL, 1);
 
        retval = opendir(new_state.cwd);
 
Index: main/fopen_wrappers.c
===================================================================
RCS file: /repository/php4/main/fopen_wrappers.c,v
retrieving revision 1.151
diff -u -3 -p -r1.151 fopen_wrappers.c
--- main/fopen_wrappers.c       4 Oct 2002 22:16:16 -0000       1.151
+++ main/fopen_wrappers.c       4 Nov 2002 23:45:12 -0000
@@ -536,7 +536,7 @@ PHPAPI char *expand_filepath(const char 
        new_state.cwd = strdup(cwd);
        new_state.cwd_length = strlen(cwd);
 
-       if(virtual_file_ex(&new_state, filepath, NULL)) {
+       if(virtual_file_ex(&new_state, filepath, NULL, 1)) {
                free(new_state.cwd);
                return NULL;
        }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to