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.

645 lines
15 KiB

  1. /*++
  2. Copyright (c) 1994-2000 Microsoft Corporation
  3. Module Name :
  4. inetmgrapp.cpp
  5. Abstract:
  6. Snapin object
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Sergei Antonov (sergeia)
  10. Project:
  11. Internet Services Manager
  12. Revision History:
  13. --*/
  14. //
  15. // Include Files
  16. //
  17. #include "stdafx.h"
  18. #include "resource.h"
  19. #include "initguid.h"
  20. #include "inetmgr.h"
  21. #include "dlldatax.h"
  22. #include "common.h"
  23. #include "guids.h"
  24. #include "inetmgr_i.c"
  25. #include "inetmgrapp.h"
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char BASED_CODE THIS_FILE[] = __FILE__;
  29. #endif
  30. #define new DEBUG_NEW
  31. #ifdef _DEBUG
  32. //
  33. // Allocation tracker
  34. //
  35. BOOL
  36. TrackAllocHook(
  37. IN size_t nSize,
  38. IN BOOL bObject,
  39. IN LONG lRequestNumber
  40. )
  41. {
  42. //
  43. // Set breakpoint on specific allocation number
  44. // to track memory leak.
  45. //
  46. //TRACEEOLID("allocation # " << lRequestNumber);
  47. return TRUE;
  48. }
  49. #endif // _DEBUG
  50. // From stdafx.cpp
  51. #ifdef _ATL_STATIC_REGISTRY
  52. #include <statreg.h>
  53. #include <statreg.cpp>
  54. #endif
  55. #include <atlimpl.cpp>
  56. #include <atlwin.cpp>
  57. #ifdef _MERGE_PROXYSTUB
  58. extern "C" HINSTANCE hProxyDll;
  59. #endif
  60. const LPCTSTR g_cszCLSID = _T("CLSID");
  61. const LPCTSTR g_cszLS32 = _T("LocalServer32");
  62. const LPCTSTR g_cszIPS32 = _T("InprocServer32");
  63. const LPCTSTR g_cszMMCBasePath = _T("Software\\Microsoft\\MMC");
  64. const LPCTSTR g_cszSnapins = _T("Snapins");
  65. const LPCTSTR g_cszNameString = _T("NameString");
  66. const LPCTSTR g_cszNameStringInd = _T("NameStringIndirect");
  67. const LPCTSTR g_cszProvider = _T("Provider");
  68. const LPCTSTR g_cszVersion = _T("Version");
  69. const LPCTSTR g_cszStandAlone = _T("StandAlone");
  70. const LPCTSTR g_cszNodeTypes = _T("NodeTypes");
  71. const LPCTSTR g_cszAbout = _T("About");
  72. const LPCTSTR g_cszExtensions = _T("Extensions");
  73. const LPCTSTR g_cszNameSpace = _T("NameSpace");
  74. const LPCTSTR g_cszDynamicExt = _T("Dynamic Extensions");
  75. const LPCTSTR g_cszValProvider = _T("Microsoft");
  76. const LPCTSTR g_cszValVersion = _T("6.0");
  77. const LPCTSTR g_cszMyCompMsc = _T("%SystemRoot%\\system32\\compmgmt.msc");
  78. const LPCTSTR g_cszServerAppsLoc = _T("System\\CurrentControlSet\\Control\\Server Applications");
  79. const LPCTSTR g_cszInetMGRBasePath = _T("Software\\Microsoft\\InetMGR");
  80. const LPCTSTR g_cszInetSTPBasePath = _T("Software\\Microsoft\\InetStp");
  81. const LPCTSTR g_cszMinorVersion = _T("MinorVersion");
  82. const LPCTSTR g_cszMajorVersion = _T("MajorVersion");
  83. const LPCTSTR g_cszParameters = _T("Parameters");
  84. const LPCTSTR g_cszHelpPath = _T("HelpLocation");
  85. //const GUID cInternetRootNode = {0xa841b6c3, 0x7577, 0x11d0, { 0xbb, 0x1f, 0x0, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  86. //const GUID cMachineNode = {0xa841b6c4, 0x7577, 0x11d0, { 0xbb, 0x1f, 0x0, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  87. //const GUID cServiceCollectorNode = {0xa841b6c5, 0x7577, 0x11d0, { 0xbb, 0x1f, 0x0, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  88. //const GUID cInstanceCollectorNode = {0xa841b6c6, 0x7577, 0x11d0, { 0xbb, 0x1f, 0x0, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  89. //const GUID cInstanceNode = {0xa841b6c7, 0x7577, 0x11d0, { 0xbb, 0x1f, 0x0, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  90. //const GUID cChildNode = {0xa841b6c8, 0x7577, 0x11d0, { 0xbb, 0x1f, 0x0, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  91. //const GUID cFileNode = {0xa841b6c9, 0x7577, 0x11d0, { 0xbb, 0x1f, 0x0, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  92. #define lstruuidNodetypeServerApps L"{476e6449-aaff-11d0-b944-00c04fd8d5b0}"
  93. CComModule _Module;
  94. BEGIN_OBJECT_MAP(ObjectMap)
  95. OBJECT_ENTRY(CLSID_InetMgr, CInetMgr)
  96. OBJECT_ENTRY(CLSID_InetMgrAbout, CInetMgrAbout)
  97. END_OBJECT_MAP()
  98. //
  99. // Message Map
  100. //
  101. BEGIN_MESSAGE_MAP(CInetmgrApp, CWinApp)
  102. //{{AFX_MSG_MAP(CInetmgrApp)
  103. //}}AFX_MSG_MAP
  104. //
  105. // Global help commands
  106. //
  107. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  108. ON_COMMAND(ID_CONTEXT_HELP, CWinApp::OnContextHelp)
  109. END_MESSAGE_MAP()
  110. //
  111. // Instantiate the app object
  112. //
  113. CInetmgrApp theApp;
  114. CInetmgrApp::CInetmgrApp()
  115. /*++
  116. Routine Description:
  117. Constructor
  118. Arguments:
  119. None
  120. Return Value:
  121. N/A
  122. --*/
  123. : CWinApp()
  124. {
  125. #ifdef _DEBUG
  126. afxMemDF |= checkAlwaysMemDF;
  127. AfxSetAllocHook(TrackAllocHook);
  128. #endif // _DEBUG
  129. }
  130. BOOL
  131. CInetmgrApp::InitInstance()
  132. /*++
  133. Routine Description:
  134. Instance initiation handler
  135. Arguments:
  136. None
  137. Return Value:
  138. TRUE for success, FALSE for failure
  139. --*/
  140. {
  141. #ifdef _MERGE_PROXYSTUB
  142. hProxyDll = m_hInstance;
  143. #endif
  144. ::AfxEnableControlContainer();
  145. //InitErrorFunctionality();
  146. _Module.Init(ObjectMap, m_hInstance);
  147. //
  148. // Save a pointer to the old help file and app name.
  149. //
  150. m_lpOriginalHelpPath = m_pszHelpFilePath;
  151. m_lpOriginalAppName = m_pszAppName;
  152. //
  153. // Build up inetmgr help path, expanding
  154. // the help path if necessary.
  155. //
  156. CString strKey;
  157. strKey.Format(_T("%s\\%s"), g_cszInetMGRBasePath, g_cszParameters);
  158. CRegKey rk;
  159. rk.Create(HKEY_LOCAL_MACHINE, strKey);
  160. DWORD len = MAX_PATH;
  161. rk.QueryValue(m_strInetMgrHelpPath.GetBuffer(len), g_cszHelpPath, &len);
  162. m_strInetMgrHelpPath.ReleaseBuffer(-1);
  163. m_strInetMgrHelpPath += _T("\\inetmgr.hlp");
  164. TRACEEOLID("Initialized help file " << m_strInetMgrHelpPath);
  165. m_pszHelpFilePath = m_strInetMgrHelpPath;
  166. #ifdef _DEBUG
  167. afxMemDF |= checkAlwaysMemDF;
  168. #endif // _DEBUG
  169. InitCommonDll();
  170. VERIFY(m_strInetMgrAppName.LoadString(IDS_APP_NAME));
  171. m_pszAppName = m_strInetMgrAppName;
  172. return CWinApp::InitInstance();
  173. }
  174. int
  175. CInetmgrApp::ExitInstance()
  176. /*++
  177. Routine Description:
  178. Exit instance handler
  179. Arguments:
  180. None
  181. Return Value:
  182. 0 for success
  183. --*/
  184. {
  185. _Module.Term();
  186. //
  187. // Restore original help file path and app name, so
  188. // MFC can safely delete them.
  189. //
  190. ASSERT_PTR(m_lpOriginalHelpPath);
  191. m_pszHelpFilePath = m_lpOriginalHelpPath;
  192. ASSERT_PTR(m_lpOriginalAppName);
  193. m_pszAppName = m_lpOriginalAppName;
  194. return CWinApp::ExitInstance();
  195. }
  196. STDAPI
  197. DllCanUnloadNow()
  198. /*++
  199. Routine Description:
  200. Used to determine whether the DLL can be unloaded by OLE
  201. Arguments:
  202. None
  203. Return Value:
  204. HRESULT
  205. --*/
  206. {
  207. #ifdef _MERGE_PROXYSTUB
  208. if (PrxDllCanUnloadNow() != S_OK)
  209. {
  210. return S_FALSE;
  211. }
  212. #endif
  213. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  214. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  215. }
  216. STDAPI
  217. DllGetClassObject(
  218. IN REFCLSID rclsid,
  219. IN REFIID riid,
  220. IN LPVOID * ppv
  221. )
  222. /*++
  223. Routine Description:
  224. Returns a class factory to create an object of the requested type
  225. Arguments:
  226. REFCLSID rclsid
  227. REFIID riid
  228. LPVOID * ppv
  229. Return Value:
  230. HRESULT
  231. --*/
  232. {
  233. #ifdef _MERGE_PROXYSTUB
  234. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  235. {
  236. return S_OK;
  237. }
  238. #endif
  239. return _Module.GetClassObject(rclsid, riid, ppv);
  240. }
  241. STDAPI
  242. DllRegisterServer()
  243. /*++
  244. Routine Description:
  245. DllRegisterServer - Adds entries to the system registry
  246. Arguments:
  247. None.
  248. Return Value:
  249. HRESULT
  250. --*/
  251. {
  252. #ifdef _MERGE_PROXYSTUB
  253. HRESULT hRes = PrxDllRegisterServer();
  254. if (FAILED(hRes))
  255. {
  256. return hRes;
  257. }
  258. #endif
  259. CError err(_Module.RegisterServer(TRUE));
  260. if (err.Succeeded())
  261. {
  262. CString str, strKey, strExtKey;
  263. try
  264. {
  265. AFX_MANAGE_STATE(::AfxGetStaticModuleState());
  266. //
  267. // Create the primary snapin nodes
  268. //
  269. CString strNameString((LPCTSTR)IDS_ROOT_NODE);
  270. CString strNameStringInd;
  271. TCHAR path[MAX_PATH];
  272. GetModuleFileName(_Module.GetResourceInstance(), path, MAX_PATH - 1);
  273. strNameStringInd.Format(_T("@%s,-%d"), path, IDS_ROOT_NODE);
  274. TRACEEOLID("MUI-lized snapin name: " << strNameStringInd);
  275. CString strProvider(g_cszValProvider);
  276. CString strVersion(g_cszValVersion);
  277. strKey.Format(_T("%s\\%s\\%s"),
  278. g_cszMMCBasePath,
  279. g_cszSnapins,
  280. GUIDToCString(CLSID_InetMgr, str)
  281. );
  282. TRACEEOLID(strKey);
  283. CString strAbout;
  284. GUIDToCString(CLSID_InetMgrAbout, strAbout);
  285. CRegKey rkSnapins, rkStandAlone, rkNodeTypes;
  286. rkSnapins.Create(HKEY_LOCAL_MACHINE, strKey);
  287. if (NULL != (HKEY)rkSnapins)
  288. {
  289. rkSnapins.SetValue(strAbout, g_cszAbout);
  290. rkSnapins.SetValue(strNameString, g_cszNameString);
  291. rkSnapins.SetValue(strNameStringInd, g_cszNameStringInd);
  292. rkSnapins.SetValue(strProvider, g_cszProvider);
  293. rkSnapins.SetValue(strVersion, g_cszVersion);
  294. }
  295. rkStandAlone.Create(rkSnapins, g_cszStandAlone);
  296. rkNodeTypes.Create(rkSnapins, g_cszNodeTypes);
  297. //
  298. // Create the nodetype GUIDS
  299. //
  300. CRegKey rkN1, rkN2, rkN3, rkN4, rkN5, rkN6, rkN7, rkN8;
  301. rkN1.Create(rkNodeTypes, GUIDToCString(cInternetRootNode, str));
  302. rkN2.Create(rkNodeTypes, GUIDToCString(cMachineNode, str));
  303. rkN3.Create(rkNodeTypes, GUIDToCString(cInstanceNode, str));
  304. rkN4.Create(rkNodeTypes, GUIDToCString(cChildNode, str));
  305. rkN5.Create(rkNodeTypes, GUIDToCString(cFileNode, str));
  306. rkN6.Create(rkNodeTypes, GUIDToCString(cServiceCollectorNode, str));
  307. rkN7.Create(rkNodeTypes, GUIDToCString(cAppPoolsNode, str));
  308. rkN8.Create(rkNodeTypes, GUIDToCString(cAppPoolNode, str));
  309. {
  310. //
  311. // Register as a dynamic extension to computer management
  312. //
  313. strExtKey.Format(
  314. _T("%s\\%s\\%s\\%s"),
  315. g_cszMMCBasePath,
  316. g_cszNodeTypes,
  317. lstruuidNodetypeServerApps,
  318. g_cszDynamicExt
  319. );
  320. TRACEEOLID(strExtKey);
  321. CRegKey rkMMCNodeTypes;
  322. rkMMCNodeTypes.Create(HKEY_LOCAL_MACHINE, strExtKey);
  323. if (NULL != (HKEY)rkMMCNodeTypes)
  324. {
  325. rkMMCNodeTypes.SetValue(
  326. strNameString,
  327. GUIDToCString(CLSID_InetMgr, str)
  328. );
  329. }
  330. }
  331. {
  332. //
  333. // Register as a namespace extension to computer management
  334. //
  335. strExtKey.Format(
  336. _T("%s\\%s\\%s\\%s\\%s"),
  337. g_cszMMCBasePath,
  338. g_cszNodeTypes,
  339. lstruuidNodetypeServerApps,
  340. g_cszExtensions,
  341. g_cszNameSpace
  342. );
  343. TRACEEOLID(strExtKey);
  344. CRegKey rkMMCNodeTypes;
  345. rkMMCNodeTypes.Create(HKEY_LOCAL_MACHINE, strExtKey);
  346. if (NULL != (HKEY)rkMMCNodeTypes)
  347. {
  348. rkMMCNodeTypes.SetValue(
  349. strNameString,
  350. GUIDToCString(CLSID_InetMgr, str)
  351. );
  352. }
  353. }
  354. //
  355. // This key indicates that the service in question is available
  356. // on the local machine
  357. //
  358. CRegKey rkCompMgmt;
  359. rkCompMgmt.Create(HKEY_LOCAL_MACHINE, g_cszServerAppsLoc);
  360. if (NULL != (HKEY)rkCompMgmt)
  361. {
  362. rkCompMgmt.SetValue(strNameString, GUIDToCString(CLSID_InetMgr, str));
  363. }
  364. }
  365. catch(CMemoryException * e)
  366. {
  367. e->Delete();
  368. err = ERROR_NOT_ENOUGH_MEMORY;
  369. }
  370. catch(COleException * e)
  371. {
  372. e->Delete();
  373. err = SELFREG_E_CLASS;
  374. }
  375. }
  376. return err;
  377. }
  378. STDAPI
  379. DllUnregisterServer()
  380. /*++
  381. Routine Description:
  382. DllUnregisterServer - Removes entries from the system registry
  383. Arguments:
  384. None.
  385. Return Value:
  386. HRESULT
  387. --*/
  388. {
  389. #ifdef _MERGE_PROXYSTUB
  390. PrxDllUnregisterServer();
  391. #endif
  392. CError err;
  393. try
  394. {
  395. CString strKey(g_cszMMCBasePath);
  396. strKey += _T("\\");
  397. strKey += g_cszSnapins;
  398. TRACEEOLID(strKey);
  399. CString str, strExtKey;
  400. CRegKey rkBase;
  401. rkBase.Create(HKEY_LOCAL_MACHINE, strKey);
  402. ASSERT(NULL != (HKEY)rkBase);
  403. if (NULL != (HKEY)rkBase)
  404. {
  405. CRegKey rkCLSID;
  406. rkCLSID.Create(rkBase, GUIDToCString(CLSID_InetMgr, str));
  407. ASSERT(NULL != (HKEY)rkCLSID);
  408. if (NULL != (HKEY)rkCLSID)
  409. {
  410. ::RegDeleteKey(rkCLSID, g_cszStandAlone);
  411. {
  412. CRegKey rkNodeTypes;
  413. rkNodeTypes.Create(rkCLSID, g_cszNodeTypes);
  414. ASSERT(NULL != (HKEY)rkNodeTypes);
  415. if (NULL != (HKEY)rkNodeTypes)
  416. {
  417. ::RegDeleteKey(rkNodeTypes, GUIDToCString(cInternetRootNode, str));
  418. ::RegDeleteKey(rkNodeTypes, GUIDToCString(cMachineNode, str));
  419. ::RegDeleteKey(rkNodeTypes, GUIDToCString(cInstanceNode, str));
  420. ::RegDeleteKey(rkNodeTypes, GUIDToCString(cChildNode, str));
  421. ::RegDeleteKey(rkNodeTypes, GUIDToCString(cFileNode, str));
  422. ::RegDeleteKey(rkNodeTypes, GUIDToCString(cServiceCollectorNode, str));
  423. ::RegDeleteKey(rkNodeTypes, GUIDToCString(cAppPoolsNode, str));
  424. ::RegDeleteKey(rkNodeTypes, GUIDToCString(cAppPoolNode, str));
  425. }
  426. }
  427. ::RegDeleteKey(rkCLSID, g_cszNodeTypes);
  428. }
  429. ::RegDeleteKey(rkBase, GUIDToCString(CLSID_InetMgr, str));
  430. }
  431. {
  432. //
  433. // Delete a dynamic extension to computer management
  434. //
  435. strExtKey.Format(
  436. _T("%s\\%s\\%s\\%s"),
  437. g_cszMMCBasePath,
  438. g_cszNodeTypes,
  439. lstruuidNodetypeServerApps,
  440. g_cszDynamicExt
  441. );
  442. CRegKey rkMMCNodeTypes;
  443. rkMMCNodeTypes.Create(HKEY_LOCAL_MACHINE, strExtKey);
  444. if (NULL != (HKEY)rkMMCNodeTypes)
  445. {
  446. ::RegDeleteValue(rkMMCNodeTypes, GUIDToCString(CLSID_InetMgr, str));
  447. }
  448. }
  449. {
  450. //
  451. // Delete the namespace extension to computer management
  452. //
  453. strExtKey.Format(
  454. _T("%s\\%s\\%s\\%s\\%s"),
  455. g_cszMMCBasePath,
  456. g_cszNodeTypes,
  457. lstruuidNodetypeServerApps,
  458. g_cszExtensions,
  459. g_cszNameSpace
  460. );
  461. CRegKey rkMMCNodeTypes;
  462. rkMMCNodeTypes.Create(HKEY_LOCAL_MACHINE, strExtKey);
  463. ::RegDeleteValue(rkMMCNodeTypes, GUIDToCString(CLSID_InetMgr, str));
  464. }
  465. //
  466. // And the service itself no longer available on the local
  467. // computer
  468. //
  469. CRegKey rkCompMgmt;
  470. rkCompMgmt.Create(HKEY_LOCAL_MACHINE, g_cszServerAppsLoc);
  471. ::RegDeleteValue(rkCompMgmt, GUIDToCString(CLSID_InetMgr, str));
  472. }
  473. catch(CException * e)
  474. {
  475. err.GetLastWinError();
  476. e->Delete();
  477. }
  478. if (err.Failed())
  479. {
  480. return err.Failed();
  481. }
  482. return _Module.UnregisterServer();
  483. }
  484. HRESULT CInetMgrAbout::GetSnapinVersion(LPOLESTR * lpVersion)
  485. {
  486. CRegKey rk;
  487. rk.Create(HKEY_LOCAL_MACHINE, g_cszInetSTPBasePath);
  488. DWORD minor, major;
  489. if ( ERROR_SUCCESS == rk.QueryValue(minor, g_cszMinorVersion)
  490. && ERROR_SUCCESS == rk.QueryValue(major, g_cszMajorVersion)
  491. )
  492. {
  493. CString buf;
  494. buf.Format(_T("%d.%d"), major, minor);
  495. *lpVersion = (LPOLESTR)::CoTaskMemAlloc((buf.GetLength() + 1) * sizeof(OLECHAR));
  496. if (*lpVersion == NULL)
  497. {
  498. return E_OUTOFMEMORY;
  499. }
  500. ::ocscpy(*lpVersion, T2OLE((LPTSTR)(LPCTSTR)buf));
  501. return S_OK;
  502. }
  503. return E_FAIL;
  504. }