tests/krb5: Add get_krbtgt_sname() method
[Samba.git] / source4 / torture / ldap / common.c
blobd16f611fa771c8e90ddb501840c560054414c80d
1 /*
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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "includes.h"
24 #include "libcli/ldap/ldap_client.h"
25 #include "torture/smbtorture.h"
26 #include "torture/ldap/proto.h"
28 NTSTATUS torture_ldap_bind(struct ldap_connection *conn, const char *userdn, const char *password)
30 NTSTATUS status;
32 status = ldap_bind_simple(conn, userdn, password);
33 if (!NT_STATUS_IS_OK(status)) {
34 printf("Failed to bind with provided credentials - %s\n",
35 nt_errstr(status));
38 return status;
41 NTSTATUS torture_ldap_bind_sasl(struct ldap_connection *conn,
42 struct cli_credentials *creds,
43 struct loadparm_context *lp_ctx)
45 NTSTATUS status;
47 status = ldap_bind_sasl(conn, creds, lp_ctx);
48 if (!NT_STATUS_IS_OK(status)) {
49 printf("Failed sasl bind with provided credentials - %s\n",
50 nt_errstr(status));
53 return status;
56 /* open a ldap connection to a server */
57 NTSTATUS torture_ldap_connection(struct torture_context *tctx,
58 struct ldap_connection **conn,
59 const char *url)
61 NTSTATUS status;
63 if (!url) {
64 printf("You must specify a url string\n");
65 return NT_STATUS_INVALID_PARAMETER;
68 *conn = ldap4_new_connection(tctx, tctx->lp_ctx, tctx->ev);
70 status = ldap_connect(*conn, url);
71 if (!NT_STATUS_IS_OK(status)) {
72 printf("Failed to connect to ldap server '%s' - %s\n",
73 url, nt_errstr(status));
76 return status;
79 /* close an ldap connection to a server */
80 NTSTATUS torture_ldap_close(struct ldap_connection *conn)
82 struct ldap_message *msg;
83 struct ldap_request *req;
84 NTSTATUS status;
86 printf("Closing the connection...\n");
88 msg = new_ldap_message(conn);
89 if (!msg) {
90 talloc_free(conn);
91 return NT_STATUS_NO_MEMORY;
94 printf(" Try a UnbindRequest\n");
96 msg->type = LDAP_TAG_UnbindRequest;
98 req = ldap_request_send(conn, msg);
99 if (!req) {
100 talloc_free(conn);
101 return NT_STATUS_NO_MEMORY;
104 status = ldap_request_wait(req);
105 if (!NT_STATUS_IS_OK(status)) {
106 printf("error in ldap unbind request - %s\n", nt_errstr(status));
107 talloc_free(conn);
108 return status;
111 talloc_free(conn);
112 return NT_STATUS_OK;
115 NTSTATUS torture_ldap_init(TALLOC_CTX *ctx)
117 struct torture_suite *suite = torture_suite_create(ctx, "ldap");
118 torture_suite_add_simple_test(suite, "bench-cldap", torture_bench_cldap);
119 torture_suite_add_simple_test(suite, "basic", torture_ldap_basic);
120 torture_suite_add_simple_test(suite, "sort", torture_ldap_sort);
121 torture_suite_add_simple_test(suite, "cldap", torture_cldap);
122 torture_suite_add_simple_test(suite, "netlogon-udp", torture_netlogon_udp);
123 torture_suite_add_simple_test(suite, "netlogon-tcp", torture_netlogon_tcp);
124 torture_suite_add_simple_test(suite, "schema", torture_ldap_schema);
125 torture_suite_add_simple_test(suite, "uptodatevector", torture_ldap_uptodatevector);
126 torture_suite_add_simple_test(suite, "nested-search", test_ldap_nested_search);
127 torture_suite_add_simple_test(
128 suite, "session-expiry", torture_ldap_session_expiry);
130 suite->description = talloc_strdup(suite, "LDAP and CLDAP tests");
132 torture_register_suite(ctx, suite);
134 return NT_STATUS_OK;