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

« back to all changes in this revision

Viewing changes to pynslcd/passwd.py

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2011-12-31 13:30:00 UTC
  • Revision ID: package-import@ubuntu.com-20111231133000-c2lpa27xp5s6q481
Tags: 0.8.5
* support larger gecos values (closes: #640781)
* updated Swedish debconf translation by Martin Bagge (closes: #640623)
* consistently handle whitespace in configuration file during package
  configuration (thanks Nick) (closes: #641619)
* add a versioned dependency on libpam0g to ensure the PAM libraries are
  multiarch-aware
* in debconf, treat the "hard" value for tls_reqcert as if it was "demand"
  (closes: #642347)
* reduce loglevel of user not found messages to avoid spamming the logs
  with useless information (thanks Wakko Warner) (closes: #641820)
* other logging improvements
* keep nslcd running during package upgrades (closes: #644892)
* explicitly parse numbers as base 10 (thanks Jakub Hrozek)
* implement FreeBSD group membership NSS function (thanks Tom Judge)
* fix an issue where changes in /etc/nsswitch.conf were not correctly
  picked up and could lead to lookups being disabled on upgrade
  (closes: #645599)
* fix an issue with detecting the uid of the calling process and log
  denied shadow requests in debug mode
* fix a typo in the disconnect logic code (thanks Martin Poole)
* enable hardening options during build
* implement configuration file handling in pynslcd and other pynslcd
  improvements (pynslcd is not in a Debian package yet)
* update debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
                           loginShell='loginShell',
35
35
                           objectClass='objectClass')
36
36
filter = '(objectClass=posixAccount)'
37
 
bases = ( 'ou=people,dc=test,dc=tld', )
 
37
 
 
38
 
 
39
class Search(common.Search):
 
40
 
 
41
    case_sensitive = ('uid', 'uidNumber', )
 
42
    limit_attributes = ('uid', 'uidNumber', )
 
43
    required = ('uid', 'uidNumber', 'gidNumber', 'gecos', 'homeDirectory',
 
44
                'loginShell')
38
45
 
39
46
 
40
47
class PasswdRequest(common.Request):
41
48
 
42
49
    def write(self, dn, attributes, parameters):
43
 
        # get uid attribute and check against requested user name
 
50
        # get values
44
51
        names = attributes['uid']
45
 
        if 'uid' in parameters:
46
 
            if parameters['uid'] not in names:
47
 
                return
48
 
            names = ( parameters['uid'], )
49
 
        # get user password entry
50
52
        if 'shadowAccount' in attributes['objectClass']:
51
53
            passwd = 'x'
52
54
        else:
53
55
            passwd = attributes['userPassword'][0]
54
 
        # get numeric user and group ids
55
 
        uids = ( parameters['uidNumber'], ) if 'uidNumber' in parameters else attributes['uidNumber']
56
 
        uids = [ int(x) for x in uids ]
57
 
        # get other passwd properties
 
56
        uids = [int(x) for x in attributes['uidNumber']]
58
57
        gid = int(attributes['gidNumber'][0])
59
58
        gecos = attributes['gecos'][0]
60
59
        home = attributes['homeDirectory'][0]
62
61
        # write results
63
62
        for name in names:
64
63
            if not common.isvalidname(name):
65
 
                print 'Warning: passwd entry %s contains invalid user name: "%s"' % ( dn, name )
 
64
                print '%s: %s: denied by validnames option' % (dn, attmap['uid'])
66
65
            else:
67
66
                for uid in uids:
68
67
                    self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
98
97
    action = constants.NSLCD_ACTION_PASSWD_ALL
99
98
 
100
99
 
101
 
# FIXME: have something in common that does this
102
 
def do_search(conn, flt=None, base=None):
103
 
    mybases = ( base, ) if base else bases
104
 
    flt = flt or filter
105
 
    import cfg
106
 
    # perform a search for each search base
107
 
    for base in mybases:
108
 
        # do the LDAP search
109
 
        try:
110
 
            scope = locals().get('scope', cfg.scope)
111
 
            res = conn.search_s(base, scope, flt, [attmap['uid']])
112
 
            for entry in res:
113
 
                if entry[0]:
114
 
                    yield entry
115
 
        except ldap.NO_SUCH_OBJECT:
116
 
            # FIXME: log message
117
 
            pass
118
 
 
119
100
def uid2entry(conn, uid):
120
101
    """Look up the user by uid and return the LDAP entry or None if the user
121
102
    was not found."""
122
 
    myfilter = '(&%s(%s=%s))' % ( filter,
123
 
                  attmap['uid'], ldap.filter.escape_filter_chars(uid) )
124
 
    for dn, attributes in do_search(conn, myfilter):
125
 
        if uid in attributes[attmap['uid']]:
126
 
            return dn, attributes
 
103
    for dn, attributes in Search(conn, parameters=dict(uid=uid)):
 
104
        return dn, attributes
 
105
 
127
106
 
128
107
def uid2dn(conn, uid):
129
108
    """Look up the user by uid and return the DN or None if the user was
134
113
 
135
114
# FIXME: use cache of dn2uid and try to use DN to get uid attribute
136
115
 
 
116
 
137
117
def dn2uid(conn, dn):
138
118
    """Look up the user by dn and return a uid or None if the user was
139
119
    not found."""
140
 
    try:
141
 
        for dn, attributes in do_search(conn, base=dn):
142
 
            return attributes[attmap['uid']][0]
143
 
    except ldap.NO_SUCH_OBJECT:
144
 
        return None
 
120
    for dn, attributes in Search(conn, base=dn):
 
121
        return attributes['uid'][0]