static struct ldb_message *get_best_match(struct ldb_dn *dn,
		                          struct ldb_result *result)
{
	int matched = 0;    /* Index of the current best match in result */
	size_t length = 0;  /* The length of the current candidate       */
	const struct ldb_val *target = NULL;    /* value we're looking for */
	const struct ldb_val *candidate = NULL; /* current candidate value */
	int x = 0;

	target = ldb_dn_get_rdn_val(dn);
	for(x = 0; x < result->count; x++) {
		candidate = ldb_dn_get_rdn_val(result->msgs[x]->dn);
		if (strncasecmp((char *) target->data,
				(char *) candidate->data,
				target->length) == 0) {
			/* Exact match stop searching and return */
			return result->msgs[x];
		}
		if (candidate->length > length) {
			matched = x;
			length  = candidate->length;
		}
	}
	return result->msgs[matched];
}
static struct ldb_message *get_best_match(struct ldb_dn *dn,
		                          struct ldb_result *result)
{
	int matched = 0;     
	size_t length = 0;   
	const struct ldb_val *target = NULL;     
	const struct ldb_val *candidate = NULL;  
	int x = 0;

	target = ldb_dn_get_rdn_val(dn);
	for(x = 0; x < result->count; x++) {
		candidate = ldb_dn_get_rdn_val(result->msgs[x]->dn);
		if (strncasecmp((char *) target->data,
				(char *) candidate->data,
				target->length) == 0) {
			 
			return result->msgs[x];
		}
		if (candidate->length > length) {
			matched = x;
			length  = candidate->length;
		}
	}
	return result->msgs[matched];
}