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.

133 lines
3.9 KiB

  1. //
  2. // This file contains two routines to map a given RID to the corresponding
  3. // user name or group name
  4. // It may become part of a bigger library at some later date, but for now
  5. // it is just included in the source files
  6. // Main purpose? Localization support
  7. //
  8. #ifndef _ACCOUNT_INFO_C_
  9. #define _ACCOUNT_INFO_C
  10. BOOL LookupAliasFromRid(LPWSTR TargetComputer, DWORD Rid, LPWSTR Name, PDWORD cchName)
  11. {
  12. SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY;
  13. SID_NAME_USE snu;
  14. PSID pSid;
  15. WCHAR DomainName[DNLEN+1];
  16. DWORD cchDomainName = DNLEN;
  17. BOOL bSuccess = FALSE;
  18. //
  19. // Sid is the same regardless of machine, since the well-known
  20. // BUILTIN domain is referenced.
  21. //
  22. if(AllocateAndInitializeSid(
  23. &sia,
  24. 2,
  25. SECURITY_BUILTIN_DOMAIN_RID,
  26. Rid,
  27. 0, 0, 0, 0, 0, 0,
  28. &pSid
  29. ))
  30. {
  31. bSuccess = LookupAccountSidW(
  32. TargetComputer,
  33. pSid,
  34. Name,
  35. cchName,
  36. DomainName,
  37. &cchDomainName,
  38. &snu
  39. );
  40. FreeSid(pSid);
  41. }
  42. return bSuccess;
  43. }
  44. BOOL LookupUserGroupFromRid(LPWSTR TargetComputer, DWORD Rid, LPWSTR Name, PDWORD cchName)
  45. {
  46. PUSER_MODALS_INFO_2 umi2;
  47. NET_API_STATUS nas;
  48. UCHAR SubAuthorityCount;
  49. PSID pSid;
  50. SID_NAME_USE snu;
  51. WCHAR DomainName[DNLEN+1];
  52. DWORD cchDomainName = DNLEN;
  53. BOOL bSuccess = FALSE; // assume failure
  54. //
  55. // get the account domain Sid on the target machine
  56. // note: if you were looking up multiple sids based on the same
  57. // account domain, only need to call this once.
  58. //
  59. nas = NetUserModalsGet(TargetComputer, 2, (LPBYTE *)&umi2);
  60. if(nas != NERR_Success)
  61. {
  62. SetLastError(nas);
  63. return FALSE;
  64. }
  65. SubAuthorityCount = *GetSidSubAuthorityCount(umi2->usrmod2_domain_id);
  66. //
  67. // allocate storage for new Sid. account domain Sid + account Rid
  68. //
  69. pSid = (PSID)HeapAlloc(GetProcessHeap(),
  70. 0,
  71. GetSidLengthRequired((UCHAR)(SubAuthorityCount + 1)));
  72. if(pSid != NULL)
  73. {
  74. if(InitializeSid(
  75. pSid,
  76. GetSidIdentifierAuthority(umi2->usrmod2_domain_id),
  77. (BYTE)(SubAuthorityCount+1)
  78. ))
  79. {
  80. DWORD SubAuthIndex = 0;
  81. //
  82. // copy existing subauthorities from account domain Sid into
  83. // new Sid
  84. //
  85. for( ; SubAuthIndex < SubAuthorityCount ; SubAuthIndex++)
  86. {
  87. *GetSidSubAuthority(pSid, SubAuthIndex) =
  88. *GetSidSubAuthority(umi2->usrmod2_domain_id, SubAuthIndex);
  89. }
  90. //
  91. // append Rid to new Sid
  92. //
  93. *GetSidSubAuthority(pSid, SubAuthorityCount) = Rid;
  94. bSuccess = LookupAccountSidW(
  95. TargetComputer,
  96. pSid,
  97. Name,
  98. cchName,
  99. DomainName,
  100. &cchDomainName,
  101. &snu
  102. );
  103. }
  104. HeapFree(GetProcessHeap(), 0, pSid);
  105. }
  106. NetApiBufferFree(umi2);
  107. return bSuccess;
  108. }
  109. #endif