Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7340 lines
184 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. ******************************************************************************/
  16. // Include files
  17. #include "pch.h"
  18. #include "resource.h"
  19. #include "BootCfg.h"
  20. #include "BootCfg64.h"
  21. // ***************************************************************************
  22. //
  23. // Routine description : Main function which calls all the other main functions depending on
  24. // the option specified by the user.
  25. //
  26. // Arguments:
  27. // [in] argc : argument count specified at the command prompt.
  28. // [in] argv : arguments specified at the command prompt.
  29. //
  30. // Return Value : DWORD
  31. // 0 : If the utility successfully performs the specified operation.
  32. // 1 : If the utility is unsuccessful in performing the specified operation.
  33. // ***************************************************************************
  34. // Main function of the program
  35. DWORD _cdecl _tmain( DWORD argc, LPCTSTR argv[] )
  36. {
  37. // Declaring the main option switches as boolean values
  38. BOOL bUsage = FALSE ;
  39. BOOL bCopy = FALSE ;
  40. BOOL bChange = FALSE ;
  41. BOOL bQuery = FALSE ;
  42. BOOL bDelete = FALSE ;
  43. BOOL bRawString = FALSE ;
  44. BOOL bResult = FALSE ;
  45. BOOL bNeedPwd = FALSE ;
  46. DWORD dwExitcode = ERROR_SUCCESS;
  47. BOOL bProcess = FALSE ;
  48. BOOL bTimeOut = FALSE ;
  49. BOOL bDefault = FALSE ;
  50. BOOL bDebug = FALSE ;
  51. BOOL bEms = FALSE ;
  52. BOOL bAddSw = FALSE ;
  53. BOOL bRmSw = FALSE ;
  54. BOOL bDbg1394 = FALSE ;
  55. BOOL bMirror = FALSE ;
  56. TCHAR szServer[MAX_RES_STRING] = NULL_STRING ;
  57. DWORD dwRetVal = 0 ;
  58. #ifdef _WIN64
  59. dwExitcode = InitializeEFI();
  60. #endif
  61. if(argc == 1)
  62. {
  63. dwExitcode = QueryBootIniSettings( argc, argv );
  64. return dwExitcode;
  65. }
  66. // Call the preProcessOptions function to find out the option selected by the user
  67. dwExitcode = preProcessOptions( argc, argv, &bUsage, &bCopy, &bQuery, &bDelete,&bRawString,&bDefault,&bTimeOut,&bDebug,&bEms,&bAddSw,&bRmSw,&bDbg1394,&bMirror);
  68. if(dwExitcode == EXIT_FAILURE)
  69. {
  70. ReleaseGlobals();
  71. return dwExitcode;
  72. }
  73. /*#ifdef _WIN64
  74. dwExitcode = InitializeEFI();
  75. #endif
  76. */
  77. if(bUsage && bTimeOut)
  78. {
  79. #ifndef _WIN64
  80. //check the remote systemtype and display error
  81. //if it is a 64 bit
  82. dwRetVal = CheckSystemType( szServer);
  83. if(dwRetVal==EXIT_SUCCESS )
  84. {
  85. displayTimeOutUsage_X86() ;
  86. }
  87. else
  88. {
  89. return EXIT_FAILURE ;
  90. }
  91. #else
  92. displayTimeOutUsage_IA64();
  93. #endif
  94. ReleaseGlobals();
  95. return EXIT_SUCCESS ;
  96. }
  97. if(bUsage && bDefault)
  98. {
  99. #ifndef _WIN64
  100. dwRetVal = CheckSystemType( szServer);
  101. if(dwRetVal==EXIT_SUCCESS )
  102. {
  103. displayChangeOSUsage_X86();
  104. }
  105. else
  106. {
  107. return EXIT_FAILURE ;
  108. }
  109. #else
  110. displayDefaultEntryUsage_IA64();
  111. #endif
  112. ReleaseGlobals();
  113. return EXIT_SUCCESS ;
  114. }
  115. // If BootIni.exe /?
  116. if( ( bUsage ==TRUE)&& ( bCopy==FALSE )&& (bQuery==FALSE)&&(bDelete==FALSE)&&(bRawString ==FALSE)
  117. &&(bDefault==FALSE)&&(bTimeOut==FALSE) && (bDebug==FALSE)&& (bEms==FALSE)&&(bAddSw==FALSE)
  118. &&(bRmSw==FALSE)&&( bDbg1394==FALSE )&&(bMirror== FALSE) )
  119. {
  120. #ifndef _WIN64
  121. dwExitcode = displayMainUsage_X86();
  122. #else
  123. displayMainUsage_IA64();
  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. dwExitcode = QueryBootIniSettings( argc, argv );
  159. }
  160. if(bTimeOut)
  161. {
  162. #ifndef _WIN64
  163. dwExitcode = ChangeTimeOut(argc,argv);
  164. #else
  165. dwExitcode = ChangeTimeOut_IA64(argc,argv);
  166. #endif
  167. }
  168. if(bDefault)
  169. {
  170. #ifndef _WIN64
  171. dwExitcode = ChangeDefaultOs(argc,argv);
  172. #else
  173. dwExitcode = ChangeDefaultBootEntry_IA64(argc,argv);
  174. #endif
  175. }
  176. if(bDebug )
  177. {
  178. #ifndef _WIN64
  179. dwExitcode = ProcessDebugSwitch( argc, argv );
  180. #else
  181. dwExitcode = ProcessDebugSwitch_IA64(argc,argv);
  182. #endif
  183. }
  184. if(bEms )
  185. {
  186. #ifndef _WIN64
  187. dwExitcode = ProcessEmsSwitch( argc, argv );
  188. #else
  189. dwExitcode = ProcessEmsSwitch_IA64(argc,argv);
  190. #endif
  191. }
  192. if(bAddSw )
  193. {
  194. #ifndef _WIN64
  195. dwExitcode = ProcessAddSwSwitch( argc, argv );
  196. #else
  197. dwExitcode = ProcessAddSwSwitch_IA64(argc,argv);
  198. #endif
  199. }
  200. if(bRmSw )
  201. {
  202. #ifndef _WIN64
  203. dwExitcode = ProcessRmSwSwitch( argc, argv );
  204. #else
  205. dwExitcode = ProcessRmSwSwitch_IA64( argc, argv );
  206. #endif
  207. }
  208. if (bDbg1394 )
  209. {
  210. #ifndef _WIN64
  211. dwExitcode = ProcessDbg1394Switch(argc,argv);
  212. #else
  213. dwExitcode = ProcessDbg1394Switch_IA64(argc,argv);
  214. #endif
  215. }
  216. if(bMirror)
  217. {
  218. #ifdef _WIN64
  219. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX));
  220. //dwExitcode = ProcessMirrorSwitch_IA64(argc,argv);
  221. #else
  222. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX));
  223. #endif
  224. }
  225. // exit with the appropriate return value if there is no problem
  226. ReleaseGlobals();
  227. return dwExitcode;
  228. }
  229. // ***************************************************************************
  230. //
  231. //
  232. // Routine Description : Function used to process the main options
  233. //
  234. // Arguments:
  235. // [ in ] argc : Number of command line arguments
  236. // [ in ] argv : Array containing command line arguments
  237. // [ out ] pbUsage : Pointer to boolean variable which will indicate
  238. // whether usage option is specified by the user.
  239. // [ out ] pbCopy : Pointer to boolean variable which will indicate
  240. // whether copy option is specified by the user.
  241. // [ out ] pbQuery : Pointer to boolean variable which will indicate
  242. // whether query option is specified by the user.
  243. // [ out ] pbChange : Pointer to boolean variable which will indicate
  244. // whether change option is specified by the user.
  245. // [ out ] pbDelete : Pointer to boolean variable which will indicate
  246. // whether delete option is specified by the user.
  247. // [ out ] pbRawString : Pointer to the boolean indicating whether raw option
  248. // is specified by the user.
  249. // [ out ] pbDefault : Pointer to the boolean indicating whether default option
  250. // is specified by the user.
  251. // [ out ] pbTimeOut : Pointer to the boolean indicating whether timeout option
  252. // is specified by the user.
  253. // [ out ] pbDebug : Pointer to the boolean indicating whether debug option
  254. // is specified by the user.
  255. // [ out ] pbEms : Pointer to the boolean indicating whether ems option
  256. // is specified by the user.
  257. // [ out ] pbAddSw : Pointer to the boolean indicating whether Addsw option
  258. // is specified by the user.
  259. // [ out ] pbRmSw : Pointer to the boolean indicating whether rmsw option
  260. // is specified by the user.
  261. // [ out ] pbDbg1394 : Pointer to the boolean indicating whether dbg1394 option
  262. // is specified by the user.
  263. // [ out ] pbMirror : Pointer to the boolean indicating whether mirror option
  264. // is specified by the user.
  265. //
  266. // Return Type : Bool
  267. // A Bool value indicating EXIT_SUCCESS on success else
  268. // EXIT_FAILURE on failure
  269. //
  270. // ***************************************************************************
  271. DWORD preProcessOptions( DWORD argc, LPCTSTR argv[],
  272. PBOOL pbUsage,
  273. PBOOL pbCopy,
  274. PBOOL pbQuery,
  275. PBOOL pbDelete,
  276. PBOOL pbRawString,
  277. PBOOL pbDefault,
  278. PBOOL pbTimeOut,
  279. PBOOL pbDebug,
  280. PBOOL pbEms,
  281. PBOOL pbAddSw,
  282. PBOOL pbRmSw,
  283. PBOOL pbDbg1394 ,
  284. PBOOL pbMirror
  285. )
  286. {
  287. // Initialise a boolean variable bOthers to find out whether switches other
  288. // than the main swithces are selected by the user
  289. BOOL bOthers = FALSE;
  290. DWORD dwCount = 0;
  291. DWORD dwi = 0;
  292. BOOL bMainUsage = FALSE ;
  293. TCHAR szServer[MAX_RES_STRING] = NULL_STRING ;
  294. DWORD dwRetVal = 0;
  295. BOOL bConnFlag = FALSE ;
  296. // Populate the TCMDPARSER structure and pass the structure to the DoParseParam
  297. // function. DoParseParam function populates the corresponding variables depending
  298. // upon the command line input.
  299. TCMDPARSER cmdOptions[] = {
  300. { CMDOPTION_COPY, 0, 1, 0, pbCopy, NULL_STRING, NULL, NULL },
  301. { CMDOPTION_QUERY, 0, 1, 0, pbQuery, NULL_STRING, NULL, NULL },
  302. { CMDOPTION_DELETE, 0, 1, 0, pbDelete, NULL_STRING, NULL, NULL },
  303. { CMDOPTION_USAGE, CP_USAGE, 1, 0, pbUsage, NULL_STRING, NULL, NULL },
  304. { CMDOTHEROPTIONS, CP_DEFAULT, 0, 0, &bOthers, NULL_STRING, NULL, NULL },
  305. { CMDOPTION_RAW, 0,1, 0, pbRawString, NULL_STRING, NULL, NULL },
  306. { CMDOPTION_DEFAULTOS, 0,1,0,pbDefault,NULL_STRING,NULL,NULL},
  307. { CMDOPTION_TIMEOUT, 0,1,0,pbTimeOut,NULL_STRING,NULL,NULL},
  308. { CMDOPTION_DEBUG, 0,1,0,pbDebug,NULL_STRING,NULL,NULL},
  309. { CMDOPTION_EMS, 0,1,0,pbEms,NULL_STRING,NULL,NULL},
  310. { CMDOPTION_ADDSW, 0,1,0,pbAddSw,NULL_STRING,NULL,NULL},
  311. { CMDOPTION_RMSW, 0,1,0,pbRmSw,NULL_STRING,NULL,NULL},
  312. { CMDOPTION_DBG1394, 0,1,0,pbDbg1394,NULL_STRING,NULL,NULL},
  313. { CMDOPTION_MIRROR, 0,1,0,pbMirror,NULL_STRING,NULL,NULL}
  314. };
  315. dwRetVal = CheckSystemType( szServer);
  316. if(dwRetVal==EXIT_FAILURE )
  317. {
  318. return EXIT_FAILURE ;
  319. }
  320. // If there is an error while parsing, display "Invalid Syntax"
  321. // If more than one main option is selected, then display error message
  322. // If usage is specified for sub-options
  323. // If none of the options are specified
  324. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  325. {
  326. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  327. DISPLAY_MESSAGE(stderr,GetReason());
  328. return EXIT_FAILURE ;
  329. }
  330. //checking if the user has entered more than 1 option.
  331. if (*pbCopy)
  332. {
  333. dwCount++ ;
  334. }
  335. if (*pbQuery)
  336. {
  337. dwCount++ ;
  338. }
  339. if (*pbDelete)
  340. {
  341. dwCount++ ;
  342. }
  343. if (*pbRawString)
  344. {
  345. dwCount++ ;
  346. // Check if any of the other valid switches have been
  347. // given as an input to the raw string
  348. if( *pbTimeOut || *pbDebug || *pbAddSw
  349. ||*pbRmSw || *pbDbg1394 || *pbEms
  350. ||*pbDelete || *pbCopy || *pbQuery
  351. ||*pbDefault || *pbMirror)
  352. {
  353. // Check wether the usage switch has been entered
  354. if( *pbUsage )
  355. {
  356. DISPLAY_MESSAGE(stderr,GetResString(IDS_MAIN_USAGE));
  357. return ( EXIT_FAILURE );
  358. }
  359. // Check if the other option is specified after the
  360. // 'raw' option
  361. for( dwi = 0; dwi < argc; dwi++ )
  362. {
  363. if( lstrcmpi( argv[ dwi ], _T("-raw") ) == 0
  364. || lstrcmpi( argv[ dwi ], _T("/raw") ) == 0 )
  365. {
  366. if( (dwi+1) == argc )
  367. {
  368. DISPLAY_MESSAGE(stderr,GetResString(IDS_MAIN_USAGE));
  369. return ( EXIT_FAILURE );
  370. }
  371. else if( _tcschr( argv[ dwi + 1 ], _T( '\"' ) ) != 0 )
  372. {
  373. DISPLAY_MESSAGE(stderr,GetResString(IDS_MAIN_USAGE));
  374. return ( EXIT_FAILURE );
  375. }
  376. }
  377. }
  378. dwCount--;
  379. }
  380. }
  381. if (*pbDefault)
  382. {
  383. dwCount++ ;
  384. }
  385. if (*pbTimeOut)
  386. {
  387. dwCount++ ;
  388. }
  389. if (*pbDebug)
  390. {
  391. dwCount++ ;
  392. }
  393. if(*pbAddSw)
  394. {
  395. dwCount++ ;
  396. }
  397. if(*pbRmSw)
  398. {
  399. dwCount++ ;
  400. }
  401. if(*pbDbg1394)
  402. {
  403. dwCount++ ;
  404. }
  405. if(*pbEms)
  406. {
  407. dwCount++ ;
  408. }
  409. if(*pbMirror)
  410. {
  411. dwCount++ ;
  412. }
  413. //display an error message if the user enters more than 1 main option
  414. if( ( ( dwCount > 1 ) ) ||
  415. //display an error message if the user enters 1 main option along with other junk
  416. ( (*pbUsage) && bOthers ) ||
  417. //display an error message if the user does not enter any main option
  418. ( !(*pbCopy) && !(*pbQuery) && !(*pbDelete) && !(*pbUsage) && !(*pbRawString)&& !(*pbDefault)&&!(*pbTimeOut)&&!(*pbDebug)&& !( *pbEms)&& !(*pbAddSw)&& !(*pbRmSw)&& !(*pbDbg1394)&& !(*pbMirror) ) )
  419. {
  420. DISPLAY_MESSAGE(stderr,GetResString(IDS_MAIN_USAGE));
  421. return ( EXIT_FAILURE );
  422. }
  423. return ( EXIT_SUCCESS );
  424. }
  425. /*****************************************************************************
  426. Routine Description:
  427. This routine is to make another OS instance copy for which you
  428. can add switches.
  429. Arguments:
  430. [in] : argc Number of command line arguments
  431. [in] : argv Array containing command line arguments
  432. Return Value :
  433. DWORD
  434. ******************************************************************************/
  435. DWORD CopyBootIniSettings( DWORD argc, LPCTSTR argv[] )
  436. {
  437. // Declaring the main option switch and the usage switch as
  438. // boolean values and initialising them
  439. BOOL bCopy = FALSE ;
  440. BOOL bUsage = FALSE;
  441. // size of the buffer and the key buffer storing the keys
  442. // Length of the buffer will be incremented dynamically based on
  443. // the number of keys present in the boot.ini file. First the length
  444. // is initialised to 100 TCHAR bytes.
  445. LPTSTR szBuf = NULL_STRING ;
  446. // File pointer pointing to the boot.ini file
  447. FILE *stream = NULL;
  448. // dynamic array containing all the keys of the boot.ini file
  449. TARRAY arr = NULL;
  450. // The key for which a new OS instance is to be built
  451. TCHAR key[MAX_RES_STRING] = NULL_STRING;
  452. BOOL bRes = FALSE ;
  453. // Variable storing the path of boot.ini file
  454. LPTSTR szPath = NULL_STRING ;
  455. TCHAR szTmpPath[MAX_RES_STRING] = NULL_STRING ;
  456. // Variable which stores the new key-value pair
  457. TCHAR newInstance[500] = NULL_STRING ;
  458. // Variable to keep track the OS entry specified by the user
  459. DWORD dwDefault = 0;
  460. // It contains the return length of GetPrivateProfileSection API
  461. DWORD dwReturnLen = 0;
  462. // Number of keys present in the boot.ini file
  463. DWORD dwNumKeys = 0;
  464. BOOL bNeedPwd =FALSE;
  465. DWORD dwId = 0;
  466. TCHAR szMesgBuffer[MAX_RES_STRING] = NULL_STRING;
  467. // Initialising the variables that are passed to TCMDPARSER structure
  468. STRING256 szServer = NULL_STRING;
  469. STRING256 szUser = NULL_STRING;
  470. STRING256 szPassword = NULL_STRING;
  471. STRING256 szDescription = NULL_STRING;
  472. BOOL bFlag = FALSE ;
  473. BOOL bMemFlag = FALSE ;
  474. DWORD dwLength = MAX_STRING_LENGTH1 ;
  475. LPCTSTR szToken = NULL ;
  476. DWORD dwRetVal = 0 ;
  477. BOOL bConnFlag = FALSE ;
  478. STRING256 szCopyStr = NULL_STRING ;
  479. LPCTSTR szToken1 = NULL ;
  480. // Builiding the TCMDPARSER structure
  481. TCMDPARSER cmdOptions[] = {
  482. { CMDOPTION_COPY, CP_MAIN_OPTION, 1, 0, &bCopy, NULL_STRING, NULL, NULL },
  483. { SWITCH_SERVER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szServer, NULL_STRING, NULL, NULL },
  484. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  485. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  486. { SWITCH_DESCRIPTION, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szDescription, NULL_STRING, NULL, NULL },
  487. { CMDOPTION_USAGE, CP_USAGE, 0, 0, &bUsage, 0, 0 },
  488. { SWITCH_ID, CP_TYPE_UNUMERIC | CP_VALUE_MANDATORY | CP_MANDATORY, 1, 0, &dwDefault, NULL_STRING, NULL, NULL }
  489. };
  490. dwRetVal = CheckSystemType( szServer);
  491. if(dwRetVal==EXIT_FAILURE )
  492. {
  493. return EXIT_FAILURE ;
  494. }
  495. szBuf = ( LPTSTR ) malloc( dwLength*sizeof( TCHAR ) );
  496. if(szBuf == NULL)
  497. {
  498. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  499. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  500. ShowLastError(stderr);
  501. SAFEFREE(szBuf);
  502. return (EXIT_FAILURE);
  503. }
  504. // Variable storing the path of boot.ini file
  505. szPath = (TCHAR*)malloc(MAX_RES_STRING* sizeof(TCHAR));
  506. if(szPath == NULL)
  507. {
  508. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  509. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  510. ShowLastError(stderr);
  511. SAFEFREE(szBuf);
  512. SAFEFREE(szPath);
  513. return (EXIT_FAILURE);
  514. }
  515. //copy the Asterix token which is required for password prompting.
  516. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  517. _tcscpy(szPassword,TOKEN_ASTERIX);
  518. // Parsing the copy option switches
  519. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  520. {
  521. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  522. ShowMessage(stderr,GetReason());
  523. SAFEFREE(szBuf);
  524. SAFEFREE(szPath);
  525. return (EXIT_FAILURE);
  526. }
  527. // Displaying copy usage if user specified -? with -copy option
  528. if( bUsage )
  529. {
  530. dwRetVal = CheckSystemType( szServer);
  531. if(dwRetVal==EXIT_SUCCESS )
  532. {
  533. SAFEFREE(szBuf);
  534. SAFEFREE(szPath);
  535. displayCopyUsage_X86();
  536. return (EXIT_SUCCESS);
  537. }
  538. else
  539. {
  540. SAFEFREE(szBuf);
  541. SAFEFREE(szPath);
  542. return (EXIT_FAILURE);
  543. }
  544. }
  545. //display an error message saying that Friendly name
  546. // must be restricted ot 67 characters.
  547. if(lstrlen(szDescription) >= 67)
  548. {
  549. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_FRIENDLY_NAME));
  550. SAFEFREE(szBuf);
  551. SAFEFREE(szPath);
  552. return (EXIT_FAILURE);
  553. }
  554. //display error message if the username is entered with out a machine name
  555. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  556. {
  557. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  558. ShowMessage(stderr,GetReason());
  559. SAFEFREE(szBuf);
  560. SAFEFREE(szPath);
  561. return EXIT_FAILURE ;
  562. }
  563. //display error message if the user enters password without entering username
  564. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  565. {
  566. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  567. ShowMessage(stderr,GetReason());
  568. SAFEFREE(szBuf);
  569. SAFEFREE(szPath);
  570. return EXIT_FAILURE ;
  571. }
  572. // for prompting the password if the user enters
  573. // * after -p option.
  574. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  575. {
  576. bNeedPwd = TRUE ;
  577. }
  578. //set the bneedpassword to true if the server name is specified and password is not specified.
  579. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  580. {
  581. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  582. {
  583. bNeedPwd = TRUE ;
  584. }
  585. else
  586. {
  587. bNeedPwd = FALSE ;
  588. }
  589. if(_tcslen(szPassword)!= 0 )
  590. {
  591. _tcscpy(szPassword,NULL_STRING);
  592. }
  593. }
  594. //display an error message if the server is empty.
  595. if( (cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0))
  596. {
  597. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  598. SAFEFREE(szBuf);
  599. SAFEFREE(szPath);
  600. return EXIT_FAILURE ;
  601. }
  602. //display an error message if the user is empty.
  603. if((cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  604. {
  605. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  606. SAFEFREE(szBuf);
  607. SAFEFREE(szPath);
  608. return EXIT_FAILURE ;
  609. }
  610. // Establishing connection to the specified machine and getting the file pointer
  611. // of the boot.ini file if there is no error while establishing connection
  612. lstrcpy(szPath, PATH_BOOTINI );
  613. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  614. {
  615. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  616. {
  617. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  618. if(szToken == NULL)
  619. {
  620. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  621. return (EXIT_FAILURE);
  622. }
  623. lstrcpy(szServer,szToken);
  624. }
  625. }
  626. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  627. {
  628. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  629. _tcscpy(szServer,_T(""));
  630. }
  631. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  632. if(bFlag == EXIT_FAILURE)
  633. {
  634. SAFECLOSE(stream);
  635. SAFEFREE(szBuf);
  636. SAFEFREE(szPath);
  637. SafeCloseConnection(szServer,bConnFlag);
  638. return (EXIT_FAILURE);
  639. }
  640. // Getting the keys of the Operating system section in the boot.ini file
  641. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  642. if(arr == NULL)
  643. {
  644. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  645. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  646. ShowLastError(stderr);
  647. resetFileAttrib(szPath);
  648. SAFECLOSE(stream);
  649. SAFEFREE(szBuf);
  650. SAFEFREE(szPath);
  651. SafeCloseConnection(szServer,bConnFlag);
  652. return (EXIT_FAILURE);
  653. }
  654. lstrcpy(szTmpPath,szPath);
  655. // Getting the total number of keys in the operating systems section
  656. dwNumKeys = DynArrayGetCount(arr);
  657. if((dwNumKeys >= MAX_BOOTID_VAL) )
  658. {
  659. DISPLAY_MESSAGE(stderr,GetResString(IDS_MAX_BOOTID));
  660. resetFileAttrib(szPath);
  661. SAFEFREE(szBuf);
  662. SAFEFREE(szPath);
  663. DestroyDynamicArray(&arr);
  664. SAFECLOSE(stream);
  665. SafeCloseConnection(szServer,bConnFlag);
  666. return (EXIT_FAILURE);
  667. }
  668. // Displaying error message if the number of keys is less than the OS entry
  669. // line number specified by the user
  670. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  671. {
  672. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  673. resetFileAttrib(szPath);
  674. SAFEFREE(szBuf);
  675. SAFEFREE(szPath);
  676. DestroyDynamicArray(&arr);
  677. SAFECLOSE(stream);
  678. SafeCloseConnection(szServer,bConnFlag);
  679. return (EXIT_FAILURE);
  680. }
  681. // Getting the key of the OS entry specified by the user
  682. if(arr != NULL)
  683. {
  684. LPCWSTR pwsz = NULL ;
  685. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  686. if(pwsz != NULL)
  687. {
  688. _tcscpy( key,pwsz);
  689. }
  690. else
  691. {
  692. resetFileAttrib(szPath);
  693. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  694. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  695. ShowLastError(stderr);
  696. SAFEFREE(szBuf);
  697. SAFEFREE(szPath);
  698. SAFECLOSE(stream);
  699. DestroyDynamicArray(&arr);
  700. SafeCloseConnection(szServer,bConnFlag);
  701. return (EXIT_FAILURE);
  702. }
  703. }
  704. else
  705. {
  706. resetFileAttrib(szPath);
  707. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  708. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  709. ShowLastError(stderr);
  710. SAFEFREE(szBuf);
  711. SAFEFREE(szPath);
  712. SAFECLOSE(stream);
  713. DestroyDynamicArray(&arr);
  714. SafeCloseConnection(szServer,bConnFlag);
  715. return (EXIT_FAILURE);
  716. }
  717. // Copying the key to a newInstance variable which will hold the new key-value pair.
  718. lstrcpy(newInstance, key);
  719. szToken = _tcstok(newInstance,TOKEN_EQUAL);
  720. if(szToken == NULL)
  721. {
  722. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  723. resetFileAttrib(szPath);
  724. SAFEFREE(szBuf);
  725. SAFEFREE(szPath);
  726. SAFECLOSE(stream);
  727. DestroyDynamicArray(&arr);
  728. SafeCloseConnection(szServer,bConnFlag);
  729. return (EXIT_FAILURE);
  730. }
  731. // Building the newInstance.
  732. lstrcat(newInstance, TOKEN_EQUAL );
  733. lstrcat(newInstance, TOKEN_SINGLEQUOTE);
  734. // Copying the description specified by the user as the value of the new key.
  735. lstrcat(newInstance, szDescription);
  736. lstrcat(newInstance, TOKEN_SINGLEQUOTE);
  737. //
  738. //concatenating the star so that the boundschecker does not
  739. //give invalid argument exception
  740. //
  741. lstrcat(key,TOKEN_STAR);
  742. szToken = _tcstok(key,TOKEN_FWDSLASH1);
  743. if(szToken == NULL)
  744. {
  745. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  746. resetFileAttrib(szPath);
  747. SAFEFREE(szBuf);
  748. SAFEFREE(szPath);
  749. SAFECLOSE(stream);
  750. DestroyDynamicArray(&arr);
  751. SafeCloseConnection(szServer,bConnFlag);
  752. return (EXIT_FAILURE);
  753. }
  754. // get the Os Load options into the szToken1 string.
  755. szToken1 = _tcstok(NULL,TOKEN_STAR);
  756. lstrcpy(szCopyStr,szToken1);
  757. lstrcat(newInstance,TOKEN_EMPTYSPACE);
  758. lstrcat(newInstance,TOKEN_FWDSLASH1) ;
  759. lstrcat(newInstance,szCopyStr);
  760. newInstance[lstrlen(newInstance) + 1] = _T('\0');
  761. // Reallocating the buffer length depending on the return value and of the
  762. // GetPrivateProfileSection API. Its return a value 2 less than the buffer size
  763. // if the buffer size is not enough to hold all the key-value pairs.
  764. while( 1 )
  765. {
  766. dwReturnLen = GetPrivateProfileSection(OS_FIELD, szBuf, dwLength, szTmpPath);
  767. // If buffer length is sufficient break
  768. if ( dwLength - 2 != dwReturnLen )
  769. break;
  770. // Increasing the buffer length and reallocate the size
  771. dwLength += 100;
  772. szBuf = ( LPTSTR ) realloc( szBuf, dwLength * sizeof( TCHAR ) );
  773. if (szBuf == NULL)
  774. {
  775. bMemFlag = TRUE ;
  776. break ;
  777. }
  778. }
  779. //display error message if there is no enough memory
  780. if (bMemFlag == TRUE)
  781. {
  782. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  783. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  784. ShowLastError(stderr);
  785. resetFileAttrib(szPath);
  786. resetFileAttrib(szTmpPath);
  787. SAFEFREE(szBuf);
  788. SAFEFREE(szPath);
  789. DestroyDynamicArray(&arr);
  790. SAFECLOSE(stream);
  791. SafeCloseConnection(szServer,bConnFlag);
  792. return (EXIT_FAILURE);
  793. }
  794. // Adding the new key-value pair
  795. lstrcat(szBuf + dwReturnLen, newInstance);
  796. // Appending the null character at the end
  797. *(szBuf + dwReturnLen + 1 + lstrlen(newInstance)) = '\0';
  798. // Writing to the profile section with new key-value pair
  799. if( WritePrivateProfileSection(OS_FIELD, szBuf, szTmpPath) != 0 )
  800. {
  801. _stprintf(szMesgBuffer,GetResString(IDS_COPY_SUCCESS),dwDefault);
  802. DISPLAY_MESSAGE(stdout,szMesgBuffer);
  803. bRes = resetFileAttrib(szPath);
  804. bRes = resetFileAttrib(szTmpPath);
  805. SAFEFREE(szBuf);
  806. SAFEFREE(szPath);
  807. DestroyDynamicArray(&arr);
  808. SafeCloseConnection(szServer,bConnFlag);
  809. SAFECLOSE(stream);
  810. return(bRes);
  811. }
  812. else
  813. {
  814. DISPLAY_MESSAGE(stderr,GetResString(IDS_COPY_OS));
  815. resetFileAttrib(szPath);
  816. resetFileAttrib(szTmpPath);
  817. SAFEFREE(szBuf);
  818. SAFEFREE(szPath);
  819. DestroyDynamicArray(&arr);
  820. SafeCloseConnection(szServer,bConnFlag);
  821. SAFECLOSE(stream);
  822. return (EXIT_FAILURE);
  823. }
  824. // Closing the opened boot.ini file handl
  825. SAFECLOSE(stream);
  826. bRes = resetFileAttrib(szPath);
  827. bRes = resetFileAttrib(szTmpPath);
  828. SAFEFREE(szBuf);
  829. SAFEFREE(szPath);
  830. DestroyDynamicArray(&arr);
  831. SafeCloseConnection(szServer,bConnFlag);
  832. return (bRes);
  833. }
  834. /*****************************************************************************
  835. Routine Description:
  836. This routine is to delete an OS entry from the Operating systems
  837. section of Boot.ini file in the specified machine.
  838. Arguments:
  839. [in] : argc Number of command line arguments
  840. [in] : argv Array containing command line arguments
  841. Return Value :
  842. DWORD
  843. ******************************************************************************/
  844. DWORD DeleteBootIniSettings( DWORD argc, LPCTSTR argv[] )
  845. {
  846. // Declaring the main option switch and the usage switch as
  847. // boolean values and initialsing them
  848. BOOL bDelete = FALSE ;
  849. BOOL bUsage = FALSE;
  850. BOOL bRes = FALSE ;
  851. // dwDefault variable stores the OS entry specified by the user
  852. DWORD dwDefault = 0;
  853. // Variables containing the count of key-value pairs
  854. DWORD dwInitialCount = 0;
  855. // Variable which will store the final key-value pairs
  856. LPTSTR szFinalStr = NULL_STRING;
  857. // array storing all the keys of the operating systems section
  858. TARRAY arrKeyValue;
  859. // Variable storing the path of boot.ini file
  860. LPTSTR szPath = NULL_STRING ;
  861. // File pointer to the boot.ini file
  862. FILE *stream = NULL;
  863. BOOL bNeedPwd = FALSE ;
  864. BOOL bFlag = FALSE ;
  865. TCHAR szMesgBuffer[MAX_RES_STRING] = NULL_STRING;
  866. // Initialising the variables that are passed to TCMDPARSER structure
  867. STRING256 szServer = NULL_STRING;
  868. STRING256 szUser = NULL_STRING;
  869. STRING256 szPassword = NULL_STRING;
  870. STRING100 szDescription = NULL_STRING;
  871. LPCTSTR szToken = NULL ;
  872. DWORD dwRetVal = 0 ;
  873. BOOL bConnFlag = FALSE ;
  874. // Builiding the TCMDPARSER structure
  875. TCMDPARSER cmdOptions[] = {
  876. { CMDOPTION_DELETE, CP_MAIN_OPTION, 1, 0, &bDelete, NULL_STRING, NULL, NULL },
  877. { SWITCH_SERVER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szServer, NULL_STRING, NULL, NULL },
  878. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  879. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  880. { CMDOPTION_USAGE, CP_USAGE, 0, 0, &bUsage, NULL_STRING, NULL, NULL },
  881. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY | CP_MANDATORY, 1, 0, &dwDefault, NULL_STRING, NULL, NULL }
  882. };
  883. //
  884. //check if the remote system is 64 bit and if so
  885. // display an error.
  886. //
  887. dwRetVal = CheckSystemType( szServer);
  888. if(dwRetVal==EXIT_FAILURE )
  889. {
  890. return EXIT_FAILURE ;
  891. }
  892. szFinalStr =(TCHAR*)malloc(MAX_STRING_LENGTH1 *sizeof(TCHAR));
  893. if(szFinalStr == NULL )
  894. {
  895. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  896. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  897. ShowLastError(stderr);
  898. return EXIT_FAILURE ;
  899. }
  900. // Variable storing the path of boot.ini file
  901. szPath = (TCHAR*)malloc(MAX_RES_STRING * sizeof(TCHAR));
  902. if(szPath == NULL)
  903. {
  904. SAFEFREE(szFinalStr);
  905. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  906. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  907. ShowLastError(stderr);
  908. return EXIT_FAILURE ;
  909. }
  910. //copy the Asterix token which is required for password prompting.
  911. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  912. _tcscpy(szPassword,TOKEN_ASTERIX);
  913. // Parsing the delete option switches
  914. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  915. {
  916. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  917. ShowMessage(stderr,GetReason());
  918. SAFEFREE(szFinalStr);
  919. SAFEFREE(szPath);
  920. return (EXIT_FAILURE);
  921. }
  922. // Displaying delete usage if user specified -? with -delete option
  923. if( bUsage )
  924. {
  925. dwRetVal = CheckSystemType( szServer);
  926. if(dwRetVal==EXIT_SUCCESS )
  927. {
  928. displayDeleteUsage_X86();
  929. SAFEFREE(szFinalStr);
  930. SAFEFREE(szPath);
  931. return (EXIT_SUCCESS);
  932. }else
  933. {
  934. SAFEFREE(szFinalStr);
  935. SAFEFREE(szPath);
  936. return (EXIT_FAILURE);
  937. }
  938. }
  939. //display error message if the username is entered with out a machine name
  940. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  941. {
  942. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  943. ShowMessage(stderr,GetReason());
  944. SAFEFREE(szFinalStr);
  945. SAFEFREE(szPath);
  946. return EXIT_FAILURE ;
  947. }
  948. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  949. {
  950. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  951. ShowMessage(stderr,GetReason());
  952. SAFEFREE(szFinalStr);
  953. SAFEFREE(szPath);
  954. return EXIT_FAILURE ;
  955. }
  956. //
  957. //for setting the bNeedPwd
  958. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  959. {
  960. bNeedPwd = TRUE ;
  961. }
  962. //set the bneedpassword to true if the server name is specified and password is not specified.
  963. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  964. {
  965. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  966. {
  967. bNeedPwd = TRUE ;
  968. }
  969. else
  970. {
  971. bNeedPwd = FALSE ;
  972. }
  973. if(_tcslen(szPassword)!= 0 )
  974. {
  975. _tcscpy(szPassword,NULL_STRING);
  976. }
  977. }
  978. //display an error message if the server is empty.
  979. if( (cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0))
  980. {
  981. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  982. SAFEFREE(szFinalStr);
  983. SAFEFREE(szPath);
  984. return EXIT_FAILURE ;
  985. }
  986. //display an error message if the user is empty.
  987. if((cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  988. {
  989. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  990. SAFEFREE(szFinalStr);
  991. SAFEFREE(szPath);
  992. return EXIT_FAILURE ;
  993. }
  994. // Searching the path of the boot.ini file in the specified system
  995. // In general the boot.ini file resides in c:\.
  996. // Search Path function can be used to trace out the path of boot.ini file
  997. // SearchPath( "\\", "boottest.ini", ".ini", 80, (LPTSTR)filepath, (LPTSTR*)&filepart );
  998. lstrcpy(szPath, PATH_BOOTINI );
  999. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  1000. {
  1001. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  1002. {
  1003. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  1004. if(szToken == NULL)
  1005. {
  1006. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  1007. return (EXIT_FAILURE);
  1008. }
  1009. else
  1010. {
  1011. lstrcpy(szServer,szToken);
  1012. }
  1013. }
  1014. }
  1015. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  1016. {
  1017. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  1018. _tcscpy(szServer,_T(""));
  1019. }
  1020. // Establishing connection to the specified machine and getting the file pointer
  1021. // of the boot.ini file if there is no error while establishing connection
  1022. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag );
  1023. if(bFlag == EXIT_FAILURE)
  1024. {
  1025. SAFECLOSE(stream);
  1026. SAFEFREE(szFinalStr);
  1027. SAFEFREE(szPath);
  1028. SafeCloseConnection(szServer,bConnFlag);
  1029. return (EXIT_FAILURE);
  1030. }
  1031. // Getting all the key-value pairs of the operating system into a dynamic
  1032. // array for manipulation.
  1033. arrKeyValue = getKeyValueOfINISection( szPath, OS_FIELD);
  1034. if(arrKeyValue == NULL)
  1035. {
  1036. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1037. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1038. ShowLastError(stderr);
  1039. resetFileAttrib(szPath);
  1040. SAFECLOSE(stream);
  1041. SAFEFREE(szFinalStr);
  1042. SAFEFREE(szPath);
  1043. SafeCloseConnection(szServer,bConnFlag);
  1044. return (EXIT_FAILURE);
  1045. }
  1046. // Getting the total no: of key-value pairs in the operating system section.
  1047. dwInitialCount = DynArrayGetCount(arrKeyValue);
  1048. // Checking whether the given OS entry is valid or not. If the OS entry given
  1049. // is greater than the number of keys present, then display an error message
  1050. if( ( dwDefault <= 0 ) || ( dwDefault > dwInitialCount ) )
  1051. {
  1052. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  1053. resetFileAttrib(szPath);
  1054. SAFECLOSE(stream);
  1055. SAFEFREE(szFinalStr);
  1056. SAFEFREE(szPath);
  1057. DestroyDynamicArray(&arrKeyValue);
  1058. SafeCloseConnection(szServer,bConnFlag);
  1059. return (EXIT_FAILURE);
  1060. }
  1061. // If only one OS entry is present and if the user tries to delete the OS entry, then
  1062. // display an error message
  1063. if( DynArrayGetCount(arrKeyValue) == 1)
  1064. {
  1065. DISPLAY_MESSAGE(stderr,GetResString(IDS_ONLY_ONE_OS));
  1066. resetFileAttrib(szPath);
  1067. SAFECLOSE(stream);
  1068. SAFEFREE(szFinalStr);
  1069. SAFEFREE(szPath);
  1070. DestroyDynamicArray(&arrKeyValue);
  1071. SafeCloseConnection(szServer,bConnFlag);
  1072. return (EXIT_FAILURE);
  1073. }
  1074. // Remove the OS entry specified by the user from the dynamic array
  1075. DynArrayRemove(arrKeyValue, dwDefault - 1);
  1076. // Setting the buffer to 0, to avoid any junk value
  1077. memset(szFinalStr, 0, MAX_STRING_LENGTH1);
  1078. // Forming the final string from all the key-value pairs
  1079. if (stringFromDynamicArray1( arrKeyValue,szFinalStr ) == EXIT_FAILURE)
  1080. {
  1081. resetFileAttrib(szPath);
  1082. SAFECLOSE(stream);
  1083. SAFEFREE(szFinalStr);
  1084. SAFEFREE(szPath);
  1085. DestroyDynamicArray(&arrKeyValue);
  1086. SafeCloseConnection(szServer,bConnFlag);
  1087. return (EXIT_FAILURE);
  1088. }
  1089. // Writing to the profile section with new key-value pair
  1090. // If the return value is non-zero, then there is an error.
  1091. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  1092. {
  1093. _stprintf(szMesgBuffer,GetResString(IDS_DEL_SUCCESS),dwDefault);
  1094. DISPLAY_MESSAGE(stdout,szMesgBuffer);
  1095. bRes = resetFileAttrib(szPath);
  1096. SAFECLOSE(stream);
  1097. SAFEFREE(szFinalStr);
  1098. SAFEFREE(szPath);
  1099. DestroyDynamicArray(&arrKeyValue);
  1100. SafeCloseConnection(szServer,bConnFlag);
  1101. return (bRes);
  1102. }
  1103. else
  1104. {
  1105. DISPLAY_MESSAGE(stderr,GetResString(IDS_DELETE_OS));
  1106. resetFileAttrib(szPath);
  1107. SAFECLOSE(stream);
  1108. SAFEFREE(szFinalStr);
  1109. SAFEFREE(szPath);
  1110. DestroyDynamicArray(&arrKeyValue);
  1111. SafeCloseConnection(szServer,bConnFlag);
  1112. return (EXIT_FAILURE);
  1113. }
  1114. // Closing the boot.ini stream
  1115. SAFECLOSE(stream);
  1116. bRes = resetFileAttrib(szPath);
  1117. SAFEFREE(szFinalStr);
  1118. SAFEFREE(szPath);
  1119. DestroyDynamicArray(&arrKeyValue);
  1120. SafeCloseConnection(szServer,bConnFlag);
  1121. return (bRes);
  1122. }
  1123. /*****************************************************************************
  1124. Routine Description:
  1125. This routine is to display the current boot.ini file settings for
  1126. the specified system.
  1127. Arguments:
  1128. [in] : argc Number of command line arguments
  1129. [in] : argv Array containing command line arguments
  1130. Return Value :
  1131. DWORD
  1132. ******************************************************************************/
  1133. DWORD QueryBootIniSettings( DWORD argc, LPCTSTR argv[] )
  1134. {
  1135. // File pointer pointing to the boot.ini file
  1136. FILE *stream = NULL;
  1137. // Declaring the main option switch and the usage switch as
  1138. // boolean values and initialsing them
  1139. BOOL bQuery = FALSE ;
  1140. BOOL bUsage = FALSE;
  1141. BOOL bExitVal = TRUE;
  1142. BOOL bNeedPwd = FALSE ;
  1143. BOOL bVerbose = TRUE ;
  1144. TCOLUMNS ResultHeader[ MAX_COLUMNS ];
  1145. TARRAY arrResults = NULL ;
  1146. TARRAY arrKeyValuePairs = NULL;
  1147. TARRAY arrBootLoader = NULL;
  1148. DWORD dwFormatType = 0;
  1149. BOOL bHeader = TRUE ;
  1150. DWORD dwLength = 0 ;
  1151. DWORD dwCnt = 0;
  1152. TCHAR szValue[MAX_RES_STRING] = NULL_STRING ;
  1153. TCHAR szFriendlyName[MAX_CMD_LENGTH] = TOKEN_NA ;
  1154. TCHAR szBootOptions[MAX_RES_STRING] = TOKEN_NA ;
  1155. TCHAR szBootEntry[MAX_RES_STRING] = TOKEN_NA ;
  1156. TCHAR szArcPath[MAX_RES_STRING] = TOKEN_NA ;
  1157. TCHAR szTmpString[MAX_RES_STRING] = TOKEN_NA ;
  1158. PTCHAR psztok = NULL ;
  1159. DWORD dwRow = 0;
  1160. DWORD dwCount = 0;
  1161. BOOL bRes = FALSE ;
  1162. BOOL bFlag = FALSE ;
  1163. DWORD dwIndex = 0 ;
  1164. DWORD dwLength1 = 0 ;
  1165. DWORD dwFinalLength = 0 ;
  1166. // Initialising the variables that are passed to TCMDPARSER structure
  1167. STRING256 szServer = NULL_STRING;
  1168. STRING256 szUser = NULL_STRING;
  1169. STRING256 szPassword = NULL_STRING;
  1170. STRING100 szPath = NULL_STRING;
  1171. LPCWSTR szKeyName[MAX_RES_STRING] ;
  1172. TCHAR szResults[MAX_RES_STRING][MAX_RES_STRING] ;
  1173. TCHAR szDisplay[MAX_RES_STRING] = NULL_STRING ;
  1174. DWORD dwSectionFlag = 0 ;
  1175. LPCTSTR szToken = NULL ;
  1176. DWORD dwRetVal= 0 ;
  1177. BOOL bConnFlag = FALSE ;
  1178. BOOL bTokenFlag = FALSE ;
  1179. BOOL bPasswdFlag = FALSE ;
  1180. // Builiding the TCMDPARSER structure
  1181. TCMDPARSER cmdOptions[] = {
  1182. { CMDOPTION_QUERY, CP_MAIN_OPTION, 1, 0, &bQuery, NULL_STRING, NULL, NULL },
  1183. { SWITCH_SERVER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szServer, NULL_STRING, NULL, NULL },
  1184. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  1185. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  1186. { CMDOPTION_USAGE, CP_USAGE, 0, 0, &bUsage, NULL_STRING, NULL, NULL }
  1187. };
  1188. dwRetVal = CheckSystemType( szServer);
  1189. if(dwRetVal==EXIT_FAILURE )
  1190. {
  1191. return EXIT_FAILURE ;
  1192. }
  1193. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  1194. _tcscpy(szPassword,TOKEN_ASTERIX);
  1195. // Parsing all the switches specified with -query option
  1196. if ( ! DoParseParam( argc, argv,SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  1197. {
  1198. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  1199. ShowMessage(stderr,GetReason());
  1200. return (EXIT_FAILURE);
  1201. }
  1202. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  1203. {
  1204. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  1205. {
  1206. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  1207. if(szToken == NULL)
  1208. {
  1209. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  1210. return (EXIT_FAILURE);
  1211. }
  1212. lstrcpy(szServer,szToken);
  1213. }
  1214. }
  1215. // Displaying query usage if user specified -? with -query option
  1216. if( bUsage )
  1217. {
  1218. dwRetVal = CheckSystemType( szServer);
  1219. if(dwRetVal==EXIT_SUCCESS )
  1220. {
  1221. displayQueryUsage();
  1222. return (EXIT_SUCCESS);
  1223. }
  1224. else
  1225. {
  1226. return (EXIT_FAILURE);
  1227. }
  1228. }
  1229. #ifdef _WIN64
  1230. bExitVal = QueryBootIniSettings_IA64();
  1231. return bExitVal;
  1232. #endif
  1233. //display error message if the username is entered with out a machine name
  1234. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  1235. {
  1236. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  1237. ShowMessage(stderr,GetReason());
  1238. return EXIT_FAILURE ;
  1239. }
  1240. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  1241. {
  1242. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  1243. ShowMessage(stderr,GetReason());
  1244. return EXIT_FAILURE ;
  1245. }
  1246. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  1247. {
  1248. bNeedPwd = TRUE ;
  1249. }
  1250. //set the bneedpassword to true if the server name is specified and password is not specified.
  1251. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  1252. {
  1253. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  1254. {
  1255. bNeedPwd = TRUE ;
  1256. }
  1257. else
  1258. {
  1259. bNeedPwd = FALSE ;
  1260. }
  1261. if(_tcslen(szPassword)!= 0 )
  1262. {
  1263. _tcscpy(szPassword,NULL_STRING);
  1264. }
  1265. }
  1266. if((cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0))
  1267. {
  1268. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  1269. return EXIT_FAILURE ;
  1270. }
  1271. if( (cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  1272. {
  1273. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  1274. return EXIT_FAILURE ;
  1275. }
  1276. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  1277. {
  1278. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  1279. _tcscpy(szServer,_T(""));
  1280. }
  1281. //set the default format as list
  1282. dwFormatType = SR_FORMAT_LIST;
  1283. //forms the header for the OS options
  1284. FormHeader(bHeader,ResultHeader,bVerbose);
  1285. //create dynamic array to hold the results for the BootOptions
  1286. arrResults = CreateDynamicArray();
  1287. //create dynamic array to hold the results for the BootLoader section
  1288. arrBootLoader = CreateDynamicArray();
  1289. if(arrResults == NULL || arrBootLoader == NULL)
  1290. {
  1291. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1292. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1293. ShowLastError(stderr);
  1294. if (arrResults!=NULL)
  1295. DestroyDynamicArray(&arrResults);
  1296. return (EXIT_FAILURE);
  1297. }
  1298. lstrcpy(szPath, PATH_BOOTINI );
  1299. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  1300. if(bFlag == EXIT_FAILURE)
  1301. {
  1302. SAFECLOSE(stream);
  1303. DestroyDynamicArray(&arrResults);
  1304. DestroyDynamicArray(&arrBootLoader);
  1305. SafeCloseConnection(szServer,bConnFlag);
  1306. return (EXIT_FAILURE);
  1307. }
  1308. //to store entries corresponding to Operating Systems sections
  1309. arrKeyValuePairs = getKeyValueOfINISection( szPath, OS_FIELD );
  1310. //to store entries corresponding to BootLoader section
  1311. arrBootLoader = getKeysOfINISection(szPath,BOOTLOADERSECTION);
  1312. if( (arrBootLoader == NULL)||(arrKeyValuePairs == NULL))
  1313. {
  1314. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1315. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1316. ShowLastError(stderr);
  1317. resetFileAttrib(szPath);
  1318. SAFECLOSE(stream);
  1319. DestroyDynamicArray(&arrResults);
  1320. DestroyDynamicArray(&arrBootLoader);
  1321. SafeCloseConnection(szServer,bConnFlag);
  1322. return (EXIT_FAILURE);
  1323. }
  1324. dwCount = DynArrayGetCount(arrBootLoader);
  1325. //to display the Header Column
  1326. DISPLAY_MESSAGE(stdout,TOKEN_NEXTLINE);
  1327. DISPLAY_MESSAGE(stdout,BOOT_HEADER);
  1328. DISPLAY_MESSAGE(stdout,DASHES_BOOTOS);
  1329. // this loop is for calculating the maximum width of the the keys which will be displayed.
  1330. for(dwIndex=0;dwIndex < dwCount;dwIndex++)
  1331. {
  1332. szKeyName[dwIndex] = DynArrayItemAsString(arrBootLoader,dwIndex);
  1333. //the value correspondin to the key is obtained.
  1334. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,szKeyName[dwIndex],szResults[dwIndex]);
  1335. if (dwSectionFlag == MALLOC_FAILURE)
  1336. {
  1337. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1338. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1339. ShowLastError(stderr);
  1340. resetFileAttrib(szPath);
  1341. SAFECLOSE(stream);
  1342. DestroyDynamicArray(&arrResults);
  1343. DestroyDynamicArray(&arrBootLoader);
  1344. SafeCloseConnection(szServer,bConnFlag);
  1345. return EXIT_FAILURE;
  1346. }
  1347. dwLength1 = lstrlen(szKeyName[dwIndex]);
  1348. if (dwLength1 > dwFinalLength)
  1349. {
  1350. dwFinalLength = dwLength1;
  1351. }
  1352. }
  1353. // display the results of the bootloader section.
  1354. for(dwIndex=0;dwIndex < dwCount;dwIndex++)
  1355. {
  1356. dwLength1 = dwFinalLength - lstrlen(szKeyName[dwIndex]) + 1;
  1357. DISPLAY_MESSAGE(stdout,szKeyName[dwIndex]);
  1358. _tcscpy(szDisplay,TOKEN_COLONSYMBOL);
  1359. _tcsncat(szDisplay,TOKEN_50SPACES,dwLength1);
  1360. DISPLAY_MESSAGE(stdout,szDisplay);
  1361. DISPLAY_MESSAGE(stdout,szResults[dwIndex]);
  1362. DISPLAY_MESSAGE(stdout,TOKEN_NEXTLINE);
  1363. }
  1364. DISPLAY_MESSAGE(stdout,TOKEN_NEXTLINE);
  1365. psztok = NULL ;
  1366. //getting the count of the number of boot entries
  1367. dwLength = DynArrayGetCount(arrKeyValuePairs);
  1368. for(dwCnt=0;dwCnt < dwLength;dwCnt++ )
  1369. {
  1370. dwRow = DynArrayAppendRow(arrResults,MAX_COLUMNS) ;
  1371. lstrcpy(szFriendlyName,NULL_STRING);
  1372. lstrcpy(szBootOptions,NULL_STRING);
  1373. lstrcpy(szTmpString,NULL_STRING);
  1374. if(arrKeyValuePairs != NULL)
  1375. {
  1376. LPCWSTR pwsz = NULL;
  1377. pwsz = DynArrayItemAsString( arrKeyValuePairs,dwCnt );
  1378. if(pwsz != NULL)
  1379. {
  1380. lstrcpy(szValue,pwsz);
  1381. }
  1382. else
  1383. {
  1384. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1385. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1386. ShowLastError(stderr);
  1387. SAFECLOSE(stream);
  1388. resetFileAttrib(szPath);
  1389. DestroyDynamicArray(&arrBootLoader);
  1390. DestroyDynamicArray(&arrKeyValuePairs);
  1391. DestroyDynamicArray(&arrResults);
  1392. SafeCloseConnection(szServer,bConnFlag);
  1393. return (EXIT_FAILURE);
  1394. }
  1395. }
  1396. else
  1397. {
  1398. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1399. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  1400. ShowLastError(stderr);
  1401. SAFECLOSE(stream);
  1402. resetFileAttrib(szPath);
  1403. DestroyDynamicArray(&arrBootLoader);
  1404. DestroyDynamicArray(&arrResults);
  1405. SafeCloseConnection(szServer,bConnFlag);
  1406. return (EXIT_FAILURE);
  1407. }
  1408. psztok = _tcstok(szValue,TOKEN_EQUAL);
  1409. if(psztok != NULL)
  1410. {
  1411. lstrcpy(szArcPath,psztok);
  1412. psztok = _tcstok(NULL,TOKEN_FWDSLASH1 );
  1413. if(psztok != NULL)
  1414. {
  1415. lstrcpy(szFriendlyName,psztok);
  1416. lstrcat(szValue,TOKEN_STAR);
  1417. psztok = _tcstok(NULL,TOKEN_STAR);
  1418. if(psztok != NULL)
  1419. {
  1420. lstrcpy(szTmpString,psztok);
  1421. }
  1422. else
  1423. {
  1424. bTokenFlag = TRUE ;
  1425. }
  1426. }else
  1427. {
  1428. bTokenFlag = TRUE ;
  1429. }
  1430. }
  1431. else
  1432. {
  1433. bTokenFlag = TRUE ;
  1434. }
  1435. _ltow(dwCnt+1,szBootEntry,10);
  1436. DynArraySetString2( arrResults,dwRow ,COL0,szBootEntry,0 );
  1437. if(lstrlen(szFriendlyName)==0)
  1438. {
  1439. lstrcpy(szFriendlyName,TOKEN_NA);
  1440. }
  1441. DynArraySetString2( arrResults,dwRow ,COL1,szFriendlyName,0 );
  1442. DynArraySetString2(arrResults,dwRow,COL2,szArcPath,0);
  1443. if(lstrlen(szTmpString) != 0)
  1444. {
  1445. lstrcat(szBootOptions,TOKEN_FWDSLASH1);
  1446. lstrcat(szBootOptions,szTmpString);
  1447. }
  1448. else
  1449. {
  1450. lstrcpy(szBootOptions,TOKEN_NA);
  1451. }
  1452. DynArraySetString2( arrResults,dwRow ,COL3,szBootOptions,0 );
  1453. }
  1454. DISPLAY_MESSAGE(stdout,OS_HEADER);
  1455. DISPLAY_MESSAGE(stdout,DASHES_OS);
  1456. ShowResults(MAX_COLUMNS, ResultHeader, dwFormatType,arrResults ) ;
  1457. // Closing the boot.ini stream and destroying the dynamic arrays.
  1458. DestroyDynamicArray(&arrResults);
  1459. DestroyDynamicArray(&arrBootLoader);
  1460. DestroyDynamicArray(&arrKeyValuePairs);
  1461. SAFECLOSE(stream);
  1462. bRes = resetFileAttrib(szPath);
  1463. SafeCloseConnection(szServer,bConnFlag);
  1464. return (bRes);
  1465. }
  1466. /*****************************************************************************
  1467. Routine Description:
  1468. This function gets all the keys present in the specified section of
  1469. an .ini file and then returns the dynamic array containing all the
  1470. keys
  1471. Arguments:
  1472. [in] sziniFile : Name of the ini file.
  1473. [in] szinisection : Name of the section in the boot.ini.
  1474. Return Value :
  1475. TARRAY ( pointer to the dynamic array )
  1476. ******************************************************************************/
  1477. TARRAY getKeysOfINISection( LPTSTR sziniFile, LPTSTR sziniSection )
  1478. {
  1479. // Dynamic array which will hold all the keys
  1480. TARRAY arrKeys = NULL;
  1481. // Number of characters returned by the GetPrivateProfileString function
  1482. DWORD len = 0 ;
  1483. // Variables used in the loop
  1484. DWORD i = 0 ;
  1485. DWORD j = 0 ;
  1486. // Buffer which will be populated by the GetPrivateProfileString function
  1487. LPTSTR inBuf = NULL ;
  1488. DWORD dwLength = MAX_STRING_LENGTH1;
  1489. // Temporary variable which will contain the individual keys
  1490. LPTSTR szTemp = NULL ;
  1491. inBuf = (LPTSTR)malloc(dwLength*sizeof(TCHAR));
  1492. if(inBuf==NULL)
  1493. {
  1494. return NULL ;
  1495. }
  1496. szTemp = (LPTSTR)malloc(dwLength*sizeof(TCHAR));
  1497. if((szTemp == NULL))
  1498. {
  1499. SAFEFREE(inBuf);
  1500. return NULL ;
  1501. }
  1502. memset(inBuf,0,dwLength);
  1503. memset(szTemp,0,dwLength);
  1504. while(1)
  1505. {
  1506. // Getting all the keys from the boot.ini file
  1507. len = GetPrivateProfileString (sziniSection,
  1508. NULL,
  1509. ERROR_PROFILE_STRING,
  1510. inBuf,
  1511. dwLength,
  1512. sziniFile);
  1513. //if the size of the string is not sufficient then increment the size.
  1514. if(len == dwLength-2)
  1515. {
  1516. dwLength +=100 ;
  1517. inBuf = (LPTSTR)realloc(inBuf,dwLength*sizeof(TCHAR));
  1518. if(inBuf == NULL)
  1519. {
  1520. SAFEFREE(inBuf);
  1521. SAFEFREE(szTemp);
  1522. return NULL ;
  1523. }
  1524. szTemp = (LPTSTR)realloc(szTemp,dwLength*sizeof(TCHAR));
  1525. if(szTemp == NULL)
  1526. {
  1527. SAFEFREE(inBuf);
  1528. SAFEFREE(szTemp);
  1529. return NULL ;
  1530. }
  1531. }
  1532. else
  1533. break ;
  1534. }
  1535. // Creating a dynamic array by using the function in the DynArray.c module.
  1536. // This dynamic array will contain all the keys.
  1537. arrKeys = CreateDynamicArray();
  1538. if(arrKeys == NULL)
  1539. {
  1540. SAFEFREE(inBuf);
  1541. SAFEFREE(szTemp);
  1542. return NULL ;
  1543. }
  1544. // Looping through the characters returned by the above function
  1545. while(i<len)
  1546. {
  1547. // Each individual key will be got in arrTest array
  1548. szTemp[ j++ ] = inBuf[ i ];
  1549. if( inBuf[ i ] == TOKEN_DELIM )
  1550. {
  1551. // Setting j to 0 to start the next key.
  1552. j = 0;
  1553. // Appending each key to the dynamic array
  1554. DynArrayAppendString( arrKeys, szTemp, 0 );
  1555. if(lstrlen(szTemp)==0)
  1556. {
  1557. SAFEFREE(inBuf);
  1558. SAFEFREE(szTemp);
  1559. return NULL ;
  1560. }
  1561. }
  1562. // Incrementing loop variable
  1563. i++;
  1564. }
  1565. SAFEFREE(inBuf);
  1566. SAFEFREE(szTemp);
  1567. // returning the dynamic array containing all the keys
  1568. return arrKeys;
  1569. }
  1570. /*****************************************************************************
  1571. Routine Description:
  1572. This function gets all the key-value pairs of the [operating systems]
  1573. section and returns a dynamic array containing all the key-value pairs
  1574. Arguments:
  1575. [in] sziniFile : Name of the ini file.
  1576. [in] szinisection : Name of the section in the boot.ini.
  1577. Return Value :
  1578. TARRAY ( pointer to the dynamic array )
  1579. ******************************************************************************/
  1580. TARRAY getKeyValueOfINISection( LPTSTR iniFile, LPTSTR sziniSection )
  1581. {
  1582. // Dynamic array which will hold all the key-value pairs
  1583. TARRAY arrKeyValue = NULL;
  1584. // Number of characters returned by the GetPrivateProfileSection function
  1585. DWORD len = 0;
  1586. // Variables used in the loop
  1587. DWORD i = 0 ;
  1588. DWORD j = 0 ;
  1589. LPTSTR inbuf = NULL;
  1590. // Buffer which will be populated by the GetPrivateProfileSection function
  1591. // Temporary variable which will contain the individual keys
  1592. LPTSTR szTemp = NULL ;
  1593. DWORD dwLength = MAX_STRING_LENGTH1 ;
  1594. // Initialising loop variables
  1595. i = 0;
  1596. j = 0;
  1597. //return NULL if failed to allocate memory.
  1598. inbuf = (LPTSTR)malloc(dwLength*sizeof(TCHAR));
  1599. if(inbuf==NULL)
  1600. {
  1601. return NULL ;
  1602. }
  1603. //return NULL if failed to allocate memory
  1604. szTemp = (LPTSTR)malloc(dwLength*sizeof(TCHAR));
  1605. if(szTemp == NULL)
  1606. {
  1607. SAFEFREE(inbuf);
  1608. return NULL ;
  1609. }
  1610. memset(inbuf,0,dwLength);
  1611. while(1)
  1612. {
  1613. // Getting all the key-value pairs from the boot.ini file
  1614. len = GetPrivateProfileSection (sziniSection, inbuf,dwLength, iniFile);
  1615. if(len == dwLength -2)
  1616. {
  1617. dwLength +=100 ;
  1618. inbuf = (LPTSTR)realloc(inbuf,dwLength*sizeof(TCHAR));
  1619. szTemp = (LPTSTR)realloc(szTemp,dwLength*sizeof(TCHAR));
  1620. if((inbuf== NULL)||(szTemp==NULL))
  1621. {
  1622. SAFEFREE(inbuf);
  1623. SAFEFREE(szTemp);
  1624. return NULL ;
  1625. }
  1626. }
  1627. else
  1628. break ;
  1629. }
  1630. inbuf[lstrlen(inbuf)] = '\0';
  1631. // Creating a dynamic array by using the function in the DynArray.c module.
  1632. // This dynamic array will contain all the key-value pairs.
  1633. arrKeyValue = CreateDynamicArray();
  1634. if(arrKeyValue == NULL)
  1635. {
  1636. SAFEFREE(inbuf);
  1637. SAFEFREE(szTemp);
  1638. return NULL ;
  1639. }
  1640. // Looping through the characters returned by the above function
  1641. while(i<len)
  1642. {
  1643. // Each individual key will be got in arrTest array
  1644. szTemp[ j++ ] = inbuf[ i ];
  1645. if( inbuf[ i ] == TOKEN_DELIM)
  1646. {
  1647. szTemp[j+1] = '\0';
  1648. // Setting j to 0 to start the next key.
  1649. j = 0;
  1650. // Appending each key-value to the dynamic array
  1651. DynArrayAppendString( arrKeyValue, szTemp, 0 );
  1652. if(lstrlen(szTemp)==0)
  1653. {
  1654. SAFEFREE(inbuf);
  1655. SAFEFREE(szTemp);
  1656. return NULL ;
  1657. }
  1658. }
  1659. // Incrementing loop variable
  1660. i++;
  1661. }
  1662. // returning the dynamic array containing all the key-value pairs
  1663. SAFEFREE(inbuf);
  1664. SAFEFREE(szTemp);
  1665. return arrKeyValue;
  1666. }
  1667. /*****************************************************************************
  1668. Routine Description:
  1669. This function deletes a key from an ini section of an ini file
  1670. Arguments:
  1671. [in] szKey : Name of the key which has to be deleted
  1672. from the given section present in the
  1673. given ini file
  1674. [in] sziniFile : Name of the ini file.
  1675. [in] szinisection : Name of the section in the boot.ini.
  1676. Return Value :
  1677. BOOL (TRUE if there is no error, else the value is FALSE)
  1678. ******************************************************************************/
  1679. BOOL deleteKeyFromINISection( LPTSTR szKey, LPTSTR sziniFile, LPTSTR sziniSection )
  1680. {
  1681. // If the third parameter (default value) is NULL, the key pointed to by
  1682. // the key parameter is deleted from the specified section of the specified
  1683. // INI file
  1684. if( WritePrivateProfileString( sziniSection, szKey, NULL, sziniFile ) == 0 )
  1685. {
  1686. // If there is an error while writing then return false
  1687. return FALSE;
  1688. }
  1689. // If there is no error, then return true
  1690. return TRUE;
  1691. }
  1692. /*****************************************************************************
  1693. Routine Description:
  1694. This function removes a sub-string from a string
  1695. Arguments:
  1696. [in] szString : Main string
  1697. [in] szSubString : Sub-string
  1698. Return Value :
  1699. VOID
  1700. ******************************************************************************/
  1701. VOID removeSubString( LPTSTR szString, LPCTSTR szSubString )
  1702. {
  1703. TCHAR szFinalStr[MAX_STRING_LENGTH1] = NULL_STRING ;
  1704. DWORD dwSize = 1;
  1705. TCHAR sep[] = TOKEN_EMPTYSPACE;
  1706. PTCHAR pszToken = NULL_STRING;
  1707. // Character space is used for tokenising
  1708. lstrcpy( sep, _T(" ") );
  1709. // Getting the first token
  1710. pszToken = _tcstok( szString, sep );
  1711. while( pszToken != NULL )
  1712. {
  1713. // If the token is equal to the sub-string, then the token
  1714. // is not added to the final string. The final string contains
  1715. // all the tokens except the sub-string specified.
  1716. if(lstrcmpi( pszToken, szSubString ) != 0 )
  1717. {
  1718. lstrcpy( szFinalStr + dwSize - 1, TOKEN_EMPTYSPACE);
  1719. lstrcpy( szFinalStr + dwSize, pszToken );
  1720. dwSize = dwSize + lstrlen(pszToken) + 1;
  1721. }
  1722. // Getting the next token
  1723. pszToken = _tcstok( NULL, sep );
  1724. }
  1725. lstrcpy(szString,szFinalStr);
  1726. }
  1727. /*****************************************************************************
  1728. Routine Description:
  1729. This function establishes a connection to the specified system with
  1730. the given credentials.
  1731. Arguments:
  1732. [in] szServer : server name to coonect to
  1733. [in] szUser : User Name
  1734. [in] szPassword : password
  1735. [in] bNeedPwd : Boolean for asking the password.
  1736. [in] szPath : path of the ini file .
  1737. Return Value :
  1738. BOOL (EXIT_SUCCESS if there is no error, else the value is EXIT_FAILURE)
  1739. ******************************************************************************/
  1740. BOOL openConnection( STRING256 szServer, STRING256 szUser,STRING256 szPassword,
  1741. STRING100 szPath,BOOL bNeedPwd,FILE *stream,PBOOL pbConnFlag)
  1742. {
  1743. // Declaring the file path string which will hold the path of boot.ini file
  1744. TCHAR filePath[MAX_RES_STRING] = NULL_STRING ;
  1745. // Loop variable
  1746. DWORD i = 0;
  1747. // Position of the character we are searching for
  1748. #ifndef _WIN64
  1749. DWORD dwPos = 0;
  1750. #else
  1751. __int64 dwPos = 0;
  1752. #endif
  1753. // Boolean variable which will keep trach whether boot.ini file is present in
  1754. // any drive of a system or not
  1755. BOOL bFound = FALSE;
  1756. DWORD dwRetVal = 0 ;
  1757. // All the possible drive letters in a system
  1758. // A and B are removed, since they are assigned for floppy disk drives.
  1759. TCHAR szDrives[] = { DRIVE_C, DRIVE_D, DRIVE_E, DRIVE_F, DRIVE_G, DRIVE_H, DRIVE_I, DRIVE_J,DRIVE_K, DRIVE_L,
  1760. DRIVE_M, DRIVE_N, DRIVE_O, DRIVE_P,DRIVE_Q,DRIVE_R,DRIVE_S,DRIVE_T,DRIVE_U,
  1761. DRIVE_V,DRIVE_W,DRIVE_X,DRIVE_Y,DRIVE_Z};
  1762. // Pointer to the first occurence of the character '$'
  1763. TCHAR *pdest = NULL;
  1764. BOOL bResult = FALSE;
  1765. INT nRetVal = 0;
  1766. *pbConnFlag = TRUE ;
  1767. if( lstrcmpi(szServer, NULL_STRING) != 0 )
  1768. {
  1769. //bResult = EstablishConnection(szServer,szUser,SIZE_OF_ARRAY(szUser),szPassword,SIZE_OF_ARRAY(szPassword),bNeedPwd);
  1770. bResult = EstablishConnection(szServer,szUser,256,szPassword,SIZE_OF_ARRAY(szPassword),bNeedPwd);
  1771. if (bResult == FALSE)
  1772. {
  1773. DISPLAY_MESSAGE( stderr,ERROR_TAG );
  1774. DISPLAY_MESSAGE( stderr, GetReason());
  1775. return EXIT_FAILURE ;
  1776. }
  1777. else
  1778. {
  1779. switch( GetLastError() )
  1780. {
  1781. case I_NO_CLOSE_CONNECTION:
  1782. *pbConnFlag = FALSE ;
  1783. break;
  1784. case E_LOCAL_CREDENTIALS:
  1785. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  1786. {
  1787. *pbConnFlag = FALSE ;
  1788. break;
  1789. }
  1790. }
  1791. }
  1792. dwRetVal = CheckSystemType( szServer);
  1793. if(dwRetVal==EXIT_FAILURE )
  1794. {
  1795. return EXIT_FAILURE ;
  1796. }
  1797. // Building the file path of boot.ini file
  1798. // File Path is in \\server\C$\boot.ini format.
  1799. // Right now assuming that boot.ini file is in C Drive
  1800. lstrcpy(filePath, TOKEN_BACKSLASH4);
  1801. lstrcat(filePath, szServer);
  1802. lstrcat(filePath, TOKEN_BACKSLASH2);
  1803. lstrcat(filePath, TOKEN_C_DOLLAR);
  1804. lstrcat(filePath, TOKEN_BACKSLASH2);
  1805. lstrcat(filePath, TOKEN_BOOTINI_PATH);
  1806. lstrcpy(szPath, filePath);
  1807. // Finding the drive containing the boot.ini file
  1808. // For remote computer the path will be in the format
  1809. // \\MACHINE\DRIVELETTER$\boot.ini
  1810. while( i < 25 )
  1811. {
  1812. pdest = _tcschr(filePath, TOKEN_DOLLAR);
  1813. if (pdest==NULL)
  1814. {
  1815. return FALSE ;
  1816. }
  1817. dwPos = pdest - filePath ;
  1818. filePath[dwPos - 1] = szDrives[i];
  1819. stream = _tfopen(filePath,READ_MODE);
  1820. // If the boot.ini is found
  1821. if( stream != NULL )
  1822. {
  1823. bFound = TRUE;
  1824. fclose(stream);
  1825. break;
  1826. }
  1827. i++;
  1828. }
  1829. }
  1830. else
  1831. {
  1832. dwRetVal = CheckSystemType( szServer);
  1833. if(dwRetVal==EXIT_FAILURE )
  1834. {
  1835. return EXIT_FAILURE ;
  1836. }
  1837. lstrcpy(filePath, TOKEN_PATH);
  1838. // Finding the drive containing the boot.ini file
  1839. // For local computer the path will be in the format
  1840. // DRIVELETTER:\boot.ini
  1841. while( i < 25 )
  1842. {
  1843. pdest = _tcschr(filePath,_T(':'));
  1844. if (pdest==NULL)
  1845. {
  1846. return FALSE ;
  1847. }
  1848. dwPos = pdest - filePath + 1;
  1849. filePath[dwPos - 2] = szDrives[i];
  1850. stream = _tfopen(filePath, READ_MODE);
  1851. // If the boot.ini is found
  1852. if(stream != NULL )
  1853. {
  1854. fclose(stream);
  1855. bFound = TRUE;
  1856. break;
  1857. }
  1858. i++;
  1859. }
  1860. }
  1861. // If boot.ini is not found in any drives, then display error message
  1862. if( bFound == FALSE )
  1863. {
  1864. DISPLAY_MESSAGE(stderr,GetResString(IDS_BOOTINI));
  1865. return EXIT_FAILURE ;
  1866. }
  1867. nRetVal = _tchmod(filePath, _S_IREAD | _S_IWRITE);
  1868. // Changing the file permissions of the boot.ini file
  1869. if( nRetVal != 0 )
  1870. {
  1871. DISPLAY_MESSAGE(stderr,GetResString(IDS_READWRITE_BOOTINI));
  1872. return EXIT_FAILURE ;
  1873. }
  1874. else if (nRetVal == -1)
  1875. {
  1876. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_FILE));
  1877. return EXIT_FAILURE ;
  1878. }
  1879. // Open the Boot.ini file with both read and write mode
  1880. // If there is no error in opening the file, then return success
  1881. // of the boot.ini file to the calling function
  1882. return EXIT_SUCCESS ;
  1883. }
  1884. // ***************************************************************************
  1885. // Routine Description:
  1886. // This function fetches 64 bit Delete Usage information from resource file and displays it
  1887. //
  1888. // Arguments:
  1889. // None
  1890. //
  1891. // Return Value:
  1892. // void
  1893. // ***************************************************************************
  1894. void displayDeleteUsage_IA64()
  1895. {
  1896. DWORD dwIndex = ID_DEL_HELP_IA64_BEGIN;
  1897. for(;dwIndex <= ID_DEL_HELP_IA64_END;dwIndex++)
  1898. {
  1899. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  1900. }
  1901. }
  1902. // ***************************************************************************
  1903. // Routine Description:
  1904. // This function fetches 32 bit Delete Usage information from resource file and displays it
  1905. //
  1906. // Arguments:
  1907. // None
  1908. //
  1909. // Return Value:
  1910. // void
  1911. // ***************************************************************************
  1912. void displayDeleteUsage_X86()
  1913. {
  1914. DWORD dwIndex = ID_DEL_HELP_BEGIN;
  1915. for(;dwIndex <= ID_DEL_HELP_END;dwIndex++)
  1916. {
  1917. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  1918. }
  1919. }
  1920. // ***************************************************************************
  1921. // Routine Description:
  1922. // This function fetches 64 bit Copy Usage information from resource file and displays it
  1923. //
  1924. // Arguments:
  1925. // None
  1926. //
  1927. // Return Value:
  1928. // void
  1929. // ***************************************************************************
  1930. VOID displayCopyUsage_IA64()
  1931. {
  1932. DWORD dwIndex = ID_COPY_HELP_IA64_BEGIN;
  1933. for(;dwIndex <=ID_COPY_HELP_IA64_END;dwIndex++)
  1934. {
  1935. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  1936. }
  1937. }
  1938. // ***************************************************************************
  1939. // Routine Description:
  1940. // This function fetches 32 bit Copy Usage information from resource file and displays it
  1941. //
  1942. // Arguments:
  1943. // None
  1944. //
  1945. // Return Value:
  1946. // void
  1947. // ***************************************************************************
  1948. VOID displayCopyUsage_X86()
  1949. {
  1950. DWORD dwIndex = ID_COPY_HELP_BEGIN;
  1951. for(;dwIndex <=ID_COPY_HELP_END;dwIndex++)
  1952. {
  1953. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  1954. }
  1955. }
  1956. // ***************************************************************************
  1957. // Routine Description:
  1958. // This function fetches Query Usage information from resource file and displays it
  1959. //
  1960. // Arguments:
  1961. // None
  1962. //
  1963. // Return Value:
  1964. // void
  1965. // ***************************************************************************
  1966. VOID displayQueryUsage()
  1967. {
  1968. #ifdef _WIN64
  1969. displayQueryUsage_IA64();
  1970. #else
  1971. displayQueryUsage_X86();
  1972. #endif
  1973. }
  1974. // ***************************************************************************
  1975. // Routine Description:
  1976. // This function fetches Query Usage information from resource file and displays it
  1977. //
  1978. // Arguments:
  1979. // None
  1980. //
  1981. // Return Value:
  1982. // void
  1983. // ***************************************************************************
  1984. VOID displayQueryUsage_IA64()
  1985. {
  1986. DWORD dwIndex = ID_QUERY_HELP64_BEGIN ;
  1987. for(;dwIndex <= ID_QUERY_HELP64_END ;dwIndex++ )
  1988. {
  1989. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  1990. }
  1991. }
  1992. // ***************************************************************************
  1993. // Routine Description:
  1994. // This function fetches Query Usage information from resource file and displays it
  1995. //
  1996. // Arguments:
  1997. // None
  1998. //
  1999. // Return Value:
  2000. // void
  2001. // ***************************************************************************
  2002. VOID displayQueryUsage_X86()
  2003. {
  2004. DWORD dwIndex = ID_QUERY_HELP_BEGIN ;
  2005. for(;dwIndex <= ID_QUERY_HELP_END;dwIndex++ )
  2006. {
  2007. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  2008. }
  2009. }
  2010. // ***************************************************************************
  2011. // Routine Description:
  2012. // This function fetches Main Usage information from resource file and displays it
  2013. //
  2014. // Arguments:
  2015. // None
  2016. //
  2017. // Return Value:
  2018. // void
  2019. // ***************************************************************************
  2020. DWORD displayMainUsage_X86()
  2021. {
  2022. TCHAR szServer[MAX_RES_STRING] = NULL_STRING ;
  2023. DWORD dwRetVal = 0;
  2024. DWORD dwIndex = ID_MAIN_HELP_BEGIN1 ;
  2025. //display the error message if the target system is a 64 bit system or if error occured in
  2026. //retreiving the information
  2027. dwRetVal = CheckSystemType( szServer);
  2028. if(dwRetVal==EXIT_FAILURE )
  2029. {
  2030. return (EXIT_FAILURE);
  2031. }
  2032. for(;dwIndex <= ID_MAIN_HELP_END1 ;dwIndex++)
  2033. {
  2034. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  2035. }
  2036. return EXIT_SUCCESS ;
  2037. }
  2038. // ***************************************************************************
  2039. // Routine Description:
  2040. // This function fetches Usage information for the 64 bit system
  2041. //
  2042. // Arguments:
  2043. // None
  2044. //
  2045. // Return Value:
  2046. // void
  2047. // ***************************************************************************
  2048. VOID displayMainUsage_IA64()
  2049. {
  2050. DWORD dwIndex = ID_MAIN_HELP_IA64_BEGIN ;
  2051. for(;dwIndex <= ID_MAIN_HELP_IA64_END ;dwIndex++)
  2052. {
  2053. if( (dwIndex == IDS_MAIN_HELP23_IA64 ) || (dwIndex == IDS_MAIN_HELP24_IA64) || (dwIndex == IDS_MAIN_HELP38_IA64) )
  2054. {
  2055. continue;
  2056. }
  2057. else
  2058. {
  2059. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  2060. }
  2061. }
  2062. }
  2063. /*****************************************************************************
  2064. Routine Description:
  2065. This function resets the permissions with the original set of
  2066. permissions ( -readonly -hidden -system )
  2067. and then exits with the given exit code.
  2068. Arguments
  2069. [in] szFilePath : File Path of the boot.ini file
  2070. Return Value :
  2071. BOOL (EXIT_SUCCESS if there is no error, else the value is EXIT_FAILURE)
  2072. ******************************************************************************/
  2073. BOOL resetFileAttrib( LPTSTR szFilePath )
  2074. {
  2075. if(szFilePath==NULL)
  2076. {
  2077. return FALSE ;
  2078. }
  2079. // Resetting the file permission of the boot.ini file to its original
  2080. // permission list( -r, -h, -s )
  2081. if( _tchmod(szFilePath, _S_IREAD != 0 ) )
  2082. {
  2083. DISPLAY_MESSAGE(stderr,GetResString(IDS_RESET_ERROR));
  2084. return EXIT_FAILURE ;
  2085. }
  2086. return EXIT_SUCCESS ;
  2087. }
  2088. /*****************************************************************************
  2089. Routine Description:
  2090. This function returns a string from a dynamic array .
  2091. Arguments
  2092. [in] arrKeyValuePairs : Dynamic array which contains all the
  2093. key-value pairs.
  2094. [out] szFiinalStr : String which is formed from all the key-value pairs
  2095. Return Value :
  2096. BOOL (EXIT_SUCCESS if there is no error, else the value is EXIT_FAILURE)
  2097. ******************************************************************************/
  2098. BOOL stringFromDynamicArray1( TARRAY arrKeyValuePairs ,LPTSTR szFinalStr )
  2099. {
  2100. // Total number of elements in the array
  2101. DWORD dwKeyValueCount = 0;
  2102. // Variable used to keep track the current position while appending strings.
  2103. DWORD dwStrSize = 0;
  2104. // Loop variable
  2105. DWORD i = 0;
  2106. // Initialsing size and loop variables to 0
  2107. dwStrSize = 0;
  2108. i = 0;
  2109. if( (arrKeyValuePairs ==NULL)||(szFinalStr==NULL))
  2110. {
  2111. return EXIT_FAILURE ;
  2112. }
  2113. // Getting the total number of key-value pairs
  2114. if(arrKeyValuePairs != NULL)
  2115. {
  2116. dwKeyValueCount = DynArrayGetCount(arrKeyValuePairs);
  2117. }
  2118. else
  2119. {
  2120. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2121. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2122. ShowLastError(stderr);
  2123. return (EXIT_FAILURE) ;
  2124. }
  2125. // Looping through all the key-value pairs and building the final string
  2126. // containing all the key value pairs. This string has to be passed to
  2127. // WriteProfileSection
  2128. while( (i <= dwKeyValueCount - 1 )&& (arrKeyValuePairs != NULL) )
  2129. {
  2130. // Building the final string, by getting each key-value pair present in the
  2131. // dynamic array
  2132. if(arrKeyValuePairs != NULL)
  2133. {
  2134. LPCWSTR pwsz = NULL;
  2135. pwsz = DynArrayItemAsString( arrKeyValuePairs, i ) ;
  2136. if(pwsz != NULL)
  2137. {
  2138. lstrcpy(szFinalStr + dwStrSize, pwsz );
  2139. dwStrSize = dwStrSize + lstrlen(pwsz) + 1;
  2140. i++;
  2141. }
  2142. else
  2143. {
  2144. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2145. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2146. ShowLastError(stderr);
  2147. return EXIT_FAILURE ;
  2148. }
  2149. }
  2150. else
  2151. {
  2152. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2153. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2154. ShowLastError(stderr);
  2155. return EXIT_FAILURE ;
  2156. }
  2157. }
  2158. return EXIT_SUCCESS ;
  2159. }
  2160. // ***************************************************************************
  2161. // Routine Description:
  2162. // This function is used to build the header and also display the
  2163. // result in the required format as specified by the user.
  2164. //
  2165. // Arguments:
  2166. // [ in ] arrResults : argument(s) count specified at the command prompt
  2167. // [ in ] dwFormatType : format flags
  2168. // [ in ] bHeader : Boolean for specifying if the header is required or not.
  2169. //
  2170. // Return Value:
  2171. // none
  2172. //
  2173. // ***************************************************************************
  2174. VOID FormHeader(BOOL bHeader,TCOLUMNS *ResultHeader,BOOL bVerbose)
  2175. {
  2176. //OS Entry
  2177. ResultHeader[COL0].dwWidth = COL_BOOTOPTION_WIDTH ;
  2178. ResultHeader[COL0].dwFlags = SR_TYPE_STRING;
  2179. ResultHeader[COL0].pFunction = NULL;
  2180. ResultHeader[COL0].pFunctionData = NULL;
  2181. lstrcpy( ResultHeader[COL0].szFormat, NULL_STRING );
  2182. lstrcpy( ResultHeader[COL0].szColumn,COL_BOOTOPTION );
  2183. ResultHeader[COL1].dwWidth = COL_FRIENDLYNAME_WIDTH;
  2184. ResultHeader[COL1].dwFlags = SR_TYPE_STRING;
  2185. ResultHeader[COL1].pFunction = NULL;
  2186. ResultHeader[COL1].pFunctionData = NULL;
  2187. lstrcpy( ResultHeader[COL1].szFormat, NULL_STRING );
  2188. lstrcpy( ResultHeader[COL1].szColumn,COL_FRIENDLYNAME );
  2189. ResultHeader[COL2].dwWidth = COL_ARC_WIDTH;
  2190. ResultHeader[COL2].dwFlags = SR_TYPE_STRING;
  2191. ResultHeader[COL2].pFunction = NULL;
  2192. ResultHeader[COL2].pFunctionData = NULL;
  2193. lstrcpy( ResultHeader[COL2].szFormat, NULL_STRING );
  2194. lstrcpy( ResultHeader[COL2].szColumn,COL_ARCPATH );
  2195. ResultHeader[COL3].dwWidth = COL_BOOTID_WIDTH;
  2196. ResultHeader[COL3].dwFlags = SR_TYPE_STRING;
  2197. ResultHeader[COL3].pFunction = NULL;
  2198. ResultHeader[COL3].pFunctionData = NULL;
  2199. lstrcpy( ResultHeader[COL3].szFormat, NULL_STRING );
  2200. lstrcpy( ResultHeader[COL3].szColumn,COL_BOOTID );
  2201. }
  2202. // ***************************************************************************
  2203. // Routine Description:
  2204. // This routine is to display the current boot.ini file settings for
  2205. // the specified system.
  2206. //
  2207. // Arguments:
  2208. // [ in ] argc : Number of command line arguments
  2209. // [ in ] argv : Array containing command line arguments
  2210. // Return Value:
  2211. // DWORD
  2212. //
  2213. // ***************************************************************************
  2214. DWORD AppendRawString( DWORD argc, LPCTSTR argv[] )
  2215. {
  2216. BOOL bUsage = FALSE ;
  2217. BOOL bNeedPwd = FALSE ;
  2218. BOOL bRaw = FALSE ;
  2219. DWORD dwId = 0;
  2220. DWORD dwDefault = 0;
  2221. TARRAY arr ;
  2222. TCHAR szkey[MAX_RES_STRING] = NULL_STRING;
  2223. FILE *stream = NULL;
  2224. // Initialising the variables that are passed to TCMDPARSER structure
  2225. STRING256 szServer = NULL_STRING;
  2226. STRING256 szUser = NULL_STRING;
  2227. STRING256 szPassword = NULL_STRING;
  2228. STRING100 szPath = NULL_STRING;
  2229. STRING256 szRawString = NULL_STRING ;
  2230. DWORD dwNumKeys = 0;
  2231. BOOL bRes = FALSE ;
  2232. PTCHAR pToken = NULL ;
  2233. LPTSTR szFinalStr = NULL ;
  2234. BOOL bFlag = FALSE ;
  2235. TCHAR szBuffer[MAX_RES_STRING] = NULL_STRING ;
  2236. LPCTSTR szToken = NULL ;
  2237. DWORD dwRetVal = 0 ;
  2238. BOOL bConnFlag = FALSE ;
  2239. BOOL bAppendFlag = FALSE ;
  2240. TCHAR szErrorMsg[MAX_RES_STRING] = NULL_STRING ;
  2241. // Building the TCMDPARSER structure
  2242. TCMDPARSER cmdOptions[] =
  2243. {
  2244. { CMDOPTION_RAW, CP_MAIN_OPTION, 1, 0,&bRaw, NULL_STRING, NULL, NULL },
  2245. { SWITCH_SERVER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szServer, NULL_STRING, NULL, NULL },
  2246. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  2247. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  2248. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  2249. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY | CP_MANDATORY, 1, 0, &dwDefault, NULL_STRING, NULL, NULL },
  2250. { CMDOPTION_DEFAULT, CP_DEFAULT | CP_TYPE_TEXT | CP_MANDATORY, 1, 0, &szRawString,NULL_STRING, NULL, NULL },
  2251. { CMDOPTION_APPEND , 0, 1, 0, &bAppendFlag,NULL_STRING, NULL, NULL }
  2252. };
  2253. //
  2254. //check if the remote system is 64 bit and if so
  2255. // display an error.
  2256. //
  2257. dwRetVal = CheckSystemType( szServer);
  2258. if(dwRetVal==EXIT_FAILURE )
  2259. {
  2260. return EXIT_FAILURE ;
  2261. }
  2262. szFinalStr = (TCHAR*) malloc(MAX_STRING_LENGTH1* sizeof(TCHAR) );
  2263. if (szFinalStr== NULL)
  2264. {
  2265. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2266. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_TAG));
  2267. ShowLastError(stderr);
  2268. return (EXIT_FAILURE);
  2269. }
  2270. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  2271. _tcscpy(szPassword,TOKEN_ASTERIX);
  2272. // Parsing the copy option switches
  2273. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  2274. {
  2275. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  2276. ShowMessage(stderr,GetReason());
  2277. SAFEFREE(szFinalStr);
  2278. return (EXIT_FAILURE);
  2279. }
  2280. // Displaying query usage if user specified -? with -query option
  2281. if( bUsage )
  2282. {
  2283. dwRetVal = CheckSystemType( szServer);
  2284. if(dwRetVal==EXIT_SUCCESS )
  2285. {
  2286. displayRawUsage_X86();
  2287. SAFEFREE(szFinalStr);
  2288. return (EXIT_SUCCESS);
  2289. }
  2290. else
  2291. {
  2292. SAFEFREE(szFinalStr);
  2293. return (EXIT_FAILURE);
  2294. }
  2295. }
  2296. // error checking in case the
  2297. // raw string does not start with a "/" .
  2298. if(*szRawString != _T('/'))
  2299. {
  2300. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_FWDSLASH));
  2301. SAFEFREE(szFinalStr);
  2302. return (EXIT_FAILURE);
  2303. }
  2304. //display error message if the username is entered with out a machine name
  2305. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  2306. {
  2307. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  2308. ShowMessage(stderr,GetReason());
  2309. SAFEFREE(szFinalStr);
  2310. return EXIT_FAILURE ;
  2311. }
  2312. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  2313. {
  2314. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  2315. ShowMessage(stderr,GetReason());
  2316. SAFEFREE(szFinalStr);
  2317. return EXIT_FAILURE ;
  2318. }
  2319. //for setting the bNeedPwd
  2320. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  2321. {
  2322. bNeedPwd = TRUE ;
  2323. }
  2324. //set the bneedpassword to true if the server name is specified and password is not specified.
  2325. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  2326. {
  2327. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  2328. {
  2329. bNeedPwd = TRUE ;
  2330. }
  2331. else
  2332. {
  2333. bNeedPwd = FALSE ;
  2334. }
  2335. if(_tcslen(szPassword)!= 0 )
  2336. {
  2337. _tcscpy(szPassword,NULL_STRING);
  2338. }
  2339. }
  2340. //display an error message if the server is empty.
  2341. if((cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0))
  2342. {
  2343. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  2344. SAFEFREE(szFinalStr);
  2345. return EXIT_FAILURE ;
  2346. }
  2347. //display an error message if the user is empty.
  2348. if((cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  2349. {
  2350. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  2351. SAFEFREE(szFinalStr);
  2352. return EXIT_FAILURE ;
  2353. }
  2354. // Establishing connection to the specified machine and getting the file pointer
  2355. // of the boot.ini file if there is no error while establishing connection
  2356. lstrcpy(szPath, PATH_BOOTINI );
  2357. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  2358. {
  2359. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  2360. {
  2361. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  2362. if(szToken == NULL)
  2363. {
  2364. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  2365. return (EXIT_FAILURE);
  2366. }
  2367. lstrcpy(szServer,szToken);
  2368. }
  2369. }
  2370. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  2371. {
  2372. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  2373. _tcscpy(szServer,_T(""));
  2374. }
  2375. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag );
  2376. if(bFlag == EXIT_FAILURE)
  2377. {
  2378. SAFEFREE(szFinalStr);
  2379. SAFECLOSE(stream);
  2380. SafeCloseConnection(szServer,bConnFlag);
  2381. return (EXIT_FAILURE);
  2382. }
  2383. dwRetVal = CheckSystemType( szServer);
  2384. if(dwRetVal==EXIT_FAILURE )
  2385. {
  2386. SAFEFREE(szFinalStr);
  2387. SAFECLOSE(stream);
  2388. SafeCloseConnection(szServer,bConnFlag);
  2389. return (EXIT_FAILURE);
  2390. }
  2391. // Getting the keys of the Operating system section in the boot.ini file
  2392. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  2393. if(arr == NULL)
  2394. {
  2395. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2396. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2397. ShowLastError(stderr);
  2398. resetFileAttrib(szPath);
  2399. SAFEFREE(szFinalStr);
  2400. SAFECLOSE(stream);
  2401. SafeCloseConnection(szServer,bConnFlag);
  2402. return EXIT_FAILURE ;
  2403. }
  2404. // Getting the total number of keys in the operating systems section
  2405. dwNumKeys = DynArrayGetCount(arr);
  2406. //
  2407. if((dwNumKeys >= MAX_BOOTID_VAL)&&(dwDefault >= MAX_BOOTID_VAL ))
  2408. {
  2409. DISPLAY_MESSAGE(stderr,GetResString(IDS_MAX_BOOTID));
  2410. resetFileAttrib(szPath);
  2411. SAFEFREE(szFinalStr);
  2412. DestroyDynamicArray(&arr);
  2413. SAFECLOSE(stream);
  2414. SafeCloseConnection(szServer,bConnFlag);
  2415. return (EXIT_FAILURE);
  2416. }
  2417. // Displaying error message if the number of keys is less than the OS entry
  2418. // line number specified by the user
  2419. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  2420. {
  2421. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  2422. resetFileAttrib(szPath);
  2423. DestroyDynamicArray(&arr);
  2424. SAFEFREE(szFinalStr);
  2425. SAFECLOSE(stream);
  2426. SafeCloseConnection(szServer,bConnFlag);
  2427. return (EXIT_FAILURE);
  2428. }
  2429. // Getting the key of the OS entry specified by the user
  2430. if (arr != NULL)
  2431. {
  2432. LPCWSTR pwsz = NULL;
  2433. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  2434. if(pwsz != NULL)
  2435. {
  2436. _tcscpy( szkey,pwsz);
  2437. }
  2438. else
  2439. {
  2440. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2441. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2442. ShowLastError(stderr);
  2443. resetFileAttrib(szPath);
  2444. DestroyDynamicArray(&arr);
  2445. SAFEFREE(szFinalStr);
  2446. SAFECLOSE(stream);
  2447. SafeCloseConnection(szServer,bConnFlag);
  2448. return EXIT_FAILURE ;
  2449. }
  2450. }
  2451. else
  2452. {
  2453. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2454. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2455. ShowLastError(stderr);
  2456. resetFileAttrib(szPath);
  2457. DestroyDynamicArray(&arr);
  2458. SAFEFREE(szFinalStr);
  2459. SAFECLOSE(stream);
  2460. SafeCloseConnection(szServer,bConnFlag);
  2461. return EXIT_FAILURE ;
  2462. }
  2463. if(bAppendFlag == FALSE)
  2464. {
  2465. pToken = _tcstok(szkey ,TOKEN_FWDSLASH1);
  2466. if(pToken == NULL)
  2467. {
  2468. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  2469. resetFileAttrib(szPath);
  2470. DestroyDynamicArray(&arr);
  2471. SAFEFREE(szFinalStr);
  2472. SAFECLOSE(stream);
  2473. SafeCloseConnection(szServer,bConnFlag);
  2474. return EXIT_FAILURE ;
  2475. }
  2476. }
  2477. lstrcat(szkey , TOKEN_EMPTYSPACE);
  2478. CharLower(szRawString);
  2479. lstrcat(szkey ,szRawString);
  2480. if( _tcslen(szkey) >= MAX_RES_STRING)
  2481. {
  2482. _stprintf(szErrorMsg,GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  2483. DISPLAY_MESSAGE( stderr,szErrorMsg);
  2484. resetFileAttrib(szPath);
  2485. DestroyDynamicArray(&arr);
  2486. SAFEFREE(szFinalStr);
  2487. SAFECLOSE(stream);
  2488. SafeCloseConnection(szServer,bConnFlag);
  2489. return EXIT_FAILURE ;
  2490. }
  2491. DynArrayRemove(arr, dwDefault - 1 );
  2492. DynArrayInsertString(arr, dwDefault - 1, szkey, MAX_RES_STRING);
  2493. // Setting the buffer to 0, to avoid any junk value
  2494. memset(szFinalStr, 0, MAX_STRING_LENGTH1);
  2495. // Forming the final string from all the key-value pairs
  2496. if (stringFromDynamicArray1( arr,szFinalStr) == EXIT_FAILURE)
  2497. {
  2498. DestroyDynamicArray(&arr);
  2499. SAFEFREE(szFinalStr);
  2500. SAFECLOSE(stream);
  2501. resetFileAttrib(szPath);
  2502. SafeCloseConnection(szServer,bConnFlag);
  2503. return EXIT_FAILURE;
  2504. }
  2505. // Writing to the profile section with new key-value pair
  2506. // If the return value is non-zero, then there is an error.
  2507. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  2508. {
  2509. _stprintf(szBuffer,GetResString(IDS_SWITCH_ADD), dwDefault );
  2510. DISPLAY_MESSAGE(stdout,szBuffer);
  2511. }
  2512. else
  2513. {
  2514. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  2515. DestroyDynamicArray(&arr);
  2516. resetFileAttrib(szPath);
  2517. SAFEFREE(szFinalStr);
  2518. SAFECLOSE(stream);
  2519. SafeCloseConnection(szServer,bConnFlag);
  2520. return (EXIT_FAILURE);
  2521. }
  2522. //reset the file attributes and free the memory and close the connection to the server.
  2523. bRes = resetFileAttrib(szPath);
  2524. DestroyDynamicArray(&arr);
  2525. SAFEFREE(szFinalStr);
  2526. SAFECLOSE(stream);
  2527. SafeCloseConnection(szServer,bConnFlag);
  2528. return (EXIT_SUCCESS);
  2529. }
  2530. // ***************************************************************************
  2531. // Routine Description:
  2532. // This routine is to display the current boot.ini file settings for
  2533. // the specified system.
  2534. //
  2535. // Arguments:
  2536. // none
  2537. // Return Value:
  2538. // VOID
  2539. //
  2540. // ***************************************************************************
  2541. VOID displayRawUsage_X86()
  2542. {
  2543. DWORD dwIndex = RAW_HELP_BEGIN;
  2544. for(;dwIndex <= RAW_HELP_END;dwIndex++)
  2545. {
  2546. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  2547. }
  2548. }
  2549. // ***************************************************************************
  2550. // Routine Description:
  2551. // Display the help for the 64 bit raw option.
  2552. //
  2553. // Arguments:
  2554. // none
  2555. // Return Value:
  2556. // VOID
  2557. //
  2558. // ***************************************************************************
  2559. VOID displayRawUsage_IA64()
  2560. {
  2561. DWORD dwIndex = RAW_HELP_IA64_BEGIN;
  2562. for(;dwIndex <= RAW_HELP_IA64_END;dwIndex++)
  2563. {
  2564. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  2565. }
  2566. }
  2567. // ***************************************************************************
  2568. // Routine Description:
  2569. // This routine is to change the timout of the boot.ini file settings for
  2570. // the specified system.
  2571. // Arguments:
  2572. // [in ] argc : Number of command line arguments
  2573. // [in ] argv : Array containing command line arguments
  2574. //
  2575. // Return Value:
  2576. // DWORD
  2577. //
  2578. // ***************************************************************************
  2579. DWORD ChangeTimeOut(DWORD argc,LPCTSTR argv[])
  2580. {
  2581. STRING256 szServer = NULL_STRING;
  2582. STRING256 szUser = NULL_STRING;
  2583. STRING256 szPassword = NULL_STRING;
  2584. STRING100 szPath = NULL_STRING;
  2585. FILE *stream = NULL;
  2586. BOOL bNeedPwd = FALSE ;
  2587. TARRAY arrResults;
  2588. BOOL bRes= FALSE ;
  2589. DWORD dwCount = 0;
  2590. DWORD dwTimeOut = 0 ;
  2591. BOOL bFlag = 0 ;
  2592. TCHAR timeOutstr[STRING20] = NULL_STRING;
  2593. LPCTSTR szToken = NULL ;
  2594. DWORD dwRetVal = 0 ;
  2595. BOOL bConnFlag = FALSE ;
  2596. TCMDPARSER cmdOptions[] =
  2597. {
  2598. { CMDOPTION_TIMEOUT, CP_MAIN_OPTION | CP_TYPE_UNUMERIC | CP_VALUE_OPTIONAL|CP_VALUE_MANDATORY, 1, 0,&dwTimeOut,NULL_STRING, NULL, NULL},
  2599. { SWITCH_SERVER,CP_TYPE_TEXT|CP_VALUE_MANDATORY,1,0,&szServer,NULL_STRING,NULL,NULL},
  2600. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  2601. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  2602. };
  2603. //
  2604. //check if the remote system is 64 bit and if so
  2605. // display an error.
  2606. //
  2607. dwRetVal = CheckSystemType( szServer);
  2608. if(dwRetVal==EXIT_FAILURE )
  2609. {
  2610. return EXIT_FAILURE ;
  2611. }
  2612. //copy the Asterix token which is required for password prompting.
  2613. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  2614. _tcscpy(szPassword,TOKEN_ASTERIX);
  2615. if( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  2616. {
  2617. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  2618. ShowMessage(stderr,GetReason());
  2619. return EXIT_FAILURE ;
  2620. }
  2621. //display error message if the username is entered with out a machine name
  2622. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  2623. {
  2624. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  2625. ShowMessage(stderr,GetReason());
  2626. return EXIT_FAILURE ;
  2627. }
  2628. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  2629. {
  2630. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  2631. ShowMessage(stderr,GetReason());
  2632. return EXIT_FAILURE ;
  2633. }
  2634. //for setting the bNeedPwd
  2635. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  2636. {
  2637. bNeedPwd = TRUE ;
  2638. }
  2639. //set the bneedpassword to true if the server name is specified and password is not specified.
  2640. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  2641. {
  2642. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  2643. {
  2644. bNeedPwd = TRUE ;
  2645. }
  2646. else
  2647. {
  2648. bNeedPwd = FALSE ;
  2649. }
  2650. if(_tcslen(szPassword)!= 0 )
  2651. {
  2652. _tcscpy(szPassword,NULL_STRING);
  2653. }
  2654. }
  2655. //display an error message if the server is empty.
  2656. if((cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0))
  2657. {
  2658. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  2659. return EXIT_FAILURE ;
  2660. }
  2661. //display an error message if the user is empty.
  2662. if( (cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  2663. {
  2664. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  2665. return EXIT_FAILURE ;
  2666. }
  2667. // Establishing connection to the specified machine and getting the file pointer
  2668. // of the boot.ini file if there is no error while establishing connection
  2669. lstrcpy(szPath, PATH_BOOTINI );
  2670. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  2671. {
  2672. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  2673. {
  2674. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  2675. if(szToken == NULL)
  2676. {
  2677. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  2678. return (EXIT_FAILURE);
  2679. }
  2680. lstrcpy(szServer,szToken);
  2681. }
  2682. }
  2683. //display a warning message if it is a local system and set the server name to empty.
  2684. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  2685. {
  2686. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  2687. _tcscpy(szServer,_T(""));
  2688. }
  2689. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  2690. if(bFlag == EXIT_FAILURE)
  2691. {
  2692. SafeCloseConnection(szServer,bConnFlag);
  2693. return (EXIT_FAILURE);
  2694. }
  2695. arrResults = CreateDynamicArray();
  2696. if(arrResults == NULL)
  2697. {
  2698. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2699. resetFileAttrib(szPath);
  2700. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2701. ShowLastError(stderr);
  2702. SafeCloseConnection(szServer,bConnFlag);
  2703. SAFECLOSE(stream);
  2704. return (EXIT_FAILURE);
  2705. }
  2706. dwCount = DynArrayGetCount(arrResults);
  2707. if(dwTimeOut > TIMEOUT_MAX)
  2708. {
  2709. DISPLAY_MESSAGE(stderr,GetResString(IDS_TIMEOUT_RANGE));
  2710. resetFileAttrib(szPath);
  2711. DestroyDynamicArray(&arrResults);
  2712. SafeCloseConnection(szServer,bConnFlag);
  2713. SAFECLOSE(stream);
  2714. return (EXIT_FAILURE);
  2715. }
  2716. // Converting the numeric value to string because the WritePrivateProfileString
  2717. // takes only string value as the value for a particular key
  2718. _itot( dwTimeOut, timeOutstr, 10 );
  2719. // Changing the timeout value
  2720. if( WritePrivateProfileString( BOOTLOADERSECTION,TIMEOUT_SWITCH,
  2721. timeOutstr, szPath ) != 0 )
  2722. {
  2723. DestroyDynamicArray(&arrResults);
  2724. DISPLAY_MESSAGE(stdout,GetResString(IDS_TIMEOUT_CHANGE));
  2725. resetFileAttrib(szPath);
  2726. SafeCloseConnection(szServer,bConnFlag);
  2727. SAFECLOSE(stream);
  2728. return EXIT_SUCCESS ;
  2729. }
  2730. // DISPLAY Error message and exit with Error code of 1.
  2731. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_TIMEOUT));
  2732. bRes = resetFileAttrib(szPath);
  2733. DestroyDynamicArray(&arrResults);
  2734. SafeCloseConnection(szServer,bConnFlag);
  2735. SAFECLOSE(stream);
  2736. return EXIT_FAILURE ;
  2737. }
  2738. // ***************************************************************************
  2739. // Routine Description:
  2740. // Display the help for the timeout option.
  2741. // Arguments:
  2742. // NONE.
  2743. // Return Value:
  2744. // VOID
  2745. //
  2746. // ***************************************************************************
  2747. VOID displayTimeOutUsage_X86()
  2748. {
  2749. DWORD dwIndex = TIMEOUT_HELP_BEGIN;
  2750. for(;dwIndex <= TIMEOUT_HELP_END;dwIndex++)
  2751. {
  2752. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  2753. }
  2754. }
  2755. // ***************************************************************************
  2756. // Routine Description:
  2757. // Display the help for the 64 BIT timeout option.
  2758. // Arguments:
  2759. // NONE.
  2760. // Return Value:
  2761. // VOID
  2762. //
  2763. // ***************************************************************************
  2764. VOID displayTimeOutUsage_IA64()
  2765. {
  2766. DWORD dwIndex = TIMEOUT_HELP_IA64_BEGIN;
  2767. for(;dwIndex <= TIMEOUT_HELP_IA64_END;dwIndex++)
  2768. {
  2769. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  2770. }
  2771. }
  2772. // ***************************************************************************
  2773. // Routine Description:
  2774. // This routine is to change the Default OS boot.ini file settings for
  2775. // the specified system.
  2776. // Arguments:
  2777. // [IN] argc Number of command line arguments
  2778. // [IN] argv Array containing command line arguments
  2779. //
  2780. // Return Value:
  2781. // DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.
  2782. //
  2783. // ***************************************************************************
  2784. DWORD ChangeDefaultOs(DWORD argc,LPCTSTR argv[])
  2785. {
  2786. STRING256 szServer = NULL_STRING ;
  2787. STRING256 szUser = NULL_STRING ;
  2788. STRING256 szPassword = NULL_STRING ;
  2789. DWORD dwId = 0;
  2790. BOOL bDefaultOs = FALSE ;
  2791. STRING100 szPath ;
  2792. FILE *stream = NULL;
  2793. BOOL bNeedPwd = FALSE ;
  2794. TARRAY arrResults ;
  2795. DWORD dwCount = 0;
  2796. BOOL bFlag = FALSE ;
  2797. PTCHAR psztok = NULL ;
  2798. TCHAR szTmp[MAX_RES_STRING] = NULL_STRING ;
  2799. TCHAR szTmpBootId[MAX_RES_STRING] = NULL_STRING ;
  2800. TCHAR szDefaultId[MAX_RES_STRING] = NULL_STRING ;
  2801. DWORD dwValue = 0 ;
  2802. BOOL bExitFlag = FALSE ;
  2803. LPCWSTR pwsz[MAX_RES_STRING] ;
  2804. LPCWSTR pwszBootId [MAX_RES_STRING] ;
  2805. LPTSTR szFinalStr = NULL ;
  2806. LPCTSTR szToken = NULL ;
  2807. DWORD dwRetVal = 0 ;
  2808. BOOL bConnFlag = FALSE ;
  2809. BOOL bRes = FALSE;
  2810. TCMDPARSER cmdOptions[] =
  2811. {
  2812. { CMDOPTION_DEFAULTOS, CP_MAIN_OPTION, 1, 0,&bDefaultOs, NULL_STRING, NULL, NULL },
  2813. { SWITCH_SERVER,CP_TYPE_TEXT|CP_VALUE_MANDATORY,1,0,&szServer,NULL_STRING,NULL,NULL},
  2814. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  2815. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  2816. { SWITCH_ID,CP_TYPE_NUMERIC | CP_VALUE_MANDATORY| CP_MANDATORY, 1, 0, &dwId, NULL_STRING, NULL, NULL }
  2817. };
  2818. //
  2819. //check if the remote system is 64 bit and if so
  2820. // display an error.
  2821. //
  2822. dwRetVal = CheckSystemType( szServer);
  2823. if(dwRetVal==EXIT_FAILURE )
  2824. {
  2825. return EXIT_FAILURE ;
  2826. }
  2827. //copy the Asterix token which is required for password prompting.
  2828. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  2829. _tcscpy(szPassword,TOKEN_ASTERIX);
  2830. if( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  2831. {
  2832. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  2833. ShowMessage(stderr,GetReason());
  2834. return EXIT_FAILURE ;
  2835. }
  2836. if(dwId <= 0)
  2837. {
  2838. SetReason(GetResString( IDS_INVALID_OSID));
  2839. ShowMessage(stderr,GetReason());
  2840. return EXIT_FAILURE ;
  2841. }
  2842. //display error message if the username is entered with out a machine name
  2843. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  2844. {
  2845. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  2846. ShowMessage(stderr,GetReason());
  2847. return EXIT_FAILURE ;
  2848. }
  2849. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  2850. {
  2851. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  2852. ShowMessage(stderr,GetReason());
  2853. return EXIT_FAILURE ;
  2854. }
  2855. //display an error message if the server is empty.
  2856. if((cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0))
  2857. {
  2858. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  2859. return EXIT_FAILURE ;
  2860. }
  2861. //display an error message if the user is empty.
  2862. if((cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  2863. {
  2864. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  2865. return EXIT_FAILURE ;
  2866. }
  2867. //for setting the bNeedPwd
  2868. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  2869. {
  2870. bNeedPwd = TRUE ;
  2871. }
  2872. //set the bneedpassword to true if the server name is specified and password is not specified.
  2873. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  2874. {
  2875. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  2876. {
  2877. bNeedPwd = TRUE ;
  2878. }
  2879. else
  2880. {
  2881. bNeedPwd = FALSE ;
  2882. }
  2883. if(_tcslen(szPassword)!= 0 )
  2884. {
  2885. _tcscpy(szPassword,NULL_STRING);
  2886. }
  2887. }
  2888. // Establishing connection to the specified machine and getting the file pointer
  2889. // of the boot.ini file if there is no error while establishing connection
  2890. lstrcpy(szPath, PATH_BOOTINI );
  2891. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  2892. {
  2893. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  2894. {
  2895. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  2896. if(szToken == NULL)
  2897. {
  2898. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  2899. return (EXIT_FAILURE);
  2900. }
  2901. lstrcpy(szServer,szToken);
  2902. }
  2903. }
  2904. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  2905. {
  2906. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  2907. _tcscpy(szServer,_T(""));
  2908. }
  2909. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  2910. if(bFlag == EXIT_FAILURE)
  2911. {
  2912. SafeCloseConnection(szServer,bConnFlag);
  2913. return (EXIT_FAILURE);
  2914. }
  2915. arrResults = CreateDynamicArray();
  2916. //return failure if failed to allocate memory
  2917. if(arrResults == NULL)
  2918. {
  2919. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2920. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2921. ShowLastError(stderr);
  2922. DestroyDynamicArray(&arrResults);
  2923. SafeCloseConnection(szServer,bConnFlag);
  2924. SAFECLOSE(stream);
  2925. return (EXIT_FAILURE);
  2926. }
  2927. arrResults = getKeyValueOfINISection( szPath, OS_FIELD );
  2928. if(arrResults == NULL)
  2929. {
  2930. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2931. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2932. ShowLastError(stderr);
  2933. resetFileAttrib(szPath);
  2934. DestroyDynamicArray(&arrResults);
  2935. SafeCloseConnection(szServer,bConnFlag);
  2936. SAFECLOSE(stream);
  2937. return EXIT_FAILURE ;
  2938. }
  2939. dwCount = DynArrayGetCount(arrResults);
  2940. if(dwId<=0 || dwId > dwCount )
  2941. {
  2942. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_OSID));
  2943. resetFileAttrib(szPath);
  2944. DestroyDynamicArray(&arrResults);
  2945. SafeCloseConnection(szServer,bConnFlag);
  2946. SAFECLOSE(stream);
  2947. return EXIT_FAILURE ;
  2948. }
  2949. if(arrResults !=NULL)
  2950. {
  2951. pwsz[0] = DynArrayItemAsString(arrResults, dwId - 1);
  2952. pwszBootId[0] = DynArrayItemAsString(arrResults, 0);
  2953. if( (pwsz != NULL) || (pwszBootId != NULL) )
  2954. {
  2955. lstrcpy(szTmp,pwsz[0]) ;
  2956. lstrcpy(szDefaultId,pwsz[0]);
  2957. }
  2958. else
  2959. {
  2960. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2961. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2962. ShowLastError(stderr);
  2963. resetFileAttrib(szPath);
  2964. DestroyDynamicArray(&arrResults);
  2965. SafeCloseConnection(szServer,bConnFlag);
  2966. SAFECLOSE(stream);
  2967. return EXIT_FAILURE ;
  2968. }
  2969. }
  2970. else
  2971. {
  2972. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2973. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2974. ShowLastError(stderr);
  2975. resetFileAttrib(szPath);
  2976. DestroyDynamicArray(&arrResults);
  2977. SafeCloseConnection(szServer,bConnFlag);
  2978. SAFECLOSE(stream);
  2979. return EXIT_FAILURE ;
  2980. }
  2981. szFinalStr = (LPTSTR)malloc(MAX_STRING_LENGTH1*sizeof(TCHAR));
  2982. if(szFinalStr == NULL)
  2983. {
  2984. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  2985. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  2986. ShowLastError(stderr);
  2987. resetFileAttrib(szPath);
  2988. DestroyDynamicArray(&arrResults);
  2989. SafeCloseConnection(szServer,bConnFlag);
  2990. SAFECLOSE(stream);
  2991. return EXIT_FAILURE ;
  2992. }
  2993. //loop through all the Boot entries and
  2994. for(dwValue = dwId -1 ; dwValue > 0 ; dwValue-- )
  2995. {
  2996. pwszBootId[dwValue] = DynArrayItemAsString(arrResults,dwValue );
  2997. pwsz[dwValue] = DynArrayItemAsString(arrResults, dwValue - 1);
  2998. DynArrayRemove(arrResults, dwValue );
  2999. if (pwsz[dwValue] != NULL)
  3000. {
  3001. lstrcpy(szTmpBootId,pwsz[dwValue]) ;
  3002. }
  3003. else
  3004. {
  3005. bExitFlag = TRUE ;
  3006. break ;
  3007. }
  3008. DynArrayInsertString(arrResults, dwValue, szTmpBootId, MAX_RES_STRING);
  3009. }
  3010. if (bExitFlag == TRUE )
  3011. {
  3012. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3013. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3014. ShowLastError(stderr);
  3015. resetFileAttrib(szPath);
  3016. DestroyDynamicArray(&arrResults);
  3017. SafeCloseConnection(szServer,bConnFlag);
  3018. SAFECLOSE(stream);
  3019. SAFEFREE(szFinalStr);
  3020. return EXIT_FAILURE ;
  3021. }
  3022. DynArrayRemove(arrResults, 0 );
  3023. DynArrayInsertString(arrResults, 0, szDefaultId, MAX_RES_STRING);
  3024. // Setting the buffer to 0, to avoid any junk value
  3025. memset(szFinalStr, 0, MAX_STRING_LENGTH1);
  3026. if(stringFromDynamicArray1( arrResults,szFinalStr) == EXIT_FAILURE )
  3027. {
  3028. bExitFlag = TRUE ;
  3029. }
  3030. // Writing to the profile section with new key-value pair
  3031. // If the return value is non-zero, then there is an error.
  3032. if( ( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) == 0 ) || (bExitFlag == TRUE ) )
  3033. {
  3034. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERR_CHANGE));
  3035. resetFileAttrib(szPath);
  3036. DestroyDynamicArray(&arrResults);
  3037. SafeCloseConnection(szServer,bConnFlag);
  3038. SAFECLOSE(stream);
  3039. SAFEFREE(szFinalStr);
  3040. return EXIT_FAILURE ;
  3041. }
  3042. //to strip of the unwanted string from the string and save the required part in the Boot Loader section.
  3043. szToken = _tcstok(szTmp,TOKEN_EQUAL);
  3044. if(szToken == NULL)
  3045. {
  3046. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  3047. resetFileAttrib(szPath);
  3048. DestroyDynamicArray(&arrResults);
  3049. SafeCloseConnection(szServer,bConnFlag);
  3050. SAFECLOSE(stream);
  3051. SAFEFREE(szFinalStr);
  3052. return (EXIT_FAILURE);
  3053. }
  3054. if( WritePrivateProfileString( BOOTLOADERSECTION, KEY_DEFAULT, szTmp,
  3055. szPath ) != 0 )
  3056. {
  3057. DISPLAY_MESSAGE(stdout,GetResString(IDS_DEF_CHANGE));
  3058. }
  3059. else
  3060. {
  3061. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERR_CHANGE));
  3062. DestroyDynamicArray(&arrResults);
  3063. resetFileAttrib(szPath);
  3064. SafeCloseConnection(szServer,bConnFlag);
  3065. SAFECLOSE(stream);
  3066. SAFEFREE(szFinalStr);
  3067. return EXIT_FAILURE ;
  3068. }
  3069. bRes = resetFileAttrib(szPath);
  3070. DestroyDynamicArray(&arrResults);
  3071. SafeCloseConnection(szServer,bConnFlag);
  3072. SAFECLOSE(stream);
  3073. SAFEFREE(szFinalStr);
  3074. return bRes ;
  3075. }
  3076. // ***************************************************************************
  3077. // Routine Description : Display the help for the default entry option (x86).
  3078. //
  3079. // Parameters : none
  3080. //
  3081. // Return Type : VOID
  3082. //
  3083. // ***************************************************************************
  3084. VOID displayChangeOSUsage_X86()
  3085. {
  3086. DWORD dwIndex = DEFAULT_BEGIN;
  3087. for(;dwIndex <=DEFAULT_END;dwIndex++)
  3088. {
  3089. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  3090. }
  3091. }
  3092. // ***************************************************************************
  3093. //
  3094. // Routine Description : Display the help for the default entry option (IA64).
  3095. //
  3096. // Parameters : none
  3097. //
  3098. // Return Type : VOID
  3099. //
  3100. // ***************************************************************************
  3101. VOID displayDefaultEntryUsage_IA64()
  3102. {
  3103. DWORD dwIndex = DEFAULT_IA64_BEGIN;
  3104. for(;dwIndex <=DEFAULT_IA64_END;dwIndex++)
  3105. {
  3106. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  3107. }
  3108. }
  3109. // ***************************************************************************
  3110. // Routine Description:
  3111. // Implement the Debug switch.
  3112. // Arguments:
  3113. // [IN] argc Number of command line arguments
  3114. // [IN] argv Array containing command line arguments
  3115. //
  3116. // Return Value:
  3117. // DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  3118. //
  3119. // ***************************************************************************
  3120. DWORD ProcessDebugSwitch( DWORD argc, LPCTSTR argv[] )
  3121. {
  3122. BOOL bUsage = FALSE ;
  3123. BOOL bNeedPwd = FALSE ;
  3124. BOOL bDebug = FALSE ;
  3125. DWORD dwId = 0;
  3126. TARRAY arrResults ;
  3127. FILE *stream = NULL;
  3128. // Initialising the variables that are passed to TCMDPARSER structure
  3129. STRING256 szServer = NULL_STRING;
  3130. STRING256 szUser = NULL_STRING;
  3131. STRING256 szPassword = NULL_STRING;
  3132. STRING100 szPath = NULL_STRING;
  3133. TCHAR szDebug[MAX_RES_STRING] = NULL_STRING ;
  3134. TCHAR szPort[MAX_RES_STRING] = NULL_STRING ;
  3135. TCHAR szBoot[MAX_RES_STRING] = NULL_STRING ;
  3136. BOOL bRes = FALSE ;
  3137. LPTSTR szFinalStr = NULL ;
  3138. BOOL bFlag = FALSE ;
  3139. DWORD dwBaudRate = 0 ;
  3140. DWORD dwCount = 0 ;
  3141. DWORD dwSectionFlag = 0 ;
  3142. TCHAR szBuffer[MAX_RES_STRING] = NULL_STRING ;
  3143. TCHAR szTmpBuffer[MAX_RES_STRING] = NULL_STRING ;
  3144. TCHAR szBaudRate[MAX_RES_STRING] = NULL_STRING ;
  3145. TCHAR szString[MAX_STRING_LENGTH1] = NULL_STRING ;
  3146. TCHAR szTemp[MAX_RES_STRING] = NULL_STRING ;
  3147. _TCHAR *szValues[2] = {NULL};
  3148. TCHAR szMessage[MAX_STRING_LENGTH] = NULL_STRING;
  3149. TCHAR szErrorMsg[MAX_RES_STRING] = NULL_STRING ;
  3150. DWORD dwCode = 0 ;
  3151. LPCTSTR szToken = NULL ;
  3152. DWORD dwRetVal = 0 ;
  3153. BOOL bConnFlag = FALSE ;
  3154. // Building the TCMDPARSER structure
  3155. TCMDPARSER cmdOptions[] =
  3156. {
  3157. { CMDOPTION_DEBUG, CP_MAIN_OPTION, 1, 0,&bDebug, NULL_STRING, NULL, NULL },
  3158. { SWITCH_SERVER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szServer, NULL_STRING, NULL, NULL },
  3159. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  3160. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  3161. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  3162. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY | CP_MANDATORY, 1, 0, &dwId, NULL_STRING, NULL, NULL },
  3163. { SWITCH_PORT, CP_TYPE_TEXT | CP_VALUE_MANDATORY|CP_MODE_VALUES,1,0,&szPort,COM_PORT_RANGE,NULL,NULL},
  3164. { SWITCH_BAUD, CP_TYPE_TEXT | CP_VALUE_MANDATORY |CP_MODE_VALUES,1,0,&szBaudRate,BAUD_RATE_VALUES_DEBUG,NULL,NULL},
  3165. { CMDOPTION_DEFAULT, CP_DEFAULT | CP_TYPE_TEXT | CP_MANDATORY , 1, 0, &szDebug,NULL_STRING, NULL, NULL }
  3166. };
  3167. //
  3168. //check if the remote system is 64 bit and if so
  3169. // display an error.
  3170. //
  3171. dwRetVal = CheckSystemType( szServer);
  3172. if(dwRetVal==EXIT_FAILURE )
  3173. {
  3174. return EXIT_FAILURE ;
  3175. }
  3176. //copy the Asterix token which is required for password prompting.
  3177. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  3178. _tcscpy(szPassword,TOKEN_ASTERIX);
  3179. // Parsing the copy option switches
  3180. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  3181. {
  3182. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  3183. ShowMessage(stderr,GetReason());
  3184. return (EXIT_FAILURE);
  3185. }
  3186. if(bUsage)
  3187. {
  3188. dwRetVal = CheckSystemType( szServer);
  3189. if(dwRetVal==EXIT_SUCCESS )
  3190. {
  3191. displayDebugUsage_X86();
  3192. return (EXIT_SUCCESS);
  3193. }else
  3194. {
  3195. return (EXIT_FAILURE);
  3196. }
  3197. }
  3198. if(dwId <= 0)
  3199. {
  3200. SetReason(GetResString( IDS_INVALID_OSID));
  3201. ShowMessage(stderr,GetReason());
  3202. return EXIT_FAILURE ;
  3203. }
  3204. //display error message if the username is entered with out a machine name
  3205. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  3206. {
  3207. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  3208. ShowMessage(stderr,GetReason());
  3209. return EXIT_FAILURE ;
  3210. }
  3211. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  3212. {
  3213. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  3214. ShowMessage(stderr,GetReason());
  3215. return EXIT_FAILURE ;
  3216. }
  3217. //for setting the bNeedPwd
  3218. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  3219. {
  3220. bNeedPwd = TRUE ;
  3221. }
  3222. //set the bneedpassword to true if the server name is specified and password is not specified.
  3223. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  3224. {
  3225. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  3226. {
  3227. bNeedPwd = TRUE ;
  3228. }
  3229. else
  3230. {
  3231. bNeedPwd = FALSE ;
  3232. }
  3233. if(_tcslen(szPassword)!= 0 )
  3234. {
  3235. _tcscpy(szPassword,NULL_STRING);
  3236. }
  3237. }
  3238. //display an error message if the server is empty.
  3239. if( (cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0) )
  3240. {
  3241. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  3242. return EXIT_FAILURE ;
  3243. }
  3244. //display an error message if the user is empty.
  3245. if( (cmdOptions[2].dwActuals!=0) && (lstrlen(szUser)==0 ))
  3246. {
  3247. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  3248. return EXIT_FAILURE ;
  3249. }
  3250. //display an error message if the user specifies any string other than on,off,edit.
  3251. if( !( ( lstrcmpi(szDebug,VALUE_ON)== 0)|| (lstrcmpi(szDebug,VALUE_OFF)== 0) ||(lstrcmpi(szDebug,EDIT_STRING)== 0) ))
  3252. {
  3253. szValues[0]= (_TCHAR *)szDebug ;
  3254. szValues[1]= (_TCHAR *)CMDOPTION_DEBUG ;
  3255. FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  3256. GetResString(IDS_OPTION_SNTAX_ERROR),0,MAKELANGID(LANG_NEUTRAL,
  3257. SUBLANG_DEFAULT),szMessage, MAX_STRING_LENGTH,(va_list*)szValues);
  3258. DISPLAY_MESSAGE(stderr,szMessage);
  3259. return EXIT_FAILURE;
  3260. }
  3261. if( (lstrcmpi(szDebug,EDIT_STRING)== 0)&& (lstrlen(szPort)==0) && (lstrlen(szBaudRate)==0) )
  3262. {
  3263. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_EDIT_SYNTAX));
  3264. return EXIT_FAILURE;
  3265. }
  3266. // Establishing connection to the specified machine and getting the file pointer
  3267. // of the boot.ini file if there is no error while establishing connection
  3268. arrResults = CreateDynamicArray();
  3269. //return failure if failed to allocate memory
  3270. if(arrResults == NULL)
  3271. {
  3272. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3273. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3274. ShowLastError(stderr);
  3275. return (EXIT_FAILURE);
  3276. }
  3277. lstrcpy(szPath, PATH_BOOTINI );
  3278. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  3279. {
  3280. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  3281. {
  3282. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  3283. if(szToken == NULL)
  3284. {
  3285. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  3286. return (EXIT_FAILURE);
  3287. }
  3288. lstrcpy(szServer,szToken);
  3289. }
  3290. }
  3291. // display a warning message if it is a local system and set the
  3292. // server name to empty.
  3293. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  3294. {
  3295. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  3296. lstrcpy(szServer,_T(""));
  3297. }
  3298. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  3299. if(bFlag == EXIT_FAILURE)
  3300. {
  3301. SafeCloseConnection(szServer,bConnFlag);
  3302. return (EXIT_FAILURE);
  3303. }
  3304. arrResults = getKeyValueOfINISection( szPath, OS_FIELD );
  3305. if(arrResults == NULL)
  3306. {
  3307. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3308. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3309. ShowLastError(stderr);
  3310. resetFileAttrib(szPath);
  3311. SAFECLOSE(stream);
  3312. DestroyDynamicArray(&arrResults);
  3313. SafeCloseConnection(szServer,bConnFlag);
  3314. return EXIT_FAILURE ;
  3315. }
  3316. //getting the number of boot entries
  3317. dwCount = DynArrayGetCount(arrResults);
  3318. if(dwId<=0 || dwId > dwCount )
  3319. {
  3320. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_OSID));
  3321. resetFileAttrib(szPath);
  3322. SAFECLOSE(stream);
  3323. DestroyDynamicArray(&arrResults);
  3324. SafeCloseConnection(szServer,bConnFlag);
  3325. return EXIT_FAILURE ;
  3326. }
  3327. lstrcpy(szString ,DynArrayItemAsString(arrResults, dwId - 1 ));
  3328. if(lstrlen(szString) == 0)
  3329. {
  3330. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3331. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3332. ShowLastError(stderr);
  3333. resetFileAttrib(szPath);
  3334. SAFECLOSE(stream);
  3335. DestroyDynamicArray(&arrResults);
  3336. SafeCloseConnection(szServer,bConnFlag);
  3337. return EXIT_FAILURE ;
  3338. }
  3339. // check if the user entered the value of debug as on and do accordingly
  3340. if( lstrcmpi(szDebug,VALUE_ON)== 0)
  3341. {
  3342. //display error message if the user specifies Baud rate with out specifying COM port.
  3343. if((lstrlen(szPort)== 0) && (lstrlen(szBaudRate)!= 0))
  3344. {
  3345. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  3346. resetFileAttrib(szPath);
  3347. SAFECLOSE(stream);
  3348. DestroyDynamicArray(&arrResults);
  3349. SafeCloseConnection(szServer,bConnFlag);
  3350. return EXIT_FAILURE ;
  3351. }
  3352. //check if the debug switch is already present and if so display a error message.
  3353. if( (_tcsstr(szString,DEBUG_SWITCH) != NULL ) && ( (lstrlen(szPort)== 0)&&(lstrlen(szBaudRate)== 0) ) )
  3354. {
  3355. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_DEBUG));
  3356. resetFileAttrib(szPath);
  3357. SAFECLOSE(stream);
  3358. DestroyDynamicArray(&arrResults);
  3359. SafeCloseConnection(szServer,bConnFlag);
  3360. return EXIT_FAILURE ;
  3361. }
  3362. else
  3363. {
  3364. if(_tcsstr(szString,DEBUG_SWITCH) == NULL )
  3365. {
  3366. lstrcat(szString,TOKEN_EMPTYSPACE);
  3367. lstrcat(szString,DEBUG_SWITCH);
  3368. }
  3369. }
  3370. // get the type of the Com port present
  3371. dwCode = GetSubString(szString,TOKEN_DEBUGPORT,szTemp);
  3372. if((lstrlen(szTemp )!= 0)&& (lstrlen(szPort)!= 0))
  3373. {
  3374. _stprintf(szBuffer,GetResString(IDS_ERROR_DUPLICATE_COM_PORT), dwId );
  3375. DISPLAY_MESSAGE(stderr,szBuffer);
  3376. resetFileAttrib(szPath);
  3377. SAFECLOSE(stream);
  3378. DestroyDynamicArray(&arrResults);
  3379. SafeCloseConnection(szServer,bConnFlag);
  3380. return EXIT_FAILURE ;
  3381. }
  3382. // if the debug port is specified by the user.
  3383. if(lstrlen(szPort)!= 0)
  3384. {
  3385. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  3386. if (dwSectionFlag == MALLOC_FAILURE)
  3387. {
  3388. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3389. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3390. ShowLastError(stderr);
  3391. resetFileAttrib(szPath);
  3392. SAFECLOSE(stream);
  3393. DestroyDynamicArray(&arrResults);
  3394. SafeCloseConnection(szServer,bConnFlag);
  3395. return EXIT_FAILURE ;
  3396. }
  3397. if(lstrlen(szBoot)!= 0)
  3398. {
  3399. if (lstrcmpi(szBoot,szPort)==0)
  3400. {
  3401. DISPLAY_MESSAGE( stderr, GetResString(IDS_ERROR_REDIRECT_PORT));
  3402. resetFileAttrib(szPath);
  3403. SAFECLOSE(stream);
  3404. DestroyDynamicArray(&arrResults);
  3405. SafeCloseConnection(szServer,bConnFlag);
  3406. return EXIT_FAILURE ;
  3407. }
  3408. }
  3409. lstrcat(szTmpBuffer,TOKEN_EMPTYSPACE);
  3410. lstrcat(szTmpBuffer,TOKEN_DEBUGPORT) ;
  3411. lstrcat(szTmpBuffer,TOKEN_EQUAL) ;
  3412. CharLower(szPort);
  3413. lstrcat(szTmpBuffer,szPort);
  3414. lstrcat(szString,szTmpBuffer);
  3415. }
  3416. lstrcpy(szTemp,NULL_STRING);
  3417. //to add the Baud rate value specified by the user.
  3418. GetBaudRateVal(szString,szTemp) ;
  3419. if(lstrlen(szBaudRate)!=0)
  3420. {
  3421. if(lstrlen(szTemp )!= 0)
  3422. {
  3423. _stprintf(szBuffer,GetResString(IDS_ERROR_DUPLICATE_BAUD_VAL), dwId );
  3424. DISPLAY_MESSAGE(stderr,szBuffer);
  3425. resetFileAttrib(szPath);
  3426. SAFECLOSE(stream);
  3427. DestroyDynamicArray(&arrResults);
  3428. SafeCloseConnection(szServer,bConnFlag);
  3429. return EXIT_FAILURE ;
  3430. }else
  3431. {
  3432. //forming the string to be concatenated to the BootEntry string
  3433. lstrcpy(szTemp,BAUD_RATE);
  3434. lstrcat(szTemp,TOKEN_EQUAL);
  3435. lstrcat(szTemp,szBaudRate);
  3436. //append the string containing the modified port value to the string
  3437. lstrcat(szString,TOKEN_EMPTYSPACE);
  3438. lstrcat(szString,szTemp);
  3439. }
  3440. }
  3441. }
  3442. else if( lstrcmpi(szDebug,VALUE_OFF)== 0)
  3443. {
  3444. if((lstrlen(szPort)!= 0) || (lstrlen(szBaudRate)!= 0))
  3445. {
  3446. DestroyDynamicArray(&arrResults);
  3447. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  3448. resetFileAttrib(szPath);
  3449. SAFECLOSE(stream);
  3450. SafeCloseConnection(szServer,bConnFlag);
  3451. return EXIT_FAILURE ;
  3452. }
  3453. if (_tcsstr(szString,DEBUG_SWITCH) == 0 )
  3454. {
  3455. DISPLAY_MESSAGE(stderr,GetResString(IDS_DEBUG_ABSENT));
  3456. resetFileAttrib(szPath);
  3457. SAFECLOSE(stream);
  3458. DestroyDynamicArray(&arrResults);
  3459. SafeCloseConnection(szServer,bConnFlag);
  3460. return EXIT_FAILURE ;
  3461. }
  3462. else
  3463. {
  3464. // remove the /debug switch.
  3465. removeSubString(szString,DEBUG_SWITCH);
  3466. lstrcpy(szTemp,NULL_STRING);
  3467. // get the type of the Com port present
  3468. dwCode = GetSubString(szString,TOKEN_DEBUGPORT,szTemp);
  3469. if(lstrcmpi(szTemp,PORT_1394)==0)
  3470. {
  3471. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_1394_REMOVE));
  3472. resetFileAttrib(szPath);
  3473. SAFECLOSE(stream);
  3474. DestroyDynamicArray(&arrResults);
  3475. SafeCloseConnection(szServer,bConnFlag);
  3476. return EXIT_FAILURE ;
  3477. }
  3478. // remove the /debugport=comport switch if it is present from the Boot Entry
  3479. if (lstrlen(szTemp )!= 0)
  3480. {
  3481. removeSubString(szString,szTemp);
  3482. }
  3483. lstrcpy(szTemp , NULL_STRING );
  3484. //remove the baud rate switch if it is present.
  3485. GetBaudRateVal(szString,szTemp) ;
  3486. if (lstrlen(szTemp )!= 0)
  3487. {
  3488. removeSubString(szString,szTemp);
  3489. }
  3490. }
  3491. }
  3492. // if the user enters the EDIT option
  3493. else if(lstrcmpi(szDebug,SWITCH_EDIT)== 0)
  3494. {
  3495. //display error message if the /debugport=1394 switch is present already.
  3496. if(_tcsstr(szString,DEBUGPORT_1394)!=0)
  3497. {
  3498. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_EDIT_1394_SWITCH));
  3499. resetFileAttrib(szPath);
  3500. SAFECLOSE(stream);
  3501. DestroyDynamicArray(&arrResults);
  3502. SafeCloseConnection(szServer,bConnFlag);
  3503. return EXIT_FAILURE ;
  3504. }
  3505. if (_tcsstr(szString,DEBUG_SWITCH) == 0 )
  3506. {
  3507. _stprintf(szBuffer,GetResString(IDS_ERROR_NO_DBG_SWITCH), dwId );
  3508. DISPLAY_MESSAGE(stderr,szBuffer);
  3509. resetFileAttrib(szPath);
  3510. SAFECLOSE(stream);
  3511. DestroyDynamicArray(&arrResults);
  3512. SafeCloseConnection(szServer,bConnFlag);
  3513. return EXIT_FAILURE ;
  3514. }
  3515. lstrcpy(szTemp,NULL_STRING);
  3516. dwCode = GetSubString(szString,TOKEN_DEBUGPORT,szTemp);
  3517. //display an error message if user is trying to add baudrate value
  3518. // when there is no COM port present in the boot options.
  3519. if( (lstrlen(szTemp)==0)&&(lstrlen(szPort)== 0)&&(lstrlen(szBaudRate)!= 0) )
  3520. {
  3521. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_COM_PORT));
  3522. resetFileAttrib(szPath);
  3523. SAFECLOSE(stream);
  3524. DestroyDynamicArray(&arrResults);
  3525. SafeCloseConnection(szServer,bConnFlag);
  3526. return EXIT_FAILURE ;
  3527. }
  3528. else
  3529. {
  3530. // chk if the port has been spec by the user
  3531. if((lstrlen(szPort)== 0)&&(lstrlen(szBaudRate)== 0))
  3532. {
  3533. DestroyDynamicArray(&arrResults);
  3534. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_DEBUG));
  3535. resetFileAttrib(szPath);
  3536. SAFECLOSE(stream);
  3537. SafeCloseConnection(szServer,bConnFlag);
  3538. return EXIT_FAILURE ;
  3539. }
  3540. if(lstrlen(szPort)!= 0)
  3541. {
  3542. lstrcpy(szTemp , NULL_STRING );
  3543. // get the type of the Com port present
  3544. lstrcpy(szTemp,NULL_STRING);
  3545. dwCode = GetSubString(szString,TOKEN_DEBUGPORT,szTemp);
  3546. //display error message if there is no COM port found at all in the OS option
  3547. //changed for displaying error
  3548. if(lstrlen(szTemp )== 0 )
  3549. {
  3550. _stprintf(szBuffer,GetResString(IDS_ERROR_NO_COM_PORT), dwId );
  3551. DISPLAY_MESSAGE(stderr,szBuffer);
  3552. bRes = resetFileAttrib(szPath);
  3553. SAFECLOSE(stream);
  3554. DestroyDynamicArray(&arrResults);
  3555. SafeCloseConnection(szServer,bConnFlag);
  3556. return EXIT_FAILURE ;
  3557. }
  3558. // remove the /debugport=comport switch if it is present from the Boot Entry
  3559. removeSubString(szString,szTemp);
  3560. lstrcpy(szTemp,TOKEN_DEBUGPORT) ;
  3561. lstrcat(szTemp,TOKEN_EQUAL);
  3562. CharUpper(szPort) ;
  3563. lstrcat(szTemp,szPort);
  3564. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  3565. if (dwSectionFlag == MALLOC_FAILURE)
  3566. {
  3567. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3568. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3569. ShowLastError(stderr);
  3570. resetFileAttrib(szPath);
  3571. SAFECLOSE(stream);
  3572. DestroyDynamicArray(&arrResults);
  3573. SafeCloseConnection(szServer,bConnFlag);
  3574. return EXIT_FAILURE ;
  3575. }
  3576. if(lstrlen(szBoot)!= 0)
  3577. {
  3578. if (lstrcmpi(szBoot,szPort)==0)
  3579. {
  3580. DISPLAY_MESSAGE( stderr, GetResString(IDS_ERROR_REDIRECT_PORT));
  3581. resetFileAttrib(szPath);
  3582. SAFECLOSE(stream);
  3583. DestroyDynamicArray(&arrResults);
  3584. SafeCloseConnection(szServer,bConnFlag);
  3585. return EXIT_FAILURE ;
  3586. }
  3587. }
  3588. //append the string containing the modified port value to the string
  3589. lstrcat(szString,TOKEN_EMPTYSPACE);
  3590. lstrcat(szString,szTemp);
  3591. }
  3592. //to edit the baud rate value
  3593. if(lstrlen(szBaudRate)!= 0)
  3594. {
  3595. lstrcpy(szTemp , NULL_STRING );
  3596. //remove the baud rate switch if it is present.
  3597. GetBaudRateVal(szString,szTemp) ;
  3598. // remove the swithc to be changed.
  3599. removeSubString(szString,szTemp);
  3600. //forming the string to be concatenated to the BootEntry string
  3601. lstrcpy(szTemp,BAUD_RATE);
  3602. lstrcat(szTemp,TOKEN_EQUAL);
  3603. lstrcat(szTemp,szBaudRate);
  3604. //append the string containing the modified port value to the string
  3605. lstrcat(szString,TOKEN_EMPTYSPACE);
  3606. lstrcat(szString,szTemp);
  3607. }
  3608. }
  3609. }
  3610. //display an error message if the Os Load Options string is more than
  3611. // 254 characters in length.
  3612. if( _tcslen(szString) >= MAX_RES_STRING)
  3613. {
  3614. _stprintf(szErrorMsg,GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  3615. DISPLAY_MESSAGE( stderr,szErrorMsg);
  3616. SAFEFREE(szFinalStr);
  3617. resetFileAttrib(szPath);
  3618. SAFECLOSE(stream);
  3619. DestroyDynamicArray(&arrResults);
  3620. SafeCloseConnection(szServer,bConnFlag);
  3621. return (EXIT_FAILURE);
  3622. }
  3623. DynArrayRemove(arrResults, dwId - 1 );
  3624. DynArrayInsertString(arrResults, dwId - 1, szString, MAX_STRING_LENGTH1);
  3625. // Variable storing the path of boot.ini file
  3626. szFinalStr = (TCHAR*)malloc(MAX_STRING_LENGTH1* sizeof(TCHAR));
  3627. if (szFinalStr == NULL)
  3628. {
  3629. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3630. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3631. SAFEFREE(szFinalStr);
  3632. resetFileAttrib(szPath);
  3633. SAFECLOSE(stream);
  3634. ShowLastError(stderr);
  3635. DestroyDynamicArray(&arrResults);
  3636. SafeCloseConnection(szServer,bConnFlag);
  3637. return (EXIT_FAILURE);
  3638. }
  3639. // Setting the buffer to 0, to avoid any junk value
  3640. memset(szFinalStr, 0, MAX_STRING_LENGTH1);
  3641. // Forming the final string from all the key-value pairs
  3642. if (stringFromDynamicArray1( arrResults,szFinalStr) == EXIT_FAILURE)
  3643. {
  3644. DestroyDynamicArray(&arrResults);
  3645. SAFEFREE(szFinalStr);
  3646. resetFileAttrib(szPath);
  3647. SAFECLOSE(stream);
  3648. SafeCloseConnection(szServer,bConnFlag);
  3649. return EXIT_FAILURE;
  3650. }
  3651. // Writing to the profile section with new key-value pair
  3652. // If the return value is non-zero, then there is an error.
  3653. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  3654. {
  3655. _stprintf(szBuffer,GetResString(IDS_SWITCH_CHANGE), dwId );
  3656. DISPLAY_MESSAGE(stdout,szBuffer);
  3657. }
  3658. else
  3659. {
  3660. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  3661. DestroyDynamicArray(&arrResults);
  3662. resetFileAttrib(szPath);
  3663. SAFEFREE(szFinalStr);
  3664. SAFECLOSE(stream);
  3665. SafeCloseConnection(szServer,bConnFlag);
  3666. return (EXIT_FAILURE);
  3667. }
  3668. bRes = resetFileAttrib(szPath);
  3669. SAFEFREE(szFinalStr);
  3670. SAFECLOSE(stream);
  3671. SafeCloseConnection(szServer,bConnFlag);
  3672. DestroyDynamicArray(&arrResults);
  3673. return (bRes) ;
  3674. }
  3675. // ***************************************************************************
  3676. //
  3677. // Routine Description : Get the Type of Baud Rate present in Boot Entry
  3678. //
  3679. // Parameters : szString : The String which is to be searched.
  3680. // szTemp : String which will get the com port type
  3681. // Return Type : VOID
  3682. //
  3683. // ***************************************************************************
  3684. VOID GetBaudRateVal(LPTSTR szString, LPTSTR szTemp)
  3685. {
  3686. if(_tcsstr(szString,BAUD_VAL6)!=0)
  3687. {
  3688. lstrcpy(szTemp,BAUD_VAL6);
  3689. }
  3690. else if(_tcsstr(szString,BAUD_VAL7)!=0)
  3691. {
  3692. lstrcpy(szTemp,BAUD_VAL7);
  3693. }
  3694. else if(_tcsstr(szString,BAUD_VAL8)!=0)
  3695. {
  3696. lstrcpy(szTemp,BAUD_VAL8);
  3697. }
  3698. else if(_tcsstr(szString,BAUD_VAL9)!=0)
  3699. {
  3700. lstrcpy(szTemp,BAUD_VAL9);
  3701. }
  3702. else if(_tcsstr(szString,BAUD_VAL10)!=0)
  3703. {
  3704. lstrcpy(szTemp,BAUD_VAL10);
  3705. }
  3706. }
  3707. // ***************************************************************************
  3708. // Routine Description:
  3709. // Implement the ProcessEmsSwitch switch.
  3710. // Arguments:
  3711. // [IN] argc Number of command line arguments
  3712. // [IN] argv Array containing command line arguments
  3713. //
  3714. // Return Value:
  3715. // DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  3716. //
  3717. // ***************************************************************************
  3718. DWORD ProcessEmsSwitch( DWORD argc, LPCTSTR argv[] )
  3719. {
  3720. BOOL bUsage = FALSE ;
  3721. BOOL bNeedPwd = FALSE ;
  3722. BOOL bEms = FALSE ;
  3723. DWORD dwId = 0;
  3724. TARRAY arrResults ;
  3725. TARRAY arrBootIni ;
  3726. FILE *stream = NULL;
  3727. // Initialising the variables that are passed to TCMDPARSER structure
  3728. STRING256 szServer = NULL_STRING;
  3729. STRING256 szUser = NULL_STRING;
  3730. STRING256 szPassword = NULL_STRING;
  3731. STRING100 szPath = NULL_STRING;
  3732. TCHAR szPort[MAX_RES_STRING] = NULL_STRING ;
  3733. BOOL bRes = FALSE ;
  3734. BOOL bFlag = FALSE ;
  3735. DWORD dwCount = 0 ;
  3736. TCHAR szBuffer[MAX_RES_STRING] = NULL_STRING ;
  3737. TCHAR szDefault[MAX_RES_STRING] = NULL_STRING ;
  3738. TCHAR szString[MAX_STRING_LENGTH1] = NULL_STRING ;
  3739. TCHAR szBaudRate[MAX_RES_STRING] = NULL_STRING ;
  3740. TCHAR szBoot[MAX_RES_STRING] = NULL_STRING ;
  3741. LPTSTR szFinalStr = NULL ;
  3742. BOOL bRedirectFlag = FALSE ;
  3743. TCHAR szRedirectBaudrate[MAX_RES_STRING] = NULL_STRING ;
  3744. BOOL bRedirectBaudFlag = FALSE ;
  3745. TCHAR szErrorMsg[MAX_RES_STRING] = NULL_STRING ;
  3746. DWORD dwSectionFlag = FALSE ;
  3747. TCHAR szDebugPort[MAX_RES_STRING] = NULL_STRING ;
  3748. TCHAR szBootString[MAX_RES_STRING] = NULL_STRING ;
  3749. DWORD dwI = 0 ;
  3750. BOOL bMemFlag = FALSE ;
  3751. BOOL bDefault = FALSE ;
  3752. LPCTSTR szToken = NULL ;
  3753. DWORD dwRetVal = 0 ;
  3754. BOOL bConnFlag = FALSE ;
  3755. TCMDPARSER cmdOptions[] =
  3756. {
  3757. { CMDOPTION_EMS, CP_MAIN_OPTION, 1, 0,&bDefault, NULL_STRING, NULL, NULL },
  3758. { SWITCH_SERVER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szServer, NULL_STRING, NULL, NULL },
  3759. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  3760. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  3761. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  3762. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY , 1, 0, &dwId, NULL_STRING, NULL, NULL },
  3763. { SWITCH_PORT, CP_TYPE_TEXT | CP_VALUE_MANDATORY|CP_MODE_VALUES,1,0,&szPort,EMS_PORT_VALUES,NULL,NULL},
  3764. { SWITCH_BAUD, CP_TYPE_TEXT | CP_VALUE_MANDATORY |CP_MODE_VALUES,1,0,&szBaudRate,BAUD_RATE_VALUES_EMS,NULL,NULL},
  3765. { CMDOPTION_DEFAULT, CP_DEFAULT | CP_TYPE_TEXT | CP_MANDATORY , 1, 0, &szDefault,NULL_STRING, NULL, NULL }
  3766. };
  3767. //
  3768. //check if the remote system is 64 bit and if so
  3769. // display an error.
  3770. //
  3771. dwRetVal = CheckSystemType( szServer);
  3772. if(dwRetVal==EXIT_FAILURE )
  3773. {
  3774. return EXIT_FAILURE ;
  3775. }
  3776. //copy the Asterix token which is required for password prompting.
  3777. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  3778. _tcscpy(szPassword,TOKEN_ASTERIX);
  3779. // Parsing the copy option switches
  3780. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  3781. {
  3782. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  3783. ShowMessage(stderr,GetReason());
  3784. return (EXIT_FAILURE);
  3785. }
  3786. if(bUsage)
  3787. {
  3788. dwRetVal = CheckSystemType( szServer);
  3789. if(dwRetVal==EXIT_SUCCESS )
  3790. {
  3791. displayEmsUsage_X86() ;
  3792. return (EXIT_SUCCESS) ;
  3793. }else
  3794. {
  3795. return (EXIT_FAILURE);
  3796. }
  3797. }
  3798. //display error message if the username is entered with out a machine name
  3799. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  3800. {
  3801. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  3802. ShowMessage(stderr,GetReason());
  3803. return EXIT_FAILURE ;
  3804. }
  3805. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  3806. {
  3807. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  3808. ShowMessage(stderr,GetReason());
  3809. return EXIT_FAILURE ;
  3810. }
  3811. //for setting the bNeedPwd
  3812. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  3813. {
  3814. bNeedPwd = TRUE ;
  3815. }
  3816. //set the bneedpassword to true if the server name is specified and password is not specified.
  3817. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  3818. {
  3819. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  3820. {
  3821. bNeedPwd = TRUE ;
  3822. }
  3823. else
  3824. {
  3825. bNeedPwd = FALSE ;
  3826. }
  3827. if(_tcslen(szPassword)!= 0 )
  3828. {
  3829. _tcscpy(szPassword,NULL_STRING);
  3830. }
  3831. }
  3832. //display an error message if the server is empty.
  3833. if( (cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0) )
  3834. {
  3835. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  3836. return EXIT_FAILURE ;
  3837. }
  3838. //display an error message if the user is empty.
  3839. if((cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  3840. {
  3841. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  3842. return EXIT_FAILURE ;
  3843. }
  3844. //display error message if the user enters any invalid string.
  3845. if( !( ( lstrcmpi(szDefault,VALUE_ON)== 0) || (lstrcmpi(szDefault,VALUE_OFF)== 0 ) ||(lstrcmpi(szDefault,EDIT_STRING)== 0) ) )
  3846. {
  3847. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_EMS));
  3848. return EXIT_FAILURE;
  3849. }
  3850. if( (lstrcmpi(szDefault,EDIT_STRING)== 0)&& (lstrlen(szPort)==0) && (lstrlen(szBaudRate)==0) )
  3851. {
  3852. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_EDIT_SYNTAX));
  3853. return EXIT_FAILURE;
  3854. }
  3855. if( ( (lstrcmpi(szDefault,ON_STRING)== 0) || (lstrcmpi(szDefault,OFF_STRING)== 0) )&& (cmdOptions[5].dwActuals==0) )
  3856. {
  3857. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_ID_MISSING));
  3858. DISPLAY_MESSAGE(stderr,GetResString(IDS_EMS_HELP));
  3859. return EXIT_FAILURE;
  3860. }
  3861. // Establishing connection to the specified machine and getting the file pointer
  3862. // of the boot.ini file if there is no error while establishing connection
  3863. lstrcpy(szPath, PATH_BOOTINI );
  3864. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  3865. {
  3866. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  3867. {
  3868. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  3869. if(szToken == NULL)
  3870. {
  3871. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  3872. return (EXIT_FAILURE);
  3873. }
  3874. lstrcpy(szServer,szToken);
  3875. }
  3876. }
  3877. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  3878. {
  3879. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  3880. _tcscpy(szServer,_T(""));
  3881. }
  3882. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  3883. if(bFlag == EXIT_FAILURE)
  3884. {
  3885. SafeCloseConnection(szServer,bConnFlag);
  3886. return (EXIT_FAILURE);
  3887. }
  3888. arrResults = CreateDynamicArray();
  3889. //return failure if failed to allocate memory
  3890. if(arrResults == NULL)
  3891. {
  3892. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3893. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3894. ShowLastError(stderr);
  3895. resetFileAttrib(szPath);
  3896. SafeCloseConnection(szServer,bConnFlag);
  3897. SAFECLOSE(stream);
  3898. return (EXIT_FAILURE);
  3899. }
  3900. arrResults = getKeyValueOfINISection( szPath, OS_FIELD );
  3901. if(arrResults != NULL)
  3902. {
  3903. lstrcpy(szString ,DynArrayItemAsString(arrResults, dwId - 1 ));
  3904. }
  3905. else
  3906. {
  3907. bMemFlag = TRUE ;
  3908. }
  3909. if((szString == NULL)||(bMemFlag == TRUE ))
  3910. {
  3911. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3912. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3913. ShowLastError(stderr);
  3914. resetFileAttrib(szPath);
  3915. DestroyDynamicArray(&arrResults);
  3916. SafeCloseConnection(szServer,bConnFlag);
  3917. SAFECLOSE(stream);
  3918. return EXIT_FAILURE ;
  3919. }
  3920. //getting the number of boot entries
  3921. dwCount = DynArrayGetCount(arrResults);
  3922. if((dwId<=0 || dwId > dwCount ) && (lstrcmpi(szDefault,SWITCH_EDIT)!= 0) )
  3923. {
  3924. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_OSID));
  3925. DestroyDynamicArray(&arrResults);
  3926. resetFileAttrib(szPath);
  3927. SafeCloseConnection(szServer,bConnFlag);
  3928. SAFECLOSE(stream);
  3929. return EXIT_FAILURE ;
  3930. }
  3931. // common code till here . from here process acc to the ON/OFF/EDIT flag.
  3932. if(lstrcmpi(szDefault,ON_STRING)==0)
  3933. {
  3934. if((_tcsstr(szString,REDIRECT) != 0))
  3935. {
  3936. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_REDIRECT_SWITCH));
  3937. DestroyDynamicArray(&arrResults);
  3938. SAFECLOSE(stream);
  3939. resetFileAttrib(szPath);
  3940. SafeCloseConnection(szServer,bConnFlag);
  3941. return EXIT_FAILURE;
  3942. }
  3943. //Display an error message if there is no redirect port present in the
  3944. // bootloader section and the user also does not specify the COM port.
  3945. if ((lstrlen(szPort)== 0))
  3946. {
  3947. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  3948. if (dwSectionFlag == MALLOC_FAILURE)
  3949. {
  3950. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3951. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3952. ShowLastError(stderr);
  3953. DestroyDynamicArray(&arrResults);
  3954. SAFECLOSE(stream);
  3955. resetFileAttrib(szPath);
  3956. SafeCloseConnection(szServer,bConnFlag);
  3957. return EXIT_FAILURE;
  3958. }
  3959. if(lstrlen(szBoot)== 0 )
  3960. {
  3961. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NO_PORT));
  3962. DestroyDynamicArray(&arrResults);
  3963. SAFECLOSE(stream);
  3964. resetFileAttrib(szPath);
  3965. SafeCloseConnection(szServer,bConnFlag);
  3966. return EXIT_FAILURE;
  3967. }
  3968. }
  3969. if(lstrlen(szPort)!= 0)
  3970. {
  3971. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,BAUDRATE_STRING,szRedirectBaudrate);
  3972. if (dwSectionFlag == MALLOC_FAILURE)
  3973. {
  3974. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3975. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3976. ShowLastError(stderr);
  3977. DestroyDynamicArray(&arrResults);
  3978. SAFECLOSE(stream);
  3979. resetFileAttrib(szPath);
  3980. SafeCloseConnection(szServer,bConnFlag);
  3981. return EXIT_FAILURE;
  3982. }
  3983. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  3984. if (dwSectionFlag == MALLOC_FAILURE)
  3985. {
  3986. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  3987. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  3988. ShowLastError(stderr);
  3989. DestroyDynamicArray(&arrResults);
  3990. SAFECLOSE(stream);
  3991. resetFileAttrib(szPath);
  3992. SafeCloseConnection(szServer,bConnFlag);
  3993. return EXIT_FAILURE;
  3994. }
  3995. //display warning message if the redirect=COMX entry is already present in the BootLoader section.
  3996. if(lstrlen(szBoot)!= 0 )
  3997. {
  3998. DISPLAY_MESSAGE(stdout,GetResString(IDS_WARN_REDIRECT));
  3999. bRedirectFlag = TRUE ;
  4000. }
  4001. if( (lstrlen(szRedirectBaudrate)!=0)&&(lstrlen(szBaudRate)!= 0 ))
  4002. {
  4003. DISPLAY_MESSAGE(stdout,GetResString(IDS_WARN_REDIRECTBAUD));
  4004. bRedirectBaudFlag = TRUE ;
  4005. }
  4006. // if the Boot loader section does not
  4007. // contain any port for redirection.
  4008. if(!bRedirectFlag)
  4009. {
  4010. if (lstrcmpi(szPort,USEBIOSSET)== 0)
  4011. {
  4012. lstrcpy(szPort,USEBIOSSETTINGS);
  4013. }
  4014. // scan the entire BOOT.INI and check if the specified Port
  4015. lstrcpy(szDebugPort,DEBUGPORT);
  4016. lstrcat(szDebugPort,szPort);
  4017. arrBootIni = getKeyValueOfINISection( szPath, OS_FIELD );
  4018. if(arrBootIni == NULL)
  4019. {
  4020. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4021. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  4022. ShowLastError(stderr);
  4023. resetFileAttrib(szPath);
  4024. SafeCloseConnection(szServer,bConnFlag);
  4025. DestroyDynamicArray(&arrResults);
  4026. SAFECLOSE(stream);
  4027. return EXIT_FAILURE ;
  4028. }
  4029. //
  4030. //loop through all the OS entries and check if any of the
  4031. //
  4032. for(dwI = 0 ;dwI < dwCount-1 ; dwI++ )
  4033. {
  4034. lstrcpy(szBootString ,DynArrayItemAsString(arrBootIni,dwI));
  4035. CharLower(szDebugPort);
  4036. if(_tcsstr(szBootString,szDebugPort)!= 0)
  4037. {
  4038. DISPLAY_MESSAGE( stderr, GetResString(IDS_ERROR_DEBUG_PORT));
  4039. resetFileAttrib(szPath);
  4040. SafeCloseConnection(szServer,bConnFlag);
  4041. DestroyDynamicArray(&arrResults);
  4042. DestroyDynamicArray(&arrBootIni);
  4043. SAFECLOSE(stream);
  4044. return EXIT_FAILURE ;
  4045. }
  4046. }
  4047. //convert the com port value specified by user to upper case for storing into the ini file.
  4048. CharUpper(szPort);
  4049. if( WritePrivateProfileString( BOOTLOADERSECTION,KEY_REDIRECT,szPort, szPath ) != 0 )
  4050. {
  4051. DISPLAY_MESSAGE(stdout,GetResString(IDS_EMS_CHANGE_BOOTLOADER));
  4052. }
  4053. else
  4054. {
  4055. DISPLAY_MESSAGE(stderr,GetResString(IDS_EMS_CHANGE_ERROR_BLOADER));
  4056. resetFileAttrib(szPath);
  4057. SafeCloseConnection(szServer,bConnFlag);
  4058. DestroyDynamicArray(&arrResults);
  4059. DestroyDynamicArray(&arrBootIni);
  4060. SAFECLOSE(stream);
  4061. return EXIT_FAILURE ;
  4062. }
  4063. }
  4064. }
  4065. if(!bRedirectBaudFlag)
  4066. {
  4067. // to add the baudrate to the BOOTLOADER section.
  4068. if(lstrlen(szBaudRate) != 0 )
  4069. {
  4070. if( WritePrivateProfileString( BOOTLOADERSECTION,KEY_BAUDRATE,szBaudRate, szPath ) != 0 )
  4071. {
  4072. DISPLAY_MESSAGE(stdout,GetResString(IDS_EMS_CHANGE_BAUDRATE));
  4073. }
  4074. else
  4075. {
  4076. DISPLAY_MESSAGE(stderr,GetResString(IDS_EMS_CHANGE_ERROR_BAUDRATE));
  4077. resetFileAttrib(szPath);
  4078. SafeCloseConnection(szServer,bConnFlag);
  4079. DestroyDynamicArray(&arrResults);
  4080. DestroyDynamicArray(&arrBootIni);
  4081. SAFECLOSE(stream);
  4082. return EXIT_FAILURE ;
  4083. }
  4084. }
  4085. }
  4086. //add the /redirect into the OS options.
  4087. lstrcat(szString,TOKEN_EMPTYSPACE);
  4088. lstrcat(szString,REDIRECT);
  4089. //display an error message if the Os Load Options string is more than
  4090. // 254 characters in length.
  4091. if( _tcslen(szString) >= MAX_RES_STRING)
  4092. {
  4093. _stprintf(szErrorMsg,GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  4094. DISPLAY_MESSAGE( stderr,szErrorMsg);
  4095. SAFEFREE(szFinalStr);
  4096. resetFileAttrib(szPath);
  4097. SafeCloseConnection(szServer,bConnFlag);
  4098. DestroyDynamicArray(&arrResults);
  4099. DestroyDynamicArray(&arrBootIni);
  4100. SAFECLOSE(stream);
  4101. return (EXIT_FAILURE);
  4102. }
  4103. DynArrayRemove(arrResults, dwId - 1 );
  4104. DynArrayInsertString(arrResults, dwId - 1, szString, MAX_STRING_LENGTH1);
  4105. szFinalStr = (TCHAR*)malloc(MAX_STRING_LENGTH1* sizeof(TCHAR));
  4106. if (szFinalStr == NULL)
  4107. {
  4108. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4109. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  4110. ShowLastError(stderr);
  4111. SAFEFREE(szFinalStr);
  4112. resetFileAttrib(szPath);
  4113. SafeCloseConnection(szServer,bConnFlag);
  4114. DestroyDynamicArray(&arrResults);
  4115. DestroyDynamicArray(&arrBootIni);
  4116. SAFECLOSE(stream);
  4117. return (EXIT_FAILURE);
  4118. }
  4119. // Setting the buffer to 0, to avoid any junk value
  4120. memset(szFinalStr, 0, MAX_STRING_LENGTH1);
  4121. // Forming the final string from all the key-value pairs
  4122. if (stringFromDynamicArray1( arrResults,szFinalStr) == EXIT_FAILURE)
  4123. {
  4124. DestroyDynamicArray(&arrResults);
  4125. SAFEFREE(szFinalStr);
  4126. resetFileAttrib(szPath);
  4127. SafeCloseConnection(szServer,bConnFlag);
  4128. DestroyDynamicArray(&arrResults);
  4129. DestroyDynamicArray(&arrBootIni);
  4130. SAFECLOSE(stream);
  4131. return EXIT_FAILURE;
  4132. }
  4133. // Writing to the profile section with new key-value pair
  4134. // If the return value is non-zero, then there is an error.
  4135. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  4136. {
  4137. _stprintf(szBuffer,GetResString(IDS_SWITCH_CHANGE), dwId );
  4138. DISPLAY_MESSAGE(stdout,szBuffer);
  4139. }
  4140. else
  4141. {
  4142. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  4143. SAFEFREE(szFinalStr);
  4144. resetFileAttrib(szPath);
  4145. SafeCloseConnection(szServer,bConnFlag);
  4146. DestroyDynamicArray(&arrResults);
  4147. DestroyDynamicArray(&arrBootIni);
  4148. SAFECLOSE(stream);
  4149. return (EXIT_FAILURE);
  4150. }
  4151. }
  4152. if(lstrcmpi(szDefault,EDIT_STRING)==0)
  4153. {
  4154. //display error message if user enters a id for the edit option.
  4155. if(dwId!=0)
  4156. {
  4157. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_EMS));
  4158. SAFEFREE(szFinalStr);
  4159. SAFECLOSE(stream);
  4160. resetFileAttrib(szPath);
  4161. SafeCloseConnection(szServer,bConnFlag);
  4162. DestroyDynamicArray(&arrResults);
  4163. return EXIT_FAILURE ;
  4164. }
  4165. if (lstrcmpi(szPort,USEBIOSSET)== 0)
  4166. {
  4167. lstrcpy(szPort,USEBIOSSETTINGS);
  4168. }
  4169. //get the keys of the specified ini section.
  4170. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,BAUDRATE_STRING,szRedirectBaudrate);
  4171. if (dwSectionFlag == MALLOC_FAILURE)
  4172. {
  4173. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4174. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  4175. ShowLastError(stderr);
  4176. DestroyDynamicArray(&arrResults);
  4177. SAFECLOSE(stream);
  4178. SAFEFREE(szFinalStr);
  4179. resetFileAttrib(szPath);
  4180. SafeCloseConnection(szServer,bConnFlag);
  4181. return EXIT_FAILURE;
  4182. }
  4183. //get the keys of the specified ini section.
  4184. dwSectionFlag = getKeysOfSpecifiedINISection(szPath ,BOOTLOADERSECTION,REDIRECT_STRING,szBoot);
  4185. if (dwSectionFlag == MALLOC_FAILURE)
  4186. {
  4187. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4188. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  4189. ShowLastError(stderr);
  4190. DestroyDynamicArray(&arrResults);
  4191. SAFECLOSE(stream);
  4192. SAFEFREE(szFinalStr);
  4193. resetFileAttrib(szPath);
  4194. SafeCloseConnection(szServer,bConnFlag);
  4195. return EXIT_FAILURE;
  4196. }
  4197. if( (lstrlen(szBoot) == 0 ) && ((cmdOptions[6].dwActuals!=0)) )
  4198. {
  4199. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_COM_PORT));
  4200. DestroyDynamicArray(&arrResults);
  4201. SAFECLOSE(stream);
  4202. SAFEFREE(szFinalStr);
  4203. resetFileAttrib(szPath);
  4204. SafeCloseConnection(szServer,bConnFlag);
  4205. return EXIT_FAILURE;
  4206. }
  4207. if( (lstrlen(szRedirectBaudrate) == 0 ) && ((cmdOptions[7].dwActuals!=0)) )
  4208. {
  4209. DISPLAY_MESSAGE( stderr,GetResString(IDS_ERROR_BAUDRATE_HELP));
  4210. DestroyDynamicArray(&arrResults);
  4211. SAFECLOSE(stream);
  4212. SAFEFREE(szFinalStr);
  4213. resetFileAttrib(szPath);
  4214. SafeCloseConnection(szServer,bConnFlag);
  4215. return EXIT_FAILURE;
  4216. }
  4217. lstrcpy(szDebugPort,DEBUGPORT);
  4218. lstrcat(szDebugPort,szPort);
  4219. arrBootIni = getKeyValueOfINISection( szPath, OS_FIELD );
  4220. if(arrBootIni == NULL)
  4221. {
  4222. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4223. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  4224. ShowLastError(stderr);
  4225. resetFileAttrib(szPath);
  4226. SafeCloseConnection(szServer,bConnFlag);
  4227. DestroyDynamicArray(&arrResults);
  4228. SAFECLOSE(stream);
  4229. return EXIT_FAILURE ;
  4230. }
  4231. //
  4232. //loop through all the OS entries and check if any of the
  4233. //
  4234. for(dwI = 0 ;dwI < dwCount-1 ; dwI++ )
  4235. {
  4236. lstrcpy(szBootString ,DynArrayItemAsString(arrBootIni,dwI));
  4237. CharLower(szDebugPort);
  4238. if(_tcsstr(szBootString,szDebugPort)!= 0)
  4239. {
  4240. DISPLAY_MESSAGE( stderr, GetResString(IDS_ERROR_DEBUG_PORT));
  4241. resetFileAttrib(szPath);
  4242. SafeCloseConnection(szServer,bConnFlag);
  4243. DestroyDynamicArray(&arrResults);
  4244. DestroyDynamicArray(&arrBootIni);
  4245. SAFECLOSE(stream);
  4246. return EXIT_FAILURE ;
  4247. }
  4248. }
  4249. // edit the Boot loader section with the redirect values entered by the user.
  4250. CharUpper(szPort);
  4251. if(lstrlen(szPort)!= 0)
  4252. {
  4253. if( WritePrivateProfileString( BOOTLOADERSECTION,KEY_REDIRECT,
  4254. szPort, szPath ) != 0 )
  4255. {
  4256. DISPLAY_MESSAGE(stdout,GetResString(IDS_EMS_CHANGE_BOOTLOADER));
  4257. }
  4258. else
  4259. {
  4260. DISPLAY_MESSAGE(stderr,GetResString(IDS_EMS_CHANGE_ERROR_BLOADER));
  4261. resetFileAttrib(szPath);
  4262. SAFEFREE(szFinalStr);
  4263. DestroyDynamicArray(&arrResults);
  4264. DestroyDynamicArray(&arrBootIni);
  4265. SafeCloseConnection(szServer,bConnFlag);
  4266. SAFECLOSE(stream);
  4267. return EXIT_FAILURE ;
  4268. }
  4269. }
  4270. // edit the Boot loader section with the baudrate values entered by the user.
  4271. if(lstrlen(szBaudRate)!= 0)
  4272. {
  4273. if( WritePrivateProfileString( BOOTLOADERSECTION,KEY_BAUDRATE,
  4274. szBaudRate, szPath ) != 0 )
  4275. {
  4276. DISPLAY_MESSAGE(stdout,GetResString(IDS_EMS_CHANGE_BAUDRATE));
  4277. }
  4278. else
  4279. {
  4280. DISPLAY_MESSAGE(stderr,GetResString(IDS_EMS_CHANGE_ERROR_BAUDRATE));
  4281. resetFileAttrib(szPath);
  4282. SAFEFREE(szFinalStr);
  4283. DestroyDynamicArray(&arrResults);
  4284. DestroyDynamicArray(&arrBootIni);
  4285. SAFECLOSE(stream);
  4286. SafeCloseConnection(szServer,bConnFlag);
  4287. return EXIT_FAILURE ;
  4288. }
  4289. }
  4290. }
  4291. // if the option value is off.
  4292. if(lstrcmpi(szDefault,VALUE_OFF)==0)
  4293. {
  4294. //display an error message if either the com port or baud rate is typed in the command line
  4295. if((lstrlen(szBaudRate)!=0)||(lstrlen(szPort)!=0))
  4296. {
  4297. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_EMS));
  4298. DestroyDynamicArray(&arrResults);
  4299. SAFEFREE(szFinalStr);
  4300. SAFECLOSE(stream);
  4301. resetFileAttrib(szPath);
  4302. SafeCloseConnection(szServer,bConnFlag);
  4303. return EXIT_FAILURE;
  4304. }
  4305. // display error message if the /redirect switch is not present in the Boot.ini
  4306. if((_tcsstr(szString,REDIRECT) == 0))
  4307. {
  4308. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_REDIRECT_SWITCH));
  4309. DestroyDynamicArray(&arrResults);
  4310. SAFEFREE(szFinalStr);
  4311. SAFECLOSE(stream);
  4312. resetFileAttrib(szPath);
  4313. SafeCloseConnection(szServer,bConnFlag);
  4314. return EXIT_FAILURE;
  4315. }
  4316. //remove the /redirect switch from the OS entry specified .
  4317. removeSubString(szString,REDIRECT);
  4318. //display an error message if the Os Load options string is more than
  4319. // 255 characters in length.
  4320. if( _tcslen(szString) >= MAX_RES_STRING)
  4321. {
  4322. _stprintf(szErrorMsg,GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  4323. DISPLAY_MESSAGE( stderr,szErrorMsg);
  4324. resetFileAttrib(szPath);
  4325. DestroyDynamicArray(&arrResults);
  4326. SAFEFREE(szFinalStr);
  4327. SAFECLOSE(stream);
  4328. SafeCloseConnection(szServer,bConnFlag);
  4329. return (EXIT_FAILURE);
  4330. }
  4331. DynArrayRemove(arrResults, dwId - 1 );
  4332. DynArrayInsertString(arrResults, dwId - 1, szString, MAX_STRING_LENGTH1);
  4333. szFinalStr = (TCHAR*)malloc(MAX_STRING_LENGTH1* sizeof(TCHAR));
  4334. if (szFinalStr == NULL)
  4335. {
  4336. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4337. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  4338. ShowLastError(stderr);
  4339. resetFileAttrib(szPath);
  4340. DestroyDynamicArray(&arrResults);
  4341. SAFEFREE(szFinalStr);
  4342. SAFECLOSE(stream);
  4343. SafeCloseConnection(szServer,bConnFlag);
  4344. return (EXIT_FAILURE);
  4345. }
  4346. // Setting the buffer to 0, to avoid any junk value
  4347. memset(szFinalStr, 0, MAX_STRING_LENGTH1);
  4348. // Forming the final string from all the key-value pairs
  4349. if (stringFromDynamicArray1( arrResults,szFinalStr) == EXIT_FAILURE)
  4350. {
  4351. DestroyDynamicArray(&arrResults);
  4352. SAFEFREE(szFinalStr);
  4353. SAFECLOSE(stream);
  4354. resetFileAttrib(szPath);
  4355. SafeCloseConnection(szServer,bConnFlag);
  4356. return EXIT_FAILURE;
  4357. }
  4358. // Writing to the profile section with new key-value pair
  4359. // If the return value is non-zero, then there is an error.
  4360. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  4361. {
  4362. _stprintf(szBuffer,GetResString(IDS_SWITCH_CHANGE), dwId );
  4363. DISPLAY_MESSAGE(stdout,szBuffer);
  4364. }
  4365. else
  4366. {
  4367. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  4368. DestroyDynamicArray(&arrResults);
  4369. SAFEFREE(szFinalStr);
  4370. resetFileAttrib(szPath);
  4371. SAFECLOSE(stream);
  4372. SafeCloseConnection(szServer,bConnFlag);
  4373. return (EXIT_FAILURE);
  4374. }
  4375. }
  4376. SAFEFREE(szFinalStr);
  4377. SAFECLOSE(stream);
  4378. bRes = resetFileAttrib(szPath);
  4379. DestroyDynamicArray(&arrResults);
  4380. SafeCloseConnection(szServer,bConnFlag);
  4381. return (bRes) ;
  4382. }
  4383. // ***************************************************************************
  4384. // Routine Description : Display the help for the Ems entry option (X86).
  4385. //
  4386. // Parameters : none
  4387. //
  4388. // Return Type : VOID
  4389. //
  4390. // ***************************************************************************
  4391. VOID displayEmsUsage_X86()
  4392. {
  4393. DWORD dwIndex = IDS_EMS_BEGIN_X86 ;
  4394. for(;dwIndex <=IDS_EMS_END_X86;dwIndex++)
  4395. {
  4396. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  4397. }
  4398. }
  4399. // ***************************************************************************
  4400. // Routine Description : Display the help for the Debug entry option (X86).
  4401. //
  4402. // Parameters : none
  4403. //
  4404. // Return Type : VOID
  4405. // ***************************************************************************
  4406. VOID displayDebugUsage_X86()
  4407. {
  4408. DWORD dwIndex = IDS_DEBUG_BEGIN_X86 ;
  4409. for(;dwIndex <=IDS_DEBUG_END_X86;dwIndex++)
  4410. {
  4411. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  4412. }
  4413. }
  4414. // ***************************************************************************
  4415. // Routine Description : Display the help for the Ems entry option (IA64).
  4416. //
  4417. // Parameters : none
  4418. //
  4419. // Return Type : VOID
  4420. //
  4421. // ***************************************************************************
  4422. VOID displayEmsUsage_IA64()
  4423. {
  4424. DWORD dwIndex = IDS_EMS_BEGIN_IA64 ;
  4425. for(;dwIndex <=IDS_EMS_END_IA64;dwIndex++)
  4426. {
  4427. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  4428. }
  4429. }
  4430. // ***************************************************************************
  4431. // Routine Description : Display the help for the Debug entry option (IA64).
  4432. //
  4433. // Parameters : none
  4434. //
  4435. // Return Type : VOID
  4436. // ***************************************************************************
  4437. VOID displayDebugUsage_IA64()
  4438. {
  4439. DWORD dwIndex = IDS_DEBUG_BEGIN_IA64 ;
  4440. for(;dwIndex <= IDS_DEBUG_END_IA64 ;dwIndex++)
  4441. {
  4442. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  4443. }
  4444. }
  4445. // ***************************************************************************
  4446. // Routine Description : This function gets all the keys present in the specified section of
  4447. // an .ini file and then returns the dynamic array containing all the
  4448. // keys
  4449. //
  4450. // Parameters : LPTSTR sziniFile (in) - Name of the ini file.
  4451. // LPTSTR szinisection (in) - Name of the section in the boot.ini.
  4452. //
  4453. // Return Type : TARRAY ( pointer to the dynamic array )
  4454. //
  4455. // ***************************************************************************
  4456. DWORD getKeysOfSpecifiedINISection( LPTSTR sziniFile, LPTSTR sziniSection,LPCWSTR szKeyName ,LPTSTR szValue)
  4457. {
  4458. // Number of characters returned by the GetPrivateProfileString function
  4459. DWORD len = 0;
  4460. DWORD dwLength = MAX_STRING_LENGTH1 ;
  4461. // Buffer which will be populated by the GetPrivateProfileString function
  4462. LPTSTR inBuf = NULL ;
  4463. inBuf = (LPTSTR)malloc(dwLength*sizeof(TCHAR));
  4464. if(inBuf == NULL)
  4465. {
  4466. return MALLOC_FAILURE ;
  4467. }
  4468. while(1)
  4469. {
  4470. // Getting all the keys from the boot.ini file
  4471. len = GetPrivateProfileString
  4472. (sziniSection,
  4473. szKeyName,
  4474. ERROR_PROFILE_STRING1,
  4475. inBuf,
  4476. dwLength,
  4477. sziniFile);
  4478. //if the size of the string is not sufficient then increment the size.
  4479. if(len == dwLength-2)
  4480. {
  4481. dwLength +=100 ;
  4482. inBuf = (LPTSTR)realloc(inBuf,dwLength*sizeof(TCHAR));
  4483. if(inBuf == NULL)
  4484. {
  4485. SAFEFREE(inBuf);
  4486. return MALLOC_FAILURE;
  4487. }
  4488. }
  4489. else
  4490. break ;
  4491. }
  4492. //copy the value into the destination buffer only if
  4493. // the size is less than 255 else return FAILURE.
  4494. //
  4495. if(lstrlen(inBuf) <= MAX_RES_STRING)
  4496. {
  4497. lstrcpy(szValue,inBuf);
  4498. }
  4499. else
  4500. {
  4501. SAFEFREE(inBuf);
  4502. return MALLOC_FAILURE;
  4503. }
  4504. SAFEFREE(inBuf);
  4505. return EXIT_SUCCESS ;
  4506. }
  4507. // ***************************************************************************
  4508. // Routine Description:
  4509. // Implement the Add Switch switch.
  4510. // Arguments:
  4511. // [IN] argc Number of command line arguments
  4512. // [IN] argv Array containing command line arguments
  4513. //
  4514. // Return Value:
  4515. // DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  4516. //
  4517. // ***************************************************************************
  4518. DWORD ProcessAddSwSwitch( DWORD argc, LPCTSTR argv[] )
  4519. {
  4520. BOOL bUsage = FALSE ;
  4521. BOOL bNeedPwd = FALSE ;
  4522. BOOL bAddSw = FALSE ;
  4523. DWORD dwDefault = 0;
  4524. TARRAY arr ;
  4525. TCHAR szkey[MAX_STRING_LENGTH1] = NULL_STRING;
  4526. FILE *stream = NULL;
  4527. // Initialising the variables that are passed to TCMDPARSER structure
  4528. STRING256 szServer = NULL_STRING;
  4529. STRING256 szUser = NULL_STRING;
  4530. STRING256 szPassword = NULL_STRING;
  4531. STRING100 szPath = NULL_STRING;
  4532. DWORD dwNumKeys = 0;
  4533. BOOL bRes = FALSE ;
  4534. LPTSTR szFinalStr = NULL ;
  4535. BOOL bFlag = FALSE ;
  4536. TCHAR szMaxmem[10] = NULL_STRING ;
  4537. TCHAR szBuffer[MAX_RES_STRING] = NULL_STRING ;
  4538. TCHAR szErrorMsg[MAX_RES_STRING] = NULL_STRING ;
  4539. BOOL bBaseVideo = FALSE ;
  4540. BOOL bSos = FALSE ;
  4541. BOOL bNoGui = FALSE ;
  4542. DWORD dwMaxmem = 0 ;
  4543. BOOL bErrorFlag = FALSE ;
  4544. LPCTSTR szToken = NULL ;
  4545. DWORD dwRetVal = 0 ;
  4546. BOOL bConnFlag = FALSE ;
  4547. TCMDPARSER cmdOptions[] =
  4548. {
  4549. { CMDOPTION_ADDSW, CP_MAIN_OPTION, 1, 0,&bAddSw, NULL_STRING, NULL, NULL },
  4550. { SWITCH_SERVER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szServer, NULL_STRING, NULL, NULL },
  4551. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  4552. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  4553. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  4554. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY|CP_MANDATORY , 1, 0, &dwDefault, NULL_STRING, NULL, NULL },
  4555. { SWITCH_MAXMEM, CP_TYPE_UNUMERIC | CP_VALUE_MANDATORY,1,0,&dwMaxmem,NULL_STRING,NULL,NULL},
  4556. { SWITCH_BASEVIDEO, 0,1,0,&bBaseVideo,NULL_STRING,NULL,NULL},
  4557. { SWITCH_NOGUIBOOT, 0,1,0,&bNoGui,NULL_STRING,NULL,NULL},
  4558. { SWITCH_SOS, 0,1,0,&bSos,NULL_STRING,NULL,NULL},
  4559. };
  4560. //
  4561. //check if the remote system is 64 bit and if so
  4562. // display an error.
  4563. //
  4564. dwRetVal = CheckSystemType( szServer);
  4565. if(dwRetVal==EXIT_FAILURE )
  4566. {
  4567. return EXIT_FAILURE ;
  4568. }
  4569. //copy the Asterix token which is required for password prompting.
  4570. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  4571. _tcscpy(szPassword,TOKEN_ASTERIX);
  4572. // Parsing the copy option switches
  4573. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  4574. {
  4575. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  4576. ShowMessage(stderr,GetReason());
  4577. return (EXIT_FAILURE);
  4578. }
  4579. // Displaying query usage if user specified -? with -query option
  4580. if( bUsage )
  4581. {
  4582. dwRetVal = CheckSystemType( szServer);
  4583. if(dwRetVal==EXIT_SUCCESS )
  4584. {
  4585. displayAddSwUsage_X86();
  4586. return (EXIT_SUCCESS);
  4587. }else
  4588. {
  4589. return (EXIT_FAILURE);
  4590. }
  4591. }
  4592. if( (cmdOptions[6].dwActuals!=0) && (dwMaxmem < 32 ) )
  4593. {
  4594. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_MAXMEM_VALUES));
  4595. return EXIT_FAILURE ;
  4596. }
  4597. //display an error message if the user does not enter even one of
  4598. if((dwMaxmem==0)&& (!bBaseVideo)&& (!bNoGui)&&(!bSos) )
  4599. {
  4600. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_ADDSW));
  4601. return EXIT_FAILURE ;
  4602. }
  4603. //display error message if the username is entered with out a machine name
  4604. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  4605. {
  4606. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  4607. ShowMessage(stderr,GetReason());
  4608. return EXIT_FAILURE ;
  4609. }
  4610. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  4611. {
  4612. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  4613. ShowMessage(stderr,GetReason());
  4614. return EXIT_FAILURE ;
  4615. }
  4616. //for setting the bNeedPwd
  4617. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  4618. {
  4619. bNeedPwd = TRUE ;
  4620. }
  4621. //set the bneedpassword to true if the server name is specified and password is not specified.
  4622. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  4623. {
  4624. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  4625. {
  4626. bNeedPwd = TRUE ;
  4627. }
  4628. else
  4629. {
  4630. bNeedPwd = FALSE ;
  4631. }
  4632. if(_tcslen(szPassword)!= 0 )
  4633. {
  4634. _tcscpy(szPassword,NULL_STRING);
  4635. }
  4636. }
  4637. //display an error message if the server is empty.
  4638. if((cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0))
  4639. {
  4640. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  4641. return EXIT_FAILURE ;
  4642. }
  4643. //display an error message if the user is empty.
  4644. if((cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  4645. {
  4646. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  4647. return EXIT_FAILURE ;
  4648. }
  4649. szFinalStr = (TCHAR*) malloc(MAX_STRING_LENGTH1* sizeof(TCHAR) );
  4650. if (szFinalStr== NULL)
  4651. {
  4652. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4653. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_TAG));
  4654. ShowLastError(stderr);
  4655. return (EXIT_FAILURE);
  4656. }
  4657. // Establishing connection to the specified machine and getting the file pointer
  4658. // of the boot.ini file if there is no error while establishing connection
  4659. lstrcpy(szPath, PATH_BOOTINI );
  4660. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  4661. {
  4662. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  4663. {
  4664. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  4665. if(szToken == NULL)
  4666. {
  4667. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  4668. SAFEFREE(szFinalStr);
  4669. return (EXIT_FAILURE);
  4670. }
  4671. lstrcpy(szServer,szToken);
  4672. }
  4673. }
  4674. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  4675. {
  4676. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  4677. _tcscpy(szServer,_T(""));
  4678. }
  4679. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  4680. if(bFlag == EXIT_FAILURE)
  4681. {
  4682. SAFEFREE(szFinalStr);
  4683. SAFECLOSE(stream);
  4684. SafeCloseConnection(szServer,bConnFlag);
  4685. return (EXIT_FAILURE);
  4686. }
  4687. // Getting the keys of the Operating system section in the boot.ini file
  4688. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  4689. if(arr == NULL)
  4690. {
  4691. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4692. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  4693. ShowLastError(stderr);
  4694. resetFileAttrib(szPath);
  4695. SAFEFREE(szFinalStr);
  4696. SAFECLOSE(stream);
  4697. SafeCloseConnection(szServer,bConnFlag);
  4698. return EXIT_FAILURE ;
  4699. }
  4700. // Getting the total number of keys in the operating systems section
  4701. dwNumKeys = DynArrayGetCount(arr);
  4702. if((dwNumKeys >= MAX_BOOTID_VAL)&& (dwDefault >= MAX_BOOTID_VAL ) )
  4703. {
  4704. DISPLAY_MESSAGE(stderr,GetResString(IDS_MAX_BOOTID));
  4705. resetFileAttrib(szPath);
  4706. SAFEFREE(szFinalStr);
  4707. DestroyDynamicArray(&arr);
  4708. SAFECLOSE(stream);
  4709. SafeCloseConnection(szServer,bConnFlag);
  4710. return (EXIT_FAILURE);
  4711. }
  4712. // Displaying error message if the number of keys is less than the OS entry
  4713. // line number specified by the user
  4714. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  4715. {
  4716. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  4717. resetFileAttrib(szPath);
  4718. DestroyDynamicArray(&arr);
  4719. SAFEFREE(szFinalStr);
  4720. SAFECLOSE(stream);
  4721. SafeCloseConnection(szServer,bConnFlag);
  4722. return (EXIT_FAILURE);
  4723. }
  4724. // Getting the key of the OS entry specified by the user
  4725. if (arr != NULL)
  4726. {
  4727. LPCWSTR pwsz = NULL;
  4728. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  4729. if(pwsz != NULL)
  4730. {
  4731. _tcscpy( szkey,pwsz);
  4732. }
  4733. else
  4734. {
  4735. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4736. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  4737. ShowLastError(stderr);
  4738. resetFileAttrib(szPath);
  4739. DestroyDynamicArray(&arr);
  4740. SAFEFREE(szFinalStr);
  4741. SAFECLOSE(stream);
  4742. SafeCloseConnection(szServer,bConnFlag);
  4743. return EXIT_FAILURE ;
  4744. }
  4745. }
  4746. else
  4747. {
  4748. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4749. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  4750. ShowLastError(stderr);
  4751. resetFileAttrib(szPath);
  4752. DestroyDynamicArray(&arr);
  4753. SAFEFREE(szFinalStr);
  4754. SAFECLOSE(stream);
  4755. SafeCloseConnection(szServer,bConnFlag);
  4756. return EXIT_FAILURE ;
  4757. }
  4758. //if the max mem switch is specified by the user.
  4759. if(dwMaxmem != 0)
  4760. {
  4761. if(_tcsstr(szkey,MAXMEM_VALUE1) != 0)
  4762. {
  4763. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_MAXMEM_SWITCH));
  4764. resetFileAttrib(szPath);
  4765. DestroyDynamicArray(&arr);
  4766. SAFEFREE(szFinalStr);
  4767. SAFECLOSE(stream);
  4768. SafeCloseConnection(szServer,bConnFlag);
  4769. return EXIT_FAILURE ;
  4770. }
  4771. else
  4772. {
  4773. lstrcat(szkey , TOKEN_EMPTYSPACE);
  4774. lstrcat(szkey ,MAXMEM_VALUE1);
  4775. lstrcat(szkey,TOKEN_EQUAL);
  4776. _ltow(dwMaxmem,szMaxmem,10);
  4777. lstrcat(szkey,szMaxmem);
  4778. }
  4779. }
  4780. // if the base video is specified by the user.
  4781. if (bBaseVideo)
  4782. {
  4783. if(_tcsstr(szkey,BASEVIDEO_VALUE) != 0)
  4784. {
  4785. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_BASEVIDEO_SWITCH));
  4786. resetFileAttrib(szPath);
  4787. DestroyDynamicArray(&arr);
  4788. SAFEFREE(szFinalStr);
  4789. SAFECLOSE(stream);
  4790. SafeCloseConnection(szServer,bConnFlag);
  4791. return EXIT_FAILURE ;
  4792. }
  4793. else
  4794. {
  4795. lstrcat(szkey , TOKEN_EMPTYSPACE);
  4796. lstrcat(szkey ,BASEVIDEO_SWITCH);
  4797. }
  4798. }
  4799. // if the SOS is specified by the user.
  4800. if(bSos)
  4801. {
  4802. if(_tcsstr(szkey,SOS_VALUE) != 0)
  4803. {
  4804. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_SOS_SWITCH ) );
  4805. resetFileAttrib(szPath);
  4806. DestroyDynamicArray(&arr);
  4807. SAFEFREE(szFinalStr);
  4808. SAFECLOSE(stream);
  4809. SafeCloseConnection(szServer,bConnFlag);
  4810. return EXIT_FAILURE ;
  4811. }
  4812. else
  4813. {
  4814. lstrcat(szkey , TOKEN_EMPTYSPACE);
  4815. lstrcat(szkey ,SOS_SWITCH);
  4816. }
  4817. }
  4818. // if the noguiboot is specified by the user.
  4819. if(bNoGui)
  4820. {
  4821. if(_tcsstr(szkey,NOGUI_VALUE) != 0)
  4822. {
  4823. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPL_NOGUI_SWITCH));
  4824. resetFileAttrib(szPath);
  4825. DestroyDynamicArray(&arr);
  4826. SAFEFREE(szFinalStr);
  4827. SAFECLOSE(stream);
  4828. SafeCloseConnection(szServer,bConnFlag);
  4829. return EXIT_FAILURE ;
  4830. }
  4831. else
  4832. {
  4833. lstrcat(szkey , TOKEN_EMPTYSPACE);
  4834. lstrcat(szkey ,NOGUI_VALUE );
  4835. }
  4836. }
  4837. if( _tcslen(szkey) >= MAX_RES_STRING)
  4838. {
  4839. _stprintf(szErrorMsg,GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  4840. DISPLAY_MESSAGE( stderr,szErrorMsg);
  4841. SAFEFREE(szFinalStr);
  4842. SAFECLOSE(stream);
  4843. resetFileAttrib(szPath);
  4844. SafeCloseConnection(szServer,bConnFlag);
  4845. return EXIT_FAILURE;
  4846. }
  4847. DynArrayRemove(arr, dwDefault - 1 );
  4848. DynArrayInsertString(arr, dwDefault - 1, szkey, MAX_STRING_LENGTH1);
  4849. // Setting the buffer to 0, to avoid any junk value
  4850. memset(szFinalStr, 0, MAX_STRING_LENGTH1);
  4851. // Forming the final string from all the key-value pairs
  4852. if (stringFromDynamicArray1( arr,szFinalStr) == EXIT_FAILURE)
  4853. {
  4854. DestroyDynamicArray(&arr);
  4855. SAFEFREE(szFinalStr);
  4856. SAFECLOSE(stream);
  4857. resetFileAttrib(szPath);
  4858. SafeCloseConnection(szServer,bConnFlag);
  4859. return EXIT_FAILURE;
  4860. }
  4861. // Writing to the profile section with new key-value pair
  4862. // If the return value is non-zero, then there is an error.
  4863. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  4864. {
  4865. _stprintf(szBuffer,GetResString(IDS_SWITCH_ADD), dwDefault );
  4866. DISPLAY_MESSAGE(stdout,szBuffer);
  4867. }
  4868. else
  4869. {
  4870. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_ADD_SWITCHES));
  4871. DestroyDynamicArray(&arr);
  4872. resetFileAttrib(szPath);
  4873. SAFEFREE(szFinalStr);
  4874. SAFECLOSE(stream);
  4875. SafeCloseConnection(szServer,bConnFlag);
  4876. return (EXIT_FAILURE);
  4877. }
  4878. //reset the file attributes and free the memory and close the connection to the server.
  4879. bRes = resetFileAttrib(szPath);
  4880. DestroyDynamicArray(&arr);
  4881. SAFEFREE(szFinalStr);
  4882. SAFECLOSE(stream);
  4883. SafeCloseConnection(szServer,bConnFlag);
  4884. return (bRes);
  4885. }
  4886. // ***************************************************************************
  4887. // Routine Description:
  4888. // This routine is to remove the switches to the boot.ini file settings for
  4889. // the specified system.
  4890. // Arguments:
  4891. // [IN] argc Number of command line arguments
  4892. // [IN] argv Array containing command line arguments
  4893. //
  4894. // Return Value:
  4895. // DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  4896. //
  4897. // ***************************************************************************
  4898. DWORD ProcessRmSwSwitch( DWORD argc, LPCTSTR argv[] )
  4899. {
  4900. BOOL bUsage = FALSE ;
  4901. BOOL bNeedPwd = FALSE ;
  4902. BOOL bRmSw = FALSE ;
  4903. DWORD dwDefault = 0;
  4904. TARRAY arr = NULL ;
  4905. TCHAR szkey[MAX_STRING_LENGTH1] = NULL_STRING;
  4906. FILE *stream = NULL;
  4907. // Initialising the variables that are passed to TCMDPARSER structure
  4908. STRING256 szServer = NULL_STRING;
  4909. STRING256 szUser = NULL_STRING;
  4910. STRING256 szPassword = NULL_STRING;
  4911. STRING100 szPath = NULL_STRING;
  4912. TCHAR szTmp[MAX_RES_STRING] = NULL_STRING ;
  4913. TCHAR szChangeKeyValue[MAX_RES_STRING] = NULL_STRING ;
  4914. DWORD dwNumKeys = 0;
  4915. BOOL bRes = FALSE ;
  4916. PTCHAR pToken = NULL ;
  4917. LPTSTR szFinalStr = NULL ;
  4918. BOOL bFlag = FALSE ;
  4919. TCHAR szMaxmem[STRING10] = NULL_STRING ;
  4920. TCHAR szBuffer[MAX_RES_STRING] = NULL_STRING ;
  4921. TCHAR szDefault[MAX_RES_STRING] = NULL_STRING ;
  4922. BOOL bBaseVideo = FALSE ;
  4923. BOOL bSos = FALSE ;
  4924. BOOL bNoGui = FALSE ;
  4925. DWORD bMaxmem = FALSE ;
  4926. BOOL bErrorFlag = FALSE ;
  4927. TCHAR szTemp[MAX_RES_STRING] = NULL_STRING ;
  4928. TCHAR szString[MAX_RES_STRING] = NULL_STRING ;
  4929. LPTSTR szSubString = NULL ;
  4930. DWORD dwCode = 0;
  4931. LPCTSTR szToken = NULL ;
  4932. DWORD dwRetVal = 0;
  4933. BOOL bConnFlag = FALSE ;
  4934. TCMDPARSER cmdOptions[] =
  4935. {
  4936. { CMDOPTION_RMSW, CP_MAIN_OPTION, 1, 0,&bRmSw, NULL_STRING, NULL, NULL },
  4937. { SWITCH_SERVER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szServer, NULL_STRING, NULL, NULL },
  4938. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  4939. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  4940. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  4941. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY|CP_MANDATORY , 1, 0, &dwDefault, NULL_STRING, NULL, NULL },
  4942. { SWITCH_MAXMEM, 0,1,0,&bMaxmem,NULL_STRING,NULL,NULL},
  4943. { SWITCH_BASEVIDEO, 0,1,0,&bBaseVideo,NULL_STRING,NULL,NULL},
  4944. { SWITCH_NOGUIBOOT, 0,1,0,&bNoGui,NULL_STRING,NULL,NULL},
  4945. { SWITCH_SOS, 0,1,0,&bSos,NULL_STRING,NULL,NULL},
  4946. };
  4947. //
  4948. //check if the remote system is 64 bit and if so
  4949. // display an error.
  4950. //
  4951. dwRetVal = CheckSystemType( szServer);
  4952. if(dwRetVal==EXIT_FAILURE )
  4953. {
  4954. return EXIT_FAILURE ;
  4955. }
  4956. //copy the Asterix token which is required for password prompting.
  4957. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  4958. _tcscpy(szPassword,TOKEN_ASTERIX);
  4959. // Parsing the copy option switches
  4960. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  4961. {
  4962. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  4963. ShowMessage(stderr,GetReason());
  4964. return (EXIT_FAILURE);
  4965. }
  4966. // Displaying query usage if user specified -? with -query option
  4967. if( bUsage )
  4968. {
  4969. dwRetVal = CheckSystemType( szServer);
  4970. if(dwRetVal==EXIT_SUCCESS )
  4971. {
  4972. displayRmSwUsage_X86();
  4973. return (EXIT_SUCCESS);
  4974. }else
  4975. {
  4976. return (EXIT_FAILURE);
  4977. }
  4978. }
  4979. //display error message if the username is entered with out a machine name
  4980. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  4981. {
  4982. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  4983. ShowMessage(stderr,GetReason());
  4984. return EXIT_FAILURE ;
  4985. }
  4986. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  4987. {
  4988. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  4989. ShowMessage(stderr,GetReason());
  4990. return EXIT_FAILURE ;
  4991. }
  4992. //for setting the bNeedPwd
  4993. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  4994. {
  4995. bNeedPwd = TRUE ;
  4996. }
  4997. //set the bneedpassword to true if the server name is specified and password is not specified.
  4998. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  4999. {
  5000. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  5001. {
  5002. bNeedPwd = TRUE ;
  5003. }
  5004. else
  5005. {
  5006. bNeedPwd = FALSE ;
  5007. }
  5008. if(_tcslen(szPassword)!= 0 )
  5009. {
  5010. _tcscpy(szPassword,NULL_STRING);
  5011. }
  5012. }
  5013. //display an error message if the server is empty.
  5014. if((cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0))
  5015. {
  5016. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  5017. return EXIT_FAILURE ;
  5018. }
  5019. //display an error message if the user is empty.
  5020. if((cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  5021. {
  5022. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  5023. return EXIT_FAILURE ;
  5024. }
  5025. //display an error mesage if none of the options are specified.
  5026. if((!bSos)&&(!bBaseVideo)&&(!bNoGui)&&(!bMaxmem))
  5027. {
  5028. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_RMSW));
  5029. return EXIT_FAILURE ;
  5030. }
  5031. //display a warning message if the user specifies local system name
  5032. // with -s.
  5033. szFinalStr = (TCHAR*) malloc(MAX_STRING_LENGTH1* sizeof(TCHAR) );
  5034. if (szFinalStr== NULL)
  5035. {
  5036. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  5037. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_TAG));
  5038. ShowLastError(stderr);
  5039. return (EXIT_FAILURE);
  5040. }
  5041. // Establishing connection to the specified machine and getting the file pointer
  5042. // of the boot.ini file if there is no error while establishing connection
  5043. lstrcpy(szPath, PATH_BOOTINI );
  5044. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  5045. {
  5046. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  5047. {
  5048. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  5049. if(szToken == NULL)
  5050. {
  5051. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  5052. SAFEFREE(szFinalStr);
  5053. return (EXIT_FAILURE);
  5054. }
  5055. lstrcpy(szServer,szToken);
  5056. }
  5057. }
  5058. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  5059. {
  5060. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  5061. _tcscpy(szServer,_T(""));
  5062. }
  5063. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  5064. if(bFlag == EXIT_FAILURE)
  5065. {
  5066. SAFEFREE(szFinalStr);
  5067. SAFECLOSE(stream);
  5068. SafeCloseConnection(szServer,bConnFlag);
  5069. return (EXIT_FAILURE);
  5070. }
  5071. // Getting the keys of the Operating system section in the boot.ini file
  5072. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  5073. if(arr == NULL)
  5074. {
  5075. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  5076. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  5077. ShowLastError(stderr);
  5078. resetFileAttrib(szPath);
  5079. SAFEFREE(szFinalStr);
  5080. SAFECLOSE(stream);
  5081. SafeCloseConnection(szServer,bConnFlag);
  5082. return EXIT_FAILURE ;
  5083. }
  5084. // Getting the total number of keys in the operating systems section
  5085. dwNumKeys = DynArrayGetCount(arr);
  5086. if( (dwNumKeys >= MAX_BOOTID_VAL)&&(dwDefault >= MAX_BOOTID_VAL ) )
  5087. {
  5088. DISPLAY_MESSAGE(stderr,GetResString(IDS_MAX_BOOTID));
  5089. resetFileAttrib(szPath);
  5090. SAFEFREE(szFinalStr);
  5091. DestroyDynamicArray(&arr);
  5092. SAFECLOSE(stream);
  5093. SafeCloseConnection(szServer,bConnFlag);
  5094. return (EXIT_FAILURE);
  5095. }
  5096. // Displaying error message if the number of keys is less than the OS entry
  5097. // line number specified by the user
  5098. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  5099. {
  5100. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  5101. resetFileAttrib(szPath);
  5102. DestroyDynamicArray(&arr);
  5103. SAFEFREE(szFinalStr);
  5104. SAFECLOSE(stream);
  5105. SafeCloseConnection(szServer,bConnFlag);
  5106. return (EXIT_FAILURE);
  5107. }
  5108. // Getting the key of the OS entry specified by the user
  5109. if (arr != NULL)
  5110. {
  5111. LPCWSTR pwsz = NULL;
  5112. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  5113. if(pwsz != NULL)
  5114. {
  5115. _tcscpy( szkey,pwsz);
  5116. }
  5117. else
  5118. {
  5119. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  5120. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  5121. ShowLastError(stderr);
  5122. bRes = resetFileAttrib(szPath);
  5123. DestroyDynamicArray(&arr);
  5124. SAFEFREE(szFinalStr);
  5125. SAFECLOSE(stream);
  5126. SafeCloseConnection(szServer,bConnFlag);
  5127. return EXIT_FAILURE ;
  5128. }
  5129. }
  5130. else
  5131. {
  5132. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  5133. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  5134. ShowLastError(stderr);
  5135. bRes = resetFileAttrib(szPath);
  5136. DestroyDynamicArray(&arr);
  5137. SAFEFREE(szFinalStr);
  5138. SAFECLOSE(stream);
  5139. SafeCloseConnection(szServer,bConnFlag);
  5140. return EXIT_FAILURE ;
  5141. }
  5142. //if the max mem switch is specified by the user.
  5143. if(bMaxmem==TRUE)
  5144. {
  5145. if(_tcsstr(szkey,MAXMEM_VALUE1) == 0)
  5146. {
  5147. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_MAXMEM_SWITCH));
  5148. bRes = resetFileAttrib(szPath);
  5149. DestroyDynamicArray(&arr);
  5150. SAFEFREE(szFinalStr);
  5151. SAFECLOSE(stream);
  5152. SafeCloseConnection(szServer,bConnFlag);
  5153. return EXIT_FAILURE ;
  5154. }
  5155. else
  5156. {
  5157. szSubString = ( LPTSTR ) malloc( MAX_RES_STRING*sizeof( TCHAR ) );
  5158. if(szSubString == NULL)
  5159. {
  5160. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  5161. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_TAG));
  5162. ShowLastError(stderr);
  5163. bRes = resetFileAttrib(szPath);
  5164. DestroyDynamicArray(&arr);
  5165. SAFEFREE(szFinalStr);
  5166. SAFECLOSE(stream);
  5167. SafeCloseConnection(szServer,bConnFlag);
  5168. return EXIT_FAILURE;
  5169. }
  5170. lstrcpy(szTemp,NULL_STRING);
  5171. dwCode = GetSubString(szkey,MAXMEM_VALUE1,szSubString);
  5172. //remove the substring specified.
  5173. if(dwCode == EXIT_SUCCESS)
  5174. {
  5175. removeSubString(szkey,szSubString);
  5176. }
  5177. }
  5178. }
  5179. // if the base video is specified by the user.
  5180. if (bBaseVideo==TRUE)
  5181. {
  5182. if(_tcsstr(szkey,BASEVIDEO_VALUE) == 0)
  5183. {
  5184. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_BV_SWITCH));
  5185. bRes = resetFileAttrib(szPath);
  5186. DestroyDynamicArray(&arr);
  5187. SAFEFREE(szFinalStr);
  5188. SAFECLOSE(stream);
  5189. SafeCloseConnection(szServer,bConnFlag);
  5190. return EXIT_FAILURE ;
  5191. }
  5192. else
  5193. {
  5194. removeSubString(szkey,BASEVIDEO_VALUE);
  5195. }
  5196. }
  5197. // if the SOS is specified by the user.
  5198. if(bSos==TRUE)
  5199. {
  5200. if(_tcsstr(szkey,SOS_VALUE) == 0)
  5201. {
  5202. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_SOS_SWITCH ) );
  5203. resetFileAttrib(szPath);
  5204. DestroyDynamicArray(&arr);
  5205. SAFEFREE(szFinalStr);
  5206. SAFECLOSE(stream);
  5207. SafeCloseConnection(szServer,bConnFlag);
  5208. return EXIT_FAILURE ;
  5209. }
  5210. else
  5211. {
  5212. removeSubString(szkey,SOS_VALUE);
  5213. }
  5214. }
  5215. // if the noguiboot is specified by the user.
  5216. if(bNoGui==TRUE)
  5217. {
  5218. if(_tcsstr(szkey,NOGUI_VALUE) == 0)
  5219. {
  5220. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_NOGUI_SWITCH));
  5221. resetFileAttrib(szPath);
  5222. DestroyDynamicArray(&arr);
  5223. SAFEFREE(szFinalStr);
  5224. SAFECLOSE(stream);
  5225. SafeCloseConnection(szServer,bConnFlag);
  5226. return EXIT_FAILURE ;
  5227. }
  5228. else
  5229. {
  5230. removeSubString(szkey,NOGUI_VALUE);
  5231. }
  5232. }
  5233. DynArrayRemove(arr, dwDefault - 1 );
  5234. DynArrayInsertString(arr, dwDefault - 1, szkey, MAX_STRING_LENGTH1);
  5235. // Setting the buffer to 0, to avoid any junk value
  5236. memset(szFinalStr, 0, MAX_STRING_LENGTH1);
  5237. // Forming the final string from all the key-value pairs
  5238. if (stringFromDynamicArray1( arr,szFinalStr) == EXIT_FAILURE)
  5239. {
  5240. DestroyDynamicArray(&arr);
  5241. SAFEFREE(szFinalStr);
  5242. SAFECLOSE(stream);
  5243. resetFileAttrib(szPath);
  5244. SafeCloseConnection(szServer,bConnFlag);
  5245. return EXIT_FAILURE;
  5246. }
  5247. // Writing to the profile section with new key-value pair
  5248. // If the return value is non-zero, then there is an error.
  5249. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  5250. {
  5251. _stprintf(szBuffer,GetResString(IDS_SWITCH_DELETE), dwDefault );
  5252. DISPLAY_MESSAGE(stdout,szBuffer);
  5253. }
  5254. else
  5255. {
  5256. _stprintf(szBuffer,GetResString(IDS_NO_SWITCH_DELETE), dwDefault );
  5257. DISPLAY_MESSAGE(stderr,szBuffer);
  5258. DestroyDynamicArray(&arr);
  5259. resetFileAttrib(szPath);
  5260. SAFEFREE(szFinalStr);
  5261. SAFECLOSE(stream);
  5262. SafeCloseConnection(szServer,bConnFlag);
  5263. return (EXIT_FAILURE);
  5264. }
  5265. //reset the file attributes and free the memory and close the connection to the server.
  5266. bRes = resetFileAttrib(szPath);
  5267. DestroyDynamicArray(&arr);
  5268. SAFEFREE(szFinalStr);
  5269. SAFECLOSE(stream);
  5270. SafeCloseConnection(szServer,bConnFlag);
  5271. return (EXIT_SUCCESS);
  5272. }
  5273. // ***************************************************************************
  5274. // Routine Description : Display the help for the AddSw entry option (X86).
  5275. //
  5276. // Parameters : none
  5277. //
  5278. // Return Type : VOID
  5279. //
  5280. // ***************************************************************************
  5281. VOID displayAddSwUsage_X86()
  5282. {
  5283. DWORD dwIndex = IDS_ADDSW_BEGIN_X86 ;
  5284. for(;dwIndex <=IDS_ADDSW_END_X86;dwIndex++)
  5285. {
  5286. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  5287. }
  5288. }
  5289. // ***************************************************************************
  5290. // Routine Description : Display the help for the AddSw entry option (IA64).
  5291. //
  5292. // Arguments : none
  5293. //
  5294. // Return Type : VOID
  5295. //
  5296. // ***************************************************************************
  5297. VOID displayAddSwUsage_IA64()
  5298. {
  5299. DWORD dwIndex = IDS_ADDSW_BEGIN_IA64 ;
  5300. for(;dwIndex <=IDS_ADDSW_END_IA64;dwIndex++)
  5301. {
  5302. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  5303. }
  5304. }
  5305. // ***************************************************************************
  5306. //
  5307. // Routine Description : Display the help for the RmSw entry option (IA64).
  5308. //
  5309. // Arguments : none
  5310. //
  5311. // Return Type : VOID
  5312. //
  5313. // ***************************************************************************
  5314. VOID displayRmSwUsage_IA64()
  5315. {
  5316. DWORD dwIndex = IDS_RMSW_BEGIN_IA64 ;
  5317. for(;dwIndex <=IDS_RMSW_END_IA64;dwIndex++)
  5318. {
  5319. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  5320. }
  5321. }
  5322. // ***************************************************************************
  5323. //
  5324. // Routine Description : Display the help for the RmSw entry option (X86).
  5325. //
  5326. // Arguments : none
  5327. //
  5328. // Return Type : VOID
  5329. //
  5330. // ***************************************************************************
  5331. VOID displayRmSwUsage_X86()
  5332. {
  5333. DWORD dwIndex = IDS_RMSW_BEGIN_X86 ;
  5334. for(;dwIndex <=IDS_RMSW_END_X86;dwIndex++)
  5335. {
  5336. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  5337. }
  5338. }
  5339. // ***************************************************************************
  5340. //
  5341. // Routine Description : This function retreives a part of the string.
  5342. //
  5343. // Parameters :
  5344. // LPTSTR szString (in) - String in which substring is to be found.
  5345. // LPTSTR szPartString (in) - Part String whose remaining substring is to be found.
  5346. // LPTSTR pszFullString (out) - String in which substring is to be found.
  5347. //
  5348. //
  5349. // Return Type : DWORD
  5350. //
  5351. //
  5352. // ***************************************************************************
  5353. DWORD GetSubString(LPTSTR szString,LPTSTR szPartString,LPTSTR pszFullString)
  5354. {
  5355. TCHAR szTemp[MAX_RES_STRING]= NULL_STRING ;
  5356. PTCHAR pszMemValue = NULL ;
  5357. PTCHAR pszdest = NULL ;
  5358. #ifndef _WIN64
  5359. DWORD dwPos = 0;
  5360. #else
  5361. INT64 dwPos = 0;
  5362. #endif
  5363. pszMemValue = _tcsstr(szString,szPartString);
  5364. if(pszMemValue == NULL)
  5365. {
  5366. return EXIT_FAILURE ;
  5367. }
  5368. //copy the remaining part of the string into a buffer
  5369. lstrcpy(szTemp,pszMemValue);
  5370. //search for the empty space.
  5371. pszdest = _tcschr(szTemp,_T(' '));
  5372. if (pszdest==NULL)
  5373. {
  5374. //the api returns NULL if it is not able to find the
  5375. // character . This means that the required switch is at the end
  5376. //of the string . so we are copying it fully
  5377. lstrcpy(pszFullString,szTemp);
  5378. return EXIT_SUCCESS ;
  5379. }
  5380. dwPos = pszdest - szTemp ;
  5381. szTemp[dwPos] = _T('\0');
  5382. lstrcpy(pszFullString,szTemp);
  5383. return EXIT_SUCCESS ;
  5384. }
  5385. // ***************************************************************************
  5386. // Routine Description:
  5387. // This routine is to add/remove the /debugport=1394
  5388. // switches to the boot.ini file settings for the specified system.
  5389. // Arguments:
  5390. // [IN] argc Number of command line arguments
  5391. // [IN] argv Array containing command line arguments
  5392. //
  5393. // Return Value:
  5394. // DWORD (EXIT_SUCCESS for success and EXIT_FAILURE for Failure.)
  5395. //
  5396. // ***************************************************************************
  5397. DWORD ProcessDbg1394Switch( DWORD argc, LPCTSTR argv[] )
  5398. {
  5399. BOOL bUsage = FALSE ;
  5400. BOOL bNeedPwd = FALSE ;
  5401. BOOL bDbg1394 = FALSE ;
  5402. DWORD dwDefault = 0;
  5403. TARRAY arr ;
  5404. TCHAR szkey[MAX_RES_STRING] = NULL_STRING;
  5405. FILE *stream = NULL;
  5406. // Initialising the variables that are passed to TCMDPARSER structure
  5407. STRING256 szServer = NULL_STRING;
  5408. STRING256 szUser = NULL_STRING;
  5409. STRING256 szPassword = NULL_STRING;
  5410. STRING100 szPath = NULL_STRING;
  5411. DWORD dwNumKeys = 0;
  5412. BOOL bRes = FALSE ;
  5413. LPTSTR szFinalStr = NULL ;
  5414. BOOL bFlag = FALSE ;
  5415. TCHAR szMaxmem[STRING10] = NULL_STRING ;
  5416. TCHAR szBuffer[MAX_RES_STRING] = NULL_STRING ;
  5417. TCHAR szDefault[MAX_RES_STRING] = NULL_STRING ;
  5418. TCHAR szTemp[MAX_RES_STRING] = NULL_STRING ;
  5419. TCHAR szErrorMsg[MAX_RES_STRING] = NULL_STRING ;
  5420. LPTSTR szSubString = NULL ;
  5421. DWORD dwCode = 0;
  5422. DWORD dwChannel = 0;
  5423. TCHAR szChannel[MAX_RES_STRING] = NULL_STRING ;
  5424. LPCTSTR szToken = NULL ;
  5425. DWORD dwRetVal = 0 ;
  5426. BOOL bConnFlag = FALSE ;
  5427. TCMDPARSER cmdOptions[] =
  5428. {
  5429. { CMDOPTION_DBG1394, CP_MAIN_OPTION, 1, 0,&bDbg1394,NULL_STRING , NULL, NULL },
  5430. { SWITCH_SERVER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szServer, NULL_STRING, NULL, NULL },
  5431. { SWITCH_USER, CP_TYPE_TEXT | CP_VALUE_MANDATORY, 1, 0, &szUser, NULL_STRING, NULL, NULL },
  5432. { SWITCH_PASSWORD, CP_TYPE_TEXT | CP_VALUE_OPTIONAL, 1, 0, &szPassword, NULL_STRING, NULL, NULL },
  5433. { CMDOPTION_USAGE, CP_USAGE, 1, 0, &bUsage, NULL_STRING, NULL, NULL },
  5434. { SWITCH_ID, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY| CP_MANDATORY , 1, 0, &dwDefault, NULL_STRING, NULL, NULL },
  5435. { CMDOPTION_CHANNEL, CP_TYPE_NUMERIC | CP_VALUE_MANDATORY,1,0,&dwChannel,NULL_STRING,NULL,NULL},
  5436. { CMDOPTION_DEFAULT, CP_DEFAULT|CP_TYPE_TEXT | CP_MANDATORY, 1, 0, &szDefault,NULL_STRING, NULL, NULL }
  5437. };
  5438. //
  5439. //check if the remote system is 64 bit and if so
  5440. // display an error.
  5441. //
  5442. dwRetVal = CheckSystemType( szServer);
  5443. if(dwRetVal==EXIT_FAILURE )
  5444. {
  5445. return EXIT_FAILURE ;
  5446. }
  5447. //copy the Asterix token which is required for password prompting.
  5448. _tcscpy(cmdOptions[3].szValues,TOKEN_ASTERIX) ;
  5449. _tcscpy(szPassword,TOKEN_ASTERIX);
  5450. // Parsing the copy option switches
  5451. if ( ! DoParseParam( argc, argv, SIZE_OF_ARRAY(cmdOptions ), cmdOptions ) )
  5452. {
  5453. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  5454. ShowMessage(stderr,GetReason());
  5455. return (EXIT_FAILURE);
  5456. }
  5457. // Displaying query usage if user specified -? with -query option
  5458. if( bUsage )
  5459. {
  5460. dwRetVal = CheckSystemType( szServer);
  5461. if(dwRetVal==EXIT_SUCCESS )
  5462. {
  5463. displayDbg1394Usage_X86();
  5464. return (EXIT_SUCCESS);
  5465. }else
  5466. {
  5467. return (EXIT_FAILURE);
  5468. }
  5469. }
  5470. //
  5471. //display error message if user enters a value
  5472. // other than on or off
  5473. //
  5474. if( ( lstrcmpi(szDefault,OFF_STRING)!=0 ) && (lstrcmpi(szDefault,ON_STRING)!=0 ) )
  5475. {
  5476. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_DEFAULT_MISSING));
  5477. DISPLAY_MESSAGE(stderr,GetResString(IDS_1394_HELP));
  5478. return (EXIT_FAILURE);
  5479. }
  5480. if((cmdOptions[5].dwActuals == 0) &&(dwDefault == 0 ))
  5481. {
  5482. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_ID_MISSING));
  5483. DISPLAY_MESSAGE(stderr,GetResString(IDS_1394_HELP));
  5484. return (EXIT_FAILURE);
  5485. }
  5486. if(( lstrcmpi(szDefault,OFF_STRING)==0 ) &&(dwChannel != 0) )
  5487. {
  5488. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_SYNTAX_DBG1394));
  5489. return (EXIT_FAILURE);
  5490. }
  5491. if( ( lstrcmpi(szDefault,ON_STRING)==0 ) && (cmdOptions[6].dwActuals != 0) && ( (dwChannel < 1) ||(dwChannel > 64 )) )
  5492. {
  5493. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_CH_RANGE));
  5494. return (EXIT_FAILURE);
  5495. }
  5496. //display error message if the username is entered with out a machine name
  5497. if( (cmdOptions[1].dwActuals == 0)&&(cmdOptions[2].dwActuals != 0))
  5498. {
  5499. SetReason(GetResString(IDS_USER_BUT_NOMACHINE));
  5500. ShowMessage(stderr,GetReason());
  5501. return EXIT_FAILURE ;
  5502. }
  5503. if( (cmdOptions[2].dwActuals == 0)&&(cmdOptions[3].dwActuals != 0))
  5504. {
  5505. SetReason(GetResString(IDS_PASSWD_BUT_NOUSER));
  5506. ShowMessage(stderr,GetReason());
  5507. return EXIT_FAILURE ;
  5508. }
  5509. //for setting the bNeedPwd
  5510. if( ( _tcscmp(szPassword,TOKEN_ASTERIX )==0 ) && (IsLocalSystem(szServer)==FALSE ))
  5511. {
  5512. bNeedPwd = TRUE ;
  5513. }
  5514. //set the bneedpassword to true if the server name is specified and password is not specified.
  5515. if((cmdOptions[1].dwActuals!=0)&&(cmdOptions[3].dwActuals==0))
  5516. {
  5517. if( (lstrlen( szServer ) != 0) && (IsLocalSystem(szServer)==FALSE) )
  5518. {
  5519. bNeedPwd = TRUE ;
  5520. }
  5521. else
  5522. {
  5523. bNeedPwd = FALSE ;
  5524. }
  5525. if(_tcslen(szPassword)!= 0 )
  5526. {
  5527. _tcscpy(szPassword,NULL_STRING);
  5528. }
  5529. }
  5530. //display an error message if the server is empty.
  5531. if((cmdOptions[1].dwActuals!=0)&&(lstrlen(szServer)==0))
  5532. {
  5533. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_SERVER));
  5534. return EXIT_FAILURE ;
  5535. }
  5536. //display an error message if the user is empty.
  5537. if((cmdOptions[2].dwActuals!=0)&&(lstrlen(szUser)==0 ))
  5538. {
  5539. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_NULL_USER));
  5540. return EXIT_FAILURE ;
  5541. }
  5542. if(StrCmpN(szServer,TOKEN_BACKSLASH4,2)==0)
  5543. {
  5544. if(!StrCmpN(szServer,TOKEN_BACKSLASH6,3)==0)
  5545. {
  5546. szToken = _tcstok(szServer,TOKEN_BACKSLASH4);
  5547. if(szToken == NULL)
  5548. {
  5549. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  5550. return (EXIT_FAILURE);
  5551. }
  5552. lstrcpy(szServer,szToken);
  5553. }
  5554. }
  5555. szFinalStr = (TCHAR*) malloc(MAX_STRING_LENGTH1* sizeof(TCHAR) );
  5556. if (szFinalStr== NULL)
  5557. {
  5558. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  5559. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_TAG));
  5560. ShowLastError(stderr);
  5561. return (EXIT_FAILURE);
  5562. }
  5563. // Establishing connection to the specified machine and getting the file pointer
  5564. // of the boot.ini file if there is no error while establishing connection
  5565. lstrcpy(szPath, PATH_BOOTINI );
  5566. //display a warning message if the user specifies local system name
  5567. // with -s.
  5568. if( (IsLocalSystem(szServer)==TRUE)&&(lstrlen(szUser)!=0))
  5569. {
  5570. DISPLAY_MESSAGE(stdout,GetResString(WARN_LOCALCREDENTIALS));
  5571. _tcscpy(szServer,_T(""));
  5572. }
  5573. bFlag = openConnection( szServer, szUser, szPassword, szPath,bNeedPwd,stream,&bConnFlag);
  5574. if(bFlag == EXIT_FAILURE)
  5575. {
  5576. SAFEFREE(szFinalStr);
  5577. SAFECLOSE(stream);
  5578. SafeCloseConnection(szServer,bConnFlag);
  5579. return (EXIT_FAILURE);
  5580. }
  5581. // Getting the keys of the Operating system section in the boot.ini file
  5582. arr = getKeyValueOfINISection( szPath, OS_FIELD );
  5583. if(arr == NULL)
  5584. {
  5585. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  5586. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  5587. ShowLastError(stderr);
  5588. resetFileAttrib(szPath);
  5589. SAFEFREE(szFinalStr);
  5590. SAFECLOSE(stream);
  5591. SafeCloseConnection(szServer,bConnFlag);
  5592. return EXIT_FAILURE ;
  5593. }
  5594. // Getting the total number of keys in the operating systems section
  5595. dwNumKeys = DynArrayGetCount(arr);
  5596. if( (dwNumKeys >= MAX_BOOTID_VAL) && (dwDefault >= MAX_BOOTID_VAL ) )
  5597. {
  5598. DISPLAY_MESSAGE(stderr,GetResString(IDS_MAX_BOOTID));
  5599. resetFileAttrib(szPath);
  5600. SAFEFREE(szFinalStr);
  5601. DestroyDynamicArray(&arr);
  5602. SAFECLOSE(stream);
  5603. SafeCloseConnection(szServer,bConnFlag);
  5604. return (EXIT_FAILURE);
  5605. }
  5606. // Displaying error message if the number of keys is less than the OS entry
  5607. // line number specified by the user
  5608. if( ( dwDefault <= 0 ) || ( dwDefault > dwNumKeys ) )
  5609. {
  5610. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_BOOTID));
  5611. resetFileAttrib(szPath);
  5612. DestroyDynamicArray(&arr);
  5613. SAFEFREE(szFinalStr);
  5614. SAFECLOSE(stream);
  5615. SafeCloseConnection(szServer,bConnFlag);
  5616. return (EXIT_FAILURE);
  5617. }
  5618. // Getting the key of the OS entry specified by the user
  5619. if (arr != NULL)
  5620. {
  5621. LPCWSTR pwsz = NULL;
  5622. pwsz = DynArrayItemAsString( arr, dwDefault - 1 ) ;
  5623. if(pwsz != NULL)
  5624. {
  5625. _tcscpy( szkey,pwsz);
  5626. }
  5627. else
  5628. {
  5629. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  5630. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  5631. ShowLastError(stderr);
  5632. resetFileAttrib(szPath);
  5633. DestroyDynamicArray(&arr);
  5634. SAFEFREE(szFinalStr);
  5635. SAFECLOSE(stream);
  5636. SafeCloseConnection(szServer,bConnFlag);
  5637. return EXIT_FAILURE ;
  5638. }
  5639. }
  5640. else
  5641. {
  5642. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  5643. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  5644. ShowLastError(stderr);
  5645. resetFileAttrib(szPath);
  5646. DestroyDynamicArray(&arr);
  5647. SAFEFREE(szFinalStr);
  5648. SAFECLOSE(stream);
  5649. SafeCloseConnection(szServer,bConnFlag);
  5650. return EXIT_FAILURE ;
  5651. }
  5652. if(lstrcmpi(szDefault,ON_STRING)==0 )
  5653. {
  5654. if(_tcsstr(szkey,DEBUGPORT) != 0)
  5655. {
  5656. DISPLAY_MESSAGE(stderr,GetResString(IDS_DUPLICATE_ENTRY));
  5657. resetFileAttrib(szPath);
  5658. DestroyDynamicArray(&arr);
  5659. SAFEFREE(szFinalStr);
  5660. SAFECLOSE(stream);
  5661. SafeCloseConnection(szServer,bConnFlag);
  5662. return EXIT_FAILURE ;
  5663. }
  5664. if((_tcsstr(szkey,DEBUG_SWITCH) == 0))
  5665. {
  5666. lstrcat(szkey,TOKEN_EMPTYSPACE);
  5667. lstrcat(szkey,DEBUG_SWITCH);
  5668. }
  5669. lstrcat(szkey,TOKEN_EMPTYSPACE);
  5670. lstrcat(szkey,DEBUGPORT_1394) ;
  5671. if(dwChannel!=0)
  5672. {
  5673. //frame the string and concatenate to the Os Load options.
  5674. lstrcat(szkey,TOKEN_EMPTYSPACE);
  5675. lstrcat(szkey,TOKEN_CHANNEL);
  5676. lstrcat(szkey,TOKEN_EQUAL);
  5677. _ltow(dwChannel,szChannel,10);
  5678. lstrcat(szkey,szChannel);
  5679. }
  5680. }
  5681. if(lstrcmpi(szDefault,OFF_STRING)==0 )
  5682. {
  5683. if(_tcsstr(szkey,DEBUGPORT_1394) == 0)
  5684. {
  5685. DISPLAY_MESSAGE(stderr,GetResString(IDS_NO_1394_SWITCH));
  5686. resetFileAttrib(szPath);
  5687. DestroyDynamicArray(&arr);
  5688. SAFEFREE(szFinalStr);
  5689. SAFECLOSE(stream);
  5690. SafeCloseConnection(szServer,bConnFlag);
  5691. return EXIT_FAILURE ;
  5692. }
  5693. removeSubString(szkey,DEBUGPORT_1394);
  5694. removeSubString(szkey,DEBUG_SWITCH);
  5695. if(_tcsstr(szkey,TOKEN_CHANNEL)!=0)
  5696. {
  5697. lstrcpy(szTemp,NULL_STRING);
  5698. dwCode = GetSubString(szkey,TOKEN_CHANNEL,szTemp);
  5699. if(dwCode == EXIT_FAILURE )
  5700. {
  5701. DISPLAY_MESSAGE( stderr,GetResString(IDS_NO_TOKENS));
  5702. resetFileAttrib(szPath);
  5703. DestroyDynamicArray(&arr);
  5704. SAFEFREE(szFinalStr);
  5705. SAFECLOSE(stream);
  5706. SafeCloseConnection(szServer,bConnFlag);
  5707. return EXIT_FAILURE ;
  5708. }
  5709. if(lstrlen(szTemp)!=0)
  5710. {
  5711. removeSubString(szkey,szTemp);
  5712. }
  5713. }
  5714. }
  5715. if( _tcslen(szkey) >= MAX_RES_STRING)
  5716. {
  5717. _stprintf(szErrorMsg,GetResString(IDS_ERROR_STRING_LENGTH),MAX_RES_STRING);
  5718. DISPLAY_MESSAGE( stderr,szErrorMsg);
  5719. resetFileAttrib(szPath);
  5720. DestroyDynamicArray(&arr);
  5721. SAFEFREE(szFinalStr);
  5722. SAFECLOSE(stream);
  5723. SafeCloseConnection(szServer,bConnFlag);
  5724. return EXIT_FAILURE ;
  5725. }
  5726. DynArrayRemove(arr, dwDefault - 1 );
  5727. DynArrayInsertString(arr, dwDefault - 1, szkey, MAX_RES_STRING);
  5728. // Setting the buffer to 0, to avoid any junk value
  5729. memset(szFinalStr, 0, MAX_STRING_LENGTH1);
  5730. // Forming the final string from all the key-value pairs
  5731. if (stringFromDynamicArray1( arr,szFinalStr) == EXIT_FAILURE)
  5732. {
  5733. DestroyDynamicArray(&arr);
  5734. SAFEFREE(szFinalStr);
  5735. SAFECLOSE(stream);
  5736. resetFileAttrib(szPath);
  5737. SafeCloseConnection(szServer,bConnFlag);
  5738. return EXIT_FAILURE;
  5739. }
  5740. // Writing to the profile section with new key-value pair
  5741. // If the return value is non-zero, then there is an error.
  5742. if( WritePrivateProfileSection(OS_FIELD, szFinalStr, szPath ) != 0 )
  5743. {
  5744. _stprintf(szBuffer,GetResString(IDS_SUCCESS_CHANGE_OSOPTIONS), dwDefault );
  5745. DISPLAY_MESSAGE(stdout,szBuffer);
  5746. }
  5747. else
  5748. {
  5749. _stprintf(szBuffer,GetResString(IDS_ERROR_LOAD_OSOPTIONS), dwDefault );
  5750. DISPLAY_MESSAGE(stderr,szBuffer);
  5751. DestroyDynamicArray(&arr);
  5752. resetFileAttrib(szPath);
  5753. SAFEFREE(szFinalStr);
  5754. SAFECLOSE(stream);
  5755. SafeCloseConnection(szServer,bConnFlag);
  5756. return (EXIT_FAILURE);
  5757. }
  5758. //reset the file attributes and free the memory and close the connection to the server.
  5759. bRes = resetFileAttrib(szPath);
  5760. DestroyDynamicArray(&arr);
  5761. SAFEFREE(szFinalStr);
  5762. SAFECLOSE(stream);
  5763. SafeCloseConnection(szServer,bConnFlag);
  5764. return (bRes);
  5765. }
  5766. // ***************************************************************************
  5767. //
  5768. // Routine Description : Display the help for the Dbg1394 entry option (X86).
  5769. //
  5770. // Arguments : none
  5771. //
  5772. // Return Type : VOID
  5773. //
  5774. // ***************************************************************************
  5775. VOID displayDbg1394Usage_X86()
  5776. {
  5777. DWORD dwIndex = IDS_DBG1394_BEGIN_X86 ;
  5778. for(;dwIndex <=IDS_DBG1394_END_X86;dwIndex++)
  5779. {
  5780. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  5781. }
  5782. }
  5783. // ***************************************************************************
  5784. //
  5785. // Routine Description : Display the help for the Dbg1394 entry option (IA64).
  5786. //
  5787. // Arguments : none
  5788. //
  5789. // Return Type : VOID
  5790. //
  5791. // ***************************************************************************
  5792. VOID displayDbg1394Usage_IA64()
  5793. {
  5794. DWORD dwIndex = IDS_DBG1394_BEGIN_IA64 ;
  5795. for(;dwIndex <=IDS_DBG1394_END_IA64 ;dwIndex++)
  5796. {
  5797. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  5798. }
  5799. }
  5800. // ***************************************************************************
  5801. //
  5802. // Routine Description : determines if the computer is 32 bit system or 64 bit
  5803. // Arguments :
  5804. // [ in ] szComputerName : System name
  5805. // Return Type : DWORD
  5806. // TRUE : if the system is a 32 bit system
  5807. // FALSE : if the system is a 64 bit system
  5808. // ***************************************************************************
  5809. DWORD GetCPUInfo(LPTSTR szComputerName)
  5810. {
  5811. HKEY hKey1 = 0;
  5812. HKEY hRemoteKey = 0;
  5813. TCHAR szPath[MAX_STRING_LENGTH + 1] = SUBKEY ;
  5814. DWORD dwValueSize = MAX_STRING_LENGTH + 1;
  5815. DWORD dwRetCode = ERROR_SUCCESS;
  5816. DWORD dwError = 0;
  5817. TCHAR szTmpCompName[MAX_STRING_LENGTH+1] = NULL_STRING;
  5818. TCHAR szTemp[MAX_RES_STRING+1] = NULL_STRING ;
  5819. DWORD len = lstrlen(szTemp);
  5820. TCHAR szVal[MAX_RES_STRING+1] = NULL_STRING ;
  5821. DWORD dwLength = MAX_STRING_LENGTH ;
  5822. LPTSTR szReturnValue = NULL ;
  5823. DWORD dwCode = 0 ;
  5824. szReturnValue = ( LPTSTR ) malloc( dwLength*sizeof( TCHAR ) );
  5825. if(szReturnValue == NULL)
  5826. {
  5827. return ERROR_RETREIVE_REGISTRY ;
  5828. }
  5829. if(lstrlen(szComputerName)!= 0 )
  5830. {
  5831. lstrcpy(szTmpCompName,TOKEN_BACKSLASH4);
  5832. lstrcat(szTmpCompName,szComputerName);
  5833. }
  5834. else
  5835. {
  5836. lstrcpy(szTmpCompName,szComputerName);
  5837. }
  5838. // Get Remote computer local machine key
  5839. dwError = RegConnectRegistry(szTmpCompName,HKEY_LOCAL_MACHINE,&hRemoteKey);
  5840. if (dwError == ERROR_SUCCESS)
  5841. {
  5842. dwError = RegOpenKeyEx(hRemoteKey,szPath,0,KEY_READ,&hKey1);
  5843. if (dwError == ERROR_SUCCESS)
  5844. {
  5845. dwRetCode = RegQueryValueEx(hKey1, IDENTIFIER_VALUE, NULL, NULL,(LPBYTE) szReturnValue, &dwValueSize);
  5846. if (dwRetCode == ERROR_MORE_DATA)
  5847. {
  5848. szReturnValue = ( LPTSTR ) realloc( szReturnValue , dwValueSize * sizeof( TCHAR ) );
  5849. dwRetCode = RegQueryValueEx(hKey1, IDENTIFIER_VALUE, NULL, NULL,(LPBYTE) szReturnValue, &dwValueSize);
  5850. }
  5851. if(dwRetCode != ERROR_SUCCESS)
  5852. {
  5853. RegCloseKey(hKey1);
  5854. RegCloseKey(hRemoteKey);
  5855. SAFEFREE(szReturnValue);
  5856. return ERROR_RETREIVE_REGISTRY ;
  5857. }
  5858. }
  5859. else
  5860. {
  5861. RegCloseKey(hRemoteKey);
  5862. SAFEFREE(szReturnValue);
  5863. return ERROR_RETREIVE_REGISTRY ;
  5864. }
  5865. RegCloseKey(hKey1);
  5866. }
  5867. else
  5868. {
  5869. RegCloseKey(hRemoteKey);
  5870. SAFEFREE(szReturnValue);
  5871. return ERROR_RETREIVE_REGISTRY ;
  5872. }
  5873. RegCloseKey(hRemoteKey);
  5874. lstrcpy(szVal,X86_MACHINE);
  5875. //check if the specified system contains the words x86 (belongs to the 32 )
  5876. // set the flag to true if the specified system is 64 bit .
  5877. if( !_tcsstr(szReturnValue,szVal))
  5878. {
  5879. dwCode = SYSTEM_64_BIT ;
  5880. }
  5881. else
  5882. {
  5883. dwCode = SYSTEM_32_BIT ;
  5884. }
  5885. SAFEFREE(szReturnValue);
  5886. return dwCode ;
  5887. }//GetCPUInfo
  5888. // ***************************************************************************
  5889. //
  5890. // Routine Description : determines if the computer is 32 bit system or 64 bit
  5891. // Arguments :
  5892. // [ in ] szServer : System name
  5893. // Return Type : DWORD
  5894. // EXIT_FAILURE : if the system is a 32 bit system
  5895. // EXIT_SUCCESS : if the system is a 64 bit system
  5896. // ***************************************************************************
  5897. DWORD CheckSystemType(LPTSTR szServer)
  5898. {
  5899. DWORD dwSystemType = 0 ;
  5900. #ifndef _WIN64
  5901. //display the error message if the target system is a 64 bit system or if error occured in
  5902. //retreiving the information
  5903. dwSystemType = GetCPUInfo(szServer);
  5904. if(dwSystemType == ERROR_RETREIVE_REGISTRY)
  5905. {
  5906. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_SYSTEM_INFO));
  5907. return (EXIT_FAILURE);
  5908. }
  5909. if(dwSystemType == SYSTEM_64_BIT)
  5910. {
  5911. if(lstrlen(szServer)== 0 )
  5912. {
  5913. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_VERSION_MISMATCH));
  5914. }
  5915. else
  5916. {
  5917. DISPLAY_MESSAGE(stderr,GetResString(IDS_REMOTE_NOT_SUPPORTED));
  5918. }
  5919. return (EXIT_FAILURE);
  5920. }
  5921. #endif
  5922. return EXIT_SUCCESS ;
  5923. }
  5924. // ***************************************************************************
  5925. //
  5926. // Routine Description : determines if the computer is 32 bit system or 64 bit
  5927. // Arguments :
  5928. // [ in ] szServer : System name
  5929. // [ in ] bFlag : Flag
  5930. // Return Type : VOID
  5931. //
  5932. //
  5933. // ***************************************************************************
  5934. VOID SafeCloseConnection(LPTSTR szServer,BOOL bFlag)
  5935. {
  5936. if (bFlag )
  5937. {
  5938. CloseConnection(szServer);
  5939. }
  5940. }
  5941. // ***************************************************************************
  5942. //
  5943. // Routine Description : Display the help for the mirror option (IA64).
  5944. // Arguments :
  5945. // : NONE
  5946. //
  5947. // Return Type : VOID
  5948. //
  5949. //
  5950. // ***************************************************************************
  5951. VOID displayMirrorUsage_IA64()
  5952. {
  5953. DWORD dwIndex = IDS_MIRROR_BEGIN_IA64 ;
  5954. for(;dwIndex <=IDS_MIRROR_END_IA64 ;dwIndex++)
  5955. {
  5956. DISPLAY_MESSAGE(stdout,GetResString(dwIndex));
  5957. }
  5958. }