text
stringlengths
1
93.6k
elif cidrlength > 128:
raise PermError('Invalid IP6 CIDR length', mech)
if not RE_IP6.match(arg):
raise PermError('Invalid IP6 address', mech)
else:
if cidrlength is not None or cidr6length is not None:
if m in ALL_MECHANISMS:
raise PermError('CIDR not allowed', mech)
cidrlength = self.cidrmax
if m in ('a', 'mx', 'ptr', 'exists', 'include'):
if m == 'exists' and not arg:
raise PermError('implicit exists not allowed', mech)
arg = self.expand_domain(arg)
if not arg:
raise PermError('%s empty domain:'%self.d,mech)
if m == 'include':
if arg == self.d:
if mech != 'include':
raise PermError('include has trivial recursion', mech)
raise PermError('include mechanism missing domain', mech)
return mech, m, arg, cidrlength, result
# validate 'all' mechanism per RFC 4408 ABNF
if m == 'all' and mech.count(':'):
# print '|'+ arg + '|', mech, self.d,
self.note_error(
'Invalid all mechanism format - only qualifier allowed with all'
, mech)
if m in ALL_MECHANISMS:
return mech, m, arg, cidrlength, result
if m[1:] in ALL_MECHANISMS:
x = self.note_error(
'Unknown qualifier, RFC 4408 para 4.6.1, found in', mech)
else:
x = self.note_error('Unknown mechanism found', mech)
return mech, m, arg, cidrlength, x
def check0(self, spf, recursion):
"""Test this query information against SPF text.
Returns (result, mta-status-code, explanation) where
result in ['fail', 'unknown', 'pass', 'none']
"""
if not spf:
return ('none', 250, EXPLANATIONS['none'])
# Split string by space, drop the 'v=spf1'. Split by all whitespace
# casuses things like carriage returns being treated as valid space
# separators, so split() is not sufficient.
spf = spf.split(' ')
# Catch case where SPF record has no spaces.
# Can never happen with conforming dns_spf(), however
# in the future we might want to give warnings
# for common mistakes like IN TXT "v=spf1" "mx" "-all"
# in relaxed mode.
if spf[0].lower() != 'v=spf1':
if self.strict > 1:
raise AmbiguityWarning('Invalid SPF record in', self.d)
return ('none', 250, EXPLANATIONS['none'])
# Just to make it even more fun, the relevant piece of the ABNF for
# term separations is *( 1*SP ( directive / modifier ) ), so it's one
# or more spaces, not just one. So strip empty mechanisms.
spf = [mech for mech in spf[1:] if mech]
# copy of explanations to be modified by exp=
exps = self.exps
redirect = None
# no mechanisms at all cause unknown result, unless
# overridden with 'default=' modifier
#
default = 'neutral'
mechs = []
modifiers = []
# Look for modifiers
#
for mech in spf:
m = RE_MODIFIER.split(mech)[1:]
if len(m) != 2:
mechs.append(self.validate_mechanism(mech))
continue
mod,arg = m
if mod in modifiers:
if mod == 'redirect':
raise PermError('redirect= MUST appear at most once',mech)
self.note_error('%s= MUST appear at most once'%mod,mech)
# just use last one in lax mode
modifiers.append(mod)
if mod == 'exp':
# always fetch explanation to check permerrors
if not arg:
raise PermError('exp has empty domain-spec:',arg)
arg = self.expand_domain(arg)
if arg:
try:
exp = self.get_explanation(arg)