xref: /netbsd-src/external/bsd/nsd/dist/contrib/bind2nsd/bind2nsd/NamedConf.py (revision d83a80ee7fb31190352cf1f781441e06ca6a86db)
1#!/usr/bin/env python
2# Copyright (c) 2007, Secure64 Software Corporation
3#
4# Permission is hereby granted, free of charge, to any person obtaining a copy
5# of this software and associated documentation files (the "Software"), to deal
6# in the Software without restriction, including without limitation the rights
7# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8# copies of the Software, and to permit persons to whom the Software is
9# furnished to do so, subject to the following conditions:
10#
11# The above copyright notice and this permission notice shall be included in
12# all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20# THE SOFTWARE.
21#
22#
23#
24#	class to represent a named.conf file
25#
26
27import os
28import os.path
29import sys
30
31if os.path.exists('../bind2nsd/Config.py'):
32   sys.path.append('../bind2nsd')
33   from Config import *
34   from Parser import *
35   from Zone import *
36   from Utils import *
37else:
38   from bind2nsd.Config import *
39   from bind2nsd.Parser import *
40   from bind2nsd.Zone import *
41   from bind2nsd.Utils import *
42
43
44class Options:
45   def __init__(self):
46      self.allow_notify = []
47      self.allow_recursion = []
48      self.allow_transfer = []
49      self.also_notify = []
50      self.check_names = []
51      self.coresize = ""
52      self.directory = ""
53      self.dump_file = ""
54      self.pid_file = ""
55      self.recursive_clients = ""
56      self.statistics_file = ""
57      self.transfer_format = ""
58      self.version = ""
59      return
60
61   def dump(self):
62      report_info('=> Options:')
63      report_info('   allow-notify:      %s' % (self.allow_notify))
64      report_info('   allow-recursion:   %s' % (self.allow_recursion))
65      report_info('   allow-transfer:    %s' % (self.allow_transfer))
66      report_info('   also-notify:       %s' % (self.also_notify))
67      report_info('   check-names:       %s' % (str(self.check_names)))
68      report_info('   coresize:          %s' % (self.coresize))
69      report_info('   directory:         %s' % (self.directory))
70      report_info('   dump-file:         %s' % (self.dump_file))
71      report_info('   pid-file:          %s' % (self.pid_file))
72      report_info('   recursive-clients: %s' % (self.recursive_clients))
73      report_info('   statistics-file:   %s' % (self.statistics_file))
74      report_info('   transfer-format:   %s' % (self.transfer_format))
75      report_info('   version:           %s' % (self.version))
76      return
77
78   def setDirectory(self, name):
79      self.directory = name
80      return
81
82   def getDirectory(self):
83      return self.directory
84
85   def setDumpFile(self, name):
86      self.dump_file = name
87      return
88
89   def getDumpFile(self):
90      return self.dump_file
91
92   def setPidFile(self, name):
93      self.pid_file = name
94      return
95
96   def getPidFile(self):
97      return self.pid_file
98
99   def setStatisticsFile(self, name):
100      self.statistics_file = name
101      return
102
103   def getStatisticsFile(self):
104      return self.statistics_file
105
106   def addAllowNotify(self, quad):
107      self.allow_notify.append(quad)
108      return
109
110   def setAllowNotify(self, list):
111      self.allow_notify = list
112      return
113
114   def getAllowNotify(self):
115      return self.allow_notify
116
117   def addAllowTransfer(self, quad):
118      self.allow_transfer.append(quad)
119      return
120
121   def setAllowTransfer(self, list):
122      self.allow_transfer = list
123      return
124
125   def getAllowTransfer(self):
126      return self.allow_transfer
127
128   def addAlsoNotify(self, quad):
129      self.also_notify.append(quad)
130      return
131
132   def setAlsoNotify(self, list):
133      self.also_notify = list
134      return
135
136   def getAlsoNotify(self):
137      return self.also_notify
138
139   def addAllowRecursion(self, quad):
140      self.allow_recursion.append(quad)
141      return
142
143   def setAllowRecursion(self, list):
144      self.allow_recursion = list
145      return
146
147   def getAllowRecursion(self):
148      return self.allow_recursion
149
150   def addCheckNames(self, val):
151      self.check_names.append(val)
152      return
153
154   def getCheckNames(self):
155      return self.check_names
156
157   def setCoresize(self, val):
158      self.coresize = val
159      return
160
161   def getCoresize(self):
162      return self.coresize
163
164   def setTransferFormat(self, val):
165      self.transfer_format = val
166      return
167
168   def getTransferFormat(self):
169      return self.transfer_format
170
171   def setVersion(self, val):
172      self.version = val
173      return
174
175   def getVersion(self):
176      return self.version
177
178   def setRecursiveClients(self, val):
179      self.recursive_clients = val
180      return
181
182   def getRecursiveClients(self):
183      return self.recursive_clients
184
185
186class NamedConf:
187
188   def __init__(self, fname):
189      self.fname = fname
190      self.options = Options()
191      self.includes = []
192      self.zones = {}
193      self.keys = {}
194
195      parser = Parser(self)
196      parser.parse(Tokenizer(self.fname))
197      return
198
199   def dump(self):
200      report_info('=> NamedConf: dumping data from \"%s\"...' % (self.fname))
201      self.options.dump()
202      report_info('=> NamedConf: list of includes...')
203      report_info(str(self.includes))
204
205      report_info('=> NamedConf: zone info...')
206      zlist = self.zones.keys()
207      zlist.sort()
208      for ii in zlist:
209         self.zones[ii].dump()
210
211      report_info('=> NamedConf: key info...')
212      klist = self.keys.keys()
213      klist.sort()
214      for ii in klist:
215         self.keys[ii].dump()
216
217      return
218
219   def getOptions(self):
220      return self.options
221
222   def addZone(self, zone):
223      name = zone.getName()
224      self.zones[name] = zone
225      return
226
227   def getZones(self):
228      return self.zones
229
230   def getZone(self, name):
231      if name in self.zones:
232         return self.zones[name]
233      else:
234         return None
235
236   def addKey(self, key):
237      name = key.getName()
238      self.keys[name] = key
239      return
240
241   def getKey(self, name):
242      if name in self.keys:
243         return self.keys[name]
244      else:
245         return None
246
247   def getKeys(self):
248      return self.keys
249
250