def _GetSocketCredentials(path):
    """Connect to a Unix socket and return remote credentials.

  """
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    try:
        sock.settimeout(10)
        sock.connect(path)
        return netutils.GetSocketCredentials(sock)
    finally:
        sock.close()
Beispiel #2
0
    def handle_accept(self):
        """Accept a new client connection.

    Creates a new instance of the handler class, which will use asyncore to
    serve the client.

    """
        accept_result = utils.IgnoreSignals(self.accept)
        if accept_result is not None:
            connected_socket, client_address = accept_result
            if self.family == socket.AF_UNIX:
                # override the client address, as for unix sockets nothing meaningful
                # is passed in from accept anyway
                client_address = netutils.GetSocketCredentials(
                    connected_socket)
            logging.info(
                "Accepted connection from %s",
                netutils.FormatAddress(client_address, family=self.family))
            self.handle_connection(connected_socket, client_address)