]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/suffixalias.c
Fix LBER_ERROR vs. -1 confusion.
[openldap] / servers / slapd / suffixalias.c
index 8751d83773d58f2a6d9bb7075d80322a9b758d55..e42279d09ae1022001a2f158dc61c99795d8a7cf 100644 (file)
@@ -1,5 +1,6 @@
+/* $OpenLDAP$ */
 /*
- * Copyright 1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1999-2003 The OpenLDAP Foundation, All Rights Reserved.
  *
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file in the top level
  * directory of this package.
 #include "slap.h"
 
 /* 
- * given a normalized uppercased dn (or root part), return an aliased dn if any of the 
- * alias suffixes match
+ * given a normalized uppercased dn (or root part),
+ * return an aliased dn if any of the alias suffixes match
  */
-char *suffixAlias (char *dn, Operation *op, Backend *be)
+void suffix_alias(
+       Backend *be,
+       struct berval *dn )
 {
-       int     i, dnLength;
+       int     i, dnLength;
 
-       if(dn == NULL) return NULL;
+       if(dn == NULL || be == NULL || dn->bv_len == 0)
+               return;
 
-       dnLength = strlen ( dn );
-        for ( i = 0;
-              be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
-              i += 2) {
-                int aliasLength = strlen (be->be_suffixAlias[i]);
+       dnLength = dn->bv_len;
+
+       for ( i = 0;
+               be->be_suffixAlias != NULL && be->be_suffixAlias[i].bv_val != NULL;
+               i += 2 )
+       {
+               int aliasLength = be->be_suffixAlias[i].bv_len;
                int diff = dnLength - aliasLength;
 
                if ( diff < 0 ) {
                        /* alias is longer than dn */
                        continue;
                } else if ( diff > 0 ) {
-                       if ( ! DNSEPARATOR(dn[diff-1]) ) {
+                       if ( ! DN_SEPARATOR(dn->bv_val[diff-1]) ) {
                                /* boundary is not at a DN separator */
                                continue;
                        }
@@ -52,16 +58,24 @@ char *suffixAlias (char *dn, Operation *op, Backend *be)
                        /* XXX or an escaped separator... oh well */
                }
 
-               if (!strcmp(be->be_suffixAlias[i], &dn[diff])) {
-                        char *oldDN = dn;
-                       dn = ch_malloc( diff + strlen(be->be_suffixAlias[i+1]) + 1 );
-                       strncpy( dn, oldDN, diff );
-                       strcpy( &dn[diff], be->be_suffixAlias[i+1] );
-                       Debug( LDAP_DEBUG_ARGS, "SuffixAlias: converted \"%s\" to \"%s\"\n",
-                               oldDN, dn, 0);
-                        free (oldDN);
+               if (!strcmp(be->be_suffixAlias[i].bv_val, &dn->bv_val[diff])) {
+                       char *oldDN = dn->bv_val;
+                       dn->bv_len = diff + be->be_suffixAlias[i+1].bv_len;
+                       dn->bv_val = ch_malloc( dn->bv_len + 1 );
+                       strncpy( dn->bv_val, oldDN, diff );
+                       strcpy( &dn->bv_val[diff], be->be_suffixAlias[i+1].bv_val );
+#ifdef NEW_LOGGING
+                       LDAP_LOG( OPERATION, INFO, 
+                               "suffix_alias: converted \"%s\" to \"%s\"\n",
+                               oldDN, dn->bv_val, 0 );
+#else
+                       Debug( LDAP_DEBUG_ARGS,
+                               "suffix_alias: converted \"%s\" to \"%s\"\n",
+                               oldDN, dn->bv_val, 0);
+#endif
+
+                       free (oldDN);
                        break;
                }
        }
-       return dn;
 }