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.

244 lines
6.8 KiB

  1. // icwhelp.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To build a separate proxy/stub DLL,
  4. // run nmake -f icwhelpps.mk in the project directory.
  5. #include "stdafx.h"
  6. #include "initguid.h"
  7. #include "icwhelp.h"
  8. #include "icwhelp_i.c"
  9. #include "RefDial.h"
  10. #include "DialErr.h"
  11. #include "SmStart.h"
  12. #include "ICWCfg.h"
  13. #include "tapiloc.h"
  14. #include "UserInfo.h"
  15. #include "webgate.h"
  16. #include "INSHandler.h"
  17. const TCHAR c_szICWDbgEXE[] = TEXT("ICWDEBUG.EXE");
  18. const TCHAR c_szICWEXE[] = TEXT("ICWCONN1.EXE");
  19. CComModule _Module;
  20. BOOL g_fRasIsReady = FALSE;
  21. BOOL g_bProxy = FALSE;
  22. DWORD g_dwPlatform = 0xFFFFFFFF;
  23. DWORD g_dwBuild = 0xFFFFFFFF;
  24. LPTSTR g_pszAppDir = NULL;
  25. BEGIN_OBJECT_MAP(ObjectMap)
  26. OBJECT_ENTRY(CLSID_RefDial, CRefDial)
  27. OBJECT_ENTRY(CLSID_DialErr, CDialErr)
  28. OBJECT_ENTRY(CLSID_SmartStart, CSmartStart)
  29. OBJECT_ENTRY(CLSID_ICWSystemConfig, CICWSystemConfig)
  30. OBJECT_ENTRY(CLSID_TapiLocationInfo, CTapiLocationInfo)
  31. OBJECT_ENTRY(CLSID_UserInfo, CUserInfo)
  32. OBJECT_ENTRY(CLSID_WebGate, CWebGate)
  33. OBJECT_ENTRY(CLSID_INSHandler, CINSHandler)
  34. END_OBJECT_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // DLL Entry Point
  37. extern "C"
  38. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  39. {
  40. if (dwReason == DLL_PROCESS_ATTACH)
  41. {
  42. TCHAR szPath[MAX_PATH];
  43. BOOL fBail = TRUE;
  44. // Make sure the attaching process is ICWCONN1.EXE. If not, we won't
  45. // load
  46. if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)))
  47. {
  48. NULL_TERM_TCHARS(szPath);
  49. // See of the file name part of the path contains what we expect
  50. if ( (NULL != _tcsstr(_tcsupr(szPath), c_szICWEXE)) || (NULL != _tcsstr(_tcsupr(szPath), c_szICWDbgEXE)))
  51. fBail = FALSE;
  52. }
  53. // Allow a debug override of the check
  54. #ifdef DEBUG
  55. {
  56. // See if we should override the BAIL out for debug
  57. if (fBail)
  58. {
  59. HKEY hkey;
  60. DWORD dwSize = 0;
  61. DWORD dwType = 0;
  62. DWORD dwData = 0;
  63. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,
  64. TEXT("Software\\Microsoft\\ISignup\\Debug"),
  65. &hkey))
  66. {
  67. dwSize = sizeof(dwData);
  68. if (ERROR_SUCCESS == RegQueryValueEx(hkey,
  69. TEXT("AllowICWHELPToRun"),
  70. 0,
  71. &dwType,
  72. (LPBYTE)&dwData,
  73. &dwSize))
  74. {
  75. // Override the fBail if dwData is non-zero
  76. fBail = (0 == dwData);
  77. }
  78. }
  79. if (hkey)
  80. RegCloseKey(hkey);
  81. }
  82. }
  83. #endif
  84. if (fBail)
  85. {
  86. // We are outa here!!!
  87. return(FALSE);
  88. }
  89. _Module.Init(ObjectMap, hInstance);
  90. DisableThreadLibraryCalls(hInstance);
  91. // Get the OS Version
  92. if (0xFFFFFFFF == g_dwPlatform)
  93. {
  94. OSVERSIONINFO osver;
  95. ZeroMemory(&osver,sizeof(osver));
  96. osver.dwOSVersionInfoSize = sizeof(osver);
  97. if (GetVersionEx(&osver))
  98. {
  99. g_dwPlatform = osver.dwPlatformId;
  100. g_dwBuild = osver.dwBuildNumber & 0xFFFF;
  101. }
  102. }
  103. // Get the AppDir
  104. LPTSTR p;
  105. g_pszAppDir = (LPTSTR)GlobalAlloc(GPTR, MAX_PATH * sizeof(TCHAR));
  106. if (g_pszAppDir)
  107. {
  108. if (GetModuleFileName(hInstance, g_pszAppDir, MAX_PATH))
  109. {
  110. p = &g_pszAppDir[lstrlen(g_pszAppDir)-1];
  111. while (*p != '\\' && p >= g_pszAppDir)
  112. p--;
  113. if (*p == '\\') *(p++) = '\0';
  114. }
  115. else
  116. {
  117. return FALSE;
  118. }
  119. }
  120. else
  121. {
  122. return FALSE;
  123. }
  124. }
  125. else if (dwReason == DLL_PROCESS_DETACH)
  126. {
  127. GlobalFree(g_pszAppDir);
  128. _Module.Term();
  129. }
  130. return TRUE; // ok
  131. }
  132. /////////////////////////////////////////////////////////////////////////////
  133. // Used to determine whether the DLL can be unloaded by OLE
  134. STDAPI DllCanUnloadNow(void)
  135. {
  136. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // Returns a class factory to create an object of the requested type
  140. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  141. {
  142. return _Module.GetClassObject(rclsid, riid, ppv);
  143. }
  144. /////////////////////////////////////////////////////////////////////////////
  145. // DllRegisterServer - Adds entries to the system registry
  146. STDAPI DllRegisterServer(void)
  147. {
  148. // registers object, typelib and all interfaces in typelib
  149. return _Module.RegisterServer(TRUE);
  150. }
  151. /////////////////////////////////////////////////////////////////////////////
  152. // DllUnregisterServer - Removes entries from the system registry
  153. STDAPI DllUnregisterServer(void)
  154. {
  155. _Module.UnregisterServer();
  156. return S_OK;
  157. }
  158. #define MAX_STRINGS 5
  159. int iSzTable=0;
  160. TCHAR szStrTable[MAX_STRINGS][512];
  161. /////////////////////////////////////////////////////////////////////////////
  162. // Utility Globals
  163. //+----------------------------------------------------------------------------
  164. // NAME: GetSz
  165. //
  166. // Load strings from resources
  167. //
  168. // Created 1/28/96, Chris Kauffman
  169. //+----------------------------------------------------------------------------
  170. LPTSTR GetSz(WORD wszID)
  171. {
  172. LPTSTR psz = szStrTable[iSzTable];
  173. iSzTable++;
  174. if (iSzTable >= MAX_STRINGS)
  175. iSzTable = 0;
  176. if (!LoadString(_Module.GetModuleInstance(), wszID, psz, 512))
  177. {
  178. TraceMsg(TF_GENERAL, TEXT("ICWHELP:LoadString failed %d\n"), (DWORD) wszID);
  179. *psz = 0;
  180. }
  181. return (psz);
  182. }
  183. #ifdef UNICODE
  184. int iSzTableA=0;
  185. CHAR szStrTableA[MAX_STRINGS][512];
  186. //+----------------------------------------------------------------------------
  187. // NAME: GetSzA
  188. //
  189. // Load ascii strings from resources
  190. //
  191. // Created 3/10/99, Wootaek Seo
  192. //+----------------------------------------------------------------------------
  193. LPSTR GetSzA(WORD wszID)
  194. {
  195. LPSTR psz = szStrTableA[iSzTable];
  196. iSzTableA++;
  197. if (iSzTableA >= MAX_STRINGS)
  198. iSzTableA = 0;
  199. if (!LoadStringA(_Module.GetModuleInstance(), wszID, psz, 512))
  200. {
  201. TraceMsg(TF_GENERAL, TEXT("ICWHELP:LoadStringA failed %d\n"), (DWORD) wszID);
  202. *psz = 0;
  203. }
  204. return (psz);
  205. }
  206. #endif