Here's my version with the $socket_path variable added, and some code to check both "standard" path locations if the main path isn't found.
-- Chris Petersen Programmer / Web Designer Silicon Mechanics: http://www.siliconmechanics.com/ Blade Servers: http://www.siliconmechanics.com/c292/blade-server.php 1U Servers: http://www.siliconmechanics.com/c272/1u-server.php
# Copyright (C) 2003 Corporation of Balclutha. All rights reserved. # # Visit us at http://www.balclutha.org for all of your open source # software development and support requirements and hosted solutions. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program 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. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # package Mail::SpamAssassin::AuthCourier; # # A mechanism which uses the Courier MTA's authdaemond server to # determine mail account information. Courier is found at http://courier-mta.org # # This module automagically overrides the builtin getpwnam and getpwuid # functions. # use Exporter; use IO::Socket::UNIX; @ISA = qw(Exporter); @EXPORT = qw( getpwnam getpwuid ); # # ensure overriding for our own internal usage as well ... # use subs qw( getpwnam getpwuid ); # # Find the path to the socket file # my $socket_path = '/usr/lib/courier/var/authdaemon/socket'; if (! -e $socket_path) { if (-e '/var/spool/courier/authdaemon/socket') { $socket_path = '/var/spool/courier/authdaemon/socket'; } elsif (-e '/usr/lib/courier/var/authdaemon/socket') { $socket_path = '/usr/lib/courier/var/authdaemon/socket'; } } # # For some frustrating reason, the socket seems to be unusable unless set each time. # Please contact us if you have the solution to this enhancement. # BEGIN { # $socket = IO::Socket::UNIX->new($socket_path); } END { $socket->close if $socket; } sub getpwnam { my $name = shift; my $socket = IO::Socket::UNIX->new($socket_path) or die "authdaemond socket error: $!\n"; print $socket "PRE . login $name\n"; my %results = (); my ($k, $v); while (<$socket>) { ($k,$v) = split '=', $_, 2; chomp $v if $v; $results{$k} = $v; } $socket->close if $socket; # some auth mechanisms don't return UID - these must be fetched from /etc/passwd or # it's moral equivalent until Sam patches these as per my request... my $uid = $results{'UID'} || CORE::getpwnam($name); # stop some naf 'uninitialized' errors ... return wantarray ? ('','','','','','','') : undef unless $uid; # uid 0 = root !!! return wantarray ? ( $results{'USERNAME'}, $results{'PASSWD'}, int($uid), int($results{'GID'}), $results{'QUOTA'}, $results{'COMMENT'}, $results{'GCOS'}, $results{'HOME'}, '/bin/bash') : $uid; } sub getpwuid { return (getpwnam($_[0]))[2]; } 1;
