#include "slap.h"
+const struct berval slap_empty_bv = { 0, "" };
+
#define SLAP_LDAPDN_PRETTY 0x1
/*
* (use memcmp, which implies alphabetical order in case of IA5 value;
* this should guarantee the repeatability of the operation).
*
+ * Note: the sorting can be slightly improved by sorting first
+ * by attribute type length, then by alphabetical order.
+ *
* uses a linear search; should be fine since the number of AVAs in
* a RDN should be limited.
*/
return( LDAP_SUCCESS );
}
+/*
+ * 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
+dnParent(
+ struct berval *dn,
+ struct berval *pdn )
+{
+ const char *p;
+
+ p = strchr( dn->bv_val, ',' );
+
+ /* one-level dn */
+ if ( p == NULL ) {
+ pdn->bv_val = "";
+ pdn->bv_len = 0;
+ return LDAP_SUCCESS;
+ }
+
+ assert( DN_SEPARATOR( p[ 0 ] ) );
+ p++;
+
+ assert( ATTR_LEADCHAR( p[ 0 ] ) );
+ pdn->bv_val = p;
+ pdn->bv_len = dn->bv_len - (p - dn->bv_val);
+
+ return LDAP_SUCCESS;
+}
+
#ifdef SLAP_DN_MIGRATION
/*
* these routines are provided for migration purposes only!
return dn;
}
-/*
- * dnParent - dn's parent, in-place
- */
-int
-dnParent(
- const char *dn,
- const char **pdn )
-{
- const char *p;
- int rc;
-
- rc = ldap_str2rdn( dn, NULL, (char **)&p,
- LDAP_DN_FORMAT_LDAP | LDAP_DN_SKIP );
- if ( rc != LDAP_SUCCESS ) {
- return rc;
- }
-
- /* Parent is root */
- if (*p == '\0') {
- *pdn = "";
- return LDAP_SUCCESS;
- }
-
- assert( DN_SEPARATOR( p[ 0 ] ) );
- p++;
-
- while ( ASCII_SPACE( p[ 0 ] ) ) {
- p++;
- }
-
- *pdn = p;
-
- return LDAP_SUCCESS;
-}
-
/*
* dn_parent - return the dn's parent, in-place
* FIXME: should be replaced by dnParent()
const char *dn )
{
const char *pdn;
+ struct berval bv;
if ( dn == NULL ) {
return NULL;
return NULL;
}
- if ( be != NULL && be_issuffix( be, dn ) ) {
+ bv.bv_val = dn;
+ bv.bv_len = strlen(bv.bv_val);
+ if ( be != NULL && be_issuffix( be, &bv ) ) {
return NULL;
}
}
/*
- * FIXME: should be replaced by dnExtractRdn()
+ * We can assume the input is a prettied or normalized DN
*/
int
dn_rdnlen(
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;
}