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.

198 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. rndreg.cpp
  5. Abstract:
  6. This module contains implementation of registry operations used
  7. in the Rendezvous control.
  8. --*/
  9. #include "stdafx.h"
  10. #include "rndreg.h"
  11. #include "rndils.h"
  12. const WCHAR gsz_RendezvousRoot[] =
  13. L"Software\\Microsoft\\Windows\\CurrentVersion\\Dynamic Directory";
  14. const WCHAR gsz_ConfInstRelRoot[] = L"Conference";
  15. DWORD CRegistry::ms_ErrorCode = ERROR_SUCCESS;
  16. WCHAR CRegistry::ms_ServerName[MAX_REG_WSTR_SIZE];
  17. WCHAR CRegistry::ms_ProtocolId[MAX_REG_WSTR_SIZE];
  18. WCHAR CRegistry::ms_SubType[MAX_REG_WSTR_SIZE];
  19. WCHAR CRegistry::ms_AdvertisingScope[MAX_REG_WSTR_SIZE];
  20. WCHAR CRegistry::ms_IsEncrypted[MAX_REG_WSTR_SIZE];
  21. REG_INFO g_ConfInstInfoArray[] =
  22. {
  23. {MA_PROTOCOL, CRegistry::ms_ProtocolId}
  24. // {MA_ADVERTISING_SCOPE, CRegistry::ms_AdvertisingScope},
  25. // {MA_ISENCRYPTED, CRegistry::ms_IsEncrypted}
  26. };
  27. DWORD g_ContInstInfoArraySize =
  28. (sizeof g_ConfInstInfoArray) / (sizeof REG_INFO);
  29. // re-read the registry entry for server name
  30. BOOL
  31. CRegistry::NotifyServerNameChange(
  32. )
  33. {
  34. // read the server name under the rendezvous key
  35. return ReadRegValue(
  36. m_RendezvousKey,
  37. REG_SERVER_NAME,
  38. CRegistry::ms_ServerName
  39. );
  40. }
  41. BOOL
  42. CRegistry::ReadRegValue(
  43. IN HKEY Key,
  44. IN const WCHAR * pName,
  45. IN WCHAR * pValue
  46. )
  47. {
  48. DWORD ValueType = REG_SZ;
  49. DWORD BufferSize = 0;
  50. // determine the size of the buffer
  51. ms_ErrorCode = RegQueryValueExW(
  52. Key,
  53. pName,
  54. 0,
  55. &ValueType,
  56. NULL,
  57. &BufferSize
  58. );
  59. if ( ERROR_SUCCESS != ms_ErrorCode )
  60. {
  61. return FALSE;
  62. }
  63. // check if the reqd buffer is bigger than the pre-allocated buffer size
  64. if ( (MAX_REG_WSTR_SIZE < BufferSize) )
  65. {
  66. ms_ErrorCode = ERROR_OUTOFMEMORY;
  67. return FALSE;
  68. }
  69. // retrieve the value into the allocated buffer
  70. ms_ErrorCode = RegQueryValueExW(
  71. Key,
  72. pName,
  73. 0,
  74. &ValueType,
  75. (BYTE *)pValue,
  76. &BufferSize
  77. );
  78. return (ERROR_SUCCESS == ms_ErrorCode);
  79. }
  80. BOOL
  81. CRegistry::ReadConfInstValues(
  82. IN HKEY ConfInstKey
  83. )
  84. {
  85. for ( DWORD i = 0; i < g_ContInstInfoArraySize; i ++)
  86. {
  87. if ( !ReadRegValue(
  88. ConfInstKey,
  89. CILSDirectory::RTConferenceAttributeName(
  90. g_ConfInstInfoArray[i].Attribute
  91. ),
  92. g_ConfInstInfoArray[i].wstrValue
  93. ))
  94. {
  95. return FALSE;
  96. }
  97. }
  98. return TRUE;
  99. }
  100. CRegistry::CRegistry(
  101. )
  102. // : m_Event(FALSE, FALSE, NULL, NULL)
  103. {
  104. // open rendezvous key
  105. ms_ErrorCode = RegOpenKeyExW(
  106. HKEY_LOCAL_MACHINE,
  107. gsz_RendezvousRoot,
  108. 0,
  109. KEY_READ,
  110. &m_RendezvousKey
  111. );
  112. if ( ERROR_SUCCESS != ms_ErrorCode )
  113. {
  114. return;
  115. }
  116. // ZoltanS note: The key is closed in the destructor.
  117. #ifdef SEARCH_REGISTRY_FOR_ILS_SERVER_NAME
  118. // read the server info (only wstr values) under the rendezvous key
  119. if ( !ReadRegValue(
  120. m_RendezvousKey,
  121. REG_SERVER_NAME,
  122. CRegistry::ms_ServerName
  123. ))
  124. {
  125. DBGOUT((ERROR, _T("CRegistry::CRegistry : could not read servername from registry")));
  126. }
  127. #endif
  128. // open conference instance key root
  129. HKEY ConfInstKey;
  130. ms_ErrorCode = RegOpenKeyExW(
  131. m_RendezvousKey,
  132. gsz_ConfInstRelRoot,
  133. 0,
  134. KEY_READ,
  135. &ConfInstKey
  136. );
  137. if ( ERROR_SUCCESS != ms_ErrorCode )
  138. {
  139. return;
  140. }
  141. KEY_WRAP ConfInstKeyWrap(ConfInstKey);
  142. if ( !ReadConfInstValues(ConfInstKey) )
  143. {
  144. return;
  145. }
  146. /*
  147. // register for a notification when the values under the rendezvous key change
  148. // are added or deleted. since the server name value exists under the key,
  149. // any change in its value will cause the event handle to be signaled, other changes
  150. // will be harmless (other than deletion of the server name value)
  151. ms_ErrorCode = RegNotifyChangeKeyValue(
  152. m_RendezvousKey, // key to be registered for notification
  153. FALSE, // only the key, no subkeys
  154. REG_NOTIFY_CHANGE_LAST_SET, // only modifications, addition/deletion of values
  155. (HANDLE)m_Event, // handle to be signaled
  156. TRUE // async
  157. );
  158. if ( ERROR_SUCCESS != ms_ErrorCode )
  159. {
  160. return;
  161. }
  162. */
  163. // success
  164. ms_ErrorCode = ERROR_SUCCESS;
  165. return;
  166. }