chiark / gitweb /
configure.ac: Some random formatting tweaks.
[tripe] / contrib / knock.in
CommitLineData
b147e573
MW
1#! /bin/sh
2
3set -e
4
5### This script performs the passive side of a dynamic association. It is
6### intended to be set as the `tripe' user's shell, and invoked via ssh(1).
7### Specifically, for each dynamic peer, add a line to `.ssh/authorized_keys'
8### of the form
9###
10### command="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### command="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 no command.
21
22: ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
23: ${bindir=@bindir@}
24: ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
25: ${tripectl=$bindir/tripectl}
26export TRIPEDIR TRIPESOCK
27
d3731285
MW
28## Make sure we're being called properly, and figure out the peer identity.
29case "$#,$1" in
30 2,-c) ;;
31 *)
32 echo >&2 "usage: $0 -c '[SERVER:]PEER [hello|goodbye]'"
33 exit 1
b147e573 34 ;;
d3731285 35esac
b147e573 36
d3731285
MW
37## SSH has smushed all of our arguments together, so let's split them apart
38## again.
39set -- $2
40
41## Examine the peer identifier and work out how to proceed.
42case "$#,$1" in
43 0,*) echo >&2 "$0: missing peer identifier"; exit 1 ;;
44 *:*) mode=proxy server=${1%:*} user=${1##*:} ;;
45 *) mode=local user=$1 ;;
46esac
47shift
b147e573 48
d3731285
MW
49## If there's no action then check to see whether SSH has hidden one
50## somewhere. Make sure the command looks sensible.
51case "$#" in 0) set -- $SSH_ORIGINAL_COMMAND ;; esac
52case "$#,$1" in
53 0, | 1,hello) act=hello ;;
54 1,goodbye) act=goodbye ;;
55 *) echo >&2 "$0: unknown action spec \`$*'"; exit 1 ;;
56esac
57
58## Now actually do something.
59case "$mode,$act" in
60 proxy,*)
61 exec ssh "$server" "$user" "$act"
62 ;;
63 local,hello)
64 exec $tripectl SVCSUBMIT connect passive "$user"
65 ;;
66 local,goodbye)
67 peer=$($tripectl SVCSUBMIT connect userpeer "$user")
68 exec $tripectl KILL "$peer"
69 ;;
b147e573 70 *)
d3731285 71 echo >&2 "$0: unknown mode/action $mode/$act"
b147e573
MW
72 exit 1
73 ;;
b147e573 74esac