xref: /reactos/dll/win32/wldap32/modify.c (revision c2c66aff)
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 "winldap_private.h"
22 
23 #ifdef HAVE_LDAP
24 static LDAPMod *nullmods[] = { NULL };
25 #endif
26 
27 /***********************************************************************
28  *      ldap_modifyA     (WLDAP32.@)
29  *
30  * See ldap_modifyW.
31  */
32 ULONG CDECL ldap_modifyA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[] )
33 {
34     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
35 #ifdef HAVE_LDAP
36     WCHAR *dnW = NULL;
37     LDAPModW **modsW = NULL;
38 
39     ret = WLDAP32_LDAP_NO_MEMORY;
40 
41     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), mods );
42 
43     if (!ld) return ~0u;
44 
45     if (dn) {
46         dnW = strAtoW( dn );
47         if (!dnW) goto exit;
48     }
49     if (mods) {
50         modsW = modarrayAtoW( mods );
51         if (!modsW) goto exit;
52     }
53 
54     ret = ldap_modifyW( ld, dnW, modsW );
55 
56 exit:
57     strfreeW( dnW );
58     modarrayfreeW( modsW );
59 
60 #endif
61     return ret;
62 }
63 
64 /***********************************************************************
65  *      ldap_modifyW     (WLDAP32.@)
66  *
67  * Change an entry in a directory tree (asynchronous operation).
68  *
69  * PARAMS
70  *  ld     [I] Pointer to an LDAP context.
71  *  dn     [I] DN of the entry to change.
72  *  mods   [I] Pointer to an array of LDAPModW structures, each
73  *             specifying an attribute and its values to change.
74  *
75  * RETURNS
76  *  Success: Message ID of the modify operation.
77  *  Failure: An LDAP error code.
78  *
79  * NOTES
80  *  Call ldap_result with the message ID to get the result of
81  *  the operation. Cancel the operation by calling ldap_abandon
82  *  with the message ID.
83  */
84 ULONG CDECL ldap_modifyW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[] )
85 {
86     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
87 #ifdef HAVE_LDAP
88     char *dnU = NULL;
89     LDAPMod **modsU = NULL;
90     int msg;
91 
92     ret = WLDAP32_LDAP_NO_MEMORY;
93 
94     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), mods );
95 
96     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
97 
98     if (dn) {
99         dnU = strWtoU( dn );
100         if (!dnU) goto exit;
101     }
102     if (mods) {
103         modsU = modarrayWtoU( mods );
104         if (!modsU) goto exit;
105     }
106 
107     ret = ldap_modify_ext( ld, dn ? dnU : "", mods ? modsU : nullmods,
108                            NULL, NULL, &msg );
109 
110     if (ret == LDAP_SUCCESS)
111         ret = msg;
112     else
113         ret = ~0u;
114 
115 exit:
116     strfreeU( dnU );
117     modarrayfreeU( modsU );
118 
119 #endif
120     return ret;
121 }
122 
123 /***********************************************************************
124  *      ldap_modify_extA     (WLDAP32.@)
125  *
126  * See ldap_modify_extW.
127  */
128 ULONG CDECL ldap_modify_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[],
129     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
130 {
131     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
132 #ifdef HAVE_LDAP
133     WCHAR *dnW = NULL;
134     LDAPModW **modsW = NULL;
135     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
136 
137     ret = WLDAP32_LDAP_NO_MEMORY;
138 
139     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), mods,
140            serverctrls, clientctrls, message );
141 
142     if (!ld) return ~0u;
143 
144     if (dn) {
145         dnW = strAtoW( dn );
146         if (!dnW) goto exit;
147     }
148     if (mods) {
149         modsW = modarrayAtoW( mods );
150         if (!modsW) goto exit;
151     }
152     if (serverctrls) {
153         serverctrlsW = controlarrayAtoW( serverctrls );
154         if (!serverctrlsW) goto exit;
155     }
156     if (clientctrls) {
157         clientctrlsW = controlarrayAtoW( clientctrls );
158         if (!clientctrlsW) goto exit;
159     }
160 
161     ret = ldap_modify_extW( ld, dnW, modsW, serverctrlsW, clientctrlsW, message );
162 
163 exit:
164     strfreeW( dnW );
165     modarrayfreeW( modsW );
166     controlarrayfreeW( serverctrlsW );
167     controlarrayfreeW( clientctrlsW );
168 
169 #endif
170     return ret;
171 }
172 
173 /***********************************************************************
174  *      ldap_modify_extW     (WLDAP32.@)
175  *
176  * Change an entry in a directory tree (asynchronous operation).
177  *
178  * PARAMS
179  *  ld          [I] Pointer to an LDAP context.
180  *  dn          [I] DN of the entry to change.
181  *  mods        [I] Pointer to an array of LDAPModW structures, each
182  *                  specifying an attribute and its values to change.
183  *  serverctrls [I] Array of LDAP server controls.
184  *  clientctrls [I] Array of LDAP client controls.
185  *  message     [O] Message ID of the modify operation.
186  *
187  * RETURNS
188  *  Success: LDAP_SUCCESS
189  *  Failure: An LDAP error code.
190  *
191  * NOTES
192  *  Call ldap_result with the message ID to get the result of
193  *  the operation. The serverctrls and clientctrls parameters are
194  *  optional and should be set to NULL if not used.
195  */
196 ULONG CDECL ldap_modify_extW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[],
197     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
198 {
199     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
200 #ifdef HAVE_LDAP
201     char *dnU = NULL;
202     LDAPMod **modsU = NULL;
203     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
204     int dummy;
205 
206     ret = WLDAP32_LDAP_NO_MEMORY;
207 
208     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), mods,
209            serverctrls, clientctrls, message );
210 
211     if (!ld) return ~0u;
212 
213     if (dn) {
214         dnU = strWtoU( dn );
215         if (!dnU) goto exit;
216     }
217     if (mods) {
218         modsU = modarrayWtoU( mods );
219         if (!modsU) goto exit;
220     }
221     if (serverctrls) {
222         serverctrlsU = controlarrayWtoU( serverctrls );
223         if (!serverctrlsU) goto exit;
224     }
225     if (clientctrls) {
226         clientctrlsU = controlarrayWtoU( clientctrls );
227         if (!clientctrlsU) goto exit;
228     }
229 
230     ret = map_error( ldap_modify_ext( ld, dn ? dnU : "", mods ? modsU : nullmods, serverctrlsU,
231                                       clientctrlsU, message ? (int *)message : &dummy ));
232 
233 exit:
234     strfreeU( dnU );
235     modarrayfreeU( modsU );
236     controlarrayfreeU( serverctrlsU );
237     controlarrayfreeU( clientctrlsU );
238 
239 #endif
240     return ret;
241 }
242 
243 /***********************************************************************
244  *      ldap_modify_ext_sA     (WLDAP32.@)
245  *
246  * See ldap_modify_ext_sW.
247  */
248 ULONG CDECL ldap_modify_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[],
249     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
250 {
251     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
252 #ifdef HAVE_LDAP
253     WCHAR *dnW = NULL;
254     LDAPModW **modsW = NULL;
255     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
256 
257     ret = WLDAP32_LDAP_NO_MEMORY;
258 
259     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), mods,
260            serverctrls, clientctrls );
261 
262     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
263 
264     if (dn) {
265         dnW = strAtoW( dn );
266         if (!dnW) goto exit;
267     }
268     if (mods) {
269         modsW = modarrayAtoW( mods );
270         if (!modsW) goto exit;
271     }
272     if (serverctrls) {
273         serverctrlsW = controlarrayAtoW( serverctrls );
274         if (!serverctrlsW) goto exit;
275     }
276     if (clientctrls) {
277         clientctrlsW = controlarrayAtoW( clientctrls );
278         if (!clientctrlsW) goto exit;
279     }
280 
281     ret = ldap_modify_ext_sW( ld, dnW, modsW, serverctrlsW, clientctrlsW );
282 
283 exit:
284     strfreeW( dnW );
285     modarrayfreeW( modsW );
286     controlarrayfreeW( serverctrlsW );
287     controlarrayfreeW( clientctrlsW );
288 
289 #endif
290     return ret;
291 }
292 
293 /***********************************************************************
294  *      ldap_modify_ext_sW     (WLDAP32.@)
295  *
296  * Change an entry in a directory tree (synchronous operation).
297  *
298  * PARAMS
299  *  ld          [I] Pointer to an LDAP context.
300  *  dn          [I] DN of the entry to change.
301  *  mods        [I] Pointer to an array of LDAPModW structures, each
302  *                  specifying an attribute and its values to change.
303  *  serverctrls [I] Array of LDAP server controls.
304  *  clientctrls [I] Array of LDAP client controls.
305  *
306  * RETURNS
307  *  Success: LDAP_SUCCESS
308  *  Failure: An LDAP error code.
309  *
310  * NOTES
311  *  The serverctrls and clientctrls parameters are optional and
312  *  should be set to NULL if not used.
313  */
314 ULONG CDECL ldap_modify_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[],
315     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
316 {
317     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
318 #ifdef HAVE_LDAP
319     char *dnU = NULL;
320     LDAPMod **modsU = NULL;
321     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
322 
323     ret = WLDAP32_LDAP_NO_MEMORY;
324 
325     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), mods,
326            serverctrls, clientctrls );
327 
328     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
329 
330     if (dn) {
331         dnU = strWtoU( dn );
332         if (!dnU) goto exit;
333     }
334     if (mods) {
335         modsU = modarrayWtoU( mods );
336         if (!modsU) goto exit;
337     }
338     if (serverctrls) {
339         serverctrlsU = controlarrayWtoU( serverctrls );
340         if (!serverctrlsU) goto exit;
341     }
342     if (clientctrls) {
343         clientctrlsU = controlarrayWtoU( clientctrls );
344         if (!clientctrlsU) goto exit;
345     }
346 
347     ret = map_error( ldap_modify_ext_s( ld, dn ? dnU : "", mods ? modsU : nullmods,
348                                         serverctrlsU, clientctrlsU ));
349 
350 exit:
351     strfreeU( dnU );
352     modarrayfreeU( modsU );
353     controlarrayfreeU( serverctrlsU );
354     controlarrayfreeU( clientctrlsU );
355 
356 #endif
357     return ret;
358 }
359 
360 /***********************************************************************
361  *      ldap_modify_sA     (WLDAP32.@)
362  *
363  * See ldap_modify_sW.
364  */
365 ULONG CDECL ldap_modify_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[] )
366 {
367     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
368 #ifdef HAVE_LDAP
369     WCHAR *dnW = NULL;
370     LDAPModW **modsW = NULL;
371 
372     ret = WLDAP32_LDAP_NO_MEMORY;
373 
374     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), mods );
375 
376     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
377 
378     if (dn) {
379         dnW = strAtoW( dn );
380         if (!dnW) goto exit;
381     }
382     if (mods) {
383         modsW = modarrayAtoW( mods );
384         if (!modsW) goto exit;
385     }
386 
387     ret = ldap_modify_sW( ld, dnW, modsW );
388 
389 exit:
390     strfreeW( dnW );
391     modarrayfreeW( modsW );
392 
393 #endif
394     return ret;
395 }
396 
397 /***********************************************************************
398  *      ldap_modify_sW     (WLDAP32.@)
399  *
400  * Change an entry in a directory tree (synchronous operation).
401  *
402  * PARAMS
403  *  ld      [I] Pointer to an LDAP context.
404  *  dn      [I] DN of the entry to change.
405  *  attrs   [I] Pointer to an array of LDAPModW structures, each
406  *              specifying an attribute and its values to change.
407  *
408  * RETURNS
409  *  Success: LDAP_SUCCESS
410  *  Failure: An LDAP error code.
411  */
412 ULONG CDECL ldap_modify_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[] )
413 {
414     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
415 #ifdef HAVE_LDAP
416     char *dnU = NULL;
417     LDAPMod **modsU = NULL;
418 
419     ret = WLDAP32_LDAP_NO_MEMORY;
420 
421     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), mods );
422 
423     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
424 
425     if (dn) {
426         dnU = strWtoU( dn );
427         if (!dnU) goto exit;
428     }
429     if (mods) {
430         modsU = modarrayWtoU( mods );
431         if (!modsU) goto exit;
432     }
433 
434     ret = map_error( ldap_modify_ext_s( ld, dn ? dnU : "", mods ? modsU : nullmods, NULL, NULL ));
435 
436 exit:
437     strfreeU( dnU );
438     modarrayfreeU( modsU );
439 
440 #endif
441     return ret;
442 }
443