From ca1c374ebf58ccc5ed00346876835026958fe7bd Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Jun 10 2020 18:35:38 +0000 Subject: IPA-EPN: Fixes to starttls mode, convert some log errors to exceptions Tested security mode with none, starttls and ssl security. Fixes: https://pagure.io/freeipa/issue/3687 Signed-off-by: Rob Crittenden Reviewed-By: Francois Cami --- diff --git a/ipaclient/install/ipa_epn.py b/ipaclient/install/ipa_epn.py index dfe8d36..bf1644e 100644 --- a/ipaclient/install/ipa_epn.py +++ b/ipaclient/install/ipa_epn.py @@ -583,7 +583,7 @@ class MTAClient: def _connect(self): try: - if self._security_protocol == "none": + if self._security_protocol.lower() in ["none", "starttls"]: self._conn = smtplib.SMTP( host=self._smtp_hostname, port=self._smtp_port, @@ -615,7 +615,7 @@ class MTAClient: if ( self._conn.has_extn("STARTTLS") - and self._security_protocol == "starttls" + and self._security_protocol.lower() == "starttls" ): try: self._conn.starttls() @@ -634,30 +634,30 @@ class MTAClient: try: self._conn.login(self._username, self._password) if self._security_protocol == "none": - logger.info( + logger.warning( "IPA-EPN: Username and Password " "were sent in the clear." ) except smtplib.SMTPAuthenticationError: - logger.error( + raise RuntimeError( "IPA-EPN: Authentication to %s:%s failed, " - "please check your username and/or password:", - self._smtp_hostname, - self._smtp_port, + "please check your username and/or password:" % + (self._smtp_hostname, + self._smtp_port,) ) except smtplib.SMTPException as e: - logger.error( - "IPA-EPN: SMTP Error at %s:%s:%s", - self._smtp_hostname, - self._smtp_port, - e, + raise RuntimeError( + "IPA-EPN: SMTP Error at %s:%s:%s" % + (self._smtp_hostname, + self._smtp_port, + e,) ) else: err_str = ( "IPA-EPN: Server at %s:%s " - "does not support authentication.", - self._smtp_hostname, - self._smtp_port, + "does not support authentication." % + (self._smtp_hostname, + self._smtp_port,) ) logger.error(err_str)