本文整理汇总了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');
}
示例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';
}
示例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;
}
示例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'];
}
}
示例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';
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
}
示例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());
}
}
示例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;
}
示例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'));
}
示例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);
}
}
}
示例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");
}
示例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";
示例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');
}
}