5

Calls to PHP's is_readable() function are returning false on a directory that is readable from the command prompt. I have changed permissions to most-permissible and still no luck.

ls -lad /remote/samba_share
drwxrwxr-x 13 me users 0 May 29 15:49 /remote/samba_share

ls -la /remote/samba_share
drwxr-xr-x  4 me users 0 May  8 14:19 /remote/samba_share/local_dir
drwxr-xr-x 16 me users 0 May 14 19:49 /remote/samba_share/second_drive
drwxrwxrwx 12 me users 0 May 30 09:42 /remote/samba_share/ext_raid

Running the following code...

if (is_readable('/remote/samba_share'              )){ echo "share ok\n";  } else { echo "share BAD\n";  }
if (is_readable('/remote/samba_share/local_dir'    )){ echo "local ok\n";  } else { echo "local BAD\n";  }
if (is_readable('/remote/samba_share/second_drive' )){ echo "second ok\n"; } else { echo "second BAD\n"; }
if (is_readable('/remote/samba_share/ext_raid'     )){ echo "raid ok\n";   } else { echo "raid BAD\n";   }

...results in...

share ok
local ok
second BAD
raid BAD

Any directory under the samba share that is not on the physical primary partition seems to fail.

Config details of machine where is_readable() is called:

php -v
PHP 5.3.11-pl0-gentoo (cli) (built: May  5 2012 16:48:35)

php.ini:
    safe_mode = Off
    safe_mode_gid = On # (tried either way, shouldn't matter)
    ;open_basedir =

/etc/fstab entry:
    //remote_machine/samba_share /remote/samba_share cifs iocharset=utf8,credentials=/blahblah/samba_credentials,uid=me,gid=users,file_mode=0777,dir_mode=0777,auto   0 0

eix samba
[I] net-fs/samba
     Installed versions:  3.5.15!t

Config details of remote machine:

eix samba
[I] net-fs/samba
     Installed versions:  3.5.15!t

/etc/samba/smb.conf:

    [samba_share]
       path = /samba_share/
       public = yes
       writable = yes
    ;  printable = yes
       browseable = yes
       create mask = 0777
       create mode = 0777
       directory mode = 0777

I have tried everything I can think of to get this working, and now I feel dumb. :-) I can provide kernel config too if that seems relevant to anyone. THANKS for any help!

hakre
  • 193,403
  • 52
  • 435
  • 836
moodboom
  • 6,225
  • 2
  • 41
  • 45
  • 'second_share', as in that's actually some OTHER mounted samba share, underneath the main samba share? – Marc B May 30 '12 at 14:56
  • No, it's a second drive mounted on the remote machine, located under the samba share directory. For some reason, every dir physically located on the primary partition on that machine works, but other locations mounted on different partitions don't. – moodboom May 30 '12 at 15:00
  • Marc B, I updated the question to clarify this better. – moodboom May 30 '12 at 15:31
  • I have a workaround for this for now. I can set up a samba share on the remote machine that directly shares the ext_raid mount point, and is_readable() returns true. At this point, this seems like a PHP bug to me. is_readable() does not seem to tolerate crossing partitions inside a samba share path. – moodboom May 30 '12 at 17:17
  • 2
    If anyone else is able to verify my conclusions here, I'll accept their answer and submit a PHP bug report. Thanks! – moodboom May 30 '12 at 18:57
  • Shouldn't `is_readable` only work on files, not direcotries? So BAD would be ok and ok would be BAD? – hakre May 30 '12 at 21:19
  • From [the PHP docs](http://php.net/manual/en/function.is-readable.php): _Returns TRUE if the file or directory specified by filename exists and is readable, FALSE otherwise._ In my case it's used by ampache to check for a valid path to song files. – moodboom May 30 '12 at 21:58

2 Answers2

1

is_readable() just wraps the access system call to determine the file permission, so it´s very likely not a php issue.

According to the samba configuration and file permissions a very likely reason could be SELINUX. PHP is probably running as different user (no matter if CLI wether apache mod), so it could be that selinux denies access for this user.

So check if selinux is enabled and disabled it or configure it appropriate.

Yogu
  • 9,165
  • 5
  • 37
  • 58
Sebastian Keßler
  • 1,043
  • 8
  • 8
  • Thanks Sebastian. I don't have SELINUX enabled. I'm running the PHP test from the command line, as the "me" user in the example, so it's not a different user in that case. I'll write up some C code and see what access() gives me... – moodboom May 31 '12 at 13:25
  • access seems to work fine. code: `cout << "access R_OK share: " << access("/remote/samba_share", R_OK) << endl; cout << "access R_OK local: " << access("/remote/samba_share/local_dir", R_OK) << endl; cout << "access R_OK second: " << access("/remote/samba_share/second_drive", R_OK) << endl; cout << "access R_OK raid: " << access("/remote/samba_share/ext_raid", R_OK) << endl;' result: `access R_OK share: 0` `access R_OK local: 0` `access R_OK second: 0` `access R_OK raid: 0` I guess I need to dig into the Zend Engine code for the access() call...? – moodboom May 31 '12 at 14:06
  • @sebastian: it's highly unlikely php would be running as a different user when in CLI mode - root perms are required to change between user ids. – Marc B May 31 '12 at 14:16
  • @moodboom: i really didn´t expected that. just had a look at the code (https://github.com/php/php-src/blob/master/ext/standard/filestat.c) and there is nothing special happening in php_stat() but the access call. I´m curious now, think a bug ticket would be a good choice now. – Sebastian Keßler May 31 '12 at 15:52
  • @SebastianKeßler I was hoping someone else could verify what I'm seeing first. There are so many potential variables. But I guess a bug ticket is the place to explore them, rather than here. Thanks! – moodboom May 31 '12 at 16:00
1

I didn't find a simple answer for this, so I created a new PHP bug ticket to track down the problem better. Thanks for all the input!

moodboom
  • 6,225
  • 2
  • 41
  • 45