Commit | Line | Data |
---|---|---|
b147e573 MW |
1 | #! /bin/sh |
2 | ||
3 | set -e | |
4 | ||
5 | ### This script performs the passive side of a dynamic association. It is | |
0f51cf5a MW |
6 | ### intended to be set as the forced command in an `.ssh/authorized_keys' |
7 | ### file. Specifically, for each dynamic peer, add a line to | |
8 | ### `.ssh/authorized_keys' of the form | |
b147e573 | 9 | ### |
0f51cf5a | 10 | ### environment="TRIPE_USER=PEER" ssh-rsa ... |
b147e573 MW |
11 | ### |
12 | ### There's an additional wrinkle. Suppose that the passive TrIPE endpoint | |
13 | ### is behind a NAT, and the SSH gateway is on a different machine. The | |
14 | ### gateway should have its own `tripe' user, and this script should again be | |
15 | ### its shell. On the gateway, add a `.ssh/authorized_keys' entry | |
16 | ### | |
0f51cf5a | 17 | ### environment="TRIPE_USER=tripe@SERVER:PEER" ssh-rsa ... |
b147e573 MW |
18 | ### |
19 | ### for the dynamic endpoint. On the passive endpoint itself, you need an | |
0f51cf5a MW |
20 | ### entry for the gateway's `tripe' user's key, with `TRIPE_GATEWAY' set to |
21 | ### any value, like | |
22 | ### | |
23 | ### environment="TRIPE_GATEWAY=t" ssh-rsa ... | |
24 | ### | |
25 | ### For backwards compatibility, it can also be set as the `tripe' user's | |
26 | ### shell, with the `[tripe@SERVER:]PEER' indicator set as the forced | |
27 | ### command. If there are no forced command or `TRIPE_*' environment | |
28 | ### variables then it is assumed that a gateway is calling. | |
b147e573 MW |
29 | |
30 | : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@} | |
31 | : ${bindir=@bindir@} | |
32 | : ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock} | |
33 | : ${tripectl=$bindir/tripectl} | |
34 | export TRIPEDIR TRIPESOCK | |
35 | ||
d3731285 | 36 | ## Make sure we're being called properly, and figure out the peer identity. |
0f51cf5a MW |
37 | case "${TRIPE_USER+t},${TRIPE_GATEWAY+t},$#,$1" in |
38 | t,,0,) set -- "$TRIPE_USER" ;; | |
39 | ,t,0,) set -- $SSH_ORIGINAL_COMMAND; unset SSH_ORIGINAL_COMMAND ;; | |
40 | ,,2,-c) ;; | |
d3731285 | 41 | *) |
0f51cf5a | 42 | echo >&2 "usage: $0 -c [SERVER:]PEER [ACTION]" |
d3731285 | 43 | exit 1 |
b147e573 | 44 | ;; |
d3731285 | 45 | esac |
b147e573 | 46 | |
d3731285 MW |
47 | ## Examine the peer identifier and work out how to proceed. |
48 | case "$#,$1" in | |
0f51cf5a | 49 | 0,*) echo >&2 "missing peer identifier"; exit 1 ;; |
d3731285 MW |
50 | *:*) mode=proxy server=${1%:*} user=${1##*:} ;; |
51 | *) mode=local user=$1 ;; | |
52 | esac | |
53 | shift | |
b147e573 | 54 | |
0f51cf5a | 55 | ## Fetch the optional command from where SSH stashed it. |
d3731285 MW |
56 | case "$#" in 0) set -- $SSH_ORIGINAL_COMMAND ;; esac |
57 | case "$#,$1" in | |
58 | 0, | 1,hello) act=hello ;; | |
59 | 1,goodbye) act=goodbye ;; | |
60 | *) echo >&2 "$0: unknown action spec \`$*'"; exit 1 ;; | |
61 | esac | |
62 | ||
63 | ## Now actually do something. | |
64 | case "$mode,$act" in | |
65 | proxy,*) | |
66 | exec ssh "$server" "$user" "$act" | |
67 | ;; | |
68 | local,hello) | |
69 | exec $tripectl SVCSUBMIT connect passive "$user" | |
70 | ;; | |
71 | local,goodbye) | |
72 | peer=$($tripectl SVCSUBMIT connect userpeer "$user") | |
73 | exec $tripectl KILL "$peer" | |
74 | ;; | |
b147e573 | 75 | *) |
d3731285 | 76 | echo >&2 "$0: unknown mode/action $mode/$act" |
b147e573 MW |
77 | exit 1 |
78 | ;; | |
b147e573 | 79 | esac |