chiark / gitweb /
101a461f7c1e52be2f1487be03a6061787e8d288
[chiark-utils.git] / fishdescriptor / py / fishdescriptor / fish.py
1 # python 3 only
2
3 import socket
4 import subprocess
5
6 class Donor():
7     def __init__(s):
8         pass
9
10     def _ancilmsg(fds):
11         '''
12             use Socket;
13             use Socket::MsgHdr;
14             my $fds = pack "i*", @ARGV;
15             my $m = Socket::MsgHdr::pack_cmsghdr SOL_SOCKET, SCM_RIGHTS, $fds;
16             print join ", ", unpack "C*", $m
17         '''
18
19 def _geteuid(pid):
20     def _shuffle_fd3():
21         dup(1,3)
22         dup(2,1)
23     sp = subprocess.Popen(preexec_fn = _suffle_fd3,
24           stdin = subprocess.DEVNULL, stdout = subprocess.PIPE,
25           close_fds = False,
26           args = ['gdb', '-p', pid, '-batch', '-ex'
27                   'python import os; os.fdopen(30,"w").write("%d\n" % '
28                   +'gdb.parse_and_eval("(uid_t)geteuid()"))'])
29     (output, dummy) = sp.communicate()
30     
31 2009
32
33 def fish(pid, fds):
34     # -> list of fds in our process
35     sockname = '/run/user/' + 
36     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
37
38 def deliver(pid, fds, path):
39     gdb -batch -p %d -ex '