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

« back to all changes in this revision

Viewing changes to pynslcd/network.py

  • Committer: Bazaar Package Importer
  • Author(s): Arthur de Jong
  • Date: 2011-05-13 15:00:00 UTC
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20110513150000-evnhjevo5rr17tyw
Tags: 0.8.3
* support using the objectSid attribute to provide numeric user and group
  ids, based on a patch by Wesley Mason
* check shadow account and password expiry properties (similarly to what
  pam_unix does) in the PAM handling code
* implement attribute mapping functionality in pynslcd
* relax default for validnames option to allow user names of only two
  characters (closes: #620235)
* make user and group name validation errors a little more informative
* small portability improvements
* general code improvements and refactoring in pynslcd
* some simplifications in the protocol between the PAM module and nslcd
  (without actual protocol changes so far)
* fix debconf LDAP search base suggestion when domain has more than two
  parts (patch by Per Carlson) (closes: #626571)
* search for LDAP server by looking for SRV _ldap._tcp DNS records and
  try to query LDAP server for base DN during package configuration
  (based on work by Petter Reinholdtsen for the sssd package)
* upgrade to standards-version 3.9.2 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
19
# 02110-1301 USA
20
20
 
 
21
import logging
 
22
 
21
23
import constants
22
24
import common
23
25
 
24
 
import struct
25
 
import ldap.filter
26
 
import socket
 
26
 
 
27
attmap = common.Attributes(cn='cn',
 
28
                           ipNetworkNumber='ipNetworkNumber')
 
29
filter = '(objectClass=ipNetwork)'
27
30
 
28
31
 
29
32
class NetworkRequest(common.Request):
30
33
 
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, [])
 
34
    def write(self, dn, attributes, parameters):
 
35
        networkname = common.get_rdn_value(dn, attmap['cn'])
 
36
        networknames = attributes['cn']
42
37
        if not networknames:
43
 
            print 'Error: entry %s does not contain %s value' % ( dn, self.attmap_cn)
 
38
            print 'Error: entry %s does not contain %s value' % (dn, attmap['cn'])
44
39
        if not networkname:
45
40
            networkname = networknames.pop(0)
46
41
        elif networkname in networknames:
47
42
            networknames.remove(networkname)
48
 
        addresses = attributes.get(self.attmap_ipNetworkNumber, [])
 
43
        addresses = attributes['ipNetworkNumber']
49
44
        if not addresses:
50
 
            print 'Error: entry %s does not contain %s value' % ( dn, self.attmap_ipNetworkNumber)
 
45
            print 'Error: entry %s does not contain %s value' % (dn, attmap['ipNetworkNumber'])
51
46
        # write result
52
47
        self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
53
48
        self.fp.write_string(networkname)
61
56
 
62
57
    action = constants.NSLCD_ACTION_NETWORK_BYNAME
63
58
 
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) )
 
59
    def read_parameters(self, fp):
 
60
        return dict(cn=fp.read_string())
70
61
 
71
62
 
72
63
class NetworkByAddressRequest(NetworkRequest):
73
64
 
74
65
    action = constants.NSLCD_ACTION_NETWORK_BYADDR
75
66
 
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) )
 
67
    def read_parameters(self, fp):
 
68
        return dict(ipNetworkNumber=fp.read_address())
83
69
 
84
70
 
85
71
class NetworkAllRequest(NetworkRequest):