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.

1858 lines
61 KiB

  1. // server.cpp : Implementation of CSmtpAdminService
  2. #include "stdafx.h"
  3. #include "IADM.h"
  4. #include "imd.h"
  5. #include "smtpadm.h"
  6. #include "ipaccess.h"
  7. #include "oleutil.h"
  8. #include "metautil.h"
  9. #include "smtpcmn.h"
  10. #include "service.h"
  11. #include "virsvr.h"
  12. #include "smtpprop.h"
  13. // Must define THIS_FILE_* macros to use SmtpCreateException()
  14. #define THIS_FILE_HELP_CONTEXT 0
  15. #define THIS_FILE_PROG_ID _T("Smtpadm.Service.1")
  16. #define THIS_FILE_IID IID_ISmtpAdminService
  17. /////////////////////////////////////////////////////////////////////////////
  18. //
  19. STDMETHODIMP CSmtpAdminService::InterfaceSupportsErrorInfo(REFIID riid)
  20. {
  21. static const IID* arr[] =
  22. {
  23. &IID_ISmtpAdminService,
  24. };
  25. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  26. {
  27. if (InlineIsEqualGUID(*arr[i],riid))
  28. return S_OK;
  29. }
  30. return S_FALSE;
  31. }
  32. CSmtpAdminService::CSmtpAdminService () :
  33. m_lPort ( 25 ),
  34. m_lLogMethod ( 0 )
  35. // CComBSTR's are initialized to NULL by default.
  36. {
  37. m_ftLastChanged.dwHighDateTime = 0;
  38. m_ftLastChanged.dwLowDateTime = 0;
  39. m_psaAdmins = NULL;
  40. InitAsyncTrace ( );
  41. }
  42. CSmtpAdminService::~CSmtpAdminService ()
  43. {
  44. // All CComBSTR's are freed automatically.
  45. if ( m_psaAdmins ) {
  46. SafeArrayDestroy ( m_psaAdmins );
  47. }
  48. TermAsyncTrace ( );
  49. }
  50. // Which Server to configure:
  51. STDMETHODIMP CSmtpAdminService::get_Server ( BSTR * pstrServer )
  52. {
  53. return StdPropertyGet ( m_strServer, pstrServer );
  54. }
  55. STDMETHODIMP CSmtpAdminService::put_Server ( BSTR strServer )
  56. {
  57. // If the server name changes, that means the client will have to
  58. // call Get again:
  59. // I assume this here:
  60. _ASSERT ( sizeof (DWORD) == sizeof (int) );
  61. return StdPropertyPutServerName ( &m_strServer, strServer, (DWORD *) &m_fGotProperties, 1 );
  62. }
  63. // Server Properties:
  64. STDMETHODIMP CSmtpAdminService::get_ServerBindings( SAFEARRAY ** ppsastrServerBindings )
  65. {
  66. return StdPropertyGet ( &m_mszServerBindings, ppsastrServerBindings );
  67. }
  68. STDMETHODIMP CSmtpAdminService::put_ServerBindings( SAFEARRAY * pstrServerBindings )
  69. {
  70. return StdPropertyPut ( &m_mszServerBindings, pstrServerBindings, &m_bvChangedFields, BitMask(ID_SERVER_BINDINGS));
  71. }
  72. STDMETHODIMP CSmtpAdminService::get_ServerBindingsVariant( SAFEARRAY ** ppsavarServerBindings )
  73. {
  74. HRESULT hr;
  75. SAFEARRAY * psastrServerBindings = NULL;
  76. hr = get_ServerBindings ( &psastrServerBindings );
  77. if ( FAILED(hr) ) {
  78. goto Exit;
  79. }
  80. hr = StringArrayToVariantArray ( psastrServerBindings, ppsavarServerBindings );
  81. Exit:
  82. if ( psastrServerBindings ) {
  83. SafeArrayDestroy ( psastrServerBindings );
  84. }
  85. return hr;
  86. }
  87. STDMETHODIMP CSmtpAdminService::put_ServerBindingsVariant( SAFEARRAY * psavarServerBindings )
  88. {
  89. HRESULT hr;
  90. SAFEARRAY * psastrServerBindings = NULL;
  91. hr = VariantArrayToStringArray ( psavarServerBindings, &psastrServerBindings );
  92. if ( FAILED(hr) ) {
  93. goto Exit;
  94. }
  95. hr = put_ServerBindings ( psastrServerBindings );
  96. Exit:
  97. if ( psastrServerBindings ) {
  98. SafeArrayDestroy ( psastrServerBindings );
  99. }
  100. return hr;
  101. }
  102. STDMETHODIMP CSmtpAdminService::get_SecureBindings( SAFEARRAY ** ppsastrSecureBindings )
  103. {
  104. return StdPropertyGet ( &m_mszSecureBindings, ppsastrSecureBindings );
  105. }
  106. STDMETHODIMP CSmtpAdminService::put_SecureBindings( SAFEARRAY * pstrSecureBindings )
  107. {
  108. return StdPropertyPut ( &m_mszSecureBindings, pstrSecureBindings, &m_bvChangedFields, BitMask(ID_SECURE_BINDINGS));
  109. }
  110. STDMETHODIMP CSmtpAdminService::get_SecureBindingsVariant( SAFEARRAY ** ppsavarSecureBindings )
  111. {
  112. HRESULT hr;
  113. SAFEARRAY * psastrSecureServerBindings = NULL;
  114. hr = get_SecureBindings ( &psastrSecureServerBindings );
  115. if ( FAILED(hr) ) {
  116. goto Exit;
  117. }
  118. hr = StringArrayToVariantArray ( psastrSecureServerBindings, ppsavarSecureBindings );
  119. Exit:
  120. if ( psastrSecureServerBindings ) {
  121. SafeArrayDestroy ( psastrSecureServerBindings );
  122. }
  123. return hr;
  124. }
  125. STDMETHODIMP CSmtpAdminService::put_SecureBindingsVariant( SAFEARRAY * psavarSecureBindings )
  126. {
  127. HRESULT hr;
  128. SAFEARRAY * psastrSecureServerBindings = NULL;
  129. hr = VariantArrayToStringArray ( psavarSecureBindings, &psastrSecureServerBindings );
  130. if ( FAILED(hr) ) {
  131. goto Exit;
  132. }
  133. hr = put_SecureBindings ( psastrSecureServerBindings );
  134. Exit:
  135. if ( psastrSecureServerBindings ) {
  136. SafeArrayDestroy ( psastrSecureServerBindings );
  137. }
  138. return hr;
  139. }
  140. STDMETHODIMP CSmtpAdminService::get_Port( long * plPort )
  141. {
  142. return StdPropertyGet ( m_lPort, plPort );
  143. }
  144. STDMETHODIMP CSmtpAdminService::put_Port( long lPort )
  145. {
  146. return StdPropertyPut ( &m_lPort, lPort, &m_bvChangedFields, BitMask(ID_PORT));
  147. }
  148. STDMETHODIMP CSmtpAdminService::get_SSLPort( long * plSSLPort )
  149. {
  150. return StdPropertyGet ( m_lSSLPort, plSSLPort );
  151. }
  152. STDMETHODIMP CSmtpAdminService::put_SSLPort( long lSSLPort )
  153. {
  154. return StdPropertyPut ( &m_lSSLPort, lSSLPort, &m_bvChangedFields, BitMask(ID_SSLPORT));
  155. }
  156. STDMETHODIMP CSmtpAdminService::get_OutboundPort( long * plOutboundPort )
  157. {
  158. return StdPropertyGet ( m_lOutboundPort, plOutboundPort );
  159. }
  160. STDMETHODIMP CSmtpAdminService::put_OutboundPort( long lOutboundPort )
  161. {
  162. return StdPropertyPut ( &m_lOutboundPort, lOutboundPort, &m_bvChangedFields, BitMask(ID_OUTBOUNDPORT));
  163. }
  164. STDMETHODIMP CSmtpAdminService::get_HopCount( long * plHopCount )
  165. {
  166. return StdPropertyGet ( m_lHopCount, plHopCount );
  167. }
  168. STDMETHODIMP CSmtpAdminService::put_HopCount( long lHopCount )
  169. {
  170. return StdPropertyPut ( &m_lHopCount, lHopCount, &m_bvChangedFields, BitMask(ID_HOP_COUNT));
  171. }
  172. STDMETHODIMP CSmtpAdminService::get_SmartHost( BSTR * pstrSmartHost )
  173. {
  174. return StdPropertyGet ( m_strSmartHost, pstrSmartHost );
  175. }
  176. STDMETHODIMP CSmtpAdminService::put_SmartHost( BSTR strSmartHost )
  177. {
  178. return StdPropertyPut ( &m_strSmartHost, strSmartHost, &m_bvChangedFields, BitMask(ID_SMARTHOST));
  179. }
  180. STDMETHODIMP CSmtpAdminService::get_EnableDNSLookup( BOOL * pfEnableDNSLookup )
  181. {
  182. return StdPropertyGet ( m_fEnableDNSLookup, pfEnableDNSLookup );
  183. }
  184. STDMETHODIMP CSmtpAdminService::put_EnableDNSLookup( BOOL fEnableDNSLookup )
  185. {
  186. return StdPropertyPut ( &m_fEnableDNSLookup, fEnableDNSLookup, &m_bvChangedFields, BitMask(ID_ENABLEDNSLOOKUP));
  187. }
  188. STDMETHODIMP CSmtpAdminService::get_PostmasterEmail( BSTR * pstrPostmasterEmail )
  189. {
  190. return StdPropertyGet ( m_strPostmasterEmail, pstrPostmasterEmail );
  191. }
  192. STDMETHODIMP CSmtpAdminService::put_PostmasterEmail( BSTR strPostmasterEmail )
  193. {
  194. return StdPropertyPut ( &m_strPostmasterEmail, strPostmasterEmail, &m_bvChangedFields, BitMask(ID_POSTMASTEREMAIL));
  195. }
  196. STDMETHODIMP CSmtpAdminService::get_PostmasterName( BSTR * pstrPostmasterName )
  197. {
  198. return StdPropertyGet ( m_strPostmasterName, pstrPostmasterName );
  199. }
  200. STDMETHODIMP CSmtpAdminService::put_PostmasterName( BSTR strPostmasterName )
  201. {
  202. return StdPropertyPut ( &m_strPostmasterName, strPostmasterName, &m_bvChangedFields, BitMask(ID_POSTMASTERNAME));
  203. }
  204. STDMETHODIMP CSmtpAdminService::get_DefaultDomain( BSTR * pstrDefaultDomain )
  205. {
  206. return StdPropertyGet ( m_strDefaultDomain, pstrDefaultDomain );
  207. }
  208. STDMETHODIMP CSmtpAdminService::put_DefaultDomain( BSTR strDefaultDomain )
  209. {
  210. return StdPropertyPut ( &m_strDefaultDomain, strDefaultDomain, &m_bvChangedFields, BitMask(ID_DEFAULTDOMAIN));
  211. }
  212. STDMETHODIMP CSmtpAdminService::get_FQDN( BSTR * pstrFQDN )
  213. {
  214. return StdPropertyGet ( m_strFQDN, pstrFQDN );
  215. }
  216. STDMETHODIMP CSmtpAdminService::put_FQDN( BSTR strFQDN )
  217. {
  218. return StdPropertyPut ( &m_strFQDN, strFQDN, &m_bvChangedFields, BitMask(ID_FQDN));
  219. }
  220. STDMETHODIMP CSmtpAdminService::get_DropDir( BSTR * pstrDropDir )
  221. {
  222. return StdPropertyGet ( m_strDropDir, pstrDropDir );
  223. }
  224. STDMETHODIMP CSmtpAdminService::put_DropDir( BSTR strDropDir )
  225. {
  226. return StdPropertyPut ( &m_strDropDir, strDropDir, &m_bvChangedFields, BitMask(ID_DROPDIR));
  227. }
  228. STDMETHODIMP CSmtpAdminService::get_BadMailDir( BSTR * pstrBadMailDir )
  229. {
  230. return StdPropertyGet ( m_strBadMailDir, pstrBadMailDir );
  231. }
  232. STDMETHODIMP CSmtpAdminService::put_BadMailDir( BSTR strBadMailDir )
  233. {
  234. return StdPropertyPut ( &m_strBadMailDir, strBadMailDir, &m_bvChangedFields, BitMask(ID_BADMAILDIR));
  235. }
  236. STDMETHODIMP CSmtpAdminService::get_PickupDir( BSTR * pstrPickupDir )
  237. {
  238. return StdPropertyGet ( m_strPickupDir, pstrPickupDir );
  239. }
  240. STDMETHODIMP CSmtpAdminService::put_PickupDir( BSTR strPickupDir )
  241. {
  242. return StdPropertyPut ( &m_strPickupDir, strPickupDir, &m_bvChangedFields, BitMask(ID_PICKUPDIR));
  243. }
  244. STDMETHODIMP CSmtpAdminService::get_QueueDir( BSTR * pstrQueueDir )
  245. {
  246. return StdPropertyGet ( m_strQueueDir, pstrQueueDir );
  247. }
  248. STDMETHODIMP CSmtpAdminService::put_QueueDir( BSTR strQueueDir )
  249. {
  250. return StdPropertyPut ( &m_strQueueDir, strQueueDir, &m_bvChangedFields, BitMask(ID_QUEUEDIR));
  251. }
  252. STDMETHODIMP CSmtpAdminService::get_MaxInConnection( long * plMaxInConnection )
  253. {
  254. return StdPropertyGet ( m_lMaxInConnection, plMaxInConnection );
  255. }
  256. STDMETHODIMP CSmtpAdminService::put_MaxInConnection( long lMaxInConnection )
  257. {
  258. return StdPropertyPut ( &m_lMaxInConnection, lMaxInConnection, &m_bvChangedFields, BitMask(ID_MAXINCONNECTION));
  259. }
  260. STDMETHODIMP CSmtpAdminService::get_MaxOutConnection( long * plMaxOutConnection )
  261. {
  262. return StdPropertyGet ( m_lMaxOutConnection, plMaxOutConnection );
  263. }
  264. STDMETHODIMP CSmtpAdminService::put_MaxOutConnection( long lMaxOutConnection )
  265. {
  266. return StdPropertyPut ( &m_lMaxOutConnection, lMaxOutConnection, &m_bvChangedFields, BitMask(ID_MAXOUTCONNECTION));
  267. }
  268. STDMETHODIMP CSmtpAdminService::get_InConnectionTimeout( long * plInConnectionTimeout )
  269. {
  270. return StdPropertyGet ( m_lInConnectionTimeout, plInConnectionTimeout );
  271. }
  272. STDMETHODIMP CSmtpAdminService::put_InConnectionTimeout( long lInConnectionTimeout )
  273. {
  274. return StdPropertyPut ( &m_lInConnectionTimeout, lInConnectionTimeout, &m_bvChangedFields, BitMask(ID_INCONNECTIONTIMEOUT));
  275. }
  276. STDMETHODIMP CSmtpAdminService::get_OutConnectionTimeout( long * plOutConnectionTimeout )
  277. {
  278. return StdPropertyGet ( m_lOutConnectionTimeout, plOutConnectionTimeout );
  279. }
  280. STDMETHODIMP CSmtpAdminService::put_OutConnectionTimeout( long lOutConnectionTimeout )
  281. {
  282. return StdPropertyPut ( &m_lOutConnectionTimeout, lOutConnectionTimeout, &m_bvChangedFields, BitMask(ID_OUTCONNECTIONTIMEOUT));
  283. }
  284. STDMETHODIMP CSmtpAdminService::get_MaxMessageSize( long * plMaxMessageSize )
  285. {
  286. return StdPropertyGet ( m_lMaxMessageSize, plMaxMessageSize );
  287. }
  288. STDMETHODIMP CSmtpAdminService::put_MaxMessageSize( long lMaxMessageSize )
  289. {
  290. return StdPropertyPut ( &m_lMaxMessageSize, lMaxMessageSize, &m_bvChangedFields, BitMask(ID_MAXMESSAGESIZE));
  291. }
  292. STDMETHODIMP CSmtpAdminService::get_MaxSessionSize( long * plMaxSessionSize )
  293. {
  294. return StdPropertyGet ( m_lMaxSessionSize, plMaxSessionSize );
  295. }
  296. STDMETHODIMP CSmtpAdminService::put_MaxSessionSize( long lMaxSessionSize )
  297. {
  298. return StdPropertyPut ( &m_lMaxSessionSize, lMaxSessionSize, &m_bvChangedFields, BitMask(ID_MAXSESSIONSIZE));
  299. }
  300. STDMETHODIMP CSmtpAdminService::get_MaxMessageRecipients( long * plMaxMessageRecipients )
  301. {
  302. return StdPropertyGet ( m_lMaxMessageRecipients, plMaxMessageRecipients );
  303. }
  304. STDMETHODIMP CSmtpAdminService::put_MaxMessageRecipients( long lMaxMessageRecipients )
  305. {
  306. return StdPropertyPut ( &m_lMaxMessageRecipients, lMaxMessageRecipients, &m_bvChangedFields, BitMask(ID_MAXMESSAGERECIPIENTS));
  307. }
  308. STDMETHODIMP CSmtpAdminService::get_LocalRetries( long * plLocalRetries )
  309. {
  310. return StdPropertyGet ( m_lLocalRetries, plLocalRetries );
  311. }
  312. STDMETHODIMP CSmtpAdminService::put_LocalRetries( long lLocalRetries )
  313. {
  314. return StdPropertyPut ( &m_lLocalRetries, lLocalRetries, &m_bvChangedFields, BitMask(ID_LOCALRETRIES));
  315. }
  316. STDMETHODIMP CSmtpAdminService::get_LocalRetryTime( long * plLocalRetryTime )
  317. {
  318. return StdPropertyGet ( m_lLocalRetryTime, plLocalRetryTime );
  319. }
  320. STDMETHODIMP CSmtpAdminService::put_LocalRetryTime( long lLocalRetryTime )
  321. {
  322. return StdPropertyPut ( &m_lLocalRetryTime, lLocalRetryTime, &m_bvChangedFields, BitMask(ID_LOCALRETRYTIME));
  323. }
  324. STDMETHODIMP CSmtpAdminService::get_RemoteRetries( long * plRemoteRetries )
  325. {
  326. return StdPropertyGet ( m_lRemoteRetries, plRemoteRetries );
  327. }
  328. STDMETHODIMP CSmtpAdminService::put_RemoteRetries( long lRemoteRetries )
  329. {
  330. return StdPropertyPut ( &m_lRemoteRetries, lRemoteRetries, &m_bvChangedFields, BitMask(ID_REMOTERETRIES));
  331. }
  332. STDMETHODIMP CSmtpAdminService::get_RemoteRetryTime( long * plRemoteRetryTime )
  333. {
  334. return StdPropertyGet ( m_lRemoteRetryTime, plRemoteRetryTime );
  335. }
  336. STDMETHODIMP CSmtpAdminService::put_RemoteRetryTime( long lRemoteRetryTime )
  337. {
  338. return StdPropertyPut ( &m_lRemoteRetryTime, lRemoteRetryTime, &m_bvChangedFields, BitMask(ID_REMOTERETRYTIME));
  339. }
  340. STDMETHODIMP CSmtpAdminService::get_ETRNDays( long * plETRNDays )
  341. {
  342. return StdPropertyGet ( m_lETRNDays, plETRNDays );
  343. }
  344. STDMETHODIMP CSmtpAdminService::put_ETRNDays( long lETRNDays )
  345. {
  346. return StdPropertyPut ( &m_lETRNDays, lETRNDays, &m_bvChangedFields, BitMask(ID_ETRNDAYS));
  347. }
  348. STDMETHODIMP CSmtpAdminService::get_SendDNRToPostmaster( BOOL * pfSendDNRToPostmaster )
  349. {
  350. return StdPropertyGet ( m_fSendDNRToPostmaster, pfSendDNRToPostmaster );
  351. }
  352. STDMETHODIMP CSmtpAdminService::put_SendDNRToPostmaster( BOOL fSendDNRToPostmaster )
  353. {
  354. return StdPropertyPut ( &m_fSendDNRToPostmaster, fSendDNRToPostmaster, &m_bvChangedFields, BitMask(ID_SENDDNRTOPOSTMASTER));
  355. }
  356. STDMETHODIMP CSmtpAdminService::get_SendBadmailToPostmaster( BOOL * pfSendBadmailToPostmaster)
  357. {
  358. return StdPropertyGet ( m_fSendBadmailToPostmaster, pfSendBadmailToPostmaster );
  359. }
  360. STDMETHODIMP CSmtpAdminService::put_SendBadmailToPostmaster( BOOL fSendBadmailToPostmaster )
  361. {
  362. return StdPropertyPut ( &m_fSendBadmailToPostmaster, fSendBadmailToPostmaster, &m_bvChangedFields, BitMask(ID_SENDBADMAILTOPOSTMASTER));
  363. }
  364. STDMETHODIMP CSmtpAdminService::get_RoutingDLL( BSTR * pstrRoutingDLL )
  365. {
  366. return StdPropertyGet ( m_strRoutingDLL, pstrRoutingDLL );
  367. }
  368. STDMETHODIMP CSmtpAdminService::put_RoutingDLL( BSTR strRoutingDLL )
  369. {
  370. return StdPropertyPut ( &m_strRoutingDLL, strRoutingDLL, &m_bvChangedFields, BitMask(ID_ROUTINGDLL));
  371. }
  372. STDMETHODIMP CSmtpAdminService::get_RoutingSources ( SAFEARRAY ** ppsastrRoutingSources )
  373. {
  374. return StdPropertyGet ( &m_mszRoutingSources, ppsastrRoutingSources );
  375. }
  376. STDMETHODIMP CSmtpAdminService::put_RoutingSources ( SAFEARRAY * psastrRoutingSources )
  377. {
  378. return StdPropertyPut ( &m_mszRoutingSources, psastrRoutingSources, &m_bvChangedFields, BitMask(ID_ROUTINGSOURCES) );
  379. }
  380. STDMETHODIMP CSmtpAdminService::get_RoutingSourcesVariant( SAFEARRAY ** ppsavarRoutingSources )
  381. {
  382. HRESULT hr;
  383. SAFEARRAY * psastrRoutingSources = NULL;
  384. hr = get_RoutingSources ( &psastrRoutingSources );
  385. if ( FAILED(hr) ) {
  386. goto Exit;
  387. }
  388. hr = StringArrayToVariantArray ( psastrRoutingSources, ppsavarRoutingSources );
  389. Exit:
  390. if ( psastrRoutingSources ) {
  391. SafeArrayDestroy ( psastrRoutingSources );
  392. }
  393. return hr;
  394. }
  395. STDMETHODIMP CSmtpAdminService::put_RoutingSourcesVariant( SAFEARRAY * psavarRoutingSources )
  396. {
  397. HRESULT hr;
  398. SAFEARRAY * psastrRoutingSources = NULL;
  399. hr = VariantArrayToStringArray ( psavarRoutingSources, &psastrRoutingSources );
  400. if ( FAILED(hr) ) {
  401. goto Exit;
  402. }
  403. hr = put_RoutingSources ( psastrRoutingSources );
  404. Exit:
  405. if ( psastrRoutingSources ) {
  406. SafeArrayDestroy ( psastrRoutingSources );
  407. }
  408. return hr;
  409. }
  410. STDMETHODIMP CSmtpAdminService::get_LocalDomains ( SAFEARRAY ** ppsastrLocalDomains )
  411. {
  412. return StdPropertyGet ( &m_mszLocalDomains, ppsastrLocalDomains );
  413. }
  414. STDMETHODIMP CSmtpAdminService::put_LocalDomains ( SAFEARRAY * psastrLocalDomains )
  415. {
  416. return StdPropertyPut ( &m_mszLocalDomains, psastrLocalDomains, &m_bvChangedFields, BitMask(ID_LOCALDOMAINS) );
  417. }
  418. STDMETHODIMP CSmtpAdminService::get_DomainRouting ( SAFEARRAY ** ppsastrDomainRouting )
  419. {
  420. return StdPropertyGet ( &m_mszDomainRouting, ppsastrDomainRouting );
  421. }
  422. STDMETHODIMP CSmtpAdminService::put_DomainRouting ( SAFEARRAY * psastrDomainRouting )
  423. {
  424. return StdPropertyPut ( &m_mszDomainRouting, psastrDomainRouting, &m_bvChangedFields, BitMask(ID_DOMAINROUTING) );
  425. }
  426. STDMETHODIMP CSmtpAdminService::get_DomainRoutingVariant( SAFEARRAY ** ppsastrDomainRouting )
  427. {
  428. HRESULT hr;
  429. SAFEARRAY * pstrDomainRouting = NULL;
  430. hr = get_DomainRouting ( &pstrDomainRouting );
  431. if ( FAILED(hr) ) {
  432. goto Exit;
  433. }
  434. hr = StringArrayToVariantArray ( pstrDomainRouting, ppsastrDomainRouting );
  435. Exit:
  436. if ( pstrDomainRouting ) {
  437. SafeArrayDestroy ( pstrDomainRouting );
  438. }
  439. return hr;
  440. }
  441. STDMETHODIMP CSmtpAdminService::put_DomainRoutingVariant( SAFEARRAY * psastrDomainRouting )
  442. {
  443. HRESULT hr;
  444. SAFEARRAY * pstrDomainRouting = NULL;
  445. hr = VariantArrayToStringArray ( psastrDomainRouting, &pstrDomainRouting );
  446. if ( FAILED(hr) ) {
  447. goto Exit;
  448. }
  449. hr = put_DomainRouting ( pstrDomainRouting );
  450. Exit:
  451. if ( pstrDomainRouting ) {
  452. SafeArrayDestroy ( pstrDomainRouting );
  453. }
  454. return hr;
  455. }
  456. STDMETHODIMP CSmtpAdminService::get_MasqueradeDomain( BSTR * pstrMasqueradeDomain )
  457. {
  458. return StdPropertyGet ( m_strMasqueradeDomain, pstrMasqueradeDomain );
  459. }
  460. STDMETHODIMP CSmtpAdminService::put_MasqueradeDomain( BSTR strMasqueradeDomain )
  461. {
  462. return StdPropertyPut ( &m_strMasqueradeDomain, strMasqueradeDomain, &m_bvChangedFields, BitMask(ID_MASQUERADE));
  463. }
  464. STDMETHODIMP CSmtpAdminService::get_SendNdrTo( BSTR * pstrAddr )
  465. {
  466. return StdPropertyGet( m_strNdrAddr, pstrAddr );
  467. }
  468. STDMETHODIMP CSmtpAdminService::put_SendNdrTo( BSTR strAddr )
  469. {
  470. return StdPropertyPut ( &m_strNdrAddr, strAddr, &m_bvChangedFields, BitMask(ID_SENDNDRTO));
  471. }
  472. STDMETHODIMP CSmtpAdminService::get_SendBadTo( BSTR * pstrAddr )
  473. {
  474. return StdPropertyGet( m_strBadAddr, pstrAddr );
  475. }
  476. STDMETHODIMP CSmtpAdminService::put_SendBadTo( BSTR strAddr )
  477. {
  478. return StdPropertyPut ( &m_strBadAddr, strAddr, &m_bvChangedFields, BitMask(ID_SENDBADTO));
  479. }
  480. STDMETHODIMP CSmtpAdminService::get_RemoteSecurePort( long * plRemoteSecurePort )
  481. {
  482. return StdPropertyGet( m_lRemoteSecurePort, plRemoteSecurePort );
  483. }
  484. STDMETHODIMP CSmtpAdminService::put_RemoteSecurePort( long lRemoteSecurePort )
  485. {
  486. return StdPropertyPut ( &m_lRemoteSecurePort, lRemoteSecurePort, &m_bvChangedFields, BitMask(ID_REMOTE_SECURE_PORT));
  487. }
  488. STDMETHODIMP CSmtpAdminService::get_ShouldDeliver( BOOL * pfShouldDeliver )
  489. {
  490. return StdPropertyGet( m_fShouldDeliver, pfShouldDeliver );
  491. }
  492. STDMETHODIMP CSmtpAdminService::put_ShouldDeliver( BOOL fShouldDeliver )
  493. {
  494. return StdPropertyPut ( &m_fShouldDeliver, fShouldDeliver, &m_bvChangedFields, BitMask(ID_SHOULD_DELIVER));
  495. }
  496. STDMETHODIMP CSmtpAdminService::get_AlwaysUseSsl( BOOL * pfAlwaysUseSsl )
  497. {
  498. return StdPropertyGet( m_fAlwaysUseSsl, pfAlwaysUseSsl );
  499. }
  500. STDMETHODIMP CSmtpAdminService::put_AlwaysUseSsl( BOOL fAlwaysUseSsl )
  501. {
  502. return StdPropertyPut ( &m_fAlwaysUseSsl, fAlwaysUseSsl, &m_bvChangedFields, BitMask(ID_ALWAYS_USE_SSL));
  503. }
  504. STDMETHODIMP CSmtpAdminService::get_LimitRemoteConnections( BOOL * pfLimitRemoteConnections )
  505. {
  506. return StdPropertyGet( m_fLimitRemoteConnections, pfLimitRemoteConnections );
  507. }
  508. STDMETHODIMP CSmtpAdminService::put_LimitRemoteConnections( BOOL fLimitRemoteConnections )
  509. {
  510. return StdPropertyPut ( &m_fLimitRemoteConnections, fLimitRemoteConnections, &m_bvChangedFields, BitMask(ID_LIMIT_REMOTE_CONNECTIONS));
  511. }
  512. STDMETHODIMP CSmtpAdminService::get_MaxOutConnPerDomain( long * plMaxOutConnPerDomain )
  513. {
  514. return StdPropertyGet( m_lMaxOutConnPerDomain, plMaxOutConnPerDomain );
  515. }
  516. STDMETHODIMP CSmtpAdminService::put_MaxOutConnPerDomain( long lMaxOutConnPerDomain )
  517. {
  518. return StdPropertyPut ( &m_lMaxOutConnPerDomain, lMaxOutConnPerDomain, &m_bvChangedFields, BitMask(ID_MAX_OUT_CONN_PER_DOMAIN));
  519. }
  520. STDMETHODIMP CSmtpAdminService::get_AllowVerify( BOOL * pfAllowVerify )
  521. {
  522. return StdPropertyGet( m_fAllowVerify, pfAllowVerify );
  523. }
  524. STDMETHODIMP CSmtpAdminService::put_AllowVerify( BOOL fAllowVerify )
  525. {
  526. return StdPropertyPut ( &m_fAllowVerify, fAllowVerify, &m_bvChangedFields, BitMask(ID_ALLOW_VERIFY));
  527. }
  528. STDMETHODIMP CSmtpAdminService::get_AllowExpand( BOOL * pfAllowExpand )
  529. {
  530. return StdPropertyGet( m_fAllowExpand, pfAllowExpand);
  531. }
  532. STDMETHODIMP CSmtpAdminService::put_AllowExpand( BOOL fAllowExpand )
  533. {
  534. return StdPropertyPut ( &m_fAllowExpand, fAllowExpand, &m_bvChangedFields, BitMask(ID_ALLOW_EXPAND));
  535. }
  536. STDMETHODIMP CSmtpAdminService::get_SmartHostType( long * plSmartHostType )
  537. {
  538. return StdPropertyGet( m_lSmartHostType, plSmartHostType );
  539. }
  540. STDMETHODIMP CSmtpAdminService::put_SmartHostType( long lSmartHostType )
  541. {
  542. return StdPropertyPut ( &m_lSmartHostType, lSmartHostType, &m_bvChangedFields, BitMask(ID_SMART_HOST_TYPE));
  543. }
  544. STDMETHODIMP CSmtpAdminService::get_BatchMessages( BOOL * pfBatchMessages )
  545. {
  546. return StdPropertyGet( m_fBtachMsgs, pfBatchMessages );
  547. }
  548. STDMETHODIMP CSmtpAdminService::put_BatchMessages( BOOL fBatchMessages )
  549. {
  550. return StdPropertyPut ( &m_fBtachMsgs, fBatchMessages, &m_bvChangedFields, BitMask(ID_BATCH_MSGS));
  551. }
  552. STDMETHODIMP CSmtpAdminService::get_BatchMessageLimit( long * plBatchMessageLimit )
  553. {
  554. return StdPropertyGet( m_lBatchMsgLimit, plBatchMessageLimit );
  555. }
  556. STDMETHODIMP CSmtpAdminService::put_BatchMessageLimit( long lBatchMessageLimit )
  557. {
  558. return StdPropertyPut ( &m_lBatchMsgLimit, lBatchMessageLimit, &m_bvChangedFields, BitMask(ID_BATCH_MSG_LIMIT));
  559. }
  560. STDMETHODIMP CSmtpAdminService::get_DoMasquerade( BOOL * pfDoMasquerade )
  561. {
  562. return StdPropertyGet( m_fDoMasquerade, pfDoMasquerade );
  563. }
  564. STDMETHODIMP CSmtpAdminService::put_DoMasquerade( BOOL fDoMasquerade )
  565. {
  566. return StdPropertyPut ( &m_fDoMasquerade, fDoMasquerade, &m_bvChangedFields, BitMask(ID_DO_MASQUERADE));
  567. }
  568. STDMETHODIMP CSmtpAdminService::get_Administrators ( SAFEARRAY ** ppsastrAdmins )
  569. {
  570. TraceFunctEnter ( "CSmtpAdminService::get_Administrators" );
  571. HRESULT hr = NOERROR;
  572. if ( m_psaAdmins ) {
  573. hr = SafeArrayCopy ( m_psaAdmins, ppsastrAdmins );
  574. }
  575. else {
  576. *ppsastrAdmins = NULL;
  577. hr = NOERROR;
  578. }
  579. TraceFunctLeave ();
  580. return hr;
  581. }
  582. STDMETHODIMP CSmtpAdminService::put_Administrators ( SAFEARRAY * psastrAdmins )
  583. {
  584. TraceFunctEnter ( "CSmtpAdminService::put_Administrators" );
  585. HRESULT hr = NOERROR;
  586. if ( m_psaAdmins ) {
  587. SafeArrayDestroy ( m_psaAdmins );
  588. }
  589. if ( psastrAdmins ) {
  590. hr = SafeArrayCopy ( psastrAdmins, &m_psaAdmins );
  591. }
  592. else {
  593. m_psaAdmins = NULL;
  594. hr = NOERROR;
  595. }
  596. TraceFunctLeave ();
  597. return hr;
  598. }
  599. STDMETHODIMP CSmtpAdminService::get_AdministratorsVariant( SAFEARRAY ** ppsavarAdmins )
  600. {
  601. HRESULT hr;
  602. SAFEARRAY * psastrAdmins = NULL;
  603. hr = get_Administrators ( &psastrAdmins );
  604. if ( FAILED(hr) ) {
  605. goto Exit;
  606. }
  607. hr = StringArrayToVariantArray ( psastrAdmins, ppsavarAdmins );
  608. Exit:
  609. if ( psastrAdmins ) {
  610. SafeArrayDestroy ( psastrAdmins );
  611. }
  612. return hr;
  613. }
  614. STDMETHODIMP CSmtpAdminService::put_AdministratorsVariant( SAFEARRAY * psavarAdmins )
  615. {
  616. HRESULT hr;
  617. SAFEARRAY * psastrAdmins = NULL;
  618. hr = VariantArrayToStringArray ( psavarAdmins, &psastrAdmins );
  619. if ( FAILED(hr) ) {
  620. goto Exit;
  621. }
  622. hr = put_Administrators ( psastrAdmins );
  623. Exit:
  624. if ( psastrAdmins ) {
  625. SafeArrayDestroy ( psastrAdmins );
  626. }
  627. return hr;
  628. }
  629. STDMETHODIMP CSmtpAdminService::get_LogFileDirectory( BSTR * pstrLogFileDirectory )
  630. {
  631. return StdPropertyGet ( m_strLogFileDirectory, pstrLogFileDirectory );
  632. }
  633. STDMETHODIMP CSmtpAdminService::put_LogFileDirectory( BSTR strLogFileDirectory )
  634. {
  635. return StdPropertyPut ( &m_strLogFileDirectory, strLogFileDirectory, &m_bvChangedFields, BitMask(ID_LOGFILEDIRECTORY));
  636. }
  637. STDMETHODIMP CSmtpAdminService::get_LogFilePeriod( long * plLogFilePeriod )
  638. {
  639. return StdPropertyGet ( m_lLogFilePeriod, plLogFilePeriod );
  640. }
  641. STDMETHODIMP CSmtpAdminService::put_LogFilePeriod( long lLogFilePeriod )
  642. {
  643. return StdPropertyPut ( &m_lLogFilePeriod, lLogFilePeriod, &m_bvChangedFields, BitMask(ID_LOGFILEPERIOD));
  644. }
  645. STDMETHODIMP CSmtpAdminService::get_LogFileTruncateSize( long * plLogFileTruncateSize )
  646. {
  647. return StdPropertyGet ( m_lLogFileTruncateSize, plLogFileTruncateSize );
  648. }
  649. STDMETHODIMP CSmtpAdminService::put_LogFileTruncateSize( long lLogFileTruncateSize )
  650. {
  651. return StdPropertyPut ( &m_lLogFileTruncateSize, lLogFileTruncateSize, &m_bvChangedFields, BitMask(ID_LOGFILETRUNCATESIZE));
  652. }
  653. STDMETHODIMP CSmtpAdminService::get_LogMethod( long * plLogMethod )
  654. {
  655. return StdPropertyGet ( m_lLogMethod, plLogMethod );
  656. }
  657. STDMETHODIMP CSmtpAdminService::put_LogMethod( long lLogMethod )
  658. {
  659. return StdPropertyPut ( &m_lLogMethod, lLogMethod, &m_bvChangedFields, BitMask(ID_LOGMETHOD));
  660. }
  661. STDMETHODIMP CSmtpAdminService::get_LogType( long * plLogType )
  662. {
  663. return StdPropertyGet ( m_lLogType, plLogType );
  664. }
  665. STDMETHODIMP CSmtpAdminService::put_LogType( long lLogType )
  666. {
  667. return StdPropertyPut ( &m_lLogType, lLogType, &m_bvChangedFields, BitMask(ID_LOGTYPE));
  668. }
  669. //////////////////////////////////////////////////////////////////////
  670. // Methods:
  671. //////////////////////////////////////////////////////////////////////
  672. //$-------------------------------------------------------------------
  673. //
  674. // CSmtpAdminService::Get
  675. //
  676. // Description:
  677. //
  678. // Gets server properties from the metabase.
  679. //
  680. // Parameters:
  681. //
  682. // (property) m_strServer
  683. //
  684. // Returns:
  685. //
  686. // E_POINTER, DISP_E_EXCEPTION, E_OUTOFMEMORY or NOERROR.
  687. //
  688. //--------------------------------------------------------------------
  689. STDMETHODIMP CSmtpAdminService::Get ( )
  690. {
  691. TraceFunctEnter ( "CSmtpAdminService::Get" );
  692. HRESULT hr = NOERROR;
  693. CComPtr<IMSAdminBase> pmetabase;
  694. // Validate Server & Service Instance:
  695. // Talk to the metabase:
  696. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  697. if ( FAILED(hr) ) {
  698. goto Exit;
  699. }
  700. hr = GetPropertiesFromMetabase ( pmetabase );
  701. if ( FAILED(hr) ) {
  702. goto Exit;
  703. }
  704. StateTrace ( 0, "Successfully got server properties" );
  705. m_fGotProperties = TRUE;
  706. m_bvChangedFields = 0;
  707. Exit:
  708. TraceFunctLeave ();
  709. return hr;
  710. // CComPtr automatically releases the metabase handle.
  711. }
  712. //$-------------------------------------------------------------------
  713. //
  714. // CSmtpAdminService::Set
  715. //
  716. // Description:
  717. //
  718. // Sends server properties to the metabase.
  719. //
  720. // Parameters:
  721. //
  722. // (property) m_strServer
  723. // fFailIfChanged - return an error if the metabase has changed?
  724. //
  725. // Returns:
  726. //
  727. // E_POINTER, DISP_E_EXCEPTION, E_OUTOFMEMORY or NOERROR.
  728. //
  729. //--------------------------------------------------------------------
  730. STDMETHODIMP CSmtpAdminService::Set ( BOOL fFailIfChanged )
  731. {
  732. TraceFunctEnter ( "CSmtpAdminService::Set" );
  733. HRESULT hr = NOERROR;
  734. CComPtr<IMSAdminBase> pmetabase;
  735. // Make sure the client call Get first:
  736. if ( !m_fGotProperties ) {
  737. ErrorTrace ( 0, "Didn't call get first" );
  738. hr = SmtpCreateException ( IDS_SMTPEXCEPTION_DIDNT_CALL_GET );
  739. goto Exit;
  740. }
  741. // nothing has been changed
  742. if( m_bvChangedFields == 0 )
  743. {
  744. hr = NOERROR;
  745. goto Exit;
  746. }
  747. // Validate data members:
  748. if ( !ValidateStrings () ) {
  749. // !!!magnush - what about the case when any strings are NULL?
  750. hr = E_FAIL;
  751. goto Exit;
  752. }
  753. if ( !ValidateProperties ( ) ) {
  754. hr = SmtpCreateExceptionFromWin32Error ( ERROR_INVALID_PARAMETER );;
  755. goto Exit;
  756. }
  757. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  758. if ( FAILED(hr) ) {
  759. goto Exit;
  760. }
  761. hr = SendPropertiesToMetabase ( fFailIfChanged, pmetabase );
  762. if ( FAILED(hr) ) {
  763. goto Exit;
  764. }
  765. StateTrace ( 0, "Successfully set server properties" );
  766. // successfully saved, reset change field bitmap
  767. m_bvChangedFields = 0;
  768. Exit:
  769. TraceFunctLeave ();
  770. return hr;
  771. }
  772. //$-------------------------------------------------------------------
  773. //
  774. // CSmtpAdminService::GetPropertiesFromMetabase
  775. //
  776. // Description:
  777. //
  778. // Asks the metabase for each property in this class.
  779. // This class's properties come from /LM/SmtpSvc/
  780. //
  781. // Parameters:
  782. //
  783. // pMetabase - The metabase object
  784. //
  785. // Returns:
  786. //
  787. // E_OUTOFMEMORY and others.
  788. //
  789. //--------------------------------------------------------------------
  790. HRESULT CSmtpAdminService::GetPropertiesFromMetabase ( IMSAdminBase * pMetabase )
  791. {
  792. TraceFunctEnter ( "CSmtpAdminService::GetPropertiesFromMetabase" );
  793. HRESULT hr = NOERROR;
  794. CMetabaseKey metabase ( pMetabase );
  795. BOOL fRet = TRUE;
  796. PSECURITY_DESCRIPTOR pSD = NULL;
  797. DWORD cbSD = 0;
  798. hr = metabase.Open ( SMTP_MD_ROOT_PATH );
  799. if ( FAILED(hr) ) {
  800. ErrorTraceX ( (LPARAM) this, "Failed to open SmtpSvc key, %x", GetLastError() );
  801. // Return some kind of error code here:
  802. hr = SmtpCreateExceptionFromWin32Error ( GetLastError () );
  803. goto Exit;
  804. }
  805. fRet = TRUE;
  806. #if 0
  807. fRet = StdGetMetabaseProp ( &metabase, MD_SECURE_PORT, DEFAULT_SSLPORT, &m_lSSLPort ) && fRet;
  808. #endif
  809. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_SMTP_PORT, DEFAULT_OUTBOND_PORT, &m_lOutboundPort ) && fRet;
  810. fRet = StdGetMetabaseProp ( &metabase, MD_SMARTHOST_NAME, DEFAULT_SMART_HOST, &m_strSmartHost ) && fRet;
  811. fRet = StdGetMetabaseProp ( &metabase, MD_HOP_COUNT, DEFAULT_HOP_COUNT, &m_lHopCount ) && fRet;
  812. fRet = StdGetMetabaseProp ( &metabase, MD_REVERSE_NAME_LOOKUP,DEFAULT_ENABLE_DNS_LOOKUP, &m_fEnableDNSLookup ) && fRet;
  813. fRet = StdGetMetabaseProp ( &metabase, MD_POSTMASTER_EMAIL, DEFAULT_POSTMASTER_EMAIL, &m_strPostmasterEmail ) && fRet;
  814. fRet = StdGetMetabaseProp ( &metabase, MD_POSTMASTER_NAME, DEFAULT_POSTMASTER_NAME, &m_strPostmasterName ) && fRet;
  815. fRet = StdGetMetabaseProp ( &metabase, MD_FQDN_VALUE, DEFAULT_FQDN, &m_strFQDN ) && fRet;
  816. fRet = StdGetMetabaseProp ( &metabase, MD_DEFAULT_DOMAIN_VALUE, DEFAULT_DEFAULT_DOMAIN, &m_strDefaultDomain ) && fRet;
  817. fRet = StdGetMetabaseProp ( &metabase, MD_MAIL_DROP_DIR, DEFAULT_DROP_DIR, &m_strDropDir ) && fRet;
  818. fRet = StdGetMetabaseProp ( &metabase, MD_BAD_MAIL_DIR, DEFAULT_BADMAIL_DIR, &m_strBadMailDir ) && fRet;
  819. fRet = StdGetMetabaseProp ( &metabase, MD_MAIL_PICKUP_DIR, DEFAULT_PICKUP_DIR, &m_strPickupDir ) && fRet;
  820. fRet = StdGetMetabaseProp ( &metabase, MD_MAIL_QUEUE_DIR, DEFAULT_QUEUE_DIR, &m_strQueueDir ) && fRet;
  821. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_OUTBOUND_CONNECTION, DEFAULT_MAX_OUT_CONNECTION, &m_lMaxOutConnection ) && fRet;
  822. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_TIMEOUT, DEFAULT_OUT_CONNECTION_TIMEOUT, &m_lOutConnectionTimeout ) && fRet;
  823. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_MSG_SIZE, DEFAULT_MAX_MESSAGE_SIZE, &m_lMaxMessageSize ) && fRet;
  824. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_MSG_SIZE_B4_CLOSE, DEFAULT_MAX_SESSION_SIZE, &m_lMaxSessionSize ) && fRet;
  825. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_RECIPIENTS, DEFAULT_MAX_MESSAGE_RECIPIENTS, &m_lMaxMessageRecipients ) && fRet;
  826. fRet = StdGetMetabaseProp ( &metabase, MD_LOCAL_RETRY_ATTEMPTS, DEFAULT_LOCAL_RETRIES, &m_lLocalRetries) && fRet;
  827. fRet = StdGetMetabaseProp ( &metabase, MD_LOCAL_RETRY_MINUTES, DEFAULT_LOCAL_RETRY_TIME, &m_lLocalRetryTime) && fRet;
  828. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_RETRY_ATTEMPTS, DEFAULT_REMOTE_RETRIES, &m_lRemoteRetries) && fRet;
  829. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_RETRY_MINUTES, DEFAULT_REMOTE_RETRY_TIME, &m_lRemoteRetryTime) && fRet;
  830. fRet = StdGetMetabaseProp ( &metabase, MD_ETRN_DAYS, DEFAULT_ETRN_DAYS, &m_lETRNDays) && fRet;
  831. fRet = StdGetMetabaseProp ( &metabase, MD_ROUTING_DLL, DEFAULT_ROUTING_DLL, &m_strRoutingDLL) && fRet;
  832. fRet = StdGetMetabaseProp ( &metabase, MD_ROUTING_SOURCES, DEFAULT_ROUTING_SOURCES, &m_mszRoutingSources) && fRet;
  833. fRet = StdGetMetabaseProp ( &metabase, MD_LOCAL_DOMAINS, DEFAULT_LOCAL_DOMAINS, &m_mszLocalDomains) && fRet;
  834. fRet = StdGetMetabaseProp ( &metabase, MD_DOMAIN_ROUTING, DEFAULT_DOMAIN_ROUTING, &m_mszDomainRouting) && fRet;
  835. fRet = StdGetMetabaseProp ( &metabase, MD_MASQUERADE_NAME, DEFAULT_MASQUERADE_DOMAIN, &m_strMasqueradeDomain) && fRet;
  836. fRet = StdGetMetabaseProp ( &metabase, MD_SEND_NDR_TO, DEFAULT_SENDNDRTO, &m_strNdrAddr) && fRet;
  837. fRet = StdGetMetabaseProp ( &metabase, MD_SEND_BAD_TO, DEFAULT_SENDBADTO, &m_strBadAddr) && fRet;
  838. fRet = StdGetMetabaseProp ( &metabase, MD_REMOTE_SECURE_PORT, DEFAULT_REMOTE_SECURE_PORT, &m_lRemoteSecurePort) && fRet;
  839. fRet = StdGetMetabaseProp ( &metabase, MD_SHOULD_DELIVER, DEFAULT_SHOULD_DELIVER, &m_fShouldDeliver ) && fRet;
  840. fRet = StdGetMetabaseProp ( &metabase, MD_ALWAYS_USE_SSL, DEFAULT_ALWAYS_USE_SSL, &m_fAlwaysUseSsl ) && fRet;
  841. fRet = StdGetMetabaseProp ( &metabase, MD_LIMIT_REMOTE_CONNECTIONS, DEFAULT_LIMIT_REMOTE_CONNECTIONS, &m_fLimitRemoteConnections ) && fRet;
  842. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_OUT_CONN_PER_DOMAIN, DEFAULT_MAX_OUT_CONN_PER_DOMAIN, &m_lMaxOutConnPerDomain ) && fRet;
  843. fRet = StdGetMetabaseProp ( &metabase, MD_SMARTHOST_TYPE, DEFAULT_SMART_HOST_TYPE, &m_lSmartHostType ) && fRet;
  844. fRet = StdGetMetabaseProp ( &metabase, MD_BATCH_MSG_LIMIT, DEFAULT_BATCH_MSG_LIMIT, &m_lBatchMsgLimit ) && fRet;
  845. fRet = StdGetMetabaseProp ( &metabase, MD_DO_MASQUERADE, DEFAULT_DO_MASQUERADE, &m_fDoMasquerade ) && fRet;
  846. // the following properties are set on smtpsvc/<instance-id> level for virtual server
  847. fRet = StdGetMetabaseProp ( &metabase, MD_SERVER_BINDINGS, DEFAULT_SERVER_BINDINGS, &m_mszServerBindings ) && fRet;
  848. fRet = StdGetMetabaseProp ( &metabase, MD_SECURE_BINDINGS, DEFAULT_SECURE_BINDINGS, &m_mszSecureBindings ) && fRet;
  849. // fRet = StdGetMetabaseProp ( &metabase, MD_PORT, DEFAULT_PORT, &m_lPort ) && fRet;
  850. fRet = StdGetMetabaseProp ( &metabase, MD_MAX_CONNECTIONS, DEFAULT_MAX_IN_CONNECTION, &m_lMaxInConnection ) && fRet;
  851. fRet = StdGetMetabaseProp ( &metabase, MD_CONNECTION_TIMEOUT, DEFAULT_IN_CONNECTION_TIMEOUT, &m_lInConnectionTimeout ) && fRet;
  852. fRet = StdGetMetabaseProp ( &metabase, MD_LOGFILE_DIRECTORY, DEFAULT_LOGFILE_DIRECTORY, &m_strLogFileDirectory) && fRet;
  853. fRet = StdGetMetabaseProp ( &metabase, MD_LOGFILE_PERIOD, DEFAULT_LOGFILE_PERIOD, &m_lLogFilePeriod) && fRet;
  854. fRet = StdGetMetabaseProp ( &metabase, MD_LOGFILE_TRUNCATE_SIZE,DEFAULT_LOGFILE_TRUNCATE_SIZE, &m_lLogFileTruncateSize) && fRet;
  855. // fRet = StdGetMetabaseProp ( &metabase, MD_LOG_METHOD, DEFAULT_LOG_METHOD, &m_lLogMethod) && fRet;
  856. fRet = StdGetMetabaseProp ( &metabase, MD_LOG_TYPE, DEFAULT_LOG_TYPE, &m_lLogType) && fRet;
  857. // Get the admin ACL
  858. DWORD dwDummy;
  859. pSD = NULL;
  860. cbSD = 0;
  861. metabase.GetData ( _T(""), MD_ADMIN_ACL, IIS_MD_UT_SERVER, BINARY_METADATA, &dwDummy, &cbSD, METADATA_INHERIT);
  862. if ( cbSD != 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER ) {
  863. pSD = (PSECURITY_DESCRIPTOR) new char [ cbSD ];
  864. if( NULL == pSD )
  865. {
  866. hr = E_OUTOFMEMORY;
  867. goto Exit;
  868. }
  869. fRet = metabase.GetData ( _T(""), MD_ADMIN_ACL, IIS_MD_UT_SERVER, BINARY_METADATA, pSD, &cbSD,METADATA_INHERIT );
  870. }
  871. // Check all property strings:
  872. // If any string is NULL, it is because we failed to allocate memory:
  873. if ( !ValidateStrings () ) {
  874. hr = E_OUTOFMEMORY;
  875. goto Exit;
  876. }
  877. // We can only fail from memory allocations:
  878. _ASSERT ( fRet );
  879. // Save the last changed time for this key:
  880. m_ftLastChanged.dwHighDateTime = 0;
  881. m_ftLastChanged.dwLowDateTime = 0;
  882. hr = pMetabase->GetLastChangeTime ( metabase.QueryHandle(), _T(""), &m_ftLastChanged, FALSE );
  883. if ( FAILED (hr) ) {
  884. ErrorTraceX ( (LPARAM) this, "Failed to get last change time: %x", hr );
  885. // Ignore this error.
  886. hr = NOERROR;
  887. }
  888. // Validate the data received from the metabase:
  889. _ASSERT ( ValidateStrings () );
  890. _ASSERT ( ValidateProperties( ) );
  891. // Extract the Administrator list:
  892. if ( m_psaAdmins ) {
  893. SafeArrayDestroy ( m_psaAdmins );
  894. m_psaAdmins = NULL;
  895. }
  896. if ( pSD ) {
  897. hr = AclToAdministrators ( m_strServer, pSD, &m_psaAdmins );
  898. BAIL_ON_FAILURE(hr);
  899. }
  900. if ( !ValidateProperties( ) ) {
  901. CorrectProperties ();
  902. }
  903. Exit:
  904. delete (char*) pSD;
  905. TraceFunctLeave ();
  906. return hr;
  907. // CMetabaseKey automatically closes its handle
  908. }
  909. //$-------------------------------------------------------------------
  910. //
  911. // CSmtpAdminService::SendPropertiesToMetabase
  912. //
  913. // Description:
  914. //
  915. // Saves each property to the metabase.
  916. // This class's properties go into /LM/SmtpSvc/
  917. //
  918. // Parameters:
  919. //
  920. // fFailIfChanged - Return a failure code if the metabase
  921. // has changed since last get.
  922. // pMetabase - the metabase object.
  923. //
  924. // Returns:
  925. //
  926. // E_OUTOFMEMORY and others.
  927. //
  928. //--------------------------------------------------------------------
  929. HRESULT CSmtpAdminService::SendPropertiesToMetabase (
  930. BOOL fFailIfChanged,
  931. IMSAdminBase * pMetabase
  932. )
  933. {
  934. TraceFunctEnter ( "CSmtpAdminService::SendPropertiesToMetabase" );
  935. HRESULT hr = NOERROR;
  936. CMetabaseKey metabase ( pMetabase );
  937. BOOL fRet = TRUE;
  938. //
  939. // Set the admin acl:
  940. //
  941. PSECURITY_DESCRIPTOR pSD = NULL;
  942. DWORD cbSD = 0;
  943. // if ( m_bvChangedFields & CHNG_ADMINACL ) {
  944. if ( m_psaAdmins ) {
  945. hr = AdministratorsToAcl ( m_strServer, m_psaAdmins, &pSD, &cbSD );
  946. BAIL_ON_FAILURE(hr);
  947. }
  948. // }
  949. hr = metabase.Open ( SMTP_MD_ROOT_PATH, METADATA_PERMISSION_WRITE );
  950. if ( FAILED(hr) ) {
  951. ErrorTraceX ( (LPARAM) this, "Failed to open SmtpSvc key, %x", GetLastError() );
  952. // !!!magnush - Should we return a simple Service doesn't exist error code?
  953. hr = SmtpCreateExceptionFromWin32Error ( GetLastError () );
  954. goto Exit;
  955. }
  956. // Does the client care if the key has changed?
  957. if ( fFailIfChanged ) {
  958. // Did the key change?
  959. if ( HasKeyChanged ( pMetabase, metabase.QueryHandle(), &m_ftLastChanged ) ) {
  960. StateTrace ( (LPARAM) this, "Metabase has changed, not setting properties" );
  961. // !!!magnush - Return the appropriate error code:
  962. hr = E_FAIL;
  963. goto Exit;
  964. }
  965. }
  966. //
  967. // The general procedure here is to keep setting metabase properties
  968. // as long as nothing has gone wrong. This is done by short-circuiting
  969. // the statement by ANDing it with the status code. This makes the code
  970. // much more concise.
  971. //
  972. fRet = TRUE;
  973. #if 0
  974. if ( m_bvChangedFields & BitMask(ID_SSLPORT) )
  975. {
  976. fRet = StdPutMetabaseProp ( &metabase, MD_SECURE_PORT, m_lSSLPort ) && fRet;
  977. }
  978. #endif
  979. if ( m_bvChangedFields & BitMask(ID_OUTBOUNDPORT) )
  980. {
  981. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_SMTP_PORT, m_lOutboundPort ) && fRet;
  982. }
  983. if ( m_bvChangedFields & BitMask(ID_HOP_COUNT) )
  984. {
  985. fRet = StdPutMetabaseProp ( &metabase, MD_HOP_COUNT, m_lHopCount ) && fRet;
  986. }
  987. if ( m_bvChangedFields & BitMask(ID_SMARTHOST) )
  988. {
  989. fRet = StdPutMetabaseProp ( &metabase, MD_SMARTHOST_NAME, m_strSmartHost ) && fRet;
  990. }
  991. if ( m_bvChangedFields & BitMask(ID_ENABLEDNSLOOKUP) )
  992. {
  993. fRet = StdPutMetabaseProp ( &metabase, MD_REVERSE_NAME_LOOKUP,m_fEnableDNSLookup ) && fRet;
  994. }
  995. if ( m_bvChangedFields & BitMask(ID_POSTMASTEREMAIL) )
  996. {
  997. fRet = StdPutMetabaseProp ( &metabase, MD_POSTMASTER_EMAIL, m_strPostmasterEmail ) && fRet;
  998. }
  999. if ( m_bvChangedFields & BitMask(ID_POSTMASTERNAME) )
  1000. {
  1001. fRet = StdPutMetabaseProp ( &metabase, MD_POSTMASTER_NAME, m_strPostmasterName ) && fRet;
  1002. }
  1003. if ( m_bvChangedFields & BitMask(ID_FQDN) )
  1004. {
  1005. // need to set the UPDATED flag
  1006. if( m_strFQDN.m_str && m_strFQDN.m_str[0] )
  1007. {
  1008. fRet = StdPutMetabaseProp ( &metabase, MD_UPDATED_FQDN, 1 ) && fRet;
  1009. fRet = StdPutMetabaseProp ( &metabase, MD_FQDN_VALUE, m_strFQDN ) && fRet;
  1010. }
  1011. else
  1012. {
  1013. // empty string indicating using TCP/IP setting
  1014. fRet = StdPutMetabaseProp ( &metabase, MD_UPDATED_FQDN, 0 ) && fRet;
  1015. }
  1016. }
  1017. if ( m_bvChangedFields & BitMask(ID_DEFAULTDOMAIN) )
  1018. {
  1019. // need to set the UPDATE flag
  1020. fRet = StdPutMetabaseProp ( &metabase, MD_UPDATED_DEFAULT_DOMAIN, 1 ) && fRet;
  1021. fRet = StdPutMetabaseProp ( &metabase, MD_DEFAULT_DOMAIN_VALUE, m_strDefaultDomain ) && fRet;
  1022. }
  1023. if ( m_bvChangedFields & BitMask(ID_DROPDIR) )
  1024. {
  1025. fRet = StdPutMetabaseProp ( &metabase, MD_MAIL_DROP_DIR, m_strDropDir ) && fRet;
  1026. }
  1027. if ( m_bvChangedFields & BitMask(ID_BADMAILDIR) )
  1028. {
  1029. fRet = StdPutMetabaseProp ( &metabase, MD_BAD_MAIL_DIR, m_strBadMailDir ) && fRet;
  1030. }
  1031. if ( m_bvChangedFields & BitMask(ID_PICKUPDIR) )
  1032. {
  1033. fRet = StdPutMetabaseProp ( &metabase, MD_MAIL_PICKUP_DIR, m_strPickupDir ) && fRet;
  1034. }
  1035. if ( m_bvChangedFields & BitMask(ID_QUEUEDIR) )
  1036. {
  1037. fRet = StdPutMetabaseProp ( &metabase, MD_MAIL_QUEUE_DIR, m_strQueueDir ) && fRet;
  1038. }
  1039. if ( m_bvChangedFields & BitMask(ID_MAXOUTCONNECTION) )
  1040. {
  1041. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_OUTBOUND_CONNECTION, m_lMaxOutConnection ) && fRet;
  1042. }
  1043. if ( m_bvChangedFields & BitMask(ID_OUTCONNECTIONTIMEOUT) )
  1044. {
  1045. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_TIMEOUT, m_lOutConnectionTimeout ) && fRet;
  1046. }
  1047. if ( m_bvChangedFields & BitMask(ID_MAXMESSAGESIZE) )
  1048. {
  1049. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_MSG_SIZE, m_lMaxMessageSize ) && fRet;
  1050. }
  1051. if ( m_bvChangedFields & BitMask(ID_MAXSESSIONSIZE) )
  1052. {
  1053. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_MSG_SIZE_B4_CLOSE, m_lMaxSessionSize ) && fRet;
  1054. }
  1055. if ( m_bvChangedFields & BitMask(ID_MAXMESSAGERECIPIENTS) )
  1056. {
  1057. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_RECIPIENTS, m_lMaxMessageRecipients ) && fRet;
  1058. }
  1059. if ( m_bvChangedFields & BitMask(ID_LOCALRETRYTIME) )
  1060. {
  1061. fRet = StdPutMetabaseProp ( &metabase, MD_LOCAL_RETRY_MINUTES, m_lLocalRetryTime) && fRet;
  1062. }
  1063. if ( m_bvChangedFields & BitMask(ID_REMOTERETRYTIME) )
  1064. {
  1065. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_RETRY_MINUTES, m_lRemoteRetryTime) && fRet;
  1066. }
  1067. if ( m_bvChangedFields & BitMask(ID_ETRNDAYS) )
  1068. {
  1069. fRet = StdPutMetabaseProp ( &metabase, MD_ETRN_DAYS, m_lETRNDays) && fRet;
  1070. }
  1071. if ( m_bvChangedFields & BitMask(ID_ROUTINGDLL) )
  1072. {
  1073. fRet = StdPutMetabaseProp ( &metabase, MD_ROUTING_DLL, m_strRoutingDLL) && fRet;
  1074. }
  1075. if ( m_bvChangedFields & BitMask(ID_ROUTINGSOURCES) )
  1076. {
  1077. fRet = StdPutMetabaseProp ( &metabase, MD_ROUTING_SOURCES, &m_mszRoutingSources) && fRet;
  1078. }
  1079. if ( m_bvChangedFields & BitMask(ID_LOCALDOMAINS) )
  1080. {
  1081. fRet = StdPutMetabaseProp ( &metabase, MD_LOCAL_DOMAINS, &m_mszLocalDomains) && fRet;
  1082. }
  1083. if ( m_bvChangedFields & BitMask(ID_DOMAINROUTING) )
  1084. {
  1085. fRet = StdPutMetabaseProp ( &metabase, MD_DOMAIN_ROUTING, &m_mszDomainRouting) && fRet;
  1086. }
  1087. if ( m_bvChangedFields & BitMask(ID_LOCALRETRIES) )
  1088. {
  1089. fRet = StdPutMetabaseProp ( &metabase, MD_LOCAL_RETRY_ATTEMPTS, m_lLocalRetries) && fRet;
  1090. }
  1091. if ( m_bvChangedFields & BitMask(ID_REMOTERETRIES) )
  1092. {
  1093. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_RETRY_ATTEMPTS, m_lRemoteRetries) && fRet;
  1094. }
  1095. if ( m_bvChangedFields & BitMask(ID_MASQUERADE) )
  1096. {
  1097. fRet = StdPutMetabaseProp ( &metabase, MD_MASQUERADE_NAME, m_strMasqueradeDomain) && fRet;
  1098. }
  1099. if ( m_bvChangedFields & BitMask(ID_SENDNDRTO) )
  1100. {
  1101. fRet = StdPutMetabaseProp ( &metabase, MD_SEND_NDR_TO, m_strNdrAddr) && fRet;
  1102. }
  1103. if ( m_bvChangedFields & BitMask(ID_SENDBADTO) )
  1104. {
  1105. fRet = StdPutMetabaseProp ( &metabase, MD_SEND_BAD_TO, m_strBadAddr) && fRet;
  1106. }
  1107. if ( m_bvChangedFields & BitMask(ID_REMOTE_SECURE_PORT) )
  1108. {
  1109. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_SECURE_PORT, m_lRemoteSecurePort) && fRet;
  1110. }
  1111. if ( m_bvChangedFields & BitMask(ID_SHOULD_DELIVER) )
  1112. {
  1113. fRet = StdPutMetabaseProp ( &metabase, MD_SHOULD_DELIVER, m_fShouldDeliver) && fRet;
  1114. }
  1115. if ( m_bvChangedFields & BitMask(ID_ALWAYS_USE_SSL) )
  1116. {
  1117. fRet = StdPutMetabaseProp ( &metabase, MD_ALWAYS_USE_SSL, m_fAlwaysUseSsl) && fRet;
  1118. }
  1119. if ( m_bvChangedFields & BitMask(ID_LIMIT_REMOTE_CONNECTIONS) )
  1120. {
  1121. fRet = StdPutMetabaseProp ( &metabase, MD_LIMIT_REMOTE_CONNECTIONS, m_fLimitRemoteConnections) && fRet;
  1122. }
  1123. if ( m_bvChangedFields & BitMask(ID_MAX_OUT_CONN_PER_DOMAIN) )
  1124. {
  1125. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_OUT_CONN_PER_DOMAIN, m_lMaxOutConnPerDomain) && fRet;
  1126. }
  1127. if ( m_bvChangedFields & BitMask(ID_SMART_HOST_TYPE) )
  1128. {
  1129. fRet = StdPutMetabaseProp ( &metabase, MD_SMARTHOST_TYPE, m_lSmartHostType) && fRet;
  1130. }
  1131. if ( m_bvChangedFields & BitMask(ID_BATCH_MSG_LIMIT) )
  1132. {
  1133. fRet = StdPutMetabaseProp ( &metabase, MD_BATCH_MSG_LIMIT, m_lBatchMsgLimit) && fRet;
  1134. }
  1135. if ( m_bvChangedFields & BitMask(ID_DO_MASQUERADE) )
  1136. {
  1137. fRet = StdPutMetabaseProp ( &metabase, MD_DO_MASQUERADE, m_fDoMasquerade) && fRet;
  1138. }
  1139. // the following properties are set on smtpsvc/<instance-id> level for virtual server
  1140. if ( m_bvChangedFields & BitMask(ID_SERVER_BINDINGS) )
  1141. {
  1142. fRet = StdPutMetabaseProp ( &metabase, MD_SERVER_BINDINGS, &m_mszServerBindings ) && fRet;
  1143. }
  1144. if ( m_bvChangedFields & BitMask(ID_SECURE_BINDINGS) )
  1145. {
  1146. fRet = StdPutMetabaseProp ( &metabase, MD_SECURE_BINDINGS, &m_mszSecureBindings ) && fRet;
  1147. }
  1148. if ( m_bvChangedFields & BitMask(ID_PORT) )
  1149. {
  1150. // fRet = StdPutMetabaseProp ( &metabase, MD_PORT, m_lPort ) && fRet;
  1151. }
  1152. if ( m_bvChangedFields & BitMask(ID_MAXINCONNECTION) )
  1153. {
  1154. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_CONNECTIONS, m_lMaxInConnection ) && fRet;
  1155. }
  1156. if ( m_bvChangedFields & BitMask(ID_INCONNECTIONTIMEOUT) )
  1157. {
  1158. fRet = StdPutMetabaseProp ( &metabase, MD_CONNECTION_TIMEOUT,m_lInConnectionTimeout ) && fRet;
  1159. }
  1160. if ( m_bvChangedFields & BitMask(ID_LOGFILEDIRECTORY) )
  1161. {
  1162. fRet = StdPutMetabaseProp ( &metabase, MD_LOGFILE_DIRECTORY, m_strLogFileDirectory) && fRet;
  1163. }
  1164. if ( m_bvChangedFields & BitMask(ID_LOGFILEPERIOD) )
  1165. {
  1166. fRet = StdPutMetabaseProp ( &metabase, MD_LOGFILE_PERIOD, m_lLogFilePeriod) && fRet;
  1167. }
  1168. if ( m_bvChangedFields & BitMask(ID_LOGFILETRUNCATESIZE) )
  1169. {
  1170. fRet = StdPutMetabaseProp ( &metabase, MD_LOGFILE_TRUNCATE_SIZE, m_lLogFileTruncateSize) && fRet;
  1171. }
  1172. // if ( m_bvChangedFields & BitMask(ID_LOGMETHOD) )
  1173. // {
  1174. // fRet = StdPutMetabaseProp ( &metabase, MD_LOG_TYPE, m_lLogMethod) && fRet;
  1175. // }
  1176. if ( m_bvChangedFields & BitMask(ID_LOGTYPE) )
  1177. {
  1178. fRet = StdPutMetabaseProp ( &metabase, MD_LOG_TYPE, m_lLogType) && fRet;
  1179. }
  1180. // if ( m_bvChangedFields & CHNG_ADMINACL ) {
  1181. if ( pSD ) {
  1182. fRet = fRet && metabase.SetData ( _T(""), MD_ADMIN_ACL, IIS_MD_UT_SERVER, BINARY_METADATA, pSD, cbSD, METADATA_INHERIT | METADATA_REFERENCE);
  1183. }
  1184. else {
  1185. pMetabase->DeleteData ( metabase.QueryHandle(), _T(""), MD_ADMIN_ACL, BINARY_METADATA );
  1186. }
  1187. // }
  1188. // Save the data to the metabase:
  1189. // hr = metabase.Close();
  1190. // BAIL_ON_FAILURE(hr);
  1191. metabase.Close();
  1192. hr = pMetabase->SaveData ();
  1193. if ( FAILED (hr) ) {
  1194. ErrorTraceX ( (LPARAM) this, "Failed SaveData call (%x)", hr );
  1195. goto Exit;
  1196. }
  1197. // Save the last changed time for this key:
  1198. m_ftLastChanged.dwHighDateTime = 0;
  1199. m_ftLastChanged.dwLowDateTime = 0;
  1200. hr = pMetabase->GetLastChangeTime ( metabase.QueryHandle(), _T(""), &m_ftLastChanged, FALSE );
  1201. if ( FAILED (hr) ) {
  1202. ErrorTraceX ( (LPARAM) this, "Failed to get last change time: %x", hr );
  1203. // Ignore this error.
  1204. hr = NOERROR;
  1205. }
  1206. Exit:
  1207. delete (char*) pSD;
  1208. if( SUCCEEDED(hr) && !fRet )
  1209. {
  1210. hr = SmtpCreateExceptionFromWin32Error ( GetLastError () );
  1211. }
  1212. TraceFunctLeave ();
  1213. return hr;
  1214. // CMetabaseKey automatically closes its handle
  1215. }
  1216. //$-------------------------------------------------------------------
  1217. //
  1218. // CSmtpAdminService::ValidateStrings
  1219. //
  1220. // Description:
  1221. //
  1222. // Checks to make sure each string property is non-null.
  1223. //
  1224. // Returns:
  1225. //
  1226. // FALSE if any string property is NULL.
  1227. //
  1228. //--------------------------------------------------------------------
  1229. BOOL CSmtpAdminService::ValidateStrings ( ) const
  1230. {
  1231. TraceFunctEnter ( "CSmtpAdminService::ValidateStrings" );
  1232. // Check all property strings:
  1233. // If any string is NULL, return FALSE:
  1234. if (
  1235. !m_strSmartHost ||
  1236. !m_strPostmasterEmail ||
  1237. !m_strPostmasterName ||
  1238. !m_strDefaultDomain ||
  1239. !m_strBadMailDir ||
  1240. !m_strPickupDir ||
  1241. !m_strQueueDir ||
  1242. !m_strRoutingDLL ||
  1243. !m_strLogFileDirectory
  1244. ) {
  1245. ErrorTrace ( (LPARAM) this, "String validation failed" );
  1246. TraceFunctLeave ();
  1247. return FALSE;
  1248. }
  1249. _ASSERT ( IS_VALID_STRING ( m_strSmartHost ) );
  1250. _ASSERT ( IS_VALID_STRING ( m_strPostmasterEmail ) );
  1251. _ASSERT ( IS_VALID_STRING ( m_strPostmasterName ) );
  1252. _ASSERT ( IS_VALID_STRING ( m_strDefaultDomain ) );
  1253. _ASSERT ( IS_VALID_STRING ( m_strBadMailDir ) );
  1254. _ASSERT ( IS_VALID_STRING ( m_strPickupDir ) );
  1255. _ASSERT ( IS_VALID_STRING ( m_strQueueDir ) );
  1256. _ASSERT ( IS_VALID_STRING ( m_strRoutingDLL ) );
  1257. _ASSERT ( IS_VALID_STRING ( m_strLogFileDirectory ) );
  1258. TraceFunctLeave ();
  1259. return TRUE;
  1260. }
  1261. //$-------------------------------------------------------------------
  1262. //
  1263. // CSmtpAdminService::ValidateProperties
  1264. //
  1265. // Description:
  1266. //
  1267. // Checks to make sure all parameters are valid.
  1268. //
  1269. // Parameters:
  1270. //
  1271. //
  1272. // Returns:
  1273. //
  1274. // FALSE if any property was not valid.
  1275. //
  1276. //--------------------------------------------------------------------
  1277. BOOL CSmtpAdminService::ValidateProperties ( ) const
  1278. {
  1279. BOOL fRet = TRUE;
  1280. _ASSERT ( ValidateStrings () );
  1281. /*
  1282. fRet = fRet && PV_MinMax ( m_lPort, MIN_PORT, MAX_PORT );
  1283. fRet = fRet && PV_MinMax ( m_lSSLPort, MIN_SSLPORT, MAX_SSLPORT );
  1284. fRet = fRet && PV_MinMax ( m_lOutboundPort, MIN_OUTBOND_PORT, MAX_OUTBOND_PORT );
  1285. fRet = fRet && PV_MinMax ( m_lMaxInConnection, MIN_MAX_IN_CONNECTION, MAX_MAX_IN_CONNECTION );
  1286. fRet = fRet && PV_MinMax ( m_lMaxOutConnection, MIN_MAX_OUT_CONNECTION, MAX_MAX_OUT_CONNECTION );
  1287. fRet = fRet && PV_MinMax ( m_lInConnectionTimeout, MIN_IN_CONNECTION_TIMEOUT, MAX_IN_CONNECTION_TIMEOUT );
  1288. fRet = fRet && PV_MinMax ( m_lOutConnectionTimeout, MIN_OUT_CONNECTION_TIMEOUT, MAX_OUT_CONNECTION_TIMEOUT );
  1289. fRet = fRet && PV_MinMax ( m_lMaxMessageSize, MIN_MAX_MESSAGE_SIZE, MAX_MAX_MESSAGE_SIZE );
  1290. fRet = fRet && PV_MinMax ( m_lMaxSessionSize, MIN_MAX_SESSION_SIZE, MAX_MAX_SESSION_SIZE );
  1291. fRet = fRet && PV_MinMax ( m_lMaxMessageRecipients, MIN_MAX_MESSAGE_RECIPIENTS, MAX_MAX_MESSAGE_RECIPIENTS );
  1292. fRet = fRet && PV_MinMax ( m_lLocalRetries, MIN_LOCAL_RETRIES, MAX_LOCAL_RETRIES );
  1293. fRet = fRet && PV_MinMax ( m_lLocalRetryTime, MIN_LOCAL_RETRY_TIME, MAX_LOCAL_RETRY_TIME );
  1294. fRet = fRet && PV_MinMax ( m_lRemoteRetries, MIN_REMOTE_RETRIES, MAX_REMOTE_RETRIES );
  1295. fRet = fRet && PV_MinMax ( m_lRemoteRetryTime, MIN_REMOTE_RETRY_TIME, MAX_REMOTE_RETRY_TIME );
  1296. fRet = fRet && PV_MinMax ( m_lETRNDays, MIN_ETRN_DAYS, MAX_ETRN_DAYS );
  1297. fRet = fRet && PV_MinMax ( m_lLogFilePeriod, MIN_LOGFILE_PERIOD, MAX_LOGFILE_PERIOD );
  1298. fRet = fRet && PV_MinMax ( m_lLogFileTruncateSize, MIN_LOGFILE_TRUNCATE_SIZE, MAX_LOGFILE_TRUNCATE_SIZE );
  1299. fRet = fRet && PV_MinMax ( m_lLogMethod, MIN_LOG_METHOD, MAX_LOG_METHOD );
  1300. fRet = fRet && PV_MinMax ( m_lLogType, MIN_LOG_TYPE, MAX_LOG_TYPE );
  1301. fRet = fRet && PV_Boolean ( m_fEnableDNSLookup );
  1302. fRet = fRet && PV_Boolean ( m_fSendDNRToPostmaster );
  1303. fRet = fRet && PV_Boolean ( m_fSendBadmailToPostmaster );
  1304. */
  1305. return fRet;
  1306. }
  1307. void CSmtpAdminService::CorrectProperties ( )
  1308. {
  1309. /*
  1310. if ( m_strServer && !PV_MaxChars ( m_strServer, MAXLEN_SERVER ) ) {
  1311. m_strServer[ MAXLEN_SERVER - 1 ] = NULL;
  1312. }
  1313. if ( !PV_MinMax ( m_dwArticleTimeLimit, MIN_ARTICLETIMELIMIT, MAX_ARTICLETIMELIMIT ) ) {
  1314. m_dwArticleTimeLimit = DEFAULT_ARTICLETIMELIMIT;
  1315. }
  1316. if ( !PV_MinMax ( m_dwHistoryExpiration, MIN_HISTORYEXPIRATION, MAX_HISTORYEXPIRATION ) ) {
  1317. m_dwHistoryExpiration = DEFAULT_HISTORYEXPIRATION;
  1318. }
  1319. if ( !PV_Boolean ( m_fHonorClientMsgIDs ) ) {
  1320. m_fHonorClientMsgIDs = !!m_fHonorClientMsgIDs;
  1321. }
  1322. if ( !PV_MaxChars ( m_strSmtpServer, MAXLEN_SMTPSERVER ) ) {
  1323. m_strSmtpServer[ MAXLEN_SMTPSERVER - 1 ] = NULL;
  1324. }
  1325. if ( !PV_Boolean ( m_fAllowClientPosts ) ) {
  1326. m_fAllowClientPosts = !!m_fAllowClientPosts;
  1327. }
  1328. if ( !PV_Boolean ( m_fAllowFeedPosts ) ) {
  1329. m_fAllowFeedPosts = !!m_fAllowFeedPosts;
  1330. }
  1331. if ( !PV_Boolean ( m_fAllowControlMsgs ) ) {
  1332. m_fAllowControlMsgs = !!m_fAllowControlMsgs;
  1333. }
  1334. if ( !PV_MaxChars ( m_strDefaultModeratorDomain, MAXLEN_DEFAULTMODERATORDOMAIN ) ) {
  1335. m_strDefaultModeratorDomain[ MAXLEN_DEFAULTMODERATORDOMAIN - 1] = NULL;
  1336. }
  1337. if ( !PV_MinMax ( m_dwCommandLogMask, MIN_COMMANDLOGMASK, MAX_COMMANDLOGMASK ) ) {
  1338. m_dwCommandLogMask = DEFAULT_COMMANDLOGMASK;
  1339. }
  1340. if ( !PV_Boolean ( m_fDisableNewnews ) ) {
  1341. m_fDisableNewnews = !!m_fDisableNewnews;
  1342. }
  1343. if ( !PV_MinMax ( m_dwExpireRunFrequency, MIN_EXPIRERUNFREQUENCY, MAX_EXPIRERUNFREQUENCY ) ) {
  1344. m_dwExpireRunFrequency = DEFAULT_EXPIRERUNFREQUENCY;
  1345. }
  1346. if ( !PV_MinMax ( m_dwShutdownLatency, MIN_SHUTDOWNLATENCY, MAX_SHUTDOWNLATENCY ) ) {
  1347. m_dwShutdownLatency = DEFAULT_SHUTDOWNLATENCY;
  1348. }
  1349. ---------
  1350. if ( m_bvChangedFields & BitMask(ID_PORT) )
  1351. {
  1352. fRet = StdPutMetabaseProp ( &metabase, MD_PORT, m_lPort ) && fRet;
  1353. }
  1354. #if 0
  1355. if ( m_bvChangedFields & BitMask(ID_SSLPORT) )
  1356. {
  1357. fRet = StdPutMetabaseProp ( &metabase, MD_SECURE_PORT, m_lSSLPort ) && fRet;
  1358. }
  1359. #endif
  1360. if ( m_bvChangedFields & BitMask(ID_OUTBOUNDPORT) )
  1361. {
  1362. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_SMTP_PORT, m_lOutboundPort ) && fRet;
  1363. }
  1364. if ( m_strServer && !PV_MaxChars ( m_strServer, MAXLEN_SERVER ) ) {
  1365. m_strServer[ MAXLEN_SERVER - 1 ] = NULL;
  1366. }
  1367. if ( m_bvChangedFields & BitMask(ID_SMARTHOST) )
  1368. {
  1369. fRet = StdPutMetabaseProp ( &metabase, MD_SMARTHOST_NAME, m_strSmartHost ) && fRet;
  1370. }
  1371. if ( m_bvChangedFields & BitMask(ID_ENABLEDNSLOOKUP) )
  1372. {
  1373. fRet = StdPutMetabaseProp ( &metabase, MD_REVERSE_NAME_LOOKUP,m_fEnableDNSLookup ) && fRet;
  1374. }
  1375. if ( m_bvChangedFields & BitMask(ID_POSTMASTEREMAIL) )
  1376. {
  1377. fRet = StdPutMetabaseProp ( &metabase, MD_POSTMASTER_EMAIL, m_strPostmasterEmail ) && fRet;
  1378. }
  1379. if ( m_bvChangedFields & BitMask(ID_POSTMASTERNAME) )
  1380. {
  1381. fRet = StdPutMetabaseProp ( &metabase, MD_POSTMASTER_NAME, m_strPostmasterName ) && fRet;
  1382. }
  1383. if ( m_bvChangedFields & BitMask(ID_DEFAULTDOMAIN) )
  1384. {
  1385. fRet = StdPutMetabaseProp ( &metabase, MD_DEFAULT_DOMAIN_VALUE, m_strDefaultDomain ) && fRet;
  1386. }
  1387. if ( m_bvChangedFields & BitMask(ID_BADMAILDIR) )
  1388. {
  1389. fRet = StdPutMetabaseProp ( &metabase, MD_BAD_MAIL_DIR, m_strBadMailDir ) && fRet;
  1390. }
  1391. if ( m_bvChangedFields & BitMask(ID_PICKUPDIR) )
  1392. {
  1393. fRet = StdPutMetabaseProp ( &metabase, MD_MAIL_PICKUP_DIR, m_strPickupDir ) && fRet;
  1394. }
  1395. if ( m_bvChangedFields & BitMask(ID_QUEUEDIR) )
  1396. {
  1397. fRet = StdPutMetabaseProp ( &metabase, MD_MAIL_QUEUE_DIR, m_strQueueDir ) && fRet;
  1398. }
  1399. if ( m_bvChangedFields & BitMask(ID_MAXINCONNECTION) )
  1400. {
  1401. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_CONNECTIONS, m_lMaxInConnection ) && fRet;
  1402. }
  1403. if ( m_bvChangedFields & BitMask(ID_MAXOUTCONNECTION) )
  1404. {
  1405. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_OUTBOUND_CONNECTION, m_lMaxOutConnection ) && fRet;
  1406. }
  1407. if ( m_bvChangedFields & BitMask(ID_INCONNECTIONTIMEOUT) )
  1408. {
  1409. fRet = StdPutMetabaseProp ( &metabase, MD_CONNECTION_TIMEOUT,m_lInConnectionTimeout ) && fRet;
  1410. }
  1411. if ( m_bvChangedFields & BitMask(ID_OUTCONNECTIONTIMEOUT) )
  1412. {
  1413. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_TIMEOUT, m_lOutConnectionTimeout ) && fRet;
  1414. }
  1415. if ( m_bvChangedFields & BitMask(ID_MAXMESSAGESIZE) )
  1416. {
  1417. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_MSG_SIZE, m_lMaxMessageSize ) && fRet;
  1418. }
  1419. if ( m_bvChangedFields & BitMask(ID_MAXSESSIONSIZE) )
  1420. {
  1421. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_MSG_SIZE_B4_CLOSE, m_lMaxSessionSize ) && fRet;
  1422. }
  1423. if ( m_bvChangedFields & BitMask(ID_MAXMESSAGERECIPIENTS) )
  1424. {
  1425. fRet = StdPutMetabaseProp ( &metabase, MD_MAX_RECIPIENTS, m_lMaxMessageRecipients ) && fRet;
  1426. }
  1427. if ( m_bvChangedFields & BitMask(ID_MAXRETRIES) )
  1428. {
  1429. fRet = StdPutMetabaseProp ( &metabase, MD_LOCAL_RETRY_ATTEMPTS, m_lMaxRetries ) && fRet;
  1430. }
  1431. if ( m_bvChangedFields & BitMask(ID_LOCALRETRYTIME) )
  1432. {
  1433. fRet = StdPutMetabaseProp ( &metabase, MD_LOCAL_RETRY_MINUTES, m_lLocalRetryTime) && fRet;
  1434. }
  1435. if ( m_bvChangedFields & BitMask(ID_REMOTERETRYTIME) )
  1436. {
  1437. fRet = StdPutMetabaseProp ( &metabase, MD_REMOTE_RETRY_MINUTES, m_lRemoteRetryTime) && fRet;
  1438. }
  1439. if ( m_bvChangedFields & BitMask(ID_ETRNDAYS) )
  1440. {
  1441. fRet = StdPutMetabaseProp ( &metabase, MD_ETRN_DAYS, m_lETRNDays) && fRet;
  1442. }
  1443. if ( m_bvChangedFields & BitMask(ID_SENDDNRTOPOSTMASTER) )
  1444. {
  1445. fRet = StdPutMetabaseProp ( &metabase, MD_SEND_NDR_TO_ADMIN, m_fSendDNRToPostmaster) && fRet;
  1446. }
  1447. if ( m_bvChangedFields & BitMask(ID_SENDBADMAILTOPOSTMASTER) )
  1448. {
  1449. fRet = StdPutMetabaseProp ( &metabase, MD_SEND_BAD_TO_ADMIN, m_fSendBadmailToPostmaster) && fRet;
  1450. }
  1451. // if ( m_bvChangedFields & BitMask(ID_RTTYPE) )
  1452. // {
  1453. // fRet = StdPutMetabaseProp ( &metabase, MD_ROUTING_SOURCES, m_lRTType) && fRet;
  1454. // }
  1455. if ( m_bvChangedFields & BitMask(ID_ROUTINGSOURCES) )
  1456. {
  1457. fRet = StdPutMetabaseProp ( &metabase, MD_ROUTING_SOURCES, m_strRoutingSources) && fRet;
  1458. }
  1459. if ( m_bvChangedFields & BitMask(ID_LOGFILEDIRECTORY) )
  1460. {
  1461. fRet = StdPutMetabaseProp ( &metabase, MD_LOGFILE_DIRECTORY, m_strLogFileDirectory) && fRet;
  1462. }
  1463. if ( m_bvChangedFields & BitMask(ID_LOGFILEPERIOD) )
  1464. {
  1465. fRet = StdPutMetabaseProp ( &metabase, MD_LOGFILE_PERIOD, m_lLogFilePeriod) && fRet;
  1466. }
  1467. if ( m_bvChangedFields & BitMask(ID_LOGFILETRUNCATESIZE) )
  1468. {
  1469. fRet = StdPutMetabaseProp ( &metabase, MD_LOGFILE_TRUNCATE_SIZE, m_lLogFileTruncateSize) && fRet;
  1470. }
  1471. // if ( m_bvChangedFields & BitMask(ID_LOGMETHOD) )
  1472. // {
  1473. // fRet = StdPutMetabaseProp ( &metabase, MD_LOG_TYPE, m_lLogMethod) && fRet;
  1474. // }
  1475. if ( m_bvChangedFields & BitMask(ID_LOGTYPE) )
  1476. {
  1477. fRet = StdPutMetabaseProp ( &metabase, MD_LOG_TYPE, m_lLogType) && fRet;
  1478. }
  1479. */
  1480. _ASSERT ( ValidateProperties ( ) );
  1481. }