]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/dn.c
Added return()
[openldap] / servers / slapd / dn.c
index bd51b3c13d9d7c8c7616517c0c2045da21f09ac1..cac66133e160a7b75b48ab5af487796690d9c19f 100644 (file)
 
 #include "slap.h"
 
-#define DNSEPARATOR(c) (c == ',' || c == ';')
-#define SEPARATOR(c)   (c == ',' || c == ';' || c == '+')
-#define SPACE(c)       (c == ' ' || c == '\n')
-#define NEEDSESCAPE(c) (c == '\\' || c == '"')
 #define B4TYPE         0
 #define INTYPE         1
 #define B4EQUAL                2
@@ -161,7 +157,19 @@ dn_parent(
        char    *s;
        int     inquote, gotesc;
 
-       if ( dn == NULL || *dn == '\0' || be_issuffix( be, dn ) ) {
+       if( dn == NULL ) {
+               return NULL;
+       }
+
+       while(*dn && SPACE(*dn)) {
+               dn++;
+       }
+
+       if( *dn == '\0' ) {
+               return( NULL );
+       }
+
+       if ( be_issuffix( be, dn ) ) {
                return( NULL );
        }
 
@@ -179,7 +187,7 @@ dn_parent(
                if ( *(s + 1) == '\0' ) {
                        return( NULL );
                } else {
-                       return( strdup( s + 1 ) );
+                       return( ch_strdup( &s[1] ) );
                }
        }
 
@@ -191,22 +199,96 @@ dn_parent(
        inquote = 0;
        for ( s = dn; *s; s++ ) {
                if ( *s == '\\' ) {
-                       if ( *(s + 1) )
+                       if ( *(s + 1) ) {
                                s++;
+                       }
                        continue;
                }
                if ( inquote ) {
-                       if ( *s == '"' )
+                       if ( *s == '"' ) {
                                inquote = 0;
+                       }
                } else {
-                       if ( *s == '"' )
+                       if ( *s == '"' ) {
                                inquote = 1;
-                       else if ( DNSEPARATOR( *s ) )
-                               return( strdup( s + 1 ) );
+                       } else if ( DNSEPARATOR( *s ) ) {
+                               return( ch_strdup( &s[1] ) );
+                       }
                }
        }
 
-       return( strdup("") );
+       return( ch_strdup( "" ) );
+}
+
+char * dn_rdn( 
+    Backend    *be,
+    char       *dn )
+{
+       char    *s;
+       int     inquote, gotesc;
+
+       if( dn == NULL ) {
+               return NULL;
+       }
+
+       while(*dn && SPACE(*dn)) {
+               dn++;
+       }
+
+       if( *dn == '\0' ) {
+               return( NULL );
+       }
+
+       if ( be_issuffix( be, dn ) ) {
+               return( NULL );
+       }
+
+       dn = ch_strdup( dn );
+
+       /*
+        * no =, assume it is a dns name, like blah@some.domain.name
+        * if the blah@ part is there, return some.domain.name.  if
+        * it's just some.domain.name, return domain.name.
+        */
+       if ( strchr( dn, '=' ) == NULL ) {
+               if ( (s = strchr( dn, '@' )) == NULL ) {
+                       if ( (s = strchr( dn, '.' )) == NULL ) {
+                               return( dn );
+                       }
+               }
+               *s = '\0';
+               return( dn );
+       }
+
+       /*
+        * else assume it is an X.500-style name, which looks like
+        * foo=bar,sha=baz,...
+        */
+
+       inquote = 0;
+
+       for ( s = dn; *s; s++ ) {
+               if ( *s == '\\' ) {
+                       if ( *(s + 1) ) {
+                               s++;
+                       }
+                       continue;
+               }
+               if ( inquote ) {
+                       if ( *s == '"' ) {
+                               inquote = 0;
+                       }
+               } else {
+                       if ( *s == '"' ) {
+                               inquote = 1;
+                       } else if ( DNSEPARATOR( *s ) ) {
+                               *s = '\0';
+                               return( dn );
+                       }
+               }
+       }
+
+       return( dn );
 }
 
 /*
@@ -233,7 +315,7 @@ dn_issuffix(
                return( 0 );
        }
 
-       return( strcasecmp( dn + dnlen - suffixlen, suffix ) == 0 );
+       return( strcmp( dn + dnlen - suffixlen, suffix ) == 0 );
 }
 
 /*