2
# network.py - lookup functions for network names and addresses
4
# Copyright (C) 2011 Arthur de Jong
6
# This library is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU Lesser General Public
8
# License as published by the Free Software Foundation; either
9
# version 2.1 of the License, or (at your option) any later version.
11
# This library is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
# Lesser General Public License for more details.
16
# You should have received a copy of the GNU Lesser General Public
17
# License along with this library; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29
class NetworkRequest(common.Request):
31
filter = '(objectClass=ipNetwork)'
34
attmap_ipNetworkNumber = 'ipNetworkNumber'
36
attributes = ( 'cn', 'ipNetworkNumber' )
38
def write(self, entry):
39
dn, attributes = entry
40
networkname = common.get_rdn_value(entry, self.attmap_cn)
41
networknames = attributes.get(self.attmap_cn, [])
43
print 'Error: entry %s does not contain %s value' % ( dn, self.attmap_cn)
45
networkname = networknames.pop(0)
47
networknames.remove(networkname)
48
addresses = attributes.get(self.attmap_ipNetworkNumber, [])
50
print 'Error: entry %s does not contain %s value' % ( dn, self.attmap_ipNetworkNumber)
52
self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
53
self.fp.write_string(networkname)
54
self.fp.write_stringlist(networknames)
55
self.fp.write_int32(len(addresses))
56
for address in addresses:
57
self.fp.write_address(address)
60
class NetworkByNameRequest(NetworkRequest):
62
action = constants.NSLCD_ACTION_NETWORK_BYNAME
64
def read_parameters(self):
65
self.name = self.fp.read_string()
68
return '(&%s(%s=%s))' % ( self.filter,
69
self.attmap_cn, ldap.filter.escape_filter_chars(self.name) )
72
class NetworkByAddressRequest(NetworkRequest):
74
action = constants.NSLCD_ACTION_NETWORK_BYADDR
76
def read_parameters(self):
77
self.address = self.fp.read_address()
80
return '(&%s(%s=%s))' % ( self.filter,
81
self.attmap_ipNetworkNumber,
82
ldap.filter.escape_filter_chars(self.address) )
85
class NetworkAllRequest(NetworkRequest):
87
action = constants.NSLCD_ACTION_NETWORK_ALL