博客首页 注册 建议与交流 排行榜 加入友情链接         宝宝相册的专门空间
推荐 投诉 搜索: 帮助
  dorainm.cublog.cn

关于作者
dorainm
dorainm@gmail.com

我的梦想是当一名地主家的少爷,家有良田千顷,终日不学无术,没事领着一帮狗和奴才去调戏一下良家少女……

格物、致知、正心、诚意、修身、齐家、治国、平天下

电影的长度取决于观众的那泡尿能憋多久

(手机丢光了...
买了个能打电话的手机)
|| << >> ||
我的分类


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

   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

#

 TAG perl setuid 权限
发表于: 2008-04-28,修改于: 2008-04-28 18:39,已浏览186次,有评论0条 推荐 投诉


网友评论
 发表评论