summaryrefslogtreecommitdiffstats
path: root/ldap/servers/slapd/dn.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldap/servers/slapd/dn.c')
-rw-r--r--ldap/servers/slapd/dn.c133
1 files changed, 75 insertions, 58 deletions
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
index bd22f76e..e50ec768 100644
--- a/ldap/servers/slapd/dn.c
+++ b/ldap/servers/slapd/dn.c
@@ -493,13 +493,19 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
char *d = NULL; /* work pointer for dest */
char *ends = NULL;
char *endd = NULL;
- char *typestart = NULL;
- char *subtypestart = NULL; /* used for the nested DN */
char *lastesc = NULL;
+ /* rdn avs for the main DN */
+ char *typestart = NULL;
int rdn_av_count = 0;
struct berval *rdn_avs = NULL;
struct berval initial_rdn_av_stack[ SLAPI_DNNORM_INITIAL_RDN_AVS ];
+ /* rdn avs for the nested DN */
+ char *subtypestart = NULL; /* used for nested rdn avs */
+ int subrdn_av_count = 0;
+ struct berval *subrdn_avs = NULL;
+ struct berval subinitial_rdn_av_stack[ SLAPI_DNNORM_INITIAL_RDN_AVS ];
int chkblank = 0;
+ int avstat = 0;
if (NULL == dest) {
goto bail;
@@ -596,6 +602,12 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
rc = -1;
goto bail;
} /* otherwise, go through */
+ if (ISESCAPE(*s)) {
+ subtypestart = NULL; /* if escaped, can't be multivalued dn */
+ } else {
+ subtypestart = d; /* prepare for '+' in the nested DN, if any */
+ }
+ subrdn_av_count = 0;
case INVALUE: /* in value; cn=ABC */
/* ^ */
if (ISESCAPE(*s)) {
@@ -612,20 +624,6 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
goto bail;
} else {
if (ISEQUAL(*(s+1))) {
- if (NULL == subtypestart) {
- /* e.g., cn=a\=b\,c\=d */
- /* ^ */
- *d = '\0';
- subtypestart = strrchr(*dest, '=');
- if (subtypestart) {
- /* pointing 'a' in the above example */
- subtypestart++;
- }
- /* else
- * No equal for the nested DN looking value.
- * Just through it.
- */
- }
while (ISSPACE(*(d-1))) {
/* remove trailing spaces */
d--;
@@ -649,16 +647,18 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
* multivalued RDNs.
*/
if (subtypestart &&
- (ISPLUS(*(s+1)) || rdn_av_count > 0)) {
- add_rdn_av(subtypestart, d, &rdn_av_count,
- &rdn_avs, initial_rdn_av_stack);
+ (ISPLUS(*(s+1)) || subrdn_av_count > 0)) {
+ add_rdn_av(subtypestart, d, &subrdn_av_count,
+ &subrdn_avs, subinitial_rdn_av_stack);
}
if (!ISPLUS(*(s+1))) { /* at end of this RDN */
- if (rdn_av_count > 1) {
- sort_rdn_avs( rdn_avs, rdn_av_count, 1 );
+ if (subrdn_av_count > 1) {
+ sort_rdn_avs( subrdn_avs,
+ subrdn_av_count, 1 );
}
- if (rdn_av_count > 0) {
- reset_rdn_avs( &rdn_avs, &rdn_av_count );
+ if (subrdn_av_count > 0) {
+ reset_rdn_avs( &subrdn_avs,
+ &subrdn_av_count );
subtypestart = NULL;
}
}
@@ -667,9 +667,17 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
*d++ = *s++; /* '\\' */
PR_snprintf(d, 3, "%X", *s); /* hexpair */
d += 2;
- if (ISPLUS(*s) && PL_strnstr(s, "\\=", ends - s)) {
+ if (ISPLUS(*s)) {
/* next type start of multi values */
- subtypestart = d;
+ /* should not be a escape char AND should be
+ * followed by \\= or \\3D */
+ if (!ISESCAPE(*s) &&
+ (PL_strnstr(s, "\\=", ends - s) ||
+ PL_strncaserstr(s, "\\3D", ends - s))) {
+ subtypestart = d;
+ } else {
+ subtypestart = NULL;
+ }
}
if (SEPARATOR(*s) || ISEQUAL(*s)) {
while (ISSPACE(*(s+1)))
@@ -681,26 +689,12 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
}
} else if (((state == INVALUE1ST) &&
(s+2 < ends) && LEADNEEDSESCAPESTR(s+1)) ||
- ((state == INVALUE) &&
+ ((state == INVALUE) &&
(((s+2 < ends) && NEEDSESCAPESTR(s+1)) ||
(ISEOV(s+3, ends) && ISBLANKSTR(s+1))))) {
/* e.g., cn=abc\20 ,... */
/* ^ */
if (ISEQUALSTR(s+1)) {
- if (NULL == subtypestart) {
- /* e.g., cn=a\3Db\2Cc\3Dd */
- /* ^ */
- *d = '\0';
- subtypestart = strrchr(*dest, '=');
- if (subtypestart) {
- /* pointing 'a' in the above example */
- subtypestart++;
- }
- /* else
- * No equal for the nested DN looking value.
- * Just through it.
- */
- }
while (ISSPACE(*(d-1))) {
/* remove trailing spaces */
d--;
@@ -724,25 +718,33 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
* multivalued RDNs.
*/
if (subtypestart &&
- (ISPLUSSTR(s+1) || rdn_av_count > 0)) {
- add_rdn_av(subtypestart, d, &rdn_av_count,
- &rdn_avs, initial_rdn_av_stack);
+ (ISPLUSSTR(s+1) || subrdn_av_count > 0)) {
+ add_rdn_av(subtypestart, d, &subrdn_av_count,
+ &subrdn_avs, subinitial_rdn_av_stack);
}
if (!ISPLUSSTR(s+1)) { /* at end of this RDN */
- if (rdn_av_count > 1) {
- sort_rdn_avs( rdn_avs, rdn_av_count, 1 );
+ if (subrdn_av_count > 1) {
+ sort_rdn_avs( subrdn_avs, subrdn_av_count, 1 );
}
- if (rdn_av_count > 0) {
- reset_rdn_avs( &rdn_avs, &rdn_av_count );
+ if (subrdn_av_count > 0) {
+ reset_rdn_avs( &subrdn_avs, &subrdn_av_count );
+ subtypestart = NULL;
}
}
}
*d++ = *s++; /* '\\' */
*d++ = *s++; /* HEX */
*d++ = *s++; /* HEX */
- if (ISPLUSSTR(s-2) && PL_strnstr(s, "\\=", ends - s)) {
+ if (ISPLUSSTR(s-2)) {
/* next type start of multi values */
- subtypestart = d;
+ /* should not be a escape char AND should be followed
+ * by \\= or \\3D */
+ if (!ISESCAPE(*s) && (PL_strnstr(s, "\\=", ends - s) ||
+ PL_strncaserstr(s, "\\3D", ends - s))) {
+ subtypestart = d;
+ } else {
+ subtypestart = NULL;
+ }
}
if (SEPARATORSTR(s-2) || ISEQUALSTR(s-2)) {
while (ISSPACE(*s)) /* remove leading spaces */
@@ -804,6 +806,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
continue;
}
subtypestart = d; /* prepare for '+' in the quoted value, if any */
+ subrdn_av_count = 0;
case INQUOTEDVALUE:
if (ISQUOTE(*s)) {
if (ISESCAPE(*(d-1))) { /* the quote is escaped */
@@ -855,16 +858,17 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
* Track and sort attribute values within
* multivalued RDNs.
*/
- if (ISPLUS(*s) || rdn_av_count > 0) {
- add_rdn_av(subtypestart, d, &rdn_av_count,
- &rdn_avs, initial_rdn_av_stack);
+ if (subtypestart &&
+ (ISPLUS(*s) || subrdn_av_count > 0)) {
+ add_rdn_av(subtypestart, d, &subrdn_av_count,
+ &subrdn_avs, subinitial_rdn_av_stack);
}
if (!ISPLUS(*s)) { /* at end of this RDN */
- if (rdn_av_count > 1) {
- sort_rdn_avs( rdn_avs, rdn_av_count, 1 );
+ if (subrdn_av_count > 1) {
+ sort_rdn_avs( subrdn_avs, subrdn_av_count, 1 );
}
- if (rdn_av_count > 0) {
- reset_rdn_avs( &rdn_avs, &rdn_av_count );
+ if (subrdn_av_count > 0) {
+ reset_rdn_avs( &subrdn_avs, &subrdn_av_count );
subtypestart = NULL;
}
}
@@ -897,7 +901,8 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
* Track and sort attribute values within
* multivalued RDNs.
*/
- if (ISPLUS(*s) || rdn_av_count > 0) {
+ if (typestart &&
+ (ISPLUS(*s) || rdn_av_count > 0)) {
add_rdn_av(typestart, d, &rdn_av_count,
&rdn_avs, initial_rdn_av_stack);
}
@@ -907,6 +912,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
}
if (rdn_av_count > 0) {
reset_rdn_avs( &rdn_avs, &rdn_av_count );
+ typestart = NULL;
}
}
@@ -931,7 +937,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
* rdn to our list to sort. We should only be in the INVALUE
* or B4SEPARATOR state if we have a valid rdn component to
* be added. */
- if ((rdn_av_count > 0) && ((state == INVALUE1ST) ||
+ if (typestart && (rdn_av_count > 0) && ((state == INVALUE1ST) ||
(state == INVALUE) || (state == B4SEPARATOR))) {
add_rdn_av(typestart, d, &rdn_av_count, &rdn_avs, initial_rdn_av_stack);
}
@@ -1160,6 +1166,17 @@ rdn_av_swap( struct berval *av1, struct berval *av2, int escape )
/* Introduced for the upgrade tool. DON'T USE THIS API! */
char *
+slapi_dn_normalize_original( char *dn )
+{
+ /* LDAPDebug( LDAP_DEBUG_TRACE, "=> slapi_dn_normalize \"%s\"\n", dn, 0, 0 ); */
+ *(substr_dn_normalize_orig( dn, dn + strlen( dn ))) = '\0';
+ /* LDAPDebug( LDAP_DEBUG_TRACE, "<= slapi_dn_normalize \"%s\"\n", dn, 0, 0 ); */
+
+ return( dn );
+}
+
+/* Introduced for the upgrade tool. DON'T USE THIS API! */
+char *
slapi_dn_normalize_case_original( char *dn )
{
/* LDAPDebug( LDAP_DEBUG_TRACE, "=> slapi_dn_normalize \"%s\"\n", dn, 0, 0 ); */