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.

368 lines
7.9 KiB

  1. #include "precomp.h"
  2. DWORD
  3. OpenRegistryWIRELESSRootKey(
  4. LPWSTR pszServerName,
  5. LPWSTR pszWirelessRegRootContainer,
  6. HKEY * phRegistryKey
  7. )
  8. {
  9. DWORD dwError = 0;
  10. dwError = RegOpenKeyExW(
  11. HKEY_LOCAL_MACHINE,
  12. (LPCWSTR) pszWirelessRegRootContainer,
  13. 0,
  14. KEY_ALL_ACCESS,
  15. phRegistryKey
  16. );
  17. BAIL_ON_WIN32_ERROR(dwError);
  18. error:
  19. return(dwError);
  20. }
  21. DWORD
  22. ReadPolicyObjectFromRegistry(
  23. HKEY hRegistryKey,
  24. LPWSTR pszPolicyDN,
  25. LPWSTR pszWirelessRegRootContainer,
  26. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObject
  27. )
  28. {
  29. DWORD dwError = 0;
  30. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  31. dwError = UnMarshallRegistryPolicyObject(
  32. hRegistryKey,
  33. pszWirelessRegRootContainer,
  34. pszPolicyDN,
  35. REG_FULLY_QUALIFIED_NAME,
  36. &pWirelessPolicyObject
  37. );
  38. BAIL_ON_WIN32_ERROR(dwError);
  39. *ppWirelessPolicyObject = pWirelessPolicyObject;
  40. cleanup:
  41. return(dwError);
  42. error:
  43. if (pWirelessPolicyObject) {
  44. FreeWirelessPolicyObject(
  45. pWirelessPolicyObject
  46. );
  47. }
  48. *ppWirelessPolicyObject = NULL;
  49. goto cleanup;
  50. }
  51. DWORD
  52. UnMarshallRegistryPolicyObject(
  53. HKEY hRegistryKey,
  54. LPWSTR pszWirelessRegRootContainer,
  55. LPWSTR pszWirelessPolicyDN,
  56. DWORD dwNameType,
  57. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObject
  58. )
  59. {
  60. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  61. HKEY hRegKey = NULL;
  62. DWORD dwType = 0;
  63. DWORD dwSize = 0;
  64. DWORD dwWirelessDataType = 0;
  65. DWORD dwWhenChanged = 0;
  66. LPBYTE pBuffer = NULL;
  67. DWORD i = 0;
  68. DWORD dwCount = 0;
  69. DWORD dwError = 0;
  70. LPWSTR pszTemp = NULL;
  71. LPWSTR pszString = NULL;
  72. LPWSTR pszRelativeName = NULL;
  73. DWORD dwRootPathLen = 0;
  74. if (!pszWirelessPolicyDN || !*pszWirelessPolicyDN) {
  75. dwError = ERROR_INVALID_DATA;
  76. BAIL_ON_WIN32_ERROR(dwError);
  77. }
  78. if (dwNameType == REG_FULLY_QUALIFIED_NAME) {
  79. dwRootPathLen = wcslen(pszWirelessRegRootContainer);
  80. if (wcslen(pszWirelessPolicyDN) <= (dwRootPathLen+1)) {
  81. dwError = ERROR_INVALID_DATA;
  82. BAIL_ON_WIN32_ERROR(dwError);
  83. }
  84. pszRelativeName = pszWirelessPolicyDN + dwRootPathLen + 1;
  85. }else {
  86. pszRelativeName = pszWirelessPolicyDN;
  87. }
  88. dwError = RegOpenKeyExW(
  89. hRegistryKey,
  90. pszRelativeName,
  91. 0,
  92. KEY_ALL_ACCESS,
  93. &hRegKey
  94. );
  95. BAIL_ON_WIN32_ERROR(dwError);
  96. pWirelessPolicyObject = (PWIRELESS_POLICY_OBJECT)AllocPolMem(
  97. sizeof(WIRELESS_POLICY_OBJECT)
  98. );
  99. if (!pWirelessPolicyObject) {
  100. dwError = ERROR_OUTOFMEMORY;
  101. BAIL_ON_WIN32_ERROR(dwError);
  102. }
  103. pWirelessPolicyObject->pszWirelessOwnersReference = AllocPolStr(
  104. pszWirelessPolicyDN
  105. );
  106. if (!pWirelessPolicyObject->pszWirelessOwnersReference) {
  107. dwError = ERROR_OUTOFMEMORY;
  108. BAIL_ON_WIN32_ERROR(dwError);
  109. }
  110. dwError = RegstoreQueryValue(
  111. hRegKey,
  112. L"WirelessName",
  113. REG_SZ,
  114. (LPBYTE *)&pWirelessPolicyObject->pszWirelessName,
  115. &dwSize
  116. );
  117. BAIL_ON_WIN32_ERROR(dwError);
  118. dwError = RegstoreQueryValue(
  119. hRegKey,
  120. L"description",
  121. REG_SZ,
  122. (LPBYTE *)&pWirelessPolicyObject->pszDescription,
  123. &dwSize
  124. );
  125. // BAIL_ON_WIN32_ERROR(dwError);
  126. dwError = RegstoreQueryValue(
  127. hRegKey,
  128. L"WirelessID",
  129. REG_SZ,
  130. (LPBYTE *)&pWirelessPolicyObject->pszWirelessID,
  131. &dwSize
  132. );
  133. BAIL_ON_WIN32_ERROR(dwError);
  134. dwType = REG_DWORD;
  135. dwSize = sizeof(DWORD);
  136. dwError = RegQueryValueExW(
  137. hRegKey,
  138. L"WirelessDataType",
  139. NULL,
  140. &dwType,
  141. (LPBYTE)&dwWirelessDataType,
  142. &dwSize
  143. );
  144. BAIL_ON_WIN32_ERROR(dwError);
  145. pWirelessPolicyObject->dwWirelessDataType = dwWirelessDataType;
  146. dwError = RegstoreQueryValue(
  147. hRegKey,
  148. L"WirelessData",
  149. REG_BINARY,
  150. &pWirelessPolicyObject->pWirelessData,
  151. &pWirelessPolicyObject->dwWirelessDataLen
  152. );
  153. BAIL_ON_WIN32_ERROR(dwError);
  154. dwType = REG_DWORD;
  155. dwSize = sizeof(DWORD);
  156. dwError = RegQueryValueExW(
  157. hRegKey,
  158. L"whenChanged",
  159. NULL,
  160. &dwType,
  161. (LPBYTE)&dwWhenChanged,
  162. &dwSize
  163. );
  164. BAIL_ON_WIN32_ERROR(dwError);
  165. pWirelessPolicyObject->dwWhenChanged = dwWhenChanged;
  166. *ppWirelessPolicyObject = pWirelessPolicyObject;
  167. if (hRegKey) {
  168. RegCloseKey(hRegKey);
  169. }
  170. return(dwError);
  171. error:
  172. *ppWirelessPolicyObject = NULL;
  173. if (pWirelessPolicyObject) {
  174. FreeWirelessPolicyObject(pWirelessPolicyObject);
  175. }
  176. if (hRegKey) {
  177. RegCloseKey(hRegKey);
  178. }
  179. return(dwError);
  180. }
  181. DWORD
  182. RegstoreQueryValue(
  183. HKEY hRegKey,
  184. LPWSTR pszValueName,
  185. DWORD dwType,
  186. LPBYTE * ppValueData,
  187. LPDWORD pdwSize
  188. )
  189. {
  190. DWORD dwSize = 0;
  191. LPWSTR pszValueData = NULL;
  192. DWORD dwError = 0;
  193. LPBYTE pBuffer = NULL;
  194. LPWSTR pszBuf = NULL;
  195. dwError = RegQueryValueExW(
  196. hRegKey,
  197. pszValueName,
  198. NULL,
  199. &dwType,
  200. NULL,
  201. &dwSize
  202. );
  203. BAIL_ON_WIN32_ERROR(dwError);
  204. if (dwSize == 0) {
  205. dwError = ERROR_INVALID_DATA;
  206. BAIL_ON_WIN32_ERROR(dwError);
  207. }
  208. pBuffer = (LPBYTE)AllocPolMem(dwSize);
  209. if (!pBuffer) {
  210. dwError = ERROR_OUTOFMEMORY;
  211. BAIL_ON_WIN32_ERROR(dwError);
  212. }
  213. dwError = RegQueryValueExW(
  214. hRegKey,
  215. pszValueName,
  216. NULL,
  217. &dwType,
  218. pBuffer,
  219. &dwSize
  220. );
  221. BAIL_ON_WIN32_ERROR(dwError);
  222. switch (dwType) {
  223. case REG_SZ:
  224. pszBuf = (LPWSTR) pBuffer;
  225. if (!pszBuf || !*pszBuf) {
  226. dwError = ERROR_INVALID_DATA;
  227. BAIL_ON_WIN32_ERROR(dwError);
  228. }
  229. break;
  230. default:
  231. break;
  232. }
  233. *ppValueData = pBuffer;
  234. *pdwSize = dwSize;
  235. return(dwError);
  236. error:
  237. if (pBuffer) {
  238. FreePolMem(pBuffer);
  239. }
  240. *ppValueData = NULL;
  241. *pdwSize = 0;
  242. return(dwError);
  243. }
  244. VOID
  245. FlushRegSaveKey(
  246. HKEY hRegistryKey
  247. )
  248. {
  249. DWORD dwError = 0;
  250. WCHAR lpszName[MAX_PATH];
  251. DWORD dwSize = 0;
  252. memset(lpszName, 0, sizeof(WCHAR)*MAX_PATH);
  253. dwSize = MAX_PATH;
  254. while((RegEnumKeyExW(
  255. hRegistryKey,
  256. 0,
  257. lpszName,
  258. &dwSize,
  259. NULL,
  260. NULL,
  261. NULL,
  262. NULL)) == ERROR_SUCCESS) {
  263. dwError = RegDeleteKeyW(
  264. hRegistryKey,
  265. lpszName
  266. );
  267. if (dwError != ERROR_SUCCESS) {
  268. break;
  269. }
  270. memset(lpszName, 0, sizeof(WCHAR)*MAX_PATH);
  271. dwSize = MAX_PATH;
  272. }
  273. return;
  274. }