/usr/bin/libertine-session-bridge is in libertine-tools 1.0.0+16.04.20160411-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | #!/usr/bin/python3
import libertine.utils
import os
import select
import signal
import sys
from socket import *
def accept_new_connection():
newconn = container_dbus_session_sock.accept()[0]
descriptors.append(newconn)
host_dbus_session_sock = socket(AF_UNIX, SOCK_STREAM)
host_dbus_session_sock.connect(host_dbus_session_addr)
descriptors.append(host_dbus_session_sock)
socket_pairs.append([newconn, host_dbus_session_sock])
def get_socket_pair(socket):
for i in range(len(socket_pairs)):
if socket in socket_pairs[i]:
return socket_pairs[i]
def get_socket_partner(socket):
socket_pair = get_socket_pair(socket)
for i in range(len(socket_pair)):
if socket != socket_pair[i]:
return socket_pair[i]
def close_connections(remove_socket):
partner_socket = get_socket_partner(remove_socket)
socket_pair = get_socket_pair(remove_socket)
socket_pairs.remove(socket_pair)
descriptors.remove(remove_socket)
remove_socket.shutdown(SHUT_RDWR)
remove_socket.close()
descriptors.remove(partner_socket)
partner_socket.shutdown(SHUT_RDWR)
partner_socket.close()
def close_all_connections():
for i, j in socket_pairs:
i.shutdown(SHUT_RDWR)
i.close()
j.shutdown(SHUT_RDWR)
j.close()
def get_host_dbus_socket():
socket_key = "DBUS_SESSION_BUS_ADDRESS=unix:abstract="
with open(os.path.join(libertine.utils.get_user_runtime_dir(), 'dbus-session'), 'r') as fd:
dbus_session_str = fd.read()
fd.close()
host_dbus_socket = dbus_session_str.partition(socket_key)[2]
host_dbus_socket = host_dbus_socket.rstrip('\n')
host_dbus_socket = "\0%s" % host_dbus_socket
return host_dbus_socket
def socket_cleanup(signum, frame):
container_dbus_session_sock.close()
close_all_connections()
os.remove(dbus_session_socket_path)
def main_loop():
signal.signal(signal.SIGTERM, socket_cleanup)
signal.signal(signal.SIGINT, socket_cleanup)
while 1:
try:
rlist, wlist, elist = select.select(descriptors, [], [])
except InterruptedError:
continue
except:
break
for sock in rlist:
if sock.fileno() == -1:
continue
if sock == container_dbus_session_sock:
accept_new_connection()
else:
data = sock.recv(4096)
if len(data) == 0:
close_connections(sock)
continue
send_sock = get_socket_partner(sock)
if send_sock.fileno() < 0:
continue
totalsent = 0
while totalsent < len(data):
sent = send_sock.send(data)
if sent == 0:
close_connections(sock)
break
totalsent = totalsent + sent
dbus_session_socket_path = sys.argv[1]
container_dbus_session_sock = socket(AF_UNIX, SOCK_STREAM)
container_dbus_session_sock.bind(dbus_session_socket_path)
container_dbus_session_sock.listen(5)
host_dbus_session_addr = get_host_dbus_socket()
descriptors = [container_dbus_session_sock]
socket_pairs = []
main_loop()
|