forked from reactos/reactos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
news2
52 lines (40 loc) · 1.86 KB
/
news2
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
Re: alternative to SeCaptureSubjectContext for Win2000 sought
From: "dave porter" <[email protected]>
Reply to: "dave porter"
Date: Mon, 26 Jun 2000 10:57:18 -0400
Newsgroups:
comp.os.ms-windows.programmer.nt.kernel-mode
Followup to: newsgroup
References:
> Under advise, I have tried ZwOpenProcessToken(), but to little avail.
> ZwQueryInformationToken( ..TokenUser ...) doesn't seem to want to do its
job
> either under NT4.
I could be jumping in the middle here, but in what way doesn't it work?
This code works for me:
int bufLen = 256; // we suppose this is enough
void* sidBuf = new char[bufLen];
int sidLen = 0;
void* pToken = PsReferencePrimaryToken(PsGetCurrentProcess());
if (!pToken) ... error ...
NTSTATUS ntstatus = ObOpenObjectByPointer(pToken, 0, 0, TOKEN_QUERY,
0, KernelMode, &handle);
if (!NT_SUCCESS(ntstatus)) ... error ...
TOKEN_USER* user = static_cast<TOKEN_USER*>(sidBuf);
ULONG tokenInfoLen;
ntstatus = ZwQueryInformationToken(handle, TokenUser, user, bufLen,
&tokenInfoLen);
if (!NT_SUCCESS(ntstatus)) ... error ...
assert(tokenInfoLen <= bufLen); // else we would have got an error,
right?
assert(user->User.Sid == user+1); // SID is in buffer just past
TOKEN_USER structure
sidLen = tokenInfoLen - sizeof (TOKEN_USER);
memmove(sidBuf, user->User.Sid, sidLen); // shuffle down the buffer
Naturally, this returns the id of the thread that's running it.
If you execute this in DriverEntry, you're running in some
thread in the system process, which is not related to
the thread which executed the Win32 StartService call.