2
# alias.py - lookup functions for aliasnet addresses
4
# Copyright (C) 2010 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
28
class AliasRequest(common.Request):
30
filter = '(objectClass=nisMailAlias)'
33
attmap_rfc822MailMember = 'rfc822MailMember'
35
attributes = ( 'cn', 'rfc822MailMember' )
37
def write(self, entry):
38
dn, attributes = entry
39
# get name and check against requested name
40
names = attributes.get(self.attmap_cn, [])
42
logging.error('Error: entry %s does not contain %s value', dn, self.attmap_cn)
45
if self.name.lower() not in (x.lower() for x in names):
47
names = ( self.name, )
48
# get the members of the alias
49
members = attributes.get(self.attmap_rfc822MailMember, [])
51
logging.error('Error: entry %s does not contain %s value', dn, self.attmap_rfc822MailMember)
55
self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
56
self.fp.write_string(name)
57
self.fp.write_stringlist(members)
60
class AliasByNameRequest(AliasRequest):
62
action = constants.NSLCD_ACTION_ALIAS_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 AliasAllRequest(AliasRequest):
74
action = constants.NSLCD_ACTION_ALIAS_ALL