Skip to content

Commit

Permalink
fix: add polkit support for root app
Browse files Browse the repository at this point in the history
add polkit support for root app

Log: add polkit support for root app

Bug: https://pms.uniontech.com/bug-view-273929.html
  • Loading branch information
Johnson-zs committed Sep 20, 2024
1 parent 5506587 commit 5a61bd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <QDir>
#include <QDebug>
#include <QDateTime>
#include <QDBusConnection>
#include <QDBusConnectionInterface>

// 系统库文件
#include <cups.h>
Expand All @@ -38,7 +40,7 @@ QString DBusEnableInterface::getAuthorizedInfo()

bool DBusEnableInterface::enable(const QString& hclass, const QString& name, const QString& path, const QString& value, bool enable_device, const QString strDriver)

Check warning on line 41 in deepin-devicemanager-server/src/EnableControl/DBusEnableInterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'strDriver' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.
{
if (!DriverDBusInterface::authority())
if (!isRootCaller() && !DriverDBusInterface::authority())
return false;

// 网卡通过ioctl禁用
Expand Down Expand Up @@ -68,7 +70,7 @@ bool DBusEnableInterface::enable(const QString& hclass, const QString& name, con

Q_SCRIPTABLE bool DBusEnableInterface::enablePrinter(const QString& hclass, const QString& name, const QString& path, bool enable_device)
{
if (!DriverDBusInterface::authority())
if (!isRootCaller() && !DriverDBusInterface::authority())
return false;

ipp_op_t op = enable_device ? IPP_OP_RESUME_PRINTER : IPP_OP_PAUSE_PRINTER;
Expand Down Expand Up @@ -259,3 +261,10 @@ void DBusEnableInterface::modifyPath(QString& path)
{
path.replace(QRegExp("[1-9]$"),"0");
}

bool DBusEnableInterface::isRootCaller()
{
if (connection().interface()->serviceUid(message().service()).value() == 0)
return true;
return false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class DBusEnableInterface : public QObject, protected QDBusContext
public:
explicit DBusEnableInterface(QObject *parent = nullptr);

private:
bool getUserAuthorPasswd(void);

public slots:
/**
* @brief getRemoveInfo
Expand Down Expand Up @@ -118,6 +115,8 @@ public slots:
* @param path 需要修正的路径 /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:1.0
*/
void modifyPath(QString& path);

bool isRootCaller();
};

#endif // DBUSENABLEINTERFACE_H

0 comments on commit 5a61bd9

Please sign in to comment.