]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/dn.c
alternate fix to ITS#3916
[openldap] / servers / slapd / dn.c
index 05e5ea6916140b8a926ad9b9ce0edde7a7c33d9b..24bc185ff5376d1ab4aab97ddf3ff12948740920 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2005 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -34,7 +34,6 @@
 #include <ac/time.h>
 
 #include "slap.h"
-#include "ldap_pvt.h" /* must be after slap.h, to get ldap_bv2dn_x() & co */
 #include "lutil.h"
 
 /*
@@ -60,14 +59,14 @@ LDAPRDN_validate( LDAPRDN rdn )
        int             iAVA;
        int             rc;
 
-       assert( rdn );
+       assert( rdn != NULL );
 
        for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
                LDAPAVA                 *ava = rdn[ iAVA ];
                AttributeDescription    *ad;
                slap_syntax_validate_func *validate = NULL;
 
-               assert( ava );
+               assert( ava != NULL );
                
                if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
                        const char      *text = NULL;
@@ -113,20 +112,20 @@ LDAPDN_validate( LDAPDN dn )
        int             iRDN;
        int             rc;
 
-       assert( dn );
+       assert( dn != NULL );
 
        for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
                LDAPRDN         rdn = dn[ iRDN ];
                int             iAVA;
 
-               assert( rdn );
+               assert( rdn != NULL );
 
                for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
                        LDAPAVA                 *ava = rdn[ iAVA ];
                        AttributeDescription    *ad;
                        slap_syntax_validate_func *validate = NULL;
 
-                       assert( ava );
+                       assert( ava != NULL );
                        
                        if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
                                const char      *text = NULL;
@@ -174,7 +173,7 @@ dnValidate(
        int             rc;
        LDAPDN          dn = NULL;
 
-       assert( in );
+       assert( in != NULL );
 
        if ( in->bv_len == 0 ) {
                return LDAP_SUCCESS;
@@ -212,7 +211,7 @@ rdnValidate(
        LDAPRDN         rdn;
        char*           p;
 
-       assert( in );
+       assert( in != NULL );
        if ( in->bv_len == 0 ) {
                return LDAP_SUCCESS;
 
@@ -262,14 +261,14 @@ AVA_Sort( LDAPRDN rdn, int iAVA )
        int             i;
        LDAPAVA         *ava_in = rdn[ iAVA ];
 
-       assert( rdn );
-       assert( ava_in );
+       assert( rdn != NULL );
+       assert( ava_in != NULL );
        
        for ( i = 0; i < iAVA; i++ ) {
                LDAPAVA         *ava = rdn[ i ];
                int             a, j;
 
-               assert( ava );
+               assert( ava != NULL );
 
                a = strcmp( ava_in->la_attr.bv_val, ava->la_attr.bv_val );
 
@@ -338,7 +337,7 @@ LDAPRDN_rewrite( LDAPRDN rdn, unsigned flags, void *ctx )
                struct berval           bv = BER_BVNULL;
                int                     do_sort = 0;
 
-               assert( ava );
+               assert( ava != NULL );
 
                if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
                        const char      *text = NULL;
@@ -445,13 +444,13 @@ LDAPDN_rewrite( LDAPDN dn, unsigned flags, void *ctx )
        int             iRDN;
        int             rc;
 
-       assert( dn );
+       assert( dn != NULL );
 
        for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
                LDAPRDN         rdn = dn[ iRDN ];
                int             iAVA;
 
-               assert( rdn );
+               assert( rdn != NULL );
 
                for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
                        LDAPAVA                 *ava = rdn[ iAVA ];
@@ -463,7 +462,7 @@ LDAPDN_rewrite( LDAPDN dn, unsigned flags, void *ctx )
                        struct berval           bv = BER_BVNULL;
                        int                     do_sort = 0;
 
-                       assert( ava );
+                       assert( ava != NULL );
 
                        if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
                                const char      *text = NULL;
@@ -571,8 +570,8 @@ dnNormalize(
     struct berval *out,
     void *ctx)
 {
-       assert( val );
-       assert( out );
+       assert( val != NULL );
+       assert( out != NULL );
 
        Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 );
 
@@ -627,8 +626,8 @@ rdnNormalize(
     struct berval *out,
     void *ctx)
 {
-       assert( val );
-       assert( out );
+       assert( val != NULL );
+       assert( out != NULL );
 
        Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 );
        if ( val->bv_len != 0 ) {
@@ -683,8 +682,8 @@ dnPretty(
        struct berval *out,
        void *ctx)
 {
-       assert( val );
-       assert( out );
+       assert( val != NULL );
+       assert( out != NULL );
 
        Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 );
 
@@ -740,8 +739,8 @@ rdnPretty(
        struct berval *out,
        void *ctx)
 {
-       assert( val );
-       assert( out );
+       assert( val != NULL );
+       assert( out != NULL );
 
        Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 );
 
@@ -801,8 +800,8 @@ dnPrettyNormalDN(
        int flags,
        void *ctx )
 {
-       assert( val );
-       assert( dn );
+       assert( val != NULL );
+       assert( dn != NULL );
 
        Debug( LDAP_DEBUG_TRACE, ">>> dn%sDN: <%s>\n", 
                        flags == SLAP_LDAPDN_PRETTY ? "Pretty" : "Normal", 
@@ -855,9 +854,9 @@ dnPrettyNormal(
 {
        Debug( LDAP_DEBUG_TRACE, ">>> dnPrettyNormal: <%s>\n", val->bv_val, 0, 0 );
 
-       assert( val );
-       assert( pretty );
-       assert( normal );
+       assert( val != NULL );
+       assert( pretty != NULL );
+       assert( normal != NULL );
 
        if ( val->bv_len == 0 ) {
                ber_dupbv_x( pretty, val, ctx );
@@ -941,9 +940,9 @@ dnMatch(
        int match;
        struct berval *asserted = (struct berval *) assertedValue;
 
-       assert( matchp );
-       assert( value );
-       assert( assertedValue );
+       assert( matchp != NULL );
+       assert( value != NULL );
+       assert( assertedValue != NULL );
        assert( !BER_BVISNULL( value ) );
        assert( !BER_BVISNULL( asserted ) );
        
@@ -976,9 +975,9 @@ dnRelativeMatch(
        int match;
        struct berval *asserted = (struct berval *) assertedValue;
 
-       assert( matchp );
-       assert( value );
-       assert( assertedValue );
+       assert( matchp != NULL );
+       assert( value != NULL );
+       assert( assertedValue != NULL );
        assert( !BER_BVISNULL( value ) );
        assert( !BER_BVISNULL( asserted ) );
 
@@ -1003,7 +1002,6 @@ dnRelativeMatch(
 
                *matchp = match;
                return LDAP_SUCCESS;
-
        }
 
        if( mr == slap_schema.si_mr_dnSuperiorMatch ) {
@@ -1076,9 +1074,9 @@ rdnMatch(
        int match;
        struct berval *asserted = (struct berval *) assertedValue;
 
-       assert( matchp );
-       assert( value );
-       assert( assertedValue );
+       assert( matchp != NULL );
+       assert( value != NULL );
+       assert( assertedValue != NULL );
        
        match = value->bv_len - asserted->bv_len;
 
@@ -1099,6 +1097,10 @@ rdnMatch(
  * dnParent - dn's parent, in-place
  * note: the incoming dn is assumed to be normalized/prettyfied,
  * so that escaped rdn/ava separators are in '\'+hexpair form
+ *
+ * note: "dn" and "pdn" can point to the same berval;
+ * beware that, in this case, the pointer to the original buffer
+ * will get lost.
  */
 void
 dnParent( 
@@ -1120,8 +1122,8 @@ dnParent(
        p++;
 
        assert( ATTR_LEADCHAR( p[ 0 ] ) );
-       pdn->bv_val = p;
        pdn->bv_len = dn->bv_len - (p - dn->bv_val);
+       pdn->bv_val = p;
 
        return;
 }
@@ -1163,8 +1165,8 @@ dnExtractRdn(
        const char      *p;
        int             rc;
 
-       assert( dn );
-       assert( rdn );
+       assert( dn != NULL );
+       assert( rdn != NULL );
 
        if( dn->bv_len == 0 ) {
                return LDAP_OTHER;
@@ -1192,7 +1194,7 @@ dn_rdnlen(
 {
        const char      *p;
 
-       assert( dn_in );
+       assert( dn_in != NULL );
 
        if ( dn_in == NULL ) {
                return 0;
@@ -1300,7 +1302,7 @@ build_new_dn( struct berval * new_dn,
        new_dn->bv_len = parent_dn->bv_len + newrdn->bv_len + 1;
        new_dn->bv_val = (char *) slap_sl_malloc( new_dn->bv_len + 1, memctx );
 
-       ptr = lutil_strcopy( new_dn->bv_val, newrdn->bv_val );
+       ptr = lutil_strncopy( new_dn->bv_val, newrdn->bv_val, newrdn->bv_len );
        *ptr++ = ',';
        strcpy( ptr, parent_dn->bv_val );
 }
@@ -1317,8 +1319,8 @@ dnIsSuffix(
 {
        int     d = dn->bv_len - suffix->bv_len;
 
-       assert( dn );
-       assert( suffix );
+       assert( dn != NULL );
+       assert( suffix != NULL );
 
        /* empty suffix matches any dn */
        if ( suffix->bv_len == 0 ) {
@@ -1357,7 +1359,9 @@ dnIsOneLevelRDN( struct berval *rdn )
        return 1;
 }
 
+#ifdef HAVE_TLS
 static SLAP_CERT_MAP_FN *DNX509PeerNormalizeCertMap = NULL;
+#endif
 
 int register_certificate_map_function(SLAP_CERT_MAP_FN *fn)
 {