mirror of
https://github.com/tnodir/fort
synced 2024-11-15 06:35:23 +00:00
Driver: Prepare add/del apps.
This commit is contained in:
parent
44a58a07bc
commit
786f250c57
1268
src/3rdparty/tlsf/tlsf.c
vendored
Normal file
1268
src/3rdparty/tlsf/tlsf.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
96
src/3rdparty/tlsf/tlsf.h
vendored
Normal file
96
src/3rdparty/tlsf/tlsf.h
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
#ifndef INCLUDED_tlsf
|
||||
#define INCLUDED_tlsf
|
||||
|
||||
/*
|
||||
** Two Level Segregated Fit memory allocator, version 3.1.
|
||||
** Written by Matthew Conte
|
||||
** http://tlsf.baisoku.org
|
||||
**
|
||||
** Based on the original documentation by Miguel Masmano:
|
||||
** http://www.gii.upv.es/tlsf/main/docs
|
||||
**
|
||||
** This implementation was written to the specification
|
||||
** of the document, therefore no GPL restrictions apply.
|
||||
**
|
||||
** Copyright (c) 2006-2016, Matthew Conte
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** * Neither the name of the copyright holder nor the
|
||||
** names of its contributors may be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
|
||||
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* Definition of the TLSF_API. */
|
||||
/* Provide the ability to override linkage features of the interface. */
|
||||
#if !defined(TLSF_API)
|
||||
#define TLSF_API
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
|
||||
/* pool_t: a block of memory that TLSF can manage. */
|
||||
typedef void* tlsf_t;
|
||||
typedef void* pool_t;
|
||||
|
||||
/* Create/destroy a memory pool. */
|
||||
TLSF_API tlsf_t tlsf_create(void* mem);
|
||||
TLSF_API tlsf_t tlsf_create_with_pool(void* mem, size_t bytes);
|
||||
TLSF_API void tlsf_destroy(tlsf_t tlsf);
|
||||
TLSF_API pool_t tlsf_get_pool(tlsf_t tlsf);
|
||||
|
||||
/* Add/remove memory pools. */
|
||||
TLSF_API pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
|
||||
TLSF_API void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
|
||||
|
||||
/* malloc/memalign/realloc/free replacements. */
|
||||
TLSF_API void* tlsf_malloc(tlsf_t tlsf, size_t bytes);
|
||||
TLSF_API void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes);
|
||||
TLSF_API void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size);
|
||||
TLSF_API void tlsf_free(tlsf_t tlsf, void* ptr);
|
||||
|
||||
/* Returns internal block size, not original request size */
|
||||
TLSF_API size_t tlsf_block_size(void* ptr);
|
||||
|
||||
/* Overheads/limits of internal structures. */
|
||||
TLSF_API size_t tlsf_size(void);
|
||||
TLSF_API size_t tlsf_align_size(void);
|
||||
TLSF_API size_t tlsf_block_size_min(void);
|
||||
TLSF_API size_t tlsf_block_size_max(void);
|
||||
TLSF_API size_t tlsf_pool_overhead(void);
|
||||
TLSF_API size_t tlsf_alloc_overhead(void);
|
||||
|
||||
/* Debugging. */
|
||||
typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
|
||||
TLSF_API void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
|
||||
/* Returns nonzero if any internal consistency check fails. */
|
||||
TLSF_API int tlsf_check(tlsf_t tlsf);
|
||||
TLSF_API int tlsf_check_pool(pool_t pool);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
4
src/3rdparty/tommyds/tommyhashdyn.c
vendored
4
src/3rdparty/tommyds/tommyhashdyn.c
vendored
@ -147,7 +147,7 @@ TOMMY_API void tommy_hashdyn_insert(tommy_hashdyn* hashdyn, tommy_hashdyn_node*
|
||||
hashdyn_grow_step(hashdyn);
|
||||
}
|
||||
|
||||
TOMMY_API void* tommy_hashdyn_remove_existing(tommy_hashdyn* hashdyn, tommy_hashdyn_node* node)
|
||||
TOMMY_API void tommy_hashdyn_remove_existing(tommy_hashdyn* hashdyn, tommy_hashdyn_node* node)
|
||||
{
|
||||
tommy_size_t pos = node->index & hashdyn->bucket_mask;
|
||||
|
||||
@ -156,8 +156,6 @@ TOMMY_API void* tommy_hashdyn_remove_existing(tommy_hashdyn* hashdyn, tommy_hash
|
||||
--hashdyn->count;
|
||||
|
||||
hashdyn_shrink_step(hashdyn);
|
||||
|
||||
return node->data;
|
||||
}
|
||||
|
||||
TOMMY_API void* tommy_hashdyn_remove(tommy_hashdyn* hashdyn, tommy_search_func* cmp, const void* cmp_arg, tommy_hash_t hash)
|
||||
|
3
src/3rdparty/tommyds/tommyhashdyn.h
vendored
3
src/3rdparty/tommyds/tommyhashdyn.h
vendored
@ -236,9 +236,8 @@ tommy_inline void* tommy_hashdyn_search(tommy_hashdyn* hashdyn, tommy_search_fun
|
||||
/**
|
||||
* Removes an element from the hashtable.
|
||||
* You must already have the address of the element to remove.
|
||||
* \return The tommy_node::data field of the node removed.
|
||||
*/
|
||||
TOMMY_API void* tommy_hashdyn_remove_existing(tommy_hashdyn* hashdyn, tommy_hashdyn_node* node);
|
||||
TOMMY_API void tommy_hashdyn_remove_existing(tommy_hashdyn* hashdyn, tommy_hashdyn_node* node);
|
||||
|
||||
/**
|
||||
* Calls the specified function for each element in the hashtable.
|
||||
|
35
src/3rdparty/tommyds/tommylist.h
vendored
35
src/3rdparty/tommyds/tommylist.h
vendored
@ -195,9 +195,8 @@ tommy_inline void tommy_list_insert_tail_not_empty(tommy_node* head, tommy_node*
|
||||
/**
|
||||
* Inserts an element at the head of a list.
|
||||
* \param node The node to insert.
|
||||
* \param data The object containing the node. It's used to set the tommy_node::data field of the node.
|
||||
*/
|
||||
tommy_inline void tommy_list_insert_head(tommy_list* list, tommy_node* node, void* data)
|
||||
tommy_inline void tommy_list_insert_head_check(tommy_list* list, tommy_node* node)
|
||||
{
|
||||
tommy_node* head = tommy_list_head(list);
|
||||
|
||||
@ -205,16 +204,13 @@ tommy_inline void tommy_list_insert_head(tommy_list* list, tommy_node* node, voi
|
||||
tommy_list_insert_head_not_empty(list, node);
|
||||
else
|
||||
tommy_list_insert_first(list, node);
|
||||
|
||||
node->data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts an element at the tail of a list.
|
||||
* \param node The node to insert.
|
||||
* \param data The object containing the node. It's used to set the tommy_node::data field of the node.
|
||||
*/
|
||||
tommy_inline void tommy_list_insert_tail(tommy_list* list, tommy_node* node, void* data)
|
||||
tommy_inline void tommy_list_insert_tail_check(tommy_list* list, tommy_node* node)
|
||||
{
|
||||
tommy_node* head = tommy_list_head(list);
|
||||
|
||||
@ -222,6 +218,28 @@ tommy_inline void tommy_list_insert_tail(tommy_list* list, tommy_node* node, voi
|
||||
tommy_list_insert_tail_not_empty(head, node);
|
||||
else
|
||||
tommy_list_insert_first(list, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts an element at the head of a list and sets the data.
|
||||
* \param node The node to insert.
|
||||
* \param data The object containing the node. It's used to set the tommy_node::data field of the node.
|
||||
*/
|
||||
tommy_inline void tommy_list_insert_head(tommy_list* list, tommy_node* node, void* data)
|
||||
{
|
||||
tommy_list_insert_head_check(list, node);
|
||||
|
||||
node->data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts an element at the tail of a list and sets the data.
|
||||
* \param node The node to insert.
|
||||
* \param data The object containing the node. It's used to set the tommy_node::data field of the node.
|
||||
*/
|
||||
tommy_inline void tommy_list_insert_tail(tommy_list* list, tommy_node* node, void* data)
|
||||
{
|
||||
tommy_list_insert_tail_check(list, node);
|
||||
|
||||
node->data = data;
|
||||
}
|
||||
@ -232,9 +250,8 @@ tommy_inline void tommy_list_insert_tail(tommy_list* list, tommy_node* node, voi
|
||||
* \note The node content is left unchanged, including the tommy_node::next
|
||||
* and tommy_node::prev fields that still contain pointers at the list.
|
||||
* \param node The node to remove. The node must be in the list.
|
||||
* \return The tommy_node::data field of the node removed.
|
||||
*/
|
||||
tommy_inline void* tommy_list_remove_existing(tommy_list* list, tommy_node* node)
|
||||
tommy_inline void tommy_list_remove_existing(tommy_list* list, tommy_node* node)
|
||||
{
|
||||
tommy_node* head = tommy_list_head(list);
|
||||
|
||||
@ -249,8 +266,6 @@ tommy_inline void* tommy_list_remove_existing(tommy_list* list, tommy_node* node
|
||||
*list = node->next; /* the new head, in case 0 */
|
||||
else
|
||||
node->prev->next = node->next;
|
||||
|
||||
return node->data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,6 +83,8 @@ DEFINE_GUID(FORT_GUID_FILTER_REAUTH_OUT,
|
||||
#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)
|
||||
|
||||
|
||||
#ifndef NT_SUCCESS
|
||||
|
@ -100,8 +100,8 @@ fort_conf_ip_included (const PFORT_CONF conf, UINT32 remote_ip,
|
||||
fort_conf_ip_included((conf), (remote_ip), 1)
|
||||
|
||||
static BOOL
|
||||
fort_conf_app_exe_equal (UINT32 path_len, const char *path,
|
||||
PFORT_APP_ENTRY app_entry)
|
||||
fort_conf_app_exe_equal (PFORT_APP_ENTRY app_entry,
|
||||
const char *path, UINT32 path_len)
|
||||
{
|
||||
const char *app_path = (const char *) (app_entry + 1);
|
||||
const UINT32 app_path_len = app_entry->path_len;
|
||||
@ -114,7 +114,7 @@ fort_conf_app_exe_equal (UINT32 path_len, const char *path,
|
||||
|
||||
static FORT_APP_FLAGS
|
||||
fort_conf_app_exe_find (const PFORT_CONF conf,
|
||||
UINT32 path_len, const char *path)
|
||||
const char *path, UINT32 path_len)
|
||||
{
|
||||
FORT_APP_FLAGS app_flags;
|
||||
const char *data;
|
||||
@ -130,7 +130,7 @@ fort_conf_app_exe_find (const PFORT_CONF conf,
|
||||
do {
|
||||
const PFORT_APP_ENTRY app_entry = (const PFORT_APP_ENTRY) app_entries;
|
||||
|
||||
if (fort_conf_app_exe_equal(path_len, path, app_entry)) {
|
||||
if (fort_conf_app_exe_equal(app_entry, path, path_len)) {
|
||||
app_flags = app_entry->flags;
|
||||
goto end;
|
||||
}
|
||||
@ -146,8 +146,8 @@ fort_conf_app_exe_find (const PFORT_CONF conf,
|
||||
}
|
||||
|
||||
static int
|
||||
fort_conf_app_prefix_cmp (UINT32 path_len, const char *path,
|
||||
PFORT_APP_ENTRY app_entry)
|
||||
fort_conf_app_prefix_cmp (PFORT_APP_ENTRY app_entry,
|
||||
const char *path, UINT32 path_len)
|
||||
{
|
||||
const char *app_path = (const char *) (app_entry + 1);
|
||||
const UINT32 app_path_len = app_entry->path_len;
|
||||
@ -160,7 +160,7 @@ fort_conf_app_prefix_cmp (UINT32 path_len, const char *path,
|
||||
|
||||
static FORT_APP_FLAGS
|
||||
fort_conf_app_prefix_find (const PFORT_CONF conf,
|
||||
UINT32 path_len, const char *path)
|
||||
const char *path, UINT32 path_len)
|
||||
{
|
||||
FORT_APP_FLAGS app_flags;
|
||||
const char *data;
|
||||
@ -182,7 +182,7 @@ fort_conf_app_prefix_find (const PFORT_CONF conf,
|
||||
const int mid = (low + high) / 2;
|
||||
const UINT32 app_off = app_offsets[mid];
|
||||
const PFORT_APP_ENTRY app_entry = (PFORT_APP_ENTRY) (app_entries + app_off);
|
||||
const int res = fort_conf_app_prefix_cmp(path_len, path, app_entry);
|
||||
const int res = fort_conf_app_prefix_cmp(app_entry, path, path_len);
|
||||
|
||||
if (res < 0)
|
||||
high = mid - 1;
|
||||
@ -237,16 +237,16 @@ fort_conf_app_wild_find (const PFORT_CONF conf, const char *path)
|
||||
|
||||
static FORT_APP_FLAGS
|
||||
fort_conf_app_find (const PFORT_CONF conf,
|
||||
UINT32 path_len, const char *path,
|
||||
const char *path, UINT32 path_len,
|
||||
fort_conf_app_exe_find_func *exe_find_func)
|
||||
{
|
||||
FORT_APP_FLAGS app_flags;
|
||||
|
||||
app_flags = exe_find_func(conf, path_len, path);
|
||||
app_flags = exe_find_func(conf, path, path_len);
|
||||
if (app_flags.v != 0)
|
||||
goto end;
|
||||
|
||||
app_flags = fort_conf_app_prefix_find(conf, path_len, path);
|
||||
app_flags = fort_conf_app_prefix_find(conf, path, path_len);
|
||||
if (app_flags.v != 0)
|
||||
goto end;
|
||||
|
||||
@ -259,7 +259,7 @@ fort_conf_app_find (const PFORT_CONF conf,
|
||||
static BOOL
|
||||
fort_conf_app_blocked (const PFORT_CONF conf, FORT_APP_FLAGS app_flags)
|
||||
{
|
||||
const BOOL app_found = app_flags.found;
|
||||
const BOOL app_found = (app_flags.v != 0);
|
||||
|
||||
if (app_found && !app_flags.use_group_perm) {
|
||||
return app_flags.blocked;
|
||||
|
@ -76,7 +76,9 @@ typedef struct fort_app_flags {
|
||||
UCHAR group_index;
|
||||
UCHAR use_group_perm : 1;
|
||||
UCHAR blocked : 1;
|
||||
UCHAR found : 1;
|
||||
UCHAR alerted : 1;
|
||||
UCHAR in_conf : 1;
|
||||
UCHAR in_pool : 1;
|
||||
};
|
||||
};
|
||||
} FORT_APP_FLAGS, *PFORT_APP_FLAGS;
|
||||
@ -141,6 +143,6 @@ typedef struct fort_conf_io {
|
||||
#define FORT_CONF_ADDR_DATA_OFF offsetof(FORT_CONF_ADDR_GROUP, ip)
|
||||
|
||||
typedef FORT_APP_FLAGS fort_conf_app_exe_find_func(
|
||||
const PFORT_CONF conf, UINT32 path_len, const char *path);
|
||||
const PFORT_CONF conf, const char *path, UINT32 path_len);
|
||||
|
||||
#endif FORTCONF_H
|
||||
|
@ -1,14 +1,15 @@
|
||||
/* Fort Firewall Configuration */
|
||||
|
||||
#define FORT_CONF_BLOCK_SIZE (8 * 1024)
|
||||
#define FORT_CONF_POOL_SIZE (8 * 1024)
|
||||
#define FORT_CONF_POOL_DATA_OFF offsetof(FORT_CONF_POOL, data)
|
||||
|
||||
/* Synchronize with tommy_node! */
|
||||
typedef struct fort_conf_block {
|
||||
struct fort_conf_block *next;
|
||||
struct fort_conf_block *prev;
|
||||
typedef struct fort_conf_pool {
|
||||
struct fort_conf_pool *next;
|
||||
struct fort_conf_pool *prev;
|
||||
|
||||
UINT16 top;
|
||||
} FORT_CONF_BLOCK, *PFORT_CONF_BLOCK;
|
||||
char data[4];
|
||||
} FORT_CONF_POOL, *PFORT_CONF_POOL;
|
||||
|
||||
/* Synchronize with tommy_hashdyn_node! */
|
||||
typedef struct fort_conf_exe_node {
|
||||
@ -23,7 +24,9 @@ typedef struct fort_conf_exe_node {
|
||||
typedef struct fort_conf_ref {
|
||||
UINT32 volatile refcount;
|
||||
|
||||
tommy_list exe_blocks;
|
||||
tlsf_t tlsf;
|
||||
tommy_list pools;
|
||||
tommy_list free_nodes;
|
||||
|
||||
tommy_arrayof exe_nodes;
|
||||
tommy_hashdyn exe_map;
|
||||
@ -71,32 +74,92 @@ fort_device_flag (PFORT_DEVICE_CONF device_conf, UCHAR flag)
|
||||
return fort_device_flags(device_conf) & flag;
|
||||
}
|
||||
|
||||
static FORT_APP_FLAGS
|
||||
fort_conf_ref_exe_find (const PFORT_CONF conf,
|
||||
UINT32 path_len, const char *path)
|
||||
static void
|
||||
fort_conf_pool_done (PFORT_CONF_REF conf_ref)
|
||||
{
|
||||
PFORT_CONF_REF conf_ref = (PFORT_CONF_REF) ((char *) conf - offsetof(FORT_CONF_REF, conf));
|
||||
const tommy_key_t path_hash = (tommy_key_t) tommy_hash_u64(
|
||||
0, path, path_len);
|
||||
tommy_node *pool = tommy_list_head(&conf_ref->pools);
|
||||
while (pool != NULL) {
|
||||
tommy_node *next = pool->next;
|
||||
tommy_free(pool);
|
||||
pool = next;
|
||||
}
|
||||
}
|
||||
|
||||
static void *
|
||||
fort_conf_pool_malloc (PFORT_CONF_REF conf_ref, UINT32 size)
|
||||
{
|
||||
tommy_node *pool = tommy_list_tail(&conf_ref->pools);
|
||||
void *p;
|
||||
|
||||
if (pool == NULL) {
|
||||
const UINT32 pool_size = (size >= FORT_CONF_POOL_SIZE)
|
||||
? size * 2 : FORT_CONF_POOL_SIZE;
|
||||
|
||||
pool = tommy_malloc(pool_size);
|
||||
if (pool == NULL)
|
||||
return NULL;
|
||||
|
||||
tommy_list_insert_first(&conf_ref->pools, pool);
|
||||
|
||||
conf_ref->tlsf = tlsf_create_with_pool(
|
||||
(char *) pool + FORT_CONF_POOL_DATA_OFF,
|
||||
pool_size - FORT_CONF_POOL_DATA_OFF);
|
||||
}
|
||||
|
||||
p = tlsf_malloc(conf_ref->tlsf, size);
|
||||
if (p == NULL) {
|
||||
const UINT32 pool_size = (size >= FORT_CONF_POOL_SIZE)
|
||||
? size * 2 : FORT_CONF_POOL_SIZE;
|
||||
|
||||
pool = tommy_malloc(pool_size);
|
||||
if (pool == NULL)
|
||||
return NULL;
|
||||
|
||||
tommy_list_insert_head_not_empty(&conf_ref->pools, pool);
|
||||
|
||||
tlsf_add_pool(conf_ref->tlsf,
|
||||
(char *) pool + FORT_CONF_POOL_DATA_OFF,
|
||||
pool_size - FORT_CONF_POOL_DATA_OFF);
|
||||
|
||||
p = tlsf_malloc(conf_ref->tlsf, size);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static PFORT_CONF_EXE_NODE
|
||||
fort_conf_ref_exe_find_node (PFORT_CONF_REF conf_ref,
|
||||
const char *path, UINT32 path_len,
|
||||
tommy_key_t path_hash)
|
||||
{
|
||||
PFORT_CONF_EXE_NODE node = (PFORT_CONF_EXE_NODE) tommy_hashdyn_bucket(
|
||||
&conf_ref->exe_map, path_hash);
|
||||
|
||||
FORT_APP_FLAGS app_flags;
|
||||
app_flags.v = 0;
|
||||
|
||||
while (node != NULL) {
|
||||
PFORT_APP_ENTRY entry = node->app_entry;
|
||||
|
||||
if (node->path_hash == path_hash
|
||||
&& fort_conf_app_exe_equal(path_len, path, entry)) {
|
||||
app_flags = entry->flags;
|
||||
break;
|
||||
&& fort_conf_app_exe_equal(node->app_entry, path, path_len)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static FORT_APP_FLAGS
|
||||
fort_conf_exe_find (const PFORT_CONF conf,
|
||||
const char *path, UINT32 path_len)
|
||||
{
|
||||
PFORT_CONF_REF conf_ref = (PFORT_CONF_REF) ((char *) conf - offsetof(FORT_CONF_REF, conf));
|
||||
const tommy_key_t path_hash = (tommy_key_t) tommy_hash_u64(0, path, path_len);
|
||||
|
||||
const PFORT_CONF_EXE_NODE node = fort_conf_ref_exe_find_node(
|
||||
conf_ref, path, path_len, path_hash);
|
||||
|
||||
FORT_APP_FLAGS app_flags;
|
||||
app_flags.v = node ? node->app_entry->flags.v : 0;
|
||||
|
||||
return app_flags;
|
||||
}
|
||||
|
||||
@ -117,7 +180,7 @@ fort_conf_ref_exe_fill (PFORT_CONF_REF conf_ref)
|
||||
for (i = 0; i < count; ++i) {
|
||||
const PFORT_APP_ENTRY entry = (const PFORT_APP_ENTRY) app_entries;
|
||||
const char *path = (const char *) (entry + 1);
|
||||
const UINT16 path_len = entry->path_len;
|
||||
const UINT32 path_len = entry->path_len;
|
||||
const tommy_key_t path_hash = (tommy_key_t) tommy_hash_u64(0, path, path_len);
|
||||
|
||||
tommy_hashdyn_node *node = tommy_arrayof_ref(exe_nodes, i);
|
||||
@ -128,12 +191,133 @@ fort_conf_ref_exe_fill (PFORT_CONF_REF conf_ref)
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL
|
||||
fort_conf_ref_exe_add_path (PFORT_CONF_REF conf_ref,
|
||||
const char *path, UINT32 path_len,
|
||||
FORT_APP_FLAGS flags)
|
||||
{
|
||||
const tommy_key_t path_hash = (tommy_key_t) tommy_hash_u64(0, path, path_len);
|
||||
|
||||
const PFORT_CONF_EXE_NODE node = fort_conf_ref_exe_find_node(
|
||||
conf_ref, path, path_len, path_hash);
|
||||
|
||||
if (node == NULL) {
|
||||
const UINT16 entry_size = FORT_CONF_APP_ENTRY_SIZE(path_len);
|
||||
PFORT_APP_ENTRY entry = fort_conf_pool_malloc(conf_ref, entry_size);
|
||||
|
||||
if (entry == NULL)
|
||||
return FALSE;
|
||||
|
||||
flags.in_pool = 1;
|
||||
entry->flags = flags;
|
||||
|
||||
entry->path_len = (UINT16) path_len;
|
||||
|
||||
// Copy path
|
||||
{
|
||||
char *new_path = (char *) (entry + 1);
|
||||
RtlCopyMemory(new_path, path, path_len);
|
||||
}
|
||||
|
||||
// Add exe node
|
||||
{
|
||||
PFORT_CONF conf = &conf_ref->conf;
|
||||
|
||||
tommy_arrayof *exe_nodes = &conf_ref->exe_nodes;
|
||||
tommy_hashdyn *exe_map = &conf_ref->exe_map;
|
||||
|
||||
tommy_hashdyn_node *node = tommy_list_tail(&conf_ref->free_nodes);
|
||||
|
||||
if (node != NULL) {
|
||||
tommy_list_remove_existing(&conf_ref->free_nodes, node);
|
||||
} else {
|
||||
const UINT16 index = conf->exe_apps_n;
|
||||
|
||||
tommy_arrayof_grow(exe_nodes, index + 1);
|
||||
|
||||
node = tommy_arrayof_ref(exe_nodes, index);
|
||||
}
|
||||
|
||||
tommy_hashdyn_insert(exe_map, node, entry, path_hash);
|
||||
|
||||
++conf->exe_apps_n;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (flags.alerted)
|
||||
return FALSE;
|
||||
|
||||
// Replace flags
|
||||
{
|
||||
PFORT_APP_ENTRY entry = node->app_entry;
|
||||
|
||||
flags.in_pool = entry->flags.in_pool;
|
||||
entry->flags = flags;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL
|
||||
fort_conf_ref_exe_add_entry (PFORT_CONF_REF conf_ref, const PFORT_APP_ENTRY entry)
|
||||
{
|
||||
const char *path = (const char *) (entry + 1);
|
||||
const UINT32 path_len = entry->path_len;
|
||||
const FORT_APP_FLAGS flags = entry->flags;
|
||||
|
||||
return fort_conf_ref_exe_add_path(conf_ref, path, path_len, flags);
|
||||
}
|
||||
|
||||
static void
|
||||
fort_conf_ref_exe_del_path (PFORT_CONF_REF conf_ref,
|
||||
const char *path, UINT32 path_len)
|
||||
{
|
||||
const tommy_key_t path_hash = (tommy_key_t) tommy_hash_u64(0, path, path_len);
|
||||
|
||||
PFORT_CONF_EXE_NODE node = fort_conf_ref_exe_find_node(
|
||||
conf_ref, path, path_len, path_hash);
|
||||
|
||||
if (node == NULL)
|
||||
return;
|
||||
|
||||
// Delete from conf
|
||||
{
|
||||
PFORT_CONF conf = &conf_ref->conf;
|
||||
--conf->exe_apps_n;
|
||||
}
|
||||
|
||||
// Delete from pool
|
||||
{
|
||||
PFORT_APP_ENTRY entry = node->app_entry;
|
||||
if (entry->flags.in_pool) {
|
||||
tlsf_free(conf_ref->tlsf, entry);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete from exe map
|
||||
tommy_hashdyn_remove_existing(&conf_ref->exe_map, (tommy_hashdyn_node *) node);
|
||||
|
||||
tommy_list_insert_tail_check(&conf_ref->free_nodes, (tommy_node *) node);
|
||||
}
|
||||
|
||||
static void
|
||||
fort_conf_ref_exe_del_entry (PFORT_CONF_REF conf_ref, const PFORT_APP_ENTRY entry)
|
||||
{
|
||||
const char *path = (const char *) (entry + 1);
|
||||
const UINT32 path_len = entry->path_len;
|
||||
|
||||
fort_conf_ref_exe_del_path(conf_ref, path, path_len);
|
||||
}
|
||||
|
||||
static void
|
||||
fort_conf_ref_init (PFORT_CONF_REF conf_ref)
|
||||
{
|
||||
conf_ref->refcount = 0;
|
||||
|
||||
tommy_list_init(&conf_ref->exe_blocks);
|
||||
tommy_list_init(&conf_ref->pools);
|
||||
tommy_list_init(&conf_ref->free_nodes);
|
||||
|
||||
tommy_arrayof_init(&conf_ref->exe_nodes, sizeof(FORT_CONF_EXE_NODE));
|
||||
tommy_hashdyn_init(&conf_ref->exe_map);
|
||||
@ -158,13 +342,7 @@ fort_conf_ref_new (const PFORT_CONF conf, ULONG len)
|
||||
static void
|
||||
fort_conf_ref_del (PFORT_CONF_REF conf_ref)
|
||||
{
|
||||
/* Delete exe blocks */
|
||||
tommy_node *exe_block = tommy_list_head(&conf_ref->exe_blocks);
|
||||
while (exe_block) {
|
||||
tommy_node *next = exe_block->next;
|
||||
tommy_free(exe_block);
|
||||
exe_block = next;
|
||||
}
|
||||
fort_conf_pool_done(conf_ref);
|
||||
|
||||
tommy_hashdyn_done(&conf_ref->exe_map);
|
||||
tommy_arrayof_done(&conf_ref->exe_nodes);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "../common/fortconf.c"
|
||||
#include "../common/fortlog.c"
|
||||
#include "../common/fortprov.c"
|
||||
#include "forttlsf.c"
|
||||
#include "forttds.c"
|
||||
#include "fortcnf.c"
|
||||
#include "fortbuf.c"
|
||||
@ -143,7 +144,7 @@ fort_callout_classify_v4 (const FWPS_INCOMING_VALUES0 *inFixedValues,
|
||||
|
||||
if (fort_conf_ip_inet_included(&conf_ref->conf, remote_ip)) {
|
||||
const FORT_APP_FLAGS app_flags = fort_conf_app_find(
|
||||
&conf_ref->conf, path_len, path, fort_conf_ref_exe_find);
|
||||
&conf_ref->conf, path, path_len, fort_conf_exe_find);
|
||||
|
||||
if (!fort_conf_app_blocked(&conf_ref->conf, app_flags)) {
|
||||
if (conf_flags.log_stat) {
|
||||
@ -179,14 +180,21 @@ fort_callout_classify_v4 (const FWPS_INCOMING_VALUES0 *inFixedValues,
|
||||
}
|
||||
|
||||
if (conf_flags.log_blocked) {
|
||||
const UINT16 remote_port = inFixedValues->incomingValue[
|
||||
remotePortField].value.uint16;
|
||||
const IPPROTO ip_proto = (IPPROTO) inFixedValues->incomingValue[
|
||||
ipProtoField].value.uint8;
|
||||
FORT_APP_FLAGS flags;
|
||||
flags.v = 0;
|
||||
flags.blocked = 1;
|
||||
flags.alerted = 1;
|
||||
|
||||
fort_buffer_blocked_write(&g_device->buffer,
|
||||
remote_ip, remote_port, ip_proto,
|
||||
process_id, path_len, path, &irp, &info);
|
||||
if (fort_conf_ref_exe_add_path(conf_ref, path, path_len, flags)) {
|
||||
const UINT16 remote_port = inFixedValues->incomingValue[
|
||||
remotePortField].value.uint16;
|
||||
const IPPROTO ip_proto = (IPPROTO) inFixedValues->incomingValue[
|
||||
ipProtoField].value.uint8;
|
||||
|
||||
fort_buffer_blocked_write(&g_device->buffer,
|
||||
remote_ip, remote_port, ip_proto,
|
||||
process_id, path_len, path, &irp, &info);
|
||||
}
|
||||
}
|
||||
|
||||
block:
|
||||
@ -968,11 +976,13 @@ fort_device_control (PDEVICE_OBJECT device, PIRP irp)
|
||||
{
|
||||
PIO_STACK_LOCATION irp_stack;
|
||||
ULONG_PTR info = 0;
|
||||
ULONG control_code;
|
||||
NTSTATUS status = STATUS_INVALID_PARAMETER;
|
||||
|
||||
irp_stack = IoGetCurrentIrpStackLocation(irp);
|
||||
control_code = irp_stack->Parameters.DeviceIoControl.IoControlCode;
|
||||
|
||||
switch (irp_stack->Parameters.DeviceIoControl.IoControlCode) {
|
||||
switch (control_code) {
|
||||
case FORT_IOCTL_VALIDATE: {
|
||||
const PFORT_CONF_VERSION conf_ver = irp->AssociatedIrp.SystemBuffer;
|
||||
const ULONG len = irp_stack->Parameters.DeviceIoControl.InputBufferLength;
|
||||
@ -1049,6 +1059,31 @@ fort_device_control (PDEVICE_OBJECT device, PIRP irp)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FORT_IOCTL_ADDAPP:
|
||||
case FORT_IOCTL_DELAPP: {
|
||||
const PFORT_APP_ENTRY app_entry = irp->AssociatedIrp.SystemBuffer;
|
||||
const ULONG len = irp_stack->Parameters.DeviceIoControl.InputBufferLength;
|
||||
|
||||
if (len > sizeof(FORT_APP_ENTRY)
|
||||
&& len >= (sizeof(FORT_APP_ENTRY) + app_entry->path_len)) {
|
||||
PFORT_CONF_REF conf_ref = fort_conf_ref_take(&g_device->conf);
|
||||
|
||||
if (conf_ref == NULL) {
|
||||
status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
} else {
|
||||
if (control_code == FORT_IOCTL_ADDAPP) {
|
||||
status = fort_conf_ref_exe_add_entry(conf_ref, app_entry)
|
||||
? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
|
||||
} else {
|
||||
fort_conf_ref_exe_del_entry(conf_ref, app_entry);
|
||||
status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
fort_conf_ref_put(&g_device->conf, conf_ref);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
6
src/driver/forttlsf.c
Normal file
6
src/driver/forttlsf.c
Normal file
@ -0,0 +1,6 @@
|
||||
/* Fort Firewall TLSF */
|
||||
|
||||
#define TLSF_API static
|
||||
#define tlsf_printf
|
||||
|
||||
#include "..\3rdparty\tlsf\tlsf.c"
|
@ -72,7 +72,7 @@ void ProgramsWindow::onRestoreWindowState()
|
||||
|
||||
void ProgramsWindow::onRetranslateUi()
|
||||
{
|
||||
m_cbLogBlocked->setText(tr("Show Blocked Programs"));
|
||||
m_cbLogBlocked->setText(tr("Alert Blocked Programs"));
|
||||
|
||||
appListModel()->refresh();
|
||||
}
|
||||
|
@ -165,11 +165,11 @@ quint16 FortCommon::confAppFind(const void *drvConf,
|
||||
{
|
||||
const PFORT_CONF conf = (const PFORT_CONF) drvConf;
|
||||
const QString kernelPathLower = kernelPath.toLower();
|
||||
const int len = kernelPathLower.size() * int(sizeof(wchar_t));
|
||||
const quint32 len = quint32(kernelPathLower.size()) * sizeof(wchar_t);
|
||||
const wchar_t *p = (const wchar_t *) kernelPathLower.utf16();
|
||||
|
||||
const FORT_APP_FLAGS app_flags =
|
||||
fort_conf_app_find(conf, len, (const char *) p,
|
||||
fort_conf_app_find(conf, (const char *) p, len,
|
||||
fort_conf_app_exe_find);
|
||||
|
||||
return app_flags.v;
|
||||
|
@ -32,9 +32,9 @@ void AppListModel::addLogEntry(const LogEntryBlocked &logEntry)
|
||||
+ ':' + QString::number(logEntry.port());
|
||||
#endif
|
||||
|
||||
beginResetModel();
|
||||
confManager()->addApp(appPath, QDateTime(), 0, true, true);
|
||||
endResetModel();
|
||||
if (confManager()->addApp(appPath, QDateTime(), 0, true, true)) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
int AppListModel::rowCount(const QModelIndex &parent) const
|
||||
|
@ -69,8 +69,9 @@ QVariant TaskListModel::data(const QModelIndex &index, int role) const
|
||||
case 2: return formatDateTime(taskInfo->lastRun());
|
||||
case 3: return formatDateTime(taskInfo->lastSuccess());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::CheckStateRole:
|
||||
case RoleEnabled:
|
||||
|
@ -294,7 +294,7 @@ bool ConfUtil::parseApps(int groupOffset, bool blocked, const QString &text,
|
||||
appEntry.flags.group_index = quint8(groupOffset);
|
||||
appEntry.flags.use_group_perm = 1;
|
||||
appEntry.flags.blocked = blocked;
|
||||
appEntry.flags.found = 1;
|
||||
appEntry.flags.in_conf = 1;
|
||||
|
||||
appsMap.insert(appPath, appEntry.v);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user