/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1999-2007 The OpenLDAP Foundation.
+ * Copyright 1999-2009 The OpenLDAP Foundation.
* Portions Copyright 1999 Dmitry Kovalev.
* Portions Copyright 2002 Pierangelo Masarati.
* Portions Copyright 2004 Mark Adamson.
BER_BVZERO( &bsi->bsi_attrs[ 0 ].an_name );
for ( p = attrs; !BER_BVISNULL( &p->an_name ); p++ ) {
- if ( BACKSQL_NCMP( &p->an_name, &AllUser ) == 0 ) {
+ if ( BACKSQL_NCMP( &p->an_name, slap_bv_all_user_attrs ) == 0 ) {
/* handle "*" */
bsi->bsi_flags |= BSQL_SF_ALL_USER;
}
continue;
- } else if ( BACKSQL_NCMP( &p->an_name, &AllOper ) == 0 ) {
+ } else if ( BACKSQL_NCMP( &p->an_name, slap_bv_all_operational_attrs ) == 0 ) {
/* handle "+" */
bsi->bsi_flags |= BSQL_SF_ALL_OPER;
}
continue;
- } else if ( BACKSQL_NCMP( &p->an_name, &NoAttrs ) == 0 ) {
+ } else if ( BACKSQL_NCMP( &p->an_name, slap_bv_no_attrs ) == 0 ) {
/* ignore "1.1" */
continue;
/* use hints if available */
for ( p = bi->sql_anlist; !BER_BVISNULL( &p->an_name ); p++ ) {
- if ( BACKSQL_NCMP( &p->an_name, &AllUser ) == 0 ) {
+ if ( BACKSQL_NCMP( &p->an_name, slap_bv_all_user_attrs ) == 0 ) {
/* handle "*" */
bsi->bsi_flags |= BSQL_SF_ALL_USER;
}
continue;
- } else if ( BACKSQL_NCMP( &p->an_name, &AllOper ) == 0 ) {
+ } else if ( BACKSQL_NCMP( &p->an_name, slap_bv_all_operational_attrs ) == 0 ) {
/* handle "+" */
bsi->bsi_flags |= BSQL_SF_ALL_OPER;
rs->sr_err = rc;
}
}
+
+ if ( gotit && BACKSQL_IS_GET_OC( flags ) ) {
+ bsi->bsi_base_id.eid_oc = backsql_id2oc( bi,
+ bsi->bsi_base_id.eid_oc_id );
+ if ( bsi->bsi_base_id.eid_oc == NULL ) {
+ /* error? */
+ backsql_free_entryID( &bsi->bsi_base_id, 1,
+ op->o_tmpmemctx );
+ rc = rs->sr_err = LDAP_OTHER;
+ }
+ }
}
bsi->bsi_status = rc;
struct berval keyval;
#else /* ! BACKSQL_ARBITRARY_KEY */
unsigned long keyval;
- char keyvalbuf[] = "18446744073709551615";
+ char keyvalbuf[LDAP_PVT_INTTYPE_CHARS(unsigned long)];
#endif /* ! BACKSQL_ARBITRARY_KEY */
switch ( f->f_choice ) {
(ber_len_t)STRLENOF( "9=9"), "9=9");
} else if ( !BER_BVISNULL( &bi->sql_subtree_cond ) ) {
+ /* This should always be true... */
backsql_strfcat_x( &bsi->bsi_join_where,
bsi->bsi_op->o_tmpmemctx,
"b",
{
lowid = PAGECOOKIE_TO_SQL_ID( ((PagedResultsState *)bsi->bsi_op->o_pagedresults_state)->ps_cookie );
}
+
if ( lowid ) {
char lowidstring[48];
int lowidlen;
- lowidlen = snprintf( lowidstring, 48, " AND ldap_entries.id>%d", lowid );
+ lowidlen = snprintf( lowidstring, sizeof( lowidstring ),
+ " AND ldap_entries.id>%lu", lowid );
backsql_strfcat_x( &bsi->bsi_join_where,
bsi->bsi_op->o_tmpmemctx,
"l",
goto cleanup;
}
#endif /* ! BACKSQL_ARBITRARY_KEY */
+ c_id->eid_oc = bsi->bsi_oc;
c_id->eid_oc_id = bsi->bsi_oc->bom_id;
c_id->eid_dn = pdn;
/* If paged results are in effect, check the paging cookie */
if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
- PagedResultsState *ps = op->o_pagedresults_state;
rs->sr_err = parse_paged_cookie( op, rs );
if ( rs->sr_err != LDAP_SUCCESS ) {
send_ldap_result( op, rs );
* and then send to client; don't free entry_id if baseObject...
*/
for ( eid = bsi.bsi_id_list;
- eid != NULL;
- eid = backsql_free_entryID( op,
- eid, eid == &bsi.bsi_base_id ? 0 : 1 ) )
+ eid != NULL;
+ eid = backsql_free_entryID(
+ eid, eid == &bsi.bsi_base_id ? 0 : 1, op->o_tmpmemctx ) )
{
int rc;
Attribute *a_hasSubordinate = NULL,
rs->sr_ref = NULL;
rs->sr_matched = NULL;
rs->sr_entry = NULL;
+ if ( rs->sr_err == LDAP_REFERRAL ) {
+ rs->sr_err = LDAP_SUCCESS;
+ }
goto next_entry;
}
rs->sr_attrs = op->ors_attrs;
rs->sr_operational_attrs = NULL;
rs->sr_entry = e;
+ e->e_private = (void *)eid;
rs->sr_flags = ( e == &user_entry ) ? REP_ENTRY_MODIFIABLE : 0;
/* FIXME: need the whole entry (ITS#3480) */
rs->sr_err = send_search_entry( op, rs );
+ e->e_private = NULL;
rs->sr_entry = NULL;
rs->sr_attrs = NULL;
rs->sr_operational_attrs = NULL;
/* cleanup in case of abandon */
for ( ; eid != NULL;
- eid = backsql_free_entryID( op,
- eid, eid == &bsi.bsi_base_id ? 0 : 1 ) )
+ eid = backsql_free_entryID(
+ eid, eid == &bsi.bsi_base_id ? 0 : 1, op->o_tmpmemctx ) )
;
backsql_entry_clean( op, &base_entry );
#endif /* BACKSQL_SYNCPROV */
done:;
- (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+ (void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
if ( bsi.bsi_attrs != NULL ) {
op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
*ent = NULL;
rc = backsql_get_db_conn( op, &dbh );
- if ( !dbh ) {
- return LDAP_OTHER;
+ if ( rc != LDAP_SUCCESS ) {
+ return rc;
}
if ( at ) {
BACKSQL_ISF_GET_ENTRY );
if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
- (void)backsql_free_entryID( op, &bsi.bsi_base_id, 0 );
+ (void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
}
if ( rc == LDAP_SUCCESS ) {
{
backsql_entry_clean( op, e );
- ch_free( e );
+ entry_free( e );
return 0;
}
static int
parse_paged_cookie( Operation *op, SlapReply *rs )
{
- LDAPControl **c;
int rc = LDAP_SUCCESS;
- ber_tag_t tag;
- ber_int_t size;
- BerElement *ber;
- struct berval cookie = BER_BVNULL;
PagedResultsState *ps = op->o_pagedresults_state;
/* this function must be invoked only if the pagedResults
* by the frontend */
assert( get_pagedresults( op ) > SLAP_CONTROL_IGNORED );
- /* look for the appropriate ctrl structure */
- for ( c = op->o_ctrls; c[0] != NULL; c++ ) {
- if ( strcmp( c[0]->ldctl_oid, LDAP_CONTROL_PAGEDRESULTS ) == 0 )
- {
- break;
- }
- }
-
- if ( c[0] == NULL ) {
- rs->sr_text = "missing pagedResults control";
- return LDAP_PROTOCOL_ERROR;
- }
-
- /* Tested by frontend */
- assert( c[0]->ldctl_value.bv_len > 0 );
-
- /* Parse the control value
- * realSearchControlValue ::= SEQUENCE {
- * size INTEGER (0..maxInt),
- * -- requested page size from client
- * -- result set size estimate from server
- * cookie OCTET STRING
- * }
- */
- ber = ber_init( &c[0]->ldctl_value );
- if ( ber == NULL ) {
- rs->sr_text = "internal error";
- return LDAP_OTHER;
- }
-
- tag = ber_scanf( ber, "{im}", &size, &cookie );
-
- /* Tested by frontend */
- assert( tag != LBER_ERROR );
- assert( size >= 0 );
-
/* cookie decoding/checks deferred to backend... */
- if ( cookie.bv_len ) {
+ if ( ps->ps_cookieval.bv_len ) {
PagedResultsCookie reqcookie;
- if( cookie.bv_len != sizeof( reqcookie ) ) {
+ if( ps->ps_cookieval.bv_len != sizeof( reqcookie ) ) {
/* bad cookie */
rs->sr_text = "paged results cookie is invalid";
rc = LDAP_PROTOCOL_ERROR;
goto done;
}
- AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie ));
+ AC_MEMCPY( &reqcookie, ps->ps_cookieval.bv_val, sizeof( reqcookie ));
if ( reqcookie > ps->ps_cookie ) {
/* bad cookie */
} 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
ps->ps_cookie = 0;
ps->ps_count = 0;
}
done:;
- (void)ber_free( ber, 1 );
return rc;
}