Skip to content
Merged
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
41 changes: 41 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,29 @@
#include <util/utils.h>
#include <QDebug>
#include <DLog>
#include <DApplication>

Check warning on line 14 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 14 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DWidgetUtil>

Check warning on line 15 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DWidgetUtil> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 15 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DWidgetUtil> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DGuiApplicationHelper>

Check warning on line 16 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DGuiApplicationHelper> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 16 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DGuiApplicationHelper> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusConnection>

Check warning on line 17 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusConnection> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 17 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDBusConnection> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <DApplicationSettings>
#endif

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#if defined (Q_OS_LINUX)
#include <polkit-qt5-1/PolkitQt1/Authority>
#include <polkit-qt5-1/PolkitQt1/Subject>
#endif
#else
#if defined (Q_OS_LINUX)
#include <polkit-qt6-1/PolkitQt1/Authority>

Check warning on line 30 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <polkit-qt6-1/PolkitQt1/Authority> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 30 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <polkit-qt6-1/PolkitQt1/Authority> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <polkit-qt6-1/PolkitQt1/Subject>

Check warning on line 31 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <polkit-qt6-1/PolkitQt1/Subject> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 31 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <polkit-qt6-1/PolkitQt1/Subject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif
#endif

const QString s_PolkitActionCreate = "com.deepin.bootmaker.create";


DCORE_USE_NAMESPACE
DWIDGET_USE_NAMESPACE
Expand Down Expand Up @@ -53,6 +68,27 @@

#endif

// 在前端中预先进行身份验证, 便于流程控制
static bool checkAuthorization()
{
#if defined (Q_OS_LINUX)
QString busName = QDBusConnection::systemBus().baseService();
auto authority = PolkitQt1::Authority::instance();
if (!authority) {
qWarning() << "Failed to get Polkit authority instance";
return false;
}
PolkitQt1::Authority::Result ret = authority->checkAuthorizationSync(
s_PolkitActionCreate,
PolkitQt1::SystemBusNameSubject(busName),
PolkitQt1::Authority::AllowUserInteraction);

return PolkitQt1::Authority::Yes == ret;
#else
return true;
#endif
}

int main(int argc, char **argv)
{
qInfo() << "Starting Boot Maker application";
Expand All @@ -78,6 +114,11 @@
// app.setApplicationVersion(DApplication::buildVersion(VERSION));
// app.setTheme("light");

if (!checkAuthorization()) {

Check warning on line 117 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition '!checkAuthorization()' is always false

Check warning on line 117 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Condition '!checkAuthorization()' is always false
qInfo() << "Authorization failed, exiting";
exit(0);
}

#ifdef Q_OS_MAC
qDebug() << "Checking root privileges on macOS";
if (switchToRoot(app)) {
Expand Down
8 changes: 7 additions & 1 deletion src/service/bootmakerservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ void BootMakerService::Reboot()

void BootMakerService::Start()
{
// 启动服务, 不会修改系统, 不需要鉴权
Q_D(BootMakerService);
qInfo() << "Start requested";
if (!d->checkAuthorization(s_PolkitActionCreate)) {
qWarning() << "Start request denied - Authorization failed";
return;
}

qDebug() << "Starting Boot Maker";
emit s_StartBootMarker();
}
Expand Down
Loading