有没有办法改变PHP(Ubuntu)中的当前用户?

时间:2011-08-11 21:48:27

标签: php

最近我一直在寻找一个PHP / Linux shell脚本,它可以将当前工作用户从“www-data”更改为另一个。

因为我尝试运行这项服务:http://cfgfactory.com/images/servers_hire.png这基本上是一个“使命召唤4”服务器,它工作得很好,因为我意识到在职责4服务器的调用中有一个错误让你下载任何文件从服务器我尝试下载../../../var/www/config.php,这工作得很好......所以我为这项服务设置了一个新用户,这就是为什么我需要一种更改用户的方法< / p>

这就是我启动服务器的方式:

function start_cod4($mod,$port,$id){


    $cod4_dir = '/home/bartz/cod4/';
    if(getcwd() != $cod4_dir){
            chdir($cod4_dir);   
    }

    $run = array(
    'sv_hostname' => 'Hire & Play No.'.$id.' by ^1CFG^7Factory.com/host/ - Free game server hiring !',
    'rcon_password' => substr(md5(uniqid()),0,5),
    'g_password' => 'war'.substr(md5(uniqid()),0,3)
    );

    exec('nohup ./cod4_lnxded +set s_num='.$id.' +set net_port '.$port.' +set dedicated 2 +set fs_game mods/'.$mod.' +set sv_punkbuster 1 +set sv_hostname "'.$run['sv_hostname'].'" +set rcon_password "'.$run['rcon_password'].'" +set g_password "'.$run['g_password'].'" +set promod_mode match_mr10 +set g_gametype sd +map '.random_map().' > /dev/null 2>&1 &');
    return $run;

}

所以基本上我需要一个PHP或者任何一个SH脚本来改变当前的工作用户。

提前致谢!

1 个答案:

答案 0 :(得分:1)

在Unix系统上,您无法从常规用户更改为另一个用户。如果模仿另一个安全系统需要posix_setuid(id of victim),那么它将完全消除安全系统。

您必须以root身份启动PHP脚本,然后执行posix_seteuid()以承担其他ID。

更安全的替代方法是以普通用户身份运行脚本,然后exec()调用sudo来运行CoD启动脚本。