у меня так.
1. файл squid.schema:
##
## schema file for OpenLDAP 2.x (unofficial)
## Schema for storing Squid maps in LDAP
##
attributetype ( 1.1.2.1.1.1
NAME 'squidMapKey'
DESC 'key (left hand side) of an aliases or map entry'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} )
attributetype ( 1.1.2.1.1.2
NAME 'squidMapName'
DESC 'identifier for the particular map'
EQUALITY caseIgnoreMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{128} SINGLE-VALUE )
attributetype ( 1.1.2.1.1.3
NAME 'squidMapValue'
DESC 'value (right hand side) of a map entry'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 SINGLE-VALUE )
attributetype ( 1.1.2.1.1.4
NAME 'squidMapLimit'
DESC 'value (right hand side) of a map limit'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
objectclass ( 1.1.2.2.1.1
NAME 'squidMap'
SUP top AUXILIARY
DESC 'squid map definition'
MUST squidMapName
MAY ( Description $ squidMapLimit ) )
objectclass ( 1.1.2.2.1.2
NAME 'squidMapObject'
SUP squidMap AUXILIARY
DESC 'squid map object'
MUST ( squidMapName $ squidMapKey $ squidMapValue )
MAY ( Description $ squidMapLimit ) )
2. скрипт squid_ldap.map.pl:
#!/usr/bin/perl
#
# squid ldap map
#
use Getopt::Long qw(:config no_ignore_case);
use Net::hostent;
use Net::LDAP;
#use strict;
# const
my $VERSION = '20051123';
# variables
my $ldap;
my $object;
my $result;
my $opt_groupdn = '';
my $opt_binddn = '';
my $opt_bindpasswd = '';
my $opt_secretfile = '';
my $opt_uri = '';
GetOptions(
'b=s' => \$opt_groupdn,
'D=s' => \$opt_binddn,
'w=s' => \$opt_bindpasswd,
'W=s' => \$opt_secretfile,
'H=s' => \$opt_uri );
# check: requires param
&usage unless($opt_groupdn and $opt_uri);
#connect
$ldap = Net::LDAP->new($opt_uri) or die("connect $opt_uri failed!");
# bind
if($opt_binddn){
# check: secretfile
if($opt_secretfile){
open(FILE, "<$opt_secretfile") or die("error read $opt_secretfile");
$opt_bindpasswd = <FILE>;
close(FILE); }
$result = $ldap->bind($opt_binddn, password=>$opt_bindpasswd);
# anonymous bind
}else{ $result = $ldap->bind(); }
$result->code and die($result->error);
# use buffers off
$| = 1;
# BASIC
while(<STDIN>){
chomp;
# format: user password
unless(/^(\S+)\s*(\S*)$/){ print "ERR\n"; next; }
$object = $1;
# rules %SRC
if($object =~ m/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/){
# check IP or gethost(IP)
my ($host, undef) = @{gethost($object)};
if(check_object($object) or check_object($host)){
print "OK\n";
next;
$result = $ldap->bind($opt_binddn, password=>$opt_bindpasswd);
# anonymous bind
}else{ $result = $ldap->bind(); }
$result->code and die($result->error);
# use buffers off
$| = 1;
# BASIC
while(<STDIN>){
chomp;
# format: user password
unless(/^(\S+)\s*(\S*)$/){ print "ERR\n"; next; }
$object = $1;
# rules %SRC
if($object =~ m/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/){
# check IP or gethost(IP)
my ($host, undef) = @{gethost($object)};
if(check_object($object) or check_object($host)){
print "OK\n";
next;
next;
}
print "ERR\n";
next;
}
# rules %LOGIN
if(check_object($object)){
# return: OK
print "OK\n";
}else{
# return: ERR
print "ERR\n";
}
}
sub check_object(){
my $value = shift;
# check: valid object
$result = $ldap->search(
base=>"squidMapKey=$value," . $opt_groupdn,
filter=>"(objectClass=squidMapObject)",
attrs=>['squidMapValue'] );
# return: OK
return 1 if($result->count and ($result->entry->get_value('squidMapValue') eq 'TRUE'));
return 0;
}
sub usage(){
print <<EOF;
squid_ldap_map.pl version $VERSION
Usage: squid_ldap_map.pl -b "squidMapName=users,ou=squid,dc=ldap,dc=local" -H ldaps://ldap.local
-b squidMapNameDN (REQUIRED)
-H LdapURI (REQUIRED)
-D BindDN
-w BindPasswd
-W SecretFile
EOF
exit;
}
3. конфигурация squid.conf:
# стандартная авторизация
auth_param ntlm program /usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp
auth_param ntlm children 5
auth_param ntlm max_challenge_reuses 0
auth_param ntlm max_challenge_lifetime 2 minutes
auth_param ntlm use_ntlm_negotiate off
auth_param basic program /usr/bin/ntlm_auth --helper-protocol=squid-2.5-basic
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off
#определяем ACL
acl NTLMauth proxy_auth REQUIRED
external_acl_type type_users_map ttl=10 children=1 %LOGIN /usr/lib/squid/squid_ldap_map.pl -b "squidMapName=users,ou=squid,dc=ldap,dc=local" -H ldaps://ldap.local
external_acl_type type_computers_map ttl=10 children=1 %SRC /usr/lib/squid/squid_ldap_map.pl -b "squidMapName=computers,ou=squid,dc=ldap,dc=local" -H ldaps://ldap.local
acl acl_allow_users external type_users_map
acl acl_allow_comps external type_computers_map
# политика поведения самое простое к примеру
http_access deny !acl_allow_comps
http_access allow acl_allow_users
http_access deny all
4. сами списки в ldap к примеру так squid.ldif:
dn: ou=squid,dc=ldap,dc=local
objectClass: top
objectClass: organizationalUnit
ou: squid
dn: squidMapName=users,ou=squid,dc=ldap,dc=local
objectClass: top
objectClass: squidMap
objectClass: organizationalUnit
ou: squid
squidMapName: users
dn: squidMapKey=afletdinov,squidMapName=users,ou=squid,dc=ldap,dc=local
objectClass: top
objectClass: squidMap
objectClass: squidMapObject
objectClass: organizationalUnit
squidMapName: users
ou: squid
squidMapKey: afletdinov
squidMapValue: TRUE
dn: squidMapName=computers,ou=squid,dc=ldap,dc=local
objectClass: top
objectClass: squidMap
objectClass: organizationalUnit
ou: squid
squidMapName: computers
dn: squidMapKey=it11.local,squidMapName=users,ou=squid,dc=ldap,dc=local
objectClass: top
objectClass: squidMap
objectClass: squidMapObject
objectClass: organizationalUnit
squidMapName: computers
ou: squid
squidMapKey: it11.local
squidMapValue: TRUE
В выше приведенном два списка пользователи и компьютеры, работает NTLM авторизация, запрещены компьютеры которых нет в списке computers либо они заблокированы, и разрешаем пользователей.
Компьютеры можно записывать по DNS имени или по ип адресу.
Так же возможно блокировать по DST, вести списки разрешенных либо запрещенных сайтов.
К приведенным ACL можно применять правила по времени и спулы.
Самое главное squid автоматически применяет изменения по времени как в опции TTL.
Работает замечательно. В Ldap желательно выставить индексы на squidMapKey, squidMapValue.