🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nn
1 messages
1 total messages Started by James Vandevegt Tue, 05 Oct 1993 20:21
suggested inews mods w/ source!
#4933
Author: James Vandevegt
Date: Tue, 05 Oct 1993 20:21
616 lines
15422 bytes
The following is a printout of two files from
~nnsrcdir/inews, conf.h & inews.c.  I have added
some code to both programs, delimited by
the UNL comments.  This additional code allows
a new option for inews:  using the Yellow Pages
Default Domain Name as the "From:" machine instead
of the hostname from which inews was called.
This feature is useful in clustered environments
with a common, distributed mail system.

Read the lengthy comment inside conf.h for more
information.  I'm writing this about two weeks after
the modifications since I've been waiting to see if
any errors pop up and I wrote that explanation back when
the idea surfaced.

I'm posting these listing here with
the hope that they will be picked up and considered for
implementation by the maintainers of nn.

Scan for 'UNL' to pick out the main parts I've modified.

----Start conf.h
/*
 * Configuration file for nn version of nntp inews.  Written by
 * Steve Simmons (scs@lokkur.dexter.mi.us), Dec 19, 1989.  Placed
 * in the public domain by the author.  This file rationalizes
 * the stock NNTP release of inews with the definitions for NN.
 * The rationalization was done as of NN version 6.3.10 and NNTP
 * version 1.5.7.
 *
 * You must edit this file to reflect your local configuration
 * and environment.
 *
 * Follow the instructions given in the comments.  See the file
 * README for more comments.
 *
 * $RCSfile: conf.h,v $	$Revision: 1.1 $
 *
 * $Author: news $	$Date: 89/12/20 17:43:03 $
 *
 * $State: Exp $	$Locker:  $
 *
 * $Log:	conf.h,v $
 * Revision 1.1  89/12/20  17:43:03  news
 * Initial revision
 *
 * May 1st, 1990, Kim Storm
 * Modifications to get hostname for free (see README.NN)
 */

#ifndef	NNINEWSCONF_H
#define	NNINEWSCONF_H

#include	"config.h"

#ifndef NNTP
/* WHY DO YOU WANT TO MAKE MINI-INEWS WHEN YOU DONT USE NNTP */
#endif

/* UNL added feature
	If you would like inews to first try to get the name of
	the NIS domain (using yp_get_default_domain()), define
	GYPDNAME (Get YP Domain Name).  Items will be from
	user@YPDNAME, where YPDNAME is the character string
	returned by yp_get_default_domain().

	This is especially useful for clustered systems where
	users may be logged into several different machines
	and post from several different machines.  This method
	will make all users in the cluster appear, to the
	outside world, as a single machine with a common
	entry point for email.

	This upgrade in capabilities was requested by
	machine administrators at the Computing Resource
	Center at the University of Nebraska--Lincoln.
	The changes were made by J. VandeVegt.
	Address any queries to manager@unlinfo.unl.edu.

	Define DOMAIN and HIDDENNET as outlined below.  Their
	definitions will be used should the call to
	yp_get_default_domain() fail. 
*/

#define GYPDNAME
/* UNL end */

/*
 *  Define your local domain name.  You *must* define something, either
 *  here, in config.h, or elsewhere according to your local standards.
 *  See comment below on HIDDENNET.
 *
 *  You are not strictly *required* to have a domain name; nonetheless
 *  it's a good idea.  If you are on the Internet or otherwise have a
 *  valid domain name, use it (except see HIDDENNET below).  If you're
 *  a uucp-only site, use ".uucp" for now and go get a real name.
 *
 *  Note that if you imbed your domain name in the hostname and you don't
 *  use HIDDENNET, you may get a period on the end of your fully qualified
 *  domian name (FQDN) in postings.  In that case, use HIDDENNET and
 *  define DOMAIN to be your FQDN.
 */

#define	DOMAIN	"unl.edu" 

/*
 *  If you define this, the hostname will not appear in the posting
 *  data except on the path.  Items will be from user@DOMAIN (with
 *  DOMAIN as defined above).  If you don't want this, comment it out.
 */

/*#define	HIDDENNET /* */

/*
 *  There are a number of ways that inews will try to figure out the
 *  host name.  When used with nn, the definitions in ../config.h
 *  will specify this, so you don't have to do anything special here.
 */

