From 16c52f7a0786a2583c32fb44ee12ff4f1863f355 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 12 Aug 2004 22:23:57 +0000 Subject: r1792: split ldap_setup_connection() and provide an ldap_bind_simple() function (This used to be commit d9f8f97c9eaa8078f411adf0a8db607365082197) --- source4/libcli/ldap/ldap.c | 64 ++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 22 deletions(-) (limited to 'source4') 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; } -- cgit