summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-05-19 19:28:15 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-05-19 19:28:15 +0200
commit146b189d54e51609634d9dc4b1ab47f9e3c91d49 (patch)
tree46736322d00b6798c1e9458278cf6c53d23dad10 /src
parent36be9c4a11833dfceea8a2edeee0087d2f1620b1 (diff)
disallow running with sudo
unless you use the --i-am-really-stupid flag
Diffstat (limited to 'src')
-rw-r--r--src/init/initHelpers.cpp5
-rw-r--r--src/init/initHelpers.hpp7
-rw-r--r--src/main.cpp21
3 files changed, 33 insertions, 0 deletions
diff --git a/src/init/initHelpers.cpp b/src/init/initHelpers.cpp
new file mode 100644
index 00000000..dc51650a
--- /dev/null
+++ b/src/init/initHelpers.cpp
@@ -0,0 +1,5 @@
+#include "initHelpers.hpp"
+
+bool Init::isSudo() {
+ return getuid() != geteuid() || !geteuid();
+}
diff --git a/src/init/initHelpers.hpp b/src/init/initHelpers.hpp
new file mode 100644
index 00000000..3b9f7915
--- /dev/null
+++ b/src/init/initHelpers.hpp
@@ -0,0 +1,7 @@
+#pragma once
+
+#include "../defines.hpp"
+
+namespace Init {
+ bool isSudo();
+}; \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 7cbef959..cdad06e7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,12 +2,33 @@
#include "debug/Log.hpp"
#include "Compositor.hpp"
#include "config/ConfigManager.hpp"
+#include "init/initHelpers.hpp"
+
+// I am a bad bad boy and have used some global vars here,
+// just for this file
+bool ignoreSudo = false;
int main(int argc, char** argv) {
if (!getenv("XDG_RUNTIME_DIR"))
RIP("XDG_RUNTIME_DIR not set!");
+ // parse some args
+ for (int i = 1; i < argc; ++i) {
+ if (!strcmp(argv[i], "--i-am-really-stupid"))
+ ignoreSudo = true;
+ }
+
+ if (!ignoreSudo) {
+ if (Init::isSudo()) {
+ Debug::log(CRIT, "Hyprland shall not be run as the root user. If you really want to, use the --i-am-really-stupid flag.");
+ return 1;
+ }
+ } else {
+ Debug::log(WARN, "Running with ignored root checks, I surely hope you know what you're doing.");
+ sleep(1);
+ }
+
Debug::log(LOG, "Welcome to Hyprland!");
// let's init the compositor.