From b3370c013c1a02a96f055c8c57928f084afc1b4c Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sun, 6 Sep 2020 15:29:13 +0300 Subject: [PATCH] Driver: Reformat common/. --- src/driver/common/fortconf.c | 46 ++++++++++++++++++++---------------- src/driver/common/fortconf.h | 11 +++++---- src/driver/common/fortdev.h | 36 ++++++++++++++-------------- src/driver/common/fortlog.c | 6 ++--- src/driver/common/fortlog.h | 6 ++--- src/driver/common/fortprov.c | 28 +++++++++++----------- 6 files changed, 69 insertions(+), 64 deletions(-) diff --git a/src/driver/common/fortconf.c b/src/driver/common/fortconf.c index 18bb3b2f..5148aece 100644 --- a/src/driver/common/fortconf.c +++ b/src/driver/common/fortconf.c @@ -71,7 +71,7 @@ static BOOL fort_conf_ip_inrange(UINT32 ip, UINT32 count, const UINT32 *iprange) FORT_API BOOL fort_conf_ip_inlist(UINT32 ip, const PFORT_CONF_ADDR_LIST addr_list) { return fort_conf_ip_inarr(ip, addr_list->ip_n, fort_conf_addr_list_ip_ref(addr_list)) - || fort_conf_ip_inrange(ip, addr_list->pair_n, fort_conf_addr_list_pair_ref(addr_list)); + || fort_conf_ip_inrange(ip, addr_list->pair_n, fort_conf_addr_list_pair_ref(addr_list)); } FORT_API PFORT_CONF_ADDR_GROUP fort_conf_addr_group_ref(const PFORT_CONF conf, int addr_group_index) @@ -83,7 +83,8 @@ FORT_API PFORT_CONF_ADDR_GROUP fort_conf_addr_group_ref(const PFORT_CONF conf, i } FORT_API BOOL fort_conf_ip_included(const PFORT_CONF conf, - fort_conf_zones_ip_included_func zone_func, void *ctx, UINT32 remote_ip, int addr_group_index) + fort_conf_zones_ip_included_func zone_func, void *ctx, UINT32 remote_ip, + int addr_group_index) { const PFORT_CONF_ADDR_GROUP addr_group = fort_conf_addr_group_ref(conf, addr_group_index); @@ -91,16 +92,18 @@ FORT_API BOOL fort_conf_ip_included(const PFORT_CONF conf, const BOOL exclude_all = addr_group->exclude_all; const BOOL ip_included = include_all - ? TRUE - : ((!addr_group->include_is_empty - && fort_conf_ip_inlist(remote_ip, fort_conf_addr_group_include_list_ref(addr_group))) - || (zone_func != NULL && zone_func(ctx, addr_group->include_zones, remote_ip))); + ? TRUE + : ((!addr_group->include_is_empty + && fort_conf_ip_inlist( + remote_ip, fort_conf_addr_group_include_list_ref(addr_group))) + || (zone_func != NULL && zone_func(ctx, addr_group->include_zones, remote_ip))); const BOOL ip_excluded = exclude_all - ? TRUE - : ((!addr_group->exclude_is_empty - && fort_conf_ip_inlist(remote_ip, fort_conf_addr_group_exclude_list_ref(addr_group))) - || (zone_func != NULL && zone_func(ctx, addr_group->exclude_zones, remote_ip))); + ? TRUE + : ((!addr_group->exclude_is_empty + && fort_conf_ip_inlist( + remote_ip, fort_conf_addr_group_exclude_list_ref(addr_group))) + || (zone_func != NULL && zone_func(ctx, addr_group->exclude_zones, remote_ip))); return include_all ? !ip_excluded : (exclude_all ? ip_included : (ip_included && !ip_excluded)); } @@ -123,7 +126,7 @@ FORT_API BOOL fort_conf_app_exe_equal(PFORT_APP_ENTRY app_entry, const char *pat } FORT_API FORT_APP_FLAGS fort_conf_app_exe_find( - const PFORT_CONF conf, const char *path, UINT32 path_len) + const PFORT_CONF conf, const char *path, UINT32 path_len) { FORT_APP_FLAGS app_flags; const char *data; @@ -166,7 +169,7 @@ static int fort_conf_app_prefix_cmp(PFORT_APP_ENTRY app_entry, const char *path, } static FORT_APP_FLAGS fort_conf_app_prefix_find( - const PFORT_CONF conf, const char *path, UINT32 path_len) + const PFORT_CONF conf, const char *path, UINT32 path_len) { FORT_APP_FLAGS app_flags; const char *data; @@ -241,7 +244,7 @@ end: } FORT_API FORT_APP_FLAGS fort_conf_app_find(const PFORT_CONF conf, const char *path, UINT32 path_len, - fort_conf_app_exe_find_func *exe_find_func) + fort_conf_app_exe_find_func *exe_find_func) { FORT_APP_FLAGS app_flags; @@ -273,9 +276,9 @@ FORT_API BOOL fort_conf_app_blocked(const PFORT_CONF conf, FORT_APP_FLAGS app_fl const BOOL allow_all = conf->flags.app_allow_all; const BOOL app_blocked = - block_all ? TRUE : (app_found && (app_perm & conf->app_perms_block_mask)); + block_all ? TRUE : (app_found && (app_perm & conf->app_perms_block_mask)); const BOOL app_allowed = - allow_all ? TRUE : (app_found && (app_perm & conf->app_perms_allow_mask)); + allow_all ? TRUE : (app_found && (app_perm & conf->app_perms_allow_mask)); return block_all ? !app_allowed : (allow_all ? app_blocked : (app_blocked && !app_allowed)); } @@ -323,12 +326,13 @@ FORT_API UINT16 fort_conf_app_period_bits(const PFORT_CONF conf, FORT_TIME time, FORT_API void fort_conf_app_perms_mask_init(PFORT_CONF conf, UINT32 group_bits) { UINT32 perms_mask = (group_bits & 0x0001) | ((group_bits & 0x0002) << 1) - | ((group_bits & 0x0004) << 2) | ((group_bits & 0x0008) << 3) | ((group_bits & 0x0010) << 4) - | ((group_bits & 0x0020) << 5) | ((group_bits & 0x0040) << 6) | ((group_bits & 0x0080) << 7) - | ((group_bits & 0x0100) << 8) | ((group_bits & 0x0200) << 9) - | ((group_bits & 0x0400) << 10) | ((group_bits & 0x0800) << 11) - | ((group_bits & 0x1000) << 12) | ((group_bits & 0x2000) << 13) - | ((group_bits & 0x4000) << 14) | ((group_bits & 0x8000) << 15); + | ((group_bits & 0x0004) << 2) | ((group_bits & 0x0008) << 3) + | ((group_bits & 0x0010) << 4) | ((group_bits & 0x0020) << 5) + | ((group_bits & 0x0040) << 6) | ((group_bits & 0x0080) << 7) + | ((group_bits & 0x0100) << 8) | ((group_bits & 0x0200) << 9) + | ((group_bits & 0x0400) << 10) | ((group_bits & 0x0800) << 11) + | ((group_bits & 0x1000) << 12) | ((group_bits & 0x2000) << 13) + | ((group_bits & 0x4000) << 14) | ((group_bits & 0x8000) << 15); perms_mask |= perms_mask << 1; diff --git a/src/driver/common/fortconf.h b/src/driver/common/fortconf.h index 8017cf5f..0c62757c 100644 --- a/src/driver/common/fortconf.h +++ b/src/driver/common/fortconf.h @@ -197,7 +197,7 @@ typedef struct fort_conf_io (FORT_CONF_ADDR_LIST_OFF + FORT_CONF_IP_ARR_SIZE(ip_n) + FORT_CONF_IP_RANGE_SIZE(pair_n)) typedef FORT_APP_FLAGS fort_conf_app_exe_find_func( - const PFORT_CONF conf, const char *path, UINT32 path_len); + const PFORT_CONF conf, const char *path, UINT32 path_len); typedef BOOL fort_conf_zones_ip_included_func(void *ctx, UINT32 zones_mask, UINT32 remote_ip); @@ -212,22 +212,23 @@ FORT_API BOOL is_time_in_period(FORT_TIME time, FORT_PERIOD period); FORT_API BOOL fort_conf_ip_inlist(UINT32 ip, const PFORT_CONF_ADDR_LIST addr_list); FORT_API PFORT_CONF_ADDR_GROUP fort_conf_addr_group_ref( - const PFORT_CONF conf, int addr_group_index); + const PFORT_CONF conf, int addr_group_index); #define fort_conf_addr_group_include_list_ref(addr_group) ((PFORT_CONF_ADDR_LIST)(addr_group)->data) #define fort_conf_addr_group_exclude_list_ref(addr_group) \ ((PFORT_CONF_ADDR_LIST)((addr_group)->data + (addr_group)->exclude_off)) FORT_API BOOL fort_conf_ip_included(const PFORT_CONF conf, - fort_conf_zones_ip_included_func zone_func, void *ctx, UINT32 remote_ip, int addr_group_index); + fort_conf_zones_ip_included_func zone_func, void *ctx, UINT32 remote_ip, + int addr_group_index); FORT_API BOOL fort_conf_app_exe_equal(PFORT_APP_ENTRY app_entry, const char *path, UINT32 path_len); FORT_API FORT_APP_FLAGS fort_conf_app_exe_find( - const PFORT_CONF conf, const char *path, UINT32 path_len); + const PFORT_CONF conf, const char *path, UINT32 path_len); FORT_API FORT_APP_FLAGS fort_conf_app_find(const PFORT_CONF conf, const char *path, UINT32 path_len, - fort_conf_app_exe_find_func *exe_find_func); + fort_conf_app_exe_find_func *exe_find_func); FORT_API BOOL fort_conf_app_blocked(const PFORT_CONF conf, FORT_APP_FLAGS app_flags); diff --git a/src/driver/common/fortdev.h b/src/driver/common/fortdev.h index 6a3a03e9..76e4f60f 100644 --- a/src/driver/common/fortdev.h +++ b/src/driver/common/fortdev.h @@ -11,68 +11,68 @@ /* GUID-s generated by guidgen.exe */ /* {012B3999-B791-463E-918C-C32B53E9350E} */ -DEFINE_GUID( - FORT_GUID_PROVIDER, 0x12b3999, 0xb791, 0x463e, 0x91, 0x8c, 0xc3, 0x2b, 0x53, 0xe9, 0x35, 0xe); +DEFINE_GUID(FORT_GUID_PROVIDER, 0x12b3999, 0xb791, 0x463e, 0x91, 0x8c, 0xc3, 0x2b, 0x53, 0xe9, 0x35, + 0xe); /* {749978E2-CB6A-42F9-9C30-1A3EA9810185} */ DEFINE_GUID(FORT_GUID_CALLOUT_CONNECT_V4, 0x749978e2, 0xcb6a, 0x42f9, 0x9c, 0x30, 0x1a, 0x3e, 0xa9, - 0x81, 0x1, 0x85); + 0x81, 0x1, 0x85); /* {CED9C0FC-DF22-4F39-9185-B435726CABB2} */ DEFINE_GUID(FORT_GUID_CALLOUT_ACCEPT_V4, 0xced9c0fc, 0xdf22, 0x4f39, 0x91, 0x85, 0xb4, 0x35, 0x72, - 0x6c, 0xab, 0xb2); + 0x6c, 0xab, 0xb2); /* {1F50005D-CDBC-42A0-A0C0-53E43081FABE} */ DEFINE_GUID(FORT_GUID_CALLOUT_STREAM_V4, 0x1f50005d, 0xcdbc, 0x42a0, 0xa0, 0xc0, 0x53, 0xe4, 0x30, - 0x81, 0xfa, 0xbe); + 0x81, 0xfa, 0xbe); /* {5F1A7B3C-3E88-41C9-A442-61CFE6A48806} */ DEFINE_GUID(FORT_GUID_CALLOUT_DATAGRAM_V4, 0x5f1a7b3c, 0x3e88, 0x41c9, 0xa4, 0x42, 0x61, 0xcf, 0xe6, - 0xa4, 0x88, 0x6); + 0xa4, 0x88, 0x6); /* {DED18B1B-0022-415F-AFDC-C9D59CE6D475} */ DEFINE_GUID(FORT_GUID_CALLOUT_IN_TRANSPORT_V4, 0xded18b1b, 0x22, 0x415f, 0xaf, 0xdc, 0xc9, 0xd5, - 0x9c, 0xe6, 0xd4, 0x75); + 0x9c, 0xe6, 0xd4, 0x75); /* {0004F6D3-8430-4B35-9BF7-23C25C25003E} */ DEFINE_GUID(FORT_GUID_CALLOUT_OUT_TRANSPORT_V4, 0x4f6d3, 0x8430, 0x4b35, 0x9b, 0xf7, 0x23, 0xc2, - 0x5c, 0x25, 0x0, 0x3e); + 0x5c, 0x25, 0x0, 0x3e); /* {AFA06CD5-4942-4FDF-8A4A-2EDEB25BBECE} */ -DEFINE_GUID( - FORT_GUID_SUBLAYER, 0xafa06cd5, 0x4942, 0x4fdf, 0x8a, 0x4a, 0x2e, 0xde, 0xb2, 0x5b, 0xbe, 0xce); +DEFINE_GUID(FORT_GUID_SUBLAYER, 0xafa06cd5, 0x4942, 0x4fdf, 0x8a, 0x4a, 0x2e, 0xde, 0xb2, 0x5b, + 0xbe, 0xce); /* {91CF8B80-7BB2-42BA-8A26-8242E14532FC} */ DEFINE_GUID(FORT_GUID_FILTER_CONNECT_V4, 0x91cf8b80, 0x7bb2, 0x42ba, 0x8a, 0x26, 0x82, 0x42, 0xe1, - 0x45, 0x32, 0xfc); + 0x45, 0x32, 0xfc); /* {544A3E25-7BEB-4970-88EF-B4BCA2CE2482} */ DEFINE_GUID(FORT_GUID_FILTER_ACCEPT_V4, 0x544a3e25, 0x7beb, 0x4970, 0x88, 0xef, 0xb4, 0xbc, 0xa2, - 0xce, 0x24, 0x82); + 0xce, 0x24, 0x82); /* {ED0F2527-A787-4CA2-9493-C96320422FCF} */ DEFINE_GUID(FORT_GUID_FILTER_STREAM_V4, 0xed0f2527, 0xa787, 0x4ca2, 0x94, 0x93, 0xc9, 0x63, 0x20, - 0x42, 0x2f, 0xcf); + 0x42, 0x2f, 0xcf); /* {A3700639-1B50-461C-BE4C-BC350A7FB3A9} */ DEFINE_GUID(FORT_GUID_FILTER_DATAGRAM_V4, 0xa3700639, 0x1b50, 0x461c, 0xbe, 0x4c, 0xbc, 0x35, 0xa, - 0x7f, 0xb3, 0xa9); + 0x7f, 0xb3, 0xa9); /* {F515D62B-26A3-413E-874C-D65CE70C9AEF} */ DEFINE_GUID(FORT_GUID_FILTER_IN_TRANSPORT_V4, 0xf515d62b, 0x26a3, 0x413e, 0x87, 0x4c, 0xd6, 0x5c, - 0xe7, 0xc, 0x9a, 0xef); + 0xe7, 0xc, 0x9a, 0xef); /* {D284AFE8-4CAF-4432-A753-B6F311BDA2BA} */ DEFINE_GUID(FORT_GUID_FILTER_OUT_TRANSPORT_V4, 0xd284afe8, 0x4caf, 0x4432, 0xa7, 0x53, 0xb6, 0xf3, - 0x11, 0xbd, 0xa2, 0xba); + 0x11, 0xbd, 0xa2, 0xba); /* {C2D858F8-2951-4EED-8DA1-A4930F8E5204} */ DEFINE_GUID(FORT_GUID_FILTER_REAUTH_IN, 0xc2d858f8, 0x2951, 0x4eed, 0x8d, 0xa1, 0xa4, 0x93, 0xf, - 0x8e, 0x52, 0x4); + 0x8e, 0x52, 0x4); /* {749709CE-9686-4056-B89A-7A5852DFC898} */ DEFINE_GUID(FORT_GUID_FILTER_REAUTH_OUT, 0x749709ce, 0x9686, 0x4056, 0xb8, 0x9a, 0x7a, 0x58, 0x52, - 0xdf, 0xc8, 0x98); + 0xdf, 0xc8, 0x98); #define FORT_DEVICE_NAME "\\\\.\\fortfw" diff --git a/src/driver/common/fortlog.c b/src/driver/common/fortlog.c index 7e8ed122..45374dd0 100644 --- a/src/driver/common/fortlog.c +++ b/src/driver/common/fortlog.c @@ -3,7 +3,7 @@ #include "fortlog.h" FORT_API void fort_log_blocked_header_write(char *p, BOOL blocked, UINT32 remote_ip, - UINT16 remote_port, UCHAR ip_proto, UINT32 pid, UINT32 path_len) + UINT16 remote_port, UCHAR ip_proto, UINT32 pid, UINT32 path_len) { UINT32 *up = (UINT32 *) p; @@ -14,7 +14,7 @@ FORT_API void fort_log_blocked_header_write(char *p, BOOL blocked, UINT32 remote } FORT_API void fort_log_blocked_write(char *p, BOOL blocked, UINT32 remote_ip, UINT16 remote_port, - UCHAR ip_proto, UINT32 pid, UINT32 path_len, const char *path) + UCHAR ip_proto, UINT32 pid, UINT32 path_len, const char *path) { fort_log_blocked_header_write(p, blocked, remote_ip, remote_port, ip_proto, pid, path_len); @@ -24,7 +24,7 @@ FORT_API void fort_log_blocked_write(char *p, BOOL blocked, UINT32 remote_ip, UI } FORT_API void fort_log_blocked_header_read(const char *p, BOOL *blocked, UINT32 *remote_ip, - UINT16 *remote_port, UCHAR *ip_proto, UINT32 *pid, UINT32 *path_len) + UINT16 *remote_port, UCHAR *ip_proto, UINT32 *pid, UINT32 *path_len) { const UINT32 *up = (const UINT32 *) p; diff --git a/src/driver/common/fortlog.h b/src/driver/common/fortlog.h index a4806ce8..2dec7694 100644 --- a/src/driver/common/fortlog.h +++ b/src/driver/common/fortlog.h @@ -46,13 +46,13 @@ extern "C" { #endif FORT_API void fort_log_blocked_header_write(char *p, BOOL blocked, UINT32 remote_ip, - UINT16 remote_port, UCHAR ip_proto, UINT32 pid, UINT32 path_len); + UINT16 remote_port, UCHAR ip_proto, UINT32 pid, UINT32 path_len); FORT_API void fort_log_blocked_write(char *p, BOOL blocked, UINT32 remote_ip, UINT16 remote_port, - UCHAR ip_proto, UINT32 pid, UINT32 path_len, const char *path); + UCHAR ip_proto, UINT32 pid, UINT32 path_len, const char *path); FORT_API void fort_log_blocked_header_read(const char *p, BOOL *blocked, UINT32 *remote_ip, - UINT16 *remote_port, UCHAR *ip_proto, UINT32 *pid, UINT32 *path_len); + UINT16 *remote_port, UCHAR *ip_proto, UINT32 *pid, UINT32 *path_len); FORT_API void fort_log_proc_new_header_write(char *p, UINT32 pid, UINT32 path_len); diff --git a/src/driver/common/fortprov.c b/src/driver/common/fortprov.c index f3fc8591..b2752e22 100644 --- a/src/driver/common/fortprov.c +++ b/src/driver/common/fortprov.c @@ -154,15 +154,15 @@ FORT_API DWORD fort_prov_register(HANDLE transEngine, BOOL is_boot) ifilter4.action.calloutKey = FORT_GUID_CALLOUT_ACCEPT_V4; if ((status = FwpmProviderAdd0(engine, &provider, NULL)) - || (status = FwpmCalloutAdd0(engine, &ocallout4, NULL, NULL)) - || (status = FwpmCalloutAdd0(engine, &icallout4, NULL, NULL)) - || (status = FwpmCalloutAdd0(engine, &scallout4, NULL, NULL)) - || (status = FwpmCalloutAdd0(engine, &dcallout4, NULL, NULL)) - || (status = FwpmCalloutAdd0(engine, &itcallout4, NULL, NULL)) - || (status = FwpmCalloutAdd0(engine, &otcallout4, NULL, NULL)) - || (status = FwpmSubLayerAdd0(engine, &sublayer, NULL)) - || (status = FwpmFilterAdd0(engine, &ofilter4, NULL, NULL)) - || (status = FwpmFilterAdd0(engine, &ifilter4, NULL, NULL))) { + || (status = FwpmCalloutAdd0(engine, &ocallout4, NULL, NULL)) + || (status = FwpmCalloutAdd0(engine, &icallout4, NULL, NULL)) + || (status = FwpmCalloutAdd0(engine, &scallout4, NULL, NULL)) + || (status = FwpmCalloutAdd0(engine, &dcallout4, NULL, NULL)) + || (status = FwpmCalloutAdd0(engine, &itcallout4, NULL, NULL)) + || (status = FwpmCalloutAdd0(engine, &otcallout4, NULL, NULL)) + || (status = FwpmSubLayerAdd0(engine, &sublayer, NULL)) + || (status = FwpmFilterAdd0(engine, &ofilter4, NULL, NULL)) + || (status = FwpmFilterAdd0(engine, &ifilter4, NULL, NULL))) { fort_prov_trans_abort(engine); } @@ -184,7 +184,7 @@ FORT_API DWORD fort_prov_flow_register(HANDLE transEngine, BOOL filter_transport FWPM_FILTER0 itfilter4, otfilter4; HANDLE engine = transEngine; const UINT32 filter_flags = FWPM_FILTER_FLAG_PERMIT_IF_CALLOUT_UNREGISTERED - | FWP_CALLOUT_FLAG_ALLOW_MID_STREAM_INSPECTION; + | FWP_CALLOUT_FLAG_ALLOW_MID_STREAM_INSPECTION; DWORD status; if (!transEngine) { @@ -235,10 +235,10 @@ FORT_API DWORD fort_prov_flow_register(HANDLE transEngine, BOOL filter_transport otfilter4.action.calloutKey = FORT_GUID_CALLOUT_OUT_TRANSPORT_V4; if ((status = FwpmFilterAdd0(engine, &sfilter4, NULL, NULL)) - || (status = FwpmFilterAdd0(engine, &dfilter4, NULL, NULL)) - || (filter_transport - && ((status = FwpmFilterAdd0(engine, &itfilter4, NULL, NULL)) - || (status = FwpmFilterAdd0(engine, &otfilter4, NULL, NULL))))) { + || (status = FwpmFilterAdd0(engine, &dfilter4, NULL, NULL)) + || (filter_transport + && ((status = FwpmFilterAdd0(engine, &itfilter4, NULL, NULL)) + || (status = FwpmFilterAdd0(engine, &otfilter4, NULL, NULL))))) { fort_prov_trans_abort(engine); }