#!/usr/bin/perl ## $Id: auth-squid,v 1.2 2012/07/07 05:29:12 pdc Exp $ ## (c) 2000-2007 Pavel Polyakov #### use IO::Handle; $debug=0; open LOG, ">/tmp/auth-$$"; LOG->autoflush(1); $|=1; sub reload() { my $PASS, $name, $pass; open PASS,"/etc/squid-passwd" || die "cant open passwd"; while() { if(/^(\S+)\s+(\S+)\s*$/) { ($name,$pass)=(lc $1,$2); my $m=0; if($pass=~/^[0-9a-f]{32}$/) { # check if md5 $m=1; # print "md5 detected"; }; $md5{$name}=$m; # md5 flag $passwd{$name}=$pass; print STDERR "pass: $name \t$pass\t$m\n" if $debug>1; } } close PASS; } reload; while(<>) { my $ok=0; if(/^(\S+)\s+(\S+)\s*$/){ print LOG "got: $_\n"; ($name,$pass)=(lc $1,$2); my $p=$passwd{$name}; if($p eq '') { # zero-len pass, no such username! print LOG "Null pass!\n"; print STDERR "Null pass!\n" if $debug>2; reload; my $p=$passwd{$name}; # next if $p eq ''; } if($md5{$name}) { # check md5 flag $m=`echo '$name:$pass' | /sbin/md5`; chomp $m; print STDERR "md5=$m, need $p\n" if $debug>2; $ok=$m eq $p; if($ok) { # remember pass - no more md5 in mem $passwd{$name}=$pass; undef $md5{$name}; #print STDERR "remember pass $pass for $name\n" if $debug>2; print STDERR "remember pass for $name\n" if $debug>2; print LOG "remember pass for $name\n"; } } elsif($p eq $pass) {$ok=1}; # whole string compare }; print($ok?"OK\n":"ERR\n"); }