/usr/lib/news/bin/cnfsheadconf is in inn2 2.6.0-2.
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | #! /usr/bin/perl -w
use lib '/usr/share/perl5'; use INN::Config;
# $Id: cnfsheadconf.in 9216 2011-07-05 18:30:57Z iulius $
#
# Copyright Andreas Lamrecht 1998
# <Andreas.Lamprect@siemens.at>
#
# Modified by Kjetil T. Homme 1998
# <kjetilho@ifi.uio.no>
#
# Modified by Robert R. Collier 1998
# <rob@lspace.org>
#
# bigint support added by Duane Currie (sandman@hub.org) 1998
#
# cnfsheadconf is originally from cnfsstat 1999
# <kondou@nec.co.jp>
use strict;
use Getopt::Long;
# Required for >32bit integers.
use Math::BigInt;
use Math::BigFloat;
my $conffile = "$INN::Config::pathetc/cycbuff.conf";
my $storageconf = "$INN::Config::pathetc/storage.conf";
# Hex to bigint conversion routine.
# bhex(HEXSTRING) returns BIGINT (with leading + chopped off).
#
# In most languages, unlimited size integers are done using string math
# libraries usually called bigint. (Java, Perl, etc.)
#
# Bigint's are really just strings.
sub bhex {
my $hexValue = shift;
$hexValue =~ s/^0x//;
my $integerValue = Math::BigInt->new('0');
for (my $i = 0; $i < length($hexValue); $i+=2) {
# Could be more efficient going at larger increments, but byte
# by byte is safer for the case of 9 byte values, 11 bytes, etc.
my $byte = substr($hexValue, $i, 2);
my $byteIntValue = hex($byte);
# bmuladd() is only in Perl >= 5.10.0.
$integerValue->bmul('256');
$integerValue->badd("$byteIntValue");
}
my $result = $integerValue->bstr();
$result =~ s/^\+//;
return $result;
}
sub bint2hex {
my $d = shift;
my $o = "0";
my $integerValue = Math::BigInt->new("$d");
while ($integerValue->is_pos() and not $integerValue->is_zero()) {
my $h = $integerValue->copy()->bmod('16')->bstr();
$integerValue->bdiv('16');
$h =~ s/^\+//;
$h='a' if $h eq '10';
$h='b' if $h eq '11';
$h='c' if $h eq '12';
$h='d' if $h eq '13';
$h='e' if $h eq '14';
$h='f' if $h eq '15';
$o="$h$o";
}
# The result ends with a "0".
return "$o";
}
sub usage {
print <<"_end_";
Summary tool for cycbuff header manipulation
Usage:
$0 [-c CYCBUFF] [-h] [-w]
If called without args, does a one-time status of all CNFS buffers.
-c <cycbuff>: print out status of cycbuff
-h: this information
-w: change header
_end_
exit(1);
}
my (%buff, $cycbuff, $opt_w);
GetOptions(
'c=s' => \$cycbuff,
'w' => \$opt_w,
'h' => sub { usage() },
);
unless (read_cycbuffconf()) {
print STDERR "Cannot open CycBuff Conffile $conffile ...\n";
exit (1);
}
unless (read_storageconf()) {
print STDERR "No valid $storageconf.\n";
exit (1);
}
sub read_cycbuffconf {
my (@line, %class, %metamode);
return 0 unless open my $CONFFILE, '<', $conffile;
while (<$CONFFILE>) {
$_ =~ s/^\s*(.*?)\s*$/$1/;
# Read continuation lines.
while(/\\$/) {
chop;
chop (my $next = <$CONFFILE>);
$next =~ s/^\s*(.*?)\s*$/$1/;
$_ .= $next;
}
# \x23 below is #. Emacs perl-mode gets confused by the "comment".
next if ($_ =~ /^\s*$/ || $_ =~ /^\x23/);
next if ($_ =~ /^cycbuffupdate:/ || $_ =~ /^refreshinterval:/);
if($_ =~ /^metacycbuff:/) {
@line = split(/:/, $_);
if ($class{$line[1]}) {
print STDERR "Class $line[1] more than one time in CycBuff Conffile $conffile ...\n";
return 0;
}
$class{$line[1]} = $line[2];
if (scalar @line > 3 && $line[3] ne "") {
$metamode{$line[1]} = $line[3];
} else {
$metamode{$line[1]} = "INTERLEAVE";
}
next;
}
if ($_ =~ /^cycbuff/) {
@line = split(/:/, $_);
if ($buff{$line[1]}) {
print STDERR "Buff $line[1] more than one time in CycBuff Conffile $conffile ...\n";
return 1;
}
$buff{$line[1]} = $line[2];
next;
}
print STDERR "Unknown config line \"$_\" in CycBuff Conffile $conffile ...\n";
}
close $CONFFILE;
return 1;
}
sub read_storageconf {
my $line = 0;
my %stor;
return 0 unless open my $STOR, '<', $storageconf;
while (<$STOR>) {
++$line;
next if /^\s*#/;
# defaults
my %key = ("NEWSGROUPS" => "*",
"SIZE" => "0,0");
if (/method\s+cnfs\s+\{/) {
while (<$STOR>) {
++$line;
next if /^\s*#/;
last if /\}/;
if (/(\w+):\s+(\S+)/i) {
$key{uc($1)} = $2;
}
}
unless (defined $key{'CLASS'} && defined $key{'OPTIONS'}) {
print STDERR "storage.conf:$line: ".
"Missing 'class' or 'options'\n";
return 0;
}
$key{'SIZE'} .= ",0" unless $key{'SIZE'} =~ /,/;
$key{'SIZE'} =~ s/,/:/;
if (defined $stor{$key{'OPTIONS'}}) {
print STDERR "storage.conf:$line: ".
"Class $key{'CLASS'} has several criteria\n";
} else {
$stor{$key{'OPTIONS'}} = "$key{'NEWSGROUPS'}:$key{'CLASS'}:" .
"$key{'SIZE'}:$key{'OPTIONS'}";
}
}
}
close $STOR;
return 1;
}
START:
# If no cycbuff is specified, we check all of them and exit.
if (not defined $cycbuff) {
foreach (sort keys %buff) {
print_cycbuff_head($buff{$_});
}
exit(0);
}
if (not defined $buff{$cycbuff}) {
print STDERR "No buffer definition for buffer $cycbuff...\n";
exit(1);
}
print_cycbuff_head($buff{$cycbuff});
sub make_time {
my ($t) = @_;
my (@ret);
my ($sec,$min,$hour,$mday,$mon,$year) =
(localtime($t))[0..5];
push (@ret, sprintf("%04d-%02d-%02d %2d:%02d:%02d",
$year + 1900, $mon + 1, $mday, $hour, $min, $sec));
$t = time - $t;
$mday = int($t/86400); $t = $t % 86400;
$hour = int($t/3600); $t = $t % 3600;
$min = int($t/60); $t = $t % 60;
push (@ret, sprintf("%4d days, %2d:%02d:%02d",
$mday, $hour, $min, $t));
return @ret;
}
sub print_cycbuff_head {
my ($buffpath) = @_;
my $CNFSMASIZ = 8;
my $CNFSNASIZ = 16;
my $CNFSPASIZ = 64;
my $CNFSLASIZ = 16;
my $headerlength = 2 * $CNFSMASIZ + 2 * $CNFSNASIZ + $CNFSPASIZ + (6 * $CNFSLASIZ);
my ($BUFF, $buff);
if ($opt_w) {
if ( !open $BUFF, '+<', $buffpath ) {
print STDERR "Cannot open Cycbuff $buffpath ...\n";
exit(1);
}
} else {
if ( !open $BUFF, '<', $buffpath ) {
print STDERR "Cannot open Cycbuff $buffpath ...\n";
exit(1);
}
}
$buff = "";
if ( !read $BUFF, $buff, $headerlength ) {
print STDERR "Cannot read $headerlength bytes from file $buffpath...\n";
exit(1);
}
my ($magic, $name, $path, $lena, $freea, $updatea, $cyclenuma, $metaname, $orderinmetaa, $currentbuff, $blksza) = unpack("a8 a16 a64 a16 a16 a16 a16 a16 a16 a8 a16", $buff);
if (!$magic) {
print STDERR "Error while unpacking header ...\n";
exit(1);
}
my $len = bhex($lena);
my $free = bhex($freea);
my $update = hex($updatea);
my $cyclenum = hex($cyclenuma) - 1;
my $orderinmeta = hex($orderinmetaa);
my $blksz = ($magic =~ m/^CBuf4/) ? hex($blksza) : 512;
my ($nupdate_str, $nago_str) = make_time($update);
$name =~ s/\0//g;
print " Buffer $name, len: ";
printf "%.2f", Math::BigFloat->new($len) / (1024 * 1024);
print " Mbytes, used: ";
printf "%.2f Mbytes", Math::BigFloat->new($free) / (1024 * 1024);
printf " (%4.1f%%) %3d cycles\n",
100 * Math::BigFloat->new($free) / Math::BigFloat->new($len),
$cyclenum;
print " Meta $metaname, order: ";
printf "%d", $orderinmeta;
print ", current: $currentbuff";
print ", blocksize: $blksz";
print "\n Newest: $nupdate_str, $nago_str ago\n";
if ($opt_w) {
print "\nBuffer [$name] => ";
my $in = <>;
chop $in;
if ($in ne "") {
$name = sprintf("%0.9s\0", $in);
}
print "Path [$path] => ";
$in = <>;
chop $in;
if ($in ne "") {
$path = sprintf("%0.65s\0", $in);
}
print "Length [$len ($lena)] => ";
$in = <>;
chop $in;
if ($in ne "") {
$in = bint2hex($in);
$lena = sprintf("%017.17s\0", $in);
}
print "Free [$free ($freea)] => ";
$in = <>;
chop $in;
if ($in ne "") {
$in = bint2hex($in);
$freea = sprintf("%017.17s\0", $in);
}
print "Meta [$metaname] => ";
$in = <>;
chop $in;
if ($in ne "") {
$metaname = sprintf("%0.17s\0", $in);
}
print "Order [$orderinmeta ($orderinmetaa)] => ";
$in = <>;
chop $in;
if ($in ne "") {
$in = bint2hex($in);
$orderinmetaa = sprintf("%017.17s\0", $in);
}
print "Currentbuff [$currentbuff] => ";
$in = <>;
chop $in;
if ($in eq "TRUE" || $in eq "FALSE") {
$currentbuff = sprintf("%0.8s", $in);
}
$buff = pack("a8 a16 a64 a16 a16 a16 a16 a16 a16 a8", $magic, $name, $path, $lena, $freea, $updatea, $cyclenuma, $metaname, $orderinmetaa, $currentbuff);
$buff .= pack("a16", $blksza) if ($magic =~ m/^CBuf4/);
seek $BUFF, 0, 0;
if(! syswrite $BUFF, $buff, $headerlength ) {
print STDERR "Cannot write $headerlength bytes to file $buffpath...\n";
exit(1);
}
}
close $BUFF;
return;
}
|