I have added the capability by using following cmd on terminal (alternative of setting CAP_SETUID in drop-in file). Verified that setuid/seteuid is working.
setcap cap_sys_admin,cap_setuid+ep /usr/bin/<processname>
Now I want to to set my process privileged as root --> sync() --> set to original privilege---> do some work --> set as root again--->sync()
while using setuid(),I have found out that we can set process as root only one time in one boot cycle. However it can be done by seteuid(), I have tried that also , still not able to achieved the desired result.
Can you please suggest what I am missing or doing work.
int id = geteuid(); int r0= seteuid(0); // This will raise process to root mode sync(); //process can perform operation as root user seteuid(id); //set process as non root user
first time r0 is 0[successful], second time r0 is -1[error in seteuid(0)] . (In same boot cycle) Thanks in advance.