is_mine = (*ads)->is_mine;
#if HAVE_LDAP
- if ((*ads)->ld) {
- ldap_unbind((*ads)->ld);
- }
+ ads_disconnect(*ads);
#endif
SAFE_FREE((*ads)->server.realm);
SAFE_FREE((*ads)->server.workgroup);
return ads_sasl_bind(ads);
}
+/**
+ * Disconnect the LDAP server
+ * @param ads Pointer to an existing ADS_STRUCT
+ **/
+void ads_disconnect(ADS_STRUCT *ads)
+{
+ if (ads->ld) {
+ ldap_unbind(ads->ld);
+ ads->ld = NULL;
+ }
+}
+
/*
Duplicate a struct berval into talloc'ed memory
*/
DEBUG(3,("Reopening ads connection to realm '%s' after error %s\n",
ads->config.realm, ads_errstr(status)));
- if (ads->ld) {
- ldap_unbind(ads->ld);
- }
-
- ads->ld = NULL;
+ ads_disconnect(ads);
status = ads_connect(ads);
if (!ADS_ERR_OK(status)) {