]> git.sur5r.net Git - openldap/blob - servers/slapd/dn.c
3ba5acff7ac4a8ffc05a68c02b35a626060c761d
[openldap] / servers / slapd / dn.c
1 /* dn.c - routines for dealing with distinguished names */
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
12 #include <ac/ctype.h>
13 #include <ac/socket.h>
14 #include <ac/string.h>
15 #include <ac/time.h>
16
17 #include "ldap_pvt.h"
18
19 #include "slap.h"
20
21 const struct berval slap_empty_bv = { 0, "" };
22
23 #define SLAP_LDAPDN_PRETTY 0x1
24
25 #define SLAP_LDAPDN_MAXLEN 8192
26
27 /*
28  * The DN syntax-related functions take advantage of the dn representation
29  * handling functions ldap_str2dn/ldap_dn2str.  The latter are not schema-
30  * aware, so the attributes and their values need be validated (and possibly
31  * normalized).  In the current implementation the required validation/nor-
32  * malization/"pretty"ing are done on newly created DN structural represen-
33  * tations; however the idea is to move towards DN handling in structural
34  * representation instead of the current string representation.  To this
35  * purpose, we need to do only the required operations and keep track of
36  * what has been done to minimize their impact on performances.
37  *
38  * Developers are strongly encouraged to use this feature, to speed-up
39  * its stabilization.
40  */
41
42 #define AVA_PRIVATE( ava ) ( ( AttributeDescription * )(ava)->la_private )
43
44 /*
45  * In-place, schema-aware validation of the
46  * structural representation of a distinguished name.
47  */
48 static int
49 LDAPDN_validate( LDAPDN *dn )
50 {
51         int             iRDN;
52         int             rc;
53
54         assert( dn );
55
56         for ( iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
57                 LDAPRDN         *rdn = dn[ 0 ][ iRDN ];
58                 int             iAVA;
59
60                 assert( rdn );
61
62                 for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
63                         LDAPAVA                 *ava = rdn[ 0 ][ iAVA ];
64                         AttributeDescription    *ad;
65                         slap_syntax_validate_func *validate = NULL;
66
67                         assert( ava );
68                         
69                         if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
70                                 const char      *text = NULL;
71
72                                 rc = slap_bv2ad( &ava->la_attr, &ad, &text );
73                                 if ( rc != LDAP_SUCCESS ) {
74                                         return LDAP_INVALID_SYNTAX;
75                                 }
76
77                                 ava->la_private = ( void * )ad;
78                         }
79
80                         /* 
81                          * Replace attr oid/name with the canonical name
82                          */
83                         ava->la_attr = ad->ad_cname;
84
85                         validate = ad->ad_type->sat_syntax->ssyn_validate;
86
87                         if ( validate ) {
88                                 /*
89                                  * validate value by validate function
90                                  */
91                                 rc = ( *validate )( ad->ad_type->sat_syntax,
92                                         &ava->la_value );
93                         
94                                 if ( rc != LDAP_SUCCESS ) {
95                                         return LDAP_INVALID_SYNTAX;
96                                 }
97                         }
98                 }
99         }
100
101         return LDAP_SUCCESS;
102 }
103
104 /*
105  * dn validate routine
106  */
107 int
108 dnValidate(
109         Syntax *syntax,
110         struct berval *in )
111 {
112         int             rc;
113         LDAPDN          *dn = NULL;
114
115         assert( in );
116
117         if ( in->bv_len == 0 ) {
118                 return LDAP_SUCCESS;
119
120         } else if ( in->bv_len > SLAP_LDAPDN_MAXLEN ) {
121                 return LDAP_INVALID_SYNTAX;
122         }
123
124         rc = ldap_bv2dn( in, &dn, LDAP_DN_FORMAT_LDAP );
125         if ( rc != LDAP_SUCCESS ) {
126                 return LDAP_INVALID_SYNTAX;
127         }
128
129         assert( strlen( in->bv_val ) == in->bv_len );
130
131         /*
132          * Schema-aware validate
133          */
134         rc = LDAPDN_validate( dn );
135         if ( rc == LDAP_SUCCESS ) {
136                 ldap_dnfree( dn );
137         }
138         
139         return LDAP_INVALID_SYNTAX;
140 }
141
142 /*
143  * AVA sorting inside a RDN
144  *
145  * rule: sort attributeTypes in alphabetical order; in case of multiple
146  * occurrences of the same attributeType, sort values in byte order
147  * (use memcmp, which implies alphabetical order in case of IA5 value;
148  * this should guarantee the repeatability of the operation).
149  *
150  * Note: the sorting can be slightly improved by sorting first
151  * by attribute type length, then by alphabetical order.
152  *
153  * uses a linear search; should be fine since the number of AVAs in
154  * a RDN should be limited.
155  */
156 static void
157 AVA_Sort( LDAPRDN *rdn, int iAVA )
158 {
159         int             i;
160         LDAPAVA         *ava_in = rdn[ 0 ][ iAVA ];
161
162         assert( rdn );
163         assert( ava_in );
164         
165         for ( i = 0; i < iAVA; i++ ) {
166                 LDAPAVA         *ava = rdn[ 0 ][ i ];
167                 int             a, j;
168
169                 assert( ava );
170
171                 a = strcmp( ava_in->la_attr.bv_val, ava->la_attr.bv_val );
172
173                 if ( a > 0 ) {
174                         break;
175                 }
176
177                 while ( a == 0 ) {
178                         int             v, d;
179
180                         d = ava_in->la_value.bv_len - ava->la_value.bv_len;
181
182                         v = memcmp( ava_in->la_value.bv_val, 
183                                         ava->la_value.bv_val,
184                                         d <= 0 ? ava_in->la_value.bv_len 
185                                                 : ava->la_value.bv_len );
186
187                         if ( v == 0 && d != 0 ) {
188                                 v = d;
189                         }
190
191                         if ( v <= 0 ) {
192                                 /* 
193                                  * got it!
194                                  */
195                                 break;
196                         }
197
198                         if ( ++i == iAVA ) {
199                                 /*
200                                  * already sorted
201                                  */
202                                 return;
203                         }
204
205                         ava = rdn[ 0 ][ i ];
206                         a = strcmp( ava_in->la_attr.bv_val, 
207                                         ava->la_attr.bv_val );
208                 }
209
210                 /*
211                  * move ahead
212                  */
213                 for ( j = iAVA; j > i; j-- ) {
214                         rdn[ 0 ][ j ] = rdn[ 0 ][ j - 1 ];
215                 }
216                 rdn[ 0 ][ i ] = ava_in;
217
218                 return;
219         }
220 }
221
222 /*
223  * In-place, schema-aware normalization / "pretty"ing of the
224  * structural representation of a distinguished name.
225  */
226 static int
227 LDAPDN_rewrite( LDAPDN *dn, unsigned flags )
228 {
229         int             iRDN;
230         int             rc;
231
232         assert( dn );
233
234         for ( iRDN = 0; dn[ 0 ][ iRDN ]; iRDN++ ) {
235                 LDAPRDN         *rdn = dn[ 0 ][ iRDN ];
236                 int             iAVA;
237
238                 assert( rdn );
239
240                 for ( iAVA = 0; rdn[ 0 ][ iAVA ]; iAVA++ ) {
241                         LDAPAVA                 *ava = rdn[ 0 ][ iAVA ];
242                         AttributeDescription    *ad;
243                         slap_syntax_transform_func *transf = NULL;
244                         MatchingRule *mr;
245                         struct berval           bv = { 0, NULL };
246                         int                     do_sort = 0;
247
248                         assert( ava );
249
250                         if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
251                                 const char      *text = NULL;
252
253                                 rc = slap_bv2ad( &ava->la_attr, &ad, &text );
254                                 if ( rc != LDAP_SUCCESS ) {
255                                         return LDAP_INVALID_SYNTAX;
256                                 }
257                                 
258                                 ava->la_private = ( void * )ad;
259                                 do_sort = 1;
260                         }
261
262                         /* 
263                          * Replace attr oid/name with the canonical name
264                          */
265                         ava->la_attr = ad->ad_cname;
266
267                         if( ava->la_flags & LDAP_AVA_BINARY ) {
268                                 /* AVA is binary encoded, don't muck with it */
269                                 transf = NULL;
270                                 mr = NULL;
271
272                         } else if( flags & SLAP_LDAPDN_PRETTY ) {
273                                 transf = ad->ad_type->sat_syntax->ssyn_pretty;
274                                 mr = NULL;
275                         } else {
276                                 transf = ad->ad_type->sat_syntax->ssyn_normalize;
277                                 mr = ad->ad_type->sat_equality;
278                         }
279
280                         if ( transf ) {
281                                 /*
282                                  * transform value by normalize/pretty function
283                                  *      if value is empty, use empty_bv
284                                  */
285                                 rc = ( *transf )( ad->ad_type->sat_syntax,
286                                         ava->la_value.bv_len
287                                                 ? &ava->la_value
288                                                 : (struct berval *) &slap_empty_bv,
289                                         &bv );
290                         
291                                 if ( rc != LDAP_SUCCESS ) {
292                                         return LDAP_INVALID_SYNTAX;
293                                 }
294                         }
295
296                         if( mr && ( mr->smr_usage & SLAP_MR_DN_FOLD ) ) {
297                                 char *s = bv.bv_val;
298
299                                 ber_str2bv( UTF8normalize( bv.bv_val ? &bv
300                                         : &ava->la_value, LDAP_UTF8_CASEFOLD ),
301                                         0, 0, &bv );
302                                 free( s );
303                         }
304
305                         if( bv.bv_val ) {
306                                 free( ava->la_value.bv_val );
307                                 ava->la_value = bv;
308                         }
309
310                         if( do_sort ) AVA_Sort( rdn, iAVA );
311                 }
312         }
313
314         return LDAP_SUCCESS;
315 }
316
317 /*
318  * dn normalize routine
319  */
320 int
321 dnNormalize(
322         Syntax *syntax,
323         struct berval *val,
324         struct berval **normalized )
325 {
326         struct berval *out;
327         int rc;
328
329         assert( normalized && *normalized == NULL );
330
331         out = ch_malloc( sizeof( struct berval ) );
332         rc = dnNormalize2( syntax, val, out );
333         if ( rc != LDAP_SUCCESS )
334                 free( out );
335         else
336                 *normalized = out;
337         return rc;
338 }
339
340 int
341 dnNormalize2(
342         Syntax *syntax,
343         struct berval *val,
344         struct berval *out )
345 {
346         assert( val );
347         assert( out );
348
349         Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 );
350
351         if ( val->bv_len != 0 ) {
352                 LDAPDN          *dn = NULL;
353                 int             rc;
354
355                 /*
356                  * Go to structural representation
357                  */
358                 rc = ldap_bv2dn( val, &dn, LDAP_DN_FORMAT_LDAP );
359                 if ( rc != LDAP_SUCCESS ) {
360                         return LDAP_INVALID_SYNTAX;
361                 }
362
363                 assert( strlen( val->bv_val ) == val->bv_len );
364
365                 /*
366                  * Schema-aware rewrite
367                  */
368                 if ( LDAPDN_rewrite( dn, 0 ) != LDAP_SUCCESS ) {
369                         ldap_dnfree( dn );
370                         return LDAP_INVALID_SYNTAX;
371                 }
372
373                 /*
374                  * Back to string representation
375                  */
376                 rc = ldap_dn2bv( dn, out, LDAP_DN_FORMAT_LDAPV3 );
377
378                 ldap_dnfree( dn );
379
380                 if ( rc != LDAP_SUCCESS ) {
381                         return LDAP_INVALID_SYNTAX;
382                 }
383         } else {
384                 ber_dupbv( out, val );
385         }
386
387         Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val, 0, 0 );
388
389         return LDAP_SUCCESS;
390 }
391
392 /*
393  * dn "pretty"ing routine
394  */
395 int
396 dnPretty(
397         Syntax *syntax,
398         struct berval *val,
399         struct berval **pretty)
400 {
401         struct berval *out;
402         int rc;
403
404         assert( pretty && *pretty == NULL );
405
406         out = ch_malloc( sizeof( struct berval ) );
407         rc = dnPretty2( syntax, val, out );
408         if ( rc != LDAP_SUCCESS )
409                 free( out );
410         else
411                 *pretty = out;
412         return rc;
413 }
414
415 int
416 dnPretty2(
417         Syntax *syntax,
418         struct berval *val,
419         struct berval *out)
420 {
421         assert( val );
422         assert( out );
423
424         Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 );
425
426         if ( val->bv_len == 0 ) {
427                 ber_dupbv( out, val );
428
429         } else if ( val->bv_len > SLAP_LDAPDN_MAXLEN ) {
430                 return LDAP_INVALID_SYNTAX;
431
432         } else {
433                 LDAPDN          *dn = NULL;
434                 int             rc;
435
436                 /* FIXME: should be liberal in what we accept */
437                 rc = ldap_bv2dn( val, &dn, LDAP_DN_FORMAT_LDAP );
438                 if ( rc != LDAP_SUCCESS ) {
439                         return LDAP_INVALID_SYNTAX;
440                 }
441
442                 assert( strlen( val->bv_val ) == val->bv_len );
443
444                 /*
445                  * Schema-aware rewrite
446                  */
447                 if ( LDAPDN_rewrite( dn, SLAP_LDAPDN_PRETTY ) != LDAP_SUCCESS ) {
448                         ldap_dnfree( dn );
449                         return LDAP_INVALID_SYNTAX;
450                 }
451
452                 /* FIXME: not sure why the default isn't pretty */
453                 /* RE: the default is the form that is used as
454                  * an internal representation; the pretty form
455                  * is a variant */
456                 rc = ldap_dn2bv( dn, out,
457                         LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
458
459                 ldap_dnfree( dn );
460
461                 if ( rc != LDAP_SUCCESS ) {
462                         return LDAP_INVALID_SYNTAX;
463                 }
464         }
465
466         Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val, 0, 0 );
467
468         return LDAP_SUCCESS;
469 }
470
471 /*
472  * Combination of both dnPretty and dnNormalize
473  */
474 int
475 dnPrettyNormal(
476         Syntax *syntax,
477         struct berval *val,
478         struct berval *pretty,
479         struct berval *normal)
480 {
481         Debug( LDAP_DEBUG_TRACE, ">>> dnPrettyNormal: <%s>\n", val->bv_val, 0, 0 );
482
483         assert( val );
484         assert( pretty );
485         assert( normal );
486
487         if ( val->bv_len == 0 ) {
488                 ber_dupbv( pretty, val );
489                 ber_dupbv( normal, val );
490
491         } else if ( val->bv_len > SLAP_LDAPDN_MAXLEN ) {
492                 /* too big */
493                 return LDAP_INVALID_SYNTAX;
494
495         } else {
496                 LDAPDN          *dn = NULL;
497                 int             rc;
498
499                 pretty->bv_val = NULL;
500                 normal->bv_val = NULL;
501                 pretty->bv_len = 0;
502                 normal->bv_len = 0;
503
504                 /* FIXME: should be liberal in what we accept */
505                 rc = ldap_bv2dn( val, &dn, LDAP_DN_FORMAT_LDAP );
506                 if ( rc != LDAP_SUCCESS ) {
507                         return LDAP_INVALID_SYNTAX;
508                 }
509
510                 assert( strlen( val->bv_val ) == val->bv_len );
511
512                 /*
513                  * Schema-aware rewrite
514                  */
515                 if ( LDAPDN_rewrite( dn, SLAP_LDAPDN_PRETTY ) != LDAP_SUCCESS ) {
516                         ldap_dnfree( dn );
517                         return LDAP_INVALID_SYNTAX;
518                 }
519
520                 rc = ldap_dn2bv( dn, pretty,
521                         LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
522
523                 if ( rc != LDAP_SUCCESS ) {
524                         ldap_dnfree( dn );
525                         return LDAP_INVALID_SYNTAX;
526                 }
527
528                 if ( LDAPDN_rewrite( dn, 0 ) != LDAP_SUCCESS ) {
529                         ldap_dnfree( dn );
530                         free( pretty->bv_val );
531                         pretty->bv_val = NULL;
532                         pretty->bv_len = 0;
533                         return LDAP_INVALID_SYNTAX;
534                 }
535
536                 rc = ldap_dn2bv( dn, normal, LDAP_DN_FORMAT_LDAPV3 );
537
538                 ldap_dnfree( dn );
539                 if ( rc != LDAP_SUCCESS ) {
540                         free( pretty->bv_val );
541                         pretty->bv_val = NULL;
542                         pretty->bv_len = 0;
543                         return LDAP_INVALID_SYNTAX;
544                 }
545         }
546
547         Debug( LDAP_DEBUG_TRACE, "<<< dnPrettyNormal: <%s>, <%s>\n",
548                 pretty->bv_val, normal->bv_val, 0 );
549
550         return LDAP_SUCCESS;
551 }
552
553 /*
554  * dnMatch routine
555  */
556 int
557 dnMatch(
558         int *matchp,
559         slap_mask_t flags,
560         Syntax *syntax,
561         MatchingRule *mr,
562         struct berval *value,
563         void *assertedValue )
564 {
565         int match;
566         struct berval *asserted = (struct berval *) assertedValue;
567
568         assert( matchp );
569         assert( value );
570         assert( assertedValue );
571         
572         match = value->bv_len - asserted->bv_len;
573
574         if ( match == 0 ) {
575                 match = strcmp( value->bv_val, asserted->bv_val );
576         }
577
578 #ifdef NEW_LOGGING
579         LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
580                 "dnMatch: %d\n    %s\n    %s\n", match,
581                 value->bv_val, asserted->bv_val ));
582 #else
583         Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
584                 match, value->bv_val, asserted->bv_val );
585 #endif
586
587         *matchp = match;
588         return( LDAP_SUCCESS );
589 }
590
591 /*
592  * dnParent - dn's parent, in-place
593  *
594  * note: the incoming dn is assumed to be normalized/prettyfied,
595  * so that escaped rdn/ava separators are in '\'+hexpair form
596  */
597 void
598 dnParent( 
599         struct berval   *dn, 
600         struct berval   *pdn )
601 {
602         char    *p;
603
604         p = strchr( dn->bv_val, ',' );
605
606         /* one-level dn */
607         if ( p == NULL ) {
608                 *pdn = slap_empty_bv;
609                 return;
610         }
611
612         assert( DN_SEPARATOR( p[ 0 ] ) );
613         p++;
614
615         assert( ATTR_LEADCHAR( p[ 0 ] ) );
616         pdn->bv_val = p;
617         pdn->bv_len = dn->bv_len - (p - dn->bv_val);
618
619         return;
620 }
621
622 int
623 dnExtractRdn( 
624         struct berval   *dn, 
625         struct berval   *rdn )
626 {
627         LDAPRDN         *tmpRDN;
628         const char      *p;
629         int             rc;
630
631         assert( dn );
632         assert( rdn );
633
634         if( dn->bv_len == 0 ) {
635                 return LDAP_OTHER;
636         }
637
638         rc = ldap_bv2rdn( dn, &tmpRDN, (char **)&p, LDAP_DN_FORMAT_LDAP );
639         if ( rc != LDAP_SUCCESS ) {
640                 return rc;
641         }
642
643         rc = ldap_rdn2bv( tmpRDN, rdn, LDAP_DN_FORMAT_LDAPV3 );
644         ldap_rdnfree( tmpRDN );
645         if ( rc != LDAP_SUCCESS ) {
646                 return rc;
647         }
648
649         return LDAP_SUCCESS;
650 }
651
652 /*
653  * We can assume the input is a prettied or normalized DN
654  */
655 int 
656 dn_rdnlen(
657         Backend         *be,
658         struct berval   *dn_in )
659 {
660         const char      *p;
661
662         assert( dn_in );
663
664         if ( dn_in == NULL ) {
665                 return 0;
666         }
667
668         if ( !dn_in->bv_len ) {
669                 return 0;
670         }
671
672         if ( be != NULL && be_issuffix( be, dn_in ) ) {
673                 return 0;
674         }
675
676         p = strchr( dn_in->bv_val, ',' );
677
678         return p ? p - dn_in->bv_val : dn_in->bv_len;
679 }
680
681
682 /* rdnValidate:
683  *
684  * LDAP_SUCCESS if rdn is a legal rdn;
685  * LDAP_INVALID_SYNTAX otherwise (including a sequence of rdns)
686  */
687 int
688 rdnValidate( struct berval *rdn )
689 {
690 #if 1
691         /* Major cheat!
692          * input is a pretty or normalized DN
693          * hence, we can just search for ','
694          */
695         if( rdn == NULL || rdn->bv_len == 0 ||
696                 rdn->bv_len > SLAP_LDAPDN_MAXLEN )
697         {
698                 return LDAP_INVALID_SYNTAX;
699         }
700
701         return strchr( rdn->bv_val, ',' ) == NULL
702                 ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
703
704 #else
705         LDAPRDN         *RDN, **DN[ 2 ] = { &RDN, NULL };
706         const char      *p;
707         int             rc;
708
709         /*
710          * must be non-empty
711          */
712         if ( rdn == NULL || rdn == '\0' ) {
713                 return 0;
714         }
715
716         /*
717          * must be parsable
718          */
719         rc = ldap_bv2rdn( rdn, &RDN, (char **)&p, LDAP_DN_FORMAT_LDAP );
720         if ( rc != LDAP_SUCCESS ) {
721                 return 0;
722         }
723
724         /*
725          * Must be one-level
726          */
727         if ( p[ 0 ] != '\0' ) {
728                 return 0;
729         }
730
731         /*
732          * Schema-aware validate
733          */
734         if ( rc == LDAP_SUCCESS ) {
735                 rc = LDAPDN_validate( DN );
736         }
737         ldap_rdnfree( RDN );
738
739         /*
740          * Must validate (there's a repeated parsing ...)
741          */
742         return ( rc == LDAP_SUCCESS );
743 #endif
744 }
745
746
747 /* build_new_dn:
748  *
749  * Used by ldbm/bdb2 back_modrdn to create the new dn of entries being
750  * renamed.
751  *
752  * new_dn = parent (p_dn) + separator + rdn (newrdn) + null.
753  */
754
755 void
756 build_new_dn( struct berval * new_dn,
757         struct berval * parent_dn,
758         struct berval * newrdn )
759 {
760         char *ptr;
761
762         if ( parent_dn == NULL ) {
763                 ber_dupbv( new_dn, newrdn );
764                 return;
765         }
766
767         new_dn->bv_len = parent_dn->bv_len + newrdn->bv_len + 1;
768         new_dn->bv_val = (char *) ch_malloc( new_dn->bv_len + 1 );
769
770         ptr = slap_strcopy( new_dn->bv_val, newrdn->bv_val );
771         *ptr++ = ',';
772         strcpy( ptr, parent_dn->bv_val );
773 }
774
775
776 /*
777  * dnIsSuffix - tells whether suffix is a suffix of dn.
778  * Both dn and suffix must be normalized.
779  */
780 int
781 dnIsSuffix(
782         const struct berval *dn,
783         const struct berval *suffix )
784 {
785         int     d = dn->bv_len - suffix->bv_len;
786
787         assert( dn );
788         assert( suffix );
789
790         /* empty suffix matches any dn */
791         if ( suffix->bv_len == 0 ) {
792                 return 1;
793         }
794
795         /* suffix longer than dn */
796         if ( d < 0 ) {
797                 return 0;
798         }
799
800         /* no rdn separator or escaped rdn separator */
801         if ( d > 1 && !DN_SEPARATOR( dn->bv_val[ d - 1 ] ) ) {
802                 return 0;
803         }
804
805         /* no possible match or malformed dn */
806         if ( d == 1 ) {
807                 return 0;
808         }
809
810         /* compare */
811         return( strcmp( dn->bv_val + d, suffix->bv_val ) == 0 );
812 }