/*
 *  If you don't have bcopy, the following define will make one...
 */

/* #define USG			/* */

/*
 *  You shouldn't need to touch anything below this line.
 */

/*
 *  This is the code needed to get the proper hostname.
 *
 *	nn provides a gethostname function for generic use.
 *	we fake uname() for inews.c using this:
 */

#define	uname(str) gethostname(str, sizeof(str))

/*
 *  Stock nntp inews and nn use some different #define names for the
 *  same general functions.  This synchronises them.
 */

#define	SERVER_FILE   "/crc/local/lib/nn/nntp_server"

/*
 *	Reverse engineering (nn got this the other way around)....
 */

#ifdef HAVE_STRCHR
#define	rindex strrchr
#define index strchr
#endif

#ifdef NO_BZERO
#ifndef USG
#define USG
#endif
#endif

/*
 *  Sanity checks (You know.  Checks you get from Sanity Claus)
 */

#ifdef	HIDDENNET
#ifndef	DOMAIN
YOU_BLEW_IT READ_THE_INSTRUCTIONS_AGAIN
#endif
#endif

#endif	/* of ifdef NNINEWSCONF_H */
-----end conf.h


-----begin inews.c
#ifndef lint
static char *sccsid = "@(#)inews.c	1.16	(Berkeley) 8/27/89";
#endif

/*
 * Itty-bitty inews for talking to remote server.
 * Simply accept input on stdin (or via a named file) and dump this
 * to the server; add a From: and Path: line if missing in the original.
 * Print meaningful errors from the server.
 * Limit .signature files to MAX_SIGNATURE lines.
 * No processing of command line options.
 *
 * Original by Steven Grady <grady@ucbvax.Berkeley.EDU>, with thanks from
 * Phil Lapsley <phil@ucbvax.berkeley.edu>
 * Send bug reports to Stan Barber <sob@bcm.tmc.edu>
 */

#include <stdio.h>
#include <pwd.h>
#include <ctype.h>
#include "conf.h"
#include "nntp.h"
#ifndef FOR_NN
#ifdef USG
#include <string.h>
#else not USG
#include <strings.h>
#endif not USG
#endif

#define	MAX_SIGNATURE	4

extern	FILE	*ser_wr_fp;

char	host_name[256];

main(argc, argv)
int	argc;
char	*argv[];
{
	char	line[NNTP_STRLEN], s[NNTP_STRLEN];
	int	seen_fromline, in_header, seen_header;
	int	response;
	char	*server;
	char	*getserverbyfile();
	register char	*cp;

	++argv;
	while (argc > 1)
		if (*argv[0] == '-') {
			++argv;
			--argc;
		} else
			break;

	if (argc > 1) {
		if (freopen(*argv, "r", stdin) == NULL) {
			perror(*argv);
			exit(1);
		}
	}

	uname(host_name);

	server = getserverbyfile(SERVER_FILE);
	if (server == NULL) {
		fprintf(stderr,
			"Can't get the name of the news server from %s.\n",
			SERVER_FILE);
		fprintf(stderr,
	       "Either fix this file, or put NNTPSERVER in your enviroment.\n");
		exit(1);
	}

	response = server_init(server);
	if (response < 0) {
		printf("Couldn't connect to %s news server, try again later.\n",
			server);
		exit(1);
	}

	if (handle_server_response(response, server) < 0
	    || response == OK_NOPOST) {
		close_server();
		exit(1);
	}

	put_server("POST");
	(void) get_server(line, sizeof(line));
	if (*line != CHAR_CONT) {
		if (atoi(line) == ERR_NOPOST) {
			close_server();
			fprintf(stderr,
				"Sorry, you can't post from this machine.\n");
			exit(1);
		} else {
			close_server();
		        fprintf(stderr, "Remote error: %s\n", line);
			exit(1);
		}
	}

	in_header = 1;
	seen_header = 0;
	seen_fromline = 0;

	while (gets(s) != NULL) {
		if (s[0] == '.')    /* Single . is eof, so put in extra one */
			(void) fputc('.', ser_wr_fp);
		if (in_header && strneql(s, "From:", sizeof("From:")-1)) {
	                seen_header = 1;
			seen_fromline = 1;
		}
		if (in_header && s[0] == '\0') {
	                if (seen_header) {
		                in_header = 0;
			        if (!seen_fromline)
				        gen_frompath();
			} else {
			        continue;
			}
		} else if (in_header) {
		        if (valid_header(s))
			        seen_header = 1;
	                else
                                continue;
		}
		fprintf(ser_wr_fp, "%s\r\n", s);
	}

	append_signature();

	fprintf(ser_wr_fp, ".\r\n");
	(void) fflush(ser_wr_fp);
	(void) get_server(line, sizeof(line));
	if (*line != CHAR_OK) {
		if (atoi(line) == ERR_POSTFAIL) {
			close_server();
			printf("Article not accepted by server; not posted.\n");
			for (cp = line + 4; *cp && *cp != '\r'; cp++)
				if (*cp == '\\')
					putchar('\n');
				else
					putchar(*cp);
			exit(1);
		} else {
			close_server();
			fprintf(stderr, "Remote error: %s\n", line);
			exit(1);
		}
	}

	/*
	 * Close server sends the server a
	 * "quit" command for us, which is why we don't send it.
	 */

	close_server();

	exit(0);
}

