2021-03-16 18:36:12 +00:00
|
|
|
/* Fort Firewall Driver Device */
|
|
|
|
|
|
|
|
#include "fortdev.h"
|
|
|
|
|
2022-01-08 12:30:59 +00:00
|
|
|
#include "common/fortioctl.h"
|
2021-03-17 13:12:18 +00:00
|
|
|
#include "common/fortprov.h"
|
2021-03-16 18:36:12 +00:00
|
|
|
|
|
|
|
#include "fortcout.h"
|
2023-04-26 17:01:16 +00:00
|
|
|
#include "fortps.h"
|
2021-12-13 17:55:46 +00:00
|
|
|
#include "fortscb.h"
|
2022-05-29 09:19:13 +00:00
|
|
|
#include "forttrace.h"
|
2023-04-28 05:09:31 +00:00
|
|
|
#include "fortutl.h"
|
2021-03-16 18:36:12 +00:00
|
|
|
|
|
|
|
static PFORT_DEVICE g_device = NULL;
|
|
|
|
|
2023-03-30 12:31:48 +00:00
|
|
|
FORT_API PFORT_DEVICE fort_device(void)
|
2021-03-16 18:36:12 +00:00
|
|
|
{
|
|
|
|
return g_device;
|
|
|
|
}
|
|
|
|
|
2023-04-13 11:11:43 +00:00
|
|
|
FORT_API void fort_device_set(PFORT_DEVICE device)
|
2021-03-16 18:36:12 +00:00
|
|
|
{
|
|
|
|
g_device = device;
|
|
|
|
}
|
|
|
|
|
2023-04-27 07:23:12 +00:00
|
|
|
static void fort_worker_reauth(void)
|
2021-03-16 18:36:12 +00:00
|
|
|
{
|
2023-04-28 17:55:43 +00:00
|
|
|
FORT_CHECK_STACK();
|
|
|
|
|
2023-04-02 15:02:26 +00:00
|
|
|
const FORT_CONF_FLAGS conf_flags = fort_device()->conf.conf_flags;
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-15 16:04:14 +00:00
|
|
|
const NTSTATUS status = fort_callout_force_reauth(conf_flags);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
|
|
|
if (!NT_SUCCESS(status)) {
|
2022-01-29 08:42:30 +00:00
|
|
|
LOG("Worker Reauth: Error: %x\n", status);
|
2022-05-29 09:19:13 +00:00
|
|
|
TRACE(FORT_DEVICE_WORKER_REAUTH_ERROR, status, 0, 0);
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-28 17:55:43 +00:00
|
|
|
static void fort_app_period_timer(void)
|
2021-03-16 18:36:12 +00:00
|
|
|
{
|
2023-04-28 17:55:43 +00:00
|
|
|
FORT_CHECK_STACK();
|
|
|
|
|
2023-04-02 15:02:26 +00:00
|
|
|
if (fort_conf_ref_period_update(&fort_device()->conf, /*force=*/FALSE, /*periods_n=*/NULL)) {
|
|
|
|
fort_worker_queue(&fort_device()->worker, FORT_WORKER_REAUTH);
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-01 15:51:06 +00:00
|
|
|
FORT_API void fort_device_on_system_time(void)
|
|
|
|
{
|
|
|
|
if (fort_timer_is_running(&fort_device()->app_timer)) {
|
|
|
|
fort_app_period_timer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 18:36:12 +00:00
|
|
|
FORT_API NTSTATUS fort_device_create(PDEVICE_OBJECT device, PIRP irp)
|
|
|
|
{
|
|
|
|
UNUSED(device);
|
|
|
|
|
2023-04-28 17:55:43 +00:00
|
|
|
FORT_CHECK_STACK();
|
|
|
|
|
2023-01-06 14:30:34 +00:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
2021-03-16 18:36:12 +00:00
|
|
|
/* Device opened */
|
2023-04-13 11:11:43 +00:00
|
|
|
const UCHAR flags = fort_device_flag_set(&fort_device()->conf, FORT_DEVICE_IS_OPENED, TRUE);
|
|
|
|
if ((flags & FORT_DEVICE_IS_OPENED) != 0) {
|
2021-03-16 18:36:12 +00:00
|
|
|
status = STATUS_SHARING_VIOLATION; /* Only one client may connect */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NT_SUCCESS(status)) {
|
|
|
|
/* Clear buffer */
|
2023-04-02 15:02:26 +00:00
|
|
|
fort_buffer_clear(&fort_device()->buffer);
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fort_request_complete(irp, status);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORT_API NTSTATUS fort_device_close(PDEVICE_OBJECT device, PIRP irp)
|
|
|
|
{
|
|
|
|
UNUSED(device);
|
|
|
|
|
2023-04-28 17:55:43 +00:00
|
|
|
FORT_CHECK_STACK();
|
|
|
|
|
2021-03-16 18:36:12 +00:00
|
|
|
fort_request_complete(irp, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORT_API NTSTATUS fort_device_cleanup(PDEVICE_OBJECT device, PIRP irp)
|
|
|
|
{
|
|
|
|
UNUSED(device);
|
|
|
|
|
2023-04-28 17:55:43 +00:00
|
|
|
FORT_CHECK_STACK();
|
|
|
|
|
2021-03-16 18:36:12 +00:00
|
|
|
/* Device closed */
|
|
|
|
fort_device_flag_set(
|
2023-04-02 15:02:26 +00:00
|
|
|
&fort_device()->conf, (FORT_DEVICE_IS_OPENED | FORT_DEVICE_IS_VALIDATED), FALSE);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
|
|
|
/* Clear conf */
|
|
|
|
{
|
2023-04-02 15:02:26 +00:00
|
|
|
const FORT_CONF_FLAGS old_conf_flags = fort_conf_ref_set(&fort_device()->conf, NULL);
|
|
|
|
FORT_CONF_FLAGS conf_flags = fort_device()->conf.conf_flags;
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-02 15:02:26 +00:00
|
|
|
fort_conf_zones_set(&fort_device()->conf, NULL);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-02 15:02:26 +00:00
|
|
|
fort_stat_conf_flags_update(&fort_device()->stat, &conf_flags);
|
2023-01-04 15:16:23 +00:00
|
|
|
|
|
|
|
fort_callout_force_reauth(old_conf_flags);
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear buffer */
|
2023-04-02 15:02:26 +00:00
|
|
|
fort_buffer_clear(&fort_device()->buffer);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
|
|
|
fort_request_complete(irp, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
static NTSTATUS fort_device_control_validate(const PFORT_CONF_VERSION conf_ver, ULONG len)
|
2021-03-16 18:36:12 +00:00
|
|
|
{
|
2021-03-17 07:15:21 +00:00
|
|
|
if (len == sizeof(FORT_CONF_VERSION)) {
|
|
|
|
if (conf_ver->driver_version == DRIVER_VERSION) {
|
2023-04-02 15:02:26 +00:00
|
|
|
fort_device_flag_set(&fort_device()->conf, FORT_DEVICE_IS_VALIDATED, TRUE);
|
2021-03-17 07:15:21 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-26 17:01:16 +00:00
|
|
|
static NTSTATUS fort_device_control_setservices(const PFORT_SERVICE_INFO_LIST services, ULONG len)
|
|
|
|
{
|
|
|
|
if (len > sizeof(FORT_SERVICE_INFO_LIST)) {
|
2023-04-27 05:16:42 +00:00
|
|
|
fort_pstree_update_services(&fort_device()->ps_tree, services,
|
|
|
|
/*data_len=*/len - FORT_SERVICE_INFO_LIST_DATA_OFF);
|
2023-04-26 17:01:16 +00:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
static NTSTATUS fort_device_control_setconf(const PFORT_CONF_IO conf_io, ULONG len)
|
|
|
|
{
|
|
|
|
if (len > sizeof(FORT_CONF_IO)) {
|
|
|
|
const PFORT_CONF conf = &conf_io->conf;
|
|
|
|
PFORT_CONF_REF conf_ref = fort_conf_ref_new(conf, len - FORT_CONF_IO_CONF_OFF);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
if (conf_ref == NULL) {
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
} else {
|
2023-04-02 15:02:26 +00:00
|
|
|
const FORT_CONF_FLAGS old_conf_flags =
|
|
|
|
fort_conf_ref_set(&fort_device()->conf, conf_ref);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-02 15:02:26 +00:00
|
|
|
fort_stat_conf_update(&fort_device()->stat, conf_io);
|
2023-04-17 09:43:25 +00:00
|
|
|
fort_shaper_conf_update(&fort_device()->shaper, conf_io);
|
2021-03-17 07:15:21 +00:00
|
|
|
|
2023-01-04 15:16:23 +00:00
|
|
|
return fort_callout_force_reauth(old_conf_flags);
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
static NTSTATUS fort_device_control_setflags(const PFORT_CONF_FLAGS conf_flags, ULONG len)
|
|
|
|
{
|
|
|
|
if (len == sizeof(FORT_CONF_FLAGS)) {
|
2023-04-02 15:02:26 +00:00
|
|
|
const FORT_CONF_FLAGS old_conf_flags =
|
|
|
|
fort_conf_ref_flags_set(&fort_device()->conf, conf_flags);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-02 15:02:26 +00:00
|
|
|
fort_stat_conf_flags_update(&fort_device()->stat, conf_flags);
|
2023-04-17 09:43:25 +00:00
|
|
|
fort_shaper_conf_flags_update(&fort_device()->shaper, conf_flags);
|
2022-09-18 07:36:08 +00:00
|
|
|
|
2023-01-04 15:16:23 +00:00
|
|
|
return fort_callout_force_reauth(old_conf_flags);
|
2021-03-17 07:15:21 +00:00
|
|
|
}
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
static NTSTATUS fort_device_control_getlog(PVOID out, ULONG out_len, PIRP irp, ULONG_PTR *info)
|
|
|
|
{
|
2023-04-26 14:49:45 +00:00
|
|
|
if (out_len < FORT_BUFFER_SIZE)
|
2021-03-17 07:15:21 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-28 05:09:31 +00:00
|
|
|
const NTSTATUS status = fort_buffer_xmove(&fort_device()->buffer, irp, out, out_len, info);
|
|
|
|
|
|
|
|
if (status == STATUS_PENDING) {
|
|
|
|
fort_buffer_irp_mark_pending(irp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2021-03-17 07:15:21 +00:00
|
|
|
}
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-27 11:43:57 +00:00
|
|
|
inline static NTSTATUS fort_device_control_app_conf(
|
|
|
|
const PFORT_APP_ENTRY app_entry, PFORT_CONF_REF conf_ref, BOOL is_adding)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (is_adding) {
|
|
|
|
status = fort_conf_ref_exe_add_entry(conf_ref, app_entry, FALSE);
|
|
|
|
} else {
|
|
|
|
fort_conf_ref_exe_del_entry(conf_ref, app_entry);
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
static NTSTATUS fort_device_control_app(const PFORT_APP_ENTRY app_entry, ULONG len, BOOL is_adding)
|
|
|
|
{
|
2023-04-27 11:43:57 +00:00
|
|
|
if (len < sizeof(FORT_APP_ENTRY) || len < (sizeof(FORT_APP_ENTRY) + app_entry->path_len))
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-27 11:43:57 +00:00
|
|
|
PFORT_CONF_REF conf_ref = fort_conf_ref_take(&fort_device()->conf);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-27 11:43:57 +00:00
|
|
|
if (conf_ref == NULL)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-27 11:43:57 +00:00
|
|
|
const NTSTATUS status = fort_device_control_app_conf(app_entry, conf_ref, is_adding);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-27 11:43:57 +00:00
|
|
|
fort_conf_ref_put(&fort_device()->conf, conf_ref);
|
2021-03-17 07:15:21 +00:00
|
|
|
|
2023-04-27 11:43:57 +00:00
|
|
|
if (NT_SUCCESS(status)) {
|
|
|
|
fort_worker_reauth();
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 11:43:57 +00:00
|
|
|
return status;
|
2021-03-17 07:15:21 +00:00
|
|
|
}
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
static NTSTATUS fort_device_control_setzones(const PFORT_CONF_ZONES zones, ULONG len)
|
|
|
|
{
|
|
|
|
if (len >= FORT_CONF_ZONES_DATA_OFF) {
|
|
|
|
PFORT_CONF_ZONES conf_zones = fort_conf_zones_new(zones, len);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
if (conf_zones == NULL) {
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
} else {
|
2023-04-02 15:02:26 +00:00
|
|
|
fort_conf_zones_set(&fort_device()->conf, conf_zones);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-26 12:25:59 +00:00
|
|
|
fort_worker_reauth();
|
2021-03-17 07:15:21 +00:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
static NTSTATUS fort_device_control_setzoneflag(const PFORT_CONF_ZONE_FLAG zone_flag, ULONG len)
|
|
|
|
{
|
|
|
|
if (len == sizeof(FORT_CONF_ZONE_FLAG)) {
|
2023-04-02 15:02:26 +00:00
|
|
|
fort_conf_zone_flag_set(&fort_device()->conf, zone_flag);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
2023-04-26 12:25:59 +00:00
|
|
|
fort_worker_reauth();
|
2021-03-17 07:15:21 +00:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
2021-03-17 07:15:21 +00:00
|
|
|
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS fort_device_control_process(
|
|
|
|
const PIO_STACK_LOCATION irp_stack, PIRP irp, ULONG_PTR *info)
|
|
|
|
{
|
|
|
|
const int control_code = irp_stack->Parameters.DeviceIoControl.IoControlCode;
|
|
|
|
|
|
|
|
if (control_code != FORT_IOCTL_VALIDATE
|
2023-04-02 15:02:26 +00:00
|
|
|
&& fort_device_flag(&fort_device()->conf, FORT_DEVICE_IS_VALIDATED) == 0)
|
2021-03-17 07:15:21 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
PVOID buffer = irp->AssociatedIrp.SystemBuffer;
|
|
|
|
const ULONG in_len = irp_stack->Parameters.DeviceIoControl.InputBufferLength;
|
|
|
|
const ULONG out_len = irp_stack->Parameters.DeviceIoControl.OutputBufferLength;
|
|
|
|
|
|
|
|
switch (control_code) {
|
|
|
|
case FORT_IOCTL_VALIDATE:
|
|
|
|
return fort_device_control_validate(buffer, in_len);
|
2023-04-26 17:01:16 +00:00
|
|
|
case FORT_IOCTL_SETSERVICES:
|
|
|
|
return fort_device_control_setservices(buffer, in_len);
|
2021-03-17 07:15:21 +00:00
|
|
|
case FORT_IOCTL_SETCONF:
|
|
|
|
return fort_device_control_setconf(buffer, in_len);
|
|
|
|
case FORT_IOCTL_SETFLAGS:
|
|
|
|
return fort_device_control_setflags(buffer, in_len);
|
|
|
|
case FORT_IOCTL_GETLOG:
|
|
|
|
return fort_device_control_getlog(buffer, out_len, irp, info);
|
|
|
|
case FORT_IOCTL_ADDAPP:
|
|
|
|
case FORT_IOCTL_DELAPP:
|
|
|
|
return fort_device_control_app(buffer, in_len, (control_code == FORT_IOCTL_ADDAPP));
|
|
|
|
case FORT_IOCTL_SETZONES:
|
|
|
|
return fort_device_control_setzones(buffer, in_len);
|
|
|
|
case FORT_IOCTL_SETZONEFLAG:
|
|
|
|
return fort_device_control_setzoneflag(buffer, in_len);
|
2021-03-16 18:36:12 +00:00
|
|
|
default:
|
2022-09-18 07:36:08 +00:00
|
|
|
return STATUS_INVALID_DEVICE_REQUEST;
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
2021-03-17 07:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FORT_API NTSTATUS fort_device_control(PDEVICE_OBJECT device, PIRP irp)
|
|
|
|
{
|
|
|
|
UNUSED(device);
|
|
|
|
|
2023-04-28 17:55:43 +00:00
|
|
|
FORT_CHECK_STACK();
|
|
|
|
|
2023-01-06 14:30:34 +00:00
|
|
|
ULONG_PTR info = 0;
|
|
|
|
|
2021-03-17 07:15:21 +00:00
|
|
|
const PIO_STACK_LOCATION irp_stack = IoGetCurrentIrpStackLocation(irp);
|
|
|
|
const NTSTATUS status = fort_device_control_process(irp_stack, irp, &info);
|
2021-03-16 18:36:12 +00:00
|
|
|
|
|
|
|
if (!NT_SUCCESS(status) && status != FORT_STATUS_USER_ERROR) {
|
2022-01-29 08:42:30 +00:00
|
|
|
LOG("Device Control: Error: %x\n", status);
|
2022-05-29 09:19:13 +00:00
|
|
|
TRACE(FORT_DEVICE_DEVICE_CONTROL_ERROR, status, 0, 0);
|
2021-03-16 18:36:12 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 05:09:31 +00:00
|
|
|
if (status != STATUS_PENDING) {
|
2021-03-17 07:15:21 +00:00
|
|
|
fort_request_complete_info(irp, status, info);
|
|
|
|
}
|
2021-03-16 18:36:12 +00:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
2021-03-17 13:12:18 +00:00
|
|
|
|
2023-03-22 13:05:53 +00:00
|
|
|
FORT_API NTSTATUS fort_device_shutdown(PDEVICE_OBJECT device, PIRP irp)
|
|
|
|
{
|
|
|
|
UNUSED(device);
|
|
|
|
|
2023-04-28 17:55:43 +00:00
|
|
|
FORT_CHECK_STACK();
|
|
|
|
|
2023-03-22 13:05:53 +00:00
|
|
|
if (fort_device() != NULL) {
|
|
|
|
fort_stat_close_flows(&fort_device()->stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
fort_request_complete(irp, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2023-03-19 16:20:33 +00:00
|
|
|
static NTSTATUS fort_device_register_provider(void)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2023-04-17 08:17:00 +00:00
|
|
|
fort_prov_init();
|
|
|
|
|
2023-03-19 16:20:33 +00:00
|
|
|
HANDLE engine;
|
2023-04-17 08:17:00 +00:00
|
|
|
status = fort_prov_trans_open(&engine);
|
2023-03-19 16:20:33 +00:00
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
return status;
|
|
|
|
|
|
|
|
const FORT_PROV_BOOT_CONF boot_conf = fort_prov_get_boot_conf(engine);
|
|
|
|
|
|
|
|
fort_device_flag_set(&fort_device()->conf, FORT_DEVICE_BOOT_FILTER, boot_conf.boot_filter);
|
|
|
|
fort_device_flag_set(
|
|
|
|
&fort_device()->conf, FORT_DEVICE_BOOT_FILTER_LOCALS, boot_conf.filter_locals);
|
|
|
|
|
|
|
|
fort_prov_unregister(engine);
|
|
|
|
|
|
|
|
status = fort_prov_register(engine, boot_conf);
|
|
|
|
|
|
|
|
return fort_prov_trans_close(engine, status);
|
|
|
|
}
|
|
|
|
|
2023-04-27 07:23:12 +00:00
|
|
|
FORT_API NTSTATUS fort_device_load(PVOID device_param)
|
2021-03-17 13:12:18 +00:00
|
|
|
{
|
2023-03-19 16:20:33 +00:00
|
|
|
NTSTATUS status;
|
2021-03-17 13:12:18 +00:00
|
|
|
|
2023-04-27 07:23:12 +00:00
|
|
|
PDEVICE_OBJECT device = device_param;
|
2021-03-17 13:12:18 +00:00
|
|
|
|
2022-05-08 12:31:13 +00:00
|
|
|
fort_worker_func_set(&fort_device()->worker, FORT_WORKER_REAUTH, &fort_worker_reauth);
|
|
|
|
|
2021-03-17 13:12:18 +00:00
|
|
|
fort_device_conf_open(&fort_device()->conf);
|
|
|
|
fort_buffer_open(&fort_device()->buffer);
|
|
|
|
fort_stat_open(&fort_device()->stat);
|
2023-04-06 10:29:11 +00:00
|
|
|
fort_pending_open(&fort_device()->pending);
|
2023-01-04 15:16:23 +00:00
|
|
|
fort_shaper_open(&fort_device()->shaper);
|
2023-01-06 10:55:10 +00:00
|
|
|
fort_timer_open(&fort_device()->log_timer, 500, /*flags=*/0, &fort_callout_timer);
|
|
|
|
fort_timer_open(
|
|
|
|
&fort_device()->app_timer, 60000, FORT_TIMER_COALESCABLE, &fort_app_period_timer);
|
2022-01-07 09:12:12 +00:00
|
|
|
fort_pstree_open(&fort_device()->ps_tree);
|
2021-03-17 13:12:18 +00:00
|
|
|
|
2023-03-19 16:20:33 +00:00
|
|
|
/* Register filters provider */
|
|
|
|
status = fort_device_register_provider();
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
return status;
|
2021-03-17 13:12:18 +00:00
|
|
|
|
|
|
|
/* Install callouts */
|
2022-01-07 09:12:12 +00:00
|
|
|
status = fort_callout_install(device);
|
2023-03-19 16:20:33 +00:00
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
return status;
|
2021-03-17 13:12:18 +00:00
|
|
|
|
|
|
|
/* Register worker */
|
2023-03-19 16:20:33 +00:00
|
|
|
status = fort_worker_register(device, &fort_device()->worker);
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
return status;
|
2021-03-17 13:12:18 +00:00
|
|
|
|
|
|
|
/* Register power state change callback */
|
2023-03-19 16:20:33 +00:00
|
|
|
status = fort_syscb_power_register();
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
return status;
|
2021-03-17 13:12:18 +00:00
|
|
|
|
|
|
|
/* Register system time change callback */
|
2023-03-19 16:20:33 +00:00
|
|
|
status = fort_syscb_time_register();
|
|
|
|
if (!NT_SUCCESS(status))
|
|
|
|
return status;
|
2021-03-17 13:12:18 +00:00
|
|
|
|
2023-04-27 07:28:12 +00:00
|
|
|
/* Enumerate processes */
|
|
|
|
fort_pstree_enum_processes();
|
2022-02-07 11:46:11 +00:00
|
|
|
|
2023-03-19 16:20:33 +00:00
|
|
|
return STATUS_SUCCESS;
|
2021-03-17 13:12:18 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 12:31:48 +00:00
|
|
|
FORT_API void fort_device_unload(void)
|
2021-03-17 13:12:18 +00:00
|
|
|
{
|
2022-05-09 07:47:20 +00:00
|
|
|
/* Stop system notifiers */
|
|
|
|
fort_syscb_power_unregister();
|
|
|
|
fort_syscb_time_unregister();
|
2021-03-17 13:12:18 +00:00
|
|
|
|
2022-05-09 07:47:20 +00:00
|
|
|
/* Stop timers */
|
2021-03-17 13:12:18 +00:00
|
|
|
fort_timer_close(&fort_device()->app_timer);
|
|
|
|
fort_timer_close(&fort_device()->log_timer);
|
|
|
|
|
2022-05-09 07:47:20 +00:00
|
|
|
/* Stop worker threads */
|
2021-03-17 13:12:18 +00:00
|
|
|
fort_worker_unregister(&fort_device()->worker);
|
|
|
|
|
2022-05-09 07:47:20 +00:00
|
|
|
/* Stop process monitor */
|
|
|
|
fort_pstree_close(&fort_device()->ps_tree);
|
|
|
|
|
2023-04-06 10:29:11 +00:00
|
|
|
/* Stop packets shaper & pending */
|
2023-01-04 15:16:23 +00:00
|
|
|
fort_shaper_close(&fort_device()->shaper);
|
2023-04-06 10:29:11 +00:00
|
|
|
fort_pending_close(&fort_device()->pending);
|
2022-05-09 07:47:20 +00:00
|
|
|
|
|
|
|
/* Stop stat & buffer controllers */
|
|
|
|
fort_stat_close(&fort_device()->stat);
|
|
|
|
fort_buffer_close(&fort_device()->buffer);
|
2021-03-17 13:12:18 +00:00
|
|
|
|
2022-10-03 08:09:45 +00:00
|
|
|
/* Uninstall callouts */
|
|
|
|
fort_callout_remove();
|
|
|
|
|
|
|
|
/* Unregister filters provider */
|
2023-03-18 16:58:54 +00:00
|
|
|
if (fort_device_flag(&fort_device()->conf, FORT_DEVICE_BOOT_FILTER) == 0) {
|
2023-04-17 08:17:00 +00:00
|
|
|
fort_prov_trans_unregister();
|
2021-03-17 13:12:18 +00:00
|
|
|
}
|
|
|
|
}
|