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.

1754 lines
49 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <tchar.h>
  4. #include <winver.h>
  5. #include <winnetwk.h>
  6. #include "network.h"
  7. #include "idw_dbg.h"
  8. #include "machines.h"
  9. #include "server.h"
  10. #define TTEST // Test non-threaded execution for server reporting.
  11. /*++
  12. Filename : Network.c
  13. Description: Contains the network access code.
  14. Created by: Wally Ho
  15. History: Created on 28/01/2000.
  16. 09.19.2001 Joe Holman fixes for idwlog bugs 409338, 399178, and 352810
  17. Contains these functions:
  18. 1. FILE* OpenCookieFile();
  19. 2. VOID CloseCookieFile(IN FILE* fpOpenFile);
  20. 3. VOID DeleteCookieFile( VOID )
  21. 4. BOOL WriteIdwlogCookie ( IN LPINSTALL_DATA pId);
  22. 5. BOOL ReadIdwlogCookie ( OUT LPINSTALL_DATA lpId);
  23. 6. BOOL ServerWriteMinimum (LPINSTALL_DATA pId,
  24. LPMACHINE_DETAILS pMd);
  25. 7. VOID ServerWriteMaximum (LPTSTR szFileName,
  26. LPINSTALL_DATA pId);
  27. 8. VOID WriteThread(IN LPSERVER_WRITE_PARAMS pSw);
  28. 9. VOID DeleteDatafile (LPINSTALL_DATA);
  29. 10. BOOL WriteDataToAvailableServer (LPINSTALL_DATA pId,
  30. LPTSTR szServerData)
  31. 11. BOOL SetCancelMutex ( VOID );
  32. 12. BOOL ClearCancelMutex ( VOID );
  33. 13. BOOL PauseForMutex( VOID );
  34. 14. BOOL FileExistsEx( IN LPTSTR szFileName);
  35. 15 VOID DeleteIPCConnections( VOID );
  36. --*/
  37. // Global Mutex Handle;
  38. HANDLE g_hCancelMutex;
  39. HANDLE g_hInstanceMutex;
  40. FILE*
  41. OpenCookieFile(VOID)
  42. /*++
  43. Routine Description:
  44. This will try drives c through z to find the idwlog.cookie file.
  45. Arguments:
  46. NONE
  47. Return Value:
  48. NULL for failure.
  49. The file handle if found.
  50. Author: Wally Ho (wallyho) Jan 31st, 2000
  51. --*/
  52. {
  53. FILE* fpOpenFile;
  54. TCHAR szDriveFile [ 20];
  55. UINT i;
  56. for (i= TEXT('c'); i <= TEXT('z'); i++){
  57. _stprintf ( szDriveFile, TEXT("%c:\\idwlog.cookie"), i);
  58. fpOpenFile = _tfopen(szDriveFile, TEXT("r"));
  59. // if we find the file we return the handle to it.
  60. if (NULL != fpOpenFile)
  61. return fpOpenFile;
  62. }
  63. // if we get here we know we found nothing.
  64. return NULL;
  65. }
  66. VOID
  67. CloseCookieFile(IN FILE* fpOpenFile)
  68. /*++
  69. Author: Wally Ho (wallyho) Jan 31st, 2000
  70. Routine Description:
  71. This will close the cookie file and Delete it
  72. It will try drives c through z to find the idwlog.cookie file.
  73. Arguments:
  74. The File Handle.
  75. Return Value:
  76. NONE
  77. --*/
  78. {
  79. fclose(fpOpenFile);
  80. }
  81. VOID
  82. DeleteCookieFile( VOID )
  83. /*++
  84. Author: Wally Ho (wallyho) Jan 31st, 2000
  85. Routine Description:
  86. This will delete the cookiefile.
  87. It will try drives c through z to find the idwlog.cookie file.
  88. Arguments:
  89. NONE
  90. Return Value:
  91. NONE
  92. --*/
  93. {
  94. TCHAR szDriveFile [ 20];
  95. UINT i;
  96. BOOL bDeleteSuccess = FALSE;
  97. // Try to delete the idwlog.cookie file.
  98. // specifies.
  99. for (i = TEXT('c'); i <= TEXT('z');i++){
  100. _stprintf ( szDriveFile, TEXT("%c:\\idwlog.cookie"), i);
  101. //
  102. // If we get a non zero return from DeleteFile
  103. // then we know the delete file was a success.
  104. //
  105. if (FALSE != DeleteFile(szDriveFile) ){
  106. bDeleteSuccess = TRUE;
  107. break;
  108. }
  109. }
  110. if (FALSE == bDeleteSuccess)
  111. Idwlog(TEXT("DeleteCookieFile ERROR - There was a problem deleting the idwlog.cookie file, gle = %ld, file = %s\n"), GetLastError(), szDriveFile );
  112. else
  113. Idwlog(TEXT("The idwlog.cookie file was successfully deleted.\n"));
  114. }
  115. BOOL
  116. WriteIdwlogCookie (IN LPINSTALL_DATA pId)
  117. /*++
  118. Routine Description:
  119. The cookie file will be saved as idwlog.cookie.
  120. The file will be hidden and will wind up on the root of the system
  121. drive.
  122. This cookie file passes information we can only get from the install
  123. program over to the second part of the idwlog.
  124. The new cookie file format is this. Keyword seprated by 1 space.
  125. Much cleaner and easily extensible.
  126. ComputerName WALLYHO_DEV
  127. SystemBuild 2190
  128. SystemBuildDelta 30
  129. SystemBuildLocation LAB
  130. InstallingBuild 2195
  131. InstallingBuildDelta 30
  132. InstallingBuildLocation LAB
  133. MachineID 3212115354
  134. Cdrom YES|NO
  135. Network YES|NO
  136. Type CLEAN|UPGRADE
  137. Msi N
  138. SPMethod
  139. OEMImage YES|NO
  140. Arguments:
  141. INSTALL_DATA structure.
  142. Return Value:
  143. NONE
  144. --*/
  145. {
  146. HANDLE hFile;
  147. TCHAR szLineBuffer [ MAX_PATH ];
  148. TCHAR szIdwlogCookieFile[30];
  149. DWORD dwNumWritten;
  150. if (TRUE == pId->bFindBLDFile){
  151. // wallyho:
  152. // Get the system drive and write the cookie file there.
  153. // originally it would write it in the SAVE_FILE and thats
  154. // always c:. If this fails say %SystemDrive% doesn't exist in
  155. // windows 9X (I don't know if it does?) then we'll default to c:
  156. if(FALSE == GetEnvironmentVariable(TEXT("SystemDrive"), szIdwlogCookieFile, 30))
  157. _stprintf(szIdwlogCookieFile,TEXT("c:"));
  158. _tcscat(szIdwlogCookieFile,TEXT("\\idwlog.cookie"));
  159. hFile = CreateFile (szIdwlogCookieFile,
  160. GENERIC_WRITE,
  161. 0,
  162. NULL,
  163. CREATE_ALWAYS,
  164. FILE_ATTRIBUTE_HIDDEN,
  165. NULL );
  166. if (hFile == INVALID_HANDLE_VALUE){
  167. OutputDebugString ("Unable to write idwlog.cookie file.\n");
  168. Idwlog(TEXT("Problem writing the idwlog.cookie file.\n\
  169. Returning without writing. Last Error %lu\n"), GetLastError());
  170. return FALSE;
  171. }
  172. /*
  173. New format for the idwlog.cookie file.
  174. ComputerName WALLYHO_DEV
  175. SystemBuild 2190
  176. SystemBuildDelta 30
  177. SystemBuildLocation Lab01_N.000219-2219
  178. InstallingBuild 2195
  179. InstallingBuildDelta 30
  180. InstallingBuildLocation Lab01_N.000219-2219
  181. MachineID 3212115354
  182. Cdrom YES|NO
  183. Network YES|NO
  184. Type CLEAN|UPGRADE
  185. Msi N
  186. SPMethod
  187. SPMSI YES|NO
  188. OEMImage YES|NO
  189. IdwlogServer \\ntcore2\idwlog
  190. */
  191. // Write into idwlog.cookie
  192. ZeroMemory((LPTSTR)szLineBuffer,MAX_PATH);
  193. //The computer name
  194. _stprintf (szLineBuffer, TEXT("\nComputerName %s\r"), pId->szComputerName);
  195. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  196. //The user name
  197. _stprintf (szLineBuffer, TEXT("\nUserName %s\r"), pId->szUserName );
  198. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  199. //The domain name
  200. _stprintf (szLineBuffer, TEXT("\nDomainName %s\r"), pId->szUserDomain );
  201. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  202. //The System build.
  203. _stprintf (szLineBuffer, TEXT("\nSystemBuild %lu\r"), pId->dwSystemBuild);
  204. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  205. //The System build Delta
  206. _stprintf (szLineBuffer, TEXT("\nSystemBuildDelta %lu\r"), pId->dwSystemBuildDelta);
  207. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  208. //The SP build, same as above different name for backend.
  209. _stprintf (szLineBuffer, TEXT("\nSystemSPBuild %lu\r"), pId->dwSystemSPBuild);
  210. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  211. //The System build location name
  212. _stprintf (szLineBuffer, TEXT("\nSystemBuildLocation %s\r"), pId->szSystemBuildSourceLocation);
  213. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  214. //The Installing build.
  215. _stprintf (szLineBuffer, TEXT("\nInstallingBuild %lu\r"), pId->dwInstallingBuild);
  216. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  217. //The Installing build Delta
  218. _stprintf (szLineBuffer, TEXT("\nInstallingBuildDelta %lu\r"), pId->dwInstallingBuildDelta);
  219. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  220. //The Installing SP build, same as above but with different name for backend.
  221. _stprintf (szLineBuffer, TEXT("\nInstallingSPBuild %lu\r"), pId->dwInstallingSPBuild);
  222. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  223. //The Installing build location name
  224. _stprintf (szLineBuffer, TEXT("\nInstallingBuildLocation %s\r"), pId->szInstallingBuildSourceLocation);
  225. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  226. //The Machine Id.
  227. _stprintf (szLineBuffer, TEXT("\nMachineID %0.9lu\r"), pId->dwMachineID);
  228. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  229. //The Cdrom Bool
  230. _stprintf (szLineBuffer, TEXT("\nCdrom %s\r"), pId->bCdrom? TEXT("YES"): TEXT("NO"));
  231. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  232. //The Network Bool
  233. _stprintf (szLineBuffer, TEXT("\nNetwork %s\r"), pId->bNetwork? TEXT("YES"): TEXT("NO"));
  234. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  235. //The Type Bool
  236. _stprintf (szLineBuffer, TEXT("\nType %s\r"), pId->bClean? TEXT("CLEAN"): TEXT("UPGRADE"));
  237. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  238. // Check for MSI install
  239. _stprintf (szLineBuffer, TEXT("\nMsi %s\r"), pId->bMsi ? TEXT("YES"): TEXT("NO"));
  240. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  241. // Check for SP install type. We can have: uninstall, patch, or full.
  242. //
  243. if ( pId->bSPUninst ) {
  244. _stprintf (szLineBuffer, TEXT("\nSPMethod %s\r"), TEXT("REMOVE"));
  245. }
  246. if ( pId->bSPPatch ) {
  247. _stprintf (szLineBuffer, TEXT("\nSPMethod %s\r"), TEXT("PATCH"));
  248. }
  249. if ( pId->bSPFull ) {
  250. _stprintf (szLineBuffer, TEXT("\nSPMethod %s\r"), TEXT("FULL"));
  251. }
  252. if ( pId->bSPUpdate ) {
  253. _stprintf (szLineBuffer, TEXT("\nSPMethod %s\r"), TEXT("UPDATE"));
  254. }
  255. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  256. // Check for OEM Image
  257. //
  258. _stprintf (szLineBuffer, TEXT("\nOEMImage %s\r"), pId->bOEMImage? TEXT("YES"): TEXT("NO"));
  259. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  260. // Check for Sku
  261. _stprintf (szLineBuffer, TEXT("\nSku %lu\r"), pId->dwSku);
  262. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  263. // Write out the server.
  264. _stprintf (szLineBuffer, TEXT("\nIdwlogServer %s\r"), pId->szIdwlogServer);
  265. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  266. CloseHandle (hFile);
  267. }
  268. else{
  269. // wallyho:
  270. // Get the system drive and write the cookie file there.
  271. // originally it would write it in the SAVE_FILE and thats
  272. // always c:. If this fails say %SystemDrive% doesn't exist in
  273. // windows 9X (I don't know if it does?) then we'll default to c:
  274. Idwlog(TEXT("Writing the NO_BUILD_DATA cookie. So we know its not a CD BOOT INSTALL.\n"));
  275. if(FALSE == GetEnvironmentVariable(TEXT("SystemDrive"), szIdwlogCookieFile, 30))
  276. _stprintf(szIdwlogCookieFile,TEXT("c:"));
  277. _tcscat(szIdwlogCookieFile,TEXT("\\idwlog.cookie"));
  278. hFile = CreateFile (szIdwlogCookieFile,
  279. GENERIC_WRITE,
  280. 0,
  281. NULL,
  282. CREATE_ALWAYS,
  283. FILE_ATTRIBUTE_HIDDEN,
  284. NULL );
  285. if (hFile == INVALID_HANDLE_VALUE){
  286. OutputDebugString ("Unable to write idwlog.cookie file.\n");
  287. Idwlog(TEXT("Problem writing the idwlog.cookie file.\n\
  288. Returning without writing. Last Error %lu\n"), GetLastError());
  289. return FALSE;
  290. }
  291. /*
  292. New format for the no BLD idwlog.cookie file.
  293. NO_BUILD_DATA
  294. */
  295. // Write into idwlog.cookie
  296. ZeroMemory((LPTSTR)szLineBuffer,MAX_PATH);
  297. // The A file to show no build occured.
  298. _tcscpy(szLineBuffer, TEXT("\nNO_BUILD_DATA\r"));
  299. WriteFile (hFile,(LPTSTR)szLineBuffer,_tcsclen(szLineBuffer)+1 , &dwNumWritten, NULL);
  300. CloseHandle (hFile);
  301. }
  302. return TRUE;
  303. }
  304. BOOL
  305. ReadIdwlogCookie( OUT LPINSTALL_DATA lpId)
  306. /*++
  307. Routine Description:
  308. This will get the install data from the idwlog cookie file.
  309. Arguments:
  310. Structure to hold all the data we have from the install.
  311. Return Value:
  312. TRUE for success.
  313. FALSE for non success.
  314. Author: Wally Ho (wallyho) Jan 31st, 2000
  315. --*/
  316. {
  317. FILE* fpOpenFile;
  318. TCHAR szLineBuffer[256];
  319. TCHAR szResponse[10];
  320. TCHAR szDontCare[50];
  321. BOOL b = TRUE;
  322. DWORD dw;
  323. /*
  324. If \idwlog.cookie exists, then use the data from here to
  325. create the file on the database. Otherwise ??
  326. Example idwlog.cookie
  327. ComputerName WALLYHO_DEV
  328. SystemBuild 2190
  329. SystemBuildDelta 30
  330. SystemBuildLocation Lab01_N.000219-2219
  331. InstallingBuild 2195
  332. InstallingBuildDelta 30
  333. InstallingBuildLocation Lab01_N.000219-2219
  334. MachineID 3212115354
  335. Cdrom YES|NO
  336. Network YES|NO
  337. Type CLEAN|UPGRADE
  338. Msi N
  339. SPMehthod
  340. OEMImage YES|NO
  341. IdwlogServer \\ntcore2\idwlog
  342. or
  343. NO_BUILD_DATA
  344. */
  345. fpOpenFile = OpenCookieFile();
  346. if (NULL == fpOpenFile){
  347. // Do something about not finding the cookie.
  348. Idwlog(TEXT("Could not find the Cookie file!! Err: %d\n"), GetLastError());
  349. // OutputDebugString (TEXT("Idwlog could not find cookie file\n"));
  350. //<Do some minimal task here. To alert? What? I'll think of later.>
  351. b = FALSE;
  352. }else{
  353. do {
  354. // we've found the cookie.
  355. // Get the line one after another.
  356. _fgetts(szLineBuffer, 256,fpOpenFile);
  357. Idwlog(TEXT("ReadIdwlogCookie: szLineBuffer=>>>%s<<<"), szLineBuffer );
  358. // NO_BUILD_DATA
  359. if (NULL != _tcsstr(szLineBuffer, TEXT("NO_BUILD_DATA"))){
  360. lpId->bFindBLDFile = FALSE;
  361. b = FALSE;
  362. }
  363. //ComputerName
  364. if (NULL != _tcsstr(szLineBuffer, TEXT("ComputerName")))
  365. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,lpId->szComputerName);
  366. //UserName
  367. if (NULL != _tcsstr(szLineBuffer, TEXT("UserName")))
  368. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,lpId->szUserName );
  369. //DomainName
  370. if (NULL != _tcsstr(szLineBuffer, TEXT("DomainName")))
  371. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,lpId->szUserDomain );
  372. //SystemBuild
  373. else if( NULL != _tcsstr (szLineBuffer, TEXT("SystemBuild ") )){
  374. _stscanf(szLineBuffer,TEXT("%s %lu"),szDontCare,&dw);
  375. lpId->dwSystemBuild = dw;
  376. dw = 0;
  377. }
  378. //SystemBuildDelta
  379. else if( NULL != _tcsstr (szLineBuffer, TEXT("SystemBuildDelta ") )){
  380. _stscanf(szLineBuffer,TEXT("%s %lu"),szDontCare, &dw);
  381. lpId->dwSystemBuildDelta = dw;
  382. dw = 0;
  383. }
  384. //SystemSPBuild
  385. else if( NULL != _tcsstr (szLineBuffer, TEXT("SystemSPBuild ") )){
  386. _stscanf(szLineBuffer,TEXT("%s %lu"),szDontCare, &dw);
  387. lpId->dwSystemSPBuild = dw;
  388. dw = 0;
  389. }
  390. //SystemBuildLocation
  391. else if( NULL != _tcsstr (szLineBuffer, TEXT("SystemBuildLocation ") ))
  392. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,lpId->szSystemBuildSourceLocation);
  393. //InstallingBuild
  394. else if( NULL != _tcsstr (szLineBuffer, TEXT("InstallingBuild ") )){
  395. _stscanf(szLineBuffer,TEXT("%s %lu"),szDontCare,&dw);
  396. lpId->dwInstallingBuild = dw;
  397. dw = 0;
  398. }
  399. //InstallingBuildDelta
  400. else if( NULL != _tcsstr (szLineBuffer, TEXT("InstallingBuildDelta") )){
  401. _stscanf(szLineBuffer,TEXT("%s %lu"),szDontCare,&dw);
  402. lpId->dwInstallingBuildDelta = dw;
  403. dw = 0;
  404. }
  405. //InstallingSPBuild
  406. else if( NULL != _tcsstr (szLineBuffer, TEXT("InstallingSPBuild") )){
  407. _stscanf(szLineBuffer,TEXT("%s %lu"),szDontCare,&dw);
  408. lpId->dwInstallingSPBuild = dw;
  409. dw = 0;
  410. }
  411. //InstallingBuildLocation
  412. else if( NULL != _tcsstr (szLineBuffer, TEXT("InstallingBuildLocation") ))
  413. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,lpId->szInstallingBuildSourceLocation);
  414. // MachineID
  415. else if(NULL != _tcsstr(szLineBuffer, TEXT("MachineID"))){
  416. _stscanf(szLineBuffer,TEXT("%s %lu"),szDontCare,&dw);
  417. lpId->dwMachineID = dw;
  418. dw = 0;
  419. }
  420. // Sku
  421. else if(NULL != _tcsstr(szLineBuffer, TEXT("Sku"))){
  422. _stscanf(szLineBuffer,TEXT("%s %lu"),szDontCare,&dw);
  423. lpId->dwSku = dw;
  424. dw = 0;
  425. }
  426. // Get the server. This prevents server serparation.
  427. else if(NULL != _tcsstr(szLineBuffer, TEXT("IdwlogServer")))
  428. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,lpId->szIdwlogServer);
  429. // Cdrom
  430. else if(NULL != _tcsstr(szLineBuffer, TEXT("Cdrom"))){
  431. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,szResponse);
  432. if(szResponse[0] == TEXT('Y'))
  433. lpId->bCdrom = TRUE;
  434. else
  435. lpId->bCdrom = FALSE;
  436. }
  437. // Network
  438. else if(NULL != _tcsstr(szLineBuffer, TEXT("Network"))){
  439. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,szResponse);
  440. if(szResponse[0] == TEXT('Y'))
  441. lpId->bNetwork = TRUE;
  442. else
  443. lpId->bNetwork = FALSE;
  444. }
  445. // Type
  446. else if(NULL != _tcsstr(szLineBuffer, TEXT("Type"))){
  447. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,szResponse);
  448. if(szResponse[0] == TEXT('C')){
  449. lpId->bClean = TRUE;
  450. lpId->bUpgrade = FALSE;
  451. }
  452. else{
  453. lpId->bClean = FALSE;
  454. lpId->bUpgrade = TRUE;
  455. }
  456. }
  457. // Msi
  458. else if(NULL != _tcsstr(szLineBuffer, TEXT("Msi"))){
  459. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,szResponse);
  460. if(szResponse[0] == TEXT('Y'))
  461. lpId->bMsi = TRUE;
  462. else
  463. lpId->bMsi = FALSE;
  464. }
  465. // SP Method (of install)
  466. //
  467. else {
  468. Idwlog(TEXT("compare: >>>%s<<<\n"), szLineBuffer );
  469. if( _tcsstr(szLineBuffer, TEXT("SPMethod"))){
  470. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,szResponse);
  471. if(szResponse[0] == TEXT('R')) // uninstall/remove
  472. lpId->bSPUninst = TRUE;
  473. else
  474. lpId->bSPUninst = FALSE;
  475. if(szResponse[0] == TEXT('P')) // patch
  476. lpId->bSPPatch = TRUE;
  477. else
  478. lpId->bSPPatch = FALSE;
  479. if(szResponse[0] == TEXT('F')) // full (winnt32)
  480. lpId->bSPFull = TRUE;
  481. else
  482. lpId->bSPFull = FALSE;
  483. if(szResponse[0] == TEXT('U')) // update
  484. lpId->bSPUpdate = TRUE;
  485. else
  486. lpId->bSPUpdate = FALSE;
  487. Idwlog(TEXT("read-in values: bSPUninst = %d, bSPPatch = %d, bSPFull = %d, bSPUpdate = %d\n"), lpId->bSPUninst, lpId->bSPPatch, lpId->bSPFull, lpId->bSPUpdate );
  488. }
  489. // OEMImage
  490. else if(NULL != _tcsstr(szLineBuffer, TEXT("OEMImage"))){
  491. _stscanf(szLineBuffer,TEXT("%s %s"),szDontCare,szResponse);
  492. if(szResponse[0] == TEXT('Y'))
  493. lpId->bOEMImage = TRUE;
  494. else
  495. lpId->bOEMImage = FALSE;
  496. }
  497. }
  498. } while( 0 == feof(fpOpenFile) );
  499. CloseCookieFile( fpOpenFile );
  500. }
  501. return b;
  502. }
  503. BOOL
  504. ServerWriteMinimum (LPINSTALL_DATA pId,
  505. LPMACHINE_DETAILS pMd)
  506. /*++
  507. Author: Wally Ho (wallyho) Jan 31st, 2000
  508. Routine Description:
  509. This writes a *.2 file when we cannot find a *.1.
  510. There isn't any data in this one as its only the
  511. title we care about build and machine. This should
  512. catch all the CD installs that don't have a *.1 file written.
  513. Ie. Its run from setuploader.
  514. Arguments:
  515. Return Value:
  516. NONE
  517. --*/
  518. {
  519. //TCHAR szServerData[4096];
  520. BOOL bReturn;
  521. Idwlog(TEXT("Entered ServerWriteMinimum.\n"));
  522. GetNTSoundInfo(pMd);
  523. // If we are doing an OEMImage, we NEVER want to say that it was from a CDBOOT.
  524. //
  525. if ( pId->bOEMImage ) {
  526. // OEMImage
  527. //
  528. _stprintf (g_szServerData, TEXT("OEMImage:YES\r\n") );
  529. }
  530. else {
  531. // CDBootInstall
  532. //
  533. _stprintf (g_szServerData,
  534. TEXT("CDBootInstall:%s\r\n"),
  535. pId->bCDBootInstall? TEXT("YES") : TEXT("NO"));
  536. // OEMImage
  537. //
  538. _stprintf (g_szServerData+_tcsclen(g_szServerData), TEXT("OEMImage:NO\r\n") );
  539. }
  540. // Installed Build
  541. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  542. TEXT("InstallingBuild:%lu\r\n"), pId->dwInstallingBuild);
  543. // Installed Build Major
  544. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  545. TEXT("InstallingBuildMajor:%lu\r\n"), pId->dwInstallingMajorVersion);
  546. // Installed Build Minor
  547. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  548. TEXT("InstallingBuildMinor:%lu\r\n"), pId->dwInstallingMinorVersion);
  549. // Installed Build Delta
  550. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  551. TEXT("InstallingBuildDelta:%lu\r\n"), pId->dwInstallingBuildDelta);
  552. // same as above but different name for backend
  553. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  554. TEXT("InstallingSPBuild:%lu\r\n"), pId->dwInstallingSPBuild);
  555. // Installed Build Location
  556. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  557. TEXT("InstallingBuildLocation:%s\r\n"), pId->szInstallingBuildSourceLocation);
  558. // MachineId
  559. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  560. TEXT("MachineID:%0.9lu\r\n"), pId->dwMachineID);
  561. //UserName
  562. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  563. TEXT("Username:%s\r\n"),pId->szUserName);
  564. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  565. TEXT("Platform:%s\r\n"),pId->szPlatform);
  566. // Ram
  567. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  568. TEXT("RAM:%lu\r\n"),pMd->dwPhysicalRamInMB);
  569. // Architeture
  570. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  571. TEXT("Arch:%s\r\n"), pId->szArch);
  572. // Num Processors
  573. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  574. TEXT("NumProcs:%lu\r\n"), pMd->dwNumberOfProcessors);
  575. // Video Information
  576. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  577. TEXT("Vidinfo:%s\r\n"),pMd->szVideoInfo);
  578. // Display Name
  579. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  580. TEXT("VidDriver:%s\r\n"), pMd->szVideoDisplayName);
  581. // Locale
  582. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  583. TEXT("Locale:%s\r\n"), pId->szLocaleId );
  584. // Sound Card
  585. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  586. TEXT("Sound:%s\r\n"),
  587. pMd->iNumWaveOutDevices? pMd->szWaveDriverName[0] : TEXT("NONE")
  588. );
  589. // Network Cards.
  590. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  591. TEXT("NetCards:%s\r\n"),pMd->szNetcards);
  592. // Is ACPI
  593. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  594. TEXT("ACPI:%d\r\n"),pMd->bACPI);
  595. //Is PcCard?
  596. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  597. TEXT("PCMCIA:%d\r\n"), pMd->bPCCard);
  598. // Stepping Level of the proccessor
  599. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  600. TEXT("CPU:%lu\r\n"), pMd->dwProcessorLevel);
  601. // Scsi
  602. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  603. TEXT("SCSI:%s\r\n"), pMd->szScsi);
  604. // Is Usb?
  605. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  606. TEXT("USB:%d\r\n"), pMd->bUSB);
  607. // Is Infrared?
  608. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  609. TEXT("Infrared:%d\r\n"),pMd->bIR);
  610. // Modem
  611. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  612. TEXT("Modem:%s\r\n"), pMd->szModem);
  613. // Is Hydra
  614. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  615. TEXT("Hydra:%d\r\n"), pId->bHydra);
  616. // Number of Displays
  617. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  618. TEXT("Displays:%d\r\n"), pMd->iNumDisplays);
  619. // Sku
  620. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  621. TEXT("Sku:%lu\r\n"),pId->dwSku);
  622. Idwlog(TEXT("pId->dwSku = %ld\n"), pId->dwSku);
  623. bReturn = WriteDataToAvailableServer(pId, g_szServerData);
  624. return bReturn;
  625. }
  626. BOOL
  627. ServerWriteMaximum (LPINSTALL_DATA pId,
  628. LPMACHINE_DETAILS pMd)
  629. /*++
  630. Author: Wally Ho (wallyho) Jan 31st, 2000
  631. Routine Description:
  632. This does the connection to the server machine and then
  633. uploads the file. This is the Maximal data case.
  634. Arguments:
  635. Return Value:
  636. TRUE for success and
  637. FALSE for 15 minute time out for servers. Try again when rebooting.
  638. --*/
  639. {
  640. //TCHAR g_szServerData[4096];
  641. BOOL bReturn;
  642. Idwlog(TEXT("Entered ServerWriteMaximum.\n"));
  643. //wsprintf only accepts 1k buffers.
  644. // Wallyho's Addition. I'm going to split it into separate
  645. // calls to make sure above is true. It also makes it easier
  646. // to read. :-)
  647. // OEMImage
  648. //
  649. if ( pId->bOEMImage ) {
  650. _stprintf (g_szServerData, TEXT("OEMImage:YES\r\n") );
  651. }
  652. else {
  653. _stprintf (g_szServerData, TEXT("OEMImage:NO\r\n") );
  654. }
  655. // MachineId
  656. _stprintf (g_szServerData,
  657. TEXT("MachineID:%0.9lu\r\n"), pId->dwMachineID);
  658. // System Build
  659. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  660. TEXT("SystemBuild:%lu\r\n"), pId->dwSystemBuild);
  661. // System Build Major
  662. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  663. TEXT("SystemBuildMajor:%lu\r\n"), pId->dwSystemMajorVersion);
  664. // System Build Minor
  665. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  666. TEXT("SystemBuildMinor:%lu\r\n"), pId->dwSystemMinorVersion);
  667. // System Build Delta
  668. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  669. TEXT("SystemBuildDelta:%lu\r\n"), pId->dwSystemBuildDelta);
  670. // same as above, but just different name for backend processing.
  671. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  672. TEXT("SystemSPBuild:%lu\r\n"), pId->dwSystemSPBuild);
  673. // System Build Location
  674. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  675. TEXT("SystemBuildLocation:%s\r\n"), pId->szSystemBuildSourceLocation);
  676. // Installed Build
  677. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  678. TEXT("InstallingBuild:%lu\r\n"), pId->dwInstallingBuild);
  679. // Installed Build Major
  680. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  681. TEXT("InstallingBuildMajor:%lu\r\n"), pId->dwInstallingMajorVersion);
  682. // Installed Build Minor
  683. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  684. TEXT("InstallingBuildMinor:%lu\r\n"), pId->dwInstallingMinorVersion);
  685. // Installed Build Delta
  686. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  687. TEXT("InstallingBuildDelta:%lu\r\n"), pId->dwInstallingBuildDelta);
  688. // same as above but different name for backend processing
  689. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  690. TEXT("InstallingSPBuild:%lu\r\n"), pId->dwInstallingSPBuild);
  691. // Installed Build Location
  692. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  693. TEXT("InstallingBuildLocation:%s\r\n"), pId->szInstallingBuildSourceLocation);
  694. // Source Media
  695. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  696. TEXT("Source Media:%s\r\n"),pId->bCdrom? TEXT("C"): TEXT("N"));
  697. // Upgrade
  698. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  699. TEXT("Type:%s\r\n"), pId->bUpgrade? TEXT("U"):TEXT("C"));
  700. // Sku
  701. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  702. TEXT("Sku:%lu\r\n"),pId->dwSku);
  703. //UserName
  704. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  705. TEXT("Username:%s\r\n"),pId->szUserName);
  706. // Ram
  707. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  708. TEXT("RAM:%lu\r\n"),pMd->dwPhysicalRamInMB);
  709. //PlatForm
  710. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  711. TEXT("Platform:%s\r\n"),pId->szPlatform);
  712. // Architeture
  713. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  714. TEXT("Arch:%s\r\n"), pId->szArch);
  715. // Num Processors
  716. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  717. TEXT("NumProcs:%lu\r\n"), pMd->dwNumberOfProcessors);
  718. // Video Information
  719. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  720. TEXT("Vidinfo:%s\r\n"),pMd->szVideoInfo);
  721. // Display Name
  722. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  723. TEXT("VidDriver:%s\r\n"), pMd->szVideoDisplayName);
  724. // Locale
  725. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  726. TEXT("Locale:%s\r\n"), pId->szLocaleId );
  727. // Sound Card
  728. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  729. TEXT("Sound:%s\r\n"),
  730. pMd->iNumWaveOutDevices? pMd->szWaveDriverName[0] : TEXT("NONE")
  731. );
  732. // Network Cards.
  733. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  734. TEXT("NetCards:%s\r\n"),pMd->szNetcards);
  735. // Is ACPI
  736. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  737. TEXT("ACPI:%d\r\n"),pMd->bACPI);
  738. //Is PcCard?
  739. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  740. TEXT("PCMCIA:%d\r\n"), pMd->bPCCard);
  741. // Stepping Level of the proccessor
  742. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  743. TEXT("CPU:%lu\r\n"), pMd->dwProcessorLevel);
  744. // Scsi
  745. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  746. TEXT("SCSI:%s\r\n"), pMd->szScsi);
  747. // Is Usb?
  748. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  749. TEXT("USB:%d\r\n"), pMd->bUSB);
  750. // Is Infrared?
  751. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  752. TEXT("Infrared:%d\r\n"),pMd->bIR);
  753. // Modem
  754. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  755. TEXT("Modem:%s\r\n"), pMd->szModem);
  756. // Is Hydra
  757. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  758. TEXT("Hydra:%d\r\n"), pId->bHydra);
  759. // Number of Displays
  760. _stprintf (g_szServerData+_tcsclen(g_szServerData),
  761. TEXT("Displays:%d\r\n"), pMd->iNumDisplays);
  762. // Is Msi?
  763. _stprintf (g_szServerData + _tcsclen(g_szServerData),
  764. TEXT("MSI:%s\r\n"), pId->bMsi? TEXT("Y") : TEXT("N") );
  765. // Is SP uninst ?
  766. if ( pId->bSPUninst ) {
  767. _stprintf (g_szServerData + _tcsclen(g_szServerData),
  768. TEXT("SPMethod:%s\r\n"), TEXT("REMOVE") );
  769. Idwlog(TEXT("ServerWriteMaximum - SPMethod:UNINSTALL\n"));
  770. }
  771. // Is SP Patching?
  772. if ( pId->bSPPatch ) {
  773. _stprintf (g_szServerData + _tcsclen(g_szServerData),
  774. TEXT("SPMethod:%s\r\n"), TEXT("PATCH") );
  775. Idwlog(TEXT("ServerWriteMaximum - SPMethod:PATCH\n"));
  776. }
  777. // Is SP Full ?
  778. if ( pId->bSPFull ) {
  779. _stprintf (g_szServerData + _tcsclen(g_szServerData),
  780. TEXT("SPMethod:%s\r\n"), TEXT("FULL") );
  781. Idwlog(TEXT("ServerWriteMaximum - SPMethod:FULL\n"));
  782. }
  783. // Is SP Update ?
  784. if ( pId->bSPUpdate ) {
  785. _stprintf (g_szServerData + _tcsclen(g_szServerData),
  786. TEXT("SPMethod:%s\r\n"), TEXT("UPDATE") );
  787. Idwlog(TEXT("ServerWriteMaximum - SPMethod:UPDATE\n"));
  788. }
  789. bReturn = WriteDataToAvailableServer(pId, g_szServerData);
  790. return bReturn;
  791. }
  792. BOOL
  793. WriteDataToAvailableServer (LPINSTALL_DATA pId,
  794. LPTSTR g_szServerData)
  795. /*++
  796. Author: Wally W. Ho (wallyho)
  797. Date: 5/22/2000
  798. Routine Description:
  799. This routines allows us to time out a write operation so that
  800. bad network access won't hold us up.
  801. Arguments:
  802. LPINSTALL_DATA pId
  803. LPTSTR g_szServerData
  804. Return Value:
  805. TRUE for success.
  806. FALSE for failure.
  807. --*/
  808. {
  809. DWORD dw;
  810. DWORD dwTimeOut;
  811. HANDLE hThrd;
  812. DWORD dwTimeOutInterval;
  813. DWORD dwExitCode;
  814. BOOL b;
  815. //____<Thread Probing >______________________________________________________________________
  816. // This will stop the probing after say 10 minutes of probing.
  817. // Or when it succeeds.
  818. #ifdef TTEST
  819. Idwlog(TEXT("Entered WriteDataToAvailableServer().\n"));
  820. pId->szServerData = g_szServerData;
  821. b = WriteThread ( pId );
  822. Idwlog(TEXT("Exiting WriteDataToAvailableServer() with b = %d.\n"), b );
  823. return ( b );
  824. #endif TTEST
  825. pId->szServerData = g_szServerData;
  826. hThrd = CreateThread(NULL,
  827. 0,
  828. (LPTHREAD_START_ROUTINE)WriteThread,
  829. (LPINSTALL_DATA) pId,
  830. 0,
  831. &dw);
  832. // This is in milli seconds so 10 * factor is 10 minutes.
  833. dwTimeOutInterval = 10 * (1000 * 60);
  834. dwTimeOut = WaitForSingleObject (hThrd, dwTimeOutInterval);
  835. // This means the server passed the timeout.
  836. if (dwTimeOut == WAIT_TIMEOUT){
  837. // Exit the thread
  838. if(FALSE == GetExitCodeThread(hThrd,&dwExitCode))
  839. Idwlog(TEXT("Failed to get the exit code for the write thread.\n"));
  840. else{
  841. //
  842. // Don't terminate the thread
  843. //
  844. //TerminateThread(hThrd, dwExitCode);
  845. Idwlog(TEXT("Timeout Write Thread: %lu \n"), hThrd);
  846. }
  847. Idwlog(TEXT("Tried all servers we are concluding after 10 minutes elapsed!.\n"));
  848. Idwlog(TEXT("Leaving shortcut, idwlog.exe and cookie available for next reboot.\n"));
  849. Idwlog(TEXT("Ending connection to server.\n"));
  850. //Leaving everything in place so that a reboot will catch this.
  851. CloseHandle (hThrd);
  852. return FALSE;
  853. }
  854. CloseHandle (hThrd);
  855. Idwlog(TEXT("Ending connection to server.\n"));
  856. return TRUE;
  857. //____<Thread Probing >______________________________________________________________________
  858. }
  859. DWORD WINAPI
  860. WriteThread(IN LPINSTALL_DATA pId)
  861. /*++
  862. Author: Wally W. Ho (wallyho)
  863. Date: 2/22/2000
  864. Routine Description:
  865. This routine finds the best server to write the data package to.
  866. Arguments:
  867. LPINSTALL_DATA
  868. Return Value:
  869. TRUE or FALSE as thread exit codes.
  870. --*/
  871. {
  872. BOOL bRet;
  873. UINT iAttempts;
  874. DWORD Actual;
  875. DWORD Size;
  876. BOOL bWrite = TRUE;
  877. HANDLE hWrite = INVALID_HANDLE_VALUE;
  878. TCHAR szInstallingBuild [20];
  879. TCHAR szIdwlogUniqueName [ MAX_PATH ];
  880. BOOL b;
  881. Idwlog(TEXT("Entered WriteThread().\n"));
  882. // Build the name for the file.
  883. // ie \\ntcore2\idwlog\computername2195.1
  884. if ( 0 == pId->dwInstallingBuild)
  885. _stprintf (szInstallingBuild, TEXT("latest"));
  886. else
  887. _stprintf (szInstallingBuild, TEXT("%lu"), pId->dwInstallingBuild);
  888. // In the 1st case we enter this routine with no known server.
  889. // In the second case we get the server from the cookie.
  890. // So we should try to see if that server works before
  891. // probing.
  892. if (TEXT('\0') == pId->szIdwlogServer[0])
  893. b = FALSE;
  894. else {
  895. SERVERS sb;
  896. _tcscpy(sb.szSvr, pId->szIdwlogServer );
  897. b = (BOOL) ServerOnlineThread( &sb);
  898. }
  899. // This is the retry Loop!>
  900. // We'll try the found server 5 times with 5 second spacing.
  901. // Then we'll query the server list again and try that server
  902. // Do until we get on pausing 1 second between
  903. #define NUM_TRIES 5
  904. Idwlog(TEXT("WriteThread - Starting retry loop.\n"));
  905. while (TRUE) {
  906. if ( FALSE == b ) {
  907. pId->bIsServerOnline = FALSE;
  908. iAttempts = 0;
  909. while (pId->bIsServerOnline == FALSE && iAttempts < NUM_TRIES) {
  910. Idwlog(TEXT("WriteThread - SERVER Attempt %d just before IsServerOnLine()\n"), iAttempts);
  911. IsServerOnline( pId );
  912. Idwlog(TEXT("WriteThread - after IsServerOnLine(), pId->bIsServerOnLine = %d\n"), pId->bIsServerOnline );
  913. // Wait for 2 seconds between server tries.
  914. Sleep( 2 * (1000) );
  915. iAttempts++;
  916. // We are going to end here if we can find all the servers in 5 tries.
  917. //
  918. if ( iAttempts >= NUM_TRIES ) {
  919. Idwlog(TEXT("WriteThread ERROR - After %d attempts, we are quitting since we coundn't find a Server.\n"), iAttempts);
  920. return (FALSE);
  921. }
  922. }
  923. Idwlog(TEXT("WriteThread - after the while loop.\n") );
  924. }else{
  925. Idwlog( TEXT("Server FOUND no probing attempted.\n") );
  926. pId->bIsServerOnline = TRUE;
  927. }
  928. // We've got a server!!
  929. // Add the server to the end of the datapackage.
  930. if ( pId->bIsServerOnline == TRUE ) {
  931. _stprintf (pId->szServerData + _tcslen(pId->szServerData),
  932. TEXT("IdwlogServer:%s\r\n"),pId->szIdwlogServer );
  933. // Make sure the file gets written.
  934. // Don't want stoppage by bandwidth constriction etc..
  935. // Make 3 hits on the same server.
  936. iAttempts = 0;
  937. bRet = FALSE;
  938. while (bRet == FALSE && iAttempts < 3) {
  939. _stprintf (szIdwlogUniqueName, TEXT("%s\\%s-%lu-%s.%d"),
  940. pId->szIdwlogServer,
  941. szInstallingBuild,
  942. pId->dwMachineID,
  943. pId->szComputerName,
  944. pId->iStageSequence);
  945. hWrite = CreateFile( szIdwlogUniqueName,
  946. GENERIC_WRITE,
  947. 0,
  948. NULL,
  949. CREATE_ALWAYS,
  950. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
  951. NULL );
  952. if (INVALID_HANDLE_VALUE != hWrite) {
  953. // We have a handle to a active server.
  954. // Upload the package.
  955. SetFilePointer( hWrite, 0, NULL, FILE_END );
  956. Size = _tcsclen( pId->szServerData );
  957. bRet = WriteFile( hWrite, pId->szServerData, Size, &Actual, NULL );
  958. if (FALSE == bRet) {
  959. Idwlog(TEXT("FILE Attempt %d: Writing data package to Servershare: %s failed! Last Error is %lu\n"),
  960. iAttempts + 1, pId->szIdwlogServer, GetLastError());
  961. }
  962. // Flush the buffers to make sure its all makes it to the drive.
  963. FlushFileBuffers(hWrite);
  964. // wait 3 seconds between attempts
  965. Sleep(3000);
  966. CloseHandle(hWrite );
  967. }else
  968. Idwlog(TEXT("FILE Attempt %d: Failed in trying to directly write the file: %s."),
  969. iAttempts + 1,
  970. szIdwlogUniqueName);
  971. iAttempts++;
  972. }
  973. if (FALSE == bRet && iAttempts >= 3 ) {
  974. Idwlog(TEXT("After %d FILE attempts, still could not write to Servershare: %s! Last Error is %lu.\n"),
  975. iAttempts, pId->szIdwlogServer, GetLastError());
  976. WhatErrorMessage(GetLastError());
  977. Idwlog(TEXT("We will try the same server a second time.\n"));
  978. Idwlog(TEXT("The servers will be enumerated again at 10 second intervals.\n"));
  979. // <At this point we could purge the file locally?>
  980. // Wait for 10 seconds between server tries.
  981. Sleep( 10 * ( 1000 ) );
  982. // Means server was not found. Try to find another server.
  983. // Get the Server that is online.
  984. pId->bIsServerOnline = FALSE;
  985. } else {
  986. Idwlog(TEXT("Writing data package to Servershare: %s Succeeded.\n"),
  987. pId->szIdwlogServer);
  988. break;
  989. }
  990. }
  991. b = FALSE;
  992. }
  993. // Delete all the known connections.
  994. DeleteIPCConnections();
  995. Idwlog(TEXT("Exiting WriteThread() with return of TRUE.\n"));
  996. return TRUE;
  997. }
  998. VOID
  999. DeleteIPCConnections( VOID )
  1000. /*++
  1001. Copyright (c) 2000, Microsoft.
  1002. Author: Wally W. Ho (wallyho)
  1003. Date: 12/5/2000
  1004. Routine Description:
  1005. This function will delete all the IPC$ NULL net authentications
  1006. Arguments:
  1007. NONE
  1008. Return Value:
  1009. NONE
  1010. --*/
  1011. {
  1012. TCHAR szRemoteName [MAX_PATH];
  1013. for (INT i = 0; i < sizeof(g_ServerBlock) / sizeof(SERVERS); i++){
  1014. // RemoteName is the server name alone without the share.
  1015. // pServerBlock->szSvr comes in as \\idwlog\idwlogwhstl
  1016. // make it idwlog only..
  1017. _tcscpy(szRemoteName, g_ServerBlock[i].szSvr);
  1018. *_tcsrchr(szRemoteName,TEXT('\\')) = TEXT('\0');
  1019. // make sure it always disconnnected
  1020. _tcscat(szRemoteName,TEXT("\\IPC$"));
  1021. WNetCancelConnection2( szRemoteName, 0, TRUE);
  1022. }
  1023. }
  1024. /*
  1025. //____<Below is Authentication with guest account probe>___________
  1026. // Setup the memory for the connection.
  1027. // Try This Connection then try the file probe.
  1028. // This will log us onto the service to make it work.
  1029. // RemoteName is the server name along without the share.
  1030. // szIdwlogServer comes in as \\idwlog\idwlogwhstl
  1031. // make is idwlog only..
  1032. _tcscpy(szRemoteName,pId->szIdwlogServer);
  1033. pRemoteName = szRemoteName;
  1034. pRemoteName = pRemoteName + 2;
  1035. l = pRemoteName;
  1036. //*_tcsrchr(pRemoteName,TEXT('\\')) = TEXT('\0');
  1037. Idwlog(TEXT("Remote name is %s.\n"), szRemoteName);
  1038. // if the drive is being used shut it down so we can use it.
  1039. // WNetCancelConnection2( DRIVE_LETTER_TO_SHARE, CONNECT_UPDATE_PROFILE, TRUE );
  1040. ZeroMemory( &NetResource, sizeof( NetResource ) );
  1041. NetResource.dwType = RESOURCETYPE_DISK ;
  1042. NetResource.lpLocalName = DRIVE_LETTER_TO_SHARE;
  1043. NetResource.lpRemoteName = szRemoteName;
  1044. NetResource.lpProvider = NULL;
  1045. _stprintf(szUserId,TEXT("%s\\guest"),szRemoteName);
  1046. // First, try to connect with the current user ID
  1047. if (NO_ERROR != ( dwError = WNetAddConnection2( &NetResource, NULL, NULL, 0 )) ){
  1048. Idwlog(TEXT("WNetAddConnection2 FAILED with ID = NULL and PWD = NULL.\n"));
  1049. // Second, try to connect with idwuser as user and pw.
  1050. if ( NO_ERROR != ( dwError = WNetAddConnection2( &NetResource, NULL, szUserId, 0 )) )
  1051. Idwlog(TEXT("WNetAddConnection2 FAILED using authentication credentials on %s. Error %lu.\n"),
  1052. pId->szIdwlogServer, dwError);
  1053. }
  1054. if ( NO_ERROR == dwError )
  1055. Idwlog(TEXT("WNetAddConnection2 successfully connected.\n"));
  1056. //____<Below is File probe>___________
  1057. // ie \\idwlog\idwlog\2195-MachineId-ComputerName.1
  1058. _stprintf (szIdwlogUniqueName, TEXT("%s\\%s-%lu-%s.%d"),
  1059. pId->szIdwlogServer,// DRIVE_LETTER_TO_SHARE,
  1060. szInstallingBuild,
  1061. pId->dwMachineID,
  1062. pId->szComputerName,
  1063. pId->iStageSequence);
  1064. hWrite = CreateFile( szIdwlogUniqueName,
  1065. GENERIC_WRITE,
  1066. 0,
  1067. NULL,
  1068. CREATE_ALWAYS,
  1069. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
  1070. NULL );
  1071. */
  1072. VOID
  1073. DeleteDatafile (LPINSTALL_DATA pId)
  1074. /*++
  1075. Copyright (c) 2000, Microsoft.
  1076. Author: Wally W. Ho (wallyho)
  1077. Date: 8/23/2000
  1078. Routine Description:
  1079. Deletes the file from the server if the user cancels it.
  1080. Arguments:
  1081. Data Structure.
  1082. Return Value:
  1083. NONE
  1084. --*/
  1085. {
  1086. TCHAR szFileToDelete[MAX_PATH];
  1087. TCHAR szInstallingBuild [20];
  1088. TCHAR szServerData[ 200 ];
  1089. HANDLE hWrite;
  1090. BOOL bRet;
  1091. DWORD dwActual;
  1092. /*
  1093. Wallyho: This isn't a trivial problem. Why?
  1094. Its because I've multithreaded the probing.
  1095. So we have to check if both the idwlog.exe is running
  1096. if so kill it.
  1097. If it writes the Idwlog Cookie then we know it finished.
  1098. So we have to stop it. The only way is to use a mutex.
  1099. Which we check. This is just a piece of memory that sits in
  1100. kernel space or simply its the global space of the computer.
  1101. We check if its there at the end if so we delete both the
  1102. cookie and the file off the server.
  1103. This is the best way I can think of to do this as we have no idea
  1104. where the file is being written.
  1105. Two cases occur:
  1106. 1. If the process writing the file has not finished.
  1107. We set a mutex in the cancel. Which this checks for.
  1108. If set we delete the file and the cookie.
  1109. 2. If the process writing the file is passed the last check
  1110. then we cannot delete the file in the first process.
  1111. We then read the cookie for the server.
  1112. We go to that server and delete the file.
  1113. Then we delete the cookie and finally the mutex.
  1114. */
  1115. //
  1116. // If there is no IdwlogServer data, there is nothing to delete
  1117. //
  1118. if (NULL == pId->szIdwlogServer ||
  1119. 0 != _tcsncmp(pId->szIdwlogServer, TEXT("\\\\"), 2)) {
  1120. return;
  1121. }
  1122. if ( 0 == pId->dwInstallingBuild)
  1123. _stprintf (szInstallingBuild, TEXT("latest"));
  1124. else
  1125. _stprintf (szInstallingBuild, TEXT("%lu"), pId->dwInstallingBuild);
  1126. // ie \\ntcore2\idwlog\2195-MachineId-Computername.1
  1127. _stprintf (szFileToDelete, TEXT("%s\\%s-%lu-%s.%d"),
  1128. pId->szIdwlogServer,
  1129. szInstallingBuild,
  1130. pId->dwMachineID,
  1131. pId->szComputerName,
  1132. pId->iStageSequence);
  1133. Idwlog(TEXT("File deleted is: %s"), szFileToDelete);
  1134. SetFileAttributes(szFileToDelete,FILE_ATTRIBUTE_NORMAL);
  1135. if (TRUE == FileExistsEx(szFileToDelete)) {
  1136. DeleteFile( szFileToDelete);
  1137. }
  1138. else{
  1139. szFileToDelete[_tcslen(szFileToDelete) -1] = TEXT('0');
  1140. // If we succeed in deleting the file, then don't write a 0.
  1141. //Create the *.0 file.
  1142. hWrite = CreateFile( szFileToDelete,
  1143. GENERIC_WRITE,
  1144. 0,
  1145. NULL,
  1146. CREATE_ALWAYS,
  1147. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
  1148. NULL );
  1149. if ( hWrite == INVALID_HANDLE_VALUE ) {
  1150. Idwlog(TEXT("Problems creating the %lu delete file."), pId->iStageSequence );
  1151. } else {
  1152. // Upgrade: This we need for the timeout in the 0 files
  1153. _stprintf ( szServerData,
  1154. TEXT("Type:%s\r\n"), pId->bUpgrade? TEXT("U"):TEXT("C"));
  1155. bRet = WriteFile( hWrite, szServerData, _tcsclen( szServerData ), &dwActual, NULL );
  1156. CloseHandle(hWrite);
  1157. }
  1158. }
  1159. }
  1160. BOOL
  1161. SetCancelMutex ( VOID )
  1162. /*++
  1163. Author: wallyho
  1164. Routine Description:
  1165. Arguments:
  1166. Return Value:
  1167. --*/
  1168. {
  1169. g_hCancelMutex = CreateMutex( NULL,TRUE, TEXT("IdwlogCancelMutex"));
  1170. if (g_hCancelMutex == NULL){
  1171. Idwlog(TEXT("Could not set mutex.\n"));
  1172. return FALSE;
  1173. }else{
  1174. Idwlog(TEXT("Mutex set.\n"));
  1175. return TRUE;
  1176. }
  1177. }
  1178. BOOL
  1179. ClearCancelMutex ( VOID )
  1180. /*++
  1181. Author: wallyho
  1182. Routine Description:
  1183. Arguments:
  1184. Return Value:
  1185. --*/
  1186. {
  1187. if (FALSE == ReleaseMutex(g_hCancelMutex)){
  1188. Idwlog(TEXT("Problems releasing cancel mutex.\n"));
  1189. return TRUE;
  1190. }
  1191. else{
  1192. Idwlog(TEXT("Released cancel mutex.\n"));
  1193. return FALSE;
  1194. }
  1195. }
  1196. BOOL
  1197. PauseForMutex(VOID )
  1198. /*++
  1199. Author: wallyho
  1200. Routine Description:
  1201. This checks a mutex by opening it. we put in the systems global space
  1202. or as better know the "kernel space". This way the separate processes
  1203. can synchronize and delete file in case of canceling.
  1204. Since we randomly find servers online we have no way of finding out
  1205. what is available or not. We will wait till the cookie is complete
  1206. and then we delete.
  1207. Arguments:
  1208. Return Value:
  1209. FALSE Immediately if we don't find the mutex.
  1210. FALSE after we wait for the mutex.
  1211. --*/
  1212. {
  1213. HANDLE hOpenMutex;
  1214. hOpenMutex = OpenMutex( MUTEX_ALL_ACCESS, FALSE, TEXT("IdwlogCancelMutex") );
  1215. if (hOpenMutex == NULL){
  1216. // Idwlog(TEXT("Mutex turned off already. Lets look for the cookie.\n"));
  1217. return FALSE;
  1218. }else{
  1219. Idwlog(TEXT("Have to wait on -1 to finish then completing cancel.\n"));
  1220. WaitForSingleObject(hOpenMutex,60000 /* Up to 1 minute wait*/);
  1221. Idwlog(TEXT("Finished waiting. Continuing....\n"));
  1222. return FALSE;
  1223. }
  1224. }
  1225. BOOL
  1226. SetInstanceMutex ( VOID )
  1227. /*++
  1228. Author: wallyho
  1229. Routine Description:
  1230. Arguments:
  1231. Return Value:
  1232. TRUE if exists.
  1233. --*/
  1234. {
  1235. g_hInstanceMutex = CreateMutex( NULL,TRUE, TEXT("IdwlogInstanceMutex"));
  1236. if (g_hInstanceMutex == NULL){
  1237. return FALSE;
  1238. }else{
  1239. if (ERROR_ALREADY_EXISTS == GetLastError())
  1240. return TRUE;
  1241. else
  1242. return FALSE;
  1243. }
  1244. }
  1245. BOOL
  1246. ClearInstanceMutex ( VOID )
  1247. /*++
  1248. Author: wallyho
  1249. Routine Description:
  1250. Arguments:
  1251. Return Value:
  1252. --*/
  1253. {
  1254. if (FALSE == ReleaseMutex(g_hInstanceMutex)){
  1255. Idwlog(TEXT("Problems releasing cancel mutex.\n"));
  1256. return TRUE;
  1257. }
  1258. else{
  1259. Idwlog(TEXT("Released cancel mutex.\n"));
  1260. return FALSE;
  1261. }
  1262. }
  1263. BOOL
  1264. FileExistsEx( IN LPTSTR szFileName)
  1265. /*++
  1266. Copyright (c) 2000, Microsoft.
  1267. Author: Wally W. Ho (wallyho)
  1268. Date: 8/7/2000
  1269. Routine Description:
  1270. This test the existence of a partially matching FileName.
  1271. Arguments:
  1272. NONE
  1273. Return Value:
  1274. SUCCESS TRUE
  1275. FAIL FALSE
  1276. --*/
  1277. {
  1278. HANDLE hFile = INVALID_HANDLE_VALUE;
  1279. WIN32_FIND_DATA W32FD;
  1280. hFile = FindFirstFile(szFileName, &W32FD);
  1281. if( INVALID_HANDLE_VALUE == hFile ){
  1282. return FALSE;
  1283. }else{
  1284. FindClose(hFile);
  1285. return TRUE;
  1286. }
  1287. }