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

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