Skip to content

Commit

Permalink
Split setgid and setuid, add privilege check
Browse files Browse the repository at this point in the history
  • Loading branch information
D.B committed Sep 20, 2016
1 parent d98c26d commit 5e585f9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sway/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,18 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
if (getuid() != geteuid() || getgid() != getegid()) {
if (setgid(getgid()) != 0 || setuid(getuid()) != 0) {
if (setgid(getgid()) != 0) {
sway_log(L_ERROR, "Unable to drop root");
exit(EXIT_FAILURE);
}
if (setuid(getuid()) != 0) {
sway_log(L_ERROR, "Unable to drop root");
exit(EXIT_FAILURE);
}
}
if (setuid(0) != -1) {
sway_log(L_ERROR, "Root privileges can be restored.");
exit(EXIT_FAILURE);
}
char *socket_path = getenv("SWAYSOCK");
if (!socket_path) {
Expand Down

0 comments on commit 5e585f9

Please sign in to comment.