🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #28203

PERL calling back to INN [was Re: risk of UNIX postings being misidentified as spam?]

#28203
From: Ed Mooring
Date: Sat, 16 May 1998 00:00
181 lines
5933 bytes
I rounded up enough tuits to let perl call back into INN for the
features I outlined. It's been running for a few thousand trials in my
production server, so I guess it's time to unleash it on the world. The
patch that follows is against inn-1.7.2.innsync-1.1d as archived on
jeremy@exit109.com's web site.

I have provided no documentation as yet, so this sketch will have to do
for you doughty beta testers:

There are four perl subs available from the perl subroutines called
from within INN:

INN::havehist(messageid)  # returns true if messageid is in the history db
INN::newsgroup(newsgroup) # returns the status of the news group (the last
	                  # field of the active file, or false if the
			  # isn't in your active file
INN::cancel(messageid)    # cancels messageid on your server

INN::addhist(messageid, arrivaltime,articletime,expiretime,paths)
			  # adds messageid to the history database
			  # all the other fields are optional.
			  # the time fields default to the current
			  # time, and the paths field defaults to
			  # the empty string.

Passing garbage messageid's _will_ crash INN. This patch has no
sanity checking on content or length of messageid's. I await field
reports to determine whether such checking is necessary.

Here's the patch:

*** ../inn-1.7.2.insync-1.1d/innd/innd.c	Mon Dec  8 15:48:50 1997
--- innd/innd.c	Fri May 15 16:25:47 1998
***************
*** 937,942 ****
--- 937,943 ----
  #if defined(DO_PERL)
      /* Load the Perl code */
      PERLsetup(_PATH_PERL_STARTUP_INND, _PATH_PERL_FILTER_INND, "filter_art");
+     PERLinndAPIinit();
      PerlFilter (TRUE) ;
  #endif /* defined(DO_PERL) */
   
*** ../inn-1.7.2.insync-1.1d/innd/cc.c	Fri Dec 12 08:58:54 1997
--- innd/cc.c	Fri May 15 23:13:03 1998
***************
*** 1868,1870 ****
--- 1868,1994 ----
      CCclose();
      CCsetup();
  }
+ 
+ /*
+  * The beginnings of a perl interface to the INN command set.
+  * I chose to put it in this file to avoid having to rewrite any code,
+  * and to avoid having to change the visibility of any of the functions
+  * in this module.
+  * -- Ed Mooring (mooring@acm.org) May 14, 1998
+  */
+ 
+ #if defined(DO_PERL)
+ 
+ #include "EXTERN.h"
+ #include "perl.h"
+ #include "XSUB.h"
+ 
+ 
+ XS(XS_INN_havehist)
+ {
+     dXSARGS;
+     char*	msgid;
+ 
+     if (items != 1)
+         croak("Usage: INN::havehist(msgid)");
+ 
+     msgid = (char *)SvPV(ST(0),na);
+     HIShavearticle(msgid) ? XSRETURN_YES : XSRETURN_NO;
+ }
+ 
+ XS(XS_INN_cancel)
+ {
+     dXSARGS;
+     char*	msgid;
+     char*	parambuf[2];
+ 
+     if (items != 1)
+         croak("Usage: INN::cancel(msgid)");
+ 
+     msgid = (char *)SvPV(ST(0),na);
+     parambuf[0]=msgid;
+     parambuf[1]= 0;
+     /* CCcancel returns NULL on success, hence reversed return codes */
+     CCcancel(parambuf) ? XSRETURN_NO : XSRETURN_YES;
+ }
+ 
+ XS(XS_INN_addhist)
+ {
+     dXSARGS;
+     char*	msgid;
+     char*	arrivaltime;
+     char*	articletime;
+     char*	expiretime;
+     char*	articlepaths = "";
+     char	tbuff[12];
+     char*	parambuf[6];
+ 
+     if (items < 1 || items > 5)
+ 	croak("Usage INN::addhist(msgid,[arrivaltime,articletime,expiretime,paths])");
+ 
+ 
+     /* we will always have a message id */
+     msgid = (char *)SvPV(ST(0),na);
+ 
+     /* set up sensible defaults for the time values */
+     sprintf(tbuff, "%d",time((long *)0));
+     arrivaltime = articletime = expiretime = tbuff;
+ 
+     switch (items) {
+     case 2:
+ 	arrivaltime = (char *)SvPV(ST(1),na);
+ 	articletime = expiretime = arrivaltime;
+ 	break;
+     case 3: 
+ 	arrivaltime = (char *)SvPV(ST(1),na);
+ 	articletime = (char *)SvPV(ST(2),na);
+ 	expiretime = arrivaltime;
+ 	break;
+     case 4:
+ 	arrivaltime = (char *)SvPV(ST(1),na);
+ 	articletime = (char *)SvPV(ST(2),na);
+ 	expiretime =  (char *)SvPV(ST(3),na);
+ 	break;
+     case 5:
+ 	arrivaltime = (char *)SvPV(ST(1),na);
+ 	articletime = (char *)SvPV(ST(2),na);
+ 	expiretime =  (char *)SvPV(ST(3),na);
+ 	articlepaths =  (char *)SvPV(ST(4),na);
+ 	break;
+     }
+     parambuf[0] = msgid;
+     parambuf[1] = arrivaltime;
+     parambuf[2] = articletime;
+     parambuf[3] = expiretime;
+     parambuf[4] = articlepaths;
+     parambuf[5] = 0;
+ 
+     /* CCaddhist returns NULL on success, hence reversed return codes */
+     CCaddhist(parambuf) ? XSRETURN_NO : XSRETURN_YES;
+ }
+ 
+ XS(XS_INN_newsgroup)
+ {
+     dXSARGS;
+     char*	newsgroup;
+     NEWSGROUP*  ngp;
+ 
+     if (items != 1)
+         croak("Usage: INN::newsgroup(msgid)");
+     newsgroup = (char *)SvPV(ST(0),na);
+ 
+     if ((ngp = NGfind(newsgroup)) == NULL)
+ 	XSRETURN_UNDEF;
+     else
+ 	XSRETURN_PV(ngp->Rest);
+ }
+ 
+ void
+ PERLinndAPIinit()
+ {
+     newXS("INN::havehist", XS_INN_havehist, "cc.c");
+     newXS("INN::cancel", XS_INN_cancel, "cc.c");
+     newXS("INN::addhist", XS_INN_addhist, "cc.c");
+     newXS("INN::newsgroup", XS_INN_newsgroup, "cc.c");
+ }
+ #endif
-- 
Regards,
Ed Mooring (mooring@tymnet.com 408-922-7504)

Technical Details
Message-ID: <6jjme1$948@arduin.Tymnet.COM>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <6io1ku$c3$1@samba.rahul.net> <4Z741.34$bZ4.14913@firestorm.gunslinger.net> <6iui65$rl2@arduin.Tymnet.COM> <SXG41.48$bZ4.17908@firestorm.gunslinger.net>

Show Full Headers
Complete Article Headers
Message-ID: <6jjme1$948@arduin.Tymnet.COM>
Subject: PERL calling back to INN [was Re: risk of UNIX postings being misidentified as spam?]
Date: Sat, 16 May 1998 00:00:00 +0000
From: mooring@arduin.Tymnet.COM (Ed Mooring)
References: <6io1ku$c3$1@samba.rahul.net> <4Z741.34$bZ4.14913@firestorm.gunslinger.net> <6iui65$rl2@arduin.Tymnet.COM> <SXG41.48$bZ4.17908@firestorm.gunslinger.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 353764581
Organization: MCI Data Services Engineering, San Jose
Newsgroups: news.software.nntp