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