4 socket2unix is a simple 'LD_PRELOAD' wrapper to ``convert'' network sockets to
5 UNIX sockets. Useful on remote systems with untrusted users (but trusted root)
6 to be able to launch a server which is accessible only by the user. Normal
7 sockets are usable by everyone on the system.
9 It works for both servers (`listen(3)`) and clients (`connect(3)`).
11 These UNIX sockets can also be forwarded over SSH with `socat` (see below).
18 - dynamic linker/loader which supports 'LD_PRELOAD' (e.g. GNU/Linux's or
25 ./configure && make && make check
27 Then either install the library with `make install` or just copy it from
28 `src/.libs/` to wherever you want to install it:
30 rm -f /destination/path/for/library/libsocket2unix.so
31 cp -L src/.libs/libsocket2unix.so /destination/path/for/library/
33 *Important:* Don't overwrite an existing `libsocket2unix.so` file which is in
34 use by any program or the program may crash. Instead remove the file first and
35 then copy the new version. This is not a bug in socket2unix, but a general
42 Set 'LD_PRELOAD' to include the _absolute_ path to `libsocket2unix.so`:
44 LD_PRELOAD=/absolute/path/to/libsocket2unix.so
46 The 'SOCKET2UNIX_PATH' environment variable must be set to the path of the
47 UNIX socket to use (client) or create (server). The IP version ("v4" or "v6")
48 and the port number (if applicable) is appended to create a unique path.
53 $ LD_PRELOAD=/path/to/libsocket2unix.so \
54 SOCKET2UNIX_PATH=`pwd`/test nc -l -p 5000
56 This creates two sockets named `socket-v4-5000` and `socket-v6-5000` in the
57 current directory. If the files already exist and are sockets, they are
58 overwritten. Other file types are not touched.
62 $ LD_PRELOAD=/path/to/libsocket2unix.so \
63 SOCKET2UNIX_PATH=`pwd`/test nc localhost 5000
65 `nc` connects to the server socket created above and both instances can talk
66 to each other without knowing they use an UNIX socket instead of a TCP
67 connection on port 5000.
70 The following additional environment variables are available:
72 - 'SOCKET2UNIX_DEBUG':
73 Control debug level. 1 = errors only, 2 = warnings only, 3 = debug messages.
75 - 'SOCKET2UNIX_OPTIONS':
76 Comma separated list of options for socket2unix. Valid options are (without
78 - 'client_only': Don't intercept calls to `listen()` and `accept()`.
79 - 'server_only': Don't intercept calls to `connect()`.
80 These options are useful if a program has both client and server
81 functionality but only one part should be redirected.
87 `socat` can be used to forward UNIX sockets over SSH. Thanks to [1] for the
90 [1]: http://www.debian-administration.org/users/dkg/weblog/68
92 `socat` is required on both local and remote system.
94 To forward the server socket `path/to/socket/remote` from `remote-host` to
95 `path/to/socket/local` on the local host run this command on the local system:
97 $ socat UNIX-LISTEN:path/to/socket/local,reuseaddr,fork \
98 EXEC:'ssh remote-host socat STDIO UNIX-CONNECT\:path/to/socket/remote'
100 Any program on the local host can then connect to `path/to/socket/local` and
101 the connection gets forwarded to `remote-host`.
103 To use the forwarding with socket2unix the sockets must be named appropriately
104 (see above). For example to use socket2unix on the client-side:
106 $ socat UNIX-LISTEN:socket-v4-4711,reuseaddr,fork ...
108 Connect to the forwarded socket:
110 $ LD_PRELOAD=/path/to/libsocket2unix.so \
111 SOCKET2UNIX_PATH=`pwd`/socket nc -4 localhost 3000
113 The same works for the remote socket.
119 If you find any bugs not mentioned in this document please report them to
120 <simon@ruderich.org> with socket2unix in the subject.
126 Written by Simon Ruderich <simon@ruderich.org>.
132 socket2unix is licensed under GPL version 3 or later.
134 Copyright (C) 2013 Simon Ruderich
136 This program is free software: you can redistribute it and/or modify
137 it under the terms of the GNU General Public License as published by
138 the Free Software Foundation, either version 3 of the License, or
139 (at your option) any later version.
141 This program is distributed in the hope that it will be useful,
142 but WITHOUT ANY WARRANTY; without even the implied warranty of
143 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144 GNU General Public License for more details.
146 You should have received a copy of the GNU General Public License
147 along with this program. If not, see <http://www.gnu.org/licenses/>.