chiark / gitweb /
server/tripe.h: Don't say `struct bulkcrypto' where we don't have to.
[tripe] / contrib / knock.in
1 #! /bin/sh
2
3 set -e
4
5 ### This script performs the passive side of a dynamic association.  It is
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
9 ###
10 ###     environment="TRIPE_USER=PEER" ssh-rsa ...
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 ###
17 ###     environment="TRIPE_USER=tripe@SERVER:PEER" ssh-rsa ...
18 ###
19 ### for the dynamic endpoint.  On the passive endpoint itself, you need an
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.
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
36 ## Make sure we're being called properly, and figure out the peer identity.
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) ;;
41   *)
42     echo >&2 "usage: $0 -c [SERVER:]PEER [ACTION]"
43     exit 1
44     ;;
45 esac
46
47 ## Examine the peer identifier and work out how to proceed.
48 case "$#,$1" in
49   0,*) echo >&2 "missing peer identifier"; exit 1 ;;
50   *:*) mode=proxy server=${1%:*} user=${1##*:} ;;
51   *) mode=local user=$1 ;;
52 esac
53 shift
54
55 ## Fetch the optional command from where SSH stashed it.
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     ;;
75   *)
76     echo >&2 "$0: unknown mode/action $mode/$act"
77     exit 1
78     ;;
79 esac