Conf: Add version and data offset.

This commit is contained in:
Nodir Temirkhodjaev 2015-02-04 12:29:27 +05:00
parent e43cec4d49
commit 6575b1a927
6 changed files with 27 additions and 11 deletions

View File

@ -6,6 +6,15 @@ local sys = require"sys"
local persist, boot local persist, boot
if #arg == 0 then
print[[
Usage: luajit.exe scripts/provider.lua <arguments>
Argumets:
persist ... Register provider, otherwise unregister
boot ...... Block access to network when WIPF is not running
]]
end
-- Process arguments -- Process arguments
for _, v in ipairs(arg) do for _, v in ipairs(arg) do
if v == "persist" then if v == "persist" then

View File

@ -333,7 +333,7 @@ wipf_device_control (PDEVICE_OBJECT device, PIRP irp)
const PWIPF_CONF conf = irp->AssociatedIrp.SystemBuffer; const PWIPF_CONF conf = irp->AssociatedIrp.SystemBuffer;
const ULONG len = irp_stack->Parameters.DeviceIoControl.InputBufferLength; const ULONG len = irp_stack->Parameters.DeviceIoControl.InputBufferLength;
if (len > WIPF_CONF_SIZE_MIN) { if (len > WIPF_CONF_DATA_OFF) {
PWIPF_CONF_REF conf_ref = wipf_conf_ref_new(conf, len); PWIPF_CONF_REF conf_ref = wipf_conf_ref_new(conf, len);
if (conf_ref == NULL) { if (conf_ref == NULL) {

View File

@ -192,7 +192,7 @@ wipf_lua_conf_buffer_size (lua_State *L)
|| apps_len > WIPF_CONF_APPS_LEN_MAX) || apps_len > WIPF_CONF_APPS_LEN_MAX)
return 0; return 0;
lua_pushinteger(L, WIPF_CONF_SIZE_MIN lua_pushinteger(L, WIPF_CONF_DATA_OFF
+ (ip_include_n + ip_exclude_n) * 2 * sizeof(UINT32) + (ip_include_n + ip_exclude_n) * 2 * sizeof(UINT32)
+ (groups_n + apps_n) * sizeof(UINT32) + (groups_n + apps_n) * sizeof(UINT32)
+ groups_len + apps_len + groups_len + apps_len
@ -267,7 +267,7 @@ wipf_lua_conf_write (lua_State *L)
groups_off = data_offset; groups_off = data_offset;
wipf_lua_conf_write_strtable(L, 18, groups_n, &data); /* groups */ wipf_lua_conf_write_strtable(L, 18, groups_n, &data); /* groups */
conf_size = WIPF_CONF_SIZE_MIN + data_offset; conf_size = WIPF_CONF_DATA_OFF + data_offset;
#undef data_offset #undef data_offset
conf->ip_include_all = ip_include_all; conf->ip_include_all = ip_include_all;
@ -276,6 +276,9 @@ wipf_lua_conf_write (lua_State *L)
conf->app_block_all = app_block_all; conf->app_block_all = app_block_all;
conf->app_allow_all = app_allow_all; conf->app_allow_all = app_allow_all;
conf->conf_version = WIPF_CONF_VERSION;
conf->data_off = WIPF_CONF_DATA_OFF;
conf->ip_include_n = ip_include_n; conf->ip_include_n = ip_include_n;
conf->ip_exclude_n = ip_exclude_n; conf->ip_exclude_n = ip_exclude_n;
@ -363,7 +366,7 @@ static int
wipf_lua_conf_read (lua_State *L) wipf_lua_conf_read (lua_State *L)
{ {
const PWIPF_CONF conf = lua_touserdata(L, 1); const PWIPF_CONF conf = lua_touserdata(L, 1);
const char *data = (const char *) &conf->data; const char *data = (const char *) conf + conf->data_off;
if (!conf) return 0; if (!conf) return 0;
@ -409,7 +412,7 @@ wipf_lua_conf_ip_inrange (lua_State *L)
const PWIPF_CONF conf = lua_touserdata(L, 1); const PWIPF_CONF conf = lua_touserdata(L, 1);
const UINT32 ip = (UINT32) lua_tonumber(L, 2); const UINT32 ip = (UINT32) lua_tonumber(L, 2);
const BOOL included = lua_toboolean(L, 3); const BOOL included = lua_toboolean(L, 3);
const char *data = (const char *) &conf->data; const char *data = (const char *) conf + conf->data_off;
const UINT32 count = included ? conf->ip_include_n : conf->ip_exclude_n; const UINT32 count = included ? conf->ip_include_n : conf->ip_exclude_n;
const UINT32 from_off = included ? conf->ip_from_include_off : conf->ip_from_exclude_off; const UINT32 from_off = included ? conf->ip_from_include_off : conf->ip_from_exclude_off;

View File

@ -36,7 +36,7 @@ wipf_conf_ip_inrange (UINT32 ip, UINT32 count,
static BOOL static BOOL
wipf_conf_ip_included (const PWIPF_CONF conf, UINT32 remote_ip) wipf_conf_ip_included (const PWIPF_CONF conf, UINT32 remote_ip)
{ {
const char *data = (const char *) &conf->data; const char *data = (const char *) conf + conf->data_off;
const BOOL ip_included = conf->ip_include_all ? TRUE const BOOL ip_included = conf->ip_include_all ? TRUE
: wipf_conf_ip_inrange(remote_ip, conf->ip_include_n, : wipf_conf_ip_inrange(remote_ip, conf->ip_include_n,
@ -115,7 +115,7 @@ static BOOL
wipf_conf_app_blocked (const PWIPF_CONF conf, wipf_conf_app_blocked (const PWIPF_CONF conf,
UINT32 path_len, const char *path, BOOL *notify) UINT32 path_len, const char *path, BOOL *notify)
{ {
const char *data = (const char *) &conf->data; const char *data = (const char *) conf + conf->data_off;
const int app_index = wipf_conf_app_index(path_len, path, conf->apps_n, const int app_index = wipf_conf_app_index(path_len, path, conf->apps_n,
(const UINT32 *) (data + conf->apps_off)); (const UINT32 *) (data + conf->apps_off));
const UINT32 *apps_perms = (const UINT32 *) (data + conf->apps_perms_off); const UINT32 *apps_perms = (const UINT32 *) (data + conf->apps_perms_off);

View File

@ -7,7 +7,10 @@ typedef struct wipf_conf {
UINT32 app_log_blocked : 1; UINT32 app_log_blocked : 1;
UINT32 app_block_all : 1; UINT32 app_block_all : 1;
UINT32 app_allow_all : 1; UINT32 app_allow_all : 1;
UINT32 group_bits : 10; UINT32 group_bits : 16;
UINT16 conf_version;
UINT16 data_off;
UINT16 ip_include_n; UINT16 ip_include_n;
UINT16 ip_exclude_n; UINT16 ip_exclude_n;
@ -31,7 +34,8 @@ typedef struct wipf_conf {
UCHAR data[4]; UCHAR data[4];
} WIPF_CONF, *PWIPF_CONF; } WIPF_CONF, *PWIPF_CONF;
#define WIPF_CONF_SIZE_MIN offsetof(WIPF_CONF, data) #define WIPF_CONF_VERSION 1
#define WIPF_CONF_DATA_OFF offsetof(WIPF_CONF, data)
#define WIPF_CONF_IP_MAX (1 * 1024 * 1024) #define WIPF_CONF_IP_MAX (1 * 1024 * 1024)
#define WIPF_CONF_GROUP_MAX 16 #define WIPF_CONF_GROUP_MAX 16
#define WIPF_CONF_GROUP_NAME_MAX 256 #define WIPF_CONF_GROUP_NAME_MAX 256

View File

@ -158,8 +158,8 @@ do
assert(not wipf.conf_ip_inrange(conf_bin, sock.inet_pton("193.0.0.0", true))) assert(not wipf.conf_ip_inrange(conf_bin, sock.inet_pton("193.0.0.0", true)))
assert(wipf.conf_app_blocked(conf_bin, util_fs.path_to_dospath[[System]])) assert(wipf.conf_app_blocked(conf_bin, util_fs.path_to_dospath[[System]]))
assert(not wipf.conf_app_blocked(conf_bin, util_fs.path_to_dospath[[C:\Programs\Skype\Phone\Skype.exe]])) assert(not wipf.conf_app_blocked(conf_bin, util_fs.path_to_dospath[[C:\programs\skype\phone\skype.exe]]))
assert(not wipf.conf_app_blocked(conf_bin, util_fs.path_to_dospath[[C:\Utils\Dev\Git\bin\git.exe]])) assert(not wipf.conf_app_blocked(conf_bin, util_fs.path_to_dospath[[C:\utils\dev\git\bin\git.exe]]))
print("OK") print("OK")
end end