[news.admin] What really happened at gordon and a plea...

davido@gordon.UUCP (David Ornstein) (07/10/87)

Recently, gordon (my site) had a problem.  This problem was the result of
a bug in a news<-->mail gateway that I built for the VMS machines here.
Following is a description of how the system is supposed to work and what
the symptoms of the looping problem were (if you haven't seen them!)

Once I get the system running in a bug-free kind-o-way I'll post the 
whole thing for everyone.

Any help in determining the exact problem with the gateway would be 
appreciated as well as any general or specific suggestions about the
mechanism.

Here is the man page for the system that I have put together...

=========================================================================
                                                      newsmail(5)

             <PRELIMINARY - KNOWN BUGS - DON'T INSTALL THIS>

NAME
     newsmail - VMS Mail interface to USEnet

INTRODUCTION
     USENET (Users' Network) is a bulletin board shared among
     many computer systems around the world.  USENET is a logical
     network, sitting on top of several physical netwroks,
     including UUCP, BLICN, BERKNET, X.25 and the ARPANET.  Sites
     on USENET include many universities, private companies and
     research organizations.  Currently, there are over 75,000
     participants at over 2500 USENET sites in the USA, Canada,
     Europe, Japan and Korea with more joining literally every
     day.  Most are running the UNIX operating system.

     USENET is organized into a heirarchy of newsgroups each of
     which contains discussions about a various subject.  There
     are currently over 300 newsgroups that are generally distri-
     buted to every site on the net.  In addition, each site may
     have its own groups for discussions that should be held only
     within the company.  The subjects in the network-wide news-
     groups carry a great range of discussions centering around
     everything from the details of the latest security bug found
     in VMS to discussions about skiing to what happened last
     week on General Hospital.

     Because no single person is going to be interested in read-
     ing all of the articles in all of the newsgroups, it is pos-
     sible to limit your receipt of articles from USENET to only
     those articles that exist in specific groups in which you
     are interested.

DESCRIPTION
     There are many different ways to read news and the appropri-
     ate one really depends on your reading habits and personal
     preferences.  If you read a high volume of news each day, a
     dedicated news reading program (such as rn) probably makes
     sense.  rn is a sophisticated program that allows you to
     quickly and easily sift through a large number of articles
     with mechanisms like subject kill and others.  To use rn,
     you must log into the machine that is running the news
     software (GORDON) and use the program there.

     If, however, you read a reasonably small number of news-
     groups, a second option is now available to you: newsmail.

     newsmail is a set of capabilities that allow various users
     on a local network to have news articles from various groups
     be sent to them using standard mail facilities.  Each user
     declares which newsgroups they are interested in receiving
     and all new messages in those groups are automatically for-
     warded to them (via whatever mailing machinations are
     needed).

     Each message that is forwarded is received by the user on
     his or her home machine in the following format:

          From: <newsgroup_name>
          Subject: <Article subject>
          <blank line>
          <Article header lines>
          <Article body>

     This forging of the sender of the article allows the user to
     use the REPLY capability of his/her mail program to post
     reply articles.  For example, if an article is received in a
     group called comp.os.vms, the user would receive a message
     from a user named comp.os.vms (on the machine running the
     newsmail software - GORDON at Access). If the user replys to
     this message, the reply is caught by the machine in the net-
     work that runs the news software and the article is posted.
     As a natural side effect of this, you can post an article by
     simply sending mail to GORDON::groupname.

NEWSGROUPS
     At the end of this document is a listing of what newsgroups
     we are currently receiving.  There are a couple hundred more
     that we could be getting, but don't because of space on on
     GORDON's disk. If you are interested in the list, let me
     (David Ornstein) know and I'll send you a copy. Individual
     groups are pretty easy to turn on.

     As mentioned in the introduction, it is very easy to create
     company-wide newsgroups that will not be distributed outside
     of Access.  If you have ideas for these groups, let me know
     and we can try setting some of them up.

     If you are interested in trying out the news system via
     newsmail, let me know which groups you are interested in and
     I will turn them on for you.

IMPLEMENTATION
     The news forwarding system is built using fake system
     entries for users in the sys file for news. Each user has a
     line of the form:

          Musername:newsgroups::/usr/local/bin/forgemail %s user-
          name

     This causes the news software to send the article off (using
     the article's file location as the %s replacement operator)
     to the forgemail command.  This program (see source in
     /usr/src/local/forgemail) sets the uid to that of a trusted
     user and calls a script called mailart in /usr/local/bin.
     This script figures out what the subject and newsgroup of
     the article are and sends the message off to the given user,
     forging the from line to be the newsgroup name.

     Articles being sent to USEnet via mail (in reply to a mailed
     article or directly mailed) get sent to a script called
     rcvart in /usr/local/bin.  This forwarding is done in the
     aliases file in /usr/lib. There must be a line in this file
     for each newsgroup that is active for posting-via-mail to
     work correctly. The rcvart script takes the incoming article
     and figures out who it came from, what newsgroup it is to
     and posts the article using inews.

NEWSGROUP LIST
	
	[big list removed]

------------------------------------------------------------------

That's the man pages.

Now the problem.  As I best understand the problem, here's what happened:

	Somebody on one of the VMS machines mailed an article to soc.singles
		on gordon.

	The article was sent out to the net.

	I know that the From line was incorrectly: ...gordon!soc.singles.

	Somebody out there (bob@acornrc?) replied, via mail, to the
		posting.  This mail was sent to gordon!soc.singles.

	The newsmail system caught the article (via the mail aliases in the
		/usr/lib/aliases file).

	[some stuff]

	This mailed reply was posted.

	This posting was sent back in to the newsmail system and it sat
	reposting the article, tacking a news header on each time.

Now, my problem is:  I don't understand what [some stuff] is.  I would have
expected that the trapped article would have been sent to the rcvart script
and that the article would be posted.  I just don't understand how it got out
of news again.

Thanks for any help you can give...

==========================================================================


Here are the scripts and the source to forgemail.c:

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh.
# The following files will be created:
export PATH; PATH=/bin:$PATH

if test -f 'rcvart'
then
	echo shar: over-writing existing file "'rcvart'"
fi
echo extracting "'rcvart'"
cat << \SHAR_EOF > 'rcvart'
cat > /tmp/rcvart.$$
logfile=/usr/lib/news/newsmail/log
from=`grep "From " /tmp/rcvart.$$ | cut -d" " -f2`
grp=`grep "To:" /tmp/rcvart.$$ |/usr/local/bin/validgrp -d`
group=$grp
title=`grep "Subject:" /tmp/rcvart.$$ | cut -c10-`
cat /tmp/rcvart.$$ | awk -f /usr/local/bin/trimhdr.awk > /tmp/artbody.$$
/usr/lib/news/inews -n $group -f $from -t "$title" < /tmp/artbody.$$
rm /tmp/*.$$
echo -n "Article posted to $group by $from on " >> $logfile
date >> $logfile
SHAR_EOF
if test -f 'trimhdr.awk'
then
	echo shar: over-writing existing file "'trimhdr.awk'"
fi
echo extracting "'trimhdr.awk'"
cat << \SHAR_EOF > 'trimhdr.awk'
BEGIN {inhdrs = 1}
{
	if ($0 == "")
		inhdrs = 0;
	if (inhdrs != 1)
		print $0
}
SHAR_EOF
if test -f 'validgrp.c'
then
	echo shar: over-writing existing file "'validgrp.c'"
fi
echo extracting "'validgrp.c'"
cat << \SHAR_EOF > 'validgrp.c'
/* VALIDGRP.C */

/* This program operates as a filter on all of its arguments to determine
   what the first valid newsgroup listed is.  This is echoed to stdout.
*/

#include <stdio.h>
#include <ctype.h>

int	groups;
char	*glist[600];
char	grpbuf[30000];

char	*validName();

main(argc, argv)

int	argc;
char	*argv[];

{
	FILE	*actfile;
	FILE	*reject;
	char	*grpptr;
	char	linebuf[200];
	char	*testgrp[20];
	char	testbuf[1000];
	char	*testptr;
	char	*src;
	int	gcount;
	int	i;
	int	c;
	char	*newname;

	actfile = fopen("/usr/lib/news/active", "r");
	if (actfile == NULL)
		exit(1);

	if (strcmp(argv[1], "-d") == 0) {
		reject = fopen("/usr/lib/news/newsmail/rejectgrps", "a");
		if (reject == NULL)
			exit(1);
	} else
		reject = NULL;

	groups = 0;
	grpptr = grpbuf;
	while (fgets(linebuf, sizeof(linebuf) - 1, actfile) != NULL) {
		glist[groups++] = grpptr;
		src = linebuf;
		while (*src != ' ' && *src != '\0')
			*grpptr++ = *src++;
		*grpptr++ = '\0';
	}

	gcount = 0;
	testptr = testbuf;
	testgrp[gcount++] = testbuf;
	while((c = getchar()) != EOF) {
		if (c == ' ' || c == ',') {
			*testptr++ = '\0';
			testgrp[gcount++] = testptr;
		} else
			*testptr++ = (char)c;
	}
	*testptr++ = '\0';
			
	for (i = 0; i < gcount; i++)
		if ((newname = validName(testgrp[i])) != NULL) {
			printf("%s", newname);
			break;
		} else {
			if (reject != NULL)
				fprintf(reject, "%s\n", testgrp[i]);
		}

	fclose(actfile);
	if (reject != NULL)
		fclose(reject);
	if (i == argc)
		exit(1);
	else
		exit(0);
}

char	*validName(str)

char	*str;

{
	int	i;
	static char	ngname[200];
	char	wrkbuf[200];
	char	*s, *d;	

	if (strlen(str) == 0)
		return NULL;

	strcpy(ngname, str);

	/* Trim anything to the right of an '@' */

	s = ngname;
	d = wrkbuf;
	while (*s != '\0')
		if (*s == '@')
			break;
		else
			*d++ = *s++;
	*d++ = '\0';
	strcpy(ngname, wrkbuf);

	/* Get rid of punctuation except periods that aren't on the edge */

	s = ngname;
	d = wrkbuf;

	while (*s != '\0') {
		if (*s == '.' && s > ngname) {
			*d++ = *s++;
			continue;
		}
		if ((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') ||
			(*s >= '0' && *s <= '9'))
			*d++ = *s++;
		else
			s++;
	}
	*d++ = '\0';
	strcpy(ngname, wrkbuf);

	/* Search the group list */

	for (i = 0; i < groups; i++) {
		if (strlen(glist[i]) != 0) {
			if (icmp(ngname, glist[i]))
				return ngname;
		}
	}
	return NULL;
}
	
icmp(str1, str2)

char	*str1, *str2;

{
	int	len1 = strlen(str1);
	int	len2 = strlen(str2);
	int	i;
	
	if (len1 != len2)
		return 0;

	for (i = 0; i < len1; i++)
		if (str1[i] != str2[i])
			return 0;

	return 1;
}

SHAR_EOF
if test -f 'mailart'
then
	echo shar: over-writing existing file "'mailart'"
fi
echo extracting "'mailart'"
cat << \SHAR_EOF > 'mailart'
grep Subject: $1 > /tmp/mailart.$$
echo "" >> /tmp/mailart.$$
grep -v Subject: $1 >> /tmp/mailart.$$
from=`grep Newsgroups: $1|cut -c13-|cut -d, -f1`
/usr/lib/sendmail -f $from $2 < /tmp/mailart.$$
rm /tmp/mailart.$$

SHAR_EOF
if test -f 'forgemail.c'
then
	echo shar: over-writing existing file "'forgemail.c'"
fi
echo extracting "'forgemail.c'"
cat << \SHAR_EOF > 'forgemail.c'
/* FORGEMAIL.C */

/* This program takes a file and mails it to a specific user, forging
	the from entry based on the Newsgroups: line inthe file.

	Usage: forgemail article to
*/

#include <stdio.h>


main(argc, argv)

int	argc;
char	**argv;

{
	char cmdbuf[200];
	int x;

	/* Do a setuid to uucp's user id	*/

	x = setreuid(4,4);

	/* Build the command buffer	*/

	sprintf(cmdbuf, "/usr/local/bin/mailart %s %s",
		argv[1], argv[2]);

	system(cmdbuf);
}

SHAR_EOF
#	End of shell archive
exit 0
-- 
-----------------------------------------------------------------------------
David Ornstein		"Never join a religion that has a water slide."

Internet:	davido@gordon.uucp
UUCP:		{mit-eddie|seismo}!mirror!gordon!davido
	     or {harvard|ames|decvax|husc6}!necntc!davido
US Snail:	Access Technology, 6 Pleasant St, Natck MA 01760
-----------------------------------------------------------------------------