]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/controls.c
ITS#3563 fix parseSubentries bug
[openldap] / servers / slapd / controls.c
index 341d7ab962f4c3765aa1c3e042e9a6167df359c1..b8b18974fc8a9acaabcf24c2367509878e37be31 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2005 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -844,10 +844,11 @@ static int parsePagedResults (
        SlapReply *rs,
        LDAPControl *ctrl )
 {
-       ber_tag_t tag;
-       ber_int_t size;
-       BerElement *ber;
-       struct berval cookie = BER_BVNULL;
+       int             rc = LDAP_SUCCESS;
+       ber_tag_t       tag;
+       ber_int_t       size;
+       BerElement      *ber;
+       struct berval   cookie = BER_BVNULL;
 
        if ( op->o_pagedresults != SLAP_NO_CONTROL ) {
                rs->sr_text = "paged results control specified multiple times";
@@ -879,16 +880,17 @@ static int parsePagedResults (
        }
 
        tag = ber_scanf( ber, "{im}", &size, &cookie );
-       (void) ber_free( ber, 1 );
 
        if( tag == LBER_ERROR ) {
                rs->sr_text = "paged results control could not be decoded";
-               return LDAP_PROTOCOL_ERROR;
+               rc = LDAP_PROTOCOL_ERROR;
+               goto done;
        }
 
        if( size < 0 ) {
                rs->sr_text = "paged results control size invalid";
-               return LDAP_PROTOCOL_ERROR;
+               rc = LDAP_PROTOCOL_ERROR;
+               goto done;
        }
 
        if( cookie.bv_len ) {
@@ -896,7 +898,8 @@ static int parsePagedResults (
                if( cookie.bv_len != sizeof( reqcookie ) ) {
                        /* bad cookie */
                        rs->sr_text = "paged results cookie is invalid";
-                       return LDAP_PROTOCOL_ERROR;
+                       rc = LDAP_PROTOCOL_ERROR;
+                       goto done;
                }
 
                AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie ));
@@ -904,17 +907,28 @@ static int parsePagedResults (
                if ( reqcookie > op->o_pagedresults_state.ps_cookie ) {
                        /* bad cookie */
                        rs->sr_text = "paged results cookie is invalid";
-                       return LDAP_PROTOCOL_ERROR;
+                       rc = LDAP_PROTOCOL_ERROR;
+                       goto done;
 
                } else if ( reqcookie < op->o_pagedresults_state.ps_cookie ) {
                        rs->sr_text = "paged results cookie is invalid or old";
-                       return LDAP_UNWILLING_TO_PERFORM;
+                       rc = LDAP_UNWILLING_TO_PERFORM;
+                       goto done;
                }
 
        } else {
                /* Initial request.  Initialize state. */
+#if 0
+               if ( op->o_conn->c_pagedresults_state.ps_cookie != 0 ) {
+                       /* There's another pagedResults control on the
+                        * same connection; reject new pagedResults controls 
+                        * (allowed by RFC2696) */
+                       rs->sr_text = "paged results cookie unavailable; try later";
+                       rc = LDAP_UNWILLING_TO_PERFORM;
+                       goto done;
+               }
+#endif
                op->o_pagedresults_state.ps_cookie = 0;
-               op->o_pagedresults_state.ps_id = NOID;
                op->o_pagedresults_state.ps_count = 0;
        }
 
@@ -939,7 +953,9 @@ static int parsePagedResults (
                op->o_pagedresults = SLAP_NONCRITICAL_CONTROL;
        }
 
-       return LDAP_SUCCESS;
+done:;
+       (void)ber_free( ber, 1 );
+       return rc;
 }
 
 static int parseAssert (
@@ -1191,8 +1207,8 @@ static int parseSubentries (
 
        /* FIXME: should use BER library */
        if( ( ctrl->ldctl_value.bv_len != 3 )
-               && ( ctrl->ldctl_value.bv_val[0] != 0x01 )
-               && ( ctrl->ldctl_value.bv_val[1] != 0x01 ))
+               || ( ctrl->ldctl_value.bv_val[0] != 0x01 )
+               || ( ctrl->ldctl_value.bv_val[1] != 0x01 ))
        {
                rs->sr_text = "subentries control value encoding is bogus";
                return LDAP_PROTOCOL_ERROR;