Source code of Windows XP (NT5)
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.

367 lines
7.6 KiB

  1. #include "precomp.h"
  2. DWORD
  3. LoadPersistedTnFilters(
  4. HKEY hParentRegKey
  5. )
  6. {
  7. DWORD dwError = 0;
  8. HKEY hRegKey = NULL;
  9. DWORD dwSize = 0;
  10. WCHAR szTnFilterUniqueID[MAX_PATH];
  11. DWORD dwIndex = 0;
  12. PTUNNEL_FILTER pTnFilter = NULL;
  13. LPWSTR pszServerName = NULL;
  14. HANDLE hTnFilter = NULL;
  15. DWORD dwPersist = 0;
  16. dwPersist |= PERSIST_SPD_OBJECT;
  17. dwError = RegOpenKeyExW(
  18. hParentRegKey,
  19. L"Tunnel Filters",
  20. 0,
  21. KEY_ALL_ACCESS,
  22. &hRegKey
  23. );
  24. BAIL_ON_WIN32_ERROR(dwError);
  25. while (1) {
  26. dwSize = MAX_PATH;
  27. szTnFilterUniqueID[0] = L'\0';
  28. dwError = RegEnumKeyExW(
  29. hRegKey,
  30. dwIndex,
  31. szTnFilterUniqueID,
  32. &dwSize,
  33. NULL,
  34. NULL,
  35. 0,
  36. 0
  37. );
  38. if (dwError == ERROR_NO_MORE_ITEMS) {
  39. dwError = ERROR_SUCCESS;
  40. break;
  41. }
  42. BAIL_ON_WIN32_ERROR(dwError);
  43. dwError = SPDReadTnFilter(
  44. hRegKey,
  45. szTnFilterUniqueID,
  46. &pTnFilter
  47. );
  48. if (dwError) {
  49. dwIndex++;
  50. continue;
  51. }
  52. dwError = AddTunnelFilter(
  53. pszServerName,
  54. dwPersist,
  55. pTnFilter,
  56. &hTnFilter
  57. );
  58. if (pTnFilter) {
  59. FreeTnFilters(
  60. 1,
  61. pTnFilter
  62. );
  63. }
  64. if (hTnFilter) {
  65. CloseTunnelFilterHandle(hTnFilter);
  66. }
  67. dwIndex++;
  68. }
  69. error:
  70. if (hRegKey) {
  71. RegCloseKey(hRegKey);
  72. }
  73. return (dwError);
  74. }
  75. DWORD
  76. SPDReadTnFilter(
  77. HKEY hParentRegKey,
  78. LPWSTR pszTnFilterUniqueID,
  79. PTUNNEL_FILTER * ppTnFilter
  80. )
  81. {
  82. DWORD dwError = 0;
  83. HKEY hRegKey = NULL;
  84. PTUNNEL_FILTER pTnFilter = NULL;
  85. LPWSTR pszFilterID = NULL;
  86. DWORD dwSize = 0;
  87. DWORD dwType = 0;
  88. DWORD dwInterfaceType = 0;
  89. DWORD dwMirrored = 0;
  90. LPBYTE pBuffer = NULL;
  91. DWORD dwBufferSize = 0;
  92. DWORD dwInboundFilterFlag = 0;
  93. DWORD dwOutboundFilterFlag = 0;
  94. LPWSTR pszPolicyID = NULL;
  95. dwError = RegOpenKeyExW(
  96. hParentRegKey,
  97. pszTnFilterUniqueID,
  98. 0,
  99. KEY_ALL_ACCESS,
  100. &hRegKey
  101. );
  102. BAIL_ON_WIN32_ERROR(dwError);
  103. pTnFilter = (PTUNNEL_FILTER) AllocSPDMem(
  104. sizeof(TUNNEL_FILTER)
  105. );
  106. if (!pTnFilter) {
  107. dwError = ERROR_OUTOFMEMORY;
  108. BAIL_ON_WIN32_ERROR(dwError);
  109. }
  110. dwError = RegstoreQueryValue(
  111. hRegKey,
  112. L"FilterID",
  113. REG_SZ,
  114. (LPBYTE *)&pszFilterID,
  115. &dwSize
  116. );
  117. BAIL_ON_WIN32_ERROR(dwError);
  118. wGUIDFromString(
  119. pszFilterID,
  120. &pTnFilter->gFilterID
  121. );
  122. dwError = RegstoreQueryValue(
  123. hRegKey,
  124. L"FilterName",
  125. REG_SZ,
  126. (LPBYTE *)&pTnFilter->pszFilterName,
  127. &dwSize
  128. );
  129. BAIL_ON_WIN32_ERROR(dwError);
  130. dwType = REG_DWORD;
  131. dwSize = sizeof(DWORD);
  132. dwError = RegQueryValueExW(
  133. hRegKey,
  134. L"InterfaceType",
  135. NULL,
  136. &dwType,
  137. (LPBYTE)&dwInterfaceType,
  138. &dwSize
  139. );
  140. BAIL_ON_WIN32_ERROR(dwError);
  141. pTnFilter->InterfaceType = (IF_TYPE) dwInterfaceType;
  142. dwType = REG_DWORD;
  143. dwSize = sizeof(DWORD);
  144. dwError = RegQueryValueExW(
  145. hRegKey,
  146. L"Mirrored",
  147. NULL,
  148. &dwType,
  149. (LPBYTE)&dwMirrored,
  150. &dwSize
  151. );
  152. BAIL_ON_WIN32_ERROR(dwError);
  153. pTnFilter->bCreateMirror = (BOOL) dwMirrored;
  154. dwType = REG_DWORD;
  155. dwSize = sizeof(DWORD);
  156. dwError = RegQueryValueExW(
  157. hRegKey,
  158. L"Flags",
  159. NULL,
  160. &dwType,
  161. (LPBYTE)&pTnFilter->dwFlags,
  162. &dwSize
  163. );
  164. BAIL_ON_WIN32_ERROR(dwError);
  165. dwError = RegstoreQueryValue(
  166. hRegKey,
  167. L"Tunnel Filter Buffer",
  168. REG_BINARY,
  169. (LPBYTE *)&pBuffer,
  170. &dwBufferSize
  171. );
  172. BAIL_ON_WIN32_ERROR(dwError);
  173. dwError = UnMarshallTnFilterBuffer(
  174. pBuffer,
  175. dwBufferSize,
  176. pTnFilter
  177. );
  178. BAIL_ON_WIN32_ERROR(dwError);
  179. dwType = REG_DWORD;
  180. dwSize = sizeof(DWORD);
  181. dwError = RegQueryValueExW(
  182. hRegKey,
  183. L"InboundFilterFlag",
  184. NULL,
  185. &dwType,
  186. (LPBYTE)&dwInboundFilterFlag,
  187. &dwSize
  188. );
  189. BAIL_ON_WIN32_ERROR(dwError);
  190. pTnFilter->InboundFilterFlag = (FILTER_FLAG) dwInboundFilterFlag;
  191. dwType = REG_DWORD;
  192. dwSize = sizeof(DWORD);
  193. dwError = RegQueryValueExW(
  194. hRegKey,
  195. L"OutboundFilterFlag",
  196. NULL,
  197. &dwType,
  198. (LPBYTE)&dwOutboundFilterFlag,
  199. &dwSize
  200. );
  201. BAIL_ON_WIN32_ERROR(dwError);
  202. pTnFilter->OutboundFilterFlag = (FILTER_FLAG) dwOutboundFilterFlag;
  203. pTnFilter->dwDirection = 0;
  204. pTnFilter->dwWeight = 0;
  205. dwError = RegstoreQueryValue(
  206. hRegKey,
  207. L"PolicyID",
  208. REG_SZ,
  209. (LPBYTE *)&pszPolicyID,
  210. &dwSize
  211. );
  212. BAIL_ON_WIN32_ERROR(dwError);
  213. wGUIDFromString(
  214. pszPolicyID,
  215. &pTnFilter->gPolicyID
  216. );
  217. *ppTnFilter = pTnFilter;
  218. cleanup:
  219. if (hRegKey) {
  220. RegCloseKey(hRegKey);
  221. }
  222. if (pszFilterID) {
  223. FreeSPDStr(pszFilterID);
  224. }
  225. if (pBuffer) {
  226. FreeSPDMem(pBuffer);
  227. }
  228. if (pszPolicyID) {
  229. FreeSPDStr(pszPolicyID);
  230. }
  231. return (dwError);
  232. error:
  233. *ppTnFilter = NULL;
  234. if (pTnFilter) {
  235. FreeTnFilters(
  236. 1,
  237. pTnFilter
  238. );
  239. }
  240. goto cleanup;
  241. }
  242. DWORD
  243. UnMarshallTnFilterBuffer(
  244. LPBYTE pBuffer,
  245. DWORD dwBufferSize,
  246. PTUNNEL_FILTER pTnFilter
  247. )
  248. {
  249. DWORD dwError = 0;
  250. LPBYTE pMem = NULL;
  251. pMem = pBuffer;
  252. pMem += sizeof(GUID);
  253. pMem += sizeof(DWORD);
  254. memcpy(
  255. (LPBYTE) &pTnFilter->SrcAddr,
  256. pMem,
  257. sizeof(ADDR)
  258. );
  259. pMem += sizeof(ADDR);
  260. memcpy(
  261. (LPBYTE) &pTnFilter->DesAddr,
  262. pMem,
  263. sizeof(ADDR)
  264. );
  265. pMem += sizeof(ADDR);
  266. memcpy(
  267. (LPBYTE) &pTnFilter->Protocol,
  268. pMem,
  269. sizeof(PROTOCOL)
  270. );
  271. pMem += sizeof(PROTOCOL);
  272. memcpy(
  273. (LPBYTE) &pTnFilter->SrcPort,
  274. pMem,
  275. sizeof(PORT)
  276. );
  277. pMem += sizeof(PORT);
  278. memcpy(
  279. (LPBYTE) &pTnFilter->DesPort,
  280. pMem,
  281. sizeof(PORT)
  282. );
  283. pMem += sizeof(PORT);
  284. memcpy(
  285. (LPBYTE) &pTnFilter->SrcTunnelAddr,
  286. pMem,
  287. sizeof(ADDR)
  288. );
  289. pMem += sizeof(ADDR);
  290. memcpy(
  291. (LPBYTE) &pTnFilter->DesTunnelAddr,
  292. pMem,
  293. sizeof(ADDR)
  294. );
  295. pMem += sizeof(ADDR);
  296. return (dwError);
  297. }