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

« back to all changes in this revision

Viewing changes to pynslcd/tio.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
# tio.py - I/O functions
 
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 struct
 
22
import os
 
23
import socket
 
24
 
 
25
 
 
26
# definition for reading and writing INT32 values
 
27
_int32 = struct.Struct('i')
 
28
 
 
29
# FIXME: use something from config.py to determine the correct size
 
30
_uid_t = struct.Struct('i')
 
31
 
 
32
# FIXME: use something from config.py to determine the correct size
 
33
_gid_t = struct.Struct('i')
 
34
 
 
35
# FIXME: use something from config.py to determine the correct size
 
36
_struct_timeval = struct.Struct('ll')
 
37
 
 
38
class TIOStreamError(Exception):
 
39
    pass
 
40
 
 
41
class TIOStream(object):
 
42
    """File-like object that allows reading and writing nslcd-protocol
 
43
    entities."""
 
44
 
 
45
    def __init__(self, conn):
 
46
        conn.setblocking(1)
 
47
        conn.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, _struct_timeval.pack(0, 500000))
 
48
        conn.setsockopt(socket.SOL_SOCKET, socket.SO_SNDTIMEO, _struct_timeval.pack(60, 0))
 
49
        self.fp = os.fdopen(conn.fileno(), 'w+b', 1024*1024)
 
50
 
 
51
    def read(self, size):
 
52
        return self.fp.read(size)
 
53
 
 
54
    def read_int32(self):
 
55
        return _int32.unpack(self.read(_int32.size))[0]
 
56
 
 
57
    def read_uid_t(self):
 
58
        return _uid_t.unpack(self.read(_uid_t.size))[0]
 
59
 
 
60
    def read_gid_t(self):
 
61
        return _gid_t.unpack(self.read(_gid_t.size))[0]
 
62
 
 
63
    def read_string(self, maxsize=None):
 
64
        len = self.read_int32()
 
65
        if maxsize and len >= maxsize:
 
66
            raise TIOStreamError()
 
67
        return self.read(len)
 
68
 
 
69
    def read_address(self):
 
70
        """Read an address (usually IPv4 or IPv6) from the stream and return
 
71
        the address as a string representation."""
 
72
        af = self.read_int32()
 
73
        return socket.inet_ntop(af, self.read_string(maxsize=64))
 
74
 
 
75
    def write(self, value):
 
76
        self.fp.write(value)
 
77
 
 
78
    def write_int32(self, value):
 
79
        self.write(_int32.pack(value))
 
80
 
 
81
    def write_uid_t(self, value):
 
82
        self.write(_uid_t.pack(value))
 
83
 
 
84
    def write_gid_t(self, value):
 
85
        self.write(_gid_t.pack(value))
 
86
 
 
87
    def write_string(self, value):
 
88
        self.write_int32(len(value))
 
89
        self.write(value)
 
90
 
 
91
    def write_stringlist(self, value):
 
92
        lst = tuple(value)
 
93
        self.write_int32(len(lst))
 
94
        for string in lst:
 
95
            self.write_string(string)
 
96
 
 
97
    @staticmethod
 
98
    def _to_address(value):
 
99
        # try IPv4 first
 
100
        try:
 
101
            return socket.AF_INET, socket.inet_pton(socket.AF_INET, value)
 
102
        except socket.error:
 
103
            pass # try the next one
 
104
        # fall back to IPv6
 
105
        return socket.AF_INET6, socket.inet_pton(socket.AF_INET6, value)
 
106
 
 
107
    def write_address(self, value):
 
108
        """Write an address (usually IPv4 or IPv6) in a string representation
 
109
        to the stream."""
 
110
        # first try to make it into an IPv6 address
 
111
        af, address = TIOStream._to_address(value)
 
112
        self.write_int32(af)
 
113
        self.write_string(address)
 
114
 
 
115
    def close(self):
 
116
        try:
 
117
            self.fp.close()
 
118
        except IOError:
 
119
            pass
 
120
 
 
121
    def __del__(self):
 
122
        self.close()