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