当前位置: 首页>>代码示例>>PHP>>正文


PHP posix_getgroups函数代码示例

本文整理汇总了PHP中posix_getgroups函数的典型用法代码示例。如果您正苦于以下问题:PHP posix_getgroups函数的具体用法?PHP posix_getgroups怎么用?PHP posix_getgroups使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了posix_getgroups函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getGroups

 public function getGroups()
 {
     $gids = posix_getgroups();
     $ret = [];
     foreach ($gids as $gid) {
         $ret[] = new Group($gid);
     }
     return $ret;
 }
开发者ID:mariuslundgard,项目名称:php-core,代码行数:9,代码来源:Process.php

示例2: get

 public function get($name)
 {
     $data = posix_getpwnam($name);
     if ($data !== false) {
         $data['groups'] = array_map(function ($group) {
             $group = posix_getgrgid($group);
             return $group['name'];
         }, posix_getgroups());
     }
     return $data;
 }
开发者ID:EaterOfCode,项目名称:Order,代码行数:11,代码来源:Posix.php

示例3: check

 /**
  * @inheritdoc
  *
  * @return array
  */
 function check()
 {
     if ($this->path[0] == '/') {
         $filename = $this->path;
     } else {
         $filename = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $this->path);
     }
     if (file_exists($filename)) {
         $isWriteable = is_writeable($filename);
     } else {
         $isWriteable = is_writeable(dirname($filename));
     }
     if (!$isWriteable) {
         if (function_exists('posix_getgroups')) {
             $userID = posix_geteuid();
             $user = posix_getpwuid($userID);
             $currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename));
             $currentOwner = posix_getpwuid($currentOwnerID);
             $message = "User '{$user['name']}' needs to be able to write to this file:\n{$filename}\n\nThe file is currently owned by '{$currentOwner['name']}'.  ";
             if ($user['name'] == $currentOwner['name']) {
                 $message .= "We recommend that you make the file writeable.";
             } else {
                 $groups = posix_getgroups();
                 $groupList = array();
                 foreach ($groups as $group) {
                     $groupInfo = posix_getgrgid($group);
                     if (in_array($currentOwner['name'], $groupInfo['members'])) {
                         $groupList[] = $groupInfo['name'];
                     }
                 }
                 if ($groupList) {
                     $message .= "\tWe recommend that you make the file group-writeable and change the group to one of these groups:\n - " . implode("\n - ", $groupList) . "\n\nFor example:\nchmod g+w {$filename}\nchgrp " . $groupList[0] . " {$filename}";
                 } else {
                     $message .= "  There is no user-group that contains both the web-server user and the owner of this file.  Change the ownership of the file, create a new group, or temporarily make the file writeable by everyone during the install process.";
                 }
             }
         } else {
             $message = "The webserver user needs to be able to write to this file:\n{$filename}";
         }
         return array(EnvironmentCheck::ERROR, $message);
     }
     return array(EnvironmentCheck::OK, '');
 }
开发者ID:helpfulrobot,项目名称:silverstripe-environmentcheck,代码行数:48,代码来源:FileWriteableCheck.php

示例4: have_direct_access

 function have_direct_access()
 {
     if (!is_null($this->have_direct_access)) {
         return $this->have_direct_access;
     }
     $this->have_direct_access = false;
     if (!function_exists('getmyuid') || !function_exists('fileowner') || !function_exists('posix_getgroups') || !function_exists('filegroup')) {
         return $this->have_direct_access;
     }
     $temp_file_name = $this->config->root_path . '/temp-write-test-' . time();
     $temp_handle = @fopen($temp_file_name, 'w');
     if ($temp_handle) {
         if (getmyuid() == @fileowner($temp_file_name) || in_array(@filegroup($temp_file_name), posix_getgroups())) {
             $this->have_direct_access = true;
         }
         @fclose($temp_handle);
         @unlink($temp_file_name);
     }
     return $this->have_direct_access;
 }
开发者ID:pcbrsites,项目名称:leeflets,代码行数:20,代码来源:filesystem.php

