aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sway/main.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/sway/main.c b/sway/main.c
index e0af4a79..d4585f73 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -186,12 +186,17 @@ static void log_kernel(void) {
186 186
187static bool drop_permissions(void) { 187static bool drop_permissions(void) {
188 if (getuid() != geteuid() || getgid() != getegid()) { 188 if (getuid() != geteuid() || getgid() != getegid()) {
189 if (setuid(getuid()) != 0 || setgid(getgid()) != 0) { 189 // Set the gid and uid in the correct order.
190 sway_log(SWAY_ERROR, "Unable to drop root, refusing to start"); 190 if (setgid(getgid()) != 0) {
191 sway_log(SWAY_ERROR, "Unable to drop root group, refusing to start");
192 return false;
193 }
194 if (setuid(getuid()) != 0) {
195 sway_log(SWAY_ERROR, "Unable to drop root user, refusing to start");
191 return false; 196 return false;
192 } 197 }
193 } 198 }
194 if (setuid(0) != -1) { 199 if (setgid(0) != -1 || setuid(0) != -1) {
195 sway_log(SWAY_ERROR, "Unable to drop root (we shouldn't be able to " 200 sway_log(SWAY_ERROR, "Unable to drop root (we shouldn't be able to "
196 "restore it after setuid), refusing to start"); 201 "restore it after setuid), refusing to start");
197 return false; 202 return false;