Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. rtsrc.h
  5. Abstract:
  6. Implementation of IRoutingSource interface
  7. Author:
  8. Fei Su (feisu) 9/22/97 Created.
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "smtpadm.h"
  13. #include "smtpprop.h"
  14. #include "rtsrc.h"
  15. #include "oleutil.h"
  16. #include "metautil.h"
  17. // Must define THIS_FILE_* macros to use SmtpCreateException()
  18. #define THIS_FILE_HELP_CONTEXT 0
  19. #define THIS_FILE_PROG_ID _T("Smtpadm.VirtualServer.1")
  20. #define THIS_FILE_IID IID_IRoutingSource
  21. #define RS_RELATIVE_NAME _T("RoutingSources")
  22. #define ID_DS_TYPE 0
  23. #define ID_DS_DATA_DIRECTORY 1
  24. #define ID_DS_DEFAULT_MAIL_ROOT 2
  25. #define ID_DS_BIND_TYPE 3
  26. #define ID_DS_SCHEMA_TYPE 4
  27. #define ID_DS_HOST 5
  28. #define ID_DS_NAMING_CONTEXT 6
  29. #define ID_DS_ACCOUNT 7
  30. #define ID_DS_PASSWORD 8
  31. #define DEFAULT_DS_TYPE _T("LDAP")
  32. #define DEFAULT_DS_DATA_DIRECTORY _T("")
  33. #define DEFAULT_DS_DEFAULT_MAIL_ROOT _T("/Mailbox")
  34. #define DEFAULT_DS_BIND_TYPE _T("None")
  35. #define DEFAULT_DS_SCHEMA_TYPE _T("Exchange5")
  36. #define DEFAULT_DS_HOST _T("")
  37. #define DEFAULT_DS_NAMING_CONTEXT _T("")
  38. #define DEFAULT_DS_ACCOUNT _T("")
  39. #define DEFAULT_DS_PASSWORD _T("")
  40. /////////////////////////////////////////////////////////////////////////////
  41. //
  42. STDMETHODIMP CRoutingSource::InterfaceSupportsErrorInfo(REFIID riid)
  43. {
  44. static const IID* arr[] =
  45. {
  46. &IID_IRoutingSource,
  47. };
  48. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  49. {
  50. if (InlineIsEqualGUID(*arr[i],riid))
  51. return S_OK;
  52. }
  53. return S_FALSE;
  54. }
  55. //////////////////////////////////////////////////////////////////////
  56. // Properties:
  57. //////////////////////////////////////////////////////////////////////
  58. STDMETHODIMP CRoutingSource::get_Type( BSTR * pstrType )
  59. {
  60. return StdPropertyGet ( m_strType, pstrType );
  61. }
  62. STDMETHODIMP CRoutingSource::put_Type( BSTR strType )
  63. {
  64. return StdPropertyPut ( &m_strType, strType, &m_dwFC, BitMask(ID_DS_TYPE));
  65. }
  66. STDMETHODIMP CRoutingSource::get_DataDirectory( BSTR * pstrDataDirectory )
  67. {
  68. return StdPropertyGet ( m_strDataDirectory, pstrDataDirectory );
  69. }
  70. STDMETHODIMP CRoutingSource::put_DataDirectory( BSTR strDataDirectory )
  71. {
  72. return StdPropertyPut ( &m_strDataDirectory, strDataDirectory, &m_dwFC, BitMask(ID_DS_DATA_DIRECTORY) );
  73. }
  74. STDMETHODIMP CRoutingSource::get_DefaultMailRoot( BSTR * pstrDefaultMailRoot )
  75. {
  76. return StdPropertyGet ( m_strDefaultMailroot, pstrDefaultMailRoot );
  77. }
  78. STDMETHODIMP CRoutingSource::put_DefaultMailRoot( BSTR strDefaultMailRoot )
  79. {
  80. return StdPropertyPut ( &m_strDefaultMailroot, strDefaultMailRoot, &m_dwFC, BitMask(ID_DS_DEFAULT_MAIL_ROOT) );
  81. }
  82. STDMETHODIMP CRoutingSource::get_BindType( BSTR * pstrBindType )
  83. {
  84. return StdPropertyGet ( m_strBindType, pstrBindType );
  85. }
  86. STDMETHODIMP CRoutingSource::put_BindType( BSTR strBindType )
  87. {
  88. return StdPropertyPut ( &m_strBindType, strBindType, &m_dwFC, BitMask(ID_DS_BIND_TYPE) );
  89. }
  90. STDMETHODIMP CRoutingSource::get_SchemaType( BSTR * pstrSchemaType )
  91. {
  92. return StdPropertyGet ( m_strSchemaType, pstrSchemaType );
  93. }
  94. STDMETHODIMP CRoutingSource::put_SchemaType( BSTR strSchemaType )
  95. {
  96. return StdPropertyPut ( &m_strSchemaType, strSchemaType, &m_dwFC, BitMask(ID_DS_SCHEMA_TYPE) );
  97. }
  98. STDMETHODIMP CRoutingSource::get_Host( BSTR * pstrHost )
  99. {
  100. return StdPropertyGet ( m_strHost, pstrHost );
  101. }
  102. STDMETHODIMP CRoutingSource::put_Host( BSTR strHost )
  103. {
  104. return StdPropertyPut ( &m_strHost, strHost, &m_dwFC, BitMask(ID_DS_HOST) );
  105. }
  106. STDMETHODIMP CRoutingSource::get_NamingContext( BSTR * pstrNamingContext )
  107. {
  108. return StdPropertyGet ( m_strNamingContext, pstrNamingContext );
  109. }
  110. STDMETHODIMP CRoutingSource::put_NamingContext( BSTR strNamingContext )
  111. {
  112. return StdPropertyPut ( &m_strNamingContext, strNamingContext, &m_dwFC, BitMask(ID_DS_NAMING_CONTEXT) );
  113. }
  114. STDMETHODIMP CRoutingSource::get_Account( BSTR * pstrAccount )
  115. {
  116. return StdPropertyGet ( m_strAccount, pstrAccount );
  117. }
  118. STDMETHODIMP CRoutingSource::put_Account( BSTR strAccount )
  119. {
  120. return StdPropertyPut ( &m_strAccount, strAccount, &m_dwFC, BitMask(ID_DS_ACCOUNT) );
  121. }
  122. STDMETHODIMP CRoutingSource::get_Password( BSTR * pstrPassword )
  123. {
  124. return StdPropertyGet ( m_strPassword, pstrPassword );
  125. }
  126. STDMETHODIMP CRoutingSource::put_Password( BSTR strPassword )
  127. {
  128. return StdPropertyPut ( &m_strPassword, strPassword, &m_dwFC, BitMask(ID_DS_PASSWORD) );
  129. }
  130. ///////////////////////////////////////////////////////////////////
  131. // Get / Set methods (internal)
  132. ///////////////////////////////////////////////////////////////////
  133. HRESULT CRoutingSource::Get(CMetabaseKey * pMBVirtualServer)
  134. {
  135. TraceFunctEnter ( "CRoutingSource::Get" );
  136. HRESULT hr = NOERROR;
  137. if( !pMBVirtualServer )
  138. BAIL_WITH_FAILURE(hr, E_POINTER);
  139. if( !StdGetMetabaseProp(pMBVirtualServer, MD_SMTP_DS_TYPE, DEFAULT_DS_TYPE, &m_strType, RS_RELATIVE_NAME) )
  140. BAIL_WITH_FAILURE(hr, GetLastError());
  141. if( !StdGetMetabaseProp(pMBVirtualServer, MD_SMTP_DS_DATA_DIRECTORY, DEFAULT_DS_DATA_DIRECTORY, &m_strDataDirectory, RS_RELATIVE_NAME) )
  142. BAIL_WITH_FAILURE(hr, GetLastError());
  143. if( !StdGetMetabaseProp(pMBVirtualServer, MD_SMTP_DS_DEFAULT_MAIL_ROOT, DEFAULT_DS_DEFAULT_MAIL_ROOT, &m_strDefaultMailroot, RS_RELATIVE_NAME) )
  144. BAIL_WITH_FAILURE(hr, GetLastError());
  145. if( !StdGetMetabaseProp(pMBVirtualServer, MD_SMTP_DS_BIND_TYPE, DEFAULT_DS_BIND_TYPE, &m_strBindType, RS_RELATIVE_NAME) )
  146. BAIL_WITH_FAILURE(hr, GetLastError());
  147. if( !StdGetMetabaseProp(pMBVirtualServer, MD_SMTP_DS_SCHEMA_TYPE, DEFAULT_DS_SCHEMA_TYPE, &m_strSchemaType, RS_RELATIVE_NAME) )
  148. BAIL_WITH_FAILURE(hr, GetLastError());
  149. if( !StdGetMetabaseProp(pMBVirtualServer, MD_SMTP_DS_HOST, DEFAULT_DS_HOST, &m_strHost, RS_RELATIVE_NAME) )
  150. BAIL_WITH_FAILURE(hr, GetLastError());
  151. if( !StdGetMetabaseProp(pMBVirtualServer, MD_SMTP_DS_NAMING_CONTEXT, DEFAULT_DS_NAMING_CONTEXT, &m_strNamingContext, RS_RELATIVE_NAME) )
  152. BAIL_WITH_FAILURE(hr, GetLastError());
  153. if( !StdGetMetabaseProp(pMBVirtualServer, MD_SMTP_DS_ACCOUNT, DEFAULT_DS_ACCOUNT, &m_strAccount, RS_RELATIVE_NAME) )
  154. BAIL_WITH_FAILURE(hr, GetLastError());
  155. if( !StdGetMetabaseProp(pMBVirtualServer, MD_SMTP_DS_PASSWORD, DEFAULT_DS_PASSWORD, &m_strPassword, RS_RELATIVE_NAME) )
  156. BAIL_WITH_FAILURE(hr, GetLastError());
  157. Exit:
  158. TraceFunctLeave ();
  159. return hr;
  160. }
  161. HRESULT CRoutingSource::Set(CMetabaseKey * pMBVirtualServer)
  162. {
  163. TraceFunctEnter ( "CRoutingSource::Set" );
  164. HRESULT hr = NOERROR;
  165. if( !pMBVirtualServer )
  166. BAIL_WITH_FAILURE(hr, E_POINTER);
  167. if( IS_FLAG_SET(m_dwFC, BitMask(ID_DS_TYPE)) &&
  168. !StdPutMetabaseProp(pMBVirtualServer, MD_SMTP_DS_TYPE, m_strType, RS_RELATIVE_NAME) )
  169. BAIL_WITH_FAILURE(hr, GetLastError());
  170. if( IS_FLAG_SET(m_dwFC, BitMask(ID_DS_DATA_DIRECTORY)) &&
  171. !StdPutMetabaseProp(pMBVirtualServer, MD_SMTP_DS_DATA_DIRECTORY, m_strDataDirectory, RS_RELATIVE_NAME) )
  172. BAIL_WITH_FAILURE(hr, GetLastError());
  173. if( IS_FLAG_SET(m_dwFC, BitMask(ID_DS_DEFAULT_MAIL_ROOT)) &&
  174. !StdPutMetabaseProp(pMBVirtualServer, MD_SMTP_DS_DEFAULT_MAIL_ROOT, m_strDefaultMailroot, RS_RELATIVE_NAME) )
  175. BAIL_WITH_FAILURE(hr, GetLastError());
  176. if( IS_FLAG_SET(m_dwFC, BitMask(ID_DS_BIND_TYPE)) &&
  177. !StdPutMetabaseProp(pMBVirtualServer, MD_SMTP_DS_BIND_TYPE, m_strBindType, RS_RELATIVE_NAME) )
  178. BAIL_WITH_FAILURE(hr, GetLastError());
  179. if( IS_FLAG_SET(m_dwFC, BitMask(ID_DS_SCHEMA_TYPE)) &&
  180. !StdPutMetabaseProp(pMBVirtualServer, MD_SMTP_DS_SCHEMA_TYPE, m_strSchemaType, RS_RELATIVE_NAME) )
  181. BAIL_WITH_FAILURE(hr, GetLastError());
  182. if( IS_FLAG_SET(m_dwFC, BitMask(ID_DS_HOST)) &&
  183. !StdPutMetabaseProp(pMBVirtualServer, MD_SMTP_DS_HOST, m_strHost, RS_RELATIVE_NAME) )
  184. BAIL_WITH_FAILURE(hr, GetLastError());
  185. if( IS_FLAG_SET(m_dwFC, BitMask(ID_DS_NAMING_CONTEXT)) &&
  186. !StdPutMetabaseProp(pMBVirtualServer, MD_SMTP_DS_NAMING_CONTEXT, m_strNamingContext, RS_RELATIVE_NAME) )
  187. BAIL_WITH_FAILURE(hr, GetLastError());
  188. if( IS_FLAG_SET(m_dwFC, BitMask(ID_DS_ACCOUNT)) &&
  189. !StdPutMetabaseProp(pMBVirtualServer, MD_SMTP_DS_ACCOUNT, m_strAccount, RS_RELATIVE_NAME) )
  190. BAIL_WITH_FAILURE(hr, GetLastError());
  191. if( IS_FLAG_SET(m_dwFC, BitMask(ID_DS_PASSWORD)) &&
  192. !StdPutMetabaseProp(pMBVirtualServer, MD_SMTP_DS_PASSWORD, m_strPassword, RS_RELATIVE_NAME, IIS_MD_UT_SERVER, METADATA_SECURE | METADATA_INHERIT) )
  193. BAIL_WITH_FAILURE(hr, GetLastError());
  194. Exit:
  195. TraceFunctLeave ();
  196. return hr;
  197. }