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.

908 lines
24 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998
  5. //
  6. // File: ScripLog.cpp
  7. //
  8. // Contents:
  9. //
  10. // History: 9-Aug-99 NishadM Created
  11. //
  12. //---------------------------------------------------------------------------
  13. #include "gptext.h"
  14. #include "scriplog.h"
  15. #include <wbemtime.h>
  16. //
  17. // macros
  18. //
  19. #define MakeScriptId( wszKey, wszGpoId, wszSomId, wszType ) \
  20. wszKey = (LPWSTR) LocalAlloc( LPTR, (wcslen(wszGpoId) + wcslen(wszSomId) + wcslen(wszType) + 3) * sizeof(WCHAR) ); \
  21. if ( wszKey ) \
  22. { \
  23. wcscpy( wszKey, wszGpoId );wcscat( wszKey, L"-" ); \
  24. wcscat( wszKey, wszSomId );wcscat( wszKey, L"-" ); \
  25. wcscat( wszKey, wszType ); \
  26. }
  27. //*************************************************************
  28. //
  29. // CScriptsLogger::CScriptsLogger()
  30. //
  31. // Purpose: Constructor
  32. //
  33. // Parameters: pWbemServices - Wbem services
  34. //
  35. //*************************************************************
  36. CScriptsLogger::CScriptsLogger( IWbemServices *pWbemServices )
  37. : m_bInitialized(FALSE),
  38. m_pWbemServices(pWbemServices)
  39. {
  40. //
  41. // Policy Object, RSOP_PolicySetting in MOF
  42. //
  43. m_xbstrPath = L"__PATH";
  44. if ( !m_xbstrPath )
  45. return;
  46. m_xbstrId = L"id";
  47. if ( !m_xbstrId )
  48. return;
  49. m_xbstrName = L"name";
  50. if ( !m_xbstrName )
  51. return;
  52. m_xbstrGPO = L"GPOID";
  53. if ( !m_xbstrGPO )
  54. return;
  55. m_xbstrSOM = L"SOMID";
  56. if ( !m_xbstrSOM )
  57. return;
  58. m_xbstrOrderClass = L"precedence";
  59. if ( !m_xbstrOrderClass )
  60. return;
  61. //
  62. // Script Policy Object, RSOP_ScriptPolicySetting in MOF
  63. //
  64. m_xbstrScriptPolicySetting = L"RSOP_ScriptPolicySetting";
  65. if ( !m_xbstrScriptPolicySetting )
  66. return;
  67. //
  68. // ScriptType field of RSOP_ScriptPolicySetting in the MOF
  69. //
  70. m_xbstrScriptType = L"ScriptType";
  71. if ( !m_xbstrScriptType )
  72. return;
  73. //
  74. // ScriptList field of RSOP_ScriptPolicySetting in MOF
  75. //
  76. m_xbstrScriptList = L"ScriptList";
  77. if ( !m_xbstrScriptList )
  78. return;
  79. //
  80. // Order field of RSOP_ScriptPolicySetting in MOF
  81. //
  82. m_xbstrOrder = L"scriptOrder";
  83. if ( !m_xbstrOrder )
  84. return;
  85. //
  86. // WBEM version of CF for RSOP_ScriptPolicySetting
  87. //
  88. HRESULT hr = m_pWbemServices->GetObject( m_xbstrScriptPolicySetting,
  89. 0L,
  90. 0,
  91. &m_xScriptPolicySetting,
  92. 0 );
  93. if ( FAILED(hr) )
  94. {
  95. return;
  96. }
  97. //
  98. // individual script commands, RSOP_ScriptCmd in MOF
  99. //
  100. m_xbstrScriptCommand = L"RSOP_ScriptCmd";
  101. if ( !m_xbstrScriptCommand )
  102. return;
  103. //
  104. // Script field of RSOP_ScriptCmd
  105. //
  106. m_xbstrScript = L"Script";
  107. if ( !m_xbstrScript )
  108. return;
  109. //
  110. // Arguments field of RSOP_ScriptCmd
  111. //
  112. m_xbstrArguments = L"Arguments";
  113. if ( !m_xbstrArguments )
  114. return;
  115. //
  116. // executionTime field of RSOP_ScriptCmd
  117. //
  118. m_xbstrExecutionTime = L"executionTime";
  119. if ( !m_xbstrExecutionTime )
  120. return;
  121. //
  122. // WBEM version of CF for RSOP_ScriptCmd
  123. //
  124. hr = m_pWbemServices->GetObject( m_xbstrScriptCommand,
  125. 0L,
  126. 0,
  127. &m_xScriptCommand,
  128. 0 );
  129. if ( FAILED(hr) )
  130. {
  131. return;
  132. }
  133. //
  134. // spawn an instance of RSOP_ScriptPolicySetting
  135. //
  136. hr = m_xScriptPolicySetting->SpawnInstance( 0, &m_pInstance );
  137. if ( FAILED (hr) )
  138. {
  139. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: spawn instance failed, %d."), hr ));
  140. return;
  141. }
  142. m_bInitialized = TRUE;
  143. }
  144. //*************************************************************
  145. //
  146. // CScriptsLogger::Log()
  147. //
  148. // Purpose: Logs an instance of registry policy object
  149. //
  150. //
  151. //*************************************************************
  152. HRESULT
  153. CScriptsLogger::Log(PRSOP_ScriptList pList,
  154. LPWSTR wszGPOID,
  155. LPWSTR wszSOMID,
  156. LPWSTR wszRSOPGPOID,
  157. DWORD cOrder )
  158. {
  159. HRESULT hr = S_OK;
  160. VARIANT var;
  161. //
  162. // if CScriptsLogger is initialized
  163. //
  164. if ( !m_bInitialized )
  165. {
  166. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: object not initialized.")));
  167. return E_UNEXPECTED;
  168. }
  169. //
  170. // create a SafeArray of commands
  171. //
  172. XSafeArray xSafeArray = MakeSafeArrayOfScripts( pList );
  173. if ( !xSafeArray )
  174. {
  175. hr = HRESULT_FROM_WIN32( GetLastError() );
  176. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: could not create safe array of scripts.")));
  177. return hr;
  178. }
  179. //
  180. // set "id" for RSOP_PolicySetting
  181. //
  182. LPCWSTR wszType = ScriptTypeString( GetScriptType(pList) );
  183. XPtrLF<WCHAR> wszId;
  184. MakeScriptId( wszId, wszGPOID, wszSOMID, wszType );
  185. if ( wszId )
  186. {
  187. XBStr xId( wszId );
  188. if ( !xId )
  189. {
  190. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: ID is NULL.")));
  191. return E_OUTOFMEMORY;
  192. }
  193. var.vt = VT_BSTR;
  194. var.bstrVal = xId;
  195. hr = m_pInstance->Put( m_xbstrId, 0, &var, 0 );
  196. if ( FAILED (hr) )
  197. {
  198. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: put failed, %d."), hr ));
  199. return hr;
  200. }
  201. }
  202. else
  203. {
  204. hr = HRESULT_FROM_WIN32( GetLastError() );
  205. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: memory allocation failed.")));
  206. return hr;
  207. }
  208. //
  209. // set "name" for RSOP_PolicySetting
  210. //
  211. XBStr xName( L"Group Policy Object Scripts" );
  212. var.vt = VT_BSTR;
  213. var.bstrVal = xName;
  214. hr = m_pInstance->Put( m_xbstrName, 0, &var, 0 );
  215. if ( FAILED (hr) )
  216. {
  217. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: put name failed, %d."), hr ));
  218. return hr;
  219. }
  220. //
  221. // set "GPOID" for RSOP_PolicySetting
  222. //
  223. var.vt = VT_BSTR;
  224. var.bstrVal = wszRSOPGPOID;
  225. hr = m_pInstance->Put( m_xbstrGPO, 0, &var, 0 );
  226. if ( FAILED (hr) )
  227. {
  228. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: put GPOID failed, %d."), hr ));
  229. return hr;
  230. }
  231. //
  232. // set "SOMID" for RSOP_PolicySetting
  233. //
  234. var.vt = VT_BSTR;
  235. var.bstrVal = wszSOMID;
  236. hr = m_pInstance->Put( m_xbstrSOM, 0, &var, 0 );
  237. if ( FAILED (hr) )
  238. {
  239. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: put SOMID failed, %d."), hr ));
  240. return hr;
  241. }
  242. //
  243. // set "precedence" for RSOP_PolicySetting
  244. //
  245. var.vt = VT_I4;
  246. var.lVal = 1;
  247. hr = m_pInstance->Put( m_xbstrOrderClass, 0, &var, 0 );
  248. if ( FAILED (hr) )
  249. {
  250. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: put mergeOrder_Class failed, %d."), hr ));
  251. return hr;
  252. }
  253. //
  254. // set the "ScriptType" for RSOP_ScriptPolicySetting
  255. //
  256. var.vt = VT_I4;
  257. var.lVal = (LONG) GetScriptType(pList);
  258. hr = m_pInstance->Put( m_xbstrScriptType, 0, &var, 0 );
  259. if ( FAILED (hr) )
  260. {
  261. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: put ScriptType failed, %d."), hr ));
  262. return hr;
  263. }
  264. //
  265. // set the "ScriptList" for RSOP_ScriptPolicySetting
  266. //
  267. var.vt = VT_ARRAY | VT_UNKNOWN;
  268. var.parray = xSafeArray;
  269. hr = m_pInstance->Put( m_xbstrScriptList, 0, &var, 0 );
  270. if ( FAILED (hr) )
  271. {
  272. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: put ScriptList failed, %d."), hr ));
  273. return hr;
  274. }
  275. //
  276. // set the "Order" for RSOP_ScriptPolicySetting
  277. //
  278. var.vt = VT_I4;
  279. var.lVal = cOrder;
  280. hr = m_pInstance->Put( m_xbstrOrder, 0, &var, 0 );
  281. if ( FAILED (hr) )
  282. {
  283. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Log: put Order failed, %d."), hr ));
  284. return hr;
  285. }
  286. //
  287. // commit the instance of RSOP_ScriptPolicySetting
  288. //
  289. hr = m_pWbemServices->PutInstance( m_pInstance, WBEM_FLAG_CREATE_OR_UPDATE, NULL, NULL );
  290. return hr;
  291. }
  292. HRESULT
  293. CScriptsLogger::Update( PRSOP_ScriptList pList,
  294. LPCWSTR wszGPOID,
  295. LPCWSTR wszSOMID )
  296. {
  297. if ( !m_bInitialized )
  298. {
  299. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Update: object not initialized.")));
  300. return E_UNEXPECTED;
  301. }
  302. XInterface<IEnumWbemClassObject> xEnum;
  303. //
  304. // create an enumeration of RSOP_ScriptPolicySetting objects
  305. //
  306. HRESULT hr = m_pWbemServices->CreateInstanceEnum( m_xbstrScriptPolicySetting,
  307. WBEM_FLAG_SHALLOW,
  308. NULL,
  309. &xEnum );
  310. if ( FAILED(hr) )
  311. {
  312. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Update: CreateInstanceEnum() failed, %d."), hr ));
  313. return hr;
  314. }
  315. ULONG ulReturned = 1;
  316. LONG TIMEOUT = -1;
  317. LPWSTR wszId;
  318. LPCWSTR wszType = ScriptTypeString( GetScriptType( pList ) );
  319. MakeScriptId( wszId, wszGPOID, wszSOMID, wszType );
  320. if ( !wszId )
  321. {
  322. hr = HRESULT_FROM_WIN32( GetLastError() );
  323. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Update: memory allocation error, %d."), hr ));
  324. return hr;
  325. }
  326. XPtrLF<WCHAR> xId = wszId;
  327. while ( ulReturned == 1 && SUCCEEDED( hr ) )
  328. {
  329. XInterface<IWbemClassObject> xInstance;
  330. //
  331. // for every object
  332. //
  333. hr = xEnum->Next( TIMEOUT,
  334. 1,
  335. &xInstance,
  336. &ulReturned );
  337. if ( FAILED( hr ) )
  338. {
  339. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Update: enumeration failed, %d."), hr ));
  340. }
  341. else if ( ulReturned == 1 )
  342. {
  343. VARIANT var;
  344. VariantInit( &var );
  345. //
  346. // get the "id" from RSOP_ScriptPolicySetting
  347. //
  348. hr = xInstance->Get( m_xbstrId,
  349. 0L,
  350. &var,
  351. 0,
  352. 0 );
  353. if ( SUCCEEDED(hr) )
  354. {
  355. XVariant xVar(&var);
  356. if ( !wcscmp( var.bstrVal, wszId ) )
  357. {
  358. XSafeArray xSafeArray = MakeSafeArrayOfScripts( pList );
  359. if ( xSafeArray )
  360. {
  361. //
  362. // set the "ScriptList" for RSOP_ScriptPolicySetting
  363. //
  364. VARIANT var2;
  365. var2.vt = VT_ARRAY | VT_UNKNOWN;
  366. var2.parray = xSafeArray;
  367. hr = xInstance->Put( m_xbstrScriptList, 0, &var2, 0 );
  368. if ( SUCCEEDED (hr) )
  369. {
  370. //
  371. // commit the instance of RSOP_ScriptPolicySetting
  372. //
  373. hr = m_pWbemServices->PutInstance( xInstance, WBEM_FLAG_UPDATE_ONLY, NULL, NULL );
  374. if ( FAILED( hr ) )
  375. {
  376. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Update: PutInstance() failed, %d."), hr ));
  377. }
  378. }
  379. else
  380. {
  381. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Update: Put ScriptList failed, %d."), hr ));
  382. }
  383. }
  384. else
  385. {
  386. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Update: could not create safearray.")));
  387. }
  388. }
  389. }
  390. else
  391. {
  392. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Update: pInstance->Get() failed, %d."), hr ));
  393. }
  394. }
  395. }
  396. return hr;
  397. }
  398. HRESULT
  399. CScriptsLogger::Delete( PRSOP_ScriptList pList )
  400. {
  401. if ( !m_bInitialized )
  402. {
  403. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Delete: object not initialized.")));
  404. return E_UNEXPECTED;
  405. }
  406. XInterface<IEnumWbemClassObject> xEnum;
  407. //
  408. // create an enumeration of RSOP_ScriptPolicySetting objects
  409. //
  410. HRESULT hr = m_pWbemServices->CreateInstanceEnum( m_xbstrScriptPolicySetting,
  411. WBEM_FLAG_SHALLOW,
  412. NULL,
  413. &xEnum );
  414. if ( FAILED(hr) )
  415. {
  416. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Delete: could not enumerate instances.")));
  417. }
  418. ULONG ulReturned = 1;
  419. LONG TIMEOUT = -1;
  420. ScriptType type = GetScriptType( pList );
  421. while ( ulReturned == 1 )
  422. {
  423. XInterface<IWbemClassObject> xInstance;
  424. //
  425. // for every object
  426. //
  427. hr = xEnum->Next( TIMEOUT,
  428. 1,
  429. &xInstance,
  430. &ulReturned );
  431. if ( FAILED( hr ) )
  432. {
  433. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Delete: could not get next instance, %d."), hr));
  434. }
  435. else if ( ulReturned == 1 )
  436. {
  437. VARIANT var;
  438. VariantInit( &var );
  439. //
  440. // get the "type" from RSOP_ScriptPolicySetting
  441. //
  442. hr = xInstance->Get( m_xbstrScriptType,
  443. 0L,
  444. &var,
  445. 0,
  446. 0 );
  447. if ( SUCCEEDED(hr) )
  448. {
  449. //
  450. // if type field matches,
  451. //
  452. if ( var.lVal == (long) type )
  453. {
  454. hr = xInstance->Get( m_xbstrPath,
  455. 0L,
  456. &var,
  457. 0,
  458. 0 );
  459. if ( SUCCEEDED(hr) )
  460. {
  461. //
  462. // delete the instance
  463. // we could optimize and return here but,
  464. // by not doing so, we cleanup all the objects
  465. //
  466. hr = m_pWbemServices->DeleteInstance( var.bstrVal,
  467. 0L,
  468. 0,
  469. 0 );
  470. if ( FAILED( hr ) )
  471. {
  472. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Delete: could not delete instance, %d."), hr ));
  473. }
  474. }
  475. else
  476. {
  477. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Delete: could not get type value, %d."), hr));
  478. }
  479. VariantClear( &var );
  480. }
  481. }
  482. else
  483. {
  484. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::Delete: could not get type, %d."), hr));
  485. }
  486. }
  487. }
  488. return hr;
  489. }
  490. IUnknown*
  491. CScriptsLogger::PutScriptCommand( LPCWSTR wszCommand, LPCWSTR wszParams, SYSTEMTIME* pExecTime )
  492. {
  493. IUnknown* pUnk = 0;
  494. //
  495. // if CScriptsLogger is initialized
  496. //
  497. if ( !m_bInitialized )
  498. {
  499. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::PutScriptCommand: object not initialized.")));
  500. return pUnk;
  501. }
  502. IWbemClassObject* pInstance = 0;
  503. //
  504. // spawn an instance of RSOP_ScriptCmd
  505. //
  506. HRESULT hr = m_xScriptCommand->SpawnInstance( 0, &pInstance );
  507. if ( FAILED (hr) )
  508. {
  509. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::PutScriptCommand: spawn instance failed, %d."), hr ));
  510. return pUnk;
  511. }
  512. XInterface<IWbemClassObject> xInstance( pInstance );
  513. VARIANT var;
  514. //
  515. // set the Script field for RSOP_ScriptCmd
  516. //
  517. XBStr xCommand( ( LPWSTR ) wszCommand );
  518. var.vt = VT_BSTR;
  519. var.bstrVal = xCommand;
  520. hr = pInstance->Put( m_xbstrScript, 0, &var, 0 );
  521. if ( FAILED (hr) )
  522. {
  523. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::PutScriptCommand: put Script failed, %d."), hr ));
  524. return pUnk;
  525. }
  526. //
  527. // set the Arguments field for RSOP_ScriptCmd
  528. //
  529. XBStr xParams( ( LPWSTR ) wszParams );
  530. var.vt = VT_BSTR;
  531. var.bstrVal = xParams;
  532. hr = pInstance->Put( m_xbstrArguments, 0, &var, 0 );
  533. if ( FAILED (hr) )
  534. {
  535. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::PutScriptCommand: put Arguments failed, %d."), hr ));
  536. return pUnk;
  537. }
  538. //
  539. // set the executionTime field for RSOP_ScriptCmd
  540. //
  541. XBStr xExecutionTime;
  542. hr = SystemTimeToWbemTime( *pExecTime, xExecutionTime );
  543. if ( FAILED (hr) )
  544. {
  545. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::PutScriptCommand: put SystemTimeToWbemTime failed, %d."), hr ));
  546. return pUnk;
  547. }
  548. var.vt = VT_BSTR;
  549. var.bstrVal = xExecutionTime;
  550. hr = pInstance->Put( m_xbstrExecutionTime, 0, &var, 0 );
  551. if ( FAILED (hr) )
  552. {
  553. DebugMsg((DM_WARNING, TEXT("CScriptsLogger::PutScriptCommand: put executionTime failed, %d."), hr ));
  554. return pUnk;
  555. }
  556. pInstance->QueryInterface( IID_IUnknown, (void **)&pUnk);
  557. return pUnk;
  558. }
  559. LPSAFEARRAY
  560. CScriptsLogger::MakeSafeArrayOfScripts( PRSOP_ScriptList pList )
  561. {
  562. SAFEARRAYBOUND arrayBound[1];
  563. arrayBound[0].lLbound = 0;
  564. arrayBound[0].cElements = GetScriptCount( pList );
  565. //
  566. // create a SafeArray of RSOP_ScriptCmd
  567. //
  568. SAFEARRAY *pSafeArray = SafeArrayCreate( VT_UNKNOWN, 1, arrayBound );
  569. if ( pSafeArray )
  570. {
  571. DWORD nCommand = GetScriptCount( pList );
  572. if ( nCommand )
  573. {
  574. LPCWSTR szCommand = 0, szParams = 0;
  575. void* pv;
  576. long dwIndex = 0;
  577. SYSTEMTIME* pExecTime = 0;
  578. //
  579. // populate the array
  580. //
  581. GetFirstScript( pList, &pv, &szCommand, &szParams, &pExecTime );
  582. do
  583. {
  584. IUnknown* pUnk = PutScriptCommand( szCommand, szParams, pExecTime );
  585. SafeArrayPutElement( pSafeArray, &dwIndex, pUnk );
  586. nCommand--;
  587. dwIndex++;
  588. GetNextScript( pList, &pv, &szCommand, &szParams, &pExecTime );
  589. } while ( nCommand );
  590. }
  591. }
  592. return pSafeArray;
  593. }
  594. //*************************************************************
  595. //
  596. // LogScriptsRsopData()
  597. //
  598. // Purpose: Logs scripts Rsop data to Cimom database
  599. //
  600. // Return: True if successful
  601. //
  602. //*************************************************************
  603. HRESULT
  604. LogScriptsRsopData( RSOPScriptList pScriptList,
  605. IWbemServices* pWbemServices,
  606. LPCWSTR wszGPOID,
  607. LPCWSTR wszSOMID,
  608. LPCWSTR wszRSOPGPOID,
  609. DWORD cOrder )
  610. {
  611. PRSOP_ScriptList pList = (PRSOP_ScriptList) pScriptList;
  612. HRESULT hr = E_POINTER;
  613. void* pv = 0;
  614. if ( wszGPOID && wszSOMID && pWbemServices && pScriptList )
  615. {
  616. CScriptsLogger scriptsLogger( pWbemServices );
  617. //
  618. // RSOP logging for scripts ext
  619. //
  620. hr = scriptsLogger.Log( pList, (LPWSTR)wszGPOID, (LPWSTR)wszSOMID, (LPWSTR)wszRSOPGPOID, cOrder );
  621. }
  622. return hr;
  623. }
  624. HRESULT
  625. UpdateScriptsRsopData( RSOPScriptList pScriptList,
  626. IWbemServices* pWbemServices,
  627. LPCWSTR wszGPOID,
  628. LPCWSTR wszSOMID )
  629. {
  630. PRSOP_ScriptList pList = (PRSOP_ScriptList) pScriptList;
  631. HRESULT hr = E_POINTER;
  632. void* pv = 0;
  633. if ( wszGPOID && pWbemServices && wszSOMID && pScriptList )
  634. {
  635. CScriptsLogger scriptsLogger( pWbemServices );
  636. //
  637. // RSOP update for scripts
  638. //
  639. hr = scriptsLogger.Update( pList, wszGPOID, wszSOMID );
  640. }
  641. return hr;
  642. }
  643. //*************************************************************
  644. //
  645. // DeleteScriptsRsopData()
  646. //
  647. // Purpose: Logs scripts Rsop data to Cimom database
  648. //
  649. // Return: True if successful
  650. //
  651. //*************************************************************
  652. HRESULT
  653. DeleteScriptsRsopData( RSOPScriptList pScriptList, IWbemServices* pWbemServices )
  654. {
  655. PRSOP_ScriptList pList = (PRSOP_ScriptList) pScriptList;
  656. HRESULT hr = E_POINTER;
  657. void* pv = 0;
  658. if ( pWbemServices && pScriptList )
  659. {
  660. CScriptsLogger scriptsLogger( pWbemServices );
  661. //
  662. // delete all previous instances of RSOP_ScriptPolicySetting
  663. // with matching type
  664. //
  665. hr = scriptsLogger.Delete( pList );
  666. }
  667. return hr;
  668. }
  669. LPWSTR
  670. GetNamespace( IWbemServices* pWbemServices )
  671. {
  672. LPWSTR szNamespace = 0;
  673. if ( pWbemServices )
  674. {
  675. BSTR bstrClass = SysAllocString( L"RSOP_ScriptPolicySetting" );
  676. if ( bstrClass )
  677. {
  678. IEnumWbemClassObject *pEnum;
  679. HRESULT hr;
  680. hr = pWbemServices->CreateInstanceEnum( bstrClass,
  681. WBEM_FLAG_SHALLOW,
  682. 0,
  683. &pEnum );
  684. if ( SUCCEEDED ( hr ) )
  685. {
  686. IWbemClassObject *pInstance = 0;
  687. ULONG ulReturned = 1;
  688. hr = pEnum->Next( -1,
  689. 1,
  690. &pInstance,
  691. &ulReturned );
  692. if ( SUCCEEDED( hr ) )
  693. {
  694. BSTR bstrPath = SysAllocString( L"__PATH" );
  695. VARIANT var;
  696. VariantInit( &var );
  697. hr = pInstance->Get( bstrPath,
  698. 0L,
  699. &var,
  700. 0,
  701. 0 );
  702. if ( SUCCEEDED( hr ) )
  703. {
  704. szNamespace = wcschr( var.bstrVal, L':' );
  705. if ( szNamespace )
  706. {
  707. *szNamespace = 0;
  708. }
  709. szNamespace = (LPWSTR) LocalAlloc( LPTR, ( wcslen( var.bstrVal ) + 1 ) * sizeof(WCHAR) );
  710. if ( szNamespace )
  711. {
  712. wcscpy( szNamespace, var.bstrVal );
  713. }
  714. else
  715. {
  716. DebugMsg((DM_WARNING, TEXT("GetNamespace: failed to allocate memory, %d."), GetLastError() ));
  717. }
  718. VariantClear(&var);
  719. }
  720. else
  721. {
  722. DebugMsg((DM_WARNING, TEXT("GetNamespace: failed to get __PATH, %d."), hr ));
  723. }
  724. pInstance->Release();
  725. }
  726. else
  727. {
  728. DebugMsg((DM_WARNING, TEXT("GetNamespace: failed to get instance, %d."), hr ));
  729. }
  730. pEnum->Release();
  731. }
  732. else
  733. {
  734. DebugMsg((DM_WARNING, TEXT("GetNamespace: failed to enumerate instances, %d."), hr ));
  735. }
  736. SysFreeString( bstrClass );
  737. }
  738. else
  739. {
  740. DebugMsg((DM_WARNING, TEXT("GetNamespace: failed to allocate memory, %d."), GetLastError() ));
  741. }
  742. }
  743. else
  744. {
  745. DebugMsg((DM_WARNING, TEXT("GetNamespace: bad IWbemServices pointer.")));
  746. }
  747. return szNamespace;
  748. }