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.

313 lines
8.8 KiB

  1. /*++
  2. Copyright (C) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. COMOBJ.CPP
  5. Abstract:
  6. Implements mofcomp com objects.
  7. History:
  8. a-davj 17-Sept-98 Created.
  9. --*/
  10. #include "precomp.h"
  11. #include "commain.h"
  12. #include "wbemcli.h"
  13. #include "wbemprov.h"
  14. #include "wbemint.h"
  15. #include "comobj.h"
  16. #include "mofout.h"
  17. #include "mofparse.h"
  18. #include "dllcalls.h"
  19. #include "datasrc.h"
  20. SCODE Compile(CMofParser & Parser, IWbemServices *pOverride, IWbemContext * pCtx, long lOptionFlags, long lClassFlags, long lInstanceFlags,
  21. WCHAR * wszDefault, WCHAR *UserName, WCHAR *pPassword , WCHAR *Authority,
  22. WCHAR * wszBmof, bool bInProc, WBEM_COMPILE_STATUS_INFO *pInfo);
  23. void ClearStatus(WBEM_COMPILE_STATUS_INFO *pInfo)
  24. {
  25. if(pInfo)
  26. {
  27. pInfo->lPhaseError = 0; // 0, 1, 2, or 3 matching current return value
  28. pInfo->hRes = 0; // Actual error
  29. pInfo->ObjectNum = 0;
  30. pInfo->FirstLine = 0;
  31. pInfo->LastLine = 0;
  32. pInfo->dwOutFlags = 0;
  33. }
  34. }
  35. HRESULT APIENTRY CompileFileViaDLL(
  36. /* [in] */ LPWSTR FileName,
  37. /* [in] */ LPWSTR ServerAndNamespace,
  38. /* [in] */ LPWSTR User,
  39. /* [in] */ LPWSTR Authority,
  40. /* [in] */ LPWSTR Password,
  41. /* [in] */ LONG lOptionFlags,
  42. /* [in] */ LONG lClassFlags,
  43. /* [in] */ LONG lInstanceFlags,
  44. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo)
  45. {
  46. SCODE sc;
  47. if(FileName == NULL)
  48. return WBEM_E_INVALID_PARAMETER;
  49. TCHAR cFile[MAX_PATH];
  50. ClearStatus(pInfo);
  51. TCHAR * pFile = NULL;
  52. if(FileName)
  53. {
  54. CopyOrConvert(cFile, FileName, MAX_PATH);
  55. pFile = cFile;
  56. }
  57. try
  58. {
  59. DebugInfo dbg((lOptionFlags & WBEM_FLAG_CONSOLE_PRINT) != 0);
  60. CMofParser Parser(pFile, &dbg);
  61. sc = Compile(Parser, NULL, NULL, lOptionFlags, lClassFlags, lInstanceFlags,
  62. ServerAndNamespace, User, Password, Authority,
  63. NULL, false, pInfo);
  64. }
  65. catch (GenericException ge)
  66. {
  67. sc = ge.GetHRESULT();
  68. }
  69. return sc;
  70. }
  71. HRESULT APIENTRY CreateBMOFViaDLL(
  72. /* [in] */ LPWSTR TextFileName,
  73. /* [in] */ LPWSTR BMOFFileName,
  74. /* [in] */ LPWSTR ServerAndNamespace,
  75. /* [in] */ LONG lOptionFlags,
  76. /* [in] */ LONG lClassFlags,
  77. /* [in] */ LONG lInstanceFlags,
  78. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo)
  79. {
  80. SCODE sc;
  81. TCHAR cFile[MAX_PATH];
  82. if(TextFileName == NULL || BMOFFileName == NULL)
  83. return WBEM_E_INVALID_PARAMETER;
  84. ClearStatus(pInfo);
  85. TCHAR * pFile = NULL;
  86. if(TextFileName)
  87. {
  88. CopyOrConvert(cFile, TextFileName, MAX_PATH);
  89. pFile = cFile;
  90. }
  91. try
  92. {
  93. DebugInfo dbg((lOptionFlags & WBEM_FLAG_CONSOLE_PRINT) != 0);
  94. CMofParser Parser(pFile, &dbg);
  95. sc = Compile(Parser, NULL, NULL, lOptionFlags, lClassFlags, lInstanceFlags,
  96. ServerAndNamespace, NULL, NULL, NULL,
  97. BMOFFileName, false, pInfo);
  98. }
  99. catch (GenericException ge)
  100. {
  101. sc = ge.GetHRESULT();
  102. }
  103. return sc;
  104. }
  105. HRESULT CMofComp::CompileFile(
  106. /* [in] */ LPWSTR FileName,
  107. /* [in] */ LPWSTR ServerAndNamespace,
  108. /* [in] */ LPWSTR User,
  109. /* [in] */ LPWSTR Authority,
  110. /* [in] */ LPWSTR Password,
  111. /* [in] */ LONG lOptionFlags,
  112. /* [in] */ LONG lClassFlags,
  113. /* [in] */ LONG lInstanceFlags,
  114. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo)
  115. {
  116. SCODE sc;
  117. if(FileName == NULL)
  118. return WBEM_E_INVALID_PARAMETER;
  119. TCHAR cFile[MAX_PATH];
  120. ClearStatus(pInfo);
  121. TCHAR * pFile = NULL;
  122. if(FileName)
  123. {
  124. CopyOrConvert(cFile, FileName, MAX_PATH);
  125. pFile = cFile;
  126. }
  127. try
  128. {
  129. DebugInfo dbg((lOptionFlags & WBEM_FLAG_CONSOLE_PRINT) != 0);
  130. CMofParser Parser(pFile, &dbg);
  131. if((lOptionFlags & WBEM_FLAG_CHECK_ONLY) && (lOptionFlags & WBEM_FLAG_CONSOLE_PRINT))
  132. Parser.SetToDoScopeCheck();
  133. sc = Compile(Parser, NULL, NULL, lOptionFlags, lClassFlags, lInstanceFlags,
  134. ServerAndNamespace, User, Password, Authority,
  135. NULL, false, pInfo);
  136. }
  137. catch (GenericException ge)
  138. {
  139. sc = ge.GetHRESULT();
  140. }
  141. return sc;
  142. }
  143. HRESULT CMofComp::CompileBuffer(
  144. /* [in] */ long BuffSize,
  145. /* [size_is][in] */ BYTE __RPC_FAR *pBuffer,
  146. /* [in] */ LPWSTR ServerAndNamespace,
  147. /* [in] */ LPWSTR User,
  148. /* [in] */ LPWSTR Authority,
  149. /* [in] */ LPWSTR Password,
  150. /* [in] */ LONG lOptionFlags,
  151. /* [in] */ LONG lClassFlags,
  152. /* [in] */ LONG lInstanceFlags,
  153. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo)
  154. {
  155. SCODE sc;
  156. if(pBuffer == NULL || BuffSize == 0)
  157. return WBEM_E_INVALID_PARAMETER;
  158. DebugInfo dbg((lOptionFlags & WBEM_FLAG_CONSOLE_PRINT) != 0);
  159. CMofParser Parser(&dbg);
  160. try
  161. {
  162. Parser.SetBuffer((char *)pBuffer, BuffSize);
  163. sc = Compile(Parser, NULL, NULL, lOptionFlags, lClassFlags, lInstanceFlags,
  164. ServerAndNamespace, User, Password, Authority,
  165. NULL, false, pInfo);
  166. }
  167. catch(...)
  168. {
  169. sc = WBEM_E_FAILED;
  170. }
  171. return sc;
  172. }
  173. HRESULT CMofComp::CreateBMOF(
  174. /* [in] */ LPWSTR TextFileName,
  175. /* [in] */ LPWSTR BMOFFileName,
  176. /* [in] */ LPWSTR ServerAndNamespace,
  177. /* [in] */ LONG lOptionFlags,
  178. /* [in] */ LONG lClassFlags,
  179. /* [in] */ LONG lInstanceFlags,
  180. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo)
  181. {
  182. SCODE sc;
  183. TCHAR cFile[MAX_PATH];
  184. if(TextFileName == NULL || BMOFFileName == NULL)
  185. return WBEM_E_INVALID_PARAMETER;
  186. ClearStatus(pInfo);
  187. TCHAR * pFile = NULL;
  188. if(TextFileName)
  189. {
  190. CopyOrConvert(cFile, TextFileName, MAX_PATH);
  191. pFile = cFile;
  192. }
  193. try
  194. {
  195. DebugInfo dbg((lOptionFlags & WBEM_FLAG_CONSOLE_PRINT) != 0);
  196. CMofParser Parser(pFile, &dbg);
  197. sc = Compile(Parser, NULL, NULL, lOptionFlags, lClassFlags, lInstanceFlags,
  198. ServerAndNamespace, NULL, NULL, NULL,
  199. BMOFFileName, false, pInfo);
  200. }
  201. catch (GenericException ge)
  202. {
  203. sc = ge.GetHRESULT();
  204. }
  205. return sc;
  206. }
  207. HRESULT CWinmgmtMofComp::WinmgmtCompileFile(
  208. /* [in] */ LPWSTR FileName,
  209. /* [in] */ LPWSTR ServerAndNamespace,
  210. /* [in] */ LONG lOptionFlags,
  211. /* [in] */ LONG lClassFlags,
  212. /* [in] */ LONG lInstanceFlags,
  213. /* [in] */ IWbemServices __RPC_FAR *pOverride,
  214. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  215. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo)
  216. {
  217. SCODE sc;
  218. TCHAR cFile[MAX_PATH];
  219. if(FileName == NULL)
  220. return WBEM_E_INVALID_PARAMETER;
  221. ClearStatus(pInfo);
  222. TCHAR * pFile = NULL;
  223. if(FileName)
  224. {
  225. CopyOrConvert(cFile, FileName, MAX_PATH);
  226. pFile = cFile;
  227. }
  228. try
  229. {
  230. DebugInfo dbg((lOptionFlags & WBEM_FLAG_CONSOLE_PRINT) != 0);
  231. CMofParser Parser(pFile, &dbg);
  232. sc = Compile(Parser, pOverride, pCtx, lOptionFlags, lClassFlags, lInstanceFlags,
  233. ServerAndNamespace, NULL, NULL, NULL,
  234. NULL, true, pInfo);
  235. }
  236. catch (GenericException ge)
  237. {
  238. sc = ge.GetHRESULT();
  239. }
  240. return sc;
  241. }
  242. HRESULT CWinmgmtMofComp::WinmgmtCompileBuffer(
  243. /* [in] */ long BuffSize,
  244. /* [size_is][in] */ BYTE __RPC_FAR *pBuffer,
  245. /* [in] */ LONG lOptionFlags,
  246. /* [in] */ LONG lClassFlags,
  247. /* [in] */ LONG lInstanceFlags,
  248. /* [in] */ IWbemServices __RPC_FAR *pOverride,
  249. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  250. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo)
  251. {
  252. if(pBuffer == NULL || BuffSize == 0)
  253. return WBEM_E_INVALID_PARAMETER;
  254. DebugInfo dbg((lOptionFlags & WBEM_FLAG_CONSOLE_PRINT) != 0);
  255. CMofParser Parser(&dbg);
  256. try
  257. {
  258. Parser.SetBuffer((char *)pBuffer, BuffSize);
  259. SCODE sc = Compile(Parser, pOverride, pCtx, lOptionFlags, lClassFlags, lInstanceFlags,
  260. NULL, NULL, NULL, NULL, NULL, true, pInfo);
  261. return sc;
  262. }
  263. catch(...)
  264. {
  265. return S_FALSE;
  266. }
  267. }