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.
So on the cmd shell I call
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")
But testapp stops with chown: changing ownership of '/sbin/reboot': Operation not permitted
So, what has to be done to enable renaming this particular file from within an app not running 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 .
@datenwolf: Without beeing impolite, but if I ask into the crowd "What's the time"? 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
rename("file1" "file2");
Then everything works like a charm.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.