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


PHP posix_seteuid函数代码示例

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


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

function update_user($user)
{
    global $mcm;
    /* if we ran validate_login(),then the $user_id hasn't been set... */
    if (!isset($user['user_id'])) {
        $user['user_id'] = $mcm['user_id'];
    }
    $prefs = mcm_action('lookup_prefs', $user['user_id']);
    if (isset($user['forced_target'])) {
        $prefs['pref_target'] = $user['forced_target'];
    }
    echo "updating symlinks for user '{$user['user_name']}' on directory '{$prefs['pref_target']}'\n";
    if (!($prefs = validate_prefs($prefs))) {
        return;
    }
    posix_seteuid(0);
    posix_seteuid($prefs['pref_sysid']);
    echo "  - creating virtualfs based on accepted items: ";
    $params = array('user_id' => $user['user_id'], 'item_status' => 'accepted', 'item_type' => 'MUSIC');
    $accepted = mcm_action('lookup_itemlist', $params);
    $virtualfs = create_virtualfs($accepted, $prefs['pref_extensions']);
    echo count($accepted) . "\n";
    echo "  - verifying current symlinks... \n";
    $create = mcm_action('verify_symlinks_against_virtualfs', array('path' => $prefs['pref_target'], 'virtualfs' => $virtualfs));
    echo "  - creating new symlinks: " . count($create) . "\n";
    $mcmnew_dir = "{$prefs['pref_target']}/_mcmnew";
    if (!make_mcmnew_dir($mcmnew_dir)) {
        return;
    }
    chdir($mcmnew_dir);
    $prev_dirname = false;
    foreach ($create as $item) {
        $source = $item;
        $dirname = basename(dirname($item));
        $filename = basename($item);
        $dest = $dirname . "/" . $filename;
        if ($prefs['pref_codepage'] != $mcm['codepage']) {
            $dest = iconv(strtoupper($mcm['codepage']), strtoupper($prefs['pref_codepage']), $dest);
        }
        if ($dirname != $prev_dirname) {
            mkdir(dirname($dest));
            echo "    {$dirname}\n";
        }
        echo "      {$filename}\n";
        symlink($item, $dest);
        $prev_dirname = $dirname;
    }
}
开发者ID:jaquer,项目名称:MusicCollectionManagement,代码行数:48,代码来源:create_symlinks.php

示例3: sudo

 /**
  * Helper method which allows to execute a callable as the super user the server got started by.
  *
  * @param callable $callable  The callable to run
  * @param array    $arguments Arguments to pass to the callable
  *
  * @return mixed The callables result
  */
 public static function sudo(callable $callable, array $arguments = array())
 {
     // don't do anything under Windows
     if (FileSystem::getOsIdentifier() === FileSystem::OS_IDENTIFIER_WIN) {
         return call_user_func_array($callable, $arguments);
     }
     // get the current user user pair (super user and effective user)
     $currentUserId = (int) posix_geteuid();
     $superUserId = (int) posix_getuid();
     // temporarily switch to the super user
     posix_seteuid($superUserId);
     // execute the callable
     $result = call_user_func_array($callable, $arguments);
     // switch back to the effective user
     posix_seteuid($currentUserId);
     return $result;
 }
开发者ID:jinchunguang,项目名称:appserver,代码行数:25,代码来源:PermissionHelper.php

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

示例5: 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());
         // print a message with the old UID/EUID
         $applicationServer->getSystemLogger()->info("Running as " . posix_getuid() . "/" . posix_geteuid());
         // extract the variables
         $uid = 0;
         extract(posix_getpwnam('root'));
         // switcht 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 " . posix_getuid() . "/" . posix_geteuid());
         // @TODO Switch group also!!!!
     } catch (\Exception $e) {
         $applicationServer->getSystemLogger()->error($e->__toString());
     }
 }
开发者ID:jinchunguang,项目名称:appserver,代码行数:32,代码来源:SwitchRootListener.php

示例6: dirname

    $fastagi->config['fastagi']['basedir'] = dirname(__FILE__);
}
// perform some security checks
$script = $fastagi->config['fastagi']['basedir'] . DIRECTORY_SEPARATOR . $fastagi->request['agi_network_script'];
// in the same directory (or subdirectory)
$mydir = dirname($fastagi->config['fastagi']['basedir']) . DIRECTORY_SEPARATOR;
$dir = dirname($script) . DIRECTORY_SEPARATOR;
if (substr($dir, 0, strlen($mydir)) != $mydir) {
    $fastagi->conlog("{$script} is not allowed to execute.");
    exit;
}
// make sure it exists
if (!file_exists($script)) {
    $fastagi->conlog("{$script} does not exist.");
    exit;
}
// drop privileges
if (isset($fastagi->config['fastagi']['setuid']) && $fastagi->config['fastagi']['setuid']) {
    $owner = fileowner($script);
    $group = filegroup($script);
    if (!posix_setgid($group) || !posix_setegid($group) || !posix_setuid($owner) || !posix_seteuid($owner)) {
        $fastagi->conlog("failed to lower privileges.");
        exit;
    }
}
// make sure script is still readable
if (!is_readable($script)) {
    $fastagi->conlog("{$script} is not readable.");
    exit;
}
require_once $script;
开发者ID:vovax3m,项目名称:serverside,代码行数:31,代码来源:phpagi-fastagi.php

