summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregor Beck <gbeck@sernet.de>2011-06-21 08:16:56 +0200
committerKarolin Seeger <kseeger@samba.org>2011-07-26 21:52:02 +0200
commit00836e62ae58ca687b2ad6ed509b9ca4bf1009c4 (patch)
tree16ca4479feb3d0862782ebba5ba08a45f78bf983
parent104a0e419d3f9c23e688e1b7d75e5d5fa9a55695 (diff)
downloadsamba-00836e62ae58ca687b2ad6ed509b9ca4bf1009c4.tar.gz
samba-00836e62ae58ca687b2ad6ed509b9ca4bf1009c4.tar.xz
samba-00836e62ae58ca687b2ad6ed509b9ca4bf1009c4.zip
s3:smbldap: make smbldap_connect_system self contained
The last patches address bug #8253 (winbindd panics if verify_idpool() fails). (cherry picked from commit c6d5c7cc830d59e7b6f0fa5a38eae27b0f1aa4bb)
-rw-r--r--source3/lib/smbldap.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 76bf7e02218..1d507fb6963 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -1165,8 +1165,9 @@ static int rebindproc_connect (LDAP * ld, LDAP_CONST char *url, int request,
/*******************************************************************
connect to the ldap server under system privilege.
******************************************************************/
-static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * ldap_struct)
+static int smbldap_connect_system(struct smbldap_state *ldap_state)
{
+ LDAP *ldap_struct = ldap_state->ldap_struct;
int rc;
int version;
@@ -1177,7 +1178,8 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * ldap_
/* get the default dn and password only if they are not set already */
if (!fetch_ldap_pw(&bind_dn, &bind_secret)) {
DEBUG(0, ("ldap_connect_system: Failed to retrieve password from secrets.tdb\n"));
- return LDAP_INVALID_CREDENTIALS;
+ rc = LDAP_INVALID_CREDENTIALS;
+ goto done;
}
smbldap_set_creds(ldap_state, false, bind_dn, bind_secret);
SAFE_FREE(bind_dn);
@@ -1223,7 +1225,7 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * ldap_
ld_error ? ld_error : "(unknown)"));
SAFE_FREE(ld_error);
ldap_state->num_failures++;
- return rc;
+ goto done;
}
ldap_state->num_failures = 0;
@@ -1238,6 +1240,11 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * ldap_
DEBUG(3, ("ldap_connect_system: successful connection to the LDAP server\n"));
DEBUGADD(10, ("ldap_connect_system: LDAP server %s support paged results\n",
ldap_state->paged_results ? "does" : "does not"));
+done:
+ if (rc != 0) {
+ ldap_unbind(ldap_struct);
+ ldap_state->ldap_struct = NULL;
+ }
return rc;
}
@@ -1292,9 +1299,7 @@ static int smbldap_open(struct smbldap_state *ldap_state)
return rc;
}
- if ((rc = smbldap_connect_system(ldap_state, ldap_state->ldap_struct))) {
- ldap_unbind(ldap_state->ldap_struct);
- ldap_state->ldap_struct = NULL;
+ if ((rc = smbldap_connect_system(ldap_state))) {
return rc;
}