amoralej / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 years ago
Clone

Blame SOURCES/0062-Ticket-47591-entries-with-empty-objectclass-attribut.patch

cc3dff
From 5edce023ae5977bebfdfd05ad21febc51c5b428b Mon Sep 17 00:00:00 2001
cc3dff
From: Ludwig Krispenz <lkrispen@redhat.com>
cc3dff
Date: Tue, 26 Nov 2013 09:15:53 +0100
cc3dff
Subject: [PATCH 62/65] Ticket 47591 - entries with empty objectclass attribute
cc3dff
 value can be hidden
cc3dff
cc3dff
Bug Description:   The problem is that for the empty value
cc3dff
cc3dff
	objectClass;vdcsn-5283b8e0000000c80000;deleted
cc3dff
cc3dff
	it is compared to "ldapsubentry" and "nstombstone"
cc3dff
cc3dff
	'if (PL_strncasecmp(type.bv_val,"tombstone",0)'
cc3dff
cc3dff
	and with length 0, this is always true.
cc3dff
cc3dff
Fix Description:   add a check bv_len >= strlen(valuetocompare)
cc3dff
			or	bv_len == strlen(valuetocompare)
cc3dff
			define constants for lengths
cc3dff
cc3dff
https://fedorahosted.org/389/ticket/47591
cc3dff
cc3dff
Reviewed by: richm, thanks
cc3dff
(cherry picked from commit 6b47eb4f54ff1e0a8b9c4aa9f3e6c3c3d958fd56)
cc3dff
---
cc3dff
 ldap/servers/slapd/entry.c        | 15 ++++++++-------
cc3dff
 ldap/servers/slapd/slapi-plugin.h | 15 ++++++++++++++-
cc3dff
 2 files changed, 22 insertions(+), 8 deletions(-)
cc3dff
cc3dff
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
cc3dff
index e0248c8..60e1dfe 100644
cc3dff
--- a/ldap/servers/slapd/entry.c
cc3dff
+++ b/ldap/servers/slapd/entry.c
cc3dff
@@ -340,7 +340,7 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
cc3dff
 			rawdn = NULL; /* Set once in the loop. 
cc3dff
 							 This won't affect the caller's passed address. */
cc3dff
 		}
