![]() |
| | #1 | |
| Registered User Join Date: Dec 2005
Posts: 3
| Setuid function ??? 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;
}
#[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:
| |
| wampire is offline | |
| | #2 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,758
| Only root can setuid(). |
| brewbuck is offline | |
| | #3 | |
| Registered User Join Date: Dec 2005
Posts: 3
| Not only root can setuid. Explained here below. Quote:
| |
| wampire is offline | |
| | #4 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,492
| What does your second setuid() call return?
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #5 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,758
| |
| brewbuck is offline | |
| | #6 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,492
| It wasn't any UID. It was the one of the user running the program, as you can see from the real UID. And then back to the setuid user.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #7 |
| Registered User Join Date: Dec 2005
Posts: 3
| but after exec My saved-user-id is 80 and second setuid must set effective user id to 80 but these program dont do it. |
| wampire is offline | |
| | #8 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,492
| Actually, your saved uid is 1001, because that's the user who starts the app. Then you do the setuid to 1001, setting the effective uid (which was 80) to 1001. The saved uid doesn't change. Thus, at the time you call setuid(80), ruid, euid and suid are all 1001, so the setuid call fails.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #9 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,758
| |
| brewbuck is offline | |
| | #10 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,758
| |
| brewbuck is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling sample DarkGDK Program | Phyxashun | Game Programming | 6 | 01-27-2009 03:07 AM |
| Seg Fault in Compare Function | tytelizgal | C Programming | 1 | 10-25-2008 03:06 PM |
| Another syntax error | caldeira | C Programming | 31 | 09-05-2008 01:01 AM |
| How to fix misaligned assignment statements in the source code? | biggyK | C++ Programming | 28 | 07-16-2006 11:35 PM |
| const at the end of a sub routine? | Kleid-0 | C++ Programming | 14 | 10-23-2005 06:44 PM |