示例5: array

             $gmembers = array();
             foreach ($ginfo['members'] as $index => $label) {
                 $gmembers[] = $label;
             }
             if (count($gmembers)) {
                 $glabel .= ' (' . implode(', ', $gmembers) . ')';
             }
         }
     }
     // display gathered information
     echo '<p>' . i18n::s('user/group of this script:') . ' ' . $ulabel . '/' . $glabel . "</p>\n";
 } else {
     echo '<p>' . i18n::s('Impossible to retrieve user/group of this script.') . "</p>\n";
 }
 // user/group of this process
 if (is_callable('posix_geteuid') && ($uid = posix_geteuid()) !== FALSE && is_callable('posix_getgroups') && ($gids = posix_getgroups()) !== FALSE) {
     // describe user
     $ulabel = $uid;
     if (is_callable('posix_getpwuid') && ($uinfo = posix_getpwuid($uid)) !== FALSE) {
         if (isset($uinfo['name'])) {
             $ulabel = $uinfo['name'] . '[' . $uid . ']';
         }
     }
     // describe groups
     $glabel = '';
     foreach ($gids as $gid) {
         // group name
         if (is_callable('posix_getgrgid') && ($ginfo = posix_getgrgid($gid)) !== FALSE && isset($ginfo['name'])) {
             $glabel .= $ginfo['name'] . '[' . $gid . ']';
         } else {
             $glabel .= $gid;
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:test.php

示例6: isInFossyGroup

 function isInFossyGroup()
 {
     $gid_array = posix_getgroups();
     foreach ($gid_array as $gid) {
         $gid_info = posix_getgrgid($gid);
         if ($gid_info['name'] === 'fossy') {
             return true;
         }
     }
     $uid = posix_getuid();
     $uid_info = posix_getpwuid($uid);
     return $uid_info['name'] !== 'root';
 }
开发者ID:rlintu,项目名称:fossology,代码行数:13,代码来源:TestPgDb.php

示例7: getMWScriptWithArgs

/**
 * Run a MediaWiki script based on the parameters (like --wiki) given to CLI.
 *
 * The first argument must be the relative (to MediaWiki) script file path.
 * If only a filename is given, it will be assumed to reside in /maintenance.
 * The second argument must be the --wiki parameter. This is to avoid
 * any "options with args" ambiguity (see Maintenance.php).
 *
 * When the actual script is run, $argv[0] (this file's name) will be not be kept.
 * Also, $argv[1] (the script path) will be changed to the script file name.
 * All other arguments will be preserved.
 *
 * @return string Absolute MediaWiki script path
 */
function getMWScriptWithArgs()
{
    global $argv;
    if (count($argv) < 2) {
        fwrite(STDERR, "This script can only be run from the command line.\n");
        exit(1);
    }
    # Security check -- don't allow scripts to run as privileged users
    $gids = posix_getgroups();
    foreach ($gids as $gid) {
        $info = posix_getgrgid($gid);
        if ($info && in_array($info['name'], array('sudo', 'wikidev', 'root'))) {
            fwrite(STDERR, "Cannot run a MediaWiki script as a user in the " . "group {$info['name']}\n");
            fwrite(STDERR, <<<EOT
Maintenance scripts should generally be run using sudo -u www-data which
is available to all wikidev users.  Running a maintenance script as a
privileged user risks compromise of the user account.

You should run this script as the www-data user:

 sudo -u www-data <command>

EOT
);
            exit(1);
        }
    }
    $relFile = $argv[1];
    // the script file to run
    # If no MW directory is given then assume this is a /maintenance script
    if (strpos($relFile, '/') === false) {
        $relFile = "maintenance/{$relFile}";
        // convenience
    }
    # Remove effects of this wrapper from $argv...
    array_shift($argv);
    // remove this file's name from args
    # Code stolen from wfBasename() in GlobalFunctions.php :)
    if (preg_match("#([^/\\\\]*?)[/\\\\]*\$#", $argv[0], $matches)) {
        $argv[0] = $matches[1];
        // make first arg the script file name
    }
    # For addwiki.php, the wiki DB doesn't yet exist, and for some
    # other maintenance scripts we don't care what wiki DB is used...
    $wikiless = array('maintenance/purgeList.php', 'extensions/WikimediaMaintenance/addWiki.php', 'extensions/WikimediaMaintenance/dumpInterwiki.php', 'extensions/WikimediaMaintenance/getJobQueueLengths.php', 'extensions/WikimediaMaintenance/rebuildInterwiki.php', 'extensions/WikimediaMaintenance/filebackend/setZoneAccess.php', 'maintenance/mctest.php', 'maintenance/mcc.php');
    # Check if a --wiki param was given...
    # Maintenance.php will treat $argv[1] as the wiki if it doesn't start '-'
    if (!isset($argv[1]) || !preg_match('/^([^-]|--wiki(=|$))/', $argv[1])) {
        if (in_array($relFile, $wikiless)) {
            # Assume aawiki as Maintenance.php does.
            $argv = array_merge(array($argv[0], "--wiki=aawiki"), array_slice($argv, 1));
        }
    }
    # MWScript.php should be in common/
    require_once __DIR__ . '/MWVersion.php';
    $file = getMediaWikiCli($relFile);
    if (!file_exists($file)) {
        fwrite(STDERR, "The MediaWiki script file \"{$file}\" does not exist.\n");
        exit(1);
    }
    return $file;
}
开发者ID:nomoa,项目名称:operations-mediawiki-config,代码行数:76,代码来源:MWScript.php

示例8: getgroups

 /**
  * Get groups
  *
  * @return array
  */
 public function getgroups()
 {
     return posix_getgroups();
 }
开发者ID:dantudor,项目名称:posix,代码行数:9,代码来源:Posix.php

示例9: is_writable_or_chmodable

function is_writable_or_chmodable($fn)
{
    $stat = stat($fn);
    if (!$stat) {
        return false;
    }
    $myuid = posix_getuid();
    $mygids = posix_getgroups();
    if ($myuid == 0 || $myuid == $stat['uid'] || in_array($stat['gid'], $mygids) && $stat['mode'] & 020 || $stat['mode'] & 02) {
        return true;
    }
    return false;
}
开发者ID:ziv0chou,项目名称:pcc,代码行数:13,代码来源:phpconfigcheck.php

示例10: checkGroups

 /**
  * Check if test on filesystem group ownership can be done in this environment
  * If so, return second group of webserver user
  *
  * @param string calling method name
  * @return mixed FALSE if test cannot be run, string name of the second group of webserver user
  */
 private function checkGroups($methodName)
 {
     if (TYPO3_OS == 'WIN') {
         $this->markTestSkipped($methodName . '() test not available on Windows.');
         return FALSE;
     }
     if (!function_exists('posix_getgroups')) {
         $this->markTestSkipped('Function posix_getgroups() not available, ' . $methodName . '() tests skipped');
     }
     $groups = posix_getgroups();
     if (count($groups) <= 1) {
         $this->markTestSkipped($methodName . '() test cannot be done when the web server user is only member of 1 group.');
         return FALSE;
     }
     $groupInfo = posix_getgrgid($groups[1]);
     return $groupInfo['name'];
 }
开发者ID:nicksergio,项目名称:TYPO3v4-Core,代码行数:24,代码来源:GeneralUtilityTest.php

示例11: _chmod

 /**
  * @author faw, phpBB Group and Kleeja team
  */
 function _chmod($filepath, $perm = 0644)
 {
     static $continue;
     if (empty($continue)) {
         if (!function_exists('fileowner') || !function_exists('filegroup')) {
             #if we cant get those data, no need to complete the check
             $continue['process'] = false;
         } else {
             #get the owner and group of the common.php file, why common.php? it's the master
             $common_php_owner = @fileowner(PATH . 'includes/common.php');
             $common_php_group = @filegroup(PATH . 'includes/common.php');
             // And the owner and the groups PHP is running under.
             $php_uid = function_exists('posix_getuid') ? @posix_getuid() : false;
             $php_gids = function_exists('posix_getgroups') ? @posix_getgroups() : false;
             // If we are unable to get owner/group, then do not try to set them by guessing
             if (!$php_uid || empty($php_gids) || !$common_php_owner || !$common_php_group) {
                 $continue['process'] = false;
             } else {
                 $continue = array('process' => true, 'common_owner' => $common_php_owner, 'common_group' => $common_php_group, 'php_uid' => $php_uid, 'php_gids' => $php_gids);
             }
         }
     }
     # From static, or not .. lets continue
     if ($continue['process']) {
         $file_uid = @fileowner($this->_fixpath($filepath));
         $file_gid = @filegroup($this->_fixpath($filepath));
         // Change owner
         if (@chown($this->_fixpath($filepath), $continue['common_owner'])) {
             clearstatcache();
             $file_uid = @fileowner($this->_fixpath($filepath));
         }
         // Change group
         if (@chgrp($this->_fixpath($filepath), $continue['common_group'])) {
             clearstatcache();
             $file_gid = @filegroup($this->_fixpath($filepath));
         }
         // If the file_uid/gid now match the one from common.php we can process further, else we are not able to change something
         if ($file_uid != $continue['common_owner'] || $file_gid != $continue['common_group']) {
             $continue['process'] = false;
         }
     }
     # Still able to process?
     if ($continue['process']) {
         if ($file_uid == $continue['php_uid']) {
             $php = 'owner';
         } else {
             if (in_array($file_gid, $continue['php_gids'])) {
                 $php = 'group';
             } else {
                 // Since we are setting the everyone bit anyway, no need to do expensive operations
                 $continue['process'] = false;
             }
         }
     }
     // We are not able to determine or change something
     if (!$continue['process']) {
         $php = 'other';
     }
     // Owner always has read/write permission
     $owner = 4 | 2;
     if (is_dir($this->_fixpath($filepath))) {
         $owner |= 1;
         // Only add execute bit to the permission if the dir needs to be readable
         if ($perm & 4) {
             $perm |= 1;
         }
     }
     switch ($php) {
         case 'owner':
             $result = @chmod($this->_fixpath($filepath), ($owner << 6) + (0 << 3) + (0 << 0));
             clearstatcache();
             if (is_readable($this->_fixpath($filepath)) && is_writable($this->_fixpath($filepath))) {
                 break;
             }
         case 'group':
             $result = @chmod($this->_fixpath($filepath), ($owner << 6) + ($perm << 3) + (0 << 0));
             clearstatcache();
             if ((!($perm & 4) || is_readable($this->_fixpath($filepath))) && (!($perm & 2) || is_writable($this->_fixpath($filepath)))) {
                 break;
             }
         case 'other':
             $result = @chmod($this->_fixpath($filepath), ($owner << 6) + ($perm << 3) + ($perm << 0));
             clearstatcache();
             if ((!($perm & 4) || is_readable($this->_fixpath($filepath))) && (!($perm & 2) || is_writable($this->_fixpath($filepath)))) {
                 break;
             }
         default:
             return false;
             break;
     }
     # if nothing works well use the handler...
     if (!$result) {
         $result = $this->f->_chmod($this->_fixpath($filepath), $perm);
     }
     return $result;
 }
开发者ID:Saleh7,项目名称:Kleeja,代码行数:99,代码来源:plugins.php

示例12: getopt

 * The name of the testrepo will be in the fossology.conf file in the test
 * configuration directory.
 *
 * This program can be called to drop the DB and clean up.
 *
 * @version "$Id$"
 *
 * Created on Sep 14, 2011 by Mark Donohoe
 */
require_once __DIR__ . '/../lib/libTestDB.php';
$Options = getopt('c:d:esh');
$usage = $argv[0] . ": [-h] -c path [-d name] [-s]\n" . "-c path:  The path to the fossology system configuration directory\n" . "-d name:  Drop the named data base.\n" . "-e:       create ONLY an empty db, sysconf dir and repository\n" . "-h:       This message (Usage)\n" . "-s:       Start the scheduler with the new sysconfig directory\n" . "Examples:\n" . "  Create a test DB: 'createTestDb.php' \n" . "  Drop the database fosstest1537938: 'createTestDb.php -d fosstest1537938'\n" . "  Create test DB, start scheduler: 'createTestDb.php -s'\n" . "  Create empty DB, sysconf and repo: 'createTestDb.php -e'\n";
$pathPrefix = '/srv/fossology';
$dbPrefix = 'fosstest';
// check if the user is in the fossy group
$gid_array = posix_getgroups();
$gflag = 0;
// 0: in the fossy group, 1: not in the fossy group
foreach ($gid_array as $gid) {
    $gid_info = posix_getgrgid($gid);
    if ($gid_info['name'] === 'fossy') {
        $gflag = 1;
        // the user is in fossy group
        break;
    }
}
$uid = posix_getuid();
$uid_info = posix_getpwuid($uid);
if ($uid_info['name'] === 'root') {
    $gflag = 1;
}
开发者ID:pombredanne,项目名称:fossology-test,代码行数:31,代码来源:createTestDB.php

示例13: checkGroups

 /**
  * Check if test on filesystem group ownership can be done in this environment
  * If so, return second group of webserver user
  *
  * @param string calling method name
  * @return mixed FALSE if test cannot be run, string name of the second group of webserver user
  */
 private function checkGroups($methodName)
 {
     if (TYPO3_OS == 'WIN') {
         $this->markTestSkipped($methodName . '() test not available on Windows.');
         return false;
     }
     if (!function_exists('posix_getgroups')) {
         $this->markTestSkipped('Function posix_getgroups() not available, ' . $methodName . '() tests skipped');
     }
     $groups = posix_getgroups();
     if (count($groups) <= 1) {
         $this->markTestSkipped($methodName . '() test cannot be done when the web server user is only member of 1 group.');
         return false;
     }
     $uname = strtolower(php_uname());
     $groupOffset = 1;
     if (strpos($uname, 'darwin') !== false) {
         // We are on OSX and it seems that the first group needs to be fetched since Mavericks
         $groupOffset = 0;
     }
     $groupInfo = posix_getgrgid($groups[$groupOffset]);
     return $groupInfo['name'];
 }
开发者ID:hlop,项目名称:TYPO3.CMS,代码行数:30,代码来源:GeneralUtilityTest.php

示例14: modeBitShift

 /**
  * Get the number of bits to shift to get the privileges of the user of the current process.
  * 
  * {@example
  *  $mode = ($file['mode'] >> $file->modeBitShift()) & 7;          // Privileges for the current user as bitset (rwx)
  *  $privs = substr($file['privs'], 7 - $file->modeBitShift(), 3); // Privileges for the current user as string
  * }}
  *
  * @param  int $flags  FS::% options
  * @return int
  * @throws Exception if posix extension is not available.
  */
 public function modeBitShift($user, $flags = 0)
 {
     if (!extension_loaded('posix')) {
         throw new Exception("Unable to determine the which part of the mode of '{$this->_path}' applies to the current user: Posix extension not avaible.");
     }
     return $this->getAttribute('uid', $flags) == posix_getuid() ? 6 : (in_array($this->getAttribute('gid', $flags), posix_getgroups()) ? 3 : 0);
 }
开发者ID:jasny,项目名称:Q,代码行数:19,代码来源:Node.php

示例15: posix_getegid

echo "gid={$gid}\n";
$egid = posix_getegid();
echo "egid={$egid}\n";
posix_setuid(1004);
$uid = posix_getuid();
echo "uid={$uid}\n";
posix_seteuid(1004);
$euid = posix_geteuid();
echo "euid={$euid}\n";
posix_setgid(1004);
$gid = posix_getgid();
echo "gid={$gid}\n";
posix_setegid(1004);
$egid = posix_getegid();
echo "egid={$egid}\n";
$groups = posix_getgroups();
echo "groups=\n";
print_r($groups);
$login = posix_getlogin();
echo "login={$login}\n";
$pgrp = posix_getpgrp();
echo "pgrp={$pgrp}\n";
$setsid = posix_setsid();
if ($setsid > 0) {
    echo "posix_setsid succeeded\n";
} else {
    echo "posix_setsid failed\n";
}
$getpgid = posix_getpgid($pid);
if ($getpgid > 0) {
    echo "posix_getpgid succeeded\n";
开发者ID:jenalgit,项目名称:roadsend-php,代码行数:31,代码来源:posix.php


注:本文中的posix_getgroups函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。