diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-06-14 18:53:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-14 18:53:40 -0400 |
commit | 298f56353ef155f6a2ccc977c96b2ff5d971e65e (patch) | |
tree | dcb3b74f1dde93bce8657b7509662ffd7db667d0 /sway/main.c | |
parent | a5c07dde6aba87584ddb6c6a2769472a6003623a (diff) | |
parent | eb6e38c86d2deb37cc6f378f8644c4a530fd7448 (diff) |
Merge branch 'master' into server-decoration
Diffstat (limited to 'sway/main.c')
-rw-r--r-- | sway/main.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/sway/main.c b/sway/main.c index b9549b12..82375e0b 100644 --- a/sway/main.c +++ b/sway/main.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200112L #include <stdio.h> #include <stdlib.h> @@ -27,6 +27,7 @@ #include "stringop.h" #include "sway.h" #include "log.h" +#include "util.h" static bool terminate_request = false; static int exit_value = 0; @@ -209,6 +210,27 @@ static void security_sanity_check() { #endif } +static void executable_sanity_check() { +#ifdef __linux__ + struct stat sb; + char *exe = realpath("/proc/self/exe", NULL); + stat(exe, &sb); + // We assume that cap_get_file returning NULL implies ENODATA + if (sb.st_mode & (S_ISUID|S_ISGID) && cap_get_file(exe)) { + sway_log(L_ERROR, + "sway executable has both the s(g)uid bit AND file caps set."); + sway_log(L_ERROR, + "This is strongly discouraged (and completely broken)."); + sway_log(L_ERROR, + "Please clear one of them (either the suid bit, or the file caps)."); + sway_log(L_ERROR, + "If unsure, strip the file caps."); + exit(EXIT_FAILURE); + } + free(exe); +#endif +} + int main(int argc, char **argv) { static int verbose = 0, debug = 0, validate = 0; @@ -288,6 +310,15 @@ int main(int argc, char **argv) { } } + // we need to setup logging before wlc_init in case it fails. + if (debug) { + init_log(L_DEBUG); + } else if (verbose || validate) { + init_log(L_INFO); + } else { + init_log(L_ERROR); + } + if (optind < argc) { // Behave as IPC client if(optind != 1) { sway_log(L_ERROR, "Don't use options with the IPC client"); @@ -317,6 +348,7 @@ int main(int argc, char **argv) { return 0; } + executable_sanity_check(); #ifdef __linux__ bool suid = false; if (getuid() != geteuid() || getgid() != getegid()) { @@ -329,14 +361,6 @@ int main(int argc, char **argv) { } #endif - // we need to setup logging before wlc_init in case it fails. - if (debug) { - init_log(L_DEBUG); - } else if (verbose || validate) { - init_log(L_INFO); - } else { - init_log(L_ERROR); - } wlc_log_set_handler(wlc_log_handler); log_kernel(); log_distro(); @@ -409,4 +433,3 @@ int main(int argc, char **argv) { return exit_value; } - |