From bf2cf589d6bf920b906eee36397dea895acf82d5 Mon Sep 17 00:00:00 2001 From: Kayou Date: Fri, 1 Mar 2019 22:48:44 +0100 Subject: [PATCH] fix ldap --- conf/class.auth.ldap.php | 47 +++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/conf/class.auth.ldap.php b/conf/class.auth.ldap.php index 681af23..1d753c4 100644 --- a/conf/class.auth.ldap.php +++ b/conf/class.auth.ldap.php @@ -1,65 +1,59 @@ con->begin(); $cur = $this->con->openCursor($this->user_table); - # parmetre de configuration pour l'interface PHP pour administrer - # notre annuaire LDAP + # LDAP parameter $server = "localhost"; $port = "389"; $racine = "dc=yunohost,dc=org"; - #connection au serveur ldap + # LDAP connection $ds=ldap_connect($server); ldap_set_option ($ds, LDAP_OPT_PROTOCOL_VERSION, 3); if (ldap_bind($ds,"uid=".$user_id.",ou=users,dc=yunohost,dc=org",$pwd)) { - # On définit le mot de passe, il est inséré dans tous les cas. + # Store the password $cur->user_pwd = $pwd; - # Si l'utilisateur existe, nous allons uniquement mettre à jour - # son mot de passe dans la table utilisateur de Dotclear. + # If the user exist, then we just update his password. if ($this->core->userExists($user_id)) { $this->sudo(array($this->core,'updUser'),$user_id,$cur); $this->con->commit(); } - # Si l'utilisateur n'existe pas, nous allons le créer. - # Afin qu'il puisse se connecter, il est nécessaire de lui donner - # au moins une permission "usage" sur le blog "default". + # If not, we create him. + # In order for him to connect, + # it is necessary to give him at least + # a permission "usage" on the blog "default". else { - #on recherche l'utilisateur dans le ldap pour recuperer toutes les informations - $sr=ldap_search($ds,$racine,"uid=$user_id",array( "dn", "cn", "sn", "mail", "givenName")); + # search the user in ldap, and get infos + $sr=ldap_search($ds,$racine,"uid=$user_id",array( "dn", "cn", "sn", "mail", "givenname")); # /!\ fields have to be in lowercase $info = ldap_get_entries($ds, $sr); - #si le ldap ne ramene qu'un seul utilisateur if ($info["count"] ==1) { $cur->user_id = $user_id; $cur->user_email = $info[0]['mail'][0]; - $cur->user_name = $info[0]['givenName'][0]; + $cur->user_name = $info[0]['givenname'][0]; $cur->user_firstname = $info[0]['sn'][0]; - $cur->user_lang = 'fr'; - $cur->user_tz = 'Europe/Paris'; - $cur->user_default_blog = 'default'; + $cur->user_lang = 'fr'; # Can change this, PR are welcome + $cur->user_tz = 'Europe/Paris'; # Can change this, PR are welcome + $cur->user_default_blog = 'default'; # Can change this, PR are welcome $this->sudo(array($this->core,'addUser'),$cur); + # Possible roles: #admin "administrator" #usage "manage their own entries and comments" #publish "publish entries and comments" @@ -70,17 +64,16 @@ class myDcAuth extends dcAuth #media_admin "manage all media items" #pages "manage pages" #blogroll "manage blogroll" - $this->sudo(array($this->core,'setUserBlogPermissions'),$user_id,'default',array('admin'=>true)); + $this->sudo(array($this->core,'setUserBlogPermissions'),$user_id,'default',array('usage'=>true)); # Can change this, PR are welcome $this->con->commit(); } } - # Les opérations précédentes se sont déroulées sans erreur, nous - # pouvons maintenant appeler la méthode parente afin d'initialiser - # l'utilisateur dans l'object $core->auth + # The previous operations proceeded without error, + # we can now call the parent method return parent::checkUser($user_id, $pwd, $user_key, $check_blog); } - # En cas d'erreur on annule la transaction et on renvoie "false" + # In case of error we cancel and return "false" $this->con->rollback(); return false; }