msvcrt: Use the msvcrt version of printf everywhere.
[wine] / dlls / wldap32 / modify.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 static LDAPMod *nullmods[] = { NULL };
35 #else
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 ULONG ldap_modifyA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[] )
45 {
46     ULONG ret = LDAP_NOT_SUPPORTED;
47 #ifdef HAVE_LDAP
48     WCHAR *dnW = NULL;
49     LDAPModW **modsW = NULL;
50     
51     ret = WLDAP32_LDAP_NO_MEMORY;
52
53     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), mods );
54
55     if (!ld) return ~0UL;
56
57     if (dn) {
58         dnW = strAtoW( dn );
59         if (!dnW) goto exit;
60     }
61     if (mods) {
62         modsW = modarrayAtoW( mods );
63         if (!modsW) goto exit;
64     }
65
66     ret = ldap_modifyW( ld, dnW, modsW );
67
68 exit:
69     strfreeW( dnW );
70     modarrayfreeW( modsW );
71
72 #endif
73     return ret;
74 }
75
76 ULONG ldap_modifyW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[] )
77 {
78     ULONG ret = LDAP_NOT_SUPPORTED;
79 #ifdef HAVE_LDAP
80     char *dnU = NULL;
81     LDAPMod **modsU = NULL;
82     int msg;
83
84     ret = WLDAP32_LDAP_NO_MEMORY;
85
86     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), mods );
87
88     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
89
90     if (dn) {
91         dnU = strWtoU( dn );
92         if (!dnU) goto exit;
93     }
94     if (mods) {
95         modsU = modarrayWtoU( mods );
96         if (!modsU) goto exit;
97     }
98
99     ret = ldap_modify_ext( ld, dn ? dnU : "", mods ? modsU : nullmods,
100                            NULL, NULL, &msg );
101
102     if (ret == LDAP_SUCCESS)
103         ret = msg;
104     else
105         ret = ~0UL;
106
107 exit:
108     strfreeU( dnU );
109     modarrayfreeU( modsU );
110
111 #endif
112     return ret;
113 }
114
115 ULONG ldap_modify_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[],
116     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
117 {
118     ULONG ret = LDAP_NOT_SUPPORTED;
119 #ifdef HAVE_LDAP
120     WCHAR *dnW = NULL;
121     LDAPModW **modsW = NULL;
122     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
123
124     ret = WLDAP32_LDAP_NO_MEMORY;
125
126     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), mods,
127            serverctrls, clientctrls, message );
128
129     if (!ld) return ~0UL;
130
131     if (dn) {
132         dnW = strAtoW( dn );
133         if (!dnW) goto exit;
134     }
135     if (mods) {
136         modsW = modarrayAtoW( mods );
137         if (!modsW) goto exit;
138     }
139     if (serverctrls) {
140         serverctrlsW = controlarrayAtoW( serverctrls );
141         if (!serverctrlsW) goto exit;
142     }
143     if (clientctrls) {
144         clientctrlsW = controlarrayAtoW( clientctrls );
145         if (!clientctrlsW) goto exit;
146     }
147
148     ret = ldap_modify_extW( ld, dnW, modsW, serverctrlsW, clientctrlsW, message );
149
150 exit:
151     strfreeW( dnW );
152     modarrayfreeW( modsW );
153     controlarrayfreeW( serverctrlsW );
154     controlarrayfreeW( clientctrlsW );
155
156 #endif
157     return ret;
158 }
159
160 ULONG ldap_modify_extW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[],
161     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
162 {
163     ULONG ret = LDAP_NOT_SUPPORTED;
164 #ifdef HAVE_LDAP
165     char *dnU = NULL;
166     LDAPMod **modsU = NULL;
167     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
168     int dummy;
169
170     ret = WLDAP32_LDAP_NO_MEMORY;
171
172     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), mods,
173            serverctrls, clientctrls, message );
174
175     if (!ld) return ~0UL;
176
177     if (dn) {
178         dnU = strWtoU( dn );
179         if (!dnU) goto exit;
180     }
181     if (mods) {
182         modsU = modarrayWtoU( mods );
183         if (!modsU) goto exit;
184     }
185     if (serverctrls) {
186         serverctrlsU = controlarrayWtoU( serverctrls );
187         if (!serverctrlsU) goto exit;
188     }
189     if (clientctrls) {
190         clientctrlsU = controlarrayWtoU( clientctrls );
191         if (!clientctrlsU) goto exit;
192     }
193
194     ret = ldap_modify_ext( ld, dn ? dnU : "", mods ? modsU : nullmods, serverctrlsU,
195                            clientctrlsU, message ? (int *)message : &dummy );
196
197 exit:
198     strfreeU( dnU );
199     modarrayfreeU( modsU );
200     controlarrayfreeU( serverctrlsU );
201     controlarrayfreeU( clientctrlsU );
202
203 #endif
204     return ret;
205 }
206
207 ULONG ldap_modify_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[],
208     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
209 {
210     ULONG ret = LDAP_NOT_SUPPORTED;
211 #ifdef HAVE_LDAP
212     WCHAR *dnW = NULL;
213     LDAPModW **modsW = NULL;
214     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
215
216     ret = WLDAP32_LDAP_NO_MEMORY;
217
218     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), mods,
219            serverctrls, clientctrls );
220
221     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
222
223     if (dn) {
224         dnW = strAtoW( dn );
225         if (!dnW) goto exit;
226     }
227     if (mods) {
228         modsW = modarrayAtoW( mods );
229         if (!modsW) goto exit;
230     }
231     if (serverctrls) {
232         serverctrlsW = controlarrayAtoW( serverctrls );
233         if (!serverctrlsW) goto exit;
234     }
235     if (clientctrls) {
236         clientctrlsW = controlarrayAtoW( clientctrls );
237         if (!clientctrlsW) goto exit;
238     }
239
240     ret = ldap_modify_ext_sW( ld, dnW, modsW, serverctrlsW, clientctrlsW );
241
242 exit:
243     strfreeW( dnW );
244     modarrayfreeW( modsW );
245     controlarrayfreeW( serverctrlsW );
246     controlarrayfreeW( clientctrlsW );
247
248 #endif
249     return ret;
250 }
251
252 ULONG ldap_modify_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[],
253     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
254 {
255     ULONG ret = LDAP_NOT_SUPPORTED;
256 #ifdef HAVE_LDAP
257     char *dnU = NULL;
258     LDAPMod **modsU = NULL;
259     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
260
261     ret = WLDAP32_LDAP_NO_MEMORY;
262
263     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), mods,
264            serverctrls, clientctrls );
265
266     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
267
268     if (dn) {
269         dnU = strWtoU( dn );
270         if (!dnU) goto exit;
271     }
272     if (mods) {
273         modsU = modarrayWtoU( mods );
274         if (!modsU) goto exit;
275     }
276     if (serverctrls) {
277         serverctrlsU = controlarrayWtoU( serverctrls );
278         if (!serverctrlsU) goto exit;
279     }
280     if (clientctrls) {
281         clientctrlsU = controlarrayWtoU( clientctrls );
282         if (!clientctrlsU) goto exit;
283     }
284
285     ret = ldap_modify_ext_s( ld, dn ? dnU : "", mods ? modsU : nullmods,
286                              serverctrlsU, clientctrlsU );
287
288 exit:
289     strfreeU( dnU );
290     modarrayfreeU( modsU );
291     controlarrayfreeU( serverctrlsU );
292     controlarrayfreeU( clientctrlsU );
293
294 #endif
295     return ret;
296 }
297
298 ULONG ldap_modify_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[] )
299 {
300     ULONG ret = LDAP_NOT_SUPPORTED;
301 #ifdef HAVE_LDAP
302     WCHAR *dnW = NULL;
303     LDAPModW **modsW = NULL;
304
305     ret = WLDAP32_LDAP_NO_MEMORY;
306
307     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), mods );
308
309     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
310
311     if (dn) {
312         dnW = strAtoW( dn );
313         if (!dnW) goto exit;
314     }
315     if (mods) {
316         modsW = modarrayAtoW( mods );
317         if (!modsW) goto exit;
318     }
319
320     ret = ldap_modify_sW( ld, dnW, modsW );
321
322 exit:
323     strfreeW( dnW );
324     modarrayfreeW( modsW );
325
326 #endif
327     return ret;
328 }
329
330 ULONG ldap_modify_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[] )
331 {
332     ULONG ret = LDAP_NOT_SUPPORTED;
333 #ifdef HAVE_LDAP
334     char *dnU = NULL;
335     LDAPMod **modsU = NULL;
336
337     ret = WLDAP32_LDAP_NO_MEMORY;
338
339     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), mods );
340
341     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
342
343     if (dn) {
344         dnU = strWtoU( dn );
345         if (!dnU) goto exit;
346     }
347     if (mods) {
348         modsU = modarrayWtoU( mods );
349         if (!modsU) goto exit;
350     }
351
352     ret = ldap_modify_ext_s( ld, dn ? dnU : "", mods ? modsU : nullmods, NULL, NULL );
353
354 exit:
355     strfreeU( dnU );
356     modarrayfreeU( modsU );
357
358 #endif
359     return ret;
360 }