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.

580 lines
20 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. server.c
  5. Abstract:
  6. This file implements the server file copy code.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Wesley Witt (wesw) 17-Feb-1996
  11. --*/
  12. #include "wizard.h"
  13. #pragma hdrstop
  14. FILE_QUEUE_INFO ServerFileQueue[] =
  15. {
  16. //------------------------------------------------------------------------------------------------------------------------------------------------------------
  17. // Section Name Dest Dir INF Dir Id Dest Dir Id Platforms Copy Flags
  18. //------------------------------------------------------------------------------------------------------------------------------------------------------------
  19. { TEXT("ServerSystemFiles"), NULL, DIRID_SYSTEM, DIRID_SYSTEM, PLATFORM_NONE, SP_COPY_NEWER },
  20. { TEXT("HelpFilesCommon"), NULL, DIRID_HELP, DIRID_HELP, PLATFORM_NONE, SP_COPY_NEWER },
  21. { TEXT("HelpFilesServer"), NULL, DIRID_HELP, DIRID_HELP, PLATFORM_NONE, SP_COPY_NEWER },
  22. { TEXT("ServerPrinterFiles"), NULL, PRINTER_DRIVER_DIR, DIRID_SPOOLDRIVERS, PLATFORM_USE_PRINTER, SP_COPY_NEWER },
  23. { TEXT("ClientFiles"), FAXCLIENTS_DIR, PRINTER_CLIENT_DIR, DIRID_SPOOLDRIVERS, PLATFORM_USE_MACHINE, SP_COPY_NEWER },
  24. { TEXT("OutlookConfigFile"), OUTLOOKCONFIG_DIR, OUTLOOK_ECF_DIR, DIRID_WINDOWS, PLATFORM_NONE, SP_COPY_NEWER },
  25. { TEXT("ClientCoverPageFiles"), COVERPAGE_DIR, COVERPAGE_CLIENT_DIR, DIRID_SYSTEM, PLATFORM_NONE, SP_COPY_NEWER },
  26. { TEXT("ClientCoverPageFiles"), COVERPAGE_DIR, COVERPAGE_CLIENT_DIR, DIRID_SPOOLDRIVERS, PLATFORM_NONE, SP_COPY_NEWER }
  27. //
  28. // ClientCoverPageFiles MUST be the last section because when upgrading
  29. // the coverpages should not be installed. This is accomplished by decrementing
  30. // file queue count.
  31. //
  32. };
  33. #define CountServerFileQueue (sizeof(ServerFileQueue)/sizeof(FILE_QUEUE_INFO))
  34. FILE_QUEUE_INFO WorkstationFileQueue[] =
  35. {
  36. //------------------------------------------------------------------------------------------------------------------------------------------------------------
  37. // Section Name Dest Dir INF Dir Id Dest Dir Id Platforms Copy Flags
  38. //------------------------------------------------------------------------------------------------------------------------------------------------------------
  39. { TEXT("ServerSystemFiles"), NULL, DIRID_SYSTEM, DIRID_SYSTEM, PLATFORM_NONE, SP_COPY_NEWER },
  40. { TEXT("HelpFilesCommon"), NULL, DIRID_HELP, DIRID_HELP, PLATFORM_NONE, SP_COPY_NEWER },
  41. { TEXT("HelpFilesServer"), NULL, DIRID_HELP, DIRID_HELP, PLATFORM_NONE, SP_COPY_NEWER },
  42. { TEXT("HelpFilesWorkstation"), NULL, DIRID_HELP, DIRID_HELP, PLATFORM_NONE, SP_COPY_NEWER },
  43. { TEXT("ServerPrinterFiles"), NULL, PRINTER_DRIVER_DIR, DIRID_SPOOLDRIVERS, PLATFORM_USE_PRINTER, SP_COPY_NEWER },
  44. { TEXT("ClientFiles"), FAXCLIENTS_DIR, PRINTER_CLIENT_DIR, DIRID_SPOOLDRIVERS, PLATFORM_USE_MACHINE, SP_COPY_NEWER },
  45. { TEXT("OutlookConfigFile"), OUTLOOKCONFIG_DIR, OUTLOOK_ECF_DIR, DIRID_WINDOWS, PLATFORM_NONE, SP_COPY_NEWER },
  46. { TEXT("ClientCoverPageFiles"), COVERPAGE_DIR, COVERPAGE_CLIENT_DIR, DIRID_SPOOLDRIVERS, PLATFORM_NONE, SP_COPY_NEWER }
  47. //
  48. // ClientCoverPageFiles MUST be the last section because when upgrading
  49. // the coverpages should not be installed. This is accomplished by decrementing
  50. // file queue count.
  51. //
  52. };
  53. #define CountWorkstationFileQueue (sizeof(WorkstationFileQueue)/sizeof(FILE_QUEUE_INFO))
  54. FILE_QUEUE_INFO DriverClientFileQueue[] =
  55. {
  56. //---------------------------------------------------------------------------------------------------------------------------------------------------------
  57. // Section Name Dest Dir INF Dir Id Dest Dir Id Platforms Copy Flags
  58. //---------------------------------------------------------------------------------------------------------------------------------------------------------
  59. { TEXT("ServerPrinterFiles"), NULL, PRINTER_DRIVER_DIR, DIRID_SPOOLDRIVERS, PLATFORM_USE_PRINTER, SP_COPY_NEWER },
  60. { TEXT("ClientFiles"), FAXCLIENTS_DIR, PRINTER_CLIENT_DIR, DIRID_SPOOLDRIVERS, PLATFORM_USE_MACHINE, SP_COPY_NEWER }
  61. };
  62. #define CountDriverClientFileQueue (sizeof(DriverClientFileQueue)/sizeof(FILE_QUEUE_INFO))
  63. UINT
  64. InstallQueueCallback(
  65. IN PVOID QueueContext,
  66. IN UINT Notification,
  67. IN UINT Param1,
  68. IN UINT Param2
  69. )
  70. {
  71. LPTSTR TextBuffer;
  72. DWORD len;
  73. PFILE_QUEUE_CONTEXT FileQueueContext = (PFILE_QUEUE_CONTEXT) QueueContext;
  74. if (Notification == SPFILENOTIFY_STARTCOPY) {
  75. TextBuffer = MemAlloc(
  76. ((_tcslen( ((PFILEPATHS)Param1)->Target ) + 32) * sizeof(TCHAR)) +
  77. ((_tcslen( ((PFILEPATHS)Param1)->Source ) + 32) * sizeof(TCHAR))
  78. );
  79. if (TextBuffer) {
  80. _stprintf(
  81. TextBuffer,
  82. TEXT("%s%s"),
  83. GetString( IDS_COPYING ),
  84. ((PFILEPATHS)Param1)->Target
  85. );
  86. len = ExtraChars( GetDlgItem( FileQueueContext->hwnd, IDC_PROGRESS_TEXT ), TextBuffer );
  87. if (len) {
  88. LPTSTR FileName = CompactFileName( ((PFILEPATHS)Param1)->Target, len );
  89. _stprintf(
  90. TextBuffer,
  91. TEXT("%s%s"),
  92. GetString( IDS_COPYING ),
  93. FileName
  94. );
  95. MemFree( FileName );
  96. }
  97. SetDlgItemText(
  98. FileQueueContext->hwnd,
  99. IDC_PROGRESS_TEXT,
  100. TextBuffer
  101. );
  102. _stprintf(
  103. TextBuffer,
  104. TEXT("%s %s -> %s"),
  105. GetString( IDS_COPYING ),
  106. ((PFILEPATHS)Param1)->Source,
  107. ((PFILEPATHS)Param1)->Target
  108. );
  109. DebugPrint(( TEXT("%s"), TextBuffer ));
  110. MemFree( TextBuffer );
  111. }
  112. }
  113. //
  114. // Want default processing.
  115. //
  116. return SetupDefaultQueueCallback( FileQueueContext->QueueContext, Notification, Param1, Param2 );
  117. }
  118. VOID
  119. SetProgress(
  120. HWND hwnd,
  121. DWORD StatusString
  122. )
  123. {
  124. if (Unattended) {
  125. return;
  126. }
  127. SendMessage( hwnd, WM_MY_PROGRESS, 10, 0 );
  128. SetDlgItemText(
  129. hwnd,
  130. IDC_PROGRESS_TEXT,
  131. GetString( StatusString )
  132. );
  133. }
  134. DWORD
  135. ServerFileCopyThread(
  136. HWND hwnd
  137. )
  138. {
  139. HINF FaxSetupInf;
  140. HSPFILEQ *FileQueue;
  141. PVOID QueueContext;
  142. DWORD ErrorCode = 0;
  143. DWORD PlatformsMask;
  144. DWORD i;
  145. int DlgErr;
  146. SECURITY_INFO SecurityInfo;
  147. PFILE_QUEUE_INFO FileQueueInfo;
  148. DWORD CountFileQueueInfo;
  149. DWORD OldInstallType;
  150. TCHAR FileName[256];
  151. TCHAR SrcDir[MAX_PATH];
  152. TCHAR DestDir[MAX_PATH];
  153. DWORD BytesNeeded;
  154. BOOL CompleteInstall;
  155. if (NtGuiMode) {
  156. MyStartService( L"LanmanServer" );
  157. if (FaxDevices && Enabled) {
  158. CompleteInstall = TRUE;
  159. }
  160. } else {
  161. CompleteInstall = TRUE;
  162. }
  163. //
  164. // copy all of the files
  165. //
  166. ExpandEnvironmentStrings( TEXT("%windir%\\awmodem.inf"), FileName, sizeof(FileName)/sizeof(TCHAR) );
  167. MyDeleteFile( FileName );
  168. //
  169. // copy faxwiz.dll to the printer driver directory
  170. // this is necessary because layout.inf cannot have
  171. // duplicate entries and we need faxwiz.dll to be
  172. // copied to more than one location
  173. //
  174. if (NtGuiMode && (InstallMode & INSTALL_NEW)) {
  175. if (GetPrinterDriverDirectory( NULL, NULL, 1, (LPBYTE) DestDir, MAX_PATH, &BytesNeeded )) {
  176. _tcscat( DestDir, TEXT("\\faxwiz.dll") );
  177. ExpandEnvironmentStrings( TEXT("%systemroot%\\system32\\faxwiz.dll"), SrcDir, sizeof(SrcDir)/sizeof(TCHAR) );
  178. CopyFile( SrcDir, DestDir, FALSE );
  179. }
  180. }
  181. if (InstallMode & INSTALL_UPGRADE) {
  182. if (GetPrinterDriverDirectory( NULL, NULL, 1, (LPBYTE) SrcDir, MAX_PATH, &BytesNeeded )) {
  183. LPTSTR DirectoryPath = _tcsrchr( SrcDir, TEXT( '\\' ) );
  184. if (DirectoryPath) {
  185. *++DirectoryPath = 0;
  186. _tcscpy( DestDir, SrcDir );
  187. _tcscpy( DirectoryPath, OLD_COVERPAGE_DIR );
  188. _tcscat( DestDir, COVERPAGE_DIR );
  189. MoveFile( SrcDir, DestDir );
  190. }
  191. }
  192. }
  193. if (!Unattended) {
  194. if (InstallMode & INSTALL_NEW) {
  195. SendMessage( hwnd, WM_MY_PROGRESS, 0xff, 50 );
  196. } else {
  197. SendMessage( hwnd, WM_MY_PROGRESS, 0xff, 10 );
  198. }
  199. }
  200. //
  201. // when running in nt gui mode setup
  202. // the files do not need to be copied
  203. // because they have been copied during
  204. // text mode setup.
  205. //
  206. if (!NtGuiMode) {
  207. if (!InitializeFileQueue( hwnd, &FaxSetupInf, &FileQueue, &QueueContext, SourceDirectory )) {
  208. ErrorCode = IDS_COULD_NOT_COPY_FILES;
  209. goto error_exit;
  210. }
  211. if (InstallType & FAX_INSTALL_WORKSTATION) {
  212. FileQueueInfo = WorkstationFileQueue;
  213. CountFileQueueInfo = CountWorkstationFileQueue;
  214. //
  215. // If upgrading, decrement the count to drop the coverpage section
  216. //
  217. if (InstallMode & INSTALL_UPGRADE) {
  218. CountFileQueueInfo--;
  219. }
  220. } else {
  221. FileQueueInfo = ServerFileQueue;
  222. CountFileQueueInfo = CountServerFileQueue;
  223. //
  224. // If upgrading, decrement the count to drop the coverpage section
  225. //
  226. if (InstallMode & INSTALL_UPGRADE) {
  227. CountFileQueueInfo--;
  228. }
  229. }
  230. if (InstallMode & INSTALL_DRIVERS) {
  231. FileQueueInfo = DriverClientFileQueue;
  232. CountFileQueueInfo = CountDriverClientFileQueue;
  233. }
  234. if (!ProcessFileQueue( FaxSetupInf, FileQueue, QueueContext, SourceDirectory,
  235. FileQueueInfo, CountFileQueueInfo, InstallQueueCallback, SETUP_ACTION_COPY )) {
  236. ErrorCode = IDS_COULD_NOT_COPY_FILES;
  237. goto error_exit;
  238. }
  239. if (!CloseFileQueue( FileQueue, QueueContext )) {
  240. ErrorCode = IDS_COULD_NOT_COPY_FILES;
  241. goto error_exit;
  242. }
  243. }
  244. //
  245. // set the registry data
  246. //
  247. SetProgress( hwnd, IDS_SETTING_REGISTRY );
  248. if (!SetServerRegistryData()) {
  249. DebugPrint(( TEXT("SetServerRegistryDatae() failed") ));
  250. ErrorCode = IDS_COULD_SET_REG_DATA;
  251. goto error_exit;
  252. }
  253. if (!SetClientRegistryData()) {
  254. DebugPrint(( TEXT("SetClientRegistryDatae() failed") ));
  255. ErrorCode = IDS_COULD_SET_REG_DATA;
  256. goto error_exit;
  257. }
  258. if (InstallType & FAX_INSTALL_WORKSTATION) {
  259. SetSoundRegistryData();
  260. }
  261. #ifdef MSFT_FAXVIEW
  262. CreateFileAssociation(
  263. FAXVIEW_EXTENSION,
  264. FAXVIEW_ASSOC_NAME,
  265. FAXVIEW_ASSOC_DESC,
  266. FAXVIEW_OPEN_COMMAND,
  267. FAXVIEW_PRINT_COMMAND,
  268. FAXVIEW_PRINTTO_COMMAND,
  269. FAXVIEW_FILE_NAME,
  270. FAXVIEW_ICON_INDEX
  271. );
  272. CreateFileAssociation(
  273. FAXVIEW_EXTENSION2,
  274. FAXVIEW_ASSOC_NAME,
  275. FAXVIEW_ASSOC_DESC,
  276. FAXVIEW_OPEN_COMMAND,
  277. FAXVIEW_PRINT_COMMAND,
  278. FAXVIEW_PRINTTO_COMMAND,
  279. FAXVIEW_FILE_NAME,
  280. FAXVIEW_ICON_INDEX
  281. );
  282. #endif
  283. DeleteModemRegistryKey();
  284. //
  285. // set all of the install flags in the registry
  286. // this must be done before the fax service is
  287. // started so it can query the values
  288. //
  289. for (i=0,PlatformsMask=0; i<CountPlatforms; i++) {
  290. if (Platforms[i].Selected) {
  291. PlatformsMask |= (1 << i);
  292. }
  293. }
  294. OldInstallType = InstallType;
  295. SetInstalledFlag( TRUE );
  296. SetInstallType( RequestedSetupType == SETUP_TYPE_WORKSTATION ? FAX_INSTALL_WORKSTATION : FAX_INSTALL_SERVER );
  297. SetInstalledPlatforms( PlatformsMask );
  298. SetUnInstallInfo();
  299. //
  300. // install the fax service
  301. //
  302. if (InstallMode & INSTALL_NEW) {
  303. SetProgress( hwnd, IDS_INSTALLING_FAXSVC );
  304. if (!InstallFaxService( WizData.UseLocalSystem, !CompleteInstall, WizData.AccountName, WizData.Password )) {
  305. ErrorCode = GetLastError();
  306. if (ErrorCode != ERROR_SERVICE_LOGON_FAILED) {
  307. DebugPrint(( TEXT("InstallFaxService() failed") ));
  308. goto error_exit;
  309. }
  310. if (NtGuiMode) {
  311. WizData.UseLocalSystem = TRUE;
  312. if (!InstallFaxService( WizData.UseLocalSystem, NtGuiMode, WizData.AccountName, WizData.Password )) {
  313. DebugPrint(( TEXT("InstallFaxService() failed") ));
  314. ErrorCode = IDS_COULD_NOT_INSTALL_FAX_SERVICE;
  315. goto error_exit;
  316. }
  317. }
  318. while( ErrorCode == ERROR_SERVICE_LOGON_FAILED) {
  319. DWORD Answer ;
  320. ZeroMemory( &SecurityInfo, sizeof(SECURITY_INFO) );
  321. _tcscpy( SecurityInfo.AccountName, WizData.AccountName );
  322. _tcscpy( SecurityInfo.Password, WizData.Password );
  323. do{ // Return to here if user chooses CANCEL and then waffles on the decision.
  324. DlgErr = DialogBoxParam(
  325. FaxWizModuleHandle,
  326. MAKEINTRESOURCE(IDD_SECURITY_ERROR),
  327. hwnd,
  328. SecurityErrorDlgProc,
  329. (LPARAM) &SecurityInfo
  330. );
  331. Answer = IDYES ;
  332. if (DlgErr == -1 || DlgErr == 0) {
  333. DebugPrint(( TEXT("SecurityErrorDlgProc() failed or was cancelled -- First while loop") ));
  334. Answer = PopUpMsg( hwnd, IDS_QUERY_CANCEL, FALSE, MB_YESNO );
  335. if( Answer == IDYES ){
  336. goto error_exit_no_popup;
  337. }
  338. }
  339. } while( Answer == IDNO );
  340. _tcscpy( WizData.AccountName, SecurityInfo.AccountName );
  341. _tcscpy( WizData.Password, SecurityInfo.Password );
  342. if (!InstallFaxService( WizData.UseLocalSystem, NtGuiMode, WizData.AccountName, WizData.Password )) {
  343. DebugPrint(( TEXT("InstallFaxService() failed") ));
  344. ErrorCode = GetLastError();
  345. if (ErrorCode != ERROR_SERVICE_LOGON_FAILED) {
  346. DebugPrint(( TEXT("InstallFaxService() failed") ));
  347. ErrorCode = IDS_COULD_NOT_INSTALL_FAX_SERVICE;
  348. goto error_exit;
  349. }
  350. } else {
  351. ErrorCode = 0;
  352. }
  353. }
  354. }
  355. }
  356. //
  357. // do the exchange stuff
  358. //
  359. SetProgress( hwnd, IDS_INSTALLING_EXCHANGE );
  360. DoExchangeInstall( hwnd );
  361. //
  362. // start the fax service
  363. //
  364. SetProgress( hwnd, IDS_STARTING_FAXSVC );
  365. //
  366. // can't start the fax service during gui mode
  367. // setup because netlogon has not yet been started
  368. // so the service controller cannot logon to the
  369. // account that the fax service runs under
  370. //
  371. if (!NtGuiMode) {
  372. ErrorCode = StartFaxService();
  373. if (ErrorCode == ERROR_SERVICE_LOGON_FAILED) {
  374. while( ErrorCode == ERROR_SERVICE_LOGON_FAILED) {
  375. DWORD Answer;
  376. ZeroMemory( &SecurityInfo, sizeof(SECURITY_INFO) );
  377. _tcscpy( SecurityInfo.AccountName, WizData.AccountName );
  378. _tcscpy( SecurityInfo.Password, WizData.Password );
  379. do{ // Return to here if user choses CANCEL and then waffles on the decision.
  380. DlgErr = DialogBoxParam(
  381. FaxWizModuleHandle,
  382. MAKEINTRESOURCE(IDD_SECURITY_ERROR),
  383. hwnd,
  384. SecurityErrorDlgProc,
  385. (LPARAM) &SecurityInfo
  386. );
  387. Answer = IDYES;
  388. if (DlgErr == -1 || DlgErr == 0) {
  389. DebugPrint(( TEXT("SecurityErrorDlgProc() failed or was cancelled -- Second while loop") ));
  390. Answer = PopUpMsg( hwnd, IDS_QUERY_CANCEL, FALSE, MB_YESNO );
  391. if( Answer == IDYES ){
  392. goto error_exit_no_popup;
  393. }
  394. }
  395. } while( Answer == IDNO );
  396. _tcscpy( WizData.AccountName, SecurityInfo.AccountName );
  397. _tcscpy( WizData.Password, SecurityInfo.Password );
  398. if (!SetServiceAccount( TEXT("Fax"), &SecurityInfo )) {
  399. DebugPrint(( TEXT("SetServiceSecurity() failed") ));
  400. ErrorCode = IDS_CANT_SET_SERVICE_ACCOUNT;
  401. goto error_exit;
  402. }
  403. ErrorCode = StartFaxService();
  404. }
  405. }
  406. if (ErrorCode != ERROR_SUCCESS) {
  407. ErrorCode = IDS_COULD_NOT_START_FAX_SERVICE;
  408. goto error_exit;
  409. }
  410. }
  411. if (InstallMode & INSTALL_NEW) {
  412. SetProgress( hwnd, IDS_CREATING_FAXPRT );
  413. if (CompleteInstall) {
  414. if (!CreateServerFaxPrinter( hwnd, WizData.PrinterName )) {
  415. DebugPrint(( TEXT("CreateServerFaxPrinter() failed") ));
  416. if (!NtGuiMode) {
  417. StopFaxService();
  418. DeleteFaxService();
  419. SetInstalledFlag( FALSE );
  420. ErrorCode = IDS_COULD_NOT_CREATE_PRINTER;
  421. goto error_exit;
  422. }
  423. }
  424. }
  425. } else {
  426. AddPrinterDrivers();
  427. }
  428. if (((InstallMode & INSTALL_NEW) || (InstallMode & INSTALL_UPGRADE)) && CompleteInstall) {
  429. SetProgress( hwnd, IDS_CREATING_GROUPS );
  430. CreateGroupItems( FALSE, NULL );
  431. }
  432. if (InstallMode & INSTALL_NEW) {
  433. InstallHelpFiles();
  434. }
  435. if (InstallMode & INSTALL_NEW) {
  436. MakeDirectory( FAX_DIR );
  437. MakeDirectory( FAX_RECEIVE_DIR );
  438. MakeDirectory( FAX_QUEUE_DIR );
  439. CreateNetworkShare( FAX_DIR, FAX_SHARE, EMPTY_STRING );
  440. }
  441. //
  442. // create the client install shares, only if we're not installing on sam
  443. //
  444. CreateNetworkShare(
  445. FAXCLIENTS_FULL_PATH,
  446. FAXCLIENTS_DIR,
  447. FAXCLIENTS_COMMENT
  448. );
  449. if (!Unattended) {
  450. SetWindowLong( hwnd, DWL_MSGRESULT, 0 );
  451. PropSheet_PressButton( GetParent(hwnd), PSBTN_NEXT );
  452. }
  453. return TRUE;
  454. error_exit:
  455. PopUpMsg( hwnd, ErrorCode, TRUE, 0 );
  456. error_exit_no_popup:
  457. InstallThreadError = ErrorCode;
  458. OkToCancel = TRUE;
  459. if (!Unattended) {
  460. PropSheet_PressButton( GetParent(hwnd), PSBTN_CANCEL );
  461. SetWindowLong( hwnd, DWL_MSGRESULT, -1 );
  462. }
  463. //
  464. // reset the install registry data
  465. //
  466. SetInstalledFlag( Installed );
  467. SetInstallType( OldInstallType );
  468. SetInstalledPlatforms( InstalledPlatforms );
  469. if (!Installed) {
  470. DeleteUnInstallInfo();
  471. }
  472. return FALSE;
  473. }