Here’s a very brief example of how to use setuid() and setgid() functions in your C program.
int main(void)
{
int current_uid = getuid();
printf(”My UID is: %d. My GID is: %d\n”, current_uid, getgid());
system(”/usr/bin/id”);
if (setuid(0))
{
perror(”setuid”);
return 1;
}
//I am now root!
printf(”My UID is: %d. My GID is: %d\n”, getuid(), getgid());
system(”/usr/bin/id”);
//Time to drop back to regular user priviledges
setuid(current_uid);
printf(”My UID is: %d. My GID is: %d\n”, getuid(), getgid());
system(”/usr/bin/id”);
return 0;
}
The program above should be pretty self explainatory, now:
Tags: C, gcc, Linux, setgid, setuid, System
shPanel is now in production. You should see http://www.adamsinfo.com/shpanel-linux-system-hosting-control-panel/ to preorder! I welcome any ideas/comments
Tags: Control Panel, Hosting, Linux, shPanel, System