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


PHP posix_getgrnam函数代码示例

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


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

示例1: testChangeGroup

 public function testChangeGroup()
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $this->markTestSkipped("chown tests don't work on Windows");
     }
     $userinfo = posix_getpwuid(posix_geteuid());
     $username = $userinfo['name'];
     //we may change the group only if we belong to it
     //so find a group that we are in
     $group = null;
     foreach (array('users', 'www-data', 'cdrom') as $groupname) {
         $grpinfo = posix_getgrnam($groupname);
         if ($grpinfo['gid'] == $userinfo['gid']) {
             //current group id, the file has that group anyway
             continue;
         }
         if (in_array($username, $grpinfo['members'])) {
             $group = $grpinfo;
             break;
         }
     }
     if ($group === null) {
         $this->markTestSkipped('found no group we can change ownership to');
     }
     $this->project->setUserProperty('targetuser', $username . '.' . $group['name']);
     $this->executeTarget(__FUNCTION__);
     $a = stat(PHING_TEST_BASE . '/etc/tasks/system/tmp/chowntestA');
     $b = stat(PHING_TEST_BASE . '/etc/tasks/system/tmp/chowntestB');
     $this->assertNotEquals($group['gid'], $a['gid'], 'chowntestA group should not have changed');
     $this->assertEquals($group['gid'], $b['gid'], 'chowntestB group should have changed');
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:31,代码来源:ChownTaskTest.php

示例2: preUp

 public function preUp()
 {
     $this->needed_group_name = 'codendiadm';
     $codendi_ugroup = posix_getgrnam($this->needed_group_name);
     $this->codendi_ugroup_id = $codendi_ugroup['gid'];
     $this->needed_access_right = '0755';
 }
开发者ID:pombredanne,项目名称:tuleap,代码行数:7,代码来源:201504171343_restore_FRS_owner_group.php

示例3: import

 public function import($id_)
 {
     Logger::debug('main', 'UserGroupDB::unix::import(' . $id_ . ')');
     $tab = posix_getgrnam($id_);
     if (is_array($tab)) {
         $id = '';
         $name = '';
         $description = '';
         $published = true;
         $members = null;
         if (isset($tab['name'])) {
             $id = $tab['name'];
             $name = $tab['name'];
         }
         if (isset($tab['members'])) {
             $members = $tab['members'];
         }
         $ug = new UsersGroup($id, $name, $description, $published);
         if (is_array($members)) {
             $ug->extras = array('member' => $members);
         }
         if ($this->isOK($ug)) {
             return $ug;
         }
     }
     return NULL;
 }
开发者ID:skdong,项目名称:nfs-ovd,代码行数:27,代码来源:unix.php

示例4: setUsersGid

 protected function setUsersGid()
 {
     // figure out the GID for "users" for tests
     $this->usersGid = 1000;
     // default
     if (posix_geteuid() === 0 && function_exists('posix_getgrnam')) {
         $info = posix_getgrnam('users');
         $this->usersGid = $info['gid'];
     }
 }
开发者ID:alex-fang,项目名称:Archive,代码行数:10,代码来源:v7_tar_test.php

示例5: __construct

 /**
  * 构造方法
  */
 public function __construct($setting)
 {
     $this->config = $setting['config'];
     $this->cronPath = $setting['cron_path'];
     if (isset($setting['group'])) {
         $groupinfo = posix_getpwnam($setting['group']);
         posix_setgid($groupinfo['gid']);
     }
     if (isset($setting['user'])) {
         $userinfo = posix_getgrnam($setting['user']);
         posix_setuid($groupinfo['uid']);
     }
     include __DIR__ . '/ParseCrontab.php';
     include __DIR__ . '/ParseInterval.php';
 }
开发者ID:Corzcode,项目名称:php-crontab,代码行数:18,代码来源:Cron.php

