3 * Manages PAM repository connection with local imap server help
8 * @author Oliver Schulze <oliver@samera.com.py>,
9 * Andrew McMillan <andrew@mcmillan.net.nz>
10 * @copyright Based on Eric Seigne script drivers_squid_pam.php
11 * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
14 require_once("auth-functions.php");
27 * @param string $imap_url formated for imap_open()
29 function imapPamDrivers($imap_url){
30 $this->__construct($imap_url);
37 * @param string $imap_url formated for imap_open()
39 function __construct($imap_url)
42 if (empty($imap_url)){
43 $c->messages
[] = sprintf(i18n('drivers_imap_pam : imap_url parameter not configured in /etc/davical/*-conf.php'));
52 * Check the username / password against the IMAP server
54 function RIMAP_check($username, $password ){
57 $imap_username = $username;
58 if ( function_exists('mb_convert_encoding') ) {
59 $imap_username = mb_convert_encoding($imap_username, "UTF7-IMAP",mb_detect_encoding($imap_username));
62 $imap_username = imap_utf7_encode($imap_username);
65 //$imap_url = '{localhost:143/imap/notls}';
66 //$imap_url = '{localhost:993/imap/ssl/novalidate-cert}';
67 $imap_url = $c->authenticate_hook
['config']['imap_url'];
70 $imap_stream = @imap_open
($imap_url, $imap_username, $password, OP_HALFOPEN
);
71 //print_r(imap_errors());
74 imap_close($imap_stream);
79 if ( $auth_result == "OK") {
80 $principal = new Principal('username',$username);
81 if ( ! $principal->Exists() ) {
82 dbg_error_log( "PAM", "Principal '%s' doesn't exist in local DB, we need to create it",$username );
83 if ( strstr($username, '@') ) {
84 $name_arr = explode('@', $username);
85 $fullname = ucfirst(strtolower($name_arr[0]));
89 $fullname = ucfirst(strtolower($username));
90 $email = $username . "@" . $c->authenticate_hook
['config']['email_base'];
93 $principal->Create( array(
94 'username' => $username,
95 'user_active' => true,
97 'fullname' => ucfirst($fullname)
99 if ( ! $principal->Exists() ) {
100 dbg_error_log( "PAM", "Unable to create local principal for '%s'", $username );
103 CreateHomeCollections($username);
108 dbg_error_log( "PAM", "User %s is not a valid username (or password was wrong)", $username );