• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP posix_setgid函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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})");
     }
 }
开发者ID:ngyuki,项目名称:php-setuidgid,代码行数:25,代码来源:SetUidGid.php


示例2: onWorkerStart

 /**
  * 此事件在worker进程启动时发生。这里创建的对象可以在worker进程生命周期内使用。
  * 
  * @param ISwoole $sw
  * @param int $worker_id
  */
 function onWorkerStart($sw, $worker_id)
 {
     $this->ctx->pid = getmypid();
     $user = posix_getpwnam($this->ctx->cfgs['default']['owner']['user']);
     posix_setuid($user['uid']);
     posix_setgid($user['gid']);
     $this->worker_id = $worker_id;
 }
开发者ID:heesey,项目名称:LeePHP-Socket,代码行数:14,代码来源:AppServer.php


示例3: setUser

 /**
  * 设置进程运行账号
  * @param [type] $user [description]
  */
 public static function setUser($user)
 {
     $userInfo = posix_getpwnam($user);
     if (!$userInfo) {
         return;
     }
     posix_setgid($userInfo['gid']);
     posix_setuid($userInfo['uid']);
 }
开发者ID:hitzheng,项目名称:ares,代码行数:13,代码来源:proc.php


示例4: setUid

 public static function setUid($uid, $gid)
 {
     if (!posix_setgid($gid)) {
         // 必须先设置GID, 再设置UID
         throw new Exception("Unable to set GID: " . posix_strerror(posix_get_last_error()));
     }
     if (!posix_setuid($uid)) {
         throw new Exception("Unable to set UID: " . posix_strerror(posix_get_last_error()));
     }
 }
开发者ID:panlatent,项目名称:aurora,代码行数:10,代码来源:Posix.php


示例5: change_identity

/**
 * Change the identity to a non-priv user
 */
function change_identity($uid, $gid)
{
    if (!posix_setgid($gid)) {
        print "Unable to setgid to " . $gid . "!\n";
        exit;
    }
    if (!posix_setuid($uid)) {
        print "Unable to setuid to " . $uid . "!\n";
        exit;
    }
}
开发者ID:rsbauer,项目名称:KismetServerSimulator,代码行数:14,代码来源:kismetsim.php


示例6: changeUser

 /**
  * 改变进程的用户ID
  * @param $user
  */
 static function changeUser($user)
 {
     if (!function_exists('posix_getpwnam')) {
         trigger_error(__METHOD__ . ": require posix extension.");
         return;
     }
     $user = posix_getpwnam($user);
     if ($user) {
         posix_setuid($user['uid']);
         posix_setgid($user['gid']);
     }
 }
开发者ID:jasonshaw,项目名称:framework-1,代码行数:16,代码来源:Console.php


示例7: onStart

 function onStart($serv)
 {
     if (!defined('WEBROOT')) {
         define('WEBROOT', $this->config['server']['webroot']);
     }
     if (isset($this->config['server']['user'])) {
         $user = posix_getpwnam($this->config['server']['user']);
         if ($user) {
             posix_setuid($user['uid']);
             posix_setgid($user['gid']);
         }
     }
     $this->log(self::SOFTWARE . ". running. on {$this->server->host}:{$this->server->port}");
 }
开发者ID:jinguanio,项目名称:swoole_websocket,代码行数:14,代码来源:HttpServer.php


示例8: __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


示例9: dropPrivileges

 protected function dropPrivileges(array $server)
 {
     if (!array_key_exists('user', $server) and !array_key_exists('group', $server)) {
         // nothing to do
         return;
     }
     if (posix_getuid() != 0) {
         echo "\n[Warning] Can't change uid/gid because aip is not run by superuser\n";
         return;
     }
     if (isset($server['user'])) {
         posix_setuid(self::getUserId($server['user']));
     }
     if (isset($server['group'])) {
         posix_setgid(self::getGroupId($server['group']));
     }
 }
开发者ID:LookForwardPersistence,项目名称:appserver-in-php,代码行数:17,代码来源:Runner.php


