Пример #1
0
 def validate(self, parameters):
     """Check the username for validity and fill in the DN if needed."""
     # check username for validity
     common.validate_name(parameters['username'])
     # look up user DN
     entry = passwd.uid2entry(self.conn, parameters['username'])
     if not entry:
         # FIXME: we should close the stream with an empty response here
         raise ValueError('%r: user not found' % parameters['username'])
     # save the DN
     parameters['userdn'] = entry[0]
     # get the "real" username
     value = passwd.attmap.get_rdn_value(entry[0], 'uid')
     if not value:
         # get the username from the uid attribute
         values = entry[1]['uid']
         if not values or not values[0]:
             logging.warning('%s: is missing a %s attribute', entry[0],
                             passwd.attmap['uid'])
         value = values[0]
     # check the username
     if value and not common.is_valid_name(value):
         raise ValueError('%s: has invalid %s attribute', entry[0],
                          passwd.attmap['uid'])
     # check if the username is different and update it if needed
     if value != parameters['username']:
         logging.info('username changed from %r to %r',
                      parameters['username'], value)
         parameters['username'] = value
Пример #2
0
 def validate(self, parameters):
     """This method checks the provided username for validity and fills
     in the DN if needed."""
     # check username for validity
     common.validate_name(parameters['username'])
     # look up user DN
     entry = passwd.uid2entry(self.conn, parameters['username'])
     if not entry:
         # FIXME: we should close the stream with an empty response here
         raise ValueError('%r: user not found' % parameters['username'])
     # save the DN
     parameters['userdn'] = entry[0]
     # get the "real" username
     value = passwd.attmap.get_rdn_value(entry[0], 'uid')
     if not value:
         # get the username from the uid attribute
         values = entry[1]['uid']
         if not values or not values[0]:
             logging.warning('%s: is missing a %s attribute', entry[0], passwd.attmap['uid'])
         value = values[0]
     # check the username
     if value and not common.is_valid_name(value):
         raise ValueError('%s: has invalid %s attribute', entry[0], passwd.attmap['uid'])
     # check if the username is different and update it if needed
     if value != parameters['username']:
         logging.info('username changed from %r to %r', parameters['username'], value)
         parameters['username'] = value
Пример #3
0
 def validate_request(self, parameters):
     """This method checks the provided username for validity and fills
     in the DN if needed."""
     # check username for validity
     common.validate_name(parameters['username'])
     # look up user DN if not known
     if not parameters['userdn']:
         entry = passwd.uid2entry(self.conn, parameters['username'])
         if not entry:
             raise ValueError('%r: user not found' % parameters['username'])
         # save the DN
         parameters['userdn'] = entry[0]
         # get the "real" username
         value = common.get_rdn_value(entry[0], passwd.attmap['uid'])
         if not value:
             # get the username from the uid attribute
             values = myldap_get_values(entry, passwd.attmap['uid'])
             if not values or not values[0]:
                 logging.warn('%s: is missing a %s attribute', dn, passwd.attmap['uid'])
             value = values[0]
         # check the username
         if value and not common.isvalidname(value):
             raise ValueError('%s: has invalid %s attribute', dn, passwd.attmap['uid'])
         # check if the username is different and update it if needed
         if value != parameters['username']:
             logging.info('username changed from %r to %r', parameters['username'], value)
             parameters['username'] = value
Пример #4
0
 def mk_filter(self):
     # we still need a custom mk_filter because this is an | query
     if attmap['member'] and 'memberUid' in self.parameters:
         memberuid = self.parameters['memberUid']
         entry = passwd.uid2entry(self.conn, memberuid)
         if entry:
             return '(&%s(|(%s=%s)(%s=%s)))' % (
                 self.filter, attmap['memberUid'],
                 escape_filter_chars(memberuid), attmap['member'],
                 escape_filter_chars(entry[0]))
     return super(Search, self).mk_filter()
Пример #5
0
 def mk_filter(self):
     # we still need a custom mk_filter because this is an | query
     if attmap['member'] and 'memberUid' in self.parameters:
         memberuid = self.parameters['memberUid']
         entry = passwd.uid2entry(self.conn, memberuid)
         if entry:
             return '(&%s(|(%s=%s)(%s=%s)))' % (
                     self.filter,
                     attmap['memberUid'], escape_filter_chars(memberuid),
                     attmap['member'], escape_filter_chars(entry[0])
                 )
     return super(Search, self).mk_filter()