Index: emsabp.c
===================================================================
--- emsabp.c	(revision 1356)
+++ emsabp.c	(working copy)
@@ -213,54 +200,50 @@
 	struct loadparm_context	*lp_ctx;
 	struct GUID		*guid = (struct GUID *) NULL;
 	const char		*netbiosname = NULL;
-	const char		*guid_str = NULL;
-	enum ldb_scope		scope = LDB_SCOPE_SUBTREE;
+	const struct ldb_val	*ldb_value = NULL;
 	struct ldb_result	*res = NULL;
-	char			*dn = NULL;
 	struct ldb_dn		*ldb_dn = NULL;
 	const char * const	recipient_attrs[] = { "*", NULL };
-	const char		*firstorgdn = NULL;
+	const char		*server_entry = NULL;
 
 	lp_ctx = emsabp_ctx->lp_ctx;
 
 	netbiosname = lp_netbios_name(lp_ctx);
 	if (!netbiosname) return NULL;
 
-	/* Step 1. Find the Exchange Organization */
+	/* Step 1. Find server record in CN=Servers,CN=Default-First-Site-Name,CN=Sites,<CONFIG_DN> sub-tree */
 	ret = ldb_search(emsabp_ctx->conf_ctx, emsabp_ctx->mem_ctx, &res,
 			 ldb_get_default_basedn(emsabp_ctx->conf_ctx),
-			 scope, recipient_attrs, "(objectClass=msExchOrganizationContainer)");
+			 LDB_SCOPE_SUBTREE, recipient_attrs, 
+			 "(&(objectClass=server)(cn=%s))", netbiosname);
 
 	if (ret != LDB_SUCCESS || !res->count) {
 		return NULL;
 	}
 
-	firstorgdn = ldb_msg_find_attr_as_string(res->msgs[0], "distinguishedName", NULL);
-	if (!firstorgdn) {
+	server_entry = ldb_msg_find_attr_as_string(res->msgs[0], "distinguishedName", NULL);
+	if (!server_entry) {
 		return NULL;
 	}
 
-	/* Step 2. Find the OpenChange Server object */
-	dn = talloc_asprintf(emsabp_ctx->mem_ctx, "CN=Servers,CN=First Administrative Group,CN=Administrative Groups,%s",
-			     firstorgdn);
-	ldb_dn = ldb_dn_new(emsabp_ctx->mem_ctx, emsabp_ctx->conf_ctx, dn);
-	talloc_free(dn);
+	/* Step 2. Fetch "NTDS Settings" info for the server */
+	ldb_dn = ldb_dn_new(emsabp_ctx->mem_ctx, emsabp_ctx->conf_ctx, server_entry);
 	if (!ldb_dn_validate(ldb_dn)) {
 		return NULL;
 	}
 
 	ret = ldb_search(emsabp_ctx->conf_ctx, emsabp_ctx->mem_ctx, &res, ldb_dn, 
-			 scope, recipient_attrs, "(cn=%s)", netbiosname);
+			 LDB_SCOPE_ONELEVEL, recipient_attrs, "(cn=NTDS Settings)");
 	if (ret != LDB_SUCCESS || !res->count) {
 		return NULL;
 	}
 
 	/* Step 3. Retrieve the objectGUID GUID */
-	guid_str = ldb_msg_find_attr_as_string(res->msgs[0], "objectGUID", NULL);
-	if (!guid_str) return NULL;
+	ldb_value = ldb_msg_find_ldb_val(res->msgs[0], "objectGUID");
+	if (!ldb_value)	return NULL;
 
 	guid = talloc_zero(emsabp_ctx->mem_ctx, struct GUID);
-	GUID_from_string(guid_str, guid);
+	GUID_from_data_blob(ldb_value, guid);
 	
 	return guid;
 }
