Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2298 lines
66 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: wmihooks.cpp
  7. //
  8. // Contents: implementation of CWMIRsop
  9. //
  10. //----------------------------------------------------------------------------
  11. #include <stdafx.h>
  12. #include <wmihooks.h>
  13. #include "util.h"
  14. WCHAR const QUERY_LANG[] = L"WQL";
  15. WCHAR const WMI_CLASS[] = L"__CLASS";
  16. WCHAR const RSOP_NAME_SPACE[] = L"root\\rsop\\computer";
  17. WCHAR const RSOP_PREC_ONE_QUERY[] = L"select * from RSOP_SecuritySettings where precedence=1";
  18. WCHAR const RSOP_ALL_QUERY[] = L"select * from RSOP_SecuritySettings";
  19. WCHAR const RSOP_STATUS[] = L"Status";
  20. WCHAR const RSOP_ERROR[] = L"ErrorCode";
  21. WCHAR const RSOP_PRECEDENCE[] = L"precedence";
  22. WCHAR const RSOP_GPOID[] = L"GPOID";
  23. WCHAR const RSOP_KEYNAME[] = L"KeyName";
  24. WCHAR const RSOP_SETTING[] = L"Setting";
  25. WCHAR const RSOP_USERRIGHT[] = L"UserRight";
  26. WCHAR const RSOP_ACCOUNTLIST[] = L"AccountList";
  27. WCHAR const RSOP_EVENTLOG_TYPE[] = L"Type";
  28. //String Constants for RSOP_classNames
  29. WCHAR const RSOP_SEC_NUM[] = TEXT("RSOP_SecuritySettingNumeric");
  30. WCHAR const RSOP_SEC_BOOL[] = TEXT("RSOP_SecuritySettingBoolean");
  31. WCHAR const RSOP_SCE_STRING[] = TEXT("RSOP_SecuritySettingString");
  32. WCHAR const RSOP_AUDIT[] = TEXT("RSOP_AuditPolicy");
  33. WCHAR const RSOP_EVENT_NUM[] = TEXT("RSOP_SecurityEventLogSettingNumeric");
  34. WCHAR const RSOP_EVENT_BOOL[] = TEXT("RSOP_SecurityEventLogSettingBoolean");
  35. WCHAR const RSOP_REG_VAL[] = TEXT("RSOP_RegistryValue");
  36. WCHAR const RSOP_USER_RIGHT[] = TEXT("RSOP_UserPrivilegeRight");
  37. WCHAR const RSOP_RGROUPS[] = TEXT("RSOP_RestrictedGroup");
  38. WCHAR const RSOP_SERVICE[] = TEXT("RSOP_SystemService");
  39. WCHAR const RSOP_FILE[] = TEXT("RSOP_File");
  40. WCHAR const RSOP_REG[] = TEXT("RSOP_RegistryKey");
  41. //KeyNames
  42. WCHAR const MIN_PASS_AGE[] = TEXT("MinimumPasswordAge");
  43. WCHAR const MAX_PASS_AGE[] = TEXT("MaximumPasswordAge");
  44. WCHAR const MIN_PASS_LEN[] = TEXT("MinimumPasswordLength");
  45. WCHAR const PASS_HIS_SIZE[] = TEXT("PasswordHistorySize");
  46. WCHAR const REQUIRE_LOGON_TO_CHANGE_PASS[] = TEXT("RequireLogonToChangePassword");
  47. WCHAR const LOCKOUT_COUNT[] = TEXT("LockoutBadCount");
  48. WCHAR const RESET_LOCKOUT_COUNT[] = TEXT("ResetLockoutCount");
  49. WCHAR const LOCKOUT_DURATION[] = TEXT("LockoutDuration");
  50. WCHAR const MAX_TICKET_AGE[] = TEXT("MaxTicketAge");
  51. WCHAR const MAX_RENEW_AGE[] = TEXT("MaxRenewAge");
  52. WCHAR const MAX_SERVICE_AGE[] = TEXT("MaxServiceAge");
  53. WCHAR const MAX_CLOCK_SKEW[] = TEXT("MaxClockSkew");
  54. WCHAR const VALIDATE_CLIENT[] = TEXT("TicketValidateClient");
  55. WCHAR const PASS_COMPLEX[] = TEXT("PasswordComplexity");
  56. WCHAR const FORCE_LOGOFF[] = TEXT("ForceLogOffWhenHourExpire");
  57. WCHAR const ENABLE_ADMIN[] = TEXT("EnableAdminAccount");
  58. WCHAR const ENABLE_GUEST[] = TEXT("EnableGuestAccount");
  59. WCHAR const LSA_ANON_LOOKUP[] = TEXT("LSAAnonymousNameLookup");
  60. WCHAR const CLEAR_TEXT_PASS[] = TEXT("ClearTextPassword");
  61. WCHAR const AUDIT_SYSTEM_EVENTS[] = TEXT("AuditSystemEvents");
  62. WCHAR const AUDIT_LOGON_EVENTS[] = TEXT("AuditLogonEvents");
  63. WCHAR const AUDIT_OBJECT_ACCESS[] = TEXT("AuditObjectAccess");
  64. WCHAR const AUDIT_PRIVILEGE_USE[] = TEXT("AuditPrivilegeUse");
  65. WCHAR const AUDIT_POLICY_CHANGE[] = TEXT("AuditPolicyChange");
  66. WCHAR const AUDIT_ACCOUNT_MANAGE[] = TEXT("AuditAccountManage");
  67. WCHAR const AUDIT_PROCESS_TRAKING[] = TEXT("AuditProcessTracking");
  68. WCHAR const AUDIT_DS_ACCESS[] = TEXT("AuditDSAccess");
  69. WCHAR const AUDIT_ACCOUNT_LOGON[] = TEXT("AuditAccountLogon");
  70. WCHAR const MAX_LOG_SIZE[] = TEXT("MaximumLogSize");
  71. WCHAR const AUDIT_LOG_RETENTION_PERIOD[] = TEXT ("AuditLogRetentionPeriod");
  72. WCHAR const RETENTION_DAYS[] = TEXT ("RetentionDays");
  73. WCHAR const RESTRICT_GUEST_ACCESS[] = TEXT ("RestrictGuestAccess");
  74. WCHAR const NEW_GUEST_NAME[] = TEXT ("NewGuestName");
  75. WCHAR const NEW_ADMINISTRATOR_NAME[] = TEXT ("NewAdministratorName");
  76. VOID FreeRI(PRSOP_INFO ptr)
  77. {
  78. if(ptr)
  79. {
  80. if(ptr->pszGPOID)
  81. LocalFree(ptr->pszGPOID);
  82. LocalFree(ptr);
  83. }
  84. }
  85. VOID InitWMI_SEC_PROFILE_INFO(PWMI_SCE_PROFILE_INFO pProfileInfo)
  86. {
  87. memset(pProfileInfo,0,sizeof(SCE_PROFILE_INFO));
  88. pProfileInfo->MinimumPasswordAge = SCE_NO_VALUE;
  89. pProfileInfo->MaximumPasswordAge = SCE_NO_VALUE;
  90. pProfileInfo->MinimumPasswordLength = SCE_NO_VALUE;
  91. pProfileInfo->PasswordComplexity = SCE_NO_VALUE;
  92. pProfileInfo->PasswordHistorySize = SCE_NO_VALUE;
  93. pProfileInfo->LockoutBadCount = SCE_NO_VALUE;
  94. pProfileInfo->ResetLockoutCount = SCE_NO_VALUE;
  95. pProfileInfo->LockoutDuration = SCE_NO_VALUE;
  96. pProfileInfo->RequireLogonToChangePassword = SCE_NO_VALUE;
  97. pProfileInfo->ForceLogoffWhenHourExpire = SCE_NO_VALUE;
  98. pProfileInfo->NewAdministratorName = 0;
  99. pProfileInfo->NewGuestName = 0;
  100. pProfileInfo->EnableAdminAccount = SCE_NO_VALUE;
  101. pProfileInfo->EnableGuestAccount = SCE_NO_VALUE;
  102. pProfileInfo->LSAAnonymousNameLookup = SCE_NO_VALUE;
  103. pProfileInfo->ClearTextPassword = SCE_NO_VALUE;
  104. pProfileInfo->AuditDSAccess = SCE_NO_VALUE;
  105. pProfileInfo->AuditAccountLogon = SCE_NO_VALUE;
  106. pProfileInfo->MaximumLogSize[0] = SCE_NO_VALUE;
  107. pProfileInfo->MaximumLogSize[1] = SCE_NO_VALUE;
  108. pProfileInfo->MaximumLogSize[2] = SCE_NO_VALUE;
  109. pProfileInfo->AuditLogRetentionPeriod[0] = SCE_NO_VALUE;
  110. pProfileInfo->AuditLogRetentionPeriod[1] = SCE_NO_VALUE;
  111. pProfileInfo->AuditLogRetentionPeriod[2] = SCE_NO_VALUE;
  112. pProfileInfo->RetentionDays[0] = SCE_NO_VALUE;
  113. pProfileInfo->RetentionDays[1] = SCE_NO_VALUE;
  114. pProfileInfo->RetentionDays[2] = SCE_NO_VALUE;
  115. pProfileInfo->RestrictGuestAccess[0] = SCE_NO_VALUE;
  116. pProfileInfo->RestrictGuestAccess[1] = SCE_NO_VALUE;
  117. pProfileInfo->RestrictGuestAccess[2] = SCE_NO_VALUE;
  118. pProfileInfo->AuditSystemEvents = SCE_NO_VALUE;
  119. pProfileInfo->AuditLogonEvents = SCE_NO_VALUE;
  120. pProfileInfo->AuditObjectAccess = SCE_NO_VALUE;
  121. pProfileInfo->AuditPrivilegeUse = SCE_NO_VALUE;
  122. pProfileInfo->AuditPolicyChange = SCE_NO_VALUE;
  123. pProfileInfo->AuditAccountManage = SCE_NO_VALUE;
  124. pProfileInfo->AuditProcessTracking = SCE_NO_VALUE;
  125. pProfileInfo->pInfo=NULL;
  126. pProfileInfo->pRIMinimumPasswordAge=NULL;
  127. pProfileInfo->pRIMaximumPasswordAge=NULL;
  128. pProfileInfo->pRIMinimumPasswordLength=NULL;
  129. pProfileInfo->pRIPasswordComplexity=NULL;
  130. pProfileInfo->pRIPasswordHistorySize=NULL;
  131. pProfileInfo->pRILockoutBadCount=NULL;
  132. pProfileInfo->pRIResetLockoutCount=NULL;
  133. pProfileInfo->pRILockoutDuration=NULL;
  134. pProfileInfo->pRIRequireLogonToChangePassword=NULL;
  135. pProfileInfo->pRIForceLogoffWhenHourExpire=NULL;
  136. pProfileInfo->pRIEnableAdminAccount=NULL;
  137. pProfileInfo->pRIEnableGuestAccount=NULL;
  138. pProfileInfo->pRILSAAnonymousNameLookup=NULL;
  139. pProfileInfo->pRINewAdministratorName=NULL;
  140. pProfileInfo->pRINewGuestName=NULL;
  141. pProfileInfo->pRIClearTextPassword=NULL;
  142. pProfileInfo->pRIMaxTicketAge=NULL;
  143. pProfileInfo->pRIMaxRenewAge=NULL;
  144. pProfileInfo->pRIMaxServiceAge=NULL;
  145. pProfileInfo->pRIMaxClockSkew=NULL;
  146. pProfileInfo->pRITicketValidateClient=NULL;
  147. pProfileInfo->pRIAuditSystemEvents=NULL;
  148. pProfileInfo->pRIAuditLogonEvents=NULL;
  149. pProfileInfo->pRIAuditObjectAccess=NULL;
  150. pProfileInfo->pRIAuditPrivilegeUse=NULL;
  151. pProfileInfo->pRIAuditPolicyChange=NULL;
  152. pProfileInfo->pRIAuditAccountManage=NULL;
  153. pProfileInfo->pRIAuditProcessTracking=NULL;
  154. pProfileInfo->pRIAuditDSAccess=NULL;
  155. pProfileInfo->pRIAuditAccountLogon=NULL;
  156. pProfileInfo->pRIMaximumLogSize[0]=NULL;
  157. pProfileInfo->pRIMaximumLogSize[1]=NULL;
  158. pProfileInfo->pRIMaximumLogSize[2]=NULL;
  159. pProfileInfo->pRIAuditLogRetentionPeriod[0]=NULL;
  160. pProfileInfo->pRIAuditLogRetentionPeriod[1]=NULL;
  161. pProfileInfo->pRIAuditLogRetentionPeriod[2]=NULL;
  162. pProfileInfo->pRIRetentionDays[0]=NULL;
  163. pProfileInfo->pRIRetentionDays[1]=NULL;
  164. pProfileInfo->pRIRetentionDays[2]=NULL;
  165. pProfileInfo->pRIRestrictGuestAccess[0]=NULL;
  166. pProfileInfo->pRIRestrictGuestAccess[1]=NULL;
  167. pProfileInfo->pRIRestrictGuestAccess[2]=NULL;
  168. }
  169. VOID FreeList(list<PRSOP_INFO> * li)
  170. {
  171. for(list<PRSOP_INFO>::iterator i = li->begin();
  172. i != li->end();
  173. ++i )
  174. {
  175. FreeRI(*i);
  176. }
  177. li->erase(li->begin(),li->end());
  178. }
  179. VOID FreeVector(vector<PRSOP_INFO> * li)
  180. {
  181. for(vector<PRSOP_INFO>::iterator i = li->begin();
  182. i != li->end();
  183. ++i )
  184. {
  185. FreeRI(*i);
  186. }
  187. li->erase(li->begin(),li->end());
  188. }
  189. VOID FreeWMI_SCE_PROFILE_INFO(PWMI_SCE_PROFILE_INFO pProfileInfo)
  190. {
  191. if (!pProfileInfo) {
  192. return;
  193. }
  194. //TODO
  195. //Use the code to Free SCE_PROFILE_INFO
  196. FreeRI(pProfileInfo->pInfo);
  197. FreeRI(pProfileInfo->pRIMinimumPasswordAge);
  198. FreeRI(pProfileInfo->pRIMaximumPasswordAge);
  199. FreeRI(pProfileInfo->pRIMinimumPasswordLength);
  200. FreeRI(pProfileInfo->pRIPasswordComplexity);
  201. FreeRI(pProfileInfo->pRIPasswordHistorySize);
  202. FreeRI(pProfileInfo->pRILockoutBadCount);
  203. FreeRI(pProfileInfo->pRIResetLockoutCount);
  204. FreeRI(pProfileInfo->pRILockoutDuration);
  205. FreeRI(pProfileInfo->pRIRequireLogonToChangePassword);
  206. FreeRI(pProfileInfo->pRIForceLogoffWhenHourExpire);
  207. FreeRI(pProfileInfo->pRIEnableAdminAccount);
  208. FreeRI(pProfileInfo->pRIEnableGuestAccount);
  209. FreeRI(pProfileInfo->pRILSAAnonymousNameLookup);
  210. FreeRI(pProfileInfo->pRINewAdministratorName);
  211. FreeRI(pProfileInfo->pRINewGuestName);
  212. FreeRI(pProfileInfo->pRIClearTextPassword);
  213. FreeRI(pProfileInfo->pRIMaxTicketAge);
  214. FreeRI(pProfileInfo->pRIMaxRenewAge);
  215. FreeRI(pProfileInfo->pRIMaxServiceAge);
  216. FreeRI(pProfileInfo->pRIMaxClockSkew);
  217. FreeRI(pProfileInfo->pRITicketValidateClient);
  218. FreeRI(pProfileInfo->pRIAuditSystemEvents);
  219. FreeRI(pProfileInfo->pRIAuditLogonEvents);
  220. FreeRI(pProfileInfo->pRIAuditObjectAccess);
  221. FreeRI(pProfileInfo->pRIAuditPrivilegeUse);
  222. FreeRI(pProfileInfo->pRIAuditPolicyChange);
  223. FreeRI(pProfileInfo->pRIAuditAccountManage);
  224. FreeRI(pProfileInfo->pRIAuditProcessTracking);
  225. FreeRI(pProfileInfo->pRIAuditDSAccess);
  226. FreeRI(pProfileInfo->pRIAuditAccountLogon);
  227. FreeRI(pProfileInfo->pRIMaximumLogSize[0]);
  228. FreeRI(pProfileInfo->pRIMaximumLogSize[1]);
  229. FreeRI(pProfileInfo->pRIMaximumLogSize[2]);
  230. FreeRI(pProfileInfo->pRIAuditLogRetentionPeriod[0]);
  231. FreeRI(pProfileInfo->pRIAuditLogRetentionPeriod[1]);
  232. FreeRI(pProfileInfo->pRIAuditLogRetentionPeriod[2]);
  233. FreeRI(pProfileInfo->pRIRetentionDays[0]);
  234. FreeRI(pProfileInfo->pRIRetentionDays[1]);
  235. FreeRI(pProfileInfo->pRIRetentionDays[2]);
  236. FreeRI(pProfileInfo->pRIRestrictGuestAccess[0]);
  237. FreeRI(pProfileInfo->pRIRestrictGuestAccess[1]);
  238. FreeRI(pProfileInfo->pRIRestrictGuestAccess[2]);
  239. FreeList(&(pProfileInfo->listRIInfPrivilegeAssignedTo));
  240. FreeList(&(pProfileInfo->listRIGroupMemebership));
  241. FreeList(&(pProfileInfo->listRIServices));
  242. FreeVector(&(pProfileInfo->vecRIFiles));
  243. FreeVector(&(pProfileInfo->vecRIReg));
  244. SceFreeProfileMemory(pProfileInfo);
  245. }
  246. CWMIRsop::~CWMIRsop() {
  247. if (m_vecAllRSOPCache) {
  248. for(vector<PWMI_SCE_PROFILE_INFO>::iterator i = m_vecAllRSOPCache->begin();
  249. i != m_vecAllRSOPCache->end();
  250. ++i )
  251. {
  252. PWMI_SCE_PROFILE_INFO pProfileInfo = *i;
  253. FreeWMI_SCE_PROFILE_INFO(pProfileInfo);
  254. }
  255. }
  256. delete m_vecAllRSOPCache;
  257. m_vecAllRSOPCache = NULL; // be extra carefull because the old code is not to delete it at all.
  258. if (m_pSvc) {
  259. m_pSvc->Release();
  260. }
  261. }
  262. HRESULT CWMIRsop::Initialize()
  263. {
  264. HRESULT hr = S_OK;
  265. IWbemLocator *pLoc = NULL;
  266. //Already initialized
  267. if(m_pSvc)
  268. return hr;
  269. if (!m_pRSOPInformation)
  270. {
  271. return E_FAIL;
  272. }
  273. hr = CoCreateInstance(CLSID_WbemLocator,
  274. 0,
  275. CLSCTX_INPROC_SERVER,
  276. IID_IWbemLocator,
  277. (LPVOID *) &pLoc);
  278. if (FAILED(hr))
  279. {
  280. return hr;
  281. }
  282. const int cchMaxLength = 512;
  283. WCHAR szNameSpace[cchMaxLength];//LPOLESTR pszNameSpace = (LPOLESTR) LocalAlloc (LPTR, cchMaxLength * sizeof (WCHAR));
  284. hr = m_pRSOPInformation->GetNamespace (
  285. GPO_SECTION_MACHINE,
  286. szNameSpace,
  287. cchMaxLength);
  288. szNameSpace[cchMaxLength - 1] = L'\0';
  289. if (SUCCEEDED(hr))
  290. {
  291. BSTR bstrNameSpace = SysAllocString (szNameSpace);
  292. if (bstrNameSpace)
  293. {
  294. hr = pLoc->ConnectServer(bstrNameSpace,
  295. NULL,
  296. NULL,
  297. 0,
  298. NULL,
  299. 0,
  300. 0,
  301. &m_pSvc
  302. );
  303. SysFreeString(bstrNameSpace);
  304. }
  305. else
  306. hr = E_OUTOFMEMORY;
  307. }
  308. if (SUCCEEDED(hr))
  309. {
  310. // Set the proxy so that impersonation of the client occurs.
  311. hr = CoSetProxyBlanket(m_pSvc,
  312. RPC_C_AUTHN_WINNT,
  313. RPC_C_AUTHZ_NONE,
  314. NULL,
  315. RPC_C_AUTHN_LEVEL_CALL,
  316. RPC_C_IMP_LEVEL_IMPERSONATE,
  317. NULL,
  318. EOAC_NONE);
  319. }
  320. pLoc->Release();
  321. return hr; // Program successfully completed.
  322. }
  323. HRESULT CWMIRsop::EnumeratePrecedenceOne(IEnumWbemClassObject **ppEnum)
  324. {
  325. HRESULT hr = m_pSvc->ExecQuery(_bstr_t(QUERY_LANG),
  326. _bstr_t(RSOP_PREC_ONE_QUERY),
  327. WBEM_FLAG_FORWARD_ONLY,
  328. NULL,
  329. ppEnum);
  330. return hr;
  331. }
  332. HRESULT CWMIRsop::EnumerateAll(IEnumWbemClassObject **ppEnum)
  333. {
  334. HRESULT hr = m_pSvc->ExecQuery(_bstr_t(QUERY_LANG),
  335. _bstr_t(RSOP_ALL_QUERY),
  336. WBEM_FLAG_FORWARD_ONLY,
  337. NULL,
  338. ppEnum);
  339. return hr;
  340. }
  341. HRESULT CWMIRsop::GetNextInstance(IEnumWbemClassObject *pEnum,
  342. IWbemClassObject** rsopInstance)
  343. {
  344. HRESULT hr = WBEM_S_FALSE;
  345. ULONG returnedNum = 0;
  346. if(pEnum)
  347. {
  348. hr = pEnum->Next(WBEM_INFINITE,
  349. 1,
  350. rsopInstance,
  351. &returnedNum);
  352. if( FAILED(hr) )
  353. return hr;
  354. if (returnedNum == 0)
  355. hr = WBEM_S_FALSE;
  356. }
  357. return hr;
  358. }
  359. HRESULT CWMIRsop::GetClass(IWbemClassObject* rsopInstance,
  360. LPWSTR *ppClass)
  361. {
  362. PTSTR pszClassName;
  363. VARIANT value;
  364. HRESULT hr = rsopInstance->Get(_bstr_t(WMI_CLASS),
  365. 0,
  366. &value,
  367. NULL,
  368. NULL);
  369. if(FAILED(hr) || value.vt != VT_BSTR || value.bstrVal == NULL)
  370. return hr;
  371. pszClassName = (PTSTR) V_BSTR(&value);
  372. ULONG uLen = wcslen(pszClassName);
  373. *ppClass = (LPWSTR)LocalAlloc(LPTR, (uLen + 1) * sizeof(WCHAR));
  374. if( *ppClass == NULL )
  375. {
  376. VariantClear(&value);
  377. return E_OUTOFMEMORY;
  378. }
  379. wcscpy(*ppClass,pszClassName);
  380. VariantClear(&value);
  381. return hr;
  382. }
  383. HRESULT CWMIRsop::GetRSOPInfo(IWbemClassObject *rsopInstance,
  384. PRSOP_INFO pInfo)
  385. {
  386. HRESULT hr = S_OK;
  387. PTSTR pszGPOID = 0;
  388. UINT status = 0;
  389. UINT precedence = 0;
  390. VARIANT value;
  391. //Get Status
  392. hr = rsopInstance->Get(_bstr_t(RSOP_STATUS),
  393. 0,
  394. &value,
  395. NULL,
  396. NULL);
  397. if(FAILED(hr))
  398. return hr;
  399. pInfo->status = (ULONG) V_UINT(&value);
  400. VariantClear(&value);
  401. //Get Error
  402. hr = rsopInstance->Get(_bstr_t(RSOP_ERROR),
  403. 0,
  404. &value,
  405. NULL,
  406. NULL);
  407. if(FAILED(hr))
  408. return hr;
  409. pInfo->error = (ULONG) V_UINT(&value);
  410. VariantClear(&value);
  411. //Get Precedence
  412. hr = rsopInstance->Get(_bstr_t(RSOP_PRECEDENCE),
  413. 0,
  414. &value,
  415. NULL,
  416. NULL);
  417. if(FAILED(hr))
  418. return hr;
  419. pInfo->precedence = (ULONG) V_UINT(&value);
  420. VariantClear(&value);
  421. //Get GPOID
  422. hr = rsopInstance->Get(_bstr_t(RSOP_GPOID),
  423. 0,
  424. &value,
  425. NULL,
  426. NULL);
  427. if(FAILED(hr) || value.vt != VT_BSTR || (value.vt == VT_BSTR && value.bstrVal == NULL) )
  428. return hr;
  429. pszGPOID = (PTSTR) V_BSTR(&value);
  430. ULONG uLen = wcslen(pszGPOID);
  431. pInfo->pszGPOID = (LPWSTR)LocalAlloc(LPTR, (uLen + 1) * sizeof(WCHAR));
  432. if( pInfo->pszGPOID == NULL )
  433. {
  434. VariantClear(&value);
  435. return E_OUTOFMEMORY;
  436. }
  437. wcscpy(pInfo->pszGPOID, pszGPOID);
  438. VariantClear(&value);
  439. return hr;
  440. }
  441. HRESULT CWMIRsop::GetPrecedenceOneRSOPInfo(PWMI_SCE_PROFILE_INFO *ppProfileInfo)
  442. {
  443. HRESULT hr = S_OK;
  444. IWbemClassObject *rsopInstance = NULL;
  445. IEnumWbemClassObject *pEnumObject = NULL;
  446. PWMI_SCE_PROFILE_INFO pTempProfileInfo = NULL;
  447. PRSOP_INFO pInfo = NULL;
  448. hr = Initialize();
  449. if( FAILED(hr) )
  450. goto exit_gracefully;
  451. hr = EnumeratePrecedenceOne(&pEnumObject);
  452. if( FAILED(hr) )
  453. goto exit_gracefully;
  454. pTempProfileInfo = new WMI_SCE_PROFILE_INFO;
  455. if( !pTempProfileInfo )
  456. {
  457. hr = E_OUTOFMEMORY;
  458. goto exit_gracefully;
  459. }
  460. InitWMI_SEC_PROFILE_INFO(pTempProfileInfo);
  461. //Get each instance
  462. while( ((hr = GetNextInstance(pEnumObject, &rsopInstance)) != WBEM_S_FALSE) && !FAILED(hr) )
  463. {
  464. pInfo = (PRSOP_INFO)LocalAlloc(LPTR, sizeof(RSOP_INFO));
  465. if(pInfo == NULL)
  466. {
  467. hr = E_OUTOFMEMORY;
  468. goto exit_gracefully;
  469. }
  470. //Get RSOP_INFO
  471. hr = GetRSOPInfo(rsopInstance, pInfo);
  472. if( FAILED(hr) )
  473. goto exit_gracefully;
  474. hr = AddInstance(rsopInstance,
  475. pInfo,
  476. pTempProfileInfo);
  477. if( FAILED(hr) )
  478. goto exit_gracefully;
  479. rsopInstance->Release();
  480. rsopInstance = NULL;
  481. pInfo = NULL;
  482. }
  483. exit_gracefully:
  484. if(FAILED(hr))
  485. {
  486. if (rsopInstance)
  487. rsopInstance->Release(); // if while loop somehow terminate to here, rsopInstance is never released there
  488. if(pEnumObject)
  489. pEnumObject->Release();
  490. FreeRI(pInfo);
  491. //Free pTempProfileInfo
  492. FreeWMI_SCE_PROFILE_INFO(pTempProfileInfo);
  493. pTempProfileInfo = NULL;
  494. }
  495. *ppProfileInfo = pTempProfileInfo;
  496. return hr;
  497. }
  498. PWMI_SCE_PROFILE_INFO SearchProfileInList(vector<PWMI_SCE_PROFILE_INFO> *vecInfo,
  499. PRSOP_INFO pInfo)
  500. {
  501. for(vector<PWMI_SCE_PROFILE_INFO>::iterator i = vecInfo->begin();
  502. i != vecInfo->end();
  503. ++i )
  504. {
  505. PWMI_SCE_PROFILE_INFO pProfileInfo = *i;
  506. if(_wcsicmp(pProfileInfo->pInfo->pszGPOID,pInfo->pszGPOID) == 0 )
  507. return pProfileInfo;
  508. }
  509. return NULL;
  510. }
  511. //Function Object Used for sorting vector
  512. struct less_mag : public binary_function<PWMI_SCE_PROFILE_INFO, PWMI_SCE_PROFILE_INFO, bool> {
  513. bool operator()(PWMI_SCE_PROFILE_INFO x, PWMI_SCE_PROFILE_INFO y)
  514. { return x->pInfo->precedence < y->pInfo->precedence; }
  515. };
  516. HRESULT CWMIRsop::GetAllRSOPInfo(vector<PWMI_SCE_PROFILE_INFO> *vecInfo)
  517. {
  518. HRESULT hr = S_OK;
  519. IWbemClassObject *rsopInstance = NULL;
  520. IEnumWbemClassObject *pEnumObject = NULL;
  521. PRSOP_INFO pInfo = NULL;
  522. PWMI_SCE_PROFILE_INFO pProfileInfo = NULL;
  523. if (NULL == vecInfo) {
  524. return E_INVALIDARG;
  525. }
  526. //
  527. // If we've alrady cached the info from WMI then just return it
  528. // don't try and get it again
  529. //
  530. if (m_vecAllRSOPCache)
  531. {
  532. for(vector<PWMI_SCE_PROFILE_INFO>::iterator i = m_vecAllRSOPCache->begin();
  533. i != m_vecAllRSOPCache->end();
  534. ++i )
  535. {
  536. vecInfo->push_back(*i);
  537. }
  538. return S_OK;
  539. }
  540. hr = Initialize();
  541. if( FAILED(hr) )
  542. goto exit_gracefully;
  543. hr = EnumerateAll(&pEnumObject);
  544. if( FAILED(hr) )
  545. goto exit_gracefully;
  546. //Get each instance
  547. while( ((hr = GetNextInstance(pEnumObject, &rsopInstance)) != WBEM_S_FALSE) && !FAILED(hr) )
  548. {
  549. pInfo = (PRSOP_INFO)LocalAlloc(LPTR, sizeof(RSOP_INFO));
  550. if(pInfo == NULL)
  551. {
  552. hr = E_OUTOFMEMORY;
  553. goto exit_gracefully;
  554. }
  555. //Get RSOP_INFO
  556. hr = GetRSOPInfo(rsopInstance, pInfo);
  557. if( FAILED(hr) )
  558. goto exit_gracefully;
  559. pProfileInfo = SearchProfileInList(vecInfo,pInfo);
  560. if(!pProfileInfo)
  561. {
  562. pProfileInfo = new WMI_SCE_PROFILE_INFO;
  563. if(!pProfileInfo)
  564. {
  565. hr = E_OUTOFMEMORY;
  566. goto exit_gracefully;
  567. }
  568. InitWMI_SEC_PROFILE_INFO(pProfileInfo);
  569. pProfileInfo->pInfo = (PRSOP_INFO)LocalAlloc(LPTR,sizeof(RSOP_INFO));
  570. if(!pProfileInfo->pInfo)
  571. {
  572. hr = E_OUTOFMEMORY;
  573. goto exit_gracefully;
  574. }
  575. pProfileInfo->pInfo->pszGPOID = (LPWSTR)LocalAlloc(LPTR, (wcslen(pInfo->pszGPOID)+1)*sizeof(WCHAR));
  576. if(!pProfileInfo->pInfo->pszGPOID)
  577. {
  578. hr = E_OUTOFMEMORY;
  579. goto exit_gracefully;
  580. }
  581. wcscpy(pProfileInfo->pInfo->pszGPOID,pInfo->pszGPOID);
  582. vecInfo->push_back(pProfileInfo);
  583. }
  584. if( pProfileInfo->pInfo->precedence < pInfo->precedence )
  585. pProfileInfo->pInfo->precedence = pInfo->precedence;
  586. hr = AddInstance(rsopInstance,
  587. pInfo,
  588. pProfileInfo);
  589. if(FAILED(hr))
  590. goto exit_gracefully;
  591. rsopInstance->Release();
  592. rsopInstance = NULL;
  593. pInfo = NULL;
  594. }
  595. sort(vecInfo->begin(),vecInfo->end(),less_mag());
  596. m_vecAllRSOPCache = new vector<PWMI_SCE_PROFILE_INFO>;
  597. if (m_vecAllRSOPCache)
  598. {
  599. for(vector<PWMI_SCE_PROFILE_INFO>::iterator i = vecInfo->begin();
  600. i != vecInfo->end();
  601. ++i )
  602. {
  603. m_vecAllRSOPCache->push_back(*i);
  604. }
  605. }
  606. exit_gracefully:
  607. if(FAILED(hr))
  608. {
  609. FreeRI(pInfo);
  610. //Free the vector
  611. for(vector<PWMI_SCE_PROFILE_INFO>::iterator i = vecInfo->begin();
  612. i != vecInfo->end();
  613. ++i )
  614. {
  615. PWMI_SCE_PROFILE_INFO pProfileInfo = *i;
  616. FreeWMI_SCE_PROFILE_INFO(pProfileInfo);
  617. }
  618. }
  619. if(pEnumObject)
  620. pEnumObject->Release();
  621. if(rsopInstance)
  622. rsopInstance->Release();
  623. return hr;
  624. }
  625. HRESULT CWMIRsop::AddNumericSetting(IWbemClassObject *rsopInstance,
  626. PRSOP_INFO pInfo,
  627. PWMI_SCE_PROFILE_INFO pProfileInfo)
  628. {
  629. HRESULT hr = S_OK;
  630. VARIANT bKeyName;
  631. PTSTR keyName;
  632. VARIANT bSettingValue;
  633. DWORD settingValue;
  634. _TRACE (1, L"Entering CWMIRsop::AddNumericSetting\n");
  635. hr = rsopInstance->Get((BSTR)RSOP_KEYNAME,
  636. 0,
  637. &bKeyName,
  638. NULL,
  639. NULL);
  640. if( FAILED(hr) || bKeyName.vt != VT_BSTR || bKeyName.bstrVal == NULL)
  641. goto exit_gracefully;
  642. hr = rsopInstance->Get((BSTR)RSOP_SETTING,
  643. 0,
  644. &bSettingValue,
  645. NULL,
  646. NULL);
  647. if( FAILED(hr) )
  648. goto exit_gracefully;
  649. keyName = V_BSTR(&bKeyName);
  650. settingValue = V_UINT(&bSettingValue);
  651. if(!_wcsicmp(keyName, MIN_PASS_AGE))
  652. {
  653. pProfileInfo->MinimumPasswordAge = settingValue;
  654. pProfileInfo->pRIMinimumPasswordAge = pInfo;
  655. }
  656. else if(!_wcsicmp(keyName, MAX_PASS_AGE))
  657. {
  658. pProfileInfo->MaximumPasswordAge = settingValue;
  659. pProfileInfo->pRIMaximumPasswordAge = pInfo;
  660. }
  661. else if(!_wcsicmp(keyName, MIN_PASS_LEN))
  662. {
  663. pProfileInfo->MinimumPasswordLength = settingValue;
  664. pProfileInfo->pRIMinimumPasswordLength = pInfo;
  665. }
  666. else if(!_wcsicmp(keyName, PASS_HIS_SIZE))
  667. {
  668. pProfileInfo->PasswordHistorySize = settingValue;
  669. pProfileInfo->pRIPasswordHistorySize = pInfo;
  670. }
  671. else if(!_wcsicmp(keyName, LOCKOUT_COUNT))
  672. {
  673. pProfileInfo->LockoutBadCount = settingValue;
  674. pProfileInfo->pRILockoutBadCount = pInfo;
  675. }
  676. else if(!_wcsicmp(keyName, RESET_LOCKOUT_COUNT))
  677. {
  678. pProfileInfo->ResetLockoutCount = settingValue;
  679. pProfileInfo->pRIResetLockoutCount = pInfo;
  680. }
  681. else if(!_wcsicmp(keyName, LOCKOUT_DURATION))
  682. {
  683. pProfileInfo->LockoutDuration = settingValue;
  684. pProfileInfo->pRILockoutDuration = pInfo;
  685. }
  686. else if(!_wcsicmp(keyName, MAX_TICKET_AGE))
  687. {
  688. if(!pProfileInfo->pKerberosInfo)
  689. {
  690. pProfileInfo->pKerberosInfo =
  691. (PSCE_KERBEROS_TICKET_INFO) LocalAlloc(LPTR, sizeof(SCE_KERBEROS_TICKET_INFO));
  692. if(pProfileInfo->pKerberosInfo == NULL)
  693. {
  694. hr = E_OUTOFMEMORY;
  695. goto exit_gracefully;
  696. }
  697. }
  698. pProfileInfo->pKerberosInfo->MaxTicketAge = settingValue;
  699. pProfileInfo->pRIMaxTicketAge = pInfo;
  700. }
  701. else if(!_wcsicmp(keyName, MAX_RENEW_AGE))
  702. {
  703. if(!pProfileInfo->pKerberosInfo)
  704. {
  705. pProfileInfo->pKerberosInfo =
  706. (PSCE_KERBEROS_TICKET_INFO) LocalAlloc(LPTR, sizeof(SCE_KERBEROS_TICKET_INFO));
  707. if(pProfileInfo->pKerberosInfo == NULL)
  708. {
  709. hr = E_OUTOFMEMORY;
  710. goto exit_gracefully;
  711. }
  712. }
  713. pProfileInfo->pKerberosInfo->MaxRenewAge = settingValue;
  714. pProfileInfo->pRIMaxRenewAge = pInfo;
  715. }
  716. else if(!_wcsicmp(keyName, MAX_SERVICE_AGE))
  717. {
  718. if(!pProfileInfo->pKerberosInfo)
  719. {
  720. pProfileInfo->pKerberosInfo =
  721. (PSCE_KERBEROS_TICKET_INFO) LocalAlloc(LPTR, sizeof(SCE_KERBEROS_TICKET_INFO));
  722. if(pProfileInfo->pKerberosInfo == NULL)
  723. {
  724. hr = E_OUTOFMEMORY;
  725. goto exit_gracefully;
  726. }
  727. }
  728. pProfileInfo->pKerberosInfo->MaxServiceAge = settingValue;
  729. pProfileInfo->pRIMaxServiceAge = pInfo;
  730. }
  731. else if(!_wcsicmp(keyName, MAX_CLOCK_SKEW))
  732. {
  733. if(!pProfileInfo->pKerberosInfo)
  734. {
  735. pProfileInfo->pKerberosInfo =
  736. (PSCE_KERBEROS_TICKET_INFO) LocalAlloc(LPTR, sizeof(SCE_KERBEROS_TICKET_INFO));
  737. if(pProfileInfo->pKerberosInfo == NULL)
  738. {
  739. hr = E_OUTOFMEMORY;
  740. goto exit_gracefully;
  741. }
  742. }
  743. pProfileInfo->pKerberosInfo->MaxClockSkew = settingValue;
  744. pProfileInfo->pRIMaxClockSkew = pInfo;
  745. }
  746. else
  747. {
  748. _ASSERT (FALSE); // key name not accounted for
  749. }
  750. exit_gracefully:
  751. VariantClear(&bKeyName);
  752. VariantClear(&bSettingValue);
  753. _TRACE (-1,L"Leaving CWMIRsop::AddNumericSetting\n");
  754. return hr;
  755. }
  756. HRESULT CWMIRsop::AddEventLogNumericSetting(IWbemClassObject *rsopInstance,
  757. PRSOP_INFO pInfo,
  758. PWMI_SCE_PROFILE_INFO pProfileInfo)
  759. {
  760. VARIANT bKeyName;
  761. VARIANT bSettingValue;
  762. VARIANT bType;
  763. _TRACE (1, L"Entering CWMIRsop::AddEventLogNumericSetting\n");
  764. HRESULT hr = rsopInstance->Get((BSTR)RSOP_KEYNAME,
  765. 0,
  766. &bKeyName,
  767. NULL,
  768. NULL);
  769. if( FAILED(hr) || bKeyName.vt != VT_BSTR || bKeyName.bstrVal == NULL)
  770. goto exit_gracefully;
  771. hr = rsopInstance->Get((BSTR)RSOP_SETTING,
  772. 0,
  773. &bSettingValue,
  774. NULL,
  775. NULL);
  776. if( FAILED(hr) )
  777. goto exit_gracefully;
  778. hr = rsopInstance->Get((BSTR)RSOP_EVENTLOG_TYPE,
  779. 0,
  780. &bType,
  781. NULL,
  782. NULL);
  783. if( FAILED(hr) )
  784. goto exit_gracefully;
  785. PTSTR keyName = V_BSTR(&bKeyName);
  786. DWORD settingValue = V_UINT(&bSettingValue);
  787. PTSTR typeValue = V_BSTR(&bType);
  788. unsigned long ulType = wcstoul (typeValue, L'\0', 10);
  789. ASSERT (ulType <= 2);
  790. if ( ulType <= 2 )
  791. {
  792. if ( !_wcsicmp(keyName, MAX_LOG_SIZE) )
  793. {
  794. pProfileInfo->MaximumLogSize[ulType] = settingValue;
  795. pProfileInfo->pRIMaximumLogSize[ulType] = pInfo;
  796. }
  797. else if ( !_wcsicmp(keyName, AUDIT_LOG_RETENTION_PERIOD) )
  798. {
  799. pProfileInfo->AuditLogRetentionPeriod[ulType] = settingValue;
  800. pProfileInfo->pRIAuditLogRetentionPeriod[ulType] = pInfo;
  801. }
  802. else if ( !_wcsicmp(keyName, RETENTION_DAYS) )
  803. {
  804. pProfileInfo->RetentionDays[ulType] = settingValue;
  805. pProfileInfo->pRIRetentionDays[ulType] = pInfo;
  806. }
  807. else
  808. {
  809. _ASSERT (FALSE); // key name not accounted for
  810. }
  811. }
  812. else
  813. hr = E_FAIL;
  814. exit_gracefully:
  815. VariantClear (&bKeyName);
  816. VariantClear (&bSettingValue);
  817. VariantClear (&bType);
  818. _TRACE (-1,L"Leaving CWMIRsop::AddEventLogNumericSetting\n");
  819. return hr;
  820. }
  821. HRESULT CWMIRsop::AddEventLogBooleanSetting(IWbemClassObject *rsopInstance,
  822. PRSOP_INFO pInfo,
  823. PWMI_SCE_PROFILE_INFO pProfileInfo)
  824. {
  825. HRESULT hr = S_OK;
  826. VARIANT bKeyName;
  827. PTSTR keyName = 0;
  828. VARIANT bSettingValue;
  829. DWORD settingValue;
  830. BOOL boolVal = FALSE;
  831. VARIANT bType;
  832. PTSTR typeValue = 0;
  833. _TRACE (1, L"Entering CWMIRsop::AddEventLogBooleanSetting\n");
  834. hr = rsopInstance->Get((BSTR)RSOP_KEYNAME,
  835. 0,
  836. &bKeyName,
  837. NULL,
  838. NULL);
  839. if( FAILED(hr) || bKeyName.vt != VT_BSTR || bKeyName.bstrVal == NULL)
  840. goto exit_gracefully;
  841. hr = rsopInstance->Get((BSTR)RSOP_SETTING,
  842. 0,
  843. &bSettingValue,
  844. NULL,
  845. NULL);
  846. if( FAILED(hr) )
  847. goto exit_gracefully;
  848. hr = rsopInstance->Get((BSTR)RSOP_EVENTLOG_TYPE,
  849. 0,
  850. &bType,
  851. NULL,
  852. NULL);
  853. if( FAILED(hr) )
  854. goto exit_gracefully;
  855. keyName = V_BSTR(&bKeyName);
  856. boolVal = V_BOOL(&bSettingValue);
  857. settingValue = (boolVal)? 1:0;
  858. typeValue = V_BSTR(&bType);
  859. unsigned long ulType = wcstoul (typeValue, L'\0', 10);
  860. ASSERT (ulType <= 2);
  861. if ( ulType <= 2 )
  862. {
  863. if ( !_wcsicmp(keyName, RESTRICT_GUEST_ACCESS) )
  864. {
  865. pProfileInfo->RestrictGuestAccess[ulType] = settingValue;
  866. pProfileInfo->pRIRestrictGuestAccess[ulType] = pInfo;
  867. }
  868. else
  869. {
  870. _ASSERT (FALSE); // key name not accounted for
  871. }
  872. }
  873. else
  874. hr = E_FAIL;
  875. exit_gracefully:
  876. VariantClear (&bKeyName);
  877. VariantClear (&bSettingValue);
  878. VariantClear (&bType);
  879. _TRACE (-1,L"Leaving CWMIRsop::AddEventLogBooleanSetting\n");
  880. return hr;
  881. }
  882. HRESULT CWMIRsop::AddBooleanSetting(IWbemClassObject *rsopInstance,
  883. PRSOP_INFO pInfo,
  884. PWMI_SCE_PROFILE_INFO pProfileInfo)
  885. {
  886. VARIANT bKeyName;
  887. PTSTR keyName;
  888. VARIANT bSettingValue;
  889. BOOL boolVal;
  890. DWORD settingValue;
  891. HRESULT hr = S_OK;
  892. _TRACE (1, L"Entering CWMIRsop::AddBooleanSetting\n");
  893. hr = rsopInstance->Get((BSTR)RSOP_KEYNAME,
  894. 0,
  895. &bKeyName,
  896. NULL,
  897. NULL);
  898. if(FAILED(hr) || bKeyName.vt != VT_BSTR || bKeyName.bstrVal == NULL)
  899. goto exit_gracefully;
  900. hr = rsopInstance->Get((BSTR)RSOP_SETTING,
  901. 0,
  902. &bSettingValue,
  903. NULL,
  904. NULL);
  905. if(FAILED(hr))
  906. goto exit_gracefully;
  907. keyName = (PTSTR) V_BSTR(&bKeyName);
  908. boolVal = V_BOOL(&bSettingValue);
  909. settingValue = (boolVal)? 1:0;
  910. if(!_wcsicmp(keyName, PASS_COMPLEX))
  911. {
  912. pProfileInfo->PasswordComplexity = settingValue;
  913. pProfileInfo->pRIPasswordComplexity = pInfo;
  914. }
  915. else if(!_wcsicmp(keyName, FORCE_LOGOFF))
  916. {
  917. pProfileInfo->ForceLogoffWhenHourExpire = settingValue;
  918. pProfileInfo->pRIForceLogoffWhenHourExpire = pInfo;
  919. }
  920. else if(!_wcsicmp(keyName, ENABLE_ADMIN))
  921. {
  922. pProfileInfo->EnableAdminAccount = settingValue;
  923. pProfileInfo->pRIEnableAdminAccount = pInfo;
  924. }
  925. else if(!_wcsicmp(keyName, ENABLE_GUEST))
  926. {
  927. pProfileInfo->EnableGuestAccount = settingValue;
  928. pProfileInfo->pRIEnableGuestAccount = pInfo;
  929. }
  930. else if(!_wcsicmp(keyName, LSA_ANON_LOOKUP))
  931. {
  932. pProfileInfo->LSAAnonymousNameLookup = settingValue;
  933. pProfileInfo->pRILSAAnonymousNameLookup = pInfo;
  934. }
  935. else if(!_wcsicmp(keyName, CLEAR_TEXT_PASS))
  936. {
  937. pProfileInfo->ClearTextPassword = settingValue;
  938. pProfileInfo->pRIClearTextPassword = pInfo;
  939. }
  940. else if (!_wcsicmp(keyName, REQUIRE_LOGON_TO_CHANGE_PASS))
  941. {
  942. pProfileInfo->RequireLogonToChangePassword = settingValue;
  943. pProfileInfo->pRIRequireLogonToChangePassword = pInfo;
  944. }
  945. else if(!_wcsicmp(keyName, VALIDATE_CLIENT))
  946. {
  947. if(!pProfileInfo->pKerberosInfo)
  948. {
  949. pProfileInfo->pKerberosInfo =
  950. (PSCE_KERBEROS_TICKET_INFO) LocalAlloc(LPTR, sizeof(SCE_KERBEROS_TICKET_INFO));
  951. if(pProfileInfo->pKerberosInfo == NULL)
  952. {
  953. hr = E_OUTOFMEMORY;
  954. goto exit_gracefully;
  955. }
  956. }
  957. pProfileInfo->pKerberosInfo->TicketValidateClient = settingValue;
  958. pProfileInfo->pRITicketValidateClient = pInfo;
  959. }
  960. else
  961. {
  962. _ASSERT (FALSE); // key name not accounted for
  963. }
  964. exit_gracefully:
  965. VariantClear(&bKeyName);
  966. VariantClear(&bSettingValue);
  967. _TRACE (-1,L"Leaving CWMIRsop::AddBooleanSetting\n");
  968. return hr;
  969. }
  970. HRESULT CWMIRsop::AddAuditSetting(IWbemClassObject *rsopInstance,
  971. PRSOP_INFO pInfo,
  972. PWMI_SCE_PROFILE_INFO pProfileInfo)
  973. {
  974. VARIANT bCategoryName;
  975. PTSTR categoryName;
  976. VARIANT vSuccessVal;
  977. VARIANT vFailVal;
  978. BOOL successVal;
  979. BOOL failVal;
  980. DWORD settingVal = 0;
  981. HRESULT hr = S_OK;
  982. _TRACE (1, L"Entering CWMIRsop::AddAuditSetting\n");
  983. hr = rsopInstance->Get(_bstr_t(TEXT("Category")),
  984. 0,
  985. &bCategoryName,
  986. NULL,
  987. NULL
  988. );
  989. if(FAILED(hr) || bCategoryName.vt != VT_BSTR || bCategoryName.bstrVal == NULL)
  990. goto exit_gracefully;
  991. hr = rsopInstance->Get(_bstr_t(TEXT("Success")),
  992. 0,
  993. &vSuccessVal,
  994. NULL,
  995. NULL
  996. );
  997. if(FAILED(hr))
  998. goto exit_gracefully;
  999. hr = rsopInstance->Get(_bstr_t(TEXT("Failure")),
  1000. 0,
  1001. &vFailVal,
  1002. NULL,
  1003. NULL
  1004. );
  1005. if(FAILED(hr))
  1006. goto exit_gracefully;
  1007. categoryName = (PTSTR) V_BSTR(&bCategoryName);
  1008. successVal = V_BOOL(&vSuccessVal);
  1009. failVal = V_BOOL(&vFailVal);
  1010. if (successVal)
  1011. settingVal |= 1;
  1012. if (failVal)
  1013. settingVal |= 2;
  1014. if(!_wcsicmp(categoryName, AUDIT_SYSTEM_EVENTS))
  1015. {
  1016. pProfileInfo->AuditSystemEvents = settingVal;
  1017. pProfileInfo->pRIAuditSystemEvents = pInfo;
  1018. }
  1019. else if(!_wcsicmp(categoryName, AUDIT_LOGON_EVENTS))
  1020. {
  1021. pProfileInfo->AuditLogonEvents = settingVal;
  1022. pProfileInfo->pRIAuditLogonEvents = pInfo;
  1023. }
  1024. else if(!_wcsicmp(categoryName, AUDIT_OBJECT_ACCESS))
  1025. {
  1026. pProfileInfo->AuditObjectAccess = settingVal;
  1027. pProfileInfo->pRIAuditObjectAccess = pInfo;
  1028. }
  1029. else if (!_wcsicmp(categoryName, AUDIT_PRIVILEGE_USE))
  1030. {
  1031. pProfileInfo->AuditPrivilegeUse = settingVal;
  1032. pProfileInfo->pRIAuditPrivilegeUse = pInfo;
  1033. }
  1034. else if(!_wcsicmp(categoryName, AUDIT_POLICY_CHANGE))
  1035. {
  1036. pProfileInfo->AuditPolicyChange = settingVal;
  1037. pProfileInfo->pRIAuditPolicyChange = pInfo;
  1038. }
  1039. else if(!_wcsicmp(categoryName, AUDIT_ACCOUNT_MANAGE))
  1040. {
  1041. pProfileInfo->AuditAccountManage = settingVal;
  1042. pProfileInfo->pRIAuditAccountManage = pInfo;
  1043. }
  1044. else if(!_wcsicmp(categoryName, AUDIT_PROCESS_TRAKING))
  1045. {
  1046. pProfileInfo->AuditProcessTracking = settingVal;
  1047. pProfileInfo->pRIAuditProcessTracking = pInfo;
  1048. }
  1049. else if(!_wcsicmp(categoryName, AUDIT_DS_ACCESS))
  1050. {
  1051. pProfileInfo->AuditDSAccess = settingVal;
  1052. pProfileInfo->pRIAuditDSAccess = pInfo;
  1053. }
  1054. else if(!_wcsicmp(categoryName, AUDIT_ACCOUNT_LOGON))
  1055. {
  1056. pProfileInfo->AuditAccountLogon = settingVal;
  1057. pProfileInfo->pRIAuditAccountLogon = pInfo;
  1058. }
  1059. else
  1060. {
  1061. _ASSERT (FALSE); // key name not accounted for
  1062. }
  1063. exit_gracefully:
  1064. VariantClear(&bCategoryName);
  1065. VariantClear(&vSuccessVal);
  1066. VariantClear(&vFailVal);
  1067. _TRACE (-1,L"Leaving CWMIRsop::AddAuditSetting\n");
  1068. return hr;
  1069. }
  1070. HRESULT CWMIRsop::AddUserRightSetting(
  1071. IWbemClassObject *rsopInstance,
  1072. PRSOP_INFO pInfo,
  1073. PWMI_SCE_PROFILE_INFO pProfileInfo)
  1074. {
  1075. VARIANT bUserRight;
  1076. PTSTR userRight = NULL;
  1077. VARIANT vAccountList;
  1078. HRESULT hr = S_OK;
  1079. _TRACE (1, L"Entering CWMIRsop::AddUserRightSetting\n");
  1080. hr = rsopInstance->Get(_bstr_t(RSOP_USERRIGHT),
  1081. 0,
  1082. &bUserRight,
  1083. NULL,
  1084. NULL);
  1085. if( FAILED(hr) || bUserRight.vt != VT_BSTR || bUserRight.bstrVal == NULL )
  1086. goto exit_gracefully;
  1087. hr = rsopInstance->Get(_bstr_t(RSOP_ACCOUNTLIST),
  1088. 0,
  1089. &vAccountList,
  1090. NULL,
  1091. NULL);
  1092. if( FAILED(hr) )
  1093. goto exit_gracefully;
  1094. DWORD len;
  1095. len = wcslen((PTSTR) V_BSTR(&bUserRight));
  1096. userRight = (PTSTR) LocalAlloc(LPTR, (len+1) * sizeof(WCHAR) );
  1097. if(!userRight)
  1098. {
  1099. hr = E_OUTOFMEMORY;
  1100. goto exit_gracefully;
  1101. }
  1102. wcscpy(userRight, (PTSTR) V_BSTR(&bUserRight));
  1103. PSCE_PRIVILEGE_ASSIGNMENT head;
  1104. head = pProfileInfo->OtherInfo.scp.u.pInfPrivilegeAssignedTo;
  1105. if (!head)
  1106. {
  1107. head = (pProfileInfo->OtherInfo.scp.u.pInfPrivilegeAssignedTo =
  1108. (PSCE_PRIVILEGE_ASSIGNMENT) LocalAlloc(LPTR, sizeof(SCE_PRIVILEGE_ASSIGNMENT)));
  1109. if(!head)
  1110. {
  1111. hr = E_OUTOFMEMORY;
  1112. goto exit_gracefully;
  1113. }
  1114. }
  1115. else
  1116. {
  1117. PSCE_PRIVILEGE_ASSIGNMENT current;
  1118. current = (PSCE_PRIVILEGE_ASSIGNMENT) LocalAlloc(LPTR, sizeof(SCE_PRIVILEGE_ASSIGNMENT));
  1119. if(!current)
  1120. {
  1121. hr = E_OUTOFMEMORY;
  1122. goto exit_gracefully;
  1123. }
  1124. current->Next = head;
  1125. head = current;
  1126. pProfileInfo->OtherInfo.scp.u.pInfPrivilegeAssignedTo = head;
  1127. }
  1128. head->Name = userRight;
  1129. userRight = NULL;
  1130. if(V_VT(&vAccountList) != VT_NULL)
  1131. {
  1132. SAFEARRAY* ptempArray;
  1133. ptempArray = NULL;
  1134. BSTR tempString;
  1135. long lowerBoundray=0, upperBoundray=0, loopCount=0;
  1136. ptempArray = V_ARRAY(&vAccountList);
  1137. if ( FAILED(SafeArrayGetLBound(ptempArray, 1, &lowerBoundray)) ) lowerBoundray = 0;
  1138. if ( FAILED(SafeArrayGetUBound(ptempArray, 1, &upperBoundray)) ) upperBoundray = 0;
  1139. PSCE_NAME_LIST nameHead = head->AssignedTo;
  1140. for (loopCount = lowerBoundray; loopCount <= upperBoundray; loopCount++)
  1141. {
  1142. hr = SafeArrayGetElement(ptempArray,
  1143. &loopCount,
  1144. &tempString);
  1145. if ( FAILED(hr) ) goto exit_gracefully;
  1146. if(!nameHead)
  1147. {
  1148. nameHead =
  1149. (head->AssignedTo = (PSCE_NAME_LIST) LocalAlloc(LPTR, sizeof(SCE_NAME_LIST)));
  1150. if(!nameHead)
  1151. {
  1152. hr = E_OUTOFMEMORY;
  1153. goto exit_gracefully;
  1154. }
  1155. }
  1156. else
  1157. {
  1158. PSCE_NAME_LIST currentName =
  1159. (PSCE_NAME_LIST) LocalAlloc(LPTR, sizeof(SCE_NAME_LIST));
  1160. if(!currentName)
  1161. {
  1162. hr = E_OUTOFMEMORY;
  1163. goto exit_gracefully;
  1164. }
  1165. currentName->Next = nameHead;
  1166. nameHead = currentName;
  1167. head->AssignedTo = nameHead;
  1168. }
  1169. DWORD nameLen = wcslen((PTSTR) tempString);
  1170. nameHead->Name = (PTSTR) LocalAlloc(LPTR, (nameLen+1) *sizeof(WCHAR) );
  1171. if(!nameHead->Name)
  1172. {
  1173. hr = E_OUTOFMEMORY;
  1174. goto exit_gracefully;
  1175. }
  1176. wcscpy(nameHead->Name, (PTSTR) tempString);
  1177. }
  1178. }
  1179. //Set other info
  1180. pProfileInfo->listRIInfPrivilegeAssignedTo.push_front(pInfo);
  1181. exit_gracefully:
  1182. if(FAILED(hr) && (userRight != NULL))
  1183. {
  1184. LocalFree(userRight);
  1185. }
  1186. VariantClear(&bUserRight);
  1187. VariantClear(&vAccountList);
  1188. _TRACE (-1,L"Leaving CWMIRsop::AddUserRightSetting\n");
  1189. return hr;
  1190. }
  1191. HRESULT CWMIRsop::AddRegValSetting(IWbemClassObject *rsopInstance,
  1192. PRSOP_INFO pInfo,
  1193. PWMI_SCE_PROFILE_INFO pProfileInfo)
  1194. {
  1195. VARIANT bKeyName;
  1196. PTSTR keyName;
  1197. VARIANT vSettingValue;
  1198. VARIANT vType;
  1199. PTSTR settingValue;
  1200. DWORD type;
  1201. HRESULT hr = S_OK;
  1202. _TRACE (1, L"Entering CWMIRsop::AddRegValSetting\n");
  1203. hr = rsopInstance->Get(_bstr_t(TEXT("Path")),
  1204. 0,
  1205. &bKeyName,
  1206. NULL,
  1207. NULL);
  1208. if(FAILED(hr) || bKeyName.vt != VT_BSTR || bKeyName.bstrVal == NULL )
  1209. goto exit_gracefully;
  1210. hr = rsopInstance->Get(_bstr_t(TEXT("Data")),
  1211. 0,
  1212. &vSettingValue,
  1213. NULL,
  1214. NULL);
  1215. if(FAILED(hr) || vSettingValue.vt != VT_BSTR || vSettingValue.bstrVal == NULL )
  1216. goto exit_gracefully;
  1217. hr = rsopInstance->Get(_bstr_t(TEXT("Type")),
  1218. 0,
  1219. &vType,
  1220. NULL,
  1221. NULL);
  1222. if(FAILED(hr))
  1223. goto exit_gracefully;
  1224. DWORD len;
  1225. len = wcslen((PTSTR) V_BSTR(&bKeyName));
  1226. keyName = (PTSTR) LocalAlloc(LPTR, (len+1) *sizeof(WCHAR));
  1227. if(!keyName)
  1228. {
  1229. hr = E_OUTOFMEMORY;
  1230. goto exit_gracefully;
  1231. }
  1232. wcscpy(keyName,(PTSTR) V_BSTR(&bKeyName));
  1233. len = wcslen((PTSTR) V_BSTR(&vSettingValue));
  1234. settingValue = (PTSTR) LocalAlloc(LPTR, (len+1) *sizeof(WCHAR));
  1235. if(!settingValue)
  1236. {
  1237. hr = E_OUTOFMEMORY;
  1238. goto exit_gracefully;
  1239. }
  1240. wcscpy(settingValue,(PTSTR) V_BSTR(&vSettingValue));
  1241. type = (DWORD) V_I4(&vType);
  1242. DWORD arrayIndex;
  1243. if ((arrayIndex = pProfileInfo->RegValueCount) == 0)
  1244. {
  1245. pProfileInfo->aRegValues =
  1246. (PSCE_REGISTRY_VALUE_INFO) LocalAlloc(LPTR, sizeof(SCE_REGISTRY_VALUE_INFO)* m_cRegValueSize);
  1247. if(!pProfileInfo->aRegValues)
  1248. {
  1249. hr = E_OUTOFMEMORY;
  1250. goto exit_gracefully;
  1251. }
  1252. }
  1253. //double the array preserving the content
  1254. if( arrayIndex >= m_cRegValueSize )
  1255. {
  1256. PSCE_REGISTRY_VALUE_INFO temp = (PSCE_REGISTRY_VALUE_INFO) LocalAlloc(LPTR, sizeof(SCE_REGISTRY_VALUE_INFO)* m_cRegValueSize * 2);
  1257. if(!temp)
  1258. {
  1259. hr = E_OUTOFMEMORY;
  1260. goto exit_gracefully;
  1261. }
  1262. memcpy(temp,pProfileInfo->aRegValues,sizeof(SCE_REGISTRY_VALUE_INFO)*arrayIndex);
  1263. LocalFree(pProfileInfo->aRegValues);
  1264. pProfileInfo->aRegValues = temp;
  1265. m_cRegValueSize *= 2;
  1266. }
  1267. pProfileInfo->aRegValues[arrayIndex].FullValueName = keyName;
  1268. pProfileInfo->aRegValues[arrayIndex].Value = settingValue;
  1269. pProfileInfo->aRegValues[arrayIndex].ValueType = type;
  1270. pProfileInfo->RegValueCount += 1;
  1271. //Store RSOP_INFO
  1272. pProfileInfo->vecRIRegValues.push_back(pInfo);
  1273. exit_gracefully:
  1274. VariantClear(&bKeyName);
  1275. VariantClear(&vSettingValue);
  1276. VariantClear(&vType);
  1277. _TRACE (-1,L"Leaving CWMIRsop::AddRegValSetting\n");
  1278. return hr;
  1279. }
  1280. HRESULT CWMIRsop::AddRestrictedGroupSetting(IWbemClassObject *rsopInstance,
  1281. PRSOP_INFO pInfo,
  1282. PWMI_SCE_PROFILE_INFO pProfileInfo)
  1283. {
  1284. VARIANT bRGroup;
  1285. PTSTR RGroup;
  1286. VARIANT vMembers;
  1287. HRESULT hr = S_OK;
  1288. _TRACE (1, L"Entering CWMIRsop::AddRestrictedGroupSetting\n");
  1289. hr = rsopInstance->Get(_bstr_t(TEXT("GroupName")),
  1290. 0,
  1291. &bRGroup,
  1292. NULL,
  1293. NULL
  1294. );
  1295. if(FAILED(hr) || bRGroup.vt != VT_BSTR || bRGroup.bstrVal == NULL )
  1296. goto exit_gracefully;
  1297. hr = rsopInstance->Get(_bstr_t(TEXT("Members")),
  1298. 0,
  1299. &vMembers,
  1300. NULL,
  1301. NULL
  1302. );
  1303. if(FAILED(hr))
  1304. goto exit_gracefully;
  1305. DWORD len;
  1306. len = wcslen((PTSTR) V_BSTR(&bRGroup));
  1307. RGroup = (PTSTR) LocalAlloc(LPTR, (len+1) * sizeof(WCHAR));
  1308. if(!RGroup)
  1309. {
  1310. hr = E_OUTOFMEMORY;
  1311. goto exit_gracefully;
  1312. }
  1313. wcscpy(RGroup, (PTSTR) V_BSTR(&bRGroup));
  1314. PSCE_GROUP_MEMBERSHIP head;
  1315. head = pProfileInfo->pGroupMembership;
  1316. if (!head)
  1317. {
  1318. head = (pProfileInfo->pGroupMembership =
  1319. (PSCE_GROUP_MEMBERSHIP) LocalAlloc(LPTR, sizeof(SCE_GROUP_MEMBERSHIP)));
  1320. if(!head)
  1321. {
  1322. hr = E_OUTOFMEMORY;
  1323. goto exit_gracefully;
  1324. }
  1325. }
  1326. else
  1327. {
  1328. PSCE_GROUP_MEMBERSHIP current =
  1329. (PSCE_GROUP_MEMBERSHIP) LocalAlloc(LPTR, sizeof(SCE_GROUP_MEMBERSHIP));
  1330. if(!current)
  1331. {
  1332. hr = E_OUTOFMEMORY;
  1333. goto exit_gracefully;
  1334. }
  1335. current->Next = head;
  1336. head = current;
  1337. pProfileInfo->pGroupMembership = head;
  1338. }
  1339. head->GroupName = RGroup;
  1340. if(V_VT(&vMembers) != VT_NULL)
  1341. {
  1342. SAFEARRAY* ptempArray = NULL;
  1343. BSTR tempString;
  1344. long lowerBoundray=0, upperBoundray=0, loopCount=0;
  1345. ptempArray = V_ARRAY(&vMembers);
  1346. if ( FAILED(SafeArrayGetLBound(ptempArray, 1, &lowerBoundray)) ) lowerBoundray = 0;
  1347. if ( FAILED(SafeArrayGetUBound(ptempArray, 1, &upperBoundray)) ) upperBoundray = 0;
  1348. PSCE_NAME_LIST nameHead = head->pMembers;
  1349. for (loopCount = lowerBoundray; loopCount <= upperBoundray; loopCount++){
  1350. hr = SafeArrayGetElement(ptempArray,
  1351. &loopCount,
  1352. &tempString);
  1353. if ( FAILED(hr) ) goto exit_gracefully;
  1354. if(!nameHead)
  1355. {
  1356. nameHead =
  1357. (head->pMembers = (PSCE_NAME_LIST) LocalAlloc(LPTR, sizeof(SCE_NAME_LIST)));
  1358. if(!nameHead)
  1359. {
  1360. hr = E_OUTOFMEMORY;
  1361. goto exit_gracefully;
  1362. }
  1363. }
  1364. else
  1365. {
  1366. PSCE_NAME_LIST currentName =
  1367. (PSCE_NAME_LIST) LocalAlloc(LPTR, sizeof(SCE_NAME_LIST));
  1368. if(!currentName)
  1369. {
  1370. hr = E_OUTOFMEMORY;
  1371. goto exit_gracefully;
  1372. }
  1373. currentName->Next = nameHead;
  1374. nameHead = currentName;
  1375. head->pMembers = nameHead;
  1376. }
  1377. DWORD nameLen = wcslen((PTSTR) tempString);
  1378. nameHead->Name = (PTSTR) LocalAlloc(LPTR, (nameLen+1) *sizeof(WCHAR) );
  1379. if ( !(nameHead->Name) ) {
  1380. hr = E_OUTOFMEMORY;
  1381. goto exit_gracefully;
  1382. }
  1383. wcscpy(nameHead->Name, (PTSTR) tempString);
  1384. }
  1385. }
  1386. //Add RSOP info
  1387. pProfileInfo->listRIGroupMemebership.push_front(pInfo);
  1388. exit_gracefully:
  1389. VariantClear(&bRGroup);
  1390. VariantClear(&vMembers);
  1391. _TRACE (-1,L"Leaving CWMIRsop::AddRestrictedGroupSetting\n");
  1392. return hr;
  1393. }
  1394. HRESULT CWMIRsop::AddServiceSetting(IWbemClassObject *rsopInstance,
  1395. PRSOP_INFO pInfo,
  1396. PWMI_SCE_PROFILE_INFO pProfileInfo)
  1397. {
  1398. VARIANT bServiceName;
  1399. PTSTR serviceName;
  1400. VARIANT vSDDL;
  1401. VARIANT vStartup;
  1402. PSECURITY_DESCRIPTOR SDDL = NULL;
  1403. DWORD startup;
  1404. HRESULT hr = S_OK;
  1405. _TRACE (1, L"Entering CWMIRsop::AddServiceSetting\n");
  1406. hr = rsopInstance->Get(_bstr_t(TEXT("Service")),
  1407. 0,
  1408. &bServiceName,
  1409. NULL,
  1410. NULL);
  1411. if(FAILED(hr) || bServiceName.vt != VT_BSTR || bServiceName.bstrVal == NULL )
  1412. goto exit_gracefully;
  1413. hr = rsopInstance->Get(_bstr_t(TEXT("SDDLString")),
  1414. 0,
  1415. &vSDDL,
  1416. NULL,
  1417. NULL);
  1418. if(FAILED(hr))
  1419. goto exit_gracefully;
  1420. hr = rsopInstance->Get((BSTR)(TEXT("StartupMode")),
  1421. 0,
  1422. &vStartup,
  1423. NULL,
  1424. NULL);
  1425. if(FAILED(hr))
  1426. goto exit_gracefully;
  1427. DWORD len;
  1428. len = wcslen((PTSTR) V_BSTR(&bServiceName));
  1429. serviceName = (PTSTR) LocalAlloc(LPTR, (len+1) *sizeof(WCHAR));
  1430. if(!serviceName)
  1431. {
  1432. hr = E_OUTOFMEMORY;
  1433. goto exit_gracefully;
  1434. }
  1435. wcscpy(serviceName,(PTSTR) V_BSTR(&bServiceName));
  1436. ULONG sdLen;
  1437. sdLen = 0;
  1438. if( !ConvertStringSecurityDescriptorToSecurityDescriptor(
  1439. (PTSTR) V_BSTR(&vSDDL),
  1440. SDDL_REVISION_1,
  1441. &SDDL,
  1442. &sdLen
  1443. ) )
  1444. {
  1445. hr = HRESULT_FROM_WIN32(GetLastError());
  1446. goto exit_gracefully;
  1447. }
  1448. startup = (DWORD) V_I4(&vStartup);
  1449. PSCE_SERVICES head;
  1450. head = pProfileInfo->pServices;
  1451. if (!head)
  1452. {
  1453. head = (pProfileInfo->pServices =
  1454. (PSCE_SERVICES) LocalAlloc(LPTR, sizeof(SCE_SERVICES)));
  1455. if(!head)
  1456. {
  1457. hr = E_OUTOFMEMORY;
  1458. goto exit_gracefully;
  1459. }
  1460. }
  1461. else
  1462. {
  1463. PSCE_SERVICES current =
  1464. (PSCE_SERVICES) LocalAlloc(LPTR, sizeof(SCE_SERVICES));
  1465. if(!current)
  1466. {
  1467. hr = E_OUTOFMEMORY;
  1468. goto exit_gracefully;
  1469. }
  1470. current->Next = head;
  1471. head = current;
  1472. pProfileInfo->pServices = head;
  1473. }
  1474. head->ServiceName = serviceName;
  1475. head->General.pSecurityDescriptor = SDDL;
  1476. head->Startup = (BYTE) startup; //no data loss value is <= 4
  1477. //Add RSOP info
  1478. pProfileInfo->listRIServices.push_front(pInfo);
  1479. exit_gracefully:
  1480. VariantClear(&bServiceName);
  1481. VariantClear(&vSDDL);
  1482. VariantClear(&vStartup);
  1483. _TRACE (-1,L"Leaving CWMIRsop::AddServiceSetting\n");
  1484. return hr;
  1485. }
  1486. HRESULT CWMIRsop::AddFileSetting(IWbemClassObject *rsopInstance,
  1487. PRSOP_INFO pInfo,
  1488. PWMI_SCE_PROFILE_INFO pProfileInfo)
  1489. {
  1490. VARIANT bFileName;
  1491. PTSTR fileName = NULL;
  1492. VARIANT vSDDL;
  1493. VARIANT vMode;
  1494. PSECURITY_DESCRIPTOR SDDL = NULL;
  1495. DWORD mode = 0;
  1496. _TRACE (1, L"Entering CWMIRsop::AddFileSetting\n");
  1497. HRESULT hr = S_OK;
  1498. hr = rsopInstance->Get((BSTR)(TEXT("Path")),
  1499. 0,
  1500. &bFileName,
  1501. NULL,
  1502. NULL
  1503. );
  1504. if(FAILED(hr) || bFileName.vt != VT_BSTR || bFileName.bstrVal == NULL )
  1505. goto exit_gracefully;
  1506. hr = rsopInstance->Get((BSTR)(TEXT("Mode")),
  1507. 0,
  1508. &vMode,
  1509. NULL,
  1510. NULL
  1511. );
  1512. if(FAILED(hr))
  1513. goto exit_gracefully;
  1514. hr = rsopInstance->Get((BSTR)(TEXT("SDDLString")),
  1515. 0,
  1516. &vSDDL,
  1517. NULL,
  1518. NULL
  1519. );
  1520. if(FAILED(hr))
  1521. goto exit_gracefully;
  1522. DWORD len;
  1523. len = wcslen((PTSTR) V_BSTR(&bFileName));
  1524. fileName = (PTSTR) LocalAlloc(LPTR, len * sizeof(TCHAR) + 2);
  1525. if(!fileName)
  1526. {
  1527. hr = E_OUTOFMEMORY;
  1528. goto exit_gracefully;
  1529. }
  1530. wcscpy(fileName, (PTSTR) V_BSTR(&bFileName));
  1531. mode = (DWORD) V_I4(&vMode);
  1532. if (mode != 1)
  1533. {
  1534. ULONG sdLen = 0;
  1535. if( !ConvertStringSecurityDescriptorToSecurityDescriptor(
  1536. (PTSTR) V_BSTR(&vSDDL),
  1537. SDDL_REVISION_1,
  1538. &SDDL,
  1539. &sdLen
  1540. ))
  1541. {
  1542. hr = HRESULT_FROM_WIN32(GetLastError());
  1543. goto exit_gracefully;
  1544. }
  1545. }
  1546. PSCE_OBJECT_ARRAY head;
  1547. head = pProfileInfo->pFiles.pAllNodes;
  1548. if(!head)
  1549. {
  1550. head = (pProfileInfo->pFiles.pAllNodes =
  1551. (PSCE_OBJECT_ARRAY) LocalAlloc(LPTR, sizeof(SCE_OBJECT_ARRAY)));
  1552. if(!head)
  1553. {
  1554. hr = E_OUTOFMEMORY;
  1555. goto exit_gracefully;
  1556. }
  1557. head->pObjectArray =
  1558. (PSCE_OBJECT_SECURITY*) LocalAlloc(LPTR, sizeof(PSCE_OBJECT_SECURITY)*m_cFileSize);
  1559. if(!head->pObjectArray)
  1560. {
  1561. hr = E_OUTOFMEMORY;
  1562. goto exit_gracefully;
  1563. }
  1564. }
  1565. else if(head->Count >= m_cFileSize)
  1566. {
  1567. PSCE_OBJECT_SECURITY* temp = (PSCE_OBJECT_SECURITY*) LocalAlloc(LPTR, sizeof(PSCE_OBJECT_SECURITY)*m_cFileSize*2);
  1568. if(!temp)
  1569. {
  1570. hr = E_OUTOFMEMORY;
  1571. goto exit_gracefully;
  1572. }
  1573. memcpy(temp,head->pObjectArray,head->Count *sizeof(PSCE_OBJECT_SECURITY));
  1574. LocalFree(head->pObjectArray);
  1575. head->pObjectArray = temp;
  1576. m_cFileSize *=2;
  1577. }
  1578. DWORD index;
  1579. index = head->Count;
  1580. head->pObjectArray[index] =
  1581. (PSCE_OBJECT_SECURITY) LocalAlloc(LPTR, sizeof(SCE_OBJECT_SECURITY));
  1582. if(!head->pObjectArray[index])
  1583. {
  1584. hr = E_OUTOFMEMORY;
  1585. goto exit_gracefully;
  1586. }
  1587. head->pObjectArray[index]->Name = fileName;
  1588. head->pObjectArray[index]->pSecurityDescriptor = SDDL;
  1589. head->pObjectArray[index]->Status = (BYTE) mode;
  1590. head->Count++;
  1591. //SET RSOP INFO
  1592. pProfileInfo->vecRIFiles.push_back(pInfo);
  1593. exit_gracefully:
  1594. VariantClear(&bFileName);
  1595. VariantClear(&vMode);
  1596. if(mode != 1){
  1597. VariantClear(&vSDDL);
  1598. }
  1599. _TRACE (-1,L"Leaving CWMIRsop::AddFileSetting\n");
  1600. return hr;
  1601. }
  1602. HRESULT CWMIRsop::AddRegSetting(IWbemClassObject *rsopInstance,
  1603. PRSOP_INFO pInfo,
  1604. PWMI_SCE_PROFILE_INFO pProfileInfo)
  1605. {
  1606. PTSTR gpoID = NULL;
  1607. VARIANT bFileName;
  1608. PTSTR fileName = NULL;
  1609. VARIANT vSDDL;
  1610. VARIANT vMode;
  1611. PSECURITY_DESCRIPTOR SDDL = NULL;
  1612. DWORD mode = 0;
  1613. static DWORD multiplier = 1;
  1614. HRESULT hr = S_OK;
  1615. _TRACE (1, L"Entering CWMIRsop::AddRegSetting\n");
  1616. hr = rsopInstance->Get((BSTR)(TEXT("Path")),
  1617. 0,
  1618. &bFileName,
  1619. NULL,
  1620. NULL
  1621. );
  1622. if(FAILED(hr) || bFileName.vt != VT_BSTR || bFileName.bstrVal == NULL )
  1623. goto exit_gracefully;
  1624. hr = rsopInstance->Get((BSTR)(TEXT("Mode")),
  1625. 0,
  1626. &vMode,
  1627. NULL,
  1628. NULL
  1629. );
  1630. if(FAILED(hr))
  1631. goto exit_gracefully;
  1632. hr = rsopInstance->Get((BSTR)(TEXT("SDDLString")),
  1633. 0,
  1634. &vSDDL,
  1635. NULL,
  1636. NULL
  1637. );
  1638. if(FAILED(hr))
  1639. goto exit_gracefully;
  1640. DWORD len;
  1641. len = wcslen((PTSTR) V_BSTR(&bFileName));
  1642. fileName = (PTSTR) LocalAlloc(LPTR, len * sizeof(TCHAR) + 2);
  1643. if(!fileName)
  1644. {
  1645. hr = E_OUTOFMEMORY;
  1646. goto exit_gracefully;
  1647. }
  1648. wcscpy(fileName, (PTSTR) V_BSTR(&bFileName));
  1649. mode = (DWORD) V_I4(&vMode);
  1650. if (mode != 1)
  1651. {
  1652. ULONG sdLen = 0;
  1653. if( !ConvertStringSecurityDescriptorToSecurityDescriptor(
  1654. (PTSTR) V_BSTR(&vSDDL),
  1655. SDDL_REVISION_1,
  1656. &SDDL,
  1657. &sdLen
  1658. ))
  1659. {
  1660. hr = HRESULT_FROM_WIN32(GetLastError());
  1661. goto exit_gracefully;
  1662. }
  1663. }
  1664. PSCE_OBJECT_ARRAY head;
  1665. head = pProfileInfo->pRegistryKeys.pAllNodes;
  1666. if(!head){
  1667. head = (pProfileInfo->pRegistryKeys.pAllNodes =
  1668. (PSCE_OBJECT_ARRAY) LocalAlloc(LPTR, sizeof(SCE_OBJECT_ARRAY)));
  1669. if(!head)
  1670. {
  1671. hr = E_OUTOFMEMORY;
  1672. goto exit_gracefully;
  1673. }
  1674. head->pObjectArray =
  1675. (PSCE_OBJECT_SECURITY*) LocalAlloc(LPTR, sizeof(PSCE_OBJECT_SECURITY)*m_cRegArrayCount);
  1676. if(!head->pObjectArray)
  1677. {
  1678. hr = E_OUTOFMEMORY;
  1679. goto exit_gracefully;
  1680. }
  1681. }
  1682. else if(head->Count >= m_cRegArrayCount){
  1683. PSCE_OBJECT_SECURITY* temp = head->pObjectArray;
  1684. head->pObjectArray =
  1685. (PSCE_OBJECT_SECURITY*) LocalAlloc(LPTR, sizeof(PSCE_OBJECT_SECURITY)*m_cRegArrayCount*2);
  1686. if(!head->pObjectArray)
  1687. {
  1688. hr = E_OUTOFMEMORY;
  1689. goto exit_gracefully;
  1690. }
  1691. memcpy(head->pObjectArray,temp,head->Count *sizeof(PSCE_OBJECT_SECURITY));
  1692. LocalFree(temp);
  1693. m_cRegArrayCount *= 2;
  1694. }
  1695. //
  1696. // Can't initialize at declaration since this is skipped by gotos
  1697. //
  1698. DWORD index;
  1699. index = head->Count;
  1700. head->pObjectArray[index] =
  1701. (PSCE_OBJECT_SECURITY) LocalAlloc(LPTR, sizeof(SCE_OBJECT_SECURITY));
  1702. if (head->pObjectArray[index]) {
  1703. head->pObjectArray[index]->Name = fileName;
  1704. head->pObjectArray[index]->pSecurityDescriptor = SDDL;
  1705. head->pObjectArray[index]->Status = (BYTE) mode;
  1706. head->Count++;
  1707. }
  1708. //add rsop info
  1709. pProfileInfo->vecRIReg.push_back(pInfo);
  1710. exit_gracefully:
  1711. VariantClear(&bFileName);
  1712. VariantClear(&vMode);
  1713. if(mode != 1){
  1714. VariantClear(&vSDDL);
  1715. }
  1716. _TRACE (-1, L"Leaving CWMIRsop::AddRegSetting\n");
  1717. return hr;
  1718. }
  1719. HRESULT CWMIRsop::AddStringSetting (IWbemClassObject *rsopInstance,
  1720. PRSOP_INFO pInfo,
  1721. PWMI_SCE_PROFILE_INFO pProfileInfo)
  1722. {
  1723. HRESULT hr = S_OK;
  1724. VARIANT bKeyName;
  1725. PWSTR keyName = 0;
  1726. VARIANT bSettingValue;
  1727. PWSTR settingValue = 0;
  1728. _TRACE (1, L"Entering CWMIRsop::AddStringSetting\n");
  1729. hr = rsopInstance->Get((BSTR)RSOP_KEYNAME,
  1730. 0,
  1731. &bKeyName,
  1732. NULL,
  1733. NULL);
  1734. if( FAILED(hr) || bKeyName.vt != VT_BSTR || bKeyName.bstrVal == NULL)
  1735. goto exit_gracefully;
  1736. hr = rsopInstance->Get((BSTR)RSOP_SETTING,
  1737. 0,
  1738. &bSettingValue,
  1739. NULL,
  1740. NULL);
  1741. if( FAILED(hr) || bSettingValue.vt != VT_BSTR || bSettingValue.bstrVal == NULL)
  1742. goto exit_gracefully;
  1743. keyName = V_BSTR(&bKeyName);
  1744. settingValue = V_BSTR(&bSettingValue);
  1745. if (!_wcsicmp(keyName, NEW_GUEST_NAME))
  1746. {
  1747. if ( 0 != pProfileInfo->NewGuestName )
  1748. {
  1749. LocalFree (pProfileInfo->NewGuestName);
  1750. pProfileInfo->NewGuestName = 0;
  1751. }
  1752. size_t len = wcslen (settingValue);
  1753. pProfileInfo->NewGuestName = (PWSTR) LocalAlloc (LPTR, (len + 1) * sizeof (TCHAR));
  1754. if ( pProfileInfo->NewGuestName )
  1755. {
  1756. wcscpy (pProfileInfo->NewGuestName, settingValue);
  1757. }
  1758. else
  1759. hr = E_OUTOFMEMORY;
  1760. pProfileInfo->pRINewGuestName = pInfo;
  1761. }
  1762. else if (!_wcsicmp(keyName, NEW_ADMINISTRATOR_NAME))
  1763. {
  1764. if ( 0 != pProfileInfo->NewAdministratorName )
  1765. {
  1766. LocalFree (pProfileInfo->NewAdministratorName);
  1767. pProfileInfo->NewAdministratorName = 0;
  1768. }
  1769. size_t len = wcslen (settingValue);
  1770. pProfileInfo->NewAdministratorName = (PWSTR) LocalAlloc (LPTR, (len + 1) * sizeof (TCHAR));
  1771. if ( pProfileInfo->NewAdministratorName )
  1772. {
  1773. wcscpy (pProfileInfo->NewAdministratorName, settingValue);
  1774. }
  1775. else
  1776. hr = E_OUTOFMEMORY;
  1777. pProfileInfo->pRINewAdministratorName = pInfo;
  1778. }
  1779. else
  1780. {
  1781. _ASSERT (FALSE); // key name not accounted for
  1782. }
  1783. exit_gracefully:
  1784. VariantClear(&bKeyName);
  1785. VariantClear(&bSettingValue);
  1786. _TRACE (-1,L"Leaving CWMIRsop::AddStringSetting\n");
  1787. return hr;
  1788. }
  1789. HRESULT CWMIRsop::AddInstance(IWbemClassObject *rsopInstance,
  1790. PRSOP_INFO pInfo,
  1791. PWMI_SCE_PROFILE_INFO pProfileInfo)
  1792. {
  1793. HRESULT hr = S_OK;
  1794. LPWSTR className = NULL;
  1795. _TRACE (1, L"Entering CWMIRsop::AddInstance\n");
  1796. //Get RSOP_Class Name
  1797. hr = GetClass(rsopInstance, &className);
  1798. if( FAILED(hr) )
  1799. goto exit_gracefully;
  1800. if(!_wcsicmp(className, RSOP_SEC_NUM))
  1801. {
  1802. hr = AddNumericSetting(rsopInstance,
  1803. pInfo,
  1804. pProfileInfo);
  1805. }
  1806. else if(!_wcsicmp(className, RSOP_SEC_BOOL))
  1807. {
  1808. hr = AddBooleanSetting(rsopInstance,
  1809. pInfo,
  1810. pProfileInfo);
  1811. }
  1812. else if(!_wcsicmp(className, RSOP_SCE_STRING))
  1813. {
  1814. hr = AddStringSetting(rsopInstance,pInfo,pProfileInfo);
  1815. }
  1816. else if(!_wcsicmp(className, RSOP_AUDIT))
  1817. {
  1818. hr = AddAuditSetting(rsopInstance,pInfo,pProfileInfo);
  1819. }
  1820. else if(!_wcsicmp(className, RSOP_EVENT_NUM))
  1821. {
  1822. hr = AddEventLogNumericSetting (rsopInstance, pInfo, pProfileInfo);
  1823. }
  1824. else if(!_wcsicmp(className, RSOP_EVENT_BOOL))
  1825. {
  1826. hr = AddEventLogBooleanSetting(rsopInstance,pInfo,pProfileInfo);
  1827. }
  1828. else if(!_wcsicmp(className, RSOP_REG_VAL))
  1829. {
  1830. hr = AddRegValSetting(rsopInstance,pInfo,pProfileInfo);
  1831. }
  1832. else if(!_wcsicmp(className, RSOP_USER_RIGHT))
  1833. {
  1834. hr = AddUserRightSetting(rsopInstance,pInfo,pProfileInfo);
  1835. }
  1836. else if(!_wcsicmp(className, RSOP_RGROUPS))
  1837. {
  1838. hr = AddRestrictedGroupSetting(rsopInstance,pInfo,pProfileInfo);
  1839. }
  1840. else if(!_wcsicmp(className, RSOP_SERVICE))
  1841. {
  1842. hr = AddServiceSetting(rsopInstance,pInfo,pProfileInfo);
  1843. }
  1844. else if(!_wcsicmp(className, RSOP_FILE))
  1845. {
  1846. hr = AddFileSetting(rsopInstance,pInfo,pProfileInfo);
  1847. }
  1848. else if(!_wcsicmp(className, RSOP_REG))
  1849. {
  1850. hr = AddRegSetting(rsopInstance,pInfo,pProfileInfo);
  1851. }
  1852. else
  1853. {
  1854. _ASSERT (FALSE); // class not accounted for
  1855. }
  1856. exit_gracefully:
  1857. _TRACE (-1,L"Exiting CWMIRsop::AddInstance\n");
  1858. LocalFree(className);
  1859. return hr;
  1860. }
  1861. HRESULT
  1862. CWMIRsop::GetGPOFriendlyName (PWSTR lpGPOID, PWSTR *pGPOName)
  1863. {
  1864. BSTR pQuery = NULL, pName = NULL;
  1865. LPTSTR lpQuery = NULL;
  1866. IEnumWbemClassObject * pEnum = NULL;
  1867. IWbemClassObject *pObjects[2];
  1868. HRESULT hr;
  1869. ULONG ulRet;
  1870. VARIANT varGPOName;
  1871. //
  1872. // Set the default
  1873. //
  1874. *pGPOName = NULL;
  1875. //
  1876. // Build the query
  1877. //
  1878. lpQuery = (LPTSTR) LocalAlloc (LPTR, ((lstrlen(lpGPOID) + 50) * sizeof(TCHAR)));
  1879. if (!lpQuery)
  1880. {
  1881. _TRACE (0, L"CWMIRsop::GetGPOFriendlyName: Failed to allocate memory for unicode query");
  1882. hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
  1883. goto Exit;
  1884. }
  1885. wsprintf (lpQuery, TEXT("SELECT name, id FROM RSOP_GPO where id=\"%s\""), lpGPOID);
  1886. pQuery = SysAllocString (lpQuery);
  1887. if (!pQuery)
  1888. {
  1889. _TRACE (0, L"CWMIRsop::GetGPOFriendlyName: Failed to allocate memory for query");
  1890. hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
  1891. goto Exit;
  1892. }
  1893. //
  1894. // Allocate BSTRs for the property names we want to retreive
  1895. //
  1896. pName = SysAllocString (TEXT("name"));
  1897. if (!pName)
  1898. {
  1899. _TRACE (0, L"CWMIRsop::GetGPOFriendlyName: Failed to allocate memory for name");
  1900. hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
  1901. goto Exit;
  1902. }
  1903. //
  1904. // Execute the query
  1905. //
  1906. hr = m_pSvc->ExecQuery (_bstr_t(QUERY_LANG), pQuery,
  1907. WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
  1908. NULL, &pEnum);
  1909. if (FAILED(hr))
  1910. {
  1911. _TRACE (0, L"CWMIRsop::GetGPOFriendlyName: Failed to query for %s with 0x%x\n",
  1912. pQuery, hr);
  1913. goto Exit;
  1914. }
  1915. //
  1916. // Loop through the results
  1917. //
  1918. hr = pEnum->Next(WBEM_INFINITE, 1, pObjects, &ulRet);
  1919. if (FAILED(hr))
  1920. {
  1921. _TRACE (0, L"CWMIRsop::GetGPOFriendlyName: Failed to get first item in query results for %s with 0x%x\n",
  1922. pQuery, hr);
  1923. goto Exit;
  1924. }
  1925. //
  1926. // Check for the "data not available case"
  1927. //
  1928. if (ulRet == 0)
  1929. {
  1930. hr = S_OK;
  1931. goto Exit;
  1932. }
  1933. //
  1934. // Get the name
  1935. //
  1936. VariantInit(&varGPOName);
  1937. hr = pObjects[0]->Get (pName, 0, &varGPOName, NULL, NULL);
  1938. if (FAILED(hr))
  1939. {
  1940. _TRACE (0, L"CWMIRsop::GetGPOFriendlyName: Failed to get gponame in query results for %s with 0x%x\n",
  1941. pQuery, hr);
  1942. goto Exit;
  1943. }
  1944. //
  1945. // Save the name
  1946. //
  1947. *pGPOName = (LPTSTR) LocalAlloc (LPTR, (lstrlen(varGPOName.bstrVal) + 1) * sizeof(TCHAR));
  1948. if (!(*pGPOName))
  1949. {
  1950. _TRACE (0, L"CWMIRsop::GetGPOFriendlyName: Failed to allocate memory for GPO Name");
  1951. hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
  1952. goto Exit;
  1953. }
  1954. lstrcpy (*pGPOName, varGPOName.bstrVal);
  1955. hr = S_OK;
  1956. Exit:
  1957. VariantClear (&varGPOName);
  1958. if (pEnum)
  1959. {
  1960. pEnum->Release();
  1961. }
  1962. if (pQuery)
  1963. {
  1964. SysFreeString (pQuery);
  1965. }
  1966. if (lpQuery)
  1967. {
  1968. LocalFree (lpQuery);
  1969. }
  1970. if (pName)
  1971. {
  1972. SysFreeString (pName);
  1973. }
  1974. return hr;
  1975. }