blob: e2cd599563ebf5b8d70f25e161090296b62dd0ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
#include "precomp.h"
using namespace System;
using namespace System::Security::Principal;
using namespace Xunit;
using namespace WixInternal::TestSupport;
using namespace WixInternal::TestSupport::XunitExtensions;
namespace DutilTests
{
public ref class ProcUtil
{
public:
[Fact]
void ProcGetTokenInformationTest()
{
HRESULT hr = S_OK;
TOKEN_USER* pTokenUser = NULL;
LPWSTR sczSid = NULL;
try
{
hr = ProcGetTokenInformation(::GetCurrentProcess(), TokenUser, reinterpret_cast<LPVOID*>(&pTokenUser));
NativeAssert::Succeeded(hr, "Failed to get TokenUser for current process.");
if (!::ConvertSidToStringSidW(pTokenUser->User.Sid, &sczSid))
{
hr = HRESULT_FROM_WIN32(::GetLastError());
NativeAssert::Succeeded(hr, "Failed to get string SID from TokenUser SID.");
}
Assert::Equal<String^>(WindowsIdentity::GetCurrent()->User->Value, gcnew String(sczSid));
}
finally
{
ReleaseMem(pTokenUser);
ReleaseStr(sczSid);
}
}
[SkippableFact]
void ProcHasPrivilegeTest()
{
HRESULT hr = S_OK;
BOOL fHasPrivilege = FALSE;
hr = ProcHasPrivilege(::GetCurrentProcess(), SE_CREATE_TOKEN_NAME, &fHasPrivilege);
NativeAssert::Succeeded(hr, "Failed to check privilege for current process.");
if (fHasPrivilege)
{
WixAssert::Skip("Didn't expect process to have SE_CREATE_TOKEN_NAME privilege");
}
hr = ProcHasPrivilege(::GetCurrentProcess(), SE_INC_WORKING_SET_NAME, &fHasPrivilege);
NativeAssert::Succeeded(hr, "Failed to check privilege for current process.");
if (!fHasPrivilege)
{
WixAssert::Skip("Expected process to have SE_INC_WORKING_SET_NAME privilege");
}
}
};
}
|