La historia es la siguiente:
Soy administrador de algunos servidores en Linux, y “mi jefe” me solicitó crear un script (bash, php, python, lo que sea) que realice una búsqueda en todo el directorio LDAP e identifique que usuarios están próximos a expirar y envíe una alerta a un correo electrónico con dicho listado.
Hasta ahí sin problema. El problema sobrevino cuando la búsqueda en el directorio no arrojaba ningún resultado.
ldapsearch -LLL -x -b ou=users,dc=slabinfo,dc=com,dc=co -h 127.0.0.1 "(&(objectClass=virtualmailaccount)(objectClass=posixAccount)(expireDate>=1359936000)(expireDate<=1360454400))" uid uidnumber expireDate
Examinando detenidamente el RFC4511 me encuentro con esto:
4.5.1. Search Request
The Search request is defined as follows:
SearchRequest ::= [APPLICATION 3] SEQUENCE {
baseObject LDAPDN,
scope ENUMERATED {
baseObject (0),
singleLevel (1),
wholeSubtree (2),
... },
derefAliases ENUMERATED {
neverDerefAliases (0),
derefInSearching (1),
derefFindingBaseObj (2),
derefAlways (3) },
sizeLimit INTEGER (0 .. maxInt),
timeLimit INTEGER (0 .. maxInt),
typesOnly BOOLEAN,
filter Filter,
attributes AttributeSelection }
AttributeSelection ::= SEQUENCE OF selector LDAPString
-- The LDAPString is constrained to
-- <attributeSelector> in Section 4.5.1.8
Filter ::= CHOICE {
and [0] SET SIZE (1..MAX) OF filter Filter,
or [1] SET SIZE (1..MAX) OF filter Filter,
not [2] Filter,
equalityMatch [3] AttributeValueAssertion,
substrings [4] SubstringFilter,
greaterOrEqual [5] AttributeValueAssertion,
lessOrEqual [6] AttributeValueAssertion,
present [7] AttributeDescription,
approxMatch [8] AttributeValueAssertion,
extensibleMatch [9] MatchingRuleAssertion,
... }
SubstringFilter ::= SEQUENCE {
type AttributeDescription,
substrings SEQUENCE SIZE (1..MAX) OF substring CHOICE {
initial [0] AssertionValue, -- can occur at most once
any [1] AssertionValue,
final [2] AssertionValue } -- can occur at most once
}
MatchingRuleAssertion ::= SEQUENCE {
matchingRule [1] MatchingRuleId OPTIONAL,
type [2] AttributeDescription OPTIONAL,
matchValue [3] AssertionValue,
dnAttributes [4] BOOLEAN DEFAULT FALSE }
El atributo que intentaba buscar tenía un pequeño problema: No tenía ninguna Ordering Rule definida. La solución? editar el schema ldap correspondiente dejándolo así:
attributetype ( 1.3.6.1.4.1.22339.1.1.26 NAME 'expireDate'
DESC 'Expire date'
EQUALITY integerMatch
<strong>ORDERING integerOrderingMatch</strong>
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
El texto en negrita, es la Ordering Rule
Luego simplemente reemplacé el schema “problemático” con el nuevo corregido y voilá! mi búsqueda LDAP funciona correctamente.
ldapsearch -LLL -x -b ou=users,dc=slabinfo,dc=com,dc=co -h 127.0.0.1 "(&(objectClass=virtualmailaccount)(objectClass=posixAccount)(expireDate>=1359936000)(expireDate<=1360454400))" uid uidnumber expireDate
dn: uid=john,ou=Users,dc=slabinfo,dc=com,dc=co
uid: john
uidNumber: 1002
expireDate: 1360022400
Me gusta:
Me gusta Cargando...