What I'm trying to understand is whether LogonUser
with LOGON32_LOGON_INTERACTIVE
produces restricted token or not? Here is my code:
int davai() { FILE * fp; fp = fopen ("C:\\tmp\\davai.txt", "a"); fprintf(fp, "shevedi davai"); fflush(fp); HANDLE token = NULL; HANDLE dupToken = NULL; if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_DUPLICATE, &token)) { fprintf(fp, "davai: OpenProcessToken cheijva. %d\n", (int)GetLastError()); fflush(fp); } if (DuplicateTokenEx(token, MAXIMUM_ALLOWED, NULL, SecurityDelegation, TokenPrimary, &dupToken) == 0) { fprintf(fp, "davai: OpenProcessToken DuplicateTokenEx. %d\n", (int)GetLastError()); fflush(fp); } PTOKEN_GROUPS pPrivilegesToken = NULL; DWORD cbSize = 0; GetTokenInformation(dupToken, TokenGroups, NULL, 0, &cbSize); pPrivilegesToken = (PTOKEN_GROUPS) LocalAlloc(LPTR, cbSize); if (GetTokenInformation(dupToken, TokenGroups, pPrivilegesToken, cbSize, &cbSize) == FALSE) { fprintf(fp, "davai: GetTokenInformation cheijva. %d\n", (int)GetLastError()); fflush(fp); } char * gio; for (ULONG i = 0; i < pPrivilegesToken->GroupCount; i++) { if (ConvertSidToStringSid(pPrivilegesToken->Groups[i].Sid, &gio) == 0) { fprintf(fp, "davai: ConvertSidToStringSid cheijva. %d\n", (int)GetLastError()); fflush(fp); } fprintf(fp, "Value: %s attribute -> %ld \n",gio, pPrivilegesToken->Groups[i].Attributes); fflush(fp); } LocalFree (gio); return 1; }
which is run by a token which was obtained by LOGON32_LOGON_INTERACTIVE
. And my output is this:
Value: S-1-5-21-1018819917-2920201817-244685803-513 attribute -> 7 Value: S-1-1-0 attribute -> 7 Value: S-1-5-21-1018819917-2920201817-244685803-1000 attribute -> 7 Value: S-1-5-32-544 attribute -> 16 Value: S-1-5-32-545 attribute -> 7 Value: S-1-5-4 attribute -> 7 Value: S-1-2-1 attribute -> 7 Value: S-1-5-11 attribute -> 7 Value: S-1-5-15 attribute -> 7 Value: S-1-5-5-0-19732224 attribute -> -1073741817 Value: S-1-5-64-10 attribute -> 7 Value: S-1-16-8192 attribute -> 96
Notice the 16
with Administrators Group
. If I use LOGON32_LOGON_BATCH
I get this:
S-1-5-21-1018819917-2920201817-244685803-513 attribute -> 7 Value: S-1-1-0 attribute -> 7 Value: S-1-5-21-1018819917-2920201817-244685803-1000 attribute -> 7 Value: S-1-5-32-544 attribute -> 15 Value: S-1-5-32-545 attribute -> 7 Value: S-1-5-3 attribute -> 7 Value: S-1-2-1 attribute -> 7 Value: S-1-5-11 attribute -> 7 Value: S-1-5-15 attribute -> 7 Value: S-1-2-0 attribute -> 7 Value: S-1-5-5-0-20537541 attribute -> -1073741817 Value: S-1-5-64-10 attribute -> 7 Value: S-1-16-12288 attribute -> 96
I also found that some people have same problem as I do.
1)Perl: IsAdminUser returns incorrect value
2)In Windows: How do you programatically launch a process in administrator mode under another user context?
3)How to call LogonUser() to get a non-restricted full token inside a Windows Service with UAC enabled?
It seems to me that LOGON32_LOGON_INTERACTIVE
produces restricted token (or is it that just different types of logons produce different kind of token?), Is there any documentation that would verify that I'm right?