chiark / gitweb /
ipif/service.c: Delete the `signals' vector.
[userv-utils.git] / newsrc-lg / getgroups
1 #!/usr/bin/perl
2 #
3 # Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
4 # Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
5 # Copyright 1999,2003
6 #    Chancellor Masters and Scholars of the University of Cambridge
7 # Copyright 2010 Tony Finch <fanf@dotat.at>
8 #
9 # This is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with userv-utils; if not, see http://www.gnu.org/licenses/.
21
22 $minreaddays= 21;
23 $maxperuser= 250;
24 $fetchdir= "/var/lib/news/fetch";
25 chdir("/etc/news") || die $!;
26
27 open(CONF,"nntp-merge.conf") || die $!;
28 while(<CONF>) {
29     next if m/^\#/ || !m/^\S/;
30     next if m/^(myfqdn|xref|server|server-nosearch|fetch|read|post|permit|believe|minreaddays)\s/;
31     if (m/^maxperuser\s+(\d+)\s+$/) {
32         $maxperuser= $1;
33     } elsif (m/^extrarc\s+(\S+)\s+$/) {
34         push(@extrarc,$1);
35     } else {
36         die "$_ ?";
37     }
38 }
39
40 open IGN,"</etc/news/newsrc-ignoredusers" or die $!;
41 while (<IGN>) {
42     chomp;
43     next if m/^\#/;
44     s/\s*$//;
45     $ign{$_}= 1;
46 }
47 close IGN or die $!;
48
49 open PASS,"</etc/userlist" or die $!;
50 while (<PASS>) {
51     chomp;
52     next if m/^\#/;
53     $user= $_;
54     next if $ign{$user};
55     open GL,"userv -t 30 $user newsrc-listgroups |" or die $!;
56     scan("user $user",1);
57     close GL; $? and warn "getgroups: error getting groups for $user (code $?)";
58 }
59 close PASS or die $!;
60
61 for $f (@extrarc) {
62     open GL,"< $f" or die $!;
63     scan("file $f",0);
64     close GL or die $!;
65 }
66
67 chdir($fetchdir) || die $!;
68 open(NG,">all-read-groups.new") || die $!;
69 print(NG join("\n",sort keys %yes)."\n") || die $!;
70 close(NG) || die $!;
71 rename("all-read-groups.new","all-read-groups") || die $!;
72
73 printf "total %d groups\n",scalar(keys %yes);
74 exit(0);
75
76 sub scan ($) {
77     my ($where,$toomanyenf) = @_;
78     @g= ();
79     while (<GL>) {
80         die "bad group in $where" unless m/^[-a-z0-9+]+\.[-a-z0-9+._]+$/i;
81         push @g, $&;
82     }
83     warn("too many from $where"), return if $toomanyenf && @g > $maxperuser;
84     map { $yes{$_}=1; } @g;
85     printf "%-20s - %4d groups\n",$where,scalar(@g);
86 }