Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/pynslcd/host.py
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2011-05-01 21:08:39 +0200
committerArthur de Jong <arthur@arthurdejong.org>2011-05-01 21:08:39 +0200
commit4c19151250e318fa38dac33e5db1397b9d95a43e (patch)
treef177c2225f49ff5bb1b126663b3c734f63d7773e /pynslcd/host.py
parentb4fa5371a770e8ba90a8d0ccd62ddabea0124fd5 (diff)
implement attribute mapping functionality and do some refactoring
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1454 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'pynslcd/host.py')
-rw-r--r--pynslcd/host.py32
1 files changed, 11 insertions, 21 deletions
diff --git a/pynslcd/host.py b/pynslcd/host.py
index b8c86d0..5fcbc31 100644
--- a/pynslcd/host.py
+++ b/pynslcd/host.py
@@ -18,33 +18,30 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
-import ldap.filter
+import logging
import constants
import common
-class HostRequest(common.Request):
-
- filter = '(objectClass=ipHost)'
+attmap = common.Attributes(cn='cn', ipHostNumber='ipHostNumber')
+filter = '(objectClass=ipHost)'
- attmap_cn = 'cn'
- attmap_ipHostNumber = 'ipHostNumber'
- attributes = ( 'cn', 'ipHostNumber' )
+class HostRequest(common.Request):
def write(self, dn, attributes):
- hostname = common.get_rdn_value(dn, self.attmap_cn)
- hostnames = attributes.get(self.attmap_cn, [])
+ hostname = common.get_rdn_value(dn, attmap['cn'])
+ hostnames = attributes['cn']
if not hostnames:
- print 'Error: entry %s does not contain %s value' % ( dn, self.attmap_cn )
+ print 'Error: entry %s does not contain %s value' % ( dn, attmap['cn'] )
if not hostname:
hostname = hostnames.pop(0)
elif hostname in hostnames:
hostnames.remove(hostname)
- addresses = attributes.get(self.attmap_ipHostNumber, [])
+ addresses = attributes['ipHostNumber']
if not addresses:
- print 'Error: entry %s does not contain %s value' % ( dn, self.attmap_ipHostNumber )
+ print 'Error: entry %s does not contain %s value' % ( dn, attmap['ipHostNumber'] )
# write result
self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
self.fp.write_string(hostname)
@@ -57,27 +54,20 @@ class HostRequest(common.Request):
class HostByNameRequest(HostRequest):
action = constants.NSLCD_ACTION_HOST_BYNAME
+ filter_attrs = dict(cn='name')
def read_parameters(self):
self.name = self.fp.read_string()
- def mk_filter(self):
- return '(&%s(%s=%s))' % ( self.filter,
- self.attmap_cn, ldap.filter.escape_filter_chars(self.name) )
-
class HostByAddressRequest(HostRequest):
action = constants.NSLCD_ACTION_HOST_BYADDR
+ filter_attrs = dict(ipHostNumber='address')
def read_parameters(self):
self.address = self.fp.read_address()
- def mk_filter(self):
- return '(&%s(%s=%s))' % ( self.filter,
- self.attmap_ipHostNumber,
- ldap.filter.escape_filter_chars(self.address) )
-
class HostAllRequest(HostRequest):