#include "slap.h"
+const struct berval slap_empty_bv = { 0, "" };
+
#define SLAP_LDAPDN_PRETTY 0x1
/*
return( LDAP_SUCCESS );
}
-#ifdef SLAP_DN_MIGRATION
-/*
- * these routines are provided for migration purposes only!
- * dn_normalize is deprecated in favor of dnNormalize
- * strcmp/strcasecmp for DNs is deprecated in favor of dnMatch
- *
- * other routines are likewise deprecated but may not yet have
- * replacement functions.
- */
-
-/*
- * dn_normalize - put dn into a canonical form suitable for storing
- * in a hash database. this involves normalizing the case as well as
- * the format. the dn is normalized in place as well as returned if valid.
- * Deprecated in favor of dnNormalize()
- */
-char *
-dn_normalize( char *dn )
-{
- struct berval val;
- struct berval *normalized = NULL;
- int rc;
-
- if ( dn == NULL || dn[0] == '\0' ) {
- return dn;
- }
-
- val.bv_val = dn;
- val.bv_len = strlen( dn );
-
- rc = dnNormalize( NULL, &val, &normalized );
- if ( rc != LDAP_SUCCESS ) {
- return NULL;
- }
-
- if ( val.bv_len < normalized->bv_len ) {
- ber_bvfree( normalized );
- return NULL;
- }
-
- AC_MEMCPY( dn, normalized->bv_val, normalized->bv_len + 1 );
- ber_bvfree( normalized );
-
- return dn;
-}
-
/*
* dnParent - dn's parent, in-place
*
* note: the incoming dn is assumed to be normalized/prettyfied,
* so that escaped rdn/ava separators are in '\'+hexpair form
*/
-int
+void
dnParent(
- const char *dn,
- const char **pdn )
+ struct berval *dn,
+ struct berval *pdn )
{
- const char *p;
+ char *p;
- p = strchr( dn, ',' );
+ p = strchr( dn->bv_val, ',' );
+ /* one-level dn */
if ( p == NULL ) {
- return LDAP_INVALID_DN_SYNTAX;
+ *pdn = slap_empty_bv;
+ return;
}
assert( DN_SEPARATOR( p[ 0 ] ) );
p++;
- assert( ! ASCII_SPACE( p[ 0 ] ) );
- *pdn = p;
-
- return LDAP_SUCCESS;
-}
-
-/*
- * dn_parent - return the dn's parent, in-place
- * FIXME: should be replaced by dnParent()
- */
-char *
-dn_parent(
- Backend *be,
- const char *dn )
-{
- const char *pdn;
-
- if ( dn == NULL ) {
- return NULL;
- }
-
- while ( dn[ 0 ] != '\0' && ASCII_SPACE( dn[ 0 ] ) ) {
- dn++;
- }
-
- if ( dn[ 0 ] == '\0' ) {
- return NULL;
- }
+ assert( ATTR_LEADCHAR( p[ 0 ] ) );
+ pdn->bv_val = p;
+ pdn->bv_len = dn->bv_len - (p - dn->bv_val);
- if ( be != NULL && be_issuffix( be, dn ) ) {
- return NULL;
- }
-
- if ( dnParent( dn, &pdn ) != LDAP_SUCCESS ) {
- return NULL;
- }
-
- return ( char * )pdn;
+ return;
}
-#endif /* SLAP_DN_MIGRATION */
-
int
dnExtractRdn(
}
/*
- * FIXME: should be replaced by dnExtractRdn()
+ * We can assume the input is a prettied or normalized DN
*/
int
dn_rdnlen(
Backend *be,
struct berval *dn_in )
{
- int rc;
const char *p;
assert( dn_in );
return 0;
}
- if ( be != NULL && be_issuffix( be, dn_in->bv_val ) ) {
+ if ( be != NULL && be_issuffix( be, dn_in ) ) {
return 0;
}
- rc = ldap_str2rdn( dn_in->bv_val, NULL, (char **)&p,
- LDAP_DN_FORMAT_LDAP | LDAP_DN_SKIP );
- if ( rc != LDAP_SUCCESS ) {
- return 0;
- }
+ p = strchr( dn_in->bv_val, ',' );
- return p - dn_in->bv_val;
+ return p ? p - dn_in->bv_val : dn_in->bv_len;
}
}
/* no rdn separator or escaped rdn separator */
- if ( d > 1 && ( !DN_SEPARATOR( dn->bv_val[ d - 1 ] )
- || DN_ESCAPE( dn->bv_val[ d - 2 ] ) ) ) {
+ if ( d > 1 && !DN_SEPARATOR( dn->bv_val[ d - 1 ] ) ) {
return 0;
}