#!/usr/local/bin/perl -Tw # Copyright (c) 2000 River of Stars, LLC. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by River of Stars, LLC. # 4. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. my $DEBUG = 1; ##### # web heartbeat nuker of active keys ##### use strict; use Sys::Syslog; BEGIN { push(@INC, '/usr/local/libexec/authhb'); } use hbu; ##### # setup/constants ##### my $UNCHARS = '[\w\d_\.-]+'; # legal chars for account names ##### # var declarations ##### my ($er, $now, $k, $ip, $stamp, @ipl, $un, $kun, @rest); ##### # prototypes predeclarations to avoid screwing up line number reports ##### #sub foo ($$$$$$); ##### # main ##### openlog('authhb-nuker', 'pid', 'local6'); # set specialized options for syslog $un = shift @ARGV; if ($un =~ m/^($UNCHARS)$/o) { $un = $1; if ( opendir (DBD, $hbu::dr) ) { @ipl = grep !/^\./, readdir DBD; # get list of ips in database dir closedir DBD; foreach $ip (@ipl) { if ( $ip = ip4v ($ip) ) { # make sure it's a proper db file $k = keyg ($ip); # pull key from db file if ( $k =~ m/^ERRKEY/ ) { syslog ('notice', "%s: found no key data for %s", $k, $ip); next; } ($kun, @rest) = parsekey($k); if ($un eq $kun ) { # is it the right user? syslog ('notice', 'nuking %s entry on %s', $un, $ip); if ( $er = keyr ($ip) ) { # nuke it syslog ('notice', '%s: problem nuking %s on %s', $er, $ip); } } } else { syslog ('err', 'garbage file in database dir: %s', $ip); exit(1); } } } else { syslog ('err', 'unable to open db dir: %s', $hbu::dr); exit(1); } } else { syslog('err', "illegal characters in nuke target name"); exit(1); } exit 0;