Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setuid vs seteuid function

Tags:

c

linux

unix

setuid

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.

like image 208
mohangraj Avatar asked Oct 12 '15 08:10

mohangraj


People also ask

What does seteuid do?

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".

What does setuid do in C?

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.

What does setuid return?

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.

Is setuid A system call?

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.


1 Answers

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).
like image 137
user3159253 Avatar answered Oct 27 '22 00:10

user3159253