如何在C语言中的Linux上放弃root特权? [英] How to drop root privileges on linux in C?
本文介绍了如何在C语言中的Linux上放弃root特权?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以非root用户的身份分叉,执行和编程,而父级保留root权限.
I'd like to fork and exec and program as a non root user while the parent retains root permissions.
伪代码:
pid = fork();
if (pid == 0) {
if (RunAsUser(ConvertStringToUserId("John")) == false) {
stop();
}
if (RunAsUser(ConvertStringToUserId("admin")) == true) {
stop();
}
CreateProcess();
}
推荐答案
如果要在C代码中放弃特权,请使用函数 setuid
.
If you want to drop privileges in C code, use the function setuid
.
这篇关于如何在C语言中的Linux上放弃root特权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文