Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymilter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
misc
pymilter
Commits
b2e0b2eb
Commit
b2e0b2eb
authored
12 years ago
by
Stuart Gathman
Browse files
Options
Downloads
Patches
Plain Diff
Fix CNAME following bug.
parent
04a241f1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Milter/dns.py
+24
-4
24 additions, 4 deletions
Milter/dns.py
with
24 additions
and
4 deletions
Milter/dns.py
+
24
−
4
View file @
b2e0b2eb
...
@@ -70,15 +70,23 @@ class Session(object):
...
@@ -70,15 +70,23 @@ class Session(object):
pre: qtype in [
'
A
'
,
'
AAAA
'
,
'
MX
'
,
'
PTR
'
,
'
TXT
'
,
'
SPF
'
]
pre: qtype in [
'
A
'
,
'
AAAA
'
,
'
MX
'
,
'
PTR
'
,
'
TXT
'
,
'
SPF
'
]
post: isinstance(__return__, types.ListType)
post: isinstance(__return__, types.ListType)
"""
"""
if
name
.
endswith
(
'
.
'
):
name
=
name
[:
-
1
]
if
not
reduce
(
lambda
x
,
y
:
x
and
0
<
len
(
y
)
<
64
,
name
.
split
(
'
.
'
),
True
):
return
[]
# invalid DNS name (too long or empty)
result
=
self
.
cache
.
get
(
(
name
,
qtype
)
)
result
=
self
.
cache
.
get
(
(
name
,
qtype
)
)
cname
=
None
cname
=
None
if
result
:
return
result
cnamek
=
(
name
,
'
CNAME
'
)
cname
=
self
.
cache
.
get
(
cnamek
)
if
not
result
:
if
cname
:
cname
=
cname
[
0
]
else
:
safe2cache
=
Session
.
SAFE2CACHE
safe2cache
=
Session
.
SAFE2CACHE
for
k
,
v
in
DNSLookup
(
name
,
qtype
):
for
k
,
v
in
DNSLookup
(
name
,
qtype
):
if
k
==
(
name
,
'
CNAME
'
)
:
if
k
==
c
name
k
:
cname
=
v
cname
=
v
if
(
qtype
,
k
[
1
])
in
safe2cache
:
if
k
[
1
]
==
'
CNAME
'
or
(
qtype
,
k
[
1
])
in
safe2cache
:
self
.
cache
.
setdefault
(
k
,
[]).
append
(
v
)
self
.
cache
.
setdefault
(
k
,
[]).
append
(
v
)
result
=
self
.
cache
.
get
(
(
name
,
qtype
),
[])
result
=
self
.
cache
.
get
(
(
name
,
qtype
),
[])
if
not
result
and
cname
:
if
not
result
and
cname
:
...
@@ -89,10 +97,22 @@ class Session(object):
...
@@ -89,10 +97,22 @@ class Session(object):
raise
DNSError
(
'
Length of CNAME chain exceeds %d
'
%
MAX_CNAME
)
raise
DNSError
(
'
Length of CNAME chain exceeds %d
'
%
MAX_CNAME
)
cnames
[
name
]
=
cname
cnames
[
name
]
=
cname
if
cname
in
cnames
:
if
cname
in
cnames
:
raise
DNSError
,
'
CNAME loop
'
raise
DNSError
(
'
CNAME loop
'
)
result
=
self
.
dns
(
cname
,
qtype
,
cnames
=
cnames
)
result
=
self
.
dns
(
cname
,
qtype
,
cnames
=
cnames
)
if
result
:
self
.
cache
[(
name
,
qtype
)]
=
result
return
result
return
result
def
dns_txt
(
self
,
domainname
,
enc
=
'
ascii
'
):
"
Get a list of TXT records for a domain name.
"
if
domainname
:
try
:
return
[
''
.
join
(
s
.
decode
(
enc
)
for
s
in
a
)
for
a
in
self
.
dns
(
domainname
,
'
TXT
'
)]
except
UnicodeEncodeError
:
raise
DNSError
(
'
Non-ascii character in SPF TXT record.
'
)
return
[]
DNS
.
DiscoverNameServers
()
DNS
.
DiscoverNameServers
()
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment