From ca689e4b30c7270b1a65bc84858724f13058421d Mon Sep 17 00:00:00 2001 From: SJ Date: Thu, 13 Sep 2012 23:47:04 +0200 Subject: [PATCH] fixed an issue with ldap_sync in case of the users DN is changed --- webui/model/user/import.php | 7 +++++++ webui/model/user/user.php | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/webui/model/user/import.php b/webui/model/user/import.php index 1965d99e..0ac52d8a 100644 --- a/webui/model/user/import.php +++ b/webui/model/user/import.php @@ -211,6 +211,13 @@ class ModelUserImport extends Model { } else { + /* update DN field if it's an existing user */ + + if(($cuid = $this->model_user_user->get_uid_by_name($_user['username'])) > 0) { + $this->model_user_user->update_dn_by_uid($cuid, $_user['dn']); + continue; + } + /* or add the new user */ $user = $this->createNewUserArray($_user['dn'], $_user['username'], $_user['realname'], $_user['emails'], $globals); diff --git a/webui/model/user/user.php b/webui/model/user/user.php index 09ad970a..68aaba07 100644 --- a/webui/model/user/user.php +++ b/webui/model/user/user.php @@ -445,6 +445,20 @@ class ModelUserUser extends Model { } + public function update_dn_by_uid($uid = 0, $new_dn = '') { + if(!$this->check_uid($uid) || $new_dn == ''){ return 0; } + + $user = $this->get_user_by_uid($uid); + + if(isset($user['uid']) && $user['dn'] != '' && $user['dn'] != '*') { + $query = $this->db->query("UPDATE " . TABLE_USER . " SET dn=? WHERE uid=?", array($new_dn, $uid)); + return 1; + } + + return 0; + } + + public function delete_user($uid) { if(!$this->check_uid($uid)){ return 0; }