文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Perl程序中类似setuid的权限设置

Perl程序中类似setuid的权限设置

时间:2008-04-28  来源:dorainm

   Perl 编写了一个系统的服务程序(见文章 另类的 Linux在线文本打印和基于 Perl的 Web Service ),开机时候利用 rc.d启动,但是运行时刻都是 root权限,对于脚本程序,比起二进制的ELF文件,毕竟更怕些,嘻,因为比较容易暴露源代码…

    为了保障运行的稳定性,也让系统更稳定一些,我们需要类似 setuid之类的函数,在不需要特权的时候,以一个伪用户权限运行。

    Perl 在处理这权限,用 $< 和 $>,如下:

$< The real uid of this process. (Mnemonic: it's the uid you came
        *from*, if you're running setuid.) You can change both the real
        uid and the effective uid at the same time by using
        POSIX::setuid(). Since changes to $< require a system call,
        check $! after a change attempt to detect any possible errors.

$> The effective uid of this process. Example:

            $< = $>; # set real to effective uid

            ($<,$>) = ($>,$<); # swap real and effective uid


        You can change both the effective uid and the real uid at the
        same time by using POSIX::setuid(). Changes to $> require a
        check to $! to detect any possible errors after an attempted
        change.

        (Mnemonic: it's the uid you went *to*, if you're running
        setuid.) $< and $> can be swapped only on machines supporting
        setreuid().


    简单的 $< 用法如下:

#!/usr/bin/perl

$> = 0;
system "whoami";

$> = 1000;
system "whoami";

$> = 0;
system "whoami";



    运行效果如下:

# ./test.pl
root
dorainm
root

#

相关阅读 更多 +
排行榜 更多 +
别惹神枪手安卓版

别惹神枪手安卓版

冒险解谜 下载
坦克战争世界

坦克战争世界

模拟经营 下载
丛林反击战

丛林反击战

飞行射击 下载