winspool.drv: Update Portuguese (Brazilian) translation.
[wine/hacks.git] / dlls / wldap32 / extended.c
blob821449f45ebbb12b0c5558612bf6fc908dd61b3d
1 /*
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
21 #include "config.h"
23 #include "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #endif
36 #include "winldap_private.h"
37 #include "wldap32.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
41 /***********************************************************************
42 * ldap_close_extended_op (WLDAP32.@)
44 * Close an extended operation.
46 * PARAMS
47 * ld [I] Pointer to an LDAP context.
48 * msgid [I] Message ID of the operation to be closed.
50 * RETURNS
51 * Success: LDAP_SUCCESS
52 * Failure: An LDAP error code.
54 * NOTES
55 * Contrary to native, OpenLDAP does not require us to close
56 * extended operations, so this is a no-op.
58 ULONG CDECL ldap_close_extended_op( WLDAP32_LDAP *ld, ULONG msgid )
60 TRACE( "(%p, 0x%08x)\n", ld, msgid );
62 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
63 return WLDAP32_LDAP_SUCCESS;
66 /***********************************************************************
67 * ldap_extended_operationA (WLDAP32.@)
69 * See ldap_extended_operationW.
71 ULONG CDECL ldap_extended_operationA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
72 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
74 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
75 #ifdef HAVE_LDAP
76 WCHAR *oidW = NULL;
77 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
79 ret = WLDAP32_LDAP_NO_MEMORY;
81 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
82 clientctrls, message );
84 if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
86 if (oid) {
87 oidW = strAtoW( oid );
88 if (!oidW) goto exit;
90 if (serverctrls) {
91 serverctrlsW = controlarrayAtoW( serverctrls );
92 if (!serverctrlsW) goto exit;
94 if (clientctrls) {
95 clientctrlsW = controlarrayAtoW( clientctrls );
96 if (!clientctrlsW) goto exit;
99 ret = ldap_extended_operationW( ld, oidW, data, serverctrlsW, clientctrlsW, message );
101 exit:
102 strfreeW( oidW );
103 controlarrayfreeW( serverctrlsW );
104 controlarrayfreeW( clientctrlsW );
106 #endif
107 return ret;
110 /***********************************************************************
111 * ldap_extended_operationW (WLDAP32.@)
113 * Perform an extended operation (asynchronous mode).
115 * PARAMS
116 * ld [I] Pointer to an LDAP context.
117 * oid [I] OID of the extended operation.
118 * data [I] Data needed by the operation.
119 * serverctrls [I] Array of LDAP server controls.
120 * clientctrls [I] Array of LDAP client controls.
121 * message [O] Message ID of the extended operation.
123 * RETURNS
124 * Success: LDAP_SUCCESS
125 * Failure: An LDAP error code.
127 * NOTES
128 * The data parameter should be set to NULL if the operation
129 * requires no data. Call ldap_result with the message ID to
130 * get the result of the operation or ldap_abandon to cancel
131 * the operation. The serverctrls and clientctrls parameters
132 * are optional and should be set to NULL if not used. Call
133 * ldap_close_extended_op to close the operation.
135 ULONG CDECL ldap_extended_operationW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
136 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
138 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
139 #ifdef HAVE_LDAP
140 char *oidU = NULL;
141 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
143 ret = WLDAP32_LDAP_NO_MEMORY;
145 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
146 clientctrls, message );
148 if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
150 if (oid) {
151 oidU = strWtoU( oid );
152 if (!oidU) goto exit;
154 if (serverctrls) {
155 serverctrlsU = controlarrayWtoU( serverctrls );
156 if (!serverctrlsU) goto exit;
158 if (clientctrls) {
159 clientctrlsU = controlarrayWtoU( clientctrls );
160 if (!clientctrlsU) goto exit;
163 ret = map_error( ldap_extended_operation( ld, oid ? oidU : "", (struct berval *)data,
164 serverctrlsU, clientctrlsU, (int *)message ));
166 exit:
167 strfreeU( oidU );
168 controlarrayfreeU( serverctrlsU );
169 controlarrayfreeU( clientctrlsU );
171 #endif
172 return ret;
175 /***********************************************************************
176 * ldap_extended_operation_sA (WLDAP32.@)
178 * See ldap_extended_operation_sW.
180 ULONG CDECL ldap_extended_operation_sA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
181 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, PCHAR *retoid,
182 struct WLDAP32_berval **retdata )
184 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
185 #ifdef HAVE_LDAP
186 WCHAR *oidW = NULL, *retoidW = NULL;
187 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
189 ret = WLDAP32_LDAP_NO_MEMORY;
191 TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
192 clientctrls, retoid, retdata );
194 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
196 if (oid) {
197 oidW = strAtoW( oid );
198 if (!oidW) goto exit;
200 if (serverctrls) {
201 serverctrlsW = controlarrayAtoW( serverctrls );
202 if (!serverctrlsW) goto exit;
204 if (clientctrls) {
205 clientctrlsW = controlarrayAtoW( clientctrls );
206 if (!clientctrlsW) goto exit;
209 ret = ldap_extended_operation_sW( ld, oidW, data, serverctrlsW, clientctrlsW,
210 &retoidW, retdata );
212 if (retoid && retoidW) {
213 *retoid = strWtoA( retoidW );
214 if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
215 ldap_memfreeW( retoidW );
218 exit:
219 strfreeW( oidW );
220 controlarrayfreeW( serverctrlsW );
221 controlarrayfreeW( clientctrlsW );
223 #endif
224 return ret;
227 /***********************************************************************
228 * ldap_extended_operation_sW (WLDAP32.@)
230 * Perform an extended operation (synchronous mode).
232 * PARAMS
233 * ld [I] Pointer to an LDAP context.
234 * oid [I] OID of the extended operation.
235 * data [I] Data needed by the operation.
236 * serverctrls [I] Array of LDAP server controls.
237 * clientctrls [I] Array of LDAP client controls.
238 * retoid [O] OID of the server response message.
239 * retdata [O] Data returned by the server.
241 * RETURNS
242 * Success: LDAP_SUCCESS
243 * Failure: An LDAP error code.
245 * NOTES
246 * The data parameter should be set to NULL if the operation
247 * requires no data. The serverctrls, clientctrls, retoid and
248 * and retdata parameters are also optional. Set to NULL if not
249 * used. Free retoid and retdata after use with ldap_memfree.
251 ULONG CDECL ldap_extended_operation_sW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
252 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, PWCHAR *retoid,
253 struct WLDAP32_berval **retdata )
255 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
256 #ifdef HAVE_LDAP
257 char *oidU = NULL, *retoidU = NULL;
258 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
260 ret = WLDAP32_LDAP_NO_MEMORY;
262 TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
263 clientctrls, retoid, retdata );
265 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
267 if (oid) {
268 oidU = strWtoU( oid );
269 if (!oidU) goto exit;
271 if (serverctrls) {
272 serverctrlsU = controlarrayWtoU( serverctrls );
273 if (!serverctrlsU) goto exit;
275 if (clientctrls) {
276 clientctrlsU = controlarrayWtoU( clientctrls );
277 if (!clientctrlsU) goto exit;
280 ret = map_error( ldap_extended_operation_s( ld, oid ? oidU : "", (struct berval *)data, serverctrlsU,
281 clientctrlsU, &retoidU, (struct berval **)retdata ));
283 if (retoid && retoidU) {
284 *retoid = strUtoW( retoidU );
285 if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
286 ldap_memfree( retoidU );
289 exit:
290 strfreeU( oidU );
291 controlarrayfreeU( serverctrlsU );
292 controlarrayfreeU( clientctrlsU );
294 #endif
295 return ret;