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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
misc
pymilter
Commits
8dfda22c
Commit
8dfda22c
authored
11 years ago
by
Stuart Gathman
Browse files
Options
Downloads
Patches
Plain Diff
Add dns name support for iniplist()
parent
8f7c0908
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Milter/utils.py
+17
-0
17 additions, 0 deletions
Milter/utils.py
with
17 additions
and
0 deletions
Milter/utils.py
+
17
−
0
View file @
8dfda22c
...
...
@@ -11,6 +11,7 @@ from email.Header import decode_header
#import email.Utils
import
rfc822
dnsre
=
re
.
compile
(
r
'
^[a-z][-a-z\d.]+$
'
,
re
.
IGNORECASE
)
PAT_IP4
=
r
'
\.
'
.
join
([
r
'
(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])
'
]
*
4
)
ip4re
=
re
.
compile
(
PAT_IP4
+
'
$
'
)
ip6re
=
re
.
compile
(
'
(?:%(hex4)s:){6}%(ls32)s$
'
...
...
@@ -67,6 +68,12 @@ def iniplist(ipaddr,iplist):
True
>>>
iniplist
(
'
192.168.0.45
'
,[
'
192.168.0.*
'
])
True
>>>
iniplist
(
'
4.2.2.2
'
,[
'
b.resolvers.Level3.net
'
])
True
>>>
iniplist
(
'
2607:f8b0:4004:801::
'
,[
'
google.com/64
'
])
True
>>>
iniplist
(
'
4.2.2.2
'
,[
'
nothing.example.com
'
])
False
>>>
iniplist
(
'
2001:610:779:0:223:6cff:fe9a:9cf3
'
,[
'
127.0.0.1
'
,
'
172.20.1.0/24
'
,
'
2001:610:779::/48
'
])
True
>>>
iniplist
(
'
2G01:610:779:0:223:6cff:fe9a:9cf3
'
,[
'
127.0.0.1
'
,
'
172.20.1.0/24
'
,
'
2001:610:779::/48
'
])
...
...
@@ -75,8 +82,10 @@ def iniplist(ipaddr,iplist):
ValueError
:
Invalid
ip
syntax
:
2
G01
:
610
:
779
:
0
:
223
:
6
cff
:
fe9a
:
9
cf3
"""
if
ip4re
.
match
(
ipaddr
):
fam
=
socket
.
AF_INET
ipnum
=
addr2bin
(
ipaddr
)
elif
ip6re
.
match
(
ipaddr
):
fam
=
socket
.
AF_INET6
ipnum
=
bin2long6
(
inet_pton
(
ipaddr
))
else
:
raise
ValueError
(
'
Invalid ip syntax:
'
+
ipaddr
)
...
...
@@ -96,6 +105,13 @@ def iniplist(ipaddr,iplist):
n
=
128
if
cidr
(
bin2long6
(
inet_pton
(
p
[
0
])),
n
,
MASK6
)
==
cidr
(
ipnum
,
n
,
MASK6
):
return
True
elif
dnsre
.
match
(
p
[
0
]):
try
:
sfx
=
'
/
'
.
join
([
''
]
+
p
[
1
:])
addrlist
=
[
r
[
4
][
0
]
+
sfx
for
r
in
socket
.
getaddrinfo
(
p
[
0
],
25
,
fam
)]
if
iniplist
(
ipaddr
,
addrlist
):
return
True
except
socket
.
gaierror
:
pass
elif
fnmatchcase
(
ipaddr
,
pat
):
return
True
return
False
...
...
@@ -103,6 +119,7 @@ def iniplist(ipaddr,iplist):
## Split email into Fullname and address.
# This replaces <code>email.Utils.parseaddr</code> but fixes
# some <a href="http://bugs.python.org/issue1025395">tricky test cases</a>.
# Additional tricky cases are still broken. Patches welcome.
#
def
parseaddr
(
t
):
"""
Split email into Fullname and address.
...
...
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