]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/suffixalias.c
Add referral generator
[openldap] / servers / slapd / suffixalias.c
index 7fff1f617004afca743bbd51c4903c7b12d44cb6..848364897b679808a6ff9db80f4ebd94d7cf57a2 100644 (file)
@@ -1,5 +1,6 @@
+/* $OpenLDAP$ */
 /*
- * Copyright 1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1999-2000 The OpenLDAP Foundation, All Rights Reserved.
  *
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file in the top level
  * directory of this package.
 #include "portable.h"
 
 #include <stdio.h>
-#include <string.h>
-#include <ac/socket.h>         /* Get struct sockaddr for slap.h */
+#include <ac/string.h>
+#include <ac/socket.h>
 #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)
+char *suffix_alias(
+       Backend *be,
+       char *dn )
 {
        int     i, dnLength;
 
        if(dn == NULL) return NULL;
+       if(be == NULL) return dn;
 
        dnLength = strlen ( dn );
-        for ( i = 0;
-              be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
-              i += 2) {
-                int aliasLength = strlen (be->be_suffixAlias[i]);
+
+       for ( i = 0;
+               be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
+               i += 2 )
+       {
+               int aliasLength = strlen (be->be_suffixAlias[i]);
                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[diff-1]) ) {
                                /* boundary is not at a DN separator */
                                continue;
                        }
@@ -53,15 +59,17 @@ char *suffixAlias (char *dn, Operation *op, Backend *be)
                }
 
                if (!strcmp(be->be_suffixAlias[i], &dn[diff])) {
-                        char *oldDN = dn;
+                       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\"",
+                       Debug( LDAP_DEBUG_ARGS,
+                               "suffix_alias: converted \"%s\" to \"%s\"\n",
                                oldDN, dn, 0);
-                        free (oldDN);
+                       free (oldDN);
                        break;
                }
        }
+
        return dn;
 }