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.

214 lines
6.2 KiB

  1. // P3Domains.cpp : Implementation of CP3Domains
  2. #include "stdafx.h"
  3. #include "P3Admin.h"
  4. #include "P3Domains.h"
  5. #include "P3Domain.h"
  6. #include "P3DomainEnum.h"
  7. #include <Iads.h>
  8. #include <Adshlp.h>
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CP3Domains
  11. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. //////////////////////////////////////////////////////////////////////
  14. CP3Domains::CP3Domains() :
  15. m_pIUnk(NULL), m_pAdminX(NULL)
  16. {
  17. }
  18. CP3Domains::~CP3Domains()
  19. {
  20. if ( NULL != m_pIUnk )
  21. m_pIUnk->Release();
  22. }
  23. //////////////////////////////////////////////////////////////////////
  24. // IP3Domains
  25. //////////////////////////////////////////////////////////////////////
  26. STDMETHODIMP CP3Domains::get__NewEnum(IEnumVARIANT* *ppIEnumVARIANT)
  27. {
  28. if ( NULL == ppIEnumVARIANT ) return E_INVALIDARG;
  29. if ( NULL == m_pAdminX ) return E_POINTER;
  30. HRESULT hr;
  31. LPUNKNOWN pIUnk;
  32. IEnumVARIANT *pIEnumVARIANT;
  33. CComObject<CP3DomainEnum>* p;
  34. *ppIEnumVARIANT = NULL;
  35. hr = m_pAdminX->GetDomainEnum( &pIEnumVARIANT );
  36. if SUCCEEDED( hr )
  37. {
  38. hr = CComObject<CP3DomainEnum>::CreateInstance(&p); // Reference count still 0
  39. if SUCCEEDED( hr )
  40. {
  41. // Increment the reference count on the source object and pass it to the new enumerator
  42. hr = m_pIUnk->QueryInterface(IID_IUnknown, reinterpret_cast<LPVOID*>( &pIUnk ));
  43. if SUCCEEDED( hr )
  44. {
  45. hr = p->Init( pIUnk, m_pAdminX, pIEnumVARIANT );
  46. if SUCCEEDED( hr )
  47. hr = p->QueryInterface( IID_IEnumVARIANT, reinterpret_cast<LPVOID*>( ppIEnumVARIANT ));
  48. }
  49. if FAILED( hr )
  50. delete p;
  51. }
  52. pIEnumVARIANT->Release();
  53. }
  54. return hr;
  55. }
  56. STDMETHODIMP CP3Domains::get_Count(long *pVal)
  57. {
  58. if ( NULL == m_pAdminX ) return E_POINTER;
  59. return m_pAdminX->GetDomainCount( reinterpret_cast<ULONG*>( pVal ));
  60. }
  61. STDMETHODIMP CP3Domains::get_Item(VARIANT vIndex, IP3Domain **ppIP3Domain)
  62. {
  63. VARIANT *pv = &vIndex;
  64. if ( NULL == ppIP3Domain ) return E_INVALIDARG;
  65. if ( (VT_VARIANT|VT_BYREF) == V_VT( pv ))
  66. pv = V_VARIANTREF( pv );
  67. if ( VT_BSTR != V_VT( pv ) && VT_I4 != V_VT( pv ))
  68. return E_INVALIDARG;
  69. if ( VT_BSTR == V_VT( pv ) && NULL == V_BSTR( pv ))
  70. return E_INVALIDARG;
  71. if ( NULL == m_pAdminX ) return E_POINTER;
  72. HRESULT hr = E_INVALIDARG;
  73. _bstr_t _bstrDomainName;
  74. VARIANT v;
  75. VariantInit( &v );
  76. // Find the requested item
  77. if ( VT_I4 == V_VT( pv ))
  78. { // Find by Index
  79. int iIndex = V_I4( pv );
  80. CComPtr<IEnumVARIANT> spIEnumVARIANT;
  81. CComPtr<IP3Domain> spIDomain;
  82. hr = get__NewEnum( &spIEnumVARIANT );
  83. if ( S_OK == hr )
  84. {
  85. if ( (S_OK == hr) && (0 < iIndex - 1) )
  86. hr = spIEnumVARIANT->Skip( iIndex - 1 );
  87. if ( S_OK == hr )
  88. {
  89. hr = spIEnumVARIANT->Next( 1, &v, NULL );
  90. if ( S_OK == hr )
  91. {
  92. if ( VT_DISPATCH == V_VT( &v ))
  93. hr = V_DISPATCH( &v )->QueryInterface( __uuidof( IP3Domain ), reinterpret_cast<void**>( &spIDomain ));
  94. else
  95. hr = E_UNEXPECTED;
  96. VariantClear( &v );
  97. }
  98. }
  99. if ( S_OK == hr )
  100. {
  101. BSTR bstrDomainName;
  102. hr = spIDomain->get_Name( &bstrDomainName );
  103. _bstrDomainName = bstrDomainName;
  104. SysFreeString( bstrDomainName );
  105. }
  106. }
  107. }
  108. if ( VT_BSTR == V_VT( pv ))
  109. { // Find by Name
  110. _bstrDomainName = V_BSTR( pv );
  111. hr = m_pAdminX->ValidateDomain( _bstrDomainName );
  112. }
  113. // Wrap it with COM
  114. if SUCCEEDED( hr )
  115. {
  116. LPUNKNOWN pIUnk;
  117. CComObject<CP3Domain> *p;
  118. hr = CComObject<CP3Domain>::CreateInstance( &p ); // Reference count still 0
  119. if SUCCEEDED( hr )
  120. {
  121. hr = m_pIUnk->QueryInterface(IID_IUnknown, reinterpret_cast<LPVOID*>( &pIUnk ));
  122. if SUCCEEDED( hr )
  123. {
  124. hr = p->Init( pIUnk, m_pAdminX, _bstrDomainName );
  125. if SUCCEEDED( hr )
  126. hr = p->QueryInterface(IID_IP3Domain, reinterpret_cast<void**>( ppIP3Domain ));
  127. }
  128. if FAILED( hr )
  129. delete p; // Release
  130. }
  131. }
  132. return hr;
  133. }
  134. STDMETHODIMP CP3Domains::Add(BSTR bstrDomainName)
  135. {
  136. if ( NULL == m_pAdminX ) return E_POINTER;
  137. HRESULT hr = m_pAdminX->AddDomain( bstrDomainName );
  138. if ( S_OK == hr || ERROR_FILE_EXISTS == hr )
  139. {
  140. ULONG ulCount;
  141. // Don't want to fail because of this. The operation was really succeesful, just may have an issue with the service state.
  142. HRESULT hr2 = m_pAdminX->GetDomainCount( &ulCount );
  143. if ( S_OK == hr2 && 1 == ulCount )
  144. hr2 = m_pAdminX->EnablePOP3SVC();
  145. }
  146. return hr;
  147. }
  148. STDMETHODIMP CP3Domains::Remove(BSTR bstrDomainName)
  149. {
  150. if ( NULL == m_pAdminX ) return E_POINTER;
  151. return m_pAdminX->RemoveDomain( bstrDomainName );
  152. }
  153. STDMETHODIMP CP3Domains::SearchForMailbox(BSTR bstrUserName, BSTR *pbstrDomainName)
  154. {
  155. if ( NULL == pbstrDomainName ) return E_INVALIDARG;
  156. if ( NULL == m_pAdminX ) return E_POINTER;
  157. HRESULT hr;
  158. LPWSTR psDomainName = NULL;
  159. hr = m_pAdminX->SearchDomainsForMailbox( bstrUserName, &psDomainName );
  160. if ( S_OK == hr )
  161. {
  162. *pbstrDomainName = SysAllocString( psDomainName );
  163. delete [] psDomainName;
  164. }
  165. return hr;
  166. }
  167. //////////////////////////////////////////////////////////////////////
  168. // Implementation: public
  169. //////////////////////////////////////////////////////////////////////
  170. HRESULT CP3Domains::Init(IUnknown *pIUnk, CP3AdminWorker *p)
  171. {
  172. if ( NULL == pIUnk ) return E_INVALIDARG;
  173. if ( NULL == p ) return E_INVALIDARG;
  174. m_pIUnk = pIUnk;
  175. m_pAdminX = p;
  176. return S_OK;
  177. }