lib/kolab_sync.php

Aleksander Machniak machniak at kolabsys.com
Thu Oct 18 14:27:58 CEST 2012


 lib/kolab_sync.php |   41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

New commits:
commit 989e0a4ef1d9eaf203b1b1841ec6e0732554111d
Author: Aleksander Machniak <alec at alec.pl>
Date:   Thu Oct 18 14:26:59 2012 +0200

    Remove first-log-in-to-Roundcube requirement (#1055)

diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index ab0e3d5..0a645c2 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -221,7 +221,8 @@ class kolab_sync extends rcube
             return null;
         }
 
-        $login_lc = $this->config->get('login_lc');
+        $login_lc     = $this->config->get('login_lc');
+        $default_port = $this->config->get('default_port', 143);
 
         // parse $host
         $a_host = parse_url($host);
@@ -231,13 +232,13 @@ class kolab_sync extends rcube
             if (!empty($a_host['port'])) {
                 $port = $a_host['port'];
             }
-            else if ($ssl && $ssl != 'tls' && (!$config['default_port'] || $config['default_port'] == 143)) {
+            else if ($ssl && $ssl != 'tls' && (!$default_port || $default_port == 143)) {
                 $port = 993;
             }
         }
 
         if (!$port) {
-            $port = $this->config->get('default_port');
+            $port = $default_port;
         }
 
         // Convert username to lowercase. If storage backend
@@ -259,23 +260,41 @@ class kolab_sync extends rcube
         $username = rcube_utils::idn_to_ascii($username);
 
         // user already registered?
-        $user = rcube_user::query($username, $host);
-        if (!is_object($user)) {
-            // @TODO: log error
-            return null;
+        if ($user = rcube_user::query($username, $host)) {
+            $username = $user->data['username'];
         }
 
-        // Configure environment
-        $this->user = $user;
-        $username   = $user->data['username'];
-
         // authenticate user in IMAP
         $storage = $this->get_storage();
         if (!$storage->connect($host, $username, $password, $port, $ssl)) {
             return null;
         }
 
+        // No user in database, but IMAP auth works
+        if (!is_object($user)) {
+            if ($this->config->get('auto_create_user')) {
+                // create a new user record
+                $user = rcube_user::create($username, $host);
+
+                if (!$user) {
+                    self::raise_error(array(
+                        'code' => 620, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__,
+                        'message' => "Failed to create a user record",
+                    ), true, false);
+                    return null;
+                }
+            }
+            else {
+                self::raise_error(array(
+                    'code' => 620, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__,
+                    'message' => "Access denied for new user $username. 'auto_create_user' is disabled",
+                ), true, false);
+                return null;
+            }
+        }
+
         // overwrite config with user preferences
+        $this->user = $user;
         $this->config->set_user_prefs((array)$this->user->get_prefs());
         $this->set_storage_prop();
 





More information about the commits mailing list