我正在尝试使用下面的代码更改进程的真实 UID
int ERN2=setreuid(euid,m_ruid);
printf("something went wrong with setreuid %s\n", strerror(ERN2));
std::cout<<"error no for setrugid"<<ERN2<<"\n";
if ( ERN2 == 0)
{
.....
}
m_ruid
是 root(0),euid
是接受的 ID,但是当我得到 setreuid()
的结果时,它的总是 -1 并且我使用了 strerror()
,它表示“不允许操作”,此外我还可以更改 realGID setregid()
但始终更改 UID失败了,任何人都可以提供一些线索。
我使用的是 FreeBSD。我想知道为什么即使我们将 root 作为参数之一也会发生这种情况。
最佳答案
手册页非常清楚:
The setreuid() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
这就是几乎所有系统调用的错误返回方式。它们不返回 errno,只返回 -1
或错误时的等效值,并设置全局变量 errno
。
如果不清楚,请尝试 strerror(errno)
看看会得到什么。
关于c++ - setreuid() 失败,操作不允许,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39703573/