s3: add LDAP Alias Dereferencing support
[samba.git] / source3 / lib / smbldap.c
index f7ca1c167bdc82623bef3c05e548b93e75f040e2..4727c1593e57f84e79bdf8ab845ee977ba4ecb7c 100644 (file)
@@ -877,6 +877,7 @@ static int smbldap_open_connection (struct smbldap_state *ldap_state)
 {
        int rc = LDAP_SUCCESS;
        int version;
+       int deref;
        LDAP **ldap_struct = &ldap_state->ldap_struct;
 
        rc = smb_ldap_setup_conn(ldap_struct, ldap_state->uri);
@@ -902,6 +903,16 @@ static int smbldap_open_connection (struct smbldap_state *ldap_state)
                return rc;
        }
 
+       /* Set alias dereferencing method */
+       deref = lp_ldap_deref();
+       if (deref != -1) {
+               if (ldap_set_option (*ldap_struct, LDAP_OPT_DEREF, &deref) != LDAP_OPT_SUCCESS) {
+                       DEBUG(1,("smbldap_open_connection: Failed to set dereferencing method: %d\n", deref));
+               } else {
+                       DEBUG(5,("Set dereferencing method: %d\n", deref));
+               }
+       }
+
        DEBUG(2, ("smbldap_open_connection: connection opened\n"));
        return rc;
 }