gpt4 book ai didi

c++ - 在 C++ 中将 UID 设置为 root 以外的用户

转载 作者:行者123 更新时间:2023-11-28 03:32:46 25 4
gpt4 key购买 nike

我正在 Ubuntu 11.04 上的 NetBeans 6.9 上使用 C++ 进行开发。我正在进行 system() 调用,我希望将其称为用户“peter”而不是 root。我明白了

setuid(0);

将用户设置为 root 但如何将用户设置为 peter?

谢谢,彼得。

最佳答案

您可能想通过例如搜索密码文件以查找正确的用户 ID getpwnam() .像这样的东西:

// look up peter's uid
uid_t peter_uid=getpwnam("peter")->pw_uid;

// Become peter
setuid(peter_uid);
seteuid(peter_uid);

关于c++ - 在 C++ 中将 UID 设置为 root 以外的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12023559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com