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.

841 lines
22 KiB

  1. #include <unk.h>
  2. #include <wbemcli.h>
  3. #include <wbemprov.h>
  4. #include <atlbase.h>
  5. #include <sync.h>
  6. #include "activeds.h"
  7. #include "genlex.h"
  8. #include "objpath.h"
  9. #include "Utility.h"
  10. #include "PolicGPO.h"
  11. /*****************************\
  12. *** POLICY PROVIDER HELPERS ***
  13. \*****************************/
  14. // returns addref'd pointer back to m_pWMIMgmt
  15. IWbemServices* CPolicyGPO::GetWMIServices(void)
  16. {
  17. CInCritSec lock(&m_CS);
  18. if (NULL != m_pWMIMgmt)
  19. m_pWMIMgmt->AddRef();
  20. return m_pWMIMgmt;
  21. }
  22. // returns addref'd pointer back to m_pADMgmt
  23. IADsContainer* CPolicyGPO::GetADServices(wchar_t *pADPath)
  24. {
  25. DEBUGTRACE((LOG_ESS, "POLICMAN: [WMIGPO] GetADServices (%S)\n", pADPath));
  26. CInCritSec lock(&m_CS);
  27. IADsContainer *pADContainer = NULL;
  28. HRESULT hres;
  29. if(NULL != pADPath)
  30. {
  31. wchar_t
  32. szDSPath[MAX_PATH];
  33. // wcscpy(szDSPath,L"LDAP://");
  34. // wcscat(szDSPath, pADPath);
  35. hres = ADsGetObject(pADPath, IID_IADsContainer, (void**) &pADContainer);
  36. if (FAILED(hres))
  37. ERRORTRACE((LOG_ESS, "POLICMAN: ADsGetObject failed 0x%08X\n", hres));
  38. }
  39. return pADContainer;
  40. }
  41. // returns false if services pointer has already been set
  42. bool CPolicyGPO::SetWMIServices(IWbemServices* pServices)
  43. {
  44. CInCritSec lock(&m_CS);
  45. bool bOldOneNull;
  46. if (bOldOneNull = (m_pWMIMgmt == NULL))
  47. {
  48. m_pWMIMgmt = pServices;
  49. pServices->AddRef();
  50. }
  51. return bOldOneNull;
  52. }
  53. // returns false if services pointer has already been set
  54. bool CPolicyGPO::SetADServices(IADsContainer* pServices)
  55. {
  56. CInCritSec lock(&m_CS);
  57. bool bOldOneNull;
  58. if (bOldOneNull = (m_pADMgmt == NULL))
  59. {
  60. m_pADMgmt = pServices;
  61. if(pServices) pServices->AddRef();
  62. }
  63. return bOldOneNull;
  64. }
  65. CPolicyGPO::~CPolicyGPO()
  66. {
  67. // **** WMI services object
  68. if (NULL != m_pWMIMgmt)
  69. {
  70. m_pWMIMgmt->Release();
  71. m_pWMIMgmt= NULL;
  72. }
  73. // **** AD services object
  74. if (NULL != m_pADMgmt)
  75. {
  76. m_pADMgmt->Release();
  77. m_pADMgmt= NULL;
  78. }
  79. };
  80. void* CPolicyGPO::GetInterface(REFIID riid)
  81. {
  82. if(riid == IID_IWbemServices)
  83. return &m_XProvider;
  84. else if(riid == IID_IWbemProviderInit)
  85. return &m_XInit;
  86. else return NULL;
  87. }
  88. /********************\
  89. *** Object Support ***
  90. \********************/
  91. // returns addref'd pointer to class object
  92. IWbemClassObject* CPolicyGPO::XProvider::GetWMIGPOClass()
  93. {
  94. CInCritSec lock(&m_pObject->m_CS);
  95. if (m_pWMIGPOClassObject == NULL)
  96. {
  97. IWbemServices* pWinMgmt = NULL;
  98. if (pWinMgmt = m_pObject->GetWMIServices())
  99. {
  100. CReleaseMe relMgmt(pWinMgmt);
  101. pWinMgmt->GetObject(g_bstrClassWMIGPO,
  102. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  103. NULL,
  104. &m_pWMIGPOClassObject,
  105. NULL);
  106. }
  107. }
  108. if (m_pWMIGPOClassObject)
  109. m_pWMIGPOClassObject->AddRef();
  110. return m_pWMIGPOClassObject;
  111. }
  112. // returns addref'd pointer to emply class instance
  113. IWbemClassObject* CPolicyGPO::XProvider::GetWMIGPOInstance()
  114. {
  115. IWbemClassObject* pObj = NULL;
  116. IWbemClassObject* pClass = NULL;
  117. if (pClass = GetWMIGPOClass())
  118. {
  119. CReleaseMe releaseClass(pClass);
  120. pClass->SpawnInstance(0, &pObj);
  121. }
  122. return pObj;
  123. }
  124. CPolicyGPO::XProvider::~XProvider()
  125. {
  126. if(NULL != m_pWMIGPOClassObject)
  127. {
  128. m_pWMIGPOClassObject->Release();
  129. m_pWMIGPOClassObject = NULL;
  130. }
  131. }
  132. /*************************\
  133. *** IWbemProviderInit ***
  134. \*************************/
  135. STDMETHODIMP CPolicyGPO::XInit::Initialize(
  136. LPWSTR, LONG, LPWSTR, LPWSTR, IWbemServices* pServices, IWbemContext* pCtxt,
  137. IWbemProviderInitSink* pSink)
  138. {
  139. DEBUGTRACE((LOG_ESS, "POLICMAN: [WMIGPO] IWbemProviderInit::Initialize\n"));
  140. CComPtr<IADs>
  141. pRootDSE;
  142. CComPtr<IADsContainer>
  143. pObject;
  144. HRESULT
  145. hres = WBEM_S_NO_ERROR,
  146. hres2 = WBEM_S_NO_ERROR;
  147. wchar_t
  148. szDSPath[MAX_PATH];
  149. // **** impersonate client for security
  150. hres = CoImpersonateClient();
  151. if(FAILED(hres))
  152. {
  153. ERRORTRACE((LOG_ESS, "POLICMAN: (CoImpersonateClient) could not assume client permissions, 0x%08X\n", hres));
  154. return WBEM_S_ACCESS_DENIED;
  155. }
  156. else
  157. {
  158. // **** safe WMI name space pointer
  159. m_pObject->SetWMIServices(pServices);
  160. // **** get pointer to AD policy template table
  161. hres = ADsGetObject(L"LDAP://rootDSE", IID_IADs, (void**)&pRootDSE);
  162. if (FAILED(hres))
  163. {
  164. ERRORTRACE((LOG_ESS, "POLICMAN: (ADsGetObject) could not get object: LDAP://rootDSE, 0x%08X\n", hres));
  165. return WBEM_E_NOT_FOUND;
  166. }
  167. else
  168. {
  169. hres = pRootDSE->Get(L"defaultNamingContext",&m_pObject->m_vDsLocalContext);
  170. if(FAILED(hres))
  171. {
  172. ERRORTRACE((LOG_ESS, "POLICMAN: (IADs::Get) could not get defaultNamingContext, 0x%08X\n", hres));
  173. hres = WBEM_E_NOT_FOUND;
  174. }
  175. hres = pRootDSE->Get(L"configurationNamingContext",&m_pObject->m_vDsConfigContext);
  176. if(FAILED(hres))
  177. {
  178. ERRORTRACE((LOG_ESS, "POLICMAN: (IADs::Get) could not get configurationNamingContext, 0x%08X\n", hres));
  179. hres = WBEM_E_NOT_FOUND;
  180. }
  181. }
  182. }
  183. hres2 = pSink->SetStatus(hres, 0);
  184. if(FAILED(hres2))
  185. {
  186. ERRORTRACE((LOG_ESS, "POLICMAN: could not set return status\n"));
  187. if(SUCCEEDED(hres)) hres = hres2;
  188. }
  189. return hres;
  190. }
  191. /*******************\
  192. *** IWbemServices ***
  193. \*******************/
  194. STDMETHODIMP CPolicyGPO::XProvider::GetObjectAsync(
  195. /* [in] */ const BSTR ObjectPath,
  196. /* [in] */ long lFlags,
  197. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  198. /* [in] */ IWbemObjectSink __RPC_FAR *pResponse)
  199. {
  200. DEBUGTRACE((LOG_ESS, "POLICMAN: [WMIGPO] IWbemServices::GetObjectAsync(%S, 0x%x, 0x%x, 0x%x)\n", ObjectPath, lFlags, pCtx, pResponse));
  201. HRESULT
  202. hres = WBEM_S_NO_ERROR,
  203. hres2 = WBEM_S_NO_ERROR;
  204. wchar_t
  205. *DsPath = NULL;
  206. CComPtr<IWbemServices>
  207. pNamespace;
  208. CComPtr<IADsContainer>
  209. pADsContainer;
  210. CComPtr<IDispatch>
  211. pDisp;
  212. CComPtr<IWbemClassObject>
  213. pObj;
  214. CComPtr<IDirectoryObject>
  215. pDirObj;
  216. // **** impersonate client
  217. hres = CoImpersonateClient();
  218. if(FAILED(hres))
  219. {
  220. ERRORTRACE((LOG_ESS, "POLICMAN: (CoImpersonateClient) could not assume callers permissions, 0x%08X\n",hres));
  221. hres = WBEM_E_ACCESS_DENIED;
  222. }
  223. else
  224. {
  225. pNamespace = m_pObject->GetWMIServices();
  226. if(pNamespace == NULL)
  227. {
  228. ERRORTRACE((LOG_ESS, "POLICMAN: WMI services not initialized\n"));
  229. hres = WBEM_E_NOT_FOUND;
  230. }
  231. else
  232. {
  233. // **** Check arguments
  234. if(ObjectPath == NULL || pResponse == NULL)
  235. {
  236. ERRORTRACE((LOG_ESS, "POLICMAN: object path and/or return object are NULL\n"));
  237. hres = WBEM_E_INVALID_PARAMETER;
  238. }
  239. else
  240. {
  241. // **** parse object path
  242. CObjectPathParser
  243. ObjPath(e_ParserAcceptRelativeNamespace);
  244. ParsedObjectPath
  245. *pParsedObjectPath = NULL;
  246. if((ObjPath.NoError != ObjPath.Parse(ObjectPath, &pParsedObjectPath)) ||
  247. (0 != _wcsicmp(g_bstrClassWMIGPO, pParsedObjectPath->m_pClass)) ||
  248. (1 != pParsedObjectPath->m_dwNumKeys))
  249. {
  250. ERRORTRACE((LOG_ESS, "POLICMAN: Parse error for object: %S\n", ObjectPath));
  251. hres = WBEM_E_INVALID_QUERY;
  252. }
  253. else
  254. {
  255. int x;
  256. for(x = 0; x < pParsedObjectPath->m_dwNumKeys; x++)
  257. if(0 == _wcsicmp((*(pParsedObjectPath->m_paKeys + x))->m_pName, g_bstrDsPath))
  258. DsPath = V_BSTR(&((*(pParsedObjectPath->m_paKeys + x))->m_vValue));
  259. try
  260. {
  261. // **** obtain WMIGPO object pointed to by DsPath
  262. pADsContainer = m_pObject->GetADServices(DsPath);
  263. if(pADsContainer == NULL)
  264. {
  265. ERRORTRACE((LOG_ESS, "POLICMAN: could not find container in AD: %S\n", DsPath));
  266. return WBEM_E_NOT_FOUND;
  267. }
  268. // **** Get pointer to instance in AD
  269. hres = pADsContainer->GetObject(g_bstrADClassWMIGPO,
  270. QString(L"CN=") << L"SINGLE_WMIGPO", &pDisp);
  271. if(FAILED(hres)) return ADSIToWMIErrorCodes(hres);
  272. hres = pDisp->QueryInterface(IID_IDirectoryObject, (void **)&pDirObj);
  273. if(FAILED(hres)) return hres;
  274. // **** Get the instance and send it back
  275. hres = WMIGPO_ADToCIM(&pObj, pDirObj, pNamespace);
  276. if(FAILED(hres)) return ADSIToWMIErrorCodes(hres);
  277. if(pObj == NULL) return WBEM_E_FAILED;
  278. // **** Set object
  279. pResponse->Indicate(1, &pObj);
  280. }
  281. catch(long hret)
  282. {
  283. hres = ADSIToWMIErrorCodes(hret);
  284. ERRORTRACE((LOG_ESS, "POLICMAN: Translation of object from AD to WMI generated HRESULT 0x%08X\n", hres));
  285. }
  286. catch(wchar_t *swErrString)
  287. {
  288. ERRORTRACE((LOG_ESS, "POLICMAN: Caught Exception: %S\n", swErrString));
  289. hres = WBEM_E_FAILED;
  290. }
  291. catch(...)
  292. {
  293. // please leave the word 'unknown' in lower case.
  294. ERRORTRACE((LOG_ESS, "POLICMAN: Caught Unknown Exception\n"));
  295. hres = WBEM_E_FAILED;
  296. }
  297. }
  298. hres2 = pResponse->SetStatus(0,hres, NULL, NULL);
  299. if(FAILED(hres2))
  300. {
  301. ERRORTRACE((LOG_ESS, "POLICMAN: could not set return status\n"));
  302. if(SUCCEEDED(hres)) hres = hres2;
  303. }
  304. ObjPath.Free(pParsedObjectPath);
  305. pParsedObjectPath = NULL;
  306. }
  307. }
  308. CoRevertToSelf();
  309. }
  310. return hres;
  311. }
  312. STDMETHODIMP CPolicyGPO::XProvider::CreateInstanceEnumAsync(
  313. /* [in] */ const BSTR Class,
  314. /* [in] */ long lFlags,
  315. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  316. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  317. {
  318. DEBUGTRACE((LOG_ESS, "POLICMAN: [WMIGPO] IWbemServices::CreateInstanceEnumAsync(%S, 0x%x, 0x%x, 0x%x)\n", Class, lFlags, pCtx, pResponseHandler));
  319. HRESULT
  320. hres = WBEM_S_NO_ERROR,
  321. hres2 = WBEM_S_NO_ERROR;
  322. CComVariant
  323. v1;
  324. ULONG
  325. nFetched = 0;
  326. CComPtr<IWbemClassObject>
  327. pObj;
  328. CComPtr<IWbemServices>
  329. pNamespace;
  330. CComPtr<IDirectorySearch>
  331. pDirSrch;
  332. CComPtr<IDirectoryObject>
  333. pDirObj;
  334. CComPtr<IADsContainer>
  335. pADsContainer;
  336. IEnumVARIANT
  337. *pEnum = NULL;
  338. wchar_t
  339. *pszContexts[] = { L"GLOBAL", L"LOCAL" },
  340. *pszDistName[] = { L"distinguishedName" },
  341. objPath[1024];
  342. ADS_SEARCH_HANDLE
  343. searchHandle;
  344. ADS_SEARCH_COLUMN
  345. searchColumn;
  346. // **** impersonate client
  347. hres = CoImpersonateClient();
  348. if (FAILED(hres))
  349. {
  350. ERRORTRACE((LOG_ESS, "POLICMAN: (CoImpersonateClient) could not assume callers permissions, 0x%08X\n",hres));
  351. hres = WBEM_E_ACCESS_DENIED;
  352. }
  353. else
  354. {
  355. // **** Check arguments
  356. if(Class == NULL || pResponseHandler == NULL)
  357. {
  358. ERRORTRACE((LOG_ESS, "POLICMAN: object path and/or return object are NULL\n"));
  359. hres = WBEM_E_INVALID_PARAMETER;
  360. }
  361. else
  362. {
  363. // **** parse object path
  364. CObjectPathParser
  365. ObjPath(e_ParserAcceptRelativeNamespace);
  366. ParsedObjectPath
  367. *pParsedObjectPath = NULL;
  368. if((ObjPath.NoError != ObjPath.Parse(Class, &pParsedObjectPath)) ||
  369. (0 != _wcsicmp(g_bstrClassWMIGPO, pParsedObjectPath->m_pClass)) ||
  370. (0 != pParsedObjectPath->m_dwNumKeys))
  371. {
  372. ERRORTRACE((LOG_ESS, "POLICMAN: Parse error for object: %S\n", Class));
  373. hres = WBEM_E_INVALID_QUERY;
  374. }
  375. else
  376. {
  377. // **** bind to global catalog and WMI
  378. pNamespace = m_pObject->GetWMIServices();
  379. if(pNamespace == NULL)
  380. {
  381. ERRORTRACE((LOG_ESS, "POLICMAN: WMI and/or AD services not initialized: 0x%08X\n", hres));
  382. hres = WBEM_E_NOT_FOUND;
  383. }
  384. else
  385. {
  386. for(int i = 0; i < AD_MAX_CONTEXT; i++)
  387. {
  388. switch(i)
  389. {
  390. case AD_LOCAL_CONTEXT :
  391. wcscpy(objPath,L"LDAP://CN=System,");
  392. break;
  393. case AD_GLOBAL_CONTEXT :
  394. wcscpy(objPath,L"LDAP://CN=Services,CN=Configuration,");
  395. default : ;
  396. }
  397. wcscat(objPath, m_pObject->m_vDsLocalContext.bstrVal);
  398. pADsContainer = m_pObject->GetADServices(objPath);
  399. if(pADsContainer == NULL)
  400. {
  401. // ERRORTRACE((LOG_ESS, "POLICMAN: could not find container in AD: %S\n", DsPath));
  402. hres = WBEM_E_NOT_FOUND;
  403. }
  404. else
  405. {
  406. hres = pADsContainer->QueryInterface(IID_IDirectorySearch, (void **)&pDirSrch);
  407. // **** set search preferences
  408. // **** perform search
  409. hres = pDirSrch->ExecuteSearch(
  410. QString(L"(objectCategory=") << g_bstrADClassWMIGPO << L")",
  411. pszDistName,
  412. 1,
  413. &searchHandle);
  414. if(FAILED(hres))
  415. {
  416. ERRORTRACE((LOG_ESS, "POLICMAN: Could perform Global Catalog search for Som objects, 0x%08X\n", hres));
  417. hres = WBEM_E_FAILED;
  418. }
  419. else
  420. {
  421. try
  422. {
  423. while(SUCCEEDED(hres = pDirSrch->GetNextRow(searchHandle)) &&
  424. (S_ADS_NOMORE_ROWS != hres))
  425. {
  426. // **** get path to object
  427. hres = pDirSrch->GetColumn(searchHandle, pszDistName[0], &searchColumn);
  428. if(FAILED(hres)) return ADSIToWMIErrorCodes(hres);
  429. // **** get pointer to object
  430. wcscpy(objPath, L"LDAP://");
  431. wcscat(objPath, searchColumn.pADsValues->CaseIgnoreString);
  432. pDirSrch->FreeColumn(&searchColumn);
  433. hres = ADsGetObject(objPath, IID_IDirectoryObject, (void **)&pDirObj);
  434. if(FAILED(hres)) return ADSIToWMIErrorCodes(hres);
  435. hres = WMIGPO_ADToCIM(&pObj, pDirObj, pNamespace);
  436. if(FAILED(hres)) return ADSIToWMIErrorCodes(hres);
  437. if(pObj == NULL) return WBEM_E_FAILED;
  438. hres = pResponseHandler->Indicate(1, &pObj);
  439. pDirObj = NULL;
  440. pObj = NULL;
  441. }
  442. }
  443. catch(long hret)
  444. {
  445. hres = ADSIToWMIErrorCodes(hret);
  446. ERRORTRACE((LOG_ESS, "POLICMAN: Translation of Policy object from AD to WMI generated HRESULT 0x%08X\n", hres));
  447. }
  448. catch(wchar_t *swErrString)
  449. {
  450. ERRORTRACE((LOG_ESS, "POLICMAN: Caught Exception: %S\n", swErrString));
  451. hres = WBEM_E_FAILED;
  452. }
  453. catch(...)
  454. {
  455. ERRORTRACE((LOG_ESS, "POLICMAN: Caught unknown Exception\n"));
  456. hres = WBEM_E_FAILED;
  457. }
  458. hres = pDirSrch->CloseSearchHandle(searchHandle);
  459. }
  460. }
  461. }
  462. }
  463. }
  464. ObjPath.Free(pParsedObjectPath);
  465. hres2 = pResponseHandler->SetStatus(0, hres, NULL, NULL);
  466. if(FAILED(hres2))
  467. {
  468. ERRORTRACE((LOG_ESS, "POLICMAN: could not set return status\n"));
  469. if(SUCCEEDED(hres)) hres = hres2;
  470. }
  471. }
  472. CoRevertToSelf();
  473. }
  474. return hres;
  475. }
  476. STDMETHODIMP CPolicyGPO::XProvider::PutInstanceAsync(
  477. /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  478. /* [in] */ long lFlags,
  479. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  480. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  481. {
  482. DEBUGTRACE((LOG_ESS, "POLICMAN: [WMIGPO] IWbemServices::PutInstanceAsync(0x%x, 0x%x, 0x%x, 0x%x)\n", pInst, lFlags, pCtx, pResponseHandler));
  483. HRESULT
  484. hres = WBEM_S_NO_ERROR;
  485. CComVariant
  486. v1, vRelPath;
  487. CComPtr<IADsContainer>
  488. pADsContainer;
  489. CComPtr<IDirectoryObject>
  490. pDirObj;
  491. // **** impersonate client
  492. hres = CoImpersonateClient();
  493. if(FAILED(hres))
  494. {
  495. ERRORTRACE((LOG_ESS, "POLICMAN: (CoImpersonateClient) could not assume callers permissions, 0x%08X\n",hres));
  496. hres = WBEM_E_ACCESS_DENIED;
  497. }
  498. else
  499. {
  500. // **** check arguments
  501. if((NULL == pInst) || (NULL == pResponseHandler))
  502. {
  503. ERRORTRACE((LOG_ESS, "POLICMAN: object handle and/or return status object are NULL\n"));
  504. hres = WBEM_E_INVALID_PARAMETER;
  505. }
  506. else
  507. {
  508. // **** put policy obj into AD
  509. try
  510. {
  511. // **** aquire AD path in which to place object
  512. hres = pInst->Get(g_bstrDsPath, 0, &v1, NULL, NULL);
  513. if(FAILED(hres)) return hres;
  514. if(VT_BSTR == v1.vt)
  515. pADsContainer = m_pObject->GetADServices(V_BSTR(&v1));
  516. if(pADsContainer == NULL)
  517. {
  518. ERRORTRACE((LOG_ESS, "POLICMAN: Could not find or connect to domain: %S\n", V_BSTR(&v1)));
  519. return WBEM_E_ACCESS_DENIED;
  520. }
  521. else
  522. {
  523. hres = pADsContainer->QueryInterface(IID_IDirectoryObject, (void **)&pDirObj);
  524. if(FAILED(hres)) return hres;
  525. // **** copy policy obj into AD
  526. hres = WMIGPO_CIMToAD(pInst, pDirObj, lFlags);
  527. if(FAILED(hres)) return ADSIToWMIErrorCodes(hres);
  528. }
  529. }
  530. catch(long hret)
  531. {
  532. hres = ADSIToWMIErrorCodes(hret);
  533. ERRORTRACE((LOG_ESS, "POLICMAN: Translation of Policy object from WMI to AD generated HRESULT 0x%08X\n", hres));
  534. }
  535. catch(wchar_t *swErrString)
  536. {
  537. ERRORTRACE((LOG_ESS, "POLICMAN: Caught Exception: %S\n", swErrString));
  538. hres = WBEM_E_FAILED;
  539. }
  540. catch(...)
  541. {
  542. ERRORTRACE((LOG_ESS, "POLICMAN: Caught unknown Exception\n"));
  543. hres = WBEM_E_FAILED;
  544. }
  545. // send it back as we may have added keys
  546. if(SUCCEEDED(hres))
  547. pResponseHandler->Indicate(1, &pInst);
  548. // **** indicate return status
  549. pInst->Get(L"__RELPATH", 0, &vRelPath, NULL, NULL);
  550. if(FAILED(pResponseHandler->SetStatus(0, hres, vRelPath.bstrVal, NULL)))
  551. {
  552. ERRORTRACE((LOG_ESS, "POLICMAN: could not set return status\n"));
  553. }
  554. }
  555. CoRevertToSelf();
  556. }
  557. return hres;
  558. }
  559. STDMETHODIMP CPolicyGPO::XProvider::DeleteInstanceAsync(
  560. /* [in] */ const BSTR ObjectPath,
  561. /* [in] */ long lFlags,
  562. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  563. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  564. {
  565. DEBUGTRACE((LOG_ESS, "POLICMAN: [WMIGPO] IWbemServices::DeleteInstanceAsync(%S, 0x%x, 0x%x, 0x%x)\n", ObjectPath, lFlags, pCtx, pResponseHandler));
  566. HRESULT
  567. hres = WBEM_S_NO_ERROR,
  568. hres2 = WBEM_S_NO_ERROR;
  569. CComPtr<IADsContainer>
  570. pADsContainer;
  571. CComPtr<IDispatch>
  572. pDisp;
  573. CComPtr<IADsDeleteOps>
  574. pDelObj;
  575. wchar_t
  576. *DsPath = NULL;
  577. // **** impersonate client
  578. hres = CoImpersonateClient();
  579. if(FAILED(hres))
  580. {
  581. ERRORTRACE((LOG_ESS, "POLICMAN: (CoImpersonateClient) could not assume callers permissions, 0x%08X\n",hres));
  582. hres = WBEM_E_ACCESS_DENIED;
  583. }
  584. else
  585. {
  586. // **** Check arguments
  587. if(ObjectPath == NULL || pResponseHandler == NULL)
  588. {
  589. ERRORTRACE((LOG_ESS, "POLICMAN: object handle and/or return status object are NULL\n"));
  590. return WBEM_E_INVALID_PARAMETER;
  591. }
  592. else
  593. {
  594. // **** parse WMI object path
  595. CObjectPathParser
  596. ObjPath(e_ParserAcceptRelativeNamespace);
  597. ParsedObjectPath
  598. *pParsedObjectPath = NULL;
  599. if((ObjPath.NoError != ObjPath.Parse(ObjectPath, &pParsedObjectPath)) ||
  600. (0 != _wcsicmp(g_bstrClassWMIGPO, pParsedObjectPath->m_pClass)) ||
  601. (1 != pParsedObjectPath->m_dwNumKeys))
  602. {
  603. ERRORTRACE((LOG_ESS, "POLICMAN: Parse error for object: %S\n", ObjectPath));
  604. hres = WBEM_E_INVALID_QUERY;
  605. }
  606. else
  607. {
  608. int x;
  609. // **** only grab ID key for now
  610. for(x = 0; x < pParsedObjectPath->m_dwNumKeys; x++)
  611. if(0 == _wcsicmp((*(pParsedObjectPath->m_paKeys + x))->m_pName, g_bstrDsPath))
  612. DsPath = V_BSTR(&((*(pParsedObjectPath->m_paKeys + x))->m_vValue));
  613. // **** obtain WMIGPO object pointed to by DsPath
  614. pADsContainer = m_pObject->GetADServices(DsPath);
  615. if(pADsContainer == NULL)
  616. {
  617. ERRORTRACE((LOG_ESS, "POLICMAN: could not find container in AD: %S\n", DsPath));
  618. hres = WBEM_E_NOT_FOUND;
  619. }
  620. else
  621. {
  622. // **** Get pointer to instance in AD
  623. hres = pADsContainer->GetObject(g_bstrADClassWMIGPO, L"CN=SINGLE_WMIGPO", &pDisp);
  624. if(FAILED(hres))
  625. {
  626. hres = ADSIToWMIErrorCodes(hres);
  627. ERRORTRACE((LOG_ESS, "POLICMAN: (IADsContainer::GetObject) could not get object in AD 0x%08X\n", hres));
  628. }
  629. else
  630. {
  631. hres = pDisp->QueryInterface(IID_IADsDeleteOps, (void **)&pDelObj);
  632. if(FAILED(hres))
  633. {
  634. ERRORTRACE((LOG_ESS, "POLICMAN: (IDispatch::QueryInterface) could not get IID_IADsDeleteOps interface on object\n"));
  635. }
  636. else
  637. {
  638. // **** delete the instance and all its children in AD
  639. hres = pDelObj->DeleteObject(0);
  640. if(FAILED(hres))
  641. {
  642. hres = ADSIToWMIErrorCodes(hres);
  643. ERRORTRACE((LOG_ESS, "POLICMAN: (IADsDeleteOps::DeleteObject) could not delete object\n"));
  644. }
  645. }
  646. }
  647. }
  648. ObjPath.Free(pParsedObjectPath);
  649. }
  650. // **** Set Status
  651. hres2 = pResponseHandler->SetStatus(0, hres, NULL, NULL);
  652. if(FAILED(hres2))
  653. {
  654. ERRORTRACE((LOG_ESS, "POLICMAN: could not set return status\n"));
  655. if(SUCCEEDED(hres)) hres = hres2;
  656. }
  657. }
  658. CoRevertToSelf();
  659. }
  660. return hres;
  661. }
  662. STDMETHODIMP CPolicyGPO::XProvider::ExecQueryAsync(
  663. /* [in] */ const BSTR QueryLanguage,
  664. /* [in] */ const BSTR Query,
  665. /* [in] */ long lFlags,
  666. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  667. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  668. {
  669. return WBEM_E_NOT_SUPPORTED;
  670. }
  671. STDMETHODIMP CPolicyGPO::XProvider::ExecMethodAsync(
  672. /* [in] */ const BSTR strObjectPath,
  673. /* [in] */ const BSTR strMethodName,
  674. /* [in] */ long lFlags,
  675. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  676. /* [in] */ IWbemClassObject __RPC_FAR *pInParams,
  677. /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler)
  678. {
  679. return WBEM_E_NOT_SUPPORTED;
  680. }