Parsers for RFC 5536 message headers and RFC 8315 Cancel-Lock and Cancel-Key header fields.
The canlock-hp package contains standalone header parsers that can be
used to implement RFC 8315 Netnews Cancel-Locks on the receiving
(server) side.
They are intended as preprocessors for canlock, the command line
frontend of libcanlock, but are
independent programs.
canlock-mhp (Message Header Parser) is intended to process RFC 5536 Netnews articles and can be used to extract and unfold a single header field.
canlock-hfp (Header Field Parser) is intended to process RFC 8315 header fields ("Cancel-Lock" and "Cancel-Key").
See README for details.
This script "check.sh" for POSIX operating systems expects
the pathname of the article with the Keys ("Cancel-Key"
header field) as the first option.
The second option must be the pathname of the article with the Locks
("Cancel-Lock" header field).
Both articles must be in canonical format (with CRLF line breaks).
#! /bin/sh
set -e
# Check options
if test $# -ne 2
then
printf "%s\n%s\n" "Usage example: check.sh supersede.txt target.txt" \
"(Both articles must be in canonical format)"
exit 1
fi
# Check for utilities to be installed
canlock-mhp -v >/dev/null
canlock-hfp -v >/dev/null
canlock -v >/dev/null
# Extract Keys and Locks using canlock-hp
C_KEYS=$(<$1 canlock-mhp -f "Cancel-Key" | canlock-hfp 2>/dev/null)
printf "Keys : %s\n" "$C_KEYS" 1>&2
C_LOCKS=$(<$2 canlock-mhp -f "Cancel-Lock" | canlock-hfp 2>/dev/null)
printf "Locks: %s\n" "$C_LOCKS" 1>&2
# Check Keys against Locks using (lib)canlock
RES=1
for k in $C_KEYS
do
# Do not check with zero length Keys (treat as mismatch)
if test $(printf "%s" "$k" | tail -c 1 ) = ":"
then
RES=1
printf "\n%s\n" "Zero length Key \"$k\"" 1>&2
printf "%s\n" "=> Not checked" 1>&2
continue
fi
for l in $C_LOCKS
do
printf "\n%s\n" "Check Key \"$k\" against Lock \"$l\"" 1>&2
set +e
canlock -c "$k","$l" >/dev/null 2>&1
RES=$?
set -e
if test $RES -eq 0
then
printf "%s\n" "=> Good" 1>&2
break
else
printf "%s\n" "=> Mismatch" 1>&2
fi
done
# On success abort outer loop too
if test $RES -eq 0
then
break
fi
done
# Check for error
if test $RES -ne 0
then
exit 1
fi
# EOF