Hi,

We have observed that the HELP command is not pluggable, so here is a patch to do so, and a sample plugin (that makes qp respond that there isn't documentation when a HELP xxx command is issued, instead of repeating the default help message).

Also, HELP capability is not announced in EHLO, so we announce it from the plugin.

Our patch isn't breaking any of the existing QP functionality (everything stays the same if you don't plug in to help), but maybe the default qp behaviour shouldn't be like it is. I think that by default (if nothing is plugged in) the HELP command should be disabled, returning DENY, and that it should be plugins work to make that change. Would this behaviour of denying help be breaking RFCs in any way?


Jose Luis Martinez
CAPSiDE

Index: qpsmtpd-0.40/plugins/help_plugin
===================================================================
--- qpsmtpd-0.40/plugins/help_plugin
+++ qpsmtpd-0.40/plugins/help_plugin
@@ -0,0 +1,22 @@
+#!perl
+
+=head1 NAME
+
+help_plugin
+
+=head1 DESCRIPTION
+
+Example B<help> plugin.
+
+Plugin should return B<OK> or B<DENY>.
+  B<OK>   - Returns an informative message.
+  B<DENY> - Returns a syntax error.
+
+=cut
+
+sub hook_ehlo {
+  my ($self, $qp) = @_;
+  my $cap = $qp->notes('capabilities');
+  $cap ||= [];
+  push @$cap, 'HELP';
+  $qp->notes('capabilities', $cap);
+  return DECLINED;
+}
+
+sub hook_help {
+  my ($self, $transaction, @args) = @_;
+
+  return OK, "No help available for SMTP command: $args[0]" if $args[0];
+  return OK; # Default message
+}
Index: qpsmtpd-0.40/lib/Qpsmtpd/SMTP.pm
===================================================================
--- qpsmtpd-0.40/lib/Qpsmtpd/SMTP.pm
+++ qpsmtpd-0.40/lib/Qpsmtpd/SMTP.pm
@@ -476,14 +476,30 @@
 }

 sub help {
-  my $self = shift;
-  $self->respond(214,
-          "This is qpsmtpd " .
-          ($self->config('smtpgreeting') ? '' : $self->version),
-          "See http://smtpd.develooper.com/";,
- 'To report bugs or send comments, mail to <[EMAIL PROTECTED]>.');
+  my ($self, @args) = @_;
+  $self->run_hooks("help", @args);
 }

+sub help_respond {
+  my ($self, $rc, $msg, $args) = @_;
+  if ($rc == DONE) {
+    return 1;
+  }
+  elsif ($rc == DENY) {
+ # DISCUSS: maybe should count as "unrecognized command" if it's not within the EHLO response
+    $msg->[0] ||= "Syntax error, command not recognized";
+    $self->respond(500, @$msg);
+    return 1;
+  } else { # everything else (DECLINED, OK, ...)
+    $msg->[0] ||= "This is qpsmtpd " .
+                  ($self->config('smtpgreeting') ? '' : $self->version),
+                  "See http://smtpd.develooper.com/";,
+ 'To report bugs or send comments, mail to <[EMAIL PROTECTED]>.';
+    $self->respond(214, @$msg);
+    return 1;
+  }
+}
+
 sub noop {
   my $self = shift;
   $self->respond(250, "OK");
Index: qpsmtpd-0.40/lib/Qpsmtpd/Plugin.pm
===================================================================
--- qpsmtpd-0.40/lib/Qpsmtpd/Plugin.pm
+++ qpsmtpd-0.40/lib/Qpsmtpd/Plugin.pm
@@ -9,7 +9,7 @@
     rcpt_parse rcpt_pre rcpt mail_parse mail mail_pre
     data data_post queue_pre queue queue_post
     quit reset_transaction disconnect post-connection
-    unrecognized_command deny ok received_line
+    unrecognized_command deny ok received_line help
 );
 our %hooks = map { $_ => 1 } @hooks;

Reply via email to