PageRenderTime 124ms CodeModel.GetById 60ms app.highlight 11ms RepoModel.GetById 49ms app.codeStats 0ms

/admin/win/nsi/nsis_uac/uac.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 169 lines | 134 code | 25 blank | 10 comment | 5 complexity | 4d605c083624b8d004e4b5a51f4e21d5 MD5 | raw file
  1//Copyright (C) 2007 Anders Kjersem. Licensed under the zlib/libpng license, see License.txt for details.
  2#pragma once

  3/** /#define BUILD_DBGRELEASE // Include simple debug output in release version */
  4/** /#define BUILD_DBGSELECTELVMODE //Test MyRunAs*/
  5
  6/** /#define UNICODE // Unicode build */
  7/**/#define FEAT_CUSTOMRUNASDLG // Include custom runas dialog */
  8/**/#define FEAT_CUSTOMRUNASDLG_TRANSLATE //*/
  9/**/#define FEAT_MSRUNASDLGMODHACK // Default to other user radio button */
 10
 11
 12#if !defined(APSTUDIO_INVOKED) && !defined(RC_INVOKED)

 13
 14#if (defined(_MSC_VER) && !defined(_DEBUG))

 15	#pragma comment(linker,"/opt:nowin98")

 16	#pragma comment(linker,"/ignore:4078")

 17	#pragma comment(linker,"/merge:.rdata=.text")

 18	
 19	//#pragma intrinsic(memset) //http://www.codeguru.com/forum/showthread.php?t=371491&page=2&pp=15 | http://www.ddj.com/windows/184416623
 20#endif

 21
 22#if defined(UNICODE) && !defined(_UNICODE)

 23#define _UNICODE

 24#endif

 25#ifdef _UNICODE

 26#define TFUNCSUFFIX W

 27#else

 28#define TFUNCSUFFIX A

 29#endif

 30#define _PCJOIN(a,b) a##b

 31#define PCJOIN(a,b) _PCJOIN(a,b)

 32
 33
 34#define _WIN32_WINNT 0x0501

 35#define WIN32_LEAN_AND_MEAN

 36#include <windows.h>

 37#include <ShellAPI.h>

 38#include <TChar.h>

 39#include "NSISUtil.h"

 40
 41#ifndef SEE_MASK_NOZONECHECKS

 42#define SEE_MASK_NOZONECHECKS 0x00800000

 43#endif

 44
 45#define COUNTOF(___c) ( sizeof(___c)/sizeof(___c[0]) )

 46#ifndef ARRAYSIZE

 47#define ARRAYSIZE COUNTOF

 48#endif

 49#define FORCEINLINE __forceinline

 50
 51#if _MSC_VER >= 1400

 52extern void* __cdecl memset(void*mem,int c,size_t len);
 53#endif

 54
 55FORCEINLINE LRESULT MySndDlgItemMsg(HWND hDlg,int id,UINT Msg,WPARAM wp=0,LPARAM lp=0) {return SendMessage(GetDlgItem(hDlg,id),Msg,wp,lp);}
 56#ifndef UAC_NOCUSTOMIMPLEMENTATIONS

 57FORCEINLINE HANDLE WINAPI GetCurrentProcess(){return ((HANDLE)(-1));}
 58FORCEINLINE HANDLE WINAPI GetCurrentThread(){return ((HANDLE)(-2));}
 59
 60#define MyTStrLen lstrlen

 61
 62#undef lstrcpy

 63#define lstrcpy MyTStrCpy

 64FORCEINLINE LPTSTR MyTStrCpy(LPTSTR s1,LPCTSTR s2) {return PCJOIN(lstr,PCJOIN(cpyn,TFUNCSUFFIX))(s1,s2,0x7FFFFFFF);}
 65
 66#undef lstrcat

 67#define lstrcat MyTStrCat

 68LPTSTR MyTStrCat(LPTSTR s1,LPCTSTR s2) 
 69#ifdef UAC_INITIMPORTS

 70{return s1?MyTStrCpy(&s1[MyTStrLen(s1)],s2):NULL;}
 71#else

 72;
 73#endif //UAC_INITIMPORTS
 74
 75#endif //UAC_NOCUSTOMIMPLEMENTATIONS
 76
 77
 78//DelayLoaded functions:
 79typedef BOOL	(WINAPI*ALLOWSETFOREGROUNDWINDOW)(DWORD dwProcessId);
 80typedef BOOL	(WINAPI*OPENPROCESSTOKEN)(HANDLE ProcessHandle,DWORD DesiredAccess,PHANDLE TokenHandle);
 81typedef BOOL	(WINAPI*OPENTHREADTOKEN)(HANDLE ThreadHandle,DWORD DesiredAccess,BOOL OpenAsSelf,PHANDLE TokenHandle);
 82typedef BOOL	(WINAPI*GETTOKENINFORMATION)(HANDLE hToken,TOKEN_INFORMATION_CLASS TokInfoClass,LPVOID TokInfo,DWORD TokInfoLenh,PDWORD RetLen);
 83typedef BOOL	(WINAPI*ALLOCATEANDINITIALIZESID)(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,BYTE nSubAuthorityCount,DWORD sa0,DWORD sa1,DWORD sa2,DWORD sa3,DWORD sa4,DWORD sa5,DWORD sa6,DWORD sa7,PSID*pSid);
 84typedef PVOID	(WINAPI*FREESID)(PSID pSid);
 85typedef BOOL	(WINAPI*EQUALSID)(PSID pSid1,PSID pSid2);
 86typedef BOOL	(WINAPI*CHECKTOKENMEMBERSHIP)(HANDLE TokenHandle,PSID SidToCheck,PBOOL IsMember);
 87#ifdef FEAT_CUSTOMRUNASDLG

 88typedef BOOL	(WINAPI*GETUSERNAME)(LPTSTR lpBuffer,LPDWORD nSize);
 89typedef BOOL	(WINAPI*CREATEPROCESSWITHLOGONW)(LPCWSTR lpUsername,LPCWSTR lpDomain,LPCWSTR lpPassword,DWORD dwLogonFlags,LPCWSTR lpApplicationName,LPWSTR lpCommandLine,DWORD dwCreationFlags,LPVOID pEnv,LPCWSTR WorkDir,LPSTARTUPINFOW pSI,LPPROCESS_INFORMATION pPI);
 90#define SECURITY_WIN32

 91#include <Security.h>//NameSamCompatible

 92typedef BOOLEAN	(WINAPI*GETUSERNAMEEX)(EXTENDED_NAME_FORMAT NameFormat,LPTSTR lpNameBuffer,PULONG nSize);
 93#endif

 94#ifdef UAC_INITIMPORTS

 95ALLOWSETFOREGROUNDWINDOW _AllowSetForegroundWindow=0;
 96OPENPROCESSTOKEN		_OpenProcessToken=0;
 97OPENTHREADTOKEN			_OpenThreadToken=0;
 98GETTOKENINFORMATION		_GetTokenInformation=0;
 99ALLOCATEANDINITIALIZESID _AllocateAndInitializeSid=0;
