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.

271 lines
6.8 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: policy-w.c
  7. //
  8. // Contents: Policy management for WMI.
  9. //
  10. //
  11. // History: KrishnaG.
  12. // AbhisheV.
  13. // t-hhsu
  14. //
  15. //----------------------------------------------------------------------------
  16. #include "precomp.h"
  17. //extern LPWSTR PolicyDNAttributes[];
  18. DWORD
  19. WMIEnumPolicyDataEx(
  20. IWbemServices *pWbemServices,
  21. PWIRELESS_POLICY_DATA ** pppWirelessPolicyData,
  22. PDWORD pdwNumPolicyObjects
  23. )
  24. {
  25. DWORD dwError = 0;
  26. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObjects = NULL;
  27. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  28. PWIRELESS_POLICY_DATA * ppWirelessPolicyData = NULL;
  29. DWORD dwNumPolicyObjects = 0;
  30. DWORD i = 0;
  31. DWORD j = 0;
  32. dwError = WMIEnumPolicyObjectsEx(
  33. pWbemServices,
  34. &ppWirelessPolicyObjects,
  35. &dwNumPolicyObjects
  36. );
  37. BAIL_ON_WIN32_ERROR(dwError);
  38. if (dwNumPolicyObjects) {
  39. ppWirelessPolicyData = (PWIRELESS_POLICY_DATA *) AllocPolMem(
  40. dwNumPolicyObjects*sizeof(PWIRELESS_POLICY_DATA));
  41. if (!ppWirelessPolicyData) {
  42. dwError = ERROR_OUTOFMEMORY;
  43. BAIL_ON_WIN32_ERROR(dwError);
  44. }
  45. }
  46. for (i = 0; i < dwNumPolicyObjects; i++) {
  47. dwError = WMIUnmarshallPolicyData(
  48. *(ppWirelessPolicyObjects + i),
  49. &pWirelessPolicyData
  50. );
  51. if (!dwError) {
  52. *(ppWirelessPolicyData + j) = pWirelessPolicyData;
  53. j++;
  54. }
  55. }
  56. if (j == 0) {
  57. if (ppWirelessPolicyData) {
  58. FreePolMem(ppWirelessPolicyData);
  59. ppWirelessPolicyData = NULL;
  60. }
  61. }
  62. *pppWirelessPolicyData = ppWirelessPolicyData;
  63. *pdwNumPolicyObjects = j;
  64. dwError = ERROR_SUCCESS;
  65. cleanup:
  66. if (ppWirelessPolicyObjects) {
  67. FreeWirelessPolicyObjects(
  68. ppWirelessPolicyObjects,
  69. dwNumPolicyObjects
  70. );
  71. }
  72. return(dwError);
  73. error:
  74. if (ppWirelessPolicyData) {
  75. FreeMulWirelessPolicyData(
  76. ppWirelessPolicyData,
  77. i
  78. );
  79. }
  80. *pppWirelessPolicyData = NULL;
  81. *pdwNumPolicyObjects = 0;
  82. goto cleanup;
  83. }
  84. DWORD
  85. WMIEnumPolicyObjectsEx(
  86. IWbemServices *pWbemServices,
  87. PWIRELESS_POLICY_OBJECT ** pppWirelessPolicyObjects,
  88. PDWORD pdwNumPolicyObjects
  89. )
  90. {
  91. DWORD dwError = 0;
  92. HRESULT hr = S_OK;
  93. DWORD dwNumPolicyObjectsReturned = 0;
  94. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  95. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObjects = NULL;
  96. ///wbem
  97. IEnumWbemClassObject *pEnum = NULL;
  98. IWbemClassObject *pObj = NULL;
  99. ULONG uReturned = 0;
  100. VARIANT var;
  101. LPWSTR tmpStr = NULL;
  102. BSTR bstrTmp = NULL;
  103. *pppWirelessPolicyObjects = NULL;
  104. *pdwNumPolicyObjects = 0;
  105. VariantInit(&var);
  106. bstrTmp = SysAllocString(L"RSOP_IEEE80211PolicySetting");
  107. if(!bstrTmp) {
  108. dwError = ERROR_OUTOFMEMORY;
  109. BAIL_ON_WIN32_ERROR(dwError);
  110. }
  111. //get enum
  112. hr = IWbemServices_CreateInstanceEnum(
  113. pWbemServices,
  114. bstrTmp, //L"RSOP_IEEE80211PolicySetting"
  115. WBEM_FLAG_FORWARD_ONLY,
  116. 0,
  117. &pEnum
  118. );
  119. SysFreeString(bstrTmp);
  120. BAIL_ON_WMI_ERROR_WITH_WIN32(hr, dwError);
  121. //process
  122. while (1)
  123. {
  124. hr = IEnumWbemClassObject_Next(pEnum, WBEM_INFINITE, 1, &pObj, &uReturned);
  125. if (hr == WBEM_S_NO_ERROR)
  126. {
  127. hr = IWbemClassObject_Get(
  128. pObj,
  129. L"id",
  130. 0,
  131. &var,
  132. 0,
  133. 0
  134. );
  135. BAIL_ON_WMI_ERROR_WITH_WIN32(hr, dwError);
  136. tmpStr = var.bstrVal;
  137. if (!wcsstr(tmpStr, L"msieee80211-Policy")) {
  138. IWbemClassObject_Release(pObj);
  139. VariantClear(&var);
  140. continue;
  141. }
  142. pWirelessPolicyObject = NULL;
  143. dwError = UnMarshallWMIPolicyObject(
  144. pObj,
  145. &pWirelessPolicyObject
  146. );
  147. if (dwError == ERROR_SUCCESS) {
  148. dwError = ReallocatePolMem(
  149. (LPVOID *) &ppWirelessPolicyObjects,
  150. sizeof(PWIRELESS_POLICY_OBJECT)*(dwNumPolicyObjectsReturned),
  151. sizeof(PWIRELESS_POLICY_OBJECT)*(dwNumPolicyObjectsReturned + 1)
  152. );
  153. BAIL_ON_WIN32_ERROR(dwError);
  154. *(ppWirelessPolicyObjects + dwNumPolicyObjectsReturned) = pWirelessPolicyObject;
  155. dwNumPolicyObjectsReturned++;
  156. }
  157. //free
  158. IWbemClassObject_Release(pObj);
  159. VariantClear(&var);
  160. } else {
  161. if(hr == WBEM_S_FALSE) {
  162. break;
  163. } else {
  164. BAIL_ON_WMI_ERROR_WITH_WIN32(hr, dwError);
  165. }
  166. }
  167. }
  168. *pppWirelessPolicyObjects = ppWirelessPolicyObjects;
  169. *pdwNumPolicyObjects = dwNumPolicyObjectsReturned;
  170. dwError = ERROR_SUCCESS;
  171. cleanup:
  172. if(pEnum)
  173. IEnumWbemClassObject_Release(pEnum);
  174. return(dwError);
  175. error:
  176. if (pObj) {
  177. IWbemClassObject_Release(pObj);
  178. pObj = NULL;
  179. }
  180. VariantClear(&var);
  181. if (ppWirelessPolicyObjects) {
  182. FreeWirelessPolicyObjects(
  183. ppWirelessPolicyObjects,
  184. dwNumPolicyObjectsReturned
  185. );
  186. }
  187. if (pWirelessPolicyObject) {
  188. FreeWirelessPolicyObject(
  189. pWirelessPolicyObject
  190. );
  191. }
  192. *pppWirelessPolicyObjects = NULL;
  193. *pdwNumPolicyObjects = 0;
  194. goto cleanup;
  195. }
  196. DWORD
  197. WMIUnmarshallPolicyData(
  198. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject,
  199. PWIRELESS_POLICY_DATA * ppWirelessPolicyData
  200. )
  201. {
  202. DWORD dwError = 0;
  203. dwError = UnmarshallWirelessPolicyObject(
  204. pWirelessPolicyObject,
  205. WIRELESS_WMI_PROVIDER, //(procrule.h)
  206. ppWirelessPolicyData
  207. );
  208. BAIL_ON_WIN32_ERROR(dwError);
  209. if (*ppWirelessPolicyData) {
  210. (*ppWirelessPolicyData)->dwFlags |= WLSTORE_READONLY;
  211. }
  212. error:
  213. return(dwError);
  214. }