2
# netgroup.py - lookup functions for netgroups
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
28
_netgroup_triple_re = re.compile(r'^\s*\(\s*(?P<host>.*)\s*,\s*(?P<user>.*)\s*,\s*(?P<domain>.*)\s*\)\s*$')
31
attmap = common.Attributes(cn='cn',
32
nisNetgroupTriple='nisNetgroupTriple',
33
memberNisNetgroup='memberNisNetgroup')
34
filter = '(objectClass=nisNetgroup)'
37
class NetgroupRequest(common.Request):
39
def write(self, dn, attributes, parameters):
40
# get names and check against requested user name
41
names = attributes['cn']
42
if 'cn' in parameters:
43
if parameters['cn'] not in names:
45
names = ( parameters['cn'], )
47
print 'Error: entry %s does not contain %s value' % (dn, attmap['cn'])
48
# write the netgroup triples
49
for triple in attributes['nisNetgroupTriple']:
50
m = _netgroup_triple_re.match(triple)
52
print 'Warning: entry %s contains invalid %s value: %r' % ( dn, attmap['nisNetgroupTriple'], triple)
54
self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
55
self.fp.write_int32(constants.NSLCD_NETGROUP_TYPE_TRIPLE)
56
self.fp.write_string(m.group('host'))
57
self.fp.write_string(m.group('user'))
58
self.fp.write_string(m.group('domain'))
59
# write netgroup members
60
for member in attributes['memberNisNetgroup']:
61
self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
62
self.fp.write_int32(constants.NSLCD_NETGROUP_TYPE_NETGROUP)
63
self.fp.write_string(member)
66
class NetgroupByNameRequest(NetgroupRequest):
68
action = constants.NSLCD_ACTION_NETGROUP_BYNAME
70
def read_parameters(self, fp):
71
return dict(cn=fp.read_string())