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.

1800 lines
58 KiB

  1. /******************************************************************************
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. OpenFiles.cpp
  5. Abstract:
  6. Enables an administrator to disconnect/query open files ina given system.
  7. Author:
  8. Akhil Gokhale (akhil.gokhale@wipro.com) 1-Nov-2000
  9. Revision History:
  10. Akhil Gokhale (akhil.gokhale@wipro.com) 1-Nov-2000 : Created It.
  11. ******************************************************************************/
  12. #include "pch.h"
  13. #include "OpenFiles.h"
  14. #include "Disconnect.h"
  15. #include "Query.h"
  16. #include <limits.h>
  17. #include "resource.h"
  18. #define EXIT_ENV_SUCCESS 1
  19. #define EXIT_ENV_FAILURE 0
  20. #define SUBKEY _T("HARDWARE\\DESCRIPTION\\SYSTEM\\CENTRALPROCESSOR\\0")
  21. #define ERROR_RETREIVE_REGISTRY 4
  22. #define TOKEN_BACKSLASH4 _T("\\\\")
  23. #define IDENTIFIER_VALUE _T("Identifier")
  24. #define SAFEFREE(pVal) \
  25. if(pVal != NULL) \
  26. { \
  27. free(pVal); \
  28. pVal = NULL ;\
  29. }
  30. #define X86_MACHINE _T("x86")
  31. #define SYSTEM_64_BIT 2
  32. #define SYSTEM_32_BIT 3
  33. BOOL g_bIs32BitEnv = TRUE ;
  34. // Fuction protorypes. These functions will be used only in current file.
  35. DWORD GetCPUInfo(LPTSTR szComputerName);
  36. DWORD CheckSystemType(LPTSTR szServer);
  37. DWORD CheckSystemType64(LPTSTR szServer);
  38. BOOL ProcessQuery(DWORD argc,LPCTSTR argv[],LONG lMemorySize);
  39. BOOL ProcessDisconnect(DWORD argc,LPCTSTR argv[],LONG lMemorySize);
  40. BOOL ProcessLocal(DWORD argc,LPCTSTR argv[]);
  41. BOOL ProcessOptions( DWORD argc,LPCTSTR argv[],PBOOL pbDisconnect,
  42. PBOOL pbQuery,PBOOL pbUsage,
  43. PBOOL pbResetFlag,
  44. LONG lMemorySize);
  45. BOOL ProcessOptions( DWORD argc, LPCTSTR argv[],PBOOL pbQuery,LPTSTR pszServer,
  46. LPTSTR pszUserName,LPTSTR pszPassword,LPTSTR pszFormat,
  47. PBOOL pbShowNoHeader,PBOOL pbVerbose,PBOOL pbNeedPassword);
  48. BOOL ProcessOptions( DWORD argc, LPCTSTR argv[], PBOOL pbDisconnect,
  49. LPTSTR pszServer,LPTSTR pszUserName,LPTSTR pszPassword,
  50. LPTSTR pszID,LPTSTR pszAccessedby,LPTSTR pszOpenmode,
  51. LPTSTR pszOpenFile,PBOOL pbNeedPassword);
  52. BOOL
  53. ProcessOptions( DWORD argc,
  54. LPCTSTR argv[],
  55. LPTSTR pszLocalvalue);
  56. VOID Usage();
  57. VOID DisconnectUsage();
  58. VOID QueryUsage();
  59. VOID LocalUsage();
  60. /*-----------------------------------------------------------------------------
  61. Routine Description:
  62. Main routine that calls the disconnect and query options
  63. Arguments:
  64. [in] argc - Number of command line arguments
  65. [in] argv - Array containing command line arguments
  66. Returned Value:
  67. DWORD - 0 for success exit
  68. - 1 for failure exit
  69. -----------------------------------------------------------------------------*/
  70. DWORD _cdecl
  71. _tmain( DWORD argc, LPCTSTR argv[] )
  72. {
  73. BOOL bCleanExit = FALSE;
  74. try{
  75. // local variables to this function
  76. BOOL bResult = TRUE;
  77. BOOL bNeedPassword = FALSE;
  78. // variables to hold the values specified at the command prompt
  79. BOOL bUsage = FALSE;// -? ( help )
  80. BOOL bDisconnect = FALSE;// -disconnect
  81. //query command line options
  82. BOOL bQuery = FALSE;// -query
  83. BOOL bRestFlag = FALSE;
  84. LONG lMemorySize =0; // Memory needed for allocation.
  85. DWORD dwRetVal = 0;
  86. #ifndef _WIN64
  87. dwRetVal = CheckSystemType( NULL_STRING);
  88. if(dwRetVal!=EXIT_SUCCESS )
  89. {
  90. return EXIT_FAILURE;
  91. }
  92. #endif
  93. // Followin is a guess to allocate the memory for variables used
  94. // in many function. Guess is to allocate memory equals to Lenghth of
  95. // maximum command line argumant.
  96. for(UINT i = 1;i<argc;i++)
  97. {
  98. if(lMemorySize < lstrlen(argv[i]))
  99. lMemorySize = lstrlen(argv[i]);
  100. }
  101. // Check for minimum memory required. If above logic gets memory size
  102. // less than MIN_MEMORY_REQUIRED, then make this to MIN_MEMORY_REQUIRED.
  103. lMemorySize = ((lMemorySize<MIN_MEMORY_REQUIRED)?
  104. MIN_MEMORY_REQUIRED:
  105. lMemorySize);
  106. // if no command line argument is given than -query option
  107. // is takan by default.
  108. if(argc == 1)
  109. {
  110. if(IsWin2KOrLater()==FALSE)
  111. {
  112. ShowMessage(stderr,GetResString(IDS_INVALID_OS));
  113. bCleanExit = FALSE;
  114. }
  115. else
  116. {
  117. bCleanExit = DoQuery(NULL_STRING,FALSE,NULL_STRING,FALSE);
  118. }
  119. }
  120. else
  121. {
  122. // process and validate the command line options
  123. bResult = ProcessOptions( argc,
  124. argv,
  125. &bDisconnect,
  126. &bQuery,
  127. &bUsage,
  128. &bRestFlag,
  129. lMemorySize);
  130. if(bResult == TRUE)
  131. {
  132. if(bUsage == TRUE)// check if -? is given as parameter
  133. {
  134. if(bQuery == TRUE)//check if -create is also given
  135. {
  136. QueryUsage();// show usage for -create option
  137. bCleanExit = TRUE;
  138. }
  139. else if (bDisconnect==TRUE)//check if -disconnect is also given
  140. {
  141. DisconnectUsage();//Show usage for -disconnect option
  142. bCleanExit = TRUE;
  143. }
  144. else if (bRestFlag==TRUE)//check if -disconnect is also given
  145. {
  146. LocalUsage();//Show usage for -local option
  147. bCleanExit = TRUE;
  148. }
  149. else
  150. {
  151. Usage();//as no -create Or -disconnect given, show main
  152. // usage.
  153. bCleanExit = TRUE;
  154. }
  155. }
  156. else
  157. {
  158. if(bRestFlag == TRUE)
  159. {
  160. bCleanExit = ProcessLocal(argc,argv);
  161. bCleanExit = TRUE;
  162. }
  163. else if(bQuery == TRUE)
  164. {
  165. // Process command line parameter specific to -query and
  166. bCleanExit = ProcessQuery(argc,
  167. argv,
  168. lMemorySize);
  169. }
  170. else if(bDisconnect==TRUE)
  171. {
  172. // Process command line parameter specific to -disconnect
  173. bCleanExit = ProcessDisconnect(argc,
  174. argv,
  175. lMemorySize);
  176. }
  177. else
  178. {
  179. CHString szTemp;
  180. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  181. szTemp = argv[0];
  182. szTemp.MakeUpper();
  183. szTemp.Format(GetResString(IDS_INVALID_SYNTAX),szTemp);
  184. ShowMessage( stderr,(LPCWSTR)szTemp);
  185. bCleanExit = FALSE;
  186. }
  187. }
  188. }
  189. else
  190. {
  191. if(g_bIs32BitEnv == TRUE)
  192. {
  193. // invalid syntax
  194. ShowMessage( stderr,GetReason());
  195. }
  196. // return from the function
  197. bCleanExit = FALSE;
  198. }
  199. }
  200. }
  201. catch(CHeap_Exception cheapException)
  202. {
  203. // catching the CHStrig related memory exceptions...
  204. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  205. DISPLAY_MESSAGE(stderr,GetResString(IDS_ID_SHOW_ERROR));
  206. DISPLAY_MESSAGE(stderr,GetReason());
  207. bCleanExit = FALSE;
  208. }
  209. // Release global memory if any allocated through common functionality
  210. ReleaseGlobals();
  211. return bCleanExit?EXIT_SUCCESS:EXIT_FAILURE;
  212. }//_tmain
  213. /*-----------------------------------------------------------------------------
  214. Routine Description:
  215. This function will perform Local related tasks.
  216. Arguments:
  217. [in] argc - Number of command line arguments
  218. [in] argv - Array containing command line arguments
  219. Returned Value:
  220. BOOL --True if it succeeds
  221. --False if it fails.
  222. -----------------------------------------------------------------------------*/
  223. BOOL
  224. ProcessLocal( DWORD argc,LPCTSTR argv[])
  225. {
  226. BOOL bResult = FALSE; // Variable to store function return value
  227. LPTSTR pszLocalValue = new TCHAR[MAX_USERNAME_LENGTH];// MAX_USERNAME_LENGTH
  228. // just taken for its length
  229. if(pszLocalValue == NULL)
  230. {
  231. // Some variable not having enough memory
  232. // Show Error----
  233. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  234. DISPLAY_MESSAGE(stderr,GetResString(IDS_ID_SHOW_ERROR));
  235. //Release allocated memory safely
  236. ShowLastError(stderr);
  237. return FALSE;
  238. }
  239. // Initialize currently allocated arrays.
  240. memset(pszLocalValue,0,(MAX_USERNAME_LENGTH)*sizeof(TCHAR));
  241. bResult = ProcessOptions( argc,argv,pszLocalValue);
  242. if(bResult == FALSE)
  243. {
  244. // invalid syntax
  245. ShowMessage( stderr,GetReason() );
  246. //Release allocated memory safely
  247. SAFEDELETE(pszLocalValue);
  248. // return from the function
  249. return FALSE;
  250. }
  251. bResult = DoLocalOpenFiles(0,FALSE,FALSE,pszLocalValue); // Only last argument is of interst
  252. SAFEDELETE(pszLocalValue);
  253. return bResult;
  254. }
  255. /*-----------------------------------------------------------------------------
  256. Routine Description:
  257. This function will perform query related tasks.
  258. Arguments:
  259. [in] argc - Number of command line arguments
  260. [in] argv - Array containing command line arguments
  261. [in] lMemorySize - Maximum amount of memory to be allocated.
  262. Returned Value:
  263. BOOL --True if it succeeds
  264. --False if it fails.
  265. -----------------------------------------------------------------------------*/
  266. BOOL
  267. ProcessQuery( DWORD argc,
  268. LPCTSTR argv[],
  269. LONG lMemorySize
  270. )
  271. {
  272. BOOL bResult = FALSE; // Variable to store function return value
  273. BOOL bCloseConnection = FALSE; //Check whether connection to be
  274. // closed or not
  275. CHString szChString; // Temp. variable
  276. DWORD dwRetVal = 0;
  277. // options.
  278. BOOL bQuery = FALSE; // -query query
  279. BOOL bShowNoHeader = FALSE;// -nh (noheader)
  280. BOOL bVerbose = FALSE;// -v (verbose)
  281. BOOL bNeedPassword = FALSE;// need password or not
  282. LPTSTR pszServer = new TCHAR[lMemorySize+1];// -s ( server name)
  283. LPTSTR pszUserName = new TCHAR[lMemorySize+1];// -u ( user name)
  284. LPTSTR pszPassword = new TCHAR[lMemorySize+1];// -p ( password)
  285. LPTSTR pszFormat = new TCHAR[lMemorySize+1];// -format
  286. LPTSTR pszServerName = new TCHAR[lMemorySize+1];// server name used for
  287. // EstablishConnection
  288. // Function.
  289. LPTSTR pszServerNameHeadPosition = NULL;
  290. LPTSTR pszServerHeadPosition = NULL;
  291. // Check if memory allocated to all variables properly
  292. if((pszServer == NULL)||
  293. (pszUserName == NULL)||
  294. (pszPassword == NULL)||
  295. (pszFormat == NULL)||
  296. (pszServerName == NULL)
  297. )
  298. {
  299. // Some variable not having enough memory
  300. // Show Error----
  301. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  302. DISPLAY_MESSAGE(stderr,GetResString(IDS_ID_SHOW_ERROR));
  303. //Release allocated memory safely
  304. ShowLastError(stderr);
  305. SAFEDELETE(pszServer);
  306. SAFEDELETE(pszUserName);
  307. SAFEDELETE(pszPassword);
  308. SAFEDELETE(pszFormat);
  309. SAFEDELETE(pszServerName);
  310. return FALSE;
  311. }
  312. pszServerNameHeadPosition = pszServerName;//store Head position Address
  313. // to successfully delete
  314. // allocated memory block
  315. pszServerHeadPosition = pszServer;
  316. // Initialize currently allocated arrays.
  317. memset(pszServer,0,(lMemorySize+1)*sizeof(TCHAR));
  318. memset(pszUserName,0,(lMemorySize+1)*sizeof(TCHAR));
  319. memset(pszPassword,0,(lMemorySize+1)*sizeof(TCHAR));
  320. memset(pszFormat,0,(lMemorySize+1)*sizeof(TCHAR));
  321. memset(pszServerName,0,(lMemorySize+1)*sizeof(TCHAR));
  322. bResult = ProcessOptions( argc,
  323. argv,
  324. &bQuery,
  325. pszServer,
  326. pszUserName,
  327. pszPassword,
  328. pszFormat,
  329. &bShowNoHeader,
  330. &bVerbose,
  331. &bNeedPassword);
  332. if ( bResult == FALSE )
  333. {
  334. // invalid syntax
  335. ShowMessage( stderr,GetReason() );
  336. //Release allocated memory safely
  337. SAFEDELETE(pszServerHeadPosition);
  338. SAFEDELETE(pszUserName);
  339. SAFEDELETE(pszPassword);
  340. SAFEDELETE(pszFormat);
  341. SAFEDELETE(pszServerNameHeadPosition);
  342. // return from the function
  343. return FALSE;
  344. }
  345. szChString = pszServer;
  346. if((lstrcmpi(szChString.Left(2),DOUBLE_SLASH)==0)&&(szChString.GetLength()>2))
  347. {
  348. szChString = szChString.Mid( 2,szChString.GetLength()) ;
  349. }
  350. if(lstrcmpi(szChString.Left(1),SINGLE_SLASH)!=0)
  351. {
  352. lstrcpy(pszServer,(LPCWSTR)szChString);
  353. }
  354. lstrcpy(pszServerName,pszServer);
  355. // Try to connect to remote server. Function checks for local machine
  356. // so here no checking is done.
  357. if(IsLocalSystem(pszServerName)==TRUE)
  358. {
  359. if(lstrlen(pszUserName)>0)
  360. {
  361. DISPLAY_MESSAGE(stdout,GetResString(IDS_LOCAL_SYSTEM));
  362. }
  363. }
  364. else
  365. {
  366. if(EstablishConnection( pszServerName,
  367. pszUserName,
  368. lMemorySize,
  369. pszPassword,
  370. lMemorySize,
  371. bNeedPassword )==FALSE)
  372. {
  373. // Connection to remote system failed , Show corresponding error
  374. // and exit from function.
  375. ShowMessage( stderr,GetResString(IDS_ID_SHOW_ERROR) );
  376. if(lstrlen(GetReason())==0)
  377. {
  378. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_CREDENTIALS));
  379. }
  380. else
  381. {
  382. DISPLAY_MESSAGE( stderr,GetReason() );
  383. }
  384. //Release allocated memory safely
  385. SAFEDELETE(pszServerHeadPosition);
  386. SAFEDELETE(pszUserName);
  387. SAFEDELETE(pszPassword);
  388. SAFEDELETE(pszFormat);
  389. SAFEDELETE(pszServerNameHeadPosition);
  390. return FALSE;
  391. }
  392. // determine whether this connection needs to disconnected later or not
  393. // though the connection is successfull, some conflict might have occured
  394. switch( GetLastError() )
  395. {
  396. case I_NO_CLOSE_CONNECTION:
  397. bCloseConnection = FALSE;
  398. break;
  399. case E_LOCAL_CREDENTIALS:
  400. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  401. {
  402. //
  403. // some error occured ... but can be ignored
  404. // connection need not be disconnected
  405. bCloseConnection= FALSE;
  406. // show the warning message
  407. DISPLAY_MESSAGE(stdout,GetResString(IDS_ID_SHOW_WARNING));
  408. DISPLAY_MESSAGE(stdout,GetReason());
  409. break;
  410. }
  411. default:
  412. bCloseConnection = TRUE;
  413. }
  414. }
  415. bResult = DoQuery(pszServer,
  416. bShowNoHeader,
  417. pszFormat,
  418. bVerbose);
  419. // Close the network connection which is previously opened by
  420. // EstablishConnection
  421. if(bCloseConnection==TRUE)
  422. {
  423. CloseConnection(pszServerName);
  424. }
  425. SAFEDELETE(pszServerHeadPosition);
  426. SAFEDELETE(pszUserName);
  427. SAFEDELETE(pszPassword);
  428. SAFEDELETE(pszFormat);
  429. SAFEDELETE(pszServerNameHeadPosition);
  430. return bResult;
  431. }
  432. /*-----------------------------------------------------------------------------
  433. Routine Description:
  434. This function will perform Disconnect related tasks.
  435. Arguments:
  436. [in] argc - Number of command line arguments
  437. [in] argv - Array containing command line arguments
  438. [in] lMemorySize - Maximum amount of memory to be allocated.
  439. [in] pbNeedPassword - To check whether the password is required
  440. or not.
  441. Returned Value:
  442. BOOL --True if it succeeds
  443. --False if it fails.
  444. -----------------------------------------------------------------------------*/
  445. BOOL
  446. ProcessDisconnect(DWORD argc,LPCTSTR argv[],LONG lMemorySize)
  447. {
  448. BOOL bResult = FALSE; // Variable to store function return value
  449. DWORD dwRetVal = 0;
  450. BOOL bCloseConnection = FALSE; //Check whether connection to be
  451. // closed or not
  452. BOOL bNeedPassword = FALSE; // Ask for password or not.
  453. CHString szChString; // Temp. variable
  454. // options.
  455. BOOL bQuery = FALSE; // -query query
  456. BOOL bShowNoHeader = FALSE;// -nh (noheader)
  457. LPTSTR pszServer = new TCHAR[lMemorySize+1];// -s ( server name)
  458. LPTSTR pszUserName = new TCHAR[lMemorySize+1];// -u ( user name)
  459. LPTSTR pszPassword = new TCHAR[lMemorySize+1];// -p ( password)
  460. LPTSTR pszServerName = new TCHAR[lMemorySize+1];// server name used for
  461. // EstablishConnection
  462. // Function.
  463. LPTSTR pszServerNameHeadPosition = NULL;
  464. LPTSTR pszServerHeadPosition = NULL;
  465. LPTSTR pszID = new TCHAR[lMemorySize+1];// -I ( id )
  466. LPTSTR pszAccessedby = new TCHAR[lMemorySize+1];//-a(accessedby)
  467. LPTSTR pszOpenmode = new TCHAR[lMemorySize+1];// -o ( openmode)
  468. LPTSTR pszOpenFile = new TCHAR[lMemorySize+1];// -op( openfile)
  469. // Check if memory allocated to all variables properly
  470. if((pszServer == NULL)||
  471. (pszUserName == NULL)||
  472. (pszPassword == NULL)||
  473. (pszServerName == NULL)||
  474. (pszID == NULL)||
  475. (pszAccessedby == NULL)||
  476. (pszOpenmode == NULL)||
  477. (pszOpenFile == NULL)
  478. )
  479. {
  480. // Some variable not having enough memory
  481. // Show Error----
  482. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  483. DISPLAY_MESSAGE(stderr,GetResString(IDS_ID_SHOW_ERROR));
  484. //Release allocated memory safely
  485. ShowLastError(stderr);
  486. SAFEDELETE(pszServer);
  487. SAFEDELETE(pszUserName);
  488. SAFEDELETE(pszPassword);
  489. SAFEDELETE(pszServerName);
  490. SAFEDELETE(pszID);
  491. SAFEDELETE(pszAccessedby);
  492. SAFEDELETE(pszOpenmode);
  493. SAFEDELETE(pszOpenFile);
  494. return FALSE;
  495. }
  496. pszServerNameHeadPosition = pszServerName;//store Head position Address
  497. // to successfully delete
  498. // allocated memory block
  499. pszServerHeadPosition = pszServer;
  500. // Initialize currently allocated arrays.
  501. memset(pszServer,0,(lMemorySize+1)*sizeof(TCHAR));
  502. memset(pszUserName,0,(lMemorySize+1)*sizeof(TCHAR));
  503. memset(pszPassword,0,(lMemorySize+1)*sizeof(TCHAR));
  504. memset(pszServerName,0,(lMemorySize+1)*sizeof(TCHAR));
  505. memset(pszID,0,(lMemorySize)*sizeof(TCHAR));
  506. memset(pszAccessedby,0,(lMemorySize+1)*sizeof(TCHAR));
  507. memset(pszOpenmode,0,(lMemorySize+1)*sizeof(TCHAR));
  508. memset(pszOpenFile,0,(lMemorySize+1)*sizeof(TCHAR));
  509. bResult = ProcessOptions( argc,
  510. argv,
  511. &bQuery,
  512. pszServer,
  513. pszUserName,
  514. pszPassword,
  515. pszID,
  516. pszAccessedby,
  517. pszOpenmode,
  518. pszOpenFile,
  519. &bNeedPassword);
  520. if ( bResult == FALSE )
  521. {
  522. // invalid syntax
  523. ShowMessage( stderr,GetReason() );
  524. //Release allocated memory safely
  525. SAFEDELETE(pszServerHeadPosition);
  526. SAFEDELETE(pszUserName);
  527. SAFEDELETE(pszPassword);
  528. SAFEDELETE(pszServerNameHeadPosition);
  529. SAFEDELETE(pszID);
  530. SAFEDELETE(pszAccessedby);
  531. SAFEDELETE(pszOpenmode);
  532. SAFEDELETE(pszOpenFile);
  533. // return from the function
  534. return FALSE;
  535. }
  536. szChString = pszServer;
  537. if((lstrcmpi(szChString.Left(2),DOUBLE_SLASH)==0)&&(szChString.GetLength()>2))
  538. {
  539. szChString = szChString.Mid( 2,szChString.GetLength()) ;
  540. }
  541. if(lstrcmpi(szChString.Left(2),SINGLE_SLASH)!=0)
  542. {
  543. lstrcpy(pszServer,(LPCWSTR)szChString);
  544. }
  545. lstrcpy(pszServerName,pszServer);
  546. if(IsLocalSystem(pszServerName)==TRUE)
  547. {
  548. #ifndef _WIN64
  549. dwRetVal = CheckSystemType( NULL_STRING);
  550. if(dwRetVal!=EXIT_SUCCESS )
  551. {
  552. return EXIT_FAILURE;
  553. }
  554. #else
  555. dwRetVal = CheckSystemType64( NULL_STRING);
  556. if(dwRetVal!=EXIT_SUCCESS )
  557. {
  558. return EXIT_FAILURE;
  559. }
  560. #endif //Comment 2
  561. if(lstrlen(pszUserName)>0)
  562. {
  563. DISPLAY_MESSAGE(stdout,GetResString(IDS_LOCAL_SYSTEM));
  564. }
  565. }
  566. else
  567. {
  568. if(EstablishConnection( pszServerName,
  569. pszUserName,
  570. lMemorySize,
  571. pszPassword,
  572. lMemorySize,
  573. bNeedPassword )==FALSE)
  574. {
  575. // Connection to remote system failed , Show corresponding error
  576. // and exit from function.
  577. ShowMessage( stderr,
  578. GetResString(IDS_ID_SHOW_ERROR) );
  579. if(lstrlen(GetReason())==0)
  580. {
  581. DISPLAY_MESSAGE(stderr,GetResString(IDS_INVALID_CREDENTIALS));
  582. }
  583. else
  584. {
  585. DISPLAY_MESSAGE( stderr,GetReason() );
  586. }
  587. //Release allocated memory safely
  588. SAFEDELETE(pszServerHeadPosition);
  589. SAFEDELETE(pszUserName);
  590. SAFEDELETE(pszPassword);
  591. SAFEDELETE(pszServerNameHeadPosition);
  592. SAFEDELETE(pszID);
  593. SAFEDELETE(pszAccessedby);
  594. SAFEDELETE(pszOpenmode);
  595. SAFEDELETE(pszOpenFile);
  596. return FALSE;
  597. }
  598. // determine whether this connection needs to disconnected later or not
  599. // though the connection is successfull, some conflict might have occured
  600. switch( GetLastError() )
  601. {
  602. case I_NO_CLOSE_CONNECTION:
  603. bCloseConnection = FALSE;
  604. break;
  605. case E_LOCAL_CREDENTIALS:
  606. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  607. {
  608. //
  609. // some error occured ... but can be ignored
  610. // connection need not be disconnected
  611. bCloseConnection= FALSE;
  612. // show the warning message
  613. DISPLAY_MESSAGE(stdout,GetResString(IDS_ID_SHOW_WARNING));
  614. DISPLAY_MESSAGE(stdout,GetReason());
  615. break;
  616. }
  617. default:
  618. bCloseConnection = TRUE;
  619. }
  620. }
  621. // Do Disconnect open files.....
  622. bResult = DisconnectOpenFile(pszServer,
  623. pszID,
  624. pszAccessedby,
  625. pszOpenmode,
  626. pszOpenFile );
  627. // Close the network connection which is previously opened by
  628. // EstablishConnection
  629. if(bCloseConnection==TRUE)
  630. {
  631. CloseConnection(pszServerName);
  632. }
  633. // Free memory which is previously allocated.
  634. SAFEDELETE(pszServerHeadPosition);
  635. SAFEDELETE(pszUserName);
  636. SAFEDELETE(pszPassword);
  637. SAFEDELETE(pszServerNameHeadPosition);
  638. SAFEDELETE(pszID);
  639. SAFEDELETE(pszAccessedby);
  640. SAFEDELETE(pszOpenmode);
  641. SAFEDELETE(pszOpenFile);
  642. return bResult;
  643. }
  644. /*-----------------------------------------------------------------------------
  645. Routine Description:
  646. This function takes command line argument and checks for correct syntax and
  647. if the syntax is ok, it returns the values in different variables. variables
  648. [out] will contain respective values.
  649. Arguments:
  650. [in] argc - Number of command line arguments
  651. [in] argv - Array containing command line arguments
  652. [out] pszLocalValue - contains the values for -local option
  653. Returned Value:
  654. BOOL --True if it succeeds
  655. --False if it fails.
  656. -----------------------------------------------------------------------------*/
  657. BOOL
  658. ProcessOptions( DWORD argc,
  659. LPCTSTR argv[],
  660. LPTSTR pszLocalValue)
  661. {
  662. TCMDPARSER cmdOptions[ MAX_LOCAL_OPTIONS ];//Variable to store command line
  663. CHString szTempString;
  664. TCHAR szTemp[MAX_RES_STRING*2];
  665. szTempString = GetResString(IDS_UTILITY_NAME);
  666. wsprintf(szTemp,GetResString(IDS_INVALID_SYNTAX),(LPCWSTR)szTempString);
  667. // -local
  668. cmdOptions[ OI_O_LOCAL ].dwCount = 1;
  669. cmdOptions[ OI_O_LOCAL ].dwActuals = 0;
  670. cmdOptions[ OI_O_LOCAL ].dwFlags = CP_MAIN_OPTION|CP_VALUE_OPTIONAL|CP_MODE_VALUES| CP_TYPE_TEXT;
  671. cmdOptions[ OI_O_LOCAL ].pValue = pszLocalValue;
  672. cmdOptions[ OI_O_LOCAL ].pFunction = NULL;
  673. cmdOptions[ OI_O_LOCAL ].pFunctionData = NULL;
  674. lstrcpy( cmdOptions[ OI_O_LOCAL ].szValues, GetResString(IDS_LOCAL_OPTION) );
  675. lstrcpy( cmdOptions[ OI_O_LOCAL ].szOption, OPTION_LOCAL );
  676. //
  677. // do the command line parsing
  678. if ( DoParseParam( argc,argv,MAX_LOCAL_OPTIONS,cmdOptions ) == FALSE )
  679. {
  680. ShowMessage(stderr,GetResString(IDS_ID_SHOW_ERROR));
  681. return FALSE; // invalid syntax
  682. }
  683. if(lstrlen(pszLocalValue) == 0)
  684. {
  685. lstrcpy(pszLocalValue,L"SHOW_STATUS"); // this string does not require localization
  686. // as it is storing value other than ON/OFF
  687. }
  688. return TRUE;
  689. }
  690. /*-----------------------------------------------------------------------------
  691. Routine Description:
  692. This function takes command line argument and checks for correct syntax and
  693. if the syntax is ok, it returns the values in different variables. variables
  694. [out] will contain respective values.
  695. Arguments:
  696. [in] argc - Number of command line arguments
  697. [in] argv - Array containing command line arguments
  698. [out] pbDisconnect - Discoonect option string
  699. [out] pbQuery - Query option string
  700. [out] pbUsage - The usage option
  701. [out] pbNeedPassword - To check whether the password is required
  702. or not.
  703. [in] lMemorySize - Maximum amount of memory to be allocated.
  704. Returned Value:
  705. BOOL --True if it succeeds
  706. --False if it fails.
  707. -----------------------------------------------------------------------------*/
  708. BOOL
  709. ProcessOptions( DWORD argc,
  710. LPCTSTR argv[],
  711. PBOOL pbDisconnect,
  712. PBOOL pbQuery,
  713. PBOOL pbUsage,
  714. PBOOL pbResetFlag,
  715. LONG lMemorySize)
  716. {
  717. DWORD dwRetVal = 0;
  718. // local variables
  719. TCMDPARSER cmdOptions[ MAX_OPTIONS ];//Variable to store command line
  720. // options.
  721. LPTSTR pszTempServer = new TCHAR[lMemorySize+1];
  722. LPTSTR pszTempUser = new TCHAR[lMemorySize+1];
  723. LPTSTR pszTempPassword = new TCHAR[lMemorySize+1];
  724. TARRAY arrTemp = NULL;
  725. CHString szTempString;
  726. TCHAR szTemp[MAX_RES_STRING*2];
  727. szTempString = GetResString(IDS_UTILITY_NAME);
  728. wsprintf(szTemp,GetResString(IDS_INVALID_SYNTAX),(LPCWSTR)szTempString);
  729. // Allocates memory
  730. arrTemp = CreateDynamicArray();
  731. BOOL bTemp = FALSE; // Temp. Variable
  732. //
  733. if((pszTempUser == NULL)||
  734. (pszTempPassword== NULL)||
  735. (pszTempServer == NULL)||
  736. (arrTemp == NULL))
  737. {
  738. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  739. DISPLAY_MESSAGE(stderr,GetResString(IDS_ID_SHOW_ERROR));
  740. ShowLastError(stderr);
  741. SAFEDELETE(pszTempUser);
  742. SAFEDELETE(pszTempPassword);
  743. SAFEDELETE(pszTempServer);
  744. DestroyDynamicArray(&arrTemp);
  745. return FALSE;
  746. }
  747. // prepare the command options
  748. // -disconnect option for help
  749. cmdOptions[ OI_DISCONNECT ].dwCount = 1;
  750. cmdOptions[ OI_DISCONNECT ].dwActuals = 0;
  751. cmdOptions[ OI_DISCONNECT ].dwFlags = 0;
  752. cmdOptions[ OI_DISCONNECT ].pValue = pbDisconnect;
  753. cmdOptions[ OI_DISCONNECT ].pFunction = NULL;
  754. cmdOptions[ OI_DISCONNECT ].pFunctionData = NULL;
  755. lstrcpy( cmdOptions[ OI_DISCONNECT ].szValues, NULL_STRING );
  756. lstrcpy( cmdOptions[ OI_DISCONNECT ].szOption, OPTION_DISCONNECT );
  757. // -query option for help
  758. cmdOptions[ OI_QUERY ].dwCount = 1;
  759. cmdOptions[ OI_QUERY ].dwActuals = 0;
  760. cmdOptions[ OI_QUERY ].dwFlags = 0;
  761. cmdOptions[ OI_QUERY ].pValue = pbQuery;
  762. cmdOptions[ OI_QUERY ].pFunction = NULL;
  763. cmdOptions[ OI_QUERY ].pFunctionData = NULL;
  764. lstrcpy( cmdOptions[ OI_QUERY ].szValues, NULL_STRING );
  765. lstrcpy( cmdOptions[ OI_QUERY ].szOption, OPTION_QUERY );
  766. // -? option for help
  767. cmdOptions[ OI_USAGE ].dwCount = 1;
  768. cmdOptions[ OI_USAGE ].dwActuals = 0;
  769. cmdOptions[ OI_USAGE ].dwFlags = CP_USAGE;
  770. cmdOptions[ OI_USAGE ].pValue = pbUsage;
  771. cmdOptions[ OI_USAGE ].pFunction = NULL;
  772. cmdOptions[ OI_USAGE ].pFunctionData = NULL;
  773. lstrcpy( cmdOptions[ OI_USAGE ].szValues, NULL_STRING );
  774. lstrcpy( cmdOptions[ OI_USAGE ].szOption, OPTION_USAGE );
  775. // -local
  776. cmdOptions[ OI_LOCAL ].dwCount = 1;
  777. cmdOptions[ OI_LOCAL ].dwActuals = 0;
  778. cmdOptions[ OI_LOCAL ].dwFlags = 0;
  779. cmdOptions[ OI_LOCAL ].pValue = pbResetFlag;
  780. cmdOptions[ OI_LOCAL ].pFunction = NULL;
  781. cmdOptions[ OI_LOCAL ].pFunctionData = NULL;
  782. lstrcpy( cmdOptions[ OI_LOCAL ].szValues, NULL_STRING );
  783. lstrcpy( cmdOptions[ OI_LOCAL ].szOption, OPTION_LOCAL );
  784. // default ..
  785. // Although there is no default option for this utility...
  786. // At this moment all the switches other than specified above will be
  787. // treated as default parameter for Main DoParceParam.
  788. // Exact parcing depending on optins (-query or -disconnect) will be done
  789. // at that respective places.
  790. lstrcpy(cmdOptions[ OI_DEFAULT ].szOption,NULL_STRING);
  791. cmdOptions[ OI_DEFAULT ].dwFlags = CP_TYPE_TEXT | CP_MODE_ARRAY|CP_DEFAULT;
  792. cmdOptions[ OI_DEFAULT ].dwCount = 0;
  793. cmdOptions[ OI_DEFAULT ].dwActuals = 0;
  794. cmdOptions[ OI_DEFAULT ].pValue = &arrTemp;
  795. lstrcpy(cmdOptions[ OI_DEFAULT ].szValues,NULL_STRING);
  796. cmdOptions[ OI_DEFAULT ].pFunction = NULL;
  797. cmdOptions[ OI_DEFAULT ].pFunctionData = NULL;
  798. //
  799. // do the command line parsing
  800. if ( DoParseParam( argc,argv,MAX_OPTIONS,cmdOptions ) == FALSE )
  801. {
  802. ShowMessage(stderr,GetResString(IDS_ID_SHOW_ERROR));
  803. SAFEDELETE(pszTempUser);
  804. SAFEDELETE(pszTempPassword);
  805. SAFEDELETE(pszTempServer);
  806. DestroyDynamicArray(&arrTemp);
  807. return FALSE; // invalid syntax
  808. }
  809. DestroyDynamicArray(&arrTemp);//Release memory as variable no longer needed
  810. arrTemp = NULL;
  811. // Check if all of following is true is an error
  812. if((*pbUsage==TRUE)&&argc>3)
  813. {
  814. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  815. SetReason(szTemp);
  816. return FALSE;
  817. }
  818. // -query ,-disconnect and -local options cannot come together
  819. if(((*pbQuery)+(*pbDisconnect)+(*pbResetFlag))>1)
  820. {
  821. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  822. SetReason(szTemp);
  823. SAFEDELETE(pszTempUser);
  824. SAFEDELETE(pszTempPassword);
  825. SAFEDELETE(pszTempServer);
  826. return FALSE;
  827. }
  828. else if((argc == 2)&&(*pbUsage == TRUE))
  829. {
  830. // if -? alone given its a valid conmmand line
  831. SAFEDELETE(pszTempUser);
  832. SAFEDELETE(pszTempPassword);
  833. SAFEDELETE(pszTempServer);
  834. return TRUE;
  835. }
  836. if((argc>2)&& (*pbQuery==FALSE)&&(*pbDisconnect==FALSE)&&(*pbResetFlag==FALSE))
  837. {
  838. // If command line argument is equals or greater than 2 atleast one
  839. // of -query OR -local OR -disconnect should be present in it.
  840. // (for "-?" previous condition already takes care)
  841. // This to prevent from following type of command line argument:
  842. // OpnFiles.exe -nh ... Which is a invalid syntax.
  843. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  844. SetReason(szTemp);
  845. SAFEDELETE(pszTempUser);
  846. SAFEDELETE(pszTempPassword);
  847. SAFEDELETE(pszTempServer);
  848. return FALSE;
  849. }
  850. SAFEDELETE(pszTempUser);
  851. SAFEDELETE(pszTempPassword);
  852. SAFEDELETE(pszTempServer);
  853. return TRUE;
  854. }//ProcesOptions
  855. /*-----------------------------------------------------------------------------
  856. Routine Description:
  857. This function takes command line argument and checks for correct syntax and
  858. if the syntax is ok, it returns the values in different variables. variables
  859. [out] will contain respective values. This Functin specifically checks
  860. command line parameters requered for QUERY option.
  861. Arguments:
  862. [in] argc - Number of command line arguments
  863. [in] argv - Array containing command line arguments
  864. [out] pbQuery - query option string
  865. [out] pszServer - remote server name
  866. [out] pszUserName - username for the remote system
  867. [out] pszPassword - password for the remote system for the
  868. username
  869. [out] pszFormat - format checking
  870. [out] pbShowNoHeader - show header
  871. [out] pbVerbose - show verbose
  872. Returned Value:
  873. BOOL --True if it succeeds
  874. --False if it fails.
  875. -----------------------------------------------------------------------------*/
  876. BOOL
  877. ProcessOptions( DWORD argc,
  878. LPCTSTR argv[],
  879. PBOOL pbQuery,
  880. LPTSTR pszServer,
  881. LPTSTR pszUserName,
  882. LPTSTR pszPassword,
  883. LPTSTR pszFormat,
  884. PBOOL pbShowNoHeader,
  885. PBOOL pbVerbose,
  886. PBOOL pbNeedPassword)
  887. {
  888. // Check in/out parameters...
  889. if((pszServer == NULL)||(pszUserName==NULL)||(pszPassword==NULL)||
  890. (pszFormat == NULL))
  891. {
  892. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  893. DISPLAY_MESSAGE(stderr,GetResString(IDS_ID_SHOW_ERROR));
  894. return FALSE; // Memory ERROR
  895. }
  896. TCMDPARSER cmdOptions[ MAX_QUERY_OPTIONS ];//Variable to store command line
  897. CHString szTempString;
  898. TCHAR szTemp[MAX_RES_STRING*2];
  899. TCHAR szTypeHelpMsg[MAX_RES_STRING];
  900. DWORD dwRetVal = 0;
  901. szTempString = GetResString(IDS_UTILITY_NAME);
  902. wsprintf(szTemp,GetResString(IDS_INVALID_SYNTAX),(LPCWSTR)szTempString);
  903. wsprintf(szTypeHelpMsg,GetResString(IDS_TYPE_Q_HELP),(LPCWSTR)szTempString);
  904. //
  905. // prepare the command options
  906. // -query option for help
  907. cmdOptions[ OI_Q_QUERY ].dwCount = 1;
  908. cmdOptions[ OI_Q_QUERY ].dwActuals = 0;
  909. cmdOptions[ OI_Q_QUERY ].dwFlags = CP_MAIN_OPTION ;
  910. cmdOptions[ OI_Q_QUERY ].pValue = pbQuery;
  911. cmdOptions[ OI_Q_QUERY ].pFunction = NULL;
  912. cmdOptions[ OI_Q_QUERY ].pFunctionData = NULL;
  913. lstrcpy( cmdOptions[ OI_Q_QUERY ].szValues, NULL_STRING );
  914. lstrcpy( cmdOptions[ OI_Q_QUERY ].szOption, OPTION_QUERY );
  915. // -s option remote system name
  916. cmdOptions[ OI_Q_SERVER_NAME ].dwCount = 1;
  917. cmdOptions[ OI_Q_SERVER_NAME ].dwActuals = 0;
  918. cmdOptions[ OI_Q_SERVER_NAME ].dwFlags = CP_TYPE_TEXT | CP_VALUE_MANDATORY;
  919. cmdOptions[ OI_Q_SERVER_NAME ].pValue = pszServer;
  920. cmdOptions[ OI_Q_SERVER_NAME ].pFunction = NULL;
  921. cmdOptions[ OI_Q_SERVER_NAME ].pFunctionData = NULL;
  922. lstrcpy( cmdOptions[ OI_Q_SERVER_NAME ].szValues, NULL_STRING );
  923. lstrcpy( cmdOptions[ OI_Q_SERVER_NAME ].szOption, OPTION_SERVER );
  924. // -u option user name for the specified system
  925. cmdOptions[ OI_Q_USER_NAME ].dwCount = 1;
  926. cmdOptions[ OI_Q_USER_NAME ].dwActuals = 0;
  927. cmdOptions[ OI_Q_USER_NAME ].dwFlags = CP_TYPE_TEXT | CP_VALUE_MANDATORY;
  928. cmdOptions[ OI_Q_USER_NAME ].pValue = pszUserName;
  929. cmdOptions[ OI_Q_USER_NAME ].pFunction = NULL;
  930. cmdOptions[ OI_Q_USER_NAME ].pFunctionData = NULL;
  931. lstrcpy( cmdOptions[ OI_Q_USER_NAME ].szValues, NULL_STRING );
  932. lstrcpy( cmdOptions[ OI_Q_USER_NAME ].szOption, OPTION_USERNAME );
  933. // -p option password for the given username
  934. cmdOptions[ OI_Q_PASSWORD ].dwCount = 1;
  935. cmdOptions[ OI_Q_PASSWORD ].dwActuals = 0;
  936. cmdOptions[ OI_Q_PASSWORD ].dwFlags = CP_TYPE_TEXT | CP_VALUE_OPTIONAL;
  937. cmdOptions[ OI_Q_PASSWORD ].pValue = pszPassword;
  938. cmdOptions[ OI_Q_PASSWORD ].pFunction = NULL;
  939. cmdOptions[ 3 ].pFunctionData = NULL;
  940. lstrcpy( cmdOptions[ OI_Q_PASSWORD ].szValues, NULL_STRING );
  941. lstrcpy( cmdOptions[ OI_Q_PASSWORD ].szOption, OPTION_PASSWORD );
  942. // -fo (format)
  943. lstrcpy(cmdOptions[ OI_Q_FORMAT ].szOption,OPTION_FORMAT);
  944. cmdOptions[ OI_Q_FORMAT ].dwFlags = CP_TYPE_TEXT|CP_VALUE_MANDATORY
  945. |CP_MODE_VALUES;
  946. cmdOptions[ OI_Q_FORMAT ].dwCount = 1;
  947. cmdOptions[ OI_Q_FORMAT ].dwActuals = 0;
  948. cmdOptions[ OI_Q_FORMAT ].pValue = pszFormat;
  949. lstrcpy(cmdOptions[ OI_Q_FORMAT ].szValues,FORMAT_OPTIONS);
  950. cmdOptions[ OI_Q_FORMAT ].pFunction = NULL;
  951. cmdOptions[ OI_Q_FORMAT ].pFunctionData = NULL;
  952. //-nh (noheader)
  953. lstrcpy(cmdOptions[ OI_Q_NO_HEADER ].szOption,OPTION_NOHEADER);
  954. cmdOptions[ OI_Q_NO_HEADER ].dwFlags = 0;
  955. cmdOptions[ OI_Q_NO_HEADER ].dwCount = 1;
  956. cmdOptions[ OI_Q_NO_HEADER ].dwActuals = 0;
  957. cmdOptions[ OI_Q_NO_HEADER ].pValue = pbShowNoHeader;
  958. lstrcpy(cmdOptions[ OI_Q_NO_HEADER ].szValues,NULL_STRING);
  959. cmdOptions[ OI_Q_NO_HEADER ].pFunction = NULL;
  960. cmdOptions[ OI_Q_NO_HEADER ].pFunctionData = NULL;
  961. //-v verbose
  962. lstrcpy(cmdOptions[ OI_Q_VERBOSE ].szOption,OPTION_VERBOSE);
  963. cmdOptions[ OI_Q_VERBOSE ].dwFlags = 0;
  964. cmdOptions[ OI_Q_VERBOSE ].dwCount = 1;
  965. cmdOptions[ OI_Q_VERBOSE ].dwActuals = 0;
  966. cmdOptions[ OI_Q_VERBOSE ].pValue = pbVerbose;
  967. lstrcpy(cmdOptions[ OI_Q_VERBOSE].szValues,NULL_STRING);
  968. cmdOptions[ OI_Q_VERBOSE ].pFunction = NULL;
  969. cmdOptions[ OI_Q_VERBOSE ].pFunctionData = NULL;
  970. // init the password with '*'
  971. if ( pszPassword != NULL )
  972. lstrcpy( pszPassword, _T( "*" ) );
  973. //
  974. // do the command line parsing
  975. if ( DoParseParam( argc,argv,MAX_QUERY_OPTIONS,cmdOptions ) == FALSE )
  976. {
  977. ShowMessage(stderr,GetResString(IDS_ID_SHOW_ERROR));
  978. return FALSE; // invalid syntax
  979. }
  980. // -n is allowed only with -fo TABLE (which is also default)
  981. // and CSV
  982. if((*pbShowNoHeader == TRUE) &&
  983. ((lstrcmpi(pszFormat,GetResString(IDS_LIST))==0)))
  984. {
  985. lstrcpy(szTemp,GetResString(IDS_HEADER_NOT_ALLOWED));
  986. lstrcat(szTemp,szTypeHelpMsg);
  987. SetReason(szTemp);
  988. return FALSE;
  989. }
  990. // "-p" should not be specified without "-u"
  991. if ( cmdOptions[ OI_Q_USER_NAME ].dwActuals == 0 &&
  992. cmdOptions[ OI_Q_PASSWORD ].dwActuals != 0 )
  993. {
  994. // invalid syntax
  995. lstrcpy(szTemp,ERROR_PASSWORD_BUT_NOUSERNAME );
  996. lstrcat(szTemp,szTypeHelpMsg);
  997. SetReason(szTemp);
  998. return FALSE; // indicate failure
  999. }
  1000. if(*pbQuery==FALSE)
  1001. {
  1002. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  1003. SetReason(szTemp);
  1004. return FALSE;
  1005. }
  1006. // "-u" should not be specified without "-s"
  1007. if ( cmdOptions[ OI_Q_SERVER_NAME ].dwActuals == 0 &&
  1008. cmdOptions[ OI_Q_USER_NAME ].dwActuals != 0 )
  1009. {
  1010. // invalid syntax
  1011. lstrcpy(szTemp,ERROR_USERNAME_BUT_NOMACHINE);
  1012. lstrcat(szTemp,szTypeHelpMsg);
  1013. SetReason(szTemp);
  1014. return FALSE; // indicate failure
  1015. }
  1016. szTempString = pszServer;
  1017. szTempString.TrimRight();
  1018. lstrcpy(pszServer,(LPCWSTR)szTempString);
  1019. // server name with 0 length is invalid.
  1020. if((cmdOptions[ OI_Q_SERVER_NAME ].dwActuals != 0) &&
  1021. (lstrlen(pszServer)==0))
  1022. {
  1023. lstrcpy(szTemp,GetResString(IDS_SERVER_EMPTY));
  1024. lstrcat(szTemp,szTypeHelpMsg);
  1025. SetReason(szTemp);
  1026. return FALSE;
  1027. }
  1028. // server name with 0 length is invalid.
  1029. szTempString = pszUserName;
  1030. szTempString.TrimRight();
  1031. lstrcpy(pszUserName,(LPCWSTR)szTempString);
  1032. if((cmdOptions[ OI_Q_USER_NAME ].dwActuals != 0) &&
  1033. (lstrlen(pszUserName)==0))
  1034. {
  1035. lstrcpy(szTemp,GetResString(IDS_USERNAME_EMPTY));
  1036. lstrcat(szTemp,szTypeHelpMsg);
  1037. SetReason(szTemp);
  1038. return FALSE;
  1039. }
  1040. // user given -p option and not given password
  1041. // so it is needed to prompt for password.
  1042. if ( cmdOptions[ OI_Q_PASSWORD ].dwActuals != 0 &&
  1043. pszPassword != NULL && lstrcmp( pszPassword, _T( "*" ) ) == 0 )
  1044. {
  1045. // user wants the utility to prompt for the password before trying to connect
  1046. *pbNeedPassword = TRUE;
  1047. }
  1048. else if ( cmdOptions[ OI_Q_PASSWORD ].dwActuals == 0 &&
  1049. ( cmdOptions[ OI_Q_SERVER_NAME ].dwActuals != 0 || cmdOptions[ OI_Q_USER_NAME ].dwActuals != 0 ) )
  1050. {
  1051. // -s, -u is specified without password ...
  1052. // utility needs to try to connect first and if it fails then prompt for the password
  1053. *pbNeedPassword = TRUE;
  1054. if ( pszPassword != NULL )
  1055. {
  1056. lstrcpy( pszPassword, _T( "" ) );
  1057. }
  1058. }
  1059. return TRUE;
  1060. }
  1061. /*-----------------------------------------------------------------------------
  1062. Routine Description:
  1063. This function takes command line argument and checks for correct syntax and
  1064. if the syntax is ok, it returns the values in different variables. variables
  1065. [out] will contain respective values. This Functin specifically checks
  1066. command line parameters requered for DISCONNECT option.
  1067. Arguments:
  1068. [in] argc - Number of command line arguments
  1069. [in] argv - Array containing command line arguments
  1070. [out] pbDisconnect - discoonect option string
  1071. [out] pszServer - remote server name
  1072. [out] pszUserName - username for the remote system
  1073. [out] pszPassword - password for the remote system for the
  1074. username
  1075. [out] pszID - Open file ids
  1076. [out] pszAccessedby - Name of user name who access the file
  1077. [out] pszOpenmode - accessed mode (read/Write)
  1078. [out] pszOpenFile - Open file name
  1079. Returned Value:
  1080. BOOL --True if it succeeds
  1081. --False if it fails.
  1082. -----------------------------------------------------------------------------*/
  1083. BOOL
  1084. ProcessOptions( DWORD argc,
  1085. LPCTSTR argv[],
  1086. PBOOL pbDisconnect,
  1087. LPTSTR pszServer,
  1088. LPTSTR pszUserName,
  1089. LPTSTR pszPassword,
  1090. LPTSTR pszID,
  1091. LPTSTR pszAccessedby,
  1092. LPTSTR pszOpenmode,
  1093. LPTSTR pszOpenFile,
  1094. PBOOL pbNeedPassword)
  1095. {
  1096. // Check in/out parameters...
  1097. if((pszServer == NULL)||(pszUserName==NULL)||(pszPassword==NULL)||
  1098. (pszID == NULL)||(pszAccessedby==NULL)|| (pszAccessedby == NULL)||
  1099. (pszOpenmode == NULL)||(pszOpenFile==NULL))
  1100. {
  1101. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1102. DISPLAY_MESSAGE(stderr,GetResString(IDS_ID_SHOW_ERROR));
  1103. return FALSE; // Memory ERROR
  1104. }
  1105. TCMDPARSER cmdOptions[ MAX_DISCONNECT_OPTIONS ];//Variable to store command line
  1106. CHString szTempString;
  1107. TCHAR szTemp[MAX_RES_STRING*2];
  1108. TCHAR szTypeHelpMsg[MAX_RES_STRING];
  1109. DWORD dwRetVal = 0;
  1110. szTempString = GetResString(IDS_UTILITY_NAME);
  1111. wsprintf(szTemp,GetResString(IDS_INVALID_SYNTAX),(LPCWSTR)szTempString);
  1112. wsprintf(szTypeHelpMsg,GetResString(IDS_TYPE_D_HELP),(LPCWSTR)szTempString);
  1113. //
  1114. // prepare the command options
  1115. // -disconnect option for help
  1116. cmdOptions[ OI_D_DISCONNECT ].dwCount = 1;
  1117. cmdOptions[ OI_D_DISCONNECT ].dwActuals = 0;
  1118. cmdOptions[ OI_D_DISCONNECT ].dwFlags = CP_MAIN_OPTION ;
  1119. cmdOptions[ OI_D_DISCONNECT ].pValue = pbDisconnect;
  1120. cmdOptions[ OI_D_DISCONNECT ].pFunction = NULL;
  1121. cmdOptions[ OI_D_DISCONNECT ].pFunctionData = NULL;
  1122. lstrcpy( cmdOptions[ OI_D_DISCONNECT ].szValues, NULL_STRING );
  1123. lstrcpy( cmdOptions[ OI_D_DISCONNECT ].szOption, OPTION_DISCONNECT );
  1124. // -s option remote system name
  1125. cmdOptions[ OI_D_SERVER_NAME ].dwCount = 1;
  1126. cmdOptions[ OI_D_SERVER_NAME ].dwActuals = 0;
  1127. cmdOptions[ OI_D_SERVER_NAME ].dwFlags = CP_TYPE_TEXT | CP_VALUE_MANDATORY;
  1128. cmdOptions[ OI_D_SERVER_NAME ].pValue = pszServer;
  1129. cmdOptions[ OI_D_SERVER_NAME ].pFunction = NULL;
  1130. cmdOptions[ OI_D_SERVER_NAME ].pFunctionData = NULL;
  1131. lstrcpy( cmdOptions[ OI_D_SERVER_NAME ].szValues, NULL_STRING );
  1132. lstrcpy( cmdOptions[ OI_D_SERVER_NAME ].szOption, OPTION_SERVER );
  1133. // -u option user name for the specified system
  1134. cmdOptions[ OI_D_USER_NAME ].dwCount = 1;
  1135. cmdOptions[ OI_D_USER_NAME ].dwActuals = 0;
  1136. cmdOptions[ OI_D_USER_NAME ].dwFlags = CP_TYPE_TEXT | CP_VALUE_MANDATORY;
  1137. cmdOptions[ OI_D_USER_NAME ].pValue = pszUserName;
  1138. cmdOptions[ OI_D_USER_NAME ].pFunction = NULL;
  1139. cmdOptions[ OI_D_USER_NAME ].pFunctionData = NULL;
  1140. lstrcpy( cmdOptions[ OI_D_USER_NAME ].szValues, NULL_STRING );
  1141. lstrcpy( cmdOptions[ OI_D_USER_NAME ].szOption, OPTION_USERNAME );
  1142. // -p option password for the given username
  1143. cmdOptions[ OI_D_PASSWORD ].dwCount = 1;
  1144. cmdOptions[ OI_D_PASSWORD ].dwActuals = 0;
  1145. cmdOptions[ OI_D_PASSWORD ].dwFlags = CP_TYPE_TEXT | CP_VALUE_OPTIONAL;
  1146. cmdOptions[ OI_D_PASSWORD ].pValue = pszPassword;
  1147. cmdOptions[ OI_D_PASSWORD ].pFunction = NULL;
  1148. cmdOptions[ OI_D_PASSWORD ].pFunctionData = NULL;
  1149. lstrcpy( cmdOptions[ OI_D_PASSWORD ].szValues, NULL_STRING );
  1150. lstrcpy( cmdOptions[ OI_D_PASSWORD ].szOption, OPTION_PASSWORD );
  1151. // -id Values
  1152. cmdOptions[ OI_D_ID ].dwCount = 1;
  1153. cmdOptions[ OI_D_ID ].dwActuals = 0;
  1154. cmdOptions[ OI_D_ID ].dwFlags = CP_TYPE_TEXT | CP_VALUE_MANDATORY;
  1155. cmdOptions[ OI_D_ID ].pValue = pszID;
  1156. cmdOptions[ OI_D_ID ].pFunction = NULL;
  1157. cmdOptions[ OI_D_ID ].pFunctionData = NULL;
  1158. lstrcpy( cmdOptions[ OI_D_ID ].szValues, NULL_STRING );
  1159. lstrcpy( cmdOptions[ OI_D_ID ].szOption, OPTION_ID );
  1160. // -a (accessed by)
  1161. cmdOptions[ OI_D_ACCESSED_BY ].dwCount = 1;
  1162. cmdOptions[ OI_D_ACCESSED_BY ].dwActuals = 0;
  1163. cmdOptions[ OI_D_ACCESSED_BY ].dwFlags = CP_TYPE_TEXT | CP_VALUE_MANDATORY;;
  1164. cmdOptions[ OI_D_ACCESSED_BY ].pValue = pszAccessedby;
  1165. cmdOptions[ OI_D_ACCESSED_BY].pFunction = NULL;
  1166. cmdOptions[ OI_D_ACCESSED_BY ].pFunctionData = NULL;
  1167. lstrcpy( cmdOptions[ OI_D_ACCESSED_BY ].szValues, NULL_STRING );
  1168. lstrcpy( cmdOptions[ OI_D_ACCESSED_BY ].szOption, OPTION_ACCESSEDBY );
  1169. // -o (openmode)
  1170. cmdOptions[ OI_D_OPEN_MODE ].dwCount = 1;
  1171. cmdOptions[ OI_D_OPEN_MODE].dwActuals = 0;
  1172. cmdOptions[ OI_D_OPEN_MODE ].dwFlags = CP_VALUE_MANDATORY | CP_MODE_VALUES|
  1173. CP_TYPE_TEXT;
  1174. cmdOptions[ OI_D_OPEN_MODE ].pValue = pszOpenmode;
  1175. cmdOptions[ OI_D_OPEN_MODE ].pFunction = NULL;
  1176. cmdOptions[ OI_D_OPEN_MODE ].pFunctionData = NULL;
  1177. lstrcpy(cmdOptions[ OI_D_OPEN_MODE ].szValues,GetResString(IDS_OPENMODE_OPTION));
  1178. lstrcpy(cmdOptions[ OI_D_OPEN_MODE ].szOption, OPTION_OPENMODE );
  1179. // -op (openfile)
  1180. cmdOptions[ OI_D_OPEN_FILE ].dwCount = 1;
  1181. cmdOptions[ OI_D_OPEN_FILE ].dwActuals = 0;
  1182. cmdOptions[ OI_D_OPEN_FILE ].dwFlags = CP_TYPE_TEXT | CP_VALUE_MANDATORY;;
  1183. cmdOptions[ OI_D_OPEN_FILE ].pValue = pszOpenFile;
  1184. cmdOptions[ OI_D_OPEN_FILE ].pFunction = NULL;
  1185. cmdOptions[ OI_D_OPEN_FILE ].pFunctionData = NULL;
  1186. lstrcpy( cmdOptions[ OI_D_OPEN_FILE ].szValues, NULL_STRING );
  1187. lstrcpy( cmdOptions[ OI_D_OPEN_FILE ].szOption, OPTION_OPENFILE );
  1188. // init the passsword variable with '*'
  1189. if ( pszPassword != NULL )
  1190. lstrcpy( pszPassword, _T( "*" ) );
  1191. //
  1192. // do the command line parsing
  1193. if ( DoParseParam( argc,argv,MAX_DISCONNECT_OPTIONS ,cmdOptions ) == FALSE )
  1194. {
  1195. ShowMessage(stderr,GetResString(IDS_ID_SHOW_ERROR));
  1196. return FALSE; // invalid syntax
  1197. }
  1198. if(*pbDisconnect==FALSE)
  1199. {
  1200. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  1201. SetReason(szTemp);
  1202. return FALSE;
  1203. }
  1204. // At least one of -id OR -a OR -o is required.
  1205. if((cmdOptions[ OI_D_ID ].dwActuals==0)&&
  1206. (cmdOptions[ OI_D_ACCESSED_BY ].dwActuals==0)&&
  1207. (cmdOptions[ OI_D_OPEN_MODE ].dwActuals==0)
  1208. )
  1209. {
  1210. lstrcpy(szTemp,GetResString(IDS_NO_ID_ACC_OF));
  1211. lstrcat(szTemp,szTypeHelpMsg);
  1212. SetReason(szTemp);
  1213. return FALSE;
  1214. }
  1215. // "-u" should not be specified without "-s"
  1216. if ( cmdOptions[ OI_D_SERVER_NAME ].dwActuals == 0 &&
  1217. cmdOptions[ OI_D_USER_NAME ].dwActuals != 0 )
  1218. {
  1219. // invalid syntax
  1220. lstrcpy(szTemp,ERROR_USERNAME_BUT_NOMACHINE);
  1221. lstrcat(szTemp,szTypeHelpMsg);
  1222. SetReason(szTemp);
  1223. return FALSE; // indicate failure
  1224. }
  1225. // "-p" should not be specified without "-u"
  1226. if ( cmdOptions[ OI_D_USER_NAME ].dwActuals == 0 &&
  1227. cmdOptions[ OI_D_PASSWORD ].dwActuals != 0 )
  1228. {
  1229. // invalid syntax
  1230. lstrcpy(szTemp,ERROR_PASSWORD_BUT_NOUSERNAME );
  1231. lstrcat(szTemp,szTypeHelpMsg);
  1232. SetReason(szTemp);
  1233. return FALSE; // indicate failure
  1234. }
  1235. szTempString = pszServer;
  1236. szTempString.TrimRight();
  1237. lstrcpy(pszServer,(LPCWSTR)szTempString);
  1238. // server name with 0 length is invalid.
  1239. if((cmdOptions[ OI_D_SERVER_NAME ].dwActuals != 0) &&
  1240. (lstrlen(pszServer)==0))
  1241. {
  1242. lstrcpy(szTemp,GetResString(IDS_SERVER_EMPTY));
  1243. lstrcat(szTemp,szTypeHelpMsg);
  1244. SetReason(szTemp);
  1245. return FALSE;
  1246. }
  1247. // server name with 0 length is invalid.
  1248. szTempString = pszUserName;
  1249. szTempString.TrimRight();
  1250. lstrcpy(pszUserName,(LPCWSTR)szTempString);
  1251. if((cmdOptions[ OI_D_USER_NAME ].dwActuals != 0) &&
  1252. (lstrlen(pszUserName)==0))
  1253. {
  1254. lstrcpy(szTemp,GetResString(IDS_USERNAME_EMPTY));
  1255. lstrcat(szTemp,szTypeHelpMsg);
  1256. SetReason(szTemp);
  1257. return FALSE;
  1258. }
  1259. // user given -p option and not given password
  1260. // so it is needed to prompt for password.
  1261. if ( cmdOptions[ OI_D_PASSWORD ].dwActuals != 0 &&
  1262. pszPassword != NULL && lstrcmp( pszPassword, _T( "*" ) ) == 0 )
  1263. {
  1264. // user wants the utility to prompt for the password before trying to connect
  1265. *pbNeedPassword = TRUE;
  1266. }
  1267. else if ( cmdOptions[ OI_D_PASSWORD ].dwActuals == 0 &&
  1268. ( cmdOptions[ OI_D_SERVER_NAME ].dwActuals != 0 || cmdOptions[ OI_D_USER_NAME ].dwActuals != 0 ) )
  1269. {
  1270. // -s, -u is specified without password ...
  1271. // utility needs to try to connect first and if it fails then prompt for the password
  1272. *pbNeedPassword = TRUE;
  1273. if ( pszPassword != NULL )
  1274. {
  1275. lstrcpy( pszPassword, _T( "" ) );
  1276. }
  1277. }
  1278. // Check if Accessed by is not given as and empty string
  1279. // or a string having only spaces....
  1280. szTempString = pszAccessedby;
  1281. szTempString.TrimRight();
  1282. lstrcpy(pszAccessedby,(LPCWSTR)szTempString);
  1283. if((cmdOptions[ OI_D_ACCESSED_BY ].dwActuals != 0) &&
  1284. (lstrlen(pszAccessedby) == 0))
  1285. {
  1286. lstrcpy(szTemp,GetResString(IDS_ACCESSBY_EMPTY));
  1287. lstrcat(szTemp,szTypeHelpMsg);
  1288. SetReason(szTemp);
  1289. return FALSE;
  1290. }
  1291. // Check if Open File is not given as and empty string
  1292. // or a string having only spaces....
  1293. szTempString = pszOpenFile;
  1294. szTempString.TrimRight();
  1295. lstrcpy(pszOpenFile,(LPCWSTR)szTempString);
  1296. if((cmdOptions[ OI_D_OPEN_FILE ].dwActuals != 0) &&
  1297. (lstrlen(pszOpenFile) == 0))
  1298. {
  1299. lstrcpy(szTemp,GetResString(IDS_OPEN_FILE_EMPTY));
  1300. lstrcat(szTemp,szTypeHelpMsg);
  1301. SetReason(szTemp);
  1302. return FALSE;
  1303. }
  1304. // Check if -id option is given and if it is numeric ,
  1305. // also if it is numeric then check its range
  1306. if((IsNumeric((LPCTSTR)pszID,10,TRUE)==TRUE)&&
  1307. (cmdOptions[ OI_D_ID ].dwActuals==1))
  1308. {
  1309. if((AsLong((LPCTSTR)pszID,10)>UINT_MAX) ||
  1310. (AsLong((LPCTSTR)pszID,10)<1))
  1311. {
  1312. // Message shown on screen will be...
  1313. // ERROR: Invlid ID.
  1314. lstrcpy(szTemp,GetResString(IDS_ERROR_ID));
  1315. lstrcat(szTemp,szTypeHelpMsg);
  1316. SetReason(szTemp);
  1317. return FALSE;
  1318. }
  1319. }
  1320. // check user given "*" or any junk string....
  1321. if(!((lstrcmp((LPCTSTR)pszID,ASTERIX)==0)||
  1322. (IsNumeric((LPCTSTR)pszID,10,TRUE)==TRUE))
  1323. &&(lstrlen((LPCTSTR)pszID)!=0))
  1324. {
  1325. // Message shown on screen will be...
  1326. // ERROR: Invlid ID.
  1327. lstrcpy(szTemp,GetResString(IDS_ERROR_ID));
  1328. lstrcat(szTemp,szTypeHelpMsg);
  1329. SetReason(szTemp);
  1330. return FALSE;
  1331. }
  1332. return TRUE;
  1333. }
  1334. /*-----------------------------------------------------------------------------
  1335. Routine Description:
  1336. Displays how to use -disconnect option
  1337. Arguments:
  1338. None
  1339. Returned Value:
  1340. None
  1341. -----------------------------------------------------------------------------*/
  1342. VOID
  1343. DisconnectUsage()
  1344. {
  1345. // local variables
  1346. DWORD dw = 0;
  1347. // start displaying the usage
  1348. for( dw = IDS_HELP_LINE1; dw <= IDS_HELP_LINE_END; dw++ )
  1349. ShowMessage( stdout, GetResString( dw ) );
  1350. }//DisconnectUsage
  1351. /*-----------------------------------------------------------------------------
  1352. Routine Description:
  1353. Displays how to use -query option
  1354. Arguments:
  1355. None
  1356. Returned Value:
  1357. None
  1358. -----------------------------------------------------------------------------*/
  1359. VOID
  1360. QueryUsage()
  1361. {
  1362. // local variables
  1363. DWORD dw = 0;
  1364. // start displaying the usage
  1365. for( dw = IDS_HELP_QUERY1; dw <= IDS_HELP_QUERY_END; dw++ )
  1366. ShowMessage( stdout, GetResString( dw ) );
  1367. }//query Usage
  1368. /*-----------------------------------------------------------------------------
  1369. Routine Description:
  1370. Displays how to use this Utility
  1371. Arguments:
  1372. None
  1373. Returned Value:
  1374. None
  1375. -----------------------------------------------------------------------------*/
  1376. VOID
  1377. Usage()
  1378. {
  1379. // local variables
  1380. DWORD dw = 0;
  1381. // start displaying the usage
  1382. for( dw = IDS_HELP_MAIN1; dw <= IDS_HELP_MAIN_END; dw++ )
  1383. ShowMessage( stdout, GetResString( dw ) );
  1384. }//Usage
  1385. /*-----------------------------------------------------------------------------
  1386. Routine Description:
  1387. Displays how to use -local option
  1388. Arguments:
  1389. None
  1390. Returned Value:
  1391. None
  1392. -----------------------------------------------------------------------------*/
  1393. VOID
  1394. LocalUsage()
  1395. {
  1396. // local variables
  1397. DWORD dw = 0;
  1398. // start displaying the usage
  1399. for( dw = IDS_HELP_LOCAL1; dw <= IDS_HELP_LOCAL_END; dw++ )
  1400. ShowMessage( stdout, GetResString( dw ) );
  1401. }//-local
  1402. /*-----------------------------------------------------------------------------
  1403. Routine Description:
  1404. Arguments:
  1405. Returned Value:
  1406. None
  1407. -----------------------------------------------------------------------------*/
  1408. DWORD CheckSystemType(LPTSTR szServer)
  1409. {
  1410. DWORD dwSystemType = 0 ;
  1411. #ifndef _WIN64
  1412. //display the error message if the target system is a 64 bit system or if error occured in
  1413. //retreiving the information
  1414. dwSystemType = GetCPUInfo(szServer);
  1415. if(dwSystemType == ERROR_RETREIVE_REGISTRY)
  1416. {
  1417. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_SYSTEM_INFO));
  1418. return (EXIT_FAILURE);
  1419. }
  1420. if(dwSystemType == SYSTEM_64_BIT)
  1421. {
  1422. if(lstrlen(szServer)== 0 )
  1423. {
  1424. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_VERSION_MISMATCH));
  1425. }
  1426. else
  1427. {
  1428. DISPLAY_MESSAGE(stderr,GetResString(IDS_REMOTE_NOT_SUPPORTED));
  1429. }
  1430. return (EXIT_FAILURE);
  1431. }
  1432. #endif
  1433. return EXIT_SUCCESS ;
  1434. }
  1435. // ***************************************************************************
  1436. // Name : GetCPUInfo
  1437. // Routine Description : determines if the computer is 32 bit system or 64 bit
  1438. // Arguments :
  1439. // [ in ] szComputerName : System name
  1440. // Return Type : BOOL
  1441. // TRUE : if the system is a 32 bit system
  1442. // FALSE : if the system is a 64 bit system
  1443. // ***************************************************************************
  1444. DWORD GetCPUInfo(LPTSTR szComputerName)
  1445. {
  1446. HKEY hKey1 = 0;
  1447. HKEY hRemoteKey = 0;
  1448. TCHAR szCurrentPath[MAX_STRING_LENGTH + 1] = NULL_STRING;
  1449. TCHAR szPath[MAX_STRING_LENGTH + 1] = SUBKEY ;
  1450. DWORD dwValueSize = MAX_STRING_LENGTH + 1;
  1451. DWORD dwRetCode = ERROR_SUCCESS;
  1452. DWORD dwError = 0;
  1453. TCHAR szTmpCompName[MAX_STRING_LENGTH+1] = NULL_STRING;
  1454. TCHAR szTemp[MAX_RES_STRING+1] = NULL_STRING ;
  1455. DWORD len = lstrlen(szTemp);
  1456. TCHAR szVal[MAX_RES_STRING+1] = NULL_STRING ;
  1457. DWORD dwLength = MAX_STRING_LENGTH ;
  1458. LPTSTR szReturnValue = NULL ;
  1459. DWORD dwCode = 0 ;
  1460. szReturnValue = ( LPTSTR ) malloc( dwLength*sizeof( TCHAR ) );
  1461. if(szReturnValue == NULL)
  1462. {
  1463. return ERROR_RETREIVE_REGISTRY ;
  1464. }
  1465. if(lstrlen(szComputerName)!= 0 )
  1466. {
  1467. lstrcpy(szTmpCompName,TOKEN_BACKSLASH4);
  1468. lstrcat(szTmpCompName,szComputerName);
  1469. }
  1470. else
  1471. {
  1472. lstrcpy(szTmpCompName,szComputerName);
  1473. }
  1474. // Get Remote computer local machine key
  1475. dwError = RegConnectRegistry(szTmpCompName,HKEY_LOCAL_MACHINE,&hRemoteKey);
  1476. if (dwError == ERROR_SUCCESS)
  1477. {
  1478. dwError = RegOpenKeyEx(hRemoteKey,szPath,0,KEY_READ,&hKey1);
  1479. if (dwError == ERROR_SUCCESS)
  1480. {
  1481. dwRetCode = RegQueryValueEx(hKey1, IDENTIFIER_VALUE, NULL, NULL,(LPBYTE) szReturnValue, &dwValueSize);
  1482. if (dwRetCode == ERROR_MORE_DATA)
  1483. {
  1484. szReturnValue = ( LPTSTR ) realloc( szReturnValue , dwValueSize * sizeof( TCHAR ) );
  1485. dwRetCode = RegQueryValueEx(hKey1, IDENTIFIER_VALUE, NULL, NULL,(LPBYTE) szReturnValue, &dwValueSize);
  1486. }
  1487. if(dwRetCode != ERROR_SUCCESS)
  1488. {
  1489. RegCloseKey(hKey1);
  1490. RegCloseKey(hRemoteKey);
  1491. return ERROR_RETREIVE_REGISTRY ;
  1492. }
  1493. }
  1494. else
  1495. {
  1496. RegCloseKey(hRemoteKey);
  1497. return ERROR_RETREIVE_REGISTRY ;
  1498. }
  1499. RegCloseKey(hKey1);
  1500. }
  1501. else
  1502. {
  1503. RegCloseKey(hRemoteKey);
  1504. return ERROR_RETREIVE_REGISTRY ;
  1505. }
  1506. RegCloseKey(hRemoteKey);
  1507. lstrcpy(szVal,X86_MACHINE);
  1508. //check if the specified system contains the words x86 (belongs to the 32 )
  1509. // set the flag to true if the specified system is 64 bit .
  1510. if( !_tcsstr(szReturnValue,szVal))
  1511. {
  1512. dwCode = SYSTEM_64_BIT ;
  1513. }
  1514. else
  1515. {
  1516. dwCode = SYSTEM_32_BIT ;
  1517. }
  1518. SAFEFREE(szReturnValue);
  1519. return dwCode ;
  1520. }//GetCPUInfo
  1521. /*-----------------------------------------------------------------------------
  1522. Routine Description:
  1523. Arguments:
  1524. Returned Value:
  1525. None
  1526. -----------------------------------------------------------------------------*/
  1527. DWORD CheckSystemType64(LPTSTR szServer)
  1528. {
  1529. DWORD dwSystemType = 0 ;
  1530. #ifdef _WIN64
  1531. //display the error message if the target system is a 64 bit system or if error occured in
  1532. //retreiving the information
  1533. dwSystemType = GetCPUInfo(szServer);
  1534. if(dwSystemType == ERROR_RETREIVE_REGISTRY)
  1535. {
  1536. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_SYSTEM_INFO));
  1537. return (EXIT_FAILURE);
  1538. }
  1539. if(dwSystemType == SYSTEM_32_BIT)
  1540. {
  1541. if(lstrlen(szServer)== 0 )
  1542. {
  1543. DISPLAY_MESSAGE(stderr,GetResString(IDS_ERROR_VERSION_MISMATCH1));
  1544. }
  1545. else
  1546. {
  1547. DISPLAY_MESSAGE(stderr,GetResString(IDS_REMOTE_NOT_SUPPORTED1));
  1548. }
  1549. return (EXIT_FAILURE);
  1550. }
  1551. #endif
  1552. return EXIT_SUCCESS ;
  1553. }