public function readyBuildDir() { if (!is_dir($this->getdbdDir . '/builds/') && !mkdir($this->getdbdDir . '/builds/')) { die("Critical: build directory '" . $this->getdbdDir . '/builds/\' does not exist.'); } if (!posix_access($this->getdbdDir . '/builds/', POSIX_W_OK)) { die("Critical: build directory '" . $this->getdbdDir . "/builds/' is not writable.\n"); } if ($this->buildDir === null) { $this->buildDir = $this->getdbdDir . '/builds/' . $this->buildID; } if (is_dir($this->buildDir) || mkdir($this->buildDir)) { // echo "Build directory is ". $this->buildDir. "\n"; } }
<?php $folder = $_SERVER['DOCUMENT_ROOT'] . 'pf-2016/data'; $file_name = 'file_test.txt'; $file = $folder . '' . $file_name; if (posix_access($folder, POSIX_R_OK | POSIX_W_OK) && $_POST['data']) { $handler = fopen($file, 'a+'); $decode = json_decode($_POST['data'], true); // var_dump($_POST['data']); $addr = $_SERVER['DOCUMENT_ROOT'] . 'pf-2016/data/' . $decode['name'] . '.json'; // echo $addr; $file = fopen($addr, 'a+'); fwrite($file, $_POST['data']); fclose($file); echo '<div id="send_mail">message envoyé</div>'; } else { $error = posix_get_last_error(); echo 'Erreur ' . $error . ' :' . posix_strerror($error) . '<br />'; echo '</br />Contact Root for rights mofo<br />'; }
<?php var_dump(posix_access()); var_dump(posix_access(array())); var_dump(posix_access('foo', array())); var_dump(posix_access(null)); var_dump(posix_access('./foobar')); ?> ===DONE===
<?php $file = 'some_file'; if (posix_access($file, POSIX_R_OK | POSIX_W_OK)) { echo 'The file is readable and writable!'; } else { $error = posix_get_last_error(); echo "Error {$error}: " . posix_strerror($error); }
<?php $file = '/etc/passwd' . chr(0) . 'asdf'; var_dump(posix_access($file)); var_dump(posix_mkfifo($file, 0644)); var_dump(posix_mknod($file, 0644));
<?php var_dump(posix_access(str_repeat('bogus path', 1042)));
<?php $filename = dirname(__FILE__) . '/foo.test'; var_dump(posix_access($filename, POSIX_F_OK)); $fp = fopen($filename, "w"); fwrite($fp, "foo"); fclose($fp); chmod($filename, 00); var_dump(posix_access($filename, POSIX_R_OK)); var_dump(posix_access($filename, POSIX_W_OK)); var_dump(posix_access($filename, POSIX_X_OK)); ?> ===DONE=== <?php $filename = dirname(__FILE__) . '/foo.test'; chmod($filename, 0700); unlink($filename);
public function isWriteable($dir, $type = "dir") { if ($this->getFilteredOption("USE_POSIX", $this->repository) == true && extension_loaded('posix')) { $real = AJXP_MetaStreamWrapper::getRealFSReference($dir); return posix_access($real, POSIX_W_OK); } //clearstatcache(); return is_writable($dir); }
/** * openCookie * * @access protected * @throws Exception */ protected function openCookie() { // ensure file is writable if (file_exists($this->cookie)) { if (posix_access($this->cookie, POSIX_W_OK) === false) { throw new Exception('File *' . $this->cookie . '* must be writable ' . 'for cookie storage.'); } } // ensure file directory is writable $dir = dirname($this->cookie); if (is_writable($dir) === false) { throw new Exception('Path *' . $dir . '* must be writable for cookie ' . 'storage.'); } // open file $resource = fopen($this->cookie, 'w'); fclose($resource); }
/** * Determine accessibility of a file * * @param string $file The name of the file to be tested. * @param int $mode A mask consisting of one or more of POSIX_F_OK, POSIX_R_OK, POSIX_W_OK and POSIX_X_OK. * * @return bool */ public function access($file, $mode = POSIX_F_OK) { return posix_access($file, $mode); }
#!/usr/bin/php <?php if (!posix_access(__FILE__, POSIX_X_OK)) { die("Access denied\n"); } chdir(realpath(dirname(__FILE__))); if (posix_isatty(STDIN)) { define('DEBUG', true); } else { define('DEBUG', false); } /** * SimpleMVC specifed directory default is '.' * If app folder is not in the same directory update it's path */ $smvc = realpath(dirname(__FILE__)); /** Set the full path to the docroot */ define('ROOT', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR); /** Make the application relative to the docroot, for symlink'd index.php */ if (!is_dir($smvc) and is_dir(ROOT . $smvc)) { $smvc = ROOT . $smvc; } /** Define the absolute paths for configured directories */ define('SMVC', realpath($smvc) . DIRECTORY_SEPARATOR); /** Unset non used variables */ unset($smvc); require SMVC . 'vendor/autoload.php'; use Helpers\Audit; function dbg($msg) { if (DEBUG) {
} define('WORKERMAN_LOG_DIR', $log_dir . '/'); // ==ipc-key== if (!($ipc_key = Man\Core\Lib\Config::get('workerman.ipc_key'))) { $ipc_key = fileinode(WORKERMAN_ROOT_DIR); } define('IPC_KEY', $ipc_key); // ==shm-size== if (!($shm_size = Man\Core\Lib\Config::get('workerman.shm_size'))) { $shm_size = 393216; } define('DEFAULT_SHM_SIZE', $shm_size); //检查pid对应的进程是否存在,不存在删除PID文件 if ($cmd != 'status' && is_file(WORKERMAN_PID_FILE)) { //检查权限 if (!posix_access(WORKERMAN_PID_FILE, POSIX_W_OK)) { if ($stat = stat(WORKERMAN_PID_FILE)) { if (($start_pwuid = posix_getpwuid($stat['uid'])) && ($current_pwuid = posix_getpwuid(posix_getuid()))) { exit("\n[31;40mWorkerman is started by user {$start_pwuid['name']}, {$current_pwuid['name']} can not {$cmd} Workerman, Permission denied[0m\n\n[31;40mWorkerman {$cmd} failed[0m\n\n"); } } exit("[31;40mCan not {$cmd} Workerman, Permission denied[0m\n"); } //检查pid进程是否存在 if ($pid = @file_get_contents(WORKERMAN_PID_FILE)) { if (false === posix_kill($pid, 0)) { if (!unlink(WORKERMAN_PID_FILE)) { exit("[31;40mCan not {$cmd} Workerman[0m\n\n"); } } }
/** * Tests whether it is possible for the current user to write to the * specified path. * * @param string $path * @return boolean */ public static function testWritable($path) { if (!isset(self::$_availableFunctions['posix_access'])) { self::$_availableFunctions['posix_access'] = function_exists('posix_access'); } /* I'll work out a non-POSIX implementation of this when/if it becomes necessary. */ if (self::$_availableFunctions['posix_access']) { // If file doesn't exist yet, test parent directory if (!file_exists($path)) { $path = dirname($path); } return posix_access($path, POSIX_W_OK); } return true; }
<?php var_dump(posix_access('/tmp', POSIX_W_OK)); ?> ===DONE===
function searchNotReadAbleFiles($dir) { $notReadableFiles = array(); $files = array_diff(scandir($dir), array('.', '..')); $folders = array(); foreach ($files as $file) { if (is_dir($dir . '/' . $file)) { $folders[] = $file; if (!@posix_access($dir . '/' . $file, POSIX_R_OK | POSIX_W_OK)) { $notReadableFiles[] = $dir . '/' . $file; } if (@is_dir($dir . '/' . $file) && $dir . '/' . $file != 'custom/veranstaltungsfotos') { $notReadableFiles = array_merge($notReadableFiles, searchNotReadAbleFiles($dir . '/' . $file)); } } } return $notReadableFiles; }
public function isWriteable($dir, $type = "dir") { if ($this->getFilteredOption("USE_POSIX", $this->repository->getId()) == true && extension_loaded('posix')) { $real = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $dir); return posix_access($real, POSIX_W_OK); } return is_writable($dir); }
function VS($x, $y) { var_dump($x === $y); if ($x !== $y) { echo "Failed: {$y}\n"; echo "Got: {$x}\n"; var_dump(debug_backtrace()); } } function VERIFY($x) { VS($x != false, true); } ////////////////////////////////////////////////////////////////////// VERIFY(posix_access(__DIR__ . "/ext_posix.php")); VERIFY(strlen(posix_ctermid())); VERIFY(strlen(posix_getcwd())); $ret = posix_getgrgid(posix_getgid()); VERIFY($ret != false); VERIFY(count((array) $ret) != 0); $bynam = posix_getgrnam($ret['name']); VS($ret, $bynam); $ret = posix_getgrnam("root"); VERIFY($ret != false); VERIFY(count((array) $ret) != 0); $bygid = posix_getgrgid($ret['gid']); VS($ret, $bygid); // $ret = posix_getgroups(); // VERIFY($ret != false); // VERIFY(count((array)$ret) != 0);
<?php $ekos_host = "localhost"; $ekos_db = "test"; $ekos_user = "******"; $ekos_pwd = ""; $cbd_host = "localhost"; $cbd_db = "central"; $cbd_user = "******"; $cbd_pwd = ""; $registerPHPFunctions = false; $admin_group = "root"; $user_name = $_SERVER['REMOTE_USER']; $user_info = posix_getpwnam($user_name); $user_group = posix_getgrgid($user_info['gid']); //astra linux maclabel - ignore this if (posix_access('/etc/security/msec_mac/' . $user_info['uid'], POSIX_R_OK)) { $user_maclabel = file_get_contents('/etc/security/msec_mac/' . $user_info['uid']); $user_maclabel = explode(':', $user_maclabel); $user_maxcategory = trim(array_pop($user_maclabel)); $user_maxlevel = array_pop($user_maclabel); $user_maclabel = '{' . $user_maxlevel . ',' . $user_maxcategory . '}'; } else { $user_maclabel = ""; }