1 # helper for DNS management tool
3 # Copyright (C) Amitay Isaacs 2011-2012
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from samba
.dcerpc
import dnsserver
, dnsp
22 # Always create a copy of strings when creating DNS_RPC_RECORDs
23 # to overcome the bug in pidl generated python bindings.
27 class ARecord(dnsserver
.DNS_RPC_RECORD
):
28 def __init__(self
, ip_addr
, serial
=1, ttl
=900, rank
=dnsp
.DNS_RANK_ZONE
,
30 super(ARecord
, self
).__init
__()
31 self
.wType
= dnsp
.DNS_TYPE_A
32 self
.dwFlags
= rank | node_flag
33 self
.dwSerial
= serial
34 self
.dwTtlSeconds
= ttl
35 self
._ip
_addr
= ip_addr
[:]
36 self
.data
= self
._ip
_addr
39 class AAAARecord(dnsserver
.DNS_RPC_RECORD
):
41 def __init__(self
, ip6_addr
, serial
=1, ttl
=900, rank
=dnsp
.DNS_RANK_ZONE
,
43 super(AAAARecord
, self
).__init
__()
44 self
.wType
= dnsp
.DNS_TYPE_AAAA
45 self
.dwFlags
= rank | node_flag
46 self
.dwSerial
= serial
47 self
.dwTtlSeconds
= ttl
48 self
._ip
6_addr
= ip6_addr
[:]
49 self
.data
= self
._ip
6_addr
52 class PTRRecord(dnsserver
.DNS_RPC_RECORD
):
54 def __init__(self
, ptr
, serial
=1, ttl
=900, rank
=dnsp
.DNS_RANK_ZONE
,
56 super(PTRRecord
, self
).__init
__()
57 self
.wType
= dnsp
.DNS_TYPE_PTR
58 self
.dwFlags
= rank | node_flag
59 self
.dwSerial
= serial
60 self
.dwTtlSeconds
= ttl
62 ptr_name
= dnsserver
.DNS_RPC_NAME()
63 ptr_name
.str = self
._ptr
64 ptr_name
.len = len(ptr
)
68 class CNameRecord(dnsserver
.DNS_RPC_RECORD
):
70 def __init__(self
, cname
, serial
=1, ttl
=900, rank
=dnsp
.DNS_RANK_ZONE
,
72 super(CNameRecord
, self
).__init
__()
73 self
.wType
= dnsp
.DNS_TYPE_CNAME
74 self
.dwFlags
= rank | node_flag
75 self
.dwSerial
= serial
76 self
.dwTtlSeconds
= ttl
77 self
._cname
= cname
[:]
78 cname_name
= dnsserver
.DNS_RPC_NAME()
79 cname_name
.str = self
._cname
80 cname_name
.len = len(cname
)
81 self
.data
= cname_name
84 class NSRecord(dnsserver
.DNS_RPC_RECORD
):
86 def __init__(self
, dns_server
, serial
=1, ttl
=900, rank
=dnsp
.DNS_RANK_ZONE
,
88 super(NSRecord
, self
).__init
__()
89 self
.wType
= dnsp
.DNS_TYPE_NS
90 self
.dwFlags
= rank | node_flag
91 self
.dwSerial
= serial
92 self
.dwTtlSeconds
= ttl
93 self
._dns
_server
= dns_server
[:]
94 ns
= dnsserver
.DNS_RPC_NAME()
95 ns
.str = self
._dns
_server
96 ns
.len = len(dns_server
)
100 class MXRecord(dnsserver
.DNS_RPC_RECORD
):
102 def __init__(self
, mail_server
, preference
, serial
=1, ttl
=900,
103 rank
=dnsp
.DNS_RANK_ZONE
, node_flag
=0):
104 super(MXRecord
, self
).__init
__()
105 self
.wType
= dnsp
.DNS_TYPE_MX
106 self
.dwFlags
= rank | node_flag
107 self
.dwSerial
= serial
108 self
.dwTtlSeconds
= ttl
109 self
._mail
_server
= mail_server
[:]
110 mx
= dnsserver
.DNS_RPC_RECORD_NAME_PREFERENCE()
111 mx
.wPreference
= preference
112 mx
.nameExchange
.str = self
._mail
_server
113 mx
.nameExchange
.len = len(mail_server
)
117 class SOARecord(dnsserver
.DNS_RPC_RECORD
):
119 def __init__(self
, mname
, rname
, serial
=1, refresh
=900, retry
=600,
120 expire
=86400, minimum
=3600, ttl
=3600, rank
=dnsp
.DNS_RANK_ZONE
,
121 node_flag
=dnsp
.DNS_RPC_FLAG_AUTH_ZONE_ROOT
):
122 super(SOARecord
, self
).__init
__()
123 self
.wType
= dnsp
.DNS_TYPE_SOA
124 self
.dwFlags
= rank | node_flag
125 self
.dwSerial
= serial
126 self
.dwTtlSeconds
= ttl
127 self
._mname
= mname
[:]
128 self
._rname
= rname
[:]
129 soa
= dnsserver
.DNS_RPC_RECORD_SOA()
130 soa
.dwSerialNo
= serial
131 soa
.dwRefresh
= refresh
133 soa
.dwExpire
= expire
134 soa
.dwMinimumTtl
= minimum
135 soa
.NamePrimaryServer
.str = self
._mname
136 soa
.NamePrimaryServer
.len = len(mname
)
137 soa
.ZoneAdministratorEmail
.str = self
._rname
138 soa
.ZoneAdministratorEmail
.len = len(rname
)
142 class SRVRecord(dnsserver
.DNS_RPC_RECORD
):
144 def __init__(self
, target
, port
, priority
=0, weight
=100, serial
=1, ttl
=900,
145 rank
=dnsp
.DNS_RANK_ZONE
, node_flag
=0):
146 super(SRVRecord
, self
).__init
__()
147 self
.wType
= dnsp
.DNS_TYPE_SRV
148 self
.dwFlags
= rank | node_flag
149 self
.dwSerial
= serial
150 self
.dwTtlSeconds
= ttl
151 self
._target
= target
[:]
152 srv
= dnsserver
.DNS_RPC_RECORD_SRV()
153 srv
.wPriority
= priority
156 srv
.nameTarget
.str = self
._target
157 srv
.nameTarget
.len = len(target
)
161 class TXTRecord(dnsserver
.DNS_RPC_RECORD
):
163 def __init__(self
, slist
, serial
=1, ttl
=900, rank
=dnsp
.DNS_RANK_ZONE
,
165 super(TXTRecord
, self
).__init
__()
166 self
.wType
= dnsp
.DNS_TYPE_TXT
167 self
.dwFlags
= rank | node_flag
168 self
.dwSerial
= serial
169 self
.dwTtlSeconds
= ttl
172 self
._slist
.append(s
[:])
174 for s
in self
._slist
:
175 name
= dnsserver
.DNS_RPC_NAME()
179 txt
= dnsserver
.DNS_RPC_RECORD_STRING()
180 txt
.count
= len(slist
)