aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/sway/config.c b/sway/config.c
index 88e6fad1..f46ce882 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -1,3 +1,5 @@
1#define _POSIX_C_SOURCE 200809L
2#define _XOPEN_SOURCE 500
1#include <stdio.h> 3#include <stdio.h>
2#include <stdbool.h> 4#include <stdbool.h>
3#include <stdlib.h> 5#include <stdlib.h>
@@ -12,6 +14,7 @@
12#include <limits.h> 14#include <limits.h>
13#include <float.h> 15#include <float.h>
14#include <dirent.h> 16#include <dirent.h>
17#include <strings.h>
15#include "wayland-desktop-shell-server-protocol.h" 18#include "wayland-desktop-shell-server-protocol.h"
16#include "sway/commands.h" 19#include "sway/commands.h"
17#include "sway/config.h" 20#include "sway/config.h"
@@ -487,7 +490,7 @@ static bool load_config(const char *path, struct sway_config *config) {
487} 490}
488 491
489static int qstrcmp(const void* a, const void* b) { 492static int qstrcmp(const void* a, const void* b) {
490 return strcmp(*((char**) a), *((char**) b)); 493 return strcmp(*((char**) a), *((char**) b));
491} 494}
492 495
493bool load_main_config(const char *file, bool is_active) { 496bool load_main_config(const char *file, bool is_active) {
@@ -528,11 +531,13 @@ bool load_main_config(const char *file, bool is_active) {
528 list_t *secconfigs = create_list(); 531 list_t *secconfigs = create_list();
529 char *base = SYSCONFDIR "/sway/security.d/"; 532 char *base = SYSCONFDIR "/sway/security.d/";
530 struct dirent *ent = readdir(dir); 533 struct dirent *ent = readdir(dir);
534 struct stat s;
531 while (ent != NULL) { 535 while (ent != NULL) {
532 if (ent->d_type == DT_REG) { 536 char *_path = malloc(strlen(ent->d_name) + strlen(base) + 1);
533 char *_path = malloc(strlen(ent->d_name) + strlen(base) + 1); 537 strcpy(_path, base);
534 strcpy(_path, base); 538 strcat(_path, ent->d_name);
535 strcat(_path, ent->d_name); 539 lstat(_path, &s);
540 if (S_ISREG(s.st_mode)) {
536 list_add(secconfigs, _path); 541 list_add(secconfigs, _path);
537 } 542 }
538 ent = readdir(dir); 543 ent = readdir(dir);
@@ -542,7 +547,6 @@ bool load_main_config(const char *file, bool is_active) {
542 list_qsort(secconfigs, qstrcmp); 547 list_qsort(secconfigs, qstrcmp);
543 for (int i = 0; i < secconfigs->length; ++i) { 548 for (int i = 0; i < secconfigs->length; ++i) {
544 char *_path = secconfigs->items[i]; 549 char *_path = secconfigs->items[i];
545 struct stat s;
546 if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (s.st_mode & 0777) != 0644) { 550 if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (s.st_mode & 0777) != 0644) {
547 sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644", _path); 551 sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644", _path);
548 success = false; 552 success = false;