bug-mailfromd


Search for: Advanced

Re: [Bug-mailfromd] email dns bl requires hash


Marc Roos <M.Roos@xxxxxxxxxxxxxxxxx> ha escrit:

> I would like to use an email dns blacklist something like 
> http://msbl.org/ebl.html.
> 
> This one uses an sha1 hash, so the check manually goes like this[1]. I 
> assume there is no internal function available that generates an 
> sha1sum? Is it possible to invoke this command and use it in the 
> module[2]?

Try the attached module.  Sample use:

   if match_ebl('noemail@xxxxxxxxxxx', '.ebl.msbl.org', '127.0.0.2')
      ...

Note, that the module does not do email canonicalization as suggested by
http://msbl.org/ebl-design.html.  It is trivial to implement, if needed.

Best regards,
Sergey

module 'match_ebl'.

require 'status'
require 'dns'
require 'match_cidr'

#pragma regex push +extended

func match_ebl(string email, string zone, string iprange)
  returns number
do
  set fd open("|&sha1sum")
  write(fd, email)
  shutdown(fd, SHUT_WR)
  set line getline(fd)
  if line matches '^([a-f0-9]+)  -'
    string res resolve (\1, zone)
    if res == "0"
      return 0
    fi
    if match_cidr (res, iprange)
      return 1
    else
      return 0
    fi
  else
    throw e_failure "unparsable return from sha1sum: %line"
  fi
done