Bug 69876 - [patch] SMTP connections fail if IP reverse DNS fails
Summary: [patch] SMTP connections fail if IP reverse DNS fails
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Unmaintained
Component: smtp (show other bugs)
Version: SVN
Platform: Unlisted Binaries All
: NOR normal
Target Milestone: ---
Assignee: Marc Mutz
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-12-08 20:29 UTC by Thiago Macieira
Modified: 2004-02-07 13:28 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Patch adding brackets to bare IPs in EHLO/HELO (1.05 KB, patch)
2003-12-08 20:36 UTC, Thiago Macieira
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thiago Macieira 2003-12-08 20:29:19 UTC
This comes from Bug #69828, which in turn has been reported as a Debian bug. 
The bug has been found to affect IPv6 connections, but I am sure it affects 
IPv4 too. 
 
When kio_smtp attempts to connect to an SMTP server and is not using a fake 
hostname, it will try and resolve the local socket address into a hostname so 
as to use it as part of the EHLO/HELO command. 
 
The problem is when that reverse resolution fails. The current code will 
return the IP address entered as a string, which is clearly invalid for SMTP 
-- IP addresses must be enclosed in square brackets ( [ and ] ). Example: 
 
EHLO ::1 
501 syntactically invalid EHLO argument(s) 
EHLO [::1] 
250-prometheus.local.lan Hello localhost [::1] 
 
This has probably gone unnoticed because MTAs accept IPv4 without enclosing 
brackets: 
EHLO 127.0.0.1 
250-prometheus.local.lan Hello thiago at localhost.localdomain [127.0.0.1] 
 
(MTA tested was Exim; [127.0.0.1] works as expected as well) 
 
I have come up with a patch to do exactly that. It compiles, but I can't test 
it. There's also another problem: it depends on the NI_NAMEREQD macro, which 
is a design flaw in the KExtendedSocket::resolve API (my fault). I will solve 
that in KDE 3.3 by deprecating that function. 
 
The patch as it is now should solve the problem in almost all cases, since 
NI_NAMEREQD's absence also implies no IPv6 support. It will only fail with 
those MTAs that follow the RFC and don't allow bare IPv4 addresses either. 
 
Can someone test the patch and then post it for revision?
Comment 1 Thiago Macieira 2003-12-08 20:36:35 UTC
Created attachment 3621 [details]
Patch adding brackets to bare IPs in EHLO/HELO

Here goes the patch. It compiles, but I can't test whether it solves the
problem. At least it doesn't break existing support (that much I've tested).
Comment 2 Marc Mutz 2004-02-07 13:28:27 UTC
Subject: kdebase/kioslave/smtp

CVS commit by mutz: 

>From KDE_3_2_BRANCH:

Patch by Thiago to fix RFC (2)821 violation: Numeric hostnames must be domain-literals (enclosed in brackets). Took me a while to understand how the patch works (i.e. a grep -R /usr/include NI_NAMEREQD), so I've added a verbose comment explaining it.

CCMAIL: 69876-done@bugs.kde.org


  M +15 -1     smtp.cc   1.140


--- kdebase/kioslave/smtp/smtp.cc  #1.139:1.140
@@ -75,4 +75,11 @@ using std::auto_ptr;
 # include <sys/socket.h>
 #endif
+#include <netdb.h>
+
+#ifndef NI_NAMEREQD
+// FIXME for KDE 3.3: fake defintion
+// API design flaw in KExtendedSocket::resolve
+# define NI_NAMEREQD    0
+#endif
 
 extern "C" {
@@ -502,5 +509,12 @@ bool SMTPProtocol::smtp_open(const QStri
     QString tmpPort;
     KSocketAddress* addr = KExtendedSocket::localAddress(m_iSock);
-    KExtendedSocket::resolve(addr, m_hostname, tmpPort);
+    // perform name lookup. NI_NAMEREQD means: don't return a numeric
+    // value (we need to know when we get have the IP address, so we
+    // can enclose it in sqaure brackets (domain-literal). Failure to
+    // do so is normally harmless with IPv4, but fails for IPv6:
+    if (KExtendedSocket::resolve(addr, m_hostname, tmpPort, NI_NAMEREQD) != 0)
+      // FQDN resolution failed
+      // use the IP address as domain-literal
+      m_hostname = '[' + addr->nodeName() + ']';
     delete addr;