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.

207 lines
4.7 KiB

  1. // groups.cpp : Implementation of CsmtpadmApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "smtpadm.h"
  4. #include "alias.h"
  5. #include "oleutil.h"
  6. #include "smtpapi.h"
  7. #include <lmapibuf.h>
  8. #include "smtpcmn.h"
  9. // Must define THIS_FILE_* macros to use SmtpCreateException()
  10. #define THIS_FILE_HELP_CONTEXT 0
  11. #define THIS_FILE_PROG_ID _T("Smtpadm.Alias.1")
  12. #define THIS_FILE_IID IID_ISmtpAdminAlias
  13. #define DEFAULT_NEWSGROUP_NAME _T("")
  14. #define DEFAULT_NEWSGROUP_DESCRIPTION _T("")
  15. #define DEFAULT_NEWSGROUP_MODERATOR _T("")
  16. #define DEFAULT_NEWSGROUP_READONLY FALSE
  17. /////////////////////////////////////////////////////////////////////////////
  18. //
  19. //
  20. // Use a macro to define all the default methods
  21. //
  22. DECLARE_METHOD_IMPLEMENTATION_FOR_STANDARD_EXTENSION_INTERFACES(SmtpAdminAlias, CSmtpAdminAlias, IID_ISmtpAdminAlias)
  23. STDMETHODIMP CSmtpAdminAlias::InterfaceSupportsErrorInfo(REFIID riid)
  24. {
  25. static const IID* arr[] =
  26. {
  27. &IID_ISmtpAdminAlias,
  28. };
  29. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  30. {
  31. if (InlineIsEqualGUID(*arr[i],riid))
  32. return S_OK;
  33. }
  34. return S_FALSE;
  35. }
  36. CSmtpAdminAlias::CSmtpAdminAlias () :
  37. m_lCount ( 0 ),
  38. m_lType ( NAME_TYPE_USER )
  39. // CComBSTR's are initialized to NULL by default.
  40. {
  41. InitAsyncTrace ( );
  42. m_pSmtpNameList = NULL;
  43. m_iadsImpl.SetService ( MD_SERVICE_NAME );
  44. m_iadsImpl.SetName ( _T("Alias") );
  45. m_iadsImpl.SetClass ( _T("IIsSmtpAlias") );
  46. }
  47. CSmtpAdminAlias::~CSmtpAdminAlias ()
  48. {
  49. if ( m_pSmtpNameList ) {
  50. ::NetApiBufferFree ( m_pSmtpNameList );
  51. }
  52. // All CComBSTR's are freed automatically.
  53. TermAsyncTrace ( );
  54. }
  55. //
  56. // IADs methods:
  57. //
  58. DECLARE_SIMPLE_IADS_IMPLEMENTATION(CSmtpAdminAlias,m_iadsImpl)
  59. //////////////////////////////////////////////////////////////////////
  60. // Properties:
  61. //////////////////////////////////////////////////////////////////////
  62. STDMETHODIMP CSmtpAdminAlias::get_Count ( long* plCount )
  63. {
  64. return StdPropertyGet ( m_lCount, plCount );
  65. }
  66. // The current alias's properties:
  67. STDMETHODIMP CSmtpAdminAlias::get_EmailId ( BSTR * pstrEmailId )
  68. {
  69. return StdPropertyGet ( m_strEmailId, pstrEmailId );
  70. }
  71. STDMETHODIMP CSmtpAdminAlias::put_EmailId ( BSTR strEmailId )
  72. {
  73. return StdPropertyPut ( &strEmailId, strEmailId );
  74. }
  75. STDMETHODIMP CSmtpAdminAlias::get_Domain ( BSTR * pstrDomain )
  76. {
  77. return StdPropertyGet ( m_strDomain, pstrDomain );
  78. }
  79. STDMETHODIMP CSmtpAdminAlias::put_Domain ( BSTR strDomain )
  80. {
  81. return StdPropertyPut ( &m_strDomain, strDomain );
  82. }
  83. STDMETHODIMP CSmtpAdminAlias::get_Type ( long* plType )
  84. {
  85. return StdPropertyGet ( m_lType, plType );
  86. }
  87. STDMETHODIMP CSmtpAdminAlias::put_Type ( long lType )
  88. {
  89. return StdPropertyPut ( &m_lType, lType );
  90. }
  91. //////////////////////////////////////////////////////////////////////
  92. // Methods:
  93. //////////////////////////////////////////////////////////////////////
  94. STDMETHODIMP CSmtpAdminAlias::Find (
  95. BSTR strWildmat,
  96. long cMaxResults
  97. )
  98. {
  99. TraceFunctEnter ( "CSmtpAdminAlias::Find" );
  100. HRESULT hr = NOERROR;
  101. DWORD dwErr = NOERROR;
  102. // Free the old newsgroup list:
  103. if ( m_pSmtpNameList ) {
  104. ::NetApiBufferFree ( m_pSmtpNameList );
  105. m_pSmtpNameList = NULL;
  106. }
  107. m_lCount = 0;
  108. dwErr = SmtpGetNameList (
  109. m_iadsImpl.QueryComputer(),
  110. strWildmat,
  111. NAME_TYPE_ALL,
  112. cMaxResults,
  113. TRUE,
  114. &m_pSmtpNameList,
  115. m_iadsImpl.QueryInstance());
  116. if ( dwErr != 0 ) {
  117. ErrorTraceX ( (LPARAM) this, "Failed to find alias: %x", dwErr );
  118. SetLastError( dwErr );
  119. hr = SmtpCreateExceptionFromWin32Error ( dwErr );
  120. goto Exit;
  121. }
  122. m_lCount = m_pSmtpNameList->cEntries;
  123. Exit:
  124. TraceFunctLeave ();
  125. return hr;
  126. }
  127. STDMETHODIMP CSmtpAdminAlias::GetNth( long lIndex )
  128. {
  129. _ASSERT( lIndex >=0 && lIndex < m_lCount );
  130. WCHAR* pchStartOfDomain = NULL;
  131. WCHAR* p = NULL;
  132. LPSMTP_NAME_ENTRY pNameEntry;
  133. if( !m_pSmtpNameList )
  134. {
  135. return SmtpCreateException (IDS_SMTPEXCEPTION_DIDNT_ENUMERATE);
  136. }
  137. if( lIndex < 0 || lIndex >= m_lCount )
  138. {
  139. return SmtpCreateException (IDS_SMTPEXCEPTION_INVALID_INDEX);
  140. }
  141. //_ASSERT( CAddr::ValidateEmailName(m_pSmtpNameList[lIndex].lpszName) );
  142. pNameEntry = &m_pSmtpNameList->aNameEntry[lIndex];
  143. p = pNameEntry->lpszName;
  144. while( *p && *p != '@' ) p++;
  145. _ASSERT( *p );
  146. if( !*p )
  147. {
  148. return SmtpCreateException (IDS_SMTPEXCEPTION_INVALID_ADDRESS);
  149. }
  150. pchStartOfDomain = p+1;
  151. m_lType = pNameEntry->dwType;
  152. m_strDomain = (LPCWSTR) pchStartOfDomain;
  153. *(pchStartOfDomain-1) = '\0';
  154. m_strEmailId = pNameEntry->lpszName; // converted to UNICODE
  155. *(pchStartOfDomain-1) = '@'; // turn it back
  156. return NOERROR;
  157. }