示例6: chgrp

 /**
  * Change the group of an array of files or directories.
  *
  * @param string|array|\Traversable $files     A filename, an array of files, or a \Traversable instance to change group
  * @param string                    $group     The group name
  * @param bool                      $recursive Whether change the group recursively or not
  *
  * @throws IOException When the change fail
  */
 public function chgrp($files, $group, $recursive = false)
 {
     foreach ($this->toIterator($files) as $file) {
         if ($recursive && is_dir($file) && !is_link($file)) {
             $this->chgrp(new \FilesystemIterator($file), $group, true);
         }
         if (is_link($file) && function_exists('lchgrp')) {
             if (true !== @lchgrp($file, $group) || defined('HHVM_VERSION') && !posix_getgrnam($group)) {
                 throw new IOException(sprintf('Failed to chgrp file "%s".', $file), 0, null, $file);
             }
         } else {
             if (true !== @chgrp($file, $group)) {
                 throw new IOException(sprintf('Failed to chgrp file "%s".', $file), 0, null, $file);
             }
         }
     }
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:26,代码来源:Filesystem.php

示例7: setUser

 public static function setUser($user, $group = null)
 {
     if (false === ($info = posix_getpwnam($user))) {
         throw new Exception("Does not exist operating system user: {$user}");
     }
     $uid = $info['uid'];
     if ($group) {
         if (false === ($info = posix_getgrnam($group))) {
             throw new Exception("Does not exist operating system group: {$group}");
         } else {
             $gid = $info['gid'];
         }
     } else {
         $gid = $info['gid'];
     }
     static::setUid($uid, $gid);
 }
开发者ID:panlatent,项目名称:aurora,代码行数:17,代码来源:Posix.php

示例8: process

 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasParameter('uecode.daemon')) {
         return;
     }
     $config = $container->getParameter('uecode.daemon');
     // merges each configured daemon with default configs
     // and makes sure the pid directory is writable
     $filesystem = new Filesystem();
     foreach ($config['daemons'] as $name => $cnf) {
         if (null == $cnf) {
             $cnf = array();
         }
         try {
             $pidDir = $cnf['appPidDir'];
             $filesystem->mkdir($pidDir, 0777);
         } catch (\Exception $e) {
             echo 'UecodeDaemonBundle exception: ', $e->getMessage(), "\n";
         }
         if (isset($cnf['appUser']) || isset($cnf['appGroup'])) {
             if (isset($cnf['appUser']) && function_exists('posix_getpwnam')) {
                 $user = posix_getpwnam($cnf['appUser']);
                 if ($user) {
                     $cnf['appRunAsUID'] = $user['uid'];
                 }
             }
             if (isset($cnf['appGroup']) && function_exists('posix_getgrnam')) {
                 $group = posix_getgrnam($cnf['appGroup']);
                 if ($group) {
                     $cnf['appRunAsGID'] = $group['gid'];
                 }
             }
             if (!isset($cnf['appRunAsGID'])) {
                 $user = posix_getpwuid($cnf['appRunAsUID']);
                 $cnf['appRunAsGID'] = $user['gid'];
             }
         }
         $cnf['logLocation'] = rtrim($cnf['logDir'], '/') . '/' . $cnf['appName'] . 'Daemon.log';
         $cnf['appPidLocation'] = rtrim($cnf['appPidDir'], '/') . '/' . $cnf['appName'] . '/' . $cnf['appName'] . '.pid';
         unset($cnf['logDir'], $cnf['appPidDir']);
         $container->setParameter($name . '.daemon.options', $cnf);
     }
 }
开发者ID:uecode,项目名称:daemon-bundle,代码行数:46,代码来源:InitPass.php

示例9: handle

 /**
  * Handle an event.
  *
  * @param \League\Event\EventInterface $event The triggering event
  *
  * @return void
  * @see \League\Event\ListenerInterface::handle()
  */
 public function handle(EventInterface $event)
 {
     try {
         // load the application server instance
         /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */
         $applicationServer = $this->getApplicationServer();
         // write a log message that the event has been invoked
         $applicationServer->getSystemLogger()->info($event->getName());
         // don't do anything under Windows
         if (FileSystem::getOsIdentifier() === 'WIN') {
             $applicationServer->getSystemLogger()->info('Don\'t switch UID to \'%s\' because OS is Windows');
             return;
         }
         // initialize the variable for user/group
         $uid = 0;
         $gid = 0;
         // throw an exception if the POSIX extension is not available
         if (extension_loaded('posix') === false) {
             throw new \Exception('Can\'t switch user, because POSIX extension is not available');
         }
         // print a message with the old UID/EUID
         $applicationServer->getSystemLogger()->info("Running as " . posix_getuid() . "/" . posix_geteuid());
         // extract the user and group name as variables
         extract(posix_getgrnam($applicationServer->getSystemConfiguration()->getGroup()));
         extract(posix_getpwnam($applicationServer->getSystemConfiguration()->getUser()));
         // switch the effective GID to the passed group
         if (posix_setegid($gid) === false) {
             $applicationServer->getSystemLogger()->error(sprintf('Can\'t switch GID to \'%s\'', $gid));
         }
         // print a message with the new GID/EGID
         $applicationServer->getSystemLogger()->info("Running as group" . posix_getgid() . "/" . posix_getegid());
         // switch the effective UID to the passed user
         if (posix_seteuid($uid) === false) {
             $applicationServer->getSystemLogger()->error(sprintf('Can\'t switch UID to \'%s\'', $uid));
         }
         // print a message with the new UID/EUID
         $applicationServer->getSystemLogger()->info("Running as user " . posix_getuid() . "/" . posix_geteuid());
     } catch (\Exception $e) {
         $applicationServer->getSystemLogger()->error($e->__toString());
     }
 }
