Hi,
I'm trying to run a simple setuid program on Linux. I know that shell scripts aren't allowed to setuid, so I wrote a simple C file to do the job (yes I know it's not wise to use the system() command, it's just for testing purposes).
This is the code:
And the permissions are:
-rwsr-xr-x 1 relz arzey setuid_prog*
It is supposed to print the effective user-id, and then list the files in a directory accesible only by the owner "relz".
But when I run this program from another user, I get his user-id returned, and of course the directory can't be listed because of "permission denied".
What am I doing wrong?
I'm trying to run a simple setuid program on Linux. I know that shell scripts aren't allowed to setuid, so I wrote a simple C file to do the job (yes I know it's not wise to use the system() command, it's just for testing purposes).
This is the code:
Code:
#include <unistd.h>
#include <sys/types.h>
int main (int argc, char *argv) {
printf(" When I invoke getuid I get: %d\n", getuid());
system ("ls ~relz/temp/locked_dir");
return 0;
}
-rwsr-xr-x 1 relz arzey setuid_prog*
It is supposed to print the effective user-id, and then list the files in a directory accesible only by the owner "relz".
But when I run this program from another user, I get his user-id returned, and of course the directory can't be listed because of "permission denied".
What am I doing wrong?