#!/usr/local/bin/perl ############################################################################# # Change the $port to the $port your authsrv runs on and the ip address $them # to whatever the ipaddress is of the authsrv machine # The syntax of Authsrv varies but can be found by telnetting to the # authsrv on the port its listening on # Change accordingly Below on Line 80; # In my case Gauntlet 4.1 the syntax is "Authsrv ready. (4.1)" # Squid expects only an "OK" or a "ERR" as authentication # BEWARE!!!!!!!! These authentication transactions take place in CLEAR TEXT # The author Advises that While this will work to a remote machine # it is safer to run squid and authsrv on the same machine # Software is supplied as is and no warranty or guarantee is offerd by the author # Change the software if you need everybody else does. # Thanks to Anthony Cox for his great Code # Peter Robinson peter@securegateway.org ######################################################################## # FLAGS $DEBUG=0; use Socket; ($them,$port) = @ARGV; $them = '127.0.0.1'; $port = '7777'; $port = 23 unless $port; $them = 'localhost' unless $them; chop($hostname = `hostname`); ###### MAIN LOOP ###### while (<>) { chop; ($user,$pwd) = split /\s/; ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $port) = getservbyname($port,'tcp') unless $port =~ /^\d+$/; if ( $DEBUG == 1 ) {print "Using port $port to connect to server on host $them...\n"; } ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname); ($name, $aliases,$type,$len,$thataddr) = gethostbyname($them); if (socket(S,AF_INET, SOCK_STREAM, $proto)) { if ( $DEBUG == 1 ) {print "Socket creation succeeded.\n"; } } else { die $!; } $sockaddr = 'S n a4 x8'; $this = pack($sockaddr, AF_INET, 0, $thisaddr); $that = pack($sockaddr, AF_INET, $port, $thataddr); if (bind(S, $this)) { if ( $DEBUG == 1 ) { print "Bind succeeded.\n"; } } else { die $!; } if (connect(S, $that)) { if ( $DEBUG == 1 ) { print "Connect succeeded.\n"; } } else { die $!; } while () { if ( $DEBUG==1) { print ">$_"; } chop; if ( $_ eq "Authsrv ready. (4.1)" ) { syswrite S,"authenticate $user\n"; if ( $DEBUG==1) { print ">authenticate $user\n"; } } if ( $_ eq "password" ) { syswrite S,"response $pwd\n"; if ( $DEBUG==1) { print ">response $pwd\n"; } } if ( $_ eq "ok" ) { syswrite STDOUT,"OK\n"; last; } if ( $_ eq "Permission Denied." ) { syswrite STDOUT,"ERR\n"; last; } } if ( $DEBUG==1) { print ">Loop again\n"; } } syswrite S,"quit\n"; close (S);