]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/suffixmassage.c
fix printing a NULL value (ITS#3698)
[openldap] / servers / slapd / back-meta / suffixmassage.c
index 8f051d835db97dcb8239e3a58c58bbbbfaa76677..94409125227f55c93335f4297a1a94d88a1df49f 100644 (file)
 #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 : "" ),
+                               ( dn->bv_val ? dn->bv_val : dmy ),
                                dc->conn, &res->bv_val ) )
        {
        case REWRITE_REGEXEC_OK:
@@ -78,13 +78,11 @@ ldap_back_dn_massage(
                } 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;
                
@@ -104,6 +102,11 @@ ldap_back_dn_massage(
                rc = LDAP_OTHER;
                break;
        }
+
+       if ( res->bv_val == dmy ) { 
+               BER_BVZERO( res );
+       }
+
        return rc;
 }
 
@@ -168,16 +171,11 @@ ldap_back_dn_massage(
                        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
                        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;
                }
        }