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.

338 lines
6.9 KiB

  1. #include "precomp.h"
  2. DWORD
  3. LoadPersistedMMAuthMethods(
  4. HKEY hParentRegKey
  5. )
  6. {
  7. DWORD dwError = 0;
  8. HKEY hRegKey = NULL;
  9. DWORD dwSize = 0;
  10. WCHAR szMMAuthUniqueID[MAX_PATH];
  11. DWORD dwIndex = 0;
  12. PMM_AUTH_METHODS pMMAuthMethods = NULL;
  13. LPWSTR pszServerName = NULL;
  14. DWORD dwPersist = 0;
  15. dwPersist |= PERSIST_SPD_OBJECT;
  16. dwError = RegOpenKeyExW(
  17. hParentRegKey,
  18. L"MM Auth Methods",
  19. 0,
  20. KEY_ALL_ACCESS,
  21. &hRegKey
  22. );
  23. BAIL_ON_WIN32_ERROR(dwError);
  24. while (1) {
  25. dwSize = MAX_PATH;
  26. szMMAuthUniqueID[0] = L'\0';
  27. dwError = RegEnumKeyExW(
  28. hRegKey,
  29. dwIndex,
  30. szMMAuthUniqueID,
  31. &dwSize,
  32. NULL,
  33. NULL,
  34. 0,
  35. 0
  36. );
  37. if (dwError == ERROR_NO_MORE_ITEMS) {
  38. dwError = ERROR_SUCCESS;
  39. break;
  40. }
  41. BAIL_ON_WIN32_ERROR(dwError);
  42. dwError = SPDReadMMAuthMethods(
  43. hRegKey,
  44. szMMAuthUniqueID,
  45. &pMMAuthMethods
  46. );
  47. if (dwError) {
  48. dwIndex++;
  49. continue;
  50. }
  51. dwError = AddMMAuthMethods(
  52. pszServerName,
  53. dwPersist,
  54. pMMAuthMethods
  55. );
  56. if (pMMAuthMethods) {
  57. FreeMMAuthMethods(
  58. 1,
  59. pMMAuthMethods
  60. );
  61. }
  62. dwIndex++;
  63. }
  64. error:
  65. if (hRegKey) {
  66. RegCloseKey(hRegKey);
  67. }
  68. return (dwError);
  69. }
  70. DWORD
  71. SPDReadMMAuthMethods(
  72. HKEY hParentRegKey,
  73. LPWSTR pszMMAuthUniqueID,
  74. PMM_AUTH_METHODS * ppMMAuthMethods
  75. )
  76. {
  77. DWORD dwError = 0;
  78. HKEY hRegKey = NULL;
  79. PMM_AUTH_METHODS pMMAuthMethods = NULL;
  80. LPWSTR pszAuthID = NULL;
  81. DWORD dwSize = 0;
  82. DWORD dwType = 0;
  83. LPBYTE pBuffer = NULL;
  84. DWORD dwBufferSize = 0;
  85. dwError = RegOpenKeyExW(
  86. hParentRegKey,
  87. pszMMAuthUniqueID,
  88. 0,
  89. KEY_ALL_ACCESS,
  90. &hRegKey
  91. );
  92. BAIL_ON_WIN32_ERROR(dwError);
  93. pMMAuthMethods = (PMM_AUTH_METHODS) AllocSPDMem(
  94. sizeof(MM_AUTH_METHODS)
  95. );
  96. if (!pMMAuthMethods) {
  97. dwError = ERROR_OUTOFMEMORY;
  98. BAIL_ON_WIN32_ERROR(dwError);
  99. }
  100. dwError = RegstoreQueryValue(
  101. hRegKey,
  102. L"AuthID",
  103. REG_SZ,
  104. (LPBYTE *)&pszAuthID,
  105. &dwSize
  106. );
  107. BAIL_ON_WIN32_ERROR(dwError);
  108. wGUIDFromString(
  109. pszAuthID,
  110. &pMMAuthMethods->gMMAuthID
  111. );
  112. dwType = REG_DWORD;
  113. dwSize = sizeof(DWORD);
  114. dwError = RegQueryValueExW(
  115. hRegKey,
  116. L"Flags",
  117. NULL,
  118. &dwType,
  119. (LPBYTE)&pMMAuthMethods->dwFlags,
  120. &dwSize
  121. );
  122. BAIL_ON_WIN32_ERROR(dwError);
  123. dwError = RegstoreQueryValue(
  124. hRegKey,
  125. L"AuthInfoBundle",
  126. REG_BINARY,
  127. (LPBYTE *)&pBuffer,
  128. &dwBufferSize
  129. );
  130. BAIL_ON_WIN32_ERROR(dwError);
  131. dwError = UnMarshallMMAuthInfoBundle(
  132. pBuffer,
  133. dwBufferSize,
  134. &pMMAuthMethods->pAuthenticationInfo,
  135. &pMMAuthMethods->dwNumAuthInfos
  136. );
  137. BAIL_ON_WIN32_ERROR(dwError);
  138. *ppMMAuthMethods = pMMAuthMethods;
  139. cleanup:
  140. if (hRegKey) {
  141. RegCloseKey(hRegKey);
  142. }
  143. if (pszAuthID) {
  144. FreeSPDStr(pszAuthID);
  145. }
  146. if (pBuffer) {
  147. FreeSPDMem(pBuffer);
  148. }
  149. return (dwError);
  150. error:
  151. *ppMMAuthMethods = NULL;
  152. if (pMMAuthMethods) {
  153. FreeMMAuthMethods(
  154. 1,
  155. pMMAuthMethods
  156. );
  157. }
  158. goto cleanup;
  159. }
  160. DWORD
  161. UnMarshallMMAuthInfoBundle(
  162. LPBYTE pBuffer,
  163. DWORD dwBufferSize,
  164. PIPSEC_MM_AUTH_INFO * ppMMAuthInfos,
  165. PDWORD pdwNumAuthInfos
  166. )
  167. {
  168. DWORD dwError = 0;
  169. LPBYTE pMem = NULL;
  170. PIPSEC_MM_AUTH_INFO pMMAuthInfos = NULL;
  171. DWORD dwNumAuthInfos = 0;
  172. PIPSEC_MM_AUTH_INFO pTemp = NULL;
  173. DWORD i = 0;
  174. DWORD dwNumBytesAdvanced = 0;
  175. pMem = pBuffer;
  176. pMem += sizeof(GUID);
  177. pMem += sizeof(DWORD);
  178. memcpy(
  179. (LPBYTE) &dwNumAuthInfos,
  180. pMem,
  181. sizeof(DWORD)
  182. );
  183. pMem += sizeof(DWORD);
  184. pMMAuthInfos = (PIPSEC_MM_AUTH_INFO) AllocSPDMem(
  185. sizeof(IPSEC_MM_AUTH_INFO)*dwNumAuthInfos
  186. );
  187. if (!pMMAuthInfos) {
  188. dwError = ERROR_OUTOFMEMORY;
  189. BAIL_ON_WIN32_ERROR(dwError);
  190. }
  191. pTemp = pMMAuthInfos;
  192. for (i = 0; i < dwNumAuthInfos; i++) {
  193. dwError = UnMarshallMMAuthMethod(
  194. pMem,
  195. pTemp,
  196. &dwNumBytesAdvanced
  197. );
  198. BAIL_ON_WIN32_ERROR(dwError);
  199. pMem += dwNumBytesAdvanced;
  200. pTemp++;
  201. }
  202. *ppMMAuthInfos = pMMAuthInfos;
  203. *pdwNumAuthInfos = dwNumAuthInfos;
  204. return (dwError);
  205. error:
  206. if (pMMAuthInfos) {
  207. FreeIniMMAuthInfos(
  208. i,
  209. pMMAuthInfos
  210. );
  211. }
  212. *ppMMAuthInfos = NULL;
  213. *pdwNumAuthInfos = 0;
  214. return (dwError);
  215. }
  216. DWORD
  217. UnMarshallMMAuthMethod(
  218. LPBYTE pBuffer,
  219. PIPSEC_MM_AUTH_INFO pMMAuthInfo,
  220. PDWORD pdwNumBytesAdvanced
  221. )
  222. {
  223. DWORD dwError = 0;
  224. LPBYTE pMem = NULL;
  225. DWORD dwNumBytesAdvanced = 0;
  226. DWORD dwAuthMethod = 0;
  227. DWORD dwAuthInfoSize = 0;
  228. LPBYTE pAuthInfo = NULL;
  229. pMem = pBuffer;
  230. memcpy(
  231. (LPBYTE) &dwAuthMethod,
  232. pMem,
  233. sizeof(DWORD)
  234. );
  235. pMem += sizeof(DWORD);
  236. dwNumBytesAdvanced += sizeof(DWORD);
  237. memcpy(
  238. (LPBYTE) &dwAuthInfoSize,
  239. pMem,
  240. sizeof(DWORD)
  241. );
  242. pMem += sizeof(DWORD);
  243. dwNumBytesAdvanced += sizeof(DWORD);
  244. if (dwAuthInfoSize) {
  245. pAuthInfo = (LPBYTE) AllocSPDMem(
  246. dwAuthInfoSize
  247. );
  248. if (!pAuthInfo) {
  249. dwError = ERROR_OUTOFMEMORY;
  250. BAIL_ON_WIN32_ERROR(dwError);
  251. }
  252. memcpy(
  253. pAuthInfo,
  254. pMem,
  255. dwAuthInfoSize
  256. );
  257. }
  258. pMem += dwAuthInfoSize;
  259. dwNumBytesAdvanced += dwAuthInfoSize;
  260. pMMAuthInfo->AuthMethod = (MM_AUTH_ENUM) dwAuthMethod;
  261. pMMAuthInfo->dwAuthInfoSize = dwAuthInfoSize;
  262. pMMAuthInfo->pAuthInfo = pAuthInfo;
  263. *pdwNumBytesAdvanced = dwNumBytesAdvanced;
  264. return (dwError);
  265. error:
  266. *pdwNumBytesAdvanced = 0;
  267. return (dwError);
  268. }