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

PHP posix_setuid函数代码示例

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

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



在下文中一共展示了posix_setuid函数的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: 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


示例13: start

 /**
  * Causes this pseudo-thread to begin parallel execution.
  *
  * This method first checks of all the Shared Memory Segment. If okay, it
  * forks the child process, attaches signal handler and returns immediatly.
  * The status is set to running, and a PID is assigned. The result is that
  * two pseudo-threads are running concurrently: the current thread (which
  * returns from the call to the start() method) and the other thread (which
  * executes its run() method).
  * 
  * @throws ZendX_Console_Process_Exception When SHM segments can't be created
  * @throws ZendX_Console_Process_Exception When process forking fails
  * @return void
  */
 public function start()
 {
     if (!$this->_ipcIsOkay) {
         require_once 'ZendX/Console/Process/Exception.php';
         throw new ZendX_Console_Process_Exception('Unable to create SHM segments for process communications');
     }
     // @see http://www.php.net/manual/en/function.pcntl-fork.php#41150
     @ob_end_flush();
     pcntl_signal(SIGCHLD, SIG_IGN);
     $pid = @pcntl_fork();
     if ($pid === -1) {
         require_once 'ZendX/Console/Process/Exception.php';
         throw new ZendX_Console_Process_Exception('Forking process failed');
     } else {
         if ($pid === 0) {
             // This is the child
             $this->_isChild = true;
             // Sleep a second to avoid problems
             sleep(1);
             // Install the signal handler
             pcntl_signal(SIGUSR1, array($this, '_sigHandler'));
             // If requested, change process identity
             if ($this->_guid !== null) {
                 posix_setgid($this->_guid);
             }
             if ($this->_puid !== null) {
                 posix_setuid($this->_puid);
             }
             // Run the child
             try {
                 $this->_run();
             } catch (Exception $e) {
                 // We have to catch any exceptions and clean up the process,
                 // else we will have a memory leak.
             }
             // Destroy the child after _run() execution. Required to avoid
             // unuseful child processes after execution
             exit(0);
         } else {
             // Else this is the parent
             $this->_isChild = false;
             $this->_isRunning = true;
             $this->_pid = $pid;
         }
     }
 }
开发者ID:jkimdon,项目名称:cohomeals,代码行数:60,代码来源:Unix.php


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


示例15: 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


示例16: 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


示例17: 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


示例18: setOwner

 /**
  * set owner(user,group) of process
  *
  * @return
  */
 public function setOwner($name)
 {
     $set = false;
     if (empty($name)) {
         return true;
     }
     $user = posix_getpwnam($name);
     if ($user) {
         $uid = $user['uid'];
         $gid = $user['gid'];
         $set = posix_setuid($uid);
         posix_setgid($gid);
     }
     if (!$set) {
         $this->_log("cannot change owner ({$name})\n");
     }
     return $set;
 }
开发者ID:shaogx,项目名称:easyJob,代码行数:23,代码来源:Command.php


示例19: changeProcessToWebUser

 /**
  * Changes the current user to the web user
  *
  * @return boolean
  */
 private function changeProcessToWebUser()
 {
     $userInfo = posix_getpwnam($this->config->app->webUser);
     $uidWeb = $userInfo['uid'];
     $gidWeb = $userInfo['gid'];
     // If the current user is the web user then success
     $uid = posix_getuid();
     $gid = posix_getgid();
     if ($uid === $uidWeb && $gid === $gidWeb) {
         return true;
     }
     // If the user is not root then there is no chance to succeed.
     if ($uid !== 0) {
         throw new \Exception("Error: The process real group id could not be changed.");
     }
     // If the user is root then attempt to change to the web user and group
     if (posix_setgid($gidWeb) !== true) {
         throw new \Exception("Error: The process real group id could not be changed.");
     }
     if (posix_setuid($uidWeb) !== true) {
         throw new \Exception("Error: The process real user id could not be changed.");
     }
     $uid = posix_getuid();
     $gid = posix_getgid();
     if ($uid !== $uidWeb || $gid !== $gidWeb) {
         throw new \Exeption("Error: Somehow the user was not changed to the web user.");
     }
     return true;
 }
开发者ID:JanOschii,项目名称:webird,代码行数:34,代码来源:Task.php


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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP posix_strerror函数代码示例发布时间:2022-05-15
下一篇:
PHP posix_setsid函数代码示例发布时间: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