1c2c66affSColin Finck /*
2c2c66affSColin Finck * WLDAP32 - LDAP support for Wine
3c2c66affSColin Finck *
4c2c66affSColin Finck * Copyright 2005 Hans Leidekker
5c2c66affSColin Finck *
6c2c66affSColin Finck * This library is free software; you can redistribute it and/or
7c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
8c2c66affSColin Finck * License as published by the Free Software Foundation; either
9c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
10c2c66affSColin Finck *
11c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
12c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14c2c66affSColin Finck * Lesser General Public License for more details.
15c2c66affSColin Finck *
16c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
17c2c66affSColin Finck * License along with this library; if not, write to the Free Software
18c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19c2c66affSColin Finck */
20c2c66affSColin Finck
21*e6368408SAmine Khaldi #include "config.h"
22*e6368408SAmine Khaldi #include "wine/port.h"
23*e6368408SAmine Khaldi
24*e6368408SAmine Khaldi #include <stdarg.h>
25*e6368408SAmine Khaldi #ifdef HAVE_LDAP_H
26*e6368408SAmine Khaldi #include <ldap.h>
27*e6368408SAmine Khaldi #endif
28*e6368408SAmine Khaldi
29*e6368408SAmine Khaldi #include "windef.h"
30*e6368408SAmine Khaldi #include "winbase.h"
31*e6368408SAmine Khaldi #include "winnls.h"
32*e6368408SAmine Khaldi
33c2c66affSColin Finck #include "winldap_private.h"
34*e6368408SAmine Khaldi #include "wldap32.h"
35*e6368408SAmine Khaldi #include "wine/debug.h"
36*e6368408SAmine Khaldi
37*e6368408SAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
38c2c66affSColin Finck
39c2c66affSColin Finck /***********************************************************************
40c2c66affSColin Finck * ldap_close_extended_op (WLDAP32.@)
41c2c66affSColin Finck *
42c2c66affSColin Finck * Close an extended operation.
43c2c66affSColin Finck *
44c2c66affSColin Finck * PARAMS
45c2c66affSColin Finck * ld [I] Pointer to an LDAP context.
46c2c66affSColin Finck * msgid [I] Message ID of the operation to be closed.
47c2c66affSColin Finck *
48c2c66affSColin Finck * RETURNS
49c2c66affSColin Finck * Success: LDAP_SUCCESS
50c2c66affSColin Finck * Failure: An LDAP error code.
51c2c66affSColin Finck *
52c2c66affSColin Finck * NOTES
53c2c66affSColin Finck * Contrary to native, OpenLDAP does not require us to close
54c2c66affSColin Finck * extended operations, so this is a no-op.
55c2c66affSColin Finck */
ldap_close_extended_op(WLDAP32_LDAP * ld,ULONG msgid)56c2c66affSColin Finck ULONG CDECL ldap_close_extended_op( WLDAP32_LDAP *ld, ULONG msgid )
57c2c66affSColin Finck {
58c2c66affSColin Finck TRACE( "(%p, 0x%08x)\n", ld, msgid );
59c2c66affSColin Finck
60c2c66affSColin Finck if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
61c2c66affSColin Finck return WLDAP32_LDAP_SUCCESS;
62c2c66affSColin Finck }
63c2c66affSColin Finck
64c2c66affSColin Finck /***********************************************************************
65c2c66affSColin Finck * ldap_extended_operationA (WLDAP32.@)
66c2c66affSColin Finck *
67c2c66affSColin Finck * See ldap_extended_operationW.
68c2c66affSColin Finck */
ldap_extended_operationA(WLDAP32_LDAP * ld,PCHAR oid,struct WLDAP32_berval * data,PLDAPControlA * serverctrls,PLDAPControlA * clientctrls,ULONG * message)69c2c66affSColin Finck ULONG CDECL ldap_extended_operationA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
70c2c66affSColin Finck PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
71c2c66affSColin Finck {
72c2c66affSColin Finck ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
73c2c66affSColin Finck #ifdef HAVE_LDAP
74c2c66affSColin Finck WCHAR *oidW = NULL;
75c2c66affSColin Finck LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
76c2c66affSColin Finck
77c2c66affSColin Finck ret = WLDAP32_LDAP_NO_MEMORY;
78c2c66affSColin Finck
79c2c66affSColin Finck TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
80c2c66affSColin Finck clientctrls, message );
81c2c66affSColin Finck
82c2c66affSColin Finck if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
83c2c66affSColin Finck
84c2c66affSColin Finck if (oid) {
85c2c66affSColin Finck oidW = strAtoW( oid );
86c2c66affSColin Finck if (!oidW) goto exit;
87c2c66affSColin Finck }
88c2c66affSColin Finck if (serverctrls) {
89c2c66affSColin Finck serverctrlsW = controlarrayAtoW( serverctrls );
90c2c66affSColin Finck if (!serverctrlsW) goto exit;
91c2c66affSColin Finck }
92c2c66affSColin Finck if (clientctrls) {
93c2c66affSColin Finck clientctrlsW = controlarrayAtoW( clientctrls );
94c2c66affSColin Finck if (!clientctrlsW) goto exit;
95c2c66affSColin Finck }
96c2c66affSColin Finck
97c2c66affSColin Finck ret = ldap_extended_operationW( ld, oidW, data, serverctrlsW, clientctrlsW, message );
98c2c66affSColin Finck
99c2c66affSColin Finck exit:
100c2c66affSColin Finck strfreeW( oidW );
101c2c66affSColin Finck controlarrayfreeW( serverctrlsW );
102c2c66affSColin Finck controlarrayfreeW( clientctrlsW );
103c2c66affSColin Finck
104c2c66affSColin Finck #endif
105c2c66affSColin Finck return ret;
106c2c66affSColin Finck }
107c2c66affSColin Finck
108c2c66affSColin Finck /***********************************************************************
109c2c66affSColin Finck * ldap_extended_operationW (WLDAP32.@)
110c2c66affSColin Finck *
111c2c66affSColin Finck * Perform an extended operation (asynchronous mode).
112c2c66affSColin Finck *
113c2c66affSColin Finck * PARAMS
114c2c66affSColin Finck * ld [I] Pointer to an LDAP context.
115c2c66affSColin Finck * oid [I] OID of the extended operation.
116c2c66affSColin Finck * data [I] Data needed by the operation.
117c2c66affSColin Finck * serverctrls [I] Array of LDAP server controls.
118c2c66affSColin Finck * clientctrls [I] Array of LDAP client controls.
119c2c66affSColin Finck * message [O] Message ID of the extended operation.
120c2c66affSColin Finck *
121c2c66affSColin Finck * RETURNS
122c2c66affSColin Finck * Success: LDAP_SUCCESS
123c2c66affSColin Finck * Failure: An LDAP error code.
124c2c66affSColin Finck *
125c2c66affSColin Finck * NOTES
126c2c66affSColin Finck * The data parameter should be set to NULL if the operation
127c2c66affSColin Finck * requires no data. Call ldap_result with the message ID to
128c2c66affSColin Finck * get the result of the operation or ldap_abandon to cancel
129c2c66affSColin Finck * the operation. The serverctrls and clientctrls parameters
130c2c66affSColin Finck * are optional and should be set to NULL if not used. Call
131c2c66affSColin Finck * ldap_close_extended_op to close the operation.
132c2c66affSColin Finck */
ldap_extended_operationW(WLDAP32_LDAP * ld,PWCHAR oid,struct WLDAP32_berval * data,PLDAPControlW * serverctrls,PLDAPControlW * clientctrls,ULONG * message)133c2c66affSColin Finck ULONG CDECL ldap_extended_operationW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
134c2c66affSColin Finck PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
135c2c66affSColin Finck {
136c2c66affSColin Finck ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
137c2c66affSColin Finck #ifdef HAVE_LDAP
138c2c66affSColin Finck char *oidU = NULL;
139c2c66affSColin Finck LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
140c2c66affSColin Finck
141c2c66affSColin Finck ret = WLDAP32_LDAP_NO_MEMORY;
142c2c66affSColin Finck
143c2c66affSColin Finck TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
144c2c66affSColin Finck clientctrls, message );
145c2c66affSColin Finck
146c2c66affSColin Finck if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
147c2c66affSColin Finck
148c2c66affSColin Finck if (oid) {
149c2c66affSColin Finck oidU = strWtoU( oid );
150c2c66affSColin Finck if (!oidU) goto exit;
151c2c66affSColin Finck }
152c2c66affSColin Finck if (serverctrls) {
153c2c66affSColin Finck serverctrlsU = controlarrayWtoU( serverctrls );
154c2c66affSColin Finck if (!serverctrlsU) goto exit;
155c2c66affSColin Finck }
156c2c66affSColin Finck if (clientctrls) {
157c2c66affSColin Finck clientctrlsU = controlarrayWtoU( clientctrls );
158c2c66affSColin Finck if (!clientctrlsU) goto exit;
159c2c66affSColin Finck }
160c2c66affSColin Finck
161c2c66affSColin Finck ret = map_error( ldap_extended_operation( ld, oid ? oidU : "", (struct berval *)data,
162c2c66affSColin Finck serverctrlsU, clientctrlsU, (int *)message ));
163c2c66affSColin Finck
164c2c66affSColin Finck exit:
165c2c66affSColin Finck strfreeU( oidU );
166c2c66affSColin Finck controlarrayfreeU( serverctrlsU );
167c2c66affSColin Finck controlarrayfreeU( clientctrlsU );
168c2c66affSColin Finck
169c2c66affSColin Finck #endif
170c2c66affSColin Finck return ret;
171c2c66affSColin Finck }
172c2c66affSColin Finck
173c2c66affSColin Finck /***********************************************************************
174c2c66affSColin Finck * ldap_extended_operation_sA (WLDAP32.@)
175c2c66affSColin Finck *
176c2c66affSColin Finck * See ldap_extended_operation_sW.
177c2c66affSColin Finck */
ldap_extended_operation_sA(WLDAP32_LDAP * ld,PCHAR oid,struct WLDAP32_berval * data,PLDAPControlA * serverctrls,PLDAPControlA * clientctrls,PCHAR * retoid,struct WLDAP32_berval ** retdata)178c2c66affSColin Finck ULONG CDECL ldap_extended_operation_sA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
179c2c66affSColin Finck PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, PCHAR *retoid,
180c2c66affSColin Finck struct WLDAP32_berval **retdata )
181c2c66affSColin Finck {
182c2c66affSColin Finck ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
183c2c66affSColin Finck #ifdef HAVE_LDAP
184c2c66affSColin Finck WCHAR *oidW = NULL, *retoidW = NULL;
185c2c66affSColin Finck LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
186c2c66affSColin Finck
187c2c66affSColin Finck ret = WLDAP32_LDAP_NO_MEMORY;
188c2c66affSColin Finck
189c2c66affSColin Finck TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
190c2c66affSColin Finck clientctrls, retoid, retdata );
191c2c66affSColin Finck
192c2c66affSColin Finck if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
193c2c66affSColin Finck
194c2c66affSColin Finck if (oid) {
195c2c66affSColin Finck oidW = strAtoW( oid );
196c2c66affSColin Finck if (!oidW) goto exit;
197c2c66affSColin Finck }
198c2c66affSColin Finck if (serverctrls) {
199c2c66affSColin Finck serverctrlsW = controlarrayAtoW( serverctrls );
200c2c66affSColin Finck if (!serverctrlsW) goto exit;
201c2c66affSColin Finck }
202c2c66affSColin Finck if (clientctrls) {
203c2c66affSColin Finck clientctrlsW = controlarrayAtoW( clientctrls );
204c2c66affSColin Finck if (!clientctrlsW) goto exit;
205c2c66affSColin Finck }
206c2c66affSColin Finck
207c2c66affSColin Finck ret = ldap_extended_operation_sW( ld, oidW, data, serverctrlsW, clientctrlsW,
208c2c66affSColin Finck &retoidW, retdata );
209c2c66affSColin Finck
210c2c66affSColin Finck if (retoid && retoidW) {
211c2c66affSColin Finck *retoid = strWtoA( retoidW );
212c2c66affSColin Finck if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
213c2c66affSColin Finck ldap_memfreeW( retoidW );
214c2c66affSColin Finck }
215c2c66affSColin Finck
216c2c66affSColin Finck exit:
217c2c66affSColin Finck strfreeW( oidW );
218c2c66affSColin Finck controlarrayfreeW( serverctrlsW );
219c2c66affSColin Finck controlarrayfreeW( clientctrlsW );
220c2c66affSColin Finck
221c2c66affSColin Finck #endif
222c2c66affSColin Finck return ret;
223c2c66affSColin Finck }
224c2c66affSColin Finck
225c2c66affSColin Finck /***********************************************************************
226c2c66affSColin Finck * ldap_extended_operation_sW (WLDAP32.@)
227c2c66affSColin Finck *
228c2c66affSColin Finck * Perform an extended operation (synchronous mode).
229c2c66affSColin Finck *
230c2c66affSColin Finck * PARAMS
231c2c66affSColin Finck * ld [I] Pointer to an LDAP context.
232c2c66affSColin Finck * oid [I] OID of the extended operation.
233c2c66affSColin Finck * data [I] Data needed by the operation.
234c2c66affSColin Finck * serverctrls [I] Array of LDAP server controls.
235c2c66affSColin Finck * clientctrls [I] Array of LDAP client controls.
236c2c66affSColin Finck * retoid [O] OID of the server response message.
237c2c66affSColin Finck * retdata [O] Data returned by the server.
238c2c66affSColin Finck *
239c2c66affSColin Finck * RETURNS
240c2c66affSColin Finck * Success: LDAP_SUCCESS
241c2c66affSColin Finck * Failure: An LDAP error code.
242c2c66affSColin Finck *
243c2c66affSColin Finck * NOTES
244c2c66affSColin Finck * The data parameter should be set to NULL if the operation
245c2c66affSColin Finck * requires no data. The serverctrls, clientctrls, retoid and
246c2c66affSColin Finck * and retdata parameters are also optional. Set to NULL if not
247c2c66affSColin Finck * used. Free retoid and retdata after use with ldap_memfree.
248c2c66affSColin Finck */
ldap_extended_operation_sW(WLDAP32_LDAP * ld,PWCHAR oid,struct WLDAP32_berval * data,PLDAPControlW * serverctrls,PLDAPControlW * clientctrls,PWCHAR * retoid,struct WLDAP32_berval ** retdata)249c2c66affSColin Finck ULONG CDECL ldap_extended_operation_sW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
250c2c66affSColin Finck PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, PWCHAR *retoid,
251c2c66affSColin Finck struct WLDAP32_berval **retdata )
252c2c66affSColin Finck {
253c2c66affSColin Finck ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
254c2c66affSColin Finck #ifdef HAVE_LDAP
255c2c66affSColin Finck char *oidU = NULL, *retoidU = NULL;
256c2c66affSColin Finck LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
257c2c66affSColin Finck
258c2c66affSColin Finck ret = WLDAP32_LDAP_NO_MEMORY;
259c2c66affSColin Finck
260c2c66affSColin Finck TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
261c2c66affSColin Finck clientctrls, retoid, retdata );
262c2c66affSColin Finck
263c2c66affSColin Finck if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
264c2c66affSColin Finck
265c2c66affSColin Finck if (oid) {
266c2c66affSColin Finck oidU = strWtoU( oid );
267c2c66affSColin Finck if (!oidU) goto exit;
268c2c66affSColin Finck }
269c2c66affSColin Finck if (serverctrls) {
270c2c66affSColin Finck serverctrlsU = controlarrayWtoU( serverctrls );
271c2c66affSColin Finck if (!serverctrlsU) goto exit;
272c2c66affSColin Finck }
273c2c66affSColin Finck if (clientctrls) {
274c2c66affSColin Finck clientctrlsU = controlarrayWtoU( clientctrls );
275c2c66affSColin Finck if (!clientctrlsU) goto exit;
276c2c66affSColin Finck }
277c2c66affSColin Finck
278c2c66affSColin Finck ret = map_error( ldap_extended_operation_s( ld, oid ? oidU : "", (struct berval *)data, serverctrlsU,
279c2c66affSColin Finck clientctrlsU, &retoidU, (struct berval **)retdata ));
280c2c66affSColin Finck
281c2c66affSColin Finck if (retoid && retoidU) {
282c2c66affSColin Finck *retoid = strUtoW( retoidU );
283c2c66affSColin Finck if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
284c2c66affSColin Finck ldap_memfree( retoidU );
285c2c66affSColin Finck }
286c2c66affSColin Finck
287c2c66affSColin Finck exit:
288c2c66affSColin Finck strfreeU( oidU );
289c2c66affSColin Finck controlarrayfreeU( serverctrlsU );
290c2c66affSColin Finck controlarrayfreeU( clientctrlsU );
291c2c66affSColin Finck
292c2c66affSColin Finck #endif
293c2c66affSColin Finck return ret;
294c2c66affSColin Finck }
295