summaryrefslogtreecommitdiff
path: root/source4/libcli/ldap/ldap.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/libcli/ldap/ldap.c')
-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;
}