cc3dff
-		if ( PL_strncasecmp( type.bv_val, "dn", type.bv_len ) == 0 ) {
cc3dff
+		if ( type.bv_len == SLAPI_ATTR_DN_LENGTH && PL_strncasecmp( type.bv_val, SLAPI_ATTR_DN, type.bv_len ) == 0 ) {
cc3dff
 			if ( slapi_entry_get_dn_const(e)!=NULL ) {
cc3dff
 				char ebuf[ BUFSIZ ];
cc3dff
 				LDAPDebug( LDAP_DEBUG_TRACE,
cc3dff
@@ -376,7 +376,7 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
cc3dff
 			continue;
cc3dff
 		}
cc3dff
 
cc3dff
-		if ( PL_strncasecmp( type.bv_val, "rdn", type.bv_len ) == 0 ) {
cc3dff
+		if ( type.bv_len == SLAPI_ATTR_RDN_LENGTH && PL_strncasecmp( type.bv_val, SLAPI_ATTR_RDN, type.bv_len ) == 0 ) {
cc3dff
 			if ( NULL == slapi_entry_get_rdn_const( e )) {
cc3dff
 				slapi_entry_set_rdn( e, value.bv_val );
cc3dff
 			}
cc3dff
@@ -387,13 +387,13 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
cc3dff
 
cc3dff
 		/* If SLAPI_STR2ENTRY_NO_ENTRYDN is set, skip entrydn */
cc3dff
 		if ( (flags & SLAPI_STR2ENTRY_NO_ENTRYDN) &&
cc3dff
-		     PL_strncasecmp( type.bv_val, "entrydn", type.bv_len ) == 0 ) {
cc3dff
+		     type.bv_len == SLAPI_ATTR_ENTRYDN_LENGTH && PL_strncasecmp( type.bv_val, SLAPI_ATTR_ENTRYDN, type.bv_len ) == 0 ) {
cc3dff
 			if (freeval) slapi_ch_free_string(&value.bv_val);
cc3dff
 			continue;
cc3dff
 		}
cc3dff
 
cc3dff
 		/* retrieve uniqueid */
cc3dff
-		if ( PL_strncasecmp (type.bv_val, SLAPI_ATTR_UNIQUEID, type.bv_len) == 0 ){
cc3dff
+		if ( type.bv_len == SLAPI_ATTR_UNIQUEID_LENGTH && PL_strncasecmp (type.bv_val, SLAPI_ATTR_UNIQUEID, type.bv_len) == 0 ){
cc3dff
 
cc3dff
 			if (e->e_uniqueid != NULL){
cc3dff
 				LDAPDebug (LDAP_DEBUG_TRACE, 
cc3dff
@@ -411,10 +411,11 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
cc3dff
 			continue;
cc3dff
 		}
cc3dff
 		
cc3dff
-		if (PL_strncasecmp(type.bv_val,"objectclass",type.bv_len) == 0) {
cc3dff
-			if (PL_strncasecmp(value.bv_val,"ldapsubentry",value.bv_len) == 0)
cc3dff
+		if (value_state == VALUE_PRESENT && type.bv_len >= SLAPI_ATTR_OBJECTCLASS_LENGTH
cc3dff
+				&& PL_strncasecmp(type.bv_val, SLAPI_ATTR_OBJECTCLASS, type.bv_len) == 0) {
cc3dff
+			if (value.bv_len >= SLAPI_ATTR_VALUE_SUBENTRY_LENGTH && PL_strncasecmp(value.bv_val,SLAPI_ATTR_VALUE_SUBENTRY,value.bv_len) == 0)
cc3dff
 				e->e_flags |= SLAPI_ENTRY_LDAPSUBENTRY;
cc3dff
-			if (PL_strncasecmp(value.bv_val, SLAPI_ATTR_VALUE_TOMBSTONE,value.bv_len) == 0)
cc3dff
+			if (value.bv_len >= SLAPI_ATTR_VALUE_TOMBSTONE_LENGTH && PL_strncasecmp(value.bv_val, SLAPI_ATTR_VALUE_TOMBSTONE,value.bv_len) == 0)
cc3dff
 				e->e_flags |= SLAPI_ENTRY_FLAG_TOMBSTONE;
cc3dff
 		}
cc3dff
 		
cc3dff
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
cc3dff
index d456af8..d8cfe33 100644
cc3dff
--- a/ldap/servers/slapd/slapi-plugin.h
cc3dff
+++ b/ldap/servers/slapd/slapi-plugin.h
cc3dff
@@ -395,9 +395,22 @@ NSPR_API(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char *fmt, ...)
cc3dff
 #define SLAPI_ATTR_OBJECTCLASS			"objectclass"
cc3dff
 #define SLAPI_ATTR_VALUE_TOMBSTONE		"nsTombstone"
cc3dff
 #define SLAPI_ATTR_VALUE_PARENT_UNIQUEID	"nsParentUniqueID"
cc3dff
+#define SLAPI_ATTR_VALUE_SUBENTRY		"ldapsubentry"
cc3dff
 #define SLAPI_ATTR_NSCP_ENTRYDN 		"nscpEntryDN"
cc3dff
 #define SLAPI_ATTR_ENTRYUSN 			"entryusn"
cc3dff
-#define SLAPI_ATTR_ENTRYDN 				"entrydn"
cc3dff
+#define SLAPI_ATTR_ENTRYDN 			"entrydn"
cc3dff
+#define SLAPI_ATTR_DN 				"dn"
cc3dff
+#define SLAPI_ATTR_RDN 				"rdn"
cc3dff
+#define SLAPI_ATTR_UNIQUEID_LENGTH		10
cc3dff
+#define SLAPI_ATTR_OBJECTCLASS_LENGTH		11
cc3dff
+#define SLAPI_ATTR_VALUE_TOMBSTONE_LENGTH	11
cc3dff
+#define SLAPI_ATTR_VALUE_PARENT_UNIQUEID_LENGTH	16
cc3dff
+#define SLAPI_ATTR_VALUE_SUBENTRY_LENGTH	12
cc3dff
+#define SLAPI_ATTR_NSCP_ENTRYDN_LENGTH 		11
cc3dff
+#define SLAPI_ATTR_ENTRYUSN_LENGTH 		8
cc3dff
+#define SLAPI_ATTR_ENTRYDN_LENGTH 		7
cc3dff
+#define SLAPI_ATTR_DN_LENGTH 			2
cc3dff
+#define SLAPI_ATTR_RDN_LENGTH 			3
cc3dff
 
cc3dff
 
cc3dff
 /* opaque structures */
cc3dff
-- 
cc3dff
1.8.1.4
cc3dff