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.

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