- if (getuid() == 0) {
- if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
- std::cout << "Running Dolphin with sudo is not supported as it can cause bugs and expose you to security vulnerabilities. Instead, install the "
- "`kio-admin` package from your distro and use it to manage root-owned locations by right-clicking on them and selecting \"Open as "
- "Administrator\"."
- << std::endl;
- return EXIT_FAILURE;
- } else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
- std::cout << "Running Dolphin with kdesu is not supported as it can cause bugs and expose you to security vulnerabilities. Instead, install the "
- "`kio-admin` package from your distro and use it to manage root-owned locations by right-clicking on them and selecting \"Open as "
- "Administrator\"."
- << std::endl;
- return EXIT_FAILURE;
- }
+ if (getuid() == 0 && (!qEnvironmentVariableIsEmpty("SUDO_USER") || !qEnvironmentVariableIsEmpty("KDESU_USER"))) {
+ QCoreApplication app(argc, argv); // Needed for the xi18ndc() call below.
+ std::cout << qPrintable(
+ xi18ndc(dolphinTranslationDomain,
+ "@info:shell %1 is a terminal command",
+ "Running <application>Dolphin</application> with <command>sudo</command> is discouraged. Please run <icode>%1</icode> instead.",
+ QStringLiteral("dolphin --sudo")))
+ << std::endl;
+ // We could perform a privilege de-escalation here and continue as normal. It is a bit safer though to simply let the user restart without sudo.
+ return EXIT_FAILURE;