8000 check *every* regex, not just first by msimerson · Pull Request #246 · smtpd/qpsmtpd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

check *every* regex, not just first #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2015
Merged

Conversation

msimerson
Copy link
Member

This corrects an issue raised by Chris Dallimore on the email list.

To: qpsmtpd@perl.org
From: Chris Dallimore <snip>
Subject: helo plugin fails to match badhelo

The helo plugin fails to match any entries in badhelo, as the is_regex_match sub returns after the first (usually unsuccessful) test.

This works for me:

--- a/plugins/helo
+++ b/plugins/helo
@@ -301,40 +301,27 @@

sub is_in_badhelo {
    my ($self, $host) = @_;
-
-    my $error = "I do not believe you are $host.";
+    my $error = "Your HELO hostname is not allowed";

    $host = lc $host;
    foreach my $bad ($self->qp->config('badhelo')) {
        if ($bad =~ /[\{\}\[\]\(\)\^\$\|\*\+\?\\\!]/) {    # it's a regexp
-            return $self->is_regex_match($host, $bad);
+            #$self->log( LOGDEBUG, "is regex ($bad)");
+            if (substr($bad, 0, 1) eq '!') {
+                $bad = substr $bad, 1;
+                if ($host !~ /$bad/) {
+                    #$self->log( LOGDEBUG, "matched negative pattern (\!$bad)");
+                    return $error, "badhelo negative pattern match (\!$bad)";
        }
-        if ($host eq lc $bad) {
-            return $error, "in badhelo";
        }
+            elsif ($host =~ /$bad/) {
+                #$self->log( LOGDEBUG, "matched ($bad)");
+                return $error, "badhelo pattern match ($bad)";
    }
-    return;
}
-
-sub is_regex_match {
-    my ($self, $host, $pattern) = @_;
-
-    my $error = "Your HELO hostname is not allowed";
-
-    #$self->log( LOGDEBUG, "is regex ($pattern)");
-    if (substr($pattern, 0, 1) eq '!') {
-        $pattern = substr $pattern, 1;
-        if ($host !~ /$pattern/) {
-
-            #$self->log( LOGDEBUG, "matched ($pattern)");
-            return $error, "badhelo pattern match ($pattern)";
+        elsif ($host eq lc $bad) {
+            return $error, "($bad) in badhelo";
        }
-        return;
-    }
-    if ($host =~ /$pattern/) {
-
-        #$self->log( LOGDEBUG, "matched ($pattern)");
-        return $error, "badhelo pattern match ($pattern)";
    }
    return;
}

msimerson added a commit that referenced this pull request Dec 20, 2015
check *every* regex, not just first
@msimerson msimerson merged commit 66e76f5 into smtpd:master Dec 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0