svn commit: samba r2754 - in branches/SAMBA_4_0/source/ldap_server: .

idra at samba.org idra at samba.org
Wed Sep 29 17:37:59 GMT 2004


Author: idra
Date: 2004-09-29 17:37:59 +0000 (Wed, 29 Sep 2004)
New Revision: 2754

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source/ldap_server&rev=2754&nolog=1

Log:

Change sldb_trim_dn() to be sldb_fix_dn() as we are not really trimming.

Make it handle all cases:
- remove spaces before and after ','
- remove spaces after '='

TODO: check if there are escape chars in the RFC, they are not handled here yet.

Simo.


Modified:
   branches/SAMBA_4_0/source/ldap_server/ldap_simple_ldb.c


Changeset:
Modified: branches/SAMBA_4_0/source/ldap_server/ldap_simple_ldb.c
===================================================================
--- branches/SAMBA_4_0/source/ldap_server/ldap_simple_ldb.c	2004-09-29 15:26:38 UTC (rev 2753)
+++ branches/SAMBA_4_0/source/ldap_server/ldap_simple_ldb.c	2004-09-29 17:37:59 UTC (rev 2754)
@@ -34,44 +34,60 @@
 } while(0)
 
 
-static const char *sldb_trim_dn(TALLOC_CTX *mem_ctx, const char *dn)
+/*
+   fix the DN removing unneded non-significative spaces
+   this function ASSUME the string is talloced
+ */
+static char *sldb_fix_dn(const char *dn)
 {
-	char *new_dn;
-	char *w;
-	int i,s = -1;
-	int before = 1;
+	char *new_dn, *n, *current;
+	int i, j, k;
 
-	new_dn = talloc_strdup(mem_ctx, dn);
+	/* alloc enough room to host the whole dn as multibyte string */
+	new_dn = talloc(dn, strlen(dn) + 1);
 	if (!new_dn) {
-		return dn;
+		DEBUG(0, ("sldb_fix_dn: Out of memory!"));
+		return NULL;
 	}
 
-	w = new_dn;
-	for (i=0; dn[i]; i++) {
+	i = j = 0;
+	while (dn[i] != '\0') {
+		/* it is legal to check for ascii chars in utf-8 as it is
+		 * guaranted to never contain ascii chars (up to 0x7F) as part
+		 * of a multibyte sequence */
 
-		if (dn[i] == ' ') {
-			if (s == -1) s = i;
+		new_dn[j] = dn[i];
+
+		if (dn[i] == ',' || dn[i] == '=') {
+			/* skip spaces after ',' or '=' */
+			for (++i; dn[i] == ' '; i++) ;
+			j++;
 			continue;
 		}
-
-		if (before && dn[i] != ',' && s != -1) {
-			i=s;
+		if (dn[i] == ' ') {
+			/* check if there's a ',' after these spaces */
+			for (k = i; dn[k] == ' '; k++) ;
+			if (dn[k] == ',') {
+				/* skip spaces */
+				i = k;
+				continue;
+			} else {
+				/* fill the dest buffer with the spaces */
+				for (; dn[i] == ' '; i++, j++) {
+					new_dn[j] = ' ';
+				}
+				continue;
+			}
 		}
-		if (dn[i] == ',') {
-			before = 0;
-		} else {
-			before = 1;
-		}
-		*w = dn[i];
-		w++;
-		s = -1;
+		i++;
+		j++;
 	}
+	new_dn[j] = '\0';
 
-	*w = '\0';
-
 	return new_dn;
 }
 
+
 static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
 				     struct ldap_SearchRequest *r)
 {
@@ -91,7 +107,10 @@
 
 	samdb = samdb_connect(call);
 	ldb = samdb->ldb;
-	basedn = sldb_trim_dn(samdb, r->basedn);
+	basedn = sldb_fix_dn(r->basedn);
+	if (basedn == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	DEBUG(10, ("sldb_Search: basedn: [%s]\n", basedn));
 	DEBUG(10, ("sldb_Search: filter: [%s]\n", r->filter));
@@ -207,7 +226,10 @@
 
 	samdb = samdb_connect(call);
 	ldb = samdb->ldb;
-	dn = sldb_trim_dn(samdb, r->dn);
+	dn = sldb_fix_dn(r->dn);
+	if (dn == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	DEBUG(10, ("sldb_add: dn: [%s]\n", dn));
 
@@ -301,7 +323,10 @@
 
 	samdb = samdb_connect(call);
 	ldb = samdb->ldb;
-	dn = sldb_trim_dn(samdb, r->dn);
+	dn = sldb_fix_dn(r->dn);
+	if (dn == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	DEBUG(10, ("sldb_Del: dn: [%s]\n", dn));
 
@@ -352,7 +377,10 @@
 
 	samdb = samdb_connect(call);
 	ldb = samdb->ldb;
-	dn = sldb_trim_dn(samdb, r->dn);
+	dn = sldb_fix_dn(r->dn);
+	if (dn == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	DEBUG(10, ("sldb_modify: dn: [%s]\n", dn));
 
@@ -465,7 +493,10 @@
 
 	samdb = samdb_connect(call);
 	ldb = samdb->ldb;
-	dn = sldb_trim_dn(samdb, r->dn);
+	dn = sldb_fix_dn(r->dn);
+	if (dn == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	DEBUG(10, ("sldb_Compare: dn: [%s]\n", dn));
 	filter = talloc_asprintf(samdb, "(%s=%*s)", r->attribute, r->value.length, r->value.data);



More information about the samba-cvs mailing list