]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/search.c
Suck in HEAD changes since 2.1alpha
[openldap] / servers / slapd / back-bdb / search.c
1 /* search.c - search operation */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12
13 #include "back-bdb.h"
14 #include "idl.h"
15 #include "external.h"
16
17 static int base_candidate(
18         BackendDB       *be,
19         Entry   *e,
20         ID              *ids );
21 static int search_candidates(
22         BackendDB *be,
23         Operation *op,
24         Entry *e,
25         Filter *filter,
26         int scope,
27         int deref,
28         ID      *ids );
29
30 int
31 bdb_search(
32         BackendDB       *be,
33         Connection      *conn,
34         Operation       *op,
35         struct berval   *base,
36         struct berval   *nbase,
37         int             scope,
38         int             deref,
39         int             slimit,
40         int             tlimit,
41         Filter  *filter,
42         struct berval   *filterstr,
43         AttributeName   *attrs,
44         int             attrsonly )
45 {
46         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
47         int             rc;
48         const char *text = NULL;
49         time_t          stoptime;
50         ID              id, cursor;
51         ID              candidates[BDB_IDL_UM_SIZE];
52         Entry           *e = NULL;
53         BerVarray v2refs = NULL;
54         Entry   *matched = NULL;
55         struct berval   realbase = { 0, NULL };
56         int             nentries = 0;
57         int             manageDSAit;
58
59         struct slap_limits_set *limit = NULL;
60         int isroot = 0;
61
62 #ifdef NEW_LOGGING
63         LDAP_LOG (( "search", LDAP_LEVEL_ENTRY,"bdb_back_search\n"));
64 #else
65         Debug( LDAP_DEBUG_TRACE, "=> bdb_back_search\n",
66                 0, 0, 0);
67 #endif
68
69         manageDSAit = get_manageDSAit( op );
70
71         if ( nbase->bv_len == 0 ) {
72                 /* DIT root special case */
73                 e = (Entry *) &slap_entry_root;
74                 rc = 0;
75         } else                                          
76 #ifdef BDB_ALIASES
77         /* get entry with reader lock */
78         if ( deref & LDAP_DEREF_FINDING ) {
79                 e = deref_dn_r( be, nbase-, &err, &matched, &text );
80
81         } else
82 #endif
83         {
84                 rc = bdb_dn2entry_r( be, NULL, nbase, &e, &matched, 0 );
85         }
86
87         switch(rc) {
88         case DB_NOTFOUND:
89         case 0:
90                 break;
91         default:
92                 if (e != NULL) {
93                         bdb_cache_return_entry_r(&bdb->bi_cache, e);
94                 }
95                 if (matched != NULL) {
96                         bdb_cache_return_entry_r(&bdb->bi_cache, matched);
97                 }
98                 send_ldap_result( conn, op, rc=LDAP_OTHER,
99                         NULL, "internal error", NULL, NULL );
100                 return rc;
101         }
102
103         if ( e == NULL ) {
104                 struct berval matched_dn = { 0, NULL };
105                 BerVarray refs = NULL;
106
107                 if ( matched != NULL ) {
108                         BerVarray erefs;
109
110                         ber_dupbv( &matched_dn, &matched->e_name );
111
112                         erefs = is_entry_referral( matched )
113                                 ? get_entry_referrals( be, conn, op, matched )
114                                 : NULL;
115
116                         bdb_cache_return_entry_r (&bdb->bi_cache, matched);
117                         matched = NULL;
118
119                         if( erefs ) {
120                                 refs = referral_rewrite( erefs, &matched_dn,
121                                         base, scope );
122                                 ber_bvarray_free( erefs );
123                         }
124
125                 } else {
126                         refs = referral_rewrite( default_referral,
127                                 NULL, base, scope );
128                 }
129
130                 send_ldap_result( conn, op,     rc=LDAP_REFERRAL ,
131                         matched_dn.bv_val, text, refs, NULL );
132
133                 if ( refs ) ber_bvarray_free( refs );
134                 if ( matched_dn.bv_val ) ber_memfree( matched_dn.bv_val );
135                 return rc;
136         }
137
138         if (!manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
139                 /* entry is a referral, don't allow add */
140                 struct berval matched_dn;
141                 BerVarray erefs, refs;
142                 
143                 ber_dupbv( &matched_dn, &e->e_name );
144                 erefs = get_entry_referrals( be, conn, op, e );
145                 refs = NULL;
146
147                 bdb_cache_return_entry_r( &bdb->bi_cache, e );
148                 e = NULL;
149
150                 if( erefs ) {
151                         refs = referral_rewrite( erefs, &matched_dn,
152                                 base, scope );
153                         ber_bvarray_free( erefs );
154                 }
155
156 #ifdef NEW_LOGGING
157                 LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: entry is referral\n"));
158 #else
159                 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
160                         0, 0, 0 );
161 #endif
162
163                 send_ldap_result( conn, op, LDAP_REFERRAL,
164                         matched_dn.bv_val,
165                         refs ? NULL : "bad referral object",
166                         refs, NULL );
167
168                 ber_bvarray_free( refs );
169                 ber_memfree( matched_dn.bv_val );
170                 return 1;
171         }
172
173         /* if not root, get appropriate limits */
174         if ( be_isroot( be, &op->o_ndn ) ) {
175                 isroot = 1;
176         } else {
177                 ( void ) get_limits( be, &op->o_ndn, &limit );
178         }
179
180         /* The time/size limits come first because they require very little
181          * effort, so there's no chance the candidates are selected and then 
182          * the request is not honored only because of time/size constraints */
183
184         /* if no time limit requested, use soft limit (unless root!) */
185         if ( isroot ) {
186                 if ( tlimit == 0 ) {
187                         tlimit = -1;    /* allow root to set no limit */
188                 }
189
190                 if ( slimit == 0 ) {
191                         slimit = -1;
192                 }
193
194         } else {
195                 /* if no limit is required, use soft limit */
196                 if ( tlimit <= 0 ) {
197                         tlimit = limit->lms_t_soft;
198
199                 /* if requested limit higher than hard limit, abort */
200                 } else if ( tlimit > limit->lms_t_hard ) {
201                         /* no hard limit means use soft instead */
202                         if ( limit->lms_t_hard == 0 ) {
203                                 tlimit = limit->lms_t_soft;
204
205                         /* positive hard limit means abort */
206                         } else if ( limit->lms_t_hard > 0 ) {
207                                 send_search_result( conn, op, 
208                                                 LDAP_UNWILLING_TO_PERFORM,
209                                                 NULL, NULL, NULL, NULL, 0 );
210                                 rc = 0;
211                                 goto done;
212                         }
213                 
214                         /* negative hard limit means no limit */
215                 }
216                 
217                 /* if no limit is required, use soft limit */
218                 if ( slimit <= 0 ) {
219                         slimit = limit->lms_s_soft;
220
221                 /* if requested limit higher than hard limit, abort */
222                 } else if ( slimit > limit->lms_s_hard ) {
223                         /* no hard limit means use soft instead */
224                         if ( limit->lms_s_hard == 0 ) {
225                                 slimit = limit->lms_s_soft;
226
227                         /* positive hard limit means abort */
228                         } else if ( limit->lms_s_hard > 0 ) {
229                                 send_search_result( conn, op, 
230                                                 LDAP_UNWILLING_TO_PERFORM,
231                                                 NULL, NULL, NULL, NULL, 0 );
232                                 rc = 0; 
233                                 goto done;
234                         }
235                         
236                         /* negative hard limit means no limit */
237                 }
238         }
239
240         /* compute it anyway; root does not use it */
241         stoptime = op->o_time + tlimit;
242
243         /* select candidates */
244         if ( scope == LDAP_SCOPE_BASE ) {
245                 rc = base_candidate( be, e, candidates );
246
247         } else {
248                 BDB_IDL_ALL( bdb, candidates );
249                 rc = search_candidates( be, op, e, filter,
250                         scope, deref, candidates );
251         }
252
253         /* need normalized dn below */
254         ber_dupbv( &realbase, &e->e_nname );
255
256         /* start cursor at base entry's id 
257          * FIXME: hack to make "" base work
258          * FIXME: moddn needs to assign new ID for this to work
259          */
260         cursor = e->e_id == NOID ? 1 : e->e_id;
261
262         if ( e != &slap_entry_root ) {
263                 bdb_cache_return_entry_r(&bdb->bi_cache, e);
264         }
265         e = NULL;
266
267         if ( candidates[0] == 0 ) {
268 #ifdef NEW_LOGGING
269         LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: no candidates\n"));
270 #else
271                 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
272                         0, 0, 0 );
273 #endif
274
275                 send_search_result( conn, op,
276                         LDAP_SUCCESS,
277                         NULL, NULL, NULL, NULL, 0 );
278
279                 rc = 1;
280                 goto done;
281         }
282
283         /* if not root and candidates exceed to-be-checked entries, abort */
284         if ( !isroot && limit->lms_s_unchecked != -1 ) {
285                 if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
286                         send_search_result( conn, op, 
287                                         LDAP_UNWILLING_TO_PERFORM,
288                                         NULL, NULL, NULL, NULL, 0 );
289                         rc = 1;
290                         goto done;
291                 }
292         }
293
294         for ( id = bdb_idl_first( candidates, &cursor );
295                 id != NOID;
296                 id = bdb_idl_next( candidates, &cursor ) )
297         {
298                 int             scopeok = 0;
299
300                 /* check for abandon */
301                 if ( op->o_abandon ) {
302                         rc = 0;
303                         goto done;
304                 }
305
306                 /* check time limit */
307                 if ( tlimit != -1 && slap_get_time() > stoptime ) {
308                         send_search_result( conn, op, rc = LDAP_TIMELIMIT_EXCEEDED,
309                                 NULL, NULL, v2refs, NULL, nentries );
310                         goto done;
311                 }
312
313                 /* get the entry with reader lock */
314                 rc = bdb_id2entry_r( be, NULL, id, &e );
315
316                 if ( e == NULL ) {
317                         if( !BDB_IDL_IS_RANGE(candidates) ) {
318                                 /* only complain for non-range IDLs */
319 #ifdef NEW_LOGGING
320                                 LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: candidate %ld not found\n", (long) id));
321 #else
322                                 Debug( LDAP_DEBUG_TRACE,
323                                         "bdb_search: candidate %ld not found\n",
324                                         (long) id, 0, 0 );
325 #endif
326                         }
327
328                         goto loop_continue;
329                 }
330
331 #ifdef BDB_SUBENTRIES
332                 if ( is_entry_subentry( e ) ) {
333                         if( scope != LDAP_SCOPE_BASE ) {
334                                 if(!get_subentries_visibility( op )) {
335                                         /* only subentries are visible */
336                                         goto loop_continue;
337                                 }
338
339                         } else if ( get_subentries( op ) &&
340                                 !get_subentries_visibility( op ))
341                         {
342                                 /* only subentries are visible */
343                                 goto loop_continue;
344                         }
345
346                 } else if ( get_subentries_visibility( op )) {
347                         /* only subentries are visible */
348                         goto loop_continue;
349                 }
350 #endif
351
352 #ifdef BDB_ALIASES
353                 if ( deref & LDAP_DEREF_SEARCHING && is_entry_alias( e ) ) {
354                         Entry *matched;
355                         int err;
356                         const char *text;
357                         
358                         e = deref_entry_r( be, e, &err, &matched, &text );
359
360                         if( e == NULL ) {
361                                 e = matched;
362                                 goto loop_continue;
363                         }
364
365                         if( e->e_id == id ) {
366                                 /* circular loop */
367                                 goto loop_continue;
368                         }
369
370                         /* need to skip alias which deref into scope */
371                         if( scope & LDAP_SCOPE_ONELEVEL ) {
372                                 struct berval   pdn;
373                                 
374                                 dnParent( &e->e_nname, &pdn ):
375                                 if ( ber_bvcmp( pdn, &realbase ) ) {
376                                         goto loop_continue;
377                                 }
378
379                         } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) {
380                                 /* alias is within scope */
381 #ifdef NEW_LOGGING
382                                 LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: \"%s\" in subtree\n", e->edn));
383 #else
384                                 Debug( LDAP_DEBUG_TRACE,
385                                         "bdb_search: \"%s\" in subtree\n",
386                                         e->e_dn, 0, 0 );
387 #endif
388                                 goto loop_continue;
389                         }
390
391                         scopeok = 1;
392                 }
393 #endif
394
395                 /*
396                  * if it's a referral, add it to the list of referrals. only do
397                  * this for non-base searches, and don't check the filter
398                  * explicitly here since it's only a candidate anyway.
399                  */
400                 if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
401                         is_entry_referral( e ) )
402                 {
403                         BerVarray erefs = get_entry_referrals(
404                                 be, conn, op, e );
405                         BerVarray refs = referral_rewrite( erefs,
406                                 &e->e_name, NULL,
407                                 scope == LDAP_SCOPE_SUBTREE 
408                                         ? LDAP_SCOPE_SUBTREE
409                                         : LDAP_SCOPE_BASE );
410
411                         send_search_reference( be, conn, op,
412                                 e, refs, NULL, &v2refs );
413
414                         ber_bvarray_free( refs );
415
416                         goto loop_continue;
417                 }
418
419                 /* if it matches the filter and scope, send it */
420                 rc = test_filter( be, conn, op, e, filter );
421                 if ( rc == LDAP_COMPARE_TRUE ) {
422                         struct berval   dn;
423
424                         /* check scope */
425                         if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
426                                 if ( be_issuffix( be, &e->e_nname ) ) {
427                                         scopeok = (realbase.bv_len == 0);
428                                 } else {
429                                         dnParent( &e->e_nname, &dn );
430                                         scopeok = dn_match( &dn, &realbase );
431                                 }
432
433                         } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
434                                 scopeok = dnIsSuffix( &e->e_nname, &realbase );
435
436                         } else {
437                                 scopeok = 1;
438                         }
439
440                         if ( scopeok ) {
441                                 /* check size limit */
442                                 if ( --slimit == -1 ) {
443                                         bdb_cache_return_entry_r (&bdb->bi_cache, e);
444                                         e = NULL;
445                                         send_search_result( conn, op,
446                                                 rc = LDAP_SIZELIMIT_EXCEEDED, NULL, NULL,
447                                                 v2refs, NULL, nentries );
448                                         goto done;
449                                 }
450
451                                 if (e) {
452                                         int result;
453                                         
454                                         if( op->o_noop ) {
455                                                 result = 0;
456                                         } else {
457                                                 result = send_search_entry( be, conn, op,
458                                                         e, attrs, attrsonly, NULL);
459                                         }
460
461                                         switch (result) {
462                                         case 0:         /* entry sent ok */
463                                                 nentries++;
464                                                 break;
465                                         case 1:         /* entry not sent */
466                                                 break;
467                                         case -1:        /* connection closed */
468                                                 bdb_cache_return_entry_r(&bdb->bi_cache, e);
469                                                 e = NULL;
470                                                 rc = LDAP_OTHER;
471                                                 goto done;
472                                         }
473                                 }
474                         } else {
475 #ifdef NEW_LOGGING
476                                 LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: %ld scope not okay\n", (long) id));
477 #else
478                                 Debug( LDAP_DEBUG_TRACE,
479                                         "bdb_search: %ld scope not okay\n",
480                                         (long) id, 0, 0 );
481 #endif
482                         }
483                 } else {
484 #ifdef NEW_LOGGING
485                                 LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: %ld does match filter\n", (long) id));
486 #else
487                         Debug( LDAP_DEBUG_TRACE,
488                                 "bdb_search: %ld does match filter\n",
489                                 (long) id, 0, 0 );
490 #endif
491                 }
492
493 loop_continue:
494                 if( e != NULL ) {
495                         /* free reader lock */
496                         bdb_cache_return_entry_r ( &bdb->bi_cache, e );
497                         e = NULL;
498                 }
499
500                 ldap_pvt_thread_yield();
501         }
502         send_search_result( conn, op,
503                 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
504                 NULL, NULL, v2refs, NULL, nentries );
505
506         rc = 0;
507
508 done:
509         if( e != NULL ) {
510                 /* free reader lock */
511                 bdb_cache_return_entry_r ( &bdb->bi_cache, e );
512         }
513
514         if( v2refs ) ber_bvarray_free( v2refs );
515         if( realbase.bv_val ) ch_free( realbase.bv_val );
516
517         return rc;
518 }
519
520
521 static int base_candidate(
522         BackendDB       *be,
523         Entry   *e,
524         ID              *ids )
525 {
526 #ifdef NEW_LOGGING
527         LDAP_LOG (( "search", LDAP_LEVEL_ENTRY,"base_candidate: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id));
528 #else
529         Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
530                 e->e_dn, (long) e->e_id, 0);
531 #endif
532
533         ids[0] = 1;
534         ids[1] = e->e_id;
535         return 0;
536 }
537
538 /* Is "objectClass=xx" mentioned anywhere in this filter? Presence
539  * doesn't count, we're looking for explicit values. Also count depth
540  * of filter tree while we're at it.
541  */
542 static int oc_filter(
543         Filter *f,
544         int cur,
545         int *max
546 )
547 {
548         int rc = 0;
549
550         if( cur > *max ) *max = cur;
551
552         switch(f->f_choice) {
553         case LDAP_FILTER_EQUALITY:
554         case LDAP_FILTER_APPROX:
555                 if (f->f_av_desc == slap_schema.si_ad_objectClass)
556                         rc = 1;
557                 break;
558
559         case LDAP_FILTER_SUBSTRINGS:
560                 if (f->f_sub_desc == slap_schema.si_ad_objectClass)
561                         rc = 1;
562                 break;
563
564         case LDAP_FILTER_AND:
565         case LDAP_FILTER_OR:
566                 cur++;
567                 for (f=f->f_and; f; f=f->f_next)
568                         if ((rc = oc_filter(f, cur, max)))
569                                 break;
570                 break;
571         default:
572                 break;
573         }
574         return rc;
575 }
576
577 static int search_candidates(
578         BackendDB *be,
579         Operation *op,
580         Entry *e,
581         Filter *filter,
582         int scope,
583         int deref,
584         ID      *ids )
585 {
586         int rc, depth = 1;
587         Filter          f, scopef, rf, xf;
588         ID              *stack;
589         AttributeAssertion aa_ref;
590 #ifdef BDB_SUBENTRIES
591         Filter  sf;
592         AttributeAssertion aa_subentry;
593 #endif
594 #ifdef BDB_ALIASES
595         Filter  af;
596         AttributeAssertion aa_alias;
597 #endif
598
599         /*
600          * This routine takes as input a filter (user-filter)
601          * and rewrites it as follows:
602          *      (&(scope=DN)[(objectClass=subentry)]
603          *              (|[(objectClass=referral)(objectClass=alias)](user-filter))
604          */
605
606 #ifdef NEW_LOGGING
607         LDAP_LOG (( "search", LDAP_LEVEL_ENTRY,"search_candidates: base=\"%s\" (0x%08lx) scope=%d\n", e->e_dn, (long) e->e_id, scope));
608 #else
609         Debug(LDAP_DEBUG_TRACE,
610                 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
611                 e->e_dn, (long) e->e_id, scope );
612 #endif
613
614         xf.f_or = filter;
615         xf.f_choice = LDAP_FILTER_OR;
616         xf.f_next = NULL;
617
618         /* If the user's filter doesn't mention objectClass, or if
619          * it just uses objectClass=*, these clauses are redundant.
620          */
621         if (oc_filter(filter, 1, &depth) && !get_subentries_visibility(op) ) {
622                 if( !get_manageDSAit(op) ) { /* match referrals */
623                         struct berval bv_ref = { sizeof("REFERRAL")-1, "REFERRAL" };
624                         rf.f_choice = LDAP_FILTER_EQUALITY;
625                         rf.f_ava = &aa_ref;
626                         rf.f_av_desc = slap_schema.si_ad_objectClass;
627                         rf.f_av_value = bv_ref;
628                         rf.f_next = xf.f_or;
629                         xf.f_or = &rf;
630                 }
631
632 #ifdef BDB_ALIASES
633                 if( deref & LDAP_DEREF_SEARCHING ) { /* match aliases */
634                         struct berval bv_alias = { sizeof("ALIAS")-1, "ALIAS" };
635                         af.f_choice = LDAP_FILTER_EQUALITY;
636                         af.f_ava = &aa_alias;
637                         af.f_av_desc = slap_schema.si_ad_objectClass;
638                         af.f_av_value = bv_alias;
639                         af.f_next = xf.f_or;
640                         xf.f_or = &af;
641                 }
642 #endif
643                 /* We added one of these clauses, filter depth increased */
644                 if( xf.f_or != filter ) depth++;
645         }
646
647         f.f_next = NULL;
648         f.f_choice = LDAP_FILTER_AND;
649         f.f_and = &scopef;
650         scopef.f_choice = scope == LDAP_SCOPE_SUBTREE
651                 ? SLAPD_FILTER_DN_SUBTREE
652                 : SLAPD_FILTER_DN_ONE;
653         scopef.f_dn = &e->e_nname;
654         scopef.f_next = xf.f_or == filter ? filter : &xf ;
655         /* Filter depth increased again, adding scope clause */
656         depth++;
657
658 #ifdef BDB_SUBENTRIES
659         if( get_subentries_visibility( op ) ) {
660                 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
661                 sf.f_choice = LDAP_FILTER_EQUALITY;
662                 sf.f_ava = &aa_subentry;
663                 sf.f_av_desc = slap_schema.si_ad_objectClass;
664                 sf.f_av_value = bv_subentry;
665                 sf.f_next = scopef.f_next;
666                 scopef.f_next = &sf;
667         }
668 #endif
669
670         /* Allocate IDL stack, plus 1 more for former tmp */
671         stack = malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
672
673         rc = bdb_filter_candidates( be, &f, ids, stack, stack+BDB_IDL_UM_SIZE );
674
675         free( stack );
676
677         if( rc ) {
678 #ifdef NEW_LOGGING
679         LDAP_LOG (( "search", LDAP_LEVEL_DETAIL1,"bdb_search_candidates: failed (rc=%d)\n", rc));
680 #else
681                 Debug(LDAP_DEBUG_TRACE,
682                         "bdb_search_candidates: failed (rc=%d)\n",
683                         rc, NULL, NULL );
684 #endif
685
686         } else {
687 #ifdef NEW_LOGGING
688                 LDAP_LOG (( "search", LDAP_LEVEL_DETAIL1,"bdb_search_candidates: id=%ld first=%ld last=%ld\n", (long) ids[0], (long) BDB_IDL_FIRST(ids), (long) BDB_IDL_LAST(ids)));
689 #else
690                 Debug(LDAP_DEBUG_TRACE,
691                         "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
692                         (long) ids[0],
693                         (long) BDB_IDL_FIRST(ids),
694                         (long) BDB_IDL_LAST(ids) );
695 #endif
696         }
697
698         return rc;
699 }