I am trying to run a script from my c++ code owned by root. But it throws me an error permission denied to run the script.
Permissions on files are as follows:
-rwx------ 1 root mygame 39 Dec 24 19:11 script.sh
-rwsr-xr-x 1 gag5kor mygame 7999 Dec 26 12:23 a.out
C++ code:
int err = system("./script.sh");
cout << "Before err: " << err << endl;
cout << "setuid: " << seteuid(0) << endl;
err = system("./script.sh");
cout << "After err: " << err << endl;
getuid() and geteuid() function returns me same value (say 1234) even after I call setuid(0) to get the root permissions.
What I am doing wrong here?
I read the other answers on stackoverflow but not able to understand properly.