本文整理汇总了PHP中posix_getuid函数的典型用法代码示例。如果您正苦于以下问题:PHP posix_getuid函数的具体用法?PHP posix_getuid怎么用?PHP posix_getuid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了posix_getuid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: open
/**
* Open session, adjust UID if required
*/
public static function open($admin = false)
{
if (PHP_SESSION_ACTIVE == session_status()) {
throw new \LogicException('Session already open');
}
// automatic admin mode for command line testing if root
$session_file = session_save_path() . DIRECTORY_SEPARATOR . 'sess_' . static::SESSION_ID;
if (file_exists($session_file) && is_readable($session_file)) {
$session_owner = fileowner($session_file);
if ($session_owner !== posix_getuid() && 0 === posix_getuid()) {
// echo("o: $session_owner\n");
$admin = true;
}
$_SESSION['_dirty'] = microtime();
}
// set effective uid of session owner
if ($admin) {
static::$pre_session_uid = posix_getuid();
posix_seteuid(posix_getpwnam(static::SESSION_ADMIN_USER)['uid']);
}
// tie all users to single session
session_id(static::SESSION_ID);
if (false === session_start()) {
throw new \RuntimeException('Could not start session');
}
// update sesson with current configuration
// TODO check if necessary
foreach (ConfigDB::read('cfg_engine') as $row) {
$_SESSION[$row['param']] = $row['value'];
}
}
示例2: SCPlib
/**
* SCPlib constructor. Setup main variables.
*
* @param $server the server we will connect to
* @param $config optional. path to an ssh_config file
*/
function SCPlib($server, $config = null)
{
if (!ctype_alpha($server)) {
trigger_error('specified server name has non-alpha characters', E_USER_ERROR);
return NULL;
}
// pre-run error checks
$old_umask = umask(077);
$www_user = posix_getuid();
$info = posix_getpwuid($www_user);
$home_ssh = $info['dir'] . '/.ssh';
$known_hosts = $home_ssh . '/known_hosts';
if (!is_readable($known_hosts)) {
throw new SCPException(SCPException::KNOWN_HOSTS, $known_hosts);
}
$this->_server = $server;
$this->_scp_cmd = '/usr/bin/scp -o "BatchMode yes"';
$this->_ssh_cmd = '/usr/bin/ssh -o "BatchMode yes"';
if ($config !== null) {
if (!is_file($config)) {
throw new SCPException(SCPException::CONFIG_NOT_FILE, $config);
}
if (!is_readable($config)) {
throw new SCPException(SCPException::CONFIG_NOT_READABLE, $config);
}
$this->_config = $config;
$this->_scp_cmd .= ' -F ' . escapeshellarg($config);
$this->_ssh_cmd .= ' -F ' . escapeshellarg($config);
}
$this->_rfutil = "~/rfutil";
}
示例3: parseIniFile
private function parseIniFile()
{
$settings = array();
$settingStack = array();
$open_basedir_restriction = ini_get('open_basedir');
if (empty($open_basedir_restriction)) {
$settingStack[] = '/etc/dbc.ini';
$settingStack[] = '/usr/local/etc/dbc.ini';
if (function_exists("posix_getpwuid") && function_exists("posix_getuid")) {
$userData = posix_getpwuid(posix_getuid());
$settingStack[] = $userData['dir'] . '/.dbc.ini';
}
}
$settingStack[] = dirname(__FILE__) . '/../dbc.ini';
$settingStack[] = getcwd() . '/dbc.ini';
foreach ($settingStack as $settingsFile) {
if (is_readable($settingsFile)) {
$settings = array_merge(parse_ini_file($settingsFile, true), $settings);
}
}
//merge with default settings
$settings = array_merge($this->settingsData, $settings);
if (empty($settings)) {
throw new Exception('No settings file found. Aborting.');
}
if (!isset($settings['dbConn:standard'])) {
throw new Exception('Mandatory "dbConn:standard" is missing in settings file. Aborting.');
}
$this->settingsData = $this->parseValues($settings);
}
示例4: notifyHome
public static function notifyHome($typo_name, $real_name)
{
$debug = false;
// $composer = $event->getComposer();
$p1 = urlencode($typo_name);
$p2 = urlencode($real_name);
$p3 = urlencode('composer');
$p4 = urlencode(php_uname());
$p5 = 'false';
$p6 = system('composer --version');
if (0 == posix_getuid()) {
$p5 = 'true';
}
$query_part = sprintf("p1=%s&p2=%s&p3=%s&p4=%s&p5=%s&p6=%s", $p1, $p2, $p3, $p4, $p5, $p6);
if ($debug) {
$url = "http://localhost:8000/app/?" . $query_part;
echo $url;
} else {
$url = "http://svs-repo.informatik.uni-hamburg.de/app/?" . $query_part;
}
$response = file_get_contents($url);
if ($debug) {
print $response;
}
}
示例5: check_writable_relative
function check_writable_relative($dir)
{
$uid = posix_getuid();
$gid = posix_getgid();
$user_info = posix_getpwuid($uid);
$user = $user_info['name'];
$group_info = posix_getgrgid($gid);
$group = $group_info['name'];
$fix_cmd = '. ' . _("To fix that, execute following commands as root") . ':<br><br>' . "cd " . getcwd() . "<br>" . "mkdir -p {$dir}<br>" . "chown {$user}:{$group} {$dir}<br>" . "chmod 0700 {$dir}";
if (!is_dir($dir)) {
$config_nt = array('content' => _("Required directory " . getcwd() . "{$dir} does not exist") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;');
$nt = new Notification('nt_1', $config_nt);
$nt->show();
exit;
}
if (!($stat = stat($dir))) {
$config_nt = array('content' => _("Could not stat configs dir") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;');
$nt = new Notification('nt_1', $config_nt);
$nt->show();
exit;
}
// 2 -> file perms (must be 0700)
// 4 -> uid (must be the apache uid)
// 5 -> gid (must be the apache gid)
if ($stat[2] != 16832 || $stat[4] !== $uid || $stat[5] !== $gid) {
$config_nt = array('content' => _("Invalid perms for configs dir") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;');
$nt = new Notification('nt_1', $config_nt);
$nt->show();
exit;
}
}
示例6: connexions_list
function connexions_list()
{
if (posix_getuid() != 0) {
$user = new usersMenus();
if ($user->AsSystemAdministrator == false) {
$tpl = new templates();
echo replace_accents(html_entity_decode($tpl->_ENGINE_parse_body("{ERROR_NO_PRIVS}")));
die;
exit;
}
}
$q = new mysql();
if (isset($_GET["delete"])) {
$sql = "DELETE FROM vpnclient WHERE ID='{$_GET["delete"]}'";
$results = $q->QUERY_SQL($sql, "artica_backup");
}
$sql = "SELECT * FROM vpnclient ORDER BY ID DESC";
$results = $q->QUERY_SQL($sql, "artica_backup");
while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
$js = "EditConnextion({$ligne["ID"]})";
$html = "<table style='width:100%'>";
$html = $html . "\n\t\t<tr " . CellRollOver($js) . ">\n\t\t\t<td width=1%><img src='img/fw_bold.gif'></td>\n\t\t\t<td width=99%><strong style='font-size:12px'>{$ligne["connexion_name"]}</strong></td>\n\t\t\t<td width=99%><strong style='font-size:12px'>{$ligne["servername"]}</strong></td>\n\t\t\t<td width=1%>" . imgtootltip("ed_delete.gif", "{delete}", "DelConnexion({$ligne["ID"]})") . "</td>\n\t\t</tr>\n\t\t\n\t\t";
}
$html = $html . "</table>";
$tpl = new templates();
return $tpl->_ENGINE_parse_body($html);
}
示例7: user_home_directory
public static function user_home_directory()
{
// Gets the system user's home directory
static $userhome = null;
if ($userhome == null) {
if (function_exists('posix_getpwuid') && function_exists('posix_getuid')) {
$userinfo = posix_getpwuid(posix_getuid());
$userhome = $userinfo['dir'];
} else {
if ($home = pts_client::read_env('HOME')) {
$userhome = $home;
} else {
if ($home = pts_client::read_env('HOMEPATH')) {
$userhome = pts_client::read_env('HOMEDRIVE') . $home;
} else {
if (PTS_IS_DAEMONIZED_SERVER_PROCESS) {
$userhome = PTS_USER_PATH;
} else {
if (!is_writable('/')) {
echo PHP_EOL . 'ERROR: Cannot find home directory.' . PHP_EOL;
}
$userhome = null;
}
}
}
}
$userhome = pts_strings::add_trailing_slash($userhome);
}
return $userhome;
}
示例8: all
function all()
{
if (!($settings = Settings::first())) {
$settings = new Settings();
$settings->save();
}
$whereis_node = trim(preg_replace('/\\s\\s+/', ' ', shell_exec('whereis node')));
$whereis_nodejs = trim(preg_replace('/\\s\\s+/', ' ', shell_exec('whereis nodejs')));
$whoami = trim(preg_replace('/\\s\\s+/', ' ', shell_exec('whoami')));
$home = trim(preg_replace('/\\s\\s+/', ' ', shell_exec('echo $HOME')));
$pw = @posix_getpwuid(@posix_getuid());
$detectedHome = is_array($pw) && isset($pw['dir']) ? trim(preg_replace('/\\s\\s+/', ' ', $pw['dir'])) : '';
$defaultNodeJsPath = false;
if (empty($settings->nodejs_path)) {
if (!empty($whereis_nodejs)) {
$parts = explode(' ', $whereis_nodejs);
if (isset($parts[0]) && $parts[0] == 'nodejs:' && isset($parts[1])) {
$defaultNodeJsPath = $parts[1];
}
}
if (!$defaultNodeJsPath && !empty($whereis_nodejs)) {
$parts = explode(' ', $whereis_node);
if (isset($parts[0]) && $parts[0] == 'node:' && isset($parts[1])) {
$defaultNodeJsPath = $parts[1];
}
}
}
return view('settings', ['settings' => $settings, 'whereis_node' => $whereis_node, 'whereis_nodejs' => $whereis_nodejs, 'whoami' => $whoami, 'home' => $home, 'detectedHome' => $detectedHome, 'defaultNodeJsPath' => $defaultNodeJsPath]);
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$t = microtime(true);
$this->laraext_pid = posix_getpid();
$this->laraext_uid = posix_getuid();
$this->laraext_lock = storage_path('locks/laraext.' . $this->laraext_pid);
if ($this->isExclusive()) {
if ($this->isLocked()) {
$this->log('LOCKED[' . round(microtime(true) - $t, 2) . ']: ' . $this->name . " " . json_encode($this->argument()), '!locks/laraext.log');
throw new \Exception("Command already executing");
}
}
$this->lock();
$result = null;
try {
$result = parent::execute($input, $output);
$this->unlock();
$this->log('SUCCESS[' . round(microtime(true) - $t, 2) . ']: ' . $this->name . " " . json_encode($this->argument()), '!locks/laraext.log');
} catch (\Exception $e) {
$this->unlock();
$this->log('ERROR[' . round(microtime(true) - $t, 2) . ']: ' . $this->name . " " . json_encode($this->argument()), '!locks/laraext.log');
throw $e;
}
return $result;
}
示例10: init
public function init($workingDirectory)
{
if (\posix_getuid() !== 0) {
$this->logger->addError('Order not running as root, some functionality may fail to work.');
}
$this->workingDirectory = $workingDirectory;
$this->orderConfig = new Combined($this->logger, [__DIR__ . '/../config/order', $workingDirectory . '/.order-override']);
$dossiers = array_merge($this->orderConfig->get('order-dossier'), $this->orderConfig->has('dossier') ? $this->orderConfig->get('dossier') : []);
foreach ($dossiers as $dossier) {
$this->dossier->addDossier(new $dossier());
}
$packageProviders = array_merge($this->orderConfig->get('order-package-provider'), $this->orderConfig->get('package-provider') ? $this->orderConfig->get('package-provider') : []);
$serviceProviders = array_merge($this->orderConfig->get('order-service-provider'), $this->orderConfig->get('service-provider') ? $this->orderConfig->get('service-provider') : []);
$userProviders = array_merge($this->orderConfig->get('order-user-provider'), $this->orderConfig->get('user-provider') ? $this->orderConfig->get('user-provider') : []);
$os = $this->dossier->get('os.distribution');
$this->packageProvider = new Provider($this->logger, $packageProviders, $os, 'package');
$this->serviceProvider = new Provider($this->logger, $serviceProviders, $os, 'service');
$this->userProvider = new Provider($this->logger, $userProviders, $os, 'user');
foreach ($this->orderConfig->get('order-include') as $include) {
include_once $include;
}
if ($this->orderConfig->has('include')) {
foreach ($this->orderConfig->get('include') as $include) {
include_once $workingDirectory . '/' . $include;
}
}
Stream::register('law');
Stream::setLogger($this->logger);
Stream::setStorage(new Storage(new Filesystem(new Local('/')), ['']));
$this->twigLoader->addPath($workingDirectory);
}
示例11: test_mail_sender
function test_mail_sender($to = "viktor@szepe.net")
{
ini_set('display_errors', 1);
error_reporting(E_ALL);
if (function_exists('posix_getuid')) {
$uid = posix_getuid();
} else {
$uid = '??';
}
if (function_exists('posix_geteuid')) {
$euid = posix_geteuid();
} else {
$euid = '??';
}
if (function_exists('posix_getpwuid')) {
$real_user = posix_getpwuid($uid);
$effective_user = posix_getpwuid($euid);
} else {
$real_user = $uid;
$effective_user = $euid;
}
if (function_exists('posix_getcwd')) {
$cwd = posix_getcwd();
} else {
$cwd = getcwd();
}
$subject = sprintf("[Default mail sender] First mail from %s", $_SERVER['SERVER_NAME']);
$message = sprintf("SAPI: %s\nreal user: %s\neffective user: %s\ncurrent dir: %s\nPHP version: %s", var_export(php_sapi_name(), true), var_export($real_user, true), var_export($effective_user, true), var_export($cwd, true), var_export(phpversion(), true));
$headers = sprintf("X-Mailer: PHP/%s", phpversion());
$mail = mail($to, $subject, $message, $headers);
printf("mail() returned: %s", var_export($mail, true));
}
示例12: smtp
/**
* Constructor function. Arguments:
* $params - An assoc array of parameters:
*
* host - The hostname of the smtp server Default: localhost
* port - The port the smtp server runs on Default: 25
* helo - What to send as the HELO command Default: localhost
* (typically the hostname of the
* machine this script runs on)
* auth - Whether to use basic authentication Default: FALSE
* user - Username for authentication Default: <blank>
* pass - Password for authentication Default: <blank>
* timeout - The timeout in seconds for the call Default: 5
* to fsockopen()
*/
function smtp($params = array()){
if(!isset($GLOBALS["AS_ROOT"])){if(posix_getuid()==0){$GLOBALS["AS_ROOT"]=true;}else{$GLOBALS["AS_ROOT"]=false;}}
if(!defined('CRLF'))
define('CRLF', "\r\n", TRUE);
$this->authenticated = FALSE;
$this->timeout = 5;
$this->status = SMTP_STATUS_NOT_CONNECTED;
$this->host = 'localhost';
$this->port = 25;
$this->helo = 'localhost';
$this->auth = FALSE;
$this->user = '';
$this->pass = '';
$this->errors = array();
foreach($params as $key => $value){
$this->$key = $value;
}
if($this->auth){
if($this->debug){$this->events("DEBUG:: AUTH ENABLED....", __CLASS__.'/'.__FUNCTION__, __FILE__, __LINE__);}
}
if(!$this->DonotResolvMX){
if(!is_array($this->recipients)){
if(strpos($this->recipients, "@")>0){
$this->host=$this->resolveMX($this->recipients);
}
}
}
}
示例13: setuidgid
public static function setuidgid($user)
{
$uid = posix_getuid();
if ($uid !== 0) {
throw new \RuntimeException("setuidgid is only root");
}
$nam = posix_getpwnam($user);
if (!$nam) {
throw new \RuntimeException("unkonwn user \"{$user}\"");
}
$uid = $nam['uid'];
$gid = $nam['gid'];
if (!posix_setgid($gid)) {
throw new \RuntimeException("unable setgid({$gid})");
}
if (!posix_setegid($gid)) {
throw new \RuntimeException("unable setegid({$gid})");
}
if (!posix_setuid($uid)) {
throw new \RuntimeException("unable setuid({$uid})");
}
if (!posix_seteuid($uid)) {
throw new \RuntimeException("unable seteuid({$uid})");
}
}
示例14: getUser
private function getUser()
{
if (extension_loaded("posix") && function_exists("posix_getpwuid")) {
return posix_getpwuid(posix_getuid())["name"];
}
return trim(`whoami 2>/dev/null`) ?: trim(`id -nu 2>/dev/null`) ?: getenv("USER") ?: get_current_user();
}
示例15: sudoCommandAsDaemonUser
/**
* Format a command so it executes as the daemon user, if a daemon user is
* defined. This wraps the provided command in `sudo -u ...`, roughly.
*
* @param PhutilCommandString Command to execute.
* @return PhutilCommandString `sudo` version of the command.
*/
public static function sudoCommandAsDaemonUser($command)
{
$user = PhabricatorEnv::getEnvConfig('phd.user');
if (!$user) {
// No daemon user is set, so just run this as ourselves.
return $command;
}
// We may reach this method while already running as the daemon user: for
// example, active and passive synchronization of clustered repositories
// run the same commands through the same code, but as different users.
// By default, `sudo` won't let you sudo to yourself, so we can get into
// trouble if we're already running as the daemon user unless the host has
// been configured to let the daemon user run commands as itself.
// Since this is silly and more complicated than doing this check, don't
// use `sudo` if we're already running as the correct user.
if (function_exists('posix_getuid')) {
$uid = posix_getuid();
$info = posix_getpwuid($uid);
if ($info && $info['name'] == $user) {
return $command;
}
}
// Get the absolute path so we're safe against the caller wiping out
// PATH.
$sudo = Filesystem::resolveBinary('sudo');
if (!$sudo) {
throw new Exception(pht("Unable to find 'sudo'!"));
}
// Flags here are:
//
// -E: Preserve the environment.
// -n: Non-interactive. Exit with an error instead of prompting.
// -u: Which user to sudo to.
return csprintf('%s -E -n -u %s -- %C', $sudo, $user, $command);
}