Synchronise user's firstname, lastname, mail between database and LDAP

diff -Nur redmine-0.9.0/app/controllers/my_controller.rb redmine-0.9.0.new/app/controllers/my_controller.rb
--- redmine-0.9.0/app/controllers/my_controller.rb	2009-04-05 15:33:54.000000000 +0200
+++ redmine-0.9.0.new/app/controllers/my_controller.rb	2009-07-14 15:18:01.514861128 +0200
@@ -59,6 +59,9 @@
       @user.pref.attributes = params[:pref]
       @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
       if @user.save
+        if @user.auth_source and @user.auth_source.respond_to?('update')
+          @user.auth_source.update(@user.login, @user.firstname, @user.lastname, @user.mail)
+        end
         @user.pref.save
         @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
         set_language_if_valid @user.language
diff -Nur redmine-0.9.0/app/models/auth_source_ldap.rb redmine-0.9.0.new/app/models/auth_source_ldap.rb
--- redmine-0.9.0/app/models/auth_source_ldap.rb	2009-07-14 16:19:41.141886766 +0200
+++ redmine-0.9.0.new/app/models/auth_source_ldap.rb	2009-07-14 15:18:01.514861128 +0200
@@ -80,6 +80,23 @@
   rescue  LDAP::Error => text
     raise "LDAP Auth Error: " + text
   end
+  
+  def update(login, firstname, lastname, mail)
+    ldap_con = initialize_ldap_con(self.account, self.account_password)
+    entry = [
+      LDAP.mod(LDAP::LDAP_MOD_REPLACE, self.attr_firstname, [firstname]),
+      LDAP.mod(LDAP::LDAP_MOD_REPLACE, self.attr_lastname, [lastname]),
+      LDAP.mod(LDAP::LDAP_MOD_REPLACE, self.attr_mail, [mail])
+    ]
+    if self.filter.empty?
+      filter = self.attr_login + "=" + encode(login)
+    else
+      filter = self.filter.gsub("$login", encode(login))
+    end
+    ldap_con.modify(filter + "," + self.base_dn, entry)
+  rescue  LDAP::Error => text
+    raise "LDAP Auth Error: " + text
+  end
 
   # test the connection to the LDAP
   def test_connection
diff -Nur redmine-0.9.0/app/models/user.rb redmine-0.9.0.new/app/models/user.rb
--- redmine-0.9.0/app/models/user.rb	2009-05-17 14:59:14.000000000 +0200
+++ redmine-0.9.0.new/app/models/user.rb	2009-07-14 16:18:47.845859827 +0200
@@ -102,7 +102,10 @@
       return nil if !user.active?
       if user.auth_source
         # user has an external authentication method
-        return nil unless user.auth_source.authenticate(login, password)
+        attrs = user.auth_source.authenticate(login, password)
+        return nil unless attrs
+        # synchronise db with ldap
+        user.update_attributes(attrs[0])
       else
         # authentication with local password
         return nil unless User.hash_password(password) == user.hashed_password        
