<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
#
# external_acl helper to Squid to verify NT Domain group
# membership using wbinfo
#
# This program is put in the public domain by Jerry Murdock 
# &lt;jmurdock@itraktech.com&gt;. It is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Author:
#   Jerry Murdock &lt;jmurdock@itraktech.com&gt;
#
# Version history:
#   2005-12-26 Guido Serassio &lt;guido.serassio@acmeconsulting.it&gt;
#               Add '-d' command line debugging option
#
#   2005-12-24 Guido Serassio &lt;guido.serassio@acmeconsulting.it&gt;
#               Fix for wbinfo from Samba 3.0.21
#
#   2004-08-15 Henrik Nordstrom &lt;hno@squid-cache.org&gt;
#		Helper protocol changed to URL escaped in Squid-3.0
#
#   2005-06-28 Arno Streuli &lt;astreuli@gmail.com&gt;
#               Add multi group check
#
#   2002-07-05 Jerry Murdock &lt;jmurdock@itraktech.com&gt;
#		Initial release


#
# Globals
#
use vars qw/ %opt /;

# Disable output buffering
$|=1;           

sub debug {
	print STDERR "@_\n" if $opt{d};
}

#
# Check if a user belongs to a group
#
sub check {
        local($user, $group) = @_;
        $groupSID = `wbinfo -n "$group" | cut -d" " -f1`;
        chop  $groupSID;
        $groupGID = `wbinfo -Y "$groupSID"`;
        chop $groupGID;
        &amp;debug( "User:  -$user-\nGroup: -$group-\nSID:   -$groupSID-\nGID:   -$groupGID-");
        return 'ERR' if($groupGID eq ""); # Verify if groupGID variable is empty.
        return 'ERR' if(`wbinfo -r \Q$user\E` eq ""); # Verify if "wbinfo -r" command returns no value.
        return 'OK' if(`wbinfo -r \Q$user\E` =~ /^$groupGID$/m);
        return 'ERR';
}

#
# Command line options processing
#
sub init()
{
    use Getopt::Std;
    my $opt_string = 'hd';
    getopts( "$opt_string", \%opt ) or usage();
    usage() if $opt{h};
}

#
# Message about this program and how to use it
#
sub usage()
{
	print "Usage: wbinfo_group.pl -dh\n";
	print "\t-d enable debugging\n";
	print "\t-h print the help\n";
	exit;
}

init();
print STDERR "Debugging mode ON.\n" if $opt{d};

#
# Main loop
#
while (&lt;STDIN&gt;) {
        chop;
	&amp;debug ("Got $_ from squid");
        ($user, @groups) = split(/\s+/);
	$user =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("c",hex($1))/eg;
 	# test for each group squid send in it's request
 	foreach $group (@groups) {
		$group =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("c",hex($1))/eg;
 		$ans = &amp;check($user, $group);
 		last if $ans eq "OK";
 	}
	&amp;debug ("Sending $ans to squid");
	print "$ans\n";
}

</pre></body></html>