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.

2729 lines
82 KiB

  1. // service.cpp : Implementation of CsmtpadmApp and DLL registration.
  2. #include "stdafx.h"
  3. #include <lmcons.h>
  4. #include "IADM.h"
  5. #include "imd.h"
  6. #include "mdmsg.h"
  7. #include "iisinfo.h"
  8. #include "iiscnfgp.h"
  9. #include "smtpprop.h"
  10. #include "smtpadm.h"
  11. #include "ipaccess.h"
  12. #include "oleutil.h"
  13. #include "metautil.h"
  14. #include "smtpcmn.h"
  15. #include "smtpapi.h"
  16. #include "virsvr.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_ISmtpAdminVirtualServer
  21. /////////////////////////////////////////////////////////////////////////////
  22. //
  23. CSmtpAdminVirtualServer::CSmtpAdminVirtualServer () :
  24. m_lPort (25 ),
  25. m_lLogMethod ( 0 ),
  26. m_dwServerState ( MD_SERVER_STATE_STOPPED ),
  27. m_pPrivateIpAccess ( NULL ),
  28. m_dwWin32ErrorCode ( NOERROR ),
  29. m_pPrivateBindings ( NULL ),
  30. m_lRouteAction ( 0 )
  31. // CComBSTR's are initialized to NULL by default.
  32. {
  33. m_psaAdmins = NULL;
  34. InitAsyncTrace ( );
  35. // Create the Ip Access collection:
  36. CComObject<CTcpAccess> * pIpAccess;
  37. CComObject<CTcpAccess>::CreateInstance ( &pIpAccess );
  38. pIpAccess->QueryInterface ( IID_ITcpAccess, (void **) &m_pIpAccess );
  39. m_pPrivateIpAccess = pIpAccess;
  40. }
  41. CSmtpAdminVirtualServer::~CSmtpAdminVirtualServer ()
  42. {
  43. // All CComBSTR's are freed automatically.
  44. if ( m_psaAdmins ) {
  45. SafeArrayDestroy ( m_psaAdmins );
  46. }
  47. TermAsyncTrace ( );
  48. }
  49. STDMETHODIMP CSmtpAdminVirtualServer::InterfaceSupportsErrorInfo(REFIID riid)
  50. {
  51. static const IID* arr[] =
  52. {
  53. &IID_ISmtpAdminVirtualServer,
  54. };
  55. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  56. {
  57. if (InlineIsEqualGUID(*arr[i],riid))
  58. return S_OK;
  59. }
  60. return S_FALSE;
  61. }
  62. // Which service to configure:
  63. STDMETHODIMP CSmtpAdminVirtualServer::get_Server ( BSTR * pstrServer )
  64. {
  65. return StdPropertyGet ( m_strServer, pstrServer );
  66. }
  67. STDMETHODIMP CSmtpAdminVirtualServer::put_Server ( BSTR strServer )
  68. {
  69. VALIDATE_STRING ( strServer, MAXLEN_SERVER );
  70. // If the server name changes, that means the client will have to
  71. // call Get again:
  72. // I assume this here:
  73. _ASSERT ( sizeof (DWORD) == sizeof (int) );
  74. return StdPropertyPutServerName ( &m_strServer, strServer, (DWORD *) &m_fGotProperties, 1);
  75. }
  76. STDMETHODIMP CSmtpAdminVirtualServer::get_ServiceInstance ( long * plServiceInstance )
  77. {
  78. return StdPropertyGet ( m_dwServiceInstance, plServiceInstance );
  79. }
  80. STDMETHODIMP CSmtpAdminVirtualServer::put_ServiceInstance ( long lServiceInstance )
  81. {
  82. // If the service instance changes, that means the client will have to
  83. // call Get again:
  84. // I assume this here:
  85. _ASSERT ( sizeof (DWORD) == sizeof (int) );
  86. return StdPropertyPut ( &m_dwServiceInstance, lServiceInstance, (DWORD *) &m_fGotProperties, 1 );
  87. }
  88. STDMETHODIMP CSmtpAdminVirtualServer::get_TcpAccess ( ITcpAccess ** ppTcpAccess )
  89. {
  90. return m_pIpAccess->QueryInterface ( IID_ITcpAccess, (void **) ppTcpAccess );
  91. }
  92. STDMETHODIMP CSmtpAdminVirtualServer::get_Bindings ( IServerBindings ** ppBindings )
  93. {
  94. TraceQuietEnter ( "CSmtpAdminVirtualServer::get_Bindings" );
  95. HRESULT hr = NOERROR;
  96. if ( !m_pBindings ) {
  97. ErrorTrace ( 0, "Didn't call get first" );
  98. hr = SmtpCreateException ( IDS_SMTPEXCEPTION_DIDNT_CALL_GET );
  99. goto Exit;
  100. }
  101. else {
  102. hr = m_pBindings->QueryInterface ( IID_IServerBindings, (void **) ppBindings );
  103. _ASSERT ( SUCCEEDED(hr) );
  104. }
  105. Exit:
  106. if ( FAILED(hr) && hr != DISP_E_EXCEPTION ) {
  107. hr = SmtpCreateExceptionFromHresult ( hr );
  108. }
  109. TraceFunctLeave ();
  110. return hr;
  111. }
  112. STDMETHODIMP CSmtpAdminVirtualServer::get_BindingsDispatch ( IDispatch ** ppBindings )
  113. {
  114. HRESULT hr = NOERROR;
  115. CComPtr<IServerBindings> pBindings;
  116. hr = get_Bindings ( &pBindings );
  117. if ( FAILED(hr) ) {
  118. goto Exit;
  119. }
  120. hr = pBindings->QueryInterface ( IID_IDispatch, (void **) ppBindings );
  121. if ( FAILED(hr) ) {
  122. goto Exit;
  123. }
  124. Exit:
  125. return hr;
  126. }
  127. STDMETHODIMP CSmtpAdminVirtualServer::get_RoutingSource ( IRoutingSource ** ppRoutingSource )
  128. {
  129. TraceQuietEnter ( "CSmtpAdminVirtualServer::get_RoutingSource" );
  130. HRESULT hr = NOERROR;
  131. hr = m_RoutingSource.QueryInterface ( IID_IRoutingSource, (void **) ppRoutingSource );
  132. BAIL_ON_FAILURE(hr);
  133. Exit:
  134. TraceFunctLeave ();
  135. return hr;
  136. }
  137. STDMETHODIMP CSmtpAdminVirtualServer::get_RoutingSourceDispatch ( IDispatch ** ppRoutingSource )
  138. {
  139. TraceQuietEnter ( "CSmtpAdminVirtualServer::get_RoutingSourceDispatch" );
  140. HRESULT hr = NOERROR;
  141. hr = m_RoutingSource.QueryInterface ( IID_IDispatch, (void **) ppRoutingSource );
  142. BAIL_ON_FAILURE(hr);
  143. Exit:
  144. TraceFunctLeave ();
  145. return hr;
  146. }
  147. // Server overridable Properties:
  148. STDMETHODIMP CSmtpAdminVirtualServer::get_ServerBindings( SAFEARRAY ** ppsastrServerBindings )
  149. {
  150. return StdPropertyGet ( &m_mszServerBindings, ppsastrServerBindings );
  151. }
  152. STDMETHODIMP CSmtpAdminVirtualServer::put_ServerBindings( SAFEARRAY * pstrServerBindings )
  153. {
  154. return StdPropertyPut ( &m_mszServerBindings, pstrServerBindings, &m_bvChangedFields, BitMask(ID_SERVER_BINDINGS));
  155. }
  156. STDMETHODIMP CSmtpAdminVirtualServer::get_ServerBindingsVariant( SAFEARRAY ** ppsavarServerBindings )
  157. {
  158. HRESULT hr;
  159. SAFEARRAY * psastrServerBindings = NULL;
  160. hr = get_ServerBindings ( &psastrServerBindings );
  161. if ( FAILED(hr) ) {
  162. goto Exit;
  163. }
  164. hr = StringArrayToVariantArray ( psastrServerBindings, ppsavarServerBindings );
  165. Exit:
  166. if ( psastrServerBindings ) {
  167. SafeArrayDestroy ( psastrServerBindings );
  168. }
  169. return hr;
  170. }
  171. STDMETHODIMP CSmtpAdminVirtualServer::put_ServerBindingsVariant( SAFEARRAY * psavarServerBindings )
  172. {
  173. HRESULT hr;
  174. SAFEARRAY * psastrServerBindings = NULL;
  175. hr = VariantArrayToStringArray ( psavarServerBindings, &psastrServerBindings );
  176. if ( FAILED(hr) ) {
  177. goto Exit;
  178. }
  179. hr = put_ServerBindings ( psastrServerBindings );
  180. Exit:
  181. if ( psastrServerBindings ) {
  182. SafeArrayDestroy ( psastrServerBindings );
  183. }
  184. return hr;
  185. }
  186. STDMETHODIMP CSmtpAdminVirtualServer::get_SecureBindings( SAFEARRAY ** ppsastrSecureBindings )
  187. {
  188. return StdPropertyGet ( &m_mszSecureBindings, ppsastrSecureBindings );
  189. }
  190. STDMETHODIMP CSmtpAdminVirtualServer::put_SecureBindings( SAFEARRAY * pstrSecureBindings )
  191. {
  192. return StdPropertyPut ( &m_mszSecureBindings, pstrSecureBindings, &m_bvChangedFields, BitMask(ID_SECURE_BINDINGS));
  193. }
  194. STDMETHODIMP CSmtpAdminVirtualServer::get_SecureBindingsVariant( SAFEARRAY ** ppsavarSecureBindings )
  195. {
  196. HRESULT hr;
  197. SAFEARRAY * psastrSecureServerBindings = NULL;
  198. hr = get_SecureBindings ( &psastrSecureServerBindings );
  199. if ( FAILED(hr) ) {
  200. goto Exit;
  201. }
  202. hr = StringArrayToVariantArray ( psastrSecureServerBindings, ppsavarSecureBindings );
  203. Exit:
  204. if ( psastrSecureServerBindings ) {
  205. SafeArrayDestroy ( psastrSecureServerBindings );
  206. }
  207. return hr;
  208. }
  209. STDMETHODIMP CSmtpAdminVirtualServer::put_SecureBindingsVariant( SAFEARRAY * psavarSecureBindings )
  210. {
  211. HRESULT hr;
  212. SAFEARRAY * psastrSecureServerBindings = NULL;
  213. hr = VariantArrayToStringArray ( psavarSecureBindings, &psastrSecureServerBindings );
  214. if ( FAILED(hr) ) {
  215. goto Exit;
  216. }
  217. hr = put_SecureBindings ( psastrSecureServerBindings );
  218. Exit:
  219. if ( psastrSecureServerBindings ) {
  220. SafeArrayDestroy ( psastrSecureServerBindings );
  221. }
  222. return hr;
  223. }
  224. STDMETHODIMP CSmtpAdminVirtualServer::get_Port( long * plPort )
  225. {
  226. return StdPropertyGet ( m_lPort, plPort );
  227. }
  228. STDMETHODIMP CSmtpAdminVirtualServer::put_Port( long lPort )
  229. {
  230. return StdPropertyPut ( &m_lPort, lPort, &m_bvChangedFields, BitMask(ID_PORT));
  231. }
  232. STDMETHODIMP CSmtpAdminVirtualServer::get_SSLPort( long * plSSLPort )
  233. {
  234. return StdPropertyGet ( m_lSSLPort, plSSLPort );
  235. }
  236. STDMETHODIMP CSmtpAdminVirtualServer::put_SSLPort( long lSSLPort )
  237. {
  238. return StdPropertyPut ( &m_lSSLPort, lSSLPort, &m_bvChangedFields, BitMask(ID_SSLPORT));
  239. }
  240. STDMETHODIMP CSmtpAdminVirtualServer::get_OutboundPort( long * plOutboundPort )
  241. {
  242. return StdPropertyGet ( m_lOutboundPort, plOutboundPort );
  243. }
  244. STDMETHODIMP CSmtpAdminVirtualServer::put_OutboundPort( long lOutboundPort )
  245. {
  246. return StdPropertyPut ( &m_lOutboundPort, lOutboundPort, &m_bvChangedFields, BitMask(ID_OUTBOUNDPORT));
  247. }
  248. STDMETHODIMP CSmtpAdminVirtualServer::get_HopCount( long * plHopCount )
  249. {
  250. return StdPropertyGet ( m_lHopCount, plHopCount );
  251. }
  252. STDMETHODIMP CSmtpAdminVirtualServer::put_HopCount( long lHopCount )
  253. {
  254. return StdPropertyPut ( &m_lHopCount, lHopCount, &m_bvChangedFields, BitMask(ID_HOP_COUNT));
  255. }
  256. STDMETHODIMP CSmtpAdminVirtualServer::get_SmartHost( BSTR * pstrSmartHost )
  257. {
  258. return StdPropertyGet ( m_strSmartHost, pstrSmartHost );
  259. }
  260. STDMETHODIMP CSmtpAdminVirtualServer::put_SmartHost( BSTR strSmartHost )
  261. {
  262. return StdPropertyPut ( &m_strSmartHost, strSmartHost, &m_bvChangedFields, BitMask(ID_SMARTHOST));
  263. }
  264. STDMETHODIMP CSmtpAdminVirtualServer::get_EnableDNSLookup( BOOL * pfEnableDNSLookup )
  265. {
  266. return StdPropertyGet ( m_fEnableDNSLookup, pfEnableDNSLookup );
  267. }
  268. STDMETHODIMP CSmtpAdminVirtualServer::put_EnableDNSLookup( BOOL fEnableDNSLookup )
  269. {
  270. return StdPropertyPut ( &m_fEnableDNSLookup, fEnableDNSLookup, &m_bvChangedFields, BitMask(ID_ENABLEDNSLOOKUP));
  271. }
  272. STDMETHODIMP CSmtpAdminVirtualServer::get_PostmasterEmail( BSTR * pstrPostmasterEmail )
  273. {
  274. return StdPropertyGet ( m_strPostmasterEmail, pstrPostmasterEmail );
  275. }
  276. STDMETHODIMP CSmtpAdminVirtualServer::put_PostmasterEmail( BSTR strPostmasterEmail )
  277. {
  278. return StdPropertyPut ( &m_strPostmasterEmail, strPostmasterEmail, &m_bvChangedFields, BitMask(ID_POSTMASTEREMAIL));
  279. }
  280. STDMETHODIMP CSmtpAdminVirtualServer::get_PostmasterName( BSTR * pstrPostmasterName )
  281. {
  282. return StdPropertyGet ( m_strPostmasterName, pstrPostmasterName );
  283. }
  284. STDMETHODIMP CSmtpAdminVirtualServer::put_PostmasterName( BSTR strPostmasterName )
  285. {
  286. return StdPropertyPut ( &m_strPostmasterName, strPostmasterName, &m_bvChangedFields, BitMask(ID_POSTMASTERNAME));
  287. }
  288. STDMETHODIMP CSmtpAdminVirtualServer::get_DefaultDomain( BSTR * pstrDefaultDomain )
  289. {
  290. return StdPropertyGet ( m_strDefaultDomain, pstrDefaultDomain );
  291. }
  292. STDMETHODIMP CSmtpAdminVirtualServer::put_DefaultDomain( BSTR strDefaultDomain )
  293. {
  294. return StdPropertyPut ( &m_strDefaultDomain, strDefaultDomain, &m_bvChangedFields, BitMask(ID_DEFAULTDOMAIN));
  295. }
  296. STDMETHODIMP CSmtpAdminVirtualServer::get_FQDN( BSTR * pstrFQDN )
  297. {
  298. return StdPropertyGet ( m_strFQDN, pstrFQDN );
  299. }
  300. STDMETHODIMP CSmtpAdminVirtualServer::put_FQDN( BSTR strFQDN )
  301. {
  302. return StdPropertyPut ( &m_strFQDN, strFQDN, &m_bvChangedFields, BitMask(ID_FQDN));
  303. }
  304. STDMETHODIMP CSmtpAdminVirtualServer::get_DropDir( BSTR * pstrDropDir )
  305. {
  306. return StdPropertyGet ( m_strDropDir, pstrDropDir );
  307. }
  308. STDMETHODIMP CSmtpAdminVirtualServer::put_DropDir( BSTR strDropDir )
  309. {
  310. return StdPropertyPut ( &m_strDropDir, strDropDir, &m_bvChangedFields, BitMask(ID_DROPDIR));
  311. }
  312. STDMETHODIMP CSmtpAdminVirtualServer::get_BadMailDir( BSTR * pstrBadMailDir )
  313. {
  314. return StdPropertyGet ( m_strBadMailDir, pstrBadMailDir );
  315. }
  316. STDMETHODIMP CSmtpAdminVirtualServer::put_BadMailDir( BSTR strBadMailDir )
  317. {
  318. return StdPropertyPut ( &m_strBadMailDir, strBadMailDir, &m_bvChangedFields, BitMask(ID_BADMAILDIR));
  319. }
  320. STDMETHODIMP CSmtpAdminVirtualServer::get_PickupDir( BSTR * pstrPickupDir )
  321. {
  322. return StdPropertyGet ( m_strPickupDir, pstrPickupDir );
  323. }
  324. STDMETHODIMP CSmtpAdminVirtualServer::put_PickupDir( BSTR strPickupDir )
  325. {
  326. return StdPropertyPut ( &m_strPickupDir, strPickupDir, &m_bvChangedFields, BitMask(ID_PICKUPDIR));
  327. }
  328. STDMETHODIMP CSmtpAdminVirtualServer::get_QueueDir( BSTR * pstrQueueDir )
  329. {
  330. return StdPropertyGet ( m_strQueueDir, pstrQueueDir );
  331. }
  332. STDMETHODIMP CSmtpAdminVirtualServer::put_QueueDir( BSTR strQueueDir )
  333. {
  334. return StdPropertyPut ( &m_strQueueDir, strQueueDir, &m_bvChangedFields, BitMask(ID_QUEUEDIR));
  335. }
  336. STDMETHODIMP CSmtpAdminVirtualServer::get_MaxInConnection( long * plMaxInConnection )
  337. {
  338. return StdPropertyGet ( m_lMaxInConnection, plMaxInConnection );
  339. }
  340. STDMETHODIMP CSmtpAdminVirtualServer::put_MaxInConnection( long lMaxInConnection )
  341. {
  342. return StdPropertyPut ( &m_lMaxInConnection, lMaxInConnection, &m_bvChangedFields, BitMask(ID_MAXINCONNECTION));
  343. }
  344. STDMETHODIMP CSmtpAdminVirtualServer::get_MaxOutConnection( long * plMaxOutConnection )
  345. {
  346. return StdPropertyGet ( m_lMaxOutConnection, plMaxOutConnection );
  347. }
  348. STDMETHODIMP CSmtpAdminVirtualServer::put_MaxOutConnection( long lMaxOutConnection )
  349. {
  350. return StdPropertyPut ( &m_lMaxOutConnection, lMaxOutConnection, &m_bvChangedFields, BitMask(ID_MAXOUTCONNECTION));
  351. }
  352. STDMETHODIMP CSmtpAdminVirtualServer::get_InConnectionTimeout( long * plInConnectionTimeout )
  353. {
  354. return StdPropertyGet ( m_lInConnectionTimeout, plInConnectionTimeout );
  355. }
  356. STDMETHODIMP CSmtpAdminVirtualServer::put_InConnectionTimeout( long lInConnectionTimeout )
  357. {
  358. return StdPropertyPut ( &m_lInConnectionTimeout, lInConnectionTimeout, &m_bvChangedFields, BitMask(ID_INCONNECTIONTIMEOUT));
  359. }
  360. STDMETHODIMP CSmtpAdminVirtualServer::get_OutConnectionTimeout( long * plOutConnectionTimeout )
  361. {
  362. return StdPropertyGet ( m_lOutConnectionTimeout, plOutConnectionTimeout );
  363. }
  364. STDMETHODIMP CSmtpAdminVirtualServer::put_OutConnectionTimeout( long lOutConnectionTimeout )
  365. {
  366. return StdPropertyPut ( &m_lOutConnectionTimeout, lOutConnectionTimeout, &m_bvChangedFields, BitMask(ID_OUTCONNECTIONTIMEOUT));
  367. }
  368. STDMETHODIMP CSmtpAdminVirtualServer::get_MaxMessageSize( long * plMaxMessageSize )
  369. {
  370. return StdPropertyGet ( m_lMaxMessageSize, plMaxMessageSize );
  371. }
  372. STDMETHODIMP CSmtpAdminVirtualServer::put_MaxMessageSize( long lMaxMessageSize )
  373. {
  374. return StdPropertyPut ( &m_lMaxMessageSize, lMaxMessageSize, &m_bvChangedFields, BitMask(ID_MAXMESSAGESIZE));
  375. }
  376. STDMETHODIMP CSmtpAdminVirtualServer::get_MaxSessionSize( long * plMaxSessionSize )
  377. {
  378. return StdPropertyGet ( m_lMaxSessionSize, plMaxSessionSize );
  379. }
  380. STDMETHODIMP CSmtpAdminVirtualServer::put_MaxSessionSize( long lMaxSessionSize )
  381. {
  382. return StdPropertyPut ( &m_lMaxSessionSize, lMaxSessionSize, &m_bvChangedFields, BitMask(ID_MAXSESSIONSIZE));
  383. }
  384. STDMETHODIMP CSmtpAdminVirtualServer::get_MaxMessageRecipients( long * plMaxMessageRecipients )
  385. {
  386. return StdPropertyGet ( m_lMaxMessageRecipients, plMaxMessageRecipients );
  387. }
  388. STDMETHODIMP CSmtpAdminVirtualServer::put_MaxMessageRecipients( long lMaxMessageRecipients )
  389. {
  390. return StdPropertyPut ( &m_lMaxMessageRecipients, lMaxMessageRecipients, &m_bvChangedFields, BitMask(ID_MAXMESSAGERECIPIENTS));
  391. }
  392. STDMETHODIMP CSmtpAdminVirtualServer::get_LocalRetries( long * plLocalRetries )
  393. {
  394. return StdPropertyGet ( m_lLocalRetries, plLocalRetries );
  395. }
  396. STDMETHODIMP CSmtpAdminVirtualServer::put_LocalRetries( long lLocalRetries )
  397. {
  398. return StdPropertyPut ( &m_lLocalRetries, lLocalRetries, &m_bvChangedFields, BitMask(ID_LOCALRETRIES));
  399. }
  400. STDMETHODIMP CSmtpAdminVirtualServer::get_LocalRetryTime( long * plLocalRetryTime )
  401. {
  402. return StdPropertyGet ( m_lLocalRetryTime, plLocalRetryTime );
  403. }
  404. STDMETHODIMP CSmtpAdminVirtualServer::put_LocalRetryTime( long lLocalRetryTime )
  405. {
  406. return StdPropertyPut ( &m_lLocalRetryTime, lLocalRetryTime, &m_bvChangedFields, BitMask(ID_LOCALRETRYTIME));
  407. }
  408. STDMETHODIMP CSmtpAdminVirtualServer::get_RemoteRetries( long * plRemoteRetries )
  409. {
  410. return StdPropertyGet ( m_lRemoteRetries, plRemoteRetries );
  411. }
  412. STDMETHODIMP CSmtpAdminVirtualServer::put_RemoteRetries( long lRemoteRetries )
  413. {
  414. return StdPropertyPut ( &m_lRemoteRetries, lRemoteRetries, &m_bvChangedFields, BitMask(ID_REMOTERETRIES));
  415. }
  416. STDMETHODIMP CSmtpAdminVirtualServer::get_RemoteRetryTime( long * plRemoteRetryTime )
  417. {
  418. return StdPropertyGet ( m_lRemoteRetryTime, plRemoteRetryTime );
  419. }
  420. STDMETHODIMP CSmtpAdminVirtualServer::put_RemoteRetryTime( long lRemoteRetryTime )
  421. {
  422. return StdPropertyPut ( &m_lRemoteRetryTime, lRemoteRetryTime, &m_bvChangedFields, BitMask(ID_REMOTERETRYTIME));
  423. }
  424. STDMETHODIMP CSmtpAdminVirtualServer::get_ETRNDays( long * plETRNDays )
  425. {
  426. return StdPropertyGet ( m_lETRNDays, plETRNDays );
  427. }
  428. STDMETHODIMP CSmtpAdminVirtualServer::put_ETRNDays( long lETRNDays )
  429. {
  430. return StdPropertyPut ( &m_lETRNDays, lETRNDays, &m_bvChangedFields, BitMask(ID_ETRNDAYS));
  431. }
  432. STDMETHODIMP CSmtpAdminVirtualServer::get_SendDNRToPostmaster( BOOL * pfSendDNRToPostmaster )
  433. {
  434. return StdPropertyGet ( m_fSendDNRToPostmaster, pfSendDNRToPostmaster );
  435. }
  436. STDMETHODIMP CSmtpAdminVirtualServer::put_SendDNRToPostmaster( BOOL fSendDNRToPostmaster )
  437. {
  438. return StdPropertyPut ( &m_fSendDNRToPostmaster, fSendDNRToPostmaster, &m_bvChangedFields, BitMask(ID_SENDDNRTOPOSTMASTER));
  439. }
  440. STDMETHODIMP CSmtpAdminVirtualServer::get_SendBadmailToPostmaster( BOOL * pfSendBadmailToPostmaster)
  441. {
  442. return StdPropertyGet ( m_fSendBadmailToPostmaster, pfSendBadmailToPostmaster );
  443. }
  444. STDMETHODIMP CSmtpAdminVirtualServer::put_SendBadmailToPostmaster( BOOL fSendBadmailToPostmaster )
  445. {
  446. return StdPropertyPut ( &m_fSendBadmailToPostmaster, fSendBadmailToPostmaster, &m_bvChangedFields, BitMask(ID_SENDBADMAILTOPOSTMASTER));
  447. }
  448. STDMETHODIMP CSmtpAdminVirtualServer::get_RoutingDLL( BSTR * pstrRoutingDLL )
  449. {
  450. return StdPropertyGet ( m_strRoutingDLL, pstrRoutingDLL );
  451. }
  452. STDMETHODIMP CSmtpAdminVirtualServer::put_RoutingDLL( BSTR strRoutingDLL )
  453. {
  454. return StdPropertyPut ( &m_strRoutingDLL, strRoutingDLL, &m_bvChangedFields, BitMask(ID_ROUTINGDLL));
  455. }
  456. STDMETHODIMP CSmtpAdminVirtualServer::get_RoutingSources ( SAFEARRAY ** ppsastrRoutingSources )
  457. {
  458. return StdPropertyGet ( &m_mszRoutingSources, ppsastrRoutingSources );
  459. }
  460. STDMETHODIMP CSmtpAdminVirtualServer::put_RoutingSources ( SAFEARRAY * psastrRoutingSources )
  461. {
  462. return StdPropertyPut ( &m_mszRoutingSources, psastrRoutingSources, &m_bvChangedFields, BitMask(ID_ROUTINGSOURCES) );
  463. }
  464. STDMETHODIMP CSmtpAdminVirtualServer::get_RoutingSourcesVariant( SAFEARRAY ** ppsavarRoutingSources )
  465. {
  466. HRESULT hr;
  467. SAFEARRAY * psastrRoutingSources = NULL;
  468. hr = get_RoutingSources ( &psastrRoutingSources );
  469. if ( FAILED(hr) ) {
  470. goto Exit;
  471. }
  472. hr = StringArrayToVariantArray ( psastrRoutingSources, ppsavarRoutingSources );
  473. Exit:
  474. if ( psastrRoutingSources ) {
  475. SafeArrayDestroy ( psastrRoutingSources );
  476. }
  477. return hr;
  478. }
  479. STDMETHODIMP CSmtpAdminVirtualServer::put_RoutingSourcesVariant( SAFEARRAY * psavarRoutingSources )
  480. {
  481. HRESULT hr;
  482. SAFEARRAY * psastrRoutingSources = NULL;
  483. hr = VariantArrayToStringArray ( psavarRoutingSources, &psastrRoutingSources );
  484. if ( FAILED(hr) ) {
  485. goto Exit;
  486. }
  487. hr = put_RoutingSources ( psastrRoutingSources );
  488. Exit:
  489. if ( psastrRoutingSources ) {
  490. SafeArrayDestroy ( psastrRoutingSources );
  491. }
  492. return hr;
  493. }
  494. STDMETHODIMP CSmtpAdminVirtualServer::get_LocalDomains ( SAFEARRAY ** ppsastrLocalDomains )
  495. {
  496. return StdPropertyGet ( &m_mszLocalDomains, ppsastrLocalDomains );
  497. }
  498. STDMETHODIMP CSmtpAdminVirtualServer::put_LocalDomains ( SAFEARRAY * psastrLocalDomains )
  499. {
  500. return StdPropertyPut ( &m_mszLocalDomains, psastrLocalDomains, &m_bvChangedFields, BitMask(ID_LOCALDOMAINS) );
  501. }
  502. STDMETHODIMP CSmtpAdminVirtualServer::get_DomainRouting ( SAFEARRAY ** ppsastrDomainRouting )
  503. {
  504. return StdPropertyGet ( &m_mszDomainRouting, ppsastrDomainRouting );
  505. }
  506. STDMETHODIMP CSmtpAdminVirtualServer::put_DomainRouting ( SAFEARRAY * psastrDomainRouting )
  507. {
  508. return StdPropertyPut ( &m_mszDomainRouting, psastrDomainRouting, &m_bvChangedFields, BitMask(ID_DOMAINROUTING) );
  509. }
  510. STDMETHODIMP CSmtpAdminVirtualServer::get_DomainRoutingVariant( SAFEARRAY ** ppsavarDomainRouting )
  511. {
  512. HRESULT hr;
  513. SAFEARRAY * pstrDomainRouting = NULL;
  514. hr = get_DomainRouting ( &pstrDomainRouting );
  515. if ( FAILED(hr) ) {
  516. goto Exit;
  517. }
  518. hr = StringArrayToVariantArray ( pstrDomainRouting, ppsavarDomainRouting );
  519. Exit:
  520. if ( pstrDomainRouting ) {
  521. SafeArrayDestroy ( pstrDomainRouting );
  522. }
  523. return hr;
  524. }
  525. STDMETHODIMP CSmtpAdminVirtualServer::put_DomainRoutingVariant( SAFEARRAY * psastrDomainRouting )
  526. {
  527. HRESULT hr;
  528. SAFEARRAY * pstrDomainRouting = NULL;
  529. hr = VariantArrayToStringArray ( psastrDomainRouting, &pstrDomainRouting );
  530. if ( FAILED(hr) ) {
  531. goto Exit;
  532. }
  533. hr = put_DomainRouting ( pstrDomainRouting );
  534. Exit:
  535. if ( pstrDomainRouting ) {
  536. SafeArrayDestroy ( pstrDomainRouting );
  537. }
  538. return hr;
  539. }
  540. STDMETHODIMP CSmtpAdminVirtualServer::get_MasqueradeDomain( BSTR * pstrMasqueradeDomain )
  541. {
  542. return StdPropertyGet ( m_strMasqueradeDomain, pstrMasqueradeDomain );
  543. }
  544. STDMETHODIMP CSmtpAdminVirtualServer::put_MasqueradeDomain( BSTR strMasqueradeDomain )
  545. {
  546. return StdPropertyPut ( &m_strMasqueradeDomain, strMasqueradeDomain, &m_bvChangedFields, BitMask(ID_MASQUERADE));
  547. }
  548. STDMETHODIMP CSmtpAdminVirtualServer::get_SendNdrTo( BSTR * pstrAddr )
  549. {
  550. return StdPropertyGet( m_strNdrAddr, pstrAddr );
  551. }
  552. STDMETHODIMP CSmtpAdminVirtualServer::put_SendNdrTo( BSTR strAddr )
  553. {
  554. return StdPropertyPut ( &m_strNdrAddr, strAddr, &m_bvChangedFields, BitMask(ID_SENDNDRTO));
  555. }
  556. STDMETHODIMP CSmtpAdminVirtualServer::get_SendBadTo( BSTR * pstrAddr )
  557. {
  558. return StdPropertyGet( m_strBadAddr, pstrAddr );
  559. }
  560. STDMETHODIMP CSmtpAdminVirtualServer::put_SendBadTo( BSTR strAddr )
  561. {
  562. return StdPropertyPut ( &m_strBadAddr, strAddr, &m_bvChangedFields, BitMask(ID_SENDBADTO));
  563. }
  564. STDMETHODIMP CSmtpAdminVirtualServer::get_RemoteSecurePort( long * plRemoteSecurePort )
  565. {
  566. return StdPropertyGet( m_lRemoteSecurePort, plRemoteSecurePort );
  567. }
  568. STDMETHODIMP CSmtpAdminVirtualServer::put_RemoteSecurePort( long lRemoteSecurePort )
  569. {
  570. return StdPropertyPut ( &m_lRemoteSecurePort, lRemoteSecurePort, &m_bvChangedFields, BitMask(ID_REMOTE_SECURE_PORT));
  571. }
  572. STDMETHODIMP CSmtpAdminVirtualServer::get_ShouldDeliver( BOOL * pfShouldDeliver )
  573. {
  574. return StdPropertyGet( m_fShouldDeliver, pfShouldDeliver );
  575. }
  576. STDMETHODIMP CSmtpAdminVirtualServer::put_ShouldDeliver( BOOL fShouldDeliver )
  577. {
  578. return StdPropertyPut ( &m_fShouldDeliver, fShouldDeliver, &m_bvChangedFields, BitMask(ID_SHOULD_DELIVER));
  579. }
  580. STDMETHODIMP CSmtpAdminVirtualServer::get_AlwaysUseSsl( BOOL * pfAlwaysUseSsl )
  581. {
  582. return StdPropertyGet( m_fAlwaysUseSsl, pfAlwaysUseSsl );
  583. }
  584. STDMETHODIMP CSmtpAdminVirtualServer::put_AlwaysUseSsl( BOOL fAlwaysUseSsl )
  585. {
  586. return StdPropertyPut ( &m_fAlwaysUseSsl, fAlwaysUseSsl, &m_bvChangedFields, BitMask(ID_ALWAYS_USE_SSL));
  587. }
  588. STDMETHODIMP CSmtpAdminVirtualServer::get_LimitRemoteConnections( BOOL * pfLimitRemoteConnections )
  589. {
  590. return StdPropertyGet( m_fLimitRemoteConnections, pfLimitRemoteConnections );
  591. }
  592. STDMETHODIMP CSmtpAdminVirtualServer::put_LimitRemoteConnections( BOOL fLimitRemoteConnections )
  593. {
  594. return StdPropertyPut ( &m_fLimitRemoteConnections, fLimitRemoteConnections, &m_bvChangedFields, BitMask(ID_LIMIT_REMOTE_CONNECTIONS));
  595. }
  596. STDMETHODIMP CSmtpAdminVirtualServer::get_MaxOutConnPerDomain( long * plMaxOutConnPerDomain )
  597. {
  598. return StdPropertyGet( m_lMaxOutConnPerDomain, plMaxOutConnPerDomain );
  599. }
  600. STDMETHODIMP CSmtpAdminVirtualServer::put_MaxOutConnPerDomain( long lMaxOutConnPerDomain )
  601. {
  602. return StdPropertyPut ( &m_lMaxOutConnPerDomain, lMaxOutConnPerDomain, &m_bvChangedFields, BitMask(ID_MAX_OUT_CONN_PER_DOMAIN));
  603. }
  604. STDMETHODIMP CSmtpAdminVirtualServer::get_AllowVerify( BOOL * pfAllowVerify )
  605. {
  606. return StdPropertyGet( m_fAllowVerify, pfAllowVerify );
  607. }
  608. STDMETHODIMP CSmtpAdminVirtualServer::put_AllowVerify( BOOL fAllowVerify )
  609. {
  610. return StdPropertyPut ( &m_fAllowVerify, fAllowVerify, &m_bvChangedFields, BitMask(ID_ALLOW_VERIFY));
  611. }
  612. STDMETHODIMP CSmtpAdminVirtualServer::get_AllowExpand( BOOL * pfAllowExpand )
  613. {
  614. return StdPropertyGet( m_fAllowExpand, pfAllowExpand);
  615. }
  616. STDMETHODIMP CSmtpAdminVirtualServer::put_AllowExpand( BOOL fAllowExpand )
  617. {
  618. return StdPropertyPut ( &m_fAllowExpand, fAllowExpand, &m_bvChangedFields, BitMask(ID_ALLOW_EXPAND));
  619. }
  620. STDMETHODIMP CSmtpAdminVirtualServer::get_SmartHostType( long * plSmartHostType )
  621. {
  622. return StdPropertyGet( m_lSmartHostType, plSmartHostType );
  623. }
  624. STDMETHODIMP CSmtpAdminVirtualServer::put_SmartHostType( long lSmartHostType )
  625. {
  626. return StdPropertyPut ( &m_lSmartHostType, lSmartHostType, &m_bvChangedFields, BitMask(ID_SMART_HOST_TYPE));
  627. }
  628. STDMETHODIMP CSmtpAdminVirtualServer::get_BatchMessages( BOOL * pfBatchMessages )
  629. {
  630. return StdPropertyGet( m_fBtachMsgs, pfBatchMessages );
  631. }
  632. STDMETHODIMP CSmtpAdminVirtualServer::put_BatchMessages( BOOL fBatchMessages )
  633. {
  634. return StdPropertyPut ( &m_fBtachMsgs, fBatchMessages, &m_bvChangedFields, BitMask(ID_BATCH_MSGS));
  635. }
  636. STDMETHODIMP CSmtpAdminVirtualServer::get_BatchMessageLimit( long * plBatchMessageLimit )
  637. {
  638. return StdPropertyGet( m_lBatchMsgLimit, plBatchMessageLimit );
  639. }
  640. STDMETHODIMP CSmtpAdminVirtualServer::put_BatchMessageLimit( long lBatchMessageLimit )
  641. {
  642. return StdPropertyPut ( &m_lBatchMsgLimit, lBatchMessageLimit, &m_bvChangedFields, BitMask(ID_BATCH_MSG_LIMIT));
  643. }
  644. STDMETHODIMP CSmtpAdminVirtualServer::get_DoMasquerade( BOOL * pfDoMasquerade )
  645. {
  646. return StdPropertyGet( m_fDoMasquerade, pfDoMasquerade );
  647. }
  648. STDMETHODIMP CSmtpAdminVirtualServer::put_DoMasquerade( BOOL fDoMasquerade )
  649. {
  650. return StdPropertyPut ( &m_fDoMasquerade, fDoMasquerade, &m_bvChangedFields, BitMask(ID_DO_MASQUERADE));
  651. }
  652. STDMETHODIMP CSmtpAdminVirtualServer::get_Administrators ( SAFEARRAY ** ppsastrAdmins )
  653. {
  654. TraceFunctEnter ( "CSmtpAdminVirtualServer::get_Administrators" );
  655. HRESULT hr = NOERROR;
  656. if ( m_psaAdmins ) {
  657. hr = SafeArrayCopy ( m_psaAdmins, ppsastrAdmins );
  658. }
  659. else {
  660. *ppsastrAdmins = NULL;
  661. hr = NOERROR;
  662. }
  663. TraceFunctLeave ();
  664. return hr;
  665. }
  666. STDMETHODIMP CSmtpAdminVirtualServer::put_Administrators ( SAFEARRAY * psastrAdmins )
  667. {
  668. TraceFunctEnter ( "CSmtpAdminVirtualServer::put_Administrators" );
  669. HRESULT hr = NOERROR;
  670. if ( m_psaAdmins ) {
  671. SafeArrayDestroy ( m_psaAdmins );
  672. }
  673. if ( psastrAdmins ) {
  674. hr = SafeArrayCopy ( psastrAdmins, &m_psaAdmins );
  675. }
  676. else {
  677. m_psaAdmins = NULL;
  678. hr = NOERROR;
  679. }
  680. TraceFunctLeave ();
  681. return hr;
  682. }
  683. STDMETHODIMP CSmtpAdminVirtualServer::get_AdministratorsVariant( SAFEARRAY ** ppsavarAdmins )
  684. {
  685. HRESULT hr;
  686. SAFEARRAY * psastrAdmins = NULL;
  687. hr = get_Administrators ( &psastrAdmins );
  688. if ( FAILED(hr) ) {
  689. goto Exit;
  690. }
  691. hr = StringArrayToVariantArray ( psastrAdmins, ppsavarAdmins );
  692. Exit:
  693. if ( psastrAdmins ) {
  694. SafeArrayDestroy ( psastrAdmins );
  695. }
  696. return hr;
  697. }
  698. STDMETHODIMP CSmtpAdminVirtualServer::put_AdministratorsVariant( SAFEARRAY * psavarAdmins )
  699. {
  700. HRESULT hr;
  701. SAFEARRAY * psastrAdmins = NULL;
  702. hr = VariantArrayToStringArray ( psavarAdmins, &psastrAdmins );
  703. if ( FAILED(hr) ) {
  704. goto Exit;
  705. }
  706. hr = put_Administrators ( psastrAdmins );
  707. Exit:
  708. if ( psastrAdmins ) {
  709. SafeArrayDestroy ( psastrAdmins );
  710. }
  711. return hr;
  712. }
  713. STDMETHODIMP CSmtpAdminVirtualServer::get_AuthenticationPackages(BSTR *pstrAuthPackages)
  714. {
  715. return StdPropertyGet(m_strAuthPackages, pstrAuthPackages);
  716. }
  717. STDMETHODIMP CSmtpAdminVirtualServer::put_AuthenticationPackages(BSTR strAuthPackages)
  718. {
  719. return StdPropertyPut(&m_strAuthPackages, strAuthPackages, &m_bvChangedFields,
  720. BitMask(ID_AUTH_PACKAGES));
  721. }
  722. STDMETHODIMP CSmtpAdminVirtualServer::get_ClearTextAuthPackage(BSTR *pstrAuthPackages)
  723. {
  724. return StdPropertyGet(m_strClearTextAuthPackage, pstrAuthPackages);
  725. }
  726. STDMETHODIMP CSmtpAdminVirtualServer::put_ClearTextAuthPackage(BSTR strAuthPackages)
  727. {
  728. return StdPropertyPut(&m_strClearTextAuthPackage, strAuthPackages, &m_bvChangedFields,
  729. BitMask(ID_CLEARTEXT_AUTH_PACKAGE));
  730. }
  731. STDMETHODIMP CSmtpAdminVirtualServer::get_AuthenticationMethod(long *plAuthMethod)
  732. {
  733. return StdPropertyGet(m_lAuthMethod, plAuthMethod);
  734. }
  735. STDMETHODIMP CSmtpAdminVirtualServer::put_AuthenticationMethod(long lAuthMethod)
  736. {
  737. return StdPropertyPut(&m_lAuthMethod, lAuthMethod, &m_bvChangedFields,
  738. BitMask(ID_AUTH_METHOD));
  739. }
  740. STDMETHODIMP CSmtpAdminVirtualServer::get_DefaultLogonDomain(BSTR *pstrLogonDomain)
  741. {
  742. return StdPropertyGet(m_strDefaultLogonDomain, pstrLogonDomain);
  743. }
  744. STDMETHODIMP CSmtpAdminVirtualServer::put_DefaultLogonDomain(BSTR strLogonDomain)
  745. {
  746. return StdPropertyPut(&m_strDefaultLogonDomain, strLogonDomain, &m_bvChangedFields,
  747. BitMask(ID_DEFAULT_LOGON_DOMAIN));
  748. }
  749. STDMETHODIMP CSmtpAdminVirtualServer::get_RouteAction(long *plRouteAction)
  750. {
  751. return StdPropertyGet(m_lRouteAction, plRouteAction);
  752. }
  753. STDMETHODIMP CSmtpAdminVirtualServer::put_RouteAction(long lRouteAction)
  754. {
  755. return StdPropertyPut(&m_lRouteAction, lRouteAction, &m_bvChangedFields,
  756. BitMask(ID_ROUTE_ACTION));
  757. }
  758. STDMETHODIMP CSmtpAdminVirtualServer::get_RouteUserName(BSTR *pstrRouteUserName)
  759. {
  760. return StdPropertyGet(m_strRouteUserName, pstrRouteUserName);
  761. }
  762. STDMETHODIMP CSmtpAdminVirtualServer::put_RouteUserName(BSTR strRouteUserName)
  763. {
  764. return StdPropertyPut(&m_strRouteUserName, strRouteUserName, &m_bvChangedFields,
  765. BitMask(ID_ROUTE_USER_NAME));
  766. }
  767. STDMETHODIMP CSmtpAdminVirtualServer::get_RoutePassword(BSTR *pstrRoutePassword)
  768. {
  769. return StdPropertyGet(m_strRoutePassword, pstrRoutePassword);
  770. }
  771. STDMETHODIMP CSmtpAdminVirtualServer::put_RoutePassword(BSTR strRoutePassword)
  772. {
  773. return StdPropertyPut(&m_strRoutePassword, strRoutePassword, &m_bvChangedFields,
  774. BitMask(ID_ROUTE_PASSWORD));
  775. }
  776. STDMETHODIMP CSmtpAdminVirtualServer::get_LogFileDirectory( BSTR * pstrLogFileDirectory )
  777. {
  778. return StdPropertyGet ( m_strLogFileDirectory, pstrLogFileDirectory );
  779. }
  780. STDMETHODIMP CSmtpAdminVirtualServer::put_LogFileDirectory( BSTR strLogFileDirectory )
  781. {
  782. return StdPropertyPut ( &m_strLogFileDirectory, strLogFileDirectory, &m_bvChangedFields, BitMask(ID_LOGFILEDIRECTORY));
  783. }
  784. STDMETHODIMP CSmtpAdminVirtualServer::get_LogFilePeriod( long * plLogFilePeriod )
  785. {
  786. return StdPropertyGet ( m_lLogFilePeriod, plLogFilePeriod );
  787. }
  788. STDMETHODIMP CSmtpAdminVirtualServer::put_LogFilePeriod( long lLogFilePeriod )
  789. {
  790. return StdPropertyPut ( &m_lLogFilePeriod, lLogFilePeriod, &m_bvChangedFields, BitMask(ID_LOGFILEPERIOD));
  791. }
  792. STDMETHODIMP CSmtpAdminVirtualServer::get_LogFileTruncateSize( long * plLogFileTruncateSize )
  793. {
  794. return StdPropertyGet ( m_lLogFileTruncateSize, plLogFileTruncateSize );
  795. }
  796. STDMETHODIMP CSmtpAdminVirtualServer::put_LogFileTruncateSize( long lLogFileTruncateSize )
  797. {
  798. return StdPropertyPut ( &m_lLogFileTruncateSize, lLogFileTruncateSize, &m_bvChangedFields, BitMask(ID_LOGFILETRUNCATESIZE));
  799. }
  800. STDMETHODIMP CSmtpAdminVirtualServer::get_LogMethod( long * plLogMethod )
  801. {
  802. return StdPropertyGet ( m_lLogMethod, plLogMethod );
  803. }
  804. STDMETHODIMP CSmtpAdminVirtualServer::put_LogMethod( long lLogMethod )
  805. {
  806. return StdPropertyPut ( &m_lLogMethod, lLogMethod, &m_bvChangedFields, BitMask(ID_LOGMETHOD));
  807. }
  808. STDMETHODIMP CSmtpAdminVirtualServer::get_LogType( long * plLogType )
  809. {
  810. return StdPropertyGet ( m_lLogType, plLogType );
  811. }
  812. STDMETHODIMP CSmtpAdminVirtualServer::put_LogType( long lLogType )
  813. {
  814. return StdPropertyPut ( &m_lLogType, lLogType, &m_bvChangedFields, BitMask(ID_LOGTYPE));
  815. }
  816. //
  817. // Service State Properties:
  818. //
  819. STDMETHODIMP CSmtpAdminVirtualServer::get_AutoStart ( BOOL * pfAutoStart )
  820. {
  821. return StdPropertyGet ( m_fAutoStart, pfAutoStart );
  822. }
  823. STDMETHODIMP CSmtpAdminVirtualServer::put_AutoStart ( BOOL fAutoStart )
  824. {
  825. return StdPropertyPut ( &m_fAutoStart, fAutoStart, &m_bvChangedFields, BitMask(ID_AUTOSTART) );
  826. }
  827. STDMETHODIMP CSmtpAdminVirtualServer::get_ServerState ( DWORD * pdwServerState )
  828. {
  829. return StdPropertyGet ( (long)m_dwServerState, (long *)pdwServerState );
  830. }
  831. STDMETHODIMP CSmtpAdminVirtualServer::get_Win32ErrorCode ( long * plWin32ErrorCode )
  832. {
  833. return StdPropertyGet ( m_dwWin32ErrorCode, plWin32ErrorCode );
  834. }
  835. // Service-specific properties:
  836. STDMETHODIMP CSmtpAdminVirtualServer::get_Comment( BSTR * pstrComment )
  837. {
  838. return StdPropertyGet ( m_strComment, pstrComment );
  839. }
  840. STDMETHODIMP CSmtpAdminVirtualServer::put_Comment( BSTR strComment )
  841. {
  842. return StdPropertyPut ( &m_strComment, strComment, &m_bvChangedFields, BitMask(ID_COMMENT));
  843. }
  844. /*
  845. STDMETHODIMP CSmtpAdminVirtualServer::get_ErrorControl ( BOOL * pfErrorControl )
  846. {
  847. return StdPropertyGet ( m_fErrorControl, pfErrorControl );
  848. }
  849. STDMETHODIMP CSmtpAdminVirtualServer::put_ErrorControl ( BOOL fErrorControl )
  850. {
  851. return StdPropertyPut ( &m_fErrorControl, fErrorControl );
  852. }
  853. */
  854. //////////////////////////////////////////////////////////////////////
  855. // Methods:
  856. //////////////////////////////////////////////////////////////////////
  857. STDMETHODIMP CSmtpAdminVirtualServer::BackupRoutingTable( BSTR strPath )
  858. {
  859. TraceFunctEnter ( "CSmtpAdminVirtualServer::BackupRoutingTable" );
  860. HRESULT hr = NOERROR;
  861. DWORD dwErr = NOERROR;
  862. dwErr = SmtpBackupRoutingTable (
  863. (LPWSTR) m_strServer,
  864. (LPWSTR) strPath,
  865. (int)m_dwServiceInstance );
  866. if ( dwErr != 0 ) {
  867. ErrorTraceX ( (LPARAM) this, "Failed to backup routing table: %x", dwErr );
  868. SetLastError( dwErr );
  869. hr = SmtpCreateExceptionFromWin32Error ( dwErr );
  870. goto Exit;
  871. }
  872. Exit:
  873. TraceFunctLeave ();
  874. return hr;
  875. }
  876. //$-------------------------------------------------------------------
  877. //
  878. // CSmtpAdminVirtualServer::Get
  879. //
  880. // Description:
  881. //
  882. // Gets server properties from the metabase.
  883. //
  884. // Parameters:
  885. //
  886. // (property) m_strServer
  887. // (property) m_dwServiceInstance - which SMTP to talk to.
  888. //
  889. // Returns:
  890. //
  891. // E_POINTER, DISP_E_EXCEPTION, E_OUTOFMEMORY or NOERROR.
  892. //
  893. //--------------------------------------------------------------------
  894. STDMETHODIMP CSmtpAdminVirtualServer::Get ( )
  895. {
  896. TraceFunctEnter ( "CSmtpAdminVirtualServer::Get" );
  897. HRESULT hr = NOERROR;
  898. CComPtr<IMSAdminBase> pmetabase;
  899. CComObject<CServerBindings> * pBindings = NULL;
  900. // Create the bindings collection:
  901. m_pBindings.Release ();
  902. hr = CComObject<CServerBindings>::CreateInstance ( &pBindings );
  903. if ( FAILED(hr) ) {
  904. FatalTrace ( (LPARAM) this, "Could not create bindings collection" );
  905. goto Exit;
  906. }
  907. hr = pBindings->QueryInterface ( IID_IServerBindings, (void **) &m_pBindings );
  908. _ASSERT ( SUCCEEDED(hr) );
  909. if ( FAILED(hr) ) {
  910. goto Exit;
  911. }
  912. m_pPrivateBindings = pBindings;
  913. // Validate Server & Service Instance:
  914. // Talk to the metabase:
  915. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  916. if ( FAILED(hr) ) {
  917. goto Exit;
  918. }
  919. hr = GetPropertiesFromMetabase ( pmetabase );
  920. if ( FAILED(hr) ) {
  921. goto Exit;
  922. }
  923. StateTrace ( 0, "Successfully got service properties" );
  924. m_fGotProperties = TRUE;
  925. m_bvChangedFields = 0;
  926. Exit:
  927. TraceFunctLeave ();
  928. return hr;
  929. // CComPtr automatically releases the metabase handle.
  930. }
  931. //$-------------------------------------------------------------------
  932. //
  933. // CSmtpAdminVirtualServer::Set
  934. //
  935. // Description:
  936. //
  937. // Sends server properties to the metabase.
  938. //
  939. // Parameters:
  940. //
  941. // (property) m_strServer
  942. // fFailIfChanged - return an error if the metabase has changed?
  943. //
  944. // Returns:
  945. //
  946. // E_POINTER, DISP_E_EXCEPTION, E_OUTOFMEMORY or NOERROR.
  947. //
  948. //--------------------------------------------------------------------
  949. STDMETHODIMP CSmtpAdminVirtualServer::Set ( BOOL fFailIfChanged )
  950. {
  951. TraceFunctEnter ( "CSmtpAdminVirtualServer::Set" );
  952. HRESULT hr = NOERROR;
  953. CComPtr<IMSAdminBase> pmetabase;
  954. // Make sure the client call Get first:
  955. if ( !m_fGotProperties ) {
  956. ErrorTrace ( 0, "Didn't call get first" );
  957. hr = SmtpCreateException ( IDS_SMTPEXCEPTION_DIDNT_CALL_GET );
  958. goto Exit;
  959. }
  960. // Validate Server & Service Instance:
  961. if ( m_dwServiceInstance == 0 ) {
  962. return SmtpCreateException ( IDS_SMTPEXCEPTION_SERVICE_INSTANCE_CANT_BE_ZERO );
  963. }
  964. if ( !m_fGotProperties ) {
  965. return SmtpCreateException ( IDS_SMTPEXCEPTION_DIDNT_CALL_GET );
  966. }
  967. // Validate data members:
  968. if ( !ValidateStrings () ) {
  969. hr = E_OUTOFMEMORY;
  970. goto Exit;
  971. }
  972. if ( !ValidateProperties ( ) ) {
  973. hr = SmtpCreateExceptionFromWin32Error ( ERROR_INVALID_PARAMETER );
  974. goto Exit;
  975. }
  976. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  977. if ( FAILED(hr) ) {
  978. goto Exit;
  979. }
  980. hr = SendPropertiesToMetabase ( fFailIfChanged, pmetabase );
  981. if ( FAILED(hr) ) {
  982. goto Exit;
  983. }
  984. StateTrace ( 0, "Successfully set service properties" );
  985. // successfully saved, reset change field bitmap
  986. m_bvChangedFields = 0;
  987. Exit:
  988. TraceFunctLeave ();
  989. return hr;
  990. }
  991. #define MAX_SLEEP_INST 30000
  992. #define SLEEP_INTERVAL 500
  993. HRESULT CSmtpAdminVirtualServer::ControlService (
  994. IMSAdminBase * pMetabase,
  995. DWORD ControlCode,
  996. DWORD dwDesiredState,
  997. DWORD dwPendingState
  998. )
  999. {
  1000. TraceFunctEnter ( "CSmtpAdminVirtualServer::ControlService" );
  1001. HRESULT hr = NOERROR;
  1002. DWORD dwCurrentState = dwPendingState;
  1003. DWORD dwOldState = dwPendingState;
  1004. DWORD dwSleepTotal = 0;
  1005. hr = CheckServiceState ( pMetabase, &dwCurrentState );
  1006. BAIL_ON_FAILURE(hr);
  1007. if ( dwCurrentState == dwDesiredState ) {
  1008. // Nothing to do...
  1009. goto Exit;
  1010. }
  1011. dwOldState = dwCurrentState;
  1012. //
  1013. // Special case: trying to start a paused service:
  1014. //
  1015. if ( dwDesiredState == MD_SERVER_STATE_STARTED &&
  1016. dwCurrentState == MD_SERVER_STATE_PAUSED ) {
  1017. ControlCode = MD_SERVER_COMMAND_CONTINUE;
  1018. dwPendingState = MD_SERVER_STATE_CONTINUING;
  1019. }
  1020. hr = WriteStateCommand ( pMetabase, ControlCode );
  1021. BAIL_ON_FAILURE(hr);
  1022. for(dwSleepTotal = 0, dwCurrentState = dwPendingState;
  1023. (dwCurrentState == dwPendingState || dwCurrentState == dwOldState) && (dwSleepTotal < MAX_SLEEP_INST);
  1024. dwSleepTotal += SLEEP_INTERVAL
  1025. )
  1026. {
  1027. Sleep ( SLEEP_INTERVAL );
  1028. hr = CheckServiceState ( pMetabase, &dwCurrentState );
  1029. BAIL_ON_FAILURE(hr);
  1030. if ( m_dwWin32ErrorCode != NOERROR ) {
  1031. //
  1032. // The service gave an error code.
  1033. //
  1034. break;
  1035. }
  1036. }
  1037. if ( dwSleepTotal >= MAX_SLEEP_INST ) {
  1038. hr = HRESULT_FROM_WIN32 ( ERROR_SERVICE_REQUEST_TIMEOUT );
  1039. goto Exit;
  1040. }
  1041. Exit:
  1042. // m_State = TranslateServerState ( dwCurrentState );
  1043. m_dwServerState = dwCurrentState;
  1044. TraceFunctLeave ();
  1045. return hr;
  1046. }
  1047. HRESULT CSmtpAdminVirtualServer::WriteStateCommand ( IMSAdminBase * pMetabase, DWORD ControlCode )
  1048. {
  1049. HRESULT hr = NOERROR;
  1050. CMetabaseKey metabase ( pMetabase );
  1051. BOOL fRet = TRUE;
  1052. TCHAR szInstancePath [ METADATA_MAX_NAME_LEN ];
  1053. GetMDInstancePath ( szInstancePath, m_dwServiceInstance );
  1054. hr = metabase.Open ( szInstancePath, METADATA_PERMISSION_WRITE );
  1055. if( FAILED(hr) )
  1056. {
  1057. hr = SmtpCreateExceptionFromWin32Error( GetLastError() );
  1058. goto Exit;
  1059. }
  1060. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_WIN32_ERROR, NOERROR, _T(""), IIS_MD_UT_SERVER, METADATA_VOLATILE );
  1061. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_SERVER_COMMAND, ControlCode );
  1062. if ( !fRet ) {
  1063. hr = SmtpCreateExceptionFromWin32Error ( GetLastError () );
  1064. goto Exit;
  1065. }
  1066. Exit:
  1067. return hr;
  1068. }
  1069. HRESULT CSmtpAdminVirtualServer::CheckServiceState ( IMSAdminBase * pMetabase, DWORD * pdwState )
  1070. {
  1071. HRESULT hr = NOERROR;
  1072. CMetabaseKey metabase ( pMetabase );
  1073. TCHAR szInstancePath [ METADATA_MAX_NAME_LEN ];
  1074. BOOL fRet = TRUE;
  1075. *pdwState = MD_SERVER_STATE_INVALID;
  1076. GetMDInstancePath ( szInstancePath, m_dwServiceInstance );
  1077. hr = metabase.Open ( szInstancePath );
  1078. if( FAILED(hr) )
  1079. {
  1080. hr = SmtpCreateExceptionFromWin32Error( GetLastError() );
  1081. goto Exit;
  1082. }
  1083. fRet = metabase.GetDword ( MD_WIN32_ERROR, &m_dwWin32ErrorCode );
  1084. fRet = metabase.GetDword ( MD_SERVER_STATE, pdwState );
  1085. Exit:
  1086. if ( !fRet ) {
  1087. hr = HRESULT_FROM_WIN32( GetLastError () );
  1088. }
  1089. return hr;
  1090. }
  1091. STDMETHODIMP CSmtpAdminVirtualServer::Start ( )
  1092. {
  1093. TraceFunctEnter ( "CSmtpAdminVirtualServer::Start" );
  1094. HRESULT hr = NOERROR;
  1095. CComPtr<IMSAdminBase> pmetabase;
  1096. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  1097. if ( FAILED(hr) ) {
  1098. goto Exit;
  1099. }
  1100. hr = ControlService (
  1101. pmetabase,
  1102. MD_SERVER_COMMAND_START,
  1103. MD_SERVER_STATE_STARTED,
  1104. MD_SERVER_STATE_STARTING
  1105. );
  1106. Exit:
  1107. TraceFunctLeave ();
  1108. return hr;
  1109. }
  1110. STDMETHODIMP CSmtpAdminVirtualServer::Pause ( )
  1111. {
  1112. TraceFunctEnter ( "CSmtpAdminVirtualServer::Pause" );
  1113. HRESULT hr = NOERROR;
  1114. CComPtr<IMSAdminBase> pmetabase;
  1115. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  1116. if ( FAILED(hr) ) {
  1117. goto Exit;
  1118. }
  1119. hr = ControlService (
  1120. pmetabase,
  1121. MD_SERVER_COMMAND_PAUSE,
  1122. MD_SERVER_STATE_PAUSED,
  1123. MD_SERVER_STATE_PAUSING
  1124. );
  1125. Exit:
  1126. TraceFunctLeave ();
  1127. return hr;
  1128. }
  1129. STDMETHODIMP CSmtpAdminVirtualServer::Continue ( )
  1130. {
  1131. TraceFunctEnter ( "CSmtpAdminVirtualServer::Pause" );
  1132. HRESULT hr = NOERROR;
  1133. CComPtr<IMSAdminBase> pmetabase;
  1134. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  1135. if ( FAILED(hr) ) {
  1136. goto Exit;
  1137. }
  1138. hr = ControlService (
  1139. pmetabase,
  1140. MD_SERVER_COMMAND_CONTINUE,
  1141. MD_SERVER_STATE_STARTED,
  1142. MD_SERVER_STATE_CONTINUING
  1143. );
  1144. Exit:
  1145. TraceFunctLeave ();
  1146. return hr;
  1147. }
  1148. STDMETHODIMP CSmtpAdminVirtualServer::Stop ( )
  1149. {
  1150. TraceFunctEnter ( "CSmtpAdminVirtualServer::Start" );
  1151. HRESULT hr = NOERROR;
  1152. CComPtr<IMSAdminBase> pmetabase;
  1153. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  1154. if ( FAILED(hr) ) {
  1155. goto Exit;
  1156. }
  1157. hr = ControlService (
  1158. pmetabase,
  1159. MD_SERVER_COMMAND_STOP,
  1160. MD_SERVER_STATE_STOPPED,
  1161. MD_SERVER_STATE_STOPPING
  1162. );
  1163. Exit:
  1164. TraceFunctLeave ();
  1165. return hr;
  1166. }
  1167. //$-------------------------------------------------------------------
  1168. //
  1169. // CSmtpAdminVirtualServer::GetPropertiesFromMetabase
  1170. //
  1171. // Description:
  1172. //
  1173. // Asks the metabase for each property in this class.
  1174. // This class's properties come from /LM/SmtpSvc/
  1175. //
  1176. // Parameters:
  1177. //
  1178. // pMetabase - The metabase object
  1179. //
  1180. // Returns:
  1181. //
  1182. //
  1183. //--------------------------------------------------------------------
  1184. HRESULT CSmtpAdminVirtualServer::GetPropertiesFromMetabase ( IMSAdminBase * pMetabase )
  1185. {
  1186. TraceFunctEnter ( "CSmtpAdminVirtualServer::GetPropertiesFromMetabase" );
  1187. HRESULT hr = NOERROR;
  1188. CMetabaseKey metabase ( pMetabase );
  1189. BOOL fRet = TRUE;
  1190. TCHAR szInstancePath [ METADATA_MAX_NAME_LEN ];
  1191. WCHAR wszDefaultComment[128]={0};
  1192. PSECURITY_DESCRIPTOR pSD = NULL;
  1193. DWORD cbSD = 0;
  1194. GetMDInstancePath ( szInstancePath, m_dwServiceInstance );
  1195. wsprintfW( wszDefaultComment, L"[SMTP Virtual Server #%d]", m_dwServiceInstance );
  1196. hr = metabase.Open ( szInstancePath );
  1197. if( FAILED(hr) )
  1198. {
  1199. hr = SmtpCreateExceptionFromWin32Error( GetLastError() );
  1200. goto Exit;
  1201. }
  1202. // Overridable server properties:
  1203. hr = m_RoutingSource.Get(&metabase);
  1204. BAIL_ON_FAILURE(hr);
  1205. #if 0
  1206. fRet = StdGetMetabaseProp ( &metabase, MD_SECURE_PORT, DEFAULT_SSLPORT, &m_lSSLPort ) && fRet;
  1207. #endif
  1208. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_SMTP_PORT, DEFAULT_OUTBOND_PORT, &m_lOutboundPort ) && fRet;
  1209. fRet = StdGetMetabaseProp ( &metabase, MD_SMARTHOST_NAME, DEFAULT_SMART_HOST, &m_strSmartHost ) && fRet;
  1210. fRet = StdGetMetabaseProp ( &metabase, MD_HOP_COUNT, DEFAULT_HOP_COUNT, &m_lHopCount ) && fRet;
  1211. fRet = StdGetMetabaseProp ( &metabase, MD_REVERSE_NAME_LOOKUP,DEFAULT_ENABLE_DNS_LOOKUP, &m_fEnableDNSLookup ) && fRet;
  1212. fRet = StdGetMetabaseProp ( &metabase, MD_POSTMASTER_EMAIL, DEFAULT_POSTMASTER_EMAIL, &m_strPostmasterEmail ) && fRet;
  1213. fRet = StdGetMetabaseProp ( &metabase, MD_POSTMASTER_NAME, DEFAULT_POSTMASTER_NAME, &m_strPostmasterName ) && fRet;
  1214. fRet = StdGetMetabaseProp ( &metabase, MD_FQDN_VALUE, DEFAULT_FQDN, &m_strFQDN ) && fRet;
  1215. fRet = StdGetMetabaseProp ( &metabase, MD_DEFAULT_DOMAIN_VALUE, DEFAULT_DEFAULT_DOMAIN, &m_strDefaultDomain ) && fRet;
  1216. fRet = StdGetMetabaseProp ( &metabase, MD_MAIL_DROP_DIR, DEFAULT_DROP_DIR, &m_strDropDir ) && fRet;
  1217. fRet = StdGetMetabaseProp ( &metabase, MD_BAD_MAIL_DIR, DEFAULT_BADMAIL_DIR, &m_strBadMailDir ) && fRet;
  1218. fRet = StdGetMetabaseProp ( &metabase, MD_MAIL_PICKUP_DIR, DEFAULT_PICKUP_DIR, &m_strPickupDir ) && fRet;
  1219. fRet = StdGetMetabaseProp ( &metabase, MD_MAIL_QUEUE_DIR, DEFAULT_QUEUE_DIR, &m_strQueueDir ) && fRet;
  1220. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_OUTBOUND_CONNECTION, DEFAULT_MAX_OUT_CONNECTION, &m_lMaxOutConnection ) && fRet;
  1221. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_TIMEOUT, DEFAULT_OUT_CONNECTION_TIMEOUT, &m_lOutConnectionTimeout ) && fRet;
  1222. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_MSG_SIZE, DEFAULT_MAX_MESSAGE_SIZE, &m_lMaxMessageSize ) && fRet;
  1223. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_MSG_SIZE_B4_CLOSE, DEFAULT_MAX_SESSION_SIZE, &m_lMaxSessionSize ) && fRet;
  1224. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_RECIPIENTS, DEFAULT_MAX_MESSAGE_RECIPIENTS, &m_lMaxMessageRecipients ) && fRet;
  1225. fRet = StdGetMetabaseProp ( &metabase, MD_LOCAL_RETRY_ATTEMPTS, DEFAULT_LOCAL_RETRIES, &m_lLocalRetries) && fRet;
  1226. fRet = StdGetMetabaseProp ( &metabase, MD_LOCAL_RETRY_MINUTES, DEFAULT_LOCAL_RETRY_TIME, &m_lLocalRetryTime) && fRet;
  1227. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_RETRY_ATTEMPTS, DEFAULT_REMOTE_RETRIES, &m_lRemoteRetries) && fRet;
  1228. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_RETRY_MINUTES, DEFAULT_REMOTE_RETRY_TIME, &m_lRemoteRetryTime) && fRet;
  1229. fRet = StdGetMetabaseProp ( &metabase, MD_ETRN_DAYS, DEFAULT_ETRN_DAYS, &m_lETRNDays) && fRet;
  1230. fRet = StdGetMetabaseProp ( &metabase, MD_ROUTING_DLL, DEFAULT_ROUTING_DLL, &m_strRoutingDLL) && fRet;
  1231. fRet = StdGetMetabaseProp ( &metabase, MD_ROUTING_SOURCES, DEFAULT_ROUTING_SOURCES, &m_mszRoutingSources) && fRet;
  1232. fRet = StdGetMetabaseProp ( &metabase, MD_LOCAL_DOMAINS, DEFAULT_LOCAL_DOMAINS, &m_mszLocalDomains) && fRet;
  1233. fRet = StdGetMetabaseProp ( &metabase, MD_DOMAIN_ROUTING, DEFAULT_DOMAIN_ROUTING, &m_mszDomainRouting) && fRet;
  1234. fRet = StdGetMetabaseProp ( &metabase, MD_MASQUERADE_NAME, DEFAULT_MASQUERADE_DOMAIN, &m_strMasqueradeDomain) && fRet;
  1235. fRet = StdGetMetabaseProp ( &metabase, MD_SEND_NDR_TO, DEFAULT_SENDNDRTO, &m_strNdrAddr) && fRet;
  1236. fRet = StdGetMetabaseProp ( &metabase, MD_SEND_BAD_TO, DEFAULT_SENDBADTO, &m_strBadAddr) && fRet;
  1237. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_SECURE_PORT, DEFAULT_REMOTE_SECURE_PORT, &m_lRemoteSecurePort) && fRet;
  1238. fRet = StdGetMetabaseProp ( &metabase, MD_SHOULD_DELIVER, DEFAULT_SHOULD_DELIVER, &m_fShouldDeliver ) && fRet;
  1239. fRet = StdGetMetabaseProp ( &metabase, MD_ALWAYS_USE_SSL, DEFAULT_ALWAYS_USE_SSL, &m_fAlwaysUseSsl ) && fRet;
  1240. fRet = StdGetMetabaseProp ( &metabase, MD_LIMIT_REMOTE_CONNECTIONS, DEFAULT_LIMIT_REMOTE_CONNECTIONS, &m_fLimitRemoteConnections ) && fRet;
  1241. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_OUT_CONN_PER_DOMAIN, DEFAULT_MAX_OUT_CONN_PER_DOMAIN, &m_lMaxOutConnPerDomain ) && fRet;
  1242. fRet = StdGetMetabaseProp ( &metabase, MD_SMARTHOST_TYPE, DEFAULT_SMART_HOST_TYPE, &m_lSmartHostType ) && fRet;
  1243. fRet = StdGetMetabaseProp ( &metabase, MD_BATCH_MSG_LIMIT, DEFAULT_BATCH_MSG_LIMIT, &m_lBatchMsgLimit ) && fRet;
  1244. fRet = StdGetMetabaseProp ( &metabase, MD_DO_MASQUERADE, DEFAULT_DO_MASQUERADE, &m_fDoMasquerade ) && fRet;
  1245. fRet = StdGetMetabaseProp ( &metabase, MD_ROUTE_ACTION, DEFAULT_ROUTE_ACTION, &m_lRouteAction ) && fRet;
  1246. fRet = StdGetMetabaseProp ( &metabase, MD_ROUTE_USER_NAME, DEFAULT_ROUTE_USER_NAME, &m_strRouteUserName ) && fRet;
  1247. fRet = StdGetMetabaseProp ( &metabase, MD_ROUTE_PASSWORD, DEFAULT_ROUTE_PASSWORD, &m_strRoutePassword ) && fRet;
  1248. //
  1249. // IIS common propperties
  1250. //
  1251. fRet = StdGetMetabaseProp ( &metabase, MD_SERVER_BINDINGS, DEFAULT_SERVER_BINDINGS, &m_mszServerBindings ) && fRet;
  1252. fRet = StdGetMetabaseProp ( &metabase, MD_SECURE_BINDINGS, DEFAULT_SECURE_BINDINGS, &m_mszSecureBindings ) && fRet;
  1253. // fRet = StdGetMetabaseProp ( &metabase, MD_PORT, DEFAULT_PORT, &m_lPort ) && fRet;
  1254. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_CONNECTIONS, DEFAULT_MAX_IN_CONNECTION, &m_lMaxInConnection ) && fRet;
  1255. fRet = StdGetMetabaseProp ( &metabase, MD_CONNECTION_TIMEOUT,DEFAULT_IN_CONNECTION_TIMEOUT, &m_lInConnectionTimeout ) && fRet;
  1256. fRet = StdGetMetabaseProp ( &metabase, MD_NTAUTHENTICATION_PROVIDERS, DEFAULT_AUTH_PACKAGES, &m_strAuthPackages) && fRet;
  1257. fRet = StdGetMetabaseProp ( &metabase, MD_SMTP_CLEARTEXT_AUTH_PROVIDER, DEFAULT_CLEARTEXT_AUTH_PACKAGE, &m_strClearTextAuthPackage) && fRet;
  1258. fRet = StdGetMetabaseProp ( &metabase, MD_AUTHORIZATION, DEFAULT_AUTHENTICATION, &m_lAuthMethod) && fRet;
  1259. fRet = StdGetMetabaseProp ( &metabase, MD_SASL_LOGON_DOMAIN, DEFAULT_LOGON_DOMAIN, &m_strDefaultLogonDomain) && fRet;
  1260. fRet = StdGetMetabaseProp ( &metabase, MD_LOGFILE_DIRECTORY, DEFAULT_LOGFILE_DIRECTORY, &m_strLogFileDirectory) && fRet;
  1261. fRet = StdGetMetabaseProp ( &metabase, MD_LOGFILE_PERIOD, DEFAULT_LOGFILE_PERIOD, &m_lLogFilePeriod) && fRet;
  1262. fRet = StdGetMetabaseProp ( &metabase, MD_LOGFILE_TRUNCATE_SIZE,DEFAULT_LOGFILE_TRUNCATE_SIZE, &m_lLogFileTruncateSize) && fRet;
  1263. fRet = StdGetMetabaseProp ( &metabase, MD_LOG_TYPE, DEFAULT_LOG_TYPE, &m_lLogType) && fRet;
  1264. fRet = StdGetMetabaseProp ( &metabase, MD_SERVER_AUTOSTART, DEFAULT_AUTOSTART, &m_fAutoStart ) && fRet;
  1265. fRet = StdGetMetabaseProp ( &metabase, MD_SERVER_COMMENT, wszDefaultComment, &m_strComment ) && fRet;
  1266. fRet = StdGetMetabaseProp ( &metabase, MD_SERVER_STATE, MD_SERVER_STATE_STOPPED, &m_dwServerState ) && fRet;
  1267. fRet = StdGetMetabaseProp ( &metabase, MD_WIN32_ERROR, NOERROR, &m_dwWin32ErrorCode ) && fRet;
  1268. // Get the admin ACL
  1269. pSD = NULL;
  1270. cbSD = 0;
  1271. hr = metabase.GetDataSize ( _T(""), MD_ADMIN_ACL, BINARY_METADATA, &cbSD );
  1272. if( SUCCEEDED(hr) )
  1273. {
  1274. _ASSERT ( cbSD != 0 );
  1275. pSD = (PSECURITY_DESCRIPTOR) new char [ cbSD ];
  1276. if( NULL == pSD )
  1277. {
  1278. hr = E_OUTOFMEMORY;
  1279. goto Exit;
  1280. }
  1281. hr = NOERROR;
  1282. hr = metabase.GetBinary ( MD_ADMIN_ACL, pSD, cbSD );
  1283. BAIL_ON_FAILURE(hr);
  1284. }
  1285. //
  1286. // Get the tcp access restrictions:
  1287. //
  1288. hr = m_pPrivateIpAccess->GetFromMetabase ( &metabase );
  1289. BAIL_ON_FAILURE(hr);
  1290. // Check all property strings:
  1291. // If any string is NULL, it is because we failed to allocate memory:
  1292. if ( !ValidateStrings () ) {
  1293. hr = E_OUTOFMEMORY;
  1294. goto Exit;
  1295. }
  1296. // We can only fail from memory allocations:
  1297. _ASSERT ( fRet );
  1298. // Save the last changed time for this key:
  1299. m_ftLastChanged.dwHighDateTime = 0;
  1300. m_ftLastChanged.dwLowDateTime = 0;
  1301. hr = pMetabase->GetLastChangeTime ( metabase.QueryHandle(), _T(""), &m_ftLastChanged, FALSE );
  1302. if ( FAILED (hr) ) {
  1303. ErrorTraceX ( (LPARAM) this, "Failed to get last change time: %x", hr );
  1304. // Ignore this error.
  1305. hr = NOERROR;
  1306. }
  1307. // Extract the bindings:
  1308. hr = MDBindingsToIBindings ( &m_mszServerBindings, TRUE, m_pBindings );
  1309. BAIL_ON_FAILURE(hr);
  1310. hr = MDBindingsToIBindings ( &m_mszSecureBindings, FALSE, m_pBindings );
  1311. BAIL_ON_FAILURE(hr);
  1312. // Extract the Administrator list:
  1313. if ( m_psaAdmins ) {
  1314. SafeArrayDestroy ( m_psaAdmins );
  1315. m_psaAdmins = NULL;
  1316. }
  1317. if ( pSD ) {
  1318. hr = AclToAdministrators ( m_strServer, pSD, &m_psaAdmins );
  1319. BAIL_ON_FAILURE(hr);
  1320. }
  1321. // Validate the data received from the metabase:
  1322. _ASSERT ( ValidateStrings () );
  1323. _ASSERT ( ValidateProperties( ) );
  1324. if ( !ValidateProperties( ) ) {
  1325. CorrectProperties ();
  1326. }
  1327. Exit:
  1328. delete (char*) pSD;
  1329. TraceFunctLeave ();
  1330. return hr;
  1331. // CMetabaseKey automatically closes its handle
  1332. }
  1333. //$-------------------------------------------------------------------
  1334. //
  1335. // CSmtpAdminVirtualServer::SendPropertiesToMetabase
  1336. //
  1337. // Description:
  1338. //
  1339. // Saves each property to the metabase.
  1340. // This class's properties go into /LM/SmtpSvc/
  1341. //
  1342. // Parameters:
  1343. //
  1344. // fFailIfChanged - Return a failure code if the metabase
  1345. // has changed since last get.
  1346. // pMetabase - the metabase object.
  1347. //
  1348. // Returns:
  1349. //
  1350. //
  1351. //--------------------------------------------------------------------
  1352. HRESULT CSmtpAdminVirtualServer::SendPropertiesToMetabase (
  1353. BOOL fFailIfChanged,
  1354. IMSAdminBase * pMetabase
  1355. )
  1356. {
  1357. TraceFunctEnter ( "CSmtpAdminVirtualServer::SendPropertiesToMetabase" );
  1358. HRESULT hr = NOERROR;
  1359. CMetabaseKey metabase ( pMetabase );
  1360. BOOL fRet = TRUE;
  1361. TCHAR szInstancePath [ METADATA_MAX_NAME_LEN ];
  1362. //
  1363. // Set the admin acl:
  1364. //
  1365. PSECURITY_DESCRIPTOR pSD = NULL;
  1366. DWORD cbSD = 0;
  1367. // if ( m_bvChangedFields & CHNG_ADMINACL ) {
  1368. if ( m_psaAdmins ) {
  1369. hr = AdministratorsToAcl ( m_strServer, m_psaAdmins, &pSD, &cbSD );
  1370. BAIL_ON_FAILURE(hr);
  1371. }
  1372. // }
  1373. // Open metabase key
  1374. GetMDInstancePath ( szInstancePath, m_dwServiceInstance );
  1375. hr = metabase.Open ( szInstancePath, METADATA_PERMISSION_WRITE );
  1376. if ( FAILED(hr) ) {
  1377. ErrorTraceX ( (LPARAM) this, "Failed to open instance key, %x", GetLastError() );
  1378. // !!!magnush - Should we return a simple Service doesn't exist error code?
  1379. hr = SmtpCreateExceptionFromWin32Error ( GetLastError () );
  1380. goto Exit;
  1381. }
  1382. // Does the client care if the key has changed?
  1383. if ( fFailIfChanged ) {
  1384. // Did the key change?
  1385. if ( HasKeyChanged ( pMetabase, metabase.QueryHandle(), &m_ftLastChanged ) ) {
  1386. StateTrace ( (LPARAM) this, "Metabase has changed, not setting properties" );
  1387. // !!!magnush - Return the appropriate error code:
  1388. hr = E_FAIL;
  1389. goto Exit;
  1390. }
  1391. }
  1392. // Extract the bindings:
  1393. if( !(m_bvChangedFields & BitMask(ID_SERVER_BINDINGS)) )
  1394. {
  1395. hr = IBindingsToMDBindings ( m_pBindings, TRUE, &m_mszServerBindings );
  1396. BAIL_ON_FAILURE(hr);
  1397. m_bvChangedFields |= BitMask(ID_SERVER_BINDINGS);
  1398. }
  1399. if( !(m_bvChangedFields & BitMask(ID_SECURE_BINDINGS)) )
  1400. {
  1401. hr = IBindingsToMDBindings ( m_pBindings, FALSE, &m_mszSecureBindings );
  1402. BAIL_ON_FAILURE(hr);
  1403. m_bvChangedFields |= BitMask(ID_SECURE_BINDINGS);
  1404. }
  1405. //
  1406. // The general procedure here is to keep setting metabase properties
  1407. // as long as nothing has gone wrong. This is done by short-circuiting
  1408. // the statement by ANDing it with the status code. This makes the code
  1409. // much more concise.
  1410. //
  1411. fRet = TRUE;
  1412. // Overridable server properties:
  1413. hr = m_RoutingSource.Set(&metabase);
  1414. BAIL_ON_FAILURE(hr);
  1415. #if 0
  1416. if ( m_bvChangedFields & BitMask(ID_SSLPORT) )
  1417. {
  1418. fRet = StdPutMetabaseProp ( &metabase, MD_SECURE_PORT, m_lSSLPort ) && fRet;
  1419. }
  1420. #endif
  1421. if ( m_bvChangedFields & BitMask(ID_OUTBOUNDPORT) )
  1422. {
  1423. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_SMTP_PORT, m_lOutboundPort ) && fRet;
  1424. }
  1425. if ( m_bvChangedFields & BitMask(ID_HOP_COUNT) )
  1426. {
  1427. fRet = StdPutMetabaseProp ( &metabase, MD_HOP_COUNT, m_lHopCount ) && fRet;
  1428. }
  1429. if ( m_bvChangedFields & BitMask(ID_SMARTHOST) )
  1430. {
  1431. fRet = StdPutMetabaseProp ( &metabase, MD_SMARTHOST_NAME, m_strSmartHost ) && fRet;
  1432. }
  1433. if ( m_bvChangedFields & BitMask(ID_ENABLEDNSLOOKUP) )
  1434. {
  1435. fRet = StdPutMetabaseProp ( &metabase, MD_REVERSE_NAME_LOOKUP,m_fEnableDNSLookup ) && fRet;
  1436. }
  1437. if ( m_bvChangedFields & BitMask(ID_POSTMASTEREMAIL) )
  1438. {
  1439. fRet = StdPutMetabaseProp ( &metabase, MD_POSTMASTER_EMAIL, m_strPostmasterEmail ) && fRet;
  1440. }
  1441. if ( m_bvChangedFields & BitMask(ID_POSTMASTERNAME) )
  1442. {
  1443. fRet = StdPutMetabaseProp ( &metabase, MD_POSTMASTER_NAME, m_strPostmasterName ) && fRet;
  1444. }
  1445. if ( m_bvChangedFields & BitMask(ID_FQDN) )
  1446. {
  1447. if( m_strFQDN.m_str && m_strFQDN.m_str[0] )
  1448. {
  1449. fRet = StdPutMetabaseProp ( &metabase, MD_FQDN_VALUE, m_strFQDN ) && fRet;
  1450. }
  1451. else
  1452. {
  1453. if( !metabase.DeleteData( _T(""), MD_FQDN_VALUE, STRING_METADATA ) )
  1454. {
  1455. // not an error if data not exists on the instance level
  1456. fRet = fRet && ( GetLastError() == MD_ERROR_DATA_NOT_FOUND );
  1457. }
  1458. }
  1459. }
  1460. if ( m_bvChangedFields & BitMask(ID_DEFAULTDOMAIN) )
  1461. {
  1462. fRet = StdPutMetabaseProp ( &metabase, MD_DEFAULT_DOMAIN_VALUE, m_strDefaultDomain ) && fRet;
  1463. }
  1464. if ( m_bvChangedFields & BitMask(ID_DROPDIR) )
  1465. {
  1466. fRet = StdPutMetabaseProp ( &metabase, MD_MAIL_DROP_DIR, m_strDropDir ) && fRet;
  1467. }
  1468. if ( m_bvChangedFields & BitMask(ID_BADMAILDIR) )
  1469. {
  1470. fRet = StdPutMetabaseProp ( &metabase, MD_BAD_MAIL_DIR, m_strBadMailDir ) && fRet;
  1471. }
  1472. if ( m_bvChangedFields & BitMask(ID_PICKUPDIR) )
  1473. {
  1474. fRet = StdPutMetabaseProp ( &metabase, MD_MAIL_PICKUP_DIR, m_strPickupDir ) && fRet;
  1475. }
  1476. if ( m_bvChangedFields & BitMask(ID_QUEUEDIR) )
  1477. {
  1478. fRet = StdPutMetabaseProp ( &metabase, MD_MAIL_QUEUE_DIR, m_strQueueDir ) && fRet;
  1479. }
  1480. if ( m_bvChangedFields & BitMask(ID_MAXOUTCONNECTION) )
  1481. {
  1482. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_OUTBOUND_CONNECTION, m_lMaxOutConnection ) && fRet;
  1483. }
  1484. if ( m_bvChangedFields & BitMask(ID_OUTCONNECTIONTIMEOUT) )
  1485. {
  1486. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_TIMEOUT, m_lOutConnectionTimeout ) && fRet;
  1487. }
  1488. if ( m_bvChangedFields & BitMask(ID_MAXMESSAGESIZE) )
  1489. {
  1490. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_MSG_SIZE, m_lMaxMessageSize ) && fRet;
  1491. }
  1492. if ( m_bvChangedFields & BitMask(ID_MAXSESSIONSIZE) )
  1493. {
  1494. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_MSG_SIZE_B4_CLOSE, m_lMaxSessionSize ) && fRet;
  1495. }
  1496. if ( m_bvChangedFields & BitMask(ID_MAXMESSAGERECIPIENTS) )
  1497. {
  1498. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_RECIPIENTS, m_lMaxMessageRecipients ) && fRet;
  1499. }
  1500. if ( m_bvChangedFields & BitMask(ID_LOCALRETRYTIME) )
  1501. {
  1502. fRet = StdPutMetabaseProp ( &metabase, MD_LOCAL_RETRY_MINUTES, m_lLocalRetryTime) && fRet;
  1503. }
  1504. if ( m_bvChangedFields & BitMask(ID_REMOTERETRYTIME) )
  1505. {
  1506. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_RETRY_MINUTES, m_lRemoteRetryTime) && fRet;
  1507. }
  1508. if ( m_bvChangedFields & BitMask(ID_ETRNDAYS) )
  1509. {
  1510. fRet = StdPutMetabaseProp ( &metabase, MD_ETRN_DAYS, m_lETRNDays) && fRet;
  1511. }
  1512. if ( m_bvChangedFields & BitMask(ID_ROUTINGDLL) )
  1513. {
  1514. fRet = StdPutMetabaseProp ( &metabase, MD_ROUTING_DLL, m_strRoutingDLL) && fRet;
  1515. }
  1516. if ( m_bvChangedFields & BitMask(ID_ROUTINGSOURCES) )
  1517. {
  1518. fRet = StdPutMetabaseProp ( &metabase, MD_ROUTING_SOURCES, &m_mszRoutingSources) && fRet;
  1519. }
  1520. if ( m_bvChangedFields & BitMask(ID_LOCALDOMAINS) )
  1521. {
  1522. fRet = StdPutMetabaseProp ( &metabase, MD_LOCAL_DOMAINS, &m_mszLocalDomains) && fRet;
  1523. }
  1524. if ( m_bvChangedFields & BitMask(ID_DOMAINROUTING) )
  1525. {
  1526. fRet = StdPutMetabaseProp ( &metabase, MD_DOMAIN_ROUTING, &m_mszDomainRouting) && fRet;
  1527. }
  1528. if ( m_bvChangedFields & BitMask(ID_LOCALRETRIES) )
  1529. {
  1530. fRet = StdPutMetabaseProp ( &metabase, MD_LOCAL_RETRY_ATTEMPTS, m_lLocalRetries) && fRet;
  1531. }
  1532. if ( m_bvChangedFields & BitMask(ID_REMOTERETRIES) )
  1533. {
  1534. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_RETRY_ATTEMPTS, m_lRemoteRetries) && fRet;
  1535. }
  1536. if ( m_bvChangedFields & BitMask(ID_MASQUERADE) )
  1537. {
  1538. fRet = StdPutMetabaseProp ( &metabase, MD_MASQUERADE_NAME, m_strMasqueradeDomain) && fRet;
  1539. }
  1540. if ( m_bvChangedFields & BitMask(ID_SENDNDRTO) )
  1541. {
  1542. fRet = StdPutMetabaseProp ( &metabase, MD_SEND_NDR_TO, m_strNdrAddr) && fRet;
  1543. }
  1544. if ( m_bvChangedFields & BitMask(ID_SENDBADTO) )
  1545. {
  1546. fRet = StdPutMetabaseProp ( &metabase, MD_SEND_BAD_TO, m_strBadAddr) && fRet;
  1547. }
  1548. if ( m_bvChangedFields & BitMask(ID_REMOTE_SECURE_PORT) )
  1549. {
  1550. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_SECURE_PORT, m_lRemoteSecurePort) && fRet;
  1551. }
  1552. if ( m_bvChangedFields & BitMask(ID_SHOULD_DELIVER) )
  1553. {
  1554. fRet = StdPutMetabaseProp ( &metabase, MD_SHOULD_DELIVER, m_fShouldDeliver) && fRet;
  1555. }
  1556. if ( m_bvChangedFields & BitMask(ID_ALWAYS_USE_SSL) )
  1557. {
  1558. fRet = StdPutMetabaseProp ( &metabase, MD_ALWAYS_USE_SSL, m_fAlwaysUseSsl) && fRet;
  1559. }
  1560. if ( m_bvChangedFields & BitMask(ID_LIMIT_REMOTE_CONNECTIONS) )
  1561. {
  1562. fRet = StdPutMetabaseProp ( &metabase, MD_LIMIT_REMOTE_CONNECTIONS, m_fLimitRemoteConnections) && fRet;
  1563. }
  1564. if ( m_bvChangedFields & BitMask(ID_MAX_OUT_CONN_PER_DOMAIN) )
  1565. {
  1566. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_OUT_CONN_PER_DOMAIN, m_lMaxOutConnPerDomain) && fRet;
  1567. }
  1568. if ( m_bvChangedFields & BitMask(ID_SMART_HOST_TYPE) )
  1569. {
  1570. fRet = StdPutMetabaseProp ( &metabase, MD_SMARTHOST_TYPE, m_lSmartHostType) && fRet;
  1571. }
  1572. if ( m_bvChangedFields & BitMask(ID_BATCH_MSG_LIMIT) )
  1573. {
  1574. fRet = StdPutMetabaseProp ( &metabase, MD_BATCH_MSG_LIMIT, m_lBatchMsgLimit) && fRet;
  1575. }
  1576. if ( m_bvChangedFields & BitMask(ID_DO_MASQUERADE) )
  1577. {
  1578. fRet = StdPutMetabaseProp ( &metabase, MD_DO_MASQUERADE, m_fDoMasquerade) && fRet;
  1579. }
  1580. // outbound security
  1581. if ( m_bvChangedFields & BitMask(ID_ROUTE_ACTION) )
  1582. {
  1583. fRet = StdPutMetabaseProp ( &metabase, MD_ROUTE_ACTION, m_lRouteAction) && fRet;
  1584. }
  1585. if ( m_bvChangedFields & BitMask(ID_ROUTE_USER_NAME) )
  1586. {
  1587. fRet = StdPutMetabaseProp ( &metabase, MD_ROUTE_USER_NAME, m_strRouteUserName) && fRet;
  1588. }
  1589. if ( m_bvChangedFields & BitMask(ID_ROUTE_PASSWORD) )
  1590. {
  1591. fRet = StdPutMetabaseProp ( &metabase, MD_ROUTE_PASSWORD, m_strRoutePassword) && fRet;
  1592. }
  1593. //
  1594. // IIS common properties
  1595. //
  1596. if ( m_bvChangedFields & BitMask(ID_SERVER_BINDINGS) )
  1597. {
  1598. fRet = StdPutMetabaseProp ( &metabase, MD_SERVER_BINDINGS, &m_mszServerBindings ) && fRet;
  1599. }
  1600. if ( m_bvChangedFields & BitMask(ID_SECURE_BINDINGS) )
  1601. {
  1602. fRet = StdPutMetabaseProp ( &metabase, MD_SECURE_BINDINGS, &m_mszSecureBindings ) && fRet;
  1603. }
  1604. if ( m_bvChangedFields & BitMask(ID_MAXINCONNECTION) )
  1605. {
  1606. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_CONNECTIONS, m_lMaxInConnection ) && fRet;
  1607. }
  1608. if ( m_bvChangedFields & BitMask(ID_INCONNECTIONTIMEOUT) )
  1609. {
  1610. fRet = StdPutMetabaseProp ( &metabase, MD_CONNECTION_TIMEOUT,m_lInConnectionTimeout ) && fRet;
  1611. }
  1612. if (m_bvChangedFields & BitMask(ID_AUTH_PACKAGES))
  1613. {
  1614. fRet = fRet && StdPutMetabaseProp(&metabase, MD_NTAUTHENTICATION_PROVIDERS, m_strAuthPackages);
  1615. }
  1616. if (m_bvChangedFields & BitMask(ID_CLEARTEXT_AUTH_PACKAGE))
  1617. {
  1618. fRet = fRet && StdPutMetabaseProp(&metabase, MD_SMTP_CLEARTEXT_AUTH_PROVIDER, m_strClearTextAuthPackage);
  1619. }
  1620. if (m_bvChangedFields & BitMask(ID_AUTH_METHOD))
  1621. {
  1622. fRet = fRet && StdPutMetabaseProp(&metabase, MD_AUTHORIZATION, m_lAuthMethod);
  1623. }
  1624. if (m_bvChangedFields & BitMask(ID_DEFAULT_LOGON_DOMAIN))
  1625. {
  1626. fRet = fRet && StdPutMetabaseProp(&metabase, MD_SASL_LOGON_DOMAIN, m_strDefaultLogonDomain);
  1627. }
  1628. if ( m_bvChangedFields & BitMask(ID_LOGFILEDIRECTORY) )
  1629. {
  1630. fRet = StdPutMetabaseProp ( &metabase, MD_LOGFILE_DIRECTORY, m_strLogFileDirectory) && fRet;
  1631. }
  1632. if ( m_bvChangedFields & BitMask(ID_LOGFILEPERIOD) )
  1633. {
  1634. fRet = StdPutMetabaseProp ( &metabase, MD_LOGFILE_PERIOD, m_lLogFilePeriod) && fRet;
  1635. }
  1636. if ( m_bvChangedFields & BitMask(ID_LOGFILETRUNCATESIZE) )
  1637. {
  1638. fRet = StdPutMetabaseProp ( &metabase, MD_LOGFILE_TRUNCATE_SIZE, m_lLogFileTruncateSize) && fRet;
  1639. }
  1640. // if ( m_bvChangedFields & BitMask(ID_LOGMETHOD) )
  1641. // {
  1642. // fRet = StdPutMetabaseProp ( &metabase, MD_LOG_TYPE, m_lLogMethod) && fRet;
  1643. // }
  1644. if ( m_bvChangedFields & BitMask(ID_LOGTYPE) )
  1645. {
  1646. fRet = StdPutMetabaseProp ( &metabase, MD_LOG_TYPE, m_lLogType) && fRet;
  1647. }
  1648. if ( m_bvChangedFields & BitMask(ID_AUTOSTART) ) {
  1649. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_SERVER_AUTOSTART, m_fAutoStart );
  1650. }
  1651. if ( m_bvChangedFields & BitMask(ID_COMMENT) ) {
  1652. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_SERVER_COMMENT, m_strComment );
  1653. }
  1654. #if 0
  1655. // if ( m_bvChangedFields & CHNG_ADMINACL ) {
  1656. if ( pSD ) {
  1657. hr = metabase.SetData ( _T(""), MD_ADMIN_ACL, IIS_MD_UT_SERVER, BINARY_METADATA, pSD, cbSD, METADATA_INHERIT | METADATA_REFERENCE);
  1658. BAIL_ON_FAILURE(hr);
  1659. }
  1660. else {
  1661. pMetabase->DeleteData ( metabase.QueryHandle(), _T(""), MD_ADMIN_ACL, BINARY_METADATA );
  1662. }
  1663. // }
  1664. #endif
  1665. // if ( m_bvChangedFields & CHNG_IPACCESS ) {
  1666. hr = m_pPrivateIpAccess->SendToMetabase ( &metabase );
  1667. BAIL_ON_FAILURE(hr);
  1668. // }
  1669. // Save the data to the metabase:
  1670. // hr = metabase.Close();
  1671. // BAIL_ON_FAILURE(hr);
  1672. metabase.Close();
  1673. hr = pMetabase->SaveData ();
  1674. if ( FAILED (hr) ) {
  1675. ErrorTraceX ( (LPARAM) this, "Failed SaveData call (%x)", hr );
  1676. }
  1677. // Save the last changed time for this key:
  1678. m_ftLastChanged.dwHighDateTime = 0;
  1679. m_ftLastChanged.dwLowDateTime = 0;
  1680. hr = pMetabase->GetLastChangeTime ( metabase.QueryHandle(), _T(""), &m_ftLastChanged, FALSE );
  1681. if ( FAILED (hr) ) {
  1682. ErrorTraceX ( (LPARAM) this, "Failed to get last change time: %x", hr );
  1683. // Ignore this error.
  1684. hr = NOERROR;
  1685. }
  1686. Exit:
  1687. delete (char*) pSD;
  1688. if( SUCCEEDED(hr) && !fRet )
  1689. {
  1690. hr = SmtpCreateExceptionFromWin32Error ( GetLastError () );
  1691. }
  1692. TraceFunctLeave ();
  1693. return hr;
  1694. // CMetabaseKey automatically closes its handle
  1695. }
  1696. //$-------------------------------------------------------------------
  1697. //
  1698. // CSmtpAdminVirtualServer::ValidateStrings
  1699. //
  1700. // Description:
  1701. //
  1702. // Checks to make sure each string property is non-null.
  1703. //
  1704. // Returns:
  1705. //
  1706. // FALSE if any string property is NULL.
  1707. //
  1708. //--------------------------------------------------------------------
  1709. BOOL CSmtpAdminVirtualServer::ValidateStrings ( ) const
  1710. {
  1711. TraceFunctEnter ( "CSmtpAdminVirtualServer::ValidateStrings" );
  1712. // Check all property strings:
  1713. // If any string is NULL, return FALSE:
  1714. if (
  1715. !m_strSmartHost ||
  1716. !m_strPostmasterEmail ||
  1717. !m_strPostmasterName ||
  1718. !m_strDefaultDomain ||
  1719. !m_strBadMailDir ||
  1720. !m_strPickupDir ||
  1721. !m_strQueueDir ||
  1722. !m_strRoutingDLL ||
  1723. !m_strLogFileDirectory
  1724. ) {
  1725. ErrorTrace ( (LPARAM) this, "String validation failed" );
  1726. TraceFunctLeave ();
  1727. return FALSE;
  1728. }
  1729. _ASSERT ( IS_VALID_STRING ( m_strSmartHost ) );
  1730. _ASSERT ( IS_VALID_STRING ( m_strPostmasterEmail ) );
  1731. _ASSERT ( IS_VALID_STRING ( m_strPostmasterName ) );
  1732. _ASSERT ( IS_VALID_STRING ( m_strDefaultDomain ) );
  1733. _ASSERT ( IS_VALID_STRING ( m_strBadMailDir ) );
  1734. _ASSERT ( IS_VALID_STRING ( m_strPickupDir ) );
  1735. _ASSERT ( IS_VALID_STRING ( m_strQueueDir ) );
  1736. _ASSERT ( IS_VALID_STRING ( m_strRoutingDLL ) );
  1737. _ASSERT ( IS_VALID_STRING ( m_strLogFileDirectory ) );
  1738. TraceFunctLeave ();
  1739. return TRUE;
  1740. }
  1741. //$-------------------------------------------------------------------
  1742. //
  1743. // CSmtpAdminVirtualServer::ValidateProperties
  1744. //
  1745. // Description:
  1746. //
  1747. // Checks to make sure all parameters are valid.
  1748. //
  1749. // Parameters:
  1750. //
  1751. //
  1752. // Returns:
  1753. //
  1754. //
  1755. //--------------------------------------------------------------------
  1756. BOOL CSmtpAdminVirtualServer::ValidateProperties ( ) const
  1757. {
  1758. BOOL fRet = TRUE;
  1759. _ASSERT ( ValidateStrings () );
  1760. /*
  1761. fRet = fRet && PV_MinMax ( m_lPort, MIN_PORT, MAX_PORT );
  1762. fRet = fRet && PV_MinMax ( m_lSSLPort, MIN_SSLPORT, MAX_SSLPORT );
  1763. fRet = fRet && PV_MinMax ( m_lOutboundPort, MIN_OUTBOND_PORT, MAX_OUTBOND_PORT );
  1764. fRet = fRet && PV_MinMax ( m_lMaxInConnection, MIN_MAX_IN_CONNECTION, MAX_MAX_IN_CONNECTION );
  1765. fRet = fRet && PV_MinMax ( m_lMaxOutConnection, MIN_MAX_OUT_CONNECTION, MAX_MAX_OUT_CONNECTION );
  1766. fRet = fRet && PV_MinMax ( m_lInConnectionTimeout, MIN_IN_CONNECTION_TIMEOUT, MAX_IN_CONNECTION_TIMEOUT );
  1767. fRet = fRet && PV_MinMax ( m_lOutConnectionTimeout, MIN_OUT_CONNECTION_TIMEOUT, MAX_OUT_CONNECTION_TIMEOUT );
  1768. fRet = fRet && PV_MinMax ( m_lMaxMessageSize, MIN_MAX_MESSAGE_SIZE, MAX_MAX_MESSAGE_SIZE );
  1769. fRet = fRet && PV_MinMax ( m_lMaxSessionSize, MIN_MAX_SESSION_SIZE, MAX_MAX_SESSION_SIZE );
  1770. fRet = fRet && PV_MinMax ( m_lMaxMessageRecipients, MIN_MAX_MESSAGE_RECIPIENTS, MAX_MAX_MESSAGE_RECIPIENTS );
  1771. fRet = fRet && PV_MinMax ( m_lLocalRetries, MIN_LOCAL_RETRIES, MAX_LOCAL_RETRIES );
  1772. fRet = fRet && PV_MinMax ( m_lLocalRetryTime, MIN_LOCAL_RETRY_TIME, MAX_LOCAL_RETRY_TIME );
  1773. fRet = fRet && PV_MinMax ( m_lRemoteRetries, MIN_REMOTE_RETRIES, MAX_REMOTE_RETRIES );
  1774. fRet = fRet && PV_MinMax ( m_lRemoteRetryTime, MIN_REMOTE_RETRY_TIME, MAX_REMOTE_RETRY_TIME );
  1775. fRet = fRet && PV_MinMax ( m_lETRNDays, MIN_ETRN_DAYS, MAX_ETRN_DAYS );
  1776. // fRet = fRet && PV_MinMax ( m_lRTType, MIN_RTTYPE, MAX_RTTYPE );
  1777. fRet = fRet && PV_MinMax ( m_lLogFilePeriod, MIN_LOGFILE_PERIOD, MAX_LOGFILE_PERIOD );
  1778. fRet = fRet && PV_MinMax ( m_lLogFileTruncateSize, MIN_LOGFILE_TRUNCATE_SIZE, MAX_LOGFILE_TRUNCATE_SIZE );
  1779. fRet = fRet && PV_MinMax ( m_lLogMethod, MIN_LOG_METHOD, MAX_LOG_METHOD );
  1780. fRet = fRet && PV_MinMax ( m_lLogType, MIN_LOG_TYPE, MAX_LOG_TYPE );
  1781. fRet = fRet && PV_Boolean ( m_fEnableDNSLookup );
  1782. fRet = fRet && PV_Boolean ( m_fSendDNRToPostmaster );
  1783. fRet = fRet && PV_Boolean ( m_fSendBadmailToPostmaster );
  1784. fRet = fRet && PV_Boolean ( m_fAutoStart );
  1785. */
  1786. return fRet;
  1787. }
  1788. void CSmtpAdminVirtualServer::CorrectProperties ( )
  1789. {
  1790. /*
  1791. if ( m_strServer && !PV_MaxChars ( m_strServer, MAXLEN_SERVER ) ) {
  1792. m_strServer[ MAXLEN_SERVER - 1 ] = NULL;
  1793. }
  1794. if ( !PV_MinMax ( m_dwArticleTimeLimit, MIN_ARTICLETIMELIMIT, MAX_ARTICLETIMELIMIT ) ) {
  1795. m_dwArticleTimeLimit = DEFAULT_ARTICLETIMELIMIT;
  1796. }
  1797. if ( !PV_MinMax ( m_dwHistoryExpiration, MIN_HISTORYEXPIRATION, MAX_HISTORYEXPIRATION ) ) {
  1798. m_dwHistoryExpiration = DEFAULT_HISTORYEXPIRATION;
  1799. }
  1800. if ( !PV_Boolean ( m_fHonorClientMsgIDs ) ) {
  1801. m_fHonorClientMsgIDs = !!m_fHonorClientMsgIDs;
  1802. }
  1803. if ( !PV_MaxChars ( m_strSmtpServer, MAXLEN_SMTPSERVER ) ) {
  1804. m_strSmtpServer[ MAXLEN_SMTPSERVER - 1 ] = NULL;
  1805. }
  1806. if ( !PV_Boolean ( m_fAllowClientPosts ) ) {
  1807. m_fAllowClientPosts = !!m_fAllowClientPosts;
  1808. }
  1809. if ( !PV_Boolean ( m_fAllowFeedPosts ) ) {
  1810. m_fAllowFeedPosts = !!m_fAllowFeedPosts;
  1811. }
  1812. if ( !PV_Boolean ( m_fAllowControlMsgs ) ) {
  1813. m_fAllowControlMsgs = !!m_fAllowControlMsgs;
  1814. }
  1815. if ( !PV_MaxChars ( m_strDefaultModeratorDomain, MAXLEN_DEFAULTMODERATORDOMAIN ) ) {
  1816. m_strDefaultModeratorDomain[ MAXLEN_DEFAULTMODERATORDOMAIN - 1] = NULL;
  1817. }
  1818. if ( !PV_MinMax ( m_dwCommandLogMask, MIN_COMMANDLOGMASK, MAX_COMMANDLOGMASK ) ) {
  1819. m_dwCommandLogMask = DEFAULT_COMMANDLOGMASK;
  1820. }
  1821. if ( !PV_Boolean ( m_fDisableNewnews ) ) {
  1822. m_fDisableNewnews = !!m_fDisableNewnews;
  1823. }
  1824. if ( !PV_MinMax ( m_dwExpireRunFrequency, MIN_EXPIRERUNFREQUENCY, MAX_EXPIRERUNFREQUENCY ) ) {
  1825. m_dwExpireRunFrequency = DEFAULT_EXPIRERUNFREQUENCY;
  1826. }
  1827. if ( !PV_MinMax ( m_dwShutdownLatency, MIN_SHUTDOWNLATENCY, MAX_SHUTDOWNLATENCY ) ) {
  1828. m_dwShutdownLatency = DEFAULT_SHUTDOWNLATENCY;
  1829. }
  1830. */
  1831. _ASSERT ( ValidateProperties ( ) );
  1832. }
  1833. HRESULT AclToAdministrators ( LPCTSTR strServer, PSECURITY_DESCRIPTOR pSDRelative, SAFEARRAY ** ppsaAdmins )
  1834. {
  1835. HRESULT hr = NOERROR;
  1836. SAFEARRAY * psaResult = NULL;
  1837. SAFEARRAYBOUND rgsaBound[1];
  1838. DWORD cbAcl;
  1839. long cAdmins;
  1840. long i;
  1841. PSECURITY_DESCRIPTOR pSD = NULL;
  1842. PACL pAcl;
  1843. BOOL fDaclPresent;
  1844. BOOL fDaclDef;
  1845. pSD = (PSECURITY_DESCRIPTOR)pSDRelative;
  1846. if (pSD == NULL)
  1847. {
  1848. //
  1849. // Empty...
  1850. //
  1851. return ERROR_SUCCESS;
  1852. }
  1853. if (!IsValidSecurityDescriptor(pSD))
  1854. {
  1855. return GetLastError();
  1856. }
  1857. _VERIFY(GetSecurityDescriptorDacl(pSD, &fDaclPresent, &pAcl, &fDaclDef));
  1858. if (!fDaclPresent || pAcl == NULL)
  1859. {
  1860. return ERROR_SUCCESS;
  1861. }
  1862. if (!IsValidAcl(pAcl))
  1863. {
  1864. return GetLastError();
  1865. }
  1866. cAdmins = pAcl->AceCount;
  1867. cbAcl = pAcl->AclSize;
  1868. rgsaBound[0].lLbound = 0;
  1869. rgsaBound[0].cElements = cAdmins;
  1870. psaResult = SafeArrayCreate ( VT_BSTR, 1, rgsaBound );
  1871. if ( !psaResult ) {
  1872. BAIL_WITH_FAILURE ( hr, E_OUTOFMEMORY );
  1873. }
  1874. for ( i = 0; i < cAdmins; i++ ) {
  1875. PVOID pAce;
  1876. PACE_HEADER pAceHeader;
  1877. PSID pSID;
  1878. if ( GetAce(pAcl, i, &pAce) ) {
  1879. pAceHeader = (PACE_HEADER)pAce;
  1880. if ( pAceHeader->AceType == ACCESS_ALLOWED_ACE_TYPE ) {
  1881. CComBSTR str;
  1882. pSID = (PSID)&((PACCESS_ALLOWED_ACE)pAce)->SidStart;
  1883. hr = SidToString ( pSID, &str );
  1884. BAIL_ON_FAILURE(hr);
  1885. hr = SafeArrayPutElement ( psaResult, &i, (PVOID) str );
  1886. BAIL_ON_FAILURE(hr);
  1887. }
  1888. }
  1889. }
  1890. if ( *ppsaAdmins ) {
  1891. SafeArrayDestroy ( *ppsaAdmins );
  1892. }
  1893. *ppsaAdmins = psaResult;
  1894. Exit:
  1895. return hr;
  1896. }
  1897. PSID
  1898. GetOwnerSID()
  1899. /*++
  1900. Routine Description:
  1901. Arguments:
  1902. Return Value:
  1903. Owner sid
  1904. --*/
  1905. {
  1906. PSID pSID = NULL;
  1907. SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
  1908. if (!AllocateAndInitializeSid(
  1909. &NtAuthority,
  1910. 2,
  1911. SECURITY_BUILTIN_DOMAIN_RID,
  1912. DOMAIN_ALIAS_RID_ADMINS,
  1913. 0, 0, 0, 0, 0, 0,
  1914. &pSID))
  1915. {
  1916. _ASSERT( 0 );
  1917. //TRACEEOLID("Unable to get primary SID " << ::GetLastError());
  1918. }
  1919. return pSID;
  1920. }
  1921. HRESULT AdministratorsToAcl (
  1922. LPCTSTR strServer,
  1923. SAFEARRAY * psaAdmins,
  1924. PSECURITY_DESCRIPTOR* ppSD,
  1925. DWORD * pcbSD
  1926. )
  1927. {
  1928. HRESULT hr = NOERROR;
  1929. long lBound;
  1930. long uBound;
  1931. long i;
  1932. BOOL fRet;
  1933. DWORD cbAcl;
  1934. PACL pAclResult = NULL;
  1935. PSID pSID;
  1936. *ppSD = NULL;
  1937. *pcbSD = 0;
  1938. if ( psaAdmins == NULL ) {
  1939. lBound = 0;
  1940. uBound = -1;
  1941. }
  1942. else {
  1943. SafeArrayGetLBound ( psaAdmins, 1, &lBound );
  1944. SafeArrayGetUBound ( psaAdmins, 1, &uBound );
  1945. }
  1946. // Do we have an array of Domain\Usernames?
  1947. if ( lBound > uBound ) {
  1948. // Nothing in the array, so the ACL is NULL.
  1949. goto Exit;
  1950. }
  1951. //
  1952. // Calculate ACL size:
  1953. //
  1954. cbAcl = sizeof (ACL);
  1955. for ( i = lBound; i <= uBound ; i++ ) {
  1956. CComBSTR str;
  1957. pSID = NULL;
  1958. SafeArrayGetElement ( psaAdmins, &i, &str );
  1959. hr = StringToSid ( strServer, str, &pSID );
  1960. if ( SUCCEEDED(hr) && pSID) {
  1961. cbAcl += GetLengthSid ( pSID );
  1962. cbAcl += sizeof ( ACCESS_ALLOWED_ACE );
  1963. cbAcl -= sizeof (DWORD);
  1964. delete pSID;
  1965. }
  1966. hr = NOERROR;
  1967. }
  1968. pAclResult = (PACL) new char [ cbAcl ];
  1969. if ( !pAclResult ) {
  1970. BAIL_WITH_FAILURE(hr, E_OUTOFMEMORY);
  1971. }
  1972. fRet = InitializeAcl ( pAclResult, cbAcl, ACL_REVISION );
  1973. _ASSERT ( fRet );
  1974. if ( !fRet ) {
  1975. BAIL_WITH_FAILURE(hr, RETURNCODETOHRESULT(GetLastError() ) );
  1976. }
  1977. //
  1978. // Create ACL:
  1979. //
  1980. for ( i = lBound; i <= uBound; i++ ) {
  1981. CComBSTR str;
  1982. PSID pSID;
  1983. pSID = NULL;
  1984. SafeArrayGetElement ( psaAdmins, &i, &str );
  1985. hr = StringToSid ( strServer, str, &pSID );
  1986. if ( SUCCEEDED(hr) ) {
  1987. fRet = AddAccessAllowedAce (
  1988. pAclResult,
  1989. ACL_REVISION,
  1990. FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE,
  1991. pSID
  1992. );
  1993. delete pSID;
  1994. if ( !fRet ) {
  1995. BAIL_WITH_FAILURE(hr, RETURNCODETOHRESULT(GetLastError() ) );
  1996. }
  1997. }
  1998. hr = NOERROR;
  1999. }
  2000. //
  2001. // Build the security descriptor
  2002. //
  2003. PSECURITY_DESCRIPTOR pSD;
  2004. pSD = new char[SECURITY_DESCRIPTOR_MIN_LENGTH];
  2005. if( NULL == pSD )
  2006. {
  2007. hr = E_OUTOFMEMORY;
  2008. goto Exit;
  2009. }
  2010. _VERIFY(InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION));
  2011. _VERIFY(SetSecurityDescriptorDacl(pSD, TRUE, pAclResult, FALSE));
  2012. //
  2013. // Set owner and primary group
  2014. //
  2015. pSID = GetOwnerSID();
  2016. _ASSERT(pSID);
  2017. _VERIFY(SetSecurityDescriptorOwner(pSD, pSID, TRUE));
  2018. _VERIFY(SetSecurityDescriptorGroup(pSD, pSID, TRUE));
  2019. //
  2020. // Convert to self-relative
  2021. //
  2022. PSECURITY_DESCRIPTOR pSDSelfRelative;
  2023. pSDSelfRelative = NULL;
  2024. DWORD dwSize;
  2025. dwSize = 0L;
  2026. MakeSelfRelativeSD(pSD, pSDSelfRelative, &dwSize);
  2027. pSDSelfRelative = new char[dwSize];
  2028. if( NULL == pSDSelfRelative )
  2029. {
  2030. hr = E_OUTOFMEMORY;
  2031. goto Exit;
  2032. }
  2033. MakeSelfRelativeSD(pSD, pSDSelfRelative, &dwSize);
  2034. //
  2035. // Clean up
  2036. //
  2037. delete (char*)pSD;
  2038. FreeSid( pSID );
  2039. _ASSERT ( SUCCEEDED(hr) );
  2040. *ppSD = pSDSelfRelative;
  2041. *pcbSD = dwSize;
  2042. Exit:
  2043. if ( FAILED(hr) ) {
  2044. delete pAclResult;
  2045. }
  2046. return hr;
  2047. }
  2048. HRESULT SidToString ( PSID pSID, BSTR * pStr )
  2049. {
  2050. HRESULT hr = NOERROR;
  2051. BOOL fLookup;
  2052. SID_NAME_USE SidToNameUse;
  2053. WCHAR wszUsername [ PATHLEN ];
  2054. DWORD cbUsername = sizeof ( wszUsername );
  2055. WCHAR wszDomain [ PATHLEN ];
  2056. DWORD cbDomain = sizeof ( wszDomain );
  2057. WCHAR wszResult [ 2 * PATHLEN + 2 ];
  2058. fLookup = LookupAccountSid (
  2059. // wszSearchDomain,
  2060. NULL,
  2061. pSID,
  2062. wszUsername,
  2063. &cbUsername,
  2064. wszDomain,
  2065. &cbDomain,
  2066. &SidToNameUse
  2067. );
  2068. if ( !fLookup ) {
  2069. BAIL_WITH_FAILURE(hr, RETURNCODETOHRESULT (GetLastError ()) );
  2070. }
  2071. wsprintf ( wszResult, _T("%s\\%s"), wszDomain, wszUsername );
  2072. *pStr = ::SysAllocString ( wszResult );
  2073. Exit:
  2074. if ( *pStr ) {
  2075. return NOERROR;
  2076. }
  2077. else {
  2078. return E_OUTOFMEMORY;
  2079. }
  2080. }
  2081. //-------------------------------------------------------------------------
  2082. // Description:
  2083. // Returns the SID for a an account (given as a COMPUTER/USER)
  2084. // Parameters:
  2085. // strSystemName - Name of "computer" on which account is
  2086. // str - Name of user account to look up
  2087. // ppSID - Out parameter; This function allocates a SID for the
  2088. // accountand returns a pointer to it .
  2089. // Returns:
  2090. // S_OK on success. Caller frees *ppSID using delete.
  2091. // Error HRESULT otherwise. *ppSID will be NULL.
  2092. //-------------------------------------------------------------------------
  2093. HRESULT StringToSid ( LPCWSTR strSystemName, LPWSTR str, PSID * ppSID )
  2094. {
  2095. HRESULT hr = NOERROR;
  2096. BOOL fLookup;
  2097. WCHAR wszRefDomain[PATHLEN];
  2098. DWORD cbRefDomain = sizeof ( wszRefDomain );
  2099. DWORD cbSid = 0;
  2100. SID_NAME_USE SidNameUse;
  2101. *ppSID = NULL;
  2102. if ( str[0] == '\\' ) {
  2103. //
  2104. // Skip the initial \, this is for BUILTIN usernames:
  2105. //
  2106. str++;
  2107. }
  2108. _ASSERT ( str[0] != '\\' );
  2109. fLookup = LookupAccountName (
  2110. strSystemName,
  2111. str,
  2112. *ppSID,
  2113. &cbSid,
  2114. wszRefDomain,
  2115. &cbRefDomain,
  2116. &SidNameUse
  2117. );
  2118. // First lookup will fail, but the size will be right:
  2119. if ( GetLastError() != ERROR_INSUFFICIENT_BUFFER ) {
  2120. DWORD dw;
  2121. dw = GetLastError ();
  2122. BAIL_WITH_FAILURE(hr, RETURNCODETOHRESULT ( GetLastError () ) );
  2123. }
  2124. *ppSID = (LPVOID) new char [ cbSid ];
  2125. if ( !*ppSID ) {
  2126. BAIL_WITH_FAILURE(hr, E_OUTOFMEMORY);
  2127. }
  2128. fLookup = LookupAccountName (
  2129. strSystemName,
  2130. str,
  2131. *ppSID,
  2132. &cbSid,
  2133. wszRefDomain,
  2134. &cbRefDomain,
  2135. &SidNameUse
  2136. );
  2137. if ( !fLookup ) {
  2138. DWORD dw;
  2139. dw = GetLastError ();
  2140. BAIL_WITH_FAILURE(hr, RETURNCODETOHRESULT ( GetLastError () ) );
  2141. }
  2142. Exit:
  2143. if(FAILED(hr) && *ppSID != NULL) {
  2144. delete (*ppSID);
  2145. *ppSID = NULL;
  2146. }
  2147. return hr;
  2148. }