Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C setuid vs seteuid函数_C_Linux_Unix_Setuid - Fatal编程技术网

C setuid vs seteuid函数

C setuid vs seteuid函数,c,linux,unix,setuid,C,Linux,Unix,Setuid,setuid和seteuid函数的区别是什么。在手册页中,这两个函数具有相似的描述 setuid: DESCRIPTION setuid() sets the effective user ID of the calling process. If the effective UID of the caller is root, the real UID and saved set-user-ID are also set. 塞特伊德: DESCRIPTION s

setuid和seteuid函数的区别是什么。在手册页中,这两个函数具有相似的描述

setuid:

DESCRIPTION

   setuid()  sets  the  effective user ID of the calling process.  If the effective UID of the caller is root, the real UID and saved
   set-user-ID are also set.
塞特伊德:

DESCRIPTION

   seteuid()  sets  the  effective user ID of the calling process.  Unprivileged user processes may only set the effective user ID to
   the real user ID, the effective user ID or the saved set-user-ID.
在这两种描述中,包含
设置调用进程的有效用户ID
。那么两者之间的区别是什么呢 这两个函数以及这些函数之间的功能差异

还有一个疑问是,使用chmod(chmodu+s)只有我们 可以设置文件的“设置用户id”权限。然后,只有在程序运行时,进程才具有设置为“设置”的权限 用户id。除此之外,这些函数如何设置进程的有效用户id

来自:

在回答“为什么使用seteuid()”问题时:一些系统应用程序使用seteuid(),以便它们可以尝试以“有效”用户的权限执行指令。这允许以root身份运行的编程确保,例如,它创建的任何文件都是使用有效的用户id而不是root id创建的


也许最值得注意的应用程序是Unix“cron”系统,它必须以用户“root”身份运行,但有责任以任意用户的身份执行任意命令。

需要什么。为什么根用户需要非特权用户标识。你有什么例子吗?一个可能的例子是,当一个进程需要一些特权资源(例如,HTTP服务器需要80个端口),但在该进程收集了该资源之后,就完全不需要再以
root
身份运行了(因此,您可以检查,Apache Web服务器以非特权用户的身份运行,如
\uHTTP
\uApache
)。通常,这样的措施被用作安全预防措施:非特权服务器的可能中断通常会带来较少的有害后果。我对上面的手册页参考有疑问。使用setuid,我们可以设置进程的有效用户id。例如:setuid(getuid());执行此语句后,进程的有效用户ID将更改为当前用户。因此,要重新获得root权限,我只需使用setuid(0);但是为什么手册页引用显示
之后无法使用setuid()。您可以使用setuid(2)完成此操作
。的可能重复项看起来与您当天的其他帖子相似。为了整理内容,可能会编辑稍后发布的问题以包含上述信息,然后删除此问题?那么,安全预防理论是错误的吗?
   Thus, a set-user-ID-root program wishing to temporarily drop root
   privileges, assume the identity of an unprivileged user, and then
   regain root privileges afterward cannot use setuid().  You can
   accomplish this with seteuid(2).