mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:56:22 +00:00
UI: Prepare driver services info updating
This commit is contained in:
parent
7fbd0532e6
commit
3809580a73
@ -41,6 +41,29 @@ typedef struct fort_conf_flags
|
||||
UINT32 group_bits : 16;
|
||||
} FORT_CONF_FLAGS, *PFORT_CONF_FLAGS;
|
||||
|
||||
typedef struct fort_service_info
|
||||
{
|
||||
UINT32 process_id;
|
||||
|
||||
UCHAR name_len;
|
||||
WCHAR name[2];
|
||||
} FORT_SERVICE_INFO, *PFORT_SERVICE_INFO;
|
||||
|
||||
typedef struct fort_service_info_list
|
||||
{
|
||||
UINT16 services_n;
|
||||
|
||||
FORT_SERVICE_INFO data[1];
|
||||
} FORT_SERVICE_INFO_LIST, *PFORT_SERVICE_INFO_LIST;
|
||||
|
||||
#define FORT_SERVICE_INFO_NAME_OFF offsetof(FORT_SERVICE_INFO, name)
|
||||
#define FORT_SERVICE_INFO_LIST_DATA_OFF offsetof(FORT_SERVICE_INFO_LIST, data)
|
||||
#define FORT_SERVICE_INFO_NAME_MAX 256
|
||||
#define FORT_SERVICE_INFO_NAME_MAX_SIZE (FORT_SERVICE_INFO_NAME_MAX * sizeof(WCHAR))
|
||||
#define FORT_SERVICE_INFO_MAX_SIZE (FORT_SERVICE_INFO_NAME_OFF + FORT_SERVICE_INFO_NAME_MAX_SIZE)
|
||||
#define FORT_SERVICE_INFO_LIST_MIN_SIZE \
|
||||
(FORT_SERVICE_INFO_LIST_DATA_OFF + FORT_SERVICE_INFO_MAX_SIZE)
|
||||
|
||||
typedef struct fort_conf_addr4_list
|
||||
{
|
||||
UINT32 ip_n;
|
||||
|
@ -174,12 +174,13 @@ DEFINE_GUID(FORT_GUID_EMPTY, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00,
|
||||
#define FORT_CTL_CODE(i, a) CTL_CODE(FORT_DEVICE_TYPE, FORT_IOCTL_BASE + (i), METHOD_BUFFERED, (a))
|
||||
|
||||
#define FORT_IOCTL_VALIDATE FORT_CTL_CODE(0, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_SETCONF FORT_CTL_CODE(1, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_SETFLAGS FORT_CTL_CODE(2, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_GETLOG FORT_CTL_CODE(3, FILE_READ_DATA)
|
||||
#define FORT_IOCTL_ADDAPP FORT_CTL_CODE(4, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_DELAPP FORT_CTL_CODE(5, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_SETZONES FORT_CTL_CODE(6, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_SETZONEFLAG FORT_CTL_CODE(7, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_SETSERVICES FORT_CTL_CODE(1, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_SETCONF FORT_CTL_CODE(2, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_SETFLAGS FORT_CTL_CODE(3, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_GETLOG FORT_CTL_CODE(4, FILE_READ_DATA)
|
||||
#define FORT_IOCTL_ADDAPP FORT_CTL_CODE(5, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_DELAPP FORT_CTL_CODE(6, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_SETZONES FORT_CTL_CODE(7, FILE_WRITE_DATA)
|
||||
#define FORT_IOCTL_SETZONEFLAG FORT_CTL_CODE(8, FILE_WRITE_DATA)
|
||||
|
||||
#endif // FORTIOCTL_H
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "common/fortprov.h"
|
||||
|
||||
#include "fortcout.h"
|
||||
#include "fortps.h"
|
||||
#include "fortscb.h"
|
||||
#include "forttrace.h"
|
||||
|
||||
@ -144,6 +145,17 @@ static NTSTATUS fort_device_control_validate(const PFORT_CONF_VERSION conf_ver,
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
static NTSTATUS fort_device_control_setservices(const PFORT_SERVICE_INFO_LIST services, ULONG len)
|
||||
{
|
||||
if (len > sizeof(FORT_SERVICE_INFO_LIST)) {
|
||||
fort_pstree_update_services(&fort_device()->ps_tree, services);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
static NTSTATUS fort_device_control_setconf(const PFORT_CONF_IO conf_io, ULONG len)
|
||||
{
|
||||
if (len > sizeof(FORT_CONF_IO)) {
|
||||
@ -267,6 +279,8 @@ static NTSTATUS fort_device_control_process(
|
||||
switch (control_code) {
|
||||
case FORT_IOCTL_VALIDATE:
|
||||
return fort_device_control_validate(buffer, in_len);
|
||||
case FORT_IOCTL_SETSERVICES:
|
||||
return fort_device_control_setservices(buffer, in_len);
|
||||
case FORT_IOCTL_SETCONF:
|
||||
return fort_device_control_setconf(buffer, in_len);
|
||||
case FORT_IOCTL_SETFLAGS:
|
||||
|
@ -12,8 +12,9 @@
|
||||
#define FORT_SVCHOST_PREFIX L"\\svchost\\"
|
||||
#define FORT_SVCHOST_EXE L"svchost.exe"
|
||||
|
||||
#define FORT_PSTREE_NAME_LEN_MAX (120 * sizeof(WCHAR))
|
||||
#define FORT_PSTREE_NAMES_POOL_SIZE (4 * 1024)
|
||||
#define FORT_PSTREE_NAME_LEN_MAX 120
|
||||
#define FORT_PSTREE_NAME_LEN_MAX_SIZE (FORT_PSTREE_NAME_LEN_MAX * sizeof(WCHAR))
|
||||
#define FORT_PSTREE_NAMES_POOL_SIZE (4 * 1024)
|
||||
|
||||
#define FORT_PSNAME_DATA_OFF offsetof(FORT_PSNAME, data)
|
||||
|
||||
@ -243,7 +244,7 @@ static BOOL fort_pstree_svchost_check(
|
||||
}
|
||||
|
||||
const USHORT nameLen = (USHORT) ((PCHAR) endp - (PCHAR) argp);
|
||||
if (nameLen >= FORT_PSTREE_NAME_LEN_MAX)
|
||||
if (nameLen >= FORT_PSTREE_NAME_LEN_MAX_SIZE)
|
||||
return FALSE;
|
||||
|
||||
serviceName->Length = nameLen;
|
||||
@ -714,3 +715,8 @@ FORT_API BOOL fort_pstree_get_proc_name(
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
FORT_API void fort_pstree_update_services(
|
||||
PFORT_PSTREE ps_tree, const PFORT_SERVICE_INFO_LIST services)
|
||||
{
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "fortpool.h"
|
||||
#include "forttds.h"
|
||||
|
||||
#define FORT_PSTREE_ACTIVE 0x0001
|
||||
#define FORT_PSTREE_ACTIVE 0x0001
|
||||
|
||||
typedef struct fort_pstree
|
||||
{
|
||||
@ -37,6 +37,9 @@ FORT_API void NTAPI fort_pstree_enum_processes(void);
|
||||
FORT_API BOOL fort_pstree_get_proc_name(
|
||||
PFORT_PSTREE ps_tree, DWORD processId, PUNICODE_STRING path, BOOL *inherited);
|
||||
|
||||
FORT_API void fort_pstree_update_services(
|
||||
PFORT_PSTREE ps_tree, const PFORT_SERVICE_INFO_LIST services);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <log/logentryblocked.h>
|
||||
#include <log/logmanager.h>
|
||||
#include <manager/envmanager.h>
|
||||
#include <manager/serviceinfomanager.h>
|
||||
#include <manager/windowmanager.h>
|
||||
#include <task/taskinfo.h>
|
||||
#include <task/taskmanager.h>
|
||||
@ -1134,6 +1135,21 @@ bool ConfManager::validateDriver()
|
||||
return driverManager->validate(buf, verSize);
|
||||
}
|
||||
|
||||
void ConfManager::updateDriverServices()
|
||||
{
|
||||
ConfUtil confUtil;
|
||||
QByteArray buf;
|
||||
|
||||
auto serviceInfoManager = IoC<ServiceInfoManager>();
|
||||
const QVector<ServiceInfo> services = serviceInfoManager->loadServiceInfoList(
|
||||
ServiceInfo::StateActive, /*displayName=*/false);
|
||||
|
||||
const int outSize = confUtil.writeServices(services, buf);
|
||||
|
||||
auto driverManager = IoC<DriverManager>();
|
||||
driverManager->writeServices(buf, outSize);
|
||||
}
|
||||
|
||||
bool ConfManager::updateDriverConf(bool onlyFlags)
|
||||
{
|
||||
ConfUtil confUtil;
|
||||
|
@ -85,6 +85,7 @@ public:
|
||||
virtual bool checkPassword(const QString &password);
|
||||
|
||||
bool validateDriver();
|
||||
void updateDriverServices();
|
||||
virtual bool updateDriverConf(bool onlyFlags = false);
|
||||
void updateDriverZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
|
||||
const QList<QByteArray> &zonesData);
|
||||
|
@ -17,6 +17,11 @@ quint32 ioctlValidate()
|
||||
return FORT_IOCTL_VALIDATE;
|
||||
}
|
||||
|
||||
quint32 ioctlSetServices()
|
||||
{
|
||||
return FORT_IOCTL_SETSERVICES;
|
||||
}
|
||||
|
||||
quint32 ioctlSetConf()
|
||||
{
|
||||
return FORT_IOCTL_SETCONF;
|
||||
|
@ -10,6 +10,7 @@ namespace DriverCommon {
|
||||
QString deviceName();
|
||||
|
||||
quint32 ioctlValidate();
|
||||
quint32 ioctlSetServices();
|
||||
quint32 ioctlSetConf();
|
||||
quint32 ioctlSetFlags();
|
||||
quint32 ioctlGetLog();
|
||||
|
@ -96,6 +96,11 @@ bool DriverManager::validate(QByteArray &buf, int size)
|
||||
return writeData(DriverCommon::ioctlValidate(), buf, size);
|
||||
}
|
||||
|
||||
bool DriverManager::writeServices(QByteArray &buf, int size)
|
||||
{
|
||||
return writeData(DriverCommon::ioctlSetServices(), buf, size);
|
||||
}
|
||||
|
||||
bool DriverManager::writeConf(QByteArray &buf, int size, bool onlyFlags)
|
||||
{
|
||||
return writeData(
|
||||
|
@ -42,6 +42,7 @@ public slots:
|
||||
|
||||
bool validate(QByteArray &buf, int size);
|
||||
|
||||
bool writeServices(QByteArray &buf, int size);
|
||||
bool writeConf(QByteArray &buf, int size, bool onlyFlags = false);
|
||||
bool writeApp(QByteArray &buf, int size, bool remove = false);
|
||||
bool writeZones(QByteArray &buf, int size, bool onlyFlags = false);
|
||||
|
@ -21,10 +21,10 @@
|
||||
#include <manager/translationmanager.h>
|
||||
#include <model/zonelistmodel.h>
|
||||
#include <rpc/appinfomanagerrpc.h>
|
||||
#include <rpc/askpendingmanagerrpc.h>
|
||||
#include <rpc/confmanagerrpc.h>
|
||||
#include <rpc/drivermanagerrpc.h>
|
||||
#include <rpc/logmanagerrpc.h>
|
||||
#include <rpc/askpendingmanagerrpc.h>
|
||||
#include <rpc/quotamanagerrpc.h>
|
||||
#include <rpc/rpcmanager.h>
|
||||
#include <rpc/serviceinfomanagerrpc.h>
|
||||
@ -240,14 +240,19 @@ bool FortManager::removeDriver()
|
||||
bool FortManager::setupDriver()
|
||||
{
|
||||
auto driverManager = IoC<DriverManager>();
|
||||
auto confManager = IoC<ConfManager>();
|
||||
|
||||
bool ok = driverManager->openDevice();
|
||||
|
||||
if (ok && !IoC<ConfManager>()->validateDriver()) {
|
||||
if (ok && !confManager->validateDriver()) {
|
||||
driverManager->closeDevice();
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
confManager->updateDriverServices();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,30 @@
|
||||
|
||||
namespace {
|
||||
|
||||
int writeServicesHeader(char *data, int servicesCount)
|
||||
{
|
||||
PFORT_SERVICE_INFO_LIST infoList = (PFORT_SERVICE_INFO_LIST) data;
|
||||
|
||||
infoList->services_n = servicesCount;
|
||||
|
||||
return FORT_SERVICE_INFO_LIST_DATA_OFF;
|
||||
}
|
||||
|
||||
int writeServiceInfo(char *data, const ServiceInfo &serviceInfo)
|
||||
{
|
||||
PFORT_SERVICE_INFO info = (PFORT_SERVICE_INFO) data;
|
||||
|
||||
info->process_id = serviceInfo.processId;
|
||||
|
||||
const int nameLen = serviceInfo.serviceName.size();
|
||||
info->name_len = nameLen;
|
||||
|
||||
const QString name = serviceInfo.serviceName.toLower();
|
||||
memcpy(info->name, name.utf16(), nameLen * sizeof(char16_t));
|
||||
|
||||
return FORT_SERVICE_INFO_NAME_OFF + nameLen;
|
||||
}
|
||||
|
||||
void writeConfFlags(const FirewallConf &conf, PFORT_CONF_FLAGS confFlags)
|
||||
{
|
||||
confFlags->boot_filter = conf.bootFilter();
|
||||
@ -64,6 +88,35 @@ void ConfUtil::setErrorMessage(const QString &errorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
int ConfUtil::writeVersion(QByteArray &buf)
|
||||
{
|
||||
const int verSize = sizeof(FORT_CONF_VERSION);
|
||||
|
||||
buf.reserve(verSize);
|
||||
|
||||
// Fill the buffer
|
||||
PFORT_CONF_VERSION confVer = (PFORT_CONF_VERSION) buf.data();
|
||||
|
||||
confVer->driver_version = DRIVER_VERSION;
|
||||
|
||||
return verSize;
|
||||
}
|
||||
|
||||
int ConfUtil::writeServices(const QVector<ServiceInfo> &services, QByteArray &buf)
|
||||
{
|
||||
buf.reserve(FORT_SERVICE_INFO_LIST_MIN_SIZE);
|
||||
|
||||
int outSize = writeServicesHeader(buf.data(), services.size());
|
||||
|
||||
for (const ServiceInfo &info : services) {
|
||||
buf.reserve(outSize + FORT_SERVICE_INFO_MAX_SIZE);
|
||||
|
||||
outSize += writeServiceInfo(buf.data() + outSize, info);
|
||||
}
|
||||
|
||||
return outSize;
|
||||
}
|
||||
|
||||
int ConfUtil::write(const FirewallConf &conf, ConfAppsWalker *confAppsWalker,
|
||||
EnvManager &envManager, QByteArray &buf)
|
||||
{
|
||||
@ -144,20 +197,6 @@ int ConfUtil::writeAppEntry(const App &app, bool isNew, QByteArray &buf)
|
||||
return int(exeAppsSize);
|
||||
}
|
||||
|
||||
int ConfUtil::writeVersion(QByteArray &buf)
|
||||
{
|
||||
const int verSize = sizeof(FORT_CONF_VERSION);
|
||||
|
||||
buf.reserve(verSize);
|
||||
|
||||
// Fill the buffer
|
||||
PFORT_CONF_VERSION confVer = (PFORT_CONF_VERSION) buf.data();
|
||||
|
||||
confVer->driver_version = DRIVER_VERSION;
|
||||
|
||||
return verSize;
|
||||
}
|
||||
|
||||
int ConfUtil::writeZone(const IpRange &ipRange, QByteArray &buf)
|
||||
{
|
||||
const int addrSize = FORT_CONF_ADDR_LIST_SIZE(
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
#include <util/service/serviceinfo.h>
|
||||
|
||||
#include "addressrange.h"
|
||||
|
||||
class AddressGroup;
|
||||
@ -41,11 +43,12 @@ signals:
|
||||
void errorMessageChanged();
|
||||
|
||||
public slots:
|
||||
int writeVersion(QByteArray &buf);
|
||||
int writeServices(const QVector<ServiceInfo> &services, QByteArray &buf);
|
||||
int write(const FirewallConf &conf, ConfAppsWalker *confAppsWalker, EnvManager &envManager,
|
||||
QByteArray &buf);
|
||||
int writeFlags(const FirewallConf &conf, QByteArray &buf);
|
||||
int writeAppEntry(const App &app, bool isNew, QByteArray &buf);
|
||||
int writeVersion(QByteArray &buf);
|
||||
int writeZone(const IpRange &ipRange, QByteArray &buf);
|
||||
int writeZones(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
|
||||
const QList<QByteArray> &zonesData, QByteArray &buf);
|
||||
|
@ -15,6 +15,6 @@
|
||||
#define APP_UPDATES_URL "https://github.com/tnodir/fort/releases"
|
||||
#define APP_UPDATES_API_URL "https://api.github.com/repos/tnodir/fort/releases/latest"
|
||||
|
||||
#define DRIVER_VERSION 30
|
||||
#define DRIVER_VERSION 31
|
||||
|
||||
#endif // FORT_VERSION_H
|
||||
|
Loading…
Reference in New Issue
Block a user