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.

896 lines
25 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. scedll.cpp
  5. Abstract:
  6. SCE Client dll initialization
  7. Author:
  8. Jin Huang (jinhuang) 23-Jan-1998 created
  9. --*/
  10. #include "headers.h"
  11. #include "sceutil.h"
  12. #include <winsafer.h>
  13. #include <winsaferp.h>
  14. #include <objbase.h>
  15. #include <initguid.h>
  16. #include <wbemidl.h>
  17. #include <wbemprov.h>
  18. #include <atlbase.h>
  19. CComModule _Module;
  20. #include <atlcom.h>
  21. extern HINSTANCE MyModuleHandle;
  22. extern CRITICAL_SECTION DiagnosisPolicypropSync;
  23. extern CRITICAL_SECTION PolicyNotificationSync;
  24. extern LIST_ENTRY ScepNotifyList;
  25. BOOL
  26. UninitializeChangeNotify();
  27. #define GPT_SCEDLL_PATH TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions\\SceCli")
  28. #define SCE_REGVALUE_DEFAULT_FILE TEXT("sceregvl.inf")
  29. #define SAM_FILTER_PATH TEXT("System\\CurrentControlSet\\Control\\Lsa")
  30. #define SAM_FILTER_VALUE TEXT("Notification Packages")
  31. DWORD
  32. ScepQuerySamFilterValue(
  33. IN HKEY hKey,
  34. IN BOOL bAdd,
  35. OUT PWSTR *pmszValue,
  36. OUT DWORD *pcbSize,
  37. OUT BOOL *pbChanged
  38. );
  39. VOID
  40. ScepInitClientData(
  41. void
  42. );
  43. VOID
  44. ScepUnInitClientData(
  45. void
  46. );
  47. DWORD
  48. DllpModifySamFilterRegistration(
  49. IN BOOL bAdd
  50. )
  51. {
  52. DWORD lResult;
  53. HKEY hKey=NULL;
  54. if(( lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  55. SAM_FILTER_PATH,
  56. 0,
  57. KEY_READ | KEY_WRITE,
  58. &hKey
  59. )) == ERROR_SUCCESS ) {
  60. DWORD dSize=0;
  61. PWSTR mszValue=NULL;
  62. BOOL bChanged=FALSE;
  63. //
  64. // find out if "scecli" is registered already
  65. //
  66. lResult = ScepQuerySamFilterValue(hKey,
  67. bAdd,
  68. &mszValue,
  69. &dSize,
  70. &bChanged
  71. );
  72. if ( lResult == ERROR_SUCCESS &&
  73. bChanged && mszValue ) {
  74. //
  75. // set the value
  76. //
  77. lResult = RegSetValueEx (
  78. hKey,
  79. SAM_FILTER_VALUE,
  80. 0,
  81. REG_MULTI_SZ,
  82. (BYTE *)mszValue,
  83. dSize
  84. );
  85. }
  86. RegCloseKey(hKey);
  87. }
  88. return lResult;
  89. }
  90. DWORD
  91. ScepQuerySamFilterValue(
  92. IN HKEY hKey,
  93. IN BOOL bAdd,
  94. OUT PWSTR *pmszValue,
  95. OUT DWORD *pcbSize,
  96. OUT BOOL *pbChanged
  97. )
  98. /*
  99. Routine Description:
  100. query the existing notification packages. Add or remove "scecli" to the
  101. packages depending on the flag "bAdd". The packages are in MULTI_SZ
  102. format.
  103. Arguments:
  104. hKey - the base key handle off where the packages are saved
  105. bAdd - if TRUE, add "scecli" to the packages if it's not there
  106. if FALSE, remove "scecli" from the packages
  107. pmszValue - the modified packages value (in MULTI_SZ format)
  108. pcbSize - the size of the packages (in bytes)
  109. pbChanged - TRUE if anything is changed
  110. Return Value:
  111. Win32 error code
  112. */
  113. {
  114. DWORD lResult;
  115. DWORD RegType=REG_MULTI_SZ;
  116. DWORD dSize=0;
  117. PWSTR msz=NULL;
  118. if(( lResult = RegQueryValueEx(hKey,
  119. SAM_FILTER_VALUE,
  120. 0,
  121. &RegType,
  122. NULL,
  123. &dSize
  124. )) == ERROR_SUCCESS ) {
  125. //
  126. // query existing registered packages
  127. //
  128. if ( RegType == REG_MULTI_SZ ) {
  129. msz = (PWSTR)LocalAlloc( LMEM_ZEROINIT, dSize+2*sizeof(TCHAR));
  130. if ( msz ) {
  131. lResult = RegQueryValueEx(hKey,
  132. SAM_FILTER_VALUE,
  133. 0,
  134. &RegType,
  135. (UCHAR *)msz,
  136. &dSize
  137. );
  138. } else {
  139. lResult = ERROR_NOT_ENOUGH_MEMORY;
  140. }
  141. } else {
  142. lResult = ERROR_FILE_NOT_FOUND;
  143. }
  144. }
  145. if ( lResult == ERROR_FILE_NOT_FOUND ||
  146. lResult == ERROR_PATH_NOT_FOUND ) {
  147. //
  148. // if doesn't find the value, ignore the error
  149. //
  150. lResult = ERROR_SUCCESS;
  151. }
  152. *pbChanged = FALSE;
  153. *pcbSize = 0;
  154. *pmszValue = NULL;
  155. if ( lResult == ERROR_SUCCESS &&
  156. msz == NULL &&
  157. bAdd ) {
  158. //
  159. // add scecli to the multi-sz value
  160. // note, since msz is NULL, no need to remove scecli for unregister
  161. //
  162. *pmszValue = (PWSTR)LocalAlloc(0, 16);
  163. if ( *pmszValue ) {
  164. wcscpy(*pmszValue, L"scecli");
  165. (*pmszValue)[6] = L'\0';
  166. (*pmszValue)[7] = L'\0';
  167. *pcbSize = 16;
  168. *pbChanged = TRUE;
  169. } else {
  170. lResult = ERROR_NOT_ENOUGH_MEMORY;
  171. }
  172. }
  173. if ( ERROR_SUCCESS == lResult &&
  174. msz != NULL ) {
  175. //
  176. // there are existing values in the field
  177. //
  178. PWSTR pStart=msz;
  179. DWORD Len=0, Len2;
  180. BOOL bFound = FALSE;
  181. while ( pStart && pStart[0] != L'\0' &&
  182. Len <= dSize/2 ) {
  183. if ( _wcsicmp(pStart, L"scecli") == 0 ) {
  184. bFound = TRUE;
  185. break;
  186. } else {
  187. Len2 = wcslen(pStart)+1;
  188. pStart = pStart + Len2;
  189. Len += Len2;
  190. }
  191. }
  192. //
  193. // add/remove scecli
  194. //
  195. if ( bFound ) {
  196. //
  197. // pStart is pointing to scecli, remove it
  198. //
  199. if ( !bAdd ) {
  200. Len = (DWORD)(pStart - msz);
  201. Len2 = wcslen(pStart);
  202. *pmszValue = (PWSTR)LocalAlloc(LPTR, dSize + 2*sizeof(TCHAR) - (Len2 + 1)*sizeof(TCHAR) );
  203. if ( *pmszValue ) {
  204. memcpy(*pmszValue, msz, Len*sizeof(TCHAR));
  205. memcpy(*pmszValue+Len, pStart+Len2+1, dSize - (Len+Len2+1)*sizeof(TCHAR));
  206. *pcbSize = dSize - (Len2+1)*sizeof(TCHAR);
  207. *pbChanged = TRUE;
  208. } else {
  209. lResult = ERROR_NOT_ENOUGH_MEMORY;
  210. }
  211. }
  212. } else {
  213. //
  214. // not found, add scecli
  215. //
  216. if ( bAdd ) {
  217. *pmszValue = (PWSTR)LocalAlloc(LPTR, dSize + 2*sizeof(TCHAR) + 7*sizeof(TCHAR) );
  218. if ( *pmszValue ) {
  219. memcpy(*pmszValue, msz, dSize);
  220. Len2 = 1;
  221. while ( msz[dSize/2-Len2] == L'\0' ) {
  222. Len2++;
  223. }
  224. wcscpy(*pmszValue+dSize/2-Len2+2, L"scecli");
  225. *pcbSize = dSize + (2-Len2+wcslen(TEXT("scecli"))+2)*sizeof(TCHAR);
  226. *pbChanged = TRUE;
  227. } else {
  228. lResult = ERROR_NOT_ENOUGH_MEMORY;
  229. }
  230. }
  231. }
  232. }
  233. if ( msz ) {
  234. LocalFree(msz);
  235. }
  236. return lResult;
  237. }
  238. /*=============================================================================
  239. ** Procedure Name: DllMain
  240. **
  241. ** Arguments:
  242. **
  243. **
  244. **
  245. ** Returns: 0 = SUCCESS
  246. ** !0 = ERROR
  247. **
  248. ** Abstract:
  249. **
  250. ** Notes:
  251. **
  252. **===========================================================================*/
  253. BOOL WINAPI DllMain(
  254. IN HANDLE DllHandle,
  255. IN ULONG ulReason,
  256. IN LPVOID Reserved )
  257. {
  258. switch(ulReason) {
  259. case DLL_PROCESS_ATTACH:
  260. MyModuleHandle = (HINSTANCE)DllHandle;
  261. (VOID) ScepInitClientData();
  262. //
  263. // initialize dynamic stack allocation
  264. //
  265. SafeAllocaInitialize(SAFEALLOCA_USE_DEFAULT,
  266. SAFEALLOCA_USE_DEFAULT,
  267. NULL,
  268. NULL
  269. );
  270. //
  271. // Fall through to process first thread
  272. //
  273. #if DBG
  274. DebugInitialize();
  275. #endif
  276. case DLL_THREAD_ATTACH:
  277. break;
  278. case DLL_PROCESS_DETACH:
  279. UninitializeChangeNotify();
  280. (VOID) ScepUnInitClientData();
  281. #if DBG
  282. DebugUninit();
  283. #endif
  284. break;
  285. case DLL_THREAD_DETACH:
  286. break;
  287. }
  288. return TRUE;
  289. }
  290. VOID
  291. ScepInitClientData()
  292. /*
  293. Routine Description:
  294. Initialize global data for the client
  295. Arguments:
  296. None
  297. Return Value:
  298. None
  299. */
  300. {
  301. /*
  302. initialize critical section that protects global rsop pointers (namespace, status, logfilename)
  303. by serializing multiple diagnostic modes/policy prop (planning mode uses no globals and is synch)
  304. this is necessary because the asynch thread that calls back the client and needs the above
  305. globals to be preserved (simple thread variables will not do since the asynch thread doesn't know
  306. that it is calling back to the same client thread that it got spawned by)
  307. logic for the acquizition/release of the crit sec is as follows for two cases that arise:
  308. case (a) background thread (no asynch thread spawned)
  309. Exported Policy Function (grab cs) ---> all GPO processing is synch ---> client returns (release cs)
  310. case (b) foreground thread (asynch thread is spawned for slow config areas)
  311. Exported Policy Function (grab cs) ---> try to spawn asynch thread ---> IF asynch thread spawned succ-
  312. essfully it (releases cs) ELSE the synch thread (releases cs)
  313. */
  314. InitializeCriticalSection(&DiagnosisPolicypropSync);
  315. //
  316. // Initialize critical section used by policy notification from LSA/SAM.
  317. // The critical section protects a global counter for the number of
  318. // notifications sent to SCE. If the count is 0, there is no pending
  319. // notification that has not been added to the queue in SCE server;
  320. // otherwise, some notifications have been sent but has not returned yet.
  321. //
  322. // The global count is used to control if policy propagation should be
  323. // allowed.
  324. //
  325. InitializeCriticalSection(&PolicyNotificationSync);
  326. InitializeListHead( &ScepNotifyList );
  327. }
  328. VOID
  329. ScepUnInitClientData()
  330. /*
  331. Routine Description:
  332. Uninitialize global data for the client
  333. Arguments:
  334. None
  335. Return Value:
  336. None
  337. */
  338. {
  339. DeleteCriticalSection(&DiagnosisPolicypropSync);
  340. DeleteCriticalSection(&PolicyNotificationSync);
  341. }
  342. /////////////////////////////////////////////////////////////////////////////
  343. // DllRegisterServer - Adds entries to the system registry
  344. STDAPI DllRegisterServer(void)
  345. {
  346. HKEY hKey;
  347. LONG lResult;
  348. DWORD dwDisp;
  349. FILETIME Time;
  350. DWORD dwMachine;
  351. WCHAR szFile[MAX_PATH + 30];
  352. HRESULT hr;
  353. /* the old interface
  354. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPT_SCEDLL_PATH, 0, NULL,
  355. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  356. &hKey, &dwDisp);
  357. if (lResult != ERROR_SUCCESS)
  358. {
  359. return lResult;
  360. }
  361. RegSetValueEx (hKey, TEXT("ProcessGPO"), 0, REG_SZ, (LPBYTE)TEXT("SceWinlogonConfigureSystem"),
  362. (lstrlen(TEXT("SceWinlogonConfigureSystem")) + 1) * sizeof(TCHAR));
  363. RegSetValueEx (hKey, TEXT("DllName"), 0, REG_EXPAND_SZ, (LPBYTE)TEXT("scecli.dll"),
  364. (lstrlen(TEXT("scecli.dll")) + 1) * sizeof(TCHAR));
  365. */
  366. //
  367. // delete the old interface registration
  368. //
  369. RegDeleteKey ( HKEY_LOCAL_MACHINE, GPT_SCEDLL_PATH );
  370. //
  371. // register the new interface
  372. //
  373. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPT_SCEDLL_NEW_PATH, 0, NULL,
  374. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  375. &hKey, &dwDisp);
  376. if (lResult != ERROR_SUCCESS)
  377. {
  378. return lResult;
  379. }
  380. RegSetValueEx (hKey, TEXT("ProcessGroupPolicy"), 0, REG_SZ, (LPBYTE)TEXT("SceProcessSecurityPolicyGPO"),
  381. (lstrlen(TEXT("SceProcessSecurityPolicyGPO")) + 1) * sizeof(TCHAR));
  382. // RSOP Planning mode API
  383. RegSetValueEx (hKey, TEXT("GenerateGroupPolicy"), 0, REG_SZ, (LPBYTE)TEXT("SceGenerateGroupPolicy"),
  384. (lstrlen(TEXT("SceGenerateGroupPolicy")) + 1) * sizeof(TCHAR));
  385. // RSOP Planning mode logging default (planning.log) -
  386. // turn on logging (ignore any errors)
  387. dwDisp = 1;
  388. RegSetValueEx (hKey, TEXT("ExtensionRsopPlanningDebugLevel"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  389. // RSOP Diagnosis mode API
  390. RegSetValueEx (hKey, TEXT("ProcessGroupPolicyEx"), 0, REG_SZ, (LPBYTE)TEXT("SceProcessSecurityPolicyGPOEx"),
  391. (lstrlen(TEXT("SceProcessSecurityPolicyGPOEx")) + 1) * sizeof(TCHAR));
  392. // RSOP Diagnosis mode or regular Policy Propagation logging default (diagnosis.log and/or winlogon.log)
  393. // turn on logging (ignore any errors)
  394. dwDisp = 1;
  395. RegSetValueEx (hKey, TEXT("ExtensionDebugLevel"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  396. RegSetValueEx (hKey, TEXT("DllName"), 0, REG_EXPAND_SZ, (LPBYTE)TEXT("scecli.dll"),
  397. (lstrlen(TEXT("scecli.dll")) + 1) * sizeof(TCHAR));
  398. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)TEXT("Security"),
  399. (lstrlen(TEXT("Security")) + 1) * sizeof(TCHAR));
  400. RegDeleteValue (hKey, TEXT("<No Name>"));
  401. dwDisp = 1;
  402. RegSetValueEx (hKey, TEXT("NoUserPolicy"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  403. RegSetValueEx (hKey, TEXT("NoGPOListChanges"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  404. RegSetValueEx (hKey, TEXT("EnableAsynchronousProcessing"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  405. dwDisp = 960;
  406. RegSetValueEx (hKey, TEXT("MaxNoGPOListChangesInterval"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  407. RegCloseKey (hKey);
  408. // EFS recovery policy extension
  409. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPT_EFS_NEW_PATH, 0, NULL,
  410. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  411. &hKey, &dwDisp);
  412. if (lResult != ERROR_SUCCESS)
  413. {
  414. return lResult;
  415. }
  416. RegSetValueEx (hKey, TEXT("ProcessGroupPolicy"), 0, REG_SZ, (LPBYTE)TEXT("SceProcessEFSRecoveryGPO"),
  417. (lstrlen(TEXT("SceProcessEFSRecoveryGPO")) + 1) * sizeof(TCHAR));
  418. RegSetValueEx (hKey, TEXT("DllName"), 0, REG_EXPAND_SZ, (LPBYTE)TEXT("scecli.dll"),
  419. (lstrlen(TEXT("scecli.dll")) + 1) * sizeof(TCHAR));
  420. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)TEXT("EFS recovery"),
  421. (lstrlen(TEXT("EFS recovery")) + 1) * sizeof(TCHAR));
  422. RegDeleteValue (hKey, TEXT("<No Name>"));
  423. dwDisp = 1;
  424. RegSetValueEx (hKey, TEXT("NoUserPolicy"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  425. RegSetValueEx (hKey, TEXT("NoGPOListChanges"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  426. RegDeleteValue (hKey, TEXT("RequireSuccessfulRegistry") );
  427. RegSetValueEx (hKey, TEXT("RequiresSuccessfulRegistry"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  428. RegCloseKey (hKey);
  429. #if 0
  430. #error "should not get here"
  431. dwMachine = WhichNTProduct();
  432. //
  433. // Set the default policy only if this is not a server.
  434. //
  435. if (dwMachine == NtProductWinNt)
  436. {
  437. //
  438. // register default SAFER policy to disable executables embedded in Outlook
  439. //
  440. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  441. SAFER_HKLM_REGBASE,
  442. 0,
  443. NULL,
  444. REG_OPTION_NON_VOLATILE,
  445. KEY_WRITE,
  446. NULL,
  447. &hKey,
  448. &dwDisp);
  449. if (lResult != ERROR_SUCCESS)
  450. {
  451. return lResult;
  452. }
  453. RegCloseKey (hKey);
  454. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  455. SAFER_HKLM_REGBASE SAFER_REGKEY_SEPERATOR SAFER_CODEIDS_REGSUBKEY,
  456. 0,
  457. NULL,
  458. REG_OPTION_NON_VOLATILE,
  459. KEY_WRITE,
  460. NULL,
  461. &hKey,
  462. &dwDisp);
  463. if (lResult != ERROR_SUCCESS)
  464. {
  465. return lResult;
  466. }
  467. RegSetValueEx (hKey,
  468. SAFER_EXETYPES_REGVALUE,
  469. 0,
  470. REG_MULTI_SZ,
  471. (LPBYTE)SAFER_DEFAULT_EXECUTABLE_FILE_TYPES,
  472. sizeof(SAFER_DEFAULT_EXECUTABLE_FILE_TYPES));
  473. dwDisp = 0x00000001;
  474. RegSetValueEx (hKey,
  475. SAFER_TRANSPARENTENABLED_REGVALUE,
  476. 0,
  477. REG_DWORD,
  478. (LPBYTE)&dwDisp,
  479. sizeof(DWORD));
  480. dwDisp = 0x00040000;
  481. RegSetValueEx (hKey,
  482. SAFER_DEFAULTOBJ_REGVALUE,
  483. 0,
  484. REG_DWORD,
  485. (LPBYTE)&dwDisp,
  486. sizeof(DWORD));
  487. dwDisp = 0x00000000;
  488. RegSetValueEx (hKey,
  489. SAFER_AUTHENTICODE_REGVALUE,
  490. 0,
  491. REG_DWORD,
  492. (LPBYTE)&dwDisp,
  493. sizeof(DWORD));
  494. dwDisp = 0x00000000;
  495. RegSetValueEx (hKey,
  496. SAFER_POLICY_SCOPE,
  497. 0,
  498. REG_DWORD,
  499. (LPBYTE)&dwDisp,
  500. sizeof(DWORD));
  501. RegCloseKey (hKey);
  502. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  503. SAFER_HKLM_REGBASE SAFER_REGKEY_SEPERATOR SAFER_CODEIDS_REGSUBKEY \
  504. SAFER_REGKEY_SEPERATOR SAFER_LEVEL_ZERO,
  505. 0,
  506. NULL,
  507. REG_OPTION_NON_VOLATILE,
  508. KEY_WRITE,
  509. NULL,
  510. &hKey,
  511. &dwDisp);
  512. if (lResult != ERROR_SUCCESS)
  513. {
  514. return lResult;
  515. }
  516. RegCloseKey (hKey);
  517. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  518. SAFER_HKLM_REGBASE SAFER_REGKEY_SEPERATOR SAFER_CODEIDS_REGSUBKEY \
  519. SAFER_REGKEY_SEPERATOR SAFER_LEVEL_ZERO SAFER_REGKEY_SEPERATOR SAFER_PATHS_REGSUBKEY,
  520. 0,
  521. NULL,
  522. REG_OPTION_NON_VOLATILE,
  523. KEY_WRITE,
  524. NULL,
  525. &hKey,
  526. &dwDisp);
  527. if (lResult != ERROR_SUCCESS)
  528. {
  529. return lResult;
  530. }
  531. RegCloseKey (hKey);
  532. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE,
  533. SAFER_HKLM_REGBASE SAFER_REGKEY_SEPERATOR SAFER_CODEIDS_REGSUBKEY \
  534. SAFER_REGKEY_SEPERATOR SAFER_LEVEL_ZERO SAFER_REGKEY_SEPERATOR \
  535. SAFER_PATHS_REGSUBKEY SAFER_REGKEY_SEPERATOR SAFER_DEFAULT_RULE_GUID,
  536. 0,
  537. NULL,
  538. REG_OPTION_NON_VOLATILE,
  539. KEY_WRITE,
  540. NULL,
  541. &hKey,
  542. &dwDisp);
  543. if (lResult != ERROR_SUCCESS)
  544. {
  545. return lResult;
  546. }
  547. RegSetValueEx (hKey,
  548. SAFER_IDS_DESCRIPTION_REGVALUE,
  549. 0,
  550. REG_SZ,
  551. (LPBYTE)&L"",
  552. sizeof(L""));
  553. dwDisp = 0x00000000;
  554. RegSetValueEx (hKey,
  555. SAFER_IDS_SAFERFLAGS_REGVALUE,
  556. 0,
  557. REG_DWORD,
  558. (LPBYTE)&dwDisp,
  559. sizeof(DWORD));
  560. RegSetValueEx (hKey,
  561. SAFER_IDS_ITEMDATA_REGVALUE,
  562. 0,
  563. REG_EXPAND_SZ,
  564. (LPBYTE)&L"%HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Cache%OLK*",
  565. sizeof(L"%HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Cache%OLK*"));
  566. GetSystemTimeAsFileTime(&Time);
  567. RegSetValueEx (hKey,
  568. SAFER_IDS_LASTMODIFIED_REGVALUE,
  569. 0,
  570. REG_QWORD,
  571. (LPBYTE)&Time,
  572. sizeof(FILETIME));
  573. RegCloseKey (hKey);
  574. }
  575. #endif
  576. //
  577. // turn on default logging for component installs
  578. //
  579. if ( ERROR_SUCCESS == RegCreateKeyEx (HKEY_LOCAL_MACHINE, SCE_ROOT_PATH, 0, NULL,
  580. REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_QUERY_VALUE | KEY_SET_VALUE, NULL,
  581. &hKey, &dwDisp) ) {
  582. dwDisp = 1;
  583. RegSetValueEx (hKey, TEXT("SetupCompDebugLevel"), 0, REG_DWORD, (LPBYTE)&dwDisp, sizeof(DWORD));
  584. //
  585. // create value DefaultTemplate = C:\Windows\Inf\SecRecs.INF
  586. //
  587. DWORD dwType = REG_SZ;
  588. if (ERROR_FILE_NOT_FOUND == RegQueryValueEx(hKey, TEXT("DefaultTemplate"), NULL, &dwType, NULL, NULL) ){
  589. szFile[0] = L'\0';
  590. GetSystemWindowsDirectory(szFile, MAX_PATH);
  591. wcscat(szFile, L"\\inf\\secrecs.inf");
  592. if ((DWORD)-1 != GetFileAttributes( szFile ) ) {
  593. RegSetValueEx (hKey,
  594. TEXT("DefaultTemplate"),
  595. 0,
  596. REG_SZ,
  597. (LPBYTE)szFile,
  598. (wcslen(szFile) + 1) * sizeof(WCHAR));
  599. }
  600. }
  601. RegCloseKey (hKey);
  602. }
  603. //
  604. // compile scersop.mof
  605. //
  606. szFile[0] = L'\0';
  607. if ( GetSystemDirectory( szFile, MAX_PATH ) ) {
  608. LPWSTR sz = szFile + wcslen(szFile);
  609. if ( sz != szFile && *(sz-1) != L'\\') {
  610. *sz++ = L'\\';
  611. *sz = L'\0';
  612. }
  613. wcscat(szFile, L"Wbem\\SceRsop.mof");
  614. if ((DWORD)-1 != GetFileAttributes(szFile)) {
  615. hr = ::CoInitialize (NULL);
  616. if (SUCCEEDED(hr)) {
  617. //
  618. // Get the MOF compiler interface
  619. //
  620. CComPtr<IMofCompiler> srpMof;
  621. hr = ::CoCreateInstance (CLSID_MofCompiler, NULL, CLSCTX_INPROC_SERVER, IID_IMofCompiler, (void **)&srpMof);
  622. if (SUCCEEDED(hr)) {
  623. WBEM_COMPILE_STATUS_INFO stat;
  624. //
  625. // compile RSOP mof
  626. //
  627. hr = srpMof->CompileFile( szFile,
  628. NULL,
  629. NULL,
  630. NULL,
  631. NULL,
  632. 0,
  633. 0,
  634. 0,
  635. &stat
  636. );
  637. }
  638. ::CoUninitialize();
  639. }
  640. }
  641. }
  642. //
  643. // register the default registry values
  644. //
  645. SceRegisterRegValues(SCE_REGVALUE_DEFAULT_FILE);
  646. //
  647. // register SAM policy filter
  648. //
  649. DllpModifySamFilterRegistration(TRUE);
  650. return S_OK;
  651. }
  652. /////////////////////////////////////////////////////////////////////////////
  653. // DllUnregisterServer - Removes entries from the system registry
  654. STDAPI DllUnregisterServer(void)
  655. {
  656. //
  657. // delete old interface
  658. //
  659. RegDeleteKey (HKEY_LOCAL_MACHINE, GPT_SCEDLL_PATH);
  660. //
  661. // delete new interfaces
  662. //
  663. RegDeleteKey (HKEY_LOCAL_MACHINE, GPT_SCEDLL_NEW_PATH);
  664. RegDeleteKey (HKEY_LOCAL_MACHINE, GPT_EFS_NEW_PATH);
  665. DllpModifySamFilterRegistration(FALSE);
  666. return S_OK;
  667. }