Source code of Windows XP (NT5)
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.

127 lines
3.4 KiB

  1. // Copyright (C) 1999 Microsoft Corporation
  2. //
  3. // Implementation of ICloneSecurityPrincipal::AddSidHistory
  4. //
  5. // sburns 5-3-99
  6. #include "headers.hxx"
  7. #include "resource.h"
  8. #include "common.hpp"
  9. #include "implmain.hpp"
  10. HRESULT
  11. CloneSecurityPrincipal::DoAddSidHistory(
  12. const String& srcPrincipalSamName,
  13. const String& dstPrincipalSamName,
  14. long flags)
  15. {
  16. LOG_FUNCTION(CloneSecurityPrincipal::DoAddSidHistory);
  17. if (srcPrincipalSamName.empty())
  18. {
  19. SetComError(IDS_MISSING_SRC_SAM_NAME);
  20. return E_INVALIDARG;
  21. }
  22. if (flags)
  23. {
  24. // not used, should be 0
  25. SetComError(IDS_FLAGS_ARE_UNUSED);
  26. return E_INVALIDARG;
  27. }
  28. if (!connection || !connection->IsConnected())
  29. {
  30. SetComError(IDS_MUST_CONNECT_FIRST);
  31. return Win32ToHresult(ERROR_ONLY_IF_CONNECTED);
  32. };
  33. // At this point, the Computer objects contain the normalized
  34. // source and destination DC names, and their domains, and any
  35. // necessary authenticated connections to those DCs have been
  36. // established.
  37. HRESULT hr = S_OK;
  38. do
  39. {
  40. // use DNS names, if we have them
  41. String srcDc = connection->srcDcDnsName;
  42. String srcDomain = connection->srcComputer->GetDomainDnsName();
  43. if (srcDomain.empty())
  44. {
  45. // source domain not win2k, so use netbios names.
  46. srcDomain = connection->srcComputer->GetDomainNetbiosName();
  47. srcDc = connection->srcComputer->GetNetbiosName();
  48. }
  49. // use a DNS domain name as the dest domain is NT 5
  50. String dstDomain = connection->dstComputer->GetDomainDnsName();
  51. // if dstPrincipalSamName is not specified, use srcPrincipalSamName
  52. String dstSamName =
  53. dstPrincipalSamName.empty()
  54. ? srcPrincipalSamName
  55. : dstPrincipalSamName;
  56. SEC_WINNT_AUTH_IDENTITY authInfo;
  57. authInfo.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
  58. authInfo.User = 0;
  59. authInfo.UserLength = 0;
  60. authInfo.Domain = 0;
  61. authInfo.DomainLength = 0;
  62. authInfo.Password = 0;
  63. authInfo.PasswordLength = 0;
  64. LOG(L"Calling DsAddSidHistory");
  65. LOG(String::format(L"Flags : %1!X!", 0));
  66. LOG(String::format(L"SrcDomain : %1", srcDomain.c_str()));
  67. LOG(String::format(L"SrcPrincipal : %1", srcPrincipalSamName.c_str()));
  68. LOG(String::format(L"SrcDomainController : %1", srcDc.c_str()));
  69. LOG(String::format(L"DstDomain : %1", dstDomain.c_str()));
  70. LOG(String::format(L"DstPrincipal : %1", dstSamName.c_str()));
  71. hr =
  72. Win32ToHresult(
  73. ::DsAddSidHistory(
  74. connection->dstDsBindHandle,
  75. 0, // unused
  76. srcDomain.c_str(),
  77. srcPrincipalSamName.c_str(),
  78. srcDc.c_str(),
  79. 0, // &authInfo,
  80. dstDomain.c_str(),
  81. dstSamName.c_str()));
  82. LOG_HRESULT(hr);
  83. if (FAILED(hr))
  84. {
  85. unsigned id = IDS_ADD_SID_HISTORY_FAILED;
  86. if (hr == Win32ToHresult(ERROR_INVALID_HANDLE))
  87. {
  88. // this is typically due to misconfiguring the source dc
  89. id = IDS_ADD_SID_HISTORY_FAILED_WITH_INVALID_HANDLE;
  90. }
  91. SetComError(
  92. String::format(
  93. id,
  94. GetErrorMessage(hr).c_str()));
  95. break;
  96. }
  97. }
  98. while (0);
  99. return hr;
  100. }