4377N/A * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A long pIndex = -
1;
// index of primaryGroup in groups array 0N/A // get NT information first 0N/A // then set values into NTSystem 0N/A // Unable to find exception class 0N/A // primary group may or may not be part of supplementary groups 0N/A // found primary group in groups array 0N/A // primary group is only group in groups array 0N/A // the groups array is non-empty, 0N/A // and may or may not contain the primary group 0N/A // primary group not in groups array 0N/A // primary group in groups array - 0N/A // allocate one less array entry and do not add into new array 0N/A // continue if equal to primary group 0N/A printf(
"unable to find IllegalArgumentException class\n");
0N/A // first try the thread token 0N/A // next try the process token 0N/A printf(
" [getToken] OpenProcessToken error [%d]: ",
0N/A printf(
" [getToken] got user access token\n");
0N/A // get token information 0N/A NULL,
// TokenInformation - if NULL get buffer size 0N/A 0,
// since TokenInformation is NULL 0N/A printf(
" [getUser] GetTokenInformation error [%d]: ",
0N/A printf(
" [getUser] LookupAccountSid error [%d]: ",
0N/A printf(
" [getUser] userName: %s, domainName = %s\n",
0N/A printf(
" [getUser] LookupAccountName error [%d]: ",
0N/A // ok not to have a domain SID (no error) 0N/A // get token information 0N/A NULL,
// TokenInformation - if NULL get buffer size 0N/A 0,
// since TokenInformation is NULL 0N/A printf(
" [getPrimaryGroup] GetTokenInformation error [%d]: ",
0N/A printf(
" [getPrimaryGroup] Got TokenPrimaryGroup info\n");
0N/A // get token information 0N/A NULL,
// TokenInformation - if NULL get buffer size 0N/A 0,
// since TokenInformation is NULL 0N/A printf(
" [getGroups] GetTokenInformation error [%d]: ",
0N/A printf(
" [getGroups] Got TokenGroups info\n");
0N/A // return group info 0N/A (
" [getImpersonationToken] OpenProcessToken error [%d]: ",
0N/A printf(
" [getImpersonationToken] DuplicateToken error [%d]: ",
0N/A // Validate the binary SID. 0N/A // Get the identifier authority value from the SID. 0N/A // Get the number of subauthorities in the SID. 0N/A // Compute the buffer length. 0N/A // S-SID_REVISION- + IdentifierAuthority- + subauthorities- + NULL 0N/A // Check input buffer length. 0N/A // If too small, indicate the proper size and set last error. 0N/A // Add 'S' prefix and revision number to the string. 0N/A // Add SID identifier authority to the string. 0N/A TEXT(
"0x%02hx%02hx%02hx%02hx%02hx%02hx"),
0N/A // Add SID subauthorities to the string. 0N/A // If dwLastError is in the network range, 0N/A // load the message source. 0N/A // Call FormatMessage() to allow for message 0N/A // text to be acquired from the system 0N/A // or from the supplied module handle. 0N/A hModule,
// module to get message from (NULL == system) 0N/A // Output message string on stderr. 0N/A // Free the buffer allocated by the system. 0N/A // If we loaded a message source, unload it. 0N/A * 1. comment out first two #includes 0N/A * 2. set 'debug' to TRUE 0N/A * 3. comment out 'getCurrent' 0N/A * 4. uncomment 'main' 0N/A * 6. link nt.obj user32.lib advapi32.lib /out:nt.exe 0N/Avoid main(int argc, char *argv[]) { 0N/A HANDLE tokenHandle = INVALID_HANDLE_VALUE; 0N/A LPTSTR userName = NULL; 0N/A LPTSTR userSid = NULL; 0N/A LPTSTR domainName = NULL; 0N/A LPTSTR domainSid = NULL; 0N/A LPTSTR primaryGroup = NULL; 0N/A DWORD numGroups = 0; 0N/A LPTSTR *groups = NULL; 0N/A HANDLE impersonationToken = 0; 0N/A printf("getting access token\n"); 0N/A if (getToken(&tokenHandle) == FALSE) { 0N/A printf("getting user info\n"); 0N/A (tokenHandle, &userName, &domainName, &userSid, &domainSid) == FALSE) { 0N/A printf("getting primary group\n"); 0N/A if (getPrimaryGroup(tokenHandle, &primaryGroup) == FALSE) { 0N/A printf("getting supplementary groups\n"); 0N/A if (getGroups(tokenHandle, &numGroups, &groups) == FALSE) { 0N/A printf("getting impersonation token\n"); 0N/A if (getImpersonationToken(&impersonationToken) == FALSE) { 0N/A printf("userName = %s, userSid = %s, domainName = %s, domainSid = %s\n", 0N/A userName, userSid, domainName, domainSid); 0N/A printf("primaryGroup = %s\n", primaryGroup); 0N/A for (i = 0; i < numGroups; i++) { 0N/A printf("Group[%d] = %s\n", i, groups[i]); 0N/A printf("impersonationToken = %ld\n", impersonationToken); 0N/A if (userName != NULL) { 0N/A HeapFree(GetProcessHeap(), 0, userName); 0N/A if (userSid != NULL) { 0N/A HeapFree(GetProcessHeap(), 0, userSid); 0N/A if (domainName != NULL) { 0N/A HeapFree(GetProcessHeap(), 0, domainName); 0N/A if (domainSid != NULL) { 0N/A HeapFree(GetProcessHeap(), 0, domainSid); 0N/A if (primaryGroup != NULL) { 0N/A HeapFree(GetProcessHeap(), 0, primaryGroup); 0N/A if (groups != NULL) { 0N/A for (i = 0; i < numGroups; i++) { 0N/A if (groups[i] != NULL) { 0N/A HeapFree(GetProcessHeap(), 0, groups[i]); 0N/A HeapFree(GetProcessHeap(), 0, groups); 4377N/A CloseHandle(impersonationToken); 0N/A * extra main method for testing debug printing 0N/Avoid main(int argc, char *argv[]) { 0N/A fprintf(stderr,"Usage: %s <error number>\n", argv[0]); 0N/A DisplayErrorText(atoi(argv[1]));