示例7: restoreRootUidGid

 protected function restoreRootUidGid()
 {
     posix_setegid(0);
     posix_seteuid(0);
 }
开发者ID:pombredanne,项目名称:tuleap,代码行数:5,代码来源:User_SSHKeyDumper.class.php

示例8: seteuid

 /**
  * Set the effective UID of the current process
  *
  * @param int $uid The user id.
  *
  * @return bool
  */
 public function seteuid(int $uid) : bool
 {
     return posix_seteuid($uid);
 }
开发者ID:aurimasniekis,项目名称:php-wrappers,代码行数:11,代码来源:Posix.php

示例9: dropPrivileges

 private function dropPrivileges()
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         return;
     }
     $user = $this->options->user;
     if (!extension_loaded("posix")) {
         if ($user !== null) {
             throw new \RuntimeException("Posix extension must be enabled to switch to user '{$user}'!");
         }
     } elseif (posix_geteuid() === 0) {
         if ($user === null) {
             $this->logger->warning("Running as privileged user is discouraged! Use the 'user' option to switch to another user after startup!");
             return;
         }
         $info = posix_getpwnam($user);
         if (!$info) {
             throw new \RuntimeException("Switching to user '{$user}' failed, because it doesn't exist!");
         }
         $success = posix_seteuid($info["uid"]);
         if (!$success) {
             throw new \RuntimeException("Switching to user '{$user}' failed, probably because of missing privileges.'");
         }
     }
 }
开发者ID:efueger,项目名称:aerys,代码行数:25,代码来源:Server.php

示例10: setIds

 /**
  * De-escalates privileges
  */
 private function setIds()
 {
     posix_seteuid($this->config['daemon']['user']['uid']);
     posix_setegid($this->config['daemon']['user']['gid']);
 }
开发者ID:jlkaufman,项目名称:blackhole-bot,代码行数:8,代码来源:Daemon.php

示例11: posix_setgid

 include 'AtomintersoftModule.php';
 include 'SamairModule.php';
 include 'FreeCheckerModule.php';
 include 'NNTimeModule.php';
 // set proper permissions
 if (posix_getgid() != GID) {
     posix_setgid(GID);
 }
 if (posix_getuid() != UID) {
     posix_setuid(UID);
 }
 if (posix_getegid() != GID) {
     posix_setegid(GID);
 }
 if (posix_geteuid() != UID) {
     posix_seteuid(UID);
 }
 // first check that an instance is not already running
 if (file_exists(PIDFILE)) {
     $line = file(PIDFILE);
     $pid = trim($line[0]);
     if (count(explode("\n", shell_exec("ps --pid " . $pid))) > 2) {
         die("An instance of the daemon is already running with PID {$pid}\n");
     } else {
         // no process with that PID, can safely remove the existing PID file
         print "Found dangling PID file, removing...\n";
         unlink(PIDFILE);
     }
 }
 // fork the main process
 $pid = pcntl_fork();
开发者ID:TheProjecter,项目名称:miscellaneousrepo,代码行数:31,代码来源:daemon.php

示例12: test_error_handler

<?php

echo "*** Test substituting argument 1 with object values ***\n";
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars)
{
    if (error_reporting() != 0) {
        // report non-silenced errors
        echo "Error: {$err_no} - {$err_msg}, {$filename}({$linenum})\n";
    }
}
set_error_handler('test_error_handler');
class classWithToString
{
    public function __toString()
    {
        return "Class A object";
    }
}
class classWithoutToString
{
}
$variation_array = array('instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString());
foreach ($variation_array as $var) {
    var_dump(posix_seteuid($var));
}
开发者ID:badlamer,项目名称:hhvm,代码行数:25,代码来源:posix_seteuid_error2.php

示例13: close

 /**
  * Close session and return to previous uid
  */
 public static function close()
 {
     session_write_close();
     // change uid back
     if (null !== static::$pre_session_uid) {
         posix_seteuid(static::$pre_session_uid);
         static::$pre_session_uid = null;
     }
 }
开发者ID:dermidgen,项目名称:moode,代码行数:12,代码来源:Session.php

示例14: posix_getuid

    echo "posix_getppid succeeded\n";
} else {
    echo "posix_getppid failed\n";
}
$uid = posix_getuid();
echo "uid={$uid}\n";
$euid = posix_geteuid();
echo "euid={$euid}\n";
$gid = posix_getgid();
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";
开发者ID:jenalgit,项目名称:roadsend-php,代码行数:31,代码来源:posix.php

示例15: var_dump

<?php

echo "*** Test by calling method or function with incorrect numbers of arguments ***\n";
$uid = '123';
$extra_arg = '12312';
var_dump(posix_seteuid($uid, $extra_arg));
var_dump(posix_seteuid());
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:posix_seteuid_error.php


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