auth/spnego: rename 'nt_status' to 'status' in gensec_spnego_create_negTokenInit()
[Samba.git] / python / samba / dnsserver.py
blob1c9f3bc8b894d22398fd80c9b4c025fbf054adc8
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.
26 class ARecord(dnsserver.DNS_RPC_RECORD):
27 def __init__(self, ip_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
28 node_flag=0):
29 super(ARecord, self).__init__()
30 self.wType = dnsp.DNS_TYPE_A
31 self.dwFlags = rank | node_flag
32 self.dwSerial = serial
33 self.dwTtlSeconds = ttl
34 self._ip_addr = ip_addr[:]
35 self.data = self._ip_addr
38 class AAAARecord(dnsserver.DNS_RPC_RECORD):
40 def __init__(self, ip6_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
41 node_flag=0):
42 super(AAAARecord, self).__init__()
43 self.wType = dnsp.DNS_TYPE_AAAA
44 self.dwFlags = rank | node_flag
45 self.dwSerial = serial
46 self.dwTtlSeconds = ttl
47 self._ip6_addr = ip6_addr[:]
48 self.data = self._ip6_addr
51 class PTRRecord(dnsserver.DNS_RPC_RECORD):
53 def __init__(self, ptr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
54 node_flag=0):
55 super(PTRRecord, self).__init__()
56 self.wType = dnsp.DNS_TYPE_PTR
57 self.dwFlags = rank | node_flag
58 self.dwSerial = serial
59 self.dwTtlSeconds = ttl
60 self._ptr = ptr[:]
61 ptr_name = dnsserver.DNS_RPC_NAME()
62 ptr_name.str = self._ptr
63 ptr_name.len = len(ptr)
64 self.data = ptr_name
67 class CNameRecord(dnsserver.DNS_RPC_RECORD):
69 def __init__(self, cname, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
70 node_flag=0):
71 super(CNameRecord, self).__init__()
72 self.wType = dnsp.DNS_TYPE_CNAME
73 self.dwFlags = rank | node_flag
74 self.dwSerial = serial
75 self.dwTtlSeconds = ttl
76 self._cname = cname[:]
77 cname_name = dnsserver.DNS_RPC_NAME()
78 cname_name.str = self._cname
79 cname_name.len = len(cname)
80 self.data = cname_name
83 class NSRecord(dnsserver.DNS_RPC_RECORD):
85 def __init__(self, dns_server, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
86 node_flag=0):
87 super(NSRecord, self).__init__()
88 self.wType = dnsp.DNS_TYPE_NS
89 self.dwFlags = rank | node_flag
90 self.dwSerial = serial
91 self.dwTtlSeconds = ttl
92 self._dns_server = dns_server[:]
93 ns = dnsserver.DNS_RPC_NAME()
94 ns.str = self._dns_server
95 ns.len = len(dns_server)
96 self.data = ns
99 class MXRecord(dnsserver.DNS_RPC_RECORD):
101 def __init__(self, mail_server, preference, serial=1, ttl=900,
102 rank=dnsp.DNS_RANK_ZONE, node_flag=0):
103 super(MXRecord, self).__init__()
104 self.wType = dnsp.DNS_TYPE_MX
105 self.dwFlags = rank | node_flag
106 self.dwSerial = serial
107 self.dwTtlSeconds = ttl
108 self._mail_server = mail_server[:]
109 mx = dnsserver.DNS_RPC_RECORD_NAME_PREFERENCE()
110 mx.wPreference = preference
111 mx.nameExchange.str = self._mail_server
112 mx.nameExchange.len = len(mail_server)
113 self.data = mx
116 class SOARecord(dnsserver.DNS_RPC_RECORD):
118 def __init__(self, mname, rname, serial=1, refresh=900, retry=600,
119 expire=86400, minimum=3600, ttl=3600, rank=dnsp.DNS_RANK_ZONE,
120 node_flag=dnsp.DNS_RPC_FLAG_AUTH_ZONE_ROOT):
121 super(SOARecord, self).__init__()
122 self.wType = dnsp.DNS_TYPE_SOA
123 self.dwFlags = rank | node_flag
124 self.dwSerial = serial
125 self.dwTtlSeconds = ttl
126 self._mname = mname[:]
127 self._rname = rname[:]
128 soa = dnsserver.DNS_RPC_RECORD_SOA()
129 soa.dwSerialNo = serial
130 soa.dwRefresh = refresh
131 soa.dwRetry = retry
132 soa.dwExpire = expire
133 soa.dwMinimumTtl = minimum
134 soa.NamePrimaryServer.str = self._mname
135 soa.NamePrimaryServer.len = len(mname)
136 soa.ZoneAdministratorEmail.str = self._rname
137 soa.ZoneAdministratorEmail.len = len(rname)
138 self.data = soa
141 class SRVRecord(dnsserver.DNS_RPC_RECORD):
143 def __init__(self, target, port, priority=0, weight=100, serial=1, ttl=900,
144 rank=dnsp.DNS_RANK_ZONE, node_flag=0):
145 super(SRVRecord, self).__init__()
146 self.wType = dnsp.DNS_TYPE_SRV
147 self.dwFlags = rank | node_flag
148 self.dwSerial = serial
149 self.dwTtlSeconds = ttl
150 self._target = target[:]
151 srv = dnsserver.DNS_RPC_RECORD_SRV()
152 srv.wPriority = priority
153 srv.wWeight = weight
154 srv.wPort = port
155 srv.nameTarget.str = self._target
156 srv.nameTarget.len = len(target)
157 self.data = srv
160 class TXTRecord(dnsserver.DNS_RPC_RECORD):
162 def __init__(self, slist, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
163 node_flag=0):
164 super(TXTRecord, self).__init__()
165 self.wType = dnsp.DNS_TYPE_TXT
166 self.dwFlags = rank | node_flag
167 self.dwSerial = serial
168 self.dwTtlSeconds = ttl
169 self._slist = []
170 for s in slist:
171 self._slist.append(s[:])
172 names = []
173 for s in self._slist:
174 name = dnsserver.DNS_RPC_NAME()
175 name.str = s
176 name.len = len(s)
177 names.append(name)
178 txt = dnsserver.DNS_RPC_RECORD_STRING()
179 txt.count = len(slist)
180 txt.str = names
181 self.data = txt