示例10: run

 function run($work)
 {
     if (1 === posix_getppid()) {
         return;
     }
     if ($this->user) {
         if (!posix_setgid($this->user['gid']) || !posix_setuid($this->user['uid'])) {
             throw new \RuntimeException("Unable to switch to user '{$this->user['name']}'");
         }
     }
     Utility::fork(function () use($work) {
         if (-1 === posix_setsid()) {
             throw new \RuntimeException('Unable to set setsid()');
         }
         if (false === chdir('/')) {
             throw new \RuntimeException('Unable to chdir(\'/\')');
         }
         umask(0);
         Utility::fork($work);
     });
 }
开发者ID:JaredWilliams,项目名称:PHPGearmanToolkit,代码行数:21,代码来源:ProcessControl.php


示例11: changeUser

 /**
  * @return bool
  */
 private function changeUser()
 {
     $user = $this->container->getConfig()->get('command.user');
     // Bypass cache commands as we need the sudoer user to run the commands
     if (null !== $user && (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] !== 'flushall') && (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] !== 'redis:flushall') && (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] !== 'apc:flushall')) {
         $name = $user;
         $user = posix_getpwnam($user);
         posix_setgid($user['gid']);
         posix_setuid($user['uid']);
         if (posix_geteuid() !== (int) $user['uid']) {
             $output = new ConsoleOutput();
             $formatter = new FormatterHelper();
             $output->writeln('', true);
             $errorMessages = array('', ' [Error] ', ' Could not change user to ' . $name . ' ', '');
             $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
             $output->writeln($formattedBlock);
             $output->writeln('', true);
             return false;
         }
     }
     return true;
 }
开发者ID:sinergi,项目名称:core,代码行数:25,代码来源:CommandRuntime.php


示例12: posix_getgrnam

 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";
$UpdateLiceneseRef = false;
开发者ID:pombredanne,项目名称:fossology-test,代码行数:31,代码来源:migratetest.php


示例13: setProcessUser

 /**
  * 尝试设置运行当前进程的用户
  * @return void
  */
 protected static function setProcessUser($user_name)
 {
     if (empty($user_name) || posix_getuid() !== 0) {
         return;
     }
     $user_info = posix_getpwnam($user_name);
     if ($user_info['uid'] != posix_getuid() || $user_info['gid'] != posix_getgid()) {
         if (!posix_setgid($user_info['gid']) || !posix_setuid($user_info['uid'])) {
             self::log('Notice : Can not run woker as ' . $user_name . " , You shuld be root\n", true);
         }
     }
 }
开发者ID:hongbo819,项目名称:webChat,代码行数:16,代码来源:Worker.php


示例14: changeUser

 function changeUser()
 {
     $username = common_config('daemon', 'user');
     if ($username) {
         $user_info = posix_getpwnam($username);
         if (!$user_info) {
             common_log(LOG_WARNING, 'Ignoring unknown user for daemon: ' . $username);
         } else {
             common_log(LOG_INFO, "Setting user to " . $username);
             posix_setuid($user_info['uid']);
         }
     }
     $groupname = common_config('daemon', 'group');
     if ($groupname) {
         $group_info = posix_getgrnam($groupname);
         if (!$group_info) {
             common_log(LOG_WARNING, 'Ignoring unknown group for daemon: ' . $groupname);
         } else {
             common_log(LOG_INFO, "Setting group to " . $groupname);
             posix_setgid($group_info['gid']);
         }
     }
 }
开发者ID:himmelex,项目名称:NTW,代码行数:23,代码来源:daemon.php


示例15: changeUser

 /**
  * @throws Exception
  */
 private function changeUser()
 {
     $user = $this->getConfig()->getUser();
     if ($user) {
         $user = posix_getpwnam($user);
         if (posix_geteuid() !== (int) $user['uid']) {
             posix_setgid($user['gid']);
             posix_setuid($user['uid']);
             if (posix_geteuid() !== (int) $user['uid']) {
                 $message = "Unable to change user to {$user['uid']}";
                 if (null !== $this->logger) {
                     $this->logger->error($message);
                 }
                 throw new Exception($message);
             }
         }
     }
 }
开发者ID:ly827,项目名称:gearman,代码行数:21,代码来源:Application.php


