#include #include #define _WIN32_WINNT 0x0a00 #define WINVER 0x0a00 #include #include #include #include int main () { HANDLE tok; PTOKEN_USER tp = (PTOKEN_USER) malloc (65536); DWORD ret; LPSTR str; WCHAR name[256]; WCHAR dom[256]; WCHAR aname[513]; PSID rsid = (PSID) malloc (128); DWORD nlen, dlen, rlen; SID_NAME_USE type; if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &tok)) { printf ("OpenProcessToken: %u\n", GetLastError ()); return 1; } if (!GetTokenInformation (tok, TokenUser, tp, 65536, &ret)) { printf ("GetTokenInformation(user): %u\n", GetLastError ()); return 1; } ConvertSidToStringSidA (tp->User.Sid, &str); printf ("Sid: %s\n", str); LocalFree (str); nlen = dlen = 256; if (LookupAccountSidW (NULL, tp->User.Sid, name, &nlen, dom, &dlen, &type)) printf ("Dom\\Name: %ls\\%ls\n", dom, name); else printf ("LookupAccountSidW: %u\n", GetLastError ()); rlen = 128; dlen = 256; if (LookupAccountNameW (NULL, name, rsid, &rlen, dom, &dlen, &type)) { ConvertSidToStringSidA (rsid, &str); printf ("Reverse Sid (%ls): %s\n", name, str); LocalFree (str); } else printf ("LookupAccountNameW (%ls): %u\n", name, GetLastError ()); wcpcpy (wcpcpy (wcpcpy (aname, dom), L"\\"), name); rlen = 128; dlen = 256; if (LookupAccountNameW (NULL, aname, rsid, &rlen, dom, &dlen, &type)) { ConvertSidToStringSidA (rsid, &str); printf ("Reverse Sid (%ls): %s\n", aname, str); LocalFree (str); } else printf ("LookupAccountNameW (%ls): %u\n", aname, GetLastError ()); return 0; }