🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #84203

Re: Mail-to-News

#84203
From: Dennis Davis
Date: Mon, 18 Jul 2011 14:10
280 lines
10262 bytes
In the referenced article, =?windows-1252?Q?Julien_=C9LIE?=
 <iulius@nom-de-mon-site.com.invalid> writes:
> 
> > (1) Check that:
> >
> > server:                 localhost
> >
> > is set in inn.conf.  The default is to have it unset.  Without this
> > set, inews won't know how to post articles.
> >
> > (2) Make sure the example entry:
> >
> > #DHD#peer ME {
> > #DHD#  hostname: "localhost, 127.0.0.1, ::1"
> > #DHD#}
> >
> >
> > is commented out similar to what I've done.  With this entry present,
> > the local host can only transit articles, not post them.
> 
> What was used to post articles?

Ultimately the s/w was using inews.

> I see that mailnews.py knows both IHAVE (transit mode) and POST (reader 
> mode, with MODE READER sent after connecting to the news server).
> 
>      if method == 'ihave':
>          […]
>      else:
>          nntplib.NNTP(host, port, readermode=True)
> 
> 
> Unless you were using inews (POST), as it can be guessed in the comment 
> of (1).  Then why not use rnews (IHAVE) instead?  :-)

The smiley -- :-) -- is duly noted.  However you're suggesting that
a specific third-party package which knows about the "ihave" method
is installed to solve this problem.  Not all mail-to-news packages
I've seen know about "ihave".  If you're talking python, the older
"postnews 0.5.3" script seems to rely on readermode.  Many others
rely on a working version of inews.  As does the mailpost perl
script that comes with INN-2.5.2.  Are you suggesting that the
mailpost perl script be extended to use "ihave" where using inews is
not applicable?

