Exemple #1
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
Exemple #2
0
 def write(self, dn, attributes, parameters):
     # get name
     name = common.get_rdn_value(dn, attmap['cn'])
     names = attributes['cn']
     if not names:
         print 'Error: entry %s does not contain %s value' % (dn, attmap['cn'])
     if 'cn' in parameters and parameters['cn'] not in names + [ name, ]:
         return # case of result entry did not match
     if not name:
         name = names.pop(0)
     elif name in names:
         names.remove(name)
     # get port number
     ( port, ) = attributes['ipServicePort']
     if not port:
         print 'Error: entry %s does not contain %s value' % (dn, attmap['ipServicePort'])
     port = int(port)
     # get protocol
     protocols = attributes['ipServiceProtocol']
     if 'ipServiceProtocol' in parameters:
         if parameters['ipServiceProtocol'] not in protocols:
             return
         protocols = ( parameters['ipServiceProtocol'], )
     # write result
     for protocol in protocols:
         self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
         self.fp.write_string(name)
         self.fp.write_stringlist(names)
         self.fp.write_int32(port)
         self.fp.write_string(protocol)
Exemple #3
0
 def write(self, dn, attributes, parameters):
     hostname = common.get_rdn_value(dn, attmap['cn'])
     hostnames = attributes['cn']
     if not hostnames:
         print 'Error: entry %s does not contain %s value' % ( dn, attmap['cn'] )
     if not hostname:
         hostname = hostnames.pop(0)
     elif hostname in hostnames:
         hostnames.remove(hostname)
     addresses = attributes['ipHostNumber']
     if not addresses:
         print 'Error: entry %s does not contain %s value' % ( dn, attmap['ipHostNumber'] )
     # write result
     self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
     self.fp.write_string(hostname)
     self.fp.write_stringlist(hostnames)
     self.fp.write_int32(len(addresses))
     for address in addresses:
         self.fp.write_address(address)
Exemple #4
0
 def write(self, dn, attributes, parameters):
     # get name
     name = common.get_rdn_value(dn, attmap['cn'])
     names = attributes['cn']
     if not names:
         print 'Error: entry %s does not contain %s value' % ( dn, attmap['cn'] )
     if 'cn' in parameters and parameters['cn'] not in names:
         return # case of result entry did not match
     if not name:
         name = names.pop(0)
     elif name in names:
         names.remove(name)
     # get number
     ( number, ) = attributes['oncRpcNumber']
     if not number:
         print 'Error: entry %s does not contain %s value' % ( dn, attmap['oncRpcNumber'])
     number = int(number)
     # write result
     self.fp.write_int32(constants.NSLCD_RESULT_BEGIN)
     self.fp.write_string(name)
     self.fp.write_stringlist(names)
     self.fp.write_int32(number)