/*++ Copyright (c) 2000 Microsoft Corporation. All rights reserved. --*/ // EBFilter.cpp : Implementation of CEBFilter #include "stdafx.h" #include "exeblock.h" #include "EBFilter.h" #include "EBSessionFilter.h" #include "ebscannerdatafilter.h" ///////////////////////////////////////////////////////////////////////////// // CEBFilter // // // FwxFilterHookEvents g_FTPHookEvents= {DWORD(fwx_Connect_Tcp | FWX_ALL_SOURCES)}; ////////////////////////////////////////////////////////////////////////////// // CEBFilter::FilterInit // // implements IFWXFilter::FilterInit // // ////////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE CEBFilter::FilterInit( /* [in] */ IFWXFirewall __RPC_FAR *CallBackInterface, /* [out] */ FwxFilterHookEvents * pFilterHookEvents) { // // Keep a reference for the callback interface. // m_spCallBackInterface = CallBackInterface; // // Define the events that will trigger call to IFWXFilter::AttachToSession // *pFilterHookEvents = g_FTPHookEvents; return S_OK; } ////////////////////////////////////////////////////////////////////////////// // CEBFilter::ReloadConfiguration // // implements IFWXFilter::ReloadConfiguration // // ////////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE CEBFilter::ReloadConfiguration(void) { // // Nothing to do here // return S_OK; } ////////////////////////////////////////////////////////////////////////////// // CEBFilter::FilterShutdown // // implements IFWXFilter::FilterShutdown // // ////////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE CEBFilter::FilterShutdown(void) { // // Nothing to do here // return S_OK; } ////////////////////////////////////////////////////////////////////////////// // CEBFilter::PrepareRulesData // // implements IFWXFilter::PrepareRulesData // // ////////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE CEBFilter::PrepareRulesData( /* [in] */ IFPCPolicyRule * pPolicyRule, /* [out] */ IFWXPerRuleDataplugin ** ProcessedRulesData ) { HRESULT hr; *ProcessedRulesData = NULL; LONG VPSize; CComVariant svarKey, svarValue; BYTE BlockedData; CComPtr prd; CComPtr pPerRuleParameterSets; CComPtr pPerRuleParameterSet; CComBSTR bstr; hr = pPolicyRule->get_VendorParametersSets(&pPerRuleParameterSets); if (FAILED(hr)) { goto Cleanup; } hr = CPreparedRuleData::CreateInstance(&prd); if(FAILED(hr)) { goto Cleanup; } *ProcessedRulesData = prd; (*ProcessedRulesData)->AddRef(); // This AddRef is actually for the prd hr = pPerRuleParameterSets->get_Count(&VPSize); if(FAILED(hr)) { goto Cleanup; } if(VPSize == 0) { // We will just use the default goto Cleanup; } svarKey = VENDOR_PARAMETER_SET_NAME; if(svarKey.vt == VT_ERROR) { hr = E_OUTOFMEMORY; goto Cleanup; } hr = pPerRuleParameterSets->Item(svarKey, &pPerRuleParameterSet); if(FAILED(hr)) { if(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { // // This can happen, not an error. // hr = S_OK; } goto Cleanup; } bstr = "block"; if(!bstr) { goto Cleanup; } hr = pPerRuleParameterSet->get_Value(bstr, &svarValue); if(FAILED(hr)) { if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { // // there is no rule configuration, use the default // hr = S_OK; } goto Cleanup; } if(svarValue.vt != VT_BSTR) { hr = E_INVALIDARG; goto Cleanup; } // // If the value is '1', set 1 in 'Per Rule Data'. This tells the filter to block EXE files. // BlockedData = (!wcscmp(svarValue.bstrVal, L"1") ? 1 : 0); hr = prd->SetData(1, &BlockedData); Cleanup: if(FAILED(hr)) { if (*ProcessedRulesData) { *ProcessedRulesData = NULL; } } else { // If we are here and everything went Ok, we can remove the refcount prd.Detach(); } return hr; } ////////////////////////////////////////////////////////////////////////////// // CEBFilter::AttachToSession // // implements IFWXFilter::AttachToSession // // ////////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE CEBFilter::AttachToSession( /* [in] */ IFWXSession * pIFWXSession, /* [out] */ IFWXSessionFilter ** pUnkMonitoring, /* [out] */ FwxFilterHookEvents * pFilterHookEvents ) { HRESULT hr; CComObject *pSessionFilter; hr = CComObject::CreateInstance(&pSessionFilter); if (FAILED(hr)) { return hr; } pSessionFilter->AddRef(); hr = pSessionFilter->Initialize(pIFWXSession, m_spCallBackInterface); if (SUCCEEDED(hr)) { *pUnkMonitoring = pSessionFilter; } else { *pUnkMonitoring = NULL; pSessionFilter->Release(); } if (SUCCEEDED(hr)) { *pFilterHookEvents = g_FTPHookEvents; } return hr; }