]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/pagectrl.c
ITS#5571 prevent Adds from displacing {0}config
[openldap] / libraries / libldap / pagectrl.c
index 40093cb6fd5ed48ead9b6d6d3d8cd16b6a1a9ace..8aac0c892a4ee644b9a7b1896574e5fa1d9a68ee 100644 (file)
@@ -1,6 +1,6 @@
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2006 The OpenLDAP Foundation.
+ * Copyright 1998-2008 The OpenLDAP Foundation.
  * Copyright 2006 Hans Leidekker
  * All rights reserved.
  *
@@ -12,9 +12,6 @@
  * top-level directory of the distribution or, alternatively, at
  * <http://www.OpenLDAP.org/license.html>.
  */
-/* Portions Copyright (C) The Internet Society (1999)
- * ASN.1 fragments are from RFC 2696; see RFC for full legal notices.
- */
 
 #include "portable.h"
 
@@ -65,8 +62,9 @@ ldap_create_page_control_value(
        if ( ld == NULL || value == NULL ||
                pagesize < 1 || pagesize > LDAP_MAXINT )
        {
-               ld->ld_errno = LDAP_PARAM_ERROR;
-               return ld->ld_errno;
+               if ( ld )
+                       ld->ld_errno = LDAP_PARAM_ERROR;
+               return LDAP_PARAM_ERROR;
        }
 
        assert( LDAP_VALID( ld ) );
@@ -141,7 +139,6 @@ ldap_create_page_control(
        LDAPControl     **ctrlp )
 {
        struct berval   value;
-       BerElement      *ber;
 
        if ( ctrlp == NULL ) {
                ld->ld_errno = LDAP_PARAM_ERROR;
@@ -151,19 +148,11 @@ ldap_create_page_control(
        ld->ld_errno = ldap_create_page_control_value( ld,
                pagesize, cookie, &value );
        if ( ld->ld_errno == LDAP_SUCCESS ) {
-               if ((ber = ldap_alloc_ber_with_options(ld)) == NULL) {
-                       ld->ld_errno = LDAP_NO_MEMORY;
-                       return LDAP_NO_MEMORY;
-               }
-
-               ld->ld_errno = ldap_create_control( LDAP_CONTROL_PAGEDRESULTS,
-                       ber, iscritical, ctrlp );
-               if ( ld->ld_errno == LDAP_SUCCESS ) {
-                       (*ctrlp)->ldctl_value = value;
-               } else {
+               ld->ld_errno = ldap_control_create( LDAP_CONTROL_PAGEDRESULTS,
+                       iscritical, &value, 0, ctrlp );
+               if ( ld->ld_errno != LDAP_SUCCESS ) {
                        LDAP_FREE( value.bv_val );
                }
-               ber_free(ber, 1);
        }
 
        return ld->ld_errno;
@@ -195,8 +184,9 @@ ldap_parse_pageresponse_control(
        ber_int_t count;
 
        if ( ld == NULL || ctrl == NULL || cookie == NULL ) {
-               ld->ld_errno = LDAP_PARAM_ERROR;
-               return ld->ld_errno;
+               if ( ld )
+                       ld->ld_errno = LDAP_PARAM_ERROR;
+               return LDAP_PARAM_ERROR;
        }
 
        /* Create a BerElement from the berval returned in the control. */
@@ -257,7 +247,7 @@ ldap_parse_page_control(
                return ld->ld_errno;
        }
 
-       c = ldap_find_control( LDAP_CONTROL_PAGEDRESULTS, ctrls );
+       c = ldap_control_find( LDAP_CONTROL_PAGEDRESULTS, ctrls, NULL );
        if ( c == NULL ) {
                /* No page control was found. */
                ld->ld_errno = LDAP_CONTROL_NOT_FOUND;
@@ -266,7 +256,7 @@ ldap_parse_page_control(
 
        ld->ld_errno = ldap_parse_pageresponse_control( ld, c, countp, &cookie );
        if ( ld->ld_errno == LDAP_SUCCESS ) {
-               *cookiep = LDAP_MALLOC( sizeof( struct berval ) );
+               *cookiep = LDAP_MALLOC( sizeof( struct berval ) );
                if ( *cookiep == NULL ) {
                        ld->ld_errno = LDAP_NO_MEMORY;
                } else {