100FREESID					_FreeSid=0;
101EQUALSID				_EqualSid=0;
102CHECKTOKENMEMBERSHIP	_CheckTokenMembership=0;
103#ifdef FEAT_CUSTOMRUNASDLG

104GETUSERNAME				_GetUserName=0;
105GETUSERNAMEEX			_GetUserNameEx=0;
106CREATEPROCESSWITHLOGONW	_CreateProcessWithLogonW=0;
107#endif

108#else

109#ifdef FEAT_CUSTOMRUNASDLG

110extern GETUSERNAME _GetUserName;
111extern GETUSERNAMEEX _GetUserNameEx;
112extern CREATEPROCESSWITHLOGONW _CreateProcessWithLogonW;
113#endif

114#endif /* UAC_INITIMPORTS */ 

115
116
117extern DWORD DelayLoadDlls();
118#ifdef FEAT_CUSTOMRUNASDLG

119extern DWORD MyRunAs(HINSTANCE hInstDll,SHELLEXECUTEINFO&sei);
120#endif

121
122#if !defined(NTDDI_VISTA) || defined(BUILD_OLDSDK)

123//#if !defined(NTDDI_VERSION) || (NTDDI_VERSION < 0x06000000) || !defined(NTDDI_VISTA) 
124//#if !defined(TOKEN_ELEVATION_TYPE) || defined(BUILD_OLDSDK)
125enum TOKEN_ELEVATION_TYPE { 
126	TokenElevationTypeDefault = 1, 
127	TokenElevationTypeFull, 
128	TokenElevationTypeLimited 
129};
130enum _TOKEN_INFORMATION_CLASS___VISTA {
131	TokenElevationType = (TokenOrigin+1),
132	TokenLinkedToken,
133	TokenElevation,
134	TokenHasRestrictions,
135	TokenAccessInformation,
136	TokenVirtualizationAllowed,
137	TokenVirtualizationEnabled,
138	TokenIntegrityLevel,
139	TokenUIAccess,
140	TokenMandatoryPolicy,
141	TokenLogonSid,
142};
143#endif

144
145
146#if defined(_DEBUG) || defined(BUILD_DBGRELEASE)

147//Simple debug helpers:
148#define  BUILD_DBG

149/** /#define BUILD_XPTEST //Pretend UAC exists and "elevate" with NT runas */ 
150#define DBG_RESETDBGVIEW() do{HWND hDbgView=FindWindowA("dbgviewClass",0);PostMessage(hDbgView,WM_COMMAND,40020,0);if(0)SetForegroundWindow(hDbgView);}while(0)

151#define _pp_MakeStr_(x)	#x

152#define pp_MakeStr(x)	_pp_MakeStr_(x)

153#define TRACE OutputDebugStringA

154#define DBGONLY(_x) _x

155#ifndef ASSERT

156#define ASSERT(_x) do{if(!(_x)){MessageBoxA(GetActiveWindow(),#_x##"\n\n"##__FILE__##":"## pp_MakeStr(__LINE__),"SimpleAssert",0);/*TRACE(#_x##"\n"##__FILE__##":" pp_MakeStr(__LINE__)"\n");*/}}while(0)

157#endif

158#define VERIFY(_x) ASSERT(_x)

159static void TRACEF(const char*fmt,...) {va_list a;va_start(a,fmt);static TCHAR b[1024*4];if (sizeof(TCHAR)!=sizeof(char)){static TCHAR fmtBuf[COUNTOF(b)];VERIFY(wsprintf(fmtBuf,_T("%hs"),fmt)<COUNTOF(fmtBuf));fmt=(LPCSTR)fmtBuf;}wvsprintf(b,(TCHAR*)fmt,a);OutputDebugString(b);}
160#else

161#define TRACE /*(void)0*/

162#define DBGONLY(_x)

163#define ASSERT(_x)

164#define VERIFY(_x) ((void)(_x))

165#define TRACEF TRACE

166#endif /* DEBUG */

167
168#endif /* APSTUDIO_INVOKED */

169