[net.news.b] two "/usr/lib/new/active" lines for same news group

ado@elsie.UUCP (03/12/84)

Apologies if this has already been around the net.

Subject: more than one line for the same news group in "active"
Index:	2.10 inews.c

Description:
If
	1.  there's a line for a news group in "/usr/lib/news/active"
	2.  there's no corresponding directory in "/usr/spool/news" and
	3.  an article is posted to the news group
then a second line for the news group is added to the "active" file.

Repeat-by:
	ed - /usr/lib/news/active
	$a
	bogus 00000
	.
	w
	q
	echo "This is a test." | inews -t test -n bogus
	tail /usr/lib/news/active
and note the two lines for "bogus" at the end of the file.
Be sure to remove these lines, the inserted "bogus" article,
and the "/usr/spool/news/bogus" directory when the test is done.

Fix:
I'd best leave it to wiser heads.  I can, however, note where the challenge is.
The function "ngcheck" in "inews.c" includes these lines:

	/*
	 * If a user is trying to input to a non-existent group complain.
	 * First check to see if the newsgroup ever existed.  To do this, try
	 * to find the name in the "active" file.
	 */
	if (mode != CREATENG && !is_ctl) {
		/* Ick! Figure out if the newsgroup is in the active file. */
		sprintf(dir, "grep -s '^%s ' %s", ngname, ACTIVE);
		if ((system(dir) != 0))
			xerror("There is no such newsgroup as %s.", ngname);
		else {
			strcpy(dir, dirname(ngname));
			mknewsg(dir, ngname);
			return 0;
		}
	}

whilst the function "mknewsg" contains these lines at its start:

	mknewsg(fulldir, ngname)
	char	*fulldir;
	char	*ngname;
	{
		int	pid;
		register char *p;
		char sysbuf[200];
		char parent[200];
		struct stat sbuf;

		if (ngname == NULL || !isalpha(ngname[0]))
			xerror("Tried to make illegal newsgroup %s", ngname);

and these lines at the end:

		/* Update the "active newsgroup" file. */
		if (ngname && *ngname) {
			actfp = xfopen(ACTIVE, "a");
			fprintf(actfp, "%s 00000\n", ngname);
			fclose(actfp);
		}

In brief:  ngcheck determines that it should "make the news group" because its
name appears in the active file.  It calls "mknewsg" to do this.
"Mknewsg" proceeds to add the name to the file again (in the last lines
shown above).

Possible fixes:

1.  Have "ngcheck" always complain:
	if (mode != CREATENG && !is_ctl) {
		xerror("There is no such newsgroup as %s.", ngname);
	}

2.  Have "mknewsg" avoid adding an "active" line if "ngname" is NULL.  This
    involves changing the call in ngcheck to
		mknewsg(dir, (char *) NULL);
    and changing the
		if (ngname == NULL || !isalpha(ngname[0]))
			xerror("Tried to make illegal newsgroup %s", ngname);
    code in "mknewsg" to
		if (ngname != NULL && !isalpha(ngname[0]))
			xerror("Tried to make illegal newsgroup %s", ngname);

3.  Add a parameter to mknewsg (or a global variable) to control whether a
    line is added to the active file.

Take it away, gurus.
-- 
UUCP:	decvax!harpo!seismo!rlgvax!cvl!elsie!ado
DDD:	(301) 496-5688