setuid funciton
Hello everybody
I have written simple code about usage of setuid. this program file set-user-id bit is on and this process after exec when I execute this program, effective user id and saved-user-id bit will be program-file's user id. this correct?
But the last output when I set uid to 80(www) ,effective user id wasn't 80. Why not? saved set user id is still 80? What is the problem?
I compiled below code with gcc and I set-user-id bit and change own file with this command
Code:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{
printf("Real UID\t= %d\n", getuid());
printf("Effective UID\t= %d\n", geteuid());
printf("Real GID\t= %d\n", getgid());
printf("Effective GID\t= %d\n", getegid());
setuid(1001);
printf("Real UID\t= %d\n", getuid());
printf("Effective UID\t= %d\n", geteuid());
printf("Real GID\t= %d\n", getgid());
printf("Effective GID\t= %d\n", getegid());setuid(80);
printf("Real UID\t= %d\n", getuid());
printf("Effective UID\t= %d\n", geteuid());
printf("Real GID\t= %d\n", getgid());
printf("Effective GID\t= %d\n", getegid());
return EXIT_SUCCESS;
}gcc setuid-simple.c -o setuid-simple#[root] chown www setuid-simple
#[root] chmod 4755 setuid-simple
and output with ls command
-rwsr-xr-x 1 www wheel 5708 23 Ara 11:41 setuid-simple
this is program's output:
Quote:
Real UID = 1001
Effective UID = 80
Real GID = 0
Effective GID = 0
/*setuid(1001)*/
Real UID = 1001
Effective UID = 1001
Real GID = 0
Effective GID = 0
/*setuid(80)*/
Real UID = 1001
Effective UID = 1001
Real GID = 0
Effective GID = 0
Signature · 7 lines
Cihan Kömeçoðlu, EnderUNIX SDT mailto:[email protected] - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Cihan Kömeçoğlu
Hello everybody
I have written simple code about usage of setuid. this program file set-user-id bit is on and this process after exec when I execute this program, effective user id and saved-user-id bit will be program-file's user id. this correct?
Quoted 7 lines
But the last output when I set uid to 80(www) ,effective user id wasn't 80. Why not? saved set user id is still 80? What is the problem?
I compiled below code with gcc and I set-user-id bit and change own file with this command
[snip]
It works for me; I get:
Real UID = 1001
Effective UID = 80
Real UID = 1001
Effective UID = 1001
Real UID = 1001
Effective UID = 80
This is with a 2.6.17.13 kernel, compiled from stock sources (no vendor patches).
If you are using a kernel with additional security features (e.g. SELinux, AppArmor etc), it may impose additional restrictions on setuid(). You could try using setreuid() to swap the real and effective UIDs, rather than relying upon the saved UID.
Signature · 5 lines
Glynn Clements <[email protected]> - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
I understand. Thanks for your answer
I try this code under Freebsd 6.2
and dont give me this output
Quoted 35 lines · you
Quoted 7 lines · Cihan Kömeçoľlu
Hello everybody
I have written simple code about usage of setuid. this program file set-user-id bit is on and this process after exec when I execute this program, effective user id and saved-user-id bit will be program-file's user id. this correct?
Quoted 7 lines
But the last output when I set uid to 80(www) ,effective user id wasn't 80. Why not? saved set user id is still 80? What is the problem?
I compiled below code with gcc and I set-user-id bit and change own file with this command
[snip]
It works for me; I get:
Real UID = 1001 Effective UID = 80 Real UID = 1001 Effective UID = 1001 Real UID = 1001 Effective UID = 80This is with a 2.6.17.13 kernel, compiled from stock sources (no vendor patches).
If you are using a kernel with additional security features (e.g. SELinux, AppArmor etc), it may impose additional restrictions on
setuid(). You could try usingsetreuid()to swap the real and effective UIDs, rather than relying upon the saved UID.
Signature · 7 lines
Cihan Kömeçoðlu, EnderUNIX SDT mailto:[email protected] - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html