> > (I've tried using mailpost on Solaris and I get a failure:
> >
> >   can't lock /var/tmp/mailpost-msgid.lock: Bad file number
> >
> >   on the second article posted.  The first one creates the above file
> >   &  article database.  I suspect this is because mailpost uses the
> >   flock perl command and this isn't working as expected on Solaris.
> >   If so this should be easy to fix, just tweak the perl to use
> >   something like the perl module LockFile-Simple-0.207.  Should be
> >   good enough.  It's just finding time to do this.)
> 
> Is it linked to:
> 
>    http://inn.eyrie.org/trac/ticket/81
> 
>      mailpost tries to store its message ID database in INN's pathtmp,
>      but since it's usually running as the mail system (often daemon)
>      rather than as news, this fails.
> 
> or is it something totally different?  What are the rights on your 
> /var/tmp/mailpost-msgid.lock file?  (readable and writable by the user 
> or daemon which runs mailpost?)

It isn't linked to:

http://inn.eyrie.org/trac/ticket/81

I noted the warnings about this in the documentation.  I'm using
exim to inject the email articles as news.  The exim transport that
does this has a couple of lines:

  user = NEWS_USER
  command = /bin/sh -c ${lookup{$local_part}SEARCH{MAIL2NEWS_INJECTORS}}

so the command *is* being run as the news user.  This worked well
on the Cnews system and does work with INN.

The problem, as I indicated, seems due to file locking being system
specific.  I suspect most INN development is done on Linux, which
seems to have both fnctl(2) and flock(2) and the corresponding
perl functions.  However my older perl book includes the following
comment about fnctl:

  fcntl will produce a fatal error if used on a machine that doesn't
  implement fcntl(2).

It also includes the following comment about flock:

  Invoking flock will produce a fatal error if used on a machine
  that doesn't implement flock(2), or emulate it through some other
  locking mechanism.

The *BSD systems, OpenBSD at least, have flock(2) but not fnctl(2).
Solarix has fnctl(2) but *not* flock(2), other than in the SunOS/BSD
Compatibility Library Functions, which aren't really usable for
me.  This is a potential problem when installing INN on Solaris as
several of the perl scripts use the flock perl function.  Including
the mailpost script which I want to use.

Locking with the perl scripts that come with INN seems fairly basic,
ie it's file locking rather than locking records inside a database.
So I first thought to switch the file locking in mailpost to use
the shlock program that comes with INN.  However I decided against
this as the LockFile-Simple module seems more versatile as well as
system-independent.

So I installed the LockFile-Simple perl module and modified the code
of mailpost to use this module if it's available.  Now everything is
working as expected.  The pullnews and signcontrol perl scripts that
come with INN also use flock; I suppose I should also look at these
scripts.

Patches to mailpost are given below in case they're of use to anyone
else.

*** mailpost.o	Fri Jun  3 10:51:39 2011
--- mailpost	Mon Jul  4 13:11:18 2011
***************
*** 35,44 ****
--- 35,51 ----
  my $LOCK_NB = 4;
  my $LOCK_UN = 8;
  
+ my $lockmgr;
+ 
  my $usage = $0 ;
  $usage =~ s!.*/!! ;
  my $prog = $usage ;
  
+ my $use_lockfile_simple = 0;
+ 
+ eval { require LockFile::Simple; import LockFile::Simple;
+        $use_lockfile_simple = 1; };
+ 
  my $use_syslog = 0;
  
  eval { require Sys::Syslog; import Sys::Syslog; $use_syslog = 1; };
***************
*** 381,398 ****
  
  my $lockfile = sprintf("%s.lock", $Database);
  
! open(LOCKFILE, "<$lockfile") || 
!     open(LOCKFILE, ">$lockfile") ||
!     mailArtAndDie ("can't open $lockfile: $!") ;
! 
! my $i ;
! for ($i = 0 ; $i < 5 ; $i++) {
!     flock(LOCKFILE, $LOCK_EX) && last ;
!     sleep 1 ;
  }
  
- mailArtAndDie ("can't lock $lockfile: $!") if ($i == 5) ;
- 
  my %DATABASE ;
  dbmopen(%DATABASE, $Database, 0666) || mailArtAndDie ("can't dbmopen $Database: $!");
  
--- 388,411 ----
  
  my $lockfile = sprintf("%s.lock", $Database);
  
! if ($use_lockfile_simple) {
!     $lockmgr = LockFile::Simple->make (-format => '%f.lock',
!         -max => 5, -delay => 1);
!     $lockmgr->lock ($Database) || mailArtAndDie ("can't lock $Database");
! } else {
!     open(LOCKFILE, "<$lockfile") || 
!         open(LOCKFILE, ">$lockfile") ||
!         mailArtAndDie ("can't open $lockfile: $!") ;
!     
!     my $i ;
!     for ($i = 0 ; $i < 5 ; $i++) {
!         flock(LOCKFILE, $LOCK_EX) && last ;
!         sleep 1 ;
!     }
!     
!     mailArtAndDie ("can't lock $lockfile: $!") if ($i == 5) ;
  }
  
  my %DATABASE ;
  dbmopen(%DATABASE, $Database, 0666) || mailArtAndDie ("can't dbmopen $Database: $!");
  
***************
*** 416,423 ****
  
  dbmclose(%DATABASE) || mailArtAndDie ("can't dbmclose $Database: $!") ;
  
! flock(LOCKFILE, $LOCK_UN) || mailArtAndDie ("can't unlock $lockfile: $!");
! close LOCKFILE ;
  
  ## For crosspost.
  
--- 429,440 ----
  
  dbmclose(%DATABASE) || mailArtAndDie ("can't dbmclose $Database: $!") ;
  
! if ($use_lockfile_simple) {
!     $lockmgr->unlock ($Database) || mailArtAndDie ("can't unlock $Database");
! } else {
!     flock(LOCKFILE, $LOCK_UN) || mailArtAndDie ("can't unlock $lockfile: $!");
!     close LOCKFILE ;
! }
  
  ## For crosspost.
  
***************
*** 442,458 ****
  
    sleep $opt_c ;
  
!   open(LOCKFILE, "<$lockfile") || 
!     open(LOCKFILE, ">$lockfile") ||
!       mailArtAndDie ("can't open $lockfile: $!") ;
  
-   my $i ;
-   for ($i = 0 ; $i < 5 ; $i++) {
-     flock(LOCKFILE, $LOCK_EX) && last ;
-     sleep 1 ;
-   }
-   mailArtAndDie ("can't lock $lockfile: $!") if ($i == 5) ;
- 
    my $umask_bak = umask();
    umask(000);
    dbmopen(%DATABASE, $Database, 0666) || mailArtAndDie ("can't dbmopen $Database: $!");
--- 459,481 ----
  
    sleep $opt_c ;
  
! if ($use_lockfile_simple) {
!     $lockmgr = LockFile::Simple->make (-format => '%f.lock',
!         -max => 5, -delay => 1);
!     $lockmgr->lock ($Database) || mailArtAndDie ("can't lock $Database");
! } else {
!       open(LOCKFILE, "<$lockfile") || 
!         open(LOCKFILE, ">$lockfile") ||
!           mailArtAndDie ("can't open $lockfile: $!") ;
!     
!       my $i ;
!       for ($i = 0 ; $i < 5 ; $i++) {
!         flock(LOCKFILE, $LOCK_EX) && last ;
!         sleep 1 ;
!       }
!       mailArtAndDie ("can't lock $lockfile: $!") if ($i == 5) ;
! }
  
    my $umask_bak = umask();
    umask(000);
    dbmopen(%DATABASE, $Database, 0666) || mailArtAndDie ("can't dbmopen $Database: $!");
***************
*** 464,471 ****
  
    dbmclose(%DATABASE) || mailArtAndDie ("can't dbmclose $Database: $!") ;
  
!   flock(LOCKFILE, $LOCK_UN) || mailArtAndDie ("can't unlock $lockfile: $!");
!   close LOCKFILE ;
  
    if (defined($dup)) {
      syslog("err", "mismatch $newsgroups") if $debugging && $use_syslog;
--- 487,498 ----
  
    dbmclose(%DATABASE) || mailArtAndDie ("can't dbmclose $Database: $!") ;
  
! if ($use_lockfile_simple) {
!     $lockmgr->unlock ($Database) || mailArtAndDie ("can't unlock $Database");
! } else {
!       flock(LOCKFILE, $LOCK_UN) || mailArtAndDie ("can't unlock $lockfile: $!");
!       close LOCKFILE ;
! }
  
    if (defined($dup)) {
      syslog("err", "mismatch $newsgroups") if $debugging && $use_syslog;
-- 
Dennis Davis, BUCS, University of Bath, Bath, BA2 7AY, UK
D.H.Davis@bath.ac.uk
Technical Details
Message-ID: <LoJ8po.KpC.B.larch@bath.ac.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!num2.nntp.dca.giganews.com!num1.nntp.dca.giganews.com!number.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin1!goblin.stu.neva.ru!news2.euro.net!feeder.news-service.com!news-transit.tcx.org.uk!nntp-feed.chiark.greenend.org.uk!ewrotcd!bath.ac.uk!ccsdhd
References: <iuaorh$gbt$1@n102.xanadu-bbs.net> <iufpeq$qgh$1@n102.xanadu-bbs.net> <LnLzu6.6IE.B.larch@bath.ac.uk> <ivvjd7$c15$1@news.trigofacile.com>

Show Full Headers
Complete Article Headers
Message-ID: <LoJ8po.KpC.B.larch@bath.ac.uk>
Subject: Re: Mail-to-News
Date: Mon, 18 Jul 2011 14:10:36 GMT
From: ccsdhd@bath.ac.uk (Dennis Davis)
References: <iuaorh$gbt$1@n102.xanadu-bbs.net> <iufpeq$qgh$1@n102.xanadu-bbs.net> <LnLzu6.6IE.B.larch@bath.ac.uk> <ivvjd7$c15$1@news.trigofacile.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.20141118.mbox.gz!num2.nntp.dca.giganews.com!num1.nntp.dca.giganews.com!number.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin1!goblin.stu.neva.ru!news2.euro.net!feeder.news-service.com!news-transit.tcx.org.uk!nntp-feed.chiark.greenend.org.uk!ewrotcd!bath.ac.uk!ccsdhd
Newsgroups: news.software.nntp
Organization: BUCS, University of Bath, UK
Lines: 279