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.

254 lines
9.7 KiB

  1. //
  2. // MODULE: LOCALREGCONNECT.CPP
  3. //
  4. // PURPOSE: read - write to the registry; simulate this in some cases where Online TS uses
  5. // registry, but Local TS doesn't
  6. //
  7. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  8. //
  9. // AUTHOR: Oleg Kalosha, Joe Mabel
  10. //
  11. // ORIGINAL DATE: 8-24-98 in Online TS
  12. //
  13. // NOTES:
  14. // 1. This file is for Local TS only
  15. // 2. If we are moving toward a COM object at some point, we will probably have to establish an
  16. // abstract class in lieu of CAPGTSRegConnector and have Online & Local TS's each derive their
  17. // own version. Meanwhile (1/99), we share a common interface (defined in APGTSRegConnect.h)
  18. // but implement it differently.
  19. // 3. >>> WORK IN PROGRESS !!!! JM 1/19/98
  20. //
  21. // Version Date By Comments
  22. //--------------------------------------------------------------------
  23. // V3.0 08-04-98 OK
  24. // V3.0 09-10-98 JM backslashing; access log file info
  25. // V3.1 01-19-98 JM branch out version exclusively for Local TS
  26. #pragma warning(disable:4786)
  27. #include "stdafx.h"
  28. #include "apgtsregconnect.h"
  29. #include "event.h"
  30. #include "apgtsevt.h"
  31. #include "apgtscls.h"
  32. #include "apgts.h"
  33. #include "apiwraps.h"
  34. #include "CHMFileReader.h"
  35. #define REG_LOCAL_TS_LOC _T("SOFTWARE\\Microsoft")
  36. LPCTSTR CAPGTSRegConnector::RegSoftwareLoc() {return REG_LOCAL_TS_LOC;}
  37. #define REG_LOCAL_TS_PROGRAM _T("TShoot")
  38. LPCTSTR CAPGTSRegConnector::RegThisProgram() {return REG_LOCAL_TS_PROGRAM;}
  39. // subordinate key, child to the above and parent to keys for individual troubleshooter topics.
  40. #define REG_LOCAL_TS_LIST _T("TroubleshooterList")
  41. // where the topic-specific resource path is located ("\TroubleshooterList\Topic_name\Path"):
  42. #define TOPICRESOURCE_STR _T("Path")
  43. // where the topic-specific resource path is located ("\TroubleshooterList\Topic_name\Path"):
  44. #define TOPICFILE_EXTENSION_STR _T("FExtension")
  45. // registry value defaults
  46. // Most relevant values differ from Online TS
  47. // (Looks like old Local TS uses the same default resource path as Online TS, so we'll
  48. // preserve that here >>> till we work out what's right - JM 1/19/99)
  49. #define DEF_FULLRESOURCE _T("c:\\inetsrv\\scripts\\apgts\\resource")
  50. #define DEF_VROOTPATH _T("/scripts/apgts/apgts.dll") // (irrelevant in Local TS)
  51. #define DEF_MAX_THREADS 1 // only 1 pool thread in Local TS
  52. #define DEF_THREADS_PER_PROCESSOR 1 // only 1 pool thread in Local TS
  53. #define DEF_MAX_WORK_QUEUE_ITEMS 1 // only 1 work queue item at a time in Local TS
  54. #define DEF_COOKIE_LIFE_IN_MINS 90 // (irrelevant in Local TS)
  55. #define DEF_RELOAD_DELAY 50 // (irrelevant in Local TS)
  56. #define DEF_DETAILED_EVENT_LOGGING 0
  57. #define DEF_TOPICFILE_EXTENSION _T(".dsc")
  58. #define DEF_SNIFF_AUTOMATIC 1
  59. #define DEF_SNIFF_MANUAL 1
  60. ////////////////////////////////////////////////////////////////////////////////////
  61. // CAPGTSRegConnector::CRegistryInfo
  62. ////////////////////////////////////////////////////////////////////////////////////
  63. void CAPGTSRegConnector::CRegistryInfo::SetToDefault()
  64. {
  65. // Attempt to extract a default resource path based upon the DLL name.
  66. // It was a deliberate decision to utilize the existing global module handle.
  67. strResourcePath= _T("");
  68. if (INVALID_HANDLE_VALUE != ghModule)
  69. {
  70. // Build the default resource path from the module name.
  71. DWORD len;
  72. TCHAR szModulePath[MAXBUF];
  73. CString strModulePath;
  74. len = ::GetModuleFileName( reinterpret_cast<HMODULE>(ghModule), szModulePath, MAXBUF - 1 );
  75. if (len!=0)
  76. {
  77. szModulePath[len] = _T('\0');
  78. strModulePath = szModulePath;
  79. strResourcePath = CAbstractFileReader::GetJustPath(strModulePath);
  80. if (!strResourcePath.IsEmpty())
  81. strResourcePath += _T("\\resource\\");
  82. }
  83. }
  84. if (strResourcePath.IsEmpty())
  85. strResourcePath = DEF_FULLRESOURCE;
  86. strVrootPath = DEF_VROOTPATH;
  87. dwMaxThreads = DEF_MAX_THREADS;
  88. dwThreadsPP = DEF_THREADS_PER_PROCESSOR;
  89. dwMaxWQItems = DEF_MAX_WORK_QUEUE_ITEMS;
  90. dwCookieLife = DEF_COOKIE_LIFE_IN_MINS;
  91. dwReloadDelay = DEF_RELOAD_DELAY;
  92. dwDetailedEventLogging = DEF_DETAILED_EVENT_LOGGING;
  93. dwSniffAutomatic = DEF_SNIFF_AUTOMATIC;
  94. dwSniffManual = DEF_SNIFF_MANUAL;
  95. strLogFilePath = DEF_FULLRESOURCE;
  96. strTopicFileExtension = DEF_TOPICFILE_EXTENSION;
  97. m_bIsRead = false;
  98. }
  99. ////////////////////////////////////////////////////////////////////////////////////
  100. // CAPGTSRegConnector
  101. ////////////////////////////////////////////////////////////////////////////////////
  102. CAPGTSRegConnector::CAPGTSRegConnector(const CString& strTopicName)
  103. : m_strTopicName(strTopicName)
  104. {
  105. Clear();
  106. }
  107. // OUTPUT maskChanged or-ed ERegConnector-based mask of elements that have been
  108. // changed since last read
  109. // OUTPUT maskCreated In Online TS, this is
  110. // or-ed ERegConnector-based mask of elements that were created
  111. // in registry (because they previously didn't exist in registry)
  112. // In Local TS, it always returns 0, because we don't do this.
  113. void CAPGTSRegConnector::ReadUpdateRegistry(int & maskChanged, int & maskCreated)
  114. {
  115. CRegUtil reg;
  116. bool was_created = false;
  117. CString str_tmp;
  118. DWORD dw_tmp = 0;
  119. maskChanged = 0;
  120. maskCreated = 0;
  121. try
  122. {
  123. // [BC - 20010302] - Registry access needs to be restricted to run local TShoot
  124. // for certain user accts, such as WinXP built in guest acct. To minimize change
  125. // access only restricted for local TShoot, not online.
  126. REGSAM samRegistryAccess= KEY_QUERY_VALUE | KEY_NOTIFY;
  127. if(RUNNING_ONLINE_TS())
  128. samRegistryAccess= KEY_QUERY_VALUE | KEY_WRITE;
  129. if (reg.Create(HKEY_LOCAL_MACHINE, RegSoftwareLoc(), &was_created, samRegistryAccess))
  130. {
  131. if(RUNNING_ONLINE_TS())
  132. samRegistryAccess= KEY_READ | KEY_WRITE;
  133. if (reg.Create(RegThisProgram(), &was_created, samRegistryAccess))
  134. {
  135. /////////////////////////////////////////////////////////////////////////////
  136. // Working in ...\TShoot root key
  137. reg.GetNumericValue(SNIFF_AUTOMATIC_STR, m_RegistryInfo.dwSniffAutomatic);
  138. /////////////////////////////////////////////////////////////////////////////
  139. // Working in ...\TShoot root key
  140. reg.GetNumericValue(SNIFF_MANUAL_STR, m_RegistryInfo.dwSniffManual);
  141. /////////////////////////////////////////////////////////////////////////////
  142. // VROOTPATH_STR code suppressed in Local TS
  143. /////////////////////////////////////////////////////////////////////////////
  144. // MAX_THREADS_STR code suppressed in Local TS
  145. /////////////////////////////////////////////////////////////////////////////
  146. // THREADS_PER_PROCESSOR_STR code suppressed in Local TS
  147. /////////////////////////////////////////////////////////////////////////////
  148. // MAX_WORK_QUEUE_ITEMS_STR code suppressed in Local TS
  149. /////////////////////////////////////////////////////////////////////////////
  150. // COOKIE_LIFE_IN_MINS_STR code suppressed in Local TS
  151. /////////////////////////////////////////////////////////////////////////////
  152. // RELOAD_DELAY_STR code suppressed in Local TS
  153. /////////////////////////////////////////////////////////////////////////////
  154. // DETAILED_EVENT_LOGGING_STR code suppressed in Local TS
  155. /////////////////////////////////////////////////////////////////////////////
  156. // Now opening subkeys
  157. bool bFullResourceStrExists = reg.GetStringValue(FULLRESOURCE_STR, str_tmp);
  158. bool bTopicResourceExists = false;
  159. // check in troubleshooter list if topic-related resource path exists
  160. // (it can be CHM file).
  161. if (reg.Create(REG_LOCAL_TS_LIST, &was_created, KEY_READ))
  162. {
  163. if (reg.Create(m_strTopicName, &was_created, KEY_READ))
  164. {
  165. if (reg.GetStringValue(TOPICRESOURCE_STR, str_tmp))
  166. {
  167. if (CCHMFileReader::IsPathToCHMfile(str_tmp))
  168. str_tmp = CCHMFileReader::FormCHMPath(str_tmp);
  169. else
  170. BackslashIt(str_tmp, true);
  171. if (AssignString(m_RegistryInfo.strResourcePath, str_tmp,
  172. EV_GTS_SERVER_REG_CHG_DIR) )
  173. {
  174. maskChanged |= eResourcePath;
  175. }
  176. bTopicResourceExists = true;
  177. }
  178. reg.GetStringValue(TOPICFILE_EXTENSION_STR, m_RegistryInfo.strTopicFileExtension);
  179. }
  180. }
  181. if (bFullResourceStrExists && !bTopicResourceExists)
  182. {
  183. BackslashIt(str_tmp, true);
  184. if (AssignString(m_RegistryInfo.strResourcePath, str_tmp,
  185. EV_GTS_SERVER_REG_CHG_DIR) )
  186. {
  187. maskChanged |= eResourcePath;
  188. }
  189. }
  190. }
  191. else
  192. throw CAPGTSRegConnectorException(__FILE__, __LINE__, reg, eProblemWithKey);
  193. }
  194. else
  195. throw CAPGTSRegConnectorException(__FILE__, __LINE__, reg, eProblemWithKey);
  196. reg.Close();
  197. /* /////////////////////////////////////////////////////////////////////////
  198. ///// >>> We are not using logging so far in the Local TS. Oleg. 02.01.99 //
  199. ////////////////////////////////////////////////////////////////////////////
  200. // >>> The following may be irrelevant: I don't think we should ultimately be keeping
  201. // such a log for Local TS. In any event, I've gotten rid of a bunch of certainly
  202. // irrelevant code to read this from registry & make an entry in the event log. JM 1/19/99
  203. // Set the log file path arbitrarily to the current setting of the resource path
  204. m_RegistryInfo.strLogFilePath = m_RegistryInfo.strResourcePath;
  205. // Set m_RegistryInfo.strLogFilePath to the setting from the registry.
  206. // Note: The code here should remain identical with the code in the catch block
  207. // below (excluding the call to throw of course).
  208. BackslashIt( m_RegistryInfo.strLogFilePath, true);
  209. */
  210. }
  211. catch (CAPGTSRegConnectorException&)
  212. {
  213. // Set m_RegistryInfo.strLogFilePath = m_RegistryInfo.strResourcePath in the
  214. // case where we could not get the log file path from the registry.
  215. BackslashIt( m_RegistryInfo.strLogFilePath, true );
  216. // Rethrow the exception upward to be logged.
  217. throw;
  218. }
  219. }
  220. // RETURN desired number of pool threads. In Local TS, this is always 1!
  221. DWORD CAPGTSRegConnector::GetDesiredThreadCount()
  222. {
  223. return 1;
  224. }