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.

354 lines
8.9 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. if ((wcslen(pwszRegKey) + wcslen(&wszGuid[0]) + 2) > REG_MAX_KEY_NAME)
  47. {
  48. SetLastError(ERROR_INVALID_PARAMETER);
  49. return(FALSE);
  50. }
  51. wcscpy(&wsz[0], pwszRegKey);
  52. wcscat(&wsz[0], L"\\");
  53. wcscat(&wsz[0], &wszGuid[0]);
  54. if (RegOpenKeyExU( HKEY_LOCAL_MACHINE,
  55. &wsz[0],
  56. 0,
  57. KEY_READ,
  58. &hKey) != ERROR_SUCCESS)
  59. {
  60. return(FALSE);
  61. }
  62. dwType = 0;
  63. dwSize = (REG_MAX_KEY_NAME) * sizeof(WCHAR);
  64. if (RegQueryValueExU( hKey,
  65. REG_DLL_NAME,
  66. NULL,
  67. &dwType,
  68. (BYTE *)pwszRetDLLName,
  69. &dwSize) != ERROR_SUCCESS)
  70. {
  71. pwszRetDLLName[0] = NULL;
  72. RegCloseKey(hKey);
  73. return(FALSE);
  74. }
  75. dwType = 0;
  76. dwSize = (REG_MAX_FUNC_NAME) * sizeof(WCHAR);
  77. if (RegQueryValueExU( hKey,
  78. REG_FUNC_NAME,
  79. NULL,
  80. &dwType,
  81. (BYTE *)&wsz[0],
  82. &dwSize) != ERROR_SUCCESS)
  83. {
  84. pszRetFuncName[0] = NULL;
  85. RegCloseKey(hKey);
  86. return(FALSE);
  87. }
  88. if (WideCharToMultiByte(0, 0, &wsz[0], wcslen(&wsz[0]) + 1,
  89. pszRetFuncName, REG_MAX_FUNC_NAME, NULL, NULL) < 1)
  90. {
  91. RegCloseKey(hKey);
  92. return(FALSE);
  93. }
  94. RegCloseKey(hKey);
  95. return(TRUE);
  96. }
  97. BOOL SetRegProvider(GUID *pgActionID, WCHAR *pwszRegKey, WCHAR *pwszDLLName, WCHAR *pwszFuncName)
  98. {
  99. HRESULT hr;
  100. DWORD dwDisposition;
  101. HKEY hKey;
  102. WCHAR wsz[REG_MAX_KEY_NAME];
  103. WCHAR wszGuid[REG_MAX_GUID_TEXT];
  104. if (!(pgActionID) ||
  105. !(pwszRegKey) ||
  106. !(pwszDLLName) ||
  107. !(pwszFuncName))
  108. {
  109. SetLastError(ERROR_INVALID_PARAMETER);
  110. return(FALSE);
  111. }
  112. if (!(guid2wstr(pgActionID, &wszGuid[0])))
  113. {
  114. SetLastError(ERROR_INVALID_PARAMETER);
  115. return(FALSE);
  116. }
  117. if ((wcslen(pwszRegKey) + wcslen(&wszGuid[0]) + 2) > REG_MAX_KEY_NAME)
  118. {
  119. SetLastError(ERROR_INVALID_PARAMETER);
  120. return(FALSE);
  121. }
  122. wcscpy(&wsz[0], pwszRegKey);
  123. wcscat(&wsz[0], L"\\");
  124. wcscat(&wsz[0], &wszGuid[0]);
  125. hr = RegCreateKeyExU(HKEY_LOCAL_MACHINE,
  126. &wsz[0],
  127. 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  128. &hKey, &dwDisposition);
  129. if (hr != ERROR_SUCCESS)
  130. {
  131. SetLastError(hr);
  132. return(FALSE);
  133. }
  134. hr = RegSetValueExU(hKey, REG_DLL_NAME,
  135. 0, REG_SZ,
  136. (BYTE *)pwszDLLName,
  137. (wcslen(pwszDLLName) + 1) * sizeof(WCHAR));
  138. hr |= RegSetValueExU(hKey, REG_FUNC_NAME,
  139. 0, REG_SZ,
  140. (BYTE *)pwszFuncName,
  141. (wcslen(pwszFuncName) + 1) * sizeof(WCHAR));
  142. RegCloseKey(hKey);
  143. if (hr != ERROR_SUCCESS)
  144. {
  145. return(FALSE);
  146. }
  147. return(TRUE);
  148. }
  149. BOOL RemoveRegProvider(GUID *pgActionID, WCHAR *pwszRegKey)
  150. {
  151. WCHAR wsz[REG_MAX_KEY_NAME];
  152. WCHAR wszGuid[REG_MAX_GUID_TEXT];
  153. if (!(pgActionID) ||
  154. !(pwszRegKey))
  155. {
  156. SetLastError(ERROR_INVALID_PARAMETER);
  157. return(FALSE);
  158. }
  159. if (!(guid2wstr(pgActionID, &wszGuid[0])))
  160. {
  161. SetLastError(ERROR_INVALID_PARAMETER);
  162. return(FALSE);
  163. }
  164. if ((wcslen(pwszRegKey) + wcslen(&wszGuid[0]) + 2) > REG_MAX_KEY_NAME)
  165. {
  166. SetLastError(ERROR_INVALID_PARAMETER);
  167. return(FALSE);
  168. }
  169. wcscpy(&wsz[0], pwszRegKey);
  170. wcscat(&wsz[0], L"\\");
  171. wcscat(&wsz[0], &wszGuid[0]);
  172. if (RegDeleteKeyU(HKEY_LOCAL_MACHINE, &wsz[0]) != ERROR_SUCCESS)
  173. {
  174. return(FALSE);
  175. }
  176. return(TRUE);
  177. }
  178. void GetRegSecuritySettings(DWORD *pdwState)
  179. {
  180. HKEY hKeyRoot;
  181. WCHAR wszBuffer[STATUS_SIZE];
  182. DWORD dwType;
  183. DWORD dwSize;
  184. dwType = 0;
  185. dwSize = STATUS_SIZE * sizeof(WCHAR);
  186. *pdwState = 2; // Default to high
  187. if (RegOpenHKCUKeyExU( HKEY_CURRENT_USER,
  188. SZIE30SAFTYLEVEL,
  189. 0, // dwReserved
  190. KEY_READ,
  191. &hKeyRoot) != ERROR_SUCCESS)
  192. {
  193. return;
  194. }
  195. if (RegQueryValueExU( hKeyRoot,
  196. SZIE30SAFTYLEVELNAME,
  197. NULL,
  198. &dwType,
  199. (BYTE *)&wszBuffer[0],
  200. &dwSize) != ERROR_SUCCESS)
  201. {
  202. RegCloseKey(hKeyRoot);
  203. return;
  204. }
  205. RegCloseKey(hKeyRoot);
  206. if (dwType == REG_SZ)
  207. {
  208. if (wcscmp(&wszBuffer[0], L"FailInform") == 0)
  209. {
  210. *pdwState = 2;
  211. }
  212. else if (wcscmp(&wszBuffer[0], L"Query") == 0)
  213. {
  214. *pdwState = 1;
  215. }
  216. else if (wcscmp(&wszBuffer[0], L"SucceedSilent") == 0)
  217. {
  218. *pdwState = 0;
  219. }
  220. }
  221. }
  222. void WINAPI WintrustGetRegPolicyFlags(DWORD *pdwState)
  223. {
  224. HKEY hKey;
  225. DWORD dwDisposition;
  226. DWORD lErr;
  227. DWORD dwType;
  228. DWORD cbData;
  229. *pdwState = 0;
  230. cbData = sizeof(DWORD);
  231. // Open the registry and get to the state var
  232. if (RegCreateHKCUKeyExU(HKEY_CURRENT_USER,
  233. REGPATH_WINTRUST_POLICY_FLAGS,
  234. 0,
  235. NULL,
  236. REG_OPTION_NON_VOLATILE,
  237. KEY_READ,
  238. NULL,
  239. &hKey,
  240. &dwDisposition) != ERROR_SUCCESS)
  241. {
  242. return;
  243. }
  244. // read the state var
  245. if (RegQueryValueExU( hKey,
  246. REGNAME_WINTRUST_POLICY_FLAGS,
  247. NULL,
  248. &dwType,
  249. (BYTE *)pdwState,
  250. &cbData) != ERROR_SUCCESS)
  251. {
  252. *pdwState = 0;
  253. RegCloseKey(hKey);
  254. return;
  255. }
  256. RegCloseKey(hKey);
  257. if ((dwType != REG_DWORD) &&
  258. (dwType != REG_BINARY))
  259. {
  260. *pdwState = 0;
  261. return;
  262. }
  263. }
  264. BOOL WINAPI WintrustSetRegPolicyFlags(DWORD dwState)
  265. {
  266. HKEY hKey;
  267. DWORD dwDisposition;
  268. DWORD lErr;
  269. DWORD dwType;
  270. DWORD cbData;
  271. cbData = sizeof(DWORD);
  272. if (RegCreateHKCUKeyExU(HKEY_CURRENT_USER,
  273. REGPATH_WINTRUST_POLICY_FLAGS,
  274. 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  275. &hKey, &dwDisposition) != ERROR_SUCCESS)
  276. {
  277. return(FALSE);
  278. }
  279. if (RegSetValueExU(hKey,
  280. REGNAME_WINTRUST_POLICY_FLAGS,
  281. 0,
  282. REG_DWORD,
  283. (BYTE *)&dwState,
  284. sizeof(DWORD)) != ERROR_SUCCESS)
  285. {
  286. RegCloseKey(hKey);
  287. return(FALSE);
  288. }
  289. RegCloseKey(hKey);
  290. return(TRUE);
  291. }