]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/suffixmassage.c
don't lookup rootdn if the password is incorrect (ITS#4004)
[openldap] / servers / slapd / back-meta / suffixmassage.c
index 05e4ca21834fcb76777008b4e0090e82a2b89f04..da96c8be2d33f22d1e514f11fe9fdb49096c3a56 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003 The OpenLDAP Foundation.
+ * Copyright 2003-2005 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #ifdef ENABLE_REWRITE
 int
 ldap_back_dn_massage(
-       dncookie *dc,
-       struct berval *dn,
-       struct berval *res
-)
+       dncookie        *dc,
+       struct berval   *dn,
+       struct berval   *res )
 {
-       int rc = 0;
+       int             rc = 0;
+       static char     *dmy = "";
 
-       switch (rewrite_session( dc->rwmap->rwm_rw, dc->ctx, (dn->bv_len ? dn->bv_val : ""), dc->conn, 
-                               &res->bv_val )) {
+       switch ( rewrite_session( dc->target->mt_rwmap.rwm_rw, dc->ctx,
+                               ( dn->bv_val ? dn->bv_val : dmy ),
+                               dc->conn, &res->bv_val ) )
+       {
        case REWRITE_REGEXEC_OK:
                if ( res->bv_val != NULL ) {
                        res->bv_len = strlen( res->bv_val );
                } else {
                        *res = *dn;
                }
-#ifdef NEW_LOGGING
-               LDAP_LOG( BACK_LDAP, DETAIL1, 
-                       "[rw] %s: \"%s\" -> \"%s\"\n", dc->ctx, dn->bv_val, res->bv_val );              
-#else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_ARGS,
-                       "[rw] %s: \"%s\" -> \"%s\"\n", dc->ctx, dn->bv_val, res->bv_val );              
-#endif /* !NEW_LOGGING */
+                       "[rw] %s: \"%s\" -> \"%s\"\n",
+                       dc->ctx,
+                       BER_BVISNULL( dn ) ? "" : dn->bv_val,
+                       BER_BVISNULL( res ) ? "" : res->bv_val );
                rc = LDAP_SUCCESS;
                break;
                
@@ -102,6 +102,11 @@ ldap_back_dn_massage(
                rc = LDAP_OTHER;
                break;
        }
+
+       if ( res->bv_val == dmy ) { 
+               BER_BVZERO( res );
+       }
+
        return rc;
 }
 
@@ -121,14 +126,14 @@ ldap_back_dn_massage(
        int     i, src, dst;
        struct berval pretty = {0,NULL}, *dn = odn;
 
-       assert( res );
+       assert( res != NULL );
 
        if ( dn == NULL ) {
                res->bv_val = NULL;
                res->bv_len = 0;
                return 0;
        }
-       if ( dc->rwmap == NULL || dc->rwmap->rwm_suffix_massage == NULL ) {
+       if ( dc->target->mt_rwmap.rwm_suffix_massage == NULL ) {
                *res = *dn;
                return 0;
        }
@@ -147,9 +152,9 @@ ldap_back_dn_massage(
        }
 
        for ( i = 0;
-               dc->rwmap->rwm_suffix_massage[i].bv_val != NULL;
+               dc->target->mt_rwmap.rwm_suffix_massage[i].bv_val != NULL;
                i += 4 ) {
-               int aliasLength = dc->rwmap->rwm_suffix_massage[i+src].bv_len;
+               int aliasLength = dc->target->mt_rwmap.rwm_suffix_massage[i+src].bv_len;
                int diff = dn->bv_len - aliasLength;
 
                if ( diff < 0 ) {
@@ -161,21 +166,16 @@ ldap_back_dn_massage(
                        /* At a DN Separator */
                }
 
-               if ( !strcmp( dc->rwmap->rwm_suffix_massage[i+src].bv_val, &dn->bv_val[diff] ) ) {
-                       res->bv_len = diff + dc->rwmap->rwm_suffix_massage[i+dst].bv_len;
+               if ( !strcmp( dc->target->mt_rwmap.rwm_suffix_massage[i+src].bv_val, &dn->bv_val[diff] ) ) {
+                       res->bv_len = diff + dc->target->mt_rwmap.rwm_suffix_massage[i+dst].bv_len;
                        res->bv_val = ch_malloc( res->bv_len + 1 );
                        strncpy( res->bv_val, dn->bv_val, diff );
-                       strcpy( &res->bv_val[diff], dc->rwmap->rwm_suffix_massage[i+dst].bv_val );
-#ifdef NEW_LOGGING
-                       LDAP_LOG ( BACK_LDAP, ARGS, 
-                               "ldap_back_dn_massage: converted \"%s\" to \"%s\"\n",
-                               dn->bv_val, res->bv_val, 0 );
-#else
+                       strcpy( &res->bv_val[diff], dc->target->mt_rwmap.rwm_suffix_massage[i+dst].bv_val );
                        Debug( LDAP_DEBUG_ARGS,
                                "ldap_back_dn_massage:"
                                " converted \"%s\" to \"%s\"\n",
-                               dn->bv_val, res->bv_val, 0 );
-#endif
+                               BER_BVISNULL( dn ) ? "" : dn->bv_val,
+                               BER_BVISNULL( res ) ? "" : res->bv_val, 0 );
                        break;
                }
        }