mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:15:39 +00:00
Driver: Simplify prov_boot flag.
This commit is contained in:
parent
1cdfeb2ba0
commit
2ed4609165
@ -2,11 +2,22 @@
|
||||
|
||||
typedef struct fort_prov_data {
|
||||
UINT32 version : 24;
|
||||
UINT32 persist : 1;
|
||||
UINT32 boot : 1;
|
||||
UINT32 is_boot : 1;
|
||||
} FORT_PROV_DATA, *PFORT_PROV_DATA;
|
||||
|
||||
|
||||
static DWORD
|
||||
fort_prov_open (HANDLE *enginep)
|
||||
{
|
||||
return FwpmEngineOpen0(NULL, RPC_C_AUTHN_WINNT, NULL, NULL, enginep);
|
||||
}
|
||||
|
||||
static void
|
||||
fort_prov_close (HANDLE engine)
|
||||
{
|
||||
FwpmEngineClose0(engine);
|
||||
}
|
||||
|
||||
static void
|
||||
fort_prov_delete (HANDLE engine)
|
||||
{
|
||||
@ -23,16 +34,16 @@ fort_prov_unregister (void)
|
||||
{
|
||||
HANDLE engine;
|
||||
|
||||
if (FwpmEngineOpen0(NULL, RPC_C_AUTHN_WINNT, NULL, NULL, &engine))
|
||||
if (fort_prov_open(&engine))
|
||||
return;
|
||||
|
||||
fort_prov_delete(engine);
|
||||
|
||||
FwpmEngineClose0(engine);
|
||||
fort_prov_close(engine);
|
||||
}
|
||||
|
||||
static DWORD
|
||||
fort_prov_register (BOOL persist, BOOL boot, BOOL *is_tempp, BOOL *is_bootp)
|
||||
fort_prov_register (BOOL is_boot, BOOL *is_bootp)
|
||||
{
|
||||
FWPM_PROVIDER0 *old_provider, provider;
|
||||
FWPM_CALLOUT0 ocallout4, icallout4;
|
||||
@ -43,8 +54,7 @@ fort_prov_register (BOOL persist, BOOL boot, BOOL *is_tempp, BOOL *is_bootp)
|
||||
UINT32 filter_flags;
|
||||
DWORD status;
|
||||
|
||||
if ((status = FwpmEngineOpen0(
|
||||
NULL, RPC_C_AUTHN_WINNT, NULL, NULL, &engine)))
|
||||
if ((status = fort_prov_open(&engine)))
|
||||
goto end;
|
||||
|
||||
if (!(status = FwpmProviderGetByKey0(
|
||||
@ -55,12 +65,12 @@ fort_prov_register (BOOL persist, BOOL boot, BOOL *is_tempp, BOOL *is_bootp)
|
||||
if (old_provider_data) {
|
||||
provider_data = *old_provider_data;
|
||||
}
|
||||
|
||||
FwpmFreeMemory0((void **) &old_provider);
|
||||
|
||||
if (old_provider_data) {
|
||||
if (provider_data.persist) {
|
||||
persist = provider_data.persist;
|
||||
boot = provider_data.boot;
|
||||
if (provider_data.is_boot) {
|
||||
is_boot = is_bootp ? provider_data.is_boot : is_boot;
|
||||
|
||||
if (provider_data.version == APP_VERSION)
|
||||
goto end_close;
|
||||
@ -70,13 +80,12 @@ fort_prov_register (BOOL persist, BOOL boot, BOOL *is_tempp, BOOL *is_bootp)
|
||||
}
|
||||
|
||||
provider_data.version = APP_VERSION;
|
||||
provider_data.persist = persist;
|
||||
provider_data.boot = boot;
|
||||
provider_data.is_boot = is_boot;
|
||||
|
||||
filter_flags = boot ? 0 : FWPM_FILTER_FLAG_PERMIT_IF_CALLOUT_UNREGISTERED;
|
||||
filter_flags = is_boot ? 0 : FWPM_FILTER_FLAG_PERMIT_IF_CALLOUT_UNREGISTERED;
|
||||
|
||||
RtlZeroMemory(&provider, sizeof(FWPM_PROVIDER0));
|
||||
provider.flags = persist ? FWPM_PROVIDER_FLAG_PERSISTENT : 0;
|
||||
provider.flags = is_boot ? FWPM_PROVIDER_FLAG_PERSISTENT : 0;
|
||||
provider.providerKey = FORT_GUID_PROVIDER;
|
||||
provider.displayData.name = (wchar_t *) L"FortProvider";
|
||||
provider.displayData.description = (wchar_t *) L"Fort Firewall Provider";
|
||||
@ -133,15 +142,13 @@ fort_prov_register (BOOL persist, BOOL boot, BOOL *is_tempp, BOOL *is_bootp)
|
||||
|| (status = FwpmFilterAdd0(engine, &ifilter4, NULL, NULL))
|
||||
|| (status = FwpmTransactionCommit0(engine))) {
|
||||
FwpmTransactionAbort0(engine);
|
||||
} else if (is_tempp) {
|
||||
*is_tempp = !persist;
|
||||
}
|
||||
|
||||
end_close:
|
||||
FwpmEngineClose0(engine);
|
||||
fort_prov_close(engine);
|
||||
|
||||
if (is_bootp) {
|
||||
*is_bootp = boot;
|
||||
*is_bootp = is_boot;
|
||||
}
|
||||
|
||||
end:
|
||||
|
@ -29,7 +29,6 @@ typedef struct fort_conf_ref {
|
||||
typedef struct fort_device {
|
||||
BOOL active : 1;
|
||||
BOOL filter_enabled : 1;
|
||||
BOOL prov_temporary : 1;
|
||||
BOOL prov_boot : 1;
|
||||
|
||||
UINT32 connect4_id;
|
||||
@ -317,8 +316,7 @@ fort_callout_force_reauth (PDEVICE_OBJECT device)
|
||||
fort_prov_unregister();
|
||||
|
||||
// Register
|
||||
status = fort_prov_register(!g_device->prov_temporary,
|
||||
g_device->prov_boot, NULL, NULL);
|
||||
status = fort_prov_register(g_device->prov_boot, NULL);
|
||||
|
||||
if (status == STATUS_SUCCESS) {
|
||||
status = fort_callout_install(device);
|
||||
@ -453,7 +451,7 @@ fort_driver_unload (PDRIVER_OBJECT driver)
|
||||
|
||||
fort_buffer_close(&g_device->buffer);
|
||||
|
||||
if (g_device->prov_temporary)
|
||||
if (!g_device->prov_boot)
|
||||
fort_prov_unregister();
|
||||
|
||||
RtlInitUnicodeString(&device_link, DOS_DEVICE_NAME);
|
||||
@ -500,11 +498,10 @@ DriverEntry (PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
|
||||
|
||||
// Register filters provider
|
||||
{
|
||||
BOOL is_temp = FALSE, is_boot = FALSE;
|
||||
BOOL is_boot = FALSE;
|
||||
|
||||
status = fort_prov_register(FALSE, FALSE, &is_temp, &is_boot);
|
||||
status = fort_prov_register(FALSE, &is_boot);
|
||||
|
||||
g_device->prov_temporary = is_temp;
|
||||
g_device->prov_boot = is_boot;
|
||||
}
|
||||
}
|
||||
|
@ -105,9 +105,9 @@ bool FortCommon::confAppBlocked(const void *drvConf,
|
||||
return blocked;
|
||||
}
|
||||
|
||||
uint FortCommon::provRegister(bool boot)
|
||||
uint FortCommon::provRegister(bool isBoot)
|
||||
{
|
||||
return fort_prov_register(TRUE, boot, NULL, NULL);
|
||||
return fort_prov_register(isBoot, NULL);
|
||||
}
|
||||
|
||||
void FortCommon::provUnregister()
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
static bool confAppBlocked(const void *drvConf,
|
||||
const QString &kernelPath, bool *notify = 0);
|
||||
|
||||
static uint provRegister(bool boot);
|
||||
static uint provRegister(bool isBoot);
|
||||
static void provUnregister();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user