示例16: changeIdentity

 /**
  * Method to change the identity of the daemon process and resources.
  *
  * @return  boolean  True if identity successfully changed
  *
  * @since   11.1
  * @see     posix_setuid()
  */
 protected function changeIdentity()
 {
     // Get the group and user ids to set for the daemon.
     $uid = (int) $this->config->get('application_uid', 0);
     $gid = (int) $this->config->get('application_gid', 0);
     // Get the application process id file path.
     $file = $this->config->get('application_pid_file');
     // Change the user id for the process id file if necessary.
     if ($uid && fileowner($file) != $uid && !@chown($file, $uid)) {
         JLog::add('Unable to change user ownership of the process id file.', JLog::ERROR);
         return false;
     }
     // Change the group id for the process id file if necessary.
     if ($gid && filegroup($file) != $gid && !@chgrp($file, $gid)) {
         JLog::add('Unable to change group ownership of the process id file.', JLog::ERROR);
         return false;
     }
     // Set the correct home directory for the process.
     if ($uid && ($info = posix_getpwuid($uid)) && is_dir($info['dir'])) {
         system('export HOME="' . $info['dir'] . '"');
     }
     // Change the user id for the process necessary.
     if ($uid && posix_getuid($file) != $uid && !@posix_setuid($uid)) {
         JLog::add('Unable to change user ownership of the proccess.', JLog::ERROR);
         return false;
     }
     // Change the group id for the process necessary.
     if ($gid && posix_getgid($file) != $gid && !@posix_setgid($gid)) {
         JLog::add('Unable to change group ownership of the proccess.', JLog::ERROR);
         return false;
     }
     // Get the user and group information based on uid and gid.
     $user = posix_getpwuid($uid);
     $group = posix_getgrgid($gid);
     JLog::add('Changed daemon identity to ' . $user['name'] . ':' . $group['name'], JLog::INFO);
     return true;
 }
开发者ID:raquelsa,项目名称:Joomla,代码行数:45,代码来源:daemon.php


