Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.9 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <shellapi.h>
  5. #include <sddl.h>
  6. DWORD __cdecl main (int argc, char *argv[])
  7. {
  8. WCHAR szPath[4*MAX_PATH];
  9. WCHAR szName[MAX_PATH];
  10. DWORD dwType;
  11. LPTSTR szOldPath;
  12. WCHAR szOutPath[4*MAX_PATH];
  13. BOOL bResult;
  14. if (argc != 3) {
  15. printf("Usage: %s </s|/u> <user name or Sid>\n", argv[0]);
  16. return 0;
  17. }
  18. if (strcmp(argv[1],"/s") == 0) {
  19. WCHAR *szSid, szUserName[MAX_PATH+1], szDomainName[MAX_PATH+1];
  20. PSID pSid;
  21. DWORD cUserName = MAX_PATH, cDomainName = MAX_PATH;
  22. SID_NAME_USE SidUse;
  23. szSid = (WCHAR *)LocalAlloc(LPTR, sizeof(WCHAR)*(1+strlen(argv[2])));
  24. wsprintf(szSid, L"%S", argv[2]);
  25. ConvertStringSidToSid (szSid, &pSid);
  26. if (!LookupAccountSid(NULL, pSid, szUserName, &cUserName, szDomainName, &cDomainName, &SidUse)) {
  27. printf("LookupAccountSid failed with error %d\n", GetLastError());
  28. return 0;
  29. }
  30. printf("UserName = %S, DomainName = %S, SidUse = %d\n", szUserName, szDomainName, SidUse);
  31. return;
  32. }
  33. else {
  34. WCHAR *szSid, szUserName[MAX_PATH+1], szDomainName[MAX_PATH+1];
  35. PSID pSid;
  36. DWORD cUserName = 1024, cDomainName = MAX_PATH;
  37. SID_NAME_USE SidUse;
  38. wsprintf(szUserName, L"%S", argv[2]);
  39. pSid = (SID *)LocalAlloc(LPTR, 1024);
  40. if (!LookupAccountName(NULL, szUserName, pSid, &cUserName, szDomainName, &cDomainName, &SidUse)) {
  41. printf("LookupAccountName failed with error %d\n", GetLastError());
  42. return 0;
  43. }
  44. ConvertSidToStringSid(pSid, &szSid);
  45. printf("SId = %S, Domain = %S, SidUse = %d\n", szSid, szDomainName, SidUse);
  46. return;
  47. }
  48. return 0;
  49. }