~ubuntu-branches/ubuntu/trusty/nss-pam-ldapd/trusty-proposed

« back to all changes in this revision

Viewing changes to pynslcd/network.py

  • Committer: Bazaar Package Importer
  • Author(s): Arthur de Jong
  • Date: 2011-03-10 22:00:00 UTC
  • mto: (14.1.5 experimental) (16.1.6)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20110310220000-tyhxifj2ovpxnqqm
Tags: 0.8.1
* SECURITY FIX: the PAM module will allow authentication for users that do
                not exist in LDAP, this allows login to local users with an
                incorrect password (CVE-2011-0438)
                the explotability of the problem depends on the details of
                the PAM stack and the use of the minimum_uid PAM option
* add FreeBSD support, partially imported from the FreeBSD port (thanks to
  Jacques Vidrine, Artem Kazakov and Alexander V. Chernikov)
* document how to replace name pam_check_service_attr and
  pam_check_host_attr options in PADL's pam_ldap with with pam_authz_search
  in nss-pam-ldapd (closes: #610925)
* implement a fqdn variable that can be used in pam_authz_search filters
* create the directory to hold the socket and pidfile on startup
* implement host, network and netgroup support in pynslcd

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# network.py - lookup functions for network names and addresses
 
3
#
 
4
# Copyright (C) 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 constants
 
22
import common
 
23
 
 
24
import struct
 
25
import ldap.filter
 
26
import socket
 
27
 
 
28
 
 
29
class NetworkRequest(common.Request):
 
30
 
 
31
    filter = '(objectClass=ipNetwork)'
 
32
 
 
33
    attmap_cn           = 'cn'
 
34
    attmap_ipNetworkNumber = 'ipNetworkNumber'
 
35
 
 
36
    attributes = ( 'cn', 'ipNetworkNumber' )
 
37
 
 
38
    def write(self, entry):
 
39
        dn, attributes = entry
 
40
        networkname = common.get_rdn_value(entry, self.attmap_cn)
 
41
        networknames = attributes.get(self.attmap_cn, [])
 
42
        if not networknames:
 
43
            print 'Error: entry %s does not contain %s value' % ( dn, self.attmap_cn)
 
44
        if not networkname:
 
45
            networkname = networknames.pop(0)
 
46
        else:
 
47
            networknames.remove(networkname)
 
48
        addresses = attributes.get(self.attmap_ipNetworkNumber, [])
 
49
        if not addresses:
 
50
            print 'Error: entry %s does not contain %s value' % ( dn, self.attmap_ipNetworkNumber)
 
51
        # write result
 
52
        self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
 
53
        self.fp.write_string(networkname)
 
54
        self.fp.write_stringlist(networknames)
 
55
        self.fp.write_int32(len(addresses))
 
56
        for address in addresses:
 
57
            self.fp.write_address(address)
 
58
 
 
59
 
 
60
class NetworkByNameRequest(NetworkRequest):
 
61
 
 
62
    action = constants.NSLCD_ACTION_NETWORK_BYNAME
 
63
 
 
64
    def read_parameters(self):
 
65
        self.name = self.fp.read_string()
 
66
 
 
67
    def mk_filter(self):
 
68
        return '(&%s(%s=%s))' % ( self.filter,
 
69
                  self.attmap_cn, ldap.filter.escape_filter_chars(self.name) )
 
70
 
 
71
 
 
72
class NetworkByAddressRequest(NetworkRequest):
 
73
 
 
74
    action = constants.NSLCD_ACTION_NETWORK_BYADDR
 
75
 
 
76
    def read_parameters(self):
 
77
        self.address = self.fp.read_address()
 
78
 
 
79
    def mk_filter(self):
 
80
        return '(&%s(%s=%s))' % ( self.filter,
 
81
                  self.attmap_ipNetworkNumber,
 
82
                  ldap.filter.escape_filter_chars(self.address) )
 
83
 
 
84
 
 
85
class NetworkAllRequest(NetworkRequest):
 
86
 
 
87
    action = constants.NSLCD_ACTION_NETWORK_ALL