PEP8: add spaces after operators
[nivanova/samba-autobuild/.git] / python / samba / dnsserver.py
1 # helper for DNS management tool
2 #
3 # Copyright (C) Amitay Isaacs 2011-2012
4 #
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.
9 #
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.
14 #
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/>.
17 #
18
19 from samba.dcerpc import dnsserver, dnsp
20
21 #
22 # Always create a copy of strings when creating DNS_RPC_RECORDs
23 # to overcome the bug in pidl generated python bindings.
24 #
25
26
27 class ARecord(dnsserver.DNS_RPC_RECORD):
28     def __init__(self, ip_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
29                  node_flag=0):
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
37
38
39 class AAAARecord(dnsserver.DNS_RPC_RECORD):
40
41     def __init__(self, ip6_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
42                  node_flag=0):
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._ip6_addr = ip6_addr[:]
49         self.data = self._ip6_addr
50
51
52 class PTRRecord(dnsserver.DNS_RPC_RECORD):
53
54     def __init__(self, ptr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
55                  node_flag=0):
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
61         self._ptr = ptr[:]
62         ptr_name = dnsserver.DNS_RPC_NAME()
63         ptr_name.str = self._ptr
64         ptr_name.len = len(ptr)
65         self.data = ptr_name
66
67
68 class CNameRecord(dnsserver.DNS_RPC_RECORD):
69
70     def __init__(self, cname, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
71                  node_flag=0):
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
82
83
84 class NSRecord(dnsserver.DNS_RPC_RECORD):
85
86     def __init__(self, dns_server, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
87                  node_flag=0):
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)
97         self.data = ns
98
99
100 class MXRecord(dnsserver.DNS_RPC_RECORD):
101
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)
114         self.data = mx
115
116
117 class SOARecord(dnsserver.DNS_RPC_RECORD):
118
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
132         soa.dwRetry = retry
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)
139         self.data = soa
140
141
142 class SRVRecord(dnsserver.DNS_RPC_RECORD):
143
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
154         srv.wWeight = weight
155         srv.wPort = port
156         srv.nameTarget.str = self._target
157         srv.nameTarget.len = len(target)
158         self.data = srv
159
160
161 class TXTRecord(dnsserver.DNS_RPC_RECORD):
162
163     def __init__(self, slist, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
164                  node_flag=0):
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
170         self._slist = []
171         for s in slist:
172             self._slist.append(s[:])
173         names = []
174         for s in self._slist:
175             name = dnsserver.DNS_RPC_NAME()
176             name.str = s
177             name.len = len(s)
178             names.append(name)
179         txt = dnsserver.DNS_RPC_RECORD_STRING()
180         txt.count = len(slist)
181         txt.str = names
182         self.data = txt