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.

321 lines
6.5 KiB

  1. #include "precomp.h"
  2. DWORD
  3. LoadPersistedMMFilters(
  4. HKEY hParentRegKey
  5. )
  6. {
  7. DWORD dwError = 0;
  8. HKEY hRegKey = NULL;
  9. DWORD dwSize = 0;
  10. WCHAR szMMFilterUniqueID[MAX_PATH];
  11. DWORD dwIndex = 0;
  12. PMM_FILTER pMMFilter = NULL;
  13. LPWSTR pszServerName = NULL;
  14. HANDLE hMMFilter = NULL;
  15. DWORD dwPersist = 0;
  16. dwPersist |= PERSIST_SPD_OBJECT;
  17. dwError = RegOpenKeyExW(
  18. hParentRegKey,
  19. L"MM Filters",
  20. 0,
  21. KEY_ALL_ACCESS,
  22. &hRegKey
  23. );
  24. BAIL_ON_WIN32_ERROR(dwError);
  25. while (1) {
  26. dwSize = MAX_PATH;
  27. szMMFilterUniqueID[0] = L'\0';
  28. dwError = RegEnumKeyExW(
  29. hRegKey,
  30. dwIndex,
  31. szMMFilterUniqueID,
  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 = SPDReadMMFilter(
  44. hRegKey,
  45. szMMFilterUniqueID,
  46. &pMMFilter
  47. );
  48. if (dwError) {
  49. dwIndex++;
  50. continue;
  51. }
  52. dwError = AddMMFilter(
  53. pszServerName,
  54. dwPersist,
  55. pMMFilter,
  56. &hMMFilter
  57. );
  58. if (pMMFilter) {
  59. FreeMMFilters(
  60. 1,
  61. pMMFilter
  62. );
  63. }
  64. if (hMMFilter) {
  65. CloseMMFilterHandle(hMMFilter);
  66. }
  67. dwIndex++;
  68. }
  69. error:
  70. if (hRegKey) {
  71. RegCloseKey(hRegKey);
  72. }
  73. return (dwError);
  74. }
  75. DWORD
  76. SPDReadMMFilter(
  77. HKEY hParentRegKey,
  78. LPWSTR pszMMFilterUniqueID,
  79. PMM_FILTER * ppMMFilter
  80. )
  81. {
  82. DWORD dwError = 0;
  83. HKEY hRegKey = NULL;
  84. PMM_FILTER pMMFilter = 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. LPWSTR pszPolicyID = NULL;
  93. LPWSTR pszAuthID = NULL;
  94. dwError = RegOpenKeyExW(
  95. hParentRegKey,
  96. pszMMFilterUniqueID,
  97. 0,
  98. KEY_ALL_ACCESS,
  99. &hRegKey
  100. );
  101. BAIL_ON_WIN32_ERROR(dwError);
  102. pMMFilter = (PMM_FILTER) AllocSPDMem(
  103. sizeof(MM_FILTER)
  104. );
  105. if (!pMMFilter) {
  106. dwError = ERROR_OUTOFMEMORY;
  107. BAIL_ON_WIN32_ERROR(dwError);
  108. }
  109. dwError = RegstoreQueryValue(
  110. hRegKey,
  111. L"FilterID",
  112. REG_SZ,
  113. (LPBYTE *)&pszFilterID,
  114. &dwSize
  115. );
  116. BAIL_ON_WIN32_ERROR(dwError);
  117. wGUIDFromString(
  118. pszFilterID,
  119. &pMMFilter->gFilterID
  120. );
  121. dwError = RegstoreQueryValue(
  122. hRegKey,
  123. L"FilterName",
  124. REG_SZ,
  125. (LPBYTE *)&pMMFilter->pszFilterName,
  126. &dwSize
  127. );
  128. BAIL_ON_WIN32_ERROR(dwError);
  129. dwType = REG_DWORD;
  130. dwSize = sizeof(DWORD);
  131. dwError = RegQueryValueExW(
  132. hRegKey,
  133. L"InterfaceType",
  134. NULL,
  135. &dwType,
  136. (LPBYTE)&dwInterfaceType,
  137. &dwSize
  138. );
  139. BAIL_ON_WIN32_ERROR(dwError);
  140. pMMFilter->InterfaceType = (IF_TYPE) dwInterfaceType;
  141. dwType = REG_DWORD;
  142. dwSize = sizeof(DWORD);
  143. dwError = RegQueryValueExW(
  144. hRegKey,
  145. L"Mirrored",
  146. NULL,
  147. &dwType,
  148. (LPBYTE)&dwMirrored,
  149. &dwSize
  150. );
  151. BAIL_ON_WIN32_ERROR(dwError);
  152. pMMFilter->bCreateMirror = (BOOL) dwMirrored;
  153. dwType = REG_DWORD;
  154. dwSize = sizeof(DWORD);
  155. dwError = RegQueryValueExW(
  156. hRegKey,
  157. L"Flags",
  158. NULL,
  159. &dwType,
  160. (LPBYTE)&pMMFilter->dwFlags,
  161. &dwSize
  162. );
  163. BAIL_ON_WIN32_ERROR(dwError);
  164. dwError = RegstoreQueryValue(
  165. hRegKey,
  166. L"MM Filter Buffer",
  167. REG_BINARY,
  168. (LPBYTE *)&pBuffer,
  169. &dwBufferSize
  170. );
  171. BAIL_ON_WIN32_ERROR(dwError);
  172. dwError = UnMarshallMMFilterBuffer(
  173. pBuffer,
  174. dwBufferSize,
  175. pMMFilter
  176. );
  177. BAIL_ON_WIN32_ERROR(dwError);
  178. pMMFilter->dwDirection = 0;
  179. pMMFilter->dwWeight = 0;
  180. dwError = RegstoreQueryValue(
  181. hRegKey,
  182. L"PolicyID",
  183. REG_SZ,
  184. (LPBYTE *)&pszPolicyID,
  185. &dwSize
  186. );
  187. BAIL_ON_WIN32_ERROR(dwError);
  188. wGUIDFromString(
  189. pszPolicyID,
  190. &pMMFilter->gPolicyID
  191. );
  192. dwError = RegstoreQueryValue(
  193. hRegKey,
  194. L"AuthID",
  195. REG_SZ,
  196. (LPBYTE *)&pszAuthID,
  197. &dwSize
  198. );
  199. BAIL_ON_WIN32_ERROR(dwError);
  200. wGUIDFromString(
  201. pszAuthID,
  202. &pMMFilter->gMMAuthID
  203. );
  204. *ppMMFilter = pMMFilter;
  205. cleanup:
  206. if (hRegKey) {
  207. RegCloseKey(hRegKey);
  208. }
  209. if (pszFilterID) {
  210. FreeSPDStr(pszFilterID);
  211. }
  212. if (pBuffer) {
  213. FreeSPDMem(pBuffer);
  214. }
  215. if (pszPolicyID) {
  216. FreeSPDStr(pszPolicyID);
  217. }
  218. if (pszAuthID) {
  219. FreeSPDStr(pszAuthID);
  220. }
  221. return (dwError);
  222. error:
  223. *ppMMFilter = NULL;
  224. if (pMMFilter) {
  225. FreeMMFilters(
  226. 1,
  227. pMMFilter
  228. );
  229. }
  230. goto cleanup;
  231. }
  232. DWORD
  233. UnMarshallMMFilterBuffer(
  234. LPBYTE pBuffer,
  235. DWORD dwBufferSize,
  236. PMM_FILTER pMMFilter
  237. )
  238. {
  239. DWORD dwError = 0;
  240. LPBYTE pMem = NULL;
  241. pMem = pBuffer;
  242. pMem += sizeof(GUID);
  243. pMem += sizeof(DWORD);
  244. memcpy(
  245. (LPBYTE) &pMMFilter->SrcAddr,
  246. pMem,
  247. sizeof(ADDR)
  248. );
  249. pMem += sizeof(ADDR);
  250. memcpy(
  251. (LPBYTE) &pMMFilter->DesAddr,
  252. pMem,
  253. sizeof(ADDR)
  254. );
  255. pMem += sizeof(ADDR);
  256. return (dwError);
  257. }