#include "portable.h"
#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "slap.h"
-static char **dn_explode();
+#include <ac/ctype.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#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
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 );
}
if ( *(s + 1) == '\0' ) {
return( NULL );
} else {
- return( strdup( s + 1 ) );
+ return( ch_strdup( &s[1] ) );
+ }
+ }
+
+ /*
+ * 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 ) ) {
+ return( ch_strdup( &s[1] ) );
+ }
+ }
+ }
+
+ 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 );
}
/*
*/
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 ) ) {
+ *s = '\0';
+ return( dn );
+ }
}
}
- return( strdup("") );
+ return( dn );
}
/*
return( 0 );
}
- return( strcasecmp( dn + dnlen - suffixlen, suffix ) == 0 );
+ return( strcmp( dn + dnlen - suffixlen, suffix ) == 0 );
}
/*