]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/controls.c
use slab allocation
[openldap] / servers / slapd / controls.c
index 1a0e42b82dd67926f5002cd09789954972f6330a..f8170df43fa1f8edf58afa98f409c2aa8dd38fdc 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2008 The OpenLDAP Foundation.
+ * Copyright 1998-2009 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -539,6 +539,37 @@ void slap_free_ctrls(
        op->o_tmpfree( ctrls, op->o_tmpmemctx );
 }
 
+int slap_add_ctrls(
+       Operation *op,
+       SlapReply *rs,
+       LDAPControl **ctrls )
+{
+       int i = 0, j;
+       LDAPControl **ctrlsp;
+
+       if ( rs->sr_ctrls ) {
+               for ( ; rs->sr_ctrls[ i ]; i++ ) ;
+       }
+
+       for ( j=0; ctrls[j]; j++ ) ;
+
+       ctrlsp = op->o_tmpalloc(( i+j+1 )*sizeof(LDAPControl *), op->o_tmpmemctx );
+       i = 0;
+       if ( rs->sr_ctrls ) {
+               for ( ; rs->sr_ctrls[i]; i++ )
+                       ctrlsp[i] = rs->sr_ctrls[i];
+       }
+       for ( j=0; ctrls[j]; j++)
+               ctrlsp[i++] = ctrls[j];
+       ctrlsp[i] = NULL;
+
+       if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED )
+               op->o_tmpfree( rs->sr_ctrls, op->o_tmpmemctx );
+       rs->sr_ctrls = ctrlsp;
+       rs->sr_flags |= REP_CTRLS_MUSTBEFREED;
+       return i;
+}
+
 int slap_parse_ctrl(
        Operation *op,
        SlapReply *rs,
@@ -1203,6 +1234,8 @@ static int parsePagedResults (
        if ( !cookie.bv_len ) {
                ps->ps_count = 0;
                ps->ps_cookie = 0;
+               /* taint ps_cookie, to detect whether it's set */
+               op->o_conn->c_pagedresults_state.ps_cookie = NOID;
        }
 
        /* NOTE: according to RFC 2696 3.:
@@ -1383,7 +1416,7 @@ parseReadAttrs(
 
                an[i].an_desc = NULL;
                an[i].an_oc = NULL;
-               an[i].an_oc_exclude = 0;
+               an[i].an_flags = 0;
                rc = slap_bv2ad( &an[i].an_name, &an[i].an_desc, &dummy );
                if ( rc == LDAP_SUCCESS ) {
                        an[i].an_name = an[i].an_desc->ad_cname;
@@ -1640,6 +1673,24 @@ static int parseSearchOptions (
                return LDAP_PROTOCOL_ERROR;
        }
 
+       if ( search_flags & ~(LDAP_SEARCH_FLAG_DOMAIN_SCOPE) ) {
+               /* Search flags not recognised so far,
+                * including:
+                *              LDAP_SEARCH_FLAG_PHANTOM_ROOT
+                */
+               if ( ctrl->ldctl_iscritical ) {
+                       rs->sr_text = "searchOptions contained unrecognized flag";
+                       return LDAP_UNWILLING_TO_PERFORM;
+               }
+
+               /* Ignore */
+               Debug( LDAP_DEBUG_TRACE,
+                       "searchOptions: conn=%lu unrecognized flag(s) 0x%x (non-critical)\n", 
+                       op->o_connid, (unsigned)search_flags, 0 );
+
+               return LDAP_SUCCESS;
+       }
+
        if ( search_flags & LDAP_SEARCH_FLAG_DOMAIN_SCOPE ) {
                if ( op->o_domain_scope != SLAP_CONTROL_NONE ) {
                        rs->sr_text = "searchOptions control specified multiple times "
@@ -1652,15 +1703,6 @@ static int parseSearchOptions (
                        : SLAP_CONTROL_NONCRITICAL;
        }
 
-       if ( search_flags & ~(LDAP_SEARCH_FLAG_DOMAIN_SCOPE) ) {
-               /* Other search flags not recognised so far,
-                * including:
-                *              LDAP_SEARCH_FLAG_PHANTOM_ROOM
-                */
-               rs->sr_text = "searchOptions contained unrecognized flag";
-               return LDAP_UNWILLING_TO_PERFORM;
-       }
-
        return LDAP_SUCCESS;
 }