2006-11-21 06:02:05 +00:00
|
|
|
/***************************************************************************
|
2011-02-04 14:57:33 +00:00
|
|
|
* Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
|
2006-11-21 06:02:05 +00:00
|
|
|
* Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
|
2015-02-04 09:22:03 +00:00
|
|
|
* Copyright (C) 2015 by Mathieu Tarral <mathieu.tarral@gmail.com> *
|
2006-11-21 06:02:05 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
2006-12-08 21:24:08 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
2006-11-21 06:02:05 +00:00
|
|
|
***************************************************************************/
|
|
|
|
|
2018-03-04 13:38:16 +00:00
|
|
|
#include "dbusinterface.h"
|
|
|
|
#include "dolphin_generalsettings.h"
|
2015-07-29 20:54:54 +00:00
|
|
|
#include "dolphin_version.h"
|
2018-03-04 13:38:16 +00:00
|
|
|
#include "dolphindebug.h"
|
2007-09-27 12:36:40 +00:00
|
|
|
#include "dolphinmainwindow.h"
|
2015-04-22 13:29:39 +00:00
|
|
|
#include "global.h"
|
2007-09-27 12:36:40 +00:00
|
|
|
|
2015-02-04 09:22:03 +00:00
|
|
|
#include <KAboutData>
|
2015-11-14 21:37:40 +00:00
|
|
|
#include <KCrash>
|
2018-03-04 13:38:16 +00:00
|
|
|
#include <KDBusService>
|
2014-10-18 12:42:41 +00:00
|
|
|
#include <KLocalizedString>
|
2015-04-27 11:01:18 +00:00
|
|
|
#include <Kdelibs4ConfigMigrator>
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2018-03-04 13:38:16 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
|
2017-02-19 01:32:48 +00:00
|
|
|
#ifndef Q_OS_WIN
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <iostream>
|
|
|
|
|
2014-11-08 21:50:38 +00:00
|
|
|
extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
2017-02-19 01:32:48 +00:00
|
|
|
#ifndef Q_OS_WIN
|
Re-allow running Dolphin as the root user (but still not using sudo)
Summary:
Prohibiting the use of Dolphin as the actual root user (not using `sudo` or `kdesu`) breaks legitimate use cases for using the root user. An example is Kali, a distro that logs in as the root user by default as a deliberate design choice.
In such an environment, there is no additional security vulnerability beyond what you're already potentially exposing yourself to. So, let's re-enable it.
BUG: 387974
FIXED-IN: 18.08.0
Test Plan:
- Log in as normal user and run `sudo dolphin`: you get an error message.
- Log in as normal user and run `kdesu dolphin`: you get an error message.
- Log in as the root user and run dolphin normally: it works.
Reviewers: markg, elvisangelaccio, #dolphin
Reviewed By: markg
Subscribers: chinmoyr, cfeck, elvisangelaccio, mmustac, Fuchs, markg, graesslin, nicolasfella, zzag, kfm-devel, emmanuelp
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D12795
2018-05-09 23:18:08 +00:00
|
|
|
// Prohibit using sudo or kdesu (but allow using the root user directly)
|
2017-02-19 01:32:48 +00:00
|
|
|
if (getuid() == 0) {
|
Re-allow running Dolphin as the root user (but still not using sudo)
Summary:
Prohibiting the use of Dolphin as the actual root user (not using `sudo` or `kdesu`) breaks legitimate use cases for using the root user. An example is Kali, a distro that logs in as the root user by default as a deliberate design choice.
In such an environment, there is no additional security vulnerability beyond what you're already potentially exposing yourself to. So, let's re-enable it.
BUG: 387974
FIXED-IN: 18.08.0
Test Plan:
- Log in as normal user and run `sudo dolphin`: you get an error message.
- Log in as normal user and run `kdesu dolphin`: you get an error message.
- Log in as the root user and run dolphin normally: it works.
Reviewers: markg, elvisangelaccio, #dolphin
Reviewed By: markg
Subscribers: chinmoyr, cfeck, elvisangelaccio, mmustac, Fuchs, markg, graesslin, nicolasfella, zzag, kfm-devel, emmanuelp
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D12795
2018-05-09 23:18:08 +00:00
|
|
|
if (!qEnvironmentVariableIsEmpty("SUDO_USER")) {
|
|
|
|
std::cout << "Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities." << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
} else if (!qEnvironmentVariableIsEmpty("KDESU_USER")) {
|
|
|
|
std::cout << "Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities." << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2017-02-19 01:32:48 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-04 09:22:03 +00:00
|
|
|
QApplication app(argc, argv);
|
2015-03-25 11:38:02 +00:00
|
|
|
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
2016-11-22 16:55:34 +00:00
|
|
|
app.setWindowIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"), app.windowIcon()));
|
2015-04-27 11:01:18 +00:00
|
|
|
|
2015-11-14 21:37:40 +00:00
|
|
|
KCrash::initialize();
|
|
|
|
|
2015-02-06 08:32:39 +00:00
|
|
|
Kdelibs4ConfigMigrator migrate(QStringLiteral("dolphin"));
|
|
|
|
migrate.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
|
|
|
|
migrate.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
|
|
|
|
migrate.migrate();
|
|
|
|
|
2015-11-29 18:19:33 +00:00
|
|
|
KLocalizedString::setApplicationDomain("dolphin");
|
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
KAboutData aboutData(QStringLiteral("dolphin"), i18n("Dolphin"), QStringLiteral(DOLPHIN_VERSION_STRING),
|
2015-02-04 09:22:03 +00:00
|
|
|
i18nc("@title", "File Manager"),
|
|
|
|
KAboutLicense::GPL,
|
2016-01-14 19:45:49 +00:00
|
|
|
i18nc("@info:credit", "(C) 2006-2016 Peter Penz, Frank Reininghaus, and Emmanuel Pescosta"));
|
2016-03-16 21:17:37 +00:00
|
|
|
aboutData.setHomepage(QStringLiteral("http://dolphin.kde.org"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Emmanuel Pescosta"),
|
|
|
|
i18nc("@info:credit", "Maintainer (since 2014) and developer"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("emmanuelpescosta099@gmail.com"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Frank Reininghaus"),
|
|
|
|
i18nc("@info:credit", "Maintainer (2012-2014) and developer"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("frank78ac@googlemail.com"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Peter Penz"),
|
|
|
|
i18nc("@info:credit", "Maintainer and developer (2006-2012)"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("peter.penz19@gmail.com"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Sebastian Trüg"),
|
|
|
|
i18nc("@info:credit", "Developer"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("trueg@kde.org"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "David Faure"),
|
|
|
|
i18nc("@info:credit", "Developer"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("faure@kde.org"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Aaron J. Seigo"),
|
|
|
|
i18nc("@info:credit", "Developer"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("aseigo@kde.org"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Rafael Fernández López"),
|
|
|
|
i18nc("@info:credit", "Developer"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("ereslibre@kde.org"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Kevin Ottens"),
|
|
|
|
i18nc("@info:credit", "Developer"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("ervin@kde.org"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Holger Freyther"),
|
|
|
|
i18nc("@info:credit", "Developer"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("freyther@gmx.net"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Max Blazejak"),
|
|
|
|
i18nc("@info:credit", "Developer"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("m43ksrocks@gmail.com"));
|
2015-02-04 09:22:03 +00:00
|
|
|
aboutData.addAuthor(i18nc("@info:credit", "Michael Austin"),
|
|
|
|
i18nc("@info:credit", "Documentation"),
|
2016-03-16 21:17:37 +00:00
|
|
|
QStringLiteral("tuxedup@users.sourceforge.net"));
|
2015-02-04 09:22:03 +00:00
|
|
|
|
|
|
|
KAboutData::setApplicationData(aboutData);
|
|
|
|
|
2015-02-04 09:29:33 +00:00
|
|
|
KDBusService dolphinDBusService;
|
2015-04-22 13:29:39 +00:00
|
|
|
DBusInterface interface;
|
2015-02-04 09:29:33 +00:00
|
|
|
|
2015-02-04 09:22:03 +00:00
|
|
|
QCommandLineParser parser;
|
|
|
|
aboutData.setupCommandLine(&parser);
|
|
|
|
|
|
|
|
// command line options
|
2016-05-05 11:43:02 +00:00
|
|
|
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("select"), i18nc("@info:shell", "The files and folders passed as arguments "
|
2015-02-04 09:22:03 +00:00
|
|
|
"will be selected.")));
|
2016-03-16 21:17:37 +00:00
|
|
|
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("split"), i18nc("@info:shell", "Dolphin will get started with a split view.")));
|
|
|
|
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("daemon"), i18nc("@info:shell", "Start Dolphin Daemon (only required for DBus Interface)")));
|
|
|
|
parser.addPositionalArgument(QStringLiteral("+[Url]"), i18nc("@info:shell", "Document to open"));
|
2015-02-04 09:22:03 +00:00
|
|
|
|
|
|
|
parser.process(app);
|
|
|
|
aboutData.processCommandLine(&parser);
|
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
if (parser.isSet(QStringLiteral("daemon"))) {
|
2015-04-22 13:29:39 +00:00
|
|
|
return app.exec();
|
|
|
|
}
|
2015-02-04 09:22:03 +00:00
|
|
|
|
|
|
|
const QStringList args = parser.positionalArguments();
|
2015-04-22 13:29:39 +00:00
|
|
|
QList<QUrl> urls = Dolphin::validateUris(args);
|
2015-02-04 09:22:03 +00:00
|
|
|
|
2015-04-27 10:55:53 +00:00
|
|
|
if (urls.isEmpty()) {
|
|
|
|
// We need at least one URL to open Dolphin
|
2015-10-10 13:09:48 +00:00
|
|
|
urls.append(Dolphin::homeUrl());
|
2015-02-04 09:22:03 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
const bool splitView = parser.isSet(QStringLiteral("split")) || GeneralSettings::splitView();
|
2015-04-27 10:55:53 +00:00
|
|
|
if (splitView && urls.size() < 2) {
|
|
|
|
// Split view does only make sense if we have at least 2 URLs
|
|
|
|
urls.append(urls.last());
|
2015-02-04 09:22:03 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 11:01:18 +00:00
|
|
|
DolphinMainWindow* mainWindow = new DolphinMainWindow();
|
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
if (parser.isSet(QStringLiteral("select"))) {
|
2015-04-27 11:01:18 +00:00
|
|
|
mainWindow->openFiles(urls, splitView);
|
2015-04-27 10:55:53 +00:00
|
|
|
} else {
|
2015-04-27 11:01:18 +00:00
|
|
|
mainWindow->openDirectories(urls, splitView);
|
2015-02-04 09:22:03 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 11:01:18 +00:00
|
|
|
mainWindow->show();
|
2015-02-04 09:22:03 +00:00
|
|
|
|
|
|
|
if (app.isSessionRestored()) {
|
|
|
|
const QString className = KXmlGuiWindow::classNameOfToplevel(1);
|
|
|
|
if (className == QLatin1String("DolphinMainWindow")) {
|
2015-04-27 11:01:18 +00:00
|
|
|
mainWindow->restore(1);
|
2015-02-04 09:22:03 +00:00
|
|
|
} else {
|
2015-02-24 16:07:55 +00:00
|
|
|
qCWarning(DolphinDebug) << "Unknown class " << className << " in session saved data!";
|
2012-12-05 20:44:06 +00:00
|
|
|
}
|
2007-04-09 19:12:54 +00:00
|
|
|
}
|
2007-09-27 12:36:40 +00:00
|
|
|
|
2015-02-04 09:22:03 +00:00
|
|
|
return app.exec(); // krazy:exclude=crash;
|
2007-09-27 12:36:40 +00:00
|
|
|
}
|