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.

336 lines
8.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: registry.cpp
  8. //
  9. // Contents: Microsoft Internet Security Trust Provider
  10. //
  11. // Functions: WintrustGetRegPolicyFlags
  12. // GetRegProvider
  13. // SetRegProvider
  14. // GetRegSecuritySettings
  15. //
  16. // History: 28-May-1997 pberkman created
  17. //
  18. //--------------------------------------------------------------------------
  19. #include "global.hxx"
  20. #include "cryptreg.h"
  21. #define SZIE30SAFTYLEVEL L"Software\\Microsoft\\Internet Explorer\\Security"
  22. #define SZIE30SAFTYLEVELNAME L"Safety Warning Level"
  23. #define STATUS_SIZE 64
  24. BOOL GetRegProvider(GUID *pgActionID, WCHAR *pwszRegKey, WCHAR *pwszRetDLLName, char *pszRetFuncName)
  25. {
  26. HKEY hKey;
  27. WCHAR wsz[REG_MAX_KEY_NAME];
  28. WCHAR wszGuid[REG_MAX_GUID_TEXT];
  29. DWORD dwType;
  30. DWORD dwSize;
  31. if (!(pgActionID) ||
  32. !(pwszRegKey) ||
  33. !(pwszRetDLLName) ||
  34. !(pszRetFuncName))
  35. {
  36. SetLastError(ERROR_INVALID_PARAMETER);
  37. return(FALSE);
  38. }
  39. pwszRetDLLName[0] = NULL;
  40. pszRetFuncName[0] = NULL;
  41. if (!(guid2wstr(pgActionID, &wszGuid[0])))
  42. {
  43. SetLastError(ERROR_INVALID_PARAMETER);
  44. return(FALSE);
  45. }
  46. wcscpy(&wsz[0], pwszRegKey);
  47. wcscat(&wsz[0], L"\\");
  48. wcscat(&wsz[0], &wszGuid[0]);
  49. if (RegOpenKeyExU( HKEY_LOCAL_MACHINE,
  50. &wsz[0],
  51. 0,
  52. KEY_READ,
  53. &hKey) != ERROR_SUCCESS)
  54. {
  55. return(FALSE);
  56. }
  57. dwType = 0;
  58. dwSize = (REG_MAX_KEY_NAME) * sizeof(WCHAR);
  59. if (RegQueryValueExU( hKey,
  60. REG_DLL_NAME,
  61. NULL,
  62. &dwType,
  63. (BYTE *)pwszRetDLLName,
  64. &dwSize) != ERROR_SUCCESS)
  65. {
  66. pwszRetDLLName[0] = NULL;
  67. RegCloseKey(hKey);
  68. return(FALSE);
  69. }
  70. dwType = 0;
  71. dwSize = (REG_MAX_FUNC_NAME) * sizeof(WCHAR);
  72. if (RegQueryValueExU( hKey,
  73. REG_FUNC_NAME,
  74. NULL,
  75. &dwType,
  76. (BYTE *)&wsz[0],
  77. &dwSize) != ERROR_SUCCESS)
  78. {
  79. pszRetFuncName[0] = NULL;
  80. RegCloseKey(hKey);
  81. return(FALSE);
  82. }
  83. if (WideCharToMultiByte(0, 0, &wsz[0], wcslen(&wsz[0]) + 1,
  84. pszRetFuncName, REG_MAX_FUNC_NAME, NULL, NULL) < 1)
  85. {
  86. RegCloseKey(hKey);
  87. return(FALSE);
  88. }
  89. RegCloseKey(hKey);
  90. return(TRUE);
  91. }
  92. BOOL SetRegProvider(GUID *pgActionID, WCHAR *pwszRegKey, WCHAR *pwszDLLName, WCHAR *pwszFuncName)
  93. {
  94. HRESULT hr;
  95. DWORD dwDisposition;
  96. HKEY hKey;
  97. WCHAR wsz[REG_MAX_KEY_NAME];
  98. WCHAR wszGuid[REG_MAX_GUID_TEXT];
  99. if (!(pgActionID) ||
  100. !(pwszRegKey) ||
  101. !(pwszDLLName) ||
  102. !(pwszFuncName))
  103. {
  104. SetLastError(ERROR_INVALID_PARAMETER);
  105. return(FALSE);
  106. }
  107. if (!(guid2wstr(pgActionID, &wszGuid[0])))
  108. {
  109. SetLastError(ERROR_INVALID_PARAMETER);
  110. return(FALSE);
  111. }
  112. wcscpy(&wsz[0], pwszRegKey);
  113. wcscat(&wsz[0], L"\\");
  114. wcscat(&wsz[0], &wszGuid[0]);
  115. hr = RegCreateKeyExU(HKEY_LOCAL_MACHINE,
  116. &wsz[0],
  117. 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  118. &hKey, &dwDisposition);
  119. if (hr != ERROR_SUCCESS)
  120. {
  121. SetLastError(hr);
  122. return(FALSE);
  123. }
  124. hr = RegSetValueExU(hKey, REG_DLL_NAME,
  125. 0, REG_SZ,
  126. (BYTE *)pwszDLLName,
  127. (wcslen(pwszDLLName) + 1) * sizeof(WCHAR));
  128. hr |= RegSetValueExU(hKey, REG_FUNC_NAME,
  129. 0, REG_SZ,
  130. (BYTE *)pwszFuncName,
  131. (wcslen(pwszFuncName) + 1) * sizeof(WCHAR));
  132. RegCloseKey(hKey);
  133. if (hr != ERROR_SUCCESS)
  134. {
  135. return(FALSE);
  136. }
  137. return(TRUE);
  138. }
  139. BOOL RemoveRegProvider(GUID *pgActionID, WCHAR *pwszRegKey)
  140. {
  141. WCHAR wsz[REG_MAX_KEY_NAME];
  142. WCHAR wszGuid[REG_MAX_GUID_TEXT];
  143. if (!(pgActionID) ||
  144. !(pwszRegKey))
  145. {
  146. SetLastError(ERROR_INVALID_PARAMETER);
  147. return(FALSE);
  148. }
  149. if (!(guid2wstr(pgActionID, &wszGuid[0])))
  150. {
  151. SetLastError(ERROR_INVALID_PARAMETER);
  152. return(FALSE);
  153. }
  154. wcscpy(&wsz[0], pwszRegKey);
  155. wcscat(&wsz[0], L"\\");
  156. wcscat(&wsz[0], &wszGuid[0]);
  157. if (RegDeleteKeyU(HKEY_LOCAL_MACHINE, &wsz[0]) != ERROR_SUCCESS)
  158. {
  159. return(FALSE);
  160. }
  161. return(TRUE);
  162. }
  163. void GetRegSecuritySettings(DWORD *pdwState)
  164. {
  165. HKEY hKeyRoot;
  166. WCHAR wszBuffer[STATUS_SIZE];
  167. DWORD dwType;
  168. DWORD dwSize;
  169. dwType = 0;
  170. dwSize = STATUS_SIZE * sizeof(WCHAR);
  171. *pdwState = 2; // Default to high
  172. if (RegOpenHKCUKeyExU( HKEY_CURRENT_USER,
  173. SZIE30SAFTYLEVEL,
  174. 0, // dwReserved
  175. KEY_READ,
  176. &hKeyRoot) != ERROR_SUCCESS)
  177. {
  178. return;
  179. }
  180. if (RegQueryValueExU( hKeyRoot,
  181. SZIE30SAFTYLEVELNAME,
  182. NULL,
  183. &dwType,
  184. (BYTE *)&wszBuffer[0],
  185. &dwSize) != ERROR_SUCCESS)
  186. {
  187. RegCloseKey(hKeyRoot);
  188. return;
  189. }
  190. RegCloseKey(hKeyRoot);
  191. if (dwType == REG_SZ)
  192. {
  193. if (wcscmp(&wszBuffer[0], L"FailInform") == 0)
  194. {
  195. *pdwState = 2;
  196. }
  197. else if (wcscmp(&wszBuffer[0], L"Query") == 0)
  198. {
  199. *pdwState = 1;
  200. }
  201. else if (wcscmp(&wszBuffer[0], L"SucceedSilent") == 0)
  202. {
  203. *pdwState = 0;
  204. }
  205. }
  206. }
  207. void WINAPI WintrustGetRegPolicyFlags(DWORD *pdwState)
  208. {
  209. HKEY hKey;
  210. DWORD dwDisposition;
  211. DWORD lErr;
  212. DWORD dwType;
  213. DWORD cbData;
  214. *pdwState = 0;
  215. cbData = sizeof(DWORD);
  216. // Open the registry and get to the state var
  217. if (RegCreateHKCUKeyExU(HKEY_CURRENT_USER,
  218. REGPATH_WINTRUST_POLICY_FLAGS,
  219. 0,
  220. NULL,
  221. REG_OPTION_NON_VOLATILE,
  222. KEY_READ,
  223. NULL,
  224. &hKey,
  225. &dwDisposition) != ERROR_SUCCESS)
  226. {
  227. return;
  228. }
  229. // read the state var
  230. if (RegQueryValueExU( hKey,
  231. REGNAME_WINTRUST_POLICY_FLAGS,
  232. NULL,
  233. &dwType,
  234. (BYTE *)pdwState,
  235. &cbData) != ERROR_SUCCESS)
  236. {
  237. *pdwState = 0;
  238. RegCloseKey(hKey);
  239. return;
  240. }
  241. RegCloseKey(hKey);
  242. if ((dwType != REG_DWORD) &&
  243. (dwType != REG_BINARY))
  244. {
  245. *pdwState = 0;
  246. return;
  247. }
  248. }
  249. BOOL WINAPI WintrustSetRegPolicyFlags(DWORD dwState)
  250. {
  251. HKEY hKey;
  252. DWORD dwDisposition;
  253. DWORD lErr;
  254. DWORD dwType;
  255. DWORD cbData;
  256. cbData = sizeof(DWORD);
  257. if (RegCreateHKCUKeyExU(HKEY_CURRENT_USER,
  258. REGPATH_WINTRUST_POLICY_FLAGS,
  259. 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  260. &hKey, &dwDisposition) != ERROR_SUCCESS)
  261. {
  262. return(FALSE);
  263. }
  264. if (RegSetValueExU(hKey,
  265. REGNAME_WINTRUST_POLICY_FLAGS,
  266. 0,
  267. REG_DWORD,
  268. (BYTE *)&dwState,
  269. sizeof(DWORD)) != ERROR_SUCCESS)
  270. {
  271. RegCloseKey(hKey);
  272. return(FALSE);
  273. }
  274. RegCloseKey(hKey);
  275. return(TRUE);
  276. }