{"id":1328,"date":"2016-12-12T20:57:15","date_gmt":"2016-12-12T19:57:15","guid":{"rendered":"https:\/\/elkano.org\/blog\/?p=1328"},"modified":"2016-12-14T16:20:58","modified_gmt":"2016-12-14T15:20:58","slug":"como-anadir-indices-en-openldap","status":"publish","type":"post","link":"https:\/\/elkano.org\/blog\/como-anadir-indices-en-openldap\/","title":{"rendered":"C\u00f3mo a\u00f1adir \u00edndices en OpenLDAP"},"content":{"rendered":"<p>Si encuentras en el log de OpenLDAP entradas de este tipo cuando se realizan b\u00fasquedas de los objetos significa que las b\u00fasquedas se realizan sobre un atributo que no tiene \u00edndice en LDAP:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-linenumbers=\"false\" data-enlighter-theme=\"atomic\">\r\nslapd[14318]: &lt;= mdb_equality_candidates: (associatedDomain) not indexed\r\n<\/pre>\n<p>Estas b\u00fasquedas podr\u00edan ser bastante costosas si tenemos un LDAP con muchos datos por lo que si este tipo de b\u00fasquedas son muy frecuentes conviene a\u00f1adir un \u00edndice al atributo. Para ello crearemos un fichero <strong>add-index.ldif<\/strong> con el siguiente contenido:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-linenumbers=\"false\" data-enlighter-theme=\"atomic\">\r\ndn: olcDatabase={1}mdb,cn=config\r\nchangetype: modify\r\nreplace: olcDbIndex\r\nolcDbIndex: associatedDomain eq\r\n<\/pre>\n<p>En este caso creamos un \u00edndice de tipo de <strong>eq<\/strong> como se puede observar en la \u00faltima l\u00ednea ya que las b\u00fasquedas son del tipo &#8216;associatedDomain=dominio&#8217;, pero existen otro tipo de \u00edndices dependiendo del tipo de b\u00fasqueda a realizar sobre el atributo:<\/p>\n<blockquote><p><strong>pres<\/strong> should be used if use searches of the form &#8216;objectclass=person&#8217; or &#8216;attribute=mail&#8217; will be used.<br \/>\n<strong>approx<\/strong> MUST be used if use searches of the form &#8216;sn~=person&#8217; (a &#8216;sounds-like&#8217; search) will be used.<br \/>\n<strong>eq<\/strong> should be used if searches of the form &#8216;sn=smith&#8217; will be used i.e no wildcards are included (uses the EQUALITY rule only).<br \/>\n<strong>sub<\/strong> should be used if use searches of the form &#8216;sn=sm*&#8217; i.e wildcards are included (uses the SUBSTR rule). This rule may be enhanced by a using subinitial (optimised for &#8216;sn=*s&#8217;), subany (optimised for &#8216;sn=*n*&#8217;) or subfinal (optimised for &#8216;sn=th*&#8217;). One or more sub parameters may be included.<\/p><\/blockquote>\n<p>Tambi\u00e9n podr\u00edamos combinar varios tipos de \u00edndices de esta forma:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-linenumbers=\"false\" data-enlighter-theme=\"atomic\">\r\nolcDbIndex: associatedDomain eq,sub\r\n<\/pre>\n<p>Una vez generado el fichero solo tenemos que ejecutar el siguiente comando e introducir la clave del usuario admin del esquema:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-linenumbers=\"false\" data-enlighter-theme=\"atomic\">\r\n$ ldapadd -h localhost -D &quot;cn=admin,cn=config&quot; -f add-index.ldif -W\r\nEnter LDAP Password: \r\nmodifying entry &quot;olcDatabase={1}mdb,cn=config&quot;\r\n<\/pre>\n<p>Si no sabemos la clave del usuario <strong>cn=admin,cn=config<\/strong> podemos cambiar la contrase\u00f1a tal como se explica en este post <a href=\"https:\/\/elkano.org\/blog\/openldap-como-establecer-la-clave-de-root-del-esquema\/\">Cambiar la clave de cn=admin,cn=config<\/a> o utilizar el siguiente comando que no requiere una autenticaci\u00f3n expl\u00edcita ya que se basa en la autenticaci\u00f3n del propio usuario:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-linenumbers=\"false\" data-enlighter-theme=\"atomic\">\r\nldapmodify -Y EXTERNAL -H ldapi:\/\/\/ -f add-index.ldif\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Si encuentras en el log de OpenLDAP entradas de este tipo cuando se realizan b\u00fasquedas de los objetos significa que las b\u00fasquedas se realizan sobre un atributo que no tiene \u00edndice en LDAP: slapd[14318]: &lt;= mdb_equality_candidates: (associatedDomain) not indexed Estas b\u00fasquedas podr\u00edan ser bastante costosas si tenemos un LDAP con muchos datos por lo que [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[95,193,94],"_links":{"self":[{"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/posts\/1328"}],"collection":[{"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/comments?post=1328"}],"version-history":[{"count":1,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/posts\/1328\/revisions"}],"predecessor-version":[{"id":1330,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/posts\/1328\/revisions\/1330"}],"wp:attachment":[{"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/media?parent=1328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/categories?post=1328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/tags?post=1328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}