- //
- // Error suppression on is_readable() in case of an open_basedir or
- // safe_mode failure. All we care about is whether or not we can
- // read it at this point. If the PHP environment is going to panic
- // over trying to see if the file can be read in the first place,
- // that is not helpful to us here.
-
- // See random_bytes_dev_urandom.php
- require_once $RandomCompatDIR.'/random_bytes_dev_urandom.php';
+ $RandomCompatUrandom = true;
+ $RandomCompat_basedir = ini_get('open_basedir');
+
+ if (!empty($RandomCompat_basedir)) {
+ $RandomCompat_open_basedir = explode(
+ PATH_SEPARATOR,
+ strtolower($RandomCompat_basedir)
+ );
+ $RandomCompatUrandom = in_array(
+ '/dev',
+ $RandomCompat_open_basedir
+ );
+ $RandomCompat_open_basedir = null;
+ }
+
+ if (
+ !function_exists('random_bytes')
+ &&
+ $RandomCompatUrandom
+ &&
+ @is_readable('/dev/urandom')
+ ) {
+ // Error suppression on is_readable() in case of an open_basedir
+ // or safe_mode failure. All we care about is whether or not we
+ // can read it at this point. If the PHP environment is going to
+ // panic over trying to see if the file can be read in the first
+ // place, that is not helpful to us here.
+
+ // See random_bytes_dev_urandom.php
+ require_once $RandomCompatDIR.'/random_bytes_dev_urandom.php';
+ }
+ // Unset variables after use
+ $RandomCompat_basedir = null;
+ $RandomCompatUrandom = null;