@GrapheneOS You can't see this, but if you want to protect your privacy and security, a demon rectangle packed to the brim with propriety malware is not something you should trust, no matter what OS you run on it.
@mia@snacks I'll advise him to suid to normal user for the usage print, but it seems that will increase the chances of a vulnerability rather than decrease them.
@mia@snacks If it did complicated things with argv it could be vulnerable - but as it does a 3 byte read at most and either way it exits without calling suid(), there is no argv attack possible in the code.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */
int main(int argc, char *argv[]) { /* print help or version of there are any arguments */ if (argc >= 2){help_or_version(argv[0], argv[1]);}
/* exit(1) if group does not exist or member is not in group */ check_group_membership();
/* change to root user */ if (setuid(0) != 0){error_exit("Suspend binary is not setuid.");}
/* 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_exit("Linux doesn't support Suspend-to-RAM");}
/* 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_exit("Writing deep failed");} if (write(state, "mem\n", 4) != 4){perror_exit("Writing mem failed");}
/* close the fd's */ close(mem_sleep); close(state);
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */
void check_group_membership() { /* get gid of power group and see if user is a member of that gid */ struct group *gnupu = getgrnam(GROUP_NAME); if (!gnupu){error_exit(GROUP_NAME" group does not exist.\n");} if (!group_member(gnupu->gr_gid)){error_exit("User is not in "GROUP_NAME" group.\n");} }
[[[ To any NSA, CIA & FBI agents reading my profile; please consider ]]][[[ whether defending the US Constitution against all enemies, ]]][[[ foreign or domestic, requires you to follow Snowden's example. ]]]Free software extremist who enjoys freedom and posting ですぅ.Please don't confuse me with an "open source" supporter ですぅ.GNU+Jihad against proprietary and "open source" software ですぅぅぅぅぅぅ!!!ⓘ User is the leader of an international terrorist organization.ですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅですぅ??