The deny-rsync script from bug 3945.
[rsync/rsync.git] / support / deny-rsync
CommitLineData
5e7f63f0
MM
1#!/bin/bash
2# deny-rsync [message]: send an rsync-protocol error message
3
4protocol_version=29
5exit_code=4 # same as a daemon that refuses an option
6
7# byte_escape 29 ==> \035
8function byte_escape {
9 octbyte="000$(bc <<<"obase=8; $1")"
10 echo -n "\\${octbyte: -3}"
11}
12
13msg="$1"
14if [ "${#msg}" -gt 255 ]; then
15 # message is too long for this naive script to handle
16 msg="${msg:0:252}..."
17fi
18
19# send protocol version
20echo -ne "$(byte_escape $protocol_version)\\000\\000\\000"
21
22# send checksum seed
23echo -ne "\\000\\000\\000\\000"
24
25# the following is equivalent to rwrite(FERROR, $msg)
26# message header: length 17; MPLEX_BASE + code FERROR
27echo -ne "$(byte_escape ${#msg})\\000\\000\\010"
28# data
29echo -n "$msg"
30
31exit $exit_code