15
15
// You should have received a copy of the GNU Lesser General Public License
16
16
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18
#if defined(_WIN32) && !defined(__STDWX_H__)
22
19
#include "boinc_win.h"
20
#elif defined(_WIN32) && defined(__STDWX_H__)
24
#include "diagnostics.h"
24
25
#include "win_util.h"
86
87
// In Windows 2000 we need to use the Product Suite APIs
87
88
// Don't static link because it won't load on non-Win2000 systems
88
hmodNtDll = GetModuleHandle( "NTDLL.DLL" );
89
hmodNtDll = GetModuleHandleA( "NTDLL.DLL" );
89
90
if (hmodNtDll != NULL)
91
92
pfnVerSetConditionMask = (PFnVerSetConditionMask )GetProcAddress( hmodNtDll, "VerSetConditionMask");
92
93
if (pfnVerSetConditionMask != NULL)
94
95
dwlConditionMask = (*pfnVerSetConditionMask)( dwlConditionMask, VER_SUITENAME, VER_AND );
95
hmodK32 = GetModuleHandle( "KERNEL32.DLL" );
96
hmodK32 = GetModuleHandleA( "KERNEL32.DLL" );
96
97
if (hmodK32 != NULL)
98
99
pfnVerifyVersionInfoA = (PFnVerifyVersionInfoA)GetProcAddress( hmodK32, "VerifyVersionInfoA") ;
354
355
pace = (ACCESS_ALLOWED_ACE *)HeapAlloc(
355
356
GetProcessHeap(),
356
357
HEAP_ZERO_MEMORY,
357
sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(psid) -
358
sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(psid) - sizeof(DWORD)
360
361
if (pace == NULL)
363
364
pace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
364
365
pace->Header.AceFlags = CONTAINER_INHERIT_ACE |
365
INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE;
366
pace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE) +
367
GetLengthSid(psid) - sizeof(DWORD);
368
pace->Header.AceSize = (WORD)sizeof(ACCESS_ALLOWED_ACE) +
369
(WORD)GetLengthSid(psid) -
368
371
pace->Mask = GENERIC_ALL;
370
373
if (!CopySid(GetLengthSid(psid), &pace->SidStart, psid))
671
674
if(*Sid == NULL) throw;
673
ReferencedDomain = (LPTSTR)HeapAlloc(
676
ReferencedDomain = (LPSTR)HeapAlloc(
674
677
GetProcessHeap(),
676
cchReferencedDomain * sizeof(TCHAR)
679
cchReferencedDomain * sizeof(CHAR)
679
682
if(ReferencedDomain == NULL) throw;
682
685
// Obtain the SID of the specified account on the specified system.
684
while(!LookupAccountName(
687
while(!LookupAccountNameA(
685
688
SystemName, // machine to lookup account on
686
689
AccountName, // account to lookup
687
690
*Sid, // SID of interest
703
706
if(*Sid == NULL) throw;
705
ReferencedDomain = (LPTSTR)HeapReAlloc(
708
ReferencedDomain = (LPSTR)HeapReAlloc(
706
709
GetProcessHeap(),
708
711
ReferencedDomain,
709
cchReferencedDomain * sizeof(TCHAR)
712
cchReferencedDomain * sizeof(CHAR)
711
714
if(ReferencedDomain == NULL) throw;
741
// Suspend or resume the threads in a given process.
744
// signature of OpenThread()
746
typedef HANDLE (WINAPI *tOT)(
747
DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId
750
// Suspend or resume the threads in a given process,
751
// but don't suspend 'calling_thread'.
742
753
// The only way to do this on Windows is to enumerate
743
754
// all the threads in the entire system,
744
755
// and find those belonging to the process (ugh!!)
748
typedef HANDLE (WINAPI *tOT)(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId);
750
int suspend_or_resume_threads(DWORD pid, bool resume) {
758
int suspend_or_resume_threads(
759
DWORD pid, DWORD calling_thread_id, bool resume
751
761
HANDLE threads, thread;
752
HMODULE hKernel32Lib = NULL;
762
static HMODULE hKernel32Lib = NULL;
753
763
THREADENTRY32 te = {0};
764
static tOT pOT = NULL;
756
766
// Dynamically link to the proper function pointers.
757
hKernel32Lib = GetModuleHandle("kernel32.dll");
758
pOT = (tOT) GetProcAddress( hKernel32Lib, "OpenThread" );
768
hKernel32Lib = GetModuleHandleA("kernel32.dll");
771
pOT = (tOT) GetProcAddress( hKernel32Lib, "OpenThread" );
788
if (!diagnostics_is_thread_exempt_suspend(te.th32ThreadID)) continue;
789
if (te.th32ThreadID == calling_thread_id) continue;
774
790
if (te.th32OwnerProcessID == pid) {
775
791
thread = pOT(THREAD_SUSPEND_RESUME, FALSE, te.th32ThreadID);
776
792
resume ? ResumeThread(thread) : SuspendThread(thread);
829
845
if (hkSetupHive) RegCloseKey(hkSetupHive);
830
846
if (lpszRegistryValue) free(lpszRegistryValue);
850
// return true if running under remote desktop
851
// (in which case CUDA apps don't work)
853
typedef BOOL (__stdcall *tWTSQSI)( IN HANDLE, IN DWORD, IN DWORD, OUT LPTSTR*, OUT DWORD* );
854
typedef VOID (__stdcall *tWTSFM)( IN PVOID );
856
bool is_remote_desktop() {
857
static HMODULE wtsapi32lib = NULL;
858
static tWTSQSI pWTSQSI = NULL;
859
static tWTSFM pWTSFM = NULL;
864
wtsapi32lib = LoadLibrary(_T("wtsapi32.dll"));
866
pWTSQSI = (tWTSQSI)GetProcAddress(wtsapi32lib, "WTSQuerySessionInformationA");
867
pWTSFM = (tWTSFM)GetProcAddress(wtsapi32lib, "WTSFreeMemory");
871
// WTSQuerySessionInformation(
872
// WTS_CURRENT_SERVER_HANDLE,
873
// WTS_CURRENT_SESSION,
874
// WTSClientProtocolType,
886
USHORT prot = *(USHORT*)pBuf;
888
if (prot == 2) return true;