forked from Mirrors/openclonk
win32: Add a firewall exception on installation
Conflicts: Makefile.am
parent
8baf5d7ced
commit
2847569a12
|
@ -711,11 +711,17 @@ AM_CXXFLAGS += -DOC_SYSTEM_DATA_DIR=\"${pkgdatadir}\"
|
|||
%.ocf: $(srcdir)/planet/%.ocf c4group$(EXEEXT)
|
||||
./c4group$(EXEEXT) $< -t $@ || c4group $< -t $@
|
||||
|
||||
## windows setup.exe
|
||||
if WIN32
|
||||
tools/install/firewall.dll: $(srcdir)/tools/install/firewall.cpp
|
||||
mkdir -p tools/install
|
||||
$(CXX) -shared -o tools/install/firewall.dll $(srcdir)/tools/install/firewall.cpp -lole32 -loleaut32
|
||||
setup_openclonk.exe: $(srcdir)/tools/install/oc.nsi c4group$(EXEEXT) clonk$(EXEEXT) $(c4groups)
|
||||
makensis -NOCD -DSRCDIR=$(srcdir) '-DPROGRAMFILES=$$PROGRAMFILES' \
|
||||
-DPRODUCT_NAME="$$(sed -n 's/SET(C4ENGINENAME\s\+"\(.\+\)")/\1/ p' $(srcdir)/Version.txt)$$(sed -n 's/SET(C4VERSIONBUILDNAME\s\+"\(.\+\)")/\1/ p' $(srcdir)/Version.txt)" \
|
||||
-DPRODUCT_COMPANY="$$(sed -n 's/SET(C4PROJECT\s\+"\(.\+\)")/\1/ p' $(srcdir)/Version.txt)" \
|
||||
$< "-XOutFile $@"
|
||||
endif
|
||||
|
||||
## other stuff
|
||||
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
#ifndef _EXDLL_H_
|
||||
#define _EXDLL_H_
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define UNUSED __attribute__((unused))
|
||||
#else
|
||||
#define UNUSED
|
||||
#endif
|
||||
|
||||
// only include this file from one place in your DLL.
|
||||
// (it is all static, if you use it in two places it will fail)
|
||||
|
||||
#define EXDLL_INIT() { \
|
||||
g_stringsize=string_size; \
|
||||
g_stacktop=stacktop; \
|
||||
g_variables=variables; }
|
||||
|
||||
// For page showing plug-ins
|
||||
#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8)
|
||||
#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd)
|
||||
#define NOTIFY_BYE_BYE 'x'
|
||||
|
||||
typedef struct _stack_t {
|
||||
struct _stack_t *next;
|
||||
char text[1]; // this should be the length of string_size
|
||||
} stack_t;
|
||||
|
||||
|
||||
static unsigned int g_stringsize;
|
||||
static stack_t **g_stacktop;
|
||||
static char *g_variables;
|
||||
|
||||
static int __stdcall popstring(char *str) UNUSED; // 0 on success, 1 on empty stack
|
||||
static void __stdcall pushstring(const char *str) UNUSED;
|
||||
static char * __stdcall getuservariable(const int varnum) UNUSED;
|
||||
static void __stdcall setuservariable(const int varnum, const char *var) UNUSED;
|
||||
|
||||
enum
|
||||
{
|
||||
INST_0, // $0
|
||||
INST_1, // $1
|
||||
INST_2, // $2
|
||||
INST_3, // $3
|
||||
INST_4, // $4
|
||||
INST_5, // $5
|
||||
INST_6, // $6
|
||||
INST_7, // $7
|
||||
INST_8, // $8
|
||||
INST_9, // $9
|
||||
INST_R0, // $R0
|
||||
INST_R1, // $R1
|
||||
INST_R2, // $R2
|
||||
INST_R3, // $R3
|
||||
INST_R4, // $R4
|
||||
INST_R5, // $R5
|
||||
INST_R6, // $R6
|
||||
INST_R7, // $R7
|
||||
INST_R8, // $R8
|
||||
INST_R9, // $R9
|
||||
INST_CMDLINE, // $CMDLINE
|
||||
INST_INSTDIR, // $INSTDIR
|
||||
INST_OUTDIR, // $OUTDIR
|
||||
INST_EXEDIR, // $EXEDIR
|
||||
INST_LANG, // $LANGUAGE
|
||||
__INST_LAST
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int autoclose;
|
||||
int all_user_var;
|
||||
int exec_error;
|
||||
int abort;
|
||||
int exec_reboot;
|
||||
int reboot_called;
|
||||
int XXX_cur_insttype; // deprecated
|
||||
int XXX_insttype_changed; // deprecated
|
||||
int silent;
|
||||
int instdir_error;
|
||||
int rtl;
|
||||
int errlvl;
|
||||
int alter_reg_view;
|
||||
int status_update;
|
||||
} exec_flags_type;
|
||||
|
||||
typedef struct {
|
||||
exec_flags_type *exec_flags;
|
||||
int (__stdcall *ExecuteCodeSegment)(int, HWND);
|
||||
void (__stdcall *validate_filename)(char *);
|
||||
} extra_parameters;
|
||||
|
||||
// utility functions (not required but often useful)
|
||||
static int __stdcall popstring(char *str)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop || !*g_stacktop) return 1;
|
||||
th=(*g_stacktop);
|
||||
lstrcpyA(str,th->text);
|
||||
*g_stacktop = th->next;
|
||||
GlobalFree((HGLOBAL)th);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __stdcall popstring(wchar_t *str, int len)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop || !*g_stacktop) return 1;
|
||||
th=(*g_stacktop);
|
||||
MultiByteToWideChar(CP_ACP, 0, th->text, -1, str, len);
|
||||
*g_stacktop = th->next;
|
||||
GlobalFree((HGLOBAL)th);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __stdcall pushstring(const char *str)
|
||||
{
|
||||
stack_t *th;
|
||||
if (!g_stacktop) return;
|
||||
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
|
||||
lstrcpynA(th->text,str,g_stringsize);
|
||||
th->next=*g_stacktop;
|
||||
*g_stacktop=th;
|
||||
}
|
||||
|
||||
static char * __stdcall getuservariable(const int varnum)
|
||||
{
|
||||
if (varnum < 0 || varnum >= __INST_LAST) return NULL;
|
||||
return g_variables+varnum*g_stringsize;
|
||||
}
|
||||
|
||||
static void __stdcall setuservariable(const int varnum, const char *var)
|
||||
{
|
||||
if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
|
||||
lstrcpyA(g_variables + varnum*g_stringsize, var);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif//_EXDLL_H_
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
nsisFirewall -- Small NSIS plugin for simple tasks with Windows Firewall
|
||||
Web site: http://wiz0u.free.fr/prog/nsisFirewall
|
||||
|
||||
Copyright (c) 2007-2009 Olivier Marcoux
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#undef UNICODE
|
||||
#undef _UNICODE
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <shlwapi.h>
|
||||
|
||||
#include <initguid.h>
|
||||
#include "netfw.h"
|
||||
#include "exdll.h"
|
||||
|
||||
HRESULT AddAuthorizedApplication(wchar_t * ExceptionName, wchar_t * ProcessPath)
|
||||
{
|
||||
HRESULT hr = CoInitialize(NULL);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
INetFwMgr * mgr = 0;
|
||||
INetFwAuthorizedApplication * app = 0;
|
||||
INetFwPolicy * localPolicy = 0;
|
||||
INetFwProfile * profile = 0;
|
||||
INetFwAuthorizedApplications * apps = 0;
|
||||
|
||||
BSTR bstrRuleName = SysAllocString(ExceptionName);
|
||||
BSTR bstrApplicationName = SysAllocString(ProcessPath);
|
||||
|
||||
hr = CoCreateInstance(CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, IID_INetFwMgr,
|
||||
reinterpret_cast<void**>(static_cast<INetFwMgr**>(&mgr)));
|
||||
if (FAILED(hr)) goto out;
|
||||
|
||||
hr = CoCreateInstance(CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER, IID_INetFwAuthorizedApplication,
|
||||
reinterpret_cast<void**>(static_cast<INetFwAuthorizedApplication**>(&app)));
|
||||
if (FAILED(hr)) goto out;
|
||||
|
||||
app->put_ProcessImageFileName(bstrApplicationName);
|
||||
app->put_Name(bstrRuleName);
|
||||
app->put_Scope(NET_FW_SCOPE_ALL);
|
||||
app->put_IpVersion(NET_FW_IP_VERSION_ANY);
|
||||
app->put_Enabled(VARIANT_TRUE);
|
||||
|
||||
hr = mgr->get_LocalPolicy(&localPolicy);
|
||||
if (FAILED(hr)) goto out;
|
||||
|
||||
hr = localPolicy->get_CurrentProfile(&profile);
|
||||
if (FAILED(hr)) goto out;
|
||||
|
||||
hr = profile->get_AuthorizedApplications(&apps);
|
||||
if (FAILED(hr)) goto out;
|
||||
|
||||
hr = apps->Add(app);
|
||||
|
||||
out:
|
||||
SysFreeString(bstrRuleName);
|
||||
SysFreeString(bstrApplicationName);
|
||||
if(apps) apps->Release();
|
||||
if(profile) profile->Release();
|
||||
if(localPolicy) localPolicy->Release();
|
||||
if(app) app->Release();
|
||||
if(mgr) mgr->Release();
|
||||
CoUninitialize();
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT RemoveAuthorizedApplication(wchar_t * ProcessPath)
|
||||
{
|
||||
HRESULT hr = CoInitialize(NULL);
|
||||
if (FAILED(hr)) return hr;
|
||||
|
||||
INetFwMgr * mgr = 0;
|
||||
INetFwPolicy * localPolicy = 0;
|
||||
INetFwProfile * profile = 0;
|
||||
INetFwAuthorizedApplications * apps = 0;
|
||||
|
||||
BSTR bstrApplicationName = SysAllocString(ProcessPath);
|
||||
|
||||
hr = CoCreateInstance(CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, IID_INetFwMgr,
|
||||
reinterpret_cast<void**>(static_cast<INetFwMgr**>(&mgr)));
|
||||
if (FAILED(hr)) goto out;
|
||||
|
||||
hr = mgr->get_LocalPolicy(&localPolicy);
|
||||
if (FAILED(hr)) goto out;
|
||||
|
||||
hr = localPolicy->get_CurrentProfile(&profile);
|
||||
if (FAILED(hr)) goto out;
|
||||
|
||||
hr = profile->get_AuthorizedApplications(&apps);
|
||||
if (FAILED(hr)) goto out;
|
||||
|
||||
hr = apps->Remove(bstrApplicationName);
|
||||
|
||||
out:
|
||||
SysFreeString(bstrApplicationName);
|
||||
if(apps) apps->Release();
|
||||
if(profile) profile->Release();
|
||||
if(localPolicy) localPolicy->Release();
|
||||
if(mgr) mgr->Release();
|
||||
CoUninitialize();
|
||||
return hr;
|
||||
}
|
||||
|
||||
extern "C" void __declspec(dllexport) AddAuthorizedApplication(HWND hwndParent, int string_size,
|
||||
TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
EXDLL_INIT();
|
||||
|
||||
wchar_t ExceptionName[256], ProcessPath[MAX_PATH];
|
||||
popstring(ProcessPath, MAX_PATH);
|
||||
popstring(ExceptionName, 256);
|
||||
HRESULT result = AddAuthorizedApplication(ExceptionName, ProcessPath);
|
||||
// push the result back to NSIS
|
||||
TCHAR intBuffer[16];
|
||||
wsprintf(intBuffer, _T("%d"), result);
|
||||
pushstring(intBuffer);
|
||||
}
|
||||
|
||||
extern "C" void __declspec(dllexport) RemoveAuthorizedApplication(HWND hwndParent, int string_size,
|
||||
TCHAR *variables, stack_t **stacktop)
|
||||
{
|
||||
EXDLL_INIT();
|
||||
|
||||
wchar_t ProcessPath[MAX_PATH];
|
||||
popstring(ProcessPath, MAX_PATH);
|
||||
HRESULT result = RemoveAuthorizedApplication(ProcessPath);
|
||||
// push the result back to NSIS
|
||||
TCHAR intBuffer[16];
|
||||
wsprintf(intBuffer, _T("%d"), result);
|
||||
pushstring(intBuffer);
|
||||
}
|
||||
|
||||
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -74,6 +74,9 @@ LangString MUI_TEXT_USERPATH ${LANG_English} "User Path"
|
|||
; Game Explorer
|
||||
!include "${SRCDIR}/tools/install\GameExplorer.nsh"
|
||||
|
||||
; Firewall helper
|
||||
!addplugindir "tools/install"
|
||||
|
||||
ShowInstDetails show
|
||||
ShowUnInstDetails show
|
||||
|
||||
|
@ -204,6 +207,9 @@ Section
|
|||
WriteRegStr HKCR "OpenClonk.Update\Shell\Update" "" "Update"
|
||||
WriteRegStr HKCR "OpenClonk.Update\Shell\Update\Command" "" "$\"$INSTDIR\Clonk.exe$\" $\"%1$\""
|
||||
|
||||
; Add a Firewall exception
|
||||
firewall::AddAuthorizedApplication "$INSTDIR\Clonk.exe" "$(^Name)"
|
||||
|
||||
SectionEnd
|
||||
|
||||
|
||||
|
@ -274,4 +280,7 @@ Section Uninstall
|
|||
DeleteRegKey HKCR ".ocu"
|
||||
DeleteRegKey HKCR "OpenClonk.Update"
|
||||
|
||||
; Remove the Firewall exception
|
||||
firewall::RemoveAuthorizedApplication "$INSTDIR\Clonk.exe"
|
||||
|
||||
SectionEnd
|
||||
|
|
Loading…
Reference in New Issue