ID:               21310
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Feedback
 Bug Type:         *Directory/Filesystem functions
 Operating System: Solaris 8
 PHP Version:      4.3.0


Previous Comments:
------------------------------------------------------------------------

[2003-02-12 14:19:34] [EMAIL PROTECTED]

Try the patch below.  Solaris has issues with getcwd() needing read
perms on directories (instead of just execute).  This patch lets PHP
open files even if it cannot get the cwd, or resolve the realpath() of
a file.

Index: TSRM/tsrm_virtual_cwd.c
===================================================================
RCS file: /repository/TSRM/tsrm_virtual_cwd.c,v
retrieving revision 1.41
diff -u -b -u -r1.41 tsrm_virtual_cwd.c
--- TSRM/tsrm_virtual_cwd.c     6 Nov 2002 18:07:22 -0000       1.41
+++ TSRM/tsrm_virtual_cwd.c     12 Feb 2003 04:39:11 -0000
@@ -303,7 +303,7 @@
                return (0);
 
 #if !defined(TSRM_WIN32) && !defined(NETWARE)
-       if (IS_ABSOLUTE_PATH(path, path_length)) {
+       if (IS_ABSOLUTE_PATH(path, path_length) || (state->cwd_length < 1))
{
                if (use_realpath && realpath(path, resolved_path)) {
                        path = resolved_path;
                        path_length = strlen(path);
@@ -363,6 +363,7 @@
        }
 
 
+  if (state->cwd_length > 0 || IS_ABSOLUTE_PATH(path, path_length)) {
        ptr = tsrm_strtok_r(path_copy, TOKENIZER_STRING, &tok);
        while (ptr) {
                ptr_length = strlen(ptr);
@@ -416,6 +417,11 @@
                state->cwd[state->cwd_length+1] = '\0';
                state->cwd_length++;
        }
+  } else {
+       state->cwd = (char *) realloc(state->cwd, path_length+1);
+       memcpy(state->cwd, path, path_length+1);
+       state->cwd_length = path_length;
+  }
 
        if (verify_path && verify_path(state)) {
                CWD_STATE_FREE(state);
Index: main/main.c
===================================================================
RCS file: /repository/php4/main/main.c,v
retrieving revision 1.512.2.5
diff -u -b -u -r1.512.2.5 main.c
--- main/main.c 16 Dec 2002 15:44:06 -0000      1.512.2.5
+++ main/main.c 12 Feb 2003 04:39:12 -0000
@@ -1507,7 +1507,11 @@
 {
        zend_file_handle *prepend_file_p, *append_file_p;
        zend_file_handle prepend_file, append_file;
+#ifdef VIRTUAL_DIR
        char *old_cwd;
+#else
+       int old_cwd_fd;
+#endif
        char *old_primary_file_path = NULL;
        int retval = 0;
 
@@ -1515,9 +1519,11 @@
        if (php_handle_special_queries(TSRMLS_C)) {
                return 0;
        }
+#ifdef VIRTUAL_DIR
 #define OLD_CWD_SIZE 4096
        old_cwd = do_alloca(OLD_CWD_SIZE);
        old_cwd[0] = '\0';
+#endif
 
        zend_try {
 #ifdef PHP_WIN32
@@ -1528,7 +1534,11 @@
 
                if (primary_file->type == ZEND_HANDLE_FILENAME 
                                && primary_file->filename) {
+#ifdef VIRTUAL_DIR
                        VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
+#else
+                       old_cwd_fd = open(".", 0);
+#endif
                        VCWD_CHDIR_FILE(primary_file->filename);
                }
 
@@ -1578,10 +1588,14 @@
                
        } zend_end_try();
 
+#ifdef VIRTUAL_DIR
        if (old_cwd[0] != '\0') {
                VCWD_CHDIR(old_cwd);
        }
        free_alloca(old_cwd);
+#else
+       fchdir(old_cwd_fd);
+#endif
        return retval;
 }
 /* }}} */
Index: main/safe_mode.c
===================================================================
RCS file: /repository/php4/main/safe_mode.c,v
retrieving revision 1.51
diff -u -b -u -r1.51 safe_mode.c
--- main/safe_mode.c    6 Nov 2002 18:07:23 -0000       1.51
+++ main/safe_mode.c    12 Feb 2003 04:39:12 -0000
@@ -121,6 +121,8 @@
                        VCWD_REALPATH(filename, path);
                        *s = DEFAULT_SLASH;
                } else {
+                       path[0] = '.';
+                       path[1] = '\0';
                        VCWD_GETCWD(path, sizeof(path));
                }
        } /* end CHECKUID_ALLOW_ONLY_DIR */


------------------------------------------------------------------------

[2003-02-06 12:37:26] [EMAIL PROTECTED]

Have you checked ALL directories permissions (especially permission to
read for HTTP server) from / to directory with included file?

------------------------------------------------------------------------

[2003-02-06 12:06:31] [EMAIL PROTECTED]

I've also experienced the same problem on Solaris 8, w/ PHP 4.3.0, but
haven't been able to duplicate it on Linux.  The problem occurs when
running scripts through the web, but the problem doesn't occur when
running from the CLI.  For me it has nothing to do w/ permissions--same
problem even if the files/directories have full RWX permissions set.

For all of you dealing w/ this issue, a workaround I'm using so I don't
have to hard-code the full path in scripts is something like:

require(dirname($_SERVER['SCRIPT_FILENAME']).'/../lib/test.php');

That works both from web and CLI.

------------------------------------------------------------------------

[2003-02-04 16:52:55] [EMAIL PROTECTED]

I am able to duplicate this on Solaris 8, Apache 1.3.27, PHP 4.3.0.  I
traced it to getcwd() (aka VCWD_GETCWD) returning null, and
errno=EACCES in fopen_wrappers.c:expand_filepath().  The same code
works on 4.2.3.  However, this test was done in a non-standard
environment using Kerberos and a distributed file system, so this test
may not be representative.

For those of you experiencing this problem, check to see that there is
read perms on the afflicted directory and all ancestors.

------------------------------------------------------------------------

[2003-01-23 06:41:04] [EMAIL PROTECTED]

Not to jump in..

Theres a cron job i've been running on a few servers and
it's survived quite a few php upgrades.  I tested
php4.3.0 on one of those servers (upgrading cli from 4.2.3)
and now the cron job refuses to run.  Same issue as above.
It appears the cli is not honoring include path. (My path
has a . (dot), and relative paths from the directory of
the script do not work after the upgrade.  The application
running on the webserver works fine on 4.3.0.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/21310

-- 
Edit this bug report at http://bugs.php.net/?id=21310&edit=1

Reply via email to