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.

238 lines
8.9 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: snapin.cpp
  7. //
  8. // Contents: WiF Policy Snapin
  9. //
  10. //
  11. // History: TaroonM
  12. // 10/30/01
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #include "initguid.h"
  17. #include "about.h"
  18. CComModule _Module;
  19. BEGIN_OBJECT_MAP(ObjectMap)
  20. OBJECT_ENTRY(CLSID_Snapin, CComponentDataPrimaryImpl)
  21. OBJECT_ENTRY(CLSID_Extension, CComponentDataExtensionImpl)
  22. OBJECT_ENTRY(CLSID_About, CSnapinAboutImpl)
  23. END_OBJECT_MAP()
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. class CSnapinApp : public CWinApp
  30. {
  31. public:
  32. virtual BOOL InitInstance();
  33. virtual int ExitInstance();
  34. };
  35. CSnapinApp theApp;
  36. BOOL CSnapinApp::InitInstance()
  37. {
  38. _Module.Init(ObjectMap, m_hInstance);
  39. // set the application name:
  40. //First free the string allocated by MFC at CWinApp startup.
  41. //The string is allocated before InitInstance is called.
  42. free((void*)m_pszAppName);
  43. //Change the name of the application file.
  44. //The CWinApp destructor will free the memory.
  45. CString strName;
  46. strName.LoadString (IDS_NAME);
  47. m_pszAppName=_tcsdup(strName);
  48. SHFusionInitializeFromModuleID (m_hInstance, 2);
  49. return CWinApp::InitInstance();
  50. }
  51. int CSnapinApp::ExitInstance()
  52. {
  53. SHFusionUninitialize();
  54. _Module.Term();
  55. DEBUG_VERIFY_INSTANCE_COUNT(CComponentImpl);
  56. DEBUG_VERIFY_INSTANCE_COUNT(CComponentDataImpl);
  57. return CWinApp::ExitInstance();
  58. }
  59. /////////////////////////////////////////////////////////////////////////////
  60. // Used to determine whether the DLL can be unloaded by OLE
  61. STDAPI DllCanUnloadNow(void)
  62. {
  63. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  64. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // Returns a class factory to create an object of the requested type
  68. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  69. {
  70. return _Module.GetClassObject(rclsid, riid, ppv);
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // DllRegisterServer - Adds entries to the system registry
  74. STDAPI DllRegisterServer(void)
  75. {
  76. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  77. // registers object, typelib and all interfaces in typelib
  78. HRESULT hr = _Module.RegisterServer(FALSE);
  79. if (hr == S_OK)
  80. {
  81. // the dll was registered ok, so proceed to do the MMC registry fixups
  82. // open the registry at \\My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\SnapIns
  83. HKEY hkMMC = NULL;
  84. LONG lErr = RegOpenKeyEx (HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\MMC\\SnapIns"), 0, KEY_ALL_ACCESS, &hkMMC);
  85. if (lErr == ERROR_SUCCESS)
  86. {
  87. // create our subkey(s)
  88. HKEY hkSub = NULL;
  89. lErr = RegCreateKey (hkMMC, cszSnapin, &hkSub);
  90. if (lErr == ERROR_SUCCESS)
  91. {
  92. // A couple of simple values into our subkey
  93. // NameString = IP Security Management
  94. // NodeType = {36703241-D16C-11d0-9CE4-0080C7221EBD}
  95. // Version = 1.0
  96. // TODO: resource hardcoded strings
  97. CString strName;
  98. strName.LoadString (IDS_NAME);
  99. lErr = RegSetValueEx (hkSub, _T("NameString"), 0, REG_SZ, (CONST BYTE *)(LPCTSTR)strName, strName.GetLength() * sizeof (TCHAR));
  100. ASSERT (lErr == ERROR_SUCCESS);
  101. TCHAR szModuleFileName[MAX_PATH * 2 + 1];
  102. ZeroMemory(szModuleFileName, sizeof(szModuleFileName));
  103. DWORD dwRet = ::GetModuleFileName(_Module.GetModuleInstance(),
  104. szModuleFileName,
  105. DimensionOf(szModuleFileName)-1);
  106. szModuleFileName[MAX_PATH*2] = L'\0';
  107. if (0 != dwRet)
  108. {
  109. CString strNameIndirect;
  110. strNameIndirect.Format(_T("@%s,-%u"),
  111. szModuleFileName,
  112. IDS_NAME);
  113. lErr = RegSetValueEx(hkSub,
  114. _T("NameStringIndirect"),
  115. 0,
  116. REG_SZ,
  117. (CONST BYTE *)(LPCTSTR)strNameIndirect,
  118. strNameIndirect.GetLength() * sizeof (TCHAR));
  119. ASSERT (lErr == ERROR_SUCCESS);
  120. }
  121. //lErr = RegSetValueEx (hkSub, _T("NodeType"), 0, REG_SZ, (CONST BYTE *)&(_T("{36703241-D16C-11d0-9CE4-0080C7221EBD}")), wcslen (_T("{36703241-D16C-11d0-9CE4-0080C7221EBD}")) * sizeof (TCHAR));
  122. //ASSERT (lErr == ERROR_SUCCESS);
  123. lErr = RegSetValueEx (hkSub, _T("NodeType"), 0, REG_SZ, (CONST BYTE *)&(_T("{36D6CA65-3367-49de-BB22-1907554F6075}")), wcslen (_T("{36D6CA65-3367-49de-BB22-1907554F6075}")) * sizeof (TCHAR));
  124. ASSERT (lErr == ERROR_SUCCESS);
  125. lErr = RegSetValueEx (hkSub, _T("Provider"), 0, REG_SZ, (CONST BYTE *)&(_T("Microsoft Corporation")), wcslen (_T("Microsoft Corporation")) * sizeof (TCHAR));
  126. ASSERT (lErr == ERROR_SUCCESS);
  127. lErr = RegSetValueEx (hkSub, _T("Version"), 0, REG_SZ, (CONST BYTE *)&(_T("1.0")), wcslen (_T("1.01")) * sizeof (TCHAR));
  128. ASSERT (lErr == ERROR_SUCCESS);
  129. lErr = RegSetValueEx (hkSub, _T("About"), 0, REG_SZ, (CONST BYTE *)&(_T("{DD468E14-AF42-4d63-8908-EDAC4A9E67AE}")), wcslen (_T("{DD468E14-AF42-4d63-8908-EDAC4A9E67AE}")) * sizeof (TCHAR));
  130. ASSERT (lErr == ERROR_SUCCESS);
  131. HKEY hkType = NULL;
  132. /*
  133. // create "StandAlone" subkey
  134. lErr = RegCreateKey (hkSub, _T("StandAlone"), &hkType);
  135. ASSERT (lErr == ERROR_SUCCESS);
  136. RegCloseKey( hkType );
  137. */
  138. hkType = NULL;
  139. // create "Extension" subkey
  140. lErr = RegCreateKey (hkSub, _T("Extension"), &hkType);
  141. ASSERT (lErr == ERROR_SUCCESS);
  142. RegCloseKey( hkType );
  143. hkType = NULL;
  144. // close the hkSub
  145. RegCloseKey (hkSub);
  146. }
  147. // close the hkMMC
  148. RegCloseKey (hkMMC);
  149. hkMMC = NULL;
  150. // Register as an extension to the Security Template snap-in
  151. {
  152. #define WIRELESS_POLMGR_NAME _T("Wireless Network Policy Manager Extension")
  153. // lstruuidNodetypeSceTemplate is defined as L"{668A49ED-8888-11d1-AB72-00C04FB6C6FA}" in sceattch.h
  154. // open the registry at \\My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\Node Types
  155. lErr = RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\MMC\\NodeTypes"), 0, KEY_ALL_ACCESS, &hkMMC );
  156. ASSERT( lErr == ERROR_SUCCESS );
  157. if (lErr == ERROR_SUCCESS)
  158. {
  159. HKEY hkNameSpace = NULL;
  160. // Now open the Security Template entry: {668A49ED-8888-11d1-AB72-00C04FB6C6FA}\Extensions\NameSpace
  161. lErr = RegCreateKey( hkMMC, _T("{668A49ED-8888-11d1-AB72-00C04FB6C6FA}\\Extensions\\NameSpace"), &hkNameSpace );
  162. ASSERT( lErr == ERROR_SUCCESS );
  163. if (lErr == ERROR_SUCCESS)
  164. {
  165. // We want to add ourselves as an extension to the Security editor
  166. //lErr = RegSetValueEx( hkNameSpace, _T("{DEA8AFA0-CC85-11d0-9CE2-0080C7221EBD}" ),
  167. lErr = RegSetValueEx( hkNameSpace, cszSnapin,
  168. 0, REG_SZ, (CONST BYTE *)&(WIRELESS_POLMGR_NAME),
  169. wcslen( WIRELESS_POLMGR_NAME ) * sizeof (TCHAR));
  170. ASSERT( lErr == ERROR_SUCCESS );
  171. }
  172. }
  173. }
  174. } else
  175. {
  176. ASSERT (0);
  177. hr = E_UNEXPECTED;
  178. }
  179. }
  180. return hr;
  181. }
  182. /////////////////////////////////////////////////////////////////////////////
  183. // DllUnregisterServer - Removes entries from the system registry
  184. STDAPI DllUnregisterServer(void)
  185. {
  186. _Module.UnregisterServer();
  187. return S_OK;
  188. }