s4:LDAP server - Enable support for returning referrals through it
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sun, 21 Feb 2010 10:56:12 +0000 (11:56 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 24 Feb 2010 21:16:54 +0000 (08:16 +1100)
This is needed for my work regarding the referrals when the domain scope control
isn't specified.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
source4/ldap_server/ldap_backend.c

index 689fd31141466201d63405e976d009b164cee0db..1c5a2b2a042e73f3464295d6bf04f6098585f162 100644 (file)
@@ -475,6 +475,28 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
 queue_reply:
                        ldapsrv_queue_reply(call, ent_r);
                }
+
+               /* Send back referrals if they do exist (search operations) */
+               if (res->refs != NULL) {
+                       char **ref;
+                       struct ldap_SearchResRef *ent_ref;
+
+                       for (ref = res->refs; *ref != NULL; ++ref) {
+                               ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultReference);
+                               NT_STATUS_HAVE_NO_MEMORY(ent_r);
+
+                               /* Better to have the whole referrals kept here,
+                                * than to find someone further up didn't put
+                                * a value in the right spot in the talloc tree
+                                */
+                               talloc_steal(ent_r, *ref);
+
+                               ent_ref = &ent_r->msg->r.SearchResultReference;
+                               ent_ref->referral = *ref;
+
+                               ldapsrv_queue_reply(call, ent_r);
+                       }
+               }
        }
 
 reply: