text
stringlengths 1
93.6k
|
|---|
self.options = {}
|
try:
|
self.lookups = 0
|
if not spf:
|
spf = self.dns_spf(self.d)
|
if self.verbose: self.log("top",self.d,spf)
|
if self.libspf_local and spf:
|
spf = insert_libspf_local_policy(
|
spf, self.libspf_local)
|
rc = self.check1(spf, self.d, 0)
|
if self.perm_error:
|
# lax processing encountered a permerror, but continued
|
self.perm_error.ext = rc
|
raise self.perm_error
|
return rc
|
except TempError as x:
|
self.prob = x.msg
|
if x.mech:
|
self.mech.append(x.mech)
|
return ('temperror', 451, 'SPF Temporary Error: ' + str(x))
|
except PermError as x:
|
if not self.perm_error:
|
self.perm_error = x
|
self.prob = x.msg
|
if x.mech:
|
self.mech.append(x.mech)
|
# Pre-Lentczner draft treats this as an unknown result
|
# and equivalent to no SPF record.
|
return ('permerror', 550, 'SPF Permanent Error: ' + str(x))
|
def check1(self, spf, domain, recursion):
|
# spf rfc: 3.7 Processing Limits
|
#
|
if recursion > MAX_RECURSION:
|
# This should never happen in strict mode
|
# because of the other limits we check,
|
# so if it does, there is something wrong with
|
# our code. It is not a PermError because there is not
|
# necessarily anything wrong with the SPF record.
|
if self.strict:
|
raise AssertionError('Too many levels of recursion')
|
# As an extended result, however, it should be
|
# a PermError.
|
raise PermError('Too many levels of recursion')
|
try:
|
try:
|
tmp, self.d = self.d, domain
|
return self.check0(spf, recursion)
|
finally:
|
self.d = tmp
|
except AmbiguityWarning as x:
|
self.prob = x.msg
|
if x.mech:
|
self.mech.append(x.mech)
|
return ('ambiguous', 000, 'SPF Ambiguity Warning: %s' % x)
|
def note_error(self, *msg):
|
if self.strict:
|
raise PermError(*msg)
|
# if lax mode, note error and continue
|
if not self.perm_error:
|
try:
|
raise PermError(*msg)
|
except PermError as x:
|
# FIXME: keep a list of errors for even friendlier diagnostics.
|
self.perm_error = x
|
return self.perm_error
|
def expand_domain(self,arg):
|
"validate and expand domain-spec"
|
# any trailing dot was removed by expand()
|
if RE_TOPLAB.split(arg)[-1]:
|
raise PermError('Invalid domain found (use FQDN)', arg)
|
return self.expand(arg)
|
def validate_mechanism(self, mech):
|
"""Parse and validate a mechanism.
|
Returns mech,m,arg,cidrlength,result
|
Examples:
|
>>> q = query(s='strong-bad@email.example.com.',
|
... h='mx.example.org', i='192.0.2.3')
|
>>> q.validate_mechanism('A')
|
('A', 'a', 'email.example.com', 32, 'pass')
|
>>> q = query(s='strong-bad@email.example.com',
|
... h='mx.example.org', i='192.0.2.3')
|
>>> q.validate_mechanism('A//64')
|
('A//64', 'a', 'email.example.com', 32, 'pass')
|
>>> q.validate_mechanism('A/24//64')
|
('A/24//64', 'a', 'email.example.com', 24, 'pass')
|
>>> q.validate_mechanism('?mx:%{d}/27')
|
('?mx:%{d}/27', 'mx', 'email.example.com', 27, 'neutral')
|
>>> try: q.validate_mechanism('ip4:1.2.3.4/247')
|
... except PermError as x: print(x)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.