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.

365 lines
11 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CluAdmEx.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CCluAdmExApp class and DLL initialization
  10. // routines.
  11. //
  12. // Author:
  13. // David Potter (davidp) June 28, 1996
  14. //
  15. // Revision History:
  16. //
  17. // Notes:
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "resource.h"
  22. #include <initguid.h>
  23. #include <aclui.h> // for ISecurityInformation
  24. #include <CluAdmEx.h>
  25. #include "CluAdmX.h"
  26. #include "ExtObj.h"
  27. #include "RegExt.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. #define IID_DEFINED
  34. #include "ExtObjID_i.c"
  35. CComModule _Module;
  36. #pragma warning(disable : 4701) // local variable may be used without having been initialized
  37. #include <atlimpl.cpp>
  38. #pragma warning(default : 4701)
  39. BEGIN_OBJECT_MAP(ObjectMap)
  40. OBJECT_ENTRY(CLSID_CoCluAdmEx, CExtObject)
  41. END_OBJECT_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // Global Function Prototypes
  44. /////////////////////////////////////////////////////////////////////////////
  45. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppv);
  46. STDAPI DllCanUnloadNow(void);
  47. STDAPI DllRegisterServer(void);
  48. STDAPI DllUnregisterServer(void);
  49. STDAPI DllRegisterCluAdminExtension(IN HCLUSTER hcluster);
  50. STDAPI DllUnregisterCluAdminExtension(IN HCLUSTER hcluster);
  51. /////////////////////////////////////////////////////////////////////////////
  52. // class CCluAdmExApp
  53. /////////////////////////////////////////////////////////////////////////////
  54. class CCluAdmExApp : public CWinApp
  55. {
  56. public:
  57. virtual BOOL InitInstance();
  58. virtual int ExitInstance();
  59. };
  60. CCluAdmExApp theApp;
  61. /////////////////////////////////////////////////////////////////////////////
  62. //++
  63. //
  64. // CCluAdmExApp::InitInstance
  65. //
  66. // Routine Description:
  67. // Initialize this instance of the application.
  68. //
  69. // Arguments:
  70. // None.
  71. //
  72. // Return Value:
  73. // TRUE Application initialized successfully.
  74. // FALSE Error initializing application.
  75. //
  76. //--
  77. /////////////////////////////////////////////////////////////////////////////
  78. BOOL CCluAdmExApp::InitInstance(void)
  79. {
  80. _Module.Init(ObjectMap, m_hInstance);
  81. // Construct the help path.
  82. {
  83. TCHAR szPath[_MAX_PATH];
  84. TCHAR szDrive[_MAX_PATH];
  85. TCHAR szDir[_MAX_DIR];
  86. size_t cchPath;
  87. HRESULT hr;
  88. BOOL fEnable;
  89. VERIFY(::GetSystemWindowsDirectory(szPath, _MAX_PATH));
  90. cchPath = _tcslen(szPath);
  91. if (szPath[cchPath - 1] != _T('\\'))
  92. {
  93. szPath[cchPath++] = _T('\\');
  94. szPath[cchPath] = _T('\0');
  95. } // if: no backslash on the end of the path
  96. hr = StringCchCopy( &szPath[ cchPath ], RTL_NUMBER_OF( szPath ) - cchPath, _T("Help\\") );
  97. ASSERT( SUCCEEDED( hr ) );
  98. _tsplitpath(szPath, szDrive, szDir, NULL, NULL);
  99. _tmakepath(szPath, szDrive, szDir, _T("cluadmin"), _T(".hlp"));
  100. free((void *) m_pszHelpFilePath);
  101. fEnable = AfxEnableMemoryTracking(FALSE);
  102. m_pszHelpFilePath = _tcsdup(szPath);
  103. AfxEnableMemoryTracking(fEnable);
  104. } // Construct the help path
  105. return CWinApp::InitInstance();
  106. } //*** CCluAdmExApp::InitInstance()
  107. /////////////////////////////////////////////////////////////////////////////
  108. //++
  109. //
  110. // CCluAdmExApp::ExitInstance
  111. //
  112. // Routine Description:
  113. // Cleans up this instance of the application.
  114. //
  115. // Arguments:
  116. // None.
  117. //
  118. // Return Value:
  119. // Application's exit code. 0 indicates no errors.
  120. //
  121. //--
  122. /////////////////////////////////////////////////////////////////////////////
  123. int CCluAdmExApp::ExitInstance(void)
  124. {
  125. _Module.Term();
  126. return CWinApp::ExitInstance();
  127. } //*** CCluAdmExApp::ExitInstance()
  128. /////////////////////////////////////////////////////////////////////////////
  129. // Used to determine whether the DLL can be unloaded by OLE
  130. STDAPI DllCanUnloadNow(void)
  131. {
  132. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  133. return ( AfxDllCanUnloadNow() && ( _Module.GetLockCount() == 0 ) ) ? S_OK : S_FALSE;
  134. }
  135. /////////////////////////////////////////////////////////////////////////////
  136. // Returns a class factory to create an object of the requested type
  137. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  138. {
  139. return _Module.GetClassObject(rclsid, riid, ppv);
  140. }
  141. /////////////////////////////////////////////////////////////////////////////
  142. // DllRegisterServer - Adds entries to the system registry
  143. STDAPI DllRegisterServer(void)
  144. {
  145. // registers object, typelib and all interfaces in typelib
  146. return _Module.RegisterServer(FALSE /*bRegTypeLib*/);
  147. }
  148. /////////////////////////////////////////////////////////////////////////////
  149. // DllUnregisterServer - Adds entries to the system registry
  150. STDAPI DllUnregisterServer(void)
  151. {
  152. _Module.UnregisterServer();
  153. return S_OK;
  154. }
  155. /////////////////////////////////////////////////////////////////////////////
  156. //++
  157. //
  158. // FormatError
  159. //
  160. // Routine Description:
  161. // Format an error.
  162. //
  163. // Arguments:
  164. // rstrError [OUT] String in which to return the error message.
  165. // dwError [IN] Error code to format.
  166. //
  167. // Return Value:
  168. // None.
  169. //
  170. //--
  171. /////////////////////////////////////////////////////////////////////////////
  172. void FormatError(CString & rstrError, DWORD dwError)
  173. {
  174. DWORD _cch;
  175. TCHAR _szError[512];
  176. _cch = FormatMessage(
  177. FORMAT_MESSAGE_FROM_SYSTEM,
  178. NULL,
  179. dwError,
  180. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  181. _szError,
  182. sizeof(_szError) / sizeof(TCHAR),
  183. 0
  184. );
  185. if (_cch == 0)
  186. {
  187. // Format the NT status code from NTDLL since this hasn't been
  188. // integrated into the system yet.
  189. _cch = FormatMessage(
  190. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
  191. ::GetModuleHandle(_T("NTDLL.DLL")),
  192. dwError,
  193. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  194. _szError,
  195. sizeof(_szError) / sizeof(TCHAR),
  196. 0
  197. );
  198. if (_cch == 0)
  199. {
  200. // One last chance: see if ACTIVEDS.DLL can format the status code
  201. HMODULE activeDSHandle = ::LoadLibrary(_T("ACTIVEDS.DLL"));
  202. _cch = FormatMessage(
  203. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
  204. activeDSHandle,
  205. dwError,
  206. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
  207. _szError,
  208. sizeof(_szError) / sizeof(TCHAR),
  209. 0
  210. );
  211. ::FreeLibrary( activeDSHandle );
  212. } // if: error formatting status code from NTDLL
  213. } // if: error formatting status code from system
  214. if (_cch > 0)
  215. {
  216. rstrError = _szError;
  217. } // if: no error
  218. else
  219. {
  220. #ifdef _DEBUG
  221. DWORD _sc = GetLastError();
  222. TRACE(_T("FormatError() - Error 0x%08.8x formatting string for error code 0x%08.8x\n"), _sc, dwError);
  223. #endif
  224. rstrError.Format(_T("Error 0x%08.8x"), dwError);
  225. } // else: error formatting the message
  226. } //*** FormatError()
  227. /////////////////////////////////////////////////////////////////////////////
  228. //++
  229. //
  230. // DllRegisterCluAdminExtension
  231. //
  232. // Routine Description:
  233. // Register the extension with the cluster database.
  234. //
  235. // Arguments:
  236. // hCluster [IN] Handle to the cluster to modify.
  237. //
  238. // Return Value:
  239. // S_OK Extension registered successfully.
  240. // Win32 error code if another failure occurred.
  241. //
  242. //--
  243. /////////////////////////////////////////////////////////////////////////////
  244. STDAPI DllRegisterCluAdminExtension(IN HCLUSTER hCluster)
  245. {
  246. HRESULT hr;
  247. HRESULT hrReturn = S_OK;
  248. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  249. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  250. hrReturn = RegisterCluAdminClusterExtension(
  251. hCluster,
  252. &CLSID_CoCluAdmEx
  253. );
  254. if ( hrReturn == S_OK )
  255. {
  256. while (*pwszResTypes != L'\0')
  257. {
  258. wprintf(L" %ws\n", pwszResTypes);
  259. hr = RegisterCluAdminResourceTypeExtension(
  260. hCluster,
  261. pwszResTypes,
  262. &CLSID_CoCluAdmEx
  263. );
  264. if (hr != S_OK)
  265. {
  266. hrReturn = hr;
  267. }
  268. pwszResTypes += wcslen(pwszResTypes) + 1;
  269. } // while: more resource types
  270. }
  271. return hrReturn;
  272. } //*** DllRegisterCluAdminExtension()
  273. /////////////////////////////////////////////////////////////////////////////
  274. //++
  275. //
  276. // DllUnregisterCluAdminExtension
  277. //
  278. // Routine Description:
  279. // Unregister the extension with the cluster database.
  280. //
  281. // Arguments:
  282. // hCluster [IN] Handle to the cluster to modify.
  283. //
  284. // Return Value:
  285. // S_OK Extension unregistered successfully.
  286. // Win32 error code if another failure occurred.
  287. //
  288. //--
  289. /////////////////////////////////////////////////////////////////////////////
  290. STDAPI DllUnregisterCluAdminExtension(IN HCLUSTER hCluster)
  291. {
  292. HRESULT hr;
  293. HRESULT hrReturn = S_OK;
  294. LPCWSTR pwszResTypes = g_wszResourceTypeNames;
  295. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  296. hrReturn = UnregisterCluAdminClusterExtension(
  297. hCluster,
  298. &CLSID_CoCluAdmEx
  299. );
  300. if ( hrReturn == S_OK )
  301. {
  302. while (*pwszResTypes != L'\0')
  303. {
  304. wprintf(L" %ws\n", pwszResTypes);
  305. hr = UnregisterCluAdminResourceTypeExtension(
  306. hCluster,
  307. pwszResTypes,
  308. &CLSID_CoCluAdmEx
  309. );
  310. if (hr != S_OK)
  311. {
  312. hrReturn = hr;
  313. }
  314. pwszResTypes += wcslen(pwszResTypes) + 1;
  315. } // while: more resource types
  316. }
  317. return hrReturn;
  318. } //*** DllUnregisterCluAdminExtension()