/usr/sbin/get-news is in suck 4.3.2-11.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | #! /usr/bin/perl -w
# NOTE: this script needs to be run by the news user.
# Debian systems will not allow normal users to run ctlinnd and innxmit
# or rnews.
# Perl version by Blars Blarson, based on sh version by Christophe Le Bars,
# Brian Mays, Tolleff Fog Heen, and others
use strict;
use File::Copy;
use File::Path;
# defaults, may be overriden in config file or command line
my %var = (
"batchmode" => "-br",
"bindir" => "/usr/bin",
"etcdir" => "/etc/suck",
"logdir" => "/var/log/suck",
"newsbin" => "/usr/sbin",
"newsspooldir" => "/var/spool/news",
"postfilter" => "/usr/lib/suck/put-news",
"process" => "gp",
"quiet" => 0,
"remoteport" => 119,
"server" => "localhost",
"servtype" => "inn2",
"spooldir" => "/var/spool/suck",
"statedir" => "/var/lib/suck",
"timestamp" => 0,
"verbose" => 0,
);
my @siteoptions = (
"userid",
"password",
"suckoptions",
"rpostoptions",
"remoteport",
"postfilter",
"process",
);
my $site;
my $etcdir = "/etc/suck";
my $getnewsconf = "$etcdir/get-news.conf";
my $exit = 0;
# read the configuration file
open CONF, "<$getnewsconf" or die "Could not open $getnewsconf: $!";
while ($_ = <CONF>) {
if (/^([a-z0-9\-\_\.]+)\:\s+(.*)$/) {
$var{$1} = $2;
} else {
die "Unknown line in $getnewsconf:\n$_" unless (/^\s*(?:$|\#)/);
}
}
close CONF;
my $quiet = $var{'quiet'};
my $verbose = $var{'verbose'};
my $timestamp = $var{'timestamp'};
unless (defined $var{'rnews'}) {
if (-x "/usr/lib/news/input/rnews") {
$var{'rnews'} = "/usr/lib/news/input/rnews";
} elsif (-x '/usr/bin/rnews') {
$var{'rnews'} = '/usr/bin/rnews';
} else {
die "rnews not found\n";
}
}
my $defserver = $var{'remoteserver'};
if (exists $var{"outgoingfile"}) {
$site = $var{"outgoingfile"};
} else {
$site = $var{"remoteserver"};
}
# see if site is on the command line
if (scalar(@ARGV) && $ARGV[0] !~ /^-/) {
$site = shift @ARGV;
$var{"remoteserver"} = $site;
}
foreach my $opt (@siteoptions) {
if (exists $var{"${site}_${opt}"}) {
$var{$opt} = $var{"${site}_${opt}"};
}
}
# process the rest of the command line
while ($_ = shift @ARGV) {
if (/^-outgoingfile$/) {
$site = shift @ARGV;
foreach my $opt (@siteoptions) {
if (exists $var{"${site}_${opt}"}) {
$var{$opt} = $var{"${site}_${opt}"};
}
}
} elsif (/^-server$/) {
$var{"server"} = shift @ARGV;
} elsif (/^-get(?:only)?$/) {
$var{"process"} = "g";
} elsif (/^-post(?:only)?$/) {
$var{"process"} = "p";
} elsif (/^-user(?:id)?$/) {
$var{"userid"} = shift @ARGV;
} elsif (/^-password$/) {
$var{"password"} = shift @ARGV;
} elsif (/^-noauth$/) {
delete $var{"userid"};
delete $var{"password"};
} elsif (/^-port$/) {
$var{"remoteport"} = shift @ARGV;
} elsif (/^-q(?:iet)?$/) {
$quiet++;
} elsif (/^-v(?:erbose)?$/) {
$verbose++;
} elsif (/^-timestamp$/) {
$timestamp++;
} elsif (/^-h(?:elp)?$/) {
print "Usage: $0 [<sitename>] [-option parm]...\n\n".
" <sitename> The NNTP server you will connect to.\n".
"\n".
"Options:\n".
" -outgoingfile <filename> The file of your remote server\n".
" outgoing articles.\n".
" (default = the remote server name)\n".
" -userid <userid> The userid to send to the remote\n".
" server.\n".
" -password <password> The password to send to the remote\n".
" server.\n".
" -noauth Do not send userid and password.\n".
" (even if they are specified in\n".
" ${getnewsconf})\n".
" -port <port> Set remote port number.\n".
" -server <sitename> Your local NNTP server.\n".
" (default = \"$var{'server'}\")\n".
" -q Do not display the BPS and article\n".
" count messages during download. \n".
" Multiple -q to suppress message\n".
" -getonly Only get new messages, do not post\n".
" -postonly Only post outgoing messages, do not get\n".
" new ones\n".
" -timestamp put timestamps in log\n".
" -verbose Display more messages about process.\n".
" Use multiple times for debugging.\n".
"\n";
exit 0;
} else {
die "Unknown option: $_ (use -h for help)";
}
}
if ($verbose > 1) {
print "Options:\n";
foreach (keys %var) {
print "$_: $var{$_}\n";
}
print "\n";
}
my $authopts = '';
if (exists $var{'userid'}) {
$authopts = '-Q';
$ENV{'NNTP_USER'} = $var{'userid'};
$ENV{'NNTP_PASS'} = $var{'password'};
}
if ($var{'servtype'} =~ /^inn/) {
if (system("$var{'bindir'}/testhost $var{'server'} -s -e") != 0) {
die "Bad status for the $var{'server'} local NNTP news server: $?";
}
}
my $lastdir = "$var{'logdir'}/$var{'remoteserver'}";
if (! -d $lastdir) {
die "could not create $lastdir" unless mkdir($lastdir);
}
sub ts {
return "" unless($timestamp);
my @now = localtime();
return sprintf("%02d:%02d:%02d ", $now[2], $now[1], $now[0]);
}
my $getnewslog = "$var{'logdir'}/get-news.log";
open LOG, ">>", $getnewslog or die "Could not open $getnewslog: $!";
print LOG "\n".scalar(localtime())."\n";
if ($var{'process'} =~ /g/) {
my $batchfile = "$var{'statedir'}/batch.$var{'remoteserver'}.$$";
my $msgdir = "$var{'spooldir'}/$var{'remoteserver'}";
my $errlog = "$var{'logdir'}/errlog";
my $suffix = '';
my $popt = '';
if($defserver ne $var{'remoteserver'}) {
$suffix = ".$var{'remoteserver'}";
$popt = "-p $suffix";
}
if($quiet && $var{'suckoptions'} !~ /-q/) {
$var{'suckoptions'} .= ' -q';
}
print LOG ts()."getnews: download articles\n" unless($quiet > 1);
my $suckcmd = "$var{bindir}/suck $var{'remoteserver'} $var{'suckoptions'}"
." $authopts $var{'batchmode'} $batchfile -dt $var{'statedir'}"
." -dm $msgdir -dd $var{'etcdir'} $popt -N $var{'remoteport'}"
." -E $errlog";
print ts()."$suckcmd\n" if($verbose);
open SUCK, "-|", $suckcmd or die "Could not start $suckcmd: $!";
while (my $l = <SUCK>) {
print LOG ts().$l;
print ts().$l if($verbose);
}
close SUCK;
if ($? == 0 || $? == 256) {
print ts()."Downloaded Articles\n" unless($quiet > 1);
if (-f "$var{'statedir'}/suck.newrc$suffix") {
rename("$var{'etcdir'}/sucknewsrc$suffix",
"$var{'etcdir'}/sucknewsrc$suffix.old");
move("$var{'statedir'}/suck.newrc$suffix",
"$var{'etcdir'}/sucknewsrc$suffix");
}
move("$var{'statedir'}/suck.sorted$suffix",$lastdir)
if (-f "$var{'statedir'}/suck.sorted$suffix");
move("$var{'statedir'}/suck.killog$suffix",$lastdir)
if (-f "$var{'statedir'}/suck.killog$suffix");
move("$var{'etcdir'}/suckothermsgs$suffix",$lastdir)
if (-f "$var{'etcdir'}/suckothermsgs$suffix");
if (-f $batchfile) {
my $batchcmd = "NNTPSERVER=$var{'server'} $var{'rnews'} <$batchfile";
print ts()."$batchcmd\n" if ($verbose);
if (system($batchcmd)) {
print STDERR "Local posting error\n";
$exit = 255;
} else {
print ts()."Posted Articles Locally\n" unless($quiet > 1);
rmtree($msgdir);
unlink($batchfile);
}
}
} else {
print STDERR "Error getting articles, see $errlog\n";
$exit = 1;
}
}
if (! $exit && $var{'process'} =~ /p/) {
my $outgoing = $var{'newsspooldir'};
foreach my $a ('.outgoing', 'out.going', 'outgoing') {
if (-d "$outgoing/$a") {
$outgoing .= "/$a";
last;
}
}
$outgoing .= "/$site";
my $artdir = $var{'newsspooldir'};
$artdir .= "/articles" if (-d "$artdir/articles");
my $outgoingnew = "${outgoing}.new";
foreach my $o ($outgoingnew, $outgoing) {
if (-s $o) {
if ($o ne $outgoingnew) {
rename($outgoing,$outgoingnew);
if ($var{'servtype'} =~ /^inn/) {
my $flushcmd = "$var{'newsbin'}/ctlinnd flush $site";
print ts()."$flushcmd\n" if ($verbose);
if (system($flushcmd) != 0) {
print STDERR "Problem running $flushcmd: $!\n";
}
}
}
my $outfile = "$var{'statedir'}/rpost.$var{'remoteserver'}.$$";
my $postcmd = "$var{'bindir'}/rpost $var{'remoteserver'}"
." -N $var{'remoteport'} $authopts -E $var{'logdir'}/errlog"
." $var{'rpostoptions'} -b $outgoingnew -p $artdir"
." -f $var{'postfilter'} \\\$\\\$o=$outfile"
." \\\$\\\$i $outfile";
print LOG ts()."Posting outgoing articles\n";
print ts()."$postcmd\n" if ($verbose);
if (system($postcmd) != 0) {
print STDERR "Error remote posting\n";
$exit = 2;
last;
} else {
print ts()."Remotely posted articles\n" unless($quiet > 1);
unlink($outfile);
unlink($outgoingnew);
}
}
}
}
print ts()."get-news processing complete\n" unless($quiet > 1);
close LOG;
exit($exit);
|