linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* setuid funciton
@ 2007-12-25 19:12 Cihan Kömeçoğlu
  2007-12-26  3:28 ` Glynn Clements
  0 siblings, 1 reply; 3+ messages in thread
From: Cihan Kömeçoğlu @ 2007-12-25 19:12 UTC (permalink / raw)
  To: linux-c-programming

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 




-- 
Cihan Kömeçoðlu,
EnderUNIX SDT                         mailto:cihan@enderunix.org

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-12-26 23:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-25 19:12 setuid funciton Cihan Kömeçoğlu
2007-12-26  3:28 ` Glynn Clements
2007-12-26 23:48   ` Re[2]: " Cihan Kömeçoğlu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).