What is the difference between setuid and seteuid function. In man page both of the function have similar description.
setuid:
DESCRIPTION
setuid() sets the effective user ID of the calling process. If the effective UID of the caller is root, the real UID and saved
set-user-ID are also set.
seteuid:
DESCRIPTION
seteuid() sets the effective user ID of the calling process. Unprivileged user processes may only set the effective user ID to
the real user ID, the effective user ID or the saved set-user-ID.
In both of the description contains sets the effective user ID of the calling process
. So what is the difference between
these two and how the functionality differs between these functions.
And One more doubt is, using chmod(chmod u+s ) only we can set the set user id permission to the file. Then only during runtime of the program, the process have permission who is set to set user id. Apart from these how these functions set the effective userid to the process.
seteuid() sets the effective user ID of the calling process. Unprivileged processes may only set the effective user ID to the real user ID, the effective user ID or the saved set-user-ID. Precisely the same holds for setegid() with "group" instead of "user".
The setuid() function checks the effective user ID of the caller and if it is the superuser, all process related user ID's are set to uid. After this has occurred, it is impossible for the program to regain root privileges.
If successful, setuid() returns zero. On failure, it returns -1 and sets errno to one of the following values: EINVAL. The value of uid is out of range.
The original Linux setuid() system call supported only 16-bit user IDs. Subsequently, Linux 2.4 added setuid32() supporting 32-bit IDs. The glibc setuid() wrapper function transparently deals with the variation across kernel versions.
From the man page:
Thus, a set-user-ID-root program wishing to temporarily drop root
privileges, assume the identity of an unprivileged user, and then
regain root privileges afterward cannot use setuid(). You can
accomplish this with seteuid(2).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With