Patch for off-by-one ldap search error.

Peter Haight peterh at sapros.com
Wed Feb 27 15:49:24 GMT 2002


It was constantly missing the last user added when I was browsing through the
user list. It turned out that in my setup, the last user added would always
be the first user in the LDAP query.

This patch is against the SAMBA_2_2 cvs branch.

-------------- next part --------------
Index: pdb_ldap.c
===================================================================
RCS file: /cvsroot/samba/source/passdb/pdb_ldap.c,v
retrieving revision 1.1.2.24
diff -u -r1.1.2.24 pdb_ldap.c
--- pdb_ldap.c	5 Feb 2002 15:58:40 -0000	1.1.2.24
+++ pdb_ldap.c	27 Feb 2002 23:37:24 -0000
@@ -56,6 +56,7 @@
 	LDAP *ldap_struct;
 	LDAPMessage *result;
 	LDAPMessage *entry;
+	int index;
 };
 
 static struct ldap_enum_info global_ldap_ent;
@@ -705,6 +706,7 @@
 
 	global_ldap_ent.entry = ldap_first_entry(global_ldap_ent.ldap_struct,
 				 global_ldap_ent.result);
+	global_ldap_ent.index = -1;
 
 	return True;
 }
@@ -731,8 +733,11 @@
 	if (!global_ldap_ent.entry)
 		return False;
 
-	global_ldap_ent.entry =	ldap_next_entry(global_ldap_ent.ldap_struct,
-				global_ldap_ent.entry);
+	global_ldap_ent.index++;
+	if (global_ldap_ent.index > 0)
+	{
+		global_ldap_ent.entry =	ldap_next_entry(global_ldap_ent.ldap_struct, global_ldap_ent.entry);
+	}
 
 	if (global_ldap_ent.entry != NULL)
 	{


More information about the samba-technical mailing list