Commit | Line | Data |
---|---|---|
5e7f63f0 | 1 | #!/bin/bash |
33cc92a6 WD |
2 | # Send an error message via the rsync-protocol to a non-daemon client rsync. |
3 | # | |
4 | # Usage: deny-rsync "message" | |
5e7f63f0 MM |
5 | |
6 | protocol_version=29 | |
7 | exit_code=4 # same as a daemon that refuses an option | |
8 | ||
33cc92a6 | 9 | # e.g. byte_escape 29 => \035 |
5e7f63f0 | 10 | function byte_escape { |
33cc92a6 | 11 | echo -ne "\\0$(printf "%o" $1)" |
5e7f63f0 MM |
12 | } |
13 | ||
14 | msg="$1" | |
33cc92a6 WD |
15 | if [ "${#msg}" -gt 254 ]; then |
16 | # truncate a message that is too long for this naive script to handle | |
17 | msg="${msg:0:251}..." | |
5e7f63f0 | 18 | fi |
33cc92a6 | 19 | msglen=$(( ${#msg} + 1 )) # add 1 for the newline we append below |
5e7f63f0 MM |
20 | |
21 | # send protocol version | |
22 | echo -ne "$(byte_escape $protocol_version)\\000\\000\\000" | |
23 | ||
24 | # send checksum seed | |
25 | echo -ne "\\000\\000\\000\\000" | |
26 | ||
33cc92a6 | 27 | # the following is equivalent to rwrite(FERROR, "$msg\n") |
5e7f63f0 | 28 | # message header: length 17; MPLEX_BASE + code FERROR |
33cc92a6 | 29 | echo -ne "$(byte_escape $msglen)\\000\\000\\010" |
5e7f63f0 | 30 | # data |
33cc92a6 WD |
31 | echo -E "$msg" |
32 | ||
33 | # make sure the client gets the message and not a write error | |
34 | sleep 1 | |
5e7f63f0 MM |
35 | |
36 | exit $exit_code |