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.

8601 lines
287 KiB

  1. /******************************************************************************
  2. Copyright(c) Microsoft Corporation
  3. Module Name:
  4. BootCfg.cpp
  5. Abstract:
  6. This file is intended to have the functionality for
  7. configuring, displaying, changing and deleting boot.ini
  8. settings for the local host or a remote system.
  9. Author:
  10. J.S.Vasu 17/1/2001
  11. Revision History:
  12. J.S.Vasu 17/1/2001 Localisation,function headers
  13. SanthoshM.B 10/2/2001 Added 64 bit functionality Code.
  14. J.S.Vasu 15/2/2001 Added the functionality of 32 bit and 64 bit acc to the DCR's.
  15. J.S.Vasu 5/10/2001 Fixed some RAID bugs.
  16. J.S.Vasu 26/11/2001 Fixed some Raid Bugs.
  17. ******************************************************************************/
  18. // Include files
  19. #include "pch.h"
  20. #include "resource.h"
  21. #include "BootCfg.h"
  22. #include "BootCfg64.h"
  23. #include <strsafe.h>
  24. DWORD ProcessCloneSwitch_IA64(DWORD argc, LPCWSTR argv[] );
  25. DWORD _cdecl _tmain( DWORD argc, LPCTSTR argv[] )
  26. /*++
  27. Routine description : Main function which calls all the other main functions depending on
  28. the option specified by the user.
  29. Arguments:
  30. [in] argc : argument count specified at the command prompt.
  31. [in] argv : arguments specified at the command prompt.
  32. Return Value : DWORD
  33. 0 : If the utility successfully performs the specified operation.
  34. 1 : If the utility is unsuccessful in performing the specified operation.
  35. --*/
  36. {
  37. // Declaring the main option switches as boolean values
  38. BOOL bUsage = FALSE ;
  39. BOOL bCopy = FALSE ;
  40. BOOL bQuery = FALSE ;
  41. BOOL bDelete = FALSE ;
  42. BOOL bRawString = FALSE ;
  43. DWORD dwExitcode = ERROR_SUCCESS;
  44. BOOL bTimeOut = FALSE ;
  45. BOOL bDefault = FALSE ;
  46. BOOL bDebug = FALSE ;
  47. BOOL bEms = FALSE ;
  48. BOOL bAddSw = FALSE ;
  49. BOOL bRmSw = FALSE ;
  50. BOOL bDbg1394 = FALSE ;
  51. BOOL bMirror = FALSE ;
  52. BOOL bList = FALSE ;
  53. BOOL bUpdate = FALSE ;
  54. BOOL bClone = FALSE ;
  55. DWORD result =0;
  56. TCHAR szServer[MAX_RES_STRING+1] = NULL_STRING ;
  57. if( 1 == argc )
  58. {
  59. #ifndef _WIN64
  60. if( FALSE == IsUserAdmin() )
  61. {
  62. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  63. ReleaseGlobals();
  64. return EXIT_FAILURE;
  65. }
  66. dwExitcode = QueryBootIniSettings( argc, argv );
  67. #else
  68. if( FALSE == IsUserAdmin() )
  69. {
  70. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_64 ));
  71. ReleaseGlobals();
  72. return EXIT_FAILURE;
  73. }
  74. dwExitcode = QueryBootIniSettings_IA64( argc, argv );
  75. #endif
  76. ReleaseGlobals();
  77. return dwExitcode;
  78. }
  79. // Call the preProcessOptions function to find out the option selected by the user
  80. dwExitcode = preProcessOptions( argc, argv, &bUsage, &bCopy, &bQuery, &bDelete,&bRawString,&bDefault,&bTimeOut,&bDebug,&bEms,&bAddSw,&bRmSw,&bDbg1394,&bMirror,&bList,&bUpdate,&bClone);
  81. if(dwExitcode == EXIT_FAILURE)
  82. {
  83. ReleaseGlobals();
  84. return dwExitcode;
  85. }
  86. //check out for non administrative user
  87. #ifndef _WIN64
  88. /*
  89. if( FALSE == IsUserAdmin() )
  90. {
  91. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  92. ReleaseGlobals();
  93. return EXIT_FAILURE;
  94. }
  95. */
  96. #else
  97. /* if( FALSE == IsUserAdmin() )
  98. {
  99. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_64 ));
  100. ReleaseGlobals();
  101. return EXIT_FAILURE;
  102. }
  103. */
  104. #endif
  105. // If BootIni.exe /?
  106. if( ( bUsage ==TRUE)&& ( bCopy==FALSE )&& (bQuery==FALSE)&&(bDelete==FALSE)&&(bRawString ==FALSE)
  107. &&(bDefault==FALSE)&&(bTimeOut==FALSE) && (bDebug==FALSE)&& (bEms==FALSE)&&(bAddSw==FALSE)
  108. &&(bRmSw==FALSE)&&( bDbg1394==FALSE )&&(bMirror== FALSE) && (bList==FALSE)&&(bUpdate == FALSE)&&(bClone==FALSE) )
  109. {
  110. #ifndef _WIN64
  111. /*
  112. //check whether he is administrator or not
  113. if( !IsUserAdmin() )
  114. {
  115. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  116. ReleaseGlobals();
  117. return EXIT_FAILURE;
  118. }
  119. */
  120. dwExitcode = displayMainUsage_X86();
  121. #else
  122. displayMainUsage_IA64();
  123. ReleaseGlobals();
  124. return EXIT_SUCCESS ;
  125. #endif
  126. }
  127. if(bRawString)
  128. {
  129. #ifndef _WIN64
  130. dwExitcode = AppendRawString(argc,argv);
  131. #else
  132. dwExitcode = RawStringOsOptions_IA64(argc,argv);
  133. #endif
  134. ReleaseGlobals();
  135. return dwExitcode;
  136. }
  137. // If BootIni.exe -copy option is selected
  138. if( bCopy )
  139. {
  140. #ifndef _WIN64
  141. dwExitcode = CopyBootIniSettings( argc, argv );
  142. #else
  143. dwExitcode = CopyBootIniSettings_IA64( argc, argv);
  144. #endif
  145. }
  146. // If BootIni.exe -delete option is selected
  147. if( bDelete )
  148. {
  149. #ifndef _WIN64
  150. dwExitcode = DeleteBootIniSettings( argc, argv );
  151. #else
  152. dwExitcode = DeleteBootIniSettings_IA64( argc, argv );
  153. #endif
  154. }
  155. // If BootIni.exe -query option is selected
  156. if( bQuery )
  157. {
  158. #ifndef _WIN64
  159. dwExitcode = QueryBootIniSettings( argc, argv );
  160. #else
  161. dwExitcode = QueryBootIniSettings_IA64( argc, argv );
  162. #endif
  163. }
  164. if(bTimeOut)
  165. {
  166. #ifndef _WIN64
  167. dwExitcode = ChangeTimeOut(argc,argv);
  168. #else
  169. dwExitcode = ChangeTimeOut_IA64(argc,argv);
  170. #endif
  171. }
  172. if(bDefault)
  173. {
  174. #ifndef _WIN64
  175. dwExitcode = ChangeDefaultOs(argc,argv);
  176. #else
  177. dwExitcode = ChangeDefaultBootEntry_IA64(argc,argv);
  178. #endif
  179. }
  180. if(bDebug )
  181. {
  182. #ifndef _WIN64
  183. dwExitcode = ProcessDebugSwitch( argc, argv );
  184. #else
  185. dwExitcode = ProcessDebugSwitch_IA64(argc,argv);
  186. #endif
  187. }
  188. if(bEms )
  189. {
  190. #ifndef _WIN64
  191. dwExitcode = ProcessEmsSwitch( argc, argv );
  192. #else
  193. dwExitcode = ProcessEmsSwitch_IA64(argc,argv);
  194. #endif
  195. }
  196. if(bAddSw )
  197. {
  198. #ifndef _WIN64
  199. dwExitcode = ProcessAddSwSwitch( argc, argv );
  200. #else
  201. dwExitcode = ProcessAddSwSwitch_IA64(argc,argv);
  202. #endif
  203. }
  204. if(bRmSw )
  205. {
  206. #ifndef _WIN64
  207. dwExitcode = ProcessRmSwSwitch( argc, argv );
  208. #else
  209. dwExitcode = ProcessRmSwSwitch_IA64( argc, argv );
  210. #endif
  211. }
  212. if (bDbg1394 )
  213. {
  214. #ifndef _WIN64
  215. dwExitcode = ProcessDbg1394Switch(argc,argv);
  216. #else
  217. dwExitcode = ProcessDbg1394Switch_IA64(argc,argv);
  218. #endif
  219. }
  220. if(bMirror)
  221. {
  222. #ifdef _WIN64
  223. dwExitcode = ProcessMirrorSwitch_IA64(argc,argv);
  224. #else
  225. ShowMessage(stderr,GetResString(IDS_MAIN_USAGE));
  226. dwExitcode = EXIT_FAILURE;
  227. #endif
  228. }
  229. if(bList)
  230. {
  231. #ifdef _WIN64
  232. dwExitcode = ProcessListSwitch_IA64(argc,argv);
  233. #else
  234. ShowMessage(stderr,GetResString(IDS_MAIN_USAGE));
  235. dwExitcode = EXIT_FAILURE;
  236. #endif
  237. }
  238. if(bUpdate)
  239. {
  240. #ifdef _WIN64
  241. dwExitcode = ProcessUpdateSwitch_IA64(argc,argv);
  242. #else
  243. ShowMessage(stderr,GetResString(IDS_MAIN_USAGE));
  244. dwExitcode = EXIT_FAILURE;
  245. #endif
  246. }
  247. if(bClone == TRUE )
  248. {
  249. #ifdef _WIN64
  250. dwExitcode = ProcessCloneSwitch_IA64(argc,argv);
  251. #else
  252. ShowMessage(stderr,GetResString(IDS_MAIN_USAGE));
  253. dwExitcode = EXIT_FAILURE;
  254. #endif
  255. }
  256. // exit with the appropriate return value if there is no problem
  257. ReleaseGlobals();
  258. return dwExitcode;
  259. }
  260. DWORD
  261. preProcessOptions( IN DWORD argc,
  262. IN LPCTSTR argv[],
  263. OUT PBOOL pbUsage,
  264. OUT PBOOL pbCopy,
  265. OUT PBOOL pbQuery,
  266. OUT PBOOL pbDelete,
  267. OUT PBOOL pbRawString,
  268. OUT PBOOL pbDefault,
  269. OUT PBOOL pbTimeOut,
  270. OUT PBOOL pbDebug,
  271. OUT PBOOL pbEms,
  272. OUT PBOOL pbAddSw,
  273. OUT PBOOL pbRmSw,
  274. OUT PBOOL pbDbg1394 ,
  275. OUT PBOOL pbMirror ,
  276. OUT PBOOL pbList ,
  277. OUT PBOOL pbUpdate,
  278. OUT PBOOL pbClone
  279. )
  280. /*++
  281. Routine Description : This function process the command line arguments passed
  282. to the utility.
  283. Arguments:
  284. [ in ] argc : Number of command line arguments
  285. [ in ] argv : Array containing command line arguments
  286. [ out ] pbUsage : Pointer to boolean variable which will indicate
  287. whether usage option is specified by the user.
  288. [ out ] pbCopy : Pointer to boolean variable which will indicate
  289. whether copy option is specified by the user.
  290. [ out ] pbQuery : Pointer to boolean variable which will indicate
  291. whether query option is specified by the user.
  292. [ out ] pbChange : Pointer to boolean variable which will indicate
  293. whether change option is specified by the user.
  294. [ out ] pbDelete : Pointer to boolean variable which will indicate
  295. whether delete option is specified by the user.
  296. [ out ] pbRawString : Pointer to the boolean indicating whether raw option
  297. is specified by the user.
  298. [ out ] pbDefault : Pointer to the boolean indicating whether default option
  299. is specified by the user.
  300. [ out ] pbTimeOut : Pointer to the boolean indicating whether timeout option
  301. is specified by the user.
  302. [ out ] pbDebug : Pointer to the boolean indicating whether debug option
  303. is specified by the user.
  304. [ out ] pbEms : Pointer to the boolean indicating whether ems option
  305. is specified by the user.
  306. [ out ] pbAddSw : Pointer to the boolean indicating whether Addsw option
  307. is specified by the user.
  308. [ out ] pbRmSw : Pointer to the boolean indicating whether rmsw option
  309. is specified by the user.
  310. [ out ] pbDbg1394 : Pointer to the boolean indicating whether dbg1394 option
  311. is specified by the user.
  312. [ out ] pbMirror : Pointer to the boolean indicating whether mirror option
  313. is specified by the user.
  314. Return Type : Bool
  315. A Bool value indicating EXIT_SUCCESS on success else
  316. EXIT_FAILURE on failure
  317. -*/
  318. {
  319. // Initialise a boolean variable bOthers to find out whether switches other
  320. // than the main swithces are selected by the user
  321. DWORD dwCount = 0;
  322. DWORD dwi = 0;
  323. TARRAY arrTemp = NULL;
  324. TCMDPARSER2 cmdOptions[17];
  325. PTCMDPARSER2 pcmdOption;
  326. BOOL bStatus = FALSE;
  327. // BOOL bOthers = FALSE;
  328. arrTemp = CreateDynamicArray();
  329. if( NULL == arrTemp )
  330. {
  331. SetLastError(E_OUTOFMEMORY);
  332. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  333. return EXIT_FAILURE;
  334. }
  335. // Populate the TCMDPARSER structure and pass the structure to the DoParseParam
  336. // function. DoParseParam function populates the corresponding variables depending
  337. // upon the command line input.
  338. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  339. //copy option
  340. pcmdOption = &cmdOptions[0];
  341. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  342. pcmdOption->pwszOptions = CMDOPTION_COPY;
  343. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  344. pcmdOption->dwCount = 1;
  345. pcmdOption->pValue = pbCopy;
  346. //query option
  347. pcmdOption = &cmdOptions[1];
  348. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  349. pcmdOption->pwszOptions = CMDOPTION_QUERY;
  350. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  351. pcmdOption->dwCount = 1;
  352. pcmdOption->pValue = pbQuery;
  353. //delete option
  354. pcmdOption = &cmdOptions[2];
  355. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  356. pcmdOption->pwszOptions = CMDOPTION_DELETE;
  357. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  358. pcmdOption->dwCount = 1;
  359. pcmdOption->pValue = pbDelete;
  360. //usage option
  361. pcmdOption = &cmdOptions[3];
  362. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  363. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  364. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  365. pcmdOption->dwFlags = CP2_USAGE;
  366. pcmdOption->dwCount = 1;
  367. pcmdOption->pValue = pbUsage;
  368. //raw option
  369. pcmdOption = &cmdOptions[4];
  370. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  371. pcmdOption->pwszOptions = CMDOPTION_RAW;
  372. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  373. pcmdOption->dwCount = 1;
  374. pcmdOption->pValue = pbRawString;
  375. //default os option
  376. pcmdOption = &cmdOptions[5];
  377. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  378. pcmdOption->pwszOptions = CMDOPTION_DEFAULTOS;
  379. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  380. pcmdOption->dwCount = 1;
  381. pcmdOption->pValue = pbDefault;
  382. // timeout option
  383. pcmdOption = &cmdOptions[6];
  384. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  385. pcmdOption->pwszOptions = CMDOPTION_TIMEOUT;
  386. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  387. pcmdOption->dwCount = 1;
  388. pcmdOption->pValue = pbTimeOut;
  389. //debug option
  390. pcmdOption = &cmdOptions[7];
  391. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  392. pcmdOption->pwszOptions = CMDOPTION_DEBUG;
  393. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  394. pcmdOption->dwCount = 1;
  395. pcmdOption->pValue = pbDebug;
  396. //ems option
  397. pcmdOption = &cmdOptions[8];
  398. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  399. pcmdOption->pwszOptions = CMDOPTION_EMS;
  400. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  401. pcmdOption->dwCount = 1;
  402. pcmdOption->pValue = pbEms;
  403. //addsw option
  404. pcmdOption = &cmdOptions[9];
  405. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  406. pcmdOption->pwszOptions = CMDOPTION_ADDSW;
  407. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  408. pcmdOption->dwCount = 1;
  409. pcmdOption->pValue = pbAddSw;
  410. //rmsw option
  411. pcmdOption = &cmdOptions[10];
  412. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  413. pcmdOption->pwszOptions = CMDOPTION_RMSW;
  414. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  415. pcmdOption->dwCount = 1;
  416. pcmdOption->pValue = pbRmSw;
  417. //dbg1394 option
  418. pcmdOption = &cmdOptions[11];
  419. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  420. pcmdOption->pwszOptions = CMDOPTION_DBG1394;
  421. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  422. pcmdOption->dwCount = 1;
  423. pcmdOption->pValue = pbDbg1394;
  424. //mirror option
  425. pcmdOption = &cmdOptions[12];
  426. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  427. pcmdOption->pwszOptions = CMDOPTION_MIRROR;
  428. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  429. pcmdOption->dwCount = 1;
  430. pcmdOption->pValue = pbMirror;
  431. //list option
  432. pcmdOption = &cmdOptions[13];
  433. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  434. pcmdOption->pwszOptions = CMDOPTION_LIST;
  435. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  436. pcmdOption->dwCount = 1;
  437. pcmdOption->pValue = pbList;
  438. //update option
  439. pcmdOption = &cmdOptions[14];
  440. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  441. pcmdOption->pwszOptions = CMDOPTION_UPDATE;
  442. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  443. pcmdOption->dwCount = 1;
  444. pcmdOption->pValue = pbUpdate;
  445. pcmdOption = &cmdOptions[14];
  446. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  447. pcmdOption->pwszOptions = CMDOPTION_UPDATE;
  448. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  449. pcmdOption->dwCount = 1;
  450. pcmdOption->pValue = pbUpdate;
  451. //clone
  452. pcmdOption = &cmdOptions[15];
  453. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  454. pcmdOption->pwszOptions = CMDOPTION_CLONE;
  455. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  456. pcmdOption->dwCount = 1;
  457. pcmdOption->pValue = pbClone ;
  458. //other options
  459. pcmdOption = &cmdOptions[16];
  460. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  461. pcmdOption->dwType = CP_TYPE_TEXT;
  462. pcmdOption->dwFlags = CP2_DEFAULT | CP2_MODE_ARRAY;
  463. pcmdOption->pValue = &arrTemp;
  464. // If there is an error while parsing, display "Invalid Syntax"
  465. // If more than one main option is selected, then display error message
  466. // If usage is specified for sub-options
  467. // If none of the options are specified
  468. bStatus = DoParseParam2( argc, argv, -1, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 );
  469. if ( !bStatus )
  470. {
  471. //ignore this error because a user might have specified main option and sub option
  472. //which gets FALSE by this function, do the validation here to determine
  473. //whether user has entered correct option or not
  474. //if bUsage is specified but error occurs means user entered some junk
  475. DestroyDynamicArray( &arrTemp);
  476. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL);
  477. return EXIT_FAILURE ;
  478. }
  479. DestroyDynamicArray( &arrTemp);
  480. //checking if the user has entered more than 1 option.
  481. if (*pbCopy)
  482. {
  483. dwCount++ ;
  484. }
  485. if (*pbQuery)
  486. {
  487. dwCount++ ;
  488. }
  489. if (*pbDelete)
  490. {
  491. dwCount++ ;
  492. }
  493. if (*pbRawString)
  494. {
  495. dwCount++ ;
  496. // Check if any of the other valid switches have been
  497. // given as an input to the raw string
  498. if( *pbTimeOut || *pbDebug || *pbAddSw
  499. ||*pbRmSw || *pbDbg1394 || *pbEms
  500. ||*pbDelete || *pbCopy || *pbQuery
  501. ||*pbDefault || *pbMirror || *pbList || *pbUpdate || *pbClone)
  502. {
  503. // Check wether the usage switch has been entered
  504. if( *pbUsage )
  505. {
  506. ShowMessage(stderr,GetResString(IDS_MAIN_USAGE));
  507. return ( EXIT_FAILURE );
  508. }
  509. // Check if the other option is specified after the
  510. // 'raw' option
  511. for( dwi = 0; dwi < argc; dwi++ )
  512. {
  513. if( StringCompare( argv[ dwi ], OPTION_RAW, TRUE, 0 ) == 0 )
  514. {
  515. if( (dwi+1) == argc )
  516. {
  517. ShowMessage(stderr,GetResString(IDS_MAIN_USAGE));
  518. return ( EXIT_FAILURE );
  519. }
  520. else if( argv[dwi + 1][0] != _T( '\"' ) )
  521. {
  522. ShowMessage(stderr,GetResString(IDS_MAIN_USAGE));
  523. return ( EXIT_FAILURE );
  524. }
  525. }
  526. }
  527. dwCount--;
  528. }
  529. }
  530. if (*pbDefault)
  531. {
  532. dwCount++ ;
  533. }
  534. if (*pbTimeOut)
  535. {
  536. dwCount++ ;
  537. }
  538. if (*pbDebug)
  539. {
  540. dwCount++ ;
  541. }
  542. if(*pbAddSw)
  543. {
  544. dwCount++ ;
  545. }
  546. if(*pbRmSw)
  547. {
  548. dwCount++ ;
  549. }
  550. if(*pbDbg1394)
  551. {
  552. dwCount++ ;
  553. }
  554. if(*pbEms)
  555. {
  556. dwCount++ ;
  557. }
  558. if(*pbMirror)
  559. {
  560. dwCount++ ;
  561. }
  562. if(*pbList)
  563. {
  564. dwCount++ ;
  565. }
  566. if(*pbUpdate)
  567. {
  568. dwCount++ ;
  569. }
  570. if(*pbClone)
  571. {
  572. dwCount++ ;
  573. }
  574. //display an error message if the user enters more than 1 main option
  575. //display an error message if the user enters 1 main option along with other junk
  576. //display an error message if the user does not enter any main option
  577. if( ( ( dwCount > 1 ) ) ||
  578. ( (*pbUsage) && !bStatus ) ||
  579. ( !(*pbCopy) && !(*pbQuery) && !(*pbDelete) && !(*pbUsage) && !(*pbRawString)&& !(*pbDefault)&&!(*pbTimeOut)&&!(*pbDebug)&& !( *pbEms)&& !(*pbAddSw)&& !(*pbRmSw)&& !(*pbDbg1394)&& !(*pbMirror) &&!(*pbUpdate) && !(*pbList)&& !(*pbClone) ) )
  580. {
  581. ShowMessage(stderr,GetResString(IDS_MAIN_USAGE));
  582. return ( EXIT_FAILURE );
  583. }
  584. //if usage is specified with some junk
  585. if( *pbUsage && dwCount <=0 && argc >= 3 )
  586. {
  587. ShowMessage(stderr,GetResString(IDS_MAIN_USAGE));
  588. return ( EXIT_FAILURE );
  589. }
  590. return ( EXIT_SUCCESS );
  591. }
  592. DWORD
  593. CopyBootIniSettings(
  594. IN DWORD argc,
  595. IN LPCTSTR argv[]
  596. )
  597. /*++
  598. Routine Description:
  599. This routine is to make another OS instance copy for which you
  600. can add switches.
  601. Arguments:
  602. [in] argc : Number of command line arguments
  603. [in] argv : Array containing command line arguments
  604. Return Value :
  605. DWORD
  606. --*/
  607. {
  608. HRESULT hr = S_OK;
  609. BOOL bCopy = FALSE ;
  610. BOOL bUsage = FALSE;
  611. FILE *stream = NULL;
  612. TARRAY arr = NULL;
  613. BOOL bRes = FALSE ;
  614. WCHAR szPath[MAX_STRING_LENGTH] = NULL_STRING;
  615. TCHAR szTmpPath[MAX_RES_STRING+1] = NULL_STRING ;
  616. DWORD dwNumKeys = 0;
  617. BOOL bNeedPwd = FALSE;
  618. BOOL bFlag = FALSE;
  619. WCHAR *szServer = NULL;
  620. WCHAR *szUser = NULL;
  621. WCHAR szPassword[MAX_RES_STRING+1] = NULL_STRING;
  622. WCHAR szDescription[FRIENDLY_NAME_LENGTH] = NULL_STRING;
  623. DWORD dwDefault = 0;
  624. DWORD dwLength = MAX_STRING_LENGTH1 ;
  625. LPCTSTR szToken = NULL ;
  626. DWORD dwRetVal = 0 ;
  627. BOOL bConnFlag = FALSE ;
  628. TCHAR szFriendlyName[255] = NULL_STRING ;
  629. LPCWSTR pwsz = NULL ;
  630. TCHAR newInstance[255] = NULL_STRING ;
  631. LPTSTR pszKey1 = NULL ;
  632. LPWSTR szPathOld = NULL;
  633. LPWSTR szFriendlyNameOld = NULL;
  634. LPWSTR szOsOptionsOld = NULL;
  635. TCHAR szTempBuf[MAX_RES_STRING+1] = NULL_STRING ;
  636. LPWSTR szFinalstr = NULL;
  637. TCMDPARSER2 cmdOptions[7];
  638. PTCMDPARSER2 pcmdOption;
  639. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  640. //copy * to szPassword
  641. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  642. //main option
  643. pcmdOption = &cmdOptions[0];
  644. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  645. pcmdOption->pwszOptions = CMDOPTION_COPY;
  646. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  647. pcmdOption->dwCount = 1;
  648. pcmdOption->pValue = &bCopy;
  649. //server option
  650. pcmdOption = &cmdOptions[1];
  651. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  652. pcmdOption->pwszOptions = SWITCH_SERVER;
  653. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  654. pcmdOption->dwType = CP_TYPE_TEXT;
  655. pcmdOption->dwCount = 1;
  656. //user option
  657. pcmdOption = &cmdOptions[2];
  658. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  659. pcmdOption->pwszOptions = SWITCH_USER;
  660. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  661. pcmdOption->dwType = CP_TYPE_TEXT;
  662. pcmdOption->dwCount = 1;
  663. //password option
  664. pcmdOption = &cmdOptions[3];
  665. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  666. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  667. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  668. pcmdOption->dwType = CP_TYPE_TEXT;
  669. pcmdOption->dwCount = 1;
  670. pcmdOption->pValue = szPassword;
  671. pcmdOption->dwLength= MAX_STRING_LENGTH;
  672. //description option
  673. pcmdOption = &cmdOptions[4];
  674. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  675. pcmdOption->pwszOptions = SWITCH_DESCRIPTION ;
  676. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_VALUE_TRIMINPUT;
  677. pcmdOption->dwType = CP_TYPE_TEXT;
  678. pcmdOption->dwCount = 1;
  679. pcmdOption->pValue = szDescription;
  680. pcmdOption->dwLength= FRIENDLY_NAME_LENGTH;
  681. //id usage
  682. pcmdOption = &cmdOptions[5];
  683. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  684. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  685. pcmdOption->dwFlags = CP2_USAGE;
  686. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  687. pcmdOption->dwCount = 1;
  688. pcmdOption->pValue = &bUsage;
  689. //default option
  690. pcmdOption = &cmdOptions[6];
  691. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  692. pcmdOption->pwszOptions = SWITCH_ID;
  693. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MANDATORY ;
  694. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  695. pcmdOption->dwCount = 1;
  696. pcmdOption->pValue = &dwDefault;
  697. SecureZeroMemory(szFriendlyName, sizeof( szFriendlyName) );
  698. // Parsing the copy option switches
  699. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  700. {
  701. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  702. return (EXIT_FAILURE);
  703. }
  704. szServer = cmdOptions[1].pValue;
  705. szUser = cmdOptions[2].pValue;
  706. if( NULL == szUser )
  707. {
  708. szUser = (WCHAR *)AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  709. if( NULL == szUser )
  710. {
  711. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  712. return (EXIT_FAILURE);
  713. }
  714. }
  715. TrimString( szServer, TRIM_ALL );
  716. TrimString( szUser, TRIM_ALL );
  717. //check if usage is specified with more than one option
  718. if( (TRUE == bUsage) && (argc > 3) )
  719. {
  720. ShowMessage(stderr,GetResString(IDS_COPY_USAGE));
  721. return ( EXIT_FAILURE );
  722. }
  723. //display an error message if the server is empty.
  724. if( (cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  725. {
  726. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  727. FreeMemory((LPVOID *)&szServer );
  728. FreeMemory((LPVOID *)&szUser );
  729. return EXIT_FAILURE ;
  730. }
  731. //display an error message if the user is empty.
  732. if((cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser, 0)==0 ))
  733. {
  734. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  735. FreeMemory((LPVOID *)&szServer );
  736. FreeMemory((LPVOID *)&szUser );
  737. return EXIT_FAILURE ;
  738. }
  739. //display error message if the username is entered with out a machine name
  740. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  741. {
  742. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  743. return EXIT_FAILURE ;
  744. }
  745. //display error message if the user enters password without entering username
  746. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  747. {
  748. ShowMessage(stderr, GetResString(IDS_PASSWD_BUT_NOUSER));
  749. return EXIT_FAILURE ;
  750. }
  751. //if usage is specified
  752. if(bUsage)
  753. {
  754. if( CheckSystemType(szServer) == EXIT_FAILURE )
  755. {
  756. FreeMemory((LPVOID *)&szServer );
  757. FreeMemory((LPVOID *)&szUser );
  758. return (EXIT_FAILURE);
  759. }
  760. displayCopyUsage_X86();
  761. FreeMemory((LPVOID *)&szServer );
  762. FreeMemory((LPVOID *)&szUser );
  763. return (EXIT_SUCCESS) ;
  764. }
  765. //check whether he is administrator or not
  766. if( IsLocalSystem(szServer) )
  767. {
  768. if( !IsUserAdmin() )
  769. {
  770. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  771. ReleaseGlobals();
  772. return EXIT_FAILURE;
  773. }
  774. }
  775. if(IsLocalSystem( szServer ) == FALSE )
  776. {
  777. // set the bNeedPwd to True or False .
  778. if ( cmdOptions[3].dwActuals != 0 &&
  779. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  780. {
  781. // user wants the utility to prompt for the password before trying to connect
  782. bNeedPwd = TRUE;
  783. }
  784. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  785. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  786. {
  787. // -s, -u is specified without password ...
  788. // utility needs to try to connect first and if it fails then prompt for the password
  789. bNeedPwd = TRUE;
  790. if ( szPassword != NULL )
  791. {
  792. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  793. }
  794. }
  795. }
  796. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  797. {
  798. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  799. {
  800. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  801. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  802. {
  803. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  804. FreeMemory((LPVOID *)&szServer );
  805. FreeMemory((LPVOID *)&szUser );
  806. return (EXIT_FAILURE);
  807. }
  808. StringCopy(szServer,szToken, SIZE_OF_ARRAY_IN_CHARS(szServer));
  809. }
  810. }
  811. //display warning message if local credentils are supplied
  812. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  813. {
  814. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  815. }
  816. //open the file pointer
  817. // of the boot.ini file if there is no error while establishing connection
  818. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  819. if(bFlag == EXIT_FAILURE)
  820. {
  821. SAFECLOSE(stream);
  822. SafeCloseConnection(szServer,bConnFlag);
  823. FreeMemory((LPVOID *)&szServer );
  824. FreeMemory((LPVOID *)&szUser );
  825. return (EXIT_FAILURE);
  826. }
  827. // Getting the keys of the Operating system section in the boot.ini file
  828. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  829. if(arr == NULL)
  830. {
  831. resetFileAttrib(szPath);
  832. SAFECLOSE(stream);
  833. SafeCloseConnection(szServer,bConnFlag);
  834. FreeMemory((LPVOID *)&szServer );
  835. FreeMemory((LPVOID *)&szUser );
  836. return (EXIT_FAILURE);
  837. }
  838. StringCopy(szTmpPath,szPath, SIZE_OF_ARRAY(szTmpPath));
  839. // Getting the total number of keys in the operating systems section
  840. dwNumKeys = DynArrayGetCount(arr);
  841. if((dwNumKeys >= MAX_BOOTID_VAL) )
  842. {
  843. ShowMessage(stderr,GetResString(IDS_MAX_BOOTID));
  844. resetFileAttrib(szPath);
  845. DestroyDynamicArray(&arr);
  846. SAFECLOSE(stream);
  847. SafeCloseConnection(szServer,bConnFlag);
  848. FreeMemory((LPVOID *)&szServer );
  849. FreeMemory((LPVOID *)&szUser );
  850. return (EXIT_FAILURE);
  851. }
  852. // Displaying error message if the number of keys is less than the OS entry
  853. // line number specified by the user
  854. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  855. {
  856. ShowMessage(stderr,GetResString(IDS_INVALID_BOOTID));
  857. resetFileAttrib(szPath);
  858. DestroyDynamicArray(&arr);
  859. SAFECLOSE(stream);
  860. SafeCloseConnection(szServer,bConnFlag);
  861. FreeMemory((LPVOID *)&szServer );
  862. FreeMemory((LPVOID *)&szUser );
  863. return (EXIT_FAILURE);
  864. }
  865. // Getting the key of the OS entry specified by the user
  866. if(arr != NULL)
  867. {
  868. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  869. pszKey1 = (LPWSTR)AllocateMemory((StringLength(pwsz, 0)+2)*sizeof(WCHAR) );
  870. if(pszKey1 == NULL)
  871. {
  872. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  873. resetFileAttrib(szPath);
  874. SAFECLOSE(stream);
  875. SafeCloseConnection(szServer,bConnFlag);
  876. FreeMemory((LPVOID *)&szServer );
  877. FreeMemory((LPVOID *)&szUser );
  878. return (EXIT_FAILURE);
  879. }
  880. StringCopy( pszKey1, pwsz, SIZE_OF_ARRAY_IN_CHARS(pszKey1) );
  881. //divide this for friendly name and boot options
  882. szPathOld = (LPWSTR)pszKey1;
  883. szFriendlyNameOld = wcschr( pszKey1, L'=');
  884. szFriendlyNameOld[0]=L'\0';
  885. szFriendlyNameOld++;
  886. szOsOptionsOld = wcsrchr( szFriendlyNameOld, L'"');
  887. szOsOptionsOld++;
  888. if(StringLengthW(szOsOptionsOld, 0) != 0)
  889. {
  890. //szOsOptionsOld++;
  891. szOsOptionsOld[0]=L'\0';
  892. szOsOptionsOld++;
  893. }
  894. dwLength = StringLength(pszKey1, 0)+StringLength(szFriendlyNameOld,0)+StringLength(szOsOptionsOld,0)+1;
  895. }
  896. else
  897. {
  898. resetFileAttrib(szPath);
  899. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  900. ShowMessage( stderr, ERROR_TAG);
  901. ShowLastError(stderr);
  902. SAFECLOSE(stream);
  903. DestroyDynamicArray(&arr);
  904. SafeCloseConnection(szServer,bConnFlag);
  905. FreeMemory((LPVOID *)&szServer );
  906. FreeMemory((LPVOID *)&szUser );
  907. return (EXIT_FAILURE);
  908. }
  909. // Copying the description specified by the user as the value of the new key.
  910. if(( cmdOptions[4].dwActuals == 0) )
  911. {
  912. TrimString2(szFriendlyNameOld, L"\"", TRIM_ALL);
  913. if( StringLengthW(szFriendlyNameOld,0) > 59 )
  914. {
  915. StringCopy( szTempBuf, szFriendlyNameOld,59 ); //67
  916. hr = StringCchPrintf(szFriendlyName,SIZE_OF_ARRAY(szFriendlyName),L"\"%s%s\"", GetResString(IDS_COPY_OF), szTempBuf);
  917. }
  918. else
  919. {
  920. hr = StringCchPrintf(szFriendlyName, SIZE_OF_ARRAY(szFriendlyName),L"\"%s%s\"", GetResString(IDS_COPY_OF), szFriendlyNameOld);
  921. }
  922. dwLength = StringLengthW(szPathOld, 0)+StringLengthW(szFriendlyName,0)+StringLengthW(szOsOptionsOld,0)+1;
  923. //End of Changes
  924. //check if total length is exceeded max length of entry
  925. if( dwLength > MAX_RES_STRING )
  926. {
  927. ShowMessage( stderr,GetResString(IDS_STRING_TOO_LONG));
  928. resetFileAttrib(szPath);
  929. SAFECLOSE(stream);
  930. SAFEFREE(pszKey1);
  931. DestroyDynamicArray(&arr);
  932. SafeCloseConnection(szServer,bConnFlag);
  933. FreeMemory((LPVOID *)&szServer );
  934. FreeMemory((LPVOID *)&szUser );
  935. return (EXIT_FAILURE);
  936. }
  937. }
  938. else
  939. {
  940. //check if total length is exceeded max length of entry
  941. if( dwLength-StringLengthW(szFriendlyNameOld, 0)+StringLengthW(szDescription, 0) > MAX_RES_STRING )
  942. {
  943. ShowMessage( stderr,GetResString(IDS_STRING_TOO_LONG));
  944. resetFileAttrib(szPath);
  945. SAFECLOSE(stream);
  946. SAFEFREE(pszKey1);
  947. DestroyDynamicArray(&arr);
  948. SafeCloseConnection(szServer,bConnFlag);
  949. FreeMemory((LPVOID *)&szServer );
  950. FreeMemory((LPVOID *)&szUser );
  951. return (EXIT_FAILURE);
  952. }
  953. StringCopy( szFriendlyName, TOKEN_SINGLEQUOTE, SIZE_OF_ARRAY(szFriendlyName) );
  954. TrimString( szDescription, TRIM_ALL );
  955. if( (StringLength(szDescription, 0) != 0) ) //||lstrcmp(szDescription,L" "))
  956. {
  957. StringConcat( szFriendlyName, szDescription, SIZE_OF_ARRAY(szFriendlyName) );
  958. }
  959. StringConcat( szFriendlyName, TOKEN_SINGLEQUOTE, SIZE_OF_ARRAY(szFriendlyName) );
  960. }
  961. StringCopy( newInstance, szPathOld, SIZE_OF_ARRAY(newInstance) );
  962. StringConcat( newInstance, TOKEN_EQUAL, SIZE_OF_ARRAY(newInstance));
  963. StringConcat( newInstance, szFriendlyName, SIZE_OF_ARRAY(newInstance));
  964. StringConcat( newInstance, L" ", SIZE_OF_ARRAY(newInstance));
  965. StringConcat( newInstance, szOsOptionsOld, SIZE_OF_ARRAY(newInstance) );
  966. //not needed any more
  967. SAFEFREE(pszKey1);
  968. DynArrayAppendString( arr, newInstance, StringLengthW(newInstance, 0) );
  969. if( EXIT_FAILURE == stringFromDynamicArray2(arr, &szFinalstr ) )
  970. {
  971. bRes = resetFileAttrib(szPath);
  972. SAFEFREE(szFinalstr);
  973. DestroyDynamicArray(&arr);
  974. SafeCloseConnection(szServer,bConnFlag);
  975. FreeMemory((LPVOID *)&szServer );
  976. FreeMemory((LPVOID *)&szUser );
  977. SAFECLOSE(stream);
  978. return(EXIT_FAILURE);
  979. }
  980. // Writing to the profile section with new key-value pair
  981. if( WritePrivateProfileSection(OS_FIELD, szFinalstr, szTmpPath) != 0 )
  982. {
  983. ShowMessageEx(stdout, 1, TRUE, GetResString(IDS_COPY_SUCCESS),dwDefault);
  984. bRes = resetFileAttrib(szPath);
  985. SAFEFREE(szFinalstr);
  986. DestroyDynamicArray(&arr);
  987. SafeCloseConnection(szServer,bConnFlag);
  988. FreeMemory((LPVOID *)&szServer );
  989. FreeMemory((LPVOID *)&szUser );
  990. SAFECLOSE(stream);
  991. return(bRes);
  992. }
  993. else
  994. {
  995. ShowMessage(stderr,GetResString(IDS_COPY_OS));
  996. resetFileAttrib(szPath);
  997. SAFEFREE(szFinalstr);
  998. DestroyDynamicArray(&arr);
  999. SafeCloseConnection(szServer,bConnFlag);
  1000. FreeMemory((LPVOID *)&szServer );
  1001. FreeMemory((LPVOID *)&szUser );
  1002. SAFECLOSE(stream);
  1003. return (EXIT_FAILURE);
  1004. }
  1005. // Closing the opened boot.ini file handl
  1006. SAFECLOSE(stream);
  1007. bRes = resetFileAttrib(szPath);
  1008. SAFEFREE(szFinalstr);
  1009. DestroyDynamicArray(&arr);
  1010. SafeCloseConnection(szServer,bConnFlag);
  1011. FreeMemory((LPVOID *)&szServer );
  1012. FreeMemory((LPVOID *)&szUser );
  1013. return (bRes);
  1014. }
  1015. DWORD
  1016. DeleteBootIniSettings( IN DWORD argc,
  1017. IN LPCTSTR argv[]
  1018. )
  1019. /*++
  1020. Routine Description:
  1021. This routine is to delete an OS entry from the Operating systems
  1022. section of Boot.ini file in the specified machine.
  1023. Arguments:
  1024. [in] argc : Number of command line arguments
  1025. [in] argv : Array containing command line arguments
  1026. Return Value :
  1027. DWORD
  1028. --*/
  1029. {
  1030. TARRAY arrKeyValue = NULL;
  1031. TARRAY arrBootIni = NULL;
  1032. BOOL bDelete = FALSE ;
  1033. BOOL bUsage = FALSE;
  1034. BOOL bRes = FALSE ;
  1035. DWORD dwInitialCount = 0;
  1036. LPTSTR szFinalStr = NULL_STRING;
  1037. WCHAR szPath[MAX_RES_STRING] = NULL_STRING ;
  1038. FILE *stream = NULL;
  1039. BOOL bNeedPwd = FALSE ;
  1040. BOOL bFlag = FALSE ;
  1041. LPWSTR szTemp = NULL;
  1042. WCHAR *szServer = NULL;
  1043. WCHAR *szUser = NULL;
  1044. WCHAR szPassword[MAX_STRING_LENGTH] = NULL_STRING;
  1045. DWORD dwDefault = 0;
  1046. LPCTSTR szToken = NULL ;
  1047. DWORD dwRetVal = 0 ;
  1048. BOOL bConnFlag = FALSE ;
  1049. DWORD dwI = 0 ;
  1050. TCHAR szRedirectBaudrate[MAX_RES_STRING+1] = NULL_STRING ;
  1051. TCHAR szBoot[MAX_RES_STRING+1] = NULL_STRING ;
  1052. DWORD dwSectionFlag = 0 ;
  1053. LPWSTR pToken = NULL;
  1054. BOOL bRedirect = FALSE;
  1055. LPWSTR szARCPath = NULL;
  1056. // Builiding the TCMDPARSER structure
  1057. TCMDPARSER2 cmdOptions[6];
  1058. PTCMDPARSER2 pcmdOption;
  1059. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  1060. //copy * to szPassword
  1061. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  1062. //main option
  1063. pcmdOption = &cmdOptions[0];
  1064. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1065. pcmdOption->pwszOptions = CMDOPTION_DELETE;
  1066. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  1067. pcmdOption->dwCount = 1;
  1068. pcmdOption->pValue = &bDelete;
  1069. pcmdOption = &cmdOptions[1];
  1070. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1071. pcmdOption->pwszOptions = SWITCH_SERVER;
  1072. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  1073. pcmdOption->dwType = CP_TYPE_TEXT;
  1074. pcmdOption->dwCount = 1;
  1075. pcmdOption = &cmdOptions[2];
  1076. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1077. pcmdOption->pwszOptions = SWITCH_USER;
  1078. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  1079. pcmdOption->dwType = CP_TYPE_TEXT;
  1080. pcmdOption->dwCount = 1;
  1081. pcmdOption = &cmdOptions[3];
  1082. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1083. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  1084. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  1085. pcmdOption->dwType = CP_TYPE_TEXT;
  1086. pcmdOption->dwCount = 1;
  1087. pcmdOption->pValue = szPassword;
  1088. pcmdOption->dwLength= MAX_STRING_LENGTH;
  1089. pcmdOption = &cmdOptions[4];
  1090. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1091. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  1092. pcmdOption->dwFlags = CP2_USAGE;
  1093. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  1094. pcmdOption->dwCount = 1;
  1095. pcmdOption->pValue = &bUsage;
  1096. pcmdOption = &cmdOptions[5];
  1097. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1098. pcmdOption->pwszOptions = SWITCH_ID;
  1099. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MANDATORY;
  1100. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  1101. pcmdOption->dwCount = 1;
  1102. pcmdOption->pValue = &dwDefault;
  1103. // Parsing the delete option switches
  1104. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  1105. {
  1106. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1107. return (EXIT_FAILURE);
  1108. }
  1109. szServer = cmdOptions[1].pValue;
  1110. szUser = cmdOptions[2].pValue;
  1111. if( NULL == szUser )
  1112. {
  1113. szUser = (LPWSTR) AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  1114. if( NULL == szUser )
  1115. {
  1116. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1117. return (EXIT_FAILURE);
  1118. }
  1119. }
  1120. TrimString( szServer, TRIM_ALL );
  1121. TrimString( szUser, TRIM_ALL );
  1122. //check if usage is specified with more than one option
  1123. if( (TRUE == bUsage) && (argc > 3) )
  1124. {
  1125. ShowMessage(stderr,GetResString(IDS_DELETE_USAGE));
  1126. return ( EXIT_FAILURE );
  1127. }
  1128. //display an error message if the server is empty.
  1129. if( (cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  1130. {
  1131. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  1132. FreeMemory((LPVOID *)&szServer );
  1133. FreeMemory((LPVOID *)&szUser );
  1134. return EXIT_FAILURE ;
  1135. }
  1136. //display an error message if the user is empty.
  1137. if((cmdOptions[2].dwActuals!=0)&&(StringLength(szUser, 0)==0 ))
  1138. {
  1139. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  1140. FreeMemory((LPVOID *)&szServer );
  1141. FreeMemory((LPVOID *)&szUser );
  1142. return EXIT_FAILURE ;
  1143. }
  1144. //display error message if the username is entered with out a machine name
  1145. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  1146. {
  1147. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  1148. ShowMessage(stderr,GetReason());
  1149. FreeMemory((LPVOID *)&szServer );
  1150. FreeMemory((LPVOID *)&szUser );
  1151. return EXIT_FAILURE ;
  1152. }
  1153. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  1154. {
  1155. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  1156. ShowMessage(stderr,GetReason());
  1157. FreeMemory((LPVOID *)&szServer );
  1158. FreeMemory((LPVOID *)&szUser );
  1159. return EXIT_FAILURE ;
  1160. }
  1161. //if usage is specified
  1162. if(bUsage)
  1163. {
  1164. if( CheckSystemType(szServer) == EXIT_FAILURE )
  1165. {
  1166. FreeMemory((LPVOID *)&szServer );
  1167. FreeMemory((LPVOID *)&szUser );
  1168. return (EXIT_FAILURE);
  1169. }
  1170. displayDeleteUsage_X86();
  1171. FreeMemory((LPVOID *)&szServer );
  1172. FreeMemory((LPVOID *)&szUser );
  1173. return (EXIT_SUCCESS) ;
  1174. }
  1175. //check whether he is administrator or not
  1176. if( IsLocalSystem(szServer) )
  1177. {
  1178. if( !IsUserAdmin() )
  1179. {
  1180. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  1181. ReleaseGlobals();
  1182. return EXIT_FAILURE;
  1183. }
  1184. }
  1185. //
  1186. //for setting the bNeedPwd
  1187. if(IsLocalSystem( szServer ) == FALSE )
  1188. {
  1189. // set the bNeedPwd to True or False .
  1190. if ( cmdOptions[3].dwActuals != 0 &&
  1191. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  1192. {
  1193. // user wants the utility to prompt for the password before trying to connect
  1194. bNeedPwd = TRUE;
  1195. }
  1196. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  1197. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  1198. {
  1199. // -s, -u is specified without password ...
  1200. // utility needs to try to connect first and if it fails then prompt for the password
  1201. bNeedPwd = TRUE;
  1202. if ( szPassword != NULL )
  1203. {
  1204. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  1205. }
  1206. }
  1207. }
  1208. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  1209. {
  1210. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  1211. {
  1212. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  1213. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  1214. {
  1215. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  1216. return (EXIT_FAILURE);
  1217. }
  1218. else
  1219. {
  1220. StringCopy(szServer,szToken, MAX_RES_STRING);
  1221. }
  1222. }
  1223. }
  1224. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser,0)!=0))
  1225. {
  1226. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  1227. }
  1228. // Establishing connection to the specified machine and getting the file pointer
  1229. // of the boot.ini file if there is no error while establishing connection
  1230. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag );
  1231. if(bFlag == EXIT_FAILURE)
  1232. {
  1233. SAFECLOSE(stream);
  1234. SafeCloseConnection(szServer,bConnFlag);
  1235. FreeMemory((LPVOID *)&szServer );
  1236. FreeMemory((LPVOID *)&szUser );
  1237. return (EXIT_FAILURE);
  1238. }
  1239. // Getting all the key-value pairs of the operating system into a dynamic
  1240. // array for manipulation.
  1241. arrKeyValue = getKeyValueOfINISection( szPath, OS_FIELD);
  1242. if(arrKeyValue == NULL)
  1243. {
  1244. resetFileAttrib(szPath);
  1245. SAFECLOSE(stream);
  1246. SafeCloseConnection(szServer,bConnFlag);
  1247. FreeMemory((LPVOID *)&szServer );
  1248. FreeMemory((LPVOID *)&szUser );
  1249. return (EXIT_FAILURE);
  1250. }
  1251. // Getting the total no: of key-value pairs in the operating system section.
  1252. dwInitialCount = DynArrayGetCount(arrKeyValue);
  1253. // Checking whether the given OS entry is valid or not. If the OS entry given
  1254. // is greater than the number of keys present, then display an error message
  1255. if( ( dwDefault <= 0 ) || ( dwDefault > dwInitialCount ) )
  1256. {
  1257. ShowMessage(stderr,GetResString(IDS_INVALID_BOOTID));
  1258. resetFileAttrib(szPath);
  1259. SAFECLOSE(stream);
  1260. DestroyDynamicArray(&arrKeyValue);
  1261. SafeCloseConnection(szServer,bConnFlag);
  1262. FreeMemory((LPVOID *)&szServer );
  1263. FreeMemory((LPVOID *)&szUser );
  1264. return (EXIT_FAILURE);
  1265. }
  1266. // If only one OS entry is present and if the user tries to delete the OS entry, then
  1267. // display an error message
  1268. if( 1 == dwInitialCount )
  1269. {
  1270. ShowMessage(stderr,GetResString(IDS_ONLY_ONE_OS));
  1271. resetFileAttrib(szPath);
  1272. SAFECLOSE(stream);
  1273. DestroyDynamicArray(&arrKeyValue);
  1274. SafeCloseConnection(szServer,bConnFlag);
  1275. FreeMemory((LPVOID *)&szServer );
  1276. FreeMemory((LPVOID *)&szUser );
  1277. return (EXIT_FAILURE);
  1278. }
  1279. if( (DWORD) StringLengthW(DynArrayItemAsString(arrKeyValue,dwDefault - 1), 0 ) > MAX_RES_STRING )
  1280. {
  1281. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH), MAX_RES_STRING);
  1282. resetFileAttrib(szPath);
  1283. DestroyDynamicArray(&arrKeyValue);
  1284. SAFECLOSE(stream);
  1285. SafeCloseConnection(szServer,bConnFlag);
  1286. FreeMemory((LPVOID *)&szServer );
  1287. FreeMemory((LPVOID *)&szUser );
  1288. return EXIT_FAILURE ;
  1289. }
  1290. //check before deleting this entry check if it contains /redirect switch or not
  1291. //this is because if it contains /redirect switch and any other other doesn't contains
  1292. //then we have to remove redirect port and baud rate from boot loader section
  1293. szTemp = (LPWSTR)DynArrayItemAsString(arrKeyValue,dwDefault - 1);
  1294. pToken = _tcsrchr(szTemp , L'"') ;
  1295. if(NULL== pToken)
  1296. {
  1297. ShowMessage(stderr,GetResString(IDS_NO_TOKENS));
  1298. resetFileAttrib(szPath);
  1299. DestroyDynamicArray(&arrBootIni);
  1300. DestroyDynamicArray(&arrKeyValue);
  1301. SAFECLOSE(stream);
  1302. SafeCloseConnection(szServer,bConnFlag);
  1303. FreeMemory((LPVOID *)&szServer );
  1304. FreeMemory((LPVOID *)&szUser );
  1305. return EXIT_FAILURE ;
  1306. }
  1307. pToken++;
  1308. StringCopy(szRedirectBaudrate,REDIRECT_SWITCH, SIZE_OF_ARRAY(szRedirectBaudrate));
  1309. CharLower(szRedirectBaudrate);
  1310. if( FindString(pToken,szRedirectBaudrate, 0) != 0)
  1311. {
  1312. bRedirect = TRUE ;
  1313. }
  1314. // Remove the OS entry specified by the user from the dynamic array
  1315. DynArrayRemove(arrKeyValue, dwDefault - 1);
  1316. //reform the ini section
  1317. if (stringFromDynamicArray2( arrKeyValue,&szFinalStr) == EXIT_FAILURE)
  1318. {
  1319. resetFileAttrib(szPath);
  1320. SAFECLOSE(stream);
  1321. DestroyDynamicArray(&arrKeyValue);
  1322. SafeCloseConnection(szServer,bConnFlag);
  1323. FreeMemory((LPVOID *)&szServer );
  1324. FreeMemory((LPVOID *)&szUser );
  1325. return (EXIT_FAILURE);
  1326. }
  1327. //check if it is default entry, if so retrieve the ARC path of first entry
  1328. if( 1 == dwDefault )
  1329. {
  1330. szTemp = (LPWSTR)DynArrayItemAsString( arrKeyValue, 0 );
  1331. szARCPath = (LPWSTR)AllocateMemory((StringLength(szTemp,0)+10)*sizeof(WCHAR));
  1332. if( NULL == szARCPath )
  1333. {
  1334. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  1335. resetFileAttrib(szPath);
  1336. SAFECLOSE(stream);
  1337. SAFEFREE(szFinalStr);
  1338. DestroyDynamicArray(&arrKeyValue);
  1339. SafeCloseConnection(szServer,bConnFlag);
  1340. FreeMemory((LPVOID *)&szServer );
  1341. FreeMemory((LPVOID *)&szUser );
  1342. }
  1343. StringCopy(szARCPath, szTemp, GetBufferSize(szARCPath)/sizeof(szARCPath) );
  1344. szTemp = wcstok(szARCPath, L"=");
  1345. }
  1346. // Writing to the profile section with new key-value pair
  1347. // If the return value is non-zero, then there is an error.
  1348. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  1349. {
  1350. ShowMessageEx(stdout,1, TRUE, GetResString(IDS_DEL_SUCCESS),dwDefault);
  1351. }
  1352. else
  1353. {
  1354. ShowMessage(stderr,GetResString(IDS_DELETE_OS));
  1355. resetFileAttrib(szPath);
  1356. SAFECLOSE(stream);
  1357. SAFEFREE(szFinalStr);
  1358. DestroyDynamicArray(&arrKeyValue);
  1359. SafeCloseConnection(szServer,bConnFlag);
  1360. FreeMemory((LPVOID *)&szServer );
  1361. FreeMemory((LPVOID *)&szUser );
  1362. FreeMemory((LPVOID *)&szARCPath );
  1363. return (EXIT_FAILURE);
  1364. }
  1365. //now change the default entry in the bootloader section if deleted entry is default entry
  1366. if( 1 == dwDefault )
  1367. {
  1368. if( WritePrivateProfileString( BOOTLOADERSECTION, KEY_DEFAULT, szARCPath,
  1369. szPath ) == 0 )
  1370. {
  1371. ShowMessage(stderr,GetResString(IDS_ERR_CHANGE));
  1372. resetFileAttrib(szPath);
  1373. SAFECLOSE(stream);
  1374. SAFEFREE(szFinalStr);
  1375. DestroyDynamicArray(&arrKeyValue);
  1376. SafeCloseConnection(szServer,bConnFlag);
  1377. FreeMemory((LPVOID *)&szServer );
  1378. FreeMemory((LPVOID *)&szUser );
  1379. FreeMemory((LPVOID *)&szARCPath );
  1380. return (EXIT_FAILURE);
  1381. }
  1382. FreeMemory((LPVOID *)&szARCPath );
  1383. }
  1384. //this is to ensure that redirect switch is not there in any entry other than deleted one
  1385. dwInitialCount = DynArrayGetCount(arrKeyValue);
  1386. bFlag = FALSE ;
  1387. for(dwI = 0 ;dwI < dwInitialCount ; dwI++ )
  1388. {
  1389. szTemp = (LPWSTR)DynArrayItemAsString(arrKeyValue,dwI);
  1390. pToken = _tcsrchr(szTemp , L'"') ;
  1391. if(NULL== pToken)
  1392. {
  1393. ShowMessage(stderr,GetResString(IDS_NO_TOKENS));
  1394. resetFileAttrib(szPath);
  1395. DestroyDynamicArray(&arrKeyValue);
  1396. SAFEFREE(szFinalStr);
  1397. SAFECLOSE(stream);
  1398. SafeCloseConnection(szServer,bConnFlag);
  1399. FreeMemory((LPVOID *)&szServer );
  1400. FreeMemory((LPVOID *)&szUser );
  1401. return EXIT_FAILURE ;
  1402. }
  1403. pToken++;
  1404. CharLower(szRedirectBaudrate);
  1405. if( FindString(pToken,szRedirectBaudrate, 0)!= 0 && (dwI != dwDefault -1) )
  1406. {
  1407. bFlag = TRUE ;
  1408. }
  1409. }
  1410. if(FALSE == bFlag && bRedirect)
  1411. {
  1412. // First check if the Redirect section is present and if so delete
  1413. // the section.
  1414. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  1415. if (dwSectionFlag == EXIT_FAILURE)
  1416. {
  1417. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1418. resetFileAttrib(szPath);
  1419. SAFECLOSE(stream);
  1420. SAFEFREE(szFinalStr);
  1421. DestroyDynamicArray(&arrBootIni);
  1422. SafeCloseConnection(szServer,bConnFlag);
  1423. FreeMemory((LPVOID *)&szServer );
  1424. FreeMemory((LPVOID *)&szUser );
  1425. return EXIT_FAILURE ;
  1426. }
  1427. //If the Redirect section is present then delete it.
  1428. if( StringLengthW(szBoot,0) != 0)
  1429. {
  1430. if(TRUE== deleteKeyFromINISection(KEY_REDIRECT,szPath,BOOTLOADERSECTION))
  1431. {
  1432. ShowMessage(stdout,GetResString(IDS_REDIRECT_REMOVED));
  1433. }
  1434. else
  1435. {
  1436. ShowMessage(stdout,GetResString(IDS_ERROR_REDIRECT_REMOVED));
  1437. SAFEFREE(szFinalStr);
  1438. SAFECLOSE(stream);
  1439. bRes = resetFileAttrib(szPath);
  1440. DestroyDynamicArray(&arrKeyValue);
  1441. DestroyDynamicArray(&arrBootIni);
  1442. SafeCloseConnection(szServer,bConnFlag);
  1443. FreeMemory((LPVOID *)&szServer );
  1444. FreeMemory((LPVOID *)&szUser );
  1445. }
  1446. }
  1447. // First check if the Redirect section is present and if so delete
  1448. // the section.
  1449. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,KEY_BAUDRATE,szBoot);
  1450. if (dwSectionFlag == EXIT_FAILURE)
  1451. {
  1452. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1453. SAFEFREE(szFinalStr);
  1454. SAFECLOSE(stream);
  1455. bRes = resetFileAttrib(szPath);
  1456. DestroyDynamicArray(&arrKeyValue);
  1457. DestroyDynamicArray(&arrBootIni);
  1458. SafeCloseConnection(szServer,bConnFlag);
  1459. FreeMemory((LPVOID *)&szServer );
  1460. FreeMemory((LPVOID *)&szUser );
  1461. return EXIT_FAILURE ;
  1462. }
  1463. // First check if the Redirection baudrate section is present and if so delete
  1464. // the section.
  1465. if(StringLengthW(szBoot, 0)!=0)
  1466. {
  1467. if(TRUE == deleteKeyFromINISection(KEY_BAUDRATE,szPath,BOOTLOADERSECTION))
  1468. {
  1469. ShowMessage(stdout,GetResString(IDS_BAUDRATE_REMOVED));
  1470. }
  1471. else
  1472. {
  1473. ShowMessage(stdout,GetResString(IDS_ERROR_BAUDRATE_REMOVED));
  1474. }
  1475. }
  1476. }
  1477. // Closing the boot.ini stream
  1478. SAFECLOSE(stream);
  1479. bRes = resetFileAttrib(szPath);
  1480. SAFEFREE(szFinalStr);
  1481. DestroyDynamicArray(&arrKeyValue);
  1482. DestroyDynamicArray(&arrBootIni);
  1483. SafeCloseConnection(szServer,bConnFlag);
  1484. FreeMemory((LPVOID *)&szServer );
  1485. FreeMemory((LPVOID *)&szUser );
  1486. return (bRes);
  1487. }
  1488. DWORD QueryBootIniSettings( DWORD argc, LPCTSTR argv[] )
  1489. /*++
  1490. Routine Description:
  1491. This routine is to display the current boot.ini file settings for
  1492. the specified system.
  1493. Arguments:
  1494. [in] argc : Number of command line arguments
  1495. [in] argv : Array containing command line arguments
  1496. Return Value :
  1497. DWORD
  1498. --*/
  1499. {
  1500. // File pointer pointing to the boot.ini file
  1501. TCOLUMNS ResultHeader[ MAX_COLUMNS ];
  1502. FILE *stream = NULL;
  1503. BOOL bQuery = FALSE ;
  1504. BOOL bUsage = FALSE;
  1505. BOOL bNeedPwd = FALSE ;
  1506. BOOL bVerbose = TRUE ;
  1507. TARRAY arrResults = NULL ;
  1508. TARRAY arrKeyValuePairs = NULL;
  1509. TARRAY arrBootLoader = NULL;
  1510. DWORD dwFormatType = 0;
  1511. BOOL bHeader = TRUE ;
  1512. DWORD dwLength = 0 ;
  1513. DWORD dwCnt = 0;
  1514. TCHAR szValue[255] = NULL_STRING ;
  1515. TCHAR szFriendlyName[MAX_STRING_LENGTH] = NULL_STRING;
  1516. TCHAR szValue1[255] = NULL_STRING ;
  1517. TCHAR szBootOptions[255] = TOKEN_NA ;
  1518. TCHAR szBootEntry[255] = TOKEN_NA ;
  1519. TCHAR szArcPath[255] = TOKEN_NA ;
  1520. TCHAR szTmpString[255] = TOKEN_NA ;
  1521. PTCHAR psztok = NULL ;
  1522. DWORD dwRow = 0;
  1523. DWORD dwCount = 0;
  1524. BOOL bRes = FALSE ;
  1525. BOOL bFlag = FALSE ;
  1526. DWORD dwIndex = 0 ;
  1527. DWORD dwLength1 = 0 ;
  1528. DWORD dwFinalLength = 0 ;
  1529. WCHAR *szServer = NULL;
  1530. WCHAR *szUser = NULL;
  1531. WCHAR szPassword[MAX_STRING_LENGTH] = NULL_STRING;
  1532. WCHAR szPath[MAX_RES_STRING+1] = NULL_STRING;
  1533. LPWSTR szResults[MAX_RES_STRING+1];
  1534. LPCWSTR szKeyName;
  1535. TCHAR szDisplay[MAX_RES_STRING+1] = NULL_STRING ;
  1536. DWORD dwSectionFlag = 0 ;
  1537. LPCTSTR szToken = NULL ;
  1538. DWORD dwRetVal= 0 ;
  1539. BOOL bConnFlag = FALSE ;
  1540. PTCHAR pszString = NULL ;
  1541. PTCHAR pszFriendlyName = NULL ;
  1542. TCHAR szFinalString[MAX_RES_STRING+1] = NULL_STRING ;
  1543. // Builiding the TCMDPARSER structure
  1544. TCMDPARSER2 cmdOptions[5];
  1545. PTCMDPARSER2 pcmdOption;
  1546. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  1547. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  1548. //main option
  1549. pcmdOption = &cmdOptions[0];
  1550. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1551. pcmdOption->pwszOptions = CMDOPTION_QUERY;
  1552. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  1553. pcmdOption->dwCount = 1;
  1554. pcmdOption->pValue = &bQuery;
  1555. //server option
  1556. pcmdOption = &cmdOptions[1];
  1557. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1558. pcmdOption->pwszOptions = SWITCH_SERVER;
  1559. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  1560. pcmdOption->dwType = CP_TYPE_TEXT;
  1561. pcmdOption->dwCount = 1;
  1562. //user option
  1563. pcmdOption = &cmdOptions[2];
  1564. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1565. pcmdOption->pwszOptions = SWITCH_USER;
  1566. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  1567. pcmdOption->dwType = CP_TYPE_TEXT;
  1568. pcmdOption->dwCount = 1;
  1569. //password option
  1570. pcmdOption = &cmdOptions[3];
  1571. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1572. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  1573. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  1574. pcmdOption->dwType = CP_TYPE_TEXT;
  1575. pcmdOption->dwCount = 1;
  1576. pcmdOption->pValue = szPassword;
  1577. pcmdOption->dwLength= MAX_STRING_LENGTH;
  1578. //usage option
  1579. pcmdOption = &cmdOptions[4];
  1580. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  1581. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  1582. pcmdOption->dwFlags = CP2_USAGE;
  1583. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  1584. pcmdOption->dwCount = 1;
  1585. pcmdOption->pValue = &bUsage;
  1586. // Parsing all the switches specified with -query option
  1587. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  1588. {
  1589. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1590. return (EXIT_FAILURE);
  1591. }
  1592. szServer = cmdOptions[1].pValue;
  1593. szUser = cmdOptions[2].pValue;
  1594. if( NULL == szUser )
  1595. {
  1596. szUser = (LPWSTR) AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  1597. if( NULL == szUser )
  1598. {
  1599. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1600. return (EXIT_FAILURE);
  1601. }
  1602. }
  1603. TrimString( szServer, TRIM_ALL );
  1604. TrimString( szUser, TRIM_ALL );
  1605. //check if usage is specified with more than one option
  1606. if( (TRUE == bUsage) && (argc > 3) )
  1607. {
  1608. ShowMessage(stderr,GetResString(IDS_QUERY_USAGE));
  1609. return ( EXIT_FAILURE );
  1610. }
  1611. //check for empty values of server
  1612. if((cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  1613. {
  1614. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  1615. FreeMemory((LPVOID *)&szServer );
  1616. FreeMemory((LPVOID *)&szUser );
  1617. return EXIT_FAILURE ;
  1618. }
  1619. //check for empty values of user
  1620. if( (cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser, 0)==0 ))
  1621. {
  1622. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  1623. FreeMemory((LPVOID *)&szServer );
  1624. FreeMemory((LPVOID *)&szUser );
  1625. return EXIT_FAILURE ;
  1626. }
  1627. //display error message if the username is entered without a machine name
  1628. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  1629. {
  1630. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  1631. FreeMemory((LPVOID *)&szServer );
  1632. FreeMemory((LPVOID *)&szUser );
  1633. return EXIT_FAILURE ;
  1634. }
  1635. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  1636. {
  1637. ShowMessage(stderr, GetResString(IDS_PASSWD_BUT_NOUSER));
  1638. FreeMemory((LPVOID *)&szServer );
  1639. FreeMemory((LPVOID *)&szUser );
  1640. return EXIT_FAILURE ;
  1641. }
  1642. // Displaying query usage if user specified -? with -query option
  1643. if( bUsage )
  1644. {
  1645. if( CheckSystemType(szServer) == EXIT_FAILURE )
  1646. {
  1647. FreeMemory((LPVOID *)&szServer );
  1648. FreeMemory((LPVOID *)&szUser );
  1649. return (EXIT_FAILURE);
  1650. }
  1651. displayQueryUsage();
  1652. FreeMemory((LPVOID *)&szServer );
  1653. FreeMemory((LPVOID *)&szUser );
  1654. return (EXIT_SUCCESS);
  1655. }
  1656. //check whether he is administrator or not
  1657. if( IsLocalSystem(szServer) )
  1658. {
  1659. if( !IsUserAdmin() )
  1660. {
  1661. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  1662. ReleaseGlobals();
  1663. return EXIT_FAILURE;
  1664. }
  1665. }
  1666. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  1667. {
  1668. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  1669. {
  1670. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  1671. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  1672. {
  1673. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  1674. FreeMemory((LPVOID *)&szServer );
  1675. FreeMemory((LPVOID *)&szUser );
  1676. return (EXIT_FAILURE);
  1677. }
  1678. StringCopy(szServer,szToken, MAX_STRING_LENGTH+1);
  1679. }
  1680. }
  1681. //
  1682. //for setting the bNeedPwd
  1683. if(IsLocalSystem( szServer ) == FALSE )
  1684. {
  1685. // set the bNeedPwd to True or False .
  1686. if ( cmdOptions[3].dwActuals != 0 &&
  1687. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  1688. {
  1689. // user wants the utility to prompt for the password before trying to connect
  1690. bNeedPwd = TRUE;
  1691. }
  1692. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  1693. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  1694. {
  1695. // -s, -u is specified without password ...
  1696. // utility needs to try to connect first and if it fails then prompt for the password
  1697. bNeedPwd = TRUE;
  1698. if ( szPassword != NULL )
  1699. {
  1700. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  1701. }
  1702. }
  1703. }
  1704. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  1705. {
  1706. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  1707. }
  1708. //set the default format as list
  1709. dwFormatType = SR_FORMAT_LIST;
  1710. //forms the header for the OS options
  1711. FormHeader(bHeader,ResultHeader,bVerbose);
  1712. //create dynamic array to hold the results for the BootOptions
  1713. arrResults = CreateDynamicArray();
  1714. //create dynamic array to hold the results for the BootLoader section
  1715. arrBootLoader = CreateDynamicArray();
  1716. if(arrResults == NULL || arrBootLoader == NULL)
  1717. {
  1718. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1719. SaveLastError();
  1720. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1721. FreeMemory((LPVOID *)&szServer );
  1722. FreeMemory((LPVOID *)&szUser );
  1723. return (EXIT_FAILURE);
  1724. }
  1725. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  1726. if(bFlag == EXIT_FAILURE)
  1727. {
  1728. SAFECLOSE(stream);
  1729. DestroyDynamicArray(&arrResults);
  1730. DestroyDynamicArray(&arrBootLoader);
  1731. SafeCloseConnection(szServer,bConnFlag);
  1732. FreeMemory((LPVOID *)&szServer );
  1733. FreeMemory((LPVOID *)&szUser );
  1734. return (EXIT_FAILURE);
  1735. }
  1736. //to store entries corresponding to Operating Systems sections
  1737. arrKeyValuePairs = getKeyValueOfINISection( szPath, OS_FIELD );
  1738. //to store entries corresponding to BootLoader section
  1739. arrBootLoader = getKeysOfINISection(szPath,BOOTLOADERSECTION);
  1740. if( (arrBootLoader == NULL)||(arrKeyValuePairs == NULL))
  1741. {
  1742. resetFileAttrib(szPath);
  1743. SAFECLOSE(stream);
  1744. DestroyDynamicArray(&arrResults);
  1745. DestroyDynamicArray(&arrBootLoader);
  1746. SafeCloseConnection(szServer,bConnFlag);
  1747. FreeMemory((LPVOID *)&szServer );
  1748. FreeMemory((LPVOID *)&szUser );
  1749. return (EXIT_FAILURE);
  1750. }
  1751. //getting the count of the number of boot entries
  1752. dwLength = DynArrayGetCount(arrKeyValuePairs);
  1753. for(dwCnt=0;dwCnt < dwLength;dwCnt++ )
  1754. {
  1755. dwRow = DynArrayAppendRow(arrResults,MAX_COLUMNS) ;
  1756. StringCopy(szFriendlyName,NULL_STRING, SIZE_OF_ARRAY(szFriendlyName));
  1757. StringCopy(szBootOptions,NULL_STRING, SIZE_OF_ARRAY(szBootOptions));
  1758. StringCopy(szTmpString,NULL_STRING, SIZE_OF_ARRAY(szTmpString));
  1759. if(arrKeyValuePairs != NULL)
  1760. {
  1761. LPCWSTR pwsz = NULL;
  1762. pwsz = DynArrayItemAsString( arrKeyValuePairs,dwCnt );
  1763. if(StringLengthW(pwsz, 0) > 254)
  1764. {
  1765. ShowMessage( stderr,GetResString(IDS_STRING_TOO_LONG));
  1766. SAFECLOSE(stream);
  1767. resetFileAttrib(szPath);
  1768. DestroyDynamicArray(&arrBootLoader);
  1769. DestroyDynamicArray(&arrKeyValuePairs);
  1770. DestroyDynamicArray(&arrResults);
  1771. SafeCloseConnection(szServer,bConnFlag);
  1772. FreeMemory((LPVOID *)&szServer );
  1773. FreeMemory((LPVOID *)&szUser );
  1774. return (EXIT_FAILURE);
  1775. }
  1776. if(pwsz != NULL)
  1777. {
  1778. StringCopy(szValue,pwsz, SIZE_OF_ARRAY(szValue));
  1779. StringCopy(szValue1,pwsz, SIZE_OF_ARRAY(szValue1));
  1780. }
  1781. else
  1782. {
  1783. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1784. ShowMessage( stderr, ERROR_TAG);
  1785. ShowLastError(stderr);
  1786. SAFECLOSE(stream);
  1787. resetFileAttrib(szPath);
  1788. DestroyDynamicArray(&arrBootLoader);
  1789. DestroyDynamicArray(&arrKeyValuePairs);
  1790. DestroyDynamicArray(&arrResults);
  1791. SafeCloseConnection(szServer,bConnFlag);
  1792. FreeMemory((LPVOID *)&szServer );
  1793. FreeMemory((LPVOID *)&szUser );
  1794. return (EXIT_FAILURE);
  1795. }
  1796. }
  1797. else
  1798. {
  1799. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1800. ShowMessage( stderr, ERROR_TAG);
  1801. ShowLastError(stderr);
  1802. SAFECLOSE(stream);
  1803. resetFileAttrib(szPath);
  1804. DestroyDynamicArray(&arrBootLoader);
  1805. DestroyDynamicArray(&arrResults);
  1806. if(NULL !=arrKeyValuePairs)
  1807. DestroyDynamicArray(&arrKeyValuePairs);
  1808. SafeCloseConnection(szServer,bConnFlag);
  1809. FreeMemory((LPVOID *)&szServer );
  1810. FreeMemory((LPVOID *)&szUser );
  1811. return (EXIT_FAILURE);
  1812. }
  1813. //Parse the string to obtain the Boot Path
  1814. psztok = wcschr(szValue,L'=');
  1815. if( NULL == psztok )
  1816. {
  1817. ShowMessage( stderr, GetResString(IDS_NO_TOKENS));
  1818. SAFECLOSE(stream);
  1819. resetFileAttrib(szPath);
  1820. DestroyDynamicArray(&arrBootLoader);
  1821. DestroyDynamicArray(&arrResults);
  1822. DestroyDynamicArray(&arrKeyValuePairs);
  1823. SafeCloseConnection(szServer,bConnFlag);
  1824. FreeMemory((LPVOID *)&szServer );
  1825. FreeMemory((LPVOID *)&szUser );
  1826. return (EXIT_FAILURE);
  1827. }
  1828. psztok[0]=0;
  1829. if(StringLength(szValue,0) != 0 )
  1830. {
  1831. StringCopy(szArcPath,szValue, SIZE_OF_ARRAY(szArcPath));
  1832. }
  1833. else
  1834. {
  1835. ShowMessage( stderr, GetResString(IDS_NO_TOKENS));
  1836. SAFECLOSE(stream);
  1837. resetFileAttrib(szPath);
  1838. DestroyDynamicArray(&arrBootLoader);
  1839. DestroyDynamicArray(&arrResults);
  1840. DestroyDynamicArray(&arrKeyValuePairs);
  1841. SafeCloseConnection(szServer,bConnFlag);
  1842. FreeMemory((LPVOID *)&szServer );
  1843. FreeMemory((LPVOID *)&szUser );
  1844. return (EXIT_FAILURE);
  1845. }
  1846. //get the friendly name
  1847. pszFriendlyName = DivideToken(szValue1,szFinalString);
  1848. if(pszFriendlyName == NULL)
  1849. {
  1850. ShowMessage( stderr, GetResString(IDS_NO_TOKENS));
  1851. SAFECLOSE(stream);
  1852. resetFileAttrib(szPath);
  1853. DestroyDynamicArray(&arrBootLoader);
  1854. DestroyDynamicArray(&arrResults);
  1855. DestroyDynamicArray(&arrKeyValuePairs);
  1856. SafeCloseConnection(szServer,bConnFlag);
  1857. FreeMemory((LPVOID *)&szServer );
  1858. FreeMemory((LPVOID *)&szUser );
  1859. return (EXIT_FAILURE);
  1860. }
  1861. pszString = _tcsrchr(szValue1,L'\"');
  1862. pszString++ ;
  1863. StringCopy(szTmpString,pszString, SIZE_OF_ARRAY(szTmpString));
  1864. TrimString(szTmpString,TRIM_ALL);
  1865. _ltow(dwCnt+1,szBootEntry,10);
  1866. DynArraySetString2( arrResults,dwRow ,COL0,szBootEntry,0 );
  1867. if(StringLengthW(pszFriendlyName, 0)==0)
  1868. {
  1869. pszFriendlyName=TOKEN_NA;
  1870. }
  1871. DynArraySetString2( arrResults,dwRow ,COL1,pszFriendlyName,0 );
  1872. DynArraySetString2(arrResults,dwRow,COL2,szArcPath,0);
  1873. if(StringLengthW(szTmpString, 0) != 0)
  1874. {
  1875. //lstrcat(szBootOptions,TOKEN_FWDSLASH1);
  1876. StringConcat(szBootOptions,szTmpString, SIZE_OF_ARRAY(szBootOptions));
  1877. }
  1878. else
  1879. {
  1880. StringCopy(szBootOptions,TOKEN_NA, SIZE_OF_ARRAY(szBootOptions));
  1881. }
  1882. DynArraySetString2( arrResults,dwRow ,COL3,szBootOptions,0 );
  1883. }
  1884. dwCount = DynArrayGetCount(arrBootLoader);
  1885. bFlag = TRUE;
  1886. // this loop is for getting key values of boot loader section and
  1887. // calculating the maximum width of the the keys which will be displayed.
  1888. for(dwIndex=0;dwIndex < dwCount;dwIndex++)
  1889. {
  1890. szKeyName = DynArrayItemAsString(arrBootLoader,dwIndex);
  1891. szResults[dwIndex] = (LPWSTR)AllocateMemory(MAX_STRING_LENGTH*sizeof(WCHAR) );
  1892. if( NULL == szResults[dwIndex] )
  1893. {
  1894. bFlag = FALSE;
  1895. break;
  1896. }
  1897. //the value correspondin to the key is obtained.
  1898. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,szKeyName,szResults[dwIndex]);
  1899. if (dwSectionFlag == EXIT_FAILURE)
  1900. {
  1901. bFlag = FALSE;
  1902. break;
  1903. }
  1904. dwLength1 = StringLengthW(szKeyName,0);
  1905. if (dwLength1 > dwFinalLength)
  1906. {
  1907. dwFinalLength = dwLength1;
  1908. }
  1909. }
  1910. if( FALSE == bFlag )
  1911. {
  1912. //free the memory allocated for values
  1913. for(dwIndex=0;dwIndex < dwCount;dwIndex++)
  1914. {
  1915. FreeMemory((LPVOID *) &szResults[dwIndex] );
  1916. }
  1917. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  1918. resetFileAttrib(szPath);
  1919. SAFECLOSE(stream);
  1920. DestroyDynamicArray(&arrResults);
  1921. DestroyDynamicArray(&arrBootLoader);
  1922. DestroyDynamicArray(&arrKeyValuePairs);
  1923. SafeCloseConnection(szServer,bConnFlag);
  1924. FreeMemory((LPVOID *)&szServer );
  1925. FreeMemory((LPVOID *)&szUser );
  1926. return EXIT_FAILURE;
  1927. }
  1928. ShowMessage(stdout,TOKEN_NEXTLINE);
  1929. ShowMessage(stdout,BOOT_HEADER);
  1930. ShowMessage(stdout,DASHES_BOOTOS);
  1931. // display the results of the bootloader section.
  1932. for(dwIndex=0;dwIndex < dwCount;dwIndex++)
  1933. {
  1934. szKeyName = DynArrayItemAsString(arrBootLoader,dwIndex);
  1935. dwLength1 = dwFinalLength - StringLengthW(szKeyName, 0) + 1;
  1936. ShowMessage(stdout,szKeyName);
  1937. StringCopy(szDisplay,TOKEN_COLONSYMBOL, SIZE_OF_ARRAY(szDisplay));
  1938. StringConcat(szDisplay,TOKEN_50SPACES,dwLength1+1);
  1939. ShowMessage(stdout,szDisplay);
  1940. ShowMessage(stdout,szResults[dwIndex]);
  1941. ShowMessage(stdout,TOKEN_NEXTLINE);
  1942. }
  1943. ShowMessage(stdout,TOKEN_NEXTLINE);
  1944. ShowMessage(stdout,OS_HEADER);
  1945. ShowMessage(stdout,DASHES_OS);
  1946. ShowResults(MAX_COLUMNS, ResultHeader, dwFormatType,arrResults ) ;
  1947. //free the memory allocated for values
  1948. for(dwIndex=0;dwIndex < dwCount;dwIndex++)
  1949. {
  1950. FreeMemory((LPVOID *) &szResults[dwIndex] );
  1951. }
  1952. // Closing the boot.ini stream and destroying the dynamic arrays.
  1953. DestroyDynamicArray(&arrResults);
  1954. DestroyDynamicArray(&arrBootLoader);
  1955. DestroyDynamicArray(&arrKeyValuePairs);
  1956. SAFECLOSE(stream);
  1957. bRes = resetFileAttrib(szPath);
  1958. SafeCloseConnection(szServer,bConnFlag);
  1959. FreeMemory((LPVOID *)&szServer );
  1960. FreeMemory((LPVOID *)&szUser );
  1961. return (bRes);
  1962. }
  1963. TARRAY
  1964. getKeysOfINISection(
  1965. IN LPTSTR sziniFile,
  1966. IN LPTSTR sziniSection
  1967. )
  1968. /*++
  1969. Routine Description:
  1970. This function gets all the keys present in the specified section of
  1971. an .ini file and then returns the dynamic array containing all the
  1972. keys
  1973. Arguments:
  1974. [in] sziniFile : Name of the ini file.
  1975. [in] szinisection : Name of the section in the boot.ini.
  1976. Return Value :
  1977. TARRAY ( pointer to the dynamic array )
  1978. --*/
  1979. {
  1980. TARRAY arrKeys = NULL;
  1981. DWORD len = 0 ;
  1982. DWORD i = 0 ;
  1983. DWORD j = 0 ;
  1984. LPTSTR inBuf = NULL ;
  1985. DWORD dwLength = MAX_STRING_LENGTH1;
  1986. BOOL bNobreak = TRUE;
  1987. LPTSTR szTemp = NULL ;
  1988. inBuf = (LPTSTR)AllocateMemory(dwLength*sizeof(TCHAR));
  1989. if(inBuf==NULL)
  1990. {
  1991. return NULL ;
  1992. }
  1993. szTemp = (LPTSTR)AllocateMemory(dwLength*sizeof(TCHAR));
  1994. if((szTemp == NULL))
  1995. {
  1996. SAFEFREE(inBuf);
  1997. return NULL ;
  1998. }
  1999. SecureZeroMemory(inBuf,GetBufferSize(inBuf));
  2000. SecureZeroMemory(szTemp,GetBufferSize(szTemp));
  2001. do
  2002. {
  2003. // Getting all the keys from the boot.ini file
  2004. len = GetPrivateProfileString (sziniSection,
  2005. NULL,
  2006. ERROR_PROFILE_STRING,
  2007. inBuf,
  2008. dwLength,
  2009. sziniFile);
  2010. //if the size of the string is not sufficient then increment the size.
  2011. if(len == dwLength-2)
  2012. {
  2013. dwLength +=100 ;
  2014. if ( inBuf != NULL )
  2015. {
  2016. FreeMemory( (LPVOID *) &inBuf );
  2017. inBuf = NULL;
  2018. }
  2019. inBuf = (LPTSTR)AllocateMemory(dwLength*sizeof(TCHAR));
  2020. if(inBuf == NULL)
  2021. {
  2022. SAFEFREE(inBuf);
  2023. SAFEFREE(szTemp);
  2024. return NULL ;
  2025. }
  2026. if ( szTemp != NULL )
  2027. {
  2028. FreeMemory( (LPVOID *) &szTemp );
  2029. szTemp = NULL;
  2030. }
  2031. szTemp = (LPTSTR)AllocateMemory(dwLength*sizeof(TCHAR));
  2032. if(szTemp == NULL)
  2033. {
  2034. SAFEFREE(inBuf);
  2035. SAFEFREE(szTemp);
  2036. return NULL ;
  2037. }
  2038. }
  2039. else
  2040. {
  2041. bNobreak = FALSE;
  2042. break ;
  2043. }
  2044. }while(TRUE == bNobreak);
  2045. // Creating a dynamic array by using the function in the DynArray.c module.
  2046. // This dynamic array will contain all the keys.
  2047. arrKeys = CreateDynamicArray();
  2048. if(arrKeys == NULL)
  2049. {
  2050. SAFEFREE(inBuf);
  2051. SAFEFREE(szTemp);
  2052. return NULL ;
  2053. }
  2054. // Looping through the characters returned by the above function
  2055. while(i<len)
  2056. {
  2057. // Each individual key will be got in arrTest array
  2058. szTemp[ j++ ] = inBuf[ i ];
  2059. if( inBuf[ i ] == TOKEN_DELIM )
  2060. {
  2061. // Setting j to 0 to start the next key.
  2062. j = 0;
  2063. // Appending each key to the dynamic array
  2064. DynArrayAppendString( arrKeys, szTemp, 0 );
  2065. if(StringLength(szTemp, 0)==0)
  2066. {
  2067. SAFEFREE(inBuf);
  2068. SAFEFREE(szTemp);
  2069. DestroyDynamicArray(&arrKeys);
  2070. return NULL ;
  2071. }
  2072. }
  2073. // Incrementing loop variable
  2074. i++;
  2075. }
  2076. SAFEFREE(inBuf);
  2077. SAFEFREE(szTemp);
  2078. // returning the dynamic array containing all the keys
  2079. return arrKeys;
  2080. }
  2081. TARRAY
  2082. getKeyValueOfINISection(
  2083. IN LPTSTR iniFile,
  2084. IN LPTSTR sziniSection
  2085. )
  2086. /*++
  2087. Routine Description:
  2088. This function gets all the key-value pairs of the [operating systems]
  2089. section and returns a dynamic array containing all the key-value pairs
  2090. Arguments:
  2091. [in] sziniFile : Name of the ini file.
  2092. [in] szinisection : Name of the section in the boot.ini.
  2093. Return Value :
  2094. TARRAY ( pointer to the dynamic array )
  2095. --*/
  2096. {
  2097. HANDLE hFile;
  2098. TARRAY arrKeyValue = NULL;
  2099. DWORD len = 0;
  2100. DWORD i = 0 ;
  2101. DWORD j = 0 ;
  2102. LPTSTR inbuf = NULL;
  2103. LPTSTR szTemp = NULL ;
  2104. DWORD dwLength = MAX_STRING_LENGTH1 ;
  2105. BOOL bNobreak = TRUE;
  2106. hFile = CreateFile( iniFile, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL );
  2107. if ( hFile != INVALID_HANDLE_VALUE )
  2108. {
  2109. //get length of the file
  2110. dwLength = GetFileSize(hFile, NULL );
  2111. CloseHandle(hFile);
  2112. if( dwLength >= 2*1024*1024 ) //if file size is greater than 2MB
  2113. {
  2114. ShowMessage( stdout, GetResString(IDS_FILE_TOO_LONG) );
  2115. return NULL;
  2116. }
  2117. }
  2118. // Initialising loop variables
  2119. i = 0;
  2120. j = 0;
  2121. //return NULL if failed to allocate memory.
  2122. inbuf = (LPTSTR)AllocateMemory(dwLength*sizeof(TCHAR));
  2123. if(inbuf==NULL)
  2124. {
  2125. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2126. return NULL ;
  2127. }
  2128. //return NULL if failed to allocate memory
  2129. szTemp = (LPTSTR)AllocateMemory(dwLength*sizeof(TCHAR));
  2130. if(szTemp == NULL)
  2131. {
  2132. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2133. SAFEFREE(inbuf);
  2134. return NULL ;
  2135. }
  2136. SecureZeroMemory(inbuf,GetBufferSize(inbuf));
  2137. do
  2138. {
  2139. // Getting all the key-value pairs from the boot.ini file
  2140. len = GetPrivateProfileSection (sziniSection, inbuf,dwLength, iniFile);
  2141. if(len == dwLength -2)
  2142. {
  2143. dwLength +=1024 ;
  2144. if ( inbuf != NULL )
  2145. {
  2146. FreeMemory( (LPVOID *)&inbuf );
  2147. inbuf = NULL;
  2148. }
  2149. if ( szTemp != NULL )
  2150. {
  2151. FreeMemory( (LPVOID *)&szTemp );
  2152. szTemp = NULL;
  2153. }
  2154. inbuf = (LPTSTR)AllocateMemory(dwLength* sizeof(TCHAR));
  2155. szTemp = (LPTSTR)AllocateMemory(dwLength*sizeof(TCHAR));
  2156. if((inbuf== NULL)||(szTemp==NULL) || dwLength == 65535)
  2157. {
  2158. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2159. SAFEFREE(inbuf);
  2160. SAFEFREE(szTemp);
  2161. return NULL ;
  2162. }
  2163. }
  2164. else
  2165. {
  2166. bNobreak = FALSE;
  2167. break ;
  2168. }
  2169. }while(TRUE == bNobreak);
  2170. inbuf[StringLengthW(inbuf, 0)] = '\0';
  2171. // Creating a dynamic array by using the function in the DynArray.c module.
  2172. // This dynamic array will contain all the key-value pairs.
  2173. arrKeyValue = CreateDynamicArray();
  2174. if(arrKeyValue == NULL)
  2175. {
  2176. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2177. SAFEFREE(inbuf);
  2178. SAFEFREE(szTemp);
  2179. return NULL ;
  2180. }
  2181. // Looping through the characters returned by the above function
  2182. while(i<len)
  2183. {
  2184. // Each individual key will be got in arrTest array
  2185. szTemp[ j++ ] = inbuf[ i ];
  2186. if( inbuf[ i ] == TOKEN_DELIM)
  2187. {
  2188. szTemp[j+1] = '\0';
  2189. // Setting j to 0 to start the next key.
  2190. j = 0;
  2191. // Appending each key-value to the dynamic array
  2192. DynArrayAppendString( arrKeyValue, szTemp, 0 );
  2193. if(StringLengthW(szTemp, 0)==0)
  2194. {
  2195. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2196. ShowMessage( stderr, ERROR_TAG);
  2197. ShowLastError(stderr);
  2198. SAFEFREE(inbuf);
  2199. SAFEFREE(szTemp);
  2200. return NULL ;
  2201. }
  2202. }
  2203. // Incrementing loop variable
  2204. i++;
  2205. }
  2206. // returning the dynamic array containing all the key-value pairs
  2207. SAFEFREE(inbuf);
  2208. SAFEFREE(szTemp);
  2209. return arrKeyValue;
  2210. }
  2211. BOOL
  2212. deleteKeyFromINISection( IN LPTSTR szKey,
  2213. IN LPTSTR sziniFile,
  2214. IN LPTSTR sziniSection
  2215. )
  2216. /*++
  2217. Routine Description:
  2218. This function deletes a key from an ini section of an ini file
  2219. Arguments:
  2220. [in] szKey : Name of the key which has to be deleted
  2221. from the given section present in the
  2222. given ini file
  2223. [in] sziniFile : Name of the ini file.
  2224. [in] szinisection : Name of the section in the boot.ini.
  2225. Return Value :
  2226. BOOL (TRUE if there is no error, else the value is FALSE)
  2227. --*/
  2228. {
  2229. // If the third parameter (default value) is NULL, the key pointed to by
  2230. // the key parameter is deleted from the specified section of the specified
  2231. // INI file
  2232. if( WritePrivateProfileString( sziniSection, szKey, NULL, sziniFile ) == 0 )
  2233. {
  2234. // If there is an error while writing then return false
  2235. return FALSE;
  2236. }
  2237. // If there is no error, then return true
  2238. return TRUE;
  2239. }
  2240. DWORD removeSubString( LPTSTR szString, LPCTSTR szSubString )
  2241. /*++
  2242. Routine Description:
  2243. This function removes a sub-string from a string
  2244. Arguments:
  2245. [in] szString : Main string
  2246. [in] szSubString : Sub-string
  2247. Return Value :
  2248. VOID
  2249. --*/
  2250. {
  2251. LPWSTR szFinalStr=NULL;
  2252. DWORD dwSize =0;
  2253. TCHAR sep[] = TOKEN_EMPTYSPACE ;
  2254. PTCHAR pszToken = NULL_STRING;
  2255. DWORD dwCnt = 0 ;
  2256. DWORD dw=0;
  2257. szFinalStr = (LPWSTR) AllocateMemory( (StringLengthW(szString, 0)+10)*sizeof(WCHAR) );
  2258. if( NULL == szFinalStr )
  2259. {
  2260. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2261. return EXIT_FAILURE;
  2262. }
  2263. SecureZeroMemory( szFinalStr, GetBufferSize(szFinalStr) );
  2264. dw = StringLengthW(szString, 0)+10;
  2265. // Character space is used for tokenising
  2266. StringCopy( sep, _T(" "), SIZE_OF_ARRAY(sep) );
  2267. // Getting the first token
  2268. pszToken = _tcstok( szString, sep );
  2269. while( pszToken != NULL )
  2270. {
  2271. // If the token is equal to the sub-string, then the token
  2272. // is not added to the final string. The final string contains
  2273. // all the tokens except the sub-string specified.
  2274. if(StringCompare( pszToken, szSubString, TRUE, 0 ) != 0 )
  2275. {
  2276. if(dwCnt != 0)
  2277. {
  2278. StringCopy( szFinalStr + dwSize - 1, TOKEN_EMPTYSPACE, dw-dwSize );
  2279. }
  2280. dwCnt++ ;
  2281. StringCopy( szFinalStr + dwSize, pszToken, dw-dwSize );
  2282. dwSize = dwSize + StringLengthW(pszToken, 0) + 1;
  2283. }
  2284. // Getting the next token
  2285. pszToken = _tcstok( NULL, sep );
  2286. }
  2287. //lstrcpyn(szString,szFinalStr,lstrlen(szFinalStr)-1);
  2288. StringCopy(szString,szFinalStr, dw );
  2289. return EXIT_SUCCESS;
  2290. }
  2291. BOOL
  2292. openConnection( IN LPWSTR szServer,
  2293. IN LPWSTR szUser,
  2294. IN LPWSTR szPassword,
  2295. IN LPWSTR szPath,
  2296. IN BOOL bNeedPwd,
  2297. IN FILE *stream,
  2298. IN PBOOL pbConnFlag
  2299. )
  2300. /*++
  2301. Routine Description:
  2302. This function establishes a connection to the specified system with
  2303. the given credentials.
  2304. Arguments:
  2305. [in] szServer : server name to coonect to
  2306. [in] szUser : User Name
  2307. [in] szPassword : password
  2308. [in] bNeedPwd : Boolean for asking the password.
  2309. [in] szPath : path of the ini file .
  2310. Return Value :
  2311. BOOL (EXIT_SUCCESS if there is no error, else the value is EXIT_FAILURE)
  2312. --*/
  2313. {
  2314. // Declaring the file path string which will hold the path of boot.ini file
  2315. HRESULT hr = S_OK;
  2316. TCHAR filePath[MAX_RES_STRING+1] = NULL_STRING ;
  2317. DWORD dwRetVal = 0 ;
  2318. BOOL bResult = FALSE;
  2319. INT nRetVal = 0;
  2320. HKEY hKey;
  2321. HKEY hBootpathKey;
  2322. //WCHAR szDrive[MAX_STRING_LENGTH]=NULL_STRING;
  2323. LPTSTR szDrive = NULL ;
  2324. WCHAR szDrive1[MAX_STRING_LENGTH]=NULL_STRING;
  2325. DWORD dwSize=MAX_RES_STRING;
  2326. DWORD dwType=0;
  2327. *pbConnFlag = TRUE ;
  2328. SecureZeroMemory( filePath, sizeof(filePath));
  2329. if( StringCompare(szServer, NULL_STRING, TRUE, 0) != 0 )
  2330. {
  2331. bResult = EstablishConnection(szServer,
  2332. szUser,
  2333. (StringLengthW(szUser,0)!=0)? SIZE_OF_ARRAY_IN_CHARS(szUser):256,
  2334. szPassword,
  2335. MAX_STRING_LENGTH,
  2336. bNeedPwd);
  2337. if (bResult == FALSE)
  2338. {
  2339. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2340. SecureZeroMemory( szPassword, MAX_STRING_LENGTH );
  2341. return EXIT_FAILURE ;
  2342. }
  2343. else
  2344. {
  2345. switch( GetLastError() )
  2346. {
  2347. case I_NO_CLOSE_CONNECTION:
  2348. *pbConnFlag = FALSE ;
  2349. break;
  2350. case E_LOCAL_CREDENTIALS:
  2351. break;
  2352. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  2353. {
  2354. ShowLastErrorEx(stderr, SLE_TYPE_WARNING | SLE_INTERNAL );
  2355. *pbConnFlag = FALSE ;
  2356. break;
  2357. }
  2358. }
  2359. }
  2360. SecureZeroMemory( szPassword, MAX_STRING_LENGTH );
  2361. dwRetVal = CheckSystemType( szServer);
  2362. if(dwRetVal==EXIT_FAILURE )
  2363. {
  2364. return EXIT_FAILURE ;
  2365. }
  2366. //connect to the registry to bring the boot volume name
  2367. if( ERROR_SUCCESS != RegConnectRegistry( szServer, HKEY_LOCAL_MACHINE, &hKey ) )
  2368. {
  2369. SaveLastError();
  2370. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2371. return EXIT_FAILURE;
  2372. }
  2373. }
  2374. else
  2375. {
  2376. dwRetVal = CheckSystemType( szServer);
  2377. if(dwRetVal==EXIT_FAILURE )
  2378. {
  2379. return EXIT_FAILURE ;
  2380. }
  2381. //connect to the registry to bring the boot volume name
  2382. if( ERROR_SUCCESS != RegConnectRegistry( NULL, HKEY_LOCAL_MACHINE, &hKey ) )
  2383. {
  2384. SaveLastError();
  2385. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2386. return EXIT_FAILURE;
  2387. }
  2388. }
  2389. //now open the desired key
  2390. if( ERROR_SUCCESS != RegOpenKeyEx( hKey, REGISTRY_PATH, 0, KEY_QUERY_VALUE, &hBootpathKey ) )
  2391. {
  2392. SetLastError(nRetVal);
  2393. SaveLastError();
  2394. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2395. return EXIT_FAILURE;
  2396. }
  2397. szDrive = ( LPTSTR )AllocateMemory( dwSize*sizeof( TCHAR ) );
  2398. if(szDrive == NULL)
  2399. {
  2400. return ERROR_NOT_ENOUGH_MEMORY;
  2401. }
  2402. nRetVal = RegQueryValueEx( hBootpathKey, L"BootDir", 0, &dwType, (LPBYTE)szDrive, &dwSize ) ;
  2403. if (nRetVal == ERROR_MORE_DATA)
  2404. {
  2405. if ( szDrive != NULL )
  2406. {
  2407. FreeMemory((LPVOID *) &szDrive );
  2408. szDrive = NULL;
  2409. }
  2410. szDrive = ( LPTSTR ) AllocateMemory( dwSize*sizeof( TCHAR ) );
  2411. if( NULL == szDrive )
  2412. {
  2413. return ERROR_NOT_ENOUGH_MEMORY;
  2414. }
  2415. }
  2416. nRetVal = RegQueryValueEx( hBootpathKey, L"BootDir", 0, &dwType, (LPBYTE)szDrive, &dwSize ) ;
  2417. if( ERROR_SUCCESS != nRetVal)
  2418. {
  2419. RegCloseKey(hKey);
  2420. ShowMessage( stderr, GetResString(IDS_BOOTINI) );
  2421. return EXIT_FAILURE;
  2422. }
  2423. //this for display purpose
  2424. StringCopy( szDrive1, szDrive, SIZE_OF_ARRAY(szDrive1) );
  2425. CharUpper(szDrive1);
  2426. if( StringCompare(szServer, NULL_STRING, TRUE, 0) != 0 )
  2427. {
  2428. szDrive[1]=L'$';
  2429. szDrive[2]=0;
  2430. hr = StringCchPrintf(filePath, SIZE_OF_ARRAY(filePath), L"\\\\%s\\%s\\boot.ini", szServer, szDrive );
  2431. }
  2432. else
  2433. {
  2434. hr = StringCchPrintf(filePath, SIZE_OF_ARRAY(filePath), L"%sboot.ini", szDrive );
  2435. }
  2436. stream = _tfopen(filePath, READ_MODE);
  2437. // If boot.ini is not found, then display error message
  2438. if(stream == NULL )
  2439. {
  2440. RegCloseKey(hKey);
  2441. RegCloseKey(hBootpathKey);
  2442. ShowMessage( stderr, GetResString(IDS_BOOTINI) );
  2443. return EXIT_FAILURE ;
  2444. }
  2445. //store the attribs of ini file
  2446. g_dwAttributes = GetFileAttributes( filePath );
  2447. if( (DWORD)-1 == g_dwAttributes )
  2448. {
  2449. SaveLastError();
  2450. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2451. RegCloseKey(hKey);
  2452. RegCloseKey(hBootpathKey);
  2453. return EXIT_FAILURE;
  2454. }
  2455. // Changing the file permissions of the boot.ini file
  2456. nRetVal = _tchmod(filePath, _S_IREAD | _S_IWRITE);
  2457. if (nRetVal == -1)
  2458. {
  2459. RegCloseKey(hKey);
  2460. RegCloseKey(hBootpathKey);
  2461. ShowMessageEx( stderr, 1, TRUE, GetResString(IDS_READWRITE_BOOTINI), szDrive1 );
  2462. return EXIT_FAILURE ;
  2463. }
  2464. if( nRetVal != 0 )
  2465. {
  2466. RegCloseKey(hKey);
  2467. RegCloseKey(hBootpathKey);
  2468. ShowMessage(stderr,GetResString(IDS_READWRITE_BOOTINI));
  2469. return EXIT_FAILURE ;
  2470. }
  2471. //close the registry, it's work is over
  2472. RegCloseKey(hKey);
  2473. RegCloseKey(hBootpathKey);
  2474. //fill the return value
  2475. StringCopy( szPath, filePath, MAX_STRING_LENGTH);
  2476. return EXIT_SUCCESS ;
  2477. }
  2478. void displayDeleteUsage_IA64()
  2479. /*++
  2480. Routine Description:
  2481. This function fetches 64 bit Delete Usage information from resource file and displays it
  2482. Arguments:
  2483. None
  2484. Return Value:
  2485. void
  2486. --*/
  2487. {
  2488. DWORD dwIndex = ID_DEL_HELP_IA64_BEGIN;
  2489. for(;dwIndex <= ID_DEL_HELP_IA64_END;dwIndex++)
  2490. {
  2491. ShowMessage(stdout,GetResString(dwIndex));
  2492. }
  2493. }
  2494. void displayDeleteUsage_X86()
  2495. /*++
  2496. Routine Description:
  2497. This function fetches 32 bit Delete Usage information from resource file and displays it
  2498. Arguments:
  2499. None
  2500. Return Value:
  2501. void
  2502. --*/
  2503. {
  2504. DWORD dwIndex = ID_DEL_HELP_BEGIN;
  2505. for(;dwIndex <= ID_DEL_HELP_END;dwIndex++)
  2506. {
  2507. ShowMessage(stdout,GetResString(dwIndex));
  2508. }
  2509. }
  2510. VOID displayCopyUsage_IA64()
  2511. /*++
  2512. Routine Description:
  2513. This function fetches 64 bit Copy Usage information from resource file and displays it
  2514. Arguments:
  2515. None
  2516. Return Value:
  2517. void
  2518. --*/
  2519. {
  2520. DWORD dwIndex = ID_COPY_HELP_IA64_BEGIN;
  2521. for(;dwIndex <=ID_COPY_HELP_IA64_END;dwIndex++)
  2522. {
  2523. ShowMessage(stdout,GetResString(dwIndex));
  2524. }
  2525. }
  2526. VOID displayCopyUsage_X86()
  2527. /*++
  2528. Routine Description:
  2529. This function fetches 32 bit Copy Usage information from resource file and displays it
  2530. Arguments:
  2531. None
  2532. Return Value:
  2533. void
  2534. --*/
  2535. {
  2536. DWORD dwIndex = ID_COPY_HELP_BEGIN;
  2537. for(;dwIndex <=ID_COPY_HELP_END;dwIndex++)
  2538. {
  2539. ShowMessage(stdout,GetResString(dwIndex));
  2540. }
  2541. }
  2542. VOID displayQueryUsage()
  2543. /*++
  2544. Routine Description:
  2545. This function fetches Query Usage information from resource file and displays it
  2546. Arguments:
  2547. None
  2548. Return Value:
  2549. void
  2550. --*/
  2551. {
  2552. #ifdef _WIN64
  2553. displayQueryUsage_IA64();
  2554. #else
  2555. displayQueryUsage_X86();
  2556. #endif
  2557. }
  2558. VOID displayQueryUsage_IA64()
  2559. /*++
  2560. Routine Description:
  2561. This function fetches Query Usage information from resource file and displays it
  2562. Arguments:
  2563. None
  2564. Return Value:
  2565. void
  2566. --*/
  2567. {
  2568. DWORD dwIndex = ID_QUERY_HELP64_BEGIN ;
  2569. for(;dwIndex <= ID_QUERY_HELP64_END ;dwIndex++ )
  2570. {
  2571. ShowMessage(stdout,GetResString(dwIndex));
  2572. }
  2573. }
  2574. VOID displayQueryUsage_X86()
  2575. /*++
  2576. Routine Description:
  2577. This function fetches Query Usage information from resource file and displays it
  2578. Arguments:
  2579. None
  2580. Return Value:
  2581. void
  2582. --*/
  2583. {
  2584. DWORD dwIndex = ID_QUERY_HELP_BEGIN ;
  2585. for(;dwIndex <= ID_QUERY_HELP_END;dwIndex++ )
  2586. {
  2587. ShowMessage(stdout,GetResString(dwIndex));
  2588. }
  2589. }
  2590. DWORD displayMainUsage_X86()
  2591. /*++
  2592. Routine Description:
  2593. This function fetches Main Usage information from resource file and displays it
  2594. Arguments:
  2595. None
  2596. Return Value:
  2597. void
  2598. --*/
  2599. {
  2600. TCHAR szServer[MAX_RES_STRING+1] = NULL_STRING ;
  2601. DWORD dwRetVal = 0;
  2602. DWORD dwIndex = ID_MAIN_HELP_BEGIN1 ;
  2603. //display the error message if the target system is a 64 bit system or if error occured in
  2604. //retreiving the information
  2605. dwRetVal = CheckSystemType( szServer);
  2606. if(dwRetVal==EXIT_FAILURE )
  2607. {
  2608. return (EXIT_FAILURE);
  2609. }
  2610. for(;dwIndex <= ID_MAIN_HELP_END1 ;dwIndex++)
  2611. {
  2612. ShowMessage(stdout,GetResString(dwIndex));
  2613. }
  2614. return EXIT_SUCCESS ;
  2615. }
  2616. VOID displayMainUsage_IA64()
  2617. /*++
  2618. Routine Description:
  2619. This function fetches Usage information for the 64 bit system
  2620. Arguments:
  2621. None
  2622. Return Value:
  2623. void
  2624. --*/
  2625. {
  2626. DWORD dwIndex = ID_MAIN_HELP_IA64_BEGIN ;
  2627. for(;dwIndex <= ID_MAIN_HELP_IA64_END ;dwIndex++)
  2628. {
  2629. ShowMessage(stdout,GetResString(dwIndex));
  2630. }
  2631. }
  2632. BOOL resetFileAttrib( LPTSTR szFilePath )
  2633. /*++
  2634. Routine Description:
  2635. This function resets the permissions with the original set of
  2636. permissions ( -readonly -hidden -system )
  2637. and then exits with the given exit code.
  2638. Arguments
  2639. [in] szFilePath : File Path of the boot.ini file
  2640. Return Value :
  2641. BOOL (EXIT_SUCCESS if there is no error, else the value is EXIT_FAILURE)
  2642. --*/
  2643. {
  2644. if( NULL == szFilePath)
  2645. {
  2646. return FALSE ;
  2647. }
  2648. // Resetting the file permission of the boot.ini file to its original
  2649. // permission list( -r, -h, -s )
  2650. if( g_dwAttributes & FILE_ATTRIBUTE_READONLY )
  2651. {
  2652. g_dwAttributes |= FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY;
  2653. }
  2654. else
  2655. {
  2656. g_dwAttributes |= FILE_ATTRIBUTE_ARCHIVE;
  2657. }
  2658. if( FALSE == SetFileAttributes( szFilePath, g_dwAttributes) )
  2659. {
  2660. ShowMessage(stderr,GetResString(IDS_RESET_ERROR));
  2661. return EXIT_FAILURE ;
  2662. }
  2663. return EXIT_SUCCESS ;
  2664. }
  2665. DWORD
  2666. stringFromDynamicArray2( IN TARRAY arrKeyValuePairs,
  2667. IN LPTSTR* szFinalStr
  2668. )
  2669. /*++
  2670. Routine Description:
  2671. This function forms a string of string by combining all strings in dynamic array .
  2672. Arguments
  2673. [in] arrKeyValuePairs : Dynamic array which contains all the
  2674. key-value pairs.
  2675. [out] szFiinalStr : String which is formed from all the key-value pairs
  2676. Return Value :
  2677. BOOL (EXIT_SUCCESS if there is no error, else the value is EXIT_FAILURE)
  2678. --*/
  2679. {
  2680. // Total number of elements in the array
  2681. DWORD dwKeyValueCount = 0;
  2682. // Variable used to keep track the current position while appending strings.
  2683. DWORD dwStrSize = 0;
  2684. // Loop variable
  2685. DWORD i = 0;
  2686. DWORD dw =0;
  2687. // Initialsing size and loop variables to 0
  2688. dwStrSize = 0;
  2689. i = 0;
  2690. if( (arrKeyValuePairs ==NULL) )
  2691. {
  2692. return EXIT_FAILURE ;
  2693. }
  2694. // Getting the total number of key-value pairs
  2695. dwKeyValueCount = DynArrayGetCount(arrKeyValuePairs);
  2696. for(i=0;i < dwKeyValueCount;i++)
  2697. {
  2698. LPCWSTR pwsz = NULL;
  2699. pwsz = DynArrayItemAsString( arrKeyValuePairs, i ) ;
  2700. if(pwsz != NULL)
  2701. {
  2702. dwStrSize += StringLengthW(pwsz,0) + 1;
  2703. }
  2704. }
  2705. *szFinalStr = (LPWSTR) AllocateMemory( (dwStrSize+1)*sizeof(WCHAR));
  2706. if( NULL == *szFinalStr )
  2707. {
  2708. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2709. return EXIT_FAILURE ;
  2710. }
  2711. SecureZeroMemory(*szFinalStr, GetBufferSize(*szFinalStr));
  2712. i = 0 ;
  2713. dw = dwStrSize;
  2714. dwStrSize = 0 ;
  2715. // Looping through all the key-value pairs and building the final string
  2716. // containing all the key value pairs. This string has to be passed to
  2717. // WriteProfileSection
  2718. while( (i < dwKeyValueCount )&& (arrKeyValuePairs != NULL) )
  2719. {
  2720. // Building the final string, by getting each key-value pair present in the
  2721. // dynamic array
  2722. if(arrKeyValuePairs != NULL)
  2723. {
  2724. LPCWSTR pwsz = NULL;
  2725. pwsz = DynArrayItemAsString( arrKeyValuePairs, i ) ;
  2726. if(pwsz != NULL)
  2727. {
  2728. StringCopy(*szFinalStr + dwStrSize, pwsz, dw-dwStrSize );
  2729. dwStrSize = dwStrSize + StringLengthW(pwsz, 0) + 1;
  2730. }
  2731. }
  2732. else
  2733. {
  2734. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2735. SaveLastError();
  2736. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2737. return EXIT_FAILURE ;
  2738. }
  2739. i++;
  2740. }
  2741. return EXIT_SUCCESS ;
  2742. }
  2743. VOID
  2744. FormHeader( IN BOOL bHeader,
  2745. IN TCOLUMNS *ResultHeader,
  2746. IN BOOL bVerbose
  2747. )
  2748. /*++
  2749. Routine Description:
  2750. This function is used to build the header and also display the
  2751. result in the required format as specified by the user.
  2752. Arguments:
  2753. [ in ] arrResults : argument(s) count specified at the command prompt
  2754. [ in ] dwFormatType : format flags
  2755. [ in ] bHeader : Boolean for specifying if the header is required or not.
  2756. Return Value:
  2757. none
  2758. --*/
  2759. {
  2760. bVerbose = TRUE;
  2761. bHeader = TRUE;
  2762. //OS Entry
  2763. ResultHeader[COL0].dwWidth = COL_BOOTOPTION_WIDTH ;
  2764. ResultHeader[COL0].dwFlags = SR_TYPE_STRING;
  2765. ResultHeader[COL0].pFunction = NULL;
  2766. ResultHeader[COL0].pFunctionData = NULL;
  2767. StringCopy( ResultHeader[COL0].szFormat, NULL_STRING, SIZE_OF_ARRAY(ResultHeader[COL0].szFormat) );
  2768. StringCopy( ResultHeader[COL0].szColumn,COL_BOOTOPTION, SIZE_OF_ARRAY( ResultHeader[COL0].szColumn) );
  2769. ResultHeader[COL1].dwWidth = COL_FRIENDLYNAME_WIDTH;
  2770. ResultHeader[COL1].dwFlags = SR_TYPE_STRING;
  2771. ResultHeader[COL1].pFunction = NULL;
  2772. ResultHeader[COL1].pFunctionData = NULL;
  2773. StringCopy( ResultHeader[COL1].szFormat, NULL_STRING, SIZE_OF_ARRAY(ResultHeader[COL1].szFormat) );
  2774. StringCopy( ResultHeader[COL1].szColumn,COL_FRIENDLYNAME, SIZE_OF_ARRAY(ResultHeader[COL1].szColumn) );
  2775. ResultHeader[COL2].dwWidth = COL_ARC_WIDTH;
  2776. ResultHeader[COL2].dwFlags = SR_TYPE_STRING;
  2777. ResultHeader[COL2].pFunction = NULL;
  2778. ResultHeader[COL2].pFunctionData = NULL;
  2779. StringCopy( ResultHeader[COL2].szFormat, NULL_STRING, SIZE_OF_ARRAY(ResultHeader[COL2].szFormat) );
  2780. StringCopy( ResultHeader[COL2].szColumn,COL_ARCPATH, SIZE_OF_ARRAY(ResultHeader[COL2].szColumn) );
  2781. ResultHeader[COL3].dwWidth = COL_BOOTID_WIDTH;
  2782. ResultHeader[COL3].dwFlags = SR_TYPE_STRING;
  2783. ResultHeader[COL3].pFunction = NULL;
  2784. ResultHeader[COL3].pFunctionData = NULL;
  2785. StringCopy( ResultHeader[COL3].szFormat, NULL_STRING, SIZE_OF_ARRAY(ResultHeader[COL3].szFormat) );
  2786. StringCopy( ResultHeader[COL3].szColumn,COL_BOOTID, SIZE_OF_ARRAY(ResultHeader[COL3].szColumn) );
  2787. }
  2788. DWORD AppendRawString( DWORD argc, LPCTSTR argv[] )
  2789. /*++
  2790. // Routine Description:
  2791. // This routine will append or add a string to osloadoptions
  2792. //
  2793. // Arguments:
  2794. // [ in ] argc : Number of command line arguments
  2795. // [ in ] argv : Array containing command line arguments
  2796. // Return Value:
  2797. // DWORD
  2798. //
  2799. --*/
  2800. {
  2801. BOOL bUsage = FALSE ;
  2802. BOOL bNeedPwd = FALSE ;
  2803. BOOL bRaw = FALSE ;
  2804. DWORD dwDefault = 0;
  2805. TARRAY arr ;
  2806. LPWSTR pwszKey = NULL;
  2807. FILE *stream = NULL;
  2808. WCHAR *szServer = NULL;
  2809. WCHAR *szUser = NULL;
  2810. WCHAR szPassword[MAX_STRING_LENGTH] = NULL_STRING;
  2811. WCHAR szPath[MAX_RES_STRING+1] = NULL_STRING;
  2812. WCHAR szRawString[MAX_STRING_LENGTH] = NULL_STRING ;
  2813. DWORD dwNumKeys = 0;
  2814. BOOL bRes = FALSE ;
  2815. PTCHAR pToken = NULL ;
  2816. LPTSTR szFinalStr = NULL ;
  2817. BOOL bFlag = FALSE ;
  2818. LPCTSTR szToken = NULL ;
  2819. DWORD dwRetVal = 0 ;
  2820. BOOL bConnFlag = FALSE ;
  2821. BOOL bAppendFlag = FALSE ;
  2822. TCHAR szString[255] = NULL_STRING ;
  2823. TCMDPARSER2 cmdOptions[8];
  2824. PTCMDPARSER2 pcmdOption;
  2825. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  2826. //copy * to szPassword
  2827. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  2828. //main option
  2829. pcmdOption = &cmdOptions[0];
  2830. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  2831. pcmdOption->pwszOptions = CMDOPTION_RAW;
  2832. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  2833. pcmdOption->dwCount = 1;
  2834. pcmdOption->pValue = &bRaw;
  2835. //server option
  2836. pcmdOption = &cmdOptions[1];
  2837. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  2838. pcmdOption->pwszOptions = SWITCH_SERVER;
  2839. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  2840. pcmdOption->dwType = CP_TYPE_TEXT;
  2841. pcmdOption->dwCount = 1;
  2842. //user option
  2843. pcmdOption = &cmdOptions[2];
  2844. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  2845. pcmdOption->pwszOptions = SWITCH_USER;
  2846. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  2847. pcmdOption->dwType = CP_TYPE_TEXT;
  2848. pcmdOption->dwCount = 1;
  2849. //password option
  2850. pcmdOption = &cmdOptions[3];
  2851. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  2852. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  2853. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  2854. pcmdOption->dwType = CP_TYPE_TEXT;
  2855. pcmdOption->dwCount = 1;
  2856. pcmdOption->pValue = szPassword;
  2857. pcmdOption->dwLength= MAX_STRING_LENGTH;
  2858. //usage option
  2859. pcmdOption = &cmdOptions[4];
  2860. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  2861. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  2862. pcmdOption->dwFlags = CP2_USAGE;
  2863. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  2864. pcmdOption->dwCount = 1;
  2865. pcmdOption->pValue = &bUsage;
  2866. //id option
  2867. pcmdOption = &cmdOptions[5];
  2868. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  2869. pcmdOption->pwszOptions = SWITCH_ID;
  2870. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MANDATORY;
  2871. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  2872. pcmdOption->dwCount = 1;
  2873. pcmdOption->pValue = &dwDefault;
  2874. //default option
  2875. pcmdOption = &cmdOptions[6];
  2876. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  2877. pcmdOption->pwszOptions = CMDOPTION_DEFAULT;
  2878. pcmdOption->dwFlags = CP2_DEFAULT | CP2_MANDATORY;
  2879. pcmdOption->dwType = CP_TYPE_TEXT;
  2880. pcmdOption->dwCount = 1;
  2881. pcmdOption->pValue = szRawString;
  2882. pcmdOption->dwLength= MAX_STRING_LENGTH;
  2883. //usage option
  2884. pcmdOption = &cmdOptions[7];
  2885. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  2886. pcmdOption->pwszOptions = CMDOPTION_APPEND;
  2887. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  2888. pcmdOption->dwCount = 1;
  2889. pcmdOption->pValue = &bAppendFlag;
  2890. // Parsing the copy option switches
  2891. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  2892. {
  2893. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2894. return (EXIT_FAILURE);
  2895. }
  2896. szServer = cmdOptions[1].pValue;
  2897. szUser = cmdOptions[2].pValue;
  2898. if( NULL == szUser )
  2899. {
  2900. szUser = (WCHAR *) AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  2901. if( NULL == szUser )
  2902. {
  2903. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  2904. return (EXIT_FAILURE);
  2905. }
  2906. }
  2907. TrimString( szServer, TRIM_ALL );
  2908. TrimString( szUser, TRIM_ALL );
  2909. TrimString( szRawString, TRIM_ALL );
  2910. //check if usage is specified with more than one option
  2911. if( (TRUE == bUsage) && (argc > 3) )
  2912. {
  2913. ShowMessage(stderr,GetResString(IDS_RAW_USAGE));
  2914. return ( EXIT_FAILURE );
  2915. }
  2916. //display an error message if the server is empty.
  2917. if((cmdOptions[1].dwActuals!=0)&&(StringLength(szServer,0)==0))
  2918. {
  2919. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  2920. FreeMemory((LPVOID *) &szServer );
  2921. FreeMemory((LPVOID *) &szUser );
  2922. return EXIT_FAILURE ;
  2923. }
  2924. //display an error message if the user is empty.
  2925. if((cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser, 0)==0 ))
  2926. {
  2927. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  2928. FreeMemory((LPVOID *) &szServer );
  2929. FreeMemory((LPVOID *) &szUser );
  2930. return EXIT_FAILURE ;
  2931. }
  2932. //display error message if the username is entered with out a machine name
  2933. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  2934. {
  2935. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  2936. FreeMemory((LPVOID *) &szServer );
  2937. FreeMemory((LPVOID *) &szUser );
  2938. return EXIT_FAILURE ;
  2939. }
  2940. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  2941. {
  2942. ShowMessage(stderr,GetResString(IDS_PASSWD_BUT_NOUSER));
  2943. FreeMemory((LPVOID *) &szServer );
  2944. FreeMemory((LPVOID *) &szUser );
  2945. return EXIT_FAILURE ;
  2946. }
  2947. //if usage is specified
  2948. if(bUsage)
  2949. {
  2950. if( CheckSystemType(szServer) == EXIT_FAILURE )
  2951. {
  2952. FreeMemory((LPVOID *)&szServer );
  2953. FreeMemory((LPVOID *)&szUser );
  2954. return (EXIT_FAILURE);
  2955. }
  2956. displayRawUsage_X86();
  2957. FreeMemory( (LPVOID *) &szServer );
  2958. FreeMemory( (LPVOID *) &szUser );
  2959. return EXIT_SUCCESS;
  2960. }
  2961. //check whether he is administrator or not
  2962. if( IsLocalSystem(szServer) )
  2963. {
  2964. if( !IsUserAdmin() )
  2965. {
  2966. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  2967. ReleaseGlobals();
  2968. return EXIT_FAILURE;
  2969. }
  2970. }
  2971. // Establishing connection to the specified machine and getting the file pointer
  2972. // of the boot.ini file if there is no error while establishing connection
  2973. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  2974. {
  2975. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  2976. {
  2977. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  2978. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE ,0) !=0) )
  2979. {
  2980. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  2981. FreeMemory((LPVOID *) &szServer );
  2982. FreeMemory((LPVOID *) &szUser );
  2983. return (EXIT_FAILURE);
  2984. }
  2985. StringCopy(szServer,szToken, GetBufferSize(szServer)/sizeof(WCHAR));
  2986. }
  2987. }
  2988. //determine whether to prompt for password or not
  2989. if(IsLocalSystem( szServer ) == FALSE )
  2990. {
  2991. // set the bNeedPwd to True or False .
  2992. if ( cmdOptions[3].dwActuals != 0 &&
  2993. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  2994. {
  2995. // user wants the utility to prompt for the password before trying to connect
  2996. bNeedPwd = TRUE;
  2997. }
  2998. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  2999. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  3000. {
  3001. // -s, -u is specified without password ...
  3002. // utility needs to try to connect first and if it fails then prompt for the password
  3003. bNeedPwd = TRUE;
  3004. if ( szPassword != NULL )
  3005. {
  3006. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  3007. }
  3008. }
  3009. }
  3010. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  3011. {
  3012. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  3013. }
  3014. bFlag = openConnection( szServer, szUser, szPassword, szPath, bNeedPwd, stream, &bConnFlag );
  3015. if(bFlag == EXIT_FAILURE)
  3016. {
  3017. SAFECLOSE(stream);
  3018. SafeCloseConnection(szServer,bConnFlag);
  3019. FreeMemory((LPVOID *) &szServer );
  3020. FreeMemory((LPVOID *) &szUser );
  3021. return (EXIT_FAILURE);
  3022. }
  3023. // Getting the keys of the Operating system section in the boot.ini file
  3024. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  3025. if(arr == NULL)
  3026. {
  3027. resetFileAttrib(szPath);
  3028. SAFECLOSE(stream);
  3029. SafeCloseConnection(szServer,bConnFlag);
  3030. FreeMemory((LPVOID *) &szServer );
  3031. FreeMemory((LPVOID *) &szUser );
  3032. return EXIT_FAILURE ;
  3033. }
  3034. // Getting the total number of keys in the operating systems section
  3035. dwNumKeys = DynArrayGetCount(arr);
  3036. // Displaying error message if the number of keys is less than the OS entry
  3037. // line number specified by the user
  3038. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  3039. {
  3040. ShowMessage(stderr,GetResString(IDS_INVALID_BOOTID));
  3041. resetFileAttrib(szPath);
  3042. DestroyDynamicArray(&arr);
  3043. SAFECLOSE(stream);
  3044. SafeCloseConnection(szServer,bConnFlag);
  3045. FreeMemory((LPVOID *) &szServer );
  3046. FreeMemory((LPVOID *) &szUser );
  3047. return (EXIT_FAILURE);
  3048. }
  3049. // Getting the key of the OS entry specified by the user
  3050. if (arr != NULL)
  3051. {
  3052. LPCWSTR pwsz = NULL;
  3053. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  3054. //allocate memory to the new key
  3055. pwszKey = (LPWSTR) AllocateMemory( (StringLength(szRawString,0)+StringLength(pwsz,0)+10)*sizeof(WCHAR ) );
  3056. if( NULL == pwszKey )
  3057. {
  3058. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  3059. resetFileAttrib(szPath);
  3060. DestroyDynamicArray(&arr);
  3061. SAFECLOSE(stream);
  3062. SafeCloseConnection(szServer,bConnFlag);
  3063. FreeMemory((LPVOID *) &szServer );
  3064. FreeMemory((LPVOID *) &szUser );
  3065. return EXIT_FAILURE ;
  3066. }
  3067. StringCopy( pwszKey, pwsz, GetBufferSize(pwszKey)/sizeof(WCHAR) );
  3068. }
  3069. else
  3070. {
  3071. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3072. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  3073. resetFileAttrib(szPath);
  3074. DestroyDynamicArray(&arr);
  3075. SAFECLOSE(stream);
  3076. SafeCloseConnection(szServer,bConnFlag);
  3077. FreeMemory((LPVOID *) &szServer );
  3078. FreeMemory((LPVOID *) &szUser );
  3079. return EXIT_FAILURE ;
  3080. }
  3081. //if append is not required truncate the existing osloadoptions from the boot entry
  3082. if(bAppendFlag == FALSE)
  3083. {
  3084. pToken = _tcsrchr(pwszKey,L'"');
  3085. if(NULL== pToken)
  3086. {
  3087. ShowMessage(stderr,GetResString(IDS_NO_TOKENS));
  3088. resetFileAttrib(szPath);
  3089. DestroyDynamicArray(&arr);
  3090. SAFECLOSE(stream);
  3091. SafeCloseConnection(szServer,bConnFlag);
  3092. FreeMemory((LPVOID *) &szServer );
  3093. FreeMemory((LPVOID *) &szUser );
  3094. FreeMemory((LPVOID *) &pwszKey);
  3095. return EXIT_FAILURE ;
  3096. }
  3097. pToken++;
  3098. pToken[0]=L'\0';
  3099. }
  3100. //concatenate the raw string to the boot entry
  3101. CharLower(szRawString);
  3102. StringConcat(pwszKey , TOKEN_EMPTYSPACE, GetBufferSize(pwszKey)/sizeof(WCHAR) );
  3103. StringConcat(pwszKey ,szRawString, GetBufferSize(pwszKey)/sizeof(WCHAR) );
  3104. //check the length exceeds the max. length of boot entry
  3105. if( StringLengthW(pwszKey, 0) > MAX_RES_STRING)
  3106. {
  3107. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  3108. resetFileAttrib(szPath);
  3109. DestroyDynamicArray(&arr);
  3110. SAFECLOSE(stream);
  3111. SafeCloseConnection(szServer,bConnFlag);
  3112. FreeMemory((LPVOID *) &szServer );
  3113. FreeMemory((LPVOID *) &szUser );
  3114. FreeMemory((LPVOID *) &pwszKey);
  3115. return EXIT_FAILURE ;
  3116. }
  3117. DynArrayRemove(arr, dwDefault - 1 );
  3118. DynArrayInsertString(arr, dwDefault - 1, pwszKey, MAX_RES_STRING+1);
  3119. //free the memory, no need
  3120. FreeMemory((LPVOID *) &pwszKey);
  3121. //The memory is allocated in this function which should be freed before exitting
  3122. if (stringFromDynamicArray2( arr,&szFinalStr) == EXIT_FAILURE)
  3123. {
  3124. DestroyDynamicArray(&arr);
  3125. SAFEFREE(szFinalStr);
  3126. SAFECLOSE(stream);
  3127. resetFileAttrib(szPath);
  3128. SafeCloseConnection(szServer,bConnFlag);
  3129. FreeMemory((LPVOID *) &szServer );
  3130. FreeMemory((LPVOID *) &szUser );
  3131. return EXIT_FAILURE;
  3132. }
  3133. // Writing to the profile section with new key-value pair
  3134. // If the return value is non-zero, then there is an error.
  3135. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  3136. {
  3137. ShowMessageEx(stdout, 1, TRUE, GetResString(IDS_SWITCH_ADD), dwDefault );
  3138. }
  3139. else
  3140. {
  3141. ShowMessage(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  3142. DestroyDynamicArray(&arr);
  3143. resetFileAttrib(szPath);
  3144. SAFEFREE(szFinalStr);
  3145. SAFECLOSE(stream);
  3146. SafeCloseConnection(szServer,bConnFlag);
  3147. FreeMemory((LPVOID *) &szServer );
  3148. FreeMemory((LPVOID *) &szUser );
  3149. return (EXIT_FAILURE);
  3150. }
  3151. //reset the file attributes and free the memory and close the connection to the server.
  3152. bRes = resetFileAttrib(szPath);
  3153. DestroyDynamicArray(&arr);
  3154. SAFEFREE(szFinalStr);
  3155. SAFECLOSE(stream);
  3156. SafeCloseConnection(szServer,bConnFlag);
  3157. FreeMemory((LPVOID *) &szServer );
  3158. FreeMemory((LPVOID *) &szUser );
  3159. return (EXIT_SUCCESS);
  3160. }
  3161. VOID displayRawUsage_X86()
  3162. /*++
  3163. Routine Description:
  3164. This routine is to display the current boot.ini file settings for
  3165. the specified system.
  3166. Arguments:
  3167. none
  3168. Return Value:
  3169. VOID
  3170. --*/
  3171. {
  3172. DWORD dwIndex = RAW_HELP_BEGIN;
  3173. for(;dwIndex <= RAW_HELP_END;dwIndex++)
  3174. {
  3175. ShowMessage(stdout,GetResString(dwIndex));
  3176. }
  3177. }
  3178. VOID displayRawUsage_IA64()
  3179. /*++
  3180. Routine Description:
  3181. Display the help for the 64 bit raw option.
  3182. Arguments:
  3183. none
  3184. Return Value:
  3185. VOID
  3186. --*/
  3187. {
  3188. DWORD dwIndex = RAW_HELP_IA64_BEGIN;
  3189. for(;dwIndex <= RAW_HELP_IA64_END;dwIndex++)
  3190. {
  3191. ShowMessage(stdout,GetResString(dwIndex));
  3192. }
  3193. }
  3194. DWORD ChangeTimeOut(DWORD argc,LPCTSTR argv[])
  3195. /*++
  3196. Routine Description:
  3197. This routine is to change the timout of the boot.ini file settings for
  3198. the specified system.
  3199. Arguments:
  3200. [in ] argc : Number of command line arguments
  3201. [in ] argv : Array containing command line arguments
  3202. Return Value:
  3203. DWORD
  3204. --*/
  3205. {
  3206. WCHAR *szServer = NULL;
  3207. WCHAR *szUser = NULL;
  3208. WCHAR szPassword[MAX_STRING_LENGTH] = NULL_STRING;
  3209. WCHAR szPath[MAX_STRING_LENGTH] = NULL_STRING;
  3210. DWORD dwTimeOut = 0 ;
  3211. BOOL bTimeout = FALSE;
  3212. BOOL bNeedPwd = FALSE ;
  3213. BOOL bRes = FALSE ;
  3214. BOOL bFlag = 0 ;
  3215. FILE *stream = NULL;
  3216. TCHAR timeOutstr[STRING20] = NULL_STRING;
  3217. LPCTSTR szToken = NULL ;
  3218. DWORD dwRetVal = 0 ;
  3219. BOOL bConnFlag = FALSE ;
  3220. BOOL bUsage = FALSE;
  3221. TCMDPARSER2 cmdOptions[6];
  3222. PTCMDPARSER2 pcmdOption;
  3223. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  3224. //copy * to szPassword
  3225. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  3226. //main option
  3227. pcmdOption = &cmdOptions[0];
  3228. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3229. pcmdOption->pwszOptions = CMDOPTION_TIMEOUT;
  3230. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  3231. pcmdOption->dwCount = 1;
  3232. pcmdOption->pValue = &bTimeout;
  3233. pcmdOption = &cmdOptions[1];
  3234. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3235. pcmdOption->pwszOptions = SWITCH_SERVER;
  3236. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  3237. pcmdOption->dwType = CP_TYPE_TEXT;
  3238. pcmdOption->dwCount = 1;
  3239. pcmdOption = &cmdOptions[2];
  3240. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3241. pcmdOption->pwszOptions = SWITCH_USER;
  3242. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  3243. pcmdOption->dwType = CP_TYPE_TEXT;
  3244. pcmdOption->dwCount = 1;
  3245. pcmdOption = &cmdOptions[3];
  3246. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3247. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  3248. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  3249. pcmdOption->dwType = CP_TYPE_TEXT;
  3250. pcmdOption->dwCount = 1;
  3251. pcmdOption->pValue = szPassword;
  3252. pcmdOption->dwLength= MAX_STRING_LENGTH;
  3253. pcmdOption = &cmdOptions[4];
  3254. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3255. pcmdOption->pwszOptions = CMDOPTION_DEFAULT;
  3256. pcmdOption->dwFlags = CP2_DEFAULT | CP2_MANDATORY;
  3257. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  3258. pcmdOption->dwCount = 1;
  3259. pcmdOption->pValue = &dwTimeOut;
  3260. //usage option
  3261. pcmdOption = &cmdOptions[5];
  3262. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3263. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  3264. pcmdOption->dwFlags = CP2_USAGE;
  3265. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  3266. pcmdOption->dwCount = 1;
  3267. pcmdOption->pValue = &bUsage;
  3268. if( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  3269. {
  3270. ShowLastErrorEx(stderr,SLE_TYPE_ERROR | SLE_INTERNAL );
  3271. return EXIT_FAILURE ;
  3272. }
  3273. szServer = cmdOptions[1].pValue;
  3274. szUser = cmdOptions[2].pValue;
  3275. if( NULL == szUser )
  3276. {
  3277. szUser = (WCHAR *)AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  3278. if( NULL == szUser )
  3279. {
  3280. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  3281. return (EXIT_FAILURE);
  3282. }
  3283. }
  3284. TrimString( szServer, TRIM_ALL );
  3285. TrimString( szUser, TRIM_ALL );
  3286. //check if usage is specified with more than one option
  3287. if( (TRUE == bUsage) && (argc > 3) )
  3288. {
  3289. ShowMessage(stderr,GetResString(IDS_TIMEOUT_USAGE));
  3290. return ( EXIT_FAILURE );
  3291. }
  3292. //display an error message if the server is empty.
  3293. if( (cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  3294. {
  3295. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  3296. FreeMemory((LPVOID *)&szServer );
  3297. FreeMemory((LPVOID *)&szUser );
  3298. return EXIT_FAILURE ;
  3299. }
  3300. //display an error message if the user is empty.
  3301. if((cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser, 0)==0 ))
  3302. {
  3303. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  3304. FreeMemory((LPVOID *)&szServer );
  3305. FreeMemory((LPVOID *)&szUser );
  3306. return EXIT_FAILURE ;
  3307. }
  3308. //display error message if the username is entered with out a machine name
  3309. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  3310. {
  3311. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  3312. return EXIT_FAILURE ;
  3313. }
  3314. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  3315. {
  3316. ShowMessage(stderr, GetResString(IDS_PASSWD_BUT_NOUSER));
  3317. FreeMemory((LPVOID *)&szServer );
  3318. FreeMemory((LPVOID *)&szUser );
  3319. return EXIT_FAILURE ;
  3320. }
  3321. if(dwTimeOut > TIMEOUT_MAX )
  3322. {
  3323. ShowMessage(stderr,GetResString(IDS_TIMEOUT_RANGE));
  3324. FreeMemory((LPVOID *)&szServer );
  3325. FreeMemory((LPVOID *)&szUser );
  3326. return (EXIT_FAILURE);
  3327. }
  3328. if(bUsage)
  3329. {
  3330. if( CheckSystemType(szServer) == EXIT_FAILURE )
  3331. {
  3332. FreeMemory((LPVOID *)&szServer );
  3333. FreeMemory((LPVOID *)&szUser );
  3334. return (EXIT_FAILURE);
  3335. }
  3336. displayTimeOutUsage_X86();
  3337. FreeMemory((LPVOID *)&szServer );
  3338. FreeMemory((LPVOID *)&szUser );
  3339. return (EXIT_SUCCESS);
  3340. }
  3341. //check whether he is administrator or not
  3342. if( IsLocalSystem(szServer) )
  3343. {
  3344. if( !IsUserAdmin() )
  3345. {
  3346. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  3347. FreeMemory((LPVOID *)&szServer );
  3348. FreeMemory((LPVOID *)&szUser );
  3349. ReleaseGlobals();
  3350. return EXIT_FAILURE;
  3351. }
  3352. }
  3353. if(IsLocalSystem( szServer ) == FALSE )
  3354. {
  3355. // set the bNeedPwd to True or False .
  3356. if ( cmdOptions[3].dwActuals != 0 &&
  3357. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  3358. {
  3359. // user wants the utility to prompt for the password before trying to connect
  3360. bNeedPwd = TRUE;
  3361. }
  3362. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  3363. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  3364. {
  3365. // -s, -u is specified without password ...
  3366. // utility needs to try to connect first and if it fails then prompt for the password
  3367. bNeedPwd = TRUE;
  3368. if ( szPassword != NULL )
  3369. {
  3370. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  3371. }
  3372. }
  3373. }
  3374. // Establishing connection to the specified machine and getting the file pointer
  3375. // of the boot.ini file if there is no error while establishing connection
  3376. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  3377. {
  3378. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  3379. {
  3380. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  3381. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  3382. {
  3383. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  3384. return (EXIT_FAILURE);
  3385. }
  3386. StringCopy(szServer,szToken, GetBufferSize(szServer)/sizeof(WCHAR));
  3387. }
  3388. }
  3389. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  3390. if(bFlag == EXIT_FAILURE)
  3391. {
  3392. SafeCloseConnection(szServer,bConnFlag);
  3393. FreeMemory((LPVOID *)&szServer );
  3394. FreeMemory((LPVOID *)&szUser );
  3395. return (EXIT_FAILURE);
  3396. }
  3397. //display a warning message if it is a local system and set the server name to empty.
  3398. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  3399. {
  3400. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  3401. }
  3402. // Converting the numeric value to string because the WritePrivateProfileString
  3403. // takes only string value as the value for a particular key
  3404. _itot( dwTimeOut, timeOutstr, 10 );
  3405. // Changing the timeout value
  3406. if( WritePrivateProfileString( BOOTLOADERSECTION,TIMEOUT_SWITCH,
  3407. timeOutstr, szPath ) != 0 )
  3408. {
  3409. ShowMessage(stdout,GetResString(IDS_TIMEOUT_CHANGE));
  3410. resetFileAttrib(szPath);
  3411. SafeCloseConnection(szServer,bConnFlag);
  3412. SAFECLOSE(stream);
  3413. FreeMemory((LPVOID *)&szServer );
  3414. FreeMemory((LPVOID *)&szUser );
  3415. return EXIT_SUCCESS ;
  3416. }
  3417. // DISPLAY Error message and exit with Error code of 1.
  3418. ShowMessage(stderr,GetResString(IDS_ERROR_TIMEOUT));
  3419. bRes = resetFileAttrib(szPath);
  3420. SafeCloseConnection(szServer,bConnFlag);
  3421. SAFECLOSE(stream);
  3422. return EXIT_FAILURE ;
  3423. }
  3424. VOID displayTimeOutUsage_X86()
  3425. /*++
  3426. Routine Description:
  3427. Display the help for the timeout option.
  3428. Arguments:
  3429. NONE.
  3430. Return Value:
  3431. VOID
  3432. --*/
  3433. {
  3434. DWORD dwIndex = TIMEOUT_HELP_BEGIN;
  3435. for(;dwIndex <= TIMEOUT_HELP_END;dwIndex++)
  3436. {
  3437. ShowMessage(stdout,GetResString(dwIndex));
  3438. }
  3439. }
  3440. VOID
  3441. displayTimeOutUsage_IA64()
  3442. /*++
  3443. Routine Description:
  3444. Display the help for the 64 BIT timeout option.
  3445. Arguments:
  3446. NONE.
  3447. Return Value:
  3448. VOID
  3449. --*/
  3450. {
  3451. DWORD dwIndex = TIMEOUT_HELP_IA64_BEGIN;
  3452. for(;dwIndex <= TIMEOUT_HELP_IA64_END;dwIndex++)
  3453. {
  3454. ShowMessage(stdout,GetResString(dwIndex));
  3455. }
  3456. }
  3457. DWORD
  3458. ChangeDefaultOs( IN DWORD argc,
  3459. IN LPCTSTR argv[]
  3460. )
  3461. /*++
  3462. Routine Description:
  3463. This routine is to change the Default OS boot.ini file settings for
  3464. the specified system.
  3465. Arguments:
  3466. [IN] argc Number of command line arguments
  3467. [IN] argv Array containing command line arguments
  3468. Return Value:
  3469. DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.
  3470. --*/
  3471. {
  3472. WCHAR *szServer = NULL;
  3473. WCHAR *szUser = NULL;
  3474. WCHAR szPassword[MAX_STRING_LENGTH] = NULL_STRING ;
  3475. DWORD dwId = 0;
  3476. BOOL bDefaultOs = FALSE ;
  3477. WCHAR szPath[MAX_RES_STRING+1] = NULL_STRING;
  3478. FILE *stream = NULL;
  3479. BOOL bNeedPwd = FALSE ;
  3480. TARRAY arrResults = NULL;
  3481. DWORD dwCount = 0;
  3482. BOOL bFlag = FALSE ;
  3483. TCHAR szDefaultId[MAX_RES_STRING+1] = NULL_STRING ;
  3484. long dwValue = 0 ;
  3485. LPCWSTR pwsz = NULL;
  3486. LPCWSTR pwszBootId = NULL;
  3487. LPTSTR szFinalStr = NULL ;
  3488. LPTSTR szTemp = NULL;
  3489. LPCTSTR szToken = NULL ;
  3490. BOOL bConnFlag = FALSE ;
  3491. BOOL bRes = FALSE;
  3492. BOOL bUsage = FALSE;
  3493. TCMDPARSER2 cmdOptions[6];
  3494. PTCMDPARSER2 pcmdOption;
  3495. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  3496. //copy * to szPassword
  3497. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  3498. //main option
  3499. pcmdOption = &cmdOptions[0];
  3500. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3501. pcmdOption->pwszOptions = CMDOPTION_DEFAULTOS;
  3502. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  3503. pcmdOption->dwCount = 1;
  3504. pcmdOption->pValue = &bDefaultOs;
  3505. //server option
  3506. pcmdOption = &cmdOptions[1];
  3507. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3508. pcmdOption->pwszOptions = SWITCH_SERVER;
  3509. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  3510. pcmdOption->dwType = CP_TYPE_TEXT;
  3511. pcmdOption->dwCount = 1;
  3512. //user option
  3513. pcmdOption = &cmdOptions[2];
  3514. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3515. pcmdOption->pwszOptions = SWITCH_USER;
  3516. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  3517. pcmdOption->dwType = CP_TYPE_TEXT;
  3518. pcmdOption->dwCount = 1;
  3519. //password option
  3520. pcmdOption = &cmdOptions[3];
  3521. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3522. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  3523. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  3524. pcmdOption->dwType = CP_TYPE_TEXT;
  3525. pcmdOption->dwCount = 1;
  3526. pcmdOption->pValue = szPassword;
  3527. pcmdOption->dwLength= MAX_STRING_LENGTH;
  3528. //id option
  3529. pcmdOption = &cmdOptions[4];
  3530. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3531. pcmdOption->pwszOptions = SWITCH_ID;
  3532. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MANDATORY;
  3533. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  3534. pcmdOption->dwCount = 1;
  3535. pcmdOption->pValue = &dwId;
  3536. //usage option
  3537. pcmdOption = &cmdOptions[5];
  3538. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3539. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  3540. pcmdOption->dwFlags = CP2_USAGE;
  3541. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  3542. pcmdOption->dwCount = 1;
  3543. pcmdOption->pValue = &bUsage;
  3544. // Parsing the copy option switches
  3545. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  3546. {
  3547. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  3548. return (EXIT_FAILURE);
  3549. }
  3550. szServer = cmdOptions[1].pValue;
  3551. szUser = cmdOptions[2].pValue;
  3552. if( NULL == szUser )
  3553. {
  3554. szUser = (WCHAR *)AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  3555. if( NULL == szUser )
  3556. {
  3557. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  3558. return (EXIT_FAILURE);
  3559. }
  3560. }
  3561. TrimString( szServer, TRIM_ALL );
  3562. TrimString( szUser, TRIM_ALL );
  3563. //check if usage is specified with more than one option
  3564. if( (TRUE == bUsage) && (argc > 3) )
  3565. {
  3566. ShowMessage(stderr,GetResString(IDS_DEFAULTOS_USAGE));
  3567. return ( EXIT_FAILURE );
  3568. }
  3569. //display an error message if the server is empty.
  3570. if( (cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  3571. {
  3572. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  3573. FreeMemory((LPVOID *)&szServer );
  3574. FreeMemory((LPVOID *)&szUser );
  3575. return EXIT_FAILURE ;
  3576. }
  3577. //display an error message if the user is empty.
  3578. if((cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser, 0)==0 ))
  3579. {
  3580. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  3581. FreeMemory((LPVOID *)&szServer );
  3582. FreeMemory((LPVOID *)&szUser );
  3583. return EXIT_FAILURE ;
  3584. }
  3585. //display error message if the username is entered with out a machine name
  3586. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  3587. {
  3588. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  3589. FreeMemory((LPVOID *)&szServer );
  3590. FreeMemory((LPVOID *)&szUser );
  3591. return EXIT_FAILURE ;
  3592. }
  3593. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  3594. {
  3595. ShowMessage(stderr, GetResString(IDS_PASSWD_BUT_NOUSER));
  3596. FreeMemory((LPVOID *)&szServer );
  3597. FreeMemory((LPVOID *)&szUser );
  3598. return EXIT_FAILURE ;
  3599. }
  3600. if(bUsage )
  3601. {
  3602. if( CheckSystemType(szServer) == EXIT_FAILURE )
  3603. {
  3604. FreeMemory((LPVOID *)&szServer );
  3605. FreeMemory((LPVOID *)&szUser );
  3606. return (EXIT_FAILURE);
  3607. }
  3608. displayChangeOSUsage_X86();
  3609. FreeMemory((LPVOID *)&szServer );
  3610. FreeMemory((LPVOID *)&szUser );
  3611. return(EXIT_SUCCESS);
  3612. }
  3613. //check whether he is administrator or not
  3614. if( IsLocalSystem(szServer) )
  3615. {
  3616. if( !IsUserAdmin() )
  3617. {
  3618. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  3619. FreeMemory((LPVOID *)&szServer );
  3620. FreeMemory((LPVOID *)&szUser );
  3621. ReleaseGlobals();
  3622. return EXIT_FAILURE;
  3623. }
  3624. }
  3625. if(dwId <= 0)
  3626. {
  3627. ShowMessage(stderr, GetResString( IDS_INVALID_OSID));
  3628. FreeMemory((LPVOID *)&szServer );
  3629. FreeMemory((LPVOID *)&szUser );
  3630. return EXIT_FAILURE ;
  3631. }
  3632. if(IsLocalSystem( szServer ) == FALSE )
  3633. {
  3634. // set the bNeedPwd to True or False .
  3635. if ( cmdOptions[3].dwActuals != 0 &&
  3636. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  3637. {
  3638. // user wants the utility to prompt for the password before trying to connect
  3639. bNeedPwd = TRUE;
  3640. }
  3641. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  3642. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  3643. {
  3644. // -s, -u is specified without password ...
  3645. // utility needs to try to connect first and if it fails then prompt for the password
  3646. bNeedPwd = TRUE;
  3647. if ( szPassword != NULL )
  3648. {
  3649. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  3650. }
  3651. }
  3652. }
  3653. // Establishing connection to the specified machine and getting the file pointer
  3654. // of the boot.ini file if there is no error while establishing connection
  3655. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  3656. {
  3657. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  3658. {
  3659. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  3660. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  3661. {
  3662. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  3663. FreeMemory((LPVOID *)&szServer );
  3664. FreeMemory((LPVOID *)&szUser );
  3665. return (EXIT_FAILURE);
  3666. }
  3667. StringCopy(szServer,szToken, GetBufferSize(szServer)/sizeof(WCHAR));
  3668. }
  3669. }
  3670. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  3671. if(bFlag == EXIT_FAILURE)
  3672. {
  3673. SafeCloseConnection(szServer,bConnFlag);
  3674. FreeMemory((LPVOID *)&szServer );
  3675. FreeMemory((LPVOID *)&szUser );
  3676. return (EXIT_FAILURE);
  3677. }
  3678. //display warning message
  3679. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  3680. {
  3681. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  3682. }
  3683. arrResults = CreateDynamicArray();
  3684. //return failure if failed to allocate memory
  3685. if(arrResults == NULL)
  3686. {
  3687. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3688. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM);
  3689. SafeCloseConnection(szServer,bConnFlag);
  3690. FreeMemory((LPVOID *)&szServer );
  3691. FreeMemory((LPVOID *)&szUser );
  3692. SAFECLOSE(stream);
  3693. return (EXIT_FAILURE);
  3694. }
  3695. arrResults = getKeyValueOfINISection( szPath, OS_FIELD );
  3696. if(arrResults == NULL)
  3697. {
  3698. resetFileAttrib(szPath);
  3699. DestroyDynamicArray(&arrResults);
  3700. SafeCloseConnection(szServer,bConnFlag);
  3701. FreeMemory((LPVOID *)&szServer );
  3702. FreeMemory((LPVOID *)&szUser );
  3703. SAFECLOSE(stream);
  3704. return EXIT_FAILURE ;
  3705. }
  3706. dwCount = DynArrayGetCount(arrResults);
  3707. if(dwId<=0 || dwId > dwCount )
  3708. {
  3709. ShowMessage(stderr,GetResString(IDS_INVALID_OSID));
  3710. resetFileAttrib(szPath);
  3711. DestroyDynamicArray(&arrResults);
  3712. SafeCloseConnection(szServer,bConnFlag);
  3713. SAFECLOSE(stream);
  3714. FreeMemory((LPVOID *)&szServer );
  3715. FreeMemory((LPVOID *)&szUser );
  3716. return EXIT_FAILURE ;
  3717. }
  3718. if(arrResults !=NULL)
  3719. {
  3720. pwsz = DynArrayItemAsString(arrResults, dwId - 1);
  3721. if(NULL == pwsz)
  3722. {
  3723. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3724. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  3725. resetFileAttrib(szPath);
  3726. DestroyDynamicArray(&arrResults);
  3727. SafeCloseConnection(szServer,bConnFlag);
  3728. SAFECLOSE(stream);
  3729. FreeMemory((LPVOID *)&szServer );
  3730. FreeMemory((LPVOID *)&szUser );
  3731. return EXIT_FAILURE ;
  3732. }
  3733. //check whether it exceeds maximum limit or not
  3734. if( (StringLengthW(pwsz, 0)>MAX_RES_STRING) || (StringLengthW(pwszBootId, 0)>MAX_RES_STRING ))
  3735. {
  3736. ShowMessage( stderr, GetResString(IDS_STRING_TOO_LONG));
  3737. resetFileAttrib(szPath);
  3738. DestroyDynamicArray(&arrResults);
  3739. SafeCloseConnection(szServer,bConnFlag);
  3740. SAFECLOSE(stream);
  3741. FreeMemory((LPVOID *)&szServer );
  3742. FreeMemory((LPVOID *)&szUser );
  3743. return EXIT_FAILURE ;
  3744. }
  3745. StringCopy(szDefaultId,pwsz, SIZE_OF_ARRAY(szDefaultId));
  3746. }
  3747. else
  3748. {
  3749. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3750. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  3751. resetFileAttrib(szPath);
  3752. DestroyDynamicArray(&arrResults);
  3753. SafeCloseConnection(szServer,bConnFlag);
  3754. SAFECLOSE(stream);
  3755. FreeMemory((LPVOID *)&szServer );
  3756. FreeMemory((LPVOID *)&szUser );
  3757. return EXIT_FAILURE ;
  3758. }
  3759. //loop through all the Boot entries and
  3760. for(dwValue = dwId-2 ; dwValue>=0 ; dwValue-- )
  3761. {
  3762. szTemp = (LPWSTR)DynArrayItemAsString(arrResults,dwValue );
  3763. DynArrayRemove(arrResults, dwValue+1 );
  3764. DynArrayInsertString(arrResults, dwValue+1, szTemp, StringLengthW(szTemp, 0));
  3765. }
  3766. DynArrayRemove(arrResults, 0 );
  3767. DynArrayInsertString(arrResults, 0, szDefaultId, StringLengthW(szDefaultId, 0));
  3768. // Setting the buffer to 0, to avoid any junk value
  3769. if (stringFromDynamicArray2( arrResults,&szFinalStr) == EXIT_FAILURE)
  3770. {
  3771. resetFileAttrib(szPath);
  3772. DestroyDynamicArray(&arrResults);
  3773. SafeCloseConnection(szServer,bConnFlag);
  3774. SAFECLOSE(stream);
  3775. SAFEFREE(szFinalStr);
  3776. FreeMemory((LPVOID *)&szServer );
  3777. FreeMemory((LPVOID *)&szUser );
  3778. return EXIT_FAILURE ;
  3779. }
  3780. // Writing to the profile section with new key-value pair
  3781. // If the return value is non-zero, then there is an error.
  3782. if( ( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) == 0 ) )
  3783. {
  3784. ShowMessage(stderr,GetResString(IDS_ERR_CHANGE));
  3785. resetFileAttrib(szPath);
  3786. DestroyDynamicArray(&arrResults);
  3787. SafeCloseConnection(szServer,bConnFlag);
  3788. SAFECLOSE(stream);
  3789. SAFEFREE(szFinalStr);
  3790. FreeMemory((LPVOID *)&szServer );
  3791. FreeMemory((LPVOID *)&szUser );
  3792. return EXIT_FAILURE ;
  3793. }
  3794. //to strip of the unwanted string from the string and save the required part in the Boot Loader section.
  3795. szToken = _tcstok(szDefaultId,TOKEN_EQUAL);
  3796. if(szToken == NULL)
  3797. {
  3798. ShowMessage( stderr,GetResString(IDS_NO_TOKENS));
  3799. resetFileAttrib(szPath);
  3800. DestroyDynamicArray(&arrResults);
  3801. SafeCloseConnection(szServer,bConnFlag);
  3802. SAFECLOSE(stream);
  3803. SAFEFREE(szFinalStr);
  3804. FreeMemory((LPVOID *)&szServer );
  3805. FreeMemory((LPVOID *)&szUser );
  3806. return (EXIT_FAILURE);
  3807. }
  3808. if( WritePrivateProfileString( BOOTLOADERSECTION, KEY_DEFAULT, szDefaultId,
  3809. szPath ) != 0 )
  3810. {
  3811. ShowMessage(stdout,GetResString(IDS_OS_CHANGE));
  3812. }
  3813. else
  3814. {
  3815. ShowMessage(stderr,GetResString(IDS_ERR_CHANGE));
  3816. DestroyDynamicArray(&arrResults);
  3817. resetFileAttrib(szPath);
  3818. SafeCloseConnection(szServer,bConnFlag);
  3819. SAFECLOSE(stream);
  3820. SAFEFREE(szFinalStr);
  3821. FreeMemory((LPVOID *)&szServer );
  3822. FreeMemory((LPVOID *)&szUser );
  3823. return EXIT_FAILURE ;
  3824. }
  3825. bRes = resetFileAttrib(szPath);
  3826. DestroyDynamicArray(&arrResults);
  3827. SafeCloseConnection(szServer,bConnFlag);
  3828. SAFECLOSE(stream);
  3829. SAFEFREE(szFinalStr);
  3830. FreeMemory((LPVOID *)&szServer );
  3831. FreeMemory((LPVOID *)&szUser );
  3832. return bRes ;
  3833. }
  3834. VOID displayChangeOSUsage_X86()
  3835. /*++
  3836. Routine Description : Display the help for the default entry option (x86).
  3837. Parameters : none
  3838. Return Type : VOID
  3839. --*/
  3840. {
  3841. DWORD dwIndex = DEFAULT_BEGIN;
  3842. for(;dwIndex <=DEFAULT_END;dwIndex++)
  3843. {
  3844. ShowMessage(stdout,GetResString(dwIndex));
  3845. }
  3846. }
  3847. VOID
  3848. displayDefaultEntryUsage_IA64()
  3849. /*++
  3850. Routine Description : Display the help for the default entry option (IA64).
  3851. Parameters : none
  3852. Return Type : VOID
  3853. --*/
  3854. {
  3855. DWORD dwIndex = DEFAULT_IA64_BEGIN;
  3856. for(;dwIndex <=DEFAULT_IA64_END;dwIndex++)
  3857. {
  3858. ShowMessage(stdout,GetResString(dwIndex));
  3859. }
  3860. }
  3861. DWORD
  3862. ProcessDebugSwitch( IN DWORD argc,
  3863. IN LPCTSTR argv[]
  3864. )
  3865. /*++
  3866. Routine Description:
  3867. Implement the Debug switch.
  3868. Arguments:
  3869. [IN] argc Number of command line arguments
  3870. [IN] argv Array containing command line arguments
  3871. Return Value:
  3872. DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  3873. --*/
  3874. {
  3875. BOOL bUsage = FALSE ;
  3876. BOOL bNeedPwd = FALSE ;
  3877. BOOL bDebug = FALSE ;
  3878. DWORD dwId = 0;
  3879. TARRAY arrResults = NULL;
  3880. FILE *stream = NULL;
  3881. WCHAR *szServer = NULL;
  3882. WCHAR *szUser = NULL;
  3883. WCHAR szPassword[MAX_STRING_LENGTH] = NULL_STRING;
  3884. WCHAR szPath[MAX_STRING_LENGTH] = NULL_STRING;
  3885. TCHAR szDebug[MAX_RES_STRING+1] = NULL_STRING ;
  3886. TCHAR szPort[MAX_RES_STRING+1] = NULL_STRING ;
  3887. TCHAR szBoot[MAX_RES_STRING+1] = NULL_STRING ;
  3888. BOOL bRes = FALSE ;
  3889. LPTSTR szFinalStr = NULL ;
  3890. BOOL bFlag = FALSE ;
  3891. DWORD dwCount = 0 ;
  3892. DWORD dwSectionFlag = 0 ;
  3893. TCHAR szTmpBuffer[MAX_RES_STRING+1] = NULL_STRING ;
  3894. TCHAR szBaudRate[MAX_RES_STRING+1] = NULL_STRING ;
  3895. TCHAR szString[255] = NULL_STRING ;
  3896. TCHAR szTemp[MAX_RES_STRING+1] = NULL_STRING ;
  3897. TCHAR *szValues[2] = {NULL};
  3898. DWORD dwCode = 0 ;
  3899. LPCTSTR szToken = NULL ;
  3900. DWORD dwRetVal = 0 ;
  3901. BOOL bConnFlag = FALSE ;
  3902. TCMDPARSER2 cmdOptions[9];
  3903. PTCMDPARSER2 pcmdOption;
  3904. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  3905. //copy * to szPassword
  3906. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  3907. //main option
  3908. pcmdOption = &cmdOptions[0];
  3909. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3910. pcmdOption->pwszOptions = CMDOPTION_DEBUG;
  3911. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  3912. pcmdOption->dwCount = 1;
  3913. pcmdOption->pValue = &bDebug;
  3914. //server option
  3915. pcmdOption = &cmdOptions[1];
  3916. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3917. pcmdOption->pwszOptions = SWITCH_SERVER;
  3918. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  3919. pcmdOption->dwType = CP_TYPE_TEXT;
  3920. pcmdOption->dwCount = 1;
  3921. //user option
  3922. pcmdOption = &cmdOptions[2];
  3923. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3924. pcmdOption->pwszOptions = SWITCH_USER;
  3925. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  3926. pcmdOption->dwType = CP_TYPE_TEXT;
  3927. pcmdOption->dwCount = 1;
  3928. //password option
  3929. pcmdOption = &cmdOptions[3];
  3930. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3931. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  3932. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  3933. pcmdOption->dwType = CP_TYPE_TEXT;
  3934. pcmdOption->dwCount = 1;
  3935. pcmdOption->pValue = szPassword;
  3936. pcmdOption->dwLength= MAX_STRING_LENGTH;
  3937. //usage
  3938. pcmdOption = &cmdOptions[4];
  3939. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3940. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  3941. pcmdOption->dwFlags = CP2_USAGE;
  3942. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  3943. pcmdOption->dwCount = 1;
  3944. pcmdOption->pValue = &bUsage;
  3945. //id option
  3946. pcmdOption = &cmdOptions[5];
  3947. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3948. pcmdOption->pwszOptions = SWITCH_ID;
  3949. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MANDATORY;
  3950. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  3951. pcmdOption->dwCount = 1;
  3952. pcmdOption->pValue = &dwId;
  3953. //port option
  3954. pcmdOption = &cmdOptions[6];
  3955. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3956. pcmdOption->pwszOptions = SWITCH_PORT;
  3957. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MODE_VALUES | CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;
  3958. pcmdOption->dwType = CP_TYPE_TEXT;
  3959. pcmdOption->dwCount = 1;
  3960. pcmdOption->pValue = szPort;
  3961. pcmdOption->pwszValues = COM_PORT_RANGE;
  3962. pcmdOption->dwLength= MAX_STRING_LENGTH;
  3963. //baud option
  3964. pcmdOption = &cmdOptions[7];
  3965. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3966. pcmdOption->pwszOptions = SWITCH_BAUD;
  3967. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MODE_VALUES | CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;
  3968. pcmdOption->dwType = CP_TYPE_TEXT;
  3969. pcmdOption->dwCount = 1;
  3970. pcmdOption->pValue = szBaudRate;
  3971. pcmdOption->pwszValues = BAUD_RATE_VALUES_DEBUG;
  3972. pcmdOption->dwLength= MAX_STRING_LENGTH;
  3973. //default on/off option
  3974. pcmdOption = &cmdOptions[8];
  3975. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  3976. pcmdOption->pwszOptions = CMDOPTION_DEFAULT;
  3977. pcmdOption->dwFlags = CP2_DEFAULT | CP2_MANDATORY | CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;
  3978. pcmdOption->dwType = CP_TYPE_TEXT;
  3979. pcmdOption->dwCount = 1;
  3980. pcmdOption->pValue = szDebug;
  3981. pcmdOption->dwLength= MAX_STRING_LENGTH;
  3982. // Parsing the copy option switches
  3983. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  3984. {
  3985. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  3986. return (EXIT_FAILURE);
  3987. }
  3988. szServer = cmdOptions[1].pValue;
  3989. szUser = cmdOptions[2].pValue;
  3990. if( NULL == szUser )
  3991. {
  3992. szUser = (WCHAR *)AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  3993. if( NULL == szUser )
  3994. {
  3995. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  3996. return (EXIT_FAILURE);
  3997. }
  3998. }
  3999. TrimString( szServer, TRIM_ALL );
  4000. TrimString( szUser, TRIM_ALL );
  4001. TrimString( szDebug, TRIM_ALL );
  4002. TrimString( szBaudRate, TRIM_ALL );
  4003. TrimString( szPort, TRIM_ALL );
  4004. //check if usage is specified with more than one option
  4005. if( (TRUE == bUsage) && (argc > 3) )
  4006. {
  4007. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  4008. return ( EXIT_FAILURE );
  4009. }
  4010. //display an error message if the server is empty.
  4011. if( (cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  4012. {
  4013. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  4014. FreeMemory((LPVOID *)&szServer );
  4015. FreeMemory((LPVOID *)&szUser );
  4016. return EXIT_FAILURE ;
  4017. }
  4018. //display an error message if the user is empty.
  4019. if((cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser, 0)==0 ))
  4020. {
  4021. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  4022. FreeMemory((LPVOID *)&szServer );
  4023. FreeMemory((LPVOID *)&szUser );
  4024. return EXIT_FAILURE ;
  4025. }
  4026. //display error message if the username is entered with out a machine name
  4027. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  4028. {
  4029. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  4030. FreeMemory((LPVOID *)&szServer );
  4031. FreeMemory((LPVOID *)&szUser );
  4032. return EXIT_FAILURE ;
  4033. }
  4034. //display error message if the user enters password without entering username
  4035. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  4036. {
  4037. ShowMessage(stderr, GetResString(IDS_PASSWD_BUT_NOUSER));
  4038. FreeMemory((LPVOID *)&szServer );
  4039. FreeMemory((LPVOID *)&szUser );
  4040. return EXIT_FAILURE ;
  4041. }
  4042. // Displaying query usage if user specified -? with -query option
  4043. if( bUsage )
  4044. {
  4045. if( CheckSystemType(szServer) == EXIT_FAILURE )
  4046. {
  4047. FreeMemory((LPVOID *)&szServer );
  4048. FreeMemory((LPVOID *)&szUser );
  4049. return (EXIT_FAILURE);
  4050. }
  4051. displayDebugUsage_X86();
  4052. FreeMemory((LPVOID *)&szServer );
  4053. FreeMemory((LPVOID *)&szUser );
  4054. return (EXIT_SUCCESS);
  4055. }
  4056. //check whether he is administrator or not
  4057. if( IsLocalSystem(szServer) )
  4058. {
  4059. if( !IsUserAdmin() )
  4060. {
  4061. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  4062. ReleaseGlobals();
  4063. return EXIT_FAILURE;
  4064. }
  4065. }
  4066. //check if invald id is entered
  4067. if(dwId <= 0)
  4068. {
  4069. ShowMessage(stderr, GetResString( IDS_INVALID_OSID));
  4070. FreeMemory((LPVOID *)&szServer );
  4071. FreeMemory((LPVOID *)&szUser );
  4072. return EXIT_FAILURE ;
  4073. }
  4074. // Displaying copy usage if user specified -? with -copy option
  4075. if(IsLocalSystem( szServer ) == FALSE )
  4076. {
  4077. // set the bNeedPwd to True or False .
  4078. if ( cmdOptions[3].dwActuals != 0 &&
  4079. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  4080. {
  4081. // user wants the utility to prompt for the password before trying to connect
  4082. bNeedPwd = TRUE;
  4083. }
  4084. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  4085. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  4086. {
  4087. // -s, -u is specified without password ...
  4088. // utility needs to try to connect first and if it fails then prompt for the password
  4089. bNeedPwd = TRUE;
  4090. if ( szPassword != NULL )
  4091. {
  4092. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  4093. }
  4094. }
  4095. }
  4096. //display an error message if the user specifies any string other than on,off,edit.
  4097. if( !( ( StringCompare(szDebug, VALUE_ON, TRUE, 0)== 0)|| (StringCompare(szDebug, VALUE_OFF, TRUE, 0)== 0) ||(StringCompare(szDebug,EDIT_STRING, TRUE, 0)== 0) ))
  4098. {
  4099. szValues[0]= (_TCHAR *)szDebug ;
  4100. szValues[1]= (_TCHAR *)CMDOPTION_DEBUG ;
  4101. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  4102. FreeMemory((LPVOID *)&szServer );
  4103. FreeMemory((LPVOID *)&szUser );
  4104. return EXIT_FAILURE;
  4105. }
  4106. if( (StringCompare(szDebug, EDIT_STRING, TRUE, 0)== 0)&& (StringLength(szPort, 0)==0) && (StringLengthW(szBaudRate, 0)==0) )
  4107. {
  4108. ShowMessage(stderr,GetResString(IDS_INVALID_EDIT_SYNTAX));
  4109. FreeMemory((LPVOID *)&szServer );
  4110. FreeMemory((LPVOID *)&szUser );
  4111. return EXIT_FAILURE;
  4112. }
  4113. // Establishing connection to the specified machine and getting the file pointer
  4114. // of the boot.ini file if there is no error while establishing connection
  4115. arrResults = CreateDynamicArray();
  4116. if(arrResults == NULL)
  4117. {
  4118. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4119. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  4120. FreeMemory((LPVOID *)&szServer );
  4121. FreeMemory((LPVOID *)&szUser );
  4122. return (EXIT_FAILURE);
  4123. }
  4124. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  4125. {
  4126. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  4127. {
  4128. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  4129. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  4130. {
  4131. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  4132. return (EXIT_FAILURE);
  4133. }
  4134. StringCopy(szServer,szToken, GetBufferSize(szServer)/sizeof(WCHAR));
  4135. }
  4136. }
  4137. // display a warning message if it is a local system and set the
  4138. // server name to empty.
  4139. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  4140. {
  4141. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  4142. }
  4143. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  4144. if(bFlag == EXIT_FAILURE)
  4145. {
  4146. SafeCloseConnection(szServer,bConnFlag);
  4147. FreeMemory((LPVOID *)&szServer );
  4148. FreeMemory((LPVOID *)&szUser );
  4149. return (EXIT_FAILURE);
  4150. }
  4151. arrResults = getKeyValueOfINISection( szPath, OS_FIELD );
  4152. if(arrResults == NULL)
  4153. {
  4154. resetFileAttrib(szPath);
  4155. SAFECLOSE(stream);
  4156. DestroyDynamicArray(&arrResults);
  4157. SafeCloseConnection(szServer,bConnFlag);
  4158. FreeMemory((LPVOID *)&szServer );
  4159. FreeMemory((LPVOID *)&szUser );
  4160. return EXIT_FAILURE ;
  4161. }
  4162. //getting the number of boot entries
  4163. dwCount = DynArrayGetCount(arrResults);
  4164. if(dwId<=0 || dwId > dwCount )
  4165. {
  4166. ShowMessage(stderr,GetResString(IDS_INVALID_OSID));
  4167. resetFileAttrib(szPath);
  4168. SAFECLOSE(stream);
  4169. DestroyDynamicArray(&arrResults);
  4170. SafeCloseConnection(szServer,bConnFlag);
  4171. FreeMemory((LPVOID *)&szServer );
  4172. FreeMemory((LPVOID *)&szUser );
  4173. return EXIT_FAILURE ;
  4174. }
  4175. if( (DWORD) StringLengthW( DynArrayItemAsString(arrResults, dwId - 1 ),0 ) > MAX_RES_STRING )
  4176. {
  4177. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  4178. resetFileAttrib(szPath);
  4179. SAFECLOSE(stream);
  4180. DestroyDynamicArray(&arrResults);
  4181. SafeCloseConnection(szServer,bConnFlag);
  4182. FreeMemory((LPVOID *)&szServer );
  4183. FreeMemory((LPVOID *)&szUser );
  4184. return EXIT_FAILURE ;
  4185. }
  4186. StringCopy(szString ,DynArrayItemAsString(arrResults, dwId - 1 ), SIZE_OF_ARRAY(szString));
  4187. if(StringLengthW(szString, 0) == 0)
  4188. {
  4189. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4190. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  4191. resetFileAttrib(szPath);
  4192. SAFECLOSE(stream);
  4193. DestroyDynamicArray(&arrResults);
  4194. SafeCloseConnection(szServer,bConnFlag);
  4195. FreeMemory((LPVOID *)&szServer );
  4196. FreeMemory((LPVOID *)&szUser );
  4197. return EXIT_FAILURE ;
  4198. }
  4199. // check if the user entered the value of debug as on and do accordingly
  4200. if( StringCompare(szDebug,VALUE_ON, TRUE, 0)== 0)
  4201. {
  4202. //check if the debug switch is already present and if so display a error message.
  4203. if( (FindString(szString,DEBUG_SWITCH,0) != NULL ) && ( (StringLengthW(szPort,0)== 0)&&(StringLengthW(szBaudRate,0)== 0) ) )
  4204. {
  4205. ShowMessage(stderr,GetResString(IDS_DUPL_DEBUG));
  4206. resetFileAttrib(szPath);
  4207. SAFECLOSE(stream);
  4208. DestroyDynamicArray(&arrResults);
  4209. SafeCloseConnection(szServer,bConnFlag);
  4210. FreeMemory((LPVOID *)&szServer );
  4211. FreeMemory((LPVOID *)&szUser );
  4212. return EXIT_FAILURE ;
  4213. }
  4214. else
  4215. {
  4216. if(FindString(szString,DEBUG_SWITCH, 0) == NULL )
  4217. {
  4218. StringCopy(szTmpBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szTmpBuffer));
  4219. StringConcat(szTmpBuffer,DEBUG_SWITCH, SIZE_OF_ARRAY(szTmpBuffer));
  4220. }
  4221. }
  4222. // check already com port present or not
  4223. dwCode = GetSubString(szString,TOKEN_DEBUGPORT,szTemp);
  4224. if((EXIT_SUCCESS == dwCode) && (StringLengthW(szTemp, 0 )!= 0)&& (StringLengthW(szPort, 0)!= 0))
  4225. {
  4226. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_DUPLICATE_COM_PORT), dwId );
  4227. resetFileAttrib(szPath);
  4228. SAFECLOSE(stream);
  4229. DestroyDynamicArray(&arrResults);
  4230. SafeCloseConnection(szServer,bConnFlag);
  4231. FreeMemory((LPVOID *)&szServer );
  4232. FreeMemory((LPVOID *)&szUser );
  4233. return EXIT_FAILURE ;
  4234. }
  4235. // get the type of the Com port present
  4236. dwCode = GetSubString(szString,PORT_1394,szTemp);
  4237. if( StringLengthW(szTemp, 0)!= 0 && EXIT_SUCCESS == dwCode)
  4238. {
  4239. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_1394_COM_PORT), dwId );
  4240. resetFileAttrib(szPath);
  4241. SAFECLOSE(stream);
  4242. DestroyDynamicArray(&arrResults);
  4243. SafeCloseConnection(szServer,bConnFlag);
  4244. FreeMemory((LPVOID *)&szServer );
  4245. FreeMemory((LPVOID *)&szUser );
  4246. return EXIT_FAILURE ;
  4247. }
  4248. // if the debug port is specified by the user
  4249. if(StringLengthW(szPort, 0)!= 0)
  4250. {
  4251. // compare that with the redirected port in boot loader section
  4252. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  4253. if (dwSectionFlag == EXIT_FAILURE)
  4254. {
  4255. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  4256. resetFileAttrib(szPath);
  4257. SAFECLOSE(stream);
  4258. DestroyDynamicArray(&arrResults);
  4259. SafeCloseConnection(szServer,bConnFlag);
  4260. FreeMemory((LPVOID *)&szServer );
  4261. FreeMemory((LPVOID *)&szUser );
  4262. return EXIT_FAILURE ;
  4263. }
  4264. if(StringLengthW(szBoot, 0)!= 0)
  4265. {
  4266. if (StringCompare(szBoot,szPort, TRUE, 0)==0)
  4267. {
  4268. ShowMessage( stderr, GetResString(IDS_ERROR_REDIRECT_PORT));
  4269. resetFileAttrib(szPath);
  4270. SAFECLOSE(stream);
  4271. DestroyDynamicArray(&arrResults);
  4272. SafeCloseConnection(szServer,bConnFlag);
  4273. FreeMemory((LPVOID *)&szServer );
  4274. FreeMemory((LPVOID *)&szUser );
  4275. return EXIT_FAILURE ;
  4276. }
  4277. }
  4278. if( StringLength(szTmpBuffer,0)== 0 )
  4279. {
  4280. StringCopy(szTmpBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szTmpBuffer));
  4281. }
  4282. else
  4283. {
  4284. StringConcat(szTmpBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szTmpBuffer));
  4285. }
  4286. StringConcat(szTmpBuffer,TOKEN_DEBUGPORT, SIZE_OF_ARRAY(szTmpBuffer)) ;
  4287. StringConcat(szTmpBuffer,TOKEN_EQUAL, SIZE_OF_ARRAY(szTmpBuffer)) ;
  4288. CharLower(szPort);
  4289. StringConcat(szTmpBuffer,szPort, SIZE_OF_ARRAY(szTmpBuffer));
  4290. }
  4291. StringCopy(szTemp,NULL_STRING, SIZE_OF_ARRAY(szTemp));
  4292. GetBaudRateVal(szString,szTemp) ;
  4293. //to add the Baud rate value specified by the user.
  4294. if(StringLengthW(szBaudRate, 0)!=0)
  4295. {
  4296. if(StringLengthW(szTemp, 0)!= 0)
  4297. {
  4298. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_DUPLICATE_BAUD_VAL), dwId );
  4299. resetFileAttrib(szPath);
  4300. SAFECLOSE(stream);
  4301. DestroyDynamicArray(&arrResults);
  4302. SafeCloseConnection(szServer,bConnFlag);
  4303. FreeMemory((LPVOID *)&szServer );
  4304. FreeMemory((LPVOID *)&szUser );
  4305. return EXIT_FAILURE ;
  4306. }
  4307. else
  4308. {
  4309. //forming the string to be concatenated to the BootEntry string
  4310. if( StringLength(szTmpBuffer,0)== 0 )
  4311. {
  4312. StringCopy(szTmpBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szTmpBuffer));
  4313. }
  4314. else
  4315. {
  4316. StringConcat(szTmpBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szTmpBuffer));
  4317. }
  4318. StringConcat(szTmpBuffer,BAUD_RATE, SIZE_OF_ARRAY(szTmpBuffer));
  4319. StringConcat(szTmpBuffer,TOKEN_EQUAL, SIZE_OF_ARRAY(szTmpBuffer));
  4320. StringConcat(szTmpBuffer,szBaudRate, SIZE_OF_ARRAY(szTmpBuffer));
  4321. }
  4322. }
  4323. }
  4324. else if( StringCompare(szDebug,VALUE_OFF, TRUE, 0)== 0)
  4325. {
  4326. if((StringLengthW(szPort, 0)!= 0) || (StringLengthW(szBaudRate, 0)!= 0))
  4327. {
  4328. DestroyDynamicArray(&arrResults);
  4329. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  4330. resetFileAttrib(szPath);
  4331. SAFECLOSE(stream);
  4332. SafeCloseConnection(szServer,bConnFlag);
  4333. FreeMemory((LPVOID *)&szServer );
  4334. FreeMemory((LPVOID *)&szUser );
  4335. return EXIT_FAILURE ;
  4336. }
  4337. if (FindString(szString,DEBUG_SWITCH, 0) == 0 )
  4338. {
  4339. ShowMessage(stderr,GetResString(IDS_DEBUG_ABSENT));
  4340. resetFileAttrib(szPath);
  4341. SAFECLOSE(stream);
  4342. DestroyDynamicArray(&arrResults);
  4343. SafeCloseConnection(szServer,bConnFlag);
  4344. FreeMemory((LPVOID *)&szServer );
  4345. FreeMemory((LPVOID *)&szUser );
  4346. return EXIT_FAILURE ;
  4347. }
  4348. else
  4349. {
  4350. // remove the /debug switch.
  4351. if( EXIT_FAILURE == removeSubString(szString,DEBUG_SWITCH) )
  4352. {
  4353. resetFileAttrib(szPath);
  4354. SAFECLOSE(stream);
  4355. DestroyDynamicArray(&arrResults);
  4356. SafeCloseConnection(szServer,bConnFlag);
  4357. FreeMemory((LPVOID *)&szServer );
  4358. FreeMemory((LPVOID *)&szUser );
  4359. return EXIT_FAILURE ;
  4360. }
  4361. StringCopy(szTemp,NULL_STRING, SIZE_OF_ARRAY(szTemp));
  4362. // get the type of the Com port present
  4363. dwCode = GetSubString(szString,TOKEN_DEBUGPORT,szTemp);
  4364. if(StringCompare(szTemp,PORT_1394, TRUE, 0)==0)
  4365. {
  4366. ShowMessage(stderr,GetResString(IDS_ERROR_1394_REMOVE));
  4367. resetFileAttrib(szPath);
  4368. SAFECLOSE(stream);
  4369. DestroyDynamicArray(&arrResults);
  4370. SafeCloseConnection(szServer,bConnFlag);
  4371. FreeMemory((LPVOID *)&szServer );
  4372. FreeMemory((LPVOID *)&szUser );
  4373. return EXIT_FAILURE ;
  4374. }
  4375. // remove the /debugport=comport switch if it is present from the Boot Entry
  4376. if (StringLengthW(szTemp, 0)!= 0)
  4377. {
  4378. if( EXIT_FAILURE == removeSubString(szString,szTemp) )
  4379. {
  4380. resetFileAttrib(szPath);
  4381. SAFECLOSE(stream);
  4382. DestroyDynamicArray(&arrResults);
  4383. SafeCloseConnection(szServer,bConnFlag);
  4384. FreeMemory((LPVOID *)&szServer );
  4385. FreeMemory((LPVOID *)&szUser );
  4386. return EXIT_FAILURE ;
  4387. }
  4388. }
  4389. StringCopy(szTemp , NULL_STRING, SIZE_OF_ARRAY(szTemp) );
  4390. //remove the baud rate switch if it is present.
  4391. GetBaudRateVal(szString,szTemp) ;
  4392. if (StringLengthW(szTemp, 0)!= 0)
  4393. {
  4394. if( EXIT_FAILURE == removeSubString(szString,szTemp))
  4395. {
  4396. resetFileAttrib(szPath);
  4397. SAFECLOSE(stream);
  4398. DestroyDynamicArray(&arrResults);
  4399. SafeCloseConnection(szServer,bConnFlag);
  4400. FreeMemory((LPVOID *)&szServer );
  4401. FreeMemory((LPVOID *)&szUser );
  4402. return EXIT_FAILURE ;
  4403. }
  4404. }
  4405. }
  4406. }
  4407. // if the user enters the EDIT option
  4408. else if(StringCompare(szDebug,SWITCH_EDIT, TRUE, 0)== 0)
  4409. {
  4410. //display error message if the /debugport=1394 switch is present already.
  4411. if(FindString(szString,DEBUGPORT_1394, 0)!=0)
  4412. {
  4413. ShowMessage(stderr,GetResString(IDS_ERROR_EDIT_1394_SWITCH));
  4414. resetFileAttrib(szPath);
  4415. SAFECLOSE(stream);
  4416. DestroyDynamicArray(&arrResults);
  4417. SafeCloseConnection(szServer,bConnFlag);
  4418. FreeMemory((LPVOID *)&szServer );
  4419. FreeMemory((LPVOID *)&szUser );
  4420. return EXIT_FAILURE ;
  4421. }
  4422. //display error message if debug switch is not present
  4423. if (FindString(szString,DEBUG_SWITCH,0) == 0 )
  4424. {
  4425. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_NO_DBG_SWITCH), dwId );
  4426. resetFileAttrib(szPath);
  4427. SAFECLOSE(stream);
  4428. DestroyDynamicArray(&arrResults);
  4429. SafeCloseConnection(szServer,bConnFlag);
  4430. FreeMemory((LPVOID *)&szServer );
  4431. FreeMemory((LPVOID *)&szUser );
  4432. return EXIT_FAILURE ;
  4433. }
  4434. StringCopy(szTemp,NULL_STRING, SIZE_OF_ARRAY(szTemp));
  4435. dwCode = GetSubString(szString,TOKEN_DEBUGPORT,szTemp);
  4436. //display an error message if user is trying to add baudrate value
  4437. // when there is no COM port present in the boot options.
  4438. // chk if the port has been spec by the user
  4439. if((StringLengthW(szPort, 0)== 0)&&(StringLengthW(szBaudRate, 0)== 0))
  4440. {
  4441. DestroyDynamicArray(&arrResults);
  4442. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  4443. resetFileAttrib(szPath);
  4444. SAFECLOSE(stream);
  4445. SafeCloseConnection(szServer,bConnFlag);
  4446. FreeMemory((LPVOID *)&szServer );
  4447. FreeMemory((LPVOID *)&szUser );
  4448. return EXIT_FAILURE ;
  4449. }
  4450. if(StringLengthW(szPort, 0)!= 0)
  4451. {
  4452. StringCopy(szTemp , NULL_STRING, SIZE_OF_ARRAY(szTemp) );
  4453. // get the type of the Com port present
  4454. dwCode = GetSubString(szString,TOKEN_DEBUGPORT,szTemp);
  4455. //display error message if there is no COM port found at all in the OS option
  4456. //changed for displaying error
  4457. if(StringLengthW(szTemp,0 )== 0 )
  4458. {
  4459. ShowMessageEx(stderr, TRUE, 1, GetResString(IDS_ERROR_NO_COM_PORT), dwId );
  4460. bRes = resetFileAttrib(szPath);
  4461. SAFECLOSE(stream);
  4462. DestroyDynamicArray(&arrResults);
  4463. SafeCloseConnection(szServer,bConnFlag);
  4464. FreeMemory((LPVOID *)&szServer );
  4465. FreeMemory((LPVOID *)&szUser );
  4466. return EXIT_FAILURE ;
  4467. }
  4468. // remove the /debugport=comport switch if it is present from the Boot Entry
  4469. if( EXIT_FAILURE == removeSubString(szString,szTemp) )
  4470. {
  4471. resetFileAttrib(szPath);
  4472. SAFECLOSE(stream);
  4473. DestroyDynamicArray(&arrResults);
  4474. SafeCloseConnection(szServer,bConnFlag);
  4475. FreeMemory((LPVOID *)&szServer );
  4476. FreeMemory((LPVOID *)&szUser );
  4477. return EXIT_FAILURE ;
  4478. }
  4479. StringCopy(szTmpBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szTmpBuffer));
  4480. StringConcat(szTmpBuffer,TOKEN_DEBUGPORT, SIZE_OF_ARRAY(szTmpBuffer)) ;
  4481. StringConcat(szTmpBuffer,TOKEN_EQUAL, SIZE_OF_ARRAY(szTmpBuffer));
  4482. CharUpper(szPort) ;
  4483. StringConcat(szTmpBuffer,szPort, SIZE_OF_ARRAY(szTmpBuffer));
  4484. //check if redirect port is same as that of changed port for this boot entry
  4485. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  4486. if (dwSectionFlag == EXIT_FAILURE)
  4487. {
  4488. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  4489. ShowLastError(stderr);
  4490. resetFileAttrib(szPath);
  4491. SAFECLOSE(stream);
  4492. DestroyDynamicArray(&arrResults);
  4493. SafeCloseConnection(szServer,bConnFlag);
  4494. FreeMemory((LPVOID *)&szServer );
  4495. FreeMemory((LPVOID *)&szUser );
  4496. return EXIT_FAILURE ;
  4497. }
  4498. if(StringLengthW(szBoot, 0)!= 0)
  4499. {
  4500. if (StringCompare(szBoot,szPort, TRUE, 0)==0)
  4501. {
  4502. ShowMessage( stderr, GetResString(IDS_ERROR_REDIRECT_PORT));
  4503. resetFileAttrib(szPath);
  4504. SAFECLOSE(stream);
  4505. DestroyDynamicArray(&arrResults);
  4506. SafeCloseConnection(szServer,bConnFlag);
  4507. FreeMemory((LPVOID *)&szServer );
  4508. FreeMemory((LPVOID *)&szUser );
  4509. return EXIT_FAILURE ;
  4510. }
  4511. }
  4512. }
  4513. //to edit the baud rate value
  4514. if(StringLengthW(szBaudRate, 0)!= 0)
  4515. {
  4516. StringCopy(szTemp , NULL_STRING, SIZE_OF_ARRAY(szTemp) );
  4517. //remove the baud rate switch if it is present.
  4518. GetBaudRateVal(szString,szTemp) ;
  4519. // remove the swithc to be changed.
  4520. if( EXIT_FAILURE == removeSubString(szString,szTemp) )
  4521. {
  4522. resetFileAttrib(szPath);
  4523. SAFECLOSE(stream);
  4524. DestroyDynamicArray(&arrResults);
  4525. SafeCloseConnection(szServer,bConnFlag);
  4526. FreeMemory((LPVOID *)&szServer );
  4527. FreeMemory((LPVOID *)&szUser );
  4528. return (EXIT_FAILURE);
  4529. }
  4530. //forming the string to be concatenated to the BootEntry string
  4531. if( StringLength(szTmpBuffer,0) == 0 )
  4532. {
  4533. StringCopy(szTmpBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szTmpBuffer));
  4534. }
  4535. else
  4536. {
  4537. StringConcat(szTmpBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szTmpBuffer));
  4538. }
  4539. StringConcat(szTmpBuffer,BAUD_RATE, SIZE_OF_ARRAY(szTmpBuffer));
  4540. StringConcat(szTmpBuffer,TOKEN_EQUAL, SIZE_OF_ARRAY(szTmpBuffer));
  4541. StringConcat(szTmpBuffer,szBaudRate, SIZE_OF_ARRAY(szTmpBuffer));
  4542. }
  4543. }
  4544. //now check if length exceeds the max length allowed for boot entry
  4545. if( StringLength(szString, 0 )+StringLength(szTmpBuffer,0) > MAX_RES_STRING )
  4546. {
  4547. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  4548. resetFileAttrib(szPath);
  4549. SAFECLOSE(stream);
  4550. DestroyDynamicArray(&arrResults);
  4551. SafeCloseConnection(szServer,bConnFlag);
  4552. FreeMemory((LPVOID *)&szServer );
  4553. FreeMemory((LPVOID *)&szUser );
  4554. return EXIT_FAILURE ;
  4555. }
  4556. else
  4557. {
  4558. //append the string containing the modified port value to the string
  4559. StringConcat(szString,szTmpBuffer, SIZE_OF_ARRAY(szString));
  4560. }
  4561. //remove the existing entry
  4562. DynArrayRemove(arrResults, dwId - 1 );
  4563. //insert the new entry
  4564. DynArrayInsertString(arrResults, dwId - 1, szString, 0);
  4565. // Forming the final string from all the key-value pairs
  4566. if (stringFromDynamicArray2( arrResults,&szFinalStr) == EXIT_FAILURE)
  4567. {
  4568. DestroyDynamicArray(&arrResults);
  4569. SAFEFREE(szFinalStr);
  4570. resetFileAttrib(szPath);
  4571. SAFECLOSE(stream);
  4572. SafeCloseConnection(szServer,bConnFlag);
  4573. FreeMemory((LPVOID *)&szServer );
  4574. FreeMemory((LPVOID *)&szUser );
  4575. return EXIT_FAILURE;
  4576. }
  4577. // Writing to the profile section with new key-value pair
  4578. // If the return value is non-zero, then there is an error.
  4579. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  4580. {
  4581. ShowMessageEx(stdout, 1, TRUE, GetResString(IDS_SWITCH_CHANGE), dwId );
  4582. }
  4583. else
  4584. {
  4585. SaveLastError();
  4586. ShowLastError(stderr);
  4587. ShowMessage(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  4588. DestroyDynamicArray(&arrResults);
  4589. resetFileAttrib(szPath);
  4590. SAFEFREE(szFinalStr);
  4591. SAFECLOSE(stream);
  4592. SafeCloseConnection(szServer,bConnFlag);
  4593. FreeMemory((LPVOID *)&szServer );
  4594. FreeMemory((LPVOID *)&szUser );
  4595. return (EXIT_FAILURE);
  4596. }
  4597. bRes = resetFileAttrib(szPath);
  4598. SAFEFREE(szFinalStr);
  4599. SAFECLOSE(stream);
  4600. SafeCloseConnection(szServer,bConnFlag);
  4601. DestroyDynamicArray(&arrResults);
  4602. FreeMemory((LPVOID *)&szServer );
  4603. FreeMemory((LPVOID *)&szUser );
  4604. return (bRes) ;
  4605. }
  4606. VOID GetBaudRateVal(LPTSTR szString, LPTSTR szTemp)
  4607. /*++
  4608. Routine Description : Get the Type of Baud Rate present in Boot Entry
  4609. Parameters : szString : The String which is to be searched.
  4610. szTemp : String which will get the com port type
  4611. Return Type : VOID
  4612. --*/
  4613. {
  4614. if(FindString(szString,BAUD_VAL6,0)!=0)
  4615. {
  4616. StringCopy(szTemp,BAUD_VAL6, MAX_RES_STRING);
  4617. }
  4618. else if(FindString(szString,BAUD_VAL7,0)!=0)
  4619. {
  4620. StringCopy(szTemp,BAUD_VAL7, MAX_RES_STRING);
  4621. }
  4622. else if(FindString(szString,BAUD_VAL8,0)!=0)
  4623. {
  4624. StringCopy(szTemp,BAUD_VAL8, MAX_RES_STRING);
  4625. }
  4626. else if(FindString(szString,BAUD_VAL9,0)!=0)
  4627. {
  4628. StringCopy(szTemp,BAUD_VAL9, MAX_RES_STRING);
  4629. }
  4630. else if(FindString(szString,BAUD_VAL10,0)!=0)
  4631. {
  4632. StringCopy(szTemp,BAUD_VAL10, MAX_RES_STRING);
  4633. }
  4634. }
  4635. DWORD
  4636. ProcessEmsSwitch( IN DWORD argc,
  4637. IN LPCTSTR argv[]
  4638. )
  4639. /*++
  4640. Routine Description:
  4641. Implement the ProcessEmsSwitch switch.
  4642. Arguments:
  4643. [IN] argc Number of command line arguments
  4644. [IN] argv Array containing command line arguments
  4645. Return Value:
  4646. DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  4647. --*/
  4648. {
  4649. BOOL bUsage = FALSE ;
  4650. BOOL bNeedPwd = FALSE ;
  4651. BOOL bEms = FALSE ;
  4652. DWORD dwId = 0;
  4653. TARRAY arrResults = NULL;
  4654. TARRAY arrBootIni = NULL;
  4655. FILE *stream = NULL;
  4656. // Initialising the variables that are passed to TCMDPARSER structure
  4657. WCHAR *szServer = NULL;
  4658. WCHAR *szUser = NULL;
  4659. WCHAR szPassword[MAX_RES_STRING+1] = NULL_STRING;
  4660. WCHAR szPath[MAX_RES_STRING+1] = NULL_STRING;
  4661. TCHAR szPort[MAX_RES_STRING+1] = NULL_STRING ;
  4662. BOOL bRes = FALSE ;
  4663. BOOL bFlag = FALSE ;
  4664. DWORD dwCount = 0 ;
  4665. TCHAR szDefault[MAX_RES_STRING+1] = NULL_STRING ;
  4666. TCHAR szString[255] = NULL_STRING ;
  4667. TCHAR szBaudRate[MAX_RES_STRING+1] = NULL_STRING ;
  4668. TCHAR szBoot[MAX_RES_STRING+1] = NULL_STRING ;
  4669. LPTSTR szFinalStr = NULL ;
  4670. BOOL bRedirectFlag = FALSE ;
  4671. TCHAR szRedirectBaudrate[MAX_RES_STRING+1] = NULL_STRING ;
  4672. BOOL bRedirectBaudFlag = FALSE ;
  4673. DWORD dwSectionFlag = FALSE ;
  4674. TCHAR szDebugPort[MAX_RES_STRING+1] = NULL_STRING ;
  4675. TCHAR szBootString[MAX_RES_STRING+1] = NULL_STRING ;
  4676. DWORD dwI = 0 ;
  4677. LPCTSTR szToken = NULL ;
  4678. DWORD dwRetVal = 0 ;
  4679. BOOL bConnFlag = FALSE ;
  4680. LPWSTR pToken=NULL;
  4681. LPWSTR szTemp=NULL;
  4682. TCMDPARSER2 cmdOptions[9];
  4683. PTCMDPARSER2 pcmdOption;
  4684. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  4685. //copy * to szPassword
  4686. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  4687. //main option
  4688. pcmdOption = &cmdOptions[0];
  4689. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  4690. pcmdOption->pwszOptions = CMDOPTION_EMS;
  4691. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  4692. pcmdOption->dwCount = 1;
  4693. pcmdOption->pValue = &bEms;
  4694. //server option
  4695. pcmdOption = &cmdOptions[1];
  4696. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  4697. pcmdOption->pwszOptions = SWITCH_SERVER;
  4698. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  4699. pcmdOption->dwType = CP_TYPE_TEXT;
  4700. pcmdOption->dwCount = 1;
  4701. //user option
  4702. pcmdOption = &cmdOptions[2];
  4703. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  4704. pcmdOption->pwszOptions = SWITCH_USER;
  4705. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  4706. pcmdOption->dwType = CP_TYPE_TEXT;
  4707. pcmdOption->dwCount = 1;
  4708. //password option
  4709. pcmdOption = &cmdOptions[3];
  4710. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  4711. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  4712. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  4713. pcmdOption->dwType = CP_TYPE_TEXT;
  4714. pcmdOption->dwCount = 1;
  4715. pcmdOption->pValue = szPassword;
  4716. pcmdOption->dwLength= MAX_STRING_LENGTH;
  4717. //usage
  4718. pcmdOption = &cmdOptions[4];
  4719. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  4720. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  4721. pcmdOption->dwFlags = CP2_USAGE;
  4722. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  4723. pcmdOption->dwCount = 1;
  4724. pcmdOption->pValue = &bUsage;
  4725. //default option
  4726. pcmdOption = &cmdOptions[5];
  4727. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  4728. pcmdOption->pwszOptions = SWITCH_ID;
  4729. pcmdOption->dwFlags = CP_VALUE_MANDATORY;
  4730. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  4731. pcmdOption->dwCount = 1;
  4732. pcmdOption->pValue = &dwId;
  4733. //port option
  4734. pcmdOption = &cmdOptions[6];
  4735. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  4736. pcmdOption->pwszOptions = SWITCH_PORT;
  4737. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MODE_VALUES | CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;;
  4738. pcmdOption->dwType = CP_TYPE_TEXT;
  4739. pcmdOption->dwCount = 1;
  4740. pcmdOption->pValue = szPort;
  4741. pcmdOption->pwszValues = EMS_PORT_VALUES;
  4742. pcmdOption->dwLength= MAX_STRING_LENGTH;
  4743. //baudrate option
  4744. pcmdOption = &cmdOptions[7];
  4745. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  4746. pcmdOption->pwszOptions = SWITCH_BAUD;
  4747. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MODE_VALUES | CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;;
  4748. pcmdOption->dwType = CP_TYPE_TEXT;
  4749. pcmdOption->dwCount = 1;
  4750. pcmdOption->pValue = szBaudRate;
  4751. pcmdOption->pwszValues = BAUD_RATE_VALUES_EMS;
  4752. pcmdOption->dwLength= MAX_STRING_LENGTH;
  4753. //default on/off option
  4754. pcmdOption = &cmdOptions[8];
  4755. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  4756. pcmdOption->pwszOptions = CMDOPTION_DEFAULT;
  4757. pcmdOption->dwFlags = CP2_DEFAULT | CP2_MANDATORY | CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;;
  4758. pcmdOption->dwType = CP_TYPE_TEXT;
  4759. pcmdOption->dwCount = 1;
  4760. pcmdOption->pValue = szDefault;
  4761. pcmdOption->dwLength= MAX_STRING_LENGTH;
  4762. // Parsing the ems option switches
  4763. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  4764. {
  4765. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  4766. return (EXIT_FAILURE);
  4767. }
  4768. szServer = cmdOptions[1].pValue;
  4769. szUser = cmdOptions[2].pValue;
  4770. if( NULL == szUser )
  4771. {
  4772. szUser = (WCHAR *)AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  4773. if( NULL == szUser )
  4774. {
  4775. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  4776. return (EXIT_FAILURE);
  4777. }
  4778. }
  4779. TrimString( szServer, TRIM_ALL );
  4780. TrimString( szUser, TRIM_ALL );
  4781. //check if usage is specified with more than one option
  4782. if( (TRUE == bUsage) && (argc > 3) )
  4783. {
  4784. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_EMS));
  4785. return ( EXIT_FAILURE );
  4786. }
  4787. //display an error message if the server is empty.
  4788. if( (cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  4789. {
  4790. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  4791. FreeMemory((LPVOID *)&szServer );
  4792. FreeMemory((LPVOID *)&szUser );
  4793. return EXIT_FAILURE ;
  4794. }
  4795. //display an error message if the user is empty.
  4796. if((cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser, 0)==0 ))
  4797. {
  4798. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  4799. FreeMemory((LPVOID *)&szServer );
  4800. FreeMemory((LPVOID *)&szUser );
  4801. return EXIT_FAILURE ;
  4802. }
  4803. //display error message if the username is entered with out a machine name
  4804. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  4805. {
  4806. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  4807. FreeMemory((LPVOID *)&szServer );
  4808. FreeMemory((LPVOID *)&szUser );
  4809. return EXIT_FAILURE ;
  4810. }
  4811. //display error message if the user enters password without entering username
  4812. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  4813. {
  4814. ShowMessage(stderr, GetResString(IDS_PASSWD_BUT_NOUSER));
  4815. FreeMemory((LPVOID *)&szServer );
  4816. FreeMemory((LPVOID *)&szUser );
  4817. return EXIT_FAILURE ;
  4818. }
  4819. //if usage is specified
  4820. if(bUsage)
  4821. {
  4822. if( CheckSystemType(szServer) == EXIT_FAILURE )
  4823. {
  4824. FreeMemory((LPVOID *)&szServer );
  4825. FreeMemory((LPVOID *)&szUser );
  4826. return (EXIT_FAILURE);
  4827. }
  4828. displayEmsUsage_X86() ;
  4829. FreeMemory((LPVOID *)&szServer );
  4830. FreeMemory((LPVOID *)&szUser );
  4831. return (EXIT_SUCCESS) ;
  4832. }
  4833. //check whether the logged on user is administrator or not
  4834. if( IsLocalSystem(szServer) )
  4835. {
  4836. if( !IsUserAdmin() )
  4837. {
  4838. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  4839. ReleaseGlobals();
  4840. return EXIT_FAILURE;
  4841. }
  4842. }
  4843. //display error message if the user enters not any valid string.
  4844. if( !( ( StringCompare(szDefault,VALUE_ON, TRUE, 0)== 0) || (StringCompare(szDefault,VALUE_OFF, TRUE, 0)== 0 ) ||(StringCompare(szDefault,EDIT_STRING,TRUE,0)== 0) ) )
  4845. {
  4846. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_EMS));
  4847. FreeMemory((LPVOID *)&szServer );
  4848. FreeMemory((LPVOID *)&szUser );
  4849. return EXIT_FAILURE;
  4850. }
  4851. //display error message if either port or baud rate is not speicified along with edit option
  4852. if( (StringCompare(szDefault,EDIT_STRING,TRUE, 0)== 0)&& (StringLengthW(szPort, 0)==0) && (StringLengthW(szBaudRate, 0)==0) )
  4853. {
  4854. ShowMessage(stderr,GetResString(IDS_INVALID_EDIT_SYNTAX));
  4855. FreeMemory((LPVOID *)&szServer );
  4856. FreeMemory((LPVOID *)&szUser );
  4857. return EXIT_FAILURE;
  4858. }
  4859. //display error message if edit option is specified with /id option
  4860. if( (StringCompare(szDefault,EDIT_STRING,TRUE, 0)== 0) && (cmdOptions[5].dwActuals!=0) )
  4861. {
  4862. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_EMS));
  4863. FreeMemory((LPVOID *)&szServer );
  4864. FreeMemory((LPVOID *)&szUser );
  4865. return EXIT_FAILURE;
  4866. }
  4867. //display error message if /id is not specified with on/off values
  4868. if( ( (StringCompare(szDefault,ON_STRING,TRUE,0)== 0) || (StringCompare(szDefault,OFF_STRING,TRUE,0)== 0) )&& (cmdOptions[5].dwActuals==0) )
  4869. {
  4870. ShowMessage(stderr,GetResString(IDS_ERROR_ID_MISSING));
  4871. ShowMessage(stderr,GetResString(IDS_EMS_HELP));
  4872. FreeMemory((LPVOID *)&szServer );
  4873. FreeMemory((LPVOID *)&szUser );
  4874. return EXIT_FAILURE;
  4875. }
  4876. if(IsLocalSystem( szServer ) == FALSE )
  4877. {
  4878. // set the bNeedPwd to True or False .
  4879. if ( cmdOptions[3].dwActuals != 0 &&
  4880. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  4881. {
  4882. // user wants the utility to prompt for the password before trying to connect
  4883. bNeedPwd = TRUE;
  4884. }
  4885. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  4886. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  4887. {
  4888. // -s, -u is specified without password ...
  4889. // utility needs to try to connect first and if it fails then prompt for the password
  4890. bNeedPwd = TRUE;
  4891. if ( szPassword != NULL )
  4892. {
  4893. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  4894. }
  4895. }
  4896. }
  4897. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  4898. {
  4899. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  4900. {
  4901. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  4902. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  4903. {
  4904. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  4905. FreeMemory((LPVOID *)&szServer );
  4906. FreeMemory((LPVOID *)&szUser );
  4907. return (EXIT_FAILURE);
  4908. }
  4909. StringCopy(szServer,szToken, SIZE_OF_ARRAY_IN_CHARS(szServer));
  4910. }
  4911. }
  4912. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  4913. if(bFlag == EXIT_FAILURE)
  4914. {
  4915. SafeCloseConnection(szServer,bConnFlag);
  4916. FreeMemory((LPVOID *)&szServer );
  4917. FreeMemory((LPVOID *)&szUser );
  4918. return (EXIT_FAILURE);
  4919. }
  4920. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  4921. {
  4922. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  4923. }
  4924. arrResults = CreateDynamicArray();
  4925. if(arrResults == NULL)
  4926. {
  4927. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4928. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  4929. resetFileAttrib(szPath);
  4930. SafeCloseConnection(szServer,bConnFlag);
  4931. FreeMemory((LPVOID *)&szServer );
  4932. FreeMemory((LPVOID *)&szUser );
  4933. SAFECLOSE(stream);
  4934. return (EXIT_FAILURE);
  4935. }
  4936. arrResults = getKeyValueOfINISection( szPath, OS_FIELD );
  4937. if(arrResults != NULL)
  4938. {
  4939. //getting the number of boot entries
  4940. dwCount = DynArrayGetCount(arrResults);
  4941. //check the validity of boot entry
  4942. if( (StringCompare(szDefault,SWITCH_EDIT,TRUE,0)!= 0) )
  4943. {
  4944. if((dwId<=0 || dwId > dwCount ) )
  4945. {
  4946. ShowMessage(stderr,GetResString(IDS_INVALID_OSID));
  4947. DestroyDynamicArray(&arrResults);
  4948. resetFileAttrib(szPath);
  4949. SafeCloseConnection(szServer,bConnFlag);
  4950. SAFECLOSE(stream);
  4951. return EXIT_FAILURE ;
  4952. }
  4953. if( StringLengthW(DynArrayItemAsString(arrResults, dwId - 1 ), 0) > MAX_RES_STRING )
  4954. {
  4955. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  4956. resetFileAttrib(szPath);
  4957. DestroyDynamicArray(&arrResults);
  4958. SafeCloseConnection(szServer,bConnFlag);
  4959. SAFECLOSE(stream);
  4960. FreeMemory((LPVOID *)&szServer );
  4961. FreeMemory((LPVOID *)&szUser );
  4962. return (EXIT_FAILURE);
  4963. }
  4964. StringCopy(szString ,DynArrayItemAsString(arrResults, dwId - 1 ), SIZE_OF_ARRAY(szString));
  4965. if((StringLength(szString,0)==0))
  4966. {
  4967. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4968. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM);
  4969. resetFileAttrib(szPath);
  4970. DestroyDynamicArray(&arrResults);
  4971. SafeCloseConnection(szServer,bConnFlag);
  4972. FreeMemory((LPVOID *)&szServer );
  4973. FreeMemory((LPVOID *)&szUser );
  4974. SAFECLOSE(stream);
  4975. return EXIT_FAILURE ;
  4976. }
  4977. }
  4978. }
  4979. else
  4980. {
  4981. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4982. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM);
  4983. resetFileAttrib(szPath);
  4984. DestroyDynamicArray(&arrResults);
  4985. SafeCloseConnection(szServer,bConnFlag);
  4986. FreeMemory((LPVOID *)&szServer );
  4987. FreeMemory((LPVOID *)&szUser );
  4988. SAFECLOSE(stream);
  4989. return EXIT_FAILURE ;
  4990. }
  4991. // common code till here . from here process acc to the ON/OFF/EDIT flag.
  4992. if(StringCompare(szDefault,ON_STRING,TRUE,0)==0)
  4993. {
  4994. pToken = StrRChrW(szString, NULL, L'"');
  4995. if(NULL== pToken)
  4996. {
  4997. ShowMessage(stderr,GetResString(IDS_NO_TOKENS));
  4998. resetFileAttrib(szPath);
  4999. DestroyDynamicArray(&arrResults);
  5000. SAFECLOSE(stream);
  5001. SafeCloseConnection(szServer,bConnFlag);
  5002. FreeMemory((LPVOID *)&szServer );
  5003. FreeMemory((LPVOID *)&szUser );
  5004. return EXIT_FAILURE ;
  5005. }
  5006. pToken++;
  5007. //check if redirect port is already present
  5008. if((FindString(pToken, REDIRECT, 0) != 0))
  5009. {
  5010. ShowMessage(stderr,GetResString(IDS_DUPL_REDIRECT_SWITCH));
  5011. DestroyDynamicArray(&arrResults);
  5012. SAFECLOSE(stream);
  5013. resetFileAttrib(szPath);
  5014. SafeCloseConnection(szServer,bConnFlag);
  5015. FreeMemory((LPVOID *)&szServer );
  5016. FreeMemory((LPVOID *)&szUser );
  5017. return EXIT_FAILURE;
  5018. }
  5019. //Display an error message if there is no redirect port present in the
  5020. // bootloader section and the user also does not specify the COM port.
  5021. if ((StringLengthW(szPort, 0)== 0))
  5022. {
  5023. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  5024. if (dwSectionFlag == EXIT_FAILURE)
  5025. {
  5026. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  5027. DestroyDynamicArray(&arrResults);
  5028. SAFECLOSE(stream);
  5029. resetFileAttrib(szPath);
  5030. SafeCloseConnection(szServer,bConnFlag);
  5031. FreeMemory((LPVOID *)&szServer );
  5032. FreeMemory((LPVOID *)&szUser );
  5033. return EXIT_FAILURE;
  5034. }
  5035. if(StringLengthW(szBoot,0)== 0 )
  5036. {
  5037. ShowMessage(stderr,GetResString(IDS_ERROR_NO_PORT));
  5038. DestroyDynamicArray(&arrResults);
  5039. SAFECLOSE(stream);
  5040. resetFileAttrib(szPath);
  5041. SafeCloseConnection(szServer,bConnFlag);
  5042. FreeMemory((LPVOID *)&szServer );
  5043. FreeMemory((LPVOID *)&szUser );
  5044. return EXIT_FAILURE;
  5045. }
  5046. }
  5047. //display an error message if the Os Load Options string is more than
  5048. // 254 characters in length.
  5049. if( StringLengthW(szString, 0)+StringLengthW(TOKEN_EMPTYSPACE,0)+StringLength(REDIRECT,0) > MAX_RES_STRING)
  5050. {
  5051. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  5052. resetFileAttrib(szPath);
  5053. SafeCloseConnection(szServer,bConnFlag);
  5054. DestroyDynamicArray(&arrResults);
  5055. SAFECLOSE(stream);
  5056. FreeMemory((LPVOID *)&szServer );
  5057. FreeMemory((LPVOID *)&szUser );
  5058. return (EXIT_FAILURE);
  5059. }
  5060. //add the /redirect into the OS options.
  5061. StringConcat(szString,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szString));
  5062. StringConcat(szString,REDIRECT, SIZE_OF_ARRAY(szString));
  5063. if( (StringLengthW(szPort, 0)!= 0) || (StringLengthW(szBaudRate, 0) != 0) )
  5064. {
  5065. //retrieve the baudrate string from the boot loader string
  5066. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,BAUDRATE_STRING,szRedirectBaudrate);
  5067. if (dwSectionFlag == EXIT_FAILURE)
  5068. {
  5069. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  5070. DestroyDynamicArray(&arrResults);
  5071. SAFECLOSE(stream);
  5072. resetFileAttrib(szPath);
  5073. SafeCloseConnection(szServer,bConnFlag);
  5074. FreeMemory((LPVOID *)&szServer );
  5075. FreeMemory((LPVOID *)&szUser );
  5076. return EXIT_FAILURE;
  5077. }
  5078. //retreive the Redirect String from the Boot Loader Section
  5079. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  5080. if (dwSectionFlag == EXIT_FAILURE)
  5081. {
  5082. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  5083. DestroyDynamicArray(&arrResults);
  5084. SAFECLOSE(stream);
  5085. resetFileAttrib(szPath);
  5086. SafeCloseConnection(szServer,bConnFlag);
  5087. FreeMemory((LPVOID *)&szServer );
  5088. FreeMemory((LPVOID *)&szUser );
  5089. return EXIT_FAILURE;
  5090. }
  5091. //display warning message if the redirect=COMX entry is already present in the BootLoader section.
  5092. if( (StringLengthW(szBoot, 0)!= 0) )
  5093. {
  5094. if( StringLengthW(szPort, 0)!= 0 )
  5095. {
  5096. ShowMessage(stdout,GetResString(IDS_WARN_REDIRECT));
  5097. }
  5098. bRedirectFlag = TRUE ;
  5099. }
  5100. if( (StringLengthW(szRedirectBaudrate, 0)!=0)&&(StringLengthW(szBaudRate, 0)!= 0 ))
  5101. {
  5102. ShowMessage(stdout,GetResString(IDS_WARN_REDIRECTBAUD));
  5103. bRedirectBaudFlag = TRUE ;
  5104. }
  5105. // if the Boot loader section does not
  5106. // contain any port for redirection.
  5107. if(!bRedirectFlag)
  5108. {
  5109. if (StringCompare(szPort,USEBIOSSET,TRUE,0)== 0)
  5110. {
  5111. StringCopy(szPort,USEBIOSSETTINGS, SIZE_OF_ARRAY(szPort));
  5112. }
  5113. //
  5114. // scan the entire BOOT.INI and check if the specified Port
  5115. // is already present and if so display an error message.
  5116. //
  5117. if(StringLengthW(szPort, 0)!=0)
  5118. {
  5119. StringCopy(szDebugPort,DEBUGPORT, SIZE_OF_ARRAY(szDebugPort));
  5120. StringConcat(szDebugPort,szPort, SIZE_OF_ARRAY(szDebugPort));
  5121. }
  5122. arrBootIni = getKeyValueOfINISection( szPath, OS_FIELD );
  5123. if(arrBootIni == NULL)
  5124. {
  5125. resetFileAttrib(szPath);
  5126. SafeCloseConnection(szServer,bConnFlag);
  5127. DestroyDynamicArray(&arrResults);
  5128. SAFECLOSE(stream);
  5129. return EXIT_FAILURE ;
  5130. }
  5131. //
  5132. //loop through all the OS entries and check.
  5133. //
  5134. for(dwI = 0 ;dwI <= dwCount-1 ; dwI++ )
  5135. {
  5136. szTemp = (LPWSTR)DynArrayItemAsString(arrBootIni,dwI);
  5137. if(StringLengthW(szDebugPort, 0) !=0 )
  5138. {
  5139. CharLower(szDebugPort);
  5140. if(FindString(szTemp,szDebugPort, 0)!= 0)
  5141. {
  5142. ShowMessage( stderr, GetResString(IDS_ERROR_DEBUG_PORT));
  5143. resetFileAttrib(szPath);
  5144. SafeCloseConnection(szServer,bConnFlag);
  5145. DestroyDynamicArray(&arrResults);
  5146. DestroyDynamicArray(&arrBootIni);
  5147. SAFECLOSE(stream);
  5148. FreeMemory((LPVOID *)&szServer );
  5149. FreeMemory((LPVOID *)&szUser );
  5150. return EXIT_FAILURE ;
  5151. }
  5152. }
  5153. }
  5154. //no need free it
  5155. DestroyDynamicArray(&arrBootIni);
  5156. //convert the com port value specified by user to upper case for storing into the ini file.
  5157. CharUpper(szPort);
  5158. if( WritePrivateProfileString( BOOTLOADERSECTION,KEY_REDIRECT,szPort, szPath ) != 0 )
  5159. {
  5160. ShowMessage(stdout,GetResString(IDS_EMS_CHANGE_BOOTLOADER));
  5161. }
  5162. else
  5163. {
  5164. ShowMessage(stderr,GetResString(IDS_EMS_CHANGE_ERROR_BLOADER));
  5165. resetFileAttrib(szPath);
  5166. SafeCloseConnection(szServer,bConnFlag);
  5167. DestroyDynamicArray(&arrResults);
  5168. SAFECLOSE(stream);
  5169. FreeMemory((LPVOID *)&szServer );
  5170. FreeMemory((LPVOID *)&szUser );
  5171. return EXIT_FAILURE ;
  5172. }
  5173. }
  5174. }
  5175. if(!bRedirectBaudFlag)
  5176. {
  5177. //add the baudrate to the BOOTLOADER section.
  5178. if(StringLengthW(szBaudRate, 0) != 0 )
  5179. {
  5180. if( WritePrivateProfileString( BOOTLOADERSECTION,KEY_BAUDRATE,szBaudRate, szPath ) != 0 )
  5181. {
  5182. ShowMessage(stdout,GetResString(IDS_EMS_CHANGE_BAUDRATE));
  5183. }
  5184. else
  5185. {
  5186. ShowMessage(stderr,GetResString(IDS_EMS_CHANGE_ERROR_BAUDRATE));
  5187. resetFileAttrib(szPath);
  5188. SafeCloseConnection(szServer,bConnFlag);
  5189. DestroyDynamicArray(&arrResults);
  5190. SAFECLOSE(stream);
  5191. FreeMemory((LPVOID *)&szUser );
  5192. return EXIT_FAILURE ;
  5193. }
  5194. }
  5195. }
  5196. DynArrayRemove(arrResults, dwId - 1 );
  5197. DynArrayInsertString(arrResults, dwId - 1, szString, 0);
  5198. if (stringFromDynamicArray2( arrResults,&szFinalStr) == EXIT_FAILURE)
  5199. {
  5200. DestroyDynamicArray(&arrResults);
  5201. SAFEFREE(szFinalStr);
  5202. resetFileAttrib(szPath);
  5203. SafeCloseConnection(szServer,bConnFlag);
  5204. DestroyDynamicArray(&arrResults);
  5205. SAFECLOSE(stream);
  5206. return EXIT_FAILURE;
  5207. }
  5208. // Writing to the profile section with new key-value pair
  5209. // If the return value is non-zero, then there is an error.
  5210. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  5211. {
  5212. ShowMessageEx(stdout, 1, TRUE, GetResString(IDS_SWITCH_CHANGE), dwId );
  5213. }
  5214. else
  5215. {
  5216. ShowMessage(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  5217. SAFEFREE(szFinalStr);
  5218. resetFileAttrib(szPath);
  5219. SafeCloseConnection(szServer,bConnFlag);
  5220. DestroyDynamicArray(&arrResults);
  5221. SAFECLOSE(stream);
  5222. FreeMemory((LPVOID *)&szServer );
  5223. FreeMemory((LPVOID *)&szUser );
  5224. return (EXIT_FAILURE);
  5225. }
  5226. }
  5227. if(StringCompare(szDefault,EDIT_STRING,TRUE,0)==0)
  5228. {
  5229. if (StringCompare(szPort,USEBIOSSET,TRUE,0)== 0)
  5230. {
  5231. StringCopy(szPort,USEBIOSSETTINGS, SIZE_OF_ARRAY(szPort));
  5232. }
  5233. //get the keys of the specified ini section.
  5234. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,BAUDRATE_STRING,szRedirectBaudrate);
  5235. if (dwSectionFlag == EXIT_FAILURE)
  5236. {
  5237. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  5238. DestroyDynamicArray(&arrResults);
  5239. SAFECLOSE(stream);
  5240. SAFEFREE(szFinalStr);
  5241. resetFileAttrib(szPath);
  5242. SafeCloseConnection(szServer,bConnFlag);
  5243. FreeMemory((LPVOID *)&szServer );
  5244. FreeMemory((LPVOID *)&szUser );
  5245. return EXIT_FAILURE;
  5246. }
  5247. //get the keys of the specified ini section.
  5248. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  5249. if (dwSectionFlag == EXIT_FAILURE)
  5250. {
  5251. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  5252. DestroyDynamicArray(&arrResults);
  5253. SAFECLOSE(stream);
  5254. SAFEFREE(szFinalStr);
  5255. resetFileAttrib(szPath);
  5256. SafeCloseConnection(szServer,bConnFlag);
  5257. FreeMemory((LPVOID *)&szServer );
  5258. FreeMemory((LPVOID *)&szUser );
  5259. return EXIT_FAILURE;
  5260. }
  5261. if( (StringLengthW(szRedirectBaudrate, 0) == 0 ) && ((cmdOptions[7].dwActuals!=0)) )
  5262. {
  5263. ShowMessage( stderr,GetResString(IDS_ERROR_BAUDRATE_HELP));
  5264. DestroyDynamicArray(&arrResults);
  5265. SAFECLOSE(stream);
  5266. SAFEFREE(szFinalStr);
  5267. resetFileAttrib(szPath);
  5268. SafeCloseConnection(szServer,bConnFlag);
  5269. FreeMemory((LPVOID *)&szServer );
  5270. FreeMemory((LPVOID *)&szUser );
  5271. return EXIT_FAILURE;
  5272. }
  5273. if(StringLengthW(szPort, 0) != 0)
  5274. {
  5275. StringCopy(szDebugPort,DEBUGPORT, SIZE_OF_ARRAY(szDebugPort));
  5276. StringConcat(szDebugPort,szPort, SIZE_OF_ARRAY(szDebugPort));
  5277. }
  5278. //get the all boot entries and
  5279. //loop through all the OS entries and check if any of the
  5280. //boot entries contain the same port
  5281. arrBootIni = getKeyValueOfINISection( szPath, OS_FIELD );
  5282. if(arrBootIni == NULL)
  5283. {
  5284. resetFileAttrib(szPath);
  5285. SafeCloseConnection(szServer,bConnFlag);
  5286. DestroyDynamicArray(&arrResults);
  5287. SAFECLOSE(stream);
  5288. FreeMemory((LPVOID *)&szServer );
  5289. FreeMemory((LPVOID *)&szUser );
  5290. return EXIT_FAILURE ;
  5291. }
  5292. if(StringLengthW(szDebugPort, 0)!=0)
  5293. {
  5294. for(dwI = 0 ;dwI < dwCount-1 ; dwI++ )
  5295. {
  5296. StringCopy(szBootString ,DynArrayItemAsString(arrBootIni,dwI), MAX_RES_STRING);
  5297. CharLower(szDebugPort);
  5298. if(FindString(szBootString,szDebugPort, 0)!= 0)
  5299. {
  5300. ShowMessage( stderr, GetResString(IDS_ERROR_DEBUG_PORT));
  5301. resetFileAttrib(szPath);
  5302. SafeCloseConnection(szServer,bConnFlag);
  5303. DestroyDynamicArray(&arrResults);
  5304. DestroyDynamicArray(&arrBootIni);
  5305. SAFECLOSE(stream);
  5306. FreeMemory((LPVOID *)&szServer );
  5307. FreeMemory((LPVOID *)&szUser );
  5308. return EXIT_FAILURE ;
  5309. }
  5310. }
  5311. }
  5312. //free it, no need
  5313. DestroyDynamicArray(&arrBootIni);
  5314. // edit the Boot loader section with the redirect values entered by the user.
  5315. CharUpper(szPort);
  5316. if(StringLengthW(szPort, 0)!= 0)
  5317. {
  5318. if( WritePrivateProfileString( BOOTLOADERSECTION,KEY_REDIRECT, szPort, szPath ) != 0 )
  5319. {
  5320. ShowMessage(stdout,GetResString(IDS_EMS_CHANGE_BOOTLOADER));
  5321. }
  5322. else
  5323. {
  5324. ShowMessage(stderr,GetResString(IDS_EMS_CHANGE_ERROR_BLOADER));
  5325. resetFileAttrib(szPath);
  5326. SAFEFREE(szFinalStr);
  5327. DestroyDynamicArray(&arrResults);
  5328. SafeCloseConnection(szServer,bConnFlag);
  5329. FreeMemory((LPVOID *)&szServer );
  5330. FreeMemory((LPVOID *)&szUser );
  5331. SAFECLOSE(stream);
  5332. return EXIT_FAILURE ;
  5333. }
  5334. }
  5335. // edit the Boot loader section with the baudrate values entered by the user.
  5336. if(StringLengthW(szBaudRate, 0)!= 0)
  5337. {
  5338. if( WritePrivateProfileString( BOOTLOADERSECTION,KEY_BAUDRATE, szBaudRate, szPath ) != 0 )
  5339. {
  5340. ShowMessage(stdout,GetResString(IDS_EMS_CHANGE_BAUDRATE));
  5341. }
  5342. else
  5343. {
  5344. ShowMessage(stderr,GetResString(IDS_EMS_CHANGE_ERROR_BAUDRATE));
  5345. resetFileAttrib(szPath);
  5346. SAFEFREE(szFinalStr);
  5347. DestroyDynamicArray(&arrResults);
  5348. SAFECLOSE(stream);
  5349. SafeCloseConnection(szServer,bConnFlag);
  5350. FreeMemory((LPVOID *)&szServer );
  5351. FreeMemory((LPVOID *)&szUser );
  5352. return EXIT_FAILURE ;
  5353. }
  5354. }
  5355. }
  5356. // if the option value is off.
  5357. if(StringCompare(szDefault,VALUE_OFF,TRUE,0)==0)
  5358. {
  5359. //display an error message if either the com port or baud rate is typed in the command line
  5360. if((StringLengthW(szBaudRate, 0)!=0)||(StringLengthW(szPort, 0)!=0))
  5361. {
  5362. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_EMS));
  5363. DestroyDynamicArray(&arrResults);
  5364. SAFEFREE(szFinalStr);
  5365. SAFECLOSE(stream);
  5366. resetFileAttrib(szPath);
  5367. SafeCloseConnection(szServer,bConnFlag);
  5368. FreeMemory((LPVOID *)&szServer );
  5369. FreeMemory((LPVOID *)&szUser );
  5370. return EXIT_FAILURE;
  5371. }
  5372. // display error message if the /redirect switch is not present in the Boot.ini
  5373. pToken = StrRChrW(szString , NULL, L'"') ;
  5374. if((FindString(pToken,REDIRECT,0) == 0))
  5375. {
  5376. ShowMessage(stderr,GetResString(IDS_NO_REDIRECT_SWITCH));
  5377. DestroyDynamicArray(&arrResults);
  5378. SAFEFREE(szFinalStr);
  5379. SAFECLOSE(stream);
  5380. resetFileAttrib(szPath);
  5381. SafeCloseConnection(szServer,bConnFlag);
  5382. FreeMemory((LPVOID *)&szServer );
  5383. FreeMemory((LPVOID *)&szUser );
  5384. return EXIT_FAILURE;
  5385. }
  5386. //remove the /redirect switch from the OS entry specified .
  5387. if( EXIT_FAILURE == removeSubString(szString,REDIRECT) )
  5388. {
  5389. resetFileAttrib(szPath);
  5390. SAFECLOSE(stream);
  5391. DestroyDynamicArray(&arrResults);
  5392. SafeCloseConnection(szServer,bConnFlag);
  5393. FreeMemory((LPVOID *)&szServer );
  5394. FreeMemory((LPVOID *)&szUser );
  5395. return (EXIT_FAILURE);
  5396. }
  5397. //display an error message if the Os Load options string is more than
  5398. // 255 characters in length.
  5399. if( StringLengthW(szString, 0) > MAX_RES_STRING)
  5400. {
  5401. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  5402. resetFileAttrib(szPath);
  5403. DestroyDynamicArray(&arrResults);
  5404. SAFEFREE(szFinalStr);
  5405. SAFECLOSE(stream);
  5406. SafeCloseConnection(szServer,bConnFlag);
  5407. return (EXIT_FAILURE);
  5408. }
  5409. DynArrayRemove(arrResults, dwId - 1 );
  5410. DynArrayInsertString(arrResults, dwId - 1, szString, 0);
  5411. if (stringFromDynamicArray2( arrResults,&szFinalStr) == EXIT_FAILURE)
  5412. {
  5413. DestroyDynamicArray(&arrResults);
  5414. SAFEFREE(szFinalStr);
  5415. SAFECLOSE(stream);
  5416. resetFileAttrib(szPath);
  5417. SafeCloseConnection(szServer,bConnFlag);
  5418. FreeMemory((LPVOID *)&szServer );
  5419. FreeMemory((LPVOID *)&szUser );
  5420. return EXIT_FAILURE;
  5421. }
  5422. // Writing to the profile section with new key-value pair
  5423. // If the return value is non-zero, then there is an error.
  5424. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  5425. {
  5426. ShowMessageEx(stdout, 1, TRUE, GetResString(IDS_SWITCH_CHANGE), dwId );
  5427. }
  5428. else
  5429. {
  5430. ShowMessage(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  5431. DestroyDynamicArray(&arrResults);
  5432. SAFEFREE(szFinalStr);
  5433. resetFileAttrib(szPath);
  5434. SAFECLOSE(stream);
  5435. SafeCloseConnection(szServer,bConnFlag);
  5436. FreeMemory((LPVOID *)&szServer );
  5437. FreeMemory((LPVOID *)&szUser );
  5438. return (EXIT_FAILURE);
  5439. }
  5440. /********************************************/
  5441. // scan the entire BOOT.INI and check if the specified Port
  5442. // is already present and if so display an error message.
  5443. //
  5444. StringCopy(szRedirectBaudrate,REDIRECT_SWITCH, SIZE_OF_ARRAY(szRedirectBaudrate));
  5445. arrBootIni = getKeyValueOfINISection( szPath, OS_FIELD );
  5446. if(arrBootIni == NULL)
  5447. {
  5448. resetFileAttrib(szPath);
  5449. SafeCloseConnection(szServer,bConnFlag);
  5450. DestroyDynamicArray(&arrResults);
  5451. SAFECLOSE(stream);
  5452. FreeMemory((LPVOID *)&szServer );
  5453. FreeMemory((LPVOID *)&szUser );
  5454. return EXIT_FAILURE ;
  5455. }
  5456. //
  5457. //set the Flag to False.
  5458. //
  5459. bFlag = FALSE ;
  5460. //
  5461. // Loop through all the OS entries and check if any of the
  5462. // entries contain the /redirect switch.If not then set the
  5463. // flag to TRUE and remove the entries from Boot Loader section.
  5464. for(dwI = 0 ;dwI < dwCount ; dwI++ )
  5465. {
  5466. szTemp = (LPWSTR)DynArrayItemAsString(arrBootIni,dwI);
  5467. pToken = StrRChrW(szTemp , NULL, L'"') ;
  5468. if(NULL== pToken)
  5469. {
  5470. SAFEFREE(szFinalStr);
  5471. SAFECLOSE(stream);
  5472. bRes = resetFileAttrib(szPath);
  5473. DestroyDynamicArray(&arrResults);
  5474. DestroyDynamicArray(&arrBootIni);
  5475. SafeCloseConnection(szServer,bConnFlag);
  5476. }
  5477. pToken++;
  5478. CharLower(szRedirectBaudrate);
  5479. if( FindString(pToken, szRedirectBaudrate, 0)!= 0)
  5480. {
  5481. bFlag = TRUE ;
  5482. }
  5483. }
  5484. //free it, no need
  5485. DestroyDynamicArray(&arrBootIni);
  5486. if(FALSE == bFlag )
  5487. {
  5488. // First check if the Redirect section is present and if so delete
  5489. // the section.
  5490. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  5491. if (dwSectionFlag == EXIT_FAILURE)
  5492. {
  5493. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  5494. ShowLastError(stderr);
  5495. SAFEFREE(szFinalStr);
  5496. SAFECLOSE(stream);
  5497. bRes = resetFileAttrib(szPath);
  5498. DestroyDynamicArray(&arrResults);
  5499. SafeCloseConnection(szServer,bConnFlag);
  5500. }
  5501. //If the Redirect section is present then delete it.
  5502. if( StringLengthW(szBoot, 0) != 0)
  5503. {
  5504. if(TRUE== deleteKeyFromINISection(KEY_REDIRECT,szPath,BOOTLOADERSECTION))
  5505. {
  5506. ShowMessage(stdout,GetResString(IDS_REDIRECT_REMOVED));
  5507. }
  5508. else
  5509. {
  5510. ShowMessage(stdout,GetResString(IDS_ERROR_REDIRECT_REMOVED));
  5511. SAFEFREE(szFinalStr);
  5512. SAFECLOSE(stream);
  5513. bRes = resetFileAttrib(szPath);
  5514. DestroyDynamicArray(&arrResults);
  5515. SafeCloseConnection(szServer,bConnFlag);
  5516. }
  5517. }
  5518. // First check if the Redirect section is present and if so delete
  5519. // the section.
  5520. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,KEY_BAUDRATE,szBoot);
  5521. if (dwSectionFlag == EXIT_FAILURE)
  5522. {
  5523. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  5524. SAFEFREE(szFinalStr);
  5525. SAFECLOSE(stream);
  5526. bRes = resetFileAttrib(szPath);
  5527. DestroyDynamicArray(&arrResults);
  5528. SafeCloseConnection(szServer,bConnFlag);
  5529. FreeMemory((LPVOID *)&szServer );
  5530. FreeMemory((LPVOID *)&szUser );
  5531. return EXIT_FAILURE;
  5532. }
  5533. // First check if the Redirection baudrate section is present and if so delete
  5534. // the section.
  5535. if(StringLengthW(szBoot, 0)!=0)
  5536. {
  5537. if(TRUE == deleteKeyFromINISection(KEY_BAUDRATE,szPath,BOOTLOADERSECTION))
  5538. {
  5539. ShowMessage(stdout,GetResString(IDS_BAUDRATE_REMOVED));
  5540. }
  5541. else
  5542. {
  5543. ShowMessage(stdout,GetResString(IDS_ERROR_BAUDRATE_REMOVED));
  5544. SAFEFREE(szFinalStr);
  5545. SAFECLOSE(stream);
  5546. bRes = resetFileAttrib(szPath);
  5547. DestroyDynamicArray(&arrResults);
  5548. SafeCloseConnection(szServer,bConnFlag);
  5549. }
  5550. }
  5551. }
  5552. }
  5553. SAFEFREE(szFinalStr);
  5554. SAFECLOSE(stream);
  5555. bRes = resetFileAttrib(szPath);
  5556. DestroyDynamicArray(&arrResults);
  5557. SafeCloseConnection(szServer,bConnFlag);
  5558. FreeMemory((LPVOID *)&szServer );
  5559. FreeMemory((LPVOID *)&szUser );
  5560. return (bRes) ;
  5561. }
  5562. VOID displayEmsUsage_X86()
  5563. /*++
  5564. Routine Description : Display the help for the Ems entry option (X86).
  5565. Parameters : none
  5566. Return Type : VOID
  5567. --*/
  5568. {
  5569. DWORD dwIndex = IDS_EMS_BEGIN_X86 ;
  5570. for(;dwIndex <=IDS_EMS_END_X86;dwIndex++)
  5571. {
  5572. ShowMessage(stdout,GetResString(dwIndex));
  5573. }
  5574. }
  5575. VOID displayDebugUsage_X86()
  5576. /*++
  5577. Routine Description : Display the help for the Debug entry option (X86).
  5578. Parameters : none
  5579. Return Type : VOID
  5580. --*/
  5581. {
  5582. DWORD dwIndex = IDS_DEBUG_BEGIN_X86 ;
  5583. for(;dwIndex <=IDS_DEBUG_END_X86;dwIndex++)
  5584. {
  5585. ShowMessage(stdout,GetResString(dwIndex));
  5586. }
  5587. }
  5588. VOID displayEmsUsage_IA64()
  5589. /*++
  5590. Routine Description : Display the help for the Ems entry option (IA64).
  5591. Parameters : none
  5592. Return Type : VOID
  5593. --*/
  5594. {
  5595. DWORD dwIndex = IDS_EMS_BEGIN_IA64 ;
  5596. for(;dwIndex <=IDS_EMS_END_IA64;dwIndex++)
  5597. {
  5598. ShowMessage(stdout,GetResString(dwIndex));
  5599. }
  5600. }
  5601. VOID displayDebugUsage_IA64()
  5602. /*++
  5603. Routine Description : Display the help for the Debug entry option (IA64).
  5604. Parameters : none
  5605. Return Type : VOID
  5606. --*/
  5607. {
  5608. DWORD dwIndex = IDS_DEBUG_BEGIN_IA64 ;
  5609. for(;dwIndex <= IDS_DEBUG_END_IA64 ;dwIndex++)
  5610. {
  5611. ShowMessage(stdout,GetResString(dwIndex));
  5612. }
  5613. }
  5614. DWORD
  5615. getKeysOfSpecifiedINISection(
  5616. IN LPTSTR sziniFile,
  5617. IN LPTSTR sziniSection,
  5618. IN LPCWSTR szKeyName ,
  5619. OUT LPTSTR szValue
  5620. )
  5621. /*++
  5622. Routine Description : This function gets all the keys present in the specified section of
  5623. an .ini file and then returns the dynamic array containing all the
  5624. keys
  5625. Parameters : LPTSTR sziniFile (in) - Name of the ini file.
  5626. LPTSTR szinisection (in) - Name of the section in the boot.ini.
  5627. Return Type : EXIT_SUCCESS if successfully returns
  5628. EXIT_FAILURE otherwise
  5629. --*/
  5630. {
  5631. // Number of characters returned by the GetPrivateProfileString function
  5632. DWORD len = 0;
  5633. DWORD dwLength = MAX_STRING_LENGTH1 ;
  5634. LPTSTR inBuf = NULL ;
  5635. BOOL bNobreak = TRUE;
  5636. inBuf = (LPTSTR)AllocateMemory(dwLength*sizeof(TCHAR));
  5637. if(inBuf == NULL)
  5638. {
  5639. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  5640. SaveLastError();
  5641. return EXIT_FAILURE ;
  5642. }
  5643. do
  5644. {
  5645. // Getting all the keys from the boot.ini file
  5646. len = GetPrivateProfileString( sziniSection,
  5647. szKeyName,
  5648. ERROR_PROFILE_STRING1,
  5649. inBuf,
  5650. dwLength,
  5651. sziniFile);
  5652. //if the size of the string is not sufficient then increment the size.
  5653. if(len == dwLength-2)
  5654. {
  5655. dwLength +=100 ;
  5656. if ( inBuf != NULL )
  5657. {
  5658. FreeMemory((LPVOID *) &inBuf );
  5659. inBuf = NULL;
  5660. }
  5661. inBuf = (LPTSTR)AllocateMemory(dwLength*sizeof(TCHAR));
  5662. if(inBuf == NULL)
  5663. {
  5664. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  5665. SaveLastError();
  5666. return EXIT_FAILURE;
  5667. }
  5668. }
  5669. else
  5670. {
  5671. bNobreak = FALSE;
  5672. break ;
  5673. }
  5674. }while(TRUE == bNobreak);
  5675. //copy the value into the destination buffer only if
  5676. // the size is less than 255 else return FAILURE.
  5677. //
  5678. if(StringLengthW(inBuf, 0) <= MAX_RES_STRING)
  5679. {
  5680. StringCopy(szValue,inBuf, MAX_RES_STRING);
  5681. }
  5682. else
  5683. {
  5684. SAFEFREE(inBuf);
  5685. SetReason(GetResString(IDS_STRING_TOO_LONG));
  5686. return EXIT_FAILURE;
  5687. }
  5688. SAFEFREE(inBuf);
  5689. return EXIT_SUCCESS ;
  5690. }
  5691. DWORD
  5692. ProcessAddSwSwitch( IN DWORD argc,
  5693. IN LPCTSTR argv[]
  5694. )
  5695. /*++
  5696. Routine Description:
  5697. Implement the Add Switch switch.
  5698. Arguments:
  5699. [IN] argc Number of command line arguments
  5700. [IN] argv Array containing command line arguments
  5701. Return Value:
  5702. DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  5703. --*/
  5704. {
  5705. BOOL bUsage = FALSE ;
  5706. BOOL bNeedPwd = FALSE ;
  5707. BOOL bAddSw = FALSE ;
  5708. DWORD dwDefault = 0;
  5709. TARRAY arr = NULL;
  5710. TCHAR szkey[MAX_RES_STRING+1] = NULL_STRING;
  5711. FILE *stream = NULL;
  5712. WCHAR *szServer = NULL;
  5713. WCHAR *szUser = NULL;
  5714. WCHAR szPassword[MAX_STRING_LENGTH] = NULL_STRING;
  5715. WCHAR szPath[MAX_STRING_LENGTH] = NULL_STRING;
  5716. WCHAR szBuffer[MAX_RES_STRING+1] = NULL_STRING;
  5717. DWORD dwNumKeys = 0;
  5718. BOOL bRes = FALSE ;
  5719. LPTSTR szFinalStr = NULL ;
  5720. BOOL bFlag = FALSE ;
  5721. TCHAR szMaxmem[10] = NULL_STRING ;
  5722. BOOL bBaseVideo = FALSE ;
  5723. BOOL bSos = FALSE ;
  5724. BOOL bNoGui = FALSE ;
  5725. DWORD dwMaxmem = 0 ;
  5726. LPCTSTR szToken = NULL ;
  5727. DWORD dwRetVal = 0 ;
  5728. BOOL bConnFlag = FALSE ;
  5729. TCMDPARSER2 cmdOptions[10];
  5730. PTCMDPARSER2 pcmdOption;
  5731. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  5732. //copy * to szPassword
  5733. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  5734. //main option
  5735. pcmdOption = &cmdOptions[0];
  5736. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5737. pcmdOption->pwszOptions = CMDOPTION_ADDSW;
  5738. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  5739. pcmdOption->dwCount = 1;
  5740. pcmdOption->pValue = &bAddSw;
  5741. //server option
  5742. pcmdOption = &cmdOptions[1];
  5743. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5744. pcmdOption->pwszOptions = SWITCH_SERVER;
  5745. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  5746. pcmdOption->dwType = CP_TYPE_TEXT;
  5747. pcmdOption->dwCount = 1;
  5748. //user option
  5749. pcmdOption = &cmdOptions[2];
  5750. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5751. pcmdOption->pwszOptions = SWITCH_USER;
  5752. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  5753. pcmdOption->dwType = CP_TYPE_TEXT;
  5754. pcmdOption->dwCount = 1;
  5755. //password option
  5756. pcmdOption = &cmdOptions[3];
  5757. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5758. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  5759. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  5760. pcmdOption->dwType = CP_TYPE_TEXT;
  5761. pcmdOption->dwCount = 1;
  5762. pcmdOption->pValue = szPassword;
  5763. pcmdOption->dwLength= MAX_STRING_LENGTH;
  5764. //id usage
  5765. pcmdOption = &cmdOptions[4];
  5766. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5767. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  5768. pcmdOption->dwFlags = CP2_USAGE;
  5769. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  5770. pcmdOption->dwCount = 1;
  5771. pcmdOption->pValue = &bUsage;
  5772. //default option
  5773. pcmdOption = &cmdOptions[5];
  5774. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5775. pcmdOption->pwszOptions = SWITCH_ID;
  5776. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MANDATORY;
  5777. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  5778. pcmdOption->dwCount = 1;
  5779. pcmdOption->pValue = &dwDefault;
  5780. //maxmem option
  5781. pcmdOption = &cmdOptions[6];
  5782. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5783. pcmdOption->pwszOptions = SWITCH_MAXMEM;
  5784. pcmdOption->dwFlags = CP_VALUE_MANDATORY;
  5785. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  5786. pcmdOption->dwCount = 1;
  5787. pcmdOption->pValue = &dwMaxmem;
  5788. //basvideo option
  5789. pcmdOption = &cmdOptions[7];
  5790. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5791. pcmdOption->pwszOptions = SWITCH_BASEVIDEO;
  5792. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  5793. pcmdOption->dwCount = 1;
  5794. pcmdOption->pValue = &bBaseVideo;
  5795. //nogui option
  5796. pcmdOption = &cmdOptions[8];
  5797. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5798. pcmdOption->pwszOptions = SWITCH_NOGUIBOOT;
  5799. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  5800. pcmdOption->dwCount = 1;
  5801. pcmdOption->pValue = &bNoGui;
  5802. //nogui option
  5803. pcmdOption = &cmdOptions[9];
  5804. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  5805. pcmdOption->pwszOptions = SWITCH_SOS;
  5806. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  5807. pcmdOption->dwCount = 1;
  5808. pcmdOption->pValue = &bSos;
  5809. // Parsing the copy option switches
  5810. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  5811. {
  5812. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  5813. return (EXIT_FAILURE);
  5814. }
  5815. szServer = cmdOptions[1].pValue;
  5816. szUser = cmdOptions[2].pValue;
  5817. if( NULL == szUser )
  5818. {
  5819. szUser = (WCHAR *)AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  5820. if( NULL == szUser )
  5821. {
  5822. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  5823. return (EXIT_FAILURE);
  5824. }
  5825. }
  5826. TrimString( szServer, TRIM_ALL );
  5827. TrimString( szUser, TRIM_ALL );
  5828. //check if usage is specified with more than one option
  5829. if( (TRUE == bUsage) && (argc > 3) )
  5830. {
  5831. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_ADDSW));
  5832. return ( EXIT_FAILURE );
  5833. }
  5834. if( (cmdOptions[6].dwActuals!=0) && (dwMaxmem < 32 ) )
  5835. {
  5836. ShowMessage(stderr,GetResString(IDS_ERROR_MAXMEM_VALUES));
  5837. FreeMemory( (LPVOID *) &szServer );
  5838. FreeMemory( (LPVOID *) &szUser );
  5839. return EXIT_FAILURE ;
  5840. }
  5841. //display an error message if the server is empty.
  5842. if((cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  5843. {
  5844. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  5845. FreeMemory( (LPVOID *) &szServer );
  5846. FreeMemory( (LPVOID *) &szUser );
  5847. return EXIT_FAILURE ;
  5848. }
  5849. //display an error message if the user is empty.
  5850. if((cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser, 0)==0 ))
  5851. {
  5852. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  5853. FreeMemory( (LPVOID *) &szServer );
  5854. FreeMemory( (LPVOID *) &szUser );
  5855. return EXIT_FAILURE ;
  5856. }
  5857. //display error message if the username is entered with out a machine name
  5858. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  5859. {
  5860. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  5861. FreeMemory( (LPVOID *) &szServer );
  5862. FreeMemory( (LPVOID *) &szUser );
  5863. return EXIT_FAILURE ;
  5864. }
  5865. //display an error if password specified without user name
  5866. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  5867. {
  5868. ShowMessage(stderr, GetResString(IDS_PASSWD_BUT_NOUSER));
  5869. FreeMemory( (LPVOID *) &szServer );
  5870. FreeMemory( (LPVOID *) &szUser );
  5871. return EXIT_FAILURE ;
  5872. }
  5873. //if usage is specified
  5874. if(bUsage)
  5875. {
  5876. if( CheckSystemType(szServer) == EXIT_FAILURE )
  5877. {
  5878. FreeMemory((LPVOID *)&szServer );
  5879. FreeMemory((LPVOID *)&szUser );
  5880. return (EXIT_FAILURE);
  5881. }
  5882. displayAddSwUsage_X86();
  5883. FreeMemory( (LPVOID *) &szServer );
  5884. FreeMemory( (LPVOID *) &szUser );
  5885. return EXIT_SUCCESS;
  5886. }
  5887. //check whether he is administrator or not
  5888. if( IsLocalSystem(szServer) )
  5889. {
  5890. if( !IsUserAdmin() )
  5891. {
  5892. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  5893. ReleaseGlobals();
  5894. return EXIT_FAILURE;
  5895. }
  5896. }
  5897. //display an error message if the user does not enter even one of
  5898. if((dwMaxmem==0)&& (!bBaseVideo)&& (!bNoGui)&&(!bSos) )
  5899. {
  5900. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_ADDSW));
  5901. FreeMemory( (LPVOID *) &szServer );
  5902. FreeMemory( (LPVOID *) &szUser );
  5903. return EXIT_FAILURE ;
  5904. }
  5905. //for setting the bNeedPwd
  5906. if(IsLocalSystem( szServer ) == FALSE )
  5907. {
  5908. // set the bNeedPwd to True or False .
  5909. if ( cmdOptions[3].dwActuals != 0 &&
  5910. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  5911. {
  5912. // user wants the utility to prompt for the password before trying to connect
  5913. bNeedPwd = TRUE;
  5914. }
  5915. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  5916. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  5917. {
  5918. // -s, -u is specified without password ...
  5919. // utility needs to try to connect first and if it fails then prompt for the password
  5920. bNeedPwd = TRUE;
  5921. if ( szPassword != NULL )
  5922. {
  5923. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  5924. }
  5925. }
  5926. }
  5927. // Establishing connection to the specified machine and getting the file pointer
  5928. // of the boot.ini file if there is no error while establishing connection
  5929. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  5930. {
  5931. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  5932. {
  5933. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  5934. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  5935. {
  5936. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  5937. return (EXIT_FAILURE);
  5938. }
  5939. StringCopy(szServer,szToken, GetBufferSize(szServer)/sizeof(WCHAR));
  5940. }
  5941. }
  5942. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  5943. if(bFlag == EXIT_FAILURE)
  5944. {
  5945. SAFEFREE(szFinalStr);
  5946. SAFECLOSE(stream);
  5947. SafeCloseConnection(szServer,bConnFlag);
  5948. FreeMemory( (LPVOID *) &szServer );
  5949. FreeMemory( (LPVOID *) &szUser );
  5950. return (EXIT_FAILURE);
  5951. }
  5952. //display warning message if local credentials are supplied
  5953. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  5954. {
  5955. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  5956. }
  5957. // Getting the keys of the Operating system section in the boot.ini file
  5958. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  5959. if(arr == NULL)
  5960. {
  5961. resetFileAttrib(szPath);
  5962. SAFEFREE(szFinalStr);
  5963. SAFECLOSE(stream);
  5964. SafeCloseConnection(szServer,bConnFlag);
  5965. FreeMemory( (LPVOID *) &szServer );
  5966. FreeMemory( (LPVOID *) &szUser );
  5967. return EXIT_FAILURE ;
  5968. }
  5969. // Getting the total number of keys in the operating systems section
  5970. dwNumKeys = DynArrayGetCount(arr);
  5971. // Displaying error message if the number of keys is less than the OS entry
  5972. // line number specified by the user
  5973. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  5974. {
  5975. ShowMessage(stderr,GetResString(IDS_INVALID_BOOTID));
  5976. resetFileAttrib(szPath);
  5977. DestroyDynamicArray(&arr);
  5978. SAFEFREE(szFinalStr);
  5979. SAFECLOSE(stream);
  5980. SafeCloseConnection(szServer,bConnFlag);
  5981. FreeMemory( (LPVOID *) &szServer );
  5982. FreeMemory( (LPVOID *) &szUser );
  5983. return (EXIT_FAILURE);
  5984. }
  5985. // Getting the key of the OS entry specified by the user
  5986. if (arr != NULL)
  5987. {
  5988. LPCWSTR pwsz = NULL;
  5989. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  5990. if( StringLengthW(pwsz,0) > MAX_RES_STRING)
  5991. {
  5992. ShowMessage( stderr,GetResString(IDS_STRING_TOO_LONG));
  5993. SAFEFREE(szFinalStr);
  5994. SAFECLOSE(stream);
  5995. resetFileAttrib(szPath);
  5996. SafeCloseConnection(szServer,bConnFlag);
  5997. FreeMemory( (LPVOID *) &szServer );
  5998. FreeMemory( (LPVOID *) &szUser );
  5999. return EXIT_FAILURE;
  6000. }
  6001. if(pwsz != NULL)
  6002. {
  6003. StringCopy( szkey,pwsz, SIZE_OF_ARRAY(szkey));
  6004. }
  6005. else
  6006. {
  6007. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  6008. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM);
  6009. resetFileAttrib(szPath);
  6010. DestroyDynamicArray(&arr);
  6011. SAFEFREE(szFinalStr);
  6012. SAFECLOSE(stream);
  6013. SafeCloseConnection(szServer,bConnFlag);
  6014. FreeMemory( (LPVOID *) &szServer );
  6015. FreeMemory( (LPVOID *) &szUser );
  6016. return EXIT_FAILURE ;
  6017. }
  6018. }
  6019. else
  6020. {
  6021. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  6022. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM);
  6023. resetFileAttrib(szPath);
  6024. DestroyDynamicArray(&arr);
  6025. SAFEFREE(szFinalStr);
  6026. SAFECLOSE(stream);
  6027. SafeCloseConnection(szServer,bConnFlag);
  6028. FreeMemory( (LPVOID *) &szServer );
  6029. FreeMemory( (LPVOID *) &szUser );
  6030. return EXIT_FAILURE ;
  6031. }
  6032. //if the max mem switch is specified by the user.
  6033. if(dwMaxmem != 0)
  6034. {
  6035. if(FindString(szkey,MAXMEM_VALUE1,0) != 0)
  6036. {
  6037. ShowMessage(stderr,GetResString(IDS_DUPL_MAXMEM_SWITCH));
  6038. resetFileAttrib(szPath);
  6039. DestroyDynamicArray(&arr);
  6040. SAFEFREE(szFinalStr);
  6041. SAFECLOSE(stream);
  6042. SafeCloseConnection(szServer,bConnFlag);
  6043. FreeMemory( (LPVOID *) &szServer );
  6044. FreeMemory( (LPVOID *) &szUser );
  6045. return EXIT_FAILURE ;
  6046. }
  6047. else
  6048. {
  6049. if( StringLength( szBuffer, 0 ) == 0 )
  6050. {
  6051. StringCopy( szBuffer, TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  6052. }
  6053. else
  6054. {
  6055. StringConcat(szBuffer , TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  6056. }
  6057. StringConcat(szBuffer ,MAXMEM_VALUE1, SIZE_OF_ARRAY(szBuffer));
  6058. StringConcat(szBuffer,TOKEN_EQUAL, SIZE_OF_ARRAY(szBuffer));
  6059. _ltow(dwMaxmem,szMaxmem,10);
  6060. StringConcat(szBuffer,szMaxmem, SIZE_OF_ARRAY(szBuffer));
  6061. }
  6062. }
  6063. // if the base video is specified by the user.
  6064. if (bBaseVideo)
  6065. {
  6066. if(FindString(szkey,BASEVIDEO_VALUE, 0) != 0)
  6067. {
  6068. ShowMessage(stderr,GetResString(IDS_DUPL_BASEVIDEO_SWITCH));
  6069. resetFileAttrib(szPath);
  6070. DestroyDynamicArray(&arr);
  6071. SAFEFREE(szFinalStr);
  6072. SAFECLOSE(stream);
  6073. SafeCloseConnection(szServer,bConnFlag);
  6074. FreeMemory( (LPVOID *) &szServer );
  6075. FreeMemory( (LPVOID *) &szUser );
  6076. return EXIT_FAILURE ;
  6077. }
  6078. else
  6079. {
  6080. if( StringLength( szBuffer, 0 ) == 0 )
  6081. {
  6082. StringCopy( szBuffer, TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  6083. }
  6084. else
  6085. {
  6086. StringConcat(szBuffer , TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  6087. }
  6088. StringConcat(szBuffer ,BASEVIDEO_SWITCH, SIZE_OF_ARRAY(szBuffer));
  6089. }
  6090. }
  6091. // if the SOS is specified by the user.
  6092. if(bSos)
  6093. {
  6094. if(FindString(szkey,SOS_VALUE, 0) != 0)
  6095. {
  6096. ShowMessage(stderr,GetResString(IDS_DUPL_SOS_SWITCH ) );
  6097. resetFileAttrib(szPath);
  6098. DestroyDynamicArray(&arr);
  6099. SAFEFREE(szFinalStr);
  6100. SAFECLOSE(stream);
  6101. SafeCloseConnection(szServer,bConnFlag);
  6102. FreeMemory( (LPVOID *) &szServer );
  6103. FreeMemory( (LPVOID *) &szUser );
  6104. return EXIT_FAILURE ;
  6105. }
  6106. else
  6107. {
  6108. if( StringLength( szBuffer, 0 ) == 0 )
  6109. {
  6110. StringCopy( szBuffer, TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  6111. }
  6112. else
  6113. {
  6114. StringConcat(szBuffer , TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  6115. }
  6116. StringConcat(szBuffer ,SOS_SWITCH, SIZE_OF_ARRAY(szBuffer));
  6117. }
  6118. }
  6119. // if the noguiboot is specified by the user.
  6120. if(bNoGui)
  6121. {
  6122. if(_tcsstr(szkey,NOGUI_VALUE) != 0)
  6123. {
  6124. ShowMessage(stderr,GetResString(IDS_DUPL_NOGUI_SWITCH));
  6125. resetFileAttrib(szPath);
  6126. DestroyDynamicArray(&arr);
  6127. SAFEFREE(szFinalStr);
  6128. SAFECLOSE(stream);
  6129. SafeCloseConnection(szServer,bConnFlag);
  6130. FreeMemory( (LPVOID *) &szServer );
  6131. FreeMemory( (LPVOID *) &szUser );
  6132. return EXIT_FAILURE ;
  6133. }
  6134. else
  6135. {
  6136. if( StringLength( szBuffer, 0 ) == 0 )
  6137. {
  6138. StringCopy( szBuffer, TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  6139. }
  6140. else
  6141. {
  6142. StringConcat(szBuffer , TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  6143. }
  6144. StringConcat(szBuffer ,NOGUI_VALUE, SIZE_OF_ARRAY(szBuffer) );
  6145. }
  6146. }
  6147. if( StringLengthW(szkey, 0)+StringLengthW(szBuffer, 0) > MAX_RES_STRING)
  6148. {
  6149. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  6150. SAFEFREE(szFinalStr);
  6151. SAFECLOSE(stream);
  6152. resetFileAttrib(szPath);
  6153. SafeCloseConnection(szServer,bConnFlag);
  6154. FreeMemory( (LPVOID *) &szServer );
  6155. FreeMemory( (LPVOID *) &szUser );
  6156. return EXIT_FAILURE;
  6157. }
  6158. else
  6159. {
  6160. StringConcat(szkey , szBuffer, SIZE_OF_ARRAY(szkey));
  6161. }
  6162. DynArrayRemove(arr, dwDefault - 1 );
  6163. DynArrayInsertString(arr, dwDefault - 1, szkey, 0);
  6164. // Setting the buffer to 0, to avoid any junk value
  6165. if (stringFromDynamicArray2( arr,&szFinalStr) == EXIT_FAILURE)
  6166. {
  6167. DestroyDynamicArray(&arr);
  6168. SAFEFREE(szFinalStr);
  6169. SAFECLOSE(stream);
  6170. resetFileAttrib(szPath);
  6171. SafeCloseConnection(szServer,bConnFlag);
  6172. FreeMemory( (LPVOID *) &szServer );
  6173. FreeMemory( (LPVOID *) &szUser );
  6174. return EXIT_FAILURE;
  6175. }
  6176. // Writing to the profile section with new key-value pair
  6177. // If the return value is non-zero, then there is an error.
  6178. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  6179. {
  6180. ShowMessageEx(stdout, 1, TRUE, GetResString(IDS_SWITCH_ADD), dwDefault );
  6181. }
  6182. else
  6183. {
  6184. ShowMessage(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  6185. DestroyDynamicArray(&arr);
  6186. resetFileAttrib(szPath);
  6187. SAFEFREE(szFinalStr);
  6188. SAFECLOSE(stream);
  6189. SafeCloseConnection(szServer,bConnFlag);
  6190. FreeMemory( (LPVOID *) &szServer );
  6191. FreeMemory( (LPVOID *) &szUser );
  6192. return (EXIT_FAILURE);
  6193. }
  6194. //reset the file attributes and free the memory and close the connection to the server.
  6195. bRes = resetFileAttrib(szPath);
  6196. DestroyDynamicArray(&arr);
  6197. SAFEFREE(szFinalStr);
  6198. SAFECLOSE(stream);
  6199. SafeCloseConnection(szServer,bConnFlag);
  6200. FreeMemory( (LPVOID *) &szServer );
  6201. FreeMemory( (LPVOID *) &szUser );
  6202. return (bRes);
  6203. }
  6204. DWORD
  6205. ProcessRmSwSwitch( IN DWORD argc,
  6206. IN LPCTSTR argv[]
  6207. )
  6208. /*++
  6209. Routine Description:
  6210. This routine is to remove the switches to the boot.ini file settings for
  6211. the specified system.
  6212. Arguments:
  6213. [IN] argc Number of command line arguments
  6214. [IN] argv Array containing command line arguments
  6215. Return Value:
  6216. DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  6217. --*/
  6218. {
  6219. BOOL bUsage = FALSE ;
  6220. BOOL bNeedPwd = FALSE ;
  6221. BOOL bRmSw = FALSE ;
  6222. DWORD dwDefault = 0;
  6223. TARRAY arr = NULL ;
  6224. TCHAR szkey[255] = NULL_STRING;
  6225. FILE *stream = NULL;
  6226. WCHAR *szServer = NULL;
  6227. WCHAR *szUser = NULL;
  6228. WCHAR szPassword[MAX_STRING_LENGTH] = NULL_STRING;
  6229. WCHAR szPath[MAX_RES_STRING+1] = NULL_STRING;
  6230. DWORD dwNumKeys = 0;
  6231. BOOL bRes = FALSE ;
  6232. LPTSTR szFinalStr = NULL ;
  6233. BOOL bFlag = FALSE ;
  6234. BOOL bBaseVideo = FALSE ;
  6235. BOOL bSos = FALSE ;
  6236. BOOL bNoGui = FALSE ;
  6237. BOOL bMaxmem = 0;
  6238. TCHAR szTemp[MAX_RES_STRING+1] = NULL_STRING ;
  6239. TCHAR szErrorMsg[MAX_RES_STRING+1] = NULL_STRING ;
  6240. WCHAR szSubString[MAX_STRING_LENGTH] = NULL_STRING;
  6241. DWORD dwCode = 0;
  6242. LPCTSTR szToken = NULL ;
  6243. DWORD dwRetVal = 0;
  6244. BOOL bConnFlag = FALSE ;
  6245. TCMDPARSER2 cmdOptions[10];
  6246. PTCMDPARSER2 pcmdOption;
  6247. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  6248. //copy * to szPassword
  6249. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  6250. //main option
  6251. pcmdOption = &cmdOptions[0];
  6252. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6253. pcmdOption->pwszOptions = CMDOPTION_RMSW;
  6254. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  6255. pcmdOption->dwCount = 1;
  6256. pcmdOption->pValue = &bRmSw;
  6257. //server option
  6258. pcmdOption = &cmdOptions[1];
  6259. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6260. pcmdOption->pwszOptions = SWITCH_SERVER;
  6261. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  6262. pcmdOption->dwType = CP_TYPE_TEXT;
  6263. pcmdOption->dwCount = 1;
  6264. //user option
  6265. pcmdOption = &cmdOptions[2];
  6266. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6267. pcmdOption->pwszOptions = SWITCH_USER;
  6268. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  6269. pcmdOption->dwType = CP_TYPE_TEXT;
  6270. pcmdOption->dwCount = 1;
  6271. //password option
  6272. pcmdOption = &cmdOptions[3];
  6273. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6274. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  6275. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  6276. pcmdOption->dwType = CP_TYPE_TEXT;
  6277. pcmdOption->dwCount = 1;
  6278. pcmdOption->pValue = szPassword;
  6279. pcmdOption->dwLength= MAX_STRING_LENGTH;
  6280. //id usage
  6281. pcmdOption = &cmdOptions[4];
  6282. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6283. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  6284. pcmdOption->dwFlags = CP2_USAGE;
  6285. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  6286. pcmdOption->dwCount = 1;
  6287. pcmdOption->pValue = &bUsage;
  6288. //default option
  6289. pcmdOption = &cmdOptions[5];
  6290. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6291. pcmdOption->pwszOptions = SWITCH_ID;
  6292. pcmdOption->dwFlags = CP_VALUE_MANDATORY | CP2_MANDATORY;
  6293. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  6294. pcmdOption->dwCount = 1;
  6295. pcmdOption->pValue = &dwDefault;
  6296. //maxmem option
  6297. pcmdOption = &cmdOptions[6];
  6298. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6299. pcmdOption->pwszOptions = SWITCH_MAXMEM;
  6300. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  6301. pcmdOption->dwCount = 1;
  6302. pcmdOption->pValue = &bMaxmem;
  6303. //basvideo option
  6304. pcmdOption = &cmdOptions[7];
  6305. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6306. pcmdOption->pwszOptions = SWITCH_BASEVIDEO;
  6307. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  6308. pcmdOption->dwCount = 1;
  6309. pcmdOption->pValue = &bBaseVideo;
  6310. //nogui option
  6311. pcmdOption = &cmdOptions[8];
  6312. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6313. pcmdOption->pwszOptions = SWITCH_NOGUIBOOT;
  6314. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  6315. pcmdOption->dwCount = 1;
  6316. pcmdOption->pValue = &bNoGui;
  6317. //sos option
  6318. pcmdOption = &cmdOptions[9];
  6319. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6320. pcmdOption->pwszOptions = SWITCH_SOS;
  6321. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  6322. pcmdOption->dwCount = 1;
  6323. pcmdOption->pValue = &bSos;
  6324. // Parsing the copy option switches
  6325. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  6326. {
  6327. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  6328. return (EXIT_FAILURE);
  6329. }
  6330. szServer = cmdOptions[1].pValue;
  6331. szUser = cmdOptions[2].pValue;
  6332. if( NULL == szUser )
  6333. {
  6334. szUser = (WCHAR *)AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  6335. if( NULL == szUser )
  6336. {
  6337. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  6338. return (EXIT_FAILURE);
  6339. }
  6340. }
  6341. TrimString( szServer, TRIM_ALL );
  6342. TrimString( szUser, TRIM_ALL );
  6343. //check if usage is specified with more than one option
  6344. if( (TRUE == bUsage) && (argc > 3) )
  6345. {
  6346. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_RMSW));
  6347. return ( EXIT_FAILURE );
  6348. }
  6349. //display an error message if the server is empty.
  6350. if((cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  6351. {
  6352. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  6353. FreeMemory( (LPVOID *) &szServer );
  6354. FreeMemory( (LPVOID *) &szUser );
  6355. return EXIT_FAILURE ;
  6356. }
  6357. //display an error message if the user is empty.
  6358. if((cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser, 0)==0 ))
  6359. {
  6360. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  6361. FreeMemory( (LPVOID *) &szServer );
  6362. FreeMemory( (LPVOID *) &szUser );
  6363. return EXIT_FAILURE ;
  6364. }
  6365. //display error message if the username is entered with out a machine name
  6366. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  6367. {
  6368. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  6369. FreeMemory( (LPVOID *) &szServer );
  6370. FreeMemory( (LPVOID *) &szUser );
  6371. return EXIT_FAILURE ;
  6372. }
  6373. //display an error if password specified without user name
  6374. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  6375. {
  6376. ShowMessage(stderr, GetResString(IDS_PASSWD_BUT_NOUSER));
  6377. FreeMemory( (LPVOID *) &szServer );
  6378. FreeMemory( (LPVOID *) &szUser );
  6379. return EXIT_FAILURE ;
  6380. }
  6381. // Displaying query usage if user specified -? with -query option
  6382. if( bUsage )
  6383. {
  6384. if( CheckSystemType(szServer) == EXIT_FAILURE )
  6385. {
  6386. FreeMemory((LPVOID *)&szServer );
  6387. FreeMemory((LPVOID *)&szUser );
  6388. return (EXIT_FAILURE);
  6389. }
  6390. displayRmSwUsage_X86();
  6391. FreeMemory((LPVOID *)&szServer );
  6392. FreeMemory((LPVOID *)&szUser );
  6393. return (EXIT_SUCCESS);
  6394. }
  6395. //check whether he is administrator or not
  6396. if( IsLocalSystem(szServer) )
  6397. {
  6398. if( !IsUserAdmin() )
  6399. {
  6400. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  6401. ReleaseGlobals();
  6402. return EXIT_FAILURE;
  6403. }
  6404. }
  6405. //display an error message if the user does not enter even one of
  6406. if((!bMaxmem)&& (!bBaseVideo)&& (!bNoGui)&&(!bSos) )
  6407. {
  6408. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_ADDSW));
  6409. FreeMemory( (LPVOID *) &szServer );
  6410. FreeMemory( (LPVOID *) &szUser );
  6411. return EXIT_FAILURE ;
  6412. }
  6413. //for setting the bNeedPwd
  6414. if(IsLocalSystem( szServer ) == FALSE )
  6415. {
  6416. // set the bNeedPwd to True or False .
  6417. if ( cmdOptions[3].dwActuals != 0 &&
  6418. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  6419. {
  6420. // user wants the utility to prompt for the password before trying to connect
  6421. bNeedPwd = TRUE;
  6422. }
  6423. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  6424. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  6425. {
  6426. // -s, -u is specified without password ...
  6427. // utility needs to try to connect first and if it fails then prompt for the password
  6428. bNeedPwd = TRUE;
  6429. if ( szPassword != NULL )
  6430. {
  6431. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  6432. }
  6433. }
  6434. }
  6435. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  6436. {
  6437. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  6438. {
  6439. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  6440. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  6441. {
  6442. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  6443. return (EXIT_FAILURE);
  6444. }
  6445. StringCopy(szServer,szToken, MAX_RES_STRING);
  6446. }
  6447. }
  6448. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  6449. if(bFlag == EXIT_FAILURE)
  6450. {
  6451. SAFECLOSE(stream);
  6452. SafeCloseConnection(szServer,bConnFlag);
  6453. FreeMemory( (LPVOID *) &szServer );
  6454. FreeMemory( (LPVOID *) &szUser );
  6455. return (EXIT_FAILURE);
  6456. }
  6457. //display warning message if local credentials are supplied
  6458. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  6459. {
  6460. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  6461. }
  6462. // Getting the keys of the Operating system section in the boot.ini file
  6463. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  6464. if(arr == NULL)
  6465. {
  6466. resetFileAttrib(szPath);
  6467. SAFEFREE(szFinalStr);
  6468. SAFECLOSE(stream);
  6469. SafeCloseConnection(szServer,bConnFlag);
  6470. FreeMemory( (LPVOID *) &szServer );
  6471. FreeMemory( (LPVOID *) &szUser );
  6472. return EXIT_FAILURE ;
  6473. }
  6474. // Getting the total number of keys in the operating systems section
  6475. dwNumKeys = DynArrayGetCount(arr);
  6476. // Displaying error message if the number of keys is less than the OS entry
  6477. // line number specified by the user
  6478. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  6479. {
  6480. ShowMessage(stderr,GetResString(IDS_INVALID_BOOTID));
  6481. resetFileAttrib(szPath);
  6482. DestroyDynamicArray(&arr);
  6483. SAFEFREE(szFinalStr);
  6484. SAFECLOSE(stream);
  6485. SafeCloseConnection(szServer,bConnFlag);
  6486. FreeMemory( (LPVOID *) &szServer );
  6487. FreeMemory( (LPVOID *) &szUser );
  6488. return (EXIT_FAILURE);
  6489. }
  6490. // Getting the key of the OS entry specified by the user
  6491. if (arr != NULL)
  6492. {
  6493. LPCWSTR pwsz = NULL;
  6494. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  6495. if(StringLengthW(pwsz,0) > MAX_RES_STRING )
  6496. {
  6497. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  6498. ShowMessage( stderr,szErrorMsg);
  6499. ShowLastError(stderr);
  6500. bRes = resetFileAttrib(szPath);
  6501. DestroyDynamicArray(&arr);
  6502. SAFEFREE(szFinalStr);
  6503. SAFECLOSE(stream);
  6504. SafeCloseConnection(szServer,bConnFlag);
  6505. FreeMemory( (LPVOID *) &szServer );
  6506. FreeMemory( (LPVOID *) &szUser );
  6507. return EXIT_FAILURE ;
  6508. }
  6509. if(pwsz != NULL)
  6510. {
  6511. StringCopy( szkey,pwsz, SIZE_OF_ARRAY(szkey));
  6512. }
  6513. else
  6514. {
  6515. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  6516. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  6517. bRes = resetFileAttrib(szPath);
  6518. DestroyDynamicArray(&arr);
  6519. SAFEFREE(szFinalStr);
  6520. SAFECLOSE(stream);
  6521. SafeCloseConnection(szServer,bConnFlag);
  6522. FreeMemory( (LPVOID *) &szServer );
  6523. FreeMemory( (LPVOID *) &szUser );
  6524. return EXIT_FAILURE ;
  6525. }
  6526. }
  6527. else
  6528. {
  6529. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  6530. ShowMessage( stderr, ERROR_TAG);
  6531. ShowLastError(stderr);
  6532. bRes = resetFileAttrib(szPath);
  6533. DestroyDynamicArray(&arr);
  6534. SAFEFREE(szFinalStr);
  6535. SAFECLOSE(stream);
  6536. SafeCloseConnection(szServer,bConnFlag);
  6537. FreeMemory( (LPVOID *) &szServer );
  6538. FreeMemory( (LPVOID *) &szUser );
  6539. return EXIT_FAILURE ;
  6540. }
  6541. //if the max mem switch is specified by the user.
  6542. if(bMaxmem==TRUE)
  6543. {
  6544. if(FindString(szkey,MAXMEM_VALUE1,0) == 0)
  6545. {
  6546. ShowMessage(stderr,GetResString(IDS_NO_MAXMEM_SWITCH));
  6547. bRes = resetFileAttrib(szPath);
  6548. DestroyDynamicArray(&arr);
  6549. SAFEFREE(szFinalStr);
  6550. SAFECLOSE(stream);
  6551. SafeCloseConnection(szServer,bConnFlag);
  6552. FreeMemory( (LPVOID *) &szServer );
  6553. FreeMemory( (LPVOID *) &szUser );
  6554. return EXIT_FAILURE ;
  6555. }
  6556. else
  6557. {
  6558. StringCopy(szTemp,NULL_STRING, MAX_RES_STRING);
  6559. dwCode = GetSubString(szkey,MAXMEM_VALUE1,szSubString);
  6560. //remove the substring specified.
  6561. if(dwCode == EXIT_SUCCESS)
  6562. {
  6563. if( EXIT_FAILURE == removeSubString(szkey,szSubString) )
  6564. {
  6565. resetFileAttrib(szPath);
  6566. SAFECLOSE(stream);
  6567. SafeCloseConnection(szServer,bConnFlag);
  6568. FreeMemory( (LPVOID *) &szServer );
  6569. FreeMemory( (LPVOID *) &szUser );
  6570. return (EXIT_FAILURE);
  6571. }
  6572. }
  6573. }
  6574. }
  6575. // if the base video is specified by the user.
  6576. if (bBaseVideo==TRUE)
  6577. {
  6578. if(FindString(szkey,BASEVIDEO_VALUE, 0) == 0)
  6579. {
  6580. ShowMessage(stderr,GetResString(IDS_NO_BV_SWITCH));
  6581. bRes = resetFileAttrib(szPath);
  6582. DestroyDynamicArray(&arr);
  6583. SAFEFREE(szFinalStr);
  6584. SAFECLOSE(stream);
  6585. SafeCloseConnection(szServer,bConnFlag);
  6586. FreeMemory( (LPVOID *) &szServer );
  6587. FreeMemory( (LPVOID *) &szUser );
  6588. return EXIT_FAILURE ;
  6589. }
  6590. else
  6591. {
  6592. if( EXIT_FAILURE == removeSubString(szkey,BASEVIDEO_VALUE) )
  6593. {
  6594. bRes = resetFileAttrib(szPath);
  6595. DestroyDynamicArray(&arr);
  6596. SAFEFREE(szFinalStr);
  6597. SAFECLOSE(stream);
  6598. SafeCloseConnection(szServer,bConnFlag);
  6599. FreeMemory( (LPVOID *) &szServer );
  6600. FreeMemory( (LPVOID *) &szUser );
  6601. return (EXIT_FAILURE);
  6602. }
  6603. }
  6604. }
  6605. // if the SOS is specified by the user.
  6606. if(bSos==TRUE)
  6607. {
  6608. if(FindString(szkey,SOS_VALUE, 0) == 0)
  6609. {
  6610. ShowMessage(stderr,GetResString(IDS_NO_SOS_SWITCH ) );
  6611. resetFileAttrib(szPath);
  6612. DestroyDynamicArray(&arr);
  6613. SAFEFREE(szFinalStr);
  6614. SAFECLOSE(stream);
  6615. SafeCloseConnection(szServer,bConnFlag);
  6616. FreeMemory( (LPVOID *) &szServer );
  6617. FreeMemory( (LPVOID *) &szUser );
  6618. return EXIT_FAILURE ;
  6619. }
  6620. else
  6621. {
  6622. if( EXIT_FAILURE == removeSubString(szkey,SOS_VALUE) )
  6623. {
  6624. bRes = resetFileAttrib(szPath);
  6625. DestroyDynamicArray(&arr);
  6626. SAFEFREE(szFinalStr);
  6627. SAFECLOSE(stream);
  6628. SafeCloseConnection(szServer,bConnFlag);
  6629. FreeMemory( (LPVOID *) &szServer );
  6630. FreeMemory( (LPVOID *) &szUser );
  6631. return (EXIT_FAILURE);
  6632. }
  6633. }
  6634. }
  6635. // if the noguiboot is specified by the user.
  6636. if(bNoGui==TRUE)
  6637. {
  6638. if(FindString(szkey,NOGUI_VALUE, 0) == 0)
  6639. {
  6640. ShowMessage(stderr,GetResString(IDS_NO_NOGUI_SWITCH));
  6641. resetFileAttrib(szPath);
  6642. DestroyDynamicArray(&arr);
  6643. SAFEFREE(szFinalStr);
  6644. SAFECLOSE(stream);
  6645. SafeCloseConnection(szServer,bConnFlag);
  6646. FreeMemory( (LPVOID *) &szServer );
  6647. FreeMemory( (LPVOID *) &szUser );
  6648. return EXIT_FAILURE ;
  6649. }
  6650. else
  6651. {
  6652. if( EXIT_FAILURE == removeSubString(szkey,NOGUI_VALUE) )
  6653. {
  6654. resetFileAttrib(szPath);
  6655. DestroyDynamicArray(&arr);
  6656. SAFEFREE(szFinalStr);
  6657. SAFECLOSE(stream);
  6658. SafeCloseConnection(szServer,bConnFlag);
  6659. FreeMemory( (LPVOID *) &szServer );
  6660. FreeMemory( (LPVOID *) &szUser );
  6661. return EXIT_FAILURE ;
  6662. }
  6663. }
  6664. }
  6665. DynArrayRemove(arr, dwDefault - 1 );
  6666. //DynArrayInsertString(arr, dwDefault - 1, szkey, MAX_STRING_LENGTH1);
  6667. DynArrayInsertString(arr, dwDefault - 1, szkey, 0);
  6668. if (stringFromDynamicArray2( arr,&szFinalStr) == EXIT_FAILURE)
  6669. {
  6670. DestroyDynamicArray(&arr);
  6671. SAFEFREE(szFinalStr);
  6672. SAFECLOSE(stream);
  6673. resetFileAttrib(szPath);
  6674. SafeCloseConnection(szServer,bConnFlag);
  6675. FreeMemory( (LPVOID *) &szServer );
  6676. FreeMemory( (LPVOID *) &szUser );
  6677. return EXIT_FAILURE;
  6678. }
  6679. // Writing to the profile section with new key-value pair
  6680. // If the return value is non-zero, then there is an error.
  6681. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  6682. {
  6683. ShowMessageEx(stdout, 1, TRUE, GetResString(IDS_SWITCH_DELETE), dwDefault );
  6684. }
  6685. else
  6686. {
  6687. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_NO_SWITCH_DELETE), dwDefault );
  6688. DestroyDynamicArray(&arr);
  6689. resetFileAttrib(szPath);
  6690. SAFEFREE(szFinalStr);
  6691. SAFECLOSE(stream);
  6692. SafeCloseConnection(szServer,bConnFlag);
  6693. FreeMemory( (LPVOID *) &szServer );
  6694. FreeMemory( (LPVOID *) &szUser );
  6695. return (EXIT_FAILURE);
  6696. }
  6697. //reset the file attributes and free the memory and close the connection to the server.
  6698. bRes = resetFileAttrib(szPath);
  6699. DestroyDynamicArray(&arr);
  6700. SAFEFREE(szFinalStr);
  6701. SAFECLOSE(stream);
  6702. SafeCloseConnection(szServer,bConnFlag);
  6703. FreeMemory( (LPVOID *) &szServer );
  6704. FreeMemory( (LPVOID *) &szUser );
  6705. return (EXIT_SUCCESS);
  6706. }
  6707. VOID displayAddSwUsage_X86()
  6708. /*++
  6709. Routine Description : Display the help for the AddSw entry option (X86).
  6710. Parameters : none
  6711. Return Type : VOID
  6712. --*/
  6713. {
  6714. DWORD dwIndex = IDS_ADDSW_BEGIN_X86 ;
  6715. for(;dwIndex <=IDS_ADDSW_END_X86;dwIndex++)
  6716. {
  6717. ShowMessage(stdout,GetResString(dwIndex));
  6718. }
  6719. }
  6720. VOID displayAddSwUsage_IA64()
  6721. /*++
  6722. Routine Description : Display the help for the AddSw entry option (IA64).
  6723. Arguments : none
  6724. Return Type : VOID
  6725. --*/
  6726. {
  6727. DWORD dwIndex = IDS_ADDSW_BEGIN_IA64 ;
  6728. for(;dwIndex <=IDS_ADDSW_END_IA64;dwIndex++)
  6729. {
  6730. ShowMessage(stdout,GetResString(dwIndex));
  6731. }
  6732. }
  6733. VOID displayRmSwUsage_IA64()
  6734. /*++
  6735. Routine Description : Display the help for the RmSw entry option (IA64).
  6736. Arguments : none
  6737. Return Type : VOID
  6738. --*/
  6739. {
  6740. DWORD dwIndex = IDS_RMSW_BEGIN_IA64 ;
  6741. for(;dwIndex <=IDS_RMSW_END_IA64;dwIndex++)
  6742. {
  6743. ShowMessage(stdout,GetResString(dwIndex));
  6744. }
  6745. }
  6746. VOID displayRmSwUsage_X86()
  6747. /*++
  6748. Routine Description : Display the help for the RmSw entry option (X86).
  6749. Arguments : none
  6750. Return Type : VOID
  6751. --*/
  6752. {
  6753. DWORD dwIndex = IDS_RMSW_BEGIN_X86 ;
  6754. for(;dwIndex <=IDS_RMSW_END_X86;dwIndex++)
  6755. {
  6756. ShowMessage(stdout,GetResString(dwIndex));
  6757. }
  6758. }
  6759. DWORD
  6760. GetSubString( IN LPTSTR szString,
  6761. IN LPTSTR szPartString,
  6762. OUT LPTSTR pszFullString
  6763. )
  6764. /*++
  6765. Routine Description : This function retreives a part of the string.
  6766. Parameters :
  6767. LPTSTR szString (in) - String in which substring is to be found.
  6768. LPTSTR szPartString (in) - Part String whose remaining substring is to be found.
  6769. LPTSTR pszFullString (out) - String in which substring is to be found.
  6770. Return Type : DWORD
  6771. --*/
  6772. {
  6773. TCHAR szTemp[255]= NULL_STRING ;
  6774. LPTSTR pszMemValue = NULL ;
  6775. LPTSTR pszdest = NULL ;
  6776. #ifndef _WIN64
  6777. DWORD dwPos = 0;
  6778. #else
  6779. INT64 dwPos = 0;
  6780. #endif
  6781. pszMemValue = (LPTSTR)FindString(szString,szPartString,0);
  6782. if(pszMemValue == NULL)
  6783. {
  6784. return EXIT_FAILURE ;
  6785. }
  6786. //copy the remaining part of the string into a buffer
  6787. StringCopy(szTemp,pszMemValue, SIZE_OF_ARRAY(szTemp));
  6788. //search for the empty space.
  6789. pszdest = StrChrW(szTemp,_T(' '));
  6790. if (NULL == pszdest)
  6791. {
  6792. //the api returns NULL if it is not able to find the
  6793. // character . This means that the required switch is at the end
  6794. //of the string . so we are copying it fully
  6795. StringCopy(pszFullString,szTemp, MAX_RES_STRING);
  6796. return EXIT_SUCCESS ;
  6797. }
  6798. dwPos = pszdest - szTemp ;
  6799. szTemp[dwPos] = _T('\0');
  6800. StringCopy(pszFullString,szTemp, MAX_RES_STRING);
  6801. return EXIT_SUCCESS ;
  6802. }
  6803. DWORD
  6804. ProcessDbg1394Switch( IN DWORD argc,
  6805. IN LPCTSTR argv[]
  6806. )
  6807. /*++
  6808. Routine Description:
  6809. This routine is to add/remove the /debugport=1394
  6810. switches to the boot.ini file settings for the specified system.
  6811. Arguments:
  6812. [IN] argc Number of command line arguments
  6813. [IN] argv Array containing command line arguments
  6814. Return Value:
  6815. DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  6816. --*/
  6817. {
  6818. BOOL bUsage = FALSE ;
  6819. BOOL bNeedPwd = FALSE ;
  6820. BOOL bDbg1394 = FALSE ;
  6821. DWORD dwDefault = 0;
  6822. TARRAY arr = NULL;
  6823. TCHAR szkey[MAX_RES_STRING+2] = NULL_STRING;
  6824. FILE *stream = NULL;
  6825. WCHAR *szServer = NULL;
  6826. WCHAR *szUser = NULL;
  6827. WCHAR szPassword[MAX_STRING_LENGTH] = NULL_STRING;
  6828. WCHAR szPath[MAX_STRING_LENGTH] = NULL_STRING;
  6829. DWORD dwNumKeys = 0;
  6830. BOOL bRes = FALSE ;
  6831. LPTSTR szFinalStr = NULL ;
  6832. BOOL bFlag = FALSE ;
  6833. TCHAR szDefault[MAX_STRING_LENGTH] = NULL_STRING ;
  6834. TCHAR szTemp[MAX_RES_STRING+1] = NULL_STRING ;
  6835. TCHAR szBuffer[MAX_RES_STRING+1] = NULL_STRING ;
  6836. LPTSTR szSubString = NULL ;
  6837. DWORD dwCode = 0;
  6838. DWORD dwChannel = 0;
  6839. TCHAR szChannel[MAX_RES_STRING+1] = NULL_STRING ;
  6840. LPCTSTR szToken = NULL ;
  6841. DWORD dwRetVal = 0 ;
  6842. BOOL bConnFlag = FALSE ;
  6843. TCMDPARSER2 cmdOptions[8];
  6844. PTCMDPARSER2 pcmdOption;
  6845. SecureZeroMemory(cmdOptions, SIZE_OF_ARRAY(cmdOptions)*sizeof(TCMDPARSER2) );
  6846. //copy * to szPassword
  6847. StringCopy( szPassword, L"*", SIZE_OF_ARRAY(szPassword) );
  6848. //main option
  6849. pcmdOption = &cmdOptions[0];
  6850. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6851. pcmdOption->pwszOptions = CMDOPTION_DBG1394;
  6852. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  6853. pcmdOption->dwCount = 1;
  6854. pcmdOption->pValue = &bDbg1394;
  6855. //server option
  6856. pcmdOption = &cmdOptions[1];
  6857. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6858. pcmdOption->pwszOptions = SWITCH_SERVER;
  6859. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  6860. pcmdOption->dwType = CP_TYPE_TEXT;
  6861. pcmdOption->dwCount = 1;
  6862. //user option
  6863. pcmdOption = &cmdOptions[2];
  6864. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6865. pcmdOption->pwszOptions = SWITCH_USER;
  6866. pcmdOption->dwFlags = CP2_ALLOCMEMORY | CP_VALUE_MANDATORY;
  6867. pcmdOption->dwType = CP_TYPE_TEXT;
  6868. pcmdOption->dwCount = 1;
  6869. //password option
  6870. pcmdOption = &cmdOptions[3];
  6871. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6872. pcmdOption->pwszOptions = SWITCH_PASSWORD;
  6873. pcmdOption->dwFlags = CP2_VALUE_OPTIONAL;
  6874. pcmdOption->dwType = CP_TYPE_TEXT;
  6875. pcmdOption->dwCount = 1;
  6876. pcmdOption->pValue = szPassword;
  6877. pcmdOption->dwLength= MAX_STRING_LENGTH;
  6878. // usage
  6879. pcmdOption = &cmdOptions[4];
  6880. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6881. pcmdOption->pwszOptions = CMDOPTION_USAGE;
  6882. pcmdOption->dwFlags = CP2_USAGE;
  6883. pcmdOption->dwType = CP_TYPE_BOOLEAN;
  6884. pcmdOption->dwCount = 1;
  6885. pcmdOption->pValue = &bUsage;
  6886. //default option
  6887. pcmdOption = &cmdOptions[5];
  6888. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6889. pcmdOption->pwszOptions = SWITCH_ID;
  6890. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  6891. pcmdOption->dwCount = 1;
  6892. pcmdOption->pValue = &dwDefault;
  6893. //id option
  6894. pcmdOption = &cmdOptions[6];
  6895. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6896. pcmdOption->pwszOptions = CMDOPTION_CHANNEL;
  6897. pcmdOption->dwFlags = CP_VALUE_MANDATORY;
  6898. pcmdOption->dwType = CP_TYPE_UNUMERIC;
  6899. pcmdOption->dwCount = 1;
  6900. pcmdOption->pValue = &dwChannel;
  6901. //on/off option
  6902. pcmdOption = &cmdOptions[7];
  6903. StringCopyA( pcmdOption->szSignature, "PARSER2", 8 );
  6904. pcmdOption->pwszOptions = CMDOPTION_DEFAULT;
  6905. pcmdOption->dwFlags = CP2_DEFAULT | CP2_MANDATORY | CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;;
  6906. pcmdOption->dwType = CP_TYPE_TEXT;
  6907. pcmdOption->dwCount = 1;
  6908. pcmdOption->pValue = szDefault;
  6909. pcmdOption->dwLength= MAX_STRING_LENGTH;
  6910. // Parsing the copy option switches
  6911. if ( !DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdOptions ), cmdOptions, 0 ) )
  6912. {
  6913. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  6914. return (EXIT_FAILURE);
  6915. }
  6916. szServer = cmdOptions[1].pValue;
  6917. szUser = cmdOptions[2].pValue;
  6918. if( NULL == szUser )
  6919. {
  6920. szUser = (WCHAR *)AllocateMemory( MAX_STRING_LENGTH*sizeof(WCHAR) );
  6921. if( NULL == szUser )
  6922. {
  6923. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  6924. return (EXIT_FAILURE);
  6925. }
  6926. }
  6927. TrimString( szServer, TRIM_ALL );
  6928. TrimString( szUser, TRIM_ALL );
  6929. //check if usage is specified with more than one option
  6930. if( (TRUE == bUsage) && (argc > 3) )
  6931. {
  6932. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_DBG1394));
  6933. return ( EXIT_FAILURE );
  6934. }
  6935. //display an error message if the server is empty.
  6936. if((cmdOptions[1].dwActuals!=0)&&(StringLengthW(szServer, 0)==0))
  6937. {
  6938. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  6939. return EXIT_FAILURE ;
  6940. }
  6941. //display an error message if the user is empty.
  6942. if((cmdOptions[2].dwActuals!=0)&&(StringLengthW(szUser,0)==0 ))
  6943. {
  6944. ShowMessage(stderr,GetResString(IDS_ERROR_NULL_USER));
  6945. return EXIT_FAILURE ;
  6946. }
  6947. // Displaying query usage if user specified -? with -query option
  6948. if( bUsage )
  6949. {
  6950. if( CheckSystemType(szServer) == EXIT_FAILURE )
  6951. {
  6952. FreeMemory((LPVOID *)&szServer );
  6953. FreeMemory((LPVOID *)&szUser );
  6954. return (EXIT_FAILURE);
  6955. }
  6956. displayDbg1394Usage_X86();
  6957. FreeMemory((LPVOID *)&szServer );
  6958. FreeMemory((LPVOID *)&szUser );
  6959. return (EXIT_SUCCESS);
  6960. }
  6961. //check whether he is administrator or not
  6962. if( IsLocalSystem(szServer) )
  6963. {
  6964. if( !IsUserAdmin() )
  6965. {
  6966. ShowMessage( stderr, GetResString(IDS_NOT_ADMINISTRATOR_32 ));
  6967. ReleaseGlobals();
  6968. return EXIT_FAILURE;
  6969. }
  6970. }
  6971. //
  6972. //display error message if user enters a value
  6973. // other than on or off
  6974. //
  6975. if( ( StringCompare(szDefault,OFF_STRING,TRUE,0)!=0 ) && (StringCompare(szDefault,ON_STRING,TRUE,0)!=0 ) )
  6976. {
  6977. ShowMessage(stderr,GetResString(IDS_ERROR_DEFAULT_MISSING));
  6978. ShowMessage(stderr,GetResString(IDS_1394_HELP));
  6979. FreeMemory((LPVOID *)&szServer );
  6980. FreeMemory((LPVOID *)&szUser );
  6981. return (EXIT_FAILURE);
  6982. }
  6983. if(( StringCompare(szDefault,OFF_STRING,TRUE,0)==0 ) && (cmdOptions[6].dwActuals != 0) )
  6984. {
  6985. ShowMessage(stderr,GetResString(IDS_INVALID_SYNTAX_DBG1394));
  6986. FreeMemory((LPVOID *)&szServer );
  6987. FreeMemory((LPVOID *)&szUser );
  6988. return (EXIT_FAILURE);
  6989. }
  6990. if(( StringCompare(szDefault,ON_STRING,TRUE,0)==0 ) && (cmdOptions[6].dwActuals == 0) )
  6991. {
  6992. ShowMessage(stderr,GetResString(IDS_MISSING_CHANNEL));
  6993. FreeMemory((LPVOID *)&szServer );
  6994. FreeMemory((LPVOID *)&szUser );
  6995. return (EXIT_FAILURE);
  6996. }
  6997. if( ( StringCompare(szDefault,ON_STRING,TRUE,0)==0 ) && (cmdOptions[6].dwActuals != 0) && ( (dwChannel < 1) ||(dwChannel > 64 )) )
  6998. {
  6999. ShowMessage(stderr,GetResString(IDS_INVALID_CH_RANGE));
  7000. FreeMemory((LPVOID *)&szServer );
  7001. FreeMemory((LPVOID *)&szUser );
  7002. return (EXIT_FAILURE);
  7003. }
  7004. //display error message if the username is entered with out a machine name
  7005. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  7006. {
  7007. ShowMessage(stderr, GetResString(IDS_USER_BUT_NOMACHINE));
  7008. FreeMemory((LPVOID *)&szServer );
  7009. FreeMemory((LPVOID *)&szUser );
  7010. return EXIT_FAILURE ;
  7011. }
  7012. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  7013. {
  7014. ShowMessage(stderr, GetResString(IDS_PASSWD_BUT_NOUSER));
  7015. FreeMemory((LPVOID *)&szServer );
  7016. FreeMemory((LPVOID *)&szUser );
  7017. return EXIT_FAILURE ;
  7018. }
  7019. //for setting the bNeedPwd
  7020. if(IsLocalSystem( szServer ) == FALSE )
  7021. {
  7022. // set the bNeedPwd to True or False .
  7023. if ( cmdOptions[3].dwActuals != 0 &&
  7024. szPassword != NULL && StringCompare( szPassword, _T( "*" ), TRUE, 0 ) == 0 )
  7025. {
  7026. // user wants the utility to prompt for the password before trying to connect
  7027. bNeedPwd = TRUE;
  7028. }
  7029. else if ( cmdOptions[ 3 ].dwActuals == 0 &&
  7030. ( cmdOptions[ 1 ].dwActuals != 0 || cmdOptions[ 2 ].dwActuals != 0 ) )
  7031. {
  7032. // -s, -u is specified without password ...
  7033. // utility needs to try to connect first and if it fails then prompt for the password
  7034. bNeedPwd = TRUE;
  7035. if ( szPassword != NULL )
  7036. {
  7037. StringCopy( szPassword, _T( "" ), MAX_STRING_LENGTH );
  7038. }
  7039. }
  7040. }
  7041. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  7042. {
  7043. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  7044. {
  7045. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  7046. if( (szToken == NULL)&&(StringCompare(szServer,TOKEN_BACKSLASH4, TRUE, 0) !=0) )
  7047. {
  7048. ShowMessage( stderr,GetResString(IDS_ERROR_PARSE_NAME));
  7049. return (EXIT_FAILURE);
  7050. }
  7051. StringCopy(szServer,szToken, MAX_RES_STRING);
  7052. }
  7053. }
  7054. // Establishing connection to the specified machine and getting the file pointer
  7055. // of the boot.ini file if there is no error while establishing connection
  7056. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  7057. if(bFlag == EXIT_FAILURE)
  7058. {
  7059. SAFEFREE(szFinalStr);
  7060. SAFECLOSE(stream);
  7061. SafeCloseConnection(szServer,bConnFlag);
  7062. FreeMemory((LPVOID *)&szServer );
  7063. FreeMemory((LPVOID *)&szUser );
  7064. return (EXIT_FAILURE);
  7065. }
  7066. //display a warning message if the user specifies local system name with -s.
  7067. if( (IsLocalSystem(szServer)==TRUE)&&(StringLengthW(szUser, 0)!=0))
  7068. {
  7069. ShowMessage(stderr,GetResString(WARN_LOCALCREDENTIALS));
  7070. }
  7071. // Getting the keys of the Operating system section in the boot.ini file
  7072. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  7073. if(arr == NULL)
  7074. {
  7075. resetFileAttrib(szPath);
  7076. SAFEFREE(szFinalStr);
  7077. SAFECLOSE(stream);
  7078. SafeCloseConnection(szServer,bConnFlag);
  7079. FreeMemory((LPVOID *)&szServer );
  7080. FreeMemory((LPVOID *)&szUser );
  7081. return EXIT_FAILURE ;
  7082. }
  7083. // Getting the total number of keys in the operating systems section
  7084. dwNumKeys = DynArrayGetCount(arr);
  7085. // Displaying error message if the number of keys is less than the OS entry
  7086. // line number specified by the user
  7087. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  7088. {
  7089. ShowMessage(stderr,GetResString(IDS_INVALID_BOOTID));
  7090. resetFileAttrib(szPath);
  7091. DestroyDynamicArray(&arr);
  7092. SAFEFREE(szFinalStr);
  7093. SAFECLOSE(stream);
  7094. SafeCloseConnection(szServer,bConnFlag);
  7095. FreeMemory((LPVOID *)&szServer );
  7096. FreeMemory((LPVOID *)&szUser );
  7097. return (EXIT_FAILURE);
  7098. }
  7099. // Getting the key of the OS entry specified by the user
  7100. if (arr != NULL)
  7101. {
  7102. LPCWSTR pwsz = NULL;
  7103. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  7104. if( StringLengthW(pwsz, 0) > MAX_RES_STRING)
  7105. {
  7106. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  7107. resetFileAttrib(szPath);
  7108. DestroyDynamicArray(&arr);
  7109. SAFEFREE(szFinalStr);
  7110. SAFECLOSE(stream);
  7111. SafeCloseConnection(szServer,bConnFlag);
  7112. FreeMemory((LPVOID *)&szServer );
  7113. FreeMemory((LPVOID *)&szUser );
  7114. return EXIT_FAILURE ;
  7115. }
  7116. if(pwsz != NULL)
  7117. {
  7118. StringCopy( szkey,pwsz, SIZE_OF_ARRAY(szkey));
  7119. }
  7120. else
  7121. {
  7122. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  7123. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM);
  7124. resetFileAttrib(szPath);
  7125. DestroyDynamicArray(&arr);
  7126. SAFEFREE(szFinalStr);
  7127. SAFECLOSE(stream);
  7128. SafeCloseConnection(szServer,bConnFlag);
  7129. FreeMemory((LPVOID *)&szServer );
  7130. FreeMemory((LPVOID *)&szUser );
  7131. return EXIT_FAILURE ;
  7132. }
  7133. }
  7134. else
  7135. {
  7136. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  7137. ShowLastErrorEx(stderr, SLE_TYPE_ERROR | SLE_SYSTEM);
  7138. ShowLastError(stderr);
  7139. resetFileAttrib(szPath);
  7140. DestroyDynamicArray(&arr);
  7141. SAFEFREE(szFinalStr);
  7142. SAFECLOSE(stream);
  7143. SafeCloseConnection(szServer,bConnFlag);
  7144. FreeMemory((LPVOID *)&szServer );
  7145. FreeMemory((LPVOID *)&szUser );
  7146. return EXIT_FAILURE ;
  7147. }
  7148. if(StringCompare(szDefault,ON_STRING,TRUE,0)==0 )
  7149. {
  7150. if(FindString(szkey,DEBUGPORT,0) != 0)
  7151. {
  7152. ShowMessage(stderr,GetResString(IDS_DUPLICATE_ENTRY));
  7153. resetFileAttrib(szPath);
  7154. DestroyDynamicArray(&arr);
  7155. SAFEFREE(szFinalStr);
  7156. SAFECLOSE(stream);
  7157. SafeCloseConnection(szServer,bConnFlag);
  7158. FreeMemory((LPVOID *)&szServer );
  7159. FreeMemory((LPVOID *)&szUser );
  7160. return EXIT_FAILURE ;
  7161. }
  7162. if(FindString(szkey,BAUD_TOKEN,0) != 0)
  7163. {
  7164. ShowMessage(stderr,GetResString(IDS_ERROR_BAUD_RATE));
  7165. resetFileAttrib(szPath);
  7166. DestroyDynamicArray(&arr);
  7167. SAFEFREE(szFinalStr);
  7168. SAFECLOSE(stream);
  7169. SafeCloseConnection(szServer,bConnFlag);
  7170. FreeMemory((LPVOID *)&szServer );
  7171. FreeMemory((LPVOID *)&szUser );
  7172. return EXIT_FAILURE ;
  7173. }
  7174. if((FindString(szkey,DEBUG_SWITCH,0) == 0))
  7175. {
  7176. StringCopy(szBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  7177. StringConcat(szBuffer,DEBUG_SWITCH, SIZE_OF_ARRAY(szBuffer));
  7178. }
  7179. if( StringLength(szBuffer,0) == 0 )
  7180. {
  7181. StringCopy(szBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  7182. }
  7183. else
  7184. {
  7185. StringConcat(szBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  7186. }
  7187. StringConcat(szBuffer,DEBUGPORT_1394, SIZE_OF_ARRAY(szBuffer)) ;
  7188. if(dwChannel!=0)
  7189. {
  7190. //frame the string and concatenate to the Os Load options if the total length is less than 254.
  7191. StringConcat(szBuffer,TOKEN_EMPTYSPACE, SIZE_OF_ARRAY(szBuffer));
  7192. StringConcat(szBuffer,TOKEN_CHANNEL, SIZE_OF_ARRAY(szBuffer));
  7193. StringConcat(szBuffer,TOKEN_EQUAL, SIZE_OF_ARRAY(szBuffer));
  7194. _ltow(dwChannel,szChannel,10);
  7195. StringConcat(szBuffer,szChannel, SIZE_OF_ARRAY(szBuffer));
  7196. }
  7197. //check if boot entry length exceeds the max. boot entry or not
  7198. if( StringLength(szkey,0)+StringLength(szBuffer,0) > MAX_RES_STRING )
  7199. {
  7200. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  7201. resetFileAttrib(szPath);
  7202. DestroyDynamicArray(&arr);
  7203. SAFEFREE(szFinalStr);
  7204. SAFECLOSE(stream);
  7205. SafeCloseConnection(szServer,bConnFlag);
  7206. FreeMemory((LPVOID *)&szServer );
  7207. FreeMemory((LPVOID *)&szUser );
  7208. return EXIT_FAILURE ;
  7209. }
  7210. else
  7211. {
  7212. StringConcat( szkey, szBuffer, SIZE_OF_ARRAY(szkey));
  7213. }
  7214. }
  7215. if(StringCompare(szDefault,OFF_STRING,TRUE,0)==0 )
  7216. {
  7217. if(FindString(szkey,DEBUGPORT_1394,0) == 0)
  7218. {
  7219. ShowMessage(stderr,GetResString(IDS_NO_1394_SWITCH));
  7220. resetFileAttrib(szPath);
  7221. DestroyDynamicArray(&arr);
  7222. SAFEFREE(szFinalStr);
  7223. SAFECLOSE(stream);
  7224. SafeCloseConnection(szServer,bConnFlag);
  7225. FreeMemory((LPVOID *)&szServer );
  7226. FreeMemory((LPVOID *)&szUser );
  7227. return EXIT_FAILURE ;
  7228. }
  7229. if( EXIT_FAILURE == removeSubString(szkey,DEBUGPORT_1394) )
  7230. {
  7231. resetFileAttrib(szPath);
  7232. DestroyDynamicArray(&arr);
  7233. SAFEFREE(szFinalStr);
  7234. SAFEFREE(szSubString);
  7235. SAFECLOSE(stream);
  7236. SafeCloseConnection(szServer,bConnFlag);
  7237. FreeMemory((LPVOID *)&szServer );
  7238. FreeMemory((LPVOID *)&szUser );
  7239. return EXIT_FAILURE ;
  7240. }
  7241. if( EXIT_FAILURE == removeSubString(szkey,DEBUG_SWITCH) )
  7242. {
  7243. resetFileAttrib(szPath);
  7244. DestroyDynamicArray(&arr);
  7245. SAFEFREE(szFinalStr);
  7246. SAFEFREE(szSubString);
  7247. SAFECLOSE(stream);
  7248. SafeCloseConnection(szServer,bConnFlag);
  7249. FreeMemory((LPVOID *)&szServer );
  7250. FreeMemory((LPVOID *)&szUser );
  7251. return EXIT_FAILURE ;
  7252. }
  7253. if(FindString(szkey,TOKEN_CHANNEL,0)!=0)
  7254. {
  7255. StringCopy(szTemp,NULL_STRING, MAX_RES_STRING);
  7256. dwCode = GetSubString(szkey,TOKEN_CHANNEL,szTemp);
  7257. if(dwCode == EXIT_FAILURE )
  7258. {
  7259. ShowMessage( stderr,GetResString(IDS_NO_TOKENS));
  7260. resetFileAttrib(szPath);
  7261. DestroyDynamicArray(&arr);
  7262. SAFEFREE(szFinalStr);
  7263. SAFECLOSE(stream);
  7264. SafeCloseConnection(szServer,bConnFlag);
  7265. FreeMemory((LPVOID *)&szServer );
  7266. FreeMemory((LPVOID *)&szUser );
  7267. return EXIT_FAILURE ;
  7268. }
  7269. if(StringLengthW(szTemp, 0)!=0)
  7270. {
  7271. if( EXIT_FAILURE == removeSubString(szkey,szTemp) )
  7272. {
  7273. resetFileAttrib(szPath);
  7274. DestroyDynamicArray(&arr);
  7275. SAFEFREE(szFinalStr);
  7276. SAFEFREE(szSubString);
  7277. SAFECLOSE(stream);
  7278. SafeCloseConnection(szServer,bConnFlag);
  7279. FreeMemory((LPVOID *)&szServer );
  7280. FreeMemory((LPVOID *)&szUser );
  7281. return EXIT_FAILURE ;
  7282. }
  7283. }
  7284. }
  7285. }
  7286. if( StringLengthW(szkey, 0) > MAX_RES_STRING)
  7287. {
  7288. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  7289. resetFileAttrib(szPath);
  7290. DestroyDynamicArray(&arr);
  7291. SAFEFREE(szFinalStr);
  7292. SAFECLOSE(stream);
  7293. SafeCloseConnection(szServer,bConnFlag);
  7294. FreeMemory((LPVOID *)&szServer );
  7295. FreeMemory((LPVOID *)&szUser );
  7296. return EXIT_FAILURE ;
  7297. }
  7298. DynArrayRemove(arr, dwDefault - 1 );
  7299. DynArrayInsertString(arr, dwDefault - 1, szkey, MAX_RES_STRING+1);
  7300. if (stringFromDynamicArray2( arr,&szFinalStr) == EXIT_FAILURE)
  7301. {
  7302. DestroyDynamicArray(&arr);
  7303. SAFEFREE(szFinalStr);
  7304. SAFECLOSE(stream);
  7305. resetFileAttrib(szPath);
  7306. SafeCloseConnection(szServer,bConnFlag);
  7307. FreeMemory((LPVOID *)&szServer );
  7308. FreeMemory((LPVOID *)&szUser );
  7309. return EXIT_FAILURE;
  7310. }
  7311. // Writing to the profile section with new key-value pair
  7312. // If the return value is non-zero, then there is an error.
  7313. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  7314. {
  7315. ShowMessageEx(stdout, 1, TRUE, GetResString(IDS_SUCCESS_CHANGE_OSOPTIONS), dwDefault );
  7316. }
  7317. else
  7318. {
  7319. ShowMessageEx(stderr, 1, TRUE, GetResString(IDS_ERROR_LOAD_OSOPTIONS), dwDefault );
  7320. DestroyDynamicArray(&arr);
  7321. resetFileAttrib(szPath);
  7322. SAFEFREE(szFinalStr);
  7323. SAFECLOSE(stream);
  7324. SafeCloseConnection(szServer,bConnFlag);
  7325. FreeMemory((LPVOID *)&szServer );
  7326. FreeMemory((LPVOID *)&szUser );
  7327. return (EXIT_FAILURE);
  7328. }
  7329. //reset the file attributes and free the memory and close the connection to the server.
  7330. bRes = resetFileAttrib(szPath);
  7331. DestroyDynamicArray(&arr);
  7332. SAFEFREE(szFinalStr);
  7333. SAFECLOSE(stream);
  7334. SafeCloseConnection(szServer,bConnFlag);
  7335. FreeMemory((LPVOID *)&szServer );
  7336. FreeMemory((LPVOID *)&szUser );
  7337. return (bRes);
  7338. }
  7339. VOID
  7340. displayDbg1394Usage_X86()
  7341. // ***************************************************************************
  7342. //
  7343. // Routine Description : Display the help for the Dbg1394 entry option (X86).
  7344. //
  7345. // Arguments : none
  7346. //
  7347. // Return Type : VOID
  7348. //
  7349. // ***************************************************************************
  7350. {
  7351. DWORD dwIndex = IDS_DBG1394_BEGIN_X86 ;
  7352. for(;dwIndex <=IDS_DBG1394_END_X86;dwIndex++)
  7353. {
  7354. ShowMessage(stdout,GetResString(dwIndex));
  7355. }
  7356. }
  7357. VOID
  7358. displayDbg1394Usage_IA64()
  7359. /*++
  7360. Routine Description : Display the help for the Dbg1394 entry option (IA64).
  7361. Arguments : none
  7362. Return Type : VOID
  7363. --*/
  7364. {
  7365. DWORD dwIndex = IDS_DBG1394_BEGIN_IA64 ;
  7366. for(;dwIndex <=IDS_DBG1394_END_IA64 ;dwIndex++)
  7367. {
  7368. ShowMessage(stdout,GetResString(dwIndex));
  7369. }
  7370. }
  7371. DWORD
  7372. GetCPUInfo(LPTSTR szComputerName)
  7373. /*++
  7374. Routine Description : determines if the computer is 32 bit system or 64 bit
  7375. Arguments :
  7376. [ in ] szComputerName : System name
  7377. Return Type : DWORD
  7378. TRUE : if the system is a 32 bit system
  7379. FALSE : if the system is a 64 bit system
  7380. --*/
  7381. {
  7382. HKEY hKey1 = 0;
  7383. HKEY hRemoteKey = 0;
  7384. TCHAR szPath[MAX_STRING_LENGTH + 1] = SUBKEY ;
  7385. DWORD dwValueSize = MAX_STRING_LENGTH + 1;
  7386. DWORD dwRetCode = ERROR_SUCCESS;
  7387. DWORD dwError = 0;
  7388. TCHAR szTmpCompName[MAX_STRING_LENGTH+4] = NULL_STRING;
  7389. TCHAR szVal[MAX_RES_STRING+1] = NULL_STRING ;
  7390. DWORD dwLength = MAX_STRING_LENGTH ;
  7391. LPTSTR szReturnValue = NULL ;
  7392. DWORD dwCode = 0 ;
  7393. szReturnValue = ( LPTSTR )AllocateMemory( dwLength*sizeof( TCHAR ) );
  7394. if(szReturnValue == NULL)
  7395. {
  7396. return ERROR_NOT_ENOUGH_MEMORY;
  7397. }
  7398. if(StringLengthW(szComputerName,0)!= 0 )
  7399. {
  7400. StringCopy(szTmpCompName,TOKEN_BACKSLASH4, SIZE_OF_ARRAY(szTmpCompName));
  7401. StringConcat(szTmpCompName,szComputerName, SIZE_OF_ARRAY(szTmpCompName));
  7402. }
  7403. else
  7404. {
  7405. StringCopy(szTmpCompName,szComputerName, SIZE_OF_ARRAY(szTmpCompName));
  7406. }
  7407. // Get Remote computer local machine key
  7408. dwError = RegConnectRegistry(szTmpCompName,HKEY_LOCAL_MACHINE,&hRemoteKey);
  7409. if (dwError == ERROR_SUCCESS)
  7410. {
  7411. dwError = RegOpenKeyEx(hRemoteKey,szPath,0,KEY_READ,&hKey1);
  7412. if (dwError == ERROR_SUCCESS)
  7413. {
  7414. dwRetCode = RegQueryValueEx(hKey1, IDENTIFIER_VALUE, NULL, NULL,(LPBYTE) szReturnValue, &dwValueSize);
  7415. if (dwRetCode == ERROR_MORE_DATA)
  7416. {
  7417. if ( szReturnValue != NULL )
  7418. {
  7419. FreeMemory((LPVOID *) &szReturnValue );
  7420. szReturnValue = NULL;
  7421. }
  7422. szReturnValue = ( LPTSTR ) AllocateMemory( dwValueSize*sizeof( TCHAR ) );
  7423. if( NULL == szReturnValue )
  7424. {
  7425. RegCloseKey(hKey1);
  7426. RegCloseKey(hRemoteKey);
  7427. return ERROR_NOT_ENOUGH_MEMORY;
  7428. }
  7429. dwRetCode = RegQueryValueEx(hKey1, IDENTIFIER_VALUE, NULL, NULL,(LPBYTE) szReturnValue, &dwValueSize);
  7430. }
  7431. if(dwRetCode != ERROR_SUCCESS)
  7432. {
  7433. RegCloseKey(hKey1);
  7434. RegCloseKey(hRemoteKey);
  7435. SAFEFREE(szReturnValue);
  7436. return ERROR_RETREIVE_REGISTRY ;
  7437. }
  7438. }
  7439. else
  7440. {
  7441. RegCloseKey(hRemoteKey);
  7442. SAFEFREE(szReturnValue);
  7443. return ERROR_RETREIVE_REGISTRY ;
  7444. }
  7445. RegCloseKey(hKey1);
  7446. }
  7447. else
  7448. {
  7449. RegCloseKey(hRemoteKey);
  7450. SAFEFREE(szReturnValue);
  7451. return ERROR_RETREIVE_REGISTRY ;
  7452. }
  7453. RegCloseKey(hRemoteKey);
  7454. StringCopy(szVal,X86_MACHINE, SIZE_OF_ARRAY(szVal));
  7455. //check if the specified system contains the words x86 (belongs to the 32 )
  7456. // set the flag to true if the specified system is 64 bit .
  7457. if( !FindString(szReturnValue,szVal,0))
  7458. {
  7459. dwCode = SYSTEM_64_BIT ;
  7460. }
  7461. else
  7462. {
  7463. dwCode = SYSTEM_32_BIT ;
  7464. }
  7465. SAFEFREE(szReturnValue);
  7466. return dwCode ;
  7467. }//GetCPUInfo
  7468. DWORD CheckSystemType(LPTSTR szServer)
  7469. /*++
  7470. Routine Description : determines if the computer is 32 bit system or 64 bit
  7471. Arguments :
  7472. [ in ] szServer : System name
  7473. Return Type : DWORD
  7474. EXIT_FAILURE : if the system is a 32 bit system
  7475. EXIT_SUCCESS : if the system is a 64 bit system
  7476. --*/
  7477. {
  7478. DWORD dwSystemType = 0 ;
  7479. #ifndef _WIN64
  7480. //display the error message if the target system is a 64 bit system or if error occured in
  7481. //retreiving the information
  7482. dwSystemType = GetCPUInfo(szServer);
  7483. if(dwSystemType == ERROR_RETREIVE_REGISTRY)
  7484. {
  7485. ShowMessage(stderr,GetResString(IDS_ERROR_SYSTEM_INFO));
  7486. return (EXIT_FAILURE);
  7487. }
  7488. if( dwSystemType == ERROR_NOT_ENOUGH_MEMORY )
  7489. {
  7490. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  7491. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  7492. return EXIT_FAILURE;
  7493. }
  7494. if(dwSystemType == SYSTEM_64_BIT)
  7495. {
  7496. if(StringLengthW(szServer,0)== 0 )
  7497. {
  7498. ShowMessage(stderr,GetResString(IDS_ERROR_VERSION_MISMATCH));
  7499. }
  7500. else
  7501. {
  7502. ShowMessage(stderr,GetResString(IDS_REMOTE_NOT_SUPPORTED));
  7503. }
  7504. return (EXIT_FAILURE);
  7505. }
  7506. #endif
  7507. return EXIT_SUCCESS ;
  7508. }
  7509. VOID
  7510. SafeCloseConnection( IN LPTSTR szServer,
  7511. IN BOOL bFlag)
  7512. /*++
  7513. Routine Description : determines if the computer is 32 bit system or 64 bit
  7514. Arguments :
  7515. [ in ] szServer : System name
  7516. [ in ] bFlag : Flag
  7517. Return Type : VOID
  7518. --*/
  7519. {
  7520. if (bFlag )
  7521. {
  7522. CloseConnection(szServer);
  7523. }
  7524. }
  7525. VOID
  7526. displayMirrorUsage_IA64()
  7527. /*++
  7528. Routine Description : Display the help for the mirror option (IA64).
  7529. Arguments :
  7530. : NONE
  7531. Return Type : VOID
  7532. --*/
  7533. {
  7534. DWORD dwIndex = IDS_MIRROR_BEGIN_IA64 ;
  7535. for(;dwIndex <=IDS_MIRROR_END_IA64 ;dwIndex++)
  7536. {
  7537. ShowMessage(stdout,GetResString(dwIndex));
  7538. }
  7539. }
  7540. LPTSTR
  7541. DivideToken( IN LPTSTR szString,
  7542. IN LPTSTR szFinalString )
  7543. /*--
  7544. Routine Description : It gets the string osfriendly name from a boot entry
  7545. Arguments
  7546. [ in ] szString : boot entry string
  7547. [ out ] szFinalString : Output represents the osfriendly name.
  7548. Return Type : NULL if any error occurs else
  7549. the osfriendly name.
  7550. --*/
  7551. {
  7552. LPTSTR szTemp=NULL;
  7553. LPTSTR szTemp1=NULL;
  7554. #ifndef _WIN64
  7555. DWORD dwLength = 0 ;
  7556. #else
  7557. INT64 dwLength = 0 ;
  7558. #endif
  7559. if( szString == NULL)
  7560. {
  7561. return NULL ;
  7562. }
  7563. //Find the first occurance of the double quote.
  7564. szTemp = StrChrW(szString,L'=');
  7565. if(NULL==szTemp)
  7566. {
  7567. return NULL ;
  7568. }
  7569. szTemp+=2;
  7570. //Find the last occurance of the single quote.
  7571. szTemp1 = (LPTSTR)StrRChrW(szTemp, NULL, L'\"');
  7572. if(NULL==szTemp1)
  7573. {
  7574. return NULL ;
  7575. }
  7576. dwLength = (szTemp1 - szTemp + 1) ;
  7577. StringCopy(szFinalString,szTemp, (unsigned long)dwLength);
  7578. szFinalString[dwLength] = L'\0';
  7579. return szFinalString ;
  7580. }