~ubuntu-branches/ubuntu/precise/nss-pam-ldapd/precise-security

« back to all changes in this revision

Viewing changes to pynslcd/group.py

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2011-09-04 21:00:00 UTC
  • mfrom: (14.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20110904210000-pe3u91iga88vtr16
Tags: 0.8.4
* Upload to unstable
* switch to using the member attribute by default instead of
  uniqueMember (backwards incompatible change)
* only return "x" as a password hash when the object has the shadowAccount
  objectClass and nsswitch.conf is configured to do shadow lookups using
  LDAP (this avoids some problems with pam_unix)
* fix problem with partial attribute name matches in DN (thanks Timothy
  White)
* fix a problem with objectSid mappings with recent versions of OpenLDAP
  (patch by Wesley Mason)
* set the socket timeout in a connection callback to avoid timeout
  issues during the SSL handshake (patch by Stefan Völkel)
* check for unknown variables in pam_authz_search
* only check password expiration when authenticating, only check account
  expiration when doing authorisation
* make buffer sizes consistent and grow all buffers holding string
  representations of numbers to be able to hold 64-bit numbers
* update AX_PTHREAD from autoconf-archive
* support querying DNS SRV records from a different domain than the current
  one (based on a patch by James M. Leddy)
* fix a problem with uninitialised memory while parsing the tls_ciphers
  option (closes: #638872) (but doesn't work yet due to #640384)
* implement bounds checking of numeric values read from LDAP (patch by
  Jakub Hrozek)
* correctly support large uid and gid values from LDAP (patch by Jakub
  Hrozek)
* improvements to the configure script (patch by Jakub Hrozek)
* switch to dh for debian/rules and bump debhelper compatibility to 8
* build Debian packages with multiarch support
* ship shlibs (but still no symbol files) for libnss-ldapd since that was
  the easiest way to support multiarch
* fix output in init script when restarting nslcd (closes: #637132)
* correctly handle leading and trailing spaces in preseeded debconf uri
  option (patch by Andreas B. Mundt) (closes: #637863)
* support spaces around database names in /etc/nsswitch.conf while
  configuring package (closes: #640185)
* updated Russian debconf translation by Yuri Kozlov (closes: #637751)
* updated French debconf translation by Christian Perrier (closes: #637756)
* added Slovak debconf translation by Slavko (closes: #637759)
* updated Danish debconf translation by Joe Hansen (closes :#637763)
* updated Brazilian Portuguese debconf translation by Denis Doria
* updated Portuguese debconf translation by Américo Monteiro
* updated Japanese debconf translation by Kenshi Muto (closes: #638195)
* updated Czech debconf translation by Miroslav Kure (closes: #639026)
* updated German debconf translation by Chris Leick (closes: #639107)
* updated Spanish debconf translation by Francisco Javier Cuadrado
  (closes: #639236)
* updated Dutch debconf translation by Arthur de Jong with help from Paul
  Gevers and Jeroen Schot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# group.py - group entry lookup routines
 
3
#
 
4
# Copyright (C) 2010, 2011 Arthur de Jong
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
19
# 02110-1301 USA
 
20
 
 
21
import logging
 
22
import ldap.filter
 
23
 
 
24
import constants
 
25
import common
 
26
from passwd import dn2uid, uid2dn
 
27
 
 
28
 
 
29
def clean(lst):
 
30
    if lst:
 
31
        for i in lst:
 
32
            yield i.replace('\0', '')
 
33
 
 
34
 
 
35
attmap = common.Attributes(cn='cn',
 
36
                           userPassword='"*"',
 
37
                           gidNumber='gidNumber',
 
38
                           memberUid='memberUid',
 
39
                           member='member')
 
40
filter = '(|(objectClass=posixGroup)(objectClass=groupOfNames))'
 
41
 
 
42
 
 
43
class GroupRequest(common.Request):
 
44
 
 
45
    wantmembers = True
 
46
 
 
47
    def write(self, dn, attributes, parameters):
 
48
        # get group names and check against requested group name
 
49
        names = attributes['cn']
 
50
        if 'cn' in parameters:
 
51
            if parameters['cn'] not in names:
 
52
                return
 
53
            names = ( parameters['cn'], )
 
54
        # get group group password
 
55
        passwd = attributes['userPassword'][0]
 
56
        # get group id(s)
 
57
        gids = (  parameters['gidNumber'], ) if 'gidNumber' in parameters else attributes['gidNumber']
 
58
        gids = [ int(x) for x in gids ]
 
59
        # build member list
 
60
        members = set()
 
61
        if self.wantmembers:
 
62
            # add the memberUid values
 
63
            for member in clean(attributes['memberUid']):
 
64
                if common.isvalidname(member):
 
65
                    members.add(member)
 
66
            # translate and add the member values
 
67
            for memberdn in clean(attributes['member']):
 
68
                member = dn2uid(self.conn, memberdn)
 
69
                if member and common.isvalidname(member):
 
70
                    members.add(member)
 
71
        # actually return the results
 
72
        for name in names:
 
73
            if not common.isvalidname(name):
 
74
                print 'Warning: group entry %s contains invalid group name: "%s"' % ( dn, name )
 
75
            else:
 
76
                for gid in gids:
 
77
                    self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
 
78
                    self.fp.write_string(name)
 
79
                    self.fp.write_string(passwd)
 
80
                    self.fp.write_gid_t(gid)
 
81
                    self.fp.write_stringlist(members)
 
82
 
 
83
 
 
84
class GroupByNameRequest(GroupRequest):
 
85
 
 
86
    action = constants.NSLCD_ACTION_GROUP_BYNAME
 
87
 
 
88
    def read_parameters(self, fp):
 
89
        name = fp.read_string()
 
90
        common.validate_name(name)
 
91
        return dict(cn=name)
 
92
 
 
93
 
 
94
class GroupByGidRequest(GroupRequest):
 
95
 
 
96
    action = constants.NSLCD_ACTION_GROUP_BYGID
 
97
 
 
98
    def read_parameters(self, fp):
 
99
        return dict(gidNumber=fp.read_gid_t())
 
100
 
 
101
 
 
102
class GroupByMemberRequest(GroupRequest):
 
103
 
 
104
    action = constants.NSLCD_ACTION_GROUP_BYMEMBER
 
105
    wantmembers = False
 
106
 
 
107
    def __init__(self, *args, **kwargs):
 
108
        super(GroupByMemberRequest, self).__init__(*args, **kwargs)
 
109
        # set up our own attributes that leave out membership attributes
 
110
        self.attmap = common.Attributes(attmap)
 
111
        del self.attmap['memberUid']
 
112
        del self.attmap['member']
 
113
 
 
114
    def read_parameters(self, fp):
 
115
        memberuid = fp.read_string()
 
116
        common.validate_name(memberuid)
 
117
        return dict(memberUid=memberuid)
 
118
 
 
119
    def attributes(self):
 
120
        return self.attmap.attributes()
 
121
 
 
122
    def mk_filter(self, parameters):
 
123
        # we still need a custom mk_filter because this is an | query
 
124
        memberuid = parameters['memberUid']
 
125
        if attmap['member']:
 
126
            dn = uid2dn(self.conn, memberuid)
 
127
            if dn:
 
128
                return '(&%s(|(%s=%s)(%s=%s)))' % ( self.filter,
 
129
                          attmap['memberUid'], ldap.filter.escape_filter_chars(memberuid),
 
130
                          attmap['member'], ldap.filter.escape_filter_chars(dn) )
 
131
        return '(&%s(%s=%s))' % ( self.filter,
 
132
                  attmap['memberUid'], ldap.filter.escape_filter_chars(memberuid) )
 
133
 
 
134
 
 
135
class GroupAllRequest(GroupRequest):
 
136
 
 
137
    action = constants.NSLCD_ACTION_GROUP_ALL