[imp] Whacked out Imp hook
Alan W. Rateliff, II
lists at rateliff.net
Fri Mar 28 21:08:25 PST 2003
I'm having a problem now with the hooks I wrote for Imp and Horde. I
*though* they were working, and when I get the expected results when running
them in a PHP shell, but the system doesn't see it the same as I do :)
The _imp_hook_vinfo I wrote resolves the user-entered user portion of an
email address (completed by $_SERVER['HTTP_HOST']) to a username against
Sendmail's virtuser db.
For example,
A user logs into mail.fooyoo.com, enters "foo". The hook sees this as
foo at fooyoo.com and searches the Sendmail virtuser db to resolve it to a
local username.
Now, it works for explicitly-stated email addresses, but for the default
domains (@fooyoo.com) it fails.
@fooyoo.com foouser
doofus at fooyoo.com doofus
nitwit at fooyoo.com nitwit
Logic would say that if I enter a name of "foouser" or anything other than
the explicitly-defined addresses, that the hook should resolve it to
"foouser" and authenticate with that user.
Oh, but no.
I'd appreciate if someone could look at my hook and tell me what I might
have missed. I don't think the braces are matched in this email, and like I
said, I get the desired results when I use the PHP Shell...
I have the _horde_hook_username activated, which just combines the username
with "@" and the domain.
Thanks.
global $conf;
$vdomain = getenv('HTTP_HOST');
$vdomain = substr($vdomain, strpos($vdomain,".")+1);
$vdomain = String::lower($vdomain);
if ($type == 'username') {
$userfull = $_SESSION['imp']['user']."@".$vdomain;
$etcmail = '/etc/mail/';
$virtuser = 'virtualmail';
$dbh = dba_open($etcmail.$virtuser,'r','ndbm');
if (!function_exists('isUser')) {
function isUser($user) { return
(($user!=NULL)&&(strpos($user,'@'))); }
}
$vuser = $userfull;
if ($dbh) {
while (isUser($vuser)) {
$domain=substr($vuser,strpos($vuser,'@'));
$vuser=dba_fetch($vuser,$dbh);
if ($vuser==NULL) $vuser=dba_fetch($domain,$dbh);
$vuser = preg_replace('/%1/', $_SESSION['imp']['user'],
$vuser); // domain aliasing
if ($vuser==$userfull) $vuser=NULL;
// recursion bad
}
}
dba_close($dbh);
return $vuser;
} elseif ($type == 'vdomain') {
return $vdomain;
} else {
return new PEAR_Error('invalid type: ' . $type);
}
}
}
--
Alan W. Rateliff, II : RATELIFF.NET
Independent Technology Consultant : alan2 at rateliff.net
(Office) 850/350-0260 : (Mobile) 850/559-0100
-------------------------------------------------------------
[System Administration][IT Consulting][Computer Sales/Repair]
More information about the imp
mailing list