Embed Notice
HTML Code
Corresponding Notice
- Embed this notice@pid_eins Lennart does it again making things less secure.
suid binaries are very secure provided you program the software correctly.
Here's an example of secure suid software I found, free from vulnerabilities;
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <grp.h>
#include <unistd.h>
int main(void)
{
/* get gid of power-tools group */
struct group *power = getgrnam("power-tools");
if (!power){fprintf(stderr,"power-tools group does not exist.\n"), exit(1);}
/* check if the current user has the gid of power */
if (!group_member(power->gr_gid)){fprintf(stderr, "User is not in power-tools group.\n"), exit(1);}
/* change to root user */
if (setuid(0) != 0){fprintf(stderr,"Suspend binary is not setuid.\n"), exit(1);}
/* open mem_sleep and state */
int mem_sleep = open("/sys/power/mem_sleep", O_WRONLY);
int state = open("/sys/power/state", O_WRONLY);
if (!mem_sleep || !state){perror("Linux doesn't support Suspend-to-RAM"), exit(1);}
/* write deep to /sys/power/mem_sleep then mem to /sys/power/state to Suspend-to-RAM */
if (write(mem_sleep, "deep\n", 5) != 5){perror("Writing deep failed"), exit(1);}
if (write(state, "mem\n", 4) != 4){perror("Writing mem failed"), exit(1);}
/* close the fd's */
close(mem_sleep);
close(state);
return 0;
}