[英]linux capabilities to rename a root owned file
For some component testing , in my C++ testapp on Ubuntu 14.04, I'd like to rename /sbin/reboot temporarily to prevent my system under test (another big c++ app started inside testapp) from calling system("/sbin/reboot")
and after the test I want to restore /sbin/reboot
to its full glory. 对于某些组件测试 ,在Ubuntu 14.04上的C ++ testapp中 ,我想临时重命名/ sbin / reboot以防止被测
system("/sbin/reboot")
在testapp中启动了另一个大型c ++应用)调用system("/sbin/reboot")
在测试之后,我想将/sbin/reboot
恢复到其全部性能。
So on the cmd shell I call 所以在cmd shell上我称
sudo setcap cap_chown,cap_dac_override,cap_setfcap=+ep testapp
in order to enable my testapp to call system("chown user /sbin/reboot")
furthermore system("chgrp developer /sbin/reboot")
and system("mv /sbin/reboot /sbin/reboot.tmp")
为了使我的testapp能够调用
system("chown user /sbin/reboot")
system("chgrp developer /sbin/reboot")
和system("mv /sbin/reboot /sbin/reboot.tmp")
But testapp stops with chown: changing ownership of '/sbin/reboot': Operation not permitted 但是testapp以chown停止:更改'/ sbin / reboot'的所有权:不允许操作
So, what has to be done to enable renaming this particular file from within an app not running sudo? 因此,必须执行哪些操作才能从未运行sudo的应用程序中重命名此特定文件?
For all linux capability experts in the www: the question was - " Which of the linux capabilities does my app need to rename /sbin/reboot withou sudo - to get the same effect as calling sudo mv /sbin/reboot /sbin/reboot.tmp
in a shell . 对于www中的所有linux功能专家:问题是-“ 我的应用程序需要使用sudo重命名/ sbin / reboot哪个Linux功能,以获得与调用
sudo mv /sbin/reboot /sbin/reboot.tmp
相同的效果sudo mv /sbin/reboot /sbin/reboot.tmp
外壳中的sudo mv /sbin/reboot /sbin/reboot.tmp
。
@datenwolf: Without beeing impolite, but if I ask into the crowd "What's the time"? @datenwolf:不用蜜蜂礼貌,但是如果我问人群“几点了?” an answer like "you asked the wrong question, because I don't have a watch, but I have a humidity meter, so if you ask about humidity, I am glad to help you" does not help me at all.
诸如“您问错了问题,因为我没有手表,但是我有湿度计,所以如果您询问湿度,很高兴为您提供帮助”之类的答案根本没有帮助我。
The solution to rename a root owned file is, to only set 重命名拥有根文件的解决方案是仅设置
sudo setcap cap_dac_override=+ep MyTestApp
on commandline, and instead of using 在命令行上,而不是使用
system("mv file1 file2");
in MyTestApp source-code, switch back to 在MyTestApp源代码中,切换回
rename("file1" "file2");
Then everything works like a charm. 然后,一切都像魅力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.