fort/src/ui/fortcommon.cpp

187 lines
4.4 KiB
C++
Raw Normal View History

2017-08-25 16:04:46 +00:00
#include "fortcommon.h"
2018-01-09 06:58:20 +00:00
#define _WIN32_WINNT 0x0601
2017-08-25 16:04:46 +00:00
#define WIN32_LEAN_AND_MEAN
#include <qt_windows.h>
2017-08-25 16:04:46 +00:00
#include <winioctl.h>
#include <fwpmu.h>
#include "../common/common.h"
#include "../common/fortconf.h"
#include "../common/fortconf.c"
#include "../common/fortlog.c"
#include "../common/fortprov.c"
FortCommon::FortCommon(QObject *parent) :
QObject(parent)
{
}
QString FortCommon::deviceName()
{
return QLatin1String(FORT_DEVICE_NAME);
}
2019-03-10 18:03:59 +00:00
quint32 FortCommon::ioctlValidate()
{
return FORT_IOCTL_VALIDATE;
}
2017-08-25 16:04:46 +00:00
quint32 FortCommon::ioctlSetConf()
{
return FORT_IOCTL_SETCONF;
}
quint32 FortCommon::ioctlSetFlags()
{
return FORT_IOCTL_SETFLAGS;
}
quint32 FortCommon::ioctlGetLog()
{
return FORT_IOCTL_GETLOG;
}
2017-12-06 13:41:26 +00:00
int FortCommon::bufferSize()
2017-08-25 16:04:46 +00:00
{
return FORT_BUFFER_SIZE;
}
2018-01-12 11:33:19 +00:00
quint32 FortCommon::confIoConfOff()
{
return FORT_CONF_IO_CONF_OFF;
}
2017-11-01 13:49:11 +00:00
quint32 FortCommon::logBlockedHeaderSize()
2017-08-25 16:04:46 +00:00
{
2017-11-01 13:49:11 +00:00
return FORT_LOG_BLOCKED_HEADER_SIZE;
2017-08-25 16:04:46 +00:00
}
2017-11-01 13:49:11 +00:00
quint32 FortCommon::logBlockedSize(quint32 pathLen)
2017-08-25 16:04:46 +00:00
{
2017-11-01 13:49:11 +00:00
return FORT_LOG_BLOCKED_SIZE(pathLen);
2017-08-25 16:04:46 +00:00
}
2017-11-24 08:53:11 +00:00
quint32 FortCommon::logProcNewHeaderSize()
{
return FORT_LOG_PROC_NEW_HEADER_SIZE;
}
quint32 FortCommon::logProcNewSize(quint32 pathLen)
{
return FORT_LOG_PROC_NEW_SIZE(pathLen);
}
2017-11-29 10:12:34 +00:00
quint32 FortCommon::logStatHeaderSize()
2017-11-24 08:53:11 +00:00
{
2017-11-29 10:12:34 +00:00
return FORT_LOG_STAT_HEADER_SIZE;
2017-11-24 08:53:11 +00:00
}
2017-11-27 07:04:10 +00:00
quint32 FortCommon::logStatTrafSize(quint16 procCount)
{
return FORT_LOG_STAT_TRAF_SIZE(procCount);
}
2017-11-29 10:12:34 +00:00
quint32 FortCommon::logStatSize(quint16 procCount)
{
return FORT_LOG_STAT_SIZE(procCount);
}
2017-11-07 12:15:58 +00:00
quint32 FortCommon::logType(const char *input)
{
return fort_log_type(input);
}
2017-11-01 13:49:11 +00:00
void FortCommon::logBlockedHeaderWrite(char *output,
quint32 remoteIp, quint32 pid,
quint32 pathLen)
2017-08-25 16:04:46 +00:00
{
2017-11-01 13:49:11 +00:00
fort_log_blocked_header_write(output, remoteIp, pid, pathLen);
2017-08-25 16:04:46 +00:00
}
2017-11-01 13:49:11 +00:00
void FortCommon::logBlockedHeaderRead(const char *input,
quint32 *remoteIp, quint32 *pid,
quint32 *pathLen)
2017-08-25 16:04:46 +00:00
{
2017-11-01 13:49:11 +00:00
fort_log_blocked_header_read(input, remoteIp, pid, pathLen);
2017-08-25 16:04:46 +00:00
}
2017-11-24 08:53:11 +00:00
void FortCommon::logProcNewHeaderWrite(char *output,
quint32 pid, quint32 pathLen)
{
fort_log_proc_new_header_write(output, pid, pathLen);
}
void FortCommon::logProcNewHeaderRead(const char *input,
quint32 *pid, quint32 *pathLen)
{
fort_log_proc_new_header_read(input, pid, pathLen);
}
2017-11-27 07:04:10 +00:00
void FortCommon::logStatTrafHeaderRead(const char *input,
quint16 *procCount)
{
fort_log_stat_traf_header_read(input, procCount);
}
2017-08-30 08:34:37 +00:00
void FortCommon::confAppPermsMaskInit(void *drvConf)
2017-08-29 08:40:23 +00:00
{
PFORT_CONF conf = (PFORT_CONF) drvConf;
fort_conf_app_perms_mask_init(conf, conf->flags.group_bits);
2017-08-29 08:40:23 +00:00
}
bool FortCommon::confIpInRange(const void *drvConf, quint32 ip,
bool included, int addrGroupIndex)
2017-08-29 08:40:23 +00:00
{
const PFORT_CONF conf = (const PFORT_CONF) drvConf;
const PFORT_CONF_ADDR_GROUP addr_group = fort_conf_addr_group_ref(
conf, addrGroupIndex);
2017-08-29 08:40:23 +00:00
const UINT32 count = included ? addr_group->include_n
: addr_group->exclude_n;
const UINT32 *iprange = included
? fort_conf_addr_group_include_ref(addr_group)
: fort_conf_addr_group_exclude_ref(addr_group);
2017-08-29 08:40:23 +00:00
return fort_conf_ip_inrange(ip, count, iprange);
2017-08-29 08:40:23 +00:00
}
2017-12-25 15:23:26 +00:00
int FortCommon::confAppIndex(const void *drvConf,
const QString &kernelPath)
2017-08-29 08:40:23 +00:00
{
const PFORT_CONF conf = (const PFORT_CONF) drvConf;
2017-09-13 08:26:51 +00:00
const QString kernelPathLower = kernelPath.toLower();
const int len = kernelPathLower.size() * sizeof(wchar_t);
const wchar_t *p = (const wchar_t *) kernelPathLower.utf16();
2017-08-29 08:40:23 +00:00
2017-12-25 15:23:26 +00:00
return fort_conf_app_index(conf, len, (const char *) p);
}
quint8 FortCommon::confAppGroupIndex(const void *drvConf, int appIndex)
{
const PFORT_CONF conf = (const PFORT_CONF) drvConf;
return fort_conf_app_group_index(conf, appIndex);
}
bool FortCommon::confAppBlocked(const void *drvConf, int appIndex)
{
const PFORT_CONF conf = (const PFORT_CONF) drvConf;
return fort_conf_app_blocked(conf, appIndex);
2017-08-29 08:40:23 +00:00
}
2017-09-03 09:20:37 +00:00
quint16 FortCommon::confAppPeriodBits(const void *drvConf, int hour)
{
const PFORT_CONF conf = (const PFORT_CONF) drvConf;
return fort_conf_app_period_bits(conf, hour, hour, nullptr);
}
2017-09-03 09:20:37 +00:00
void FortCommon::provUnregister()
{
2019-02-08 08:19:20 +00:00
fort_prov_unregister(nullptr);
2017-09-03 09:20:37 +00:00
}