diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,28 @@ m_messageWidget->setCloseButtonVisible(true); m_messageWidget->hide(); +#ifndef Q_OS_WIN + QProcessEnvironment system_env = QProcessEnvironment::systemEnvironment(); + + // If running as root, show a big scary warning + if (system_env.value("USER") == QStringLiteral("root") && + system_env.value("SUDO_USER") == QStringLiteral("root")) { + showErrorMessage(i18n("Running Dolphin as root can be dangerous. Please be careful.")); + } + // If running with sudo, inform the user that this isn't necessary + else if (system_env.value("USER") == QStringLiteral("root") && + ! system_env.value("SUDO_USER").isEmpty()) { + /* TODO: change this message to instead encourage people to run with normal + * permissions for their system-file-and-other-user-file-management needs + * once PolicyKit support is added to KIO and enabled: + * - https://bugs.kde.org/show_bug.cgi?id=179678 + * - https://phabricator.kde.org/T6561 + * - https://phabricator.kde.org/T8075 + */ + showErrorMessage(i18n("Running Dolphin using `sudo` can be dangerous and may expose you to security risks.")); + } +#endif + m_view = new DolphinView(url, this); connect(m_view, &DolphinView::urlChanged, m_urlNavigator, &KUrlNavigator::setLocationUrl); diff --git a/src/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -35,21 +35,8 @@ #include #include -#ifndef Q_OS_WIN -#include -#endif -#include - extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv) { -#ifndef Q_OS_WIN - // Check whether we are running as root - if (getuid() == 0) { - std::cout << "Executing Dolphin as root is not possible." << std::endl; - return EXIT_FAILURE; - } -#endif - QApplication app(argc, argv); app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); app.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app.windowIcon()));