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


PHP posix_getpwnam函数代码示例

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


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

示例1: open

 /**
  * Open session, adjust UID if required
  */
 public static function open($admin = false)
 {
     if (PHP_SESSION_ACTIVE == session_status()) {
         throw new \LogicException('Session already open');
     }
     // automatic admin mode for command line testing if root
     $session_file = session_save_path() . DIRECTORY_SEPARATOR . 'sess_' . static::SESSION_ID;
     if (file_exists($session_file) && is_readable($session_file)) {
         $session_owner = fileowner($session_file);
         if ($session_owner !== posix_getuid() && 0 === posix_getuid()) {
             // echo("o: $session_owner\n");
             $admin = true;
         }
         $_SESSION['_dirty'] = microtime();
     }
     // set effective uid of session owner
     if ($admin) {
         static::$pre_session_uid = posix_getuid();
         posix_seteuid(posix_getpwnam(static::SESSION_ADMIN_USER)['uid']);
     }
     // tie all users to single session
     session_id(static::SESSION_ID);
     if (false === session_start()) {
         throw new \RuntimeException('Could not start session');
     }
     // update sesson with current configuration
     // TODO check if necessary
     foreach (ConfigDB::read('cfg_engine') as $row) {
         $_SESSION[$row['param']] = $row['value'];
     }
 }
开发者ID:dermidgen,项目名称:moode,代码行数:34,代码来源:Session.php

示例2: migrateGroup

