Ticket #83: newgroup-updategroup.patch

File newgroup-updategroup.patch, 2.4 KB (added by eagle, 14 years ago)

Patch against INN 2.4.1

  • inn-2.4.1/control/controlchan.in

    old new  
    254254    return $cachedctl = [ reverse @ctllist ];
    255255}
    256256
     257sub findaction {
     258    my ($ctllist, $type, $newsgroup, $sender) = @_;
     259    my ($action, $hier);
     260
     261    foreach (@$ctllist) {
     262        my @ctlline = split /:/;
     263        # 0: type  1: from@addr  2: group.*  3: action
     264        if ($type =~ /$ctlline[0]/ and $sender =~ /$ctlline[1]/i and
     265            ($type !~ /(?:new|rm)group/ or $newsgroup =~ /$ctlline[2]/)) {
     266            $action = $ctlline[3];
     267            $action =~ s/\^(.+)\$/$1/;
     268            $action =~ s/\\//g;
     269            $hier = $ctlline[2] if $type eq 'checkgroups';
     270            last;
     271        }
     272    }
     273
     274    ($action, $hier);
     275}
     276
     277# Does the group exist in the active file ?
     278sub group_exists {
     279    my $group = shift;
     280    my $found = 0;
     281    local *ACTIVE;
     282
     283    unless (open(ACTIVE, $inn::active)) {
     284        logdie("cannot open active file $inn::active");
     285    }
     286
     287    while (<ACTIVE>) {
     288        next unless (/^([^:]+):/);
     289        if ($group eq $1) {
     290            $found = 1;
     291            last;
     292        }
     293    }
     294    close ACTIVE;
     295
     296    $found;
     297}
     298
     299
    257300# Parse a control message's permissions.
    258301sub ctlperm {
    259302    my ($type, $sender, $newsgroup, $token, $headers, $body) = @_;
    260303
    261     my $action = 'drop';    # default
    262     my ($logname, $hier);
     304    my ($logname, $action, $hier);
    263305
    264306    # newgroup and rmgroup require newsgroup names; check explicitly for that
    265307    # here and return drop if the newsgroup is missing (to avoid a bunch of
     
    271313    }
    272314
    273315    my $ctllist = readctlfile();
    274     foreach (@$ctllist) {
    275         my @ctlline = split /:/;
    276         # 0: type  1: from@addr  2: group.*  3: action
    277         if ($type =~ /$ctlline[0]/ and $sender =~ /$ctlline[1]/i and
    278             ($type !~ /(?:new|rm)group/ or $newsgroup =~ /$ctlline[2]/)) {
    279             $action = $ctlline[3];
    280             $action =~ s/\^(.+)\$/$1/;
    281             $action =~ s/\\//g;
    282             $hier = $ctlline[2] if $type eq 'checkgroups';
    283             last;
    284         }
     316    if (lc $type eq 'newgroup' && group_exists($newsgroup)) {
     317        ($action, $hier) = findaction($ctllist, 'updategroup',
     318                                                $newsgroup, $sender);
     319    }
     320    if (!defined($action)) {
     321        ($action, $hier) = findaction($ctllist, $type, $newsgroup, $sender);
    285322    }
     323    $action ||= 'drop';     # default if not found.
    286324
    287325    ($action, $logname) = split(/=/, $action);