Tag: setuid seteuid
Header file: # include <unistd. h>
Define the function: int setuid (uid_t UID );
Function Description:
Setuid () is used to reset the user identification code for executing the current process. however, for this function to be useful, the valid user ID must be 0 (Root ). in Linux, when the root user uses setuid () to convert it to another user identification code, the root permission is discarded and fully converted to the user identity. That is to say, this process will no longer have the setuid () permission in the future. If you only temporarily discard the root permission and want to retrieve the permission again later, you must use seteuid ().
Returned value: if the execution is successful, 0 is returned. If the execution fails,-1 is returned. The error code is stored in errno.
Note: When compiling a program with setuid root, we recommend that you run setuid (getuid () immediately after the root permission is used to reduce the system security risks caused by this program ()); to discard the root permission. in addition, the Linux system will not generate core dump when the process UID and EUID are inconsistent.
Difference between setuid () and seteuid ()