summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGregor Beck <gbeck@sernet.de>2011-06-21 08:16:56 +0200
committerStefan Metzmacher <metze@samba.org>2011-07-01 12:37:50 +0200
commit1765833481ca441429bdf8dd167b729a24edbfa2 (patch)
tree7e4534fca27dc23ddd95627c6e2f5f1948ebe5a3 /source3
parent6aff8b19fcdbf694cc8dbd388f87e55cce475939 (diff)
downloadsamba-1765833481ca441429bdf8dd167b729a24edbfa2.tar.gz
samba-1765833481ca441429bdf8dd167b729a24edbfa2.tar.bz2
samba-1765833481ca441429bdf8dd167b729a24edbfa2.zip
s3:smbldap: make smbldap_connect_system self contained
Signed-off-by: Stefan Metzmacher <metze@samba.org> Autobuild-User: Stefan Metzmacher <metze@samba.org> Autobuild-Date: Fri Jul 1 12:37:50 CEST 2011 on sn-devel-104
Diffstat (limited to 'source3')
-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 1fbefbf2d5..5c99e4b6e8 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -1166,8 +1166,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;
@@ -1178,7 +1179,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);
@@ -1224,7 +1226,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;
@@ -1239,6 +1241,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;
}
@@ -1293,9 +1300,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;
}