Discussion:
Error 502 unimplemented
Javier
2003-07-17 17:37:03 UTC
Permalink
Hi

I've just installed qmail on my server and now I want to make some
tests.

I did a telnet connection and tried this:

telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 ptptpt.servidorekkk.net ESMTP
hello yahoo.com
502 unimplemented (#5.5.1)


Could somebody tell me why I received a 502 error message ?

Thanks in advance

<jl>
Charles Cazabon
2003-07-17 20:01:11 UTC
Permalink
Post by Javier
I've just installed qmail on my server and now I want to make some
tests.
[...]
Post by Javier
220 ptptpt.servidorekkk.net ESMTP
hello yahoo.com
502 unimplemented (#5.5.1)
Could somebody tell me why I received a 502 error message ?
Because "hello" isn't a valid SMTP command. Read RFC2821.

Charles
--
---------------------------------------------------------------------------
Charles Cazabon <***@discworld.dyndns.org>
GPL'ed software available at: http://www.qcc.ca/~charlesc/software/
Read http://www.qcc.ca/~charlesc/writings/12-steps-to-qmail-list-bliss.html
---------------------------------------------------------------------------
Markus Stumpf
2003-07-17 19:58:36 UTC
Permalink
Post by Javier
Could somebody tell me why I received a 502 error message ?
You didn't send a valid SMTP command.

\Maex
--
SpaceNet AG | Joseph-Dollinger-Bogen 14 | Fon: +49 (89) 32356-0
Research & Development | D-80807 Muenchen | Fax: +49 (89) 32356-299
"The security, stability and reliability of a computer system is reciprocally
proportional to the amount of vacuity between the ears of the admin"
Marc A. Pelletier
2003-07-17 23:27:35 UTC
Permalink
Post by Markus Stumpf
Post by Javier
Could somebody tell me why I received a 502 error message ?
You didn't send a valid SMTP command.
\Maex
No, it's a qmail bug.

502 should only be sent for commands which are valid, recognized, but not
implemented. A command which is not recognized at all (and thus, all invalid
commands) should return 500. (4.2.4)

It is, actually, trivial to fix qmail-smtpd to return the right error number
(I have). I can't think of any valid reason why unknown commands give 502
replies instead of 500 in there.

-- Marc A. Pelletier
Adam Aube
2003-07-21 17:34:40 UTC
Permalink
Post by Marc A. Pelletier
502 should only be sent for commands which are valid, recognized,
but not implemented. A command which is not recognized at all
(and thus, all invalid commands) should return 500. (4.2.4)
Actually, RFC 2821 4.2.4 says:

"502 SHOULD be used when the command is actually recognized by the
SMTP server, but not implemented. If the command is not recognized,
code 500 SHOULD be returned."

So unless a later RFC changed this wording, qmail is in compliance.

Adam
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.237 / Virus Database: 115 - Release Date: 3/7/2001
Marc A. Pelletier
2003-07-22 00:20:32 UTC
Permalink
Post by Adam Aube
"502 SHOULD be used when the command is actually recognized by the
SMTP server, but not implemented. If the command is not recognized,
code 500 SHOULD be returned."
So unless a later RFC changed this wording, qmail is in compliance.
Okay, wanna pick nits? Here's a nit to pick for you nitpicking pleasure:

"SHOULD" This word, or the adjective "RECOMMENDED", mean that there may
exist valid reasons in particular circumstances to ignore a particular item,
but the full implications must be understood and carefully weighed before
choosing a different course. [2.3]

Try as I might, I can't see any valid reason (or careful weighting) to
blindly replacing 500 with 502.

-- Marc A. Pelletier
Jonathan de Boyne Pollard
2003-07-22 12:11:32 UTC
Permalink
AA> "502 SHOULD be used when the command is actually recognized by
AA> the SMTP server, but not implemented. If the command is not
AA> recognized, code 500 SHOULD be returned."
AA>
AA> So unless a later RFC changed this wording, qmail is in
AA> compliance.

"qmail-smtpd" is complying because violation of a "SHOULD" doesn't imply
non-compliance. However, "qmail-smtpd" is _not_ following the recommendation
in the second sentence that you quote. If the command is not recognised,
"qmail-smtpd" is returning code 502, not code 500. (Stock "qmail-smtpd"
doesn't actually have a "recognised, but not implemented" category.)
Jeremy Kitchen
2003-07-17 19:56:33 UTC
Permalink
Post by Javier
Hi
hello yahoo.com
502 unimplemented (#5.5.1)
that's not proper SMTP speak. you probably meant HELO or EHLO.
--
Jeremy Kitchen

Proud Linux Administrator
http://www.w4nk3r.com
http://www.scriptkitchen.com
Adam Aube
2003-07-22 00:52:53 UTC
Permalink
Post by Marc A. Pelletier
Try as I might, I can't see any valid reason (or careful weighting) to
blindly replacing 500 with 502.
Programming simplicity. If I strictly adhere to the RFC, I have to
code handlers for all SMTP commands, even those I don't implement.
If I only code the ones I do implement, and respond 502 to anything
else, I save some code space and some effort.

This is also beneficial in case of extensions to the protocol. If
a new SMTP command is added in a new RFC, I can't return 500 anyomore,
because it's now a valid command. I would have to recode the SMTP
server to respond 502 for those new commands.

On the other hand, if I already respond 502 to any command I don't
implement (which is permitted under the RFC), there is nothing to
modify in the code.

Adam
Marc A. Pelletier
2003-07-22 01:02:44 UTC
Permalink
Post by Adam Aube
Post by Marc A. Pelletier
Try as I might, I can't see any valid reason (or careful weighting) to
blindly replacing 500 with 502.
Programming simplicity. If I strictly adhere to the RFC, I have to
code handlers for all SMTP commands, even those I don't implement.
If I only code the ones I do implement, and respond 502 to anything
else, I save some code space and some effort.
Err, no. You need not recognize a command that you do not implement at all.
It would be perfectly legal to respond with 500 to a SOML FROM command for
instance. (Indeed, 4.2.2 defines 500 as "Syntax error, *command not
recognized*" [emphasis mine]). If you want just the one error, then it
should be 500 not 502.

Replying 502 is, quite clearly, intended to mean "I know what you're trying to
do, but I don't implement that". Responding 502 to a command which is not
valid breaks that.

4.5.1 gives the (very short) list of commands which an SMTP implementation
must recognize. Anything not in that list is fair game to a 500.
Post by Adam Aube
This is also beneficial in case of extensions to the protocol. If
a new SMTP command is added in a new RFC, I can't return 500 anyomore,
because it's now a valid command. I would have to recode the SMTP
server to respond 502 for those new commands.
Again, you *can* return 500 to a command that exists but you don't recognize
yourself.
Post by Adam Aube
On the other hand, if I already respond 502 to any command I don't
implement (which is permitted under the RFC), there is nothing to
modify in the code.
Permitted, but not needed. In fact, RFC 2821 says you should do the opposite.

And while we are picking nits, the well intentionned behavior of qmail-smtpd
of breaking the connection when it receives a bare CR or LF is also forbidden
(4.5.2 states: "The mail data may contain any of the 128 ASCII characters.
All characters are to be delivered to the recipient's mailbox, including
spaces, vertical and horizontal tabs, and other control characters.")

Remember that the fact that your client MUST NOT send bare CR or LF [2.3.7]
doesn't mean that you are allowed to drop the connection because it does.
Indeed, [3.9] forbids closing the connection unless you have accepted a QUIT
command or have to forcibly close with with a 421 whose message text is fixed
[4.2] and which means the service must shut down (nothing about errors in
protocol there).

Keep the golden rule of interoperability in mind. "Be exacting in what you
provide, and lenient in what you accept."

That said, I don't beleive it is entirely unreasonable to refuse messages
containing bare CR or LF to coerce broken implementations to be fixed. It
should be refused with an appropriate reply code, tough, and not shut the
connection down. Perhaps 554 might be appropriate.

-- Marc A. Pelletier
Robin Bowes
2003-07-22 06:43:05 UTC
Permalink
Post by Marc A. Pelletier
Err, no.
This is Russell Nelson's autoresponder... :o)

R.
--
Robin Bowes | http://robinbowes.com
Adam Aube
2003-07-22 12:13:00 UTC
Permalink
Post by Marc A. Pelletier
Err, no. You need not recognize a command that you do not implement at
all. It would be perfectly legal to respond with 500 to a SOML FROM
command for instance. (Indeed, 4.2.2 defines 500 as "Syntax error,
*command not recognized*" [emphasis mine]). If you want just the one
error, then it should be 500 not 502.
I think you're nit picking as much as you accuse me of doing. What is the
practical difference between "command not recognized" (500) and "command
not implemented" (502)? Both are sent in response to a command that the mail
server does not handle. Whether the command is valid or not is splitting
hairs.

So let's take a more practical approach - how is the choice of 502 instead
of 500 causing interoperability problems? If it IS causing problems, then
let's worry about fixing it. If not, then this discussion is purely
academic.
Post by Marc A. Pelletier
And while we are picking nits, the well intentionned behavior of
qmail-smtpd of breaking the connection when it receives a bare CR
or LF is also forbidden
No argument here - that could, theoretically, cause interoperability
problems.
Post by Marc A. Pelletier
That said, I don't beleive it is entirely unreasonable to refuse
messages containing bare CR or LF to coerce broken implementations
to be fixed. It should be refused with an appropriate reply code,
tough, and not shut the connection down. Perhaps 554 might be
appropriate.
Good idea - I've seen a patch that "fixes" this behavior by making
qmail accept a bare CR or LF. It could easily be modified to return
a 554 instead. The patch is at:

http://www.arctic.org/~dean/patches/qmail-0.95-liberal-lf.patch

Adam
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.237 / Virus Database: 115 - Release Date: 3/7/2001
Charles Cazabon
2003-07-22 14:35:44 UTC
Permalink
Post by Marc A. Pelletier
Post by Adam Aube
Programming simplicity. If I strictly adhere to the RFC, I have to
code handlers for all SMTP commands, even those I don't implement.
If I only code the ones I do implement, and respond 502 to anything
else, I save some code space and some effort.
Err, no.
Actually, yes.
Post by Marc A. Pelletier
Replying 502 is, quite clearly, intended to mean "I know what you're trying
to do, but I don't implement that". Responding 502 to a command which is
not valid breaks that.
Since the only person sending non-existent commands is the fumble-fingered
administrator testing his SMTP installation with telnet, why exactly does this
matter?

Charles
--
---------------------------------------------------------------------------
Charles Cazabon <***@discworld.dyndns.org>
GPL'ed software available at: http://www.qcc.ca/~charlesc/software/
Read http://www.qcc.ca/~charlesc/writings/12-steps-to-qmail-list-bliss.html
---------------------------------------------------------------------------
Jonathan de Boyne Pollard
2003-07-22 17:47:14 UTC
Permalink
AA> If I only code the [handlers for commands] I do implement,
AA> and respond 502 to anything else, I save some code space
AA> and some effort.

MAP> Err, no. [...]

CC> Actually, yes.

Marc is correct. The correct answer is "No.". It takes the
same amount of code space to respond "500" to "anything else"
as it does to respond "502", and requires the same amount of
effort to write.

<URL:http://homepages.tesco.net./~J.deBoynePollard/Softwares/qmail.html#smtpd-502-to-500>
Markus Stumpf
2003-07-22 19:30:52 UTC
Permalink
Post by Marc A. Pelletier
Remember that the fact that your client MUST NOT send bare CR or LF [2.3.7]
doesn't mean that you are allowed to drop the connection because it does.
Indeed, [3.9] forbids closing the connection unless you have accepted a QUIT
command or have to forcibly close with with a 421 whose message text is fixed
[4.2] and which means the service must shut down (nothing about errors in
protocol there).
So the implication would be to run in a timeout because there is a
deadlock in the communication, because both servers are waiting for the
other to send. To prevent a possible DoS for the receiver and because the
connection would die in any case after the timeout it is pretty useless to
wait for something that will never happen. So the receiving mailserver has
three possibilities:
1) wait until timeout hits (this is rather braindead given the fact you
know what will happen before the timeout even starts running)
2) try to fixup the data (IMHO bare CR or LF are a serious violation of
the protocol. One should not support that so rejection is preferred
over fixup in this case).
3) drop the connection at once.
Post by Marc A. Pelletier
Keep the golden rule of interoperability in mind. "Be exacting in what you
provide, and lenient in what you accept."
This is only an excuse invented by lame programmers and not a golden rule.
The golden rule is
"fix your fscking bugs in your broken software, looser, NOW!".

\Maex
--
SpaceNet AG | Joseph-Dollinger-Bogen 14 | Fon: +49 (89) 32356-0
Research & Development | D-80807 Muenchen | Fax: +49 (89) 32356-299
"The security, stability and reliability of a computer system is reciprocally
proportional to the amount of vacuity between the ears of the admin"
Jonathan de Boyne Pollard
2003-07-23 09:25:49 UTC
Permalink
MAP> Keep the golden rule of interoperability in mind. "Be exacting
MAP> in what you provide, and lenient in what you accept."

MS> This is only an excuse invented by lame programmers and not
MS> a golden rule.

Actually, it's a mis-statement of Postel's Principle, which was
about robustness, and which was coined by the eponymous Jon Postel.

<URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/qmail-myths-dispelled.html#MythAboutBareLFs>
Jonathan de Boyne Pollard
2003-07-22 12:04:05 UTC
Permalink
MAP> Keep the golden rule of interoperability in mind.
MAP> "Be exacting in what you provide, and lenient in
MAP> what you accept."

<URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/qmail-myths-dispelled.html#MythAboutBareLFs>
Larry Weldon
2003-07-22 11:41:36 UTC
Permalink
Post by Adam Aube
Post by Marc A. Pelletier
Try as I might, I can't see any valid reason (or careful weighting) to
blindly replacing 500 with 502.
Programming simplicity. If I strictly adhere to the RFC, I have to
code handlers for all SMTP commands, even those I don't implement.
If I only code the ones I do implement, and respond 502 to anything
else, I save some code space and some effort.
Bill Gates does that a lot. But he makes up for it by simulating "code
fatness". ;) (just being funny)
Post by Adam Aube
This is also beneficial in case of extensions to the protocol. If
a new SMTP command is added in a new RFC, I can't return 500 anyomore,
because it's now a valid command. I would have to recode the SMTP
server to respond 502 for those new commands.
On the other hand, if I already respond 502 to any command I don't
implement (which is permitted under the RFC), there is nothing to
modify in the code.
Isn't "unimplemented" meant for those situations where an RFC is written
later than older codde to which it applies?
Post by Adam Aube
Adam
--
Larry Weldon <***@welcoin.com>
Jonathan de Boyne Pollard
2003-07-22 12:26:01 UTC
Permalink
AA> If I strictly adhere to the RFC, I have to code handlers
AA> for all SMTP commands, even those I don't implement.

If you strictly adhere to the RFC, you have to code handlers for all SMTP
commands _that you recognise_, even those that you don't implement. You are
not required to recognise all possible SMTP commands, however.

AA> [...] if I already respond 502 to any command I don't
AA> implement [...]

You are actually talking about responding 502 to any command that you don't
_recognise_, which the RFC says one ought not to do.
Loading...