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.

229 lines
7.5 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cmsafenet.cpp
  4. //
  5. // Module: CMDIAL32.DLL AND CMSTP.EXE
  6. //
  7. // Synopsis: This module contains the functions to allow Connection Manager to
  8. // interact with the SafeNet downlevel L2TP/IPSec client.
  9. //
  10. // Copyright (c) 1997-1999 Microsoft Corporation
  11. //
  12. // Author: quintinb created 09/10/01
  13. //
  14. //+----------------------------------------------------------------------------
  15. //+----------------------------------------------------------------------------
  16. //
  17. // Function IsSafeNetClientAvailable
  18. //
  19. // Synopsis Check to see if the SafeNet L2TP client is installed
  20. //
  21. // Arguments None
  22. //
  23. // Returns TRUE - SafeNet L2TP client has been installed
  24. // FALSE - otherwise
  25. //
  26. // History 9/7/01 quintinb Created
  27. //
  28. //-----------------------------------------------------------------------------
  29. BOOL IsSafeNetClientAvailable(void)
  30. {
  31. BOOL bReturn = FALSE;
  32. //
  33. // More cmstp fixups...
  34. //
  35. #ifndef OS_NT4
  36. CPlatform plat;
  37. if (plat.IsNT4() || plat.IsWin9x())
  38. #else
  39. if (OS_NT4 || OS_W9X)
  40. #endif
  41. {
  42. //
  43. // If this isn't NT5+ then we need to look for the SafeNet
  44. // client. First look for the downlevel l2tp client version regkey.
  45. //
  46. HKEY hKey = NULL;
  47. LONG lResult = RegOpenKeyExU(HKEY_LOCAL_MACHINE,
  48. TEXT("Software\\Microsoft\\Microsoft IPsec VPN"),
  49. 0,
  50. KEY_READ,
  51. &hKey);
  52. if (ERROR_SUCCESS == lResult)
  53. {
  54. //
  55. // Okay, we have the regkey that is good enough to tell us the client
  56. // is available. We should further try linking to the SnPolicy.dll and
  57. // querying for a version of the API that we can live with, but this
  58. // is enough to tell us it is available.
  59. //
  60. RegCloseKey(hKey);
  61. bReturn = TRUE;
  62. }
  63. }
  64. return bReturn;
  65. }
  66. //+----------------------------------------------------------------------------
  67. //
  68. // Function LinkToSafeNet
  69. //
  70. // Synopsis Loads the snpolicy.dll and calls the SnPolicyApiNegotiateVersion
  71. // API to get the SafeNet Config utility APIs.
  72. //
  73. // Arguments SafeNetLinkageStruct* pSnLinkage - struct to hold the SafeNet
  74. // function pointers.
  75. //
  76. // Returns TRUE - if the SafeNet L2TP config APIs were loaded
  77. // FALSE - otherwise
  78. //
  79. // History 9/7/01 quintinb Created
  80. //
  81. //-----------------------------------------------------------------------------
  82. BOOL LinkToSafeNet(SafeNetLinkageStruct* pSnLinkage)
  83. {
  84. if (NULL == pSnLinkage)
  85. {
  86. CMASSERTMSG(FALSE, TEXT("LinkToSafeNet -- NULL pointer passed for the SafeNetLinkageStruct"));
  87. return FALSE;
  88. }
  89. BOOL bReturn = FALSE;
  90. pSnLinkage->hSnPolicy = LoadLibraryA("snpolicy.dll");
  91. if (pSnLinkage->hSnPolicy)
  92. {
  93. pfnSnPolicyApiNegotiateVersionSpec pfnSnPolicyApiNegotiateVersion = (pfnSnPolicyApiNegotiateVersionSpec)GetProcAddress(pSnLinkage->hSnPolicy, "SnPolicyApiNegotiateVersion");
  94. if (pfnSnPolicyApiNegotiateVersion)
  95. {
  96. DWORD dwMajor = POLICY_MAJOR_VERSION;
  97. DWORD dwMinor = POLICY_MINOR_VERSION;
  98. POLICY_FUNCS_V1_0 PolicyFuncs = {0};
  99. if (pfnSnPolicyApiNegotiateVersion(&dwMajor, &dwMinor, &PolicyFuncs))
  100. {
  101. bReturn = (PolicyFuncs.SnPolicySet && PolicyFuncs.SnPolicyGet && PolicyFuncs.SnPolicyReload);
  102. if (bReturn)
  103. {
  104. pSnLinkage->pfnSnPolicySet = PolicyFuncs.SnPolicySet;
  105. pSnLinkage->pfnSnPolicyGet = PolicyFuncs.SnPolicyGet;
  106. pSnLinkage->pfnSnPolicyReload = PolicyFuncs.SnPolicyReload;
  107. }
  108. else
  109. {
  110. FreeLibrary(pSnLinkage->hSnPolicy);
  111. }
  112. }
  113. }
  114. }
  115. else
  116. {
  117. CMTRACE1(TEXT("LinkToSafeNet -- unable to load snpolicy.dll, GLE %d"), GetLastError());
  118. }
  119. return bReturn;
  120. }
  121. //+----------------------------------------------------------------------------
  122. //
  123. // Function UnLinkFromSafeNet
  124. //
  125. // Synopsis Unloads the SafeNet configuration dll and zeros the
  126. // passed in linkage structure.
  127. //
  128. // Arguments SafeNetLinkageStruct* pSnLinkage - struct to holding the SafeNet
  129. // linkage info.
  130. //
  131. // Returns Nothing
  132. //
  133. // History 9/7/01 quintinb Created
  134. //
  135. //-----------------------------------------------------------------------------
  136. void UnLinkFromSafeNet(SafeNetLinkageStruct* pSnLinkage)
  137. {
  138. if (pSnLinkage)
  139. {
  140. if (pSnLinkage->hSnPolicy)
  141. {
  142. FreeLibrary(pSnLinkage->hSnPolicy);
  143. }
  144. ZeroMemory(pSnLinkage, sizeof(SafeNetLinkageStruct));
  145. }
  146. }
  147. //+----------------------------------------------------------------------------
  148. //
  149. // Function GetPathToSafeNetLogFile
  150. //
  151. // Synopsis Returns the full path to the SafeNet log file by looking up the
  152. // SafeNet directory in the registry and appending the fixed log
  153. // file name. Note that this function allocates the memory for the
  154. // string which must be freed by the caller.
  155. //
  156. // Arguments None
  157. //
  158. // Returns Allocated buffer holding the full path to the SafeNet log file.
  159. //
  160. // History 9/7/01 quintinb Created
  161. //
  162. //-----------------------------------------------------------------------------
  163. LPTSTR GetPathToSafeNetLogFile(void)
  164. {
  165. HKEY hKey;
  166. LPTSTR pszLogFilePath = NULL;
  167. DWORD dwSize = 0;
  168. DWORD dwType;
  169. const TCHAR* const c_pszRegKeySafeNetProgramPaths = TEXT("SOFTWARE\\IRE\\SafeNet/Soft-PK\\ProgramPaths");
  170. const TCHAR* const c_pszRegValueCertMgrPath = TEXT("CERTMGRPATH");
  171. const TCHAR* const c_pszSafeNetLogFileName = TEXT("\\isakmp.log");
  172. LONG lResult = RegOpenKeyExU(HKEY_LOCAL_MACHINE, c_pszRegKeySafeNetProgramPaths, 0, NULL, &hKey);
  173. if (ERROR_SUCCESS == lResult)
  174. {
  175. //
  176. // First let's figure out the size of the path buffer
  177. //
  178. lResult = RegQueryValueExU(hKey, c_pszRegValueCertMgrPath, NULL, &dwType, NULL, &dwSize);
  179. if ((ERROR_SUCCESS == lResult) && (dwSize > 0))
  180. {
  181. //
  182. // Okay, we have the size of the path. Now add the size of the file onto it and allocate
  183. // the string buffer.
  184. //
  185. dwSize = dwSize + lstrlenU(c_pszSafeNetLogFileName); // dwSize already includes the NULL char
  186. dwSize *= sizeof(TCHAR);
  187. pszLogFilePath = (LPTSTR)CmMalloc(dwSize);
  188. if (pszLogFilePath)
  189. {
  190. lResult = RegQueryValueExU(hKey, c_pszRegValueCertMgrPath, NULL, &dwType, (BYTE*)pszLogFilePath, &dwSize);
  191. if (ERROR_SUCCESS == lResult)
  192. {
  193. lstrcatU(pszLogFilePath, c_pszSafeNetLogFileName);
  194. }
  195. else
  196. {
  197. CmFree(pszLogFilePath);
  198. pszLogFilePath = NULL;
  199. }
  200. }
  201. }
  202. RegCloseKey(hKey);
  203. }
  204. return pszLogFilePath;
  205. }