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.

767 lines
25 KiB

  1. /*++
  2. Copyright (c) 1994 - 1995 Microsoft Corporation
  3. Module Name:
  4. trueconn.c
  5. Abstract:
  6. This module contains routines for copying drivers from the Server to the
  7. Workstation for Point and Print or "True Connections."
  8. Author:
  9. Krishna Ganugapati (Krishna Ganugapati) 21-Apr-1994
  10. Revision History:
  11. 21-Apr-1994 - Created.
  12. 21-Apr-1994 - There are actually two code modules in this file. Both deal
  13. with true connections
  14. 27-Oct-1994 - Matthew Felton (mattfe) rewrite updatefile routine to allow
  15. non power users to point and print, for caching. Removed
  16. old Caching code.
  17. 23-Feb-1995 - Matthew Felton (mattfe) removed more code by allowing spladdprinterdriver
  18. to do all file copying.
  19. 24-Mar-1999 - Felix Maxa (AMaxa) AddPrinterDriver key must be read from the old location
  20. of the Servers key in System hive
  21. 19-Oct-2000 - Steve Kiraly (SteveKi) Read the AddPrinterDrivers key every time, group
  22. policy modifies this key while the spooler is running, we don't want require
  23. the customer to restart the spooler when this policy changes.
  24. --*/
  25. #include "precomp.h"
  26. DWORD dwLoadTrustedDrivers = 0;
  27. WCHAR TrustedDriverPath[MAX_PATH];
  28. DWORD dwSyncOpenPrinter = 0;
  29. BOOL
  30. ReadImpersonateOnCreate(
  31. VOID
  32. )
  33. {
  34. BOOL bImpersonateOnCreate = FALSE;
  35. HKEY hKey = NULL;
  36. NT_PRODUCT_TYPE NtProductType = {0};
  37. DWORD dwRetval = ERROR_SUCCESS;
  38. DWORD cbData = sizeof(bImpersonateOnCreate);
  39. DWORD dwType = REG_DWORD;
  40. //
  41. // Open the providers registry key
  42. //
  43. dwRetval = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  44. szOldLocationOfServersKey,
  45. 0,
  46. KEY_READ, &hKey);
  47. if (dwRetval == ERROR_SUCCESS)
  48. {
  49. //
  50. // Attempt to read the AddPrinterDrivers policy.
  51. //
  52. dwRetval = RegQueryValueEx(hKey,
  53. L"AddPrinterDrivers",
  54. NULL,
  55. &dwType,
  56. (LPBYTE)&bImpersonateOnCreate,
  57. &cbData);
  58. }
  59. //
  60. // If we did not read the AddPrinterDrivers policy then set the default
  61. // based on the product type.
  62. //
  63. if (dwRetval != ERROR_SUCCESS)
  64. {
  65. bImpersonateOnCreate = FALSE;
  66. // Server Default Always Impersonate on AddPrinterConnection
  67. // WorkStation Default Do Not Impersonate on AddPrinterConnection
  68. if (RtlGetNtProductType(&NtProductType))
  69. {
  70. if (NtProductType != NtProductWinNt)
  71. {
  72. bImpersonateOnCreate = TRUE;
  73. }
  74. }
  75. }
  76. if (hKey)
  77. {
  78. RegCloseKey(hKey);
  79. }
  80. return bImpersonateOnCreate;
  81. }
  82. BOOL
  83. CopyDriversLocally(
  84. PWSPOOL pSpool,
  85. LPWSTR pEnvironment,
  86. LPBYTE pDriverInfo,
  87. DWORD dwLevel,
  88. DWORD cbDriverInfo,
  89. LPDWORD pcbNeeded)
  90. {
  91. DWORD ReturnValue=FALSE;
  92. DWORD RpcError;
  93. DWORD dwServerMajorVersion = 0;
  94. DWORD dwServerMinorVersion = 0;
  95. BOOL DaytonaServer = TRUE;
  96. BOOL bReturn = FALSE;
  97. if (pSpool->Type != SJ_WIN32HANDLE) {
  98. SetLastError(ERROR_INVALID_HANDLE);
  99. return(FALSE);
  100. }
  101. //
  102. // Test RPC call to determine if we're talking to Daytona or Product 1
  103. //
  104. SYNCRPCHANDLE( pSpool );
  105. RpcTryExcept {
  106. ReturnValue = RpcGetPrinterDriver2(pSpool->RpcHandle,
  107. pEnvironment, dwLevel,
  108. pDriverInfo,
  109. cbDriverInfo,
  110. pcbNeeded,
  111. cThisMajorVersion,
  112. cThisMinorVersion,
  113. &dwServerMajorVersion,
  114. &dwServerMinorVersion);
  115. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  116. RpcError = RpcExceptionCode();
  117. ReturnValue = RpcError;
  118. if (RpcError == RPC_S_PROCNUM_OUT_OF_RANGE) {
  119. //
  120. // Product 1 server
  121. //
  122. DaytonaServer = FALSE;
  123. }
  124. } RpcEndExcept
  125. if ( DaytonaServer ) {
  126. if (ReturnValue) {
  127. SetLastError(ReturnValue);
  128. goto FreeDone;
  129. }
  130. } else {
  131. RpcTryExcept {
  132. //
  133. // I am talking to a Product 1.0/511/528
  134. //
  135. ReturnValue = RpcGetPrinterDriver( pSpool->RpcHandle,
  136. pEnvironment,
  137. dwLevel,
  138. pDriverInfo,
  139. cbDriverInfo,
  140. pcbNeeded );
  141. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  142. RpcError = RpcExceptionCode();
  143. } RpcEndExcept
  144. if (ReturnValue) {
  145. SetLastError(ReturnValue);
  146. goto FreeDone;
  147. }
  148. }
  149. switch (dwLevel) {
  150. case 2:
  151. bReturn = MarshallUpStructure(pDriverInfo, DriverInfo2Fields, sizeof(DRIVER_INFO_2), RPC_CALL);
  152. break;
  153. case 3:
  154. bReturn = MarshallUpStructure(pDriverInfo, DriverInfo3Fields, sizeof(DRIVER_INFO_3), RPC_CALL);
  155. break;
  156. case 4:
  157. bReturn = MarshallUpStructure(pDriverInfo, DriverInfo4Fields, sizeof(DRIVER_INFO_4), RPC_CALL);
  158. break;
  159. case 6:
  160. bReturn = MarshallUpStructure(pDriverInfo, DriverInfo6Fields, sizeof(DRIVER_INFO_6), RPC_CALL);
  161. break;
  162. case DRIVER_INFO_VERSION_LEVEL:
  163. bReturn = MarshallUpStructure(pDriverInfo, DriverInfoVersionFields, sizeof(DRIVER_INFO_VERSION), RPC_CALL);
  164. break;
  165. default:
  166. DBGMSG(DBG_ERROR,
  167. ("CopyDriversLocally: Invalid level %d", dwLevel));
  168. SetLastError(ERROR_INVALID_LEVEL);
  169. bReturn = FALSE;
  170. goto FreeDone;
  171. }
  172. if (bReturn)
  173. {
  174. bReturn = DownloadDriverFiles(pSpool, pDriverInfo, dwLevel);
  175. }
  176. FreeDone:
  177. return bReturn;
  178. }
  179. BOOL
  180. ConvertDependentFilesToTrustedPath(
  181. LPWSTR *pNewDependentFiles,
  182. LPWSTR pOldDependentFiles,
  183. DWORD dwVersion)
  184. {
  185. //
  186. // Assuming version is single digit
  187. // we need space for \ and the version digit
  188. //
  189. DWORD dwVersionPathLen = wcslen(TrustedDriverPath) + 2;
  190. DWORD dwFilenameLen, cchSize;
  191. LPWSTR pStr1, pStr2, pStr3;
  192. if ( !pOldDependentFiles || !*pOldDependentFiles ) {
  193. *pNewDependentFiles = NULL;
  194. return TRUE;
  195. }
  196. pStr1 = pOldDependentFiles;
  197. cchSize = 0;
  198. while ( *pStr1 ) {
  199. pStr2 = wcsrchr( pStr1, L'\\' );
  200. dwFilenameLen = wcslen(pStr2) + 1;
  201. cchSize += dwVersionPathLen + dwFilenameLen;
  202. pStr1 = pStr2 + dwFilenameLen;
  203. }
  204. // For the last \0
  205. ++cchSize;
  206. *pNewDependentFiles = AllocSplMem(cchSize*sizeof(WCHAR));
  207. if ( !*pNewDependentFiles ) {
  208. return FALSE;
  209. }
  210. pStr1 = pOldDependentFiles;
  211. pStr3 = *pNewDependentFiles;
  212. while ( *pStr1 ) {
  213. pStr2 = wcsrchr( pStr1, L'\\' );
  214. dwFilenameLen = wcslen(pStr2) + 1;
  215. StringCchPrintf( pStr3, cchSize, L"%ws\\%d%ws", TrustedDriverPath, dwVersion, pStr2 );
  216. pStr1 = pStr2 + dwFilenameLen;
  217. pStr3 += dwVersionPathLen + dwFilenameLen;
  218. cchSize -= dwVersionPathLen + dwFilenameLen;
  219. }
  220. *pStr3 = '\0';
  221. return TRUE;
  222. }
  223. LPWSTR
  224. ConvertToTrustedPath(
  225. PWCHAR pScratchBuffer,
  226. DWORD cchScratchBuffer,
  227. LPWSTR pDriverPath,
  228. DWORD cVersion
  229. )
  230. {
  231. PWSTR pData;
  232. SPLASSERT( pScratchBuffer != NULL && pDriverPath != NULL );
  233. pData = wcsrchr( pDriverPath, L'\\' );
  234. StringCchPrintf( pScratchBuffer, cchScratchBuffer, L"%ws\\%d%ws", TrustedDriverPath, cVersion, pData );
  235. return ( AllocSplStr( pScratchBuffer ) );
  236. }
  237. //
  238. // GetPolicy()
  239. //
  240. // We are hard coding the policy to try the server first and then
  241. // to try the inf install if this installation failed.
  242. //
  243. // This function may be used in the future to leverage different policies.
  244. //
  245. DWORD
  246. GetPolicy()
  247. {
  248. return (SERVER_INF_INSTALL);
  249. }
  250. //
  251. // If there is a language monitor associated with the driver and it is
  252. // not installed on this machine NULL the pMonitorName field.
  253. // We do not want to download the monitor from thr server since there
  254. // is no version associated with them
  255. //
  256. BOOL
  257. NullMonitorName (
  258. LPBYTE pDriverInfo,
  259. DWORD dwLevel
  260. )
  261. {
  262. LPWSTR *ppMonitorName = NULL;
  263. BOOL bReturn = FALSE;
  264. switch (dwLevel) {
  265. case 3:
  266. case 4:
  267. case 6:
  268. {
  269. ppMonitorName = &((LPDRIVER_INFO_6)pDriverInfo)->pMonitorName;
  270. break;
  271. }
  272. case DRIVER_INFO_VERSION_LEVEL:
  273. {
  274. ppMonitorName = &((LPDRIVER_INFO_VERSION)pDriverInfo)->pMonitorName;
  275. break;
  276. }
  277. default:
  278. {
  279. break;
  280. }
  281. }
  282. if (ppMonitorName && *ppMonitorName && **ppMonitorName &&
  283. !SplMonitorIsInstalled(*ppMonitorName))
  284. {
  285. *ppMonitorName = NULL;
  286. bReturn = TRUE;
  287. }
  288. return bReturn;
  289. }
  290. BOOL
  291. DownloadDriverFiles(
  292. PWSPOOL pSpool,
  293. LPBYTE pDriverInfo,
  294. DWORD dwLevel
  295. )
  296. {
  297. PWCHAR pScratchBuffer = NULL;
  298. BOOL bReturnValue = FALSE;
  299. LPBYTE pTempDriverInfo = NULL;
  300. DWORD dwVersion;
  301. DWORD dwInstallPolicy = GetPolicy();
  302. LPDRIVER_INFO_6 pTempDriverInfo6, pDriverInfo6;
  303. //
  304. // If there is a language monitor associated with the driver and it is
  305. // not installed on this machine NULL the pMonitorName field.
  306. // We do not want to pull down the monitor since there is no version
  307. // associated with them
  308. //
  309. NullMonitorName(pDriverInfo, dwLevel);
  310. //
  311. // If LoadTrustedDrivers is FALSE
  312. // then we don't care, we load the files from
  313. // server itself because he has the files
  314. //
  315. if ( !IsTrustedPathConfigured() ) {
  316. //
  317. // At this point dwInstallPolicy will always be SERVER_INF_INSTALL
  318. // as this is hardcoded in the GetPolicy() call.
  319. // This will always be executed in the current GetPolicy() implementation.
  320. //
  321. // If this is only a server install or we're doing a server install first.
  322. //
  323. if( dwInstallPolicy & SERVER_INSTALL_ONLY || dwInstallPolicy & SERVER_INF_INSTALL )
  324. {
  325. //
  326. // SplAddPrinterDriverEx will do the copying of the Driver files if the
  327. // date and time are newer than the drivers it already has
  328. //
  329. bReturnValue = SplAddPrinterDriverEx( NULL,
  330. dwLevel,
  331. pDriverInfo,
  332. APD_COPY_NEW_FILES | APD_INSTALL_WARNED_DRIVER | APD_RETURN_BLOCKING_STATUS_CODE | APD_DONT_SET_CHECKPOINT,
  333. pSpool->hIniSpooler,
  334. DO_NOT_USE_SCRATCH_DIR,
  335. ReadImpersonateOnCreate() );
  336. }
  337. //
  338. // dwInstallPolicy will be SERVER_INF_INSTALL at this point due to the
  339. // current implementation of GetPolicy(). The below code will only be
  340. // executed if the SplAddPrinterDriverEx calls above failed.
  341. //
  342. // Do this only if we haven't tried a previous install or the previous attempt failed.
  343. // Policy: If this is an INF install only,
  344. // or we're doing and INF install first,
  345. // or the INF install is happening after the server install.
  346. //
  347. if( !bReturnValue && (ERROR_PRINTER_DRIVER_BLOCKED != GetLastError()) && !(dwInstallPolicy & SERVER_INSTALL_ONLY) )
  348. {
  349. LPDRIVER_INFO_2 pDriverInfo2 = (LPDRIVER_INFO_2)pDriverInfo;
  350. LPDRIVER_INFO_1 pDriverInfo1 = (LPDRIVER_INFO_1)pDriverInfo;
  351. //
  352. // Assume if info2 is valid, info1 is too.
  353. //
  354. if( pDriverInfo2 ) {
  355. //
  356. // Paranoid code. We should never receive a call with a level
  357. // one, but if we did, the driver info struct for level 1 is
  358. // different to that in a level 2, so we could AV if we don't
  359. // do this.
  360. //
  361. bReturnValue = AddDriverFromLocalCab( dwLevel == 1 ? pDriverInfo1->pName : pDriverInfo2->pName,
  362. pSpool->hIniSpooler );
  363. }
  364. else if( dwInstallPolicy & INF_INSTALL_ONLY )
  365. {
  366. //
  367. // If this isn't an inf only install, then we should not overwrite the
  368. // last error that will occur with AddPrinterDriver calls.
  369. // If this is an inf install only, pDriverInfo2 was NULL
  370. // so we need to set some last error for this install.
  371. //
  372. SetLastError( ERROR_INVALID_PARAMETER );
  373. }
  374. }
  375. //
  376. // Due to the current implemenation of GetPolicy() the below section
  377. // of code will never be executed. If the GetPolicy() call changes from
  378. // being hardcoded into something actually policy driven, then could be used.
  379. //
  380. // If the inf install is followed by a server install.
  381. // Do this only if the previous install has failed.
  382. //
  383. if( !bReturnValue && dwInstallPolicy & INF_SERVER_INSTALL )
  384. {
  385. //
  386. // SplAddPrinterDriverEx will do the copying of the Driver files if the
  387. // date and time are newer than the drivers it already has
  388. //
  389. bReturnValue = SplAddPrinterDriverEx( NULL,
  390. dwLevel,
  391. pDriverInfo,
  392. APD_COPY_NEW_FILES | APD_INSTALL_WARNED_DRIVER | APD_RETURN_BLOCKING_STATUS_CODE | APD_DONT_SET_CHECKPOINT,
  393. pSpool->hIniSpooler,
  394. DO_NOT_USE_SCRATCH_DIR,
  395. ReadImpersonateOnCreate() );
  396. }
  397. return bReturnValue;
  398. }
  399. //
  400. // check if we have a valid path to retrieve the files from
  401. //
  402. if ( !TrustedDriverPath || !*TrustedDriverPath ) {
  403. DBGMSG( DBG_WARNING, ( "DownloadDriverFiles Bad Trusted Driver Path\n" ));
  404. SetLastError( ERROR_FILE_NOT_FOUND );
  405. return(FALSE);
  406. }
  407. DBGMSG( DBG_TRACE, ( "Retrieving Files from Trusted Driver Path\n" ) );
  408. DBGMSG( DBG_TRACE, ( "Trusted Driver Path is %ws\n", TrustedDriverPath ) );
  409. //
  410. // In the code below the if statement we make the assumption that the caller
  411. // passed in a pointer to a DRIVER_INFO_6 structure or to a DRIVER_INFO_6
  412. // compatible structure, we need to check the level
  413. //
  414. if (dwLevel == DRIVER_INFO_VERSION_LEVEL)
  415. {
  416. SetLastError(ERROR_INVALID_LEVEL);
  417. return FALSE;
  418. }
  419. try {
  420. pScratchBuffer = AllocSplMem( MAX_PATH );
  421. if ( pScratchBuffer == NULL )
  422. leave;
  423. pDriverInfo6 = (LPDRIVER_INFO_6) pDriverInfo;
  424. pTempDriverInfo = AllocSplMem(sizeof(DRIVER_INFO_6));
  425. if ( pTempDriverInfo == NULL )
  426. leave;
  427. pTempDriverInfo6 = (LPDRIVER_INFO_6) pTempDriverInfo;
  428. pTempDriverInfo6->cVersion = pDriverInfo6->cVersion;
  429. pTempDriverInfo6->pName = pDriverInfo6->pName;
  430. pTempDriverInfo6->pEnvironment = pDriverInfo6->pEnvironment;
  431. pTempDriverInfo6->pDriverPath = ConvertToTrustedPath(pScratchBuffer,
  432. MAX_PATH,
  433. pDriverInfo6->pDriverPath,
  434. pDriverInfo6->cVersion);
  435. pTempDriverInfo6->pConfigFile = ConvertToTrustedPath(pScratchBuffer,
  436. MAX_PATH,
  437. pDriverInfo6->pConfigFile,
  438. pDriverInfo6->cVersion);
  439. pTempDriverInfo6->pDataFile = ConvertToTrustedPath(pScratchBuffer,
  440. MAX_PATH,
  441. pDriverInfo6->pDataFile,
  442. pDriverInfo6->cVersion);
  443. if ( pTempDriverInfo6->pDataFile == NULL ||
  444. pTempDriverInfo6->pDriverPath == NULL ||
  445. pTempDriverInfo6->pConfigFile == NULL ) {
  446. leave;
  447. }
  448. if ( dwLevel == 2 )
  449. goto Call;
  450. pTempDriverInfo6->pMonitorName = pDriverInfo6->pMonitorName;
  451. pTempDriverInfo6->pDefaultDataType = pDriverInfo6->pDefaultDataType;
  452. if ( pDriverInfo6->pHelpFile && *pDriverInfo6->pHelpFile ) {
  453. pTempDriverInfo6->pHelpFile = ConvertToTrustedPath(pScratchBuffer,
  454. MAX_PATH,
  455. pDriverInfo6->pHelpFile,
  456. pDriverInfo6->cVersion);
  457. if ( !pTempDriverInfo6->pHelpFile )
  458. leave;
  459. }
  460. if ( !ConvertDependentFilesToTrustedPath(&pTempDriverInfo6->pDependentFiles,
  461. pDriverInfo6->pDependentFiles,
  462. pDriverInfo6->cVersion) )
  463. leave;
  464. if ( dwLevel == 3 )
  465. goto Call;
  466. SPLASSERT(dwLevel == 4 || dwLevel == 6);
  467. pTempDriverInfo6->pszzPreviousNames = pDriverInfo6->pszzPreviousNames;
  468. Call:
  469. //
  470. // At this point dwInstallPolicy will always be SERVER_INF_INSTALL
  471. // as this is hardcoded in the GetPolicy() call.
  472. // This will always be executed in the current GetPolicy() implementation
  473. //
  474. // If this is only a server install or we're doing a server install first.
  475. //
  476. if( dwInstallPolicy & SERVER_INSTALL_ONLY || dwInstallPolicy & SERVER_INF_INSTALL )
  477. {
  478. //
  479. // SplAddPrinterDriverEx will do the copying of the Driver files if the
  480. // date and time are newer than the drivers it already has
  481. //
  482. bReturnValue = SplAddPrinterDriverEx( NULL,
  483. dwLevel,
  484. pTempDriverInfo,
  485. APD_COPY_NEW_FILES | APD_INSTALL_WARNED_DRIVER | APD_RETURN_BLOCKING_STATUS_CODE | APD_DONT_SET_CHECKPOINT,
  486. pSpool->hIniSpooler,
  487. DO_NOT_USE_SCRATCH_DIR,
  488. ReadImpersonateOnCreate() );
  489. }
  490. //
  491. // dwInstallPolicy will be SERVER_INF_INSTALL at this point due to the
  492. // current implementation of GetPolicy(). The below code will only be
  493. // executed if the SplAddPrinterDriverEx calls above failed.
  494. //
  495. // Do this only if we haven't tried a previous install or the previous attempt failed.
  496. // Policy: If this is an INF install only,
  497. // or we're doing and INF install first,
  498. // or the INF install is happening after the server install.
  499. //
  500. if( !bReturnValue && (ERROR_PRINTER_DRIVER_BLOCKED != GetLastError()) && !(dwInstallPolicy & SERVER_INSTALL_ONLY) ) {
  501. LPDRIVER_INFO_2 pDriverInfo2 = (LPDRIVER_INFO_2)pDriverInfo;
  502. LPDRIVER_INFO_1 pDriverInfo1 = (LPDRIVER_INFO_1)pDriverInfo;
  503. //
  504. // Set up the info structures first... (assume if info2 is valid, info1 is too)
  505. //
  506. if( pDriverInfo2 ) {
  507. //
  508. // Paranoid code. We should never receive a call with a level
  509. // one, but if we did, the driver info struct for level 1 is
  510. // different to that in a level 2, so we could AV if we don't
  511. // treat them differently.
  512. //
  513. bReturnValue = AddDriverFromLocalCab( dwLevel == 1 ? pDriverInfo1->pName : pDriverInfo2->pName,
  514. pSpool->hIniSpooler );
  515. }
  516. else if( dwInstallPolicy & INF_INSTALL_ONLY ) {
  517. //
  518. // If this isn't an inf only install, then we should not overwrite the
  519. // last error that will occur with AddPrinterDriver calls.
  520. // If this install was only an inf install, pDriverInfo2 was NULL
  521. // so we need to set some last error for this install.
  522. //
  523. SetLastError( ERROR_INVALID_PARAMETER );
  524. }
  525. }
  526. //
  527. // Due to the current implemenation of GetPolicy() the below section
  528. // of code will never be executed. If the GetPolicy() call changes from
  529. // being hardcoded into something actually policy driven, then could be used.
  530. //
  531. // If the inf install is followed by a server install.
  532. // Do this only if the previous install has failed.
  533. //
  534. if( !bReturnValue && dwInstallPolicy & INF_SERVER_INSTALL )
  535. {
  536. //
  537. // SplAddPrinterDriverEx will do the copying of the Driver files if the
  538. // date and time are newer than the drivers it already has
  539. //
  540. bReturnValue = SplAddPrinterDriverEx( NULL,
  541. dwLevel,
  542. pTempDriverInfo,
  543. APD_COPY_NEW_FILES | APD_INSTALL_WARNED_DRIVER | APD_RETURN_BLOCKING_STATUS_CODE | APD_DONT_SET_CHECKPOINT,
  544. pSpool->hIniSpooler,
  545. DO_NOT_USE_SCRATCH_DIR,
  546. ReadImpersonateOnCreate() );
  547. }
  548. } finally {
  549. FreeSplMem( pScratchBuffer );
  550. if ( pTempDriverInfo != NULL ) {
  551. FreeSplStr(pTempDriverInfo6->pDriverPath);
  552. FreeSplStr(pTempDriverInfo6->pConfigFile);
  553. FreeSplStr(pTempDriverInfo6->pDataFile);
  554. FreeSplStr(pTempDriverInfo6->pDependentFiles);
  555. FreeSplMem(pTempDriverInfo);
  556. }
  557. }
  558. return bReturnValue;
  559. }
  560. VOID
  561. QueryTrustedDriverInformation(
  562. VOID
  563. )
  564. {
  565. DWORD dwRet;
  566. DWORD cbData;
  567. DWORD dwType = 0;
  568. HKEY hKey;
  569. //
  570. // There was a migration of printer connections cache from System
  571. // to sftware. The Servers key and the AddPrinterDrivers values
  572. // remain at the old location, though.
  573. //
  574. dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szOldLocationOfServersKey,
  575. 0, KEY_READ, &hKey);
  576. if (dwRet != ERROR_SUCCESS) {
  577. return;
  578. }
  579. cbData = sizeof(DWORD);
  580. dwRet = RegQueryValueEx(hKey, L"LoadTrustedDrivers", NULL, &dwType, (LPBYTE)&dwLoadTrustedDrivers, &cbData);
  581. if (dwRet != ERROR_SUCCESS) {
  582. dwLoadTrustedDrivers = 0;
  583. }
  584. //
  585. // By Default we don't wait for the RemoteOpenPrinter to succeed if we have a cache ( Connection )
  586. // Users might want to have Syncronous opens
  587. //
  588. cbData = sizeof(DWORD);
  589. dwRet = RegQueryValueEx(hKey, L"SyncOpenPrinter", NULL, &dwType, (LPBYTE)&dwSyncOpenPrinter, &cbData);
  590. if (dwRet != ERROR_SUCCESS) {
  591. dwSyncOpenPrinter = 0;
  592. }
  593. //
  594. // if !dwLoadedTrustedDrivers then just return
  595. // we won't be using the driver path at all
  596. //
  597. if (!dwLoadTrustedDrivers) {
  598. DBGMSG(DBG_TRACE, ("dwLoadTrustedDrivers is %d\n", dwLoadTrustedDrivers));
  599. RegCloseKey(hKey);
  600. return;
  601. }
  602. cbData = sizeof(TrustedDriverPath);
  603. dwRet = RegQueryValueEx(hKey, L"TrustedDriverPath", NULL, &dwType, (LPBYTE)TrustedDriverPath, &cbData);
  604. if (dwRet != ERROR_SUCCESS) {
  605. dwLoadTrustedDrivers = 0;
  606. DBGMSG(DBG_TRACE, ("dwLoadTrustedDrivers is %d\n", dwLoadTrustedDrivers));
  607. RegCloseKey(hKey);
  608. return;
  609. }
  610. DBGMSG(DBG_TRACE, ("dwLoadTrustedDrivers is %d\n", dwLoadTrustedDrivers));
  611. DBGMSG(DBG_TRACE, ("TrustedPath is %ws\n", TrustedDriverPath));
  612. RegCloseKey(hKey);
  613. return;
  614. }
  615. BOOL
  616. IsTrustedPathConfigured(
  617. IN VOID
  618. )
  619. {
  620. return !!dwLoadTrustedDrivers;
  621. }