2 Unix SMB/CIFS mplementation.
3 LDAP protocol helper functions for SAMBA
5 Copyright (C) Stefan Metzmacher 2004
6 Copyright (C) Simo Sorce 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 BOOL test_bind_simple(struct ldap_connection *conn, const char *userdn, const char *password)
31 status = torture_ldap_bind(conn, userdn, password);
32 if (!NT_STATUS_IS_OK(status)) {
39 BOOL test_bind_sasl(struct ldap_connection *conn, const char *username, const char *domain, const char *password)
44 printf("Testing sasl bind as user\n");
46 status = torture_ldap_bind_sasl(conn, username, domain, password);
47 if (!NT_STATUS_IS_OK(status)) {
54 BOOL test_multibind(struct ldap_connection *conn, const char *userdn, const char *password)
58 printf("Testing multiple binds on a single connnection as anonymous and user\n");
60 ret = test_bind_simple(conn, NULL, NULL);
62 printf("1st bind as anonymous failed\n");
66 ret = test_bind_simple(conn, userdn, password);
68 printf("2nd bind as authenticated user failed\n");
74 BOOL torture_ldap_basic(int dummy)
77 struct ldap_connection *conn;
80 const char *host = lp_parm_string(-1, "torture", "host");
81 const char *username = lp_parm_string(-1, "torture", "username");
82 const char *domain = lp_workgroup();
83 const char *password = lp_parm_string(-1, "torture", "password");
84 const char *userdn = lp_parm_string(-1, "torture", "ldap_userdn");
85 /*const char *basedn = lp_parm_string(-1, "torture", "ldap_basedn");*/
86 const char *secret = lp_parm_string(-1, "torture", "ldap_secret");
89 mem_ctx = talloc_init("torture_ldap_basic");
91 url = talloc_asprintf(mem_ctx, "ldap://%s/", host);
93 status = torture_ldap_connection(&conn, url, userdn, secret);
94 if (!NT_STATUS_IS_OK(status)) {
98 /* other basic tests here */
100 if (!test_multibind(conn, userdn, secret)) {
104 if (!test_bind_sasl(conn, username, domain, password)) {
108 /* no more test we are closing */
110 talloc_destroy(mem_ctx);
112 torture_ldap_close(conn);