Пример #1
0
    async def modify(self, entry, changes, controls=None):
        try:
            req = {
                'object': entry.encode(),
                'changes': encode_changes(changes)
            }
            br = {'modifyRequest': ModifyRequest(req)}
            msg = {'protocolOp': protocolOp(br)}
            if controls is not None:
                msg['controls'] = controls

            msg_id = await self.send_message(msg)
            results = await self.recv_message(msg_id)
            if isinstance(results[0], Exception):
                return False, results[0]

            for message in results:
                msg_type = message['protocolOp'].name
                message = message.native
                if msg_type == 'modifyResponse':
                    if message['protocolOp']['resultCode'] != 'success':
                        return False, Exception(
                            'Failed to add DN! LDAP error! Reason: %s Diag: %s'
                            % (message['protocolOp']['resultCode'],
                               message['protocolOp']['diagnosticMessage']))

            return True, None
        except Exception as e:
            return False, e
Пример #2
0
	async def modify(self, entry, changes, controls = None):
		"""
		Performs the modify operation.
		
		:param entry: The DN of the object whose attributes are to be modified
		:type entry: str
		:param changes: Describes the changes to be made on the object. Must be a dictionary of the following format: {'attribute': [('change_type', [value])]}
		:type changes: dict
		:param controls: additional controls to be passed in the query
		:type controls: List[class:`Control`] 
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)
		"""
		try:
			req = {
				'object' : entry.encode(),
				'changes' : encode_changes(changes)
			}
			br = { 'modifyRequest' : ModifyRequest(req)}
			msg = { 'protocolOp' : protocolOp(br)}
			if controls is not None:
				msg['controls'] = controls
			
			msg_id = await self.send_message(msg)
			results = await self.recv_message(msg_id)
			if isinstance(results[0], Exception):
				return False, results[0]
			
			for message in results:
				msg_type = message['protocolOp'].name
				message = message.native
				if msg_type == 'modifyResponse':
					if message['protocolOp']['resultCode'] != 'success':
						return False, LDAPModifyException(
							entry,
							message['protocolOp']['resultCode'],
							message['protocolOp']['diagnosticMessage']
						)

			return True, None
		except Exception as e:
			return False, e