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.

163 lines
3.4 KiB

  1. // Copyright (c) 2002 Microsoft Corporation
  2. #include <windows.h>
  3. // This registry key allows for the ability to turn off signing and sealing in the
  4. // Active Directory administrative tools
  5. #define REGKEY_ADMINDEBUG TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\AdminDebug")
  6. #define REGVALUE_ADSOPENOBJECTFLAGS TEXT("ADsOpenObjectFlags")
  7. // If the following bits are set in the registry key above, the
  8. // Active Directory administrative tools will turn OFF the corresponding
  9. // ADSI feature
  10. #define REGKEY_MASK_SIGNING ((DWORD)0x1)
  11. #define REGKEY_MASK_SEALING ((DWORD)0x2)
  12. inline
  13. HRESULT
  14. ReadAdminDebugRegkey(DWORD* regkeyValue)
  15. {
  16. HRESULT hr = S_OK;
  17. HKEY key = 0;
  18. if (!regkeyValue)
  19. {
  20. hr = E_INVALIDARG;
  21. return hr;
  22. }
  23. // Open the AdminDebug key with rights to query sub values
  24. LONG result =
  25. RegOpenKeyEx(
  26. HKEY_LOCAL_MACHINE,
  27. REGKEY_ADMINDEBUG,
  28. 0,
  29. KEY_QUERY_VALUE,
  30. &key);
  31. if (ERROR_SUCCESS != result)
  32. {
  33. hr = HRESULT_FROM_WIN32(result);
  34. return hr;
  35. }
  36. if (key)
  37. {
  38. DWORD type = 0;
  39. DWORD value = 0;
  40. DWORD size = sizeof(DWORD);
  41. // Read the ADsOpenObjectFlags subkey
  42. result =
  43. RegQueryValueEx(
  44. key,
  45. REGVALUE_ADSOPENOBJECTFLAGS,
  46. 0,
  47. &type,
  48. (BYTE*)&value,
  49. &size);
  50. if (ERROR_SUCCESS == result)
  51. {
  52. // The subkey has to be a DWORD type
  53. if (REG_DWORD == type ||
  54. REG_DWORD_LITTLE_ENDIAN == type ||
  55. REG_DWORD_BIG_ENDIAN == type)
  56. {
  57. // Copy the value into the flags out parameter
  58. *regkeyValue = value;
  59. }
  60. else
  61. {
  62. hr = HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
  63. }
  64. }
  65. else
  66. {
  67. hr = HRESULT_FROM_WIN32(result);
  68. }
  69. }
  70. else
  71. {
  72. hr = E_FAIL;
  73. }
  74. // Close the regkey if it was opened successfully
  75. if (key)
  76. {
  77. RegCloseKey(key);
  78. key = 0;
  79. }
  80. return hr;
  81. }
  82. inline
  83. DWORD
  84. GetADsOpenObjectFlags()
  85. {
  86. DWORD flags = 0;
  87. // Read the registry key
  88. DWORD regkeyValue = 0;
  89. HRESULT hr = ReadAdminDebugRegkey(&regkeyValue);
  90. if (SUCCEEDED(hr))
  91. {
  92. // If the value is present and set apply
  93. // the appropriate ADSI flags for the bits that
  94. // are not present
  95. if (!(regkeyValue & REGKEY_MASK_SIGNING))
  96. {
  97. flags |= ADS_USE_SIGNING;
  98. }
  99. if (!(regkeyValue & REGKEY_MASK_SEALING))
  100. {
  101. flags |= ADS_USE_SEALING;
  102. }
  103. }
  104. else
  105. {
  106. // If the value is not present or not set
  107. // then default to using both signing and sealing
  108. flags = ADS_USE_SIGNING | ADS_USE_SEALING;
  109. }
  110. return flags;
  111. }
  112. inline
  113. HRESULT
  114. AdminToolsOpenObject(
  115. PCWSTR pathName,
  116. PCWSTR userName,
  117. PCWSTR password,
  118. DWORD flags,
  119. REFIID riid,
  120. void** object)
  121. {
  122. static DWORD additionalFlags = GetADsOpenObjectFlags();
  123. flags |= additionalFlags;
  124. return ADsOpenObject(
  125. pathName,
  126. userName,
  127. password,
  128. flags,
  129. riid,
  130. object);
  131. }