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.

914 lines
24 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. This is the main entry point for the service control manager for the web
  7. dav mini-redir service.
  8. Author:
  9. Rohan Kumar [RohanK] 08-Feb-2000
  10. Environment:
  11. User Mode - Win32
  12. Revision History:
  13. --*/
  14. #include "pch.h"
  15. #pragma hdrstop
  16. #include <ntumrefl.h>
  17. #include <usrmddav.h>
  18. #include <svcs.h>
  19. //
  20. // Allocate global data in this file.
  21. //
  22. #define GLOBAL_DATA_ALLOCATE
  23. #include "global.h"
  24. DWORD DavStop = 0;
  25. //
  26. // The amount of time in seconds a server entry is cached in the ServerNotFound
  27. // cache.
  28. //
  29. ULONG ServerNotFoundCacheLifeTimeInSec = 0;
  30. //
  31. // Should we accept/claim the OfficeWebServers and TahoeWebServers?
  32. //
  33. ULONG AcceptOfficeAndTahoeServers = 0;
  34. //
  35. // Should we LOCK (using the DAV LOCK Verb) the file on the server on the
  36. // CreateFile path when needed? To know when exactly a LOCK is sent to the
  37. // server, look at the (LOCKing) comments in the davcreat.c file.
  38. //
  39. ULONG DavSupportLockingOfFiles = 1;
  40. PSVCHOST_GLOBAL_DATA DavSvcsGlobalData;
  41. DWORD
  42. DavNotRunningAsAService(
  43. VOID
  44. );
  45. DWORD
  46. WINAPI
  47. DavFakeServiceController(
  48. LPVOID Parameter
  49. );
  50. BOOL
  51. DavCheckLUIDDeviceMapsEnabled(
  52. VOID
  53. );
  54. VOID
  55. DavReadRegistryValues(
  56. VOID
  57. );
  58. VOID
  59. WINAPI
  60. DavServiceHandler (
  61. DWORD dwOpcode
  62. )
  63. /*++
  64. Routine Description:
  65. This function is called by the Service Controller at various times when the
  66. service is running.
  67. Arguments:
  68. dwOpcode - Reason for calling the service handler.
  69. Return Value:
  70. none.
  71. --*/
  72. {
  73. DWORD err;
  74. switch (dwOpcode) {
  75. case SERVICE_CONTROL_SHUTDOWN:
  76. //
  77. // Lack of break is intentional!
  78. //
  79. case SERVICE_CONTROL_STOP:
  80. DavPrint((DEBUG_INIT, "DavServiceHandler: WebClient service is stopping.\n"));
  81. UpdateServiceStatus(SERVICE_STOP_PENDING);
  82. if (g_WorkersActive) {
  83. err = DavTerminateWorkerThreads();
  84. if (err != ERROR_SUCCESS) {
  85. DavPrint((DEBUG_ERRORS,
  86. "DavServiceMain/DavTerminateWorkerThreads: "
  87. "Error Val = %u.\n", err));
  88. }
  89. g_WorkersActive = FALSE;
  90. }
  91. if (g_RpcActive) {
  92. DavSvcsGlobalData->StopRpcServer(davclntrpc_ServerIfHandle);
  93. g_RpcActive = FALSE;
  94. }
  95. //
  96. // Close and free up the DAV stuff.
  97. //
  98. DavClose();
  99. if (g_socketinit) {
  100. err = CleanupTheSocketInterface();
  101. if (err != ERROR_SUCCESS) {
  102. DavPrint((DEBUG_ERRORS,
  103. "DavServiceMain/CleanupTheSocketInterface: "
  104. "Error Val = %u.\n", err));
  105. }
  106. g_socketinit = FALSE;
  107. }
  108. if (DavReflectorHandle != NULL) {
  109. err = UMReflectorStop(DavReflectorHandle);
  110. if (err != ERROR_SUCCESS) {
  111. DavPrint((DEBUG_ERRORS,
  112. "DavServiceMain/UMReflectorStop: Error Val = %u.\n", err));
  113. }
  114. err = UMReflectorUnregister(DavReflectorHandle);
  115. if (err != ERROR_SUCCESS) {
  116. DavPrint((DEBUG_ERRORS,
  117. "DavServiceMain/UMReflectorUnregister: Error Val = 0x%x.\n", err));
  118. }
  119. DavReflectorHandle = NULL;
  120. }
  121. if (g_RedirLoaded) {
  122. err = WsUnloadRedir();
  123. if (err != ERROR_SUCCESS) {
  124. DavPrint((DEBUG_ERRORS,
  125. "DavServiceMain/WsUnloadRedir: Error Val = %u.\n", err));
  126. }
  127. g_RedirLoaded = FALSE;
  128. }
  129. if (g_DavServiceLockSet) {
  130. DeleteCriticalSection ( &(g_DavServiceLock) );
  131. g_DavServiceLockSet = FALSE;
  132. }
  133. DavPrint((DEBUG_INIT, "DavServiceMain: WebClient service is stopped.\n"));
  134. UpdateServiceStatus(SERVICE_STOPPED);
  135. #if DBG
  136. DebugUninitialize();
  137. #endif
  138. break;
  139. case SERVICE_CONTROL_INTERROGATE:
  140. //
  141. // Refresh our status to the SCM.
  142. //
  143. SetServiceStatus(g_hStatus, &g_status);
  144. break;
  145. default:
  146. //
  147. // This may not be needed, but refresh our status to the service
  148. // controller.
  149. //
  150. DavPrint((DEBUG_INIT, "DavServiceHandler: WebClient service received SCM "
  151. "Opcode = %08lx\n", dwOpcode));
  152. ASSERT (g_hStatus);
  153. SetServiceStatus (g_hStatus, &g_status);
  154. break;
  155. }
  156. return;
  157. }
  158. VOID
  159. SvchostPushServiceGlobals(
  160. PSVCHOST_GLOBAL_DATA pGlobals
  161. )
  162. {
  163. DavSvcsGlobalData = pGlobals;
  164. }
  165. VOID
  166. WINAPI
  167. ServiceMain (
  168. DWORD dwNumServicesArgs,
  169. LPWSTR *lpServiceArgVectors
  170. )
  171. /*++
  172. Routine Description:
  173. This function is called by the Service Control Manager when starting this
  174. service.
  175. Arguments:
  176. dwNumServicesArgs - Number of arguments.
  177. lpServiceArgVectors - Array of arguments.
  178. Return Value:
  179. None.
  180. --*/
  181. {
  182. DWORD err = ERROR_SUCCESS;
  183. DWORD exitErr = ERROR_SUCCESS;
  184. HKEY KeyHandle = NULL;
  185. ULONG maxThreads = 0, initialThreads = 0, RedirRegisterCount = 0;
  186. BOOL RunningAsAService = TRUE;
  187. #if DBG
  188. DebugInitialize();
  189. #endif
  190. DavReadRegistryValues();
  191. //
  192. // Make sure svchost.exe gave us the global data
  193. //
  194. ASSERT(DavSvcsGlobalData != NULL);
  195. #if DBG
  196. {
  197. DWORD cbP = 0;
  198. WCHAR m_szProfilePath[MAX_PATH];
  199. cbP = GetEnvironmentVariable(L"USERPROFILE", m_szProfilePath, MAX_PATH);
  200. m_szProfilePath[cbP] = L'\0';
  201. DavPrint((DEBUG_MISC, "DavServiceMain: USERPROFILE: %ws\n", m_szProfilePath));
  202. }
  203. #endif
  204. g_RedirLoaded = FALSE;
  205. g_WorkersActive = FALSE;
  206. g_registeredService = FALSE;
  207. //
  208. // Initialize the SERVICE_STATUS structure g_status.
  209. //
  210. ZeroMemory (&g_status, sizeof(g_status));
  211. g_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
  212. g_status.dwControlsAccepted = (SERVICE_ACCEPT_STOP | SERVICE_CONTROL_SHUTDOWN);
  213. g_status.dwCheckPoint = 1;
  214. g_status.dwWaitHint = DAV_WAIT_HINT_TIME;
  215. DavPrint((DEBUG_MISC,
  216. "DavServiceMain: lpServiceArgVectors[0] = %ws\n", lpServiceArgVectors[0]));
  217. if ( lpServiceArgVectors[0] &&
  218. ( wcscmp(lpServiceArgVectors[0], L"notservice") == 0 ) ) {
  219. DavPrint((DEBUG_MISC, "DavServiceMain: WebClient is not running as a Service.\n"));
  220. } else {
  221. DavPrint((DEBUG_MISC, "DavServiceMain: WebClient is running as a Service.\n"));
  222. try {
  223. InitializeCriticalSection ( &(g_DavServiceLock) );
  224. } except(EXCEPTION_EXECUTE_HANDLER) {
  225. err = GetExceptionCode();
  226. DavPrint((DEBUG_ERRORS,
  227. "DavServiceMain/InitializeCriticalSection: Exception Code ="
  228. " = %08lx.\n", err));
  229. goto exitServiceMain;
  230. }
  231. g_DavServiceLockSet = TRUE;
  232. //
  233. // Register the service control handler.
  234. //
  235. g_hStatus = RegisterServiceCtrlHandler(SERVICE_DAVCLIENT, DavServiceHandler);
  236. if (g_hStatus) {
  237. g_registeredService = TRUE;
  238. DavPrint((DEBUG_INIT, "DavServiceMain: WebClient service is pending start.\n"));
  239. } else {
  240. DavPrint((DEBUG_INIT, "DavServiceMain: WebClient service failed to register.\n"));
  241. goto exitServiceMain;
  242. }
  243. }
  244. UpdateServiceStatus(SERVICE_START_PENDING);
  245. //
  246. // Attempt to load the mini-redir driver. If this fails, no point in us
  247. // starting up.
  248. //
  249. while (TRUE) {
  250. err = WsLoadRedir();
  251. if (err == ERROR_SERVICE_ALREADY_RUNNING || err == ERROR_SUCCESS) {
  252. DavPrint((DEBUG_MISC, "DavServiceMain/WsLoadRedir. Succeeded\n"));
  253. break;
  254. }
  255. //
  256. // If the transports are not ready, the MiniRedir returns an
  257. // error STATUS_REDIRECTOR_NOT_STARTED which maps to the Win32 error
  258. // ERROR_PATH_NOT_FOUND. In this case we sleep for 3 seconds and try
  259. // again with the hope that the transports will be ready soon. Also,
  260. // we update the service status to inform the SCM that we are doing
  261. // some work. We try this 5 times (till RedirRegisterCount == 4) and
  262. // if are unsuccessful, we give up.
  263. //
  264. if (err == ERROR_PATH_NOT_FOUND) {
  265. RedirRegisterCount++;
  266. DavPrint((DEBUG_ERRORS,
  267. "DavServiceMain/WsLoadRedir. RedirRegisterCount = %d\n",
  268. RedirRegisterCount));
  269. if (RedirRegisterCount >= 4) {
  270. DavPrint((DEBUG_ERRORS,
  271. "DavServiceMain/WsLoadRedir(1). Error Val = %d\n",
  272. err));
  273. goto exitServiceMain;
  274. }
  275. //
  276. // Sleep for 3 seconds.
  277. //
  278. Sleep(3000);
  279. (g_status.dwCheckPoint)++;
  280. UpdateServiceStatus(SERVICE_START_PENDING);
  281. continue;
  282. } else {
  283. DavPrint((DEBUG_ERRORS,
  284. "DavServiceMain/WsLoadRedir(2). Error Val = %d\n",
  285. err));
  286. goto exitServiceMain;
  287. }
  288. }
  289. g_RedirLoaded = TRUE;
  290. (g_status.dwCheckPoint)++;
  291. UpdateServiceStatus(SERVICE_START_PENDING);
  292. //
  293. // Initialize the global NT-style redirector device name string.
  294. //
  295. RtlInitUnicodeString(&RedirDeviceName, DD_DAV_DEVICE_NAME_U);
  296. //
  297. // Try to register the mini-redir.
  298. //
  299. err = UMReflectorRegister(DD_DAV_DEVICE_NAME_U,
  300. UMREFLECTOR_CURRENT_VERSION,
  301. &(DavReflectorHandle));
  302. if ((DavReflectorHandle == NULL) || (err != ERROR_SUCCESS)) {
  303. if (err == ERROR_SUCCESS) {
  304. err = ERROR_BAD_DRIVER;
  305. }
  306. DavPrint((DEBUG_ERRORS,
  307. "DavServiceMain/UMReflectorRegister. Error Val = %d\n",
  308. err));
  309. goto exitServiceMain;
  310. }
  311. (g_status.dwCheckPoint)++;
  312. UpdateServiceStatus(SERVICE_START_PENDING);
  313. //
  314. // Try to start the mini-redir.
  315. //
  316. err = UMReflectorStart(UMREFLECTOR_CURRENT_VERSION, DavReflectorHandle);
  317. if (err != ERROR_SUCCESS) {
  318. DavPrint((DEBUG_ERRORS,
  319. "DavServiceMain/UMReflectorStart. Error Val = %u.\n", err));
  320. goto exitServiceMain;
  321. }
  322. (g_status.dwCheckPoint)++;
  323. UpdateServiceStatus(SERVICE_START_PENDING);
  324. //
  325. // Initialize the socket interface.
  326. //
  327. err = InitializeTheSocketInterface();
  328. if (err != ERROR_SUCCESS) {
  329. DavPrint((DEBUG_ERRORS,
  330. "DavServiceMain/InitializeTheSocketInterface: Error Val = %u.\n", err));
  331. goto exitServiceMain;
  332. }
  333. //
  334. // Setup the DAV/WinInet environment.
  335. //
  336. err = DavInit();
  337. if (err != ERROR_SUCCESS) {
  338. DavPrint((DEBUG_ERRORS,
  339. "DavServiceMain/DavInit: Error Val = %u.\n", err));
  340. goto exitServiceMain;
  341. }
  342. //
  343. // Start the worker thread. This will handle completion routines queued
  344. // from other worker threads and from the request ioctl threads.
  345. //
  346. err = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  347. DAV_PARAMETERS_KEY,
  348. 0,
  349. KEY_QUERY_VALUE,
  350. &KeyHandle);
  351. if (err == ERROR_SUCCESS) {
  352. maxThreads = ReadDWord(KeyHandle,
  353. DAV_MAXTHREADS_KEY,
  354. DAV_MAXTHREADCOUNT_DEFAULT);
  355. initialThreads = ReadDWord(KeyHandle,
  356. DAV_THREADS_KEY,
  357. DAV_THREADCOUNT_DEFAULT);
  358. RegCloseKey(KeyHandle);
  359. } else {
  360. maxThreads = DAV_MAXTHREADCOUNT_DEFAULT;
  361. initialThreads = DAV_THREADCOUNT_DEFAULT;
  362. }
  363. (g_status.dwCheckPoint)++;
  364. UpdateServiceStatus(SERVICE_START_PENDING);
  365. err = DavInitWorkerThreads(initialThreads, maxThreads);
  366. if (err != ERROR_SUCCESS) {
  367. DavPrint((DEBUG_ERRORS,
  368. "DavServiceMain/DavInitWorkerThread: Error Val = %u.\n", err));
  369. goto exitServiceMain;
  370. }
  371. g_WorkersActive = TRUE;
  372. (g_status.dwCheckPoint)++;
  373. UpdateServiceStatus(SERVICE_START_PENDING);
  374. g_LUIDDeviceMapsEnabled = DavCheckLUIDDeviceMapsEnabled();
  375. //
  376. // Immediately report that we are running. All non-essential initialization
  377. // is deferred until we are called by clients to do some work.
  378. //
  379. DavPrint((DEBUG_INIT, "DavServiceMain: WebClient service is now running.\n"));
  380. (g_status.dwCheckPoint)++;
  381. UpdateServiceStatus(SERVICE_START_PENDING);
  382. //
  383. // Setup RPC server for this service.
  384. //
  385. if (!g_RpcActive) {
  386. err = DavSvcsGlobalData->StartRpcServer(L"DAV RPC SERVICE",
  387. davclntrpc_ServerIfHandle);
  388. if (err == STATUS_SUCCESS) {
  389. g_RpcActive = TRUE;
  390. } else {
  391. DavPrint((DEBUG_ERRORS,
  392. "DavServiceMain/SetupRpcServer: Error Val = %u.\n", err));
  393. }
  394. }
  395. UpdateServiceStatus(SERVICE_RUNNING);
  396. return;
  397. exitServiceMain:
  398. if (g_WorkersActive) {
  399. exitErr = DavTerminateWorkerThreads();
  400. if (exitErr != ERROR_SUCCESS) {
  401. DavPrint((DEBUG_ERRORS,
  402. "DavServiceMain/DavTerminateWorkerThreads: "
  403. "Error Val = %u.\n", exitErr));
  404. }
  405. g_WorkersActive = FALSE;
  406. }
  407. //
  408. // Close and free up the DAV stuff.
  409. //
  410. DavClose();
  411. if (g_socketinit) {
  412. exitErr = CleanupTheSocketInterface();
  413. if (exitErr != ERROR_SUCCESS) {
  414. DavPrint((DEBUG_ERRORS,
  415. "DavServiceMain/CleanupTheSocketInterface: "
  416. "Error Val = %u.\n", exitErr));
  417. }
  418. g_socketinit = FALSE;
  419. }
  420. if (g_RpcActive) {
  421. DavSvcsGlobalData->StopRpcServer(davclntrpc_ServerIfHandle);
  422. g_RpcActive = FALSE;
  423. }
  424. if (DavReflectorHandle != NULL) {
  425. exitErr = UMReflectorStop(DavReflectorHandle);
  426. if (exitErr != ERROR_SUCCESS) {
  427. DavPrint((DEBUG_ERRORS,
  428. "DavServiceMain/UMReflectorStop: Error Val = %u.\n", exitErr));
  429. }
  430. exitErr = UMReflectorUnregister(DavReflectorHandle);
  431. if (exitErr != ERROR_SUCCESS) {
  432. DavPrint((DEBUG_ERRORS,
  433. "DavServiceMain/UMReflectorUnregister: Error Val = 0x%x.\n", exitErr));
  434. }
  435. DavReflectorHandle = NULL;
  436. }
  437. if (g_RedirLoaded) {
  438. exitErr = WsUnloadRedir();
  439. if (exitErr != ERROR_SUCCESS) {
  440. DavPrint((DEBUG_ERRORS,
  441. "DavServiceMain/WsUnloadRedir: Error Val = %u.\n", exitErr));
  442. }
  443. g_RedirLoaded = FALSE;
  444. }
  445. if (g_DavServiceLockSet) {
  446. DeleteCriticalSection ( &(g_DavServiceLock) );
  447. g_DavServiceLockSet = FALSE;
  448. }
  449. //
  450. // Let the SCM know why the service did not start.
  451. //
  452. if (err != NO_ERROR) {
  453. g_status.dwWin32ExitCode = err;
  454. g_status.dwServiceSpecificExitCode = NO_ERROR;
  455. UpdateServiceStatus(SERVICE_STOPPED);
  456. }
  457. DavPrint((DEBUG_INIT, "DavServiceMain: WebClient service is stopped.\n"));
  458. #if DBG
  459. DebugUninitialize();
  460. #endif
  461. return;
  462. }
  463. DWORD
  464. DavNotRunningAsAService(
  465. VOID
  466. )
  467. /*++
  468. Routine Description:
  469. The DavClient is not being run as a Service.
  470. Arguments:
  471. None.
  472. Return Value:
  473. ERROR_SUCCESS - No problems.
  474. Win32 Error Code - Something went wrong.
  475. --*/
  476. {
  477. DWORD WStatus = ERROR_SUCCESS;
  478. HANDLE Thread;
  479. DWORD ThreadId;
  480. PWCHAR NotSrv = L"notservice";
  481. //
  482. // Create a thread for the fake service controller.
  483. //
  484. Thread = CreateThread( NULL, 0, DavFakeServiceController, 0, 0, &ThreadId );
  485. if (Thread == NULL) {
  486. WStatus = GetLastError();
  487. DavPrint((DEBUG_ERRORS,
  488. "DavNotRunningAsAService/CreateThread: Error Val = %d.\n", WStatus));
  489. return WStatus;
  490. }
  491. //
  492. // Call the Sevice Main function of the DavClient service.
  493. //
  494. ServiceMain( 2, &(NotSrv) );
  495. return WStatus;
  496. }
  497. DWORD
  498. WINAPI
  499. DavFakeServiceController(
  500. LPVOID Parameter
  501. )
  502. /*++
  503. Routine Description:
  504. The Fake service control for the DavClient when it is not running as a
  505. service. This is used to send a STOP signal to the DavClient.
  506. Arguments:
  507. Parameter - Dummy parameter.
  508. Return Value:
  509. ERROR_SUCCESS - No problems.
  510. --*/
  511. {
  512. while (DavStop == 0) {
  513. Sleep(1000);
  514. }
  515. DavServiceHandler( SERVICE_CONTROL_STOP );
  516. return 0;
  517. }
  518. BOOL
  519. DavCheckLUIDDeviceMapsEnabled(
  520. VOID
  521. )
  522. /*++
  523. Routine Description:
  524. This function calls NtQueryInformationProcess() to determine if
  525. LUID device maps are enabled
  526. Arguments:
  527. none
  528. Return Value:
  529. TRUE - LUID device maps are enabled
  530. FALSE - LUID device maps are disabled
  531. --*/
  532. {
  533. NTSTATUS Status;
  534. ULONG LUIDDeviceMapsEnabled;
  535. BOOL Result;
  536. Status = NtQueryInformationProcess( NtCurrentProcess(),
  537. ProcessLUIDDeviceMapsEnabled,
  538. &LUIDDeviceMapsEnabled,
  539. sizeof(LUIDDeviceMapsEnabled),
  540. NULL
  541. );
  542. if (!NT_SUCCESS( Status )) {
  543. Result = FALSE;
  544. }
  545. else {
  546. Result = (LUIDDeviceMapsEnabled != 0);
  547. }
  548. return( Result );
  549. }
  550. VOID
  551. _cdecl
  552. main (
  553. IN INT ArgC,
  554. IN PCHAR ArgV[]
  555. )
  556. /*++
  557. Routine Description:
  558. Main (DavClient) runs as either a service or an exe.
  559. Arguments:
  560. ArgC - Number of arguments.
  561. ArgV - Array of arguments.
  562. Return Value:
  563. ERROR_SUCCESS - No problems.
  564. Win32 Error Code - Something went wrong.
  565. --*/
  566. {
  567. BOOL RunningAsAService = TRUE;
  568. BOOL ReturnVal = FALSE;
  569. SERVICE_TABLE_ENTRYW DavServiceTableEntry[] = {
  570. { SERVICE_DAVCLIENT, ServiceMain },
  571. { NULL, NULL }
  572. };
  573. //
  574. // Are we running as a service or an exe ?
  575. //
  576. if ( ArgV[1] != NULL ) {
  577. if ( strstr(ArgV[1], "notservice") != NULL) {
  578. RunningAsAService = FALSE;
  579. }
  580. }
  581. if (RunningAsAService) {
  582. ReturnVal = StartServiceCtrlDispatcher(DavServiceTableEntry);
  583. if ( !ReturnVal ) {
  584. DavPrint((DEBUG_ERRORS,
  585. "main/StartServiceCtrlDispatcher: Error Val = %d.\n",
  586. GetLastError()));
  587. }
  588. } else {
  589. DWORD WStatus;
  590. WStatus = DavNotRunningAsAService();
  591. if ( WStatus != ERROR_SUCCESS ) {
  592. DavPrint((DEBUG_ERRORS,
  593. "main/DavNotRunningAsAService: Error Val = %d.\n",
  594. WStatus));
  595. }
  596. }
  597. return;
  598. }
  599. VOID
  600. DavReadRegistryValues(
  601. VOID
  602. )
  603. /*++
  604. Routine Description:
  605. This function reads some values from the registry and sets the globals in
  606. the WebClient service.
  607. Arguments:
  608. None.
  609. Return Value:
  610. None.
  611. --*/
  612. {
  613. ULONG WStatus = ERROR_SUCCESS;
  614. HKEY KeyHandle = NULL;
  615. ULONG ValueType = 0, ValueSize = 0;
  616. WStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
  617. DAV_PARAMETERS_KEY,
  618. 0,
  619. KEY_QUERY_VALUE,
  620. &(KeyHandle));
  621. if (WStatus != ERROR_SUCCESS) {
  622. KeyHandle = NULL;
  623. ServerNotFoundCacheLifeTimeInSec = 60;
  624. AcceptOfficeAndTahoeServers = 0;
  625. WStatus = GetLastError();
  626. DbgPrint("ERROR: DavReadRegistryValues/RegOpenKeyExW. WStatus = %d\n", WStatus);
  627. goto EXIT_THE_FUNCTION;
  628. }
  629. //
  630. // If we fail in getting the values from the registry, set them to default
  631. // values.
  632. //
  633. ValueSize = sizeof(ServerNotFoundCacheLifeTimeInSec);
  634. WStatus = RegQueryValueExW(KeyHandle,
  635. DAV_SERV_CACHE_VALUE,
  636. 0,
  637. &(ValueType),
  638. (LPBYTE)&(ServerNotFoundCacheLifeTimeInSec),
  639. &(ValueSize));
  640. if (WStatus != ERROR_SUCCESS) {
  641. ServerNotFoundCacheLifeTimeInSec = 60;
  642. WStatus = GetLastError();
  643. DbgPrint("ERROR: DavReadRegistryValues/RegQueryValueExW(1). WStatus = %d\n", WStatus);
  644. }
  645. ValueSize = sizeof(AcceptOfficeAndTahoeServers);
  646. WStatus = RegQueryValueExW(KeyHandle,
  647. DAV_ACCEPT_TAHOE_OFFICE_SERVERS,
  648. 0,
  649. &(ValueType),
  650. (LPBYTE)&(AcceptOfficeAndTahoeServers),
  651. &(ValueSize));
  652. if (WStatus != ERROR_SUCCESS) {
  653. AcceptOfficeAndTahoeServers = 0;
  654. WStatus = GetLastError();
  655. DbgPrint("ERROR: DavReadRegistryValues/RegQueryValueExW(2). WStatus = %d\n", WStatus);
  656. }
  657. ValueSize = sizeof(DavSupportLockingOfFiles);
  658. WStatus = RegQueryValueExW(KeyHandle,
  659. DAV_SUPPORT_LOCKING_OF_FILES,
  660. 0,
  661. &(ValueType),
  662. (LPBYTE)&(DavSupportLockingOfFiles),
  663. &(ValueSize));
  664. if (WStatus != ERROR_SUCCESS) {
  665. DavSupportLockingOfFiles = 1;
  666. WStatus = GetLastError();
  667. DbgPrint("ERROR: DavReadRegistryValues/RegQueryValueExW(3). WStatus = %d\n", WStatus);
  668. }
  669. ValueSize = sizeof(DavFileSizeLimitInBytes);
  670. WStatus = RegQueryValueExW(KeyHandle,
  671. DAV_FILE_SIZE_LIMIT,
  672. 0,
  673. &(ValueType),
  674. (LPBYTE)&(DavFileSizeLimitInBytes),
  675. &(ValueSize));
  676. if (WStatus != ERROR_SUCCESS) {
  677. DavFileSizeLimitInBytes = 0x2faf080;
  678. WStatus = GetLastError();
  679. DbgPrint("ERROR: DavReadRegistryValues/RegQueryValueExW(4). WStatus = %d\n", WStatus);
  680. }
  681. ValueSize = sizeof(DavFileAttributesLimitInBytes);
  682. WStatus = RegQueryValueExW(KeyHandle,
  683. DAV_ATTRIBUTES_SIZE_LIMIT,
  684. 0,
  685. &(ValueType),
  686. (LPBYTE)&(DavFileAttributesLimitInBytes),
  687. &(ValueSize));
  688. if (WStatus != ERROR_SUCCESS) {
  689. DavFileAttributesLimitInBytes = 0xf4240;
  690. WStatus = GetLastError();
  691. DbgPrint("ERROR: DavReadRegistryValues/RegQueryValueExW(5). WStatus = %d\n", WStatus);
  692. }
  693. EXIT_THE_FUNCTION:
  694. if (KeyHandle) {
  695. RegCloseKey(KeyHandle);
  696. }
  697. return;
  698. }