/*
 * append_signature -- append the person's .signature file if
 * they have one.  Limit .signature to MAX_SIGNATURE lines.
 * The rn-style DOTDIR environmental variable is used if present.
 */

append_signature()
{
	char	line[256], sigfile[256];
	char	*cp;
	struct	passwd	*passwd;
	FILE	*fp;
	char	*index(), *getenv();
	int	count = 0;
	char	*dotdir;

	passwd = getpwuid(getuid());
	if (passwd == NULL)
	  return;
#ifdef DO_DOTDIR
	if ((dotdir = getenv("DOTDIR")) == NULL)
#endif
	{
	  dotdir = passwd->pw_dir;
	}

	if (dotdir[0] == '~') {
	  (void) strcpy(sigfile, passwd->pw_dir);
	  (void) strcat(sigfile, &dotdir[1]);
	} else {
	  (void) strcpy(sigfile, dotdir);
	}
	(void) strcat(sigfile, "/");
	(void) strcat(sigfile, ".signature");

#ifdef DEBUG
  fprintf(stderr,"sigfile = '%s'\n", sigfile);
#endif

	fp = fopen(sigfile, "r");
	if (fp == NULL)
		return;

#ifdef DEBUG
  fprintf(stderr,"sigfile opened OK\n");
#endif

	fprintf(ser_wr_fp, "--\r\n");
	while (fgets(line, sizeof (line), fp)) {
		count++;
		if (count > MAX_SIGNATURE) {
			fprintf(stderr,
	      "Warning: .signature files should be no longer than %d lines.\n",
			MAX_SIGNATURE);
			fprintf(stderr,
			"(Only %d lines of your .signature were posted.)\n",
			MAX_SIGNATURE);
			break;
		}
		if (cp = index(line, '\n'))
			*cp = '\0';
		fprintf(ser_wr_fp, "%s\r\n", line);
	}
	(void) fclose(fp);
#ifdef DEBUG
	printf(".signature appended (from %s)\n", sigfile);
#endif
}


/*
 * gen_frompath -- generate From: and Path: lines, in the form
 *
 *	From: user@host.domain (full_name)
 *	Path: host!user
 *
 * This routine should only be called if the message doesn't have
 * a From: line in it.
 */

