Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2278 lines
78 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 X86_MACHINE _T("x86")
  25. #define SYSTEM_64_BIT 2
  26. #define SYSTEM_32_BIT 3
  27. BOOL g_bIs32BitEnv = TRUE ;
  28. // Fuction protorypes. These functions will be used only in current file.
  29. DWORD
  30. GetCPUInfo(
  31. IN LPTSTR szComputerName
  32. );
  33. DWORD
  34. CheckSystemType(
  35. IN LPTSTR szServer
  36. );
  37. DWORD
  38. CheckSystemType64(
  39. IN LPTSTR szServer
  40. );
  41. BOOL
  42. ProcessQuery(
  43. IN DWORD argc,
  44. IN LPCTSTR argv[]
  45. )throw (CHeap_Exception);
  46. BOOL
  47. ProcessDisconnect(
  48. IN DWORD argc,
  49. IN LPCTSTR argv[]
  50. ) throw (CHeap_Exception);
  51. BOOL
  52. ProcessLocal(
  53. IN DWORD argc,
  54. IN LPCTSTR argv[]
  55. );
  56. BOOL
  57. ProcessOptions(
  58. IN DWORD argc,
  59. IN LPCTSTR argv[],
  60. OUT PBOOL pbDisconnect,
  61. OUT PBOOL pbQuery,
  62. OUT PBOOL pbUsage,
  63. OUT PBOOL pbResetFlag
  64. );
  65. BOOL
  66. ProcessOptions(
  67. IN DWORD argc,
  68. IN LPCTSTR argv[],
  69. OUT PBOOL pbQuery,
  70. OUT LPTSTR* pszServer,
  71. OUT LPTSTR* pszUserName,
  72. OUT LPTSTR* pszPassword,
  73. OUT LPTSTR* pszFormat,
  74. OUT PBOOL pbShowNoHeader,
  75. OUT PBOOL pbVerbose,
  76. OUT PBOOL pbNeedPassword
  77. );
  78. BOOL
  79. ProcessOptions(
  80. IN DWORD argc,
  81. IN LPCTSTR argv[],
  82. OUT PBOOL pbDisconnect,
  83. OUT LPTSTR* pszServer,
  84. OUT LPTSTR* pszUserName,
  85. OUT LPTSTR* pszPassword,
  86. OUT LPTSTR* pszID,
  87. OUT LPTSTR* pszAccessedby,
  88. OUT LPTSTR* pszOpenmode,
  89. OUT LPTSTR* pszOpenFile,
  90. OUT PBOOL pbNeedPassword
  91. );
  92. BOOL
  93. ProcessOptions(
  94. IN DWORD argc,
  95. IN LPCTSTR argv[],
  96. OUT LPTSTR* pszLocalValue
  97. );
  98. BOOL
  99. Usage(
  100. VOID
  101. );
  102. BOOL
  103. DisconnectUsage(
  104. VOID
  105. );
  106. BOOL
  107. QueryUsage(
  108. VOID
  109. );
  110. BOOL
  111. LocalUsage(
  112. VOID
  113. );
  114. // Function implimentation
  115. DWORD _cdecl
  116. _tmain(
  117. IN DWORD argc,
  118. IN LPCTSTR argv[]
  119. )
  120. /*++
  121. Routine Description:
  122. Main routine that calls the disconnect and query options
  123. Arguments:
  124. [in] argc - Number of command line arguments.
  125. [in] argv - Array containing command line arguments.
  126. Returned Value:
  127. DWORD - 0 for success exit
  128. - 1 for failure exit
  129. --*/
  130. {
  131. BOOL bCleanExit = FALSE;
  132. try{
  133. // local variables to this function
  134. BOOL bResult = TRUE;
  135. // variables to hold the values specified at the command prompt
  136. // -? ( help )
  137. BOOL bUsage = FALSE;
  138. // -disconnect
  139. BOOL bDisconnect = FALSE;
  140. //query command line options
  141. // -query
  142. BOOL bQuery = FALSE;
  143. BOOL bRestFlag = FALSE;
  144. DWORD dwRetVal = 0;
  145. #ifndef _WIN64
  146. dwRetVal = CheckSystemType( L"\0");
  147. if(dwRetVal!=EXIT_SUCCESS )
  148. {
  149. return EXIT_FAILURE;
  150. }
  151. #endif
  152. // if no command line argument is given than -query option
  153. // is takan by default.
  154. if(1 == argc)
  155. {
  156. if(IsWin2KOrLater()==FALSE)
  157. {
  158. ShowMessage(stderr,GetResString(IDS_INVALID_OS));
  159. bCleanExit = FALSE;
  160. }
  161. else
  162. {
  163. if ( FALSE == IsUserAdmin())
  164. {
  165. ShowMessage(stderr,GetResString(IDS_USER_NOT_ADMIN));
  166. bCleanExit = FALSE;
  167. }
  168. else
  169. {
  170. bCleanExit = DoQuery(L"\0",FALSE,L"\0",FALSE);
  171. }
  172. }
  173. }
  174. else
  175. {
  176. // process and validate the command line options
  177. bResult = ProcessOptions( argc,
  178. argv,
  179. &bDisconnect,
  180. &bQuery,
  181. &bUsage,
  182. &bRestFlag);
  183. if( TRUE == bResult)
  184. {
  185. // check if -? is given as parameter.
  186. if( TRUE == bUsage )
  187. {
  188. //check if -create is also given.
  189. if( TRUE == bQuery)
  190. {
  191. // show usage for -create option.
  192. bCleanExit = QueryUsage();
  193. }
  194. //check if -disconnect is also given.
  195. else if ( TRUE == bDisconnect)
  196. {
  197. //Show usage for -disconnect option.
  198. bCleanExit = DisconnectUsage();
  199. }
  200. //check if -disconnect is also given.
  201. else if ( TRUE == bRestFlag)
  202. {
  203. //Show usage for -local option.
  204. bCleanExit = LocalUsage();
  205. }
  206. else
  207. {
  208. //as no -create Or -disconnect given, show main usage.
  209. bCleanExit = Usage();
  210. }
  211. }
  212. else
  213. {
  214. if( TRUE == bRestFlag)
  215. {
  216. // Process command line parameter specific to -local and
  217. // perform action for -local option.
  218. bCleanExit = ProcessLocal(argc, argv);
  219. }
  220. else if( TRUE == bQuery)
  221. {
  222. // Process command line parameter specific to -query and
  223. // perform action for -query option.
  224. bCleanExit = ProcessQuery(argc, argv);
  225. }
  226. else if( TRUE == bDisconnect)
  227. {
  228. // Process command line parameter specific to -disconnect
  229. // and perform action for -disconnect option.
  230. bCleanExit = ProcessDisconnect(argc, argv);
  231. }
  232. else
  233. {
  234. TCHAR szTemp[2*MAX_STRING_LENGTH];
  235. TCHAR szErrstr[MAX_RES_STRING];
  236. TCHAR szFormatStr[MAX_RES_STRING];
  237. SecureZeroMemory(szFormatStr,sizeof(TCHAR)*MAX_RES_STRING );
  238. SecureZeroMemory(szErrstr,sizeof(TCHAR)*MAX_RES_STRING );
  239. SecureZeroMemory(szTemp,sizeof(TCHAR)*(2*MAX_STRING_LENGTH));
  240. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  241. StringCopy(szErrstr,GetResString(IDS_UTILITY_NAME),
  242. SIZE_OF_ARRAY(szFormatStr));
  243. StringCopy(szFormatStr,GetResString(IDS_INVALID_SYNTAX),
  244. SIZE_OF_ARRAY(szFormatStr));
  245. StringCchPrintfW(szTemp,SIZE_OF_ARRAY(szTemp),szFormatStr,szErrstr);
  246. ShowMessage( stderr,(LPCWSTR)szTemp);
  247. bCleanExit = FALSE;
  248. }
  249. }
  250. }
  251. else
  252. {
  253. if( TRUE == g_bIs32BitEnv )
  254. {
  255. // invalid syntax
  256. ShowMessage( stderr,GetReason());
  257. }
  258. // return from the function
  259. bCleanExit = FALSE;
  260. }
  261. }
  262. }
  263. catch(CHeap_Exception cheapException)
  264. {
  265. // catching the CHStrig related memory exceptions...
  266. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  267. SaveLastError();
  268. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  269. bCleanExit = FALSE;
  270. }
  271. // Release global memory if any allocated through common functionality
  272. ReleaseGlobals();
  273. return bCleanExit?EXIT_SUCCESS:EXIT_FAILURE;
  274. }//_tmain
  275. BOOL
  276. ProcessLocal(
  277. IN DWORD argc,
  278. IN LPCTSTR argv[]
  279. )
  280. /*++
  281. Routine Description:
  282. This function will perform Local related tasks.
  283. Arguments:
  284. [in] argc - Number of command line arguments
  285. [in] argv - Array containing command line arguments
  286. Returned Value:
  287. BOOL --True if it succeeds
  288. --False if it fails.
  289. --*/
  290. {
  291. // Variable to store function return value
  292. BOOL bResult = FALSE;
  293. LPTSTR pszLocalValue = NULL;
  294. bResult = ProcessOptions( argc,argv,&pszLocalValue);
  295. if( FALSE ==bResult)
  296. {
  297. // invalid syntax
  298. ShowMessage( stderr,GetReason() );
  299. //Release allocated memory safely
  300. SAFEDELETE(pszLocalValue);
  301. // return from the function
  302. return FALSE;
  303. }
  304. if ( FALSE == IsUserAdmin())
  305. {
  306. ShowMessage(stderr,GetResString(IDS_USER_NOT_ADMIN));
  307. bResult = FALSE;
  308. }
  309. else
  310. {
  311. // Only last argument is of interst
  312. bResult = DoLocalOpenFiles(0,FALSE,FALSE,pszLocalValue);
  313. }
  314. FreeMemory( (LPVOID*)(&pszLocalValue));
  315. return bResult;
  316. }
  317. BOOL
  318. ProcessQuery(
  319. IN DWORD argc,
  320. IN LPCTSTR argv[]
  321. )
  322. /*++
  323. Routine Description:
  324. This function will perform query related tasks.
  325. Arguments:
  326. [in] argc - Number of command line arguments
  327. [in] argv - Array containing command line arguments
  328. Returned Value:
  329. BOOL --True if it succeeds
  330. --False if it fails.
  331. --*/
  332. {
  333. // Variable to store function return value
  334. BOOL bResult = FALSE;
  335. BOOL bCloseConnection = FALSE;
  336. // options.
  337. // -query query
  338. BOOL bQuery = FALSE;
  339. // -nh (noheader)
  340. BOOL bShowNoHeader = FALSE;
  341. // -v (verbose)
  342. BOOL bVerbose = FALSE;
  343. // need password or not
  344. BOOL bNeedPassword = FALSE;
  345. // -s ( server name)
  346. LPTSTR pszServer = NULL;
  347. // -u ( user name)
  348. LPTSTR pszUserName = NULL;
  349. // -p ( password)
  350. LPTSTR pszPassword = NULL;
  351. // -format
  352. LPTSTR pszFormat = NULL;
  353. // server name used for EstablishConnection Function.
  354. LPTSTR pszServerName = NULL;
  355. LPTSTR pszServerNameHeadPosition = NULL;
  356. try
  357. {
  358. //Stores status if connection to beclosed or not
  359. CHString szChString = L"";
  360. // Process command line options.
  361. bResult = ProcessOptions( argc,
  362. argv,
  363. &bQuery,
  364. &pszServer,
  365. &pszUserName,
  366. &pszPassword,
  367. &pszFormat,
  368. &bShowNoHeader,
  369. &bVerbose,
  370. &bNeedPassword);
  371. if ( FALSE == bResult)
  372. {
  373. // Invalid syntax.
  374. ShowMessage( stderr,GetReason() );
  375. //Release allocated memory safely
  376. FreeMemory((LPVOID*)&pszPassword);
  377. FreeMemory((LPVOID*)&pszServer);
  378. FreeMemory((LPVOID*)&pszUserName);
  379. FreeMemory((LPVOID*)&pszFormat);
  380. // return from the function
  381. return FALSE;
  382. }
  383. if( 0 != StringLength(pszServer,0))
  384. {
  385. pszServerName = (LPTSTR) AllocateMemory(GetBufferSize((LPVOID)pszServer));
  386. if( NULL == pszServerName)
  387. {
  388. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  389. SaveLastError();
  390. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  391. //Release allocated memory safely
  392. FreeMemory((LPVOID*)&pszPassword);
  393. FreeMemory((LPVOID*)&pszServer);
  394. FreeMemory((LPVOID*)&pszUserName);
  395. FreeMemory((LPVOID*)&pszFormat);
  396. // return from the function
  397. return FALSE;
  398. }
  399. // Initialize currently allocated arrays.
  400. SecureZeroMemory(pszServerName,GetBufferSize((LPVOID)pszServerName));
  401. // Store head position of 'pszServerName'.
  402. pszServerNameHeadPosition = pszServerName;
  403. szChString = pszServer;
  404. if((StringCompare(szChString.Left(2),DOUBLE_SLASH,FALSE,2)==0)
  405. &&(szChString.GetLength()>2))
  406. {
  407. szChString = szChString.Mid( 2,szChString.GetLength()) ;
  408. }
  409. if(StringCompare(szChString.Left(1),SINGLE_SLASH,FALSE,1)!=0)
  410. {
  411. StringCopy(pszServer,(LPCWSTR)szChString,
  412. GetBufferSize((LPVOID)pszServer));
  413. }
  414. StringCopy(pszServerName,pszServer,GetBufferSize((LPVOID)pszServerName));
  415. // Try to connect to remote server. Function checks for local machine
  416. // so here no checking is done.
  417. if(IsLocalSystem(pszServerName)==TRUE)
  418. {
  419. #ifndef _WIN64
  420. DWORD dwRetVal = CheckSystemType( L"\0");
  421. if(dwRetVal!=EXIT_SUCCESS )
  422. {
  423. //Release allocated memory safely
  424. FreeMemory((LPVOID*)&pszUserName);
  425. FreeMemory((LPVOID*)&pszServer);
  426. FreeMemory((LPVOID*)&pszPassword);
  427. FreeMemory((LPVOID*)&pszFormat);
  428. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  429. return EXIT_FAILURE;
  430. }
  431. #else
  432. DWORD dwRetVal = CheckSystemType64( L"\0");
  433. if(dwRetVal!=EXIT_SUCCESS )
  434. {
  435. //Release allocated memory safely
  436. FreeMemory((LPVOID*)&pszUserName);
  437. FreeMemory((LPVOID*)&pszServer);
  438. FreeMemory((LPVOID*)&pszPassword);
  439. FreeMemory((LPVOID*)&pszFormat);
  440. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  441. return EXIT_FAILURE;
  442. }
  443. #endif
  444. if(StringLength(pszUserName,0)>0)
  445. {
  446. ShowMessage(stderr,GetResString(IDS_LOCAL_SYSTEM));
  447. }
  448. // Check if current logon user had administrative rights.
  449. // Preceed only if current logon user had administrative rights.
  450. if ( FALSE == IsUserAdmin())
  451. {
  452. ShowMessage(stderr,GetResString(IDS_USER_NOT_ADMIN));
  453. //Release allocated memory safely
  454. FreeMemory((LPVOID*)&pszUserName);
  455. FreeMemory((LPVOID*)&pszServer);
  456. FreeMemory((LPVOID*)&pszPassword);
  457. FreeMemory((LPVOID*)&pszFormat);
  458. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  459. // return from the function
  460. return FALSE;
  461. }
  462. }
  463. else
  464. {
  465. if( FALSE == EstablishConnection( pszServerName,
  466. pszUserName,
  467. GetBufferSize((LPVOID)pszUserName)/sizeof(WCHAR),
  468. pszPassword,
  469. GetBufferSize((LPVOID)pszPassword)/sizeof(WCHAR),
  470. bNeedPassword ))
  471. {
  472. // Connection to remote system failed , Show corresponding error
  473. // and exit from function.
  474. ShowMessage( stderr,GetResString(IDS_ID_SHOW_ERROR) );
  475. if(StringLength(GetReason(),0)==0)
  476. {
  477. ShowMessage(stderr,GetResString(IDS_INVALID_CREDENTIALS));
  478. }
  479. else
  480. {
  481. ShowMessage( stderr,GetReason() );
  482. }
  483. //Release allocated memory safely
  484. FreeMemory((LPVOID*)&pszPassword);
  485. FreeMemory((LPVOID*)&pszServer);
  486. FreeMemory((LPVOID*)&pszUserName);
  487. FreeMemory((LPVOID*)&pszFormat);
  488. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  489. return FALSE;
  490. }
  491. // determine whether this connection needs to disconnected later or not
  492. // though the connection is successfull, some conflict might have
  493. // occured
  494. switch( GetLastError() )
  495. {
  496. case I_NO_CLOSE_CONNECTION:
  497. bCloseConnection = FALSE;
  498. break;
  499. case E_LOCAL_CREDENTIALS:
  500. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  501. {
  502. //
  503. // some error occured ... but can be ignored
  504. // connection need not be disconnected
  505. bCloseConnection= FALSE;
  506. // show the warning message
  507. ShowMessage(stderr,GetResString(IDS_ID_SHOW_WARNING));
  508. ShowMessage(stderr,GetReason());
  509. break;
  510. }
  511. default:
  512. bCloseConnection = TRUE;
  513. }
  514. }
  515. }
  516. // Password is no longer needed, better to free it.
  517. FreeMemory((LPVOID*)&pszPassword);
  518. // Perform Qyery operation.
  519. bResult = DoQuery(pszServer,
  520. bShowNoHeader,
  521. pszFormat,
  522. bVerbose);
  523. // Close the network connection which is previously opened by
  524. // EstablishConnection
  525. if(bCloseConnection==TRUE)
  526. {
  527. CloseConnection(pszServerName);
  528. }
  529. FreeMemory((LPVOID*)&pszServer);
  530. FreeMemory((LPVOID*)&pszUserName);
  531. FreeMemory((LPVOID*)&pszFormat);
  532. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  533. }
  534. catch ( CHeap_Exception cheapException)
  535. {
  536. FreeMemory((LPVOID*)&pszPassword);
  537. FreeMemory((LPVOID*)&pszServer);
  538. FreeMemory((LPVOID*)&pszUserName);
  539. FreeMemory((LPVOID*)&pszFormat);
  540. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  541. throw(cheapException);
  542. }
  543. return bResult;
  544. }
  545. BOOL
  546. ProcessDisconnect(
  547. IN DWORD argc,
  548. IN LPCTSTR argv[]
  549. )
  550. /*++
  551. Routine Description:
  552. This function will perform Disconnect related tasks.
  553. Arguments:
  554. [in] argc - Number of command line arguments
  555. [in] argv - Array containing command line arguments
  556. Returned Value:
  557. BOOL --True if it succeeds
  558. --False if it fails.
  559. --*/
  560. {
  561. // Variable to store function return value
  562. BOOL bResult = FALSE;
  563. DWORD dwRetVal = 0;
  564. //Check whether connection to be closed or not.
  565. BOOL bCloseConnection = FALSE;
  566. // Ask for password or not.
  567. BOOL bNeedPassword = FALSE;
  568. // options.
  569. // -query query
  570. BOOL bQuery = FALSE;
  571. // -s ( server name)
  572. LPTSTR pszServer = NULL;
  573. // -u ( user name)
  574. LPTSTR pszUserName = NULL;
  575. // -p ( password)
  576. LPTSTR pszPassword = NULL;
  577. // server name used for EstablishConnection Function.
  578. LPTSTR pszServerName = NULL;
  579. LPTSTR pszServerNameHeadPosition = NULL;
  580. //LPTSTR pszServerHeadPosition = NULL;
  581. // -I ( id )
  582. LPTSTR pszID = NULL;
  583. //-a(accessedby)
  584. LPTSTR pszAccessedby = NULL;
  585. // -o ( openmode)
  586. LPTSTR pszOpenmode = NULL;
  587. // -op( openfile)
  588. LPTSTR pszOpenFile = NULL;
  589. try
  590. {
  591. // Temp. variable
  592. CHString szChString = L"\0";
  593. // Process commandline options.
  594. bResult = ProcessOptions( argc,
  595. argv,
  596. &bQuery,
  597. &pszServer,
  598. &pszUserName,
  599. &pszPassword,
  600. &pszID,
  601. &pszAccessedby,
  602. &pszOpenmode,
  603. &pszOpenFile,
  604. &bNeedPassword);
  605. if ( FALSE == bResult)
  606. {
  607. // invalid syntax
  608. ShowMessage( stderr,GetReason() );
  609. //Release allocated memory safely
  610. FreeMemory((LPVOID*)&pszServer);
  611. FreeMemory((LPVOID*)&pszUserName);
  612. FreeMemory((LPVOID*)&pszPassword);
  613. FreeMemory((LPVOID*)&pszID);
  614. FreeMemory((LPVOID*)&pszAccessedby);
  615. FreeMemory((LPVOID*)&pszOpenmode);
  616. FreeMemory((LPVOID*)&pszOpenFile);
  617. // return from the function
  618. return FALSE;
  619. }
  620. if( 0 != StringLength(pszServer,0))
  621. {
  622. pszServerName = (LPTSTR) AllocateMemory(GetBufferSize((LPVOID)pszServer));
  623. if (NULL == pszServerName)
  624. {
  625. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  626. SaveLastError();
  627. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  628. //Release allocated memory safely
  629. FreeMemory((LPVOID*)&pszServer);
  630. FreeMemory((LPVOID*)&pszUserName);
  631. FreeMemory((LPVOID*)&pszPassword);
  632. FreeMemory((LPVOID*)&pszID);
  633. FreeMemory((LPVOID*)&pszAccessedby);
  634. FreeMemory((LPVOID*)&pszOpenmode);
  635. FreeMemory((LPVOID*)&pszOpenFile);
  636. }
  637. // Initialize currently allocated arrays.
  638. SecureZeroMemory(pszServerName,GetBufferSize((LPVOID)pszServerName));
  639. // store Head position Address to successfully delete allocated memory
  640. // block.
  641. pszServerNameHeadPosition = pszServerName;
  642. szChString = pszServer;
  643. // Append '\\' in front of server name is not specified.
  644. if((StringCompare(szChString.Left(2),DOUBLE_SLASH,FALSE,2)==0)
  645. &&(szChString.GetLength()>2))
  646. {
  647. szChString = szChString.Mid( 2,szChString.GetLength()) ;
  648. }
  649. if(StringCompare(szChString.Left(2),SINGLE_SLASH,FALSE,2)!=0)
  650. {
  651. StringCopy(pszServer,(LPCWSTR)szChString,
  652. GetBufferSize((LPVOID)pszServer));
  653. }
  654. StringCopy(pszServerName,pszServer,GetBufferSize((LPVOID )pszServerName));
  655. }
  656. if(IsLocalSystem(pszServerName)==TRUE)
  657. {
  658. #ifndef _WIN64
  659. dwRetVal = CheckSystemType( L"\0");
  660. if(dwRetVal!=EXIT_SUCCESS )
  661. {
  662. FreeMemory((LPVOID*)&pszServer);
  663. FreeMemory((LPVOID*)&pszUserName);
  664. FreeMemory((LPVOID*)&pszPassword);
  665. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  666. FreeMemory((LPVOID*)&pszID);
  667. FreeMemory((LPVOID*)&pszAccessedby);
  668. FreeMemory((LPVOID*)&pszOpenmode);
  669. FreeMemory((LPVOID*)&pszOpenFile);
  670. return EXIT_FAILURE;
  671. }
  672. #else
  673. dwRetVal = CheckSystemType64( L"\0");
  674. if(dwRetVal!=EXIT_SUCCESS )
  675. {
  676. FreeMemory((LPVOID*)&pszServer);
  677. FreeMemory((LPVOID*)&pszUserName);
  678. FreeMemory((LPVOID*)&pszPassword);
  679. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  680. FreeMemory((LPVOID*)&pszID);
  681. FreeMemory((LPVOID*)&pszAccessedby);
  682. FreeMemory((LPVOID*)&pszOpenmode);
  683. FreeMemory((LPVOID*)&pszOpenFile);
  684. return EXIT_FAILURE;
  685. }
  686. #endif
  687. if(StringLength(pszUserName,0)>0)
  688. {
  689. ShowMessage(stderr,GetResString(IDS_LOCAL_SYSTEM));
  690. }
  691. }
  692. else
  693. {
  694. // Connet to remote system.
  695. if(EstablishConnection( pszServerName,
  696. pszUserName,
  697. GetBufferSize((LPVOID)pszUserName)/sizeof(WCHAR),
  698. pszPassword,
  699. GetBufferSize((LPVOID)pszPassword)/sizeof(WCHAR),
  700. bNeedPassword )==FALSE)
  701. {
  702. // Connection to remote system failed , Show corresponding error
  703. // and exit from function.
  704. ShowMessage( stderr,
  705. GetResString(IDS_ID_SHOW_ERROR) );
  706. if(StringLength(GetReason(),0)==0)
  707. {
  708. ShowMessage(stderr,GetResString(IDS_INVALID_CREDENTIALS));
  709. }
  710. else
  711. {
  712. ShowMessage( stderr,GetReason() );
  713. }
  714. //Release allocated memory safely
  715. FreeMemory((LPVOID*)&pszServer);
  716. FreeMemory((LPVOID*)&pszUserName);
  717. FreeMemory((LPVOID*)&pszPassword);
  718. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  719. FreeMemory((LPVOID*)&pszID);
  720. FreeMemory((LPVOID*)&pszAccessedby);
  721. FreeMemory((LPVOID*)&pszOpenmode);
  722. FreeMemory((LPVOID*)&pszOpenFile);
  723. return FALSE;
  724. }
  725. // determine whether this connection needs to disconnected later or not
  726. // though the connection is successfull, some conflict might have
  727. // occured
  728. switch( GetLastError() )
  729. {
  730. case I_NO_CLOSE_CONNECTION:
  731. bCloseConnection = FALSE;
  732. break;
  733. case E_LOCAL_CREDENTIALS:
  734. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  735. {
  736. //
  737. // some error occured ... but can be ignored
  738. // connection need not be disconnected
  739. bCloseConnection= FALSE;
  740. // show the warning message
  741. ShowMessage(stderr,GetResString(IDS_ID_SHOW_WARNING));
  742. ShowMessage(stderr,GetReason());
  743. break;
  744. }
  745. default:
  746. bCloseConnection = TRUE;
  747. }
  748. }
  749. // Password is no longer needed, better to free it.
  750. FreeMemory((LPVOID*)&pszPassword);
  751. // Do Disconnect open files.....
  752. bResult = DisconnectOpenFile(pszServer,
  753. pszID,
  754. pszAccessedby,
  755. pszOpenmode,
  756. pszOpenFile );
  757. // Close the network connection which is previously opened by
  758. // EstablishConnection
  759. if(bCloseConnection==TRUE)
  760. {
  761. CloseConnection(pszServerName);
  762. }
  763. // Free memory which is previously allocated.
  764. FreeMemory((LPVOID*)&pszServer);
  765. FreeMemory((LPVOID*)&pszUserName);
  766. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  767. FreeMemory((LPVOID*)&pszID);
  768. FreeMemory((LPVOID*)&pszAccessedby);
  769. FreeMemory((LPVOID*)&pszOpenmode);
  770. FreeMemory((LPVOID*)&pszOpenFile);
  771. }
  772. catch (CHeap_Exception cheapException)
  773. {
  774. //Release allocated memory safely
  775. FreeMemory((LPVOID*)&pszServer);
  776. FreeMemory((LPVOID*)&pszUserName);
  777. FreeMemory((LPVOID*)&pszPassword);
  778. FreeMemory((LPVOID*)&pszID);
  779. FreeMemory((LPVOID*)&pszAccessedby);
  780. FreeMemory((LPVOID*)&pszOpenmode);
  781. FreeMemory((LPVOID*)&pszOpenFile);
  782. FreeMemory((LPVOID*)&pszServerNameHeadPosition);
  783. throw(cheapException);
  784. }
  785. return bResult;
  786. }
  787. BOOL
  788. ProcessOptions(
  789. IN DWORD argc,
  790. IN LPCTSTR argv[],
  791. OUT LPTSTR* pszLocalValue
  792. )
  793. /*++
  794. Routine Description:
  795. This function takes command line argument and checks for correct syntax and
  796. if the syntax is ok, Out variables [out] will contain respective values.
  797. Arguments:
  798. [in] argc - Number of command line arguments
  799. [in] argv - Array containing command line arguments
  800. [out] pszLocalValue - contains the values for -local option
  801. Returned Value:
  802. BOOL --True if it succeeds
  803. --False if it fails.
  804. --*/
  805. {
  806. TCMDPARSER2 cmdOptions[ MAX_LOCAL_OPTIONS ];//Variable to store command line
  807. CHString szTempString;
  808. TCHAR szTemp[MAX_RES_STRING*2];
  809. TCHAR szOptionAllowed[MAX_RES_STRING];
  810. StringCopy(szOptionAllowed,GetResString(IDS_LOCAL_OPTION),SIZE_OF_ARRAY(szTemp));
  811. szTempString = GetResString(IDS_UTILITY_NAME);
  812. StringCchPrintfW(szTemp,SIZE_OF_ARRAY(szTemp),
  813. GetResString(IDS_INVALID_SYNTAX),(LPCWSTR)szTempString);
  814. SecureZeroMemory(cmdOptions,sizeof(TCMDPARSER2) * MAX_LOCAL_OPTIONS);
  815. // -local
  816. StringCopyA( cmdOptions[ OI_O_LOCAL ].szSignature, "PARSER2\0", 8 );
  817. cmdOptions[ OI_O_LOCAL ].dwType = CP_TYPE_TEXT;
  818. cmdOptions[ OI_O_LOCAL ].pwszOptions = szLocalOption;
  819. cmdOptions[ OI_O_LOCAL ].pwszFriendlyName = NULL;
  820. cmdOptions[ OI_O_LOCAL ].pwszValues = szOptionAllowed;
  821. cmdOptions[ OI_O_LOCAL ].dwCount = 1;
  822. cmdOptions[ OI_O_LOCAL ].dwActuals = 0;
  823. cmdOptions[ OI_O_LOCAL ].dwFlags = CP2_VALUE_OPTIONAL | CP2_ALLOCMEMORY |
  824. CP2_MODE_VALUES ;
  825. cmdOptions[ OI_O_LOCAL ].pValue = NULL;
  826. cmdOptions[ OI_O_LOCAL ].dwLength = StringLength(szOptionAllowed,0);
  827. cmdOptions[ OI_O_LOCAL ].pFunction = NULL;
  828. cmdOptions[ OI_O_LOCAL ].pFunctionData = NULL;
  829. cmdOptions[ OI_O_LOCAL ].dwReserved = 0;
  830. cmdOptions[ OI_O_LOCAL ].pReserved1 = NULL;
  831. cmdOptions[ OI_O_LOCAL ].pReserved2 = NULL;
  832. cmdOptions[ OI_O_LOCAL ].pReserved3 = NULL;
  833. //
  834. // do the command line parsing
  835. if ( FALSE == DoParseParam2( argc, argv, -1, MAX_LOCAL_OPTIONS, cmdOptions,0 ))
  836. {
  837. ShowMessage(stderr,GetResString(IDS_ID_SHOW_ERROR));
  838. return FALSE; // invalid syntax
  839. }
  840. *pszLocalValue = (LPTSTR)cmdOptions[ OI_O_LOCAL ].pValue;
  841. if( NULL == *pszLocalValue)
  842. {
  843. // this string does not require localization
  844. // as it is storing value other than ON/OFF
  845. *pszLocalValue = (LPTSTR) AllocateMemory( (StringLength(L"SHOW_STATUS",0)+1) * sizeof( WCHAR ) );
  846. if ( *pszLocalValue == NULL )
  847. {
  848. SaveLastError();
  849. return FALSE;
  850. }
  851. StringCopy(*pszLocalValue, L"SHOW_STATUS", GetBufferSize((LPVOID)*pszLocalValue));
  852. }
  853. return TRUE;
  854. }
  855. BOOL
  856. ProcessOptions(
  857. IN DWORD argc,
  858. IN LPCTSTR argv[],
  859. OUT PBOOL pbDisconnect,
  860. OUT PBOOL pbQuery,
  861. OUT PBOOL pbUsage,
  862. OUT PBOOL pbResetFlag
  863. )
  864. /*++
  865. Routine Description:
  866. This function takes command line argument and checks for correct syntax and
  867. if the syntax is ok, it returns the values in different variables. variables
  868. [out] will contain respective values.
  869. Arguments:
  870. [in] argc - Number of command line arguments
  871. [in] argv - Array containing command line arguments
  872. [out] pbDisconnect - Discoonect option string
  873. [out] pbQuery - Query option string
  874. [out] pbUsage - The usage option
  875. [out] pbResetFlag - Reset flag.
  876. Returned Value:
  877. BOOL -- TRUE if it succeeds
  878. -- FALSE if it fails.
  879. --*/
  880. {
  881. // local variables
  882. TCMDPARSER2 cmdOptions[ MAX_OPTIONS ];//Variable to store command line
  883. // options.
  884. LPTSTR pszTempServer = NULL;//new TCHAR[MIN_MEMORY_REQUIRED];
  885. LPTSTR pszTempUser = NULL;//new TCHAR[MIN_MEMORY_REQUIRED];
  886. LPTSTR pszTempPassword = NULL;//new TCHAR[MIN_MEMORY_REQUIRED];
  887. TARRAY arrTemp = NULL;
  888. CHString szTempString;
  889. TCHAR szTemp[MIN_MEMORY_REQUIRED*2];
  890. szTempString = GetResString(IDS_UTILITY_NAME);
  891. StringCchPrintfW( szTemp,SIZE_OF_ARRAY(szTemp),
  892. GetResString(IDS_INVALID_SYNTAX),(LPCWSTR)szTempString);
  893. arrTemp = CreateDynamicArray();
  894. if( NULL == arrTemp)
  895. {
  896. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  897. SaveLastError();
  898. ShowLastErrorEx( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  899. return FALSE;
  900. }
  901. SecureZeroMemory(cmdOptions,sizeof(TCMDPARSER2) * MAX_OPTIONS);
  902. // prepare the command options
  903. // -disconnect option for help
  904. StringCopyA( cmdOptions[ OI_DISCONNECT ].szSignature, "PARSER2\0", 8 );
  905. cmdOptions[ OI_DISCONNECT ].dwType = CP_TYPE_BOOLEAN;
  906. cmdOptions[ OI_DISCONNECT ].pwszOptions = szDisconnectOption;
  907. cmdOptions[ OI_DISCONNECT ].pwszFriendlyName = NULL;
  908. cmdOptions[ OI_DISCONNECT ].pwszValues = NULL;
  909. cmdOptions[ OI_DISCONNECT ].dwCount = 1;
  910. cmdOptions[ OI_DISCONNECT ].dwActuals = 0;
  911. cmdOptions[ OI_DISCONNECT ].dwFlags = 0;
  912. cmdOptions[ OI_DISCONNECT ].pValue = pbDisconnect;
  913. cmdOptions[ OI_DISCONNECT ].dwLength = 0;
  914. cmdOptions[ OI_DISCONNECT ].pFunction = NULL;
  915. cmdOptions[ OI_DISCONNECT ].pFunctionData = NULL;
  916. cmdOptions[ OI_DISCONNECT ].dwReserved = 0;
  917. cmdOptions[ OI_DISCONNECT ].pReserved1 = NULL;
  918. cmdOptions[ OI_DISCONNECT ].pReserved2 = NULL;
  919. cmdOptions[ OI_DISCONNECT ].pReserved3 = NULL;
  920. // -query option for help
  921. StringCopyA( cmdOptions[ OI_QUERY ].szSignature, "PARSER2\0", 8 );
  922. cmdOptions[ OI_QUERY ].dwType = CP_TYPE_BOOLEAN;
  923. cmdOptions[ OI_QUERY ].pwszOptions = szQueryOption;
  924. cmdOptions[ OI_QUERY ].pwszFriendlyName = NULL;
  925. cmdOptions[ OI_QUERY ].pwszValues = NULL;
  926. cmdOptions[ OI_QUERY ].dwCount = 1;
  927. cmdOptions[ OI_QUERY ].dwActuals = 0;
  928. cmdOptions[ OI_QUERY ].dwFlags = 0;
  929. cmdOptions[ OI_QUERY ].pValue = pbQuery;
  930. cmdOptions[ OI_QUERY ].dwLength = 0;
  931. cmdOptions[ OI_QUERY ].pFunction = NULL;
  932. cmdOptions[ OI_QUERY ].pFunctionData = NULL;
  933. cmdOptions[ OI_QUERY ].dwReserved = 0;
  934. cmdOptions[ OI_QUERY ].pReserved1 = NULL;
  935. cmdOptions[ OI_QUERY ].pReserved2 = NULL;
  936. cmdOptions[ OI_QUERY ].pReserved3 = NULL;
  937. // /? option for help
  938. StringCopyA( cmdOptions[ OI_USAGE ].szSignature, "PARSER2\0", 8 );
  939. cmdOptions[ OI_USAGE ].dwType = CP_TYPE_BOOLEAN;
  940. cmdOptions[ OI_USAGE ].pwszOptions = szUsageOption;
  941. cmdOptions[ OI_USAGE ].pwszFriendlyName = NULL;
  942. cmdOptions[ OI_USAGE ].pwszValues = NULL;
  943. cmdOptions[ OI_USAGE ].dwCount = 1;
  944. cmdOptions[ OI_USAGE ].dwActuals = 0;
  945. cmdOptions[ OI_USAGE ].dwFlags = CP_USAGE;
  946. cmdOptions[ OI_USAGE ].pValue = pbUsage;
  947. cmdOptions[ OI_USAGE ].dwLength = 0;
  948. cmdOptions[ OI_USAGE ].pFunction = NULL;
  949. cmdOptions[ OI_USAGE ].pFunctionData = NULL;
  950. cmdOptions[ OI_USAGE ].dwReserved = 0;
  951. cmdOptions[ OI_USAGE ].pReserved1 = NULL;
  952. cmdOptions[ OI_USAGE ].pReserved2 = NULL;
  953. cmdOptions[ OI_USAGE ].pReserved3 = NULL;
  954. // -local
  955. StringCopyA( cmdOptions[ OI_LOCAL ].szSignature, "PARSER2\0", 8 );
  956. cmdOptions[ OI_LOCAL ].dwType = CP_TYPE_BOOLEAN;
  957. cmdOptions[ OI_LOCAL ].pwszOptions = szLocalOption;
  958. cmdOptions[ OI_LOCAL ].pwszFriendlyName = NULL;
  959. cmdOptions[ OI_LOCAL ].pwszValues = NULL;
  960. cmdOptions[ OI_LOCAL ].dwCount = 1;
  961. cmdOptions[ OI_LOCAL ].dwActuals = 0;
  962. cmdOptions[ OI_LOCAL ].dwFlags = 0;
  963. cmdOptions[ OI_LOCAL ].pValue = pbResetFlag;
  964. cmdOptions[ OI_LOCAL ].dwLength = 0;
  965. cmdOptions[ OI_LOCAL ].pFunction = NULL;
  966. cmdOptions[ OI_LOCAL ].pFunctionData = NULL;
  967. cmdOptions[ OI_LOCAL ].dwReserved = 0;
  968. cmdOptions[ OI_LOCAL ].pReserved1 = NULL;
  969. cmdOptions[ OI_LOCAL ].pReserved2 = NULL;
  970. cmdOptions[ OI_LOCAL ].pReserved3 = NULL;
  971. // default ..
  972. // Although there is no default option for this utility...
  973. // At this moment all the switches other than specified above will be
  974. // treated as default parameter for Main DoParceParam.
  975. // Exact parcing depending on optins (-query or -disconnect) will be done
  976. // at that respective places.
  977. StringCopyA( cmdOptions[ OI_DEFAULT ].szSignature, "PARSER2\0", 8 );
  978. cmdOptions[ OI_DEFAULT ].dwType = CP_TYPE_TEXT;
  979. cmdOptions[ OI_DEFAULT ].pwszOptions = NULL;
  980. cmdOptions[ OI_DEFAULT ].pwszFriendlyName = NULL;
  981. cmdOptions[ OI_DEFAULT ].pwszValues = NULL;
  982. cmdOptions[ OI_DEFAULT ].dwCount = 0;
  983. cmdOptions[ OI_DEFAULT ].dwActuals = 0;
  984. cmdOptions[ OI_DEFAULT ].dwFlags = CP2_MODE_ARRAY|CP2_DEFAULT;
  985. cmdOptions[ OI_DEFAULT ].pValue = &arrTemp;
  986. cmdOptions[ OI_DEFAULT ].dwLength = 0;
  987. cmdOptions[ OI_DEFAULT ].pFunction = NULL;
  988. cmdOptions[ OI_DEFAULT ].pFunctionData = NULL;
  989. cmdOptions[ OI_DEFAULT ].dwReserved = 0;
  990. cmdOptions[ OI_DEFAULT ].pReserved1 = NULL;
  991. cmdOptions[ OI_DEFAULT ].pReserved2 = NULL;
  992. cmdOptions[ OI_DEFAULT ].pReserved3 = NULL;
  993. //
  994. // do the command line parsing
  995. if ( FALSE == DoParseParam2( argc,argv,-1, MAX_OPTIONS,cmdOptions,0))
  996. {
  997. // invalid syntax.
  998. ShowMessage(stderr,GetResString(IDS_ID_SHOW_ERROR));
  999. // Release momory.
  1000. SAFERELDYNARRAY(arrTemp);
  1001. return FALSE;
  1002. }
  1003. //Release memory as variable no longer needed
  1004. SAFERELDYNARRAY(arrTemp);
  1005. // Check if all of following is true is an error
  1006. if((*pbUsage==TRUE)&&argc>3)
  1007. {
  1008. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  1009. SetReason(szTemp);
  1010. return FALSE;
  1011. }
  1012. // -query ,-disconnect and -local options cannot come together
  1013. if(((*pbQuery)+(*pbDisconnect)+(*pbResetFlag))>1)
  1014. {
  1015. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  1016. SetReason(szTemp);
  1017. SAFEDELETE(pszTempUser);
  1018. SAFEDELETE(pszTempPassword);
  1019. SAFEDELETE(pszTempServer);
  1020. return FALSE;
  1021. }
  1022. else if((2 == argc )&&( TRUE == *pbUsage))
  1023. {
  1024. // if -? alone given its a valid conmmand line
  1025. SAFEDELETE(pszTempUser);
  1026. SAFEDELETE(pszTempPassword);
  1027. SAFEDELETE(pszTempServer);
  1028. return TRUE;
  1029. }
  1030. if((argc>2)&& ( FALSE == *pbQuery)&&(FALSE == *pbDisconnect)&&
  1031. (FALSE == *pbResetFlag))
  1032. {
  1033. // If command line argument is equals or greater than 2 atleast one
  1034. // of -query OR -local OR -disconnect should be present in it.
  1035. // (for "-?" previous condition already takes care)
  1036. // This to prevent from following type of command line argument:
  1037. // OpnFiles.exe -nh ... Which is a invalid syntax.
  1038. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  1039. SetReason(szTemp);
  1040. SAFEDELETE(pszTempUser);
  1041. SAFEDELETE(pszTempPassword);
  1042. SAFEDELETE(pszTempServer);
  1043. return FALSE;
  1044. }
  1045. // Release momory.
  1046. SAFEDELETE(pszTempUser);
  1047. SAFEDELETE(pszTempPassword);
  1048. SAFEDELETE(pszTempServer);
  1049. return TRUE;
  1050. }//ProcesOptions
  1051. BOOL
  1052. ProcessOptions(
  1053. IN DWORD argc,
  1054. IN LPCTSTR argv[],
  1055. OUT PBOOL pbQuery,
  1056. OUT LPTSTR* pszServer,
  1057. OUT LPTSTR* pszUserName,
  1058. OUT LPTSTR* pszPassword,
  1059. OUT LPTSTR* pszFormat,
  1060. OUT PBOOL pbShowNoHeader,
  1061. OUT PBOOL pbVerbose,
  1062. OUT PBOOL pbNeedPassword
  1063. )
  1064. /*++
  1065. Routine Description:
  1066. This function takes command line argument and checks for correct syntax and
  1067. if the syntax is ok, it returns the values in different variables. variables
  1068. [out] will contain respective values. This Functin specifically checks
  1069. command line parameters requered for QUERY option.
  1070. Arguments:
  1071. [in] argc - Number of command line arguments.
  1072. [in] argv - Array containing command line arguments.
  1073. [out] pbQuery - query option string.
  1074. [out] pszServer - remote server name.
  1075. [out] pszUserName - username for the remote system.
  1076. [out] pszPassword - password for the remote system for the username.
  1077. [out] pszFormat - format checking.
  1078. [out] pbShowNoHeader - show header.
  1079. [out] pbVerbose - show verbose.
  1080. [out] pbNeedPassword - To check whether the password is required or not.
  1081. Returned Value:
  1082. BOOL --True if it succeeds
  1083. --False if it fails.
  1084. --*/
  1085. {
  1086. // Check in/out parameters...
  1087. //Variable to store command line structure.
  1088. TCMDPARSER2 cmdOptions[ MAX_QUERY_OPTIONS ];
  1089. CHString szTempString;
  1090. TCHAR szTemp[MIN_MEMORY_REQUIRED*2];
  1091. TCHAR szTypeHelpMsg[MIN_MEMORY_REQUIRED];
  1092. TCHAR szFormatValues[MAX_RES_STRING];
  1093. szTempString = GetResString(IDS_UTILITY_NAME);
  1094. StringCchPrintfW(szTemp,SIZE_OF_ARRAY(szTemp),
  1095. GetResString(IDS_INVALID_SYNTAX),(LPCWSTR)szTempString);
  1096. StringCchPrintfW(szTypeHelpMsg, SIZE_OF_ARRAY(szTypeHelpMsg),
  1097. GetResString(IDS_TYPE_Q_HELP),(LPCWSTR)szTempString);
  1098. StringCopy(szFormatValues, FORMAT_OPTIONS, SIZE_OF_ARRAY(szFormatValues));
  1099. //
  1100. // prepare the command options
  1101. SecureZeroMemory(cmdOptions, sizeof(TCMDPARSER2) * MAX_QUERY_OPTIONS);
  1102. // -query option for help
  1103. StringCopyA( cmdOptions[ OI_Q_QUERY ].szSignature, "PARSER2\0", 8 );
  1104. cmdOptions[ OI_Q_QUERY ].dwType = CP_TYPE_BOOLEAN;
  1105. cmdOptions[ OI_Q_QUERY ].pwszOptions = szQueryOption;
  1106. cmdOptions[ OI_Q_QUERY ].pwszFriendlyName = NULL;
  1107. cmdOptions[ OI_Q_QUERY ].pwszValues = NULL;
  1108. cmdOptions[ OI_Q_QUERY ].dwCount = 1;
  1109. cmdOptions[ OI_Q_QUERY ].dwActuals = 0;
  1110. cmdOptions[ OI_Q_QUERY ].dwFlags = 0;
  1111. cmdOptions[ OI_Q_QUERY ].pValue = pbQuery;
  1112. cmdOptions[ OI_Q_QUERY ].dwLength = 0;
  1113. cmdOptions[ OI_Q_QUERY ].pFunction = NULL;
  1114. cmdOptions[ OI_Q_QUERY ].pFunctionData = NULL;
  1115. cmdOptions[ OI_Q_QUERY ].dwReserved = 0;
  1116. cmdOptions[ OI_Q_QUERY ].pReserved1 = NULL;
  1117. cmdOptions[ OI_Q_QUERY ].pReserved2 = NULL;
  1118. cmdOptions[ OI_Q_QUERY ].pReserved3 = NULL;
  1119. // -s option remote system name
  1120. StringCopyA( cmdOptions[ OI_Q_SERVER_NAME ].szSignature, "PARSER2\0", 8 );
  1121. cmdOptions[ OI_Q_SERVER_NAME ].dwType = CP_TYPE_TEXT;
  1122. cmdOptions[ OI_Q_SERVER_NAME ].pwszOptions = szServerNameOption;
  1123. cmdOptions[ OI_Q_SERVER_NAME ].pwszFriendlyName = NULL;
  1124. cmdOptions[ OI_Q_SERVER_NAME ].pwszValues = NULL;
  1125. cmdOptions[ OI_Q_SERVER_NAME ].dwCount = 1;
  1126. cmdOptions[ OI_Q_SERVER_NAME ].dwActuals = 0;
  1127. cmdOptions[ OI_Q_SERVER_NAME ].dwFlags = CP2_ALLOCMEMORY|CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL;
  1128. cmdOptions[ OI_Q_SERVER_NAME ].pValue = NULL;
  1129. cmdOptions[ OI_Q_SERVER_NAME ].dwLength = 0;
  1130. cmdOptions[ OI_Q_SERVER_NAME ].pFunction = NULL;
  1131. cmdOptions[ OI_Q_SERVER_NAME ].pFunctionData = NULL;
  1132. cmdOptions[ OI_Q_SERVER_NAME ].dwReserved = 0;
  1133. cmdOptions[ OI_Q_SERVER_NAME ].pReserved1 = NULL;
  1134. cmdOptions[ OI_Q_SERVER_NAME ].pReserved2 = NULL;
  1135. cmdOptions[ OI_Q_SERVER_NAME ].pReserved3 = NULL;
  1136. // -u option user name for the specified system
  1137. StringCopyA( cmdOptions[ OI_Q_USER_NAME ].szSignature, "PARSER2\0", 8 );
  1138. cmdOptions[ OI_Q_USER_NAME ].dwType = CP_TYPE_TEXT;
  1139. cmdOptions[ OI_Q_USER_NAME ].pwszOptions = szUserNameOption;
  1140. cmdOptions[ OI_Q_USER_NAME ].pwszFriendlyName = NULL;
  1141. cmdOptions[ OI_Q_USER_NAME ].pwszValues = NULL;
  1142. cmdOptions[ OI_Q_USER_NAME ].dwCount = 1;
  1143. cmdOptions[ OI_Q_USER_NAME ].dwActuals = 0;
  1144. cmdOptions[ OI_Q_USER_NAME ].dwFlags = CP2_ALLOCMEMORY |CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL;
  1145. cmdOptions[ OI_Q_USER_NAME ].pValue = NULL;
  1146. cmdOptions[ OI_Q_USER_NAME ].dwLength = 0;
  1147. cmdOptions[ OI_Q_USER_NAME ].pFunction = NULL;
  1148. cmdOptions[ OI_Q_USER_NAME ].pFunctionData = NULL;
  1149. cmdOptions[ OI_Q_USER_NAME ].dwReserved = 0;
  1150. cmdOptions[ OI_Q_USER_NAME ].pReserved1 = NULL;
  1151. cmdOptions[ OI_Q_USER_NAME ].pReserved2 = NULL;
  1152. cmdOptions[ OI_Q_USER_NAME ].pReserved3 = NULL;
  1153. // -p option password for the given username
  1154. StringCopyA( cmdOptions[ OI_Q_PASSWORD ].szSignature, "PARSER2\0", 8 );
  1155. cmdOptions[ OI_Q_PASSWORD ].dwType = CP_TYPE_TEXT;
  1156. cmdOptions[ OI_Q_PASSWORD ].pwszOptions = szPasswordOption;
  1157. cmdOptions[ OI_Q_PASSWORD ].pwszFriendlyName = NULL;
  1158. cmdOptions[ OI_Q_PASSWORD ].pwszValues = NULL;
  1159. cmdOptions[ OI_Q_PASSWORD ].dwCount = 1;
  1160. cmdOptions[ OI_Q_PASSWORD ].dwActuals = 0;
  1161. cmdOptions[ OI_Q_PASSWORD ].dwFlags = CP2_ALLOCMEMORY | CP2_VALUE_OPTIONAL;
  1162. cmdOptions[ OI_Q_PASSWORD ].pValue = NULL;
  1163. cmdOptions[ OI_Q_PASSWORD ].dwLength = 0;
  1164. cmdOptions[ OI_Q_PASSWORD ].pFunction = NULL;
  1165. cmdOptions[ OI_Q_PASSWORD ].pFunctionData = NULL;
  1166. cmdOptions[ OI_Q_PASSWORD ].dwReserved = 0;
  1167. cmdOptions[ OI_Q_PASSWORD ].pReserved1 = NULL;
  1168. cmdOptions[ OI_Q_PASSWORD ].pReserved2 = NULL;
  1169. cmdOptions[ OI_Q_PASSWORD ].pReserved3 = NULL;
  1170. // -fo (format)
  1171. StringCopyA( cmdOptions[ OI_Q_FORMAT ].szSignature, "PARSER2\0", 8 );
  1172. cmdOptions[ OI_Q_FORMAT ].dwType = CP_TYPE_TEXT;
  1173. cmdOptions[ OI_Q_FORMAT ].pwszOptions = szFormatOption;
  1174. cmdOptions[ OI_Q_FORMAT ].pwszFriendlyName = NULL;
  1175. cmdOptions[ OI_Q_FORMAT ].pwszValues = szFormatValues;
  1176. cmdOptions[ OI_Q_FORMAT ].dwCount = 1;
  1177. cmdOptions[ OI_Q_FORMAT ].dwActuals = 0;
  1178. cmdOptions[ OI_Q_FORMAT ].dwFlags = CP2_MODE_VALUES | CP2_VALUE_TRIMINPUT|
  1179. CP2_VALUE_NONULL | CP2_ALLOCMEMORY;
  1180. cmdOptions[ OI_Q_FORMAT ].pValue = NULL;
  1181. cmdOptions[ OI_Q_FORMAT ].dwLength = MAX_STRING_LENGTH;
  1182. cmdOptions[ OI_Q_FORMAT ].pFunction = NULL;
  1183. cmdOptions[ OI_Q_FORMAT ].pFunctionData = NULL;
  1184. cmdOptions[ OI_Q_FORMAT ].dwReserved = 0;
  1185. cmdOptions[ OI_Q_FORMAT ].pReserved1 = NULL;
  1186. cmdOptions[ OI_Q_FORMAT ].pReserved2 = NULL;
  1187. cmdOptions[ OI_Q_FORMAT ].pReserved3 = NULL;
  1188. //-nh (noheader)
  1189. StringCopyA( cmdOptions[ OI_Q_NO_HEADER ].szSignature, "PARSER2\0", 8 );
  1190. cmdOptions[ OI_Q_NO_HEADER ].dwType = CP_TYPE_BOOLEAN;
  1191. cmdOptions[ OI_Q_NO_HEADER ].pwszOptions = szNoHeadeOption;
  1192. cmdOptions[ OI_Q_NO_HEADER ].pwszFriendlyName = NULL;
  1193. cmdOptions[ OI_Q_NO_HEADER ].pwszValues = NULL;
  1194. cmdOptions[ OI_Q_NO_HEADER ].dwCount = 1;
  1195. cmdOptions[ OI_Q_NO_HEADER ].dwActuals = 0;
  1196. cmdOptions[ OI_Q_NO_HEADER ].dwFlags = 0;
  1197. cmdOptions[ OI_Q_NO_HEADER ].pValue = pbShowNoHeader;
  1198. cmdOptions[ OI_Q_NO_HEADER ].dwLength = 0;
  1199. cmdOptions[ OI_Q_NO_HEADER ].pFunction = NULL;
  1200. cmdOptions[ OI_Q_NO_HEADER ].pFunctionData = NULL;
  1201. cmdOptions[ OI_Q_NO_HEADER ].dwReserved = 0;
  1202. cmdOptions[ OI_Q_NO_HEADER ].pReserved1 = NULL;
  1203. cmdOptions[ OI_Q_NO_HEADER ].pReserved2 = NULL;
  1204. cmdOptions[ OI_Q_NO_HEADER ].pReserved3 = NULL;
  1205. //-v verbose
  1206. StringCopyA( cmdOptions[ OI_Q_VERBOSE ].szSignature, "PARSER2\0", 8 );
  1207. cmdOptions[ OI_Q_VERBOSE ].dwType = CP_TYPE_BOOLEAN;
  1208. cmdOptions[ OI_Q_VERBOSE ].pwszOptions = szVerboseOption;
  1209. cmdOptions[ OI_Q_VERBOSE ].pwszFriendlyName = NULL;
  1210. cmdOptions[ OI_Q_VERBOSE ].pwszValues = NULL;
  1211. cmdOptions[ OI_Q_VERBOSE ].dwCount = 1;
  1212. cmdOptions[ OI_Q_VERBOSE ].dwActuals = 0;
  1213. cmdOptions[ OI_Q_VERBOSE ].dwFlags = 0;
  1214. cmdOptions[ OI_Q_VERBOSE ].pValue = pbVerbose;
  1215. cmdOptions[ OI_Q_VERBOSE ].dwLength = 0;
  1216. cmdOptions[ OI_Q_VERBOSE ].pFunction = NULL;
  1217. cmdOptions[ OI_Q_VERBOSE ].pFunctionData = NULL;
  1218. cmdOptions[ OI_Q_VERBOSE ].dwReserved = 0;
  1219. cmdOptions[ OI_Q_VERBOSE ].pReserved1 = NULL;
  1220. cmdOptions[ OI_Q_VERBOSE ].pReserved2 = NULL;
  1221. cmdOptions[ OI_Q_VERBOSE ].pReserved3 = NULL;
  1222. //
  1223. // do the command line parsing
  1224. if ( FALSE == DoParseParam2( argc,argv,OI_Q_QUERY, MAX_QUERY_OPTIONS,cmdOptions,0 ))
  1225. {
  1226. // invalid syntax
  1227. ShowMessage(stderr,GetResString(IDS_ID_SHOW_ERROR));
  1228. return FALSE;
  1229. }
  1230. *pszServer = (LPTSTR)cmdOptions[ OI_Q_SERVER_NAME ].pValue;
  1231. *pszUserName = (LPTSTR)cmdOptions[ OI_Q_USER_NAME ].pValue;
  1232. *pszPassword = (LPTSTR)cmdOptions[ OI_Q_PASSWORD ].pValue;
  1233. *pszFormat = (LPTSTR)cmdOptions[ OI_Q_FORMAT ].pValue;
  1234. // -n is allowed only with -fo TABLE (which is also default)
  1235. // and CSV.
  1236. if(( TRUE == *pbShowNoHeader) && (1 == cmdOptions[ OI_Q_FORMAT ].dwActuals) &&
  1237. (0 == StringCompare(*pszFormat,GetResString(IDS_LIST),TRUE,0)))
  1238. {
  1239. StringCopy(szTemp,GetResString(IDS_HEADER_NOT_ALLOWED),
  1240. SIZE_OF_ARRAY(szTemp));
  1241. StringConcat(szTemp,szTypeHelpMsg,SIZE_OF_ARRAY(szTemp));
  1242. SetReason(szTemp);
  1243. return FALSE;
  1244. }
  1245. // "-p" should not be specified without "-u"
  1246. if ( 0 == cmdOptions[ OI_Q_USER_NAME ].dwActuals &&
  1247. 0 != cmdOptions[ OI_Q_PASSWORD ].dwActuals)
  1248. {
  1249. // invalid syntax
  1250. StringCopy(szTemp,ERROR_PASSWORD_BUT_NOUSERNAME,SIZE_OF_ARRAY(szTemp));
  1251. StringConcat(szTemp,szTypeHelpMsg,SIZE_OF_ARRAY(szTemp));
  1252. SetReason(szTemp);
  1253. return FALSE;
  1254. }
  1255. if(*pbQuery==FALSE)
  1256. {
  1257. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  1258. SetReason(szTemp);
  1259. return FALSE;
  1260. }
  1261. // "-u" should not be specified without "-s"
  1262. if ( 0 == cmdOptions[ OI_Q_SERVER_NAME ].dwActuals &&
  1263. 0 != cmdOptions[ OI_Q_USER_NAME ].dwActuals)
  1264. {
  1265. // invalid syntax
  1266. StringCopy(szTemp,ERROR_USERNAME_BUT_NOMACHINE, SIZE_OF_ARRAY(szTemp));
  1267. StringConcat(szTemp,szTypeHelpMsg,SIZE_OF_ARRAY(szTemp));
  1268. SetReason(szTemp);
  1269. return FALSE;
  1270. }
  1271. // check the remote connectivity information
  1272. if ( *pszServer != NULL )
  1273. {
  1274. //
  1275. // if -u is not specified, we need to allocate memory
  1276. // in order to be able to retrive the current user name
  1277. //
  1278. // case 1: -p is not at all specified
  1279. // as the value for this switch is optional, we have to rely
  1280. // on the dwActuals to determine whether the switch is specified or not
  1281. // in this case utility needs to try to connect first and if it fails
  1282. // then prompt for the password -- in fact, we need not check for this
  1283. // condition explicitly except for noting that we need to prompt for the
  1284. // password
  1285. //
  1286. // case 2: -p is specified
  1287. // but we need to check whether the value is specified or not
  1288. // in this case user wants the utility to prompt for the password
  1289. // before trying to connect
  1290. //
  1291. // case 3: -p * is specified
  1292. // user name
  1293. if ( *pszUserName == NULL )
  1294. {
  1295. *pszUserName = (LPTSTR) AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1296. if ( *pszUserName == NULL )
  1297. {
  1298. SaveLastError();
  1299. return FALSE;
  1300. }
  1301. }
  1302. // password
  1303. if ( *pszPassword == NULL )
  1304. {
  1305. *pbNeedPassword = TRUE;
  1306. *pszPassword = (LPTSTR)AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1307. if ( *pszPassword == NULL )
  1308. {
  1309. SaveLastError();
  1310. return FALSE;
  1311. }
  1312. }
  1313. // case 1
  1314. if ( cmdOptions[ OI_Q_PASSWORD ].dwActuals == 0 )
  1315. {
  1316. // we need not do anything special here
  1317. }
  1318. // case 2
  1319. else if ( cmdOptions[ OI_Q_PASSWORD ].pValue == NULL )
  1320. {
  1321. StringCopy( *pszPassword, L"*", GetBufferSize((LPVOID)*pszPassword));
  1322. }
  1323. // case 3
  1324. else if ( StringCompareEx( *pszPassword, L"*", TRUE, 0 ) == 0 )
  1325. {
  1326. if ( ReallocateMemory( (LPVOID*)pszPassword,
  1327. MAX_STRING_LENGTH * sizeof( WCHAR ) ) == FALSE )
  1328. {
  1329. SaveLastError();
  1330. return FALSE;
  1331. }
  1332. // ...
  1333. *pbNeedPassword = TRUE;
  1334. }
  1335. }
  1336. return TRUE;
  1337. }
  1338. BOOL
  1339. ProcessOptions(
  1340. IN DWORD argc,
  1341. IN LPCTSTR argv[],
  1342. OUT PBOOL pbDisconnect,
  1343. OUT LPTSTR* pszServer,
  1344. OUT LPTSTR* pszUserName,
  1345. OUT LPTSTR* pszPassword,
  1346. OUT LPTSTR* pszID,
  1347. OUT LPTSTR* pszAccessedby,
  1348. OUT LPTSTR* pszOpenmode,
  1349. OUT LPTSTR* pszOpenFile,
  1350. OUT PBOOL pbNeedPassword
  1351. )
  1352. /*++
  1353. Routine Description:
  1354. This function takes command line argument and checks for correct syntax and
  1355. if the syntax is ok, it returns the values in different variables. variables
  1356. [out] will contain respective values. This Functin specifically checks
  1357. command line parameters requered for DISCONNECT option.
  1358. Arguments:
  1359. [in] argc - Number of command line arguments
  1360. [in] argv - Array containing command line arguments
  1361. [out] pbDisconnect - discoonect option string
  1362. [out] pszServer - remote server name
  1363. [out] pszUserName - username for the remote system
  1364. [out] pszPassword - password for the remote system for the
  1365. username
  1366. [out] pszID - Open file ids
  1367. [out] pszAccessedby - Name of user name who access the file
  1368. [out] pszOpenmode - accessed mode (read/Write)
  1369. [out] pszOpenFile - Open file name
  1370. [out] pbNeedPassword - To check whether the password is required
  1371. or not.
  1372. Returned Value:
  1373. BOOL --True if it succeeds
  1374. --False if it fails.
  1375. --*/
  1376. {
  1377. //Variable to store command line
  1378. TCMDPARSER2 cmdOptions[ MAX_DISCONNECT_OPTIONS ];
  1379. CHString szTempString;
  1380. TCHAR szTemp[MIN_MEMORY_REQUIRED*2];
  1381. TCHAR szTypeHelpMsg[MIN_MEMORY_REQUIRED];
  1382. TCHAR szOpenModeValues[MAX_STRING_LENGTH];
  1383. SecureZeroMemory(szOpenModeValues,sizeof(TCHAR)*MAX_STRING_LENGTH);
  1384. szTempString = GetResString(IDS_UTILITY_NAME);
  1385. StringCchPrintfW( szTemp,SIZE_OF_ARRAY(szTemp),
  1386. GetResString(IDS_INVALID_SYNTAX),(LPCWSTR)szTempString);
  1387. StringCchPrintfW( szTypeHelpMsg,SIZE_OF_ARRAY(szTypeHelpMsg),
  1388. GetResString(IDS_TYPE_D_HELP),(LPCWSTR)szTempString);
  1389. StringCopy(szOpenModeValues,OPENMODE_OPTIONS,SIZE_OF_ARRAY(szOpenModeValues));
  1390. //
  1391. // prepare the command options
  1392. SecureZeroMemory(cmdOptions,sizeof(TCMDPARSER2)*MAX_DISCONNECT_OPTIONS);
  1393. // -disconnect option for help
  1394. StringCopyA( cmdOptions[ OI_D_DISCONNECT ].szSignature, "PARSER2\0", 8 );
  1395. cmdOptions[ OI_D_DISCONNECT ].dwType = CP_TYPE_BOOLEAN;
  1396. cmdOptions[ OI_D_DISCONNECT ].pwszOptions = szDisconnectOption;
  1397. cmdOptions[ OI_D_DISCONNECT ].pwszFriendlyName = NULL;
  1398. cmdOptions[ OI_D_DISCONNECT ].pwszValues = NULL;
  1399. cmdOptions[ OI_D_DISCONNECT ].dwCount = 1;
  1400. cmdOptions[ OI_D_DISCONNECT ].dwActuals = 0;
  1401. cmdOptions[ OI_D_DISCONNECT ].dwFlags = 0;
  1402. cmdOptions[ OI_D_DISCONNECT ].pValue = pbDisconnect;
  1403. cmdOptions[ OI_D_DISCONNECT ].dwLength = 0;
  1404. cmdOptions[ OI_D_DISCONNECT ].pFunction = NULL;
  1405. cmdOptions[ OI_D_DISCONNECT ].pFunctionData = NULL;
  1406. cmdOptions[ OI_D_DISCONNECT ].dwReserved = 0;
  1407. cmdOptions[ OI_D_DISCONNECT ].pReserved1 = NULL;
  1408. cmdOptions[ OI_D_DISCONNECT ].pReserved2 = NULL;
  1409. cmdOptions[ OI_D_DISCONNECT ].pReserved3 = NULL;
  1410. // -s option remote system name
  1411. StringCopyA( cmdOptions[ OI_D_SERVER_NAME ].szSignature, "PARSER2\0", 8 );
  1412. cmdOptions[ OI_D_SERVER_NAME ].dwType = CP_TYPE_TEXT;
  1413. cmdOptions[ OI_D_SERVER_NAME ].pwszOptions = szServerNameOption;
  1414. cmdOptions[ OI_D_SERVER_NAME ].pwszFriendlyName = NULL;
  1415. cmdOptions[ OI_D_SERVER_NAME ].pwszValues = NULL;
  1416. cmdOptions[ OI_D_SERVER_NAME ].dwCount = 1;
  1417. cmdOptions[ OI_D_SERVER_NAME ].dwActuals = 0;
  1418. cmdOptions[ OI_D_SERVER_NAME ].dwFlags = CP2_ALLOCMEMORY|CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL;
  1419. cmdOptions[ OI_D_SERVER_NAME ].pValue = NULL;
  1420. cmdOptions[ OI_D_SERVER_NAME ].dwLength = 0;
  1421. cmdOptions[ OI_D_SERVER_NAME ].pFunction = NULL;
  1422. cmdOptions[ OI_D_SERVER_NAME ].pFunctionData = NULL;
  1423. cmdOptions[ OI_D_SERVER_NAME ].dwReserved = 0;
  1424. cmdOptions[ OI_D_SERVER_NAME ].pReserved1 = NULL;
  1425. cmdOptions[ OI_D_SERVER_NAME ].pReserved2 = NULL;
  1426. cmdOptions[ OI_D_SERVER_NAME ].pReserved3 = NULL;
  1427. // -u option user name for the specified system
  1428. StringCopyA( cmdOptions[ OI_D_USER_NAME ].szSignature, "PARSER2\0", 8 );
  1429. cmdOptions[ OI_D_USER_NAME ].dwType = CP_TYPE_TEXT;
  1430. cmdOptions[ OI_D_USER_NAME ].pwszOptions = szUserNameOption;
  1431. cmdOptions[ OI_D_USER_NAME ].pwszFriendlyName = NULL;
  1432. cmdOptions[ OI_D_USER_NAME ].pwszValues = NULL;
  1433. cmdOptions[ OI_D_USER_NAME ].dwCount = 1;
  1434. cmdOptions[ OI_D_USER_NAME ].dwActuals = 0;
  1435. cmdOptions[ OI_D_USER_NAME ].dwFlags = CP2_ALLOCMEMORY |CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL;
  1436. cmdOptions[ OI_D_USER_NAME ].pValue = NULL;
  1437. cmdOptions[ OI_D_USER_NAME ].dwLength = 0;
  1438. cmdOptions[ OI_D_USER_NAME ].pFunction = NULL;
  1439. cmdOptions[ OI_D_USER_NAME ].pFunctionData = NULL;
  1440. cmdOptions[ OI_D_USER_NAME ].dwReserved = 0;
  1441. cmdOptions[ OI_D_USER_NAME ].pReserved1 = NULL;
  1442. cmdOptions[ OI_D_USER_NAME ].pReserved2 = NULL;
  1443. cmdOptions[ OI_D_USER_NAME ].pReserved3 = NULL;
  1444. // -p option password for the given username
  1445. StringCopyA( cmdOptions[ OI_D_PASSWORD ].szSignature, "PARSER2\0", 8 );
  1446. cmdOptions[ OI_D_PASSWORD ].dwType = CP_TYPE_TEXT;
  1447. cmdOptions[ OI_D_PASSWORD ].pwszOptions = szPasswordOption;
  1448. cmdOptions[ OI_D_PASSWORD ].pwszFriendlyName = NULL;
  1449. cmdOptions[ OI_D_PASSWORD ].pwszValues = NULL;
  1450. cmdOptions[ OI_D_PASSWORD ].dwCount = 1;
  1451. cmdOptions[ OI_D_PASSWORD ].dwActuals = 0;
  1452. cmdOptions[ OI_D_PASSWORD ].dwFlags = CP2_ALLOCMEMORY | CP2_VALUE_OPTIONAL;
  1453. cmdOptions[ OI_D_PASSWORD ].pValue = NULL;
  1454. cmdOptions[ OI_D_PASSWORD ].dwLength = 0;
  1455. cmdOptions[ OI_D_PASSWORD ].pFunction = NULL;
  1456. cmdOptions[ OI_D_PASSWORD ].pFunctionData = NULL;
  1457. cmdOptions[ OI_D_PASSWORD ].dwReserved = 0;
  1458. cmdOptions[ OI_D_PASSWORD ].pReserved1 = NULL;
  1459. cmdOptions[ OI_D_PASSWORD ].pReserved2 = NULL;
  1460. cmdOptions[ OI_D_PASSWORD ].pReserved3 = NULL;
  1461. // -id Values
  1462. StringCopyA( cmdOptions[ OI_D_ID ].szSignature, "PARSER2\0", 8 );
  1463. cmdOptions[ OI_D_ID ].dwType = CP_TYPE_TEXT;
  1464. cmdOptions[ OI_D_ID ].pwszOptions = szIDOption;
  1465. cmdOptions[ OI_D_ID ].pwszFriendlyName = NULL;
  1466. cmdOptions[ OI_D_ID ].pwszValues = NULL;
  1467. cmdOptions[ OI_D_ID ].dwCount = 1;
  1468. cmdOptions[ OI_D_ID ].dwActuals = 0;
  1469. cmdOptions[ OI_D_ID ].dwFlags = CP2_ALLOCMEMORY|CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL;
  1470. cmdOptions[ OI_D_ID ].pValue = NULL;
  1471. cmdOptions[ OI_D_ID ].dwLength = 0;
  1472. cmdOptions[ OI_D_ID ].pFunction = NULL;
  1473. cmdOptions[ OI_D_ID ].pFunctionData = NULL;
  1474. cmdOptions[ OI_D_ID ].dwReserved = 0;
  1475. cmdOptions[ OI_D_ID ].pReserved1 = NULL;
  1476. cmdOptions[ OI_D_ID ].pReserved2 = NULL;
  1477. cmdOptions[ OI_D_ID ].pReserved3 = NULL;
  1478. // -a (accessed by)
  1479. StringCopyA( cmdOptions[ OI_D_ACCESSED_BY ].szSignature, "PARSER2\0", 8 );
  1480. cmdOptions[ OI_D_ACCESSED_BY ].dwType = CP_TYPE_TEXT;
  1481. cmdOptions[ OI_D_ACCESSED_BY ].pwszOptions = szAccessedByOption;
  1482. cmdOptions[ OI_D_ACCESSED_BY ].pwszFriendlyName = NULL;
  1483. cmdOptions[ OI_D_ACCESSED_BY ].pwszValues = NULL;
  1484. cmdOptions[ OI_D_ACCESSED_BY ].dwCount = 1;
  1485. cmdOptions[ OI_D_ACCESSED_BY ].dwActuals = 0;
  1486. cmdOptions[ OI_D_ACCESSED_BY ].dwFlags = CP2_ALLOCMEMORY|CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL;
  1487. cmdOptions[ OI_D_ACCESSED_BY ].pValue = NULL;
  1488. cmdOptions[ OI_D_ACCESSED_BY ].dwLength = 0;
  1489. cmdOptions[ OI_D_ACCESSED_BY ].pFunction = NULL;
  1490. cmdOptions[ OI_D_ACCESSED_BY ].pFunctionData = NULL;
  1491. cmdOptions[ OI_D_ACCESSED_BY ].dwReserved = 0;
  1492. cmdOptions[ OI_D_ACCESSED_BY ].pReserved1 = NULL;
  1493. cmdOptions[ OI_D_ACCESSED_BY ].pReserved2 = NULL;
  1494. cmdOptions[ OI_D_ACCESSED_BY ].pReserved3 = NULL;
  1495. // -o (openmode)
  1496. StringCopyA( cmdOptions[ OI_D_OPEN_MODE ].szSignature, "PARSER2\0", 8 );
  1497. cmdOptions[ OI_D_OPEN_MODE ].dwType = CP_TYPE_TEXT;
  1498. cmdOptions[ OI_D_OPEN_MODE ].pwszOptions = szOpenModeOption;
  1499. cmdOptions[ OI_D_OPEN_MODE ].pwszFriendlyName = NULL;
  1500. cmdOptions[ OI_D_OPEN_MODE ].pwszValues = szOpenModeValues;
  1501. cmdOptions[ OI_D_OPEN_MODE ].dwCount = 1;
  1502. cmdOptions[ OI_D_OPEN_MODE ].dwActuals = 0;
  1503. cmdOptions[ OI_D_OPEN_MODE ].dwFlags = CP2_ALLOCMEMORY|CP2_VALUE_TRIMINPUT|
  1504. CP2_VALUE_NONULL|CP2_MODE_VALUES;
  1505. cmdOptions[ OI_D_OPEN_MODE ].pValue = NULL;
  1506. cmdOptions[ OI_D_OPEN_MODE ].dwLength = 0;
  1507. cmdOptions[ OI_D_OPEN_MODE ].pFunction = NULL;
  1508. cmdOptions[ OI_D_OPEN_MODE ].pFunctionData = NULL;
  1509. cmdOptions[ OI_D_OPEN_MODE ].dwReserved = 0;
  1510. cmdOptions[ OI_D_OPEN_MODE ].pReserved1 = NULL;
  1511. cmdOptions[ OI_D_OPEN_MODE ].pReserved2 = NULL;
  1512. cmdOptions[ OI_D_OPEN_MODE ].pReserved3 = NULL;
  1513. // -op (openfile)
  1514. StringCopyA( cmdOptions[ OI_D_OPEN_FILE ].szSignature, "PARSER2\0", 8 );
  1515. cmdOptions[ OI_D_OPEN_FILE ].dwType = CP_TYPE_TEXT;
  1516. cmdOptions[ OI_D_OPEN_FILE ].pwszOptions = szOpenFileOption;
  1517. cmdOptions[ OI_D_OPEN_FILE ].pwszFriendlyName = NULL;
  1518. cmdOptions[ OI_D_OPEN_FILE ].pwszValues = NULL;
  1519. cmdOptions[ OI_D_OPEN_FILE ].dwCount = 1;
  1520. cmdOptions[ OI_D_OPEN_FILE ].dwActuals = 0;
  1521. cmdOptions[ OI_D_OPEN_FILE ].dwFlags = CP2_ALLOCMEMORY|CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL;
  1522. cmdOptions[ OI_D_OPEN_FILE ].pValue = NULL;
  1523. cmdOptions[ OI_D_OPEN_FILE ].dwLength = 0;
  1524. cmdOptions[ OI_D_OPEN_FILE ].pFunction = NULL;
  1525. cmdOptions[ OI_D_OPEN_FILE ].pFunctionData = NULL;
  1526. cmdOptions[ OI_D_OPEN_FILE ].dwReserved = 0;
  1527. cmdOptions[ OI_D_OPEN_FILE ].pReserved1 = NULL;
  1528. cmdOptions[ OI_D_OPEN_FILE ].pReserved2 = NULL;
  1529. cmdOptions[ OI_D_OPEN_FILE ].pReserved3 = NULL;
  1530. //
  1531. // do the command line parsing.
  1532. if ( FALSE == DoParseParam2( argc,argv,OI_D_DISCONNECT, MAX_DISCONNECT_OPTIONS ,cmdOptions,0))
  1533. {
  1534. // invalid syntax.
  1535. ShowMessage(stderr,GetResString(IDS_ID_SHOW_ERROR));
  1536. return FALSE;
  1537. }
  1538. // Take values from parcer structure.
  1539. *pszServer = (LPTSTR)cmdOptions[ OI_D_SERVER_NAME ].pValue;
  1540. *pszUserName = (LPTSTR)cmdOptions[ OI_D_USER_NAME ].pValue;
  1541. *pszPassword = (LPTSTR)cmdOptions[ OI_D_PASSWORD ].pValue;
  1542. *pszID = (LPTSTR)cmdOptions[ OI_D_ID ].pValue;
  1543. *pszAccessedby = (LPTSTR)cmdOptions[ OI_D_ACCESSED_BY ].pValue;
  1544. *pszOpenmode = (LPTSTR)cmdOptions[ OI_D_OPEN_MODE ].pValue;
  1545. *pszOpenFile = (LPTSTR)cmdOptions[ OI_D_OPEN_FILE ].pValue;
  1546. if(*pbDisconnect==FALSE)
  1547. {
  1548. ShowMessage( stderr, GetResString(IDS_ID_SHOW_ERROR) );
  1549. SetReason(szTemp);
  1550. return FALSE;
  1551. }
  1552. // At least one of -id OR -a OR -o is required.
  1553. if((cmdOptions[ OI_D_ID ].dwActuals==0)&&
  1554. (cmdOptions[ OI_D_ACCESSED_BY ].dwActuals==0)&&
  1555. (cmdOptions[ OI_D_OPEN_MODE ].dwActuals==0)
  1556. )
  1557. {
  1558. StringCopy(szTemp,GetResString(IDS_NO_ID_ACC_OF),SIZE_OF_ARRAY(szTemp));
  1559. StringConcat(szTemp,szTypeHelpMsg,SIZE_OF_ARRAY(szTemp));
  1560. SetReason(szTemp);
  1561. return FALSE;
  1562. }
  1563. // "-u" should not be specified without "-s"
  1564. if ( 0 == cmdOptions[ OI_D_SERVER_NAME ].dwActuals &&
  1565. 0 != cmdOptions[ OI_D_USER_NAME ].dwActuals)
  1566. {
  1567. // invalid syntax
  1568. StringCopy(szTemp,ERROR_USERNAME_BUT_NOMACHINE, SIZE_OF_ARRAY(szTemp));
  1569. StringConcat(szTemp,szTypeHelpMsg,SIZE_OF_ARRAY(szTemp));
  1570. SetReason(szTemp);
  1571. return FALSE;
  1572. }
  1573. // "-p" should not be specified without "-u"
  1574. if ( 0 == cmdOptions[ OI_D_USER_NAME ].dwActuals &&
  1575. 0 != cmdOptions[ OI_D_PASSWORD ].dwActuals)
  1576. {
  1577. // invalid syntax
  1578. StringCopy(szTemp,ERROR_PASSWORD_BUT_NOUSERNAME, SIZE_OF_ARRAY(szTemp));
  1579. StringConcat(szTemp,szTypeHelpMsg,SIZE_OF_ARRAY(szTemp));
  1580. SetReason(szTemp);
  1581. return FALSE;
  1582. }
  1583. if(1 == cmdOptions[ OI_D_ACCESSED_BY].dwActuals)
  1584. {
  1585. if(FindOneOf(*pszAccessedby,INVALID_USER_CHARS,0))
  1586. {
  1587. StringCopy(szTemp,GetResString(IDS_USER_INVALID_ADMIN),SIZE_OF_ARRAY(szTemp));
  1588. SetReason(szTemp);
  1589. return FALSE;
  1590. }
  1591. }
  1592. if (1 == cmdOptions[ OI_D_OPEN_FILE].dwActuals)
  1593. {
  1594. if(FindOneOf(*pszOpenFile,INVALID_FILE_NAME_CHARS,0))
  1595. {
  1596. StringCopy(szTemp,GetResString(IDS_FILENAME_INVALID),SIZE_OF_ARRAY(szTemp));
  1597. SetReason(szTemp);
  1598. return FALSE;
  1599. }
  1600. }
  1601. // check the remote connectivity information
  1602. if ( *pszServer != NULL )
  1603. {
  1604. //
  1605. // if -u is not specified, we need to allocate memory
  1606. // in order to be able to retrive the current user name
  1607. //
  1608. // case 1: -p is not at all specified
  1609. // as the value for this switch is optional, we have to rely
  1610. // on the dwActuals to determine whether the switch is specified or not
  1611. // in this case utility needs to try to connect first and if it fails
  1612. // then prompt for the password -- in fact, we need not check for this
  1613. // condition explicitly except for noting that we need to prompt for the
  1614. // password
  1615. //
  1616. // case 2: -p is specified
  1617. // but we need to check whether the value is specified or not
  1618. // in this case user wants the utility to prompt for the password
  1619. // before trying to connect
  1620. //
  1621. // case 3: -p * is specified
  1622. // user name
  1623. if ( *pszUserName == NULL )
  1624. {
  1625. *pszUserName = (LPTSTR) AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1626. if ( *pszUserName == NULL )
  1627. {
  1628. SaveLastError();
  1629. return FALSE;
  1630. }
  1631. }
  1632. // password
  1633. if ( *pszPassword == NULL )
  1634. {
  1635. *pbNeedPassword = TRUE;
  1636. *pszPassword = (LPTSTR)AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1637. if ( *pszPassword == NULL )
  1638. {
  1639. SaveLastError();
  1640. return FALSE;
  1641. }
  1642. }
  1643. // case 1
  1644. if ( cmdOptions[ OI_D_PASSWORD ].dwActuals == 0 )
  1645. {
  1646. // we need not do anything special here
  1647. }
  1648. // case 2
  1649. else if ( cmdOptions[ OI_D_PASSWORD ].pValue == NULL )
  1650. {
  1651. StringCopy( *pszPassword, L"*", GetBufferSize((LPVOID)*pszPassword));
  1652. }
  1653. // case 3
  1654. else if ( StringCompareEx( *pszPassword, L"*", TRUE, 0 ) == 0 )
  1655. {
  1656. if ( ReallocateMemory( (LPVOID*)pszPassword,
  1657. MAX_STRING_LENGTH * sizeof( WCHAR ) ) == FALSE )
  1658. {
  1659. SaveLastError();
  1660. return FALSE;
  1661. }
  1662. // ...
  1663. *pbNeedPassword = TRUE;
  1664. }
  1665. }
  1666. // Check if -id option is given and if it is numeric ,
  1667. // also if it is numeric then check its range
  1668. if(1 == cmdOptions[ OI_D_ID ].dwActuals)
  1669. {
  1670. if ( TRUE == IsNumeric((LPCTSTR)(*pszID),10,TRUE))
  1671. {
  1672. if((AsLong((LPCTSTR)(*pszID),10)>UINT_MAX) ||
  1673. (AsLong((LPCTSTR)(*pszID),10)<1))
  1674. {
  1675. // Message shown on screen will be...
  1676. // ERROR: Invlid ID.
  1677. StringCopy(szTemp,GetResString(IDS_ERROR_ID),SIZE_OF_ARRAY(szTemp));
  1678. StringConcat(szTemp,szTypeHelpMsg,SIZE_OF_ARRAY(szTemp));
  1679. SetReason(szTemp);
  1680. return FALSE;
  1681. }
  1682. }
  1683. // check user given "*" or any junk string....
  1684. if(!((StringCompare((LPCTSTR)(*pszID), ASTERIX, FALSE, 0)==0)||
  1685. (IsNumeric((LPCTSTR)(*pszID),10,TRUE)==TRUE))
  1686. &&(StringLength((LPCTSTR)(*pszID), 0)!=0))
  1687. {
  1688. // Message shown on screen will be...
  1689. // ERROR: Invlid ID.
  1690. StringCopy(szTemp,GetResString(IDS_ERROR_ID),SIZE_OF_ARRAY(szTemp));
  1691. StringConcat(szTemp,szTypeHelpMsg,SIZE_OF_ARRAY(szTemp));
  1692. SetReason(szTemp);
  1693. return FALSE;
  1694. }
  1695. }
  1696. return TRUE;
  1697. }
  1698. BOOL
  1699. DisconnectUsage(
  1700. VOID
  1701. )
  1702. /*++
  1703. Routine Description:
  1704. Displays how to use -disconnect option
  1705. Arguments:
  1706. None
  1707. Returned Value:
  1708. TRUE : Function returns successfully.
  1709. FALSE : otherwise.
  1710. --*/
  1711. {
  1712. // local variables
  1713. DWORD dw = 0;
  1714. // start displaying the usage
  1715. for( dw = IDS_HELP_LINE1; dw <= IDS_HELP_LINE_END; dw++ )
  1716. {
  1717. ShowMessage( stdout, GetResString( dw ) );
  1718. }
  1719. return TRUE;
  1720. }//DisconnectUsage
  1721. BOOL
  1722. QueryUsage(
  1723. VOID
  1724. )
  1725. /*++
  1726. Routine Description:
  1727. Displays how to use -query option
  1728. Arguments:
  1729. None
  1730. Returned Value:
  1731. TRUE : Function returns successfully.
  1732. FALSE : otherwise.
  1733. --*/
  1734. {
  1735. // local variables
  1736. DWORD dw = 0;
  1737. // start displaying the usage
  1738. for( dw = IDS_HELP_QUERY1; dw <= IDS_HELP_QUERY_END; dw++ )
  1739. {
  1740. ShowMessage( stdout, GetResString( dw ) );
  1741. }
  1742. return TRUE;
  1743. }//query Usage
  1744. BOOL
  1745. Usage(
  1746. VOID
  1747. )
  1748. /*++
  1749. Routine Description:
  1750. Displays how to use this Utility
  1751. Arguments:
  1752. None
  1753. Returned Value:
  1754. TRUE : Function returns successfully.
  1755. FALSE : otherwise.
  1756. --*/
  1757. {
  1758. // local variables
  1759. DWORD dw = 0;
  1760. // start displaying the usage
  1761. for( dw = IDS_HELP_MAIN1; dw <= IDS_HELP_MAIN_END; dw++ )
  1762. {
  1763. ShowMessage( stdout, GetResString( dw ) );
  1764. }
  1765. return TRUE;
  1766. }//Usage
  1767. BOOL
  1768. LocalUsage()
  1769. /*++
  1770. Routine Description:
  1771. Displays how to use -local option
  1772. Arguments:
  1773. None
  1774. Returned Value:
  1775. TRUE : Function returns successfully.
  1776. FALSE : otherwise.
  1777. --*/
  1778. {
  1779. // local variables
  1780. DWORD dw = 0;
  1781. // start displaying the usage
  1782. for( dw = IDS_HELP_LOCAL1; dw <= IDS_HELP_LOCAL_END; dw++ )
  1783. {
  1784. ShowMessage( stdout, GetResString( dw ) );
  1785. }
  1786. return TRUE;
  1787. }//-local
  1788. DWORD
  1789. CheckSystemType(
  1790. IN LPTSTR szServer
  1791. )
  1792. /*++
  1793. Routine Description:
  1794. This function returns type of present Operating system.
  1795. As this function is called only in case of 32 bit compilation, its value is
  1796. useful only build for 32 bit compilation.
  1797. Arguments:
  1798. [in] szServer : Server Name.
  1799. Returned Value:
  1800. DWORD:
  1801. EXIT_SUCCESS - If system is 32 bit.
  1802. EXIT_FAILURE - Any error or system is not 32 bit.
  1803. --*/
  1804. {
  1805. DWORD dwSystemType = 0 ;
  1806. #ifndef _WIN64
  1807. //display the error message if the target system is a 64 bit system or if
  1808. // error occured in retreiving the information
  1809. dwSystemType = GetCPUInfo(szServer);
  1810. if( ERROR_RETREIVE_REGISTRY == dwSystemType)
  1811. {
  1812. ShowMessage(stderr,GetResString(IDS_ERROR_SYSTEM_INFO));
  1813. return (EXIT_FAILURE);
  1814. }
  1815. if( SYSTEM_64_BIT == dwSystemType)
  1816. {
  1817. if( 0 == StringLength(szServer, 0))
  1818. {
  1819. ShowMessage(stderr,GetResString(IDS_ERROR_VERSION_MISMATCH));
  1820. }
  1821. else
  1822. {
  1823. ShowMessage(stderr,GetResString(IDS_REMOTE_NOT_SUPPORTED));
  1824. }
  1825. return (EXIT_FAILURE);
  1826. }
  1827. #endif
  1828. return EXIT_SUCCESS ;
  1829. }
  1830. DWORD
  1831. GetCPUInfo(
  1832. IN LPTSTR szComputerName
  1833. )
  1834. /*++
  1835. Routine Description:
  1836. This function determines if the computer is 32 bit system or 64 bit.
  1837. Arguments
  1838. [ in ] szComputerName : System name
  1839. Return Type : BOOL
  1840. TRUE : if the system is a 32 bit system
  1841. FALSE : if the system is a 64 bit system
  1842. --*/
  1843. {
  1844. HKEY hKey1 = 0;
  1845. HKEY hRemoteKey = 0;
  1846. TCHAR szCurrentPath[MAX_STRING_LENGTH + 1];
  1847. TCHAR szPath[MAX_STRING_LENGTH + 1] = SUBKEY ;
  1848. DWORD dwValueSize = MAX_STRING_LENGTH+1;
  1849. DWORD dwRetCode = ERROR_SUCCESS;
  1850. DWORD dwError = 0;
  1851. TCHAR szTmpCompName[MAX_STRING_LENGTH+1];
  1852. TCHAR szTemp[MIN_MEMORY_REQUIRED];
  1853. TCHAR szVal[MIN_MEMORY_REQUIRED];
  1854. DWORD dwLength = MAX_STRING_LENGTH + 10;
  1855. LPTSTR szReturnValue = NULL ;
  1856. DWORD dwCode = 0 ;
  1857. szReturnValue = ( LPTSTR ) AllocateMemory( dwLength*sizeof( TCHAR ) );
  1858. if( NULL == szReturnValue)
  1859. {
  1860. return ERROR_RETREIVE_REGISTRY ;
  1861. }
  1862. SecureZeroMemory(szCurrentPath, SIZE_OF_ARRAY(szCurrentPath));
  1863. SecureZeroMemory(szTmpCompName, SIZE_OF_ARRAY(szTmpCompName));
  1864. SecureZeroMemory(szTemp, SIZE_OF_ARRAY(szTemp));
  1865. SecureZeroMemory(szVal, SIZE_OF_ARRAY( szVal));
  1866. if( 0 != StringLength(szComputerName,0))
  1867. {
  1868. StringCopy(szTmpCompName,TOKEN_BACKSLASH4,SIZE_OF_ARRAY(szTmpCompName));
  1869. StringConcat(szTmpCompName,szComputerName,SIZE_OF_ARRAY(szTmpCompName));
  1870. }
  1871. else
  1872. {
  1873. StringCopy(szTmpCompName,szComputerName,SIZE_OF_ARRAY(szTmpCompName));
  1874. }
  1875. // Get Remote computer local machine key
  1876. dwError = RegConnectRegistry(szTmpCompName,HKEY_LOCAL_MACHINE,&hRemoteKey);
  1877. if ( ERROR_SUCCESS == dwError)
  1878. {
  1879. dwError = RegOpenKeyEx(hRemoteKey,szPath,0,KEY_READ,&hKey1);
  1880. if ( ERROR_SUCCESS == dwError)
  1881. {
  1882. dwRetCode = RegQueryValueEx(hKey1, IDENTIFIER_VALUE, NULL, NULL,
  1883. (LPBYTE) szReturnValue, &dwValueSize);
  1884. if ( ERROR_MORE_DATA == dwRetCode)
  1885. {
  1886. if (!ReallocateMemory((LPVOID *)&szReturnValue, dwValueSize*sizeof( TCHAR )))
  1887. {
  1888. RegCloseKey(hKey1);
  1889. RegCloseKey(hRemoteKey);
  1890. FreeMemory( (LPVOID *)&szReturnValue );
  1891. return ERROR_RETREIVE_REGISTRY ;
  1892. }
  1893. dwRetCode = RegQueryValueEx(hKey1, IDENTIFIER_VALUE, NULL, NULL,
  1894. (LPBYTE) szReturnValue, &dwValueSize);
  1895. }
  1896. if ( ERROR_SUCCESS != dwRetCode)
  1897. {
  1898. FreeMemory((LPVOID*)&szReturnValue);
  1899. RegCloseKey(hKey1);
  1900. RegCloseKey(hRemoteKey);
  1901. return ERROR_RETREIVE_REGISTRY ;
  1902. }
  1903. }
  1904. else
  1905. {
  1906. FreeMemory( (LPVOID*)&szReturnValue);
  1907. RegCloseKey(hRemoteKey);
  1908. return ERROR_RETREIVE_REGISTRY ;
  1909. }
  1910. RegCloseKey(hKey1);
  1911. }
  1912. else
  1913. {
  1914. FreeMemory((LPVOID*)&szReturnValue);
  1915. RegCloseKey(hRemoteKey);
  1916. return ERROR_RETREIVE_REGISTRY ;
  1917. }
  1918. RegCloseKey(hRemoteKey);
  1919. StringCopy(szVal,X86_MACHINE, SIZE_OF_ARRAY(szVal));
  1920. //check if the specified system contains the words x86 (belongs to the 32 )
  1921. // set the flag to true if the specified system is 64 bit .
  1922. if( !FindString(szReturnValue,szVal,0))
  1923. {
  1924. dwCode = SYSTEM_64_BIT ;
  1925. }
  1926. else
  1927. {
  1928. dwCode = SYSTEM_32_BIT ;
  1929. }
  1930. FreeMemory((LPVOID*)&szReturnValue);
  1931. return dwCode ;
  1932. }//GetCPUInfo
  1933. DWORD
  1934. CheckSystemType64(
  1935. IN LPTSTR szServer
  1936. )
  1937. /*++
  1938. Routine Description:
  1939. This function returns type of present Operating system.
  1940. As this function is called only in case of 64 bit compilation, its value is
  1941. useful only build for 64 bit compilation.
  1942. Arguments:
  1943. [in] szServer : Server Name.
  1944. Returned Value:
  1945. DWORD:
  1946. EXIT_SUCCESS - If system is 64 bit.
  1947. EXIT_FAILURE - Any error or system is not 64 bit.
  1948. --*/
  1949. {
  1950. if( NULL == szServer)
  1951. {
  1952. ShowMessage(stderr,GetResString(IDS_ERROR_SYSTEM_INFO));
  1953. return (EXIT_FAILURE);
  1954. }
  1955. #ifdef _WIN64
  1956. DWORD dwSystemType = 0 ;
  1957. //display the error message if the target system is a 64 bit system or
  1958. //if error occured in retreiving the information
  1959. dwSystemType = GetCPUInfo(szServer);
  1960. if( ERROR_RETREIVE_REGISTRY == dwSystemType)
  1961. {
  1962. ShowMessage(stderr,GetResString(IDS_ERROR_SYSTEM_INFO));
  1963. return (EXIT_FAILURE);
  1964. }
  1965. if( SYSTEM_32_BIT == dwSystemType)
  1966. {
  1967. if( 0 == StringLength(szServer,0))
  1968. {
  1969. ShowMessage(stderr,GetResString(IDS_ERROR_VERSION_MISMATCH1));
  1970. }
  1971. else
  1972. {
  1973. ShowMessage(stderr,GetResString(IDS_REMOTE_NOT_SUPPORTED1));
  1974. }
  1975. return (EXIT_FAILURE);
  1976. }
  1977. #endif
  1978. return EXIT_SUCCESS ;
  1979. }