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.
27 NTSTATUS torture_ldap_bind(struct ldap_connection *conn, const char *userdn, const char *password)
29 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
33 printf("We need a valid ldap_connection structure and be connected\n");
37 result = ldap_bind_simple(conn, userdn, password);
38 if (result != LDAP_SUCCESS) {
39 printf("Failed to bind with provided credentials\n");
40 /* FIXME: what abut actually implementing an ldap_connection_free() function ?
48 NTSTATUS torture_ldap_bind_sasl(struct ldap_connection *conn, const char *username, const char *domain, const char *password)
50 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
54 printf("We need a valid ldap_connection structure and be connected\n");
58 result = ldap_bind_sasl(conn, username, domain, password);
59 if (result != LDAP_SUCCESS) {
60 printf("Failed to bind with provided credentialsi and SASL mechanism\n");
61 /* FIXME: what abut actually implementing an ldap_connection_free() function ?
69 /* open a ldap connection to a server */
70 NTSTATUS torture_ldap_connection(struct ldap_connection **conn,
71 const char *url, const char *userdn, const char *password)
73 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
77 printf("You must specify a url string\n");
78 return NT_STATUS_INVALID_PARAMETER;
81 *conn = new_ldap_connection();
83 printf("Failed to initialize ldap_connection structure\n");
87 ret = ldap_setup_connection(*conn, url, userdn, password);
89 printf("Failed to connect with url [%s]\n", url);
90 /* FIXME: what abut actually implementing an ldap_connection_free() function ?
98 /* close an ldap connection to a server */
99 NTSTATUS torture_ldap_close(struct ldap_connection *conn)
101 /* FIXME: what about actually implementing ldap_close() ?
106 BOOL ldap_sasl_send_msg(struct ldap_connection *conn, struct ldap_message *msg,
107 const struct timeval *endtime)
115 struct asn1_data asn1;
118 msg->messageid = conn->next_msgid++;
120 if (!ldap_encode(msg, &request))
123 status = gensec_seal_packet(conn->gensec,
125 request.data, request.length,
126 request.data, request.length,
128 if (!NT_STATUS_IS_OK(status)) {
129 DEBUG(0,("gensec_seal_packet: %s\n",nt_errstr(status)));
133 len = 4 + creds.length + request.length;
134 pdu = data_blob_talloc(msg->mem_ctx, NULL, len);
135 RSIVAL(pdu.data, 0, len-4);
136 memcpy(pdu.data + 4, creds.data, creds.length);
137 memcpy(pdu.data + 4 + creds.length, request.data, request.length);
139 result = (write_data_until(conn->sock, pdu.data, pdu.length,
140 endtime) == pdu.length);
144 pdu = data_blob(NULL, 0x4000);
145 data_blob_clear(&pdu);
147 result = (read_data_until(conn->sock, pdu.data, 4, NULL) == 4);
151 len = RIVAL(pdu.data,0);
153 result = (read_data_until(conn->sock, pdu.data + 4, MIN(0x4000,len), NULL) == len);
159 creds = data_blob(pdu.data + 4 , gensec_sig_size(conn->gensec));
161 request = data_blob(pdu.data + (4 + creds.length), pdu.length - (4 + creds.length));
163 status = gensec_unseal_packet(conn->gensec,
165 request.data, request.length,
166 request.data, request.length,
168 if (!NT_STATUS_IS_OK(status)) {
169 DEBUG(0,("gensec_unseal_packet: %s\n",nt_errstr(status)));
173 mem_ctx = msg->mem_ctx;
175 msg->mem_ctx = mem_ctx;
177 asn1_load(&asn1, request);
178 if (!ldap_decode(&asn1, msg)) {