Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hostinfo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
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
Anders Blomdell
hostinfo
Commits
a9007817
Commit
a9007817
authored
6 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup handling of names that equals domain
parent
63c3bc6b
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
src/hostinfo/named.py
+18
-23
18 additions, 23 deletions
src/hostinfo/named.py
with
18 additions
and
23 deletions
src/hostinfo/named.py
+
18
−
23
View file @
a9007817
...
@@ -6,6 +6,13 @@ import re
...
@@ -6,6 +6,13 @@ import re
import
sys
import
sys
import
os
import
os
class
NoNameserverException
(
Exception
):
pass
class
InvalidHostnameException
(
Exception
):
pass
def
generate
(
tree
,
options
):
def
generate
(
tree
,
options
):
#
#
# A. Check if host is a nameserver
# A. Check if host is a nameserver
...
@@ -100,7 +107,7 @@ def header(tree, domain, origin=None):
...
@@ -100,7 +107,7 @@ def header(tree, domain, origin=None):
if
not
filter
(
lambda
ns
:
ns
.
domain
[
0
]
==
domain
and
ns
.
primary
[
0
]
==
'
yes
'
,
if
not
filter
(
lambda
ns
:
ns
.
domain
[
0
]
==
domain
and
ns
.
primary
[
0
]
==
'
yes
'
,
tree
.
_host_
.
_interface_
.
_nameserver_
):
tree
.
_host_
.
_interface_
.
_nameserver_
):
raise
Exception
(
"
No nameserver defined for %s
"
%
domain
)
raise
NoNameserver
Exception
(
"
No nameserver defined for %s
"
%
domain
)
result
=
util
.
StringArray
()
result
=
util
.
StringArray
()
if
origin
:
if
origin
:
result
+=
"
$ORIGIN %s.
"
%
origin
result
+=
"
$ORIGIN %s.
"
%
origin
...
@@ -153,8 +160,8 @@ class DomainDict:
...
@@ -153,8 +160,8 @@ class DomainDict:
pass
pass
def
add_host
(
self
,
name
,
ttl
,
kind
,
value
):
def
add_host
(
self
,
name
,
ttl
,
kind
,
value
):
if
not
re
.
match
(
'
^[*0-9a-zA-Z][-.0-9a-zA-Z]*$
'
,
name
):
if
not
re
.
match
(
'
^
(
[*0-9a-zA-Z][-.0-9a-zA-Z]*
|@)
$
'
,
name
):
raise
Exception
(
'
Invalid host name
"
%s
"'
%
name
)
raise
InvalidHostname
Exception
(
'
Invalid host name
"
%s
"'
%
name
)
if
not
name
in
self
.
host
:
if
not
name
in
self
.
host
:
self
.
host
[
name
]
=
set
()
self
.
host
[
name
]
=
set
()
pass
pass
...
@@ -197,18 +204,6 @@ class DomainDict:
...
@@ -197,18 +204,6 @@ class DomainDict:
def
generate_forward
(
tree
,
hosts
):
def
generate_forward
(
tree
,
hosts
):
def
callback
(
domain
):
def
callback
(
domain
):
result
=
header
(
tree
,
domain
,
domain
)
result
=
header
(
tree
,
domain
,
domain
)
for
name
,
address
,
ttl
in
hosts
:
if
name
==
'
%s.
'
%
(
domain
):
# Host with same name as domain goes into header
if
address
.
version
==
4
:
result
+=
(
'
@ %-8s IN A %s
'
%
(
ttl
,
str
(
address
.
exploded
)))
elif
address
.
version
==
6
:
result
+=
(
'
@ %-8s IN AAAA %s
'
%
(
ttl
,
str
(
address
.
exploded
)))
pass
pass
pass
for
mx
in
[
m
for
m
in
tree
.
_host_
.
_interface_
.
_mailhost_
for
mx
in
[
m
for
m
in
tree
.
_host_
.
_interface_
.
_mailhost_
if
m
.
domain
[
0
]
==
domain
]:
if
m
.
domain
[
0
]
==
domain
]:
pri
=
int
(
mx
.
priority
[
0
]
or
0
)
pri
=
int
(
mx
.
priority
[
0
]
or
0
)
...
@@ -276,15 +271,15 @@ def generate_forward(tree, hosts):
...
@@ -276,15 +271,15 @@ def generate_forward(tree, hosts):
for
s
in
tree
.
_subnet_
for
s
in
tree
.
_subnet_
if
s
.
domain
[
0
]
and
util
.
network
(
s
)]:
if
s
.
domain
[
0
]
and
util
.
network
(
s
)]:
for
name
,
address
,
ttl
in
hosts
:
for
name
,
address
,
ttl
in
hosts
:
try
:
if
name
.
endswith
(
'
.
'
):
if
name
.
endswith
(
'
.
'
):
d
=
'
.
'
.
join
(
name
.
split
(
'
.
'
)[
1
:
-
1
])
if
name
[
0
:
-
1
]
==
domain
:
n
=
name
.
split
(
'
.
'
)[
0
]
add_host
(
domain
,
'
@
'
,
ttl
,
address
)
add_host
(
d
,
n
,
ttl
,
address
)
continue
except
Exception
,
e
:
pass
pass
if
address
in
net
:
elif
'
.
'
.
join
(
name
.
split
(
'
.
'
)[
1
:
-
1
])
==
domain
:
add_host
(
domain
,
name
.
split
(
'
.
'
)[
0
],
ttl
,
address
)
pass
pass
elif
address
in
net
:
add_host
(
domain
,
name
,
ttl
,
address
)
add_host
(
domain
,
name
,
ttl
,
address
)
pass
pass
pass
pass
...
...
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