示例17: run

 /**
  * Runs the server. Loads the listener using XPClass::forName()
  * so that the class is loaded within the thread's process space
  * and will be recompiled whenever the thread is restarted.
  *
  * @throws  lang.XPException in case initializing the server fails
  * @throws  lang.SystemException in case setuid fails
  */
 public function run()
 {
     try {
         with($class = XPClass::forName('peer.ftp.server.FtpProtocol'), $cl = ClassLoader::getDefault());
         // Add listener
         $this->server->setProtocol($proto = $class->newInstance($storage = Proxy::newProxyInstance($cl, array(XPClass::forName('peer.ftp.server.storage.Storage')), $this->storageHandler), Proxy::newProxyInstance($cl, array(XPClass::forName('security.auth.Authenticator')), $this->authenticatorHandler)));
         // Copy interceptors to connection listener
         $proto->interceptors = $this->interceptors;
         // Enable debugging
         if ($this->cat) {
             $proto->setTrace($this->cat);
             $this->server instanceof Traceable && $this->server->setTrace($this->cat);
         }
         // Try to start the server
         $this->server->init();
     } catch (Throwable $e) {
         $this->server->shutdown();
         throw $e;
     }
     // Check if we should run child processes
     // with another uid/pid
     if (isset($this->processGroup)) {
         $group = posix_getgrnam($this->processGroup);
         $this->cat && $this->cat->debugf('Setting group to: %s (GID: %d)', $group['name'], $group['uid']);
         if (!posix_setgid($group['gid'])) {
             throw new SystemException('Could not set GID');
         }
     }
     if (isset($this->processOwner)) {
         $user = posix_getpwnam($this->processOwner);
         $this->cat && $this->cat->debugf('Setting user to: %s (UID: %d)', $user['name'], $user['uid']);
         if (!posix_setuid($user['uid'])) {
             throw new SystemException('Could not set UID');
         }
     }
     $this->server->service();
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:45,代码来源:FtpThread.class.php


示例18: array

<?php

echo "*** Test substituting argument 1 with float values ***\n";
$variation_array = array('float 10.5' => 10.5, 'float -10.5' => -10.5, 'float 12.3456789000e10' => 123456789000.0, 'float -12.3456789000e10' => -123456789000.0, 'float .5' => 0.5);
foreach ($variation_array as $var) {
    var_dump(posix_setgid($var));
}
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:posix_setgid_variation4.php


示例19: prepareNode

/**
 * Function to prepare a node before starging it
 *
 * @param   Node    $n                  The Node
 * @param   Int     $id                 Node ID
 * @param   Int     $t                  Tenant ID
 * @param   Array   $nets               Array of networks
 * @return  int                         0 Means ok
 */
function prepareNode($n, $id, $t, $nets)
{
    $user = 'unl' . $t;
    // Get UID from username
    $cmd = 'id -u ' . $user . ' 2>&1';
    exec($cmd, $o, $rc);
    $uid = $o[0];
    // Creating TAP interfaces
    foreach ($n->getEthernets() as $interface_id => $interface) {
        $tap_name = 'vunl' . $t . '_' . $id . '_' . $interface_id;
        if (isset($nets[$interface->getNetworkId()]) && $nets[$interface->getNetworkId()]->isCloud()) {
            // Network is a Cloud
            $net_name = $nets[$interface->getNetworkId()]->getNType();
        } else {
            $net_name = 'vnet' . $t . '_' . $interface->getNetworkId();
        }
        // Remove interface
        $rc = delTap($tap_name);
        if ($rc !== 0) {
            // Failed to delete TAP interface
            return $rc;
        }
        // Add interface
        $rc = addTap($tap_name, $user);
        if ($rc !== 0) {
            // Failed to add TAP interface
            return $rc;
        }
        if ($interface->getNetworkId() !== 0) {
            // Connect interface to network
            $rc = connectInterface($net_name, $tap_name);
            if ($rc !== 0) {
                // Failed to connect interface to network
                return $rc;
            }
        }
    }
    // Preparing image
    // Dropping privileges
    posix_setsid();
    posix_setgid(32768);
    if ($n->getNType() == 'iol' && !posix_setuid($uid)) {
        error_log('ERROR: ' . $GLOBALS['messages'][80036]);
        return 80036;
    }
    if (!is_file($n->getRunningPath() . '/.prepared') && !is_file($n->getRunningPath() . '/.lock')) {
        // Node is not prepared/locked
        if (!is_dir($n->getRunningPath()) && !mkdir($n->getRunningPath(), 0775, True)) {
            // Cannot create running directory
            error_log('ERROR: ' . $GLOBALS['messages'][80037]);
            return 80037;
        }
        if ($n->getConfig() == 'Saved' && $n->getConfigData() != '') {
            // Node should use saved startup-config
            if (!dumpConfig($n->getConfigData(), $n->getRunningPath() . '/startup-config')) {
                // Cannot dump config to startup-config file
                error_log('WARNING: ' . $GLOBALS['messages'][80067]);
            }
        }
        switch ($n->getNType()) {
            default:
                // Invalid node_type
                error_log('ERROR: ' . $GLOBALS['messages'][80038]);
                return 80038;
            case 'iol':
                // Check license
                if (!is_file('/opt/unetlab/addons/iol/bin/iourc')) {
                    // IOL license not found
                    error_log('ERROR: ' . $GLOBALS['messages'][80039]);
                    return 80039;
                }
                if (!file_exists($n->getRunningPath() . '/iourc') && !symlink('/opt/unetlab/addons/iol/bin/iourc', $n->getRunningPath() . '/iourc')) {
                    // Cannot link IOL license
                    error_log('ERROR: ' . $GLOBALS['messages'][80040]);
                    return 80040;
                }
                break;
            case 'docker':
                if (!is_file('/usr/bin/docker')) {
                    // docker.io is not installed
                    error_log('ERROR: ' . $GLOBALS['messages'][80082]);
                    return 80082;
                }
                $cmd = 'docker inspect --format="{{ .State.Running }}" ' . $n->getUuid();
                exec($cmd, $o, $rc);
                if ($rc != 0) {
                    // Must create docker.io container
                    $cmd = 'docker create -ti --net=none --name=' . $n->getUuid() . ' -h ' . $n->getName() . ' ' . $n->getImage();
                    exec($cmd, $o, $rc);
                    if ($rc != 0) {
                        // Failed to create container
//.........这里部分代码省略.........
开发者ID:qyqx,项目名称:unetlab,代码行数:101,代码来源:cli.php


示例20: ___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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP posix_setsid函数代码示例发布时间:2022-05-15
下一篇:
PHP posix_seteuid函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap