[PATCH 5/6] adsldp: only report search errors when iterating results

Damjan Jovanovic damjan.jov at gmail.com
Sun Feb 7 09:55:31 CST 2021


It's unclear whether MSDN's claim that searches are deferred
until GetFirstRow()/GetNextRow() is true, but .NET is
extremely unhappy if IDirectorySearch::ExecuteSearch()
fails, and even if a query with 0 results returns something
other than S_ADS_NOMORE_ROWS. For now, at least delay
returning the search error until GetFirstRow()/GetNextRow().

Signed-off-by: Damjan Jovanovic <damjan.jov at gmail.com>
---
 dlls/adsldp/adsldp.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
-------------- next part --------------
diff --git a/dlls/adsldp/adsldp.c b/dlls/adsldp/adsldp.c
index 1dacb0d6624..a04b1b5de97 100644
--- a/dlls/adsldp/adsldp.c
+++ b/dlls/adsldp/adsldp.c
@@ -409,6 +409,7 @@ typedef struct
 
 struct ldap_search_context
 {
+    HRESULT search_hr;
     LDAPSearch *page;
     LDAPMessage *res, *entry;
     BerElement *ber;
@@ -1439,15 +1440,12 @@ static HRESULT WINAPI search_ExecuteSearch(IDirectorySearch *iface, LPWSTR filte
         err = ldap_search_ext_sW(ldap->ld, ldap->object, ldap->search.scope, filter, props,
                                  ldap->search.attribtypes_only, ctrls, NULL, NULL, 0, &ldap_ctx->res);
     heap_free(props);
+    ldap_ctx->search_hr = S_OK;
     if (err != LDAP_SUCCESS)
     {
-        TRACE("ldap_search_sW error %#x\n", err);
-        if (ldap_ctx->page)
-            ldap_search_abandon_page(ldap->ld, ldap_ctx->page);
-        heap_free(ldap_ctx);
-        return HRESULT_FROM_WIN32(map_ldap_error(err));
+        TRACE("ldap_search_sW deferred error %#x\n", err);
+        ldap_ctx->search_hr = HRESULT_FROM_WIN32(map_ldap_error(err));
     }
-
     *res = ldap_ctx;
     return S_OK;
 }
@@ -1482,6 +1480,13 @@ static HRESULT WINAPI search_GetNextRow(IDirectorySearch *iface, ADS_SEARCH_HAND
 
     if (!ldap_ctx->entry)
     {
+        if (FAILED(ldap_ctx->search_hr))
+        {
+            if (ldap_ctx->search_hr == HRESULT_FROM_WIN32(ERROR_DS_NO_SUCH_OBJECT))
+                return S_ADS_NOMORE_ROWS;
+            return ldap_ctx->search_hr;
+        }
+
         ldap_ctx->count = ldap_count_entries(ldap->ld, ldap_ctx->res);
         ldap_ctx->pos = 0;
 


More information about the wine-devel mailing list