/* * ldap_search - initiate an ldap (and X.500) search operation. Parameters: * * ld LDAP descriptor * base DN of the base object * scope the search scope - one of LDAP_SCOPE_BASE, * LDAP_SCOPE_ONELEVEL, LDAP_SCOPE_SUBTREE * filter a string containing the search filter * (e.g., "(|(cn=bob)(sn=bob))") * attrs list of attribute types to return for matches * attrsonly 1 => attributes only 0 => attributes and values * * Example: * char *attrs[] = { "mail", "title", 0 }; * msgid = ldap_search( ld, "c=us@o=UM", LDAP_SCOPE_SUBTREE, "cn~=bob", * attrs, attrsonly ); */ int ldap_search( LDAP *ld, char *base, int scope, char *filter, char **attrs, int attrsonly ) { BerElement *ber; Debug( LDAP_DEBUG_TRACE, "ldap_search\n", 0, 0, 0 ); if (( ber = ldap_build_search_req( ld, base, scope, filter, attrs, attrsonly )) == NULLBER ) { return( -1 ); } #ifndef NO_CACHE if ( ld->ld_cache != NULL ) { if ( check_cache( ld, LDAP_REQ_SEARCH, ber ) == 0 ) { ber_free( ber, 1 ); ld->ld_errno = LDAP_SUCCESS; return( ld->ld_msgid ); } add_request_to_cache( ld, LDAP_REQ_SEARCH, ber ); } #endif /* NO_CACHE */ /* send the message */ return ( send_initial_request( ld, LDAP_REQ_SEARCH, base, ber )); }
/* * ldap_compare - perform an ldap (and X.500) compare operation. The dn * of the entry to compare to and the attribute and value to compare (in * attr and value) are supplied. The msgid of the response is returned. * * Example: * ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" ) */ int ldap_compare( LDAP *ld, char *dn, char *attr, char *value ) { BerElement *ber; struct berval bv; int rv; /* The compare request looks like this: * CompareRequest ::= SEQUENCE { * entry DistinguishedName, * ava SEQUENCE { * type AttributeType, * value AttributeValue * } * } * and must be wrapped in an LDAPMessage. */ #ifdef _REENTRANT LOCK_LDAP(ld); #endif Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 128, "ldap_compare\n"), 0, 0, 0 ); bv.bv_val = value; bv.bv_len = strlen(value); if ((ber = ldap_build_compare_req(ld, dn, attr, &bv, NULL)) == NULLBER) { #ifdef _REENTRANT UNLOCK_LDAP(ld); #endif return (-1); } #ifndef NO_CACHE if ( ld->ld_cache != NULL ) { if ( check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) { ber_free( ber, 1 ); ld->ld_errno = LDAP_SUCCESS; #ifdef _REENTRANT UNLOCK_LDAP(ld); #endif return( ld->ld_msgid ); } add_request_to_cache( ld, LDAP_REQ_COMPARE, ber ); } #endif /* NO_CACHE */ /* send the message */ rv = send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber ); #ifdef _REENTRANT UNLOCK_LDAP(ld); #endif return (rv); }
/* LDAPv3 API extensions */ int ldap_compare_ext(LDAP *ld, char *dn, char *attr, struct berval *bvalue, LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp) { BerElement *ber; struct berval bv; int rv; /* The compare request looks like this: * CompareRequest ::= SEQUENCE { * entry DistinguishedName, * ava SEQUENCE { * type AttributeType, * value AttributeValue * } * } * and must be wrapped in an LDAPMessage. */ #ifdef _REENTRANT LOCK_LDAP(ld); #endif Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 128, "ldap_compare\n"), 0, 0, 0 ); if ((ber = ldap_build_compare_req(ld, dn, attr, bvalue, NULL)) == NULLBER) { rv = ld->ld_errno; if (rv == LDAP_SUCCESS) rv = LDAP_OTHER; #ifdef _REENTRANT UNLOCK_LDAP(ld); #endif return (rv); } #ifndef NO_CACHE if ( ld->ld_cache != NULL ) { if ( check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) { ber_free( ber, 1 ); ld->ld_errno = LDAP_SUCCESS; *msgidp = ld->ld_msgid; #ifdef _REENTRANT UNLOCK_LDAP(ld); #endif return( LDAP_SUCCESS ); } add_request_to_cache( ld, LDAP_REQ_COMPARE, ber ); } #endif /* NO_CACHE */ /* send the message */ rv = send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber ); if (rv == -1) { rv = ld->ld_errno; if (rv == LDAP_SUCCESS){ rv = LDAP_OTHER; } #ifdef _REENTRANT UNLOCK_LDAP(ld); #endif return (rv); } *msgidp = rv; #ifdef _REENTRANT UNLOCK_LDAP(ld); #endif return (LDAP_SUCCESS); }