From 9dc1e17c353d61a82a5500d1fad787dda8c766c3 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 12 Aug 2004 22:25:01 +0000 Subject: r1793: try to bind multiple times as anonimous and user added -D parameter to torture to be able to specify: - user dn - base dn - user secret (This used to be commit 0eaec28f5c511a28764a1d350c2eaaf37272eb62) --- source4/torture/ldap/basic.c | 31 +++++++++++++++++++++++++++++-- source4/torture/ldap/common.c | 29 +++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 6 deletions(-) (limited to 'source4/torture/ldap') diff --git a/source4/torture/ldap/basic.c b/source4/torture/ldap/basic.c index 2227d70421..a9ab023d9d 100644 --- a/source4/torture/ldap/basic.c +++ b/source4/torture/ldap/basic.c @@ -1,6 +1,28 @@ #include "includes.h" +BOOL test_multibind(struct ldap_connection *conn, TALLOC_CTX *mem_ctx, const char *userdn, const char *password) +{ + NTSTATUS status; + BOOL ret = True; + + printf("\nTesting multiple binds on a single connnection as anonymous and user\n"); + + status = torture_ldap_bind(conn, userdn, password); + if (!NT_STATUS_IS_OK(status)) { + printf("1st bind as user over an anonymous bind failed\n"); + return False; + } + + status = torture_ldap_bind(conn, NULL, NULL); + if (!NT_STATUS_IS_OK(status)) { + printf("2nd bind as anonymous over an authenticated bind failed\n"); + return False; + } + + return ret; +} + BOOL torture_ldap_basic(int dummy) { NTSTATUS status; @@ -8,20 +30,25 @@ BOOL torture_ldap_basic(int dummy) TALLOC_CTX *mem_ctx; BOOL ret = True; const char *host = lp_parm_string(-1, "torture", "host"); + const char *userdn = lp_parm_string(-1, "torture", "ldap_userdn"); + const char *basedn = lp_parm_string(-1, "torture", "ldap_basedn"); + const char *secret = lp_parm_string(-1, "torture", "ldap_secret"); char *url; mem_ctx = talloc_init("torture_ldap_basic"); url = talloc_asprintf(mem_ctx, "ldap://%s/", host); - status = torture_ldap_connection(&conn, url); + status = torture_ldap_connection(&conn, url, NULL, NULL); if (!NT_STATUS_IS_OK(status)) { return False; } /* other basic tests here */ - /* --- nothing yet :-) --- */ + if (!test_multibind(conn, mem_ctx, userdn, secret)) { + ret = False; + } /* no more test we are closing */ diff --git a/source4/torture/ldap/common.c b/source4/torture/ldap/common.c index 7d8dcbe4da..7a3d8e48be 100644 --- a/source4/torture/ldap/common.c +++ b/source4/torture/ldap/common.c @@ -1,9 +1,30 @@ #include "includes.h" +NTSTATUS torture_ldap_bind(struct ldap_connection *conn, const char *userdn, const char *password) +{ + NTSTATUS status = NT_STATUS_UNSUCCESSFUL; + struct ldap_message *response; + + if (!conn) { + printf("We need a valid ldap_connection structure and be connected\n"); + return status; + } + + response = ldap_bind_simple(conn, userdn, password); + if (!response || (response->r.BindResponse.response.resultcode != 0)) { + printf("Failed to bind with provided credentials\n"); + /* FIXME: what abut actually implementing an ldap_connection_free() function ? + :-) sss */ + destroy_ldap_message(response); + return status; + } + + return NT_STATUS_OK; +} + /* open a ldap connection to a server */ -/* TODO: Add support to pass over credentials */ NTSTATUS torture_ldap_connection(struct ldap_connection **conn, - const char *url) + const char *url, const char *userdn, const char *password) { NTSTATUS status = NT_STATUS_UNSUCCESSFUL; BOOL ret; @@ -19,9 +40,9 @@ NTSTATUS torture_ldap_connection(struct ldap_connection **conn, return status; } - ret = ldap_setup_connection(*conn, url); + ret = ldap_setup_connection(*conn, url, userdn, password); if (!ret) { - printf("Failed to connect with url [%s]", url); + printf("Failed to connect with url [%s]\n", url); /* FIXME: what abut actually implementing an ldap_connection_free() function ? :-) sss */ return status; -- cgit