Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ endif()

if(UNIX AND NOT APPLE)
set(OMI_HEADERS ${OMI_HEADERS}
linux/platform_lin_suprogram.h
linux/usbdevicemonitor_lin_p.h
)

set(OMI_SOURCES ${OMI_SOURCES}
linux/externalprogressbar_lin.cpp
linux/platform_lin.cpp
linux/platform_lin_suprogram.cpp
linux/usbdevicemonitor_lin.cpp
)

Expand All @@ -96,6 +94,11 @@ if(UNIX AND NOT APPLE)
RENAME
om-imagewriter.svg
)

install(FILES ${CMAKE_SOURCE_DIR}/src/linux/udev_rules/71-usb-storage.rules
DESTINATION
lib/udev/rules.d
)
endif()

qt_add_executable(om-imagewriter
Expand Down
76 changes: 0 additions & 76 deletions src/linux/platform_lin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <QDir>
#include <QRegularExpression>

#include "platform_lin_suprogram.h"
#include "../mainapplication.h"
#include "../usbdevice.h"

Expand Down Expand Up @@ -110,78 +109,3 @@ bool platformEnumFlashDevices(AddFlashDeviceCallbackProc callback, void* cbParam
return true;
}

bool ensureElevated()
{
// If we already have root privileges do nothing
uid_t uid = getuid();
if (uid == 0)
return true;

// Search for known GUI su-applications.
// The list is priority-ordered. If there are native su-applications present,
// using the first such program. Otherwise, using just the first program that is present.
QList<SuProgram*> suPrograms = { new XdgSu(), new BeeSu(), new KdeSu(), new GkSu() };
SuProgram* suProgram = NULL;
for (int i = 0; i < suPrograms.size(); ++i)
{
// Skip missing su-apps
if (!suPrograms[i]->isPresent())
continue;

if (suPrograms[i]->isNative())
{
// If we found a native su-application - using it as preferred and stop searching
suProgram = suPrograms[i];
break;
}
else
{
// If not native, and no other su-application was found - using it, but continue searching,
// in case a native app will appear down the list
if (suProgram == NULL)
suProgram = suPrograms[i];
}
}
if (suProgram == NULL)
{
QMessageBox::critical(
NULL,
ApplicationTitle,
"<font color=\"red\">" + QObject::tr("Error!") + "</font> " + QObject::tr("No appropriate su-application found!") + "<br>" +
QObject::tr("Please, restart the program with root privileges."),
QMessageBox::Ok
);
return false;
}

// Prepare the list of arguments and restart ourselves using the su-application found
QStringList args;
// First comes our own executable
args << mApp->applicationFilePath();
// We need to explicitly pass language and initial directory so that the new instance
// inherited the current user's parameters rather than root's
QString argLang = mApp->getLocale();
if (!argLang.isEmpty())
args << "--lang=" + argLang;
QString argDir = mApp->getInitialDir();
if (!argDir.isEmpty())
args << "--dir=" + argDir;
// Finally, if image file was supplied, append it as well
QString argImage = mApp->getInitialImage();
if (!argImage.isEmpty())
args << argImage;
// And now try to take off with all this garbage
suProgram->restartAsRoot(args);

// Something went wrong, we should have never returned! Cleanup and return error
for (int i = 0; i < suPrograms.size(); ++i)
delete suPrograms[i];
QMessageBox::critical(
NULL,
ApplicationTitle,
"<font color=\"red\">" + QObject::tr("Error!") + "</font> " + QObject::tr("Failed to restart with root privileges! (Error code: %1)").arg(errno) + "<br>" +
QObject::tr("Please, restart the program with root privileges."),
QMessageBox::Ok
);
return false;
}
155 changes: 0 additions & 155 deletions src/linux/platform_lin_suprogram.cpp

This file was deleted.

73 changes: 0 additions & 73 deletions src/linux/platform_lin_suprogram.h

This file was deleted.

1 change: 1 addition & 0 deletions src/linux/udev_rules/71-usb-storage.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KERNEL=="sd*", SUBSYSTEMS=="usb", MODE="0660", TAG+="uaccess"
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ int main(int argc, char *argv[])
appTranslator.load(langName, QCoreApplication::applicationDirPath() + "/lang");
a.installTranslator(&appTranslator);

#if defined(Q_OS_MAC) || defined(Q_OS_WIN32)
if (!ensureElevated())
return 1;
#endif

#if defined(Q_OS_WIN32)
// CoInitialize() seems to be called by Qt automatically, so only set security attributes
Expand Down
17 changes: 6 additions & 11 deletions src/mainapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ QString MainApplication::getInitialDir()
// win:restricted
// win:admin
// mac:restricted
// linux:restricted
// linux:root
// linux: translated dir names
// linux: should be using udev rules with MODE="0660", TAG+="uaccess"
// win: redefined paths
if (m_Options.isSet("dir"))
if (m_Options.isSet("dir")) {
return m_Options.value("dir");

// Otherwise get the standard system Downloads location
QStringList downloadDirs = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation);
if (downloadDirs.size() > 0)
return downloadDirs.at(0);
else
return "";
} else {
// Otherwise get the standard system Downloads location
return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
}
}

// Returns the fila path passed to the application as command-line parameter
Expand Down