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.

247 lines
6.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: ntgcond.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // NTGCond.cpp: implementation of the CNTGroupsCondition class.
  11. //
  12. //////////////////////////////////////////////////////////////////////
  13. #include "precompiled.h"
  14. #include "NTGCond.h"
  15. #include "textsid.h"
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. CNTGroupsCondition::CNTGroupsCondition(IIASAttributeInfo* pCondAttr,
  20. ATL::CString& strConditionText,
  21. HWND hWndParent,
  22. LPTSTR pszServerAddress
  23. )
  24. :CCondition(pCondAttr, strConditionText)
  25. {
  26. m_fParsed = FALSE; // parsing needed
  27. m_hWndParent = hWndParent;
  28. m_pszServerAddress = pszServerAddress;
  29. }
  30. CNTGroupsCondition::CNTGroupsCondition(IIASAttributeInfo* pCondAttr,
  31. HWND hWndParent,
  32. LPTSTR pszServerAddress
  33. )
  34. :CCondition(pCondAttr)
  35. {
  36. m_fParsed = TRUE; // no parsing needed
  37. m_hWndParent = hWndParent;
  38. m_pszServerAddress = pszServerAddress;
  39. }
  40. CNTGroupsCondition::~CNTGroupsCondition()
  41. {
  42. }
  43. //+---------------------------------------------------------------------------
  44. //
  45. // Function: CNTGroupsCondition::Edit
  46. //
  47. // Synopsis: call user/group picker to pick NT groups
  48. //
  49. // Arguments: None
  50. //
  51. // Returns: HRESULT -
  52. //
  53. // History: Created Header byao 2/23/98 3:45:35 AM
  54. //
  55. //+---------------------------------------------------------------------------
  56. HRESULT CNTGroupsCondition::Edit()
  57. {
  58. TRACE_FUNCTION("CNTGroupsCondition::Edit");
  59. HRESULT hr = S_OK;
  60. CComPtr<IIASAttributeEditor> spIASGroupsAttributeEditor;
  61. hr = CoCreateInstance( CLSID_IASGroupsAttributeEditor, NULL, CLSCTX_INPROC_SERVER, IID_IIASAttributeEditor, (LPVOID *) &spIASGroupsAttributeEditor );
  62. if( FAILED( hr ) )
  63. {
  64. return hr;
  65. }
  66. if( ! spIASGroupsAttributeEditor )
  67. {
  68. return E_FAIL;
  69. }
  70. CComVariant varGroupsCondition;
  71. V_VT(&varGroupsCondition) = VT_BSTR;
  72. V_BSTR(&varGroupsCondition) = SysAllocString( (LPCTSTR) m_strConditionText );
  73. // We need to pass the machine name in somehow, so we use the
  74. // otherwise unused BSTR * pReserved parameter of this method.
  75. CComBSTR bstrServerAddress = m_pszServerAddress;
  76. hr = spIASGroupsAttributeEditor->Edit( NULL, &varGroupsCondition, &bstrServerAddress );
  77. if( S_OK == hr )
  78. {
  79. // Some casting here to make sure that we do a deep copy.
  80. m_strConditionText = (LPCTSTR) V_BSTR(&varGroupsCondition);
  81. // Next time we are asked for display text, we want to make sure that we
  82. // get call the IASGroupsAttributeEditor again.
  83. m_fParsed = FALSE;
  84. }
  85. if( FAILED( hr ) )
  86. {
  87. ShowErrorDialog(NULL,
  88. IDS_ERROR_OBJECT_PICKER,
  89. NULL,
  90. hr
  91. );
  92. }
  93. return hr;
  94. }
  95. //+---------------------------------------------------------------------------
  96. //
  97. // Function: CNTGroupsCondition::GetDisplayText
  98. //
  99. // Synopsis: get display text for NT groups
  100. //
  101. // Arguments: None
  102. //
  103. // Returns: ATL::CString - display string
  104. //
  105. // History: Created Header byao 2/23/98 3:47:52 AM
  106. //
  107. //+---------------------------------------------------------------------------
  108. ATL::CString CNTGroupsCondition::GetDisplayText()
  109. {
  110. TRACE_FUNCTION("CNTGroupsCondition::GetDisplayText");
  111. ATL::CString strDispText;
  112. HRESULT hr = S_OK;
  113. if ( !m_fParsed)
  114. {
  115. CComPtr<IIASAttributeEditor> spIASGroupsAttributeEditor;
  116. hr = CoCreateInstance( CLSID_IASGroupsAttributeEditor, NULL, CLSCTX_INPROC_SERVER, IID_IIASAttributeEditor, (LPVOID *) &spIASGroupsAttributeEditor );
  117. if ( FAILED(hr) || ! spIASGroupsAttributeEditor )
  118. {
  119. ErrorTrace(ERROR_NAPMMC_NTGCONDITION, "CoCreateInstance of Groups editor failed.");
  120. ShowErrorDialog(NULL,
  121. IDS_ERROR_PARSE_CONDITION,
  122. (LPTSTR)(LPCTSTR)m_strConditionText,
  123. hr
  124. );
  125. strDispText = _T("");
  126. return strDispText;
  127. }
  128. CComVariant varGroupsCondition;
  129. V_VT(&varGroupsCondition) = VT_BSTR;
  130. V_BSTR(&varGroupsCondition) = SysAllocString( (LPCTSTR) m_strConditionText );
  131. CComBSTR bstrDisplay;
  132. CComBSTR bstrDummy;
  133. // We need to pass the machine name in somehow, so we use the
  134. // otherwise unused BSTR * pReserved parameter of this method.
  135. CComBSTR bstrServerName = m_pszServerAddress;
  136. hr = spIASGroupsAttributeEditor->GetDisplayInfo( NULL, &varGroupsCondition, &bstrDummy, &bstrDisplay, &bstrServerName );
  137. if( SUCCEEDED(hr) )
  138. {
  139. m_strDisplayCondText = bstrDisplay;
  140. }
  141. if ( FAILED(hr) )
  142. {
  143. ErrorTrace(ERROR_NAPMMC_NTGCONDITION, "Invalid condition syntax");
  144. ShowErrorDialog(NULL,
  145. IDS_ERROR_PARSE_CONDITION,
  146. (LPTSTR)(LPCTSTR)m_strConditionText,
  147. hr
  148. );
  149. strDispText = _T("");
  150. return strDispText;
  151. }
  152. }
  153. CComBSTR bstrName;
  154. hr = m_spAttributeInfo->get_AttributeName( &bstrName );
  155. _ASSERTE( SUCCEEDED( hr ) );
  156. strDispText = bstrName;
  157. { ATL::CString matches;
  158. matches.LoadString(IDS_TEXT_MATCHES);
  159. strDispText += matches;
  160. }
  161. strDispText += _T("\"");
  162. strDispText += m_strDisplayCondText;
  163. strDispText += _T("\"");
  164. DebugTrace(DEBUG_NAPMMC_NTGCONDITION, "GetDisplayText() returning %ws", strDispText);
  165. return strDispText;
  166. }
  167. //+---------------------------------------------------------------------------
  168. //
  169. // Function: CNtGroupsCondition::GetConditionText
  170. //
  171. // Synopsis: Get the condition text for this condition.
  172. // We just need to add the NTGroups prefix to it
  173. //
  174. // Arguments: None
  175. //
  176. // Returns: WCHAR* - condition text
  177. //
  178. // History: Created Header byao 2/22/98 11:38:41 PM
  179. //
  180. //+---------------------------------------------------------------------------
  181. WCHAR* CNTGroupsCondition::GetConditionText()
  182. {
  183. TRACE_FUNCTION("CNTGroupsCondition::GetConditionText");
  184. WCHAR *pwzCondText;
  185. pwzCondText = new WCHAR[m_strConditionText.GetLength()+128];
  186. if (pwzCondText == NULL)
  187. {
  188. ErrorTrace(ERROR_NAPMMC_NTGCONDITION, "Error creating condition text, err = %x", GetLastError());
  189. ShowErrorDialog(NULL, IDS_ERROR_SDO_ERROR_GET_CONDTEXT );
  190. return NULL;
  191. }
  192. // now form the condition text
  193. wcscpy(pwzCondText, NTG_PREFIX);
  194. wcscat(pwzCondText, _T("(\"") );
  195. wcscat(pwzCondText, (LPCTSTR)m_strConditionText);
  196. wcscat(pwzCondText, _T("\")"));
  197. DebugTrace(DEBUG_NAPMMC_NTGCONDITION, "GetConditionText() returning %ws", pwzCondText);
  198. return pwzCondText;
  199. }