def __call__(self): try: self.server_conn.address = platform.original_addr(self.client_conn.connection) except Exception as e: raise exceptions.ProtocolException("Transparent mode failure: %s" % repr(e)) layer = self.ctx.next_layer(self) try: layer() finally: if self.server_conn.connected(): self.disconnect()
def __call__(self): try: self.set_server(platform.original_addr(self.client_conn.connection)) except Exception as e: raise exceptions.ProtocolException("Transparent mode failure: %s" % repr(e)) layer = self.ctx.next_layer(self) try: layer() finally: if self.server_conn.connected(): self.disconnect()
def _handle_event(self, event: events.Event) -> layer.CommandGenerator[None]: assert platform.original_addr is not None socket = yield commands.GetSocket(self.context.client) try: self.context.server.address = platform.original_addr(socket) except Exception as e: yield commands.Log(f"Transparent mode failure: {e!r}") self.child_layer = layer.NextLayer(self.context) yield from self.finish_start()
def handle_authentication_request(self, data): _logger.debug('Got auth response packet: %s' % repr(data)) password = parse_password_from_authentication_packet(data) self.target_backend = platform.original_addr(self.socket)[0] captured_uri = 'postgres://%(user)s:%(password)s@%(host)s:5432/%(database)s' % { 'user': self.options.get('user', b'').decode('utf-8'), 'password': password.decode('utf-8'), 'host': self.target_backend, 'database': self.options.get('database', b'').decode('utf-8'), } _logger.info('Intercepted auth: %s' % captured_uri) if self.connect_to_actual_backend(password): # Switch socket to non-blocking to enable messages to pass in # arbitrary order self.socket.setblocking(0) else: return False return True