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.

295 lines
8.0 KiB

  1. // SSRTE.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To merge the proxy/stub code into the object DLL, add the file
  4. // dlldatax.c to the project. Make sure precompiled headers
  5. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  6. // defines for the project.
  7. //
  8. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  9. // need to remove the following define from dlldatax.c
  10. // #define _WIN32_WINNT 0x0400
  11. //
  12. // Further, if you are running MIDL without /Oicf switch, you also
  13. // need to remove the following define from dlldatax.c.
  14. // #define USE_STUBLESS_PROXY
  15. //
  16. // Modify the custom build rule for SSRTE.idl by adding the following
  17. // files to the Outputs.
  18. // SSRTE_p.c
  19. // dlldata.c
  20. // To build a separate proxy/stub DLL,
  21. // run nmake -f SSRTEps.mk in the project directory.
  22. #include "stdafx.h"
  23. #include "resource.h"
  24. #include "SSRTE.h"
  25. #include "dlldatax.h"
  26. #include "SSRTE_i.c"
  27. #include "SSRMemberShip.h"
  28. #include "SsrCore.h"
  29. #include "SSRLog.h"
  30. #include "SCEAgent.h"
  31. #include "global.h"
  32. #ifdef _MERGE_PROXYSTUB
  33. extern "C" HINSTANCE hProxyDll;
  34. #endif
  35. CComModule _Module;
  36. BEGIN_OBJECT_MAP(ObjectMap)
  37. OBJECT_ENTRY(CLSID_SsrCore, CSsrCore)
  38. //OBJECT_ENTRY(CLSID_SsrMembership, CSsrMembership)
  39. OBJECT_ENTRY(CLSID_SsrLog, CSsrLog)
  40. OBJECT_ENTRY(CLSID_SCEAgent, CSCEAgent)
  41. END_OBJECT_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // DLL Entry Point
  44. extern "C"
  45. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  46. {
  47. lpReserved;
  48. #ifdef _MERGE_PROXYSTUB
  49. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  50. return FALSE;
  51. #endif
  52. if (dwReason == DLL_PROCESS_ATTACH)
  53. {
  54. _Module.Init(ObjectMap, hInstance, &LIBID_SSRLib);
  55. DisableThreadLibraryCalls(hInstance);
  56. //
  57. // if we haven't initialize ourselves before
  58. //
  59. if (g_dwSsrRootLen == 0)
  60. {
  61. g_wszSsrRoot[0] = L'\0';
  62. //
  63. // ExpandEnvironmentStrings returns the total length of
  64. // expanded buffer, including 0 terminator.
  65. //
  66. g_dwSsrRootLen =::ExpandEnvironmentStrings (
  67. g_pwszSSRRootToExpand,
  68. g_wszSsrRoot,
  69. MAX_PATH + 1
  70. );
  71. if (g_dwSsrRootLen == 0)
  72. {
  73. //
  74. // we have a failure.
  75. //
  76. return FALSE;
  77. }
  78. //
  79. // ExpandEnvironmentStrings includes the 0 terminator in its return value
  80. //
  81. g_dwSsrRootLen -= 1;
  82. //
  83. // create the various directory paths needed throughout out code
  84. //
  85. WCHAR wcPath[MAX_PATH + 2];
  86. wcPath[MAX_PATH + 1] = L'\0';
  87. //
  88. // report file directory
  89. //
  90. _snwprintf(wcPath,
  91. MAX_PATH + 1,
  92. L"%s\\%s",
  93. g_wszSsrRoot,
  94. L"ReportFiles"
  95. );
  96. if (wcslen(wcPath) > MAX_PATH)
  97. {
  98. //
  99. // we path too long, we won't be able to function properly. quit.
  100. //
  101. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  102. return FALSE;
  103. }
  104. g_bstrReportFilesDir = wcPath;
  105. //
  106. // configure file directory
  107. //
  108. _snwprintf(wcPath,
  109. MAX_PATH + 1,
  110. L"%s\\%s",
  111. g_wszSsrRoot,
  112. L"ConfigureFiles"
  113. );
  114. if (wcslen(wcPath) > MAX_PATH)
  115. {
  116. //
  117. // we path too long, we won't be able to function properly. quit.
  118. //
  119. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  120. return FALSE;
  121. }
  122. g_bstrConfigureFilesDir = wcPath;
  123. //
  124. // rollback file directory
  125. //
  126. _snwprintf(wcPath,
  127. MAX_PATH + 1,
  128. L"%s\\%s",
  129. g_wszSsrRoot,
  130. L"RollbackFiles"
  131. );
  132. if (wcslen(wcPath) > MAX_PATH)
  133. {
  134. //
  135. // we path too long, we won't be able to function properly. quit.
  136. //
  137. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  138. return FALSE;
  139. }
  140. g_bstrRollbackFilesDir = wcPath;
  141. //
  142. // Transform file directory
  143. //
  144. _snwprintf(wcPath,
  145. MAX_PATH + 1,
  146. L"%s\\%s",
  147. g_wszSsrRoot,
  148. L"TransformFiles"
  149. );
  150. if (wcslen(wcPath) > MAX_PATH)
  151. {
  152. //
  153. // we path too long, we won't be able to function properly. quit.
  154. //
  155. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  156. return FALSE;
  157. }
  158. g_bstrTransformFilesDir = wcPath;
  159. //
  160. // Member file directory
  161. //
  162. _snwprintf(wcPath,
  163. MAX_PATH + 1,
  164. L"%s\\%s",
  165. g_wszSsrRoot,
  166. L"Members"
  167. );
  168. if (wcslen(wcPath) > MAX_PATH)
  169. {
  170. //
  171. // we path too long, we won't be able to function properly. quit.
  172. //
  173. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  174. return FALSE;
  175. }
  176. g_bstrMemberFilesDir = wcPath;
  177. }
  178. }
  179. else if (dwReason == DLL_PROCESS_DETACH)
  180. _Module.Term();
  181. return TRUE; // ok
  182. }
  183. /////////////////////////////////////////////////////////////////////////////
  184. // Used to determine whether the DLL can be unloaded by OLE
  185. STDAPI DllCanUnloadNow(void)
  186. {
  187. #ifdef _MERGE_PROXYSTUB
  188. if (PrxDllCanUnloadNow() != S_OK)
  189. return S_FALSE;
  190. #endif
  191. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  192. }
  193. /////////////////////////////////////////////////////////////////////////////
  194. // Returns a class factory to create an object of the requested type
  195. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  196. {
  197. #ifdef _MERGE_PROXYSTUB
  198. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  199. return S_OK;
  200. #endif
  201. return _Module.GetClassObject(rclsid, riid, ppv);
  202. }
  203. /////////////////////////////////////////////////////////////////////////////
  204. // DllRegisterServer - Adds entries to the system registry
  205. STDAPI DllRegisterServer(void)
  206. {
  207. #ifdef _MERGE_PROXYSTUB
  208. HRESULT hRes = PrxDllRegisterServer();
  209. if (FAILED(hRes))
  210. return hRes;
  211. #endif
  212. // registers object, typelib and all interfaces in typelib
  213. HRESULT hr = _Module.RegisterServer(TRUE);
  214. if (SUCCEEDED(hr))
  215. {
  216. hr = SsrPDoDCOMSettings(true);
  217. }
  218. return hr;
  219. }
  220. /////////////////////////////////////////////////////////////////////////////
  221. // DllUnregisterServer - Removes entries from the system registry
  222. STDAPI DllUnregisterServer(void)
  223. {
  224. #ifdef _MERGE_PROXYSTUB
  225. PrxDllUnregisterServer();
  226. #endif
  227. HRESULT hr = _Module.UnregisterServer(TRUE);
  228. if (SUCCEEDED(hr))
  229. {
  230. hr = SsrPDoDCOMSettings(false);
  231. }
  232. return hr;
  233. }