예제 #1
0
def open_dbus_connection(bus='SESSION'):
    """Open a plain D-Bus connection

    :return: :class:`DBusConnection`
    """
    bus_addr = get_bus(bus)
    sock = socket.socket(family=socket.AF_UNIX)
    sock.connect(bus_addr)
    sock.sendall(b'\0' + make_auth_external())
    auth_parser = SASLParser()
    while not auth_parser.authenticated:
        auth_parser.feed(unwrap_read(sock.recv(1024)))
        if auth_parser.error:
            raise AuthenticationError(auth_parser.error)

    sock.sendall(BEGIN)

    conn = DBusConnection(sock)
    conn.parser.buf = auth_parser.buffer

    with DBusRouter(conn) as router:
        reply_body = Proxy(message_bus, router, timeout=10).Hello()
        conn.unique_name = reply_body[0]

    return conn
예제 #2
0
파일: asyncio.py 프로젝트: FloFaber/Sudoku
async def open_dbus_connection(bus='SESSION'):
    """Open a plain D-Bus connection

    :return: :class:`DBusConnection`
    """
    bus_addr = get_bus(bus)
    reader, writer = await asyncio.open_unix_connection(bus_addr)

    # Authentication flow
    writer.write(b'\0' + make_auth_external())
    await writer.drain()
    auth_parser = SASLParser()
    while not auth_parser.authenticated:
        b = await reader.read(1024)
        if not b:
            raise EOFError("Socket closed before authentication")
        auth_parser.feed(b)
        if auth_parser.error:
            raise AuthenticationError(auth_parser.error)

    writer.write(BEGIN)
    await writer.drain()
    # Authentication finished

    conn = DBusConnection(reader, writer)
    conn.parser.add_data(auth_parser.buffer)

    # Say *Hello* to the message bus - this must be the first message, and the
    # reply gives us our unique name.
    async with DBusRouter(conn) as router:
        reply_body = await asyncio.wait_for(
            Proxy(message_bus, router).Hello(), 10)
        conn.unique_name = reply_body[0]

    return conn
예제 #3
0
파일: trio.py 프로젝트: FloFaber/Sudoku
async def open_dbus_connection(bus='SESSION') -> DBusConnection:
    """Open a plain D-Bus connection

    :return: :class:`DBusConnection`
    """
    bus_addr = get_bus(bus)
    sock: trio.SocketStream = await trio.open_unix_socket(bus_addr)

    # Authentication flow
    await sock.send_all(b'\0' + make_auth_external())
    auth_parser = SASLParser()
    while not auth_parser.authenticated:
        b = await sock.receive_some()
        auth_parser.feed(b)
        if auth_parser.error:
            raise AuthenticationError(auth_parser.error)

    await sock.send_all(BEGIN)
    # Authentication finished

    conn = DBusConnection(sock)
    conn.parser.add_data(auth_parser.buffer)

    # Say *Hello* to the message bus - this must be the first message, and the
    # reply gives us our unique name.
    async with conn.router() as router:
        reply = await router.send_and_get_reply(message_bus.Hello())
        conn.unique_name = reply.body[0]

    return conn
예제 #4
0
def connect_and_authenticate(bus='SESSION'):
    bus_addr = get_bus(bus)
    sock = socket.socket(family=socket.AF_UNIX)
    sock.connect(bus_addr)
    sock.sendall(b'\0' + make_auth_external())
    auth_parser = SASLParser()
    while not auth_parser.authenticated:
        auth_parser.feed(sock.recv(1024))
        if auth_parser.error:
            raise AuthenticationError(auth_parser.error)

    sock.sendall(BEGIN)

    conn = DBusConnection(sock)
    conn.parser.buf = auth_parser.buffer
    return conn
예제 #5
0
파일: blocking.py 프로젝트: FloFaber/Sudoku
def open_dbus_connection(bus='SESSION') -> DBusConnection:
    """Connect to a D-Bus message bus"""
    bus_addr = get_bus(bus)
    sock = socket.socket(family=socket.AF_UNIX)
    sock.connect(bus_addr)
    sock.sendall(b'\0' + make_auth_external())
    auth_parser = SASLParser()
    while not auth_parser.authenticated:
        auth_parser.feed(unwrap_read(sock.recv(1024)))
        if auth_parser.error:
            raise AuthenticationError(auth_parser.error)

    sock.sendall(BEGIN)

    conn = DBusConnection(sock)
    conn.parser.add_data(auth_parser.buffer)
    return conn
예제 #6
0
파일: tornado.py 프로젝트: FloFaber/Sudoku
async def open_dbus_connection(bus='SESSION'):
    bus_addr = get_bus(bus)
    stream = IOStream(socket.socket(family=socket.AF_UNIX))
    await stream.connect(bus_addr)
    await stream.write(b'\0' + make_auth_external())

    auth_parser = SASLParser()
    while not auth_parser.authenticated:
        auth_parser.feed(await stream.read_bytes(1024, partial=True))
        if auth_parser.error:
            raise AuthenticationError(auth_parser.error)

    await stream.write(BEGIN)

    conn = DBusConnection(stream)

    with DBusRouter(conn) as router:
        reply_body = await wait_for(Proxy(message_bus, router).Hello(), 10)
        conn.unique_name = reply_body[0]

    return conn
예제 #7
0
 def connection_made(self, transport):
     self.transport = transport
     self.transport.write(b'\0' + make_auth_external())
예제 #8
0
def test_make_auth_external():
    b = auth.make_auth_external()
    assert b.startswith(b'AUTH EXTERNAL')
예제 #9
0
 def connected():
     self.stream.write(b'\0' + make_auth_external())
예제 #10
0
 def OnConnected(self):
     self.WriteBytes(b'\0' + make_auth_external())
     self.put_issuer("Connected to: %s:%s" % self.bus_addr)
     self.SetSockName("DBus proxy to signal server")
     self.SetTimeout(0)