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.

302 lines
7.6 KiB

  1. // tsmmc.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To build a separate proxy/stub DLL,
  4. // run nmake -f tsmmcps.mk in the project directory.
  5. #include "stdafx.h"
  6. #include "resource.h"
  7. #include <initguid.h>
  8. #include "tsmmc.h"
  9. #include "tsmmc_i.c"
  10. #include "compdata.h"
  11. LONG RecursiveDeleteKey( HKEY hKeyParent , LPTSTR lpszKeyChild );
  12. TCHAR tchSnapKey[] = TEXT( "Software\\Microsoft\\MMC\\Snapins\\" );
  13. TCHAR tchNameString[] = TEXT( "NameString" );
  14. //
  15. // MUI compatible name string
  16. //
  17. TCHAR tchNameStringIndirect[] = TEXT( "NameStringIndirect" );
  18. TCHAR tchAbout[] = TEXT( "About" );
  19. TCHAR tchNodeType[] = TEXT( "NodeTypes" );
  20. TCHAR tchStandAlone[] = TEXT( "StandAlone" );
  21. extern const GUID GUID_ResultNode = { /* 84e0518f-97a8-4caf-96fb-e9a956b10df8 */
  22. 0x84e0518f,
  23. 0x97a8,
  24. 0x4caf,
  25. {0x96, 0xfb, 0xe9, 0xa9, 0x56, 0xb1, 0x0d, 0xf8}
  26. };
  27. CComModule _Module;
  28. BEGIN_OBJECT_MAP(ObjectMap)
  29. OBJECT_ENTRY(CLSID_Compdata, CCompdata)
  30. END_OBJECT_MAP()
  31. /////////////////////////////////////////////////////////////////////////////
  32. // DLL Entry Point
  33. extern "C"
  34. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  35. {
  36. if (dwReason == DLL_PROCESS_ATTACH)
  37. {
  38. //_Module.Init(ObjectMap, hInstance, &LIBID_TSMMCLib);
  39. _Module.Init(ObjectMap, hInstance);
  40. DisableThreadLibraryCalls(hInstance);
  41. }
  42. else if (dwReason == DLL_PROCESS_DETACH)
  43. _Module.Term();
  44. return TRUE; // ok
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Used to determine whether the DLL can be unloaded by OLE
  48. STDAPI DllCanUnloadNow(void)
  49. {
  50. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. // Returns a class factory to create an object of the requested type
  54. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  55. {
  56. return _Module.GetClassObject(rclsid, riid, ppv);
  57. }
  58. /////////////////////////////////////////////////////////////////////////////
  59. // DllRegisterServer - Adds entries to the system registry
  60. STDAPI DllRegisterServer(void)
  61. {
  62. HKEY hKeyRoot , hKey;
  63. INT nLen;
  64. TCHAR tchGUID[ 40 ];
  65. TCHAR tchKey[ MAX_PATH ];//TEXT( "Software\\Microsoft\\MMC\\Snapins\\" );
  66. lstrcpy( tchKey , tchSnapKey );
  67. StringFromGUID2( CLSID_Compdata,tchGUID,sizeof( tchGUID ) /sizeof(TCHAR) );
  68. lstrcat( tchKey , tchGUID );
  69. if( RegCreateKey( HKEY_LOCAL_MACHINE,tchKey,&hKeyRoot ) != ERROR_SUCCESS )
  70. {
  71. return GetLastError( );
  72. }
  73. //
  74. // Use a MUI happy name string
  75. // Format is '@pathtomodule,-RESID' where RESID is the resource id of our string
  76. TCHAR tchBuf[ 512 ];
  77. TCHAR szModPath[MAX_PATH];
  78. if (GetModuleFileName( _Module.GetResourceInstance( ),
  79. szModPath,
  80. MAX_PATH ))
  81. {
  82. // Ensure NULL termination.
  83. szModPath[MAX_PATH - 1] = NULL;
  84. _stprintf( tchBuf, _T("@%s,-%d"),
  85. szModPath, IDS_SNAPIN_REG_TSMMC_NAME );
  86. nLen = _tcslen(tchBuf) + 1;
  87. RegSetValueEx( hKeyRoot,
  88. tchNameStringIndirect,
  89. NULL, REG_SZ,
  90. (PBYTE)&tchBuf[0],
  91. nLen * sizeof(TCHAR));
  92. }
  93. //
  94. // Write legacy non-MUI namestring for fallback in case
  95. // of error loading the MUI string.
  96. //
  97. memset(tchBuf, 0, sizeof(tchBuf));
  98. if (LoadString(_Module.GetResourceInstance( ),
  99. IDS_PROJNAME, tchBuf, SIZEOF_TCHARBUFFER(tchBuf) - 1))
  100. {
  101. nLen = _tcslen(tchBuf);
  102. RegSetValueEx(hKeyRoot, tchNameString, NULL,
  103. REG_SZ, ( PBYTE )&tchBuf[0], nLen * sizeof(TCHAR));
  104. }
  105. //
  106. // Write the 'About' info
  107. //
  108. RegSetValueEx( hKeyRoot,
  109. tchAbout,
  110. NULL,
  111. REG_SZ,
  112. (PBYTE)&tchGUID[0],
  113. sizeof( tchGUID ) );
  114. lstrcpy( tchKey,tchStandAlone );
  115. RegCreateKey( hKeyRoot,tchKey,&hKey );
  116. RegCloseKey( hKey );
  117. lstrcpy( tchKey,tchNodeType );
  118. RegCreateKey( hKeyRoot,tchKey,&hKey );
  119. TCHAR szGUID[ 40 ];
  120. HKEY hDummy;
  121. StringFromGUID2( GUID_ResultNode,szGUID,sizeof(szGUID)/sizeof(TCHAR));
  122. RegCreateKey( hKey,szGUID,&hDummy );
  123. RegCloseKey( hDummy );
  124. RegCloseKey( hKey );
  125. RegCloseKey( hKeyRoot );
  126. // registers object, typelib and all interfaces in typelib
  127. return _Module.RegisterServer(TRUE);
  128. }
  129. /////////////////////////////////////////////////////////////////////////////
  130. // DllUnregisterServer - Removes entries from the system registry
  131. STDAPI DllUnregisterServer(void)
  132. {
  133. HKEY hKey;
  134. TCHAR tchGUID[ 40 ];
  135. TCHAR tchKey[ MAX_PATH ];
  136. lstrcpy( tchKey , tchSnapKey );
  137. if( RegOpenKey( HKEY_LOCAL_MACHINE , tchKey , &hKey ) != ERROR_SUCCESS )
  138. {
  139. return GetLastError( ) ;
  140. }
  141. StringFromGUID2( CLSID_Compdata , tchGUID , sizeof( tchGUID ) / sizeof(TCHAR) );
  142. RecursiveDeleteKey( hKey , tchGUID );
  143. RegCloseKey( hKey );
  144. return _Module.UnregisterServer();
  145. }
  146. //---------------------------------------------------------------------------
  147. // Delete a key and all of its descendents.
  148. //---------------------------------------------------------------------------
  149. LONG RecursiveDeleteKey( HKEY hKeyParent , LPTSTR lpszKeyChild )
  150. {
  151. // Open the child.
  152. HKEY hKeyChild;
  153. LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyChild , 0 , KEY_ALL_ACCESS, &hKeyChild);
  154. if (lRes != ERROR_SUCCESS)
  155. {
  156. return lRes;
  157. }
  158. // Enumerate all of the decendents of this child.
  159. FILETIME time;
  160. TCHAR szBuffer[256];
  161. DWORD dwSize = SIZEOF_TCHARBUFFER( szBuffer );
  162. while( RegEnumKeyEx( hKeyChild , 0 , szBuffer , &dwSize , NULL , NULL , NULL , &time ) == S_OK )
  163. {
  164. // Delete the decendents of this child.
  165. lRes = RecursiveDeleteKey(hKeyChild, szBuffer);
  166. if (lRes != ERROR_SUCCESS)
  167. {
  168. RegCloseKey(hKeyChild);
  169. return lRes;
  170. }
  171. dwSize = SIZEOF_TCHARBUFFER( szBuffer );
  172. }
  173. // Close the child.
  174. RegCloseKey( hKeyChild );
  175. // Delete this child.
  176. return RegDeleteKey( hKeyParent , lpszKeyChild );
  177. }
  178. #ifdef ECP_TIMEBOMB
  179. //
  180. // Return's true if timebomb test passed otherwise puts up warning
  181. // UI and return's FALSE
  182. //
  183. DCBOOL CheckTimeBomb()
  184. {
  185. SYSTEMTIME lclTime;
  186. FILETIME lclFileTime;
  187. GetLocalTime(&lclTime);
  188. DCBOOL bTimeBombOk = TRUE;
  189. //
  190. // Simply check that the local date is less than June 30, 2000
  191. //
  192. if(lclTime.wYear < ECP_TIMEBOMB_YEAR)
  193. {
  194. return TRUE;
  195. }
  196. else if (lclTime.wYear == ECP_TIMEBOMB_YEAR)
  197. {
  198. if(lclTime.wMonth < ECP_TIMEBOMB_MONTH)
  199. {
  200. return TRUE;
  201. }
  202. else if(lclTime.wMonth == ECP_TIMEBOMB_MONTH)
  203. {
  204. if(lclTime.wDay < ECP_TIMEBOMB_DAY)
  205. {
  206. return TRUE;
  207. }
  208. }
  209. }
  210. DCTCHAR timeBombStr[256];
  211. if (LoadString(_Module.GetResourceInstance(),
  212. IDS_TIMEBOMB_EXPIRED,
  213. timeBombStr,
  214. SIZEOF_TCHARBUFFER(timeBombStr)) != 0)
  215. {
  216. MessageBox(NULL, timeBombStr, NULL,
  217. MB_ICONERROR | MB_OK);
  218. }
  219. //
  220. // If we reach this point the timebomb should trigger
  221. // so put up a messagebox and return FALSE
  222. // so the calling code can disable functionality
  223. //
  224. return FALSE;
  225. }
  226. #endif