aboutsummaryrefslogtreecommitdiffstats
path: root/sway/main.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-07-09 22:54:30 +0100
committerLibravatar emersion <contact@emersion.fr>2018-07-09 22:54:30 +0100
commit63b4bf500020cf35cebfdce2d73f8e359ff495c2 (patch)
tree76624b3d4820551261e5c15f773c403c1a41264e /sway/main.c
parentMerge pull request #2223 from RyanDwyer/floating-move (diff)
downloadsway-63b4bf500020cf35cebfdce2d73f8e359ff495c2.tar.gz
sway-63b4bf500020cf35cebfdce2d73f8e359ff495c2.tar.zst
sway-63b4bf500020cf35cebfdce2d73f8e359ff495c2.zip
Update for swaywm/wlroots#1126
Diffstat (limited to 'sway/main.c')
-rw-r--r--sway/main.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/sway/main.c b/sway/main.c
index ec7353be..c6453226 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -129,7 +129,7 @@ static void log_env() {
129 "SWAYSOCK" 129 "SWAYSOCK"
130 }; 130 };
131 for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) { 131 for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) {
132 wlr_log(L_INFO, "%s=%s", log_vars[i], getenv(log_vars[i])); 132 wlr_log(WLR_INFO, "%s=%s", log_vars[i], getenv(log_vars[i]));
133 } 133 }
134} 134}
135 135
@@ -144,14 +144,14 @@ static void log_distro() {
144 for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) { 144 for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) {
145 FILE *f = fopen(paths[i], "r"); 145 FILE *f = fopen(paths[i], "r");
146 if (f) { 146 if (f) {
147 wlr_log(L_INFO, "Contents of %s:", paths[i]); 147 wlr_log(WLR_INFO, "Contents of %s:", paths[i]);
148 while (!feof(f)) { 148 while (!feof(f)) {
149 char *line; 149 char *line;
150 if (!(line = read_line(f))) { 150 if (!(line = read_line(f))) {
151 break; 151 break;
152 } 152 }
153 if (*line) { 153 if (*line) {
154 wlr_log(L_INFO, "%s", line); 154 wlr_log(WLR_INFO, "%s", line);
155 } 155 }
156 free(line); 156 free(line);
157 } 157 }
@@ -163,7 +163,7 @@ static void log_distro() {
163static void log_kernel() { 163static void log_kernel() {
164 FILE *f = popen("uname -a", "r"); 164 FILE *f = popen("uname -a", "r");
165 if (!f) { 165 if (!f) {
166 wlr_log(L_INFO, "Unable to determine kernel version"); 166 wlr_log(WLR_INFO, "Unable to determine kernel version");
167 return; 167 return;
168 } 168 }
169 while (!feof(f)) { 169 while (!feof(f)) {
@@ -172,7 +172,7 @@ static void log_kernel() {
172 break; 172 break;
173 } 173 }
174 if (*line) { 174 if (*line) {
175 wlr_log(L_INFO, "%s", line); 175 wlr_log(WLR_INFO, "%s", line);
176 } 176 }
177 free(line); 177 free(line);
178 } 178 }
@@ -183,14 +183,14 @@ static void security_sanity_check() {
183 // TODO: Notify users visually if this has issues 183 // TODO: Notify users visually if this has issues
184 struct stat s; 184 struct stat s;
185 if (stat("/proc", &s)) { 185 if (stat("/proc", &s)) {
186 wlr_log(L_ERROR, 186 wlr_log(WLR_ERROR,
187 "!! DANGER !! /proc is not available - sway CANNOT enforce security rules!"); 187 "!! DANGER !! /proc is not available - sway CANNOT enforce security rules!");
188 } 188 }
189#ifdef __linux__ 189#ifdef __linux__
190 cap_flag_value_t v; 190 cap_flag_value_t v;
191 cap_t cap = cap_get_proc(); 191 cap_t cap = cap_get_proc();
192 if (!cap || cap_get_flag(cap, CAP_SYS_PTRACE, CAP_PERMITTED, &v) != 0 || v != CAP_SET) { 192 if (!cap || cap_get_flag(cap, CAP_SYS_PTRACE, CAP_PERMITTED, &v) != 0 || v != CAP_SET) {
193 wlr_log(L_ERROR, 193 wlr_log(WLR_ERROR,
194 "!! DANGER !! Sway does not have CAP_SYS_PTRACE and cannot enforce security rules for processes running as other users."); 194 "!! DANGER !! Sway does not have CAP_SYS_PTRACE and cannot enforce security rules for processes running as other users.");
195 } 195 }
196 if (cap) { 196 if (cap) {
@@ -206,13 +206,13 @@ static void executable_sanity_check() {
206 stat(exe, &sb); 206 stat(exe, &sb);
207 // We assume that cap_get_file returning NULL implies ENODATA 207 // We assume that cap_get_file returning NULL implies ENODATA
208 if (sb.st_mode & (S_ISUID|S_ISGID) && cap_get_file(exe)) { 208 if (sb.st_mode & (S_ISUID|S_ISGID) && cap_get_file(exe)) {
209 wlr_log(L_ERROR, 209 wlr_log(WLR_ERROR,
210 "sway executable has both the s(g)uid bit AND file caps set."); 210 "sway executable has both the s(g)uid bit AND file caps set.");
211 wlr_log(L_ERROR, 211 wlr_log(WLR_ERROR,
212 "This is strongly discouraged (and completely broken)."); 212 "This is strongly discouraged (and completely broken).");
213 wlr_log(L_ERROR, 213 wlr_log(WLR_ERROR,
214 "Please clear one of them (either the suid bit, or the file caps)."); 214 "Please clear one of them (either the suid bit, or the file caps).");
215 wlr_log(L_ERROR, 215 wlr_log(WLR_ERROR,
216 "If unsure, strip the file caps."); 216 "If unsure, strip the file caps.");
217 exit(EXIT_FAILURE); 217 exit(EXIT_FAILURE);
218 } 218 }
@@ -223,16 +223,16 @@ static void executable_sanity_check() {
223static void drop_permissions(bool keep_caps) { 223static void drop_permissions(bool keep_caps) {
224 if (getuid() != geteuid() || getgid() != getegid()) { 224 if (getuid() != geteuid() || getgid() != getegid()) {
225 if (setgid(getgid()) != 0) { 225 if (setgid(getgid()) != 0) {
226 wlr_log(L_ERROR, "Unable to drop root"); 226 wlr_log(WLR_ERROR, "Unable to drop root");
227 exit(EXIT_FAILURE); 227 exit(EXIT_FAILURE);
228 } 228 }
229 if (setuid(getuid()) != 0) { 229 if (setuid(getuid()) != 0) {
230 wlr_log(L_ERROR, "Unable to drop root"); 230 wlr_log(WLR_ERROR, "Unable to drop root");
231 exit(EXIT_FAILURE); 231 exit(EXIT_FAILURE);
232 } 232 }
233 } 233 }
234 if (setuid(0) != -1) { 234 if (setuid(0) != -1) {
235 wlr_log(L_ERROR, "Root privileges can be restored."); 235 wlr_log(WLR_ERROR, "Root privileges can be restored.");
236 exit(EXIT_FAILURE); 236 exit(EXIT_FAILURE);
237 } 237 }
238#ifdef __linux__ 238#ifdef __linux__
@@ -240,11 +240,11 @@ static void drop_permissions(bool keep_caps) {
240 // Drop every cap except CAP_SYS_PTRACE 240 // Drop every cap except CAP_SYS_PTRACE
241 cap_t caps = cap_init(); 241 cap_t caps = cap_init();
242 cap_value_t keep = CAP_SYS_PTRACE; 242 cap_value_t keep = CAP_SYS_PTRACE;
243 wlr_log(L_INFO, "Dropping extra capabilities"); 243 wlr_log(WLR_INFO, "Dropping extra capabilities");
244 if (cap_set_flag(caps, CAP_PERMITTED, 1, &keep, CAP_SET) || 244 if (cap_set_flag(caps, CAP_PERMITTED, 1, &keep, CAP_SET) ||
245 cap_set_flag(caps, CAP_EFFECTIVE, 1, &keep, CAP_SET) || 245 cap_set_flag(caps, CAP_EFFECTIVE, 1, &keep, CAP_SET) ||
246 cap_set_proc(caps)) { 246 cap_set_proc(caps)) {
247 wlr_log(L_ERROR, "Failed to drop extra capabilities"); 247 wlr_log(WLR_ERROR, "Failed to drop extra capabilities");
248 exit(EXIT_FAILURE); 248 exit(EXIT_FAILURE);
249 } 249 }
250 } 250 }
@@ -335,22 +335,22 @@ int main(int argc, char **argv) {
335 335
336 // TODO: switch logging over to wlroots? 336 // TODO: switch logging over to wlroots?
337 if (debug) { 337 if (debug) {
338 wlr_log_init(L_DEBUG, NULL); 338 wlr_log_init(WLR_DEBUG, NULL);
339 } else if (verbose || validate) { 339 } else if (verbose || validate) {
340 wlr_log_init(L_INFO, NULL); 340 wlr_log_init(WLR_INFO, NULL);
341 } else { 341 } else {
342 wlr_log_init(L_ERROR, NULL); 342 wlr_log_init(WLR_ERROR, NULL);
343 } 343 }
344 344
345 if (optind < argc) { // Behave as IPC client 345 if (optind < argc) { // Behave as IPC client
346 if(optind != 1) { 346 if(optind != 1) {
347 wlr_log(L_ERROR, "Don't use options with the IPC client"); 347 wlr_log(WLR_ERROR, "Don't use options with the IPC client");
348 exit(EXIT_FAILURE); 348 exit(EXIT_FAILURE);
349 } 349 }
350 drop_permissions(false); 350 drop_permissions(false);
351 char *socket_path = getenv("SWAYSOCK"); 351 char *socket_path = getenv("SWAYSOCK");
352 if (!socket_path) { 352 if (!socket_path) {
353 wlr_log(L_ERROR, "Unable to retrieve socket path"); 353 wlr_log(WLR_ERROR, "Unable to retrieve socket path");
354 exit(EXIT_FAILURE); 354 exit(EXIT_FAILURE);
355 } 355 }
356 char *command = join_args(argv + optind, argc - optind); 356 char *command = join_args(argv + optind, argc - optind);
@@ -369,7 +369,7 @@ int main(int argc, char **argv) {
369 if (getuid() != geteuid() || getgid() != getegid()) { 369 if (getuid() != geteuid() || getgid() != getegid()) {
370 // Retain capabilities after setuid() 370 // Retain capabilities after setuid()
371 if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { 371 if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
372 wlr_log(L_ERROR, "Cannot keep caps after setuid()"); 372 wlr_log(WLR_ERROR, "Cannot keep caps after setuid()");
373 exit(EXIT_FAILURE); 373 exit(EXIT_FAILURE);
374 } 374 }
375 suid = true; 375 suid = true;
@@ -390,7 +390,7 @@ int main(int argc, char **argv) {
390 // prevent ipc from crashing sway 390 // prevent ipc from crashing sway
391 signal(SIGPIPE, SIG_IGN); 391 signal(SIGPIPE, SIG_IGN);
392 392
393 wlr_log(L_INFO, "Starting sway version " SWAY_VERSION); 393 wlr_log(WLR_INFO, "Starting sway version " SWAY_VERSION);
394 394
395 layout_init(); 395 layout_init();
396 396
@@ -423,7 +423,7 @@ int main(int argc, char **argv) {
423 char *line = config->cmd_queue->items[0]; 423 char *line = config->cmd_queue->items[0];
424 struct cmd_results *res = execute_command(line, NULL); 424 struct cmd_results *res = execute_command(line, NULL);
425 if (res->status != CMD_SUCCESS) { 425 if (res->status != CMD_SUCCESS) {
426 wlr_log(L_ERROR, "Error on line '%s': %s", line, res->error); 426 wlr_log(WLR_ERROR, "Error on line '%s': %s", line, res->error);
427 } 427 }
428 free_cmd_results(res); 428 free_cmd_results(res);
429 free(line); 429 free(line);
@@ -434,7 +434,7 @@ int main(int argc, char **argv) {
434 server_run(&server); 434 server_run(&server);
435 } 435 }
436 436
437 wlr_log(L_INFO, "Shutting down sway"); 437 wlr_log(WLR_INFO, "Shutting down sway");
438 438
439 server_fini(&server); 439 server_fini(&server);
440 440