1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#!!!BASH!!
#
# This script is invoked by snntpd in response to the POST command.
# Basically it forwards any cancel requests, and invokes snsend on
# the others. It augments snsend by checking for newsgroups for
# which posting is not permitted. This script's simple-minded idea
# of access control is determined by the presence or absence of the
# .nopost file in the newsgroup directories. Obviously there's a lot
# of flexibility if you want to do more sophisticated access control.
#
# Invocation environment:
# Article to be posted will be available on descriptor 0.
# $NEWSGROUPS will always contain a non-empty space-separated list
# of newsgroups to which the article is posted.
# If the article is a control message, $CONTROL will be set to the
# value of the Control field.
# $TCPREMOTEIP and $TCPLOCALIP will be set to the posting client's IP
# and the local server IP, if invoked from the network.
# Current directory will always be the appropriate sn spool
# directory, $SNROOT if set, otherwise !!SNROOT!!.
# PATH will always contain !!BINDIR!!.
# The exit status gets translated into the NNTP response code;
# the output (if any) becomes the text of the NNTP response.
#
fail () { echo "$@"; exit 9; }
#
# Is it a control message? Notify owner and let her verify the
# request. I won't make auto-cancellation the default.
# If you don't want control messages identified, remove or comment
# out the next if ... fi block.
#
if [ "x$CONTROL" != x ]; then
parse () { CANCEL=`echo $1 |tr 'A-Z' 'a-z'`; MSGID=$2; }
parse $CONTROL
[ "x$CANCEL" = xcancel ] || fail "I only do \"cancel\" messages"
tmp="/tmp/.POST.$$"
trap 'rm -f $tmp $tmp.1' 0
sncat -i "$MSGID" |sed -e 's/
//' -e '/^$/q' >$tmp
[ -s $tmp ] || fail "I can't find \"$MSGID\""
set -e
{ echo "This is an automated message, don't reply."
echo; echo "I received this cancel request:"; echo
sed -e 's/
//' -e 's/^/> /'
echo; echo "It refers to this article (headers only):"; echo
sed 's/^/> /' $tmp
echo "You can cancel it with \"!!BINDIR!!/sncancel -i '$MSGID'\""
} >$tmp.1
mail -s "Cancellation request" ${NEWSMASTER:-${LOGNAME:-!!DEFAULT_ADMIN_EMAIL!!}} <$tmp.1 ||
fail "Unable to forward your request"
echo "Your request will be considered"
exit 0
fi
#
# Is a normal posting.
#
postable=
exists=
for ng in $NEWSGROUPS; do
mentioned=x$mentioned
# Is it a newsgroup we have?
[ -f $ng/.created ] || continue
exists=x$exists
# .nopost files "belong" to us; we alone control group post access
[ -f $ng/.nopost ] && continue
[ "x$postable" = x ] || postable="$postable,"
postable="$postable$ng"
done
[ "$exists" ] || fail "I don't have any of those newsgroups"
[ "x$postable" = x ] && fail "Posting not allowed to those newsgroups"
{
echo "X-sn-Newsgroups: $postable"
test -r /etc/news/organization && \
echo Organization: `/bin/cat /etc/news/organization`
# VERIFIED_SENDER is inherited from the authenticating script that
# invoked snntpd, if any.
[ "x$VERIFIED_SENDER" = x ] || echo "Sender: $VERIFIED_SENDER"
cat
} |snsend -v || fail "Unable to post"
echo "Posted to $postable"
: Success
|