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.

2406 lines
52 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. ProvFact.cpp
  5. Abstract:
  6. History:
  7. --*/
  8. #include "PreComp.h"
  9. #include <typeinfo.h>
  10. #include <stdio.h>
  11. #include <Aclapi.h>
  12. #include <wbemint.h>
  13. #include <HelperFuncs.h>
  14. #include <Logging.h>
  15. #include <HelperFuncs.h>
  16. #include "CGlobals.h"
  17. #include "ProvRegDeCoupled.h"
  18. #include "DateTime.h"
  19. #include "OS.h"
  20. #include <scopeguard.h>
  21. /******************************************************************************
  22. *
  23. * Name:
  24. *
  25. *
  26. * Description:
  27. *
  28. *
  29. *****************************************************************************/
  30. HRESULT SetSecurity ( HKEY a_Key , DWORD a_Access )
  31. {
  32. if (!OS::secureOS_)
  33. return ERROR_SUCCESS;
  34. HRESULT t_Result = S_OK ;
  35. SID_IDENTIFIER_AUTHORITY t_NtAuthoritySid = SECURITY_NT_AUTHORITY ;
  36. PSID t_Administrator_Sid = NULL ;
  37. ACCESS_ALLOWED_ACE *t_Administrator_ACE = NULL ;
  38. DWORD t_Administrator_ACESize = 0 ;
  39. BOOL t_BoolResult = AllocateAndInitializeSid (
  40. & t_NtAuthoritySid ,
  41. 2 ,
  42. SECURITY_BUILTIN_DOMAIN_RID,
  43. DOMAIN_ALIAS_RID_ADMINS,
  44. 0,
  45. 0,
  46. 0,
  47. 0,
  48. 0,
  49. 0,
  50. & t_Administrator_Sid
  51. );
  52. if ( t_BoolResult )
  53. {
  54. DWORD t_SidLength = ::GetLengthSid ( t_Administrator_Sid );
  55. t_Administrator_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  56. t_Administrator_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_Administrator_ACESize ] ;
  57. if ( t_Administrator_ACE )
  58. {
  59. CopySid ( t_SidLength, (PSID) & t_Administrator_ACE->SidStart, t_Administrator_Sid ) ;
  60. t_Administrator_ACE->Mask = 0x1F01FF;
  61. t_Administrator_ACE->Header.AceType = 0 ;
  62. t_Administrator_ACE->Header.AceFlags = 3 ;
  63. t_Administrator_ACE->Header.AceSize = t_Administrator_ACESize ;
  64. }
  65. else
  66. {
  67. t_Result = WBEM_E_OUT_OF_MEMORY ;
  68. }
  69. }
  70. else
  71. {
  72. DWORD t_LastError = ::GetLastError();
  73. t_Result = WBEM_E_OUT_OF_MEMORY ;
  74. }
  75. PSID t_System_Sid = NULL ;
  76. ACCESS_ALLOWED_ACE *t_System_ACE = NULL ;
  77. DWORD t_System_ACESize = 0 ;
  78. t_BoolResult = AllocateAndInitializeSid (
  79. & t_NtAuthoritySid ,
  80. 1 ,
  81. SECURITY_LOCAL_SYSTEM_RID,
  82. 0,
  83. 0,
  84. 0,
  85. 0,
  86. 0,
  87. 0,
  88. 0,
  89. & t_System_Sid
  90. );
  91. if ( t_BoolResult )
  92. {
  93. DWORD t_SidLength = ::GetLengthSid ( t_System_Sid );
  94. t_System_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  95. t_System_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_System_ACESize ] ;
  96. if ( t_System_ACE )
  97. {
  98. CopySid ( t_SidLength, (PSID) & t_System_ACE->SidStart, t_System_Sid ) ;
  99. t_System_ACE->Mask = 0x1F01FF;
  100. t_System_ACE->Header.AceType = 0 ;
  101. t_System_ACE->Header.AceFlags = 3 ;
  102. t_System_ACE->Header.AceSize = t_System_ACESize ;
  103. }
  104. else
  105. {
  106. t_Result = WBEM_E_OUT_OF_MEMORY ;
  107. }
  108. }
  109. else
  110. {
  111. DWORD t_LastError = ::GetLastError();
  112. t_Result = WBEM_E_OUT_OF_MEMORY ;
  113. }
  114. PSID t_PowerUsers_Sid = NULL ;
  115. ACCESS_ALLOWED_ACE *t_PowerUsers_ACE = NULL ;
  116. DWORD t_PowerUsers_ACESize = 0 ;
  117. t_BoolResult = AllocateAndInitializeSid (
  118. & t_NtAuthoritySid ,
  119. 2 ,
  120. SECURITY_BUILTIN_DOMAIN_RID,
  121. DOMAIN_ALIAS_RID_POWER_USERS,
  122. 0,
  123. 0,
  124. 0,
  125. 0,
  126. 0,
  127. 0,
  128. & t_PowerUsers_Sid
  129. );
  130. if ( t_BoolResult )
  131. {
  132. DWORD t_SidLength = ::GetLengthSid ( t_PowerUsers_Sid );
  133. t_PowerUsers_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  134. t_PowerUsers_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_PowerUsers_ACESize ] ;
  135. if ( t_PowerUsers_ACE )
  136. {
  137. CopySid ( t_SidLength, (PSID) & t_PowerUsers_ACE->SidStart, t_PowerUsers_Sid ) ;
  138. t_PowerUsers_ACE->Mask = GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | DELETE ;
  139. t_PowerUsers_ACE->Header.AceType = 0 ;
  140. t_PowerUsers_ACE->Header.AceFlags = 3 ;
  141. t_PowerUsers_ACE->Header.AceSize = t_PowerUsers_ACESize ;
  142. }
  143. else
  144. {
  145. t_Result = WBEM_E_OUT_OF_MEMORY ;
  146. }
  147. }
  148. else
  149. {
  150. DWORD t_LastError = ::GetLastError();
  151. t_Result = WBEM_E_OUT_OF_MEMORY ;
  152. }
  153. SID_IDENTIFIER_AUTHORITY t_WorldAuthoritySid = SECURITY_WORLD_SID_AUTHORITY ;
  154. PSID t_Everyone_Sid = NULL ;
  155. ACCESS_ALLOWED_ACE *t_Everyone_ACE = NULL ;
  156. DWORD t_Everyone_ACESize = 0 ;
  157. t_BoolResult = AllocateAndInitializeSid (
  158. & t_WorldAuthoritySid ,
  159. 1 ,
  160. SECURITY_WORLD_RID ,
  161. 0,
  162. 0,
  163. 0,
  164. 0,
  165. 0,
  166. 0,
  167. 0,
  168. & t_Everyone_Sid
  169. );
  170. if ( t_BoolResult )
  171. {
  172. DWORD t_SidLength = ::GetLengthSid ( t_Everyone_Sid );
  173. t_Everyone_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  174. t_Everyone_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_Everyone_ACESize ] ;
  175. if ( t_Everyone_ACE )
  176. {
  177. CopySid ( t_SidLength, (PSID) & t_Everyone_ACE->SidStart, t_Everyone_Sid ) ;
  178. t_Everyone_ACE->Mask = a_Access ;
  179. t_Everyone_ACE->Header.AceType = 0 ;
  180. t_Everyone_ACE->Header.AceFlags = 3 ;
  181. t_Everyone_ACE->Header.AceSize = t_Everyone_ACESize ;
  182. }
  183. else
  184. {
  185. t_Result = WBEM_E_OUT_OF_MEMORY ;
  186. }
  187. }
  188. else
  189. {
  190. DWORD t_LastError = ::GetLastError();
  191. t_Result = WBEM_E_OUT_OF_MEMORY ;
  192. }
  193. // Now we need to set permissions on the registry: Everyone read; Admins full.
  194. // We have the sid for admins from the above code. Now get the sid for "Everyone"
  195. DWORD t_TotalAclSize = sizeof(ACL) + t_Administrator_ACESize + t_System_ACESize + t_Everyone_ACESize ;
  196. PACL t_Dacl = (PACL) new BYTE [ t_TotalAclSize ] ;
  197. if ( t_Dacl )
  198. {
  199. if ( :: InitializeAcl ( t_Dacl, t_TotalAclSize, ACL_REVISION ) )
  200. {
  201. DWORD t_AceIndex = 0 ;
  202. if ( t_Everyone_ACESize && :: AddAce ( t_Dacl , ACL_REVISION, t_AceIndex , t_Everyone_ACE , t_Everyone_ACESize ) )
  203. {
  204. t_AceIndex ++ ;
  205. }
  206. if ( t_System_ACESize && :: AddAce ( t_Dacl , ACL_REVISION , t_AceIndex , t_System_ACE , t_System_ACESize ) )
  207. {
  208. t_AceIndex ++ ;
  209. }
  210. if ( t_Administrator_ACESize && :: AddAce ( t_Dacl , ACL_REVISION , t_AceIndex , t_Administrator_ACE , t_Administrator_ACESize ) )
  211. {
  212. t_AceIndex ++ ;
  213. }
  214. SECURITY_INFORMATION t_SecurityInfo = 0L;
  215. t_SecurityInfo |= DACL_SECURITY_INFORMATION;
  216. t_SecurityInfo |= PROTECTED_DACL_SECURITY_INFORMATION;
  217. SECURITY_DESCRIPTOR t_SecurityDescriptor ;
  218. t_BoolResult = InitializeSecurityDescriptor ( & t_SecurityDescriptor , SECURITY_DESCRIPTOR_REVISION ) ;
  219. if ( t_BoolResult )
  220. {
  221. t_BoolResult = SetSecurityDescriptorDacl (
  222. & t_SecurityDescriptor ,
  223. TRUE ,
  224. t_Dacl ,
  225. FALSE
  226. ) ;
  227. if ( t_BoolResult )
  228. {
  229. LONG t_SetStatus = RegSetKeySecurity (
  230. a_Key ,
  231. t_SecurityInfo ,
  232. & t_SecurityDescriptor
  233. ) ;
  234. if ( t_SetStatus != ERROR_SUCCESS )
  235. {
  236. DWORD t_LastError = GetLastError () ;
  237. t_Result = WBEM_E_ACCESS_DENIED ;
  238. }
  239. }
  240. else
  241. {
  242. t_Result = WBEM_E_CRITICAL_ERROR ;
  243. }
  244. }
  245. else
  246. {
  247. t_Result = WBEM_E_CRITICAL_ERROR ;
  248. }
  249. }
  250. delete [] ( ( BYTE * ) t_Dacl ) ;
  251. }
  252. else
  253. {
  254. t_Result = WBEM_E_OUT_OF_MEMORY ;
  255. }
  256. if ( t_Administrator_ACE )
  257. {
  258. delete [] ( ( BYTE * ) t_Administrator_ACE ) ;
  259. }
  260. if ( t_PowerUsers_ACE )
  261. {
  262. delete [] ( ( BYTE * ) t_PowerUsers_ACE ) ;
  263. }
  264. if ( t_Everyone_ACE )
  265. {
  266. delete [] ( ( BYTE * ) t_Everyone_ACE ) ;
  267. }
  268. if ( t_System_ACE )
  269. {
  270. delete [] ( ( BYTE * ) t_System_ACE ) ;
  271. }
  272. if ( t_System_Sid )
  273. {
  274. FreeSid ( t_System_Sid ) ;
  275. }
  276. if ( t_Administrator_Sid )
  277. {
  278. FreeSid ( t_Administrator_Sid ) ;
  279. }
  280. if ( t_PowerUsers_Sid )
  281. {
  282. FreeSid ( t_PowerUsers_Sid ) ;
  283. }
  284. if ( t_Everyone_Sid )
  285. {
  286. FreeSid ( t_Everyone_Sid ) ;
  287. }
  288. return t_Result ;
  289. }
  290. HRESULT SetClientSecurity ( HKEY a_Key)
  291. {
  292. if (!OS::secureOS_)
  293. return ERROR_SUCCESS;
  294. HRESULT t_Result = S_OK ;
  295. SID_IDENTIFIER_AUTHORITY t_NtAuthoritySid = SECURITY_NT_AUTHORITY ;
  296. PSID t_Administrator_Sid = NULL ;
  297. ACCESS_ALLOWED_ACE *t_Administrator_ACE = NULL ;
  298. DWORD t_Administrator_ACESize = 0 ;
  299. BOOL t_BoolResult = AllocateAndInitializeSid (
  300. & t_NtAuthoritySid ,
  301. 2 ,
  302. SECURITY_BUILTIN_DOMAIN_RID,
  303. DOMAIN_ALIAS_RID_ADMINS,
  304. 0,
  305. 0,
  306. 0,
  307. 0,
  308. 0,
  309. 0,
  310. & t_Administrator_Sid
  311. );
  312. if ( t_BoolResult )
  313. {
  314. DWORD t_SidLength = ::GetLengthSid ( t_Administrator_Sid );
  315. t_Administrator_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  316. t_Administrator_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_Administrator_ACESize ] ;
  317. if ( t_Administrator_ACE )
  318. {
  319. CopySid ( t_SidLength, (PSID) & t_Administrator_ACE->SidStart, t_Administrator_Sid ) ;
  320. t_Administrator_ACE->Mask = 0x1F01FF;
  321. t_Administrator_ACE->Header.AceType = 0 ;
  322. t_Administrator_ACE->Header.AceFlags = 3 ;
  323. t_Administrator_ACE->Header.AceSize = t_Administrator_ACESize ;
  324. }
  325. else
  326. {
  327. t_Result = WBEM_E_OUT_OF_MEMORY ;
  328. }
  329. }
  330. else
  331. {
  332. DWORD t_LastError = ::GetLastError();
  333. t_Result = WBEM_E_OUT_OF_MEMORY ;
  334. }
  335. PSID t_System_Sid = NULL ;
  336. ACCESS_ALLOWED_ACE *t_System_ACE = NULL ;
  337. DWORD t_System_ACESize = 0 ;
  338. t_BoolResult = AllocateAndInitializeSid (
  339. & t_NtAuthoritySid ,
  340. 1 ,
  341. SECURITY_LOCAL_SYSTEM_RID,
  342. 0,
  343. 0,
  344. 0,
  345. 0,
  346. 0,
  347. 0,
  348. 0,
  349. & t_System_Sid
  350. );
  351. if ( t_BoolResult )
  352. {
  353. DWORD t_SidLength = ::GetLengthSid ( t_System_Sid );
  354. t_System_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  355. t_System_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_System_ACESize ] ;
  356. if ( t_System_ACE )
  357. {
  358. CopySid ( t_SidLength, (PSID) & t_System_ACE->SidStart, t_System_Sid ) ;
  359. t_System_ACE->Mask = 0x1F01FF;
  360. t_System_ACE->Header.AceType = 0 ;
  361. t_System_ACE->Header.AceFlags = 3 ;
  362. t_System_ACE->Header.AceSize = t_System_ACESize ;
  363. }
  364. else
  365. {
  366. t_Result = WBEM_E_OUT_OF_MEMORY ;
  367. }
  368. }
  369. else
  370. {
  371. DWORD t_LastError = ::GetLastError();
  372. t_Result = WBEM_E_OUT_OF_MEMORY ;
  373. }
  374. SID_IDENTIFIER_AUTHORITY t_WorldAuthoritySid = SECURITY_WORLD_SID_AUTHORITY ;
  375. PSID t_Everyone_Sid = NULL ;
  376. ACCESS_ALLOWED_ACE *t_Everyone_ACE = NULL ;
  377. DWORD t_Everyone_ACESize = 0 ;
  378. t_BoolResult = AllocateAndInitializeSid (
  379. & t_WorldAuthoritySid ,
  380. 1 ,
  381. SECURITY_WORLD_RID ,
  382. 0,
  383. 0,
  384. 0,
  385. 0,
  386. 0,
  387. 0,
  388. 0,
  389. & t_Everyone_Sid
  390. );
  391. if ( t_BoolResult )
  392. {
  393. DWORD t_SidLength = ::GetLengthSid ( t_Everyone_Sid );
  394. t_Everyone_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  395. t_Everyone_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_Everyone_ACESize ] ;
  396. if ( t_Everyone_ACE )
  397. {
  398. CopySid ( t_SidLength, (PSID) & t_Everyone_ACE->SidStart, t_Everyone_Sid ) ;
  399. t_Everyone_ACE->Mask = KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_SET_VALUE | READ_CONTROL | KEY_QUERY_VALUE ; // JeffCoop: added KEY_SET_VALUE | READ_CONTROL | KEY_QUERY_VALUE
  400. t_Everyone_ACE->Header.AceType = 0 ;
  401. t_Everyone_ACE->Header.AceFlags = 0 ; // JeffCoop: was '3' ;
  402. t_Everyone_ACE->Header.AceSize = t_Everyone_ACESize ;
  403. }
  404. else
  405. {
  406. t_Result = WBEM_E_OUT_OF_MEMORY ;
  407. }
  408. }
  409. else
  410. {
  411. DWORD t_LastError = ::GetLastError();
  412. t_Result = WBEM_E_OUT_OF_MEMORY ;
  413. }
  414. SID_IDENTIFIER_AUTHORITY t_OwnerAuthoritySid = SECURITY_CREATOR_SID_AUTHORITY;
  415. PSID t_Owner_Sid = NULL ;
  416. ACCESS_ALLOWED_ACE *t_Owner_ACE = NULL ;
  417. DWORD t_Owner_ACESize = 0 ;
  418. t_BoolResult = AllocateAndInitializeSid (
  419. & t_OwnerAuthoritySid ,
  420. 1 ,
  421. SECURITY_CREATOR_OWNER_RID ,
  422. 0,
  423. 0,
  424. 0,
  425. 0,
  426. 0,
  427. 0,
  428. 0,
  429. & t_Owner_Sid
  430. );
  431. if ( t_BoolResult )
  432. {
  433. DWORD t_SidLength = ::GetLengthSid ( t_Owner_Sid );
  434. t_Owner_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  435. t_Owner_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_Owner_ACESize ] ;
  436. if ( t_Owner_ACE )
  437. {
  438. CopySid ( t_SidLength, (PSID) & t_Owner_ACE->SidStart, t_Owner_Sid ) ;
  439. t_Owner_ACE->Mask = KEY_ALL_ACCESS ;
  440. t_Owner_ACE->Header.AceType = ACCESS_ALLOWED_ACE_TYPE ;
  441. t_Owner_ACE->Header.AceFlags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | NO_PROPAGATE_INHERIT_ACE | INHERIT_ONLY_ACE ; // JeffCoop: added NO_PROPAGATE_INHERIT_ACE | INHERIT_ONLY_ACE
  442. t_Owner_ACE->Header.AceSize = t_Owner_ACESize ;
  443. }
  444. else
  445. {
  446. t_Result = WBEM_E_OUT_OF_MEMORY ;
  447. }
  448. }
  449. else
  450. {
  451. DWORD t_LastError = ::GetLastError();
  452. t_Result = WBEM_E_OUT_OF_MEMORY ;
  453. }
  454. // Now we need to set permissions on the registry: Everyone read; Admins full.
  455. // We have the sid for admins from the above code. Now get the sid for "Everyone"
  456. DWORD t_TotalAclSize = sizeof(ACL) + t_Administrator_ACESize + t_Owner_ACESize + t_Everyone_ACESize + t_System_ACESize;
  457. PACL t_Dacl = (PACL) new BYTE [ t_TotalAclSize ] ;
  458. if ( t_Dacl )
  459. {
  460. if ( :: InitializeAcl ( t_Dacl, t_TotalAclSize, ACL_REVISION ) )
  461. {
  462. DWORD t_AceIndex = 0 ;
  463. if ( t_Everyone_ACESize && :: AddAce ( t_Dacl , ACL_REVISION, t_AceIndex , t_Everyone_ACE , t_Everyone_ACESize ) )
  464. {
  465. t_AceIndex ++ ;
  466. }
  467. if ( t_Owner_ACESize && :: AddAce ( t_Dacl , ACL_REVISION , t_AceIndex , t_Owner_ACE , t_Owner_ACESize ) )
  468. {
  469. t_AceIndex ++ ;
  470. }
  471. if ( t_Administrator_ACESize && :: AddAce ( t_Dacl , ACL_REVISION , t_AceIndex , t_Administrator_ACE , t_Administrator_ACESize ) )
  472. {
  473. t_AceIndex ++ ;
  474. }
  475. if ( t_Administrator_ACESize && :: AddAce ( t_Dacl , ACL_REVISION , t_AceIndex , t_System_ACE , t_System_ACESize ) )
  476. {
  477. t_AceIndex ++ ;
  478. }
  479. SECURITY_INFORMATION t_SecurityInfo = 0L;
  480. t_SecurityInfo |= DACL_SECURITY_INFORMATION;
  481. SECURITY_DESCRIPTOR t_SecurityDescriptor ;
  482. t_BoolResult = InitializeSecurityDescriptor ( & t_SecurityDescriptor , SECURITY_DESCRIPTOR_REVISION ) ;
  483. if ( t_BoolResult )
  484. {
  485. t_BoolResult = SetSecurityDescriptorDacl (
  486. & t_SecurityDescriptor ,
  487. TRUE ,
  488. t_Dacl ,
  489. FALSE
  490. ) ;
  491. if ( t_BoolResult )
  492. {
  493. LONG t_SetStatus = RegSetKeySecurity (
  494. a_Key ,
  495. t_SecurityInfo ,
  496. & t_SecurityDescriptor
  497. ) ;
  498. if ( t_SetStatus != ERROR_SUCCESS )
  499. {
  500. DWORD t_LastError = GetLastError () ;
  501. t_Result = WBEM_E_ACCESS_DENIED ;
  502. }
  503. }
  504. else
  505. {
  506. t_Result = WBEM_E_CRITICAL_ERROR ;
  507. }
  508. }
  509. else
  510. {
  511. t_Result = WBEM_E_CRITICAL_ERROR ;
  512. }
  513. }
  514. delete [] ( ( BYTE * ) t_Dacl ) ;
  515. }
  516. else
  517. {
  518. t_Result = WBEM_E_OUT_OF_MEMORY ;
  519. }
  520. if ( t_Administrator_ACE )
  521. {
  522. delete [] ( ( BYTE * ) t_Administrator_ACE ) ;
  523. }
  524. if (t_Owner_ACE) delete [] ((BYTE *)t_Owner_ACE);
  525. if (t_Owner_Sid) FreeSid (t_Owner_Sid);
  526. if ( t_Everyone_ACE )
  527. {
  528. delete [] ( ( BYTE * ) t_Everyone_ACE ) ;
  529. }
  530. if ( t_System_ACE )
  531. {
  532. delete [] ( ( BYTE * ) t_System_ACE ) ;
  533. }
  534. if ( t_System_Sid )
  535. {
  536. FreeSid ( t_System_Sid ) ;
  537. }
  538. if ( t_Administrator_Sid )
  539. {
  540. FreeSid ( t_Administrator_Sid ) ;
  541. }
  542. if ( t_Everyone_Sid )
  543. {
  544. FreeSid ( t_Everyone_Sid ) ;
  545. }
  546. return t_Result ;
  547. }
  548. /******************************************************************************
  549. *
  550. * Name:
  551. *
  552. *
  553. * Description:
  554. *
  555. *
  556. *****************************************************************************/
  557. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_Null = NULL ;
  558. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_Home = L"Software\\Microsoft\\Wbem\\Transports\\Decoupled" ;
  559. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_HomeClient = L"Software\\Microsoft\\Wbem\\Transports\\Decoupled\\Client" ;
  560. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_CreationTime = L"CreationTime" ;
  561. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_User = L"User" ;
  562. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_Locale = L"Locale" ;
  563. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_Scope = L"Scope" ;
  564. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_Provider = L"Provider" ;
  565. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_MarshaledProxy = L"MarshaledProxy" ;
  566. LPCWSTR CServerObject_DecoupledClientRegistration_Element :: s_Strings_Reg_ProcessIdentifier = L"ProcessIdentifier" ;
  567. LPCWSTR CServerObject_DecoupledClientRegistration :: s_Strings_Reg_Null = NULL ;
  568. LPCWSTR CServerObject_DecoupledClientRegistration :: s_Strings_Reg_Home = L"Software\\Microsoft\\Wbem\\Transports\\Decoupled" ;
  569. LPCWSTR CServerObject_DecoupledClientRegistration :: s_Strings_Reg_HomeClient = L"Software\\Microsoft\\Wbem\\Transports\\Decoupled\\Client" ;
  570. LPCWSTR CServerObject_DecoupledServerRegistration :: s_Strings_Reg_Null = NULL ;
  571. LPCWSTR CServerObject_DecoupledServerRegistration :: s_Strings_Reg_Home = L"Software\\Microsoft\\Wbem\\Transports\\Decoupled" ;
  572. LPCWSTR CServerObject_DecoupledServerRegistration :: s_Strings_Reg_HomeServer = L"Software\\Microsoft\\Wbem\\Transports\\Decoupled\\Server" ;
  573. LPCWSTR CServerObject_DecoupledServerRegistration :: s_Strings_Reg_CreationTime = L"CreationTime" ;
  574. LPCWSTR CServerObject_DecoupledServerRegistration :: s_Strings_Reg_ProcessIdentifier = L"ProcessIdentifier" ;
  575. LPCWSTR CServerObject_DecoupledServerRegistration :: s_Strings_Reg_MarshaledProxy = L"MarshaledProxy" ;
  576. /******************************************************************************
  577. *
  578. * Name:
  579. *
  580. *
  581. * Description:
  582. *
  583. *
  584. *****************************************************************************/
  585. CServerObject_DecoupledClientRegistration_Element :: CServerObject_DecoupledClientRegistration_Element ()
  586. : m_Provider ( NULL ) ,
  587. m_Clsid ( NULL ) ,
  588. m_CreationTime ( NULL ) ,
  589. m_User ( NULL ) ,
  590. m_Locale ( NULL ) ,
  591. m_Scope ( NULL ) ,
  592. m_MarshaledProxy ( NULL ) ,
  593. m_MarshaledProxyLength ( 0 ) ,
  594. m_Result ( S_OK ) ,
  595. m_ProcessIdentifier ( 0 ) ,
  596. m_ReferenceCount ( 0 )
  597. {
  598. }
  599. /******************************************************************************
  600. *
  601. * Name:
  602. *
  603. *
  604. * Description:
  605. *
  606. *
  607. *****************************************************************************/
  608. CServerObject_DecoupledClientRegistration_Element :: ~CServerObject_DecoupledClientRegistration_Element ()
  609. {
  610. Clear () ;
  611. }
  612. /******************************************************************************
  613. *
  614. * Name:
  615. *
  616. *
  617. * Description:
  618. *
  619. *
  620. *****************************************************************************/
  621. void CServerObject_DecoupledClientRegistration_Element :: Clear ()
  622. {
  623. if ( m_Provider )
  624. {
  625. SysFreeString ( m_Provider ) ;
  626. m_Provider = NULL ;
  627. }
  628. if ( m_CreationTime )
  629. {
  630. SysFreeString ( m_CreationTime ) ;
  631. m_CreationTime = NULL ;
  632. }
  633. if ( m_User )
  634. {
  635. SysFreeString ( m_User ) ;
  636. m_User = NULL ;
  637. }
  638. if ( m_Locale )
  639. {
  640. SysFreeString ( m_Locale ) ;
  641. m_Locale = NULL ;
  642. }
  643. if ( m_Scope )
  644. {
  645. SysFreeString ( m_Scope ) ;
  646. m_Scope = NULL ;
  647. }
  648. if ( m_Clsid )
  649. {
  650. SysFreeString ( m_Clsid ) ;
  651. m_Clsid = NULL ;
  652. }
  653. if ( m_MarshaledProxy )
  654. {
  655. delete [] m_MarshaledProxy ;
  656. m_MarshaledProxy = NULL ;
  657. }
  658. }
  659. /******************************************************************************
  660. *
  661. * Name:
  662. *
  663. *
  664. * Description:
  665. *
  666. *
  667. *****************************************************************************/
  668. CServerObject_DecoupledClientRegistration_Element &CServerObject_DecoupledClientRegistration_Element :: operator= ( const CServerObject_DecoupledClientRegistration_Element &a_Key )
  669. {
  670. if ( m_Provider )
  671. {
  672. SysFreeString ( m_Provider ) ;
  673. m_Provider = NULL ;
  674. }
  675. if ( m_CreationTime )
  676. {
  677. SysFreeString ( m_CreationTime ) ;
  678. m_CreationTime = NULL ;
  679. }
  680. if ( m_User )
  681. {
  682. SysFreeString ( m_User ) ;
  683. m_User = NULL ;
  684. }
  685. if ( m_Locale )
  686. {
  687. SysFreeString ( m_Locale ) ;
  688. m_Locale = NULL ;
  689. }
  690. if ( m_Scope )
  691. {
  692. SysFreeString ( m_Scope ) ;
  693. m_Scope = NULL ;
  694. }
  695. if ( m_Clsid )
  696. {
  697. SysFreeString ( m_Clsid ) ;
  698. m_Clsid = NULL ;
  699. }
  700. if ( m_MarshaledProxy )
  701. {
  702. delete [] m_MarshaledProxy ;
  703. m_MarshaledProxy = NULL ;
  704. }
  705. if ( a_Key.m_Provider )
  706. {
  707. m_Provider = SysAllocString ( a_Key.m_Provider ) ;
  708. }
  709. if ( a_Key.m_CreationTime )
  710. {
  711. m_CreationTime = SysAllocString ( a_Key.m_CreationTime ) ;
  712. }
  713. if ( a_Key.m_User )
  714. {
  715. m_User = SysAllocString ( a_Key.m_User ) ;
  716. }
  717. if ( a_Key.m_Locale )
  718. {
  719. m_Locale = SysAllocString ( a_Key.m_Locale ) ;
  720. }
  721. if ( a_Key.m_Scope )
  722. {
  723. m_Scope = SysAllocString ( a_Key.m_Scope ) ;
  724. }
  725. if ( a_Key.m_Clsid )
  726. {
  727. m_Clsid = SysAllocString ( a_Key.m_Clsid ) ;
  728. }
  729. m_MarshaledProxyLength = a_Key.m_MarshaledProxyLength ;
  730. if ( a_Key.m_MarshaledProxy )
  731. {
  732. m_MarshaledProxy = new BYTE [ a_Key.m_MarshaledProxyLength ] ;
  733. if ( m_MarshaledProxy )
  734. {
  735. CopyMemory ( m_MarshaledProxy , a_Key.m_MarshaledProxy , a_Key.m_MarshaledProxyLength ) ;
  736. }
  737. }
  738. return *this ;
  739. }
  740. /******************************************************************************
  741. *
  742. * Name:
  743. *
  744. *
  745. * Description:
  746. *
  747. *
  748. *****************************************************************************/
  749. HRESULT CServerObject_DecoupledClientRegistration_Element :: SetProcessIdentifier ( DWORD a_ProcessIdentifier )
  750. {
  751. m_ProcessIdentifier = a_ProcessIdentifier ;
  752. return S_OK ;
  753. }
  754. /******************************************************************************
  755. *
  756. * Name:
  757. *
  758. *
  759. * Description:
  760. *
  761. *
  762. *****************************************************************************/
  763. HRESULT CServerObject_DecoupledClientRegistration_Element :: SetProvider ( BSTR a_Provider )
  764. {
  765. HRESULT t_Result = S_OK ;
  766. if ( m_Provider )
  767. {
  768. SysFreeString ( m_Provider ) ;
  769. }
  770. m_Provider = SysAllocString ( a_Provider ) ;
  771. if ( m_Provider == NULL )
  772. {
  773. t_Result = WBEM_E_OUT_OF_MEMORY ;
  774. }
  775. return t_Result ;
  776. }
  777. /******************************************************************************
  778. *
  779. * Name:
  780. *
  781. *
  782. * Description:
  783. *
  784. *
  785. *****************************************************************************/
  786. HRESULT CServerObject_DecoupledClientRegistration_Element :: SetLocale ( BSTR a_Locale )
  787. {
  788. HRESULT t_Result = S_OK ;
  789. if ( m_Locale )
  790. {
  791. SysFreeString ( m_Locale ) ;
  792. }
  793. m_Locale = SysAllocString ( a_Locale ) ;
  794. if ( m_Locale == NULL )
  795. {
  796. t_Result = WBEM_E_OUT_OF_MEMORY ;
  797. }
  798. return t_Result ;
  799. }
  800. /******************************************************************************
  801. *
  802. * Name:
  803. *
  804. *
  805. * Description:
  806. *
  807. *
  808. *****************************************************************************/
  809. HRESULT CServerObject_DecoupledClientRegistration_Element :: SetUser ( BSTR a_User )
  810. {
  811. HRESULT t_Result = S_OK ;
  812. if ( m_User )
  813. {
  814. SysFreeString ( m_User ) ;
  815. }
  816. m_User = SysAllocString ( a_User ) ;
  817. if ( m_User == NULL )
  818. {
  819. t_Result = WBEM_E_OUT_OF_MEMORY ;
  820. }
  821. return t_Result ;
  822. }
  823. /******************************************************************************
  824. *
  825. * Name:
  826. *
  827. *
  828. * Description:
  829. *
  830. *
  831. *****************************************************************************/
  832. HRESULT CServerObject_DecoupledClientRegistration_Element :: SetScope ( BSTR a_Scope )
  833. {
  834. HRESULT t_Result = S_OK ;
  835. if ( m_Scope )
  836. {
  837. SysFreeString ( m_Scope ) ;
  838. }
  839. m_Scope = SysAllocString ( a_Scope ) ;
  840. if ( m_Scope == NULL )
  841. {
  842. t_Result = WBEM_E_OUT_OF_MEMORY ;
  843. }
  844. return t_Result ;
  845. }
  846. /******************************************************************************
  847. *
  848. * Name:
  849. *
  850. *
  851. * Description:
  852. *
  853. *
  854. *****************************************************************************/
  855. HRESULT CServerObject_DecoupledClientRegistration_Element :: SetCreationTime ( BSTR a_CreationTime )
  856. {
  857. HRESULT t_Result = S_OK ;
  858. if ( m_CreationTime )
  859. {
  860. SysFreeString ( m_CreationTime ) ;
  861. }
  862. m_CreationTime = SysAllocString ( a_CreationTime ) ;
  863. if ( m_CreationTime == NULL )
  864. {
  865. t_Result = WBEM_E_OUT_OF_MEMORY ;
  866. }
  867. return t_Result ;
  868. }
  869. /******************************************************************************
  870. *
  871. * Name:
  872. *
  873. *
  874. * Description:
  875. *
  876. *
  877. *****************************************************************************/
  878. HRESULT CServerObject_DecoupledClientRegistration_Element :: SetClsid ( BSTR a_Clsid )
  879. {
  880. HRESULT t_Result = S_OK ;
  881. if ( m_Clsid )
  882. {
  883. SysFreeString ( m_Clsid ) ;
  884. }
  885. m_Clsid = SysAllocString ( a_Clsid ) ;
  886. if ( m_Clsid == NULL )
  887. {
  888. t_Result = WBEM_E_OUT_OF_MEMORY ;
  889. }
  890. return t_Result ;
  891. }
  892. /******************************************************************************
  893. *
  894. * Name:
  895. *
  896. *
  897. * Description:
  898. *
  899. *
  900. *****************************************************************************/
  901. HRESULT CServerObject_DecoupledClientRegistration_Element :: SetMarshaledProxy ( BYTE *a_MarshaledProxy , ULONG a_MarshaledProxyLength )
  902. {
  903. HRESULT t_Result = S_OK ;
  904. if ( m_MarshaledProxy )
  905. {
  906. delete [] m_MarshaledProxy ;
  907. }
  908. m_MarshaledProxyLength = a_MarshaledProxyLength ;
  909. m_MarshaledProxy = new BYTE [ a_MarshaledProxyLength ] ;
  910. if ( m_MarshaledProxy )
  911. {
  912. CopyMemory ( m_MarshaledProxy , a_MarshaledProxy , a_MarshaledProxyLength ) ;
  913. }
  914. else
  915. {
  916. t_Result = WBEM_E_OUT_OF_MEMORY ;
  917. }
  918. return t_Result ;
  919. }
  920. /******************************************************************************
  921. *
  922. * Name:
  923. *
  924. *
  925. * Description:
  926. *
  927. *
  928. *****************************************************************************/
  929. ULONG CServerObject_DecoupledClientRegistration_Element :: AddRef ()
  930. {
  931. return InterlockedIncrement ( & m_ReferenceCount ) ;
  932. }
  933. /******************************************************************************
  934. *
  935. * Name:
  936. *
  937. *
  938. * Description:
  939. *
  940. *
  941. *****************************************************************************/
  942. ULONG CServerObject_DecoupledClientRegistration_Element :: Release ()
  943. {
  944. ULONG t_ReferenceCount = InterlockedDecrement ( & m_ReferenceCount ) ;
  945. if ( t_ReferenceCount == 0 )
  946. {
  947. delete this ;
  948. }
  949. return t_ReferenceCount ;
  950. }
  951. /******************************************************************************
  952. *
  953. * Name:
  954. *
  955. *
  956. * Description:
  957. *
  958. *
  959. *****************************************************************************/
  960. HRESULT CServerObject_DecoupledClientRegistration_Element :: Validate ()
  961. {
  962. CWbemDateTime t_CreationTime ;
  963. HRESULT t_Result = t_CreationTime.PutValue ( m_CreationTime ) ;
  964. if ( SUCCEEDED ( t_Result ) )
  965. {
  966. HANDLE t_Handle = OpenProcess (
  967. PROCESS_QUERY_INFORMATION ,
  968. FALSE ,
  969. m_ProcessIdentifier
  970. ) ;
  971. if ( t_Handle )
  972. {
  973. FILETIME t_CreationFileTime ;
  974. FILETIME t_ExitFileTime ;
  975. FILETIME t_KernelFileTime ;
  976. FILETIME t_UserFileTime ;
  977. BOOL t_Status = OS::GetProcessTimes (
  978. t_Handle ,
  979. & t_CreationFileTime,
  980. & t_ExitFileTime,
  981. & t_KernelFileTime,
  982. & t_UserFileTime
  983. ) ;
  984. if ( t_Status )
  985. {
  986. CWbemDateTime t_Time ;
  987. t_Time.SetFileTimeDate ( t_CreationFileTime , VARIANT_FALSE ) ;
  988. if ( t_CreationTime.Preceeds ( t_Time ) )
  989. {
  990. t_Result = WBEM_E_NOT_FOUND ;
  991. }
  992. }
  993. CloseHandle ( t_Handle ) ;
  994. }
  995. else
  996. {
  997. t_Result = WBEM_E_NOT_FOUND ;
  998. }
  999. }
  1000. return t_Result ;
  1001. }
  1002. /******************************************************************************
  1003. *
  1004. * Name:
  1005. *
  1006. *
  1007. * Description:
  1008. *
  1009. *
  1010. *****************************************************************************/
  1011. HRESULT CServerObject_DecoupledClientRegistration_Element :: Load ( BSTR a_Clsid )
  1012. {
  1013. HRESULT t_Result = S_OK ;
  1014. Clear () ;
  1015. t_Result = SetClsid ( a_Clsid ) ;
  1016. if ( SUCCEEDED ( t_Result ) )
  1017. {
  1018. LPWSTR t_HomeClientClsid_String = NULL ;
  1019. t_Result = WmiHelper :: ConcatenateStrings (
  1020. 3,
  1021. & t_HomeClientClsid_String ,
  1022. s_Strings_Reg_HomeClient ,
  1023. L"\\" ,
  1024. a_Clsid
  1025. ) ;
  1026. if ( SUCCEEDED ( t_Result ) )
  1027. {
  1028. HKEY t_HomeClientClsid_Key ;
  1029. LONG t_RegResult = OS::RegOpenKeyEx (
  1030. HKEY_LOCAL_MACHINE ,
  1031. t_HomeClientClsid_String ,
  1032. 0 ,
  1033. KEY_READ ,
  1034. & t_HomeClientClsid_Key
  1035. ) ;
  1036. if ( t_RegResult == ERROR_SUCCESS )
  1037. {
  1038. t_Result = ProviderSubSystem_Common_Globals :: Load_String ( t_HomeClientClsid_Key , s_Strings_Reg_CreationTime , m_CreationTime ) ;
  1039. if ( SUCCEEDED ( t_Result ) )
  1040. {
  1041. t_Result = ProviderSubSystem_Common_Globals :: Load_String ( t_HomeClientClsid_Key , s_Strings_Reg_Provider , m_Provider ) ;
  1042. }
  1043. if ( SUCCEEDED ( t_Result ) )
  1044. {
  1045. t_Result = ProviderSubSystem_Common_Globals :: Load_String ( t_HomeClientClsid_Key , s_Strings_Reg_Scope , m_Scope ) ;
  1046. }
  1047. if ( SUCCEEDED ( t_Result ) )
  1048. {
  1049. t_Result = ProviderSubSystem_Common_Globals :: Load_String ( t_HomeClientClsid_Key , s_Strings_Reg_Locale , m_Locale ) ;
  1050. if ( t_Result == ERROR_FILE_NOT_FOUND )
  1051. {
  1052. t_Result = S_OK ;
  1053. }
  1054. }
  1055. if ( SUCCEEDED ( t_Result ) )
  1056. {
  1057. t_Result = ProviderSubSystem_Common_Globals :: Load_String ( t_HomeClientClsid_Key , s_Strings_Reg_User , m_User ) ;
  1058. if ( t_Result == ERROR_FILE_NOT_FOUND )
  1059. {
  1060. t_Result = S_OK ;
  1061. }
  1062. }
  1063. if ( SUCCEEDED ( t_Result ) )
  1064. {
  1065. t_Result = ProviderSubSystem_Common_Globals :: Load_ByteArray ( t_HomeClientClsid_Key , s_Strings_Reg_MarshaledProxy , m_MarshaledProxy , m_MarshaledProxyLength ) ;
  1066. }
  1067. if ( SUCCEEDED ( t_Result ) )
  1068. {
  1069. t_Result = ProviderSubSystem_Common_Globals :: Load_DWORD ( t_HomeClientClsid_Key , s_Strings_Reg_ProcessIdentifier , m_ProcessIdentifier ) ;
  1070. }
  1071. if ( SUCCEEDED ( t_Result ) )
  1072. {
  1073. t_Result = Validate () ;
  1074. }
  1075. RegCloseKey ( t_HomeClientClsid_Key ) ;
  1076. }
  1077. else
  1078. {
  1079. t_Result = WBEM_E_NOT_FOUND ;
  1080. }
  1081. SysFreeString ( t_HomeClientClsid_String ) ;
  1082. }
  1083. }
  1084. else
  1085. {
  1086. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1087. }
  1088. if ( FAILED ( t_Result ) )
  1089. {
  1090. Delete ( a_Clsid ) ;
  1091. }
  1092. return t_Result ;
  1093. }
  1094. HRESULT
  1095. CServerObject_DecoupledClientRegistration_Element::VerifyClientKey(void)
  1096. {
  1097. HKEY key;
  1098. DWORD t_Disposition = 0 ;
  1099. LONG t_RegResult = OS::RegCreateKeyEx (
  1100. HKEY_LOCAL_MACHINE ,
  1101. s_Strings_Reg_HomeClient ,
  1102. 0 ,
  1103. NULL ,
  1104. 0 ,
  1105. KEY_ALL_ACCESS,
  1106. NULL ,
  1107. & key ,
  1108. & t_Disposition
  1109. ) ;
  1110. if (t_RegResult!=ERROR_SUCCESS) return HRESULT_FROM_WIN32(t_RegResult);
  1111. SetClientSecurity(key);
  1112. RegCloseKey(key);
  1113. return S_OK;
  1114. }
  1115. /******************************************************************************
  1116. *
  1117. * Name:
  1118. *
  1119. *
  1120. * Description:
  1121. *
  1122. *
  1123. *****************************************************************************/
  1124. HRESULT CServerObject_DecoupledClientRegistration_Element :: Save ( BSTR a_Clsid )
  1125. {
  1126. HRESULT t_Result = S_OK ;
  1127. t_Result = SetClsid ( a_Clsid ) ;
  1128. if ( SUCCEEDED ( t_Result ) )
  1129. {
  1130. LPWSTR t_HomeClientClsid_String = NULL ;
  1131. t_Result = WmiHelper :: ConcatenateStrings (
  1132. 2,
  1133. & t_HomeClientClsid_String ,
  1134. s_Strings_Reg_HomeClient ,
  1135. m_Clsid
  1136. ) ;
  1137. if ( SUCCEEDED ( t_Result ) )
  1138. {
  1139. HKEY t_HomeClient_Key ;
  1140. DWORD t_Disposition = 0 ;
  1141. LONG t_RegResult = OS::RegCreateKeyEx (
  1142. HKEY_LOCAL_MACHINE ,
  1143. s_Strings_Reg_HomeClient ,
  1144. 0 ,
  1145. NULL ,
  1146. 0 ,
  1147. KEY_WRITE,
  1148. NULL ,
  1149. &t_HomeClient_Key ,
  1150. & t_Disposition
  1151. ) ;
  1152. if ( t_RegResult == ERROR_SUCCESS )
  1153. {
  1154. HKEY t_HomeClientClsid_Key ;
  1155. LONG t_RegResult = OS::RegCreateKeyEx (
  1156. t_HomeClient_Key ,
  1157. m_Clsid ,
  1158. 0 ,
  1159. NULL ,
  1160. REG_OPTION_VOLATILE ,
  1161. KEY_WRITE ,
  1162. NULL ,
  1163. & t_HomeClientClsid_Key ,
  1164. & t_Disposition
  1165. ) ;
  1166. if ( t_RegResult == ERROR_SUCCESS )
  1167. {
  1168. t_Result = SetSecurity ( t_HomeClientClsid_Key , KEY_READ ) ;
  1169. if ( t_Disposition == REG_CREATED_NEW_KEY )
  1170. {
  1171. t_Result = ProviderSubSystem_Common_Globals :: Save_String ( t_HomeClientClsid_Key , s_Strings_Reg_CreationTime , m_CreationTime ) ;
  1172. if ( SUCCEEDED ( t_Result ) )
  1173. {
  1174. t_Result = ProviderSubSystem_Common_Globals :: Save_String ( t_HomeClientClsid_Key , s_Strings_Reg_Provider , m_Provider ) ;
  1175. }
  1176. if ( SUCCEEDED ( t_Result ) )
  1177. {
  1178. t_Result = ProviderSubSystem_Common_Globals :: Save_String ( t_HomeClientClsid_Key , s_Strings_Reg_Scope , m_Scope ) ;
  1179. }
  1180. if ( SUCCEEDED ( t_Result ) )
  1181. {
  1182. if ( m_Locale )
  1183. {
  1184. t_Result = ProviderSubSystem_Common_Globals :: Save_String ( t_HomeClientClsid_Key , s_Strings_Reg_Locale , m_Locale ) ;
  1185. }
  1186. }
  1187. if ( SUCCEEDED ( t_Result ) )
  1188. {
  1189. if ( m_User )
  1190. {
  1191. t_Result = ProviderSubSystem_Common_Globals :: Save_String ( t_HomeClientClsid_Key , s_Strings_Reg_User , m_User ) ;
  1192. }
  1193. }
  1194. if ( SUCCEEDED ( t_Result ) )
  1195. {
  1196. t_Result = ProviderSubSystem_Common_Globals :: Save_ByteArray ( t_HomeClientClsid_Key , s_Strings_Reg_MarshaledProxy , m_MarshaledProxy , m_MarshaledProxyLength ) ;
  1197. }
  1198. if ( SUCCEEDED ( t_Result ) )
  1199. {
  1200. t_Result = ProviderSubSystem_Common_Globals :: Save_DWORD ( t_HomeClientClsid_Key , s_Strings_Reg_ProcessIdentifier , m_ProcessIdentifier ) ;
  1201. }
  1202. }
  1203. else
  1204. {
  1205. t_Result = WBEM_E_ALREADY_EXISTS ;
  1206. }
  1207. RegCloseKey ( t_HomeClientClsid_Key ) ;
  1208. }
  1209. RegCloseKey ( t_HomeClient_Key ) ;
  1210. }
  1211. SysFreeString ( t_HomeClientClsid_String ) ;
  1212. }
  1213. }
  1214. else
  1215. {
  1216. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1217. }
  1218. return t_Result ;
  1219. }
  1220. /******************************************************************************
  1221. *
  1222. * Name:
  1223. *
  1224. *
  1225. * Description:
  1226. *
  1227. *
  1228. *****************************************************************************/
  1229. HRESULT CServerObject_DecoupledClientRegistration_Element :: Delete ( BSTR a_Clsid )
  1230. {
  1231. HRESULT t_Result = S_OK ;
  1232. LPWSTR t_HomeClientClsid_String = NULL ;
  1233. t_Result = WmiHelper :: ConcatenateStrings (
  1234. 3,
  1235. & t_HomeClientClsid_String ,
  1236. s_Strings_Reg_HomeClient ,
  1237. L"\\" ,
  1238. a_Clsid
  1239. ) ;
  1240. if ( SUCCEEDED ( t_Result ) )
  1241. {
  1242. HKEY t_HomeClientClsid_Key ;
  1243. LONG t_RegResult = OS::RegOpenKeyEx (
  1244. HKEY_LOCAL_MACHINE ,
  1245. t_HomeClientClsid_String ,
  1246. 0 ,
  1247. KEY_READ ,
  1248. & t_HomeClientClsid_Key
  1249. ) ;
  1250. if ( t_RegResult == ERROR_SUCCESS )
  1251. {
  1252. BYTE *t_MarshaledProxy = NULL ;
  1253. ULONG t_MarshaledProxyLength = 0 ;
  1254. t_Result = ProviderSubSystem_Common_Globals :: Load_ByteArray (
  1255. t_HomeClientClsid_Key ,
  1256. s_Strings_Reg_MarshaledProxy ,
  1257. t_MarshaledProxy ,
  1258. t_MarshaledProxyLength
  1259. ) ;
  1260. if ( SUCCEEDED ( t_Result ) )
  1261. {
  1262. t_Result = ProviderSubSystem_Common_Globals :: ReleaseRegistration (
  1263. t_MarshaledProxy ,
  1264. t_MarshaledProxyLength
  1265. ) ;
  1266. if ( t_MarshaledProxy )
  1267. {
  1268. delete [] t_MarshaledProxy ;
  1269. }
  1270. }
  1271. RegCloseKey ( t_HomeClientClsid_Key ) ;
  1272. }
  1273. t_RegResult = OS::RegDeleteKey (
  1274. HKEY_LOCAL_MACHINE ,
  1275. t_HomeClientClsid_String
  1276. ) ;
  1277. if ( t_RegResult != ERROR_SUCCESS )
  1278. {
  1279. t_Result = WBEM_E_ACCESS_DENIED ;
  1280. }
  1281. SysFreeString ( t_HomeClientClsid_String ) ;
  1282. }
  1283. return t_Result ;
  1284. }
  1285. /******************************************************************************
  1286. *
  1287. * Name:
  1288. *
  1289. *
  1290. * Description:
  1291. *
  1292. *
  1293. *****************************************************************************/
  1294. CServerObject_DecoupledClientRegistration :: CServerObject_DecoupledClientRegistration (
  1295. WmiAllocator &a_Allocator
  1296. ) : m_Queue ( a_Allocator )
  1297. {
  1298. }
  1299. /******************************************************************************
  1300. *
  1301. * Name:
  1302. *
  1303. *
  1304. * Description:
  1305. *
  1306. *
  1307. *****************************************************************************/
  1308. CServerObject_DecoupledClientRegistration :: ~CServerObject_DecoupledClientRegistration ()
  1309. {
  1310. m_Queue.UnInitialize () ;
  1311. }
  1312. /******************************************************************************
  1313. *
  1314. * Name:
  1315. *
  1316. *
  1317. * Description:
  1318. *
  1319. *
  1320. *****************************************************************************/
  1321. ULONG CServerObject_DecoupledClientRegistration :: AddRef ()
  1322. {
  1323. return InterlockedIncrement ( & m_ReferenceCount ) ;
  1324. }
  1325. /******************************************************************************
  1326. *
  1327. * Name:
  1328. *
  1329. *
  1330. * Description:
  1331. *
  1332. *
  1333. *****************************************************************************/
  1334. ULONG CServerObject_DecoupledClientRegistration :: Release ()
  1335. {
  1336. ULONG t_ReferenceCount = InterlockedDecrement ( & m_ReferenceCount ) ;
  1337. if ( t_ReferenceCount == 0 )
  1338. {
  1339. delete this ;
  1340. }
  1341. return t_ReferenceCount ;
  1342. }
  1343. /******************************************************************************
  1344. *
  1345. * Name:
  1346. *
  1347. *
  1348. * Description:
  1349. *
  1350. *
  1351. *****************************************************************************/
  1352. HRESULT CServerObject_DecoupledClientRegistration :: Load ()
  1353. {
  1354. HRESULT t_Result = S_OK ;
  1355. HKEY t_HomeClient_Key ;
  1356. LONG t_RegResult = OS::RegOpenKeyEx (
  1357. HKEY_LOCAL_MACHINE ,
  1358. s_Strings_Reg_HomeClient ,
  1359. 0 ,
  1360. KEY_READ ,
  1361. & t_HomeClient_Key
  1362. ) ;
  1363. if ( t_RegResult == ERROR_SUCCESS )
  1364. {
  1365. DWORD t_Count = 0 ;
  1366. DWORD t_Size = 16 ;
  1367. BSTR *t_Elements = ( BSTR * ) malloc ( sizeof ( BSTR ) * t_Size ) ;
  1368. if ( t_Elements )
  1369. {
  1370. FILETIME t_FileTime ;
  1371. DWORD t_Class ;
  1372. BOOL t_Continue = TRUE ;
  1373. while ( SUCCEEDED ( t_Result ) && t_Continue )
  1374. {
  1375. DWORD t_NameLength = 256 ;
  1376. wchar_t t_Name [ 256 ] ;
  1377. LONG t_RegResult = OS::RegEnumKeyEx (
  1378. t_HomeClient_Key ,
  1379. t_Count ,
  1380. t_Name ,
  1381. & t_NameLength , // size of subkey buffer
  1382. NULL ,
  1383. NULL ,
  1384. NULL ,
  1385. & t_FileTime
  1386. ) ;
  1387. if ( t_RegResult == ERROR_SUCCESS )
  1388. {
  1389. if ( t_Count >= t_Size )
  1390. {
  1391. BSTR *t_NewElements = ( BSTR * ) realloc ( t_Elements , sizeof ( BSTR ) * ( t_Size + 16 ) ) ;
  1392. if ( t_NewElements )
  1393. {
  1394. t_Elements = t_NewElements ;
  1395. t_Size = t_Size + 16 ;
  1396. }
  1397. else
  1398. {
  1399. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1400. }
  1401. }
  1402. if ( SUCCEEDED ( t_Result ) )
  1403. {
  1404. t_Elements [ t_Count ] = SysAllocString ( t_Name ) ;
  1405. if ( t_Elements [ t_Count ] )
  1406. {
  1407. t_Count ++ ;
  1408. }
  1409. else
  1410. {
  1411. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1412. }
  1413. }
  1414. }
  1415. else if ( t_RegResult == ERROR_NO_MORE_ITEMS )
  1416. {
  1417. t_Continue = FALSE ;
  1418. }
  1419. else
  1420. {
  1421. t_Continue = FALSE ;
  1422. // Generate message
  1423. }
  1424. }
  1425. if ( t_Elements )
  1426. {
  1427. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  1428. {
  1429. if ( t_Elements [ t_Index ] )
  1430. {
  1431. CServerObject_DecoupledClientRegistration_Element t_Element ;
  1432. HRESULT t_TempResult = t_Element.Load ( t_Elements [ t_Index ] ) ;
  1433. if ( SUCCEEDED ( t_TempResult ) )
  1434. {
  1435. m_Queue.EnQueue ( t_Element ) ;
  1436. }
  1437. else
  1438. {
  1439. // Generate message
  1440. }
  1441. SysFreeString ( t_Elements [ t_Index ] ) ;
  1442. }
  1443. }
  1444. free ( t_Elements ) ;
  1445. }
  1446. }
  1447. else
  1448. {
  1449. }
  1450. RegCloseKey ( t_HomeClient_Key ) ;
  1451. }
  1452. else
  1453. {
  1454. t_Result = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_WIN32,t_RegResult);
  1455. }
  1456. return t_Result ;
  1457. }
  1458. /******************************************************************************
  1459. *
  1460. * Name:
  1461. *
  1462. *
  1463. * Description:
  1464. *
  1465. *
  1466. *****************************************************************************/
  1467. HRESULT CServerObject_DecoupledClientRegistration :: Load (
  1468. BSTR a_Provider ,
  1469. BSTR a_User ,
  1470. BSTR a_Locale ,
  1471. BSTR a_Scope
  1472. )
  1473. {
  1474. HRESULT t_Result = S_OK ;
  1475. HKEY t_HomeClient_Key ;
  1476. LONG t_RegResult = OS::RegOpenKeyEx (
  1477. HKEY_LOCAL_MACHINE ,
  1478. s_Strings_Reg_HomeClient ,
  1479. 0 ,
  1480. KEY_READ ,
  1481. & t_HomeClient_Key
  1482. ) ;
  1483. if ( t_RegResult == ERROR_SUCCESS )
  1484. {
  1485. DWORD t_Index = 0 ;
  1486. FILETIME t_FileTime ;
  1487. DWORD t_Class ;
  1488. BOOL t_Continue = TRUE ;
  1489. while ( SUCCEEDED ( t_Result ) && t_Continue )
  1490. {
  1491. DWORD t_NameLength = 256 ;
  1492. wchar_t t_Name [ 256 ] ;
  1493. LONG t_RegResult = OS::RegEnumKeyEx (
  1494. t_HomeClient_Key ,
  1495. t_Index ,
  1496. t_Name ,
  1497. & t_NameLength , // size of subkey buffer
  1498. NULL ,
  1499. NULL ,
  1500. NULL ,
  1501. & t_FileTime
  1502. ) ;
  1503. if ( t_RegResult == ERROR_SUCCESS )
  1504. {
  1505. CServerObject_DecoupledClientRegistration_Element t_Element ;
  1506. HRESULT t_TempResult = t_Element.Load ( t_Name ) ;
  1507. if ( SUCCEEDED ( t_TempResult ) )
  1508. {
  1509. BOOL t_Compare = ( wbem_wcsicmp ( a_Provider , t_Element.GetProvider () ) == 0 ) ;
  1510. t_Compare = t_Compare && ( wbem_wcsicmp ( a_Scope , t_Element.GetScope () ) == 0 ) ;
  1511. if ( t_Compare )
  1512. {
  1513. if ( ( a_Locale == NULL ) && ( t_Element.GetLocale () == NULL ) )
  1514. {
  1515. }
  1516. else
  1517. {
  1518. if ( ( a_Locale ) && ( t_Element.GetLocale () ) )
  1519. {
  1520. t_Compare = ( wbem_wcsicmp ( a_Locale , t_Element.GetLocale () ) == 0 ) ;
  1521. }
  1522. else
  1523. {
  1524. t_Compare = FALSE ;
  1525. }
  1526. }
  1527. }
  1528. if ( t_Compare )
  1529. {
  1530. if ( ( a_User == NULL ) && ( t_Element.GetUser () == NULL ) )
  1531. {
  1532. }
  1533. else
  1534. {
  1535. if ( ( a_User ) && ( t_Element.GetUser () ) )
  1536. {
  1537. t_Compare = ( wbem_wcsicmp ( a_User , t_Element.GetUser () ) == 0 ) ;
  1538. }
  1539. else
  1540. {
  1541. t_Compare = FALSE ;
  1542. }
  1543. }
  1544. }
  1545. if ( t_Compare )
  1546. {
  1547. m_Queue.EnQueue ( t_Element ) ;
  1548. }
  1549. }
  1550. else
  1551. {
  1552. // Generate message
  1553. }
  1554. }
  1555. else if ( t_RegResult == ERROR_NO_MORE_ITEMS )
  1556. {
  1557. t_Continue = FALSE ;
  1558. }
  1559. else
  1560. {
  1561. t_Continue = FALSE ;
  1562. // Generate message
  1563. }
  1564. t_Index ++ ;
  1565. }
  1566. RegCloseKey ( t_HomeClient_Key ) ;
  1567. }
  1568. else
  1569. {
  1570. t_Result = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_WIN32,t_RegResult);
  1571. }
  1572. return t_Result ;
  1573. }
  1574. /******************************************************************************
  1575. *
  1576. * Name:
  1577. *
  1578. *
  1579. * Description:
  1580. *
  1581. *
  1582. *****************************************************************************/
  1583. CServerObject_DecoupledServerRegistration :: CServerObject_DecoupledServerRegistration ( WmiAllocator &a_Allocator )
  1584. : m_CreationTime ( NULL ) ,
  1585. m_MarshaledProxy ( NULL ) ,
  1586. m_MarshaledProxyLength ( 0 ) ,
  1587. m_Result ( S_OK ) ,
  1588. m_ProcessIdentifier ( 0 )
  1589. {
  1590. }
  1591. /******************************************************************************
  1592. *
  1593. * Name:
  1594. *
  1595. *
  1596. * Description:
  1597. *
  1598. *
  1599. *****************************************************************************/
  1600. CServerObject_DecoupledServerRegistration :: ~CServerObject_DecoupledServerRegistration ()
  1601. {
  1602. Clear () ;
  1603. }
  1604. /******************************************************************************
  1605. *
  1606. * Name:
  1607. *
  1608. *
  1609. * Description:
  1610. *
  1611. *
  1612. *****************************************************************************/
  1613. void CServerObject_DecoupledServerRegistration :: Clear ()
  1614. {
  1615. if ( m_CreationTime )
  1616. {
  1617. SysFreeString ( m_CreationTime ) ;
  1618. m_CreationTime = NULL ;
  1619. }
  1620. if ( m_MarshaledProxy )
  1621. {
  1622. delete [] m_MarshaledProxy ;
  1623. m_MarshaledProxy = NULL ;
  1624. }
  1625. }
  1626. /******************************************************************************
  1627. *
  1628. * Name:
  1629. *
  1630. *
  1631. * Description:
  1632. *
  1633. *
  1634. *****************************************************************************/
  1635. ULONG CServerObject_DecoupledServerRegistration :: AddRef ()
  1636. {
  1637. return InterlockedIncrement ( & m_ReferenceCount ) ;
  1638. }
  1639. /******************************************************************************
  1640. *
  1641. * Name:
  1642. *
  1643. *
  1644. * Description:
  1645. *
  1646. *
  1647. *****************************************************************************/
  1648. ULONG CServerObject_DecoupledServerRegistration :: Release ()
  1649. {
  1650. ULONG t_ReferenceCount = InterlockedDecrement ( & m_ReferenceCount ) ;
  1651. if ( t_ReferenceCount == 0 )
  1652. {
  1653. delete this ;
  1654. }
  1655. return t_ReferenceCount ;
  1656. }
  1657. /******************************************************************************
  1658. *
  1659. * Name:
  1660. *
  1661. *
  1662. * Description:
  1663. *
  1664. *
  1665. *****************************************************************************/
  1666. HRESULT CServerObject_DecoupledServerRegistration :: Validate ()
  1667. {
  1668. CWbemDateTime t_CreationTime ;
  1669. HRESULT t_Result = t_CreationTime.PutValue ( m_CreationTime ) ;
  1670. if ( SUCCEEDED ( t_Result ) )
  1671. {
  1672. HANDLE t_Handle = OpenProcess (
  1673. PROCESS_QUERY_INFORMATION ,
  1674. FALSE ,
  1675. m_ProcessIdentifier
  1676. ) ;
  1677. if ( t_Handle )
  1678. {
  1679. FILETIME t_CreationFileTime ;
  1680. FILETIME t_ExitFileTime ;
  1681. FILETIME t_KernelFileTime ;
  1682. FILETIME t_UserFileTime ;
  1683. BOOL t_Status = OS::GetProcessTimes (
  1684. t_Handle ,
  1685. & t_CreationFileTime,
  1686. & t_ExitFileTime,
  1687. & t_KernelFileTime,
  1688. & t_UserFileTime
  1689. ) ;
  1690. if ( t_Status )
  1691. {
  1692. CWbemDateTime t_Time ;
  1693. t_Time.SetFileTimeDate ( t_CreationFileTime , VARIANT_FALSE ) ;
  1694. if ( t_CreationTime.Preceeds ( t_Time ) )
  1695. {
  1696. t_Result = WBEM_E_NOT_FOUND ;
  1697. }
  1698. }
  1699. CloseHandle ( t_Handle ) ;
  1700. }
  1701. else if(GetLastError() == ERROR_ACCESS_DENIED)
  1702. {
  1703. // Expected if this process is runned as low right user
  1704. t_Result = S_OK;
  1705. } else
  1706. {
  1707. t_Result = WBEM_E_NOT_FOUND;
  1708. }
  1709. }
  1710. return t_Result ;
  1711. }
  1712. /******************************************************************************
  1713. *
  1714. * Name:
  1715. *
  1716. *
  1717. * Description:
  1718. *
  1719. *
  1720. *****************************************************************************/
  1721. HRESULT CServerObject_DecoupledServerRegistration :: Load ()
  1722. {
  1723. HRESULT t_Result = S_OK ;
  1724. Clear () ;
  1725. HKEY t_HomeServerClsid_Key ;
  1726. LONG t_RegResult = OS::RegOpenKeyEx (
  1727. HKEY_LOCAL_MACHINE ,
  1728. s_Strings_Reg_HomeServer ,
  1729. 0 ,
  1730. KEY_READ ,
  1731. & t_HomeServerClsid_Key
  1732. ) ;
  1733. if ( t_RegResult == ERROR_SUCCESS )
  1734. {
  1735. ON_BLOCK_EXIT(RegCloseKey, t_HomeServerClsid_Key);
  1736. if (OS::secureOS_)
  1737. {
  1738. SECURITY_INFORMATION t_SecurityInformation = OWNER_SECURITY_INFORMATION ;
  1739. SECURITY_DESCRIPTOR *t_SecurityDescriptor = NULL ;
  1740. DWORD t_Length = 0 ;
  1741. t_RegResult = RegGetKeySecurity (
  1742. t_HomeServerClsid_Key ,
  1743. t_SecurityInformation ,
  1744. t_SecurityDescriptor ,
  1745. & t_Length
  1746. ) ;
  1747. if ( t_RegResult == ERROR_INSUFFICIENT_BUFFER )
  1748. {
  1749. t_SecurityDescriptor = ( SECURITY_DESCRIPTOR * ) new BYTE [ t_Length ] ;
  1750. if ( t_SecurityDescriptor )
  1751. {
  1752. t_RegResult = RegGetKeySecurity (
  1753. t_HomeServerClsid_Key ,
  1754. t_SecurityInformation ,
  1755. t_SecurityDescriptor ,
  1756. & t_Length
  1757. ) ;
  1758. if ( t_RegResult == ERROR_SUCCESS )
  1759. {
  1760. SID *t_Sid = NULL ;
  1761. BOOL t_Defaulted = FALSE ;
  1762. BOOL t_Status = GetSecurityDescriptorOwner (
  1763. t_SecurityDescriptor ,
  1764. ( PSID * ) & t_Sid ,
  1765. & t_Defaulted
  1766. ) ;
  1767. if ( t_Status )
  1768. {
  1769. SID_IDENTIFIER_AUTHORITY t_NtAuthoritySid = SECURITY_NT_AUTHORITY ;
  1770. PSID t_Administrator_Sid = NULL ;
  1771. BOOL t_BoolResult = AllocateAndInitializeSid (
  1772. & t_NtAuthoritySid ,
  1773. 2 ,
  1774. SECURITY_BUILTIN_DOMAIN_RID,
  1775. DOMAIN_ALIAS_RID_ADMINS,
  1776. 0,
  1777. 0,
  1778. 0,
  1779. 0,
  1780. 0,
  1781. 0,
  1782. & t_Administrator_Sid
  1783. );
  1784. if ( t_BoolResult )
  1785. {
  1786. if ( EqualSid ( t_Administrator_Sid , t_Sid ) == FALSE )
  1787. {
  1788. t_Result = WBEM_E_ACCESS_DENIED ;
  1789. }
  1790. if ( t_Administrator_Sid )
  1791. {
  1792. FreeSid ( t_Administrator_Sid ) ;
  1793. }
  1794. }
  1795. else
  1796. {
  1797. t_Result = WBEM_E_CRITICAL_ERROR ;
  1798. }
  1799. }
  1800. else
  1801. {
  1802. t_Result = WBEM_E_CRITICAL_ERROR ;
  1803. }
  1804. }
  1805. else
  1806. {
  1807. t_Result = WBEM_E_CRITICAL_ERROR ;
  1808. }
  1809. delete [] ( BYTE * ) t_SecurityDescriptor ;
  1810. }
  1811. }
  1812. else
  1813. {
  1814. t_Result = WBEM_E_CRITICAL_ERROR ;
  1815. }
  1816. }
  1817. if ( SUCCEEDED ( t_Result ) )
  1818. {
  1819. t_Result = ProviderSubSystem_Common_Globals :: Load_String ( t_HomeServerClsid_Key , s_Strings_Reg_CreationTime , m_CreationTime ) ;
  1820. }
  1821. if ( SUCCEEDED ( t_Result ) )
  1822. {
  1823. t_Result = ProviderSubSystem_Common_Globals :: Load_ByteArray ( t_HomeServerClsid_Key , s_Strings_Reg_MarshaledProxy , m_MarshaledProxy , m_MarshaledProxyLength ) ;
  1824. }
  1825. if ( SUCCEEDED ( t_Result ) )
  1826. {
  1827. t_Result = ProviderSubSystem_Common_Globals :: Load_DWORD ( t_HomeServerClsid_Key , s_Strings_Reg_ProcessIdentifier , m_ProcessIdentifier ) ;
  1828. }
  1829. if ( SUCCEEDED ( t_Result ) )
  1830. {
  1831. t_Result = Validate () ;
  1832. }
  1833. }
  1834. else
  1835. {
  1836. t_Result = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_WIN32,t_RegResult);
  1837. }
  1838. return t_Result ;
  1839. }
  1840. /******************************************************************************
  1841. *
  1842. * Name:
  1843. *
  1844. *
  1845. * Description:
  1846. *
  1847. *
  1848. *****************************************************************************/
  1849. HRESULT CServerObject_DecoupledServerRegistration :: SetCreationTime ( BSTR a_CreationTime )
  1850. {
  1851. HRESULT t_Result = S_OK ;
  1852. if ( m_CreationTime )
  1853. {
  1854. SysFreeString ( m_CreationTime ) ;
  1855. }
  1856. m_CreationTime = SysAllocString ( a_CreationTime ) ;
  1857. if ( m_CreationTime == NULL )
  1858. {
  1859. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1860. }
  1861. return t_Result ;
  1862. }
  1863. /******************************************************************************
  1864. *
  1865. * Name:
  1866. *
  1867. *
  1868. * Description:
  1869. *
  1870. *
  1871. *****************************************************************************/
  1872. HRESULT CServerObject_DecoupledServerRegistration :: SetProcessIdentifier ( DWORD a_ProcessIdentifier )
  1873. {
  1874. m_ProcessIdentifier = a_ProcessIdentifier ;
  1875. return S_OK ;
  1876. }
  1877. /******************************************************************************
  1878. *
  1879. * Name:
  1880. *
  1881. *
  1882. * Description:
  1883. *
  1884. *
  1885. *****************************************************************************/
  1886. HRESULT CServerObject_DecoupledServerRegistration :: SetMarshaledProxy ( BYTE *a_MarshaledProxy , ULONG a_MarshaledProxyLength )
  1887. {
  1888. HRESULT t_Result = S_OK ;
  1889. if ( m_MarshaledProxy )
  1890. {
  1891. delete [] m_MarshaledProxy ;
  1892. }
  1893. m_MarshaledProxyLength = a_MarshaledProxyLength ;
  1894. m_MarshaledProxy = new BYTE [ a_MarshaledProxyLength ] ;
  1895. if ( m_MarshaledProxy )
  1896. {
  1897. CopyMemory ( m_MarshaledProxy , a_MarshaledProxy , a_MarshaledProxyLength ) ;
  1898. }
  1899. else
  1900. {
  1901. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1902. }
  1903. return t_Result ;
  1904. }
  1905. /******************************************************************************
  1906. *
  1907. * Name:
  1908. *
  1909. *
  1910. * Description:
  1911. *
  1912. *
  1913. *****************************************************************************/
  1914. HRESULT CServerObject_DecoupledServerRegistration :: Save ()
  1915. {
  1916. HRESULT t_Result = S_OK ;
  1917. HKEY t_HomeServer_Key ;
  1918. DWORD t_Disposition = 0 ;
  1919. LONG t_RegResult = OS::RegCreateKeyEx (
  1920. HKEY_LOCAL_MACHINE ,
  1921. s_Strings_Reg_HomeServer ,
  1922. 0 ,
  1923. NULL ,
  1924. REG_OPTION_VOLATILE ,
  1925. KEY_WRITE ,
  1926. NULL ,
  1927. & t_HomeServer_Key ,
  1928. & t_Disposition
  1929. ) ;
  1930. if ( t_RegResult == ERROR_SUCCESS )
  1931. {
  1932. HRESULT t_TempResult = SetSecurity ( t_HomeServer_Key , KEY_READ ) ;
  1933. t_Result = ProviderSubSystem_Common_Globals :: Save_String ( t_HomeServer_Key , s_Strings_Reg_CreationTime , m_CreationTime ) ;
  1934. if ( SUCCEEDED ( t_Result ) )
  1935. {
  1936. t_Result = ProviderSubSystem_Common_Globals :: Save_ByteArray ( t_HomeServer_Key , s_Strings_Reg_MarshaledProxy , m_MarshaledProxy , m_MarshaledProxyLength ) ;
  1937. }
  1938. if ( SUCCEEDED ( t_Result ) )
  1939. {
  1940. t_Result = ProviderSubSystem_Common_Globals :: Save_DWORD ( t_HomeServer_Key , s_Strings_Reg_ProcessIdentifier , m_ProcessIdentifier ) ;
  1941. }
  1942. RegCloseKey ( t_HomeServer_Key ) ;
  1943. }
  1944. else
  1945. {
  1946. t_Result = WBEM_E_CRITICAL_ERROR ;
  1947. }
  1948. return t_Result ;
  1949. }
  1950. /******************************************************************************
  1951. *
  1952. * Name:
  1953. *
  1954. *
  1955. * Description:
  1956. *
  1957. *
  1958. *****************************************************************************/
  1959. HRESULT CServerObject_DecoupledServerRegistration :: Delete ()
  1960. {
  1961. HRESULT t_Result = S_OK ;
  1962. HKEY t_HomeServerClsid_Key ;
  1963. LONG t_RegResult = OS::RegOpenKeyEx (
  1964. HKEY_LOCAL_MACHINE ,
  1965. s_Strings_Reg_HomeServer ,
  1966. 0 ,
  1967. KEY_READ ,
  1968. & t_HomeServerClsid_Key
  1969. ) ;
  1970. if ( t_RegResult == ERROR_SUCCESS )
  1971. {
  1972. ON_BLOCK_EXIT(RegCloseKey, t_HomeServerClsid_Key);
  1973. BYTE *t_MarshaledProxy = NULL ;
  1974. ULONG t_MarshaledProxyLength = 0 ;
  1975. t_Result = ProviderSubSystem_Common_Globals :: Load_ByteArray (
  1976. t_HomeServerClsid_Key ,
  1977. s_Strings_Reg_MarshaledProxy ,
  1978. t_MarshaledProxy ,
  1979. t_MarshaledProxyLength
  1980. ) ;
  1981. if ( SUCCEEDED ( t_Result ) )
  1982. {
  1983. t_Result = ProviderSubSystem_Common_Globals :: ReleaseRegistration (
  1984. t_MarshaledProxy ,
  1985. t_MarshaledProxyLength
  1986. ) ;
  1987. if ( t_MarshaledProxy )
  1988. {
  1989. delete [] t_MarshaledProxy ;
  1990. }
  1991. }
  1992. }
  1993. t_RegResult = OS::RegDeleteKey (
  1994. HKEY_LOCAL_MACHINE ,
  1995. s_Strings_Reg_HomeServer
  1996. ) ;
  1997. if ( t_RegResult != ERROR_SUCCESS )
  1998. {
  1999. t_Result = WBEM_E_ACCESS_DENIED ;
  2000. }
  2001. return t_Result ;
  2002. }