X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fcompare.c;h=2ce7a787be0abc7c7176207119ebe45bb1b5cf1e;hb=59e9ff6243465640956b58ad1756a3ede53eca7c;hp=e7f7ee170e27bea7913f9df61251961cbf3f54e1;hpb=a23fc2fd947fa86b240732d5421e82528e42509e;p=openldap diff --git a/libraries/libldap/compare.c b/libraries/libldap/compare.c index e7f7ee170e..2ce7a787be 100644 --- a/libraries/libldap/compare.c +++ b/libraries/libldap/compare.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2015 The OpenLDAP Foundation. + * Copyright 1998-2018 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,6 +37,50 @@ * } */ +BerElement * +ldap_build_compare_req( + LDAP *ld, + LDAP_CONST char *dn, + LDAP_CONST char *attr, + struct berval *bvalue, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *msgidp ) +{ + BerElement *ber; + int rc; + + /* create a message to send */ + if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) { + return( NULL ); + } + + LDAP_NEXT_MSGID(ld, *msgidp); + rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */ + *msgidp, + LDAP_REQ_COMPARE, dn, attr, bvalue ); + if ( rc == -1 ) + { + ld->ld_errno = LDAP_ENCODING_ERROR; + ber_free( ber, 1 ); + return( NULL ); + } + + /* Put Server Controls */ + if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) { + ber_free( ber, 1 ); + return( NULL ); + } + + if( ber_printf( ber, /*{*/ "N}" ) == -1 ) { + ld->ld_errno = LDAP_ENCODING_ERROR; + ber_free( ber, 1 ); + return( NULL ); + } + + return( ber ); +} + /* * ldap_compare_ext - perform an ldap extended compare operation. The dn * of the entry to compare to and the attribute and value to compare (in @@ -74,34 +118,10 @@ ldap_compare_ext( rc = ldap_int_client_controls( ld, cctrls ); if( rc != LDAP_SUCCESS ) return rc; - /* create a message to send */ - if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) { - return( LDAP_NO_MEMORY ); - } - - LDAP_NEXT_MSGID(ld, id); - rc = ber_printf( ber, "{it{s{sON}N}", /* '}' */ - id, - LDAP_REQ_COMPARE, dn, attr, bvalue ); - if ( rc == -1 ) - { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( ld->ld_errno ); - } - - /* Put Server Controls */ - if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) { - ber_free( ber, 1 ); + ber = ldap_build_compare_req( + ld, dn, attr, bvalue, sctrls, cctrls, &id ); + if( !ber ) return ld->ld_errno; - } - - if( ber_printf( ber, /*{*/ "N}" ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( ld->ld_errno ); - } - /* send the message */ *msgidp = ldap_send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber, id );