开发者ID:jinchunguang,项目名称:appserver,代码行数:49,代码来源:SwitchUserListener.php

示例10: checksADGroup

function checksADGroup($groupname)
{
    $checked = true;
    $userinfo = @posix_getgrnam($groupname);
    if (!isset($userinfo["gid"])) {
        $checked = false;
    }
    if (!is_numeric($userinfo["gid"])) {
        $checked = false;
    }
    if ($userinfo["gid"] < 1) {
        $checked = false;
    }
    $tpl = new templates();
    if (!$checked) {
        $html = $tpl->_ENGINE_parse_body("<table style='border:0px'>\n\t\t<tr>\n\t\t\t<td width=1% style='border:0px;border-left:0px;border-bottom:0px;' valign='top'><img src='img/warning-panneau-24.png'></td>\n\t\t\t<td style='border:0px;border-left:0px;border-bottom:0px;' valign='top'><strong style='font-size:12px'>{this_group_is_not_retranslated_to_the_system}</td>\n\t\t</tr>\n\t\t</table>\n\t\t");
    } else {
        $html = $tpl->_ENGINE_parse_body(count($userinfo["members"]) . " {members}");
    }
    return $html;
}
开发者ID:BillTheBest,项目名称:1.6.x,代码行数:21,代码来源:dansguardian2.group.all.php

示例11: __construct

 /**
  * @param Bundle\ServerBundle\EventDispatcher $dispatcher
  * @param Bundle\ServerBundle\Socket\ServerSocket $server
  * @param array $options (optional)
  *
  * @throws \InvalidArgumentException When an unsupported option is provided
  * @throws \InvalidArgumentException If provided user does not exist
  * @throws \InvalidArgumentException If provided group does not exist
  * @throws \InvalidArgumentException If an invalid socket client class is provided
  * @throws \InvalidArgumentException If an invalid socket server class is provided
  * @throws \InvalidArgumentException If an invalid socket server client class is provided
  */
 public function __construct(EventDispatcher $dispatcher, ServerSocket $server, array $options = array())
 {
     $this->dispatcher = $dispatcher;
     $this->server = $server;
     $this->console = null;
     $this->isDaemon = false;
     $this->clients = array();
     $this->shutdown = false;
     // @see Resources/config/server.xml
     $this->options = array('pid_file' => null, 'user' => null, 'group' => null, 'umask' => null, 'environment' => 'dev', 'debug' => true, 'kernel_environment' => 'prod', 'kernel_debug' => false, 'address' => '*', 'port' => 1962, 'max_clients' => 100, 'max_requests_per_child' => 1000, 'document_root' => null, 'timeout' => 90, 'keepalive_timeout' => 15);
     // check option names
     if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
         throw new \InvalidArgumentException(sprintf('The Server does not support the following options: \'%s\'.', implode('\', \'', $diff)));
     }
     $this->options = array_merge($this->options, $options);
     // convert user name to user id
     if (null !== $this->options['user'] && !is_int($this->options['user'])) {
         $user = posix_getpwnam($this->options['user']);
         if (false === $user) {
             throw new \InvalidArgumentException(sprintf('User "%s" does not exist', $this->options['user']));
         }
         $this->options['user'] = $user['uid'];
     }
     // convert group name to group id
     if (null !== $this->options['group'] && !is_int($this->options['group'])) {
         $group = posix_getgrnam($this->options['group']);
         if (false === $group) {
             throw new \InvalidArgumentException(sprintf('Group "%s" does not exist', $this->options['group']));
         }
         $this->options['group'] = $group['gid'];
     }
     if (null !== $this->options['umask']) {
         umask($this->options['umask']);
     }
     declare (ticks=1);
     // pcntl signal handlers
     pcntl_signal(SIGHUP, array($this, 'signalHandler'));
     pcntl_signal(SIGINT, array($this, 'signalHandler'));
     pcntl_signal(SIGTERM, array($this, 'signalHandler'));
 }
开发者ID:avalanche123,项目名称:ServerBundle,代码行数:52,代码来源:Server.php

示例12: setUserAndGroup

 /**
  * Set unix user and group for current process.
  * @return void
  */
 public function setUserAndGroup()
 {
     // Get uid.
     $user_info = posix_getpwnam($this->user);
     if (!$user_info) {
         return self::log("Waring: User {$this->user} not exsits", true);
     }
     $uid = $user_info['uid'];
     // Get gid.
     if ($this->group) {
         $group_info = posix_getgrnam($this->group);
         if (!$group_info) {
             return self::log("Waring: Group {$this->group} not exsits", true);
         }
         $gid = $group_info['gid'];
     } else {
         $gid = $user_info['gid'];
     }
     // Set uid and gid.
     if ($uid != posix_getuid() || $gid != posix_getgid()) {
         if (!posix_setgid($gid) || !posix_initgroups($user_info['name'], $gid) || !posix_setuid($uid)) {
             self::log("Waring: change gid or uid fail.", true);
         }
     }
 }
