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.

469 lines
15 KiB

  1. /****************************************************************************
  2. Copyright information : Copyright (c) 1998-1999 Microsoft Corporation
  3. File Name : ParsedInfo.cpp
  4. Project Name : WMI Command Line
  5. Author Name : Ch. Sriramachandramurthy
  6. Date of Creation (dd/mm/yy) : 27th-September-2000
  7. Version Number : 1.0
  8. Revision History :
  9. Last Modified by : Ch. Sriramachandramurthy
  10. Last Modified Date : 11th-April-2001
  11. ****************************************************************************/
  12. #include "Precomp.h"
  13. #include "CommandSwitches.h"
  14. #include "GlobalSwitches.h"
  15. #include "HelpInfo.h"
  16. #include "ErrorLog.h"
  17. #include "ParsedInfo.h"
  18. /*------------------------------------------------------------------------
  19. Name :CParsedInfo
  20. Synopsis :This function initializes the member variables when
  21. an object of the class type is instantiated
  22. Type :Constructor
  23. Input parameter :None
  24. Output parameters :None
  25. Return Type :None
  26. Global Variables :None
  27. Calling Syntax :None
  28. Notes :None
  29. ------------------------------------------------------------------------*/
  30. CParsedInfo::CParsedInfo()
  31. {
  32. lstrcpy( m_pszPwd, NULL_STRING );
  33. }
  34. /*------------------------------------------------------------------------
  35. Name :~CParsedInfo
  36. Synopsis :This function uninitializes the member variables
  37. when an object of the class type goes out of scope.
  38. Type :Destructor
  39. Input parameter :None
  40. Output parameters :None
  41. Return Type :None
  42. Global Variables :None
  43. Calling Syntax :None
  44. Notes :None
  45. ------------------------------------------------------------------------*/
  46. CParsedInfo::~CParsedInfo()
  47. {
  48. m_GlblSwitches.Uninitialize();
  49. m_CmdSwitches.Uninitialize();
  50. }
  51. /*------------------------------------------------------------------------
  52. Name :GetCmdSwitchesObject
  53. Synopsis :This function returns CCommandSwitches object data
  54. member m_CmdSwitches
  55. Type :Member Function
  56. Input parameter :None
  57. Output parameters :None
  58. Return Type :CCommandSwitches&
  59. Global Variables :None
  60. Calling Syntax :GetCmdSwitchesObject()
  61. Notes :None
  62. ------------------------------------------------------------------------*/
  63. CCommandSwitches& CParsedInfo::GetCmdSwitchesObject()
  64. {
  65. return m_CmdSwitches;
  66. }
  67. /*------------------------------------------------------------------------
  68. Name :GetGlblSwitchesObject
  69. Synopsis :This function returns CGlblSwitches object data
  70. member m_GlblSwitches
  71. Type :Member Function
  72. Input parameter :None
  73. Output parameters :None
  74. Return Type :CGlobalSwitches&
  75. Calling Syntax :GetGlblSwitchesObject()
  76. Notes :None
  77. ------------------------------------------------------------------------*/
  78. CGlobalSwitches& CParsedInfo::GetGlblSwitchesObject()
  79. {
  80. return m_GlblSwitches;
  81. }
  82. /*------------------------------------------------------------------------
  83. Name :GetHelpInfoObject
  84. Synopsis :This function returns CHelpInfo object data
  85. member m_HelpInfo
  86. Type :Member Function
  87. Input parameter :None
  88. Output parameters :None
  89. Return Type :CHelpInfo&
  90. Calling Syntax :GetHelpInfoObject()
  91. Notes :None
  92. ------------------------------------------------------------------------*/
  93. CHelpInfo& CParsedInfo::GetHelpInfoObject()
  94. {
  95. return m_HelpInfo;
  96. }
  97. /*------------------------------------------------------------------------
  98. Name :GetErrorLogObject
  99. Synopsis :This function returns CErrorLog object data
  100. member m_ErrorLog
  101. Type :Member Function
  102. Input parameter :None
  103. Output parameters :None
  104. Return Type :CErrorLog&
  105. Calling Syntax :GetHelpInfoObject()
  106. Notes :None
  107. ------------------------------------------------------------------------*/
  108. CErrorLog& CParsedInfo::GetErrorLogObject()
  109. {
  110. return m_ErrorLog;
  111. }
  112. /*------------------------------------------------------------------------
  113. Name :Initialize
  114. Synopsis :This function Initializes the CParedInfo object.
  115. Type :Member Function
  116. Input parameter :None
  117. Output parameters :None
  118. Return Type :Void
  119. Calling Syntax :Initialize()
  120. Notes :None
  121. ------------------------------------------------------------------------*/
  122. void CParsedInfo::Initialize()
  123. {
  124. m_bNewCmd = TRUE;
  125. m_bNewCycle = TRUE;
  126. m_CmdSwitches.Initialize();
  127. m_GlblSwitches.Initialize();
  128. m_HelpInfo.Initialize();
  129. }
  130. /*------------------------------------------------------------------------
  131. Name :Uninitialize
  132. Synopsis :This function uninitializes the CGlobalSwitches and
  133. CCommandSwitches object
  134. Type :Member Function
  135. Input parameter :bBoth - boolean value
  136. Output parameters :None
  137. Return Type :
  138. Calling Syntax :Uninitialize(bBoth)
  139. Notes :None
  140. ------------------------------------------------------------------------*/
  141. void CParsedInfo::Uninitialize(BOOL bBoth)
  142. {
  143. // If session termination
  144. if (bBoth)
  145. {
  146. m_GlblSwitches.Uninitialize();
  147. m_CmdSwitches.Uninitialize();
  148. }
  149. // if new command
  150. else
  151. {
  152. m_CmdSwitches.Uninitialize();
  153. }
  154. m_bNewCmd = TRUE;
  155. m_bNewCycle = TRUE;
  156. }
  157. /*------------------------------------------------------------------------
  158. Name :GetUser
  159. Synopsis :Returns the user name
  160. Type :Member Function
  161. Input parameter :None
  162. Output parameters :None
  163. Return Type :_TCHAR*
  164. Calling Syntax :GetUser()
  165. Notes :None
  166. ------------------------------------------------------------------------*/
  167. _TCHAR* CParsedInfo::GetUser()
  168. {
  169. // Check if alias name is available
  170. if (m_CmdSwitches.GetAliasName())
  171. {
  172. // Check if /USER global switch is not explicitly
  173. // specified.
  174. if (!(m_GlblSwitches.GetConnInfoFlag() & USER))
  175. {
  176. // Check if alias user is not NULL, if so
  177. // return the alias user name
  178. if (m_CmdSwitches.GetAliasUser())
  179. {
  180. return m_CmdSwitches.GetAliasUser();
  181. }
  182. }
  183. }
  184. return m_GlblSwitches.GetUser();
  185. }
  186. /*------------------------------------------------------------------------
  187. Name :GetNode
  188. Synopsis :Returns the node name
  189. Type :Member Function
  190. Input parameter :None
  191. Output parameters :None
  192. Return Type :_TCHAR*
  193. Calling Syntax :GetNode()
  194. Notes :None
  195. ------------------------------------------------------------------------*/
  196. _TCHAR* CParsedInfo::GetNode()
  197. {
  198. // Check if alias name is available
  199. if (m_CmdSwitches.GetAliasName())
  200. {
  201. // Check if /NODE global switch is not explicitly
  202. // specified.
  203. if (!(m_GlblSwitches.GetConnInfoFlag() & NODE))
  204. {
  205. // Check if alias node name is not NULL, if so
  206. // return the alias node name
  207. if (m_CmdSwitches.GetAliasNode())
  208. {
  209. return m_CmdSwitches.GetAliasNode();
  210. }
  211. }
  212. }
  213. return m_GlblSwitches.GetNode();
  214. }
  215. /*------------------------------------------------------------------------
  216. Name :GetLocale
  217. Synopsis :Returns the locale value
  218. Type :Member Function
  219. Input parameter :None
  220. Output parameters :None
  221. Return Type :_TCHAR*
  222. Calling Syntax :GetLocale()
  223. Notes :None
  224. ------------------------------------------------------------------------*/
  225. _TCHAR* CParsedInfo::GetLocale()
  226. {
  227. // Check if alias name is available
  228. if (m_CmdSwitches.GetAliasName())
  229. {
  230. // Check if /LOCALE global switch is not explicitly
  231. // specified.
  232. if (!(m_GlblSwitches.GetConnInfoFlag() & LOCALE))
  233. {
  234. // Check if alias locale value is not NULL, if so
  235. // return the alias locale value
  236. if (m_CmdSwitches.GetAliasLocale())
  237. {
  238. return m_CmdSwitches.GetAliasLocale();
  239. }
  240. }
  241. }
  242. // return the locale specified with global switches
  243. return m_GlblSwitches.GetLocale();
  244. }
  245. /*------------------------------------------------------------------------
  246. Name :GetPassword
  247. Synopsis :Returns the password
  248. Type :Member Function
  249. Input parameter :None
  250. Output parameters :None
  251. Return Type :_TCHAR*
  252. Calling Syntax :GetPassword()
  253. Notes :None
  254. ------------------------------------------------------------------------*/
  255. _TCHAR* CParsedInfo::GetPassword()
  256. {
  257. // Check if alias name is available
  258. if (m_CmdSwitches.GetAliasName())
  259. {
  260. // Check if /PASSWORD global switch is not explicitly
  261. // specified.
  262. if (!(m_GlblSwitches.GetConnInfoFlag() & PASSWORD))
  263. {
  264. // Check if alias password value is not NULL, if so
  265. // return the alias password value
  266. if (m_CmdSwitches.GetAliasPassword())
  267. {
  268. return m_CmdSwitches.GetAliasPassword();
  269. }
  270. }
  271. }
  272. // If Credflag is set to FALSE means actual value
  273. // of the password should be passed.
  274. if (!m_CmdSwitches.GetCredentialsFlagStatus())
  275. {
  276. return m_GlblSwitches.GetPassword();
  277. }
  278. else
  279. {
  280. // treat password as BLANK
  281. return m_pszPwd;
  282. }
  283. }
  284. /*------------------------------------------------------------------------
  285. Name :GetNamespace
  286. Synopsis :Returns the namespace value
  287. Type :Member Function
  288. Input parameter :None
  289. Output parameters :None
  290. Return Type :_TCHAR*
  291. Calling Syntax :GetNamespace()
  292. Notes :None
  293. ------------------------------------------------------------------------*/
  294. _TCHAR* CParsedInfo::GetNamespace()
  295. {
  296. // Check if alias name is available
  297. if (m_CmdSwitches.GetAliasName())
  298. {
  299. // Check if alias namespace value is not NULL, if so
  300. // return the alias namespace value (else fallback to
  301. // namespace available with global switch)
  302. if (m_CmdSwitches.GetAliasNamespace())
  303. return m_CmdSwitches.GetAliasNamespace();
  304. }
  305. // return the namespace specified with global switches
  306. return m_GlblSwitches.GetNameSpace();
  307. }
  308. /*------------------------------------------------------------------------
  309. Name :GetUserDesc
  310. Synopsis :Returns the user name, if no user is available returns
  311. "N/A" - used only with CONTEXT (displaying environment
  312. variables)
  313. Type :Member Function
  314. Input parameter :None
  315. Output parameters :
  316. bstrUser - user name string
  317. Return Type :void
  318. Calling Syntax :GetUserDesc()
  319. Notes :None
  320. ------------------------------------------------------------------------*/
  321. void CParsedInfo::GetUserDesc(_bstr_t& bstrUser)
  322. {
  323. // Check if alias name is available
  324. if (m_CmdSwitches.GetAliasName())
  325. {
  326. // Check if /USER global switch is not explicitly
  327. // specified.
  328. if (!(m_GlblSwitches.GetConnInfoFlag() & USER))
  329. {
  330. // Check if alias user is not NULL, if so
  331. // return the alias user name
  332. if (m_CmdSwitches.GetAliasUser())
  333. {
  334. bstrUser = m_CmdSwitches.GetAliasUser();
  335. }
  336. }
  337. }
  338. if (m_GlblSwitches.GetUser())
  339. bstrUser = m_GlblSwitches.GetUser();
  340. else
  341. bstrUser = TOKEN_NA;
  342. }
  343. /*------------------------------------------------------------------------
  344. Name :GetNewCommandStatus
  345. Synopsis :Checks if a command is new or not (used for
  346. logging into xml file)
  347. Type :Member Function
  348. Input parameter :None
  349. Output parameters :None
  350. Return Type :BOOL
  351. Calling Syntax :GetNewCommandStatus()
  352. Notes :None
  353. ------------------------------------------------------------------------*/
  354. BOOL CParsedInfo::GetNewCommandStatus()
  355. {
  356. return m_bNewCmd;
  357. }
  358. /*------------------------------------------------------------------------
  359. Name :SetNewCommandStatus
  360. Synopsis :Sets the status of a new command
  361. Type :Member Function
  362. Input parameter :
  363. bStatus - BOOL type,status of the command
  364. Output parameters :None
  365. Return Type :void
  366. Calling Syntax :SetNewCommandStatus(bStatus)
  367. Notes :None
  368. ------------------------------------------------------------------------*/
  369. void CParsedInfo::SetNewCommandStatus(BOOL bStatus)
  370. {
  371. m_bNewCmd = bStatus;
  372. }
  373. /*------------------------------------------------------------------------
  374. Name :GetNewCycleStatus
  375. Synopsis :Returns the status of the new cycle flag
  376. Type :Member Function
  377. Input parameter :None
  378. Output parameters :None
  379. Return Type :BOOL
  380. Calling Syntax :GetNewCycleStatus()
  381. Notes :None
  382. ------------------------------------------------------------------------*/
  383. BOOL CParsedInfo::GetNewCycleStatus()
  384. {
  385. return m_bNewCycle;
  386. }
  387. /*------------------------------------------------------------------------
  388. Name :SetNewCycleStatus
  389. Synopsis :Sets the status of a new node
  390. Type :Member Function
  391. Input parameter :
  392. bStatus - BOOL type, status of the new cycle
  393. Output parameters :None
  394. Return Type :void
  395. Calling Syntax :SetNewCycleStatus(bStatus)
  396. Notes :None
  397. ------------------------------------------------------------------------*/
  398. void CParsedInfo::SetNewCycleStatus(BOOL bStatus)
  399. {
  400. m_bNewCycle = bStatus;
  401. }
  402. /*------------------------------------------------------------------------
  403. Name :GetAuthorityDesc
  404. Synopsis :Returns the <authority principle>, if no <authority principle>
  405. is available returns "N/A" - used only with CONTEXT
  406. (displaying environment variables)
  407. Type :Member Function
  408. Input parameter :None
  409. Output parameters :
  410. bstrAuthorityPrinciple - <authority principle> string
  411. Return Type :void
  412. Calling Syntax :GetAuthorityDesc()
  413. Notes :None
  414. ------------------------------------------------------------------------*/
  415. void CParsedInfo::GetAuthorityDesc(_bstr_t& bstrAuthorityPrinciple)
  416. {
  417. if (m_GlblSwitches.GetAuthorityPrinciple())
  418. bstrAuthorityPrinciple = m_GlblSwitches.GetAuthorityPrinciple();
  419. else
  420. bstrAuthorityPrinciple = TOKEN_NA;
  421. }
  422. /*------------------------------------------------------------------------
  423. Name :GetAuthorityPrinciple
  424. Synopsis :Returns the authority type.
  425. Type :Member Function
  426. Input parameter :None
  427. Output parameters :None
  428. Return Type :_TCHAR*
  429. Calling Syntax :GetAuthorityPrinciple()
  430. Notes :None
  431. ------------------------------------------------------------------------*/
  432. _TCHAR* CParsedInfo::GetAuthorityPrinciple()
  433. {
  434. // Check if alias name is available
  435. if (m_CmdSwitches.GetAliasName())
  436. {
  437. // Check if /AUTHORITY global switch is not explicitly
  438. // specified.
  439. if (!(m_GlblSwitches.GetConnInfoFlag() & AUTHORITY))
  440. {
  441. // Check if alias user is not NULL, if so
  442. // return the alias user name
  443. if (m_CmdSwitches.GetAliasAuthorityPrinciple())
  444. {
  445. return m_CmdSwitches.GetAliasAuthorityPrinciple();
  446. }
  447. }
  448. }
  449. return m_GlblSwitches.GetAuthorityPrinciple();
  450. }