]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/dn.c
Fix previous commit
[openldap] / servers / slapd / dn.c
index 532b38c7d8eaed52c588e6f71556063850197a5f..7d836a630e43c424e0275c1c161c27a1ab7de901 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "slap.h"
 
+const struct berval slap_empty_bv = { 0, "" };
+
 #define SLAP_LDAPDN_PRETTY 0x1
 
 /*
@@ -564,16 +566,16 @@ dnMatch(
  */
 int
 dnParent( 
-       const char      *dn, 
-       const char      **pdn )
+       struct berval   *dn, 
+       struct berval   *pdn )
 {
-       const char      *p;
+       char    *p;
 
-       p = strchr( dn, ',' );
+       p = strchr( dn->bv_val, ',' );
 
        /* one-level dn */
        if ( p == NULL ) {
-               *pdn = "";
+               *pdn = slap_empty_bv;
                return LDAP_SUCCESS;
        }
 
@@ -581,7 +583,8 @@ dnParent(
        p++;
 
        assert( ATTR_LEADCHAR( p[ 0 ] ) );
-       *pdn = p;
+       pdn->bv_val = p;
+       pdn->bv_len = dn->bv_len - (p - dn->bv_val);
 
        return LDAP_SUCCESS;
 }
@@ -641,7 +644,7 @@ dn_parent(
        Backend         *be,
        const char      *dn )
 {
-       const char      *pdn;
+       struct berval   bv, pdn;
 
        if ( dn == NULL ) {
                return NULL;
@@ -655,15 +658,17 @@ dn_parent(
                return NULL;
        }
 
-       if ( be != NULL && be_issuffix( be, dn ) ) {
+       bv.bv_val = (char *)dn;
+       bv.bv_len = strlen(bv.bv_val);
+       if ( be != NULL && be_issuffix( be, &bv ) ) {
                return NULL;
        }
 
-       if ( dnParent( dn, &pdn ) != LDAP_SUCCESS ) {
+       if ( dnParent( &bv, &pdn ) != LDAP_SUCCESS ) {
                return NULL;
        }
        
-       return ( char * )pdn;
+       return pdn.bv_val;
 }
 #endif /* SLAP_DN_MIGRATION */
 
@@ -699,7 +704,7 @@ dnExtractRdn(
 }
 
 /*
- * FIXME: should be replaced by dnExtractRdn()
+ * We can assume the input is a prettied or normalized DN
  */
 int 
 dn_rdnlen(
@@ -719,17 +724,13 @@ dn_rdnlen(
                return 0;
        }
 
-       if ( be != NULL && be_issuffix( be, dn_in->bv_val ) ) {
+       if ( be != NULL && be_issuffix( be, dn_in ) ) {
                return 0;
        }
 
-       rc = ldap_str2rdn( dn_in->bv_val, NULL, (char **)&p, 
-                       LDAP_DN_FORMAT_LDAP | LDAP_DN_SKIP );
-       if ( rc != LDAP_SUCCESS ) {
-               return 0;
-       }
+       p = strchr( dn_in->bv_val, ',' );
 
-       return p - dn_in->bv_val;
+       return p ? p - dn_in->bv_val : dn_in->bv_len;
 }
 
 
@@ -850,8 +851,7 @@ dnIsSuffix(
        }
 
        /* no rdn separator or escaped rdn separator */
-       if ( d > 1 && ( !DN_SEPARATOR( dn->bv_val[ d - 1 ] ) 
-                               || DN_ESCAPE( dn->bv_val[ d - 2 ] ) ) ) {
+       if ( d > 1 && !DN_SEPARATOR( dn->bv_val[ d - 1 ] ) ) {
                return 0;
        }