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