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.

111 lines
3.3 KiB

  1. #include <Windows.h>
  2. #include "VerifyConfiguration.h"
  3. #include <crtdbg.h>
  4. #define SECURITY_WIN32
  5. #include <Security.h>
  6. #include "AdsiHelpers.h"
  7. #pragma comment(lib, "secur32.lib")
  8. //-----------------------------------------------------------------------------
  9. // IsCallerDelegatable Function
  10. //
  11. // Synopsis
  12. // If an intra-forest move operation is being performed then verify that the
  13. // calling user's account has not been marked as sensitive and therefore
  14. // cannot be delegated. As the move operation is performed on the domain
  15. // controller which has the RID master role in the source domain it is
  16. // necessary to delegate the user's security context.
  17. //
  18. // Arguments
  19. // bDelegatable - this out parameter is set to true if the account is
  20. // delegatable otherwise it is set to false
  21. //
  22. // Return Value
  23. // The return value is a HRESULT. S_OK is returned if successful.
  24. //-----------------------------------------------------------------------------
  25. HRESULT __stdcall IsCallerDelegatable(bool& bDelegatable)
  26. {
  27. HRESULT hr = S_OK;
  28. bDelegatable = true;
  29. //
  30. // Retrieve distinguished name of caller.
  31. //
  32. ULONG cchCallerDn = 0;
  33. if (GetUserNameEx(NameFullyQualifiedDN, NULL, &cchCallerDn) == FALSE)
  34. {
  35. DWORD dwError = GetLastError();
  36. if ((dwError == ERROR_SUCCESS) || (dwError == ERROR_MORE_DATA))
  37. {
  38. PTSTR pszCallerDn = new _TCHAR[cchCallerDn];
  39. if (pszCallerDn)
  40. {
  41. if (GetUserNameEx(NameFullyQualifiedDN, pszCallerDn, &cchCallerDn))
  42. {
  43. //
  44. // Retrieve user account control attribute for user and check
  45. // whether the 'not delegated' flag is set. If this flag is set
  46. // then the user's account has been marked as sensitive and
  47. // therefore cannot be delegated.
  48. //
  49. try
  50. {
  51. tstring strADsPath = _T("LDAP://");
  52. strADsPath += pszCallerDn;
  53. CDirectoryObject user(strADsPath.c_str());
  54. user.AddAttribute(ATTRIBUTE_USER_ACCOUNT_CONTROL);
  55. user.GetAttributes();
  56. DWORD dwUserAccountControl = (DWORD)(long) user.GetAttributeValue(ATTRIBUTE_USER_ACCOUNT_CONTROL);
  57. if (dwUserAccountControl & ADS_UF_NOT_DELEGATED)
  58. {
  59. bDelegatable = false;
  60. }
  61. }
  62. catch (std::exception& e)
  63. {
  64. hr = E_FAIL;
  65. }
  66. catch (_com_error& ce)
  67. {
  68. hr = ce.Error();
  69. }
  70. }
  71. else
  72. {
  73. dwError = GetLastError();
  74. hr = HRESULT_FROM_WIN32(dwError);
  75. }
  76. delete [] pszCallerDn;
  77. }
  78. else
  79. {
  80. hr = E_OUTOFMEMORY;
  81. }
  82. }
  83. else
  84. {
  85. hr = HRESULT_FROM_WIN32(dwError);
  86. }
  87. }
  88. else
  89. {
  90. _ASSERT(FALSE);
  91. }
  92. return hr;
  93. }