summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2004-08-12 22:23:57 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:57:57 -0500
commit16c52f7a0786a2583c32fb44ee12ff4f1863f355 (patch)
treec7c43588fac4c0f72ed8d3a77369eeaf3d0cf302 /source4
parent2a574e22453161b8aa9578a6b512e05e5f7720a3 (diff)
downloadsamba-16c52f7a0786a2583c32fb44ee12ff4f1863f355.tar.gz
samba-16c52f7a0786a2583c32fb44ee12ff4f1863f355.tar.bz2
samba-16c52f7a0786a2583c32fb44ee12ff4f1863f355.zip
r1792: split ldap_setup_connection() and provide an ldap_bind_simple() function
(This used to be commit d9f8f97c9eaa8078f411adf0a8db607365082197)
Diffstat (limited to 'source4')
-rw-r--r--source4/libcli/ldap/ldap.c64
1 files changed, 42 insertions, 22 deletions
diff --git a/source4/libcli/ldap/ldap.c b/source4/libcli/ldap/ldap.c
index 5afd595293..d7c24e8c03 100644
--- a/source4/libcli/ldap/ldap.c
+++ b/source4/libcli/ldap/ldap.c
@@ -1739,42 +1739,62 @@ struct ldap_message *ldap_transaction(struct ldap_connection *conn,
return ldap_receive(conn, request->messageid, NULL);
}
-BOOL ldap_setup_connection(struct ldap_connection *conn,
- const char *url)
+struct ldap_message *ldap_bind_simple(struct ldap_connection *conn, const char *userdn, const char *password)
{
- struct ldap_message *msg = new_ldap_message();
struct ldap_message *response;
- BOOL result;
+ struct ldap_message *msg;
+ const char *dn, *pw;
- if (msg == NULL)
+ if (conn == NULL || msg == NULL)
return False;
- if (!ldap_connect(conn, url)) {
- destroy_ldap_message(msg);
- return False;
- }
-
- msg->messageid = conn->next_msgid++;
- msg->type = LDAP_TAG_BindRequest;
- msg->r.BindRequest.version = 3;
- if (conn->auth_dn) {
- msg->r.BindRequest.dn = conn->auth_dn;
+ if (userdn) {
+ dn = userdn;
} else {
- msg->r.BindRequest.dn = "";
+ if (conn->auth_dn) {
+ dn = conn->auth_dn;
+ } else {
+ dn = "";
+ }
}
- msg->r.BindRequest.mechanism = LDAP_AUTH_MECH_SIMPLE;
- if (conn->simple_pw) {
- msg->r.BindRequest.creds.password = conn->simple_pw;
+
+ if (password) {
+ pw = password;
} else {
- msg->r.BindRequest.creds.password = "";
+ if (conn->simple_pw) {
+ pw = conn->simple_pw;
+ } else {
+ pw = "";
+ }
}
- if ((response = ldap_transaction(conn, msg)) == NULL)
+ msg = new_ldap_simple_bind_msg(dn, pw);
+ if (!msg)
return False;
- result = (response->r.BindResponse.response.resultcode == 0);
+ response = ldap_transaction(conn, msg);
destroy_ldap_message(msg);
+ return response;
+}
+
+BOOL ldap_setup_connection(struct ldap_connection *conn,
+ const char *url, const char *userdn, const char *password)
+{
+ struct ldap_message *response;
+ BOOL result;
+
+ if (!ldap_connect(conn, url)) {
+ return False;
+ }
+
+ response = ldap_bind_simple(conn, userdn, password);
+ if (response == NULL) {
+ result = False;
+ } else {
+ result = (response->r.BindResponse.response.resultcode == 0);
+ }
+
destroy_ldap_message(response);
return result;
}