function migrateGroup($group)
{
    $groups = parseGroupFile();
    if (!isset($groups[$group])) {
        return false;
    }
    $group = $groups[$group];
    global $wgAuth;
    $dbw = $wgAuth->getDB(DB_WRITE);
    if (false == $dbw->insert('groups', array('grp_name' => $group['name'], 'grp_password' => $group['password'], 'grp_gid' => $group['gid']), __METHOD__)) {
        return false;
    }
    foreach ($group['members'] as $user) {
        $pwd = posix_getpwnam($user);
        if (!$pwd) {
            return false;
        }
        print "Migrating {$pwd['name']}\n";
        if (false == $dbw->insert('group_membership', array('gm_group' => $group['name'], 'gm_user' => $pwd['uid']), __METHOD__)) {
            $dbw->rollback();
            return false;
        }
    }
    $dbw->commit();
    wfDoUpdates();
    return true;
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:27,代码来源:migrateGroup.php

示例3: import

 public function import($login_)
 {
     Logger::debug('main', 'UserDB::unix::import(' . $login_ . ')');
     $tab = posix_getpwnam($login_);
     if (is_array($tab)) {
         $u = new User();
         if (isset($tab['name'])) {
             $u->setAttribute('login', $tab['name']);
         }
         if (isset($tab['gecos'])) {
             $ex = explode(',', $tab['gecos']);
             $u->setAttribute('displayname', $ex[0]);
         }
         if (isset($tab['uid'])) {
             $u->setAttribute('uid', $tab['uid']);
         }
         if (isset($tab['gid'])) {
             $u->setAttribute('gid', $tab['gid'], 1);
         }
         if (isset($tab['dir'])) {
             $u->setAttribute('homedir', $tab['dir']);
         }
         return $u;
     }
     return NULL;
 }
开发者ID:skdong,项目名称:nfs-ovd,代码行数:26,代码来源:unix.php

示例4: doPut

 private function doPut($token, $payload, $user = null)
 {
     Assert::string($token, "Token must be a string. Got: %s");
     Assert::string($payload, "Payload must be a string. Got: %s");
     Assert::nullOrString($user, "User must be a string or null. Got: %s");
     $path = $this->docroot . "/.well-known/acme-challenge";
     $realpath = realpath($path);
     if (!realpath($this->docroot)) {
         throw new ChallengeStoreException("Document root doesn't exist: '{$this->docroot}'");
     }
     if (!$realpath && !@mkdir($path, 0755, true)) {
         throw new ChallengeStoreException("Couldn't create public directory to serve the challenges: '{$path}'");
     }
     if ($user) {
         if (!($userInfo = posix_getpwnam($user))) {
             throw new ChallengeStoreException("Unknown user: '{$user}'");
         }
     }
     if (isset($userInfo)) {
         (yield \Amp\File\chown($this->docroot . "/.well-known", $userInfo["uid"], -1));
         (yield \Amp\File\chown($this->docroot . "/.well-known/acme-challenge", $userInfo["uid"], -1));
     }
     (yield \Amp\File\put("{$path}/{$token}", $payload));
     if (isset($userInfo)) {
         (yield \Amp\File\chown("{$path}/{$token}", $userInfo["uid"], -1));
     }
     (yield \Amp\File\chmod("{$path}/{$token}", 0644));
 }
开发者ID:kelunik,项目名称:acme-client,代码行数:28,代码来源:ChallengeStore.php

示例5: show_about

/**
 * @version $Id: footer.php 107 2008-07-22 17:27:12Z soeren $
 * @package eXtplorer
 * @copyright soeren 2007
 * @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
 * @author The  The QuiX project (http://quixplorer.sourceforge.net)
 * 
 * @license
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * Alternatively, the contents of this file may be used under the terms
 * of the GNU General Public License Version 2 or later (the "GPL"), in
 * which case the provisions of the GPL are applicable instead of
 * those above. If you wish to allow use of your version of this file only
 * under the terms of the GPL and not to allow others to use
 * your version of this file under the MPL, indicate your decision by
 * deleting  the provisions above and replace  them with the notice and
 * other provisions required by the GPL.  If you do not delete
 * the provisions above, a recipient may use your version of this file
 * under either the MPL or the GPL."
 * 
 * Shows the About Box!
 */
function show_about()
{
    // footer for html-page
    echo "\n<div id=\"ext_footer\" style=\"text-align:center;\">\r\n\t<img src=\"" . _EXT_URL . "/images/MangosWeb_small.png\" align=\"middle\" alt=\"Mangosweb Enhanced Logo\" />\r\n\t<br />\r\n\t" . ext_Lang::msg('your_version') . ": <a href=\"" . $GLOBALS['ext_home'] . "\" target=\"_blank\">eXtplorer {$GLOBALS['ext_version']}</a>\r\n\t<br />\r\n (<a href=\"http://virtuemart.net/index2.php?option=com_versions&amp;catid=5&amp;myVersion=" . $GLOBALS['ext_version'] . "\" onclick=\"javascript:void window.open('http://virtuemart.net/index2.php?option=com_versions&catid=5&myVersion=" . $GLOBALS['ext_version'] . "', 'win2', 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=580,directories=no,location=no'); return false;\" title=\"" . $GLOBALS["messages"]["check_version"] . "\">" . $GLOBALS["messages"]["check_version"] . "</a>)\r\n\t\r\n\t";
    if (function_exists("disk_free_space")) {
        $size = disk_free_space($GLOBALS['home_dir'] . $GLOBALS['separator']);
        $free = parse_file_size($size);
    } elseif (function_exists("diskfreespace")) {
        $size = diskfreespace($GLOBALS['home_dir'] . $GLOBALS['separator']);
        $free = parse_file_size($size);
    } else {
        $free = "?";
    }
    echo '<br />' . $GLOBALS["messages"]["miscfree"] . ": " . $free . " \n";
    if (extension_loaded("posix")) {
        $owner_info = '<br /><br />' . ext_Lang::msg('current_user') . ' ';
        if (ext_isFTPMode()) {
            $my_user_info = posix_getpwnam($_SESSION['ftp_login']);
            $my_group_info = posix_getgrgid($my_user_info['gid']);
        } else {
            $my_user_info = posix_getpwuid(posix_geteuid());
            $my_group_info = posix_getgrgid(posix_getegid());
        }
        $owner_info .= $my_user_info['name'] . ' (' . $my_user_info['uid'] . '), ' . $my_group_info['name'] . ' (' . $my_group_info['gid'] . ')';
        echo $owner_info;
    }
    echo "\r\n\t</div>";
}
开发者ID:BACKUPLIB,项目名称:mwenhanced,代码行数:59,代码来源:footer.php

示例6: SQUID_PAM_check

/**
* Check the username / password against the PAM system
*/
function SQUID_PAM_check($username, $password)
{
    global $c;
    $script = $c->authenticate_hook['config']['script'];
    if (empty($script)) {
        $script = $c->authenticate_hook['config']['path'];
    }
    $cmd = sprintf('echo %s %s | %s -n common-auth', escapeshellarg($username), escapeshellarg($password), $script);
    $auth_result = exec($cmd);
    if ($auth_result == "OK") {
        dbg_error_log('pwauth', 'User %s successfully authenticated', $username);
        $principal = new Principal('username', $username);
        if (!$principal->Exists()) {
            dbg_error_log('pwauth', 'User %s does not exist in local db, creating', $username);
            $pwent = posix_getpwnam($username);
            $gecos = explode(',', $pwent['gecos']);
            $fullname = $gecos[0];
            $principal->Create(array('username' => $username, 'user_active' => 't', 'email' => sprintf('%s@%s', $username, $email_base), 'fullname' => $fullname));
            if (!$principal->Exists()) {
                dbg_error_log("PAM", "Unable to create local principal for '%s'", $username);
                return false;
            }
            CreateHomeCalendar($username);
        }
        return $principal;
    } else {
        dbg_error_log("PAM", "User %s is not a valid username (or password was wrong)", $username);
        return false;
    }
}
开发者ID:derekyu1437,项目名称:davical,代码行数:33,代码来源:drivers_squid_pam.php

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

示例8: checkWorkerUserName

 /**
  * 检查启动worker进程的的用户是否合法
  * @return void
  */
 public static function checkWorkerUserName($worker_user)
 {
     if ($worker_user) {
         $user_info = posix_getpwnam($worker_user);
         return !empty($user_info);
     }
 }
开发者ID:noikiy,项目名称:workerman-flappy-bird,代码行数:11,代码来源:Checker.php

示例9: setUserName

 /**
  * Defines the current user name.
  *
  *
  * @param string $userName Unix user name.
  *
  * @throws RuntimeException When unable to update current user name.
  */
 public function setUserName($userName)
 {
     $user = posix_getpwnam($userName);
     if (!isset($user['uid'])) {
         throw new InvalidArgumentException(sprintf('"%s" is not a valid user name', $userName));
     }
     $this->setUserId($user['uid']);
 }
开发者ID:jamiefifty,项目名称:Process,代码行数:16,代码来源:Info.php

示例10: getUserLogDir

 /**
  * @param string $username
  * @throw UsernameNotFoundException
  * @return string
  */
 protected function getUserLogDir($username)
 {
     if (false === ($userinfo = posix_getpwnam($username))) {
         throw new UsernameNotFoundException();
     }
     $homeDir = $userinfo['dir'];
     return $homeDir . '/logs';
 }
开发者ID:spolischook,项目名称:ylang-ylang,代码行数:13,代码来源:ImportLogsCommand.php

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

示例12: loadUserByUsername

 /**
  * Loads the user for the given username.
  *
  * This method must throw UsernameNotFoundException if the user is not
  * found.
  *
  * @param string $username The username
  *
  * @return PosixUser
  *
  * @see UsernameNotFoundException
  *
  * @throws UsernameNotFoundException if the user is not found
  */
 public function loadUserByUsername($username)
 {
     if ($userInfo = posix_getpwnam($username)) {
         $user = new PosixUser();
         $user->setUsername($username)->setHomeDir($userInfo['dir']);
         return $user;
     }
     throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
 }
开发者ID:spolischook,项目名称:ylang-ylang,代码行数:23,代码来源:PosixUserProvider.php

示例13: setUser

 public function setUser($systemUsername)
 {
     $info = posix_getpwnam($systemUsername);
     if (!$info) {
         self::crash("User '{$systemUsername}' not found");
     }
     $this->userId = $info['uid'];
     return $this;
 }
开发者ID:firehed,项目名称:processmanager,代码行数:9,代码来源:Daemon.php

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

示例15: testGetAnotherUserUID

 /**
  * @memcheck
  */
 public function testGetAnotherUserUID()
 {
     $actual = Process::getUser(intval(`id -u nobody`));
     $expected = posix_getpwnam('nobody');
     $this->assertSame($expected['name'], $actual['name']);
     $this->assertSame($expected['uid'], $actual['uid']);
     $this->assertSame($expected['gid'], $actual['gid']);
     $this->assertSame($expected['dir'], $actual['dir']);
     $this->assertSame($expected['shell'], $actual['shell']);
 }
开发者ID:php-ion,项目名称:php-ion,代码行数:13,代码来源:ProcessTest.php


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