Microsoft Internet Security and Acceleration Server 2000 |
This section describes how to add the registration code to your filter.
To add the registration code
#import "msfpccom.tlb" rename_namespace("MSFPCCOM") named_guids //define the GUID string with your filter GUID value #define FILTER_GUID_STRING "{7CCF6FF0-D995-4da1-B452-4228047B2D1D}" //define the FILTER_PROTOCOL_GUID static const GUID FILTER_PROTOCOL_GUID = { 0x8226e96a, 0xb578, 0x4c28, { 0xb6, 0x86, 0x7e, 0xc9, 0x2b, 0xaf, 0x1e, 0xe7 } }; #define FILTER_PROTOCOL_GUID_STRING "{8226E96A-B578-4c28-B686-7EC92BAF1EE7}"
In SMTPFltr.cpp, add the following code to your filter registration code:
// This function is used to register an application filter static HRESULT RegisterFWXFilter (BOOL fRegister, FwxScope Scope) { HRESULT hr; MSFPCCOM::IFPCFilterProtocolPtr comptrIFPCFilterProtocol; CComPtr<IFWXFilterAdmin> pIFWXFilterAdmin; hr = CoCreateInstance (CLSID_FWXFilterAdmin, NULL, CLSCTX_SERVER, IID_IFWXFilterAdmin, (LPVOID *) &pIFWXFilterAdmin); if (FAILED(hr)) return hr; if (fRegister) { //Strings should be Unicode in this call hr = pIFWXFilterAdmin-> InstallFilter (CLSID_SMTPFilter,// GUID L"SMTPFilter",// Name L"Screen SMTP messages",// Description L"Microsoft",// Vendor L"1.0",// Version NULL,//Reserved parameter, must be NULL Scope); //OK if already installed. if (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) hr = S_OK; if (FAILED(hr)) return hr; hr = pIFWXFilterAdmin ->RegisterProtocolForFilter(CLSID_SMTPFilter, FILTER_PROTOCOL_GUID, L"SMTP server", L"SMTP inbound via SMTPFLTR", NULL,//Reserved parameter, must be NULL Scope); // Returns OK if already installed. if (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) hr = S_OK; if (FAILED(hr)) return hr; //Get a pointer to the protocol just registered hr = pIFWXFilterAdmin->GetProtocol(CLSID_SMTPFilter, FILTER_PROTOCOL_GUID, Scope, (struct IFPCFilterProtocol **)&comptrIFPCFilterProtocol); if (FAILED(hr)) return hr; try { //Add primary connection to the protocol just created comptrIFPCFilterProtocol->PrimaryConnections->AddTCP(MSFPCCOM::fpcInbound, 25, 25); comptrIFPCFilterProtocol->PrimaryConnections->Save(); } catch(_com_error& err) { //If adding a primary connection to the protocol fails, it is not considered an error if(err.Error() != HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) return err.Error(); } } else { //Unregister protocol hr = pIFWXFilterAdmin->UnregisterProtocolForFilter(CLSID_SMTPFilter, FILTER_PROTOCOL_GUID, Scope); //Unregister filter hr = pIFWXFilterAdmin->UninstallFilter (CLSID_SMTPFilter, Scope); } return hr; } ////////// // DllInstall - Application filter installation STDAPI DllInstall( BOOL bInstall, LPCWSTR pszCmdLine ) { FwxScope Scope; // Must have command line, must be either enterprise or array if (!pszCmdLine) return E_INVALIDARG; if (wcscmp(pszCmdLine, L"enterprise") == 0) { Scope = fwx_EnterpriseScope; } else if (wcscmp(pszCmdLine, L"array") == 0) { Scope = fwx_ArrayScope; } else { return E_INVALIDARG; } return RegisterFWXFilter(bInstall, Scope); }
DllInstall @5 PRIVATE
HRESULT STDMETHODCALLTYPE CFWXSessionFilter::FirewallEventHandler( /* [out][in] */ const FwxFirewallEvent __RPC_FAR *pFirewallEvent) { HRESULT hr = S_OK; IFWXConnection *piConnection; switch (pFirewallEvent->EventType) { // Bind request for TCP sockets case fwx_Bind_Tcp: OutputDebugString ("IFWXSessionFilter::FirewallEventHandler – fwx_Bind_Tcp\n"); OutputDebugString (FilterAccessString( pFirewallEvent-> Parameters.Bind.FilterAccess)); //Get a pointer to the connection piConnection=pFirewallEvent->Parameters.Bind.piConnection; //Set the protocol of this connection to be the filter //protocol hr = piConnection->SetProtocol(FILTER_PROTOCOL_GUID,0); if (FAILED(hr)) { OutputDebugString("\tFail to set protocol of connection to SMTP filter protocol\n"); return hr; } break;
To test the registration and installation code, follow the setup procedures described in Filter Setup, as appropriate for an enterprise or array installation. You will need to reinstall the filter when you complete the filter creation procedure.
Note Filter objects are created when the Firewall service is loaded, so the service must be restarted when you add a new filter or a new version of an existing filter.