mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 15:05:59 +01:00
disallow running with sudo
unless you use the --i-am-really-stupid flag
This commit is contained in:
parent
36be9c4a11
commit
146b189d54
3 changed files with 33 additions and 0 deletions
5
src/init/initHelpers.cpp
Normal file
5
src/init/initHelpers.cpp
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#include "initHelpers.hpp"
|
||||||
|
|
||||||
|
bool Init::isSudo() {
|
||||||
|
return getuid() != geteuid() || !geteuid();
|
||||||
|
}
|
7
src/init/initHelpers.hpp
Normal file
7
src/init/initHelpers.hpp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../defines.hpp"
|
||||||
|
|
||||||
|
namespace Init {
|
||||||
|
bool isSudo();
|
||||||
|
};
|
21
src/main.cpp
21
src/main.cpp
|
@ -2,12 +2,33 @@
|
||||||
#include "debug/Log.hpp"
|
#include "debug/Log.hpp"
|
||||||
#include "Compositor.hpp"
|
#include "Compositor.hpp"
|
||||||
#include "config/ConfigManager.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) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
if (!getenv("XDG_RUNTIME_DIR"))
|
if (!getenv("XDG_RUNTIME_DIR"))
|
||||||
RIP("XDG_RUNTIME_DIR not set!");
|
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!");
|
Debug::log(LOG, "Welcome to Hyprland!");
|
||||||
|
|
||||||
// let's init the compositor.
|
// let's init the compositor.
|
||||||
|
|
Loading…
Reference in a new issue