X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-sql%2Fsearch.c;h=cadd0366dcf6819c3b2cff8a382f533e3bffad91;hb=1c1b5ca0c4cc7da98beff036c0ab54042fe63899;hp=e293151dead64c9c9bff39a209ecfb489452c627;hpb=9066d1429095c0648097fd9c9ded110c28e85e85;p=openldap diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index e293151dea..cadd0366dc 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1999-2007 The OpenLDAP Foundation. + * Copyright 1999-2012 The OpenLDAP Foundation. * Portions Copyright 1999 Dmitry Kovalev. * Portions Copyright 2002 Pierangelo Masarati. * Portions Copyright 2004 Mark Adamson. @@ -48,6 +48,9 @@ static int backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f, and the other 26 for ldap_entries ID number. If your max(oc_map_id) is more than 63, you will need to steal more bits from ldap_entries ID number and put them into the OC ID part of the cookie. */ + +/* NOTE: not supported when BACKSQL_ARBITRARY_KEY is defined */ +#ifndef BACKSQL_ARBITRARY_KEY #define SQL_TO_PAGECOOKIE(id, oc) (((id) << 6 ) | ((oc) & 0x3F)) #define PAGECOOKIE_TO_SQL_ID(pc) ((pc) >> 6) #define PAGECOOKIE_TO_SQL_OC(pc) ((pc) & 0x3F) @@ -58,6 +61,7 @@ static void send_paged_response( Operation *op, SlapReply *rs, ID *lastid ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ static int backsql_attrlist_add( backsql_srch_info *bsi, AttributeDescription *ad ) @@ -184,7 +188,7 @@ backsql_init_search( 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; @@ -198,7 +202,7 @@ backsql_init_search( } 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; @@ -212,7 +216,7 @@ backsql_init_search( } 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; @@ -237,7 +241,7 @@ backsql_init_search( /* 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; @@ -251,7 +255,7 @@ backsql_init_search( } 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; @@ -717,6 +721,16 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) goto done; } + if ( f->f_choice & SLAPD_FILTER_UNDEFINED ) { + backsql_strfcat_x( &bsi->bsi_flt_where, + bsi->bsi_op->o_tmpmemctx, + "l", + (ber_len_t)STRLENOF( "1=0" ), "1=0" ); + done = 1; + rc = 1; + goto done; + } + switch( f->f_choice ) { case LDAP_FILTER_OR: rc = backsql_process_filter_list( bsi, f->f_or, @@ -864,7 +878,7 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) 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 ) { @@ -914,7 +928,7 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) #ifdef BACKSQL_SYNCPROV } else if ( ad == slap_schema.si_ad_entryCSN ) { /* - * support for syncrepl as producer... + * support for syncrepl as provider... */ #if 0 if ( !bsi->bsi_op->o_sync ) { @@ -1192,6 +1206,14 @@ backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f, backsql_at_map_r &at->bam_join_where ); } + if ( f->f_choice & SLAPD_FILTER_UNDEFINED ) { + backsql_strfcat_x( &bsi->bsi_flt_where, + bsi->bsi_op->o_tmpmemctx, + "l", + (ber_len_t)STRLENOF( "1=0" ), "1=0" ); + return 1; + } + switch ( f->f_choice ) { case LDAP_FILTER_EQUALITY: filter_value = &f->f_av_value; @@ -1551,6 +1573,7 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) assert( 0 ); } +#ifndef BACKSQL_ARBITRARY_KEY /* If paged results are in effect, ignore low ldap_entries.id numbers */ if ( get_pagedresults(bsi->bsi_op) > SLAP_CONTROL_IGNORED ) { unsigned long lowid = 0; @@ -1574,6 +1597,7 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) lowidstring ); } } +#endif /* ! BACKSQL_ARBITRARY_KEY */ rc = backsql_process_filter( bsi, bsi->bsi_filter ); if ( rc > 0 ) { @@ -1654,6 +1678,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) return BACKSQL_AVL_STOP; } +#ifndef BACKSQL_ARBITRARY_KEY /* If paged results have already completed this objectClass, skip it */ if ( get_pagedresults(op) > SLAP_CONTROL_IGNORED ) { if ( oc->bom_id < PAGECOOKIE_TO_SQL_OC( ((PagedResultsState *)op->o_pagedresults_state)->ps_cookie ) ) @@ -1661,6 +1686,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) return BACKSQL_AVL_CONTINUE; } } +#endif /* ! BACKSQL_ARBITRARY_KEY */ if ( bsi->bsi_n_candidates == -1 ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " @@ -1720,9 +1746,10 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) return BACKSQL_AVL_CONTINUE; } - Debug( LDAP_DEBUG_TRACE, "id: '%ld'\n", bsi->bsi_oc->bom_id, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "id: '" BACKSQL_IDNUMFMT "'\n", + bsi->bsi_oc->bom_id, 0, 0 ); - rc = backsql_BindParamInt( sth, 1, SQL_PARAM_INPUT, + rc = backsql_BindParamNumID( sth, 1, SQL_PARAM_INPUT, &bsi->bsi_oc->bom_id ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " @@ -1857,13 +1884,8 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) case LDAP_SCOPE_ONELEVEL: assert( !BER_BVISNULL( &bsi->bsi_base_id.eid_ndn ) ); -#ifdef BACKSQL_ARBITRARY_KEY - Debug( LDAP_DEBUG_TRACE, "(one)id: \"%s\"\n", - bsi->bsi_base_id.eid_id.bv_val, 0, 0 ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - Debug( LDAP_DEBUG_TRACE, "(one)id: '%lu'\n", - bsi->bsi_base_id.eid_id, 0, 0 ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + Debug( LDAP_DEBUG_TRACE, "(one)id=" BACKSQL_IDFMT "\n", + BACKSQL_IDARG(bsi->bsi_base_id.eid_id), 0, 0 ); rc = backsql_BindParamID( sth, 2, SQL_PARAM_INPUT, &bsi->bsi_base_id.eid_id ); if ( rc != SQL_SUCCESS ) { @@ -1919,10 +1941,10 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) ber_str2bv_x( row.cols[ 1 ], 0, 1, &c_id->eid_keyval, op->o_tmpmemctx ); #else /* ! BACKSQL_ARBITRARY_KEY */ - if ( lutil_atoulx( &c_id->eid_id, row.cols[ 0 ], 0 ) != 0 ) { + if ( BACKSQL_STR2ID( &c_id->eid_id, row.cols[ 0 ], 0 ) != 0 ) { goto cleanup; } - if ( lutil_atoulx( &c_id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) { + if ( BACKSQL_STR2ID( &c_id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) { goto cleanup; } #endif /* ! BACKSQL_ARBITRARY_KEY */ @@ -1937,16 +1959,11 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) *bsi->bsi_id_listtail = c_id; bsi->bsi_id_listtail = &c_id->eid_next; -#ifdef BACKSQL_ARBITRARY_KEY Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " - "added entry id=%s, keyval=%s dn=\"%s\"\n", - c_id->eid_id.bv_val, c_id->eid_keyval.bv_val, + "added entry id=" BACKSQL_IDFMT " keyval=" BACKSQL_IDFMT " dn=\"%s\"\n", + BACKSQL_IDARG(c_id->eid_id), + BACKSQL_IDARG(c_id->eid_keyval), row.cols[ 3 ] ); -#else /* ! BACKSQL_ARBITRARY_KEY */ - Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " - "added entry id=%ld, keyval=%ld dn=\"%s\"\n", - c_id->eid_id, c_id->eid_keyval, row.cols[ 3 ] ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ /* count candidates, for unchecked limit */ bsi->bsi_n_candidates--; @@ -1988,7 +2005,9 @@ backsql_search( Operation *op, SlapReply *rs ) backsql_srch_info bsi = { 0 }; backsql_entryID *eid = NULL; struct berval nbase = BER_BVNULL; - unsigned long lastid = 0; +#ifndef BACKSQL_ARBITRARY_KEY + ID lastid = 0; +#endif /* ! BACKSQL_ARBITRARY_KEY */ Debug( LDAP_DEBUG_TRACE, "==>backsql_search(): " "base=\"%s\", filter=\"%s\", scope=%d,", @@ -2125,6 +2144,7 @@ backsql_search( Operation *op, SlapReply *rs ) ( op->ors_limit->lms_s_unchecked == -1 ? -2 : ( op->ors_limit->lms_s_unchecked ) ) ); +#ifndef BACKSQL_ARBITRARY_KEY /* If paged results are in effect, check the paging cookie */ if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) { rs->sr_err = parse_paged_cookie( op, rs ); @@ -2133,6 +2153,7 @@ backsql_search( Operation *op, SlapReply *rs ) goto done; } } +#endif /* ! BACKSQL_ARBITRARY_KEY */ switch ( bsi.bsi_scope ) { case LDAP_SCOPE_BASE: @@ -2216,16 +2237,11 @@ backsql_search( Operation *op, SlapReply *rs ) goto send_results; } -#ifdef BACKSQL_ARBITRARY_KEY - Debug(LDAP_DEBUG_TRACE, "backsql_search(): loading data " - "for entry id=%s, oc_id=%ld, keyval=%s\n", - eid->eid_id.bv_val, eid->eid_oc_id, - eid->eid_keyval.bv_val ); -#else /* ! BACKSQL_ARBITRARY_KEY */ Debug(LDAP_DEBUG_TRACE, "backsql_search(): loading data " - "for entry id=%ld, oc_id=%ld, keyval=%ld\n", - eid->eid_id, eid->eid_oc_id, eid->eid_keyval ); -#endif /* ! BACKSQL_ARBITRARY_KEY */ + "for entry id=" BACKSQL_IDFMT " oc_id=" BACKSQL_IDNUMFMT ", keyval=" BACKSQL_IDFMT "\n", + BACKSQL_IDARG(eid->eid_id), + eid->eid_oc_id, + BACKSQL_IDARG(eid->eid_keyval) ); /* check scope */ switch ( op->ors_scope ) { @@ -2340,6 +2356,9 @@ backsql_search( Operation *op, SlapReply *rs ) 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; } @@ -2406,6 +2425,7 @@ backsql_search( Operation *op, SlapReply *rs ) if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE ) { +#ifndef BACKSQL_ARBITRARY_KEY /* If paged results are in effect, see if the page limit was exceeded */ if ( get_pagedresults(op) > SLAP_CONTROL_IGNORED ) { if ( rs->sr_nentries >= ((PagedResultsState *)op->o_pagedresults_state)->ps_size ) @@ -2416,6 +2436,7 @@ backsql_search( Operation *op, SlapReply *rs ) } lastid = SQL_TO_PAGECOOKIE( eid->eid_id, eid->eid_oc_id ); } +#endif /* ! BACKSQL_ARBITRARY_KEY */ rs->sr_attrs = op->ors_attrs; rs->sr_operational_attrs = NULL; rs->sr_entry = e; @@ -2463,9 +2484,12 @@ end_of_search:; send_results:; if ( rs->sr_err != SLAPD_ABANDON ) { +#ifndef BACKSQL_ARBITRARY_KEY if ( get_pagedresults(op) > SLAP_CONTROL_IGNORED ) { send_paged_response( op, rs, NULL ); - } else { + } else +#endif /* ! BACKSQL_ARBITRARY_KEY */ + { send_ldap_result( op, rs ); } } @@ -2489,7 +2513,7 @@ send_results:; #ifdef BACKSQL_SYNCPROV if ( op->o_sync ) { Operation op2 = *op; - SlapReply rs2 = { 0 }; + SlapReply rs2 = { REP_RESULT }; Entry *e = entry_alloc(); slap_callback cb = { 0 }; @@ -2660,17 +2684,12 @@ backsql_entry_release( return 0; } - +#ifndef BACKSQL_ARBITRARY_KEY /* This function is copied verbatim from back-bdb/search.c */ 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 @@ -2678,53 +2697,17 @@ parse_paged_cookie( Operation *op, SlapReply *rs ) * 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 */ @@ -2740,22 +2723,11 @@ parse_paged_cookie( Operation *op, SlapReply *rs ) } 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; } @@ -2765,7 +2737,7 @@ static void send_paged_response( Operation *op, SlapReply *rs, - unsigned long *lastid ) + ID *lastid ) { LDAPControl ctrl, *ctrls[2]; BerElementBuffer berbuf; @@ -2816,3 +2788,4 @@ send_paged_response( done: (void) ber_free_buf( ber ); } +#endif /* ! BACKSQL_ARBITRARY_KEY */