gen_frompath()
{
	char	*full_name;
	char	*cp;
	char *ypdn; /* UNL YP Domain Name */
	int ypflag; /* UNL YP flag */
	struct	passwd *passwd;
	char	*index(), *getenv();

#ifdef DEBUG
printf("gen_frompath() entered\n");
#endif
	passwd = getpwuid(getuid());

	full_name = getenv("NAME");
	if (full_name == NULL) {
		full_name = passwd->pw_gecos;
		if ((cp = index(full_name, ',')))
			*cp = '\0';
	}

/* UNL begin */
	/* If GYPDNAME is set, they extract the name of the NIS domain
		machine and use that machine in the From: line.

		If GYPNAME is not set, or if there is an error retrieving
		the NIS domain machine name, revert to using the
		DOMAIN and HIDDENNET variables
	*/

	ypflag= 0;
#ifdef GYPDNAME
	if (! yp_get_default_domain(&ypdn)) {
		fprintf(ser_wr_fp,"From: %s@%s (",passwd->pw_name,ypdn);
		ypflag= 1;
		}
#endif /* GYPDNAME */
/* UNL end */

	if (! ypflag) { /* UNL */
#ifdef DOMAIN
#ifdef HIDDENNET
		fprintf(ser_wr_fp, "From: %s@%s (",
			passwd->pw_name,
			DOMAIN);
#else /* HIDDENNET */

	/* A heuristic to see if we should tack on a domain */

	cp = index(host_name, '.');
	if (cp)
		fprintf(ser_wr_fp, "From: %s@%s (",
			passwd->pw_name,
			host_name);
	else
		fprintf(ser_wr_fp, "From: %s@%s.%s (",
			passwd->pw_name,
			host_name,
			DOMAIN);
#endif /* HIDDENNET */
#else
	fprintf(ser_wr_fp, "From: %s@%s (",
		passwd->pw_name,
		host_name);
#endif /* DOMAIN */

		} /* UNL */

	for (cp = full_name; *cp != '\0'; ++cp)
		if (*cp != '&')
			putc(*cp, ser_wr_fp);
		else {		/* Stupid & hack.  God damn it. */
			putc(toupper(passwd->pw_name[0]), ser_wr_fp);
			fprintf(ser_wr_fp, passwd->pw_name+1);
		}

	fprintf(ser_wr_fp, ")\r\n");

/* UNL begin */
#ifdef GYPDNAME
	if (ypflag) {
		fprintf(ser_wr_fp,"Path: %s!%s\r\n",ypdn,passwd->pw_name);
		}
#endif /* GYPDNAME */

	if (! ypflag) {
/* UNL end */

#ifdef HIDDENNET
	/* Only the login name - nntp server will add uucp name */
	fprintf(ser_wr_fp, "Path: %s\r\n", passwd->pw_name);
#else /* HIDDENNET */
	fprintf(ser_wr_fp, "Path: %s!%s\r\n", host_name, passwd->pw_name);
#endif /* HIDDENNET */

		} /* UNL */
}


/*
 * strneql -- determine if two strings are equal in the first n
 * characters, ignoring case.
 *
 *	Parameters:	"a" and "b" are the pointers
 *			to characters to be compared.
 *			"n" is the number of characters to compare.
 *
 *	Returns:	1 if the strings are equal, 0 otherwise.
 *
 *	Side effects:	None.
 */

strneql(a, b, n)
register char *a, *b;
int	n;
{
	char	lower();

	while (n && lower(*a) == lower(*b)) {
		if (*a == '\0')
			return (1);
		a++;
		b++;
		n--;
	}
	if (n)
		return (0);
	else
		return (1);
}

/*
 * lower -- convert a character to lower case, if it's
 *	upper case.
 *
 *	Parameters:	"c" is the character to be
 *			converted.
 *
 *	Returns:	"c" if the character is not
 *			upper case, otherwise the lower
 *			case eqivalent of "c".
 *
 *	Side effects:	None.
 */

char lower(c)
register char c;
{
	if (isascii(c) && isupper(c))
		c = c - 'A' + 'a';
	return(c);
}


/*
 * valid_header -- determine if a line is a valid header line
 *
 *	Parameters:	"h" is the header line to be checked.
 *
 *	Returns: 	1 if valid, 0 otherwise
 *
 *	Side Effects:	none
 *
 */

int valid_header(h)
register char *h;
{
  char *index();
  char *colon, *space;

  /*
   * blank or tab in first position implies this is a continuation header
   */
  if (h[0] == ' ' || h[0] == '\t')
    return (1);

  /*
   * just check for initial letter, colon, and space to make
   * sure we discard only invalid headers
   */
  colon = index(h, ':');
  space = index(h, ' ');
  if (isalpha(h[0]) && colon && space == colon + 1)
    return (1);

  /*
   * anything else is a bad header -- it should be ignored
   */
  return (0);
}
-----end inews.c
--
| James M. VandeVegt      | University of Nebraska--Lincoln          |
| vandevek@cse.unl.edu    | Computer Science and Engineering         |
--------------------------|==========================================|
| #include <disclaimer.h> |      Nothing But Net.                    |
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads