Skip to content

Commit

Permalink
Remove KAuth support
Browse files Browse the repository at this point in the history
The new previlige handling will call perf directly without a helper, so
KAuth does not make sense for that anymore.
  • Loading branch information
zeno-endemann-kdab authored and milianw committed Jul 21, 2023
1 parent 2244bb8 commit 5a6280b
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 186 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ find_package(
)

find_package(KF5Archive 5.85.0 CONFIG)
find_package(KF5Auth CONFIG)
find_package(KF5SyntaxHighlighting CONFIG)
find_package(KDDockWidgets CONFIG)
set_package_properties(
Expand Down
2 changes: 0 additions & 2 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ As of now, you will need the following dependencies to build this project:
- iconthemes
- parts
- archive (optional)
- kauth (optional)
- [KDDockWidgets](https://github.com/KDAB/KDDockWidgets)
- this library is not yet packaged on most distributions, you'll have to compile it yourself from source

Expand Down Expand Up @@ -124,7 +123,6 @@ make
# or `make install` it and launch it from your $PATH
```

If you want to use KAuth, you need to add `-DCMAKE_INSTALL_PREFIX=/usr/` to the cmake call. Otherwise KAuth won't work.
If you need help building this project for your platform, [contact us for help](https://www.kdab.com/about/contact/).

## Debugging the AppImage
Expand Down
2 changes: 0 additions & 2 deletions hotspot-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#cmakedefine01 Zstd_FOUND

#cmakedefine01 KF5Auth_FOUND

#cmakedefine01 KF5Archive_FOUND

#cmakedefine01 QCustomPlot_FOUND
Expand Down
15 changes: 0 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,3 @@ install(
FILES hotspot.notifyrc
DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR}
)

if(KF5Auth_FOUND)
target_link_libraries(hotspot KF5::AuthCore)

add_executable(hotspot-auth-helper authhelper.cpp)
target_link_libraries(hotspot-auth-helper KF5::AuthCore)

option(INSTALL_KAUTH_HELPER "Install the KAuth helper, disable when you install to a custom prefix" ON)
if(INSTALL_KAUTH_HELPER)
install(TARGETS hotspot-auth-helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR})

kauth_install_helper_files(hotspot-auth-helper com.kdab.hotspot.perf root)
kauth_install_actions(com.kdab.hotspot.perf hotspot-perf-authhelper.actions)
endif()
endif()
91 changes: 0 additions & 91 deletions src/authhelper.cpp

This file was deleted.

5 changes: 0 additions & 5 deletions src/hotspot-perf-authhelper.actions

This file was deleted.

67 changes: 2 additions & 65 deletions src/perfrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@

#include <hotspot-config.h>

#if KF5Auth_FOUND
#include <kauth_version.h>

#if KAUTH_VERSION >= QT_VERSION_CHECK(5, 92, 0)
#include <KAuth/Action>
#include <KAuth/ActionReply>
#include <KAuth/ExecuteJob>
#else
#include <KAuth>
#endif
#endif

#include <fstream>
#include <sys/stat.h>

Expand Down Expand Up @@ -122,7 +110,7 @@ void PerfRecord::startRecording(bool elevatePrivileges, const QStringList& perfO
{
if (canElevatePrivileges() && elevatePrivileges && geteuid() != 0 && !privsAlreadyElevated()) {
// elevate privileges temporarily as root
// use kauth/kdesudo to start the elevate_perf_privileges.sh script
// use pkexec/kdesudo to start the elevate_perf_privileges.sh script
// then parse its output and once we get the "waiting..." line the privileges got elevated
// in that case, we can continue to start perf and quit the elevate_perf_privileges.sh script
// once perf has started
Expand Down Expand Up @@ -202,58 +190,7 @@ void PerfRecord::startRecording(bool elevatePrivileges, const QStringList& perfO
}
});

#if KF5Auth_FOUND
KAuth::Action action(QStringLiteral("com.kdab.hotspot.perf.elevate"));
action.setHelperId(QStringLiteral("com.kdab.hotspot.perf"));
QVariantMap args;
args[QStringLiteral("output")] = outputFile->fileName();
action.setArguments(args);

auto job = action.execute();

#if KAUTH_VERSION < QT_VERSION_CHECK(5, 80, 0)
connect(job, QOverload<KJob*, unsigned long>::of(&KAuth::ExecuteJob::percent), this,
#else
connect(job, &KAuth::ExecuteJob::percentChanged, this,
#endif
[this, readTimer, readSlot](KJob*, unsigned long percent) {
if (percent == 1) { // stated
readTimer->start(250);
} else if (percent == 2) { // stopped
readSlot();

if (!m_perfRecordProcess) {
emit recordingFailed(tr("Failed to elevate privileges."));
}
}
});

// stop elevate script
connect(this, &PerfRecord::recordingStarted, job, [job] { job->kill(); });

connect(job, &KAuth::ExecuteJob::result, this, [this, sudoBinary, options](KJob* kjob) {
auto job = qobject_cast<KAuth::ExecuteJob*>(kjob);

if (job->error() == KJob::NoError) {
} else if (job->error() == KAuth::ActionReply::DBusError
|| job->error() == KAuth::ActionReply::InvalidActionError) {
// could not start the helper, maybe the helper is not installed
// fall back to kdesu
m_elevatePrivilegesProcess->start(sudoBinary, options);
} else {
const auto errorMessage = job->errorString();
if (errorMessage.isEmpty()) {
emit recordingFailed(tr("Failed to elevate privileges."));
} else {
emit recordingFailed(tr("Failed to elevate privileges: %1").arg(errorMessage));
}
}
});

job->start();
#else
m_elevatePrivilegesProcess->start(sudoBinary, options);
#endif
} else {
startRecording(perfOptions, outputPath, recordOptions, workingDirectory);
}
Expand Down Expand Up @@ -507,7 +444,7 @@ bool PerfRecord::canCompress()

bool PerfRecord::canElevatePrivileges()
{
return ALLOW_PRIVILEGE_ESCALATION && (!sudoUtil().isEmpty() || KF5Auth_FOUND);
return ALLOW_PRIVILEGE_ESCALATION && (!sudoUtil().isEmpty());
}

QString PerfRecord::perfBinaryPath()
Expand Down
2 changes: 1 addition & 1 deletion src/recordpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ RecordPage::RecordPage(QWidget* parent)
ui->elevatePrivilegesCheckBox->setChecked(false);
ui->elevatePrivilegesCheckBox->setEnabled(false);
ui->elevatePrivilegesCheckBox->setText(
tr("(Note: Install pkexec, kdesudo, kdesu or KAuth to temporarily elevate perf privileges.)"));
tr("(Note: Install pkexec, kdesudo or kdesu to temporarily elevate perf privileges.)"));
}

connect(ui->elevatePrivilegesCheckBox, &QCheckBox::toggled, this, &RecordPage::updateOffCpuCheckboxState);
Expand Down
4 changes: 0 additions & 4 deletions tests/integrationtests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ ecm_add_test(
tst_perfparser
)

if(KF5Auth_FOUND)
target_link_libraries(tst_perfparser KF5::Auth)
endif()

if(KF5Archive_FOUND)
target_link_libraries(tst_perfparser KF5::Archive)
endif()
Expand Down

0 comments on commit 5a6280b

Please sign in to comment.