perf: 改用dbus提权检测IP冲突
This commit is contained in:
parent
4cf54f01df
commit
71bed0b9e0
|
@ -1,14 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
PROGRAM=$(dpkg-divert --truename /usr/bin/kylin-nm)
|
|
||||||
|
|
||||||
if setcap cap_net_raw+ep $PROGRAM; then
|
|
||||||
chmod u-s $PROGRAM
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "kylin nm set cap success"
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ CONFIG += \
|
||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
plugins/plugin.pro \
|
plugins/plugin.pro \
|
||||||
src-vpn/src-vpn.pro \
|
src-vpn/src-vpn.pro \
|
||||||
src
|
src \
|
||||||
|
sys-dbus-register \
|
||||||
|
|
||||||
QT += widgets
|
QT += widgets
|
||||||
|
|
|
@ -4,17 +4,12 @@ include(dbus-interface/dbus-interface.pri)
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/dbusadaptor.h \
|
$$PWD/dbusadaptor.h \
|
||||||
$$PWD/kylinarping.h \
|
|
||||||
$$PWD/kylinipv4arping.h \
|
|
||||||
$$PWD/kylinipv6arping.h \
|
|
||||||
$$PWD/sysdbusregister.h \
|
$$PWD/sysdbusregister.h \
|
||||||
$$PWD/utils.h \
|
$$PWD/utils.h \
|
||||||
$$PWD/wifi-auth-thread.h
|
$$PWD/wifi-auth-thread.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/dbusadaptor.cpp \
|
$$PWD/dbusadaptor.cpp \
|
||||||
$$PWD/kylinipv4arping.cpp \
|
|
||||||
$$PWD/kylinipv6arping.cpp \
|
|
||||||
$$PWD/sysdbusregister.cpp \
|
$$PWD/sysdbusregister.cpp \
|
||||||
$$PWD/utils.cpp \
|
$$PWD/utils.cpp \
|
||||||
$$PWD/wifi-auth-thread.cpp
|
$$PWD/wifi-auth-thread.cpp
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "netdetail.h"
|
#include "netdetail.h"
|
||||||
#include "backend/kylinipv4arping.h"
|
|
||||||
#include "backend/kylinipv6arping.h"
|
|
||||||
//#include "xatom/xatom-helper.h"
|
//#include "xatom/xatom-helper.h"
|
||||||
|
|
||||||
#define THEME_SCHAME "org.ukui.style"
|
#define THEME_SCHAME "org.ukui.style"
|
||||||
|
@ -57,6 +55,9 @@
|
||||||
#define PEAP_SCRO_HEIGHT 300
|
#define PEAP_SCRO_HEIGHT 300
|
||||||
#define TLS_SCRO_HEIGHT 480
|
#define TLS_SCRO_HEIGHT 480
|
||||||
#define MAX_TAB_TEXT_LENGTH 44
|
#define MAX_TAB_TEXT_LENGTH 44
|
||||||
|
#define SYSTEM_DBUS_SERVICE "com.kylin.network.qt.systemdbus"
|
||||||
|
#define SYSTEM_DBUS_PATH "/"
|
||||||
|
#define SYSTEM_DBUS_INTERFACE "com.kylin.network.interface"
|
||||||
|
|
||||||
//extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
//extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
||||||
|
|
||||||
|
@ -1268,33 +1269,37 @@ void ThreadObject::checkIpv4ConflictThread(const QString &ipv4Address)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool isConflict = false;
|
bool isConflict = false;
|
||||||
KyIpv4Arping* ipv4Arping = new KyIpv4Arping(m_devName, ipv4Address);
|
|
||||||
if (ipv4Arping->ipv4ConflictCheck() >= 0) {
|
QDBusInterface dbusInterface(SYSTEM_DBUS_SERVICE,
|
||||||
isConflict = ipv4Arping->ipv4IsConflict();
|
SYSTEM_DBUS_PATH,
|
||||||
if (isConflict) {
|
SYSTEM_DBUS_INTERFACE,
|
||||||
QString mac = ipv4Arping->getMacAddress();
|
QDBusConnection::systemBus());
|
||||||
qDebug() << "conflict mac" << mac;
|
|
||||||
KyNetworkDeviceResourse resource;
|
if(!dbusInterface.isValid()) {
|
||||||
QStringList devList,devList1,devList2;
|
qWarning ()<< "check IPv4 conflict failed, init kylin.network.qt.systemdbus error";
|
||||||
resource.getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, devList1);
|
Q_EMIT ipv4IsConflict(isConflict);
|
||||||
resource.getNetworkDeviceList(NetworkManager::Device::Type::Wifi, devList2);
|
return;
|
||||||
devList << devList1 << devList2;
|
}
|
||||||
for(int i = 0; i < devList.size(); ++i){
|
|
||||||
QString hardAddress;
|
KyNetworkDeviceResourse resource;
|
||||||
int band;
|
QStringList devList, devList1, devList2, macList;
|
||||||
resource.getHardwareInfo(devList.at(i), hardAddress, band);
|
resource.getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, devList1);
|
||||||
if (hardAddress == mac) {
|
resource.getNetworkDeviceList(NetworkManager::Device::Type::Wifi, devList2);
|
||||||
qDebug() << "conflict local card" << devList.at(i);
|
devList << devList1 << devList2;
|
||||||
isConflict = false;
|
for (int i = 0; i < devList.size(); ++i) {
|
||||||
}
|
QString hardAddress;
|
||||||
}
|
int band;
|
||||||
}
|
resource.getHardwareInfo(devList.at(i), hardAddress, band);
|
||||||
} else {
|
macList << hardAddress;
|
||||||
qWarning() << "checkIpv4Conflict internal error";
|
}
|
||||||
|
|
||||||
|
QDBusReply <bool> reply = dbusInterface.call("checkIpv4IsConflict", m_devName, ipv4Address, macList);
|
||||||
|
if (reply.isValid()) {
|
||||||
|
isConflict = reply.value();
|
||||||
|
} else {
|
||||||
|
qWarning () << "check IPv4 conflict failed, dbus reply invalid";
|
||||||
}
|
}
|
||||||
|
|
||||||
delete ipv4Arping;
|
|
||||||
ipv4Arping = nullptr;
|
|
||||||
Q_EMIT ipv4IsConflict(isConflict);
|
Q_EMIT ipv4IsConflict(isConflict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1304,14 +1309,21 @@ void ThreadObject::checkIpv6ConflictThread(const QString &ipv6Address)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool isConflict = false;
|
bool isConflict = false;
|
||||||
KyIpv6Arping* ipv6rping = new KyIpv6Arping(m_devName, ipv6Address);
|
QDBusInterface dbusInterface(SYSTEM_DBUS_SERVICE,
|
||||||
if (ipv6rping->ipv6ConflictCheck() >= 0) {
|
SYSTEM_DBUS_PATH,
|
||||||
isConflict = ipv6rping->ipv6IsConflict();
|
SYSTEM_DBUS_INTERFACE,
|
||||||
|
QDBusConnection::systemBus());
|
||||||
|
|
||||||
|
if(!dbusInterface.isValid()) {
|
||||||
|
qWarning () << "check IPv6 conflict failed, init kylin.network.qt.systemdbus error";
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "checkIpv6Conflict internal error";
|
QDBusReply <bool> reply = dbusInterface.call("checkIpv6IsConflict", m_devName, ipv6Address);
|
||||||
|
if (reply.isValid()) {
|
||||||
|
isConflict = reply.value();
|
||||||
|
} else {
|
||||||
|
qWarning () << "check IPv6 conflict failed, dbus reply invalid";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete ipv6rping;
|
|
||||||
ipv6rping = nullptr;
|
|
||||||
Q_EMIT ipv6IsConflict(isConflict);
|
Q_EMIT ipv6IsConflict(isConflict);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
|
||||||
|
|
||||||
|
<!DOCTYPE busconfig PUBLIC
|
||||||
|
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||||
|
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||||
|
<busconfig>
|
||||||
|
<!-- Only root can own the service -->
|
||||||
|
<policy user="root">
|
||||||
|
<allow own="com.kylin.network.qt.systemdbus"/>
|
||||||
|
<allow send_interface="com.kylin.network.interface"/>
|
||||||
|
</policy>
|
||||||
|
|
||||||
|
<!-- Allow anyone to invoke methods on the interfaces -->
|
||||||
|
<policy context="default">
|
||||||
|
<allow send_destination="com.kylin.network.qt.systemdbus"
|
||||||
|
send_interface="com.kylin.network.interface"/>
|
||||||
|
<allow send_destination="com.kylin.network.qt.systemdbus"
|
||||||
|
send_interface="org.freedesktop.DBus.Introspectable"/>
|
||||||
|
<allow send_destination="com.kylin.network.qt.systemdbus"
|
||||||
|
send_interface="org.freedesktop.DBus.Properties"/>
|
||||||
|
</policy>
|
||||||
|
</busconfig>
|
|
@ -0,0 +1,4 @@
|
||||||
|
[D-BUS Service]
|
||||||
|
Name=com.kylin.network.qt.systemdbus
|
||||||
|
Exec=/usr/bin/kylin-nm-sysdbus
|
||||||
|
User=root
|
|
@ -0,0 +1,12 @@
|
||||||
|
INCLUDEPATH += $$PWD
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/kylinarping.h \
|
||||||
|
$$PWD/kylinipv4arping.h \
|
||||||
|
$$PWD/kylinipv6arping.h \
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/kylinipv4arping.cpp \
|
||||||
|
$$PWD/kylinipv6arping.cpp \
|
||||||
|
|
||||||
|
DISTFILES +=
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||||
|
*
|
||||||
|
* 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "kynmsystemdbus.h"
|
||||||
|
#include "kylinipv4arping.h"
|
||||||
|
#include "kylinipv6arping.h"
|
||||||
|
|
||||||
|
#define LOG_FLAG "[KynmSystemDbus]"
|
||||||
|
|
||||||
|
KynmSystemDbus::KynmSystemDbus(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
KynmSystemDbus::~KynmSystemDbus()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KynmSystemDbus::checkIpv4IsConflict(const QString devName, const QString ipv4Address, QStringList macList)
|
||||||
|
{
|
||||||
|
bool isConflict = false;
|
||||||
|
KyIpv4Arping* ipv4Arping = new KyIpv4Arping(devName, ipv4Address);
|
||||||
|
if (ipv4Arping->ipv4ConflictCheck() >= 0) {
|
||||||
|
isConflict = ipv4Arping->ipv4IsConflict();
|
||||||
|
if (isConflict && !macList.isEmpty()) {
|
||||||
|
QString macAddress = ipv4Arping->getMacAddress();
|
||||||
|
for (const auto mac : macList) {
|
||||||
|
if (macAddress == mac) {
|
||||||
|
qDebug() << LOG_FLAG << "IPv4 conflict mac" << mac;
|
||||||
|
isConflict = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qWarning() << LOG_FLAG << "checkIpv4Conflict internal error";
|
||||||
|
}
|
||||||
|
|
||||||
|
delete ipv4Arping;
|
||||||
|
ipv4Arping = nullptr;
|
||||||
|
|
||||||
|
return isConflict;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KynmSystemDbus::checkIpv6IsConflict(const QString devName, const QString ipv6Address)
|
||||||
|
{
|
||||||
|
bool isConflict = false;
|
||||||
|
KyIpv6Arping* ipv6rping = new KyIpv6Arping(devName, ipv6Address);
|
||||||
|
if (ipv6rping->ipv6ConflictCheck() >= 0) {
|
||||||
|
isConflict = ipv6rping->ipv6IsConflict();
|
||||||
|
} else {
|
||||||
|
qWarning() << LOG_FLAG << "checkIpv6Conflict internal error";
|
||||||
|
}
|
||||||
|
|
||||||
|
delete ipv6rping;
|
||||||
|
ipv6rping = nullptr;
|
||||||
|
|
||||||
|
return isConflict;
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||||
|
*
|
||||||
|
* 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef KYNMSYSTEMDBUS_H
|
||||||
|
#define KYNMSYSTEMDBUS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class KynmSystemDbus : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_CLASSINFO("D-Bus Interface", "com.kylin.network.interface")
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit KynmSystemDbus(QObject *parent = nullptr);
|
||||||
|
~KynmSystemDbus();
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
Q_SCRIPTABLE bool checkIpv4IsConflict(const QString devName, const QString ipv4Address, QStringList macList);
|
||||||
|
Q_SCRIPTABLE bool checkIpv6IsConflict(const QString devName, const QString ipv6Address);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // KYNMSYSTEMDBUS_H
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||||
|
*
|
||||||
|
* 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "kynmsystemdbus.h"
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include <QDBusError>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
|
QDBusConnection systemBus = QDBusConnection::systemBus();
|
||||||
|
if (!systemBus.registerService("com.kylin.network.qt.systemdbus")){
|
||||||
|
qCritical() << "QDbus register service failed reason:" << systemBus.lastError();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!systemBus.registerObject("/", new KynmSystemDbus(), QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals)){
|
||||||
|
qCritical() << "QDbus register object failed reason:" << systemBus.lastError();
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
QT += dbus network
|
||||||
|
TARGET = kylin-nm-sysdbus
|
||||||
|
TEMPLATE = app
|
||||||
|
CONFIG += c++14 qt warn_on link_pkgconfig no_keywords
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
TARGET = kylin-nm-sysdbus
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
PKGCONFIG +=gio-2.0 glib-2.0 gio-unix-2.0 libcap
|
||||||
|
|
||||||
|
inst1.files += conf/com.kylin.network.qt.systemdbus.service
|
||||||
|
inst1.path = /usr/share/dbus-1/system-services/
|
||||||
|
inst2.files += conf/com.kylin.network.qt.systemdbus.conf
|
||||||
|
inst2.path = /etc/dbus-1/system.d/
|
||||||
|
target.source += $$TARGET
|
||||||
|
target.path = /usr/bin
|
||||||
|
|
||||||
|
INSTALLS += \
|
||||||
|
target \
|
||||||
|
inst1 \
|
||||||
|
inst2 \
|
||||||
|
|
||||||
|
include(kyarping/kyarping.pri)
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
kynmsystemdbus.cpp \
|
||||||
|
main.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
kynmsystemdbus.h
|
Loading…
Reference in New Issue