2 * WLDAP32 - LDAP support for Wine
4 * Copyright 2005 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
33 #include "winldap_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
39 /***********************************************************************
40 * ldap_close_extended_op (WLDAP32.@)
42 * Close an extended operation.
45 * ld [I] Pointer to an LDAP context.
46 * msgid [I] Message ID of the operation to be closed.
49 * Success: LDAP_SUCCESS
50 * Failure: An LDAP error code.
53 * Contrary to native, OpenLDAP does not require us to close
54 * extended operations, so this is a no-op.
56 ULONG CDECL ldap_close_extended_op( WLDAP32_LDAP *ld, ULONG msgid )
58 TRACE( "(%p, 0x%08x)\n", ld, msgid );
60 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
61 return WLDAP32_LDAP_SUCCESS;
64 /***********************************************************************
65 * ldap_extended_operationA (WLDAP32.@)
67 * See ldap_extended_operationW.
69 ULONG CDECL ldap_extended_operationA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
70 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
72 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
75 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
77 ret = WLDAP32_LDAP_NO_MEMORY;
79 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
80 clientctrls, message );
82 if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
85 oidW = strAtoW( oid );
89 serverctrlsW = controlarrayAtoW( serverctrls );
90 if (!serverctrlsW) goto exit;
93 clientctrlsW = controlarrayAtoW( clientctrls );
94 if (!clientctrlsW) goto exit;
97 ret = ldap_extended_operationW( ld, oidW, data, serverctrlsW, clientctrlsW, message );
101 controlarrayfreeW( serverctrlsW );
102 controlarrayfreeW( clientctrlsW );
108 /***********************************************************************
109 * ldap_extended_operationW (WLDAP32.@)
111 * Perform an extended operation (asynchronous mode).
114 * ld [I] Pointer to an LDAP context.
115 * oid [I] OID of the extended operation.
116 * data [I] Data needed by the operation.
117 * serverctrls [I] Array of LDAP server controls.
118 * clientctrls [I] Array of LDAP client controls.
119 * message [O] Message ID of the extended operation.
122 * Success: LDAP_SUCCESS
123 * Failure: An LDAP error code.
126 * The data parameter should be set to NULL if the operation
127 * requires no data. Call ldap_result with the message ID to
128 * get the result of the operation or ldap_abandon to cancel
129 * the operation. The serverctrls and clientctrls parameters
130 * are optional and should be set to NULL if not used. Call
131 * ldap_close_extended_op to close the operation.
133 ULONG CDECL ldap_extended_operationW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
134 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
136 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
139 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
141 ret = WLDAP32_LDAP_NO_MEMORY;
143 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
144 clientctrls, message );
146 if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
149 oidU = strWtoU( oid );
150 if (!oidU) goto exit;
153 serverctrlsU = controlarrayWtoU( serverctrls );
154 if (!serverctrlsU) goto exit;
157 clientctrlsU = controlarrayWtoU( clientctrls );
158 if (!clientctrlsU) goto exit;
161 ret = map_error( ldap_extended_operation( ld, oid ? oidU : "", (struct berval *)data,
162 serverctrlsU, clientctrlsU, (int *)message ));
166 controlarrayfreeU( serverctrlsU );
167 controlarrayfreeU( clientctrlsU );
173 /***********************************************************************
174 * ldap_extended_operation_sA (WLDAP32.@)
176 * See ldap_extended_operation_sW.
178 ULONG CDECL ldap_extended_operation_sA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
179 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, PCHAR *retoid,
180 struct WLDAP32_berval **retdata )
182 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
184 WCHAR *oidW = NULL, *retoidW = NULL;
185 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
187 ret = WLDAP32_LDAP_NO_MEMORY;
189 TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
190 clientctrls, retoid, retdata );
192 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
195 oidW = strAtoW( oid );
196 if (!oidW) goto exit;
199 serverctrlsW = controlarrayAtoW( serverctrls );
200 if (!serverctrlsW) goto exit;
203 clientctrlsW = controlarrayAtoW( clientctrls );
204 if (!clientctrlsW) goto exit;
207 ret = ldap_extended_operation_sW( ld, oidW, data, serverctrlsW, clientctrlsW,
210 if (retoid && retoidW) {
211 *retoid = strWtoA( retoidW );
212 if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
213 ldap_memfreeW( retoidW );
218 controlarrayfreeW( serverctrlsW );
219 controlarrayfreeW( clientctrlsW );
225 /***********************************************************************
226 * ldap_extended_operation_sW (WLDAP32.@)
228 * Perform an extended operation (synchronous mode).
231 * ld [I] Pointer to an LDAP context.
232 * oid [I] OID of the extended operation.
233 * data [I] Data needed by the operation.
234 * serverctrls [I] Array of LDAP server controls.
235 * clientctrls [I] Array of LDAP client controls.
236 * retoid [O] OID of the server response message.
237 * retdata [O] Data returned by the server.
240 * Success: LDAP_SUCCESS
241 * Failure: An LDAP error code.
244 * The data parameter should be set to NULL if the operation
245 * requires no data. The serverctrls, clientctrls, retoid and
246 * and retdata parameters are also optional. Set to NULL if not
247 * used. Free retoid and retdata after use with ldap_memfree.
249 ULONG CDECL ldap_extended_operation_sW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
250 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, PWCHAR *retoid,
251 struct WLDAP32_berval **retdata )
253 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
255 char *oidU = NULL, *retoidU = NULL;
256 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
258 ret = WLDAP32_LDAP_NO_MEMORY;
260 TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
261 clientctrls, retoid, retdata );
263 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
266 oidU = strWtoU( oid );
267 if (!oidU) goto exit;
270 serverctrlsU = controlarrayWtoU( serverctrls );
271 if (!serverctrlsU) goto exit;
274 clientctrlsU = controlarrayWtoU( clientctrls );
275 if (!clientctrlsU) goto exit;
278 ret = map_error( ldap_extended_operation_s( ld, oid ? oidU : "", (struct berval *)data, serverctrlsU,
279 clientctrlsU, &retoidU, (struct berval **)retdata ));
281 if (retoid && retoidU) {
282 *retoid = strUtoW( retoidU );
283 if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
284 ldap_memfree( retoidU );
289 controlarrayfreeU( serverctrlsU );
290 controlarrayfreeU( clientctrlsU );