I kind of got a pop3 DA module working that would work for a pop3 for one domain. but has an issue...

IF anyone is allowed to create an account w/o approval or if user.module is hacked,
the following Distributed Authentication module works... so long as the good username/passoword,
and no syntax error in imap_open function.
However if the imap_open fails, even if I have php display_errors OFF, it still opens the header with stream error message that shows the folder and messes up drupal page by putting

 text before html head.

Please, any suggestions on how to prevent error messages from imap_open() failing stream showing on resulting login failure page?


example of module with "ourdomain.com" hard coded:

function authpop3_info($field = 0) {
  $info['name'] = 'authpop3';
  $info['protocol'] = 'POP3';
  if ($field) {return $info[$field]; }
  else { return $info; }
}

function authpop3_auth($username, $password, $server) {
$serverlowercase = strtolower($server);
if ($serverlowercase != "ourdomain.com"){ return FALSE;}
$link=imap_open("{ourdomainpop3server.com:995/pop3/ssl/novalidate-cert}",$username."@ourdomain.com",$password);
if ($link){ imap_close($link); return TRUE; }
else { return FALSE; }
}

Comments

jsloan’s picture

... in the LDAP_Integration module the following function prevents it:

>
// This wrapper is needed to avoid ldap_bind() give ugly output about denied logins
function _ldap_integration_bind($con, $dn, $pass) {
  ob_start();
  $res = ldap_bind($con, $dn, $pass);
  ob_end_clean();

  return $res;
}
</

a similar wrapper should work in your case.

webengr’s picture

a good suggestion!

I thought I had tried that earlier, but I must have made a typo, because it is making a difference now...

so far so good...

webengr’s picture

Seems to still work with 4.7.0

<?php
function authpop3_info($field = 0) {
  $info['name'] = 'authpop3';
  $info['protocol'] = 'POP3';
  if ($field) {return $info[$field]; }
  else { return $info; }
}

function authpop3_auth($username, $password, $server) {
$serverlowercase = strtolower($server);
if ($serverlowercase != "ourdomain.com"){ return FALSE;}
ob_start();
$link=imap_open("{mail.ourdomain.com:995/pop3/ssl/novalidate-cert}",$username."@ourdomain.com",$password);
ob_end_clean();
if ($link){
                imap_close($link);
                return TRUE;
                }
        else {
                return FALSE;
                }
}
?>





NOTE, you may want to see also http://drupal.org/node/8760#comment-47188
The default user.module will not authenticate remote user accounts unless user_register == 1
so a hack would be to comment out per article. I'm sure there is a better way, maybe the
imap_auth contrib has a clever way to do that...