/*++ Copyright (c) 2000 Microsoft Corporation. All rights reserved. --*/ // exeblock.cpp : Implementation of DLL Exports. // Note: Proxy/Stub Information // To build a separate proxy/stub DLL, // run nmake -f exeblockps.mk in the project directory. #include "stdafx.h" #include "resource.h" #include "initguid.h" #include "exeblock.h" #include "exeblock_i.c" #include "wspfwext_i.c" #include "EBFilter.h" #include "EBSessionFilter.h" #include "EBFTPDataFilter.h" #include "DataFilterFactory.h" #include "protocol_guids.h" #include "trace.h" ////////////////////////////////////////////////////////////////////////////// // RegisterApplicationFilter // // Register/unregister the filter in WinSock proxy. // // The SDK samples do this in the DllRegisterServer, DllUnregisterServer, // calls. This can also be done in the setup application for the filter. // // Parameters: // fRegister - TRUE for register, FALSE for unregister. // // ////////////////////////////////////////////////////////////////////////////// HRESULT RegisterApplicationFilter(BOOL fRegister) { HRESULT hr; CComPtr ifa = NULL; // Get instance of filter admin object. hr = CoCreateInstance( CLSID_FWXFilterAdmin, NULL, CLSCTX_INPROC_SERVER, IID_IFWXFilterAdmin, (void**)&ifa ); if (FAILED(hr)) return hr; // Register / unregister if (fRegister) { // // ISSUE: The filter didn't support FTP publishing. Need to fix it after Beta1 // GUID ProtocolsToInstall[] = { FTP_PROTOCOL_GUID_BIN }; int NumOfProtocols = sizeof(ProtocolsToInstall)/sizeof(ProtocolsToInstall[0]); hr = ifa->InstallFilter( CLSID_EBFilter, L"FTP block executables sample filter", L"Microsoft FTP block executable sample filter. " L"This filter prevents downloading of executable files with FTP. " L"Executable files are identifed as files beginning with MZ or ZM", L"Microsoft", L"4.0", NULL, ProtocolsToInstall, NumOfProtocols ); // It is OK if already installed. if (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) { hr = S_OK; } } else { hr = ifa->UninstallFilter(CLSID_EBFilter); } return hr; } CComModule _Module; BEGIN_OBJECT_MAP(ObjectMap) OBJECT_ENTRY(CLSID_EBFilter, CEBFilter) END_OBJECT_MAP() ///////////////////////////////////////////////////////////////////////////// // DLL Entry Point extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) { if (dwReason == DLL_PROCESS_ATTACH) { _Module.Init(ObjectMap, hInstance); DisableThreadLibraryCalls(hInstance); } else if (dwReason == DLL_PROCESS_DETACH) _Module.Term(); return TRUE; // ok } ///////////////////////////////////////////////////////////////////////////// // Used to determine whether the DLL can be unloaded by OLE STDAPI DllCanUnloadNow(void) { return (_Module.GetLockCount()==0) ? S_OK : S_FALSE; } ///////////////////////////////////////////////////////////////////////////// // Returns a class factory to create an object of the requested type STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { return _Module.GetClassObject(rclsid, riid, ppv); } ///////////////////////////////////////////////////////////////////////////// // DllRegisterServer - Adds entries to the system registry STDAPI DllRegisterServer(void) { // registers object (no typelib) HRESULT hr = _Module.RegisterServer(); return hr; } ///////////////////////////////////////////////////////////////////////////// // DllUnregisterServer - Removes entries from the system registry STDAPI DllUnregisterServer(void) { _Module.UnregisterServer(); return S_OK; } ///////////////////////////////////////////////////////////////////////////// // DllInstall - Application filter installation STDAPI DllInstall( BOOL bInstall, LPCWSTR /* pszCmdLine */ ) { return RegisterApplicationFilter(bInstall); }