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.

3342 lines
130 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. precedence.cpp
  5. Abstract:
  6. This file contains the main routine to calculate precedences.
  7. This is called during planning/diagnosis.
  8. Author:
  9. Vishnu Patankar (VishnuP) 7-April-2000
  10. Environment:
  11. User Mode - Win32
  12. Revision History:
  13. --*/
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // //
  16. // Includes //
  17. // //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include "precedence.h"
  20. #include "logger.h"
  21. #include "infp.h"
  22. #include "headers.h"
  23. #include "align.h"
  24. #include "..\sceutil.h"
  25. #include <io.h>
  26. #include "scerpc.h"
  27. extern BOOL gbAsyncWinlogonThread;
  28. extern HRESULT gHrSynchRsopStatus;
  29. extern HRESULT gHrAsynchRsopStatus;
  30. extern BOOL gbThisIsDC;
  31. extern BOOL gbDCQueried;
  32. extern PWSTR gpwszDCDomainName;
  33. extern HINSTANCE MyModuleHandle;
  34. WCHAR gpwszPlanOrDiagLogFile[MAX_PATH];
  35. ///////////////////////////////////////////////////////////////////////////////
  36. // //
  37. // Private defines //
  38. // //
  39. ///////////////////////////////////////////////////////////////////////////////
  40. #define SCEP_VALID_NAME(pName) (pName[0] == L'\0' ? NULL : pName)
  41. //
  42. // prime nos are good for hashing
  43. //
  44. #define PRIVILEGE_TABLE_SIZE 7
  45. #define GROUP_TABLE_SIZE 7
  46. #define REGISTRY_SECURITY_TABLE_SIZE 43
  47. #define FILE_SECURITY_TABLE_SIZE 43
  48. #define REGISTRY_VALUE_TABLE_SIZE 43
  49. #define SERVICES_TABLE_SIZE 5
  50. //
  51. // macro to gracefully handle errors
  52. //
  53. #define SCEP_RSOP_CONTINUE_OR_BREAK if (rc != NO_ERROR ) {\
  54. rcSave = rc;\
  55. if (rc == ERROR_NOT_ENOUGH_MEMORY)\
  56. break;\
  57. }
  58. //
  59. // macro to gracefully handle errors
  60. //
  61. #define SCEP_RSOP_CONTINUE_OR_GOTO if (rc != NO_ERROR ) {\
  62. rcSave = rc;\
  63. if (rc == ERROR_NOT_ENOUGH_MEMORY)\
  64. goto Done;\
  65. }
  66. const UINT NumSchemaClasses = sizeof ScepRsopSchemaClassNames/ sizeof(PWSTR);
  67. const UINT NumSettings = sizeof PrecedenceLookup/ sizeof(SCE_KEY_LOOKUP_PRECEDENCE);
  68. DWORD SceLogSettingsPrecedenceGPOs(
  69. IN IWbemServices *pWbemServices,
  70. IN BOOL bPlanningMode,
  71. IN PWSTR *ppwszLogFile
  72. )
  73. ///////////////////////////////////////////////////////////////////////////////
  74. // precedence algorithm ///
  75. // foreach GPO (parse all gpt*.* into SceProfileInfoBuffer) ///
  76. // foreach setting in a GPO (log the values and precedences if present)///
  77. ///////////////////////////////////////////////////////////////////////////////
  78. {
  79. PSCE_PROFILE_INFO pSceProfileInfoBuffer = NULL;
  80. PWSTR pwszGPOName = NULL;
  81. PWSTR pwszSOMID = NULL;
  82. DWORD rc = ERROR_SUCCESS;
  83. DWORD rcSave = ERROR_SUCCESS;
  84. BOOL bKerberosBlob = FALSE;
  85. PWSTR Windir = NULL;
  86. PWSTR TemplatePath = NULL;
  87. SCEP_HASH_TABLE PrivilegeHashTable(PRIVILEGE_TABLE_SIZE);
  88. SCEP_HASH_TABLE GroupHashTable(GROUP_TABLE_SIZE);
  89. SCEP_HASH_TABLE RegistrySecurityHashTable(REGISTRY_SECURITY_TABLE_SIZE);
  90. SCEP_HASH_TABLE FileSecurityHashTable(FILE_SECURITY_TABLE_SIZE);
  91. SCEP_HASH_TABLE RegistryValueHashTable(REGISTRY_VALUE_TABLE_SIZE);
  92. SCEP_HASH_TABLE ServicesHashTable(SERVICES_TABLE_SIZE);
  93. SafeAllocaAllocate( Windir, (MAX_PATH + 1) * sizeof(WCHAR) );
  94. SafeAllocaAllocate( TemplatePath, (MAX_PATH + 50 + 1) * sizeof(WCHAR) );
  95. if (NULL == Windir ||
  96. NULL == TemplatePath) {
  97. goto ExitHandler;
  98. }
  99. //
  100. // get the path to the templates
  101. //
  102. GetSystemWindowsDirectory(Windir, MAX_PATH);
  103. Windir[MAX_PATH-1] = L'\0';
  104. if (bPlanningMode) {
  105. swprintf(TemplatePath,
  106. L"%s"PLANNING_GPT_DIR L"gpt*.*",
  107. Windir);
  108. } else {
  109. swprintf(TemplatePath,
  110. L"%s"DIAGNOSIS_GPT_DIR L"gpt*.*",
  111. Windir);
  112. }
  113. gpwszPlanOrDiagLogFile[MAX_PATH-1] = L'\0';
  114. //
  115. // old planning.log/diagnosis.log removed (*ppwszLogFile != NULL if verbose)
  116. //
  117. if (*ppwszLogFile) {
  118. if (bPlanningMode) {
  119. wcscpy(gpwszPlanOrDiagLogFile, *ppwszLogFile);
  120. } else {
  121. wcscpy(gpwszPlanOrDiagLogFile, Windir);
  122. wcscat(gpwszPlanOrDiagLogFile, DIAGNOSIS_LOG_FILE);
  123. }
  124. WCHAR szTmpName[MAX_PATH];
  125. wcscpy(szTmpName, gpwszPlanOrDiagLogFile);
  126. UINT Len = wcslen(szTmpName);
  127. szTmpName[Len-3] = L'o';
  128. szTmpName[Len-2] = L'l';
  129. szTmpName[Len-1] = L'd';
  130. CopyFile( gpwszPlanOrDiagLogFile, szTmpName, FALSE );
  131. DeleteFile(gpwszPlanOrDiagLogFile);
  132. } else {
  133. gpwszPlanOrDiagLogFile[0] = L'\0';
  134. }
  135. //
  136. // clear the database log - if something fails continue
  137. //
  138. for (UINT schemaClassNum = 0; schemaClassNum < NumSchemaClasses ; schemaClassNum++ ) {
  139. rc = ScepWbemErrorToDosError(DeleteInstances(
  140. ScepRsopSchemaClassNames[schemaClassNum],
  141. pWbemServices
  142. ));
  143. if (rc != NO_ERROR)
  144. rcSave = rc;
  145. }
  146. ScepLogEventAndReport(MyModuleHandle,
  147. gpwszPlanOrDiagLogFile,
  148. 0,
  149. 0,
  150. IDS_CLEAR_RSOP_DB,
  151. rcSave,
  152. NULL
  153. );
  154. //
  155. // need to process the files from gpt9999* -> gpt0000* (opposite of jetdb merge)
  156. // use LIFO linked stack of gpt* filenames
  157. //
  158. intptr_t hFile;
  159. struct _wfinddata_t FileInfo;
  160. HINF hInf;
  161. hFile = _wfindfirst(TemplatePath, &FileInfo);
  162. PSCE_NAME_STATUS_LIST pGptNameList = NULL;
  163. if ( hFile != -1 ) {
  164. do {
  165. if (ERROR_NOT_ENOUGH_MEMORY == (rc = ScepAddToNameStatusList(
  166. &pGptNameList,
  167. FileInfo.name,
  168. wcslen(FileInfo.name),
  169. 0))) {
  170. _findclose(hFile);
  171. if (pGptNameList)
  172. ScepFreeNameStatusList(pGptNameList);
  173. rcSave = ERROR_NOT_ENOUGH_MEMORY;
  174. goto ExitHandler;
  175. }
  176. } while ( _wfindnext(hFile, &FileInfo) == 0 );
  177. _findclose(hFile);
  178. }
  179. //
  180. // first get all the GPOs, and some other info needed for logging
  181. // this is the outermost loop (per gpt*.* template)
  182. //
  183. PSCE_NAME_STATUS_LIST pCurrFileName = pGptNameList;
  184. while (pCurrFileName) {
  185. DWORD dwAuditLogRetentionPeriod[] = {SCE_NO_VALUE, SCE_NO_VALUE, SCE_NO_VALUE};
  186. DWORD dwLockoutBadCount = SCE_NO_VALUE;
  187. if (bPlanningMode) {
  188. swprintf(TemplatePath,
  189. L"%s"PLANNING_GPT_DIR L"%s",
  190. Windir, pCurrFileName->Name);
  191. } else {
  192. swprintf(TemplatePath,
  193. L"%s"DIAGNOSIS_GPT_DIR L"%s",
  194. Windir, pCurrFileName->Name);
  195. }
  196. //
  197. // open template file
  198. //
  199. rc = SceInfpOpenProfile(
  200. TemplatePath,
  201. &hInf
  202. );
  203. DWORD dSize = 0;
  204. INFCONTEXT InfLine;
  205. //
  206. // get GPO name - default to "NoName" if unable to get it
  207. //
  208. if (rc == ERROR_SUCCESS) {
  209. if ( SetupFindFirstLine(hInf,L"Version",L"DSPath",&InfLine) ) {
  210. if (SetupGetStringField(&InfLine,1,NULL,0,&dSize) && dSize > 0) {
  211. pwszGPOName = (PWSTR)ScepAlloc( 0, (dSize+1)*sizeof(WCHAR));
  212. if (!pwszGPOName) {
  213. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  214. SceInfpCloseProfile(hInf);
  215. goto NextGPO;
  216. }
  217. pwszGPOName[dSize] = L'\0';
  218. SetupGetStringField(&InfLine,1,pwszGPOName,dSize, NULL);
  219. }
  220. else
  221. rc = GetLastError();
  222. }
  223. else
  224. rc = GetLastError();
  225. if (rc != ERROR_SUCCESS) {
  226. //
  227. // log this error and continue this GPO by initializing pwszGPOName to "NoGPOName"
  228. //
  229. if (pwszGPOName)
  230. ScepFree(pwszGPOName);
  231. rcSave = rc;
  232. pwszGPOName = (PWSTR)ScepAlloc( 0, (9+1)*sizeof(WCHAR));
  233. if (!pwszGPOName) {
  234. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  235. rcSave = rc;
  236. SceInfpCloseProfile(hInf);
  237. goto NextGPO;
  238. }
  239. wcscpy(pwszGPOName, L"NoGPOName");
  240. ScepLogEventAndReport(MyModuleHandle,
  241. gpwszPlanOrDiagLogFile,
  242. 0,
  243. 0,
  244. IDS_ERROR_OPEN_CACHED_GPO,
  245. rc,
  246. TemplatePath
  247. );
  248. }
  249. } else {
  250. rcSave = rc;
  251. ScepLogEventAndReport(MyModuleHandle,
  252. gpwszPlanOrDiagLogFile,
  253. 0,
  254. 0,
  255. IDS_ERROR_OPEN_CACHED_GPO,
  256. rc,
  257. TemplatePath
  258. );
  259. //
  260. // will continue with next GPO
  261. //
  262. goto NextGPO;
  263. }
  264. //
  265. // get SOMID - default to "NoSOMID" if unable to get it
  266. //
  267. if ( SetupFindFirstLine(hInf,L"Version",L"SOMID",&InfLine) ) {
  268. if (SetupGetStringField(&InfLine,1,NULL,0,&dSize) && dSize > 0) {
  269. pwszSOMID = (PWSTR)ScepAlloc( 0, (dSize+1)*sizeof(WCHAR));
  270. pwszSOMID[dSize] = L'\0';
  271. SetupGetStringField(&InfLine,1,pwszSOMID,dSize, NULL);
  272. } else
  273. rc = GetLastError();
  274. } else
  275. rc = GetLastError();
  276. if (rc != ERROR_SUCCESS) {
  277. //
  278. // log this error and continue this GPO by initializing pwszGPOName to "NoGPOName"
  279. //
  280. if (pwszSOMID)
  281. ScepFree(pwszSOMID);
  282. rcSave = rc;
  283. pwszSOMID = (PWSTR)ScepAlloc( 0, (7 + 1)*sizeof(WCHAR));
  284. if (!pwszSOMID) {
  285. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  286. rcSave = rc;
  287. SceInfpCloseProfile(hInf);
  288. goto NextGPO;
  289. }
  290. wcscpy(pwszSOMID, L"NoSOMID");
  291. ScepLogEventAndReport(MyModuleHandle,
  292. gpwszPlanOrDiagLogFile,
  293. 0,
  294. 0,
  295. IDS_ERROR_OPEN_CACHED_GPO,
  296. rc,
  297. TemplatePath
  298. );
  299. }
  300. rc = SceInfpGetSecurityProfileInfo(
  301. hInf,
  302. AREA_ALL,
  303. &pSceProfileInfoBuffer,
  304. NULL
  305. );
  306. if (rc != ERROR_SUCCESS) {
  307. rcSave = rc;
  308. SceInfpCloseProfile(hInf);
  309. ScepLogEventAndReport(MyModuleHandle,
  310. gpwszPlanOrDiagLogFile,
  311. 0,
  312. 0,
  313. IDS_ERROR_OPEN_CACHED_GPO,
  314. rc,
  315. TemplatePath
  316. );
  317. //
  318. // will continue with next GPO
  319. //
  320. goto NextGPO;
  321. }
  322. SceInfpCloseProfile(hInf);
  323. ScepLogEventAndReport(MyModuleHandle,
  324. gpwszPlanOrDiagLogFile,
  325. 0,
  326. 0,
  327. IDS_INFO_RSOP_LOG,
  328. rc,
  329. pwszGPOName
  330. );
  331. //
  332. // now the info buffer is successfully populated - need to
  333. // iterate over all settings for this GPO
  334. //
  335. //
  336. // to efficiently access fields(settings) in the info buffer, we use a lookup table of
  337. // precomputed offsets
  338. //
  339. //
  340. // a matrix holds precedence info for fields whose locations are well known in memory
  341. // and hash-tables hold precedence info for fields whose locations are dynamic
  342. //
  343. //
  344. // try except around each log attempt - intention is to continue with next setting if
  345. // logging for current setting fails
  346. // guarded code does not explicitly throw any exceptions - error codes are set instead
  347. // so, if we get an exception it is thrown by the system in which case we ignore and continue
  348. //
  349. //
  350. // this is the second loop (setting per gpt*.* template)
  351. //
  352. bKerberosBlob = FALSE;
  353. for (UINT settingNo = 0; settingNo < NumSettings; settingNo++) {
  354. CHAR settingType = PrecedenceLookup[settingNo].KeyLookup.BufferType;
  355. PWSTR pSettingName = PrecedenceLookup[settingNo].KeyLookup.KeyString;
  356. UINT settingOffset = PrecedenceLookup[settingNo].KeyLookup.Offset;
  357. DWORD *pSettingPrecedence = &PrecedenceLookup[settingNo].Precedence;
  358. BOOL bSystemAccessPolicy = PrecedenceLookup[settingNo].bSystemAccessPolicy;
  359. BOOL bLogErrorOutsideSwitch = TRUE;
  360. //
  361. // depending on the schema class being processed, we instantiate logger objects
  362. //
  363. // on BDCs, skip system access policies
  364. if (gMachineRole == DsRole_RoleBackupDomainController &&
  365. bSystemAccessPolicy == TRUE)
  366. {
  367. continue;
  368. }
  369. switch (settingType) {
  370. case RSOP_SecuritySettingNumeric:
  371. try {
  372. {
  373. RSOP_SecuritySettingNumericLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  374. //
  375. // special case kerberos since it is dynamically allocated
  376. //
  377. if (_wcsicmp(pSettingName, L"pKerberosInfo") == 0)
  378. bKerberosBlob = TRUE;
  379. if (bKerberosBlob == FALSE &&
  380. (bPlanningMode ||
  381. !(gbDCQueried == TRUE && gbThisIsDC == TRUE) ||
  382. ((gbDCQueried == TRUE && gbThisIsDC == TRUE) && wcsstr(pCurrFileName->Name, L".dom")))) {
  383. DWORD dwValue = SCEP_TYPECAST(DWORD, pSceProfileInfoBuffer, settingOffset);
  384. if (dwValue != SCE_NO_VALUE) {
  385. //
  386. // LockoutBadCount controls two other lockout settings - so remember
  387. //
  388. if (_wcsicmp(pSettingName, L"LockoutBadCount") == 0)
  389. dwLockoutBadCount = dwValue;
  390. //
  391. // skip if dwLockoutBadCount == 0
  392. //
  393. if (_wcsicmp(pSettingName, L"ResetLockoutCount") == 0 &&
  394. (dwLockoutBadCount == 0 || dwLockoutBadCount == SCE_NO_VALUE))
  395. continue;
  396. if (_wcsicmp(pSettingName, L"LockoutDuration") == 0 &&
  397. (dwLockoutBadCount == 0 || dwLockoutBadCount == SCE_NO_VALUE))
  398. continue;
  399. rc = ScepWbemErrorToDosError(Log.Log(
  400. pSettingName,
  401. dwValue,
  402. ++(*pSettingPrecedence)
  403. ));
  404. if (rc == NO_ERROR)
  405. ScepLogEventAndReport(MyModuleHandle,
  406. gpwszPlanOrDiagLogFile,
  407. 0,
  408. 0,
  409. IDS_INFO_RSOP_LOG,
  410. rc,
  411. pSettingName
  412. );
  413. if (rc != NO_ERROR)
  414. break;
  415. }
  416. } else if (bKerberosBlob == TRUE &&
  417. (bPlanningMode ||
  418. ((gbDCQueried == TRUE && gbThisIsDC == TRUE) && wcsstr(pCurrFileName->Name, L".dom")))) {
  419. //
  420. // kerberos only if DC from *.dom. If planning mode don't care type of m/c
  421. //
  422. PSCE_KERBEROS_TICKET_INFO pKerberosInfo =
  423. SCEP_TYPECAST(PSCE_KERBEROS_TICKET_INFO, pSceProfileInfoBuffer, settingOffset);
  424. bLogErrorOutsideSwitch = FALSE;
  425. if (pKerberosInfo) {
  426. //
  427. // kerberos numeric
  428. //
  429. for (UINT NumericSubSetting = 1; NumericSubSetting < NUM_KERBEROS_SUB_SETTINGS; NumericSubSetting++ ) {
  430. pSettingName = PrecedenceLookup[settingNo + NumericSubSetting].KeyLookup.KeyString;
  431. settingOffset = PrecedenceLookup[settingNo + NumericSubSetting].KeyLookup.Offset;
  432. pSettingPrecedence = &PrecedenceLookup[settingNo + NumericSubSetting].Precedence;
  433. DWORD dwValue = SCEP_TYPECAST(DWORD, pKerberosInfo, settingOffset);
  434. if (dwValue != SCE_NO_VALUE) {
  435. rc = ScepWbemErrorToDosError(Log.Log(
  436. pSettingName,
  437. dwValue,
  438. ++(*pSettingPrecedence)
  439. ));
  440. ScepLogEventAndReport(MyModuleHandle,
  441. gpwszPlanOrDiagLogFile,
  442. 0,
  443. 0,
  444. IDS_INFO_RSOP_LOG,
  445. rc,
  446. pSettingName
  447. );
  448. SCEP_RSOP_CONTINUE_OR_BREAK
  449. }
  450. }
  451. //
  452. //kerberos boolean (moved here to incompatible case: statement - to avoid a goto)
  453. //
  454. pSettingName = PrecedenceLookup[settingNo + NUM_KERBEROS_SUB_SETTINGS].KeyLookup.KeyString;
  455. settingOffset = PrecedenceLookup[settingNo + NUM_KERBEROS_SUB_SETTINGS].KeyLookup.Offset;
  456. pSettingPrecedence = &PrecedenceLookup[settingNo + NUM_KERBEROS_SUB_SETTINGS].Precedence;
  457. DWORD dwValue = SCEP_TYPECAST(DWORD, pKerberosInfo, settingOffset);
  458. RSOP_SecuritySettingBooleanLogger LogBool(pWbemServices, pwszGPOName, pwszSOMID);
  459. if (rc != ERROR_NOT_ENOUGH_MEMORY &&
  460. dwValue != SCE_NO_VALUE) {
  461. rc = ScepWbemErrorToDosError(LogBool.Log(
  462. pSettingName,
  463. dwValue,
  464. ++(*pSettingPrecedence)
  465. ));
  466. ScepLogEventAndReport(MyModuleHandle,
  467. gpwszPlanOrDiagLogFile,
  468. 0,
  469. 0,
  470. IDS_INFO_RSOP_LOG,
  471. rc,
  472. pSettingName
  473. );
  474. if (rc != NO_ERROR ) {
  475. rcSave = rc;
  476. }
  477. }
  478. }
  479. }
  480. //
  481. // just processed NUM_KERBEROS_SUB_SETTINGS
  482. //
  483. if (bKerberosBlob)
  484. settingNo += NUM_KERBEROS_SUB_SETTINGS;
  485. }
  486. } catch (...) {
  487. //
  488. // system error continue with next setting
  489. //
  490. rc = EVENT_E_INTERNALEXCEPTION;
  491. bLogErrorOutsideSwitch = TRUE;
  492. }
  493. break;
  494. case RSOP_SecuritySettingBoolean:
  495. try {
  496. {
  497. RSOP_SecuritySettingBooleanLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  498. DWORD dwValue = SCEP_TYPECAST(DWORD, pSceProfileInfoBuffer, settingOffset);
  499. BOOL bDomainUniformSetting = (0 == _wcsicmp(pSettingName, L"ClearTextPassword") ||
  500. 0 == _wcsicmp(pSettingName, L"RequireLogonToChangePassword") ||
  501. 0 == _wcsicmp(pSettingName, L"ForceLogoffWhenHourExpire") ||
  502. 0 == _wcsicmp(pSettingName, L"EnableAdminAccount") ||
  503. 0 == _wcsicmp(pSettingName, L"EnableGuestAccount") ||
  504. 0 == _wcsicmp(pSettingName, L"PasswordComplexity"));
  505. if (bDomainUniformSetting &&
  506. !(bPlanningMode ||
  507. !(gbDCQueried == TRUE && gbThisIsDC == TRUE) ||
  508. ((gbDCQueried == TRUE && gbThisIsDC == TRUE) && wcsstr(pCurrFileName->Name, L".dom")))) {
  509. //
  510. // if it is a domain uniform policy and not coming from a domain policy on a DC, do not log.
  511. //
  512. continue;
  513. }
  514. if (dwValue != SCE_NO_VALUE) {
  515. rc = ScepWbemErrorToDosError(Log.Log(
  516. pSettingName,
  517. dwValue,
  518. ++(*pSettingPrecedence)
  519. ));
  520. if (rc == NO_ERROR)
  521. ScepLogEventAndReport(MyModuleHandle,
  522. gpwszPlanOrDiagLogFile,
  523. 0,
  524. 0,
  525. IDS_INFO_RSOP_LOG,
  526. rc,
  527. pSettingName
  528. );
  529. if (rc != NO_ERROR)
  530. break;
  531. }
  532. }
  533. } catch (...) {
  534. //
  535. // system error continue with next setting
  536. //
  537. rc = EVENT_E_INTERNALEXCEPTION;
  538. }
  539. break;
  540. case RSOP_SecuritySettingString:
  541. try {
  542. {
  543. RSOP_SecuritySettingStringLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  544. PWSTR pszValue = SCEP_TYPECAST(PWSTR, pSceProfileInfoBuffer, settingOffset);
  545. if (pszValue != NULL) {
  546. rc = ScepWbemErrorToDosError(Log.Log(
  547. pSettingName,
  548. pszValue,
  549. ++(*pSettingPrecedence)
  550. ));
  551. if (rc == NO_ERROR)
  552. ScepLogEventAndReport(MyModuleHandle,
  553. gpwszPlanOrDiagLogFile,
  554. 0,
  555. 0,
  556. IDS_INFO_RSOP_LOG,
  557. rc,
  558. pSettingName
  559. );
  560. if (rc != NO_ERROR)
  561. break;
  562. }
  563. }
  564. } catch (...) {
  565. // system error continue with next setting
  566. rc = EVENT_E_INTERNALEXCEPTION;
  567. }
  568. break;
  569. case RSOP_AuditPolicy:
  570. {
  571. RSOP_AuditPolicyLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  572. DWORD dwValue = SCEP_TYPECAST(DWORD, pSceProfileInfoBuffer, settingOffset);
  573. if (dwValue != SCE_NO_VALUE) {
  574. rc = ScepWbemErrorToDosError(Log.Log(
  575. pSettingName,
  576. dwValue,
  577. ++(*pSettingPrecedence)
  578. ));
  579. if (rc == NO_ERROR)
  580. ScepLogEventAndReport(MyModuleHandle,
  581. gpwszPlanOrDiagLogFile,
  582. 0,
  583. 0,
  584. IDS_INFO_RSOP_LOG,
  585. rc,
  586. pSettingName
  587. );
  588. if (rc != NO_ERROR)
  589. break;
  590. }
  591. }
  592. break;
  593. case RSOP_SecurityEventLogSettingNumeric:
  594. try {
  595. {
  596. RSOP_SecurityEventLogSettingNumericLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  597. bLogErrorOutsideSwitch = FALSE;
  598. for (UINT LogType = 0; LogType < NUM_EVENTLOG_TYPES ; LogType ++) {
  599. settingOffset = PrecedenceLookup[settingNo + LogType].KeyLookup.Offset;
  600. pSettingPrecedence = &PrecedenceLookup[settingNo + LogType].Precedence;
  601. DWORD dwValue = SCEP_TYPECAST(DWORD, pSceProfileInfoBuffer, settingOffset);
  602. //
  603. // calculate dwValue depdending on dwAuditLogRetentionPeriod[]
  604. //
  605. if (_wcsicmp(pSettingName, L"RetentionDays") == 0) {
  606. switch (dwAuditLogRetentionPeriod[LogType]) {
  607. case 2: // manually
  608. dwValue = MAXULONG;
  609. break;
  610. case 1: // number of days * seconds/day
  611. //if (dwValue != SCE_NO_VALUE)
  612. //dwValue = dwValue * 24 * 3600;
  613. //leave it in days
  614. break;
  615. case 0: // as needed
  616. dwValue = 0;
  617. break;
  618. // default should not happen
  619. default:
  620. dwValue = SCE_NO_VALUE;
  621. }
  622. }
  623. if (dwValue != SCE_NO_VALUE) {
  624. WCHAR pwszLogType[10];
  625. _itow((int)LogType, pwszLogType, 10);
  626. //
  627. // AuditLogRetentionPeriod controls RetentionDays - so remember
  628. // also it is never logged since it is an artifact of the template spec
  629. //
  630. if (_wcsicmp(pSettingName, L"AuditLogRetentionPeriod") == 0) {
  631. dwAuditLogRetentionPeriod[LogType] = dwValue;
  632. ScepLogEventAndReport(MyModuleHandle,
  633. gpwszPlanOrDiagLogFile,
  634. 0,
  635. 0,
  636. IDS_INFO_RSOP_LOG,
  637. LogType,
  638. pSettingName
  639. );
  640. continue;
  641. }
  642. rc = ScepWbemErrorToDosError(Log.Log(
  643. pSettingName,
  644. pwszLogType,
  645. dwValue,
  646. ++(*pSettingPrecedence)
  647. ));
  648. ScepLogEventAndReport(MyModuleHandle,
  649. gpwszPlanOrDiagLogFile,
  650. 0,
  651. 0,
  652. IDS_INFO_RSOP_LOG,
  653. LogType,
  654. pSettingName
  655. );
  656. SCEP_RSOP_CONTINUE_OR_BREAK
  657. }
  658. }
  659. //
  660. // just processed NUM_EVENTLOG_TYPES - system, application, security, for this setting
  661. //
  662. settingNo += NUM_EVENTLOG_TYPES - 1;
  663. }
  664. } catch (...) {
  665. //
  666. // system error continue with next setting
  667. //
  668. rc = EVENT_E_INTERNALEXCEPTION;
  669. bLogErrorOutsideSwitch = TRUE;
  670. }
  671. break;
  672. case RSOP_SecurityEventLogSettingBoolean:
  673. try {
  674. {
  675. RSOP_SecurityEventLogSettingBooleanLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  676. bLogErrorOutsideSwitch = FALSE;
  677. for (UINT LogType = 0; LogType < NUM_EVENTLOG_TYPES ; LogType ++) {
  678. settingOffset = PrecedenceLookup[settingNo + LogType].KeyLookup.Offset;
  679. pSettingPrecedence = &PrecedenceLookup[settingNo + LogType].Precedence;
  680. DWORD dwValue = SCEP_TYPECAST(DWORD, pSceProfileInfoBuffer, settingOffset);
  681. if (dwValue != SCE_NO_VALUE) {
  682. WCHAR pwszLogType[10];
  683. _itow((int)LogType, pwszLogType, 10);
  684. rc = ScepWbemErrorToDosError(Log.Log(
  685. pSettingName,
  686. pwszLogType,
  687. dwValue,
  688. ++(*pSettingPrecedence)
  689. ));
  690. ScepLogEventAndReport(MyModuleHandle,
  691. gpwszPlanOrDiagLogFile,
  692. 0,
  693. 0,
  694. IDS_INFO_RSOP_LOG,
  695. rc,
  696. pSettingName
  697. );
  698. SCEP_RSOP_CONTINUE_OR_BREAK
  699. }
  700. }
  701. //
  702. // processed NUM_EVENTLOG_TYPES - system, application, security, for this setting
  703. //
  704. settingNo += NUM_EVENTLOG_TYPES - 1;
  705. }
  706. } catch (...) {
  707. //
  708. // system error continue with next setting
  709. //
  710. rc = EVENT_E_INTERNALEXCEPTION;
  711. bLogErrorOutsideSwitch = TRUE;
  712. }
  713. break;
  714. case RSOP_RegistryValue:
  715. try {
  716. {
  717. RSOP_RegistryValueLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  718. DWORD dwRegCount = SCEP_TYPECAST(DWORD, pSceProfileInfoBuffer, settingOffset);
  719. PSCE_REGISTRY_VALUE_INFO aRegValues = NULL;
  720. //
  721. // 64-bit alignment fix (alternatively, have an entry for aRegValues in the offset table)
  722. //
  723. #ifdef _WIN64
  724. // CHAR *pAlign;
  725. aRegValues = pSceProfileInfoBuffer->aRegValues;
  726. // pAlign = (CHAR *)pSceProfileInfoBuffer + settingOffset + sizeof(DWORD);
  727. // aRegValues = (PSCE_REGISTRY_VALUE_INFO)ROUND_UP_POINTER(pAlign,ALIGN_LPVOID);
  728. #else
  729. aRegValues =
  730. SCEP_TYPECAST(PSCE_REGISTRY_VALUE_INFO, pSceProfileInfoBuffer, settingOffset + sizeof(DWORD));
  731. #endif
  732. bLogErrorOutsideSwitch = FALSE;
  733. if ( aRegValues == NULL )
  734. continue;
  735. for (UINT regNo = 0; regNo < dwRegCount; regNo++ ) {
  736. if ((aRegValues)[regNo].FullValueName) {
  737. pSettingPrecedence = NULL;
  738. if (NO_ERROR != (rc = RegistryValueHashTable.LookupAdd(
  739. (aRegValues)[regNo].FullValueName,
  740. &pSettingPrecedence))) {
  741. rcSave = rc;
  742. ScepLogEventAndReport(MyModuleHandle,
  743. gpwszPlanOrDiagLogFile,
  744. 0,
  745. 0,
  746. IDS_ERROR_RSOP_LOG,
  747. rc,
  748. (aRegValues)[regNo].FullValueName
  749. );
  750. //
  751. // if hash table fails for any reason, cannot
  752. // trust it for processing of other elements
  753. //
  754. break;
  755. }
  756. rc = ScepWbemErrorToDosError(Log.Log(
  757. (aRegValues)[regNo].FullValueName,
  758. (aRegValues)[regNo].ValueType,
  759. (aRegValues)[regNo].Value,
  760. ++(*pSettingPrecedence)
  761. ));
  762. ScepLogEventAndReport(MyModuleHandle,
  763. gpwszPlanOrDiagLogFile,
  764. 0,
  765. 0,
  766. IDS_INFO_RSOP_LOG,
  767. rc,
  768. (aRegValues)[regNo].FullValueName
  769. );
  770. SCEP_RSOP_CONTINUE_OR_BREAK
  771. }
  772. }
  773. }
  774. } catch (...) {
  775. //
  776. // system error continue with next setting
  777. //
  778. rc = EVENT_E_INTERNALEXCEPTION;
  779. bLogErrorOutsideSwitch = TRUE;
  780. }
  781. break;
  782. case RSOP_UserPrivilegeRight:
  783. try {
  784. {
  785. RSOP_UserPrivilegeRightLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  786. PSCE_PRIVILEGE_ASSIGNMENT pInfPrivilegeAssignedTo =
  787. SCEP_TYPECAST(PSCE_PRIVILEGE_ASSIGNMENT, pSceProfileInfoBuffer, settingOffset);
  788. bLogErrorOutsideSwitch = FALSE;
  789. while (pInfPrivilegeAssignedTo) {
  790. if (pInfPrivilegeAssignedTo->Name) {
  791. pSettingPrecedence = NULL;
  792. if (NO_ERROR != (rc = PrivilegeHashTable.LookupAdd(
  793. pInfPrivilegeAssignedTo->Name,
  794. &pSettingPrecedence))) {
  795. rcSave = rc;
  796. ScepLogEventAndReport(MyModuleHandle,
  797. gpwszPlanOrDiagLogFile,
  798. 0,
  799. 0,
  800. IDS_ERROR_RSOP_LOG,
  801. rc,
  802. pInfPrivilegeAssignedTo->Name
  803. );
  804. //
  805. // if hash table fails for any reason, cannot
  806. // trust it for processing of other elements
  807. //
  808. break;
  809. }
  810. rc = ScepWbemErrorToDosError(Log.Log(
  811. pInfPrivilegeAssignedTo->Name,
  812. pInfPrivilegeAssignedTo->AssignedTo,
  813. ++(*pSettingPrecedence)
  814. ));
  815. ScepLogEventAndReport(MyModuleHandle,
  816. gpwszPlanOrDiagLogFile,
  817. 0,
  818. 0,
  819. IDS_INFO_RSOP_LOG,
  820. rc,
  821. pInfPrivilegeAssignedTo->Name
  822. );
  823. SCEP_RSOP_CONTINUE_OR_BREAK
  824. }
  825. pInfPrivilegeAssignedTo = pInfPrivilegeAssignedTo->Next;
  826. }
  827. }
  828. } catch (...) {
  829. //
  830. // system error continue with next setting
  831. //
  832. rc = EVENT_E_INTERNALEXCEPTION;
  833. bLogErrorOutsideSwitch = TRUE;
  834. }
  835. break;
  836. case RSOP_RestrictedGroup:
  837. try {
  838. {
  839. RSOP_RestrictedGroupLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  840. PSCE_GROUP_MEMBERSHIP pGroupMembership =
  841. SCEP_TYPECAST(PSCE_GROUP_MEMBERSHIP, pSceProfileInfoBuffer, settingOffset);
  842. bLogErrorOutsideSwitch = FALSE;
  843. PWSTR pCanonicalGroupName = NULL;
  844. while (pGroupMembership) {
  845. if (pGroupMembership->GroupName) {
  846. rc = ScepCanonicalizeGroupName(pGroupMembership->GroupName,
  847. &pCanonicalGroupName
  848. );
  849. SCEP_RSOP_CONTINUE_OR_BREAK
  850. pSettingPrecedence = NULL;
  851. if (NO_ERROR != (rc = GroupHashTable.LookupAdd(
  852. pCanonicalGroupName,
  853. &pSettingPrecedence))) {
  854. rcSave = rc;
  855. ScepLogEventAndReport(MyModuleHandle,
  856. gpwszPlanOrDiagLogFile,
  857. 0,
  858. 0,
  859. IDS_ERROR_RSOP_LOG,
  860. rc,
  861. pCanonicalGroupName
  862. );
  863. //
  864. // if hash table fails for any reason, cannot
  865. // trust it for processing of other elements
  866. //
  867. if (pCanonicalGroupName)
  868. ScepFree(pCanonicalGroupName);
  869. pCanonicalGroupName = NULL;
  870. break;
  871. }
  872. rc = ScepWbemErrorToDosError(Log.Log(
  873. pCanonicalGroupName,
  874. pGroupMembership->pMembers,
  875. ++(*pSettingPrecedence)
  876. ));
  877. ScepLogEventAndReport(MyModuleHandle,
  878. gpwszPlanOrDiagLogFile,
  879. 0,
  880. 0,
  881. IDS_INFO_RSOP_LOG,
  882. rc,
  883. pCanonicalGroupName
  884. );
  885. if (pCanonicalGroupName)
  886. ScepFree(pCanonicalGroupName);
  887. pCanonicalGroupName = NULL;
  888. SCEP_RSOP_CONTINUE_OR_BREAK
  889. }
  890. pGroupMembership = pGroupMembership->Next;
  891. }
  892. }
  893. } catch (...) {
  894. //
  895. // system error continue with next setting
  896. //
  897. rc = EVENT_E_INTERNALEXCEPTION;
  898. bLogErrorOutsideSwitch = TRUE;
  899. }
  900. break;
  901. case RSOP_SystemService:
  902. try {
  903. {
  904. RSOP_SystemServiceLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  905. PSCE_SERVICES pServices =
  906. SCEP_TYPECAST(PSCE_SERVICES, pSceProfileInfoBuffer, settingOffset);
  907. bLogErrorOutsideSwitch = FALSE;
  908. while (pServices) {
  909. if (pServices->ServiceName) {
  910. pSettingPrecedence = NULL;
  911. if (NO_ERROR != (rc = ServicesHashTable.LookupAdd(
  912. pServices->ServiceName,
  913. &pSettingPrecedence))) {
  914. rcSave = rc;
  915. ScepLogEventAndReport(MyModuleHandle,
  916. gpwszPlanOrDiagLogFile,
  917. 0,
  918. 0,
  919. IDS_ERROR_RSOP_LOG,
  920. rc,
  921. pServices->ServiceName
  922. );
  923. //
  924. // if hash table fails for any reason, cannot
  925. // trust it for processing of other elements
  926. //
  927. break;
  928. }
  929. rc = ScepWbemErrorToDosError(Log.Log(
  930. pServices->ServiceName,
  931. pServices->Startup,
  932. pServices->General.pSecurityDescriptor,
  933. pServices->SeInfo,
  934. ++(*pSettingPrecedence)
  935. ));
  936. ScepLogEventAndReport(MyModuleHandle,
  937. gpwszPlanOrDiagLogFile,
  938. 0,
  939. 0,
  940. IDS_INFO_RSOP_LOG,
  941. rc,
  942. pServices->ServiceName
  943. );
  944. SCEP_RSOP_CONTINUE_OR_BREAK
  945. }
  946. pServices = pServices->Next;
  947. }
  948. }
  949. } catch (...) {
  950. //
  951. // system error continue with next setting
  952. //
  953. rc = EVENT_E_INTERNALEXCEPTION;
  954. bLogErrorOutsideSwitch = TRUE;
  955. }
  956. break;
  957. case RSOP_File:
  958. try {
  959. {
  960. RSOP_FileLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  961. SCE_OBJECTS pObjects =
  962. SCEP_TYPECAST(SCE_OBJECTS, pSceProfileInfoBuffer, settingOffset);
  963. BOOL bPathIsTranslated = FALSE;
  964. bLogErrorOutsideSwitch = FALSE;
  965. if (pObjects.pAllNodes) {
  966. PSCE_OBJECT_SECURITY *pObjectArray = pObjects.pAllNodes->pObjectArray;
  967. for (DWORD rCount = 0; rCount < pObjects.pAllNodes->Count; rCount++) {
  968. if (pObjectArray[rCount] && pObjectArray[rCount]->Name) {
  969. pSettingPrecedence = NULL;
  970. //
  971. // if diagnosis mode, translate env-vars and store
  972. //
  973. bPathIsTranslated = FALSE;
  974. PWSTR pwszTranslatedPath = NULL;
  975. if (!bPlanningMode && (wcschr(pObjectArray[rCount]->Name, L'%') != NULL )) {
  976. bPathIsTranslated = TRUE;
  977. rc = ScepClientTranslateFileDirName( pObjectArray[rCount]->Name, &pwszTranslatedPath);
  978. if ( rc == ERROR_PATH_NOT_FOUND )
  979. rc = SCESTATUS_INVALID_DATA;
  980. else if ( rc != NO_ERROR )
  981. rc = ScepDosErrorToSceStatus(rc);
  982. SCEP_RSOP_CONTINUE_OR_BREAK
  983. } else {
  984. pwszTranslatedPath = pObjectArray[rCount]->Name;
  985. }
  986. if (NO_ERROR != (rc = FileSecurityHashTable.LookupAdd(
  987. pwszTranslatedPath,
  988. &pSettingPrecedence))) {
  989. rcSave = rc;
  990. ScepLogEventAndReport(MyModuleHandle,
  991. gpwszPlanOrDiagLogFile,
  992. 0,
  993. 0,
  994. IDS_ERROR_RSOP_LOG,
  995. rc,
  996. pwszTranslatedPath
  997. );
  998. //
  999. // if hash table fails for any reason, cannot
  1000. // trust it for processing of other elements
  1001. //
  1002. if (bPathIsTranslated && pwszTranslatedPath)
  1003. LocalFree(pwszTranslatedPath);
  1004. break;
  1005. }
  1006. rc = ScepWbemErrorToDosError(Log.Log(
  1007. pwszTranslatedPath,
  1008. (bPathIsTranslated ? pObjectArray[rCount]->Name : NULL),
  1009. pObjectArray[rCount]->Status,
  1010. pObjectArray[rCount]->pSecurityDescriptor,
  1011. pObjectArray[rCount]->SeInfo,
  1012. ++(*pSettingPrecedence)
  1013. ));
  1014. ScepLogEventAndReport(MyModuleHandle,
  1015. gpwszPlanOrDiagLogFile,
  1016. 0,
  1017. 0,
  1018. IDS_INFO_RSOP_LOG,
  1019. rc,
  1020. pwszTranslatedPath
  1021. );
  1022. if (bPathIsTranslated && pwszTranslatedPath)
  1023. LocalFree(pwszTranslatedPath);
  1024. SCEP_RSOP_CONTINUE_OR_BREAK
  1025. }
  1026. }
  1027. }
  1028. }
  1029. } catch (...) {
  1030. //
  1031. // system error continue with next setting
  1032. //
  1033. rc = EVENT_E_INTERNALEXCEPTION;
  1034. bLogErrorOutsideSwitch = TRUE;
  1035. }
  1036. break;
  1037. case RSOP_RegistryKey:
  1038. try {
  1039. {
  1040. RSOP_RegistryKeyLogger Log(pWbemServices, pwszGPOName, pwszSOMID);
  1041. SCE_OBJECTS pObjects =
  1042. SCEP_TYPECAST(SCE_OBJECTS, pSceProfileInfoBuffer, settingOffset);
  1043. bLogErrorOutsideSwitch = FALSE;
  1044. if (pObjects.pAllNodes) {
  1045. PSCE_OBJECT_SECURITY *pObjectArray = pObjects.pAllNodes->pObjectArray;
  1046. for (DWORD rCount = 0; rCount < pObjects.pAllNodes->Count; rCount++) {
  1047. if (pObjectArray[rCount] && pObjectArray[rCount]->Name) {
  1048. pSettingPrecedence = NULL;
  1049. if (NO_ERROR != (rc = RegistrySecurityHashTable.LookupAdd(
  1050. pObjectArray[rCount]->Name,
  1051. &pSettingPrecedence))) {
  1052. rcSave = rc;
  1053. ScepLogEventAndReport(MyModuleHandle,
  1054. gpwszPlanOrDiagLogFile,
  1055. 0,
  1056. 0,
  1057. IDS_ERROR_RSOP_LOG,
  1058. rc,
  1059. pObjectArray[rCount]->Name
  1060. );
  1061. //
  1062. // if hash table fails for any reason, cannot
  1063. // trust it for processing of other elements
  1064. //
  1065. break;
  1066. }
  1067. rc = ScepWbemErrorToDosError(Log.Log(
  1068. pObjectArray[rCount]->Name,
  1069. pObjectArray[rCount]->Status,
  1070. pObjectArray[rCount]->pSecurityDescriptor,
  1071. pObjectArray[rCount]->SeInfo,
  1072. ++(*pSettingPrecedence)
  1073. ));
  1074. ScepLogEventAndReport(MyModuleHandle,
  1075. gpwszPlanOrDiagLogFile,
  1076. 0,
  1077. 0,
  1078. IDS_INFO_RSOP_LOG,
  1079. rc,
  1080. pObjectArray[rCount]->Name
  1081. );
  1082. SCEP_RSOP_CONTINUE_OR_BREAK
  1083. }
  1084. }
  1085. }
  1086. }
  1087. } catch (...) {
  1088. //
  1089. // system error continue with next setting
  1090. //
  1091. rc = EVENT_E_INTERNALEXCEPTION;
  1092. bLogErrorOutsideSwitch = TRUE;
  1093. }
  1094. break;
  1095. default:
  1096. //
  1097. // should not happen
  1098. //
  1099. rc = ERROR_INVALID_PARAMETER;
  1100. }
  1101. if (bLogErrorOutsideSwitch && rc != NO_ERROR ) {
  1102. //
  1103. // log error and continue
  1104. //
  1105. rcSave = rc;
  1106. ScepLogEventAndReport(MyModuleHandle,
  1107. gpwszPlanOrDiagLogFile,
  1108. 0,
  1109. 0,
  1110. IDS_ERROR_RSOP_LOG,
  1111. rc,
  1112. pSettingName
  1113. );
  1114. }
  1115. bLogErrorOutsideSwitch = TRUE;
  1116. //
  1117. // this is the only case in which we quit logging completely
  1118. //
  1119. if (rc == ERROR_NOT_ENOUGH_MEMORY)
  1120. break;
  1121. }
  1122. NextGPO:
  1123. if (pSceProfileInfoBuffer)
  1124. SceFreeProfileMemory(pSceProfileInfoBuffer);
  1125. pSceProfileInfoBuffer = NULL;
  1126. if (pwszGPOName)
  1127. ScepFree(pwszGPOName);
  1128. pwszGPOName = NULL;
  1129. if (pwszSOMID)
  1130. ScepFree(pwszSOMID);
  1131. pwszSOMID = NULL;
  1132. if (rc == ERROR_NOT_ENOUGH_MEMORY)
  1133. break;
  1134. // this is the only case in which we quit logging completely
  1135. pCurrFileName = pCurrFileName->Next;
  1136. }
  1137. if (pGptNameList)
  1138. ScepFreeNameStatusList(pGptNameList);
  1139. //
  1140. // only log the final status to both event log and logfile
  1141. // (all other statuses are logged to logfile only)
  1142. //
  1143. if (rcSave == ERROR_SUCCESS)
  1144. ScepLogEventAndReport(MyModuleHandle,
  1145. gpwszPlanOrDiagLogFile,
  1146. 0,
  1147. 0,
  1148. IDS_SUCCESS_RSOP_LOG,
  1149. rcSave,
  1150. L""
  1151. );
  1152. else
  1153. ScepLogEventAndReport(MyModuleHandle,
  1154. gpwszPlanOrDiagLogFile,
  1155. 0,
  1156. 0,
  1157. IDS_ERROR_RSOP_LOG,
  1158. rcSave,
  1159. L""
  1160. );
  1161. ExitHandler:
  1162. if ( Windir )
  1163. SafeAllocaFree( Windir );
  1164. if ( TemplatePath )
  1165. SafeAllocaFree( TemplatePath );
  1166. return rcSave;
  1167. }
  1168. SCEPR_STATUS
  1169. SceClientCallbackRsopLog(
  1170. IN AREAPR cbArea,
  1171. IN DWORD ncbErrorStatus,
  1172. IN wchar_t *pSettingInfo OPTIONAL,
  1173. IN DWORD dwPrivLow OPTIONAL,
  1174. IN DWORD dwPrivHigh OPTIONAL
  1175. )
  1176. /////////////////////////////////////////////////////////////////////////////////////////////////////
  1177. // This function is called by the server via RPC when settings defined in the jet //
  1178. // db are applied (along with a status of application, and optional detailed information) //
  1179. // //
  1180. // The areas were decided based on the granularity of configuration in scesrv. cbArea can have //
  1181. // more than one area encoded in it, again due to the resolution granularity of error in scesrv. //
  1182. // Hence this is a massive "if" routine //
  1183. // //
  1184. // configuration from jet db corresponds to precedence = "1" simulated configuration in the //
  1185. // rsop database which was logged by the client. For each area, we try to log the status of //
  1186. // configuration by querying the database for these precedence = "1" settings and updating the //
  1187. // status fields per such instance found. We should find all called back settings in WMI db except //
  1188. // for local-policy //
  1189. // //
  1190. // if any error, update golbal Synch/Asynch statuses with the accumulated status //
  1191. /////////////////////////////////////////////////////////////////////////////////////////////////////
  1192. {
  1193. DWORD rc = ERROR_SUCCESS;
  1194. DWORD rcSave = ERROR_SUCCESS;
  1195. //
  1196. // instantiate a logger that logs status from callback (has overloaded log methods)
  1197. //
  1198. try {
  1199. SCEP_DIAGNOSIS_LOGGER Log(tg_pWbemServices, NULL, NULL);
  1200. //
  1201. // password policy
  1202. //
  1203. if (cbArea & SCE_RSOP_PASSWORD_INFO) {
  1204. try {
  1205. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  1206. L"KeyName",
  1207. L"MinimumPasswordAge",
  1208. ncbErrorStatus,
  1209. FALSE
  1210. ));
  1211. ScepLogEventAndReport(MyModuleHandle,
  1212. gpwszPlanOrDiagLogFile,
  1213. 0,
  1214. 0,
  1215. IDS_ERROR_RSOP_DIAG_LOG,
  1216. rc,
  1217. L"MinimumPasswordAge"
  1218. );
  1219. SCEP_RSOP_CONTINUE_OR_GOTO
  1220. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  1221. L"KeyName",
  1222. L"MaximumPasswordAge",
  1223. ncbErrorStatus,
  1224. FALSE
  1225. ));
  1226. ScepLogEventAndReport(MyModuleHandle,
  1227. gpwszPlanOrDiagLogFile,
  1228. 0,
  1229. 0,
  1230. IDS_ERROR_RSOP_DIAG_LOG,
  1231. rc,
  1232. L"MaximumPasswordAge"
  1233. );
  1234. SCEP_RSOP_CONTINUE_OR_GOTO
  1235. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  1236. L"KeyName",
  1237. L"MinimumPasswordLength",
  1238. ncbErrorStatus,
  1239. FALSE
  1240. ));
  1241. ScepLogEventAndReport(MyModuleHandle,
  1242. gpwszPlanOrDiagLogFile,
  1243. 0,
  1244. 0,
  1245. IDS_ERROR_RSOP_DIAG_LOG,
  1246. rc,
  1247. L"MinimumPasswordLength"
  1248. );
  1249. SCEP_RSOP_CONTINUE_OR_GOTO
  1250. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  1251. L"KeyName",
  1252. L"PasswordHistorySize",
  1253. ncbErrorStatus,
  1254. FALSE
  1255. ));
  1256. ScepLogEventAndReport(MyModuleHandle,
  1257. gpwszPlanOrDiagLogFile,
  1258. 0,
  1259. 0,
  1260. IDS_ERROR_RSOP_DIAG_LOG,
  1261. rc,
  1262. L"PasswordHistorySize"
  1263. );
  1264. SCEP_RSOP_CONTINUE_OR_GOTO
  1265. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingBoolean",
  1266. L"KeyName",
  1267. L"ClearTextPassword",
  1268. ncbErrorStatus,
  1269. FALSE
  1270. ));
  1271. ScepLogEventAndReport(MyModuleHandle,
  1272. gpwszPlanOrDiagLogFile,
  1273. 0,
  1274. 0,
  1275. IDS_ERROR_RSOP_DIAG_LOG,
  1276. rc,
  1277. L"ClearTextPassword"
  1278. );
  1279. SCEP_RSOP_CONTINUE_OR_GOTO
  1280. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingBoolean",
  1281. L"KeyName",
  1282. L"PasswordComplexity",
  1283. ncbErrorStatus,
  1284. FALSE
  1285. ));
  1286. ScepLogEventAndReport(MyModuleHandle,
  1287. gpwszPlanOrDiagLogFile,
  1288. 0,
  1289. 0,
  1290. IDS_ERROR_RSOP_DIAG_LOG,
  1291. rc,
  1292. L"PasswordComplexity"
  1293. );
  1294. SCEP_RSOP_CONTINUE_OR_GOTO
  1295. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingBoolean",
  1296. L"KeyName",
  1297. L"RequireLogonToChangePassword",
  1298. ncbErrorStatus,
  1299. FALSE
  1300. ));
  1301. ScepLogEventAndReport(MyModuleHandle,
  1302. gpwszPlanOrDiagLogFile,
  1303. 0,
  1304. 0,
  1305. IDS_ERROR_RSOP_DIAG_LOG,
  1306. rc,
  1307. L"RequireLogonToChangePassword"
  1308. );
  1309. SCEP_RSOP_CONTINUE_OR_GOTO
  1310. } catch (...) {
  1311. //
  1312. // system error continue with next setting
  1313. //
  1314. rcSave = EVENT_E_INTERNALEXCEPTION;
  1315. }
  1316. }
  1317. //
  1318. // account lockout policy
  1319. //
  1320. if (cbArea & SCE_RSOP_LOCKOUT_INFO) {
  1321. try {
  1322. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  1323. L"KeyName",
  1324. L"LockoutBadCount",
  1325. ncbErrorStatus,
  1326. FALSE
  1327. ));
  1328. ScepLogEventAndReport(MyModuleHandle,
  1329. gpwszPlanOrDiagLogFile,
  1330. 0,
  1331. 0,
  1332. IDS_ERROR_RSOP_DIAG_LOG,
  1333. rc,
  1334. L"LockoutBadCount"
  1335. );
  1336. SCEP_RSOP_CONTINUE_OR_GOTO
  1337. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  1338. L"KeyName",
  1339. L"ResetLockoutCount",
  1340. ncbErrorStatus,
  1341. FALSE
  1342. ));
  1343. ScepLogEventAndReport(MyModuleHandle,
  1344. gpwszPlanOrDiagLogFile,
  1345. 0,
  1346. 0,
  1347. IDS_ERROR_RSOP_DIAG_LOG,
  1348. rc,
  1349. L"ResetLockoutCount"
  1350. );
  1351. SCEP_RSOP_CONTINUE_OR_GOTO
  1352. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  1353. L"KeyName",
  1354. L"LockoutDuration",
  1355. ncbErrorStatus,
  1356. FALSE
  1357. ));
  1358. ScepLogEventAndReport(MyModuleHandle,
  1359. gpwszPlanOrDiagLogFile,
  1360. 0,
  1361. 0,
  1362. IDS_ERROR_RSOP_DIAG_LOG,
  1363. rc,
  1364. L"LockoutDuration"
  1365. );
  1366. SCEP_RSOP_CONTINUE_OR_GOTO
  1367. } catch (...) {
  1368. //
  1369. // system error continue with next setting
  1370. //
  1371. rcSave = EVENT_E_INTERNALEXCEPTION;
  1372. }
  1373. }
  1374. //
  1375. // forcelogoff setting
  1376. //
  1377. if (cbArea & SCE_RSOP_LOGOFF_INFO) {
  1378. try {
  1379. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingBoolean",
  1380. L"KeyName",
  1381. L"ForceLogoffWhenHourExpire",
  1382. ncbErrorStatus,
  1383. FALSE
  1384. ));
  1385. ScepLogEventAndReport(MyModuleHandle,
  1386. gpwszPlanOrDiagLogFile,
  1387. 0,
  1388. 0,
  1389. IDS_ERROR_RSOP_DIAG_LOG,
  1390. rc,
  1391. L"ForceLogoffWhenHourExpire"
  1392. );
  1393. SCEP_RSOP_CONTINUE_OR_GOTO
  1394. } catch (...) {
  1395. //
  1396. // system error continue with next setting
  1397. //
  1398. rcSave = EVENT_E_INTERNALEXCEPTION;
  1399. }
  1400. }
  1401. //
  1402. // LSA policy setting
  1403. //
  1404. if (cbArea & SCE_RSOP_LSA_POLICY_INFO) {
  1405. try {
  1406. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingBoolean",
  1407. L"KeyName",
  1408. L"LSAAnonymousNameLookup",
  1409. ncbErrorStatus,
  1410. FALSE
  1411. ));
  1412. ScepLogEventAndReport(MyModuleHandle,
  1413. gpwszPlanOrDiagLogFile,
  1414. 0,
  1415. 0,
  1416. IDS_ERROR_RSOP_DIAG_LOG,
  1417. rc,
  1418. L"LSAAnonymousNameLookup"
  1419. );
  1420. SCEP_RSOP_CONTINUE_OR_GOTO
  1421. } catch (...) {
  1422. //
  1423. // system error continue with next setting
  1424. //
  1425. rcSave = EVENT_E_INTERNALEXCEPTION;
  1426. }
  1427. }
  1428. //
  1429. // disable admin account
  1430. //
  1431. if (cbArea & SCE_RSOP_DISABLE_ADMIN_INFO) {
  1432. try {
  1433. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingBoolean",
  1434. L"KeyName",
  1435. L"EnableAdminAccount",
  1436. ncbErrorStatus,
  1437. FALSE
  1438. ));
  1439. ScepLogEventAndReport(MyModuleHandle,
  1440. gpwszPlanOrDiagLogFile,
  1441. 0,
  1442. 0,
  1443. IDS_ERROR_RSOP_DIAG_LOG,
  1444. rc,
  1445. L"EnableAdminAccount"
  1446. );
  1447. SCEP_RSOP_CONTINUE_OR_GOTO
  1448. } catch (...) {
  1449. //
  1450. // system error continue with next setting
  1451. //
  1452. rcSave = EVENT_E_INTERNALEXCEPTION;
  1453. }
  1454. }
  1455. //
  1456. // disable guest account
  1457. //
  1458. if (cbArea & SCE_RSOP_DISABLE_GUEST_INFO) {
  1459. try {
  1460. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingBoolean",
  1461. L"KeyName",
  1462. L"EnableGuestAccount",
  1463. ncbErrorStatus,
  1464. FALSE
  1465. ));
  1466. ScepLogEventAndReport(MyModuleHandle,
  1467. gpwszPlanOrDiagLogFile,
  1468. 0,
  1469. 0,
  1470. IDS_ERROR_RSOP_DIAG_LOG,
  1471. rc,
  1472. L"EnableGuestAccount"
  1473. );
  1474. SCEP_RSOP_CONTINUE_OR_GOTO
  1475. } catch (...) {
  1476. //
  1477. // system error continue with next setting
  1478. //
  1479. rcSave = EVENT_E_INTERNALEXCEPTION;
  1480. }
  1481. }
  1482. //
  1483. // administratorname setting
  1484. //
  1485. if (cbArea & SCE_RSOP_ADMIN_INFO) {
  1486. try {
  1487. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingString",
  1488. L"KeyName",
  1489. L"NewAdministratorName",
  1490. ncbErrorStatus,
  1491. FALSE
  1492. ));
  1493. ScepLogEventAndReport(MyModuleHandle,
  1494. gpwszPlanOrDiagLogFile,
  1495. 0,
  1496. 0,
  1497. IDS_ERROR_RSOP_DIAG_LOG,
  1498. rc,
  1499. L"NewAdministratorName"
  1500. );
  1501. SCEP_RSOP_CONTINUE_OR_GOTO
  1502. } catch (...) {
  1503. //
  1504. // system error continue with next setting
  1505. //
  1506. rcSave = EVENT_E_INTERNALEXCEPTION;
  1507. }
  1508. }
  1509. //
  1510. // guestname setting
  1511. //
  1512. if (cbArea & SCE_RSOP_GUEST_INFO) {
  1513. try {
  1514. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingString",
  1515. L"KeyName",
  1516. L"NewGuestName",
  1517. ncbErrorStatus,
  1518. FALSE
  1519. ));
  1520. ScepLogEventAndReport(MyModuleHandle,
  1521. gpwszPlanOrDiagLogFile,
  1522. 0,
  1523. 0,
  1524. IDS_ERROR_RSOP_DIAG_LOG,
  1525. rc,
  1526. L"NewGuestName"
  1527. );
  1528. SCEP_RSOP_CONTINUE_OR_GOTO
  1529. } catch (...) {
  1530. //
  1531. // system error continue with next setting
  1532. //
  1533. rcSave = EVENT_E_INTERNALEXCEPTION;
  1534. }
  1535. }
  1536. //
  1537. // user groups settings
  1538. //
  1539. if (cbArea & SCE_RSOP_GROUP_INFO) {
  1540. try {
  1541. PWSTR pCanonicalGroupName = NULL;
  1542. PWSTR pwszCanonicalDoubleSlashName = NULL;
  1543. rc = ScepCanonicalizeGroupName(pSettingInfo,
  1544. &pCanonicalGroupName
  1545. );
  1546. SCEP_RSOP_CONTINUE_OR_GOTO
  1547. rc = ScepConvertSingleSlashToDoubleSlashPath(
  1548. pCanonicalGroupName,
  1549. &pwszCanonicalDoubleSlashName
  1550. );
  1551. if (rc == ERROR_NOT_ENOUGH_MEMORY && pCanonicalGroupName) {
  1552. ScepFree(pCanonicalGroupName);
  1553. pCanonicalGroupName = NULL;
  1554. }
  1555. SCEP_RSOP_CONTINUE_OR_GOTO
  1556. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_RestrictedGroup",
  1557. L"GroupName",
  1558. pwszCanonicalDoubleSlashName,
  1559. ncbErrorStatus,
  1560. FALSE
  1561. ));
  1562. ScepLogEventAndReport(MyModuleHandle,
  1563. gpwszPlanOrDiagLogFile,
  1564. 0,
  1565. 0,
  1566. IDS_ERROR_RSOP_DIAG_LOG,
  1567. rc,
  1568. pCanonicalGroupName
  1569. );
  1570. if (pCanonicalGroupName)
  1571. ScepFree(pCanonicalGroupName);
  1572. if (pwszCanonicalDoubleSlashName)
  1573. LocalFree(pwszCanonicalDoubleSlashName);
  1574. SCEP_RSOP_CONTINUE_OR_GOTO
  1575. } catch (...) {
  1576. //
  1577. // system error continue with next setting
  1578. //
  1579. rcSave = EVENT_E_INTERNALEXCEPTION;
  1580. }
  1581. }
  1582. //
  1583. // user privileges settings
  1584. //
  1585. if (cbArea & SCE_RSOP_PRIVILEGE_INFO) {
  1586. try {
  1587. //
  1588. // loop through all privileges to see which are set for this account and log status
  1589. // only if existing status is already != some error
  1590. //
  1591. for ( UINT i=0; i<cPrivCnt; i++) {
  1592. if ( i < 32 ) {
  1593. if (dwPrivLow & (1 << i )) {
  1594. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_UserPrivilegeRight",
  1595. L"UserRight",
  1596. SCE_Privileges[i].Name,
  1597. ncbErrorStatus,
  1598. TRUE));
  1599. ScepLogEventAndReport(MyModuleHandle,
  1600. gpwszPlanOrDiagLogFile,
  1601. 0,
  1602. 0,
  1603. IDS_ERROR_RSOP_DIAG_LOG,
  1604. rc,
  1605. SCE_Privileges[i].Name
  1606. );
  1607. SCEP_RSOP_CONTINUE_OR_GOTO
  1608. }
  1609. } else {
  1610. if (dwPrivHigh & (1 << (i-32 ))) {
  1611. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_UserPrivilegeRight",
  1612. L"UserRight",
  1613. SCE_Privileges[i].Name,
  1614. ncbErrorStatus,
  1615. TRUE));
  1616. ScepLogEventAndReport(MyModuleHandle,
  1617. gpwszPlanOrDiagLogFile,
  1618. 0,
  1619. 0,
  1620. IDS_ERROR_RSOP_DIAG_LOG,
  1621. rc,
  1622. SCE_Privileges[i].Name
  1623. );
  1624. SCEP_RSOP_CONTINUE_OR_GOTO
  1625. }
  1626. }
  1627. }
  1628. } catch (...) {
  1629. //
  1630. // system error continue with next setting
  1631. //
  1632. rcSave = EVENT_E_INTERNALEXCEPTION;
  1633. }
  1634. }
  1635. //
  1636. // file security settings
  1637. //
  1638. if (cbArea & SCE_RSOP_FILE_SECURITY_INFO) {
  1639. PWSTR pwszDoubleSlashPath = NULL;
  1640. try {
  1641. rc = ScepConvertSingleSlashToDoubleSlashPath(
  1642. pSettingInfo,
  1643. &pwszDoubleSlashPath
  1644. );
  1645. SCEP_RSOP_CONTINUE_OR_GOTO
  1646. //
  1647. // the file itself
  1648. //
  1649. if (!(cbArea & SCE_RSOP_FILE_SECURITY_INFO_CHILD)) {
  1650. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_File",
  1651. L"Path",
  1652. pwszDoubleSlashPath,
  1653. ncbErrorStatus,
  1654. FALSE
  1655. ));
  1656. ScepLogEventAndReport(MyModuleHandle,
  1657. gpwszPlanOrDiagLogFile,
  1658. 0,
  1659. 0,
  1660. IDS_ERROR_RSOP_DIAG_LOG,
  1661. rc,
  1662. pSettingInfo
  1663. );
  1664. } else {
  1665. //
  1666. // the file was error free, but some child failed
  1667. //
  1668. rc = ScepWbemErrorToDosError(Log.LogChild(L"RSOP_File",
  1669. L"Path",
  1670. pwszDoubleSlashPath,
  1671. ncbErrorStatus,
  1672. 4
  1673. ));
  1674. ScepLogEventAndReport(MyModuleHandle,
  1675. gpwszPlanOrDiagLogFile,
  1676. 0,
  1677. 0,
  1678. IDS_ERROR_RSOP_DIAG_LOG,
  1679. rc,
  1680. pSettingInfo
  1681. );
  1682. }
  1683. if (pwszDoubleSlashPath)
  1684. LocalFree(pwszDoubleSlashPath);
  1685. pwszDoubleSlashPath = NULL;
  1686. SCEP_RSOP_CONTINUE_OR_GOTO
  1687. } catch (...) {
  1688. if (pwszDoubleSlashPath)
  1689. LocalFree(pwszDoubleSlashPath);
  1690. //
  1691. // system error continue with next setting
  1692. //
  1693. rcSave = EVENT_E_INTERNALEXCEPTION;
  1694. }
  1695. }
  1696. //
  1697. // registry security settings
  1698. //
  1699. if (cbArea & SCE_RSOP_REGISTRY_SECURITY_INFO) {
  1700. PWSTR pwszDoubleSlashPath = NULL;
  1701. try {
  1702. rc = ScepConvertSingleSlashToDoubleSlashPath(
  1703. pSettingInfo,
  1704. &pwszDoubleSlashPath
  1705. );
  1706. SCEP_RSOP_CONTINUE_OR_GOTO
  1707. //
  1708. // the registry key itself
  1709. //
  1710. if (!(cbArea & SCE_RSOP_REGISTRY_SECURITY_INFO_CHILD)) {
  1711. #ifdef _WIN64
  1712. rc = ScepWbemErrorToDosError(Log.LogRegistryKey(L"RSOP_RegistryKey",
  1713. L"Path",
  1714. pwszDoubleSlashPath,
  1715. ncbErrorStatus,
  1716. FALSE
  1717. ));
  1718. ScepLogEventAndReport(MyModuleHandle,
  1719. gpwszPlanOrDiagLogFile,
  1720. 0,
  1721. 0,
  1722. IDS_ERROR_RSOP_DIAG_LOG64_32KEY,
  1723. rc,
  1724. pSettingInfo
  1725. );
  1726. #else
  1727. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_RegistryKey",
  1728. L"Path",
  1729. pwszDoubleSlashPath,
  1730. ncbErrorStatus,
  1731. FALSE
  1732. ));
  1733. ScepLogEventAndReport(MyModuleHandle,
  1734. gpwszPlanOrDiagLogFile,
  1735. 0,
  1736. 0,
  1737. IDS_ERROR_RSOP_DIAG_LOG,
  1738. rc,
  1739. pSettingInfo
  1740. );
  1741. #endif
  1742. } else {
  1743. //
  1744. // the registry-key was error free, but some child failed
  1745. //
  1746. #ifdef _WIN64
  1747. rc = ScepWbemErrorToDosError(Log.LogRegistryKey(L"RSOP_RegistryKey",
  1748. L"Path",
  1749. pwszDoubleSlashPath,
  1750. ncbErrorStatus,
  1751. TRUE
  1752. ));
  1753. ScepLogEventAndReport(MyModuleHandle,
  1754. gpwszPlanOrDiagLogFile,
  1755. 0,
  1756. 0,
  1757. IDS_ERROR_RSOP_DIAG_LOG64_32KEY,
  1758. rc,
  1759. pSettingInfo
  1760. );
  1761. #else
  1762. rc = ScepWbemErrorToDosError(Log.LogChild(L"RSOP_RegistryKey",
  1763. L"Path",
  1764. pwszDoubleSlashPath,
  1765. ncbErrorStatus,
  1766. 4
  1767. ));
  1768. ScepLogEventAndReport(MyModuleHandle,
  1769. gpwszPlanOrDiagLogFile,
  1770. 0,
  1771. 0,
  1772. IDS_ERROR_RSOP_DIAG_LOG,
  1773. rc,
  1774. pSettingInfo
  1775. );
  1776. #endif
  1777. }
  1778. if (pwszDoubleSlashPath)
  1779. LocalFree(pwszDoubleSlashPath);
  1780. pwszDoubleSlashPath = NULL;
  1781. SCEP_RSOP_CONTINUE_OR_GOTO
  1782. } catch (...) {
  1783. if (pwszDoubleSlashPath)
  1784. LocalFree(pwszDoubleSlashPath);
  1785. //
  1786. // system error continue with next setting
  1787. //
  1788. rcSave = EVENT_E_INTERNALEXCEPTION;
  1789. }
  1790. }
  1791. //
  1792. // auditlogmaxsize settings
  1793. //
  1794. if (cbArea & SCE_RSOP_AUDIT_LOG_MAXSIZE_INFO) {
  1795. try {
  1796. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecurityEventLogSettingNumeric",
  1797. L"KeyName",
  1798. L"MaximumLogSize",
  1799. L"Type",
  1800. pSettingInfo,
  1801. ncbErrorStatus
  1802. ));
  1803. ScepLogEventAndReport(MyModuleHandle,
  1804. gpwszPlanOrDiagLogFile,
  1805. 0,
  1806. 0,
  1807. IDS_ERROR_RSOP_DIAG_LOG,
  1808. rc,
  1809. L"MaximumLogSize"
  1810. );
  1811. SCEP_RSOP_CONTINUE_OR_GOTO
  1812. } catch (...) {
  1813. //
  1814. // system error continue with next setting
  1815. //
  1816. rcSave = EVENT_E_INTERNALEXCEPTION;
  1817. }
  1818. }
  1819. //
  1820. // auditlogretention settings
  1821. //
  1822. if (cbArea & SCE_RSOP_AUDIT_LOG_RETENTION_INFO) {
  1823. try {
  1824. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecurityEventLogSettingNumeric",
  1825. L"KeyName",
  1826. L"RetentionDays",
  1827. L"Type",
  1828. pSettingInfo,
  1829. ncbErrorStatus
  1830. ));
  1831. ScepLogEventAndReport(MyModuleHandle,
  1832. gpwszPlanOrDiagLogFile,
  1833. 0,
  1834. 0,
  1835. IDS_ERROR_RSOP_DIAG_LOG,
  1836. rc,
  1837. L"RetentionDays"
  1838. );
  1839. SCEP_RSOP_CONTINUE_OR_GOTO
  1840. } catch (...) {
  1841. //
  1842. // system error continue with next setting
  1843. //
  1844. rcSave = EVENT_E_INTERNALEXCEPTION;
  1845. }
  1846. }
  1847. //
  1848. // auditlogguest settings
  1849. //
  1850. if (cbArea & SCE_RSOP_AUDIT_LOG_GUEST_INFO) {
  1851. try {
  1852. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecurityEventLogSettingBolean",
  1853. L"KeyName",
  1854. L"RestrictGuestAccess",
  1855. L"Type",
  1856. pSettingInfo,
  1857. ncbErrorStatus
  1858. ));
  1859. ScepLogEventAndReport(MyModuleHandle,
  1860. gpwszPlanOrDiagLogFile,
  1861. 0,
  1862. 0,
  1863. IDS_ERROR_RSOP_DIAG_LOG,
  1864. rc,
  1865. L"RestrictGuestAccess"
  1866. );
  1867. SCEP_RSOP_CONTINUE_OR_GOTO
  1868. } catch (...) {
  1869. //
  1870. // system error continue with next setting
  1871. //
  1872. rcSave = EVENT_E_INTERNALEXCEPTION;
  1873. }
  1874. }
  1875. //
  1876. // auditevent settings
  1877. //
  1878. if (cbArea & SCE_RSOP_AUDIT_EVENT_INFO) {
  1879. try {
  1880. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_AuditPolicy",
  1881. L"Category",
  1882. L"AuditSystemEvents",
  1883. ncbErrorStatus,
  1884. FALSE
  1885. ));
  1886. ScepLogEventAndReport(MyModuleHandle,
  1887. gpwszPlanOrDiagLogFile,
  1888. 0,
  1889. 0,
  1890. IDS_ERROR_RSOP_DIAG_LOG,
  1891. rc,
  1892. L"AuditSystemEvents"
  1893. );
  1894. SCEP_RSOP_CONTINUE_OR_GOTO
  1895. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_AuditPolicy",
  1896. L"Category",
  1897. L"AuditLogonEvents",
  1898. ncbErrorStatus,
  1899. FALSE
  1900. ));
  1901. ScepLogEventAndReport(MyModuleHandle,
  1902. gpwszPlanOrDiagLogFile,
  1903. 0,
  1904. 0,
  1905. IDS_ERROR_RSOP_DIAG_LOG,
  1906. rc,
  1907. L"AuditLogonEvents"
  1908. );
  1909. SCEP_RSOP_CONTINUE_OR_GOTO
  1910. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_AuditPolicy",
  1911. L"Category",
  1912. L"AuditObjectAccess",
  1913. ncbErrorStatus,
  1914. FALSE
  1915. ));
  1916. ScepLogEventAndReport(MyModuleHandle,
  1917. gpwszPlanOrDiagLogFile,
  1918. 0,
  1919. 0,
  1920. IDS_ERROR_RSOP_DIAG_LOG,
  1921. rc,
  1922. L"AuditObjectAccess"
  1923. );
  1924. SCEP_RSOP_CONTINUE_OR_GOTO
  1925. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_AuditPolicy",
  1926. L"Category",
  1927. L"AuditPrivilegeUse",
  1928. ncbErrorStatus,
  1929. FALSE
  1930. ));
  1931. ScepLogEventAndReport(MyModuleHandle,
  1932. gpwszPlanOrDiagLogFile,
  1933. 0,
  1934. 0,
  1935. IDS_ERROR_RSOP_DIAG_LOG,
  1936. rc,
  1937. L"AuditPrivilegeUse"
  1938. );
  1939. SCEP_RSOP_CONTINUE_OR_GOTO
  1940. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_AuditPolicy",
  1941. L"Category",
  1942. L"AuditPolicyChange",
  1943. ncbErrorStatus,
  1944. FALSE
  1945. ));
  1946. ScepLogEventAndReport(MyModuleHandle,
  1947. gpwszPlanOrDiagLogFile,
  1948. 0,
  1949. 0,
  1950. IDS_ERROR_RSOP_DIAG_LOG,
  1951. rc,
  1952. L"AuditPolicyChange"
  1953. );
  1954. SCEP_RSOP_CONTINUE_OR_GOTO
  1955. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_AuditPolicy",
  1956. L"Category",
  1957. L"AuditAccountManage",
  1958. ncbErrorStatus,
  1959. FALSE
  1960. ));
  1961. ScepLogEventAndReport(MyModuleHandle,
  1962. gpwszPlanOrDiagLogFile,
  1963. 0,
  1964. 0,
  1965. IDS_ERROR_RSOP_DIAG_LOG,
  1966. rc,
  1967. L"AuditAccountManage"
  1968. );
  1969. SCEP_RSOP_CONTINUE_OR_GOTO
  1970. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_AuditPolicy",
  1971. L"Category",
  1972. L"AuditProcessTracking",
  1973. ncbErrorStatus,
  1974. FALSE
  1975. ));
  1976. ScepLogEventAndReport(MyModuleHandle,
  1977. gpwszPlanOrDiagLogFile,
  1978. 0,
  1979. 0,
  1980. IDS_ERROR_RSOP_DIAG_LOG,
  1981. rc,
  1982. L"AuditProcessTracking"
  1983. );
  1984. SCEP_RSOP_CONTINUE_OR_GOTO
  1985. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_AuditPolicy",
  1986. L"Category",
  1987. L"AuditDSAccess",
  1988. ncbErrorStatus,
  1989. FALSE
  1990. ));
  1991. ScepLogEventAndReport(MyModuleHandle,
  1992. gpwszPlanOrDiagLogFile,
  1993. 0,
  1994. 0,
  1995. IDS_ERROR_RSOP_DIAG_LOG,
  1996. rc,
  1997. L"AuditDSAccess"
  1998. );
  1999. SCEP_RSOP_CONTINUE_OR_GOTO
  2000. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_AuditPolicy",
  2001. L"Category",
  2002. L"AuditAccountLogon",
  2003. ncbErrorStatus,
  2004. FALSE
  2005. ));
  2006. ScepLogEventAndReport(MyModuleHandle,
  2007. gpwszPlanOrDiagLogFile,
  2008. 0,
  2009. 0,
  2010. IDS_ERROR_RSOP_DIAG_LOG,
  2011. rc,
  2012. L"AuditAccountLogon"
  2013. );
  2014. SCEP_RSOP_CONTINUE_OR_GOTO
  2015. } catch (...) {
  2016. //
  2017. // system error continue with next setting
  2018. //
  2019. rcSave = EVENT_E_INTERNALEXCEPTION;
  2020. }
  2021. }
  2022. //
  2023. // kerberos settings
  2024. //
  2025. if (cbArea & SCE_RSOP_KERBEROS_INFO) {
  2026. try {
  2027. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  2028. L"KeyName",
  2029. L"MaxTicketAge",
  2030. ncbErrorStatus,
  2031. FALSE
  2032. ));
  2033. ScepLogEventAndReport(MyModuleHandle,
  2034. gpwszPlanOrDiagLogFile,
  2035. 0,
  2036. 0,
  2037. IDS_ERROR_RSOP_DIAG_LOG,
  2038. rc,
  2039. L"MaxTicketAge"
  2040. );
  2041. SCEP_RSOP_CONTINUE_OR_GOTO
  2042. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  2043. L"KeyName",
  2044. L"MaxRenewAge",
  2045. ncbErrorStatus,
  2046. FALSE
  2047. ));
  2048. ScepLogEventAndReport(MyModuleHandle,
  2049. gpwszPlanOrDiagLogFile,
  2050. 0,
  2051. 0,
  2052. IDS_ERROR_RSOP_DIAG_LOG,
  2053. rc,
  2054. L"MaxRenewAge"
  2055. );
  2056. SCEP_RSOP_CONTINUE_OR_GOTO
  2057. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  2058. L"KeyName",
  2059. L"MaxServiceAge",
  2060. ncbErrorStatus,
  2061. FALSE
  2062. ));
  2063. ScepLogEventAndReport(MyModuleHandle,
  2064. gpwszPlanOrDiagLogFile,
  2065. 0,
  2066. 0,
  2067. IDS_ERROR_RSOP_DIAG_LOG,
  2068. rc,
  2069. L"MaxServiceAge"
  2070. );
  2071. SCEP_RSOP_CONTINUE_OR_GOTO
  2072. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingNumeric",
  2073. L"KeyName",
  2074. L"MaxClockSkew",
  2075. ncbErrorStatus,
  2076. FALSE
  2077. ));
  2078. ScepLogEventAndReport(MyModuleHandle,
  2079. gpwszPlanOrDiagLogFile,
  2080. 0,
  2081. 0,
  2082. IDS_ERROR_RSOP_DIAG_LOG,
  2083. rc,
  2084. L"MaxClockSkew"
  2085. );
  2086. SCEP_RSOP_CONTINUE_OR_GOTO
  2087. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SecuritySettingBoolean",
  2088. L"KeyName",
  2089. L"TicketValidateClient",
  2090. ncbErrorStatus,
  2091. FALSE
  2092. ));
  2093. ScepLogEventAndReport(MyModuleHandle,
  2094. gpwszPlanOrDiagLogFile,
  2095. 0,
  2096. 0,
  2097. IDS_ERROR_RSOP_DIAG_LOG,
  2098. rc,
  2099. L"TicketValidateClient"
  2100. );
  2101. SCEP_RSOP_CONTINUE_OR_GOTO
  2102. } catch (...) {
  2103. //
  2104. // system error continue with next setting
  2105. //
  2106. rcSave = EVENT_E_INTERNALEXCEPTION;
  2107. }
  2108. }
  2109. //
  2110. // registryvalue settings
  2111. //
  2112. if (cbArea & SCE_RSOP_REGISTRY_VALUE_INFO) {
  2113. PWSTR pwszDoubleSlashPath = NULL;
  2114. try {
  2115. //
  2116. // replace single slash with double slash for building valid WMI query
  2117. //
  2118. rc = ScepConvertSingleSlashToDoubleSlashPath(
  2119. pSettingInfo,
  2120. &pwszDoubleSlashPath
  2121. );
  2122. SCEP_RSOP_CONTINUE_OR_GOTO
  2123. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_RegistryValue",
  2124. L"Path",
  2125. pwszDoubleSlashPath,
  2126. ncbErrorStatus,
  2127. FALSE
  2128. ));
  2129. if (pwszDoubleSlashPath)
  2130. LocalFree(pwszDoubleSlashPath);
  2131. pwszDoubleSlashPath = NULL;
  2132. ScepLogEventAndReport(MyModuleHandle,
  2133. gpwszPlanOrDiagLogFile,
  2134. 0,
  2135. 0,
  2136. IDS_ERROR_RSOP_DIAG_LOG,
  2137. rc,
  2138. pSettingInfo
  2139. );
  2140. SCEP_RSOP_CONTINUE_OR_GOTO
  2141. } catch (...) {
  2142. if (pwszDoubleSlashPath)
  2143. LocalFree(pwszDoubleSlashPath);
  2144. //
  2145. // system error continue with next setting
  2146. //
  2147. rcSave = EVENT_E_INTERNALEXCEPTION;
  2148. }
  2149. }
  2150. //
  2151. // services settings
  2152. //
  2153. if (cbArea & SCE_RSOP_SERVICES_INFO) {
  2154. try {
  2155. rc = ScepWbemErrorToDosError(Log.Log(L"RSOP_SystemService",
  2156. L"Service",
  2157. pSettingInfo,
  2158. ncbErrorStatus,
  2159. FALSE
  2160. ));
  2161. ScepLogEventAndReport(MyModuleHandle,
  2162. gpwszPlanOrDiagLogFile,
  2163. 0,
  2164. 0,
  2165. IDS_ERROR_RSOP_DIAG_LOG,
  2166. rc,
  2167. pSettingInfo
  2168. );
  2169. SCEP_RSOP_CONTINUE_OR_GOTO
  2170. } catch (...) {
  2171. //
  2172. // system error continue with next setting
  2173. //
  2174. rcSave = EVENT_E_INTERNALEXCEPTION;
  2175. }
  2176. }
  2177. Done:
  2178. //
  2179. // if exception, haven't logged yet so log it
  2180. //
  2181. if (rcSave == EVENT_E_INTERNALEXCEPTION) {
  2182. ScepLogEventAndReport(MyModuleHandle,
  2183. gpwszPlanOrDiagLogFile,
  2184. 0,
  2185. 0,
  2186. IDS_ERROR_RSOP_DIAG_LOG,
  2187. rcSave,
  2188. L""
  2189. );
  2190. }
  2191. //
  2192. // merge-update the synch/asynch global status, ignore not found instances
  2193. //
  2194. //
  2195. // WBEM_E_NOT_FOUND maps to ERROR_NONE_MAPPED
  2196. // have to mask this due to an artifact of callback granularity
  2197. // however, diagnosis.log will have the errors for debugging
  2198. //
  2199. if (rcSave != ERROR_SUCCESS && rcSave != ERROR_NOT_FOUND ) {
  2200. if (!gbAsyncWinlogonThread && gHrSynchRsopStatus == S_OK)
  2201. gHrSynchRsopStatus = ScepDosErrorToWbemError(rcSave);
  2202. if (gbAsyncWinlogonThread && gHrAsynchRsopStatus == S_OK)
  2203. gHrAsynchRsopStatus = ScepDosErrorToWbemError(rcSave);
  2204. }
  2205. } catch (...) {
  2206. rcSave = EVENT_E_INTERNALEXCEPTION;
  2207. }
  2208. return rcSave;
  2209. }
  2210. DWORD
  2211. ScepConvertSingleSlashToDoubleSlashPath(
  2212. IN wchar_t *pSettingInfo,
  2213. OUT PWSTR *ppwszDoubleSlashPath
  2214. )
  2215. /////////////////////////////////////////////////////////////////////////////////////////////////////
  2216. // This function converts single slashes to double slashes to suit WMI queries //
  2217. // If success is returned, caller should free the OUT parameter //
  2218. /////////////////////////////////////////////////////////////////////////////////////////////////////
  2219. {
  2220. if (ppwszDoubleSlashPath == NULL)
  2221. return ERROR_NOT_ENOUGH_MEMORY;
  2222. UINT Len = wcslen(pSettingInfo) + 1;
  2223. PWSTR pwszSingleSlashPath=(PWSTR)LocalAlloc(LPTR, (Len)*sizeof(WCHAR));
  2224. if (pwszSingleSlashPath == NULL)
  2225. return ERROR_NOT_ENOUGH_MEMORY;
  2226. //
  2227. // max of 25 slashes per file/registry object
  2228. //
  2229. PWSTR pwszDoubleSlashPath=(PWSTR)LocalAlloc(LPTR, (Len + 50)*sizeof(WCHAR));
  2230. if (pwszDoubleSlashPath == NULL) {
  2231. LocalFree(pwszSingleSlashPath);
  2232. return ERROR_NOT_ENOUGH_MEMORY;
  2233. }
  2234. wcscpy(pwszSingleSlashPath, pSettingInfo);
  2235. UINT charNumDouble = 0;
  2236. UINT charNumSingle = 0;
  2237. while (pwszSingleSlashPath[charNumSingle] != L'\0') {
  2238. if (pwszSingleSlashPath[charNumSingle] == L'\\') {
  2239. pwszDoubleSlashPath[charNumDouble] = L'\\';
  2240. charNumDouble++;
  2241. pwszDoubleSlashPath[charNumDouble] = L'\\';
  2242. } else {
  2243. pwszDoubleSlashPath[charNumDouble] = pwszSingleSlashPath[charNumSingle];
  2244. }
  2245. charNumDouble++;
  2246. charNumSingle++;
  2247. }
  2248. if (pwszSingleSlashPath)
  2249. LocalFree(pwszSingleSlashPath);
  2250. *ppwszDoubleSlashPath = pwszDoubleSlashPath;
  2251. return ERROR_SUCCESS;
  2252. }
  2253. DWORD
  2254. ScepClientTranslateFileDirName(
  2255. IN PWSTR oldFileName,
  2256. OUT PWSTR *newFileName
  2257. )
  2258. /* ++
  2259. Routine Description:
  2260. This routine converts a generic file/directory name to a real used name
  2261. for the current system. The following generic file/directory names are handled:
  2262. %systemroot% - Windows NT root directory (e.g., c:\winnt)
  2263. %systemDirectory% - Windows NT system32 directory (e.g., c:\winnt\system32)
  2264. Arguments:
  2265. oldFileName - the file name to convert, which includes "%" to represent
  2266. some directory names
  2267. newFileName - the real file name, in which the "%" name is replaced with
  2268. the real directory name
  2269. Return values:
  2270. Win32 error code
  2271. -- */
  2272. {
  2273. //
  2274. // match for %systemroot%
  2275. //
  2276. PWSTR pTemp=NULL, pStart, TmpBuf, szVar;
  2277. DWORD rc=NO_ERROR;
  2278. DWORD newFileSize, cSize;
  2279. BOOL bContinue;
  2280. rc = ScepExpandEnvironmentVariable(oldFileName,
  2281. L"%SYSTEMROOT%",
  2282. SCE_FLAG_WINDOWS_DIR,
  2283. newFileName);
  2284. if ( rc != ERROR_FILE_NOT_FOUND ) {
  2285. return rc;
  2286. }
  2287. //
  2288. // match for %systemdirectory%
  2289. //
  2290. rc = ScepExpandEnvironmentVariable(oldFileName,
  2291. L"%SYSTEMDIRECTORY%",
  2292. SCE_FLAG_SYSTEM_DIR,
  2293. newFileName);
  2294. if ( rc != ERROR_FILE_NOT_FOUND ) {
  2295. return rc;
  2296. }
  2297. //
  2298. // match for systemdrive
  2299. //
  2300. rc = ScepExpandEnvironmentVariable(oldFileName,
  2301. L"%SYSTEMDRIVE%",
  2302. SCE_FLAG_WINDOWS_DIR,
  2303. newFileName);
  2304. if ( rc != ERROR_FILE_NOT_FOUND ) {
  2305. return rc;
  2306. }
  2307. //
  2308. // match for boot drive
  2309. //
  2310. rc = ScepExpandEnvironmentVariable(oldFileName,
  2311. L"%BOOTDRIVE%",
  2312. SCE_FLAG_BOOT_DRIVE,
  2313. newFileName);
  2314. if ( rc != ERROR_FILE_NOT_FOUND ) {
  2315. return rc;
  2316. }
  2317. rc = ERROR_SUCCESS;
  2318. //
  2319. // search for environment variable in the current process
  2320. //
  2321. pStart = wcschr(oldFileName, L'%');
  2322. if ( pStart ) {
  2323. pTemp = wcschr(pStart+1, L'%');
  2324. if ( pTemp ) {
  2325. bContinue = TRUE;
  2326. //
  2327. // find a environment variable to translate
  2328. //
  2329. TmpBuf = (PWSTR)ScepAlloc(0, ((UINT)(pTemp-pStart))*sizeof(WCHAR));
  2330. if ( TmpBuf ) {
  2331. wcsncpy(TmpBuf, pStart+1, (size_t)(pTemp-pStart-1));
  2332. TmpBuf[pTemp-pStart-1] = L'\0';
  2333. //
  2334. // try search in the client environment block
  2335. //
  2336. cSize = GetEnvironmentVariable( TmpBuf,
  2337. NULL,
  2338. 0 );
  2339. if ( cSize > 0 ) {
  2340. szVar = (PWSTR)ScepAlloc(0, (cSize+1)*sizeof(WCHAR));
  2341. if ( szVar ) {
  2342. cSize = GetEnvironmentVariable(TmpBuf,
  2343. szVar,
  2344. cSize);
  2345. if ( cSize > 0 ) {
  2346. //
  2347. // get info in szVar
  2348. //
  2349. bContinue = FALSE;
  2350. newFileSize = ((DWORD)(pStart-oldFileName))+cSize+wcslen(pTemp+1)+1;
  2351. *newFileName = (PWSTR)ScepAlloc(0, newFileSize*sizeof(TCHAR));
  2352. if (*newFileName ) {
  2353. if ( pStart != oldFileName )
  2354. wcsncpy(*newFileName, oldFileName, (size_t)(pStart-oldFileName));
  2355. swprintf((PWSTR)(*newFileName+(pStart-oldFileName)), L"%s%s", szVar, pTemp+1);
  2356. } else
  2357. rc = ERROR_NOT_ENOUGH_MEMORY;
  2358. }
  2359. ScepFree(szVar);
  2360. } else
  2361. rc = ERROR_NOT_ENOUGH_MEMORY;
  2362. }
  2363. ScepFree(TmpBuf);
  2364. } else
  2365. rc = ERROR_NOT_ENOUGH_MEMORY;
  2366. if ( NO_ERROR != rc || !bContinue ) {
  2367. //
  2368. // if errored, or do not continue
  2369. //
  2370. return(rc);
  2371. }
  2372. //
  2373. // not found in process environment,
  2374. // continue to search for DSDIT/DSLOG/SYSVOL in registry
  2375. //
  2376. if ( (gbDCQueried == TRUE && gbThisIsDC == TRUE) ) {
  2377. //
  2378. // search for DSDIT
  2379. //
  2380. rc = ScepExpandEnvironmentVariable(oldFileName,
  2381. L"%DSDIT%",
  2382. SCE_FLAG_DSDIT_DIR,
  2383. newFileName);
  2384. if ( rc != ERROR_FILE_NOT_FOUND ) {
  2385. return rc;
  2386. }
  2387. //
  2388. // search for DSLOG
  2389. //
  2390. rc = ScepExpandEnvironmentVariable(oldFileName,
  2391. L"%DSLOG%",
  2392. SCE_FLAG_DSLOG_DIR,
  2393. newFileName);
  2394. if ( rc != ERROR_FILE_NOT_FOUND ) {
  2395. return rc;
  2396. }
  2397. //
  2398. // search for SYSVOL
  2399. //
  2400. rc = ScepExpandEnvironmentVariable(oldFileName,
  2401. L"%SYSVOL%",
  2402. SCE_FLAG_SYSVOL_DIR,
  2403. newFileName);
  2404. if ( rc != ERROR_FILE_NOT_FOUND ) {
  2405. return rc;
  2406. }
  2407. }
  2408. }
  2409. }
  2410. //
  2411. // Otherwise, just copy the old name to a new buffer and return ERROR_PATH_NOT_FOUND
  2412. //
  2413. *newFileName = (PWSTR)ScepAlloc(0, (wcslen(oldFileName)+1)*sizeof(TCHAR));
  2414. if (*newFileName != NULL) {
  2415. wcscpy(*newFileName, _wcsupr(oldFileName) );
  2416. rc = ERROR_PATH_NOT_FOUND;
  2417. } else
  2418. rc = ERROR_NOT_ENOUGH_MEMORY;
  2419. return(rc);
  2420. }
  2421. VOID
  2422. ScepLogEventAndReport(
  2423. IN HINSTANCE hInstance,
  2424. IN LPTSTR LogFileName,
  2425. IN DWORD LogLevel,
  2426. IN DWORD dwEventID,
  2427. IN UINT idMsg,
  2428. IN DWORD rc,
  2429. IN PWSTR pwszMsg
  2430. )
  2431. /////////////////////////////////////////////////////////////////////////////////////////////////////
  2432. // Wrapper to log efficiently //
  2433. /////////////////////////////////////////////////////////////////////////////////////////////////////
  2434. {
  2435. if (SCEP_VALID_NAME(LogFileName)) {
  2436. LogEventAndReport(hInstance,
  2437. LogFileName,
  2438. LogLevel,
  2439. dwEventID,
  2440. idMsg,
  2441. rc,
  2442. pwszMsg
  2443. );
  2444. }
  2445. }
  2446. DWORD
  2447. ScepCanonicalizeGroupName(
  2448. IN PWSTR pwszGroupName,
  2449. OUT PWSTR *ppwszCanonicalGroupName
  2450. )
  2451. //////////////////////////////////////////////////////////////////////////////////
  2452. // memory allocated here should be freed outside //
  2453. // if SID format, returns SID itself //
  2454. // else if "BuiltinDomain\Administrator" convert to "Administrator" //
  2455. // else if (it is DC) and "g" convert to "DomainName\g" //
  2456. //////////////////////////////////////////////////////////////////////////////////
  2457. {
  2458. DWORD rc = NO_ERROR;
  2459. if (pwszGroupName == NULL || ppwszCanonicalGroupName == NULL)
  2460. return ERROR_INVALID_PARAMETER;
  2461. PWSTR pwszAfterSlash = NULL;
  2462. if (pwszAfterSlash = wcsstr(pwszGroupName, L"\\"))
  2463. ++ pwszAfterSlash;
  2464. else
  2465. pwszAfterSlash = pwszGroupName;
  2466. if ( pwszGroupName[0] == L'*' ) {
  2467. //
  2468. // if sid, just copy as is
  2469. //
  2470. *ppwszCanonicalGroupName = (PWSTR)ScepAlloc(LMEM_ZEROINIT,
  2471. (wcslen(pwszGroupName) + 1) * sizeof (WCHAR)
  2472. );
  2473. if (*ppwszCanonicalGroupName == NULL)
  2474. rc = ERROR_NOT_ENOUGH_MEMORY;
  2475. else
  2476. wcscpy(*ppwszCanonicalGroupName, pwszGroupName);
  2477. }
  2478. else if (ScepRsopLookupBuiltinNameTable(pwszAfterSlash)) {
  2479. //
  2480. // example - if "BuiltinDomainName\Administrator", we need "Administrator"
  2481. //
  2482. *ppwszCanonicalGroupName = (PWSTR)ScepAlloc(LMEM_ZEROINIT,
  2483. (wcslen(pwszAfterSlash) + 1) * sizeof (WCHAR)
  2484. );
  2485. if (*ppwszCanonicalGroupName == NULL)
  2486. rc = ERROR_NOT_ENOUGH_MEMORY;
  2487. else
  2488. wcscpy(*ppwszCanonicalGroupName, pwszAfterSlash);
  2489. }
  2490. else if (gbDCQueried == TRUE && gbThisIsDC == TRUE) {
  2491. //
  2492. // example - if "g", we need "DomainName\g"
  2493. //
  2494. if (NULL == wcsstr(pwszGroupName, L"\\")){
  2495. //
  2496. // if domain name is not available, we continue since callback will have the same problem, so OK
  2497. //
  2498. if (gpwszDCDomainName){
  2499. *ppwszCanonicalGroupName = (PWSTR)ScepAlloc(LMEM_ZEROINIT,
  2500. (wcslen(gpwszDCDomainName) + wcslen(pwszGroupName) + 2) * sizeof (WCHAR)
  2501. );
  2502. if (*ppwszCanonicalGroupName == NULL)
  2503. rc = ERROR_NOT_ENOUGH_MEMORY;
  2504. else {
  2505. wcscpy(*ppwszCanonicalGroupName, gpwszDCDomainName);
  2506. wcscat(*ppwszCanonicalGroupName, L"\\");
  2507. wcscat(*ppwszCanonicalGroupName, pwszGroupName);
  2508. }
  2509. }
  2510. }
  2511. else {
  2512. //
  2513. // already in "DomainName\g" format - simply copy
  2514. //
  2515. *ppwszCanonicalGroupName = (PWSTR)ScepAlloc(LMEM_ZEROINIT,
  2516. (wcslen(pwszGroupName) + 1) * sizeof (WCHAR)
  2517. );
  2518. if (*ppwszCanonicalGroupName == NULL)
  2519. rc = ERROR_NOT_ENOUGH_MEMORY;
  2520. else
  2521. wcscpy(*ppwszCanonicalGroupName, pwszGroupName);
  2522. }
  2523. }
  2524. else {
  2525. //
  2526. // simply copy - workstation or none of the above matched
  2527. //
  2528. *ppwszCanonicalGroupName = (PWSTR)ScepAlloc(LMEM_ZEROINIT,
  2529. (wcslen(pwszGroupName) + 1) * sizeof (WCHAR)
  2530. );
  2531. if (*ppwszCanonicalGroupName == NULL)
  2532. rc = ERROR_NOT_ENOUGH_MEMORY;
  2533. else
  2534. wcscpy(*ppwszCanonicalGroupName, pwszGroupName);
  2535. }
  2536. return rc;
  2537. }
  2538. BOOL
  2539. ScepRsopLookupBuiltinNameTable(
  2540. IN PWSTR pwszGroupName
  2541. )
  2542. //////////////////////////////////////////////////////////////////////////////////
  2543. // returns TRUE if group is found in builtin groups, else returns FALSE //
  2544. //////////////////////////////////////////////////////////////////////////////////
  2545. {
  2546. return ScepLookupWellKnownName(
  2547. pwszGroupName,
  2548. NULL, // no Lsa handle available, ScepLookupWellKnownName will open one
  2549. NULL); // don't need the SID, just want to know if it's a known principal
  2550. }