开发者ID:TongJiankang,项目名称:Workerman,代码行数:29,代码来源:Worker.php

示例13: ___init_userGroup

 /**
  * Check and chdir to $_workDir
  *
  * @return   void
  */
 private function ___init_userGroup()
 {
     $this->_debug("-----> " . __CLASS__ . '::' . __FUNCTION__ . '()', 9);
     // Get current uid and gid
     $uid_cur = posix_getuid();
     $gid_cur = posix_getgid();
     // If not root, skip the rest of this procedure
     if ($uid_cur != 0) {
         $this->_log("Skipping the setUid/setGid part, because we are not root");
         return;
     }
     // Get desired uid/gid
     $r = posix_getpwnam($this->_user);
     if ($r === false) {
         throw new A2o_AppSrv_Exception("Unable to get uid for user: {$this->_user}");
     }
     $userData = $r;
     $r = posix_getgrnam($this->_group);
     if ($r === false) {
         throw new A2o_AppSrv_Exception("Unable to get gid for group: {$this->_group}");
     }
     $groupData = $r;
     $uid_desired = $userData['uid'];
     $gid_desired = $groupData['gid'];
     // Change effective uid/gid if required
     if ($gid_cur != $gid_desired) {
         $r = posix_setgid($gid_desired);
         if ($r === false) {
             throw new A2o_AppSrv_Exception("Unable to setgid: {$gid_cur} -> {$gid_desired}");
         }
         $this->_debug("Group (GID) changed to {$this->_group} ({$gid_desired})");
     }
     if ($uid_cur != $uid_desired) {
         $r = posix_setuid($uid_desired);
         if ($r === false) {
             throw new A2o_AppSrv_Exception("Unable to setuid: {$uid_cur} -> {$uid_desired}");
         }
         $this->_debug("User (UID) changed to {$this->_user} ({$uid_desired})");
     }
     $this->_debug("Setuid/setgid complete");
 }
开发者ID:bostjanskufca,项目名称:PHP-application-server,代码行数:46,代码来源:Master.php

示例14: posix_getgrnam

 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License along
 with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ***********************************************************/
/**
 * @file migratetest.php
 * @brief Test migration function
 *
 * @return 0 for success, 1 for failure.
 **/
/* User must be in group fossy! */
$GID = posix_getgrnam("fossy");
posix_setgid($GID['gid']);
$Group = `groups`;
if (!preg_match("/\\sfossy\\s/", $Group) && posix_getgid() != $GID['gid']) {
    print "FATAL: You must be in group 'fossy' to update the FOSSology database.\n";
    exit(1);
}
/* Initialize the program configuration variables */
$SysConf = array();
// fo system configuration variables
$PG_CONN = 0;
// Database connection
$Plugins = array();
/* defaults */
$Verbose = false;
$DatabaseName = "fossology";
开发者ID:pombredanne,项目名称:fossology-test,代码行数:31,代码来源:migratetest.php

示例15: testFork_CloneEmptyToSpecifiedPath

 public function testFork_CloneEmptyToSpecifiedPath()
 {
     if (posix_getgrnam('gitolite') == false) {
         echo "testFork_CloneEmptyToSpecifiedPath: Cannot test 'cause there is no 'gitolite' user on server (CI)";
     } else {
         $name = 'tulip';
         $new_ns = 'repos/new/repo/';
         $old_ns = 'repos/';
         $old_root_dir = $this->repoDir . '/' . $old_ns . $name . '.git';
         $new_root_dir = $this->repoDir . '/' . $new_ns . $name . '.git';
         mkdir($old_root_dir, 0770, true);
         exec('GIT_DIR=' . $old_root_dir . ' git init --bare --shared=group');
         exec('cd ' . $old_root_dir . ' && touch hooks/gitolite_hook.sh');
         $this->assertTrue($this->driver->fork($name, $old_ns, $new_ns));
         $this->assertRepoIsClonedWithHooks($new_root_dir);
         $this->assertWritableByGroup($new_root_dir, 'gitolite');
         $this->assertNameSpaceFileHasBeenInitialized($new_root_dir, $new_ns, 'gitolite');
     }
 }
开发者ID:blestab,项目名称:tuleap,代码行数:19,代码来源:Git_GitoliteDriverTest.php


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